]>
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 | |
9d497a19 PA |
296 | /* One (or perhaps two) breakpoints used for software single |
297 | stepping. */ | |
298 | ||
299 | static void *single_step_breakpoints[2]; | |
300 | static struct gdbarch *single_step_gdbarch[2]; | |
301 | ||
d3ce09f5 SS |
302 | /* The style in which to perform a dynamic printf. This is a user |
303 | option because different output options have different tradeoffs; | |
304 | if GDB does the printing, there is better error handling if there | |
305 | is a problem with any of the arguments, but using an inferior | |
306 | function lets you have special-purpose printers and sending of | |
307 | output to the same place as compiled-in print functions. */ | |
308 | ||
309 | static const char dprintf_style_gdb[] = "gdb"; | |
310 | static const char dprintf_style_call[] = "call"; | |
311 | static const char dprintf_style_agent[] = "agent"; | |
312 | static const char *const dprintf_style_enums[] = { | |
313 | dprintf_style_gdb, | |
314 | dprintf_style_call, | |
315 | dprintf_style_agent, | |
316 | NULL | |
317 | }; | |
318 | static const char *dprintf_style = dprintf_style_gdb; | |
319 | ||
320 | /* The function to use for dynamic printf if the preferred style is to | |
321 | call into the inferior. The value is simply a string that is | |
322 | copied into the command, so it can be anything that GDB can | |
323 | evaluate to a callable address, not necessarily a function name. */ | |
324 | ||
325 | static char *dprintf_function = ""; | |
326 | ||
327 | /* The channel to use for dynamic printf if the preferred style is to | |
328 | call into the inferior; if a nonempty string, it will be passed to | |
329 | the call as the first argument, with the format string as the | |
330 | second. As with the dprintf function, this can be anything that | |
331 | GDB knows how to evaluate, so in addition to common choices like | |
332 | "stderr", this could be an app-specific expression like | |
333 | "mystreams[curlogger]". */ | |
334 | ||
335 | static char *dprintf_channel = ""; | |
336 | ||
337 | /* True if dprintf commands should continue to operate even if GDB | |
338 | has disconnected. */ | |
339 | static int disconnected_dprintf = 1; | |
340 | ||
5cea2a26 PA |
341 | /* A reference-counted struct command_line. This lets multiple |
342 | breakpoints share a single command list. */ | |
343 | struct counted_command_line | |
344 | { | |
345 | /* The reference count. */ | |
346 | int refc; | |
347 | ||
348 | /* The command list. */ | |
349 | struct command_line *commands; | |
350 | }; | |
351 | ||
352 | struct command_line * | |
353 | breakpoint_commands (struct breakpoint *b) | |
354 | { | |
355 | return b->commands ? b->commands->commands : NULL; | |
356 | } | |
3daf8fe5 | 357 | |
f3b1572e PA |
358 | /* Flag indicating that a command has proceeded the inferior past the |
359 | current breakpoint. */ | |
360 | ||
361 | static int breakpoint_proceeded; | |
362 | ||
956a9fb9 | 363 | const char * |
2cec12e5 AR |
364 | bpdisp_text (enum bpdisp disp) |
365 | { | |
4a64f543 MS |
366 | /* NOTE: the following values are a part of MI protocol and |
367 | represent values of 'disp' field returned when inferior stops at | |
368 | a breakpoint. */ | |
bc043ef3 | 369 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 370 | |
2cec12e5 AR |
371 | return bpdisps[(int) disp]; |
372 | } | |
c906108c | 373 | |
4a64f543 | 374 | /* Prototypes for exported functions. */ |
c906108c | 375 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 376 | if such is available. */ |
c906108c SS |
377 | static int can_use_hw_watchpoints; |
378 | ||
920d2a44 AC |
379 | static void |
380 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
381 | struct cmd_list_element *c, | |
382 | const char *value) | |
383 | { | |
3e43a32a MS |
384 | fprintf_filtered (file, |
385 | _("Debugger's willingness to use " | |
386 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
387 | value); |
388 | } | |
389 | ||
fa8d40ab JJ |
390 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
391 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 392 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
393 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
394 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
395 | static void |
396 | show_pending_break_support (struct ui_file *file, int from_tty, | |
397 | struct cmd_list_element *c, | |
398 | const char *value) | |
399 | { | |
3e43a32a MS |
400 | fprintf_filtered (file, |
401 | _("Debugger's behavior regarding " | |
402 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
403 | value); |
404 | } | |
fa8d40ab | 405 | |
765dc015 | 406 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 407 | set with "break" but falling in read-only memory. |
765dc015 VP |
408 | If 0, gdb will warn about such breakpoints, but won't automatically |
409 | use hardware breakpoints. */ | |
410 | static int automatic_hardware_breakpoints; | |
411 | static void | |
412 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
413 | struct cmd_list_element *c, | |
414 | const char *value) | |
415 | { | |
3e43a32a MS |
416 | fprintf_filtered (file, |
417 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
418 | value); |
419 | } | |
420 | ||
33e5cbd6 PA |
421 | /* If on, gdb will keep breakpoints inserted even as inferior is |
422 | stopped, and immediately insert any new breakpoints. If off, gdb | |
423 | will insert breakpoints into inferior only when resuming it, and | |
424 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
425 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
426 | ||
72d0e2c5 YQ |
427 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
428 | ||
33e5cbd6 | 429 | static void |
74960c60 | 430 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 431 | struct cmd_list_element *c, const char *value) |
74960c60 | 432 | { |
72d0e2c5 | 433 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
434 | fprintf_filtered (file, |
435 | _("Always inserted breakpoint " | |
436 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
437 | value, |
438 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
439 | else | |
3e43a32a MS |
440 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
441 | value); | |
74960c60 VP |
442 | } |
443 | ||
33e5cbd6 PA |
444 | int |
445 | breakpoints_always_inserted_mode (void) | |
446 | { | |
72d0e2c5 YQ |
447 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
448 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 449 | } |
765dc015 | 450 | |
b775012e LM |
451 | static const char condition_evaluation_both[] = "host or target"; |
452 | ||
453 | /* Modes for breakpoint condition evaluation. */ | |
454 | static const char condition_evaluation_auto[] = "auto"; | |
455 | static const char condition_evaluation_host[] = "host"; | |
456 | static const char condition_evaluation_target[] = "target"; | |
457 | static const char *const condition_evaluation_enums[] = { | |
458 | condition_evaluation_auto, | |
459 | condition_evaluation_host, | |
460 | condition_evaluation_target, | |
461 | NULL | |
462 | }; | |
463 | ||
464 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
465 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
466 | ||
467 | /* Global that we use to display information to the user (gets its value from | |
468 | condition_evaluation_mode_1. */ | |
469 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
470 | ||
471 | /* Translate a condition evaluation mode MODE into either "host" | |
472 | or "target". This is used mostly to translate from "auto" to the | |
473 | real setting that is being used. It returns the translated | |
474 | evaluation mode. */ | |
475 | ||
476 | static const char * | |
477 | translate_condition_evaluation_mode (const char *mode) | |
478 | { | |
479 | if (mode == condition_evaluation_auto) | |
480 | { | |
481 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
482 | return condition_evaluation_target; | |
483 | else | |
484 | return condition_evaluation_host; | |
485 | } | |
486 | else | |
487 | return mode; | |
488 | } | |
489 | ||
490 | /* Discovers what condition_evaluation_auto translates to. */ | |
491 | ||
492 | static const char * | |
493 | breakpoint_condition_evaluation_mode (void) | |
494 | { | |
495 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
496 | } | |
497 | ||
498 | /* Return true if GDB should evaluate breakpoint conditions or false | |
499 | otherwise. */ | |
500 | ||
501 | static int | |
502 | gdb_evaluates_breakpoint_condition_p (void) | |
503 | { | |
504 | const char *mode = breakpoint_condition_evaluation_mode (); | |
505 | ||
506 | return (mode == condition_evaluation_host); | |
507 | } | |
508 | ||
a14ed312 | 509 | void _initialize_breakpoint (void); |
c906108c | 510 | |
c906108c SS |
511 | /* Are we executing breakpoint commands? */ |
512 | static int executing_breakpoint_commands; | |
513 | ||
c02f5703 MS |
514 | /* Are overlay event breakpoints enabled? */ |
515 | static int overlay_events_enabled; | |
516 | ||
e09342b5 TJB |
517 | /* See description in breakpoint.h. */ |
518 | int target_exact_watchpoints = 0; | |
519 | ||
c906108c | 520 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 521 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 522 | current breakpoint. */ |
c906108c | 523 | |
5c44784c | 524 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 525 | |
5c44784c JM |
526 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
527 | for (B = breakpoint_chain; \ | |
528 | B ? (TMP=B->next, 1): 0; \ | |
529 | B = TMP) | |
c906108c | 530 | |
4a64f543 MS |
531 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
532 | not provided so update_global_location_list must not be called | |
533 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 534 | |
876fa593 JK |
535 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
536 | for (BP_TMP = bp_location; \ | |
537 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
538 | BP_TMP++) | |
7cc221ef | 539 | |
b775012e LM |
540 | /* Iterates through locations with address ADDRESS for the currently selected |
541 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
542 | to where the loop should start from. | |
543 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
544 | appropriate location to start with. */ | |
545 | ||
546 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
547 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
548 | BP_LOCP_TMP = BP_LOCP_START; \ | |
549 | BP_LOCP_START \ | |
550 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
551 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
552 | BP_LOCP_TMP++) | |
553 | ||
1042e4c0 SS |
554 | /* Iterator for tracepoints only. */ |
555 | ||
556 | #define ALL_TRACEPOINTS(B) \ | |
557 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 558 | if (is_tracepoint (B)) |
1042e4c0 | 559 | |
7cc221ef | 560 | /* Chains of all breakpoints defined. */ |
c906108c SS |
561 | |
562 | struct breakpoint *breakpoint_chain; | |
563 | ||
876fa593 JK |
564 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
565 | ||
566 | static struct bp_location **bp_location; | |
567 | ||
568 | /* Number of elements of BP_LOCATION. */ | |
569 | ||
570 | static unsigned bp_location_count; | |
571 | ||
4a64f543 MS |
572 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
573 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
574 | result from bp_location_has_shadow. You can use it for roughly | |
575 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
576 | an address you need to read. */ | |
876fa593 JK |
577 | |
578 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
579 | ||
4a64f543 MS |
580 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
581 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
582 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
583 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
584 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
585 | |
586 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 587 | |
4a64f543 MS |
588 | /* The locations that no longer correspond to any breakpoint, unlinked |
589 | from bp_location array, but for which a hit may still be reported | |
590 | by a target. */ | |
20874c92 VP |
591 | VEC(bp_location_p) *moribund_locations = NULL; |
592 | ||
c906108c SS |
593 | /* Number of last breakpoint made. */ |
594 | ||
95a42b64 TT |
595 | static int breakpoint_count; |
596 | ||
86b17b60 PA |
597 | /* The value of `breakpoint_count' before the last command that |
598 | created breakpoints. If the last (break-like) command created more | |
599 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
600 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
601 | static int prev_breakpoint_count; | |
c906108c | 602 | |
1042e4c0 SS |
603 | /* Number of last tracepoint made. */ |
604 | ||
95a42b64 | 605 | static int tracepoint_count; |
1042e4c0 | 606 | |
6149aea9 PA |
607 | static struct cmd_list_element *breakpoint_set_cmdlist; |
608 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 609 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 610 | |
468d015d JJ |
611 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
612 | static int | |
613 | breakpoint_enabled (struct breakpoint *b) | |
614 | { | |
0d381245 | 615 | return (b->enable_state == bp_enabled); |
468d015d JJ |
616 | } |
617 | ||
c906108c SS |
618 | /* Set breakpoint count to NUM. */ |
619 | ||
95a42b64 | 620 | static void |
fba45db2 | 621 | set_breakpoint_count (int num) |
c906108c | 622 | { |
86b17b60 | 623 | prev_breakpoint_count = breakpoint_count; |
c906108c | 624 | breakpoint_count = num; |
4fa62494 | 625 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
626 | } |
627 | ||
86b17b60 PA |
628 | /* Used by `start_rbreak_breakpoints' below, to record the current |
629 | breakpoint count before "rbreak" creates any breakpoint. */ | |
630 | static int rbreak_start_breakpoint_count; | |
631 | ||
95a42b64 TT |
632 | /* Called at the start an "rbreak" command to record the first |
633 | breakpoint made. */ | |
86b17b60 | 634 | |
95a42b64 TT |
635 | void |
636 | start_rbreak_breakpoints (void) | |
637 | { | |
86b17b60 | 638 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
639 | } |
640 | ||
641 | /* Called at the end of an "rbreak" command to record the last | |
642 | breakpoint made. */ | |
86b17b60 | 643 | |
95a42b64 TT |
644 | void |
645 | end_rbreak_breakpoints (void) | |
646 | { | |
86b17b60 | 647 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
648 | } |
649 | ||
4a64f543 | 650 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
651 | |
652 | void | |
fba45db2 | 653 | clear_breakpoint_hit_counts (void) |
c906108c SS |
654 | { |
655 | struct breakpoint *b; | |
656 | ||
657 | ALL_BREAKPOINTS (b) | |
658 | b->hit_count = 0; | |
659 | } | |
660 | ||
9add0f1b TT |
661 | /* Allocate a new counted_command_line with reference count of 1. |
662 | The new structure owns COMMANDS. */ | |
663 | ||
664 | static struct counted_command_line * | |
665 | alloc_counted_command_line (struct command_line *commands) | |
666 | { | |
667 | struct counted_command_line *result | |
668 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 669 | |
9add0f1b TT |
670 | result->refc = 1; |
671 | result->commands = commands; | |
672 | return result; | |
673 | } | |
674 | ||
675 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
676 | ||
677 | static void | |
678 | incref_counted_command_line (struct counted_command_line *cmd) | |
679 | { | |
680 | if (cmd) | |
681 | ++cmd->refc; | |
682 | } | |
683 | ||
684 | /* Decrement reference count. If the reference count reaches 0, | |
685 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
686 | nothing if *CMDP is NULL. */ | |
687 | ||
688 | static void | |
689 | decref_counted_command_line (struct counted_command_line **cmdp) | |
690 | { | |
691 | if (*cmdp) | |
692 | { | |
693 | if (--(*cmdp)->refc == 0) | |
694 | { | |
695 | free_command_lines (&(*cmdp)->commands); | |
696 | xfree (*cmdp); | |
697 | } | |
698 | *cmdp = NULL; | |
699 | } | |
700 | } | |
701 | ||
702 | /* A cleanup function that calls decref_counted_command_line. */ | |
703 | ||
704 | static void | |
705 | do_cleanup_counted_command_line (void *arg) | |
706 | { | |
707 | decref_counted_command_line (arg); | |
708 | } | |
709 | ||
710 | /* Create a cleanup that calls decref_counted_command_line on the | |
711 | argument. */ | |
712 | ||
713 | static struct cleanup * | |
714 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
715 | { | |
716 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
717 | } | |
718 | ||
c906108c | 719 | \f |
48cb2d85 VP |
720 | /* Return the breakpoint with the specified number, or NULL |
721 | if the number does not refer to an existing breakpoint. */ | |
722 | ||
723 | struct breakpoint * | |
724 | get_breakpoint (int num) | |
725 | { | |
726 | struct breakpoint *b; | |
727 | ||
728 | ALL_BREAKPOINTS (b) | |
729 | if (b->number == num) | |
730 | return b; | |
731 | ||
732 | return NULL; | |
733 | } | |
5c44784c | 734 | |
c906108c | 735 | \f |
adc36818 | 736 | |
b775012e LM |
737 | /* Mark locations as "conditions have changed" in case the target supports |
738 | evaluating conditions on its side. */ | |
739 | ||
740 | static void | |
741 | mark_breakpoint_modified (struct breakpoint *b) | |
742 | { | |
743 | struct bp_location *loc; | |
744 | ||
745 | /* This is only meaningful if the target is | |
746 | evaluating conditions and if the user has | |
747 | opted for condition evaluation on the target's | |
748 | side. */ | |
749 | if (gdb_evaluates_breakpoint_condition_p () | |
750 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
751 | return; | |
752 | ||
753 | if (!is_breakpoint (b)) | |
754 | return; | |
755 | ||
756 | for (loc = b->loc; loc; loc = loc->next) | |
757 | loc->condition_changed = condition_modified; | |
758 | } | |
759 | ||
760 | /* Mark location as "conditions have changed" in case the target supports | |
761 | evaluating conditions on its side. */ | |
762 | ||
763 | static void | |
764 | mark_breakpoint_location_modified (struct bp_location *loc) | |
765 | { | |
766 | /* This is only meaningful if the target is | |
767 | evaluating conditions and if the user has | |
768 | opted for condition evaluation on the target's | |
769 | side. */ | |
770 | if (gdb_evaluates_breakpoint_condition_p () | |
771 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
772 | ||
773 | return; | |
774 | ||
775 | if (!is_breakpoint (loc->owner)) | |
776 | return; | |
777 | ||
778 | loc->condition_changed = condition_modified; | |
779 | } | |
780 | ||
781 | /* Sets the condition-evaluation mode using the static global | |
782 | condition_evaluation_mode. */ | |
783 | ||
784 | static void | |
785 | set_condition_evaluation_mode (char *args, int from_tty, | |
786 | struct cmd_list_element *c) | |
787 | { | |
b775012e LM |
788 | const char *old_mode, *new_mode; |
789 | ||
790 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
791 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
792 | { | |
793 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
794 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
795 | "Using host evaluation mode instead.")); | |
796 | return; | |
797 | } | |
798 | ||
799 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
800 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
801 | ||
abf1152a JK |
802 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
803 | settings was "auto". */ | |
804 | condition_evaluation_mode = condition_evaluation_mode_1; | |
805 | ||
b775012e LM |
806 | /* Only update the mode if the user picked a different one. */ |
807 | if (new_mode != old_mode) | |
808 | { | |
809 | struct bp_location *loc, **loc_tmp; | |
810 | /* If the user switched to a different evaluation mode, we | |
811 | need to synch the changes with the target as follows: | |
812 | ||
813 | "host" -> "target": Send all (valid) conditions to the target. | |
814 | "target" -> "host": Remove all the conditions from the target. | |
815 | */ | |
816 | ||
b775012e LM |
817 | if (new_mode == condition_evaluation_target) |
818 | { | |
819 | /* Mark everything modified and synch conditions with the | |
820 | target. */ | |
821 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
822 | mark_breakpoint_location_modified (loc); | |
823 | } | |
824 | else | |
825 | { | |
826 | /* Manually mark non-duplicate locations to synch conditions | |
827 | with the target. We do this to remove all the conditions the | |
828 | target knows about. */ | |
829 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
830 | if (is_breakpoint (loc->owner) && loc->inserted) | |
831 | loc->needs_update = 1; | |
832 | } | |
833 | ||
834 | /* Do the update. */ | |
835 | update_global_location_list (1); | |
836 | } | |
837 | ||
838 | return; | |
839 | } | |
840 | ||
841 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
842 | what "auto" is translating to. */ | |
843 | ||
844 | static void | |
845 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
846 | struct cmd_list_element *c, const char *value) | |
847 | { | |
848 | if (condition_evaluation_mode == condition_evaluation_auto) | |
849 | fprintf_filtered (file, | |
850 | _("Breakpoint condition evaluation " | |
851 | "mode is %s (currently %s).\n"), | |
852 | value, | |
853 | breakpoint_condition_evaluation_mode ()); | |
854 | else | |
855 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
856 | value); | |
857 | } | |
858 | ||
859 | /* A comparison function for bp_location AP and BP that is used by | |
860 | bsearch. This comparison function only cares about addresses, unlike | |
861 | the more general bp_location_compare function. */ | |
862 | ||
863 | static int | |
864 | bp_location_compare_addrs (const void *ap, const void *bp) | |
865 | { | |
866 | struct bp_location *a = *(void **) ap; | |
867 | struct bp_location *b = *(void **) bp; | |
868 | ||
869 | if (a->address == b->address) | |
870 | return 0; | |
871 | else | |
872 | return ((a->address > b->address) - (a->address < b->address)); | |
873 | } | |
874 | ||
875 | /* Helper function to skip all bp_locations with addresses | |
876 | less than ADDRESS. It returns the first bp_location that | |
877 | is greater than or equal to ADDRESS. If none is found, just | |
878 | return NULL. */ | |
879 | ||
880 | static struct bp_location ** | |
881 | get_first_locp_gte_addr (CORE_ADDR address) | |
882 | { | |
883 | struct bp_location dummy_loc; | |
884 | struct bp_location *dummy_locp = &dummy_loc; | |
885 | struct bp_location **locp_found = NULL; | |
886 | ||
887 | /* Initialize the dummy location's address field. */ | |
888 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
889 | dummy_loc.address = address; | |
890 | ||
891 | /* Find a close match to the first location at ADDRESS. */ | |
892 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
893 | sizeof (struct bp_location **), | |
894 | bp_location_compare_addrs); | |
895 | ||
896 | /* Nothing was found, nothing left to do. */ | |
897 | if (locp_found == NULL) | |
898 | return NULL; | |
899 | ||
900 | /* We may have found a location that is at ADDRESS but is not the first in the | |
901 | location's list. Go backwards (if possible) and locate the first one. */ | |
902 | while ((locp_found - 1) >= bp_location | |
903 | && (*(locp_found - 1))->address == address) | |
904 | locp_found--; | |
905 | ||
906 | return locp_found; | |
907 | } | |
908 | ||
adc36818 PM |
909 | void |
910 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
911 | int from_tty) | |
912 | { | |
3a5c3e22 PA |
913 | xfree (b->cond_string); |
914 | b->cond_string = NULL; | |
adc36818 | 915 | |
3a5c3e22 | 916 | if (is_watchpoint (b)) |
adc36818 | 917 | { |
3a5c3e22 PA |
918 | struct watchpoint *w = (struct watchpoint *) b; |
919 | ||
920 | xfree (w->cond_exp); | |
921 | w->cond_exp = NULL; | |
922 | } | |
923 | else | |
924 | { | |
925 | struct bp_location *loc; | |
926 | ||
927 | for (loc = b->loc; loc; loc = loc->next) | |
928 | { | |
929 | xfree (loc->cond); | |
930 | loc->cond = NULL; | |
b775012e LM |
931 | |
932 | /* No need to free the condition agent expression | |
933 | bytecode (if we have one). We will handle this | |
934 | when we go through update_global_location_list. */ | |
3a5c3e22 | 935 | } |
adc36818 | 936 | } |
adc36818 PM |
937 | |
938 | if (*exp == 0) | |
939 | { | |
940 | if (from_tty) | |
941 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
942 | } | |
943 | else | |
944 | { | |
bbc13ae3 | 945 | const char *arg = exp; |
cc59ec59 | 946 | |
adc36818 PM |
947 | /* I don't know if it matters whether this is the string the user |
948 | typed in or the decompiled expression. */ | |
949 | b->cond_string = xstrdup (arg); | |
950 | b->condition_not_parsed = 0; | |
951 | ||
952 | if (is_watchpoint (b)) | |
953 | { | |
3a5c3e22 PA |
954 | struct watchpoint *w = (struct watchpoint *) b; |
955 | ||
adc36818 PM |
956 | innermost_block = NULL; |
957 | arg = exp; | |
1bb9788d | 958 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
959 | if (*arg) |
960 | error (_("Junk at end of expression")); | |
3a5c3e22 | 961 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
962 | } |
963 | else | |
964 | { | |
3a5c3e22 PA |
965 | struct bp_location *loc; |
966 | ||
adc36818 PM |
967 | for (loc = b->loc; loc; loc = loc->next) |
968 | { | |
969 | arg = exp; | |
970 | loc->cond = | |
1bb9788d TT |
971 | parse_exp_1 (&arg, loc->address, |
972 | block_for_pc (loc->address), 0); | |
adc36818 PM |
973 | if (*arg) |
974 | error (_("Junk at end of expression")); | |
975 | } | |
976 | } | |
977 | } | |
b775012e LM |
978 | mark_breakpoint_modified (b); |
979 | ||
8d3788bd | 980 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
981 | } |
982 | ||
d55637df TT |
983 | /* Completion for the "condition" command. */ |
984 | ||
985 | static VEC (char_ptr) * | |
6f937416 PA |
986 | condition_completer (struct cmd_list_element *cmd, |
987 | const char *text, const char *word) | |
d55637df | 988 | { |
6f937416 | 989 | const char *space; |
d55637df | 990 | |
6f937416 PA |
991 | text = skip_spaces_const (text); |
992 | space = skip_to_space_const (text); | |
d55637df TT |
993 | if (*space == '\0') |
994 | { | |
995 | int len; | |
996 | struct breakpoint *b; | |
997 | VEC (char_ptr) *result = NULL; | |
998 | ||
999 | if (text[0] == '$') | |
1000 | { | |
1001 | /* We don't support completion of history indices. */ | |
1002 | if (isdigit (text[1])) | |
1003 | return NULL; | |
1004 | return complete_internalvar (&text[1]); | |
1005 | } | |
1006 | ||
1007 | /* We're completing the breakpoint number. */ | |
1008 | len = strlen (text); | |
1009 | ||
1010 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1011 | { |
1012 | char number[50]; | |
1013 | ||
1014 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1015 | ||
1016 | if (strncmp (number, text, len) == 0) | |
1017 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1018 | } | |
d55637df TT |
1019 | |
1020 | return result; | |
1021 | } | |
1022 | ||
1023 | /* We're completing the expression part. */ | |
6f937416 | 1024 | text = skip_spaces_const (space); |
d55637df TT |
1025 | return expression_completer (cmd, text, word); |
1026 | } | |
1027 | ||
c906108c SS |
1028 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1029 | ||
1030 | static void | |
fba45db2 | 1031 | condition_command (char *arg, int from_tty) |
c906108c | 1032 | { |
52f0bd74 | 1033 | struct breakpoint *b; |
c906108c | 1034 | char *p; |
52f0bd74 | 1035 | int bnum; |
c906108c SS |
1036 | |
1037 | if (arg == 0) | |
e2e0b3e5 | 1038 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1039 | |
1040 | p = arg; | |
1041 | bnum = get_number (&p); | |
5c44784c | 1042 | if (bnum == 0) |
8a3fe4f8 | 1043 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1044 | |
1045 | ALL_BREAKPOINTS (b) | |
1046 | if (b->number == bnum) | |
2f069f6f | 1047 | { |
6dddc817 DE |
1048 | /* Check if this breakpoint has a "stop" method implemented in an |
1049 | extension language. This method and conditions entered into GDB | |
1050 | from the CLI are mutually exclusive. */ | |
1051 | const struct extension_language_defn *extlang | |
1052 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1053 | ||
1054 | if (extlang != NULL) | |
1055 | { | |
1056 | error (_("Only one stop condition allowed. There is currently" | |
1057 | " a %s stop condition defined for this breakpoint."), | |
1058 | ext_lang_capitalized_name (extlang)); | |
1059 | } | |
2566ad2d | 1060 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1061 | |
1062 | if (is_breakpoint (b)) | |
1063 | update_global_location_list (1); | |
1064 | ||
2f069f6f JB |
1065 | return; |
1066 | } | |
c906108c | 1067 | |
8a3fe4f8 | 1068 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1069 | } |
1070 | ||
a7bdde9e VP |
1071 | /* Check that COMMAND do not contain commands that are suitable |
1072 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1073 | Throw if any such commands is found. */ |
1074 | ||
a7bdde9e VP |
1075 | static void |
1076 | check_no_tracepoint_commands (struct command_line *commands) | |
1077 | { | |
1078 | struct command_line *c; | |
cc59ec59 | 1079 | |
a7bdde9e VP |
1080 | for (c = commands; c; c = c->next) |
1081 | { | |
1082 | int i; | |
1083 | ||
1084 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1085 | error (_("The 'while-stepping' command can " |
1086 | "only be used for tracepoints")); | |
a7bdde9e VP |
1087 | |
1088 | for (i = 0; i < c->body_count; ++i) | |
1089 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1090 | ||
1091 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1092 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1093 | command directly. */ |
1094 | if (strstr (c->line, "collect ") == c->line) | |
1095 | error (_("The 'collect' command can only be used for tracepoints")); | |
1096 | ||
51661e93 VP |
1097 | if (strstr (c->line, "teval ") == c->line) |
1098 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1099 | } |
1100 | } | |
1101 | ||
d77f58be SS |
1102 | /* Encapsulate tests for different types of tracepoints. */ |
1103 | ||
d9b3f62e PA |
1104 | static int |
1105 | is_tracepoint_type (enum bptype type) | |
1106 | { | |
1107 | return (type == bp_tracepoint | |
1108 | || type == bp_fast_tracepoint | |
1109 | || type == bp_static_tracepoint); | |
1110 | } | |
1111 | ||
a7bdde9e | 1112 | int |
d77f58be | 1113 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1114 | { |
d9b3f62e | 1115 | return is_tracepoint_type (b->type); |
a7bdde9e | 1116 | } |
d9b3f62e | 1117 | |
e5dd4106 | 1118 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1119 | breakpoint. This function will throw an exception if a problem is |
1120 | found. */ | |
48cb2d85 | 1121 | |
95a42b64 TT |
1122 | static void |
1123 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1124 | struct command_line *commands) | |
48cb2d85 | 1125 | { |
d77f58be | 1126 | if (is_tracepoint (b)) |
a7bdde9e | 1127 | { |
c9a6ce02 | 1128 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1129 | struct command_line *c; |
1130 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1131 | |
1132 | /* Reset the while-stepping step count. The previous commands | |
1133 | might have included a while-stepping action, while the new | |
1134 | ones might not. */ | |
1135 | t->step_count = 0; | |
1136 | ||
1137 | /* We need to verify that each top-level element of commands is | |
1138 | valid for tracepoints, that there's at most one | |
1139 | while-stepping element, and that the while-stepping's body | |
1140 | has valid tracing commands excluding nested while-stepping. | |
1141 | We also need to validate the tracepoint action line in the | |
1142 | context of the tracepoint --- validate_actionline actually | |
1143 | has side effects, like setting the tracepoint's | |
1144 | while-stepping STEP_COUNT, in addition to checking if the | |
1145 | collect/teval actions parse and make sense in the | |
1146 | tracepoint's context. */ | |
a7bdde9e VP |
1147 | for (c = commands; c; c = c->next) |
1148 | { | |
a7bdde9e VP |
1149 | if (c->control_type == while_stepping_control) |
1150 | { | |
1151 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1152 | error (_("The 'while-stepping' command " |
1153 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1154 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1155 | error (_("The 'while-stepping' command " |
1156 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1157 | |
1158 | if (while_stepping) | |
3e43a32a MS |
1159 | error (_("The 'while-stepping' command " |
1160 | "can be used only once")); | |
a7bdde9e VP |
1161 | else |
1162 | while_stepping = c; | |
1163 | } | |
c9a6ce02 PA |
1164 | |
1165 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1166 | } |
1167 | if (while_stepping) | |
1168 | { | |
1169 | struct command_line *c2; | |
1170 | ||
1171 | gdb_assert (while_stepping->body_count == 1); | |
1172 | c2 = while_stepping->body_list[0]; | |
1173 | for (; c2; c2 = c2->next) | |
1174 | { | |
a7bdde9e VP |
1175 | if (c2->control_type == while_stepping_control) |
1176 | error (_("The 'while-stepping' command cannot be nested")); | |
1177 | } | |
1178 | } | |
1179 | } | |
1180 | else | |
1181 | { | |
1182 | check_no_tracepoint_commands (commands); | |
1183 | } | |
95a42b64 TT |
1184 | } |
1185 | ||
0fb4aa4b PA |
1186 | /* Return a vector of all the static tracepoints set at ADDR. The |
1187 | caller is responsible for releasing the vector. */ | |
1188 | ||
1189 | VEC(breakpoint_p) * | |
1190 | static_tracepoints_here (CORE_ADDR addr) | |
1191 | { | |
1192 | struct breakpoint *b; | |
1193 | VEC(breakpoint_p) *found = 0; | |
1194 | struct bp_location *loc; | |
1195 | ||
1196 | ALL_BREAKPOINTS (b) | |
1197 | if (b->type == bp_static_tracepoint) | |
1198 | { | |
1199 | for (loc = b->loc; loc; loc = loc->next) | |
1200 | if (loc->address == addr) | |
1201 | VEC_safe_push(breakpoint_p, found, b); | |
1202 | } | |
1203 | ||
1204 | return found; | |
1205 | } | |
1206 | ||
95a42b64 | 1207 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1208 | validate that only allowed commands are included. */ |
95a42b64 TT |
1209 | |
1210 | void | |
4a64f543 MS |
1211 | breakpoint_set_commands (struct breakpoint *b, |
1212 | struct command_line *commands) | |
95a42b64 TT |
1213 | { |
1214 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1215 | |
9add0f1b TT |
1216 | decref_counted_command_line (&b->commands); |
1217 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1218 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1219 | } |
1220 | ||
45a43567 TT |
1221 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1222 | is not the same as the "silent" that may appear in the breakpoint's | |
1223 | commands. */ | |
1224 | ||
1225 | void | |
1226 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1227 | { | |
1228 | int old_silent = b->silent; | |
1229 | ||
1230 | b->silent = silent; | |
1231 | if (old_silent != silent) | |
8d3788bd | 1232 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1233 | } |
1234 | ||
1235 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1236 | breakpoint work for any thread. */ | |
1237 | ||
1238 | void | |
1239 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1240 | { | |
1241 | int old_thread = b->thread; | |
1242 | ||
1243 | b->thread = thread; | |
1244 | if (old_thread != thread) | |
8d3788bd | 1245 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1246 | } |
1247 | ||
1248 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1249 | breakpoint work for any task. */ | |
1250 | ||
1251 | void | |
1252 | breakpoint_set_task (struct breakpoint *b, int task) | |
1253 | { | |
1254 | int old_task = b->task; | |
1255 | ||
1256 | b->task = task; | |
1257 | if (old_task != task) | |
8d3788bd | 1258 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1259 | } |
1260 | ||
95a42b64 TT |
1261 | void |
1262 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1263 | { |
1264 | struct breakpoint *b = closure; | |
cc59ec59 | 1265 | |
6f937416 | 1266 | validate_actionline (line, b); |
a7bdde9e VP |
1267 | } |
1268 | ||
95a42b64 TT |
1269 | /* A structure used to pass information through |
1270 | map_breakpoint_numbers. */ | |
1271 | ||
1272 | struct commands_info | |
1273 | { | |
1274 | /* True if the command was typed at a tty. */ | |
1275 | int from_tty; | |
86b17b60 PA |
1276 | |
1277 | /* The breakpoint range spec. */ | |
1278 | char *arg; | |
1279 | ||
95a42b64 TT |
1280 | /* Non-NULL if the body of the commands are being read from this |
1281 | already-parsed command. */ | |
1282 | struct command_line *control; | |
86b17b60 | 1283 | |
95a42b64 TT |
1284 | /* The command lines read from the user, or NULL if they have not |
1285 | yet been read. */ | |
1286 | struct counted_command_line *cmd; | |
1287 | }; | |
1288 | ||
1289 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1290 | commands_command. */ | |
1291 | ||
c906108c | 1292 | static void |
95a42b64 | 1293 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1294 | { |
95a42b64 | 1295 | struct commands_info *info = data; |
c906108c | 1296 | |
95a42b64 TT |
1297 | if (info->cmd == NULL) |
1298 | { | |
1299 | struct command_line *l; | |
5c44784c | 1300 | |
95a42b64 TT |
1301 | if (info->control != NULL) |
1302 | l = copy_command_lines (info->control->body_list[0]); | |
1303 | else | |
86b17b60 PA |
1304 | { |
1305 | struct cleanup *old_chain; | |
1306 | char *str; | |
c5aa993b | 1307 | |
3e43a32a MS |
1308 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1309 | "%s, one per line."), | |
86b17b60 PA |
1310 | info->arg); |
1311 | ||
1312 | old_chain = make_cleanup (xfree, str); | |
1313 | ||
1314 | l = read_command_lines (str, | |
1315 | info->from_tty, 1, | |
d77f58be | 1316 | (is_tracepoint (b) |
86b17b60 PA |
1317 | ? check_tracepoint_command : 0), |
1318 | b); | |
1319 | ||
1320 | do_cleanups (old_chain); | |
1321 | } | |
a7bdde9e | 1322 | |
95a42b64 TT |
1323 | info->cmd = alloc_counted_command_line (l); |
1324 | } | |
1325 | ||
1326 | /* If a breakpoint was on the list more than once, we don't need to | |
1327 | do anything. */ | |
1328 | if (b->commands != info->cmd) | |
1329 | { | |
1330 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1331 | incref_counted_command_line (info->cmd); | |
1332 | decref_counted_command_line (&b->commands); | |
1333 | b->commands = info->cmd; | |
8d3788bd | 1334 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1335 | } |
95a42b64 TT |
1336 | } |
1337 | ||
1338 | static void | |
4a64f543 MS |
1339 | commands_command_1 (char *arg, int from_tty, |
1340 | struct command_line *control) | |
95a42b64 TT |
1341 | { |
1342 | struct cleanup *cleanups; | |
1343 | struct commands_info info; | |
1344 | ||
1345 | info.from_tty = from_tty; | |
1346 | info.control = control; | |
1347 | info.cmd = NULL; | |
1348 | /* If we read command lines from the user, then `info' will hold an | |
1349 | extra reference to the commands that we must clean up. */ | |
1350 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1351 | ||
1352 | if (arg == NULL || !*arg) | |
1353 | { | |
86b17b60 | 1354 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1355 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1356 | breakpoint_count); | |
95a42b64 TT |
1357 | else if (breakpoint_count > 0) |
1358 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1359 | else |
1360 | { | |
1361 | /* So that we don't try to free the incoming non-NULL | |
1362 | argument in the cleanup below. Mapping breakpoint | |
1363 | numbers will fail in this case. */ | |
1364 | arg = NULL; | |
1365 | } | |
95a42b64 | 1366 | } |
9766ced4 SS |
1367 | else |
1368 | /* The command loop has some static state, so we need to preserve | |
1369 | our argument. */ | |
1370 | arg = xstrdup (arg); | |
86b17b60 PA |
1371 | |
1372 | if (arg != NULL) | |
1373 | make_cleanup (xfree, arg); | |
1374 | ||
1375 | info.arg = arg; | |
95a42b64 TT |
1376 | |
1377 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1378 | ||
1379 | if (info.cmd == NULL) | |
1380 | error (_("No breakpoints specified.")); | |
1381 | ||
1382 | do_cleanups (cleanups); | |
1383 | } | |
1384 | ||
1385 | static void | |
1386 | commands_command (char *arg, int from_tty) | |
1387 | { | |
1388 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1389 | } |
40c03ae8 EZ |
1390 | |
1391 | /* Like commands_command, but instead of reading the commands from | |
1392 | input stream, takes them from an already parsed command structure. | |
1393 | ||
1394 | This is used by cli-script.c to DTRT with breakpoint commands | |
1395 | that are part of if and while bodies. */ | |
1396 | enum command_control_type | |
1397 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1398 | { | |
95a42b64 TT |
1399 | commands_command_1 (arg, 0, cmd); |
1400 | return simple_control; | |
40c03ae8 | 1401 | } |
876fa593 JK |
1402 | |
1403 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1404 | ||
1405 | static int | |
1406 | bp_location_has_shadow (struct bp_location *bl) | |
1407 | { | |
1408 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1409 | return 0; | |
1410 | if (!bl->inserted) | |
1411 | return 0; | |
1412 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1413 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1414 | return 0; |
1415 | return 1; | |
1416 | } | |
1417 | ||
9d497a19 PA |
1418 | /* Update BUF, which is LEN bytes read from the target address |
1419 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1420 | contents. | |
1421 | ||
1422 | If READBUF is not NULL, this buffer must not overlap with the of | |
1423 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1424 | failed assertion internal error will be raised. */ | |
1425 | ||
1426 | static void | |
1427 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1428 | const gdb_byte *writebuf_org, | |
1429 | ULONGEST memaddr, LONGEST len, | |
1430 | struct bp_target_info *target_info, | |
1431 | struct gdbarch *gdbarch) | |
1432 | { | |
1433 | /* Now do full processing of the found relevant range of elements. */ | |
1434 | CORE_ADDR bp_addr = 0; | |
1435 | int bp_size = 0; | |
1436 | int bptoffset = 0; | |
1437 | ||
1438 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1439 | current_program_space->aspace, 0)) | |
1440 | { | |
1441 | /* The breakpoint is inserted in a different address space. */ | |
1442 | return; | |
1443 | } | |
1444 | ||
1445 | /* Addresses and length of the part of the breakpoint that | |
1446 | we need to copy. */ | |
1447 | bp_addr = target_info->placed_address; | |
1448 | bp_size = target_info->shadow_len; | |
1449 | ||
1450 | if (bp_addr + bp_size <= memaddr) | |
1451 | { | |
1452 | /* The breakpoint is entirely before the chunk of memory we are | |
1453 | reading. */ | |
1454 | return; | |
1455 | } | |
1456 | ||
1457 | if (bp_addr >= memaddr + len) | |
1458 | { | |
1459 | /* The breakpoint is entirely after the chunk of memory we are | |
1460 | reading. */ | |
1461 | return; | |
1462 | } | |
1463 | ||
1464 | /* Offset within shadow_contents. */ | |
1465 | if (bp_addr < memaddr) | |
1466 | { | |
1467 | /* Only copy the second part of the breakpoint. */ | |
1468 | bp_size -= memaddr - bp_addr; | |
1469 | bptoffset = memaddr - bp_addr; | |
1470 | bp_addr = memaddr; | |
1471 | } | |
1472 | ||
1473 | if (bp_addr + bp_size > memaddr + len) | |
1474 | { | |
1475 | /* Only copy the first part of the breakpoint. */ | |
1476 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1477 | } | |
1478 | ||
1479 | if (readbuf != NULL) | |
1480 | { | |
1481 | /* Verify that the readbuf buffer does not overlap with the | |
1482 | shadow_contents buffer. */ | |
1483 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1484 | || readbuf >= (target_info->shadow_contents | |
1485 | + target_info->shadow_len)); | |
1486 | ||
1487 | /* Update the read buffer with this inserted breakpoint's | |
1488 | shadow. */ | |
1489 | memcpy (readbuf + bp_addr - memaddr, | |
1490 | target_info->shadow_contents + bptoffset, bp_size); | |
1491 | } | |
1492 | else | |
1493 | { | |
1494 | const unsigned char *bp; | |
1495 | CORE_ADDR placed_address = target_info->placed_address; | |
1496 | int placed_size = target_info->placed_size; | |
1497 | ||
1498 | /* Update the shadow with what we want to write to memory. */ | |
1499 | memcpy (target_info->shadow_contents + bptoffset, | |
1500 | writebuf_org + bp_addr - memaddr, bp_size); | |
1501 | ||
1502 | /* Determine appropriate breakpoint contents and size for this | |
1503 | address. */ | |
1504 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1505 | ||
1506 | /* Update the final write buffer with this inserted | |
1507 | breakpoint's INSN. */ | |
1508 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1509 | } | |
1510 | } | |
1511 | ||
8defab1a | 1512 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1513 | by replacing any memory breakpoints with their shadowed contents. |
1514 | ||
35c63cd8 JB |
1515 | If READBUF is not NULL, this buffer must not overlap with any of |
1516 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1517 | a failed assertion internal error will be raised. | |
1518 | ||
876fa593 | 1519 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1520 | bl->address - bp_location_placed_address_before_address_max |
1521 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1522 | The range we were requested to resolve shadows for is: |
1523 | memaddr ... memaddr + len | |
1524 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1525 | memaddr + len <= (bl->address |
1526 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1527 | and: |
35df4500 | 1528 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1529 | |
8defab1a | 1530 | void |
f0ba3972 PA |
1531 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1532 | const gdb_byte *writebuf_org, | |
1533 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1534 | { |
4a64f543 MS |
1535 | /* Left boundary, right boundary and median element of our binary |
1536 | search. */ | |
876fa593 | 1537 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1538 | size_t i; |
876fa593 | 1539 | |
4a64f543 MS |
1540 | /* Find BC_L which is a leftmost element which may affect BUF |
1541 | content. It is safe to report lower value but a failure to | |
1542 | report higher one. */ | |
876fa593 JK |
1543 | |
1544 | bc_l = 0; | |
1545 | bc_r = bp_location_count; | |
1546 | while (bc_l + 1 < bc_r) | |
1547 | { | |
35df4500 | 1548 | struct bp_location *bl; |
876fa593 JK |
1549 | |
1550 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1551 | bl = bp_location[bc]; |
876fa593 | 1552 | |
4a64f543 MS |
1553 | /* Check first BL->ADDRESS will not overflow due to the added |
1554 | constant. Then advance the left boundary only if we are sure | |
1555 | the BC element can in no way affect the BUF content (MEMADDR | |
1556 | to MEMADDR + LEN range). | |
876fa593 | 1557 | |
4a64f543 MS |
1558 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1559 | offset so that we cannot miss a breakpoint with its shadow | |
1560 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1561 | |
35df4500 TJB |
1562 | if ((bl->address + bp_location_shadow_len_after_address_max |
1563 | >= bl->address) | |
1564 | && (bl->address + bp_location_shadow_len_after_address_max | |
1565 | <= memaddr)) | |
876fa593 JK |
1566 | bc_l = bc; |
1567 | else | |
1568 | bc_r = bc; | |
1569 | } | |
1570 | ||
128070bb PA |
1571 | /* Due to the binary search above, we need to make sure we pick the |
1572 | first location that's at BC_L's address. E.g., if there are | |
1573 | multiple locations at the same address, BC_L may end up pointing | |
1574 | at a duplicate location, and miss the "master"/"inserted" | |
1575 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1576 | B: | |
1577 | ||
1578 | L1@A, L2@A, L3@B, ... | |
1579 | ||
1580 | BC_L could end up pointing at location L2, while the "master" | |
1581 | location could be L1. Since the `loc->inserted' flag is only set | |
1582 | on "master" locations, we'd forget to restore the shadow of L1 | |
1583 | and L2. */ | |
1584 | while (bc_l > 0 | |
1585 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1586 | bc_l--; | |
1587 | ||
876fa593 JK |
1588 | /* Now do full processing of the found relevant range of elements. */ |
1589 | ||
1590 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1591 | { |
35df4500 | 1592 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1593 | CORE_ADDR bp_addr = 0; |
1594 | int bp_size = 0; | |
1595 | int bptoffset = 0; | |
1596 | ||
35df4500 TJB |
1597 | /* bp_location array has BL->OWNER always non-NULL. */ |
1598 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1599 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1600 | bl->owner->number); |
ffce0d52 | 1601 | |
e5dd4106 | 1602 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1603 | content. */ |
1604 | ||
35df4500 TJB |
1605 | if (bl->address >= bp_location_placed_address_before_address_max |
1606 | && memaddr + len <= (bl->address | |
1607 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1608 | break; |
1609 | ||
35df4500 | 1610 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1611 | continue; |
6c95b8df | 1612 | |
9d497a19 PA |
1613 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1614 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1615 | } | |
c5aa993b | 1616 | |
9d497a19 PA |
1617 | /* Now process single-step breakpoints. These are not found in the |
1618 | bp_location array. */ | |
1619 | for (i = 0; i < 2; i++) | |
1620 | { | |
1621 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
c5aa993b | 1622 | |
9d497a19 PA |
1623 | if (bp_tgt != NULL) |
1624 | { | |
1625 | struct gdbarch *gdbarch = single_step_gdbarch[i]; | |
c5aa993b | 1626 | |
9d497a19 PA |
1627 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1628 | memaddr, len, bp_tgt, gdbarch); | |
1629 | } | |
1630 | } | |
c906108c | 1631 | } |
9d497a19 | 1632 | |
c906108c | 1633 | \f |
c5aa993b | 1634 | |
b775012e LM |
1635 | /* Return true if BPT is either a software breakpoint or a hardware |
1636 | breakpoint. */ | |
1637 | ||
1638 | int | |
1639 | is_breakpoint (const struct breakpoint *bpt) | |
1640 | { | |
1641 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1642 | || bpt->type == bp_hardware_breakpoint |
1643 | || bpt->type == bp_dprintf); | |
b775012e LM |
1644 | } |
1645 | ||
60e1c644 PA |
1646 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1647 | ||
a5606eee | 1648 | static int |
d77f58be | 1649 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1650 | { |
1651 | return (bpt->type == bp_hardware_watchpoint | |
1652 | || bpt->type == bp_read_watchpoint | |
1653 | || bpt->type == bp_access_watchpoint); | |
1654 | } | |
7270d8f2 | 1655 | |
60e1c644 PA |
1656 | /* Return true if BPT is of any watchpoint kind, hardware or |
1657 | software. */ | |
1658 | ||
3a5c3e22 | 1659 | int |
d77f58be | 1660 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1661 | { |
1662 | return (is_hardware_watchpoint (bpt) | |
1663 | || bpt->type == bp_watchpoint); | |
1664 | } | |
1665 | ||
3a5c3e22 PA |
1666 | /* Returns true if the current thread and its running state are safe |
1667 | to evaluate or update watchpoint B. Watchpoints on local | |
1668 | expressions need to be evaluated in the context of the thread that | |
1669 | was current when the watchpoint was created, and, that thread needs | |
1670 | to be stopped to be able to select the correct frame context. | |
1671 | Watchpoints on global expressions can be evaluated on any thread, | |
1672 | and in any state. It is presently left to the target allowing | |
1673 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1674 | |
1675 | static int | |
3a5c3e22 | 1676 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1677 | { |
d0d8b0c6 JK |
1678 | return (b->base.pspace == current_program_space |
1679 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1680 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1681 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1682 | } |
1683 | ||
d0fb5eae JK |
1684 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1685 | associated bp_watchpoint_scope breakpoint. */ | |
1686 | ||
1687 | static void | |
3a5c3e22 | 1688 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1689 | { |
3a5c3e22 | 1690 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1691 | |
1692 | if (b->related_breakpoint != b) | |
1693 | { | |
1694 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1695 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1696 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1697 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1698 | b->related_breakpoint = b; | |
1699 | } | |
1700 | b->disposition = disp_del_at_next_stop; | |
1701 | } | |
1702 | ||
567e1b4e JB |
1703 | /* Assuming that B is a watchpoint: |
1704 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1705 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1706 | - Evaluate the condition if there is one, and store the result |
1707 | in b->loc->cond. | |
a5606eee VP |
1708 | - Update the list of values that must be watched in B->loc. |
1709 | ||
4a64f543 MS |
1710 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1711 | nothing. If this is local watchpoint that is out of scope, delete | |
1712 | it. | |
1713 | ||
1714 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1715 | removed + inserted on each stop here. Normal breakpoints must | |
1716 | never be removed because they might be missed by a running thread | |
1717 | when debugging in non-stop mode. On the other hand, hardware | |
1718 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1719 | to each LWP since they are stored in each LWP's hardware debug | |
1720 | registers. Therefore, such LWP must be stopped first in order to | |
1721 | be able to modify its hardware watchpoints. | |
1722 | ||
1723 | Hardware watchpoints must be reset exactly once after being | |
1724 | presented to the user. It cannot be done sooner, because it would | |
1725 | reset the data used to present the watchpoint hit to the user. And | |
1726 | it must not be done later because it could display the same single | |
1727 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1728 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1729 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1730 | not user-visible - its hit is suppressed if the memory content has | |
1731 | not changed. | |
1732 | ||
1733 | The following constraints influence the location where we can reset | |
1734 | hardware watchpoints: | |
1735 | ||
1736 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1737 | called several times when GDB stops. | |
1738 | ||
1739 | [linux] | |
1740 | * Multiple hardware watchpoints can be hit at the same time, | |
1741 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1742 | hit at a time as the reason for stopping, and all the other hits | |
1743 | are presented later, one after the other, each time the user | |
1744 | requests the execution to be resumed. Execution is not resumed | |
1745 | for the threads still having pending hit event stored in | |
1746 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1747 | the inferior on the first stop the thread hit event is kept being | |
1748 | reported from its cached value by linux_nat_stopped_data_address | |
1749 | until the real thread resume happens after the watchpoint gets | |
1750 | presented and thus its LWP_INFO->STATUS gets reset. | |
1751 | ||
1752 | Therefore the hardware watchpoint hit can get safely reset on the | |
1753 | watchpoint removal from inferior. */ | |
a79d3c27 | 1754 | |
b40ce68a | 1755 | static void |
3a5c3e22 | 1756 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1757 | { |
a5606eee | 1758 | int within_current_scope; |
a5606eee | 1759 | struct frame_id saved_frame_id; |
66076460 | 1760 | int frame_saved; |
a5606eee | 1761 | |
f6bc2008 PA |
1762 | /* If this is a local watchpoint, we only want to check if the |
1763 | watchpoint frame is in scope if the current thread is the thread | |
1764 | that was used to create the watchpoint. */ | |
1765 | if (!watchpoint_in_thread_scope (b)) | |
1766 | return; | |
1767 | ||
3a5c3e22 | 1768 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1769 | return; |
1770 | ||
66076460 | 1771 | frame_saved = 0; |
a5606eee VP |
1772 | |
1773 | /* Determine if the watchpoint is within scope. */ | |
1774 | if (b->exp_valid_block == NULL) | |
1775 | within_current_scope = 1; | |
1776 | else | |
1777 | { | |
b5db5dfc UW |
1778 | struct frame_info *fi = get_current_frame (); |
1779 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1780 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1781 | ||
1782 | /* If we're in a function epilogue, unwinding may not work | |
1783 | properly, so do not attempt to recreate locations at this | |
1784 | point. See similar comments in watchpoint_check. */ | |
1785 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1786 | return; | |
66076460 DJ |
1787 | |
1788 | /* Save the current frame's ID so we can restore it after | |
1789 | evaluating the watchpoint expression on its own frame. */ | |
1790 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1791 | took a frame parameter, so that we didn't have to change the | |
1792 | selected frame. */ | |
1793 | frame_saved = 1; | |
1794 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1795 | ||
a5606eee VP |
1796 | fi = frame_find_by_id (b->watchpoint_frame); |
1797 | within_current_scope = (fi != NULL); | |
1798 | if (within_current_scope) | |
1799 | select_frame (fi); | |
1800 | } | |
1801 | ||
b5db5dfc UW |
1802 | /* We don't free locations. They are stored in the bp_location array |
1803 | and update_global_location_list will eventually delete them and | |
1804 | remove breakpoints if needed. */ | |
3a5c3e22 | 1805 | b->base.loc = NULL; |
b5db5dfc | 1806 | |
a5606eee VP |
1807 | if (within_current_scope && reparse) |
1808 | { | |
bbc13ae3 | 1809 | const char *s; |
d63d0675 | 1810 | |
a5606eee VP |
1811 | if (b->exp) |
1812 | { | |
1813 | xfree (b->exp); | |
1814 | b->exp = NULL; | |
1815 | } | |
d63d0675 | 1816 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1817 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1818 | /* If the meaning of expression itself changed, the old value is |
1819 | no longer relevant. We don't want to report a watchpoint hit | |
1820 | to the user when the old value and the new value may actually | |
1821 | be completely different objects. */ | |
1822 | value_free (b->val); | |
fa4727a6 DJ |
1823 | b->val = NULL; |
1824 | b->val_valid = 0; | |
60e1c644 PA |
1825 | |
1826 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1827 | expression is stored in the breakpoint object, not in the | |
1828 | locations (re)created below. */ | |
3a5c3e22 | 1829 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1830 | { |
1831 | if (b->cond_exp != NULL) | |
1832 | { | |
1833 | xfree (b->cond_exp); | |
1834 | b->cond_exp = NULL; | |
1835 | } | |
1836 | ||
3a5c3e22 | 1837 | s = b->base.cond_string; |
1bb9788d | 1838 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1839 | } |
a5606eee | 1840 | } |
a5606eee VP |
1841 | |
1842 | /* If we failed to parse the expression, for example because | |
1843 | it refers to a global variable in a not-yet-loaded shared library, | |
1844 | don't try to insert watchpoint. We don't automatically delete | |
1845 | such watchpoint, though, since failure to parse expression | |
1846 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1847 | if (!target_has_execution) |
2d134ed3 PA |
1848 | { |
1849 | /* Without execution, memory can't change. No use to try and | |
1850 | set watchpoint locations. The watchpoint will be reset when | |
1851 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1852 | if (!can_use_hw_watchpoints) |
1853 | { | |
1854 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1855 | b->base.type = bp_watchpoint; | |
1856 | else | |
638aa5a1 AB |
1857 | error (_("Can't set read/access watchpoint when " |
1858 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1859 | } |
2d134ed3 PA |
1860 | } |
1861 | else if (within_current_scope && b->exp) | |
a5606eee | 1862 | { |
0cf6dd15 | 1863 | int pc = 0; |
fa4727a6 | 1864 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1865 | struct program_space *frame_pspace; |
a5606eee | 1866 | |
3a1115a0 | 1867 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1868 | |
a5606eee VP |
1869 | /* Avoid setting b->val if it's already set. The meaning of |
1870 | b->val is 'the last value' user saw, and we should update | |
1871 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1872 | happens, the code that reports it updates b->val directly. |
1873 | We don't keep track of the memory value for masked | |
1874 | watchpoints. */ | |
3a5c3e22 | 1875 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1876 | { |
1877 | b->val = v; | |
1878 | b->val_valid = 1; | |
1879 | } | |
a5606eee | 1880 | |
2d134ed3 PA |
1881 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1882 | ||
a5606eee | 1883 | /* Look at each value on the value chain. */ |
9fa40276 | 1884 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1885 | { |
1886 | /* If it's a memory location, and GDB actually needed | |
1887 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1888 | must watch it. If the first value returned is |
1889 | still lazy, that means an error occurred reading it; | |
1890 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1891 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1892 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1893 | { |
1894 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1895 | |
a5606eee VP |
1896 | /* We only watch structs and arrays if user asked |
1897 | for it explicitly, never if they just happen to | |
1898 | appear in the middle of some value chain. */ | |
fa4727a6 | 1899 | if (v == result |
a5606eee VP |
1900 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1901 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1902 | { | |
1903 | CORE_ADDR addr; | |
744a8059 | 1904 | int type; |
a5606eee VP |
1905 | struct bp_location *loc, **tmp; |
1906 | ||
42ae5230 | 1907 | addr = value_address (v); |
a5606eee | 1908 | type = hw_write; |
3a5c3e22 | 1909 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1910 | type = hw_read; |
3a5c3e22 | 1911 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1912 | type = hw_access; |
3a5c3e22 PA |
1913 | |
1914 | loc = allocate_bp_location (&b->base); | |
1915 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1916 | ; |
1917 | *tmp = loc; | |
a6d9a66e | 1918 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1919 | |
1920 | loc->pspace = frame_pspace; | |
a5606eee | 1921 | loc->address = addr; |
744a8059 | 1922 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1923 | loc->watchpoint_type = type; |
1924 | } | |
1925 | } | |
9fa40276 TJB |
1926 | } |
1927 | ||
1928 | /* Change the type of breakpoint between hardware assisted or | |
1929 | an ordinary watchpoint depending on the hardware support | |
1930 | and free hardware slots. REPARSE is set when the inferior | |
1931 | is started. */ | |
a9634178 | 1932 | if (reparse) |
9fa40276 | 1933 | { |
e09342b5 | 1934 | int reg_cnt; |
9fa40276 TJB |
1935 | enum bp_loc_type loc_type; |
1936 | struct bp_location *bl; | |
a5606eee | 1937 | |
a9634178 | 1938 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1939 | |
1940 | if (reg_cnt) | |
9fa40276 TJB |
1941 | { |
1942 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1943 | enum bptype type; |
9fa40276 | 1944 | |
a9634178 TJB |
1945 | /* Use an exact watchpoint when there's only one memory region to be |
1946 | watched, and only one debug register is needed to watch it. */ | |
1947 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1948 | ||
9fa40276 | 1949 | /* We need to determine how many resources are already |
e09342b5 TJB |
1950 | used for all other hardware watchpoints plus this one |
1951 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1952 | this watchpoint in as well. */ |
1953 | ||
1954 | /* If this is a software watchpoint, we try to turn it | |
1955 | to a hardware one -- count resources as if B was of | |
1956 | hardware watchpoint type. */ | |
1957 | type = b->base.type; | |
1958 | if (type == bp_watchpoint) | |
1959 | type = bp_hardware_watchpoint; | |
1960 | ||
1961 | /* This watchpoint may or may not have been placed on | |
1962 | the list yet at this point (it won't be in the list | |
1963 | if we're trying to create it for the first time, | |
1964 | through watch_command), so always account for it | |
1965 | manually. */ | |
1966 | ||
1967 | /* Count resources used by all watchpoints except B. */ | |
1968 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1969 | ||
1970 | /* Add in the resources needed for B. */ | |
1971 | i += hw_watchpoint_use_count (&b->base); | |
1972 | ||
1973 | target_resources_ok | |
1974 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1975 | if (target_resources_ok <= 0) |
a9634178 | 1976 | { |
3a5c3e22 | 1977 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1978 | |
1979 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1980 | error (_("Target does not support this type of " |
1981 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1982 | else if (target_resources_ok < 0 && !sw_mode) |
1983 | error (_("There are not enough available hardware " | |
1984 | "resources for this watchpoint.")); | |
a1398e0c PA |
1985 | |
1986 | /* Downgrade to software watchpoint. */ | |
1987 | b->base.type = bp_watchpoint; | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | /* If this was a software watchpoint, we've just | |
1992 | found we have enough resources to turn it to a | |
1993 | hardware watchpoint. Otherwise, this is a | |
1994 | nop. */ | |
1995 | b->base.type = type; | |
a9634178 | 1996 | } |
9fa40276 | 1997 | } |
3a5c3e22 | 1998 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
1999 | { |
2000 | if (!can_use_hw_watchpoints) | |
2001 | error (_("Can't set read/access watchpoint when " | |
2002 | "hardware watchpoints are disabled.")); | |
2003 | else | |
2004 | error (_("Expression cannot be implemented with " | |
2005 | "read/access watchpoint.")); | |
2006 | } | |
9fa40276 | 2007 | else |
3a5c3e22 | 2008 | b->base.type = bp_watchpoint; |
9fa40276 | 2009 | |
3a5c3e22 | 2010 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2011 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2012 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2013 | bl->loc_type = loc_type; |
2014 | } | |
2015 | ||
2016 | for (v = val_chain; v; v = next) | |
2017 | { | |
a5606eee VP |
2018 | next = value_next (v); |
2019 | if (v != b->val) | |
2020 | value_free (v); | |
2021 | } | |
2022 | ||
c7437ca6 PA |
2023 | /* If a software watchpoint is not watching any memory, then the |
2024 | above left it without any location set up. But, | |
2025 | bpstat_stop_status requires a location to be able to report | |
2026 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2027 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2028 | { |
3a5c3e22 PA |
2029 | struct breakpoint *base = &b->base; |
2030 | base->loc = allocate_bp_location (base); | |
2031 | base->loc->pspace = frame_pspace; | |
2032 | base->loc->address = -1; | |
2033 | base->loc->length = -1; | |
2034 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2035 | } |
a5606eee VP |
2036 | } |
2037 | else if (!within_current_scope) | |
7270d8f2 | 2038 | { |
ac74f770 MS |
2039 | printf_filtered (_("\ |
2040 | Watchpoint %d deleted because the program has left the block\n\ | |
2041 | in which its expression is valid.\n"), | |
3a5c3e22 | 2042 | b->base.number); |
d0fb5eae | 2043 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2044 | } |
a5606eee VP |
2045 | |
2046 | /* Restore the selected frame. */ | |
66076460 DJ |
2047 | if (frame_saved) |
2048 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2049 | } |
2050 | ||
a5606eee | 2051 | |
74960c60 | 2052 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2053 | inserted in the inferior. We don't differentiate the type of BL's owner |
2054 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2055 | breakpoint_ops is not defined, because in insert_bp_location, | |
2056 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2057 | static int |
35df4500 | 2058 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2059 | { |
35df4500 | 2060 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2061 | return 0; |
2062 | ||
35df4500 | 2063 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2064 | return 0; |
2065 | ||
35df4500 | 2066 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2067 | return 0; |
2068 | ||
f8eba3c6 TT |
2069 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2070 | return 0; | |
2071 | ||
56710373 PA |
2072 | /* This is set for example, when we're attached to the parent of a |
2073 | vfork, and have detached from the child. The child is running | |
2074 | free, and we expect it to do an exec or exit, at which point the | |
2075 | OS makes the parent schedulable again (and the target reports | |
2076 | that the vfork is done). Until the child is done with the shared | |
2077 | memory region, do not insert breakpoints in the parent, otherwise | |
2078 | the child could still trip on the parent's breakpoints. Since | |
2079 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2080 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2081 | return 0; |
2082 | ||
31e77af2 PA |
2083 | /* Don't insert a breakpoint if we're trying to step past its |
2084 | location. */ | |
2085 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2086 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2087 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2088 | bl->address)) | |
2089 | return 0; | |
2090 | ||
74960c60 VP |
2091 | return 1; |
2092 | } | |
2093 | ||
934709f0 PW |
2094 | /* Same as should_be_inserted but does the check assuming |
2095 | that the location is not duplicated. */ | |
2096 | ||
2097 | static int | |
2098 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2099 | { | |
2100 | int result; | |
2101 | const int save_duplicate = bl->duplicate; | |
2102 | ||
2103 | bl->duplicate = 0; | |
2104 | result = should_be_inserted (bl); | |
2105 | bl->duplicate = save_duplicate; | |
2106 | return result; | |
2107 | } | |
2108 | ||
b775012e LM |
2109 | /* Parses a conditional described by an expression COND into an |
2110 | agent expression bytecode suitable for evaluation | |
2111 | by the bytecode interpreter. Return NULL if there was | |
2112 | any error during parsing. */ | |
2113 | ||
2114 | static struct agent_expr * | |
2115 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2116 | { | |
2117 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2118 | volatile struct gdb_exception ex; |
2119 | ||
2120 | if (!cond) | |
2121 | return NULL; | |
2122 | ||
2123 | /* We don't want to stop processing, so catch any errors | |
2124 | that may show up. */ | |
2125 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2126 | { | |
2127 | aexpr = gen_eval_for_expr (scope, cond); | |
2128 | } | |
2129 | ||
2130 | if (ex.reason < 0) | |
2131 | { | |
2132 | /* If we got here, it means the condition could not be parsed to a valid | |
2133 | bytecode expression and thus can't be evaluated on the target's side. | |
2134 | It's no use iterating through the conditions. */ | |
2135 | return NULL; | |
2136 | } | |
2137 | ||
2138 | /* We have a valid agent expression. */ | |
2139 | return aexpr; | |
2140 | } | |
2141 | ||
2142 | /* Based on location BL, create a list of breakpoint conditions to be | |
2143 | passed on to the target. If we have duplicated locations with different | |
2144 | conditions, we will add such conditions to the list. The idea is that the | |
2145 | target will evaluate the list of conditions and will only notify GDB when | |
2146 | one of them is true. */ | |
2147 | ||
2148 | static void | |
2149 | build_target_condition_list (struct bp_location *bl) | |
2150 | { | |
2151 | struct bp_location **locp = NULL, **loc2p; | |
2152 | int null_condition_or_parse_error = 0; | |
2153 | int modified = bl->needs_update; | |
2154 | struct bp_location *loc; | |
2155 | ||
8b4f3082 PA |
2156 | /* Release conditions left over from a previous insert. */ |
2157 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2158 | ||
b775012e LM |
2159 | /* This is only meaningful if the target is |
2160 | evaluating conditions and if the user has | |
2161 | opted for condition evaluation on the target's | |
2162 | side. */ | |
2163 | if (gdb_evaluates_breakpoint_condition_p () | |
2164 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2165 | return; | |
2166 | ||
2167 | /* Do a first pass to check for locations with no assigned | |
2168 | conditions or conditions that fail to parse to a valid agent expression | |
2169 | bytecode. If any of these happen, then it's no use to send conditions | |
2170 | to the target since this location will always trigger and generate a | |
2171 | response back to GDB. */ | |
2172 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2173 | { | |
2174 | loc = (*loc2p); | |
2175 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2176 | { | |
2177 | if (modified) | |
2178 | { | |
2179 | struct agent_expr *aexpr; | |
2180 | ||
2181 | /* Re-parse the conditions since something changed. In that | |
2182 | case we already freed the condition bytecodes (see | |
2183 | force_breakpoint_reinsertion). We just | |
2184 | need to parse the condition to bytecodes again. */ | |
2185 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2186 | loc->cond_bytecode = aexpr; | |
2187 | ||
2188 | /* Check if we managed to parse the conditional expression | |
2189 | correctly. If not, we will not send this condition | |
2190 | to the target. */ | |
2191 | if (aexpr) | |
2192 | continue; | |
2193 | } | |
2194 | ||
2195 | /* If we have a NULL bytecode expression, it means something | |
2196 | went wrong or we have a null condition expression. */ | |
2197 | if (!loc->cond_bytecode) | |
2198 | { | |
2199 | null_condition_or_parse_error = 1; | |
2200 | break; | |
2201 | } | |
2202 | } | |
2203 | } | |
2204 | ||
2205 | /* If any of these happened, it means we will have to evaluate the conditions | |
2206 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2207 | for all the other duplicate locations, thus we free all of them here. | |
2208 | ||
2209 | This is so we have a finer control over which locations' conditions are | |
2210 | being evaluated by GDB or the remote stub. */ | |
2211 | if (null_condition_or_parse_error) | |
2212 | { | |
2213 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2214 | { | |
2215 | loc = (*loc2p); | |
2216 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2217 | { | |
2218 | /* Only go as far as the first NULL bytecode is | |
2219 | located. */ | |
2220 | if (!loc->cond_bytecode) | |
2221 | return; | |
2222 | ||
2223 | free_agent_expr (loc->cond_bytecode); | |
2224 | loc->cond_bytecode = NULL; | |
2225 | } | |
2226 | } | |
2227 | } | |
2228 | ||
2229 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2230 | for this location's address. */ | |
2231 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2232 | { | |
2233 | loc = (*loc2p); | |
2234 | if (loc->cond | |
2235 | && is_breakpoint (loc->owner) | |
2236 | && loc->pspace->num == bl->pspace->num | |
2237 | && loc->owner->enable_state == bp_enabled | |
2238 | && loc->enabled) | |
2239 | /* Add the condition to the vector. This will be used later to send the | |
2240 | conditions to the target. */ | |
2241 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2242 | loc->cond_bytecode); | |
2243 | } | |
2244 | ||
2245 | return; | |
2246 | } | |
2247 | ||
d3ce09f5 SS |
2248 | /* Parses a command described by string CMD into an agent expression |
2249 | bytecode suitable for evaluation by the bytecode interpreter. | |
2250 | Return NULL if there was any error during parsing. */ | |
2251 | ||
2252 | static struct agent_expr * | |
2253 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2254 | { | |
2255 | struct cleanup *old_cleanups = 0; | |
2256 | struct expression *expr, **argvec; | |
2257 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2258 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2259 | const char *cmdrest; |
2260 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2261 | struct format_piece *fpieces; |
2262 | int nargs; | |
2263 | struct gdbarch *gdbarch = get_current_arch (); | |
2264 | ||
2265 | if (!cmd) | |
2266 | return NULL; | |
2267 | ||
2268 | cmdrest = cmd; | |
2269 | ||
2270 | if (*cmdrest == ',') | |
2271 | ++cmdrest; | |
bbc13ae3 | 2272 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2273 | |
2274 | if (*cmdrest++ != '"') | |
2275 | error (_("No format string following the location")); | |
2276 | ||
2277 | format_start = cmdrest; | |
2278 | ||
2279 | fpieces = parse_format_string (&cmdrest); | |
2280 | ||
2281 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2282 | ||
2283 | format_end = cmdrest; | |
2284 | ||
2285 | if (*cmdrest++ != '"') | |
2286 | error (_("Bad format string, non-terminated '\"'.")); | |
2287 | ||
bbc13ae3 | 2288 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2289 | |
2290 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2291 | error (_("Invalid argument syntax")); | |
2292 | ||
2293 | if (*cmdrest == ',') | |
2294 | cmdrest++; | |
bbc13ae3 | 2295 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2296 | |
2297 | /* For each argument, make an expression. */ | |
2298 | ||
2299 | argvec = (struct expression **) alloca (strlen (cmd) | |
2300 | * sizeof (struct expression *)); | |
2301 | ||
2302 | nargs = 0; | |
2303 | while (*cmdrest != '\0') | |
2304 | { | |
bbc13ae3 | 2305 | const char *cmd1; |
d3ce09f5 SS |
2306 | |
2307 | cmd1 = cmdrest; | |
2308 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2309 | argvec[nargs++] = expr; | |
2310 | cmdrest = cmd1; | |
2311 | if (*cmdrest == ',') | |
2312 | ++cmdrest; | |
2313 | } | |
2314 | ||
2315 | /* We don't want to stop processing, so catch any errors | |
2316 | that may show up. */ | |
2317 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2318 | { | |
2319 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2320 | format_start, format_end - format_start, | |
2321 | fpieces, nargs, argvec); | |
2322 | } | |
2323 | ||
752eb8b4 TT |
2324 | do_cleanups (old_cleanups); |
2325 | ||
d3ce09f5 SS |
2326 | if (ex.reason < 0) |
2327 | { | |
2328 | /* If we got here, it means the command could not be parsed to a valid | |
2329 | bytecode expression and thus can't be evaluated on the target's side. | |
2330 | It's no use iterating through the other commands. */ | |
2331 | return NULL; | |
2332 | } | |
2333 | ||
d3ce09f5 SS |
2334 | /* We have a valid agent expression, return it. */ |
2335 | return aexpr; | |
2336 | } | |
2337 | ||
2338 | /* Based on location BL, create a list of breakpoint commands to be | |
2339 | passed on to the target. If we have duplicated locations with | |
2340 | different commands, we will add any such to the list. */ | |
2341 | ||
2342 | static void | |
2343 | build_target_command_list (struct bp_location *bl) | |
2344 | { | |
2345 | struct bp_location **locp = NULL, **loc2p; | |
2346 | int null_command_or_parse_error = 0; | |
2347 | int modified = bl->needs_update; | |
2348 | struct bp_location *loc; | |
2349 | ||
8b4f3082 PA |
2350 | /* Release commands left over from a previous insert. */ |
2351 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2352 | ||
d3ce09f5 SS |
2353 | /* For now, limit to agent-style dprintf breakpoints. */ |
2354 | if (bl->owner->type != bp_dprintf | |
2355 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2356 | return; | |
2357 | ||
2358 | if (!target_can_run_breakpoint_commands ()) | |
2359 | return; | |
2360 | ||
2361 | /* Do a first pass to check for locations with no assigned | |
2362 | conditions or conditions that fail to parse to a valid agent expression | |
2363 | bytecode. If any of these happen, then it's no use to send conditions | |
2364 | to the target since this location will always trigger and generate a | |
2365 | response back to GDB. */ | |
2366 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2367 | { | |
2368 | loc = (*loc2p); | |
2369 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2370 | { | |
2371 | if (modified) | |
2372 | { | |
2373 | struct agent_expr *aexpr; | |
2374 | ||
2375 | /* Re-parse the commands since something changed. In that | |
2376 | case we already freed the command bytecodes (see | |
2377 | force_breakpoint_reinsertion). We just | |
2378 | need to parse the command to bytecodes again. */ | |
2379 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2380 | loc->owner->extra_string); | |
2381 | loc->cmd_bytecode = aexpr; | |
2382 | ||
2383 | if (!aexpr) | |
2384 | continue; | |
2385 | } | |
2386 | ||
2387 | /* If we have a NULL bytecode expression, it means something | |
2388 | went wrong or we have a null command expression. */ | |
2389 | if (!loc->cmd_bytecode) | |
2390 | { | |
2391 | null_command_or_parse_error = 1; | |
2392 | break; | |
2393 | } | |
2394 | } | |
2395 | } | |
2396 | ||
2397 | /* If anything failed, then we're not doing target-side commands, | |
2398 | and so clean up. */ | |
2399 | if (null_command_or_parse_error) | |
2400 | { | |
2401 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2402 | { | |
2403 | loc = (*loc2p); | |
2404 | if (is_breakpoint (loc->owner) | |
2405 | && loc->pspace->num == bl->pspace->num) | |
2406 | { | |
2407 | /* Only go as far as the first NULL bytecode is | |
2408 | located. */ | |
40fb6c5e | 2409 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2410 | return; |
2411 | ||
40fb6c5e HZ |
2412 | free_agent_expr (loc->cmd_bytecode); |
2413 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2414 | } |
2415 | } | |
2416 | } | |
2417 | ||
2418 | /* No NULL commands or failed bytecode generation. Build a command list | |
2419 | for this location's address. */ | |
2420 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2421 | { | |
2422 | loc = (*loc2p); | |
2423 | if (loc->owner->extra_string | |
2424 | && is_breakpoint (loc->owner) | |
2425 | && loc->pspace->num == bl->pspace->num | |
2426 | && loc->owner->enable_state == bp_enabled | |
2427 | && loc->enabled) | |
2428 | /* Add the command to the vector. This will be used later | |
2429 | to send the commands to the target. */ | |
2430 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2431 | loc->cmd_bytecode); | |
2432 | } | |
2433 | ||
2434 | bl->target_info.persist = 0; | |
2435 | /* Maybe flag this location as persistent. */ | |
2436 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2437 | bl->target_info.persist = 1; | |
2438 | } | |
2439 | ||
35df4500 TJB |
2440 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2441 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2442 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2443 | Returns 0 for success, 1 if the bp_location type is not supported or |
2444 | -1 for failure. | |
879bfdc2 | 2445 | |
4a64f543 MS |
2446 | NOTE drow/2003-09-09: This routine could be broken down to an |
2447 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2448 | static int |
35df4500 | 2449 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2450 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2451 | int *disabled_breaks, |
dd61ec5c MW |
2452 | int *hw_breakpoint_error, |
2453 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2454 | { |
0000e5cc PA |
2455 | enum errors bp_err = GDB_NO_ERROR; |
2456 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2457 | volatile struct gdb_exception e; |
879bfdc2 | 2458 | |
b775012e | 2459 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2460 | return 0; |
2461 | ||
35c63cd8 JB |
2462 | /* Note we don't initialize bl->target_info, as that wipes out |
2463 | the breakpoint location's shadow_contents if the breakpoint | |
2464 | is still inserted at that location. This in turn breaks | |
2465 | target_read_memory which depends on these buffers when | |
2466 | a memory read is requested at the breakpoint location: | |
2467 | Once the target_info has been wiped, we fail to see that | |
2468 | we have a breakpoint inserted at that address and thus | |
2469 | read the breakpoint instead of returning the data saved in | |
2470 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2471 | bl->target_info.placed_address = bl->address; |
2472 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2473 | bl->target_info.length = bl->length; |
8181d85f | 2474 | |
b775012e LM |
2475 | /* When working with target-side conditions, we must pass all the conditions |
2476 | for the same breakpoint address down to the target since GDB will not | |
2477 | insert those locations. With a list of breakpoint conditions, the target | |
2478 | can decide when to stop and notify GDB. */ | |
2479 | ||
2480 | if (is_breakpoint (bl->owner)) | |
2481 | { | |
2482 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2483 | build_target_command_list (bl); |
2484 | /* Reset the modification marker. */ | |
b775012e LM |
2485 | bl->needs_update = 0; |
2486 | } | |
2487 | ||
35df4500 TJB |
2488 | if (bl->loc_type == bp_loc_software_breakpoint |
2489 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2490 | { |
35df4500 | 2491 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2492 | { |
2493 | /* If the explicitly specified breakpoint type | |
2494 | is not hardware breakpoint, check the memory map to see | |
2495 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2496 | |
765dc015 VP |
2497 | Two important cases are: |
2498 | - location type is not hardware breakpoint, memory | |
2499 | is readonly. We change the type of the location to | |
2500 | hardware breakpoint. | |
4a64f543 MS |
2501 | - location type is hardware breakpoint, memory is |
2502 | read-write. This means we've previously made the | |
2503 | location hardware one, but then the memory map changed, | |
2504 | so we undo. | |
765dc015 | 2505 | |
4a64f543 MS |
2506 | When breakpoints are removed, remove_breakpoints will use |
2507 | location types we've just set here, the only possible | |
2508 | problem is that memory map has changed during running | |
2509 | program, but it's not going to work anyway with current | |
2510 | gdb. */ | |
765dc015 | 2511 | struct mem_region *mr |
35df4500 | 2512 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2513 | |
2514 | if (mr) | |
2515 | { | |
2516 | if (automatic_hardware_breakpoints) | |
2517 | { | |
765dc015 VP |
2518 | enum bp_loc_type new_type; |
2519 | ||
2520 | if (mr->attrib.mode != MEM_RW) | |
2521 | new_type = bp_loc_hardware_breakpoint; | |
2522 | else | |
2523 | new_type = bp_loc_software_breakpoint; | |
2524 | ||
35df4500 | 2525 | if (new_type != bl->loc_type) |
765dc015 VP |
2526 | { |
2527 | static int said = 0; | |
cc59ec59 | 2528 | |
35df4500 | 2529 | bl->loc_type = new_type; |
765dc015 VP |
2530 | if (!said) |
2531 | { | |
3e43a32a MS |
2532 | fprintf_filtered (gdb_stdout, |
2533 | _("Note: automatically using " | |
2534 | "hardware breakpoints for " | |
2535 | "read-only addresses.\n")); | |
765dc015 VP |
2536 | said = 1; |
2537 | } | |
2538 | } | |
2539 | } | |
35df4500 | 2540 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2541 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2542 | warning (_("cannot set software breakpoint " |
2543 | "at readonly address %s"), | |
35df4500 | 2544 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2545 | } |
2546 | } | |
2547 | ||
879bfdc2 DJ |
2548 | /* First check to see if we have to handle an overlay. */ |
2549 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2550 | || bl->section == NULL |
2551 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2552 | { |
2553 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2554 | TRY_CATCH (e, RETURN_MASK_ALL) |
2555 | { | |
0000e5cc PA |
2556 | int val; |
2557 | ||
dd61ec5c | 2558 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2559 | if (val) |
2560 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2561 | } |
2562 | if (e.reason < 0) | |
2563 | { | |
0000e5cc PA |
2564 | bp_err = e.error; |
2565 | bp_err_message = e.message; | |
dd61ec5c | 2566 | } |
879bfdc2 DJ |
2567 | } |
2568 | else | |
2569 | { | |
4a64f543 | 2570 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2571 | Shall we set a breakpoint at the LMA? */ |
2572 | if (!overlay_events_enabled) | |
2573 | { | |
2574 | /* Yes -- overlay event support is not active, | |
2575 | so we must try to set a breakpoint at the LMA. | |
2576 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2577 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2578 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2579 | bl->owner->number); |
879bfdc2 DJ |
2580 | else |
2581 | { | |
35df4500 TJB |
2582 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2583 | bl->section); | |
879bfdc2 | 2584 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2585 | bl->overlay_target_info = bl->target_info; |
2586 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2587 | |
2588 | /* No overlay handling: just set the breakpoint. */ | |
2589 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2590 | { | |
2591 | int val; | |
2592 | ||
2593 | val = target_insert_breakpoint (bl->gdbarch, | |
2594 | &bl->overlay_target_info); | |
2595 | if (val) | |
2596 | bp_err = GENERIC_ERROR; | |
2597 | } | |
2598 | if (e.reason < 0) | |
2599 | { | |
2600 | bp_err = e.error; | |
2601 | bp_err_message = e.message; | |
2602 | } | |
2603 | ||
2604 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2605 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2606 | "Overlay breakpoint %d " |
2607 | "failed: in ROM?\n", | |
35df4500 | 2608 | bl->owner->number); |
879bfdc2 DJ |
2609 | } |
2610 | } | |
2611 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2612 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2613 | { |
2614 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2615 | TRY_CATCH (e, RETURN_MASK_ALL) |
2616 | { | |
0000e5cc PA |
2617 | int val; |
2618 | ||
dd61ec5c | 2619 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2620 | if (val) |
2621 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2622 | } |
2623 | if (e.reason < 0) | |
2624 | { | |
0000e5cc PA |
2625 | bp_err = e.error; |
2626 | bp_err_message = e.message; | |
dd61ec5c | 2627 | } |
879bfdc2 DJ |
2628 | } |
2629 | else | |
2630 | { | |
2631 | /* No. This breakpoint will not be inserted. | |
2632 | No error, but do not mark the bp as 'inserted'. */ | |
2633 | return 0; | |
2634 | } | |
2635 | } | |
2636 | ||
0000e5cc | 2637 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2638 | { |
2639 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2640 | |
2641 | /* In some cases, we might not be able to insert a | |
2642 | breakpoint in a shared library that has already been | |
2643 | removed, but we have not yet processed the shlib unload | |
2644 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2645 | breakpoint insertion themselves can't tell why the |
2646 | breakpoint insertion failed (e.g., the remote target | |
2647 | doesn't define error codes), so we must treat generic | |
2648 | errors as memory errors. */ | |
0000e5cc | 2649 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2650 | && bl->loc_type == bp_loc_software_breakpoint |
0000e5cc | 2651 | && solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2652 | { |
4a64f543 | 2653 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2654 | bl->shlib_disabled = 1; |
8d3788bd | 2655 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2656 | if (!*disabled_breaks) |
2657 | { | |
2658 | fprintf_unfiltered (tmp_error_stream, | |
2659 | "Cannot insert breakpoint %d.\n", | |
2660 | bl->owner->number); | |
2661 | fprintf_unfiltered (tmp_error_stream, | |
2662 | "Temporarily disabling shared " | |
2663 | "library breakpoints:\n"); | |
2664 | } | |
2665 | *disabled_breaks = 1; | |
879bfdc2 | 2666 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2667 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2668 | return 0; |
879bfdc2 DJ |
2669 | } |
2670 | else | |
879bfdc2 | 2671 | { |
35df4500 | 2672 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2673 | { |
0000e5cc PA |
2674 | *hw_breakpoint_error = 1; |
2675 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2676 | fprintf_unfiltered (tmp_error_stream, |
2677 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2678 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2679 | if (bp_err_message != NULL) | |
2680 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2681 | } |
2682 | else | |
2683 | { | |
0000e5cc PA |
2684 | if (bp_err_message == NULL) |
2685 | { | |
2686 | char *message | |
2687 | = memory_error_message (TARGET_XFER_E_IO, | |
2688 | bl->gdbarch, bl->address); | |
2689 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2690 | ||
2691 | fprintf_unfiltered (tmp_error_stream, | |
2692 | "Cannot insert breakpoint %d.\n" | |
2693 | "%s\n", | |
2694 | bl->owner->number, message); | |
2695 | do_cleanups (old_chain); | |
2696 | } | |
2697 | else | |
2698 | { | |
2699 | fprintf_unfiltered (tmp_error_stream, | |
2700 | "Cannot insert breakpoint %d: %s\n", | |
2701 | bl->owner->number, | |
2702 | bp_err_message); | |
2703 | } | |
879bfdc2 | 2704 | } |
0000e5cc | 2705 | return 1; |
879bfdc2 DJ |
2706 | |
2707 | } | |
2708 | } | |
2709 | else | |
35df4500 | 2710 | bl->inserted = 1; |
879bfdc2 | 2711 | |
0000e5cc | 2712 | return 0; |
879bfdc2 DJ |
2713 | } |
2714 | ||
35df4500 | 2715 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2716 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2717 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2718 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2719 | { |
0000e5cc PA |
2720 | int val; |
2721 | ||
77b06cd7 TJB |
2722 | gdb_assert (bl->owner->ops != NULL |
2723 | && bl->owner->ops->insert_location != NULL); | |
2724 | ||
2725 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2726 | |
2727 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2728 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2729 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2730 | { |
2731 | struct bp_location *loc, **loc_temp; | |
2732 | ||
2733 | /* But don't try to insert it, if there's already another | |
2734 | hw_access location that would be considered a duplicate | |
2735 | of this one. */ | |
2736 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2737 | if (loc != bl |
85d721b8 | 2738 | && loc->watchpoint_type == hw_access |
35df4500 | 2739 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2740 | { |
35df4500 TJB |
2741 | bl->duplicate = 1; |
2742 | bl->inserted = 1; | |
2743 | bl->target_info = loc->target_info; | |
2744 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2745 | val = 0; |
2746 | break; | |
2747 | } | |
2748 | ||
2749 | if (val == 1) | |
2750 | { | |
77b06cd7 TJB |
2751 | bl->watchpoint_type = hw_access; |
2752 | val = bl->owner->ops->insert_location (bl); | |
2753 | ||
2754 | if (val) | |
2755 | /* Back to the original value. */ | |
2756 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2757 | } |
2758 | } | |
2759 | ||
35df4500 | 2760 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2761 | } |
2762 | ||
35df4500 | 2763 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2764 | { |
0000e5cc PA |
2765 | int val; |
2766 | ||
77b06cd7 TJB |
2767 | gdb_assert (bl->owner->ops != NULL |
2768 | && bl->owner->ops->insert_location != NULL); | |
2769 | ||
2770 | val = bl->owner->ops->insert_location (bl); | |
2771 | if (val) | |
2772 | { | |
2773 | bl->owner->enable_state = bp_disabled; | |
2774 | ||
2775 | if (val == 1) | |
2776 | warning (_("\ | |
2777 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2778 | of catchpoint."), bl->owner->number); | |
2779 | else | |
2780 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2781 | } | |
2782 | ||
2783 | bl->inserted = (val == 0); | |
1640b821 DJ |
2784 | |
2785 | /* We've already printed an error message if there was a problem | |
2786 | inserting this catchpoint, and we've disabled the catchpoint, | |
2787 | so just return success. */ | |
2788 | return 0; | |
879bfdc2 DJ |
2789 | } |
2790 | ||
2791 | return 0; | |
2792 | } | |
2793 | ||
6c95b8df PA |
2794 | /* This function is called when program space PSPACE is about to be |
2795 | deleted. It takes care of updating breakpoints to not reference | |
2796 | PSPACE anymore. */ | |
2797 | ||
2798 | void | |
2799 | breakpoint_program_space_exit (struct program_space *pspace) | |
2800 | { | |
2801 | struct breakpoint *b, *b_temp; | |
876fa593 | 2802 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2803 | |
2804 | /* Remove any breakpoint that was set through this program space. */ | |
2805 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2806 | { | |
2807 | if (b->pspace == pspace) | |
2808 | delete_breakpoint (b); | |
2809 | } | |
2810 | ||
2811 | /* Breakpoints set through other program spaces could have locations | |
2812 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2813 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2814 | { |
2815 | struct bp_location *tmp; | |
2816 | ||
2817 | if (loc->pspace == pspace) | |
2818 | { | |
2bdf28a0 | 2819 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2820 | if (loc->owner->loc == loc) |
2821 | loc->owner->loc = loc->next; | |
2822 | else | |
2823 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2824 | if (tmp->next == loc) | |
2825 | { | |
2826 | tmp->next = loc->next; | |
2827 | break; | |
2828 | } | |
2829 | } | |
2830 | } | |
2831 | ||
2832 | /* Now update the global location list to permanently delete the | |
2833 | removed locations above. */ | |
2834 | update_global_location_list (0); | |
2835 | } | |
2836 | ||
74960c60 VP |
2837 | /* Make sure all breakpoints are inserted in inferior. |
2838 | Throws exception on any error. | |
2839 | A breakpoint that is already inserted won't be inserted | |
2840 | again, so calling this function twice is safe. */ | |
2841 | void | |
2842 | insert_breakpoints (void) | |
2843 | { | |
2844 | struct breakpoint *bpt; | |
2845 | ||
2846 | ALL_BREAKPOINTS (bpt) | |
2847 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2848 | { |
2849 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2850 | ||
2851 | update_watchpoint (w, 0 /* don't reparse. */); | |
2852 | } | |
74960c60 | 2853 | |
b60e7edf | 2854 | update_global_location_list (1); |
74960c60 | 2855 | |
c35b1492 PA |
2856 | /* update_global_location_list does not insert breakpoints when |
2857 | always_inserted_mode is not enabled. Explicitly insert them | |
2858 | now. */ | |
2859 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2860 | insert_breakpoint_locations (); |
2861 | } | |
2862 | ||
20388dd6 YQ |
2863 | /* Invoke CALLBACK for each of bp_location. */ |
2864 | ||
2865 | void | |
2866 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2867 | { | |
2868 | struct bp_location *loc, **loc_tmp; | |
2869 | ||
2870 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2871 | { | |
2872 | callback (loc, NULL); | |
2873 | } | |
2874 | } | |
2875 | ||
b775012e LM |
2876 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2877 | target. It is the case with deleting and disabling of breakpoints when using | |
2878 | always-inserted mode. */ | |
2879 | ||
2880 | static void | |
2881 | update_inserted_breakpoint_locations (void) | |
2882 | { | |
2883 | struct bp_location *bl, **blp_tmp; | |
2884 | int error_flag = 0; | |
2885 | int val = 0; | |
2886 | int disabled_breaks = 0; | |
2887 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2888 | int hw_bp_details_reported = 0; |
b775012e LM |
2889 | |
2890 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2891 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2892 | ||
2893 | /* Explicitly mark the warning -- this will only be printed if | |
2894 | there was an error. */ | |
2895 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2896 | ||
2897 | save_current_space_and_thread (); | |
2898 | ||
2899 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2900 | { | |
2901 | /* We only want to update software breakpoints and hardware | |
2902 | breakpoints. */ | |
2903 | if (!is_breakpoint (bl->owner)) | |
2904 | continue; | |
2905 | ||
2906 | /* We only want to update locations that are already inserted | |
2907 | and need updating. This is to avoid unwanted insertion during | |
2908 | deletion of breakpoints. */ | |
2909 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2910 | continue; | |
2911 | ||
2912 | switch_to_program_space_and_thread (bl->pspace); | |
2913 | ||
2914 | /* For targets that support global breakpoints, there's no need | |
2915 | to select an inferior to insert breakpoint to. In fact, even | |
2916 | if we aren't attached to any process yet, we should still | |
2917 | insert breakpoints. */ | |
f5656ead | 2918 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2919 | && ptid_equal (inferior_ptid, null_ptid)) |
2920 | continue; | |
2921 | ||
2922 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2923 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2924 | if (val) |
2925 | error_flag = val; | |
2926 | } | |
2927 | ||
2928 | if (error_flag) | |
2929 | { | |
2930 | target_terminal_ours_for_output (); | |
2931 | error_stream (tmp_error_stream); | |
2932 | } | |
2933 | ||
2934 | do_cleanups (cleanups); | |
2935 | } | |
2936 | ||
c30eee59 | 2937 | /* Used when starting or continuing the program. */ |
c906108c | 2938 | |
74960c60 VP |
2939 | static void |
2940 | insert_breakpoint_locations (void) | |
c906108c | 2941 | { |
a5606eee | 2942 | struct breakpoint *bpt; |
35df4500 | 2943 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2944 | int error_flag = 0; |
c906108c | 2945 | int val = 0; |
3fbb6ffa | 2946 | int disabled_breaks = 0; |
81d0cc19 | 2947 | int hw_breakpoint_error = 0; |
dd61ec5c | 2948 | int hw_bp_error_explained_already = 0; |
c906108c | 2949 | |
81d0cc19 | 2950 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2951 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2952 | |
81d0cc19 GS |
2953 | /* Explicitly mark the warning -- this will only be printed if |
2954 | there was an error. */ | |
2955 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2956 | |
2957 | save_current_space_and_thread (); | |
2958 | ||
35df4500 | 2959 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2960 | { |
b775012e | 2961 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2962 | continue; |
2963 | ||
4a64f543 MS |
2964 | /* There is no point inserting thread-specific breakpoints if |
2965 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2966 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2967 | if (bl->owner->thread != -1 |
2968 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2969 | continue; |
2970 | ||
35df4500 | 2971 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2972 | |
2973 | /* For targets that support global breakpoints, there's no need | |
2974 | to select an inferior to insert breakpoint to. In fact, even | |
2975 | if we aren't attached to any process yet, we should still | |
2976 | insert breakpoints. */ | |
f5656ead | 2977 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2978 | && ptid_equal (inferior_ptid, null_ptid)) |
2979 | continue; | |
2980 | ||
3fbb6ffa | 2981 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2982 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2983 | if (val) |
eacd795a | 2984 | error_flag = val; |
879bfdc2 | 2985 | } |
c906108c | 2986 | |
4a64f543 MS |
2987 | /* If we failed to insert all locations of a watchpoint, remove |
2988 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2989 | ALL_BREAKPOINTS (bpt) |
2990 | { | |
2991 | int some_failed = 0; | |
2992 | struct bp_location *loc; | |
2993 | ||
2994 | if (!is_hardware_watchpoint (bpt)) | |
2995 | continue; | |
2996 | ||
d6b74ac4 | 2997 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2998 | continue; |
74960c60 VP |
2999 | |
3000 | if (bpt->disposition == disp_del_at_next_stop) | |
3001 | continue; | |
a5606eee VP |
3002 | |
3003 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3004 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3005 | { |
3006 | some_failed = 1; | |
3007 | break; | |
3008 | } | |
3009 | if (some_failed) | |
3010 | { | |
3011 | for (loc = bpt->loc; loc; loc = loc->next) | |
3012 | if (loc->inserted) | |
3013 | remove_breakpoint (loc, mark_uninserted); | |
3014 | ||
3015 | hw_breakpoint_error = 1; | |
3016 | fprintf_unfiltered (tmp_error_stream, | |
3017 | "Could not insert hardware watchpoint %d.\n", | |
3018 | bpt->number); | |
eacd795a | 3019 | error_flag = -1; |
a5606eee VP |
3020 | } |
3021 | } | |
3022 | ||
eacd795a | 3023 | if (error_flag) |
81d0cc19 GS |
3024 | { |
3025 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3026 | message about possibly exhausted resources. */ | |
dd61ec5c | 3027 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3028 | { |
c6510018 MS |
3029 | fprintf_unfiltered (tmp_error_stream, |
3030 | "Could not insert hardware breakpoints:\n\ | |
3031 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3032 | } |
81d0cc19 GS |
3033 | target_terminal_ours_for_output (); |
3034 | error_stream (tmp_error_stream); | |
3035 | } | |
f7545552 TT |
3036 | |
3037 | do_cleanups (cleanups); | |
c906108c SS |
3038 | } |
3039 | ||
c30eee59 TJB |
3040 | /* Used when the program stops. |
3041 | Returns zero if successful, or non-zero if there was a problem | |
3042 | removing a breakpoint location. */ | |
3043 | ||
c906108c | 3044 | int |
fba45db2 | 3045 | remove_breakpoints (void) |
c906108c | 3046 | { |
35df4500 | 3047 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3048 | int val = 0; |
c906108c | 3049 | |
35df4500 | 3050 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3051 | { |
1e4d1764 | 3052 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3053 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3054 | } |
3a1bae8e | 3055 | return val; |
c906108c SS |
3056 | } |
3057 | ||
49fa26b0 PA |
3058 | /* When a thread exits, remove breakpoints that are related to |
3059 | that thread. */ | |
3060 | ||
3061 | static void | |
3062 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3063 | { | |
3064 | struct breakpoint *b, *b_tmp; | |
3065 | ||
3066 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3067 | { | |
96181529 | 3068 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3069 | { |
3070 | b->disposition = disp_del_at_next_stop; | |
3071 | ||
3072 | printf_filtered (_("\ | |
46ecd527 | 3073 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3074 | b->number, tp->num); |
3075 | ||
3076 | /* Hide it from the user. */ | |
3077 | b->number = 0; | |
3078 | } | |
3079 | } | |
3080 | } | |
3081 | ||
6c95b8df PA |
3082 | /* Remove breakpoints of process PID. */ |
3083 | ||
3084 | int | |
3085 | remove_breakpoints_pid (int pid) | |
3086 | { | |
35df4500 | 3087 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3088 | int val; |
3089 | struct inferior *inf = find_inferior_pid (pid); | |
3090 | ||
35df4500 | 3091 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3092 | { |
35df4500 | 3093 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3094 | continue; |
3095 | ||
d3ce09f5 SS |
3096 | if (bl->owner->type == bp_dprintf) |
3097 | continue; | |
3098 | ||
35df4500 | 3099 | if (bl->inserted) |
6c95b8df | 3100 | { |
35df4500 | 3101 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3102 | if (val != 0) |
3103 | return val; | |
3104 | } | |
3105 | } | |
3106 | return 0; | |
3107 | } | |
3108 | ||
c906108c | 3109 | int |
fba45db2 | 3110 | reattach_breakpoints (int pid) |
c906108c | 3111 | { |
6c95b8df | 3112 | struct cleanup *old_chain; |
35df4500 | 3113 | struct bp_location *bl, **blp_tmp; |
c906108c | 3114 | int val; |
86b887df | 3115 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3116 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3117 | struct inferior *inf; |
3118 | struct thread_info *tp; | |
3119 | ||
3120 | tp = any_live_thread_of_process (pid); | |
3121 | if (tp == NULL) | |
3122 | return 1; | |
3123 | ||
3124 | inf = find_inferior_pid (pid); | |
3125 | old_chain = save_inferior_ptid (); | |
3126 | ||
3127 | inferior_ptid = tp->ptid; | |
a4954f26 | 3128 | |
86b887df | 3129 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3130 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3131 | |
35df4500 | 3132 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3133 | { |
35df4500 | 3134 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3135 | continue; |
3136 | ||
35df4500 | 3137 | if (bl->inserted) |
c5aa993b | 3138 | { |
35df4500 | 3139 | bl->inserted = 0; |
dd61ec5c | 3140 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3141 | if (val != 0) |
3142 | { | |
ce696e05 | 3143 | do_cleanups (old_chain); |
c5aa993b JM |
3144 | return val; |
3145 | } | |
3146 | } | |
3147 | } | |
ce696e05 | 3148 | do_cleanups (old_chain); |
c906108c SS |
3149 | return 0; |
3150 | } | |
3151 | ||
e58b0e63 PA |
3152 | static int internal_breakpoint_number = -1; |
3153 | ||
84f4c1fe PM |
3154 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3155 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3156 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3157 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3158 | breakpoint_count and that value incremented. Internal breakpoints |
3159 | do not set the internal var bpnum. */ | |
3160 | static void | |
3161 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3162 | { | |
3163 | if (internal) | |
3164 | b->number = internal_breakpoint_number--; | |
3165 | else | |
3166 | { | |
3167 | set_breakpoint_count (breakpoint_count + 1); | |
3168 | b->number = breakpoint_count; | |
3169 | } | |
3170 | } | |
3171 | ||
e62c965a | 3172 | static struct breakpoint * |
a6d9a66e | 3173 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3174 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3175 | const struct breakpoint_ops *ops) |
e62c965a | 3176 | { |
e62c965a PP |
3177 | struct symtab_and_line sal; |
3178 | struct breakpoint *b; | |
3179 | ||
4a64f543 | 3180 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3181 | |
3182 | sal.pc = address; | |
3183 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3184 | sal.pspace = current_program_space; |
e62c965a | 3185 | |
06edf0c0 | 3186 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3187 | b->number = internal_breakpoint_number--; |
3188 | b->disposition = disp_donttouch; | |
3189 | ||
3190 | return b; | |
3191 | } | |
3192 | ||
17450429 PP |
3193 | static const char *const longjmp_names[] = |
3194 | { | |
3195 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3196 | }; | |
3197 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3198 | ||
3199 | /* Per-objfile data private to breakpoint.c. */ | |
3200 | struct breakpoint_objfile_data | |
3201 | { | |
3202 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3203 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3204 | |
3205 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3206 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3207 | |
28106bc2 SDJ |
3208 | /* True if we have looked for longjmp probes. */ |
3209 | int longjmp_searched; | |
3210 | ||
3211 | /* SystemTap probe points for longjmp (if any). */ | |
3212 | VEC (probe_p) *longjmp_probes; | |
3213 | ||
17450429 | 3214 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3215 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3216 | |
3217 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3218 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3219 | |
3220 | /* True if we have looked for exception probes. */ | |
3221 | int exception_searched; | |
3222 | ||
3223 | /* SystemTap probe points for unwinding (if any). */ | |
3224 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3225 | }; |
3226 | ||
3227 | static const struct objfile_data *breakpoint_objfile_key; | |
3228 | ||
3229 | /* Minimal symbol not found sentinel. */ | |
3230 | static struct minimal_symbol msym_not_found; | |
3231 | ||
3232 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3233 | ||
3234 | static int | |
3235 | msym_not_found_p (const struct minimal_symbol *msym) | |
3236 | { | |
3237 | return msym == &msym_not_found; | |
3238 | } | |
3239 | ||
3240 | /* Return per-objfile data needed by breakpoint.c. | |
3241 | Allocate the data if necessary. */ | |
3242 | ||
3243 | static struct breakpoint_objfile_data * | |
3244 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3245 | { | |
3246 | struct breakpoint_objfile_data *bp_objfile_data; | |
3247 | ||
3248 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3249 | if (bp_objfile_data == NULL) | |
3250 | { | |
3251 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3252 | sizeof (*bp_objfile_data)); | |
3253 | ||
3254 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3255 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3256 | } | |
3257 | return bp_objfile_data; | |
3258 | } | |
3259 | ||
28106bc2 SDJ |
3260 | static void |
3261 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3262 | { | |
3263 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3264 | ||
3265 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3266 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3267 | } | |
3268 | ||
e62c965a | 3269 | static void |
af02033e | 3270 | create_overlay_event_breakpoint (void) |
e62c965a | 3271 | { |
69de3c6a | 3272 | struct objfile *objfile; |
af02033e | 3273 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3274 | |
69de3c6a PP |
3275 | ALL_OBJFILES (objfile) |
3276 | { | |
3277 | struct breakpoint *b; | |
17450429 PP |
3278 | struct breakpoint_objfile_data *bp_objfile_data; |
3279 | CORE_ADDR addr; | |
69de3c6a | 3280 | |
17450429 PP |
3281 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3282 | ||
3b7344d5 | 3283 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3284 | continue; |
3285 | ||
3b7344d5 | 3286 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3287 | { |
3b7344d5 | 3288 | struct bound_minimal_symbol m; |
17450429 PP |
3289 | |
3290 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3291 | if (m.minsym == NULL) |
17450429 PP |
3292 | { |
3293 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3294 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3295 | continue; |
3296 | } | |
3297 | bp_objfile_data->overlay_msym = m; | |
3298 | } | |
e62c965a | 3299 | |
77e371c0 | 3300 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3301 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3302 | bp_overlay_event, |
3303 | &internal_breakpoint_ops); | |
69de3c6a | 3304 | b->addr_string = xstrdup (func_name); |
e62c965a | 3305 | |
69de3c6a PP |
3306 | if (overlay_debugging == ovly_auto) |
3307 | { | |
3308 | b->enable_state = bp_enabled; | |
3309 | overlay_events_enabled = 1; | |
3310 | } | |
3311 | else | |
3312 | { | |
3313 | b->enable_state = bp_disabled; | |
3314 | overlay_events_enabled = 0; | |
3315 | } | |
e62c965a PP |
3316 | } |
3317 | update_global_location_list (1); | |
3318 | } | |
3319 | ||
0fd8e87f | 3320 | static void |
af02033e | 3321 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3322 | { |
6c95b8df | 3323 | struct program_space *pspace; |
6c95b8df PA |
3324 | struct cleanup *old_chain; |
3325 | ||
3326 | old_chain = save_current_program_space (); | |
0fd8e87f | 3327 | |
6c95b8df | 3328 | ALL_PSPACES (pspace) |
af02033e PP |
3329 | { |
3330 | struct objfile *objfile; | |
3331 | ||
3332 | set_current_program_space (pspace); | |
3333 | ||
3334 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3335 | { |
af02033e PP |
3336 | int i; |
3337 | struct gdbarch *gdbarch; | |
17450429 | 3338 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3339 | |
af02033e | 3340 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3341 | |
17450429 PP |
3342 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3343 | ||
28106bc2 SDJ |
3344 | if (!bp_objfile_data->longjmp_searched) |
3345 | { | |
25f9533e SDJ |
3346 | VEC (probe_p) *ret; |
3347 | ||
3348 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3349 | if (ret != NULL) | |
3350 | { | |
3351 | /* We are only interested in checking one element. */ | |
3352 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3353 | ||
3354 | if (!can_evaluate_probe_arguments (p)) | |
3355 | { | |
3356 | /* We cannot use the probe interface here, because it does | |
3357 | not know how to evaluate arguments. */ | |
3358 | VEC_free (probe_p, ret); | |
3359 | ret = NULL; | |
3360 | } | |
3361 | } | |
3362 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3363 | bp_objfile_data->longjmp_searched = 1; |
3364 | } | |
3365 | ||
3366 | if (bp_objfile_data->longjmp_probes != NULL) | |
3367 | { | |
3368 | int i; | |
3369 | struct probe *probe; | |
3370 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3371 | ||
3372 | for (i = 0; | |
3373 | VEC_iterate (probe_p, | |
3374 | bp_objfile_data->longjmp_probes, | |
3375 | i, probe); | |
3376 | ++i) | |
3377 | { | |
3378 | struct breakpoint *b; | |
3379 | ||
729662a5 TT |
3380 | b = create_internal_breakpoint (gdbarch, |
3381 | get_probe_address (probe, | |
3382 | objfile), | |
28106bc2 SDJ |
3383 | bp_longjmp_master, |
3384 | &internal_breakpoint_ops); | |
3385 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3386 | b->enable_state = bp_disabled; | |
3387 | } | |
3388 | ||
3389 | continue; | |
3390 | } | |
3391 | ||
0569175e TSD |
3392 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3393 | continue; | |
3394 | ||
17450429 | 3395 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3396 | { |
3397 | struct breakpoint *b; | |
af02033e | 3398 | const char *func_name; |
17450429 | 3399 | CORE_ADDR addr; |
6c95b8df | 3400 | |
3b7344d5 | 3401 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3402 | continue; |
0fd8e87f | 3403 | |
17450429 | 3404 | func_name = longjmp_names[i]; |
3b7344d5 | 3405 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3406 | { |
3b7344d5 | 3407 | struct bound_minimal_symbol m; |
17450429 PP |
3408 | |
3409 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3410 | if (m.minsym == NULL) |
17450429 PP |
3411 | { |
3412 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3413 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3414 | continue; |
3415 | } | |
3416 | bp_objfile_data->longjmp_msym[i] = m; | |
3417 | } | |
3418 | ||
77e371c0 | 3419 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3420 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3421 | &internal_breakpoint_ops); | |
af02033e PP |
3422 | b->addr_string = xstrdup (func_name); |
3423 | b->enable_state = bp_disabled; | |
3424 | } | |
0fd8e87f | 3425 | } |
af02033e | 3426 | } |
0fd8e87f | 3427 | update_global_location_list (1); |
6c95b8df PA |
3428 | |
3429 | do_cleanups (old_chain); | |
0fd8e87f UW |
3430 | } |
3431 | ||
af02033e | 3432 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3433 | static void |
af02033e | 3434 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3435 | { |
3436 | struct program_space *pspace; | |
aa7d318d | 3437 | struct cleanup *old_chain; |
af02033e | 3438 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3439 | |
3440 | old_chain = save_current_program_space (); | |
3441 | ||
3442 | ALL_PSPACES (pspace) | |
17450429 PP |
3443 | { |
3444 | struct objfile *objfile; | |
3445 | CORE_ADDR addr; | |
3446 | ||
3447 | set_current_program_space (pspace); | |
3448 | ||
aa7d318d TT |
3449 | ALL_OBJFILES (objfile) |
3450 | { | |
3451 | struct breakpoint *b; | |
17450429 | 3452 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3453 | |
17450429 | 3454 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3455 | |
3b7344d5 | 3456 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3457 | continue; |
3458 | ||
3b7344d5 | 3459 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3460 | { |
3b7344d5 | 3461 | struct bound_minimal_symbol m; |
17450429 PP |
3462 | |
3463 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3464 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3465 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3466 | { |
3467 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3468 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3469 | continue; |
3470 | } | |
3471 | bp_objfile_data->terminate_msym = m; | |
3472 | } | |
aa7d318d | 3473 | |
77e371c0 | 3474 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3475 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3476 | bp_std_terminate_master, |
3477 | &internal_breakpoint_ops); | |
aa7d318d TT |
3478 | b->addr_string = xstrdup (func_name); |
3479 | b->enable_state = bp_disabled; | |
3480 | } | |
17450429 PP |
3481 | } |
3482 | ||
aa7d318d TT |
3483 | update_global_location_list (1); |
3484 | ||
3485 | do_cleanups (old_chain); | |
3486 | } | |
3487 | ||
186c406b TT |
3488 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3489 | ||
70221824 | 3490 | static void |
186c406b TT |
3491 | create_exception_master_breakpoint (void) |
3492 | { | |
3493 | struct objfile *objfile; | |
17450429 | 3494 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3495 | |
3496 | ALL_OBJFILES (objfile) | |
3497 | { | |
17450429 PP |
3498 | struct breakpoint *b; |
3499 | struct gdbarch *gdbarch; | |
3500 | struct breakpoint_objfile_data *bp_objfile_data; | |
3501 | CORE_ADDR addr; | |
3502 | ||
3503 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3504 | ||
28106bc2 SDJ |
3505 | /* We prefer the SystemTap probe point if it exists. */ |
3506 | if (!bp_objfile_data->exception_searched) | |
3507 | { | |
25f9533e SDJ |
3508 | VEC (probe_p) *ret; |
3509 | ||
3510 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3511 | ||
3512 | if (ret != NULL) | |
3513 | { | |
3514 | /* We are only interested in checking one element. */ | |
3515 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3516 | ||
3517 | if (!can_evaluate_probe_arguments (p)) | |
3518 | { | |
3519 | /* We cannot use the probe interface here, because it does | |
3520 | not know how to evaluate arguments. */ | |
3521 | VEC_free (probe_p, ret); | |
3522 | ret = NULL; | |
3523 | } | |
3524 | } | |
3525 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3526 | bp_objfile_data->exception_searched = 1; |
3527 | } | |
3528 | ||
3529 | if (bp_objfile_data->exception_probes != NULL) | |
3530 | { | |
3531 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3532 | int i; | |
3533 | struct probe *probe; | |
3534 | ||
3535 | for (i = 0; | |
3536 | VEC_iterate (probe_p, | |
3537 | bp_objfile_data->exception_probes, | |
3538 | i, probe); | |
3539 | ++i) | |
3540 | { | |
3541 | struct breakpoint *b; | |
3542 | ||
729662a5 TT |
3543 | b = create_internal_breakpoint (gdbarch, |
3544 | get_probe_address (probe, | |
3545 | objfile), | |
28106bc2 SDJ |
3546 | bp_exception_master, |
3547 | &internal_breakpoint_ops); | |
3548 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3549 | b->enable_state = bp_disabled; | |
3550 | } | |
3551 | ||
3552 | continue; | |
3553 | } | |
3554 | ||
3555 | /* Otherwise, try the hook function. */ | |
3556 | ||
3b7344d5 | 3557 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3558 | continue; |
3559 | ||
3560 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3561 | |
3b7344d5 | 3562 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3563 | { |
3b7344d5 | 3564 | struct bound_minimal_symbol debug_hook; |
186c406b | 3565 | |
17450429 | 3566 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3567 | if (debug_hook.minsym == NULL) |
17450429 | 3568 | { |
3b7344d5 | 3569 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3570 | continue; |
3571 | } | |
3572 | ||
3573 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3574 | } |
17450429 | 3575 | |
77e371c0 | 3576 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3577 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3578 | ¤t_target); | |
06edf0c0 PA |
3579 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3580 | &internal_breakpoint_ops); | |
17450429 PP |
3581 | b->addr_string = xstrdup (func_name); |
3582 | b->enable_state = bp_disabled; | |
186c406b TT |
3583 | } |
3584 | ||
3585 | update_global_location_list (1); | |
3586 | } | |
3587 | ||
c906108c | 3588 | void |
fba45db2 | 3589 | update_breakpoints_after_exec (void) |
c906108c | 3590 | { |
35df4500 | 3591 | struct breakpoint *b, *b_tmp; |
876fa593 | 3592 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3593 | |
25b22b0a PA |
3594 | /* We're about to delete breakpoints from GDB's lists. If the |
3595 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3596 | writing the breakpoints' "shadow contents" back into memory. The | |
3597 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3598 | do that. Instead, the target is responsible from marking | |
3599 | breakpoints out as soon as it detects an exec. We don't do that | |
3600 | here instead, because there may be other attempts to delete | |
3601 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3602 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3603 | if (bploc->pspace == current_program_space) |
3604 | gdb_assert (!bploc->inserted); | |
c906108c | 3605 | |
35df4500 | 3606 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3607 | { |
6c95b8df PA |
3608 | if (b->pspace != current_program_space) |
3609 | continue; | |
3610 | ||
4a64f543 | 3611 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3612 | if (b->type == bp_shlib_event) |
3613 | { | |
3614 | delete_breakpoint (b); | |
3615 | continue; | |
3616 | } | |
c906108c | 3617 | |
4a64f543 | 3618 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3619 | if (b->type == bp_jit_event) |
3620 | { | |
3621 | delete_breakpoint (b); | |
3622 | continue; | |
3623 | } | |
3624 | ||
1900040c | 3625 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3626 | as must overlay event and longjmp master breakpoints. */ |
3627 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3628 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3629 | || b->type == bp_exception_master) | |
c4093a6a JM |
3630 | { |
3631 | delete_breakpoint (b); | |
3632 | continue; | |
3633 | } | |
3634 | ||
4a64f543 | 3635 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3636 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3637 | { |
3638 | delete_breakpoint (b); | |
3639 | continue; | |
3640 | } | |
3641 | ||
611c83ae PA |
3642 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3643 | after an exec. */ | |
186c406b | 3644 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3645 | || b->type == bp_longjmp_call_dummy |
186c406b | 3646 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3647 | { |
3648 | delete_breakpoint (b); | |
3649 | continue; | |
3650 | } | |
3651 | ||
ce78b96d JB |
3652 | if (b->type == bp_catchpoint) |
3653 | { | |
3654 | /* For now, none of the bp_catchpoint breakpoints need to | |
3655 | do anything at this point. In the future, if some of | |
3656 | the catchpoints need to something, we will need to add | |
3657 | a new method, and call this method from here. */ | |
3658 | continue; | |
3659 | } | |
3660 | ||
c5aa993b JM |
3661 | /* bp_finish is a special case. The only way we ought to be able |
3662 | to see one of these when an exec() has happened, is if the user | |
3663 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3664 | carries them to the call-site of the current callee, by setting | |
3665 | a temporary bp there and resuming. But in this case, the finish | |
3666 | will carry them entirely through the vfork & exec. | |
3667 | ||
3668 | We don't want to allow a bp_finish to remain inserted now. But | |
3669 | we can't safely delete it, 'cause finish_command has a handle to | |
3670 | the bp on a bpstat, and will later want to delete it. There's a | |
3671 | chance (and I've seen it happen) that if we delete the bp_finish | |
3672 | here, that its storage will get reused by the time finish_command | |
3673 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3674 | We really must allow finish_command to delete a bp_finish. | |
3675 | ||
e5dd4106 | 3676 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3677 | it's safe to delete something others may have handles to?" |
3678 | problem, what we'll do here is just uninsert the bp_finish, and | |
3679 | let finish_command delete it. | |
3680 | ||
3681 | (We know the bp_finish is "doomed" in the sense that it's | |
3682 | momentary, and will be deleted as soon as finish_command sees | |
3683 | the inferior stopped. So it doesn't matter that the bp's | |
3684 | address is probably bogus in the new a.out, unlike e.g., the | |
3685 | solib breakpoints.) */ | |
c5aa993b | 3686 | |
c5aa993b JM |
3687 | if (b->type == bp_finish) |
3688 | { | |
3689 | continue; | |
3690 | } | |
3691 | ||
3692 | /* Without a symbolic address, we have little hope of the | |
3693 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3694 | a.out. */ |
c5aa993b JM |
3695 | if (b->addr_string == NULL) |
3696 | { | |
3697 | delete_breakpoint (b); | |
3698 | continue; | |
3699 | } | |
c5aa993b | 3700 | } |
1900040c | 3701 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3702 | create_overlay_event_breakpoint (); |
3703 | create_longjmp_master_breakpoint (); | |
3704 | create_std_terminate_master_breakpoint (); | |
186c406b | 3705 | create_exception_master_breakpoint (); |
c906108c SS |
3706 | } |
3707 | ||
3708 | int | |
d80ee84f | 3709 | detach_breakpoints (ptid_t ptid) |
c906108c | 3710 | { |
35df4500 | 3711 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3712 | int val = 0; |
ce696e05 | 3713 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3714 | struct inferior *inf = current_inferior (); |
c5aa993b | 3715 | |
dfd4cc63 | 3716 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3717 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3718 | |
6c95b8df | 3719 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3720 | inferior_ptid = ptid; |
35df4500 | 3721 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3722 | { |
35df4500 | 3723 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3724 | continue; |
3725 | ||
bd9673a4 PW |
3726 | /* This function must physically remove breakpoints locations |
3727 | from the specified ptid, without modifying the breakpoint | |
3728 | package's state. Locations of type bp_loc_other are only | |
3729 | maintained at GDB side. So, there is no need to remove | |
3730 | these bp_loc_other locations. Moreover, removing these | |
3731 | would modify the breakpoint package's state. */ | |
3732 | if (bl->loc_type == bp_loc_other) | |
3733 | continue; | |
3734 | ||
35df4500 TJB |
3735 | if (bl->inserted) |
3736 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3737 | } |
d03285ec UW |
3738 | |
3739 | /* Detach single-step breakpoints as well. */ | |
3740 | detach_single_step_breakpoints (); | |
3741 | ||
ce696e05 | 3742 | do_cleanups (old_chain); |
3a1bae8e | 3743 | return val; |
c906108c SS |
3744 | } |
3745 | ||
35df4500 | 3746 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3747 | Note that this is used to detach breakpoints from a child fork. |
3748 | When we get here, the child isn't in the inferior list, and neither | |
3749 | do we have objects to represent its address space --- we should | |
35df4500 | 3750 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3751 | |
c906108c | 3752 | static int |
35df4500 | 3753 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3754 | { |
3755 | int val; | |
c5aa993b | 3756 | |
35df4500 TJB |
3757 | /* BL is never in moribund_locations by our callers. */ |
3758 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3759 | |
35df4500 | 3760 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3761 | /* Permanent breakpoints cannot be inserted or removed. */ |
3762 | return 0; | |
3763 | ||
74960c60 VP |
3764 | /* The type of none suggests that owner is actually deleted. |
3765 | This should not ever happen. */ | |
35df4500 | 3766 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3767 | |
35df4500 TJB |
3768 | if (bl->loc_type == bp_loc_software_breakpoint |
3769 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3770 | { |
c02f5703 MS |
3771 | /* "Normal" instruction breakpoint: either the standard |
3772 | trap-instruction bp (bp_breakpoint), or a | |
3773 | bp_hardware_breakpoint. */ | |
3774 | ||
3775 | /* First check to see if we have to handle an overlay. */ | |
3776 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3777 | || bl->section == NULL |
3778 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3779 | { |
3780 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3781 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3782 | } |
c906108c SS |
3783 | else |
3784 | { | |
4a64f543 | 3785 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3786 | Did we set a breakpoint at the LMA? */ |
3787 | if (!overlay_events_enabled) | |
3788 | { | |
3789 | /* Yes -- overlay event support is not active, so we | |
3790 | should have set a breakpoint at the LMA. Remove it. | |
3791 | */ | |
c02f5703 MS |
3792 | /* Ignore any failures: if the LMA is in ROM, we will |
3793 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3794 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3795 | target_remove_hw_breakpoint (bl->gdbarch, | |
3796 | &bl->overlay_target_info); | |
c02f5703 | 3797 | else |
35df4500 TJB |
3798 | target_remove_breakpoint (bl->gdbarch, |
3799 | &bl->overlay_target_info); | |
c02f5703 MS |
3800 | } |
3801 | /* Did we set a breakpoint at the VMA? | |
3802 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3803 | if (bl->inserted) |
c906108c | 3804 | { |
c02f5703 MS |
3805 | /* Yes -- remove it. Previously we did not bother to |
3806 | remove the breakpoint if the section had been | |
3807 | unmapped, but let's not rely on that being safe. We | |
3808 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3809 | |
3810 | /* However, we should remove *software* breakpoints only | |
3811 | if the section is still mapped, or else we overwrite | |
3812 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3813 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3814 | || section_is_mapped (bl->section)) | |
3815 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3816 | else |
3817 | val = 0; | |
c906108c | 3818 | } |
c02f5703 MS |
3819 | else |
3820 | { | |
3821 | /* No -- not inserted, so no need to remove. No error. */ | |
3822 | val = 0; | |
3823 | } | |
c906108c | 3824 | } |
879d1e6b UW |
3825 | |
3826 | /* In some cases, we might not be able to remove a breakpoint | |
3827 | in a shared library that has already been removed, but we | |
3828 | have not yet processed the shlib unload event. */ | |
076855f9 PA |
3829 | if (val |
3830 | && bl->loc_type == bp_loc_software_breakpoint | |
3831 | && solib_name_from_address (bl->pspace, bl->address)) | |
879d1e6b UW |
3832 | val = 0; |
3833 | ||
c906108c SS |
3834 | if (val) |
3835 | return val; | |
35df4500 | 3836 | bl->inserted = (is == mark_inserted); |
c906108c | 3837 | } |
35df4500 | 3838 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3839 | { |
77b06cd7 TJB |
3840 | gdb_assert (bl->owner->ops != NULL |
3841 | && bl->owner->ops->remove_location != NULL); | |
3842 | ||
35df4500 | 3843 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3844 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3845 | |
c906108c | 3846 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3847 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3848 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3849 | bl->owner->number); |
c906108c | 3850 | } |
35df4500 TJB |
3851 | else if (bl->owner->type == bp_catchpoint |
3852 | && breakpoint_enabled (bl->owner) | |
3853 | && !bl->duplicate) | |
ce78b96d | 3854 | { |
77b06cd7 TJB |
3855 | gdb_assert (bl->owner->ops != NULL |
3856 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3857 | |
77b06cd7 | 3858 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3859 | if (val) |
3860 | return val; | |
77b06cd7 | 3861 | |
35df4500 | 3862 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3863 | } |
c906108c SS |
3864 | |
3865 | return 0; | |
3866 | } | |
3867 | ||
6c95b8df | 3868 | static int |
35df4500 | 3869 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3870 | { |
3871 | int ret; | |
3872 | struct cleanup *old_chain; | |
3873 | ||
35df4500 TJB |
3874 | /* BL is never in moribund_locations by our callers. */ |
3875 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3876 | |
35df4500 | 3877 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3878 | /* Permanent breakpoints cannot be inserted or removed. */ |
3879 | return 0; | |
3880 | ||
3881 | /* The type of none suggests that owner is actually deleted. | |
3882 | This should not ever happen. */ | |
35df4500 | 3883 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3884 | |
3885 | old_chain = save_current_space_and_thread (); | |
3886 | ||
35df4500 | 3887 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3888 | |
35df4500 | 3889 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3890 | |
3891 | do_cleanups (old_chain); | |
3892 | return ret; | |
3893 | } | |
3894 | ||
c906108c SS |
3895 | /* Clear the "inserted" flag in all breakpoints. */ |
3896 | ||
25b22b0a | 3897 | void |
fba45db2 | 3898 | mark_breakpoints_out (void) |
c906108c | 3899 | { |
35df4500 | 3900 | struct bp_location *bl, **blp_tmp; |
c906108c | 3901 | |
35df4500 TJB |
3902 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3903 | if (bl->pspace == current_program_space) | |
3904 | bl->inserted = 0; | |
c906108c SS |
3905 | } |
3906 | ||
53a5351d JM |
3907 | /* Clear the "inserted" flag in all breakpoints and delete any |
3908 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3909 | |
3910 | Plus other such housekeeping that has to be done for breakpoints | |
3911 | between runs. | |
3912 | ||
53a5351d JM |
3913 | Note: this function gets called at the end of a run (by |
3914 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3915 | init_wait_for_inferior). */ |
c906108c SS |
3916 | |
3917 | ||
3918 | ||
3919 | void | |
fba45db2 | 3920 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3921 | { |
35df4500 TJB |
3922 | struct breakpoint *b, *b_tmp; |
3923 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3924 | int ix; |
6c95b8df | 3925 | struct program_space *pspace = current_program_space; |
c906108c | 3926 | |
50c71eaf PA |
3927 | /* If breakpoint locations are shared across processes, then there's |
3928 | nothing to do. */ | |
f5656ead | 3929 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3930 | return; |
3931 | ||
35df4500 | 3932 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3933 | { |
35df4500 TJB |
3934 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3935 | if (bl->pspace == pspace | |
3936 | && bl->owner->enable_state != bp_permanent) | |
3937 | bl->inserted = 0; | |
6c95b8df | 3938 | } |
075f6582 | 3939 | |
35df4500 | 3940 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3941 | { |
6c95b8df PA |
3942 | if (b->loc && b->loc->pspace != pspace) |
3943 | continue; | |
3944 | ||
c5aa993b JM |
3945 | switch (b->type) |
3946 | { | |
3947 | case bp_call_dummy: | |
e2e4d78b | 3948 | case bp_longjmp_call_dummy: |
c906108c | 3949 | |
c5aa993b | 3950 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3951 | cause problems when the inferior is rerun, so we better get |
3952 | rid of it. */ | |
3953 | ||
3954 | case bp_watchpoint_scope: | |
3955 | ||
3956 | /* Also get rid of scope breakpoints. */ | |
3957 | ||
3958 | case bp_shlib_event: | |
3959 | ||
3960 | /* Also remove solib event breakpoints. Their addresses may | |
3961 | have changed since the last time we ran the program. | |
3962 | Actually we may now be debugging against different target; | |
3963 | and so the solib backend that installed this breakpoint may | |
3964 | not be used in by the target. E.g., | |
3965 | ||
3966 | (gdb) file prog-linux | |
3967 | (gdb) run # native linux target | |
3968 | ... | |
3969 | (gdb) kill | |
3970 | (gdb) file prog-win.exe | |
3971 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3972 | */ | |
c906108c | 3973 | |
f59f708a PA |
3974 | case bp_step_resume: |
3975 | ||
3976 | /* Also remove step-resume breakpoints. */ | |
3977 | ||
c5aa993b JM |
3978 | delete_breakpoint (b); |
3979 | break; | |
c906108c | 3980 | |
c5aa993b JM |
3981 | case bp_watchpoint: |
3982 | case bp_hardware_watchpoint: | |
3983 | case bp_read_watchpoint: | |
3984 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3985 | { |
3986 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3987 | |
3a5c3e22 PA |
3988 | /* Likewise for watchpoints on local expressions. */ |
3989 | if (w->exp_valid_block != NULL) | |
3990 | delete_breakpoint (b); | |
3991 | else if (context == inf_starting) | |
3992 | { | |
3993 | /* Reset val field to force reread of starting value in | |
3994 | insert_breakpoints. */ | |
3995 | if (w->val) | |
3996 | value_free (w->val); | |
3997 | w->val = NULL; | |
3998 | w->val_valid = 0; | |
c860120c | 3999 | } |
3a5c3e22 | 4000 | } |
c5aa993b JM |
4001 | break; |
4002 | default: | |
c5aa993b JM |
4003 | break; |
4004 | } | |
4005 | } | |
1c5cfe86 PA |
4006 | |
4007 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4008 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4009 | decref_bp_location (&bl); | |
1c5cfe86 | 4010 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4011 | } |
4012 | ||
6c95b8df PA |
4013 | /* These functions concern about actual breakpoints inserted in the |
4014 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4015 | we need to hop over the bkpt --- so we check for address space | |
4016 | match, not program space. */ | |
4017 | ||
c2c6d25f JM |
4018 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4019 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4020 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4021 | permanent breakpoint. | |
4022 | - When continuing from a location with an ordinary breakpoint, we | |
4023 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4024 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4025 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4026 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4027 | |
c2c6d25f | 4028 | enum breakpoint_here |
6c95b8df | 4029 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4030 | { |
35df4500 | 4031 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4032 | int any_breakpoint_here = 0; |
c906108c | 4033 | |
35df4500 | 4034 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4035 | { |
35df4500 TJB |
4036 | if (bl->loc_type != bp_loc_software_breakpoint |
4037 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4038 | continue; |
4039 | ||
f1310107 | 4040 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
4041 | if ((breakpoint_enabled (bl->owner) |
4042 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 4043 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4044 | { |
4045 | if (overlay_debugging | |
35df4500 TJB |
4046 | && section_is_overlay (bl->section) |
4047 | && !section_is_mapped (bl->section)) | |
075f6582 | 4048 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 4049 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
4050 | return permanent_breakpoint_here; |
4051 | else | |
4052 | any_breakpoint_here = 1; | |
4053 | } | |
4054 | } | |
c906108c | 4055 | |
c2c6d25f | 4056 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4057 | } |
4058 | ||
1c5cfe86 PA |
4059 | /* Return true if there's a moribund breakpoint at PC. */ |
4060 | ||
4061 | int | |
6c95b8df | 4062 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4063 | { |
4064 | struct bp_location *loc; | |
4065 | int ix; | |
4066 | ||
4067 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4068 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4069 | return 1; |
4070 | ||
4071 | return 0; | |
4072 | } | |
c2c6d25f | 4073 | |
c36b740a | 4074 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
4075 | inserted using regular breakpoint_chain / bp_location array |
4076 | mechanism. This does not check for single-step breakpoints, which | |
4077 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
4078 | |
4079 | int | |
4a64f543 MS |
4080 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
4081 | CORE_ADDR pc) | |
c906108c | 4082 | { |
35df4500 | 4083 | struct bp_location *bl, **blp_tmp; |
c906108c | 4084 | |
35df4500 | 4085 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4086 | { |
35df4500 TJB |
4087 | if (bl->loc_type != bp_loc_software_breakpoint |
4088 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4089 | continue; |
4090 | ||
35df4500 | 4091 | if (bl->inserted |
f1310107 | 4092 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4093 | { |
4094 | if (overlay_debugging | |
35df4500 TJB |
4095 | && section_is_overlay (bl->section) |
4096 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4097 | continue; /* unmapped overlay -- can't be a match */ |
4098 | else | |
4099 | return 1; | |
4100 | } | |
c5aa993b | 4101 | } |
c36b740a VP |
4102 | return 0; |
4103 | } | |
4104 | ||
4105 | /* Returns non-zero iff there's either regular breakpoint | |
4106 | or a single step breakpoint inserted at PC. */ | |
4107 | ||
4108 | int | |
6c95b8df | 4109 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 4110 | { |
6c95b8df | 4111 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4112 | return 1; |
c906108c | 4113 | |
6c95b8df | 4114 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4115 | return 1; |
4116 | ||
c906108c SS |
4117 | return 0; |
4118 | } | |
4119 | ||
4fa8626c DJ |
4120 | /* This function returns non-zero iff there is a software breakpoint |
4121 | inserted at PC. */ | |
4122 | ||
4123 | int | |
3e43a32a MS |
4124 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4125 | CORE_ADDR pc) | |
4fa8626c | 4126 | { |
35df4500 | 4127 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4128 | |
35df4500 | 4129 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4130 | { |
35df4500 | 4131 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4132 | continue; |
4133 | ||
35df4500 TJB |
4134 | if (bl->inserted |
4135 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4136 | aspace, pc)) |
4fa8626c DJ |
4137 | { |
4138 | if (overlay_debugging | |
35df4500 TJB |
4139 | && section_is_overlay (bl->section) |
4140 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4141 | continue; /* unmapped overlay -- can't be a match */ |
4142 | else | |
4143 | return 1; | |
4144 | } | |
4145 | } | |
4146 | ||
1aafd4da | 4147 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4148 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4149 | return 1; |
4150 | ||
4fa8626c DJ |
4151 | return 0; |
4152 | } | |
4153 | ||
9093389c PA |
4154 | int |
4155 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4156 | CORE_ADDR addr, ULONGEST len) | |
4157 | { | |
4158 | struct breakpoint *bpt; | |
4159 | ||
4160 | ALL_BREAKPOINTS (bpt) | |
4161 | { | |
4162 | struct bp_location *loc; | |
4163 | ||
4164 | if (bpt->type != bp_hardware_watchpoint | |
4165 | && bpt->type != bp_access_watchpoint) | |
4166 | continue; | |
4167 | ||
4168 | if (!breakpoint_enabled (bpt)) | |
4169 | continue; | |
4170 | ||
4171 | for (loc = bpt->loc; loc; loc = loc->next) | |
4172 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4173 | { | |
4174 | CORE_ADDR l, h; | |
4175 | ||
4176 | /* Check for intersection. */ | |
4177 | l = max (loc->address, addr); | |
4178 | h = min (loc->address + loc->length, addr + len); | |
4179 | if (l < h) | |
4180 | return 1; | |
4181 | } | |
4182 | } | |
4183 | return 0; | |
4184 | } | |
4185 | ||
075f6582 DJ |
4186 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4187 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4188 | |
4189 | int | |
6c95b8df PA |
4190 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4191 | ptid_t ptid) | |
c906108c | 4192 | { |
35df4500 | 4193 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4194 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4195 | int thread = -1; |
4a306c9a | 4196 | int task = 0; |
a6f1cd96 | 4197 | |
35df4500 | 4198 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4199 | { |
35df4500 TJB |
4200 | if (bl->loc_type != bp_loc_software_breakpoint |
4201 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4202 | continue; |
4203 | ||
35df4500 TJB |
4204 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4205 | if (!breakpoint_enabled (bl->owner) | |
4206 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4207 | continue; |
4208 | ||
f1310107 | 4209 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4210 | continue; |
4211 | ||
35df4500 | 4212 | if (bl->owner->thread != -1) |
075f6582 | 4213 | { |
a6f1cd96 JB |
4214 | /* This is a thread-specific breakpoint. Check that ptid |
4215 | matches that thread. If thread hasn't been computed yet, | |
4216 | it is now time to do so. */ | |
4217 | if (thread == -1) | |
4218 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4219 | if (bl->owner->thread != thread) |
a6f1cd96 | 4220 | continue; |
075f6582 | 4221 | } |
a6f1cd96 | 4222 | |
35df4500 | 4223 | if (bl->owner->task != 0) |
4a306c9a JB |
4224 | { |
4225 | /* This is a task-specific breakpoint. Check that ptid | |
4226 | matches that task. If task hasn't been computed yet, | |
4227 | it is now time to do so. */ | |
4228 | if (task == 0) | |
4229 | task = ada_get_task_number (ptid); | |
35df4500 | 4230 | if (bl->owner->task != task) |
4a306c9a JB |
4231 | continue; |
4232 | } | |
4233 | ||
a6f1cd96 | 4234 | if (overlay_debugging |
35df4500 TJB |
4235 | && section_is_overlay (bl->section) |
4236 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4237 | continue; /* unmapped overlay -- can't be a match */ |
4238 | ||
4239 | return 1; | |
c5aa993b | 4240 | } |
c906108c SS |
4241 | |
4242 | return 0; | |
4243 | } | |
c906108c | 4244 | \f |
c5aa993b | 4245 | |
c906108c SS |
4246 | /* bpstat stuff. External routines' interfaces are documented |
4247 | in breakpoint.h. */ | |
4248 | ||
4249 | int | |
c326b90e | 4250 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4251 | { |
533be4dd | 4252 | return (ep->type == bp_catchpoint); |
c906108c SS |
4253 | } |
4254 | ||
f431efe5 PA |
4255 | /* Frees any storage that is part of a bpstat. Does not walk the |
4256 | 'next' chain. */ | |
4257 | ||
4258 | static void | |
198757a8 VP |
4259 | bpstat_free (bpstat bs) |
4260 | { | |
4261 | if (bs->old_val != NULL) | |
4262 | value_free (bs->old_val); | |
9add0f1b | 4263 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4264 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4265 | xfree (bs); |
4266 | } | |
4267 | ||
c906108c SS |
4268 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4269 | Also free any storage that is part of a bpstat. */ | |
4270 | ||
4271 | void | |
fba45db2 | 4272 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4273 | { |
4274 | bpstat p; | |
4275 | bpstat q; | |
4276 | ||
4277 | if (bsp == 0) | |
4278 | return; | |
4279 | p = *bsp; | |
4280 | while (p != NULL) | |
4281 | { | |
4282 | q = p->next; | |
198757a8 | 4283 | bpstat_free (p); |
c906108c SS |
4284 | p = q; |
4285 | } | |
4286 | *bsp = NULL; | |
4287 | } | |
4288 | ||
4289 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4290 | is part of the bpstat is copied as well. */ | |
4291 | ||
4292 | bpstat | |
fba45db2 | 4293 | bpstat_copy (bpstat bs) |
c906108c SS |
4294 | { |
4295 | bpstat p = NULL; | |
4296 | bpstat tmp; | |
4297 | bpstat retval = NULL; | |
4298 | ||
4299 | if (bs == NULL) | |
4300 | return bs; | |
4301 | ||
4302 | for (; bs != NULL; bs = bs->next) | |
4303 | { | |
4304 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4305 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4306 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4307 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4308 | if (bs->old_val != NULL) |
3c3185ac JK |
4309 | { |
4310 | tmp->old_val = value_copy (bs->old_val); | |
4311 | release_value (tmp->old_val); | |
4312 | } | |
31cc81e9 | 4313 | |
c906108c SS |
4314 | if (p == NULL) |
4315 | /* This is the first thing in the chain. */ | |
4316 | retval = tmp; | |
4317 | else | |
4318 | p->next = tmp; | |
4319 | p = tmp; | |
4320 | } | |
4321 | p->next = NULL; | |
4322 | return retval; | |
4323 | } | |
4324 | ||
4a64f543 | 4325 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4326 | |
4327 | bpstat | |
fba45db2 | 4328 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4329 | { |
c5aa993b JM |
4330 | if (bsp == NULL) |
4331 | return NULL; | |
c906108c | 4332 | |
c5aa993b JM |
4333 | for (; bsp != NULL; bsp = bsp->next) |
4334 | { | |
f431efe5 | 4335 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4336 | return bsp; |
4337 | } | |
c906108c SS |
4338 | return NULL; |
4339 | } | |
4340 | ||
ab04a2af TT |
4341 | /* See breakpoint.h. */ |
4342 | ||
47591c29 | 4343 | int |
427cd150 | 4344 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4345 | { |
ab04a2af TT |
4346 | for (; bsp != NULL; bsp = bsp->next) |
4347 | { | |
427cd150 TT |
4348 | if (bsp->breakpoint_at == NULL) |
4349 | { | |
4350 | /* A moribund location can never explain a signal other than | |
4351 | GDB_SIGNAL_TRAP. */ | |
4352 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4353 | return 1; |
427cd150 TT |
4354 | } |
4355 | else | |
47591c29 PA |
4356 | { |
4357 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4358 | sig)) | |
4359 | return 1; | |
4360 | } | |
ab04a2af TT |
4361 | } |
4362 | ||
47591c29 | 4363 | return 0; |
ab04a2af TT |
4364 | } |
4365 | ||
4a64f543 MS |
4366 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4367 | stopped at. *BSP upon return is a bpstat which points to the | |
4368 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4369 | good for anything but further calls to bpstat_num). | |
4370 | ||
8671a17b PA |
4371 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4372 | Return -1 if stopped at a breakpoint that has been deleted since | |
4373 | we set it. | |
4374 | Return 1 otherwise. */ | |
c906108c SS |
4375 | |
4376 | int | |
8671a17b | 4377 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4378 | { |
4379 | struct breakpoint *b; | |
4380 | ||
4381 | if ((*bsp) == NULL) | |
4382 | return 0; /* No more breakpoint values */ | |
8671a17b | 4383 | |
4a64f543 MS |
4384 | /* We assume we'll never have several bpstats that correspond to a |
4385 | single breakpoint -- otherwise, this function might return the | |
4386 | same number more than once and this will look ugly. */ | |
f431efe5 | 4387 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4388 | *bsp = (*bsp)->next; |
4389 | if (b == NULL) | |
4390 | return -1; /* breakpoint that's been deleted since */ | |
4391 | ||
4392 | *num = b->number; /* We have its number */ | |
4393 | return 1; | |
c906108c SS |
4394 | } |
4395 | ||
e93ca019 | 4396 | /* See breakpoint.h. */ |
c906108c SS |
4397 | |
4398 | void | |
e93ca019 | 4399 | bpstat_clear_actions (void) |
c906108c | 4400 | { |
e93ca019 JK |
4401 | struct thread_info *tp; |
4402 | bpstat bs; | |
4403 | ||
4404 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4405 | return; | |
4406 | ||
4407 | tp = find_thread_ptid (inferior_ptid); | |
4408 | if (tp == NULL) | |
4409 | return; | |
4410 | ||
4411 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4412 | { |
9add0f1b | 4413 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4414 | |
c906108c SS |
4415 | if (bs->old_val != NULL) |
4416 | { | |
4417 | value_free (bs->old_val); | |
4418 | bs->old_val = NULL; | |
4419 | } | |
4420 | } | |
4421 | } | |
4422 | ||
f3b1572e PA |
4423 | /* Called when a command is about to proceed the inferior. */ |
4424 | ||
4425 | static void | |
4426 | breakpoint_about_to_proceed (void) | |
4427 | { | |
4428 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4429 | { | |
4430 | struct thread_info *tp = inferior_thread (); | |
4431 | ||
4432 | /* Allow inferior function calls in breakpoint commands to not | |
4433 | interrupt the command list. When the call finishes | |
4434 | successfully, the inferior will be standing at the same | |
4435 | breakpoint as if nothing happened. */ | |
16c381f0 | 4436 | if (tp->control.in_infcall) |
f3b1572e PA |
4437 | return; |
4438 | } | |
4439 | ||
4440 | breakpoint_proceeded = 1; | |
4441 | } | |
4442 | ||
4a64f543 MS |
4443 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4444 | command. */ | |
c906108c | 4445 | static void |
4efb68b1 | 4446 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4447 | { |
4448 | executing_breakpoint_commands = 0; | |
4449 | } | |
4450 | ||
abf85f46 JK |
4451 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4452 | or its equivalent. */ | |
4453 | ||
4454 | static int | |
4455 | command_line_is_silent (struct command_line *cmd) | |
4456 | { | |
4457 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4458 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4459 | } | |
4460 | ||
4a64f543 MS |
4461 | /* Execute all the commands associated with all the breakpoints at |
4462 | this location. Any of these commands could cause the process to | |
4463 | proceed beyond this point, etc. We look out for such changes by | |
4464 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4465 | |
347bddb7 PA |
4466 | Returns true if a breakpoint command resumed the inferior. In that |
4467 | case, it is the caller's responsibility to recall it again with the | |
4468 | bpstat of the current thread. */ | |
4469 | ||
4470 | static int | |
4471 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4472 | { |
4473 | bpstat bs; | |
4474 | struct cleanup *old_chain; | |
347bddb7 | 4475 | int again = 0; |
c906108c SS |
4476 | |
4477 | /* Avoid endless recursion if a `source' command is contained | |
4478 | in bs->commands. */ | |
4479 | if (executing_breakpoint_commands) | |
347bddb7 | 4480 | return 0; |
c906108c SS |
4481 | |
4482 | executing_breakpoint_commands = 1; | |
4483 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4484 | ||
cf6c5ffb TT |
4485 | prevent_dont_repeat (); |
4486 | ||
4a64f543 | 4487 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4488 | bs = *bsp; |
4489 | ||
4490 | breakpoint_proceeded = 0; | |
4491 | for (; bs != NULL; bs = bs->next) | |
4492 | { | |
9add0f1b | 4493 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4494 | struct command_line *cmd; |
4495 | struct cleanup *this_cmd_tree_chain; | |
4496 | ||
4497 | /* Take ownership of the BSP's command tree, if it has one. | |
4498 | ||
4499 | The command tree could legitimately contain commands like | |
4500 | 'step' and 'next', which call clear_proceed_status, which | |
4501 | frees stop_bpstat's command tree. To make sure this doesn't | |
4502 | free the tree we're executing out from under us, we need to | |
4503 | take ownership of the tree ourselves. Since a given bpstat's | |
4504 | commands are only executed once, we don't need to copy it; we | |
4505 | can clear the pointer in the bpstat, and make sure we free | |
4506 | the tree when we're done. */ | |
9add0f1b TT |
4507 | ccmd = bs->commands; |
4508 | bs->commands = NULL; | |
abf85f46 JK |
4509 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4510 | cmd = ccmd ? ccmd->commands : NULL; | |
4511 | if (command_line_is_silent (cmd)) | |
4512 | { | |
4513 | /* The action has been already done by bpstat_stop_status. */ | |
4514 | cmd = cmd->next; | |
4515 | } | |
6c50ab1c | 4516 | |
c906108c SS |
4517 | while (cmd != NULL) |
4518 | { | |
4519 | execute_control_command (cmd); | |
4520 | ||
4521 | if (breakpoint_proceeded) | |
4522 | break; | |
4523 | else | |
4524 | cmd = cmd->next; | |
4525 | } | |
6c50ab1c JB |
4526 | |
4527 | /* We can free this command tree now. */ | |
4528 | do_cleanups (this_cmd_tree_chain); | |
4529 | ||
c906108c | 4530 | if (breakpoint_proceeded) |
32c1e744 VP |
4531 | { |
4532 | if (target_can_async_p ()) | |
347bddb7 PA |
4533 | /* If we are in async mode, then the target might be still |
4534 | running, not stopped at any breakpoint, so nothing for | |
4535 | us to do here -- just return to the event loop. */ | |
4536 | ; | |
32c1e744 VP |
4537 | else |
4538 | /* In sync mode, when execute_control_command returns | |
4539 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4540 | Breakpoint commands for that stop were not run, since |
4541 | execute_command does not run breakpoint commands -- | |
4542 | only command_line_handler does, but that one is not | |
4543 | involved in execution of breakpoint commands. So, we | |
4544 | can now execute breakpoint commands. It should be | |
4545 | noted that making execute_command do bpstat actions is | |
4546 | not an option -- in this case we'll have recursive | |
4547 | invocation of bpstat for each breakpoint with a | |
4548 | command, and can easily blow up GDB stack. Instead, we | |
4549 | return true, which will trigger the caller to recall us | |
4550 | with the new stop_bpstat. */ | |
4551 | again = 1; | |
4552 | break; | |
32c1e744 | 4553 | } |
c906108c | 4554 | } |
c2b8ed2c | 4555 | do_cleanups (old_chain); |
347bddb7 PA |
4556 | return again; |
4557 | } | |
4558 | ||
4559 | void | |
4560 | bpstat_do_actions (void) | |
4561 | { | |
353d1d73 JK |
4562 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4563 | ||
347bddb7 PA |
4564 | /* Do any commands attached to breakpoint we are stopped at. */ |
4565 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4566 | && target_has_execution | |
4567 | && !is_exited (inferior_ptid) | |
4568 | && !is_executing (inferior_ptid)) | |
4569 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4570 | and only return when it is stopped at the next breakpoint, we | |
4571 | keep doing breakpoint actions until it returns false to | |
4572 | indicate the inferior was not resumed. */ | |
16c381f0 | 4573 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4574 | break; |
353d1d73 JK |
4575 | |
4576 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4577 | } |
4578 | ||
fa4727a6 DJ |
4579 | /* Print out the (old or new) value associated with a watchpoint. */ |
4580 | ||
4581 | static void | |
4582 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4583 | { | |
4584 | if (val == NULL) | |
4585 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4586 | else | |
79a45b7d TT |
4587 | { |
4588 | struct value_print_options opts; | |
4589 | get_user_print_options (&opts); | |
4590 | value_print (val, stream, &opts); | |
4591 | } | |
fa4727a6 DJ |
4592 | } |
4593 | ||
e514a9d6 | 4594 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4595 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4596 | 'print_it' in the bpstat structure. Under some circumstances we |
4597 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4598 | normal_stop(). */ |
e514a9d6 JM |
4599 | |
4600 | static enum print_stop_action | |
4601 | print_bp_stop_message (bpstat bs) | |
4602 | { | |
4603 | switch (bs->print_it) | |
4604 | { | |
4605 | case print_it_noop: | |
4a64f543 | 4606 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4607 | return PRINT_UNKNOWN; |
4608 | break; | |
4609 | ||
4610 | case print_it_done: | |
4611 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4612 | relevant messages. */ |
e514a9d6 JM |
4613 | return PRINT_SRC_AND_LOC; |
4614 | break; | |
4615 | ||
4616 | case print_it_normal: | |
4f8d1dc6 | 4617 | { |
f431efe5 PA |
4618 | struct breakpoint *b = bs->breakpoint_at; |
4619 | ||
1a6a67de TJB |
4620 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4621 | which has since been deleted. */ | |
4622 | if (b == NULL) | |
4623 | return PRINT_UNKNOWN; | |
4624 | ||
348d480f PA |
4625 | /* Normal case. Call the breakpoint's print_it method. */ |
4626 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4627 | } |
348d480f | 4628 | break; |
3086aeae | 4629 | |
e514a9d6 | 4630 | default: |
8e65ff28 | 4631 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4632 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4633 | break; |
c906108c | 4634 | } |
c906108c SS |
4635 | } |
4636 | ||
edcc5120 TT |
4637 | /* A helper function that prints a shared library stopped event. */ |
4638 | ||
4639 | static void | |
4640 | print_solib_event (int is_catchpoint) | |
4641 | { | |
4642 | int any_deleted | |
4643 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4644 | int any_added | |
4645 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4646 | ||
4647 | if (!is_catchpoint) | |
4648 | { | |
4649 | if (any_added || any_deleted) | |
4650 | ui_out_text (current_uiout, | |
4651 | _("Stopped due to shared library event:\n")); | |
4652 | else | |
4653 | ui_out_text (current_uiout, | |
4654 | _("Stopped due to shared library event (no " | |
4655 | "libraries added or removed)\n")); | |
4656 | } | |
4657 | ||
4658 | if (ui_out_is_mi_like_p (current_uiout)) | |
4659 | ui_out_field_string (current_uiout, "reason", | |
4660 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4661 | ||
4662 | if (any_deleted) | |
4663 | { | |
4664 | struct cleanup *cleanup; | |
4665 | char *name; | |
4666 | int ix; | |
4667 | ||
4668 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4669 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4670 | "removed"); | |
4671 | for (ix = 0; | |
4672 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4673 | ix, name); | |
4674 | ++ix) | |
4675 | { | |
4676 | if (ix > 0) | |
4677 | ui_out_text (current_uiout, " "); | |
4678 | ui_out_field_string (current_uiout, "library", name); | |
4679 | ui_out_text (current_uiout, "\n"); | |
4680 | } | |
4681 | ||
4682 | do_cleanups (cleanup); | |
4683 | } | |
4684 | ||
4685 | if (any_added) | |
4686 | { | |
4687 | struct so_list *iter; | |
4688 | int ix; | |
4689 | struct cleanup *cleanup; | |
4690 | ||
4691 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4692 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4693 | "added"); | |
4694 | for (ix = 0; | |
4695 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4696 | ix, iter); | |
4697 | ++ix) | |
4698 | { | |
4699 | if (ix > 0) | |
4700 | ui_out_text (current_uiout, " "); | |
4701 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4702 | ui_out_text (current_uiout, "\n"); | |
4703 | } | |
4704 | ||
4705 | do_cleanups (cleanup); | |
4706 | } | |
4707 | } | |
4708 | ||
e514a9d6 JM |
4709 | /* Print a message indicating what happened. This is called from |
4710 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4711 | list - a list of the eventpoints that caused this stop. KIND is |
4712 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4713 | routine calls the generic print routine for printing a message |
4714 | about reasons for stopping. This will print (for example) the | |
4715 | "Breakpoint n," part of the output. The return value of this | |
4716 | routine is one of: | |
c906108c | 4717 | |
4a64f543 | 4718 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4719 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4720 | code to print the location. An example is |
c5aa993b JM |
4721 | "Breakpoint 1, " which should be followed by |
4722 | the location. | |
917317f4 | 4723 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4724 | to also print the location part of the message. |
4725 | An example is the catch/throw messages, which | |
4a64f543 | 4726 | don't require a location appended to the end. |
917317f4 | 4727 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4728 | further info to be printed. */ |
c906108c | 4729 | |
917317f4 | 4730 | enum print_stop_action |
36dfb11c | 4731 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4732 | { |
4733 | int val; | |
c5aa993b | 4734 | |
c906108c | 4735 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4736 | (Currently all watchpoints go on the bpstat whether hit or not. |
4737 | That probably could (should) be changed, provided care is taken | |
c906108c | 4738 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4739 | for (; bs; bs = bs->next) |
4740 | { | |
4741 | val = print_bp_stop_message (bs); | |
4742 | if (val == PRINT_SRC_ONLY | |
4743 | || val == PRINT_SRC_AND_LOC | |
4744 | || val == PRINT_NOTHING) | |
4745 | return val; | |
4746 | } | |
c906108c | 4747 | |
36dfb11c TT |
4748 | /* If we had hit a shared library event breakpoint, |
4749 | print_bp_stop_message would print out this message. If we hit an | |
4750 | OS-level shared library event, do the same thing. */ | |
4751 | if (kind == TARGET_WAITKIND_LOADED) | |
4752 | { | |
edcc5120 | 4753 | print_solib_event (0); |
36dfb11c TT |
4754 | return PRINT_NOTHING; |
4755 | } | |
4756 | ||
e514a9d6 | 4757 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4758 | with and nothing was printed. */ |
917317f4 | 4759 | return PRINT_UNKNOWN; |
c906108c SS |
4760 | } |
4761 | ||
c42bd95a DE |
4762 | /* Evaluate the expression EXP and return 1 if value is zero. |
4763 | This returns the inverse of the condition because it is called | |
4764 | from catch_errors which returns 0 if an exception happened, and if an | |
4765 | exception happens we want execution to stop. | |
4a64f543 | 4766 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4767 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4768 | |
4769 | static int | |
4efb68b1 | 4770 | breakpoint_cond_eval (void *exp) |
c906108c | 4771 | { |
278cd55f | 4772 | struct value *mark = value_mark (); |
c5aa993b | 4773 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4774 | |
c906108c SS |
4775 | value_free_to_mark (mark); |
4776 | return i; | |
4777 | } | |
4778 | ||
5760d0ab | 4779 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4780 | |
4781 | static bpstat | |
5760d0ab | 4782 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4783 | { |
4784 | bpstat bs; | |
4785 | ||
4786 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4787 | bs->next = NULL; |
4788 | **bs_link_pointer = bs; | |
4789 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4790 | bs->breakpoint_at = bl->owner; |
4791 | bs->bp_location_at = bl; | |
4792 | incref_bp_location (bl); | |
c906108c SS |
4793 | /* If the condition is false, etc., don't do the commands. */ |
4794 | bs->commands = NULL; | |
4795 | bs->old_val = NULL; | |
4796 | bs->print_it = print_it_normal; | |
4797 | return bs; | |
4798 | } | |
4799 | \f | |
d983da9c DJ |
4800 | /* The target has stopped with waitstatus WS. Check if any hardware |
4801 | watchpoints have triggered, according to the target. */ | |
4802 | ||
4803 | int | |
4804 | watchpoints_triggered (struct target_waitstatus *ws) | |
4805 | { | |
d92524f1 | 4806 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4807 | CORE_ADDR addr; |
4808 | struct breakpoint *b; | |
4809 | ||
4810 | if (!stopped_by_watchpoint) | |
4811 | { | |
4812 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4813 | as not triggered. */ | |
4814 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4815 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4816 | { |
4817 | struct watchpoint *w = (struct watchpoint *) b; | |
4818 | ||
4819 | w->watchpoint_triggered = watch_triggered_no; | |
4820 | } | |
d983da9c DJ |
4821 | |
4822 | return 0; | |
4823 | } | |
4824 | ||
4825 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4826 | { | |
4827 | /* We were stopped by a watchpoint, but we don't know where. | |
4828 | Mark all watchpoints as unknown. */ | |
4829 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4830 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4831 | { |
4832 | struct watchpoint *w = (struct watchpoint *) b; | |
4833 | ||
4834 | w->watchpoint_triggered = watch_triggered_unknown; | |
4835 | } | |
d983da9c | 4836 | |
3c4797ba | 4837 | return 1; |
d983da9c DJ |
4838 | } |
4839 | ||
4840 | /* The target could report the data address. Mark watchpoints | |
4841 | affected by this data address as triggered, and all others as not | |
4842 | triggered. */ | |
4843 | ||
4844 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4845 | if (is_hardware_watchpoint (b)) |
d983da9c | 4846 | { |
3a5c3e22 | 4847 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4848 | struct bp_location *loc; |
d983da9c | 4849 | |
3a5c3e22 | 4850 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4851 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4852 | { |
3a5c3e22 | 4853 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4854 | { |
3a5c3e22 PA |
4855 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4856 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4857 | |
4858 | if (newaddr == start) | |
4859 | { | |
3a5c3e22 | 4860 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4861 | break; |
4862 | } | |
4863 | } | |
4864 | /* Exact match not required. Within range is sufficient. */ | |
4865 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4866 | addr, loc->address, | |
4867 | loc->length)) | |
4868 | { | |
3a5c3e22 | 4869 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4870 | break; |
4871 | } | |
4872 | } | |
d983da9c DJ |
4873 | } |
4874 | ||
4875 | return 1; | |
4876 | } | |
4877 | ||
c906108c SS |
4878 | /* Possible return values for watchpoint_check (this can't be an enum |
4879 | because of check_errors). */ | |
4880 | /* The watchpoint has been deleted. */ | |
4881 | #define WP_DELETED 1 | |
4882 | /* The value has changed. */ | |
4883 | #define WP_VALUE_CHANGED 2 | |
4884 | /* The value has not changed. */ | |
4885 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4886 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4887 | #define WP_IGNORE 4 | |
c906108c SS |
4888 | |
4889 | #define BP_TEMPFLAG 1 | |
4890 | #define BP_HARDWAREFLAG 2 | |
4891 | ||
4a64f543 MS |
4892 | /* Evaluate watchpoint condition expression and check if its value |
4893 | changed. | |
553e4c11 JB |
4894 | |
4895 | P should be a pointer to struct bpstat, but is defined as a void * | |
4896 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4897 | |
4898 | static int | |
4efb68b1 | 4899 | watchpoint_check (void *p) |
c906108c SS |
4900 | { |
4901 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4902 | struct watchpoint *b; |
c906108c SS |
4903 | struct frame_info *fr; |
4904 | int within_current_scope; | |
4905 | ||
f431efe5 | 4906 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4907 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4908 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4909 | |
f6bc2008 PA |
4910 | /* If this is a local watchpoint, we only want to check if the |
4911 | watchpoint frame is in scope if the current thread is the thread | |
4912 | that was used to create the watchpoint. */ | |
4913 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4914 | return WP_IGNORE; |
f6bc2008 | 4915 | |
c906108c SS |
4916 | if (b->exp_valid_block == NULL) |
4917 | within_current_scope = 1; | |
4918 | else | |
4919 | { | |
edb3359d DJ |
4920 | struct frame_info *frame = get_current_frame (); |
4921 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4922 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4923 | ||
4a64f543 MS |
4924 | /* in_function_epilogue_p() returns a non-zero value if we're |
4925 | still in the function but the stack frame has already been | |
4926 | invalidated. Since we can't rely on the values of local | |
4927 | variables after the stack has been destroyed, we are treating | |
4928 | the watchpoint in that state as `not changed' without further | |
4929 | checking. Don't mark watchpoints as changed if the current | |
4930 | frame is in an epilogue - even if they are in some other | |
4931 | frame, our view of the stack is likely to be wrong and | |
4932 | frame_find_by_id could error out. */ | |
a0f49112 | 4933 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4934 | return WP_IGNORE; |
a0f49112 | 4935 | |
101dcfbe | 4936 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4937 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4938 | |
4939 | /* If we've gotten confused in the unwinder, we might have | |
4940 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4941 | if (within_current_scope) |
4942 | { | |
4943 | struct symbol *function; | |
4944 | ||
4945 | function = get_frame_function (fr); | |
4946 | if (function == NULL | |
4947 | || !contained_in (b->exp_valid_block, | |
4948 | SYMBOL_BLOCK_VALUE (function))) | |
4949 | within_current_scope = 0; | |
4950 | } | |
69fbadd5 | 4951 | |
edb3359d | 4952 | if (within_current_scope) |
c906108c SS |
4953 | /* If we end up stopping, the current frame will get selected |
4954 | in normal_stop. So this call to select_frame won't affect | |
4955 | the user. */ | |
0f7d239c | 4956 | select_frame (fr); |
c906108c | 4957 | } |
c5aa993b | 4958 | |
c906108c SS |
4959 | if (within_current_scope) |
4960 | { | |
4a64f543 MS |
4961 | /* We use value_{,free_to_}mark because it could be a *long* |
4962 | time before we return to the command level and call | |
4963 | free_all_values. We can't call free_all_values because we | |
4964 | might be in the middle of evaluating a function call. */ | |
c906108c | 4965 | |
0cf6dd15 | 4966 | int pc = 0; |
9c06b0b4 | 4967 | struct value *mark; |
fa4727a6 DJ |
4968 | struct value *new_val; |
4969 | ||
3a5c3e22 | 4970 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4971 | /* Since we don't know the exact trigger address (from |
4972 | stopped_data_address), just tell the user we've triggered | |
4973 | a mask watchpoint. */ | |
4974 | return WP_VALUE_CHANGED; | |
4975 | ||
4976 | mark = value_mark (); | |
3a1115a0 | 4977 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4978 | |
4a64f543 MS |
4979 | /* We use value_equal_contents instead of value_equal because |
4980 | the latter coerces an array to a pointer, thus comparing just | |
4981 | the address of the array instead of its contents. This is | |
4982 | not what we want. */ | |
fa4727a6 | 4983 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4984 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4985 | { |
fa4727a6 DJ |
4986 | if (new_val != NULL) |
4987 | { | |
4988 | release_value (new_val); | |
4989 | value_free_to_mark (mark); | |
4990 | } | |
c906108c SS |
4991 | bs->old_val = b->val; |
4992 | b->val = new_val; | |
fa4727a6 | 4993 | b->val_valid = 1; |
c906108c SS |
4994 | return WP_VALUE_CHANGED; |
4995 | } | |
4996 | else | |
4997 | { | |
60e1c644 | 4998 | /* Nothing changed. */ |
c906108c | 4999 | value_free_to_mark (mark); |
c906108c SS |
5000 | return WP_VALUE_NOT_CHANGED; |
5001 | } | |
5002 | } | |
5003 | else | |
5004 | { | |
79a45e25 PA |
5005 | struct ui_out *uiout = current_uiout; |
5006 | ||
c906108c | 5007 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5008 | if we temporarily ignored the watchpoint, then when |
5009 | we reenter the block in which it is valid it contains | |
5010 | garbage (in the case of a function, it may have two | |
5011 | garbage values, one before and one after the prologue). | |
5012 | So we can't even detect the first assignment to it and | |
5013 | watch after that (since the garbage may or may not equal | |
5014 | the first value assigned). */ | |
348d480f PA |
5015 | /* We print all the stop information in |
5016 | breakpoint_ops->print_it, but in this case, by the time we | |
5017 | call breakpoint_ops->print_it this bp will be deleted | |
5018 | already. So we have no choice but print the information | |
5019 | here. */ | |
9dc5e2a9 | 5020 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5021 | ui_out_field_string |
5022 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5023 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5024 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5025 | ui_out_text (uiout, |
5026 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5027 | which its expression is valid.\n"); |
4ce44c66 | 5028 | |
cdac0397 | 5029 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5030 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5031 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5032 | |
5033 | return WP_DELETED; | |
5034 | } | |
5035 | } | |
5036 | ||
18a18393 | 5037 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5038 | breakpoint location BL. This function does not check if we should |
5039 | stop, only if BL explains the stop. */ | |
5040 | ||
18a18393 | 5041 | static int |
6c95b8df | 5042 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5043 | struct address_space *aspace, CORE_ADDR bp_addr, |
5044 | const struct target_waitstatus *ws) | |
18a18393 VP |
5045 | { |
5046 | struct breakpoint *b = bl->owner; | |
5047 | ||
348d480f | 5048 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5049 | gdb_assert (b != NULL); |
5050 | ||
09ac7c10 | 5051 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5052 | } |
5053 | ||
3a5c3e22 PA |
5054 | /* Determine if the watched values have actually changed, and we |
5055 | should stop. If not, set BS->stop to 0. */ | |
5056 | ||
18a18393 VP |
5057 | static void |
5058 | bpstat_check_watchpoint (bpstat bs) | |
5059 | { | |
2bdf28a0 | 5060 | const struct bp_location *bl; |
3a5c3e22 | 5061 | struct watchpoint *b; |
2bdf28a0 JK |
5062 | |
5063 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5064 | bl = bs->bp_location_at; |
2bdf28a0 | 5065 | gdb_assert (bl != NULL); |
3a5c3e22 | 5066 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5067 | gdb_assert (b != NULL); |
18a18393 | 5068 | |
18a18393 | 5069 | { |
18a18393 VP |
5070 | int must_check_value = 0; |
5071 | ||
3a5c3e22 | 5072 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5073 | /* For a software watchpoint, we must always check the |
5074 | watched value. */ | |
5075 | must_check_value = 1; | |
5076 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5077 | /* We have a hardware watchpoint (read, write, or access) | |
5078 | and the target earlier reported an address watched by | |
5079 | this watchpoint. */ | |
5080 | must_check_value = 1; | |
5081 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5082 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5083 | /* We were stopped by a hardware watchpoint, but the target could |
5084 | not report the data address. We must check the watchpoint's | |
5085 | value. Access and read watchpoints are out of luck; without | |
5086 | a data address, we can't figure it out. */ | |
5087 | must_check_value = 1; | |
3a5c3e22 | 5088 | |
18a18393 VP |
5089 | if (must_check_value) |
5090 | { | |
3e43a32a MS |
5091 | char *message |
5092 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5093 | b->base.number); |
18a18393 VP |
5094 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5095 | int e = catch_errors (watchpoint_check, bs, message, | |
5096 | RETURN_MASK_ALL); | |
5097 | do_cleanups (cleanups); | |
5098 | switch (e) | |
5099 | { | |
5100 | case WP_DELETED: | |
5101 | /* We've already printed what needs to be printed. */ | |
5102 | bs->print_it = print_it_done; | |
5103 | /* Stop. */ | |
5104 | break; | |
60e1c644 PA |
5105 | case WP_IGNORE: |
5106 | bs->print_it = print_it_noop; | |
5107 | bs->stop = 0; | |
5108 | break; | |
18a18393 | 5109 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5110 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5111 | { |
85d721b8 PA |
5112 | /* There are two cases to consider here: |
5113 | ||
4a64f543 | 5114 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5115 | In that case, trust the target, and always report |
5116 | the watchpoint hit to the user. Even though | |
5117 | reads don't cause value changes, the value may | |
5118 | have changed since the last time it was read, and | |
5119 | since we're not trapping writes, we will not see | |
5120 | those, and as such we should ignore our notion of | |
5121 | old value. | |
5122 | ||
4a64f543 | 5123 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5124 | reads and writes. There are two ways this may |
5125 | happen: | |
5126 | ||
4a64f543 | 5127 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5128 | reads only, but can break on accesses (reads or |
5129 | writes), such as e.g., x86. We detect this case | |
5130 | at the time we try to insert read watchpoints. | |
5131 | ||
4a64f543 | 5132 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5133 | watchpoints, but, the user set an access or write |
5134 | watchpoint watching the same memory as this read | |
5135 | watchpoint. | |
5136 | ||
5137 | If we're watching memory writes as well as reads, | |
5138 | ignore watchpoint hits when we find that the | |
5139 | value hasn't changed, as reads don't cause | |
5140 | changes. This still gives false positives when | |
5141 | the program writes the same value to memory as | |
5142 | what there was already in memory (we will confuse | |
5143 | it for a read), but it's much better than | |
5144 | nothing. */ | |
5145 | ||
5146 | int other_write_watchpoint = 0; | |
5147 | ||
5148 | if (bl->watchpoint_type == hw_read) | |
5149 | { | |
5150 | struct breakpoint *other_b; | |
5151 | ||
5152 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5153 | if (other_b->type == bp_hardware_watchpoint |
5154 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5155 | { |
3a5c3e22 PA |
5156 | struct watchpoint *other_w = |
5157 | (struct watchpoint *) other_b; | |
5158 | ||
5159 | if (other_w->watchpoint_triggered | |
5160 | == watch_triggered_yes) | |
5161 | { | |
5162 | other_write_watchpoint = 1; | |
5163 | break; | |
5164 | } | |
85d721b8 PA |
5165 | } |
5166 | } | |
5167 | ||
5168 | if (other_write_watchpoint | |
5169 | || bl->watchpoint_type == hw_access) | |
5170 | { | |
5171 | /* We're watching the same memory for writes, | |
5172 | and the value changed since the last time we | |
5173 | updated it, so this trap must be for a write. | |
5174 | Ignore it. */ | |
5175 | bs->print_it = print_it_noop; | |
5176 | bs->stop = 0; | |
5177 | } | |
18a18393 VP |
5178 | } |
5179 | break; | |
5180 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5181 | if (b->base.type == bp_hardware_watchpoint |
5182 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5183 | { |
5184 | /* Don't stop: write watchpoints shouldn't fire if | |
5185 | the value hasn't changed. */ | |
5186 | bs->print_it = print_it_noop; | |
5187 | bs->stop = 0; | |
5188 | } | |
5189 | /* Stop. */ | |
5190 | break; | |
5191 | default: | |
5192 | /* Can't happen. */ | |
5193 | case 0: | |
5194 | /* Error from catch_errors. */ | |
3a5c3e22 | 5195 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5196 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5197 | /* We've already printed what needs to be printed. */ |
5198 | bs->print_it = print_it_done; | |
5199 | break; | |
5200 | } | |
5201 | } | |
5202 | else /* must_check_value == 0 */ | |
5203 | { | |
5204 | /* This is a case where some watchpoint(s) triggered, but | |
5205 | not at the address of this watchpoint, or else no | |
5206 | watchpoint triggered after all. So don't print | |
5207 | anything for this watchpoint. */ | |
5208 | bs->print_it = print_it_noop; | |
5209 | bs->stop = 0; | |
5210 | } | |
5211 | } | |
5212 | } | |
5213 | ||
7d4df6a4 DE |
5214 | /* For breakpoints that are currently marked as telling gdb to stop, |
5215 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5216 | of breakpoint referred to by BS. If we should not stop for this |
5217 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5218 | |
18a18393 VP |
5219 | static void |
5220 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5221 | { | |
2bdf28a0 JK |
5222 | const struct bp_location *bl; |
5223 | struct breakpoint *b; | |
7d4df6a4 DE |
5224 | int value_is_zero = 0; |
5225 | struct expression *cond; | |
5226 | ||
5227 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5228 | |
5229 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5230 | bl = bs->bp_location_at; |
2bdf28a0 | 5231 | gdb_assert (bl != NULL); |
f431efe5 | 5232 | b = bs->breakpoint_at; |
2bdf28a0 | 5233 | gdb_assert (b != NULL); |
18a18393 | 5234 | |
b775012e LM |
5235 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5236 | need to do so again since GDB does not know if we stopped due to a | |
5237 | breakpoint or a single step breakpoint. */ | |
5238 | ||
18a18393 | 5239 | if (frame_id_p (b->frame_id) |
edb3359d | 5240 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5241 | { |
7d4df6a4 DE |
5242 | bs->stop = 0; |
5243 | return; | |
5244 | } | |
60e1c644 | 5245 | |
12ab52e9 PA |
5246 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5247 | evaluating the condition if this isn't the specified | |
5248 | thread/task. */ | |
5249 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5250 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5251 | ||
6c1b0f7b DE |
5252 | { |
5253 | bs->stop = 0; | |
5254 | return; | |
5255 | } | |
5256 | ||
6dddc817 DE |
5257 | /* Evaluate extension language breakpoints that have a "stop" method |
5258 | implemented. */ | |
5259 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5260 | |
7d4df6a4 DE |
5261 | if (is_watchpoint (b)) |
5262 | { | |
5263 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5264 | |
7d4df6a4 DE |
5265 | cond = w->cond_exp; |
5266 | } | |
5267 | else | |
5268 | cond = bl->cond; | |
60e1c644 | 5269 | |
7d4df6a4 DE |
5270 | if (cond && b->disposition != disp_del_at_next_stop) |
5271 | { | |
5272 | int within_current_scope = 1; | |
5273 | struct watchpoint * w; | |
60e1c644 | 5274 | |
7d4df6a4 DE |
5275 | /* We use value_mark and value_free_to_mark because it could |
5276 | be a long time before we return to the command level and | |
5277 | call free_all_values. We can't call free_all_values | |
5278 | because we might be in the middle of evaluating a | |
5279 | function call. */ | |
5280 | struct value *mark = value_mark (); | |
5281 | ||
5282 | if (is_watchpoint (b)) | |
5283 | w = (struct watchpoint *) b; | |
5284 | else | |
5285 | w = NULL; | |
5286 | ||
5287 | /* Need to select the frame, with all that implies so that | |
5288 | the conditions will have the right context. Because we | |
5289 | use the frame, we will not see an inlined function's | |
5290 | variables when we arrive at a breakpoint at the start | |
5291 | of the inlined function; the current frame will be the | |
5292 | call site. */ | |
5293 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5294 | select_frame (get_current_frame ()); | |
5295 | else | |
18a18393 | 5296 | { |
7d4df6a4 DE |
5297 | struct frame_info *frame; |
5298 | ||
5299 | /* For local watchpoint expressions, which particular | |
5300 | instance of a local is being watched matters, so we | |
5301 | keep track of the frame to evaluate the expression | |
5302 | in. To evaluate the condition however, it doesn't | |
5303 | really matter which instantiation of the function | |
5304 | where the condition makes sense triggers the | |
5305 | watchpoint. This allows an expression like "watch | |
5306 | global if q > 10" set in `func', catch writes to | |
5307 | global on all threads that call `func', or catch | |
5308 | writes on all recursive calls of `func' by a single | |
5309 | thread. We simply always evaluate the condition in | |
5310 | the innermost frame that's executing where it makes | |
5311 | sense to evaluate the condition. It seems | |
5312 | intuitive. */ | |
5313 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5314 | if (frame != NULL) | |
5315 | select_frame (frame); | |
5316 | else | |
5317 | within_current_scope = 0; | |
18a18393 | 5318 | } |
7d4df6a4 DE |
5319 | if (within_current_scope) |
5320 | value_is_zero | |
5321 | = catch_errors (breakpoint_cond_eval, cond, | |
5322 | "Error in testing breakpoint condition:\n", | |
5323 | RETURN_MASK_ALL); | |
5324 | else | |
18a18393 | 5325 | { |
7d4df6a4 DE |
5326 | warning (_("Watchpoint condition cannot be tested " |
5327 | "in the current scope")); | |
5328 | /* If we failed to set the right context for this | |
5329 | watchpoint, unconditionally report it. */ | |
5330 | value_is_zero = 0; | |
18a18393 | 5331 | } |
7d4df6a4 DE |
5332 | /* FIXME-someday, should give breakpoint #. */ |
5333 | value_free_to_mark (mark); | |
18a18393 | 5334 | } |
7d4df6a4 DE |
5335 | |
5336 | if (cond && value_is_zero) | |
5337 | { | |
5338 | bs->stop = 0; | |
5339 | } | |
7d4df6a4 DE |
5340 | else if (b->ignore_count > 0) |
5341 | { | |
5342 | b->ignore_count--; | |
5343 | bs->stop = 0; | |
5344 | /* Increase the hit count even though we don't stop. */ | |
5345 | ++(b->hit_count); | |
5346 | observer_notify_breakpoint_modified (b); | |
5347 | } | |
18a18393 VP |
5348 | } |
5349 | ||
5350 | ||
9709f61c | 5351 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5352 | BP_ADDR in thread PTID. |
c906108c | 5353 | |
d983da9c | 5354 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5355 | don't understand this stop. Result is a chain of bpstat's such |
5356 | that: | |
c906108c | 5357 | |
c5aa993b | 5358 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5359 | |
c5aa993b | 5360 | if we understand why we stopped, the result is not null. |
c906108c | 5361 | |
c5aa993b JM |
5362 | Each element of the chain refers to a particular breakpoint or |
5363 | watchpoint at which we have stopped. (We may have stopped for | |
5364 | several reasons concurrently.) | |
c906108c | 5365 | |
c5aa993b JM |
5366 | Each element of the chain has valid next, breakpoint_at, |
5367 | commands, FIXME??? fields. */ | |
c906108c SS |
5368 | |
5369 | bpstat | |
6c95b8df | 5370 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5371 | CORE_ADDR bp_addr, ptid_t ptid, |
5372 | const struct target_waitstatus *ws) | |
c906108c | 5373 | { |
0d381245 | 5374 | struct breakpoint *b = NULL; |
afe38095 | 5375 | struct bp_location *bl; |
20874c92 | 5376 | struct bp_location *loc; |
5760d0ab JK |
5377 | /* First item of allocated bpstat's. */ |
5378 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5379 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5380 | bpstat bs; |
20874c92 | 5381 | int ix; |
429374b8 | 5382 | int need_remove_insert; |
f431efe5 | 5383 | int removed_any; |
c906108c | 5384 | |
f431efe5 PA |
5385 | /* First, build the bpstat chain with locations that explain a |
5386 | target stop, while being careful to not set the target running, | |
5387 | as that may invalidate locations (in particular watchpoint | |
5388 | locations are recreated). Resuming will happen here with | |
5389 | breakpoint conditions or watchpoint expressions that include | |
5390 | inferior function calls. */ | |
c5aa993b | 5391 | |
429374b8 JK |
5392 | ALL_BREAKPOINTS (b) |
5393 | { | |
5394 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5395 | continue; | |
a5606eee | 5396 | |
429374b8 JK |
5397 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5398 | { | |
4a64f543 MS |
5399 | /* For hardware watchpoints, we look only at the first |
5400 | location. The watchpoint_check function will work on the | |
5401 | entire expression, not the individual locations. For | |
5402 | read watchpoints, the watchpoints_triggered function has | |
5403 | checked all locations already. */ | |
429374b8 JK |
5404 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5405 | break; | |
18a18393 | 5406 | |
f6592439 | 5407 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5408 | continue; |
c5aa993b | 5409 | |
09ac7c10 | 5410 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5411 | continue; |
c5aa993b | 5412 | |
4a64f543 MS |
5413 | /* Come here if it's a watchpoint, or if the break address |
5414 | matches. */ | |
c5aa993b | 5415 | |
4a64f543 MS |
5416 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5417 | explain stop. */ | |
c5aa993b | 5418 | |
f431efe5 PA |
5419 | /* Assume we stop. Should we find a watchpoint that is not |
5420 | actually triggered, or if the condition of the breakpoint | |
5421 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5422 | bs->stop = 1; |
5423 | bs->print = 1; | |
d983da9c | 5424 | |
f431efe5 PA |
5425 | /* If this is a scope breakpoint, mark the associated |
5426 | watchpoint as triggered so that we will handle the | |
5427 | out-of-scope event. We'll get to the watchpoint next | |
5428 | iteration. */ | |
d0fb5eae | 5429 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5430 | { |
5431 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5432 | ||
5433 | w->watchpoint_triggered = watch_triggered_yes; | |
5434 | } | |
f431efe5 PA |
5435 | } |
5436 | } | |
5437 | ||
5438 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5439 | { | |
f1310107 | 5440 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5441 | { |
5760d0ab | 5442 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5443 | /* For hits of moribund locations, we should just proceed. */ |
5444 | bs->stop = 0; | |
5445 | bs->print = 0; | |
5446 | bs->print_it = print_it_noop; | |
5447 | } | |
5448 | } | |
5449 | ||
edcc5120 TT |
5450 | /* A bit of special processing for shlib breakpoints. We need to |
5451 | process solib loading here, so that the lists of loaded and | |
5452 | unloaded libraries are correct before we handle "catch load" and | |
5453 | "catch unload". */ | |
5454 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5455 | { | |
5d268276 | 5456 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5457 | { |
5458 | handle_solib_event (); | |
5459 | break; | |
5460 | } | |
5461 | } | |
5462 | ||
f431efe5 PA |
5463 | /* Now go through the locations that caused the target to stop, and |
5464 | check whether we're interested in reporting this stop to higher | |
5465 | layers, or whether we should resume the target transparently. */ | |
5466 | ||
5467 | removed_any = 0; | |
5468 | ||
5760d0ab | 5469 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5470 | { |
5471 | if (!bs->stop) | |
5472 | continue; | |
5473 | ||
f431efe5 | 5474 | b = bs->breakpoint_at; |
348d480f PA |
5475 | b->ops->check_status (bs); |
5476 | if (bs->stop) | |
28010a5d | 5477 | { |
348d480f | 5478 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5479 | |
429374b8 JK |
5480 | if (bs->stop) |
5481 | { | |
5482 | ++(b->hit_count); | |
8d3788bd | 5483 | observer_notify_breakpoint_modified (b); |
c906108c | 5484 | |
4a64f543 | 5485 | /* We will stop here. */ |
429374b8 JK |
5486 | if (b->disposition == disp_disable) |
5487 | { | |
816338b5 SS |
5488 | --(b->enable_count); |
5489 | if (b->enable_count <= 0 | |
5490 | && b->enable_state != bp_permanent) | |
429374b8 | 5491 | b->enable_state = bp_disabled; |
f431efe5 | 5492 | removed_any = 1; |
429374b8 JK |
5493 | } |
5494 | if (b->silent) | |
5495 | bs->print = 0; | |
5496 | bs->commands = b->commands; | |
9add0f1b | 5497 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5498 | if (command_line_is_silent (bs->commands |
5499 | ? bs->commands->commands : NULL)) | |
5500 | bs->print = 0; | |
9d6e6e84 HZ |
5501 | |
5502 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5503 | } |
5504 | ||
348d480f | 5505 | } |
a9b3a50f PA |
5506 | |
5507 | /* Print nothing for this entry if we don't stop or don't | |
5508 | print. */ | |
5509 | if (!bs->stop || !bs->print) | |
5510 | bs->print_it = print_it_noop; | |
429374b8 | 5511 | } |
876fa593 | 5512 | |
d983da9c DJ |
5513 | /* If we aren't stopping, the value of some hardware watchpoint may |
5514 | not have changed, but the intermediate memory locations we are | |
5515 | watching may have. Don't bother if we're stopping; this will get | |
5516 | done later. */ | |
d832cb68 | 5517 | need_remove_insert = 0; |
5760d0ab JK |
5518 | if (! bpstat_causes_stop (bs_head)) |
5519 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5520 | if (!bs->stop |
f431efe5 PA |
5521 | && bs->breakpoint_at |
5522 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5523 | { |
3a5c3e22 PA |
5524 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5525 | ||
5526 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5527 | need_remove_insert = 1; |
d983da9c DJ |
5528 | } |
5529 | ||
d832cb68 | 5530 | if (need_remove_insert) |
2d134ed3 | 5531 | update_global_location_list (1); |
f431efe5 PA |
5532 | else if (removed_any) |
5533 | update_global_location_list (0); | |
d832cb68 | 5534 | |
5760d0ab | 5535 | return bs_head; |
c906108c | 5536 | } |
628fe4e4 JK |
5537 | |
5538 | static void | |
5539 | handle_jit_event (void) | |
5540 | { | |
5541 | struct frame_info *frame; | |
5542 | struct gdbarch *gdbarch; | |
5543 | ||
5544 | /* Switch terminal for any messages produced by | |
5545 | breakpoint_re_set. */ | |
5546 | target_terminal_ours_for_output (); | |
5547 | ||
5548 | frame = get_current_frame (); | |
5549 | gdbarch = get_frame_arch (frame); | |
5550 | ||
5551 | jit_event_handler (gdbarch); | |
5552 | ||
5553 | target_terminal_inferior (); | |
5554 | } | |
5555 | ||
5556 | /* Prepare WHAT final decision for infrun. */ | |
5557 | ||
5558 | /* Decide what infrun needs to do with this bpstat. */ | |
5559 | ||
c906108c | 5560 | struct bpstat_what |
0e30163f | 5561 | bpstat_what (bpstat bs_head) |
c906108c | 5562 | { |
c906108c | 5563 | struct bpstat_what retval; |
628fe4e4 | 5564 | int jit_event = 0; |
0e30163f | 5565 | bpstat bs; |
c906108c | 5566 | |
628fe4e4 | 5567 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5568 | retval.call_dummy = STOP_NONE; |
186c406b | 5569 | retval.is_longjmp = 0; |
628fe4e4 | 5570 | |
0e30163f | 5571 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5572 | { |
628fe4e4 JK |
5573 | /* Extract this BS's action. After processing each BS, we check |
5574 | if its action overrides all we've seem so far. */ | |
5575 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5576 | enum bptype bptype; | |
5577 | ||
c906108c | 5578 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5579 | { |
5580 | /* I suspect this can happen if it was a momentary | |
5581 | breakpoint which has since been deleted. */ | |
5582 | bptype = bp_none; | |
5583 | } | |
20874c92 | 5584 | else |
f431efe5 | 5585 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5586 | |
5587 | switch (bptype) | |
c906108c SS |
5588 | { |
5589 | case bp_none: | |
628fe4e4 | 5590 | break; |
c906108c SS |
5591 | case bp_breakpoint: |
5592 | case bp_hardware_breakpoint: | |
5593 | case bp_until: | |
5594 | case bp_finish: | |
a9b3a50f | 5595 | case bp_shlib_event: |
c906108c SS |
5596 | if (bs->stop) |
5597 | { | |
5598 | if (bs->print) | |
628fe4e4 | 5599 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5600 | else |
628fe4e4 | 5601 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5602 | } |
5603 | else | |
628fe4e4 | 5604 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5605 | break; |
5606 | case bp_watchpoint: | |
5607 | case bp_hardware_watchpoint: | |
5608 | case bp_read_watchpoint: | |
5609 | case bp_access_watchpoint: | |
5610 | if (bs->stop) | |
5611 | { | |
5612 | if (bs->print) | |
628fe4e4 | 5613 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5614 | else |
628fe4e4 | 5615 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5616 | } |
5617 | else | |
628fe4e4 JK |
5618 | { |
5619 | /* There was a watchpoint, but we're not stopping. | |
5620 | This requires no further action. */ | |
5621 | } | |
c906108c SS |
5622 | break; |
5623 | case bp_longjmp: | |
e2e4d78b | 5624 | case bp_longjmp_call_dummy: |
186c406b | 5625 | case bp_exception: |
628fe4e4 | 5626 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5627 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5628 | break; |
5629 | case bp_longjmp_resume: | |
186c406b | 5630 | case bp_exception_resume: |
628fe4e4 | 5631 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5632 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5633 | break; |
5634 | case bp_step_resume: | |
5635 | if (bs->stop) | |
628fe4e4 JK |
5636 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5637 | else | |
c906108c | 5638 | { |
628fe4e4 JK |
5639 | /* It is for the wrong frame. */ |
5640 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5641 | } |
c906108c | 5642 | break; |
2c03e5be PA |
5643 | case bp_hp_step_resume: |
5644 | if (bs->stop) | |
5645 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5646 | else | |
5647 | { | |
5648 | /* It is for the wrong frame. */ | |
5649 | this_action = BPSTAT_WHAT_SINGLE; | |
5650 | } | |
5651 | break; | |
c906108c | 5652 | case bp_watchpoint_scope: |
c4093a6a | 5653 | case bp_thread_event: |
1900040c | 5654 | case bp_overlay_event: |
0fd8e87f | 5655 | case bp_longjmp_master: |
aa7d318d | 5656 | case bp_std_terminate_master: |
186c406b | 5657 | case bp_exception_master: |
628fe4e4 | 5658 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5659 | break; |
ce78b96d | 5660 | case bp_catchpoint: |
c5aa993b JM |
5661 | if (bs->stop) |
5662 | { | |
5663 | if (bs->print) | |
628fe4e4 | 5664 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5665 | else |
628fe4e4 | 5666 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5667 | } |
5668 | else | |
628fe4e4 JK |
5669 | { |
5670 | /* There was a catchpoint, but we're not stopping. | |
5671 | This requires no further action. */ | |
5672 | } | |
5673 | break; | |
628fe4e4 JK |
5674 | case bp_jit_event: |
5675 | jit_event = 1; | |
5676 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5677 | break; |
c906108c | 5678 | case bp_call_dummy: |
53a5351d JM |
5679 | /* Make sure the action is stop (silent or noisy), |
5680 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5681 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5682 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5683 | break; |
5684 | case bp_std_terminate: | |
5685 | /* Make sure the action is stop (silent or noisy), | |
5686 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5687 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5688 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5689 | break; |
1042e4c0 | 5690 | case bp_tracepoint: |
7a697b8d | 5691 | case bp_fast_tracepoint: |
0fb4aa4b | 5692 | case bp_static_tracepoint: |
1042e4c0 SS |
5693 | /* Tracepoint hits should not be reported back to GDB, and |
5694 | if one got through somehow, it should have been filtered | |
5695 | out already. */ | |
5696 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5697 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5698 | break; |
5699 | case bp_gnu_ifunc_resolver: | |
5700 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5701 | this_action = BPSTAT_WHAT_SINGLE; | |
5702 | break; | |
5703 | case bp_gnu_ifunc_resolver_return: | |
5704 | /* The breakpoint will be removed, execution will restart from the | |
5705 | PC of the former breakpoint. */ | |
5706 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5707 | break; | |
e7e0cddf SS |
5708 | |
5709 | case bp_dprintf: | |
a11cfd87 HZ |
5710 | if (bs->stop) |
5711 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5712 | else | |
5713 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5714 | break; |
5715 | ||
628fe4e4 JK |
5716 | default: |
5717 | internal_error (__FILE__, __LINE__, | |
5718 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5719 | } |
628fe4e4 JK |
5720 | |
5721 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5722 | } |
628fe4e4 | 5723 | |
0e30163f JK |
5724 | /* These operations may affect the bs->breakpoint_at state so they are |
5725 | delayed after MAIN_ACTION is decided above. */ | |
5726 | ||
628fe4e4 JK |
5727 | if (jit_event) |
5728 | { | |
5729 | if (debug_infrun) | |
5730 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5731 | ||
5732 | handle_jit_event (); | |
5733 | } | |
5734 | ||
0e30163f JK |
5735 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5736 | { | |
5737 | struct breakpoint *b = bs->breakpoint_at; | |
5738 | ||
5739 | if (b == NULL) | |
5740 | continue; | |
5741 | switch (b->type) | |
5742 | { | |
5743 | case bp_gnu_ifunc_resolver: | |
5744 | gnu_ifunc_resolver_stop (b); | |
5745 | break; | |
5746 | case bp_gnu_ifunc_resolver_return: | |
5747 | gnu_ifunc_resolver_return_stop (b); | |
5748 | break; | |
5749 | } | |
5750 | } | |
5751 | ||
c906108c SS |
5752 | return retval; |
5753 | } | |
5754 | ||
5755 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5756 | without hardware support). This isn't related to a specific bpstat, | |
5757 | just to things like whether watchpoints are set. */ | |
5758 | ||
c5aa993b | 5759 | int |
fba45db2 | 5760 | bpstat_should_step (void) |
c906108c SS |
5761 | { |
5762 | struct breakpoint *b; | |
cc59ec59 | 5763 | |
c906108c | 5764 | ALL_BREAKPOINTS (b) |
717a8278 | 5765 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5766 | return 1; |
c906108c SS |
5767 | return 0; |
5768 | } | |
5769 | ||
67822962 PA |
5770 | int |
5771 | bpstat_causes_stop (bpstat bs) | |
5772 | { | |
5773 | for (; bs != NULL; bs = bs->next) | |
5774 | if (bs->stop) | |
5775 | return 1; | |
5776 | ||
5777 | return 0; | |
5778 | } | |
5779 | ||
c906108c | 5780 | \f |
c5aa993b | 5781 | |
170b53b2 UW |
5782 | /* Compute a string of spaces suitable to indent the next line |
5783 | so it starts at the position corresponding to the table column | |
5784 | named COL_NAME in the currently active table of UIOUT. */ | |
5785 | ||
5786 | static char * | |
5787 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5788 | { | |
5789 | static char wrap_indent[80]; | |
5790 | int i, total_width, width, align; | |
5791 | char *text; | |
5792 | ||
5793 | total_width = 0; | |
5794 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5795 | { | |
5796 | if (strcmp (text, col_name) == 0) | |
5797 | { | |
5798 | gdb_assert (total_width < sizeof wrap_indent); | |
5799 | memset (wrap_indent, ' ', total_width); | |
5800 | wrap_indent[total_width] = 0; | |
5801 | ||
5802 | return wrap_indent; | |
5803 | } | |
5804 | ||
5805 | total_width += width + 1; | |
5806 | } | |
5807 | ||
5808 | return NULL; | |
5809 | } | |
5810 | ||
b775012e LM |
5811 | /* Determine if the locations of this breakpoint will have their conditions |
5812 | evaluated by the target, host or a mix of both. Returns the following: | |
5813 | ||
5814 | "host": Host evals condition. | |
5815 | "host or target": Host or Target evals condition. | |
5816 | "target": Target evals condition. | |
5817 | */ | |
5818 | ||
5819 | static const char * | |
5820 | bp_condition_evaluator (struct breakpoint *b) | |
5821 | { | |
5822 | struct bp_location *bl; | |
5823 | char host_evals = 0; | |
5824 | char target_evals = 0; | |
5825 | ||
5826 | if (!b) | |
5827 | return NULL; | |
5828 | ||
5829 | if (!is_breakpoint (b)) | |
5830 | return NULL; | |
5831 | ||
5832 | if (gdb_evaluates_breakpoint_condition_p () | |
5833 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5834 | return condition_evaluation_host; | |
5835 | ||
5836 | for (bl = b->loc; bl; bl = bl->next) | |
5837 | { | |
5838 | if (bl->cond_bytecode) | |
5839 | target_evals++; | |
5840 | else | |
5841 | host_evals++; | |
5842 | } | |
5843 | ||
5844 | if (host_evals && target_evals) | |
5845 | return condition_evaluation_both; | |
5846 | else if (target_evals) | |
5847 | return condition_evaluation_target; | |
5848 | else | |
5849 | return condition_evaluation_host; | |
5850 | } | |
5851 | ||
5852 | /* Determine the breakpoint location's condition evaluator. This is | |
5853 | similar to bp_condition_evaluator, but for locations. */ | |
5854 | ||
5855 | static const char * | |
5856 | bp_location_condition_evaluator (struct bp_location *bl) | |
5857 | { | |
5858 | if (bl && !is_breakpoint (bl->owner)) | |
5859 | return NULL; | |
5860 | ||
5861 | if (gdb_evaluates_breakpoint_condition_p () | |
5862 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5863 | return condition_evaluation_host; | |
5864 | ||
5865 | if (bl && bl->cond_bytecode) | |
5866 | return condition_evaluation_target; | |
5867 | else | |
5868 | return condition_evaluation_host; | |
5869 | } | |
5870 | ||
859825b8 JK |
5871 | /* Print the LOC location out of the list of B->LOC locations. */ |
5872 | ||
170b53b2 UW |
5873 | static void |
5874 | print_breakpoint_location (struct breakpoint *b, | |
5875 | struct bp_location *loc) | |
0d381245 | 5876 | { |
79a45e25 | 5877 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5878 | struct cleanup *old_chain = save_current_program_space (); |
5879 | ||
859825b8 JK |
5880 | if (loc != NULL && loc->shlib_disabled) |
5881 | loc = NULL; | |
5882 | ||
6c95b8df PA |
5883 | if (loc != NULL) |
5884 | set_current_program_space (loc->pspace); | |
5885 | ||
56435ebe TT |
5886 | if (b->display_canonical) |
5887 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5888 | else if (loc && loc->symtab) |
0d381245 VP |
5889 | { |
5890 | struct symbol *sym | |
5891 | = find_pc_sect_function (loc->address, loc->section); | |
5892 | if (sym) | |
5893 | { | |
5894 | ui_out_text (uiout, "in "); | |
5895 | ui_out_field_string (uiout, "func", | |
5896 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5897 | ui_out_text (uiout, " "); |
5898 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5899 | ui_out_text (uiout, "at "); | |
0d381245 | 5900 | } |
05cba821 JK |
5901 | ui_out_field_string (uiout, "file", |
5902 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5903 | ui_out_text (uiout, ":"); |
05cba821 | 5904 | |
0d381245 | 5905 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5906 | ui_out_field_string (uiout, "fullname", |
5907 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5908 | |
f8eba3c6 | 5909 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5910 | } |
859825b8 | 5911 | else if (loc) |
0d381245 | 5912 | { |
f99d8bf4 PA |
5913 | struct ui_file *stb = mem_fileopen (); |
5914 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5915 | |
f99d8bf4 | 5916 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5917 | demangle, ""); |
0d381245 | 5918 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5919 | |
5920 | do_cleanups (stb_chain); | |
0d381245 | 5921 | } |
859825b8 JK |
5922 | else |
5923 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5924 | |
b775012e LM |
5925 | if (loc && is_breakpoint (b) |
5926 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5927 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5928 | { | |
5929 | ui_out_text (uiout, " ("); | |
5930 | ui_out_field_string (uiout, "evaluated-by", | |
5931 | bp_location_condition_evaluator (loc)); | |
5932 | ui_out_text (uiout, ")"); | |
5933 | } | |
5934 | ||
6c95b8df | 5935 | do_cleanups (old_chain); |
0d381245 VP |
5936 | } |
5937 | ||
269b11a2 PA |
5938 | static const char * |
5939 | bptype_string (enum bptype type) | |
c906108c | 5940 | { |
c4093a6a JM |
5941 | struct ep_type_description |
5942 | { | |
5943 | enum bptype type; | |
5944 | char *description; | |
5945 | }; | |
5946 | static struct ep_type_description bptypes[] = | |
c906108c | 5947 | { |
c5aa993b JM |
5948 | {bp_none, "?deleted?"}, |
5949 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5950 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5951 | {bp_until, "until"}, |
5952 | {bp_finish, "finish"}, | |
5953 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5954 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5955 | {bp_read_watchpoint, "read watchpoint"}, |
5956 | {bp_access_watchpoint, "acc watchpoint"}, | |
5957 | {bp_longjmp, "longjmp"}, | |
5958 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5959 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5960 | {bp_exception, "exception"}, |
5961 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5962 | {bp_step_resume, "step resume"}, |
2c03e5be | 5963 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5964 | {bp_watchpoint_scope, "watchpoint scope"}, |
5965 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5966 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5967 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5968 | {bp_thread_event, "thread events"}, |
1900040c | 5969 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5970 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5971 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5972 | {bp_exception_master, "exception master"}, |
ce78b96d | 5973 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5974 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5975 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5976 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5977 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5978 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5979 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5980 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5981 | }; |
269b11a2 PA |
5982 | |
5983 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5984 | || ((int) type != bptypes[(int) type].type)) | |
5985 | internal_error (__FILE__, __LINE__, | |
5986 | _("bptypes table does not describe type #%d."), | |
5987 | (int) type); | |
5988 | ||
5989 | return bptypes[(int) type].description; | |
5990 | } | |
5991 | ||
998580f1 MK |
5992 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5993 | For CLI, prefix the list with the string 'inf'. */ | |
5994 | ||
5995 | static void | |
5996 | output_thread_groups (struct ui_out *uiout, | |
5997 | const char *field_name, | |
5998 | VEC(int) *inf_num, | |
5999 | int mi_only) | |
6000 | { | |
752eb8b4 | 6001 | struct cleanup *back_to; |
998580f1 MK |
6002 | int is_mi = ui_out_is_mi_like_p (uiout); |
6003 | int inf; | |
6004 | int i; | |
6005 | ||
6006 | /* For backward compatibility, don't display inferiors in CLI unless | |
6007 | there are several. Always display them for MI. */ | |
6008 | if (!is_mi && mi_only) | |
6009 | return; | |
6010 | ||
752eb8b4 TT |
6011 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6012 | ||
998580f1 MK |
6013 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6014 | { | |
6015 | if (is_mi) | |
6016 | { | |
6017 | char mi_group[10]; | |
6018 | ||
6019 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6020 | ui_out_field_string (uiout, NULL, mi_group); | |
6021 | } | |
6022 | else | |
6023 | { | |
6024 | if (i == 0) | |
6025 | ui_out_text (uiout, " inf "); | |
6026 | else | |
6027 | ui_out_text (uiout, ", "); | |
6028 | ||
6029 | ui_out_text (uiout, plongest (inf)); | |
6030 | } | |
6031 | } | |
6032 | ||
6033 | do_cleanups (back_to); | |
6034 | } | |
6035 | ||
269b11a2 PA |
6036 | /* Print B to gdb_stdout. */ |
6037 | ||
6038 | static void | |
6039 | print_one_breakpoint_location (struct breakpoint *b, | |
6040 | struct bp_location *loc, | |
6041 | int loc_number, | |
6042 | struct bp_location **last_loc, | |
269b11a2 PA |
6043 | int allflag) |
6044 | { | |
6045 | struct command_line *l; | |
c2c6d25f | 6046 | static char bpenables[] = "nynny"; |
c906108c | 6047 | |
79a45e25 | 6048 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6049 | int header_of_multiple = 0; |
6050 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6051 | struct value_print_options opts; |
6052 | ||
6053 | get_user_print_options (&opts); | |
0d381245 VP |
6054 | |
6055 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6056 | /* See comment in print_one_breakpoint concerning treatment of |
6057 | breakpoints with single disabled location. */ | |
0d381245 VP |
6058 | if (loc == NULL |
6059 | && (b->loc != NULL | |
6060 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6061 | header_of_multiple = 1; | |
6062 | if (loc == NULL) | |
6063 | loc = b->loc; | |
6064 | ||
c4093a6a JM |
6065 | annotate_record (); |
6066 | ||
6067 | /* 1 */ | |
6068 | annotate_field (0); | |
0d381245 VP |
6069 | if (part_of_multiple) |
6070 | { | |
6071 | char *formatted; | |
0c6773c1 | 6072 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6073 | ui_out_field_string (uiout, "number", formatted); |
6074 | xfree (formatted); | |
6075 | } | |
6076 | else | |
6077 | { | |
6078 | ui_out_field_int (uiout, "number", b->number); | |
6079 | } | |
c4093a6a JM |
6080 | |
6081 | /* 2 */ | |
6082 | annotate_field (1); | |
0d381245 VP |
6083 | if (part_of_multiple) |
6084 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6085 | else |
6086 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6087 | |
6088 | /* 3 */ | |
6089 | annotate_field (2); | |
0d381245 VP |
6090 | if (part_of_multiple) |
6091 | ui_out_field_skip (uiout, "disp"); | |
6092 | else | |
2cec12e5 | 6093 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6094 | |
c4093a6a JM |
6095 | |
6096 | /* 4 */ | |
6097 | annotate_field (3); | |
0d381245 | 6098 | if (part_of_multiple) |
54e52265 | 6099 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6100 | else |
4a64f543 MS |
6101 | ui_out_field_fmt (uiout, "enabled", "%c", |
6102 | bpenables[(int) b->enable_state]); | |
54e52265 | 6103 | ui_out_spaces (uiout, 2); |
0d381245 | 6104 | |
c4093a6a JM |
6105 | |
6106 | /* 5 and 6 */ | |
3086aeae | 6107 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6108 | { |
4a64f543 MS |
6109 | /* Although the print_one can possibly print all locations, |
6110 | calling it here is not likely to get any nice result. So, | |
6111 | make sure there's just one location. */ | |
0d381245 | 6112 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6113 | b->ops->print_one (b, last_loc); |
0d381245 | 6114 | } |
3086aeae DJ |
6115 | else |
6116 | switch (b->type) | |
6117 | { | |
6118 | case bp_none: | |
6119 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6120 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6121 | break; |
c906108c | 6122 | |
3086aeae DJ |
6123 | case bp_watchpoint: |
6124 | case bp_hardware_watchpoint: | |
6125 | case bp_read_watchpoint: | |
6126 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6127 | { |
6128 | struct watchpoint *w = (struct watchpoint *) b; | |
6129 | ||
6130 | /* Field 4, the address, is omitted (which makes the columns | |
6131 | not line up too nicely with the headers, but the effect | |
6132 | is relatively readable). */ | |
6133 | if (opts.addressprint) | |
6134 | ui_out_field_skip (uiout, "addr"); | |
6135 | annotate_field (5); | |
6136 | ui_out_field_string (uiout, "what", w->exp_string); | |
6137 | } | |
3086aeae DJ |
6138 | break; |
6139 | ||
3086aeae DJ |
6140 | case bp_breakpoint: |
6141 | case bp_hardware_breakpoint: | |
6142 | case bp_until: | |
6143 | case bp_finish: | |
6144 | case bp_longjmp: | |
6145 | case bp_longjmp_resume: | |
e2e4d78b | 6146 | case bp_longjmp_call_dummy: |
186c406b TT |
6147 | case bp_exception: |
6148 | case bp_exception_resume: | |
3086aeae | 6149 | case bp_step_resume: |
2c03e5be | 6150 | case bp_hp_step_resume: |
3086aeae DJ |
6151 | case bp_watchpoint_scope: |
6152 | case bp_call_dummy: | |
aa7d318d | 6153 | case bp_std_terminate: |
3086aeae DJ |
6154 | case bp_shlib_event: |
6155 | case bp_thread_event: | |
6156 | case bp_overlay_event: | |
0fd8e87f | 6157 | case bp_longjmp_master: |
aa7d318d | 6158 | case bp_std_terminate_master: |
186c406b | 6159 | case bp_exception_master: |
1042e4c0 | 6160 | case bp_tracepoint: |
7a697b8d | 6161 | case bp_fast_tracepoint: |
0fb4aa4b | 6162 | case bp_static_tracepoint: |
e7e0cddf | 6163 | case bp_dprintf: |
4efc6507 | 6164 | case bp_jit_event: |
0e30163f JK |
6165 | case bp_gnu_ifunc_resolver: |
6166 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6167 | if (opts.addressprint) |
3086aeae DJ |
6168 | { |
6169 | annotate_field (4); | |
54e52265 | 6170 | if (header_of_multiple) |
0d381245 | 6171 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6172 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6173 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6174 | else |
5af949e3 UW |
6175 | ui_out_field_core_addr (uiout, "addr", |
6176 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6177 | } |
6178 | annotate_field (5); | |
0d381245 | 6179 | if (!header_of_multiple) |
170b53b2 | 6180 | print_breakpoint_location (b, loc); |
0d381245 | 6181 | if (b->loc) |
a6d9a66e | 6182 | *last_loc = b->loc; |
3086aeae DJ |
6183 | break; |
6184 | } | |
c906108c | 6185 | |
6c95b8df | 6186 | |
998580f1 | 6187 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6188 | { |
6189 | struct inferior *inf; | |
998580f1 MK |
6190 | VEC(int) *inf_num = NULL; |
6191 | int mi_only = 1; | |
6c95b8df | 6192 | |
998580f1 | 6193 | ALL_INFERIORS (inf) |
6c95b8df PA |
6194 | { |
6195 | if (inf->pspace == loc->pspace) | |
998580f1 | 6196 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6197 | } |
998580f1 MK |
6198 | |
6199 | /* For backward compatibility, don't display inferiors in CLI unless | |
6200 | there are several. Always display for MI. */ | |
6201 | if (allflag | |
6202 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6203 | && (number_of_program_spaces () > 1 | |
6204 | || number_of_inferiors () > 1) | |
6205 | /* LOC is for existing B, it cannot be in | |
6206 | moribund_locations and thus having NULL OWNER. */ | |
6207 | && loc->owner->type != bp_catchpoint)) | |
6208 | mi_only = 0; | |
6209 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6210 | VEC_free (int, inf_num); | |
6c95b8df PA |
6211 | } |
6212 | ||
4a306c9a | 6213 | if (!part_of_multiple) |
c4093a6a | 6214 | { |
4a306c9a JB |
6215 | if (b->thread != -1) |
6216 | { | |
6217 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6218 | "stop only in" line a little further down. */ |
4a306c9a JB |
6219 | ui_out_text (uiout, " thread "); |
6220 | ui_out_field_int (uiout, "thread", b->thread); | |
6221 | } | |
6222 | else if (b->task != 0) | |
6223 | { | |
6224 | ui_out_text (uiout, " task "); | |
6225 | ui_out_field_int (uiout, "task", b->task); | |
6226 | } | |
c4093a6a | 6227 | } |
f1310107 | 6228 | |
8b93c638 | 6229 | ui_out_text (uiout, "\n"); |
f1310107 | 6230 | |
348d480f | 6231 | if (!part_of_multiple) |
f1310107 TJB |
6232 | b->ops->print_one_detail (b, uiout); |
6233 | ||
0d381245 | 6234 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6235 | { |
6236 | annotate_field (6); | |
8b93c638 | 6237 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6238 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6239 | the frame ID. */ |
5af949e3 UW |
6240 | ui_out_field_core_addr (uiout, "frame", |
6241 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6242 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6243 | } |
6244 | ||
28010a5d | 6245 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6246 | { |
6247 | annotate_field (7); | |
d77f58be | 6248 | if (is_tracepoint (b)) |
1042e4c0 SS |
6249 | ui_out_text (uiout, "\ttrace only if "); |
6250 | else | |
6251 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6252 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6253 | |
6254 | /* Print whether the target is doing the breakpoint's condition | |
6255 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6256 | if (is_breakpoint (b) | |
6257 | && breakpoint_condition_evaluation_mode () | |
6258 | == condition_evaluation_target) | |
6259 | { | |
6260 | ui_out_text (uiout, " ("); | |
6261 | ui_out_field_string (uiout, "evaluated-by", | |
6262 | bp_condition_evaluator (b)); | |
6263 | ui_out_text (uiout, " evals)"); | |
6264 | } | |
0101ce28 JJ |
6265 | ui_out_text (uiout, "\n"); |
6266 | } | |
6267 | ||
0d381245 | 6268 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6269 | { |
4a64f543 | 6270 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6271 | ui_out_text (uiout, "\tstop only in thread "); |
6272 | ui_out_field_int (uiout, "thread", b->thread); | |
6273 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6274 | } |
6275 | ||
556ec64d YQ |
6276 | if (!part_of_multiple) |
6277 | { | |
6278 | if (b->hit_count) | |
31f56a27 YQ |
6279 | { |
6280 | /* FIXME should make an annotation for this. */ | |
6281 | if (is_catchpoint (b)) | |
6282 | ui_out_text (uiout, "\tcatchpoint"); | |
6283 | else if (is_tracepoint (b)) | |
6284 | ui_out_text (uiout, "\ttracepoint"); | |
6285 | else | |
6286 | ui_out_text (uiout, "\tbreakpoint"); | |
6287 | ui_out_text (uiout, " already hit "); | |
6288 | ui_out_field_int (uiout, "times", b->hit_count); | |
6289 | if (b->hit_count == 1) | |
6290 | ui_out_text (uiout, " time\n"); | |
6291 | else | |
6292 | ui_out_text (uiout, " times\n"); | |
6293 | } | |
556ec64d YQ |
6294 | else |
6295 | { | |
31f56a27 YQ |
6296 | /* Output the count also if it is zero, but only if this is mi. */ |
6297 | if (ui_out_is_mi_like_p (uiout)) | |
6298 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6299 | } |
6300 | } | |
8b93c638 | 6301 | |
0d381245 | 6302 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6303 | { |
6304 | annotate_field (8); | |
8b93c638 JM |
6305 | ui_out_text (uiout, "\tignore next "); |
6306 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6307 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6308 | } |
059fb39f | 6309 | |
816338b5 SS |
6310 | /* Note that an enable count of 1 corresponds to "enable once" |
6311 | behavior, which is reported by the combination of enablement and | |
6312 | disposition, so we don't need to mention it here. */ | |
6313 | if (!part_of_multiple && b->enable_count > 1) | |
6314 | { | |
6315 | annotate_field (8); | |
6316 | ui_out_text (uiout, "\tdisable after "); | |
6317 | /* Tweak the wording to clarify that ignore and enable counts | |
6318 | are distinct, and have additive effect. */ | |
6319 | if (b->ignore_count) | |
6320 | ui_out_text (uiout, "additional "); | |
6321 | else | |
6322 | ui_out_text (uiout, "next "); | |
6323 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6324 | ui_out_text (uiout, " hits\n"); | |
6325 | } | |
6326 | ||
f196051f SS |
6327 | if (!part_of_multiple && is_tracepoint (b)) |
6328 | { | |
6329 | struct tracepoint *tp = (struct tracepoint *) b; | |
6330 | ||
6331 | if (tp->traceframe_usage) | |
6332 | { | |
6333 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6334 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6335 | ui_out_text (uiout, " bytes\n"); | |
6336 | } | |
6337 | } | |
d3ce09f5 | 6338 | |
9add0f1b | 6339 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6340 | if (!part_of_multiple && l) |
c4093a6a | 6341 | { |
3b31d625 EZ |
6342 | struct cleanup *script_chain; |
6343 | ||
c4093a6a | 6344 | annotate_field (9); |
3b31d625 | 6345 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6346 | print_command_lines (uiout, l, 4); |
3b31d625 | 6347 | do_cleanups (script_chain); |
c4093a6a | 6348 | } |
d24317b4 | 6349 | |
d9b3f62e | 6350 | if (is_tracepoint (b)) |
1042e4c0 | 6351 | { |
d9b3f62e PA |
6352 | struct tracepoint *t = (struct tracepoint *) b; |
6353 | ||
6354 | if (!part_of_multiple && t->pass_count) | |
6355 | { | |
6356 | annotate_field (10); | |
6357 | ui_out_text (uiout, "\tpass count "); | |
6358 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6359 | ui_out_text (uiout, " \n"); | |
6360 | } | |
f2a8bc8a YQ |
6361 | |
6362 | /* Don't display it when tracepoint or tracepoint location is | |
6363 | pending. */ | |
6364 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6365 | { | |
6366 | annotate_field (11); | |
6367 | ||
6368 | if (ui_out_is_mi_like_p (uiout)) | |
6369 | ui_out_field_string (uiout, "installed", | |
6370 | loc->inserted ? "y" : "n"); | |
6371 | else | |
6372 | { | |
6373 | if (loc->inserted) | |
6374 | ui_out_text (uiout, "\t"); | |
6375 | else | |
6376 | ui_out_text (uiout, "\tnot "); | |
6377 | ui_out_text (uiout, "installed on target\n"); | |
6378 | } | |
6379 | } | |
1042e4c0 SS |
6380 | } |
6381 | ||
d24317b4 VP |
6382 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6383 | { | |
3a5c3e22 PA |
6384 | if (is_watchpoint (b)) |
6385 | { | |
6386 | struct watchpoint *w = (struct watchpoint *) b; | |
6387 | ||
6388 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6389 | } | |
6390 | else if (b->addr_string) | |
d24317b4 | 6391 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6392 | } |
c4093a6a | 6393 | } |
c5aa993b | 6394 | |
0d381245 VP |
6395 | static void |
6396 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6397 | struct bp_location **last_loc, |
6c95b8df | 6398 | int allflag) |
0d381245 | 6399 | { |
8d3788bd | 6400 | struct cleanup *bkpt_chain; |
79a45e25 | 6401 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6402 | |
6403 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6404 | ||
12c5a436 | 6405 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6406 | do_cleanups (bkpt_chain); |
0d381245 VP |
6407 | |
6408 | /* If this breakpoint has custom print function, | |
6409 | it's already printed. Otherwise, print individual | |
6410 | locations, if any. */ | |
6411 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6412 | { | |
4a64f543 MS |
6413 | /* If breakpoint has a single location that is disabled, we |
6414 | print it as if it had several locations, since otherwise it's | |
6415 | hard to represent "breakpoint enabled, location disabled" | |
6416 | situation. | |
6417 | ||
6418 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6419 | internally, that's not a property exposed to user. */ |
0d381245 | 6420 | if (b->loc |
a5606eee | 6421 | && !is_hardware_watchpoint (b) |
8d3788bd | 6422 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6423 | { |
6424 | struct bp_location *loc; | |
6425 | int n = 1; | |
8d3788bd | 6426 | |
0d381245 | 6427 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6428 | { |
6429 | struct cleanup *inner2 = | |
6430 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6431 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6432 | do_cleanups (inner2); | |
6433 | } | |
0d381245 VP |
6434 | } |
6435 | } | |
6436 | } | |
6437 | ||
a6d9a66e UW |
6438 | static int |
6439 | breakpoint_address_bits (struct breakpoint *b) | |
6440 | { | |
6441 | int print_address_bits = 0; | |
6442 | struct bp_location *loc; | |
6443 | ||
6444 | for (loc = b->loc; loc; loc = loc->next) | |
6445 | { | |
c7437ca6 PA |
6446 | int addr_bit; |
6447 | ||
6448 | /* Software watchpoints that aren't watching memory don't have | |
6449 | an address to print. */ | |
6450 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6451 | continue; | |
6452 | ||
6453 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6454 | if (addr_bit > print_address_bits) |
6455 | print_address_bits = addr_bit; | |
6456 | } | |
6457 | ||
6458 | return print_address_bits; | |
6459 | } | |
0d381245 | 6460 | |
c4093a6a JM |
6461 | struct captured_breakpoint_query_args |
6462 | { | |
6463 | int bnum; | |
6464 | }; | |
c5aa993b | 6465 | |
c4093a6a | 6466 | static int |
2b65245e | 6467 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6468 | { |
6469 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6470 | struct breakpoint *b; |
a6d9a66e | 6471 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6472 | |
c4093a6a JM |
6473 | ALL_BREAKPOINTS (b) |
6474 | { | |
6475 | if (args->bnum == b->number) | |
c5aa993b | 6476 | { |
12c5a436 | 6477 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6478 | return GDB_RC_OK; |
c5aa993b | 6479 | } |
c4093a6a JM |
6480 | } |
6481 | return GDB_RC_NONE; | |
6482 | } | |
c5aa993b | 6483 | |
c4093a6a | 6484 | enum gdb_rc |
4a64f543 MS |
6485 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6486 | char **error_message) | |
c4093a6a JM |
6487 | { |
6488 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6489 | |
c4093a6a JM |
6490 | args.bnum = bnum; |
6491 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6492 | an error. */ |
b0b13bb4 DJ |
6493 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6494 | error_message, RETURN_MASK_ALL) < 0) | |
6495 | return GDB_RC_FAIL; | |
6496 | else | |
6497 | return GDB_RC_OK; | |
c4093a6a | 6498 | } |
c5aa993b | 6499 | |
09d682a4 TT |
6500 | /* Return true if this breakpoint was set by the user, false if it is |
6501 | internal or momentary. */ | |
6502 | ||
6503 | int | |
6504 | user_breakpoint_p (struct breakpoint *b) | |
6505 | { | |
46c6471b | 6506 | return b->number > 0; |
09d682a4 TT |
6507 | } |
6508 | ||
7f3b0473 | 6509 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6510 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6511 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6512 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6513 | ones for which it returns non-zero. Return the total number of | |
6514 | breakpoints listed. */ | |
c906108c | 6515 | |
d77f58be | 6516 | static int |
e5a67952 | 6517 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6518 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6519 | { |
52f0bd74 | 6520 | struct breakpoint *b; |
a6d9a66e | 6521 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6522 | int nr_printable_breakpoints; |
3b31d625 | 6523 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6524 | struct value_print_options opts; |
a6d9a66e | 6525 | int print_address_bits = 0; |
269b11a2 | 6526 | int print_type_col_width = 14; |
79a45e25 | 6527 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6528 | |
79a45b7d TT |
6529 | get_user_print_options (&opts); |
6530 | ||
4a64f543 MS |
6531 | /* Compute the number of rows in the table, as well as the size |
6532 | required for address fields. */ | |
7f3b0473 AC |
6533 | nr_printable_breakpoints = 0; |
6534 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6535 | { |
6536 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6537 | if (filter && !filter (b)) | |
6538 | continue; | |
6539 | ||
6540 | /* If we have an "args" string, it is a list of breakpoints to | |
6541 | accept. Skip the others. */ | |
6542 | if (args != NULL && *args != '\0') | |
6543 | { | |
6544 | if (allflag && parse_and_eval_long (args) != b->number) | |
6545 | continue; | |
6546 | if (!allflag && !number_is_in_list (args, b->number)) | |
6547 | continue; | |
6548 | } | |
269b11a2 | 6549 | |
e5a67952 MS |
6550 | if (allflag || user_breakpoint_p (b)) |
6551 | { | |
6552 | int addr_bit, type_len; | |
a6d9a66e | 6553 | |
e5a67952 MS |
6554 | addr_bit = breakpoint_address_bits (b); |
6555 | if (addr_bit > print_address_bits) | |
6556 | print_address_bits = addr_bit; | |
269b11a2 | 6557 | |
e5a67952 MS |
6558 | type_len = strlen (bptype_string (b->type)); |
6559 | if (type_len > print_type_col_width) | |
6560 | print_type_col_width = type_len; | |
6561 | ||
6562 | nr_printable_breakpoints++; | |
6563 | } | |
6564 | } | |
7f3b0473 | 6565 | |
79a45b7d | 6566 | if (opts.addressprint) |
3b31d625 | 6567 | bkpttbl_chain |
3e43a32a MS |
6568 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6569 | nr_printable_breakpoints, | |
3b31d625 | 6570 | "BreakpointTable"); |
8b93c638 | 6571 | else |
3b31d625 | 6572 | bkpttbl_chain |
3e43a32a MS |
6573 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6574 | nr_printable_breakpoints, | |
3b31d625 | 6575 | "BreakpointTable"); |
8b93c638 | 6576 | |
7f3b0473 | 6577 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6578 | annotate_breakpoints_headers (); |
6579 | if (nr_printable_breakpoints > 0) | |
6580 | annotate_field (0); | |
4a64f543 | 6581 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6582 | if (nr_printable_breakpoints > 0) |
6583 | annotate_field (1); | |
269b11a2 | 6584 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6585 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6586 | if (nr_printable_breakpoints > 0) |
6587 | annotate_field (2); | |
4a64f543 | 6588 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6589 | if (nr_printable_breakpoints > 0) |
6590 | annotate_field (3); | |
54e52265 | 6591 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6592 | if (opts.addressprint) |
e5a67952 MS |
6593 | { |
6594 | if (nr_printable_breakpoints > 0) | |
6595 | annotate_field (4); | |
6596 | if (print_address_bits <= 32) | |
6597 | ui_out_table_header (uiout, 10, ui_left, | |
6598 | "addr", "Address"); /* 5 */ | |
6599 | else | |
6600 | ui_out_table_header (uiout, 18, ui_left, | |
6601 | "addr", "Address"); /* 5 */ | |
6602 | } | |
d7faa9e7 AC |
6603 | if (nr_printable_breakpoints > 0) |
6604 | annotate_field (5); | |
6605 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6606 | ui_out_table_body (uiout); | |
6607 | if (nr_printable_breakpoints > 0) | |
6608 | annotate_breakpoints_table (); | |
7f3b0473 | 6609 | |
c4093a6a | 6610 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6611 | { |
6612 | QUIT; | |
6613 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6614 | if (filter && !filter (b)) | |
6615 | continue; | |
6616 | ||
6617 | /* If we have an "args" string, it is a list of breakpoints to | |
6618 | accept. Skip the others. */ | |
6619 | ||
6620 | if (args != NULL && *args != '\0') | |
6621 | { | |
6622 | if (allflag) /* maintenance info breakpoint */ | |
6623 | { | |
6624 | if (parse_and_eval_long (args) != b->number) | |
6625 | continue; | |
6626 | } | |
6627 | else /* all others */ | |
6628 | { | |
6629 | if (!number_is_in_list (args, b->number)) | |
6630 | continue; | |
6631 | } | |
6632 | } | |
6633 | /* We only print out user settable breakpoints unless the | |
6634 | allflag is set. */ | |
6635 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6636 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6637 | } |
6638 | ||
3b31d625 | 6639 | do_cleanups (bkpttbl_chain); |
698384cd | 6640 | |
7f3b0473 | 6641 | if (nr_printable_breakpoints == 0) |
c906108c | 6642 | { |
4a64f543 MS |
6643 | /* If there's a filter, let the caller decide how to report |
6644 | empty list. */ | |
d77f58be SS |
6645 | if (!filter) |
6646 | { | |
e5a67952 | 6647 | if (args == NULL || *args == '\0') |
d77f58be SS |
6648 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6649 | else | |
4a64f543 | 6650 | ui_out_message (uiout, 0, |
e5a67952 MS |
6651 | "No breakpoint or watchpoint matching '%s'.\n", |
6652 | args); | |
d77f58be | 6653 | } |
c906108c SS |
6654 | } |
6655 | else | |
c4093a6a | 6656 | { |
a6d9a66e UW |
6657 | if (last_loc && !server_command) |
6658 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6659 | } |
c906108c | 6660 | |
4a64f543 | 6661 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6662 | there have been breakpoints? */ |
c906108c | 6663 | annotate_breakpoints_table_end (); |
d77f58be SS |
6664 | |
6665 | return nr_printable_breakpoints; | |
c906108c SS |
6666 | } |
6667 | ||
ad443146 SS |
6668 | /* Display the value of default-collect in a way that is generally |
6669 | compatible with the breakpoint list. */ | |
6670 | ||
6671 | static void | |
6672 | default_collect_info (void) | |
6673 | { | |
79a45e25 PA |
6674 | struct ui_out *uiout = current_uiout; |
6675 | ||
ad443146 SS |
6676 | /* If it has no value (which is frequently the case), say nothing; a |
6677 | message like "No default-collect." gets in user's face when it's | |
6678 | not wanted. */ | |
6679 | if (!*default_collect) | |
6680 | return; | |
6681 | ||
6682 | /* The following phrase lines up nicely with per-tracepoint collect | |
6683 | actions. */ | |
6684 | ui_out_text (uiout, "default collect "); | |
6685 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6686 | ui_out_text (uiout, " \n"); | |
6687 | } | |
6688 | ||
c906108c | 6689 | static void |
e5a67952 | 6690 | breakpoints_info (char *args, int from_tty) |
c906108c | 6691 | { |
e5a67952 | 6692 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6693 | |
6694 | default_collect_info (); | |
d77f58be SS |
6695 | } |
6696 | ||
6697 | static void | |
e5a67952 | 6698 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6699 | { |
e5a67952 | 6700 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6701 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6702 | |
6703 | if (num_printed == 0) | |
6704 | { | |
e5a67952 | 6705 | if (args == NULL || *args == '\0') |
d77f58be SS |
6706 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6707 | else | |
e5a67952 | 6708 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6709 | } |
c906108c SS |
6710 | } |
6711 | ||
7a292a7a | 6712 | static void |
e5a67952 | 6713 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6714 | { |
e5a67952 | 6715 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6716 | |
6717 | default_collect_info (); | |
c906108c SS |
6718 | } |
6719 | ||
0d381245 | 6720 | static int |
714835d5 | 6721 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6722 | struct program_space *pspace, |
714835d5 | 6723 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6724 | { |
6725 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6726 | |
0d381245 VP |
6727 | for (; bl; bl = bl->next) |
6728 | { | |
6c95b8df PA |
6729 | if (bl->pspace == pspace |
6730 | && bl->address == pc | |
0d381245 VP |
6731 | && (!overlay_debugging || bl->section == section)) |
6732 | return 1; | |
6733 | } | |
6734 | return 0; | |
6735 | } | |
6736 | ||
672f9b60 | 6737 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6738 | concerns with logical breakpoints, so we match program spaces, not |
6739 | address spaces. */ | |
c906108c SS |
6740 | |
6741 | static void | |
6c95b8df PA |
6742 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6743 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6744 | struct obj_section *section, int thread) |
c906108c | 6745 | { |
52f0bd74 AC |
6746 | int others = 0; |
6747 | struct breakpoint *b; | |
c906108c SS |
6748 | |
6749 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6750 | others += (user_breakpoint_p (b) |
6751 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6752 | if (others > 0) |
6753 | { | |
a3f17187 AC |
6754 | if (others == 1) |
6755 | printf_filtered (_("Note: breakpoint ")); | |
6756 | else /* if (others == ???) */ | |
6757 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6758 | ALL_BREAKPOINTS (b) |
672f9b60 | 6759 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6760 | { |
6761 | others--; | |
6762 | printf_filtered ("%d", b->number); | |
6763 | if (b->thread == -1 && thread != -1) | |
6764 | printf_filtered (" (all threads)"); | |
6765 | else if (b->thread != -1) | |
6766 | printf_filtered (" (thread %d)", b->thread); | |
6767 | printf_filtered ("%s%s ", | |
059fb39f | 6768 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6769 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6770 | ? " (disabled)" |
6771 | : b->enable_state == bp_permanent | |
6772 | ? " (permanent)" | |
6773 | : ""), | |
6774 | (others > 1) ? "," | |
6775 | : ((others == 1) ? " and" : "")); | |
6776 | } | |
a3f17187 | 6777 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6778 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6779 | printf_filtered (".\n"); |
6780 | } | |
6781 | } | |
6782 | \f | |
c906108c | 6783 | |
e4f237da KB |
6784 | /* Return true iff it is meaningful to use the address member of |
6785 | BPT. For some breakpoint types, the address member is irrelevant | |
6786 | and it makes no sense to attempt to compare it to other addresses | |
6787 | (or use it for any other purpose either). | |
6788 | ||
4a64f543 MS |
6789 | More specifically, each of the following breakpoint types will |
6790 | always have a zero valued address and we don't want to mark | |
6791 | breakpoints of any of these types to be a duplicate of an actual | |
6792 | breakpoint at address zero: | |
e4f237da KB |
6793 | |
6794 | bp_watchpoint | |
2d134ed3 PA |
6795 | bp_catchpoint |
6796 | ||
6797 | */ | |
e4f237da KB |
6798 | |
6799 | static int | |
6800 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6801 | { | |
6802 | enum bptype type = bpt->type; | |
6803 | ||
2d134ed3 PA |
6804 | return (type != bp_watchpoint && type != bp_catchpoint); |
6805 | } | |
6806 | ||
6807 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6808 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6809 | ||
6810 | static int | |
4a64f543 MS |
6811 | watchpoint_locations_match (struct bp_location *loc1, |
6812 | struct bp_location *loc2) | |
2d134ed3 | 6813 | { |
3a5c3e22 PA |
6814 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6815 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6816 | ||
6817 | /* Both of them must exist. */ | |
6818 | gdb_assert (w1 != NULL); | |
6819 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6820 | |
4a64f543 MS |
6821 | /* If the target can evaluate the condition expression in hardware, |
6822 | then we we need to insert both watchpoints even if they are at | |
6823 | the same place. Otherwise the watchpoint will only trigger when | |
6824 | the condition of whichever watchpoint was inserted evaluates to | |
6825 | true, not giving a chance for GDB to check the condition of the | |
6826 | other watchpoint. */ | |
3a5c3e22 | 6827 | if ((w1->cond_exp |
4a64f543 MS |
6828 | && target_can_accel_watchpoint_condition (loc1->address, |
6829 | loc1->length, | |
0cf6dd15 | 6830 | loc1->watchpoint_type, |
3a5c3e22 PA |
6831 | w1->cond_exp)) |
6832 | || (w2->cond_exp | |
4a64f543 MS |
6833 | && target_can_accel_watchpoint_condition (loc2->address, |
6834 | loc2->length, | |
0cf6dd15 | 6835 | loc2->watchpoint_type, |
3a5c3e22 | 6836 | w2->cond_exp))) |
0cf6dd15 TJB |
6837 | return 0; |
6838 | ||
85d721b8 PA |
6839 | /* Note that this checks the owner's type, not the location's. In |
6840 | case the target does not support read watchpoints, but does | |
6841 | support access watchpoints, we'll have bp_read_watchpoint | |
6842 | watchpoints with hw_access locations. Those should be considered | |
6843 | duplicates of hw_read locations. The hw_read locations will | |
6844 | become hw_access locations later. */ | |
2d134ed3 PA |
6845 | return (loc1->owner->type == loc2->owner->type |
6846 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6847 | && loc1->address == loc2->address | |
6848 | && loc1->length == loc2->length); | |
e4f237da KB |
6849 | } |
6850 | ||
31e77af2 | 6851 | /* See breakpoint.h. */ |
6c95b8df | 6852 | |
31e77af2 | 6853 | int |
6c95b8df PA |
6854 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6855 | struct address_space *aspace2, CORE_ADDR addr2) | |
6856 | { | |
f5656ead | 6857 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6858 | || aspace1 == aspace2) |
6859 | && addr1 == addr2); | |
6860 | } | |
6861 | ||
f1310107 TJB |
6862 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6863 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6864 | matches ASPACE2. On targets that have global breakpoints, the address | |
6865 | space doesn't really matter. */ | |
6866 | ||
6867 | static int | |
6868 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6869 | int len1, struct address_space *aspace2, | |
6870 | CORE_ADDR addr2) | |
6871 | { | |
f5656ead | 6872 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6873 | || aspace1 == aspace2) |
6874 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6875 | } | |
6876 | ||
6877 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6878 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6879 | matches the breakpoint's address space. On targets that have global | |
6880 | breakpoints, the address space doesn't really matter. */ | |
6881 | ||
6882 | static int | |
6883 | breakpoint_location_address_match (struct bp_location *bl, | |
6884 | struct address_space *aspace, | |
6885 | CORE_ADDR addr) | |
6886 | { | |
6887 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6888 | aspace, addr) | |
6889 | || (bl->length | |
6890 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6891 | bl->address, bl->length, | |
6892 | aspace, addr))); | |
6893 | } | |
6894 | ||
1e4d1764 YQ |
6895 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6896 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6897 | true, otherwise returns false. */ | |
6898 | ||
6899 | static int | |
6900 | tracepoint_locations_match (struct bp_location *loc1, | |
6901 | struct bp_location *loc2) | |
6902 | { | |
6903 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6904 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6905 | locations at the same address of different tracepoints are regarded as | |
6906 | different locations. */ | |
6907 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6908 | else | |
6909 | return 0; | |
6910 | } | |
6911 | ||
2d134ed3 PA |
6912 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6913 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6914 | represent the same location. */ | |
6915 | ||
6916 | static int | |
4a64f543 MS |
6917 | breakpoint_locations_match (struct bp_location *loc1, |
6918 | struct bp_location *loc2) | |
2d134ed3 | 6919 | { |
2bdf28a0 JK |
6920 | int hw_point1, hw_point2; |
6921 | ||
6922 | /* Both of them must not be in moribund_locations. */ | |
6923 | gdb_assert (loc1->owner != NULL); | |
6924 | gdb_assert (loc2->owner != NULL); | |
6925 | ||
6926 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6927 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6928 | |
6929 | if (hw_point1 != hw_point2) | |
6930 | return 0; | |
6931 | else if (hw_point1) | |
6932 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6933 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6934 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6935 | else |
f1310107 TJB |
6936 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6937 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6938 | loc2->pspace->aspace, loc2->address) | |
6939 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6940 | } |
6941 | ||
76897487 KB |
6942 | static void |
6943 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6944 | int bnum, int have_bnum) | |
6945 | { | |
f63fbe86 MS |
6946 | /* The longest string possibly returned by hex_string_custom |
6947 | is 50 chars. These must be at least that big for safety. */ | |
6948 | char astr1[64]; | |
6949 | char astr2[64]; | |
76897487 | 6950 | |
bb599908 PH |
6951 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6952 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6953 | if (have_bnum) |
8a3fe4f8 | 6954 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6955 | bnum, astr1, astr2); |
6956 | else | |
8a3fe4f8 | 6957 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6958 | } |
6959 | ||
4a64f543 MS |
6960 | /* Adjust a breakpoint's address to account for architectural |
6961 | constraints on breakpoint placement. Return the adjusted address. | |
6962 | Note: Very few targets require this kind of adjustment. For most | |
6963 | targets, this function is simply the identity function. */ | |
76897487 KB |
6964 | |
6965 | static CORE_ADDR | |
a6d9a66e UW |
6966 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6967 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6968 | { |
a6d9a66e | 6969 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6970 | { |
6971 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6972 | return bpaddr; | |
6973 | } | |
88f7da05 KB |
6974 | else if (bptype == bp_watchpoint |
6975 | || bptype == bp_hardware_watchpoint | |
6976 | || bptype == bp_read_watchpoint | |
6977 | || bptype == bp_access_watchpoint | |
fe798b75 | 6978 | || bptype == bp_catchpoint) |
88f7da05 KB |
6979 | { |
6980 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6981 | have their addresses modified. */ | |
6982 | return bpaddr; | |
6983 | } | |
76897487 KB |
6984 | else |
6985 | { | |
6986 | CORE_ADDR adjusted_bpaddr; | |
6987 | ||
6988 | /* Some targets have architectural constraints on the placement | |
6989 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6990 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6991 | |
6992 | /* An adjusted breakpoint address can significantly alter | |
6993 | a user's expectations. Print a warning if an adjustment | |
6994 | is required. */ | |
6995 | if (adjusted_bpaddr != bpaddr) | |
6996 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6997 | ||
6998 | return adjusted_bpaddr; | |
6999 | } | |
7000 | } | |
7001 | ||
28010a5d PA |
7002 | void |
7003 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7004 | struct breakpoint *owner) | |
7cc221ef | 7005 | { |
7cc221ef DJ |
7006 | memset (loc, 0, sizeof (*loc)); |
7007 | ||
348d480f PA |
7008 | gdb_assert (ops != NULL); |
7009 | ||
28010a5d PA |
7010 | loc->ops = ops; |
7011 | loc->owner = owner; | |
511a6cd4 | 7012 | loc->cond = NULL; |
b775012e | 7013 | loc->cond_bytecode = NULL; |
0d381245 VP |
7014 | loc->shlib_disabled = 0; |
7015 | loc->enabled = 1; | |
e049a4b5 | 7016 | |
28010a5d | 7017 | switch (owner->type) |
e049a4b5 DJ |
7018 | { |
7019 | case bp_breakpoint: | |
7020 | case bp_until: | |
7021 | case bp_finish: | |
7022 | case bp_longjmp: | |
7023 | case bp_longjmp_resume: | |
e2e4d78b | 7024 | case bp_longjmp_call_dummy: |
186c406b TT |
7025 | case bp_exception: |
7026 | case bp_exception_resume: | |
e049a4b5 | 7027 | case bp_step_resume: |
2c03e5be | 7028 | case bp_hp_step_resume: |
e049a4b5 DJ |
7029 | case bp_watchpoint_scope: |
7030 | case bp_call_dummy: | |
aa7d318d | 7031 | case bp_std_terminate: |
e049a4b5 DJ |
7032 | case bp_shlib_event: |
7033 | case bp_thread_event: | |
7034 | case bp_overlay_event: | |
4efc6507 | 7035 | case bp_jit_event: |
0fd8e87f | 7036 | case bp_longjmp_master: |
aa7d318d | 7037 | case bp_std_terminate_master: |
186c406b | 7038 | case bp_exception_master: |
0e30163f JK |
7039 | case bp_gnu_ifunc_resolver: |
7040 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7041 | case bp_dprintf: |
e049a4b5 | 7042 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7043 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7044 | break; |
7045 | case bp_hardware_breakpoint: | |
7046 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7047 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7048 | break; |
7049 | case bp_hardware_watchpoint: | |
7050 | case bp_read_watchpoint: | |
7051 | case bp_access_watchpoint: | |
7052 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7053 | break; | |
7054 | case bp_watchpoint: | |
ce78b96d | 7055 | case bp_catchpoint: |
15c3d785 PA |
7056 | case bp_tracepoint: |
7057 | case bp_fast_tracepoint: | |
0fb4aa4b | 7058 | case bp_static_tracepoint: |
e049a4b5 DJ |
7059 | loc->loc_type = bp_loc_other; |
7060 | break; | |
7061 | default: | |
e2e0b3e5 | 7062 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7063 | } |
7064 | ||
f431efe5 | 7065 | loc->refc = 1; |
28010a5d PA |
7066 | } |
7067 | ||
7068 | /* Allocate a struct bp_location. */ | |
7069 | ||
7070 | static struct bp_location * | |
7071 | allocate_bp_location (struct breakpoint *bpt) | |
7072 | { | |
348d480f PA |
7073 | return bpt->ops->allocate_location (bpt); |
7074 | } | |
7cc221ef | 7075 | |
f431efe5 PA |
7076 | static void |
7077 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7078 | { |
348d480f | 7079 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7080 | xfree (loc); |
7081 | } | |
7082 | ||
f431efe5 PA |
7083 | /* Increment reference count. */ |
7084 | ||
7085 | static void | |
7086 | incref_bp_location (struct bp_location *bl) | |
7087 | { | |
7088 | ++bl->refc; | |
7089 | } | |
7090 | ||
7091 | /* Decrement reference count. If the reference count reaches 0, | |
7092 | destroy the bp_location. Sets *BLP to NULL. */ | |
7093 | ||
7094 | static void | |
7095 | decref_bp_location (struct bp_location **blp) | |
7096 | { | |
0807b50c PA |
7097 | gdb_assert ((*blp)->refc > 0); |
7098 | ||
f431efe5 PA |
7099 | if (--(*blp)->refc == 0) |
7100 | free_bp_location (*blp); | |
7101 | *blp = NULL; | |
7102 | } | |
7103 | ||
346774a9 | 7104 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7105 | |
346774a9 PA |
7106 | static void |
7107 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7108 | { |
346774a9 | 7109 | struct breakpoint *b1; |
c906108c | 7110 | |
346774a9 PA |
7111 | /* Add this breakpoint to the end of the chain so that a list of |
7112 | breakpoints will come out in order of increasing numbers. */ | |
7113 | ||
7114 | b1 = breakpoint_chain; | |
7115 | if (b1 == 0) | |
7116 | breakpoint_chain = b; | |
7117 | else | |
7118 | { | |
7119 | while (b1->next) | |
7120 | b1 = b1->next; | |
7121 | b1->next = b; | |
7122 | } | |
7123 | } | |
7124 | ||
7125 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7126 | ||
7127 | static void | |
7128 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7129 | struct gdbarch *gdbarch, | |
28010a5d | 7130 | enum bptype bptype, |
c0a91b2b | 7131 | const struct breakpoint_ops *ops) |
346774a9 | 7132 | { |
c906108c | 7133 | memset (b, 0, sizeof (*b)); |
2219d63c | 7134 | |
348d480f PA |
7135 | gdb_assert (ops != NULL); |
7136 | ||
28010a5d | 7137 | b->ops = ops; |
4d28f7a8 | 7138 | b->type = bptype; |
a6d9a66e | 7139 | b->gdbarch = gdbarch; |
c906108c SS |
7140 | b->language = current_language->la_language; |
7141 | b->input_radix = input_radix; | |
7142 | b->thread = -1; | |
b5de0fa7 | 7143 | b->enable_state = bp_enabled; |
c906108c SS |
7144 | b->next = 0; |
7145 | b->silent = 0; | |
7146 | b->ignore_count = 0; | |
7147 | b->commands = NULL; | |
818dd999 | 7148 | b->frame_id = null_frame_id; |
0d381245 | 7149 | b->condition_not_parsed = 0; |
84f4c1fe | 7150 | b->py_bp_object = NULL; |
d0fb5eae | 7151 | b->related_breakpoint = b; |
346774a9 PA |
7152 | } |
7153 | ||
7154 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7155 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7156 | |
7157 | static struct breakpoint * | |
7158 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7159 | enum bptype bptype, |
c0a91b2b | 7160 | const struct breakpoint_ops *ops) |
346774a9 PA |
7161 | { |
7162 | struct breakpoint *b = XNEW (struct breakpoint); | |
7163 | ||
348d480f | 7164 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7165 | add_to_breakpoint_chain (b); |
0d381245 VP |
7166 | return b; |
7167 | } | |
7168 | ||
0e30163f JK |
7169 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7170 | resolutions should be made as the user specified the location explicitly | |
7171 | enough. */ | |
7172 | ||
0d381245 | 7173 | static void |
0e30163f | 7174 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7175 | { |
2bdf28a0 JK |
7176 | gdb_assert (loc->owner != NULL); |
7177 | ||
0d381245 | 7178 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7179 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7180 | || is_tracepoint (loc->owner)) |
0d381245 | 7181 | { |
0e30163f | 7182 | int is_gnu_ifunc; |
2c02bd72 | 7183 | const char *function_name; |
6a3a010b | 7184 | CORE_ADDR func_addr; |
0e30163f | 7185 | |
2c02bd72 | 7186 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7187 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7188 | |
7189 | if (is_gnu_ifunc && !explicit_loc) | |
7190 | { | |
7191 | struct breakpoint *b = loc->owner; | |
7192 | ||
7193 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7194 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7195 | &loc->requested_address)) |
7196 | { | |
7197 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7198 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7199 | loc->requested_address, | |
7200 | b->type); | |
7201 | } | |
7202 | else if (b->type == bp_breakpoint && b->loc == loc | |
7203 | && loc->next == NULL && b->related_breakpoint == b) | |
7204 | { | |
7205 | /* Create only the whole new breakpoint of this type but do not | |
7206 | mess more complicated breakpoints with multiple locations. */ | |
7207 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7208 | /* Remember the resolver's address for use by the return |
7209 | breakpoint. */ | |
7210 | loc->related_address = func_addr; | |
0e30163f JK |
7211 | } |
7212 | } | |
7213 | ||
2c02bd72 DE |
7214 | if (function_name) |
7215 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7216 | } |
7217 | } | |
7218 | ||
a6d9a66e | 7219 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7220 | struct gdbarch * |
a6d9a66e UW |
7221 | get_sal_arch (struct symtab_and_line sal) |
7222 | { | |
7223 | if (sal.section) | |
7224 | return get_objfile_arch (sal.section->objfile); | |
7225 | if (sal.symtab) | |
7226 | return get_objfile_arch (sal.symtab->objfile); | |
7227 | ||
7228 | return NULL; | |
7229 | } | |
7230 | ||
346774a9 PA |
7231 | /* Low level routine for partially initializing a breakpoint of type |
7232 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7233 | file name, and line number are provided by SAL. |
0d381245 VP |
7234 | |
7235 | It is expected that the caller will complete the initialization of | |
7236 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7237 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7238 | |
346774a9 PA |
7239 | static void |
7240 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7241 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7242 | const struct breakpoint_ops *ops) |
0d381245 | 7243 | { |
28010a5d | 7244 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7245 | |
3742cc8b | 7246 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7247 | |
6c95b8df PA |
7248 | if (bptype != bp_catchpoint) |
7249 | gdb_assert (sal.pspace != NULL); | |
7250 | ||
f8eba3c6 TT |
7251 | /* Store the program space that was used to set the breakpoint, |
7252 | except for ordinary breakpoints, which are independent of the | |
7253 | program space. */ | |
7254 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7255 | b->pspace = sal.pspace; | |
346774a9 | 7256 | } |
c906108c | 7257 | |
346774a9 PA |
7258 | /* set_raw_breakpoint is a low level routine for allocating and |
7259 | partially initializing a breakpoint of type BPTYPE. The newly | |
7260 | created breakpoint's address, section, source file name, and line | |
7261 | number are provided by SAL. The newly created and partially | |
7262 | initialized breakpoint is added to the breakpoint chain and | |
7263 | is also returned as the value of this function. | |
7264 | ||
7265 | It is expected that the caller will complete the initialization of | |
7266 | the newly created breakpoint struct as well as output any status | |
7267 | information regarding the creation of a new breakpoint. In | |
7268 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7269 | number! Care should be taken to not allow an error to occur | |
7270 | prior to completing the initialization of the breakpoint. If this | |
7271 | should happen, a bogus breakpoint will be left on the chain. */ | |
7272 | ||
7273 | struct breakpoint * | |
7274 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7275 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7276 | const struct breakpoint_ops *ops) |
346774a9 PA |
7277 | { |
7278 | struct breakpoint *b = XNEW (struct breakpoint); | |
7279 | ||
348d480f | 7280 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7281 | add_to_breakpoint_chain (b); |
c906108c SS |
7282 | return b; |
7283 | } | |
7284 | ||
c2c6d25f JM |
7285 | |
7286 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7287 | instruction, hard-wired into the inferior's code. */ | |
7288 | void | |
7289 | make_breakpoint_permanent (struct breakpoint *b) | |
7290 | { | |
0d381245 | 7291 | struct bp_location *bl; |
cc59ec59 | 7292 | |
b5de0fa7 | 7293 | b->enable_state = bp_permanent; |
c2c6d25f | 7294 | |
4a64f543 MS |
7295 | /* By definition, permanent breakpoints are already present in the |
7296 | code. Mark all locations as inserted. For now, | |
7297 | make_breakpoint_permanent is called in just one place, so it's | |
7298 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7299 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7300 | for (bl = b->loc; bl; bl = bl->next) |
7301 | bl->inserted = 1; | |
c2c6d25f JM |
7302 | } |
7303 | ||
53a5351d | 7304 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7305 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7306 | initiated the operation. */ | |
c906108c SS |
7307 | |
7308 | void | |
186c406b | 7309 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7310 | { |
35df4500 | 7311 | struct breakpoint *b, *b_tmp; |
186c406b | 7312 | int thread = tp->num; |
0fd8e87f UW |
7313 | |
7314 | /* To avoid having to rescan all objfile symbols at every step, | |
7315 | we maintain a list of continually-inserted but always disabled | |
7316 | longjmp "master" breakpoints. Here, we simply create momentary | |
7317 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7318 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7319 | if (b->pspace == current_program_space |
186c406b TT |
7320 | && (b->type == bp_longjmp_master |
7321 | || b->type == bp_exception_master)) | |
0fd8e87f | 7322 | { |
06edf0c0 PA |
7323 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7324 | struct breakpoint *clone; | |
cc59ec59 | 7325 | |
e2e4d78b JK |
7326 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7327 | after their removal. */ | |
06edf0c0 | 7328 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7329 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7330 | clone->thread = thread; |
7331 | } | |
186c406b TT |
7332 | |
7333 | tp->initiating_frame = frame; | |
c906108c SS |
7334 | } |
7335 | ||
611c83ae | 7336 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7337 | void |
611c83ae | 7338 | delete_longjmp_breakpoint (int thread) |
c906108c | 7339 | { |
35df4500 | 7340 | struct breakpoint *b, *b_tmp; |
c906108c | 7341 | |
35df4500 | 7342 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7343 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7344 | { |
7345 | if (b->thread == thread) | |
7346 | delete_breakpoint (b); | |
7347 | } | |
c906108c SS |
7348 | } |
7349 | ||
f59f708a PA |
7350 | void |
7351 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7352 | { | |
7353 | struct breakpoint *b, *b_tmp; | |
7354 | ||
7355 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7356 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7357 | { | |
7358 | if (b->thread == thread) | |
7359 | b->disposition = disp_del_at_next_stop; | |
7360 | } | |
7361 | } | |
7362 | ||
e2e4d78b JK |
7363 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7364 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7365 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7366 | breakpoints. */ | |
7367 | ||
7368 | struct breakpoint * | |
7369 | set_longjmp_breakpoint_for_call_dummy (void) | |
7370 | { | |
7371 | struct breakpoint *b, *retval = NULL; | |
7372 | ||
7373 | ALL_BREAKPOINTS (b) | |
7374 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7375 | { | |
7376 | struct breakpoint *new_b; | |
7377 | ||
7378 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7379 | &momentary_breakpoint_ops); | |
7380 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7381 | ||
7382 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7383 | ||
7384 | gdb_assert (new_b->related_breakpoint == new_b); | |
7385 | if (retval == NULL) | |
7386 | retval = new_b; | |
7387 | new_b->related_breakpoint = retval; | |
7388 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7389 | retval = retval->related_breakpoint; | |
7390 | retval->related_breakpoint = new_b; | |
7391 | } | |
7392 | ||
7393 | return retval; | |
7394 | } | |
7395 | ||
7396 | /* Verify all existing dummy frames and their associated breakpoints for | |
7397 | THREAD. Remove those which can no longer be found in the current frame | |
7398 | stack. | |
7399 | ||
7400 | You should call this function only at places where it is safe to currently | |
7401 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7402 | frames. */ | |
7403 | ||
7404 | void | |
7405 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7406 | { | |
7407 | struct breakpoint *b, *b_tmp; | |
7408 | ||
7409 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7410 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7411 | { | |
7412 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7413 | ||
7414 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7415 | dummy_b = dummy_b->related_breakpoint; | |
7416 | if (dummy_b->type != bp_call_dummy | |
7417 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7418 | continue; | |
7419 | ||
7420 | dummy_frame_discard (dummy_b->frame_id); | |
7421 | ||
7422 | while (b->related_breakpoint != b) | |
7423 | { | |
7424 | if (b_tmp == b->related_breakpoint) | |
7425 | b_tmp = b->related_breakpoint->next; | |
7426 | delete_breakpoint (b->related_breakpoint); | |
7427 | } | |
7428 | delete_breakpoint (b); | |
7429 | } | |
7430 | } | |
7431 | ||
1900040c MS |
7432 | void |
7433 | enable_overlay_breakpoints (void) | |
7434 | { | |
52f0bd74 | 7435 | struct breakpoint *b; |
1900040c MS |
7436 | |
7437 | ALL_BREAKPOINTS (b) | |
7438 | if (b->type == bp_overlay_event) | |
7439 | { | |
7440 | b->enable_state = bp_enabled; | |
b60e7edf | 7441 | update_global_location_list (1); |
c02f5703 | 7442 | overlay_events_enabled = 1; |
1900040c MS |
7443 | } |
7444 | } | |
7445 | ||
7446 | void | |
7447 | disable_overlay_breakpoints (void) | |
7448 | { | |
52f0bd74 | 7449 | struct breakpoint *b; |
1900040c MS |
7450 | |
7451 | ALL_BREAKPOINTS (b) | |
7452 | if (b->type == bp_overlay_event) | |
7453 | { | |
7454 | b->enable_state = bp_disabled; | |
b60e7edf | 7455 | update_global_location_list (0); |
c02f5703 | 7456 | overlay_events_enabled = 0; |
1900040c MS |
7457 | } |
7458 | } | |
7459 | ||
aa7d318d TT |
7460 | /* Set an active std::terminate breakpoint for each std::terminate |
7461 | master breakpoint. */ | |
7462 | void | |
7463 | set_std_terminate_breakpoint (void) | |
7464 | { | |
35df4500 | 7465 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7466 | |
35df4500 | 7467 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7468 | if (b->pspace == current_program_space |
7469 | && b->type == bp_std_terminate_master) | |
7470 | { | |
06edf0c0 PA |
7471 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7472 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7473 | } |
7474 | } | |
7475 | ||
7476 | /* Delete all the std::terminate breakpoints. */ | |
7477 | void | |
7478 | delete_std_terminate_breakpoint (void) | |
7479 | { | |
35df4500 | 7480 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7481 | |
35df4500 | 7482 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7483 | if (b->type == bp_std_terminate) |
7484 | delete_breakpoint (b); | |
7485 | } | |
7486 | ||
c4093a6a | 7487 | struct breakpoint * |
a6d9a66e | 7488 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7489 | { |
7490 | struct breakpoint *b; | |
c4093a6a | 7491 | |
06edf0c0 PA |
7492 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7493 | &internal_breakpoint_ops); | |
7494 | ||
b5de0fa7 | 7495 | b->enable_state = bp_enabled; |
c4093a6a | 7496 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7497 | b->addr_string |
7498 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7499 | |
b60e7edf | 7500 | update_global_location_list_nothrow (1); |
74960c60 | 7501 | |
c4093a6a JM |
7502 | return b; |
7503 | } | |
7504 | ||
7505 | void | |
7506 | remove_thread_event_breakpoints (void) | |
7507 | { | |
35df4500 | 7508 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7509 | |
35df4500 | 7510 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7511 | if (b->type == bp_thread_event |
7512 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7513 | delete_breakpoint (b); |
7514 | } | |
7515 | ||
0101ce28 JJ |
7516 | struct lang_and_radix |
7517 | { | |
7518 | enum language lang; | |
7519 | int radix; | |
7520 | }; | |
7521 | ||
4efc6507 DE |
7522 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7523 | ||
7524 | struct breakpoint * | |
7525 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7526 | { | |
7527 | struct breakpoint *b; | |
7528 | ||
06edf0c0 PA |
7529 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7530 | &internal_breakpoint_ops); | |
4efc6507 DE |
7531 | update_global_location_list_nothrow (1); |
7532 | return b; | |
7533 | } | |
0101ce28 | 7534 | |
03673fc7 PP |
7535 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7536 | ||
7537 | void | |
7538 | remove_jit_event_breakpoints (void) | |
7539 | { | |
7540 | struct breakpoint *b, *b_tmp; | |
7541 | ||
7542 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7543 | if (b->type == bp_jit_event | |
7544 | && b->loc->pspace == current_program_space) | |
7545 | delete_breakpoint (b); | |
7546 | } | |
7547 | ||
cae688ec JJ |
7548 | void |
7549 | remove_solib_event_breakpoints (void) | |
7550 | { | |
35df4500 | 7551 | struct breakpoint *b, *b_tmp; |
cae688ec | 7552 | |
35df4500 | 7553 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7554 | if (b->type == bp_shlib_event |
7555 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7556 | delete_breakpoint (b); |
7557 | } | |
7558 | ||
7559 | struct breakpoint * | |
a6d9a66e | 7560 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7561 | { |
7562 | struct breakpoint *b; | |
7563 | ||
06edf0c0 PA |
7564 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7565 | &internal_breakpoint_ops); | |
b60e7edf | 7566 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7567 | return b; |
7568 | } | |
7569 | ||
7570 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7571 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7572 | ||
7573 | void | |
cb851954 | 7574 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7575 | { |
876fa593 | 7576 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7577 | |
876fa593 | 7578 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7579 | { |
2bdf28a0 | 7580 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7581 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7582 | |
4a64f543 MS |
7583 | /* We apply the check to all breakpoints, including disabled for |
7584 | those with loc->duplicate set. This is so that when breakpoint | |
7585 | becomes enabled, or the duplicate is removed, gdb will try to | |
7586 | insert all breakpoints. If we don't set shlib_disabled here, | |
7587 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7588 | if (((b->type == bp_breakpoint) |
508ccb1f | 7589 | || (b->type == bp_jit_event) |
1042e4c0 | 7590 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7591 | || (is_tracepoint (b))) |
6c95b8df | 7592 | && loc->pspace == current_program_space |
0d381245 | 7593 | && !loc->shlib_disabled |
6c95b8df | 7594 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7595 | ) |
0d381245 VP |
7596 | { |
7597 | loc->shlib_disabled = 1; | |
7598 | } | |
cae688ec JJ |
7599 | } |
7600 | } | |
7601 | ||
63644780 NB |
7602 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7603 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7604 | disabled ones can just stay disabled. */ | |
84acb35a | 7605 | |
75149521 | 7606 | static void |
84acb35a JJ |
7607 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7608 | { | |
876fa593 | 7609 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7610 | int disabled_shlib_breaks = 0; |
7611 | ||
c86cf029 VP |
7612 | /* SunOS a.out shared libraries are always mapped, so do not |
7613 | disable breakpoints; they will only be reported as unloaded | |
7614 | through clear_solib when GDB discards its shared library | |
7615 | list. See clear_solib for more information. */ | |
7616 | if (exec_bfd != NULL | |
7617 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7618 | return; | |
7619 | ||
876fa593 | 7620 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7621 | { |
2bdf28a0 | 7622 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7623 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7624 | |
1e4d1764 | 7625 | if (solib->pspace == loc->pspace |
e2dd7057 | 7626 | && !loc->shlib_disabled |
1e4d1764 YQ |
7627 | && (((b->type == bp_breakpoint |
7628 | || b->type == bp_jit_event | |
7629 | || b->type == bp_hardware_breakpoint) | |
7630 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7631 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7632 | || is_tracepoint (b)) | |
e2dd7057 | 7633 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7634 | { |
e2dd7057 PP |
7635 | loc->shlib_disabled = 1; |
7636 | /* At this point, we cannot rely on remove_breakpoint | |
7637 | succeeding so we must mark the breakpoint as not inserted | |
7638 | to prevent future errors occurring in remove_breakpoints. */ | |
7639 | loc->inserted = 0; | |
8d3788bd VP |
7640 | |
7641 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7642 | observer_notify_breakpoint_modified (b); | |
7643 | ||
e2dd7057 PP |
7644 | if (!disabled_shlib_breaks) |
7645 | { | |
7646 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7647 | warning (_("Temporarily disabling breakpoints " |
7648 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7649 | solib->so_name); |
84acb35a | 7650 | } |
e2dd7057 | 7651 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7652 | } |
7653 | } | |
84acb35a JJ |
7654 | } |
7655 | ||
63644780 NB |
7656 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7657 | notification of free_objfile. Only apply to enabled breakpoints, | |
7658 | disabled ones can just stay disabled. */ | |
7659 | ||
7660 | static void | |
7661 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7662 | { | |
7663 | struct breakpoint *b; | |
7664 | ||
7665 | if (objfile == NULL) | |
7666 | return; | |
7667 | ||
7668 | /* If the file is a shared library not loaded by the user then | |
7669 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7670 | was called. In that case there is no need to take action again. */ | |
7671 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7672 | return; | |
7673 | ||
7674 | ALL_BREAKPOINTS (b) | |
7675 | { | |
7676 | struct bp_location *loc; | |
7677 | int bp_modified = 0; | |
7678 | ||
7679 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7680 | continue; | |
7681 | ||
7682 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7683 | { | |
7684 | CORE_ADDR loc_addr = loc->address; | |
7685 | ||
7686 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7687 | && loc->loc_type != bp_loc_software_breakpoint) | |
7688 | continue; | |
7689 | ||
7690 | if (loc->shlib_disabled != 0) | |
7691 | continue; | |
7692 | ||
7693 | if (objfile->pspace != loc->pspace) | |
7694 | continue; | |
7695 | ||
7696 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7697 | && loc->loc_type != bp_loc_software_breakpoint) | |
7698 | continue; | |
7699 | ||
7700 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7701 | { | |
7702 | loc->shlib_disabled = 1; | |
7703 | loc->inserted = 0; | |
7704 | ||
7705 | mark_breakpoint_location_modified (loc); | |
7706 | ||
7707 | bp_modified = 1; | |
7708 | } | |
7709 | } | |
7710 | ||
7711 | if (bp_modified) | |
7712 | observer_notify_breakpoint_modified (b); | |
7713 | } | |
7714 | } | |
7715 | ||
ce78b96d JB |
7716 | /* FORK & VFORK catchpoints. */ |
7717 | ||
e29a4733 PA |
7718 | /* An instance of this type is used to represent a fork or vfork |
7719 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7720 | class; users downcast to "struct breakpoint *" when needed. A | |
7721 | breakpoint is really of this type iff its ops pointer points to | |
7722 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7723 | ||
7724 | struct fork_catchpoint | |
7725 | { | |
7726 | /* The base class. */ | |
7727 | struct breakpoint base; | |
7728 | ||
7729 | /* Process id of a child process whose forking triggered this | |
7730 | catchpoint. This field is only valid immediately after this | |
7731 | catchpoint has triggered. */ | |
7732 | ptid_t forked_inferior_pid; | |
7733 | }; | |
7734 | ||
4a64f543 MS |
7735 | /* Implement the "insert" breakpoint_ops method for fork |
7736 | catchpoints. */ | |
ce78b96d | 7737 | |
77b06cd7 TJB |
7738 | static int |
7739 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7740 | { |
dfd4cc63 | 7741 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7742 | } |
7743 | ||
4a64f543 MS |
7744 | /* Implement the "remove" breakpoint_ops method for fork |
7745 | catchpoints. */ | |
ce78b96d JB |
7746 | |
7747 | static int | |
77b06cd7 | 7748 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7749 | { |
dfd4cc63 | 7750 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7751 | } |
7752 | ||
7753 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7754 | catchpoints. */ | |
7755 | ||
7756 | static int | |
f1310107 | 7757 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7758 | struct address_space *aspace, CORE_ADDR bp_addr, |
7759 | const struct target_waitstatus *ws) | |
ce78b96d | 7760 | { |
e29a4733 PA |
7761 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7762 | ||
f90263c1 TT |
7763 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7764 | return 0; | |
7765 | ||
7766 | c->forked_inferior_pid = ws->value.related_pid; | |
7767 | return 1; | |
ce78b96d JB |
7768 | } |
7769 | ||
4a64f543 MS |
7770 | /* Implement the "print_it" breakpoint_ops method for fork |
7771 | catchpoints. */ | |
ce78b96d JB |
7772 | |
7773 | static enum print_stop_action | |
348d480f | 7774 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7775 | { |
36dfb11c | 7776 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7777 | struct breakpoint *b = bs->breakpoint_at; |
7778 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7779 | |
ce78b96d | 7780 | annotate_catchpoint (b->number); |
36dfb11c TT |
7781 | if (b->disposition == disp_del) |
7782 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7783 | else | |
7784 | ui_out_text (uiout, "\nCatchpoint "); | |
7785 | if (ui_out_is_mi_like_p (uiout)) | |
7786 | { | |
7787 | ui_out_field_string (uiout, "reason", | |
7788 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7789 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7790 | } | |
7791 | ui_out_field_int (uiout, "bkptno", b->number); | |
7792 | ui_out_text (uiout, " (forked process "); | |
7793 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7794 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7795 | return PRINT_SRC_AND_LOC; |
7796 | } | |
7797 | ||
4a64f543 MS |
7798 | /* Implement the "print_one" breakpoint_ops method for fork |
7799 | catchpoints. */ | |
ce78b96d JB |
7800 | |
7801 | static void | |
a6d9a66e | 7802 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7803 | { |
e29a4733 | 7804 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7805 | struct value_print_options opts; |
79a45e25 | 7806 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7807 | |
7808 | get_user_print_options (&opts); | |
7809 | ||
4a64f543 MS |
7810 | /* Field 4, the address, is omitted (which makes the columns not |
7811 | line up too nicely with the headers, but the effect is relatively | |
7812 | readable). */ | |
79a45b7d | 7813 | if (opts.addressprint) |
ce78b96d JB |
7814 | ui_out_field_skip (uiout, "addr"); |
7815 | annotate_field (5); | |
7816 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7817 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7818 | { |
7819 | ui_out_text (uiout, ", process "); | |
7820 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7821 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7822 | ui_out_spaces (uiout, 1); |
7823 | } | |
8ac3646f TT |
7824 | |
7825 | if (ui_out_is_mi_like_p (uiout)) | |
7826 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7827 | } |
7828 | ||
7829 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7830 | catchpoints. */ | |
7831 | ||
7832 | static void | |
7833 | print_mention_catch_fork (struct breakpoint *b) | |
7834 | { | |
7835 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7836 | } | |
7837 | ||
6149aea9 PA |
7838 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7839 | catchpoints. */ | |
7840 | ||
7841 | static void | |
7842 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7843 | { | |
7844 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7845 | print_recreate_thread (b, fp); |
6149aea9 PA |
7846 | } |
7847 | ||
ce78b96d JB |
7848 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7849 | ||
2060206e | 7850 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7851 | |
4a64f543 MS |
7852 | /* Implement the "insert" breakpoint_ops method for vfork |
7853 | catchpoints. */ | |
ce78b96d | 7854 | |
77b06cd7 TJB |
7855 | static int |
7856 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7857 | { |
dfd4cc63 | 7858 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7859 | } |
7860 | ||
4a64f543 MS |
7861 | /* Implement the "remove" breakpoint_ops method for vfork |
7862 | catchpoints. */ | |
ce78b96d JB |
7863 | |
7864 | static int | |
77b06cd7 | 7865 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7866 | { |
dfd4cc63 | 7867 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7868 | } |
7869 | ||
7870 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7871 | catchpoints. */ | |
7872 | ||
7873 | static int | |
f1310107 | 7874 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7875 | struct address_space *aspace, CORE_ADDR bp_addr, |
7876 | const struct target_waitstatus *ws) | |
ce78b96d | 7877 | { |
e29a4733 PA |
7878 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7879 | ||
f90263c1 TT |
7880 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7881 | return 0; | |
7882 | ||
7883 | c->forked_inferior_pid = ws->value.related_pid; | |
7884 | return 1; | |
ce78b96d JB |
7885 | } |
7886 | ||
4a64f543 MS |
7887 | /* Implement the "print_it" breakpoint_ops method for vfork |
7888 | catchpoints. */ | |
ce78b96d JB |
7889 | |
7890 | static enum print_stop_action | |
348d480f | 7891 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7892 | { |
36dfb11c | 7893 | struct ui_out *uiout = current_uiout; |
348d480f | 7894 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7895 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7896 | ||
ce78b96d | 7897 | annotate_catchpoint (b->number); |
36dfb11c TT |
7898 | if (b->disposition == disp_del) |
7899 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7900 | else | |
7901 | ui_out_text (uiout, "\nCatchpoint "); | |
7902 | if (ui_out_is_mi_like_p (uiout)) | |
7903 | { | |
7904 | ui_out_field_string (uiout, "reason", | |
7905 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7906 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7907 | } | |
7908 | ui_out_field_int (uiout, "bkptno", b->number); | |
7909 | ui_out_text (uiout, " (vforked process "); | |
7910 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7911 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7912 | return PRINT_SRC_AND_LOC; |
7913 | } | |
7914 | ||
4a64f543 MS |
7915 | /* Implement the "print_one" breakpoint_ops method for vfork |
7916 | catchpoints. */ | |
ce78b96d JB |
7917 | |
7918 | static void | |
a6d9a66e | 7919 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7920 | { |
e29a4733 | 7921 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7922 | struct value_print_options opts; |
79a45e25 | 7923 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7924 | |
7925 | get_user_print_options (&opts); | |
4a64f543 MS |
7926 | /* Field 4, the address, is omitted (which makes the columns not |
7927 | line up too nicely with the headers, but the effect is relatively | |
7928 | readable). */ | |
79a45b7d | 7929 | if (opts.addressprint) |
ce78b96d JB |
7930 | ui_out_field_skip (uiout, "addr"); |
7931 | annotate_field (5); | |
7932 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7933 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7934 | { |
7935 | ui_out_text (uiout, ", process "); | |
7936 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7937 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7938 | ui_out_spaces (uiout, 1); |
7939 | } | |
8ac3646f TT |
7940 | |
7941 | if (ui_out_is_mi_like_p (uiout)) | |
7942 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7943 | } |
7944 | ||
7945 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7946 | catchpoints. */ | |
7947 | ||
7948 | static void | |
7949 | print_mention_catch_vfork (struct breakpoint *b) | |
7950 | { | |
7951 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7952 | } | |
7953 | ||
6149aea9 PA |
7954 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7955 | catchpoints. */ | |
7956 | ||
7957 | static void | |
7958 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7959 | { | |
7960 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7961 | print_recreate_thread (b, fp); |
6149aea9 PA |
7962 | } |
7963 | ||
ce78b96d JB |
7964 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7965 | ||
2060206e | 7966 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7967 | |
edcc5120 TT |
7968 | /* An instance of this type is used to represent an solib catchpoint. |
7969 | It includes a "struct breakpoint" as a kind of base class; users | |
7970 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7971 | really of this type iff its ops pointer points to | |
7972 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7973 | ||
7974 | struct solib_catchpoint | |
7975 | { | |
7976 | /* The base class. */ | |
7977 | struct breakpoint base; | |
7978 | ||
7979 | /* True for "catch load", false for "catch unload". */ | |
7980 | unsigned char is_load; | |
7981 | ||
7982 | /* Regular expression to match, if any. COMPILED is only valid when | |
7983 | REGEX is non-NULL. */ | |
7984 | char *regex; | |
7985 | regex_t compiled; | |
7986 | }; | |
7987 | ||
7988 | static void | |
7989 | dtor_catch_solib (struct breakpoint *b) | |
7990 | { | |
7991 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7992 | ||
7993 | if (self->regex) | |
7994 | regfree (&self->compiled); | |
7995 | xfree (self->regex); | |
7996 | ||
7997 | base_breakpoint_ops.dtor (b); | |
7998 | } | |
7999 | ||
8000 | static int | |
8001 | insert_catch_solib (struct bp_location *ignore) | |
8002 | { | |
8003 | return 0; | |
8004 | } | |
8005 | ||
8006 | static int | |
8007 | remove_catch_solib (struct bp_location *ignore) | |
8008 | { | |
8009 | return 0; | |
8010 | } | |
8011 | ||
8012 | static int | |
8013 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8014 | struct address_space *aspace, | |
8015 | CORE_ADDR bp_addr, | |
8016 | const struct target_waitstatus *ws) | |
8017 | { | |
8018 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8019 | struct breakpoint *other; | |
8020 | ||
8021 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8022 | return 1; | |
8023 | ||
8024 | ALL_BREAKPOINTS (other) | |
8025 | { | |
8026 | struct bp_location *other_bl; | |
8027 | ||
8028 | if (other == bl->owner) | |
8029 | continue; | |
8030 | ||
8031 | if (other->type != bp_shlib_event) | |
8032 | continue; | |
8033 | ||
8034 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8035 | continue; | |
8036 | ||
8037 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8038 | { | |
8039 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8040 | return 1; | |
8041 | } | |
8042 | } | |
8043 | ||
8044 | return 0; | |
8045 | } | |
8046 | ||
8047 | static void | |
8048 | check_status_catch_solib (struct bpstats *bs) | |
8049 | { | |
8050 | struct solib_catchpoint *self | |
8051 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8052 | int ix; | |
8053 | ||
8054 | if (self->is_load) | |
8055 | { | |
8056 | struct so_list *iter; | |
8057 | ||
8058 | for (ix = 0; | |
8059 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8060 | ix, iter); | |
8061 | ++ix) | |
8062 | { | |
8063 | if (!self->regex | |
8064 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8065 | return; | |
8066 | } | |
8067 | } | |
8068 | else | |
8069 | { | |
8070 | char *iter; | |
8071 | ||
8072 | for (ix = 0; | |
8073 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8074 | ix, iter); | |
8075 | ++ix) | |
8076 | { | |
8077 | if (!self->regex | |
8078 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8079 | return; | |
8080 | } | |
8081 | } | |
8082 | ||
8083 | bs->stop = 0; | |
8084 | bs->print_it = print_it_noop; | |
8085 | } | |
8086 | ||
8087 | static enum print_stop_action | |
8088 | print_it_catch_solib (bpstat bs) | |
8089 | { | |
8090 | struct breakpoint *b = bs->breakpoint_at; | |
8091 | struct ui_out *uiout = current_uiout; | |
8092 | ||
8093 | annotate_catchpoint (b->number); | |
8094 | if (b->disposition == disp_del) | |
8095 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8096 | else | |
8097 | ui_out_text (uiout, "\nCatchpoint "); | |
8098 | ui_out_field_int (uiout, "bkptno", b->number); | |
8099 | ui_out_text (uiout, "\n"); | |
8100 | if (ui_out_is_mi_like_p (uiout)) | |
8101 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8102 | print_solib_event (1); | |
8103 | return PRINT_SRC_AND_LOC; | |
8104 | } | |
8105 | ||
8106 | static void | |
8107 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8108 | { | |
8109 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8110 | struct value_print_options opts; | |
8111 | struct ui_out *uiout = current_uiout; | |
8112 | char *msg; | |
8113 | ||
8114 | get_user_print_options (&opts); | |
8115 | /* Field 4, the address, is omitted (which makes the columns not | |
8116 | line up too nicely with the headers, but the effect is relatively | |
8117 | readable). */ | |
8118 | if (opts.addressprint) | |
8119 | { | |
8120 | annotate_field (4); | |
8121 | ui_out_field_skip (uiout, "addr"); | |
8122 | } | |
8123 | ||
8124 | annotate_field (5); | |
8125 | if (self->is_load) | |
8126 | { | |
8127 | if (self->regex) | |
8128 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8129 | else | |
8130 | msg = xstrdup (_("load of library")); | |
8131 | } | |
8132 | else | |
8133 | { | |
8134 | if (self->regex) | |
8135 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8136 | else | |
8137 | msg = xstrdup (_("unload of library")); | |
8138 | } | |
8139 | ui_out_field_string (uiout, "what", msg); | |
8140 | xfree (msg); | |
8ac3646f TT |
8141 | |
8142 | if (ui_out_is_mi_like_p (uiout)) | |
8143 | ui_out_field_string (uiout, "catch-type", | |
8144 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8145 | } |
8146 | ||
8147 | static void | |
8148 | print_mention_catch_solib (struct breakpoint *b) | |
8149 | { | |
8150 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8151 | ||
8152 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8153 | self->is_load ? "load" : "unload"); | |
8154 | } | |
8155 | ||
8156 | static void | |
8157 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8158 | { | |
8159 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8160 | ||
8161 | fprintf_unfiltered (fp, "%s %s", | |
8162 | b->disposition == disp_del ? "tcatch" : "catch", | |
8163 | self->is_load ? "load" : "unload"); | |
8164 | if (self->regex) | |
8165 | fprintf_unfiltered (fp, " %s", self->regex); | |
8166 | fprintf_unfiltered (fp, "\n"); | |
8167 | } | |
8168 | ||
8169 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8170 | ||
91985142 MG |
8171 | /* Shared helper function (MI and CLI) for creating and installing |
8172 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8173 | the events to be caught are load events, otherwise they are | |
8174 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8175 | temporary one. If ENABLED is non-zero the catchpoint is | |
8176 | created in an enabled state. */ | |
edcc5120 | 8177 | |
91985142 MG |
8178 | void |
8179 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8180 | { |
8181 | struct solib_catchpoint *c; | |
8182 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8183 | struct cleanup *cleanup; |
8184 | ||
edcc5120 TT |
8185 | if (!arg) |
8186 | arg = ""; | |
8187 | arg = skip_spaces (arg); | |
8188 | ||
8189 | c = XCNEW (struct solib_catchpoint); | |
8190 | cleanup = make_cleanup (xfree, c); | |
8191 | ||
8192 | if (*arg != '\0') | |
8193 | { | |
8194 | int errcode; | |
8195 | ||
8196 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8197 | if (errcode != 0) | |
8198 | { | |
8199 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8200 | ||
8201 | make_cleanup (xfree, err); | |
8202 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8203 | } | |
8204 | c->regex = xstrdup (arg); | |
8205 | } | |
8206 | ||
8207 | c->is_load = is_load; | |
91985142 | 8208 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8209 | &catch_solib_breakpoint_ops); |
8210 | ||
91985142 MG |
8211 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8212 | ||
edcc5120 TT |
8213 | discard_cleanups (cleanup); |
8214 | install_breakpoint (0, &c->base, 1); | |
8215 | } | |
8216 | ||
91985142 MG |
8217 | /* A helper function that does all the work for "catch load" and |
8218 | "catch unload". */ | |
8219 | ||
8220 | static void | |
8221 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8222 | struct cmd_list_element *command) | |
8223 | { | |
8224 | int tempflag; | |
8225 | const int enabled = 1; | |
8226 | ||
8227 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8228 | ||
8229 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8230 | } | |
8231 | ||
edcc5120 TT |
8232 | static void |
8233 | catch_load_command_1 (char *arg, int from_tty, | |
8234 | struct cmd_list_element *command) | |
8235 | { | |
8236 | catch_load_or_unload (arg, from_tty, 1, command); | |
8237 | } | |
8238 | ||
8239 | static void | |
8240 | catch_unload_command_1 (char *arg, int from_tty, | |
8241 | struct cmd_list_element *command) | |
8242 | { | |
8243 | catch_load_or_unload (arg, from_tty, 0, command); | |
8244 | } | |
8245 | ||
be5c67c1 PA |
8246 | /* An instance of this type is used to represent a syscall catchpoint. |
8247 | It includes a "struct breakpoint" as a kind of base class; users | |
8248 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8249 | really of this type iff its ops pointer points to | |
8250 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8251 | ||
8252 | struct syscall_catchpoint | |
8253 | { | |
8254 | /* The base class. */ | |
8255 | struct breakpoint base; | |
8256 | ||
8257 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8258 | syscall has been specified for filtering, its value is NULL. | |
8259 | Otherwise, it holds a list of all syscalls to be caught. The | |
8260 | list elements are allocated with xmalloc. */ | |
8261 | VEC(int) *syscalls_to_be_caught; | |
8262 | }; | |
8263 | ||
8264 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8265 | catchpoints. */ | |
8266 | ||
8267 | static void | |
8268 | dtor_catch_syscall (struct breakpoint *b) | |
8269 | { | |
8270 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8271 | ||
8272 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8273 | |
2060206e | 8274 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8275 | } |
8276 | ||
fa3064dd YQ |
8277 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8278 | ||
8279 | struct catch_syscall_inferior_data | |
8280 | { | |
8281 | /* We keep a count of the number of times the user has requested a | |
8282 | particular syscall to be tracked, and pass this information to the | |
8283 | target. This lets capable targets implement filtering directly. */ | |
8284 | ||
8285 | /* Number of times that "any" syscall is requested. */ | |
8286 | int any_syscall_count; | |
8287 | ||
8288 | /* Count of each system call. */ | |
8289 | VEC(int) *syscalls_counts; | |
8290 | ||
8291 | /* This counts all syscall catch requests, so we can readily determine | |
8292 | if any catching is necessary. */ | |
8293 | int total_syscalls_count; | |
8294 | }; | |
8295 | ||
8296 | static struct catch_syscall_inferior_data* | |
8297 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8298 | { | |
8299 | struct catch_syscall_inferior_data *inf_data; | |
8300 | ||
8301 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8302 | if (inf_data == NULL) | |
8303 | { | |
41bf6aca | 8304 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8305 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8306 | } | |
8307 | ||
8308 | return inf_data; | |
8309 | } | |
8310 | ||
8311 | static void | |
8312 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8313 | { | |
8314 | xfree (arg); | |
8315 | } | |
8316 | ||
8317 | ||
a96d9b2e SDJ |
8318 | /* Implement the "insert" breakpoint_ops method for syscall |
8319 | catchpoints. */ | |
8320 | ||
77b06cd7 TJB |
8321 | static int |
8322 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8323 | { |
be5c67c1 | 8324 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8325 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8326 | struct catch_syscall_inferior_data *inf_data |
8327 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8328 | |
fa3064dd | 8329 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8330 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8331 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8332 | else |
8333 | { | |
8334 | int i, iter; | |
cc59ec59 | 8335 | |
a96d9b2e | 8336 | for (i = 0; |
be5c67c1 | 8337 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8338 | i++) |
8339 | { | |
8340 | int elem; | |
cc59ec59 | 8341 | |
fa3064dd | 8342 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8343 | { |
fa3064dd | 8344 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8345 | uintptr_t vec_addr_offset |
8346 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8347 | uintptr_t vec_addr; |
fa3064dd YQ |
8348 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8349 | vec_addr = ((uintptr_t) VEC_address (int, | |
8350 | inf_data->syscalls_counts) | |
8351 | + vec_addr_offset); | |
a96d9b2e SDJ |
8352 | memset ((void *) vec_addr, 0, |
8353 | (iter + 1 - old_size) * sizeof (int)); | |
8354 | } | |
fa3064dd YQ |
8355 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8356 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8357 | } |
8358 | } | |
8359 | ||
dfd4cc63 | 8360 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8361 | inf_data->total_syscalls_count != 0, |
8362 | inf_data->any_syscall_count, | |
8363 | VEC_length (int, | |
8364 | inf_data->syscalls_counts), | |
8365 | VEC_address (int, | |
8366 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8367 | } |
8368 | ||
8369 | /* Implement the "remove" breakpoint_ops method for syscall | |
8370 | catchpoints. */ | |
8371 | ||
8372 | static int | |
77b06cd7 | 8373 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8374 | { |
be5c67c1 | 8375 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8376 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8377 | struct catch_syscall_inferior_data *inf_data |
8378 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8379 | |
fa3064dd | 8380 | --inf_data->total_syscalls_count; |
be5c67c1 | 8381 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8382 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8383 | else |
8384 | { | |
8385 | int i, iter; | |
cc59ec59 | 8386 | |
a96d9b2e | 8387 | for (i = 0; |
be5c67c1 | 8388 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8389 | i++) |
8390 | { | |
8391 | int elem; | |
fa3064dd | 8392 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8393 | /* Shouldn't happen. */ |
8394 | continue; | |
fa3064dd YQ |
8395 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8396 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8397 | } |
8398 | } | |
8399 | ||
dfd4cc63 | 8400 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8401 | inf_data->total_syscalls_count != 0, |
8402 | inf_data->any_syscall_count, | |
8403 | VEC_length (int, | |
8404 | inf_data->syscalls_counts), | |
3e43a32a | 8405 | VEC_address (int, |
fa3064dd | 8406 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8407 | } |
8408 | ||
8409 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8410 | catchpoints. */ | |
8411 | ||
8412 | static int | |
f1310107 | 8413 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8414 | struct address_space *aspace, CORE_ADDR bp_addr, |
8415 | const struct target_waitstatus *ws) | |
a96d9b2e | 8416 | { |
4a64f543 MS |
8417 | /* We must check if we are catching specific syscalls in this |
8418 | breakpoint. If we are, then we must guarantee that the called | |
8419 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8420 | int syscall_number = 0; |
be5c67c1 PA |
8421 | const struct syscall_catchpoint *c |
8422 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8423 | |
f90263c1 TT |
8424 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8425 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8426 | return 0; |
8427 | ||
f90263c1 TT |
8428 | syscall_number = ws->value.syscall_number; |
8429 | ||
a96d9b2e | 8430 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8431 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8432 | { |
8433 | int i, iter; | |
cc59ec59 | 8434 | |
a96d9b2e | 8435 | for (i = 0; |
be5c67c1 | 8436 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8437 | i++) |
8438 | if (syscall_number == iter) | |
4924df79 GKB |
8439 | return 1; |
8440 | ||
8441 | return 0; | |
a96d9b2e SDJ |
8442 | } |
8443 | ||
8444 | return 1; | |
8445 | } | |
8446 | ||
8447 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8448 | catchpoints. */ | |
8449 | ||
8450 | static enum print_stop_action | |
348d480f | 8451 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8452 | { |
36dfb11c | 8453 | struct ui_out *uiout = current_uiout; |
348d480f | 8454 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8455 | /* These are needed because we want to know in which state a |
8456 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8457 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8458 | must print "called syscall" or "returned from syscall". */ | |
8459 | ptid_t ptid; | |
8460 | struct target_waitstatus last; | |
8461 | struct syscall s; | |
a96d9b2e SDJ |
8462 | |
8463 | get_last_target_status (&ptid, &last); | |
8464 | ||
8465 | get_syscall_by_number (last.value.syscall_number, &s); | |
8466 | ||
8467 | annotate_catchpoint (b->number); | |
8468 | ||
36dfb11c TT |
8469 | if (b->disposition == disp_del) |
8470 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8471 | else |
36dfb11c TT |
8472 | ui_out_text (uiout, "\nCatchpoint "); |
8473 | if (ui_out_is_mi_like_p (uiout)) | |
8474 | { | |
8475 | ui_out_field_string (uiout, "reason", | |
8476 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8477 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8478 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8479 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8480 | } | |
8481 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8482 | |
8483 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8484 | ui_out_text (uiout, " (call to syscall "); |
8485 | else | |
8486 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8487 | |
36dfb11c TT |
8488 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8489 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8490 | if (s.name != NULL) | |
8491 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8492 | ||
8493 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8494 | |
8495 | return PRINT_SRC_AND_LOC; | |
8496 | } | |
8497 | ||
8498 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8499 | catchpoints. */ | |
8500 | ||
8501 | static void | |
8502 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8503 | struct bp_location **last_loc) |
a96d9b2e | 8504 | { |
be5c67c1 | 8505 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8506 | struct value_print_options opts; |
79a45e25 | 8507 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8508 | |
8509 | get_user_print_options (&opts); | |
4a64f543 MS |
8510 | /* Field 4, the address, is omitted (which makes the columns not |
8511 | line up too nicely with the headers, but the effect is relatively | |
8512 | readable). */ | |
a96d9b2e SDJ |
8513 | if (opts.addressprint) |
8514 | ui_out_field_skip (uiout, "addr"); | |
8515 | annotate_field (5); | |
8516 | ||
be5c67c1 PA |
8517 | if (c->syscalls_to_be_caught |
8518 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8519 | ui_out_text (uiout, "syscalls \""); |
8520 | else | |
8521 | ui_out_text (uiout, "syscall \""); | |
8522 | ||
be5c67c1 | 8523 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8524 | { |
8525 | int i, iter; | |
8526 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8527 | |
a96d9b2e | 8528 | for (i = 0; |
be5c67c1 | 8529 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8530 | i++) |
8531 | { | |
8532 | char *x = text; | |
8533 | struct syscall s; | |
8534 | get_syscall_by_number (iter, &s); | |
8535 | ||
8536 | if (s.name != NULL) | |
8537 | text = xstrprintf ("%s%s, ", text, s.name); | |
8538 | else | |
8539 | text = xstrprintf ("%s%d, ", text, iter); | |
8540 | ||
8541 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8542 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8543 | on every call. */ |
8544 | xfree (x); | |
8545 | } | |
8546 | /* Remove the last comma. */ | |
8547 | text[strlen (text) - 2] = '\0'; | |
8548 | ui_out_field_string (uiout, "what", text); | |
8549 | } | |
8550 | else | |
8551 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8552 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8553 | |
8554 | if (ui_out_is_mi_like_p (uiout)) | |
8555 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8556 | } |
8557 | ||
8558 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8559 | catchpoints. */ | |
8560 | ||
8561 | static void | |
8562 | print_mention_catch_syscall (struct breakpoint *b) | |
8563 | { | |
be5c67c1 PA |
8564 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8565 | ||
8566 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8567 | { |
8568 | int i, iter; | |
8569 | ||
be5c67c1 | 8570 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8571 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8572 | else | |
8573 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8574 | ||
8575 | for (i = 0; | |
be5c67c1 | 8576 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8577 | i++) |
8578 | { | |
8579 | struct syscall s; | |
8580 | get_syscall_by_number (iter, &s); | |
8581 | ||
8582 | if (s.name) | |
8583 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8584 | else | |
8585 | printf_filtered (" %d", s.number); | |
8586 | } | |
8587 | printf_filtered (")"); | |
8588 | } | |
8589 | else | |
8590 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8591 | b->number); | |
8592 | } | |
8593 | ||
6149aea9 PA |
8594 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8595 | catchpoints. */ | |
8596 | ||
8597 | static void | |
8598 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8599 | { | |
be5c67c1 PA |
8600 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8601 | ||
6149aea9 PA |
8602 | fprintf_unfiltered (fp, "catch syscall"); |
8603 | ||
be5c67c1 | 8604 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8605 | { |
8606 | int i, iter; | |
8607 | ||
8608 | for (i = 0; | |
be5c67c1 | 8609 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8610 | i++) |
8611 | { | |
8612 | struct syscall s; | |
8613 | ||
8614 | get_syscall_by_number (iter, &s); | |
8615 | if (s.name) | |
8616 | fprintf_unfiltered (fp, " %s", s.name); | |
8617 | else | |
8618 | fprintf_unfiltered (fp, " %d", s.number); | |
8619 | } | |
8620 | } | |
d9b3f62e | 8621 | print_recreate_thread (b, fp); |
6149aea9 PA |
8622 | } |
8623 | ||
a96d9b2e SDJ |
8624 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8625 | ||
2060206e | 8626 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8627 | |
8628 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8629 | ||
8630 | static int | |
8631 | syscall_catchpoint_p (struct breakpoint *b) | |
8632 | { | |
8633 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8634 | } | |
8635 | ||
346774a9 PA |
8636 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8637 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8638 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8639 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8640 | |
ab04a2af | 8641 | void |
346774a9 PA |
8642 | init_catchpoint (struct breakpoint *b, |
8643 | struct gdbarch *gdbarch, int tempflag, | |
8644 | char *cond_string, | |
c0a91b2b | 8645 | const struct breakpoint_ops *ops) |
c906108c | 8646 | { |
c5aa993b | 8647 | struct symtab_and_line sal; |
346774a9 | 8648 | |
fe39c653 | 8649 | init_sal (&sal); |
6c95b8df | 8650 | sal.pspace = current_program_space; |
c5aa993b | 8651 | |
28010a5d | 8652 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8653 | |
1b36a34b | 8654 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8655 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8656 | } |
8657 | ||
28010a5d | 8658 | void |
3ea46bff | 8659 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8660 | { |
8661 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8662 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8663 | if (is_tracepoint (b)) |
8664 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8665 | if (!internal) |
8666 | mention (b); | |
c56053d2 | 8667 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8668 | |
8669 | if (update_gll) | |
8670 | update_global_location_list (1); | |
c56053d2 PA |
8671 | } |
8672 | ||
9b70b993 | 8673 | static void |
a6d9a66e UW |
8674 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8675 | int tempflag, char *cond_string, | |
c0a91b2b | 8676 | const struct breakpoint_ops *ops) |
c906108c | 8677 | { |
e29a4733 | 8678 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8679 | |
e29a4733 PA |
8680 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8681 | ||
8682 | c->forked_inferior_pid = null_ptid; | |
8683 | ||
3ea46bff | 8684 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8685 | } |
8686 | ||
fe798b75 JB |
8687 | /* Exec catchpoints. */ |
8688 | ||
b4d90040 PA |
8689 | /* An instance of this type is used to represent an exec catchpoint. |
8690 | It includes a "struct breakpoint" as a kind of base class; users | |
8691 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8692 | really of this type iff its ops pointer points to | |
8693 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8694 | ||
8695 | struct exec_catchpoint | |
8696 | { | |
8697 | /* The base class. */ | |
8698 | struct breakpoint base; | |
8699 | ||
8700 | /* Filename of a program whose exec triggered this catchpoint. | |
8701 | This field is only valid immediately after this catchpoint has | |
8702 | triggered. */ | |
8703 | char *exec_pathname; | |
8704 | }; | |
8705 | ||
8706 | /* Implement the "dtor" breakpoint_ops method for exec | |
8707 | catchpoints. */ | |
8708 | ||
8709 | static void | |
8710 | dtor_catch_exec (struct breakpoint *b) | |
8711 | { | |
8712 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8713 | ||
8714 | xfree (c->exec_pathname); | |
348d480f | 8715 | |
2060206e | 8716 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8717 | } |
8718 | ||
77b06cd7 TJB |
8719 | static int |
8720 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8721 | { |
dfd4cc63 | 8722 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8723 | } |
c906108c | 8724 | |
fe798b75 | 8725 | static int |
77b06cd7 | 8726 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8727 | { |
dfd4cc63 | 8728 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8729 | } |
c906108c | 8730 | |
fe798b75 | 8731 | static int |
f1310107 | 8732 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8733 | struct address_space *aspace, CORE_ADDR bp_addr, |
8734 | const struct target_waitstatus *ws) | |
fe798b75 | 8735 | { |
b4d90040 PA |
8736 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8737 | ||
f90263c1 TT |
8738 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8739 | return 0; | |
8740 | ||
8741 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8742 | return 1; | |
fe798b75 | 8743 | } |
c906108c | 8744 | |
fe798b75 | 8745 | static enum print_stop_action |
348d480f | 8746 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8747 | { |
36dfb11c | 8748 | struct ui_out *uiout = current_uiout; |
348d480f | 8749 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8750 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8751 | ||
fe798b75 | 8752 | annotate_catchpoint (b->number); |
36dfb11c TT |
8753 | if (b->disposition == disp_del) |
8754 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8755 | else | |
8756 | ui_out_text (uiout, "\nCatchpoint "); | |
8757 | if (ui_out_is_mi_like_p (uiout)) | |
8758 | { | |
8759 | ui_out_field_string (uiout, "reason", | |
8760 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8761 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8762 | } | |
8763 | ui_out_field_int (uiout, "bkptno", b->number); | |
8764 | ui_out_text (uiout, " (exec'd "); | |
8765 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8766 | ui_out_text (uiout, "), "); | |
8767 | ||
fe798b75 | 8768 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8769 | } |
8770 | ||
fe798b75 | 8771 | static void |
a6d9a66e | 8772 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8773 | { |
b4d90040 | 8774 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8775 | struct value_print_options opts; |
79a45e25 | 8776 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8777 | |
8778 | get_user_print_options (&opts); | |
8779 | ||
8780 | /* Field 4, the address, is omitted (which makes the columns | |
8781 | not line up too nicely with the headers, but the effect | |
8782 | is relatively readable). */ | |
8783 | if (opts.addressprint) | |
8784 | ui_out_field_skip (uiout, "addr"); | |
8785 | annotate_field (5); | |
8786 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8787 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8788 | { |
8789 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8790 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8791 | ui_out_text (uiout, "\" "); |
8792 | } | |
8ac3646f TT |
8793 | |
8794 | if (ui_out_is_mi_like_p (uiout)) | |
8795 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8796 | } |
8797 | ||
8798 | static void | |
8799 | print_mention_catch_exec (struct breakpoint *b) | |
8800 | { | |
8801 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8802 | } | |
8803 | ||
6149aea9 PA |
8804 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8805 | catchpoints. */ | |
8806 | ||
8807 | static void | |
8808 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8809 | { | |
8810 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8811 | print_recreate_thread (b, fp); |
6149aea9 PA |
8812 | } |
8813 | ||
2060206e | 8814 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8815 | |
a96d9b2e SDJ |
8816 | static void |
8817 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8818 | const struct breakpoint_ops *ops) |
a96d9b2e | 8819 | { |
be5c67c1 | 8820 | struct syscall_catchpoint *c; |
a96d9b2e | 8821 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8822 | |
be5c67c1 PA |
8823 | c = XNEW (struct syscall_catchpoint); |
8824 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8825 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8826 | |
3ea46bff | 8827 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8828 | } |
8829 | ||
c906108c | 8830 | static int |
fba45db2 | 8831 | hw_breakpoint_used_count (void) |
c906108c | 8832 | { |
c906108c | 8833 | int i = 0; |
f1310107 TJB |
8834 | struct breakpoint *b; |
8835 | struct bp_location *bl; | |
c906108c SS |
8836 | |
8837 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8838 | { |
d6b74ac4 | 8839 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8840 | for (bl = b->loc; bl; bl = bl->next) |
8841 | { | |
8842 | /* Special types of hardware breakpoints may use more than | |
8843 | one register. */ | |
348d480f | 8844 | i += b->ops->resources_needed (bl); |
f1310107 | 8845 | } |
c5aa993b | 8846 | } |
c906108c SS |
8847 | |
8848 | return i; | |
8849 | } | |
8850 | ||
a1398e0c PA |
8851 | /* Returns the resources B would use if it were a hardware |
8852 | watchpoint. */ | |
8853 | ||
c906108c | 8854 | static int |
a1398e0c | 8855 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8856 | { |
c906108c | 8857 | int i = 0; |
e09342b5 | 8858 | struct bp_location *bl; |
c906108c | 8859 | |
a1398e0c PA |
8860 | if (!breakpoint_enabled (b)) |
8861 | return 0; | |
8862 | ||
8863 | for (bl = b->loc; bl; bl = bl->next) | |
8864 | { | |
8865 | /* Special types of hardware watchpoints may use more than | |
8866 | one register. */ | |
8867 | i += b->ops->resources_needed (bl); | |
8868 | } | |
8869 | ||
8870 | return i; | |
8871 | } | |
8872 | ||
8873 | /* Returns the sum the used resources of all hardware watchpoints of | |
8874 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8875 | the sum of the used resources of all hardware watchpoints of other | |
8876 | types _not_ TYPE. */ | |
8877 | ||
8878 | static int | |
8879 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8880 | enum bptype type, int *other_type_used) | |
8881 | { | |
8882 | int i = 0; | |
8883 | struct breakpoint *b; | |
8884 | ||
c906108c SS |
8885 | *other_type_used = 0; |
8886 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8887 | { |
a1398e0c PA |
8888 | if (b == except) |
8889 | continue; | |
e09342b5 TJB |
8890 | if (!breakpoint_enabled (b)) |
8891 | continue; | |
8892 | ||
a1398e0c PA |
8893 | if (b->type == type) |
8894 | i += hw_watchpoint_use_count (b); | |
8895 | else if (is_hardware_watchpoint (b)) | |
8896 | *other_type_used = 1; | |
e09342b5 TJB |
8897 | } |
8898 | ||
c906108c SS |
8899 | return i; |
8900 | } | |
8901 | ||
c906108c | 8902 | void |
fba45db2 | 8903 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8904 | { |
c5aa993b | 8905 | struct breakpoint *b; |
c906108c SS |
8906 | |
8907 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8908 | { |
cc60f2e3 | 8909 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8910 | { |
b5de0fa7 | 8911 | b->enable_state = bp_call_disabled; |
b60e7edf | 8912 | update_global_location_list (0); |
c5aa993b JM |
8913 | } |
8914 | } | |
c906108c SS |
8915 | } |
8916 | ||
8917 | void | |
fba45db2 | 8918 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8919 | { |
c5aa993b | 8920 | struct breakpoint *b; |
c906108c SS |
8921 | |
8922 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8923 | { |
cc60f2e3 | 8924 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8925 | { |
b5de0fa7 | 8926 | b->enable_state = bp_enabled; |
b60e7edf | 8927 | update_global_location_list (1); |
c5aa993b JM |
8928 | } |
8929 | } | |
c906108c SS |
8930 | } |
8931 | ||
8bea4e01 UW |
8932 | void |
8933 | disable_breakpoints_before_startup (void) | |
8934 | { | |
6c95b8df | 8935 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8936 | update_global_location_list (0); |
8bea4e01 UW |
8937 | } |
8938 | ||
8939 | void | |
8940 | enable_breakpoints_after_startup (void) | |
8941 | { | |
6c95b8df | 8942 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8943 | breakpoint_re_set (); |
8bea4e01 UW |
8944 | } |
8945 | ||
c906108c SS |
8946 | |
8947 | /* Set a breakpoint that will evaporate an end of command | |
8948 | at address specified by SAL. | |
8949 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8950 | ||
8951 | struct breakpoint * | |
a6d9a66e UW |
8952 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8953 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8954 | { |
52f0bd74 | 8955 | struct breakpoint *b; |
edb3359d | 8956 | |
193facb3 JK |
8957 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8958 | tail-called one. */ | |
8959 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8960 | |
06edf0c0 | 8961 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8962 | b->enable_state = bp_enabled; |
8963 | b->disposition = disp_donttouch; | |
818dd999 | 8964 | b->frame_id = frame_id; |
c906108c | 8965 | |
4a64f543 MS |
8966 | /* If we're debugging a multi-threaded program, then we want |
8967 | momentary breakpoints to be active in only a single thread of | |
8968 | control. */ | |
39f77062 KB |
8969 | if (in_thread_list (inferior_ptid)) |
8970 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8971 | |
b60e7edf | 8972 | update_global_location_list_nothrow (1); |
74960c60 | 8973 | |
c906108c SS |
8974 | return b; |
8975 | } | |
611c83ae | 8976 | |
06edf0c0 PA |
8977 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8978 | The new breakpoint will have type TYPE, and use OPS as it | |
8979 | breakpoint_ops. */ | |
e58b0e63 | 8980 | |
06edf0c0 PA |
8981 | static struct breakpoint * |
8982 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8983 | enum bptype type, | |
c0a91b2b | 8984 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8985 | { |
8986 | struct breakpoint *copy; | |
8987 | ||
06edf0c0 | 8988 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8989 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8990 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8991 | |
a6d9a66e | 8992 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8993 | copy->loc->requested_address = orig->loc->requested_address; |
8994 | copy->loc->address = orig->loc->address; | |
8995 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8996 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8997 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8998 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8999 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
9000 | copy->frame_id = orig->frame_id; |
9001 | copy->thread = orig->thread; | |
6c95b8df | 9002 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9003 | |
9004 | copy->enable_state = bp_enabled; | |
9005 | copy->disposition = disp_donttouch; | |
9006 | copy->number = internal_breakpoint_number--; | |
9007 | ||
9008 | update_global_location_list_nothrow (0); | |
9009 | return copy; | |
9010 | } | |
9011 | ||
06edf0c0 PA |
9012 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9013 | ORIG is NULL. */ | |
9014 | ||
9015 | struct breakpoint * | |
9016 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9017 | { | |
9018 | /* If there's nothing to clone, then return nothing. */ | |
9019 | if (orig == NULL) | |
9020 | return NULL; | |
9021 | ||
9022 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
9023 | } | |
9024 | ||
611c83ae | 9025 | struct breakpoint * |
a6d9a66e UW |
9026 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9027 | enum bptype type) | |
611c83ae PA |
9028 | { |
9029 | struct symtab_and_line sal; | |
9030 | ||
9031 | sal = find_pc_line (pc, 0); | |
9032 | sal.pc = pc; | |
9033 | sal.section = find_pc_overlay (pc); | |
9034 | sal.explicit_pc = 1; | |
9035 | ||
a6d9a66e | 9036 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9037 | } |
c906108c | 9038 | \f |
c5aa993b | 9039 | |
c906108c SS |
9040 | /* Tell the user we have just set a breakpoint B. */ |
9041 | ||
9042 | static void | |
fba45db2 | 9043 | mention (struct breakpoint *b) |
c906108c | 9044 | { |
348d480f | 9045 | b->ops->print_mention (b); |
79a45e25 | 9046 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9047 | return; |
c906108c SS |
9048 | printf_filtered ("\n"); |
9049 | } | |
c906108c | 9050 | \f |
c5aa993b | 9051 | |
0d381245 | 9052 | static struct bp_location * |
39d61571 | 9053 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9054 | const struct symtab_and_line *sal) |
9055 | { | |
9056 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9057 | CORE_ADDR adjusted_address; |
9058 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9059 | ||
9060 | if (loc_gdbarch == NULL) | |
9061 | loc_gdbarch = b->gdbarch; | |
9062 | ||
9063 | /* Adjust the breakpoint's address prior to allocating a location. | |
9064 | Once we call allocate_bp_location(), that mostly uninitialized | |
9065 | location will be placed on the location chain. Adjustment of the | |
9066 | breakpoint may cause target_read_memory() to be called and we do | |
9067 | not want its scan of the location chain to find a breakpoint and | |
9068 | location that's only been partially initialized. */ | |
9069 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9070 | sal->pc, b->type); | |
0d381245 | 9071 | |
d30113d4 | 9072 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9073 | loc = allocate_bp_location (b); |
d30113d4 JK |
9074 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9075 | tmp = &((*tmp)->next)) | |
0d381245 | 9076 | ; |
d30113d4 | 9077 | loc->next = *tmp; |
0d381245 | 9078 | *tmp = loc; |
3742cc8b | 9079 | |
0d381245 | 9080 | loc->requested_address = sal->pc; |
3742cc8b | 9081 | loc->address = adjusted_address; |
6c95b8df | 9082 | loc->pspace = sal->pspace; |
729662a5 TT |
9083 | loc->probe.probe = sal->probe; |
9084 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9085 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9086 | loc->section = sal->section; |
3742cc8b | 9087 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9088 | loc->line_number = sal->line; |
2f202fde | 9089 | loc->symtab = sal->symtab; |
f8eba3c6 | 9090 | |
0e30163f JK |
9091 | set_breakpoint_location_function (loc, |
9092 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
9093 | return loc; |
9094 | } | |
514f746b AR |
9095 | \f |
9096 | ||
9097 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9098 | return 0 otherwise. */ | |
9099 | ||
9100 | static int | |
9101 | bp_loc_is_permanent (struct bp_location *loc) | |
9102 | { | |
9103 | int len; | |
9104 | CORE_ADDR addr; | |
1afeeb75 | 9105 | const gdb_byte *bpoint; |
514f746b | 9106 | gdb_byte *target_mem; |
939c61fa JK |
9107 | struct cleanup *cleanup; |
9108 | int retval = 0; | |
514f746b AR |
9109 | |
9110 | gdb_assert (loc != NULL); | |
9111 | ||
9112 | addr = loc->address; | |
1afeeb75 | 9113 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9114 | |
939c61fa | 9115 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9116 | if (bpoint == NULL) |
939c61fa JK |
9117 | return 0; |
9118 | ||
514f746b AR |
9119 | target_mem = alloca (len); |
9120 | ||
939c61fa JK |
9121 | /* Enable the automatic memory restoration from breakpoints while |
9122 | we read the memory. Otherwise we could say about our temporary | |
9123 | breakpoints they are permanent. */ | |
6c95b8df PA |
9124 | cleanup = save_current_space_and_thread (); |
9125 | ||
9126 | switch_to_program_space_and_thread (loc->pspace); | |
9127 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9128 | |
514f746b | 9129 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9130 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9131 | retval = 1; |
514f746b | 9132 | |
939c61fa JK |
9133 | do_cleanups (cleanup); |
9134 | ||
9135 | return retval; | |
514f746b AR |
9136 | } |
9137 | ||
e7e0cddf SS |
9138 | /* Build a command list for the dprintf corresponding to the current |
9139 | settings of the dprintf style options. */ | |
9140 | ||
9141 | static void | |
9142 | update_dprintf_command_list (struct breakpoint *b) | |
9143 | { | |
9144 | char *dprintf_args = b->extra_string; | |
9145 | char *printf_line = NULL; | |
9146 | ||
9147 | if (!dprintf_args) | |
9148 | return; | |
9149 | ||
9150 | dprintf_args = skip_spaces (dprintf_args); | |
9151 | ||
9152 | /* Allow a comma, as it may have terminated a location, but don't | |
9153 | insist on it. */ | |
9154 | if (*dprintf_args == ',') | |
9155 | ++dprintf_args; | |
9156 | dprintf_args = skip_spaces (dprintf_args); | |
9157 | ||
9158 | if (*dprintf_args != '"') | |
9159 | error (_("Bad format string, missing '\"'.")); | |
9160 | ||
d3ce09f5 | 9161 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9162 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9163 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9164 | { |
9165 | if (!dprintf_function) | |
9166 | error (_("No function supplied for dprintf call")); | |
9167 | ||
9168 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9169 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9170 | dprintf_function, | |
9171 | dprintf_channel, | |
9172 | dprintf_args); | |
9173 | else | |
9174 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9175 | dprintf_function, | |
9176 | dprintf_args); | |
9177 | } | |
d3ce09f5 SS |
9178 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9179 | { | |
9180 | if (target_can_run_breakpoint_commands ()) | |
9181 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9182 | else | |
9183 | { | |
9184 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9185 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9186 | } | |
9187 | } | |
e7e0cddf SS |
9188 | else |
9189 | internal_error (__FILE__, __LINE__, | |
9190 | _("Invalid dprintf style.")); | |
9191 | ||
f28045c2 | 9192 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9193 | /* Manufacture a printf sequence. */ |
f28045c2 | 9194 | { |
9d6e6e84 HZ |
9195 | struct command_line *printf_cmd_line |
9196 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9197 | |
f28045c2 YQ |
9198 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9199 | printf_cmd_line->control_type = simple_control; | |
9200 | printf_cmd_line->body_count = 0; | |
9201 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9202 | printf_cmd_line->next = NULL; |
f28045c2 | 9203 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9204 | |
f28045c2 YQ |
9205 | breakpoint_set_commands (b, printf_cmd_line); |
9206 | } | |
e7e0cddf SS |
9207 | } |
9208 | ||
9209 | /* Update all dprintf commands, making their command lists reflect | |
9210 | current style settings. */ | |
9211 | ||
9212 | static void | |
9213 | update_dprintf_commands (char *args, int from_tty, | |
9214 | struct cmd_list_element *c) | |
9215 | { | |
9216 | struct breakpoint *b; | |
9217 | ||
9218 | ALL_BREAKPOINTS (b) | |
9219 | { | |
9220 | if (b->type == bp_dprintf) | |
9221 | update_dprintf_command_list (b); | |
9222 | } | |
9223 | } | |
c3f6f71d | 9224 | |
018d34a4 VP |
9225 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9226 | as textual description of the location, and COND_STRING | |
db107f19 | 9227 | as condition expression. */ |
018d34a4 VP |
9228 | |
9229 | static void | |
d9b3f62e PA |
9230 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9231 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9232 | char *filter, char *cond_string, |
e7e0cddf | 9233 | char *extra_string, |
d9b3f62e PA |
9234 | enum bptype type, enum bpdisp disposition, |
9235 | int thread, int task, int ignore_count, | |
c0a91b2b | 9236 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9237 | int enabled, int internal, unsigned flags, |
9238 | int display_canonical) | |
018d34a4 | 9239 | { |
0d381245 | 9240 | int i; |
018d34a4 VP |
9241 | |
9242 | if (type == bp_hardware_breakpoint) | |
9243 | { | |
fbbd034e AS |
9244 | int target_resources_ok; |
9245 | ||
9246 | i = hw_breakpoint_used_count (); | |
9247 | target_resources_ok = | |
9248 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9249 | i + 1, 0); |
9250 | if (target_resources_ok == 0) | |
9251 | error (_("No hardware breakpoint support in the target.")); | |
9252 | else if (target_resources_ok < 0) | |
9253 | error (_("Hardware breakpoints used exceeds limit.")); | |
9254 | } | |
9255 | ||
6c95b8df PA |
9256 | gdb_assert (sals.nelts > 0); |
9257 | ||
0d381245 VP |
9258 | for (i = 0; i < sals.nelts; ++i) |
9259 | { | |
9260 | struct symtab_and_line sal = sals.sals[i]; | |
9261 | struct bp_location *loc; | |
9262 | ||
9263 | if (from_tty) | |
5af949e3 UW |
9264 | { |
9265 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9266 | if (!loc_gdbarch) | |
9267 | loc_gdbarch = gdbarch; | |
9268 | ||
9269 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9270 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9271 | } |
0d381245 VP |
9272 | |
9273 | if (i == 0) | |
9274 | { | |
d9b3f62e | 9275 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9276 | b->thread = thread; |
4a306c9a | 9277 | b->task = task; |
855a6e68 | 9278 | |
0d381245 | 9279 | b->cond_string = cond_string; |
e7e0cddf | 9280 | b->extra_string = extra_string; |
0d381245 | 9281 | b->ignore_count = ignore_count; |
41447f92 | 9282 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9283 | b->disposition = disposition; |
6c95b8df | 9284 | |
44f238bb PA |
9285 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9286 | b->loc->inserted = 1; | |
9287 | ||
0fb4aa4b PA |
9288 | if (type == bp_static_tracepoint) |
9289 | { | |
d9b3f62e | 9290 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9291 | struct static_tracepoint_marker marker; |
9292 | ||
983af33b | 9293 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9294 | { |
9295 | /* We already know the marker exists, otherwise, we | |
9296 | wouldn't see a sal for it. */ | |
9297 | char *p = &addr_string[3]; | |
9298 | char *endp; | |
9299 | char *marker_str; | |
0fb4aa4b | 9300 | |
e9cafbcc | 9301 | p = skip_spaces (p); |
0fb4aa4b | 9302 | |
e9cafbcc | 9303 | endp = skip_to_space (p); |
0fb4aa4b PA |
9304 | |
9305 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9306 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9307 | |
3e43a32a MS |
9308 | printf_filtered (_("Probed static tracepoint " |
9309 | "marker \"%s\"\n"), | |
d9b3f62e | 9310 | t->static_trace_marker_id); |
0fb4aa4b PA |
9311 | } |
9312 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9313 | { | |
d9b3f62e | 9314 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9315 | release_static_tracepoint_marker (&marker); |
9316 | ||
3e43a32a MS |
9317 | printf_filtered (_("Probed static tracepoint " |
9318 | "marker \"%s\"\n"), | |
d9b3f62e | 9319 | t->static_trace_marker_id); |
0fb4aa4b PA |
9320 | } |
9321 | else | |
3e43a32a MS |
9322 | warning (_("Couldn't determine the static " |
9323 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9324 | } |
9325 | ||
0d381245 VP |
9326 | loc = b->loc; |
9327 | } | |
9328 | else | |
018d34a4 | 9329 | { |
39d61571 | 9330 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9331 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9332 | loc->inserted = 1; | |
0d381245 VP |
9333 | } |
9334 | ||
514f746b AR |
9335 | if (bp_loc_is_permanent (loc)) |
9336 | make_breakpoint_permanent (b); | |
9337 | ||
0d381245 VP |
9338 | if (b->cond_string) |
9339 | { | |
bbc13ae3 KS |
9340 | const char *arg = b->cond_string; |
9341 | ||
1bb9788d TT |
9342 | loc->cond = parse_exp_1 (&arg, loc->address, |
9343 | block_for_pc (loc->address), 0); | |
0d381245 | 9344 | if (*arg) |
588ae58c | 9345 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9346 | } |
e7e0cddf SS |
9347 | |
9348 | /* Dynamic printf requires and uses additional arguments on the | |
9349 | command line, otherwise it's an error. */ | |
9350 | if (type == bp_dprintf) | |
9351 | { | |
9352 | if (b->extra_string) | |
9353 | update_dprintf_command_list (b); | |
9354 | else | |
9355 | error (_("Format string required")); | |
9356 | } | |
9357 | else if (b->extra_string) | |
588ae58c | 9358 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9359 | } |
018d34a4 | 9360 | |
56435ebe | 9361 | b->display_canonical = display_canonical; |
018d34a4 VP |
9362 | if (addr_string) |
9363 | b->addr_string = addr_string; | |
9364 | else | |
9365 | /* addr_string has to be used or breakpoint_re_set will delete | |
9366 | me. */ | |
5af949e3 UW |
9367 | b->addr_string |
9368 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9369 | b->filter = filter; |
d9b3f62e | 9370 | } |
018d34a4 | 9371 | |
d9b3f62e PA |
9372 | static void |
9373 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9374 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9375 | char *filter, char *cond_string, |
e7e0cddf | 9376 | char *extra_string, |
d9b3f62e PA |
9377 | enum bptype type, enum bpdisp disposition, |
9378 | int thread, int task, int ignore_count, | |
c0a91b2b | 9379 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9380 | int enabled, int internal, unsigned flags, |
9381 | int display_canonical) | |
d9b3f62e PA |
9382 | { |
9383 | struct breakpoint *b; | |
9384 | struct cleanup *old_chain; | |
9385 | ||
9386 | if (is_tracepoint_type (type)) | |
9387 | { | |
9388 | struct tracepoint *t; | |
9389 | ||
9390 | t = XCNEW (struct tracepoint); | |
9391 | b = &t->base; | |
9392 | } | |
9393 | else | |
9394 | b = XNEW (struct breakpoint); | |
9395 | ||
9396 | old_chain = make_cleanup (xfree, b); | |
9397 | ||
9398 | init_breakpoint_sal (b, gdbarch, | |
9399 | sals, addr_string, | |
e7e0cddf | 9400 | filter, cond_string, extra_string, |
d9b3f62e PA |
9401 | type, disposition, |
9402 | thread, task, ignore_count, | |
9403 | ops, from_tty, | |
44f238bb PA |
9404 | enabled, internal, flags, |
9405 | display_canonical); | |
d9b3f62e PA |
9406 | discard_cleanups (old_chain); |
9407 | ||
3ea46bff | 9408 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9409 | } |
9410 | ||
9411 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9412 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9413 | value. COND_STRING, if not NULL, specified the condition to be | |
9414 | used for all breakpoints. Essentially the only case where | |
9415 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9416 | function. In that case, it's still not possible to specify | |
9417 | separate conditions for different overloaded functions, so | |
9418 | we take just a single condition string. | |
9419 | ||
c3f6f71d | 9420 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9421 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9422 | array contents). If the function fails (error() is called), the |
9423 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9424 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9425 | |
9426 | static void | |
8cdf0e15 | 9427 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9428 | struct linespec_result *canonical, |
e7e0cddf | 9429 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9430 | enum bptype type, enum bpdisp disposition, |
9431 | int thread, int task, int ignore_count, | |
c0a91b2b | 9432 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9433 | int enabled, int internal, unsigned flags) |
c906108c | 9434 | { |
018d34a4 | 9435 | int i; |
f8eba3c6 | 9436 | struct linespec_sals *lsal; |
cc59ec59 | 9437 | |
f8eba3c6 TT |
9438 | if (canonical->pre_expanded) |
9439 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9440 | ||
9441 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9442 | { |
f8eba3c6 TT |
9443 | /* Note that 'addr_string' can be NULL in the case of a plain |
9444 | 'break', without arguments. */ | |
9445 | char *addr_string = (canonical->addr_string | |
9446 | ? xstrdup (canonical->addr_string) | |
9447 | : NULL); | |
9448 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9449 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9450 | |
f8eba3c6 TT |
9451 | make_cleanup (xfree, filter_string); |
9452 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9453 | addr_string, | |
9454 | filter_string, | |
e7e0cddf SS |
9455 | cond_string, extra_string, |
9456 | type, disposition, | |
84f4c1fe | 9457 | thread, task, ignore_count, ops, |
44f238bb | 9458 | from_tty, enabled, internal, flags, |
56435ebe | 9459 | canonical->special_display); |
f8eba3c6 | 9460 | discard_cleanups (inner); |
c3f6f71d | 9461 | } |
c3f6f71d | 9462 | } |
c906108c | 9463 | |
9998af43 | 9464 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9465 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9466 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9467 | address strings. ADDRESS points to the end of the SAL. |
9468 | ||
9469 | The array and the line spec strings are allocated on the heap, it is | |
9470 | the caller's responsibility to free them. */ | |
c906108c | 9471 | |
b9362cc7 | 9472 | static void |
c3f6f71d | 9473 | parse_breakpoint_sals (char **address, |
58438ac1 | 9474 | struct linespec_result *canonical) |
c3f6f71d | 9475 | { |
c3f6f71d | 9476 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9477 | breakpoint. */ |
c3f6f71d JM |
9478 | if ((*address) == NULL |
9479 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9480 | { |
1bfeeb0f JL |
9481 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9482 | address. */ | |
9483 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9484 | { |
f8eba3c6 | 9485 | struct linespec_sals lsal; |
c3f6f71d | 9486 | struct symtab_and_line sal; |
1c8cdcb1 | 9487 | CORE_ADDR pc; |
cc59ec59 | 9488 | |
4a64f543 | 9489 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9490 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9491 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9492 | |
9493 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9494 | corresponding to the last call to print_frame_info. |
9495 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9496 | as the breakpoint line number is inappropriate otherwise. | |
9497 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9498 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9499 | pc = sal.pc; |
9500 | sal = find_pc_line (pc, 0); | |
00903456 | 9501 | |
4a64f543 | 9502 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9503 | where PC is the last displayed codepoint's address. So |
9504 | make sure to set sal.explicit_pc to prevent GDB from | |
9505 | trying to expand the list of sals to include all other | |
9506 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9507 | sal.pc = pc; |
00903456 JK |
9508 | sal.explicit_pc = 1; |
9509 | ||
f8eba3c6 TT |
9510 | lsal.sals.sals[0] = sal; |
9511 | lsal.sals.nelts = 1; | |
9512 | lsal.canonical = NULL; | |
9513 | ||
9514 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9515 | } |
9516 | else | |
8a3fe4f8 | 9517 | error (_("No default breakpoint address now.")); |
c906108c SS |
9518 | } |
9519 | else | |
9520 | { | |
cc80f267 JK |
9521 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9522 | ||
c906108c | 9523 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9524 | current_source_symtab (which is decode_line_1's default). |
9525 | This should produce the results we want almost all of the | |
cc80f267 JK |
9526 | time while leaving default_breakpoint_* alone. |
9527 | ||
9528 | ObjC: However, don't match an Objective-C method name which | |
9529 | may have a '+' or '-' succeeded by a '['. */ | |
9530 | if (last_displayed_sal_is_valid () | |
9531 | && (!cursal.symtab | |
9532 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9533 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9534 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9535 | get_last_displayed_symtab (), | |
9536 | get_last_displayed_line (), | |
9537 | canonical, NULL, NULL); | |
c906108c | 9538 | else |
f8eba3c6 | 9539 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9540 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9541 | } |
c3f6f71d | 9542 | } |
c906108c | 9543 | |
c906108c | 9544 | |
c3f6f71d | 9545 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9546 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9547 | |
b9362cc7 | 9548 | static void |
23e7acfb | 9549 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9550 | { |
9551 | int i; | |
cc59ec59 | 9552 | |
c3f6f71d | 9553 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9554 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9555 | } |
9556 | ||
7a697b8d SS |
9557 | /* Fast tracepoints may have restrictions on valid locations. For |
9558 | instance, a fast tracepoint using a jump instead of a trap will | |
9559 | likely have to overwrite more bytes than a trap would, and so can | |
9560 | only be placed where the instruction is longer than the jump, or a | |
9561 | multi-instruction sequence does not have a jump into the middle of | |
9562 | it, etc. */ | |
9563 | ||
9564 | static void | |
9565 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9566 | struct symtabs_and_lines *sals) | |
9567 | { | |
9568 | int i, rslt; | |
9569 | struct symtab_and_line *sal; | |
9570 | char *msg; | |
9571 | struct cleanup *old_chain; | |
9572 | ||
9573 | for (i = 0; i < sals->nelts; i++) | |
9574 | { | |
f8eba3c6 TT |
9575 | struct gdbarch *sarch; |
9576 | ||
7a697b8d SS |
9577 | sal = &sals->sals[i]; |
9578 | ||
f8eba3c6 TT |
9579 | sarch = get_sal_arch (*sal); |
9580 | /* We fall back to GDBARCH if there is no architecture | |
9581 | associated with SAL. */ | |
9582 | if (sarch == NULL) | |
9583 | sarch = gdbarch; | |
9584 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9585 | NULL, &msg); |
9586 | old_chain = make_cleanup (xfree, msg); | |
9587 | ||
9588 | if (!rslt) | |
9589 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9590 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9591 | |
9592 | do_cleanups (old_chain); | |
9593 | } | |
9594 | } | |
9595 | ||
af4908ba KS |
9596 | /* Issue an invalid thread ID error. */ |
9597 | ||
9598 | static void ATTRIBUTE_NORETURN | |
9599 | invalid_thread_id_error (int id) | |
9600 | { | |
9601 | error (_("Unknown thread %d."), id); | |
9602 | } | |
9603 | ||
018d34a4 VP |
9604 | /* Given TOK, a string specification of condition and thread, as |
9605 | accepted by the 'break' command, extract the condition | |
9606 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9607 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9608 | If no condition is found, *COND_STRING is set to NULL. |
9609 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9610 | |
9611 | static void | |
bbc13ae3 | 9612 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9613 | char **cond_string, int *thread, int *task, |
9614 | char **rest) | |
018d34a4 VP |
9615 | { |
9616 | *cond_string = NULL; | |
9617 | *thread = -1; | |
ed1d1739 KS |
9618 | *task = 0; |
9619 | *rest = NULL; | |
9620 | ||
018d34a4 VP |
9621 | while (tok && *tok) |
9622 | { | |
bbc13ae3 | 9623 | const char *end_tok; |
018d34a4 | 9624 | int toklen; |
bbc13ae3 KS |
9625 | const char *cond_start = NULL; |
9626 | const char *cond_end = NULL; | |
cc59ec59 | 9627 | |
bbc13ae3 | 9628 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9629 | |
9630 | if ((*tok == '"' || *tok == ',') && rest) | |
9631 | { | |
9632 | *rest = savestring (tok, strlen (tok)); | |
9633 | return; | |
9634 | } | |
9635 | ||
bbc13ae3 | 9636 | end_tok = skip_to_space_const (tok); |
d634f2de | 9637 | |
018d34a4 | 9638 | toklen = end_tok - tok; |
d634f2de | 9639 | |
018d34a4 VP |
9640 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9641 | { | |
f7545552 TT |
9642 | struct expression *expr; |
9643 | ||
018d34a4 | 9644 | tok = cond_start = end_tok + 1; |
1bb9788d | 9645 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9646 | xfree (expr); |
018d34a4 | 9647 | cond_end = tok; |
d634f2de | 9648 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9649 | } |
9650 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9651 | { | |
9652 | char *tmptok; | |
d634f2de | 9653 | |
018d34a4 | 9654 | tok = end_tok + 1; |
bbc13ae3 | 9655 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9656 | if (tok == tmptok) |
9657 | error (_("Junk after thread keyword.")); | |
9658 | if (!valid_thread_id (*thread)) | |
af4908ba | 9659 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9660 | tok = tmptok; |
018d34a4 | 9661 | } |
4a306c9a JB |
9662 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9663 | { | |
9664 | char *tmptok; | |
9665 | ||
9666 | tok = end_tok + 1; | |
bbc13ae3 | 9667 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9668 | if (tok == tmptok) |
9669 | error (_("Junk after task keyword.")); | |
9670 | if (!valid_task_id (*task)) | |
b6199126 | 9671 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9672 | tok = tmptok; |
4a306c9a | 9673 | } |
e7e0cddf SS |
9674 | else if (rest) |
9675 | { | |
9676 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9677 | return; |
e7e0cddf | 9678 | } |
018d34a4 VP |
9679 | else |
9680 | error (_("Junk at end of arguments.")); | |
9681 | } | |
9682 | } | |
9683 | ||
0fb4aa4b PA |
9684 | /* Decode a static tracepoint marker spec. */ |
9685 | ||
9686 | static struct symtabs_and_lines | |
9687 | decode_static_tracepoint_spec (char **arg_p) | |
9688 | { | |
9689 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9690 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9691 | struct cleanup *old_chain; |
9692 | char *p = &(*arg_p)[3]; | |
9693 | char *endp; | |
9694 | char *marker_str; | |
9695 | int i; | |
9696 | ||
e9cafbcc | 9697 | p = skip_spaces (p); |
0fb4aa4b | 9698 | |
e9cafbcc | 9699 | endp = skip_to_space (p); |
0fb4aa4b PA |
9700 | |
9701 | marker_str = savestring (p, endp - p); | |
9702 | old_chain = make_cleanup (xfree, marker_str); | |
9703 | ||
9704 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9705 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9706 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9707 | ||
9708 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9709 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9710 | ||
9711 | for (i = 0; i < sals.nelts; i++) | |
9712 | { | |
9713 | struct static_tracepoint_marker *marker; | |
9714 | ||
9715 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9716 | ||
9717 | init_sal (&sals.sals[i]); | |
9718 | ||
9719 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9720 | sals.sals[i].pc = marker->address; | |
9721 | ||
9722 | release_static_tracepoint_marker (marker); | |
9723 | } | |
9724 | ||
9725 | do_cleanups (old_chain); | |
9726 | ||
9727 | *arg_p = endp; | |
9728 | return sals; | |
9729 | } | |
9730 | ||
fd9b8c24 PA |
9731 | /* Set a breakpoint. This function is shared between CLI and MI |
9732 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9733 | modes of operations, selected by the PARSE_ARG parameter. If |
9734 | non-zero, the function will parse ARG, extracting location, | |
9735 | condition, thread and extra string. Otherwise, ARG is just the | |
9736 | breakpoint's location, with condition, thread, and extra string | |
9737 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9738 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9739 | from the internal breakpoint count. Returns true if any breakpoint | |
9740 | was created; false otherwise. */ | |
0101ce28 | 9741 | |
8cdf0e15 VP |
9742 | int |
9743 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9744 | char *arg, char *cond_string, |
9745 | int thread, char *extra_string, | |
f6de8ec2 | 9746 | int parse_arg, |
0fb4aa4b | 9747 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9748 | int ignore_count, |
9749 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9750 | const struct breakpoint_ops *ops, |
44f238bb PA |
9751 | int from_tty, int enabled, int internal, |
9752 | unsigned flags) | |
c3f6f71d | 9753 | { |
b78a6381 | 9754 | volatile struct gdb_exception e; |
f8eba3c6 | 9755 | char *copy_arg = NULL; |
c3f6f71d | 9756 | char *addr_start = arg; |
7efd8fc2 | 9757 | struct linespec_result canonical; |
c3f6f71d | 9758 | struct cleanup *old_chain; |
80c99de1 | 9759 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9760 | int pending = 0; |
4a306c9a | 9761 | int task = 0; |
86b17b60 | 9762 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9763 | |
348d480f PA |
9764 | gdb_assert (ops != NULL); |
9765 | ||
7efd8fc2 | 9766 | init_linespec_result (&canonical); |
c3f6f71d | 9767 | |
b78a6381 TT |
9768 | TRY_CATCH (e, RETURN_MASK_ALL) |
9769 | { | |
983af33b SDJ |
9770 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9771 | addr_start, ©_arg); | |
b78a6381 | 9772 | } |
0101ce28 JJ |
9773 | |
9774 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9775 | switch (e.reason) |
0101ce28 | 9776 | { |
983af33b SDJ |
9777 | case GDB_NO_ERROR: |
9778 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9779 | return 0; | |
9780 | break; | |
05ff989b AC |
9781 | case RETURN_ERROR: |
9782 | switch (e.error) | |
0101ce28 | 9783 | { |
05ff989b | 9784 | case NOT_FOUND_ERROR: |
0101ce28 | 9785 | |
05ff989b AC |
9786 | /* If pending breakpoint support is turned off, throw |
9787 | error. */ | |
fa8d40ab JJ |
9788 | |
9789 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9790 | throw_exception (e); |
9791 | ||
9792 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9793 | |
05ff989b AC |
9794 | /* If pending breakpoint support is auto query and the user |
9795 | selects no, then simply return the error code. */ | |
059fb39f | 9796 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9797 | && !nquery (_("Make %s pending on future shared library load? "), |
9798 | bptype_string (type_wanted))) | |
fd9b8c24 | 9799 | return 0; |
fa8d40ab | 9800 | |
05ff989b AC |
9801 | /* At this point, either the user was queried about setting |
9802 | a pending breakpoint and selected yes, or pending | |
9803 | breakpoint behavior is on and thus a pending breakpoint | |
9804 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9805 | { |
9806 | struct linespec_sals lsal; | |
9807 | ||
9808 | copy_arg = xstrdup (addr_start); | |
9809 | lsal.canonical = xstrdup (copy_arg); | |
9810 | lsal.sals.nelts = 1; | |
9811 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9812 | init_sal (&lsal.sals.sals[0]); | |
9813 | pending = 1; | |
9814 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9815 | } | |
05ff989b AC |
9816 | break; |
9817 | default: | |
98deb0da | 9818 | throw_exception (e); |
0101ce28 | 9819 | } |
2abae994 | 9820 | break; |
05ff989b | 9821 | default: |
983af33b | 9822 | throw_exception (e); |
0101ce28 | 9823 | } |
c3f6f71d | 9824 | |
4a64f543 | 9825 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9826 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9827 | |
c3f6f71d JM |
9828 | /* ----------------------------- SNIP ----------------------------- |
9829 | Anything added to the cleanup chain beyond this point is assumed | |
9830 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9831 | then the memory is not reclaimed. */ |
9832 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9833 | |
c3f6f71d JM |
9834 | /* Resolve all line numbers to PC's and verify that the addresses |
9835 | are ok for the target. */ | |
0101ce28 | 9836 | if (!pending) |
f8eba3c6 TT |
9837 | { |
9838 | int ix; | |
9839 | struct linespec_sals *iter; | |
9840 | ||
9841 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9842 | breakpoint_sals_to_pc (&iter->sals); | |
9843 | } | |
c3f6f71d | 9844 | |
7a697b8d | 9845 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9846 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9847 | { |
9848 | int ix; | |
9849 | struct linespec_sals *iter; | |
9850 | ||
9851 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9852 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9853 | } | |
7a697b8d | 9854 | |
c3f6f71d JM |
9855 | /* Verify that condition can be parsed, before setting any |
9856 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9857 | breakpoint. */ |
0101ce28 | 9858 | if (!pending) |
c3f6f71d | 9859 | { |
f6de8ec2 | 9860 | if (parse_arg) |
72b2ff0e | 9861 | { |
0878d0fa | 9862 | char *rest; |
52d361e1 YQ |
9863 | struct linespec_sals *lsal; |
9864 | ||
9865 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9866 | ||
0878d0fa YQ |
9867 | /* Here we only parse 'arg' to separate condition |
9868 | from thread number, so parsing in context of first | |
9869 | sal is OK. When setting the breakpoint we'll | |
9870 | re-parse it in context of each sal. */ | |
9871 | ||
9872 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9873 | &thread, &task, &rest); | |
9874 | if (cond_string) | |
9875 | make_cleanup (xfree, cond_string); | |
9876 | if (rest) | |
9877 | make_cleanup (xfree, rest); | |
9878 | if (rest) | |
9879 | extra_string = rest; | |
72b2ff0e | 9880 | } |
2f069f6f | 9881 | else |
72b2ff0e | 9882 | { |
0878d0fa YQ |
9883 | if (*arg != '\0') |
9884 | error (_("Garbage '%s' at end of location"), arg); | |
9885 | ||
9886 | /* Create a private copy of condition string. */ | |
9887 | if (cond_string) | |
9888 | { | |
9889 | cond_string = xstrdup (cond_string); | |
9890 | make_cleanup (xfree, cond_string); | |
9891 | } | |
9892 | /* Create a private copy of any extra string. */ | |
9893 | if (extra_string) | |
9894 | { | |
9895 | extra_string = xstrdup (extra_string); | |
9896 | make_cleanup (xfree, extra_string); | |
9897 | } | |
72b2ff0e | 9898 | } |
0fb4aa4b | 9899 | |
52d361e1 | 9900 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9901 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9902 | tempflag ? disp_del : disp_donttouch, |
9903 | thread, task, ignore_count, ops, | |
44f238bb | 9904 | from_tty, enabled, internal, flags); |
c906108c | 9905 | } |
0101ce28 JJ |
9906 | else |
9907 | { | |
0101ce28 JJ |
9908 | struct breakpoint *b; |
9909 | ||
0101ce28 JJ |
9910 | make_cleanup (xfree, copy_arg); |
9911 | ||
bfccc43c YQ |
9912 | if (is_tracepoint_type (type_wanted)) |
9913 | { | |
9914 | struct tracepoint *t; | |
9915 | ||
9916 | t = XCNEW (struct tracepoint); | |
9917 | b = &t->base; | |
9918 | } | |
9919 | else | |
9920 | b = XNEW (struct breakpoint); | |
9921 | ||
9922 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9923 | ||
f8eba3c6 | 9924 | b->addr_string = copy_arg; |
f6de8ec2 | 9925 | if (parse_arg) |
e12c7713 MK |
9926 | b->cond_string = NULL; |
9927 | else | |
9928 | { | |
9929 | /* Create a private copy of condition string. */ | |
9930 | if (cond_string) | |
9931 | { | |
9932 | cond_string = xstrdup (cond_string); | |
9933 | make_cleanup (xfree, cond_string); | |
9934 | } | |
9935 | b->cond_string = cond_string; | |
9936 | } | |
e7e0cddf | 9937 | b->extra_string = NULL; |
0101ce28 | 9938 | b->ignore_count = ignore_count; |
0101ce28 | 9939 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9940 | b->condition_not_parsed = 1; |
41447f92 | 9941 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9942 | if ((type_wanted != bp_breakpoint |
9943 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9944 | b->pspace = current_program_space; |
8bea4e01 | 9945 | |
bfccc43c | 9946 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9947 | } |
9948 | ||
f8eba3c6 | 9949 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9950 | { |
3e43a32a MS |
9951 | warning (_("Multiple breakpoints were set.\nUse the " |
9952 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9953 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9954 | } |
9955 | ||
80c99de1 PA |
9956 | /* That's it. Discard the cleanups for data inserted into the |
9957 | breakpoint. */ | |
9958 | discard_cleanups (bkpt_chain); | |
9959 | /* But cleanup everything else. */ | |
c3f6f71d | 9960 | do_cleanups (old_chain); |
217dc9e2 | 9961 | |
80c99de1 | 9962 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9963 | update_global_location_list (1); |
fd9b8c24 PA |
9964 | |
9965 | return 1; | |
c3f6f71d | 9966 | } |
c906108c | 9967 | |
348d480f | 9968 | /* Set a breakpoint. |
72b2ff0e VP |
9969 | ARG is a string describing breakpoint address, |
9970 | condition, and thread. | |
9971 | FLAG specifies if a breakpoint is hardware on, | |
9972 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9973 | and BP_TEMPFLAG. */ | |
348d480f | 9974 | |
98deb0da | 9975 | static void |
72b2ff0e | 9976 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9977 | { |
72b2ff0e | 9978 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9979 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9980 | ? bp_hardware_breakpoint | |
9981 | : bp_breakpoint); | |
55aa24fb SDJ |
9982 | struct breakpoint_ops *ops; |
9983 | const char *arg_cp = arg; | |
9984 | ||
9985 | /* Matching breakpoints on probes. */ | |
9986 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9987 | ops = &bkpt_probe_breakpoint_ops; | |
9988 | else | |
9989 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9990 | |
8cdf0e15 VP |
9991 | create_breakpoint (get_current_arch (), |
9992 | arg, | |
e7e0cddf | 9993 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9994 | tempflag, type_wanted, |
8cdf0e15 VP |
9995 | 0 /* Ignore count */, |
9996 | pending_break_support, | |
55aa24fb | 9997 | ops, |
8cdf0e15 | 9998 | from_tty, |
84f4c1fe | 9999 | 1 /* enabled */, |
44f238bb PA |
10000 | 0 /* internal */, |
10001 | 0); | |
c906108c SS |
10002 | } |
10003 | ||
c906108c SS |
10004 | /* Helper function for break_command_1 and disassemble_command. */ |
10005 | ||
10006 | void | |
fba45db2 | 10007 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10008 | { |
10009 | CORE_ADDR pc; | |
10010 | ||
10011 | if (sal->pc == 0 && sal->symtab != NULL) | |
10012 | { | |
10013 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10014 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10015 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10016 | sal->pc = pc; |
6a048695 | 10017 | |
4a64f543 MS |
10018 | /* If this SAL corresponds to a breakpoint inserted using a line |
10019 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10020 | if (sal->explicit_line) |
059acae7 | 10021 | skip_prologue_sal (sal); |
c906108c SS |
10022 | } |
10023 | ||
10024 | if (sal->section == 0 && sal->symtab != NULL) | |
10025 | { | |
10026 | struct blockvector *bv; | |
c5aa993b JM |
10027 | struct block *b; |
10028 | struct symbol *sym; | |
c906108c | 10029 | |
801e3a5b | 10030 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
10031 | if (bv != NULL) |
10032 | { | |
7f0df278 | 10033 | sym = block_linkage_function (b); |
c906108c SS |
10034 | if (sym != NULL) |
10035 | { | |
10036 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 10037 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
10038 | } |
10039 | else | |
10040 | { | |
4a64f543 MS |
10041 | /* It really is worthwhile to have the section, so we'll |
10042 | just have to look harder. This case can be executed | |
10043 | if we have line numbers but no functions (as can | |
10044 | happen in assembly source). */ | |
c906108c | 10045 | |
7cbd4a93 | 10046 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10047 | struct cleanup *old_chain = save_current_space_and_thread (); |
10048 | ||
10049 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10050 | |
10051 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10052 | if (msym.minsym) |
efd66ac6 | 10053 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10054 | |
10055 | do_cleanups (old_chain); | |
c906108c SS |
10056 | } |
10057 | } | |
10058 | } | |
10059 | } | |
10060 | ||
10061 | void | |
fba45db2 | 10062 | break_command (char *arg, int from_tty) |
c906108c | 10063 | { |
db107f19 | 10064 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10065 | } |
10066 | ||
c906108c | 10067 | void |
fba45db2 | 10068 | tbreak_command (char *arg, int from_tty) |
c906108c | 10069 | { |
db107f19 | 10070 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10071 | } |
10072 | ||
c906108c | 10073 | static void |
fba45db2 | 10074 | hbreak_command (char *arg, int from_tty) |
c906108c | 10075 | { |
db107f19 | 10076 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10077 | } |
10078 | ||
10079 | static void | |
fba45db2 | 10080 | thbreak_command (char *arg, int from_tty) |
c906108c | 10081 | { |
db107f19 | 10082 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10083 | } |
10084 | ||
10085 | static void | |
fba45db2 | 10086 | stop_command (char *arg, int from_tty) |
c906108c | 10087 | { |
a3f17187 | 10088 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10089 | Usage: stop in <function | address>\n\ |
a3f17187 | 10090 | stop at <line>\n")); |
c906108c SS |
10091 | } |
10092 | ||
10093 | static void | |
fba45db2 | 10094 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10095 | { |
10096 | int badInput = 0; | |
10097 | ||
c5aa993b | 10098 | if (arg == (char *) NULL) |
c906108c SS |
10099 | badInput = 1; |
10100 | else if (*arg != '*') | |
10101 | { | |
10102 | char *argptr = arg; | |
10103 | int hasColon = 0; | |
10104 | ||
4a64f543 | 10105 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10106 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10107 | function/method name. */ |
c906108c | 10108 | while (*argptr && !hasColon) |
c5aa993b JM |
10109 | { |
10110 | hasColon = (*argptr == ':'); | |
10111 | argptr++; | |
10112 | } | |
c906108c SS |
10113 | |
10114 | if (hasColon) | |
c5aa993b | 10115 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10116 | else |
c5aa993b | 10117 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10118 | } |
10119 | ||
10120 | if (badInput) | |
a3f17187 | 10121 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10122 | else |
db107f19 | 10123 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10124 | } |
10125 | ||
10126 | static void | |
fba45db2 | 10127 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10128 | { |
10129 | int badInput = 0; | |
10130 | ||
c5aa993b | 10131 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10132 | badInput = 1; |
10133 | else | |
10134 | { | |
10135 | char *argptr = arg; | |
10136 | int hasColon = 0; | |
10137 | ||
4a64f543 MS |
10138 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10139 | it is probably a line number. */ | |
c906108c | 10140 | while (*argptr && !hasColon) |
c5aa993b JM |
10141 | { |
10142 | hasColon = (*argptr == ':'); | |
10143 | argptr++; | |
10144 | } | |
c906108c SS |
10145 | |
10146 | if (hasColon) | |
c5aa993b | 10147 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10148 | else |
c5aa993b | 10149 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10150 | } |
10151 | ||
10152 | if (badInput) | |
a3f17187 | 10153 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10154 | else |
db107f19 | 10155 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10156 | } |
10157 | ||
e7e0cddf SS |
10158 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10159 | with a prewired command list consisting of a single output command, | |
10160 | built from extra arguments supplied on the dprintf command | |
10161 | line. */ | |
10162 | ||
da821c7b | 10163 | static void |
e7e0cddf SS |
10164 | dprintf_command (char *arg, int from_tty) |
10165 | { | |
10166 | create_breakpoint (get_current_arch (), | |
10167 | arg, | |
10168 | NULL, 0, NULL, 1 /* parse arg */, | |
10169 | 0, bp_dprintf, | |
10170 | 0 /* Ignore count */, | |
10171 | pending_break_support, | |
10172 | &dprintf_breakpoint_ops, | |
10173 | from_tty, | |
10174 | 1 /* enabled */, | |
10175 | 0 /* internal */, | |
10176 | 0); | |
10177 | } | |
10178 | ||
d3ce09f5 SS |
10179 | static void |
10180 | agent_printf_command (char *arg, int from_tty) | |
10181 | { | |
10182 | error (_("May only run agent-printf on the target")); | |
10183 | } | |
10184 | ||
f1310107 TJB |
10185 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10186 | ranged breakpoints. */ | |
10187 | ||
10188 | static int | |
10189 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10190 | struct address_space *aspace, | |
09ac7c10 TT |
10191 | CORE_ADDR bp_addr, |
10192 | const struct target_waitstatus *ws) | |
f1310107 | 10193 | { |
09ac7c10 | 10194 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10195 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10196 | return 0; |
10197 | ||
f1310107 TJB |
10198 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10199 | bl->length, aspace, bp_addr); | |
10200 | } | |
10201 | ||
10202 | /* Implement the "resources_needed" breakpoint_ops method for | |
10203 | ranged breakpoints. */ | |
10204 | ||
10205 | static int | |
10206 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10207 | { | |
10208 | return target_ranged_break_num_registers (); | |
10209 | } | |
10210 | ||
10211 | /* Implement the "print_it" breakpoint_ops method for | |
10212 | ranged breakpoints. */ | |
10213 | ||
10214 | static enum print_stop_action | |
348d480f | 10215 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10216 | { |
348d480f | 10217 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10218 | struct bp_location *bl = b->loc; |
79a45e25 | 10219 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10220 | |
10221 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10222 | ||
10223 | /* Ranged breakpoints have only one location. */ | |
10224 | gdb_assert (bl && bl->next == NULL); | |
10225 | ||
10226 | annotate_breakpoint (b->number); | |
10227 | if (b->disposition == disp_del) | |
10228 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10229 | else | |
10230 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10231 | if (ui_out_is_mi_like_p (uiout)) | |
10232 | { | |
10233 | ui_out_field_string (uiout, "reason", | |
10234 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10235 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10236 | } | |
10237 | ui_out_field_int (uiout, "bkptno", b->number); | |
10238 | ui_out_text (uiout, ", "); | |
10239 | ||
10240 | return PRINT_SRC_AND_LOC; | |
10241 | } | |
10242 | ||
10243 | /* Implement the "print_one" breakpoint_ops method for | |
10244 | ranged breakpoints. */ | |
10245 | ||
10246 | static void | |
10247 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10248 | struct bp_location **last_loc) | |
10249 | { | |
10250 | struct bp_location *bl = b->loc; | |
10251 | struct value_print_options opts; | |
79a45e25 | 10252 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10253 | |
10254 | /* Ranged breakpoints have only one location. */ | |
10255 | gdb_assert (bl && bl->next == NULL); | |
10256 | ||
10257 | get_user_print_options (&opts); | |
10258 | ||
10259 | if (opts.addressprint) | |
10260 | /* We don't print the address range here, it will be printed later | |
10261 | by print_one_detail_ranged_breakpoint. */ | |
10262 | ui_out_field_skip (uiout, "addr"); | |
10263 | annotate_field (5); | |
10264 | print_breakpoint_location (b, bl); | |
10265 | *last_loc = bl; | |
10266 | } | |
10267 | ||
10268 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10269 | ranged breakpoints. */ | |
10270 | ||
10271 | static void | |
10272 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10273 | struct ui_out *uiout) | |
10274 | { | |
10275 | CORE_ADDR address_start, address_end; | |
10276 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10277 | struct ui_file *stb = mem_fileopen (); |
10278 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10279 | |
10280 | gdb_assert (bl); | |
10281 | ||
10282 | address_start = bl->address; | |
10283 | address_end = address_start + bl->length - 1; | |
10284 | ||
10285 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10286 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10287 | print_core_address (bl->gdbarch, address_start), |
10288 | print_core_address (bl->gdbarch, address_end)); | |
10289 | ui_out_field_stream (uiout, "addr", stb); | |
10290 | ui_out_text (uiout, "\n"); | |
10291 | ||
10292 | do_cleanups (cleanup); | |
10293 | } | |
10294 | ||
10295 | /* Implement the "print_mention" breakpoint_ops method for | |
10296 | ranged breakpoints. */ | |
10297 | ||
10298 | static void | |
10299 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10300 | { | |
10301 | struct bp_location *bl = b->loc; | |
79a45e25 | 10302 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10303 | |
10304 | gdb_assert (bl); | |
10305 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10306 | ||
10307 | if (ui_out_is_mi_like_p (uiout)) | |
10308 | return; | |
10309 | ||
10310 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10311 | b->number, paddress (bl->gdbarch, bl->address), | |
10312 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10313 | } | |
10314 | ||
10315 | /* Implement the "print_recreate" breakpoint_ops method for | |
10316 | ranged breakpoints. */ | |
10317 | ||
10318 | static void | |
10319 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10320 | { | |
10321 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10322 | b->addr_string_range_end); | |
d9b3f62e | 10323 | print_recreate_thread (b, fp); |
f1310107 TJB |
10324 | } |
10325 | ||
10326 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10327 | ||
2060206e | 10328 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10329 | |
10330 | /* Find the address where the end of the breakpoint range should be | |
10331 | placed, given the SAL of the end of the range. This is so that if | |
10332 | the user provides a line number, the end of the range is set to the | |
10333 | last instruction of the given line. */ | |
10334 | ||
10335 | static CORE_ADDR | |
10336 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10337 | { | |
10338 | CORE_ADDR end; | |
10339 | ||
10340 | /* If the user provided a PC value, use it. Otherwise, | |
10341 | find the address of the end of the given location. */ | |
10342 | if (sal.explicit_pc) | |
10343 | end = sal.pc; | |
10344 | else | |
10345 | { | |
10346 | int ret; | |
10347 | CORE_ADDR start; | |
10348 | ||
10349 | ret = find_line_pc_range (sal, &start, &end); | |
10350 | if (!ret) | |
10351 | error (_("Could not find location of the end of the range.")); | |
10352 | ||
10353 | /* find_line_pc_range returns the start of the next line. */ | |
10354 | end--; | |
10355 | } | |
10356 | ||
10357 | return end; | |
10358 | } | |
10359 | ||
10360 | /* Implement the "break-range" CLI command. */ | |
10361 | ||
10362 | static void | |
10363 | break_range_command (char *arg, int from_tty) | |
10364 | { | |
10365 | char *arg_start, *addr_string_start, *addr_string_end; | |
10366 | struct linespec_result canonical_start, canonical_end; | |
10367 | int bp_count, can_use_bp, length; | |
10368 | CORE_ADDR end; | |
10369 | struct breakpoint *b; | |
10370 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10371 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10372 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10373 | |
10374 | /* We don't support software ranged breakpoints. */ | |
10375 | if (target_ranged_break_num_registers () < 0) | |
10376 | error (_("This target does not support hardware ranged breakpoints.")); | |
10377 | ||
10378 | bp_count = hw_breakpoint_used_count (); | |
10379 | bp_count += target_ranged_break_num_registers (); | |
10380 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10381 | bp_count, 0); | |
10382 | if (can_use_bp < 0) | |
10383 | error (_("Hardware breakpoints used exceeds limit.")); | |
10384 | ||
f8eba3c6 | 10385 | arg = skip_spaces (arg); |
f1310107 TJB |
10386 | if (arg == NULL || arg[0] == '\0') |
10387 | error(_("No address range specified.")); | |
10388 | ||
f1310107 TJB |
10389 | init_linespec_result (&canonical_start); |
10390 | ||
f8eba3c6 TT |
10391 | arg_start = arg; |
10392 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10393 | |
f8eba3c6 | 10394 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10395 | |
10396 | if (arg[0] != ',') | |
10397 | error (_("Too few arguments.")); | |
f8eba3c6 | 10398 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10399 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10400 | |
10401 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10402 | ||
10403 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10404 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10405 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10406 | ||
f8eba3c6 TT |
10407 | sal_start = lsal_start->sals.sals[0]; |
10408 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10409 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10410 | |
10411 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10412 | arg = skip_spaces (arg); |
f1310107 TJB |
10413 | |
10414 | /* Parse the end location. */ | |
10415 | ||
f1310107 TJB |
10416 | init_linespec_result (&canonical_end); |
10417 | arg_start = arg; | |
10418 | ||
f8eba3c6 | 10419 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10420 | parse_breakpoint_sals because we need to specify the start location's |
10421 | symtab and line as the default symtab and line for the end of the | |
10422 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10423 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10424 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10425 | sal_start.symtab, sal_start.line, | |
10426 | &canonical_end, NULL, NULL); | |
10427 | ||
10428 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10429 | |
f8eba3c6 | 10430 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10431 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10432 | |
10433 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10434 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10435 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10436 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10437 | ||
f8eba3c6 TT |
10438 | sal_end = lsal_end->sals.sals[0]; |
10439 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10440 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10441 | |
10442 | end = find_breakpoint_range_end (sal_end); | |
10443 | if (sal_start.pc > end) | |
177b42fe | 10444 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10445 | |
10446 | length = end - sal_start.pc + 1; | |
10447 | if (length < 0) | |
10448 | /* Length overflowed. */ | |
10449 | error (_("Address range too large.")); | |
10450 | else if (length == 1) | |
10451 | { | |
10452 | /* This range is simple enough to be handled by | |
10453 | the `hbreak' command. */ | |
10454 | hbreak_command (addr_string_start, 1); | |
10455 | ||
10456 | do_cleanups (cleanup_bkpt); | |
10457 | ||
10458 | return; | |
10459 | } | |
10460 | ||
10461 | /* Now set up the breakpoint. */ | |
10462 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10463 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10464 | set_breakpoint_count (breakpoint_count + 1); |
10465 | b->number = breakpoint_count; | |
10466 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10467 | b->addr_string = xstrdup (addr_string_start); |
10468 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10469 | b->loc->length = length; |
10470 | ||
f8eba3c6 | 10471 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10472 | |
10473 | mention (b); | |
8d3788bd | 10474 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10475 | update_global_location_list (1); |
10476 | } | |
10477 | ||
4a64f543 MS |
10478 | /* Return non-zero if EXP is verified as constant. Returned zero |
10479 | means EXP is variable. Also the constant detection may fail for | |
10480 | some constant expressions and in such case still falsely return | |
10481 | zero. */ | |
2e6e3d9c | 10482 | |
65d79d4b SDJ |
10483 | static int |
10484 | watchpoint_exp_is_const (const struct expression *exp) | |
10485 | { | |
10486 | int i = exp->nelts; | |
10487 | ||
10488 | while (i > 0) | |
10489 | { | |
10490 | int oplenp, argsp; | |
10491 | ||
10492 | /* We are only interested in the descriptor of each element. */ | |
10493 | operator_length (exp, i, &oplenp, &argsp); | |
10494 | i -= oplenp; | |
10495 | ||
10496 | switch (exp->elts[i].opcode) | |
10497 | { | |
10498 | case BINOP_ADD: | |
10499 | case BINOP_SUB: | |
10500 | case BINOP_MUL: | |
10501 | case BINOP_DIV: | |
10502 | case BINOP_REM: | |
10503 | case BINOP_MOD: | |
10504 | case BINOP_LSH: | |
10505 | case BINOP_RSH: | |
10506 | case BINOP_LOGICAL_AND: | |
10507 | case BINOP_LOGICAL_OR: | |
10508 | case BINOP_BITWISE_AND: | |
10509 | case BINOP_BITWISE_IOR: | |
10510 | case BINOP_BITWISE_XOR: | |
10511 | case BINOP_EQUAL: | |
10512 | case BINOP_NOTEQUAL: | |
10513 | case BINOP_LESS: | |
10514 | case BINOP_GTR: | |
10515 | case BINOP_LEQ: | |
10516 | case BINOP_GEQ: | |
10517 | case BINOP_REPEAT: | |
10518 | case BINOP_COMMA: | |
10519 | case BINOP_EXP: | |
10520 | case BINOP_MIN: | |
10521 | case BINOP_MAX: | |
10522 | case BINOP_INTDIV: | |
10523 | case BINOP_CONCAT: | |
10524 | case BINOP_IN: | |
10525 | case BINOP_RANGE: | |
10526 | case TERNOP_COND: | |
10527 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10528 | |
10529 | case OP_LONG: | |
10530 | case OP_DOUBLE: | |
10531 | case OP_DECFLOAT: | |
10532 | case OP_LAST: | |
10533 | case OP_COMPLEX: | |
10534 | case OP_STRING: | |
65d79d4b SDJ |
10535 | case OP_ARRAY: |
10536 | case OP_TYPE: | |
608b4967 TT |
10537 | case OP_TYPEOF: |
10538 | case OP_DECLTYPE: | |
6e72ca20 | 10539 | case OP_TYPEID: |
65d79d4b SDJ |
10540 | case OP_NAME: |
10541 | case OP_OBJC_NSSTRING: | |
10542 | ||
10543 | case UNOP_NEG: | |
10544 | case UNOP_LOGICAL_NOT: | |
10545 | case UNOP_COMPLEMENT: | |
10546 | case UNOP_ADDR: | |
10547 | case UNOP_HIGH: | |
aeaa2474 | 10548 | case UNOP_CAST: |
9eaf6705 TT |
10549 | |
10550 | case UNOP_CAST_TYPE: | |
10551 | case UNOP_REINTERPRET_CAST: | |
10552 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10553 | /* Unary, binary and ternary operators: We have to check |
10554 | their operands. If they are constant, then so is the | |
10555 | result of that operation. For instance, if A and B are | |
10556 | determined to be constants, then so is "A + B". | |
10557 | ||
10558 | UNOP_IND is one exception to the rule above, because the | |
10559 | value of *ADDR is not necessarily a constant, even when | |
10560 | ADDR is. */ | |
65d79d4b SDJ |
10561 | break; |
10562 | ||
10563 | case OP_VAR_VALUE: | |
10564 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10565 | |
65d79d4b | 10566 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10567 | possible that a buggy compiler could mark a variable as |
10568 | constant even when it is not, and TYPE_CONST would return | |
10569 | true in this case, while SYMBOL_CLASS wouldn't. | |
10570 | ||
10571 | We also have to check for function symbols because they | |
10572 | are always constant. */ | |
65d79d4b SDJ |
10573 | { |
10574 | struct symbol *s = exp->elts[i + 2].symbol; | |
10575 | ||
10576 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10577 | && SYMBOL_CLASS (s) != LOC_CONST | |
10578 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10579 | return 0; | |
10580 | break; | |
10581 | } | |
10582 | ||
10583 | /* The default action is to return 0 because we are using | |
10584 | the optimistic approach here: If we don't know something, | |
10585 | then it is not a constant. */ | |
10586 | default: | |
10587 | return 0; | |
10588 | } | |
10589 | } | |
10590 | ||
10591 | return 1; | |
10592 | } | |
10593 | ||
3a5c3e22 PA |
10594 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10595 | ||
10596 | static void | |
10597 | dtor_watchpoint (struct breakpoint *self) | |
10598 | { | |
10599 | struct watchpoint *w = (struct watchpoint *) self; | |
10600 | ||
10601 | xfree (w->cond_exp); | |
10602 | xfree (w->exp); | |
10603 | xfree (w->exp_string); | |
10604 | xfree (w->exp_string_reparse); | |
10605 | value_free (w->val); | |
10606 | ||
10607 | base_breakpoint_ops.dtor (self); | |
10608 | } | |
10609 | ||
348d480f PA |
10610 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10611 | ||
10612 | static void | |
10613 | re_set_watchpoint (struct breakpoint *b) | |
10614 | { | |
3a5c3e22 PA |
10615 | struct watchpoint *w = (struct watchpoint *) b; |
10616 | ||
348d480f PA |
10617 | /* Watchpoint can be either on expression using entirely global |
10618 | variables, or it can be on local variables. | |
10619 | ||
10620 | Watchpoints of the first kind are never auto-deleted, and even | |
10621 | persist across program restarts. Since they can use variables | |
10622 | from shared libraries, we need to reparse expression as libraries | |
10623 | are loaded and unloaded. | |
10624 | ||
10625 | Watchpoints on local variables can also change meaning as result | |
10626 | of solib event. For example, if a watchpoint uses both a local | |
10627 | and a global variables in expression, it's a local watchpoint, | |
10628 | but unloading of a shared library will make the expression | |
10629 | invalid. This is not a very common use case, but we still | |
10630 | re-evaluate expression, to avoid surprises to the user. | |
10631 | ||
10632 | Note that for local watchpoints, we re-evaluate it only if | |
10633 | watchpoints frame id is still valid. If it's not, it means the | |
10634 | watchpoint is out of scope and will be deleted soon. In fact, | |
10635 | I'm not sure we'll ever be called in this case. | |
10636 | ||
10637 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10638 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10639 | |
3a5c3e22 PA |
10640 | Don't do anything about disabled watchpoints, since they will be |
10641 | reevaluated again when enabled. */ | |
10642 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10643 | } |
10644 | ||
77b06cd7 TJB |
10645 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10646 | ||
10647 | static int | |
10648 | insert_watchpoint (struct bp_location *bl) | |
10649 | { | |
3a5c3e22 PA |
10650 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10651 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10652 | |
10653 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10654 | w->cond_exp); |
77b06cd7 TJB |
10655 | } |
10656 | ||
10657 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10658 | ||
10659 | static int | |
10660 | remove_watchpoint (struct bp_location *bl) | |
10661 | { | |
3a5c3e22 PA |
10662 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10663 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10664 | |
10665 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10666 | w->cond_exp); |
e09342b5 TJB |
10667 | } |
10668 | ||
e09342b5 | 10669 | static int |
348d480f | 10670 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10671 | struct address_space *aspace, CORE_ADDR bp_addr, |
10672 | const struct target_waitstatus *ws) | |
e09342b5 | 10673 | { |
348d480f | 10674 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10675 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10676 | |
348d480f PA |
10677 | /* Continuable hardware watchpoints are treated as non-existent if the |
10678 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10679 | some data address). Otherwise gdb won't stop on a break instruction | |
10680 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10681 | been defined. Also skip watchpoints which we know did not trigger | |
10682 | (did not match the data address). */ | |
10683 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10684 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10685 | return 0; |
9c06b0b4 | 10686 | |
348d480f | 10687 | return 1; |
9c06b0b4 TJB |
10688 | } |
10689 | ||
348d480f PA |
10690 | static void |
10691 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10692 | { |
348d480f | 10693 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10694 | |
348d480f | 10695 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10696 | } |
10697 | ||
10698 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10699 | hardware watchpoints. */ |
9c06b0b4 TJB |
10700 | |
10701 | static int | |
348d480f | 10702 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10703 | { |
3a5c3e22 PA |
10704 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10705 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10706 | |
10707 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10708 | } |
10709 | ||
10710 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10711 | hardware watchpoints. */ |
9c06b0b4 TJB |
10712 | |
10713 | static int | |
348d480f | 10714 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10715 | { |
efa80663 PA |
10716 | /* Read and access watchpoints only work with hardware support. */ |
10717 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10718 | } |
10719 | ||
9c06b0b4 | 10720 | static enum print_stop_action |
348d480f | 10721 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10722 | { |
348d480f PA |
10723 | struct cleanup *old_chain; |
10724 | struct breakpoint *b; | |
f99d8bf4 | 10725 | struct ui_file *stb; |
348d480f | 10726 | enum print_stop_action result; |
3a5c3e22 | 10727 | struct watchpoint *w; |
79a45e25 | 10728 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10729 | |
10730 | gdb_assert (bs->bp_location_at != NULL); | |
10731 | ||
348d480f | 10732 | b = bs->breakpoint_at; |
3a5c3e22 | 10733 | w = (struct watchpoint *) b; |
348d480f | 10734 | |
f99d8bf4 PA |
10735 | stb = mem_fileopen (); |
10736 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10737 | |
10738 | switch (b->type) | |
10739 | { | |
348d480f | 10740 | case bp_watchpoint: |
9c06b0b4 TJB |
10741 | case bp_hardware_watchpoint: |
10742 | annotate_watchpoint (b->number); | |
10743 | if (ui_out_is_mi_like_p (uiout)) | |
10744 | ui_out_field_string | |
10745 | (uiout, "reason", | |
10746 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10747 | mention (b); |
10748 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10749 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10750 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10751 | ui_out_field_stream (uiout, "old", stb); |
10752 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10753 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10754 | ui_out_field_stream (uiout, "new", stb); |
10755 | ui_out_text (uiout, "\n"); | |
10756 | /* More than one watchpoint may have been triggered. */ | |
10757 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10758 | break; |
10759 | ||
10760 | case bp_read_watchpoint: | |
10761 | if (ui_out_is_mi_like_p (uiout)) | |
10762 | ui_out_field_string | |
10763 | (uiout, "reason", | |
10764 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10765 | mention (b); |
10766 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10767 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10768 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10769 | ui_out_field_stream (uiout, "value", stb); |
10770 | ui_out_text (uiout, "\n"); | |
10771 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10772 | break; |
10773 | ||
10774 | case bp_access_watchpoint: | |
348d480f PA |
10775 | if (bs->old_val != NULL) |
10776 | { | |
10777 | annotate_watchpoint (b->number); | |
10778 | if (ui_out_is_mi_like_p (uiout)) | |
10779 | ui_out_field_string | |
10780 | (uiout, "reason", | |
10781 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10782 | mention (b); | |
10783 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10784 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10785 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10786 | ui_out_field_stream (uiout, "old", stb); |
10787 | ui_out_text (uiout, "\nNew value = "); | |
10788 | } | |
10789 | else | |
10790 | { | |
10791 | mention (b); | |
10792 | if (ui_out_is_mi_like_p (uiout)) | |
10793 | ui_out_field_string | |
10794 | (uiout, "reason", | |
10795 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10796 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10797 | ui_out_text (uiout, "\nValue = "); | |
10798 | } | |
f99d8bf4 | 10799 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10800 | ui_out_field_stream (uiout, "new", stb); |
10801 | ui_out_text (uiout, "\n"); | |
10802 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10803 | break; |
10804 | default: | |
348d480f | 10805 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10806 | } |
10807 | ||
348d480f PA |
10808 | do_cleanups (old_chain); |
10809 | return result; | |
10810 | } | |
10811 | ||
10812 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10813 | watchpoints. */ | |
10814 | ||
10815 | static void | |
10816 | print_mention_watchpoint (struct breakpoint *b) | |
10817 | { | |
10818 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10819 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10820 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10821 | |
10822 | switch (b->type) | |
10823 | { | |
10824 | case bp_watchpoint: | |
10825 | ui_out_text (uiout, "Watchpoint "); | |
10826 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10827 | break; | |
10828 | case bp_hardware_watchpoint: | |
10829 | ui_out_text (uiout, "Hardware watchpoint "); | |
10830 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10831 | break; | |
10832 | case bp_read_watchpoint: | |
10833 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10834 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10835 | break; | |
10836 | case bp_access_watchpoint: | |
10837 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10838 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10839 | break; | |
10840 | default: | |
10841 | internal_error (__FILE__, __LINE__, | |
10842 | _("Invalid hardware watchpoint type.")); | |
10843 | } | |
10844 | ||
10845 | ui_out_field_int (uiout, "number", b->number); | |
10846 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10847 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10848 | do_cleanups (ui_out_chain); |
10849 | } | |
10850 | ||
10851 | /* Implement the "print_recreate" breakpoint_ops method for | |
10852 | watchpoints. */ | |
10853 | ||
10854 | static void | |
10855 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10856 | { | |
3a5c3e22 PA |
10857 | struct watchpoint *w = (struct watchpoint *) b; |
10858 | ||
348d480f PA |
10859 | switch (b->type) |
10860 | { | |
10861 | case bp_watchpoint: | |
10862 | case bp_hardware_watchpoint: | |
10863 | fprintf_unfiltered (fp, "watch"); | |
10864 | break; | |
10865 | case bp_read_watchpoint: | |
10866 | fprintf_unfiltered (fp, "rwatch"); | |
10867 | break; | |
10868 | case bp_access_watchpoint: | |
10869 | fprintf_unfiltered (fp, "awatch"); | |
10870 | break; | |
10871 | default: | |
10872 | internal_error (__FILE__, __LINE__, | |
10873 | _("Invalid watchpoint type.")); | |
10874 | } | |
10875 | ||
3a5c3e22 | 10876 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10877 | print_recreate_thread (b, fp); |
348d480f PA |
10878 | } |
10879 | ||
427cd150 TT |
10880 | /* Implement the "explains_signal" breakpoint_ops method for |
10881 | watchpoints. */ | |
10882 | ||
47591c29 | 10883 | static int |
427cd150 TT |
10884 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10885 | { | |
10886 | /* A software watchpoint cannot cause a signal other than | |
10887 | GDB_SIGNAL_TRAP. */ | |
10888 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10889 | return 0; |
427cd150 | 10890 | |
47591c29 | 10891 | return 1; |
427cd150 TT |
10892 | } |
10893 | ||
348d480f PA |
10894 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10895 | ||
2060206e | 10896 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10897 | |
10898 | /* Implement the "insert" breakpoint_ops method for | |
10899 | masked hardware watchpoints. */ | |
10900 | ||
10901 | static int | |
10902 | insert_masked_watchpoint (struct bp_location *bl) | |
10903 | { | |
3a5c3e22 PA |
10904 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10905 | ||
10906 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10907 | bl->watchpoint_type); |
10908 | } | |
10909 | ||
10910 | /* Implement the "remove" breakpoint_ops method for | |
10911 | masked hardware watchpoints. */ | |
10912 | ||
10913 | static int | |
10914 | remove_masked_watchpoint (struct bp_location *bl) | |
10915 | { | |
3a5c3e22 PA |
10916 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10917 | ||
10918 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10919 | bl->watchpoint_type); |
10920 | } | |
10921 | ||
10922 | /* Implement the "resources_needed" breakpoint_ops method for | |
10923 | masked hardware watchpoints. */ | |
10924 | ||
10925 | static int | |
10926 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10927 | { | |
3a5c3e22 PA |
10928 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10929 | ||
10930 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10931 | } |
10932 | ||
10933 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10934 | masked hardware watchpoints. */ | |
10935 | ||
10936 | static int | |
10937 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10938 | { | |
10939 | return 0; | |
10940 | } | |
10941 | ||
10942 | /* Implement the "print_it" breakpoint_ops method for | |
10943 | masked hardware watchpoints. */ | |
10944 | ||
10945 | static enum print_stop_action | |
10946 | print_it_masked_watchpoint (bpstat bs) | |
10947 | { | |
10948 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10949 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10950 | |
10951 | /* Masked watchpoints have only one location. */ | |
10952 | gdb_assert (b->loc && b->loc->next == NULL); | |
10953 | ||
10954 | switch (b->type) | |
10955 | { | |
10956 | case bp_hardware_watchpoint: | |
10957 | annotate_watchpoint (b->number); | |
10958 | if (ui_out_is_mi_like_p (uiout)) | |
10959 | ui_out_field_string | |
10960 | (uiout, "reason", | |
10961 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10962 | break; | |
10963 | ||
10964 | case bp_read_watchpoint: | |
10965 | if (ui_out_is_mi_like_p (uiout)) | |
10966 | ui_out_field_string | |
10967 | (uiout, "reason", | |
10968 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10969 | break; | |
10970 | ||
10971 | case bp_access_watchpoint: | |
10972 | if (ui_out_is_mi_like_p (uiout)) | |
10973 | ui_out_field_string | |
10974 | (uiout, "reason", | |
10975 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10976 | break; | |
10977 | default: | |
10978 | internal_error (__FILE__, __LINE__, | |
10979 | _("Invalid hardware watchpoint type.")); | |
10980 | } | |
10981 | ||
10982 | mention (b); | |
9c06b0b4 TJB |
10983 | ui_out_text (uiout, _("\n\ |
10984 | Check the underlying instruction at PC for the memory\n\ | |
10985 | address and value which triggered this watchpoint.\n")); | |
10986 | ui_out_text (uiout, "\n"); | |
10987 | ||
10988 | /* More than one watchpoint may have been triggered. */ | |
10989 | return PRINT_UNKNOWN; | |
10990 | } | |
10991 | ||
10992 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10993 | masked hardware watchpoints. */ | |
10994 | ||
10995 | static void | |
10996 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10997 | struct ui_out *uiout) | |
10998 | { | |
3a5c3e22 PA |
10999 | struct watchpoint *w = (struct watchpoint *) b; |
11000 | ||
9c06b0b4 TJB |
11001 | /* Masked watchpoints have only one location. */ |
11002 | gdb_assert (b->loc && b->loc->next == NULL); | |
11003 | ||
11004 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11005 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11006 | ui_out_text (uiout, "\n"); |
11007 | } | |
11008 | ||
11009 | /* Implement the "print_mention" breakpoint_ops method for | |
11010 | masked hardware watchpoints. */ | |
11011 | ||
11012 | static void | |
11013 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11014 | { | |
3a5c3e22 | 11015 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11016 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11017 | struct cleanup *ui_out_chain; |
11018 | ||
11019 | switch (b->type) | |
11020 | { | |
11021 | case bp_hardware_watchpoint: | |
11022 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11023 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11024 | break; | |
11025 | case bp_read_watchpoint: | |
11026 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11027 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11028 | break; | |
11029 | case bp_access_watchpoint: | |
11030 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11031 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11032 | break; | |
11033 | default: | |
11034 | internal_error (__FILE__, __LINE__, | |
11035 | _("Invalid hardware watchpoint type.")); | |
11036 | } | |
11037 | ||
11038 | ui_out_field_int (uiout, "number", b->number); | |
11039 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11040 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11041 | do_cleanups (ui_out_chain); |
11042 | } | |
11043 | ||
11044 | /* Implement the "print_recreate" breakpoint_ops method for | |
11045 | masked hardware watchpoints. */ | |
11046 | ||
11047 | static void | |
11048 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11049 | { | |
3a5c3e22 | 11050 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11051 | char tmp[40]; |
11052 | ||
11053 | switch (b->type) | |
11054 | { | |
11055 | case bp_hardware_watchpoint: | |
11056 | fprintf_unfiltered (fp, "watch"); | |
11057 | break; | |
11058 | case bp_read_watchpoint: | |
11059 | fprintf_unfiltered (fp, "rwatch"); | |
11060 | break; | |
11061 | case bp_access_watchpoint: | |
11062 | fprintf_unfiltered (fp, "awatch"); | |
11063 | break; | |
11064 | default: | |
11065 | internal_error (__FILE__, __LINE__, | |
11066 | _("Invalid hardware watchpoint type.")); | |
11067 | } | |
11068 | ||
3a5c3e22 PA |
11069 | sprintf_vma (tmp, w->hw_wp_mask); |
11070 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11071 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11072 | } |
11073 | ||
11074 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11075 | ||
2060206e | 11076 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11077 | |
11078 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11079 | ||
11080 | static int | |
11081 | is_masked_watchpoint (const struct breakpoint *b) | |
11082 | { | |
11083 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11084 | } | |
11085 | ||
53a5351d JM |
11086 | /* accessflag: hw_write: watch write, |
11087 | hw_read: watch read, | |
11088 | hw_access: watch access (read or write) */ | |
c906108c | 11089 | static void |
bbc13ae3 | 11090 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11091 | int just_location, int internal) |
c906108c | 11092 | { |
a9634178 | 11093 | volatile struct gdb_exception e; |
d983da9c | 11094 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11095 | struct expression *exp; |
270140bd | 11096 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11097 | struct value *val, *mark, *result; |
c906108c | 11098 | struct frame_info *frame; |
bbc13ae3 KS |
11099 | const char *exp_start = NULL; |
11100 | const char *exp_end = NULL; | |
11101 | const char *tok, *end_tok; | |
9c06b0b4 | 11102 | int toklen = -1; |
bbc13ae3 KS |
11103 | const char *cond_start = NULL; |
11104 | const char *cond_end = NULL; | |
c906108c | 11105 | enum bptype bp_type; |
37e4754d | 11106 | int thread = -1; |
0cf6dd15 | 11107 | int pc = 0; |
9c06b0b4 TJB |
11108 | /* Flag to indicate whether we are going to use masks for |
11109 | the hardware watchpoint. */ | |
11110 | int use_mask = 0; | |
11111 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11112 | struct watchpoint *w; |
bbc13ae3 KS |
11113 | char *expression; |
11114 | struct cleanup *back_to; | |
c906108c | 11115 | |
37e4754d LM |
11116 | /* Make sure that we actually have parameters to parse. */ |
11117 | if (arg != NULL && arg[0] != '\0') | |
11118 | { | |
bbc13ae3 KS |
11119 | const char *value_start; |
11120 | ||
11121 | exp_end = arg + strlen (arg); | |
37e4754d | 11122 | |
9c06b0b4 TJB |
11123 | /* Look for "parameter value" pairs at the end |
11124 | of the arguments string. */ | |
bbc13ae3 | 11125 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11126 | { |
11127 | /* Skip whitespace at the end of the argument list. */ | |
11128 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11129 | tok--; | |
11130 | ||
11131 | /* Find the beginning of the last token. | |
11132 | This is the value of the parameter. */ | |
11133 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11134 | tok--; | |
11135 | value_start = tok + 1; | |
11136 | ||
11137 | /* Skip whitespace. */ | |
11138 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11139 | tok--; | |
11140 | ||
11141 | end_tok = tok; | |
11142 | ||
11143 | /* Find the beginning of the second to last token. | |
11144 | This is the parameter itself. */ | |
11145 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11146 | tok--; | |
11147 | tok++; | |
11148 | toklen = end_tok - tok + 1; | |
11149 | ||
11150 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11151 | { | |
11152 | /* At this point we've found a "thread" token, which means | |
11153 | the user is trying to set a watchpoint that triggers | |
11154 | only in a specific thread. */ | |
11155 | char *endp; | |
37e4754d | 11156 | |
9c06b0b4 TJB |
11157 | if (thread != -1) |
11158 | error(_("You can specify only one thread.")); | |
37e4754d | 11159 | |
9c06b0b4 TJB |
11160 | /* Extract the thread ID from the next token. */ |
11161 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11162 | |
9c06b0b4 TJB |
11163 | /* Check if the user provided a valid numeric value for the |
11164 | thread ID. */ | |
11165 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11166 | error (_("Invalid thread ID specification %s."), value_start); | |
11167 | ||
11168 | /* Check if the thread actually exists. */ | |
11169 | if (!valid_thread_id (thread)) | |
af4908ba | 11170 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11171 | } |
11172 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11173 | { | |
11174 | /* We've found a "mask" token, which means the user wants to | |
11175 | create a hardware watchpoint that is going to have the mask | |
11176 | facility. */ | |
11177 | struct value *mask_value, *mark; | |
37e4754d | 11178 | |
9c06b0b4 TJB |
11179 | if (use_mask) |
11180 | error(_("You can specify only one mask.")); | |
37e4754d | 11181 | |
9c06b0b4 | 11182 | use_mask = just_location = 1; |
37e4754d | 11183 | |
9c06b0b4 TJB |
11184 | mark = value_mark (); |
11185 | mask_value = parse_to_comma_and_eval (&value_start); | |
11186 | mask = value_as_address (mask_value); | |
11187 | value_free_to_mark (mark); | |
11188 | } | |
11189 | else | |
11190 | /* We didn't recognize what we found. We should stop here. */ | |
11191 | break; | |
37e4754d | 11192 | |
9c06b0b4 TJB |
11193 | /* Truncate the string and get rid of the "parameter value" pair before |
11194 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11195 | exp_end = tok; |
9c06b0b4 | 11196 | } |
37e4754d | 11197 | } |
bbc13ae3 KS |
11198 | else |
11199 | exp_end = arg; | |
37e4754d | 11200 | |
bbc13ae3 KS |
11201 | /* Parse the rest of the arguments. From here on out, everything |
11202 | is in terms of a newly allocated string instead of the original | |
11203 | ARG. */ | |
c906108c | 11204 | innermost_block = NULL; |
bbc13ae3 KS |
11205 | expression = savestring (arg, exp_end - arg); |
11206 | back_to = make_cleanup (xfree, expression); | |
11207 | exp_start = arg = expression; | |
1bb9788d | 11208 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11209 | exp_end = arg; |
fa8a61dc TT |
11210 | /* Remove trailing whitespace from the expression before saving it. |
11211 | This makes the eventual display of the expression string a bit | |
11212 | prettier. */ | |
11213 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11214 | --exp_end; | |
11215 | ||
65d79d4b SDJ |
11216 | /* Checking if the expression is not constant. */ |
11217 | if (watchpoint_exp_is_const (exp)) | |
11218 | { | |
11219 | int len; | |
11220 | ||
11221 | len = exp_end - exp_start; | |
11222 | while (len > 0 && isspace (exp_start[len - 1])) | |
11223 | len--; | |
11224 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11225 | } | |
11226 | ||
c906108c SS |
11227 | exp_valid_block = innermost_block; |
11228 | mark = value_mark (); | |
3a1115a0 | 11229 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11230 | |
11231 | if (just_location) | |
11232 | { | |
9c06b0b4 TJB |
11233 | int ret; |
11234 | ||
06a64a0b | 11235 | exp_valid_block = NULL; |
a1442452 | 11236 | val = value_addr (result); |
06a64a0b TT |
11237 | release_value (val); |
11238 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11239 | |
11240 | if (use_mask) | |
11241 | { | |
11242 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11243 | mask); | |
11244 | if (ret == -1) | |
11245 | error (_("This target does not support masked watchpoints.")); | |
11246 | else if (ret == -2) | |
11247 | error (_("Invalid mask or memory region.")); | |
11248 | } | |
06a64a0b TT |
11249 | } |
11250 | else if (val != NULL) | |
fa4727a6 | 11251 | release_value (val); |
c906108c | 11252 | |
bbc13ae3 KS |
11253 | tok = skip_spaces_const (arg); |
11254 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11255 | |
11256 | toklen = end_tok - tok; | |
11257 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11258 | { | |
2d134ed3 PA |
11259 | struct expression *cond; |
11260 | ||
60e1c644 | 11261 | innermost_block = NULL; |
c906108c | 11262 | tok = cond_start = end_tok + 1; |
1bb9788d | 11263 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11264 | |
11265 | /* The watchpoint expression may not be local, but the condition | |
11266 | may still be. E.g.: `watch global if local > 0'. */ | |
11267 | cond_exp_valid_block = innermost_block; | |
11268 | ||
2d134ed3 | 11269 | xfree (cond); |
c906108c SS |
11270 | cond_end = tok; |
11271 | } | |
11272 | if (*tok) | |
8a3fe4f8 | 11273 | error (_("Junk at end of command.")); |
c906108c | 11274 | |
d983da9c | 11275 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11276 | |
11277 | /* If the expression is "local", then set up a "watchpoint scope" | |
11278 | breakpoint at the point where we've left the scope of the watchpoint | |
11279 | expression. Create the scope breakpoint before the watchpoint, so | |
11280 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11281 | if (exp_valid_block && frame) |
d983da9c | 11282 | { |
edb3359d DJ |
11283 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11284 | { | |
11285 | scope_breakpoint | |
a6d9a66e UW |
11286 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11287 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11288 | bp_watchpoint_scope, |
11289 | &momentary_breakpoint_ops); | |
d983da9c | 11290 | |
edb3359d | 11291 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11292 | |
edb3359d DJ |
11293 | /* Automatically delete the breakpoint when it hits. */ |
11294 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11295 | |
edb3359d DJ |
11296 | /* Only break in the proper frame (help with recursion). */ |
11297 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11298 | |
edb3359d | 11299 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11300 | scope_breakpoint->loc->gdbarch |
11301 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11302 | scope_breakpoint->loc->requested_address |
11303 | = frame_unwind_caller_pc (frame); | |
11304 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11305 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11306 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11307 | scope_breakpoint->type); |
11308 | } | |
d983da9c DJ |
11309 | } |
11310 | ||
e8369a73 AB |
11311 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11312 | watchpoints here even if hardware watchpoints are turned off, a call | |
11313 | to update_watchpoint later in this function will cause the type to | |
11314 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11315 | ||
11316 | if (accessflag == hw_read) | |
11317 | bp_type = bp_read_watchpoint; | |
11318 | else if (accessflag == hw_access) | |
11319 | bp_type = bp_access_watchpoint; | |
11320 | else | |
11321 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11322 | |
11323 | w = XCNEW (struct watchpoint); | |
11324 | b = &w->base; | |
348d480f | 11325 | if (use_mask) |
3a5c3e22 PA |
11326 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11327 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11328 | else |
3a5c3e22 PA |
11329 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11330 | &watchpoint_breakpoint_ops); | |
37e4754d | 11331 | b->thread = thread; |
b5de0fa7 | 11332 | b->disposition = disp_donttouch; |
348d480f | 11333 | b->pspace = current_program_space; |
3a5c3e22 PA |
11334 | w->exp = exp; |
11335 | w->exp_valid_block = exp_valid_block; | |
11336 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11337 | if (just_location) |
11338 | { | |
11339 | struct type *t = value_type (val); | |
11340 | CORE_ADDR addr = value_as_address (val); | |
11341 | char *name; | |
11342 | ||
11343 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11344 | name = type_to_string (t); | |
11345 | ||
3a5c3e22 | 11346 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11347 | core_addr_to_string (addr)); |
06a64a0b TT |
11348 | xfree (name); |
11349 | ||
3a5c3e22 | 11350 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11351 | (int) (exp_end - exp_start), exp_start); |
11352 | ||
06a64a0b TT |
11353 | /* The above expression is in C. */ |
11354 | b->language = language_c; | |
11355 | } | |
11356 | else | |
3a5c3e22 | 11357 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11358 | |
11359 | if (use_mask) | |
11360 | { | |
3a5c3e22 | 11361 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11362 | } |
11363 | else | |
11364 | { | |
3a5c3e22 PA |
11365 | w->val = val; |
11366 | w->val_valid = 1; | |
9c06b0b4 | 11367 | } |
77b06cd7 | 11368 | |
c906108c SS |
11369 | if (cond_start) |
11370 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11371 | else | |
11372 | b->cond_string = 0; | |
c5aa993b | 11373 | |
c906108c | 11374 | if (frame) |
f6bc2008 | 11375 | { |
3a5c3e22 PA |
11376 | w->watchpoint_frame = get_frame_id (frame); |
11377 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11378 | } |
c906108c | 11379 | else |
f6bc2008 | 11380 | { |
3a5c3e22 PA |
11381 | w->watchpoint_frame = null_frame_id; |
11382 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11383 | } |
c906108c | 11384 | |
d983da9c | 11385 | if (scope_breakpoint != NULL) |
c906108c | 11386 | { |
d983da9c DJ |
11387 | /* The scope breakpoint is related to the watchpoint. We will |
11388 | need to act on them together. */ | |
11389 | b->related_breakpoint = scope_breakpoint; | |
11390 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11391 | } |
d983da9c | 11392 | |
06a64a0b TT |
11393 | if (!just_location) |
11394 | value_free_to_mark (mark); | |
2d134ed3 | 11395 | |
a9634178 TJB |
11396 | TRY_CATCH (e, RETURN_MASK_ALL) |
11397 | { | |
11398 | /* Finally update the new watchpoint. This creates the locations | |
11399 | that should be inserted. */ | |
3a5c3e22 | 11400 | update_watchpoint (w, 1); |
a9634178 TJB |
11401 | } |
11402 | if (e.reason < 0) | |
11403 | { | |
11404 | delete_breakpoint (b); | |
11405 | throw_exception (e); | |
11406 | } | |
11407 | ||
3ea46bff | 11408 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11409 | do_cleanups (back_to); |
c906108c SS |
11410 | } |
11411 | ||
e09342b5 | 11412 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11413 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11414 | |
c906108c | 11415 | static int |
a9634178 | 11416 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11417 | { |
11418 | int found_memory_cnt = 0; | |
2e70b7b9 | 11419 | struct value *head = v; |
c906108c SS |
11420 | |
11421 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11422 | if (!can_use_hw_watchpoints) |
c906108c | 11423 | return 0; |
c5aa993b | 11424 | |
5c44784c JM |
11425 | /* Make sure that the value of the expression depends only upon |
11426 | memory contents, and values computed from them within GDB. If we | |
11427 | find any register references or function calls, we can't use a | |
11428 | hardware watchpoint. | |
11429 | ||
11430 | The idea here is that evaluating an expression generates a series | |
11431 | of values, one holding the value of every subexpression. (The | |
11432 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11433 | a*b+c.) GDB's values hold almost enough information to establish | |
11434 | the criteria given above --- they identify memory lvalues, | |
11435 | register lvalues, computed values, etcetera. So we can evaluate | |
11436 | the expression, and then scan the chain of values that leaves | |
11437 | behind to decide whether we can detect any possible change to the | |
11438 | expression's final value using only hardware watchpoints. | |
11439 | ||
11440 | However, I don't think that the values returned by inferior | |
11441 | function calls are special in any way. So this function may not | |
11442 | notice that an expression involving an inferior function call | |
11443 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11444 | for (; v; v = value_next (v)) |
c906108c | 11445 | { |
5c44784c | 11446 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11447 | { |
8464be76 DJ |
11448 | if (v != head && value_lazy (v)) |
11449 | /* A lazy memory lvalue in the chain is one that GDB never | |
11450 | needed to fetch; we either just used its address (e.g., | |
11451 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11452 | in `a,b'). This doesn't apply to HEAD; if that is | |
11453 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11454 | ; |
53a5351d | 11455 | else |
5c44784c JM |
11456 | { |
11457 | /* Ahh, memory we actually used! Check if we can cover | |
11458 | it with hardware watchpoints. */ | |
df407dfe | 11459 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11460 | |
11461 | /* We only watch structs and arrays if user asked for it | |
11462 | explicitly, never if they just happen to appear in a | |
11463 | middle of some value chain. */ | |
11464 | if (v == head | |
11465 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11466 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11467 | { | |
42ae5230 | 11468 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11469 | int len; |
11470 | int num_regs; | |
11471 | ||
a9634178 | 11472 | len = (target_exact_watchpoints |
e09342b5 TJB |
11473 | && is_scalar_type_recursive (vtype))? |
11474 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11475 | |
e09342b5 TJB |
11476 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11477 | if (!num_regs) | |
2e70b7b9 MS |
11478 | return 0; |
11479 | else | |
e09342b5 | 11480 | found_memory_cnt += num_regs; |
2e70b7b9 | 11481 | } |
5c44784c | 11482 | } |
c5aa993b | 11483 | } |
5086187c AC |
11484 | else if (VALUE_LVAL (v) != not_lval |
11485 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11486 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11487 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11488 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11489 | } |
11490 | ||
11491 | /* The expression itself looks suitable for using a hardware | |
11492 | watchpoint, but give the target machine a chance to reject it. */ | |
11493 | return found_memory_cnt; | |
11494 | } | |
11495 | ||
8b93c638 | 11496 | void |
84f4c1fe | 11497 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11498 | { |
84f4c1fe | 11499 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11500 | } |
11501 | ||
06a64a0b TT |
11502 | /* A helper function that looks for the "-location" argument and then |
11503 | calls watch_command_1. */ | |
11504 | ||
11505 | static void | |
11506 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11507 | { | |
11508 | int just_location = 0; | |
11509 | ||
11510 | if (arg | |
11511 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11512 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11513 | { | |
e9cafbcc | 11514 | arg = skip_spaces (arg); |
06a64a0b TT |
11515 | just_location = 1; |
11516 | } | |
11517 | ||
84f4c1fe | 11518 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11519 | } |
8926118c | 11520 | |
c5aa993b | 11521 | static void |
fba45db2 | 11522 | watch_command (char *arg, int from_tty) |
c906108c | 11523 | { |
06a64a0b | 11524 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11525 | } |
11526 | ||
8b93c638 | 11527 | void |
84f4c1fe | 11528 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11529 | { |
84f4c1fe | 11530 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11531 | } |
8926118c | 11532 | |
c5aa993b | 11533 | static void |
fba45db2 | 11534 | rwatch_command (char *arg, int from_tty) |
c906108c | 11535 | { |
06a64a0b | 11536 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11537 | } |
11538 | ||
8b93c638 | 11539 | void |
84f4c1fe | 11540 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11541 | { |
84f4c1fe | 11542 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11543 | } |
8926118c | 11544 | |
c5aa993b | 11545 | static void |
fba45db2 | 11546 | awatch_command (char *arg, int from_tty) |
c906108c | 11547 | { |
06a64a0b | 11548 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11549 | } |
c906108c | 11550 | \f |
c5aa993b | 11551 | |
43ff13b4 | 11552 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11553 | because it uses the mechanisms of breakpoints. */ |
11554 | ||
bfec99b2 PA |
11555 | struct until_break_command_continuation_args |
11556 | { | |
11557 | struct breakpoint *breakpoint; | |
11558 | struct breakpoint *breakpoint2; | |
186c406b | 11559 | int thread_num; |
bfec99b2 PA |
11560 | }; |
11561 | ||
43ff13b4 | 11562 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11563 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11564 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11565 | command. */ |
c2c6d25f | 11566 | static void |
fa4cd53f | 11567 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11568 | { |
bfec99b2 PA |
11569 | struct until_break_command_continuation_args *a = arg; |
11570 | ||
11571 | delete_breakpoint (a->breakpoint); | |
11572 | if (a->breakpoint2) | |
11573 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11574 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11575 | } |
11576 | ||
c906108c | 11577 | void |
ae66c1fc | 11578 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11579 | { |
11580 | struct symtabs_and_lines sals; | |
11581 | struct symtab_and_line sal; | |
8556afb4 PA |
11582 | struct frame_info *frame; |
11583 | struct gdbarch *frame_gdbarch; | |
11584 | struct frame_id stack_frame_id; | |
11585 | struct frame_id caller_frame_id; | |
c906108c | 11586 | struct breakpoint *breakpoint; |
f107f563 | 11587 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11588 | struct cleanup *old_chain; |
186c406b TT |
11589 | int thread; |
11590 | struct thread_info *tp; | |
c906108c SS |
11591 | |
11592 | clear_proceed_status (); | |
11593 | ||
11594 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11595 | this function. */ |
c5aa993b | 11596 | |
1bfeeb0f | 11597 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11598 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11599 | get_last_displayed_symtab (), |
f8eba3c6 | 11600 | get_last_displayed_line ()); |
c906108c | 11601 | else |
f8eba3c6 TT |
11602 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11603 | (struct symtab *) NULL, 0); | |
c5aa993b | 11604 | |
c906108c | 11605 | if (sals.nelts != 1) |
8a3fe4f8 | 11606 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11607 | |
c906108c | 11608 | sal = sals.sals[0]; |
4a64f543 | 11609 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11610 | |
c906108c | 11611 | if (*arg) |
8a3fe4f8 | 11612 | error (_("Junk at end of arguments.")); |
c5aa993b | 11613 | |
c906108c | 11614 | resolve_sal_pc (&sal); |
c5aa993b | 11615 | |
186c406b TT |
11616 | tp = inferior_thread (); |
11617 | thread = tp->num; | |
11618 | ||
883bc8d1 PA |
11619 | old_chain = make_cleanup (null_cleanup, NULL); |
11620 | ||
8556afb4 PA |
11621 | /* Note linespec handling above invalidates the frame chain. |
11622 | Installing a breakpoint also invalidates the frame chain (as it | |
11623 | may need to switch threads), so do any frame handling before | |
11624 | that. */ | |
11625 | ||
11626 | frame = get_selected_frame (NULL); | |
11627 | frame_gdbarch = get_frame_arch (frame); | |
11628 | stack_frame_id = get_stack_frame_id (frame); | |
11629 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11630 | |
ae66c1fc EZ |
11631 | /* Keep within the current frame, or in frames called by the current |
11632 | one. */ | |
edb3359d | 11633 | |
883bc8d1 | 11634 | if (frame_id_p (caller_frame_id)) |
c906108c | 11635 | { |
883bc8d1 PA |
11636 | struct symtab_and_line sal2; |
11637 | ||
11638 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11639 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11640 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11641 | sal2, |
11642 | caller_frame_id, | |
f107f563 VP |
11643 | bp_until); |
11644 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11645 | |
883bc8d1 | 11646 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11647 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11648 | } |
c5aa993b | 11649 | |
c70a6932 JK |
11650 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11651 | frame = NULL; | |
11652 | ||
883bc8d1 PA |
11653 | if (anywhere) |
11654 | /* If the user told us to continue until a specified location, | |
11655 | we don't specify a frame at which we need to stop. */ | |
11656 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11657 | null_frame_id, bp_until); | |
11658 | else | |
11659 | /* Otherwise, specify the selected frame, because we want to stop | |
11660 | only at the very same frame. */ | |
11661 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11662 | stack_frame_id, bp_until); | |
11663 | make_cleanup_delete_breakpoint (breakpoint); | |
11664 | ||
a493e3e2 | 11665 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11666 | |
4a64f543 MS |
11667 | /* If we are running asynchronously, and proceed call above has |
11668 | actually managed to start the target, arrange for breakpoints to | |
11669 | be deleted when the target stops. Otherwise, we're already | |
11670 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11671 | |
8ea051c5 | 11672 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11673 | { |
bfec99b2 PA |
11674 | struct until_break_command_continuation_args *args; |
11675 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11676 | |
bfec99b2 PA |
11677 | args->breakpoint = breakpoint; |
11678 | args->breakpoint2 = breakpoint2; | |
186c406b | 11679 | args->thread_num = thread; |
f107f563 VP |
11680 | |
11681 | discard_cleanups (old_chain); | |
95e54da7 PA |
11682 | add_continuation (inferior_thread (), |
11683 | until_break_command_continuation, args, | |
604ead4a | 11684 | xfree); |
f107f563 VP |
11685 | } |
11686 | else | |
c5aa993b | 11687 | do_cleanups (old_chain); |
c906108c | 11688 | } |
ae66c1fc | 11689 | |
c906108c SS |
11690 | /* This function attempts to parse an optional "if <cond>" clause |
11691 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11692 | |
c906108c SS |
11693 | Else, it returns a pointer to the condition string. (It does not |
11694 | attempt to evaluate the string against a particular block.) And, | |
11695 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11696 | if clause in the arg string. */ |
53a5351d | 11697 | |
916703c0 | 11698 | char * |
fba45db2 | 11699 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11700 | { |
c5aa993b JM |
11701 | char *cond_string; |
11702 | ||
11703 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11704 | return NULL; |
c5aa993b | 11705 | |
4a64f543 | 11706 | /* Skip the "if" keyword. */ |
c906108c | 11707 | (*arg) += 2; |
c5aa993b | 11708 | |
c906108c | 11709 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11710 | condition string. */ |
e9cafbcc | 11711 | *arg = skip_spaces (*arg); |
c906108c | 11712 | cond_string = *arg; |
c5aa993b | 11713 | |
4a64f543 MS |
11714 | /* Assume that the condition occupies the remainder of the arg |
11715 | string. */ | |
c906108c | 11716 | (*arg) += strlen (cond_string); |
c5aa993b | 11717 | |
c906108c SS |
11718 | return cond_string; |
11719 | } | |
c5aa993b | 11720 | |
c906108c SS |
11721 | /* Commands to deal with catching events, such as signals, exceptions, |
11722 | process start/exit, etc. */ | |
c5aa993b JM |
11723 | |
11724 | typedef enum | |
11725 | { | |
44feb3ce TT |
11726 | catch_fork_temporary, catch_vfork_temporary, |
11727 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11728 | } |
11729 | catch_fork_kind; | |
11730 | ||
c906108c | 11731 | static void |
cc59ec59 MS |
11732 | catch_fork_command_1 (char *arg, int from_tty, |
11733 | struct cmd_list_element *command) | |
c906108c | 11734 | { |
a6d9a66e | 11735 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11736 | char *cond_string = NULL; |
44feb3ce TT |
11737 | catch_fork_kind fork_kind; |
11738 | int tempflag; | |
11739 | ||
11740 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11741 | tempflag = (fork_kind == catch_fork_temporary | |
11742 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11743 | |
44feb3ce TT |
11744 | if (!arg) |
11745 | arg = ""; | |
e9cafbcc | 11746 | arg = skip_spaces (arg); |
c5aa993b | 11747 | |
c906108c | 11748 | /* The allowed syntax is: |
c5aa993b JM |
11749 | catch [v]fork |
11750 | catch [v]fork if <cond> | |
11751 | ||
4a64f543 | 11752 | First, check if there's an if clause. */ |
c906108c | 11753 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11754 | |
c906108c | 11755 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11756 | error (_("Junk at end of arguments.")); |
c5aa993b | 11757 | |
c906108c | 11758 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11759 | and enable reporting of such events. */ |
c5aa993b JM |
11760 | switch (fork_kind) |
11761 | { | |
44feb3ce TT |
11762 | case catch_fork_temporary: |
11763 | case catch_fork_permanent: | |
a6d9a66e | 11764 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11765 | &catch_fork_breakpoint_ops); |
c906108c | 11766 | break; |
44feb3ce TT |
11767 | case catch_vfork_temporary: |
11768 | case catch_vfork_permanent: | |
a6d9a66e | 11769 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11770 | &catch_vfork_breakpoint_ops); |
c906108c | 11771 | break; |
c5aa993b | 11772 | default: |
8a3fe4f8 | 11773 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11774 | break; |
c5aa993b | 11775 | } |
c906108c SS |
11776 | } |
11777 | ||
11778 | static void | |
cc59ec59 MS |
11779 | catch_exec_command_1 (char *arg, int from_tty, |
11780 | struct cmd_list_element *command) | |
c906108c | 11781 | { |
b4d90040 | 11782 | struct exec_catchpoint *c; |
a6d9a66e | 11783 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11784 | int tempflag; |
c5aa993b | 11785 | char *cond_string = NULL; |
c906108c | 11786 | |
44feb3ce TT |
11787 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11788 | ||
11789 | if (!arg) | |
11790 | arg = ""; | |
e9cafbcc | 11791 | arg = skip_spaces (arg); |
c906108c SS |
11792 | |
11793 | /* The allowed syntax is: | |
c5aa993b JM |
11794 | catch exec |
11795 | catch exec if <cond> | |
c906108c | 11796 | |
4a64f543 | 11797 | First, check if there's an if clause. */ |
c906108c SS |
11798 | cond_string = ep_parse_optional_if_clause (&arg); |
11799 | ||
11800 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11801 | error (_("Junk at end of arguments.")); |
c906108c | 11802 | |
b4d90040 PA |
11803 | c = XNEW (struct exec_catchpoint); |
11804 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11805 | &catch_exec_breakpoint_ops); | |
11806 | c->exec_pathname = NULL; | |
11807 | ||
3ea46bff | 11808 | install_breakpoint (0, &c->base, 1); |
c906108c | 11809 | } |
c5aa993b | 11810 | |
9ac4176b | 11811 | void |
28010a5d PA |
11812 | init_ada_exception_breakpoint (struct breakpoint *b, |
11813 | struct gdbarch *gdbarch, | |
11814 | struct symtab_and_line sal, | |
11815 | char *addr_string, | |
c0a91b2b | 11816 | const struct breakpoint_ops *ops, |
28010a5d | 11817 | int tempflag, |
349774ef | 11818 | int enabled, |
28010a5d | 11819 | int from_tty) |
f7f9143b | 11820 | { |
f7f9143b JB |
11821 | if (from_tty) |
11822 | { | |
5af949e3 UW |
11823 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11824 | if (!loc_gdbarch) | |
11825 | loc_gdbarch = gdbarch; | |
11826 | ||
6c95b8df PA |
11827 | describe_other_breakpoints (loc_gdbarch, |
11828 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11829 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11830 | version for exception catchpoints, because two catchpoints | |
11831 | used for different exception names will use the same address. | |
11832 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11833 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11834 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11835 | the user what type of catchpoint it is. The above is good |
11836 | enough for now, though. */ | |
11837 | } | |
11838 | ||
28010a5d | 11839 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11840 | |
349774ef | 11841 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11842 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11843 | b->addr_string = addr_string; |
11844 | b->language = language_ada; | |
f7f9143b JB |
11845 | } |
11846 | ||
a96d9b2e SDJ |
11847 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11848 | filter list, or NULL if no filtering is required. */ | |
11849 | static VEC(int) * | |
11850 | catch_syscall_split_args (char *arg) | |
11851 | { | |
11852 | VEC(int) *result = NULL; | |
29d0bb3d | 11853 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11854 | |
11855 | while (*arg != '\0') | |
11856 | { | |
11857 | int i, syscall_number; | |
11858 | char *endptr; | |
11859 | char cur_name[128]; | |
11860 | struct syscall s; | |
11861 | ||
11862 | /* Skip whitespace. */ | |
529480d0 | 11863 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11864 | |
11865 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11866 | cur_name[i] = arg[i]; | |
11867 | cur_name[i] = '\0'; | |
11868 | arg += i; | |
11869 | ||
11870 | /* Check if the user provided a syscall name or a number. */ | |
11871 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11872 | if (*endptr == '\0') | |
bccd0dd2 | 11873 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11874 | else |
11875 | { | |
11876 | /* We have a name. Let's check if it's valid and convert it | |
11877 | to a number. */ | |
11878 | get_syscall_by_name (cur_name, &s); | |
11879 | ||
11880 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11881 | /* Here we have to issue an error instead of a warning, |
11882 | because GDB cannot do anything useful if there's no | |
11883 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11884 | error (_("Unknown syscall name '%s'."), cur_name); |
11885 | } | |
11886 | ||
11887 | /* Ok, it's valid. */ | |
11888 | VEC_safe_push (int, result, s.number); | |
11889 | } | |
11890 | ||
11891 | discard_cleanups (cleanup); | |
11892 | return result; | |
11893 | } | |
11894 | ||
11895 | /* Implement the "catch syscall" command. */ | |
11896 | ||
11897 | static void | |
cc59ec59 MS |
11898 | catch_syscall_command_1 (char *arg, int from_tty, |
11899 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11900 | { |
11901 | int tempflag; | |
11902 | VEC(int) *filter; | |
11903 | struct syscall s; | |
11904 | struct gdbarch *gdbarch = get_current_arch (); | |
11905 | ||
11906 | /* Checking if the feature if supported. */ | |
11907 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11908 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11909 | this architecture yet.")); |
a96d9b2e SDJ |
11910 | |
11911 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11912 | ||
e9cafbcc | 11913 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11914 | |
11915 | /* We need to do this first "dummy" translation in order | |
11916 | to get the syscall XML file loaded or, most important, | |
11917 | to display a warning to the user if there's no XML file | |
11918 | for his/her architecture. */ | |
11919 | get_syscall_by_number (0, &s); | |
11920 | ||
11921 | /* The allowed syntax is: | |
11922 | catch syscall | |
11923 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11924 | ||
11925 | Let's check if there's a syscall name. */ | |
11926 | ||
11927 | if (arg != NULL) | |
11928 | filter = catch_syscall_split_args (arg); | |
11929 | else | |
11930 | filter = NULL; | |
11931 | ||
11932 | create_syscall_event_catchpoint (tempflag, filter, | |
11933 | &catch_syscall_breakpoint_ops); | |
11934 | } | |
11935 | ||
c906108c | 11936 | static void |
fba45db2 | 11937 | catch_command (char *arg, int from_tty) |
c906108c | 11938 | { |
44feb3ce | 11939 | error (_("Catch requires an event name.")); |
c906108c SS |
11940 | } |
11941 | \f | |
11942 | ||
11943 | static void | |
fba45db2 | 11944 | tcatch_command (char *arg, int from_tty) |
c906108c | 11945 | { |
44feb3ce | 11946 | error (_("Catch requires an event name.")); |
c906108c SS |
11947 | } |
11948 | ||
8a2c437b TT |
11949 | /* A qsort comparison function that sorts breakpoints in order. */ |
11950 | ||
11951 | static int | |
11952 | compare_breakpoints (const void *a, const void *b) | |
11953 | { | |
11954 | const breakpoint_p *ba = a; | |
11955 | uintptr_t ua = (uintptr_t) *ba; | |
11956 | const breakpoint_p *bb = b; | |
11957 | uintptr_t ub = (uintptr_t) *bb; | |
11958 | ||
11959 | if ((*ba)->number < (*bb)->number) | |
11960 | return -1; | |
11961 | else if ((*ba)->number > (*bb)->number) | |
11962 | return 1; | |
11963 | ||
11964 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11965 | the number 0. */ | |
11966 | if (ua < ub) | |
11967 | return -1; | |
94b0e70d | 11968 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11969 | } |
11970 | ||
80f8a6eb | 11971 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11972 | |
11973 | static void | |
fba45db2 | 11974 | clear_command (char *arg, int from_tty) |
c906108c | 11975 | { |
8a2c437b | 11976 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11977 | VEC(breakpoint_p) *found = 0; |
11978 | int ix; | |
c906108c SS |
11979 | int default_match; |
11980 | struct symtabs_and_lines sals; | |
11981 | struct symtab_and_line sal; | |
c906108c | 11982 | int i; |
8a2c437b | 11983 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11984 | |
11985 | if (arg) | |
11986 | { | |
39cf75f7 DE |
11987 | sals = decode_line_with_current_source (arg, |
11988 | (DECODE_LINE_FUNFIRSTLINE | |
11989 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11990 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11991 | default_match = 0; |
11992 | } | |
11993 | else | |
11994 | { | |
c5aa993b | 11995 | sals.sals = (struct symtab_and_line *) |
c906108c | 11996 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11997 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11998 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11999 | |
12000 | /* Set sal's line, symtab, pc, and pspace to the values | |
12001 | corresponding to the last call to print_frame_info. If the | |
12002 | codepoint is not valid, this will set all the fields to 0. */ | |
12003 | get_last_displayed_sal (&sal); | |
c906108c | 12004 | if (sal.symtab == 0) |
8a3fe4f8 | 12005 | error (_("No source file specified.")); |
c906108c SS |
12006 | |
12007 | sals.sals[0] = sal; | |
12008 | sals.nelts = 1; | |
12009 | ||
12010 | default_match = 1; | |
12011 | } | |
12012 | ||
4a64f543 MS |
12013 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12014 | seems, because all existing breakpoints typically have both | |
12015 | file/line and pc set. So, if clear is given file/line, we can | |
12016 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12017 | |
12018 | We only support clearing given the address explicitly | |
12019 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12020 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12021 | due to optimization, all in one block. |
4a64f543 MS |
12022 | |
12023 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12024 | PC corresponding to the same file:line, the breakpoint won't |
12025 | be cleared. We probably can still clear the breakpoint, but | |
12026 | since the other PC value is never presented to user, user | |
12027 | can only find it by guessing, and it does not seem important | |
12028 | to support that. */ | |
12029 | ||
4a64f543 MS |
12030 | /* For each line spec given, delete bps which correspond to it. Do |
12031 | it in two passes, solely to preserve the current behavior that | |
12032 | from_tty is forced true if we delete more than one | |
12033 | breakpoint. */ | |
c906108c | 12034 | |
80f8a6eb | 12035 | found = NULL; |
8a2c437b | 12036 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12037 | for (i = 0; i < sals.nelts; i++) |
12038 | { | |
05cba821 JK |
12039 | const char *sal_fullname; |
12040 | ||
c906108c | 12041 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12042 | If line given (pc == 0), clear all bpts on specified line. |
12043 | If defaulting, clear all bpts on default line | |
c906108c | 12044 | or at default pc. |
c5aa993b JM |
12045 | |
12046 | defaulting sal.pc != 0 tests to do | |
12047 | ||
12048 | 0 1 pc | |
12049 | 1 1 pc _and_ line | |
12050 | 0 0 line | |
12051 | 1 0 <can't happen> */ | |
c906108c SS |
12052 | |
12053 | sal = sals.sals[i]; | |
05cba821 JK |
12054 | sal_fullname = (sal.symtab == NULL |
12055 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12056 | |
4a64f543 | 12057 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12058 | ALL_BREAKPOINTS (b) |
c5aa993b | 12059 | { |
0d381245 | 12060 | int match = 0; |
4a64f543 | 12061 | /* Are we going to delete b? */ |
cc60f2e3 | 12062 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12063 | { |
12064 | struct bp_location *loc = b->loc; | |
12065 | for (; loc; loc = loc->next) | |
12066 | { | |
f8eba3c6 TT |
12067 | /* If the user specified file:line, don't allow a PC |
12068 | match. This matches historical gdb behavior. */ | |
12069 | int pc_match = (!sal.explicit_line | |
12070 | && sal.pc | |
12071 | && (loc->pspace == sal.pspace) | |
12072 | && (loc->address == sal.pc) | |
12073 | && (!section_is_overlay (loc->section) | |
12074 | || loc->section == sal.section)); | |
4aac40c8 TT |
12075 | int line_match = 0; |
12076 | ||
12077 | if ((default_match || sal.explicit_line) | |
2f202fde | 12078 | && loc->symtab != NULL |
05cba821 | 12079 | && sal_fullname != NULL |
4aac40c8 | 12080 | && sal.pspace == loc->pspace |
05cba821 JK |
12081 | && loc->line_number == sal.line |
12082 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12083 | sal_fullname) == 0) | |
12084 | line_match = 1; | |
4aac40c8 | 12085 | |
0d381245 VP |
12086 | if (pc_match || line_match) |
12087 | { | |
12088 | match = 1; | |
12089 | break; | |
12090 | } | |
12091 | } | |
12092 | } | |
12093 | ||
12094 | if (match) | |
d6e956e5 | 12095 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12096 | } |
80f8a6eb | 12097 | } |
8a2c437b | 12098 | |
80f8a6eb | 12099 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12100 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12101 | { |
12102 | if (arg) | |
8a3fe4f8 | 12103 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12104 | else |
8a3fe4f8 | 12105 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12106 | } |
c906108c | 12107 | |
8a2c437b TT |
12108 | /* Remove duplicates from the vec. */ |
12109 | qsort (VEC_address (breakpoint_p, found), | |
12110 | VEC_length (breakpoint_p, found), | |
12111 | sizeof (breakpoint_p), | |
12112 | compare_breakpoints); | |
12113 | prev = VEC_index (breakpoint_p, found, 0); | |
12114 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12115 | { | |
12116 | if (b == prev) | |
12117 | { | |
12118 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12119 | --ix; | |
12120 | } | |
12121 | } | |
12122 | ||
d6e956e5 | 12123 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12124 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12125 | if (from_tty) |
a3f17187 | 12126 | { |
d6e956e5 | 12127 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12128 | printf_unfiltered (_("Deleted breakpoint ")); |
12129 | else | |
12130 | printf_unfiltered (_("Deleted breakpoints ")); | |
12131 | } | |
d6e956e5 VP |
12132 | |
12133 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12134 | { |
c5aa993b | 12135 | if (from_tty) |
d6e956e5 VP |
12136 | printf_unfiltered ("%d ", b->number); |
12137 | delete_breakpoint (b); | |
c906108c | 12138 | } |
80f8a6eb MS |
12139 | if (from_tty) |
12140 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12141 | |
12142 | do_cleanups (cleanups); | |
c906108c SS |
12143 | } |
12144 | \f | |
12145 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12146 | all breakpoints that are marked for deletion, whether hit or not. | |
12147 | This is called after any breakpoint is hit, or after errors. */ | |
12148 | ||
12149 | void | |
fba45db2 | 12150 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12151 | { |
35df4500 | 12152 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12153 | |
12154 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12155 | if (bs->breakpoint_at |
12156 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12157 | && bs->stop) |
f431efe5 | 12158 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12159 | |
35df4500 | 12160 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12161 | { |
b5de0fa7 | 12162 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12163 | delete_breakpoint (b); |
12164 | } | |
c906108c SS |
12165 | } |
12166 | ||
4a64f543 MS |
12167 | /* A comparison function for bp_location AP and BP being interfaced to |
12168 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12169 | does breakpoint_address_is_meaningful say for its OWNER), | |
12170 | secondarily by ordering first bp_permanent OWNERed elements and | |
12171 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12172 | qsort being an unstable algorithm. */ |
876fa593 JK |
12173 | |
12174 | static int | |
494cfb0f | 12175 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12176 | { |
494cfb0f JK |
12177 | struct bp_location *a = *(void **) ap; |
12178 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12179 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12180 | int a_perm = a->owner->enable_state == bp_permanent; |
12181 | int b_perm = b->owner->enable_state == bp_permanent; | |
12182 | ||
12183 | if (a->address != b->address) | |
12184 | return (a->address > b->address) - (a->address < b->address); | |
12185 | ||
dea2aa5f LM |
12186 | /* Sort locations at the same address by their pspace number, keeping |
12187 | locations of the same inferior (in a multi-inferior environment) | |
12188 | grouped. */ | |
12189 | ||
12190 | if (a->pspace->num != b->pspace->num) | |
12191 | return ((a->pspace->num > b->pspace->num) | |
12192 | - (a->pspace->num < b->pspace->num)); | |
12193 | ||
876fa593 JK |
12194 | /* Sort permanent breakpoints first. */ |
12195 | if (a_perm != b_perm) | |
12196 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12197 | ||
c56a97f9 JK |
12198 | /* Make the internal GDB representation stable across GDB runs |
12199 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12200 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12201 | |
12202 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12203 | return ((a->owner->number > b->owner->number) |
12204 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12205 | |
12206 | return (a > b) - (a < b); | |
12207 | } | |
12208 | ||
876fa593 | 12209 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12210 | bp_location_shadow_len_after_address_max according to the current |
12211 | content of the bp_location array. */ | |
f7545552 TT |
12212 | |
12213 | static void | |
876fa593 | 12214 | bp_location_target_extensions_update (void) |
f7545552 | 12215 | { |
876fa593 JK |
12216 | struct bp_location *bl, **blp_tmp; |
12217 | ||
12218 | bp_location_placed_address_before_address_max = 0; | |
12219 | bp_location_shadow_len_after_address_max = 0; | |
12220 | ||
12221 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12222 | { | |
12223 | CORE_ADDR start, end, addr; | |
12224 | ||
12225 | if (!bp_location_has_shadow (bl)) | |
12226 | continue; | |
12227 | ||
12228 | start = bl->target_info.placed_address; | |
12229 | end = start + bl->target_info.shadow_len; | |
12230 | ||
12231 | gdb_assert (bl->address >= start); | |
12232 | addr = bl->address - start; | |
12233 | if (addr > bp_location_placed_address_before_address_max) | |
12234 | bp_location_placed_address_before_address_max = addr; | |
12235 | ||
12236 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12237 | ||
12238 | gdb_assert (bl->address < end); | |
12239 | addr = end - bl->address; | |
12240 | if (addr > bp_location_shadow_len_after_address_max) | |
12241 | bp_location_shadow_len_after_address_max = addr; | |
12242 | } | |
f7545552 TT |
12243 | } |
12244 | ||
1e4d1764 YQ |
12245 | /* Download tracepoint locations if they haven't been. */ |
12246 | ||
12247 | static void | |
12248 | download_tracepoint_locations (void) | |
12249 | { | |
7ed2c994 | 12250 | struct breakpoint *b; |
1e4d1764 YQ |
12251 | struct cleanup *old_chain; |
12252 | ||
12253 | if (!target_can_download_tracepoint ()) | |
12254 | return; | |
12255 | ||
12256 | old_chain = save_current_space_and_thread (); | |
12257 | ||
7ed2c994 | 12258 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12259 | { |
7ed2c994 | 12260 | struct bp_location *bl; |
1e4d1764 | 12261 | struct tracepoint *t; |
f2a8bc8a | 12262 | int bp_location_downloaded = 0; |
1e4d1764 | 12263 | |
7ed2c994 | 12264 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12265 | ? !may_insert_fast_tracepoints |
12266 | : !may_insert_tracepoints)) | |
12267 | continue; | |
12268 | ||
7ed2c994 YQ |
12269 | for (bl = b->loc; bl; bl = bl->next) |
12270 | { | |
12271 | /* In tracepoint, locations are _never_ duplicated, so | |
12272 | should_be_inserted is equivalent to | |
12273 | unduplicated_should_be_inserted. */ | |
12274 | if (!should_be_inserted (bl) || bl->inserted) | |
12275 | continue; | |
1e4d1764 | 12276 | |
7ed2c994 | 12277 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12278 | |
7ed2c994 | 12279 | target_download_tracepoint (bl); |
1e4d1764 | 12280 | |
7ed2c994 | 12281 | bl->inserted = 1; |
f2a8bc8a | 12282 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12283 | } |
12284 | t = (struct tracepoint *) b; | |
12285 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12286 | if (bp_location_downloaded) |
12287 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12288 | } |
12289 | ||
12290 | do_cleanups (old_chain); | |
12291 | } | |
12292 | ||
934709f0 PW |
12293 | /* Swap the insertion/duplication state between two locations. */ |
12294 | ||
12295 | static void | |
12296 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12297 | { | |
12298 | const int left_inserted = left->inserted; | |
12299 | const int left_duplicate = left->duplicate; | |
b775012e | 12300 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12301 | const struct bp_target_info left_target_info = left->target_info; |
12302 | ||
1e4d1764 YQ |
12303 | /* Locations of tracepoints can never be duplicated. */ |
12304 | if (is_tracepoint (left->owner)) | |
12305 | gdb_assert (!left->duplicate); | |
12306 | if (is_tracepoint (right->owner)) | |
12307 | gdb_assert (!right->duplicate); | |
12308 | ||
934709f0 PW |
12309 | left->inserted = right->inserted; |
12310 | left->duplicate = right->duplicate; | |
b775012e | 12311 | left->needs_update = right->needs_update; |
934709f0 PW |
12312 | left->target_info = right->target_info; |
12313 | right->inserted = left_inserted; | |
12314 | right->duplicate = left_duplicate; | |
b775012e | 12315 | right->needs_update = left_needs_update; |
934709f0 PW |
12316 | right->target_info = left_target_info; |
12317 | } | |
12318 | ||
b775012e LM |
12319 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12320 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12321 | conditions on the target's side. Such conditions need to be updated on | |
12322 | the target. */ | |
12323 | ||
12324 | static void | |
12325 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12326 | { | |
12327 | struct bp_location **locp = NULL, **loc2p; | |
12328 | struct bp_location *loc; | |
12329 | CORE_ADDR address = 0; | |
12330 | int pspace_num; | |
12331 | ||
12332 | address = bl->address; | |
12333 | pspace_num = bl->pspace->num; | |
12334 | ||
12335 | /* This is only meaningful if the target is | |
12336 | evaluating conditions and if the user has | |
12337 | opted for condition evaluation on the target's | |
12338 | side. */ | |
12339 | if (gdb_evaluates_breakpoint_condition_p () | |
12340 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12341 | return; | |
12342 | ||
12343 | /* Flag all breakpoint locations with this address and | |
12344 | the same program space as the location | |
12345 | as "its condition has changed". We need to | |
12346 | update the conditions on the target's side. */ | |
12347 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12348 | { | |
12349 | loc = *loc2p; | |
12350 | ||
12351 | if (!is_breakpoint (loc->owner) | |
12352 | || pspace_num != loc->pspace->num) | |
12353 | continue; | |
12354 | ||
12355 | /* Flag the location appropriately. We use a different state to | |
12356 | let everyone know that we already updated the set of locations | |
12357 | with addr bl->address and program space bl->pspace. This is so | |
12358 | we don't have to keep calling these functions just to mark locations | |
12359 | that have already been marked. */ | |
12360 | loc->condition_changed = condition_updated; | |
12361 | ||
12362 | /* Free the agent expression bytecode as well. We will compute | |
12363 | it later on. */ | |
12364 | if (loc->cond_bytecode) | |
12365 | { | |
12366 | free_agent_expr (loc->cond_bytecode); | |
12367 | loc->cond_bytecode = NULL; | |
12368 | } | |
12369 | } | |
12370 | } | |
12371 | ||
4cd9bd08 | 12372 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12373 | into the inferior, only remove already-inserted locations that no |
12374 | longer should be inserted. Functions that delete a breakpoint or | |
12375 | breakpoints should pass false, so that deleting a breakpoint | |
12376 | doesn't have the side effect of inserting the locations of other | |
12377 | breakpoints that are marked not-inserted, but should_be_inserted | |
12378 | returns true on them. | |
12379 | ||
12380 | This behaviour is useful is situations close to tear-down -- e.g., | |
12381 | after an exec, while the target still has execution, but breakpoint | |
12382 | shadows of the previous executable image should *NOT* be restored | |
12383 | to the new image; or before detaching, where the target still has | |
12384 | execution and wants to delete breakpoints from GDB's lists, and all | |
12385 | breakpoints had already been removed from the inferior. */ | |
12386 | ||
0d381245 | 12387 | static void |
b60e7edf | 12388 | update_global_location_list (int should_insert) |
0d381245 | 12389 | { |
74960c60 | 12390 | struct breakpoint *b; |
876fa593 | 12391 | struct bp_location **locp, *loc; |
f7545552 | 12392 | struct cleanup *cleanups; |
b775012e LM |
12393 | /* Last breakpoint location address that was marked for update. */ |
12394 | CORE_ADDR last_addr = 0; | |
12395 | /* Last breakpoint location program space that was marked for update. */ | |
12396 | int last_pspace_num = -1; | |
f7545552 | 12397 | |
2d134ed3 PA |
12398 | /* Used in the duplicates detection below. When iterating over all |
12399 | bp_locations, points to the first bp_location of a given address. | |
12400 | Breakpoints and watchpoints of different types are never | |
12401 | duplicates of each other. Keep one pointer for each type of | |
12402 | breakpoint/watchpoint, so we only need to loop over all locations | |
12403 | once. */ | |
12404 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12405 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12406 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12407 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12408 | |
4a64f543 MS |
12409 | /* Saved former bp_location array which we compare against the newly |
12410 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12411 | struct bp_location **old_location, **old_locp; |
12412 | unsigned old_location_count; | |
12413 | ||
12414 | old_location = bp_location; | |
12415 | old_location_count = bp_location_count; | |
12416 | bp_location = NULL; | |
12417 | bp_location_count = 0; | |
12418 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12419 | |
74960c60 | 12420 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12421 | for (loc = b->loc; loc; loc = loc->next) |
12422 | bp_location_count++; | |
12423 | ||
12424 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12425 | locp = bp_location; | |
12426 | ALL_BREAKPOINTS (b) | |
12427 | for (loc = b->loc; loc; loc = loc->next) | |
12428 | *locp++ = loc; | |
12429 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12430 | bp_location_compare); |
876fa593 JK |
12431 | |
12432 | bp_location_target_extensions_update (); | |
74960c60 | 12433 | |
4a64f543 MS |
12434 | /* Identify bp_location instances that are no longer present in the |
12435 | new list, and therefore should be freed. Note that it's not | |
12436 | necessary that those locations should be removed from inferior -- | |
12437 | if there's another location at the same address (previously | |
12438 | marked as duplicate), we don't need to remove/insert the | |
12439 | location. | |
876fa593 | 12440 | |
4a64f543 MS |
12441 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12442 | and former bp_location array state respectively. */ | |
876fa593 JK |
12443 | |
12444 | locp = bp_location; | |
12445 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12446 | old_locp++) | |
74960c60 | 12447 | { |
876fa593 | 12448 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12449 | struct bp_location **loc2p; |
876fa593 | 12450 | |
e5dd4106 | 12451 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12452 | not, we have to free it. */ |
c7d46a38 | 12453 | int found_object = 0; |
20874c92 VP |
12454 | /* Tells if the location should remain inserted in the target. */ |
12455 | int keep_in_target = 0; | |
12456 | int removed = 0; | |
876fa593 | 12457 | |
4a64f543 MS |
12458 | /* Skip LOCP entries which will definitely never be needed. |
12459 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12460 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12461 | && (*locp)->address < old_loc->address) |
876fa593 | 12462 | locp++; |
c7d46a38 PA |
12463 | |
12464 | for (loc2p = locp; | |
12465 | (loc2p < bp_location + bp_location_count | |
12466 | && (*loc2p)->address == old_loc->address); | |
12467 | loc2p++) | |
12468 | { | |
b775012e LM |
12469 | /* Check if this is a new/duplicated location or a duplicated |
12470 | location that had its condition modified. If so, we want to send | |
12471 | its condition to the target if evaluation of conditions is taking | |
12472 | place there. */ | |
12473 | if ((*loc2p)->condition_changed == condition_modified | |
12474 | && (last_addr != old_loc->address | |
12475 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12476 | { |
b775012e LM |
12477 | force_breakpoint_reinsertion (*loc2p); |
12478 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12479 | } |
b775012e LM |
12480 | |
12481 | if (*loc2p == old_loc) | |
12482 | found_object = 1; | |
c7d46a38 | 12483 | } |
74960c60 | 12484 | |
b775012e LM |
12485 | /* We have already handled this address, update it so that we don't |
12486 | have to go through updates again. */ | |
12487 | last_addr = old_loc->address; | |
12488 | ||
12489 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12490 | if (!found_object) | |
12491 | force_breakpoint_reinsertion (old_loc); | |
12492 | ||
4a64f543 MS |
12493 | /* If this location is no longer present, and inserted, look if |
12494 | there's maybe a new location at the same address. If so, | |
12495 | mark that one inserted, and don't remove this one. This is | |
12496 | needed so that we don't have a time window where a breakpoint | |
12497 | at certain location is not inserted. */ | |
74960c60 | 12498 | |
876fa593 | 12499 | if (old_loc->inserted) |
0d381245 | 12500 | { |
4a64f543 MS |
12501 | /* If the location is inserted now, we might have to remove |
12502 | it. */ | |
74960c60 | 12503 | |
876fa593 | 12504 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12505 | { |
4a64f543 MS |
12506 | /* The location is still present in the location list, |
12507 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12508 | keep_in_target = 1; |
74960c60 VP |
12509 | } |
12510 | else | |
12511 | { | |
b775012e LM |
12512 | /* This location still exists, but it won't be kept in the |
12513 | target since it may have been disabled. We proceed to | |
12514 | remove its target-side condition. */ | |
12515 | ||
4a64f543 MS |
12516 | /* The location is either no longer present, or got |
12517 | disabled. See if there's another location at the | |
12518 | same address, in which case we don't need to remove | |
12519 | this one from the target. */ | |
876fa593 | 12520 | |
2bdf28a0 | 12521 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12522 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12523 | { | |
876fa593 | 12524 | for (loc2p = locp; |
c7d46a38 PA |
12525 | (loc2p < bp_location + bp_location_count |
12526 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12527 | loc2p++) |
12528 | { | |
12529 | struct bp_location *loc2 = *loc2p; | |
12530 | ||
2d134ed3 | 12531 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12532 | { |
85d721b8 PA |
12533 | /* Read watchpoint locations are switched to |
12534 | access watchpoints, if the former are not | |
12535 | supported, but the latter are. */ | |
12536 | if (is_hardware_watchpoint (old_loc->owner)) | |
12537 | { | |
12538 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12539 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12540 | } | |
12541 | ||
934709f0 PW |
12542 | /* loc2 is a duplicated location. We need to check |
12543 | if it should be inserted in case it will be | |
12544 | unduplicated. */ | |
12545 | if (loc2 != old_loc | |
12546 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12547 | { |
934709f0 | 12548 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12549 | keep_in_target = 1; |
12550 | break; | |
12551 | } | |
876fa593 JK |
12552 | } |
12553 | } | |
12554 | } | |
74960c60 VP |
12555 | } |
12556 | ||
20874c92 VP |
12557 | if (!keep_in_target) |
12558 | { | |
876fa593 | 12559 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12560 | { |
4a64f543 MS |
12561 | /* This is just about all we can do. We could keep |
12562 | this location on the global list, and try to | |
12563 | remove it next time, but there's no particular | |
12564 | reason why we will succeed next time. | |
20874c92 | 12565 | |
4a64f543 MS |
12566 | Note that at this point, old_loc->owner is still |
12567 | valid, as delete_breakpoint frees the breakpoint | |
12568 | only after calling us. */ | |
3e43a32a MS |
12569 | printf_filtered (_("warning: Error removing " |
12570 | "breakpoint %d\n"), | |
876fa593 | 12571 | old_loc->owner->number); |
20874c92 VP |
12572 | } |
12573 | removed = 1; | |
12574 | } | |
0d381245 | 12575 | } |
74960c60 VP |
12576 | |
12577 | if (!found_object) | |
1c5cfe86 | 12578 | { |
db82e815 PA |
12579 | if (removed && non_stop |
12580 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12581 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12582 | { |
db82e815 PA |
12583 | /* This location was removed from the target. In |
12584 | non-stop mode, a race condition is possible where | |
12585 | we've removed a breakpoint, but stop events for that | |
12586 | breakpoint are already queued and will arrive later. | |
12587 | We apply an heuristic to be able to distinguish such | |
12588 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12589 | breakpoint location for a bit, and will retire it | |
12590 | after we see some number of events. The theory here | |
12591 | is that reporting of events should, "on the average", | |
12592 | be fair, so after a while we'll see events from all | |
12593 | threads that have anything of interest, and no longer | |
12594 | need to keep this breakpoint location around. We | |
12595 | don't hold locations forever so to reduce chances of | |
12596 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12597 | SIGTRAP. | |
12598 | ||
12599 | The heuristic failing can be disastrous on | |
12600 | decr_pc_after_break targets. | |
12601 | ||
12602 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12603 | if we fail to recognize a late breakpoint SIGTRAP, | |
12604 | because events_till_retirement has reached 0 too | |
12605 | soon, we'll fail to do the PC adjustment, and report | |
12606 | a random SIGTRAP to the user. When the user resumes | |
12607 | the inferior, it will most likely immediately crash | |
2dec564e | 12608 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12609 | corrupted, because of being resumed e.g., in the |
12610 | middle of a multi-byte instruction, or skipped a | |
12611 | one-byte instruction. This was actually seen happen | |
12612 | on native x86-linux, and should be less rare on | |
12613 | targets that do not support new thread events, like | |
12614 | remote, due to the heuristic depending on | |
12615 | thread_count. | |
12616 | ||
12617 | Mistaking a random SIGTRAP for a breakpoint trap | |
12618 | causes similar symptoms (PC adjustment applied when | |
12619 | it shouldn't), but then again, playing with SIGTRAPs | |
12620 | behind the debugger's back is asking for trouble. | |
12621 | ||
12622 | Since hardware watchpoint traps are always | |
12623 | distinguishable from other traps, so we don't need to | |
12624 | apply keep hardware watchpoint moribund locations | |
12625 | around. We simply always ignore hardware watchpoint | |
12626 | traps we can no longer explain. */ | |
12627 | ||
876fa593 JK |
12628 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12629 | old_loc->owner = NULL; | |
20874c92 | 12630 | |
876fa593 | 12631 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12632 | } |
12633 | else | |
f431efe5 PA |
12634 | { |
12635 | old_loc->owner = NULL; | |
12636 | decref_bp_location (&old_loc); | |
12637 | } | |
20874c92 | 12638 | } |
74960c60 | 12639 | } |
1c5cfe86 | 12640 | |
348d480f PA |
12641 | /* Rescan breakpoints at the same address and section, marking the |
12642 | first one as "first" and any others as "duplicates". This is so | |
12643 | that the bpt instruction is only inserted once. If we have a | |
12644 | permanent breakpoint at the same place as BPT, make that one the | |
12645 | official one, and the rest as duplicates. Permanent breakpoints | |
12646 | are sorted first for the same address. | |
12647 | ||
12648 | Do the same for hardware watchpoints, but also considering the | |
12649 | watchpoint's type (regular/access/read) and length. */ | |
12650 | ||
12651 | bp_loc_first = NULL; | |
12652 | wp_loc_first = NULL; | |
12653 | awp_loc_first = NULL; | |
12654 | rwp_loc_first = NULL; | |
12655 | ALL_BP_LOCATIONS (loc, locp) | |
12656 | { | |
12657 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12658 | non-NULL. */ | |
348d480f | 12659 | struct bp_location **loc_first_p; |
d3fbdd86 | 12660 | b = loc->owner; |
348d480f | 12661 | |
6f380991 | 12662 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12663 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12664 | /* Don't detect duplicate for tracepoint locations because they are |
12665 | never duplicated. See the comments in field `duplicate' of | |
12666 | `struct bp_location'. */ | |
348d480f | 12667 | || is_tracepoint (b)) |
b775012e LM |
12668 | { |
12669 | /* Clear the condition modification flag. */ | |
12670 | loc->condition_changed = condition_unchanged; | |
12671 | continue; | |
12672 | } | |
348d480f PA |
12673 | |
12674 | /* Permanent breakpoint should always be inserted. */ | |
12675 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12676 | internal_error (__FILE__, __LINE__, | |
12677 | _("allegedly permanent breakpoint is not " | |
12678 | "actually inserted")); | |
12679 | ||
12680 | if (b->type == bp_hardware_watchpoint) | |
12681 | loc_first_p = &wp_loc_first; | |
12682 | else if (b->type == bp_read_watchpoint) | |
12683 | loc_first_p = &rwp_loc_first; | |
12684 | else if (b->type == bp_access_watchpoint) | |
12685 | loc_first_p = &awp_loc_first; | |
12686 | else | |
12687 | loc_first_p = &bp_loc_first; | |
12688 | ||
12689 | if (*loc_first_p == NULL | |
12690 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12691 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12692 | { | |
12693 | *loc_first_p = loc; | |
12694 | loc->duplicate = 0; | |
b775012e LM |
12695 | |
12696 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12697 | { | |
12698 | loc->needs_update = 1; | |
12699 | /* Clear the condition modification flag. */ | |
12700 | loc->condition_changed = condition_unchanged; | |
12701 | } | |
348d480f PA |
12702 | continue; |
12703 | } | |
12704 | ||
934709f0 PW |
12705 | |
12706 | /* This and the above ensure the invariant that the first location | |
12707 | is not duplicated, and is the inserted one. | |
12708 | All following are marked as duplicated, and are not inserted. */ | |
12709 | if (loc->inserted) | |
12710 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12711 | loc->duplicate = 1; |
12712 | ||
b775012e LM |
12713 | /* Clear the condition modification flag. */ |
12714 | loc->condition_changed = condition_unchanged; | |
12715 | ||
348d480f PA |
12716 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12717 | && b->enable_state != bp_permanent) | |
12718 | internal_error (__FILE__, __LINE__, | |
12719 | _("another breakpoint was inserted on top of " | |
12720 | "a permanent breakpoint")); | |
12721 | } | |
12722 | ||
b775012e | 12723 | if (breakpoints_always_inserted_mode () |
348d480f | 12724 | && (have_live_inferiors () |
f5656ead | 12725 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12726 | { |
12727 | if (should_insert) | |
12728 | insert_breakpoint_locations (); | |
12729 | else | |
12730 | { | |
12731 | /* Though should_insert is false, we may need to update conditions | |
12732 | on the target's side if it is evaluating such conditions. We | |
12733 | only update conditions for locations that are marked | |
12734 | "needs_update". */ | |
12735 | update_inserted_breakpoint_locations (); | |
12736 | } | |
12737 | } | |
348d480f | 12738 | |
1e4d1764 YQ |
12739 | if (should_insert) |
12740 | download_tracepoint_locations (); | |
12741 | ||
348d480f PA |
12742 | do_cleanups (cleanups); |
12743 | } | |
12744 | ||
12745 | void | |
12746 | breakpoint_retire_moribund (void) | |
12747 | { | |
12748 | struct bp_location *loc; | |
12749 | int ix; | |
12750 | ||
12751 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12752 | if (--(loc->events_till_retirement) == 0) | |
12753 | { | |
12754 | decref_bp_location (&loc); | |
12755 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12756 | --ix; | |
12757 | } | |
12758 | } | |
12759 | ||
12760 | static void | |
12761 | update_global_location_list_nothrow (int inserting) | |
12762 | { | |
bfd189b1 | 12763 | volatile struct gdb_exception e; |
348d480f PA |
12764 | |
12765 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12766 | update_global_location_list (inserting); | |
12767 | } | |
12768 | ||
12769 | /* Clear BKP from a BPS. */ | |
12770 | ||
12771 | static void | |
12772 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12773 | { | |
12774 | bpstat bs; | |
12775 | ||
12776 | for (bs = bps; bs; bs = bs->next) | |
12777 | if (bs->breakpoint_at == bpt) | |
12778 | { | |
12779 | bs->breakpoint_at = NULL; | |
12780 | bs->old_val = NULL; | |
12781 | /* bs->commands will be freed later. */ | |
12782 | } | |
12783 | } | |
12784 | ||
12785 | /* Callback for iterate_over_threads. */ | |
12786 | static int | |
12787 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12788 | { | |
12789 | struct breakpoint *bpt = data; | |
12790 | ||
12791 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12792 | return 0; | |
12793 | } | |
12794 | ||
12795 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12796 | callbacks. */ | |
12797 | ||
12798 | static void | |
12799 | say_where (struct breakpoint *b) | |
12800 | { | |
12801 | struct value_print_options opts; | |
12802 | ||
12803 | get_user_print_options (&opts); | |
12804 | ||
12805 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12806 | single string. */ | |
12807 | if (b->loc == NULL) | |
12808 | { | |
12809 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12810 | } | |
12811 | else | |
12812 | { | |
2f202fde | 12813 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12814 | { |
12815 | printf_filtered (" at "); | |
12816 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12817 | gdb_stdout); | |
12818 | } | |
2f202fde | 12819 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12820 | { |
12821 | /* If there is a single location, we can print the location | |
12822 | more nicely. */ | |
12823 | if (b->loc->next == NULL) | |
12824 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12825 | symtab_to_filename_for_display (b->loc->symtab), |
12826 | b->loc->line_number); | |
f8eba3c6 TT |
12827 | else |
12828 | /* This is not ideal, but each location may have a | |
12829 | different file name, and this at least reflects the | |
12830 | real situation somewhat. */ | |
12831 | printf_filtered (": %s.", b->addr_string); | |
12832 | } | |
348d480f PA |
12833 | |
12834 | if (b->loc->next) | |
12835 | { | |
12836 | struct bp_location *loc = b->loc; | |
12837 | int n = 0; | |
12838 | for (; loc; loc = loc->next) | |
12839 | ++n; | |
12840 | printf_filtered (" (%d locations)", n); | |
12841 | } | |
12842 | } | |
12843 | } | |
12844 | ||
348d480f PA |
12845 | /* Default bp_location_ops methods. */ |
12846 | ||
12847 | static void | |
12848 | bp_location_dtor (struct bp_location *self) | |
12849 | { | |
12850 | xfree (self->cond); | |
b775012e LM |
12851 | if (self->cond_bytecode) |
12852 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12853 | xfree (self->function_name); |
8b4f3082 PA |
12854 | |
12855 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12856 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12857 | } |
12858 | ||
12859 | static const struct bp_location_ops bp_location_ops = | |
12860 | { | |
12861 | bp_location_dtor | |
12862 | }; | |
12863 | ||
2060206e PA |
12864 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12865 | inherit from. */ | |
348d480f | 12866 | |
2060206e PA |
12867 | static void |
12868 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12869 | { |
12870 | decref_counted_command_line (&self->commands); | |
12871 | xfree (self->cond_string); | |
fb81d016 | 12872 | xfree (self->extra_string); |
348d480f | 12873 | xfree (self->addr_string); |
f8eba3c6 | 12874 | xfree (self->filter); |
348d480f | 12875 | xfree (self->addr_string_range_end); |
348d480f PA |
12876 | } |
12877 | ||
2060206e PA |
12878 | static struct bp_location * |
12879 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12880 | { |
12881 | struct bp_location *loc; | |
12882 | ||
12883 | loc = XNEW (struct bp_location); | |
12884 | init_bp_location (loc, &bp_location_ops, self); | |
12885 | return loc; | |
12886 | } | |
12887 | ||
2060206e PA |
12888 | static void |
12889 | base_breakpoint_re_set (struct breakpoint *b) | |
12890 | { | |
12891 | /* Nothing to re-set. */ | |
12892 | } | |
12893 | ||
12894 | #define internal_error_pure_virtual_called() \ | |
12895 | gdb_assert_not_reached ("pure virtual function called") | |
12896 | ||
12897 | static int | |
12898 | base_breakpoint_insert_location (struct bp_location *bl) | |
12899 | { | |
12900 | internal_error_pure_virtual_called (); | |
12901 | } | |
12902 | ||
12903 | static int | |
12904 | base_breakpoint_remove_location (struct bp_location *bl) | |
12905 | { | |
12906 | internal_error_pure_virtual_called (); | |
12907 | } | |
12908 | ||
12909 | static int | |
12910 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12911 | struct address_space *aspace, | |
09ac7c10 TT |
12912 | CORE_ADDR bp_addr, |
12913 | const struct target_waitstatus *ws) | |
2060206e PA |
12914 | { |
12915 | internal_error_pure_virtual_called (); | |
12916 | } | |
12917 | ||
12918 | static void | |
12919 | base_breakpoint_check_status (bpstat bs) | |
12920 | { | |
12921 | /* Always stop. */ | |
12922 | } | |
12923 | ||
12924 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12925 | errors. */ | |
12926 | ||
12927 | static int | |
12928 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12929 | { | |
12930 | internal_error_pure_virtual_called (); | |
12931 | } | |
12932 | ||
12933 | /* A "resources_needed" breakpoint_ops method that just internal | |
12934 | errors. */ | |
12935 | ||
12936 | static int | |
12937 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12938 | { | |
12939 | internal_error_pure_virtual_called (); | |
12940 | } | |
12941 | ||
12942 | static enum print_stop_action | |
12943 | base_breakpoint_print_it (bpstat bs) | |
12944 | { | |
12945 | internal_error_pure_virtual_called (); | |
12946 | } | |
12947 | ||
12948 | static void | |
12949 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12950 | struct ui_out *uiout) | |
12951 | { | |
12952 | /* nothing */ | |
12953 | } | |
12954 | ||
12955 | static void | |
12956 | base_breakpoint_print_mention (struct breakpoint *b) | |
12957 | { | |
12958 | internal_error_pure_virtual_called (); | |
12959 | } | |
12960 | ||
12961 | static void | |
12962 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12963 | { | |
12964 | internal_error_pure_virtual_called (); | |
12965 | } | |
12966 | ||
983af33b SDJ |
12967 | static void |
12968 | base_breakpoint_create_sals_from_address (char **arg, | |
12969 | struct linespec_result *canonical, | |
12970 | enum bptype type_wanted, | |
12971 | char *addr_start, | |
12972 | char **copy_arg) | |
12973 | { | |
12974 | internal_error_pure_virtual_called (); | |
12975 | } | |
12976 | ||
12977 | static void | |
12978 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12979 | struct linespec_result *c, | |
983af33b | 12980 | char *cond_string, |
e7e0cddf | 12981 | char *extra_string, |
983af33b SDJ |
12982 | enum bptype type_wanted, |
12983 | enum bpdisp disposition, | |
12984 | int thread, | |
12985 | int task, int ignore_count, | |
12986 | const struct breakpoint_ops *o, | |
12987 | int from_tty, int enabled, | |
44f238bb | 12988 | int internal, unsigned flags) |
983af33b SDJ |
12989 | { |
12990 | internal_error_pure_virtual_called (); | |
12991 | } | |
12992 | ||
12993 | static void | |
12994 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12995 | struct symtabs_and_lines *sals) | |
12996 | { | |
12997 | internal_error_pure_virtual_called (); | |
12998 | } | |
12999 | ||
ab04a2af TT |
13000 | /* The default 'explains_signal' method. */ |
13001 | ||
47591c29 | 13002 | static int |
427cd150 | 13003 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13004 | { |
47591c29 | 13005 | return 1; |
ab04a2af TT |
13006 | } |
13007 | ||
9d6e6e84 HZ |
13008 | /* The default "after_condition_true" method. */ |
13009 | ||
13010 | static void | |
13011 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13012 | { | |
13013 | /* Nothing to do. */ | |
13014 | } | |
13015 | ||
ab04a2af | 13016 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13017 | { |
13018 | base_breakpoint_dtor, | |
13019 | base_breakpoint_allocate_location, | |
13020 | base_breakpoint_re_set, | |
13021 | base_breakpoint_insert_location, | |
13022 | base_breakpoint_remove_location, | |
13023 | base_breakpoint_breakpoint_hit, | |
13024 | base_breakpoint_check_status, | |
13025 | base_breakpoint_resources_needed, | |
13026 | base_breakpoint_works_in_software_mode, | |
13027 | base_breakpoint_print_it, | |
13028 | NULL, | |
13029 | base_breakpoint_print_one_detail, | |
13030 | base_breakpoint_print_mention, | |
983af33b SDJ |
13031 | base_breakpoint_print_recreate, |
13032 | base_breakpoint_create_sals_from_address, | |
13033 | base_breakpoint_create_breakpoints_sal, | |
13034 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
13035 | base_breakpoint_explains_signal, |
13036 | base_breakpoint_after_condition_true, | |
2060206e PA |
13037 | }; |
13038 | ||
13039 | /* Default breakpoint_ops methods. */ | |
13040 | ||
13041 | static void | |
348d480f PA |
13042 | bkpt_re_set (struct breakpoint *b) |
13043 | { | |
06edf0c0 PA |
13044 | /* FIXME: is this still reachable? */ |
13045 | if (b->addr_string == NULL) | |
13046 | { | |
13047 | /* Anything without a string can't be re-set. */ | |
348d480f | 13048 | delete_breakpoint (b); |
06edf0c0 | 13049 | return; |
348d480f | 13050 | } |
06edf0c0 PA |
13051 | |
13052 | breakpoint_re_set_default (b); | |
348d480f PA |
13053 | } |
13054 | ||
2060206e | 13055 | static int |
348d480f PA |
13056 | bkpt_insert_location (struct bp_location *bl) |
13057 | { | |
13058 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13059 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13060 | &bl->target_info); | |
13061 | else | |
13062 | return target_insert_breakpoint (bl->gdbarch, | |
13063 | &bl->target_info); | |
13064 | } | |
13065 | ||
2060206e | 13066 | static int |
348d480f PA |
13067 | bkpt_remove_location (struct bp_location *bl) |
13068 | { | |
13069 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13070 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13071 | else | |
13072 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
13073 | } | |
13074 | ||
2060206e | 13075 | static int |
348d480f | 13076 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13077 | struct address_space *aspace, CORE_ADDR bp_addr, |
13078 | const struct target_waitstatus *ws) | |
348d480f | 13079 | { |
09ac7c10 | 13080 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13081 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13082 | return 0; |
13083 | ||
348d480f PA |
13084 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13085 | aspace, bp_addr)) | |
13086 | return 0; | |
13087 | ||
13088 | if (overlay_debugging /* unmapped overlay section */ | |
13089 | && section_is_overlay (bl->section) | |
13090 | && !section_is_mapped (bl->section)) | |
13091 | return 0; | |
13092 | ||
13093 | return 1; | |
13094 | } | |
13095 | ||
2060206e | 13096 | static int |
348d480f PA |
13097 | bkpt_resources_needed (const struct bp_location *bl) |
13098 | { | |
13099 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13100 | ||
13101 | return 1; | |
13102 | } | |
13103 | ||
2060206e | 13104 | static enum print_stop_action |
348d480f PA |
13105 | bkpt_print_it (bpstat bs) |
13106 | { | |
348d480f PA |
13107 | struct breakpoint *b; |
13108 | const struct bp_location *bl; | |
001c8c33 | 13109 | int bp_temp; |
79a45e25 | 13110 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13111 | |
13112 | gdb_assert (bs->bp_location_at != NULL); | |
13113 | ||
13114 | bl = bs->bp_location_at; | |
13115 | b = bs->breakpoint_at; | |
13116 | ||
001c8c33 PA |
13117 | bp_temp = b->disposition == disp_del; |
13118 | if (bl->address != bl->requested_address) | |
13119 | breakpoint_adjustment_warning (bl->requested_address, | |
13120 | bl->address, | |
13121 | b->number, 1); | |
13122 | annotate_breakpoint (b->number); | |
13123 | if (bp_temp) | |
13124 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13125 | else | |
13126 | ui_out_text (uiout, "\nBreakpoint "); | |
13127 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13128 | { |
001c8c33 PA |
13129 | ui_out_field_string (uiout, "reason", |
13130 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13131 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13132 | } |
001c8c33 PA |
13133 | ui_out_field_int (uiout, "bkptno", b->number); |
13134 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13135 | |
001c8c33 | 13136 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13137 | } |
13138 | ||
2060206e | 13139 | static void |
06edf0c0 PA |
13140 | bkpt_print_mention (struct breakpoint *b) |
13141 | { | |
79a45e25 | 13142 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13143 | return; |
13144 | ||
13145 | switch (b->type) | |
13146 | { | |
13147 | case bp_breakpoint: | |
13148 | case bp_gnu_ifunc_resolver: | |
13149 | if (b->disposition == disp_del) | |
13150 | printf_filtered (_("Temporary breakpoint")); | |
13151 | else | |
13152 | printf_filtered (_("Breakpoint")); | |
13153 | printf_filtered (_(" %d"), b->number); | |
13154 | if (b->type == bp_gnu_ifunc_resolver) | |
13155 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13156 | break; | |
13157 | case bp_hardware_breakpoint: | |
13158 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13159 | break; | |
e7e0cddf SS |
13160 | case bp_dprintf: |
13161 | printf_filtered (_("Dprintf %d"), b->number); | |
13162 | break; | |
06edf0c0 PA |
13163 | } |
13164 | ||
13165 | say_where (b); | |
13166 | } | |
13167 | ||
2060206e | 13168 | static void |
06edf0c0 PA |
13169 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13170 | { | |
13171 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13172 | fprintf_unfiltered (fp, "tbreak"); | |
13173 | else if (tp->type == bp_breakpoint) | |
13174 | fprintf_unfiltered (fp, "break"); | |
13175 | else if (tp->type == bp_hardware_breakpoint | |
13176 | && tp->disposition == disp_del) | |
13177 | fprintf_unfiltered (fp, "thbreak"); | |
13178 | else if (tp->type == bp_hardware_breakpoint) | |
13179 | fprintf_unfiltered (fp, "hbreak"); | |
13180 | else | |
13181 | internal_error (__FILE__, __LINE__, | |
13182 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13183 | ||
2060206e | 13184 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13185 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13186 | } |
13187 | ||
983af33b SDJ |
13188 | static void |
13189 | bkpt_create_sals_from_address (char **arg, | |
13190 | struct linespec_result *canonical, | |
13191 | enum bptype type_wanted, | |
13192 | char *addr_start, char **copy_arg) | |
13193 | { | |
13194 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13195 | addr_start, copy_arg); | |
13196 | } | |
13197 | ||
13198 | static void | |
13199 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13200 | struct linespec_result *canonical, | |
983af33b | 13201 | char *cond_string, |
e7e0cddf | 13202 | char *extra_string, |
983af33b SDJ |
13203 | enum bptype type_wanted, |
13204 | enum bpdisp disposition, | |
13205 | int thread, | |
13206 | int task, int ignore_count, | |
13207 | const struct breakpoint_ops *ops, | |
13208 | int from_tty, int enabled, | |
44f238bb | 13209 | int internal, unsigned flags) |
983af33b | 13210 | { |
023fa29b | 13211 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13212 | cond_string, extra_string, |
13213 | type_wanted, | |
983af33b SDJ |
13214 | disposition, thread, task, |
13215 | ignore_count, ops, from_tty, | |
44f238bb | 13216 | enabled, internal, flags); |
983af33b SDJ |
13217 | } |
13218 | ||
13219 | static void | |
13220 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13221 | struct symtabs_and_lines *sals) | |
13222 | { | |
13223 | decode_linespec_default (b, s, sals); | |
13224 | } | |
13225 | ||
06edf0c0 PA |
13226 | /* Virtual table for internal breakpoints. */ |
13227 | ||
13228 | static void | |
13229 | internal_bkpt_re_set (struct breakpoint *b) | |
13230 | { | |
13231 | switch (b->type) | |
13232 | { | |
13233 | /* Delete overlay event and longjmp master breakpoints; they | |
13234 | will be reset later by breakpoint_re_set. */ | |
13235 | case bp_overlay_event: | |
13236 | case bp_longjmp_master: | |
13237 | case bp_std_terminate_master: | |
13238 | case bp_exception_master: | |
13239 | delete_breakpoint (b); | |
13240 | break; | |
13241 | ||
13242 | /* This breakpoint is special, it's set up when the inferior | |
13243 | starts and we really don't want to touch it. */ | |
13244 | case bp_shlib_event: | |
13245 | ||
13246 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13247 | it is set up, we do not want to touch it. */ | |
13248 | case bp_thread_event: | |
13249 | break; | |
13250 | } | |
13251 | } | |
13252 | ||
13253 | static void | |
13254 | internal_bkpt_check_status (bpstat bs) | |
13255 | { | |
a9b3a50f PA |
13256 | if (bs->breakpoint_at->type == bp_shlib_event) |
13257 | { | |
13258 | /* If requested, stop when the dynamic linker notifies GDB of | |
13259 | events. This allows the user to get control and place | |
13260 | breakpoints in initializer routines for dynamically loaded | |
13261 | objects (among other things). */ | |
13262 | bs->stop = stop_on_solib_events; | |
13263 | bs->print = stop_on_solib_events; | |
13264 | } | |
13265 | else | |
13266 | bs->stop = 0; | |
06edf0c0 PA |
13267 | } |
13268 | ||
13269 | static enum print_stop_action | |
13270 | internal_bkpt_print_it (bpstat bs) | |
13271 | { | |
06edf0c0 | 13272 | struct breakpoint *b; |
06edf0c0 | 13273 | |
06edf0c0 PA |
13274 | b = bs->breakpoint_at; |
13275 | ||
06edf0c0 PA |
13276 | switch (b->type) |
13277 | { | |
348d480f PA |
13278 | case bp_shlib_event: |
13279 | /* Did we stop because the user set the stop_on_solib_events | |
13280 | variable? (If so, we report this as a generic, "Stopped due | |
13281 | to shlib event" message.) */ | |
edcc5120 | 13282 | print_solib_event (0); |
348d480f PA |
13283 | break; |
13284 | ||
13285 | case bp_thread_event: | |
13286 | /* Not sure how we will get here. | |
13287 | GDB should not stop for these breakpoints. */ | |
13288 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13289 | break; |
13290 | ||
13291 | case bp_overlay_event: | |
13292 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13293 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13294 | break; |
13295 | ||
13296 | case bp_longjmp_master: | |
13297 | /* These should never be enabled. */ | |
13298 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13299 | break; |
13300 | ||
13301 | case bp_std_terminate_master: | |
13302 | /* These should never be enabled. */ | |
13303 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13304 | "gdb should not stop!\n")); | |
348d480f PA |
13305 | break; |
13306 | ||
13307 | case bp_exception_master: | |
13308 | /* These should never be enabled. */ | |
13309 | printf_filtered (_("Exception Master Breakpoint: " | |
13310 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13311 | break; |
13312 | } | |
13313 | ||
001c8c33 | 13314 | return PRINT_NOTHING; |
06edf0c0 PA |
13315 | } |
13316 | ||
13317 | static void | |
13318 | internal_bkpt_print_mention (struct breakpoint *b) | |
13319 | { | |
13320 | /* Nothing to mention. These breakpoints are internal. */ | |
13321 | } | |
13322 | ||
06edf0c0 PA |
13323 | /* Virtual table for momentary breakpoints */ |
13324 | ||
13325 | static void | |
13326 | momentary_bkpt_re_set (struct breakpoint *b) | |
13327 | { | |
13328 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13329 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13330 | Otherwise these should have been blown away via the cleanup chain |
13331 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13332 | } | |
13333 | ||
13334 | static void | |
13335 | momentary_bkpt_check_status (bpstat bs) | |
13336 | { | |
13337 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13338 | } | |
13339 | ||
13340 | static enum print_stop_action | |
13341 | momentary_bkpt_print_it (bpstat bs) | |
13342 | { | |
79a45e25 PA |
13343 | struct ui_out *uiout = current_uiout; |
13344 | ||
001c8c33 | 13345 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13346 | { |
001c8c33 | 13347 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13348 | |
001c8c33 PA |
13349 | switch (b->type) |
13350 | { | |
13351 | case bp_finish: | |
13352 | ui_out_field_string | |
13353 | (uiout, "reason", | |
13354 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13355 | break; | |
348d480f | 13356 | |
001c8c33 PA |
13357 | case bp_until: |
13358 | ui_out_field_string | |
13359 | (uiout, "reason", | |
13360 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13361 | break; | |
13362 | } | |
348d480f PA |
13363 | } |
13364 | ||
001c8c33 | 13365 | return PRINT_UNKNOWN; |
348d480f PA |
13366 | } |
13367 | ||
06edf0c0 PA |
13368 | static void |
13369 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13370 | { |
06edf0c0 | 13371 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13372 | } |
13373 | ||
e2e4d78b JK |
13374 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13375 | ||
13376 | It gets cleared already on the removal of the first one of such placed | |
13377 | breakpoints. This is OK as they get all removed altogether. */ | |
13378 | ||
13379 | static void | |
13380 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13381 | { | |
13382 | struct thread_info *tp = find_thread_id (self->thread); | |
13383 | ||
13384 | if (tp) | |
13385 | tp->initiating_frame = null_frame_id; | |
13386 | ||
13387 | momentary_breakpoint_ops.dtor (self); | |
13388 | } | |
13389 | ||
55aa24fb SDJ |
13390 | /* Specific methods for probe breakpoints. */ |
13391 | ||
13392 | static int | |
13393 | bkpt_probe_insert_location (struct bp_location *bl) | |
13394 | { | |
13395 | int v = bkpt_insert_location (bl); | |
13396 | ||
13397 | if (v == 0) | |
13398 | { | |
13399 | /* The insertion was successful, now let's set the probe's semaphore | |
13400 | if needed. */ | |
729662a5 TT |
13401 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
13402 | bl->probe.objfile, | |
13403 | bl->gdbarch); | |
55aa24fb SDJ |
13404 | } |
13405 | ||
13406 | return v; | |
13407 | } | |
13408 | ||
13409 | static int | |
13410 | bkpt_probe_remove_location (struct bp_location *bl) | |
13411 | { | |
13412 | /* Let's clear the semaphore before removing the location. */ | |
729662a5 TT |
13413 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
13414 | bl->probe.objfile, | |
13415 | bl->gdbarch); | |
55aa24fb SDJ |
13416 | |
13417 | return bkpt_remove_location (bl); | |
13418 | } | |
13419 | ||
13420 | static void | |
13421 | bkpt_probe_create_sals_from_address (char **arg, | |
13422 | struct linespec_result *canonical, | |
13423 | enum bptype type_wanted, | |
13424 | char *addr_start, char **copy_arg) | |
13425 | { | |
13426 | struct linespec_sals lsal; | |
13427 | ||
13428 | lsal.sals = parse_probes (arg, canonical); | |
13429 | ||
13430 | *copy_arg = xstrdup (canonical->addr_string); | |
13431 | lsal.canonical = xstrdup (*copy_arg); | |
13432 | ||
13433 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13434 | } | |
13435 | ||
13436 | static void | |
13437 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13438 | struct symtabs_and_lines *sals) | |
13439 | { | |
13440 | *sals = parse_probes (s, NULL); | |
13441 | if (!sals->sals) | |
13442 | error (_("probe not found")); | |
13443 | } | |
13444 | ||
348d480f | 13445 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13446 | |
348d480f PA |
13447 | static void |
13448 | tracepoint_re_set (struct breakpoint *b) | |
13449 | { | |
13450 | breakpoint_re_set_default (b); | |
13451 | } | |
876fa593 | 13452 | |
348d480f PA |
13453 | static int |
13454 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13455 | struct address_space *aspace, CORE_ADDR bp_addr, |
13456 | const struct target_waitstatus *ws) | |
348d480f PA |
13457 | { |
13458 | /* By definition, the inferior does not report stops at | |
13459 | tracepoints. */ | |
13460 | return 0; | |
74960c60 VP |
13461 | } |
13462 | ||
13463 | static void | |
348d480f PA |
13464 | tracepoint_print_one_detail (const struct breakpoint *self, |
13465 | struct ui_out *uiout) | |
74960c60 | 13466 | { |
d9b3f62e PA |
13467 | struct tracepoint *tp = (struct tracepoint *) self; |
13468 | if (tp->static_trace_marker_id) | |
348d480f PA |
13469 | { |
13470 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13471 | |
348d480f PA |
13472 | ui_out_text (uiout, "\tmarker id is "); |
13473 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13474 | tp->static_trace_marker_id); |
348d480f PA |
13475 | ui_out_text (uiout, "\n"); |
13476 | } | |
0d381245 VP |
13477 | } |
13478 | ||
a474d7c2 | 13479 | static void |
348d480f | 13480 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13481 | { |
79a45e25 | 13482 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13483 | return; |
cc59ec59 | 13484 | |
348d480f PA |
13485 | switch (b->type) |
13486 | { | |
13487 | case bp_tracepoint: | |
13488 | printf_filtered (_("Tracepoint")); | |
13489 | printf_filtered (_(" %d"), b->number); | |
13490 | break; | |
13491 | case bp_fast_tracepoint: | |
13492 | printf_filtered (_("Fast tracepoint")); | |
13493 | printf_filtered (_(" %d"), b->number); | |
13494 | break; | |
13495 | case bp_static_tracepoint: | |
13496 | printf_filtered (_("Static tracepoint")); | |
13497 | printf_filtered (_(" %d"), b->number); | |
13498 | break; | |
13499 | default: | |
13500 | internal_error (__FILE__, __LINE__, | |
13501 | _("unhandled tracepoint type %d"), (int) b->type); | |
13502 | } | |
13503 | ||
13504 | say_where (b); | |
a474d7c2 PA |
13505 | } |
13506 | ||
348d480f | 13507 | static void |
d9b3f62e | 13508 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13509 | { |
d9b3f62e PA |
13510 | struct tracepoint *tp = (struct tracepoint *) self; |
13511 | ||
13512 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13513 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13514 | if (self->type == bp_static_tracepoint) |
348d480f | 13515 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13516 | else if (self->type == bp_tracepoint) |
348d480f PA |
13517 | fprintf_unfiltered (fp, "trace"); |
13518 | else | |
13519 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13520 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13521 | |
d9b3f62e PA |
13522 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13523 | print_recreate_thread (self, fp); | |
13524 | ||
13525 | if (tp->pass_count) | |
13526 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13527 | } |
13528 | ||
983af33b SDJ |
13529 | static void |
13530 | tracepoint_create_sals_from_address (char **arg, | |
13531 | struct linespec_result *canonical, | |
13532 | enum bptype type_wanted, | |
13533 | char *addr_start, char **copy_arg) | |
13534 | { | |
13535 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13536 | addr_start, copy_arg); | |
13537 | } | |
13538 | ||
13539 | static void | |
13540 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13541 | struct linespec_result *canonical, | |
983af33b | 13542 | char *cond_string, |
e7e0cddf | 13543 | char *extra_string, |
983af33b SDJ |
13544 | enum bptype type_wanted, |
13545 | enum bpdisp disposition, | |
13546 | int thread, | |
13547 | int task, int ignore_count, | |
13548 | const struct breakpoint_ops *ops, | |
13549 | int from_tty, int enabled, | |
44f238bb | 13550 | int internal, unsigned flags) |
983af33b | 13551 | { |
023fa29b | 13552 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13553 | cond_string, extra_string, |
13554 | type_wanted, | |
983af33b SDJ |
13555 | disposition, thread, task, |
13556 | ignore_count, ops, from_tty, | |
44f238bb | 13557 | enabled, internal, flags); |
983af33b SDJ |
13558 | } |
13559 | ||
13560 | static void | |
13561 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13562 | struct symtabs_and_lines *sals) | |
13563 | { | |
13564 | decode_linespec_default (b, s, sals); | |
13565 | } | |
13566 | ||
2060206e | 13567 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13568 | |
55aa24fb SDJ |
13569 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13570 | static probe. */ | |
13571 | ||
13572 | static void | |
13573 | tracepoint_probe_create_sals_from_address (char **arg, | |
13574 | struct linespec_result *canonical, | |
13575 | enum bptype type_wanted, | |
13576 | char *addr_start, char **copy_arg) | |
13577 | { | |
13578 | /* We use the same method for breakpoint on probes. */ | |
13579 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13580 | addr_start, copy_arg); | |
13581 | } | |
13582 | ||
13583 | static void | |
13584 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13585 | struct symtabs_and_lines *sals) | |
13586 | { | |
13587 | /* We use the same method for breakpoint on probes. */ | |
13588 | bkpt_probe_decode_linespec (b, s, sals); | |
13589 | } | |
13590 | ||
13591 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13592 | ||
5c2b4418 HZ |
13593 | /* Dprintf breakpoint_ops methods. */ |
13594 | ||
13595 | static void | |
13596 | dprintf_re_set (struct breakpoint *b) | |
13597 | { | |
13598 | breakpoint_re_set_default (b); | |
13599 | ||
13600 | /* This breakpoint could have been pending, and be resolved now, and | |
13601 | if so, we should now have the extra string. If we don't, the | |
13602 | dprintf was malformed when created, but we couldn't tell because | |
13603 | we can't extract the extra string until the location is | |
13604 | resolved. */ | |
13605 | if (b->loc != NULL && b->extra_string == NULL) | |
13606 | error (_("Format string required")); | |
13607 | ||
13608 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13609 | 2 - create a dprintf, which resolves fine. | |
13610 | 3 - disconnect from target 1 | |
13611 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13612 | ||
13613 | After steps #3/#4, you'll want the dprintf command list to | |
13614 | be updated, because target 1 and 2 may well return different | |
13615 | answers for target_can_run_breakpoint_commands(). | |
13616 | Given absence of finer grained resetting, we get to do | |
13617 | it all the time. */ | |
13618 | if (b->extra_string != NULL) | |
13619 | update_dprintf_command_list (b); | |
13620 | } | |
13621 | ||
2d9442cc HZ |
13622 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13623 | ||
13624 | static void | |
13625 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13626 | { | |
13627 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13628 | tp->extra_string); | |
13629 | print_recreate_thread (tp, fp); | |
13630 | } | |
13631 | ||
9d6e6e84 HZ |
13632 | /* Implement the "after_condition_true" breakpoint_ops method for |
13633 | dprintf. | |
13634 | ||
13635 | dprintf's are implemented with regular commands in their command | |
13636 | list, but we run the commands here instead of before presenting the | |
13637 | stop to the user, as dprintf's don't actually cause a stop. This | |
13638 | also makes it so that the commands of multiple dprintfs at the same | |
13639 | address are all handled. */ | |
13640 | ||
13641 | static void | |
13642 | dprintf_after_condition_true (struct bpstats *bs) | |
13643 | { | |
13644 | struct cleanup *old_chain; | |
13645 | struct bpstats tmp_bs = { NULL }; | |
13646 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13647 | ||
13648 | /* dprintf's never cause a stop. This wasn't set in the | |
13649 | check_status hook instead because that would make the dprintf's | |
13650 | condition not be evaluated. */ | |
13651 | bs->stop = 0; | |
13652 | ||
13653 | /* Run the command list here. Take ownership of it instead of | |
13654 | copying. We never want these commands to run later in | |
13655 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13656 | be set at same address as this dprintf, or even if running the | |
13657 | commands here throws. */ | |
13658 | tmp_bs.commands = bs->commands; | |
13659 | bs->commands = NULL; | |
13660 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13661 | ||
13662 | bpstat_do_actions_1 (&tmp_bs_p); | |
13663 | ||
13664 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13665 | bpstat_do_actions_1 may return early without processing the whole | |
13666 | list. */ | |
13667 | do_cleanups (old_chain); | |
13668 | } | |
13669 | ||
983af33b SDJ |
13670 | /* The breakpoint_ops structure to be used on static tracepoints with |
13671 | markers (`-m'). */ | |
13672 | ||
13673 | static void | |
13674 | strace_marker_create_sals_from_address (char **arg, | |
13675 | struct linespec_result *canonical, | |
13676 | enum bptype type_wanted, | |
13677 | char *addr_start, char **copy_arg) | |
13678 | { | |
13679 | struct linespec_sals lsal; | |
13680 | ||
13681 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13682 | ||
13683 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13684 | ||
13685 | canonical->addr_string = xstrdup (*copy_arg); | |
13686 | lsal.canonical = xstrdup (*copy_arg); | |
13687 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13688 | } | |
13689 | ||
13690 | static void | |
13691 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13692 | struct linespec_result *canonical, | |
983af33b | 13693 | char *cond_string, |
e7e0cddf | 13694 | char *extra_string, |
983af33b SDJ |
13695 | enum bptype type_wanted, |
13696 | enum bpdisp disposition, | |
13697 | int thread, | |
13698 | int task, int ignore_count, | |
13699 | const struct breakpoint_ops *ops, | |
13700 | int from_tty, int enabled, | |
44f238bb | 13701 | int internal, unsigned flags) |
983af33b SDJ |
13702 | { |
13703 | int i; | |
52d361e1 YQ |
13704 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13705 | canonical->sals, 0); | |
983af33b SDJ |
13706 | |
13707 | /* If the user is creating a static tracepoint by marker id | |
13708 | (strace -m MARKER_ID), then store the sals index, so that | |
13709 | breakpoint_re_set can try to match up which of the newly | |
13710 | found markers corresponds to this one, and, don't try to | |
13711 | expand multiple locations for each sal, given than SALS | |
13712 | already should contain all sals for MARKER_ID. */ | |
13713 | ||
13714 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13715 | { | |
13716 | struct symtabs_and_lines expanded; | |
13717 | struct tracepoint *tp; | |
13718 | struct cleanup *old_chain; | |
13719 | char *addr_string; | |
13720 | ||
13721 | expanded.nelts = 1; | |
13722 | expanded.sals = &lsal->sals.sals[i]; | |
13723 | ||
13724 | addr_string = xstrdup (canonical->addr_string); | |
13725 | old_chain = make_cleanup (xfree, addr_string); | |
13726 | ||
13727 | tp = XCNEW (struct tracepoint); | |
13728 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13729 | addr_string, NULL, | |
e7e0cddf SS |
13730 | cond_string, extra_string, |
13731 | type_wanted, disposition, | |
983af33b | 13732 | thread, task, ignore_count, ops, |
44f238bb | 13733 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13734 | canonical->special_display); |
13735 | /* Given that its possible to have multiple markers with | |
13736 | the same string id, if the user is creating a static | |
13737 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13738 | store the sals index, so that breakpoint_re_set can | |
13739 | try to match up which of the newly found markers | |
13740 | corresponds to this one */ | |
13741 | tp->static_trace_marker_id_idx = i; | |
13742 | ||
13743 | install_breakpoint (internal, &tp->base, 0); | |
13744 | ||
13745 | discard_cleanups (old_chain); | |
13746 | } | |
13747 | } | |
13748 | ||
13749 | static void | |
13750 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13751 | struct symtabs_and_lines *sals) | |
13752 | { | |
13753 | struct tracepoint *tp = (struct tracepoint *) b; | |
13754 | ||
13755 | *sals = decode_static_tracepoint_spec (s); | |
13756 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13757 | { | |
13758 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13759 | sals->nelts = 1; | |
13760 | } | |
13761 | else | |
13762 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13763 | } | |
13764 | ||
13765 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13766 | ||
13767 | static int | |
13768 | strace_marker_p (struct breakpoint *b) | |
13769 | { | |
13770 | return b->ops == &strace_marker_breakpoint_ops; | |
13771 | } | |
13772 | ||
53a5351d | 13773 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13774 | structures. */ |
c906108c SS |
13775 | |
13776 | void | |
fba45db2 | 13777 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13778 | { |
52f0bd74 | 13779 | struct breakpoint *b; |
c906108c | 13780 | |
8a3fe4f8 | 13781 | gdb_assert (bpt != NULL); |
c906108c | 13782 | |
4a64f543 MS |
13783 | /* Has this bp already been deleted? This can happen because |
13784 | multiple lists can hold pointers to bp's. bpstat lists are | |
13785 | especial culprits. | |
13786 | ||
13787 | One example of this happening is a watchpoint's scope bp. When | |
13788 | the scope bp triggers, we notice that the watchpoint is out of | |
13789 | scope, and delete it. We also delete its scope bp. But the | |
13790 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13791 | That bpstat is then checked for auto-deleting bp's, which are | |
13792 | deleted. | |
13793 | ||
13794 | A real solution to this problem might involve reference counts in | |
13795 | bp's, and/or giving them pointers back to their referencing | |
13796 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13797 | storage when no more references were extent. A cheaper bandaid | |
13798 | was chosen. */ | |
c906108c SS |
13799 | if (bpt->type == bp_none) |
13800 | return; | |
13801 | ||
4a64f543 MS |
13802 | /* At least avoid this stale reference until the reference counting |
13803 | of breakpoints gets resolved. */ | |
d0fb5eae | 13804 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13805 | { |
d0fb5eae | 13806 | struct breakpoint *related; |
3a5c3e22 | 13807 | struct watchpoint *w; |
d0fb5eae JK |
13808 | |
13809 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13810 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13811 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13812 | w = (struct watchpoint *) bpt; |
13813 | else | |
13814 | w = NULL; | |
13815 | if (w != NULL) | |
13816 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13817 | |
13818 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13819 | for (related = bpt; related->related_breakpoint != bpt; | |
13820 | related = related->related_breakpoint); | |
13821 | related->related_breakpoint = bpt->related_breakpoint; | |
13822 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13823 | } |
13824 | ||
a9634178 TJB |
13825 | /* watch_command_1 creates a watchpoint but only sets its number if |
13826 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13827 | a problem in that process, we'll be asked to delete the half-created | |
13828 | watchpoint. In that case, don't announce the deletion. */ | |
13829 | if (bpt->number) | |
13830 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13831 | |
c906108c SS |
13832 | if (breakpoint_chain == bpt) |
13833 | breakpoint_chain = bpt->next; | |
13834 | ||
c906108c SS |
13835 | ALL_BREAKPOINTS (b) |
13836 | if (b->next == bpt) | |
c5aa993b JM |
13837 | { |
13838 | b->next = bpt->next; | |
13839 | break; | |
13840 | } | |
c906108c | 13841 | |
f431efe5 PA |
13842 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13843 | been freed. */ | |
13844 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13845 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13846 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13847 | commands are associated with the bpstat; if we remove it here, | |
13848 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13849 | event-top.c won't do anything, and temporary breakpoints with | |
13850 | commands won't work. */ | |
13851 | ||
13852 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13853 | ||
4a64f543 MS |
13854 | /* Now that breakpoint is removed from breakpoint list, update the |
13855 | global location list. This will remove locations that used to | |
13856 | belong to this breakpoint. Do this before freeing the breakpoint | |
13857 | itself, since remove_breakpoint looks at location's owner. It | |
13858 | might be better design to have location completely | |
13859 | self-contained, but it's not the case now. */ | |
b60e7edf | 13860 | update_global_location_list (0); |
74960c60 | 13861 | |
348d480f | 13862 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13863 | /* On the chance that someone will soon try again to delete this |
13864 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13865 | bpt->type = bp_none; |
b8c9b27d | 13866 | xfree (bpt); |
c906108c SS |
13867 | } |
13868 | ||
4d6140d9 AC |
13869 | static void |
13870 | do_delete_breakpoint_cleanup (void *b) | |
13871 | { | |
13872 | delete_breakpoint (b); | |
13873 | } | |
13874 | ||
13875 | struct cleanup * | |
13876 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13877 | { | |
13878 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13879 | } | |
13880 | ||
51be5b68 PA |
13881 | /* Iterator function to call a user-provided callback function once |
13882 | for each of B and its related breakpoints. */ | |
13883 | ||
13884 | static void | |
13885 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13886 | void (*function) (struct breakpoint *, | |
13887 | void *), | |
13888 | void *data) | |
13889 | { | |
13890 | struct breakpoint *related; | |
13891 | ||
13892 | related = b; | |
13893 | do | |
13894 | { | |
13895 | struct breakpoint *next; | |
13896 | ||
13897 | /* FUNCTION may delete RELATED. */ | |
13898 | next = related->related_breakpoint; | |
13899 | ||
13900 | if (next == related) | |
13901 | { | |
13902 | /* RELATED is the last ring entry. */ | |
13903 | function (related, data); | |
13904 | ||
13905 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13906 | B. There's nothing left to do anyway, so just break | |
13907 | out. */ | |
13908 | break; | |
13909 | } | |
13910 | else | |
13911 | function (related, data); | |
13912 | ||
13913 | related = next; | |
13914 | } | |
13915 | while (related != b); | |
13916 | } | |
95a42b64 TT |
13917 | |
13918 | static void | |
13919 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13920 | { | |
13921 | delete_breakpoint (b); | |
13922 | } | |
13923 | ||
51be5b68 PA |
13924 | /* A callback for map_breakpoint_numbers that calls |
13925 | delete_breakpoint. */ | |
13926 | ||
13927 | static void | |
13928 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13929 | { | |
13930 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13931 | } | |
13932 | ||
c906108c | 13933 | void |
fba45db2 | 13934 | delete_command (char *arg, int from_tty) |
c906108c | 13935 | { |
35df4500 | 13936 | struct breakpoint *b, *b_tmp; |
c906108c | 13937 | |
ea9365bb TT |
13938 | dont_repeat (); |
13939 | ||
c906108c SS |
13940 | if (arg == 0) |
13941 | { | |
13942 | int breaks_to_delete = 0; | |
13943 | ||
46c6471b PA |
13944 | /* Delete all breakpoints if no argument. Do not delete |
13945 | internal breakpoints, these have to be deleted with an | |
13946 | explicit breakpoint number argument. */ | |
c5aa993b | 13947 | ALL_BREAKPOINTS (b) |
46c6471b | 13948 | if (user_breakpoint_p (b)) |
973d738b DJ |
13949 | { |
13950 | breaks_to_delete = 1; | |
13951 | break; | |
13952 | } | |
c906108c SS |
13953 | |
13954 | /* Ask user only if there are some breakpoints to delete. */ | |
13955 | if (!from_tty | |
e2e0b3e5 | 13956 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13957 | { |
35df4500 | 13958 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13959 | if (user_breakpoint_p (b)) |
c5aa993b | 13960 | delete_breakpoint (b); |
c906108c SS |
13961 | } |
13962 | } | |
13963 | else | |
51be5b68 | 13964 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13965 | } |
13966 | ||
0d381245 VP |
13967 | static int |
13968 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13969 | { |
0d381245 | 13970 | for (; loc; loc = loc->next) |
8645ff69 UW |
13971 | if (!loc->shlib_disabled |
13972 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13973 | return 0; |
13974 | return 1; | |
fe3f5fa8 VP |
13975 | } |
13976 | ||
776592bf DE |
13977 | /* Subroutine of update_breakpoint_locations to simplify it. |
13978 | Return non-zero if multiple fns in list LOC have the same name. | |
13979 | Null names are ignored. */ | |
13980 | ||
13981 | static int | |
13982 | ambiguous_names_p (struct bp_location *loc) | |
13983 | { | |
13984 | struct bp_location *l; | |
13985 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13986 | (int (*) (const void *, |
13987 | const void *)) streq, | |
776592bf DE |
13988 | NULL, xcalloc, xfree); |
13989 | ||
13990 | for (l = loc; l != NULL; l = l->next) | |
13991 | { | |
13992 | const char **slot; | |
13993 | const char *name = l->function_name; | |
13994 | ||
13995 | /* Allow for some names to be NULL, ignore them. */ | |
13996 | if (name == NULL) | |
13997 | continue; | |
13998 | ||
13999 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14000 | INSERT); | |
4a64f543 MS |
14001 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14002 | returns NULL. */ | |
776592bf DE |
14003 | if (*slot != NULL) |
14004 | { | |
14005 | htab_delete (htab); | |
14006 | return 1; | |
14007 | } | |
14008 | *slot = name; | |
14009 | } | |
14010 | ||
14011 | htab_delete (htab); | |
14012 | return 0; | |
14013 | } | |
14014 | ||
0fb4aa4b PA |
14015 | /* When symbols change, it probably means the sources changed as well, |
14016 | and it might mean the static tracepoint markers are no longer at | |
14017 | the same address or line numbers they used to be at last we | |
14018 | checked. Losing your static tracepoints whenever you rebuild is | |
14019 | undesirable. This function tries to resync/rematch gdb static | |
14020 | tracepoints with the markers on the target, for static tracepoints | |
14021 | that have not been set by marker id. Static tracepoint that have | |
14022 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14023 | The heuristic is: | |
14024 | ||
14025 | 1) For a tracepoint set at a specific address, look for a marker at | |
14026 | the old PC. If one is found there, assume to be the same marker. | |
14027 | If the name / string id of the marker found is different from the | |
14028 | previous known name, assume that means the user renamed the marker | |
14029 | in the sources, and output a warning. | |
14030 | ||
14031 | 2) For a tracepoint set at a given line number, look for a marker | |
14032 | at the new address of the old line number. If one is found there, | |
14033 | assume to be the same marker. If the name / string id of the | |
14034 | marker found is different from the previous known name, assume that | |
14035 | means the user renamed the marker in the sources, and output a | |
14036 | warning. | |
14037 | ||
14038 | 3) If a marker is no longer found at the same address or line, it | |
14039 | may mean the marker no longer exists. But it may also just mean | |
14040 | the code changed a bit. Maybe the user added a few lines of code | |
14041 | that made the marker move up or down (in line number terms). Ask | |
14042 | the target for info about the marker with the string id as we knew | |
14043 | it. If found, update line number and address in the matching | |
14044 | static tracepoint. This will get confused if there's more than one | |
14045 | marker with the same ID (possible in UST, although unadvised | |
14046 | precisely because it confuses tools). */ | |
14047 | ||
14048 | static struct symtab_and_line | |
14049 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14050 | { | |
d9b3f62e | 14051 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14052 | struct static_tracepoint_marker marker; |
14053 | CORE_ADDR pc; | |
0fb4aa4b PA |
14054 | |
14055 | pc = sal.pc; | |
14056 | if (sal.line) | |
14057 | find_line_pc (sal.symtab, sal.line, &pc); | |
14058 | ||
14059 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14060 | { | |
d9b3f62e | 14061 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14062 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14063 | b->number, | |
d9b3f62e | 14064 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14065 | |
d9b3f62e PA |
14066 | xfree (tp->static_trace_marker_id); |
14067 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14068 | release_static_tracepoint_marker (&marker); |
14069 | ||
14070 | return sal; | |
14071 | } | |
14072 | ||
14073 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14074 | by string ID. */ | |
14075 | if (!sal.explicit_pc | |
14076 | && sal.line != 0 | |
14077 | && sal.symtab != NULL | |
d9b3f62e | 14078 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14079 | { |
14080 | VEC(static_tracepoint_marker_p) *markers; | |
14081 | ||
14082 | markers | |
d9b3f62e | 14083 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14084 | |
14085 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14086 | { | |
80e1d417 | 14087 | struct symtab_and_line sal2; |
0fb4aa4b | 14088 | struct symbol *sym; |
80e1d417 | 14089 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14090 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14091 | |
80e1d417 | 14092 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14093 | |
d9b3f62e | 14094 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14095 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14096 | |
14097 | warning (_("marker for static tracepoint %d (%s) not " | |
14098 | "found at previous line number"), | |
d9b3f62e | 14099 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14100 | |
80e1d417 | 14101 | init_sal (&sal2); |
0fb4aa4b | 14102 | |
80e1d417 | 14103 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14104 | |
80e1d417 AS |
14105 | sal2 = find_pc_line (tpmarker->address, 0); |
14106 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14107 | ui_out_text (uiout, "Now in "); |
14108 | if (sym) | |
14109 | { | |
14110 | ui_out_field_string (uiout, "func", | |
14111 | SYMBOL_PRINT_NAME (sym)); | |
14112 | ui_out_text (uiout, " at "); | |
14113 | } | |
05cba821 JK |
14114 | ui_out_field_string (uiout, "file", |
14115 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14116 | ui_out_text (uiout, ":"); |
14117 | ||
14118 | if (ui_out_is_mi_like_p (uiout)) | |
14119 | { | |
0b0865da | 14120 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14121 | |
f35a17b5 | 14122 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14123 | } |
14124 | ||
80e1d417 | 14125 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14126 | ui_out_text (uiout, "\n"); |
14127 | ||
80e1d417 | 14128 | b->loc->line_number = sal2.line; |
2f202fde | 14129 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14130 | |
14131 | xfree (b->addr_string); | |
14132 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14133 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14134 | b->loc->line_number); |
0fb4aa4b PA |
14135 | |
14136 | /* Might be nice to check if function changed, and warn if | |
14137 | so. */ | |
14138 | ||
80e1d417 | 14139 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14140 | } |
14141 | } | |
14142 | return sal; | |
14143 | } | |
14144 | ||
8d3788bd VP |
14145 | /* Returns 1 iff locations A and B are sufficiently same that |
14146 | we don't need to report breakpoint as changed. */ | |
14147 | ||
14148 | static int | |
14149 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14150 | { | |
14151 | while (a && b) | |
14152 | { | |
14153 | if (a->address != b->address) | |
14154 | return 0; | |
14155 | ||
14156 | if (a->shlib_disabled != b->shlib_disabled) | |
14157 | return 0; | |
14158 | ||
14159 | if (a->enabled != b->enabled) | |
14160 | return 0; | |
14161 | ||
14162 | a = a->next; | |
14163 | b = b->next; | |
14164 | } | |
14165 | ||
14166 | if ((a == NULL) != (b == NULL)) | |
14167 | return 0; | |
14168 | ||
14169 | return 1; | |
14170 | } | |
14171 | ||
f1310107 TJB |
14172 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14173 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14174 | a ranged breakpoint. */ | |
14175 | ||
0e30163f | 14176 | void |
0d381245 | 14177 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14178 | struct symtabs_and_lines sals, |
14179 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14180 | { |
14181 | int i; | |
0d381245 VP |
14182 | struct bp_location *existing_locations = b->loc; |
14183 | ||
f8eba3c6 TT |
14184 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14185 | { | |
14186 | /* Ranged breakpoints have only one start location and one end | |
14187 | location. */ | |
14188 | b->enable_state = bp_disabled; | |
14189 | update_global_location_list (1); | |
14190 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14191 | "multiple locations found\n"), | |
14192 | b->number); | |
14193 | return; | |
14194 | } | |
f1310107 | 14195 | |
4a64f543 MS |
14196 | /* If there's no new locations, and all existing locations are |
14197 | pending, don't do anything. This optimizes the common case where | |
14198 | all locations are in the same shared library, that was unloaded. | |
14199 | We'd like to retain the location, so that when the library is | |
14200 | loaded again, we don't loose the enabled/disabled status of the | |
14201 | individual locations. */ | |
0d381245 | 14202 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14203 | return; |
14204 | ||
fe3f5fa8 VP |
14205 | b->loc = NULL; |
14206 | ||
0d381245 | 14207 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14208 | { |
f8eba3c6 TT |
14209 | struct bp_location *new_loc; |
14210 | ||
14211 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14212 | ||
14213 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14214 | |
0d381245 VP |
14215 | /* Reparse conditions, they might contain references to the |
14216 | old symtab. */ | |
14217 | if (b->cond_string != NULL) | |
14218 | { | |
bbc13ae3 | 14219 | const char *s; |
bfd189b1 | 14220 | volatile struct gdb_exception e; |
fe3f5fa8 | 14221 | |
0d381245 VP |
14222 | s = b->cond_string; |
14223 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14224 | { | |
1bb9788d TT |
14225 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14226 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14227 | 0); |
14228 | } | |
14229 | if (e.reason < 0) | |
14230 | { | |
3e43a32a MS |
14231 | warning (_("failed to reevaluate condition " |
14232 | "for breakpoint %d: %s"), | |
0d381245 VP |
14233 | b->number, e.message); |
14234 | new_loc->enabled = 0; | |
14235 | } | |
14236 | } | |
fe3f5fa8 | 14237 | |
f1310107 TJB |
14238 | if (sals_end.nelts) |
14239 | { | |
14240 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14241 | ||
14242 | new_loc->length = end - sals.sals[0].pc + 1; | |
14243 | } | |
0d381245 | 14244 | } |
fe3f5fa8 | 14245 | |
514f746b AR |
14246 | /* Update locations of permanent breakpoints. */ |
14247 | if (b->enable_state == bp_permanent) | |
14248 | make_breakpoint_permanent (b); | |
14249 | ||
4a64f543 MS |
14250 | /* If possible, carry over 'disable' status from existing |
14251 | breakpoints. */ | |
0d381245 VP |
14252 | { |
14253 | struct bp_location *e = existing_locations; | |
776592bf DE |
14254 | /* If there are multiple breakpoints with the same function name, |
14255 | e.g. for inline functions, comparing function names won't work. | |
14256 | Instead compare pc addresses; this is just a heuristic as things | |
14257 | may have moved, but in practice it gives the correct answer | |
14258 | often enough until a better solution is found. */ | |
14259 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14260 | ||
0d381245 VP |
14261 | for (; e; e = e->next) |
14262 | { | |
14263 | if (!e->enabled && e->function_name) | |
14264 | { | |
14265 | struct bp_location *l = b->loc; | |
776592bf DE |
14266 | if (have_ambiguous_names) |
14267 | { | |
14268 | for (; l; l = l->next) | |
f1310107 | 14269 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14270 | { |
14271 | l->enabled = 0; | |
14272 | break; | |
14273 | } | |
14274 | } | |
14275 | else | |
14276 | { | |
14277 | for (; l; l = l->next) | |
14278 | if (l->function_name | |
14279 | && strcmp (e->function_name, l->function_name) == 0) | |
14280 | { | |
14281 | l->enabled = 0; | |
14282 | break; | |
14283 | } | |
14284 | } | |
0d381245 VP |
14285 | } |
14286 | } | |
14287 | } | |
fe3f5fa8 | 14288 | |
8d3788bd VP |
14289 | if (!locations_are_equal (existing_locations, b->loc)) |
14290 | observer_notify_breakpoint_modified (b); | |
14291 | ||
b60e7edf | 14292 | update_global_location_list (1); |
fe3f5fa8 VP |
14293 | } |
14294 | ||
ef23e705 TJB |
14295 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14296 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14297 | ||
14298 | static struct symtabs_and_lines | |
14299 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14300 | { | |
14301 | char *s; | |
02d20e4a | 14302 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14303 | volatile struct gdb_exception e; |
ef23e705 | 14304 | |
983af33b | 14305 | gdb_assert (b->ops != NULL); |
ef23e705 | 14306 | s = addr_string; |
ef23e705 TJB |
14307 | |
14308 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14309 | { | |
983af33b | 14310 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14311 | } |
14312 | if (e.reason < 0) | |
14313 | { | |
14314 | int not_found_and_ok = 0; | |
14315 | /* For pending breakpoints, it's expected that parsing will | |
14316 | fail until the right shared library is loaded. User has | |
14317 | already told to create pending breakpoints and don't need | |
14318 | extra messages. If breakpoint is in bp_shlib_disabled | |
14319 | state, then user already saw the message about that | |
14320 | breakpoint being disabled, and don't want to see more | |
14321 | errors. */ | |
58438ac1 | 14322 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14323 | && (b->condition_not_parsed |
14324 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14325 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14326 | || b->enable_state == bp_disabled)) |
14327 | not_found_and_ok = 1; | |
14328 | ||
14329 | if (!not_found_and_ok) | |
14330 | { | |
14331 | /* We surely don't want to warn about the same breakpoint | |
14332 | 10 times. One solution, implemented here, is disable | |
14333 | the breakpoint on error. Another solution would be to | |
14334 | have separate 'warning emitted' flag. Since this | |
14335 | happens only when a binary has changed, I don't know | |
14336 | which approach is better. */ | |
14337 | b->enable_state = bp_disabled; | |
14338 | throw_exception (e); | |
14339 | } | |
14340 | } | |
14341 | ||
58438ac1 | 14342 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14343 | { |
f8eba3c6 | 14344 | int i; |
ef23e705 | 14345 | |
f8eba3c6 TT |
14346 | for (i = 0; i < sals.nelts; ++i) |
14347 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14348 | if (b->condition_not_parsed && s && s[0]) |
14349 | { | |
ed1d1739 KS |
14350 | char *cond_string, *extra_string; |
14351 | int thread, task; | |
ef23e705 TJB |
14352 | |
14353 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14354 | &cond_string, &thread, &task, |
14355 | &extra_string); | |
ef23e705 TJB |
14356 | if (cond_string) |
14357 | b->cond_string = cond_string; | |
14358 | b->thread = thread; | |
14359 | b->task = task; | |
e7e0cddf SS |
14360 | if (extra_string) |
14361 | b->extra_string = extra_string; | |
ef23e705 TJB |
14362 | b->condition_not_parsed = 0; |
14363 | } | |
14364 | ||
983af33b | 14365 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14366 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14367 | |
58438ac1 TT |
14368 | *found = 1; |
14369 | } | |
14370 | else | |
14371 | *found = 0; | |
ef23e705 TJB |
14372 | |
14373 | return sals; | |
14374 | } | |
14375 | ||
348d480f PA |
14376 | /* The default re_set method, for typical hardware or software |
14377 | breakpoints. Reevaluate the breakpoint and recreate its | |
14378 | locations. */ | |
14379 | ||
14380 | static void | |
28010a5d | 14381 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14382 | { |
14383 | int found; | |
f1310107 | 14384 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14385 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14386 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14387 | |
14388 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14389 | if (found) | |
14390 | { | |
14391 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14392 | expanded = sals; |
ef23e705 TJB |
14393 | } |
14394 | ||
f1310107 TJB |
14395 | if (b->addr_string_range_end) |
14396 | { | |
14397 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14398 | if (found) | |
14399 | { | |
14400 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14401 | expanded_end = sals_end; |
f1310107 TJB |
14402 | } |
14403 | } | |
14404 | ||
14405 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14406 | } |
14407 | ||
983af33b SDJ |
14408 | /* Default method for creating SALs from an address string. It basically |
14409 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14410 | ||
14411 | static void | |
14412 | create_sals_from_address_default (char **arg, | |
14413 | struct linespec_result *canonical, | |
14414 | enum bptype type_wanted, | |
14415 | char *addr_start, char **copy_arg) | |
14416 | { | |
14417 | parse_breakpoint_sals (arg, canonical); | |
14418 | } | |
14419 | ||
14420 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14421 | function for the `create_breakpoints_sal' method of | |
14422 | breakpoint_ops. */ | |
14423 | ||
14424 | static void | |
14425 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14426 | struct linespec_result *canonical, | |
983af33b | 14427 | char *cond_string, |
e7e0cddf | 14428 | char *extra_string, |
983af33b SDJ |
14429 | enum bptype type_wanted, |
14430 | enum bpdisp disposition, | |
14431 | int thread, | |
14432 | int task, int ignore_count, | |
14433 | const struct breakpoint_ops *ops, | |
14434 | int from_tty, int enabled, | |
44f238bb | 14435 | int internal, unsigned flags) |
983af33b SDJ |
14436 | { |
14437 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14438 | extra_string, |
983af33b SDJ |
14439 | type_wanted, disposition, |
14440 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14441 | enabled, internal, flags); |
983af33b SDJ |
14442 | } |
14443 | ||
14444 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14445 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14446 | ||
14447 | static void | |
14448 | decode_linespec_default (struct breakpoint *b, char **s, | |
14449 | struct symtabs_and_lines *sals) | |
14450 | { | |
14451 | struct linespec_result canonical; | |
14452 | ||
14453 | init_linespec_result (&canonical); | |
14454 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14455 | (struct symtab *) NULL, 0, | |
14456 | &canonical, multiple_symbols_all, | |
14457 | b->filter); | |
14458 | ||
14459 | /* We should get 0 or 1 resulting SALs. */ | |
14460 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14461 | ||
14462 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14463 | { | |
14464 | struct linespec_sals *lsal; | |
14465 | ||
14466 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14467 | *sals = lsal->sals; | |
14468 | /* Arrange it so the destructor does not free the | |
14469 | contents. */ | |
14470 | lsal->sals.sals = NULL; | |
14471 | } | |
14472 | ||
14473 | destroy_linespec_result (&canonical); | |
14474 | } | |
14475 | ||
28010a5d PA |
14476 | /* Prepare the global context for a re-set of breakpoint B. */ |
14477 | ||
14478 | static struct cleanup * | |
14479 | prepare_re_set_context (struct breakpoint *b) | |
14480 | { | |
14481 | struct cleanup *cleanups; | |
14482 | ||
14483 | input_radix = b->input_radix; | |
14484 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14485 | if (b->pspace != NULL) |
14486 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14487 | set_language (b->language); |
14488 | ||
14489 | return cleanups; | |
ef23e705 TJB |
14490 | } |
14491 | ||
c906108c SS |
14492 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14493 | The value we return ends up being the return value from catch_errors. | |
14494 | Unused in this case. */ | |
14495 | ||
14496 | static int | |
4efb68b1 | 14497 | breakpoint_re_set_one (void *bint) |
c906108c | 14498 | { |
4a64f543 | 14499 | /* Get past catch_errs. */ |
53a5351d | 14500 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14501 | struct cleanup *cleanups; |
c906108c | 14502 | |
348d480f PA |
14503 | cleanups = prepare_re_set_context (b); |
14504 | b->ops->re_set (b); | |
14505 | do_cleanups (cleanups); | |
c906108c SS |
14506 | return 0; |
14507 | } | |
14508 | ||
69de3c6a | 14509 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14510 | void |
69de3c6a | 14511 | breakpoint_re_set (void) |
c906108c | 14512 | { |
35df4500 | 14513 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14514 | enum language save_language; |
14515 | int save_input_radix; | |
6c95b8df | 14516 | struct cleanup *old_chain; |
c5aa993b | 14517 | |
c906108c SS |
14518 | save_language = current_language->la_language; |
14519 | save_input_radix = input_radix; | |
6c95b8df PA |
14520 | old_chain = save_current_program_space (); |
14521 | ||
35df4500 | 14522 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14523 | { |
4a64f543 | 14524 | /* Format possible error msg. */ |
fe3f5fa8 | 14525 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14526 | b->number); |
14527 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14528 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14529 | do_cleanups (cleanups); |
c5aa993b | 14530 | } |
c906108c SS |
14531 | set_language (save_language); |
14532 | input_radix = save_input_radix; | |
e62c965a | 14533 | |
0756c555 | 14534 | jit_breakpoint_re_set (); |
4efc6507 | 14535 | |
6c95b8df PA |
14536 | do_cleanups (old_chain); |
14537 | ||
af02033e PP |
14538 | create_overlay_event_breakpoint (); |
14539 | create_longjmp_master_breakpoint (); | |
14540 | create_std_terminate_master_breakpoint (); | |
186c406b | 14541 | create_exception_master_breakpoint (); |
c906108c SS |
14542 | } |
14543 | \f | |
c906108c SS |
14544 | /* Reset the thread number of this breakpoint: |
14545 | ||
14546 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14547 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14548 | void |
fba45db2 | 14549 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14550 | { |
14551 | if (b->thread != -1) | |
14552 | { | |
39f77062 KB |
14553 | if (in_thread_list (inferior_ptid)) |
14554 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14555 | |
14556 | /* We're being called after following a fork. The new fork is | |
14557 | selected as current, and unless this was a vfork will have a | |
14558 | different program space from the original thread. Reset that | |
14559 | as well. */ | |
14560 | b->loc->pspace = current_program_space; | |
c906108c SS |
14561 | } |
14562 | } | |
14563 | ||
03ac34d5 MS |
14564 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14565 | If from_tty is nonzero, it prints a message to that effect, | |
14566 | which ends with a period (no newline). */ | |
14567 | ||
c906108c | 14568 | void |
fba45db2 | 14569 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14570 | { |
52f0bd74 | 14571 | struct breakpoint *b; |
c906108c SS |
14572 | |
14573 | if (count < 0) | |
14574 | count = 0; | |
14575 | ||
14576 | ALL_BREAKPOINTS (b) | |
14577 | if (b->number == bptnum) | |
c5aa993b | 14578 | { |
d77f58be SS |
14579 | if (is_tracepoint (b)) |
14580 | { | |
14581 | if (from_tty && count != 0) | |
14582 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14583 | bptnum); | |
14584 | return; | |
14585 | } | |
14586 | ||
c5aa993b | 14587 | b->ignore_count = count; |
221ea385 KS |
14588 | if (from_tty) |
14589 | { | |
14590 | if (count == 0) | |
3e43a32a MS |
14591 | printf_filtered (_("Will stop next time " |
14592 | "breakpoint %d is reached."), | |
221ea385 KS |
14593 | bptnum); |
14594 | else if (count == 1) | |
a3f17187 | 14595 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14596 | bptnum); |
14597 | else | |
3e43a32a MS |
14598 | printf_filtered (_("Will ignore next %d " |
14599 | "crossings of breakpoint %d."), | |
221ea385 KS |
14600 | count, bptnum); |
14601 | } | |
8d3788bd | 14602 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14603 | return; |
14604 | } | |
c906108c | 14605 | |
8a3fe4f8 | 14606 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14607 | } |
14608 | ||
c906108c SS |
14609 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14610 | ||
14611 | static void | |
fba45db2 | 14612 | ignore_command (char *args, int from_tty) |
c906108c SS |
14613 | { |
14614 | char *p = args; | |
52f0bd74 | 14615 | int num; |
c906108c SS |
14616 | |
14617 | if (p == 0) | |
e2e0b3e5 | 14618 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14619 | |
c906108c | 14620 | num = get_number (&p); |
5c44784c | 14621 | if (num == 0) |
8a3fe4f8 | 14622 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14623 | if (*p == 0) |
8a3fe4f8 | 14624 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14625 | |
14626 | set_ignore_count (num, | |
14627 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14628 | from_tty); | |
221ea385 KS |
14629 | if (from_tty) |
14630 | printf_filtered ("\n"); | |
c906108c SS |
14631 | } |
14632 | \f | |
14633 | /* Call FUNCTION on each of the breakpoints | |
14634 | whose numbers are given in ARGS. */ | |
14635 | ||
14636 | static void | |
95a42b64 TT |
14637 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14638 | void *), | |
14639 | void *data) | |
c906108c | 14640 | { |
52f0bd74 AC |
14641 | int num; |
14642 | struct breakpoint *b, *tmp; | |
11cf8741 | 14643 | int match; |
197f0a60 | 14644 | struct get_number_or_range_state state; |
c906108c | 14645 | |
197f0a60 | 14646 | if (args == 0) |
e2e0b3e5 | 14647 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14648 | |
197f0a60 TT |
14649 | init_number_or_range (&state, args); |
14650 | ||
14651 | while (!state.finished) | |
c906108c | 14652 | { |
197f0a60 TT |
14653 | char *p = state.string; |
14654 | ||
11cf8741 | 14655 | match = 0; |
c5aa993b | 14656 | |
197f0a60 | 14657 | num = get_number_or_range (&state); |
5c44784c | 14658 | if (num == 0) |
c5aa993b | 14659 | { |
8a3fe4f8 | 14660 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14661 | } |
14662 | else | |
14663 | { | |
14664 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14665 | if (b->number == num) | |
14666 | { | |
11cf8741 | 14667 | match = 1; |
cdac0397 | 14668 | function (b, data); |
11cf8741 | 14669 | break; |
5c44784c | 14670 | } |
11cf8741 | 14671 | if (match == 0) |
a3f17187 | 14672 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14673 | } |
c906108c SS |
14674 | } |
14675 | } | |
14676 | ||
0d381245 VP |
14677 | static struct bp_location * |
14678 | find_location_by_number (char *number) | |
14679 | { | |
14680 | char *dot = strchr (number, '.'); | |
14681 | char *p1; | |
14682 | int bp_num; | |
14683 | int loc_num; | |
14684 | struct breakpoint *b; | |
14685 | struct bp_location *loc; | |
14686 | ||
14687 | *dot = '\0'; | |
14688 | ||
14689 | p1 = number; | |
197f0a60 | 14690 | bp_num = get_number (&p1); |
0d381245 VP |
14691 | if (bp_num == 0) |
14692 | error (_("Bad breakpoint number '%s'"), number); | |
14693 | ||
14694 | ALL_BREAKPOINTS (b) | |
14695 | if (b->number == bp_num) | |
14696 | { | |
14697 | break; | |
14698 | } | |
14699 | ||
14700 | if (!b || b->number != bp_num) | |
14701 | error (_("Bad breakpoint number '%s'"), number); | |
14702 | ||
14703 | p1 = dot+1; | |
197f0a60 | 14704 | loc_num = get_number (&p1); |
0d381245 VP |
14705 | if (loc_num == 0) |
14706 | error (_("Bad breakpoint location number '%s'"), number); | |
14707 | ||
14708 | --loc_num; | |
14709 | loc = b->loc; | |
14710 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14711 | ; | |
14712 | if (!loc) | |
14713 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14714 | ||
14715 | return loc; | |
14716 | } | |
14717 | ||
14718 | ||
1900040c MS |
14719 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14720 | If from_tty is nonzero, it prints a message to that effect, | |
14721 | which ends with a period (no newline). */ | |
14722 | ||
c906108c | 14723 | void |
fba45db2 | 14724 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14725 | { |
14726 | /* Never disable a watchpoint scope breakpoint; we want to | |
14727 | hit them when we leave scope so we can delete both the | |
14728 | watchpoint and its scope breakpoint at that time. */ | |
14729 | if (bpt->type == bp_watchpoint_scope) | |
14730 | return; | |
14731 | ||
c2c6d25f | 14732 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14733 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14734 | return; |
14735 | ||
b5de0fa7 | 14736 | bpt->enable_state = bp_disabled; |
c906108c | 14737 | |
b775012e LM |
14738 | /* Mark breakpoint locations modified. */ |
14739 | mark_breakpoint_modified (bpt); | |
14740 | ||
d248b706 KY |
14741 | if (target_supports_enable_disable_tracepoint () |
14742 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14743 | { | |
14744 | struct bp_location *location; | |
14745 | ||
14746 | for (location = bpt->loc; location; location = location->next) | |
14747 | target_disable_tracepoint (location); | |
14748 | } | |
14749 | ||
b60e7edf | 14750 | update_global_location_list (0); |
c906108c | 14751 | |
8d3788bd | 14752 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14753 | } |
14754 | ||
51be5b68 PA |
14755 | /* A callback for iterate_over_related_breakpoints. */ |
14756 | ||
14757 | static void | |
14758 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14759 | { | |
14760 | disable_breakpoint (b); | |
14761 | } | |
14762 | ||
95a42b64 TT |
14763 | /* A callback for map_breakpoint_numbers that calls |
14764 | disable_breakpoint. */ | |
14765 | ||
14766 | static void | |
14767 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14768 | { | |
51be5b68 | 14769 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14770 | } |
14771 | ||
c906108c | 14772 | static void |
fba45db2 | 14773 | disable_command (char *args, int from_tty) |
c906108c | 14774 | { |
c906108c | 14775 | if (args == 0) |
46c6471b PA |
14776 | { |
14777 | struct breakpoint *bpt; | |
14778 | ||
14779 | ALL_BREAKPOINTS (bpt) | |
14780 | if (user_breakpoint_p (bpt)) | |
14781 | disable_breakpoint (bpt); | |
14782 | } | |
9eaabc75 | 14783 | else |
0d381245 | 14784 | { |
9eaabc75 MW |
14785 | char *num = extract_arg (&args); |
14786 | ||
14787 | while (num) | |
d248b706 | 14788 | { |
9eaabc75 | 14789 | if (strchr (num, '.')) |
b775012e | 14790 | { |
9eaabc75 MW |
14791 | struct bp_location *loc = find_location_by_number (num); |
14792 | ||
14793 | if (loc) | |
14794 | { | |
14795 | if (loc->enabled) | |
14796 | { | |
14797 | loc->enabled = 0; | |
14798 | mark_breakpoint_location_modified (loc); | |
14799 | } | |
14800 | if (target_supports_enable_disable_tracepoint () | |
14801 | && current_trace_status ()->running && loc->owner | |
14802 | && is_tracepoint (loc->owner)) | |
14803 | target_disable_tracepoint (loc); | |
14804 | } | |
14805 | update_global_location_list (0); | |
b775012e | 14806 | } |
9eaabc75 MW |
14807 | else |
14808 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14809 | num = extract_arg (&args); | |
d248b706 | 14810 | } |
0d381245 | 14811 | } |
c906108c SS |
14812 | } |
14813 | ||
14814 | static void | |
816338b5 SS |
14815 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14816 | int count) | |
c906108c | 14817 | { |
afe38095 | 14818 | int target_resources_ok; |
c906108c SS |
14819 | |
14820 | if (bpt->type == bp_hardware_breakpoint) | |
14821 | { | |
14822 | int i; | |
c5aa993b | 14823 | i = hw_breakpoint_used_count (); |
53a5351d | 14824 | target_resources_ok = |
d92524f1 | 14825 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14826 | i + 1, 0); |
c906108c | 14827 | if (target_resources_ok == 0) |
8a3fe4f8 | 14828 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14829 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14830 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14831 | } |
14832 | ||
cc60f2e3 | 14833 | if (is_watchpoint (bpt)) |
c906108c | 14834 | { |
d07205c2 JK |
14835 | /* Initialize it just to avoid a GCC false warning. */ |
14836 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14837 | volatile struct gdb_exception e; |
dde02812 ES |
14838 | |
14839 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14840 | { |
3a5c3e22 PA |
14841 | struct watchpoint *w = (struct watchpoint *) bpt; |
14842 | ||
1e718ff1 TJB |
14843 | orig_enable_state = bpt->enable_state; |
14844 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14845 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14846 | } |
dde02812 | 14847 | if (e.reason < 0) |
c5aa993b | 14848 | { |
1e718ff1 | 14849 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14850 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14851 | bpt->number); | |
14852 | return; | |
c5aa993b | 14853 | } |
c906108c | 14854 | } |
0101ce28 | 14855 | |
b4c291bb KH |
14856 | if (bpt->enable_state != bp_permanent) |
14857 | bpt->enable_state = bp_enabled; | |
d248b706 | 14858 | |
b775012e LM |
14859 | bpt->enable_state = bp_enabled; |
14860 | ||
14861 | /* Mark breakpoint locations modified. */ | |
14862 | mark_breakpoint_modified (bpt); | |
14863 | ||
d248b706 KY |
14864 | if (target_supports_enable_disable_tracepoint () |
14865 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14866 | { | |
14867 | struct bp_location *location; | |
14868 | ||
14869 | for (location = bpt->loc; location; location = location->next) | |
14870 | target_enable_tracepoint (location); | |
14871 | } | |
14872 | ||
b4c291bb | 14873 | bpt->disposition = disposition; |
816338b5 | 14874 | bpt->enable_count = count; |
b60e7edf | 14875 | update_global_location_list (1); |
9c97429f | 14876 | |
8d3788bd | 14877 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14878 | } |
14879 | ||
fe3f5fa8 | 14880 | |
c906108c | 14881 | void |
fba45db2 | 14882 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14883 | { |
816338b5 | 14884 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14885 | } |
14886 | ||
14887 | static void | |
14888 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14889 | { | |
14890 | enable_breakpoint (bpt); | |
c906108c SS |
14891 | } |
14892 | ||
95a42b64 TT |
14893 | /* A callback for map_breakpoint_numbers that calls |
14894 | enable_breakpoint. */ | |
14895 | ||
14896 | static void | |
14897 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14898 | { | |
51be5b68 | 14899 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14900 | } |
14901 | ||
c906108c SS |
14902 | /* The enable command enables the specified breakpoints (or all defined |
14903 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14904 | in stopping the inferior. */ |
c906108c | 14905 | |
c906108c | 14906 | static void |
fba45db2 | 14907 | enable_command (char *args, int from_tty) |
c906108c | 14908 | { |
c906108c | 14909 | if (args == 0) |
46c6471b PA |
14910 | { |
14911 | struct breakpoint *bpt; | |
14912 | ||
14913 | ALL_BREAKPOINTS (bpt) | |
14914 | if (user_breakpoint_p (bpt)) | |
14915 | enable_breakpoint (bpt); | |
14916 | } | |
9eaabc75 | 14917 | else |
0d381245 | 14918 | { |
9eaabc75 MW |
14919 | char *num = extract_arg (&args); |
14920 | ||
14921 | while (num) | |
d248b706 | 14922 | { |
9eaabc75 | 14923 | if (strchr (num, '.')) |
b775012e | 14924 | { |
9eaabc75 MW |
14925 | struct bp_location *loc = find_location_by_number (num); |
14926 | ||
14927 | if (loc) | |
14928 | { | |
14929 | if (!loc->enabled) | |
14930 | { | |
14931 | loc->enabled = 1; | |
14932 | mark_breakpoint_location_modified (loc); | |
14933 | } | |
14934 | if (target_supports_enable_disable_tracepoint () | |
14935 | && current_trace_status ()->running && loc->owner | |
14936 | && is_tracepoint (loc->owner)) | |
14937 | target_enable_tracepoint (loc); | |
14938 | } | |
14939 | update_global_location_list (1); | |
b775012e | 14940 | } |
9eaabc75 MW |
14941 | else |
14942 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14943 | num = extract_arg (&args); | |
d248b706 | 14944 | } |
0d381245 | 14945 | } |
c906108c SS |
14946 | } |
14947 | ||
816338b5 SS |
14948 | /* This struct packages up disposition data for application to multiple |
14949 | breakpoints. */ | |
14950 | ||
14951 | struct disp_data | |
14952 | { | |
14953 | enum bpdisp disp; | |
14954 | int count; | |
14955 | }; | |
14956 | ||
c906108c | 14957 | static void |
51be5b68 PA |
14958 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14959 | { | |
816338b5 | 14960 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14961 | |
816338b5 | 14962 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14963 | } |
14964 | ||
14965 | static void | |
14966 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14967 | { |
816338b5 | 14968 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14969 | |
14970 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14971 | } |
14972 | ||
c906108c | 14973 | static void |
fba45db2 | 14974 | enable_once_command (char *args, int from_tty) |
c906108c | 14975 | { |
51be5b68 | 14976 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14977 | } |
14978 | ||
816338b5 SS |
14979 | static void |
14980 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14981 | { | |
14982 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14983 | ||
14984 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14985 | } | |
14986 | ||
14987 | static void | |
14988 | enable_count_command (char *args, int from_tty) | |
14989 | { | |
14990 | int count = get_number (&args); | |
14991 | ||
14992 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14993 | } | |
14994 | ||
c906108c | 14995 | static void |
51be5b68 | 14996 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14997 | { |
816338b5 | 14998 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14999 | |
15000 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15001 | } |
15002 | ||
c906108c | 15003 | static void |
fba45db2 | 15004 | enable_delete_command (char *args, int from_tty) |
c906108c | 15005 | { |
51be5b68 | 15006 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15007 | } |
15008 | \f | |
fa8d40ab JJ |
15009 | static void |
15010 | set_breakpoint_cmd (char *args, int from_tty) | |
15011 | { | |
15012 | } | |
15013 | ||
15014 | static void | |
15015 | show_breakpoint_cmd (char *args, int from_tty) | |
15016 | { | |
15017 | } | |
15018 | ||
1f3b5d1b PP |
15019 | /* Invalidate last known value of any hardware watchpoint if |
15020 | the memory which that value represents has been written to by | |
15021 | GDB itself. */ | |
15022 | ||
15023 | static void | |
8de0566d YQ |
15024 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15025 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15026 | const bfd_byte *data) |
15027 | { | |
15028 | struct breakpoint *bp; | |
15029 | ||
15030 | ALL_BREAKPOINTS (bp) | |
15031 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15032 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15033 | { |
3a5c3e22 | 15034 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15035 | |
3a5c3e22 PA |
15036 | if (wp->val_valid && wp->val) |
15037 | { | |
15038 | struct bp_location *loc; | |
15039 | ||
15040 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15041 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15042 | && loc->address + loc->length > addr | |
15043 | && addr + len > loc->address) | |
15044 | { | |
15045 | value_free (wp->val); | |
15046 | wp->val = NULL; | |
15047 | wp->val_valid = 0; | |
15048 | } | |
15049 | } | |
1f3b5d1b PP |
15050 | } |
15051 | } | |
15052 | ||
8181d85f DJ |
15053 | /* Create and insert a raw software breakpoint at PC. Return an |
15054 | identifier, which should be used to remove the breakpoint later. | |
15055 | In general, places which call this should be using something on the | |
15056 | breakpoint chain instead; this function should be eliminated | |
15057 | someday. */ | |
15058 | ||
15059 | void * | |
6c95b8df PA |
15060 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
15061 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
15062 | { |
15063 | struct bp_target_info *bp_tgt; | |
15064 | ||
41bf6aca | 15065 | bp_tgt = XCNEW (struct bp_target_info); |
8181d85f | 15066 | |
6c95b8df | 15067 | bp_tgt->placed_address_space = aspace; |
8181d85f | 15068 | bp_tgt->placed_address = pc; |
6c95b8df | 15069 | |
a6d9a66e | 15070 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
15071 | { |
15072 | /* Could not insert the breakpoint. */ | |
15073 | xfree (bp_tgt); | |
15074 | return NULL; | |
15075 | } | |
15076 | ||
15077 | return bp_tgt; | |
15078 | } | |
15079 | ||
4a64f543 MS |
15080 | /* Remove a breakpoint BP inserted by |
15081 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
15082 | |
15083 | int | |
a6d9a66e | 15084 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
15085 | { |
15086 | struct bp_target_info *bp_tgt = bp; | |
15087 | int ret; | |
15088 | ||
a6d9a66e | 15089 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
15090 | xfree (bp_tgt); |
15091 | ||
15092 | return ret; | |
15093 | } | |
15094 | ||
8181d85f DJ |
15095 | /* Create and insert a breakpoint for software single step. */ |
15096 | ||
15097 | void | |
6c95b8df | 15098 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15099 | struct address_space *aspace, |
15100 | CORE_ADDR next_pc) | |
8181d85f DJ |
15101 | { |
15102 | void **bpt_p; | |
15103 | ||
15104 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15105 | { |
15106 | bpt_p = &single_step_breakpoints[0]; | |
15107 | single_step_gdbarch[0] = gdbarch; | |
15108 | } | |
8181d85f DJ |
15109 | else |
15110 | { | |
15111 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15112 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15113 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15114 | } |
15115 | ||
4a64f543 MS |
15116 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15117 | be to only create the breakpoints once, and actually put them on | |
15118 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15119 | We could adjust the addresses each time they were needed. Doing | |
15120 | this requires corresponding changes elsewhere where single step | |
15121 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15122 | |
6c95b8df | 15123 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15124 | if (*bpt_p == NULL) |
5af949e3 UW |
15125 | error (_("Could not insert single-step breakpoint at %s"), |
15126 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15127 | } |
15128 | ||
f02253f1 HZ |
15129 | /* Check if the breakpoints used for software single stepping |
15130 | were inserted or not. */ | |
15131 | ||
15132 | int | |
15133 | single_step_breakpoints_inserted (void) | |
15134 | { | |
15135 | return (single_step_breakpoints[0] != NULL | |
15136 | || single_step_breakpoints[1] != NULL); | |
15137 | } | |
15138 | ||
8181d85f DJ |
15139 | /* Remove and delete any breakpoints used for software single step. */ |
15140 | ||
15141 | void | |
15142 | remove_single_step_breakpoints (void) | |
15143 | { | |
15144 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15145 | ||
15146 | /* See insert_single_step_breakpoint for more about this deprecated | |
15147 | call. */ | |
a6d9a66e UW |
15148 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15149 | single_step_breakpoints[0]); | |
15150 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15151 | single_step_breakpoints[0] = NULL; |
15152 | ||
15153 | if (single_step_breakpoints[1] != NULL) | |
15154 | { | |
a6d9a66e UW |
15155 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15156 | single_step_breakpoints[1]); | |
15157 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15158 | single_step_breakpoints[1] = NULL; |
15159 | } | |
15160 | } | |
15161 | ||
d03285ec UW |
15162 | /* Delete software single step breakpoints without removing them from |
15163 | the inferior. This is intended to be used if the inferior's address | |
15164 | space where they were inserted is already gone, e.g. after exit or | |
15165 | exec. */ | |
15166 | ||
15167 | void | |
15168 | cancel_single_step_breakpoints (void) | |
15169 | { | |
15170 | int i; | |
15171 | ||
15172 | for (i = 0; i < 2; i++) | |
15173 | if (single_step_breakpoints[i]) | |
15174 | { | |
15175 | xfree (single_step_breakpoints[i]); | |
15176 | single_step_breakpoints[i] = NULL; | |
15177 | single_step_gdbarch[i] = NULL; | |
15178 | } | |
15179 | } | |
15180 | ||
15181 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15182 | removing them. */ | |
15183 | ||
15184 | static void | |
15185 | detach_single_step_breakpoints (void) | |
15186 | { | |
15187 | int i; | |
15188 | ||
15189 | for (i = 0; i < 2; i++) | |
15190 | if (single_step_breakpoints[i]) | |
15191 | target_remove_breakpoint (single_step_gdbarch[i], | |
15192 | single_step_breakpoints[i]); | |
15193 | } | |
15194 | ||
4a64f543 MS |
15195 | /* Check whether a software single-step breakpoint is inserted at |
15196 | PC. */ | |
1aafd4da | 15197 | |
2adfaa28 | 15198 | int |
cc59ec59 MS |
15199 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15200 | CORE_ADDR pc) | |
1aafd4da UW |
15201 | { |
15202 | int i; | |
15203 | ||
15204 | for (i = 0; i < 2; i++) | |
15205 | { | |
15206 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15207 | if (bp_tgt |
15208 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15209 | bp_tgt->placed_address, | |
15210 | aspace, pc)) | |
1aafd4da UW |
15211 | return 1; |
15212 | } | |
15213 | ||
15214 | return 0; | |
15215 | } | |
15216 | ||
a96d9b2e SDJ |
15217 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15218 | non-zero otherwise. */ | |
15219 | static int | |
15220 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15221 | { | |
15222 | if (syscall_catchpoint_p (bp) | |
15223 | && bp->enable_state != bp_disabled | |
15224 | && bp->enable_state != bp_call_disabled) | |
15225 | return 1; | |
15226 | else | |
15227 | return 0; | |
15228 | } | |
15229 | ||
15230 | int | |
15231 | catch_syscall_enabled (void) | |
15232 | { | |
fa3064dd YQ |
15233 | struct catch_syscall_inferior_data *inf_data |
15234 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15235 | |
fa3064dd | 15236 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15237 | } |
15238 | ||
15239 | int | |
15240 | catching_syscall_number (int syscall_number) | |
15241 | { | |
15242 | struct breakpoint *bp; | |
15243 | ||
15244 | ALL_BREAKPOINTS (bp) | |
15245 | if (is_syscall_catchpoint_enabled (bp)) | |
15246 | { | |
be5c67c1 PA |
15247 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15248 | ||
15249 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15250 | { |
15251 | int i, iter; | |
15252 | for (i = 0; | |
be5c67c1 | 15253 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15254 | i++) |
15255 | if (syscall_number == iter) | |
15256 | return 1; | |
15257 | } | |
15258 | else | |
15259 | return 1; | |
15260 | } | |
15261 | ||
15262 | return 0; | |
15263 | } | |
15264 | ||
15265 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15266 | static VEC (char_ptr) * |
a96d9b2e | 15267 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15268 | const char *text, const char *word) |
a96d9b2e SDJ |
15269 | { |
15270 | const char **list = get_syscall_names (); | |
49c4e619 | 15271 | VEC (char_ptr) *retlist |
b45627a0 | 15272 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15273 | |
c38eea1a MS |
15274 | xfree (list); |
15275 | return retlist; | |
a96d9b2e SDJ |
15276 | } |
15277 | ||
1042e4c0 SS |
15278 | /* Tracepoint-specific operations. */ |
15279 | ||
15280 | /* Set tracepoint count to NUM. */ | |
15281 | static void | |
15282 | set_tracepoint_count (int num) | |
15283 | { | |
15284 | tracepoint_count = num; | |
4fa62494 | 15285 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15286 | } |
15287 | ||
70221824 | 15288 | static void |
1042e4c0 SS |
15289 | trace_command (char *arg, int from_tty) |
15290 | { | |
55aa24fb SDJ |
15291 | struct breakpoint_ops *ops; |
15292 | const char *arg_cp = arg; | |
15293 | ||
15294 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15295 | ops = &tracepoint_probe_breakpoint_ops; | |
15296 | else | |
15297 | ops = &tracepoint_breakpoint_ops; | |
15298 | ||
558a9d82 YQ |
15299 | create_breakpoint (get_current_arch (), |
15300 | arg, | |
15301 | NULL, 0, NULL, 1 /* parse arg */, | |
15302 | 0 /* tempflag */, | |
15303 | bp_tracepoint /* type_wanted */, | |
15304 | 0 /* Ignore count */, | |
15305 | pending_break_support, | |
15306 | ops, | |
15307 | from_tty, | |
15308 | 1 /* enabled */, | |
15309 | 0 /* internal */, 0); | |
1042e4c0 SS |
15310 | } |
15311 | ||
70221824 | 15312 | static void |
7a697b8d SS |
15313 | ftrace_command (char *arg, int from_tty) |
15314 | { | |
558a9d82 YQ |
15315 | create_breakpoint (get_current_arch (), |
15316 | arg, | |
15317 | NULL, 0, NULL, 1 /* parse arg */, | |
15318 | 0 /* tempflag */, | |
15319 | bp_fast_tracepoint /* type_wanted */, | |
15320 | 0 /* Ignore count */, | |
15321 | pending_break_support, | |
15322 | &tracepoint_breakpoint_ops, | |
15323 | from_tty, | |
15324 | 1 /* enabled */, | |
15325 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15326 | } |
15327 | ||
15328 | /* strace command implementation. Creates a static tracepoint. */ | |
15329 | ||
70221824 | 15330 | static void |
0fb4aa4b PA |
15331 | strace_command (char *arg, int from_tty) |
15332 | { | |
983af33b SDJ |
15333 | struct breakpoint_ops *ops; |
15334 | ||
15335 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15336 | or with a normal static tracepoint. */ | |
15337 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15338 | ops = &strace_marker_breakpoint_ops; | |
15339 | else | |
15340 | ops = &tracepoint_breakpoint_ops; | |
15341 | ||
558a9d82 YQ |
15342 | create_breakpoint (get_current_arch (), |
15343 | arg, | |
15344 | NULL, 0, NULL, 1 /* parse arg */, | |
15345 | 0 /* tempflag */, | |
15346 | bp_static_tracepoint /* type_wanted */, | |
15347 | 0 /* Ignore count */, | |
15348 | pending_break_support, | |
15349 | ops, | |
15350 | from_tty, | |
15351 | 1 /* enabled */, | |
15352 | 0 /* internal */, 0); | |
7a697b8d SS |
15353 | } |
15354 | ||
409873ef SS |
15355 | /* Set up a fake reader function that gets command lines from a linked |
15356 | list that was acquired during tracepoint uploading. */ | |
15357 | ||
15358 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15359 | static int next_cmd; |
409873ef SS |
15360 | |
15361 | static char * | |
15362 | read_uploaded_action (void) | |
15363 | { | |
15364 | char *rslt; | |
15365 | ||
3149d8c1 | 15366 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15367 | |
3149d8c1 | 15368 | next_cmd++; |
409873ef SS |
15369 | |
15370 | return rslt; | |
15371 | } | |
15372 | ||
00bf0b85 SS |
15373 | /* Given information about a tracepoint as recorded on a target (which |
15374 | can be either a live system or a trace file), attempt to create an | |
15375 | equivalent GDB tracepoint. This is not a reliable process, since | |
15376 | the target does not necessarily have all the information used when | |
15377 | the tracepoint was originally defined. */ | |
15378 | ||
d9b3f62e | 15379 | struct tracepoint * |
00bf0b85 | 15380 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15381 | { |
409873ef | 15382 | char *addr_str, small_buf[100]; |
d9b3f62e | 15383 | struct tracepoint *tp; |
fd9b8c24 | 15384 | |
409873ef SS |
15385 | if (utp->at_string) |
15386 | addr_str = utp->at_string; | |
15387 | else | |
15388 | { | |
15389 | /* In the absence of a source location, fall back to raw | |
15390 | address. Since there is no way to confirm that the address | |
15391 | means the same thing as when the trace was started, warn the | |
15392 | user. */ | |
3e43a32a MS |
15393 | warning (_("Uploaded tracepoint %d has no " |
15394 | "source location, using raw address"), | |
409873ef | 15395 | utp->number); |
8c042590 | 15396 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15397 | addr_str = small_buf; |
15398 | } | |
15399 | ||
15400 | /* There's not much we can do with a sequence of bytecodes. */ | |
15401 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15402 | warning (_("Uploaded tracepoint %d condition " |
15403 | "has no source form, ignoring it"), | |
409873ef | 15404 | utp->number); |
d5551862 | 15405 | |
8cdf0e15 | 15406 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15407 | addr_str, |
e7e0cddf SS |
15408 | utp->cond_string, -1, NULL, |
15409 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15410 | 0 /* tempflag */, |
0fb4aa4b | 15411 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15412 | 0 /* Ignore count */, |
15413 | pending_break_support, | |
348d480f | 15414 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15415 | 0 /* from_tty */, |
84f4c1fe | 15416 | utp->enabled /* enabled */, |
44f238bb PA |
15417 | 0 /* internal */, |
15418 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15419 | return NULL; |
15420 | ||
409873ef | 15421 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15422 | tp = get_tracepoint (tracepoint_count); |
15423 | gdb_assert (tp != NULL); | |
d5551862 | 15424 | |
00bf0b85 SS |
15425 | if (utp->pass > 0) |
15426 | { | |
8c042590 PM |
15427 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15428 | tp->base.number); | |
00bf0b85 | 15429 | |
409873ef | 15430 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15431 | } |
15432 | ||
409873ef SS |
15433 | /* If we have uploaded versions of the original commands, set up a |
15434 | special-purpose "reader" function and call the usual command line | |
15435 | reader, then pass the result to the breakpoint command-setting | |
15436 | function. */ | |
3149d8c1 | 15437 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15438 | { |
409873ef | 15439 | struct command_line *cmd_list; |
00bf0b85 | 15440 | |
409873ef | 15441 | this_utp = utp; |
3149d8c1 | 15442 | next_cmd = 0; |
d5551862 | 15443 | |
409873ef SS |
15444 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15445 | ||
d9b3f62e | 15446 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15447 | } |
3149d8c1 SS |
15448 | else if (!VEC_empty (char_ptr, utp->actions) |
15449 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15450 | warning (_("Uploaded tracepoint %d actions " |
15451 | "have no source form, ignoring them"), | |
409873ef | 15452 | utp->number); |
00bf0b85 | 15453 | |
f196051f SS |
15454 | /* Copy any status information that might be available. */ |
15455 | tp->base.hit_count = utp->hit_count; | |
15456 | tp->traceframe_usage = utp->traceframe_usage; | |
15457 | ||
00bf0b85 | 15458 | return tp; |
d9b3f62e | 15459 | } |
00bf0b85 | 15460 | |
1042e4c0 SS |
15461 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15462 | omitted. */ | |
15463 | ||
15464 | static void | |
e5a67952 | 15465 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15466 | { |
79a45e25 | 15467 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15468 | int num_printed; |
1042e4c0 | 15469 | |
e5a67952 | 15470 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15471 | |
15472 | if (num_printed == 0) | |
1042e4c0 | 15473 | { |
e5a67952 | 15474 | if (args == NULL || *args == '\0') |
d77f58be SS |
15475 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15476 | else | |
e5a67952 | 15477 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15478 | } |
ad443146 SS |
15479 | |
15480 | default_collect_info (); | |
1042e4c0 SS |
15481 | } |
15482 | ||
4a64f543 | 15483 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15484 | Not supported by all targets. */ |
15485 | static void | |
15486 | enable_trace_command (char *args, int from_tty) | |
15487 | { | |
15488 | enable_command (args, from_tty); | |
15489 | } | |
15490 | ||
4a64f543 | 15491 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15492 | Not supported by all targets. */ |
15493 | static void | |
15494 | disable_trace_command (char *args, int from_tty) | |
15495 | { | |
15496 | disable_command (args, from_tty); | |
15497 | } | |
15498 | ||
4a64f543 | 15499 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15500 | static void |
15501 | delete_trace_command (char *arg, int from_tty) | |
15502 | { | |
35df4500 | 15503 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15504 | |
15505 | dont_repeat (); | |
15506 | ||
15507 | if (arg == 0) | |
15508 | { | |
15509 | int breaks_to_delete = 0; | |
15510 | ||
15511 | /* Delete all breakpoints if no argument. | |
15512 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15513 | have to be deleted with an explicit breakpoint number |
15514 | argument. */ | |
1042e4c0 | 15515 | ALL_TRACEPOINTS (b) |
46c6471b | 15516 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15517 | { |
15518 | breaks_to_delete = 1; | |
15519 | break; | |
15520 | } | |
1042e4c0 SS |
15521 | |
15522 | /* Ask user only if there are some breakpoints to delete. */ | |
15523 | if (!from_tty | |
15524 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15525 | { | |
35df4500 | 15526 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15527 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15528 | delete_breakpoint (b); |
1042e4c0 SS |
15529 | } |
15530 | } | |
15531 | else | |
51be5b68 | 15532 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15533 | } |
15534 | ||
197f0a60 TT |
15535 | /* Helper function for trace_pass_command. */ |
15536 | ||
15537 | static void | |
d9b3f62e | 15538 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15539 | { |
d9b3f62e | 15540 | tp->pass_count = count; |
6f6484cd | 15541 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15542 | if (from_tty) |
15543 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15544 | tp->base.number, count); |
197f0a60 TT |
15545 | } |
15546 | ||
1042e4c0 SS |
15547 | /* Set passcount for tracepoint. |
15548 | ||
15549 | First command argument is passcount, second is tracepoint number. | |
15550 | If tracepoint number omitted, apply to most recently defined. | |
15551 | Also accepts special argument "all". */ | |
15552 | ||
15553 | static void | |
15554 | trace_pass_command (char *args, int from_tty) | |
15555 | { | |
d9b3f62e | 15556 | struct tracepoint *t1; |
1042e4c0 | 15557 | unsigned int count; |
1042e4c0 SS |
15558 | |
15559 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15560 | error (_("passcount command requires an " |
15561 | "argument (count + optional TP num)")); | |
1042e4c0 | 15562 | |
4a64f543 | 15563 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15564 | |
529480d0 | 15565 | args = skip_spaces (args); |
1042e4c0 SS |
15566 | if (*args && strncasecmp (args, "all", 3) == 0) |
15567 | { | |
d9b3f62e PA |
15568 | struct breakpoint *b; |
15569 | ||
1042e4c0 | 15570 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15571 | if (*args) |
15572 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15573 | |
d9b3f62e | 15574 | ALL_TRACEPOINTS (b) |
197f0a60 | 15575 | { |
d9b3f62e | 15576 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15577 | trace_pass_set_count (t1, count, from_tty); |
15578 | } | |
15579 | } | |
15580 | else if (*args == '\0') | |
1042e4c0 | 15581 | { |
5fa1d40e | 15582 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15583 | if (t1) |
197f0a60 TT |
15584 | trace_pass_set_count (t1, count, from_tty); |
15585 | } | |
15586 | else | |
15587 | { | |
15588 | struct get_number_or_range_state state; | |
15589 | ||
15590 | init_number_or_range (&state, args); | |
15591 | while (!state.finished) | |
1042e4c0 | 15592 | { |
5fa1d40e | 15593 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15594 | if (t1) |
15595 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15596 | } |
15597 | } | |
1042e4c0 SS |
15598 | } |
15599 | ||
d9b3f62e | 15600 | struct tracepoint * |
1042e4c0 SS |
15601 | get_tracepoint (int num) |
15602 | { | |
15603 | struct breakpoint *t; | |
15604 | ||
15605 | ALL_TRACEPOINTS (t) | |
15606 | if (t->number == num) | |
d9b3f62e | 15607 | return (struct tracepoint *) t; |
1042e4c0 SS |
15608 | |
15609 | return NULL; | |
15610 | } | |
15611 | ||
d5551862 SS |
15612 | /* Find the tracepoint with the given target-side number (which may be |
15613 | different from the tracepoint number after disconnecting and | |
15614 | reconnecting). */ | |
15615 | ||
d9b3f62e | 15616 | struct tracepoint * |
d5551862 SS |
15617 | get_tracepoint_by_number_on_target (int num) |
15618 | { | |
d9b3f62e | 15619 | struct breakpoint *b; |
d5551862 | 15620 | |
d9b3f62e PA |
15621 | ALL_TRACEPOINTS (b) |
15622 | { | |
15623 | struct tracepoint *t = (struct tracepoint *) b; | |
15624 | ||
15625 | if (t->number_on_target == num) | |
15626 | return t; | |
15627 | } | |
d5551862 SS |
15628 | |
15629 | return NULL; | |
15630 | } | |
15631 | ||
1042e4c0 | 15632 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15633 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15634 | If the argument is missing, the most recent tracepoint |
15635 | (tracepoint_count) is returned. */ | |
15636 | ||
d9b3f62e | 15637 | struct tracepoint * |
197f0a60 | 15638 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15639 | struct get_number_or_range_state *state) |
1042e4c0 | 15640 | { |
1042e4c0 SS |
15641 | struct breakpoint *t; |
15642 | int tpnum; | |
15643 | char *instring = arg == NULL ? NULL : *arg; | |
15644 | ||
197f0a60 TT |
15645 | if (state) |
15646 | { | |
15647 | gdb_assert (!state->finished); | |
15648 | tpnum = get_number_or_range (state); | |
15649 | } | |
15650 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15651 | tpnum = tracepoint_count; |
1042e4c0 | 15652 | else |
197f0a60 | 15653 | tpnum = get_number (arg); |
1042e4c0 SS |
15654 | |
15655 | if (tpnum <= 0) | |
15656 | { | |
15657 | if (instring && *instring) | |
15658 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15659 | instring); | |
15660 | else | |
5fa1d40e | 15661 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15662 | return NULL; |
15663 | } | |
15664 | ||
15665 | ALL_TRACEPOINTS (t) | |
15666 | if (t->number == tpnum) | |
15667 | { | |
d9b3f62e | 15668 | return (struct tracepoint *) t; |
1042e4c0 SS |
15669 | } |
15670 | ||
1042e4c0 SS |
15671 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15672 | return NULL; | |
15673 | } | |
15674 | ||
d9b3f62e PA |
15675 | void |
15676 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15677 | { | |
15678 | if (b->thread != -1) | |
15679 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15680 | ||
15681 | if (b->task != 0) | |
15682 | fprintf_unfiltered (fp, " task %d", b->task); | |
15683 | ||
15684 | fprintf_unfiltered (fp, "\n"); | |
15685 | } | |
15686 | ||
6149aea9 PA |
15687 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15688 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15689 | on each breakpoint and only include the ones for which it returns | |
15690 | non-zero. */ | |
15691 | ||
1042e4c0 | 15692 | static void |
6149aea9 PA |
15693 | save_breakpoints (char *filename, int from_tty, |
15694 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15695 | { |
15696 | struct breakpoint *tp; | |
6149aea9 | 15697 | int any = 0; |
1042e4c0 | 15698 | struct cleanup *cleanup; |
a7bdde9e | 15699 | struct ui_file *fp; |
6149aea9 | 15700 | int extra_trace_bits = 0; |
1042e4c0 | 15701 | |
6149aea9 PA |
15702 | if (filename == 0 || *filename == 0) |
15703 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15704 | |
15705 | /* See if we have anything to save. */ | |
6149aea9 | 15706 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15707 | { |
6149aea9 | 15708 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15709 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15710 | continue; |
15711 | ||
15712 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15713 | if (filter && !filter (tp)) | |
15714 | continue; | |
15715 | ||
15716 | any = 1; | |
15717 | ||
15718 | if (is_tracepoint (tp)) | |
15719 | { | |
15720 | extra_trace_bits = 1; | |
15721 | ||
15722 | /* We can stop searching. */ | |
15723 | break; | |
15724 | } | |
1042e4c0 | 15725 | } |
6149aea9 PA |
15726 | |
15727 | if (!any) | |
1042e4c0 | 15728 | { |
6149aea9 | 15729 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15730 | return; |
15731 | } | |
15732 | ||
c718be47 PA |
15733 | filename = tilde_expand (filename); |
15734 | cleanup = make_cleanup (xfree, filename); | |
15735 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15736 | if (!fp) |
6149aea9 PA |
15737 | error (_("Unable to open file '%s' for saving (%s)"), |
15738 | filename, safe_strerror (errno)); | |
a7bdde9e | 15739 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15740 | |
6149aea9 PA |
15741 | if (extra_trace_bits) |
15742 | save_trace_state_variables (fp); | |
8bf6485c | 15743 | |
6149aea9 | 15744 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15745 | { |
6149aea9 | 15746 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15747 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15748 | continue; |
8bf6485c | 15749 | |
6149aea9 PA |
15750 | /* If we have a filter, only save the breakpoints it accepts. */ |
15751 | if (filter && !filter (tp)) | |
15752 | continue; | |
15753 | ||
348d480f | 15754 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15755 | |
6149aea9 PA |
15756 | /* Note, we can't rely on tp->number for anything, as we can't |
15757 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15758 | instead. */ | |
15759 | ||
15760 | if (tp->cond_string) | |
15761 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15762 | ||
15763 | if (tp->ignore_count) | |
15764 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15765 | ||
2d9442cc | 15766 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15767 | { |
a7bdde9e VP |
15768 | volatile struct gdb_exception ex; |
15769 | ||
6149aea9 | 15770 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15771 | |
79a45e25 | 15772 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15773 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15774 | { |
79a45e25 | 15775 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15776 | } |
79a45e25 | 15777 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15778 | |
a7bdde9e VP |
15779 | if (ex.reason < 0) |
15780 | throw_exception (ex); | |
1042e4c0 | 15781 | |
a7bdde9e | 15782 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15783 | } |
6149aea9 PA |
15784 | |
15785 | if (tp->enable_state == bp_disabled) | |
15786 | fprintf_unfiltered (fp, "disable\n"); | |
15787 | ||
15788 | /* If this is a multi-location breakpoint, check if the locations | |
15789 | should be individually disabled. Watchpoint locations are | |
15790 | special, and not user visible. */ | |
15791 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15792 | { | |
15793 | struct bp_location *loc; | |
15794 | int n = 1; | |
15795 | ||
15796 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15797 | if (!loc->enabled) | |
15798 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15799 | } | |
1042e4c0 | 15800 | } |
8bf6485c | 15801 | |
6149aea9 | 15802 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15803 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15804 | ||
1042e4c0 | 15805 | if (from_tty) |
6149aea9 | 15806 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15807 | do_cleanups (cleanup); |
6149aea9 PA |
15808 | } |
15809 | ||
15810 | /* The `save breakpoints' command. */ | |
15811 | ||
15812 | static void | |
15813 | save_breakpoints_command (char *args, int from_tty) | |
15814 | { | |
15815 | save_breakpoints (args, from_tty, NULL); | |
15816 | } | |
15817 | ||
15818 | /* The `save tracepoints' command. */ | |
15819 | ||
15820 | static void | |
15821 | save_tracepoints_command (char *args, int from_tty) | |
15822 | { | |
15823 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15824 | } |
15825 | ||
15826 | /* Create a vector of all tracepoints. */ | |
15827 | ||
15828 | VEC(breakpoint_p) * | |
eeae04df | 15829 | all_tracepoints (void) |
1042e4c0 SS |
15830 | { |
15831 | VEC(breakpoint_p) *tp_vec = 0; | |
15832 | struct breakpoint *tp; | |
15833 | ||
15834 | ALL_TRACEPOINTS (tp) | |
15835 | { | |
15836 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15837 | } | |
15838 | ||
15839 | return tp_vec; | |
15840 | } | |
15841 | ||
c906108c | 15842 | \f |
4a64f543 MS |
15843 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15844 | commands. It is defined as a macro to prevent duplication. | |
15845 | COMMAND should be a string constant containing the name of the | |
15846 | command. */ | |
31e2b00f | 15847 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15848 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15849 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15850 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15851 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15852 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15853 | If a line number is specified, break at start of code for that line.\n\ | |
15854 | If a function is specified, break at start of code for that function.\n\ | |
15855 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15856 | With no LOCATION, uses current execution address of the selected\n\ |
15857 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15858 | \n\ |
15859 | THREADNUM is the number from \"info threads\".\n\ | |
15860 | CONDITION is a boolean expression.\n\ | |
15861 | \n\ | |
d41c0fc8 PA |
15862 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15863 | conditions are different.\n\ | |
31e2b00f AS |
15864 | \n\ |
15865 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15866 | ||
44feb3ce TT |
15867 | /* List of subcommands for "catch". */ |
15868 | static struct cmd_list_element *catch_cmdlist; | |
15869 | ||
15870 | /* List of subcommands for "tcatch". */ | |
15871 | static struct cmd_list_element *tcatch_cmdlist; | |
15872 | ||
9ac4176b | 15873 | void |
44feb3ce TT |
15874 | add_catch_command (char *name, char *docstring, |
15875 | void (*sfunc) (char *args, int from_tty, | |
15876 | struct cmd_list_element *command), | |
625e8578 | 15877 | completer_ftype *completer, |
44feb3ce TT |
15878 | void *user_data_catch, |
15879 | void *user_data_tcatch) | |
15880 | { | |
15881 | struct cmd_list_element *command; | |
15882 | ||
15883 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15884 | &catch_cmdlist); | |
15885 | set_cmd_sfunc (command, sfunc); | |
15886 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15887 | set_cmd_completer (command, completer); |
44feb3ce TT |
15888 | |
15889 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15890 | &tcatch_cmdlist); | |
15891 | set_cmd_sfunc (command, sfunc); | |
15892 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15893 | set_cmd_completer (command, completer); |
44feb3ce TT |
15894 | } |
15895 | ||
6c95b8df | 15896 | static void |
a79b8f6e | 15897 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15898 | { |
fa3064dd YQ |
15899 | struct catch_syscall_inferior_data *inf_data |
15900 | = get_catch_syscall_inferior_data (inf); | |
15901 | ||
15902 | inf_data->total_syscalls_count = 0; | |
15903 | inf_data->any_syscall_count = 0; | |
15904 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15905 | } |
15906 | ||
6149aea9 PA |
15907 | static void |
15908 | save_command (char *arg, int from_tty) | |
15909 | { | |
3e43a32a MS |
15910 | printf_unfiltered (_("\"save\" must be followed by " |
15911 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15912 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15913 | } | |
15914 | ||
84f4c1fe PM |
15915 | struct breakpoint * |
15916 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15917 | void *data) | |
15918 | { | |
35df4500 | 15919 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15920 | |
35df4500 | 15921 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15922 | { |
15923 | if ((*callback) (b, data)) | |
15924 | return b; | |
15925 | } | |
15926 | ||
15927 | return NULL; | |
15928 | } | |
15929 | ||
0574c78f GB |
15930 | /* Zero if any of the breakpoint's locations could be a location where |
15931 | functions have been inlined, nonzero otherwise. */ | |
15932 | ||
15933 | static int | |
15934 | is_non_inline_function (struct breakpoint *b) | |
15935 | { | |
15936 | /* The shared library event breakpoint is set on the address of a | |
15937 | non-inline function. */ | |
15938 | if (b->type == bp_shlib_event) | |
15939 | return 1; | |
15940 | ||
15941 | return 0; | |
15942 | } | |
15943 | ||
15944 | /* Nonzero if the specified PC cannot be a location where functions | |
15945 | have been inlined. */ | |
15946 | ||
15947 | int | |
09ac7c10 TT |
15948 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15949 | const struct target_waitstatus *ws) | |
0574c78f GB |
15950 | { |
15951 | struct breakpoint *b; | |
15952 | struct bp_location *bl; | |
15953 | ||
15954 | ALL_BREAKPOINTS (b) | |
15955 | { | |
15956 | if (!is_non_inline_function (b)) | |
15957 | continue; | |
15958 | ||
15959 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15960 | { | |
15961 | if (!bl->shlib_disabled | |
09ac7c10 | 15962 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15963 | return 1; |
15964 | } | |
15965 | } | |
15966 | ||
15967 | return 0; | |
15968 | } | |
15969 | ||
2f202fde JK |
15970 | /* Remove any references to OBJFILE which is going to be freed. */ |
15971 | ||
15972 | void | |
15973 | breakpoint_free_objfile (struct objfile *objfile) | |
15974 | { | |
15975 | struct bp_location **locp, *loc; | |
15976 | ||
15977 | ALL_BP_LOCATIONS (loc, locp) | |
15978 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15979 | loc->symtab = NULL; | |
15980 | } | |
15981 | ||
2060206e PA |
15982 | void |
15983 | initialize_breakpoint_ops (void) | |
15984 | { | |
15985 | static int initialized = 0; | |
15986 | ||
15987 | struct breakpoint_ops *ops; | |
15988 | ||
15989 | if (initialized) | |
15990 | return; | |
15991 | initialized = 1; | |
15992 | ||
15993 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15994 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15995 | internal and momentary breakpoints, etc.). */ | |
15996 | ops = &bkpt_base_breakpoint_ops; | |
15997 | *ops = base_breakpoint_ops; | |
15998 | ops->re_set = bkpt_re_set; | |
15999 | ops->insert_location = bkpt_insert_location; | |
16000 | ops->remove_location = bkpt_remove_location; | |
16001 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
16002 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
16003 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
16004 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
16005 | |
16006 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16007 | ops = &bkpt_breakpoint_ops; | |
16008 | *ops = bkpt_base_breakpoint_ops; | |
16009 | ops->re_set = bkpt_re_set; | |
16010 | ops->resources_needed = bkpt_resources_needed; | |
16011 | ops->print_it = bkpt_print_it; | |
16012 | ops->print_mention = bkpt_print_mention; | |
16013 | ops->print_recreate = bkpt_print_recreate; | |
16014 | ||
16015 | /* Ranged breakpoints. */ | |
16016 | ops = &ranged_breakpoint_ops; | |
16017 | *ops = bkpt_breakpoint_ops; | |
16018 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16019 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16020 | ops->print_it = print_it_ranged_breakpoint; | |
16021 | ops->print_one = print_one_ranged_breakpoint; | |
16022 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16023 | ops->print_mention = print_mention_ranged_breakpoint; | |
16024 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16025 | ||
16026 | /* Internal breakpoints. */ | |
16027 | ops = &internal_breakpoint_ops; | |
16028 | *ops = bkpt_base_breakpoint_ops; | |
16029 | ops->re_set = internal_bkpt_re_set; | |
16030 | ops->check_status = internal_bkpt_check_status; | |
16031 | ops->print_it = internal_bkpt_print_it; | |
16032 | ops->print_mention = internal_bkpt_print_mention; | |
16033 | ||
16034 | /* Momentary breakpoints. */ | |
16035 | ops = &momentary_breakpoint_ops; | |
16036 | *ops = bkpt_base_breakpoint_ops; | |
16037 | ops->re_set = momentary_bkpt_re_set; | |
16038 | ops->check_status = momentary_bkpt_check_status; | |
16039 | ops->print_it = momentary_bkpt_print_it; | |
16040 | ops->print_mention = momentary_bkpt_print_mention; | |
16041 | ||
e2e4d78b JK |
16042 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16043 | ops = &longjmp_breakpoint_ops; | |
16044 | *ops = momentary_breakpoint_ops; | |
16045 | ops->dtor = longjmp_bkpt_dtor; | |
16046 | ||
55aa24fb SDJ |
16047 | /* Probe breakpoints. */ |
16048 | ops = &bkpt_probe_breakpoint_ops; | |
16049 | *ops = bkpt_breakpoint_ops; | |
16050 | ops->insert_location = bkpt_probe_insert_location; | |
16051 | ops->remove_location = bkpt_probe_remove_location; | |
16052 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16053 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16054 | ||
2060206e PA |
16055 | /* Watchpoints. */ |
16056 | ops = &watchpoint_breakpoint_ops; | |
16057 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16058 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16059 | ops->re_set = re_set_watchpoint; |
16060 | ops->insert_location = insert_watchpoint; | |
16061 | ops->remove_location = remove_watchpoint; | |
16062 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16063 | ops->check_status = check_status_watchpoint; | |
16064 | ops->resources_needed = resources_needed_watchpoint; | |
16065 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16066 | ops->print_it = print_it_watchpoint; | |
16067 | ops->print_mention = print_mention_watchpoint; | |
16068 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16069 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16070 | |
16071 | /* Masked watchpoints. */ | |
16072 | ops = &masked_watchpoint_breakpoint_ops; | |
16073 | *ops = watchpoint_breakpoint_ops; | |
16074 | ops->insert_location = insert_masked_watchpoint; | |
16075 | ops->remove_location = remove_masked_watchpoint; | |
16076 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16077 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16078 | ops->print_it = print_it_masked_watchpoint; | |
16079 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16080 | ops->print_mention = print_mention_masked_watchpoint; | |
16081 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16082 | ||
16083 | /* Tracepoints. */ | |
16084 | ops = &tracepoint_breakpoint_ops; | |
16085 | *ops = base_breakpoint_ops; | |
16086 | ops->re_set = tracepoint_re_set; | |
16087 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16088 | ops->print_one_detail = tracepoint_print_one_detail; | |
16089 | ops->print_mention = tracepoint_print_mention; | |
16090 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16091 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16092 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16093 | ops->decode_linespec = tracepoint_decode_linespec; | |
16094 | ||
55aa24fb SDJ |
16095 | /* Probe tracepoints. */ |
16096 | ops = &tracepoint_probe_breakpoint_ops; | |
16097 | *ops = tracepoint_breakpoint_ops; | |
16098 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16099 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16100 | ||
983af33b SDJ |
16101 | /* Static tracepoints with marker (`-m'). */ |
16102 | ops = &strace_marker_breakpoint_ops; | |
16103 | *ops = tracepoint_breakpoint_ops; | |
16104 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16105 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16106 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16107 | |
16108 | /* Fork catchpoints. */ | |
16109 | ops = &catch_fork_breakpoint_ops; | |
16110 | *ops = base_breakpoint_ops; | |
16111 | ops->insert_location = insert_catch_fork; | |
16112 | ops->remove_location = remove_catch_fork; | |
16113 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16114 | ops->print_it = print_it_catch_fork; | |
16115 | ops->print_one = print_one_catch_fork; | |
16116 | ops->print_mention = print_mention_catch_fork; | |
16117 | ops->print_recreate = print_recreate_catch_fork; | |
16118 | ||
16119 | /* Vfork catchpoints. */ | |
16120 | ops = &catch_vfork_breakpoint_ops; | |
16121 | *ops = base_breakpoint_ops; | |
16122 | ops->insert_location = insert_catch_vfork; | |
16123 | ops->remove_location = remove_catch_vfork; | |
16124 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16125 | ops->print_it = print_it_catch_vfork; | |
16126 | ops->print_one = print_one_catch_vfork; | |
16127 | ops->print_mention = print_mention_catch_vfork; | |
16128 | ops->print_recreate = print_recreate_catch_vfork; | |
16129 | ||
16130 | /* Exec catchpoints. */ | |
16131 | ops = &catch_exec_breakpoint_ops; | |
16132 | *ops = base_breakpoint_ops; | |
16133 | ops->dtor = dtor_catch_exec; | |
16134 | ops->insert_location = insert_catch_exec; | |
16135 | ops->remove_location = remove_catch_exec; | |
16136 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16137 | ops->print_it = print_it_catch_exec; | |
16138 | ops->print_one = print_one_catch_exec; | |
16139 | ops->print_mention = print_mention_catch_exec; | |
16140 | ops->print_recreate = print_recreate_catch_exec; | |
16141 | ||
16142 | /* Syscall catchpoints. */ | |
16143 | ops = &catch_syscall_breakpoint_ops; | |
16144 | *ops = base_breakpoint_ops; | |
16145 | ops->dtor = dtor_catch_syscall; | |
16146 | ops->insert_location = insert_catch_syscall; | |
16147 | ops->remove_location = remove_catch_syscall; | |
16148 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16149 | ops->print_it = print_it_catch_syscall; | |
16150 | ops->print_one = print_one_catch_syscall; | |
16151 | ops->print_mention = print_mention_catch_syscall; | |
16152 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16153 | |
16154 | /* Solib-related catchpoints. */ | |
16155 | ops = &catch_solib_breakpoint_ops; | |
16156 | *ops = base_breakpoint_ops; | |
16157 | ops->dtor = dtor_catch_solib; | |
16158 | ops->insert_location = insert_catch_solib; | |
16159 | ops->remove_location = remove_catch_solib; | |
16160 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16161 | ops->check_status = check_status_catch_solib; | |
16162 | ops->print_it = print_it_catch_solib; | |
16163 | ops->print_one = print_one_catch_solib; | |
16164 | ops->print_mention = print_mention_catch_solib; | |
16165 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16166 | |
16167 | ops = &dprintf_breakpoint_ops; | |
16168 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16169 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16170 | ops->resources_needed = bkpt_resources_needed; |
16171 | ops->print_it = bkpt_print_it; | |
16172 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16173 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16174 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16175 | } |
16176 | ||
8bfd80db YQ |
16177 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16178 | ||
16179 | static struct cmd_list_element *enablebreaklist = NULL; | |
16180 | ||
c906108c | 16181 | void |
fba45db2 | 16182 | _initialize_breakpoint (void) |
c906108c SS |
16183 | { |
16184 | struct cmd_list_element *c; | |
16185 | ||
2060206e PA |
16186 | initialize_breakpoint_ops (); |
16187 | ||
84acb35a | 16188 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16189 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16190 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16191 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16192 | |
55aa24fb SDJ |
16193 | breakpoint_objfile_key |
16194 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16195 | |
fa3064dd | 16196 | catch_syscall_inferior_data |
8e260fc0 TT |
16197 | = register_inferior_data_with_cleanup (NULL, |
16198 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16199 | |
c906108c SS |
16200 | breakpoint_chain = 0; |
16201 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16202 | before a breakpoint is set. */ | |
16203 | breakpoint_count = 0; | |
16204 | ||
1042e4c0 SS |
16205 | tracepoint_count = 0; |
16206 | ||
1bedd215 AC |
16207 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16208 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16209 | Usage is `ignore N COUNT'.")); | |
c906108c | 16210 | if (xdb_commands) |
c5aa993b | 16211 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16212 | |
1bedd215 AC |
16213 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16214 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16215 | Give breakpoint number as argument after \"commands\".\n\ |
16216 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16217 | The commands themselves follow starting on the next line.\n\ | |
16218 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16219 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16220 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16221 | |
d55637df | 16222 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16223 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16224 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16225 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16226 | set_cmd_completer (c, condition_completer); |
c906108c | 16227 | |
1bedd215 | 16228 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16229 | Set a temporary breakpoint.\n\ |
c906108c SS |
16230 | Like \"break\" except the breakpoint is only temporary,\n\ |
16231 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16232 | by using \"enable delete\" on the breakpoint number.\n\ |
16233 | \n" | |
16234 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16235 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16236 | |
1bedd215 | 16237 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16238 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16239 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16240 | some target hardware may not have this support.\n\ |
16241 | \n" | |
16242 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16243 | set_cmd_completer (c, location_completer); |
c906108c | 16244 | |
1bedd215 | 16245 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16246 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16247 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16248 | so it will be deleted when hit.\n\ |
16249 | \n" | |
16250 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16251 | set_cmd_completer (c, location_completer); |
c906108c | 16252 | |
1bedd215 AC |
16253 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16254 | Enable some breakpoints.\n\ | |
c906108c SS |
16255 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16256 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16257 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16258 | With a subcommand you can enable temporarily."), |
c906108c SS |
16259 | &enablelist, "enable ", 1, &cmdlist); |
16260 | if (xdb_commands) | |
1bedd215 AC |
16261 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16262 | Enable some breakpoints.\n\ | |
c906108c SS |
16263 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16264 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16265 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16266 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16267 | |
16268 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16269 | ||
84951ab5 | 16270 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16271 | Enable some breakpoints.\n\ |
c906108c SS |
16272 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16273 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16274 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16275 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16276 | |
1a966eab AC |
16277 | add_cmd ("once", no_class, enable_once_command, _("\ |
16278 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16279 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16280 | &enablebreaklist); |
16281 | ||
1a966eab AC |
16282 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16283 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16284 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16285 | &enablebreaklist); |
16286 | ||
816338b5 SS |
16287 | add_cmd ("count", no_class, enable_count_command, _("\ |
16288 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16289 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16290 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16291 | &enablebreaklist); | |
16292 | ||
1a966eab AC |
16293 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16294 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16295 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16296 | &enablelist); |
16297 | ||
1a966eab AC |
16298 | add_cmd ("once", no_class, enable_once_command, _("\ |
16299 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16300 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16301 | &enablelist); |
16302 | ||
16303 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16304 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16305 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16306 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16307 | &enablelist); |
16308 | ||
1bedd215 AC |
16309 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16310 | Disable some breakpoints.\n\ | |
c906108c SS |
16311 | Arguments are breakpoint numbers with spaces in between.\n\ |
16312 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16313 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16314 | &disablelist, "disable ", 1, &cmdlist); |
16315 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16316 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16317 | if (xdb_commands) | |
1bedd215 AC |
16318 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16319 | Disable some breakpoints.\n\ | |
c906108c SS |
16320 | Arguments are breakpoint numbers with spaces in between.\n\ |
16321 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16322 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16323 | |
1a966eab AC |
16324 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16325 | Disable some breakpoints.\n\ | |
c906108c SS |
16326 | Arguments are breakpoint numbers with spaces in between.\n\ |
16327 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16328 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16329 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16330 | &disablelist); |
16331 | ||
1bedd215 AC |
16332 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16333 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16334 | Arguments are breakpoint numbers with spaces in between.\n\ |
16335 | To delete all breakpoints, give no argument.\n\ | |
16336 | \n\ | |
16337 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16338 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16339 | &deletelist, "delete ", 1, &cmdlist); |
16340 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16341 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16342 | if (xdb_commands) |
1bedd215 AC |
16343 | add_com ("db", class_breakpoint, delete_command, _("\ |
16344 | Delete some breakpoints.\n\ | |
c906108c | 16345 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16346 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16347 | |
1a966eab AC |
16348 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16349 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16350 | Arguments are breakpoint numbers with spaces in between.\n\ |
16351 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16352 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16353 | &deletelist); |
16354 | ||
1bedd215 AC |
16355 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16356 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16357 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16358 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16359 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16360 | If an address is specified, breakpoints at that address are cleared.\n\ |
16361 | \n\ | |
16362 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16363 | is executing in.\n\ |
16364 | \n\ | |
1bedd215 | 16365 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16366 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16367 | |
1bedd215 | 16368 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16369 | Set breakpoint at specified line or function.\n" |
16370 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16371 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16372 | |
c906108c SS |
16373 | add_com_alias ("b", "break", class_run, 1); |
16374 | add_com_alias ("br", "break", class_run, 1); | |
16375 | add_com_alias ("bre", "break", class_run, 1); | |
16376 | add_com_alias ("brea", "break", class_run, 1); | |
16377 | ||
7681d515 PM |
16378 | if (xdb_commands) |
16379 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16380 | |
16381 | if (dbx_commands) | |
16382 | { | |
1bedd215 AC |
16383 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16384 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16385 | &stoplist, "stop ", 1, &cmdlist); |
16386 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16387 | _("Break in function or address."), &stoplist); |
c5aa993b | 16388 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16389 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16390 | add_com ("status", class_info, breakpoints_info, _("\ |
16391 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16392 | The \"Type\" column indicates one of:\n\ |
16393 | \tbreakpoint - normal breakpoint\n\ | |
16394 | \twatchpoint - watchpoint\n\ | |
16395 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16396 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16397 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16398 | address and file/line number respectively.\n\ |
16399 | \n\ | |
16400 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16401 | are set to the address of the last breakpoint listed unless the command\n\ |
16402 | is prefixed with \"server \".\n\n\ | |
c906108c | 16403 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16404 | breakpoint set.")); |
c906108c SS |
16405 | } |
16406 | ||
1bedd215 | 16407 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16408 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16409 | The \"Type\" column indicates one of:\n\ |
16410 | \tbreakpoint - normal breakpoint\n\ | |
16411 | \twatchpoint - watchpoint\n\ | |
16412 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16413 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16414 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16415 | address and file/line number respectively.\n\ |
16416 | \n\ | |
16417 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16418 | are set to the address of the last breakpoint listed unless the command\n\ |
16419 | is prefixed with \"server \".\n\n\ | |
c906108c | 16420 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16421 | breakpoint set.")); |
c906108c | 16422 | |
6b04bdb7 MS |
16423 | add_info_alias ("b", "breakpoints", 1); |
16424 | ||
c906108c | 16425 | if (xdb_commands) |
1bedd215 AC |
16426 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16427 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16428 | The \"Type\" column indicates one of:\n\ |
16429 | \tbreakpoint - normal breakpoint\n\ | |
16430 | \twatchpoint - watchpoint\n\ | |
16431 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16432 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16433 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16434 | address and file/line number respectively.\n\ |
16435 | \n\ | |
16436 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16437 | are set to the address of the last breakpoint listed unless the command\n\ |
16438 | is prefixed with \"server \".\n\n\ | |
c906108c | 16439 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16440 | breakpoint set.")); |
c906108c | 16441 | |
1a966eab AC |
16442 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16443 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16444 | The \"Type\" column indicates one of:\n\ |
16445 | \tbreakpoint - normal breakpoint\n\ | |
16446 | \twatchpoint - watchpoint\n\ | |
16447 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16448 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16449 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16450 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16451 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16452 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16453 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16454 | address and file/line number respectively.\n\ |
16455 | \n\ | |
16456 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16457 | are set to the address of the last breakpoint listed unless the command\n\ |
16458 | is prefixed with \"server \".\n\n\ | |
c906108c | 16459 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16460 | breakpoint set."), |
c906108c SS |
16461 | &maintenanceinfolist); |
16462 | ||
44feb3ce TT |
16463 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16464 | Set catchpoints to catch events."), | |
16465 | &catch_cmdlist, "catch ", | |
16466 | 0/*allow-unknown*/, &cmdlist); | |
16467 | ||
16468 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16469 | Set temporary catchpoints to catch events."), | |
16470 | &tcatch_cmdlist, "tcatch ", | |
16471 | 0/*allow-unknown*/, &cmdlist); | |
16472 | ||
44feb3ce TT |
16473 | add_catch_command ("fork", _("Catch calls to fork."), |
16474 | catch_fork_command_1, | |
a96d9b2e | 16475 | NULL, |
44feb3ce TT |
16476 | (void *) (uintptr_t) catch_fork_permanent, |
16477 | (void *) (uintptr_t) catch_fork_temporary); | |
16478 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16479 | catch_fork_command_1, | |
a96d9b2e | 16480 | NULL, |
44feb3ce TT |
16481 | (void *) (uintptr_t) catch_vfork_permanent, |
16482 | (void *) (uintptr_t) catch_vfork_temporary); | |
16483 | add_catch_command ("exec", _("Catch calls to exec."), | |
16484 | catch_exec_command_1, | |
a96d9b2e SDJ |
16485 | NULL, |
16486 | CATCH_PERMANENT, | |
16487 | CATCH_TEMPORARY); | |
edcc5120 TT |
16488 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16489 | Usage: catch load [REGEX]\n\ | |
16490 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16491 | catch_load_command_1, | |
16492 | NULL, | |
16493 | CATCH_PERMANENT, | |
16494 | CATCH_TEMPORARY); | |
16495 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16496 | Usage: catch unload [REGEX]\n\ | |
16497 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16498 | catch_unload_command_1, | |
16499 | NULL, | |
16500 | CATCH_PERMANENT, | |
16501 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16502 | add_catch_command ("syscall", _("\ |
16503 | Catch system calls by their names and/or numbers.\n\ | |
16504 | Arguments say which system calls to catch. If no arguments\n\ | |
16505 | are given, every system call will be caught.\n\ | |
16506 | Arguments, if given, should be one or more system call names\n\ | |
16507 | (if your system supports that), or system call numbers."), | |
16508 | catch_syscall_command_1, | |
16509 | catch_syscall_completer, | |
44feb3ce TT |
16510 | CATCH_PERMANENT, |
16511 | CATCH_TEMPORARY); | |
c5aa993b | 16512 | |
1bedd215 AC |
16513 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16514 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16515 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16516 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16517 | an expression changes.\n\ |
16518 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16519 | the memory to which it refers.")); | |
65d12d83 | 16520 | set_cmd_completer (c, expression_completer); |
c906108c | 16521 | |
1bedd215 AC |
16522 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16523 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16524 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16525 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16526 | an expression is read.\n\ |
16527 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16528 | the memory to which it refers.")); | |
65d12d83 | 16529 | set_cmd_completer (c, expression_completer); |
c906108c | 16530 | |
1bedd215 AC |
16531 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16532 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16533 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16534 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16535 | an expression is either read or written.\n\ |
16536 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16537 | the memory to which it refers.")); | |
65d12d83 | 16538 | set_cmd_completer (c, expression_completer); |
c906108c | 16539 | |
d77f58be | 16540 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16541 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16542 | |
920d2a44 AC |
16543 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16544 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16545 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16546 | &can_use_hw_watchpoints, _("\ | |
16547 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16548 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16549 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16550 | such is available. (However, any hardware watchpoints that were\n\ | |
16551 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16552 | hardware.)"), |
16553 | NULL, | |
920d2a44 | 16554 | show_can_use_hw_watchpoints, |
85c07804 | 16555 | &setlist, &showlist); |
c906108c SS |
16556 | |
16557 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16558 | |
1042e4c0 SS |
16559 | /* Tracepoint manipulation commands. */ |
16560 | ||
16561 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16562 | Set a tracepoint at specified line or function.\n\ | |
16563 | \n" | |
16564 | BREAK_ARGS_HELP ("trace") "\n\ | |
16565 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16566 | set_cmd_completer (c, location_completer); | |
16567 | ||
16568 | add_com_alias ("tp", "trace", class_alias, 0); | |
16569 | add_com_alias ("tr", "trace", class_alias, 1); | |
16570 | add_com_alias ("tra", "trace", class_alias, 1); | |
16571 | add_com_alias ("trac", "trace", class_alias, 1); | |
16572 | ||
7a697b8d SS |
16573 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16574 | Set a fast tracepoint at specified line or function.\n\ | |
16575 | \n" | |
16576 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16577 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16578 | set_cmd_completer (c, location_completer); | |
16579 | ||
0fb4aa4b PA |
16580 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16581 | Set a static tracepoint at specified line, function or marker.\n\ | |
16582 | \n\ | |
16583 | strace [LOCATION] [if CONDITION]\n\ | |
16584 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16585 | or -m MARKER_ID.\n\ | |
16586 | If a line number is specified, probe the marker at start of code\n\ | |
16587 | for that line. If a function is specified, probe the marker at start\n\ | |
16588 | of code for that function. If an address is specified, probe the marker\n\ | |
16589 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16590 | with that name. With no LOCATION, uses current execution address of\n\ | |
16591 | the selected stack frame.\n\ | |
16592 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16593 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16594 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16595 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16596 | \n\ | |
16597 | CONDITION is a boolean expression.\n\ | |
16598 | \n\ | |
d41c0fc8 PA |
16599 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16600 | conditions are different.\n\ | |
0fb4aa4b PA |
16601 | \n\ |
16602 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16603 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16604 | set_cmd_completer (c, location_completer); | |
16605 | ||
1042e4c0 | 16606 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16607 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16608 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16609 | last tracepoint set.")); | |
16610 | ||
16611 | add_info_alias ("tp", "tracepoints", 1); | |
16612 | ||
16613 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16614 | Delete specified tracepoints.\n\ | |
16615 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16616 | No argument means delete all tracepoints."), | |
16617 | &deletelist); | |
7e20dfcd | 16618 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16619 | |
16620 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16621 | Disable specified tracepoints.\n\ | |
16622 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16623 | No argument means disable all tracepoints."), | |
16624 | &disablelist); | |
16625 | deprecate_cmd (c, "disable"); | |
16626 | ||
16627 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16628 | Enable specified tracepoints.\n\ | |
16629 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16630 | No argument means enable all tracepoints."), | |
16631 | &enablelist); | |
16632 | deprecate_cmd (c, "enable"); | |
16633 | ||
16634 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16635 | Set the passcount for a tracepoint.\n\ | |
16636 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16637 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16638 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16639 | ||
6149aea9 PA |
16640 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16641 | _("Save breakpoint definitions as a script."), | |
16642 | &save_cmdlist, "save ", | |
16643 | 0/*allow-unknown*/, &cmdlist); | |
16644 | ||
16645 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16646 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16647 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16648 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16649 | session to restore them."), | |
16650 | &save_cmdlist); | |
16651 | set_cmd_completer (c, filename_completer); | |
16652 | ||
16653 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16654 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16655 | Use the 'source' command in another debug session to restore them."), |
16656 | &save_cmdlist); | |
1042e4c0 SS |
16657 | set_cmd_completer (c, filename_completer); |
16658 | ||
6149aea9 PA |
16659 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16660 | deprecate_cmd (c, "save tracepoints"); | |
16661 | ||
1bedd215 | 16662 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16663 | Breakpoint specific settings\n\ |
16664 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16665 | pending breakpoint behavior"), |
fa8d40ab JJ |
16666 | &breakpoint_set_cmdlist, "set breakpoint ", |
16667 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16668 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16669 | Breakpoint specific settings\n\ |
16670 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16671 | pending breakpoint behavior"), |
fa8d40ab JJ |
16672 | &breakpoint_show_cmdlist, "show breakpoint ", |
16673 | 0/*allow-unknown*/, &showlist); | |
16674 | ||
7915a72c AC |
16675 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16676 | &pending_break_support, _("\ | |
16677 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16678 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16679 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16680 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16681 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16682 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16683 | NULL, |
920d2a44 | 16684 | show_pending_break_support, |
6e1d7d6c AC |
16685 | &breakpoint_set_cmdlist, |
16686 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16687 | |
16688 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16689 | |
16690 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16691 | &automatic_hardware_breakpoints, _("\ | |
16692 | Set automatic usage of hardware breakpoints."), _("\ | |
16693 | Show automatic usage of hardware breakpoints."), _("\ | |
16694 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16695 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16696 | a warning will be emitted for such breakpoints."), | |
16697 | NULL, | |
16698 | show_automatic_hardware_breakpoints, | |
16699 | &breakpoint_set_cmdlist, | |
16700 | &breakpoint_show_cmdlist); | |
74960c60 | 16701 | |
72d0e2c5 YQ |
16702 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16703 | &always_inserted_mode, _("\ | |
74960c60 VP |
16704 | Set mode for inserting breakpoints."), _("\ |
16705 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16706 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16707 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16708 | breakpoints are inserted immediately and removed only when the user\n\ | |
16709 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16710 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16711 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16712 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16713 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16714 | NULL, |
16715 | &show_always_inserted_mode, | |
16716 | &breakpoint_set_cmdlist, | |
16717 | &breakpoint_show_cmdlist); | |
f1310107 | 16718 | |
b775012e LM |
16719 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16720 | condition_evaluation_enums, | |
16721 | &condition_evaluation_mode_1, _("\ | |
16722 | Set mode of breakpoint condition evaluation."), _("\ | |
16723 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16724 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16725 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16726 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16727 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16728 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16729 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16730 | be set to \"gdb\""), | |
16731 | &set_condition_evaluation_mode, | |
16732 | &show_condition_evaluation_mode, | |
16733 | &breakpoint_set_cmdlist, | |
16734 | &breakpoint_show_cmdlist); | |
16735 | ||
f1310107 TJB |
16736 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16737 | Set a breakpoint for an address range.\n\ | |
16738 | break-range START-LOCATION, END-LOCATION\n\ | |
16739 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16740 | LINENUM, for that line in the current file,\n\ | |
16741 | FILE:LINENUM, for that line in that file,\n\ | |
16742 | +OFFSET, for that number of lines after the current line\n\ | |
16743 | or the start of the range\n\ | |
16744 | FUNCTION, for the first line in that function,\n\ | |
16745 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16746 | *ADDRESS, for the instruction at that address.\n\ | |
16747 | \n\ | |
16748 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16749 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16750 | range (including START-LOCATION and END-LOCATION).")); | |
16751 | ||
e7e0cddf SS |
16752 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16753 | Set a dynamic printf at specified line or function.\n\ | |
16754 | dprintf location,format string,arg1,arg2,...\n\ | |
16755 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16756 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16757 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16758 | set_cmd_completer (c, location_completer); |
16759 | ||
16760 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16761 | dprintf_style_enums, &dprintf_style, _("\ | |
16762 | Set the style of usage for dynamic printf."), _("\ | |
16763 | Show the style of usage for dynamic printf."), _("\ | |
16764 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16765 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16766 | console, as with the \"printf\" command.\n\ | |
16767 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16768 | program; by default printf(), but you can choose a different function or\n\ | |
16769 | output stream by setting dprintf-function and dprintf-channel."), | |
16770 | update_dprintf_commands, NULL, | |
16771 | &setlist, &showlist); | |
16772 | ||
16773 | dprintf_function = xstrdup ("printf"); | |
16774 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16775 | &dprintf_function, _("\ | |
16776 | Set the function to use for dynamic printf"), _("\ | |
16777 | Show the function to use for dynamic printf"), NULL, | |
16778 | update_dprintf_commands, NULL, | |
16779 | &setlist, &showlist); | |
16780 | ||
16781 | dprintf_channel = xstrdup (""); | |
16782 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16783 | &dprintf_channel, _("\ | |
16784 | Set the channel to use for dynamic printf"), _("\ | |
16785 | Show the channel to use for dynamic printf"), NULL, | |
16786 | update_dprintf_commands, NULL, | |
16787 | &setlist, &showlist); | |
16788 | ||
d3ce09f5 SS |
16789 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16790 | &disconnected_dprintf, _("\ | |
16791 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16792 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16793 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16794 | even if GDB disconnects or detaches from the target."), | |
16795 | NULL, | |
16796 | NULL, | |
16797 | &setlist, &showlist); | |
16798 | ||
16799 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16800 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16801 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16802 | ||
765dc015 | 16803 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16804 | |
16805 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16806 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16807 | } |