Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 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" | |
0e9f083f | 38 | #include <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" |
55aa24fb SDJ |
63 | #include "gdb_regex.h" |
64 | #include "probe.h" | |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
be34f849 | 66 | #include "continuations.h" |
1bfeeb0f JL |
67 | #include "stack.h" |
68 | #include "skip.h" | |
b775012e | 69 | #include "ax-gdb.h" |
e2e4d78b | 70 | #include "dummy-frame.h" |
c906108c | 71 | |
d3ce09f5 SS |
72 | #include "format.h" |
73 | ||
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
104c1213 | 83 | |
e7e8980f YQ |
84 | /* Enums for exception-handling support. */ |
85 | enum exception_event_kind | |
86 | { | |
87 | EX_EVENT_THROW, | |
591f19e8 | 88 | EX_EVENT_RETHROW, |
e7e8980f YQ |
89 | EX_EVENT_CATCH |
90 | }; | |
91 | ||
4a64f543 | 92 | /* Prototypes for local functions. */ |
c906108c | 93 | |
a14ed312 | 94 | static void enable_delete_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void enable_once_command (char *, int); |
c906108c | 97 | |
816338b5 SS |
98 | static void enable_count_command (char *, int); |
99 | ||
a14ed312 | 100 | static void disable_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void enable_command (char *, int); |
c906108c | 103 | |
95a42b64 TT |
104 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
105 | void *), | |
106 | void *); | |
c906108c | 107 | |
a14ed312 | 108 | static void ignore_command (char *, int); |
c906108c | 109 | |
4efb68b1 | 110 | static int breakpoint_re_set_one (void *); |
c906108c | 111 | |
348d480f PA |
112 | static void breakpoint_re_set_default (struct breakpoint *); |
113 | ||
983af33b SDJ |
114 | static void create_sals_from_address_default (char **, |
115 | struct linespec_result *, | |
116 | enum bptype, char *, | |
117 | char **); | |
118 | ||
119 | static void create_breakpoints_sal_default (struct gdbarch *, | |
120 | struct linespec_result *, | |
e7e0cddf | 121 | char *, char *, enum bptype, |
983af33b SDJ |
122 | enum bpdisp, int, int, |
123 | int, | |
124 | const struct breakpoint_ops *, | |
44f238bb | 125 | int, int, int, unsigned); |
983af33b SDJ |
126 | |
127 | static void decode_linespec_default (struct breakpoint *, char **, | |
128 | struct symtabs_and_lines *); | |
129 | ||
a14ed312 | 130 | static void clear_command (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void catch_command (char *, int); |
c906108c | 133 | |
a9634178 | 134 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 135 | |
98deb0da | 136 | static void break_command_1 (char *, int, int); |
c906108c | 137 | |
a14ed312 | 138 | static void mention (struct breakpoint *); |
c906108c | 139 | |
348d480f PA |
140 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
141 | enum bptype, | |
c0a91b2b | 142 | const struct breakpoint_ops *); |
3742cc8b YQ |
143 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
144 | const struct symtab_and_line *); | |
145 | ||
4a64f543 MS |
146 | /* This function is used in gdbtk sources and thus can not be made |
147 | static. */ | |
63c252f8 | 148 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 149 | struct symtab_and_line, |
c0a91b2b TT |
150 | enum bptype, |
151 | const struct breakpoint_ops *); | |
c906108c | 152 | |
06edf0c0 PA |
153 | static struct breakpoint * |
154 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
155 | enum bptype type, | |
c0a91b2b | 156 | const struct breakpoint_ops *ops); |
06edf0c0 | 157 | |
76897487 KB |
158 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
159 | ||
a6d9a66e UW |
160 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
161 | CORE_ADDR bpaddr, | |
88f7da05 | 162 | enum bptype bptype); |
76897487 | 163 | |
6c95b8df PA |
164 | static void describe_other_breakpoints (struct gdbarch *, |
165 | struct program_space *, CORE_ADDR, | |
5af949e3 | 166 | struct obj_section *, int); |
c906108c | 167 | |
85d721b8 PA |
168 | static int watchpoint_locations_match (struct bp_location *loc1, |
169 | struct bp_location *loc2); | |
170 | ||
f1310107 TJB |
171 | static int breakpoint_location_address_match (struct bp_location *bl, |
172 | struct address_space *aspace, | |
173 | CORE_ADDR addr); | |
174 | ||
a14ed312 | 175 | static void breakpoints_info (char *, int); |
c906108c | 176 | |
d77f58be SS |
177 | static void watchpoints_info (char *, int); |
178 | ||
e5a67952 MS |
179 | static int breakpoint_1 (char *, int, |
180 | int (*) (const struct breakpoint *)); | |
c906108c | 181 | |
4efb68b1 | 182 | static int breakpoint_cond_eval (void *); |
c906108c | 183 | |
4efb68b1 | 184 | static void cleanup_executing_breakpoints (void *); |
c906108c | 185 | |
a14ed312 | 186 | static void commands_command (char *, int); |
c906108c | 187 | |
a14ed312 | 188 | static void condition_command (char *, int); |
c906108c | 189 | |
c5aa993b JM |
190 | typedef enum |
191 | { | |
192 | mark_inserted, | |
193 | mark_uninserted | |
194 | } | |
195 | insertion_state_t; | |
c906108c | 196 | |
0bde7532 | 197 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 198 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 199 | |
e514a9d6 | 200 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 201 | |
4efb68b1 | 202 | static int watchpoint_check (void *); |
c906108c | 203 | |
a14ed312 | 204 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 205 | |
a14ed312 | 206 | static int hw_breakpoint_used_count (void); |
c906108c | 207 | |
a1398e0c PA |
208 | static int hw_watchpoint_use_count (struct breakpoint *); |
209 | ||
210 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
211 | enum bptype type, | |
212 | int *other_type_used); | |
c906108c | 213 | |
a14ed312 | 214 | static void hbreak_command (char *, int); |
c906108c | 215 | |
a14ed312 | 216 | static void thbreak_command (char *, int); |
c906108c | 217 | |
816338b5 SS |
218 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
219 | int count); | |
c906108c | 220 | |
a14ed312 | 221 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 222 | |
a14ed312 | 223 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopat_command (char *arg, 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 | ||
fe3f5fa8 | 231 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
232 | static void incref_bp_location (struct bp_location *loc); |
233 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 234 | |
39d61571 | 235 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 236 | |
b60e7edf | 237 | static void update_global_location_list (int); |
a5606eee | 238 | |
b60e7edf | 239 | static void update_global_location_list_nothrow (int); |
74960c60 | 240 | |
d77f58be | 241 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
242 | |
243 | static void insert_breakpoint_locations (void); | |
a5606eee | 244 | |
a96d9b2e SDJ |
245 | static int syscall_catchpoint_p (struct breakpoint *b); |
246 | ||
1042e4c0 SS |
247 | static void tracepoints_info (char *, int); |
248 | ||
249 | static void delete_trace_command (char *, int); | |
250 | ||
251 | static void enable_trace_command (char *, int); | |
252 | ||
253 | static void disable_trace_command (char *, int); | |
254 | ||
255 | static void trace_pass_command (char *, int); | |
256 | ||
558a9d82 YQ |
257 | static void set_tracepoint_count (int num); |
258 | ||
9c06b0b4 TJB |
259 | static int is_masked_watchpoint (const struct breakpoint *b); |
260 | ||
b775012e LM |
261 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
262 | ||
983af33b SDJ |
263 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
264 | otherwise. */ | |
265 | ||
266 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 267 | |
2060206e PA |
268 | /* The abstract base class all breakpoint_ops structures inherit |
269 | from. */ | |
ab04a2af | 270 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
271 | |
272 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
273 | that are implemented on top of software or hardware breakpoints | |
274 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
275 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
276 | ||
277 | /* Internal breakpoints class type. */ | |
06edf0c0 | 278 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
279 | |
280 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
281 | static struct breakpoint_ops momentary_breakpoint_ops; |
282 | ||
e2e4d78b JK |
283 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
284 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
285 | ||
2060206e PA |
286 | /* The breakpoint_ops structure to be used in regular user created |
287 | breakpoints. */ | |
288 | struct breakpoint_ops bkpt_breakpoint_ops; | |
289 | ||
55aa24fb SDJ |
290 | /* Breakpoints set on probes. */ |
291 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
292 | ||
e7e0cddf | 293 | /* Dynamic printf class type. */ |
c5867ab6 | 294 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 295 | |
d3ce09f5 SS |
296 | /* The style in which to perform a dynamic printf. This is a user |
297 | option because different output options have different tradeoffs; | |
298 | if GDB does the printing, there is better error handling if there | |
299 | is a problem with any of the arguments, but using an inferior | |
300 | function lets you have special-purpose printers and sending of | |
301 | output to the same place as compiled-in print functions. */ | |
302 | ||
303 | static const char dprintf_style_gdb[] = "gdb"; | |
304 | static const char dprintf_style_call[] = "call"; | |
305 | static const char dprintf_style_agent[] = "agent"; | |
306 | static const char *const dprintf_style_enums[] = { | |
307 | dprintf_style_gdb, | |
308 | dprintf_style_call, | |
309 | dprintf_style_agent, | |
310 | NULL | |
311 | }; | |
312 | static const char *dprintf_style = dprintf_style_gdb; | |
313 | ||
314 | /* The function to use for dynamic printf if the preferred style is to | |
315 | call into the inferior. The value is simply a string that is | |
316 | copied into the command, so it can be anything that GDB can | |
317 | evaluate to a callable address, not necessarily a function name. */ | |
318 | ||
319 | static char *dprintf_function = ""; | |
320 | ||
321 | /* The channel to use for dynamic printf if the preferred style is to | |
322 | call into the inferior; if a nonempty string, it will be passed to | |
323 | the call as the first argument, with the format string as the | |
324 | second. As with the dprintf function, this can be anything that | |
325 | GDB knows how to evaluate, so in addition to common choices like | |
326 | "stderr", this could be an app-specific expression like | |
327 | "mystreams[curlogger]". */ | |
328 | ||
329 | static char *dprintf_channel = ""; | |
330 | ||
331 | /* True if dprintf commands should continue to operate even if GDB | |
332 | has disconnected. */ | |
333 | static int disconnected_dprintf = 1; | |
334 | ||
5cea2a26 PA |
335 | /* A reference-counted struct command_line. This lets multiple |
336 | breakpoints share a single command list. */ | |
337 | struct counted_command_line | |
338 | { | |
339 | /* The reference count. */ | |
340 | int refc; | |
341 | ||
342 | /* The command list. */ | |
343 | struct command_line *commands; | |
344 | }; | |
345 | ||
346 | struct command_line * | |
347 | breakpoint_commands (struct breakpoint *b) | |
348 | { | |
349 | return b->commands ? b->commands->commands : NULL; | |
350 | } | |
3daf8fe5 | 351 | |
f3b1572e PA |
352 | /* Flag indicating that a command has proceeded the inferior past the |
353 | current breakpoint. */ | |
354 | ||
355 | static int breakpoint_proceeded; | |
356 | ||
956a9fb9 | 357 | const char * |
2cec12e5 AR |
358 | bpdisp_text (enum bpdisp disp) |
359 | { | |
4a64f543 MS |
360 | /* NOTE: the following values are a part of MI protocol and |
361 | represent values of 'disp' field returned when inferior stops at | |
362 | a breakpoint. */ | |
bc043ef3 | 363 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 364 | |
2cec12e5 AR |
365 | return bpdisps[(int) disp]; |
366 | } | |
c906108c | 367 | |
4a64f543 | 368 | /* Prototypes for exported functions. */ |
c906108c | 369 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 370 | if such is available. */ |
c906108c SS |
371 | static int can_use_hw_watchpoints; |
372 | ||
920d2a44 AC |
373 | static void |
374 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
375 | struct cmd_list_element *c, | |
376 | const char *value) | |
377 | { | |
3e43a32a MS |
378 | fprintf_filtered (file, |
379 | _("Debugger's willingness to use " | |
380 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
381 | value); |
382 | } | |
383 | ||
fa8d40ab JJ |
384 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
385 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 386 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
387 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
388 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
389 | static void |
390 | show_pending_break_support (struct ui_file *file, int from_tty, | |
391 | struct cmd_list_element *c, | |
392 | const char *value) | |
393 | { | |
3e43a32a MS |
394 | fprintf_filtered (file, |
395 | _("Debugger's behavior regarding " | |
396 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
397 | value); |
398 | } | |
fa8d40ab | 399 | |
765dc015 | 400 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 401 | set with "break" but falling in read-only memory. |
765dc015 VP |
402 | If 0, gdb will warn about such breakpoints, but won't automatically |
403 | use hardware breakpoints. */ | |
404 | static int automatic_hardware_breakpoints; | |
405 | static void | |
406 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
407 | struct cmd_list_element *c, | |
408 | const char *value) | |
409 | { | |
3e43a32a MS |
410 | fprintf_filtered (file, |
411 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
412 | value); |
413 | } | |
414 | ||
33e5cbd6 PA |
415 | /* If on, gdb will keep breakpoints inserted even as inferior is |
416 | stopped, and immediately insert any new breakpoints. If off, gdb | |
417 | will insert breakpoints into inferior only when resuming it, and | |
418 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
419 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
420 | ||
72d0e2c5 YQ |
421 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
422 | ||
33e5cbd6 | 423 | static void |
74960c60 | 424 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 425 | struct cmd_list_element *c, const char *value) |
74960c60 | 426 | { |
72d0e2c5 | 427 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
428 | fprintf_filtered (file, |
429 | _("Always inserted breakpoint " | |
430 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
431 | value, |
432 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
433 | else | |
3e43a32a MS |
434 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
435 | value); | |
74960c60 VP |
436 | } |
437 | ||
33e5cbd6 PA |
438 | int |
439 | breakpoints_always_inserted_mode (void) | |
440 | { | |
72d0e2c5 YQ |
441 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
442 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 443 | } |
765dc015 | 444 | |
b775012e LM |
445 | static const char condition_evaluation_both[] = "host or target"; |
446 | ||
447 | /* Modes for breakpoint condition evaluation. */ | |
448 | static const char condition_evaluation_auto[] = "auto"; | |
449 | static const char condition_evaluation_host[] = "host"; | |
450 | static const char condition_evaluation_target[] = "target"; | |
451 | static const char *const condition_evaluation_enums[] = { | |
452 | condition_evaluation_auto, | |
453 | condition_evaluation_host, | |
454 | condition_evaluation_target, | |
455 | NULL | |
456 | }; | |
457 | ||
458 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
459 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
460 | ||
461 | /* Global that we use to display information to the user (gets its value from | |
462 | condition_evaluation_mode_1. */ | |
463 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
464 | ||
465 | /* Translate a condition evaluation mode MODE into either "host" | |
466 | or "target". This is used mostly to translate from "auto" to the | |
467 | real setting that is being used. It returns the translated | |
468 | evaluation mode. */ | |
469 | ||
470 | static const char * | |
471 | translate_condition_evaluation_mode (const char *mode) | |
472 | { | |
473 | if (mode == condition_evaluation_auto) | |
474 | { | |
475 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
476 | return condition_evaluation_target; | |
477 | else | |
478 | return condition_evaluation_host; | |
479 | } | |
480 | else | |
481 | return mode; | |
482 | } | |
483 | ||
484 | /* Discovers what condition_evaluation_auto translates to. */ | |
485 | ||
486 | static const char * | |
487 | breakpoint_condition_evaluation_mode (void) | |
488 | { | |
489 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
490 | } | |
491 | ||
492 | /* Return true if GDB should evaluate breakpoint conditions or false | |
493 | otherwise. */ | |
494 | ||
495 | static int | |
496 | gdb_evaluates_breakpoint_condition_p (void) | |
497 | { | |
498 | const char *mode = breakpoint_condition_evaluation_mode (); | |
499 | ||
500 | return (mode == condition_evaluation_host); | |
501 | } | |
502 | ||
a14ed312 | 503 | void _initialize_breakpoint (void); |
c906108c | 504 | |
c906108c SS |
505 | /* Are we executing breakpoint commands? */ |
506 | static int executing_breakpoint_commands; | |
507 | ||
c02f5703 MS |
508 | /* Are overlay event breakpoints enabled? */ |
509 | static int overlay_events_enabled; | |
510 | ||
e09342b5 TJB |
511 | /* See description in breakpoint.h. */ |
512 | int target_exact_watchpoints = 0; | |
513 | ||
c906108c | 514 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 515 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 516 | current breakpoint. */ |
c906108c | 517 | |
5c44784c | 518 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 519 | |
5c44784c JM |
520 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
521 | for (B = breakpoint_chain; \ | |
522 | B ? (TMP=B->next, 1): 0; \ | |
523 | B = TMP) | |
c906108c | 524 | |
4a64f543 MS |
525 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
526 | not provided so update_global_location_list must not be called | |
527 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 528 | |
876fa593 JK |
529 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
530 | for (BP_TMP = bp_location; \ | |
531 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
532 | BP_TMP++) | |
7cc221ef | 533 | |
b775012e LM |
534 | /* Iterates through locations with address ADDRESS for the currently selected |
535 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
536 | to where the loop should start from. | |
537 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
538 | appropriate location to start with. */ | |
539 | ||
540 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
541 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
542 | BP_LOCP_TMP = BP_LOCP_START; \ | |
543 | BP_LOCP_START \ | |
544 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
545 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
546 | BP_LOCP_TMP++) | |
547 | ||
1042e4c0 SS |
548 | /* Iterator for tracepoints only. */ |
549 | ||
550 | #define ALL_TRACEPOINTS(B) \ | |
551 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 552 | if (is_tracepoint (B)) |
1042e4c0 | 553 | |
7cc221ef | 554 | /* Chains of all breakpoints defined. */ |
c906108c SS |
555 | |
556 | struct breakpoint *breakpoint_chain; | |
557 | ||
876fa593 JK |
558 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
559 | ||
560 | static struct bp_location **bp_location; | |
561 | ||
562 | /* Number of elements of BP_LOCATION. */ | |
563 | ||
564 | static unsigned bp_location_count; | |
565 | ||
4a64f543 MS |
566 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
567 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
568 | result from bp_location_has_shadow. You can use it for roughly | |
569 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
570 | an address you need to read. */ | |
876fa593 JK |
571 | |
572 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
573 | ||
4a64f543 MS |
574 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
575 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
576 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
577 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
578 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
579 | |
580 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 581 | |
4a64f543 MS |
582 | /* The locations that no longer correspond to any breakpoint, unlinked |
583 | from bp_location array, but for which a hit may still be reported | |
584 | by a target. */ | |
20874c92 VP |
585 | VEC(bp_location_p) *moribund_locations = NULL; |
586 | ||
c906108c SS |
587 | /* Number of last breakpoint made. */ |
588 | ||
95a42b64 TT |
589 | static int breakpoint_count; |
590 | ||
86b17b60 PA |
591 | /* The value of `breakpoint_count' before the last command that |
592 | created breakpoints. If the last (break-like) command created more | |
593 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
594 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
595 | static int prev_breakpoint_count; | |
c906108c | 596 | |
1042e4c0 SS |
597 | /* Number of last tracepoint made. */ |
598 | ||
95a42b64 | 599 | static int tracepoint_count; |
1042e4c0 | 600 | |
6149aea9 PA |
601 | static struct cmd_list_element *breakpoint_set_cmdlist; |
602 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 603 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 604 | |
468d015d JJ |
605 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
606 | static int | |
607 | breakpoint_enabled (struct breakpoint *b) | |
608 | { | |
0d381245 | 609 | return (b->enable_state == bp_enabled); |
468d015d JJ |
610 | } |
611 | ||
c906108c SS |
612 | /* Set breakpoint count to NUM. */ |
613 | ||
95a42b64 | 614 | static void |
fba45db2 | 615 | set_breakpoint_count (int num) |
c906108c | 616 | { |
86b17b60 | 617 | prev_breakpoint_count = breakpoint_count; |
c906108c | 618 | breakpoint_count = num; |
4fa62494 | 619 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
620 | } |
621 | ||
86b17b60 PA |
622 | /* Used by `start_rbreak_breakpoints' below, to record the current |
623 | breakpoint count before "rbreak" creates any breakpoint. */ | |
624 | static int rbreak_start_breakpoint_count; | |
625 | ||
95a42b64 TT |
626 | /* Called at the start an "rbreak" command to record the first |
627 | breakpoint made. */ | |
86b17b60 | 628 | |
95a42b64 TT |
629 | void |
630 | start_rbreak_breakpoints (void) | |
631 | { | |
86b17b60 | 632 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
633 | } |
634 | ||
635 | /* Called at the end of an "rbreak" command to record the last | |
636 | breakpoint made. */ | |
86b17b60 | 637 | |
95a42b64 TT |
638 | void |
639 | end_rbreak_breakpoints (void) | |
640 | { | |
86b17b60 | 641 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
642 | } |
643 | ||
4a64f543 | 644 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
645 | |
646 | void | |
fba45db2 | 647 | clear_breakpoint_hit_counts (void) |
c906108c SS |
648 | { |
649 | struct breakpoint *b; | |
650 | ||
651 | ALL_BREAKPOINTS (b) | |
652 | b->hit_count = 0; | |
653 | } | |
654 | ||
9add0f1b TT |
655 | /* Allocate a new counted_command_line with reference count of 1. |
656 | The new structure owns COMMANDS. */ | |
657 | ||
658 | static struct counted_command_line * | |
659 | alloc_counted_command_line (struct command_line *commands) | |
660 | { | |
661 | struct counted_command_line *result | |
662 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 663 | |
9add0f1b TT |
664 | result->refc = 1; |
665 | result->commands = commands; | |
666 | return result; | |
667 | } | |
668 | ||
669 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
670 | ||
671 | static void | |
672 | incref_counted_command_line (struct counted_command_line *cmd) | |
673 | { | |
674 | if (cmd) | |
675 | ++cmd->refc; | |
676 | } | |
677 | ||
678 | /* Decrement reference count. If the reference count reaches 0, | |
679 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
680 | nothing if *CMDP is NULL. */ | |
681 | ||
682 | static void | |
683 | decref_counted_command_line (struct counted_command_line **cmdp) | |
684 | { | |
685 | if (*cmdp) | |
686 | { | |
687 | if (--(*cmdp)->refc == 0) | |
688 | { | |
689 | free_command_lines (&(*cmdp)->commands); | |
690 | xfree (*cmdp); | |
691 | } | |
692 | *cmdp = NULL; | |
693 | } | |
694 | } | |
695 | ||
696 | /* A cleanup function that calls decref_counted_command_line. */ | |
697 | ||
698 | static void | |
699 | do_cleanup_counted_command_line (void *arg) | |
700 | { | |
701 | decref_counted_command_line (arg); | |
702 | } | |
703 | ||
704 | /* Create a cleanup that calls decref_counted_command_line on the | |
705 | argument. */ | |
706 | ||
707 | static struct cleanup * | |
708 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
709 | { | |
710 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
711 | } | |
712 | ||
c906108c | 713 | \f |
48cb2d85 VP |
714 | /* Return the breakpoint with the specified number, or NULL |
715 | if the number does not refer to an existing breakpoint. */ | |
716 | ||
717 | struct breakpoint * | |
718 | get_breakpoint (int num) | |
719 | { | |
720 | struct breakpoint *b; | |
721 | ||
722 | ALL_BREAKPOINTS (b) | |
723 | if (b->number == num) | |
724 | return b; | |
725 | ||
726 | return NULL; | |
727 | } | |
5c44784c | 728 | |
c906108c | 729 | \f |
adc36818 | 730 | |
b775012e LM |
731 | /* Mark locations as "conditions have changed" in case the target supports |
732 | evaluating conditions on its side. */ | |
733 | ||
734 | static void | |
735 | mark_breakpoint_modified (struct breakpoint *b) | |
736 | { | |
737 | struct bp_location *loc; | |
738 | ||
739 | /* This is only meaningful if the target is | |
740 | evaluating conditions and if the user has | |
741 | opted for condition evaluation on the target's | |
742 | side. */ | |
743 | if (gdb_evaluates_breakpoint_condition_p () | |
744 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
745 | return; | |
746 | ||
747 | if (!is_breakpoint (b)) | |
748 | return; | |
749 | ||
750 | for (loc = b->loc; loc; loc = loc->next) | |
751 | loc->condition_changed = condition_modified; | |
752 | } | |
753 | ||
754 | /* Mark location as "conditions have changed" in case the target supports | |
755 | evaluating conditions on its side. */ | |
756 | ||
757 | static void | |
758 | mark_breakpoint_location_modified (struct bp_location *loc) | |
759 | { | |
760 | /* This is only meaningful if the target is | |
761 | evaluating conditions and if the user has | |
762 | opted for condition evaluation on the target's | |
763 | side. */ | |
764 | if (gdb_evaluates_breakpoint_condition_p () | |
765 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
766 | ||
767 | return; | |
768 | ||
769 | if (!is_breakpoint (loc->owner)) | |
770 | return; | |
771 | ||
772 | loc->condition_changed = condition_modified; | |
773 | } | |
774 | ||
775 | /* Sets the condition-evaluation mode using the static global | |
776 | condition_evaluation_mode. */ | |
777 | ||
778 | static void | |
779 | set_condition_evaluation_mode (char *args, int from_tty, | |
780 | struct cmd_list_element *c) | |
781 | { | |
b775012e LM |
782 | const char *old_mode, *new_mode; |
783 | ||
784 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
785 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
786 | { | |
787 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
788 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
789 | "Using host evaluation mode instead.")); | |
790 | return; | |
791 | } | |
792 | ||
793 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
794 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
795 | ||
abf1152a JK |
796 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
797 | settings was "auto". */ | |
798 | condition_evaluation_mode = condition_evaluation_mode_1; | |
799 | ||
b775012e LM |
800 | /* Only update the mode if the user picked a different one. */ |
801 | if (new_mode != old_mode) | |
802 | { | |
803 | struct bp_location *loc, **loc_tmp; | |
804 | /* If the user switched to a different evaluation mode, we | |
805 | need to synch the changes with the target as follows: | |
806 | ||
807 | "host" -> "target": Send all (valid) conditions to the target. | |
808 | "target" -> "host": Remove all the conditions from the target. | |
809 | */ | |
810 | ||
b775012e LM |
811 | if (new_mode == condition_evaluation_target) |
812 | { | |
813 | /* Mark everything modified and synch conditions with the | |
814 | target. */ | |
815 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
816 | mark_breakpoint_location_modified (loc); | |
817 | } | |
818 | else | |
819 | { | |
820 | /* Manually mark non-duplicate locations to synch conditions | |
821 | with the target. We do this to remove all the conditions the | |
822 | target knows about. */ | |
823 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
824 | if (is_breakpoint (loc->owner) && loc->inserted) | |
825 | loc->needs_update = 1; | |
826 | } | |
827 | ||
828 | /* Do the update. */ | |
829 | update_global_location_list (1); | |
830 | } | |
831 | ||
832 | return; | |
833 | } | |
834 | ||
835 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
836 | what "auto" is translating to. */ | |
837 | ||
838 | static void | |
839 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
840 | struct cmd_list_element *c, const char *value) | |
841 | { | |
842 | if (condition_evaluation_mode == condition_evaluation_auto) | |
843 | fprintf_filtered (file, | |
844 | _("Breakpoint condition evaluation " | |
845 | "mode is %s (currently %s).\n"), | |
846 | value, | |
847 | breakpoint_condition_evaluation_mode ()); | |
848 | else | |
849 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
850 | value); | |
851 | } | |
852 | ||
853 | /* A comparison function for bp_location AP and BP that is used by | |
854 | bsearch. This comparison function only cares about addresses, unlike | |
855 | the more general bp_location_compare function. */ | |
856 | ||
857 | static int | |
858 | bp_location_compare_addrs (const void *ap, const void *bp) | |
859 | { | |
860 | struct bp_location *a = *(void **) ap; | |
861 | struct bp_location *b = *(void **) bp; | |
862 | ||
863 | if (a->address == b->address) | |
864 | return 0; | |
865 | else | |
866 | return ((a->address > b->address) - (a->address < b->address)); | |
867 | } | |
868 | ||
869 | /* Helper function to skip all bp_locations with addresses | |
870 | less than ADDRESS. It returns the first bp_location that | |
871 | is greater than or equal to ADDRESS. If none is found, just | |
872 | return NULL. */ | |
873 | ||
874 | static struct bp_location ** | |
875 | get_first_locp_gte_addr (CORE_ADDR address) | |
876 | { | |
877 | struct bp_location dummy_loc; | |
878 | struct bp_location *dummy_locp = &dummy_loc; | |
879 | struct bp_location **locp_found = NULL; | |
880 | ||
881 | /* Initialize the dummy location's address field. */ | |
882 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
883 | dummy_loc.address = address; | |
884 | ||
885 | /* Find a close match to the first location at ADDRESS. */ | |
886 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
887 | sizeof (struct bp_location **), | |
888 | bp_location_compare_addrs); | |
889 | ||
890 | /* Nothing was found, nothing left to do. */ | |
891 | if (locp_found == NULL) | |
892 | return NULL; | |
893 | ||
894 | /* We may have found a location that is at ADDRESS but is not the first in the | |
895 | location's list. Go backwards (if possible) and locate the first one. */ | |
896 | while ((locp_found - 1) >= bp_location | |
897 | && (*(locp_found - 1))->address == address) | |
898 | locp_found--; | |
899 | ||
900 | return locp_found; | |
901 | } | |
902 | ||
adc36818 PM |
903 | void |
904 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
905 | int from_tty) | |
906 | { | |
3a5c3e22 PA |
907 | xfree (b->cond_string); |
908 | b->cond_string = NULL; | |
adc36818 | 909 | |
3a5c3e22 | 910 | if (is_watchpoint (b)) |
adc36818 | 911 | { |
3a5c3e22 PA |
912 | struct watchpoint *w = (struct watchpoint *) b; |
913 | ||
914 | xfree (w->cond_exp); | |
915 | w->cond_exp = NULL; | |
916 | } | |
917 | else | |
918 | { | |
919 | struct bp_location *loc; | |
920 | ||
921 | for (loc = b->loc; loc; loc = loc->next) | |
922 | { | |
923 | xfree (loc->cond); | |
924 | loc->cond = NULL; | |
b775012e LM |
925 | |
926 | /* No need to free the condition agent expression | |
927 | bytecode (if we have one). We will handle this | |
928 | when we go through update_global_location_list. */ | |
3a5c3e22 | 929 | } |
adc36818 | 930 | } |
adc36818 PM |
931 | |
932 | if (*exp == 0) | |
933 | { | |
934 | if (from_tty) | |
935 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
936 | } | |
937 | else | |
938 | { | |
bbc13ae3 | 939 | const char *arg = exp; |
cc59ec59 | 940 | |
adc36818 PM |
941 | /* I don't know if it matters whether this is the string the user |
942 | typed in or the decompiled expression. */ | |
943 | b->cond_string = xstrdup (arg); | |
944 | b->condition_not_parsed = 0; | |
945 | ||
946 | if (is_watchpoint (b)) | |
947 | { | |
3a5c3e22 PA |
948 | struct watchpoint *w = (struct watchpoint *) b; |
949 | ||
adc36818 PM |
950 | innermost_block = NULL; |
951 | arg = exp; | |
1bb9788d | 952 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
953 | if (*arg) |
954 | error (_("Junk at end of expression")); | |
3a5c3e22 | 955 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
956 | } |
957 | else | |
958 | { | |
3a5c3e22 PA |
959 | struct bp_location *loc; |
960 | ||
adc36818 PM |
961 | for (loc = b->loc; loc; loc = loc->next) |
962 | { | |
963 | arg = exp; | |
964 | loc->cond = | |
1bb9788d TT |
965 | parse_exp_1 (&arg, loc->address, |
966 | block_for_pc (loc->address), 0); | |
adc36818 PM |
967 | if (*arg) |
968 | error (_("Junk at end of expression")); | |
969 | } | |
970 | } | |
971 | } | |
b775012e LM |
972 | mark_breakpoint_modified (b); |
973 | ||
8d3788bd | 974 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
975 | } |
976 | ||
d55637df TT |
977 | /* Completion for the "condition" command. */ |
978 | ||
979 | static VEC (char_ptr) * | |
6f937416 PA |
980 | condition_completer (struct cmd_list_element *cmd, |
981 | const char *text, const char *word) | |
d55637df | 982 | { |
6f937416 | 983 | const char *space; |
d55637df | 984 | |
6f937416 PA |
985 | text = skip_spaces_const (text); |
986 | space = skip_to_space_const (text); | |
d55637df TT |
987 | if (*space == '\0') |
988 | { | |
989 | int len; | |
990 | struct breakpoint *b; | |
991 | VEC (char_ptr) *result = NULL; | |
992 | ||
993 | if (text[0] == '$') | |
994 | { | |
995 | /* We don't support completion of history indices. */ | |
996 | if (isdigit (text[1])) | |
997 | return NULL; | |
998 | return complete_internalvar (&text[1]); | |
999 | } | |
1000 | ||
1001 | /* We're completing the breakpoint number. */ | |
1002 | len = strlen (text); | |
1003 | ||
1004 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1005 | { |
1006 | char number[50]; | |
1007 | ||
1008 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1009 | ||
1010 | if (strncmp (number, text, len) == 0) | |
1011 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1012 | } | |
d55637df TT |
1013 | |
1014 | return result; | |
1015 | } | |
1016 | ||
1017 | /* We're completing the expression part. */ | |
6f937416 | 1018 | text = skip_spaces_const (space); |
d55637df TT |
1019 | return expression_completer (cmd, text, word); |
1020 | } | |
1021 | ||
c906108c SS |
1022 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1023 | ||
1024 | static void | |
fba45db2 | 1025 | condition_command (char *arg, int from_tty) |
c906108c | 1026 | { |
52f0bd74 | 1027 | struct breakpoint *b; |
c906108c | 1028 | char *p; |
52f0bd74 | 1029 | int bnum; |
c906108c SS |
1030 | |
1031 | if (arg == 0) | |
e2e0b3e5 | 1032 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1033 | |
1034 | p = arg; | |
1035 | bnum = get_number (&p); | |
5c44784c | 1036 | if (bnum == 0) |
8a3fe4f8 | 1037 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1038 | |
1039 | ALL_BREAKPOINTS (b) | |
1040 | if (b->number == bnum) | |
2f069f6f | 1041 | { |
6dddc817 DE |
1042 | /* Check if this breakpoint has a "stop" method implemented in an |
1043 | extension language. This method and conditions entered into GDB | |
1044 | from the CLI are mutually exclusive. */ | |
1045 | const struct extension_language_defn *extlang | |
1046 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1047 | ||
1048 | if (extlang != NULL) | |
1049 | { | |
1050 | error (_("Only one stop condition allowed. There is currently" | |
1051 | " a %s stop condition defined for this breakpoint."), | |
1052 | ext_lang_capitalized_name (extlang)); | |
1053 | } | |
2566ad2d | 1054 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1055 | |
1056 | if (is_breakpoint (b)) | |
1057 | update_global_location_list (1); | |
1058 | ||
2f069f6f JB |
1059 | return; |
1060 | } | |
c906108c | 1061 | |
8a3fe4f8 | 1062 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1063 | } |
1064 | ||
a7bdde9e VP |
1065 | /* Check that COMMAND do not contain commands that are suitable |
1066 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1067 | Throw if any such commands is found. */ |
1068 | ||
a7bdde9e VP |
1069 | static void |
1070 | check_no_tracepoint_commands (struct command_line *commands) | |
1071 | { | |
1072 | struct command_line *c; | |
cc59ec59 | 1073 | |
a7bdde9e VP |
1074 | for (c = commands; c; c = c->next) |
1075 | { | |
1076 | int i; | |
1077 | ||
1078 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1079 | error (_("The 'while-stepping' command can " |
1080 | "only be used for tracepoints")); | |
a7bdde9e VP |
1081 | |
1082 | for (i = 0; i < c->body_count; ++i) | |
1083 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1084 | ||
1085 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1086 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1087 | command directly. */ |
1088 | if (strstr (c->line, "collect ") == c->line) | |
1089 | error (_("The 'collect' command can only be used for tracepoints")); | |
1090 | ||
51661e93 VP |
1091 | if (strstr (c->line, "teval ") == c->line) |
1092 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1093 | } |
1094 | } | |
1095 | ||
d77f58be SS |
1096 | /* Encapsulate tests for different types of tracepoints. */ |
1097 | ||
d9b3f62e PA |
1098 | static int |
1099 | is_tracepoint_type (enum bptype type) | |
1100 | { | |
1101 | return (type == bp_tracepoint | |
1102 | || type == bp_fast_tracepoint | |
1103 | || type == bp_static_tracepoint); | |
1104 | } | |
1105 | ||
a7bdde9e | 1106 | int |
d77f58be | 1107 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1108 | { |
d9b3f62e | 1109 | return is_tracepoint_type (b->type); |
a7bdde9e | 1110 | } |
d9b3f62e | 1111 | |
e5dd4106 | 1112 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1113 | breakpoint. This function will throw an exception if a problem is |
1114 | found. */ | |
48cb2d85 | 1115 | |
95a42b64 TT |
1116 | static void |
1117 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1118 | struct command_line *commands) | |
48cb2d85 | 1119 | { |
d77f58be | 1120 | if (is_tracepoint (b)) |
a7bdde9e | 1121 | { |
c9a6ce02 | 1122 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1123 | struct command_line *c; |
1124 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1125 | |
1126 | /* Reset the while-stepping step count. The previous commands | |
1127 | might have included a while-stepping action, while the new | |
1128 | ones might not. */ | |
1129 | t->step_count = 0; | |
1130 | ||
1131 | /* We need to verify that each top-level element of commands is | |
1132 | valid for tracepoints, that there's at most one | |
1133 | while-stepping element, and that the while-stepping's body | |
1134 | has valid tracing commands excluding nested while-stepping. | |
1135 | We also need to validate the tracepoint action line in the | |
1136 | context of the tracepoint --- validate_actionline actually | |
1137 | has side effects, like setting the tracepoint's | |
1138 | while-stepping STEP_COUNT, in addition to checking if the | |
1139 | collect/teval actions parse and make sense in the | |
1140 | tracepoint's context. */ | |
a7bdde9e VP |
1141 | for (c = commands; c; c = c->next) |
1142 | { | |
a7bdde9e VP |
1143 | if (c->control_type == while_stepping_control) |
1144 | { | |
1145 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1146 | error (_("The 'while-stepping' command " |
1147 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1148 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1149 | error (_("The 'while-stepping' command " |
1150 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1151 | |
1152 | if (while_stepping) | |
3e43a32a MS |
1153 | error (_("The 'while-stepping' command " |
1154 | "can be used only once")); | |
a7bdde9e VP |
1155 | else |
1156 | while_stepping = c; | |
1157 | } | |
c9a6ce02 PA |
1158 | |
1159 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1160 | } |
1161 | if (while_stepping) | |
1162 | { | |
1163 | struct command_line *c2; | |
1164 | ||
1165 | gdb_assert (while_stepping->body_count == 1); | |
1166 | c2 = while_stepping->body_list[0]; | |
1167 | for (; c2; c2 = c2->next) | |
1168 | { | |
a7bdde9e VP |
1169 | if (c2->control_type == while_stepping_control) |
1170 | error (_("The 'while-stepping' command cannot be nested")); | |
1171 | } | |
1172 | } | |
1173 | } | |
1174 | else | |
1175 | { | |
1176 | check_no_tracepoint_commands (commands); | |
1177 | } | |
95a42b64 TT |
1178 | } |
1179 | ||
0fb4aa4b PA |
1180 | /* Return a vector of all the static tracepoints set at ADDR. The |
1181 | caller is responsible for releasing the vector. */ | |
1182 | ||
1183 | VEC(breakpoint_p) * | |
1184 | static_tracepoints_here (CORE_ADDR addr) | |
1185 | { | |
1186 | struct breakpoint *b; | |
1187 | VEC(breakpoint_p) *found = 0; | |
1188 | struct bp_location *loc; | |
1189 | ||
1190 | ALL_BREAKPOINTS (b) | |
1191 | if (b->type == bp_static_tracepoint) | |
1192 | { | |
1193 | for (loc = b->loc; loc; loc = loc->next) | |
1194 | if (loc->address == addr) | |
1195 | VEC_safe_push(breakpoint_p, found, b); | |
1196 | } | |
1197 | ||
1198 | return found; | |
1199 | } | |
1200 | ||
95a42b64 | 1201 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1202 | validate that only allowed commands are included. */ |
95a42b64 TT |
1203 | |
1204 | void | |
4a64f543 MS |
1205 | breakpoint_set_commands (struct breakpoint *b, |
1206 | struct command_line *commands) | |
95a42b64 TT |
1207 | { |
1208 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1209 | |
9add0f1b TT |
1210 | decref_counted_command_line (&b->commands); |
1211 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1212 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1213 | } |
1214 | ||
45a43567 TT |
1215 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1216 | is not the same as the "silent" that may appear in the breakpoint's | |
1217 | commands. */ | |
1218 | ||
1219 | void | |
1220 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1221 | { | |
1222 | int old_silent = b->silent; | |
1223 | ||
1224 | b->silent = silent; | |
1225 | if (old_silent != silent) | |
8d3788bd | 1226 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1227 | } |
1228 | ||
1229 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1230 | breakpoint work for any thread. */ | |
1231 | ||
1232 | void | |
1233 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1234 | { | |
1235 | int old_thread = b->thread; | |
1236 | ||
1237 | b->thread = thread; | |
1238 | if (old_thread != thread) | |
8d3788bd | 1239 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1240 | } |
1241 | ||
1242 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1243 | breakpoint work for any task. */ | |
1244 | ||
1245 | void | |
1246 | breakpoint_set_task (struct breakpoint *b, int task) | |
1247 | { | |
1248 | int old_task = b->task; | |
1249 | ||
1250 | b->task = task; | |
1251 | if (old_task != task) | |
8d3788bd | 1252 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1253 | } |
1254 | ||
95a42b64 TT |
1255 | void |
1256 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1257 | { |
1258 | struct breakpoint *b = closure; | |
cc59ec59 | 1259 | |
6f937416 | 1260 | validate_actionline (line, b); |
a7bdde9e VP |
1261 | } |
1262 | ||
95a42b64 TT |
1263 | /* A structure used to pass information through |
1264 | map_breakpoint_numbers. */ | |
1265 | ||
1266 | struct commands_info | |
1267 | { | |
1268 | /* True if the command was typed at a tty. */ | |
1269 | int from_tty; | |
86b17b60 PA |
1270 | |
1271 | /* The breakpoint range spec. */ | |
1272 | char *arg; | |
1273 | ||
95a42b64 TT |
1274 | /* Non-NULL if the body of the commands are being read from this |
1275 | already-parsed command. */ | |
1276 | struct command_line *control; | |
86b17b60 | 1277 | |
95a42b64 TT |
1278 | /* The command lines read from the user, or NULL if they have not |
1279 | yet been read. */ | |
1280 | struct counted_command_line *cmd; | |
1281 | }; | |
1282 | ||
1283 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1284 | commands_command. */ | |
1285 | ||
c906108c | 1286 | static void |
95a42b64 | 1287 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1288 | { |
95a42b64 | 1289 | struct commands_info *info = data; |
c906108c | 1290 | |
95a42b64 TT |
1291 | if (info->cmd == NULL) |
1292 | { | |
1293 | struct command_line *l; | |
5c44784c | 1294 | |
95a42b64 TT |
1295 | if (info->control != NULL) |
1296 | l = copy_command_lines (info->control->body_list[0]); | |
1297 | else | |
86b17b60 PA |
1298 | { |
1299 | struct cleanup *old_chain; | |
1300 | char *str; | |
c5aa993b | 1301 | |
3e43a32a MS |
1302 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1303 | "%s, one per line."), | |
86b17b60 PA |
1304 | info->arg); |
1305 | ||
1306 | old_chain = make_cleanup (xfree, str); | |
1307 | ||
1308 | l = read_command_lines (str, | |
1309 | info->from_tty, 1, | |
d77f58be | 1310 | (is_tracepoint (b) |
86b17b60 PA |
1311 | ? check_tracepoint_command : 0), |
1312 | b); | |
1313 | ||
1314 | do_cleanups (old_chain); | |
1315 | } | |
a7bdde9e | 1316 | |
95a42b64 TT |
1317 | info->cmd = alloc_counted_command_line (l); |
1318 | } | |
1319 | ||
1320 | /* If a breakpoint was on the list more than once, we don't need to | |
1321 | do anything. */ | |
1322 | if (b->commands != info->cmd) | |
1323 | { | |
1324 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1325 | incref_counted_command_line (info->cmd); | |
1326 | decref_counted_command_line (&b->commands); | |
1327 | b->commands = info->cmd; | |
8d3788bd | 1328 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1329 | } |
95a42b64 TT |
1330 | } |
1331 | ||
1332 | static void | |
4a64f543 MS |
1333 | commands_command_1 (char *arg, int from_tty, |
1334 | struct command_line *control) | |
95a42b64 TT |
1335 | { |
1336 | struct cleanup *cleanups; | |
1337 | struct commands_info info; | |
1338 | ||
1339 | info.from_tty = from_tty; | |
1340 | info.control = control; | |
1341 | info.cmd = NULL; | |
1342 | /* If we read command lines from the user, then `info' will hold an | |
1343 | extra reference to the commands that we must clean up. */ | |
1344 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1345 | ||
1346 | if (arg == NULL || !*arg) | |
1347 | { | |
86b17b60 | 1348 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1349 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1350 | breakpoint_count); | |
95a42b64 TT |
1351 | else if (breakpoint_count > 0) |
1352 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1353 | else |
1354 | { | |
1355 | /* So that we don't try to free the incoming non-NULL | |
1356 | argument in the cleanup below. Mapping breakpoint | |
1357 | numbers will fail in this case. */ | |
1358 | arg = NULL; | |
1359 | } | |
95a42b64 | 1360 | } |
9766ced4 SS |
1361 | else |
1362 | /* The command loop has some static state, so we need to preserve | |
1363 | our argument. */ | |
1364 | arg = xstrdup (arg); | |
86b17b60 PA |
1365 | |
1366 | if (arg != NULL) | |
1367 | make_cleanup (xfree, arg); | |
1368 | ||
1369 | info.arg = arg; | |
95a42b64 TT |
1370 | |
1371 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1372 | ||
1373 | if (info.cmd == NULL) | |
1374 | error (_("No breakpoints specified.")); | |
1375 | ||
1376 | do_cleanups (cleanups); | |
1377 | } | |
1378 | ||
1379 | static void | |
1380 | commands_command (char *arg, int from_tty) | |
1381 | { | |
1382 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1383 | } |
40c03ae8 EZ |
1384 | |
1385 | /* Like commands_command, but instead of reading the commands from | |
1386 | input stream, takes them from an already parsed command structure. | |
1387 | ||
1388 | This is used by cli-script.c to DTRT with breakpoint commands | |
1389 | that are part of if and while bodies. */ | |
1390 | enum command_control_type | |
1391 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1392 | { | |
95a42b64 TT |
1393 | commands_command_1 (arg, 0, cmd); |
1394 | return simple_control; | |
40c03ae8 | 1395 | } |
876fa593 JK |
1396 | |
1397 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1398 | ||
1399 | static int | |
1400 | bp_location_has_shadow (struct bp_location *bl) | |
1401 | { | |
1402 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1403 | return 0; | |
1404 | if (!bl->inserted) | |
1405 | return 0; | |
1406 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1407 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1408 | return 0; |
1409 | return 1; | |
1410 | } | |
1411 | ||
8defab1a | 1412 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1413 | by replacing any memory breakpoints with their shadowed contents. |
1414 | ||
35c63cd8 JB |
1415 | If READBUF is not NULL, this buffer must not overlap with any of |
1416 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1417 | a failed assertion internal error will be raised. | |
1418 | ||
876fa593 | 1419 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1420 | bl->address - bp_location_placed_address_before_address_max |
1421 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1422 | The range we were requested to resolve shadows for is: |
1423 | memaddr ... memaddr + len | |
1424 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1425 | memaddr + len <= (bl->address |
1426 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1427 | and: |
35df4500 | 1428 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1429 | |
8defab1a | 1430 | void |
f0ba3972 PA |
1431 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1432 | const gdb_byte *writebuf_org, | |
1433 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1434 | { |
4a64f543 MS |
1435 | /* Left boundary, right boundary and median element of our binary |
1436 | search. */ | |
876fa593 JK |
1437 | unsigned bc_l, bc_r, bc; |
1438 | ||
4a64f543 MS |
1439 | /* Find BC_L which is a leftmost element which may affect BUF |
1440 | content. It is safe to report lower value but a failure to | |
1441 | report higher one. */ | |
876fa593 JK |
1442 | |
1443 | bc_l = 0; | |
1444 | bc_r = bp_location_count; | |
1445 | while (bc_l + 1 < bc_r) | |
1446 | { | |
35df4500 | 1447 | struct bp_location *bl; |
876fa593 JK |
1448 | |
1449 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1450 | bl = bp_location[bc]; |
876fa593 | 1451 | |
4a64f543 MS |
1452 | /* Check first BL->ADDRESS will not overflow due to the added |
1453 | constant. Then advance the left boundary only if we are sure | |
1454 | the BC element can in no way affect the BUF content (MEMADDR | |
1455 | to MEMADDR + LEN range). | |
876fa593 | 1456 | |
4a64f543 MS |
1457 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1458 | offset so that we cannot miss a breakpoint with its shadow | |
1459 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1460 | |
35df4500 TJB |
1461 | if ((bl->address + bp_location_shadow_len_after_address_max |
1462 | >= bl->address) | |
1463 | && (bl->address + bp_location_shadow_len_after_address_max | |
1464 | <= memaddr)) | |
876fa593 JK |
1465 | bc_l = bc; |
1466 | else | |
1467 | bc_r = bc; | |
1468 | } | |
1469 | ||
128070bb PA |
1470 | /* Due to the binary search above, we need to make sure we pick the |
1471 | first location that's at BC_L's address. E.g., if there are | |
1472 | multiple locations at the same address, BC_L may end up pointing | |
1473 | at a duplicate location, and miss the "master"/"inserted" | |
1474 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1475 | B: | |
1476 | ||
1477 | L1@A, L2@A, L3@B, ... | |
1478 | ||
1479 | BC_L could end up pointing at location L2, while the "master" | |
1480 | location could be L1. Since the `loc->inserted' flag is only set | |
1481 | on "master" locations, we'd forget to restore the shadow of L1 | |
1482 | and L2. */ | |
1483 | while (bc_l > 0 | |
1484 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1485 | bc_l--; | |
1486 | ||
876fa593 JK |
1487 | /* Now do full processing of the found relevant range of elements. */ |
1488 | ||
1489 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1490 | { |
35df4500 | 1491 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1492 | CORE_ADDR bp_addr = 0; |
1493 | int bp_size = 0; | |
1494 | int bptoffset = 0; | |
1495 | ||
35df4500 TJB |
1496 | /* bp_location array has BL->OWNER always non-NULL. */ |
1497 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1498 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1499 | bl->owner->number); |
ffce0d52 | 1500 | |
e5dd4106 | 1501 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1502 | content. */ |
1503 | ||
35df4500 TJB |
1504 | if (bl->address >= bp_location_placed_address_before_address_max |
1505 | && memaddr + len <= (bl->address | |
1506 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1507 | break; |
1508 | ||
35df4500 | 1509 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1510 | continue; |
35df4500 | 1511 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1512 | current_program_space->aspace, 0)) |
1513 | continue; | |
1514 | ||
c5aa993b JM |
1515 | /* Addresses and length of the part of the breakpoint that |
1516 | we need to copy. */ | |
35df4500 TJB |
1517 | bp_addr = bl->target_info.placed_address; |
1518 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1519 | |
c5aa993b JM |
1520 | if (bp_addr + bp_size <= memaddr) |
1521 | /* The breakpoint is entirely before the chunk of memory we | |
1522 | are reading. */ | |
1523 | continue; | |
8defab1a | 1524 | |
c5aa993b JM |
1525 | if (bp_addr >= memaddr + len) |
1526 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1527 | reading. */ |
c5aa993b | 1528 | continue; |
c5aa993b | 1529 | |
8defab1a DJ |
1530 | /* Offset within shadow_contents. */ |
1531 | if (bp_addr < memaddr) | |
1532 | { | |
1533 | /* Only copy the second part of the breakpoint. */ | |
1534 | bp_size -= memaddr - bp_addr; | |
1535 | bptoffset = memaddr - bp_addr; | |
1536 | bp_addr = memaddr; | |
1537 | } | |
c5aa993b | 1538 | |
8defab1a DJ |
1539 | if (bp_addr + bp_size > memaddr + len) |
1540 | { | |
1541 | /* Only copy the first part of the breakpoint. */ | |
1542 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1543 | } | |
c5aa993b | 1544 | |
f0ba3972 PA |
1545 | if (readbuf != NULL) |
1546 | { | |
35c63cd8 JB |
1547 | /* Verify that the readbuf buffer does not overlap with |
1548 | the shadow_contents buffer. */ | |
1549 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1550 | || readbuf >= (bl->target_info.shadow_contents | |
1551 | + bl->target_info.shadow_len)); | |
1552 | ||
f0ba3972 PA |
1553 | /* Update the read buffer with this inserted breakpoint's |
1554 | shadow. */ | |
1555 | memcpy (readbuf + bp_addr - memaddr, | |
1556 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1557 | } | |
1558 | else | |
1559 | { | |
1560 | struct gdbarch *gdbarch = bl->gdbarch; | |
1561 | const unsigned char *bp; | |
1562 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
20ced3e4 | 1563 | int placed_size = bl->target_info.placed_size; |
f0ba3972 PA |
1564 | |
1565 | /* Update the shadow with what we want to write to memory. */ | |
1566 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1567 | writebuf_org + bp_addr - memaddr, bp_size); | |
1568 | ||
1569 | /* Determine appropriate breakpoint contents and size for this | |
1570 | address. */ | |
1571 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1572 | ||
1573 | /* Update the final write buffer with this inserted | |
1574 | breakpoint's INSN. */ | |
1575 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1576 | } | |
c5aa993b | 1577 | } |
c906108c | 1578 | } |
c906108c | 1579 | \f |
c5aa993b | 1580 | |
b775012e LM |
1581 | /* Return true if BPT is either a software breakpoint or a hardware |
1582 | breakpoint. */ | |
1583 | ||
1584 | int | |
1585 | is_breakpoint (const struct breakpoint *bpt) | |
1586 | { | |
1587 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1588 | || bpt->type == bp_hardware_breakpoint |
1589 | || bpt->type == bp_dprintf); | |
b775012e LM |
1590 | } |
1591 | ||
60e1c644 PA |
1592 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1593 | ||
a5606eee | 1594 | static int |
d77f58be | 1595 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1596 | { |
1597 | return (bpt->type == bp_hardware_watchpoint | |
1598 | || bpt->type == bp_read_watchpoint | |
1599 | || bpt->type == bp_access_watchpoint); | |
1600 | } | |
7270d8f2 | 1601 | |
60e1c644 PA |
1602 | /* Return true if BPT is of any watchpoint kind, hardware or |
1603 | software. */ | |
1604 | ||
3a5c3e22 | 1605 | int |
d77f58be | 1606 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1607 | { |
1608 | return (is_hardware_watchpoint (bpt) | |
1609 | || bpt->type == bp_watchpoint); | |
1610 | } | |
1611 | ||
3a5c3e22 PA |
1612 | /* Returns true if the current thread and its running state are safe |
1613 | to evaluate or update watchpoint B. Watchpoints on local | |
1614 | expressions need to be evaluated in the context of the thread that | |
1615 | was current when the watchpoint was created, and, that thread needs | |
1616 | to be stopped to be able to select the correct frame context. | |
1617 | Watchpoints on global expressions can be evaluated on any thread, | |
1618 | and in any state. It is presently left to the target allowing | |
1619 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1620 | |
1621 | static int | |
3a5c3e22 | 1622 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1623 | { |
d0d8b0c6 JK |
1624 | return (b->base.pspace == current_program_space |
1625 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1626 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1627 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1628 | } |
1629 | ||
d0fb5eae JK |
1630 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1631 | associated bp_watchpoint_scope breakpoint. */ | |
1632 | ||
1633 | static void | |
3a5c3e22 | 1634 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1635 | { |
3a5c3e22 | 1636 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1637 | |
1638 | if (b->related_breakpoint != b) | |
1639 | { | |
1640 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1641 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1642 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1643 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1644 | b->related_breakpoint = b; | |
1645 | } | |
1646 | b->disposition = disp_del_at_next_stop; | |
1647 | } | |
1648 | ||
567e1b4e JB |
1649 | /* Assuming that B is a watchpoint: |
1650 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1651 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1652 | - Evaluate the condition if there is one, and store the result |
1653 | in b->loc->cond. | |
a5606eee VP |
1654 | - Update the list of values that must be watched in B->loc. |
1655 | ||
4a64f543 MS |
1656 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1657 | nothing. If this is local watchpoint that is out of scope, delete | |
1658 | it. | |
1659 | ||
1660 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1661 | removed + inserted on each stop here. Normal breakpoints must | |
1662 | never be removed because they might be missed by a running thread | |
1663 | when debugging in non-stop mode. On the other hand, hardware | |
1664 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1665 | to each LWP since they are stored in each LWP's hardware debug | |
1666 | registers. Therefore, such LWP must be stopped first in order to | |
1667 | be able to modify its hardware watchpoints. | |
1668 | ||
1669 | Hardware watchpoints must be reset exactly once after being | |
1670 | presented to the user. It cannot be done sooner, because it would | |
1671 | reset the data used to present the watchpoint hit to the user. And | |
1672 | it must not be done later because it could display the same single | |
1673 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1674 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1675 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1676 | not user-visible - its hit is suppressed if the memory content has | |
1677 | not changed. | |
1678 | ||
1679 | The following constraints influence the location where we can reset | |
1680 | hardware watchpoints: | |
1681 | ||
1682 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1683 | called several times when GDB stops. | |
1684 | ||
1685 | [linux] | |
1686 | * Multiple hardware watchpoints can be hit at the same time, | |
1687 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1688 | hit at a time as the reason for stopping, and all the other hits | |
1689 | are presented later, one after the other, each time the user | |
1690 | requests the execution to be resumed. Execution is not resumed | |
1691 | for the threads still having pending hit event stored in | |
1692 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1693 | the inferior on the first stop the thread hit event is kept being | |
1694 | reported from its cached value by linux_nat_stopped_data_address | |
1695 | until the real thread resume happens after the watchpoint gets | |
1696 | presented and thus its LWP_INFO->STATUS gets reset. | |
1697 | ||
1698 | Therefore the hardware watchpoint hit can get safely reset on the | |
1699 | watchpoint removal from inferior. */ | |
a79d3c27 | 1700 | |
b40ce68a | 1701 | static void |
3a5c3e22 | 1702 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1703 | { |
a5606eee | 1704 | int within_current_scope; |
a5606eee | 1705 | struct frame_id saved_frame_id; |
66076460 | 1706 | int frame_saved; |
a5606eee | 1707 | |
f6bc2008 PA |
1708 | /* If this is a local watchpoint, we only want to check if the |
1709 | watchpoint frame is in scope if the current thread is the thread | |
1710 | that was used to create the watchpoint. */ | |
1711 | if (!watchpoint_in_thread_scope (b)) | |
1712 | return; | |
1713 | ||
3a5c3e22 | 1714 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1715 | return; |
1716 | ||
66076460 | 1717 | frame_saved = 0; |
a5606eee VP |
1718 | |
1719 | /* Determine if the watchpoint is within scope. */ | |
1720 | if (b->exp_valid_block == NULL) | |
1721 | within_current_scope = 1; | |
1722 | else | |
1723 | { | |
b5db5dfc UW |
1724 | struct frame_info *fi = get_current_frame (); |
1725 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1726 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1727 | ||
1728 | /* If we're in a function epilogue, unwinding may not work | |
1729 | properly, so do not attempt to recreate locations at this | |
1730 | point. See similar comments in watchpoint_check. */ | |
1731 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1732 | return; | |
66076460 DJ |
1733 | |
1734 | /* Save the current frame's ID so we can restore it after | |
1735 | evaluating the watchpoint expression on its own frame. */ | |
1736 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1737 | took a frame parameter, so that we didn't have to change the | |
1738 | selected frame. */ | |
1739 | frame_saved = 1; | |
1740 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1741 | ||
a5606eee VP |
1742 | fi = frame_find_by_id (b->watchpoint_frame); |
1743 | within_current_scope = (fi != NULL); | |
1744 | if (within_current_scope) | |
1745 | select_frame (fi); | |
1746 | } | |
1747 | ||
b5db5dfc UW |
1748 | /* We don't free locations. They are stored in the bp_location array |
1749 | and update_global_location_list will eventually delete them and | |
1750 | remove breakpoints if needed. */ | |
3a5c3e22 | 1751 | b->base.loc = NULL; |
b5db5dfc | 1752 | |
a5606eee VP |
1753 | if (within_current_scope && reparse) |
1754 | { | |
bbc13ae3 | 1755 | const char *s; |
d63d0675 | 1756 | |
a5606eee VP |
1757 | if (b->exp) |
1758 | { | |
1759 | xfree (b->exp); | |
1760 | b->exp = NULL; | |
1761 | } | |
d63d0675 | 1762 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1763 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1764 | /* If the meaning of expression itself changed, the old value is |
1765 | no longer relevant. We don't want to report a watchpoint hit | |
1766 | to the user when the old value and the new value may actually | |
1767 | be completely different objects. */ | |
1768 | value_free (b->val); | |
fa4727a6 DJ |
1769 | b->val = NULL; |
1770 | b->val_valid = 0; | |
60e1c644 PA |
1771 | |
1772 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1773 | expression is stored in the breakpoint object, not in the | |
1774 | locations (re)created below. */ | |
3a5c3e22 | 1775 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1776 | { |
1777 | if (b->cond_exp != NULL) | |
1778 | { | |
1779 | xfree (b->cond_exp); | |
1780 | b->cond_exp = NULL; | |
1781 | } | |
1782 | ||
3a5c3e22 | 1783 | s = b->base.cond_string; |
1bb9788d | 1784 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1785 | } |
a5606eee | 1786 | } |
a5606eee VP |
1787 | |
1788 | /* If we failed to parse the expression, for example because | |
1789 | it refers to a global variable in a not-yet-loaded shared library, | |
1790 | don't try to insert watchpoint. We don't automatically delete | |
1791 | such watchpoint, though, since failure to parse expression | |
1792 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1793 | if (!target_has_execution) |
2d134ed3 PA |
1794 | { |
1795 | /* Without execution, memory can't change. No use to try and | |
1796 | set watchpoint locations. The watchpoint will be reset when | |
1797 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1798 | if (!can_use_hw_watchpoints) |
1799 | { | |
1800 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1801 | b->base.type = bp_watchpoint; | |
1802 | else | |
638aa5a1 AB |
1803 | error (_("Can't set read/access watchpoint when " |
1804 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1805 | } |
2d134ed3 PA |
1806 | } |
1807 | else if (within_current_scope && b->exp) | |
a5606eee | 1808 | { |
0cf6dd15 | 1809 | int pc = 0; |
fa4727a6 | 1810 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1811 | struct program_space *frame_pspace; |
a5606eee | 1812 | |
3a1115a0 | 1813 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1814 | |
a5606eee VP |
1815 | /* Avoid setting b->val if it's already set. The meaning of |
1816 | b->val is 'the last value' user saw, and we should update | |
1817 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1818 | happens, the code that reports it updates b->val directly. |
1819 | We don't keep track of the memory value for masked | |
1820 | watchpoints. */ | |
3a5c3e22 | 1821 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1822 | { |
1823 | b->val = v; | |
1824 | b->val_valid = 1; | |
1825 | } | |
a5606eee | 1826 | |
2d134ed3 PA |
1827 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1828 | ||
a5606eee | 1829 | /* Look at each value on the value chain. */ |
9fa40276 | 1830 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1831 | { |
1832 | /* If it's a memory location, and GDB actually needed | |
1833 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1834 | must watch it. If the first value returned is |
1835 | still lazy, that means an error occurred reading it; | |
1836 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1837 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1838 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1839 | { |
1840 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1841 | |
a5606eee VP |
1842 | /* We only watch structs and arrays if user asked |
1843 | for it explicitly, never if they just happen to | |
1844 | appear in the middle of some value chain. */ | |
fa4727a6 | 1845 | if (v == result |
a5606eee VP |
1846 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1847 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1848 | { | |
1849 | CORE_ADDR addr; | |
744a8059 | 1850 | int type; |
a5606eee VP |
1851 | struct bp_location *loc, **tmp; |
1852 | ||
42ae5230 | 1853 | addr = value_address (v); |
a5606eee | 1854 | type = hw_write; |
3a5c3e22 | 1855 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1856 | type = hw_read; |
3a5c3e22 | 1857 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1858 | type = hw_access; |
3a5c3e22 PA |
1859 | |
1860 | loc = allocate_bp_location (&b->base); | |
1861 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1862 | ; |
1863 | *tmp = loc; | |
a6d9a66e | 1864 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1865 | |
1866 | loc->pspace = frame_pspace; | |
a5606eee | 1867 | loc->address = addr; |
744a8059 | 1868 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1869 | loc->watchpoint_type = type; |
1870 | } | |
1871 | } | |
9fa40276 TJB |
1872 | } |
1873 | ||
1874 | /* Change the type of breakpoint between hardware assisted or | |
1875 | an ordinary watchpoint depending on the hardware support | |
1876 | and free hardware slots. REPARSE is set when the inferior | |
1877 | is started. */ | |
a9634178 | 1878 | if (reparse) |
9fa40276 | 1879 | { |
e09342b5 | 1880 | int reg_cnt; |
9fa40276 TJB |
1881 | enum bp_loc_type loc_type; |
1882 | struct bp_location *bl; | |
a5606eee | 1883 | |
a9634178 | 1884 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1885 | |
1886 | if (reg_cnt) | |
9fa40276 TJB |
1887 | { |
1888 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1889 | enum bptype type; |
9fa40276 | 1890 | |
a9634178 TJB |
1891 | /* Use an exact watchpoint when there's only one memory region to be |
1892 | watched, and only one debug register is needed to watch it. */ | |
1893 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1894 | ||
9fa40276 | 1895 | /* We need to determine how many resources are already |
e09342b5 TJB |
1896 | used for all other hardware watchpoints plus this one |
1897 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1898 | this watchpoint in as well. */ |
1899 | ||
1900 | /* If this is a software watchpoint, we try to turn it | |
1901 | to a hardware one -- count resources as if B was of | |
1902 | hardware watchpoint type. */ | |
1903 | type = b->base.type; | |
1904 | if (type == bp_watchpoint) | |
1905 | type = bp_hardware_watchpoint; | |
1906 | ||
1907 | /* This watchpoint may or may not have been placed on | |
1908 | the list yet at this point (it won't be in the list | |
1909 | if we're trying to create it for the first time, | |
1910 | through watch_command), so always account for it | |
1911 | manually. */ | |
1912 | ||
1913 | /* Count resources used by all watchpoints except B. */ | |
1914 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1915 | ||
1916 | /* Add in the resources needed for B. */ | |
1917 | i += hw_watchpoint_use_count (&b->base); | |
1918 | ||
1919 | target_resources_ok | |
1920 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1921 | if (target_resources_ok <= 0) |
a9634178 | 1922 | { |
3a5c3e22 | 1923 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1924 | |
1925 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1926 | error (_("Target does not support this type of " |
1927 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1928 | else if (target_resources_ok < 0 && !sw_mode) |
1929 | error (_("There are not enough available hardware " | |
1930 | "resources for this watchpoint.")); | |
a1398e0c PA |
1931 | |
1932 | /* Downgrade to software watchpoint. */ | |
1933 | b->base.type = bp_watchpoint; | |
1934 | } | |
1935 | else | |
1936 | { | |
1937 | /* If this was a software watchpoint, we've just | |
1938 | found we have enough resources to turn it to a | |
1939 | hardware watchpoint. Otherwise, this is a | |
1940 | nop. */ | |
1941 | b->base.type = type; | |
a9634178 | 1942 | } |
9fa40276 | 1943 | } |
3a5c3e22 | 1944 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
1945 | { |
1946 | if (!can_use_hw_watchpoints) | |
1947 | error (_("Can't set read/access watchpoint when " | |
1948 | "hardware watchpoints are disabled.")); | |
1949 | else | |
1950 | error (_("Expression cannot be implemented with " | |
1951 | "read/access watchpoint.")); | |
1952 | } | |
9fa40276 | 1953 | else |
3a5c3e22 | 1954 | b->base.type = bp_watchpoint; |
9fa40276 | 1955 | |
3a5c3e22 | 1956 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1957 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1958 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1959 | bl->loc_type = loc_type; |
1960 | } | |
1961 | ||
1962 | for (v = val_chain; v; v = next) | |
1963 | { | |
a5606eee VP |
1964 | next = value_next (v); |
1965 | if (v != b->val) | |
1966 | value_free (v); | |
1967 | } | |
1968 | ||
c7437ca6 PA |
1969 | /* If a software watchpoint is not watching any memory, then the |
1970 | above left it without any location set up. But, | |
1971 | bpstat_stop_status requires a location to be able to report | |
1972 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1973 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1974 | { |
3a5c3e22 PA |
1975 | struct breakpoint *base = &b->base; |
1976 | base->loc = allocate_bp_location (base); | |
1977 | base->loc->pspace = frame_pspace; | |
1978 | base->loc->address = -1; | |
1979 | base->loc->length = -1; | |
1980 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1981 | } |
a5606eee VP |
1982 | } |
1983 | else if (!within_current_scope) | |
7270d8f2 | 1984 | { |
ac74f770 MS |
1985 | printf_filtered (_("\ |
1986 | Watchpoint %d deleted because the program has left the block\n\ | |
1987 | in which its expression is valid.\n"), | |
3a5c3e22 | 1988 | b->base.number); |
d0fb5eae | 1989 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1990 | } |
a5606eee VP |
1991 | |
1992 | /* Restore the selected frame. */ | |
66076460 DJ |
1993 | if (frame_saved) |
1994 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1995 | } |
1996 | ||
a5606eee | 1997 | |
74960c60 | 1998 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1999 | inserted in the inferior. We don't differentiate the type of BL's owner |
2000 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2001 | breakpoint_ops is not defined, because in insert_bp_location, | |
2002 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2003 | static int |
35df4500 | 2004 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2005 | { |
35df4500 | 2006 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2007 | return 0; |
2008 | ||
35df4500 | 2009 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2010 | return 0; |
2011 | ||
35df4500 | 2012 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2013 | return 0; |
2014 | ||
f8eba3c6 TT |
2015 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2016 | return 0; | |
2017 | ||
56710373 PA |
2018 | /* This is set for example, when we're attached to the parent of a |
2019 | vfork, and have detached from the child. The child is running | |
2020 | free, and we expect it to do an exec or exit, at which point the | |
2021 | OS makes the parent schedulable again (and the target reports | |
2022 | that the vfork is done). Until the child is done with the shared | |
2023 | memory region, do not insert breakpoints in the parent, otherwise | |
2024 | the child could still trip on the parent's breakpoints. Since | |
2025 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2026 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2027 | return 0; |
2028 | ||
31e77af2 PA |
2029 | /* Don't insert a breakpoint if we're trying to step past its |
2030 | location. */ | |
2031 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2032 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2033 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2034 | bl->address)) | |
2035 | return 0; | |
2036 | ||
74960c60 VP |
2037 | return 1; |
2038 | } | |
2039 | ||
934709f0 PW |
2040 | /* Same as should_be_inserted but does the check assuming |
2041 | that the location is not duplicated. */ | |
2042 | ||
2043 | static int | |
2044 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2045 | { | |
2046 | int result; | |
2047 | const int save_duplicate = bl->duplicate; | |
2048 | ||
2049 | bl->duplicate = 0; | |
2050 | result = should_be_inserted (bl); | |
2051 | bl->duplicate = save_duplicate; | |
2052 | return result; | |
2053 | } | |
2054 | ||
b775012e LM |
2055 | /* Parses a conditional described by an expression COND into an |
2056 | agent expression bytecode suitable for evaluation | |
2057 | by the bytecode interpreter. Return NULL if there was | |
2058 | any error during parsing. */ | |
2059 | ||
2060 | static struct agent_expr * | |
2061 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2062 | { | |
2063 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2064 | volatile struct gdb_exception ex; |
2065 | ||
2066 | if (!cond) | |
2067 | return NULL; | |
2068 | ||
2069 | /* We don't want to stop processing, so catch any errors | |
2070 | that may show up. */ | |
2071 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2072 | { | |
2073 | aexpr = gen_eval_for_expr (scope, cond); | |
2074 | } | |
2075 | ||
2076 | if (ex.reason < 0) | |
2077 | { | |
2078 | /* If we got here, it means the condition could not be parsed to a valid | |
2079 | bytecode expression and thus can't be evaluated on the target's side. | |
2080 | It's no use iterating through the conditions. */ | |
2081 | return NULL; | |
2082 | } | |
2083 | ||
2084 | /* We have a valid agent expression. */ | |
2085 | return aexpr; | |
2086 | } | |
2087 | ||
2088 | /* Based on location BL, create a list of breakpoint conditions to be | |
2089 | passed on to the target. If we have duplicated locations with different | |
2090 | conditions, we will add such conditions to the list. The idea is that the | |
2091 | target will evaluate the list of conditions and will only notify GDB when | |
2092 | one of them is true. */ | |
2093 | ||
2094 | static void | |
2095 | build_target_condition_list (struct bp_location *bl) | |
2096 | { | |
2097 | struct bp_location **locp = NULL, **loc2p; | |
2098 | int null_condition_or_parse_error = 0; | |
2099 | int modified = bl->needs_update; | |
2100 | struct bp_location *loc; | |
2101 | ||
8b4f3082 PA |
2102 | /* Release conditions left over from a previous insert. */ |
2103 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2104 | ||
b775012e LM |
2105 | /* This is only meaningful if the target is |
2106 | evaluating conditions and if the user has | |
2107 | opted for condition evaluation on the target's | |
2108 | side. */ | |
2109 | if (gdb_evaluates_breakpoint_condition_p () | |
2110 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2111 | return; | |
2112 | ||
2113 | /* Do a first pass to check for locations with no assigned | |
2114 | conditions or conditions that fail to parse to a valid agent expression | |
2115 | bytecode. If any of these happen, then it's no use to send conditions | |
2116 | to the target since this location will always trigger and generate a | |
2117 | response back to GDB. */ | |
2118 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2119 | { | |
2120 | loc = (*loc2p); | |
2121 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2122 | { | |
2123 | if (modified) | |
2124 | { | |
2125 | struct agent_expr *aexpr; | |
2126 | ||
2127 | /* Re-parse the conditions since something changed. In that | |
2128 | case we already freed the condition bytecodes (see | |
2129 | force_breakpoint_reinsertion). We just | |
2130 | need to parse the condition to bytecodes again. */ | |
2131 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2132 | loc->cond_bytecode = aexpr; | |
2133 | ||
2134 | /* Check if we managed to parse the conditional expression | |
2135 | correctly. If not, we will not send this condition | |
2136 | to the target. */ | |
2137 | if (aexpr) | |
2138 | continue; | |
2139 | } | |
2140 | ||
2141 | /* If we have a NULL bytecode expression, it means something | |
2142 | went wrong or we have a null condition expression. */ | |
2143 | if (!loc->cond_bytecode) | |
2144 | { | |
2145 | null_condition_or_parse_error = 1; | |
2146 | break; | |
2147 | } | |
2148 | } | |
2149 | } | |
2150 | ||
2151 | /* If any of these happened, it means we will have to evaluate the conditions | |
2152 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2153 | for all the other duplicate locations, thus we free all of them here. | |
2154 | ||
2155 | This is so we have a finer control over which locations' conditions are | |
2156 | being evaluated by GDB or the remote stub. */ | |
2157 | if (null_condition_or_parse_error) | |
2158 | { | |
2159 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2160 | { | |
2161 | loc = (*loc2p); | |
2162 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2163 | { | |
2164 | /* Only go as far as the first NULL bytecode is | |
2165 | located. */ | |
2166 | if (!loc->cond_bytecode) | |
2167 | return; | |
2168 | ||
2169 | free_agent_expr (loc->cond_bytecode); | |
2170 | loc->cond_bytecode = NULL; | |
2171 | } | |
2172 | } | |
2173 | } | |
2174 | ||
2175 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2176 | for this location's address. */ | |
2177 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2178 | { | |
2179 | loc = (*loc2p); | |
2180 | if (loc->cond | |
2181 | && is_breakpoint (loc->owner) | |
2182 | && loc->pspace->num == bl->pspace->num | |
2183 | && loc->owner->enable_state == bp_enabled | |
2184 | && loc->enabled) | |
2185 | /* Add the condition to the vector. This will be used later to send the | |
2186 | conditions to the target. */ | |
2187 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2188 | loc->cond_bytecode); | |
2189 | } | |
2190 | ||
2191 | return; | |
2192 | } | |
2193 | ||
d3ce09f5 SS |
2194 | /* Parses a command described by string CMD into an agent expression |
2195 | bytecode suitable for evaluation by the bytecode interpreter. | |
2196 | Return NULL if there was any error during parsing. */ | |
2197 | ||
2198 | static struct agent_expr * | |
2199 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2200 | { | |
2201 | struct cleanup *old_cleanups = 0; | |
2202 | struct expression *expr, **argvec; | |
2203 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2204 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2205 | const char *cmdrest; |
2206 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2207 | struct format_piece *fpieces; |
2208 | int nargs; | |
2209 | struct gdbarch *gdbarch = get_current_arch (); | |
2210 | ||
2211 | if (!cmd) | |
2212 | return NULL; | |
2213 | ||
2214 | cmdrest = cmd; | |
2215 | ||
2216 | if (*cmdrest == ',') | |
2217 | ++cmdrest; | |
bbc13ae3 | 2218 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2219 | |
2220 | if (*cmdrest++ != '"') | |
2221 | error (_("No format string following the location")); | |
2222 | ||
2223 | format_start = cmdrest; | |
2224 | ||
2225 | fpieces = parse_format_string (&cmdrest); | |
2226 | ||
2227 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2228 | ||
2229 | format_end = cmdrest; | |
2230 | ||
2231 | if (*cmdrest++ != '"') | |
2232 | error (_("Bad format string, non-terminated '\"'.")); | |
2233 | ||
bbc13ae3 | 2234 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2235 | |
2236 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2237 | error (_("Invalid argument syntax")); | |
2238 | ||
2239 | if (*cmdrest == ',') | |
2240 | cmdrest++; | |
bbc13ae3 | 2241 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2242 | |
2243 | /* For each argument, make an expression. */ | |
2244 | ||
2245 | argvec = (struct expression **) alloca (strlen (cmd) | |
2246 | * sizeof (struct expression *)); | |
2247 | ||
2248 | nargs = 0; | |
2249 | while (*cmdrest != '\0') | |
2250 | { | |
bbc13ae3 | 2251 | const char *cmd1; |
d3ce09f5 SS |
2252 | |
2253 | cmd1 = cmdrest; | |
2254 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2255 | argvec[nargs++] = expr; | |
2256 | cmdrest = cmd1; | |
2257 | if (*cmdrest == ',') | |
2258 | ++cmdrest; | |
2259 | } | |
2260 | ||
2261 | /* We don't want to stop processing, so catch any errors | |
2262 | that may show up. */ | |
2263 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2264 | { | |
2265 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2266 | format_start, format_end - format_start, | |
2267 | fpieces, nargs, argvec); | |
2268 | } | |
2269 | ||
752eb8b4 TT |
2270 | do_cleanups (old_cleanups); |
2271 | ||
d3ce09f5 SS |
2272 | if (ex.reason < 0) |
2273 | { | |
2274 | /* If we got here, it means the command could not be parsed to a valid | |
2275 | bytecode expression and thus can't be evaluated on the target's side. | |
2276 | It's no use iterating through the other commands. */ | |
2277 | return NULL; | |
2278 | } | |
2279 | ||
d3ce09f5 SS |
2280 | /* We have a valid agent expression, return it. */ |
2281 | return aexpr; | |
2282 | } | |
2283 | ||
2284 | /* Based on location BL, create a list of breakpoint commands to be | |
2285 | passed on to the target. If we have duplicated locations with | |
2286 | different commands, we will add any such to the list. */ | |
2287 | ||
2288 | static void | |
2289 | build_target_command_list (struct bp_location *bl) | |
2290 | { | |
2291 | struct bp_location **locp = NULL, **loc2p; | |
2292 | int null_command_or_parse_error = 0; | |
2293 | int modified = bl->needs_update; | |
2294 | struct bp_location *loc; | |
2295 | ||
8b4f3082 PA |
2296 | /* Release commands left over from a previous insert. */ |
2297 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2298 | ||
d3ce09f5 SS |
2299 | /* For now, limit to agent-style dprintf breakpoints. */ |
2300 | if (bl->owner->type != bp_dprintf | |
2301 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2302 | return; | |
2303 | ||
2304 | if (!target_can_run_breakpoint_commands ()) | |
2305 | return; | |
2306 | ||
2307 | /* Do a first pass to check for locations with no assigned | |
2308 | conditions or conditions that fail to parse to a valid agent expression | |
2309 | bytecode. If any of these happen, then it's no use to send conditions | |
2310 | to the target since this location will always trigger and generate a | |
2311 | response back to GDB. */ | |
2312 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2313 | { | |
2314 | loc = (*loc2p); | |
2315 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2316 | { | |
2317 | if (modified) | |
2318 | { | |
2319 | struct agent_expr *aexpr; | |
2320 | ||
2321 | /* Re-parse the commands since something changed. In that | |
2322 | case we already freed the command bytecodes (see | |
2323 | force_breakpoint_reinsertion). We just | |
2324 | need to parse the command to bytecodes again. */ | |
2325 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2326 | loc->owner->extra_string); | |
2327 | loc->cmd_bytecode = aexpr; | |
2328 | ||
2329 | if (!aexpr) | |
2330 | continue; | |
2331 | } | |
2332 | ||
2333 | /* If we have a NULL bytecode expression, it means something | |
2334 | went wrong or we have a null command expression. */ | |
2335 | if (!loc->cmd_bytecode) | |
2336 | { | |
2337 | null_command_or_parse_error = 1; | |
2338 | break; | |
2339 | } | |
2340 | } | |
2341 | } | |
2342 | ||
2343 | /* If anything failed, then we're not doing target-side commands, | |
2344 | and so clean up. */ | |
2345 | if (null_command_or_parse_error) | |
2346 | { | |
2347 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2348 | { | |
2349 | loc = (*loc2p); | |
2350 | if (is_breakpoint (loc->owner) | |
2351 | && loc->pspace->num == bl->pspace->num) | |
2352 | { | |
2353 | /* Only go as far as the first NULL bytecode is | |
2354 | located. */ | |
40fb6c5e | 2355 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2356 | return; |
2357 | ||
40fb6c5e HZ |
2358 | free_agent_expr (loc->cmd_bytecode); |
2359 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2360 | } |
2361 | } | |
2362 | } | |
2363 | ||
2364 | /* No NULL commands or failed bytecode generation. Build a command list | |
2365 | for this location's address. */ | |
2366 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2367 | { | |
2368 | loc = (*loc2p); | |
2369 | if (loc->owner->extra_string | |
2370 | && is_breakpoint (loc->owner) | |
2371 | && loc->pspace->num == bl->pspace->num | |
2372 | && loc->owner->enable_state == bp_enabled | |
2373 | && loc->enabled) | |
2374 | /* Add the command to the vector. This will be used later | |
2375 | to send the commands to the target. */ | |
2376 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2377 | loc->cmd_bytecode); | |
2378 | } | |
2379 | ||
2380 | bl->target_info.persist = 0; | |
2381 | /* Maybe flag this location as persistent. */ | |
2382 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2383 | bl->target_info.persist = 1; | |
2384 | } | |
2385 | ||
35df4500 TJB |
2386 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2387 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2388 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2389 | Returns 0 for success, 1 if the bp_location type is not supported or |
2390 | -1 for failure. | |
879bfdc2 | 2391 | |
4a64f543 MS |
2392 | NOTE drow/2003-09-09: This routine could be broken down to an |
2393 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2394 | static int |
35df4500 | 2395 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2396 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2397 | int *disabled_breaks, |
dd61ec5c MW |
2398 | int *hw_breakpoint_error, |
2399 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2400 | { |
0000e5cc PA |
2401 | enum errors bp_err = GDB_NO_ERROR; |
2402 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2403 | volatile struct gdb_exception e; |
879bfdc2 | 2404 | |
b775012e | 2405 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2406 | return 0; |
2407 | ||
35c63cd8 JB |
2408 | /* Note we don't initialize bl->target_info, as that wipes out |
2409 | the breakpoint location's shadow_contents if the breakpoint | |
2410 | is still inserted at that location. This in turn breaks | |
2411 | target_read_memory which depends on these buffers when | |
2412 | a memory read is requested at the breakpoint location: | |
2413 | Once the target_info has been wiped, we fail to see that | |
2414 | we have a breakpoint inserted at that address and thus | |
2415 | read the breakpoint instead of returning the data saved in | |
2416 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2417 | bl->target_info.placed_address = bl->address; |
2418 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2419 | bl->target_info.length = bl->length; |
8181d85f | 2420 | |
b775012e LM |
2421 | /* When working with target-side conditions, we must pass all the conditions |
2422 | for the same breakpoint address down to the target since GDB will not | |
2423 | insert those locations. With a list of breakpoint conditions, the target | |
2424 | can decide when to stop and notify GDB. */ | |
2425 | ||
2426 | if (is_breakpoint (bl->owner)) | |
2427 | { | |
2428 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2429 | build_target_command_list (bl); |
2430 | /* Reset the modification marker. */ | |
b775012e LM |
2431 | bl->needs_update = 0; |
2432 | } | |
2433 | ||
35df4500 TJB |
2434 | if (bl->loc_type == bp_loc_software_breakpoint |
2435 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2436 | { |
35df4500 | 2437 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2438 | { |
2439 | /* If the explicitly specified breakpoint type | |
2440 | is not hardware breakpoint, check the memory map to see | |
2441 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2442 | |
765dc015 VP |
2443 | Two important cases are: |
2444 | - location type is not hardware breakpoint, memory | |
2445 | is readonly. We change the type of the location to | |
2446 | hardware breakpoint. | |
4a64f543 MS |
2447 | - location type is hardware breakpoint, memory is |
2448 | read-write. This means we've previously made the | |
2449 | location hardware one, but then the memory map changed, | |
2450 | so we undo. | |
765dc015 | 2451 | |
4a64f543 MS |
2452 | When breakpoints are removed, remove_breakpoints will use |
2453 | location types we've just set here, the only possible | |
2454 | problem is that memory map has changed during running | |
2455 | program, but it's not going to work anyway with current | |
2456 | gdb. */ | |
765dc015 | 2457 | struct mem_region *mr |
35df4500 | 2458 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2459 | |
2460 | if (mr) | |
2461 | { | |
2462 | if (automatic_hardware_breakpoints) | |
2463 | { | |
765dc015 VP |
2464 | enum bp_loc_type new_type; |
2465 | ||
2466 | if (mr->attrib.mode != MEM_RW) | |
2467 | new_type = bp_loc_hardware_breakpoint; | |
2468 | else | |
2469 | new_type = bp_loc_software_breakpoint; | |
2470 | ||
35df4500 | 2471 | if (new_type != bl->loc_type) |
765dc015 VP |
2472 | { |
2473 | static int said = 0; | |
cc59ec59 | 2474 | |
35df4500 | 2475 | bl->loc_type = new_type; |
765dc015 VP |
2476 | if (!said) |
2477 | { | |
3e43a32a MS |
2478 | fprintf_filtered (gdb_stdout, |
2479 | _("Note: automatically using " | |
2480 | "hardware breakpoints for " | |
2481 | "read-only addresses.\n")); | |
765dc015 VP |
2482 | said = 1; |
2483 | } | |
2484 | } | |
2485 | } | |
35df4500 | 2486 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2487 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2488 | warning (_("cannot set software breakpoint " |
2489 | "at readonly address %s"), | |
35df4500 | 2490 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2491 | } |
2492 | } | |
2493 | ||
879bfdc2 DJ |
2494 | /* First check to see if we have to handle an overlay. */ |
2495 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2496 | || bl->section == NULL |
2497 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2498 | { |
2499 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2500 | TRY_CATCH (e, RETURN_MASK_ALL) |
2501 | { | |
0000e5cc PA |
2502 | int val; |
2503 | ||
dd61ec5c | 2504 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2505 | if (val) |
2506 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2507 | } |
2508 | if (e.reason < 0) | |
2509 | { | |
0000e5cc PA |
2510 | bp_err = e.error; |
2511 | bp_err_message = e.message; | |
dd61ec5c | 2512 | } |
879bfdc2 DJ |
2513 | } |
2514 | else | |
2515 | { | |
4a64f543 | 2516 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2517 | Shall we set a breakpoint at the LMA? */ |
2518 | if (!overlay_events_enabled) | |
2519 | { | |
2520 | /* Yes -- overlay event support is not active, | |
2521 | so we must try to set a breakpoint at the LMA. | |
2522 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2523 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2524 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2525 | bl->owner->number); |
879bfdc2 DJ |
2526 | else |
2527 | { | |
35df4500 TJB |
2528 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2529 | bl->section); | |
879bfdc2 | 2530 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2531 | bl->overlay_target_info = bl->target_info; |
2532 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2533 | |
2534 | /* No overlay handling: just set the breakpoint. */ | |
2535 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2536 | { | |
2537 | int val; | |
2538 | ||
2539 | val = target_insert_breakpoint (bl->gdbarch, | |
2540 | &bl->overlay_target_info); | |
2541 | if (val) | |
2542 | bp_err = GENERIC_ERROR; | |
2543 | } | |
2544 | if (e.reason < 0) | |
2545 | { | |
2546 | bp_err = e.error; | |
2547 | bp_err_message = e.message; | |
2548 | } | |
2549 | ||
2550 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2551 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2552 | "Overlay breakpoint %d " |
2553 | "failed: in ROM?\n", | |
35df4500 | 2554 | bl->owner->number); |
879bfdc2 DJ |
2555 | } |
2556 | } | |
2557 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2558 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2559 | { |
2560 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2561 | TRY_CATCH (e, RETURN_MASK_ALL) |
2562 | { | |
0000e5cc PA |
2563 | int val; |
2564 | ||
dd61ec5c | 2565 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2566 | if (val) |
2567 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2568 | } |
2569 | if (e.reason < 0) | |
2570 | { | |
0000e5cc PA |
2571 | bp_err = e.error; |
2572 | bp_err_message = e.message; | |
dd61ec5c | 2573 | } |
879bfdc2 DJ |
2574 | } |
2575 | else | |
2576 | { | |
2577 | /* No. This breakpoint will not be inserted. | |
2578 | No error, but do not mark the bp as 'inserted'. */ | |
2579 | return 0; | |
2580 | } | |
2581 | } | |
2582 | ||
0000e5cc | 2583 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2584 | { |
2585 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2586 | |
2587 | /* In some cases, we might not be able to insert a | |
2588 | breakpoint in a shared library that has already been | |
2589 | removed, but we have not yet processed the shlib unload | |
2590 | event. Unfortunately, some targets that implement | |
2591 | breakpoint insertion themselves (necessary if this is a | |
2592 | HW breakpoint, but SW breakpoints likewise) can't tell | |
2593 | why the breakpoint insertion failed (e.g., the remote | |
2594 | target doesn't define error codes), so we must treat | |
2595 | generic errors as memory errors. */ | |
2596 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) | |
2597 | && solib_name_from_address (bl->pspace, bl->address)) | |
879bfdc2 | 2598 | { |
4a64f543 | 2599 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2600 | bl->shlib_disabled = 1; |
8d3788bd | 2601 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2602 | if (!*disabled_breaks) |
2603 | { | |
2604 | fprintf_unfiltered (tmp_error_stream, | |
2605 | "Cannot insert breakpoint %d.\n", | |
2606 | bl->owner->number); | |
2607 | fprintf_unfiltered (tmp_error_stream, | |
2608 | "Temporarily disabling shared " | |
2609 | "library breakpoints:\n"); | |
2610 | } | |
2611 | *disabled_breaks = 1; | |
879bfdc2 | 2612 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2613 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2614 | return 0; |
879bfdc2 DJ |
2615 | } |
2616 | else | |
879bfdc2 | 2617 | { |
35df4500 | 2618 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2619 | { |
0000e5cc PA |
2620 | *hw_breakpoint_error = 1; |
2621 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2622 | fprintf_unfiltered (tmp_error_stream, |
2623 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2624 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2625 | if (bp_err_message != NULL) | |
2626 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2627 | } |
2628 | else | |
2629 | { | |
0000e5cc PA |
2630 | if (bp_err_message == NULL) |
2631 | { | |
2632 | char *message | |
2633 | = memory_error_message (TARGET_XFER_E_IO, | |
2634 | bl->gdbarch, bl->address); | |
2635 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2636 | ||
2637 | fprintf_unfiltered (tmp_error_stream, | |
2638 | "Cannot insert breakpoint %d.\n" | |
2639 | "%s\n", | |
2640 | bl->owner->number, message); | |
2641 | do_cleanups (old_chain); | |
2642 | } | |
2643 | else | |
2644 | { | |
2645 | fprintf_unfiltered (tmp_error_stream, | |
2646 | "Cannot insert breakpoint %d: %s\n", | |
2647 | bl->owner->number, | |
2648 | bp_err_message); | |
2649 | } | |
879bfdc2 | 2650 | } |
0000e5cc | 2651 | return 1; |
879bfdc2 DJ |
2652 | |
2653 | } | |
2654 | } | |
2655 | else | |
35df4500 | 2656 | bl->inserted = 1; |
879bfdc2 | 2657 | |
0000e5cc | 2658 | return 0; |
879bfdc2 DJ |
2659 | } |
2660 | ||
35df4500 | 2661 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2662 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2663 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2664 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2665 | { |
0000e5cc PA |
2666 | int val; |
2667 | ||
77b06cd7 TJB |
2668 | gdb_assert (bl->owner->ops != NULL |
2669 | && bl->owner->ops->insert_location != NULL); | |
2670 | ||
2671 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2672 | |
2673 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2674 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2675 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2676 | { |
2677 | struct bp_location *loc, **loc_temp; | |
2678 | ||
2679 | /* But don't try to insert it, if there's already another | |
2680 | hw_access location that would be considered a duplicate | |
2681 | of this one. */ | |
2682 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2683 | if (loc != bl |
85d721b8 | 2684 | && loc->watchpoint_type == hw_access |
35df4500 | 2685 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2686 | { |
35df4500 TJB |
2687 | bl->duplicate = 1; |
2688 | bl->inserted = 1; | |
2689 | bl->target_info = loc->target_info; | |
2690 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2691 | val = 0; |
2692 | break; | |
2693 | } | |
2694 | ||
2695 | if (val == 1) | |
2696 | { | |
77b06cd7 TJB |
2697 | bl->watchpoint_type = hw_access; |
2698 | val = bl->owner->ops->insert_location (bl); | |
2699 | ||
2700 | if (val) | |
2701 | /* Back to the original value. */ | |
2702 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2703 | } |
2704 | } | |
2705 | ||
35df4500 | 2706 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2707 | } |
2708 | ||
35df4500 | 2709 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2710 | { |
0000e5cc PA |
2711 | int val; |
2712 | ||
77b06cd7 TJB |
2713 | gdb_assert (bl->owner->ops != NULL |
2714 | && bl->owner->ops->insert_location != NULL); | |
2715 | ||
2716 | val = bl->owner->ops->insert_location (bl); | |
2717 | if (val) | |
2718 | { | |
2719 | bl->owner->enable_state = bp_disabled; | |
2720 | ||
2721 | if (val == 1) | |
2722 | warning (_("\ | |
2723 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2724 | of catchpoint."), bl->owner->number); | |
2725 | else | |
2726 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2727 | } | |
2728 | ||
2729 | bl->inserted = (val == 0); | |
1640b821 DJ |
2730 | |
2731 | /* We've already printed an error message if there was a problem | |
2732 | inserting this catchpoint, and we've disabled the catchpoint, | |
2733 | so just return success. */ | |
2734 | return 0; | |
879bfdc2 DJ |
2735 | } |
2736 | ||
2737 | return 0; | |
2738 | } | |
2739 | ||
6c95b8df PA |
2740 | /* This function is called when program space PSPACE is about to be |
2741 | deleted. It takes care of updating breakpoints to not reference | |
2742 | PSPACE anymore. */ | |
2743 | ||
2744 | void | |
2745 | breakpoint_program_space_exit (struct program_space *pspace) | |
2746 | { | |
2747 | struct breakpoint *b, *b_temp; | |
876fa593 | 2748 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2749 | |
2750 | /* Remove any breakpoint that was set through this program space. */ | |
2751 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2752 | { | |
2753 | if (b->pspace == pspace) | |
2754 | delete_breakpoint (b); | |
2755 | } | |
2756 | ||
2757 | /* Breakpoints set through other program spaces could have locations | |
2758 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2759 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2760 | { |
2761 | struct bp_location *tmp; | |
2762 | ||
2763 | if (loc->pspace == pspace) | |
2764 | { | |
2bdf28a0 | 2765 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2766 | if (loc->owner->loc == loc) |
2767 | loc->owner->loc = loc->next; | |
2768 | else | |
2769 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2770 | if (tmp->next == loc) | |
2771 | { | |
2772 | tmp->next = loc->next; | |
2773 | break; | |
2774 | } | |
2775 | } | |
2776 | } | |
2777 | ||
2778 | /* Now update the global location list to permanently delete the | |
2779 | removed locations above. */ | |
2780 | update_global_location_list (0); | |
2781 | } | |
2782 | ||
74960c60 VP |
2783 | /* Make sure all breakpoints are inserted in inferior. |
2784 | Throws exception on any error. | |
2785 | A breakpoint that is already inserted won't be inserted | |
2786 | again, so calling this function twice is safe. */ | |
2787 | void | |
2788 | insert_breakpoints (void) | |
2789 | { | |
2790 | struct breakpoint *bpt; | |
2791 | ||
2792 | ALL_BREAKPOINTS (bpt) | |
2793 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2794 | { |
2795 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2796 | ||
2797 | update_watchpoint (w, 0 /* don't reparse. */); | |
2798 | } | |
74960c60 | 2799 | |
b60e7edf | 2800 | update_global_location_list (1); |
74960c60 | 2801 | |
c35b1492 PA |
2802 | /* update_global_location_list does not insert breakpoints when |
2803 | always_inserted_mode is not enabled. Explicitly insert them | |
2804 | now. */ | |
2805 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2806 | insert_breakpoint_locations (); |
2807 | } | |
2808 | ||
20388dd6 YQ |
2809 | /* Invoke CALLBACK for each of bp_location. */ |
2810 | ||
2811 | void | |
2812 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2813 | { | |
2814 | struct bp_location *loc, **loc_tmp; | |
2815 | ||
2816 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2817 | { | |
2818 | callback (loc, NULL); | |
2819 | } | |
2820 | } | |
2821 | ||
b775012e LM |
2822 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2823 | target. It is the case with deleting and disabling of breakpoints when using | |
2824 | always-inserted mode. */ | |
2825 | ||
2826 | static void | |
2827 | update_inserted_breakpoint_locations (void) | |
2828 | { | |
2829 | struct bp_location *bl, **blp_tmp; | |
2830 | int error_flag = 0; | |
2831 | int val = 0; | |
2832 | int disabled_breaks = 0; | |
2833 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2834 | int hw_bp_details_reported = 0; |
b775012e LM |
2835 | |
2836 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2837 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2838 | ||
2839 | /* Explicitly mark the warning -- this will only be printed if | |
2840 | there was an error. */ | |
2841 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2842 | ||
2843 | save_current_space_and_thread (); | |
2844 | ||
2845 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2846 | { | |
2847 | /* We only want to update software breakpoints and hardware | |
2848 | breakpoints. */ | |
2849 | if (!is_breakpoint (bl->owner)) | |
2850 | continue; | |
2851 | ||
2852 | /* We only want to update locations that are already inserted | |
2853 | and need updating. This is to avoid unwanted insertion during | |
2854 | deletion of breakpoints. */ | |
2855 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2856 | continue; | |
2857 | ||
2858 | switch_to_program_space_and_thread (bl->pspace); | |
2859 | ||
2860 | /* For targets that support global breakpoints, there's no need | |
2861 | to select an inferior to insert breakpoint to. In fact, even | |
2862 | if we aren't attached to any process yet, we should still | |
2863 | insert breakpoints. */ | |
f5656ead | 2864 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2865 | && ptid_equal (inferior_ptid, null_ptid)) |
2866 | continue; | |
2867 | ||
2868 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2869 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2870 | if (val) |
2871 | error_flag = val; | |
2872 | } | |
2873 | ||
2874 | if (error_flag) | |
2875 | { | |
2876 | target_terminal_ours_for_output (); | |
2877 | error_stream (tmp_error_stream); | |
2878 | } | |
2879 | ||
2880 | do_cleanups (cleanups); | |
2881 | } | |
2882 | ||
c30eee59 | 2883 | /* Used when starting or continuing the program. */ |
c906108c | 2884 | |
74960c60 VP |
2885 | static void |
2886 | insert_breakpoint_locations (void) | |
c906108c | 2887 | { |
a5606eee | 2888 | struct breakpoint *bpt; |
35df4500 | 2889 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2890 | int error_flag = 0; |
c906108c | 2891 | int val = 0; |
3fbb6ffa | 2892 | int disabled_breaks = 0; |
81d0cc19 | 2893 | int hw_breakpoint_error = 0; |
dd61ec5c | 2894 | int hw_bp_error_explained_already = 0; |
c906108c | 2895 | |
81d0cc19 | 2896 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2897 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2898 | |
81d0cc19 GS |
2899 | /* Explicitly mark the warning -- this will only be printed if |
2900 | there was an error. */ | |
2901 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2902 | |
2903 | save_current_space_and_thread (); | |
2904 | ||
35df4500 | 2905 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2906 | { |
b775012e | 2907 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2908 | continue; |
2909 | ||
4a64f543 MS |
2910 | /* There is no point inserting thread-specific breakpoints if |
2911 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2912 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2913 | if (bl->owner->thread != -1 |
2914 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2915 | continue; |
2916 | ||
35df4500 | 2917 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2918 | |
2919 | /* For targets that support global breakpoints, there's no need | |
2920 | to select an inferior to insert breakpoint to. In fact, even | |
2921 | if we aren't attached to any process yet, we should still | |
2922 | insert breakpoints. */ | |
f5656ead | 2923 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2924 | && ptid_equal (inferior_ptid, null_ptid)) |
2925 | continue; | |
2926 | ||
3fbb6ffa | 2927 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2928 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2929 | if (val) |
eacd795a | 2930 | error_flag = val; |
879bfdc2 | 2931 | } |
c906108c | 2932 | |
4a64f543 MS |
2933 | /* If we failed to insert all locations of a watchpoint, remove |
2934 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2935 | ALL_BREAKPOINTS (bpt) |
2936 | { | |
2937 | int some_failed = 0; | |
2938 | struct bp_location *loc; | |
2939 | ||
2940 | if (!is_hardware_watchpoint (bpt)) | |
2941 | continue; | |
2942 | ||
d6b74ac4 | 2943 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2944 | continue; |
74960c60 VP |
2945 | |
2946 | if (bpt->disposition == disp_del_at_next_stop) | |
2947 | continue; | |
a5606eee VP |
2948 | |
2949 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2950 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2951 | { |
2952 | some_failed = 1; | |
2953 | break; | |
2954 | } | |
2955 | if (some_failed) | |
2956 | { | |
2957 | for (loc = bpt->loc; loc; loc = loc->next) | |
2958 | if (loc->inserted) | |
2959 | remove_breakpoint (loc, mark_uninserted); | |
2960 | ||
2961 | hw_breakpoint_error = 1; | |
2962 | fprintf_unfiltered (tmp_error_stream, | |
2963 | "Could not insert hardware watchpoint %d.\n", | |
2964 | bpt->number); | |
eacd795a | 2965 | error_flag = -1; |
a5606eee VP |
2966 | } |
2967 | } | |
2968 | ||
eacd795a | 2969 | if (error_flag) |
81d0cc19 GS |
2970 | { |
2971 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2972 | message about possibly exhausted resources. */ | |
dd61ec5c | 2973 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2974 | { |
c6510018 MS |
2975 | fprintf_unfiltered (tmp_error_stream, |
2976 | "Could not insert hardware breakpoints:\n\ | |
2977 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2978 | } |
81d0cc19 GS |
2979 | target_terminal_ours_for_output (); |
2980 | error_stream (tmp_error_stream); | |
2981 | } | |
f7545552 TT |
2982 | |
2983 | do_cleanups (cleanups); | |
c906108c SS |
2984 | } |
2985 | ||
c30eee59 TJB |
2986 | /* Used when the program stops. |
2987 | Returns zero if successful, or non-zero if there was a problem | |
2988 | removing a breakpoint location. */ | |
2989 | ||
c906108c | 2990 | int |
fba45db2 | 2991 | remove_breakpoints (void) |
c906108c | 2992 | { |
35df4500 | 2993 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2994 | int val = 0; |
c906108c | 2995 | |
35df4500 | 2996 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2997 | { |
1e4d1764 | 2998 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2999 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3000 | } |
3a1bae8e | 3001 | return val; |
c906108c SS |
3002 | } |
3003 | ||
49fa26b0 PA |
3004 | /* When a thread exits, remove breakpoints that are related to |
3005 | that thread. */ | |
3006 | ||
3007 | static void | |
3008 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3009 | { | |
3010 | struct breakpoint *b, *b_tmp; | |
3011 | ||
3012 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3013 | { | |
96181529 | 3014 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3015 | { |
3016 | b->disposition = disp_del_at_next_stop; | |
3017 | ||
3018 | printf_filtered (_("\ | |
46ecd527 | 3019 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3020 | b->number, tp->num); |
3021 | ||
3022 | /* Hide it from the user. */ | |
3023 | b->number = 0; | |
3024 | } | |
3025 | } | |
3026 | } | |
3027 | ||
6c95b8df PA |
3028 | /* Remove breakpoints of process PID. */ |
3029 | ||
3030 | int | |
3031 | remove_breakpoints_pid (int pid) | |
3032 | { | |
35df4500 | 3033 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3034 | int val; |
3035 | struct inferior *inf = find_inferior_pid (pid); | |
3036 | ||
35df4500 | 3037 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3038 | { |
35df4500 | 3039 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3040 | continue; |
3041 | ||
d3ce09f5 SS |
3042 | if (bl->owner->type == bp_dprintf) |
3043 | continue; | |
3044 | ||
35df4500 | 3045 | if (bl->inserted) |
6c95b8df | 3046 | { |
35df4500 | 3047 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3048 | if (val != 0) |
3049 | return val; | |
3050 | } | |
3051 | } | |
3052 | return 0; | |
3053 | } | |
3054 | ||
c906108c | 3055 | int |
fba45db2 | 3056 | reattach_breakpoints (int pid) |
c906108c | 3057 | { |
6c95b8df | 3058 | struct cleanup *old_chain; |
35df4500 | 3059 | struct bp_location *bl, **blp_tmp; |
c906108c | 3060 | int val; |
86b887df | 3061 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3062 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3063 | struct inferior *inf; |
3064 | struct thread_info *tp; | |
3065 | ||
3066 | tp = any_live_thread_of_process (pid); | |
3067 | if (tp == NULL) | |
3068 | return 1; | |
3069 | ||
3070 | inf = find_inferior_pid (pid); | |
3071 | old_chain = save_inferior_ptid (); | |
3072 | ||
3073 | inferior_ptid = tp->ptid; | |
a4954f26 | 3074 | |
86b887df | 3075 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3076 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3077 | |
35df4500 | 3078 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3079 | { |
35df4500 | 3080 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3081 | continue; |
3082 | ||
35df4500 | 3083 | if (bl->inserted) |
c5aa993b | 3084 | { |
35df4500 | 3085 | bl->inserted = 0; |
dd61ec5c | 3086 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3087 | if (val != 0) |
3088 | { | |
ce696e05 | 3089 | do_cleanups (old_chain); |
c5aa993b JM |
3090 | return val; |
3091 | } | |
3092 | } | |
3093 | } | |
ce696e05 | 3094 | do_cleanups (old_chain); |
c906108c SS |
3095 | return 0; |
3096 | } | |
3097 | ||
e58b0e63 PA |
3098 | static int internal_breakpoint_number = -1; |
3099 | ||
84f4c1fe PM |
3100 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3101 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3102 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3103 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3104 | breakpoint_count and that value incremented. Internal breakpoints |
3105 | do not set the internal var bpnum. */ | |
3106 | static void | |
3107 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3108 | { | |
3109 | if (internal) | |
3110 | b->number = internal_breakpoint_number--; | |
3111 | else | |
3112 | { | |
3113 | set_breakpoint_count (breakpoint_count + 1); | |
3114 | b->number = breakpoint_count; | |
3115 | } | |
3116 | } | |
3117 | ||
e62c965a | 3118 | static struct breakpoint * |
a6d9a66e | 3119 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3120 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3121 | const struct breakpoint_ops *ops) |
e62c965a | 3122 | { |
e62c965a PP |
3123 | struct symtab_and_line sal; |
3124 | struct breakpoint *b; | |
3125 | ||
4a64f543 | 3126 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3127 | |
3128 | sal.pc = address; | |
3129 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3130 | sal.pspace = current_program_space; |
e62c965a | 3131 | |
06edf0c0 | 3132 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3133 | b->number = internal_breakpoint_number--; |
3134 | b->disposition = disp_donttouch; | |
3135 | ||
3136 | return b; | |
3137 | } | |
3138 | ||
17450429 PP |
3139 | static const char *const longjmp_names[] = |
3140 | { | |
3141 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3142 | }; | |
3143 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3144 | ||
3145 | /* Per-objfile data private to breakpoint.c. */ | |
3146 | struct breakpoint_objfile_data | |
3147 | { | |
3148 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3149 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3150 | |
3151 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3152 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3153 | |
28106bc2 SDJ |
3154 | /* True if we have looked for longjmp probes. */ |
3155 | int longjmp_searched; | |
3156 | ||
3157 | /* SystemTap probe points for longjmp (if any). */ | |
3158 | VEC (probe_p) *longjmp_probes; | |
3159 | ||
17450429 | 3160 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3161 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3162 | |
3163 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3164 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3165 | |
3166 | /* True if we have looked for exception probes. */ | |
3167 | int exception_searched; | |
3168 | ||
3169 | /* SystemTap probe points for unwinding (if any). */ | |
3170 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3171 | }; |
3172 | ||
3173 | static const struct objfile_data *breakpoint_objfile_key; | |
3174 | ||
3175 | /* Minimal symbol not found sentinel. */ | |
3176 | static struct minimal_symbol msym_not_found; | |
3177 | ||
3178 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3179 | ||
3180 | static int | |
3181 | msym_not_found_p (const struct minimal_symbol *msym) | |
3182 | { | |
3183 | return msym == &msym_not_found; | |
3184 | } | |
3185 | ||
3186 | /* Return per-objfile data needed by breakpoint.c. | |
3187 | Allocate the data if necessary. */ | |
3188 | ||
3189 | static struct breakpoint_objfile_data * | |
3190 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3191 | { | |
3192 | struct breakpoint_objfile_data *bp_objfile_data; | |
3193 | ||
3194 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3195 | if (bp_objfile_data == NULL) | |
3196 | { | |
3197 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3198 | sizeof (*bp_objfile_data)); | |
3199 | ||
3200 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3201 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3202 | } | |
3203 | return bp_objfile_data; | |
3204 | } | |
3205 | ||
28106bc2 SDJ |
3206 | static void |
3207 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3208 | { | |
3209 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3210 | ||
3211 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3212 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3213 | } | |
3214 | ||
e62c965a | 3215 | static void |
af02033e | 3216 | create_overlay_event_breakpoint (void) |
e62c965a | 3217 | { |
69de3c6a | 3218 | struct objfile *objfile; |
af02033e | 3219 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3220 | |
69de3c6a PP |
3221 | ALL_OBJFILES (objfile) |
3222 | { | |
3223 | struct breakpoint *b; | |
17450429 PP |
3224 | struct breakpoint_objfile_data *bp_objfile_data; |
3225 | CORE_ADDR addr; | |
69de3c6a | 3226 | |
17450429 PP |
3227 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3228 | ||
3b7344d5 | 3229 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3230 | continue; |
3231 | ||
3b7344d5 | 3232 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3233 | { |
3b7344d5 | 3234 | struct bound_minimal_symbol m; |
17450429 PP |
3235 | |
3236 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3237 | if (m.minsym == NULL) |
17450429 PP |
3238 | { |
3239 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3240 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3241 | continue; |
3242 | } | |
3243 | bp_objfile_data->overlay_msym = m; | |
3244 | } | |
e62c965a | 3245 | |
77e371c0 | 3246 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3247 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3248 | bp_overlay_event, |
3249 | &internal_breakpoint_ops); | |
69de3c6a | 3250 | b->addr_string = xstrdup (func_name); |
e62c965a | 3251 | |
69de3c6a PP |
3252 | if (overlay_debugging == ovly_auto) |
3253 | { | |
3254 | b->enable_state = bp_enabled; | |
3255 | overlay_events_enabled = 1; | |
3256 | } | |
3257 | else | |
3258 | { | |
3259 | b->enable_state = bp_disabled; | |
3260 | overlay_events_enabled = 0; | |
3261 | } | |
e62c965a PP |
3262 | } |
3263 | update_global_location_list (1); | |
3264 | } | |
3265 | ||
0fd8e87f | 3266 | static void |
af02033e | 3267 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3268 | { |
6c95b8df | 3269 | struct program_space *pspace; |
6c95b8df PA |
3270 | struct cleanup *old_chain; |
3271 | ||
3272 | old_chain = save_current_program_space (); | |
0fd8e87f | 3273 | |
6c95b8df | 3274 | ALL_PSPACES (pspace) |
af02033e PP |
3275 | { |
3276 | struct objfile *objfile; | |
3277 | ||
3278 | set_current_program_space (pspace); | |
3279 | ||
3280 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3281 | { |
af02033e PP |
3282 | int i; |
3283 | struct gdbarch *gdbarch; | |
17450429 | 3284 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3285 | |
af02033e | 3286 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3287 | |
17450429 PP |
3288 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3289 | ||
28106bc2 SDJ |
3290 | if (!bp_objfile_data->longjmp_searched) |
3291 | { | |
25f9533e SDJ |
3292 | VEC (probe_p) *ret; |
3293 | ||
3294 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3295 | if (ret != NULL) | |
3296 | { | |
3297 | /* We are only interested in checking one element. */ | |
3298 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3299 | ||
3300 | if (!can_evaluate_probe_arguments (p)) | |
3301 | { | |
3302 | /* We cannot use the probe interface here, because it does | |
3303 | not know how to evaluate arguments. */ | |
3304 | VEC_free (probe_p, ret); | |
3305 | ret = NULL; | |
3306 | } | |
3307 | } | |
3308 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3309 | bp_objfile_data->longjmp_searched = 1; |
3310 | } | |
3311 | ||
3312 | if (bp_objfile_data->longjmp_probes != NULL) | |
3313 | { | |
3314 | int i; | |
3315 | struct probe *probe; | |
3316 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3317 | ||
3318 | for (i = 0; | |
3319 | VEC_iterate (probe_p, | |
3320 | bp_objfile_data->longjmp_probes, | |
3321 | i, probe); | |
3322 | ++i) | |
3323 | { | |
3324 | struct breakpoint *b; | |
3325 | ||
729662a5 TT |
3326 | b = create_internal_breakpoint (gdbarch, |
3327 | get_probe_address (probe, | |
3328 | objfile), | |
28106bc2 SDJ |
3329 | bp_longjmp_master, |
3330 | &internal_breakpoint_ops); | |
3331 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3332 | b->enable_state = bp_disabled; | |
3333 | } | |
3334 | ||
3335 | continue; | |
3336 | } | |
3337 | ||
0569175e TSD |
3338 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3339 | continue; | |
3340 | ||
17450429 | 3341 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3342 | { |
3343 | struct breakpoint *b; | |
af02033e | 3344 | const char *func_name; |
17450429 | 3345 | CORE_ADDR addr; |
6c95b8df | 3346 | |
3b7344d5 | 3347 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3348 | continue; |
0fd8e87f | 3349 | |
17450429 | 3350 | func_name = longjmp_names[i]; |
3b7344d5 | 3351 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3352 | { |
3b7344d5 | 3353 | struct bound_minimal_symbol m; |
17450429 PP |
3354 | |
3355 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3356 | if (m.minsym == NULL) |
17450429 PP |
3357 | { |
3358 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3359 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3360 | continue; |
3361 | } | |
3362 | bp_objfile_data->longjmp_msym[i] = m; | |
3363 | } | |
3364 | ||
77e371c0 | 3365 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3366 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3367 | &internal_breakpoint_ops); | |
af02033e PP |
3368 | b->addr_string = xstrdup (func_name); |
3369 | b->enable_state = bp_disabled; | |
3370 | } | |
0fd8e87f | 3371 | } |
af02033e | 3372 | } |
0fd8e87f | 3373 | update_global_location_list (1); |
6c95b8df PA |
3374 | |
3375 | do_cleanups (old_chain); | |
0fd8e87f UW |
3376 | } |
3377 | ||
af02033e | 3378 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3379 | static void |
af02033e | 3380 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3381 | { |
3382 | struct program_space *pspace; | |
aa7d318d | 3383 | struct cleanup *old_chain; |
af02033e | 3384 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3385 | |
3386 | old_chain = save_current_program_space (); | |
3387 | ||
3388 | ALL_PSPACES (pspace) | |
17450429 PP |
3389 | { |
3390 | struct objfile *objfile; | |
3391 | CORE_ADDR addr; | |
3392 | ||
3393 | set_current_program_space (pspace); | |
3394 | ||
aa7d318d TT |
3395 | ALL_OBJFILES (objfile) |
3396 | { | |
3397 | struct breakpoint *b; | |
17450429 | 3398 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3399 | |
17450429 | 3400 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3401 | |
3b7344d5 | 3402 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3403 | continue; |
3404 | ||
3b7344d5 | 3405 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3406 | { |
3b7344d5 | 3407 | struct bound_minimal_symbol m; |
17450429 PP |
3408 | |
3409 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3410 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3411 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3412 | { |
3413 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3414 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3415 | continue; |
3416 | } | |
3417 | bp_objfile_data->terminate_msym = m; | |
3418 | } | |
aa7d318d | 3419 | |
77e371c0 | 3420 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3421 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3422 | bp_std_terminate_master, |
3423 | &internal_breakpoint_ops); | |
aa7d318d TT |
3424 | b->addr_string = xstrdup (func_name); |
3425 | b->enable_state = bp_disabled; | |
3426 | } | |
17450429 PP |
3427 | } |
3428 | ||
aa7d318d TT |
3429 | update_global_location_list (1); |
3430 | ||
3431 | do_cleanups (old_chain); | |
3432 | } | |
3433 | ||
186c406b TT |
3434 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3435 | ||
70221824 | 3436 | static void |
186c406b TT |
3437 | create_exception_master_breakpoint (void) |
3438 | { | |
3439 | struct objfile *objfile; | |
17450429 | 3440 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3441 | |
3442 | ALL_OBJFILES (objfile) | |
3443 | { | |
17450429 PP |
3444 | struct breakpoint *b; |
3445 | struct gdbarch *gdbarch; | |
3446 | struct breakpoint_objfile_data *bp_objfile_data; | |
3447 | CORE_ADDR addr; | |
3448 | ||
3449 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3450 | ||
28106bc2 SDJ |
3451 | /* We prefer the SystemTap probe point if it exists. */ |
3452 | if (!bp_objfile_data->exception_searched) | |
3453 | { | |
25f9533e SDJ |
3454 | VEC (probe_p) *ret; |
3455 | ||
3456 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3457 | ||
3458 | if (ret != NULL) | |
3459 | { | |
3460 | /* We are only interested in checking one element. */ | |
3461 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3462 | ||
3463 | if (!can_evaluate_probe_arguments (p)) | |
3464 | { | |
3465 | /* We cannot use the probe interface here, because it does | |
3466 | not know how to evaluate arguments. */ | |
3467 | VEC_free (probe_p, ret); | |
3468 | ret = NULL; | |
3469 | } | |
3470 | } | |
3471 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3472 | bp_objfile_data->exception_searched = 1; |
3473 | } | |
3474 | ||
3475 | if (bp_objfile_data->exception_probes != NULL) | |
3476 | { | |
3477 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3478 | int i; | |
3479 | struct probe *probe; | |
3480 | ||
3481 | for (i = 0; | |
3482 | VEC_iterate (probe_p, | |
3483 | bp_objfile_data->exception_probes, | |
3484 | i, probe); | |
3485 | ++i) | |
3486 | { | |
3487 | struct breakpoint *b; | |
3488 | ||
729662a5 TT |
3489 | b = create_internal_breakpoint (gdbarch, |
3490 | get_probe_address (probe, | |
3491 | objfile), | |
28106bc2 SDJ |
3492 | bp_exception_master, |
3493 | &internal_breakpoint_ops); | |
3494 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3495 | b->enable_state = bp_disabled; | |
3496 | } | |
3497 | ||
3498 | continue; | |
3499 | } | |
3500 | ||
3501 | /* Otherwise, try the hook function. */ | |
3502 | ||
3b7344d5 | 3503 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3504 | continue; |
3505 | ||
3506 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3507 | |
3b7344d5 | 3508 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3509 | { |
3b7344d5 | 3510 | struct bound_minimal_symbol debug_hook; |
186c406b | 3511 | |
17450429 | 3512 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3513 | if (debug_hook.minsym == NULL) |
17450429 | 3514 | { |
3b7344d5 | 3515 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3516 | continue; |
3517 | } | |
3518 | ||
3519 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3520 | } |
17450429 | 3521 | |
77e371c0 | 3522 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3523 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3524 | ¤t_target); | |
06edf0c0 PA |
3525 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3526 | &internal_breakpoint_ops); | |
17450429 PP |
3527 | b->addr_string = xstrdup (func_name); |
3528 | b->enable_state = bp_disabled; | |
186c406b TT |
3529 | } |
3530 | ||
3531 | update_global_location_list (1); | |
3532 | } | |
3533 | ||
c906108c | 3534 | void |
fba45db2 | 3535 | update_breakpoints_after_exec (void) |
c906108c | 3536 | { |
35df4500 | 3537 | struct breakpoint *b, *b_tmp; |
876fa593 | 3538 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3539 | |
25b22b0a PA |
3540 | /* We're about to delete breakpoints from GDB's lists. If the |
3541 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3542 | writing the breakpoints' "shadow contents" back into memory. The | |
3543 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3544 | do that. Instead, the target is responsible from marking | |
3545 | breakpoints out as soon as it detects an exec. We don't do that | |
3546 | here instead, because there may be other attempts to delete | |
3547 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3548 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3549 | if (bploc->pspace == current_program_space) |
3550 | gdb_assert (!bploc->inserted); | |
c906108c | 3551 | |
35df4500 | 3552 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3553 | { |
6c95b8df PA |
3554 | if (b->pspace != current_program_space) |
3555 | continue; | |
3556 | ||
4a64f543 | 3557 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3558 | if (b->type == bp_shlib_event) |
3559 | { | |
3560 | delete_breakpoint (b); | |
3561 | continue; | |
3562 | } | |
c906108c | 3563 | |
4a64f543 | 3564 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3565 | if (b->type == bp_jit_event) |
3566 | { | |
3567 | delete_breakpoint (b); | |
3568 | continue; | |
3569 | } | |
3570 | ||
1900040c | 3571 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3572 | as must overlay event and longjmp master breakpoints. */ |
3573 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3574 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3575 | || b->type == bp_exception_master) | |
c4093a6a JM |
3576 | { |
3577 | delete_breakpoint (b); | |
3578 | continue; | |
3579 | } | |
3580 | ||
4a64f543 | 3581 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3582 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3583 | { |
3584 | delete_breakpoint (b); | |
3585 | continue; | |
3586 | } | |
3587 | ||
611c83ae PA |
3588 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3589 | after an exec. */ | |
186c406b | 3590 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3591 | || b->type == bp_longjmp_call_dummy |
186c406b | 3592 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3593 | { |
3594 | delete_breakpoint (b); | |
3595 | continue; | |
3596 | } | |
3597 | ||
ce78b96d JB |
3598 | if (b->type == bp_catchpoint) |
3599 | { | |
3600 | /* For now, none of the bp_catchpoint breakpoints need to | |
3601 | do anything at this point. In the future, if some of | |
3602 | the catchpoints need to something, we will need to add | |
3603 | a new method, and call this method from here. */ | |
3604 | continue; | |
3605 | } | |
3606 | ||
c5aa993b JM |
3607 | /* bp_finish is a special case. The only way we ought to be able |
3608 | to see one of these when an exec() has happened, is if the user | |
3609 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3610 | carries them to the call-site of the current callee, by setting | |
3611 | a temporary bp there and resuming. But in this case, the finish | |
3612 | will carry them entirely through the vfork & exec. | |
3613 | ||
3614 | We don't want to allow a bp_finish to remain inserted now. But | |
3615 | we can't safely delete it, 'cause finish_command has a handle to | |
3616 | the bp on a bpstat, and will later want to delete it. There's a | |
3617 | chance (and I've seen it happen) that if we delete the bp_finish | |
3618 | here, that its storage will get reused by the time finish_command | |
3619 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3620 | We really must allow finish_command to delete a bp_finish. | |
3621 | ||
e5dd4106 | 3622 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3623 | it's safe to delete something others may have handles to?" |
3624 | problem, what we'll do here is just uninsert the bp_finish, and | |
3625 | let finish_command delete it. | |
3626 | ||
3627 | (We know the bp_finish is "doomed" in the sense that it's | |
3628 | momentary, and will be deleted as soon as finish_command sees | |
3629 | the inferior stopped. So it doesn't matter that the bp's | |
3630 | address is probably bogus in the new a.out, unlike e.g., the | |
3631 | solib breakpoints.) */ | |
c5aa993b | 3632 | |
c5aa993b JM |
3633 | if (b->type == bp_finish) |
3634 | { | |
3635 | continue; | |
3636 | } | |
3637 | ||
3638 | /* Without a symbolic address, we have little hope of the | |
3639 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3640 | a.out. */ |
c5aa993b JM |
3641 | if (b->addr_string == NULL) |
3642 | { | |
3643 | delete_breakpoint (b); | |
3644 | continue; | |
3645 | } | |
c5aa993b | 3646 | } |
1900040c | 3647 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3648 | create_overlay_event_breakpoint (); |
3649 | create_longjmp_master_breakpoint (); | |
3650 | create_std_terminate_master_breakpoint (); | |
186c406b | 3651 | create_exception_master_breakpoint (); |
c906108c SS |
3652 | } |
3653 | ||
3654 | int | |
d80ee84f | 3655 | detach_breakpoints (ptid_t ptid) |
c906108c | 3656 | { |
35df4500 | 3657 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3658 | int val = 0; |
ce696e05 | 3659 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3660 | struct inferior *inf = current_inferior (); |
c5aa993b | 3661 | |
dfd4cc63 | 3662 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3663 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3664 | |
6c95b8df | 3665 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3666 | inferior_ptid = ptid; |
35df4500 | 3667 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3668 | { |
35df4500 | 3669 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3670 | continue; |
3671 | ||
bd9673a4 PW |
3672 | /* This function must physically remove breakpoints locations |
3673 | from the specified ptid, without modifying the breakpoint | |
3674 | package's state. Locations of type bp_loc_other are only | |
3675 | maintained at GDB side. So, there is no need to remove | |
3676 | these bp_loc_other locations. Moreover, removing these | |
3677 | would modify the breakpoint package's state. */ | |
3678 | if (bl->loc_type == bp_loc_other) | |
3679 | continue; | |
3680 | ||
35df4500 TJB |
3681 | if (bl->inserted) |
3682 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3683 | } |
d03285ec UW |
3684 | |
3685 | /* Detach single-step breakpoints as well. */ | |
3686 | detach_single_step_breakpoints (); | |
3687 | ||
ce696e05 | 3688 | do_cleanups (old_chain); |
3a1bae8e | 3689 | return val; |
c906108c SS |
3690 | } |
3691 | ||
35df4500 | 3692 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3693 | Note that this is used to detach breakpoints from a child fork. |
3694 | When we get here, the child isn't in the inferior list, and neither | |
3695 | do we have objects to represent its address space --- we should | |
35df4500 | 3696 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3697 | |
c906108c | 3698 | static int |
35df4500 | 3699 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3700 | { |
3701 | int val; | |
c5aa993b | 3702 | |
35df4500 TJB |
3703 | /* BL is never in moribund_locations by our callers. */ |
3704 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3705 | |
35df4500 | 3706 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3707 | /* Permanent breakpoints cannot be inserted or removed. */ |
3708 | return 0; | |
3709 | ||
74960c60 VP |
3710 | /* The type of none suggests that owner is actually deleted. |
3711 | This should not ever happen. */ | |
35df4500 | 3712 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3713 | |
35df4500 TJB |
3714 | if (bl->loc_type == bp_loc_software_breakpoint |
3715 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3716 | { |
c02f5703 MS |
3717 | /* "Normal" instruction breakpoint: either the standard |
3718 | trap-instruction bp (bp_breakpoint), or a | |
3719 | bp_hardware_breakpoint. */ | |
3720 | ||
3721 | /* First check to see if we have to handle an overlay. */ | |
3722 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3723 | || bl->section == NULL |
3724 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3725 | { |
3726 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3727 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3728 | } |
c906108c SS |
3729 | else |
3730 | { | |
4a64f543 | 3731 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3732 | Did we set a breakpoint at the LMA? */ |
3733 | if (!overlay_events_enabled) | |
3734 | { | |
3735 | /* Yes -- overlay event support is not active, so we | |
3736 | should have set a breakpoint at the LMA. Remove it. | |
3737 | */ | |
c02f5703 MS |
3738 | /* Ignore any failures: if the LMA is in ROM, we will |
3739 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3740 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3741 | target_remove_hw_breakpoint (bl->gdbarch, | |
3742 | &bl->overlay_target_info); | |
c02f5703 | 3743 | else |
35df4500 TJB |
3744 | target_remove_breakpoint (bl->gdbarch, |
3745 | &bl->overlay_target_info); | |
c02f5703 MS |
3746 | } |
3747 | /* Did we set a breakpoint at the VMA? | |
3748 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3749 | if (bl->inserted) |
c906108c | 3750 | { |
c02f5703 MS |
3751 | /* Yes -- remove it. Previously we did not bother to |
3752 | remove the breakpoint if the section had been | |
3753 | unmapped, but let's not rely on that being safe. We | |
3754 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3755 | |
3756 | /* However, we should remove *software* breakpoints only | |
3757 | if the section is still mapped, or else we overwrite | |
3758 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3759 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3760 | || section_is_mapped (bl->section)) | |
3761 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3762 | else |
3763 | val = 0; | |
c906108c | 3764 | } |
c02f5703 MS |
3765 | else |
3766 | { | |
3767 | /* No -- not inserted, so no need to remove. No error. */ | |
3768 | val = 0; | |
3769 | } | |
c906108c | 3770 | } |
879d1e6b UW |
3771 | |
3772 | /* In some cases, we might not be able to remove a breakpoint | |
3773 | in a shared library that has already been removed, but we | |
3774 | have not yet processed the shlib unload event. */ | |
35df4500 | 3775 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3776 | val = 0; |
3777 | ||
c906108c SS |
3778 | if (val) |
3779 | return val; | |
35df4500 | 3780 | bl->inserted = (is == mark_inserted); |
c906108c | 3781 | } |
35df4500 | 3782 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3783 | { |
77b06cd7 TJB |
3784 | gdb_assert (bl->owner->ops != NULL |
3785 | && bl->owner->ops->remove_location != NULL); | |
3786 | ||
35df4500 | 3787 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3788 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3789 | |
c906108c | 3790 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3791 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3792 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3793 | bl->owner->number); |
c906108c | 3794 | } |
35df4500 TJB |
3795 | else if (bl->owner->type == bp_catchpoint |
3796 | && breakpoint_enabled (bl->owner) | |
3797 | && !bl->duplicate) | |
ce78b96d | 3798 | { |
77b06cd7 TJB |
3799 | gdb_assert (bl->owner->ops != NULL |
3800 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3801 | |
77b06cd7 | 3802 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3803 | if (val) |
3804 | return val; | |
77b06cd7 | 3805 | |
35df4500 | 3806 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3807 | } |
c906108c SS |
3808 | |
3809 | return 0; | |
3810 | } | |
3811 | ||
6c95b8df | 3812 | static int |
35df4500 | 3813 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3814 | { |
3815 | int ret; | |
3816 | struct cleanup *old_chain; | |
3817 | ||
35df4500 TJB |
3818 | /* BL is never in moribund_locations by our callers. */ |
3819 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3820 | |
35df4500 | 3821 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3822 | /* Permanent breakpoints cannot be inserted or removed. */ |
3823 | return 0; | |
3824 | ||
3825 | /* The type of none suggests that owner is actually deleted. | |
3826 | This should not ever happen. */ | |
35df4500 | 3827 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3828 | |
3829 | old_chain = save_current_space_and_thread (); | |
3830 | ||
35df4500 | 3831 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3832 | |
35df4500 | 3833 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3834 | |
3835 | do_cleanups (old_chain); | |
3836 | return ret; | |
3837 | } | |
3838 | ||
c906108c SS |
3839 | /* Clear the "inserted" flag in all breakpoints. */ |
3840 | ||
25b22b0a | 3841 | void |
fba45db2 | 3842 | mark_breakpoints_out (void) |
c906108c | 3843 | { |
35df4500 | 3844 | struct bp_location *bl, **blp_tmp; |
c906108c | 3845 | |
35df4500 TJB |
3846 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3847 | if (bl->pspace == current_program_space) | |
3848 | bl->inserted = 0; | |
c906108c SS |
3849 | } |
3850 | ||
53a5351d JM |
3851 | /* Clear the "inserted" flag in all breakpoints and delete any |
3852 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3853 | |
3854 | Plus other such housekeeping that has to be done for breakpoints | |
3855 | between runs. | |
3856 | ||
53a5351d JM |
3857 | Note: this function gets called at the end of a run (by |
3858 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3859 | init_wait_for_inferior). */ |
c906108c SS |
3860 | |
3861 | ||
3862 | ||
3863 | void | |
fba45db2 | 3864 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3865 | { |
35df4500 TJB |
3866 | struct breakpoint *b, *b_tmp; |
3867 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3868 | int ix; |
6c95b8df | 3869 | struct program_space *pspace = current_program_space; |
c906108c | 3870 | |
50c71eaf PA |
3871 | /* If breakpoint locations are shared across processes, then there's |
3872 | nothing to do. */ | |
f5656ead | 3873 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3874 | return; |
3875 | ||
35df4500 | 3876 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3877 | { |
35df4500 TJB |
3878 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3879 | if (bl->pspace == pspace | |
3880 | && bl->owner->enable_state != bp_permanent) | |
3881 | bl->inserted = 0; | |
6c95b8df | 3882 | } |
075f6582 | 3883 | |
35df4500 | 3884 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3885 | { |
6c95b8df PA |
3886 | if (b->loc && b->loc->pspace != pspace) |
3887 | continue; | |
3888 | ||
c5aa993b JM |
3889 | switch (b->type) |
3890 | { | |
3891 | case bp_call_dummy: | |
e2e4d78b | 3892 | case bp_longjmp_call_dummy: |
c906108c | 3893 | |
c5aa993b | 3894 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3895 | cause problems when the inferior is rerun, so we better get |
3896 | rid of it. */ | |
3897 | ||
3898 | case bp_watchpoint_scope: | |
3899 | ||
3900 | /* Also get rid of scope breakpoints. */ | |
3901 | ||
3902 | case bp_shlib_event: | |
3903 | ||
3904 | /* Also remove solib event breakpoints. Their addresses may | |
3905 | have changed since the last time we ran the program. | |
3906 | Actually we may now be debugging against different target; | |
3907 | and so the solib backend that installed this breakpoint may | |
3908 | not be used in by the target. E.g., | |
3909 | ||
3910 | (gdb) file prog-linux | |
3911 | (gdb) run # native linux target | |
3912 | ... | |
3913 | (gdb) kill | |
3914 | (gdb) file prog-win.exe | |
3915 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3916 | */ | |
c906108c | 3917 | |
f59f708a PA |
3918 | case bp_step_resume: |
3919 | ||
3920 | /* Also remove step-resume breakpoints. */ | |
3921 | ||
c5aa993b JM |
3922 | delete_breakpoint (b); |
3923 | break; | |
c906108c | 3924 | |
c5aa993b JM |
3925 | case bp_watchpoint: |
3926 | case bp_hardware_watchpoint: | |
3927 | case bp_read_watchpoint: | |
3928 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3929 | { |
3930 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3931 | |
3a5c3e22 PA |
3932 | /* Likewise for watchpoints on local expressions. */ |
3933 | if (w->exp_valid_block != NULL) | |
3934 | delete_breakpoint (b); | |
3935 | else if (context == inf_starting) | |
3936 | { | |
3937 | /* Reset val field to force reread of starting value in | |
3938 | insert_breakpoints. */ | |
3939 | if (w->val) | |
3940 | value_free (w->val); | |
3941 | w->val = NULL; | |
3942 | w->val_valid = 0; | |
c860120c | 3943 | } |
3a5c3e22 | 3944 | } |
c5aa993b JM |
3945 | break; |
3946 | default: | |
c5aa993b JM |
3947 | break; |
3948 | } | |
3949 | } | |
1c5cfe86 PA |
3950 | |
3951 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3952 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3953 | decref_bp_location (&bl); | |
1c5cfe86 | 3954 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3955 | } |
3956 | ||
6c95b8df PA |
3957 | /* These functions concern about actual breakpoints inserted in the |
3958 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3959 | we need to hop over the bkpt --- so we check for address space | |
3960 | match, not program space. */ | |
3961 | ||
c2c6d25f JM |
3962 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3963 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3964 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3965 | permanent breakpoint. | |
3966 | - When continuing from a location with an ordinary breakpoint, we | |
3967 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3968 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3969 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3970 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3971 | |
c2c6d25f | 3972 | enum breakpoint_here |
6c95b8df | 3973 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3974 | { |
35df4500 | 3975 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3976 | int any_breakpoint_here = 0; |
c906108c | 3977 | |
35df4500 | 3978 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3979 | { |
35df4500 TJB |
3980 | if (bl->loc_type != bp_loc_software_breakpoint |
3981 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3982 | continue; |
3983 | ||
f1310107 | 3984 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3985 | if ((breakpoint_enabled (bl->owner) |
3986 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3987 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3988 | { |
3989 | if (overlay_debugging | |
35df4500 TJB |
3990 | && section_is_overlay (bl->section) |
3991 | && !section_is_mapped (bl->section)) | |
075f6582 | 3992 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3993 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3994 | return permanent_breakpoint_here; |
3995 | else | |
3996 | any_breakpoint_here = 1; | |
3997 | } | |
3998 | } | |
c906108c | 3999 | |
c2c6d25f | 4000 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4001 | } |
4002 | ||
1c5cfe86 PA |
4003 | /* Return true if there's a moribund breakpoint at PC. */ |
4004 | ||
4005 | int | |
6c95b8df | 4006 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4007 | { |
4008 | struct bp_location *loc; | |
4009 | int ix; | |
4010 | ||
4011 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4012 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4013 | return 1; |
4014 | ||
4015 | return 0; | |
4016 | } | |
c2c6d25f | 4017 | |
c36b740a | 4018 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
4019 | inserted using regular breakpoint_chain / bp_location array |
4020 | mechanism. This does not check for single-step breakpoints, which | |
4021 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
4022 | |
4023 | int | |
4a64f543 MS |
4024 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
4025 | CORE_ADDR pc) | |
c906108c | 4026 | { |
35df4500 | 4027 | struct bp_location *bl, **blp_tmp; |
c906108c | 4028 | |
35df4500 | 4029 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4030 | { |
35df4500 TJB |
4031 | if (bl->loc_type != bp_loc_software_breakpoint |
4032 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4033 | continue; |
4034 | ||
35df4500 | 4035 | if (bl->inserted |
f1310107 | 4036 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4037 | { |
4038 | if (overlay_debugging | |
35df4500 TJB |
4039 | && section_is_overlay (bl->section) |
4040 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4041 | continue; /* unmapped overlay -- can't be a match */ |
4042 | else | |
4043 | return 1; | |
4044 | } | |
c5aa993b | 4045 | } |
c36b740a VP |
4046 | return 0; |
4047 | } | |
4048 | ||
4049 | /* Returns non-zero iff there's either regular breakpoint | |
4050 | or a single step breakpoint inserted at PC. */ | |
4051 | ||
4052 | int | |
6c95b8df | 4053 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 4054 | { |
6c95b8df | 4055 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4056 | return 1; |
c906108c | 4057 | |
6c95b8df | 4058 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4059 | return 1; |
4060 | ||
c906108c SS |
4061 | return 0; |
4062 | } | |
4063 | ||
4fa8626c DJ |
4064 | /* This function returns non-zero iff there is a software breakpoint |
4065 | inserted at PC. */ | |
4066 | ||
4067 | int | |
3e43a32a MS |
4068 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4069 | CORE_ADDR pc) | |
4fa8626c | 4070 | { |
35df4500 | 4071 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4072 | |
35df4500 | 4073 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4074 | { |
35df4500 | 4075 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4076 | continue; |
4077 | ||
35df4500 TJB |
4078 | if (bl->inserted |
4079 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4080 | aspace, pc)) |
4fa8626c DJ |
4081 | { |
4082 | if (overlay_debugging | |
35df4500 TJB |
4083 | && section_is_overlay (bl->section) |
4084 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4085 | continue; /* unmapped overlay -- can't be a match */ |
4086 | else | |
4087 | return 1; | |
4088 | } | |
4089 | } | |
4090 | ||
1aafd4da | 4091 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4092 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4093 | return 1; |
4094 | ||
4fa8626c DJ |
4095 | return 0; |
4096 | } | |
4097 | ||
9093389c PA |
4098 | int |
4099 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4100 | CORE_ADDR addr, ULONGEST len) | |
4101 | { | |
4102 | struct breakpoint *bpt; | |
4103 | ||
4104 | ALL_BREAKPOINTS (bpt) | |
4105 | { | |
4106 | struct bp_location *loc; | |
4107 | ||
4108 | if (bpt->type != bp_hardware_watchpoint | |
4109 | && bpt->type != bp_access_watchpoint) | |
4110 | continue; | |
4111 | ||
4112 | if (!breakpoint_enabled (bpt)) | |
4113 | continue; | |
4114 | ||
4115 | for (loc = bpt->loc; loc; loc = loc->next) | |
4116 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4117 | { | |
4118 | CORE_ADDR l, h; | |
4119 | ||
4120 | /* Check for intersection. */ | |
4121 | l = max (loc->address, addr); | |
4122 | h = min (loc->address + loc->length, addr + len); | |
4123 | if (l < h) | |
4124 | return 1; | |
4125 | } | |
4126 | } | |
4127 | return 0; | |
4128 | } | |
4129 | ||
075f6582 DJ |
4130 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4131 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4132 | |
4133 | int | |
6c95b8df PA |
4134 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4135 | ptid_t ptid) | |
c906108c | 4136 | { |
35df4500 | 4137 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4138 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4139 | int thread = -1; |
4a306c9a | 4140 | int task = 0; |
a6f1cd96 | 4141 | |
35df4500 | 4142 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4143 | { |
35df4500 TJB |
4144 | if (bl->loc_type != bp_loc_software_breakpoint |
4145 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4146 | continue; |
4147 | ||
35df4500 TJB |
4148 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4149 | if (!breakpoint_enabled (bl->owner) | |
4150 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4151 | continue; |
4152 | ||
f1310107 | 4153 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4154 | continue; |
4155 | ||
35df4500 | 4156 | if (bl->owner->thread != -1) |
075f6582 | 4157 | { |
a6f1cd96 JB |
4158 | /* This is a thread-specific breakpoint. Check that ptid |
4159 | matches that thread. If thread hasn't been computed yet, | |
4160 | it is now time to do so. */ | |
4161 | if (thread == -1) | |
4162 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4163 | if (bl->owner->thread != thread) |
a6f1cd96 | 4164 | continue; |
075f6582 | 4165 | } |
a6f1cd96 | 4166 | |
35df4500 | 4167 | if (bl->owner->task != 0) |
4a306c9a JB |
4168 | { |
4169 | /* This is a task-specific breakpoint. Check that ptid | |
4170 | matches that task. If task hasn't been computed yet, | |
4171 | it is now time to do so. */ | |
4172 | if (task == 0) | |
4173 | task = ada_get_task_number (ptid); | |
35df4500 | 4174 | if (bl->owner->task != task) |
4a306c9a JB |
4175 | continue; |
4176 | } | |
4177 | ||
a6f1cd96 | 4178 | if (overlay_debugging |
35df4500 TJB |
4179 | && section_is_overlay (bl->section) |
4180 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4181 | continue; /* unmapped overlay -- can't be a match */ |
4182 | ||
4183 | return 1; | |
c5aa993b | 4184 | } |
c906108c SS |
4185 | |
4186 | return 0; | |
4187 | } | |
c906108c | 4188 | \f |
c5aa993b | 4189 | |
c906108c SS |
4190 | /* bpstat stuff. External routines' interfaces are documented |
4191 | in breakpoint.h. */ | |
4192 | ||
4193 | int | |
c326b90e | 4194 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4195 | { |
533be4dd | 4196 | return (ep->type == bp_catchpoint); |
c906108c SS |
4197 | } |
4198 | ||
f431efe5 PA |
4199 | /* Frees any storage that is part of a bpstat. Does not walk the |
4200 | 'next' chain. */ | |
4201 | ||
4202 | static void | |
198757a8 VP |
4203 | bpstat_free (bpstat bs) |
4204 | { | |
4205 | if (bs->old_val != NULL) | |
4206 | value_free (bs->old_val); | |
9add0f1b | 4207 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4208 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4209 | xfree (bs); |
4210 | } | |
4211 | ||
c906108c SS |
4212 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4213 | Also free any storage that is part of a bpstat. */ | |
4214 | ||
4215 | void | |
fba45db2 | 4216 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4217 | { |
4218 | bpstat p; | |
4219 | bpstat q; | |
4220 | ||
4221 | if (bsp == 0) | |
4222 | return; | |
4223 | p = *bsp; | |
4224 | while (p != NULL) | |
4225 | { | |
4226 | q = p->next; | |
198757a8 | 4227 | bpstat_free (p); |
c906108c SS |
4228 | p = q; |
4229 | } | |
4230 | *bsp = NULL; | |
4231 | } | |
4232 | ||
4233 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4234 | is part of the bpstat is copied as well. */ | |
4235 | ||
4236 | bpstat | |
fba45db2 | 4237 | bpstat_copy (bpstat bs) |
c906108c SS |
4238 | { |
4239 | bpstat p = NULL; | |
4240 | bpstat tmp; | |
4241 | bpstat retval = NULL; | |
4242 | ||
4243 | if (bs == NULL) | |
4244 | return bs; | |
4245 | ||
4246 | for (; bs != NULL; bs = bs->next) | |
4247 | { | |
4248 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4249 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4250 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4251 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4252 | if (bs->old_val != NULL) |
3c3185ac JK |
4253 | { |
4254 | tmp->old_val = value_copy (bs->old_val); | |
4255 | release_value (tmp->old_val); | |
4256 | } | |
31cc81e9 | 4257 | |
c906108c SS |
4258 | if (p == NULL) |
4259 | /* This is the first thing in the chain. */ | |
4260 | retval = tmp; | |
4261 | else | |
4262 | p->next = tmp; | |
4263 | p = tmp; | |
4264 | } | |
4265 | p->next = NULL; | |
4266 | return retval; | |
4267 | } | |
4268 | ||
4a64f543 | 4269 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4270 | |
4271 | bpstat | |
fba45db2 | 4272 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4273 | { |
c5aa993b JM |
4274 | if (bsp == NULL) |
4275 | return NULL; | |
c906108c | 4276 | |
c5aa993b JM |
4277 | for (; bsp != NULL; bsp = bsp->next) |
4278 | { | |
f431efe5 | 4279 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4280 | return bsp; |
4281 | } | |
c906108c SS |
4282 | return NULL; |
4283 | } | |
4284 | ||
ab04a2af TT |
4285 | /* See breakpoint.h. */ |
4286 | ||
47591c29 | 4287 | int |
427cd150 | 4288 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4289 | { |
ab04a2af TT |
4290 | for (; bsp != NULL; bsp = bsp->next) |
4291 | { | |
427cd150 TT |
4292 | if (bsp->breakpoint_at == NULL) |
4293 | { | |
4294 | /* A moribund location can never explain a signal other than | |
4295 | GDB_SIGNAL_TRAP. */ | |
4296 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4297 | return 1; |
427cd150 TT |
4298 | } |
4299 | else | |
47591c29 PA |
4300 | { |
4301 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4302 | sig)) | |
4303 | return 1; | |
4304 | } | |
ab04a2af TT |
4305 | } |
4306 | ||
47591c29 | 4307 | return 0; |
ab04a2af TT |
4308 | } |
4309 | ||
4a64f543 MS |
4310 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4311 | stopped at. *BSP upon return is a bpstat which points to the | |
4312 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4313 | good for anything but further calls to bpstat_num). | |
4314 | ||
8671a17b PA |
4315 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4316 | Return -1 if stopped at a breakpoint that has been deleted since | |
4317 | we set it. | |
4318 | Return 1 otherwise. */ | |
c906108c SS |
4319 | |
4320 | int | |
8671a17b | 4321 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4322 | { |
4323 | struct breakpoint *b; | |
4324 | ||
4325 | if ((*bsp) == NULL) | |
4326 | return 0; /* No more breakpoint values */ | |
8671a17b | 4327 | |
4a64f543 MS |
4328 | /* We assume we'll never have several bpstats that correspond to a |
4329 | single breakpoint -- otherwise, this function might return the | |
4330 | same number more than once and this will look ugly. */ | |
f431efe5 | 4331 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4332 | *bsp = (*bsp)->next; |
4333 | if (b == NULL) | |
4334 | return -1; /* breakpoint that's been deleted since */ | |
4335 | ||
4336 | *num = b->number; /* We have its number */ | |
4337 | return 1; | |
c906108c SS |
4338 | } |
4339 | ||
e93ca019 | 4340 | /* See breakpoint.h. */ |
c906108c SS |
4341 | |
4342 | void | |
e93ca019 | 4343 | bpstat_clear_actions (void) |
c906108c | 4344 | { |
e93ca019 JK |
4345 | struct thread_info *tp; |
4346 | bpstat bs; | |
4347 | ||
4348 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4349 | return; | |
4350 | ||
4351 | tp = find_thread_ptid (inferior_ptid); | |
4352 | if (tp == NULL) | |
4353 | return; | |
4354 | ||
4355 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4356 | { |
9add0f1b | 4357 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4358 | |
c906108c SS |
4359 | if (bs->old_val != NULL) |
4360 | { | |
4361 | value_free (bs->old_val); | |
4362 | bs->old_val = NULL; | |
4363 | } | |
4364 | } | |
4365 | } | |
4366 | ||
f3b1572e PA |
4367 | /* Called when a command is about to proceed the inferior. */ |
4368 | ||
4369 | static void | |
4370 | breakpoint_about_to_proceed (void) | |
4371 | { | |
4372 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4373 | { | |
4374 | struct thread_info *tp = inferior_thread (); | |
4375 | ||
4376 | /* Allow inferior function calls in breakpoint commands to not | |
4377 | interrupt the command list. When the call finishes | |
4378 | successfully, the inferior will be standing at the same | |
4379 | breakpoint as if nothing happened. */ | |
16c381f0 | 4380 | if (tp->control.in_infcall) |
f3b1572e PA |
4381 | return; |
4382 | } | |
4383 | ||
4384 | breakpoint_proceeded = 1; | |
4385 | } | |
4386 | ||
4a64f543 MS |
4387 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4388 | command. */ | |
c906108c | 4389 | static void |
4efb68b1 | 4390 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4391 | { |
4392 | executing_breakpoint_commands = 0; | |
4393 | } | |
4394 | ||
abf85f46 JK |
4395 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4396 | or its equivalent. */ | |
4397 | ||
4398 | static int | |
4399 | command_line_is_silent (struct command_line *cmd) | |
4400 | { | |
4401 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4402 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4403 | } | |
4404 | ||
4a64f543 MS |
4405 | /* Execute all the commands associated with all the breakpoints at |
4406 | this location. Any of these commands could cause the process to | |
4407 | proceed beyond this point, etc. We look out for such changes by | |
4408 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4409 | |
347bddb7 PA |
4410 | Returns true if a breakpoint command resumed the inferior. In that |
4411 | case, it is the caller's responsibility to recall it again with the | |
4412 | bpstat of the current thread. */ | |
4413 | ||
4414 | static int | |
4415 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4416 | { |
4417 | bpstat bs; | |
4418 | struct cleanup *old_chain; | |
347bddb7 | 4419 | int again = 0; |
c906108c SS |
4420 | |
4421 | /* Avoid endless recursion if a `source' command is contained | |
4422 | in bs->commands. */ | |
4423 | if (executing_breakpoint_commands) | |
347bddb7 | 4424 | return 0; |
c906108c SS |
4425 | |
4426 | executing_breakpoint_commands = 1; | |
4427 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4428 | ||
cf6c5ffb TT |
4429 | prevent_dont_repeat (); |
4430 | ||
4a64f543 | 4431 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4432 | bs = *bsp; |
4433 | ||
4434 | breakpoint_proceeded = 0; | |
4435 | for (; bs != NULL; bs = bs->next) | |
4436 | { | |
9add0f1b | 4437 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4438 | struct command_line *cmd; |
4439 | struct cleanup *this_cmd_tree_chain; | |
4440 | ||
4441 | /* Take ownership of the BSP's command tree, if it has one. | |
4442 | ||
4443 | The command tree could legitimately contain commands like | |
4444 | 'step' and 'next', which call clear_proceed_status, which | |
4445 | frees stop_bpstat's command tree. To make sure this doesn't | |
4446 | free the tree we're executing out from under us, we need to | |
4447 | take ownership of the tree ourselves. Since a given bpstat's | |
4448 | commands are only executed once, we don't need to copy it; we | |
4449 | can clear the pointer in the bpstat, and make sure we free | |
4450 | the tree when we're done. */ | |
9add0f1b TT |
4451 | ccmd = bs->commands; |
4452 | bs->commands = NULL; | |
abf85f46 JK |
4453 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4454 | cmd = ccmd ? ccmd->commands : NULL; | |
4455 | if (command_line_is_silent (cmd)) | |
4456 | { | |
4457 | /* The action has been already done by bpstat_stop_status. */ | |
4458 | cmd = cmd->next; | |
4459 | } | |
6c50ab1c | 4460 | |
c906108c SS |
4461 | while (cmd != NULL) |
4462 | { | |
4463 | execute_control_command (cmd); | |
4464 | ||
4465 | if (breakpoint_proceeded) | |
4466 | break; | |
4467 | else | |
4468 | cmd = cmd->next; | |
4469 | } | |
6c50ab1c JB |
4470 | |
4471 | /* We can free this command tree now. */ | |
4472 | do_cleanups (this_cmd_tree_chain); | |
4473 | ||
c906108c | 4474 | if (breakpoint_proceeded) |
32c1e744 VP |
4475 | { |
4476 | if (target_can_async_p ()) | |
347bddb7 PA |
4477 | /* If we are in async mode, then the target might be still |
4478 | running, not stopped at any breakpoint, so nothing for | |
4479 | us to do here -- just return to the event loop. */ | |
4480 | ; | |
32c1e744 VP |
4481 | else |
4482 | /* In sync mode, when execute_control_command returns | |
4483 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4484 | Breakpoint commands for that stop were not run, since |
4485 | execute_command does not run breakpoint commands -- | |
4486 | only command_line_handler does, but that one is not | |
4487 | involved in execution of breakpoint commands. So, we | |
4488 | can now execute breakpoint commands. It should be | |
4489 | noted that making execute_command do bpstat actions is | |
4490 | not an option -- in this case we'll have recursive | |
4491 | invocation of bpstat for each breakpoint with a | |
4492 | command, and can easily blow up GDB stack. Instead, we | |
4493 | return true, which will trigger the caller to recall us | |
4494 | with the new stop_bpstat. */ | |
4495 | again = 1; | |
4496 | break; | |
32c1e744 | 4497 | } |
c906108c | 4498 | } |
c2b8ed2c | 4499 | do_cleanups (old_chain); |
347bddb7 PA |
4500 | return again; |
4501 | } | |
4502 | ||
4503 | void | |
4504 | bpstat_do_actions (void) | |
4505 | { | |
353d1d73 JK |
4506 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4507 | ||
347bddb7 PA |
4508 | /* Do any commands attached to breakpoint we are stopped at. */ |
4509 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4510 | && target_has_execution | |
4511 | && !is_exited (inferior_ptid) | |
4512 | && !is_executing (inferior_ptid)) | |
4513 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4514 | and only return when it is stopped at the next breakpoint, we | |
4515 | keep doing breakpoint actions until it returns false to | |
4516 | indicate the inferior was not resumed. */ | |
16c381f0 | 4517 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4518 | break; |
353d1d73 JK |
4519 | |
4520 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4521 | } |
4522 | ||
fa4727a6 DJ |
4523 | /* Print out the (old or new) value associated with a watchpoint. */ |
4524 | ||
4525 | static void | |
4526 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4527 | { | |
4528 | if (val == NULL) | |
4529 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4530 | else | |
79a45b7d TT |
4531 | { |
4532 | struct value_print_options opts; | |
4533 | get_user_print_options (&opts); | |
4534 | value_print (val, stream, &opts); | |
4535 | } | |
fa4727a6 DJ |
4536 | } |
4537 | ||
e514a9d6 | 4538 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4539 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4540 | 'print_it' in the bpstat structure. Under some circumstances we |
4541 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4542 | normal_stop(). */ |
e514a9d6 JM |
4543 | |
4544 | static enum print_stop_action | |
4545 | print_bp_stop_message (bpstat bs) | |
4546 | { | |
4547 | switch (bs->print_it) | |
4548 | { | |
4549 | case print_it_noop: | |
4a64f543 | 4550 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4551 | return PRINT_UNKNOWN; |
4552 | break; | |
4553 | ||
4554 | case print_it_done: | |
4555 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4556 | relevant messages. */ |
e514a9d6 JM |
4557 | return PRINT_SRC_AND_LOC; |
4558 | break; | |
4559 | ||
4560 | case print_it_normal: | |
4f8d1dc6 | 4561 | { |
f431efe5 PA |
4562 | struct breakpoint *b = bs->breakpoint_at; |
4563 | ||
1a6a67de TJB |
4564 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4565 | which has since been deleted. */ | |
4566 | if (b == NULL) | |
4567 | return PRINT_UNKNOWN; | |
4568 | ||
348d480f PA |
4569 | /* Normal case. Call the breakpoint's print_it method. */ |
4570 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4571 | } |
348d480f | 4572 | break; |
3086aeae | 4573 | |
e514a9d6 | 4574 | default: |
8e65ff28 | 4575 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4576 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4577 | break; |
c906108c | 4578 | } |
c906108c SS |
4579 | } |
4580 | ||
edcc5120 TT |
4581 | /* A helper function that prints a shared library stopped event. */ |
4582 | ||
4583 | static void | |
4584 | print_solib_event (int is_catchpoint) | |
4585 | { | |
4586 | int any_deleted | |
4587 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4588 | int any_added | |
4589 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4590 | ||
4591 | if (!is_catchpoint) | |
4592 | { | |
4593 | if (any_added || any_deleted) | |
4594 | ui_out_text (current_uiout, | |
4595 | _("Stopped due to shared library event:\n")); | |
4596 | else | |
4597 | ui_out_text (current_uiout, | |
4598 | _("Stopped due to shared library event (no " | |
4599 | "libraries added or removed)\n")); | |
4600 | } | |
4601 | ||
4602 | if (ui_out_is_mi_like_p (current_uiout)) | |
4603 | ui_out_field_string (current_uiout, "reason", | |
4604 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4605 | ||
4606 | if (any_deleted) | |
4607 | { | |
4608 | struct cleanup *cleanup; | |
4609 | char *name; | |
4610 | int ix; | |
4611 | ||
4612 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4613 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4614 | "removed"); | |
4615 | for (ix = 0; | |
4616 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4617 | ix, name); | |
4618 | ++ix) | |
4619 | { | |
4620 | if (ix > 0) | |
4621 | ui_out_text (current_uiout, " "); | |
4622 | ui_out_field_string (current_uiout, "library", name); | |
4623 | ui_out_text (current_uiout, "\n"); | |
4624 | } | |
4625 | ||
4626 | do_cleanups (cleanup); | |
4627 | } | |
4628 | ||
4629 | if (any_added) | |
4630 | { | |
4631 | struct so_list *iter; | |
4632 | int ix; | |
4633 | struct cleanup *cleanup; | |
4634 | ||
4635 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4636 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4637 | "added"); | |
4638 | for (ix = 0; | |
4639 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4640 | ix, iter); | |
4641 | ++ix) | |
4642 | { | |
4643 | if (ix > 0) | |
4644 | ui_out_text (current_uiout, " "); | |
4645 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4646 | ui_out_text (current_uiout, "\n"); | |
4647 | } | |
4648 | ||
4649 | do_cleanups (cleanup); | |
4650 | } | |
4651 | } | |
4652 | ||
e514a9d6 JM |
4653 | /* Print a message indicating what happened. This is called from |
4654 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4655 | list - a list of the eventpoints that caused this stop. KIND is |
4656 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4657 | routine calls the generic print routine for printing a message |
4658 | about reasons for stopping. This will print (for example) the | |
4659 | "Breakpoint n," part of the output. The return value of this | |
4660 | routine is one of: | |
c906108c | 4661 | |
4a64f543 | 4662 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4663 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4664 | code to print the location. An example is |
c5aa993b JM |
4665 | "Breakpoint 1, " which should be followed by |
4666 | the location. | |
917317f4 | 4667 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4668 | to also print the location part of the message. |
4669 | An example is the catch/throw messages, which | |
4a64f543 | 4670 | don't require a location appended to the end. |
917317f4 | 4671 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4672 | further info to be printed. */ |
c906108c | 4673 | |
917317f4 | 4674 | enum print_stop_action |
36dfb11c | 4675 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4676 | { |
4677 | int val; | |
c5aa993b | 4678 | |
c906108c | 4679 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4680 | (Currently all watchpoints go on the bpstat whether hit or not. |
4681 | That probably could (should) be changed, provided care is taken | |
c906108c | 4682 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4683 | for (; bs; bs = bs->next) |
4684 | { | |
4685 | val = print_bp_stop_message (bs); | |
4686 | if (val == PRINT_SRC_ONLY | |
4687 | || val == PRINT_SRC_AND_LOC | |
4688 | || val == PRINT_NOTHING) | |
4689 | return val; | |
4690 | } | |
c906108c | 4691 | |
36dfb11c TT |
4692 | /* If we had hit a shared library event breakpoint, |
4693 | print_bp_stop_message would print out this message. If we hit an | |
4694 | OS-level shared library event, do the same thing. */ | |
4695 | if (kind == TARGET_WAITKIND_LOADED) | |
4696 | { | |
edcc5120 | 4697 | print_solib_event (0); |
36dfb11c TT |
4698 | return PRINT_NOTHING; |
4699 | } | |
4700 | ||
e514a9d6 | 4701 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4702 | with and nothing was printed. */ |
917317f4 | 4703 | return PRINT_UNKNOWN; |
c906108c SS |
4704 | } |
4705 | ||
c42bd95a DE |
4706 | /* Evaluate the expression EXP and return 1 if value is zero. |
4707 | This returns the inverse of the condition because it is called | |
4708 | from catch_errors which returns 0 if an exception happened, and if an | |
4709 | exception happens we want execution to stop. | |
4a64f543 | 4710 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4711 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4712 | |
4713 | static int | |
4efb68b1 | 4714 | breakpoint_cond_eval (void *exp) |
c906108c | 4715 | { |
278cd55f | 4716 | struct value *mark = value_mark (); |
c5aa993b | 4717 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4718 | |
c906108c SS |
4719 | value_free_to_mark (mark); |
4720 | return i; | |
4721 | } | |
4722 | ||
5760d0ab | 4723 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4724 | |
4725 | static bpstat | |
5760d0ab | 4726 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4727 | { |
4728 | bpstat bs; | |
4729 | ||
4730 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4731 | bs->next = NULL; |
4732 | **bs_link_pointer = bs; | |
4733 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4734 | bs->breakpoint_at = bl->owner; |
4735 | bs->bp_location_at = bl; | |
4736 | incref_bp_location (bl); | |
c906108c SS |
4737 | /* If the condition is false, etc., don't do the commands. */ |
4738 | bs->commands = NULL; | |
4739 | bs->old_val = NULL; | |
4740 | bs->print_it = print_it_normal; | |
4741 | return bs; | |
4742 | } | |
4743 | \f | |
d983da9c DJ |
4744 | /* The target has stopped with waitstatus WS. Check if any hardware |
4745 | watchpoints have triggered, according to the target. */ | |
4746 | ||
4747 | int | |
4748 | watchpoints_triggered (struct target_waitstatus *ws) | |
4749 | { | |
d92524f1 | 4750 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4751 | CORE_ADDR addr; |
4752 | struct breakpoint *b; | |
4753 | ||
4754 | if (!stopped_by_watchpoint) | |
4755 | { | |
4756 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4757 | as not triggered. */ | |
4758 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4759 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4760 | { |
4761 | struct watchpoint *w = (struct watchpoint *) b; | |
4762 | ||
4763 | w->watchpoint_triggered = watch_triggered_no; | |
4764 | } | |
d983da9c DJ |
4765 | |
4766 | return 0; | |
4767 | } | |
4768 | ||
4769 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4770 | { | |
4771 | /* We were stopped by a watchpoint, but we don't know where. | |
4772 | Mark all watchpoints as unknown. */ | |
4773 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4774 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4775 | { |
4776 | struct watchpoint *w = (struct watchpoint *) b; | |
4777 | ||
4778 | w->watchpoint_triggered = watch_triggered_unknown; | |
4779 | } | |
d983da9c | 4780 | |
3c4797ba | 4781 | return 1; |
d983da9c DJ |
4782 | } |
4783 | ||
4784 | /* The target could report the data address. Mark watchpoints | |
4785 | affected by this data address as triggered, and all others as not | |
4786 | triggered. */ | |
4787 | ||
4788 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4789 | if (is_hardware_watchpoint (b)) |
d983da9c | 4790 | { |
3a5c3e22 | 4791 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4792 | struct bp_location *loc; |
d983da9c | 4793 | |
3a5c3e22 | 4794 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4795 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4796 | { |
3a5c3e22 | 4797 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4798 | { |
3a5c3e22 PA |
4799 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4800 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4801 | |
4802 | if (newaddr == start) | |
4803 | { | |
3a5c3e22 | 4804 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4805 | break; |
4806 | } | |
4807 | } | |
4808 | /* Exact match not required. Within range is sufficient. */ | |
4809 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4810 | addr, loc->address, | |
4811 | loc->length)) | |
4812 | { | |
3a5c3e22 | 4813 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4814 | break; |
4815 | } | |
4816 | } | |
d983da9c DJ |
4817 | } |
4818 | ||
4819 | return 1; | |
4820 | } | |
4821 | ||
c906108c SS |
4822 | /* Possible return values for watchpoint_check (this can't be an enum |
4823 | because of check_errors). */ | |
4824 | /* The watchpoint has been deleted. */ | |
4825 | #define WP_DELETED 1 | |
4826 | /* The value has changed. */ | |
4827 | #define WP_VALUE_CHANGED 2 | |
4828 | /* The value has not changed. */ | |
4829 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4830 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4831 | #define WP_IGNORE 4 | |
c906108c SS |
4832 | |
4833 | #define BP_TEMPFLAG 1 | |
4834 | #define BP_HARDWAREFLAG 2 | |
4835 | ||
4a64f543 MS |
4836 | /* Evaluate watchpoint condition expression and check if its value |
4837 | changed. | |
553e4c11 JB |
4838 | |
4839 | P should be a pointer to struct bpstat, but is defined as a void * | |
4840 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4841 | |
4842 | static int | |
4efb68b1 | 4843 | watchpoint_check (void *p) |
c906108c SS |
4844 | { |
4845 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4846 | struct watchpoint *b; |
c906108c SS |
4847 | struct frame_info *fr; |
4848 | int within_current_scope; | |
4849 | ||
f431efe5 | 4850 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4851 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4852 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4853 | |
f6bc2008 PA |
4854 | /* If this is a local watchpoint, we only want to check if the |
4855 | watchpoint frame is in scope if the current thread is the thread | |
4856 | that was used to create the watchpoint. */ | |
4857 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4858 | return WP_IGNORE; |
f6bc2008 | 4859 | |
c906108c SS |
4860 | if (b->exp_valid_block == NULL) |
4861 | within_current_scope = 1; | |
4862 | else | |
4863 | { | |
edb3359d DJ |
4864 | struct frame_info *frame = get_current_frame (); |
4865 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4866 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4867 | ||
4a64f543 MS |
4868 | /* in_function_epilogue_p() returns a non-zero value if we're |
4869 | still in the function but the stack frame has already been | |
4870 | invalidated. Since we can't rely on the values of local | |
4871 | variables after the stack has been destroyed, we are treating | |
4872 | the watchpoint in that state as `not changed' without further | |
4873 | checking. Don't mark watchpoints as changed if the current | |
4874 | frame is in an epilogue - even if they are in some other | |
4875 | frame, our view of the stack is likely to be wrong and | |
4876 | frame_find_by_id could error out. */ | |
a0f49112 | 4877 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4878 | return WP_IGNORE; |
a0f49112 | 4879 | |
101dcfbe | 4880 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4881 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4882 | |
4883 | /* If we've gotten confused in the unwinder, we might have | |
4884 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4885 | if (within_current_scope) |
4886 | { | |
4887 | struct symbol *function; | |
4888 | ||
4889 | function = get_frame_function (fr); | |
4890 | if (function == NULL | |
4891 | || !contained_in (b->exp_valid_block, | |
4892 | SYMBOL_BLOCK_VALUE (function))) | |
4893 | within_current_scope = 0; | |
4894 | } | |
69fbadd5 | 4895 | |
edb3359d | 4896 | if (within_current_scope) |
c906108c SS |
4897 | /* If we end up stopping, the current frame will get selected |
4898 | in normal_stop. So this call to select_frame won't affect | |
4899 | the user. */ | |
0f7d239c | 4900 | select_frame (fr); |
c906108c | 4901 | } |
c5aa993b | 4902 | |
c906108c SS |
4903 | if (within_current_scope) |
4904 | { | |
4a64f543 MS |
4905 | /* We use value_{,free_to_}mark because it could be a *long* |
4906 | time before we return to the command level and call | |
4907 | free_all_values. We can't call free_all_values because we | |
4908 | might be in the middle of evaluating a function call. */ | |
c906108c | 4909 | |
0cf6dd15 | 4910 | int pc = 0; |
9c06b0b4 | 4911 | struct value *mark; |
fa4727a6 DJ |
4912 | struct value *new_val; |
4913 | ||
3a5c3e22 | 4914 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4915 | /* Since we don't know the exact trigger address (from |
4916 | stopped_data_address), just tell the user we've triggered | |
4917 | a mask watchpoint. */ | |
4918 | return WP_VALUE_CHANGED; | |
4919 | ||
4920 | mark = value_mark (); | |
3a1115a0 | 4921 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4922 | |
4a64f543 MS |
4923 | /* We use value_equal_contents instead of value_equal because |
4924 | the latter coerces an array to a pointer, thus comparing just | |
4925 | the address of the array instead of its contents. This is | |
4926 | not what we want. */ | |
fa4727a6 | 4927 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4928 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4929 | { |
fa4727a6 DJ |
4930 | if (new_val != NULL) |
4931 | { | |
4932 | release_value (new_val); | |
4933 | value_free_to_mark (mark); | |
4934 | } | |
c906108c SS |
4935 | bs->old_val = b->val; |
4936 | b->val = new_val; | |
fa4727a6 | 4937 | b->val_valid = 1; |
c906108c SS |
4938 | return WP_VALUE_CHANGED; |
4939 | } | |
4940 | else | |
4941 | { | |
60e1c644 | 4942 | /* Nothing changed. */ |
c906108c | 4943 | value_free_to_mark (mark); |
c906108c SS |
4944 | return WP_VALUE_NOT_CHANGED; |
4945 | } | |
4946 | } | |
4947 | else | |
4948 | { | |
79a45e25 PA |
4949 | struct ui_out *uiout = current_uiout; |
4950 | ||
c906108c | 4951 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4952 | if we temporarily ignored the watchpoint, then when |
4953 | we reenter the block in which it is valid it contains | |
4954 | garbage (in the case of a function, it may have two | |
4955 | garbage values, one before and one after the prologue). | |
4956 | So we can't even detect the first assignment to it and | |
4957 | watch after that (since the garbage may or may not equal | |
4958 | the first value assigned). */ | |
348d480f PA |
4959 | /* We print all the stop information in |
4960 | breakpoint_ops->print_it, but in this case, by the time we | |
4961 | call breakpoint_ops->print_it this bp will be deleted | |
4962 | already. So we have no choice but print the information | |
4963 | here. */ | |
9dc5e2a9 | 4964 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4965 | ui_out_field_string |
4966 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4967 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4968 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4969 | ui_out_text (uiout, |
4970 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4971 | which its expression is valid.\n"); |
4ce44c66 | 4972 | |
cdac0397 | 4973 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4974 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4975 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4976 | |
4977 | return WP_DELETED; | |
4978 | } | |
4979 | } | |
4980 | ||
18a18393 | 4981 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4982 | breakpoint location BL. This function does not check if we should |
4983 | stop, only if BL explains the stop. */ | |
4984 | ||
18a18393 | 4985 | static int |
6c95b8df | 4986 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4987 | struct address_space *aspace, CORE_ADDR bp_addr, |
4988 | const struct target_waitstatus *ws) | |
18a18393 VP |
4989 | { |
4990 | struct breakpoint *b = bl->owner; | |
4991 | ||
348d480f | 4992 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4993 | gdb_assert (b != NULL); |
4994 | ||
09ac7c10 | 4995 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4996 | } |
4997 | ||
3a5c3e22 PA |
4998 | /* Determine if the watched values have actually changed, and we |
4999 | should stop. If not, set BS->stop to 0. */ | |
5000 | ||
18a18393 VP |
5001 | static void |
5002 | bpstat_check_watchpoint (bpstat bs) | |
5003 | { | |
2bdf28a0 | 5004 | const struct bp_location *bl; |
3a5c3e22 | 5005 | struct watchpoint *b; |
2bdf28a0 JK |
5006 | |
5007 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5008 | bl = bs->bp_location_at; |
2bdf28a0 | 5009 | gdb_assert (bl != NULL); |
3a5c3e22 | 5010 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5011 | gdb_assert (b != NULL); |
18a18393 | 5012 | |
18a18393 | 5013 | { |
18a18393 VP |
5014 | int must_check_value = 0; |
5015 | ||
3a5c3e22 | 5016 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5017 | /* For a software watchpoint, we must always check the |
5018 | watched value. */ | |
5019 | must_check_value = 1; | |
5020 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5021 | /* We have a hardware watchpoint (read, write, or access) | |
5022 | and the target earlier reported an address watched by | |
5023 | this watchpoint. */ | |
5024 | must_check_value = 1; | |
5025 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5026 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5027 | /* We were stopped by a hardware watchpoint, but the target could |
5028 | not report the data address. We must check the watchpoint's | |
5029 | value. Access and read watchpoints are out of luck; without | |
5030 | a data address, we can't figure it out. */ | |
5031 | must_check_value = 1; | |
3a5c3e22 | 5032 | |
18a18393 VP |
5033 | if (must_check_value) |
5034 | { | |
3e43a32a MS |
5035 | char *message |
5036 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5037 | b->base.number); |
18a18393 VP |
5038 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5039 | int e = catch_errors (watchpoint_check, bs, message, | |
5040 | RETURN_MASK_ALL); | |
5041 | do_cleanups (cleanups); | |
5042 | switch (e) | |
5043 | { | |
5044 | case WP_DELETED: | |
5045 | /* We've already printed what needs to be printed. */ | |
5046 | bs->print_it = print_it_done; | |
5047 | /* Stop. */ | |
5048 | break; | |
60e1c644 PA |
5049 | case WP_IGNORE: |
5050 | bs->print_it = print_it_noop; | |
5051 | bs->stop = 0; | |
5052 | break; | |
18a18393 | 5053 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5054 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5055 | { |
85d721b8 PA |
5056 | /* There are two cases to consider here: |
5057 | ||
4a64f543 | 5058 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5059 | In that case, trust the target, and always report |
5060 | the watchpoint hit to the user. Even though | |
5061 | reads don't cause value changes, the value may | |
5062 | have changed since the last time it was read, and | |
5063 | since we're not trapping writes, we will not see | |
5064 | those, and as such we should ignore our notion of | |
5065 | old value. | |
5066 | ||
4a64f543 | 5067 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5068 | reads and writes. There are two ways this may |
5069 | happen: | |
5070 | ||
4a64f543 | 5071 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5072 | reads only, but can break on accesses (reads or |
5073 | writes), such as e.g., x86. We detect this case | |
5074 | at the time we try to insert read watchpoints. | |
5075 | ||
4a64f543 | 5076 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5077 | watchpoints, but, the user set an access or write |
5078 | watchpoint watching the same memory as this read | |
5079 | watchpoint. | |
5080 | ||
5081 | If we're watching memory writes as well as reads, | |
5082 | ignore watchpoint hits when we find that the | |
5083 | value hasn't changed, as reads don't cause | |
5084 | changes. This still gives false positives when | |
5085 | the program writes the same value to memory as | |
5086 | what there was already in memory (we will confuse | |
5087 | it for a read), but it's much better than | |
5088 | nothing. */ | |
5089 | ||
5090 | int other_write_watchpoint = 0; | |
5091 | ||
5092 | if (bl->watchpoint_type == hw_read) | |
5093 | { | |
5094 | struct breakpoint *other_b; | |
5095 | ||
5096 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5097 | if (other_b->type == bp_hardware_watchpoint |
5098 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5099 | { |
3a5c3e22 PA |
5100 | struct watchpoint *other_w = |
5101 | (struct watchpoint *) other_b; | |
5102 | ||
5103 | if (other_w->watchpoint_triggered | |
5104 | == watch_triggered_yes) | |
5105 | { | |
5106 | other_write_watchpoint = 1; | |
5107 | break; | |
5108 | } | |
85d721b8 PA |
5109 | } |
5110 | } | |
5111 | ||
5112 | if (other_write_watchpoint | |
5113 | || bl->watchpoint_type == hw_access) | |
5114 | { | |
5115 | /* We're watching the same memory for writes, | |
5116 | and the value changed since the last time we | |
5117 | updated it, so this trap must be for a write. | |
5118 | Ignore it. */ | |
5119 | bs->print_it = print_it_noop; | |
5120 | bs->stop = 0; | |
5121 | } | |
18a18393 VP |
5122 | } |
5123 | break; | |
5124 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5125 | if (b->base.type == bp_hardware_watchpoint |
5126 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5127 | { |
5128 | /* Don't stop: write watchpoints shouldn't fire if | |
5129 | the value hasn't changed. */ | |
5130 | bs->print_it = print_it_noop; | |
5131 | bs->stop = 0; | |
5132 | } | |
5133 | /* Stop. */ | |
5134 | break; | |
5135 | default: | |
5136 | /* Can't happen. */ | |
5137 | case 0: | |
5138 | /* Error from catch_errors. */ | |
3a5c3e22 | 5139 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5140 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5141 | /* We've already printed what needs to be printed. */ |
5142 | bs->print_it = print_it_done; | |
5143 | break; | |
5144 | } | |
5145 | } | |
5146 | else /* must_check_value == 0 */ | |
5147 | { | |
5148 | /* This is a case where some watchpoint(s) triggered, but | |
5149 | not at the address of this watchpoint, or else no | |
5150 | watchpoint triggered after all. So don't print | |
5151 | anything for this watchpoint. */ | |
5152 | bs->print_it = print_it_noop; | |
5153 | bs->stop = 0; | |
5154 | } | |
5155 | } | |
5156 | } | |
5157 | ||
7d4df6a4 DE |
5158 | /* For breakpoints that are currently marked as telling gdb to stop, |
5159 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5160 | of breakpoint referred to by BS. If we should not stop for this |
5161 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5162 | |
18a18393 VP |
5163 | static void |
5164 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5165 | { | |
2bdf28a0 JK |
5166 | const struct bp_location *bl; |
5167 | struct breakpoint *b; | |
7d4df6a4 DE |
5168 | int value_is_zero = 0; |
5169 | struct expression *cond; | |
5170 | ||
5171 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5172 | |
5173 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5174 | bl = bs->bp_location_at; |
2bdf28a0 | 5175 | gdb_assert (bl != NULL); |
f431efe5 | 5176 | b = bs->breakpoint_at; |
2bdf28a0 | 5177 | gdb_assert (b != NULL); |
18a18393 | 5178 | |
b775012e LM |
5179 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5180 | need to do so again since GDB does not know if we stopped due to a | |
5181 | breakpoint or a single step breakpoint. */ | |
5182 | ||
18a18393 | 5183 | if (frame_id_p (b->frame_id) |
edb3359d | 5184 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5185 | { |
7d4df6a4 DE |
5186 | bs->stop = 0; |
5187 | return; | |
5188 | } | |
60e1c644 | 5189 | |
12ab52e9 PA |
5190 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5191 | evaluating the condition if this isn't the specified | |
5192 | thread/task. */ | |
5193 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5194 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5195 | ||
6c1b0f7b DE |
5196 | { |
5197 | bs->stop = 0; | |
5198 | return; | |
5199 | } | |
5200 | ||
6dddc817 DE |
5201 | /* Evaluate extension language breakpoints that have a "stop" method |
5202 | implemented. */ | |
5203 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5204 | |
7d4df6a4 DE |
5205 | if (is_watchpoint (b)) |
5206 | { | |
5207 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5208 | |
7d4df6a4 DE |
5209 | cond = w->cond_exp; |
5210 | } | |
5211 | else | |
5212 | cond = bl->cond; | |
60e1c644 | 5213 | |
7d4df6a4 DE |
5214 | if (cond && b->disposition != disp_del_at_next_stop) |
5215 | { | |
5216 | int within_current_scope = 1; | |
5217 | struct watchpoint * w; | |
60e1c644 | 5218 | |
7d4df6a4 DE |
5219 | /* We use value_mark and value_free_to_mark because it could |
5220 | be a long time before we return to the command level and | |
5221 | call free_all_values. We can't call free_all_values | |
5222 | because we might be in the middle of evaluating a | |
5223 | function call. */ | |
5224 | struct value *mark = value_mark (); | |
5225 | ||
5226 | if (is_watchpoint (b)) | |
5227 | w = (struct watchpoint *) b; | |
5228 | else | |
5229 | w = NULL; | |
5230 | ||
5231 | /* Need to select the frame, with all that implies so that | |
5232 | the conditions will have the right context. Because we | |
5233 | use the frame, we will not see an inlined function's | |
5234 | variables when we arrive at a breakpoint at the start | |
5235 | of the inlined function; the current frame will be the | |
5236 | call site. */ | |
5237 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5238 | select_frame (get_current_frame ()); | |
5239 | else | |
18a18393 | 5240 | { |
7d4df6a4 DE |
5241 | struct frame_info *frame; |
5242 | ||
5243 | /* For local watchpoint expressions, which particular | |
5244 | instance of a local is being watched matters, so we | |
5245 | keep track of the frame to evaluate the expression | |
5246 | in. To evaluate the condition however, it doesn't | |
5247 | really matter which instantiation of the function | |
5248 | where the condition makes sense triggers the | |
5249 | watchpoint. This allows an expression like "watch | |
5250 | global if q > 10" set in `func', catch writes to | |
5251 | global on all threads that call `func', or catch | |
5252 | writes on all recursive calls of `func' by a single | |
5253 | thread. We simply always evaluate the condition in | |
5254 | the innermost frame that's executing where it makes | |
5255 | sense to evaluate the condition. It seems | |
5256 | intuitive. */ | |
5257 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5258 | if (frame != NULL) | |
5259 | select_frame (frame); | |
5260 | else | |
5261 | within_current_scope = 0; | |
18a18393 | 5262 | } |
7d4df6a4 DE |
5263 | if (within_current_scope) |
5264 | value_is_zero | |
5265 | = catch_errors (breakpoint_cond_eval, cond, | |
5266 | "Error in testing breakpoint condition:\n", | |
5267 | RETURN_MASK_ALL); | |
5268 | else | |
18a18393 | 5269 | { |
7d4df6a4 DE |
5270 | warning (_("Watchpoint condition cannot be tested " |
5271 | "in the current scope")); | |
5272 | /* If we failed to set the right context for this | |
5273 | watchpoint, unconditionally report it. */ | |
5274 | value_is_zero = 0; | |
18a18393 | 5275 | } |
7d4df6a4 DE |
5276 | /* FIXME-someday, should give breakpoint #. */ |
5277 | value_free_to_mark (mark); | |
18a18393 | 5278 | } |
7d4df6a4 DE |
5279 | |
5280 | if (cond && value_is_zero) | |
5281 | { | |
5282 | bs->stop = 0; | |
5283 | } | |
7d4df6a4 DE |
5284 | else if (b->ignore_count > 0) |
5285 | { | |
5286 | b->ignore_count--; | |
5287 | bs->stop = 0; | |
5288 | /* Increase the hit count even though we don't stop. */ | |
5289 | ++(b->hit_count); | |
5290 | observer_notify_breakpoint_modified (b); | |
5291 | } | |
18a18393 VP |
5292 | } |
5293 | ||
5294 | ||
9709f61c | 5295 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5296 | BP_ADDR in thread PTID. |
c906108c | 5297 | |
d983da9c | 5298 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5299 | don't understand this stop. Result is a chain of bpstat's such |
5300 | that: | |
c906108c | 5301 | |
c5aa993b | 5302 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5303 | |
c5aa993b | 5304 | if we understand why we stopped, the result is not null. |
c906108c | 5305 | |
c5aa993b JM |
5306 | Each element of the chain refers to a particular breakpoint or |
5307 | watchpoint at which we have stopped. (We may have stopped for | |
5308 | several reasons concurrently.) | |
c906108c | 5309 | |
c5aa993b JM |
5310 | Each element of the chain has valid next, breakpoint_at, |
5311 | commands, FIXME??? fields. */ | |
c906108c SS |
5312 | |
5313 | bpstat | |
6c95b8df | 5314 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5315 | CORE_ADDR bp_addr, ptid_t ptid, |
5316 | const struct target_waitstatus *ws) | |
c906108c | 5317 | { |
0d381245 | 5318 | struct breakpoint *b = NULL; |
afe38095 | 5319 | struct bp_location *bl; |
20874c92 | 5320 | struct bp_location *loc; |
5760d0ab JK |
5321 | /* First item of allocated bpstat's. */ |
5322 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5323 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5324 | bpstat bs; |
20874c92 | 5325 | int ix; |
429374b8 | 5326 | int need_remove_insert; |
f431efe5 | 5327 | int removed_any; |
c906108c | 5328 | |
f431efe5 PA |
5329 | /* First, build the bpstat chain with locations that explain a |
5330 | target stop, while being careful to not set the target running, | |
5331 | as that may invalidate locations (in particular watchpoint | |
5332 | locations are recreated). Resuming will happen here with | |
5333 | breakpoint conditions or watchpoint expressions that include | |
5334 | inferior function calls. */ | |
c5aa993b | 5335 | |
429374b8 JK |
5336 | ALL_BREAKPOINTS (b) |
5337 | { | |
5338 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5339 | continue; | |
a5606eee | 5340 | |
429374b8 JK |
5341 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5342 | { | |
4a64f543 MS |
5343 | /* For hardware watchpoints, we look only at the first |
5344 | location. The watchpoint_check function will work on the | |
5345 | entire expression, not the individual locations. For | |
5346 | read watchpoints, the watchpoints_triggered function has | |
5347 | checked all locations already. */ | |
429374b8 JK |
5348 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5349 | break; | |
18a18393 | 5350 | |
f6592439 | 5351 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5352 | continue; |
c5aa993b | 5353 | |
09ac7c10 | 5354 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5355 | continue; |
c5aa993b | 5356 | |
4a64f543 MS |
5357 | /* Come here if it's a watchpoint, or if the break address |
5358 | matches. */ | |
c5aa993b | 5359 | |
4a64f543 MS |
5360 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5361 | explain stop. */ | |
c5aa993b | 5362 | |
f431efe5 PA |
5363 | /* Assume we stop. Should we find a watchpoint that is not |
5364 | actually triggered, or if the condition of the breakpoint | |
5365 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5366 | bs->stop = 1; |
5367 | bs->print = 1; | |
d983da9c | 5368 | |
f431efe5 PA |
5369 | /* If this is a scope breakpoint, mark the associated |
5370 | watchpoint as triggered so that we will handle the | |
5371 | out-of-scope event. We'll get to the watchpoint next | |
5372 | iteration. */ | |
d0fb5eae | 5373 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5374 | { |
5375 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5376 | ||
5377 | w->watchpoint_triggered = watch_triggered_yes; | |
5378 | } | |
f431efe5 PA |
5379 | } |
5380 | } | |
5381 | ||
5382 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5383 | { | |
f1310107 | 5384 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5385 | { |
5760d0ab | 5386 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5387 | /* For hits of moribund locations, we should just proceed. */ |
5388 | bs->stop = 0; | |
5389 | bs->print = 0; | |
5390 | bs->print_it = print_it_noop; | |
5391 | } | |
5392 | } | |
5393 | ||
edcc5120 TT |
5394 | /* A bit of special processing for shlib breakpoints. We need to |
5395 | process solib loading here, so that the lists of loaded and | |
5396 | unloaded libraries are correct before we handle "catch load" and | |
5397 | "catch unload". */ | |
5398 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5399 | { | |
5d268276 | 5400 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5401 | { |
5402 | handle_solib_event (); | |
5403 | break; | |
5404 | } | |
5405 | } | |
5406 | ||
f431efe5 PA |
5407 | /* Now go through the locations that caused the target to stop, and |
5408 | check whether we're interested in reporting this stop to higher | |
5409 | layers, or whether we should resume the target transparently. */ | |
5410 | ||
5411 | removed_any = 0; | |
5412 | ||
5760d0ab | 5413 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5414 | { |
5415 | if (!bs->stop) | |
5416 | continue; | |
5417 | ||
f431efe5 | 5418 | b = bs->breakpoint_at; |
348d480f PA |
5419 | b->ops->check_status (bs); |
5420 | if (bs->stop) | |
28010a5d | 5421 | { |
348d480f | 5422 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5423 | |
429374b8 JK |
5424 | if (bs->stop) |
5425 | { | |
5426 | ++(b->hit_count); | |
8d3788bd | 5427 | observer_notify_breakpoint_modified (b); |
c906108c | 5428 | |
4a64f543 | 5429 | /* We will stop here. */ |
429374b8 JK |
5430 | if (b->disposition == disp_disable) |
5431 | { | |
816338b5 SS |
5432 | --(b->enable_count); |
5433 | if (b->enable_count <= 0 | |
5434 | && b->enable_state != bp_permanent) | |
429374b8 | 5435 | b->enable_state = bp_disabled; |
f431efe5 | 5436 | removed_any = 1; |
429374b8 JK |
5437 | } |
5438 | if (b->silent) | |
5439 | bs->print = 0; | |
5440 | bs->commands = b->commands; | |
9add0f1b | 5441 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5442 | if (command_line_is_silent (bs->commands |
5443 | ? bs->commands->commands : NULL)) | |
5444 | bs->print = 0; | |
9d6e6e84 HZ |
5445 | |
5446 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5447 | } |
5448 | ||
348d480f | 5449 | } |
a9b3a50f PA |
5450 | |
5451 | /* Print nothing for this entry if we don't stop or don't | |
5452 | print. */ | |
5453 | if (!bs->stop || !bs->print) | |
5454 | bs->print_it = print_it_noop; | |
429374b8 | 5455 | } |
876fa593 | 5456 | |
d983da9c DJ |
5457 | /* If we aren't stopping, the value of some hardware watchpoint may |
5458 | not have changed, but the intermediate memory locations we are | |
5459 | watching may have. Don't bother if we're stopping; this will get | |
5460 | done later. */ | |
d832cb68 | 5461 | need_remove_insert = 0; |
5760d0ab JK |
5462 | if (! bpstat_causes_stop (bs_head)) |
5463 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5464 | if (!bs->stop |
f431efe5 PA |
5465 | && bs->breakpoint_at |
5466 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5467 | { |
3a5c3e22 PA |
5468 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5469 | ||
5470 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5471 | need_remove_insert = 1; |
d983da9c DJ |
5472 | } |
5473 | ||
d832cb68 | 5474 | if (need_remove_insert) |
2d134ed3 | 5475 | update_global_location_list (1); |
f431efe5 PA |
5476 | else if (removed_any) |
5477 | update_global_location_list (0); | |
d832cb68 | 5478 | |
5760d0ab | 5479 | return bs_head; |
c906108c | 5480 | } |
628fe4e4 JK |
5481 | |
5482 | static void | |
5483 | handle_jit_event (void) | |
5484 | { | |
5485 | struct frame_info *frame; | |
5486 | struct gdbarch *gdbarch; | |
5487 | ||
5488 | /* Switch terminal for any messages produced by | |
5489 | breakpoint_re_set. */ | |
5490 | target_terminal_ours_for_output (); | |
5491 | ||
5492 | frame = get_current_frame (); | |
5493 | gdbarch = get_frame_arch (frame); | |
5494 | ||
5495 | jit_event_handler (gdbarch); | |
5496 | ||
5497 | target_terminal_inferior (); | |
5498 | } | |
5499 | ||
5500 | /* Prepare WHAT final decision for infrun. */ | |
5501 | ||
5502 | /* Decide what infrun needs to do with this bpstat. */ | |
5503 | ||
c906108c | 5504 | struct bpstat_what |
0e30163f | 5505 | bpstat_what (bpstat bs_head) |
c906108c | 5506 | { |
c906108c | 5507 | struct bpstat_what retval; |
628fe4e4 | 5508 | int jit_event = 0; |
0e30163f | 5509 | bpstat bs; |
c906108c | 5510 | |
628fe4e4 | 5511 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5512 | retval.call_dummy = STOP_NONE; |
186c406b | 5513 | retval.is_longjmp = 0; |
628fe4e4 | 5514 | |
0e30163f | 5515 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5516 | { |
628fe4e4 JK |
5517 | /* Extract this BS's action. After processing each BS, we check |
5518 | if its action overrides all we've seem so far. */ | |
5519 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5520 | enum bptype bptype; | |
5521 | ||
c906108c | 5522 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5523 | { |
5524 | /* I suspect this can happen if it was a momentary | |
5525 | breakpoint which has since been deleted. */ | |
5526 | bptype = bp_none; | |
5527 | } | |
20874c92 | 5528 | else |
f431efe5 | 5529 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5530 | |
5531 | switch (bptype) | |
c906108c SS |
5532 | { |
5533 | case bp_none: | |
628fe4e4 | 5534 | break; |
c906108c SS |
5535 | case bp_breakpoint: |
5536 | case bp_hardware_breakpoint: | |
5537 | case bp_until: | |
5538 | case bp_finish: | |
a9b3a50f | 5539 | case bp_shlib_event: |
c906108c SS |
5540 | if (bs->stop) |
5541 | { | |
5542 | if (bs->print) | |
628fe4e4 | 5543 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5544 | else |
628fe4e4 | 5545 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5546 | } |
5547 | else | |
628fe4e4 | 5548 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5549 | break; |
5550 | case bp_watchpoint: | |
5551 | case bp_hardware_watchpoint: | |
5552 | case bp_read_watchpoint: | |
5553 | case bp_access_watchpoint: | |
5554 | if (bs->stop) | |
5555 | { | |
5556 | if (bs->print) | |
628fe4e4 | 5557 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5558 | else |
628fe4e4 | 5559 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5560 | } |
5561 | else | |
628fe4e4 JK |
5562 | { |
5563 | /* There was a watchpoint, but we're not stopping. | |
5564 | This requires no further action. */ | |
5565 | } | |
c906108c SS |
5566 | break; |
5567 | case bp_longjmp: | |
e2e4d78b | 5568 | case bp_longjmp_call_dummy: |
186c406b | 5569 | case bp_exception: |
628fe4e4 | 5570 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5571 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5572 | break; |
5573 | case bp_longjmp_resume: | |
186c406b | 5574 | case bp_exception_resume: |
628fe4e4 | 5575 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5576 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5577 | break; |
5578 | case bp_step_resume: | |
5579 | if (bs->stop) | |
628fe4e4 JK |
5580 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5581 | else | |
c906108c | 5582 | { |
628fe4e4 JK |
5583 | /* It is for the wrong frame. */ |
5584 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5585 | } |
c906108c | 5586 | break; |
2c03e5be PA |
5587 | case bp_hp_step_resume: |
5588 | if (bs->stop) | |
5589 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5590 | else | |
5591 | { | |
5592 | /* It is for the wrong frame. */ | |
5593 | this_action = BPSTAT_WHAT_SINGLE; | |
5594 | } | |
5595 | break; | |
c906108c | 5596 | case bp_watchpoint_scope: |
c4093a6a | 5597 | case bp_thread_event: |
1900040c | 5598 | case bp_overlay_event: |
0fd8e87f | 5599 | case bp_longjmp_master: |
aa7d318d | 5600 | case bp_std_terminate_master: |
186c406b | 5601 | case bp_exception_master: |
628fe4e4 | 5602 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5603 | break; |
ce78b96d | 5604 | case bp_catchpoint: |
c5aa993b JM |
5605 | if (bs->stop) |
5606 | { | |
5607 | if (bs->print) | |
628fe4e4 | 5608 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5609 | else |
628fe4e4 | 5610 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5611 | } |
5612 | else | |
628fe4e4 JK |
5613 | { |
5614 | /* There was a catchpoint, but we're not stopping. | |
5615 | This requires no further action. */ | |
5616 | } | |
5617 | break; | |
628fe4e4 JK |
5618 | case bp_jit_event: |
5619 | jit_event = 1; | |
5620 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5621 | break; |
c906108c | 5622 | case bp_call_dummy: |
53a5351d JM |
5623 | /* Make sure the action is stop (silent or noisy), |
5624 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5625 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5626 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5627 | break; |
5628 | case bp_std_terminate: | |
5629 | /* Make sure the action is stop (silent or noisy), | |
5630 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5631 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5632 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5633 | break; |
1042e4c0 | 5634 | case bp_tracepoint: |
7a697b8d | 5635 | case bp_fast_tracepoint: |
0fb4aa4b | 5636 | case bp_static_tracepoint: |
1042e4c0 SS |
5637 | /* Tracepoint hits should not be reported back to GDB, and |
5638 | if one got through somehow, it should have been filtered | |
5639 | out already. */ | |
5640 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5641 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5642 | break; |
5643 | case bp_gnu_ifunc_resolver: | |
5644 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5645 | this_action = BPSTAT_WHAT_SINGLE; | |
5646 | break; | |
5647 | case bp_gnu_ifunc_resolver_return: | |
5648 | /* The breakpoint will be removed, execution will restart from the | |
5649 | PC of the former breakpoint. */ | |
5650 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5651 | break; | |
e7e0cddf SS |
5652 | |
5653 | case bp_dprintf: | |
a11cfd87 HZ |
5654 | if (bs->stop) |
5655 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5656 | else | |
5657 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5658 | break; |
5659 | ||
628fe4e4 JK |
5660 | default: |
5661 | internal_error (__FILE__, __LINE__, | |
5662 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5663 | } |
628fe4e4 JK |
5664 | |
5665 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5666 | } |
628fe4e4 | 5667 | |
0e30163f JK |
5668 | /* These operations may affect the bs->breakpoint_at state so they are |
5669 | delayed after MAIN_ACTION is decided above. */ | |
5670 | ||
628fe4e4 JK |
5671 | if (jit_event) |
5672 | { | |
5673 | if (debug_infrun) | |
5674 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5675 | ||
5676 | handle_jit_event (); | |
5677 | } | |
5678 | ||
0e30163f JK |
5679 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5680 | { | |
5681 | struct breakpoint *b = bs->breakpoint_at; | |
5682 | ||
5683 | if (b == NULL) | |
5684 | continue; | |
5685 | switch (b->type) | |
5686 | { | |
5687 | case bp_gnu_ifunc_resolver: | |
5688 | gnu_ifunc_resolver_stop (b); | |
5689 | break; | |
5690 | case bp_gnu_ifunc_resolver_return: | |
5691 | gnu_ifunc_resolver_return_stop (b); | |
5692 | break; | |
5693 | } | |
5694 | } | |
5695 | ||
c906108c SS |
5696 | return retval; |
5697 | } | |
5698 | ||
5699 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5700 | without hardware support). This isn't related to a specific bpstat, | |
5701 | just to things like whether watchpoints are set. */ | |
5702 | ||
c5aa993b | 5703 | int |
fba45db2 | 5704 | bpstat_should_step (void) |
c906108c SS |
5705 | { |
5706 | struct breakpoint *b; | |
cc59ec59 | 5707 | |
c906108c | 5708 | ALL_BREAKPOINTS (b) |
717a8278 | 5709 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5710 | return 1; |
c906108c SS |
5711 | return 0; |
5712 | } | |
5713 | ||
67822962 PA |
5714 | int |
5715 | bpstat_causes_stop (bpstat bs) | |
5716 | { | |
5717 | for (; bs != NULL; bs = bs->next) | |
5718 | if (bs->stop) | |
5719 | return 1; | |
5720 | ||
5721 | return 0; | |
5722 | } | |
5723 | ||
c906108c | 5724 | \f |
c5aa993b | 5725 | |
170b53b2 UW |
5726 | /* Compute a string of spaces suitable to indent the next line |
5727 | so it starts at the position corresponding to the table column | |
5728 | named COL_NAME in the currently active table of UIOUT. */ | |
5729 | ||
5730 | static char * | |
5731 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5732 | { | |
5733 | static char wrap_indent[80]; | |
5734 | int i, total_width, width, align; | |
5735 | char *text; | |
5736 | ||
5737 | total_width = 0; | |
5738 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5739 | { | |
5740 | if (strcmp (text, col_name) == 0) | |
5741 | { | |
5742 | gdb_assert (total_width < sizeof wrap_indent); | |
5743 | memset (wrap_indent, ' ', total_width); | |
5744 | wrap_indent[total_width] = 0; | |
5745 | ||
5746 | return wrap_indent; | |
5747 | } | |
5748 | ||
5749 | total_width += width + 1; | |
5750 | } | |
5751 | ||
5752 | return NULL; | |
5753 | } | |
5754 | ||
b775012e LM |
5755 | /* Determine if the locations of this breakpoint will have their conditions |
5756 | evaluated by the target, host or a mix of both. Returns the following: | |
5757 | ||
5758 | "host": Host evals condition. | |
5759 | "host or target": Host or Target evals condition. | |
5760 | "target": Target evals condition. | |
5761 | */ | |
5762 | ||
5763 | static const char * | |
5764 | bp_condition_evaluator (struct breakpoint *b) | |
5765 | { | |
5766 | struct bp_location *bl; | |
5767 | char host_evals = 0; | |
5768 | char target_evals = 0; | |
5769 | ||
5770 | if (!b) | |
5771 | return NULL; | |
5772 | ||
5773 | if (!is_breakpoint (b)) | |
5774 | return NULL; | |
5775 | ||
5776 | if (gdb_evaluates_breakpoint_condition_p () | |
5777 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5778 | return condition_evaluation_host; | |
5779 | ||
5780 | for (bl = b->loc; bl; bl = bl->next) | |
5781 | { | |
5782 | if (bl->cond_bytecode) | |
5783 | target_evals++; | |
5784 | else | |
5785 | host_evals++; | |
5786 | } | |
5787 | ||
5788 | if (host_evals && target_evals) | |
5789 | return condition_evaluation_both; | |
5790 | else if (target_evals) | |
5791 | return condition_evaluation_target; | |
5792 | else | |
5793 | return condition_evaluation_host; | |
5794 | } | |
5795 | ||
5796 | /* Determine the breakpoint location's condition evaluator. This is | |
5797 | similar to bp_condition_evaluator, but for locations. */ | |
5798 | ||
5799 | static const char * | |
5800 | bp_location_condition_evaluator (struct bp_location *bl) | |
5801 | { | |
5802 | if (bl && !is_breakpoint (bl->owner)) | |
5803 | return NULL; | |
5804 | ||
5805 | if (gdb_evaluates_breakpoint_condition_p () | |
5806 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5807 | return condition_evaluation_host; | |
5808 | ||
5809 | if (bl && bl->cond_bytecode) | |
5810 | return condition_evaluation_target; | |
5811 | else | |
5812 | return condition_evaluation_host; | |
5813 | } | |
5814 | ||
859825b8 JK |
5815 | /* Print the LOC location out of the list of B->LOC locations. */ |
5816 | ||
170b53b2 UW |
5817 | static void |
5818 | print_breakpoint_location (struct breakpoint *b, | |
5819 | struct bp_location *loc) | |
0d381245 | 5820 | { |
79a45e25 | 5821 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5822 | struct cleanup *old_chain = save_current_program_space (); |
5823 | ||
859825b8 JK |
5824 | if (loc != NULL && loc->shlib_disabled) |
5825 | loc = NULL; | |
5826 | ||
6c95b8df PA |
5827 | if (loc != NULL) |
5828 | set_current_program_space (loc->pspace); | |
5829 | ||
56435ebe TT |
5830 | if (b->display_canonical) |
5831 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5832 | else if (loc && loc->symtab) |
0d381245 VP |
5833 | { |
5834 | struct symbol *sym | |
5835 | = find_pc_sect_function (loc->address, loc->section); | |
5836 | if (sym) | |
5837 | { | |
5838 | ui_out_text (uiout, "in "); | |
5839 | ui_out_field_string (uiout, "func", | |
5840 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5841 | ui_out_text (uiout, " "); |
5842 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5843 | ui_out_text (uiout, "at "); | |
0d381245 | 5844 | } |
05cba821 JK |
5845 | ui_out_field_string (uiout, "file", |
5846 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5847 | ui_out_text (uiout, ":"); |
05cba821 | 5848 | |
0d381245 | 5849 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5850 | ui_out_field_string (uiout, "fullname", |
5851 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5852 | |
f8eba3c6 | 5853 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5854 | } |
859825b8 | 5855 | else if (loc) |
0d381245 | 5856 | { |
f99d8bf4 PA |
5857 | struct ui_file *stb = mem_fileopen (); |
5858 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5859 | |
f99d8bf4 | 5860 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5861 | demangle, ""); |
0d381245 | 5862 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5863 | |
5864 | do_cleanups (stb_chain); | |
0d381245 | 5865 | } |
859825b8 JK |
5866 | else |
5867 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5868 | |
b775012e LM |
5869 | if (loc && is_breakpoint (b) |
5870 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5871 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5872 | { | |
5873 | ui_out_text (uiout, " ("); | |
5874 | ui_out_field_string (uiout, "evaluated-by", | |
5875 | bp_location_condition_evaluator (loc)); | |
5876 | ui_out_text (uiout, ")"); | |
5877 | } | |
5878 | ||
6c95b8df | 5879 | do_cleanups (old_chain); |
0d381245 VP |
5880 | } |
5881 | ||
269b11a2 PA |
5882 | static const char * |
5883 | bptype_string (enum bptype type) | |
c906108c | 5884 | { |
c4093a6a JM |
5885 | struct ep_type_description |
5886 | { | |
5887 | enum bptype type; | |
5888 | char *description; | |
5889 | }; | |
5890 | static struct ep_type_description bptypes[] = | |
c906108c | 5891 | { |
c5aa993b JM |
5892 | {bp_none, "?deleted?"}, |
5893 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5894 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5895 | {bp_until, "until"}, |
5896 | {bp_finish, "finish"}, | |
5897 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5898 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5899 | {bp_read_watchpoint, "read watchpoint"}, |
5900 | {bp_access_watchpoint, "acc watchpoint"}, | |
5901 | {bp_longjmp, "longjmp"}, | |
5902 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5903 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5904 | {bp_exception, "exception"}, |
5905 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5906 | {bp_step_resume, "step resume"}, |
2c03e5be | 5907 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5908 | {bp_watchpoint_scope, "watchpoint scope"}, |
5909 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5910 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5911 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5912 | {bp_thread_event, "thread events"}, |
1900040c | 5913 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5914 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5915 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5916 | {bp_exception_master, "exception master"}, |
ce78b96d | 5917 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5918 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5919 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5920 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5921 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5922 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5923 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5924 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5925 | }; |
269b11a2 PA |
5926 | |
5927 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5928 | || ((int) type != bptypes[(int) type].type)) | |
5929 | internal_error (__FILE__, __LINE__, | |
5930 | _("bptypes table does not describe type #%d."), | |
5931 | (int) type); | |
5932 | ||
5933 | return bptypes[(int) type].description; | |
5934 | } | |
5935 | ||
998580f1 MK |
5936 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5937 | For CLI, prefix the list with the string 'inf'. */ | |
5938 | ||
5939 | static void | |
5940 | output_thread_groups (struct ui_out *uiout, | |
5941 | const char *field_name, | |
5942 | VEC(int) *inf_num, | |
5943 | int mi_only) | |
5944 | { | |
752eb8b4 | 5945 | struct cleanup *back_to; |
998580f1 MK |
5946 | int is_mi = ui_out_is_mi_like_p (uiout); |
5947 | int inf; | |
5948 | int i; | |
5949 | ||
5950 | /* For backward compatibility, don't display inferiors in CLI unless | |
5951 | there are several. Always display them for MI. */ | |
5952 | if (!is_mi && mi_only) | |
5953 | return; | |
5954 | ||
752eb8b4 TT |
5955 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
5956 | ||
998580f1 MK |
5957 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
5958 | { | |
5959 | if (is_mi) | |
5960 | { | |
5961 | char mi_group[10]; | |
5962 | ||
5963 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5964 | ui_out_field_string (uiout, NULL, mi_group); | |
5965 | } | |
5966 | else | |
5967 | { | |
5968 | if (i == 0) | |
5969 | ui_out_text (uiout, " inf "); | |
5970 | else | |
5971 | ui_out_text (uiout, ", "); | |
5972 | ||
5973 | ui_out_text (uiout, plongest (inf)); | |
5974 | } | |
5975 | } | |
5976 | ||
5977 | do_cleanups (back_to); | |
5978 | } | |
5979 | ||
269b11a2 PA |
5980 | /* Print B to gdb_stdout. */ |
5981 | ||
5982 | static void | |
5983 | print_one_breakpoint_location (struct breakpoint *b, | |
5984 | struct bp_location *loc, | |
5985 | int loc_number, | |
5986 | struct bp_location **last_loc, | |
269b11a2 PA |
5987 | int allflag) |
5988 | { | |
5989 | struct command_line *l; | |
c2c6d25f | 5990 | static char bpenables[] = "nynny"; |
c906108c | 5991 | |
79a45e25 | 5992 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5993 | int header_of_multiple = 0; |
5994 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5995 | struct value_print_options opts; |
5996 | ||
5997 | get_user_print_options (&opts); | |
0d381245 VP |
5998 | |
5999 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6000 | /* See comment in print_one_breakpoint concerning treatment of |
6001 | breakpoints with single disabled location. */ | |
0d381245 VP |
6002 | if (loc == NULL |
6003 | && (b->loc != NULL | |
6004 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6005 | header_of_multiple = 1; | |
6006 | if (loc == NULL) | |
6007 | loc = b->loc; | |
6008 | ||
c4093a6a JM |
6009 | annotate_record (); |
6010 | ||
6011 | /* 1 */ | |
6012 | annotate_field (0); | |
0d381245 VP |
6013 | if (part_of_multiple) |
6014 | { | |
6015 | char *formatted; | |
0c6773c1 | 6016 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6017 | ui_out_field_string (uiout, "number", formatted); |
6018 | xfree (formatted); | |
6019 | } | |
6020 | else | |
6021 | { | |
6022 | ui_out_field_int (uiout, "number", b->number); | |
6023 | } | |
c4093a6a JM |
6024 | |
6025 | /* 2 */ | |
6026 | annotate_field (1); | |
0d381245 VP |
6027 | if (part_of_multiple) |
6028 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6029 | else |
6030 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6031 | |
6032 | /* 3 */ | |
6033 | annotate_field (2); | |
0d381245 VP |
6034 | if (part_of_multiple) |
6035 | ui_out_field_skip (uiout, "disp"); | |
6036 | else | |
2cec12e5 | 6037 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6038 | |
c4093a6a JM |
6039 | |
6040 | /* 4 */ | |
6041 | annotate_field (3); | |
0d381245 | 6042 | if (part_of_multiple) |
54e52265 | 6043 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6044 | else |
4a64f543 MS |
6045 | ui_out_field_fmt (uiout, "enabled", "%c", |
6046 | bpenables[(int) b->enable_state]); | |
54e52265 | 6047 | ui_out_spaces (uiout, 2); |
0d381245 | 6048 | |
c4093a6a JM |
6049 | |
6050 | /* 5 and 6 */ | |
3086aeae | 6051 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6052 | { |
4a64f543 MS |
6053 | /* Although the print_one can possibly print all locations, |
6054 | calling it here is not likely to get any nice result. So, | |
6055 | make sure there's just one location. */ | |
0d381245 | 6056 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6057 | b->ops->print_one (b, last_loc); |
0d381245 | 6058 | } |
3086aeae DJ |
6059 | else |
6060 | switch (b->type) | |
6061 | { | |
6062 | case bp_none: | |
6063 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6064 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6065 | break; |
c906108c | 6066 | |
3086aeae DJ |
6067 | case bp_watchpoint: |
6068 | case bp_hardware_watchpoint: | |
6069 | case bp_read_watchpoint: | |
6070 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6071 | { |
6072 | struct watchpoint *w = (struct watchpoint *) b; | |
6073 | ||
6074 | /* Field 4, the address, is omitted (which makes the columns | |
6075 | not line up too nicely with the headers, but the effect | |
6076 | is relatively readable). */ | |
6077 | if (opts.addressprint) | |
6078 | ui_out_field_skip (uiout, "addr"); | |
6079 | annotate_field (5); | |
6080 | ui_out_field_string (uiout, "what", w->exp_string); | |
6081 | } | |
3086aeae DJ |
6082 | break; |
6083 | ||
3086aeae DJ |
6084 | case bp_breakpoint: |
6085 | case bp_hardware_breakpoint: | |
6086 | case bp_until: | |
6087 | case bp_finish: | |
6088 | case bp_longjmp: | |
6089 | case bp_longjmp_resume: | |
e2e4d78b | 6090 | case bp_longjmp_call_dummy: |
186c406b TT |
6091 | case bp_exception: |
6092 | case bp_exception_resume: | |
3086aeae | 6093 | case bp_step_resume: |
2c03e5be | 6094 | case bp_hp_step_resume: |
3086aeae DJ |
6095 | case bp_watchpoint_scope: |
6096 | case bp_call_dummy: | |
aa7d318d | 6097 | case bp_std_terminate: |
3086aeae DJ |
6098 | case bp_shlib_event: |
6099 | case bp_thread_event: | |
6100 | case bp_overlay_event: | |
0fd8e87f | 6101 | case bp_longjmp_master: |
aa7d318d | 6102 | case bp_std_terminate_master: |
186c406b | 6103 | case bp_exception_master: |
1042e4c0 | 6104 | case bp_tracepoint: |
7a697b8d | 6105 | case bp_fast_tracepoint: |
0fb4aa4b | 6106 | case bp_static_tracepoint: |
e7e0cddf | 6107 | case bp_dprintf: |
4efc6507 | 6108 | case bp_jit_event: |
0e30163f JK |
6109 | case bp_gnu_ifunc_resolver: |
6110 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6111 | if (opts.addressprint) |
3086aeae DJ |
6112 | { |
6113 | annotate_field (4); | |
54e52265 | 6114 | if (header_of_multiple) |
0d381245 | 6115 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6116 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6117 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6118 | else |
5af949e3 UW |
6119 | ui_out_field_core_addr (uiout, "addr", |
6120 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6121 | } |
6122 | annotate_field (5); | |
0d381245 | 6123 | if (!header_of_multiple) |
170b53b2 | 6124 | print_breakpoint_location (b, loc); |
0d381245 | 6125 | if (b->loc) |
a6d9a66e | 6126 | *last_loc = b->loc; |
3086aeae DJ |
6127 | break; |
6128 | } | |
c906108c | 6129 | |
6c95b8df | 6130 | |
998580f1 | 6131 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6132 | { |
6133 | struct inferior *inf; | |
998580f1 MK |
6134 | VEC(int) *inf_num = NULL; |
6135 | int mi_only = 1; | |
6c95b8df | 6136 | |
998580f1 | 6137 | ALL_INFERIORS (inf) |
6c95b8df PA |
6138 | { |
6139 | if (inf->pspace == loc->pspace) | |
998580f1 | 6140 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6141 | } |
998580f1 MK |
6142 | |
6143 | /* For backward compatibility, don't display inferiors in CLI unless | |
6144 | there are several. Always display for MI. */ | |
6145 | if (allflag | |
6146 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6147 | && (number_of_program_spaces () > 1 | |
6148 | || number_of_inferiors () > 1) | |
6149 | /* LOC is for existing B, it cannot be in | |
6150 | moribund_locations and thus having NULL OWNER. */ | |
6151 | && loc->owner->type != bp_catchpoint)) | |
6152 | mi_only = 0; | |
6153 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6154 | VEC_free (int, inf_num); | |
6c95b8df PA |
6155 | } |
6156 | ||
4a306c9a | 6157 | if (!part_of_multiple) |
c4093a6a | 6158 | { |
4a306c9a JB |
6159 | if (b->thread != -1) |
6160 | { | |
6161 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6162 | "stop only in" line a little further down. */ |
4a306c9a JB |
6163 | ui_out_text (uiout, " thread "); |
6164 | ui_out_field_int (uiout, "thread", b->thread); | |
6165 | } | |
6166 | else if (b->task != 0) | |
6167 | { | |
6168 | ui_out_text (uiout, " task "); | |
6169 | ui_out_field_int (uiout, "task", b->task); | |
6170 | } | |
c4093a6a | 6171 | } |
f1310107 | 6172 | |
8b93c638 | 6173 | ui_out_text (uiout, "\n"); |
f1310107 | 6174 | |
348d480f | 6175 | if (!part_of_multiple) |
f1310107 TJB |
6176 | b->ops->print_one_detail (b, uiout); |
6177 | ||
0d381245 | 6178 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6179 | { |
6180 | annotate_field (6); | |
8b93c638 | 6181 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6182 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6183 | the frame ID. */ |
5af949e3 UW |
6184 | ui_out_field_core_addr (uiout, "frame", |
6185 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6186 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6187 | } |
6188 | ||
28010a5d | 6189 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6190 | { |
6191 | annotate_field (7); | |
d77f58be | 6192 | if (is_tracepoint (b)) |
1042e4c0 SS |
6193 | ui_out_text (uiout, "\ttrace only if "); |
6194 | else | |
6195 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6196 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6197 | |
6198 | /* Print whether the target is doing the breakpoint's condition | |
6199 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6200 | if (is_breakpoint (b) | |
6201 | && breakpoint_condition_evaluation_mode () | |
6202 | == condition_evaluation_target) | |
6203 | { | |
6204 | ui_out_text (uiout, " ("); | |
6205 | ui_out_field_string (uiout, "evaluated-by", | |
6206 | bp_condition_evaluator (b)); | |
6207 | ui_out_text (uiout, " evals)"); | |
6208 | } | |
0101ce28 JJ |
6209 | ui_out_text (uiout, "\n"); |
6210 | } | |
6211 | ||
0d381245 | 6212 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6213 | { |
4a64f543 | 6214 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6215 | ui_out_text (uiout, "\tstop only in thread "); |
6216 | ui_out_field_int (uiout, "thread", b->thread); | |
6217 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6218 | } |
6219 | ||
556ec64d YQ |
6220 | if (!part_of_multiple) |
6221 | { | |
6222 | if (b->hit_count) | |
31f56a27 YQ |
6223 | { |
6224 | /* FIXME should make an annotation for this. */ | |
6225 | if (is_catchpoint (b)) | |
6226 | ui_out_text (uiout, "\tcatchpoint"); | |
6227 | else if (is_tracepoint (b)) | |
6228 | ui_out_text (uiout, "\ttracepoint"); | |
6229 | else | |
6230 | ui_out_text (uiout, "\tbreakpoint"); | |
6231 | ui_out_text (uiout, " already hit "); | |
6232 | ui_out_field_int (uiout, "times", b->hit_count); | |
6233 | if (b->hit_count == 1) | |
6234 | ui_out_text (uiout, " time\n"); | |
6235 | else | |
6236 | ui_out_text (uiout, " times\n"); | |
6237 | } | |
556ec64d YQ |
6238 | else |
6239 | { | |
31f56a27 YQ |
6240 | /* Output the count also if it is zero, but only if this is mi. */ |
6241 | if (ui_out_is_mi_like_p (uiout)) | |
6242 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6243 | } |
6244 | } | |
8b93c638 | 6245 | |
0d381245 | 6246 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6247 | { |
6248 | annotate_field (8); | |
8b93c638 JM |
6249 | ui_out_text (uiout, "\tignore next "); |
6250 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6251 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6252 | } |
059fb39f | 6253 | |
816338b5 SS |
6254 | /* Note that an enable count of 1 corresponds to "enable once" |
6255 | behavior, which is reported by the combination of enablement and | |
6256 | disposition, so we don't need to mention it here. */ | |
6257 | if (!part_of_multiple && b->enable_count > 1) | |
6258 | { | |
6259 | annotate_field (8); | |
6260 | ui_out_text (uiout, "\tdisable after "); | |
6261 | /* Tweak the wording to clarify that ignore and enable counts | |
6262 | are distinct, and have additive effect. */ | |
6263 | if (b->ignore_count) | |
6264 | ui_out_text (uiout, "additional "); | |
6265 | else | |
6266 | ui_out_text (uiout, "next "); | |
6267 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6268 | ui_out_text (uiout, " hits\n"); | |
6269 | } | |
6270 | ||
f196051f SS |
6271 | if (!part_of_multiple && is_tracepoint (b)) |
6272 | { | |
6273 | struct tracepoint *tp = (struct tracepoint *) b; | |
6274 | ||
6275 | if (tp->traceframe_usage) | |
6276 | { | |
6277 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6278 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6279 | ui_out_text (uiout, " bytes\n"); | |
6280 | } | |
6281 | } | |
d3ce09f5 | 6282 | |
9add0f1b | 6283 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6284 | if (!part_of_multiple && l) |
c4093a6a | 6285 | { |
3b31d625 EZ |
6286 | struct cleanup *script_chain; |
6287 | ||
c4093a6a | 6288 | annotate_field (9); |
3b31d625 | 6289 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6290 | print_command_lines (uiout, l, 4); |
3b31d625 | 6291 | do_cleanups (script_chain); |
c4093a6a | 6292 | } |
d24317b4 | 6293 | |
d9b3f62e | 6294 | if (is_tracepoint (b)) |
1042e4c0 | 6295 | { |
d9b3f62e PA |
6296 | struct tracepoint *t = (struct tracepoint *) b; |
6297 | ||
6298 | if (!part_of_multiple && t->pass_count) | |
6299 | { | |
6300 | annotate_field (10); | |
6301 | ui_out_text (uiout, "\tpass count "); | |
6302 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6303 | ui_out_text (uiout, " \n"); | |
6304 | } | |
f2a8bc8a YQ |
6305 | |
6306 | /* Don't display it when tracepoint or tracepoint location is | |
6307 | pending. */ | |
6308 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6309 | { | |
6310 | annotate_field (11); | |
6311 | ||
6312 | if (ui_out_is_mi_like_p (uiout)) | |
6313 | ui_out_field_string (uiout, "installed", | |
6314 | loc->inserted ? "y" : "n"); | |
6315 | else | |
6316 | { | |
6317 | if (loc->inserted) | |
6318 | ui_out_text (uiout, "\t"); | |
6319 | else | |
6320 | ui_out_text (uiout, "\tnot "); | |
6321 | ui_out_text (uiout, "installed on target\n"); | |
6322 | } | |
6323 | } | |
1042e4c0 SS |
6324 | } |
6325 | ||
d24317b4 VP |
6326 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6327 | { | |
3a5c3e22 PA |
6328 | if (is_watchpoint (b)) |
6329 | { | |
6330 | struct watchpoint *w = (struct watchpoint *) b; | |
6331 | ||
6332 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6333 | } | |
6334 | else if (b->addr_string) | |
d24317b4 | 6335 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6336 | } |
c4093a6a | 6337 | } |
c5aa993b | 6338 | |
0d381245 VP |
6339 | static void |
6340 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6341 | struct bp_location **last_loc, |
6c95b8df | 6342 | int allflag) |
0d381245 | 6343 | { |
8d3788bd | 6344 | struct cleanup *bkpt_chain; |
79a45e25 | 6345 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6346 | |
6347 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6348 | ||
12c5a436 | 6349 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6350 | do_cleanups (bkpt_chain); |
0d381245 VP |
6351 | |
6352 | /* If this breakpoint has custom print function, | |
6353 | it's already printed. Otherwise, print individual | |
6354 | locations, if any. */ | |
6355 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6356 | { | |
4a64f543 MS |
6357 | /* If breakpoint has a single location that is disabled, we |
6358 | print it as if it had several locations, since otherwise it's | |
6359 | hard to represent "breakpoint enabled, location disabled" | |
6360 | situation. | |
6361 | ||
6362 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6363 | internally, that's not a property exposed to user. */ |
0d381245 | 6364 | if (b->loc |
a5606eee | 6365 | && !is_hardware_watchpoint (b) |
8d3788bd | 6366 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6367 | { |
6368 | struct bp_location *loc; | |
6369 | int n = 1; | |
8d3788bd | 6370 | |
0d381245 | 6371 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6372 | { |
6373 | struct cleanup *inner2 = | |
6374 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6375 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6376 | do_cleanups (inner2); | |
6377 | } | |
0d381245 VP |
6378 | } |
6379 | } | |
6380 | } | |
6381 | ||
a6d9a66e UW |
6382 | static int |
6383 | breakpoint_address_bits (struct breakpoint *b) | |
6384 | { | |
6385 | int print_address_bits = 0; | |
6386 | struct bp_location *loc; | |
6387 | ||
6388 | for (loc = b->loc; loc; loc = loc->next) | |
6389 | { | |
c7437ca6 PA |
6390 | int addr_bit; |
6391 | ||
6392 | /* Software watchpoints that aren't watching memory don't have | |
6393 | an address to print. */ | |
6394 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6395 | continue; | |
6396 | ||
6397 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6398 | if (addr_bit > print_address_bits) |
6399 | print_address_bits = addr_bit; | |
6400 | } | |
6401 | ||
6402 | return print_address_bits; | |
6403 | } | |
0d381245 | 6404 | |
c4093a6a JM |
6405 | struct captured_breakpoint_query_args |
6406 | { | |
6407 | int bnum; | |
6408 | }; | |
c5aa993b | 6409 | |
c4093a6a | 6410 | static int |
2b65245e | 6411 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6412 | { |
6413 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6414 | struct breakpoint *b; |
a6d9a66e | 6415 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6416 | |
c4093a6a JM |
6417 | ALL_BREAKPOINTS (b) |
6418 | { | |
6419 | if (args->bnum == b->number) | |
c5aa993b | 6420 | { |
12c5a436 | 6421 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6422 | return GDB_RC_OK; |
c5aa993b | 6423 | } |
c4093a6a JM |
6424 | } |
6425 | return GDB_RC_NONE; | |
6426 | } | |
c5aa993b | 6427 | |
c4093a6a | 6428 | enum gdb_rc |
4a64f543 MS |
6429 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6430 | char **error_message) | |
c4093a6a JM |
6431 | { |
6432 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6433 | |
c4093a6a JM |
6434 | args.bnum = bnum; |
6435 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6436 | an error. */ |
b0b13bb4 DJ |
6437 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6438 | error_message, RETURN_MASK_ALL) < 0) | |
6439 | return GDB_RC_FAIL; | |
6440 | else | |
6441 | return GDB_RC_OK; | |
c4093a6a | 6442 | } |
c5aa993b | 6443 | |
09d682a4 TT |
6444 | /* Return true if this breakpoint was set by the user, false if it is |
6445 | internal or momentary. */ | |
6446 | ||
6447 | int | |
6448 | user_breakpoint_p (struct breakpoint *b) | |
6449 | { | |
46c6471b | 6450 | return b->number > 0; |
09d682a4 TT |
6451 | } |
6452 | ||
7f3b0473 | 6453 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6454 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6455 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6456 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6457 | ones for which it returns non-zero. Return the total number of | |
6458 | breakpoints listed. */ | |
c906108c | 6459 | |
d77f58be | 6460 | static int |
e5a67952 | 6461 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6462 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6463 | { |
52f0bd74 | 6464 | struct breakpoint *b; |
a6d9a66e | 6465 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6466 | int nr_printable_breakpoints; |
3b31d625 | 6467 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6468 | struct value_print_options opts; |
a6d9a66e | 6469 | int print_address_bits = 0; |
269b11a2 | 6470 | int print_type_col_width = 14; |
79a45e25 | 6471 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6472 | |
79a45b7d TT |
6473 | get_user_print_options (&opts); |
6474 | ||
4a64f543 MS |
6475 | /* Compute the number of rows in the table, as well as the size |
6476 | required for address fields. */ | |
7f3b0473 AC |
6477 | nr_printable_breakpoints = 0; |
6478 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6479 | { |
6480 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6481 | if (filter && !filter (b)) | |
6482 | continue; | |
6483 | ||
6484 | /* If we have an "args" string, it is a list of breakpoints to | |
6485 | accept. Skip the others. */ | |
6486 | if (args != NULL && *args != '\0') | |
6487 | { | |
6488 | if (allflag && parse_and_eval_long (args) != b->number) | |
6489 | continue; | |
6490 | if (!allflag && !number_is_in_list (args, b->number)) | |
6491 | continue; | |
6492 | } | |
269b11a2 | 6493 | |
e5a67952 MS |
6494 | if (allflag || user_breakpoint_p (b)) |
6495 | { | |
6496 | int addr_bit, type_len; | |
a6d9a66e | 6497 | |
e5a67952 MS |
6498 | addr_bit = breakpoint_address_bits (b); |
6499 | if (addr_bit > print_address_bits) | |
6500 | print_address_bits = addr_bit; | |
269b11a2 | 6501 | |
e5a67952 MS |
6502 | type_len = strlen (bptype_string (b->type)); |
6503 | if (type_len > print_type_col_width) | |
6504 | print_type_col_width = type_len; | |
6505 | ||
6506 | nr_printable_breakpoints++; | |
6507 | } | |
6508 | } | |
7f3b0473 | 6509 | |
79a45b7d | 6510 | if (opts.addressprint) |
3b31d625 | 6511 | bkpttbl_chain |
3e43a32a MS |
6512 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6513 | nr_printable_breakpoints, | |
3b31d625 | 6514 | "BreakpointTable"); |
8b93c638 | 6515 | else |
3b31d625 | 6516 | bkpttbl_chain |
3e43a32a MS |
6517 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6518 | nr_printable_breakpoints, | |
3b31d625 | 6519 | "BreakpointTable"); |
8b93c638 | 6520 | |
7f3b0473 | 6521 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6522 | annotate_breakpoints_headers (); |
6523 | if (nr_printable_breakpoints > 0) | |
6524 | annotate_field (0); | |
4a64f543 | 6525 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6526 | if (nr_printable_breakpoints > 0) |
6527 | annotate_field (1); | |
269b11a2 | 6528 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6529 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6530 | if (nr_printable_breakpoints > 0) |
6531 | annotate_field (2); | |
4a64f543 | 6532 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6533 | if (nr_printable_breakpoints > 0) |
6534 | annotate_field (3); | |
54e52265 | 6535 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6536 | if (opts.addressprint) |
e5a67952 MS |
6537 | { |
6538 | if (nr_printable_breakpoints > 0) | |
6539 | annotate_field (4); | |
6540 | if (print_address_bits <= 32) | |
6541 | ui_out_table_header (uiout, 10, ui_left, | |
6542 | "addr", "Address"); /* 5 */ | |
6543 | else | |
6544 | ui_out_table_header (uiout, 18, ui_left, | |
6545 | "addr", "Address"); /* 5 */ | |
6546 | } | |
d7faa9e7 AC |
6547 | if (nr_printable_breakpoints > 0) |
6548 | annotate_field (5); | |
6549 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6550 | ui_out_table_body (uiout); | |
6551 | if (nr_printable_breakpoints > 0) | |
6552 | annotate_breakpoints_table (); | |
7f3b0473 | 6553 | |
c4093a6a | 6554 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6555 | { |
6556 | QUIT; | |
6557 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6558 | if (filter && !filter (b)) | |
6559 | continue; | |
6560 | ||
6561 | /* If we have an "args" string, it is a list of breakpoints to | |
6562 | accept. Skip the others. */ | |
6563 | ||
6564 | if (args != NULL && *args != '\0') | |
6565 | { | |
6566 | if (allflag) /* maintenance info breakpoint */ | |
6567 | { | |
6568 | if (parse_and_eval_long (args) != b->number) | |
6569 | continue; | |
6570 | } | |
6571 | else /* all others */ | |
6572 | { | |
6573 | if (!number_is_in_list (args, b->number)) | |
6574 | continue; | |
6575 | } | |
6576 | } | |
6577 | /* We only print out user settable breakpoints unless the | |
6578 | allflag is set. */ | |
6579 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6580 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6581 | } |
6582 | ||
3b31d625 | 6583 | do_cleanups (bkpttbl_chain); |
698384cd | 6584 | |
7f3b0473 | 6585 | if (nr_printable_breakpoints == 0) |
c906108c | 6586 | { |
4a64f543 MS |
6587 | /* If there's a filter, let the caller decide how to report |
6588 | empty list. */ | |
d77f58be SS |
6589 | if (!filter) |
6590 | { | |
e5a67952 | 6591 | if (args == NULL || *args == '\0') |
d77f58be SS |
6592 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6593 | else | |
4a64f543 | 6594 | ui_out_message (uiout, 0, |
e5a67952 MS |
6595 | "No breakpoint or watchpoint matching '%s'.\n", |
6596 | args); | |
d77f58be | 6597 | } |
c906108c SS |
6598 | } |
6599 | else | |
c4093a6a | 6600 | { |
a6d9a66e UW |
6601 | if (last_loc && !server_command) |
6602 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6603 | } |
c906108c | 6604 | |
4a64f543 | 6605 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6606 | there have been breakpoints? */ |
c906108c | 6607 | annotate_breakpoints_table_end (); |
d77f58be SS |
6608 | |
6609 | return nr_printable_breakpoints; | |
c906108c SS |
6610 | } |
6611 | ||
ad443146 SS |
6612 | /* Display the value of default-collect in a way that is generally |
6613 | compatible with the breakpoint list. */ | |
6614 | ||
6615 | static void | |
6616 | default_collect_info (void) | |
6617 | { | |
79a45e25 PA |
6618 | struct ui_out *uiout = current_uiout; |
6619 | ||
ad443146 SS |
6620 | /* If it has no value (which is frequently the case), say nothing; a |
6621 | message like "No default-collect." gets in user's face when it's | |
6622 | not wanted. */ | |
6623 | if (!*default_collect) | |
6624 | return; | |
6625 | ||
6626 | /* The following phrase lines up nicely with per-tracepoint collect | |
6627 | actions. */ | |
6628 | ui_out_text (uiout, "default collect "); | |
6629 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6630 | ui_out_text (uiout, " \n"); | |
6631 | } | |
6632 | ||
c906108c | 6633 | static void |
e5a67952 | 6634 | breakpoints_info (char *args, int from_tty) |
c906108c | 6635 | { |
e5a67952 | 6636 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6637 | |
6638 | default_collect_info (); | |
d77f58be SS |
6639 | } |
6640 | ||
6641 | static void | |
e5a67952 | 6642 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6643 | { |
e5a67952 | 6644 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6645 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6646 | |
6647 | if (num_printed == 0) | |
6648 | { | |
e5a67952 | 6649 | if (args == NULL || *args == '\0') |
d77f58be SS |
6650 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6651 | else | |
e5a67952 | 6652 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6653 | } |
c906108c SS |
6654 | } |
6655 | ||
7a292a7a | 6656 | static void |
e5a67952 | 6657 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6658 | { |
e5a67952 | 6659 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6660 | |
6661 | default_collect_info (); | |
c906108c SS |
6662 | } |
6663 | ||
0d381245 | 6664 | static int |
714835d5 | 6665 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6666 | struct program_space *pspace, |
714835d5 | 6667 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6668 | { |
6669 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6670 | |
0d381245 VP |
6671 | for (; bl; bl = bl->next) |
6672 | { | |
6c95b8df PA |
6673 | if (bl->pspace == pspace |
6674 | && bl->address == pc | |
0d381245 VP |
6675 | && (!overlay_debugging || bl->section == section)) |
6676 | return 1; | |
6677 | } | |
6678 | return 0; | |
6679 | } | |
6680 | ||
672f9b60 | 6681 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6682 | concerns with logical breakpoints, so we match program spaces, not |
6683 | address spaces. */ | |
c906108c SS |
6684 | |
6685 | static void | |
6c95b8df PA |
6686 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6687 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6688 | struct obj_section *section, int thread) |
c906108c | 6689 | { |
52f0bd74 AC |
6690 | int others = 0; |
6691 | struct breakpoint *b; | |
c906108c SS |
6692 | |
6693 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6694 | others += (user_breakpoint_p (b) |
6695 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6696 | if (others > 0) |
6697 | { | |
a3f17187 AC |
6698 | if (others == 1) |
6699 | printf_filtered (_("Note: breakpoint ")); | |
6700 | else /* if (others == ???) */ | |
6701 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6702 | ALL_BREAKPOINTS (b) |
672f9b60 | 6703 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6704 | { |
6705 | others--; | |
6706 | printf_filtered ("%d", b->number); | |
6707 | if (b->thread == -1 && thread != -1) | |
6708 | printf_filtered (" (all threads)"); | |
6709 | else if (b->thread != -1) | |
6710 | printf_filtered (" (thread %d)", b->thread); | |
6711 | printf_filtered ("%s%s ", | |
059fb39f | 6712 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6713 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6714 | ? " (disabled)" |
6715 | : b->enable_state == bp_permanent | |
6716 | ? " (permanent)" | |
6717 | : ""), | |
6718 | (others > 1) ? "," | |
6719 | : ((others == 1) ? " and" : "")); | |
6720 | } | |
a3f17187 | 6721 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6722 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6723 | printf_filtered (".\n"); |
6724 | } | |
6725 | } | |
6726 | \f | |
c906108c | 6727 | |
e4f237da KB |
6728 | /* Return true iff it is meaningful to use the address member of |
6729 | BPT. For some breakpoint types, the address member is irrelevant | |
6730 | and it makes no sense to attempt to compare it to other addresses | |
6731 | (or use it for any other purpose either). | |
6732 | ||
4a64f543 MS |
6733 | More specifically, each of the following breakpoint types will |
6734 | always have a zero valued address and we don't want to mark | |
6735 | breakpoints of any of these types to be a duplicate of an actual | |
6736 | breakpoint at address zero: | |
e4f237da KB |
6737 | |
6738 | bp_watchpoint | |
2d134ed3 PA |
6739 | bp_catchpoint |
6740 | ||
6741 | */ | |
e4f237da KB |
6742 | |
6743 | static int | |
6744 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6745 | { | |
6746 | enum bptype type = bpt->type; | |
6747 | ||
2d134ed3 PA |
6748 | return (type != bp_watchpoint && type != bp_catchpoint); |
6749 | } | |
6750 | ||
6751 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6752 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6753 | ||
6754 | static int | |
4a64f543 MS |
6755 | watchpoint_locations_match (struct bp_location *loc1, |
6756 | struct bp_location *loc2) | |
2d134ed3 | 6757 | { |
3a5c3e22 PA |
6758 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6759 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6760 | ||
6761 | /* Both of them must exist. */ | |
6762 | gdb_assert (w1 != NULL); | |
6763 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6764 | |
4a64f543 MS |
6765 | /* If the target can evaluate the condition expression in hardware, |
6766 | then we we need to insert both watchpoints even if they are at | |
6767 | the same place. Otherwise the watchpoint will only trigger when | |
6768 | the condition of whichever watchpoint was inserted evaluates to | |
6769 | true, not giving a chance for GDB to check the condition of the | |
6770 | other watchpoint. */ | |
3a5c3e22 | 6771 | if ((w1->cond_exp |
4a64f543 MS |
6772 | && target_can_accel_watchpoint_condition (loc1->address, |
6773 | loc1->length, | |
0cf6dd15 | 6774 | loc1->watchpoint_type, |
3a5c3e22 PA |
6775 | w1->cond_exp)) |
6776 | || (w2->cond_exp | |
4a64f543 MS |
6777 | && target_can_accel_watchpoint_condition (loc2->address, |
6778 | loc2->length, | |
0cf6dd15 | 6779 | loc2->watchpoint_type, |
3a5c3e22 | 6780 | w2->cond_exp))) |
0cf6dd15 TJB |
6781 | return 0; |
6782 | ||
85d721b8 PA |
6783 | /* Note that this checks the owner's type, not the location's. In |
6784 | case the target does not support read watchpoints, but does | |
6785 | support access watchpoints, we'll have bp_read_watchpoint | |
6786 | watchpoints with hw_access locations. Those should be considered | |
6787 | duplicates of hw_read locations. The hw_read locations will | |
6788 | become hw_access locations later. */ | |
2d134ed3 PA |
6789 | return (loc1->owner->type == loc2->owner->type |
6790 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6791 | && loc1->address == loc2->address | |
6792 | && loc1->length == loc2->length); | |
e4f237da KB |
6793 | } |
6794 | ||
31e77af2 | 6795 | /* See breakpoint.h. */ |
6c95b8df | 6796 | |
31e77af2 | 6797 | int |
6c95b8df PA |
6798 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6799 | struct address_space *aspace2, CORE_ADDR addr2) | |
6800 | { | |
f5656ead | 6801 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6802 | || aspace1 == aspace2) |
6803 | && addr1 == addr2); | |
6804 | } | |
6805 | ||
f1310107 TJB |
6806 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6807 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6808 | matches ASPACE2. On targets that have global breakpoints, the address | |
6809 | space doesn't really matter. */ | |
6810 | ||
6811 | static int | |
6812 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6813 | int len1, struct address_space *aspace2, | |
6814 | CORE_ADDR addr2) | |
6815 | { | |
f5656ead | 6816 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6817 | || aspace1 == aspace2) |
6818 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6819 | } | |
6820 | ||
6821 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6822 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6823 | matches the breakpoint's address space. On targets that have global | |
6824 | breakpoints, the address space doesn't really matter. */ | |
6825 | ||
6826 | static int | |
6827 | breakpoint_location_address_match (struct bp_location *bl, | |
6828 | struct address_space *aspace, | |
6829 | CORE_ADDR addr) | |
6830 | { | |
6831 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6832 | aspace, addr) | |
6833 | || (bl->length | |
6834 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6835 | bl->address, bl->length, | |
6836 | aspace, addr))); | |
6837 | } | |
6838 | ||
1e4d1764 YQ |
6839 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6840 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6841 | true, otherwise returns false. */ | |
6842 | ||
6843 | static int | |
6844 | tracepoint_locations_match (struct bp_location *loc1, | |
6845 | struct bp_location *loc2) | |
6846 | { | |
6847 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6848 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6849 | locations at the same address of different tracepoints are regarded as | |
6850 | different locations. */ | |
6851 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6852 | else | |
6853 | return 0; | |
6854 | } | |
6855 | ||
2d134ed3 PA |
6856 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6857 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6858 | represent the same location. */ | |
6859 | ||
6860 | static int | |
4a64f543 MS |
6861 | breakpoint_locations_match (struct bp_location *loc1, |
6862 | struct bp_location *loc2) | |
2d134ed3 | 6863 | { |
2bdf28a0 JK |
6864 | int hw_point1, hw_point2; |
6865 | ||
6866 | /* Both of them must not be in moribund_locations. */ | |
6867 | gdb_assert (loc1->owner != NULL); | |
6868 | gdb_assert (loc2->owner != NULL); | |
6869 | ||
6870 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6871 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6872 | |
6873 | if (hw_point1 != hw_point2) | |
6874 | return 0; | |
6875 | else if (hw_point1) | |
6876 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6877 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6878 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6879 | else |
f1310107 TJB |
6880 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6881 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6882 | loc2->pspace->aspace, loc2->address) | |
6883 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6884 | } |
6885 | ||
76897487 KB |
6886 | static void |
6887 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6888 | int bnum, int have_bnum) | |
6889 | { | |
f63fbe86 MS |
6890 | /* The longest string possibly returned by hex_string_custom |
6891 | is 50 chars. These must be at least that big for safety. */ | |
6892 | char astr1[64]; | |
6893 | char astr2[64]; | |
76897487 | 6894 | |
bb599908 PH |
6895 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6896 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6897 | if (have_bnum) |
8a3fe4f8 | 6898 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6899 | bnum, astr1, astr2); |
6900 | else | |
8a3fe4f8 | 6901 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6902 | } |
6903 | ||
4a64f543 MS |
6904 | /* Adjust a breakpoint's address to account for architectural |
6905 | constraints on breakpoint placement. Return the adjusted address. | |
6906 | Note: Very few targets require this kind of adjustment. For most | |
6907 | targets, this function is simply the identity function. */ | |
76897487 KB |
6908 | |
6909 | static CORE_ADDR | |
a6d9a66e UW |
6910 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6911 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6912 | { |
a6d9a66e | 6913 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6914 | { |
6915 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6916 | return bpaddr; | |
6917 | } | |
88f7da05 KB |
6918 | else if (bptype == bp_watchpoint |
6919 | || bptype == bp_hardware_watchpoint | |
6920 | || bptype == bp_read_watchpoint | |
6921 | || bptype == bp_access_watchpoint | |
fe798b75 | 6922 | || bptype == bp_catchpoint) |
88f7da05 KB |
6923 | { |
6924 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6925 | have their addresses modified. */ | |
6926 | return bpaddr; | |
6927 | } | |
76897487 KB |
6928 | else |
6929 | { | |
6930 | CORE_ADDR adjusted_bpaddr; | |
6931 | ||
6932 | /* Some targets have architectural constraints on the placement | |
6933 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6934 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6935 | |
6936 | /* An adjusted breakpoint address can significantly alter | |
6937 | a user's expectations. Print a warning if an adjustment | |
6938 | is required. */ | |
6939 | if (adjusted_bpaddr != bpaddr) | |
6940 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6941 | ||
6942 | return adjusted_bpaddr; | |
6943 | } | |
6944 | } | |
6945 | ||
28010a5d PA |
6946 | void |
6947 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6948 | struct breakpoint *owner) | |
7cc221ef | 6949 | { |
7cc221ef DJ |
6950 | memset (loc, 0, sizeof (*loc)); |
6951 | ||
348d480f PA |
6952 | gdb_assert (ops != NULL); |
6953 | ||
28010a5d PA |
6954 | loc->ops = ops; |
6955 | loc->owner = owner; | |
511a6cd4 | 6956 | loc->cond = NULL; |
b775012e | 6957 | loc->cond_bytecode = NULL; |
0d381245 VP |
6958 | loc->shlib_disabled = 0; |
6959 | loc->enabled = 1; | |
e049a4b5 | 6960 | |
28010a5d | 6961 | switch (owner->type) |
e049a4b5 DJ |
6962 | { |
6963 | case bp_breakpoint: | |
6964 | case bp_until: | |
6965 | case bp_finish: | |
6966 | case bp_longjmp: | |
6967 | case bp_longjmp_resume: | |
e2e4d78b | 6968 | case bp_longjmp_call_dummy: |
186c406b TT |
6969 | case bp_exception: |
6970 | case bp_exception_resume: | |
e049a4b5 | 6971 | case bp_step_resume: |
2c03e5be | 6972 | case bp_hp_step_resume: |
e049a4b5 DJ |
6973 | case bp_watchpoint_scope: |
6974 | case bp_call_dummy: | |
aa7d318d | 6975 | case bp_std_terminate: |
e049a4b5 DJ |
6976 | case bp_shlib_event: |
6977 | case bp_thread_event: | |
6978 | case bp_overlay_event: | |
4efc6507 | 6979 | case bp_jit_event: |
0fd8e87f | 6980 | case bp_longjmp_master: |
aa7d318d | 6981 | case bp_std_terminate_master: |
186c406b | 6982 | case bp_exception_master: |
0e30163f JK |
6983 | case bp_gnu_ifunc_resolver: |
6984 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6985 | case bp_dprintf: |
e049a4b5 | 6986 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6987 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6988 | break; |
6989 | case bp_hardware_breakpoint: | |
6990 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6991 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6992 | break; |
6993 | case bp_hardware_watchpoint: | |
6994 | case bp_read_watchpoint: | |
6995 | case bp_access_watchpoint: | |
6996 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6997 | break; | |
6998 | case bp_watchpoint: | |
ce78b96d | 6999 | case bp_catchpoint: |
15c3d785 PA |
7000 | case bp_tracepoint: |
7001 | case bp_fast_tracepoint: | |
0fb4aa4b | 7002 | case bp_static_tracepoint: |
e049a4b5 DJ |
7003 | loc->loc_type = bp_loc_other; |
7004 | break; | |
7005 | default: | |
e2e0b3e5 | 7006 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7007 | } |
7008 | ||
f431efe5 | 7009 | loc->refc = 1; |
28010a5d PA |
7010 | } |
7011 | ||
7012 | /* Allocate a struct bp_location. */ | |
7013 | ||
7014 | static struct bp_location * | |
7015 | allocate_bp_location (struct breakpoint *bpt) | |
7016 | { | |
348d480f PA |
7017 | return bpt->ops->allocate_location (bpt); |
7018 | } | |
7cc221ef | 7019 | |
f431efe5 PA |
7020 | static void |
7021 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7022 | { |
348d480f | 7023 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7024 | xfree (loc); |
7025 | } | |
7026 | ||
f431efe5 PA |
7027 | /* Increment reference count. */ |
7028 | ||
7029 | static void | |
7030 | incref_bp_location (struct bp_location *bl) | |
7031 | { | |
7032 | ++bl->refc; | |
7033 | } | |
7034 | ||
7035 | /* Decrement reference count. If the reference count reaches 0, | |
7036 | destroy the bp_location. Sets *BLP to NULL. */ | |
7037 | ||
7038 | static void | |
7039 | decref_bp_location (struct bp_location **blp) | |
7040 | { | |
0807b50c PA |
7041 | gdb_assert ((*blp)->refc > 0); |
7042 | ||
f431efe5 PA |
7043 | if (--(*blp)->refc == 0) |
7044 | free_bp_location (*blp); | |
7045 | *blp = NULL; | |
7046 | } | |
7047 | ||
346774a9 | 7048 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7049 | |
346774a9 PA |
7050 | static void |
7051 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7052 | { |
346774a9 | 7053 | struct breakpoint *b1; |
c906108c | 7054 | |
346774a9 PA |
7055 | /* Add this breakpoint to the end of the chain so that a list of |
7056 | breakpoints will come out in order of increasing numbers. */ | |
7057 | ||
7058 | b1 = breakpoint_chain; | |
7059 | if (b1 == 0) | |
7060 | breakpoint_chain = b; | |
7061 | else | |
7062 | { | |
7063 | while (b1->next) | |
7064 | b1 = b1->next; | |
7065 | b1->next = b; | |
7066 | } | |
7067 | } | |
7068 | ||
7069 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7070 | ||
7071 | static void | |
7072 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7073 | struct gdbarch *gdbarch, | |
28010a5d | 7074 | enum bptype bptype, |
c0a91b2b | 7075 | const struct breakpoint_ops *ops) |
346774a9 | 7076 | { |
c906108c | 7077 | memset (b, 0, sizeof (*b)); |
2219d63c | 7078 | |
348d480f PA |
7079 | gdb_assert (ops != NULL); |
7080 | ||
28010a5d | 7081 | b->ops = ops; |
4d28f7a8 | 7082 | b->type = bptype; |
a6d9a66e | 7083 | b->gdbarch = gdbarch; |
c906108c SS |
7084 | b->language = current_language->la_language; |
7085 | b->input_radix = input_radix; | |
7086 | b->thread = -1; | |
b5de0fa7 | 7087 | b->enable_state = bp_enabled; |
c906108c SS |
7088 | b->next = 0; |
7089 | b->silent = 0; | |
7090 | b->ignore_count = 0; | |
7091 | b->commands = NULL; | |
818dd999 | 7092 | b->frame_id = null_frame_id; |
0d381245 | 7093 | b->condition_not_parsed = 0; |
84f4c1fe | 7094 | b->py_bp_object = NULL; |
d0fb5eae | 7095 | b->related_breakpoint = b; |
346774a9 PA |
7096 | } |
7097 | ||
7098 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7099 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7100 | |
7101 | static struct breakpoint * | |
7102 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7103 | enum bptype bptype, |
c0a91b2b | 7104 | const struct breakpoint_ops *ops) |
346774a9 PA |
7105 | { |
7106 | struct breakpoint *b = XNEW (struct breakpoint); | |
7107 | ||
348d480f | 7108 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7109 | add_to_breakpoint_chain (b); |
0d381245 VP |
7110 | return b; |
7111 | } | |
7112 | ||
0e30163f JK |
7113 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7114 | resolutions should be made as the user specified the location explicitly | |
7115 | enough. */ | |
7116 | ||
0d381245 | 7117 | static void |
0e30163f | 7118 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7119 | { |
2bdf28a0 JK |
7120 | gdb_assert (loc->owner != NULL); |
7121 | ||
0d381245 | 7122 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7123 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7124 | || is_tracepoint (loc->owner)) |
0d381245 | 7125 | { |
0e30163f | 7126 | int is_gnu_ifunc; |
2c02bd72 | 7127 | const char *function_name; |
6a3a010b | 7128 | CORE_ADDR func_addr; |
0e30163f | 7129 | |
2c02bd72 | 7130 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7131 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7132 | |
7133 | if (is_gnu_ifunc && !explicit_loc) | |
7134 | { | |
7135 | struct breakpoint *b = loc->owner; | |
7136 | ||
7137 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7138 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7139 | &loc->requested_address)) |
7140 | { | |
7141 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7142 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7143 | loc->requested_address, | |
7144 | b->type); | |
7145 | } | |
7146 | else if (b->type == bp_breakpoint && b->loc == loc | |
7147 | && loc->next == NULL && b->related_breakpoint == b) | |
7148 | { | |
7149 | /* Create only the whole new breakpoint of this type but do not | |
7150 | mess more complicated breakpoints with multiple locations. */ | |
7151 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7152 | /* Remember the resolver's address for use by the return |
7153 | breakpoint. */ | |
7154 | loc->related_address = func_addr; | |
0e30163f JK |
7155 | } |
7156 | } | |
7157 | ||
2c02bd72 DE |
7158 | if (function_name) |
7159 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7160 | } |
7161 | } | |
7162 | ||
a6d9a66e | 7163 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7164 | struct gdbarch * |
a6d9a66e UW |
7165 | get_sal_arch (struct symtab_and_line sal) |
7166 | { | |
7167 | if (sal.section) | |
7168 | return get_objfile_arch (sal.section->objfile); | |
7169 | if (sal.symtab) | |
7170 | return get_objfile_arch (sal.symtab->objfile); | |
7171 | ||
7172 | return NULL; | |
7173 | } | |
7174 | ||
346774a9 PA |
7175 | /* Low level routine for partially initializing a breakpoint of type |
7176 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7177 | file name, and line number are provided by SAL. |
0d381245 VP |
7178 | |
7179 | It is expected that the caller will complete the initialization of | |
7180 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7181 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7182 | |
346774a9 PA |
7183 | static void |
7184 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7185 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7186 | const struct breakpoint_ops *ops) |
0d381245 | 7187 | { |
28010a5d | 7188 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7189 | |
3742cc8b | 7190 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7191 | |
6c95b8df PA |
7192 | if (bptype != bp_catchpoint) |
7193 | gdb_assert (sal.pspace != NULL); | |
7194 | ||
f8eba3c6 TT |
7195 | /* Store the program space that was used to set the breakpoint, |
7196 | except for ordinary breakpoints, which are independent of the | |
7197 | program space. */ | |
7198 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7199 | b->pspace = sal.pspace; | |
346774a9 | 7200 | } |
c906108c | 7201 | |
346774a9 PA |
7202 | /* set_raw_breakpoint is a low level routine for allocating and |
7203 | partially initializing a breakpoint of type BPTYPE. The newly | |
7204 | created breakpoint's address, section, source file name, and line | |
7205 | number are provided by SAL. The newly created and partially | |
7206 | initialized breakpoint is added to the breakpoint chain and | |
7207 | is also returned as the value of this function. | |
7208 | ||
7209 | It is expected that the caller will complete the initialization of | |
7210 | the newly created breakpoint struct as well as output any status | |
7211 | information regarding the creation of a new breakpoint. In | |
7212 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7213 | number! Care should be taken to not allow an error to occur | |
7214 | prior to completing the initialization of the breakpoint. If this | |
7215 | should happen, a bogus breakpoint will be left on the chain. */ | |
7216 | ||
7217 | struct breakpoint * | |
7218 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7219 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7220 | const struct breakpoint_ops *ops) |
346774a9 PA |
7221 | { |
7222 | struct breakpoint *b = XNEW (struct breakpoint); | |
7223 | ||
348d480f | 7224 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7225 | add_to_breakpoint_chain (b); |
c906108c SS |
7226 | return b; |
7227 | } | |
7228 | ||
c2c6d25f JM |
7229 | |
7230 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7231 | instruction, hard-wired into the inferior's code. */ | |
7232 | void | |
7233 | make_breakpoint_permanent (struct breakpoint *b) | |
7234 | { | |
0d381245 | 7235 | struct bp_location *bl; |
cc59ec59 | 7236 | |
b5de0fa7 | 7237 | b->enable_state = bp_permanent; |
c2c6d25f | 7238 | |
4a64f543 MS |
7239 | /* By definition, permanent breakpoints are already present in the |
7240 | code. Mark all locations as inserted. For now, | |
7241 | make_breakpoint_permanent is called in just one place, so it's | |
7242 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7243 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7244 | for (bl = b->loc; bl; bl = bl->next) |
7245 | bl->inserted = 1; | |
c2c6d25f JM |
7246 | } |
7247 | ||
53a5351d | 7248 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7249 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7250 | initiated the operation. */ | |
c906108c SS |
7251 | |
7252 | void | |
186c406b | 7253 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7254 | { |
35df4500 | 7255 | struct breakpoint *b, *b_tmp; |
186c406b | 7256 | int thread = tp->num; |
0fd8e87f UW |
7257 | |
7258 | /* To avoid having to rescan all objfile symbols at every step, | |
7259 | we maintain a list of continually-inserted but always disabled | |
7260 | longjmp "master" breakpoints. Here, we simply create momentary | |
7261 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7262 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7263 | if (b->pspace == current_program_space |
186c406b TT |
7264 | && (b->type == bp_longjmp_master |
7265 | || b->type == bp_exception_master)) | |
0fd8e87f | 7266 | { |
06edf0c0 PA |
7267 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7268 | struct breakpoint *clone; | |
cc59ec59 | 7269 | |
e2e4d78b JK |
7270 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7271 | after their removal. */ | |
06edf0c0 | 7272 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7273 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7274 | clone->thread = thread; |
7275 | } | |
186c406b TT |
7276 | |
7277 | tp->initiating_frame = frame; | |
c906108c SS |
7278 | } |
7279 | ||
611c83ae | 7280 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7281 | void |
611c83ae | 7282 | delete_longjmp_breakpoint (int thread) |
c906108c | 7283 | { |
35df4500 | 7284 | struct breakpoint *b, *b_tmp; |
c906108c | 7285 | |
35df4500 | 7286 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7287 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7288 | { |
7289 | if (b->thread == thread) | |
7290 | delete_breakpoint (b); | |
7291 | } | |
c906108c SS |
7292 | } |
7293 | ||
f59f708a PA |
7294 | void |
7295 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7296 | { | |
7297 | struct breakpoint *b, *b_tmp; | |
7298 | ||
7299 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7300 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7301 | { | |
7302 | if (b->thread == thread) | |
7303 | b->disposition = disp_del_at_next_stop; | |
7304 | } | |
7305 | } | |
7306 | ||
e2e4d78b JK |
7307 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7308 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7309 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7310 | breakpoints. */ | |
7311 | ||
7312 | struct breakpoint * | |
7313 | set_longjmp_breakpoint_for_call_dummy (void) | |
7314 | { | |
7315 | struct breakpoint *b, *retval = NULL; | |
7316 | ||
7317 | ALL_BREAKPOINTS (b) | |
7318 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7319 | { | |
7320 | struct breakpoint *new_b; | |
7321 | ||
7322 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7323 | &momentary_breakpoint_ops); | |
7324 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7325 | ||
7326 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7327 | ||
7328 | gdb_assert (new_b->related_breakpoint == new_b); | |
7329 | if (retval == NULL) | |
7330 | retval = new_b; | |
7331 | new_b->related_breakpoint = retval; | |
7332 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7333 | retval = retval->related_breakpoint; | |
7334 | retval->related_breakpoint = new_b; | |
7335 | } | |
7336 | ||
7337 | return retval; | |
7338 | } | |
7339 | ||
7340 | /* Verify all existing dummy frames and their associated breakpoints for | |
7341 | THREAD. Remove those which can no longer be found in the current frame | |
7342 | stack. | |
7343 | ||
7344 | You should call this function only at places where it is safe to currently | |
7345 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7346 | frames. */ | |
7347 | ||
7348 | void | |
7349 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7350 | { | |
7351 | struct breakpoint *b, *b_tmp; | |
7352 | ||
7353 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7354 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7355 | { | |
7356 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7357 | ||
7358 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7359 | dummy_b = dummy_b->related_breakpoint; | |
7360 | if (dummy_b->type != bp_call_dummy | |
7361 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7362 | continue; | |
7363 | ||
7364 | dummy_frame_discard (dummy_b->frame_id); | |
7365 | ||
7366 | while (b->related_breakpoint != b) | |
7367 | { | |
7368 | if (b_tmp == b->related_breakpoint) | |
7369 | b_tmp = b->related_breakpoint->next; | |
7370 | delete_breakpoint (b->related_breakpoint); | |
7371 | } | |
7372 | delete_breakpoint (b); | |
7373 | } | |
7374 | } | |
7375 | ||
1900040c MS |
7376 | void |
7377 | enable_overlay_breakpoints (void) | |
7378 | { | |
52f0bd74 | 7379 | struct breakpoint *b; |
1900040c MS |
7380 | |
7381 | ALL_BREAKPOINTS (b) | |
7382 | if (b->type == bp_overlay_event) | |
7383 | { | |
7384 | b->enable_state = bp_enabled; | |
b60e7edf | 7385 | update_global_location_list (1); |
c02f5703 | 7386 | overlay_events_enabled = 1; |
1900040c MS |
7387 | } |
7388 | } | |
7389 | ||
7390 | void | |
7391 | disable_overlay_breakpoints (void) | |
7392 | { | |
52f0bd74 | 7393 | struct breakpoint *b; |
1900040c MS |
7394 | |
7395 | ALL_BREAKPOINTS (b) | |
7396 | if (b->type == bp_overlay_event) | |
7397 | { | |
7398 | b->enable_state = bp_disabled; | |
b60e7edf | 7399 | update_global_location_list (0); |
c02f5703 | 7400 | overlay_events_enabled = 0; |
1900040c MS |
7401 | } |
7402 | } | |
7403 | ||
aa7d318d TT |
7404 | /* Set an active std::terminate breakpoint for each std::terminate |
7405 | master breakpoint. */ | |
7406 | void | |
7407 | set_std_terminate_breakpoint (void) | |
7408 | { | |
35df4500 | 7409 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7410 | |
35df4500 | 7411 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7412 | if (b->pspace == current_program_space |
7413 | && b->type == bp_std_terminate_master) | |
7414 | { | |
06edf0c0 PA |
7415 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7416 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7417 | } |
7418 | } | |
7419 | ||
7420 | /* Delete all the std::terminate breakpoints. */ | |
7421 | void | |
7422 | delete_std_terminate_breakpoint (void) | |
7423 | { | |
35df4500 | 7424 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7425 | |
35df4500 | 7426 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7427 | if (b->type == bp_std_terminate) |
7428 | delete_breakpoint (b); | |
7429 | } | |
7430 | ||
c4093a6a | 7431 | struct breakpoint * |
a6d9a66e | 7432 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7433 | { |
7434 | struct breakpoint *b; | |
c4093a6a | 7435 | |
06edf0c0 PA |
7436 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7437 | &internal_breakpoint_ops); | |
7438 | ||
b5de0fa7 | 7439 | b->enable_state = bp_enabled; |
c4093a6a | 7440 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7441 | b->addr_string |
7442 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7443 | |
b60e7edf | 7444 | update_global_location_list_nothrow (1); |
74960c60 | 7445 | |
c4093a6a JM |
7446 | return b; |
7447 | } | |
7448 | ||
7449 | void | |
7450 | remove_thread_event_breakpoints (void) | |
7451 | { | |
35df4500 | 7452 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7453 | |
35df4500 | 7454 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7455 | if (b->type == bp_thread_event |
7456 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7457 | delete_breakpoint (b); |
7458 | } | |
7459 | ||
0101ce28 JJ |
7460 | struct lang_and_radix |
7461 | { | |
7462 | enum language lang; | |
7463 | int radix; | |
7464 | }; | |
7465 | ||
4efc6507 DE |
7466 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7467 | ||
7468 | struct breakpoint * | |
7469 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7470 | { | |
7471 | struct breakpoint *b; | |
7472 | ||
06edf0c0 PA |
7473 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7474 | &internal_breakpoint_ops); | |
4efc6507 DE |
7475 | update_global_location_list_nothrow (1); |
7476 | return b; | |
7477 | } | |
0101ce28 | 7478 | |
03673fc7 PP |
7479 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7480 | ||
7481 | void | |
7482 | remove_jit_event_breakpoints (void) | |
7483 | { | |
7484 | struct breakpoint *b, *b_tmp; | |
7485 | ||
7486 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7487 | if (b->type == bp_jit_event | |
7488 | && b->loc->pspace == current_program_space) | |
7489 | delete_breakpoint (b); | |
7490 | } | |
7491 | ||
cae688ec JJ |
7492 | void |
7493 | remove_solib_event_breakpoints (void) | |
7494 | { | |
35df4500 | 7495 | struct breakpoint *b, *b_tmp; |
cae688ec | 7496 | |
35df4500 | 7497 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7498 | if (b->type == bp_shlib_event |
7499 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7500 | delete_breakpoint (b); |
7501 | } | |
7502 | ||
7503 | struct breakpoint * | |
a6d9a66e | 7504 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7505 | { |
7506 | struct breakpoint *b; | |
7507 | ||
06edf0c0 PA |
7508 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7509 | &internal_breakpoint_ops); | |
b60e7edf | 7510 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7511 | return b; |
7512 | } | |
7513 | ||
7514 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7515 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7516 | ||
7517 | void | |
cb851954 | 7518 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7519 | { |
876fa593 | 7520 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7521 | |
876fa593 | 7522 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7523 | { |
2bdf28a0 | 7524 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7525 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7526 | |
4a64f543 MS |
7527 | /* We apply the check to all breakpoints, including disabled for |
7528 | those with loc->duplicate set. This is so that when breakpoint | |
7529 | becomes enabled, or the duplicate is removed, gdb will try to | |
7530 | insert all breakpoints. If we don't set shlib_disabled here, | |
7531 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7532 | if (((b->type == bp_breakpoint) |
508ccb1f | 7533 | || (b->type == bp_jit_event) |
1042e4c0 | 7534 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7535 | || (is_tracepoint (b))) |
6c95b8df | 7536 | && loc->pspace == current_program_space |
0d381245 | 7537 | && !loc->shlib_disabled |
6c95b8df | 7538 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7539 | ) |
0d381245 VP |
7540 | { |
7541 | loc->shlib_disabled = 1; | |
7542 | } | |
cae688ec JJ |
7543 | } |
7544 | } | |
7545 | ||
63644780 NB |
7546 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7547 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7548 | disabled ones can just stay disabled. */ | |
84acb35a | 7549 | |
75149521 | 7550 | static void |
84acb35a JJ |
7551 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7552 | { | |
876fa593 | 7553 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7554 | int disabled_shlib_breaks = 0; |
7555 | ||
c86cf029 VP |
7556 | /* SunOS a.out shared libraries are always mapped, so do not |
7557 | disable breakpoints; they will only be reported as unloaded | |
7558 | through clear_solib when GDB discards its shared library | |
7559 | list. See clear_solib for more information. */ | |
7560 | if (exec_bfd != NULL | |
7561 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7562 | return; | |
7563 | ||
876fa593 | 7564 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7565 | { |
2bdf28a0 | 7566 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7567 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7568 | |
1e4d1764 | 7569 | if (solib->pspace == loc->pspace |
e2dd7057 | 7570 | && !loc->shlib_disabled |
1e4d1764 YQ |
7571 | && (((b->type == bp_breakpoint |
7572 | || b->type == bp_jit_event | |
7573 | || b->type == bp_hardware_breakpoint) | |
7574 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7575 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7576 | || is_tracepoint (b)) | |
e2dd7057 | 7577 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7578 | { |
e2dd7057 PP |
7579 | loc->shlib_disabled = 1; |
7580 | /* At this point, we cannot rely on remove_breakpoint | |
7581 | succeeding so we must mark the breakpoint as not inserted | |
7582 | to prevent future errors occurring in remove_breakpoints. */ | |
7583 | loc->inserted = 0; | |
8d3788bd VP |
7584 | |
7585 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7586 | observer_notify_breakpoint_modified (b); | |
7587 | ||
e2dd7057 PP |
7588 | if (!disabled_shlib_breaks) |
7589 | { | |
7590 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7591 | warning (_("Temporarily disabling breakpoints " |
7592 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7593 | solib->so_name); |
84acb35a | 7594 | } |
e2dd7057 | 7595 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7596 | } |
7597 | } | |
84acb35a JJ |
7598 | } |
7599 | ||
63644780 NB |
7600 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7601 | notification of free_objfile. Only apply to enabled breakpoints, | |
7602 | disabled ones can just stay disabled. */ | |
7603 | ||
7604 | static void | |
7605 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7606 | { | |
7607 | struct breakpoint *b; | |
7608 | ||
7609 | if (objfile == NULL) | |
7610 | return; | |
7611 | ||
7612 | /* If the file is a shared library not loaded by the user then | |
7613 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7614 | was called. In that case there is no need to take action again. */ | |
7615 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7616 | return; | |
7617 | ||
7618 | ALL_BREAKPOINTS (b) | |
7619 | { | |
7620 | struct bp_location *loc; | |
7621 | int bp_modified = 0; | |
7622 | ||
7623 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7624 | continue; | |
7625 | ||
7626 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7627 | { | |
7628 | CORE_ADDR loc_addr = loc->address; | |
7629 | ||
7630 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7631 | && loc->loc_type != bp_loc_software_breakpoint) | |
7632 | continue; | |
7633 | ||
7634 | if (loc->shlib_disabled != 0) | |
7635 | continue; | |
7636 | ||
7637 | if (objfile->pspace != loc->pspace) | |
7638 | continue; | |
7639 | ||
7640 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7641 | && loc->loc_type != bp_loc_software_breakpoint) | |
7642 | continue; | |
7643 | ||
7644 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7645 | { | |
7646 | loc->shlib_disabled = 1; | |
7647 | loc->inserted = 0; | |
7648 | ||
7649 | mark_breakpoint_location_modified (loc); | |
7650 | ||
7651 | bp_modified = 1; | |
7652 | } | |
7653 | } | |
7654 | ||
7655 | if (bp_modified) | |
7656 | observer_notify_breakpoint_modified (b); | |
7657 | } | |
7658 | } | |
7659 | ||
ce78b96d JB |
7660 | /* FORK & VFORK catchpoints. */ |
7661 | ||
e29a4733 PA |
7662 | /* An instance of this type is used to represent a fork or vfork |
7663 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7664 | class; users downcast to "struct breakpoint *" when needed. A | |
7665 | breakpoint is really of this type iff its ops pointer points to | |
7666 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7667 | ||
7668 | struct fork_catchpoint | |
7669 | { | |
7670 | /* The base class. */ | |
7671 | struct breakpoint base; | |
7672 | ||
7673 | /* Process id of a child process whose forking triggered this | |
7674 | catchpoint. This field is only valid immediately after this | |
7675 | catchpoint has triggered. */ | |
7676 | ptid_t forked_inferior_pid; | |
7677 | }; | |
7678 | ||
4a64f543 MS |
7679 | /* Implement the "insert" breakpoint_ops method for fork |
7680 | catchpoints. */ | |
ce78b96d | 7681 | |
77b06cd7 TJB |
7682 | static int |
7683 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7684 | { |
dfd4cc63 | 7685 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7686 | } |
7687 | ||
4a64f543 MS |
7688 | /* Implement the "remove" breakpoint_ops method for fork |
7689 | catchpoints. */ | |
ce78b96d JB |
7690 | |
7691 | static int | |
77b06cd7 | 7692 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7693 | { |
dfd4cc63 | 7694 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7695 | } |
7696 | ||
7697 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7698 | catchpoints. */ | |
7699 | ||
7700 | static int | |
f1310107 | 7701 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7702 | struct address_space *aspace, CORE_ADDR bp_addr, |
7703 | const struct target_waitstatus *ws) | |
ce78b96d | 7704 | { |
e29a4733 PA |
7705 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7706 | ||
f90263c1 TT |
7707 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7708 | return 0; | |
7709 | ||
7710 | c->forked_inferior_pid = ws->value.related_pid; | |
7711 | return 1; | |
ce78b96d JB |
7712 | } |
7713 | ||
4a64f543 MS |
7714 | /* Implement the "print_it" breakpoint_ops method for fork |
7715 | catchpoints. */ | |
ce78b96d JB |
7716 | |
7717 | static enum print_stop_action | |
348d480f | 7718 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7719 | { |
36dfb11c | 7720 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7721 | struct breakpoint *b = bs->breakpoint_at; |
7722 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7723 | |
ce78b96d | 7724 | annotate_catchpoint (b->number); |
36dfb11c TT |
7725 | if (b->disposition == disp_del) |
7726 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7727 | else | |
7728 | ui_out_text (uiout, "\nCatchpoint "); | |
7729 | if (ui_out_is_mi_like_p (uiout)) | |
7730 | { | |
7731 | ui_out_field_string (uiout, "reason", | |
7732 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7733 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7734 | } | |
7735 | ui_out_field_int (uiout, "bkptno", b->number); | |
7736 | ui_out_text (uiout, " (forked process "); | |
7737 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7738 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7739 | return PRINT_SRC_AND_LOC; |
7740 | } | |
7741 | ||
4a64f543 MS |
7742 | /* Implement the "print_one" breakpoint_ops method for fork |
7743 | catchpoints. */ | |
ce78b96d JB |
7744 | |
7745 | static void | |
a6d9a66e | 7746 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7747 | { |
e29a4733 | 7748 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7749 | struct value_print_options opts; |
79a45e25 | 7750 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7751 | |
7752 | get_user_print_options (&opts); | |
7753 | ||
4a64f543 MS |
7754 | /* Field 4, the address, is omitted (which makes the columns not |
7755 | line up too nicely with the headers, but the effect is relatively | |
7756 | readable). */ | |
79a45b7d | 7757 | if (opts.addressprint) |
ce78b96d JB |
7758 | ui_out_field_skip (uiout, "addr"); |
7759 | annotate_field (5); | |
7760 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7761 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7762 | { |
7763 | ui_out_text (uiout, ", process "); | |
7764 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7765 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7766 | ui_out_spaces (uiout, 1); |
7767 | } | |
8ac3646f TT |
7768 | |
7769 | if (ui_out_is_mi_like_p (uiout)) | |
7770 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7771 | } |
7772 | ||
7773 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7774 | catchpoints. */ | |
7775 | ||
7776 | static void | |
7777 | print_mention_catch_fork (struct breakpoint *b) | |
7778 | { | |
7779 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7780 | } | |
7781 | ||
6149aea9 PA |
7782 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7783 | catchpoints. */ | |
7784 | ||
7785 | static void | |
7786 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7787 | { | |
7788 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7789 | print_recreate_thread (b, fp); |
6149aea9 PA |
7790 | } |
7791 | ||
ce78b96d JB |
7792 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7793 | ||
2060206e | 7794 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7795 | |
4a64f543 MS |
7796 | /* Implement the "insert" breakpoint_ops method for vfork |
7797 | catchpoints. */ | |
ce78b96d | 7798 | |
77b06cd7 TJB |
7799 | static int |
7800 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7801 | { |
dfd4cc63 | 7802 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7803 | } |
7804 | ||
4a64f543 MS |
7805 | /* Implement the "remove" breakpoint_ops method for vfork |
7806 | catchpoints. */ | |
ce78b96d JB |
7807 | |
7808 | static int | |
77b06cd7 | 7809 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7810 | { |
dfd4cc63 | 7811 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7812 | } |
7813 | ||
7814 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7815 | catchpoints. */ | |
7816 | ||
7817 | static int | |
f1310107 | 7818 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7819 | struct address_space *aspace, CORE_ADDR bp_addr, |
7820 | const struct target_waitstatus *ws) | |
ce78b96d | 7821 | { |
e29a4733 PA |
7822 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7823 | ||
f90263c1 TT |
7824 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7825 | return 0; | |
7826 | ||
7827 | c->forked_inferior_pid = ws->value.related_pid; | |
7828 | return 1; | |
ce78b96d JB |
7829 | } |
7830 | ||
4a64f543 MS |
7831 | /* Implement the "print_it" breakpoint_ops method for vfork |
7832 | catchpoints. */ | |
ce78b96d JB |
7833 | |
7834 | static enum print_stop_action | |
348d480f | 7835 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7836 | { |
36dfb11c | 7837 | struct ui_out *uiout = current_uiout; |
348d480f | 7838 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7839 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7840 | ||
ce78b96d | 7841 | annotate_catchpoint (b->number); |
36dfb11c TT |
7842 | if (b->disposition == disp_del) |
7843 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7844 | else | |
7845 | ui_out_text (uiout, "\nCatchpoint "); | |
7846 | if (ui_out_is_mi_like_p (uiout)) | |
7847 | { | |
7848 | ui_out_field_string (uiout, "reason", | |
7849 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7850 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7851 | } | |
7852 | ui_out_field_int (uiout, "bkptno", b->number); | |
7853 | ui_out_text (uiout, " (vforked process "); | |
7854 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7855 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7856 | return PRINT_SRC_AND_LOC; |
7857 | } | |
7858 | ||
4a64f543 MS |
7859 | /* Implement the "print_one" breakpoint_ops method for vfork |
7860 | catchpoints. */ | |
ce78b96d JB |
7861 | |
7862 | static void | |
a6d9a66e | 7863 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7864 | { |
e29a4733 | 7865 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7866 | struct value_print_options opts; |
79a45e25 | 7867 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7868 | |
7869 | get_user_print_options (&opts); | |
4a64f543 MS |
7870 | /* Field 4, the address, is omitted (which makes the columns not |
7871 | line up too nicely with the headers, but the effect is relatively | |
7872 | readable). */ | |
79a45b7d | 7873 | if (opts.addressprint) |
ce78b96d JB |
7874 | ui_out_field_skip (uiout, "addr"); |
7875 | annotate_field (5); | |
7876 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7877 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7878 | { |
7879 | ui_out_text (uiout, ", process "); | |
7880 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7881 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7882 | ui_out_spaces (uiout, 1); |
7883 | } | |
8ac3646f TT |
7884 | |
7885 | if (ui_out_is_mi_like_p (uiout)) | |
7886 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7887 | } |
7888 | ||
7889 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7890 | catchpoints. */ | |
7891 | ||
7892 | static void | |
7893 | print_mention_catch_vfork (struct breakpoint *b) | |
7894 | { | |
7895 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7896 | } | |
7897 | ||
6149aea9 PA |
7898 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7899 | catchpoints. */ | |
7900 | ||
7901 | static void | |
7902 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7903 | { | |
7904 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7905 | print_recreate_thread (b, fp); |
6149aea9 PA |
7906 | } |
7907 | ||
ce78b96d JB |
7908 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7909 | ||
2060206e | 7910 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7911 | |
edcc5120 TT |
7912 | /* An instance of this type is used to represent an solib catchpoint. |
7913 | It includes a "struct breakpoint" as a kind of base class; users | |
7914 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7915 | really of this type iff its ops pointer points to | |
7916 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7917 | ||
7918 | struct solib_catchpoint | |
7919 | { | |
7920 | /* The base class. */ | |
7921 | struct breakpoint base; | |
7922 | ||
7923 | /* True for "catch load", false for "catch unload". */ | |
7924 | unsigned char is_load; | |
7925 | ||
7926 | /* Regular expression to match, if any. COMPILED is only valid when | |
7927 | REGEX is non-NULL. */ | |
7928 | char *regex; | |
7929 | regex_t compiled; | |
7930 | }; | |
7931 | ||
7932 | static void | |
7933 | dtor_catch_solib (struct breakpoint *b) | |
7934 | { | |
7935 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7936 | ||
7937 | if (self->regex) | |
7938 | regfree (&self->compiled); | |
7939 | xfree (self->regex); | |
7940 | ||
7941 | base_breakpoint_ops.dtor (b); | |
7942 | } | |
7943 | ||
7944 | static int | |
7945 | insert_catch_solib (struct bp_location *ignore) | |
7946 | { | |
7947 | return 0; | |
7948 | } | |
7949 | ||
7950 | static int | |
7951 | remove_catch_solib (struct bp_location *ignore) | |
7952 | { | |
7953 | return 0; | |
7954 | } | |
7955 | ||
7956 | static int | |
7957 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7958 | struct address_space *aspace, | |
7959 | CORE_ADDR bp_addr, | |
7960 | const struct target_waitstatus *ws) | |
7961 | { | |
7962 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7963 | struct breakpoint *other; | |
7964 | ||
7965 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7966 | return 1; | |
7967 | ||
7968 | ALL_BREAKPOINTS (other) | |
7969 | { | |
7970 | struct bp_location *other_bl; | |
7971 | ||
7972 | if (other == bl->owner) | |
7973 | continue; | |
7974 | ||
7975 | if (other->type != bp_shlib_event) | |
7976 | continue; | |
7977 | ||
7978 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7979 | continue; | |
7980 | ||
7981 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7982 | { | |
7983 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7984 | return 1; | |
7985 | } | |
7986 | } | |
7987 | ||
7988 | return 0; | |
7989 | } | |
7990 | ||
7991 | static void | |
7992 | check_status_catch_solib (struct bpstats *bs) | |
7993 | { | |
7994 | struct solib_catchpoint *self | |
7995 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7996 | int ix; | |
7997 | ||
7998 | if (self->is_load) | |
7999 | { | |
8000 | struct so_list *iter; | |
8001 | ||
8002 | for (ix = 0; | |
8003 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8004 | ix, iter); | |
8005 | ++ix) | |
8006 | { | |
8007 | if (!self->regex | |
8008 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8009 | return; | |
8010 | } | |
8011 | } | |
8012 | else | |
8013 | { | |
8014 | char *iter; | |
8015 | ||
8016 | for (ix = 0; | |
8017 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8018 | ix, iter); | |
8019 | ++ix) | |
8020 | { | |
8021 | if (!self->regex | |
8022 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8023 | return; | |
8024 | } | |
8025 | } | |
8026 | ||
8027 | bs->stop = 0; | |
8028 | bs->print_it = print_it_noop; | |
8029 | } | |
8030 | ||
8031 | static enum print_stop_action | |
8032 | print_it_catch_solib (bpstat bs) | |
8033 | { | |
8034 | struct breakpoint *b = bs->breakpoint_at; | |
8035 | struct ui_out *uiout = current_uiout; | |
8036 | ||
8037 | annotate_catchpoint (b->number); | |
8038 | if (b->disposition == disp_del) | |
8039 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8040 | else | |
8041 | ui_out_text (uiout, "\nCatchpoint "); | |
8042 | ui_out_field_int (uiout, "bkptno", b->number); | |
8043 | ui_out_text (uiout, "\n"); | |
8044 | if (ui_out_is_mi_like_p (uiout)) | |
8045 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8046 | print_solib_event (1); | |
8047 | return PRINT_SRC_AND_LOC; | |
8048 | } | |
8049 | ||
8050 | static void | |
8051 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8052 | { | |
8053 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8054 | struct value_print_options opts; | |
8055 | struct ui_out *uiout = current_uiout; | |
8056 | char *msg; | |
8057 | ||
8058 | get_user_print_options (&opts); | |
8059 | /* Field 4, the address, is omitted (which makes the columns not | |
8060 | line up too nicely with the headers, but the effect is relatively | |
8061 | readable). */ | |
8062 | if (opts.addressprint) | |
8063 | { | |
8064 | annotate_field (4); | |
8065 | ui_out_field_skip (uiout, "addr"); | |
8066 | } | |
8067 | ||
8068 | annotate_field (5); | |
8069 | if (self->is_load) | |
8070 | { | |
8071 | if (self->regex) | |
8072 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8073 | else | |
8074 | msg = xstrdup (_("load of library")); | |
8075 | } | |
8076 | else | |
8077 | { | |
8078 | if (self->regex) | |
8079 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8080 | else | |
8081 | msg = xstrdup (_("unload of library")); | |
8082 | } | |
8083 | ui_out_field_string (uiout, "what", msg); | |
8084 | xfree (msg); | |
8ac3646f TT |
8085 | |
8086 | if (ui_out_is_mi_like_p (uiout)) | |
8087 | ui_out_field_string (uiout, "catch-type", | |
8088 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8089 | } |
8090 | ||
8091 | static void | |
8092 | print_mention_catch_solib (struct breakpoint *b) | |
8093 | { | |
8094 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8095 | ||
8096 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8097 | self->is_load ? "load" : "unload"); | |
8098 | } | |
8099 | ||
8100 | static void | |
8101 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8102 | { | |
8103 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8104 | ||
8105 | fprintf_unfiltered (fp, "%s %s", | |
8106 | b->disposition == disp_del ? "tcatch" : "catch", | |
8107 | self->is_load ? "load" : "unload"); | |
8108 | if (self->regex) | |
8109 | fprintf_unfiltered (fp, " %s", self->regex); | |
8110 | fprintf_unfiltered (fp, "\n"); | |
8111 | } | |
8112 | ||
8113 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8114 | ||
91985142 MG |
8115 | /* Shared helper function (MI and CLI) for creating and installing |
8116 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8117 | the events to be caught are load events, otherwise they are | |
8118 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8119 | temporary one. If ENABLED is non-zero the catchpoint is | |
8120 | created in an enabled state. */ | |
edcc5120 | 8121 | |
91985142 MG |
8122 | void |
8123 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8124 | { |
8125 | struct solib_catchpoint *c; | |
8126 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8127 | struct cleanup *cleanup; |
8128 | ||
edcc5120 TT |
8129 | if (!arg) |
8130 | arg = ""; | |
8131 | arg = skip_spaces (arg); | |
8132 | ||
8133 | c = XCNEW (struct solib_catchpoint); | |
8134 | cleanup = make_cleanup (xfree, c); | |
8135 | ||
8136 | if (*arg != '\0') | |
8137 | { | |
8138 | int errcode; | |
8139 | ||
8140 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8141 | if (errcode != 0) | |
8142 | { | |
8143 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8144 | ||
8145 | make_cleanup (xfree, err); | |
8146 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8147 | } | |
8148 | c->regex = xstrdup (arg); | |
8149 | } | |
8150 | ||
8151 | c->is_load = is_load; | |
91985142 | 8152 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8153 | &catch_solib_breakpoint_ops); |
8154 | ||
91985142 MG |
8155 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8156 | ||
edcc5120 TT |
8157 | discard_cleanups (cleanup); |
8158 | install_breakpoint (0, &c->base, 1); | |
8159 | } | |
8160 | ||
91985142 MG |
8161 | /* A helper function that does all the work for "catch load" and |
8162 | "catch unload". */ | |
8163 | ||
8164 | static void | |
8165 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8166 | struct cmd_list_element *command) | |
8167 | { | |
8168 | int tempflag; | |
8169 | const int enabled = 1; | |
8170 | ||
8171 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8172 | ||
8173 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8174 | } | |
8175 | ||
edcc5120 TT |
8176 | static void |
8177 | catch_load_command_1 (char *arg, int from_tty, | |
8178 | struct cmd_list_element *command) | |
8179 | { | |
8180 | catch_load_or_unload (arg, from_tty, 1, command); | |
8181 | } | |
8182 | ||
8183 | static void | |
8184 | catch_unload_command_1 (char *arg, int from_tty, | |
8185 | struct cmd_list_element *command) | |
8186 | { | |
8187 | catch_load_or_unload (arg, from_tty, 0, command); | |
8188 | } | |
8189 | ||
be5c67c1 PA |
8190 | /* An instance of this type is used to represent a syscall catchpoint. |
8191 | It includes a "struct breakpoint" as a kind of base class; users | |
8192 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8193 | really of this type iff its ops pointer points to | |
8194 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8195 | ||
8196 | struct syscall_catchpoint | |
8197 | { | |
8198 | /* The base class. */ | |
8199 | struct breakpoint base; | |
8200 | ||
8201 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8202 | syscall has been specified for filtering, its value is NULL. | |
8203 | Otherwise, it holds a list of all syscalls to be caught. The | |
8204 | list elements are allocated with xmalloc. */ | |
8205 | VEC(int) *syscalls_to_be_caught; | |
8206 | }; | |
8207 | ||
8208 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8209 | catchpoints. */ | |
8210 | ||
8211 | static void | |
8212 | dtor_catch_syscall (struct breakpoint *b) | |
8213 | { | |
8214 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8215 | ||
8216 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8217 | |
2060206e | 8218 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8219 | } |
8220 | ||
fa3064dd YQ |
8221 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8222 | ||
8223 | struct catch_syscall_inferior_data | |
8224 | { | |
8225 | /* We keep a count of the number of times the user has requested a | |
8226 | particular syscall to be tracked, and pass this information to the | |
8227 | target. This lets capable targets implement filtering directly. */ | |
8228 | ||
8229 | /* Number of times that "any" syscall is requested. */ | |
8230 | int any_syscall_count; | |
8231 | ||
8232 | /* Count of each system call. */ | |
8233 | VEC(int) *syscalls_counts; | |
8234 | ||
8235 | /* This counts all syscall catch requests, so we can readily determine | |
8236 | if any catching is necessary. */ | |
8237 | int total_syscalls_count; | |
8238 | }; | |
8239 | ||
8240 | static struct catch_syscall_inferior_data* | |
8241 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8242 | { | |
8243 | struct catch_syscall_inferior_data *inf_data; | |
8244 | ||
8245 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8246 | if (inf_data == NULL) | |
8247 | { | |
41bf6aca | 8248 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8249 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8250 | } | |
8251 | ||
8252 | return inf_data; | |
8253 | } | |
8254 | ||
8255 | static void | |
8256 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8257 | { | |
8258 | xfree (arg); | |
8259 | } | |
8260 | ||
8261 | ||
a96d9b2e SDJ |
8262 | /* Implement the "insert" breakpoint_ops method for syscall |
8263 | catchpoints. */ | |
8264 | ||
77b06cd7 TJB |
8265 | static int |
8266 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8267 | { |
be5c67c1 | 8268 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8269 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8270 | struct catch_syscall_inferior_data *inf_data |
8271 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8272 | |
fa3064dd | 8273 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8274 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8275 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8276 | else |
8277 | { | |
8278 | int i, iter; | |
cc59ec59 | 8279 | |
a96d9b2e | 8280 | for (i = 0; |
be5c67c1 | 8281 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8282 | i++) |
8283 | { | |
8284 | int elem; | |
cc59ec59 | 8285 | |
fa3064dd | 8286 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8287 | { |
fa3064dd | 8288 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8289 | uintptr_t vec_addr_offset |
8290 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8291 | uintptr_t vec_addr; |
fa3064dd YQ |
8292 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8293 | vec_addr = ((uintptr_t) VEC_address (int, | |
8294 | inf_data->syscalls_counts) | |
8295 | + vec_addr_offset); | |
a96d9b2e SDJ |
8296 | memset ((void *) vec_addr, 0, |
8297 | (iter + 1 - old_size) * sizeof (int)); | |
8298 | } | |
fa3064dd YQ |
8299 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8300 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8301 | } |
8302 | } | |
8303 | ||
dfd4cc63 | 8304 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8305 | inf_data->total_syscalls_count != 0, |
8306 | inf_data->any_syscall_count, | |
8307 | VEC_length (int, | |
8308 | inf_data->syscalls_counts), | |
8309 | VEC_address (int, | |
8310 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8311 | } |
8312 | ||
8313 | /* Implement the "remove" breakpoint_ops method for syscall | |
8314 | catchpoints. */ | |
8315 | ||
8316 | static int | |
77b06cd7 | 8317 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8318 | { |
be5c67c1 | 8319 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8320 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8321 | struct catch_syscall_inferior_data *inf_data |
8322 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8323 | |
fa3064dd | 8324 | --inf_data->total_syscalls_count; |
be5c67c1 | 8325 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8326 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8327 | else |
8328 | { | |
8329 | int i, iter; | |
cc59ec59 | 8330 | |
a96d9b2e | 8331 | for (i = 0; |
be5c67c1 | 8332 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8333 | i++) |
8334 | { | |
8335 | int elem; | |
fa3064dd | 8336 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8337 | /* Shouldn't happen. */ |
8338 | continue; | |
fa3064dd YQ |
8339 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8340 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8341 | } |
8342 | } | |
8343 | ||
dfd4cc63 | 8344 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8345 | inf_data->total_syscalls_count != 0, |
8346 | inf_data->any_syscall_count, | |
8347 | VEC_length (int, | |
8348 | inf_data->syscalls_counts), | |
3e43a32a | 8349 | VEC_address (int, |
fa3064dd | 8350 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8351 | } |
8352 | ||
8353 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8354 | catchpoints. */ | |
8355 | ||
8356 | static int | |
f1310107 | 8357 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8358 | struct address_space *aspace, CORE_ADDR bp_addr, |
8359 | const struct target_waitstatus *ws) | |
a96d9b2e | 8360 | { |
4a64f543 MS |
8361 | /* We must check if we are catching specific syscalls in this |
8362 | breakpoint. If we are, then we must guarantee that the called | |
8363 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8364 | int syscall_number = 0; |
be5c67c1 PA |
8365 | const struct syscall_catchpoint *c |
8366 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8367 | |
f90263c1 TT |
8368 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8369 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8370 | return 0; |
8371 | ||
f90263c1 TT |
8372 | syscall_number = ws->value.syscall_number; |
8373 | ||
a96d9b2e | 8374 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8375 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8376 | { |
8377 | int i, iter; | |
cc59ec59 | 8378 | |
a96d9b2e | 8379 | for (i = 0; |
be5c67c1 | 8380 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8381 | i++) |
8382 | if (syscall_number == iter) | |
4924df79 GKB |
8383 | return 1; |
8384 | ||
8385 | return 0; | |
a96d9b2e SDJ |
8386 | } |
8387 | ||
8388 | return 1; | |
8389 | } | |
8390 | ||
8391 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8392 | catchpoints. */ | |
8393 | ||
8394 | static enum print_stop_action | |
348d480f | 8395 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8396 | { |
36dfb11c | 8397 | struct ui_out *uiout = current_uiout; |
348d480f | 8398 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8399 | /* These are needed because we want to know in which state a |
8400 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8401 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8402 | must print "called syscall" or "returned from syscall". */ | |
8403 | ptid_t ptid; | |
8404 | struct target_waitstatus last; | |
8405 | struct syscall s; | |
a96d9b2e SDJ |
8406 | |
8407 | get_last_target_status (&ptid, &last); | |
8408 | ||
8409 | get_syscall_by_number (last.value.syscall_number, &s); | |
8410 | ||
8411 | annotate_catchpoint (b->number); | |
8412 | ||
36dfb11c TT |
8413 | if (b->disposition == disp_del) |
8414 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8415 | else |
36dfb11c TT |
8416 | ui_out_text (uiout, "\nCatchpoint "); |
8417 | if (ui_out_is_mi_like_p (uiout)) | |
8418 | { | |
8419 | ui_out_field_string (uiout, "reason", | |
8420 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8421 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8422 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8423 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8424 | } | |
8425 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8426 | |
8427 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8428 | ui_out_text (uiout, " (call to syscall "); |
8429 | else | |
8430 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8431 | |
36dfb11c TT |
8432 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8433 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8434 | if (s.name != NULL) | |
8435 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8436 | ||
8437 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8438 | |
8439 | return PRINT_SRC_AND_LOC; | |
8440 | } | |
8441 | ||
8442 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8443 | catchpoints. */ | |
8444 | ||
8445 | static void | |
8446 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8447 | struct bp_location **last_loc) |
a96d9b2e | 8448 | { |
be5c67c1 | 8449 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8450 | struct value_print_options opts; |
79a45e25 | 8451 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8452 | |
8453 | get_user_print_options (&opts); | |
4a64f543 MS |
8454 | /* Field 4, the address, is omitted (which makes the columns not |
8455 | line up too nicely with the headers, but the effect is relatively | |
8456 | readable). */ | |
a96d9b2e SDJ |
8457 | if (opts.addressprint) |
8458 | ui_out_field_skip (uiout, "addr"); | |
8459 | annotate_field (5); | |
8460 | ||
be5c67c1 PA |
8461 | if (c->syscalls_to_be_caught |
8462 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8463 | ui_out_text (uiout, "syscalls \""); |
8464 | else | |
8465 | ui_out_text (uiout, "syscall \""); | |
8466 | ||
be5c67c1 | 8467 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8468 | { |
8469 | int i, iter; | |
8470 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8471 | |
a96d9b2e | 8472 | for (i = 0; |
be5c67c1 | 8473 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8474 | i++) |
8475 | { | |
8476 | char *x = text; | |
8477 | struct syscall s; | |
8478 | get_syscall_by_number (iter, &s); | |
8479 | ||
8480 | if (s.name != NULL) | |
8481 | text = xstrprintf ("%s%s, ", text, s.name); | |
8482 | else | |
8483 | text = xstrprintf ("%s%d, ", text, iter); | |
8484 | ||
8485 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8486 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8487 | on every call. */ |
8488 | xfree (x); | |
8489 | } | |
8490 | /* Remove the last comma. */ | |
8491 | text[strlen (text) - 2] = '\0'; | |
8492 | ui_out_field_string (uiout, "what", text); | |
8493 | } | |
8494 | else | |
8495 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8496 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8497 | |
8498 | if (ui_out_is_mi_like_p (uiout)) | |
8499 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8500 | } |
8501 | ||
8502 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8503 | catchpoints. */ | |
8504 | ||
8505 | static void | |
8506 | print_mention_catch_syscall (struct breakpoint *b) | |
8507 | { | |
be5c67c1 PA |
8508 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8509 | ||
8510 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8511 | { |
8512 | int i, iter; | |
8513 | ||
be5c67c1 | 8514 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8515 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8516 | else | |
8517 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8518 | ||
8519 | for (i = 0; | |
be5c67c1 | 8520 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8521 | i++) |
8522 | { | |
8523 | struct syscall s; | |
8524 | get_syscall_by_number (iter, &s); | |
8525 | ||
8526 | if (s.name) | |
8527 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8528 | else | |
8529 | printf_filtered (" %d", s.number); | |
8530 | } | |
8531 | printf_filtered (")"); | |
8532 | } | |
8533 | else | |
8534 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8535 | b->number); | |
8536 | } | |
8537 | ||
6149aea9 PA |
8538 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8539 | catchpoints. */ | |
8540 | ||
8541 | static void | |
8542 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8543 | { | |
be5c67c1 PA |
8544 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8545 | ||
6149aea9 PA |
8546 | fprintf_unfiltered (fp, "catch syscall"); |
8547 | ||
be5c67c1 | 8548 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8549 | { |
8550 | int i, iter; | |
8551 | ||
8552 | for (i = 0; | |
be5c67c1 | 8553 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8554 | i++) |
8555 | { | |
8556 | struct syscall s; | |
8557 | ||
8558 | get_syscall_by_number (iter, &s); | |
8559 | if (s.name) | |
8560 | fprintf_unfiltered (fp, " %s", s.name); | |
8561 | else | |
8562 | fprintf_unfiltered (fp, " %d", s.number); | |
8563 | } | |
8564 | } | |
d9b3f62e | 8565 | print_recreate_thread (b, fp); |
6149aea9 PA |
8566 | } |
8567 | ||
a96d9b2e SDJ |
8568 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8569 | ||
2060206e | 8570 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8571 | |
8572 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8573 | ||
8574 | static int | |
8575 | syscall_catchpoint_p (struct breakpoint *b) | |
8576 | { | |
8577 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8578 | } | |
8579 | ||
346774a9 PA |
8580 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8581 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8582 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8583 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8584 | |
ab04a2af | 8585 | void |
346774a9 PA |
8586 | init_catchpoint (struct breakpoint *b, |
8587 | struct gdbarch *gdbarch, int tempflag, | |
8588 | char *cond_string, | |
c0a91b2b | 8589 | const struct breakpoint_ops *ops) |
c906108c | 8590 | { |
c5aa993b | 8591 | struct symtab_and_line sal; |
346774a9 | 8592 | |
fe39c653 | 8593 | init_sal (&sal); |
6c95b8df | 8594 | sal.pspace = current_program_space; |
c5aa993b | 8595 | |
28010a5d | 8596 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8597 | |
1b36a34b | 8598 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8599 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8600 | } |
8601 | ||
28010a5d | 8602 | void |
3ea46bff | 8603 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8604 | { |
8605 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8606 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8607 | if (is_tracepoint (b)) |
8608 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8609 | if (!internal) |
8610 | mention (b); | |
c56053d2 | 8611 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8612 | |
8613 | if (update_gll) | |
8614 | update_global_location_list (1); | |
c56053d2 PA |
8615 | } |
8616 | ||
9b70b993 | 8617 | static void |
a6d9a66e UW |
8618 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8619 | int tempflag, char *cond_string, | |
c0a91b2b | 8620 | const struct breakpoint_ops *ops) |
c906108c | 8621 | { |
e29a4733 | 8622 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8623 | |
e29a4733 PA |
8624 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8625 | ||
8626 | c->forked_inferior_pid = null_ptid; | |
8627 | ||
3ea46bff | 8628 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8629 | } |
8630 | ||
fe798b75 JB |
8631 | /* Exec catchpoints. */ |
8632 | ||
b4d90040 PA |
8633 | /* An instance of this type is used to represent an exec catchpoint. |
8634 | It includes a "struct breakpoint" as a kind of base class; users | |
8635 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8636 | really of this type iff its ops pointer points to | |
8637 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8638 | ||
8639 | struct exec_catchpoint | |
8640 | { | |
8641 | /* The base class. */ | |
8642 | struct breakpoint base; | |
8643 | ||
8644 | /* Filename of a program whose exec triggered this catchpoint. | |
8645 | This field is only valid immediately after this catchpoint has | |
8646 | triggered. */ | |
8647 | char *exec_pathname; | |
8648 | }; | |
8649 | ||
8650 | /* Implement the "dtor" breakpoint_ops method for exec | |
8651 | catchpoints. */ | |
8652 | ||
8653 | static void | |
8654 | dtor_catch_exec (struct breakpoint *b) | |
8655 | { | |
8656 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8657 | ||
8658 | xfree (c->exec_pathname); | |
348d480f | 8659 | |
2060206e | 8660 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8661 | } |
8662 | ||
77b06cd7 TJB |
8663 | static int |
8664 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8665 | { |
dfd4cc63 | 8666 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8667 | } |
c906108c | 8668 | |
fe798b75 | 8669 | static int |
77b06cd7 | 8670 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8671 | { |
dfd4cc63 | 8672 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8673 | } |
c906108c | 8674 | |
fe798b75 | 8675 | static int |
f1310107 | 8676 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8677 | struct address_space *aspace, CORE_ADDR bp_addr, |
8678 | const struct target_waitstatus *ws) | |
fe798b75 | 8679 | { |
b4d90040 PA |
8680 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8681 | ||
f90263c1 TT |
8682 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8683 | return 0; | |
8684 | ||
8685 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8686 | return 1; | |
fe798b75 | 8687 | } |
c906108c | 8688 | |
fe798b75 | 8689 | static enum print_stop_action |
348d480f | 8690 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8691 | { |
36dfb11c | 8692 | struct ui_out *uiout = current_uiout; |
348d480f | 8693 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8694 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8695 | ||
fe798b75 | 8696 | annotate_catchpoint (b->number); |
36dfb11c TT |
8697 | if (b->disposition == disp_del) |
8698 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8699 | else | |
8700 | ui_out_text (uiout, "\nCatchpoint "); | |
8701 | if (ui_out_is_mi_like_p (uiout)) | |
8702 | { | |
8703 | ui_out_field_string (uiout, "reason", | |
8704 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8705 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8706 | } | |
8707 | ui_out_field_int (uiout, "bkptno", b->number); | |
8708 | ui_out_text (uiout, " (exec'd "); | |
8709 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8710 | ui_out_text (uiout, "), "); | |
8711 | ||
fe798b75 | 8712 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8713 | } |
8714 | ||
fe798b75 | 8715 | static void |
a6d9a66e | 8716 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8717 | { |
b4d90040 | 8718 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8719 | struct value_print_options opts; |
79a45e25 | 8720 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8721 | |
8722 | get_user_print_options (&opts); | |
8723 | ||
8724 | /* Field 4, the address, is omitted (which makes the columns | |
8725 | not line up too nicely with the headers, but the effect | |
8726 | is relatively readable). */ | |
8727 | if (opts.addressprint) | |
8728 | ui_out_field_skip (uiout, "addr"); | |
8729 | annotate_field (5); | |
8730 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8731 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8732 | { |
8733 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8734 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8735 | ui_out_text (uiout, "\" "); |
8736 | } | |
8ac3646f TT |
8737 | |
8738 | if (ui_out_is_mi_like_p (uiout)) | |
8739 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8740 | } |
8741 | ||
8742 | static void | |
8743 | print_mention_catch_exec (struct breakpoint *b) | |
8744 | { | |
8745 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8746 | } | |
8747 | ||
6149aea9 PA |
8748 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8749 | catchpoints. */ | |
8750 | ||
8751 | static void | |
8752 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8753 | { | |
8754 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8755 | print_recreate_thread (b, fp); |
6149aea9 PA |
8756 | } |
8757 | ||
2060206e | 8758 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8759 | |
a96d9b2e SDJ |
8760 | static void |
8761 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8762 | const struct breakpoint_ops *ops) |
a96d9b2e | 8763 | { |
be5c67c1 | 8764 | struct syscall_catchpoint *c; |
a96d9b2e | 8765 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8766 | |
be5c67c1 PA |
8767 | c = XNEW (struct syscall_catchpoint); |
8768 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8769 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8770 | |
3ea46bff | 8771 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8772 | } |
8773 | ||
c906108c | 8774 | static int |
fba45db2 | 8775 | hw_breakpoint_used_count (void) |
c906108c | 8776 | { |
c906108c | 8777 | int i = 0; |
f1310107 TJB |
8778 | struct breakpoint *b; |
8779 | struct bp_location *bl; | |
c906108c SS |
8780 | |
8781 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8782 | { |
d6b74ac4 | 8783 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8784 | for (bl = b->loc; bl; bl = bl->next) |
8785 | { | |
8786 | /* Special types of hardware breakpoints may use more than | |
8787 | one register. */ | |
348d480f | 8788 | i += b->ops->resources_needed (bl); |
f1310107 | 8789 | } |
c5aa993b | 8790 | } |
c906108c SS |
8791 | |
8792 | return i; | |
8793 | } | |
8794 | ||
a1398e0c PA |
8795 | /* Returns the resources B would use if it were a hardware |
8796 | watchpoint. */ | |
8797 | ||
c906108c | 8798 | static int |
a1398e0c | 8799 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8800 | { |
c906108c | 8801 | int i = 0; |
e09342b5 | 8802 | struct bp_location *bl; |
c906108c | 8803 | |
a1398e0c PA |
8804 | if (!breakpoint_enabled (b)) |
8805 | return 0; | |
8806 | ||
8807 | for (bl = b->loc; bl; bl = bl->next) | |
8808 | { | |
8809 | /* Special types of hardware watchpoints may use more than | |
8810 | one register. */ | |
8811 | i += b->ops->resources_needed (bl); | |
8812 | } | |
8813 | ||
8814 | return i; | |
8815 | } | |
8816 | ||
8817 | /* Returns the sum the used resources of all hardware watchpoints of | |
8818 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8819 | the sum of the used resources of all hardware watchpoints of other | |
8820 | types _not_ TYPE. */ | |
8821 | ||
8822 | static int | |
8823 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8824 | enum bptype type, int *other_type_used) | |
8825 | { | |
8826 | int i = 0; | |
8827 | struct breakpoint *b; | |
8828 | ||
c906108c SS |
8829 | *other_type_used = 0; |
8830 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8831 | { |
a1398e0c PA |
8832 | if (b == except) |
8833 | continue; | |
e09342b5 TJB |
8834 | if (!breakpoint_enabled (b)) |
8835 | continue; | |
8836 | ||
a1398e0c PA |
8837 | if (b->type == type) |
8838 | i += hw_watchpoint_use_count (b); | |
8839 | else if (is_hardware_watchpoint (b)) | |
8840 | *other_type_used = 1; | |
e09342b5 TJB |
8841 | } |
8842 | ||
c906108c SS |
8843 | return i; |
8844 | } | |
8845 | ||
c906108c | 8846 | void |
fba45db2 | 8847 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8848 | { |
c5aa993b | 8849 | struct breakpoint *b; |
c906108c SS |
8850 | |
8851 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8852 | { |
cc60f2e3 | 8853 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8854 | { |
b5de0fa7 | 8855 | b->enable_state = bp_call_disabled; |
b60e7edf | 8856 | update_global_location_list (0); |
c5aa993b JM |
8857 | } |
8858 | } | |
c906108c SS |
8859 | } |
8860 | ||
8861 | void | |
fba45db2 | 8862 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8863 | { |
c5aa993b | 8864 | struct breakpoint *b; |
c906108c SS |
8865 | |
8866 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8867 | { |
cc60f2e3 | 8868 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8869 | { |
b5de0fa7 | 8870 | b->enable_state = bp_enabled; |
b60e7edf | 8871 | update_global_location_list (1); |
c5aa993b JM |
8872 | } |
8873 | } | |
c906108c SS |
8874 | } |
8875 | ||
8bea4e01 UW |
8876 | void |
8877 | disable_breakpoints_before_startup (void) | |
8878 | { | |
6c95b8df | 8879 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8880 | update_global_location_list (0); |
8bea4e01 UW |
8881 | } |
8882 | ||
8883 | void | |
8884 | enable_breakpoints_after_startup (void) | |
8885 | { | |
6c95b8df | 8886 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8887 | breakpoint_re_set (); |
8bea4e01 UW |
8888 | } |
8889 | ||
c906108c SS |
8890 | |
8891 | /* Set a breakpoint that will evaporate an end of command | |
8892 | at address specified by SAL. | |
8893 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8894 | ||
8895 | struct breakpoint * | |
a6d9a66e UW |
8896 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8897 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8898 | { |
52f0bd74 | 8899 | struct breakpoint *b; |
edb3359d | 8900 | |
193facb3 JK |
8901 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8902 | tail-called one. */ | |
8903 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8904 | |
06edf0c0 | 8905 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8906 | b->enable_state = bp_enabled; |
8907 | b->disposition = disp_donttouch; | |
818dd999 | 8908 | b->frame_id = frame_id; |
c906108c | 8909 | |
4a64f543 MS |
8910 | /* If we're debugging a multi-threaded program, then we want |
8911 | momentary breakpoints to be active in only a single thread of | |
8912 | control. */ | |
39f77062 KB |
8913 | if (in_thread_list (inferior_ptid)) |
8914 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8915 | |
b60e7edf | 8916 | update_global_location_list_nothrow (1); |
74960c60 | 8917 | |
c906108c SS |
8918 | return b; |
8919 | } | |
611c83ae | 8920 | |
06edf0c0 PA |
8921 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8922 | The new breakpoint will have type TYPE, and use OPS as it | |
8923 | breakpoint_ops. */ | |
e58b0e63 | 8924 | |
06edf0c0 PA |
8925 | static struct breakpoint * |
8926 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8927 | enum bptype type, | |
c0a91b2b | 8928 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8929 | { |
8930 | struct breakpoint *copy; | |
8931 | ||
06edf0c0 | 8932 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8933 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8934 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8935 | |
a6d9a66e | 8936 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8937 | copy->loc->requested_address = orig->loc->requested_address; |
8938 | copy->loc->address = orig->loc->address; | |
8939 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8940 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8941 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8942 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8943 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8944 | copy->frame_id = orig->frame_id; |
8945 | copy->thread = orig->thread; | |
6c95b8df | 8946 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8947 | |
8948 | copy->enable_state = bp_enabled; | |
8949 | copy->disposition = disp_donttouch; | |
8950 | copy->number = internal_breakpoint_number--; | |
8951 | ||
8952 | update_global_location_list_nothrow (0); | |
8953 | return copy; | |
8954 | } | |
8955 | ||
06edf0c0 PA |
8956 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8957 | ORIG is NULL. */ | |
8958 | ||
8959 | struct breakpoint * | |
8960 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8961 | { | |
8962 | /* If there's nothing to clone, then return nothing. */ | |
8963 | if (orig == NULL) | |
8964 | return NULL; | |
8965 | ||
8966 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8967 | } | |
8968 | ||
611c83ae | 8969 | struct breakpoint * |
a6d9a66e UW |
8970 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8971 | enum bptype type) | |
611c83ae PA |
8972 | { |
8973 | struct symtab_and_line sal; | |
8974 | ||
8975 | sal = find_pc_line (pc, 0); | |
8976 | sal.pc = pc; | |
8977 | sal.section = find_pc_overlay (pc); | |
8978 | sal.explicit_pc = 1; | |
8979 | ||
a6d9a66e | 8980 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8981 | } |
c906108c | 8982 | \f |
c5aa993b | 8983 | |
c906108c SS |
8984 | /* Tell the user we have just set a breakpoint B. */ |
8985 | ||
8986 | static void | |
fba45db2 | 8987 | mention (struct breakpoint *b) |
c906108c | 8988 | { |
348d480f | 8989 | b->ops->print_mention (b); |
79a45e25 | 8990 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8991 | return; |
c906108c SS |
8992 | printf_filtered ("\n"); |
8993 | } | |
c906108c | 8994 | \f |
c5aa993b | 8995 | |
0d381245 | 8996 | static struct bp_location * |
39d61571 | 8997 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8998 | const struct symtab_and_line *sal) |
8999 | { | |
9000 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9001 | CORE_ADDR adjusted_address; |
9002 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9003 | ||
9004 | if (loc_gdbarch == NULL) | |
9005 | loc_gdbarch = b->gdbarch; | |
9006 | ||
9007 | /* Adjust the breakpoint's address prior to allocating a location. | |
9008 | Once we call allocate_bp_location(), that mostly uninitialized | |
9009 | location will be placed on the location chain. Adjustment of the | |
9010 | breakpoint may cause target_read_memory() to be called and we do | |
9011 | not want its scan of the location chain to find a breakpoint and | |
9012 | location that's only been partially initialized. */ | |
9013 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9014 | sal->pc, b->type); | |
0d381245 | 9015 | |
d30113d4 | 9016 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9017 | loc = allocate_bp_location (b); |
d30113d4 JK |
9018 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9019 | tmp = &((*tmp)->next)) | |
0d381245 | 9020 | ; |
d30113d4 | 9021 | loc->next = *tmp; |
0d381245 | 9022 | *tmp = loc; |
3742cc8b | 9023 | |
0d381245 | 9024 | loc->requested_address = sal->pc; |
3742cc8b | 9025 | loc->address = adjusted_address; |
6c95b8df | 9026 | loc->pspace = sal->pspace; |
729662a5 TT |
9027 | loc->probe.probe = sal->probe; |
9028 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9029 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9030 | loc->section = sal->section; |
3742cc8b | 9031 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9032 | loc->line_number = sal->line; |
2f202fde | 9033 | loc->symtab = sal->symtab; |
f8eba3c6 | 9034 | |
0e30163f JK |
9035 | set_breakpoint_location_function (loc, |
9036 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
9037 | return loc; |
9038 | } | |
514f746b AR |
9039 | \f |
9040 | ||
9041 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9042 | return 0 otherwise. */ | |
9043 | ||
9044 | static int | |
9045 | bp_loc_is_permanent (struct bp_location *loc) | |
9046 | { | |
9047 | int len; | |
9048 | CORE_ADDR addr; | |
1afeeb75 | 9049 | const gdb_byte *bpoint; |
514f746b | 9050 | gdb_byte *target_mem; |
939c61fa JK |
9051 | struct cleanup *cleanup; |
9052 | int retval = 0; | |
514f746b AR |
9053 | |
9054 | gdb_assert (loc != NULL); | |
9055 | ||
9056 | addr = loc->address; | |
1afeeb75 | 9057 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9058 | |
939c61fa | 9059 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9060 | if (bpoint == NULL) |
939c61fa JK |
9061 | return 0; |
9062 | ||
514f746b AR |
9063 | target_mem = alloca (len); |
9064 | ||
939c61fa JK |
9065 | /* Enable the automatic memory restoration from breakpoints while |
9066 | we read the memory. Otherwise we could say about our temporary | |
9067 | breakpoints they are permanent. */ | |
6c95b8df PA |
9068 | cleanup = save_current_space_and_thread (); |
9069 | ||
9070 | switch_to_program_space_and_thread (loc->pspace); | |
9071 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9072 | |
514f746b | 9073 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9074 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9075 | retval = 1; |
514f746b | 9076 | |
939c61fa JK |
9077 | do_cleanups (cleanup); |
9078 | ||
9079 | return retval; | |
514f746b AR |
9080 | } |
9081 | ||
e7e0cddf SS |
9082 | /* Build a command list for the dprintf corresponding to the current |
9083 | settings of the dprintf style options. */ | |
9084 | ||
9085 | static void | |
9086 | update_dprintf_command_list (struct breakpoint *b) | |
9087 | { | |
9088 | char *dprintf_args = b->extra_string; | |
9089 | char *printf_line = NULL; | |
9090 | ||
9091 | if (!dprintf_args) | |
9092 | return; | |
9093 | ||
9094 | dprintf_args = skip_spaces (dprintf_args); | |
9095 | ||
9096 | /* Allow a comma, as it may have terminated a location, but don't | |
9097 | insist on it. */ | |
9098 | if (*dprintf_args == ',') | |
9099 | ++dprintf_args; | |
9100 | dprintf_args = skip_spaces (dprintf_args); | |
9101 | ||
9102 | if (*dprintf_args != '"') | |
9103 | error (_("Bad format string, missing '\"'.")); | |
9104 | ||
d3ce09f5 | 9105 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9106 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9107 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9108 | { |
9109 | if (!dprintf_function) | |
9110 | error (_("No function supplied for dprintf call")); | |
9111 | ||
9112 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9113 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9114 | dprintf_function, | |
9115 | dprintf_channel, | |
9116 | dprintf_args); | |
9117 | else | |
9118 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9119 | dprintf_function, | |
9120 | dprintf_args); | |
9121 | } | |
d3ce09f5 SS |
9122 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9123 | { | |
9124 | if (target_can_run_breakpoint_commands ()) | |
9125 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9126 | else | |
9127 | { | |
9128 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9129 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9130 | } | |
9131 | } | |
e7e0cddf SS |
9132 | else |
9133 | internal_error (__FILE__, __LINE__, | |
9134 | _("Invalid dprintf style.")); | |
9135 | ||
f28045c2 | 9136 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9137 | /* Manufacture a printf sequence. */ |
f28045c2 | 9138 | { |
9d6e6e84 HZ |
9139 | struct command_line *printf_cmd_line |
9140 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9141 | |
f28045c2 YQ |
9142 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9143 | printf_cmd_line->control_type = simple_control; | |
9144 | printf_cmd_line->body_count = 0; | |
9145 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9146 | printf_cmd_line->next = NULL; |
f28045c2 | 9147 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9148 | |
f28045c2 YQ |
9149 | breakpoint_set_commands (b, printf_cmd_line); |
9150 | } | |
e7e0cddf SS |
9151 | } |
9152 | ||
9153 | /* Update all dprintf commands, making their command lists reflect | |
9154 | current style settings. */ | |
9155 | ||
9156 | static void | |
9157 | update_dprintf_commands (char *args, int from_tty, | |
9158 | struct cmd_list_element *c) | |
9159 | { | |
9160 | struct breakpoint *b; | |
9161 | ||
9162 | ALL_BREAKPOINTS (b) | |
9163 | { | |
9164 | if (b->type == bp_dprintf) | |
9165 | update_dprintf_command_list (b); | |
9166 | } | |
9167 | } | |
c3f6f71d | 9168 | |
018d34a4 VP |
9169 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9170 | as textual description of the location, and COND_STRING | |
db107f19 | 9171 | as condition expression. */ |
018d34a4 VP |
9172 | |
9173 | static void | |
d9b3f62e PA |
9174 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9175 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9176 | char *filter, char *cond_string, |
e7e0cddf | 9177 | char *extra_string, |
d9b3f62e PA |
9178 | enum bptype type, enum bpdisp disposition, |
9179 | int thread, int task, int ignore_count, | |
c0a91b2b | 9180 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9181 | int enabled, int internal, unsigned flags, |
9182 | int display_canonical) | |
018d34a4 | 9183 | { |
0d381245 | 9184 | int i; |
018d34a4 VP |
9185 | |
9186 | if (type == bp_hardware_breakpoint) | |
9187 | { | |
fbbd034e AS |
9188 | int target_resources_ok; |
9189 | ||
9190 | i = hw_breakpoint_used_count (); | |
9191 | target_resources_ok = | |
9192 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9193 | i + 1, 0); |
9194 | if (target_resources_ok == 0) | |
9195 | error (_("No hardware breakpoint support in the target.")); | |
9196 | else if (target_resources_ok < 0) | |
9197 | error (_("Hardware breakpoints used exceeds limit.")); | |
9198 | } | |
9199 | ||
6c95b8df PA |
9200 | gdb_assert (sals.nelts > 0); |
9201 | ||
0d381245 VP |
9202 | for (i = 0; i < sals.nelts; ++i) |
9203 | { | |
9204 | struct symtab_and_line sal = sals.sals[i]; | |
9205 | struct bp_location *loc; | |
9206 | ||
9207 | if (from_tty) | |
5af949e3 UW |
9208 | { |
9209 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9210 | if (!loc_gdbarch) | |
9211 | loc_gdbarch = gdbarch; | |
9212 | ||
9213 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9214 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9215 | } |
0d381245 VP |
9216 | |
9217 | if (i == 0) | |
9218 | { | |
d9b3f62e | 9219 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9220 | b->thread = thread; |
4a306c9a | 9221 | b->task = task; |
855a6e68 | 9222 | |
0d381245 | 9223 | b->cond_string = cond_string; |
e7e0cddf | 9224 | b->extra_string = extra_string; |
0d381245 | 9225 | b->ignore_count = ignore_count; |
41447f92 | 9226 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9227 | b->disposition = disposition; |
6c95b8df | 9228 | |
44f238bb PA |
9229 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9230 | b->loc->inserted = 1; | |
9231 | ||
0fb4aa4b PA |
9232 | if (type == bp_static_tracepoint) |
9233 | { | |
d9b3f62e | 9234 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9235 | struct static_tracepoint_marker marker; |
9236 | ||
983af33b | 9237 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9238 | { |
9239 | /* We already know the marker exists, otherwise, we | |
9240 | wouldn't see a sal for it. */ | |
9241 | char *p = &addr_string[3]; | |
9242 | char *endp; | |
9243 | char *marker_str; | |
0fb4aa4b | 9244 | |
e9cafbcc | 9245 | p = skip_spaces (p); |
0fb4aa4b | 9246 | |
e9cafbcc | 9247 | endp = skip_to_space (p); |
0fb4aa4b PA |
9248 | |
9249 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9250 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9251 | |
3e43a32a MS |
9252 | printf_filtered (_("Probed static tracepoint " |
9253 | "marker \"%s\"\n"), | |
d9b3f62e | 9254 | t->static_trace_marker_id); |
0fb4aa4b PA |
9255 | } |
9256 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9257 | { | |
d9b3f62e | 9258 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9259 | release_static_tracepoint_marker (&marker); |
9260 | ||
3e43a32a MS |
9261 | printf_filtered (_("Probed static tracepoint " |
9262 | "marker \"%s\"\n"), | |
d9b3f62e | 9263 | t->static_trace_marker_id); |
0fb4aa4b PA |
9264 | } |
9265 | else | |
3e43a32a MS |
9266 | warning (_("Couldn't determine the static " |
9267 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9268 | } |
9269 | ||
0d381245 VP |
9270 | loc = b->loc; |
9271 | } | |
9272 | else | |
018d34a4 | 9273 | { |
39d61571 | 9274 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9275 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9276 | loc->inserted = 1; | |
0d381245 VP |
9277 | } |
9278 | ||
514f746b AR |
9279 | if (bp_loc_is_permanent (loc)) |
9280 | make_breakpoint_permanent (b); | |
9281 | ||
0d381245 VP |
9282 | if (b->cond_string) |
9283 | { | |
bbc13ae3 KS |
9284 | const char *arg = b->cond_string; |
9285 | ||
1bb9788d TT |
9286 | loc->cond = parse_exp_1 (&arg, loc->address, |
9287 | block_for_pc (loc->address), 0); | |
0d381245 | 9288 | if (*arg) |
588ae58c | 9289 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9290 | } |
e7e0cddf SS |
9291 | |
9292 | /* Dynamic printf requires and uses additional arguments on the | |
9293 | command line, otherwise it's an error. */ | |
9294 | if (type == bp_dprintf) | |
9295 | { | |
9296 | if (b->extra_string) | |
9297 | update_dprintf_command_list (b); | |
9298 | else | |
9299 | error (_("Format string required")); | |
9300 | } | |
9301 | else if (b->extra_string) | |
588ae58c | 9302 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9303 | } |
018d34a4 | 9304 | |
56435ebe | 9305 | b->display_canonical = display_canonical; |
018d34a4 VP |
9306 | if (addr_string) |
9307 | b->addr_string = addr_string; | |
9308 | else | |
9309 | /* addr_string has to be used or breakpoint_re_set will delete | |
9310 | me. */ | |
5af949e3 UW |
9311 | b->addr_string |
9312 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9313 | b->filter = filter; |
d9b3f62e | 9314 | } |
018d34a4 | 9315 | |
d9b3f62e PA |
9316 | static void |
9317 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9318 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9319 | char *filter, char *cond_string, |
e7e0cddf | 9320 | char *extra_string, |
d9b3f62e PA |
9321 | enum bptype type, enum bpdisp disposition, |
9322 | int thread, int task, int ignore_count, | |
c0a91b2b | 9323 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9324 | int enabled, int internal, unsigned flags, |
9325 | int display_canonical) | |
d9b3f62e PA |
9326 | { |
9327 | struct breakpoint *b; | |
9328 | struct cleanup *old_chain; | |
9329 | ||
9330 | if (is_tracepoint_type (type)) | |
9331 | { | |
9332 | struct tracepoint *t; | |
9333 | ||
9334 | t = XCNEW (struct tracepoint); | |
9335 | b = &t->base; | |
9336 | } | |
9337 | else | |
9338 | b = XNEW (struct breakpoint); | |
9339 | ||
9340 | old_chain = make_cleanup (xfree, b); | |
9341 | ||
9342 | init_breakpoint_sal (b, gdbarch, | |
9343 | sals, addr_string, | |
e7e0cddf | 9344 | filter, cond_string, extra_string, |
d9b3f62e PA |
9345 | type, disposition, |
9346 | thread, task, ignore_count, | |
9347 | ops, from_tty, | |
44f238bb PA |
9348 | enabled, internal, flags, |
9349 | display_canonical); | |
d9b3f62e PA |
9350 | discard_cleanups (old_chain); |
9351 | ||
3ea46bff | 9352 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9353 | } |
9354 | ||
9355 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9356 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9357 | value. COND_STRING, if not NULL, specified the condition to be | |
9358 | used for all breakpoints. Essentially the only case where | |
9359 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9360 | function. In that case, it's still not possible to specify | |
9361 | separate conditions for different overloaded functions, so | |
9362 | we take just a single condition string. | |
9363 | ||
c3f6f71d | 9364 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9365 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9366 | array contents). If the function fails (error() is called), the |
9367 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9368 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9369 | |
9370 | static void | |
8cdf0e15 | 9371 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9372 | struct linespec_result *canonical, |
e7e0cddf | 9373 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9374 | enum bptype type, enum bpdisp disposition, |
9375 | int thread, int task, int ignore_count, | |
c0a91b2b | 9376 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9377 | int enabled, int internal, unsigned flags) |
c906108c | 9378 | { |
018d34a4 | 9379 | int i; |
f8eba3c6 | 9380 | struct linespec_sals *lsal; |
cc59ec59 | 9381 | |
f8eba3c6 TT |
9382 | if (canonical->pre_expanded) |
9383 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9384 | ||
9385 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9386 | { |
f8eba3c6 TT |
9387 | /* Note that 'addr_string' can be NULL in the case of a plain |
9388 | 'break', without arguments. */ | |
9389 | char *addr_string = (canonical->addr_string | |
9390 | ? xstrdup (canonical->addr_string) | |
9391 | : NULL); | |
9392 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9393 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9394 | |
f8eba3c6 TT |
9395 | make_cleanup (xfree, filter_string); |
9396 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9397 | addr_string, | |
9398 | filter_string, | |
e7e0cddf SS |
9399 | cond_string, extra_string, |
9400 | type, disposition, | |
84f4c1fe | 9401 | thread, task, ignore_count, ops, |
44f238bb | 9402 | from_tty, enabled, internal, flags, |
56435ebe | 9403 | canonical->special_display); |
f8eba3c6 | 9404 | discard_cleanups (inner); |
c3f6f71d | 9405 | } |
c3f6f71d | 9406 | } |
c906108c | 9407 | |
9998af43 | 9408 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9409 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9410 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9411 | address strings. ADDRESS points to the end of the SAL. |
9412 | ||
9413 | The array and the line spec strings are allocated on the heap, it is | |
9414 | the caller's responsibility to free them. */ | |
c906108c | 9415 | |
b9362cc7 | 9416 | static void |
c3f6f71d | 9417 | parse_breakpoint_sals (char **address, |
58438ac1 | 9418 | struct linespec_result *canonical) |
c3f6f71d | 9419 | { |
c3f6f71d | 9420 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9421 | breakpoint. */ |
c3f6f71d JM |
9422 | if ((*address) == NULL |
9423 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9424 | { |
1bfeeb0f JL |
9425 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9426 | address. */ | |
9427 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9428 | { |
f8eba3c6 | 9429 | struct linespec_sals lsal; |
c3f6f71d | 9430 | struct symtab_and_line sal; |
1c8cdcb1 | 9431 | CORE_ADDR pc; |
cc59ec59 | 9432 | |
4a64f543 | 9433 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9434 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9435 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9436 | |
9437 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9438 | corresponding to the last call to print_frame_info. |
9439 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9440 | as the breakpoint line number is inappropriate otherwise. | |
9441 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9442 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9443 | pc = sal.pc; |
9444 | sal = find_pc_line (pc, 0); | |
00903456 | 9445 | |
4a64f543 | 9446 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9447 | where PC is the last displayed codepoint's address. So |
9448 | make sure to set sal.explicit_pc to prevent GDB from | |
9449 | trying to expand the list of sals to include all other | |
9450 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9451 | sal.pc = pc; |
00903456 JK |
9452 | sal.explicit_pc = 1; |
9453 | ||
f8eba3c6 TT |
9454 | lsal.sals.sals[0] = sal; |
9455 | lsal.sals.nelts = 1; | |
9456 | lsal.canonical = NULL; | |
9457 | ||
9458 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9459 | } |
9460 | else | |
8a3fe4f8 | 9461 | error (_("No default breakpoint address now.")); |
c906108c SS |
9462 | } |
9463 | else | |
9464 | { | |
cc80f267 JK |
9465 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9466 | ||
c906108c | 9467 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9468 | current_source_symtab (which is decode_line_1's default). |
9469 | This should produce the results we want almost all of the | |
cc80f267 JK |
9470 | time while leaving default_breakpoint_* alone. |
9471 | ||
9472 | ObjC: However, don't match an Objective-C method name which | |
9473 | may have a '+' or '-' succeeded by a '['. */ | |
9474 | if (last_displayed_sal_is_valid () | |
9475 | && (!cursal.symtab | |
9476 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9477 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9478 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9479 | get_last_displayed_symtab (), | |
9480 | get_last_displayed_line (), | |
9481 | canonical, NULL, NULL); | |
c906108c | 9482 | else |
f8eba3c6 | 9483 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9484 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9485 | } |
c3f6f71d | 9486 | } |
c906108c | 9487 | |
c906108c | 9488 | |
c3f6f71d | 9489 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9490 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9491 | |
b9362cc7 | 9492 | static void |
23e7acfb | 9493 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9494 | { |
9495 | int i; | |
cc59ec59 | 9496 | |
c3f6f71d | 9497 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9498 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9499 | } |
9500 | ||
7a697b8d SS |
9501 | /* Fast tracepoints may have restrictions on valid locations. For |
9502 | instance, a fast tracepoint using a jump instead of a trap will | |
9503 | likely have to overwrite more bytes than a trap would, and so can | |
9504 | only be placed where the instruction is longer than the jump, or a | |
9505 | multi-instruction sequence does not have a jump into the middle of | |
9506 | it, etc. */ | |
9507 | ||
9508 | static void | |
9509 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9510 | struct symtabs_and_lines *sals) | |
9511 | { | |
9512 | int i, rslt; | |
9513 | struct symtab_and_line *sal; | |
9514 | char *msg; | |
9515 | struct cleanup *old_chain; | |
9516 | ||
9517 | for (i = 0; i < sals->nelts; i++) | |
9518 | { | |
f8eba3c6 TT |
9519 | struct gdbarch *sarch; |
9520 | ||
7a697b8d SS |
9521 | sal = &sals->sals[i]; |
9522 | ||
f8eba3c6 TT |
9523 | sarch = get_sal_arch (*sal); |
9524 | /* We fall back to GDBARCH if there is no architecture | |
9525 | associated with SAL. */ | |
9526 | if (sarch == NULL) | |
9527 | sarch = gdbarch; | |
9528 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9529 | NULL, &msg); |
9530 | old_chain = make_cleanup (xfree, msg); | |
9531 | ||
9532 | if (!rslt) | |
9533 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9534 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9535 | |
9536 | do_cleanups (old_chain); | |
9537 | } | |
9538 | } | |
9539 | ||
af4908ba KS |
9540 | /* Issue an invalid thread ID error. */ |
9541 | ||
9542 | static void ATTRIBUTE_NORETURN | |
9543 | invalid_thread_id_error (int id) | |
9544 | { | |
9545 | error (_("Unknown thread %d."), id); | |
9546 | } | |
9547 | ||
018d34a4 VP |
9548 | /* Given TOK, a string specification of condition and thread, as |
9549 | accepted by the 'break' command, extract the condition | |
9550 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9551 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9552 | If no condition is found, *COND_STRING is set to NULL. |
9553 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9554 | |
9555 | static void | |
bbc13ae3 | 9556 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9557 | char **cond_string, int *thread, int *task, |
9558 | char **rest) | |
018d34a4 VP |
9559 | { |
9560 | *cond_string = NULL; | |
9561 | *thread = -1; | |
ed1d1739 KS |
9562 | *task = 0; |
9563 | *rest = NULL; | |
9564 | ||
018d34a4 VP |
9565 | while (tok && *tok) |
9566 | { | |
bbc13ae3 | 9567 | const char *end_tok; |
018d34a4 | 9568 | int toklen; |
bbc13ae3 KS |
9569 | const char *cond_start = NULL; |
9570 | const char *cond_end = NULL; | |
cc59ec59 | 9571 | |
bbc13ae3 | 9572 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9573 | |
9574 | if ((*tok == '"' || *tok == ',') && rest) | |
9575 | { | |
9576 | *rest = savestring (tok, strlen (tok)); | |
9577 | return; | |
9578 | } | |
9579 | ||
bbc13ae3 | 9580 | end_tok = skip_to_space_const (tok); |
d634f2de | 9581 | |
018d34a4 | 9582 | toklen = end_tok - tok; |
d634f2de | 9583 | |
018d34a4 VP |
9584 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9585 | { | |
f7545552 TT |
9586 | struct expression *expr; |
9587 | ||
018d34a4 | 9588 | tok = cond_start = end_tok + 1; |
1bb9788d | 9589 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9590 | xfree (expr); |
018d34a4 | 9591 | cond_end = tok; |
d634f2de | 9592 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9593 | } |
9594 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9595 | { | |
9596 | char *tmptok; | |
d634f2de | 9597 | |
018d34a4 | 9598 | tok = end_tok + 1; |
bbc13ae3 | 9599 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9600 | if (tok == tmptok) |
9601 | error (_("Junk after thread keyword.")); | |
9602 | if (!valid_thread_id (*thread)) | |
af4908ba | 9603 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9604 | tok = tmptok; |
018d34a4 | 9605 | } |
4a306c9a JB |
9606 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9607 | { | |
9608 | char *tmptok; | |
9609 | ||
9610 | tok = end_tok + 1; | |
bbc13ae3 | 9611 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9612 | if (tok == tmptok) |
9613 | error (_("Junk after task keyword.")); | |
9614 | if (!valid_task_id (*task)) | |
b6199126 | 9615 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9616 | tok = tmptok; |
4a306c9a | 9617 | } |
e7e0cddf SS |
9618 | else if (rest) |
9619 | { | |
9620 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9621 | return; |
e7e0cddf | 9622 | } |
018d34a4 VP |
9623 | else |
9624 | error (_("Junk at end of arguments.")); | |
9625 | } | |
9626 | } | |
9627 | ||
0fb4aa4b PA |
9628 | /* Decode a static tracepoint marker spec. */ |
9629 | ||
9630 | static struct symtabs_and_lines | |
9631 | decode_static_tracepoint_spec (char **arg_p) | |
9632 | { | |
9633 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9634 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9635 | struct cleanup *old_chain; |
9636 | char *p = &(*arg_p)[3]; | |
9637 | char *endp; | |
9638 | char *marker_str; | |
9639 | int i; | |
9640 | ||
e9cafbcc | 9641 | p = skip_spaces (p); |
0fb4aa4b | 9642 | |
e9cafbcc | 9643 | endp = skip_to_space (p); |
0fb4aa4b PA |
9644 | |
9645 | marker_str = savestring (p, endp - p); | |
9646 | old_chain = make_cleanup (xfree, marker_str); | |
9647 | ||
9648 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9649 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9650 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9651 | ||
9652 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9653 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9654 | ||
9655 | for (i = 0; i < sals.nelts; i++) | |
9656 | { | |
9657 | struct static_tracepoint_marker *marker; | |
9658 | ||
9659 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9660 | ||
9661 | init_sal (&sals.sals[i]); | |
9662 | ||
9663 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9664 | sals.sals[i].pc = marker->address; | |
9665 | ||
9666 | release_static_tracepoint_marker (marker); | |
9667 | } | |
9668 | ||
9669 | do_cleanups (old_chain); | |
9670 | ||
9671 | *arg_p = endp; | |
9672 | return sals; | |
9673 | } | |
9674 | ||
fd9b8c24 PA |
9675 | /* Set a breakpoint. This function is shared between CLI and MI |
9676 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9677 | modes of operations, selected by the PARSE_ARG parameter. If |
9678 | non-zero, the function will parse ARG, extracting location, | |
9679 | condition, thread and extra string. Otherwise, ARG is just the | |
9680 | breakpoint's location, with condition, thread, and extra string | |
9681 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9682 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9683 | from the internal breakpoint count. Returns true if any breakpoint | |
9684 | was created; false otherwise. */ | |
0101ce28 | 9685 | |
8cdf0e15 VP |
9686 | int |
9687 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9688 | char *arg, char *cond_string, |
9689 | int thread, char *extra_string, | |
f6de8ec2 | 9690 | int parse_arg, |
0fb4aa4b | 9691 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9692 | int ignore_count, |
9693 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9694 | const struct breakpoint_ops *ops, |
44f238bb PA |
9695 | int from_tty, int enabled, int internal, |
9696 | unsigned flags) | |
c3f6f71d | 9697 | { |
b78a6381 | 9698 | volatile struct gdb_exception e; |
f8eba3c6 | 9699 | char *copy_arg = NULL; |
c3f6f71d | 9700 | char *addr_start = arg; |
7efd8fc2 | 9701 | struct linespec_result canonical; |
c3f6f71d | 9702 | struct cleanup *old_chain; |
80c99de1 | 9703 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9704 | int pending = 0; |
4a306c9a | 9705 | int task = 0; |
86b17b60 | 9706 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9707 | |
348d480f PA |
9708 | gdb_assert (ops != NULL); |
9709 | ||
7efd8fc2 | 9710 | init_linespec_result (&canonical); |
c3f6f71d | 9711 | |
b78a6381 TT |
9712 | TRY_CATCH (e, RETURN_MASK_ALL) |
9713 | { | |
983af33b SDJ |
9714 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9715 | addr_start, ©_arg); | |
b78a6381 | 9716 | } |
0101ce28 JJ |
9717 | |
9718 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9719 | switch (e.reason) |
0101ce28 | 9720 | { |
983af33b SDJ |
9721 | case GDB_NO_ERROR: |
9722 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9723 | return 0; | |
9724 | break; | |
05ff989b AC |
9725 | case RETURN_ERROR: |
9726 | switch (e.error) | |
0101ce28 | 9727 | { |
05ff989b | 9728 | case NOT_FOUND_ERROR: |
0101ce28 | 9729 | |
05ff989b AC |
9730 | /* If pending breakpoint support is turned off, throw |
9731 | error. */ | |
fa8d40ab JJ |
9732 | |
9733 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9734 | throw_exception (e); |
9735 | ||
9736 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9737 | |
05ff989b AC |
9738 | /* If pending breakpoint support is auto query and the user |
9739 | selects no, then simply return the error code. */ | |
059fb39f | 9740 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9741 | && !nquery (_("Make %s pending on future shared library load? "), |
9742 | bptype_string (type_wanted))) | |
fd9b8c24 | 9743 | return 0; |
fa8d40ab | 9744 | |
05ff989b AC |
9745 | /* At this point, either the user was queried about setting |
9746 | a pending breakpoint and selected yes, or pending | |
9747 | breakpoint behavior is on and thus a pending breakpoint | |
9748 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9749 | { |
9750 | struct linespec_sals lsal; | |
9751 | ||
9752 | copy_arg = xstrdup (addr_start); | |
9753 | lsal.canonical = xstrdup (copy_arg); | |
9754 | lsal.sals.nelts = 1; | |
9755 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9756 | init_sal (&lsal.sals.sals[0]); | |
9757 | pending = 1; | |
9758 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9759 | } | |
05ff989b AC |
9760 | break; |
9761 | default: | |
98deb0da | 9762 | throw_exception (e); |
0101ce28 | 9763 | } |
2abae994 | 9764 | break; |
05ff989b | 9765 | default: |
983af33b | 9766 | throw_exception (e); |
0101ce28 | 9767 | } |
c3f6f71d | 9768 | |
4a64f543 | 9769 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9770 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9771 | |
c3f6f71d JM |
9772 | /* ----------------------------- SNIP ----------------------------- |
9773 | Anything added to the cleanup chain beyond this point is assumed | |
9774 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9775 | then the memory is not reclaimed. */ |
9776 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9777 | |
c3f6f71d JM |
9778 | /* Resolve all line numbers to PC's and verify that the addresses |
9779 | are ok for the target. */ | |
0101ce28 | 9780 | if (!pending) |
f8eba3c6 TT |
9781 | { |
9782 | int ix; | |
9783 | struct linespec_sals *iter; | |
9784 | ||
9785 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9786 | breakpoint_sals_to_pc (&iter->sals); | |
9787 | } | |
c3f6f71d | 9788 | |
7a697b8d | 9789 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9790 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9791 | { |
9792 | int ix; | |
9793 | struct linespec_sals *iter; | |
9794 | ||
9795 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9796 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9797 | } | |
7a697b8d | 9798 | |
c3f6f71d JM |
9799 | /* Verify that condition can be parsed, before setting any |
9800 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9801 | breakpoint. */ |
0101ce28 | 9802 | if (!pending) |
c3f6f71d | 9803 | { |
f6de8ec2 | 9804 | if (parse_arg) |
72b2ff0e | 9805 | { |
0878d0fa | 9806 | char *rest; |
52d361e1 YQ |
9807 | struct linespec_sals *lsal; |
9808 | ||
9809 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9810 | ||
0878d0fa YQ |
9811 | /* Here we only parse 'arg' to separate condition |
9812 | from thread number, so parsing in context of first | |
9813 | sal is OK. When setting the breakpoint we'll | |
9814 | re-parse it in context of each sal. */ | |
9815 | ||
9816 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9817 | &thread, &task, &rest); | |
9818 | if (cond_string) | |
9819 | make_cleanup (xfree, cond_string); | |
9820 | if (rest) | |
9821 | make_cleanup (xfree, rest); | |
9822 | if (rest) | |
9823 | extra_string = rest; | |
72b2ff0e | 9824 | } |
2f069f6f | 9825 | else |
72b2ff0e | 9826 | { |
0878d0fa YQ |
9827 | if (*arg != '\0') |
9828 | error (_("Garbage '%s' at end of location"), arg); | |
9829 | ||
9830 | /* Create a private copy of condition string. */ | |
9831 | if (cond_string) | |
9832 | { | |
9833 | cond_string = xstrdup (cond_string); | |
9834 | make_cleanup (xfree, cond_string); | |
9835 | } | |
9836 | /* Create a private copy of any extra string. */ | |
9837 | if (extra_string) | |
9838 | { | |
9839 | extra_string = xstrdup (extra_string); | |
9840 | make_cleanup (xfree, extra_string); | |
9841 | } | |
72b2ff0e | 9842 | } |
0fb4aa4b | 9843 | |
52d361e1 | 9844 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9845 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9846 | tempflag ? disp_del : disp_donttouch, |
9847 | thread, task, ignore_count, ops, | |
44f238bb | 9848 | from_tty, enabled, internal, flags); |
c906108c | 9849 | } |
0101ce28 JJ |
9850 | else |
9851 | { | |
0101ce28 JJ |
9852 | struct breakpoint *b; |
9853 | ||
0101ce28 JJ |
9854 | make_cleanup (xfree, copy_arg); |
9855 | ||
bfccc43c YQ |
9856 | if (is_tracepoint_type (type_wanted)) |
9857 | { | |
9858 | struct tracepoint *t; | |
9859 | ||
9860 | t = XCNEW (struct tracepoint); | |
9861 | b = &t->base; | |
9862 | } | |
9863 | else | |
9864 | b = XNEW (struct breakpoint); | |
9865 | ||
9866 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9867 | ||
f8eba3c6 | 9868 | b->addr_string = copy_arg; |
f6de8ec2 | 9869 | if (parse_arg) |
e12c7713 MK |
9870 | b->cond_string = NULL; |
9871 | else | |
9872 | { | |
9873 | /* Create a private copy of condition string. */ | |
9874 | if (cond_string) | |
9875 | { | |
9876 | cond_string = xstrdup (cond_string); | |
9877 | make_cleanup (xfree, cond_string); | |
9878 | } | |
9879 | b->cond_string = cond_string; | |
9880 | } | |
e7e0cddf | 9881 | b->extra_string = NULL; |
0101ce28 | 9882 | b->ignore_count = ignore_count; |
0101ce28 | 9883 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9884 | b->condition_not_parsed = 1; |
41447f92 | 9885 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9886 | if ((type_wanted != bp_breakpoint |
9887 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9888 | b->pspace = current_program_space; |
8bea4e01 | 9889 | |
bfccc43c | 9890 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9891 | } |
9892 | ||
f8eba3c6 | 9893 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9894 | { |
3e43a32a MS |
9895 | warning (_("Multiple breakpoints were set.\nUse the " |
9896 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9897 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9898 | } |
9899 | ||
80c99de1 PA |
9900 | /* That's it. Discard the cleanups for data inserted into the |
9901 | breakpoint. */ | |
9902 | discard_cleanups (bkpt_chain); | |
9903 | /* But cleanup everything else. */ | |
c3f6f71d | 9904 | do_cleanups (old_chain); |
217dc9e2 | 9905 | |
80c99de1 | 9906 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9907 | update_global_location_list (1); |
fd9b8c24 PA |
9908 | |
9909 | return 1; | |
c3f6f71d | 9910 | } |
c906108c | 9911 | |
348d480f | 9912 | /* Set a breakpoint. |
72b2ff0e VP |
9913 | ARG is a string describing breakpoint address, |
9914 | condition, and thread. | |
9915 | FLAG specifies if a breakpoint is hardware on, | |
9916 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9917 | and BP_TEMPFLAG. */ | |
348d480f | 9918 | |
98deb0da | 9919 | static void |
72b2ff0e | 9920 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9921 | { |
72b2ff0e | 9922 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9923 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9924 | ? bp_hardware_breakpoint | |
9925 | : bp_breakpoint); | |
55aa24fb SDJ |
9926 | struct breakpoint_ops *ops; |
9927 | const char *arg_cp = arg; | |
9928 | ||
9929 | /* Matching breakpoints on probes. */ | |
9930 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9931 | ops = &bkpt_probe_breakpoint_ops; | |
9932 | else | |
9933 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9934 | |
8cdf0e15 VP |
9935 | create_breakpoint (get_current_arch (), |
9936 | arg, | |
e7e0cddf | 9937 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9938 | tempflag, type_wanted, |
8cdf0e15 VP |
9939 | 0 /* Ignore count */, |
9940 | pending_break_support, | |
55aa24fb | 9941 | ops, |
8cdf0e15 | 9942 | from_tty, |
84f4c1fe | 9943 | 1 /* enabled */, |
44f238bb PA |
9944 | 0 /* internal */, |
9945 | 0); | |
c906108c SS |
9946 | } |
9947 | ||
c906108c SS |
9948 | /* Helper function for break_command_1 and disassemble_command. */ |
9949 | ||
9950 | void | |
fba45db2 | 9951 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9952 | { |
9953 | CORE_ADDR pc; | |
9954 | ||
9955 | if (sal->pc == 0 && sal->symtab != NULL) | |
9956 | { | |
9957 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9958 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9959 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9960 | sal->pc = pc; |
6a048695 | 9961 | |
4a64f543 MS |
9962 | /* If this SAL corresponds to a breakpoint inserted using a line |
9963 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9964 | if (sal->explicit_line) |
059acae7 | 9965 | skip_prologue_sal (sal); |
c906108c SS |
9966 | } |
9967 | ||
9968 | if (sal->section == 0 && sal->symtab != NULL) | |
9969 | { | |
9970 | struct blockvector *bv; | |
c5aa993b JM |
9971 | struct block *b; |
9972 | struct symbol *sym; | |
c906108c | 9973 | |
801e3a5b | 9974 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9975 | if (bv != NULL) |
9976 | { | |
7f0df278 | 9977 | sym = block_linkage_function (b); |
c906108c SS |
9978 | if (sym != NULL) |
9979 | { | |
9980 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9981 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9982 | } |
9983 | else | |
9984 | { | |
4a64f543 MS |
9985 | /* It really is worthwhile to have the section, so we'll |
9986 | just have to look harder. This case can be executed | |
9987 | if we have line numbers but no functions (as can | |
9988 | happen in assembly source). */ | |
c906108c | 9989 | |
7cbd4a93 | 9990 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9991 | struct cleanup *old_chain = save_current_space_and_thread (); |
9992 | ||
9993 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9994 | |
9995 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9996 | if (msym.minsym) |
efd66ac6 | 9997 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9998 | |
9999 | do_cleanups (old_chain); | |
c906108c SS |
10000 | } |
10001 | } | |
10002 | } | |
10003 | } | |
10004 | ||
10005 | void | |
fba45db2 | 10006 | break_command (char *arg, int from_tty) |
c906108c | 10007 | { |
db107f19 | 10008 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10009 | } |
10010 | ||
c906108c | 10011 | void |
fba45db2 | 10012 | tbreak_command (char *arg, int from_tty) |
c906108c | 10013 | { |
db107f19 | 10014 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10015 | } |
10016 | ||
c906108c | 10017 | static void |
fba45db2 | 10018 | hbreak_command (char *arg, int from_tty) |
c906108c | 10019 | { |
db107f19 | 10020 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10021 | } |
10022 | ||
10023 | static void | |
fba45db2 | 10024 | thbreak_command (char *arg, int from_tty) |
c906108c | 10025 | { |
db107f19 | 10026 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10027 | } |
10028 | ||
10029 | static void | |
fba45db2 | 10030 | stop_command (char *arg, int from_tty) |
c906108c | 10031 | { |
a3f17187 | 10032 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10033 | Usage: stop in <function | address>\n\ |
a3f17187 | 10034 | stop at <line>\n")); |
c906108c SS |
10035 | } |
10036 | ||
10037 | static void | |
fba45db2 | 10038 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10039 | { |
10040 | int badInput = 0; | |
10041 | ||
c5aa993b | 10042 | if (arg == (char *) NULL) |
c906108c SS |
10043 | badInput = 1; |
10044 | else if (*arg != '*') | |
10045 | { | |
10046 | char *argptr = arg; | |
10047 | int hasColon = 0; | |
10048 | ||
4a64f543 | 10049 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10050 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10051 | function/method name. */ |
c906108c | 10052 | while (*argptr && !hasColon) |
c5aa993b JM |
10053 | { |
10054 | hasColon = (*argptr == ':'); | |
10055 | argptr++; | |
10056 | } | |
c906108c SS |
10057 | |
10058 | if (hasColon) | |
c5aa993b | 10059 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10060 | else |
c5aa993b | 10061 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10062 | } |
10063 | ||
10064 | if (badInput) | |
a3f17187 | 10065 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10066 | else |
db107f19 | 10067 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10068 | } |
10069 | ||
10070 | static void | |
fba45db2 | 10071 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10072 | { |
10073 | int badInput = 0; | |
10074 | ||
c5aa993b | 10075 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10076 | badInput = 1; |
10077 | else | |
10078 | { | |
10079 | char *argptr = arg; | |
10080 | int hasColon = 0; | |
10081 | ||
4a64f543 MS |
10082 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10083 | it is probably a line number. */ | |
c906108c | 10084 | while (*argptr && !hasColon) |
c5aa993b JM |
10085 | { |
10086 | hasColon = (*argptr == ':'); | |
10087 | argptr++; | |
10088 | } | |
c906108c SS |
10089 | |
10090 | if (hasColon) | |
c5aa993b | 10091 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10092 | else |
c5aa993b | 10093 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10094 | } |
10095 | ||
10096 | if (badInput) | |
a3f17187 | 10097 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10098 | else |
db107f19 | 10099 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10100 | } |
10101 | ||
e7e0cddf SS |
10102 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10103 | with a prewired command list consisting of a single output command, | |
10104 | built from extra arguments supplied on the dprintf command | |
10105 | line. */ | |
10106 | ||
da821c7b | 10107 | static void |
e7e0cddf SS |
10108 | dprintf_command (char *arg, int from_tty) |
10109 | { | |
10110 | create_breakpoint (get_current_arch (), | |
10111 | arg, | |
10112 | NULL, 0, NULL, 1 /* parse arg */, | |
10113 | 0, bp_dprintf, | |
10114 | 0 /* Ignore count */, | |
10115 | pending_break_support, | |
10116 | &dprintf_breakpoint_ops, | |
10117 | from_tty, | |
10118 | 1 /* enabled */, | |
10119 | 0 /* internal */, | |
10120 | 0); | |
10121 | } | |
10122 | ||
d3ce09f5 SS |
10123 | static void |
10124 | agent_printf_command (char *arg, int from_tty) | |
10125 | { | |
10126 | error (_("May only run agent-printf on the target")); | |
10127 | } | |
10128 | ||
f1310107 TJB |
10129 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10130 | ranged breakpoints. */ | |
10131 | ||
10132 | static int | |
10133 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10134 | struct address_space *aspace, | |
09ac7c10 TT |
10135 | CORE_ADDR bp_addr, |
10136 | const struct target_waitstatus *ws) | |
f1310107 | 10137 | { |
09ac7c10 | 10138 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10139 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10140 | return 0; |
10141 | ||
f1310107 TJB |
10142 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10143 | bl->length, aspace, bp_addr); | |
10144 | } | |
10145 | ||
10146 | /* Implement the "resources_needed" breakpoint_ops method for | |
10147 | ranged breakpoints. */ | |
10148 | ||
10149 | static int | |
10150 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10151 | { | |
10152 | return target_ranged_break_num_registers (); | |
10153 | } | |
10154 | ||
10155 | /* Implement the "print_it" breakpoint_ops method for | |
10156 | ranged breakpoints. */ | |
10157 | ||
10158 | static enum print_stop_action | |
348d480f | 10159 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10160 | { |
348d480f | 10161 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10162 | struct bp_location *bl = b->loc; |
79a45e25 | 10163 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10164 | |
10165 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10166 | ||
10167 | /* Ranged breakpoints have only one location. */ | |
10168 | gdb_assert (bl && bl->next == NULL); | |
10169 | ||
10170 | annotate_breakpoint (b->number); | |
10171 | if (b->disposition == disp_del) | |
10172 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10173 | else | |
10174 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10175 | if (ui_out_is_mi_like_p (uiout)) | |
10176 | { | |
10177 | ui_out_field_string (uiout, "reason", | |
10178 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10179 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10180 | } | |
10181 | ui_out_field_int (uiout, "bkptno", b->number); | |
10182 | ui_out_text (uiout, ", "); | |
10183 | ||
10184 | return PRINT_SRC_AND_LOC; | |
10185 | } | |
10186 | ||
10187 | /* Implement the "print_one" breakpoint_ops method for | |
10188 | ranged breakpoints. */ | |
10189 | ||
10190 | static void | |
10191 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10192 | struct bp_location **last_loc) | |
10193 | { | |
10194 | struct bp_location *bl = b->loc; | |
10195 | struct value_print_options opts; | |
79a45e25 | 10196 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10197 | |
10198 | /* Ranged breakpoints have only one location. */ | |
10199 | gdb_assert (bl && bl->next == NULL); | |
10200 | ||
10201 | get_user_print_options (&opts); | |
10202 | ||
10203 | if (opts.addressprint) | |
10204 | /* We don't print the address range here, it will be printed later | |
10205 | by print_one_detail_ranged_breakpoint. */ | |
10206 | ui_out_field_skip (uiout, "addr"); | |
10207 | annotate_field (5); | |
10208 | print_breakpoint_location (b, bl); | |
10209 | *last_loc = bl; | |
10210 | } | |
10211 | ||
10212 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10213 | ranged breakpoints. */ | |
10214 | ||
10215 | static void | |
10216 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10217 | struct ui_out *uiout) | |
10218 | { | |
10219 | CORE_ADDR address_start, address_end; | |
10220 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10221 | struct ui_file *stb = mem_fileopen (); |
10222 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10223 | |
10224 | gdb_assert (bl); | |
10225 | ||
10226 | address_start = bl->address; | |
10227 | address_end = address_start + bl->length - 1; | |
10228 | ||
10229 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10230 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10231 | print_core_address (bl->gdbarch, address_start), |
10232 | print_core_address (bl->gdbarch, address_end)); | |
10233 | ui_out_field_stream (uiout, "addr", stb); | |
10234 | ui_out_text (uiout, "\n"); | |
10235 | ||
10236 | do_cleanups (cleanup); | |
10237 | } | |
10238 | ||
10239 | /* Implement the "print_mention" breakpoint_ops method for | |
10240 | ranged breakpoints. */ | |
10241 | ||
10242 | static void | |
10243 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10244 | { | |
10245 | struct bp_location *bl = b->loc; | |
79a45e25 | 10246 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10247 | |
10248 | gdb_assert (bl); | |
10249 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10250 | ||
10251 | if (ui_out_is_mi_like_p (uiout)) | |
10252 | return; | |
10253 | ||
10254 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10255 | b->number, paddress (bl->gdbarch, bl->address), | |
10256 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10257 | } | |
10258 | ||
10259 | /* Implement the "print_recreate" breakpoint_ops method for | |
10260 | ranged breakpoints. */ | |
10261 | ||
10262 | static void | |
10263 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10264 | { | |
10265 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10266 | b->addr_string_range_end); | |
d9b3f62e | 10267 | print_recreate_thread (b, fp); |
f1310107 TJB |
10268 | } |
10269 | ||
10270 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10271 | ||
2060206e | 10272 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10273 | |
10274 | /* Find the address where the end of the breakpoint range should be | |
10275 | placed, given the SAL of the end of the range. This is so that if | |
10276 | the user provides a line number, the end of the range is set to the | |
10277 | last instruction of the given line. */ | |
10278 | ||
10279 | static CORE_ADDR | |
10280 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10281 | { | |
10282 | CORE_ADDR end; | |
10283 | ||
10284 | /* If the user provided a PC value, use it. Otherwise, | |
10285 | find the address of the end of the given location. */ | |
10286 | if (sal.explicit_pc) | |
10287 | end = sal.pc; | |
10288 | else | |
10289 | { | |
10290 | int ret; | |
10291 | CORE_ADDR start; | |
10292 | ||
10293 | ret = find_line_pc_range (sal, &start, &end); | |
10294 | if (!ret) | |
10295 | error (_("Could not find location of the end of the range.")); | |
10296 | ||
10297 | /* find_line_pc_range returns the start of the next line. */ | |
10298 | end--; | |
10299 | } | |
10300 | ||
10301 | return end; | |
10302 | } | |
10303 | ||
10304 | /* Implement the "break-range" CLI command. */ | |
10305 | ||
10306 | static void | |
10307 | break_range_command (char *arg, int from_tty) | |
10308 | { | |
10309 | char *arg_start, *addr_string_start, *addr_string_end; | |
10310 | struct linespec_result canonical_start, canonical_end; | |
10311 | int bp_count, can_use_bp, length; | |
10312 | CORE_ADDR end; | |
10313 | struct breakpoint *b; | |
10314 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10315 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10316 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10317 | |
10318 | /* We don't support software ranged breakpoints. */ | |
10319 | if (target_ranged_break_num_registers () < 0) | |
10320 | error (_("This target does not support hardware ranged breakpoints.")); | |
10321 | ||
10322 | bp_count = hw_breakpoint_used_count (); | |
10323 | bp_count += target_ranged_break_num_registers (); | |
10324 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10325 | bp_count, 0); | |
10326 | if (can_use_bp < 0) | |
10327 | error (_("Hardware breakpoints used exceeds limit.")); | |
10328 | ||
f8eba3c6 | 10329 | arg = skip_spaces (arg); |
f1310107 TJB |
10330 | if (arg == NULL || arg[0] == '\0') |
10331 | error(_("No address range specified.")); | |
10332 | ||
f1310107 TJB |
10333 | init_linespec_result (&canonical_start); |
10334 | ||
f8eba3c6 TT |
10335 | arg_start = arg; |
10336 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10337 | |
f8eba3c6 | 10338 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10339 | |
10340 | if (arg[0] != ',') | |
10341 | error (_("Too few arguments.")); | |
f8eba3c6 | 10342 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10343 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10344 | |
10345 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10346 | ||
10347 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10348 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10349 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10350 | ||
f8eba3c6 TT |
10351 | sal_start = lsal_start->sals.sals[0]; |
10352 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10353 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10354 | |
10355 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10356 | arg = skip_spaces (arg); |
f1310107 TJB |
10357 | |
10358 | /* Parse the end location. */ | |
10359 | ||
f1310107 TJB |
10360 | init_linespec_result (&canonical_end); |
10361 | arg_start = arg; | |
10362 | ||
f8eba3c6 | 10363 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10364 | parse_breakpoint_sals because we need to specify the start location's |
10365 | symtab and line as the default symtab and line for the end of the | |
10366 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10367 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10368 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10369 | sal_start.symtab, sal_start.line, | |
10370 | &canonical_end, NULL, NULL); | |
10371 | ||
10372 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10373 | |
f8eba3c6 | 10374 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10375 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10376 | |
10377 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10378 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10379 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10380 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10381 | ||
f8eba3c6 TT |
10382 | sal_end = lsal_end->sals.sals[0]; |
10383 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10384 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10385 | |
10386 | end = find_breakpoint_range_end (sal_end); | |
10387 | if (sal_start.pc > end) | |
177b42fe | 10388 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10389 | |
10390 | length = end - sal_start.pc + 1; | |
10391 | if (length < 0) | |
10392 | /* Length overflowed. */ | |
10393 | error (_("Address range too large.")); | |
10394 | else if (length == 1) | |
10395 | { | |
10396 | /* This range is simple enough to be handled by | |
10397 | the `hbreak' command. */ | |
10398 | hbreak_command (addr_string_start, 1); | |
10399 | ||
10400 | do_cleanups (cleanup_bkpt); | |
10401 | ||
10402 | return; | |
10403 | } | |
10404 | ||
10405 | /* Now set up the breakpoint. */ | |
10406 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10407 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10408 | set_breakpoint_count (breakpoint_count + 1); |
10409 | b->number = breakpoint_count; | |
10410 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10411 | b->addr_string = xstrdup (addr_string_start); |
10412 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10413 | b->loc->length = length; |
10414 | ||
f8eba3c6 | 10415 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10416 | |
10417 | mention (b); | |
8d3788bd | 10418 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10419 | update_global_location_list (1); |
10420 | } | |
10421 | ||
4a64f543 MS |
10422 | /* Return non-zero if EXP is verified as constant. Returned zero |
10423 | means EXP is variable. Also the constant detection may fail for | |
10424 | some constant expressions and in such case still falsely return | |
10425 | zero. */ | |
2e6e3d9c | 10426 | |
65d79d4b SDJ |
10427 | static int |
10428 | watchpoint_exp_is_const (const struct expression *exp) | |
10429 | { | |
10430 | int i = exp->nelts; | |
10431 | ||
10432 | while (i > 0) | |
10433 | { | |
10434 | int oplenp, argsp; | |
10435 | ||
10436 | /* We are only interested in the descriptor of each element. */ | |
10437 | operator_length (exp, i, &oplenp, &argsp); | |
10438 | i -= oplenp; | |
10439 | ||
10440 | switch (exp->elts[i].opcode) | |
10441 | { | |
10442 | case BINOP_ADD: | |
10443 | case BINOP_SUB: | |
10444 | case BINOP_MUL: | |
10445 | case BINOP_DIV: | |
10446 | case BINOP_REM: | |
10447 | case BINOP_MOD: | |
10448 | case BINOP_LSH: | |
10449 | case BINOP_RSH: | |
10450 | case BINOP_LOGICAL_AND: | |
10451 | case BINOP_LOGICAL_OR: | |
10452 | case BINOP_BITWISE_AND: | |
10453 | case BINOP_BITWISE_IOR: | |
10454 | case BINOP_BITWISE_XOR: | |
10455 | case BINOP_EQUAL: | |
10456 | case BINOP_NOTEQUAL: | |
10457 | case BINOP_LESS: | |
10458 | case BINOP_GTR: | |
10459 | case BINOP_LEQ: | |
10460 | case BINOP_GEQ: | |
10461 | case BINOP_REPEAT: | |
10462 | case BINOP_COMMA: | |
10463 | case BINOP_EXP: | |
10464 | case BINOP_MIN: | |
10465 | case BINOP_MAX: | |
10466 | case BINOP_INTDIV: | |
10467 | case BINOP_CONCAT: | |
10468 | case BINOP_IN: | |
10469 | case BINOP_RANGE: | |
10470 | case TERNOP_COND: | |
10471 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10472 | |
10473 | case OP_LONG: | |
10474 | case OP_DOUBLE: | |
10475 | case OP_DECFLOAT: | |
10476 | case OP_LAST: | |
10477 | case OP_COMPLEX: | |
10478 | case OP_STRING: | |
65d79d4b SDJ |
10479 | case OP_ARRAY: |
10480 | case OP_TYPE: | |
608b4967 TT |
10481 | case OP_TYPEOF: |
10482 | case OP_DECLTYPE: | |
6e72ca20 | 10483 | case OP_TYPEID: |
65d79d4b SDJ |
10484 | case OP_NAME: |
10485 | case OP_OBJC_NSSTRING: | |
10486 | ||
10487 | case UNOP_NEG: | |
10488 | case UNOP_LOGICAL_NOT: | |
10489 | case UNOP_COMPLEMENT: | |
10490 | case UNOP_ADDR: | |
10491 | case UNOP_HIGH: | |
aeaa2474 | 10492 | case UNOP_CAST: |
9eaf6705 TT |
10493 | |
10494 | case UNOP_CAST_TYPE: | |
10495 | case UNOP_REINTERPRET_CAST: | |
10496 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10497 | /* Unary, binary and ternary operators: We have to check |
10498 | their operands. If they are constant, then so is the | |
10499 | result of that operation. For instance, if A and B are | |
10500 | determined to be constants, then so is "A + B". | |
10501 | ||
10502 | UNOP_IND is one exception to the rule above, because the | |
10503 | value of *ADDR is not necessarily a constant, even when | |
10504 | ADDR is. */ | |
65d79d4b SDJ |
10505 | break; |
10506 | ||
10507 | case OP_VAR_VALUE: | |
10508 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10509 | |
65d79d4b | 10510 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10511 | possible that a buggy compiler could mark a variable as |
10512 | constant even when it is not, and TYPE_CONST would return | |
10513 | true in this case, while SYMBOL_CLASS wouldn't. | |
10514 | ||
10515 | We also have to check for function symbols because they | |
10516 | are always constant. */ | |
65d79d4b SDJ |
10517 | { |
10518 | struct symbol *s = exp->elts[i + 2].symbol; | |
10519 | ||
10520 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10521 | && SYMBOL_CLASS (s) != LOC_CONST | |
10522 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10523 | return 0; | |
10524 | break; | |
10525 | } | |
10526 | ||
10527 | /* The default action is to return 0 because we are using | |
10528 | the optimistic approach here: If we don't know something, | |
10529 | then it is not a constant. */ | |
10530 | default: | |
10531 | return 0; | |
10532 | } | |
10533 | } | |
10534 | ||
10535 | return 1; | |
10536 | } | |
10537 | ||
3a5c3e22 PA |
10538 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10539 | ||
10540 | static void | |
10541 | dtor_watchpoint (struct breakpoint *self) | |
10542 | { | |
10543 | struct watchpoint *w = (struct watchpoint *) self; | |
10544 | ||
10545 | xfree (w->cond_exp); | |
10546 | xfree (w->exp); | |
10547 | xfree (w->exp_string); | |
10548 | xfree (w->exp_string_reparse); | |
10549 | value_free (w->val); | |
10550 | ||
10551 | base_breakpoint_ops.dtor (self); | |
10552 | } | |
10553 | ||
348d480f PA |
10554 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10555 | ||
10556 | static void | |
10557 | re_set_watchpoint (struct breakpoint *b) | |
10558 | { | |
3a5c3e22 PA |
10559 | struct watchpoint *w = (struct watchpoint *) b; |
10560 | ||
348d480f PA |
10561 | /* Watchpoint can be either on expression using entirely global |
10562 | variables, or it can be on local variables. | |
10563 | ||
10564 | Watchpoints of the first kind are never auto-deleted, and even | |
10565 | persist across program restarts. Since they can use variables | |
10566 | from shared libraries, we need to reparse expression as libraries | |
10567 | are loaded and unloaded. | |
10568 | ||
10569 | Watchpoints on local variables can also change meaning as result | |
10570 | of solib event. For example, if a watchpoint uses both a local | |
10571 | and a global variables in expression, it's a local watchpoint, | |
10572 | but unloading of a shared library will make the expression | |
10573 | invalid. This is not a very common use case, but we still | |
10574 | re-evaluate expression, to avoid surprises to the user. | |
10575 | ||
10576 | Note that for local watchpoints, we re-evaluate it only if | |
10577 | watchpoints frame id is still valid. If it's not, it means the | |
10578 | watchpoint is out of scope and will be deleted soon. In fact, | |
10579 | I'm not sure we'll ever be called in this case. | |
10580 | ||
10581 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10582 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10583 | |
3a5c3e22 PA |
10584 | Don't do anything about disabled watchpoints, since they will be |
10585 | reevaluated again when enabled. */ | |
10586 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10587 | } |
10588 | ||
77b06cd7 TJB |
10589 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10590 | ||
10591 | static int | |
10592 | insert_watchpoint (struct bp_location *bl) | |
10593 | { | |
3a5c3e22 PA |
10594 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10595 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10596 | |
10597 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10598 | w->cond_exp); |
77b06cd7 TJB |
10599 | } |
10600 | ||
10601 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10602 | ||
10603 | static int | |
10604 | remove_watchpoint (struct bp_location *bl) | |
10605 | { | |
3a5c3e22 PA |
10606 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10607 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10608 | |
10609 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10610 | w->cond_exp); |
e09342b5 TJB |
10611 | } |
10612 | ||
e09342b5 | 10613 | static int |
348d480f | 10614 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10615 | struct address_space *aspace, CORE_ADDR bp_addr, |
10616 | const struct target_waitstatus *ws) | |
e09342b5 | 10617 | { |
348d480f | 10618 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10619 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10620 | |
348d480f PA |
10621 | /* Continuable hardware watchpoints are treated as non-existent if the |
10622 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10623 | some data address). Otherwise gdb won't stop on a break instruction | |
10624 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10625 | been defined. Also skip watchpoints which we know did not trigger | |
10626 | (did not match the data address). */ | |
10627 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10628 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10629 | return 0; |
9c06b0b4 | 10630 | |
348d480f | 10631 | return 1; |
9c06b0b4 TJB |
10632 | } |
10633 | ||
348d480f PA |
10634 | static void |
10635 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10636 | { |
348d480f | 10637 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10638 | |
348d480f | 10639 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10640 | } |
10641 | ||
10642 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10643 | hardware watchpoints. */ |
9c06b0b4 TJB |
10644 | |
10645 | static int | |
348d480f | 10646 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10647 | { |
3a5c3e22 PA |
10648 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10649 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10650 | |
10651 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10652 | } |
10653 | ||
10654 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10655 | hardware watchpoints. */ |
9c06b0b4 TJB |
10656 | |
10657 | static int | |
348d480f | 10658 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10659 | { |
efa80663 PA |
10660 | /* Read and access watchpoints only work with hardware support. */ |
10661 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10662 | } |
10663 | ||
9c06b0b4 | 10664 | static enum print_stop_action |
348d480f | 10665 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10666 | { |
348d480f PA |
10667 | struct cleanup *old_chain; |
10668 | struct breakpoint *b; | |
f99d8bf4 | 10669 | struct ui_file *stb; |
348d480f | 10670 | enum print_stop_action result; |
3a5c3e22 | 10671 | struct watchpoint *w; |
79a45e25 | 10672 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10673 | |
10674 | gdb_assert (bs->bp_location_at != NULL); | |
10675 | ||
348d480f | 10676 | b = bs->breakpoint_at; |
3a5c3e22 | 10677 | w = (struct watchpoint *) b; |
348d480f | 10678 | |
f99d8bf4 PA |
10679 | stb = mem_fileopen (); |
10680 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10681 | |
10682 | switch (b->type) | |
10683 | { | |
348d480f | 10684 | case bp_watchpoint: |
9c06b0b4 TJB |
10685 | case bp_hardware_watchpoint: |
10686 | annotate_watchpoint (b->number); | |
10687 | if (ui_out_is_mi_like_p (uiout)) | |
10688 | ui_out_field_string | |
10689 | (uiout, "reason", | |
10690 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10691 | mention (b); |
10692 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10693 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10694 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10695 | ui_out_field_stream (uiout, "old", stb); |
10696 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10697 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10698 | ui_out_field_stream (uiout, "new", stb); |
10699 | ui_out_text (uiout, "\n"); | |
10700 | /* More than one watchpoint may have been triggered. */ | |
10701 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10702 | break; |
10703 | ||
10704 | case bp_read_watchpoint: | |
10705 | if (ui_out_is_mi_like_p (uiout)) | |
10706 | ui_out_field_string | |
10707 | (uiout, "reason", | |
10708 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10709 | mention (b); |
10710 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10711 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10712 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10713 | ui_out_field_stream (uiout, "value", stb); |
10714 | ui_out_text (uiout, "\n"); | |
10715 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10716 | break; |
10717 | ||
10718 | case bp_access_watchpoint: | |
348d480f PA |
10719 | if (bs->old_val != NULL) |
10720 | { | |
10721 | annotate_watchpoint (b->number); | |
10722 | if (ui_out_is_mi_like_p (uiout)) | |
10723 | ui_out_field_string | |
10724 | (uiout, "reason", | |
10725 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10726 | mention (b); | |
10727 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10728 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10729 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10730 | ui_out_field_stream (uiout, "old", stb); |
10731 | ui_out_text (uiout, "\nNew value = "); | |
10732 | } | |
10733 | else | |
10734 | { | |
10735 | mention (b); | |
10736 | if (ui_out_is_mi_like_p (uiout)) | |
10737 | ui_out_field_string | |
10738 | (uiout, "reason", | |
10739 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10740 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10741 | ui_out_text (uiout, "\nValue = "); | |
10742 | } | |
f99d8bf4 | 10743 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10744 | ui_out_field_stream (uiout, "new", stb); |
10745 | ui_out_text (uiout, "\n"); | |
10746 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10747 | break; |
10748 | default: | |
348d480f | 10749 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10750 | } |
10751 | ||
348d480f PA |
10752 | do_cleanups (old_chain); |
10753 | return result; | |
10754 | } | |
10755 | ||
10756 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10757 | watchpoints. */ | |
10758 | ||
10759 | static void | |
10760 | print_mention_watchpoint (struct breakpoint *b) | |
10761 | { | |
10762 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10763 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10764 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10765 | |
10766 | switch (b->type) | |
10767 | { | |
10768 | case bp_watchpoint: | |
10769 | ui_out_text (uiout, "Watchpoint "); | |
10770 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10771 | break; | |
10772 | case bp_hardware_watchpoint: | |
10773 | ui_out_text (uiout, "Hardware watchpoint "); | |
10774 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10775 | break; | |
10776 | case bp_read_watchpoint: | |
10777 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10778 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10779 | break; | |
10780 | case bp_access_watchpoint: | |
10781 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10782 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10783 | break; | |
10784 | default: | |
10785 | internal_error (__FILE__, __LINE__, | |
10786 | _("Invalid hardware watchpoint type.")); | |
10787 | } | |
10788 | ||
10789 | ui_out_field_int (uiout, "number", b->number); | |
10790 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10791 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10792 | do_cleanups (ui_out_chain); |
10793 | } | |
10794 | ||
10795 | /* Implement the "print_recreate" breakpoint_ops method for | |
10796 | watchpoints. */ | |
10797 | ||
10798 | static void | |
10799 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10800 | { | |
3a5c3e22 PA |
10801 | struct watchpoint *w = (struct watchpoint *) b; |
10802 | ||
348d480f PA |
10803 | switch (b->type) |
10804 | { | |
10805 | case bp_watchpoint: | |
10806 | case bp_hardware_watchpoint: | |
10807 | fprintf_unfiltered (fp, "watch"); | |
10808 | break; | |
10809 | case bp_read_watchpoint: | |
10810 | fprintf_unfiltered (fp, "rwatch"); | |
10811 | break; | |
10812 | case bp_access_watchpoint: | |
10813 | fprintf_unfiltered (fp, "awatch"); | |
10814 | break; | |
10815 | default: | |
10816 | internal_error (__FILE__, __LINE__, | |
10817 | _("Invalid watchpoint type.")); | |
10818 | } | |
10819 | ||
3a5c3e22 | 10820 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10821 | print_recreate_thread (b, fp); |
348d480f PA |
10822 | } |
10823 | ||
427cd150 TT |
10824 | /* Implement the "explains_signal" breakpoint_ops method for |
10825 | watchpoints. */ | |
10826 | ||
47591c29 | 10827 | static int |
427cd150 TT |
10828 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10829 | { | |
10830 | /* A software watchpoint cannot cause a signal other than | |
10831 | GDB_SIGNAL_TRAP. */ | |
10832 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10833 | return 0; |
427cd150 | 10834 | |
47591c29 | 10835 | return 1; |
427cd150 TT |
10836 | } |
10837 | ||
348d480f PA |
10838 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10839 | ||
2060206e | 10840 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10841 | |
10842 | /* Implement the "insert" breakpoint_ops method for | |
10843 | masked hardware watchpoints. */ | |
10844 | ||
10845 | static int | |
10846 | insert_masked_watchpoint (struct bp_location *bl) | |
10847 | { | |
3a5c3e22 PA |
10848 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10849 | ||
10850 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10851 | bl->watchpoint_type); |
10852 | } | |
10853 | ||
10854 | /* Implement the "remove" breakpoint_ops method for | |
10855 | masked hardware watchpoints. */ | |
10856 | ||
10857 | static int | |
10858 | remove_masked_watchpoint (struct bp_location *bl) | |
10859 | { | |
3a5c3e22 PA |
10860 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10861 | ||
10862 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10863 | bl->watchpoint_type); |
10864 | } | |
10865 | ||
10866 | /* Implement the "resources_needed" breakpoint_ops method for | |
10867 | masked hardware watchpoints. */ | |
10868 | ||
10869 | static int | |
10870 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10871 | { | |
3a5c3e22 PA |
10872 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10873 | ||
10874 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10875 | } |
10876 | ||
10877 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10878 | masked hardware watchpoints. */ | |
10879 | ||
10880 | static int | |
10881 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10882 | { | |
10883 | return 0; | |
10884 | } | |
10885 | ||
10886 | /* Implement the "print_it" breakpoint_ops method for | |
10887 | masked hardware watchpoints. */ | |
10888 | ||
10889 | static enum print_stop_action | |
10890 | print_it_masked_watchpoint (bpstat bs) | |
10891 | { | |
10892 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10893 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10894 | |
10895 | /* Masked watchpoints have only one location. */ | |
10896 | gdb_assert (b->loc && b->loc->next == NULL); | |
10897 | ||
10898 | switch (b->type) | |
10899 | { | |
10900 | case bp_hardware_watchpoint: | |
10901 | annotate_watchpoint (b->number); | |
10902 | if (ui_out_is_mi_like_p (uiout)) | |
10903 | ui_out_field_string | |
10904 | (uiout, "reason", | |
10905 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10906 | break; | |
10907 | ||
10908 | case bp_read_watchpoint: | |
10909 | if (ui_out_is_mi_like_p (uiout)) | |
10910 | ui_out_field_string | |
10911 | (uiout, "reason", | |
10912 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10913 | break; | |
10914 | ||
10915 | case bp_access_watchpoint: | |
10916 | if (ui_out_is_mi_like_p (uiout)) | |
10917 | ui_out_field_string | |
10918 | (uiout, "reason", | |
10919 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10920 | break; | |
10921 | default: | |
10922 | internal_error (__FILE__, __LINE__, | |
10923 | _("Invalid hardware watchpoint type.")); | |
10924 | } | |
10925 | ||
10926 | mention (b); | |
9c06b0b4 TJB |
10927 | ui_out_text (uiout, _("\n\ |
10928 | Check the underlying instruction at PC for the memory\n\ | |
10929 | address and value which triggered this watchpoint.\n")); | |
10930 | ui_out_text (uiout, "\n"); | |
10931 | ||
10932 | /* More than one watchpoint may have been triggered. */ | |
10933 | return PRINT_UNKNOWN; | |
10934 | } | |
10935 | ||
10936 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10937 | masked hardware watchpoints. */ | |
10938 | ||
10939 | static void | |
10940 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10941 | struct ui_out *uiout) | |
10942 | { | |
3a5c3e22 PA |
10943 | struct watchpoint *w = (struct watchpoint *) b; |
10944 | ||
9c06b0b4 TJB |
10945 | /* Masked watchpoints have only one location. */ |
10946 | gdb_assert (b->loc && b->loc->next == NULL); | |
10947 | ||
10948 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10949 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10950 | ui_out_text (uiout, "\n"); |
10951 | } | |
10952 | ||
10953 | /* Implement the "print_mention" breakpoint_ops method for | |
10954 | masked hardware watchpoints. */ | |
10955 | ||
10956 | static void | |
10957 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10958 | { | |
3a5c3e22 | 10959 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10960 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10961 | struct cleanup *ui_out_chain; |
10962 | ||
10963 | switch (b->type) | |
10964 | { | |
10965 | case bp_hardware_watchpoint: | |
10966 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10967 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10968 | break; | |
10969 | case bp_read_watchpoint: | |
10970 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10971 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10972 | break; | |
10973 | case bp_access_watchpoint: | |
10974 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10975 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10976 | break; | |
10977 | default: | |
10978 | internal_error (__FILE__, __LINE__, | |
10979 | _("Invalid hardware watchpoint type.")); | |
10980 | } | |
10981 | ||
10982 | ui_out_field_int (uiout, "number", b->number); | |
10983 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10984 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10985 | do_cleanups (ui_out_chain); |
10986 | } | |
10987 | ||
10988 | /* Implement the "print_recreate" breakpoint_ops method for | |
10989 | masked hardware watchpoints. */ | |
10990 | ||
10991 | static void | |
10992 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10993 | { | |
3a5c3e22 | 10994 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10995 | char tmp[40]; |
10996 | ||
10997 | switch (b->type) | |
10998 | { | |
10999 | case bp_hardware_watchpoint: | |
11000 | fprintf_unfiltered (fp, "watch"); | |
11001 | break; | |
11002 | case bp_read_watchpoint: | |
11003 | fprintf_unfiltered (fp, "rwatch"); | |
11004 | break; | |
11005 | case bp_access_watchpoint: | |
11006 | fprintf_unfiltered (fp, "awatch"); | |
11007 | break; | |
11008 | default: | |
11009 | internal_error (__FILE__, __LINE__, | |
11010 | _("Invalid hardware watchpoint type.")); | |
11011 | } | |
11012 | ||
3a5c3e22 PA |
11013 | sprintf_vma (tmp, w->hw_wp_mask); |
11014 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11015 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11016 | } |
11017 | ||
11018 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11019 | ||
2060206e | 11020 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11021 | |
11022 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11023 | ||
11024 | static int | |
11025 | is_masked_watchpoint (const struct breakpoint *b) | |
11026 | { | |
11027 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11028 | } | |
11029 | ||
53a5351d JM |
11030 | /* accessflag: hw_write: watch write, |
11031 | hw_read: watch read, | |
11032 | hw_access: watch access (read or write) */ | |
c906108c | 11033 | static void |
bbc13ae3 | 11034 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11035 | int just_location, int internal) |
c906108c | 11036 | { |
a9634178 | 11037 | volatile struct gdb_exception e; |
d983da9c | 11038 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11039 | struct expression *exp; |
270140bd | 11040 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11041 | struct value *val, *mark, *result; |
c906108c | 11042 | struct frame_info *frame; |
bbc13ae3 KS |
11043 | const char *exp_start = NULL; |
11044 | const char *exp_end = NULL; | |
11045 | const char *tok, *end_tok; | |
9c06b0b4 | 11046 | int toklen = -1; |
bbc13ae3 KS |
11047 | const char *cond_start = NULL; |
11048 | const char *cond_end = NULL; | |
c906108c | 11049 | enum bptype bp_type; |
37e4754d | 11050 | int thread = -1; |
0cf6dd15 | 11051 | int pc = 0; |
9c06b0b4 TJB |
11052 | /* Flag to indicate whether we are going to use masks for |
11053 | the hardware watchpoint. */ | |
11054 | int use_mask = 0; | |
11055 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11056 | struct watchpoint *w; |
bbc13ae3 KS |
11057 | char *expression; |
11058 | struct cleanup *back_to; | |
c906108c | 11059 | |
37e4754d LM |
11060 | /* Make sure that we actually have parameters to parse. */ |
11061 | if (arg != NULL && arg[0] != '\0') | |
11062 | { | |
bbc13ae3 KS |
11063 | const char *value_start; |
11064 | ||
11065 | exp_end = arg + strlen (arg); | |
37e4754d | 11066 | |
9c06b0b4 TJB |
11067 | /* Look for "parameter value" pairs at the end |
11068 | of the arguments string. */ | |
bbc13ae3 | 11069 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11070 | { |
11071 | /* Skip whitespace at the end of the argument list. */ | |
11072 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11073 | tok--; | |
11074 | ||
11075 | /* Find the beginning of the last token. | |
11076 | This is the value of the parameter. */ | |
11077 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11078 | tok--; | |
11079 | value_start = tok + 1; | |
11080 | ||
11081 | /* Skip whitespace. */ | |
11082 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11083 | tok--; | |
11084 | ||
11085 | end_tok = tok; | |
11086 | ||
11087 | /* Find the beginning of the second to last token. | |
11088 | This is the parameter itself. */ | |
11089 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11090 | tok--; | |
11091 | tok++; | |
11092 | toklen = end_tok - tok + 1; | |
11093 | ||
11094 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11095 | { | |
11096 | /* At this point we've found a "thread" token, which means | |
11097 | the user is trying to set a watchpoint that triggers | |
11098 | only in a specific thread. */ | |
11099 | char *endp; | |
37e4754d | 11100 | |
9c06b0b4 TJB |
11101 | if (thread != -1) |
11102 | error(_("You can specify only one thread.")); | |
37e4754d | 11103 | |
9c06b0b4 TJB |
11104 | /* Extract the thread ID from the next token. */ |
11105 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11106 | |
9c06b0b4 TJB |
11107 | /* Check if the user provided a valid numeric value for the |
11108 | thread ID. */ | |
11109 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11110 | error (_("Invalid thread ID specification %s."), value_start); | |
11111 | ||
11112 | /* Check if the thread actually exists. */ | |
11113 | if (!valid_thread_id (thread)) | |
af4908ba | 11114 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11115 | } |
11116 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11117 | { | |
11118 | /* We've found a "mask" token, which means the user wants to | |
11119 | create a hardware watchpoint that is going to have the mask | |
11120 | facility. */ | |
11121 | struct value *mask_value, *mark; | |
37e4754d | 11122 | |
9c06b0b4 TJB |
11123 | if (use_mask) |
11124 | error(_("You can specify only one mask.")); | |
37e4754d | 11125 | |
9c06b0b4 | 11126 | use_mask = just_location = 1; |
37e4754d | 11127 | |
9c06b0b4 TJB |
11128 | mark = value_mark (); |
11129 | mask_value = parse_to_comma_and_eval (&value_start); | |
11130 | mask = value_as_address (mask_value); | |
11131 | value_free_to_mark (mark); | |
11132 | } | |
11133 | else | |
11134 | /* We didn't recognize what we found. We should stop here. */ | |
11135 | break; | |
37e4754d | 11136 | |
9c06b0b4 TJB |
11137 | /* Truncate the string and get rid of the "parameter value" pair before |
11138 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11139 | exp_end = tok; |
9c06b0b4 | 11140 | } |
37e4754d | 11141 | } |
bbc13ae3 KS |
11142 | else |
11143 | exp_end = arg; | |
37e4754d | 11144 | |
bbc13ae3 KS |
11145 | /* Parse the rest of the arguments. From here on out, everything |
11146 | is in terms of a newly allocated string instead of the original | |
11147 | ARG. */ | |
c906108c | 11148 | innermost_block = NULL; |
bbc13ae3 KS |
11149 | expression = savestring (arg, exp_end - arg); |
11150 | back_to = make_cleanup (xfree, expression); | |
11151 | exp_start = arg = expression; | |
1bb9788d | 11152 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11153 | exp_end = arg; |
fa8a61dc TT |
11154 | /* Remove trailing whitespace from the expression before saving it. |
11155 | This makes the eventual display of the expression string a bit | |
11156 | prettier. */ | |
11157 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11158 | --exp_end; | |
11159 | ||
65d79d4b SDJ |
11160 | /* Checking if the expression is not constant. */ |
11161 | if (watchpoint_exp_is_const (exp)) | |
11162 | { | |
11163 | int len; | |
11164 | ||
11165 | len = exp_end - exp_start; | |
11166 | while (len > 0 && isspace (exp_start[len - 1])) | |
11167 | len--; | |
11168 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11169 | } | |
11170 | ||
c906108c SS |
11171 | exp_valid_block = innermost_block; |
11172 | mark = value_mark (); | |
3a1115a0 | 11173 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11174 | |
11175 | if (just_location) | |
11176 | { | |
9c06b0b4 TJB |
11177 | int ret; |
11178 | ||
06a64a0b | 11179 | exp_valid_block = NULL; |
a1442452 | 11180 | val = value_addr (result); |
06a64a0b TT |
11181 | release_value (val); |
11182 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11183 | |
11184 | if (use_mask) | |
11185 | { | |
11186 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11187 | mask); | |
11188 | if (ret == -1) | |
11189 | error (_("This target does not support masked watchpoints.")); | |
11190 | else if (ret == -2) | |
11191 | error (_("Invalid mask or memory region.")); | |
11192 | } | |
06a64a0b TT |
11193 | } |
11194 | else if (val != NULL) | |
fa4727a6 | 11195 | release_value (val); |
c906108c | 11196 | |
bbc13ae3 KS |
11197 | tok = skip_spaces_const (arg); |
11198 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11199 | |
11200 | toklen = end_tok - tok; | |
11201 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11202 | { | |
2d134ed3 PA |
11203 | struct expression *cond; |
11204 | ||
60e1c644 | 11205 | innermost_block = NULL; |
c906108c | 11206 | tok = cond_start = end_tok + 1; |
1bb9788d | 11207 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11208 | |
11209 | /* The watchpoint expression may not be local, but the condition | |
11210 | may still be. E.g.: `watch global if local > 0'. */ | |
11211 | cond_exp_valid_block = innermost_block; | |
11212 | ||
2d134ed3 | 11213 | xfree (cond); |
c906108c SS |
11214 | cond_end = tok; |
11215 | } | |
11216 | if (*tok) | |
8a3fe4f8 | 11217 | error (_("Junk at end of command.")); |
c906108c | 11218 | |
d983da9c | 11219 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11220 | |
11221 | /* If the expression is "local", then set up a "watchpoint scope" | |
11222 | breakpoint at the point where we've left the scope of the watchpoint | |
11223 | expression. Create the scope breakpoint before the watchpoint, so | |
11224 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11225 | if (exp_valid_block && frame) |
d983da9c | 11226 | { |
edb3359d DJ |
11227 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11228 | { | |
11229 | scope_breakpoint | |
a6d9a66e UW |
11230 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11231 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11232 | bp_watchpoint_scope, |
11233 | &momentary_breakpoint_ops); | |
d983da9c | 11234 | |
edb3359d | 11235 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11236 | |
edb3359d DJ |
11237 | /* Automatically delete the breakpoint when it hits. */ |
11238 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11239 | |
edb3359d DJ |
11240 | /* Only break in the proper frame (help with recursion). */ |
11241 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11242 | |
edb3359d | 11243 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11244 | scope_breakpoint->loc->gdbarch |
11245 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11246 | scope_breakpoint->loc->requested_address |
11247 | = frame_unwind_caller_pc (frame); | |
11248 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11249 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11250 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11251 | scope_breakpoint->type); |
11252 | } | |
d983da9c DJ |
11253 | } |
11254 | ||
e8369a73 AB |
11255 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11256 | watchpoints here even if hardware watchpoints are turned off, a call | |
11257 | to update_watchpoint later in this function will cause the type to | |
11258 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11259 | ||
11260 | if (accessflag == hw_read) | |
11261 | bp_type = bp_read_watchpoint; | |
11262 | else if (accessflag == hw_access) | |
11263 | bp_type = bp_access_watchpoint; | |
11264 | else | |
11265 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11266 | |
11267 | w = XCNEW (struct watchpoint); | |
11268 | b = &w->base; | |
348d480f | 11269 | if (use_mask) |
3a5c3e22 PA |
11270 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11271 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11272 | else |
3a5c3e22 PA |
11273 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11274 | &watchpoint_breakpoint_ops); | |
37e4754d | 11275 | b->thread = thread; |
b5de0fa7 | 11276 | b->disposition = disp_donttouch; |
348d480f | 11277 | b->pspace = current_program_space; |
3a5c3e22 PA |
11278 | w->exp = exp; |
11279 | w->exp_valid_block = exp_valid_block; | |
11280 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11281 | if (just_location) |
11282 | { | |
11283 | struct type *t = value_type (val); | |
11284 | CORE_ADDR addr = value_as_address (val); | |
11285 | char *name; | |
11286 | ||
11287 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11288 | name = type_to_string (t); | |
11289 | ||
3a5c3e22 | 11290 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11291 | core_addr_to_string (addr)); |
06a64a0b TT |
11292 | xfree (name); |
11293 | ||
3a5c3e22 | 11294 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11295 | (int) (exp_end - exp_start), exp_start); |
11296 | ||
06a64a0b TT |
11297 | /* The above expression is in C. */ |
11298 | b->language = language_c; | |
11299 | } | |
11300 | else | |
3a5c3e22 | 11301 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11302 | |
11303 | if (use_mask) | |
11304 | { | |
3a5c3e22 | 11305 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11306 | } |
11307 | else | |
11308 | { | |
3a5c3e22 PA |
11309 | w->val = val; |
11310 | w->val_valid = 1; | |
9c06b0b4 | 11311 | } |
77b06cd7 | 11312 | |
c906108c SS |
11313 | if (cond_start) |
11314 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11315 | else | |
11316 | b->cond_string = 0; | |
c5aa993b | 11317 | |
c906108c | 11318 | if (frame) |
f6bc2008 | 11319 | { |
3a5c3e22 PA |
11320 | w->watchpoint_frame = get_frame_id (frame); |
11321 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11322 | } |
c906108c | 11323 | else |
f6bc2008 | 11324 | { |
3a5c3e22 PA |
11325 | w->watchpoint_frame = null_frame_id; |
11326 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11327 | } |
c906108c | 11328 | |
d983da9c | 11329 | if (scope_breakpoint != NULL) |
c906108c | 11330 | { |
d983da9c DJ |
11331 | /* The scope breakpoint is related to the watchpoint. We will |
11332 | need to act on them together. */ | |
11333 | b->related_breakpoint = scope_breakpoint; | |
11334 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11335 | } |
d983da9c | 11336 | |
06a64a0b TT |
11337 | if (!just_location) |
11338 | value_free_to_mark (mark); | |
2d134ed3 | 11339 | |
a9634178 TJB |
11340 | TRY_CATCH (e, RETURN_MASK_ALL) |
11341 | { | |
11342 | /* Finally update the new watchpoint. This creates the locations | |
11343 | that should be inserted. */ | |
3a5c3e22 | 11344 | update_watchpoint (w, 1); |
a9634178 TJB |
11345 | } |
11346 | if (e.reason < 0) | |
11347 | { | |
11348 | delete_breakpoint (b); | |
11349 | throw_exception (e); | |
11350 | } | |
11351 | ||
3ea46bff | 11352 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11353 | do_cleanups (back_to); |
c906108c SS |
11354 | } |
11355 | ||
e09342b5 | 11356 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11357 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11358 | |
c906108c | 11359 | static int |
a9634178 | 11360 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11361 | { |
11362 | int found_memory_cnt = 0; | |
2e70b7b9 | 11363 | struct value *head = v; |
c906108c SS |
11364 | |
11365 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11366 | if (!can_use_hw_watchpoints) |
c906108c | 11367 | return 0; |
c5aa993b | 11368 | |
5c44784c JM |
11369 | /* Make sure that the value of the expression depends only upon |
11370 | memory contents, and values computed from them within GDB. If we | |
11371 | find any register references or function calls, we can't use a | |
11372 | hardware watchpoint. | |
11373 | ||
11374 | The idea here is that evaluating an expression generates a series | |
11375 | of values, one holding the value of every subexpression. (The | |
11376 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11377 | a*b+c.) GDB's values hold almost enough information to establish | |
11378 | the criteria given above --- they identify memory lvalues, | |
11379 | register lvalues, computed values, etcetera. So we can evaluate | |
11380 | the expression, and then scan the chain of values that leaves | |
11381 | behind to decide whether we can detect any possible change to the | |
11382 | expression's final value using only hardware watchpoints. | |
11383 | ||
11384 | However, I don't think that the values returned by inferior | |
11385 | function calls are special in any way. So this function may not | |
11386 | notice that an expression involving an inferior function call | |
11387 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11388 | for (; v; v = value_next (v)) |
c906108c | 11389 | { |
5c44784c | 11390 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11391 | { |
8464be76 DJ |
11392 | if (v != head && value_lazy (v)) |
11393 | /* A lazy memory lvalue in the chain is one that GDB never | |
11394 | needed to fetch; we either just used its address (e.g., | |
11395 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11396 | in `a,b'). This doesn't apply to HEAD; if that is | |
11397 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11398 | ; |
53a5351d | 11399 | else |
5c44784c JM |
11400 | { |
11401 | /* Ahh, memory we actually used! Check if we can cover | |
11402 | it with hardware watchpoints. */ | |
df407dfe | 11403 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11404 | |
11405 | /* We only watch structs and arrays if user asked for it | |
11406 | explicitly, never if they just happen to appear in a | |
11407 | middle of some value chain. */ | |
11408 | if (v == head | |
11409 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11410 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11411 | { | |
42ae5230 | 11412 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11413 | int len; |
11414 | int num_regs; | |
11415 | ||
a9634178 | 11416 | len = (target_exact_watchpoints |
e09342b5 TJB |
11417 | && is_scalar_type_recursive (vtype))? |
11418 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11419 | |
e09342b5 TJB |
11420 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11421 | if (!num_regs) | |
2e70b7b9 MS |
11422 | return 0; |
11423 | else | |
e09342b5 | 11424 | found_memory_cnt += num_regs; |
2e70b7b9 | 11425 | } |
5c44784c | 11426 | } |
c5aa993b | 11427 | } |
5086187c AC |
11428 | else if (VALUE_LVAL (v) != not_lval |
11429 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11430 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11431 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11432 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11433 | } |
11434 | ||
11435 | /* The expression itself looks suitable for using a hardware | |
11436 | watchpoint, but give the target machine a chance to reject it. */ | |
11437 | return found_memory_cnt; | |
11438 | } | |
11439 | ||
8b93c638 | 11440 | void |
84f4c1fe | 11441 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11442 | { |
84f4c1fe | 11443 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11444 | } |
11445 | ||
06a64a0b TT |
11446 | /* A helper function that looks for the "-location" argument and then |
11447 | calls watch_command_1. */ | |
11448 | ||
11449 | static void | |
11450 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11451 | { | |
11452 | int just_location = 0; | |
11453 | ||
11454 | if (arg | |
11455 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11456 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11457 | { | |
e9cafbcc | 11458 | arg = skip_spaces (arg); |
06a64a0b TT |
11459 | just_location = 1; |
11460 | } | |
11461 | ||
84f4c1fe | 11462 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11463 | } |
8926118c | 11464 | |
c5aa993b | 11465 | static void |
fba45db2 | 11466 | watch_command (char *arg, int from_tty) |
c906108c | 11467 | { |
06a64a0b | 11468 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11469 | } |
11470 | ||
8b93c638 | 11471 | void |
84f4c1fe | 11472 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11473 | { |
84f4c1fe | 11474 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11475 | } |
8926118c | 11476 | |
c5aa993b | 11477 | static void |
fba45db2 | 11478 | rwatch_command (char *arg, int from_tty) |
c906108c | 11479 | { |
06a64a0b | 11480 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11481 | } |
11482 | ||
8b93c638 | 11483 | void |
84f4c1fe | 11484 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11485 | { |
84f4c1fe | 11486 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11487 | } |
8926118c | 11488 | |
c5aa993b | 11489 | static void |
fba45db2 | 11490 | awatch_command (char *arg, int from_tty) |
c906108c | 11491 | { |
06a64a0b | 11492 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11493 | } |
c906108c | 11494 | \f |
c5aa993b | 11495 | |
43ff13b4 | 11496 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11497 | because it uses the mechanisms of breakpoints. */ |
11498 | ||
bfec99b2 PA |
11499 | struct until_break_command_continuation_args |
11500 | { | |
11501 | struct breakpoint *breakpoint; | |
11502 | struct breakpoint *breakpoint2; | |
186c406b | 11503 | int thread_num; |
bfec99b2 PA |
11504 | }; |
11505 | ||
43ff13b4 | 11506 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11507 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11508 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11509 | command. */ |
c2c6d25f | 11510 | static void |
fa4cd53f | 11511 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11512 | { |
bfec99b2 PA |
11513 | struct until_break_command_continuation_args *a = arg; |
11514 | ||
11515 | delete_breakpoint (a->breakpoint); | |
11516 | if (a->breakpoint2) | |
11517 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11518 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11519 | } |
11520 | ||
c906108c | 11521 | void |
ae66c1fc | 11522 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11523 | { |
11524 | struct symtabs_and_lines sals; | |
11525 | struct symtab_and_line sal; | |
8556afb4 PA |
11526 | struct frame_info *frame; |
11527 | struct gdbarch *frame_gdbarch; | |
11528 | struct frame_id stack_frame_id; | |
11529 | struct frame_id caller_frame_id; | |
c906108c | 11530 | struct breakpoint *breakpoint; |
f107f563 | 11531 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11532 | struct cleanup *old_chain; |
186c406b TT |
11533 | int thread; |
11534 | struct thread_info *tp; | |
c906108c SS |
11535 | |
11536 | clear_proceed_status (); | |
11537 | ||
11538 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11539 | this function. */ |
c5aa993b | 11540 | |
1bfeeb0f | 11541 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11542 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11543 | get_last_displayed_symtab (), |
f8eba3c6 | 11544 | get_last_displayed_line ()); |
c906108c | 11545 | else |
f8eba3c6 TT |
11546 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11547 | (struct symtab *) NULL, 0); | |
c5aa993b | 11548 | |
c906108c | 11549 | if (sals.nelts != 1) |
8a3fe4f8 | 11550 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11551 | |
c906108c | 11552 | sal = sals.sals[0]; |
4a64f543 | 11553 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11554 | |
c906108c | 11555 | if (*arg) |
8a3fe4f8 | 11556 | error (_("Junk at end of arguments.")); |
c5aa993b | 11557 | |
c906108c | 11558 | resolve_sal_pc (&sal); |
c5aa993b | 11559 | |
186c406b TT |
11560 | tp = inferior_thread (); |
11561 | thread = tp->num; | |
11562 | ||
883bc8d1 PA |
11563 | old_chain = make_cleanup (null_cleanup, NULL); |
11564 | ||
8556afb4 PA |
11565 | /* Note linespec handling above invalidates the frame chain. |
11566 | Installing a breakpoint also invalidates the frame chain (as it | |
11567 | may need to switch threads), so do any frame handling before | |
11568 | that. */ | |
11569 | ||
11570 | frame = get_selected_frame (NULL); | |
11571 | frame_gdbarch = get_frame_arch (frame); | |
11572 | stack_frame_id = get_stack_frame_id (frame); | |
11573 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11574 | |
ae66c1fc EZ |
11575 | /* Keep within the current frame, or in frames called by the current |
11576 | one. */ | |
edb3359d | 11577 | |
883bc8d1 | 11578 | if (frame_id_p (caller_frame_id)) |
c906108c | 11579 | { |
883bc8d1 PA |
11580 | struct symtab_and_line sal2; |
11581 | ||
11582 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11583 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11584 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11585 | sal2, |
11586 | caller_frame_id, | |
f107f563 VP |
11587 | bp_until); |
11588 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11589 | |
883bc8d1 | 11590 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11591 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11592 | } |
c5aa993b | 11593 | |
c70a6932 JK |
11594 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11595 | frame = NULL; | |
11596 | ||
883bc8d1 PA |
11597 | if (anywhere) |
11598 | /* If the user told us to continue until a specified location, | |
11599 | we don't specify a frame at which we need to stop. */ | |
11600 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11601 | null_frame_id, bp_until); | |
11602 | else | |
11603 | /* Otherwise, specify the selected frame, because we want to stop | |
11604 | only at the very same frame. */ | |
11605 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11606 | stack_frame_id, bp_until); | |
11607 | make_cleanup_delete_breakpoint (breakpoint); | |
11608 | ||
a493e3e2 | 11609 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11610 | |
4a64f543 MS |
11611 | /* If we are running asynchronously, and proceed call above has |
11612 | actually managed to start the target, arrange for breakpoints to | |
11613 | be deleted when the target stops. Otherwise, we're already | |
11614 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11615 | |
8ea051c5 | 11616 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11617 | { |
bfec99b2 PA |
11618 | struct until_break_command_continuation_args *args; |
11619 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11620 | |
bfec99b2 PA |
11621 | args->breakpoint = breakpoint; |
11622 | args->breakpoint2 = breakpoint2; | |
186c406b | 11623 | args->thread_num = thread; |
f107f563 VP |
11624 | |
11625 | discard_cleanups (old_chain); | |
95e54da7 PA |
11626 | add_continuation (inferior_thread (), |
11627 | until_break_command_continuation, args, | |
604ead4a | 11628 | xfree); |
f107f563 VP |
11629 | } |
11630 | else | |
c5aa993b | 11631 | do_cleanups (old_chain); |
c906108c | 11632 | } |
ae66c1fc | 11633 | |
c906108c SS |
11634 | /* This function attempts to parse an optional "if <cond>" clause |
11635 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11636 | |
c906108c SS |
11637 | Else, it returns a pointer to the condition string. (It does not |
11638 | attempt to evaluate the string against a particular block.) And, | |
11639 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11640 | if clause in the arg string. */ |
53a5351d | 11641 | |
916703c0 | 11642 | char * |
fba45db2 | 11643 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11644 | { |
c5aa993b JM |
11645 | char *cond_string; |
11646 | ||
11647 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11648 | return NULL; |
c5aa993b | 11649 | |
4a64f543 | 11650 | /* Skip the "if" keyword. */ |
c906108c | 11651 | (*arg) += 2; |
c5aa993b | 11652 | |
c906108c | 11653 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11654 | condition string. */ |
e9cafbcc | 11655 | *arg = skip_spaces (*arg); |
c906108c | 11656 | cond_string = *arg; |
c5aa993b | 11657 | |
4a64f543 MS |
11658 | /* Assume that the condition occupies the remainder of the arg |
11659 | string. */ | |
c906108c | 11660 | (*arg) += strlen (cond_string); |
c5aa993b | 11661 | |
c906108c SS |
11662 | return cond_string; |
11663 | } | |
c5aa993b | 11664 | |
c906108c SS |
11665 | /* Commands to deal with catching events, such as signals, exceptions, |
11666 | process start/exit, etc. */ | |
c5aa993b JM |
11667 | |
11668 | typedef enum | |
11669 | { | |
44feb3ce TT |
11670 | catch_fork_temporary, catch_vfork_temporary, |
11671 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11672 | } |
11673 | catch_fork_kind; | |
11674 | ||
c906108c | 11675 | static void |
cc59ec59 MS |
11676 | catch_fork_command_1 (char *arg, int from_tty, |
11677 | struct cmd_list_element *command) | |
c906108c | 11678 | { |
a6d9a66e | 11679 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11680 | char *cond_string = NULL; |
44feb3ce TT |
11681 | catch_fork_kind fork_kind; |
11682 | int tempflag; | |
11683 | ||
11684 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11685 | tempflag = (fork_kind == catch_fork_temporary | |
11686 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11687 | |
44feb3ce TT |
11688 | if (!arg) |
11689 | arg = ""; | |
e9cafbcc | 11690 | arg = skip_spaces (arg); |
c5aa993b | 11691 | |
c906108c | 11692 | /* The allowed syntax is: |
c5aa993b JM |
11693 | catch [v]fork |
11694 | catch [v]fork if <cond> | |
11695 | ||
4a64f543 | 11696 | First, check if there's an if clause. */ |
c906108c | 11697 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11698 | |
c906108c | 11699 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11700 | error (_("Junk at end of arguments.")); |
c5aa993b | 11701 | |
c906108c | 11702 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11703 | and enable reporting of such events. */ |
c5aa993b JM |
11704 | switch (fork_kind) |
11705 | { | |
44feb3ce TT |
11706 | case catch_fork_temporary: |
11707 | case catch_fork_permanent: | |
a6d9a66e | 11708 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11709 | &catch_fork_breakpoint_ops); |
c906108c | 11710 | break; |
44feb3ce TT |
11711 | case catch_vfork_temporary: |
11712 | case catch_vfork_permanent: | |
a6d9a66e | 11713 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11714 | &catch_vfork_breakpoint_ops); |
c906108c | 11715 | break; |
c5aa993b | 11716 | default: |
8a3fe4f8 | 11717 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11718 | break; |
c5aa993b | 11719 | } |
c906108c SS |
11720 | } |
11721 | ||
11722 | static void | |
cc59ec59 MS |
11723 | catch_exec_command_1 (char *arg, int from_tty, |
11724 | struct cmd_list_element *command) | |
c906108c | 11725 | { |
b4d90040 | 11726 | struct exec_catchpoint *c; |
a6d9a66e | 11727 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11728 | int tempflag; |
c5aa993b | 11729 | char *cond_string = NULL; |
c906108c | 11730 | |
44feb3ce TT |
11731 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11732 | ||
11733 | if (!arg) | |
11734 | arg = ""; | |
e9cafbcc | 11735 | arg = skip_spaces (arg); |
c906108c SS |
11736 | |
11737 | /* The allowed syntax is: | |
c5aa993b JM |
11738 | catch exec |
11739 | catch exec if <cond> | |
c906108c | 11740 | |
4a64f543 | 11741 | First, check if there's an if clause. */ |
c906108c SS |
11742 | cond_string = ep_parse_optional_if_clause (&arg); |
11743 | ||
11744 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11745 | error (_("Junk at end of arguments.")); |
c906108c | 11746 | |
b4d90040 PA |
11747 | c = XNEW (struct exec_catchpoint); |
11748 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11749 | &catch_exec_breakpoint_ops); | |
11750 | c->exec_pathname = NULL; | |
11751 | ||
3ea46bff | 11752 | install_breakpoint (0, &c->base, 1); |
c906108c | 11753 | } |
c5aa993b | 11754 | |
9ac4176b | 11755 | void |
28010a5d PA |
11756 | init_ada_exception_breakpoint (struct breakpoint *b, |
11757 | struct gdbarch *gdbarch, | |
11758 | struct symtab_and_line sal, | |
11759 | char *addr_string, | |
c0a91b2b | 11760 | const struct breakpoint_ops *ops, |
28010a5d | 11761 | int tempflag, |
349774ef | 11762 | int enabled, |
28010a5d | 11763 | int from_tty) |
f7f9143b | 11764 | { |
f7f9143b JB |
11765 | if (from_tty) |
11766 | { | |
5af949e3 UW |
11767 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11768 | if (!loc_gdbarch) | |
11769 | loc_gdbarch = gdbarch; | |
11770 | ||
6c95b8df PA |
11771 | describe_other_breakpoints (loc_gdbarch, |
11772 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11773 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11774 | version for exception catchpoints, because two catchpoints | |
11775 | used for different exception names will use the same address. | |
11776 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11777 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11778 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11779 | the user what type of catchpoint it is. The above is good |
11780 | enough for now, though. */ | |
11781 | } | |
11782 | ||
28010a5d | 11783 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11784 | |
349774ef | 11785 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11786 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11787 | b->addr_string = addr_string; |
11788 | b->language = language_ada; | |
f7f9143b JB |
11789 | } |
11790 | ||
a96d9b2e SDJ |
11791 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11792 | filter list, or NULL if no filtering is required. */ | |
11793 | static VEC(int) * | |
11794 | catch_syscall_split_args (char *arg) | |
11795 | { | |
11796 | VEC(int) *result = NULL; | |
29d0bb3d | 11797 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11798 | |
11799 | while (*arg != '\0') | |
11800 | { | |
11801 | int i, syscall_number; | |
11802 | char *endptr; | |
11803 | char cur_name[128]; | |
11804 | struct syscall s; | |
11805 | ||
11806 | /* Skip whitespace. */ | |
529480d0 | 11807 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11808 | |
11809 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11810 | cur_name[i] = arg[i]; | |
11811 | cur_name[i] = '\0'; | |
11812 | arg += i; | |
11813 | ||
11814 | /* Check if the user provided a syscall name or a number. */ | |
11815 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11816 | if (*endptr == '\0') | |
bccd0dd2 | 11817 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11818 | else |
11819 | { | |
11820 | /* We have a name. Let's check if it's valid and convert it | |
11821 | to a number. */ | |
11822 | get_syscall_by_name (cur_name, &s); | |
11823 | ||
11824 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11825 | /* Here we have to issue an error instead of a warning, |
11826 | because GDB cannot do anything useful if there's no | |
11827 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11828 | error (_("Unknown syscall name '%s'."), cur_name); |
11829 | } | |
11830 | ||
11831 | /* Ok, it's valid. */ | |
11832 | VEC_safe_push (int, result, s.number); | |
11833 | } | |
11834 | ||
11835 | discard_cleanups (cleanup); | |
11836 | return result; | |
11837 | } | |
11838 | ||
11839 | /* Implement the "catch syscall" command. */ | |
11840 | ||
11841 | static void | |
cc59ec59 MS |
11842 | catch_syscall_command_1 (char *arg, int from_tty, |
11843 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11844 | { |
11845 | int tempflag; | |
11846 | VEC(int) *filter; | |
11847 | struct syscall s; | |
11848 | struct gdbarch *gdbarch = get_current_arch (); | |
11849 | ||
11850 | /* Checking if the feature if supported. */ | |
11851 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11852 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11853 | this architecture yet.")); |
a96d9b2e SDJ |
11854 | |
11855 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11856 | ||
e9cafbcc | 11857 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11858 | |
11859 | /* We need to do this first "dummy" translation in order | |
11860 | to get the syscall XML file loaded or, most important, | |
11861 | to display a warning to the user if there's no XML file | |
11862 | for his/her architecture. */ | |
11863 | get_syscall_by_number (0, &s); | |
11864 | ||
11865 | /* The allowed syntax is: | |
11866 | catch syscall | |
11867 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11868 | ||
11869 | Let's check if there's a syscall name. */ | |
11870 | ||
11871 | if (arg != NULL) | |
11872 | filter = catch_syscall_split_args (arg); | |
11873 | else | |
11874 | filter = NULL; | |
11875 | ||
11876 | create_syscall_event_catchpoint (tempflag, filter, | |
11877 | &catch_syscall_breakpoint_ops); | |
11878 | } | |
11879 | ||
c906108c | 11880 | static void |
fba45db2 | 11881 | catch_command (char *arg, int from_tty) |
c906108c | 11882 | { |
44feb3ce | 11883 | error (_("Catch requires an event name.")); |
c906108c SS |
11884 | } |
11885 | \f | |
11886 | ||
11887 | static void | |
fba45db2 | 11888 | tcatch_command (char *arg, int from_tty) |
c906108c | 11889 | { |
44feb3ce | 11890 | error (_("Catch requires an event name.")); |
c906108c SS |
11891 | } |
11892 | ||
8a2c437b TT |
11893 | /* A qsort comparison function that sorts breakpoints in order. */ |
11894 | ||
11895 | static int | |
11896 | compare_breakpoints (const void *a, const void *b) | |
11897 | { | |
11898 | const breakpoint_p *ba = a; | |
11899 | uintptr_t ua = (uintptr_t) *ba; | |
11900 | const breakpoint_p *bb = b; | |
11901 | uintptr_t ub = (uintptr_t) *bb; | |
11902 | ||
11903 | if ((*ba)->number < (*bb)->number) | |
11904 | return -1; | |
11905 | else if ((*ba)->number > (*bb)->number) | |
11906 | return 1; | |
11907 | ||
11908 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11909 | the number 0. */ | |
11910 | if (ua < ub) | |
11911 | return -1; | |
94b0e70d | 11912 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11913 | } |
11914 | ||
80f8a6eb | 11915 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11916 | |
11917 | static void | |
fba45db2 | 11918 | clear_command (char *arg, int from_tty) |
c906108c | 11919 | { |
8a2c437b | 11920 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11921 | VEC(breakpoint_p) *found = 0; |
11922 | int ix; | |
c906108c SS |
11923 | int default_match; |
11924 | struct symtabs_and_lines sals; | |
11925 | struct symtab_and_line sal; | |
c906108c | 11926 | int i; |
8a2c437b | 11927 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11928 | |
11929 | if (arg) | |
11930 | { | |
39cf75f7 DE |
11931 | sals = decode_line_with_current_source (arg, |
11932 | (DECODE_LINE_FUNFIRSTLINE | |
11933 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11934 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11935 | default_match = 0; |
11936 | } | |
11937 | else | |
11938 | { | |
c5aa993b | 11939 | sals.sals = (struct symtab_and_line *) |
c906108c | 11940 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11941 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11942 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11943 | |
11944 | /* Set sal's line, symtab, pc, and pspace to the values | |
11945 | corresponding to the last call to print_frame_info. If the | |
11946 | codepoint is not valid, this will set all the fields to 0. */ | |
11947 | get_last_displayed_sal (&sal); | |
c906108c | 11948 | if (sal.symtab == 0) |
8a3fe4f8 | 11949 | error (_("No source file specified.")); |
c906108c SS |
11950 | |
11951 | sals.sals[0] = sal; | |
11952 | sals.nelts = 1; | |
11953 | ||
11954 | default_match = 1; | |
11955 | } | |
11956 | ||
4a64f543 MS |
11957 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11958 | seems, because all existing breakpoints typically have both | |
11959 | file/line and pc set. So, if clear is given file/line, we can | |
11960 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11961 | |
11962 | We only support clearing given the address explicitly | |
11963 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11964 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11965 | due to optimization, all in one block. |
4a64f543 MS |
11966 | |
11967 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11968 | PC corresponding to the same file:line, the breakpoint won't |
11969 | be cleared. We probably can still clear the breakpoint, but | |
11970 | since the other PC value is never presented to user, user | |
11971 | can only find it by guessing, and it does not seem important | |
11972 | to support that. */ | |
11973 | ||
4a64f543 MS |
11974 | /* For each line spec given, delete bps which correspond to it. Do |
11975 | it in two passes, solely to preserve the current behavior that | |
11976 | from_tty is forced true if we delete more than one | |
11977 | breakpoint. */ | |
c906108c | 11978 | |
80f8a6eb | 11979 | found = NULL; |
8a2c437b | 11980 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11981 | for (i = 0; i < sals.nelts; i++) |
11982 | { | |
05cba821 JK |
11983 | const char *sal_fullname; |
11984 | ||
c906108c | 11985 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11986 | If line given (pc == 0), clear all bpts on specified line. |
11987 | If defaulting, clear all bpts on default line | |
c906108c | 11988 | or at default pc. |
c5aa993b JM |
11989 | |
11990 | defaulting sal.pc != 0 tests to do | |
11991 | ||
11992 | 0 1 pc | |
11993 | 1 1 pc _and_ line | |
11994 | 0 0 line | |
11995 | 1 0 <can't happen> */ | |
c906108c SS |
11996 | |
11997 | sal = sals.sals[i]; | |
05cba821 JK |
11998 | sal_fullname = (sal.symtab == NULL |
11999 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12000 | |
4a64f543 | 12001 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12002 | ALL_BREAKPOINTS (b) |
c5aa993b | 12003 | { |
0d381245 | 12004 | int match = 0; |
4a64f543 | 12005 | /* Are we going to delete b? */ |
cc60f2e3 | 12006 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12007 | { |
12008 | struct bp_location *loc = b->loc; | |
12009 | for (; loc; loc = loc->next) | |
12010 | { | |
f8eba3c6 TT |
12011 | /* If the user specified file:line, don't allow a PC |
12012 | match. This matches historical gdb behavior. */ | |
12013 | int pc_match = (!sal.explicit_line | |
12014 | && sal.pc | |
12015 | && (loc->pspace == sal.pspace) | |
12016 | && (loc->address == sal.pc) | |
12017 | && (!section_is_overlay (loc->section) | |
12018 | || loc->section == sal.section)); | |
4aac40c8 TT |
12019 | int line_match = 0; |
12020 | ||
12021 | if ((default_match || sal.explicit_line) | |
2f202fde | 12022 | && loc->symtab != NULL |
05cba821 | 12023 | && sal_fullname != NULL |
4aac40c8 | 12024 | && sal.pspace == loc->pspace |
05cba821 JK |
12025 | && loc->line_number == sal.line |
12026 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12027 | sal_fullname) == 0) | |
12028 | line_match = 1; | |
4aac40c8 | 12029 | |
0d381245 VP |
12030 | if (pc_match || line_match) |
12031 | { | |
12032 | match = 1; | |
12033 | break; | |
12034 | } | |
12035 | } | |
12036 | } | |
12037 | ||
12038 | if (match) | |
d6e956e5 | 12039 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12040 | } |
80f8a6eb | 12041 | } |
8a2c437b | 12042 | |
80f8a6eb | 12043 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12044 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12045 | { |
12046 | if (arg) | |
8a3fe4f8 | 12047 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12048 | else |
8a3fe4f8 | 12049 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12050 | } |
c906108c | 12051 | |
8a2c437b TT |
12052 | /* Remove duplicates from the vec. */ |
12053 | qsort (VEC_address (breakpoint_p, found), | |
12054 | VEC_length (breakpoint_p, found), | |
12055 | sizeof (breakpoint_p), | |
12056 | compare_breakpoints); | |
12057 | prev = VEC_index (breakpoint_p, found, 0); | |
12058 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12059 | { | |
12060 | if (b == prev) | |
12061 | { | |
12062 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12063 | --ix; | |
12064 | } | |
12065 | } | |
12066 | ||
d6e956e5 | 12067 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12068 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12069 | if (from_tty) |
a3f17187 | 12070 | { |
d6e956e5 | 12071 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12072 | printf_unfiltered (_("Deleted breakpoint ")); |
12073 | else | |
12074 | printf_unfiltered (_("Deleted breakpoints ")); | |
12075 | } | |
d6e956e5 VP |
12076 | |
12077 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12078 | { |
c5aa993b | 12079 | if (from_tty) |
d6e956e5 VP |
12080 | printf_unfiltered ("%d ", b->number); |
12081 | delete_breakpoint (b); | |
c906108c | 12082 | } |
80f8a6eb MS |
12083 | if (from_tty) |
12084 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12085 | |
12086 | do_cleanups (cleanups); | |
c906108c SS |
12087 | } |
12088 | \f | |
12089 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12090 | all breakpoints that are marked for deletion, whether hit or not. | |
12091 | This is called after any breakpoint is hit, or after errors. */ | |
12092 | ||
12093 | void | |
fba45db2 | 12094 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12095 | { |
35df4500 | 12096 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12097 | |
12098 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12099 | if (bs->breakpoint_at |
12100 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12101 | && bs->stop) |
f431efe5 | 12102 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12103 | |
35df4500 | 12104 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12105 | { |
b5de0fa7 | 12106 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12107 | delete_breakpoint (b); |
12108 | } | |
c906108c SS |
12109 | } |
12110 | ||
4a64f543 MS |
12111 | /* A comparison function for bp_location AP and BP being interfaced to |
12112 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12113 | does breakpoint_address_is_meaningful say for its OWNER), | |
12114 | secondarily by ordering first bp_permanent OWNERed elements and | |
12115 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12116 | qsort being an unstable algorithm. */ |
876fa593 JK |
12117 | |
12118 | static int | |
494cfb0f | 12119 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12120 | { |
494cfb0f JK |
12121 | struct bp_location *a = *(void **) ap; |
12122 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12123 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12124 | int a_perm = a->owner->enable_state == bp_permanent; |
12125 | int b_perm = b->owner->enable_state == bp_permanent; | |
12126 | ||
12127 | if (a->address != b->address) | |
12128 | return (a->address > b->address) - (a->address < b->address); | |
12129 | ||
dea2aa5f LM |
12130 | /* Sort locations at the same address by their pspace number, keeping |
12131 | locations of the same inferior (in a multi-inferior environment) | |
12132 | grouped. */ | |
12133 | ||
12134 | if (a->pspace->num != b->pspace->num) | |
12135 | return ((a->pspace->num > b->pspace->num) | |
12136 | - (a->pspace->num < b->pspace->num)); | |
12137 | ||
876fa593 JK |
12138 | /* Sort permanent breakpoints first. */ |
12139 | if (a_perm != b_perm) | |
12140 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12141 | ||
c56a97f9 JK |
12142 | /* Make the internal GDB representation stable across GDB runs |
12143 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12144 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12145 | |
12146 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12147 | return ((a->owner->number > b->owner->number) |
12148 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12149 | |
12150 | return (a > b) - (a < b); | |
12151 | } | |
12152 | ||
876fa593 | 12153 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12154 | bp_location_shadow_len_after_address_max according to the current |
12155 | content of the bp_location array. */ | |
f7545552 TT |
12156 | |
12157 | static void | |
876fa593 | 12158 | bp_location_target_extensions_update (void) |
f7545552 | 12159 | { |
876fa593 JK |
12160 | struct bp_location *bl, **blp_tmp; |
12161 | ||
12162 | bp_location_placed_address_before_address_max = 0; | |
12163 | bp_location_shadow_len_after_address_max = 0; | |
12164 | ||
12165 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12166 | { | |
12167 | CORE_ADDR start, end, addr; | |
12168 | ||
12169 | if (!bp_location_has_shadow (bl)) | |
12170 | continue; | |
12171 | ||
12172 | start = bl->target_info.placed_address; | |
12173 | end = start + bl->target_info.shadow_len; | |
12174 | ||
12175 | gdb_assert (bl->address >= start); | |
12176 | addr = bl->address - start; | |
12177 | if (addr > bp_location_placed_address_before_address_max) | |
12178 | bp_location_placed_address_before_address_max = addr; | |
12179 | ||
12180 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12181 | ||
12182 | gdb_assert (bl->address < end); | |
12183 | addr = end - bl->address; | |
12184 | if (addr > bp_location_shadow_len_after_address_max) | |
12185 | bp_location_shadow_len_after_address_max = addr; | |
12186 | } | |
f7545552 TT |
12187 | } |
12188 | ||
1e4d1764 YQ |
12189 | /* Download tracepoint locations if they haven't been. */ |
12190 | ||
12191 | static void | |
12192 | download_tracepoint_locations (void) | |
12193 | { | |
7ed2c994 | 12194 | struct breakpoint *b; |
1e4d1764 YQ |
12195 | struct cleanup *old_chain; |
12196 | ||
12197 | if (!target_can_download_tracepoint ()) | |
12198 | return; | |
12199 | ||
12200 | old_chain = save_current_space_and_thread (); | |
12201 | ||
7ed2c994 | 12202 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12203 | { |
7ed2c994 | 12204 | struct bp_location *bl; |
1e4d1764 | 12205 | struct tracepoint *t; |
f2a8bc8a | 12206 | int bp_location_downloaded = 0; |
1e4d1764 | 12207 | |
7ed2c994 | 12208 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12209 | ? !may_insert_fast_tracepoints |
12210 | : !may_insert_tracepoints)) | |
12211 | continue; | |
12212 | ||
7ed2c994 YQ |
12213 | for (bl = b->loc; bl; bl = bl->next) |
12214 | { | |
12215 | /* In tracepoint, locations are _never_ duplicated, so | |
12216 | should_be_inserted is equivalent to | |
12217 | unduplicated_should_be_inserted. */ | |
12218 | if (!should_be_inserted (bl) || bl->inserted) | |
12219 | continue; | |
1e4d1764 | 12220 | |
7ed2c994 | 12221 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12222 | |
7ed2c994 | 12223 | target_download_tracepoint (bl); |
1e4d1764 | 12224 | |
7ed2c994 | 12225 | bl->inserted = 1; |
f2a8bc8a | 12226 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12227 | } |
12228 | t = (struct tracepoint *) b; | |
12229 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12230 | if (bp_location_downloaded) |
12231 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12232 | } |
12233 | ||
12234 | do_cleanups (old_chain); | |
12235 | } | |
12236 | ||
934709f0 PW |
12237 | /* Swap the insertion/duplication state between two locations. */ |
12238 | ||
12239 | static void | |
12240 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12241 | { | |
12242 | const int left_inserted = left->inserted; | |
12243 | const int left_duplicate = left->duplicate; | |
b775012e | 12244 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12245 | const struct bp_target_info left_target_info = left->target_info; |
12246 | ||
1e4d1764 YQ |
12247 | /* Locations of tracepoints can never be duplicated. */ |
12248 | if (is_tracepoint (left->owner)) | |
12249 | gdb_assert (!left->duplicate); | |
12250 | if (is_tracepoint (right->owner)) | |
12251 | gdb_assert (!right->duplicate); | |
12252 | ||
934709f0 PW |
12253 | left->inserted = right->inserted; |
12254 | left->duplicate = right->duplicate; | |
b775012e | 12255 | left->needs_update = right->needs_update; |
934709f0 PW |
12256 | left->target_info = right->target_info; |
12257 | right->inserted = left_inserted; | |
12258 | right->duplicate = left_duplicate; | |
b775012e | 12259 | right->needs_update = left_needs_update; |
934709f0 PW |
12260 | right->target_info = left_target_info; |
12261 | } | |
12262 | ||
b775012e LM |
12263 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12264 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12265 | conditions on the target's side. Such conditions need to be updated on | |
12266 | the target. */ | |
12267 | ||
12268 | static void | |
12269 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12270 | { | |
12271 | struct bp_location **locp = NULL, **loc2p; | |
12272 | struct bp_location *loc; | |
12273 | CORE_ADDR address = 0; | |
12274 | int pspace_num; | |
12275 | ||
12276 | address = bl->address; | |
12277 | pspace_num = bl->pspace->num; | |
12278 | ||
12279 | /* This is only meaningful if the target is | |
12280 | evaluating conditions and if the user has | |
12281 | opted for condition evaluation on the target's | |
12282 | side. */ | |
12283 | if (gdb_evaluates_breakpoint_condition_p () | |
12284 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12285 | return; | |
12286 | ||
12287 | /* Flag all breakpoint locations with this address and | |
12288 | the same program space as the location | |
12289 | as "its condition has changed". We need to | |
12290 | update the conditions on the target's side. */ | |
12291 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12292 | { | |
12293 | loc = *loc2p; | |
12294 | ||
12295 | if (!is_breakpoint (loc->owner) | |
12296 | || pspace_num != loc->pspace->num) | |
12297 | continue; | |
12298 | ||
12299 | /* Flag the location appropriately. We use a different state to | |
12300 | let everyone know that we already updated the set of locations | |
12301 | with addr bl->address and program space bl->pspace. This is so | |
12302 | we don't have to keep calling these functions just to mark locations | |
12303 | that have already been marked. */ | |
12304 | loc->condition_changed = condition_updated; | |
12305 | ||
12306 | /* Free the agent expression bytecode as well. We will compute | |
12307 | it later on. */ | |
12308 | if (loc->cond_bytecode) | |
12309 | { | |
12310 | free_agent_expr (loc->cond_bytecode); | |
12311 | loc->cond_bytecode = NULL; | |
12312 | } | |
12313 | } | |
12314 | } | |
12315 | ||
4cd9bd08 | 12316 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12317 | into the inferior, only remove already-inserted locations that no |
12318 | longer should be inserted. Functions that delete a breakpoint or | |
12319 | breakpoints should pass false, so that deleting a breakpoint | |
12320 | doesn't have the side effect of inserting the locations of other | |
12321 | breakpoints that are marked not-inserted, but should_be_inserted | |
12322 | returns true on them. | |
12323 | ||
12324 | This behaviour is useful is situations close to tear-down -- e.g., | |
12325 | after an exec, while the target still has execution, but breakpoint | |
12326 | shadows of the previous executable image should *NOT* be restored | |
12327 | to the new image; or before detaching, where the target still has | |
12328 | execution and wants to delete breakpoints from GDB's lists, and all | |
12329 | breakpoints had already been removed from the inferior. */ | |
12330 | ||
0d381245 | 12331 | static void |
b60e7edf | 12332 | update_global_location_list (int should_insert) |
0d381245 | 12333 | { |
74960c60 | 12334 | struct breakpoint *b; |
876fa593 | 12335 | struct bp_location **locp, *loc; |
f7545552 | 12336 | struct cleanup *cleanups; |
b775012e LM |
12337 | /* Last breakpoint location address that was marked for update. */ |
12338 | CORE_ADDR last_addr = 0; | |
12339 | /* Last breakpoint location program space that was marked for update. */ | |
12340 | int last_pspace_num = -1; | |
f7545552 | 12341 | |
2d134ed3 PA |
12342 | /* Used in the duplicates detection below. When iterating over all |
12343 | bp_locations, points to the first bp_location of a given address. | |
12344 | Breakpoints and watchpoints of different types are never | |
12345 | duplicates of each other. Keep one pointer for each type of | |
12346 | breakpoint/watchpoint, so we only need to loop over all locations | |
12347 | once. */ | |
12348 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12349 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12350 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12351 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12352 | |
4a64f543 MS |
12353 | /* Saved former bp_location array which we compare against the newly |
12354 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12355 | struct bp_location **old_location, **old_locp; |
12356 | unsigned old_location_count; | |
12357 | ||
12358 | old_location = bp_location; | |
12359 | old_location_count = bp_location_count; | |
12360 | bp_location = NULL; | |
12361 | bp_location_count = 0; | |
12362 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12363 | |
74960c60 | 12364 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12365 | for (loc = b->loc; loc; loc = loc->next) |
12366 | bp_location_count++; | |
12367 | ||
12368 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12369 | locp = bp_location; | |
12370 | ALL_BREAKPOINTS (b) | |
12371 | for (loc = b->loc; loc; loc = loc->next) | |
12372 | *locp++ = loc; | |
12373 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12374 | bp_location_compare); |
876fa593 JK |
12375 | |
12376 | bp_location_target_extensions_update (); | |
74960c60 | 12377 | |
4a64f543 MS |
12378 | /* Identify bp_location instances that are no longer present in the |
12379 | new list, and therefore should be freed. Note that it's not | |
12380 | necessary that those locations should be removed from inferior -- | |
12381 | if there's another location at the same address (previously | |
12382 | marked as duplicate), we don't need to remove/insert the | |
12383 | location. | |
876fa593 | 12384 | |
4a64f543 MS |
12385 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12386 | and former bp_location array state respectively. */ | |
876fa593 JK |
12387 | |
12388 | locp = bp_location; | |
12389 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12390 | old_locp++) | |
74960c60 | 12391 | { |
876fa593 | 12392 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12393 | struct bp_location **loc2p; |
876fa593 | 12394 | |
e5dd4106 | 12395 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12396 | not, we have to free it. */ |
c7d46a38 | 12397 | int found_object = 0; |
20874c92 VP |
12398 | /* Tells if the location should remain inserted in the target. */ |
12399 | int keep_in_target = 0; | |
12400 | int removed = 0; | |
876fa593 | 12401 | |
4a64f543 MS |
12402 | /* Skip LOCP entries which will definitely never be needed. |
12403 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12404 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12405 | && (*locp)->address < old_loc->address) |
876fa593 | 12406 | locp++; |
c7d46a38 PA |
12407 | |
12408 | for (loc2p = locp; | |
12409 | (loc2p < bp_location + bp_location_count | |
12410 | && (*loc2p)->address == old_loc->address); | |
12411 | loc2p++) | |
12412 | { | |
b775012e LM |
12413 | /* Check if this is a new/duplicated location or a duplicated |
12414 | location that had its condition modified. If so, we want to send | |
12415 | its condition to the target if evaluation of conditions is taking | |
12416 | place there. */ | |
12417 | if ((*loc2p)->condition_changed == condition_modified | |
12418 | && (last_addr != old_loc->address | |
12419 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12420 | { |
b775012e LM |
12421 | force_breakpoint_reinsertion (*loc2p); |
12422 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12423 | } |
b775012e LM |
12424 | |
12425 | if (*loc2p == old_loc) | |
12426 | found_object = 1; | |
c7d46a38 | 12427 | } |
74960c60 | 12428 | |
b775012e LM |
12429 | /* We have already handled this address, update it so that we don't |
12430 | have to go through updates again. */ | |
12431 | last_addr = old_loc->address; | |
12432 | ||
12433 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12434 | if (!found_object) | |
12435 | force_breakpoint_reinsertion (old_loc); | |
12436 | ||
4a64f543 MS |
12437 | /* If this location is no longer present, and inserted, look if |
12438 | there's maybe a new location at the same address. If so, | |
12439 | mark that one inserted, and don't remove this one. This is | |
12440 | needed so that we don't have a time window where a breakpoint | |
12441 | at certain location is not inserted. */ | |
74960c60 | 12442 | |
876fa593 | 12443 | if (old_loc->inserted) |
0d381245 | 12444 | { |
4a64f543 MS |
12445 | /* If the location is inserted now, we might have to remove |
12446 | it. */ | |
74960c60 | 12447 | |
876fa593 | 12448 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12449 | { |
4a64f543 MS |
12450 | /* The location is still present in the location list, |
12451 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12452 | keep_in_target = 1; |
74960c60 VP |
12453 | } |
12454 | else | |
12455 | { | |
b775012e LM |
12456 | /* This location still exists, but it won't be kept in the |
12457 | target since it may have been disabled. We proceed to | |
12458 | remove its target-side condition. */ | |
12459 | ||
4a64f543 MS |
12460 | /* The location is either no longer present, or got |
12461 | disabled. See if there's another location at the | |
12462 | same address, in which case we don't need to remove | |
12463 | this one from the target. */ | |
876fa593 | 12464 | |
2bdf28a0 | 12465 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12466 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12467 | { | |
876fa593 | 12468 | for (loc2p = locp; |
c7d46a38 PA |
12469 | (loc2p < bp_location + bp_location_count |
12470 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12471 | loc2p++) |
12472 | { | |
12473 | struct bp_location *loc2 = *loc2p; | |
12474 | ||
2d134ed3 | 12475 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12476 | { |
85d721b8 PA |
12477 | /* Read watchpoint locations are switched to |
12478 | access watchpoints, if the former are not | |
12479 | supported, but the latter are. */ | |
12480 | if (is_hardware_watchpoint (old_loc->owner)) | |
12481 | { | |
12482 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12483 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12484 | } | |
12485 | ||
934709f0 PW |
12486 | /* loc2 is a duplicated location. We need to check |
12487 | if it should be inserted in case it will be | |
12488 | unduplicated. */ | |
12489 | if (loc2 != old_loc | |
12490 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12491 | { |
934709f0 | 12492 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12493 | keep_in_target = 1; |
12494 | break; | |
12495 | } | |
876fa593 JK |
12496 | } |
12497 | } | |
12498 | } | |
74960c60 VP |
12499 | } |
12500 | ||
20874c92 VP |
12501 | if (!keep_in_target) |
12502 | { | |
876fa593 | 12503 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12504 | { |
4a64f543 MS |
12505 | /* This is just about all we can do. We could keep |
12506 | this location on the global list, and try to | |
12507 | remove it next time, but there's no particular | |
12508 | reason why we will succeed next time. | |
20874c92 | 12509 | |
4a64f543 MS |
12510 | Note that at this point, old_loc->owner is still |
12511 | valid, as delete_breakpoint frees the breakpoint | |
12512 | only after calling us. */ | |
3e43a32a MS |
12513 | printf_filtered (_("warning: Error removing " |
12514 | "breakpoint %d\n"), | |
876fa593 | 12515 | old_loc->owner->number); |
20874c92 VP |
12516 | } |
12517 | removed = 1; | |
12518 | } | |
0d381245 | 12519 | } |
74960c60 VP |
12520 | |
12521 | if (!found_object) | |
1c5cfe86 | 12522 | { |
db82e815 PA |
12523 | if (removed && non_stop |
12524 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12525 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12526 | { |
db82e815 PA |
12527 | /* This location was removed from the target. In |
12528 | non-stop mode, a race condition is possible where | |
12529 | we've removed a breakpoint, but stop events for that | |
12530 | breakpoint are already queued and will arrive later. | |
12531 | We apply an heuristic to be able to distinguish such | |
12532 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12533 | breakpoint location for a bit, and will retire it | |
12534 | after we see some number of events. The theory here | |
12535 | is that reporting of events should, "on the average", | |
12536 | be fair, so after a while we'll see events from all | |
12537 | threads that have anything of interest, and no longer | |
12538 | need to keep this breakpoint location around. We | |
12539 | don't hold locations forever so to reduce chances of | |
12540 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12541 | SIGTRAP. | |
12542 | ||
12543 | The heuristic failing can be disastrous on | |
12544 | decr_pc_after_break targets. | |
12545 | ||
12546 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12547 | if we fail to recognize a late breakpoint SIGTRAP, | |
12548 | because events_till_retirement has reached 0 too | |
12549 | soon, we'll fail to do the PC adjustment, and report | |
12550 | a random SIGTRAP to the user. When the user resumes | |
12551 | the inferior, it will most likely immediately crash | |
2dec564e | 12552 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12553 | corrupted, because of being resumed e.g., in the |
12554 | middle of a multi-byte instruction, or skipped a | |
12555 | one-byte instruction. This was actually seen happen | |
12556 | on native x86-linux, and should be less rare on | |
12557 | targets that do not support new thread events, like | |
12558 | remote, due to the heuristic depending on | |
12559 | thread_count. | |
12560 | ||
12561 | Mistaking a random SIGTRAP for a breakpoint trap | |
12562 | causes similar symptoms (PC adjustment applied when | |
12563 | it shouldn't), but then again, playing with SIGTRAPs | |
12564 | behind the debugger's back is asking for trouble. | |
12565 | ||
12566 | Since hardware watchpoint traps are always | |
12567 | distinguishable from other traps, so we don't need to | |
12568 | apply keep hardware watchpoint moribund locations | |
12569 | around. We simply always ignore hardware watchpoint | |
12570 | traps we can no longer explain. */ | |
12571 | ||
876fa593 JK |
12572 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12573 | old_loc->owner = NULL; | |
20874c92 | 12574 | |
876fa593 | 12575 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12576 | } |
12577 | else | |
f431efe5 PA |
12578 | { |
12579 | old_loc->owner = NULL; | |
12580 | decref_bp_location (&old_loc); | |
12581 | } | |
20874c92 | 12582 | } |
74960c60 | 12583 | } |
1c5cfe86 | 12584 | |
348d480f PA |
12585 | /* Rescan breakpoints at the same address and section, marking the |
12586 | first one as "first" and any others as "duplicates". This is so | |
12587 | that the bpt instruction is only inserted once. If we have a | |
12588 | permanent breakpoint at the same place as BPT, make that one the | |
12589 | official one, and the rest as duplicates. Permanent breakpoints | |
12590 | are sorted first for the same address. | |
12591 | ||
12592 | Do the same for hardware watchpoints, but also considering the | |
12593 | watchpoint's type (regular/access/read) and length. */ | |
12594 | ||
12595 | bp_loc_first = NULL; | |
12596 | wp_loc_first = NULL; | |
12597 | awp_loc_first = NULL; | |
12598 | rwp_loc_first = NULL; | |
12599 | ALL_BP_LOCATIONS (loc, locp) | |
12600 | { | |
12601 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12602 | non-NULL. */ | |
348d480f | 12603 | struct bp_location **loc_first_p; |
d3fbdd86 | 12604 | b = loc->owner; |
348d480f | 12605 | |
6f380991 | 12606 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12607 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12608 | /* Don't detect duplicate for tracepoint locations because they are |
12609 | never duplicated. See the comments in field `duplicate' of | |
12610 | `struct bp_location'. */ | |
348d480f | 12611 | || is_tracepoint (b)) |
b775012e LM |
12612 | { |
12613 | /* Clear the condition modification flag. */ | |
12614 | loc->condition_changed = condition_unchanged; | |
12615 | continue; | |
12616 | } | |
348d480f PA |
12617 | |
12618 | /* Permanent breakpoint should always be inserted. */ | |
12619 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12620 | internal_error (__FILE__, __LINE__, | |
12621 | _("allegedly permanent breakpoint is not " | |
12622 | "actually inserted")); | |
12623 | ||
12624 | if (b->type == bp_hardware_watchpoint) | |
12625 | loc_first_p = &wp_loc_first; | |
12626 | else if (b->type == bp_read_watchpoint) | |
12627 | loc_first_p = &rwp_loc_first; | |
12628 | else if (b->type == bp_access_watchpoint) | |
12629 | loc_first_p = &awp_loc_first; | |
12630 | else | |
12631 | loc_first_p = &bp_loc_first; | |
12632 | ||
12633 | if (*loc_first_p == NULL | |
12634 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12635 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12636 | { | |
12637 | *loc_first_p = loc; | |
12638 | loc->duplicate = 0; | |
b775012e LM |
12639 | |
12640 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12641 | { | |
12642 | loc->needs_update = 1; | |
12643 | /* Clear the condition modification flag. */ | |
12644 | loc->condition_changed = condition_unchanged; | |
12645 | } | |
348d480f PA |
12646 | continue; |
12647 | } | |
12648 | ||
934709f0 PW |
12649 | |
12650 | /* This and the above ensure the invariant that the first location | |
12651 | is not duplicated, and is the inserted one. | |
12652 | All following are marked as duplicated, and are not inserted. */ | |
12653 | if (loc->inserted) | |
12654 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12655 | loc->duplicate = 1; |
12656 | ||
b775012e LM |
12657 | /* Clear the condition modification flag. */ |
12658 | loc->condition_changed = condition_unchanged; | |
12659 | ||
348d480f PA |
12660 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12661 | && b->enable_state != bp_permanent) | |
12662 | internal_error (__FILE__, __LINE__, | |
12663 | _("another breakpoint was inserted on top of " | |
12664 | "a permanent breakpoint")); | |
12665 | } | |
12666 | ||
b775012e | 12667 | if (breakpoints_always_inserted_mode () |
348d480f | 12668 | && (have_live_inferiors () |
f5656ead | 12669 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12670 | { |
12671 | if (should_insert) | |
12672 | insert_breakpoint_locations (); | |
12673 | else | |
12674 | { | |
12675 | /* Though should_insert is false, we may need to update conditions | |
12676 | on the target's side if it is evaluating such conditions. We | |
12677 | only update conditions for locations that are marked | |
12678 | "needs_update". */ | |
12679 | update_inserted_breakpoint_locations (); | |
12680 | } | |
12681 | } | |
348d480f | 12682 | |
1e4d1764 YQ |
12683 | if (should_insert) |
12684 | download_tracepoint_locations (); | |
12685 | ||
348d480f PA |
12686 | do_cleanups (cleanups); |
12687 | } | |
12688 | ||
12689 | void | |
12690 | breakpoint_retire_moribund (void) | |
12691 | { | |
12692 | struct bp_location *loc; | |
12693 | int ix; | |
12694 | ||
12695 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12696 | if (--(loc->events_till_retirement) == 0) | |
12697 | { | |
12698 | decref_bp_location (&loc); | |
12699 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12700 | --ix; | |
12701 | } | |
12702 | } | |
12703 | ||
12704 | static void | |
12705 | update_global_location_list_nothrow (int inserting) | |
12706 | { | |
bfd189b1 | 12707 | volatile struct gdb_exception e; |
348d480f PA |
12708 | |
12709 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12710 | update_global_location_list (inserting); | |
12711 | } | |
12712 | ||
12713 | /* Clear BKP from a BPS. */ | |
12714 | ||
12715 | static void | |
12716 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12717 | { | |
12718 | bpstat bs; | |
12719 | ||
12720 | for (bs = bps; bs; bs = bs->next) | |
12721 | if (bs->breakpoint_at == bpt) | |
12722 | { | |
12723 | bs->breakpoint_at = NULL; | |
12724 | bs->old_val = NULL; | |
12725 | /* bs->commands will be freed later. */ | |
12726 | } | |
12727 | } | |
12728 | ||
12729 | /* Callback for iterate_over_threads. */ | |
12730 | static int | |
12731 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12732 | { | |
12733 | struct breakpoint *bpt = data; | |
12734 | ||
12735 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12736 | return 0; | |
12737 | } | |
12738 | ||
12739 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12740 | callbacks. */ | |
12741 | ||
12742 | static void | |
12743 | say_where (struct breakpoint *b) | |
12744 | { | |
12745 | struct value_print_options opts; | |
12746 | ||
12747 | get_user_print_options (&opts); | |
12748 | ||
12749 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12750 | single string. */ | |
12751 | if (b->loc == NULL) | |
12752 | { | |
12753 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12754 | } | |
12755 | else | |
12756 | { | |
2f202fde | 12757 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12758 | { |
12759 | printf_filtered (" at "); | |
12760 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12761 | gdb_stdout); | |
12762 | } | |
2f202fde | 12763 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12764 | { |
12765 | /* If there is a single location, we can print the location | |
12766 | more nicely. */ | |
12767 | if (b->loc->next == NULL) | |
12768 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12769 | symtab_to_filename_for_display (b->loc->symtab), |
12770 | b->loc->line_number); | |
f8eba3c6 TT |
12771 | else |
12772 | /* This is not ideal, but each location may have a | |
12773 | different file name, and this at least reflects the | |
12774 | real situation somewhat. */ | |
12775 | printf_filtered (": %s.", b->addr_string); | |
12776 | } | |
348d480f PA |
12777 | |
12778 | if (b->loc->next) | |
12779 | { | |
12780 | struct bp_location *loc = b->loc; | |
12781 | int n = 0; | |
12782 | for (; loc; loc = loc->next) | |
12783 | ++n; | |
12784 | printf_filtered (" (%d locations)", n); | |
12785 | } | |
12786 | } | |
12787 | } | |
12788 | ||
348d480f PA |
12789 | /* Default bp_location_ops methods. */ |
12790 | ||
12791 | static void | |
12792 | bp_location_dtor (struct bp_location *self) | |
12793 | { | |
12794 | xfree (self->cond); | |
b775012e LM |
12795 | if (self->cond_bytecode) |
12796 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12797 | xfree (self->function_name); |
8b4f3082 PA |
12798 | |
12799 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12800 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12801 | } |
12802 | ||
12803 | static const struct bp_location_ops bp_location_ops = | |
12804 | { | |
12805 | bp_location_dtor | |
12806 | }; | |
12807 | ||
2060206e PA |
12808 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12809 | inherit from. */ | |
348d480f | 12810 | |
2060206e PA |
12811 | static void |
12812 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12813 | { |
12814 | decref_counted_command_line (&self->commands); | |
12815 | xfree (self->cond_string); | |
fb81d016 | 12816 | xfree (self->extra_string); |
348d480f | 12817 | xfree (self->addr_string); |
f8eba3c6 | 12818 | xfree (self->filter); |
348d480f | 12819 | xfree (self->addr_string_range_end); |
348d480f PA |
12820 | } |
12821 | ||
2060206e PA |
12822 | static struct bp_location * |
12823 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12824 | { |
12825 | struct bp_location *loc; | |
12826 | ||
12827 | loc = XNEW (struct bp_location); | |
12828 | init_bp_location (loc, &bp_location_ops, self); | |
12829 | return loc; | |
12830 | } | |
12831 | ||
2060206e PA |
12832 | static void |
12833 | base_breakpoint_re_set (struct breakpoint *b) | |
12834 | { | |
12835 | /* Nothing to re-set. */ | |
12836 | } | |
12837 | ||
12838 | #define internal_error_pure_virtual_called() \ | |
12839 | gdb_assert_not_reached ("pure virtual function called") | |
12840 | ||
12841 | static int | |
12842 | base_breakpoint_insert_location (struct bp_location *bl) | |
12843 | { | |
12844 | internal_error_pure_virtual_called (); | |
12845 | } | |
12846 | ||
12847 | static int | |
12848 | base_breakpoint_remove_location (struct bp_location *bl) | |
12849 | { | |
12850 | internal_error_pure_virtual_called (); | |
12851 | } | |
12852 | ||
12853 | static int | |
12854 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12855 | struct address_space *aspace, | |
09ac7c10 TT |
12856 | CORE_ADDR bp_addr, |
12857 | const struct target_waitstatus *ws) | |
2060206e PA |
12858 | { |
12859 | internal_error_pure_virtual_called (); | |
12860 | } | |
12861 | ||
12862 | static void | |
12863 | base_breakpoint_check_status (bpstat bs) | |
12864 | { | |
12865 | /* Always stop. */ | |
12866 | } | |
12867 | ||
12868 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12869 | errors. */ | |
12870 | ||
12871 | static int | |
12872 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12873 | { | |
12874 | internal_error_pure_virtual_called (); | |
12875 | } | |
12876 | ||
12877 | /* A "resources_needed" breakpoint_ops method that just internal | |
12878 | errors. */ | |
12879 | ||
12880 | static int | |
12881 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12882 | { | |
12883 | internal_error_pure_virtual_called (); | |
12884 | } | |
12885 | ||
12886 | static enum print_stop_action | |
12887 | base_breakpoint_print_it (bpstat bs) | |
12888 | { | |
12889 | internal_error_pure_virtual_called (); | |
12890 | } | |
12891 | ||
12892 | static void | |
12893 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12894 | struct ui_out *uiout) | |
12895 | { | |
12896 | /* nothing */ | |
12897 | } | |
12898 | ||
12899 | static void | |
12900 | base_breakpoint_print_mention (struct breakpoint *b) | |
12901 | { | |
12902 | internal_error_pure_virtual_called (); | |
12903 | } | |
12904 | ||
12905 | static void | |
12906 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12907 | { | |
12908 | internal_error_pure_virtual_called (); | |
12909 | } | |
12910 | ||
983af33b SDJ |
12911 | static void |
12912 | base_breakpoint_create_sals_from_address (char **arg, | |
12913 | struct linespec_result *canonical, | |
12914 | enum bptype type_wanted, | |
12915 | char *addr_start, | |
12916 | char **copy_arg) | |
12917 | { | |
12918 | internal_error_pure_virtual_called (); | |
12919 | } | |
12920 | ||
12921 | static void | |
12922 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12923 | struct linespec_result *c, | |
983af33b | 12924 | char *cond_string, |
e7e0cddf | 12925 | char *extra_string, |
983af33b SDJ |
12926 | enum bptype type_wanted, |
12927 | enum bpdisp disposition, | |
12928 | int thread, | |
12929 | int task, int ignore_count, | |
12930 | const struct breakpoint_ops *o, | |
12931 | int from_tty, int enabled, | |
44f238bb | 12932 | int internal, unsigned flags) |
983af33b SDJ |
12933 | { |
12934 | internal_error_pure_virtual_called (); | |
12935 | } | |
12936 | ||
12937 | static void | |
12938 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12939 | struct symtabs_and_lines *sals) | |
12940 | { | |
12941 | internal_error_pure_virtual_called (); | |
12942 | } | |
12943 | ||
ab04a2af TT |
12944 | /* The default 'explains_signal' method. */ |
12945 | ||
47591c29 | 12946 | static int |
427cd150 | 12947 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12948 | { |
47591c29 | 12949 | return 1; |
ab04a2af TT |
12950 | } |
12951 | ||
9d6e6e84 HZ |
12952 | /* The default "after_condition_true" method. */ |
12953 | ||
12954 | static void | |
12955 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12956 | { | |
12957 | /* Nothing to do. */ | |
12958 | } | |
12959 | ||
ab04a2af | 12960 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12961 | { |
12962 | base_breakpoint_dtor, | |
12963 | base_breakpoint_allocate_location, | |
12964 | base_breakpoint_re_set, | |
12965 | base_breakpoint_insert_location, | |
12966 | base_breakpoint_remove_location, | |
12967 | base_breakpoint_breakpoint_hit, | |
12968 | base_breakpoint_check_status, | |
12969 | base_breakpoint_resources_needed, | |
12970 | base_breakpoint_works_in_software_mode, | |
12971 | base_breakpoint_print_it, | |
12972 | NULL, | |
12973 | base_breakpoint_print_one_detail, | |
12974 | base_breakpoint_print_mention, | |
983af33b SDJ |
12975 | base_breakpoint_print_recreate, |
12976 | base_breakpoint_create_sals_from_address, | |
12977 | base_breakpoint_create_breakpoints_sal, | |
12978 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12979 | base_breakpoint_explains_signal, |
12980 | base_breakpoint_after_condition_true, | |
2060206e PA |
12981 | }; |
12982 | ||
12983 | /* Default breakpoint_ops methods. */ | |
12984 | ||
12985 | static void | |
348d480f PA |
12986 | bkpt_re_set (struct breakpoint *b) |
12987 | { | |
06edf0c0 PA |
12988 | /* FIXME: is this still reachable? */ |
12989 | if (b->addr_string == NULL) | |
12990 | { | |
12991 | /* Anything without a string can't be re-set. */ | |
348d480f | 12992 | delete_breakpoint (b); |
06edf0c0 | 12993 | return; |
348d480f | 12994 | } |
06edf0c0 PA |
12995 | |
12996 | breakpoint_re_set_default (b); | |
348d480f PA |
12997 | } |
12998 | ||
2060206e | 12999 | static int |
348d480f PA |
13000 | bkpt_insert_location (struct bp_location *bl) |
13001 | { | |
13002 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13003 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13004 | &bl->target_info); | |
13005 | else | |
13006 | return target_insert_breakpoint (bl->gdbarch, | |
13007 | &bl->target_info); | |
13008 | } | |
13009 | ||
2060206e | 13010 | static int |
348d480f PA |
13011 | bkpt_remove_location (struct bp_location *bl) |
13012 | { | |
13013 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13014 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13015 | else | |
13016 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
13017 | } | |
13018 | ||
2060206e | 13019 | static int |
348d480f | 13020 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13021 | struct address_space *aspace, CORE_ADDR bp_addr, |
13022 | const struct target_waitstatus *ws) | |
348d480f | 13023 | { |
09ac7c10 | 13024 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13025 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13026 | return 0; |
13027 | ||
348d480f PA |
13028 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13029 | aspace, bp_addr)) | |
13030 | return 0; | |
13031 | ||
13032 | if (overlay_debugging /* unmapped overlay section */ | |
13033 | && section_is_overlay (bl->section) | |
13034 | && !section_is_mapped (bl->section)) | |
13035 | return 0; | |
13036 | ||
13037 | return 1; | |
13038 | } | |
13039 | ||
2060206e | 13040 | static int |
348d480f PA |
13041 | bkpt_resources_needed (const struct bp_location *bl) |
13042 | { | |
13043 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13044 | ||
13045 | return 1; | |
13046 | } | |
13047 | ||
2060206e | 13048 | static enum print_stop_action |
348d480f PA |
13049 | bkpt_print_it (bpstat bs) |
13050 | { | |
348d480f PA |
13051 | struct breakpoint *b; |
13052 | const struct bp_location *bl; | |
001c8c33 | 13053 | int bp_temp; |
79a45e25 | 13054 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13055 | |
13056 | gdb_assert (bs->bp_location_at != NULL); | |
13057 | ||
13058 | bl = bs->bp_location_at; | |
13059 | b = bs->breakpoint_at; | |
13060 | ||
001c8c33 PA |
13061 | bp_temp = b->disposition == disp_del; |
13062 | if (bl->address != bl->requested_address) | |
13063 | breakpoint_adjustment_warning (bl->requested_address, | |
13064 | bl->address, | |
13065 | b->number, 1); | |
13066 | annotate_breakpoint (b->number); | |
13067 | if (bp_temp) | |
13068 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13069 | else | |
13070 | ui_out_text (uiout, "\nBreakpoint "); | |
13071 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13072 | { |
001c8c33 PA |
13073 | ui_out_field_string (uiout, "reason", |
13074 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13075 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13076 | } |
001c8c33 PA |
13077 | ui_out_field_int (uiout, "bkptno", b->number); |
13078 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13079 | |
001c8c33 | 13080 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13081 | } |
13082 | ||
2060206e | 13083 | static void |
06edf0c0 PA |
13084 | bkpt_print_mention (struct breakpoint *b) |
13085 | { | |
79a45e25 | 13086 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13087 | return; |
13088 | ||
13089 | switch (b->type) | |
13090 | { | |
13091 | case bp_breakpoint: | |
13092 | case bp_gnu_ifunc_resolver: | |
13093 | if (b->disposition == disp_del) | |
13094 | printf_filtered (_("Temporary breakpoint")); | |
13095 | else | |
13096 | printf_filtered (_("Breakpoint")); | |
13097 | printf_filtered (_(" %d"), b->number); | |
13098 | if (b->type == bp_gnu_ifunc_resolver) | |
13099 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13100 | break; | |
13101 | case bp_hardware_breakpoint: | |
13102 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13103 | break; | |
e7e0cddf SS |
13104 | case bp_dprintf: |
13105 | printf_filtered (_("Dprintf %d"), b->number); | |
13106 | break; | |
06edf0c0 PA |
13107 | } |
13108 | ||
13109 | say_where (b); | |
13110 | } | |
13111 | ||
2060206e | 13112 | static void |
06edf0c0 PA |
13113 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13114 | { | |
13115 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13116 | fprintf_unfiltered (fp, "tbreak"); | |
13117 | else if (tp->type == bp_breakpoint) | |
13118 | fprintf_unfiltered (fp, "break"); | |
13119 | else if (tp->type == bp_hardware_breakpoint | |
13120 | && tp->disposition == disp_del) | |
13121 | fprintf_unfiltered (fp, "thbreak"); | |
13122 | else if (tp->type == bp_hardware_breakpoint) | |
13123 | fprintf_unfiltered (fp, "hbreak"); | |
13124 | else | |
13125 | internal_error (__FILE__, __LINE__, | |
13126 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13127 | ||
2060206e | 13128 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13129 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13130 | } |
13131 | ||
983af33b SDJ |
13132 | static void |
13133 | bkpt_create_sals_from_address (char **arg, | |
13134 | struct linespec_result *canonical, | |
13135 | enum bptype type_wanted, | |
13136 | char *addr_start, char **copy_arg) | |
13137 | { | |
13138 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13139 | addr_start, copy_arg); | |
13140 | } | |
13141 | ||
13142 | static void | |
13143 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13144 | struct linespec_result *canonical, | |
983af33b | 13145 | char *cond_string, |
e7e0cddf | 13146 | char *extra_string, |
983af33b SDJ |
13147 | enum bptype type_wanted, |
13148 | enum bpdisp disposition, | |
13149 | int thread, | |
13150 | int task, int ignore_count, | |
13151 | const struct breakpoint_ops *ops, | |
13152 | int from_tty, int enabled, | |
44f238bb | 13153 | int internal, unsigned flags) |
983af33b | 13154 | { |
023fa29b | 13155 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13156 | cond_string, extra_string, |
13157 | type_wanted, | |
983af33b SDJ |
13158 | disposition, thread, task, |
13159 | ignore_count, ops, from_tty, | |
44f238bb | 13160 | enabled, internal, flags); |
983af33b SDJ |
13161 | } |
13162 | ||
13163 | static void | |
13164 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13165 | struct symtabs_and_lines *sals) | |
13166 | { | |
13167 | decode_linespec_default (b, s, sals); | |
13168 | } | |
13169 | ||
06edf0c0 PA |
13170 | /* Virtual table for internal breakpoints. */ |
13171 | ||
13172 | static void | |
13173 | internal_bkpt_re_set (struct breakpoint *b) | |
13174 | { | |
13175 | switch (b->type) | |
13176 | { | |
13177 | /* Delete overlay event and longjmp master breakpoints; they | |
13178 | will be reset later by breakpoint_re_set. */ | |
13179 | case bp_overlay_event: | |
13180 | case bp_longjmp_master: | |
13181 | case bp_std_terminate_master: | |
13182 | case bp_exception_master: | |
13183 | delete_breakpoint (b); | |
13184 | break; | |
13185 | ||
13186 | /* This breakpoint is special, it's set up when the inferior | |
13187 | starts and we really don't want to touch it. */ | |
13188 | case bp_shlib_event: | |
13189 | ||
13190 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13191 | it is set up, we do not want to touch it. */ | |
13192 | case bp_thread_event: | |
13193 | break; | |
13194 | } | |
13195 | } | |
13196 | ||
13197 | static void | |
13198 | internal_bkpt_check_status (bpstat bs) | |
13199 | { | |
a9b3a50f PA |
13200 | if (bs->breakpoint_at->type == bp_shlib_event) |
13201 | { | |
13202 | /* If requested, stop when the dynamic linker notifies GDB of | |
13203 | events. This allows the user to get control and place | |
13204 | breakpoints in initializer routines for dynamically loaded | |
13205 | objects (among other things). */ | |
13206 | bs->stop = stop_on_solib_events; | |
13207 | bs->print = stop_on_solib_events; | |
13208 | } | |
13209 | else | |
13210 | bs->stop = 0; | |
06edf0c0 PA |
13211 | } |
13212 | ||
13213 | static enum print_stop_action | |
13214 | internal_bkpt_print_it (bpstat bs) | |
13215 | { | |
06edf0c0 | 13216 | struct breakpoint *b; |
06edf0c0 | 13217 | |
06edf0c0 PA |
13218 | b = bs->breakpoint_at; |
13219 | ||
06edf0c0 PA |
13220 | switch (b->type) |
13221 | { | |
348d480f PA |
13222 | case bp_shlib_event: |
13223 | /* Did we stop because the user set the stop_on_solib_events | |
13224 | variable? (If so, we report this as a generic, "Stopped due | |
13225 | to shlib event" message.) */ | |
edcc5120 | 13226 | print_solib_event (0); |
348d480f PA |
13227 | break; |
13228 | ||
13229 | case bp_thread_event: | |
13230 | /* Not sure how we will get here. | |
13231 | GDB should not stop for these breakpoints. */ | |
13232 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13233 | break; |
13234 | ||
13235 | case bp_overlay_event: | |
13236 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13237 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13238 | break; |
13239 | ||
13240 | case bp_longjmp_master: | |
13241 | /* These should never be enabled. */ | |
13242 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13243 | break; |
13244 | ||
13245 | case bp_std_terminate_master: | |
13246 | /* These should never be enabled. */ | |
13247 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13248 | "gdb should not stop!\n")); | |
348d480f PA |
13249 | break; |
13250 | ||
13251 | case bp_exception_master: | |
13252 | /* These should never be enabled. */ | |
13253 | printf_filtered (_("Exception Master Breakpoint: " | |
13254 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13255 | break; |
13256 | } | |
13257 | ||
001c8c33 | 13258 | return PRINT_NOTHING; |
06edf0c0 PA |
13259 | } |
13260 | ||
13261 | static void | |
13262 | internal_bkpt_print_mention (struct breakpoint *b) | |
13263 | { | |
13264 | /* Nothing to mention. These breakpoints are internal. */ | |
13265 | } | |
13266 | ||
06edf0c0 PA |
13267 | /* Virtual table for momentary breakpoints */ |
13268 | ||
13269 | static void | |
13270 | momentary_bkpt_re_set (struct breakpoint *b) | |
13271 | { | |
13272 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13273 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13274 | Otherwise these should have been blown away via the cleanup chain |
13275 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13276 | } | |
13277 | ||
13278 | static void | |
13279 | momentary_bkpt_check_status (bpstat bs) | |
13280 | { | |
13281 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13282 | } | |
13283 | ||
13284 | static enum print_stop_action | |
13285 | momentary_bkpt_print_it (bpstat bs) | |
13286 | { | |
79a45e25 PA |
13287 | struct ui_out *uiout = current_uiout; |
13288 | ||
001c8c33 | 13289 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13290 | { |
001c8c33 | 13291 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13292 | |
001c8c33 PA |
13293 | switch (b->type) |
13294 | { | |
13295 | case bp_finish: | |
13296 | ui_out_field_string | |
13297 | (uiout, "reason", | |
13298 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13299 | break; | |
348d480f | 13300 | |
001c8c33 PA |
13301 | case bp_until: |
13302 | ui_out_field_string | |
13303 | (uiout, "reason", | |
13304 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13305 | break; | |
13306 | } | |
348d480f PA |
13307 | } |
13308 | ||
001c8c33 | 13309 | return PRINT_UNKNOWN; |
348d480f PA |
13310 | } |
13311 | ||
06edf0c0 PA |
13312 | static void |
13313 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13314 | { |
06edf0c0 | 13315 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13316 | } |
13317 | ||
e2e4d78b JK |
13318 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13319 | ||
13320 | It gets cleared already on the removal of the first one of such placed | |
13321 | breakpoints. This is OK as they get all removed altogether. */ | |
13322 | ||
13323 | static void | |
13324 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13325 | { | |
13326 | struct thread_info *tp = find_thread_id (self->thread); | |
13327 | ||
13328 | if (tp) | |
13329 | tp->initiating_frame = null_frame_id; | |
13330 | ||
13331 | momentary_breakpoint_ops.dtor (self); | |
13332 | } | |
13333 | ||
55aa24fb SDJ |
13334 | /* Specific methods for probe breakpoints. */ |
13335 | ||
13336 | static int | |
13337 | bkpt_probe_insert_location (struct bp_location *bl) | |
13338 | { | |
13339 | int v = bkpt_insert_location (bl); | |
13340 | ||
13341 | if (v == 0) | |
13342 | { | |
13343 | /* The insertion was successful, now let's set the probe's semaphore | |
13344 | if needed. */ | |
729662a5 TT |
13345 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
13346 | bl->probe.objfile, | |
13347 | bl->gdbarch); | |
55aa24fb SDJ |
13348 | } |
13349 | ||
13350 | return v; | |
13351 | } | |
13352 | ||
13353 | static int | |
13354 | bkpt_probe_remove_location (struct bp_location *bl) | |
13355 | { | |
13356 | /* Let's clear the semaphore before removing the location. */ | |
729662a5 TT |
13357 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
13358 | bl->probe.objfile, | |
13359 | bl->gdbarch); | |
55aa24fb SDJ |
13360 | |
13361 | return bkpt_remove_location (bl); | |
13362 | } | |
13363 | ||
13364 | static void | |
13365 | bkpt_probe_create_sals_from_address (char **arg, | |
13366 | struct linespec_result *canonical, | |
13367 | enum bptype type_wanted, | |
13368 | char *addr_start, char **copy_arg) | |
13369 | { | |
13370 | struct linespec_sals lsal; | |
13371 | ||
13372 | lsal.sals = parse_probes (arg, canonical); | |
13373 | ||
13374 | *copy_arg = xstrdup (canonical->addr_string); | |
13375 | lsal.canonical = xstrdup (*copy_arg); | |
13376 | ||
13377 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13378 | } | |
13379 | ||
13380 | static void | |
13381 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13382 | struct symtabs_and_lines *sals) | |
13383 | { | |
13384 | *sals = parse_probes (s, NULL); | |
13385 | if (!sals->sals) | |
13386 | error (_("probe not found")); | |
13387 | } | |
13388 | ||
348d480f | 13389 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13390 | |
348d480f PA |
13391 | static void |
13392 | tracepoint_re_set (struct breakpoint *b) | |
13393 | { | |
13394 | breakpoint_re_set_default (b); | |
13395 | } | |
876fa593 | 13396 | |
348d480f PA |
13397 | static int |
13398 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13399 | struct address_space *aspace, CORE_ADDR bp_addr, |
13400 | const struct target_waitstatus *ws) | |
348d480f PA |
13401 | { |
13402 | /* By definition, the inferior does not report stops at | |
13403 | tracepoints. */ | |
13404 | return 0; | |
74960c60 VP |
13405 | } |
13406 | ||
13407 | static void | |
348d480f PA |
13408 | tracepoint_print_one_detail (const struct breakpoint *self, |
13409 | struct ui_out *uiout) | |
74960c60 | 13410 | { |
d9b3f62e PA |
13411 | struct tracepoint *tp = (struct tracepoint *) self; |
13412 | if (tp->static_trace_marker_id) | |
348d480f PA |
13413 | { |
13414 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13415 | |
348d480f PA |
13416 | ui_out_text (uiout, "\tmarker id is "); |
13417 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13418 | tp->static_trace_marker_id); |
348d480f PA |
13419 | ui_out_text (uiout, "\n"); |
13420 | } | |
0d381245 VP |
13421 | } |
13422 | ||
a474d7c2 | 13423 | static void |
348d480f | 13424 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13425 | { |
79a45e25 | 13426 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13427 | return; |
cc59ec59 | 13428 | |
348d480f PA |
13429 | switch (b->type) |
13430 | { | |
13431 | case bp_tracepoint: | |
13432 | printf_filtered (_("Tracepoint")); | |
13433 | printf_filtered (_(" %d"), b->number); | |
13434 | break; | |
13435 | case bp_fast_tracepoint: | |
13436 | printf_filtered (_("Fast tracepoint")); | |
13437 | printf_filtered (_(" %d"), b->number); | |
13438 | break; | |
13439 | case bp_static_tracepoint: | |
13440 | printf_filtered (_("Static tracepoint")); | |
13441 | printf_filtered (_(" %d"), b->number); | |
13442 | break; | |
13443 | default: | |
13444 | internal_error (__FILE__, __LINE__, | |
13445 | _("unhandled tracepoint type %d"), (int) b->type); | |
13446 | } | |
13447 | ||
13448 | say_where (b); | |
a474d7c2 PA |
13449 | } |
13450 | ||
348d480f | 13451 | static void |
d9b3f62e | 13452 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13453 | { |
d9b3f62e PA |
13454 | struct tracepoint *tp = (struct tracepoint *) self; |
13455 | ||
13456 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13457 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13458 | if (self->type == bp_static_tracepoint) |
348d480f | 13459 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13460 | else if (self->type == bp_tracepoint) |
348d480f PA |
13461 | fprintf_unfiltered (fp, "trace"); |
13462 | else | |
13463 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13464 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13465 | |
d9b3f62e PA |
13466 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13467 | print_recreate_thread (self, fp); | |
13468 | ||
13469 | if (tp->pass_count) | |
13470 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13471 | } |
13472 | ||
983af33b SDJ |
13473 | static void |
13474 | tracepoint_create_sals_from_address (char **arg, | |
13475 | struct linespec_result *canonical, | |
13476 | enum bptype type_wanted, | |
13477 | char *addr_start, char **copy_arg) | |
13478 | { | |
13479 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13480 | addr_start, copy_arg); | |
13481 | } | |
13482 | ||
13483 | static void | |
13484 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13485 | struct linespec_result *canonical, | |
983af33b | 13486 | char *cond_string, |
e7e0cddf | 13487 | char *extra_string, |
983af33b SDJ |
13488 | enum bptype type_wanted, |
13489 | enum bpdisp disposition, | |
13490 | int thread, | |
13491 | int task, int ignore_count, | |
13492 | const struct breakpoint_ops *ops, | |
13493 | int from_tty, int enabled, | |
44f238bb | 13494 | int internal, unsigned flags) |
983af33b | 13495 | { |
023fa29b | 13496 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13497 | cond_string, extra_string, |
13498 | type_wanted, | |
983af33b SDJ |
13499 | disposition, thread, task, |
13500 | ignore_count, ops, from_tty, | |
44f238bb | 13501 | enabled, internal, flags); |
983af33b SDJ |
13502 | } |
13503 | ||
13504 | static void | |
13505 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13506 | struct symtabs_and_lines *sals) | |
13507 | { | |
13508 | decode_linespec_default (b, s, sals); | |
13509 | } | |
13510 | ||
2060206e | 13511 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13512 | |
55aa24fb SDJ |
13513 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13514 | static probe. */ | |
13515 | ||
13516 | static void | |
13517 | tracepoint_probe_create_sals_from_address (char **arg, | |
13518 | struct linespec_result *canonical, | |
13519 | enum bptype type_wanted, | |
13520 | char *addr_start, char **copy_arg) | |
13521 | { | |
13522 | /* We use the same method for breakpoint on probes. */ | |
13523 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13524 | addr_start, copy_arg); | |
13525 | } | |
13526 | ||
13527 | static void | |
13528 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13529 | struct symtabs_and_lines *sals) | |
13530 | { | |
13531 | /* We use the same method for breakpoint on probes. */ | |
13532 | bkpt_probe_decode_linespec (b, s, sals); | |
13533 | } | |
13534 | ||
13535 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13536 | ||
5c2b4418 HZ |
13537 | /* Dprintf breakpoint_ops methods. */ |
13538 | ||
13539 | static void | |
13540 | dprintf_re_set (struct breakpoint *b) | |
13541 | { | |
13542 | breakpoint_re_set_default (b); | |
13543 | ||
13544 | /* This breakpoint could have been pending, and be resolved now, and | |
13545 | if so, we should now have the extra string. If we don't, the | |
13546 | dprintf was malformed when created, but we couldn't tell because | |
13547 | we can't extract the extra string until the location is | |
13548 | resolved. */ | |
13549 | if (b->loc != NULL && b->extra_string == NULL) | |
13550 | error (_("Format string required")); | |
13551 | ||
13552 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13553 | 2 - create a dprintf, which resolves fine. | |
13554 | 3 - disconnect from target 1 | |
13555 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13556 | ||
13557 | After steps #3/#4, you'll want the dprintf command list to | |
13558 | be updated, because target 1 and 2 may well return different | |
13559 | answers for target_can_run_breakpoint_commands(). | |
13560 | Given absence of finer grained resetting, we get to do | |
13561 | it all the time. */ | |
13562 | if (b->extra_string != NULL) | |
13563 | update_dprintf_command_list (b); | |
13564 | } | |
13565 | ||
2d9442cc HZ |
13566 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13567 | ||
13568 | static void | |
13569 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13570 | { | |
13571 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13572 | tp->extra_string); | |
13573 | print_recreate_thread (tp, fp); | |
13574 | } | |
13575 | ||
9d6e6e84 HZ |
13576 | /* Implement the "after_condition_true" breakpoint_ops method for |
13577 | dprintf. | |
13578 | ||
13579 | dprintf's are implemented with regular commands in their command | |
13580 | list, but we run the commands here instead of before presenting the | |
13581 | stop to the user, as dprintf's don't actually cause a stop. This | |
13582 | also makes it so that the commands of multiple dprintfs at the same | |
13583 | address are all handled. */ | |
13584 | ||
13585 | static void | |
13586 | dprintf_after_condition_true (struct bpstats *bs) | |
13587 | { | |
13588 | struct cleanup *old_chain; | |
13589 | struct bpstats tmp_bs = { NULL }; | |
13590 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13591 | ||
13592 | /* dprintf's never cause a stop. This wasn't set in the | |
13593 | check_status hook instead because that would make the dprintf's | |
13594 | condition not be evaluated. */ | |
13595 | bs->stop = 0; | |
13596 | ||
13597 | /* Run the command list here. Take ownership of it instead of | |
13598 | copying. We never want these commands to run later in | |
13599 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13600 | be set at same address as this dprintf, or even if running the | |
13601 | commands here throws. */ | |
13602 | tmp_bs.commands = bs->commands; | |
13603 | bs->commands = NULL; | |
13604 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13605 | ||
13606 | bpstat_do_actions_1 (&tmp_bs_p); | |
13607 | ||
13608 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13609 | bpstat_do_actions_1 may return early without processing the whole | |
13610 | list. */ | |
13611 | do_cleanups (old_chain); | |
13612 | } | |
13613 | ||
983af33b SDJ |
13614 | /* The breakpoint_ops structure to be used on static tracepoints with |
13615 | markers (`-m'). */ | |
13616 | ||
13617 | static void | |
13618 | strace_marker_create_sals_from_address (char **arg, | |
13619 | struct linespec_result *canonical, | |
13620 | enum bptype type_wanted, | |
13621 | char *addr_start, char **copy_arg) | |
13622 | { | |
13623 | struct linespec_sals lsal; | |
13624 | ||
13625 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13626 | ||
13627 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13628 | ||
13629 | canonical->addr_string = xstrdup (*copy_arg); | |
13630 | lsal.canonical = xstrdup (*copy_arg); | |
13631 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13632 | } | |
13633 | ||
13634 | static void | |
13635 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13636 | struct linespec_result *canonical, | |
983af33b | 13637 | char *cond_string, |
e7e0cddf | 13638 | char *extra_string, |
983af33b SDJ |
13639 | enum bptype type_wanted, |
13640 | enum bpdisp disposition, | |
13641 | int thread, | |
13642 | int task, int ignore_count, | |
13643 | const struct breakpoint_ops *ops, | |
13644 | int from_tty, int enabled, | |
44f238bb | 13645 | int internal, unsigned flags) |
983af33b SDJ |
13646 | { |
13647 | int i; | |
52d361e1 YQ |
13648 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13649 | canonical->sals, 0); | |
983af33b SDJ |
13650 | |
13651 | /* If the user is creating a static tracepoint by marker id | |
13652 | (strace -m MARKER_ID), then store the sals index, so that | |
13653 | breakpoint_re_set can try to match up which of the newly | |
13654 | found markers corresponds to this one, and, don't try to | |
13655 | expand multiple locations for each sal, given than SALS | |
13656 | already should contain all sals for MARKER_ID. */ | |
13657 | ||
13658 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13659 | { | |
13660 | struct symtabs_and_lines expanded; | |
13661 | struct tracepoint *tp; | |
13662 | struct cleanup *old_chain; | |
13663 | char *addr_string; | |
13664 | ||
13665 | expanded.nelts = 1; | |
13666 | expanded.sals = &lsal->sals.sals[i]; | |
13667 | ||
13668 | addr_string = xstrdup (canonical->addr_string); | |
13669 | old_chain = make_cleanup (xfree, addr_string); | |
13670 | ||
13671 | tp = XCNEW (struct tracepoint); | |
13672 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13673 | addr_string, NULL, | |
e7e0cddf SS |
13674 | cond_string, extra_string, |
13675 | type_wanted, disposition, | |
983af33b | 13676 | thread, task, ignore_count, ops, |
44f238bb | 13677 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13678 | canonical->special_display); |
13679 | /* Given that its possible to have multiple markers with | |
13680 | the same string id, if the user is creating a static | |
13681 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13682 | store the sals index, so that breakpoint_re_set can | |
13683 | try to match up which of the newly found markers | |
13684 | corresponds to this one */ | |
13685 | tp->static_trace_marker_id_idx = i; | |
13686 | ||
13687 | install_breakpoint (internal, &tp->base, 0); | |
13688 | ||
13689 | discard_cleanups (old_chain); | |
13690 | } | |
13691 | } | |
13692 | ||
13693 | static void | |
13694 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13695 | struct symtabs_and_lines *sals) | |
13696 | { | |
13697 | struct tracepoint *tp = (struct tracepoint *) b; | |
13698 | ||
13699 | *sals = decode_static_tracepoint_spec (s); | |
13700 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13701 | { | |
13702 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13703 | sals->nelts = 1; | |
13704 | } | |
13705 | else | |
13706 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13707 | } | |
13708 | ||
13709 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13710 | ||
13711 | static int | |
13712 | strace_marker_p (struct breakpoint *b) | |
13713 | { | |
13714 | return b->ops == &strace_marker_breakpoint_ops; | |
13715 | } | |
13716 | ||
53a5351d | 13717 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13718 | structures. */ |
c906108c SS |
13719 | |
13720 | void | |
fba45db2 | 13721 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13722 | { |
52f0bd74 | 13723 | struct breakpoint *b; |
c906108c | 13724 | |
8a3fe4f8 | 13725 | gdb_assert (bpt != NULL); |
c906108c | 13726 | |
4a64f543 MS |
13727 | /* Has this bp already been deleted? This can happen because |
13728 | multiple lists can hold pointers to bp's. bpstat lists are | |
13729 | especial culprits. | |
13730 | ||
13731 | One example of this happening is a watchpoint's scope bp. When | |
13732 | the scope bp triggers, we notice that the watchpoint is out of | |
13733 | scope, and delete it. We also delete its scope bp. But the | |
13734 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13735 | That bpstat is then checked for auto-deleting bp's, which are | |
13736 | deleted. | |
13737 | ||
13738 | A real solution to this problem might involve reference counts in | |
13739 | bp's, and/or giving them pointers back to their referencing | |
13740 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13741 | storage when no more references were extent. A cheaper bandaid | |
13742 | was chosen. */ | |
c906108c SS |
13743 | if (bpt->type == bp_none) |
13744 | return; | |
13745 | ||
4a64f543 MS |
13746 | /* At least avoid this stale reference until the reference counting |
13747 | of breakpoints gets resolved. */ | |
d0fb5eae | 13748 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13749 | { |
d0fb5eae | 13750 | struct breakpoint *related; |
3a5c3e22 | 13751 | struct watchpoint *w; |
d0fb5eae JK |
13752 | |
13753 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13754 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13755 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13756 | w = (struct watchpoint *) bpt; |
13757 | else | |
13758 | w = NULL; | |
13759 | if (w != NULL) | |
13760 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13761 | |
13762 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13763 | for (related = bpt; related->related_breakpoint != bpt; | |
13764 | related = related->related_breakpoint); | |
13765 | related->related_breakpoint = bpt->related_breakpoint; | |
13766 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13767 | } |
13768 | ||
a9634178 TJB |
13769 | /* watch_command_1 creates a watchpoint but only sets its number if |
13770 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13771 | a problem in that process, we'll be asked to delete the half-created | |
13772 | watchpoint. In that case, don't announce the deletion. */ | |
13773 | if (bpt->number) | |
13774 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13775 | |
c906108c SS |
13776 | if (breakpoint_chain == bpt) |
13777 | breakpoint_chain = bpt->next; | |
13778 | ||
c906108c SS |
13779 | ALL_BREAKPOINTS (b) |
13780 | if (b->next == bpt) | |
c5aa993b JM |
13781 | { |
13782 | b->next = bpt->next; | |
13783 | break; | |
13784 | } | |
c906108c | 13785 | |
f431efe5 PA |
13786 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13787 | been freed. */ | |
13788 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13789 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13790 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13791 | commands are associated with the bpstat; if we remove it here, | |
13792 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13793 | event-top.c won't do anything, and temporary breakpoints with | |
13794 | commands won't work. */ | |
13795 | ||
13796 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13797 | ||
4a64f543 MS |
13798 | /* Now that breakpoint is removed from breakpoint list, update the |
13799 | global location list. This will remove locations that used to | |
13800 | belong to this breakpoint. Do this before freeing the breakpoint | |
13801 | itself, since remove_breakpoint looks at location's owner. It | |
13802 | might be better design to have location completely | |
13803 | self-contained, but it's not the case now. */ | |
b60e7edf | 13804 | update_global_location_list (0); |
74960c60 | 13805 | |
348d480f | 13806 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13807 | /* On the chance that someone will soon try again to delete this |
13808 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13809 | bpt->type = bp_none; |
b8c9b27d | 13810 | xfree (bpt); |
c906108c SS |
13811 | } |
13812 | ||
4d6140d9 AC |
13813 | static void |
13814 | do_delete_breakpoint_cleanup (void *b) | |
13815 | { | |
13816 | delete_breakpoint (b); | |
13817 | } | |
13818 | ||
13819 | struct cleanup * | |
13820 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13821 | { | |
13822 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13823 | } | |
13824 | ||
51be5b68 PA |
13825 | /* Iterator function to call a user-provided callback function once |
13826 | for each of B and its related breakpoints. */ | |
13827 | ||
13828 | static void | |
13829 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13830 | void (*function) (struct breakpoint *, | |
13831 | void *), | |
13832 | void *data) | |
13833 | { | |
13834 | struct breakpoint *related; | |
13835 | ||
13836 | related = b; | |
13837 | do | |
13838 | { | |
13839 | struct breakpoint *next; | |
13840 | ||
13841 | /* FUNCTION may delete RELATED. */ | |
13842 | next = related->related_breakpoint; | |
13843 | ||
13844 | if (next == related) | |
13845 | { | |
13846 | /* RELATED is the last ring entry. */ | |
13847 | function (related, data); | |
13848 | ||
13849 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13850 | B. There's nothing left to do anyway, so just break | |
13851 | out. */ | |
13852 | break; | |
13853 | } | |
13854 | else | |
13855 | function (related, data); | |
13856 | ||
13857 | related = next; | |
13858 | } | |
13859 | while (related != b); | |
13860 | } | |
95a42b64 TT |
13861 | |
13862 | static void | |
13863 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13864 | { | |
13865 | delete_breakpoint (b); | |
13866 | } | |
13867 | ||
51be5b68 PA |
13868 | /* A callback for map_breakpoint_numbers that calls |
13869 | delete_breakpoint. */ | |
13870 | ||
13871 | static void | |
13872 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13873 | { | |
13874 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13875 | } | |
13876 | ||
c906108c | 13877 | void |
fba45db2 | 13878 | delete_command (char *arg, int from_tty) |
c906108c | 13879 | { |
35df4500 | 13880 | struct breakpoint *b, *b_tmp; |
c906108c | 13881 | |
ea9365bb TT |
13882 | dont_repeat (); |
13883 | ||
c906108c SS |
13884 | if (arg == 0) |
13885 | { | |
13886 | int breaks_to_delete = 0; | |
13887 | ||
46c6471b PA |
13888 | /* Delete all breakpoints if no argument. Do not delete |
13889 | internal breakpoints, these have to be deleted with an | |
13890 | explicit breakpoint number argument. */ | |
c5aa993b | 13891 | ALL_BREAKPOINTS (b) |
46c6471b | 13892 | if (user_breakpoint_p (b)) |
973d738b DJ |
13893 | { |
13894 | breaks_to_delete = 1; | |
13895 | break; | |
13896 | } | |
c906108c SS |
13897 | |
13898 | /* Ask user only if there are some breakpoints to delete. */ | |
13899 | if (!from_tty | |
e2e0b3e5 | 13900 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13901 | { |
35df4500 | 13902 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13903 | if (user_breakpoint_p (b)) |
c5aa993b | 13904 | delete_breakpoint (b); |
c906108c SS |
13905 | } |
13906 | } | |
13907 | else | |
51be5b68 | 13908 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13909 | } |
13910 | ||
0d381245 VP |
13911 | static int |
13912 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13913 | { |
0d381245 | 13914 | for (; loc; loc = loc->next) |
8645ff69 UW |
13915 | if (!loc->shlib_disabled |
13916 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13917 | return 0; |
13918 | return 1; | |
fe3f5fa8 VP |
13919 | } |
13920 | ||
776592bf DE |
13921 | /* Subroutine of update_breakpoint_locations to simplify it. |
13922 | Return non-zero if multiple fns in list LOC have the same name. | |
13923 | Null names are ignored. */ | |
13924 | ||
13925 | static int | |
13926 | ambiguous_names_p (struct bp_location *loc) | |
13927 | { | |
13928 | struct bp_location *l; | |
13929 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13930 | (int (*) (const void *, |
13931 | const void *)) streq, | |
776592bf DE |
13932 | NULL, xcalloc, xfree); |
13933 | ||
13934 | for (l = loc; l != NULL; l = l->next) | |
13935 | { | |
13936 | const char **slot; | |
13937 | const char *name = l->function_name; | |
13938 | ||
13939 | /* Allow for some names to be NULL, ignore them. */ | |
13940 | if (name == NULL) | |
13941 | continue; | |
13942 | ||
13943 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13944 | INSERT); | |
4a64f543 MS |
13945 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13946 | returns NULL. */ | |
776592bf DE |
13947 | if (*slot != NULL) |
13948 | { | |
13949 | htab_delete (htab); | |
13950 | return 1; | |
13951 | } | |
13952 | *slot = name; | |
13953 | } | |
13954 | ||
13955 | htab_delete (htab); | |
13956 | return 0; | |
13957 | } | |
13958 | ||
0fb4aa4b PA |
13959 | /* When symbols change, it probably means the sources changed as well, |
13960 | and it might mean the static tracepoint markers are no longer at | |
13961 | the same address or line numbers they used to be at last we | |
13962 | checked. Losing your static tracepoints whenever you rebuild is | |
13963 | undesirable. This function tries to resync/rematch gdb static | |
13964 | tracepoints with the markers on the target, for static tracepoints | |
13965 | that have not been set by marker id. Static tracepoint that have | |
13966 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13967 | The heuristic is: | |
13968 | ||
13969 | 1) For a tracepoint set at a specific address, look for a marker at | |
13970 | the old PC. If one is found there, assume to be the same marker. | |
13971 | If the name / string id of the marker found is different from the | |
13972 | previous known name, assume that means the user renamed the marker | |
13973 | in the sources, and output a warning. | |
13974 | ||
13975 | 2) For a tracepoint set at a given line number, look for a marker | |
13976 | at the new address of the old line number. If one is found there, | |
13977 | assume to be the same marker. If the name / string id of the | |
13978 | marker found is different from the previous known name, assume that | |
13979 | means the user renamed the marker in the sources, and output a | |
13980 | warning. | |
13981 | ||
13982 | 3) If a marker is no longer found at the same address or line, it | |
13983 | may mean the marker no longer exists. But it may also just mean | |
13984 | the code changed a bit. Maybe the user added a few lines of code | |
13985 | that made the marker move up or down (in line number terms). Ask | |
13986 | the target for info about the marker with the string id as we knew | |
13987 | it. If found, update line number and address in the matching | |
13988 | static tracepoint. This will get confused if there's more than one | |
13989 | marker with the same ID (possible in UST, although unadvised | |
13990 | precisely because it confuses tools). */ | |
13991 | ||
13992 | static struct symtab_and_line | |
13993 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13994 | { | |
d9b3f62e | 13995 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13996 | struct static_tracepoint_marker marker; |
13997 | CORE_ADDR pc; | |
0fb4aa4b PA |
13998 | |
13999 | pc = sal.pc; | |
14000 | if (sal.line) | |
14001 | find_line_pc (sal.symtab, sal.line, &pc); | |
14002 | ||
14003 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14004 | { | |
d9b3f62e | 14005 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14006 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14007 | b->number, | |
d9b3f62e | 14008 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14009 | |
d9b3f62e PA |
14010 | xfree (tp->static_trace_marker_id); |
14011 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14012 | release_static_tracepoint_marker (&marker); |
14013 | ||
14014 | return sal; | |
14015 | } | |
14016 | ||
14017 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14018 | by string ID. */ | |
14019 | if (!sal.explicit_pc | |
14020 | && sal.line != 0 | |
14021 | && sal.symtab != NULL | |
d9b3f62e | 14022 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14023 | { |
14024 | VEC(static_tracepoint_marker_p) *markers; | |
14025 | ||
14026 | markers | |
d9b3f62e | 14027 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14028 | |
14029 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14030 | { | |
80e1d417 | 14031 | struct symtab_and_line sal2; |
0fb4aa4b | 14032 | struct symbol *sym; |
80e1d417 | 14033 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14034 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14035 | |
80e1d417 | 14036 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14037 | |
d9b3f62e | 14038 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14039 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14040 | |
14041 | warning (_("marker for static tracepoint %d (%s) not " | |
14042 | "found at previous line number"), | |
d9b3f62e | 14043 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14044 | |
80e1d417 | 14045 | init_sal (&sal2); |
0fb4aa4b | 14046 | |
80e1d417 | 14047 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14048 | |
80e1d417 AS |
14049 | sal2 = find_pc_line (tpmarker->address, 0); |
14050 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14051 | ui_out_text (uiout, "Now in "); |
14052 | if (sym) | |
14053 | { | |
14054 | ui_out_field_string (uiout, "func", | |
14055 | SYMBOL_PRINT_NAME (sym)); | |
14056 | ui_out_text (uiout, " at "); | |
14057 | } | |
05cba821 JK |
14058 | ui_out_field_string (uiout, "file", |
14059 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14060 | ui_out_text (uiout, ":"); |
14061 | ||
14062 | if (ui_out_is_mi_like_p (uiout)) | |
14063 | { | |
0b0865da | 14064 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14065 | |
f35a17b5 | 14066 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14067 | } |
14068 | ||
80e1d417 | 14069 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14070 | ui_out_text (uiout, "\n"); |
14071 | ||
80e1d417 | 14072 | b->loc->line_number = sal2.line; |
2f202fde | 14073 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14074 | |
14075 | xfree (b->addr_string); | |
14076 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14077 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14078 | b->loc->line_number); |
0fb4aa4b PA |
14079 | |
14080 | /* Might be nice to check if function changed, and warn if | |
14081 | so. */ | |
14082 | ||
80e1d417 | 14083 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14084 | } |
14085 | } | |
14086 | return sal; | |
14087 | } | |
14088 | ||
8d3788bd VP |
14089 | /* Returns 1 iff locations A and B are sufficiently same that |
14090 | we don't need to report breakpoint as changed. */ | |
14091 | ||
14092 | static int | |
14093 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14094 | { | |
14095 | while (a && b) | |
14096 | { | |
14097 | if (a->address != b->address) | |
14098 | return 0; | |
14099 | ||
14100 | if (a->shlib_disabled != b->shlib_disabled) | |
14101 | return 0; | |
14102 | ||
14103 | if (a->enabled != b->enabled) | |
14104 | return 0; | |
14105 | ||
14106 | a = a->next; | |
14107 | b = b->next; | |
14108 | } | |
14109 | ||
14110 | if ((a == NULL) != (b == NULL)) | |
14111 | return 0; | |
14112 | ||
14113 | return 1; | |
14114 | } | |
14115 | ||
f1310107 TJB |
14116 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14117 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14118 | a ranged breakpoint. */ | |
14119 | ||
0e30163f | 14120 | void |
0d381245 | 14121 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14122 | struct symtabs_and_lines sals, |
14123 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14124 | { |
14125 | int i; | |
0d381245 VP |
14126 | struct bp_location *existing_locations = b->loc; |
14127 | ||
f8eba3c6 TT |
14128 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14129 | { | |
14130 | /* Ranged breakpoints have only one start location and one end | |
14131 | location. */ | |
14132 | b->enable_state = bp_disabled; | |
14133 | update_global_location_list (1); | |
14134 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14135 | "multiple locations found\n"), | |
14136 | b->number); | |
14137 | return; | |
14138 | } | |
f1310107 | 14139 | |
4a64f543 MS |
14140 | /* If there's no new locations, and all existing locations are |
14141 | pending, don't do anything. This optimizes the common case where | |
14142 | all locations are in the same shared library, that was unloaded. | |
14143 | We'd like to retain the location, so that when the library is | |
14144 | loaded again, we don't loose the enabled/disabled status of the | |
14145 | individual locations. */ | |
0d381245 | 14146 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14147 | return; |
14148 | ||
fe3f5fa8 VP |
14149 | b->loc = NULL; |
14150 | ||
0d381245 | 14151 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14152 | { |
f8eba3c6 TT |
14153 | struct bp_location *new_loc; |
14154 | ||
14155 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14156 | ||
14157 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14158 | |
0d381245 VP |
14159 | /* Reparse conditions, they might contain references to the |
14160 | old symtab. */ | |
14161 | if (b->cond_string != NULL) | |
14162 | { | |
bbc13ae3 | 14163 | const char *s; |
bfd189b1 | 14164 | volatile struct gdb_exception e; |
fe3f5fa8 | 14165 | |
0d381245 VP |
14166 | s = b->cond_string; |
14167 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14168 | { | |
1bb9788d TT |
14169 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14170 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14171 | 0); |
14172 | } | |
14173 | if (e.reason < 0) | |
14174 | { | |
3e43a32a MS |
14175 | warning (_("failed to reevaluate condition " |
14176 | "for breakpoint %d: %s"), | |
0d381245 VP |
14177 | b->number, e.message); |
14178 | new_loc->enabled = 0; | |
14179 | } | |
14180 | } | |
fe3f5fa8 | 14181 | |
f1310107 TJB |
14182 | if (sals_end.nelts) |
14183 | { | |
14184 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14185 | ||
14186 | new_loc->length = end - sals.sals[0].pc + 1; | |
14187 | } | |
0d381245 | 14188 | } |
fe3f5fa8 | 14189 | |
514f746b AR |
14190 | /* Update locations of permanent breakpoints. */ |
14191 | if (b->enable_state == bp_permanent) | |
14192 | make_breakpoint_permanent (b); | |
14193 | ||
4a64f543 MS |
14194 | /* If possible, carry over 'disable' status from existing |
14195 | breakpoints. */ | |
0d381245 VP |
14196 | { |
14197 | struct bp_location *e = existing_locations; | |
776592bf DE |
14198 | /* If there are multiple breakpoints with the same function name, |
14199 | e.g. for inline functions, comparing function names won't work. | |
14200 | Instead compare pc addresses; this is just a heuristic as things | |
14201 | may have moved, but in practice it gives the correct answer | |
14202 | often enough until a better solution is found. */ | |
14203 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14204 | ||
0d381245 VP |
14205 | for (; e; e = e->next) |
14206 | { | |
14207 | if (!e->enabled && e->function_name) | |
14208 | { | |
14209 | struct bp_location *l = b->loc; | |
776592bf DE |
14210 | if (have_ambiguous_names) |
14211 | { | |
14212 | for (; l; l = l->next) | |
f1310107 | 14213 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14214 | { |
14215 | l->enabled = 0; | |
14216 | break; | |
14217 | } | |
14218 | } | |
14219 | else | |
14220 | { | |
14221 | for (; l; l = l->next) | |
14222 | if (l->function_name | |
14223 | && strcmp (e->function_name, l->function_name) == 0) | |
14224 | { | |
14225 | l->enabled = 0; | |
14226 | break; | |
14227 | } | |
14228 | } | |
0d381245 VP |
14229 | } |
14230 | } | |
14231 | } | |
fe3f5fa8 | 14232 | |
8d3788bd VP |
14233 | if (!locations_are_equal (existing_locations, b->loc)) |
14234 | observer_notify_breakpoint_modified (b); | |
14235 | ||
b60e7edf | 14236 | update_global_location_list (1); |
fe3f5fa8 VP |
14237 | } |
14238 | ||
ef23e705 TJB |
14239 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14240 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14241 | ||
14242 | static struct symtabs_and_lines | |
14243 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14244 | { | |
14245 | char *s; | |
02d20e4a | 14246 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14247 | volatile struct gdb_exception e; |
ef23e705 | 14248 | |
983af33b | 14249 | gdb_assert (b->ops != NULL); |
ef23e705 | 14250 | s = addr_string; |
ef23e705 TJB |
14251 | |
14252 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14253 | { | |
983af33b | 14254 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14255 | } |
14256 | if (e.reason < 0) | |
14257 | { | |
14258 | int not_found_and_ok = 0; | |
14259 | /* For pending breakpoints, it's expected that parsing will | |
14260 | fail until the right shared library is loaded. User has | |
14261 | already told to create pending breakpoints and don't need | |
14262 | extra messages. If breakpoint is in bp_shlib_disabled | |
14263 | state, then user already saw the message about that | |
14264 | breakpoint being disabled, and don't want to see more | |
14265 | errors. */ | |
58438ac1 | 14266 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14267 | && (b->condition_not_parsed |
14268 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14269 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14270 | || b->enable_state == bp_disabled)) |
14271 | not_found_and_ok = 1; | |
14272 | ||
14273 | if (!not_found_and_ok) | |
14274 | { | |
14275 | /* We surely don't want to warn about the same breakpoint | |
14276 | 10 times. One solution, implemented here, is disable | |
14277 | the breakpoint on error. Another solution would be to | |
14278 | have separate 'warning emitted' flag. Since this | |
14279 | happens only when a binary has changed, I don't know | |
14280 | which approach is better. */ | |
14281 | b->enable_state = bp_disabled; | |
14282 | throw_exception (e); | |
14283 | } | |
14284 | } | |
14285 | ||
58438ac1 | 14286 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14287 | { |
f8eba3c6 | 14288 | int i; |
ef23e705 | 14289 | |
f8eba3c6 TT |
14290 | for (i = 0; i < sals.nelts; ++i) |
14291 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14292 | if (b->condition_not_parsed && s && s[0]) |
14293 | { | |
ed1d1739 KS |
14294 | char *cond_string, *extra_string; |
14295 | int thread, task; | |
ef23e705 TJB |
14296 | |
14297 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14298 | &cond_string, &thread, &task, |
14299 | &extra_string); | |
ef23e705 TJB |
14300 | if (cond_string) |
14301 | b->cond_string = cond_string; | |
14302 | b->thread = thread; | |
14303 | b->task = task; | |
e7e0cddf SS |
14304 | if (extra_string) |
14305 | b->extra_string = extra_string; | |
ef23e705 TJB |
14306 | b->condition_not_parsed = 0; |
14307 | } | |
14308 | ||
983af33b | 14309 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14310 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14311 | |
58438ac1 TT |
14312 | *found = 1; |
14313 | } | |
14314 | else | |
14315 | *found = 0; | |
ef23e705 TJB |
14316 | |
14317 | return sals; | |
14318 | } | |
14319 | ||
348d480f PA |
14320 | /* The default re_set method, for typical hardware or software |
14321 | breakpoints. Reevaluate the breakpoint and recreate its | |
14322 | locations. */ | |
14323 | ||
14324 | static void | |
28010a5d | 14325 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14326 | { |
14327 | int found; | |
f1310107 | 14328 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14329 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14330 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14331 | |
14332 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14333 | if (found) | |
14334 | { | |
14335 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14336 | expanded = sals; |
ef23e705 TJB |
14337 | } |
14338 | ||
f1310107 TJB |
14339 | if (b->addr_string_range_end) |
14340 | { | |
14341 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14342 | if (found) | |
14343 | { | |
14344 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14345 | expanded_end = sals_end; |
f1310107 TJB |
14346 | } |
14347 | } | |
14348 | ||
14349 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14350 | } |
14351 | ||
983af33b SDJ |
14352 | /* Default method for creating SALs from an address string. It basically |
14353 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14354 | ||
14355 | static void | |
14356 | create_sals_from_address_default (char **arg, | |
14357 | struct linespec_result *canonical, | |
14358 | enum bptype type_wanted, | |
14359 | char *addr_start, char **copy_arg) | |
14360 | { | |
14361 | parse_breakpoint_sals (arg, canonical); | |
14362 | } | |
14363 | ||
14364 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14365 | function for the `create_breakpoints_sal' method of | |
14366 | breakpoint_ops. */ | |
14367 | ||
14368 | static void | |
14369 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14370 | struct linespec_result *canonical, | |
983af33b | 14371 | char *cond_string, |
e7e0cddf | 14372 | char *extra_string, |
983af33b SDJ |
14373 | enum bptype type_wanted, |
14374 | enum bpdisp disposition, | |
14375 | int thread, | |
14376 | int task, int ignore_count, | |
14377 | const struct breakpoint_ops *ops, | |
14378 | int from_tty, int enabled, | |
44f238bb | 14379 | int internal, unsigned flags) |
983af33b SDJ |
14380 | { |
14381 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14382 | extra_string, |
983af33b SDJ |
14383 | type_wanted, disposition, |
14384 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14385 | enabled, internal, flags); |
983af33b SDJ |
14386 | } |
14387 | ||
14388 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14389 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14390 | ||
14391 | static void | |
14392 | decode_linespec_default (struct breakpoint *b, char **s, | |
14393 | struct symtabs_and_lines *sals) | |
14394 | { | |
14395 | struct linespec_result canonical; | |
14396 | ||
14397 | init_linespec_result (&canonical); | |
14398 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14399 | (struct symtab *) NULL, 0, | |
14400 | &canonical, multiple_symbols_all, | |
14401 | b->filter); | |
14402 | ||
14403 | /* We should get 0 or 1 resulting SALs. */ | |
14404 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14405 | ||
14406 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14407 | { | |
14408 | struct linespec_sals *lsal; | |
14409 | ||
14410 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14411 | *sals = lsal->sals; | |
14412 | /* Arrange it so the destructor does not free the | |
14413 | contents. */ | |
14414 | lsal->sals.sals = NULL; | |
14415 | } | |
14416 | ||
14417 | destroy_linespec_result (&canonical); | |
14418 | } | |
14419 | ||
28010a5d PA |
14420 | /* Prepare the global context for a re-set of breakpoint B. */ |
14421 | ||
14422 | static struct cleanup * | |
14423 | prepare_re_set_context (struct breakpoint *b) | |
14424 | { | |
14425 | struct cleanup *cleanups; | |
14426 | ||
14427 | input_radix = b->input_radix; | |
14428 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14429 | if (b->pspace != NULL) |
14430 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14431 | set_language (b->language); |
14432 | ||
14433 | return cleanups; | |
ef23e705 TJB |
14434 | } |
14435 | ||
c906108c SS |
14436 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14437 | The value we return ends up being the return value from catch_errors. | |
14438 | Unused in this case. */ | |
14439 | ||
14440 | static int | |
4efb68b1 | 14441 | breakpoint_re_set_one (void *bint) |
c906108c | 14442 | { |
4a64f543 | 14443 | /* Get past catch_errs. */ |
53a5351d | 14444 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14445 | struct cleanup *cleanups; |
c906108c | 14446 | |
348d480f PA |
14447 | cleanups = prepare_re_set_context (b); |
14448 | b->ops->re_set (b); | |
14449 | do_cleanups (cleanups); | |
c906108c SS |
14450 | return 0; |
14451 | } | |
14452 | ||
69de3c6a | 14453 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14454 | void |
69de3c6a | 14455 | breakpoint_re_set (void) |
c906108c | 14456 | { |
35df4500 | 14457 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14458 | enum language save_language; |
14459 | int save_input_radix; | |
6c95b8df | 14460 | struct cleanup *old_chain; |
c5aa993b | 14461 | |
c906108c SS |
14462 | save_language = current_language->la_language; |
14463 | save_input_radix = input_radix; | |
6c95b8df PA |
14464 | old_chain = save_current_program_space (); |
14465 | ||
35df4500 | 14466 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14467 | { |
4a64f543 | 14468 | /* Format possible error msg. */ |
fe3f5fa8 | 14469 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14470 | b->number); |
14471 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14472 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14473 | do_cleanups (cleanups); |
c5aa993b | 14474 | } |
c906108c SS |
14475 | set_language (save_language); |
14476 | input_radix = save_input_radix; | |
e62c965a | 14477 | |
0756c555 | 14478 | jit_breakpoint_re_set (); |
4efc6507 | 14479 | |
6c95b8df PA |
14480 | do_cleanups (old_chain); |
14481 | ||
af02033e PP |
14482 | create_overlay_event_breakpoint (); |
14483 | create_longjmp_master_breakpoint (); | |
14484 | create_std_terminate_master_breakpoint (); | |
186c406b | 14485 | create_exception_master_breakpoint (); |
c906108c SS |
14486 | } |
14487 | \f | |
c906108c SS |
14488 | /* Reset the thread number of this breakpoint: |
14489 | ||
14490 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14491 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14492 | void |
fba45db2 | 14493 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14494 | { |
14495 | if (b->thread != -1) | |
14496 | { | |
39f77062 KB |
14497 | if (in_thread_list (inferior_ptid)) |
14498 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14499 | |
14500 | /* We're being called after following a fork. The new fork is | |
14501 | selected as current, and unless this was a vfork will have a | |
14502 | different program space from the original thread. Reset that | |
14503 | as well. */ | |
14504 | b->loc->pspace = current_program_space; | |
c906108c SS |
14505 | } |
14506 | } | |
14507 | ||
03ac34d5 MS |
14508 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14509 | If from_tty is nonzero, it prints a message to that effect, | |
14510 | which ends with a period (no newline). */ | |
14511 | ||
c906108c | 14512 | void |
fba45db2 | 14513 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14514 | { |
52f0bd74 | 14515 | struct breakpoint *b; |
c906108c SS |
14516 | |
14517 | if (count < 0) | |
14518 | count = 0; | |
14519 | ||
14520 | ALL_BREAKPOINTS (b) | |
14521 | if (b->number == bptnum) | |
c5aa993b | 14522 | { |
d77f58be SS |
14523 | if (is_tracepoint (b)) |
14524 | { | |
14525 | if (from_tty && count != 0) | |
14526 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14527 | bptnum); | |
14528 | return; | |
14529 | } | |
14530 | ||
c5aa993b | 14531 | b->ignore_count = count; |
221ea385 KS |
14532 | if (from_tty) |
14533 | { | |
14534 | if (count == 0) | |
3e43a32a MS |
14535 | printf_filtered (_("Will stop next time " |
14536 | "breakpoint %d is reached."), | |
221ea385 KS |
14537 | bptnum); |
14538 | else if (count == 1) | |
a3f17187 | 14539 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14540 | bptnum); |
14541 | else | |
3e43a32a MS |
14542 | printf_filtered (_("Will ignore next %d " |
14543 | "crossings of breakpoint %d."), | |
221ea385 KS |
14544 | count, bptnum); |
14545 | } | |
8d3788bd | 14546 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14547 | return; |
14548 | } | |
c906108c | 14549 | |
8a3fe4f8 | 14550 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14551 | } |
14552 | ||
c906108c SS |
14553 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14554 | ||
14555 | static void | |
fba45db2 | 14556 | ignore_command (char *args, int from_tty) |
c906108c SS |
14557 | { |
14558 | char *p = args; | |
52f0bd74 | 14559 | int num; |
c906108c SS |
14560 | |
14561 | if (p == 0) | |
e2e0b3e5 | 14562 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14563 | |
c906108c | 14564 | num = get_number (&p); |
5c44784c | 14565 | if (num == 0) |
8a3fe4f8 | 14566 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14567 | if (*p == 0) |
8a3fe4f8 | 14568 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14569 | |
14570 | set_ignore_count (num, | |
14571 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14572 | from_tty); | |
221ea385 KS |
14573 | if (from_tty) |
14574 | printf_filtered ("\n"); | |
c906108c SS |
14575 | } |
14576 | \f | |
14577 | /* Call FUNCTION on each of the breakpoints | |
14578 | whose numbers are given in ARGS. */ | |
14579 | ||
14580 | static void | |
95a42b64 TT |
14581 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14582 | void *), | |
14583 | void *data) | |
c906108c | 14584 | { |
52f0bd74 AC |
14585 | int num; |
14586 | struct breakpoint *b, *tmp; | |
11cf8741 | 14587 | int match; |
197f0a60 | 14588 | struct get_number_or_range_state state; |
c906108c | 14589 | |
197f0a60 | 14590 | if (args == 0) |
e2e0b3e5 | 14591 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14592 | |
197f0a60 TT |
14593 | init_number_or_range (&state, args); |
14594 | ||
14595 | while (!state.finished) | |
c906108c | 14596 | { |
197f0a60 TT |
14597 | char *p = state.string; |
14598 | ||
11cf8741 | 14599 | match = 0; |
c5aa993b | 14600 | |
197f0a60 | 14601 | num = get_number_or_range (&state); |
5c44784c | 14602 | if (num == 0) |
c5aa993b | 14603 | { |
8a3fe4f8 | 14604 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14605 | } |
14606 | else | |
14607 | { | |
14608 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14609 | if (b->number == num) | |
14610 | { | |
11cf8741 | 14611 | match = 1; |
cdac0397 | 14612 | function (b, data); |
11cf8741 | 14613 | break; |
5c44784c | 14614 | } |
11cf8741 | 14615 | if (match == 0) |
a3f17187 | 14616 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14617 | } |
c906108c SS |
14618 | } |
14619 | } | |
14620 | ||
0d381245 VP |
14621 | static struct bp_location * |
14622 | find_location_by_number (char *number) | |
14623 | { | |
14624 | char *dot = strchr (number, '.'); | |
14625 | char *p1; | |
14626 | int bp_num; | |
14627 | int loc_num; | |
14628 | struct breakpoint *b; | |
14629 | struct bp_location *loc; | |
14630 | ||
14631 | *dot = '\0'; | |
14632 | ||
14633 | p1 = number; | |
197f0a60 | 14634 | bp_num = get_number (&p1); |
0d381245 VP |
14635 | if (bp_num == 0) |
14636 | error (_("Bad breakpoint number '%s'"), number); | |
14637 | ||
14638 | ALL_BREAKPOINTS (b) | |
14639 | if (b->number == bp_num) | |
14640 | { | |
14641 | break; | |
14642 | } | |
14643 | ||
14644 | if (!b || b->number != bp_num) | |
14645 | error (_("Bad breakpoint number '%s'"), number); | |
14646 | ||
14647 | p1 = dot+1; | |
197f0a60 | 14648 | loc_num = get_number (&p1); |
0d381245 VP |
14649 | if (loc_num == 0) |
14650 | error (_("Bad breakpoint location number '%s'"), number); | |
14651 | ||
14652 | --loc_num; | |
14653 | loc = b->loc; | |
14654 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14655 | ; | |
14656 | if (!loc) | |
14657 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14658 | ||
14659 | return loc; | |
14660 | } | |
14661 | ||
14662 | ||
1900040c MS |
14663 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14664 | If from_tty is nonzero, it prints a message to that effect, | |
14665 | which ends with a period (no newline). */ | |
14666 | ||
c906108c | 14667 | void |
fba45db2 | 14668 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14669 | { |
14670 | /* Never disable a watchpoint scope breakpoint; we want to | |
14671 | hit them when we leave scope so we can delete both the | |
14672 | watchpoint and its scope breakpoint at that time. */ | |
14673 | if (bpt->type == bp_watchpoint_scope) | |
14674 | return; | |
14675 | ||
c2c6d25f | 14676 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14677 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14678 | return; |
14679 | ||
b5de0fa7 | 14680 | bpt->enable_state = bp_disabled; |
c906108c | 14681 | |
b775012e LM |
14682 | /* Mark breakpoint locations modified. */ |
14683 | mark_breakpoint_modified (bpt); | |
14684 | ||
d248b706 KY |
14685 | if (target_supports_enable_disable_tracepoint () |
14686 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14687 | { | |
14688 | struct bp_location *location; | |
14689 | ||
14690 | for (location = bpt->loc; location; location = location->next) | |
14691 | target_disable_tracepoint (location); | |
14692 | } | |
14693 | ||
b60e7edf | 14694 | update_global_location_list (0); |
c906108c | 14695 | |
8d3788bd | 14696 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14697 | } |
14698 | ||
51be5b68 PA |
14699 | /* A callback for iterate_over_related_breakpoints. */ |
14700 | ||
14701 | static void | |
14702 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14703 | { | |
14704 | disable_breakpoint (b); | |
14705 | } | |
14706 | ||
95a42b64 TT |
14707 | /* A callback for map_breakpoint_numbers that calls |
14708 | disable_breakpoint. */ | |
14709 | ||
14710 | static void | |
14711 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14712 | { | |
51be5b68 | 14713 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14714 | } |
14715 | ||
c906108c | 14716 | static void |
fba45db2 | 14717 | disable_command (char *args, int from_tty) |
c906108c | 14718 | { |
c906108c | 14719 | if (args == 0) |
46c6471b PA |
14720 | { |
14721 | struct breakpoint *bpt; | |
14722 | ||
14723 | ALL_BREAKPOINTS (bpt) | |
14724 | if (user_breakpoint_p (bpt)) | |
14725 | disable_breakpoint (bpt); | |
14726 | } | |
9eaabc75 | 14727 | else |
0d381245 | 14728 | { |
9eaabc75 MW |
14729 | char *num = extract_arg (&args); |
14730 | ||
14731 | while (num) | |
d248b706 | 14732 | { |
9eaabc75 | 14733 | if (strchr (num, '.')) |
b775012e | 14734 | { |
9eaabc75 MW |
14735 | struct bp_location *loc = find_location_by_number (num); |
14736 | ||
14737 | if (loc) | |
14738 | { | |
14739 | if (loc->enabled) | |
14740 | { | |
14741 | loc->enabled = 0; | |
14742 | mark_breakpoint_location_modified (loc); | |
14743 | } | |
14744 | if (target_supports_enable_disable_tracepoint () | |
14745 | && current_trace_status ()->running && loc->owner | |
14746 | && is_tracepoint (loc->owner)) | |
14747 | target_disable_tracepoint (loc); | |
14748 | } | |
14749 | update_global_location_list (0); | |
b775012e | 14750 | } |
9eaabc75 MW |
14751 | else |
14752 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14753 | num = extract_arg (&args); | |
d248b706 | 14754 | } |
0d381245 | 14755 | } |
c906108c SS |
14756 | } |
14757 | ||
14758 | static void | |
816338b5 SS |
14759 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14760 | int count) | |
c906108c | 14761 | { |
afe38095 | 14762 | int target_resources_ok; |
c906108c SS |
14763 | |
14764 | if (bpt->type == bp_hardware_breakpoint) | |
14765 | { | |
14766 | int i; | |
c5aa993b | 14767 | i = hw_breakpoint_used_count (); |
53a5351d | 14768 | target_resources_ok = |
d92524f1 | 14769 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14770 | i + 1, 0); |
c906108c | 14771 | if (target_resources_ok == 0) |
8a3fe4f8 | 14772 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14773 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14774 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14775 | } |
14776 | ||
cc60f2e3 | 14777 | if (is_watchpoint (bpt)) |
c906108c | 14778 | { |
d07205c2 JK |
14779 | /* Initialize it just to avoid a GCC false warning. */ |
14780 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14781 | volatile struct gdb_exception e; |
dde02812 ES |
14782 | |
14783 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14784 | { |
3a5c3e22 PA |
14785 | struct watchpoint *w = (struct watchpoint *) bpt; |
14786 | ||
1e718ff1 TJB |
14787 | orig_enable_state = bpt->enable_state; |
14788 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14789 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14790 | } |
dde02812 | 14791 | if (e.reason < 0) |
c5aa993b | 14792 | { |
1e718ff1 | 14793 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14794 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14795 | bpt->number); | |
14796 | return; | |
c5aa993b | 14797 | } |
c906108c | 14798 | } |
0101ce28 | 14799 | |
b4c291bb KH |
14800 | if (bpt->enable_state != bp_permanent) |
14801 | bpt->enable_state = bp_enabled; | |
d248b706 | 14802 | |
b775012e LM |
14803 | bpt->enable_state = bp_enabled; |
14804 | ||
14805 | /* Mark breakpoint locations modified. */ | |
14806 | mark_breakpoint_modified (bpt); | |
14807 | ||
d248b706 KY |
14808 | if (target_supports_enable_disable_tracepoint () |
14809 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14810 | { | |
14811 | struct bp_location *location; | |
14812 | ||
14813 | for (location = bpt->loc; location; location = location->next) | |
14814 | target_enable_tracepoint (location); | |
14815 | } | |
14816 | ||
b4c291bb | 14817 | bpt->disposition = disposition; |
816338b5 | 14818 | bpt->enable_count = count; |
b60e7edf | 14819 | update_global_location_list (1); |
9c97429f | 14820 | |
8d3788bd | 14821 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14822 | } |
14823 | ||
fe3f5fa8 | 14824 | |
c906108c | 14825 | void |
fba45db2 | 14826 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14827 | { |
816338b5 | 14828 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14829 | } |
14830 | ||
14831 | static void | |
14832 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14833 | { | |
14834 | enable_breakpoint (bpt); | |
c906108c SS |
14835 | } |
14836 | ||
95a42b64 TT |
14837 | /* A callback for map_breakpoint_numbers that calls |
14838 | enable_breakpoint. */ | |
14839 | ||
14840 | static void | |
14841 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14842 | { | |
51be5b68 | 14843 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14844 | } |
14845 | ||
c906108c SS |
14846 | /* The enable command enables the specified breakpoints (or all defined |
14847 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14848 | in stopping the inferior. */ |
c906108c | 14849 | |
c906108c | 14850 | static void |
fba45db2 | 14851 | enable_command (char *args, int from_tty) |
c906108c | 14852 | { |
c906108c | 14853 | if (args == 0) |
46c6471b PA |
14854 | { |
14855 | struct breakpoint *bpt; | |
14856 | ||
14857 | ALL_BREAKPOINTS (bpt) | |
14858 | if (user_breakpoint_p (bpt)) | |
14859 | enable_breakpoint (bpt); | |
14860 | } | |
9eaabc75 | 14861 | else |
0d381245 | 14862 | { |
9eaabc75 MW |
14863 | char *num = extract_arg (&args); |
14864 | ||
14865 | while (num) | |
d248b706 | 14866 | { |
9eaabc75 | 14867 | if (strchr (num, '.')) |
b775012e | 14868 | { |
9eaabc75 MW |
14869 | struct bp_location *loc = find_location_by_number (num); |
14870 | ||
14871 | if (loc) | |
14872 | { | |
14873 | if (!loc->enabled) | |
14874 | { | |
14875 | loc->enabled = 1; | |
14876 | mark_breakpoint_location_modified (loc); | |
14877 | } | |
14878 | if (target_supports_enable_disable_tracepoint () | |
14879 | && current_trace_status ()->running && loc->owner | |
14880 | && is_tracepoint (loc->owner)) | |
14881 | target_enable_tracepoint (loc); | |
14882 | } | |
14883 | update_global_location_list (1); | |
b775012e | 14884 | } |
9eaabc75 MW |
14885 | else |
14886 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14887 | num = extract_arg (&args); | |
d248b706 | 14888 | } |
0d381245 | 14889 | } |
c906108c SS |
14890 | } |
14891 | ||
816338b5 SS |
14892 | /* This struct packages up disposition data for application to multiple |
14893 | breakpoints. */ | |
14894 | ||
14895 | struct disp_data | |
14896 | { | |
14897 | enum bpdisp disp; | |
14898 | int count; | |
14899 | }; | |
14900 | ||
c906108c | 14901 | static void |
51be5b68 PA |
14902 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14903 | { | |
816338b5 | 14904 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14905 | |
816338b5 | 14906 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14907 | } |
14908 | ||
14909 | static void | |
14910 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14911 | { |
816338b5 | 14912 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14913 | |
14914 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14915 | } |
14916 | ||
c906108c | 14917 | static void |
fba45db2 | 14918 | enable_once_command (char *args, int from_tty) |
c906108c | 14919 | { |
51be5b68 | 14920 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14921 | } |
14922 | ||
816338b5 SS |
14923 | static void |
14924 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14925 | { | |
14926 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14927 | ||
14928 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14929 | } | |
14930 | ||
14931 | static void | |
14932 | enable_count_command (char *args, int from_tty) | |
14933 | { | |
14934 | int count = get_number (&args); | |
14935 | ||
14936 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14937 | } | |
14938 | ||
c906108c | 14939 | static void |
51be5b68 | 14940 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14941 | { |
816338b5 | 14942 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14943 | |
14944 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14945 | } |
14946 | ||
c906108c | 14947 | static void |
fba45db2 | 14948 | enable_delete_command (char *args, int from_tty) |
c906108c | 14949 | { |
51be5b68 | 14950 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14951 | } |
14952 | \f | |
fa8d40ab JJ |
14953 | static void |
14954 | set_breakpoint_cmd (char *args, int from_tty) | |
14955 | { | |
14956 | } | |
14957 | ||
14958 | static void | |
14959 | show_breakpoint_cmd (char *args, int from_tty) | |
14960 | { | |
14961 | } | |
14962 | ||
1f3b5d1b PP |
14963 | /* Invalidate last known value of any hardware watchpoint if |
14964 | the memory which that value represents has been written to by | |
14965 | GDB itself. */ | |
14966 | ||
14967 | static void | |
8de0566d YQ |
14968 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14969 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14970 | const bfd_byte *data) |
14971 | { | |
14972 | struct breakpoint *bp; | |
14973 | ||
14974 | ALL_BREAKPOINTS (bp) | |
14975 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14976 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14977 | { |
3a5c3e22 | 14978 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14979 | |
3a5c3e22 PA |
14980 | if (wp->val_valid && wp->val) |
14981 | { | |
14982 | struct bp_location *loc; | |
14983 | ||
14984 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14985 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14986 | && loc->address + loc->length > addr | |
14987 | && addr + len > loc->address) | |
14988 | { | |
14989 | value_free (wp->val); | |
14990 | wp->val = NULL; | |
14991 | wp->val_valid = 0; | |
14992 | } | |
14993 | } | |
1f3b5d1b PP |
14994 | } |
14995 | } | |
14996 | ||
8181d85f DJ |
14997 | /* Create and insert a raw software breakpoint at PC. Return an |
14998 | identifier, which should be used to remove the breakpoint later. | |
14999 | In general, places which call this should be using something on the | |
15000 | breakpoint chain instead; this function should be eliminated | |
15001 | someday. */ | |
15002 | ||
15003 | void * | |
6c95b8df PA |
15004 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
15005 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
15006 | { |
15007 | struct bp_target_info *bp_tgt; | |
15008 | ||
41bf6aca | 15009 | bp_tgt = XCNEW (struct bp_target_info); |
8181d85f | 15010 | |
6c95b8df | 15011 | bp_tgt->placed_address_space = aspace; |
8181d85f | 15012 | bp_tgt->placed_address = pc; |
6c95b8df | 15013 | |
a6d9a66e | 15014 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
15015 | { |
15016 | /* Could not insert the breakpoint. */ | |
15017 | xfree (bp_tgt); | |
15018 | return NULL; | |
15019 | } | |
15020 | ||
15021 | return bp_tgt; | |
15022 | } | |
15023 | ||
4a64f543 MS |
15024 | /* Remove a breakpoint BP inserted by |
15025 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
15026 | |
15027 | int | |
a6d9a66e | 15028 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
15029 | { |
15030 | struct bp_target_info *bp_tgt = bp; | |
15031 | int ret; | |
15032 | ||
a6d9a66e | 15033 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
15034 | xfree (bp_tgt); |
15035 | ||
15036 | return ret; | |
15037 | } | |
15038 | ||
4a64f543 MS |
15039 | /* One (or perhaps two) breakpoints used for software single |
15040 | stepping. */ | |
8181d85f DJ |
15041 | |
15042 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 15043 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
15044 | |
15045 | /* Create and insert a breakpoint for software single step. */ | |
15046 | ||
15047 | void | |
6c95b8df | 15048 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15049 | struct address_space *aspace, |
15050 | CORE_ADDR next_pc) | |
8181d85f DJ |
15051 | { |
15052 | void **bpt_p; | |
15053 | ||
15054 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15055 | { |
15056 | bpt_p = &single_step_breakpoints[0]; | |
15057 | single_step_gdbarch[0] = gdbarch; | |
15058 | } | |
8181d85f DJ |
15059 | else |
15060 | { | |
15061 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15062 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15063 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15064 | } |
15065 | ||
4a64f543 MS |
15066 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15067 | be to only create the breakpoints once, and actually put them on | |
15068 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15069 | We could adjust the addresses each time they were needed. Doing | |
15070 | this requires corresponding changes elsewhere where single step | |
15071 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15072 | |
6c95b8df | 15073 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15074 | if (*bpt_p == NULL) |
5af949e3 UW |
15075 | error (_("Could not insert single-step breakpoint at %s"), |
15076 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15077 | } |
15078 | ||
f02253f1 HZ |
15079 | /* Check if the breakpoints used for software single stepping |
15080 | were inserted or not. */ | |
15081 | ||
15082 | int | |
15083 | single_step_breakpoints_inserted (void) | |
15084 | { | |
15085 | return (single_step_breakpoints[0] != NULL | |
15086 | || single_step_breakpoints[1] != NULL); | |
15087 | } | |
15088 | ||
8181d85f DJ |
15089 | /* Remove and delete any breakpoints used for software single step. */ |
15090 | ||
15091 | void | |
15092 | remove_single_step_breakpoints (void) | |
15093 | { | |
15094 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15095 | ||
15096 | /* See insert_single_step_breakpoint for more about this deprecated | |
15097 | call. */ | |
a6d9a66e UW |
15098 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15099 | single_step_breakpoints[0]); | |
15100 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15101 | single_step_breakpoints[0] = NULL; |
15102 | ||
15103 | if (single_step_breakpoints[1] != NULL) | |
15104 | { | |
a6d9a66e UW |
15105 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15106 | single_step_breakpoints[1]); | |
15107 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15108 | single_step_breakpoints[1] = NULL; |
15109 | } | |
15110 | } | |
15111 | ||
d03285ec UW |
15112 | /* Delete software single step breakpoints without removing them from |
15113 | the inferior. This is intended to be used if the inferior's address | |
15114 | space where they were inserted is already gone, e.g. after exit or | |
15115 | exec. */ | |
15116 | ||
15117 | void | |
15118 | cancel_single_step_breakpoints (void) | |
15119 | { | |
15120 | int i; | |
15121 | ||
15122 | for (i = 0; i < 2; i++) | |
15123 | if (single_step_breakpoints[i]) | |
15124 | { | |
15125 | xfree (single_step_breakpoints[i]); | |
15126 | single_step_breakpoints[i] = NULL; | |
15127 | single_step_gdbarch[i] = NULL; | |
15128 | } | |
15129 | } | |
15130 | ||
15131 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15132 | removing them. */ | |
15133 | ||
15134 | static void | |
15135 | detach_single_step_breakpoints (void) | |
15136 | { | |
15137 | int i; | |
15138 | ||
15139 | for (i = 0; i < 2; i++) | |
15140 | if (single_step_breakpoints[i]) | |
15141 | target_remove_breakpoint (single_step_gdbarch[i], | |
15142 | single_step_breakpoints[i]); | |
15143 | } | |
15144 | ||
4a64f543 MS |
15145 | /* Check whether a software single-step breakpoint is inserted at |
15146 | PC. */ | |
1aafd4da | 15147 | |
2adfaa28 | 15148 | int |
cc59ec59 MS |
15149 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15150 | CORE_ADDR pc) | |
1aafd4da UW |
15151 | { |
15152 | int i; | |
15153 | ||
15154 | for (i = 0; i < 2; i++) | |
15155 | { | |
15156 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15157 | if (bp_tgt |
15158 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15159 | bp_tgt->placed_address, | |
15160 | aspace, pc)) | |
1aafd4da UW |
15161 | return 1; |
15162 | } | |
15163 | ||
15164 | return 0; | |
15165 | } | |
15166 | ||
a96d9b2e SDJ |
15167 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15168 | non-zero otherwise. */ | |
15169 | static int | |
15170 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15171 | { | |
15172 | if (syscall_catchpoint_p (bp) | |
15173 | && bp->enable_state != bp_disabled | |
15174 | && bp->enable_state != bp_call_disabled) | |
15175 | return 1; | |
15176 | else | |
15177 | return 0; | |
15178 | } | |
15179 | ||
15180 | int | |
15181 | catch_syscall_enabled (void) | |
15182 | { | |
fa3064dd YQ |
15183 | struct catch_syscall_inferior_data *inf_data |
15184 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15185 | |
fa3064dd | 15186 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15187 | } |
15188 | ||
15189 | int | |
15190 | catching_syscall_number (int syscall_number) | |
15191 | { | |
15192 | struct breakpoint *bp; | |
15193 | ||
15194 | ALL_BREAKPOINTS (bp) | |
15195 | if (is_syscall_catchpoint_enabled (bp)) | |
15196 | { | |
be5c67c1 PA |
15197 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15198 | ||
15199 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15200 | { |
15201 | int i, iter; | |
15202 | for (i = 0; | |
be5c67c1 | 15203 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15204 | i++) |
15205 | if (syscall_number == iter) | |
15206 | return 1; | |
15207 | } | |
15208 | else | |
15209 | return 1; | |
15210 | } | |
15211 | ||
15212 | return 0; | |
15213 | } | |
15214 | ||
15215 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15216 | static VEC (char_ptr) * |
a96d9b2e | 15217 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15218 | const char *text, const char *word) |
a96d9b2e SDJ |
15219 | { |
15220 | const char **list = get_syscall_names (); | |
49c4e619 | 15221 | VEC (char_ptr) *retlist |
b45627a0 | 15222 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15223 | |
c38eea1a MS |
15224 | xfree (list); |
15225 | return retlist; | |
a96d9b2e SDJ |
15226 | } |
15227 | ||
1042e4c0 SS |
15228 | /* Tracepoint-specific operations. */ |
15229 | ||
15230 | /* Set tracepoint count to NUM. */ | |
15231 | static void | |
15232 | set_tracepoint_count (int num) | |
15233 | { | |
15234 | tracepoint_count = num; | |
4fa62494 | 15235 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15236 | } |
15237 | ||
70221824 | 15238 | static void |
1042e4c0 SS |
15239 | trace_command (char *arg, int from_tty) |
15240 | { | |
55aa24fb SDJ |
15241 | struct breakpoint_ops *ops; |
15242 | const char *arg_cp = arg; | |
15243 | ||
15244 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15245 | ops = &tracepoint_probe_breakpoint_ops; | |
15246 | else | |
15247 | ops = &tracepoint_breakpoint_ops; | |
15248 | ||
558a9d82 YQ |
15249 | create_breakpoint (get_current_arch (), |
15250 | arg, | |
15251 | NULL, 0, NULL, 1 /* parse arg */, | |
15252 | 0 /* tempflag */, | |
15253 | bp_tracepoint /* type_wanted */, | |
15254 | 0 /* Ignore count */, | |
15255 | pending_break_support, | |
15256 | ops, | |
15257 | from_tty, | |
15258 | 1 /* enabled */, | |
15259 | 0 /* internal */, 0); | |
1042e4c0 SS |
15260 | } |
15261 | ||
70221824 | 15262 | static void |
7a697b8d SS |
15263 | ftrace_command (char *arg, int from_tty) |
15264 | { | |
558a9d82 YQ |
15265 | create_breakpoint (get_current_arch (), |
15266 | arg, | |
15267 | NULL, 0, NULL, 1 /* parse arg */, | |
15268 | 0 /* tempflag */, | |
15269 | bp_fast_tracepoint /* type_wanted */, | |
15270 | 0 /* Ignore count */, | |
15271 | pending_break_support, | |
15272 | &tracepoint_breakpoint_ops, | |
15273 | from_tty, | |
15274 | 1 /* enabled */, | |
15275 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15276 | } |
15277 | ||
15278 | /* strace command implementation. Creates a static tracepoint. */ | |
15279 | ||
70221824 | 15280 | static void |
0fb4aa4b PA |
15281 | strace_command (char *arg, int from_tty) |
15282 | { | |
983af33b SDJ |
15283 | struct breakpoint_ops *ops; |
15284 | ||
15285 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15286 | or with a normal static tracepoint. */ | |
15287 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15288 | ops = &strace_marker_breakpoint_ops; | |
15289 | else | |
15290 | ops = &tracepoint_breakpoint_ops; | |
15291 | ||
558a9d82 YQ |
15292 | create_breakpoint (get_current_arch (), |
15293 | arg, | |
15294 | NULL, 0, NULL, 1 /* parse arg */, | |
15295 | 0 /* tempflag */, | |
15296 | bp_static_tracepoint /* type_wanted */, | |
15297 | 0 /* Ignore count */, | |
15298 | pending_break_support, | |
15299 | ops, | |
15300 | from_tty, | |
15301 | 1 /* enabled */, | |
15302 | 0 /* internal */, 0); | |
7a697b8d SS |
15303 | } |
15304 | ||
409873ef SS |
15305 | /* Set up a fake reader function that gets command lines from a linked |
15306 | list that was acquired during tracepoint uploading. */ | |
15307 | ||
15308 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15309 | static int next_cmd; |
409873ef SS |
15310 | |
15311 | static char * | |
15312 | read_uploaded_action (void) | |
15313 | { | |
15314 | char *rslt; | |
15315 | ||
3149d8c1 | 15316 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15317 | |
3149d8c1 | 15318 | next_cmd++; |
409873ef SS |
15319 | |
15320 | return rslt; | |
15321 | } | |
15322 | ||
00bf0b85 SS |
15323 | /* Given information about a tracepoint as recorded on a target (which |
15324 | can be either a live system or a trace file), attempt to create an | |
15325 | equivalent GDB tracepoint. This is not a reliable process, since | |
15326 | the target does not necessarily have all the information used when | |
15327 | the tracepoint was originally defined. */ | |
15328 | ||
d9b3f62e | 15329 | struct tracepoint * |
00bf0b85 | 15330 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15331 | { |
409873ef | 15332 | char *addr_str, small_buf[100]; |
d9b3f62e | 15333 | struct tracepoint *tp; |
fd9b8c24 | 15334 | |
409873ef SS |
15335 | if (utp->at_string) |
15336 | addr_str = utp->at_string; | |
15337 | else | |
15338 | { | |
15339 | /* In the absence of a source location, fall back to raw | |
15340 | address. Since there is no way to confirm that the address | |
15341 | means the same thing as when the trace was started, warn the | |
15342 | user. */ | |
3e43a32a MS |
15343 | warning (_("Uploaded tracepoint %d has no " |
15344 | "source location, using raw address"), | |
409873ef | 15345 | utp->number); |
8c042590 | 15346 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15347 | addr_str = small_buf; |
15348 | } | |
15349 | ||
15350 | /* There's not much we can do with a sequence of bytecodes. */ | |
15351 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15352 | warning (_("Uploaded tracepoint %d condition " |
15353 | "has no source form, ignoring it"), | |
409873ef | 15354 | utp->number); |
d5551862 | 15355 | |
8cdf0e15 | 15356 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15357 | addr_str, |
e7e0cddf SS |
15358 | utp->cond_string, -1, NULL, |
15359 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15360 | 0 /* tempflag */, |
0fb4aa4b | 15361 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15362 | 0 /* Ignore count */, |
15363 | pending_break_support, | |
348d480f | 15364 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15365 | 0 /* from_tty */, |
84f4c1fe | 15366 | utp->enabled /* enabled */, |
44f238bb PA |
15367 | 0 /* internal */, |
15368 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15369 | return NULL; |
15370 | ||
409873ef | 15371 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15372 | tp = get_tracepoint (tracepoint_count); |
15373 | gdb_assert (tp != NULL); | |
d5551862 | 15374 | |
00bf0b85 SS |
15375 | if (utp->pass > 0) |
15376 | { | |
8c042590 PM |
15377 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15378 | tp->base.number); | |
00bf0b85 | 15379 | |
409873ef | 15380 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15381 | } |
15382 | ||
409873ef SS |
15383 | /* If we have uploaded versions of the original commands, set up a |
15384 | special-purpose "reader" function and call the usual command line | |
15385 | reader, then pass the result to the breakpoint command-setting | |
15386 | function. */ | |
3149d8c1 | 15387 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15388 | { |
409873ef | 15389 | struct command_line *cmd_list; |
00bf0b85 | 15390 | |
409873ef | 15391 | this_utp = utp; |
3149d8c1 | 15392 | next_cmd = 0; |
d5551862 | 15393 | |
409873ef SS |
15394 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15395 | ||
d9b3f62e | 15396 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15397 | } |
3149d8c1 SS |
15398 | else if (!VEC_empty (char_ptr, utp->actions) |
15399 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15400 | warning (_("Uploaded tracepoint %d actions " |
15401 | "have no source form, ignoring them"), | |
409873ef | 15402 | utp->number); |
00bf0b85 | 15403 | |
f196051f SS |
15404 | /* Copy any status information that might be available. */ |
15405 | tp->base.hit_count = utp->hit_count; | |
15406 | tp->traceframe_usage = utp->traceframe_usage; | |
15407 | ||
00bf0b85 | 15408 | return tp; |
d9b3f62e | 15409 | } |
00bf0b85 | 15410 | |
1042e4c0 SS |
15411 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15412 | omitted. */ | |
15413 | ||
15414 | static void | |
e5a67952 | 15415 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15416 | { |
79a45e25 | 15417 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15418 | int num_printed; |
1042e4c0 | 15419 | |
e5a67952 | 15420 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15421 | |
15422 | if (num_printed == 0) | |
1042e4c0 | 15423 | { |
e5a67952 | 15424 | if (args == NULL || *args == '\0') |
d77f58be SS |
15425 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15426 | else | |
e5a67952 | 15427 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15428 | } |
ad443146 SS |
15429 | |
15430 | default_collect_info (); | |
1042e4c0 SS |
15431 | } |
15432 | ||
4a64f543 | 15433 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15434 | Not supported by all targets. */ |
15435 | static void | |
15436 | enable_trace_command (char *args, int from_tty) | |
15437 | { | |
15438 | enable_command (args, from_tty); | |
15439 | } | |
15440 | ||
4a64f543 | 15441 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15442 | Not supported by all targets. */ |
15443 | static void | |
15444 | disable_trace_command (char *args, int from_tty) | |
15445 | { | |
15446 | disable_command (args, from_tty); | |
15447 | } | |
15448 | ||
4a64f543 | 15449 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15450 | static void |
15451 | delete_trace_command (char *arg, int from_tty) | |
15452 | { | |
35df4500 | 15453 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15454 | |
15455 | dont_repeat (); | |
15456 | ||
15457 | if (arg == 0) | |
15458 | { | |
15459 | int breaks_to_delete = 0; | |
15460 | ||
15461 | /* Delete all breakpoints if no argument. | |
15462 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15463 | have to be deleted with an explicit breakpoint number |
15464 | argument. */ | |
1042e4c0 | 15465 | ALL_TRACEPOINTS (b) |
46c6471b | 15466 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15467 | { |
15468 | breaks_to_delete = 1; | |
15469 | break; | |
15470 | } | |
1042e4c0 SS |
15471 | |
15472 | /* Ask user only if there are some breakpoints to delete. */ | |
15473 | if (!from_tty | |
15474 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15475 | { | |
35df4500 | 15476 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15477 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15478 | delete_breakpoint (b); |
1042e4c0 SS |
15479 | } |
15480 | } | |
15481 | else | |
51be5b68 | 15482 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15483 | } |
15484 | ||
197f0a60 TT |
15485 | /* Helper function for trace_pass_command. */ |
15486 | ||
15487 | static void | |
d9b3f62e | 15488 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15489 | { |
d9b3f62e | 15490 | tp->pass_count = count; |
6f6484cd | 15491 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15492 | if (from_tty) |
15493 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15494 | tp->base.number, count); |
197f0a60 TT |
15495 | } |
15496 | ||
1042e4c0 SS |
15497 | /* Set passcount for tracepoint. |
15498 | ||
15499 | First command argument is passcount, second is tracepoint number. | |
15500 | If tracepoint number omitted, apply to most recently defined. | |
15501 | Also accepts special argument "all". */ | |
15502 | ||
15503 | static void | |
15504 | trace_pass_command (char *args, int from_tty) | |
15505 | { | |
d9b3f62e | 15506 | struct tracepoint *t1; |
1042e4c0 | 15507 | unsigned int count; |
1042e4c0 SS |
15508 | |
15509 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15510 | error (_("passcount command requires an " |
15511 | "argument (count + optional TP num)")); | |
1042e4c0 | 15512 | |
4a64f543 | 15513 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15514 | |
529480d0 | 15515 | args = skip_spaces (args); |
1042e4c0 SS |
15516 | if (*args && strncasecmp (args, "all", 3) == 0) |
15517 | { | |
d9b3f62e PA |
15518 | struct breakpoint *b; |
15519 | ||
1042e4c0 | 15520 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15521 | if (*args) |
15522 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15523 | |
d9b3f62e | 15524 | ALL_TRACEPOINTS (b) |
197f0a60 | 15525 | { |
d9b3f62e | 15526 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15527 | trace_pass_set_count (t1, count, from_tty); |
15528 | } | |
15529 | } | |
15530 | else if (*args == '\0') | |
1042e4c0 | 15531 | { |
5fa1d40e | 15532 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15533 | if (t1) |
197f0a60 TT |
15534 | trace_pass_set_count (t1, count, from_tty); |
15535 | } | |
15536 | else | |
15537 | { | |
15538 | struct get_number_or_range_state state; | |
15539 | ||
15540 | init_number_or_range (&state, args); | |
15541 | while (!state.finished) | |
1042e4c0 | 15542 | { |
5fa1d40e | 15543 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15544 | if (t1) |
15545 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15546 | } |
15547 | } | |
1042e4c0 SS |
15548 | } |
15549 | ||
d9b3f62e | 15550 | struct tracepoint * |
1042e4c0 SS |
15551 | get_tracepoint (int num) |
15552 | { | |
15553 | struct breakpoint *t; | |
15554 | ||
15555 | ALL_TRACEPOINTS (t) | |
15556 | if (t->number == num) | |
d9b3f62e | 15557 | return (struct tracepoint *) t; |
1042e4c0 SS |
15558 | |
15559 | return NULL; | |
15560 | } | |
15561 | ||
d5551862 SS |
15562 | /* Find the tracepoint with the given target-side number (which may be |
15563 | different from the tracepoint number after disconnecting and | |
15564 | reconnecting). */ | |
15565 | ||
d9b3f62e | 15566 | struct tracepoint * |
d5551862 SS |
15567 | get_tracepoint_by_number_on_target (int num) |
15568 | { | |
d9b3f62e | 15569 | struct breakpoint *b; |
d5551862 | 15570 | |
d9b3f62e PA |
15571 | ALL_TRACEPOINTS (b) |
15572 | { | |
15573 | struct tracepoint *t = (struct tracepoint *) b; | |
15574 | ||
15575 | if (t->number_on_target == num) | |
15576 | return t; | |
15577 | } | |
d5551862 SS |
15578 | |
15579 | return NULL; | |
15580 | } | |
15581 | ||
1042e4c0 | 15582 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15583 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15584 | If the argument is missing, the most recent tracepoint |
15585 | (tracepoint_count) is returned. */ | |
15586 | ||
d9b3f62e | 15587 | struct tracepoint * |
197f0a60 | 15588 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15589 | struct get_number_or_range_state *state) |
1042e4c0 | 15590 | { |
1042e4c0 SS |
15591 | struct breakpoint *t; |
15592 | int tpnum; | |
15593 | char *instring = arg == NULL ? NULL : *arg; | |
15594 | ||
197f0a60 TT |
15595 | if (state) |
15596 | { | |
15597 | gdb_assert (!state->finished); | |
15598 | tpnum = get_number_or_range (state); | |
15599 | } | |
15600 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15601 | tpnum = tracepoint_count; |
1042e4c0 | 15602 | else |
197f0a60 | 15603 | tpnum = get_number (arg); |
1042e4c0 SS |
15604 | |
15605 | if (tpnum <= 0) | |
15606 | { | |
15607 | if (instring && *instring) | |
15608 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15609 | instring); | |
15610 | else | |
5fa1d40e | 15611 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15612 | return NULL; |
15613 | } | |
15614 | ||
15615 | ALL_TRACEPOINTS (t) | |
15616 | if (t->number == tpnum) | |
15617 | { | |
d9b3f62e | 15618 | return (struct tracepoint *) t; |
1042e4c0 SS |
15619 | } |
15620 | ||
1042e4c0 SS |
15621 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15622 | return NULL; | |
15623 | } | |
15624 | ||
d9b3f62e PA |
15625 | void |
15626 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15627 | { | |
15628 | if (b->thread != -1) | |
15629 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15630 | ||
15631 | if (b->task != 0) | |
15632 | fprintf_unfiltered (fp, " task %d", b->task); | |
15633 | ||
15634 | fprintf_unfiltered (fp, "\n"); | |
15635 | } | |
15636 | ||
6149aea9 PA |
15637 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15638 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15639 | on each breakpoint and only include the ones for which it returns | |
15640 | non-zero. */ | |
15641 | ||
1042e4c0 | 15642 | static void |
6149aea9 PA |
15643 | save_breakpoints (char *filename, int from_tty, |
15644 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15645 | { |
15646 | struct breakpoint *tp; | |
6149aea9 | 15647 | int any = 0; |
1042e4c0 | 15648 | struct cleanup *cleanup; |
a7bdde9e | 15649 | struct ui_file *fp; |
6149aea9 | 15650 | int extra_trace_bits = 0; |
1042e4c0 | 15651 | |
6149aea9 PA |
15652 | if (filename == 0 || *filename == 0) |
15653 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15654 | |
15655 | /* See if we have anything to save. */ | |
6149aea9 | 15656 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15657 | { |
6149aea9 | 15658 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15659 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15660 | continue; |
15661 | ||
15662 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15663 | if (filter && !filter (tp)) | |
15664 | continue; | |
15665 | ||
15666 | any = 1; | |
15667 | ||
15668 | if (is_tracepoint (tp)) | |
15669 | { | |
15670 | extra_trace_bits = 1; | |
15671 | ||
15672 | /* We can stop searching. */ | |
15673 | break; | |
15674 | } | |
1042e4c0 | 15675 | } |
6149aea9 PA |
15676 | |
15677 | if (!any) | |
1042e4c0 | 15678 | { |
6149aea9 | 15679 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15680 | return; |
15681 | } | |
15682 | ||
c718be47 PA |
15683 | filename = tilde_expand (filename); |
15684 | cleanup = make_cleanup (xfree, filename); | |
15685 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15686 | if (!fp) |
6149aea9 PA |
15687 | error (_("Unable to open file '%s' for saving (%s)"), |
15688 | filename, safe_strerror (errno)); | |
a7bdde9e | 15689 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15690 | |
6149aea9 PA |
15691 | if (extra_trace_bits) |
15692 | save_trace_state_variables (fp); | |
8bf6485c | 15693 | |
6149aea9 | 15694 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15695 | { |
6149aea9 | 15696 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15697 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15698 | continue; |
8bf6485c | 15699 | |
6149aea9 PA |
15700 | /* If we have a filter, only save the breakpoints it accepts. */ |
15701 | if (filter && !filter (tp)) | |
15702 | continue; | |
15703 | ||
348d480f | 15704 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15705 | |
6149aea9 PA |
15706 | /* Note, we can't rely on tp->number for anything, as we can't |
15707 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15708 | instead. */ | |
15709 | ||
15710 | if (tp->cond_string) | |
15711 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15712 | ||
15713 | if (tp->ignore_count) | |
15714 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15715 | ||
2d9442cc | 15716 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15717 | { |
a7bdde9e VP |
15718 | volatile struct gdb_exception ex; |
15719 | ||
6149aea9 | 15720 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15721 | |
79a45e25 | 15722 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15723 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15724 | { |
79a45e25 | 15725 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15726 | } |
79a45e25 | 15727 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15728 | |
a7bdde9e VP |
15729 | if (ex.reason < 0) |
15730 | throw_exception (ex); | |
1042e4c0 | 15731 | |
a7bdde9e | 15732 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15733 | } |
6149aea9 PA |
15734 | |
15735 | if (tp->enable_state == bp_disabled) | |
15736 | fprintf_unfiltered (fp, "disable\n"); | |
15737 | ||
15738 | /* If this is a multi-location breakpoint, check if the locations | |
15739 | should be individually disabled. Watchpoint locations are | |
15740 | special, and not user visible. */ | |
15741 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15742 | { | |
15743 | struct bp_location *loc; | |
15744 | int n = 1; | |
15745 | ||
15746 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15747 | if (!loc->enabled) | |
15748 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15749 | } | |
1042e4c0 | 15750 | } |
8bf6485c | 15751 | |
6149aea9 | 15752 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15753 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15754 | ||
1042e4c0 | 15755 | if (from_tty) |
6149aea9 | 15756 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15757 | do_cleanups (cleanup); |
6149aea9 PA |
15758 | } |
15759 | ||
15760 | /* The `save breakpoints' command. */ | |
15761 | ||
15762 | static void | |
15763 | save_breakpoints_command (char *args, int from_tty) | |
15764 | { | |
15765 | save_breakpoints (args, from_tty, NULL); | |
15766 | } | |
15767 | ||
15768 | /* The `save tracepoints' command. */ | |
15769 | ||
15770 | static void | |
15771 | save_tracepoints_command (char *args, int from_tty) | |
15772 | { | |
15773 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15774 | } |
15775 | ||
15776 | /* Create a vector of all tracepoints. */ | |
15777 | ||
15778 | VEC(breakpoint_p) * | |
eeae04df | 15779 | all_tracepoints (void) |
1042e4c0 SS |
15780 | { |
15781 | VEC(breakpoint_p) *tp_vec = 0; | |
15782 | struct breakpoint *tp; | |
15783 | ||
15784 | ALL_TRACEPOINTS (tp) | |
15785 | { | |
15786 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15787 | } | |
15788 | ||
15789 | return tp_vec; | |
15790 | } | |
15791 | ||
c906108c | 15792 | \f |
4a64f543 MS |
15793 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15794 | commands. It is defined as a macro to prevent duplication. | |
15795 | COMMAND should be a string constant containing the name of the | |
15796 | command. */ | |
31e2b00f | 15797 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15798 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15799 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15800 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15801 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15802 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15803 | If a line number is specified, break at start of code for that line.\n\ | |
15804 | If a function is specified, break at start of code for that function.\n\ | |
15805 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15806 | With no LOCATION, uses current execution address of the selected\n\ |
15807 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15808 | \n\ |
15809 | THREADNUM is the number from \"info threads\".\n\ | |
15810 | CONDITION is a boolean expression.\n\ | |
15811 | \n\ | |
d41c0fc8 PA |
15812 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15813 | conditions are different.\n\ | |
31e2b00f AS |
15814 | \n\ |
15815 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15816 | ||
44feb3ce TT |
15817 | /* List of subcommands for "catch". */ |
15818 | static struct cmd_list_element *catch_cmdlist; | |
15819 | ||
15820 | /* List of subcommands for "tcatch". */ | |
15821 | static struct cmd_list_element *tcatch_cmdlist; | |
15822 | ||
9ac4176b | 15823 | void |
44feb3ce TT |
15824 | add_catch_command (char *name, char *docstring, |
15825 | void (*sfunc) (char *args, int from_tty, | |
15826 | struct cmd_list_element *command), | |
625e8578 | 15827 | completer_ftype *completer, |
44feb3ce TT |
15828 | void *user_data_catch, |
15829 | void *user_data_tcatch) | |
15830 | { | |
15831 | struct cmd_list_element *command; | |
15832 | ||
15833 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15834 | &catch_cmdlist); | |
15835 | set_cmd_sfunc (command, sfunc); | |
15836 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15837 | set_cmd_completer (command, completer); |
44feb3ce TT |
15838 | |
15839 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15840 | &tcatch_cmdlist); | |
15841 | set_cmd_sfunc (command, sfunc); | |
15842 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15843 | set_cmd_completer (command, completer); |
44feb3ce TT |
15844 | } |
15845 | ||
6c95b8df | 15846 | static void |
a79b8f6e | 15847 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15848 | { |
fa3064dd YQ |
15849 | struct catch_syscall_inferior_data *inf_data |
15850 | = get_catch_syscall_inferior_data (inf); | |
15851 | ||
15852 | inf_data->total_syscalls_count = 0; | |
15853 | inf_data->any_syscall_count = 0; | |
15854 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15855 | } |
15856 | ||
6149aea9 PA |
15857 | static void |
15858 | save_command (char *arg, int from_tty) | |
15859 | { | |
3e43a32a MS |
15860 | printf_unfiltered (_("\"save\" must be followed by " |
15861 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15862 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15863 | } | |
15864 | ||
84f4c1fe PM |
15865 | struct breakpoint * |
15866 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15867 | void *data) | |
15868 | { | |
35df4500 | 15869 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15870 | |
35df4500 | 15871 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15872 | { |
15873 | if ((*callback) (b, data)) | |
15874 | return b; | |
15875 | } | |
15876 | ||
15877 | return NULL; | |
15878 | } | |
15879 | ||
0574c78f GB |
15880 | /* Zero if any of the breakpoint's locations could be a location where |
15881 | functions have been inlined, nonzero otherwise. */ | |
15882 | ||
15883 | static int | |
15884 | is_non_inline_function (struct breakpoint *b) | |
15885 | { | |
15886 | /* The shared library event breakpoint is set on the address of a | |
15887 | non-inline function. */ | |
15888 | if (b->type == bp_shlib_event) | |
15889 | return 1; | |
15890 | ||
15891 | return 0; | |
15892 | } | |
15893 | ||
15894 | /* Nonzero if the specified PC cannot be a location where functions | |
15895 | have been inlined. */ | |
15896 | ||
15897 | int | |
09ac7c10 TT |
15898 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15899 | const struct target_waitstatus *ws) | |
0574c78f GB |
15900 | { |
15901 | struct breakpoint *b; | |
15902 | struct bp_location *bl; | |
15903 | ||
15904 | ALL_BREAKPOINTS (b) | |
15905 | { | |
15906 | if (!is_non_inline_function (b)) | |
15907 | continue; | |
15908 | ||
15909 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15910 | { | |
15911 | if (!bl->shlib_disabled | |
09ac7c10 | 15912 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15913 | return 1; |
15914 | } | |
15915 | } | |
15916 | ||
15917 | return 0; | |
15918 | } | |
15919 | ||
2f202fde JK |
15920 | /* Remove any references to OBJFILE which is going to be freed. */ |
15921 | ||
15922 | void | |
15923 | breakpoint_free_objfile (struct objfile *objfile) | |
15924 | { | |
15925 | struct bp_location **locp, *loc; | |
15926 | ||
15927 | ALL_BP_LOCATIONS (loc, locp) | |
15928 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15929 | loc->symtab = NULL; | |
15930 | } | |
15931 | ||
2060206e PA |
15932 | void |
15933 | initialize_breakpoint_ops (void) | |
15934 | { | |
15935 | static int initialized = 0; | |
15936 | ||
15937 | struct breakpoint_ops *ops; | |
15938 | ||
15939 | if (initialized) | |
15940 | return; | |
15941 | initialized = 1; | |
15942 | ||
15943 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15944 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15945 | internal and momentary breakpoints, etc.). */ | |
15946 | ops = &bkpt_base_breakpoint_ops; | |
15947 | *ops = base_breakpoint_ops; | |
15948 | ops->re_set = bkpt_re_set; | |
15949 | ops->insert_location = bkpt_insert_location; | |
15950 | ops->remove_location = bkpt_remove_location; | |
15951 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15952 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15953 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15954 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15955 | |
15956 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15957 | ops = &bkpt_breakpoint_ops; | |
15958 | *ops = bkpt_base_breakpoint_ops; | |
15959 | ops->re_set = bkpt_re_set; | |
15960 | ops->resources_needed = bkpt_resources_needed; | |
15961 | ops->print_it = bkpt_print_it; | |
15962 | ops->print_mention = bkpt_print_mention; | |
15963 | ops->print_recreate = bkpt_print_recreate; | |
15964 | ||
15965 | /* Ranged breakpoints. */ | |
15966 | ops = &ranged_breakpoint_ops; | |
15967 | *ops = bkpt_breakpoint_ops; | |
15968 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15969 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15970 | ops->print_it = print_it_ranged_breakpoint; | |
15971 | ops->print_one = print_one_ranged_breakpoint; | |
15972 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15973 | ops->print_mention = print_mention_ranged_breakpoint; | |
15974 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15975 | ||
15976 | /* Internal breakpoints. */ | |
15977 | ops = &internal_breakpoint_ops; | |
15978 | *ops = bkpt_base_breakpoint_ops; | |
15979 | ops->re_set = internal_bkpt_re_set; | |
15980 | ops->check_status = internal_bkpt_check_status; | |
15981 | ops->print_it = internal_bkpt_print_it; | |
15982 | ops->print_mention = internal_bkpt_print_mention; | |
15983 | ||
15984 | /* Momentary breakpoints. */ | |
15985 | ops = &momentary_breakpoint_ops; | |
15986 | *ops = bkpt_base_breakpoint_ops; | |
15987 | ops->re_set = momentary_bkpt_re_set; | |
15988 | ops->check_status = momentary_bkpt_check_status; | |
15989 | ops->print_it = momentary_bkpt_print_it; | |
15990 | ops->print_mention = momentary_bkpt_print_mention; | |
15991 | ||
e2e4d78b JK |
15992 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15993 | ops = &longjmp_breakpoint_ops; | |
15994 | *ops = momentary_breakpoint_ops; | |
15995 | ops->dtor = longjmp_bkpt_dtor; | |
15996 | ||
55aa24fb SDJ |
15997 | /* Probe breakpoints. */ |
15998 | ops = &bkpt_probe_breakpoint_ops; | |
15999 | *ops = bkpt_breakpoint_ops; | |
16000 | ops->insert_location = bkpt_probe_insert_location; | |
16001 | ops->remove_location = bkpt_probe_remove_location; | |
16002 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16003 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16004 | ||
2060206e PA |
16005 | /* Watchpoints. */ |
16006 | ops = &watchpoint_breakpoint_ops; | |
16007 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16008 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16009 | ops->re_set = re_set_watchpoint; |
16010 | ops->insert_location = insert_watchpoint; | |
16011 | ops->remove_location = remove_watchpoint; | |
16012 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16013 | ops->check_status = check_status_watchpoint; | |
16014 | ops->resources_needed = resources_needed_watchpoint; | |
16015 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16016 | ops->print_it = print_it_watchpoint; | |
16017 | ops->print_mention = print_mention_watchpoint; | |
16018 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16019 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16020 | |
16021 | /* Masked watchpoints. */ | |
16022 | ops = &masked_watchpoint_breakpoint_ops; | |
16023 | *ops = watchpoint_breakpoint_ops; | |
16024 | ops->insert_location = insert_masked_watchpoint; | |
16025 | ops->remove_location = remove_masked_watchpoint; | |
16026 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16027 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16028 | ops->print_it = print_it_masked_watchpoint; | |
16029 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16030 | ops->print_mention = print_mention_masked_watchpoint; | |
16031 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16032 | ||
16033 | /* Tracepoints. */ | |
16034 | ops = &tracepoint_breakpoint_ops; | |
16035 | *ops = base_breakpoint_ops; | |
16036 | ops->re_set = tracepoint_re_set; | |
16037 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16038 | ops->print_one_detail = tracepoint_print_one_detail; | |
16039 | ops->print_mention = tracepoint_print_mention; | |
16040 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16041 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16042 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16043 | ops->decode_linespec = tracepoint_decode_linespec; | |
16044 | ||
55aa24fb SDJ |
16045 | /* Probe tracepoints. */ |
16046 | ops = &tracepoint_probe_breakpoint_ops; | |
16047 | *ops = tracepoint_breakpoint_ops; | |
16048 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16049 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16050 | ||
983af33b SDJ |
16051 | /* Static tracepoints with marker (`-m'). */ |
16052 | ops = &strace_marker_breakpoint_ops; | |
16053 | *ops = tracepoint_breakpoint_ops; | |
16054 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16055 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16056 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16057 | |
16058 | /* Fork catchpoints. */ | |
16059 | ops = &catch_fork_breakpoint_ops; | |
16060 | *ops = base_breakpoint_ops; | |
16061 | ops->insert_location = insert_catch_fork; | |
16062 | ops->remove_location = remove_catch_fork; | |
16063 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16064 | ops->print_it = print_it_catch_fork; | |
16065 | ops->print_one = print_one_catch_fork; | |
16066 | ops->print_mention = print_mention_catch_fork; | |
16067 | ops->print_recreate = print_recreate_catch_fork; | |
16068 | ||
16069 | /* Vfork catchpoints. */ | |
16070 | ops = &catch_vfork_breakpoint_ops; | |
16071 | *ops = base_breakpoint_ops; | |
16072 | ops->insert_location = insert_catch_vfork; | |
16073 | ops->remove_location = remove_catch_vfork; | |
16074 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16075 | ops->print_it = print_it_catch_vfork; | |
16076 | ops->print_one = print_one_catch_vfork; | |
16077 | ops->print_mention = print_mention_catch_vfork; | |
16078 | ops->print_recreate = print_recreate_catch_vfork; | |
16079 | ||
16080 | /* Exec catchpoints. */ | |
16081 | ops = &catch_exec_breakpoint_ops; | |
16082 | *ops = base_breakpoint_ops; | |
16083 | ops->dtor = dtor_catch_exec; | |
16084 | ops->insert_location = insert_catch_exec; | |
16085 | ops->remove_location = remove_catch_exec; | |
16086 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16087 | ops->print_it = print_it_catch_exec; | |
16088 | ops->print_one = print_one_catch_exec; | |
16089 | ops->print_mention = print_mention_catch_exec; | |
16090 | ops->print_recreate = print_recreate_catch_exec; | |
16091 | ||
16092 | /* Syscall catchpoints. */ | |
16093 | ops = &catch_syscall_breakpoint_ops; | |
16094 | *ops = base_breakpoint_ops; | |
16095 | ops->dtor = dtor_catch_syscall; | |
16096 | ops->insert_location = insert_catch_syscall; | |
16097 | ops->remove_location = remove_catch_syscall; | |
16098 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16099 | ops->print_it = print_it_catch_syscall; | |
16100 | ops->print_one = print_one_catch_syscall; | |
16101 | ops->print_mention = print_mention_catch_syscall; | |
16102 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16103 | |
16104 | /* Solib-related catchpoints. */ | |
16105 | ops = &catch_solib_breakpoint_ops; | |
16106 | *ops = base_breakpoint_ops; | |
16107 | ops->dtor = dtor_catch_solib; | |
16108 | ops->insert_location = insert_catch_solib; | |
16109 | ops->remove_location = remove_catch_solib; | |
16110 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16111 | ops->check_status = check_status_catch_solib; | |
16112 | ops->print_it = print_it_catch_solib; | |
16113 | ops->print_one = print_one_catch_solib; | |
16114 | ops->print_mention = print_mention_catch_solib; | |
16115 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16116 | |
16117 | ops = &dprintf_breakpoint_ops; | |
16118 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16119 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16120 | ops->resources_needed = bkpt_resources_needed; |
16121 | ops->print_it = bkpt_print_it; | |
16122 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16123 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16124 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16125 | } |
16126 | ||
8bfd80db YQ |
16127 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16128 | ||
16129 | static struct cmd_list_element *enablebreaklist = NULL; | |
16130 | ||
c906108c | 16131 | void |
fba45db2 | 16132 | _initialize_breakpoint (void) |
c906108c SS |
16133 | { |
16134 | struct cmd_list_element *c; | |
16135 | ||
2060206e PA |
16136 | initialize_breakpoint_ops (); |
16137 | ||
84acb35a | 16138 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16139 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16140 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16141 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16142 | |
55aa24fb SDJ |
16143 | breakpoint_objfile_key |
16144 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16145 | |
fa3064dd | 16146 | catch_syscall_inferior_data |
8e260fc0 TT |
16147 | = register_inferior_data_with_cleanup (NULL, |
16148 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16149 | |
c906108c SS |
16150 | breakpoint_chain = 0; |
16151 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16152 | before a breakpoint is set. */ | |
16153 | breakpoint_count = 0; | |
16154 | ||
1042e4c0 SS |
16155 | tracepoint_count = 0; |
16156 | ||
1bedd215 AC |
16157 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16158 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16159 | Usage is `ignore N COUNT'.")); | |
c906108c | 16160 | if (xdb_commands) |
c5aa993b | 16161 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16162 | |
1bedd215 AC |
16163 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16164 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16165 | Give breakpoint number as argument after \"commands\".\n\ |
16166 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16167 | The commands themselves follow starting on the next line.\n\ | |
16168 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16169 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16170 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16171 | |
d55637df | 16172 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16173 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16174 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16175 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16176 | set_cmd_completer (c, condition_completer); |
c906108c | 16177 | |
1bedd215 | 16178 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16179 | Set a temporary breakpoint.\n\ |
c906108c SS |
16180 | Like \"break\" except the breakpoint is only temporary,\n\ |
16181 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16182 | by using \"enable delete\" on the breakpoint number.\n\ |
16183 | \n" | |
16184 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16185 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16186 | |
1bedd215 | 16187 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16188 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16189 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16190 | some target hardware may not have this support.\n\ |
16191 | \n" | |
16192 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16193 | set_cmd_completer (c, location_completer); |
c906108c | 16194 | |
1bedd215 | 16195 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16196 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16197 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16198 | so it will be deleted when hit.\n\ |
16199 | \n" | |
16200 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16201 | set_cmd_completer (c, location_completer); |
c906108c | 16202 | |
1bedd215 AC |
16203 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16204 | Enable some breakpoints.\n\ | |
c906108c SS |
16205 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16206 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16207 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16208 | With a subcommand you can enable temporarily."), |
c906108c SS |
16209 | &enablelist, "enable ", 1, &cmdlist); |
16210 | if (xdb_commands) | |
1bedd215 AC |
16211 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16212 | Enable some breakpoints.\n\ | |
c906108c SS |
16213 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16214 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16215 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16216 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16217 | |
16218 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16219 | ||
84951ab5 | 16220 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16221 | Enable some breakpoints.\n\ |
c906108c SS |
16222 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16223 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16224 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16225 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16226 | |
1a966eab AC |
16227 | add_cmd ("once", no_class, enable_once_command, _("\ |
16228 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16229 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16230 | &enablebreaklist); |
16231 | ||
1a966eab AC |
16232 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16233 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16234 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16235 | &enablebreaklist); |
16236 | ||
816338b5 SS |
16237 | add_cmd ("count", no_class, enable_count_command, _("\ |
16238 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16239 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16240 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16241 | &enablebreaklist); | |
16242 | ||
1a966eab AC |
16243 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16244 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16245 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16246 | &enablelist); |
16247 | ||
1a966eab AC |
16248 | add_cmd ("once", no_class, enable_once_command, _("\ |
16249 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16250 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16251 | &enablelist); |
16252 | ||
16253 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16254 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16255 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16256 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16257 | &enablelist); |
16258 | ||
1bedd215 AC |
16259 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16260 | Disable some breakpoints.\n\ | |
c906108c SS |
16261 | Arguments are breakpoint numbers with spaces in between.\n\ |
16262 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16263 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16264 | &disablelist, "disable ", 1, &cmdlist); |
16265 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16266 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16267 | if (xdb_commands) | |
1bedd215 AC |
16268 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16269 | Disable some breakpoints.\n\ | |
c906108c SS |
16270 | Arguments are breakpoint numbers with spaces in between.\n\ |
16271 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16272 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16273 | |
1a966eab AC |
16274 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16275 | Disable some breakpoints.\n\ | |
c906108c SS |
16276 | Arguments are breakpoint numbers with spaces in between.\n\ |
16277 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16278 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16279 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16280 | &disablelist); |
16281 | ||
1bedd215 AC |
16282 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16283 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16284 | Arguments are breakpoint numbers with spaces in between.\n\ |
16285 | To delete all breakpoints, give no argument.\n\ | |
16286 | \n\ | |
16287 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16288 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16289 | &deletelist, "delete ", 1, &cmdlist); |
16290 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16291 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16292 | if (xdb_commands) |
1bedd215 AC |
16293 | add_com ("db", class_breakpoint, delete_command, _("\ |
16294 | Delete some breakpoints.\n\ | |
c906108c | 16295 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16296 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16297 | |
1a966eab AC |
16298 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16299 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16300 | Arguments are breakpoint numbers with spaces in between.\n\ |
16301 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16302 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16303 | &deletelist); |
16304 | ||
1bedd215 AC |
16305 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16306 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16307 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16308 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16309 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16310 | If an address is specified, breakpoints at that address are cleared.\n\ |
16311 | \n\ | |
16312 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16313 | is executing in.\n\ |
16314 | \n\ | |
1bedd215 | 16315 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16316 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16317 | |
1bedd215 | 16318 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16319 | Set breakpoint at specified line or function.\n" |
16320 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16321 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16322 | |
c906108c SS |
16323 | add_com_alias ("b", "break", class_run, 1); |
16324 | add_com_alias ("br", "break", class_run, 1); | |
16325 | add_com_alias ("bre", "break", class_run, 1); | |
16326 | add_com_alias ("brea", "break", class_run, 1); | |
16327 | ||
7681d515 PM |
16328 | if (xdb_commands) |
16329 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16330 | |
16331 | if (dbx_commands) | |
16332 | { | |
1bedd215 AC |
16333 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16334 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16335 | &stoplist, "stop ", 1, &cmdlist); |
16336 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16337 | _("Break in function or address."), &stoplist); |
c5aa993b | 16338 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16339 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16340 | add_com ("status", class_info, breakpoints_info, _("\ |
16341 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16342 | The \"Type\" column indicates one of:\n\ |
16343 | \tbreakpoint - normal breakpoint\n\ | |
16344 | \twatchpoint - watchpoint\n\ | |
16345 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16346 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16347 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16348 | address and file/line number respectively.\n\ |
16349 | \n\ | |
16350 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16351 | are set to the address of the last breakpoint listed unless the command\n\ |
16352 | is prefixed with \"server \".\n\n\ | |
c906108c | 16353 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16354 | breakpoint set.")); |
c906108c SS |
16355 | } |
16356 | ||
1bedd215 | 16357 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16358 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16359 | The \"Type\" column indicates one of:\n\ |
16360 | \tbreakpoint - normal breakpoint\n\ | |
16361 | \twatchpoint - watchpoint\n\ | |
16362 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16363 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16364 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16365 | address and file/line number respectively.\n\ |
16366 | \n\ | |
16367 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16368 | are set to the address of the last breakpoint listed unless the command\n\ |
16369 | is prefixed with \"server \".\n\n\ | |
c906108c | 16370 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16371 | breakpoint set.")); |
c906108c | 16372 | |
6b04bdb7 MS |
16373 | add_info_alias ("b", "breakpoints", 1); |
16374 | ||
c906108c | 16375 | if (xdb_commands) |
1bedd215 AC |
16376 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16377 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16378 | The \"Type\" column indicates one of:\n\ |
16379 | \tbreakpoint - normal breakpoint\n\ | |
16380 | \twatchpoint - watchpoint\n\ | |
16381 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16382 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16383 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16384 | address and file/line number respectively.\n\ |
16385 | \n\ | |
16386 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16387 | are set to the address of the last breakpoint listed unless the command\n\ |
16388 | is prefixed with \"server \".\n\n\ | |
c906108c | 16389 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16390 | breakpoint set.")); |
c906108c | 16391 | |
1a966eab AC |
16392 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16393 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16394 | The \"Type\" column indicates one of:\n\ |
16395 | \tbreakpoint - normal breakpoint\n\ | |
16396 | \twatchpoint - watchpoint\n\ | |
16397 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16398 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16399 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16400 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16401 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16402 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16403 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16404 | address and file/line number respectively.\n\ |
16405 | \n\ | |
16406 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16407 | are set to the address of the last breakpoint listed unless the command\n\ |
16408 | is prefixed with \"server \".\n\n\ | |
c906108c | 16409 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16410 | breakpoint set."), |
c906108c SS |
16411 | &maintenanceinfolist); |
16412 | ||
44feb3ce TT |
16413 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16414 | Set catchpoints to catch events."), | |
16415 | &catch_cmdlist, "catch ", | |
16416 | 0/*allow-unknown*/, &cmdlist); | |
16417 | ||
16418 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16419 | Set temporary catchpoints to catch events."), | |
16420 | &tcatch_cmdlist, "tcatch ", | |
16421 | 0/*allow-unknown*/, &cmdlist); | |
16422 | ||
44feb3ce TT |
16423 | add_catch_command ("fork", _("Catch calls to fork."), |
16424 | catch_fork_command_1, | |
a96d9b2e | 16425 | NULL, |
44feb3ce TT |
16426 | (void *) (uintptr_t) catch_fork_permanent, |
16427 | (void *) (uintptr_t) catch_fork_temporary); | |
16428 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16429 | catch_fork_command_1, | |
a96d9b2e | 16430 | NULL, |
44feb3ce TT |
16431 | (void *) (uintptr_t) catch_vfork_permanent, |
16432 | (void *) (uintptr_t) catch_vfork_temporary); | |
16433 | add_catch_command ("exec", _("Catch calls to exec."), | |
16434 | catch_exec_command_1, | |
a96d9b2e SDJ |
16435 | NULL, |
16436 | CATCH_PERMANENT, | |
16437 | CATCH_TEMPORARY); | |
edcc5120 TT |
16438 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16439 | Usage: catch load [REGEX]\n\ | |
16440 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16441 | catch_load_command_1, | |
16442 | NULL, | |
16443 | CATCH_PERMANENT, | |
16444 | CATCH_TEMPORARY); | |
16445 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16446 | Usage: catch unload [REGEX]\n\ | |
16447 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16448 | catch_unload_command_1, | |
16449 | NULL, | |
16450 | CATCH_PERMANENT, | |
16451 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16452 | add_catch_command ("syscall", _("\ |
16453 | Catch system calls by their names and/or numbers.\n\ | |
16454 | Arguments say which system calls to catch. If no arguments\n\ | |
16455 | are given, every system call will be caught.\n\ | |
16456 | Arguments, if given, should be one or more system call names\n\ | |
16457 | (if your system supports that), or system call numbers."), | |
16458 | catch_syscall_command_1, | |
16459 | catch_syscall_completer, | |
44feb3ce TT |
16460 | CATCH_PERMANENT, |
16461 | CATCH_TEMPORARY); | |
c5aa993b | 16462 | |
1bedd215 AC |
16463 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16464 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16465 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16466 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16467 | an expression changes.\n\ |
16468 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16469 | the memory to which it refers.")); | |
65d12d83 | 16470 | set_cmd_completer (c, expression_completer); |
c906108c | 16471 | |
1bedd215 AC |
16472 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16473 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16474 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16475 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16476 | an expression is read.\n\ |
16477 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16478 | the memory to which it refers.")); | |
65d12d83 | 16479 | set_cmd_completer (c, expression_completer); |
c906108c | 16480 | |
1bedd215 AC |
16481 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16482 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16483 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16484 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16485 | an expression is either read or written.\n\ |
16486 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16487 | the memory to which it refers.")); | |
65d12d83 | 16488 | set_cmd_completer (c, expression_completer); |
c906108c | 16489 | |
d77f58be | 16490 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16491 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16492 | |
920d2a44 AC |
16493 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16494 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16495 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16496 | &can_use_hw_watchpoints, _("\ | |
16497 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16498 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16499 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16500 | such is available. (However, any hardware watchpoints that were\n\ | |
16501 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16502 | hardware.)"), |
16503 | NULL, | |
920d2a44 | 16504 | show_can_use_hw_watchpoints, |
85c07804 | 16505 | &setlist, &showlist); |
c906108c SS |
16506 | |
16507 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16508 | |
1042e4c0 SS |
16509 | /* Tracepoint manipulation commands. */ |
16510 | ||
16511 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16512 | Set a tracepoint at specified line or function.\n\ | |
16513 | \n" | |
16514 | BREAK_ARGS_HELP ("trace") "\n\ | |
16515 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16516 | set_cmd_completer (c, location_completer); | |
16517 | ||
16518 | add_com_alias ("tp", "trace", class_alias, 0); | |
16519 | add_com_alias ("tr", "trace", class_alias, 1); | |
16520 | add_com_alias ("tra", "trace", class_alias, 1); | |
16521 | add_com_alias ("trac", "trace", class_alias, 1); | |
16522 | ||
7a697b8d SS |
16523 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16524 | Set a fast tracepoint at specified line or function.\n\ | |
16525 | \n" | |
16526 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16527 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16528 | set_cmd_completer (c, location_completer); | |
16529 | ||
0fb4aa4b PA |
16530 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16531 | Set a static tracepoint at specified line, function or marker.\n\ | |
16532 | \n\ | |
16533 | strace [LOCATION] [if CONDITION]\n\ | |
16534 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16535 | or -m MARKER_ID.\n\ | |
16536 | If a line number is specified, probe the marker at start of code\n\ | |
16537 | for that line. If a function is specified, probe the marker at start\n\ | |
16538 | of code for that function. If an address is specified, probe the marker\n\ | |
16539 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16540 | with that name. With no LOCATION, uses current execution address of\n\ | |
16541 | the selected stack frame.\n\ | |
16542 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16543 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16544 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16545 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16546 | \n\ | |
16547 | CONDITION is a boolean expression.\n\ | |
16548 | \n\ | |
d41c0fc8 PA |
16549 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16550 | conditions are different.\n\ | |
0fb4aa4b PA |
16551 | \n\ |
16552 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16553 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16554 | set_cmd_completer (c, location_completer); | |
16555 | ||
1042e4c0 | 16556 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16557 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16558 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16559 | last tracepoint set.")); | |
16560 | ||
16561 | add_info_alias ("tp", "tracepoints", 1); | |
16562 | ||
16563 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16564 | Delete specified tracepoints.\n\ | |
16565 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16566 | No argument means delete all tracepoints."), | |
16567 | &deletelist); | |
7e20dfcd | 16568 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16569 | |
16570 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16571 | Disable specified tracepoints.\n\ | |
16572 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16573 | No argument means disable all tracepoints."), | |
16574 | &disablelist); | |
16575 | deprecate_cmd (c, "disable"); | |
16576 | ||
16577 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16578 | Enable specified tracepoints.\n\ | |
16579 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16580 | No argument means enable all tracepoints."), | |
16581 | &enablelist); | |
16582 | deprecate_cmd (c, "enable"); | |
16583 | ||
16584 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16585 | Set the passcount for a tracepoint.\n\ | |
16586 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16587 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16588 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16589 | ||
6149aea9 PA |
16590 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16591 | _("Save breakpoint definitions as a script."), | |
16592 | &save_cmdlist, "save ", | |
16593 | 0/*allow-unknown*/, &cmdlist); | |
16594 | ||
16595 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16596 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16597 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16598 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16599 | session to restore them."), | |
16600 | &save_cmdlist); | |
16601 | set_cmd_completer (c, filename_completer); | |
16602 | ||
16603 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16604 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16605 | Use the 'source' command in another debug session to restore them."), |
16606 | &save_cmdlist); | |
1042e4c0 SS |
16607 | set_cmd_completer (c, filename_completer); |
16608 | ||
6149aea9 PA |
16609 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16610 | deprecate_cmd (c, "save tracepoints"); | |
16611 | ||
1bedd215 | 16612 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16613 | Breakpoint specific settings\n\ |
16614 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16615 | pending breakpoint behavior"), |
fa8d40ab JJ |
16616 | &breakpoint_set_cmdlist, "set breakpoint ", |
16617 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16618 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16619 | Breakpoint specific settings\n\ |
16620 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16621 | pending breakpoint behavior"), |
fa8d40ab JJ |
16622 | &breakpoint_show_cmdlist, "show breakpoint ", |
16623 | 0/*allow-unknown*/, &showlist); | |
16624 | ||
7915a72c AC |
16625 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16626 | &pending_break_support, _("\ | |
16627 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16628 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16629 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16630 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16631 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16632 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16633 | NULL, |
920d2a44 | 16634 | show_pending_break_support, |
6e1d7d6c AC |
16635 | &breakpoint_set_cmdlist, |
16636 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16637 | |
16638 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16639 | |
16640 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16641 | &automatic_hardware_breakpoints, _("\ | |
16642 | Set automatic usage of hardware breakpoints."), _("\ | |
16643 | Show automatic usage of hardware breakpoints."), _("\ | |
16644 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16645 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16646 | a warning will be emitted for such breakpoints."), | |
16647 | NULL, | |
16648 | show_automatic_hardware_breakpoints, | |
16649 | &breakpoint_set_cmdlist, | |
16650 | &breakpoint_show_cmdlist); | |
74960c60 | 16651 | |
72d0e2c5 YQ |
16652 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16653 | &always_inserted_mode, _("\ | |
74960c60 VP |
16654 | Set mode for inserting breakpoints."), _("\ |
16655 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16656 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16657 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16658 | breakpoints are inserted immediately and removed only when the user\n\ | |
16659 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16660 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16661 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16662 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16663 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16664 | NULL, |
16665 | &show_always_inserted_mode, | |
16666 | &breakpoint_set_cmdlist, | |
16667 | &breakpoint_show_cmdlist); | |
f1310107 | 16668 | |
b775012e LM |
16669 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16670 | condition_evaluation_enums, | |
16671 | &condition_evaluation_mode_1, _("\ | |
16672 | Set mode of breakpoint condition evaluation."), _("\ | |
16673 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16674 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16675 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16676 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16677 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16678 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16679 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16680 | be set to \"gdb\""), | |
16681 | &set_condition_evaluation_mode, | |
16682 | &show_condition_evaluation_mode, | |
16683 | &breakpoint_set_cmdlist, | |
16684 | &breakpoint_show_cmdlist); | |
16685 | ||
f1310107 TJB |
16686 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16687 | Set a breakpoint for an address range.\n\ | |
16688 | break-range START-LOCATION, END-LOCATION\n\ | |
16689 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16690 | LINENUM, for that line in the current file,\n\ | |
16691 | FILE:LINENUM, for that line in that file,\n\ | |
16692 | +OFFSET, for that number of lines after the current line\n\ | |
16693 | or the start of the range\n\ | |
16694 | FUNCTION, for the first line in that function,\n\ | |
16695 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16696 | *ADDRESS, for the instruction at that address.\n\ | |
16697 | \n\ | |
16698 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16699 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16700 | range (including START-LOCATION and END-LOCATION).")); | |
16701 | ||
e7e0cddf SS |
16702 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16703 | Set a dynamic printf at specified line or function.\n\ | |
16704 | dprintf location,format string,arg1,arg2,...\n\ | |
16705 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16706 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16707 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16708 | set_cmd_completer (c, location_completer); |
16709 | ||
16710 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16711 | dprintf_style_enums, &dprintf_style, _("\ | |
16712 | Set the style of usage for dynamic printf."), _("\ | |
16713 | Show the style of usage for dynamic printf."), _("\ | |
16714 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16715 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16716 | console, as with the \"printf\" command.\n\ | |
16717 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16718 | program; by default printf(), but you can choose a different function or\n\ | |
16719 | output stream by setting dprintf-function and dprintf-channel."), | |
16720 | update_dprintf_commands, NULL, | |
16721 | &setlist, &showlist); | |
16722 | ||
16723 | dprintf_function = xstrdup ("printf"); | |
16724 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16725 | &dprintf_function, _("\ | |
16726 | Set the function to use for dynamic printf"), _("\ | |
16727 | Show the function to use for dynamic printf"), NULL, | |
16728 | update_dprintf_commands, NULL, | |
16729 | &setlist, &showlist); | |
16730 | ||
16731 | dprintf_channel = xstrdup (""); | |
16732 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16733 | &dprintf_channel, _("\ | |
16734 | Set the channel to use for dynamic printf"), _("\ | |
16735 | Show the channel to use for dynamic printf"), NULL, | |
16736 | update_dprintf_commands, NULL, | |
16737 | &setlist, &showlist); | |
16738 | ||
d3ce09f5 SS |
16739 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16740 | &disconnected_dprintf, _("\ | |
16741 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16742 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16743 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16744 | even if GDB disconnects or detaches from the target."), | |
16745 | NULL, | |
16746 | NULL, | |
16747 | &setlist, &showlist); | |
16748 | ||
16749 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16750 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16751 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16752 | ||
765dc015 | 16753 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16754 | |
16755 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16756 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16757 | } |