Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
28e7fd62 | 3 | Copyright (C) 1986-2013 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
38 | #include "gdb_string.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
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" | |
edcc5120 | 69 | #include "gdb_regex.h" |
b775012e | 70 | #include "ax-gdb.h" |
e2e4d78b | 71 | #include "dummy-frame.h" |
c906108c | 72 | |
d3ce09f5 SS |
73 | #include "format.h" |
74 | ||
1042e4c0 SS |
75 | /* readline include files */ |
76 | #include "readline/readline.h" | |
77 | #include "readline/history.h" | |
78 | ||
79 | /* readline defines this. */ | |
80 | #undef savestring | |
81 | ||
034dad6f | 82 | #include "mi/mi-common.h" |
7371cf6d | 83 | #include "python/python.h" |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
95a42b64 TT |
105 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
106 | void *), | |
107 | void *); | |
c906108c | 108 | |
a14ed312 | 109 | static void ignore_command (char *, int); |
c906108c | 110 | |
4efb68b1 | 111 | static int breakpoint_re_set_one (void *); |
c906108c | 112 | |
348d480f PA |
113 | static void breakpoint_re_set_default (struct breakpoint *); |
114 | ||
983af33b SDJ |
115 | static void create_sals_from_address_default (char **, |
116 | struct linespec_result *, | |
117 | enum bptype, char *, | |
118 | char **); | |
119 | ||
120 | static void create_breakpoints_sal_default (struct gdbarch *, | |
121 | struct linespec_result *, | |
e7e0cddf | 122 | char *, char *, enum bptype, |
983af33b SDJ |
123 | enum bpdisp, int, int, |
124 | int, | |
125 | const struct breakpoint_ops *, | |
44f238bb | 126 | int, int, int, unsigned); |
983af33b SDJ |
127 | |
128 | static void decode_linespec_default (struct breakpoint *, char **, | |
129 | struct symtabs_and_lines *); | |
130 | ||
a14ed312 | 131 | static void clear_command (char *, int); |
c906108c | 132 | |
a14ed312 | 133 | static void catch_command (char *, int); |
c906108c | 134 | |
a9634178 | 135 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 136 | |
98deb0da | 137 | static void break_command_1 (char *, int, int); |
c906108c | 138 | |
a14ed312 | 139 | static void mention (struct breakpoint *); |
c906108c | 140 | |
348d480f PA |
141 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
142 | enum bptype, | |
c0a91b2b | 143 | const struct breakpoint_ops *); |
3742cc8b YQ |
144 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
145 | const struct symtab_and_line *); | |
146 | ||
4a64f543 MS |
147 | /* This function is used in gdbtk sources and thus can not be made |
148 | static. */ | |
63c252f8 | 149 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 150 | struct symtab_and_line, |
c0a91b2b TT |
151 | enum bptype, |
152 | const struct breakpoint_ops *); | |
c906108c | 153 | |
06edf0c0 PA |
154 | static struct breakpoint * |
155 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
156 | enum bptype type, | |
c0a91b2b | 157 | const struct breakpoint_ops *ops); |
06edf0c0 | 158 | |
76897487 KB |
159 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
160 | ||
a6d9a66e UW |
161 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
162 | CORE_ADDR bpaddr, | |
88f7da05 | 163 | enum bptype bptype); |
76897487 | 164 | |
6c95b8df PA |
165 | static void describe_other_breakpoints (struct gdbarch *, |
166 | struct program_space *, CORE_ADDR, | |
5af949e3 | 167 | struct obj_section *, int); |
c906108c | 168 | |
6c95b8df PA |
169 | static int breakpoint_address_match (struct address_space *aspace1, |
170 | CORE_ADDR addr1, | |
171 | struct address_space *aspace2, | |
172 | CORE_ADDR addr2); | |
173 | ||
85d721b8 PA |
174 | static int watchpoint_locations_match (struct bp_location *loc1, |
175 | struct bp_location *loc2); | |
176 | ||
f1310107 TJB |
177 | static int breakpoint_location_address_match (struct bp_location *bl, |
178 | struct address_space *aspace, | |
179 | CORE_ADDR addr); | |
180 | ||
a14ed312 | 181 | static void breakpoints_info (char *, int); |
c906108c | 182 | |
d77f58be SS |
183 | static void watchpoints_info (char *, int); |
184 | ||
e5a67952 MS |
185 | static int breakpoint_1 (char *, int, |
186 | int (*) (const struct breakpoint *)); | |
c906108c | 187 | |
4efb68b1 | 188 | static int breakpoint_cond_eval (void *); |
c906108c | 189 | |
4efb68b1 | 190 | static void cleanup_executing_breakpoints (void *); |
c906108c | 191 | |
a14ed312 | 192 | static void commands_command (char *, int); |
c906108c | 193 | |
a14ed312 | 194 | static void condition_command (char *, int); |
c906108c | 195 | |
c5aa993b JM |
196 | typedef enum |
197 | { | |
198 | mark_inserted, | |
199 | mark_uninserted | |
200 | } | |
201 | insertion_state_t; | |
c906108c | 202 | |
0bde7532 | 203 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 204 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 205 | |
e514a9d6 | 206 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 207 | |
4efb68b1 | 208 | static int watchpoint_check (void *); |
c906108c | 209 | |
a14ed312 | 210 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 211 | |
a14ed312 | 212 | static int hw_breakpoint_used_count (void); |
c906108c | 213 | |
a1398e0c PA |
214 | static int hw_watchpoint_use_count (struct breakpoint *); |
215 | ||
216 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
217 | enum bptype type, | |
218 | int *other_type_used); | |
c906108c | 219 | |
a14ed312 | 220 | static void hbreak_command (char *, int); |
c906108c | 221 | |
a14ed312 | 222 | static void thbreak_command (char *, int); |
c906108c | 223 | |
816338b5 SS |
224 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
225 | int count); | |
c906108c | 226 | |
a14ed312 | 227 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 228 | |
a14ed312 | 229 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 230 | |
a14ed312 | 231 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 232 | |
a14ed312 | 233 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 234 | |
d03285ec UW |
235 | static void detach_single_step_breakpoints (void); |
236 | ||
6c95b8df PA |
237 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
238 | CORE_ADDR pc); | |
1aafd4da | 239 | |
fe3f5fa8 | 240 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
241 | static void incref_bp_location (struct bp_location *loc); |
242 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 243 | |
39d61571 | 244 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 245 | |
b60e7edf | 246 | static void update_global_location_list (int); |
a5606eee | 247 | |
b60e7edf | 248 | static void update_global_location_list_nothrow (int); |
74960c60 | 249 | |
d77f58be | 250 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
251 | |
252 | static void insert_breakpoint_locations (void); | |
a5606eee | 253 | |
a96d9b2e SDJ |
254 | static int syscall_catchpoint_p (struct breakpoint *b); |
255 | ||
1042e4c0 SS |
256 | static void tracepoints_info (char *, int); |
257 | ||
258 | static void delete_trace_command (char *, int); | |
259 | ||
260 | static void enable_trace_command (char *, int); | |
261 | ||
262 | static void disable_trace_command (char *, int); | |
263 | ||
264 | static void trace_pass_command (char *, int); | |
265 | ||
558a9d82 YQ |
266 | static void set_tracepoint_count (int num); |
267 | ||
9c06b0b4 TJB |
268 | static int is_masked_watchpoint (const struct breakpoint *b); |
269 | ||
b775012e LM |
270 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
271 | ||
983af33b SDJ |
272 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
273 | otherwise. */ | |
274 | ||
275 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 276 | |
2060206e PA |
277 | /* The abstract base class all breakpoint_ops structures inherit |
278 | from. */ | |
ab04a2af | 279 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
280 | |
281 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
282 | that are implemented on top of software or hardware breakpoints | |
283 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
284 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
285 | ||
286 | /* Internal breakpoints class type. */ | |
06edf0c0 | 287 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
288 | |
289 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
290 | static struct breakpoint_ops momentary_breakpoint_ops; |
291 | ||
e2e4d78b JK |
292 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
293 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
294 | ||
2060206e PA |
295 | /* The breakpoint_ops structure to be used in regular user created |
296 | breakpoints. */ | |
297 | struct breakpoint_ops bkpt_breakpoint_ops; | |
298 | ||
55aa24fb SDJ |
299 | /* Breakpoints set on probes. */ |
300 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
301 | ||
e7e0cddf | 302 | /* Dynamic printf class type. */ |
c5867ab6 | 303 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 304 | |
d3ce09f5 SS |
305 | /* The style in which to perform a dynamic printf. This is a user |
306 | option because different output options have different tradeoffs; | |
307 | if GDB does the printing, there is better error handling if there | |
308 | is a problem with any of the arguments, but using an inferior | |
309 | function lets you have special-purpose printers and sending of | |
310 | output to the same place as compiled-in print functions. */ | |
311 | ||
312 | static const char dprintf_style_gdb[] = "gdb"; | |
313 | static const char dprintf_style_call[] = "call"; | |
314 | static const char dprintf_style_agent[] = "agent"; | |
315 | static const char *const dprintf_style_enums[] = { | |
316 | dprintf_style_gdb, | |
317 | dprintf_style_call, | |
318 | dprintf_style_agent, | |
319 | NULL | |
320 | }; | |
321 | static const char *dprintf_style = dprintf_style_gdb; | |
322 | ||
323 | /* The function to use for dynamic printf if the preferred style is to | |
324 | call into the inferior. The value is simply a string that is | |
325 | copied into the command, so it can be anything that GDB can | |
326 | evaluate to a callable address, not necessarily a function name. */ | |
327 | ||
328 | static char *dprintf_function = ""; | |
329 | ||
330 | /* The channel to use for dynamic printf if the preferred style is to | |
331 | call into the inferior; if a nonempty string, it will be passed to | |
332 | the call as the first argument, with the format string as the | |
333 | second. As with the dprintf function, this can be anything that | |
334 | GDB knows how to evaluate, so in addition to common choices like | |
335 | "stderr", this could be an app-specific expression like | |
336 | "mystreams[curlogger]". */ | |
337 | ||
338 | static char *dprintf_channel = ""; | |
339 | ||
340 | /* True if dprintf commands should continue to operate even if GDB | |
341 | has disconnected. */ | |
342 | static int disconnected_dprintf = 1; | |
343 | ||
5cea2a26 PA |
344 | /* A reference-counted struct command_line. This lets multiple |
345 | breakpoints share a single command list. */ | |
346 | struct counted_command_line | |
347 | { | |
348 | /* The reference count. */ | |
349 | int refc; | |
350 | ||
351 | /* The command list. */ | |
352 | struct command_line *commands; | |
353 | }; | |
354 | ||
355 | struct command_line * | |
356 | breakpoint_commands (struct breakpoint *b) | |
357 | { | |
358 | return b->commands ? b->commands->commands : NULL; | |
359 | } | |
3daf8fe5 | 360 | |
f3b1572e PA |
361 | /* Flag indicating that a command has proceeded the inferior past the |
362 | current breakpoint. */ | |
363 | ||
364 | static int breakpoint_proceeded; | |
365 | ||
956a9fb9 | 366 | const char * |
2cec12e5 AR |
367 | bpdisp_text (enum bpdisp disp) |
368 | { | |
4a64f543 MS |
369 | /* NOTE: the following values are a part of MI protocol and |
370 | represent values of 'disp' field returned when inferior stops at | |
371 | a breakpoint. */ | |
bc043ef3 | 372 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 373 | |
2cec12e5 AR |
374 | return bpdisps[(int) disp]; |
375 | } | |
c906108c | 376 | |
4a64f543 | 377 | /* Prototypes for exported functions. */ |
c906108c | 378 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 379 | if such is available. */ |
c906108c SS |
380 | static int can_use_hw_watchpoints; |
381 | ||
920d2a44 AC |
382 | static void |
383 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
384 | struct cmd_list_element *c, | |
385 | const char *value) | |
386 | { | |
3e43a32a MS |
387 | fprintf_filtered (file, |
388 | _("Debugger's willingness to use " | |
389 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
390 | value); |
391 | } | |
392 | ||
fa8d40ab JJ |
393 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
394 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 395 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
396 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
397 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
398 | static void |
399 | show_pending_break_support (struct ui_file *file, int from_tty, | |
400 | struct cmd_list_element *c, | |
401 | const char *value) | |
402 | { | |
3e43a32a MS |
403 | fprintf_filtered (file, |
404 | _("Debugger's behavior regarding " | |
405 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
406 | value); |
407 | } | |
fa8d40ab | 408 | |
765dc015 | 409 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 410 | set with "break" but falling in read-only memory. |
765dc015 VP |
411 | If 0, gdb will warn about such breakpoints, but won't automatically |
412 | use hardware breakpoints. */ | |
413 | static int automatic_hardware_breakpoints; | |
414 | static void | |
415 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
416 | struct cmd_list_element *c, | |
417 | const char *value) | |
418 | { | |
3e43a32a MS |
419 | fprintf_filtered (file, |
420 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
421 | value); |
422 | } | |
423 | ||
33e5cbd6 PA |
424 | /* If on, gdb will keep breakpoints inserted even as inferior is |
425 | stopped, and immediately insert any new breakpoints. If off, gdb | |
426 | will insert breakpoints into inferior only when resuming it, and | |
427 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
428 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
429 | ||
72d0e2c5 YQ |
430 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
431 | ||
33e5cbd6 | 432 | static void |
74960c60 | 433 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 434 | struct cmd_list_element *c, const char *value) |
74960c60 | 435 | { |
72d0e2c5 | 436 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
437 | fprintf_filtered (file, |
438 | _("Always inserted breakpoint " | |
439 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
440 | value, |
441 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
442 | else | |
3e43a32a MS |
443 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
444 | value); | |
74960c60 VP |
445 | } |
446 | ||
33e5cbd6 PA |
447 | int |
448 | breakpoints_always_inserted_mode (void) | |
449 | { | |
72d0e2c5 YQ |
450 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
451 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 452 | } |
765dc015 | 453 | |
b775012e LM |
454 | static const char condition_evaluation_both[] = "host or target"; |
455 | ||
456 | /* Modes for breakpoint condition evaluation. */ | |
457 | static const char condition_evaluation_auto[] = "auto"; | |
458 | static const char condition_evaluation_host[] = "host"; | |
459 | static const char condition_evaluation_target[] = "target"; | |
460 | static const char *const condition_evaluation_enums[] = { | |
461 | condition_evaluation_auto, | |
462 | condition_evaluation_host, | |
463 | condition_evaluation_target, | |
464 | NULL | |
465 | }; | |
466 | ||
467 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
468 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
469 | ||
470 | /* Global that we use to display information to the user (gets its value from | |
471 | condition_evaluation_mode_1. */ | |
472 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
473 | ||
474 | /* Translate a condition evaluation mode MODE into either "host" | |
475 | or "target". This is used mostly to translate from "auto" to the | |
476 | real setting that is being used. It returns the translated | |
477 | evaluation mode. */ | |
478 | ||
479 | static const char * | |
480 | translate_condition_evaluation_mode (const char *mode) | |
481 | { | |
482 | if (mode == condition_evaluation_auto) | |
483 | { | |
484 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
485 | return condition_evaluation_target; | |
486 | else | |
487 | return condition_evaluation_host; | |
488 | } | |
489 | else | |
490 | return mode; | |
491 | } | |
492 | ||
493 | /* Discovers what condition_evaluation_auto translates to. */ | |
494 | ||
495 | static const char * | |
496 | breakpoint_condition_evaluation_mode (void) | |
497 | { | |
498 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
499 | } | |
500 | ||
501 | /* Return true if GDB should evaluate breakpoint conditions or false | |
502 | otherwise. */ | |
503 | ||
504 | static int | |
505 | gdb_evaluates_breakpoint_condition_p (void) | |
506 | { | |
507 | const char *mode = breakpoint_condition_evaluation_mode (); | |
508 | ||
509 | return (mode == condition_evaluation_host); | |
510 | } | |
511 | ||
a14ed312 | 512 | void _initialize_breakpoint (void); |
c906108c | 513 | |
c906108c SS |
514 | /* Are we executing breakpoint commands? */ |
515 | static int executing_breakpoint_commands; | |
516 | ||
c02f5703 MS |
517 | /* Are overlay event breakpoints enabled? */ |
518 | static int overlay_events_enabled; | |
519 | ||
e09342b5 TJB |
520 | /* See description in breakpoint.h. */ |
521 | int target_exact_watchpoints = 0; | |
522 | ||
c906108c | 523 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 524 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 525 | current breakpoint. */ |
c906108c | 526 | |
5c44784c | 527 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 528 | |
5c44784c JM |
529 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
530 | for (B = breakpoint_chain; \ | |
531 | B ? (TMP=B->next, 1): 0; \ | |
532 | B = TMP) | |
c906108c | 533 | |
4a64f543 MS |
534 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
535 | not provided so update_global_location_list must not be called | |
536 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 537 | |
876fa593 JK |
538 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
539 | for (BP_TMP = bp_location; \ | |
540 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
541 | BP_TMP++) | |
7cc221ef | 542 | |
b775012e LM |
543 | /* Iterates through locations with address ADDRESS for the currently selected |
544 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
545 | to where the loop should start from. | |
546 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
547 | appropriate location to start with. */ | |
548 | ||
549 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
550 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
551 | BP_LOCP_TMP = BP_LOCP_START; \ | |
552 | BP_LOCP_START \ | |
553 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
554 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
555 | BP_LOCP_TMP++) | |
556 | ||
1042e4c0 SS |
557 | /* Iterator for tracepoints only. */ |
558 | ||
559 | #define ALL_TRACEPOINTS(B) \ | |
560 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 561 | if (is_tracepoint (B)) |
1042e4c0 | 562 | |
7cc221ef | 563 | /* Chains of all breakpoints defined. */ |
c906108c SS |
564 | |
565 | struct breakpoint *breakpoint_chain; | |
566 | ||
876fa593 JK |
567 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
568 | ||
569 | static struct bp_location **bp_location; | |
570 | ||
571 | /* Number of elements of BP_LOCATION. */ | |
572 | ||
573 | static unsigned bp_location_count; | |
574 | ||
4a64f543 MS |
575 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
576 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
577 | result from bp_location_has_shadow. You can use it for roughly | |
578 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
579 | an address you need to read. */ | |
876fa593 JK |
580 | |
581 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
582 | ||
4a64f543 MS |
583 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
584 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
585 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
586 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
587 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
588 | |
589 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 590 | |
4a64f543 MS |
591 | /* The locations that no longer correspond to any breakpoint, unlinked |
592 | from bp_location array, but for which a hit may still be reported | |
593 | by a target. */ | |
20874c92 VP |
594 | VEC(bp_location_p) *moribund_locations = NULL; |
595 | ||
c906108c SS |
596 | /* Number of last breakpoint made. */ |
597 | ||
95a42b64 TT |
598 | static int breakpoint_count; |
599 | ||
86b17b60 PA |
600 | /* The value of `breakpoint_count' before the last command that |
601 | created breakpoints. If the last (break-like) command created more | |
602 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
603 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
604 | static int prev_breakpoint_count; | |
c906108c | 605 | |
1042e4c0 SS |
606 | /* Number of last tracepoint made. */ |
607 | ||
95a42b64 | 608 | static int tracepoint_count; |
1042e4c0 | 609 | |
6149aea9 PA |
610 | static struct cmd_list_element *breakpoint_set_cmdlist; |
611 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 612 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 613 | |
468d015d JJ |
614 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
615 | static int | |
616 | breakpoint_enabled (struct breakpoint *b) | |
617 | { | |
0d381245 | 618 | return (b->enable_state == bp_enabled); |
468d015d JJ |
619 | } |
620 | ||
c906108c SS |
621 | /* Set breakpoint count to NUM. */ |
622 | ||
95a42b64 | 623 | static void |
fba45db2 | 624 | set_breakpoint_count (int num) |
c906108c | 625 | { |
86b17b60 | 626 | prev_breakpoint_count = breakpoint_count; |
c906108c | 627 | breakpoint_count = num; |
4fa62494 | 628 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
629 | } |
630 | ||
86b17b60 PA |
631 | /* Used by `start_rbreak_breakpoints' below, to record the current |
632 | breakpoint count before "rbreak" creates any breakpoint. */ | |
633 | static int rbreak_start_breakpoint_count; | |
634 | ||
95a42b64 TT |
635 | /* Called at the start an "rbreak" command to record the first |
636 | breakpoint made. */ | |
86b17b60 | 637 | |
95a42b64 TT |
638 | void |
639 | start_rbreak_breakpoints (void) | |
640 | { | |
86b17b60 | 641 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
642 | } |
643 | ||
644 | /* Called at the end of an "rbreak" command to record the last | |
645 | breakpoint made. */ | |
86b17b60 | 646 | |
95a42b64 TT |
647 | void |
648 | end_rbreak_breakpoints (void) | |
649 | { | |
86b17b60 | 650 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
651 | } |
652 | ||
4a64f543 | 653 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
654 | |
655 | void | |
fba45db2 | 656 | clear_breakpoint_hit_counts (void) |
c906108c SS |
657 | { |
658 | struct breakpoint *b; | |
659 | ||
660 | ALL_BREAKPOINTS (b) | |
661 | b->hit_count = 0; | |
662 | } | |
663 | ||
9add0f1b TT |
664 | /* Allocate a new counted_command_line with reference count of 1. |
665 | The new structure owns COMMANDS. */ | |
666 | ||
667 | static struct counted_command_line * | |
668 | alloc_counted_command_line (struct command_line *commands) | |
669 | { | |
670 | struct counted_command_line *result | |
671 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 672 | |
9add0f1b TT |
673 | result->refc = 1; |
674 | result->commands = commands; | |
675 | return result; | |
676 | } | |
677 | ||
678 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
679 | ||
680 | static void | |
681 | incref_counted_command_line (struct counted_command_line *cmd) | |
682 | { | |
683 | if (cmd) | |
684 | ++cmd->refc; | |
685 | } | |
686 | ||
687 | /* Decrement reference count. If the reference count reaches 0, | |
688 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
689 | nothing if *CMDP is NULL. */ | |
690 | ||
691 | static void | |
692 | decref_counted_command_line (struct counted_command_line **cmdp) | |
693 | { | |
694 | if (*cmdp) | |
695 | { | |
696 | if (--(*cmdp)->refc == 0) | |
697 | { | |
698 | free_command_lines (&(*cmdp)->commands); | |
699 | xfree (*cmdp); | |
700 | } | |
701 | *cmdp = NULL; | |
702 | } | |
703 | } | |
704 | ||
705 | /* A cleanup function that calls decref_counted_command_line. */ | |
706 | ||
707 | static void | |
708 | do_cleanup_counted_command_line (void *arg) | |
709 | { | |
710 | decref_counted_command_line (arg); | |
711 | } | |
712 | ||
713 | /* Create a cleanup that calls decref_counted_command_line on the | |
714 | argument. */ | |
715 | ||
716 | static struct cleanup * | |
717 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
718 | { | |
719 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
720 | } | |
721 | ||
c906108c | 722 | \f |
48cb2d85 VP |
723 | /* Return the breakpoint with the specified number, or NULL |
724 | if the number does not refer to an existing breakpoint. */ | |
725 | ||
726 | struct breakpoint * | |
727 | get_breakpoint (int num) | |
728 | { | |
729 | struct breakpoint *b; | |
730 | ||
731 | ALL_BREAKPOINTS (b) | |
732 | if (b->number == num) | |
733 | return b; | |
734 | ||
735 | return NULL; | |
736 | } | |
5c44784c | 737 | |
c906108c | 738 | \f |
adc36818 | 739 | |
b775012e LM |
740 | /* Mark locations as "conditions have changed" in case the target supports |
741 | evaluating conditions on its side. */ | |
742 | ||
743 | static void | |
744 | mark_breakpoint_modified (struct breakpoint *b) | |
745 | { | |
746 | struct bp_location *loc; | |
747 | ||
748 | /* This is only meaningful if the target is | |
749 | evaluating conditions and if the user has | |
750 | opted for condition evaluation on the target's | |
751 | side. */ | |
752 | if (gdb_evaluates_breakpoint_condition_p () | |
753 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
754 | return; | |
755 | ||
756 | if (!is_breakpoint (b)) | |
757 | return; | |
758 | ||
759 | for (loc = b->loc; loc; loc = loc->next) | |
760 | loc->condition_changed = condition_modified; | |
761 | } | |
762 | ||
763 | /* Mark location as "conditions have changed" in case the target supports | |
764 | evaluating conditions on its side. */ | |
765 | ||
766 | static void | |
767 | mark_breakpoint_location_modified (struct bp_location *loc) | |
768 | { | |
769 | /* This is only meaningful if the target is | |
770 | evaluating conditions and if the user has | |
771 | opted for condition evaluation on the target's | |
772 | side. */ | |
773 | if (gdb_evaluates_breakpoint_condition_p () | |
774 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
775 | ||
776 | return; | |
777 | ||
778 | if (!is_breakpoint (loc->owner)) | |
779 | return; | |
780 | ||
781 | loc->condition_changed = condition_modified; | |
782 | } | |
783 | ||
784 | /* Sets the condition-evaluation mode using the static global | |
785 | condition_evaluation_mode. */ | |
786 | ||
787 | static void | |
788 | set_condition_evaluation_mode (char *args, int from_tty, | |
789 | struct cmd_list_element *c) | |
790 | { | |
b775012e LM |
791 | const char *old_mode, *new_mode; |
792 | ||
793 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
794 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
795 | { | |
796 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
797 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
798 | "Using host evaluation mode instead.")); | |
799 | return; | |
800 | } | |
801 | ||
802 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
803 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
804 | ||
abf1152a JK |
805 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
806 | settings was "auto". */ | |
807 | condition_evaluation_mode = condition_evaluation_mode_1; | |
808 | ||
b775012e LM |
809 | /* Only update the mode if the user picked a different one. */ |
810 | if (new_mode != old_mode) | |
811 | { | |
812 | struct bp_location *loc, **loc_tmp; | |
813 | /* If the user switched to a different evaluation mode, we | |
814 | need to synch the changes with the target as follows: | |
815 | ||
816 | "host" -> "target": Send all (valid) conditions to the target. | |
817 | "target" -> "host": Remove all the conditions from the target. | |
818 | */ | |
819 | ||
b775012e LM |
820 | if (new_mode == condition_evaluation_target) |
821 | { | |
822 | /* Mark everything modified and synch conditions with the | |
823 | target. */ | |
824 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
825 | mark_breakpoint_location_modified (loc); | |
826 | } | |
827 | else | |
828 | { | |
829 | /* Manually mark non-duplicate locations to synch conditions | |
830 | with the target. We do this to remove all the conditions the | |
831 | target knows about. */ | |
832 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
833 | if (is_breakpoint (loc->owner) && loc->inserted) | |
834 | loc->needs_update = 1; | |
835 | } | |
836 | ||
837 | /* Do the update. */ | |
838 | update_global_location_list (1); | |
839 | } | |
840 | ||
841 | return; | |
842 | } | |
843 | ||
844 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
845 | what "auto" is translating to. */ | |
846 | ||
847 | static void | |
848 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
849 | struct cmd_list_element *c, const char *value) | |
850 | { | |
851 | if (condition_evaluation_mode == condition_evaluation_auto) | |
852 | fprintf_filtered (file, | |
853 | _("Breakpoint condition evaluation " | |
854 | "mode is %s (currently %s).\n"), | |
855 | value, | |
856 | breakpoint_condition_evaluation_mode ()); | |
857 | else | |
858 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
859 | value); | |
860 | } | |
861 | ||
862 | /* A comparison function for bp_location AP and BP that is used by | |
863 | bsearch. This comparison function only cares about addresses, unlike | |
864 | the more general bp_location_compare function. */ | |
865 | ||
866 | static int | |
867 | bp_location_compare_addrs (const void *ap, const void *bp) | |
868 | { | |
869 | struct bp_location *a = *(void **) ap; | |
870 | struct bp_location *b = *(void **) bp; | |
871 | ||
872 | if (a->address == b->address) | |
873 | return 0; | |
874 | else | |
875 | return ((a->address > b->address) - (a->address < b->address)); | |
876 | } | |
877 | ||
878 | /* Helper function to skip all bp_locations with addresses | |
879 | less than ADDRESS. It returns the first bp_location that | |
880 | is greater than or equal to ADDRESS. If none is found, just | |
881 | return NULL. */ | |
882 | ||
883 | static struct bp_location ** | |
884 | get_first_locp_gte_addr (CORE_ADDR address) | |
885 | { | |
886 | struct bp_location dummy_loc; | |
887 | struct bp_location *dummy_locp = &dummy_loc; | |
888 | struct bp_location **locp_found = NULL; | |
889 | ||
890 | /* Initialize the dummy location's address field. */ | |
891 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
892 | dummy_loc.address = address; | |
893 | ||
894 | /* Find a close match to the first location at ADDRESS. */ | |
895 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
896 | sizeof (struct bp_location **), | |
897 | bp_location_compare_addrs); | |
898 | ||
899 | /* Nothing was found, nothing left to do. */ | |
900 | if (locp_found == NULL) | |
901 | return NULL; | |
902 | ||
903 | /* We may have found a location that is at ADDRESS but is not the first in the | |
904 | location's list. Go backwards (if possible) and locate the first one. */ | |
905 | while ((locp_found - 1) >= bp_location | |
906 | && (*(locp_found - 1))->address == address) | |
907 | locp_found--; | |
908 | ||
909 | return locp_found; | |
910 | } | |
911 | ||
adc36818 PM |
912 | void |
913 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
914 | int from_tty) | |
915 | { | |
3a5c3e22 PA |
916 | xfree (b->cond_string); |
917 | b->cond_string = NULL; | |
adc36818 | 918 | |
3a5c3e22 | 919 | if (is_watchpoint (b)) |
adc36818 | 920 | { |
3a5c3e22 PA |
921 | struct watchpoint *w = (struct watchpoint *) b; |
922 | ||
923 | xfree (w->cond_exp); | |
924 | w->cond_exp = NULL; | |
925 | } | |
926 | else | |
927 | { | |
928 | struct bp_location *loc; | |
929 | ||
930 | for (loc = b->loc; loc; loc = loc->next) | |
931 | { | |
932 | xfree (loc->cond); | |
933 | loc->cond = NULL; | |
b775012e LM |
934 | |
935 | /* No need to free the condition agent expression | |
936 | bytecode (if we have one). We will handle this | |
937 | when we go through update_global_location_list. */ | |
3a5c3e22 | 938 | } |
adc36818 | 939 | } |
adc36818 PM |
940 | |
941 | if (*exp == 0) | |
942 | { | |
943 | if (from_tty) | |
944 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
945 | } | |
946 | else | |
947 | { | |
bbc13ae3 | 948 | const char *arg = exp; |
cc59ec59 | 949 | |
adc36818 PM |
950 | /* I don't know if it matters whether this is the string the user |
951 | typed in or the decompiled expression. */ | |
952 | b->cond_string = xstrdup (arg); | |
953 | b->condition_not_parsed = 0; | |
954 | ||
955 | if (is_watchpoint (b)) | |
956 | { | |
3a5c3e22 PA |
957 | struct watchpoint *w = (struct watchpoint *) b; |
958 | ||
adc36818 PM |
959 | innermost_block = NULL; |
960 | arg = exp; | |
1bb9788d | 961 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
962 | if (*arg) |
963 | error (_("Junk at end of expression")); | |
3a5c3e22 | 964 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
965 | } |
966 | else | |
967 | { | |
3a5c3e22 PA |
968 | struct bp_location *loc; |
969 | ||
adc36818 PM |
970 | for (loc = b->loc; loc; loc = loc->next) |
971 | { | |
972 | arg = exp; | |
973 | loc->cond = | |
1bb9788d TT |
974 | parse_exp_1 (&arg, loc->address, |
975 | block_for_pc (loc->address), 0); | |
adc36818 PM |
976 | if (*arg) |
977 | error (_("Junk at end of expression")); | |
978 | } | |
979 | } | |
980 | } | |
b775012e LM |
981 | mark_breakpoint_modified (b); |
982 | ||
8d3788bd | 983 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
984 | } |
985 | ||
d55637df TT |
986 | /* Completion for the "condition" command. */ |
987 | ||
988 | static VEC (char_ptr) * | |
6f937416 PA |
989 | condition_completer (struct cmd_list_element *cmd, |
990 | const char *text, const char *word) | |
d55637df | 991 | { |
6f937416 | 992 | const char *space; |
d55637df | 993 | |
6f937416 PA |
994 | text = skip_spaces_const (text); |
995 | space = skip_to_space_const (text); | |
d55637df TT |
996 | if (*space == '\0') |
997 | { | |
998 | int len; | |
999 | struct breakpoint *b; | |
1000 | VEC (char_ptr) *result = NULL; | |
1001 | ||
1002 | if (text[0] == '$') | |
1003 | { | |
1004 | /* We don't support completion of history indices. */ | |
1005 | if (isdigit (text[1])) | |
1006 | return NULL; | |
1007 | return complete_internalvar (&text[1]); | |
1008 | } | |
1009 | ||
1010 | /* We're completing the breakpoint number. */ | |
1011 | len = strlen (text); | |
1012 | ||
1013 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1014 | { |
1015 | char number[50]; | |
1016 | ||
1017 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1018 | ||
1019 | if (strncmp (number, text, len) == 0) | |
1020 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1021 | } | |
d55637df TT |
1022 | |
1023 | return result; | |
1024 | } | |
1025 | ||
1026 | /* We're completing the expression part. */ | |
6f937416 | 1027 | text = skip_spaces_const (space); |
d55637df TT |
1028 | return expression_completer (cmd, text, word); |
1029 | } | |
1030 | ||
c906108c SS |
1031 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1032 | ||
1033 | static void | |
fba45db2 | 1034 | condition_command (char *arg, int from_tty) |
c906108c | 1035 | { |
52f0bd74 | 1036 | struct breakpoint *b; |
c906108c | 1037 | char *p; |
52f0bd74 | 1038 | int bnum; |
c906108c SS |
1039 | |
1040 | if (arg == 0) | |
e2e0b3e5 | 1041 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1042 | |
1043 | p = arg; | |
1044 | bnum = get_number (&p); | |
5c44784c | 1045 | if (bnum == 0) |
8a3fe4f8 | 1046 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1047 | |
1048 | ALL_BREAKPOINTS (b) | |
1049 | if (b->number == bnum) | |
2f069f6f | 1050 | { |
7371cf6d PM |
1051 | /* Check if this breakpoint has a Python object assigned to |
1052 | it, and if it has a definition of the "stop" | |
1053 | method. This method and conditions entered into GDB from | |
1054 | the CLI are mutually exclusive. */ | |
1055 | if (b->py_bp_object | |
1056 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
1057 | error (_("Cannot set a condition where a Python 'stop' " | |
1058 | "method has been defined in the breakpoint.")); | |
2566ad2d | 1059 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1060 | |
1061 | if (is_breakpoint (b)) | |
1062 | update_global_location_list (1); | |
1063 | ||
2f069f6f JB |
1064 | return; |
1065 | } | |
c906108c | 1066 | |
8a3fe4f8 | 1067 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1068 | } |
1069 | ||
a7bdde9e VP |
1070 | /* Check that COMMAND do not contain commands that are suitable |
1071 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1072 | Throw if any such commands is found. */ |
1073 | ||
a7bdde9e VP |
1074 | static void |
1075 | check_no_tracepoint_commands (struct command_line *commands) | |
1076 | { | |
1077 | struct command_line *c; | |
cc59ec59 | 1078 | |
a7bdde9e VP |
1079 | for (c = commands; c; c = c->next) |
1080 | { | |
1081 | int i; | |
1082 | ||
1083 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1084 | error (_("The 'while-stepping' command can " |
1085 | "only be used for tracepoints")); | |
a7bdde9e VP |
1086 | |
1087 | for (i = 0; i < c->body_count; ++i) | |
1088 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1089 | ||
1090 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1091 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1092 | command directly. */ |
1093 | if (strstr (c->line, "collect ") == c->line) | |
1094 | error (_("The 'collect' command can only be used for tracepoints")); | |
1095 | ||
51661e93 VP |
1096 | if (strstr (c->line, "teval ") == c->line) |
1097 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1098 | } |
1099 | } | |
1100 | ||
d77f58be SS |
1101 | /* Encapsulate tests for different types of tracepoints. */ |
1102 | ||
d9b3f62e PA |
1103 | static int |
1104 | is_tracepoint_type (enum bptype type) | |
1105 | { | |
1106 | return (type == bp_tracepoint | |
1107 | || type == bp_fast_tracepoint | |
1108 | || type == bp_static_tracepoint); | |
1109 | } | |
1110 | ||
a7bdde9e | 1111 | int |
d77f58be | 1112 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1113 | { |
d9b3f62e | 1114 | return is_tracepoint_type (b->type); |
a7bdde9e | 1115 | } |
d9b3f62e | 1116 | |
e5dd4106 | 1117 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1118 | breakpoint. This function will throw an exception if a problem is |
1119 | found. */ | |
48cb2d85 | 1120 | |
95a42b64 TT |
1121 | static void |
1122 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1123 | struct command_line *commands) | |
48cb2d85 | 1124 | { |
d77f58be | 1125 | if (is_tracepoint (b)) |
a7bdde9e | 1126 | { |
c9a6ce02 | 1127 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1128 | struct command_line *c; |
1129 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1130 | |
1131 | /* Reset the while-stepping step count. The previous commands | |
1132 | might have included a while-stepping action, while the new | |
1133 | ones might not. */ | |
1134 | t->step_count = 0; | |
1135 | ||
1136 | /* We need to verify that each top-level element of commands is | |
1137 | valid for tracepoints, that there's at most one | |
1138 | while-stepping element, and that the while-stepping's body | |
1139 | has valid tracing commands excluding nested while-stepping. | |
1140 | We also need to validate the tracepoint action line in the | |
1141 | context of the tracepoint --- validate_actionline actually | |
1142 | has side effects, like setting the tracepoint's | |
1143 | while-stepping STEP_COUNT, in addition to checking if the | |
1144 | collect/teval actions parse and make sense in the | |
1145 | tracepoint's context. */ | |
a7bdde9e VP |
1146 | for (c = commands; c; c = c->next) |
1147 | { | |
a7bdde9e VP |
1148 | if (c->control_type == while_stepping_control) |
1149 | { | |
1150 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1151 | error (_("The 'while-stepping' command " |
1152 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1153 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1154 | error (_("The 'while-stepping' command " |
1155 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1156 | |
1157 | if (while_stepping) | |
3e43a32a MS |
1158 | error (_("The 'while-stepping' command " |
1159 | "can be used only once")); | |
a7bdde9e VP |
1160 | else |
1161 | while_stepping = c; | |
1162 | } | |
c9a6ce02 PA |
1163 | |
1164 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1165 | } |
1166 | if (while_stepping) | |
1167 | { | |
1168 | struct command_line *c2; | |
1169 | ||
1170 | gdb_assert (while_stepping->body_count == 1); | |
1171 | c2 = while_stepping->body_list[0]; | |
1172 | for (; c2; c2 = c2->next) | |
1173 | { | |
a7bdde9e VP |
1174 | if (c2->control_type == while_stepping_control) |
1175 | error (_("The 'while-stepping' command cannot be nested")); | |
1176 | } | |
1177 | } | |
1178 | } | |
1179 | else | |
1180 | { | |
1181 | check_no_tracepoint_commands (commands); | |
1182 | } | |
95a42b64 TT |
1183 | } |
1184 | ||
0fb4aa4b PA |
1185 | /* Return a vector of all the static tracepoints set at ADDR. The |
1186 | caller is responsible for releasing the vector. */ | |
1187 | ||
1188 | VEC(breakpoint_p) * | |
1189 | static_tracepoints_here (CORE_ADDR addr) | |
1190 | { | |
1191 | struct breakpoint *b; | |
1192 | VEC(breakpoint_p) *found = 0; | |
1193 | struct bp_location *loc; | |
1194 | ||
1195 | ALL_BREAKPOINTS (b) | |
1196 | if (b->type == bp_static_tracepoint) | |
1197 | { | |
1198 | for (loc = b->loc; loc; loc = loc->next) | |
1199 | if (loc->address == addr) | |
1200 | VEC_safe_push(breakpoint_p, found, b); | |
1201 | } | |
1202 | ||
1203 | return found; | |
1204 | } | |
1205 | ||
95a42b64 | 1206 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1207 | validate that only allowed commands are included. */ |
95a42b64 TT |
1208 | |
1209 | void | |
4a64f543 MS |
1210 | breakpoint_set_commands (struct breakpoint *b, |
1211 | struct command_line *commands) | |
95a42b64 TT |
1212 | { |
1213 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1214 | |
9add0f1b TT |
1215 | decref_counted_command_line (&b->commands); |
1216 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1217 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1218 | } |
1219 | ||
45a43567 TT |
1220 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1221 | is not the same as the "silent" that may appear in the breakpoint's | |
1222 | commands. */ | |
1223 | ||
1224 | void | |
1225 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1226 | { | |
1227 | int old_silent = b->silent; | |
1228 | ||
1229 | b->silent = silent; | |
1230 | if (old_silent != silent) | |
8d3788bd | 1231 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1232 | } |
1233 | ||
1234 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1235 | breakpoint work for any thread. */ | |
1236 | ||
1237 | void | |
1238 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1239 | { | |
1240 | int old_thread = b->thread; | |
1241 | ||
1242 | b->thread = thread; | |
1243 | if (old_thread != thread) | |
8d3788bd | 1244 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1245 | } |
1246 | ||
1247 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1248 | breakpoint work for any task. */ | |
1249 | ||
1250 | void | |
1251 | breakpoint_set_task (struct breakpoint *b, int task) | |
1252 | { | |
1253 | int old_task = b->task; | |
1254 | ||
1255 | b->task = task; | |
1256 | if (old_task != task) | |
8d3788bd | 1257 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1258 | } |
1259 | ||
95a42b64 TT |
1260 | void |
1261 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1262 | { |
1263 | struct breakpoint *b = closure; | |
cc59ec59 | 1264 | |
6f937416 | 1265 | validate_actionline (line, b); |
a7bdde9e VP |
1266 | } |
1267 | ||
95a42b64 TT |
1268 | /* A structure used to pass information through |
1269 | map_breakpoint_numbers. */ | |
1270 | ||
1271 | struct commands_info | |
1272 | { | |
1273 | /* True if the command was typed at a tty. */ | |
1274 | int from_tty; | |
86b17b60 PA |
1275 | |
1276 | /* The breakpoint range spec. */ | |
1277 | char *arg; | |
1278 | ||
95a42b64 TT |
1279 | /* Non-NULL if the body of the commands are being read from this |
1280 | already-parsed command. */ | |
1281 | struct command_line *control; | |
86b17b60 | 1282 | |
95a42b64 TT |
1283 | /* The command lines read from the user, or NULL if they have not |
1284 | yet been read. */ | |
1285 | struct counted_command_line *cmd; | |
1286 | }; | |
1287 | ||
1288 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1289 | commands_command. */ | |
1290 | ||
c906108c | 1291 | static void |
95a42b64 | 1292 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1293 | { |
95a42b64 | 1294 | struct commands_info *info = data; |
c906108c | 1295 | |
95a42b64 TT |
1296 | if (info->cmd == NULL) |
1297 | { | |
1298 | struct command_line *l; | |
5c44784c | 1299 | |
95a42b64 TT |
1300 | if (info->control != NULL) |
1301 | l = copy_command_lines (info->control->body_list[0]); | |
1302 | else | |
86b17b60 PA |
1303 | { |
1304 | struct cleanup *old_chain; | |
1305 | char *str; | |
c5aa993b | 1306 | |
3e43a32a MS |
1307 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1308 | "%s, one per line."), | |
86b17b60 PA |
1309 | info->arg); |
1310 | ||
1311 | old_chain = make_cleanup (xfree, str); | |
1312 | ||
1313 | l = read_command_lines (str, | |
1314 | info->from_tty, 1, | |
d77f58be | 1315 | (is_tracepoint (b) |
86b17b60 PA |
1316 | ? check_tracepoint_command : 0), |
1317 | b); | |
1318 | ||
1319 | do_cleanups (old_chain); | |
1320 | } | |
a7bdde9e | 1321 | |
95a42b64 TT |
1322 | info->cmd = alloc_counted_command_line (l); |
1323 | } | |
1324 | ||
1325 | /* If a breakpoint was on the list more than once, we don't need to | |
1326 | do anything. */ | |
1327 | if (b->commands != info->cmd) | |
1328 | { | |
1329 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1330 | incref_counted_command_line (info->cmd); | |
1331 | decref_counted_command_line (&b->commands); | |
1332 | b->commands = info->cmd; | |
8d3788bd | 1333 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1334 | } |
95a42b64 TT |
1335 | } |
1336 | ||
1337 | static void | |
4a64f543 MS |
1338 | commands_command_1 (char *arg, int from_tty, |
1339 | struct command_line *control) | |
95a42b64 TT |
1340 | { |
1341 | struct cleanup *cleanups; | |
1342 | struct commands_info info; | |
1343 | ||
1344 | info.from_tty = from_tty; | |
1345 | info.control = control; | |
1346 | info.cmd = NULL; | |
1347 | /* If we read command lines from the user, then `info' will hold an | |
1348 | extra reference to the commands that we must clean up. */ | |
1349 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1350 | ||
1351 | if (arg == NULL || !*arg) | |
1352 | { | |
86b17b60 | 1353 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1354 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1355 | breakpoint_count); | |
95a42b64 TT |
1356 | else if (breakpoint_count > 0) |
1357 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1358 | else |
1359 | { | |
1360 | /* So that we don't try to free the incoming non-NULL | |
1361 | argument in the cleanup below. Mapping breakpoint | |
1362 | numbers will fail in this case. */ | |
1363 | arg = NULL; | |
1364 | } | |
95a42b64 | 1365 | } |
9766ced4 SS |
1366 | else |
1367 | /* The command loop has some static state, so we need to preserve | |
1368 | our argument. */ | |
1369 | arg = xstrdup (arg); | |
86b17b60 PA |
1370 | |
1371 | if (arg != NULL) | |
1372 | make_cleanup (xfree, arg); | |
1373 | ||
1374 | info.arg = arg; | |
95a42b64 TT |
1375 | |
1376 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1377 | ||
1378 | if (info.cmd == NULL) | |
1379 | error (_("No breakpoints specified.")); | |
1380 | ||
1381 | do_cleanups (cleanups); | |
1382 | } | |
1383 | ||
1384 | static void | |
1385 | commands_command (char *arg, int from_tty) | |
1386 | { | |
1387 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1388 | } |
40c03ae8 EZ |
1389 | |
1390 | /* Like commands_command, but instead of reading the commands from | |
1391 | input stream, takes them from an already parsed command structure. | |
1392 | ||
1393 | This is used by cli-script.c to DTRT with breakpoint commands | |
1394 | that are part of if and while bodies. */ | |
1395 | enum command_control_type | |
1396 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1397 | { | |
95a42b64 TT |
1398 | commands_command_1 (arg, 0, cmd); |
1399 | return simple_control; | |
40c03ae8 | 1400 | } |
876fa593 JK |
1401 | |
1402 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1403 | ||
1404 | static int | |
1405 | bp_location_has_shadow (struct bp_location *bl) | |
1406 | { | |
1407 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1408 | return 0; | |
1409 | if (!bl->inserted) | |
1410 | return 0; | |
1411 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1412 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1413 | return 0; |
1414 | return 1; | |
1415 | } | |
1416 | ||
8defab1a | 1417 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1418 | by replacing any memory breakpoints with their shadowed contents. |
1419 | ||
35c63cd8 JB |
1420 | If READBUF is not NULL, this buffer must not overlap with any of |
1421 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1422 | a failed assertion internal error will be raised. | |
1423 | ||
876fa593 | 1424 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1425 | bl->address - bp_location_placed_address_before_address_max |
1426 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1427 | The range we were requested to resolve shadows for is: |
1428 | memaddr ... memaddr + len | |
1429 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1430 | memaddr + len <= (bl->address |
1431 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1432 | and: |
35df4500 | 1433 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1434 | |
8defab1a | 1435 | void |
f0ba3972 PA |
1436 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1437 | const gdb_byte *writebuf_org, | |
1438 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1439 | { |
4a64f543 MS |
1440 | /* Left boundary, right boundary and median element of our binary |
1441 | search. */ | |
876fa593 JK |
1442 | unsigned bc_l, bc_r, bc; |
1443 | ||
4a64f543 MS |
1444 | /* Find BC_L which is a leftmost element which may affect BUF |
1445 | content. It is safe to report lower value but a failure to | |
1446 | report higher one. */ | |
876fa593 JK |
1447 | |
1448 | bc_l = 0; | |
1449 | bc_r = bp_location_count; | |
1450 | while (bc_l + 1 < bc_r) | |
1451 | { | |
35df4500 | 1452 | struct bp_location *bl; |
876fa593 JK |
1453 | |
1454 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1455 | bl = bp_location[bc]; |
876fa593 | 1456 | |
4a64f543 MS |
1457 | /* Check first BL->ADDRESS will not overflow due to the added |
1458 | constant. Then advance the left boundary only if we are sure | |
1459 | the BC element can in no way affect the BUF content (MEMADDR | |
1460 | to MEMADDR + LEN range). | |
876fa593 | 1461 | |
4a64f543 MS |
1462 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1463 | offset so that we cannot miss a breakpoint with its shadow | |
1464 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1465 | |
35df4500 TJB |
1466 | if ((bl->address + bp_location_shadow_len_after_address_max |
1467 | >= bl->address) | |
1468 | && (bl->address + bp_location_shadow_len_after_address_max | |
1469 | <= memaddr)) | |
876fa593 JK |
1470 | bc_l = bc; |
1471 | else | |
1472 | bc_r = bc; | |
1473 | } | |
1474 | ||
128070bb PA |
1475 | /* Due to the binary search above, we need to make sure we pick the |
1476 | first location that's at BC_L's address. E.g., if there are | |
1477 | multiple locations at the same address, BC_L may end up pointing | |
1478 | at a duplicate location, and miss the "master"/"inserted" | |
1479 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1480 | B: | |
1481 | ||
1482 | L1@A, L2@A, L3@B, ... | |
1483 | ||
1484 | BC_L could end up pointing at location L2, while the "master" | |
1485 | location could be L1. Since the `loc->inserted' flag is only set | |
1486 | on "master" locations, we'd forget to restore the shadow of L1 | |
1487 | and L2. */ | |
1488 | while (bc_l > 0 | |
1489 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1490 | bc_l--; | |
1491 | ||
876fa593 JK |
1492 | /* Now do full processing of the found relevant range of elements. */ |
1493 | ||
1494 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1495 | { |
35df4500 | 1496 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1497 | CORE_ADDR bp_addr = 0; |
1498 | int bp_size = 0; | |
1499 | int bptoffset = 0; | |
1500 | ||
35df4500 TJB |
1501 | /* bp_location array has BL->OWNER always non-NULL. */ |
1502 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1503 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1504 | bl->owner->number); |
ffce0d52 | 1505 | |
e5dd4106 | 1506 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1507 | content. */ |
1508 | ||
35df4500 TJB |
1509 | if (bl->address >= bp_location_placed_address_before_address_max |
1510 | && memaddr + len <= (bl->address | |
1511 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1512 | break; |
1513 | ||
35df4500 | 1514 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1515 | continue; |
35df4500 | 1516 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1517 | current_program_space->aspace, 0)) |
1518 | continue; | |
1519 | ||
c5aa993b JM |
1520 | /* Addresses and length of the part of the breakpoint that |
1521 | we need to copy. */ | |
35df4500 TJB |
1522 | bp_addr = bl->target_info.placed_address; |
1523 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1524 | |
c5aa993b JM |
1525 | if (bp_addr + bp_size <= memaddr) |
1526 | /* The breakpoint is entirely before the chunk of memory we | |
1527 | are reading. */ | |
1528 | continue; | |
8defab1a | 1529 | |
c5aa993b JM |
1530 | if (bp_addr >= memaddr + len) |
1531 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1532 | reading. */ |
c5aa993b | 1533 | continue; |
c5aa993b | 1534 | |
8defab1a DJ |
1535 | /* Offset within shadow_contents. */ |
1536 | if (bp_addr < memaddr) | |
1537 | { | |
1538 | /* Only copy the second part of the breakpoint. */ | |
1539 | bp_size -= memaddr - bp_addr; | |
1540 | bptoffset = memaddr - bp_addr; | |
1541 | bp_addr = memaddr; | |
1542 | } | |
c5aa993b | 1543 | |
8defab1a DJ |
1544 | if (bp_addr + bp_size > memaddr + len) |
1545 | { | |
1546 | /* Only copy the first part of the breakpoint. */ | |
1547 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1548 | } | |
c5aa993b | 1549 | |
f0ba3972 PA |
1550 | if (readbuf != NULL) |
1551 | { | |
35c63cd8 JB |
1552 | /* Verify that the readbuf buffer does not overlap with |
1553 | the shadow_contents buffer. */ | |
1554 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1555 | || readbuf >= (bl->target_info.shadow_contents | |
1556 | + bl->target_info.shadow_len)); | |
1557 | ||
f0ba3972 PA |
1558 | /* Update the read buffer with this inserted breakpoint's |
1559 | shadow. */ | |
1560 | memcpy (readbuf + bp_addr - memaddr, | |
1561 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1562 | } | |
1563 | else | |
1564 | { | |
1565 | struct gdbarch *gdbarch = bl->gdbarch; | |
1566 | const unsigned char *bp; | |
1567 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
20ced3e4 | 1568 | int placed_size = bl->target_info.placed_size; |
f0ba3972 PA |
1569 | |
1570 | /* Update the shadow with what we want to write to memory. */ | |
1571 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1572 | writebuf_org + bp_addr - memaddr, bp_size); | |
1573 | ||
1574 | /* Determine appropriate breakpoint contents and size for this | |
1575 | address. */ | |
1576 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1577 | ||
1578 | /* Update the final write buffer with this inserted | |
1579 | breakpoint's INSN. */ | |
1580 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1581 | } | |
c5aa993b | 1582 | } |
c906108c | 1583 | } |
c906108c | 1584 | \f |
c5aa993b | 1585 | |
b775012e LM |
1586 | /* Return true if BPT is either a software breakpoint or a hardware |
1587 | breakpoint. */ | |
1588 | ||
1589 | int | |
1590 | is_breakpoint (const struct breakpoint *bpt) | |
1591 | { | |
1592 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1593 | || bpt->type == bp_hardware_breakpoint |
1594 | || bpt->type == bp_dprintf); | |
b775012e LM |
1595 | } |
1596 | ||
60e1c644 PA |
1597 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1598 | ||
a5606eee | 1599 | static int |
d77f58be | 1600 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1601 | { |
1602 | return (bpt->type == bp_hardware_watchpoint | |
1603 | || bpt->type == bp_read_watchpoint | |
1604 | || bpt->type == bp_access_watchpoint); | |
1605 | } | |
7270d8f2 | 1606 | |
60e1c644 PA |
1607 | /* Return true if BPT is of any watchpoint kind, hardware or |
1608 | software. */ | |
1609 | ||
3a5c3e22 | 1610 | int |
d77f58be | 1611 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1612 | { |
1613 | return (is_hardware_watchpoint (bpt) | |
1614 | || bpt->type == bp_watchpoint); | |
1615 | } | |
1616 | ||
3a5c3e22 PA |
1617 | /* Returns true if the current thread and its running state are safe |
1618 | to evaluate or update watchpoint B. Watchpoints on local | |
1619 | expressions need to be evaluated in the context of the thread that | |
1620 | was current when the watchpoint was created, and, that thread needs | |
1621 | to be stopped to be able to select the correct frame context. | |
1622 | Watchpoints on global expressions can be evaluated on any thread, | |
1623 | and in any state. It is presently left to the target allowing | |
1624 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1625 | |
1626 | static int | |
3a5c3e22 | 1627 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1628 | { |
d0d8b0c6 JK |
1629 | return (b->base.pspace == current_program_space |
1630 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1631 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1632 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1633 | } |
1634 | ||
d0fb5eae JK |
1635 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1636 | associated bp_watchpoint_scope breakpoint. */ | |
1637 | ||
1638 | static void | |
3a5c3e22 | 1639 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1640 | { |
3a5c3e22 | 1641 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1642 | |
1643 | if (b->related_breakpoint != b) | |
1644 | { | |
1645 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1646 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1647 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1648 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1649 | b->related_breakpoint = b; | |
1650 | } | |
1651 | b->disposition = disp_del_at_next_stop; | |
1652 | } | |
1653 | ||
567e1b4e JB |
1654 | /* Assuming that B is a watchpoint: |
1655 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1656 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1657 | - Evaluate the condition if there is one, and store the result |
1658 | in b->loc->cond. | |
a5606eee VP |
1659 | - Update the list of values that must be watched in B->loc. |
1660 | ||
4a64f543 MS |
1661 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1662 | nothing. If this is local watchpoint that is out of scope, delete | |
1663 | it. | |
1664 | ||
1665 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1666 | removed + inserted on each stop here. Normal breakpoints must | |
1667 | never be removed because they might be missed by a running thread | |
1668 | when debugging in non-stop mode. On the other hand, hardware | |
1669 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1670 | to each LWP since they are stored in each LWP's hardware debug | |
1671 | registers. Therefore, such LWP must be stopped first in order to | |
1672 | be able to modify its hardware watchpoints. | |
1673 | ||
1674 | Hardware watchpoints must be reset exactly once after being | |
1675 | presented to the user. It cannot be done sooner, because it would | |
1676 | reset the data used to present the watchpoint hit to the user. And | |
1677 | it must not be done later because it could display the same single | |
1678 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1679 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1680 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1681 | not user-visible - its hit is suppressed if the memory content has | |
1682 | not changed. | |
1683 | ||
1684 | The following constraints influence the location where we can reset | |
1685 | hardware watchpoints: | |
1686 | ||
1687 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1688 | called several times when GDB stops. | |
1689 | ||
1690 | [linux] | |
1691 | * Multiple hardware watchpoints can be hit at the same time, | |
1692 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1693 | hit at a time as the reason for stopping, and all the other hits | |
1694 | are presented later, one after the other, each time the user | |
1695 | requests the execution to be resumed. Execution is not resumed | |
1696 | for the threads still having pending hit event stored in | |
1697 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1698 | the inferior on the first stop the thread hit event is kept being | |
1699 | reported from its cached value by linux_nat_stopped_data_address | |
1700 | until the real thread resume happens after the watchpoint gets | |
1701 | presented and thus its LWP_INFO->STATUS gets reset. | |
1702 | ||
1703 | Therefore the hardware watchpoint hit can get safely reset on the | |
1704 | watchpoint removal from inferior. */ | |
a79d3c27 | 1705 | |
b40ce68a | 1706 | static void |
3a5c3e22 | 1707 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1708 | { |
a5606eee | 1709 | int within_current_scope; |
a5606eee | 1710 | struct frame_id saved_frame_id; |
66076460 | 1711 | int frame_saved; |
a5606eee | 1712 | |
f6bc2008 PA |
1713 | /* If this is a local watchpoint, we only want to check if the |
1714 | watchpoint frame is in scope if the current thread is the thread | |
1715 | that was used to create the watchpoint. */ | |
1716 | if (!watchpoint_in_thread_scope (b)) | |
1717 | return; | |
1718 | ||
3a5c3e22 | 1719 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1720 | return; |
1721 | ||
66076460 | 1722 | frame_saved = 0; |
a5606eee VP |
1723 | |
1724 | /* Determine if the watchpoint is within scope. */ | |
1725 | if (b->exp_valid_block == NULL) | |
1726 | within_current_scope = 1; | |
1727 | else | |
1728 | { | |
b5db5dfc UW |
1729 | struct frame_info *fi = get_current_frame (); |
1730 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1731 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1732 | ||
1733 | /* If we're in a function epilogue, unwinding may not work | |
1734 | properly, so do not attempt to recreate locations at this | |
1735 | point. See similar comments in watchpoint_check. */ | |
1736 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1737 | return; | |
66076460 DJ |
1738 | |
1739 | /* Save the current frame's ID so we can restore it after | |
1740 | evaluating the watchpoint expression on its own frame. */ | |
1741 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1742 | took a frame parameter, so that we didn't have to change the | |
1743 | selected frame. */ | |
1744 | frame_saved = 1; | |
1745 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1746 | ||
a5606eee VP |
1747 | fi = frame_find_by_id (b->watchpoint_frame); |
1748 | within_current_scope = (fi != NULL); | |
1749 | if (within_current_scope) | |
1750 | select_frame (fi); | |
1751 | } | |
1752 | ||
b5db5dfc UW |
1753 | /* We don't free locations. They are stored in the bp_location array |
1754 | and update_global_location_list will eventually delete them and | |
1755 | remove breakpoints if needed. */ | |
3a5c3e22 | 1756 | b->base.loc = NULL; |
b5db5dfc | 1757 | |
a5606eee VP |
1758 | if (within_current_scope && reparse) |
1759 | { | |
bbc13ae3 | 1760 | const char *s; |
d63d0675 | 1761 | |
a5606eee VP |
1762 | if (b->exp) |
1763 | { | |
1764 | xfree (b->exp); | |
1765 | b->exp = NULL; | |
1766 | } | |
d63d0675 | 1767 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1768 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1769 | /* If the meaning of expression itself changed, the old value is |
1770 | no longer relevant. We don't want to report a watchpoint hit | |
1771 | to the user when the old value and the new value may actually | |
1772 | be completely different objects. */ | |
1773 | value_free (b->val); | |
fa4727a6 DJ |
1774 | b->val = NULL; |
1775 | b->val_valid = 0; | |
60e1c644 PA |
1776 | |
1777 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1778 | expression is stored in the breakpoint object, not in the | |
1779 | locations (re)created below. */ | |
3a5c3e22 | 1780 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1781 | { |
1782 | if (b->cond_exp != NULL) | |
1783 | { | |
1784 | xfree (b->cond_exp); | |
1785 | b->cond_exp = NULL; | |
1786 | } | |
1787 | ||
3a5c3e22 | 1788 | s = b->base.cond_string; |
1bb9788d | 1789 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1790 | } |
a5606eee | 1791 | } |
a5606eee VP |
1792 | |
1793 | /* If we failed to parse the expression, for example because | |
1794 | it refers to a global variable in a not-yet-loaded shared library, | |
1795 | don't try to insert watchpoint. We don't automatically delete | |
1796 | such watchpoint, though, since failure to parse expression | |
1797 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1798 | if (!target_has_execution) |
2d134ed3 PA |
1799 | { |
1800 | /* Without execution, memory can't change. No use to try and | |
1801 | set watchpoint locations. The watchpoint will be reset when | |
1802 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1803 | if (!can_use_hw_watchpoints) |
1804 | { | |
1805 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1806 | b->base.type = bp_watchpoint; | |
1807 | else | |
638aa5a1 AB |
1808 | error (_("Can't set read/access watchpoint when " |
1809 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1810 | } |
2d134ed3 PA |
1811 | } |
1812 | else if (within_current_scope && b->exp) | |
a5606eee | 1813 | { |
0cf6dd15 | 1814 | int pc = 0; |
fa4727a6 | 1815 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1816 | struct program_space *frame_pspace; |
a5606eee | 1817 | |
3a1115a0 | 1818 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1819 | |
a5606eee VP |
1820 | /* Avoid setting b->val if it's already set. The meaning of |
1821 | b->val is 'the last value' user saw, and we should update | |
1822 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1823 | happens, the code that reports it updates b->val directly. |
1824 | We don't keep track of the memory value for masked | |
1825 | watchpoints. */ | |
3a5c3e22 | 1826 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1827 | { |
1828 | b->val = v; | |
1829 | b->val_valid = 1; | |
1830 | } | |
a5606eee | 1831 | |
2d134ed3 PA |
1832 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1833 | ||
a5606eee | 1834 | /* Look at each value on the value chain. */ |
9fa40276 | 1835 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1836 | { |
1837 | /* If it's a memory location, and GDB actually needed | |
1838 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1839 | must watch it. If the first value returned is |
1840 | still lazy, that means an error occurred reading it; | |
1841 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1842 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1843 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1844 | { |
1845 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1846 | |
a5606eee VP |
1847 | /* We only watch structs and arrays if user asked |
1848 | for it explicitly, never if they just happen to | |
1849 | appear in the middle of some value chain. */ | |
fa4727a6 | 1850 | if (v == result |
a5606eee VP |
1851 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1852 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1853 | { | |
1854 | CORE_ADDR addr; | |
744a8059 | 1855 | int type; |
a5606eee VP |
1856 | struct bp_location *loc, **tmp; |
1857 | ||
42ae5230 | 1858 | addr = value_address (v); |
a5606eee | 1859 | type = hw_write; |
3a5c3e22 | 1860 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1861 | type = hw_read; |
3a5c3e22 | 1862 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1863 | type = hw_access; |
3a5c3e22 PA |
1864 | |
1865 | loc = allocate_bp_location (&b->base); | |
1866 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1867 | ; |
1868 | *tmp = loc; | |
a6d9a66e | 1869 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1870 | |
1871 | loc->pspace = frame_pspace; | |
a5606eee | 1872 | loc->address = addr; |
744a8059 | 1873 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1874 | loc->watchpoint_type = type; |
1875 | } | |
1876 | } | |
9fa40276 TJB |
1877 | } |
1878 | ||
1879 | /* Change the type of breakpoint between hardware assisted or | |
1880 | an ordinary watchpoint depending on the hardware support | |
1881 | and free hardware slots. REPARSE is set when the inferior | |
1882 | is started. */ | |
a9634178 | 1883 | if (reparse) |
9fa40276 | 1884 | { |
e09342b5 | 1885 | int reg_cnt; |
9fa40276 TJB |
1886 | enum bp_loc_type loc_type; |
1887 | struct bp_location *bl; | |
a5606eee | 1888 | |
a9634178 | 1889 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1890 | |
1891 | if (reg_cnt) | |
9fa40276 TJB |
1892 | { |
1893 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1894 | enum bptype type; |
9fa40276 | 1895 | |
a9634178 TJB |
1896 | /* Use an exact watchpoint when there's only one memory region to be |
1897 | watched, and only one debug register is needed to watch it. */ | |
1898 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1899 | ||
9fa40276 | 1900 | /* We need to determine how many resources are already |
e09342b5 TJB |
1901 | used for all other hardware watchpoints plus this one |
1902 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1903 | this watchpoint in as well. */ |
1904 | ||
1905 | /* If this is a software watchpoint, we try to turn it | |
1906 | to a hardware one -- count resources as if B was of | |
1907 | hardware watchpoint type. */ | |
1908 | type = b->base.type; | |
1909 | if (type == bp_watchpoint) | |
1910 | type = bp_hardware_watchpoint; | |
1911 | ||
1912 | /* This watchpoint may or may not have been placed on | |
1913 | the list yet at this point (it won't be in the list | |
1914 | if we're trying to create it for the first time, | |
1915 | through watch_command), so always account for it | |
1916 | manually. */ | |
1917 | ||
1918 | /* Count resources used by all watchpoints except B. */ | |
1919 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1920 | ||
1921 | /* Add in the resources needed for B. */ | |
1922 | i += hw_watchpoint_use_count (&b->base); | |
1923 | ||
1924 | target_resources_ok | |
1925 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1926 | if (target_resources_ok <= 0) |
a9634178 | 1927 | { |
3a5c3e22 | 1928 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1929 | |
1930 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1931 | error (_("Target does not support this type of " |
1932 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1933 | else if (target_resources_ok < 0 && !sw_mode) |
1934 | error (_("There are not enough available hardware " | |
1935 | "resources for this watchpoint.")); | |
a1398e0c PA |
1936 | |
1937 | /* Downgrade to software watchpoint. */ | |
1938 | b->base.type = bp_watchpoint; | |
1939 | } | |
1940 | else | |
1941 | { | |
1942 | /* If this was a software watchpoint, we've just | |
1943 | found we have enough resources to turn it to a | |
1944 | hardware watchpoint. Otherwise, this is a | |
1945 | nop. */ | |
1946 | b->base.type = type; | |
a9634178 | 1947 | } |
9fa40276 | 1948 | } |
3a5c3e22 | 1949 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
1950 | { |
1951 | if (!can_use_hw_watchpoints) | |
1952 | error (_("Can't set read/access watchpoint when " | |
1953 | "hardware watchpoints are disabled.")); | |
1954 | else | |
1955 | error (_("Expression cannot be implemented with " | |
1956 | "read/access watchpoint.")); | |
1957 | } | |
9fa40276 | 1958 | else |
3a5c3e22 | 1959 | b->base.type = bp_watchpoint; |
9fa40276 | 1960 | |
3a5c3e22 | 1961 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1962 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1963 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1964 | bl->loc_type = loc_type; |
1965 | } | |
1966 | ||
1967 | for (v = val_chain; v; v = next) | |
1968 | { | |
a5606eee VP |
1969 | next = value_next (v); |
1970 | if (v != b->val) | |
1971 | value_free (v); | |
1972 | } | |
1973 | ||
c7437ca6 PA |
1974 | /* If a software watchpoint is not watching any memory, then the |
1975 | above left it without any location set up. But, | |
1976 | bpstat_stop_status requires a location to be able to report | |
1977 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1978 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1979 | { |
3a5c3e22 PA |
1980 | struct breakpoint *base = &b->base; |
1981 | base->loc = allocate_bp_location (base); | |
1982 | base->loc->pspace = frame_pspace; | |
1983 | base->loc->address = -1; | |
1984 | base->loc->length = -1; | |
1985 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1986 | } |
a5606eee VP |
1987 | } |
1988 | else if (!within_current_scope) | |
7270d8f2 | 1989 | { |
ac74f770 MS |
1990 | printf_filtered (_("\ |
1991 | Watchpoint %d deleted because the program has left the block\n\ | |
1992 | in which its expression is valid.\n"), | |
3a5c3e22 | 1993 | b->base.number); |
d0fb5eae | 1994 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1995 | } |
a5606eee VP |
1996 | |
1997 | /* Restore the selected frame. */ | |
66076460 DJ |
1998 | if (frame_saved) |
1999 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2000 | } |
2001 | ||
a5606eee | 2002 | |
74960c60 | 2003 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2004 | inserted in the inferior. We don't differentiate the type of BL's owner |
2005 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2006 | breakpoint_ops is not defined, because in insert_bp_location, | |
2007 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2008 | static int |
35df4500 | 2009 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2010 | { |
35df4500 | 2011 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2012 | return 0; |
2013 | ||
35df4500 | 2014 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2015 | return 0; |
2016 | ||
35df4500 | 2017 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2018 | return 0; |
2019 | ||
f8eba3c6 TT |
2020 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2021 | return 0; | |
2022 | ||
56710373 PA |
2023 | /* This is set for example, when we're attached to the parent of a |
2024 | vfork, and have detached from the child. The child is running | |
2025 | free, and we expect it to do an exec or exit, at which point the | |
2026 | OS makes the parent schedulable again (and the target reports | |
2027 | that the vfork is done). Until the child is done with the shared | |
2028 | memory region, do not insert breakpoints in the parent, otherwise | |
2029 | the child could still trip on the parent's breakpoints. Since | |
2030 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2031 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2032 | return 0; |
2033 | ||
74960c60 VP |
2034 | return 1; |
2035 | } | |
2036 | ||
934709f0 PW |
2037 | /* Same as should_be_inserted but does the check assuming |
2038 | that the location is not duplicated. */ | |
2039 | ||
2040 | static int | |
2041 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2042 | { | |
2043 | int result; | |
2044 | const int save_duplicate = bl->duplicate; | |
2045 | ||
2046 | bl->duplicate = 0; | |
2047 | result = should_be_inserted (bl); | |
2048 | bl->duplicate = save_duplicate; | |
2049 | return result; | |
2050 | } | |
2051 | ||
b775012e LM |
2052 | /* Parses a conditional described by an expression COND into an |
2053 | agent expression bytecode suitable for evaluation | |
2054 | by the bytecode interpreter. Return NULL if there was | |
2055 | any error during parsing. */ | |
2056 | ||
2057 | static struct agent_expr * | |
2058 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2059 | { | |
2060 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2061 | volatile struct gdb_exception ex; |
2062 | ||
2063 | if (!cond) | |
2064 | return NULL; | |
2065 | ||
2066 | /* We don't want to stop processing, so catch any errors | |
2067 | that may show up. */ | |
2068 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2069 | { | |
2070 | aexpr = gen_eval_for_expr (scope, cond); | |
2071 | } | |
2072 | ||
2073 | if (ex.reason < 0) | |
2074 | { | |
2075 | /* If we got here, it means the condition could not be parsed to a valid | |
2076 | bytecode expression and thus can't be evaluated on the target's side. | |
2077 | It's no use iterating through the conditions. */ | |
2078 | return NULL; | |
2079 | } | |
2080 | ||
2081 | /* We have a valid agent expression. */ | |
2082 | return aexpr; | |
2083 | } | |
2084 | ||
2085 | /* Based on location BL, create a list of breakpoint conditions to be | |
2086 | passed on to the target. If we have duplicated locations with different | |
2087 | conditions, we will add such conditions to the list. The idea is that the | |
2088 | target will evaluate the list of conditions and will only notify GDB when | |
2089 | one of them is true. */ | |
2090 | ||
2091 | static void | |
2092 | build_target_condition_list (struct bp_location *bl) | |
2093 | { | |
2094 | struct bp_location **locp = NULL, **loc2p; | |
2095 | int null_condition_or_parse_error = 0; | |
2096 | int modified = bl->needs_update; | |
2097 | struct bp_location *loc; | |
2098 | ||
2099 | /* This is only meaningful if the target is | |
2100 | evaluating conditions and if the user has | |
2101 | opted for condition evaluation on the target's | |
2102 | side. */ | |
2103 | if (gdb_evaluates_breakpoint_condition_p () | |
2104 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2105 | return; | |
2106 | ||
2107 | /* Do a first pass to check for locations with no assigned | |
2108 | conditions or conditions that fail to parse to a valid agent expression | |
2109 | bytecode. If any of these happen, then it's no use to send conditions | |
2110 | to the target since this location will always trigger and generate a | |
2111 | response back to GDB. */ | |
2112 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2113 | { | |
2114 | loc = (*loc2p); | |
2115 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2116 | { | |
2117 | if (modified) | |
2118 | { | |
2119 | struct agent_expr *aexpr; | |
2120 | ||
2121 | /* Re-parse the conditions since something changed. In that | |
2122 | case we already freed the condition bytecodes (see | |
2123 | force_breakpoint_reinsertion). We just | |
2124 | need to parse the condition to bytecodes again. */ | |
2125 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2126 | loc->cond_bytecode = aexpr; | |
2127 | ||
2128 | /* Check if we managed to parse the conditional expression | |
2129 | correctly. If not, we will not send this condition | |
2130 | to the target. */ | |
2131 | if (aexpr) | |
2132 | continue; | |
2133 | } | |
2134 | ||
2135 | /* If we have a NULL bytecode expression, it means something | |
2136 | went wrong or we have a null condition expression. */ | |
2137 | if (!loc->cond_bytecode) | |
2138 | { | |
2139 | null_condition_or_parse_error = 1; | |
2140 | break; | |
2141 | } | |
2142 | } | |
2143 | } | |
2144 | ||
2145 | /* If any of these happened, it means we will have to evaluate the conditions | |
2146 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2147 | for all the other duplicate locations, thus we free all of them here. | |
2148 | ||
2149 | This is so we have a finer control over which locations' conditions are | |
2150 | being evaluated by GDB or the remote stub. */ | |
2151 | if (null_condition_or_parse_error) | |
2152 | { | |
2153 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2154 | { | |
2155 | loc = (*loc2p); | |
2156 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2157 | { | |
2158 | /* Only go as far as the first NULL bytecode is | |
2159 | located. */ | |
2160 | if (!loc->cond_bytecode) | |
2161 | return; | |
2162 | ||
2163 | free_agent_expr (loc->cond_bytecode); | |
2164 | loc->cond_bytecode = NULL; | |
2165 | } | |
2166 | } | |
2167 | } | |
2168 | ||
2169 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2170 | for this location's address. */ | |
2171 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2172 | { | |
2173 | loc = (*loc2p); | |
2174 | if (loc->cond | |
2175 | && is_breakpoint (loc->owner) | |
2176 | && loc->pspace->num == bl->pspace->num | |
2177 | && loc->owner->enable_state == bp_enabled | |
2178 | && loc->enabled) | |
2179 | /* Add the condition to the vector. This will be used later to send the | |
2180 | conditions to the target. */ | |
2181 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2182 | loc->cond_bytecode); | |
2183 | } | |
2184 | ||
2185 | return; | |
2186 | } | |
2187 | ||
d3ce09f5 SS |
2188 | /* Parses a command described by string CMD into an agent expression |
2189 | bytecode suitable for evaluation by the bytecode interpreter. | |
2190 | Return NULL if there was any error during parsing. */ | |
2191 | ||
2192 | static struct agent_expr * | |
2193 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2194 | { | |
2195 | struct cleanup *old_cleanups = 0; | |
2196 | struct expression *expr, **argvec; | |
2197 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2198 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2199 | const char *cmdrest; |
2200 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2201 | struct format_piece *fpieces; |
2202 | int nargs; | |
2203 | struct gdbarch *gdbarch = get_current_arch (); | |
2204 | ||
2205 | if (!cmd) | |
2206 | return NULL; | |
2207 | ||
2208 | cmdrest = cmd; | |
2209 | ||
2210 | if (*cmdrest == ',') | |
2211 | ++cmdrest; | |
bbc13ae3 | 2212 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2213 | |
2214 | if (*cmdrest++ != '"') | |
2215 | error (_("No format string following the location")); | |
2216 | ||
2217 | format_start = cmdrest; | |
2218 | ||
2219 | fpieces = parse_format_string (&cmdrest); | |
2220 | ||
2221 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2222 | ||
2223 | format_end = cmdrest; | |
2224 | ||
2225 | if (*cmdrest++ != '"') | |
2226 | error (_("Bad format string, non-terminated '\"'.")); | |
2227 | ||
bbc13ae3 | 2228 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2229 | |
2230 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2231 | error (_("Invalid argument syntax")); | |
2232 | ||
2233 | if (*cmdrest == ',') | |
2234 | cmdrest++; | |
bbc13ae3 | 2235 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2236 | |
2237 | /* For each argument, make an expression. */ | |
2238 | ||
2239 | argvec = (struct expression **) alloca (strlen (cmd) | |
2240 | * sizeof (struct expression *)); | |
2241 | ||
2242 | nargs = 0; | |
2243 | while (*cmdrest != '\0') | |
2244 | { | |
bbc13ae3 | 2245 | const char *cmd1; |
d3ce09f5 SS |
2246 | |
2247 | cmd1 = cmdrest; | |
2248 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2249 | argvec[nargs++] = expr; | |
2250 | cmdrest = cmd1; | |
2251 | if (*cmdrest == ',') | |
2252 | ++cmdrest; | |
2253 | } | |
2254 | ||
2255 | /* We don't want to stop processing, so catch any errors | |
2256 | that may show up. */ | |
2257 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2258 | { | |
2259 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2260 | format_start, format_end - format_start, | |
2261 | fpieces, nargs, argvec); | |
2262 | } | |
2263 | ||
752eb8b4 TT |
2264 | do_cleanups (old_cleanups); |
2265 | ||
d3ce09f5 SS |
2266 | if (ex.reason < 0) |
2267 | { | |
2268 | /* If we got here, it means the command could not be parsed to a valid | |
2269 | bytecode expression and thus can't be evaluated on the target's side. | |
2270 | It's no use iterating through the other commands. */ | |
2271 | return NULL; | |
2272 | } | |
2273 | ||
d3ce09f5 SS |
2274 | /* We have a valid agent expression, return it. */ |
2275 | return aexpr; | |
2276 | } | |
2277 | ||
2278 | /* Based on location BL, create a list of breakpoint commands to be | |
2279 | passed on to the target. If we have duplicated locations with | |
2280 | different commands, we will add any such to the list. */ | |
2281 | ||
2282 | static void | |
2283 | build_target_command_list (struct bp_location *bl) | |
2284 | { | |
2285 | struct bp_location **locp = NULL, **loc2p; | |
2286 | int null_command_or_parse_error = 0; | |
2287 | int modified = bl->needs_update; | |
2288 | struct bp_location *loc; | |
2289 | ||
2290 | /* For now, limit to agent-style dprintf breakpoints. */ | |
2291 | if (bl->owner->type != bp_dprintf | |
2292 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2293 | return; | |
2294 | ||
2295 | if (!target_can_run_breakpoint_commands ()) | |
2296 | return; | |
2297 | ||
2298 | /* Do a first pass to check for locations with no assigned | |
2299 | conditions or conditions that fail to parse to a valid agent expression | |
2300 | bytecode. If any of these happen, then it's no use to send conditions | |
2301 | to the target since this location will always trigger and generate a | |
2302 | response back to GDB. */ | |
2303 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2304 | { | |
2305 | loc = (*loc2p); | |
2306 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2307 | { | |
2308 | if (modified) | |
2309 | { | |
2310 | struct agent_expr *aexpr; | |
2311 | ||
2312 | /* Re-parse the commands since something changed. In that | |
2313 | case we already freed the command bytecodes (see | |
2314 | force_breakpoint_reinsertion). We just | |
2315 | need to parse the command to bytecodes again. */ | |
2316 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2317 | loc->owner->extra_string); | |
2318 | loc->cmd_bytecode = aexpr; | |
2319 | ||
2320 | if (!aexpr) | |
2321 | continue; | |
2322 | } | |
2323 | ||
2324 | /* If we have a NULL bytecode expression, it means something | |
2325 | went wrong or we have a null command expression. */ | |
2326 | if (!loc->cmd_bytecode) | |
2327 | { | |
2328 | null_command_or_parse_error = 1; | |
2329 | break; | |
2330 | } | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | /* If anything failed, then we're not doing target-side commands, | |
2335 | and so clean up. */ | |
2336 | if (null_command_or_parse_error) | |
2337 | { | |
2338 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2339 | { | |
2340 | loc = (*loc2p); | |
2341 | if (is_breakpoint (loc->owner) | |
2342 | && loc->pspace->num == bl->pspace->num) | |
2343 | { | |
2344 | /* Only go as far as the first NULL bytecode is | |
2345 | located. */ | |
40fb6c5e | 2346 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2347 | return; |
2348 | ||
40fb6c5e HZ |
2349 | free_agent_expr (loc->cmd_bytecode); |
2350 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2351 | } |
2352 | } | |
2353 | } | |
2354 | ||
2355 | /* No NULL commands or failed bytecode generation. Build a command list | |
2356 | for this location's address. */ | |
2357 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2358 | { | |
2359 | loc = (*loc2p); | |
2360 | if (loc->owner->extra_string | |
2361 | && is_breakpoint (loc->owner) | |
2362 | && loc->pspace->num == bl->pspace->num | |
2363 | && loc->owner->enable_state == bp_enabled | |
2364 | && loc->enabled) | |
2365 | /* Add the command to the vector. This will be used later | |
2366 | to send the commands to the target. */ | |
2367 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2368 | loc->cmd_bytecode); | |
2369 | } | |
2370 | ||
2371 | bl->target_info.persist = 0; | |
2372 | /* Maybe flag this location as persistent. */ | |
2373 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2374 | bl->target_info.persist = 1; | |
2375 | } | |
2376 | ||
35df4500 TJB |
2377 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2378 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2379 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2380 | Returns 0 for success, 1 if the bp_location type is not supported or |
2381 | -1 for failure. | |
879bfdc2 | 2382 | |
4a64f543 MS |
2383 | NOTE drow/2003-09-09: This routine could be broken down to an |
2384 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2385 | static int |
35df4500 | 2386 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2387 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2388 | int *disabled_breaks, |
dd61ec5c MW |
2389 | int *hw_breakpoint_error, |
2390 | int *hw_bp_error_explained_already) | |
879bfdc2 DJ |
2391 | { |
2392 | int val = 0; | |
dd61ec5c MW |
2393 | char *hw_bp_err_string = NULL; |
2394 | struct gdb_exception e; | |
879bfdc2 | 2395 | |
b775012e | 2396 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2397 | return 0; |
2398 | ||
35c63cd8 JB |
2399 | /* Note we don't initialize bl->target_info, as that wipes out |
2400 | the breakpoint location's shadow_contents if the breakpoint | |
2401 | is still inserted at that location. This in turn breaks | |
2402 | target_read_memory which depends on these buffers when | |
2403 | a memory read is requested at the breakpoint location: | |
2404 | Once the target_info has been wiped, we fail to see that | |
2405 | we have a breakpoint inserted at that address and thus | |
2406 | read the breakpoint instead of returning the data saved in | |
2407 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2408 | bl->target_info.placed_address = bl->address; |
2409 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2410 | bl->target_info.length = bl->length; |
8181d85f | 2411 | |
b775012e LM |
2412 | /* When working with target-side conditions, we must pass all the conditions |
2413 | for the same breakpoint address down to the target since GDB will not | |
2414 | insert those locations. With a list of breakpoint conditions, the target | |
2415 | can decide when to stop and notify GDB. */ | |
2416 | ||
2417 | if (is_breakpoint (bl->owner)) | |
2418 | { | |
2419 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2420 | build_target_command_list (bl); |
2421 | /* Reset the modification marker. */ | |
b775012e LM |
2422 | bl->needs_update = 0; |
2423 | } | |
2424 | ||
35df4500 TJB |
2425 | if (bl->loc_type == bp_loc_software_breakpoint |
2426 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2427 | { |
35df4500 | 2428 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2429 | { |
2430 | /* If the explicitly specified breakpoint type | |
2431 | is not hardware breakpoint, check the memory map to see | |
2432 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2433 | |
765dc015 VP |
2434 | Two important cases are: |
2435 | - location type is not hardware breakpoint, memory | |
2436 | is readonly. We change the type of the location to | |
2437 | hardware breakpoint. | |
4a64f543 MS |
2438 | - location type is hardware breakpoint, memory is |
2439 | read-write. This means we've previously made the | |
2440 | location hardware one, but then the memory map changed, | |
2441 | so we undo. | |
765dc015 | 2442 | |
4a64f543 MS |
2443 | When breakpoints are removed, remove_breakpoints will use |
2444 | location types we've just set here, the only possible | |
2445 | problem is that memory map has changed during running | |
2446 | program, but it's not going to work anyway with current | |
2447 | gdb. */ | |
765dc015 | 2448 | struct mem_region *mr |
35df4500 | 2449 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2450 | |
2451 | if (mr) | |
2452 | { | |
2453 | if (automatic_hardware_breakpoints) | |
2454 | { | |
765dc015 VP |
2455 | enum bp_loc_type new_type; |
2456 | ||
2457 | if (mr->attrib.mode != MEM_RW) | |
2458 | new_type = bp_loc_hardware_breakpoint; | |
2459 | else | |
2460 | new_type = bp_loc_software_breakpoint; | |
2461 | ||
35df4500 | 2462 | if (new_type != bl->loc_type) |
765dc015 VP |
2463 | { |
2464 | static int said = 0; | |
cc59ec59 | 2465 | |
35df4500 | 2466 | bl->loc_type = new_type; |
765dc015 VP |
2467 | if (!said) |
2468 | { | |
3e43a32a MS |
2469 | fprintf_filtered (gdb_stdout, |
2470 | _("Note: automatically using " | |
2471 | "hardware breakpoints for " | |
2472 | "read-only addresses.\n")); | |
765dc015 VP |
2473 | said = 1; |
2474 | } | |
2475 | } | |
2476 | } | |
35df4500 | 2477 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2478 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2479 | warning (_("cannot set software breakpoint " |
2480 | "at readonly address %s"), | |
35df4500 | 2481 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2482 | } |
2483 | } | |
2484 | ||
879bfdc2 DJ |
2485 | /* First check to see if we have to handle an overlay. */ |
2486 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2487 | || bl->section == NULL |
2488 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2489 | { |
2490 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2491 | TRY_CATCH (e, RETURN_MASK_ALL) |
2492 | { | |
2493 | val = bl->owner->ops->insert_location (bl); | |
2494 | } | |
2495 | if (e.reason < 0) | |
2496 | { | |
2497 | val = 1; | |
2498 | hw_bp_err_string = (char *) e.message; | |
2499 | } | |
879bfdc2 DJ |
2500 | } |
2501 | else | |
2502 | { | |
4a64f543 | 2503 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2504 | Shall we set a breakpoint at the LMA? */ |
2505 | if (!overlay_events_enabled) | |
2506 | { | |
2507 | /* Yes -- overlay event support is not active, | |
2508 | so we must try to set a breakpoint at the LMA. | |
2509 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2510 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2511 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2512 | bl->owner->number); |
879bfdc2 DJ |
2513 | else |
2514 | { | |
35df4500 TJB |
2515 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2516 | bl->section); | |
879bfdc2 | 2517 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2518 | bl->overlay_target_info = bl->target_info; |
2519 | bl->overlay_target_info.placed_address = addr; | |
2520 | val = target_insert_breakpoint (bl->gdbarch, | |
2521 | &bl->overlay_target_info); | |
879bfdc2 | 2522 | if (val != 0) |
99361f52 | 2523 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2524 | "Overlay breakpoint %d " |
2525 | "failed: in ROM?\n", | |
35df4500 | 2526 | bl->owner->number); |
879bfdc2 DJ |
2527 | } |
2528 | } | |
2529 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2530 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2531 | { |
2532 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2533 | TRY_CATCH (e, RETURN_MASK_ALL) |
2534 | { | |
2535 | val = bl->owner->ops->insert_location (bl); | |
2536 | } | |
2537 | if (e.reason < 0) | |
2538 | { | |
2539 | val = 1; | |
2540 | hw_bp_err_string = (char *) e.message; | |
2541 | } | |
879bfdc2 DJ |
2542 | } |
2543 | else | |
2544 | { | |
2545 | /* No. This breakpoint will not be inserted. | |
2546 | No error, but do not mark the bp as 'inserted'. */ | |
2547 | return 0; | |
2548 | } | |
2549 | } | |
2550 | ||
2551 | if (val) | |
2552 | { | |
2553 | /* Can't set the breakpoint. */ | |
35df4500 | 2554 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2555 | { |
4a64f543 | 2556 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2557 | val = 0; |
35df4500 | 2558 | bl->shlib_disabled = 1; |
8d3788bd | 2559 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2560 | if (!*disabled_breaks) |
2561 | { | |
2562 | fprintf_unfiltered (tmp_error_stream, | |
2563 | "Cannot insert breakpoint %d.\n", | |
2564 | bl->owner->number); | |
2565 | fprintf_unfiltered (tmp_error_stream, | |
2566 | "Temporarily disabling shared " | |
2567 | "library breakpoints:\n"); | |
2568 | } | |
2569 | *disabled_breaks = 1; | |
879bfdc2 | 2570 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2571 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2572 | } |
2573 | else | |
879bfdc2 | 2574 | { |
35df4500 | 2575 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2576 | { |
dd61ec5c MW |
2577 | *hw_breakpoint_error = 1; |
2578 | *hw_bp_error_explained_already = hw_bp_err_string != NULL; | |
2579 | fprintf_unfiltered (tmp_error_stream, | |
2580 | "Cannot insert hardware breakpoint %d%s", | |
2581 | bl->owner->number, hw_bp_err_string ? ":" : ".\n"); | |
2582 | if (hw_bp_err_string) | |
2583 | fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string); | |
879bfdc2 DJ |
2584 | } |
2585 | else | |
2586 | { | |
578d3588 PA |
2587 | char *message = memory_error_message (TARGET_XFER_E_IO, |
2588 | bl->gdbarch, bl->address); | |
2589 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2590 | ||
879bfdc2 | 2591 | fprintf_unfiltered (tmp_error_stream, |
578d3588 PA |
2592 | "Cannot insert breakpoint %d.\n" |
2593 | "%s\n", | |
2594 | bl->owner->number, message); | |
2595 | ||
2596 | do_cleanups (old_chain); | |
879bfdc2 DJ |
2597 | } |
2598 | ||
2599 | } | |
2600 | } | |
2601 | else | |
35df4500 | 2602 | bl->inserted = 1; |
879bfdc2 DJ |
2603 | |
2604 | return val; | |
2605 | } | |
2606 | ||
35df4500 | 2607 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2608 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2609 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2610 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2611 | { |
77b06cd7 TJB |
2612 | gdb_assert (bl->owner->ops != NULL |
2613 | && bl->owner->ops->insert_location != NULL); | |
2614 | ||
2615 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2616 | |
2617 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2618 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2619 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2620 | { |
2621 | struct bp_location *loc, **loc_temp; | |
2622 | ||
2623 | /* But don't try to insert it, if there's already another | |
2624 | hw_access location that would be considered a duplicate | |
2625 | of this one. */ | |
2626 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2627 | if (loc != bl |
85d721b8 | 2628 | && loc->watchpoint_type == hw_access |
35df4500 | 2629 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2630 | { |
35df4500 TJB |
2631 | bl->duplicate = 1; |
2632 | bl->inserted = 1; | |
2633 | bl->target_info = loc->target_info; | |
2634 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2635 | val = 0; |
2636 | break; | |
2637 | } | |
2638 | ||
2639 | if (val == 1) | |
2640 | { | |
77b06cd7 TJB |
2641 | bl->watchpoint_type = hw_access; |
2642 | val = bl->owner->ops->insert_location (bl); | |
2643 | ||
2644 | if (val) | |
2645 | /* Back to the original value. */ | |
2646 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2647 | } |
2648 | } | |
2649 | ||
35df4500 | 2650 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2651 | } |
2652 | ||
35df4500 | 2653 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2654 | { |
77b06cd7 TJB |
2655 | gdb_assert (bl->owner->ops != NULL |
2656 | && bl->owner->ops->insert_location != NULL); | |
2657 | ||
2658 | val = bl->owner->ops->insert_location (bl); | |
2659 | if (val) | |
2660 | { | |
2661 | bl->owner->enable_state = bp_disabled; | |
2662 | ||
2663 | if (val == 1) | |
2664 | warning (_("\ | |
2665 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2666 | of catchpoint."), bl->owner->number); | |
2667 | else | |
2668 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2669 | } | |
2670 | ||
2671 | bl->inserted = (val == 0); | |
1640b821 DJ |
2672 | |
2673 | /* We've already printed an error message if there was a problem | |
2674 | inserting this catchpoint, and we've disabled the catchpoint, | |
2675 | so just return success. */ | |
2676 | return 0; | |
879bfdc2 DJ |
2677 | } |
2678 | ||
2679 | return 0; | |
2680 | } | |
2681 | ||
6c95b8df PA |
2682 | /* This function is called when program space PSPACE is about to be |
2683 | deleted. It takes care of updating breakpoints to not reference | |
2684 | PSPACE anymore. */ | |
2685 | ||
2686 | void | |
2687 | breakpoint_program_space_exit (struct program_space *pspace) | |
2688 | { | |
2689 | struct breakpoint *b, *b_temp; | |
876fa593 | 2690 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2691 | |
2692 | /* Remove any breakpoint that was set through this program space. */ | |
2693 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2694 | { | |
2695 | if (b->pspace == pspace) | |
2696 | delete_breakpoint (b); | |
2697 | } | |
2698 | ||
2699 | /* Breakpoints set through other program spaces could have locations | |
2700 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2701 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2702 | { |
2703 | struct bp_location *tmp; | |
2704 | ||
2705 | if (loc->pspace == pspace) | |
2706 | { | |
2bdf28a0 | 2707 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2708 | if (loc->owner->loc == loc) |
2709 | loc->owner->loc = loc->next; | |
2710 | else | |
2711 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2712 | if (tmp->next == loc) | |
2713 | { | |
2714 | tmp->next = loc->next; | |
2715 | break; | |
2716 | } | |
2717 | } | |
2718 | } | |
2719 | ||
2720 | /* Now update the global location list to permanently delete the | |
2721 | removed locations above. */ | |
2722 | update_global_location_list (0); | |
2723 | } | |
2724 | ||
74960c60 VP |
2725 | /* Make sure all breakpoints are inserted in inferior. |
2726 | Throws exception on any error. | |
2727 | A breakpoint that is already inserted won't be inserted | |
2728 | again, so calling this function twice is safe. */ | |
2729 | void | |
2730 | insert_breakpoints (void) | |
2731 | { | |
2732 | struct breakpoint *bpt; | |
2733 | ||
2734 | ALL_BREAKPOINTS (bpt) | |
2735 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2736 | { |
2737 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2738 | ||
2739 | update_watchpoint (w, 0 /* don't reparse. */); | |
2740 | } | |
74960c60 | 2741 | |
b60e7edf | 2742 | update_global_location_list (1); |
74960c60 | 2743 | |
c35b1492 PA |
2744 | /* update_global_location_list does not insert breakpoints when |
2745 | always_inserted_mode is not enabled. Explicitly insert them | |
2746 | now. */ | |
2747 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2748 | insert_breakpoint_locations (); |
2749 | } | |
2750 | ||
20388dd6 YQ |
2751 | /* Invoke CALLBACK for each of bp_location. */ |
2752 | ||
2753 | void | |
2754 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2755 | { | |
2756 | struct bp_location *loc, **loc_tmp; | |
2757 | ||
2758 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2759 | { | |
2760 | callback (loc, NULL); | |
2761 | } | |
2762 | } | |
2763 | ||
b775012e LM |
2764 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2765 | target. It is the case with deleting and disabling of breakpoints when using | |
2766 | always-inserted mode. */ | |
2767 | ||
2768 | static void | |
2769 | update_inserted_breakpoint_locations (void) | |
2770 | { | |
2771 | struct bp_location *bl, **blp_tmp; | |
2772 | int error_flag = 0; | |
2773 | int val = 0; | |
2774 | int disabled_breaks = 0; | |
2775 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2776 | int hw_bp_details_reported = 0; |
b775012e LM |
2777 | |
2778 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2779 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2780 | ||
2781 | /* Explicitly mark the warning -- this will only be printed if | |
2782 | there was an error. */ | |
2783 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2784 | ||
2785 | save_current_space_and_thread (); | |
2786 | ||
2787 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2788 | { | |
2789 | /* We only want to update software breakpoints and hardware | |
2790 | breakpoints. */ | |
2791 | if (!is_breakpoint (bl->owner)) | |
2792 | continue; | |
2793 | ||
2794 | /* We only want to update locations that are already inserted | |
2795 | and need updating. This is to avoid unwanted insertion during | |
2796 | deletion of breakpoints. */ | |
2797 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2798 | continue; | |
2799 | ||
2800 | switch_to_program_space_and_thread (bl->pspace); | |
2801 | ||
2802 | /* For targets that support global breakpoints, there's no need | |
2803 | to select an inferior to insert breakpoint to. In fact, even | |
2804 | if we aren't attached to any process yet, we should still | |
2805 | insert breakpoints. */ | |
f5656ead | 2806 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2807 | && ptid_equal (inferior_ptid, null_ptid)) |
2808 | continue; | |
2809 | ||
2810 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2811 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2812 | if (val) |
2813 | error_flag = val; | |
2814 | } | |
2815 | ||
2816 | if (error_flag) | |
2817 | { | |
2818 | target_terminal_ours_for_output (); | |
2819 | error_stream (tmp_error_stream); | |
2820 | } | |
2821 | ||
2822 | do_cleanups (cleanups); | |
2823 | } | |
2824 | ||
c30eee59 | 2825 | /* Used when starting or continuing the program. */ |
c906108c | 2826 | |
74960c60 VP |
2827 | static void |
2828 | insert_breakpoint_locations (void) | |
c906108c | 2829 | { |
a5606eee | 2830 | struct breakpoint *bpt; |
35df4500 | 2831 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2832 | int error_flag = 0; |
c906108c | 2833 | int val = 0; |
3fbb6ffa | 2834 | int disabled_breaks = 0; |
81d0cc19 | 2835 | int hw_breakpoint_error = 0; |
dd61ec5c | 2836 | int hw_bp_error_explained_already = 0; |
c906108c | 2837 | |
81d0cc19 | 2838 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2839 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2840 | |
81d0cc19 GS |
2841 | /* Explicitly mark the warning -- this will only be printed if |
2842 | there was an error. */ | |
2843 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2844 | |
2845 | save_current_space_and_thread (); | |
2846 | ||
35df4500 | 2847 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2848 | { |
b775012e | 2849 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2850 | continue; |
2851 | ||
4a64f543 MS |
2852 | /* There is no point inserting thread-specific breakpoints if |
2853 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2854 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2855 | if (bl->owner->thread != -1 |
2856 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2857 | continue; |
2858 | ||
35df4500 | 2859 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2860 | |
2861 | /* For targets that support global breakpoints, there's no need | |
2862 | to select an inferior to insert breakpoint to. In fact, even | |
2863 | if we aren't attached to any process yet, we should still | |
2864 | insert breakpoints. */ | |
f5656ead | 2865 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2866 | && ptid_equal (inferior_ptid, null_ptid)) |
2867 | continue; | |
2868 | ||
3fbb6ffa | 2869 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2870 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2871 | if (val) |
eacd795a | 2872 | error_flag = val; |
879bfdc2 | 2873 | } |
c906108c | 2874 | |
4a64f543 MS |
2875 | /* If we failed to insert all locations of a watchpoint, remove |
2876 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2877 | ALL_BREAKPOINTS (bpt) |
2878 | { | |
2879 | int some_failed = 0; | |
2880 | struct bp_location *loc; | |
2881 | ||
2882 | if (!is_hardware_watchpoint (bpt)) | |
2883 | continue; | |
2884 | ||
d6b74ac4 | 2885 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2886 | continue; |
74960c60 VP |
2887 | |
2888 | if (bpt->disposition == disp_del_at_next_stop) | |
2889 | continue; | |
a5606eee VP |
2890 | |
2891 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2892 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2893 | { |
2894 | some_failed = 1; | |
2895 | break; | |
2896 | } | |
2897 | if (some_failed) | |
2898 | { | |
2899 | for (loc = bpt->loc; loc; loc = loc->next) | |
2900 | if (loc->inserted) | |
2901 | remove_breakpoint (loc, mark_uninserted); | |
2902 | ||
2903 | hw_breakpoint_error = 1; | |
2904 | fprintf_unfiltered (tmp_error_stream, | |
2905 | "Could not insert hardware watchpoint %d.\n", | |
2906 | bpt->number); | |
eacd795a | 2907 | error_flag = -1; |
a5606eee VP |
2908 | } |
2909 | } | |
2910 | ||
eacd795a | 2911 | if (error_flag) |
81d0cc19 GS |
2912 | { |
2913 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2914 | message about possibly exhausted resources. */ | |
dd61ec5c | 2915 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2916 | { |
c6510018 MS |
2917 | fprintf_unfiltered (tmp_error_stream, |
2918 | "Could not insert hardware breakpoints:\n\ | |
2919 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2920 | } |
81d0cc19 GS |
2921 | target_terminal_ours_for_output (); |
2922 | error_stream (tmp_error_stream); | |
2923 | } | |
f7545552 TT |
2924 | |
2925 | do_cleanups (cleanups); | |
c906108c SS |
2926 | } |
2927 | ||
c30eee59 TJB |
2928 | /* Used when the program stops. |
2929 | Returns zero if successful, or non-zero if there was a problem | |
2930 | removing a breakpoint location. */ | |
2931 | ||
c906108c | 2932 | int |
fba45db2 | 2933 | remove_breakpoints (void) |
c906108c | 2934 | { |
35df4500 | 2935 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2936 | int val = 0; |
c906108c | 2937 | |
35df4500 | 2938 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2939 | { |
1e4d1764 | 2940 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2941 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2942 | } |
3a1bae8e | 2943 | return val; |
c906108c SS |
2944 | } |
2945 | ||
49fa26b0 PA |
2946 | /* When a thread exits, remove breakpoints that are related to |
2947 | that thread. */ | |
2948 | ||
2949 | static void | |
2950 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
2951 | { | |
2952 | struct breakpoint *b, *b_tmp; | |
2953 | ||
2954 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
2955 | { | |
96181529 | 2956 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
2957 | { |
2958 | b->disposition = disp_del_at_next_stop; | |
2959 | ||
2960 | printf_filtered (_("\ | |
46ecd527 | 2961 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
2962 | b->number, tp->num); |
2963 | ||
2964 | /* Hide it from the user. */ | |
2965 | b->number = 0; | |
2966 | } | |
2967 | } | |
2968 | } | |
2969 | ||
6c95b8df PA |
2970 | /* Remove breakpoints of process PID. */ |
2971 | ||
2972 | int | |
2973 | remove_breakpoints_pid (int pid) | |
2974 | { | |
35df4500 | 2975 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2976 | int val; |
2977 | struct inferior *inf = find_inferior_pid (pid); | |
2978 | ||
35df4500 | 2979 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2980 | { |
35df4500 | 2981 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2982 | continue; |
2983 | ||
d3ce09f5 SS |
2984 | if (bl->owner->type == bp_dprintf) |
2985 | continue; | |
2986 | ||
35df4500 | 2987 | if (bl->inserted) |
6c95b8df | 2988 | { |
35df4500 | 2989 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2990 | if (val != 0) |
2991 | return val; | |
2992 | } | |
2993 | } | |
2994 | return 0; | |
2995 | } | |
2996 | ||
c906108c | 2997 | int |
fba45db2 | 2998 | reattach_breakpoints (int pid) |
c906108c | 2999 | { |
6c95b8df | 3000 | struct cleanup *old_chain; |
35df4500 | 3001 | struct bp_location *bl, **blp_tmp; |
c906108c | 3002 | int val; |
86b887df | 3003 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3004 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3005 | struct inferior *inf; |
3006 | struct thread_info *tp; | |
3007 | ||
3008 | tp = any_live_thread_of_process (pid); | |
3009 | if (tp == NULL) | |
3010 | return 1; | |
3011 | ||
3012 | inf = find_inferior_pid (pid); | |
3013 | old_chain = save_inferior_ptid (); | |
3014 | ||
3015 | inferior_ptid = tp->ptid; | |
a4954f26 | 3016 | |
86b887df | 3017 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3018 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3019 | |
35df4500 | 3020 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3021 | { |
35df4500 | 3022 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3023 | continue; |
3024 | ||
35df4500 | 3025 | if (bl->inserted) |
c5aa993b | 3026 | { |
35df4500 | 3027 | bl->inserted = 0; |
dd61ec5c | 3028 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3029 | if (val != 0) |
3030 | { | |
ce696e05 | 3031 | do_cleanups (old_chain); |
c5aa993b JM |
3032 | return val; |
3033 | } | |
3034 | } | |
3035 | } | |
ce696e05 | 3036 | do_cleanups (old_chain); |
c906108c SS |
3037 | return 0; |
3038 | } | |
3039 | ||
e58b0e63 PA |
3040 | static int internal_breakpoint_number = -1; |
3041 | ||
84f4c1fe PM |
3042 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3043 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3044 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3045 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3046 | breakpoint_count and that value incremented. Internal breakpoints |
3047 | do not set the internal var bpnum. */ | |
3048 | static void | |
3049 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3050 | { | |
3051 | if (internal) | |
3052 | b->number = internal_breakpoint_number--; | |
3053 | else | |
3054 | { | |
3055 | set_breakpoint_count (breakpoint_count + 1); | |
3056 | b->number = breakpoint_count; | |
3057 | } | |
3058 | } | |
3059 | ||
e62c965a | 3060 | static struct breakpoint * |
a6d9a66e | 3061 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3062 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3063 | const struct breakpoint_ops *ops) |
e62c965a | 3064 | { |
e62c965a PP |
3065 | struct symtab_and_line sal; |
3066 | struct breakpoint *b; | |
3067 | ||
4a64f543 | 3068 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3069 | |
3070 | sal.pc = address; | |
3071 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3072 | sal.pspace = current_program_space; |
e62c965a | 3073 | |
06edf0c0 | 3074 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3075 | b->number = internal_breakpoint_number--; |
3076 | b->disposition = disp_donttouch; | |
3077 | ||
3078 | return b; | |
3079 | } | |
3080 | ||
17450429 PP |
3081 | static const char *const longjmp_names[] = |
3082 | { | |
3083 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3084 | }; | |
3085 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3086 | ||
3087 | /* Per-objfile data private to breakpoint.c. */ | |
3088 | struct breakpoint_objfile_data | |
3089 | { | |
3090 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3091 | struct minimal_symbol *overlay_msym; | |
3092 | ||
3093 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3094 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
3095 | ||
28106bc2 SDJ |
3096 | /* True if we have looked for longjmp probes. */ |
3097 | int longjmp_searched; | |
3098 | ||
3099 | /* SystemTap probe points for longjmp (if any). */ | |
3100 | VEC (probe_p) *longjmp_probes; | |
3101 | ||
17450429 PP |
3102 | /* Minimal symbol for "std::terminate()" (if any). */ |
3103 | struct minimal_symbol *terminate_msym; | |
3104 | ||
3105 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3106 | struct minimal_symbol *exception_msym; | |
28106bc2 SDJ |
3107 | |
3108 | /* True if we have looked for exception probes. */ | |
3109 | int exception_searched; | |
3110 | ||
3111 | /* SystemTap probe points for unwinding (if any). */ | |
3112 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3113 | }; |
3114 | ||
3115 | static const struct objfile_data *breakpoint_objfile_key; | |
3116 | ||
3117 | /* Minimal symbol not found sentinel. */ | |
3118 | static struct minimal_symbol msym_not_found; | |
3119 | ||
3120 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3121 | ||
3122 | static int | |
3123 | msym_not_found_p (const struct minimal_symbol *msym) | |
3124 | { | |
3125 | return msym == &msym_not_found; | |
3126 | } | |
3127 | ||
3128 | /* Return per-objfile data needed by breakpoint.c. | |
3129 | Allocate the data if necessary. */ | |
3130 | ||
3131 | static struct breakpoint_objfile_data * | |
3132 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3133 | { | |
3134 | struct breakpoint_objfile_data *bp_objfile_data; | |
3135 | ||
3136 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3137 | if (bp_objfile_data == NULL) | |
3138 | { | |
3139 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3140 | sizeof (*bp_objfile_data)); | |
3141 | ||
3142 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3143 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3144 | } | |
3145 | return bp_objfile_data; | |
3146 | } | |
3147 | ||
28106bc2 SDJ |
3148 | static void |
3149 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3150 | { | |
3151 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3152 | ||
3153 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3154 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3155 | } | |
3156 | ||
e62c965a | 3157 | static void |
af02033e | 3158 | create_overlay_event_breakpoint (void) |
e62c965a | 3159 | { |
69de3c6a | 3160 | struct objfile *objfile; |
af02033e | 3161 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3162 | |
69de3c6a PP |
3163 | ALL_OBJFILES (objfile) |
3164 | { | |
3165 | struct breakpoint *b; | |
17450429 PP |
3166 | struct breakpoint_objfile_data *bp_objfile_data; |
3167 | CORE_ADDR addr; | |
69de3c6a | 3168 | |
17450429 PP |
3169 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3170 | ||
3171 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
3172 | continue; | |
3173 | ||
3174 | if (bp_objfile_data->overlay_msym == NULL) | |
3175 | { | |
3176 | struct minimal_symbol *m; | |
3177 | ||
3178 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3179 | if (m == NULL) | |
3180 | { | |
3181 | /* Avoid future lookups in this objfile. */ | |
3182 | bp_objfile_data->overlay_msym = &msym_not_found; | |
3183 | continue; | |
3184 | } | |
3185 | bp_objfile_data->overlay_msym = m; | |
3186 | } | |
e62c965a | 3187 | |
17450429 PP |
3188 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
3189 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3190 | bp_overlay_event, |
3191 | &internal_breakpoint_ops); | |
69de3c6a | 3192 | b->addr_string = xstrdup (func_name); |
e62c965a | 3193 | |
69de3c6a PP |
3194 | if (overlay_debugging == ovly_auto) |
3195 | { | |
3196 | b->enable_state = bp_enabled; | |
3197 | overlay_events_enabled = 1; | |
3198 | } | |
3199 | else | |
3200 | { | |
3201 | b->enable_state = bp_disabled; | |
3202 | overlay_events_enabled = 0; | |
3203 | } | |
e62c965a PP |
3204 | } |
3205 | update_global_location_list (1); | |
3206 | } | |
3207 | ||
0fd8e87f | 3208 | static void |
af02033e | 3209 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3210 | { |
6c95b8df | 3211 | struct program_space *pspace; |
6c95b8df PA |
3212 | struct cleanup *old_chain; |
3213 | ||
3214 | old_chain = save_current_program_space (); | |
0fd8e87f | 3215 | |
6c95b8df | 3216 | ALL_PSPACES (pspace) |
af02033e PP |
3217 | { |
3218 | struct objfile *objfile; | |
3219 | ||
3220 | set_current_program_space (pspace); | |
3221 | ||
3222 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3223 | { |
af02033e PP |
3224 | int i; |
3225 | struct gdbarch *gdbarch; | |
17450429 | 3226 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3227 | |
af02033e | 3228 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3229 | |
17450429 PP |
3230 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3231 | ||
28106bc2 SDJ |
3232 | if (!bp_objfile_data->longjmp_searched) |
3233 | { | |
25f9533e SDJ |
3234 | VEC (probe_p) *ret; |
3235 | ||
3236 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3237 | if (ret != NULL) | |
3238 | { | |
3239 | /* We are only interested in checking one element. */ | |
3240 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3241 | ||
3242 | if (!can_evaluate_probe_arguments (p)) | |
3243 | { | |
3244 | /* We cannot use the probe interface here, because it does | |
3245 | not know how to evaluate arguments. */ | |
3246 | VEC_free (probe_p, ret); | |
3247 | ret = NULL; | |
3248 | } | |
3249 | } | |
3250 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3251 | bp_objfile_data->longjmp_searched = 1; |
3252 | } | |
3253 | ||
3254 | if (bp_objfile_data->longjmp_probes != NULL) | |
3255 | { | |
3256 | int i; | |
3257 | struct probe *probe; | |
3258 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3259 | ||
3260 | for (i = 0; | |
3261 | VEC_iterate (probe_p, | |
3262 | bp_objfile_data->longjmp_probes, | |
3263 | i, probe); | |
3264 | ++i) | |
3265 | { | |
3266 | struct breakpoint *b; | |
3267 | ||
3268 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3269 | bp_longjmp_master, | |
3270 | &internal_breakpoint_ops); | |
3271 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3272 | b->enable_state = bp_disabled; | |
3273 | } | |
3274 | ||
3275 | continue; | |
3276 | } | |
3277 | ||
0569175e TSD |
3278 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3279 | continue; | |
3280 | ||
17450429 | 3281 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3282 | { |
3283 | struct breakpoint *b; | |
af02033e | 3284 | const char *func_name; |
17450429 | 3285 | CORE_ADDR addr; |
6c95b8df | 3286 | |
17450429 | 3287 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 3288 | continue; |
0fd8e87f | 3289 | |
17450429 PP |
3290 | func_name = longjmp_names[i]; |
3291 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
3292 | { | |
3293 | struct minimal_symbol *m; | |
3294 | ||
3295 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3296 | if (m == NULL) | |
3297 | { | |
3298 | /* Prevent future lookups in this objfile. */ | |
3299 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
3300 | continue; | |
3301 | } | |
3302 | bp_objfile_data->longjmp_msym[i] = m; | |
3303 | } | |
3304 | ||
3305 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
3306 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3307 | &internal_breakpoint_ops); | |
af02033e PP |
3308 | b->addr_string = xstrdup (func_name); |
3309 | b->enable_state = bp_disabled; | |
3310 | } | |
0fd8e87f | 3311 | } |
af02033e | 3312 | } |
0fd8e87f | 3313 | update_global_location_list (1); |
6c95b8df PA |
3314 | |
3315 | do_cleanups (old_chain); | |
0fd8e87f UW |
3316 | } |
3317 | ||
af02033e | 3318 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3319 | static void |
af02033e | 3320 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3321 | { |
3322 | struct program_space *pspace; | |
aa7d318d | 3323 | struct cleanup *old_chain; |
af02033e | 3324 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3325 | |
3326 | old_chain = save_current_program_space (); | |
3327 | ||
3328 | ALL_PSPACES (pspace) | |
17450429 PP |
3329 | { |
3330 | struct objfile *objfile; | |
3331 | CORE_ADDR addr; | |
3332 | ||
3333 | set_current_program_space (pspace); | |
3334 | ||
aa7d318d TT |
3335 | ALL_OBJFILES (objfile) |
3336 | { | |
3337 | struct breakpoint *b; | |
17450429 | 3338 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3339 | |
17450429 | 3340 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3341 | |
17450429 PP |
3342 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
3343 | continue; | |
3344 | ||
3345 | if (bp_objfile_data->terminate_msym == NULL) | |
3346 | { | |
3347 | struct minimal_symbol *m; | |
3348 | ||
3349 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3350 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
3351 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
3352 | { | |
3353 | /* Prevent future lookups in this objfile. */ | |
3354 | bp_objfile_data->terminate_msym = &msym_not_found; | |
3355 | continue; | |
3356 | } | |
3357 | bp_objfile_data->terminate_msym = m; | |
3358 | } | |
aa7d318d | 3359 | |
17450429 PP |
3360 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3361 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3362 | bp_std_terminate_master, |
3363 | &internal_breakpoint_ops); | |
aa7d318d TT |
3364 | b->addr_string = xstrdup (func_name); |
3365 | b->enable_state = bp_disabled; | |
3366 | } | |
17450429 PP |
3367 | } |
3368 | ||
aa7d318d TT |
3369 | update_global_location_list (1); |
3370 | ||
3371 | do_cleanups (old_chain); | |
3372 | } | |
3373 | ||
186c406b TT |
3374 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3375 | ||
70221824 | 3376 | static void |
186c406b TT |
3377 | create_exception_master_breakpoint (void) |
3378 | { | |
3379 | struct objfile *objfile; | |
17450429 | 3380 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3381 | |
3382 | ALL_OBJFILES (objfile) | |
3383 | { | |
17450429 PP |
3384 | struct breakpoint *b; |
3385 | struct gdbarch *gdbarch; | |
3386 | struct breakpoint_objfile_data *bp_objfile_data; | |
3387 | CORE_ADDR addr; | |
3388 | ||
3389 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3390 | ||
28106bc2 SDJ |
3391 | /* We prefer the SystemTap probe point if it exists. */ |
3392 | if (!bp_objfile_data->exception_searched) | |
3393 | { | |
25f9533e SDJ |
3394 | VEC (probe_p) *ret; |
3395 | ||
3396 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3397 | ||
3398 | if (ret != NULL) | |
3399 | { | |
3400 | /* We are only interested in checking one element. */ | |
3401 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3402 | ||
3403 | if (!can_evaluate_probe_arguments (p)) | |
3404 | { | |
3405 | /* We cannot use the probe interface here, because it does | |
3406 | not know how to evaluate arguments. */ | |
3407 | VEC_free (probe_p, ret); | |
3408 | ret = NULL; | |
3409 | } | |
3410 | } | |
3411 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3412 | bp_objfile_data->exception_searched = 1; |
3413 | } | |
3414 | ||
3415 | if (bp_objfile_data->exception_probes != NULL) | |
3416 | { | |
3417 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3418 | int i; | |
3419 | struct probe *probe; | |
3420 | ||
3421 | for (i = 0; | |
3422 | VEC_iterate (probe_p, | |
3423 | bp_objfile_data->exception_probes, | |
3424 | i, probe); | |
3425 | ++i) | |
3426 | { | |
3427 | struct breakpoint *b; | |
3428 | ||
3429 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3430 | bp_exception_master, | |
3431 | &internal_breakpoint_ops); | |
3432 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3433 | b->enable_state = bp_disabled; | |
3434 | } | |
3435 | ||
3436 | continue; | |
3437 | } | |
3438 | ||
3439 | /* Otherwise, try the hook function. */ | |
3440 | ||
17450429 PP |
3441 | if (msym_not_found_p (bp_objfile_data->exception_msym)) |
3442 | continue; | |
3443 | ||
3444 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3445 | |
17450429 | 3446 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 3447 | { |
17450429 | 3448 | struct minimal_symbol *debug_hook; |
186c406b | 3449 | |
17450429 PP |
3450 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3451 | if (debug_hook == NULL) | |
3452 | { | |
3453 | bp_objfile_data->exception_msym = &msym_not_found; | |
3454 | continue; | |
3455 | } | |
3456 | ||
3457 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3458 | } |
17450429 PP |
3459 | |
3460 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
3461 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
3462 | ¤t_target); | |
06edf0c0 PA |
3463 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3464 | &internal_breakpoint_ops); | |
17450429 PP |
3465 | b->addr_string = xstrdup (func_name); |
3466 | b->enable_state = bp_disabled; | |
186c406b TT |
3467 | } |
3468 | ||
3469 | update_global_location_list (1); | |
3470 | } | |
3471 | ||
c906108c | 3472 | void |
fba45db2 | 3473 | update_breakpoints_after_exec (void) |
c906108c | 3474 | { |
35df4500 | 3475 | struct breakpoint *b, *b_tmp; |
876fa593 | 3476 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3477 | |
25b22b0a PA |
3478 | /* We're about to delete breakpoints from GDB's lists. If the |
3479 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3480 | writing the breakpoints' "shadow contents" back into memory. The | |
3481 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3482 | do that. Instead, the target is responsible from marking | |
3483 | breakpoints out as soon as it detects an exec. We don't do that | |
3484 | here instead, because there may be other attempts to delete | |
3485 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3486 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3487 | if (bploc->pspace == current_program_space) |
3488 | gdb_assert (!bploc->inserted); | |
c906108c | 3489 | |
35df4500 | 3490 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3491 | { |
6c95b8df PA |
3492 | if (b->pspace != current_program_space) |
3493 | continue; | |
3494 | ||
4a64f543 | 3495 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3496 | if (b->type == bp_shlib_event) |
3497 | { | |
3498 | delete_breakpoint (b); | |
3499 | continue; | |
3500 | } | |
c906108c | 3501 | |
4a64f543 | 3502 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3503 | if (b->type == bp_jit_event) |
3504 | { | |
3505 | delete_breakpoint (b); | |
3506 | continue; | |
3507 | } | |
3508 | ||
1900040c | 3509 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3510 | as must overlay event and longjmp master breakpoints. */ |
3511 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3512 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3513 | || b->type == bp_exception_master) | |
c4093a6a JM |
3514 | { |
3515 | delete_breakpoint (b); | |
3516 | continue; | |
3517 | } | |
3518 | ||
4a64f543 | 3519 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3520 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3521 | { |
3522 | delete_breakpoint (b); | |
3523 | continue; | |
3524 | } | |
3525 | ||
611c83ae PA |
3526 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3527 | after an exec. */ | |
186c406b | 3528 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3529 | || b->type == bp_longjmp_call_dummy |
186c406b | 3530 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3531 | { |
3532 | delete_breakpoint (b); | |
3533 | continue; | |
3534 | } | |
3535 | ||
ce78b96d JB |
3536 | if (b->type == bp_catchpoint) |
3537 | { | |
3538 | /* For now, none of the bp_catchpoint breakpoints need to | |
3539 | do anything at this point. In the future, if some of | |
3540 | the catchpoints need to something, we will need to add | |
3541 | a new method, and call this method from here. */ | |
3542 | continue; | |
3543 | } | |
3544 | ||
c5aa993b JM |
3545 | /* bp_finish is a special case. The only way we ought to be able |
3546 | to see one of these when an exec() has happened, is if the user | |
3547 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3548 | carries them to the call-site of the current callee, by setting | |
3549 | a temporary bp there and resuming. But in this case, the finish | |
3550 | will carry them entirely through the vfork & exec. | |
3551 | ||
3552 | We don't want to allow a bp_finish to remain inserted now. But | |
3553 | we can't safely delete it, 'cause finish_command has a handle to | |
3554 | the bp on a bpstat, and will later want to delete it. There's a | |
3555 | chance (and I've seen it happen) that if we delete the bp_finish | |
3556 | here, that its storage will get reused by the time finish_command | |
3557 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3558 | We really must allow finish_command to delete a bp_finish. | |
3559 | ||
e5dd4106 | 3560 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3561 | it's safe to delete something others may have handles to?" |
3562 | problem, what we'll do here is just uninsert the bp_finish, and | |
3563 | let finish_command delete it. | |
3564 | ||
3565 | (We know the bp_finish is "doomed" in the sense that it's | |
3566 | momentary, and will be deleted as soon as finish_command sees | |
3567 | the inferior stopped. So it doesn't matter that the bp's | |
3568 | address is probably bogus in the new a.out, unlike e.g., the | |
3569 | solib breakpoints.) */ | |
c5aa993b | 3570 | |
c5aa993b JM |
3571 | if (b->type == bp_finish) |
3572 | { | |
3573 | continue; | |
3574 | } | |
3575 | ||
3576 | /* Without a symbolic address, we have little hope of the | |
3577 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3578 | a.out. */ |
c5aa993b JM |
3579 | if (b->addr_string == NULL) |
3580 | { | |
3581 | delete_breakpoint (b); | |
3582 | continue; | |
3583 | } | |
c5aa993b | 3584 | } |
1900040c | 3585 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3586 | create_overlay_event_breakpoint (); |
3587 | create_longjmp_master_breakpoint (); | |
3588 | create_std_terminate_master_breakpoint (); | |
186c406b | 3589 | create_exception_master_breakpoint (); |
c906108c SS |
3590 | } |
3591 | ||
3592 | int | |
d80ee84f | 3593 | detach_breakpoints (ptid_t ptid) |
c906108c | 3594 | { |
35df4500 | 3595 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3596 | int val = 0; |
ce696e05 | 3597 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3598 | struct inferior *inf = current_inferior (); |
c5aa993b | 3599 | |
dfd4cc63 | 3600 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3601 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3602 | |
6c95b8df | 3603 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3604 | inferior_ptid = ptid; |
35df4500 | 3605 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3606 | { |
35df4500 | 3607 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3608 | continue; |
3609 | ||
bd9673a4 PW |
3610 | /* This function must physically remove breakpoints locations |
3611 | from the specified ptid, without modifying the breakpoint | |
3612 | package's state. Locations of type bp_loc_other are only | |
3613 | maintained at GDB side. So, there is no need to remove | |
3614 | these bp_loc_other locations. Moreover, removing these | |
3615 | would modify the breakpoint package's state. */ | |
3616 | if (bl->loc_type == bp_loc_other) | |
3617 | continue; | |
3618 | ||
35df4500 TJB |
3619 | if (bl->inserted) |
3620 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3621 | } |
d03285ec UW |
3622 | |
3623 | /* Detach single-step breakpoints as well. */ | |
3624 | detach_single_step_breakpoints (); | |
3625 | ||
ce696e05 | 3626 | do_cleanups (old_chain); |
3a1bae8e | 3627 | return val; |
c906108c SS |
3628 | } |
3629 | ||
35df4500 | 3630 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3631 | Note that this is used to detach breakpoints from a child fork. |
3632 | When we get here, the child isn't in the inferior list, and neither | |
3633 | do we have objects to represent its address space --- we should | |
35df4500 | 3634 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3635 | |
c906108c | 3636 | static int |
35df4500 | 3637 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3638 | { |
3639 | int val; | |
c5aa993b | 3640 | |
35df4500 TJB |
3641 | /* BL is never in moribund_locations by our callers. */ |
3642 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3643 | |
35df4500 | 3644 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3645 | /* Permanent breakpoints cannot be inserted or removed. */ |
3646 | return 0; | |
3647 | ||
74960c60 VP |
3648 | /* The type of none suggests that owner is actually deleted. |
3649 | This should not ever happen. */ | |
35df4500 | 3650 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3651 | |
35df4500 TJB |
3652 | if (bl->loc_type == bp_loc_software_breakpoint |
3653 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3654 | { |
c02f5703 MS |
3655 | /* "Normal" instruction breakpoint: either the standard |
3656 | trap-instruction bp (bp_breakpoint), or a | |
3657 | bp_hardware_breakpoint. */ | |
3658 | ||
3659 | /* First check to see if we have to handle an overlay. */ | |
3660 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3661 | || bl->section == NULL |
3662 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3663 | { |
3664 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3665 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3666 | } |
c906108c SS |
3667 | else |
3668 | { | |
4a64f543 | 3669 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3670 | Did we set a breakpoint at the LMA? */ |
3671 | if (!overlay_events_enabled) | |
3672 | { | |
3673 | /* Yes -- overlay event support is not active, so we | |
3674 | should have set a breakpoint at the LMA. Remove it. | |
3675 | */ | |
c02f5703 MS |
3676 | /* Ignore any failures: if the LMA is in ROM, we will |
3677 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3678 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3679 | target_remove_hw_breakpoint (bl->gdbarch, | |
3680 | &bl->overlay_target_info); | |
c02f5703 | 3681 | else |
35df4500 TJB |
3682 | target_remove_breakpoint (bl->gdbarch, |
3683 | &bl->overlay_target_info); | |
c02f5703 MS |
3684 | } |
3685 | /* Did we set a breakpoint at the VMA? | |
3686 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3687 | if (bl->inserted) |
c906108c | 3688 | { |
c02f5703 MS |
3689 | /* Yes -- remove it. Previously we did not bother to |
3690 | remove the breakpoint if the section had been | |
3691 | unmapped, but let's not rely on that being safe. We | |
3692 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3693 | |
3694 | /* However, we should remove *software* breakpoints only | |
3695 | if the section is still mapped, or else we overwrite | |
3696 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3697 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3698 | || section_is_mapped (bl->section)) | |
3699 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3700 | else |
3701 | val = 0; | |
c906108c | 3702 | } |
c02f5703 MS |
3703 | else |
3704 | { | |
3705 | /* No -- not inserted, so no need to remove. No error. */ | |
3706 | val = 0; | |
3707 | } | |
c906108c | 3708 | } |
879d1e6b UW |
3709 | |
3710 | /* In some cases, we might not be able to remove a breakpoint | |
3711 | in a shared library that has already been removed, but we | |
3712 | have not yet processed the shlib unload event. */ | |
35df4500 | 3713 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3714 | val = 0; |
3715 | ||
c906108c SS |
3716 | if (val) |
3717 | return val; | |
35df4500 | 3718 | bl->inserted = (is == mark_inserted); |
c906108c | 3719 | } |
35df4500 | 3720 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3721 | { |
77b06cd7 TJB |
3722 | gdb_assert (bl->owner->ops != NULL |
3723 | && bl->owner->ops->remove_location != NULL); | |
3724 | ||
35df4500 | 3725 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3726 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3727 | |
c906108c | 3728 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3729 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3730 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3731 | bl->owner->number); |
c906108c | 3732 | } |
35df4500 TJB |
3733 | else if (bl->owner->type == bp_catchpoint |
3734 | && breakpoint_enabled (bl->owner) | |
3735 | && !bl->duplicate) | |
ce78b96d | 3736 | { |
77b06cd7 TJB |
3737 | gdb_assert (bl->owner->ops != NULL |
3738 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3739 | |
77b06cd7 | 3740 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3741 | if (val) |
3742 | return val; | |
77b06cd7 | 3743 | |
35df4500 | 3744 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3745 | } |
c906108c SS |
3746 | |
3747 | return 0; | |
3748 | } | |
3749 | ||
6c95b8df | 3750 | static int |
35df4500 | 3751 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3752 | { |
3753 | int ret; | |
3754 | struct cleanup *old_chain; | |
3755 | ||
35df4500 TJB |
3756 | /* BL is never in moribund_locations by our callers. */ |
3757 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3758 | |
35df4500 | 3759 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3760 | /* Permanent breakpoints cannot be inserted or removed. */ |
3761 | return 0; | |
3762 | ||
3763 | /* The type of none suggests that owner is actually deleted. | |
3764 | This should not ever happen. */ | |
35df4500 | 3765 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3766 | |
3767 | old_chain = save_current_space_and_thread (); | |
3768 | ||
35df4500 | 3769 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3770 | |
35df4500 | 3771 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3772 | |
3773 | do_cleanups (old_chain); | |
3774 | return ret; | |
3775 | } | |
3776 | ||
c906108c SS |
3777 | /* Clear the "inserted" flag in all breakpoints. */ |
3778 | ||
25b22b0a | 3779 | void |
fba45db2 | 3780 | mark_breakpoints_out (void) |
c906108c | 3781 | { |
35df4500 | 3782 | struct bp_location *bl, **blp_tmp; |
c906108c | 3783 | |
35df4500 TJB |
3784 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3785 | if (bl->pspace == current_program_space) | |
3786 | bl->inserted = 0; | |
c906108c SS |
3787 | } |
3788 | ||
53a5351d JM |
3789 | /* Clear the "inserted" flag in all breakpoints and delete any |
3790 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3791 | |
3792 | Plus other such housekeeping that has to be done for breakpoints | |
3793 | between runs. | |
3794 | ||
53a5351d JM |
3795 | Note: this function gets called at the end of a run (by |
3796 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3797 | init_wait_for_inferior). */ |
c906108c SS |
3798 | |
3799 | ||
3800 | ||
3801 | void | |
fba45db2 | 3802 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3803 | { |
35df4500 TJB |
3804 | struct breakpoint *b, *b_tmp; |
3805 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3806 | int ix; |
6c95b8df | 3807 | struct program_space *pspace = current_program_space; |
c906108c | 3808 | |
50c71eaf PA |
3809 | /* If breakpoint locations are shared across processes, then there's |
3810 | nothing to do. */ | |
f5656ead | 3811 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3812 | return; |
3813 | ||
35df4500 | 3814 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3815 | { |
35df4500 TJB |
3816 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3817 | if (bl->pspace == pspace | |
3818 | && bl->owner->enable_state != bp_permanent) | |
3819 | bl->inserted = 0; | |
6c95b8df | 3820 | } |
075f6582 | 3821 | |
35df4500 | 3822 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3823 | { |
6c95b8df PA |
3824 | if (b->loc && b->loc->pspace != pspace) |
3825 | continue; | |
3826 | ||
c5aa993b JM |
3827 | switch (b->type) |
3828 | { | |
3829 | case bp_call_dummy: | |
e2e4d78b | 3830 | case bp_longjmp_call_dummy: |
c906108c | 3831 | |
c5aa993b | 3832 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3833 | cause problems when the inferior is rerun, so we better get |
3834 | rid of it. */ | |
3835 | ||
3836 | case bp_watchpoint_scope: | |
3837 | ||
3838 | /* Also get rid of scope breakpoints. */ | |
3839 | ||
3840 | case bp_shlib_event: | |
3841 | ||
3842 | /* Also remove solib event breakpoints. Their addresses may | |
3843 | have changed since the last time we ran the program. | |
3844 | Actually we may now be debugging against different target; | |
3845 | and so the solib backend that installed this breakpoint may | |
3846 | not be used in by the target. E.g., | |
3847 | ||
3848 | (gdb) file prog-linux | |
3849 | (gdb) run # native linux target | |
3850 | ... | |
3851 | (gdb) kill | |
3852 | (gdb) file prog-win.exe | |
3853 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3854 | */ | |
c906108c | 3855 | |
f59f708a PA |
3856 | case bp_step_resume: |
3857 | ||
3858 | /* Also remove step-resume breakpoints. */ | |
3859 | ||
c5aa993b JM |
3860 | delete_breakpoint (b); |
3861 | break; | |
c906108c | 3862 | |
c5aa993b JM |
3863 | case bp_watchpoint: |
3864 | case bp_hardware_watchpoint: | |
3865 | case bp_read_watchpoint: | |
3866 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3867 | { |
3868 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3869 | |
3a5c3e22 PA |
3870 | /* Likewise for watchpoints on local expressions. */ |
3871 | if (w->exp_valid_block != NULL) | |
3872 | delete_breakpoint (b); | |
3873 | else if (context == inf_starting) | |
3874 | { | |
3875 | /* Reset val field to force reread of starting value in | |
3876 | insert_breakpoints. */ | |
3877 | if (w->val) | |
3878 | value_free (w->val); | |
3879 | w->val = NULL; | |
3880 | w->val_valid = 0; | |
c860120c | 3881 | } |
3a5c3e22 | 3882 | } |
c5aa993b JM |
3883 | break; |
3884 | default: | |
c5aa993b JM |
3885 | break; |
3886 | } | |
3887 | } | |
1c5cfe86 PA |
3888 | |
3889 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3890 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3891 | decref_bp_location (&bl); | |
1c5cfe86 | 3892 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3893 | } |
3894 | ||
6c95b8df PA |
3895 | /* These functions concern about actual breakpoints inserted in the |
3896 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3897 | we need to hop over the bkpt --- so we check for address space | |
3898 | match, not program space. */ | |
3899 | ||
c2c6d25f JM |
3900 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3901 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3902 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3903 | permanent breakpoint. | |
3904 | - When continuing from a location with an ordinary breakpoint, we | |
3905 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3906 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3907 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3908 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3909 | |
c2c6d25f | 3910 | enum breakpoint_here |
6c95b8df | 3911 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3912 | { |
35df4500 | 3913 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3914 | int any_breakpoint_here = 0; |
c906108c | 3915 | |
35df4500 | 3916 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3917 | { |
35df4500 TJB |
3918 | if (bl->loc_type != bp_loc_software_breakpoint |
3919 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3920 | continue; |
3921 | ||
f1310107 | 3922 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3923 | if ((breakpoint_enabled (bl->owner) |
3924 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3925 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3926 | { |
3927 | if (overlay_debugging | |
35df4500 TJB |
3928 | && section_is_overlay (bl->section) |
3929 | && !section_is_mapped (bl->section)) | |
075f6582 | 3930 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3931 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3932 | return permanent_breakpoint_here; |
3933 | else | |
3934 | any_breakpoint_here = 1; | |
3935 | } | |
3936 | } | |
c906108c | 3937 | |
c2c6d25f | 3938 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3939 | } |
3940 | ||
1c5cfe86 PA |
3941 | /* Return true if there's a moribund breakpoint at PC. */ |
3942 | ||
3943 | int | |
6c95b8df | 3944 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3945 | { |
3946 | struct bp_location *loc; | |
3947 | int ix; | |
3948 | ||
3949 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3950 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3951 | return 1; |
3952 | ||
3953 | return 0; | |
3954 | } | |
c2c6d25f | 3955 | |
c36b740a | 3956 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3957 | inserted using regular breakpoint_chain / bp_location array |
3958 | mechanism. This does not check for single-step breakpoints, which | |
3959 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3960 | |
3961 | int | |
4a64f543 MS |
3962 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3963 | CORE_ADDR pc) | |
c906108c | 3964 | { |
35df4500 | 3965 | struct bp_location *bl, **blp_tmp; |
c906108c | 3966 | |
35df4500 | 3967 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3968 | { |
35df4500 TJB |
3969 | if (bl->loc_type != bp_loc_software_breakpoint |
3970 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3971 | continue; |
3972 | ||
35df4500 | 3973 | if (bl->inserted |
f1310107 | 3974 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3975 | { |
3976 | if (overlay_debugging | |
35df4500 TJB |
3977 | && section_is_overlay (bl->section) |
3978 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3979 | continue; /* unmapped overlay -- can't be a match */ |
3980 | else | |
3981 | return 1; | |
3982 | } | |
c5aa993b | 3983 | } |
c36b740a VP |
3984 | return 0; |
3985 | } | |
3986 | ||
3987 | /* Returns non-zero iff there's either regular breakpoint | |
3988 | or a single step breakpoint inserted at PC. */ | |
3989 | ||
3990 | int | |
6c95b8df | 3991 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3992 | { |
6c95b8df | 3993 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3994 | return 1; |
c906108c | 3995 | |
6c95b8df | 3996 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3997 | return 1; |
3998 | ||
c906108c SS |
3999 | return 0; |
4000 | } | |
4001 | ||
4fa8626c DJ |
4002 | /* This function returns non-zero iff there is a software breakpoint |
4003 | inserted at PC. */ | |
4004 | ||
4005 | int | |
3e43a32a MS |
4006 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4007 | CORE_ADDR pc) | |
4fa8626c | 4008 | { |
35df4500 | 4009 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4010 | |
35df4500 | 4011 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4012 | { |
35df4500 | 4013 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4014 | continue; |
4015 | ||
35df4500 TJB |
4016 | if (bl->inserted |
4017 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4018 | aspace, pc)) |
4fa8626c DJ |
4019 | { |
4020 | if (overlay_debugging | |
35df4500 TJB |
4021 | && section_is_overlay (bl->section) |
4022 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4023 | continue; /* unmapped overlay -- can't be a match */ |
4024 | else | |
4025 | return 1; | |
4026 | } | |
4027 | } | |
4028 | ||
1aafd4da | 4029 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4030 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4031 | return 1; |
4032 | ||
4fa8626c DJ |
4033 | return 0; |
4034 | } | |
4035 | ||
9093389c PA |
4036 | int |
4037 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4038 | CORE_ADDR addr, ULONGEST len) | |
4039 | { | |
4040 | struct breakpoint *bpt; | |
4041 | ||
4042 | ALL_BREAKPOINTS (bpt) | |
4043 | { | |
4044 | struct bp_location *loc; | |
4045 | ||
4046 | if (bpt->type != bp_hardware_watchpoint | |
4047 | && bpt->type != bp_access_watchpoint) | |
4048 | continue; | |
4049 | ||
4050 | if (!breakpoint_enabled (bpt)) | |
4051 | continue; | |
4052 | ||
4053 | for (loc = bpt->loc; loc; loc = loc->next) | |
4054 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4055 | { | |
4056 | CORE_ADDR l, h; | |
4057 | ||
4058 | /* Check for intersection. */ | |
4059 | l = max (loc->address, addr); | |
4060 | h = min (loc->address + loc->length, addr + len); | |
4061 | if (l < h) | |
4062 | return 1; | |
4063 | } | |
4064 | } | |
4065 | return 0; | |
4066 | } | |
4067 | ||
075f6582 DJ |
4068 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4069 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4070 | |
4071 | int | |
6c95b8df PA |
4072 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4073 | ptid_t ptid) | |
c906108c | 4074 | { |
35df4500 | 4075 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4076 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4077 | int thread = -1; |
4a306c9a | 4078 | int task = 0; |
a6f1cd96 | 4079 | |
35df4500 | 4080 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4081 | { |
35df4500 TJB |
4082 | if (bl->loc_type != bp_loc_software_breakpoint |
4083 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4084 | continue; |
4085 | ||
35df4500 TJB |
4086 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4087 | if (!breakpoint_enabled (bl->owner) | |
4088 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4089 | continue; |
4090 | ||
f1310107 | 4091 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4092 | continue; |
4093 | ||
35df4500 | 4094 | if (bl->owner->thread != -1) |
075f6582 | 4095 | { |
a6f1cd96 JB |
4096 | /* This is a thread-specific breakpoint. Check that ptid |
4097 | matches that thread. If thread hasn't been computed yet, | |
4098 | it is now time to do so. */ | |
4099 | if (thread == -1) | |
4100 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4101 | if (bl->owner->thread != thread) |
a6f1cd96 | 4102 | continue; |
075f6582 | 4103 | } |
a6f1cd96 | 4104 | |
35df4500 | 4105 | if (bl->owner->task != 0) |
4a306c9a JB |
4106 | { |
4107 | /* This is a task-specific breakpoint. Check that ptid | |
4108 | matches that task. If task hasn't been computed yet, | |
4109 | it is now time to do so. */ | |
4110 | if (task == 0) | |
4111 | task = ada_get_task_number (ptid); | |
35df4500 | 4112 | if (bl->owner->task != task) |
4a306c9a JB |
4113 | continue; |
4114 | } | |
4115 | ||
a6f1cd96 | 4116 | if (overlay_debugging |
35df4500 TJB |
4117 | && section_is_overlay (bl->section) |
4118 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4119 | continue; /* unmapped overlay -- can't be a match */ |
4120 | ||
4121 | return 1; | |
c5aa993b | 4122 | } |
c906108c SS |
4123 | |
4124 | return 0; | |
4125 | } | |
c906108c | 4126 | \f |
c5aa993b | 4127 | |
c906108c SS |
4128 | /* bpstat stuff. External routines' interfaces are documented |
4129 | in breakpoint.h. */ | |
4130 | ||
4131 | int | |
c326b90e | 4132 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4133 | { |
533be4dd | 4134 | return (ep->type == bp_catchpoint); |
c906108c SS |
4135 | } |
4136 | ||
f431efe5 PA |
4137 | /* Frees any storage that is part of a bpstat. Does not walk the |
4138 | 'next' chain. */ | |
4139 | ||
4140 | static void | |
198757a8 VP |
4141 | bpstat_free (bpstat bs) |
4142 | { | |
4143 | if (bs->old_val != NULL) | |
4144 | value_free (bs->old_val); | |
9add0f1b | 4145 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4146 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4147 | xfree (bs); |
4148 | } | |
4149 | ||
c906108c SS |
4150 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4151 | Also free any storage that is part of a bpstat. */ | |
4152 | ||
4153 | void | |
fba45db2 | 4154 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4155 | { |
4156 | bpstat p; | |
4157 | bpstat q; | |
4158 | ||
4159 | if (bsp == 0) | |
4160 | return; | |
4161 | p = *bsp; | |
4162 | while (p != NULL) | |
4163 | { | |
4164 | q = p->next; | |
198757a8 | 4165 | bpstat_free (p); |
c906108c SS |
4166 | p = q; |
4167 | } | |
4168 | *bsp = NULL; | |
4169 | } | |
4170 | ||
4171 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4172 | is part of the bpstat is copied as well. */ | |
4173 | ||
4174 | bpstat | |
fba45db2 | 4175 | bpstat_copy (bpstat bs) |
c906108c SS |
4176 | { |
4177 | bpstat p = NULL; | |
4178 | bpstat tmp; | |
4179 | bpstat retval = NULL; | |
4180 | ||
4181 | if (bs == NULL) | |
4182 | return bs; | |
4183 | ||
4184 | for (; bs != NULL; bs = bs->next) | |
4185 | { | |
4186 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4187 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4188 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4189 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4190 | if (bs->old_val != NULL) |
3c3185ac JK |
4191 | { |
4192 | tmp->old_val = value_copy (bs->old_val); | |
4193 | release_value (tmp->old_val); | |
4194 | } | |
31cc81e9 | 4195 | |
c906108c SS |
4196 | if (p == NULL) |
4197 | /* This is the first thing in the chain. */ | |
4198 | retval = tmp; | |
4199 | else | |
4200 | p->next = tmp; | |
4201 | p = tmp; | |
4202 | } | |
4203 | p->next = NULL; | |
4204 | return retval; | |
4205 | } | |
4206 | ||
4a64f543 | 4207 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4208 | |
4209 | bpstat | |
fba45db2 | 4210 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4211 | { |
c5aa993b JM |
4212 | if (bsp == NULL) |
4213 | return NULL; | |
c906108c | 4214 | |
c5aa993b JM |
4215 | for (; bsp != NULL; bsp = bsp->next) |
4216 | { | |
f431efe5 | 4217 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4218 | return bsp; |
4219 | } | |
c906108c SS |
4220 | return NULL; |
4221 | } | |
4222 | ||
ab04a2af TT |
4223 | /* See breakpoint.h. */ |
4224 | ||
4225 | enum bpstat_signal_value | |
427cd150 | 4226 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af TT |
4227 | { |
4228 | enum bpstat_signal_value result = BPSTAT_SIGNAL_NO; | |
4229 | ||
4230 | for (; bsp != NULL; bsp = bsp->next) | |
4231 | { | |
4232 | /* Ensure that, if we ever entered this loop, then we at least | |
4233 | return BPSTAT_SIGNAL_HIDE. */ | |
427cd150 | 4234 | enum bpstat_signal_value newval; |
ab04a2af | 4235 | |
427cd150 TT |
4236 | if (bsp->breakpoint_at == NULL) |
4237 | { | |
4238 | /* A moribund location can never explain a signal other than | |
4239 | GDB_SIGNAL_TRAP. */ | |
4240 | if (sig == GDB_SIGNAL_TRAP) | |
4241 | newval = BPSTAT_SIGNAL_HIDE; | |
4242 | else | |
4243 | newval = BPSTAT_SIGNAL_NO; | |
4244 | } | |
4245 | else | |
4246 | newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4247 | sig); | |
ab04a2af TT |
4248 | |
4249 | if (newval > result) | |
4250 | result = newval; | |
4251 | } | |
4252 | ||
4253 | return result; | |
4254 | } | |
4255 | ||
4a64f543 MS |
4256 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4257 | stopped at. *BSP upon return is a bpstat which points to the | |
4258 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4259 | good for anything but further calls to bpstat_num). | |
4260 | ||
8671a17b PA |
4261 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4262 | Return -1 if stopped at a breakpoint that has been deleted since | |
4263 | we set it. | |
4264 | Return 1 otherwise. */ | |
c906108c SS |
4265 | |
4266 | int | |
8671a17b | 4267 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4268 | { |
4269 | struct breakpoint *b; | |
4270 | ||
4271 | if ((*bsp) == NULL) | |
4272 | return 0; /* No more breakpoint values */ | |
8671a17b | 4273 | |
4a64f543 MS |
4274 | /* We assume we'll never have several bpstats that correspond to a |
4275 | single breakpoint -- otherwise, this function might return the | |
4276 | same number more than once and this will look ugly. */ | |
f431efe5 | 4277 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4278 | *bsp = (*bsp)->next; |
4279 | if (b == NULL) | |
4280 | return -1; /* breakpoint that's been deleted since */ | |
4281 | ||
4282 | *num = b->number; /* We have its number */ | |
4283 | return 1; | |
c906108c SS |
4284 | } |
4285 | ||
e93ca019 | 4286 | /* See breakpoint.h. */ |
c906108c SS |
4287 | |
4288 | void | |
e93ca019 | 4289 | bpstat_clear_actions (void) |
c906108c | 4290 | { |
e93ca019 JK |
4291 | struct thread_info *tp; |
4292 | bpstat bs; | |
4293 | ||
4294 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4295 | return; | |
4296 | ||
4297 | tp = find_thread_ptid (inferior_ptid); | |
4298 | if (tp == NULL) | |
4299 | return; | |
4300 | ||
4301 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4302 | { |
9add0f1b | 4303 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4304 | |
c906108c SS |
4305 | if (bs->old_val != NULL) |
4306 | { | |
4307 | value_free (bs->old_val); | |
4308 | bs->old_val = NULL; | |
4309 | } | |
4310 | } | |
4311 | } | |
4312 | ||
f3b1572e PA |
4313 | /* Called when a command is about to proceed the inferior. */ |
4314 | ||
4315 | static void | |
4316 | breakpoint_about_to_proceed (void) | |
4317 | { | |
4318 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4319 | { | |
4320 | struct thread_info *tp = inferior_thread (); | |
4321 | ||
4322 | /* Allow inferior function calls in breakpoint commands to not | |
4323 | interrupt the command list. When the call finishes | |
4324 | successfully, the inferior will be standing at the same | |
4325 | breakpoint as if nothing happened. */ | |
16c381f0 | 4326 | if (tp->control.in_infcall) |
f3b1572e PA |
4327 | return; |
4328 | } | |
4329 | ||
4330 | breakpoint_proceeded = 1; | |
4331 | } | |
4332 | ||
4a64f543 MS |
4333 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4334 | command. */ | |
c906108c | 4335 | static void |
4efb68b1 | 4336 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4337 | { |
4338 | executing_breakpoint_commands = 0; | |
4339 | } | |
4340 | ||
abf85f46 JK |
4341 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4342 | or its equivalent. */ | |
4343 | ||
4344 | static int | |
4345 | command_line_is_silent (struct command_line *cmd) | |
4346 | { | |
4347 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4348 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4349 | } | |
4350 | ||
4a64f543 MS |
4351 | /* Execute all the commands associated with all the breakpoints at |
4352 | this location. Any of these commands could cause the process to | |
4353 | proceed beyond this point, etc. We look out for such changes by | |
4354 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4355 | |
347bddb7 PA |
4356 | Returns true if a breakpoint command resumed the inferior. In that |
4357 | case, it is the caller's responsibility to recall it again with the | |
4358 | bpstat of the current thread. */ | |
4359 | ||
4360 | static int | |
4361 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4362 | { |
4363 | bpstat bs; | |
4364 | struct cleanup *old_chain; | |
347bddb7 | 4365 | int again = 0; |
c906108c SS |
4366 | |
4367 | /* Avoid endless recursion if a `source' command is contained | |
4368 | in bs->commands. */ | |
4369 | if (executing_breakpoint_commands) | |
347bddb7 | 4370 | return 0; |
c906108c SS |
4371 | |
4372 | executing_breakpoint_commands = 1; | |
4373 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4374 | ||
cf6c5ffb TT |
4375 | prevent_dont_repeat (); |
4376 | ||
4a64f543 | 4377 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4378 | bs = *bsp; |
4379 | ||
4380 | breakpoint_proceeded = 0; | |
4381 | for (; bs != NULL; bs = bs->next) | |
4382 | { | |
9add0f1b | 4383 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4384 | struct command_line *cmd; |
4385 | struct cleanup *this_cmd_tree_chain; | |
4386 | ||
4387 | /* Take ownership of the BSP's command tree, if it has one. | |
4388 | ||
4389 | The command tree could legitimately contain commands like | |
4390 | 'step' and 'next', which call clear_proceed_status, which | |
4391 | frees stop_bpstat's command tree. To make sure this doesn't | |
4392 | free the tree we're executing out from under us, we need to | |
4393 | take ownership of the tree ourselves. Since a given bpstat's | |
4394 | commands are only executed once, we don't need to copy it; we | |
4395 | can clear the pointer in the bpstat, and make sure we free | |
4396 | the tree when we're done. */ | |
9add0f1b TT |
4397 | ccmd = bs->commands; |
4398 | bs->commands = NULL; | |
abf85f46 JK |
4399 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4400 | cmd = ccmd ? ccmd->commands : NULL; | |
4401 | if (command_line_is_silent (cmd)) | |
4402 | { | |
4403 | /* The action has been already done by bpstat_stop_status. */ | |
4404 | cmd = cmd->next; | |
4405 | } | |
6c50ab1c | 4406 | |
c906108c SS |
4407 | while (cmd != NULL) |
4408 | { | |
4409 | execute_control_command (cmd); | |
4410 | ||
4411 | if (breakpoint_proceeded) | |
4412 | break; | |
4413 | else | |
4414 | cmd = cmd->next; | |
4415 | } | |
6c50ab1c JB |
4416 | |
4417 | /* We can free this command tree now. */ | |
4418 | do_cleanups (this_cmd_tree_chain); | |
4419 | ||
c906108c | 4420 | if (breakpoint_proceeded) |
32c1e744 VP |
4421 | { |
4422 | if (target_can_async_p ()) | |
347bddb7 PA |
4423 | /* If we are in async mode, then the target might be still |
4424 | running, not stopped at any breakpoint, so nothing for | |
4425 | us to do here -- just return to the event loop. */ | |
4426 | ; | |
32c1e744 VP |
4427 | else |
4428 | /* In sync mode, when execute_control_command returns | |
4429 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4430 | Breakpoint commands for that stop were not run, since |
4431 | execute_command does not run breakpoint commands -- | |
4432 | only command_line_handler does, but that one is not | |
4433 | involved in execution of breakpoint commands. So, we | |
4434 | can now execute breakpoint commands. It should be | |
4435 | noted that making execute_command do bpstat actions is | |
4436 | not an option -- in this case we'll have recursive | |
4437 | invocation of bpstat for each breakpoint with a | |
4438 | command, and can easily blow up GDB stack. Instead, we | |
4439 | return true, which will trigger the caller to recall us | |
4440 | with the new stop_bpstat. */ | |
4441 | again = 1; | |
4442 | break; | |
32c1e744 | 4443 | } |
c906108c | 4444 | } |
c2b8ed2c | 4445 | do_cleanups (old_chain); |
347bddb7 PA |
4446 | return again; |
4447 | } | |
4448 | ||
4449 | void | |
4450 | bpstat_do_actions (void) | |
4451 | { | |
353d1d73 JK |
4452 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4453 | ||
347bddb7 PA |
4454 | /* Do any commands attached to breakpoint we are stopped at. */ |
4455 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4456 | && target_has_execution | |
4457 | && !is_exited (inferior_ptid) | |
4458 | && !is_executing (inferior_ptid)) | |
4459 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4460 | and only return when it is stopped at the next breakpoint, we | |
4461 | keep doing breakpoint actions until it returns false to | |
4462 | indicate the inferior was not resumed. */ | |
16c381f0 | 4463 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4464 | break; |
353d1d73 JK |
4465 | |
4466 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4467 | } |
4468 | ||
fa4727a6 DJ |
4469 | /* Print out the (old or new) value associated with a watchpoint. */ |
4470 | ||
4471 | static void | |
4472 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4473 | { | |
4474 | if (val == NULL) | |
4475 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4476 | else | |
79a45b7d TT |
4477 | { |
4478 | struct value_print_options opts; | |
4479 | get_user_print_options (&opts); | |
4480 | value_print (val, stream, &opts); | |
4481 | } | |
fa4727a6 DJ |
4482 | } |
4483 | ||
e514a9d6 | 4484 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4485 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4486 | 'print_it' in the bpstat structure. Under some circumstances we |
4487 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4488 | normal_stop(). */ |
e514a9d6 JM |
4489 | |
4490 | static enum print_stop_action | |
4491 | print_bp_stop_message (bpstat bs) | |
4492 | { | |
4493 | switch (bs->print_it) | |
4494 | { | |
4495 | case print_it_noop: | |
4a64f543 | 4496 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4497 | return PRINT_UNKNOWN; |
4498 | break; | |
4499 | ||
4500 | case print_it_done: | |
4501 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4502 | relevant messages. */ |
e514a9d6 JM |
4503 | return PRINT_SRC_AND_LOC; |
4504 | break; | |
4505 | ||
4506 | case print_it_normal: | |
4f8d1dc6 | 4507 | { |
f431efe5 PA |
4508 | struct breakpoint *b = bs->breakpoint_at; |
4509 | ||
1a6a67de TJB |
4510 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4511 | which has since been deleted. */ | |
4512 | if (b == NULL) | |
4513 | return PRINT_UNKNOWN; | |
4514 | ||
348d480f PA |
4515 | /* Normal case. Call the breakpoint's print_it method. */ |
4516 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4517 | } |
348d480f | 4518 | break; |
3086aeae | 4519 | |
e514a9d6 | 4520 | default: |
8e65ff28 | 4521 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4522 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4523 | break; |
c906108c | 4524 | } |
c906108c SS |
4525 | } |
4526 | ||
edcc5120 TT |
4527 | /* A helper function that prints a shared library stopped event. */ |
4528 | ||
4529 | static void | |
4530 | print_solib_event (int is_catchpoint) | |
4531 | { | |
4532 | int any_deleted | |
4533 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4534 | int any_added | |
4535 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4536 | ||
4537 | if (!is_catchpoint) | |
4538 | { | |
4539 | if (any_added || any_deleted) | |
4540 | ui_out_text (current_uiout, | |
4541 | _("Stopped due to shared library event:\n")); | |
4542 | else | |
4543 | ui_out_text (current_uiout, | |
4544 | _("Stopped due to shared library event (no " | |
4545 | "libraries added or removed)\n")); | |
4546 | } | |
4547 | ||
4548 | if (ui_out_is_mi_like_p (current_uiout)) | |
4549 | ui_out_field_string (current_uiout, "reason", | |
4550 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4551 | ||
4552 | if (any_deleted) | |
4553 | { | |
4554 | struct cleanup *cleanup; | |
4555 | char *name; | |
4556 | int ix; | |
4557 | ||
4558 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4559 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4560 | "removed"); | |
4561 | for (ix = 0; | |
4562 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4563 | ix, name); | |
4564 | ++ix) | |
4565 | { | |
4566 | if (ix > 0) | |
4567 | ui_out_text (current_uiout, " "); | |
4568 | ui_out_field_string (current_uiout, "library", name); | |
4569 | ui_out_text (current_uiout, "\n"); | |
4570 | } | |
4571 | ||
4572 | do_cleanups (cleanup); | |
4573 | } | |
4574 | ||
4575 | if (any_added) | |
4576 | { | |
4577 | struct so_list *iter; | |
4578 | int ix; | |
4579 | struct cleanup *cleanup; | |
4580 | ||
4581 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4582 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4583 | "added"); | |
4584 | for (ix = 0; | |
4585 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4586 | ix, iter); | |
4587 | ++ix) | |
4588 | { | |
4589 | if (ix > 0) | |
4590 | ui_out_text (current_uiout, " "); | |
4591 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4592 | ui_out_text (current_uiout, "\n"); | |
4593 | } | |
4594 | ||
4595 | do_cleanups (cleanup); | |
4596 | } | |
4597 | } | |
4598 | ||
e514a9d6 JM |
4599 | /* Print a message indicating what happened. This is called from |
4600 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4601 | list - a list of the eventpoints that caused this stop. KIND is |
4602 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4603 | routine calls the generic print routine for printing a message |
4604 | about reasons for stopping. This will print (for example) the | |
4605 | "Breakpoint n," part of the output. The return value of this | |
4606 | routine is one of: | |
c906108c | 4607 | |
4a64f543 | 4608 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4609 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4610 | code to print the location. An example is |
c5aa993b JM |
4611 | "Breakpoint 1, " which should be followed by |
4612 | the location. | |
917317f4 | 4613 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4614 | to also print the location part of the message. |
4615 | An example is the catch/throw messages, which | |
4a64f543 | 4616 | don't require a location appended to the end. |
917317f4 | 4617 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4618 | further info to be printed. */ |
c906108c | 4619 | |
917317f4 | 4620 | enum print_stop_action |
36dfb11c | 4621 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4622 | { |
4623 | int val; | |
c5aa993b | 4624 | |
c906108c | 4625 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4626 | (Currently all watchpoints go on the bpstat whether hit or not. |
4627 | That probably could (should) be changed, provided care is taken | |
c906108c | 4628 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4629 | for (; bs; bs = bs->next) |
4630 | { | |
4631 | val = print_bp_stop_message (bs); | |
4632 | if (val == PRINT_SRC_ONLY | |
4633 | || val == PRINT_SRC_AND_LOC | |
4634 | || val == PRINT_NOTHING) | |
4635 | return val; | |
4636 | } | |
c906108c | 4637 | |
36dfb11c TT |
4638 | /* If we had hit a shared library event breakpoint, |
4639 | print_bp_stop_message would print out this message. If we hit an | |
4640 | OS-level shared library event, do the same thing. */ | |
4641 | if (kind == TARGET_WAITKIND_LOADED) | |
4642 | { | |
edcc5120 | 4643 | print_solib_event (0); |
36dfb11c TT |
4644 | return PRINT_NOTHING; |
4645 | } | |
4646 | ||
e514a9d6 | 4647 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4648 | with and nothing was printed. */ |
917317f4 | 4649 | return PRINT_UNKNOWN; |
c906108c SS |
4650 | } |
4651 | ||
4a64f543 MS |
4652 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4653 | used inside a catch_errors to evaluate the breakpoint condition. | |
4654 | The argument is a "struct expression *" that has been cast to a | |
4655 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4656 | |
4657 | static int | |
4efb68b1 | 4658 | breakpoint_cond_eval (void *exp) |
c906108c | 4659 | { |
278cd55f | 4660 | struct value *mark = value_mark (); |
c5aa993b | 4661 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4662 | |
c906108c SS |
4663 | value_free_to_mark (mark); |
4664 | return i; | |
4665 | } | |
4666 | ||
5760d0ab | 4667 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4668 | |
4669 | static bpstat | |
5760d0ab | 4670 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4671 | { |
4672 | bpstat bs; | |
4673 | ||
4674 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4675 | bs->next = NULL; |
4676 | **bs_link_pointer = bs; | |
4677 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4678 | bs->breakpoint_at = bl->owner; |
4679 | bs->bp_location_at = bl; | |
4680 | incref_bp_location (bl); | |
c906108c SS |
4681 | /* If the condition is false, etc., don't do the commands. */ |
4682 | bs->commands = NULL; | |
4683 | bs->old_val = NULL; | |
4684 | bs->print_it = print_it_normal; | |
4685 | return bs; | |
4686 | } | |
4687 | \f | |
d983da9c DJ |
4688 | /* The target has stopped with waitstatus WS. Check if any hardware |
4689 | watchpoints have triggered, according to the target. */ | |
4690 | ||
4691 | int | |
4692 | watchpoints_triggered (struct target_waitstatus *ws) | |
4693 | { | |
d92524f1 | 4694 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4695 | CORE_ADDR addr; |
4696 | struct breakpoint *b; | |
4697 | ||
4698 | if (!stopped_by_watchpoint) | |
4699 | { | |
4700 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4701 | as not triggered. */ | |
4702 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4703 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4704 | { |
4705 | struct watchpoint *w = (struct watchpoint *) b; | |
4706 | ||
4707 | w->watchpoint_triggered = watch_triggered_no; | |
4708 | } | |
d983da9c DJ |
4709 | |
4710 | return 0; | |
4711 | } | |
4712 | ||
4713 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4714 | { | |
4715 | /* We were stopped by a watchpoint, but we don't know where. | |
4716 | Mark all watchpoints as unknown. */ | |
4717 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4718 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4719 | { |
4720 | struct watchpoint *w = (struct watchpoint *) b; | |
4721 | ||
4722 | w->watchpoint_triggered = watch_triggered_unknown; | |
4723 | } | |
d983da9c | 4724 | |
3c4797ba | 4725 | return 1; |
d983da9c DJ |
4726 | } |
4727 | ||
4728 | /* The target could report the data address. Mark watchpoints | |
4729 | affected by this data address as triggered, and all others as not | |
4730 | triggered. */ | |
4731 | ||
4732 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4733 | if (is_hardware_watchpoint (b)) |
d983da9c | 4734 | { |
3a5c3e22 | 4735 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4736 | struct bp_location *loc; |
d983da9c | 4737 | |
3a5c3e22 | 4738 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4739 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4740 | { |
3a5c3e22 | 4741 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4742 | { |
3a5c3e22 PA |
4743 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4744 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4745 | |
4746 | if (newaddr == start) | |
4747 | { | |
3a5c3e22 | 4748 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4749 | break; |
4750 | } | |
4751 | } | |
4752 | /* Exact match not required. Within range is sufficient. */ | |
4753 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4754 | addr, loc->address, | |
4755 | loc->length)) | |
4756 | { | |
3a5c3e22 | 4757 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4758 | break; |
4759 | } | |
4760 | } | |
d983da9c DJ |
4761 | } |
4762 | ||
4763 | return 1; | |
4764 | } | |
4765 | ||
c906108c SS |
4766 | /* Possible return values for watchpoint_check (this can't be an enum |
4767 | because of check_errors). */ | |
4768 | /* The watchpoint has been deleted. */ | |
4769 | #define WP_DELETED 1 | |
4770 | /* The value has changed. */ | |
4771 | #define WP_VALUE_CHANGED 2 | |
4772 | /* The value has not changed. */ | |
4773 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4774 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4775 | #define WP_IGNORE 4 | |
c906108c SS |
4776 | |
4777 | #define BP_TEMPFLAG 1 | |
4778 | #define BP_HARDWAREFLAG 2 | |
4779 | ||
4a64f543 MS |
4780 | /* Evaluate watchpoint condition expression and check if its value |
4781 | changed. | |
553e4c11 JB |
4782 | |
4783 | P should be a pointer to struct bpstat, but is defined as a void * | |
4784 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4785 | |
4786 | static int | |
4efb68b1 | 4787 | watchpoint_check (void *p) |
c906108c SS |
4788 | { |
4789 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4790 | struct watchpoint *b; |
c906108c SS |
4791 | struct frame_info *fr; |
4792 | int within_current_scope; | |
4793 | ||
f431efe5 | 4794 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4795 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4796 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4797 | |
f6bc2008 PA |
4798 | /* If this is a local watchpoint, we only want to check if the |
4799 | watchpoint frame is in scope if the current thread is the thread | |
4800 | that was used to create the watchpoint. */ | |
4801 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4802 | return WP_IGNORE; |
f6bc2008 | 4803 | |
c906108c SS |
4804 | if (b->exp_valid_block == NULL) |
4805 | within_current_scope = 1; | |
4806 | else | |
4807 | { | |
edb3359d DJ |
4808 | struct frame_info *frame = get_current_frame (); |
4809 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4810 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4811 | ||
4a64f543 MS |
4812 | /* in_function_epilogue_p() returns a non-zero value if we're |
4813 | still in the function but the stack frame has already been | |
4814 | invalidated. Since we can't rely on the values of local | |
4815 | variables after the stack has been destroyed, we are treating | |
4816 | the watchpoint in that state as `not changed' without further | |
4817 | checking. Don't mark watchpoints as changed if the current | |
4818 | frame is in an epilogue - even if they are in some other | |
4819 | frame, our view of the stack is likely to be wrong and | |
4820 | frame_find_by_id could error out. */ | |
a0f49112 | 4821 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4822 | return WP_IGNORE; |
a0f49112 | 4823 | |
101dcfbe | 4824 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4825 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4826 | |
4827 | /* If we've gotten confused in the unwinder, we might have | |
4828 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4829 | if (within_current_scope) |
4830 | { | |
4831 | struct symbol *function; | |
4832 | ||
4833 | function = get_frame_function (fr); | |
4834 | if (function == NULL | |
4835 | || !contained_in (b->exp_valid_block, | |
4836 | SYMBOL_BLOCK_VALUE (function))) | |
4837 | within_current_scope = 0; | |
4838 | } | |
69fbadd5 | 4839 | |
edb3359d | 4840 | if (within_current_scope) |
c906108c SS |
4841 | /* If we end up stopping, the current frame will get selected |
4842 | in normal_stop. So this call to select_frame won't affect | |
4843 | the user. */ | |
0f7d239c | 4844 | select_frame (fr); |
c906108c | 4845 | } |
c5aa993b | 4846 | |
c906108c SS |
4847 | if (within_current_scope) |
4848 | { | |
4a64f543 MS |
4849 | /* We use value_{,free_to_}mark because it could be a *long* |
4850 | time before we return to the command level and call | |
4851 | free_all_values. We can't call free_all_values because we | |
4852 | might be in the middle of evaluating a function call. */ | |
c906108c | 4853 | |
0cf6dd15 | 4854 | int pc = 0; |
9c06b0b4 | 4855 | struct value *mark; |
fa4727a6 DJ |
4856 | struct value *new_val; |
4857 | ||
3a5c3e22 | 4858 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4859 | /* Since we don't know the exact trigger address (from |
4860 | stopped_data_address), just tell the user we've triggered | |
4861 | a mask watchpoint. */ | |
4862 | return WP_VALUE_CHANGED; | |
4863 | ||
4864 | mark = value_mark (); | |
3a1115a0 | 4865 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4866 | |
4a64f543 MS |
4867 | /* We use value_equal_contents instead of value_equal because |
4868 | the latter coerces an array to a pointer, thus comparing just | |
4869 | the address of the array instead of its contents. This is | |
4870 | not what we want. */ | |
fa4727a6 | 4871 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4872 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4873 | { |
fa4727a6 DJ |
4874 | if (new_val != NULL) |
4875 | { | |
4876 | release_value (new_val); | |
4877 | value_free_to_mark (mark); | |
4878 | } | |
c906108c SS |
4879 | bs->old_val = b->val; |
4880 | b->val = new_val; | |
fa4727a6 | 4881 | b->val_valid = 1; |
c906108c SS |
4882 | return WP_VALUE_CHANGED; |
4883 | } | |
4884 | else | |
4885 | { | |
60e1c644 | 4886 | /* Nothing changed. */ |
c906108c | 4887 | value_free_to_mark (mark); |
c906108c SS |
4888 | return WP_VALUE_NOT_CHANGED; |
4889 | } | |
4890 | } | |
4891 | else | |
4892 | { | |
79a45e25 PA |
4893 | struct ui_out *uiout = current_uiout; |
4894 | ||
c906108c | 4895 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4896 | if we temporarily ignored the watchpoint, then when |
4897 | we reenter the block in which it is valid it contains | |
4898 | garbage (in the case of a function, it may have two | |
4899 | garbage values, one before and one after the prologue). | |
4900 | So we can't even detect the first assignment to it and | |
4901 | watch after that (since the garbage may or may not equal | |
4902 | the first value assigned). */ | |
348d480f PA |
4903 | /* We print all the stop information in |
4904 | breakpoint_ops->print_it, but in this case, by the time we | |
4905 | call breakpoint_ops->print_it this bp will be deleted | |
4906 | already. So we have no choice but print the information | |
4907 | here. */ | |
9dc5e2a9 | 4908 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4909 | ui_out_field_string |
4910 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4911 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4912 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4913 | ui_out_text (uiout, |
4914 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4915 | which its expression is valid.\n"); |
4ce44c66 | 4916 | |
cdac0397 | 4917 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4918 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4919 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4920 | |
4921 | return WP_DELETED; | |
4922 | } | |
4923 | } | |
4924 | ||
18a18393 | 4925 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4926 | breakpoint location BL. This function does not check if we should |
4927 | stop, only if BL explains the stop. */ | |
4928 | ||
18a18393 | 4929 | static int |
6c95b8df | 4930 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4931 | struct address_space *aspace, CORE_ADDR bp_addr, |
4932 | const struct target_waitstatus *ws) | |
18a18393 VP |
4933 | { |
4934 | struct breakpoint *b = bl->owner; | |
4935 | ||
348d480f | 4936 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4937 | gdb_assert (b != NULL); |
4938 | ||
09ac7c10 | 4939 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4940 | } |
4941 | ||
3a5c3e22 PA |
4942 | /* Determine if the watched values have actually changed, and we |
4943 | should stop. If not, set BS->stop to 0. */ | |
4944 | ||
18a18393 VP |
4945 | static void |
4946 | bpstat_check_watchpoint (bpstat bs) | |
4947 | { | |
2bdf28a0 | 4948 | const struct bp_location *bl; |
3a5c3e22 | 4949 | struct watchpoint *b; |
2bdf28a0 JK |
4950 | |
4951 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4952 | bl = bs->bp_location_at; |
2bdf28a0 | 4953 | gdb_assert (bl != NULL); |
3a5c3e22 | 4954 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4955 | gdb_assert (b != NULL); |
18a18393 | 4956 | |
18a18393 | 4957 | { |
18a18393 VP |
4958 | int must_check_value = 0; |
4959 | ||
3a5c3e22 | 4960 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4961 | /* For a software watchpoint, we must always check the |
4962 | watched value. */ | |
4963 | must_check_value = 1; | |
4964 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4965 | /* We have a hardware watchpoint (read, write, or access) | |
4966 | and the target earlier reported an address watched by | |
4967 | this watchpoint. */ | |
4968 | must_check_value = 1; | |
4969 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4970 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4971 | /* We were stopped by a hardware watchpoint, but the target could |
4972 | not report the data address. We must check the watchpoint's | |
4973 | value. Access and read watchpoints are out of luck; without | |
4974 | a data address, we can't figure it out. */ | |
4975 | must_check_value = 1; | |
3a5c3e22 | 4976 | |
18a18393 VP |
4977 | if (must_check_value) |
4978 | { | |
3e43a32a MS |
4979 | char *message |
4980 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4981 | b->base.number); |
18a18393 VP |
4982 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4983 | int e = catch_errors (watchpoint_check, bs, message, | |
4984 | RETURN_MASK_ALL); | |
4985 | do_cleanups (cleanups); | |
4986 | switch (e) | |
4987 | { | |
4988 | case WP_DELETED: | |
4989 | /* We've already printed what needs to be printed. */ | |
4990 | bs->print_it = print_it_done; | |
4991 | /* Stop. */ | |
4992 | break; | |
60e1c644 PA |
4993 | case WP_IGNORE: |
4994 | bs->print_it = print_it_noop; | |
4995 | bs->stop = 0; | |
4996 | break; | |
18a18393 | 4997 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4998 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4999 | { |
85d721b8 PA |
5000 | /* There are two cases to consider here: |
5001 | ||
4a64f543 | 5002 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5003 | In that case, trust the target, and always report |
5004 | the watchpoint hit to the user. Even though | |
5005 | reads don't cause value changes, the value may | |
5006 | have changed since the last time it was read, and | |
5007 | since we're not trapping writes, we will not see | |
5008 | those, and as such we should ignore our notion of | |
5009 | old value. | |
5010 | ||
4a64f543 | 5011 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5012 | reads and writes. There are two ways this may |
5013 | happen: | |
5014 | ||
4a64f543 | 5015 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5016 | reads only, but can break on accesses (reads or |
5017 | writes), such as e.g., x86. We detect this case | |
5018 | at the time we try to insert read watchpoints. | |
5019 | ||
4a64f543 | 5020 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5021 | watchpoints, but, the user set an access or write |
5022 | watchpoint watching the same memory as this read | |
5023 | watchpoint. | |
5024 | ||
5025 | If we're watching memory writes as well as reads, | |
5026 | ignore watchpoint hits when we find that the | |
5027 | value hasn't changed, as reads don't cause | |
5028 | changes. This still gives false positives when | |
5029 | the program writes the same value to memory as | |
5030 | what there was already in memory (we will confuse | |
5031 | it for a read), but it's much better than | |
5032 | nothing. */ | |
5033 | ||
5034 | int other_write_watchpoint = 0; | |
5035 | ||
5036 | if (bl->watchpoint_type == hw_read) | |
5037 | { | |
5038 | struct breakpoint *other_b; | |
5039 | ||
5040 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5041 | if (other_b->type == bp_hardware_watchpoint |
5042 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5043 | { |
3a5c3e22 PA |
5044 | struct watchpoint *other_w = |
5045 | (struct watchpoint *) other_b; | |
5046 | ||
5047 | if (other_w->watchpoint_triggered | |
5048 | == watch_triggered_yes) | |
5049 | { | |
5050 | other_write_watchpoint = 1; | |
5051 | break; | |
5052 | } | |
85d721b8 PA |
5053 | } |
5054 | } | |
5055 | ||
5056 | if (other_write_watchpoint | |
5057 | || bl->watchpoint_type == hw_access) | |
5058 | { | |
5059 | /* We're watching the same memory for writes, | |
5060 | and the value changed since the last time we | |
5061 | updated it, so this trap must be for a write. | |
5062 | Ignore it. */ | |
5063 | bs->print_it = print_it_noop; | |
5064 | bs->stop = 0; | |
5065 | } | |
18a18393 VP |
5066 | } |
5067 | break; | |
5068 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5069 | if (b->base.type == bp_hardware_watchpoint |
5070 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5071 | { |
5072 | /* Don't stop: write watchpoints shouldn't fire if | |
5073 | the value hasn't changed. */ | |
5074 | bs->print_it = print_it_noop; | |
5075 | bs->stop = 0; | |
5076 | } | |
5077 | /* Stop. */ | |
5078 | break; | |
5079 | default: | |
5080 | /* Can't happen. */ | |
5081 | case 0: | |
5082 | /* Error from catch_errors. */ | |
3a5c3e22 | 5083 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5084 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5085 | /* We've already printed what needs to be printed. */ |
5086 | bs->print_it = print_it_done; | |
5087 | break; | |
5088 | } | |
5089 | } | |
5090 | else /* must_check_value == 0 */ | |
5091 | { | |
5092 | /* This is a case where some watchpoint(s) triggered, but | |
5093 | not at the address of this watchpoint, or else no | |
5094 | watchpoint triggered after all. So don't print | |
5095 | anything for this watchpoint. */ | |
5096 | bs->print_it = print_it_noop; | |
5097 | bs->stop = 0; | |
5098 | } | |
5099 | } | |
5100 | } | |
5101 | ||
7d4df6a4 DE |
5102 | /* For breakpoints that are currently marked as telling gdb to stop, |
5103 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5104 | of breakpoint referred to by BS. If we should not stop for this |
5105 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5106 | |
18a18393 VP |
5107 | static void |
5108 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5109 | { | |
5110 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
5111 | const struct bp_location *bl; |
5112 | struct breakpoint *b; | |
7d4df6a4 DE |
5113 | int value_is_zero = 0; |
5114 | struct expression *cond; | |
5115 | ||
5116 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5117 | |
5118 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5119 | bl = bs->bp_location_at; |
2bdf28a0 | 5120 | gdb_assert (bl != NULL); |
f431efe5 | 5121 | b = bs->breakpoint_at; |
2bdf28a0 | 5122 | gdb_assert (b != NULL); |
18a18393 | 5123 | |
b775012e LM |
5124 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5125 | need to do so again since GDB does not know if we stopped due to a | |
5126 | breakpoint or a single step breakpoint. */ | |
5127 | ||
18a18393 | 5128 | if (frame_id_p (b->frame_id) |
edb3359d | 5129 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5130 | { |
7d4df6a4 DE |
5131 | bs->stop = 0; |
5132 | return; | |
5133 | } | |
60e1c644 | 5134 | |
7d4df6a4 DE |
5135 | /* Evaluate Python breakpoints that have a "stop" method implemented. */ |
5136 | if (b->py_bp_object) | |
5137 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
7371cf6d | 5138 | |
7d4df6a4 DE |
5139 | if (is_watchpoint (b)) |
5140 | { | |
5141 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5142 | |
7d4df6a4 DE |
5143 | cond = w->cond_exp; |
5144 | } | |
5145 | else | |
5146 | cond = bl->cond; | |
60e1c644 | 5147 | |
7d4df6a4 DE |
5148 | if (cond && b->disposition != disp_del_at_next_stop) |
5149 | { | |
5150 | int within_current_scope = 1; | |
5151 | struct watchpoint * w; | |
60e1c644 | 5152 | |
7d4df6a4 DE |
5153 | /* We use value_mark and value_free_to_mark because it could |
5154 | be a long time before we return to the command level and | |
5155 | call free_all_values. We can't call free_all_values | |
5156 | because we might be in the middle of evaluating a | |
5157 | function call. */ | |
5158 | struct value *mark = value_mark (); | |
5159 | ||
5160 | if (is_watchpoint (b)) | |
5161 | w = (struct watchpoint *) b; | |
5162 | else | |
5163 | w = NULL; | |
5164 | ||
5165 | /* Need to select the frame, with all that implies so that | |
5166 | the conditions will have the right context. Because we | |
5167 | use the frame, we will not see an inlined function's | |
5168 | variables when we arrive at a breakpoint at the start | |
5169 | of the inlined function; the current frame will be the | |
5170 | call site. */ | |
5171 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5172 | select_frame (get_current_frame ()); | |
5173 | else | |
18a18393 | 5174 | { |
7d4df6a4 DE |
5175 | struct frame_info *frame; |
5176 | ||
5177 | /* For local watchpoint expressions, which particular | |
5178 | instance of a local is being watched matters, so we | |
5179 | keep track of the frame to evaluate the expression | |
5180 | in. To evaluate the condition however, it doesn't | |
5181 | really matter which instantiation of the function | |
5182 | where the condition makes sense triggers the | |
5183 | watchpoint. This allows an expression like "watch | |
5184 | global if q > 10" set in `func', catch writes to | |
5185 | global on all threads that call `func', or catch | |
5186 | writes on all recursive calls of `func' by a single | |
5187 | thread. We simply always evaluate the condition in | |
5188 | the innermost frame that's executing where it makes | |
5189 | sense to evaluate the condition. It seems | |
5190 | intuitive. */ | |
5191 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5192 | if (frame != NULL) | |
5193 | select_frame (frame); | |
5194 | else | |
5195 | within_current_scope = 0; | |
18a18393 | 5196 | } |
7d4df6a4 DE |
5197 | if (within_current_scope) |
5198 | value_is_zero | |
5199 | = catch_errors (breakpoint_cond_eval, cond, | |
5200 | "Error in testing breakpoint condition:\n", | |
5201 | RETURN_MASK_ALL); | |
5202 | else | |
18a18393 | 5203 | { |
7d4df6a4 DE |
5204 | warning (_("Watchpoint condition cannot be tested " |
5205 | "in the current scope")); | |
5206 | /* If we failed to set the right context for this | |
5207 | watchpoint, unconditionally report it. */ | |
5208 | value_is_zero = 0; | |
18a18393 | 5209 | } |
7d4df6a4 DE |
5210 | /* FIXME-someday, should give breakpoint #. */ |
5211 | value_free_to_mark (mark); | |
18a18393 | 5212 | } |
7d4df6a4 DE |
5213 | |
5214 | if (cond && value_is_zero) | |
5215 | { | |
5216 | bs->stop = 0; | |
5217 | } | |
5218 | else if (b->thread != -1 && b->thread != thread_id) | |
5219 | { | |
5220 | bs->stop = 0; | |
5221 | } | |
5222 | else if (b->ignore_count > 0) | |
5223 | { | |
5224 | b->ignore_count--; | |
5225 | bs->stop = 0; | |
5226 | /* Increase the hit count even though we don't stop. */ | |
5227 | ++(b->hit_count); | |
5228 | observer_notify_breakpoint_modified (b); | |
5229 | } | |
18a18393 VP |
5230 | } |
5231 | ||
5232 | ||
9709f61c | 5233 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5234 | BP_ADDR in thread PTID. |
c906108c | 5235 | |
d983da9c | 5236 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5237 | don't understand this stop. Result is a chain of bpstat's such |
5238 | that: | |
c906108c | 5239 | |
c5aa993b | 5240 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5241 | |
c5aa993b | 5242 | if we understand why we stopped, the result is not null. |
c906108c | 5243 | |
c5aa993b JM |
5244 | Each element of the chain refers to a particular breakpoint or |
5245 | watchpoint at which we have stopped. (We may have stopped for | |
5246 | several reasons concurrently.) | |
c906108c | 5247 | |
c5aa993b JM |
5248 | Each element of the chain has valid next, breakpoint_at, |
5249 | commands, FIXME??? fields. */ | |
c906108c SS |
5250 | |
5251 | bpstat | |
6c95b8df | 5252 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5253 | CORE_ADDR bp_addr, ptid_t ptid, |
5254 | const struct target_waitstatus *ws) | |
c906108c | 5255 | { |
0d381245 | 5256 | struct breakpoint *b = NULL; |
afe38095 | 5257 | struct bp_location *bl; |
20874c92 | 5258 | struct bp_location *loc; |
5760d0ab JK |
5259 | /* First item of allocated bpstat's. */ |
5260 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5261 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5262 | bpstat bs; |
20874c92 | 5263 | int ix; |
429374b8 | 5264 | int need_remove_insert; |
f431efe5 | 5265 | int removed_any; |
c906108c | 5266 | |
f431efe5 PA |
5267 | /* First, build the bpstat chain with locations that explain a |
5268 | target stop, while being careful to not set the target running, | |
5269 | as that may invalidate locations (in particular watchpoint | |
5270 | locations are recreated). Resuming will happen here with | |
5271 | breakpoint conditions or watchpoint expressions that include | |
5272 | inferior function calls. */ | |
c5aa993b | 5273 | |
429374b8 JK |
5274 | ALL_BREAKPOINTS (b) |
5275 | { | |
5276 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5277 | continue; | |
a5606eee | 5278 | |
429374b8 JK |
5279 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5280 | { | |
4a64f543 MS |
5281 | /* For hardware watchpoints, we look only at the first |
5282 | location. The watchpoint_check function will work on the | |
5283 | entire expression, not the individual locations. For | |
5284 | read watchpoints, the watchpoints_triggered function has | |
5285 | checked all locations already. */ | |
429374b8 JK |
5286 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5287 | break; | |
18a18393 | 5288 | |
f6592439 | 5289 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5290 | continue; |
c5aa993b | 5291 | |
09ac7c10 | 5292 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5293 | continue; |
c5aa993b | 5294 | |
4a64f543 MS |
5295 | /* Come here if it's a watchpoint, or if the break address |
5296 | matches. */ | |
c5aa993b | 5297 | |
4a64f543 MS |
5298 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5299 | explain stop. */ | |
c5aa993b | 5300 | |
f431efe5 PA |
5301 | /* Assume we stop. Should we find a watchpoint that is not |
5302 | actually triggered, or if the condition of the breakpoint | |
5303 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5304 | bs->stop = 1; |
5305 | bs->print = 1; | |
d983da9c | 5306 | |
f431efe5 PA |
5307 | /* If this is a scope breakpoint, mark the associated |
5308 | watchpoint as triggered so that we will handle the | |
5309 | out-of-scope event. We'll get to the watchpoint next | |
5310 | iteration. */ | |
d0fb5eae | 5311 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5312 | { |
5313 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5314 | ||
5315 | w->watchpoint_triggered = watch_triggered_yes; | |
5316 | } | |
f431efe5 PA |
5317 | } |
5318 | } | |
5319 | ||
5320 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5321 | { | |
f1310107 | 5322 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5323 | { |
5760d0ab | 5324 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5325 | /* For hits of moribund locations, we should just proceed. */ |
5326 | bs->stop = 0; | |
5327 | bs->print = 0; | |
5328 | bs->print_it = print_it_noop; | |
5329 | } | |
5330 | } | |
5331 | ||
edcc5120 TT |
5332 | /* A bit of special processing for shlib breakpoints. We need to |
5333 | process solib loading here, so that the lists of loaded and | |
5334 | unloaded libraries are correct before we handle "catch load" and | |
5335 | "catch unload". */ | |
5336 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5337 | { | |
5d268276 | 5338 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5339 | { |
5340 | handle_solib_event (); | |
5341 | break; | |
5342 | } | |
5343 | } | |
5344 | ||
f431efe5 PA |
5345 | /* Now go through the locations that caused the target to stop, and |
5346 | check whether we're interested in reporting this stop to higher | |
5347 | layers, or whether we should resume the target transparently. */ | |
5348 | ||
5349 | removed_any = 0; | |
5350 | ||
5760d0ab | 5351 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5352 | { |
5353 | if (!bs->stop) | |
5354 | continue; | |
5355 | ||
f431efe5 | 5356 | b = bs->breakpoint_at; |
348d480f PA |
5357 | b->ops->check_status (bs); |
5358 | if (bs->stop) | |
28010a5d | 5359 | { |
348d480f | 5360 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5361 | |
429374b8 JK |
5362 | if (bs->stop) |
5363 | { | |
5364 | ++(b->hit_count); | |
8d3788bd | 5365 | observer_notify_breakpoint_modified (b); |
c906108c | 5366 | |
4a64f543 | 5367 | /* We will stop here. */ |
429374b8 JK |
5368 | if (b->disposition == disp_disable) |
5369 | { | |
816338b5 SS |
5370 | --(b->enable_count); |
5371 | if (b->enable_count <= 0 | |
5372 | && b->enable_state != bp_permanent) | |
429374b8 | 5373 | b->enable_state = bp_disabled; |
f431efe5 | 5374 | removed_any = 1; |
429374b8 JK |
5375 | } |
5376 | if (b->silent) | |
5377 | bs->print = 0; | |
5378 | bs->commands = b->commands; | |
9add0f1b | 5379 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5380 | if (command_line_is_silent (bs->commands |
5381 | ? bs->commands->commands : NULL)) | |
5382 | bs->print = 0; | |
9d6e6e84 HZ |
5383 | |
5384 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5385 | } |
5386 | ||
348d480f | 5387 | } |
a9b3a50f PA |
5388 | |
5389 | /* Print nothing for this entry if we don't stop or don't | |
5390 | print. */ | |
5391 | if (!bs->stop || !bs->print) | |
5392 | bs->print_it = print_it_noop; | |
429374b8 | 5393 | } |
876fa593 | 5394 | |
d983da9c DJ |
5395 | /* If we aren't stopping, the value of some hardware watchpoint may |
5396 | not have changed, but the intermediate memory locations we are | |
5397 | watching may have. Don't bother if we're stopping; this will get | |
5398 | done later. */ | |
d832cb68 | 5399 | need_remove_insert = 0; |
5760d0ab JK |
5400 | if (! bpstat_causes_stop (bs_head)) |
5401 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5402 | if (!bs->stop |
f431efe5 PA |
5403 | && bs->breakpoint_at |
5404 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5405 | { |
3a5c3e22 PA |
5406 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5407 | ||
5408 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5409 | need_remove_insert = 1; |
d983da9c DJ |
5410 | } |
5411 | ||
d832cb68 | 5412 | if (need_remove_insert) |
2d134ed3 | 5413 | update_global_location_list (1); |
f431efe5 PA |
5414 | else if (removed_any) |
5415 | update_global_location_list (0); | |
d832cb68 | 5416 | |
5760d0ab | 5417 | return bs_head; |
c906108c | 5418 | } |
628fe4e4 JK |
5419 | |
5420 | static void | |
5421 | handle_jit_event (void) | |
5422 | { | |
5423 | struct frame_info *frame; | |
5424 | struct gdbarch *gdbarch; | |
5425 | ||
5426 | /* Switch terminal for any messages produced by | |
5427 | breakpoint_re_set. */ | |
5428 | target_terminal_ours_for_output (); | |
5429 | ||
5430 | frame = get_current_frame (); | |
5431 | gdbarch = get_frame_arch (frame); | |
5432 | ||
5433 | jit_event_handler (gdbarch); | |
5434 | ||
5435 | target_terminal_inferior (); | |
5436 | } | |
5437 | ||
5438 | /* Prepare WHAT final decision for infrun. */ | |
5439 | ||
5440 | /* Decide what infrun needs to do with this bpstat. */ | |
5441 | ||
c906108c | 5442 | struct bpstat_what |
0e30163f | 5443 | bpstat_what (bpstat bs_head) |
c906108c | 5444 | { |
c906108c | 5445 | struct bpstat_what retval; |
628fe4e4 | 5446 | int jit_event = 0; |
0e30163f | 5447 | bpstat bs; |
c906108c | 5448 | |
628fe4e4 | 5449 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5450 | retval.call_dummy = STOP_NONE; |
186c406b | 5451 | retval.is_longjmp = 0; |
628fe4e4 | 5452 | |
0e30163f | 5453 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5454 | { |
628fe4e4 JK |
5455 | /* Extract this BS's action. After processing each BS, we check |
5456 | if its action overrides all we've seem so far. */ | |
5457 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5458 | enum bptype bptype; | |
5459 | ||
c906108c | 5460 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5461 | { |
5462 | /* I suspect this can happen if it was a momentary | |
5463 | breakpoint which has since been deleted. */ | |
5464 | bptype = bp_none; | |
5465 | } | |
20874c92 | 5466 | else |
f431efe5 | 5467 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5468 | |
5469 | switch (bptype) | |
c906108c SS |
5470 | { |
5471 | case bp_none: | |
628fe4e4 | 5472 | break; |
c906108c SS |
5473 | case bp_breakpoint: |
5474 | case bp_hardware_breakpoint: | |
5475 | case bp_until: | |
5476 | case bp_finish: | |
a9b3a50f | 5477 | case bp_shlib_event: |
c906108c SS |
5478 | if (bs->stop) |
5479 | { | |
5480 | if (bs->print) | |
628fe4e4 | 5481 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5482 | else |
628fe4e4 | 5483 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5484 | } |
5485 | else | |
628fe4e4 | 5486 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5487 | break; |
5488 | case bp_watchpoint: | |
5489 | case bp_hardware_watchpoint: | |
5490 | case bp_read_watchpoint: | |
5491 | case bp_access_watchpoint: | |
5492 | if (bs->stop) | |
5493 | { | |
5494 | if (bs->print) | |
628fe4e4 | 5495 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5496 | else |
628fe4e4 | 5497 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5498 | } |
5499 | else | |
628fe4e4 JK |
5500 | { |
5501 | /* There was a watchpoint, but we're not stopping. | |
5502 | This requires no further action. */ | |
5503 | } | |
c906108c SS |
5504 | break; |
5505 | case bp_longjmp: | |
e2e4d78b | 5506 | case bp_longjmp_call_dummy: |
186c406b | 5507 | case bp_exception: |
628fe4e4 | 5508 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5509 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5510 | break; |
5511 | case bp_longjmp_resume: | |
186c406b | 5512 | case bp_exception_resume: |
628fe4e4 | 5513 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5514 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5515 | break; |
5516 | case bp_step_resume: | |
5517 | if (bs->stop) | |
628fe4e4 JK |
5518 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5519 | else | |
c906108c | 5520 | { |
628fe4e4 JK |
5521 | /* It is for the wrong frame. */ |
5522 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5523 | } |
c906108c | 5524 | break; |
2c03e5be PA |
5525 | case bp_hp_step_resume: |
5526 | if (bs->stop) | |
5527 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5528 | else | |
5529 | { | |
5530 | /* It is for the wrong frame. */ | |
5531 | this_action = BPSTAT_WHAT_SINGLE; | |
5532 | } | |
5533 | break; | |
c906108c | 5534 | case bp_watchpoint_scope: |
c4093a6a | 5535 | case bp_thread_event: |
1900040c | 5536 | case bp_overlay_event: |
0fd8e87f | 5537 | case bp_longjmp_master: |
aa7d318d | 5538 | case bp_std_terminate_master: |
186c406b | 5539 | case bp_exception_master: |
628fe4e4 | 5540 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5541 | break; |
ce78b96d | 5542 | case bp_catchpoint: |
c5aa993b JM |
5543 | if (bs->stop) |
5544 | { | |
5545 | if (bs->print) | |
628fe4e4 | 5546 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5547 | else |
628fe4e4 | 5548 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5549 | } |
5550 | else | |
628fe4e4 JK |
5551 | { |
5552 | /* There was a catchpoint, but we're not stopping. | |
5553 | This requires no further action. */ | |
5554 | } | |
5555 | break; | |
628fe4e4 JK |
5556 | case bp_jit_event: |
5557 | jit_event = 1; | |
5558 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5559 | break; |
c906108c | 5560 | case bp_call_dummy: |
53a5351d JM |
5561 | /* Make sure the action is stop (silent or noisy), |
5562 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5563 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5564 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5565 | break; |
5566 | case bp_std_terminate: | |
5567 | /* Make sure the action is stop (silent or noisy), | |
5568 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5569 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5570 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5571 | break; |
1042e4c0 | 5572 | case bp_tracepoint: |
7a697b8d | 5573 | case bp_fast_tracepoint: |
0fb4aa4b | 5574 | case bp_static_tracepoint: |
1042e4c0 SS |
5575 | /* Tracepoint hits should not be reported back to GDB, and |
5576 | if one got through somehow, it should have been filtered | |
5577 | out already. */ | |
5578 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5579 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5580 | break; |
5581 | case bp_gnu_ifunc_resolver: | |
5582 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5583 | this_action = BPSTAT_WHAT_SINGLE; | |
5584 | break; | |
5585 | case bp_gnu_ifunc_resolver_return: | |
5586 | /* The breakpoint will be removed, execution will restart from the | |
5587 | PC of the former breakpoint. */ | |
5588 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5589 | break; | |
e7e0cddf SS |
5590 | |
5591 | case bp_dprintf: | |
a11cfd87 HZ |
5592 | if (bs->stop) |
5593 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5594 | else | |
5595 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5596 | break; |
5597 | ||
628fe4e4 JK |
5598 | default: |
5599 | internal_error (__FILE__, __LINE__, | |
5600 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5601 | } |
628fe4e4 JK |
5602 | |
5603 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5604 | } |
628fe4e4 | 5605 | |
0e30163f JK |
5606 | /* These operations may affect the bs->breakpoint_at state so they are |
5607 | delayed after MAIN_ACTION is decided above. */ | |
5608 | ||
628fe4e4 JK |
5609 | if (jit_event) |
5610 | { | |
5611 | if (debug_infrun) | |
5612 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5613 | ||
5614 | handle_jit_event (); | |
5615 | } | |
5616 | ||
0e30163f JK |
5617 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5618 | { | |
5619 | struct breakpoint *b = bs->breakpoint_at; | |
5620 | ||
5621 | if (b == NULL) | |
5622 | continue; | |
5623 | switch (b->type) | |
5624 | { | |
5625 | case bp_gnu_ifunc_resolver: | |
5626 | gnu_ifunc_resolver_stop (b); | |
5627 | break; | |
5628 | case bp_gnu_ifunc_resolver_return: | |
5629 | gnu_ifunc_resolver_return_stop (b); | |
5630 | break; | |
5631 | } | |
5632 | } | |
5633 | ||
c906108c SS |
5634 | return retval; |
5635 | } | |
5636 | ||
5637 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5638 | without hardware support). This isn't related to a specific bpstat, | |
5639 | just to things like whether watchpoints are set. */ | |
5640 | ||
c5aa993b | 5641 | int |
fba45db2 | 5642 | bpstat_should_step (void) |
c906108c SS |
5643 | { |
5644 | struct breakpoint *b; | |
cc59ec59 | 5645 | |
c906108c | 5646 | ALL_BREAKPOINTS (b) |
717a8278 | 5647 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5648 | return 1; |
c906108c SS |
5649 | return 0; |
5650 | } | |
5651 | ||
67822962 PA |
5652 | int |
5653 | bpstat_causes_stop (bpstat bs) | |
5654 | { | |
5655 | for (; bs != NULL; bs = bs->next) | |
5656 | if (bs->stop) | |
5657 | return 1; | |
5658 | ||
5659 | return 0; | |
5660 | } | |
5661 | ||
c906108c | 5662 | \f |
c5aa993b | 5663 | |
170b53b2 UW |
5664 | /* Compute a string of spaces suitable to indent the next line |
5665 | so it starts at the position corresponding to the table column | |
5666 | named COL_NAME in the currently active table of UIOUT. */ | |
5667 | ||
5668 | static char * | |
5669 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5670 | { | |
5671 | static char wrap_indent[80]; | |
5672 | int i, total_width, width, align; | |
5673 | char *text; | |
5674 | ||
5675 | total_width = 0; | |
5676 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5677 | { | |
5678 | if (strcmp (text, col_name) == 0) | |
5679 | { | |
5680 | gdb_assert (total_width < sizeof wrap_indent); | |
5681 | memset (wrap_indent, ' ', total_width); | |
5682 | wrap_indent[total_width] = 0; | |
5683 | ||
5684 | return wrap_indent; | |
5685 | } | |
5686 | ||
5687 | total_width += width + 1; | |
5688 | } | |
5689 | ||
5690 | return NULL; | |
5691 | } | |
5692 | ||
b775012e LM |
5693 | /* Determine if the locations of this breakpoint will have their conditions |
5694 | evaluated by the target, host or a mix of both. Returns the following: | |
5695 | ||
5696 | "host": Host evals condition. | |
5697 | "host or target": Host or Target evals condition. | |
5698 | "target": Target evals condition. | |
5699 | */ | |
5700 | ||
5701 | static const char * | |
5702 | bp_condition_evaluator (struct breakpoint *b) | |
5703 | { | |
5704 | struct bp_location *bl; | |
5705 | char host_evals = 0; | |
5706 | char target_evals = 0; | |
5707 | ||
5708 | if (!b) | |
5709 | return NULL; | |
5710 | ||
5711 | if (!is_breakpoint (b)) | |
5712 | return NULL; | |
5713 | ||
5714 | if (gdb_evaluates_breakpoint_condition_p () | |
5715 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5716 | return condition_evaluation_host; | |
5717 | ||
5718 | for (bl = b->loc; bl; bl = bl->next) | |
5719 | { | |
5720 | if (bl->cond_bytecode) | |
5721 | target_evals++; | |
5722 | else | |
5723 | host_evals++; | |
5724 | } | |
5725 | ||
5726 | if (host_evals && target_evals) | |
5727 | return condition_evaluation_both; | |
5728 | else if (target_evals) | |
5729 | return condition_evaluation_target; | |
5730 | else | |
5731 | return condition_evaluation_host; | |
5732 | } | |
5733 | ||
5734 | /* Determine the breakpoint location's condition evaluator. This is | |
5735 | similar to bp_condition_evaluator, but for locations. */ | |
5736 | ||
5737 | static const char * | |
5738 | bp_location_condition_evaluator (struct bp_location *bl) | |
5739 | { | |
5740 | if (bl && !is_breakpoint (bl->owner)) | |
5741 | return NULL; | |
5742 | ||
5743 | if (gdb_evaluates_breakpoint_condition_p () | |
5744 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5745 | return condition_evaluation_host; | |
5746 | ||
5747 | if (bl && bl->cond_bytecode) | |
5748 | return condition_evaluation_target; | |
5749 | else | |
5750 | return condition_evaluation_host; | |
5751 | } | |
5752 | ||
859825b8 JK |
5753 | /* Print the LOC location out of the list of B->LOC locations. */ |
5754 | ||
170b53b2 UW |
5755 | static void |
5756 | print_breakpoint_location (struct breakpoint *b, | |
5757 | struct bp_location *loc) | |
0d381245 | 5758 | { |
79a45e25 | 5759 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5760 | struct cleanup *old_chain = save_current_program_space (); |
5761 | ||
859825b8 JK |
5762 | if (loc != NULL && loc->shlib_disabled) |
5763 | loc = NULL; | |
5764 | ||
6c95b8df PA |
5765 | if (loc != NULL) |
5766 | set_current_program_space (loc->pspace); | |
5767 | ||
56435ebe TT |
5768 | if (b->display_canonical) |
5769 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5770 | else if (loc && loc->symtab) |
0d381245 VP |
5771 | { |
5772 | struct symbol *sym | |
5773 | = find_pc_sect_function (loc->address, loc->section); | |
5774 | if (sym) | |
5775 | { | |
5776 | ui_out_text (uiout, "in "); | |
5777 | ui_out_field_string (uiout, "func", | |
5778 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5779 | ui_out_text (uiout, " "); |
5780 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5781 | ui_out_text (uiout, "at "); | |
0d381245 | 5782 | } |
05cba821 JK |
5783 | ui_out_field_string (uiout, "file", |
5784 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5785 | ui_out_text (uiout, ":"); |
05cba821 | 5786 | |
0d381245 | 5787 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5788 | ui_out_field_string (uiout, "fullname", |
5789 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5790 | |
f8eba3c6 | 5791 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5792 | } |
859825b8 | 5793 | else if (loc) |
0d381245 | 5794 | { |
f99d8bf4 PA |
5795 | struct ui_file *stb = mem_fileopen (); |
5796 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5797 | |
f99d8bf4 | 5798 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5799 | demangle, ""); |
0d381245 | 5800 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5801 | |
5802 | do_cleanups (stb_chain); | |
0d381245 | 5803 | } |
859825b8 JK |
5804 | else |
5805 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5806 | |
b775012e LM |
5807 | if (loc && is_breakpoint (b) |
5808 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5809 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5810 | { | |
5811 | ui_out_text (uiout, " ("); | |
5812 | ui_out_field_string (uiout, "evaluated-by", | |
5813 | bp_location_condition_evaluator (loc)); | |
5814 | ui_out_text (uiout, ")"); | |
5815 | } | |
5816 | ||
6c95b8df | 5817 | do_cleanups (old_chain); |
0d381245 VP |
5818 | } |
5819 | ||
269b11a2 PA |
5820 | static const char * |
5821 | bptype_string (enum bptype type) | |
c906108c | 5822 | { |
c4093a6a JM |
5823 | struct ep_type_description |
5824 | { | |
5825 | enum bptype type; | |
5826 | char *description; | |
5827 | }; | |
5828 | static struct ep_type_description bptypes[] = | |
c906108c | 5829 | { |
c5aa993b JM |
5830 | {bp_none, "?deleted?"}, |
5831 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5832 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5833 | {bp_until, "until"}, |
5834 | {bp_finish, "finish"}, | |
5835 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5836 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5837 | {bp_read_watchpoint, "read watchpoint"}, |
5838 | {bp_access_watchpoint, "acc watchpoint"}, | |
5839 | {bp_longjmp, "longjmp"}, | |
5840 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5841 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5842 | {bp_exception, "exception"}, |
5843 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5844 | {bp_step_resume, "step resume"}, |
2c03e5be | 5845 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5846 | {bp_watchpoint_scope, "watchpoint scope"}, |
5847 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5848 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5849 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5850 | {bp_thread_event, "thread events"}, |
1900040c | 5851 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5852 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5853 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5854 | {bp_exception_master, "exception master"}, |
ce78b96d | 5855 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5856 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5857 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5858 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5859 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5860 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5861 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5862 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5863 | }; |
269b11a2 PA |
5864 | |
5865 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5866 | || ((int) type != bptypes[(int) type].type)) | |
5867 | internal_error (__FILE__, __LINE__, | |
5868 | _("bptypes table does not describe type #%d."), | |
5869 | (int) type); | |
5870 | ||
5871 | return bptypes[(int) type].description; | |
5872 | } | |
5873 | ||
998580f1 MK |
5874 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5875 | For CLI, prefix the list with the string 'inf'. */ | |
5876 | ||
5877 | static void | |
5878 | output_thread_groups (struct ui_out *uiout, | |
5879 | const char *field_name, | |
5880 | VEC(int) *inf_num, | |
5881 | int mi_only) | |
5882 | { | |
752eb8b4 | 5883 | struct cleanup *back_to; |
998580f1 MK |
5884 | int is_mi = ui_out_is_mi_like_p (uiout); |
5885 | int inf; | |
5886 | int i; | |
5887 | ||
5888 | /* For backward compatibility, don't display inferiors in CLI unless | |
5889 | there are several. Always display them for MI. */ | |
5890 | if (!is_mi && mi_only) | |
5891 | return; | |
5892 | ||
752eb8b4 TT |
5893 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
5894 | ||
998580f1 MK |
5895 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
5896 | { | |
5897 | if (is_mi) | |
5898 | { | |
5899 | char mi_group[10]; | |
5900 | ||
5901 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5902 | ui_out_field_string (uiout, NULL, mi_group); | |
5903 | } | |
5904 | else | |
5905 | { | |
5906 | if (i == 0) | |
5907 | ui_out_text (uiout, " inf "); | |
5908 | else | |
5909 | ui_out_text (uiout, ", "); | |
5910 | ||
5911 | ui_out_text (uiout, plongest (inf)); | |
5912 | } | |
5913 | } | |
5914 | ||
5915 | do_cleanups (back_to); | |
5916 | } | |
5917 | ||
269b11a2 PA |
5918 | /* Print B to gdb_stdout. */ |
5919 | ||
5920 | static void | |
5921 | print_one_breakpoint_location (struct breakpoint *b, | |
5922 | struct bp_location *loc, | |
5923 | int loc_number, | |
5924 | struct bp_location **last_loc, | |
269b11a2 PA |
5925 | int allflag) |
5926 | { | |
5927 | struct command_line *l; | |
c2c6d25f | 5928 | static char bpenables[] = "nynny"; |
c906108c | 5929 | |
79a45e25 | 5930 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5931 | int header_of_multiple = 0; |
5932 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5933 | struct value_print_options opts; |
5934 | ||
5935 | get_user_print_options (&opts); | |
0d381245 VP |
5936 | |
5937 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5938 | /* See comment in print_one_breakpoint concerning treatment of |
5939 | breakpoints with single disabled location. */ | |
0d381245 VP |
5940 | if (loc == NULL |
5941 | && (b->loc != NULL | |
5942 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5943 | header_of_multiple = 1; | |
5944 | if (loc == NULL) | |
5945 | loc = b->loc; | |
5946 | ||
c4093a6a JM |
5947 | annotate_record (); |
5948 | ||
5949 | /* 1 */ | |
5950 | annotate_field (0); | |
0d381245 VP |
5951 | if (part_of_multiple) |
5952 | { | |
5953 | char *formatted; | |
0c6773c1 | 5954 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5955 | ui_out_field_string (uiout, "number", formatted); |
5956 | xfree (formatted); | |
5957 | } | |
5958 | else | |
5959 | { | |
5960 | ui_out_field_int (uiout, "number", b->number); | |
5961 | } | |
c4093a6a JM |
5962 | |
5963 | /* 2 */ | |
5964 | annotate_field (1); | |
0d381245 VP |
5965 | if (part_of_multiple) |
5966 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5967 | else |
5968 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5969 | |
5970 | /* 3 */ | |
5971 | annotate_field (2); | |
0d381245 VP |
5972 | if (part_of_multiple) |
5973 | ui_out_field_skip (uiout, "disp"); | |
5974 | else | |
2cec12e5 | 5975 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5976 | |
c4093a6a JM |
5977 | |
5978 | /* 4 */ | |
5979 | annotate_field (3); | |
0d381245 | 5980 | if (part_of_multiple) |
54e52265 | 5981 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5982 | else |
4a64f543 MS |
5983 | ui_out_field_fmt (uiout, "enabled", "%c", |
5984 | bpenables[(int) b->enable_state]); | |
54e52265 | 5985 | ui_out_spaces (uiout, 2); |
0d381245 | 5986 | |
c4093a6a JM |
5987 | |
5988 | /* 5 and 6 */ | |
3086aeae | 5989 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5990 | { |
4a64f543 MS |
5991 | /* Although the print_one can possibly print all locations, |
5992 | calling it here is not likely to get any nice result. So, | |
5993 | make sure there's just one location. */ | |
0d381245 | 5994 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5995 | b->ops->print_one (b, last_loc); |
0d381245 | 5996 | } |
3086aeae DJ |
5997 | else |
5998 | switch (b->type) | |
5999 | { | |
6000 | case bp_none: | |
6001 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6002 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6003 | break; |
c906108c | 6004 | |
3086aeae DJ |
6005 | case bp_watchpoint: |
6006 | case bp_hardware_watchpoint: | |
6007 | case bp_read_watchpoint: | |
6008 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6009 | { |
6010 | struct watchpoint *w = (struct watchpoint *) b; | |
6011 | ||
6012 | /* Field 4, the address, is omitted (which makes the columns | |
6013 | not line up too nicely with the headers, but the effect | |
6014 | is relatively readable). */ | |
6015 | if (opts.addressprint) | |
6016 | ui_out_field_skip (uiout, "addr"); | |
6017 | annotate_field (5); | |
6018 | ui_out_field_string (uiout, "what", w->exp_string); | |
6019 | } | |
3086aeae DJ |
6020 | break; |
6021 | ||
3086aeae DJ |
6022 | case bp_breakpoint: |
6023 | case bp_hardware_breakpoint: | |
6024 | case bp_until: | |
6025 | case bp_finish: | |
6026 | case bp_longjmp: | |
6027 | case bp_longjmp_resume: | |
e2e4d78b | 6028 | case bp_longjmp_call_dummy: |
186c406b TT |
6029 | case bp_exception: |
6030 | case bp_exception_resume: | |
3086aeae | 6031 | case bp_step_resume: |
2c03e5be | 6032 | case bp_hp_step_resume: |
3086aeae DJ |
6033 | case bp_watchpoint_scope: |
6034 | case bp_call_dummy: | |
aa7d318d | 6035 | case bp_std_terminate: |
3086aeae DJ |
6036 | case bp_shlib_event: |
6037 | case bp_thread_event: | |
6038 | case bp_overlay_event: | |
0fd8e87f | 6039 | case bp_longjmp_master: |
aa7d318d | 6040 | case bp_std_terminate_master: |
186c406b | 6041 | case bp_exception_master: |
1042e4c0 | 6042 | case bp_tracepoint: |
7a697b8d | 6043 | case bp_fast_tracepoint: |
0fb4aa4b | 6044 | case bp_static_tracepoint: |
e7e0cddf | 6045 | case bp_dprintf: |
4efc6507 | 6046 | case bp_jit_event: |
0e30163f JK |
6047 | case bp_gnu_ifunc_resolver: |
6048 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6049 | if (opts.addressprint) |
3086aeae DJ |
6050 | { |
6051 | annotate_field (4); | |
54e52265 | 6052 | if (header_of_multiple) |
0d381245 | 6053 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6054 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6055 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6056 | else |
5af949e3 UW |
6057 | ui_out_field_core_addr (uiout, "addr", |
6058 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6059 | } |
6060 | annotate_field (5); | |
0d381245 | 6061 | if (!header_of_multiple) |
170b53b2 | 6062 | print_breakpoint_location (b, loc); |
0d381245 | 6063 | if (b->loc) |
a6d9a66e | 6064 | *last_loc = b->loc; |
3086aeae DJ |
6065 | break; |
6066 | } | |
c906108c | 6067 | |
6c95b8df | 6068 | |
998580f1 | 6069 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6070 | { |
6071 | struct inferior *inf; | |
998580f1 MK |
6072 | VEC(int) *inf_num = NULL; |
6073 | int mi_only = 1; | |
6c95b8df | 6074 | |
998580f1 | 6075 | ALL_INFERIORS (inf) |
6c95b8df PA |
6076 | { |
6077 | if (inf->pspace == loc->pspace) | |
998580f1 | 6078 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6079 | } |
998580f1 MK |
6080 | |
6081 | /* For backward compatibility, don't display inferiors in CLI unless | |
6082 | there are several. Always display for MI. */ | |
6083 | if (allflag | |
6084 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6085 | && (number_of_program_spaces () > 1 | |
6086 | || number_of_inferiors () > 1) | |
6087 | /* LOC is for existing B, it cannot be in | |
6088 | moribund_locations and thus having NULL OWNER. */ | |
6089 | && loc->owner->type != bp_catchpoint)) | |
6090 | mi_only = 0; | |
6091 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6092 | VEC_free (int, inf_num); | |
6c95b8df PA |
6093 | } |
6094 | ||
4a306c9a | 6095 | if (!part_of_multiple) |
c4093a6a | 6096 | { |
4a306c9a JB |
6097 | if (b->thread != -1) |
6098 | { | |
6099 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6100 | "stop only in" line a little further down. */ |
4a306c9a JB |
6101 | ui_out_text (uiout, " thread "); |
6102 | ui_out_field_int (uiout, "thread", b->thread); | |
6103 | } | |
6104 | else if (b->task != 0) | |
6105 | { | |
6106 | ui_out_text (uiout, " task "); | |
6107 | ui_out_field_int (uiout, "task", b->task); | |
6108 | } | |
c4093a6a | 6109 | } |
f1310107 | 6110 | |
8b93c638 | 6111 | ui_out_text (uiout, "\n"); |
f1310107 | 6112 | |
348d480f | 6113 | if (!part_of_multiple) |
f1310107 TJB |
6114 | b->ops->print_one_detail (b, uiout); |
6115 | ||
0d381245 | 6116 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6117 | { |
6118 | annotate_field (6); | |
8b93c638 | 6119 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6120 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6121 | the frame ID. */ |
5af949e3 UW |
6122 | ui_out_field_core_addr (uiout, "frame", |
6123 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6124 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6125 | } |
6126 | ||
28010a5d | 6127 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6128 | { |
6129 | annotate_field (7); | |
d77f58be | 6130 | if (is_tracepoint (b)) |
1042e4c0 SS |
6131 | ui_out_text (uiout, "\ttrace only if "); |
6132 | else | |
6133 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6134 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6135 | |
6136 | /* Print whether the target is doing the breakpoint's condition | |
6137 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6138 | if (is_breakpoint (b) | |
6139 | && breakpoint_condition_evaluation_mode () | |
6140 | == condition_evaluation_target) | |
6141 | { | |
6142 | ui_out_text (uiout, " ("); | |
6143 | ui_out_field_string (uiout, "evaluated-by", | |
6144 | bp_condition_evaluator (b)); | |
6145 | ui_out_text (uiout, " evals)"); | |
6146 | } | |
0101ce28 JJ |
6147 | ui_out_text (uiout, "\n"); |
6148 | } | |
6149 | ||
0d381245 | 6150 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6151 | { |
4a64f543 | 6152 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6153 | ui_out_text (uiout, "\tstop only in thread "); |
6154 | ui_out_field_int (uiout, "thread", b->thread); | |
6155 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6156 | } |
6157 | ||
556ec64d YQ |
6158 | if (!part_of_multiple) |
6159 | { | |
6160 | if (b->hit_count) | |
31f56a27 YQ |
6161 | { |
6162 | /* FIXME should make an annotation for this. */ | |
6163 | if (is_catchpoint (b)) | |
6164 | ui_out_text (uiout, "\tcatchpoint"); | |
6165 | else if (is_tracepoint (b)) | |
6166 | ui_out_text (uiout, "\ttracepoint"); | |
6167 | else | |
6168 | ui_out_text (uiout, "\tbreakpoint"); | |
6169 | ui_out_text (uiout, " already hit "); | |
6170 | ui_out_field_int (uiout, "times", b->hit_count); | |
6171 | if (b->hit_count == 1) | |
6172 | ui_out_text (uiout, " time\n"); | |
6173 | else | |
6174 | ui_out_text (uiout, " times\n"); | |
6175 | } | |
556ec64d YQ |
6176 | else |
6177 | { | |
31f56a27 YQ |
6178 | /* Output the count also if it is zero, but only if this is mi. */ |
6179 | if (ui_out_is_mi_like_p (uiout)) | |
6180 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6181 | } |
6182 | } | |
8b93c638 | 6183 | |
0d381245 | 6184 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6185 | { |
6186 | annotate_field (8); | |
8b93c638 JM |
6187 | ui_out_text (uiout, "\tignore next "); |
6188 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6189 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6190 | } |
059fb39f | 6191 | |
816338b5 SS |
6192 | /* Note that an enable count of 1 corresponds to "enable once" |
6193 | behavior, which is reported by the combination of enablement and | |
6194 | disposition, so we don't need to mention it here. */ | |
6195 | if (!part_of_multiple && b->enable_count > 1) | |
6196 | { | |
6197 | annotate_field (8); | |
6198 | ui_out_text (uiout, "\tdisable after "); | |
6199 | /* Tweak the wording to clarify that ignore and enable counts | |
6200 | are distinct, and have additive effect. */ | |
6201 | if (b->ignore_count) | |
6202 | ui_out_text (uiout, "additional "); | |
6203 | else | |
6204 | ui_out_text (uiout, "next "); | |
6205 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6206 | ui_out_text (uiout, " hits\n"); | |
6207 | } | |
6208 | ||
f196051f SS |
6209 | if (!part_of_multiple && is_tracepoint (b)) |
6210 | { | |
6211 | struct tracepoint *tp = (struct tracepoint *) b; | |
6212 | ||
6213 | if (tp->traceframe_usage) | |
6214 | { | |
6215 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6216 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6217 | ui_out_text (uiout, " bytes\n"); | |
6218 | } | |
6219 | } | |
d3ce09f5 | 6220 | |
9add0f1b | 6221 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6222 | if (!part_of_multiple && l) |
c4093a6a | 6223 | { |
3b31d625 EZ |
6224 | struct cleanup *script_chain; |
6225 | ||
c4093a6a | 6226 | annotate_field (9); |
3b31d625 | 6227 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6228 | print_command_lines (uiout, l, 4); |
3b31d625 | 6229 | do_cleanups (script_chain); |
c4093a6a | 6230 | } |
d24317b4 | 6231 | |
d9b3f62e | 6232 | if (is_tracepoint (b)) |
1042e4c0 | 6233 | { |
d9b3f62e PA |
6234 | struct tracepoint *t = (struct tracepoint *) b; |
6235 | ||
6236 | if (!part_of_multiple && t->pass_count) | |
6237 | { | |
6238 | annotate_field (10); | |
6239 | ui_out_text (uiout, "\tpass count "); | |
6240 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6241 | ui_out_text (uiout, " \n"); | |
6242 | } | |
f2a8bc8a YQ |
6243 | |
6244 | /* Don't display it when tracepoint or tracepoint location is | |
6245 | pending. */ | |
6246 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6247 | { | |
6248 | annotate_field (11); | |
6249 | ||
6250 | if (ui_out_is_mi_like_p (uiout)) | |
6251 | ui_out_field_string (uiout, "installed", | |
6252 | loc->inserted ? "y" : "n"); | |
6253 | else | |
6254 | { | |
6255 | if (loc->inserted) | |
6256 | ui_out_text (uiout, "\t"); | |
6257 | else | |
6258 | ui_out_text (uiout, "\tnot "); | |
6259 | ui_out_text (uiout, "installed on target\n"); | |
6260 | } | |
6261 | } | |
1042e4c0 SS |
6262 | } |
6263 | ||
d24317b4 VP |
6264 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6265 | { | |
3a5c3e22 PA |
6266 | if (is_watchpoint (b)) |
6267 | { | |
6268 | struct watchpoint *w = (struct watchpoint *) b; | |
6269 | ||
6270 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6271 | } | |
6272 | else if (b->addr_string) | |
d24317b4 | 6273 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6274 | } |
c4093a6a | 6275 | } |
c5aa993b | 6276 | |
0d381245 VP |
6277 | static void |
6278 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6279 | struct bp_location **last_loc, |
6c95b8df | 6280 | int allflag) |
0d381245 | 6281 | { |
8d3788bd | 6282 | struct cleanup *bkpt_chain; |
79a45e25 | 6283 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6284 | |
6285 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6286 | ||
12c5a436 | 6287 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6288 | do_cleanups (bkpt_chain); |
0d381245 VP |
6289 | |
6290 | /* If this breakpoint has custom print function, | |
6291 | it's already printed. Otherwise, print individual | |
6292 | locations, if any. */ | |
6293 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6294 | { | |
4a64f543 MS |
6295 | /* If breakpoint has a single location that is disabled, we |
6296 | print it as if it had several locations, since otherwise it's | |
6297 | hard to represent "breakpoint enabled, location disabled" | |
6298 | situation. | |
6299 | ||
6300 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6301 | internally, that's not a property exposed to user. */ |
0d381245 | 6302 | if (b->loc |
a5606eee | 6303 | && !is_hardware_watchpoint (b) |
8d3788bd | 6304 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6305 | { |
6306 | struct bp_location *loc; | |
6307 | int n = 1; | |
8d3788bd | 6308 | |
0d381245 | 6309 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6310 | { |
6311 | struct cleanup *inner2 = | |
6312 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6313 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6314 | do_cleanups (inner2); | |
6315 | } | |
0d381245 VP |
6316 | } |
6317 | } | |
6318 | } | |
6319 | ||
a6d9a66e UW |
6320 | static int |
6321 | breakpoint_address_bits (struct breakpoint *b) | |
6322 | { | |
6323 | int print_address_bits = 0; | |
6324 | struct bp_location *loc; | |
6325 | ||
6326 | for (loc = b->loc; loc; loc = loc->next) | |
6327 | { | |
c7437ca6 PA |
6328 | int addr_bit; |
6329 | ||
6330 | /* Software watchpoints that aren't watching memory don't have | |
6331 | an address to print. */ | |
6332 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6333 | continue; | |
6334 | ||
6335 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6336 | if (addr_bit > print_address_bits) |
6337 | print_address_bits = addr_bit; | |
6338 | } | |
6339 | ||
6340 | return print_address_bits; | |
6341 | } | |
0d381245 | 6342 | |
c4093a6a JM |
6343 | struct captured_breakpoint_query_args |
6344 | { | |
6345 | int bnum; | |
6346 | }; | |
c5aa993b | 6347 | |
c4093a6a | 6348 | static int |
2b65245e | 6349 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6350 | { |
6351 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6352 | struct breakpoint *b; |
a6d9a66e | 6353 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6354 | |
c4093a6a JM |
6355 | ALL_BREAKPOINTS (b) |
6356 | { | |
6357 | if (args->bnum == b->number) | |
c5aa993b | 6358 | { |
12c5a436 | 6359 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6360 | return GDB_RC_OK; |
c5aa993b | 6361 | } |
c4093a6a JM |
6362 | } |
6363 | return GDB_RC_NONE; | |
6364 | } | |
c5aa993b | 6365 | |
c4093a6a | 6366 | enum gdb_rc |
4a64f543 MS |
6367 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6368 | char **error_message) | |
c4093a6a JM |
6369 | { |
6370 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6371 | |
c4093a6a JM |
6372 | args.bnum = bnum; |
6373 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6374 | an error. */ |
b0b13bb4 DJ |
6375 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6376 | error_message, RETURN_MASK_ALL) < 0) | |
6377 | return GDB_RC_FAIL; | |
6378 | else | |
6379 | return GDB_RC_OK; | |
c4093a6a | 6380 | } |
c5aa993b | 6381 | |
09d682a4 TT |
6382 | /* Return true if this breakpoint was set by the user, false if it is |
6383 | internal or momentary. */ | |
6384 | ||
6385 | int | |
6386 | user_breakpoint_p (struct breakpoint *b) | |
6387 | { | |
46c6471b | 6388 | return b->number > 0; |
09d682a4 TT |
6389 | } |
6390 | ||
7f3b0473 | 6391 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6392 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6393 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6394 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6395 | ones for which it returns non-zero. Return the total number of | |
6396 | breakpoints listed. */ | |
c906108c | 6397 | |
d77f58be | 6398 | static int |
e5a67952 | 6399 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6400 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6401 | { |
52f0bd74 | 6402 | struct breakpoint *b; |
a6d9a66e | 6403 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6404 | int nr_printable_breakpoints; |
3b31d625 | 6405 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6406 | struct value_print_options opts; |
a6d9a66e | 6407 | int print_address_bits = 0; |
269b11a2 | 6408 | int print_type_col_width = 14; |
79a45e25 | 6409 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6410 | |
79a45b7d TT |
6411 | get_user_print_options (&opts); |
6412 | ||
4a64f543 MS |
6413 | /* Compute the number of rows in the table, as well as the size |
6414 | required for address fields. */ | |
7f3b0473 AC |
6415 | nr_printable_breakpoints = 0; |
6416 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6417 | { |
6418 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6419 | if (filter && !filter (b)) | |
6420 | continue; | |
6421 | ||
6422 | /* If we have an "args" string, it is a list of breakpoints to | |
6423 | accept. Skip the others. */ | |
6424 | if (args != NULL && *args != '\0') | |
6425 | { | |
6426 | if (allflag && parse_and_eval_long (args) != b->number) | |
6427 | continue; | |
6428 | if (!allflag && !number_is_in_list (args, b->number)) | |
6429 | continue; | |
6430 | } | |
269b11a2 | 6431 | |
e5a67952 MS |
6432 | if (allflag || user_breakpoint_p (b)) |
6433 | { | |
6434 | int addr_bit, type_len; | |
a6d9a66e | 6435 | |
e5a67952 MS |
6436 | addr_bit = breakpoint_address_bits (b); |
6437 | if (addr_bit > print_address_bits) | |
6438 | print_address_bits = addr_bit; | |
269b11a2 | 6439 | |
e5a67952 MS |
6440 | type_len = strlen (bptype_string (b->type)); |
6441 | if (type_len > print_type_col_width) | |
6442 | print_type_col_width = type_len; | |
6443 | ||
6444 | nr_printable_breakpoints++; | |
6445 | } | |
6446 | } | |
7f3b0473 | 6447 | |
79a45b7d | 6448 | if (opts.addressprint) |
3b31d625 | 6449 | bkpttbl_chain |
3e43a32a MS |
6450 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6451 | nr_printable_breakpoints, | |
3b31d625 | 6452 | "BreakpointTable"); |
8b93c638 | 6453 | else |
3b31d625 | 6454 | bkpttbl_chain |
3e43a32a MS |
6455 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6456 | nr_printable_breakpoints, | |
3b31d625 | 6457 | "BreakpointTable"); |
8b93c638 | 6458 | |
7f3b0473 | 6459 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6460 | annotate_breakpoints_headers (); |
6461 | if (nr_printable_breakpoints > 0) | |
6462 | annotate_field (0); | |
4a64f543 | 6463 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6464 | if (nr_printable_breakpoints > 0) |
6465 | annotate_field (1); | |
269b11a2 | 6466 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6467 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6468 | if (nr_printable_breakpoints > 0) |
6469 | annotate_field (2); | |
4a64f543 | 6470 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6471 | if (nr_printable_breakpoints > 0) |
6472 | annotate_field (3); | |
54e52265 | 6473 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6474 | if (opts.addressprint) |
e5a67952 MS |
6475 | { |
6476 | if (nr_printable_breakpoints > 0) | |
6477 | annotate_field (4); | |
6478 | if (print_address_bits <= 32) | |
6479 | ui_out_table_header (uiout, 10, ui_left, | |
6480 | "addr", "Address"); /* 5 */ | |
6481 | else | |
6482 | ui_out_table_header (uiout, 18, ui_left, | |
6483 | "addr", "Address"); /* 5 */ | |
6484 | } | |
d7faa9e7 AC |
6485 | if (nr_printable_breakpoints > 0) |
6486 | annotate_field (5); | |
6487 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6488 | ui_out_table_body (uiout); | |
6489 | if (nr_printable_breakpoints > 0) | |
6490 | annotate_breakpoints_table (); | |
7f3b0473 | 6491 | |
c4093a6a | 6492 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6493 | { |
6494 | QUIT; | |
6495 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6496 | if (filter && !filter (b)) | |
6497 | continue; | |
6498 | ||
6499 | /* If we have an "args" string, it is a list of breakpoints to | |
6500 | accept. Skip the others. */ | |
6501 | ||
6502 | if (args != NULL && *args != '\0') | |
6503 | { | |
6504 | if (allflag) /* maintenance info breakpoint */ | |
6505 | { | |
6506 | if (parse_and_eval_long (args) != b->number) | |
6507 | continue; | |
6508 | } | |
6509 | else /* all others */ | |
6510 | { | |
6511 | if (!number_is_in_list (args, b->number)) | |
6512 | continue; | |
6513 | } | |
6514 | } | |
6515 | /* We only print out user settable breakpoints unless the | |
6516 | allflag is set. */ | |
6517 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6518 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6519 | } |
6520 | ||
3b31d625 | 6521 | do_cleanups (bkpttbl_chain); |
698384cd | 6522 | |
7f3b0473 | 6523 | if (nr_printable_breakpoints == 0) |
c906108c | 6524 | { |
4a64f543 MS |
6525 | /* If there's a filter, let the caller decide how to report |
6526 | empty list. */ | |
d77f58be SS |
6527 | if (!filter) |
6528 | { | |
e5a67952 | 6529 | if (args == NULL || *args == '\0') |
d77f58be SS |
6530 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6531 | else | |
4a64f543 | 6532 | ui_out_message (uiout, 0, |
e5a67952 MS |
6533 | "No breakpoint or watchpoint matching '%s'.\n", |
6534 | args); | |
d77f58be | 6535 | } |
c906108c SS |
6536 | } |
6537 | else | |
c4093a6a | 6538 | { |
a6d9a66e UW |
6539 | if (last_loc && !server_command) |
6540 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6541 | } |
c906108c | 6542 | |
4a64f543 | 6543 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6544 | there have been breakpoints? */ |
c906108c | 6545 | annotate_breakpoints_table_end (); |
d77f58be SS |
6546 | |
6547 | return nr_printable_breakpoints; | |
c906108c SS |
6548 | } |
6549 | ||
ad443146 SS |
6550 | /* Display the value of default-collect in a way that is generally |
6551 | compatible with the breakpoint list. */ | |
6552 | ||
6553 | static void | |
6554 | default_collect_info (void) | |
6555 | { | |
79a45e25 PA |
6556 | struct ui_out *uiout = current_uiout; |
6557 | ||
ad443146 SS |
6558 | /* If it has no value (which is frequently the case), say nothing; a |
6559 | message like "No default-collect." gets in user's face when it's | |
6560 | not wanted. */ | |
6561 | if (!*default_collect) | |
6562 | return; | |
6563 | ||
6564 | /* The following phrase lines up nicely with per-tracepoint collect | |
6565 | actions. */ | |
6566 | ui_out_text (uiout, "default collect "); | |
6567 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6568 | ui_out_text (uiout, " \n"); | |
6569 | } | |
6570 | ||
c906108c | 6571 | static void |
e5a67952 | 6572 | breakpoints_info (char *args, int from_tty) |
c906108c | 6573 | { |
e5a67952 | 6574 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6575 | |
6576 | default_collect_info (); | |
d77f58be SS |
6577 | } |
6578 | ||
6579 | static void | |
e5a67952 | 6580 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6581 | { |
e5a67952 | 6582 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6583 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6584 | |
6585 | if (num_printed == 0) | |
6586 | { | |
e5a67952 | 6587 | if (args == NULL || *args == '\0') |
d77f58be SS |
6588 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6589 | else | |
e5a67952 | 6590 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6591 | } |
c906108c SS |
6592 | } |
6593 | ||
7a292a7a | 6594 | static void |
e5a67952 | 6595 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6596 | { |
e5a67952 | 6597 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6598 | |
6599 | default_collect_info (); | |
c906108c SS |
6600 | } |
6601 | ||
0d381245 | 6602 | static int |
714835d5 | 6603 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6604 | struct program_space *pspace, |
714835d5 | 6605 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6606 | { |
6607 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6608 | |
0d381245 VP |
6609 | for (; bl; bl = bl->next) |
6610 | { | |
6c95b8df PA |
6611 | if (bl->pspace == pspace |
6612 | && bl->address == pc | |
0d381245 VP |
6613 | && (!overlay_debugging || bl->section == section)) |
6614 | return 1; | |
6615 | } | |
6616 | return 0; | |
6617 | } | |
6618 | ||
672f9b60 | 6619 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6620 | concerns with logical breakpoints, so we match program spaces, not |
6621 | address spaces. */ | |
c906108c SS |
6622 | |
6623 | static void | |
6c95b8df PA |
6624 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6625 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6626 | struct obj_section *section, int thread) |
c906108c | 6627 | { |
52f0bd74 AC |
6628 | int others = 0; |
6629 | struct breakpoint *b; | |
c906108c SS |
6630 | |
6631 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6632 | others += (user_breakpoint_p (b) |
6633 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6634 | if (others > 0) |
6635 | { | |
a3f17187 AC |
6636 | if (others == 1) |
6637 | printf_filtered (_("Note: breakpoint ")); | |
6638 | else /* if (others == ???) */ | |
6639 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6640 | ALL_BREAKPOINTS (b) |
672f9b60 | 6641 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6642 | { |
6643 | others--; | |
6644 | printf_filtered ("%d", b->number); | |
6645 | if (b->thread == -1 && thread != -1) | |
6646 | printf_filtered (" (all threads)"); | |
6647 | else if (b->thread != -1) | |
6648 | printf_filtered (" (thread %d)", b->thread); | |
6649 | printf_filtered ("%s%s ", | |
059fb39f | 6650 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6651 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6652 | ? " (disabled)" |
6653 | : b->enable_state == bp_permanent | |
6654 | ? " (permanent)" | |
6655 | : ""), | |
6656 | (others > 1) ? "," | |
6657 | : ((others == 1) ? " and" : "")); | |
6658 | } | |
a3f17187 | 6659 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6660 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6661 | printf_filtered (".\n"); |
6662 | } | |
6663 | } | |
6664 | \f | |
c906108c | 6665 | |
e4f237da KB |
6666 | /* Return true iff it is meaningful to use the address member of |
6667 | BPT. For some breakpoint types, the address member is irrelevant | |
6668 | and it makes no sense to attempt to compare it to other addresses | |
6669 | (or use it for any other purpose either). | |
6670 | ||
4a64f543 MS |
6671 | More specifically, each of the following breakpoint types will |
6672 | always have a zero valued address and we don't want to mark | |
6673 | breakpoints of any of these types to be a duplicate of an actual | |
6674 | breakpoint at address zero: | |
e4f237da KB |
6675 | |
6676 | bp_watchpoint | |
2d134ed3 PA |
6677 | bp_catchpoint |
6678 | ||
6679 | */ | |
e4f237da KB |
6680 | |
6681 | static int | |
6682 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6683 | { | |
6684 | enum bptype type = bpt->type; | |
6685 | ||
2d134ed3 PA |
6686 | return (type != bp_watchpoint && type != bp_catchpoint); |
6687 | } | |
6688 | ||
6689 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6690 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6691 | ||
6692 | static int | |
4a64f543 MS |
6693 | watchpoint_locations_match (struct bp_location *loc1, |
6694 | struct bp_location *loc2) | |
2d134ed3 | 6695 | { |
3a5c3e22 PA |
6696 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6697 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6698 | ||
6699 | /* Both of them must exist. */ | |
6700 | gdb_assert (w1 != NULL); | |
6701 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6702 | |
4a64f543 MS |
6703 | /* If the target can evaluate the condition expression in hardware, |
6704 | then we we need to insert both watchpoints even if they are at | |
6705 | the same place. Otherwise the watchpoint will only trigger when | |
6706 | the condition of whichever watchpoint was inserted evaluates to | |
6707 | true, not giving a chance for GDB to check the condition of the | |
6708 | other watchpoint. */ | |
3a5c3e22 | 6709 | if ((w1->cond_exp |
4a64f543 MS |
6710 | && target_can_accel_watchpoint_condition (loc1->address, |
6711 | loc1->length, | |
0cf6dd15 | 6712 | loc1->watchpoint_type, |
3a5c3e22 PA |
6713 | w1->cond_exp)) |
6714 | || (w2->cond_exp | |
4a64f543 MS |
6715 | && target_can_accel_watchpoint_condition (loc2->address, |
6716 | loc2->length, | |
0cf6dd15 | 6717 | loc2->watchpoint_type, |
3a5c3e22 | 6718 | w2->cond_exp))) |
0cf6dd15 TJB |
6719 | return 0; |
6720 | ||
85d721b8 PA |
6721 | /* Note that this checks the owner's type, not the location's. In |
6722 | case the target does not support read watchpoints, but does | |
6723 | support access watchpoints, we'll have bp_read_watchpoint | |
6724 | watchpoints with hw_access locations. Those should be considered | |
6725 | duplicates of hw_read locations. The hw_read locations will | |
6726 | become hw_access locations later. */ | |
2d134ed3 PA |
6727 | return (loc1->owner->type == loc2->owner->type |
6728 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6729 | && loc1->address == loc2->address | |
6730 | && loc1->length == loc2->length); | |
e4f237da KB |
6731 | } |
6732 | ||
6c95b8df PA |
6733 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6734 | same breakpoint location. In most targets, this can only be true | |
6735 | if ASPACE1 matches ASPACE2. On targets that have global | |
6736 | breakpoints, the address space doesn't really matter. */ | |
6737 | ||
6738 | static int | |
6739 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6740 | struct address_space *aspace2, CORE_ADDR addr2) | |
6741 | { | |
f5656ead | 6742 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6743 | || aspace1 == aspace2) |
6744 | && addr1 == addr2); | |
6745 | } | |
6746 | ||
f1310107 TJB |
6747 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6748 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6749 | matches ASPACE2. On targets that have global breakpoints, the address | |
6750 | space doesn't really matter. */ | |
6751 | ||
6752 | static int | |
6753 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6754 | int len1, struct address_space *aspace2, | |
6755 | CORE_ADDR addr2) | |
6756 | { | |
f5656ead | 6757 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6758 | || aspace1 == aspace2) |
6759 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6760 | } | |
6761 | ||
6762 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6763 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6764 | matches the breakpoint's address space. On targets that have global | |
6765 | breakpoints, the address space doesn't really matter. */ | |
6766 | ||
6767 | static int | |
6768 | breakpoint_location_address_match (struct bp_location *bl, | |
6769 | struct address_space *aspace, | |
6770 | CORE_ADDR addr) | |
6771 | { | |
6772 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6773 | aspace, addr) | |
6774 | || (bl->length | |
6775 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6776 | bl->address, bl->length, | |
6777 | aspace, addr))); | |
6778 | } | |
6779 | ||
1e4d1764 YQ |
6780 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6781 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6782 | true, otherwise returns false. */ | |
6783 | ||
6784 | static int | |
6785 | tracepoint_locations_match (struct bp_location *loc1, | |
6786 | struct bp_location *loc2) | |
6787 | { | |
6788 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6789 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6790 | locations at the same address of different tracepoints are regarded as | |
6791 | different locations. */ | |
6792 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6793 | else | |
6794 | return 0; | |
6795 | } | |
6796 | ||
2d134ed3 PA |
6797 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6798 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6799 | represent the same location. */ | |
6800 | ||
6801 | static int | |
4a64f543 MS |
6802 | breakpoint_locations_match (struct bp_location *loc1, |
6803 | struct bp_location *loc2) | |
2d134ed3 | 6804 | { |
2bdf28a0 JK |
6805 | int hw_point1, hw_point2; |
6806 | ||
6807 | /* Both of them must not be in moribund_locations. */ | |
6808 | gdb_assert (loc1->owner != NULL); | |
6809 | gdb_assert (loc2->owner != NULL); | |
6810 | ||
6811 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6812 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6813 | |
6814 | if (hw_point1 != hw_point2) | |
6815 | return 0; | |
6816 | else if (hw_point1) | |
6817 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6818 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6819 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6820 | else |
f1310107 TJB |
6821 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6822 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6823 | loc2->pspace->aspace, loc2->address) | |
6824 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6825 | } |
6826 | ||
76897487 KB |
6827 | static void |
6828 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6829 | int bnum, int have_bnum) | |
6830 | { | |
f63fbe86 MS |
6831 | /* The longest string possibly returned by hex_string_custom |
6832 | is 50 chars. These must be at least that big for safety. */ | |
6833 | char astr1[64]; | |
6834 | char astr2[64]; | |
76897487 | 6835 | |
bb599908 PH |
6836 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6837 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6838 | if (have_bnum) |
8a3fe4f8 | 6839 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6840 | bnum, astr1, astr2); |
6841 | else | |
8a3fe4f8 | 6842 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6843 | } |
6844 | ||
4a64f543 MS |
6845 | /* Adjust a breakpoint's address to account for architectural |
6846 | constraints on breakpoint placement. Return the adjusted address. | |
6847 | Note: Very few targets require this kind of adjustment. For most | |
6848 | targets, this function is simply the identity function. */ | |
76897487 KB |
6849 | |
6850 | static CORE_ADDR | |
a6d9a66e UW |
6851 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6852 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6853 | { |
a6d9a66e | 6854 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6855 | { |
6856 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6857 | return bpaddr; | |
6858 | } | |
88f7da05 KB |
6859 | else if (bptype == bp_watchpoint |
6860 | || bptype == bp_hardware_watchpoint | |
6861 | || bptype == bp_read_watchpoint | |
6862 | || bptype == bp_access_watchpoint | |
fe798b75 | 6863 | || bptype == bp_catchpoint) |
88f7da05 KB |
6864 | { |
6865 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6866 | have their addresses modified. */ | |
6867 | return bpaddr; | |
6868 | } | |
76897487 KB |
6869 | else |
6870 | { | |
6871 | CORE_ADDR adjusted_bpaddr; | |
6872 | ||
6873 | /* Some targets have architectural constraints on the placement | |
6874 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6875 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6876 | |
6877 | /* An adjusted breakpoint address can significantly alter | |
6878 | a user's expectations. Print a warning if an adjustment | |
6879 | is required. */ | |
6880 | if (adjusted_bpaddr != bpaddr) | |
6881 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6882 | ||
6883 | return adjusted_bpaddr; | |
6884 | } | |
6885 | } | |
6886 | ||
28010a5d PA |
6887 | void |
6888 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6889 | struct breakpoint *owner) | |
7cc221ef | 6890 | { |
7cc221ef DJ |
6891 | memset (loc, 0, sizeof (*loc)); |
6892 | ||
348d480f PA |
6893 | gdb_assert (ops != NULL); |
6894 | ||
28010a5d PA |
6895 | loc->ops = ops; |
6896 | loc->owner = owner; | |
511a6cd4 | 6897 | loc->cond = NULL; |
b775012e | 6898 | loc->cond_bytecode = NULL; |
0d381245 VP |
6899 | loc->shlib_disabled = 0; |
6900 | loc->enabled = 1; | |
e049a4b5 | 6901 | |
28010a5d | 6902 | switch (owner->type) |
e049a4b5 DJ |
6903 | { |
6904 | case bp_breakpoint: | |
6905 | case bp_until: | |
6906 | case bp_finish: | |
6907 | case bp_longjmp: | |
6908 | case bp_longjmp_resume: | |
e2e4d78b | 6909 | case bp_longjmp_call_dummy: |
186c406b TT |
6910 | case bp_exception: |
6911 | case bp_exception_resume: | |
e049a4b5 | 6912 | case bp_step_resume: |
2c03e5be | 6913 | case bp_hp_step_resume: |
e049a4b5 DJ |
6914 | case bp_watchpoint_scope: |
6915 | case bp_call_dummy: | |
aa7d318d | 6916 | case bp_std_terminate: |
e049a4b5 DJ |
6917 | case bp_shlib_event: |
6918 | case bp_thread_event: | |
6919 | case bp_overlay_event: | |
4efc6507 | 6920 | case bp_jit_event: |
0fd8e87f | 6921 | case bp_longjmp_master: |
aa7d318d | 6922 | case bp_std_terminate_master: |
186c406b | 6923 | case bp_exception_master: |
0e30163f JK |
6924 | case bp_gnu_ifunc_resolver: |
6925 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6926 | case bp_dprintf: |
e049a4b5 | 6927 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6928 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6929 | break; |
6930 | case bp_hardware_breakpoint: | |
6931 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6932 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6933 | break; |
6934 | case bp_hardware_watchpoint: | |
6935 | case bp_read_watchpoint: | |
6936 | case bp_access_watchpoint: | |
6937 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6938 | break; | |
6939 | case bp_watchpoint: | |
ce78b96d | 6940 | case bp_catchpoint: |
15c3d785 PA |
6941 | case bp_tracepoint: |
6942 | case bp_fast_tracepoint: | |
0fb4aa4b | 6943 | case bp_static_tracepoint: |
e049a4b5 DJ |
6944 | loc->loc_type = bp_loc_other; |
6945 | break; | |
6946 | default: | |
e2e0b3e5 | 6947 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6948 | } |
6949 | ||
f431efe5 | 6950 | loc->refc = 1; |
28010a5d PA |
6951 | } |
6952 | ||
6953 | /* Allocate a struct bp_location. */ | |
6954 | ||
6955 | static struct bp_location * | |
6956 | allocate_bp_location (struct breakpoint *bpt) | |
6957 | { | |
348d480f PA |
6958 | return bpt->ops->allocate_location (bpt); |
6959 | } | |
7cc221ef | 6960 | |
f431efe5 PA |
6961 | static void |
6962 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6963 | { |
348d480f | 6964 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6965 | xfree (loc); |
6966 | } | |
6967 | ||
f431efe5 PA |
6968 | /* Increment reference count. */ |
6969 | ||
6970 | static void | |
6971 | incref_bp_location (struct bp_location *bl) | |
6972 | { | |
6973 | ++bl->refc; | |
6974 | } | |
6975 | ||
6976 | /* Decrement reference count. If the reference count reaches 0, | |
6977 | destroy the bp_location. Sets *BLP to NULL. */ | |
6978 | ||
6979 | static void | |
6980 | decref_bp_location (struct bp_location **blp) | |
6981 | { | |
0807b50c PA |
6982 | gdb_assert ((*blp)->refc > 0); |
6983 | ||
f431efe5 PA |
6984 | if (--(*blp)->refc == 0) |
6985 | free_bp_location (*blp); | |
6986 | *blp = NULL; | |
6987 | } | |
6988 | ||
346774a9 | 6989 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6990 | |
346774a9 PA |
6991 | static void |
6992 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6993 | { |
346774a9 | 6994 | struct breakpoint *b1; |
c906108c | 6995 | |
346774a9 PA |
6996 | /* Add this breakpoint to the end of the chain so that a list of |
6997 | breakpoints will come out in order of increasing numbers. */ | |
6998 | ||
6999 | b1 = breakpoint_chain; | |
7000 | if (b1 == 0) | |
7001 | breakpoint_chain = b; | |
7002 | else | |
7003 | { | |
7004 | while (b1->next) | |
7005 | b1 = b1->next; | |
7006 | b1->next = b; | |
7007 | } | |
7008 | } | |
7009 | ||
7010 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7011 | ||
7012 | static void | |
7013 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7014 | struct gdbarch *gdbarch, | |
28010a5d | 7015 | enum bptype bptype, |
c0a91b2b | 7016 | const struct breakpoint_ops *ops) |
346774a9 | 7017 | { |
c906108c | 7018 | memset (b, 0, sizeof (*b)); |
2219d63c | 7019 | |
348d480f PA |
7020 | gdb_assert (ops != NULL); |
7021 | ||
28010a5d | 7022 | b->ops = ops; |
4d28f7a8 | 7023 | b->type = bptype; |
a6d9a66e | 7024 | b->gdbarch = gdbarch; |
c906108c SS |
7025 | b->language = current_language->la_language; |
7026 | b->input_radix = input_radix; | |
7027 | b->thread = -1; | |
b5de0fa7 | 7028 | b->enable_state = bp_enabled; |
c906108c SS |
7029 | b->next = 0; |
7030 | b->silent = 0; | |
7031 | b->ignore_count = 0; | |
7032 | b->commands = NULL; | |
818dd999 | 7033 | b->frame_id = null_frame_id; |
0d381245 | 7034 | b->condition_not_parsed = 0; |
84f4c1fe | 7035 | b->py_bp_object = NULL; |
d0fb5eae | 7036 | b->related_breakpoint = b; |
346774a9 PA |
7037 | } |
7038 | ||
7039 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7040 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7041 | |
7042 | static struct breakpoint * | |
7043 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7044 | enum bptype bptype, |
c0a91b2b | 7045 | const struct breakpoint_ops *ops) |
346774a9 PA |
7046 | { |
7047 | struct breakpoint *b = XNEW (struct breakpoint); | |
7048 | ||
348d480f | 7049 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7050 | add_to_breakpoint_chain (b); |
0d381245 VP |
7051 | return b; |
7052 | } | |
7053 | ||
0e30163f JK |
7054 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7055 | resolutions should be made as the user specified the location explicitly | |
7056 | enough. */ | |
7057 | ||
0d381245 | 7058 | static void |
0e30163f | 7059 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7060 | { |
2bdf28a0 JK |
7061 | gdb_assert (loc->owner != NULL); |
7062 | ||
0d381245 | 7063 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7064 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7065 | || is_tracepoint (loc->owner)) |
0d381245 | 7066 | { |
0e30163f | 7067 | int is_gnu_ifunc; |
2c02bd72 | 7068 | const char *function_name; |
6a3a010b | 7069 | CORE_ADDR func_addr; |
0e30163f | 7070 | |
2c02bd72 | 7071 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7072 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7073 | |
7074 | if (is_gnu_ifunc && !explicit_loc) | |
7075 | { | |
7076 | struct breakpoint *b = loc->owner; | |
7077 | ||
7078 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7079 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7080 | &loc->requested_address)) |
7081 | { | |
7082 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7083 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7084 | loc->requested_address, | |
7085 | b->type); | |
7086 | } | |
7087 | else if (b->type == bp_breakpoint && b->loc == loc | |
7088 | && loc->next == NULL && b->related_breakpoint == b) | |
7089 | { | |
7090 | /* Create only the whole new breakpoint of this type but do not | |
7091 | mess more complicated breakpoints with multiple locations. */ | |
7092 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7093 | /* Remember the resolver's address for use by the return |
7094 | breakpoint. */ | |
7095 | loc->related_address = func_addr; | |
0e30163f JK |
7096 | } |
7097 | } | |
7098 | ||
2c02bd72 DE |
7099 | if (function_name) |
7100 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7101 | } |
7102 | } | |
7103 | ||
a6d9a66e | 7104 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7105 | struct gdbarch * |
a6d9a66e UW |
7106 | get_sal_arch (struct symtab_and_line sal) |
7107 | { | |
7108 | if (sal.section) | |
7109 | return get_objfile_arch (sal.section->objfile); | |
7110 | if (sal.symtab) | |
7111 | return get_objfile_arch (sal.symtab->objfile); | |
7112 | ||
7113 | return NULL; | |
7114 | } | |
7115 | ||
346774a9 PA |
7116 | /* Low level routine for partially initializing a breakpoint of type |
7117 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7118 | file name, and line number are provided by SAL. |
0d381245 VP |
7119 | |
7120 | It is expected that the caller will complete the initialization of | |
7121 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7122 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7123 | |
346774a9 PA |
7124 | static void |
7125 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7126 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7127 | const struct breakpoint_ops *ops) |
0d381245 | 7128 | { |
28010a5d | 7129 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7130 | |
3742cc8b | 7131 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7132 | |
6c95b8df PA |
7133 | if (bptype != bp_catchpoint) |
7134 | gdb_assert (sal.pspace != NULL); | |
7135 | ||
f8eba3c6 TT |
7136 | /* Store the program space that was used to set the breakpoint, |
7137 | except for ordinary breakpoints, which are independent of the | |
7138 | program space. */ | |
7139 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7140 | b->pspace = sal.pspace; | |
346774a9 | 7141 | } |
c906108c | 7142 | |
346774a9 PA |
7143 | /* set_raw_breakpoint is a low level routine for allocating and |
7144 | partially initializing a breakpoint of type BPTYPE. The newly | |
7145 | created breakpoint's address, section, source file name, and line | |
7146 | number are provided by SAL. The newly created and partially | |
7147 | initialized breakpoint is added to the breakpoint chain and | |
7148 | is also returned as the value of this function. | |
7149 | ||
7150 | It is expected that the caller will complete the initialization of | |
7151 | the newly created breakpoint struct as well as output any status | |
7152 | information regarding the creation of a new breakpoint. In | |
7153 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7154 | number! Care should be taken to not allow an error to occur | |
7155 | prior to completing the initialization of the breakpoint. If this | |
7156 | should happen, a bogus breakpoint will be left on the chain. */ | |
7157 | ||
7158 | struct breakpoint * | |
7159 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7160 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7161 | const struct breakpoint_ops *ops) |
346774a9 PA |
7162 | { |
7163 | struct breakpoint *b = XNEW (struct breakpoint); | |
7164 | ||
348d480f | 7165 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7166 | add_to_breakpoint_chain (b); |
c906108c SS |
7167 | return b; |
7168 | } | |
7169 | ||
c2c6d25f JM |
7170 | |
7171 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7172 | instruction, hard-wired into the inferior's code. */ | |
7173 | void | |
7174 | make_breakpoint_permanent (struct breakpoint *b) | |
7175 | { | |
0d381245 | 7176 | struct bp_location *bl; |
cc59ec59 | 7177 | |
b5de0fa7 | 7178 | b->enable_state = bp_permanent; |
c2c6d25f | 7179 | |
4a64f543 MS |
7180 | /* By definition, permanent breakpoints are already present in the |
7181 | code. Mark all locations as inserted. For now, | |
7182 | make_breakpoint_permanent is called in just one place, so it's | |
7183 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7184 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7185 | for (bl = b->loc; bl; bl = bl->next) |
7186 | bl->inserted = 1; | |
c2c6d25f JM |
7187 | } |
7188 | ||
53a5351d | 7189 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7190 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7191 | initiated the operation. */ | |
c906108c SS |
7192 | |
7193 | void | |
186c406b | 7194 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7195 | { |
35df4500 | 7196 | struct breakpoint *b, *b_tmp; |
186c406b | 7197 | int thread = tp->num; |
0fd8e87f UW |
7198 | |
7199 | /* To avoid having to rescan all objfile symbols at every step, | |
7200 | we maintain a list of continually-inserted but always disabled | |
7201 | longjmp "master" breakpoints. Here, we simply create momentary | |
7202 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7203 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7204 | if (b->pspace == current_program_space |
186c406b TT |
7205 | && (b->type == bp_longjmp_master |
7206 | || b->type == bp_exception_master)) | |
0fd8e87f | 7207 | { |
06edf0c0 PA |
7208 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7209 | struct breakpoint *clone; | |
cc59ec59 | 7210 | |
e2e4d78b JK |
7211 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7212 | after their removal. */ | |
06edf0c0 | 7213 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7214 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7215 | clone->thread = thread; |
7216 | } | |
186c406b TT |
7217 | |
7218 | tp->initiating_frame = frame; | |
c906108c SS |
7219 | } |
7220 | ||
611c83ae | 7221 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7222 | void |
611c83ae | 7223 | delete_longjmp_breakpoint (int thread) |
c906108c | 7224 | { |
35df4500 | 7225 | struct breakpoint *b, *b_tmp; |
c906108c | 7226 | |
35df4500 | 7227 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7228 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7229 | { |
7230 | if (b->thread == thread) | |
7231 | delete_breakpoint (b); | |
7232 | } | |
c906108c SS |
7233 | } |
7234 | ||
f59f708a PA |
7235 | void |
7236 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7237 | { | |
7238 | struct breakpoint *b, *b_tmp; | |
7239 | ||
7240 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7241 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7242 | { | |
7243 | if (b->thread == thread) | |
7244 | b->disposition = disp_del_at_next_stop; | |
7245 | } | |
7246 | } | |
7247 | ||
e2e4d78b JK |
7248 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7249 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7250 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7251 | breakpoints. */ | |
7252 | ||
7253 | struct breakpoint * | |
7254 | set_longjmp_breakpoint_for_call_dummy (void) | |
7255 | { | |
7256 | struct breakpoint *b, *retval = NULL; | |
7257 | ||
7258 | ALL_BREAKPOINTS (b) | |
7259 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7260 | { | |
7261 | struct breakpoint *new_b; | |
7262 | ||
7263 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7264 | &momentary_breakpoint_ops); | |
7265 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7266 | ||
7267 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7268 | ||
7269 | gdb_assert (new_b->related_breakpoint == new_b); | |
7270 | if (retval == NULL) | |
7271 | retval = new_b; | |
7272 | new_b->related_breakpoint = retval; | |
7273 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7274 | retval = retval->related_breakpoint; | |
7275 | retval->related_breakpoint = new_b; | |
7276 | } | |
7277 | ||
7278 | return retval; | |
7279 | } | |
7280 | ||
7281 | /* Verify all existing dummy frames and their associated breakpoints for | |
7282 | THREAD. Remove those which can no longer be found in the current frame | |
7283 | stack. | |
7284 | ||
7285 | You should call this function only at places where it is safe to currently | |
7286 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7287 | frames. */ | |
7288 | ||
7289 | void | |
7290 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7291 | { | |
7292 | struct breakpoint *b, *b_tmp; | |
7293 | ||
7294 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7295 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7296 | { | |
7297 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7298 | ||
7299 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7300 | dummy_b = dummy_b->related_breakpoint; | |
7301 | if (dummy_b->type != bp_call_dummy | |
7302 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7303 | continue; | |
7304 | ||
7305 | dummy_frame_discard (dummy_b->frame_id); | |
7306 | ||
7307 | while (b->related_breakpoint != b) | |
7308 | { | |
7309 | if (b_tmp == b->related_breakpoint) | |
7310 | b_tmp = b->related_breakpoint->next; | |
7311 | delete_breakpoint (b->related_breakpoint); | |
7312 | } | |
7313 | delete_breakpoint (b); | |
7314 | } | |
7315 | } | |
7316 | ||
1900040c MS |
7317 | void |
7318 | enable_overlay_breakpoints (void) | |
7319 | { | |
52f0bd74 | 7320 | struct breakpoint *b; |
1900040c MS |
7321 | |
7322 | ALL_BREAKPOINTS (b) | |
7323 | if (b->type == bp_overlay_event) | |
7324 | { | |
7325 | b->enable_state = bp_enabled; | |
b60e7edf | 7326 | update_global_location_list (1); |
c02f5703 | 7327 | overlay_events_enabled = 1; |
1900040c MS |
7328 | } |
7329 | } | |
7330 | ||
7331 | void | |
7332 | disable_overlay_breakpoints (void) | |
7333 | { | |
52f0bd74 | 7334 | struct breakpoint *b; |
1900040c MS |
7335 | |
7336 | ALL_BREAKPOINTS (b) | |
7337 | if (b->type == bp_overlay_event) | |
7338 | { | |
7339 | b->enable_state = bp_disabled; | |
b60e7edf | 7340 | update_global_location_list (0); |
c02f5703 | 7341 | overlay_events_enabled = 0; |
1900040c MS |
7342 | } |
7343 | } | |
7344 | ||
aa7d318d TT |
7345 | /* Set an active std::terminate breakpoint for each std::terminate |
7346 | master breakpoint. */ | |
7347 | void | |
7348 | set_std_terminate_breakpoint (void) | |
7349 | { | |
35df4500 | 7350 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7351 | |
35df4500 | 7352 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7353 | if (b->pspace == current_program_space |
7354 | && b->type == bp_std_terminate_master) | |
7355 | { | |
06edf0c0 PA |
7356 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7357 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7358 | } |
7359 | } | |
7360 | ||
7361 | /* Delete all the std::terminate breakpoints. */ | |
7362 | void | |
7363 | delete_std_terminate_breakpoint (void) | |
7364 | { | |
35df4500 | 7365 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7366 | |
35df4500 | 7367 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7368 | if (b->type == bp_std_terminate) |
7369 | delete_breakpoint (b); | |
7370 | } | |
7371 | ||
c4093a6a | 7372 | struct breakpoint * |
a6d9a66e | 7373 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7374 | { |
7375 | struct breakpoint *b; | |
c4093a6a | 7376 | |
06edf0c0 PA |
7377 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7378 | &internal_breakpoint_ops); | |
7379 | ||
b5de0fa7 | 7380 | b->enable_state = bp_enabled; |
c4093a6a | 7381 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7382 | b->addr_string |
7383 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7384 | |
b60e7edf | 7385 | update_global_location_list_nothrow (1); |
74960c60 | 7386 | |
c4093a6a JM |
7387 | return b; |
7388 | } | |
7389 | ||
7390 | void | |
7391 | remove_thread_event_breakpoints (void) | |
7392 | { | |
35df4500 | 7393 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7394 | |
35df4500 | 7395 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7396 | if (b->type == bp_thread_event |
7397 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7398 | delete_breakpoint (b); |
7399 | } | |
7400 | ||
0101ce28 JJ |
7401 | struct lang_and_radix |
7402 | { | |
7403 | enum language lang; | |
7404 | int radix; | |
7405 | }; | |
7406 | ||
4efc6507 DE |
7407 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7408 | ||
7409 | struct breakpoint * | |
7410 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7411 | { | |
7412 | struct breakpoint *b; | |
7413 | ||
06edf0c0 PA |
7414 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7415 | &internal_breakpoint_ops); | |
4efc6507 DE |
7416 | update_global_location_list_nothrow (1); |
7417 | return b; | |
7418 | } | |
0101ce28 | 7419 | |
03673fc7 PP |
7420 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7421 | ||
7422 | void | |
7423 | remove_jit_event_breakpoints (void) | |
7424 | { | |
7425 | struct breakpoint *b, *b_tmp; | |
7426 | ||
7427 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7428 | if (b->type == bp_jit_event | |
7429 | && b->loc->pspace == current_program_space) | |
7430 | delete_breakpoint (b); | |
7431 | } | |
7432 | ||
cae688ec JJ |
7433 | void |
7434 | remove_solib_event_breakpoints (void) | |
7435 | { | |
35df4500 | 7436 | struct breakpoint *b, *b_tmp; |
cae688ec | 7437 | |
35df4500 | 7438 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7439 | if (b->type == bp_shlib_event |
7440 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7441 | delete_breakpoint (b); |
7442 | } | |
7443 | ||
7444 | struct breakpoint * | |
a6d9a66e | 7445 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7446 | { |
7447 | struct breakpoint *b; | |
7448 | ||
06edf0c0 PA |
7449 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7450 | &internal_breakpoint_ops); | |
b60e7edf | 7451 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7452 | return b; |
7453 | } | |
7454 | ||
7455 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7456 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7457 | ||
7458 | void | |
cb851954 | 7459 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7460 | { |
876fa593 | 7461 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7462 | |
876fa593 | 7463 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7464 | { |
2bdf28a0 | 7465 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7466 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7467 | |
4a64f543 MS |
7468 | /* We apply the check to all breakpoints, including disabled for |
7469 | those with loc->duplicate set. This is so that when breakpoint | |
7470 | becomes enabled, or the duplicate is removed, gdb will try to | |
7471 | insert all breakpoints. If we don't set shlib_disabled here, | |
7472 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7473 | if (((b->type == bp_breakpoint) |
508ccb1f | 7474 | || (b->type == bp_jit_event) |
1042e4c0 | 7475 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7476 | || (is_tracepoint (b))) |
6c95b8df | 7477 | && loc->pspace == current_program_space |
0d381245 | 7478 | && !loc->shlib_disabled |
6c95b8df | 7479 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7480 | ) |
0d381245 VP |
7481 | { |
7482 | loc->shlib_disabled = 1; | |
7483 | } | |
cae688ec JJ |
7484 | } |
7485 | } | |
7486 | ||
63644780 NB |
7487 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7488 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7489 | disabled ones can just stay disabled. */ | |
84acb35a | 7490 | |
75149521 | 7491 | static void |
84acb35a JJ |
7492 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7493 | { | |
876fa593 | 7494 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7495 | int disabled_shlib_breaks = 0; |
7496 | ||
c86cf029 VP |
7497 | /* SunOS a.out shared libraries are always mapped, so do not |
7498 | disable breakpoints; they will only be reported as unloaded | |
7499 | through clear_solib when GDB discards its shared library | |
7500 | list. See clear_solib for more information. */ | |
7501 | if (exec_bfd != NULL | |
7502 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7503 | return; | |
7504 | ||
876fa593 | 7505 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7506 | { |
2bdf28a0 | 7507 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7508 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7509 | |
1e4d1764 | 7510 | if (solib->pspace == loc->pspace |
e2dd7057 | 7511 | && !loc->shlib_disabled |
1e4d1764 YQ |
7512 | && (((b->type == bp_breakpoint |
7513 | || b->type == bp_jit_event | |
7514 | || b->type == bp_hardware_breakpoint) | |
7515 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7516 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7517 | || is_tracepoint (b)) | |
e2dd7057 | 7518 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7519 | { |
e2dd7057 PP |
7520 | loc->shlib_disabled = 1; |
7521 | /* At this point, we cannot rely on remove_breakpoint | |
7522 | succeeding so we must mark the breakpoint as not inserted | |
7523 | to prevent future errors occurring in remove_breakpoints. */ | |
7524 | loc->inserted = 0; | |
8d3788bd VP |
7525 | |
7526 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7527 | observer_notify_breakpoint_modified (b); | |
7528 | ||
e2dd7057 PP |
7529 | if (!disabled_shlib_breaks) |
7530 | { | |
7531 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7532 | warning (_("Temporarily disabling breakpoints " |
7533 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7534 | solib->so_name); |
84acb35a | 7535 | } |
e2dd7057 | 7536 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7537 | } |
7538 | } | |
84acb35a JJ |
7539 | } |
7540 | ||
63644780 NB |
7541 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7542 | notification of free_objfile. Only apply to enabled breakpoints, | |
7543 | disabled ones can just stay disabled. */ | |
7544 | ||
7545 | static void | |
7546 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7547 | { | |
7548 | struct breakpoint *b; | |
7549 | ||
7550 | if (objfile == NULL) | |
7551 | return; | |
7552 | ||
7553 | /* If the file is a shared library not loaded by the user then | |
7554 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7555 | was called. In that case there is no need to take action again. */ | |
7556 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7557 | return; | |
7558 | ||
7559 | ALL_BREAKPOINTS (b) | |
7560 | { | |
7561 | struct bp_location *loc; | |
7562 | int bp_modified = 0; | |
7563 | ||
7564 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7565 | continue; | |
7566 | ||
7567 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7568 | { | |
7569 | CORE_ADDR loc_addr = loc->address; | |
7570 | ||
7571 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7572 | && loc->loc_type != bp_loc_software_breakpoint) | |
7573 | continue; | |
7574 | ||
7575 | if (loc->shlib_disabled != 0) | |
7576 | continue; | |
7577 | ||
7578 | if (objfile->pspace != loc->pspace) | |
7579 | continue; | |
7580 | ||
7581 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7582 | && loc->loc_type != bp_loc_software_breakpoint) | |
7583 | continue; | |
7584 | ||
7585 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7586 | { | |
7587 | loc->shlib_disabled = 1; | |
7588 | loc->inserted = 0; | |
7589 | ||
7590 | mark_breakpoint_location_modified (loc); | |
7591 | ||
7592 | bp_modified = 1; | |
7593 | } | |
7594 | } | |
7595 | ||
7596 | if (bp_modified) | |
7597 | observer_notify_breakpoint_modified (b); | |
7598 | } | |
7599 | } | |
7600 | ||
ce78b96d JB |
7601 | /* FORK & VFORK catchpoints. */ |
7602 | ||
e29a4733 PA |
7603 | /* An instance of this type is used to represent a fork or vfork |
7604 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7605 | class; users downcast to "struct breakpoint *" when needed. A | |
7606 | breakpoint is really of this type iff its ops pointer points to | |
7607 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7608 | ||
7609 | struct fork_catchpoint | |
7610 | { | |
7611 | /* The base class. */ | |
7612 | struct breakpoint base; | |
7613 | ||
7614 | /* Process id of a child process whose forking triggered this | |
7615 | catchpoint. This field is only valid immediately after this | |
7616 | catchpoint has triggered. */ | |
7617 | ptid_t forked_inferior_pid; | |
7618 | }; | |
7619 | ||
4a64f543 MS |
7620 | /* Implement the "insert" breakpoint_ops method for fork |
7621 | catchpoints. */ | |
ce78b96d | 7622 | |
77b06cd7 TJB |
7623 | static int |
7624 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7625 | { |
dfd4cc63 | 7626 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7627 | } |
7628 | ||
4a64f543 MS |
7629 | /* Implement the "remove" breakpoint_ops method for fork |
7630 | catchpoints. */ | |
ce78b96d JB |
7631 | |
7632 | static int | |
77b06cd7 | 7633 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7634 | { |
dfd4cc63 | 7635 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7636 | } |
7637 | ||
7638 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7639 | catchpoints. */ | |
7640 | ||
7641 | static int | |
f1310107 | 7642 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7643 | struct address_space *aspace, CORE_ADDR bp_addr, |
7644 | const struct target_waitstatus *ws) | |
ce78b96d | 7645 | { |
e29a4733 PA |
7646 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7647 | ||
f90263c1 TT |
7648 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7649 | return 0; | |
7650 | ||
7651 | c->forked_inferior_pid = ws->value.related_pid; | |
7652 | return 1; | |
ce78b96d JB |
7653 | } |
7654 | ||
4a64f543 MS |
7655 | /* Implement the "print_it" breakpoint_ops method for fork |
7656 | catchpoints. */ | |
ce78b96d JB |
7657 | |
7658 | static enum print_stop_action | |
348d480f | 7659 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7660 | { |
36dfb11c | 7661 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7662 | struct breakpoint *b = bs->breakpoint_at; |
7663 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7664 | |
ce78b96d | 7665 | annotate_catchpoint (b->number); |
36dfb11c TT |
7666 | if (b->disposition == disp_del) |
7667 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7668 | else | |
7669 | ui_out_text (uiout, "\nCatchpoint "); | |
7670 | if (ui_out_is_mi_like_p (uiout)) | |
7671 | { | |
7672 | ui_out_field_string (uiout, "reason", | |
7673 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7674 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7675 | } | |
7676 | ui_out_field_int (uiout, "bkptno", b->number); | |
7677 | ui_out_text (uiout, " (forked process "); | |
7678 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7679 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7680 | return PRINT_SRC_AND_LOC; |
7681 | } | |
7682 | ||
4a64f543 MS |
7683 | /* Implement the "print_one" breakpoint_ops method for fork |
7684 | catchpoints. */ | |
ce78b96d JB |
7685 | |
7686 | static void | |
a6d9a66e | 7687 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7688 | { |
e29a4733 | 7689 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7690 | struct value_print_options opts; |
79a45e25 | 7691 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7692 | |
7693 | get_user_print_options (&opts); | |
7694 | ||
4a64f543 MS |
7695 | /* Field 4, the address, is omitted (which makes the columns not |
7696 | line up too nicely with the headers, but the effect is relatively | |
7697 | readable). */ | |
79a45b7d | 7698 | if (opts.addressprint) |
ce78b96d JB |
7699 | ui_out_field_skip (uiout, "addr"); |
7700 | annotate_field (5); | |
7701 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7702 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7703 | { |
7704 | ui_out_text (uiout, ", process "); | |
7705 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7706 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7707 | ui_out_spaces (uiout, 1); |
7708 | } | |
8ac3646f TT |
7709 | |
7710 | if (ui_out_is_mi_like_p (uiout)) | |
7711 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7712 | } |
7713 | ||
7714 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7715 | catchpoints. */ | |
7716 | ||
7717 | static void | |
7718 | print_mention_catch_fork (struct breakpoint *b) | |
7719 | { | |
7720 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7721 | } | |
7722 | ||
6149aea9 PA |
7723 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7724 | catchpoints. */ | |
7725 | ||
7726 | static void | |
7727 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7728 | { | |
7729 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7730 | print_recreate_thread (b, fp); |
6149aea9 PA |
7731 | } |
7732 | ||
ce78b96d JB |
7733 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7734 | ||
2060206e | 7735 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7736 | |
4a64f543 MS |
7737 | /* Implement the "insert" breakpoint_ops method for vfork |
7738 | catchpoints. */ | |
ce78b96d | 7739 | |
77b06cd7 TJB |
7740 | static int |
7741 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7742 | { |
dfd4cc63 | 7743 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7744 | } |
7745 | ||
4a64f543 MS |
7746 | /* Implement the "remove" breakpoint_ops method for vfork |
7747 | catchpoints. */ | |
ce78b96d JB |
7748 | |
7749 | static int | |
77b06cd7 | 7750 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7751 | { |
dfd4cc63 | 7752 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7753 | } |
7754 | ||
7755 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7756 | catchpoints. */ | |
7757 | ||
7758 | static int | |
f1310107 | 7759 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7760 | struct address_space *aspace, CORE_ADDR bp_addr, |
7761 | const struct target_waitstatus *ws) | |
ce78b96d | 7762 | { |
e29a4733 PA |
7763 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7764 | ||
f90263c1 TT |
7765 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7766 | return 0; | |
7767 | ||
7768 | c->forked_inferior_pid = ws->value.related_pid; | |
7769 | return 1; | |
ce78b96d JB |
7770 | } |
7771 | ||
4a64f543 MS |
7772 | /* Implement the "print_it" breakpoint_ops method for vfork |
7773 | catchpoints. */ | |
ce78b96d JB |
7774 | |
7775 | static enum print_stop_action | |
348d480f | 7776 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7777 | { |
36dfb11c | 7778 | struct ui_out *uiout = current_uiout; |
348d480f | 7779 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7780 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7781 | ||
ce78b96d | 7782 | annotate_catchpoint (b->number); |
36dfb11c TT |
7783 | if (b->disposition == disp_del) |
7784 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7785 | else | |
7786 | ui_out_text (uiout, "\nCatchpoint "); | |
7787 | if (ui_out_is_mi_like_p (uiout)) | |
7788 | { | |
7789 | ui_out_field_string (uiout, "reason", | |
7790 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7791 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7792 | } | |
7793 | ui_out_field_int (uiout, "bkptno", b->number); | |
7794 | ui_out_text (uiout, " (vforked process "); | |
7795 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7796 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7797 | return PRINT_SRC_AND_LOC; |
7798 | } | |
7799 | ||
4a64f543 MS |
7800 | /* Implement the "print_one" breakpoint_ops method for vfork |
7801 | catchpoints. */ | |
ce78b96d JB |
7802 | |
7803 | static void | |
a6d9a66e | 7804 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7805 | { |
e29a4733 | 7806 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7807 | struct value_print_options opts; |
79a45e25 | 7808 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7809 | |
7810 | get_user_print_options (&opts); | |
4a64f543 MS |
7811 | /* Field 4, the address, is omitted (which makes the columns not |
7812 | line up too nicely with the headers, but the effect is relatively | |
7813 | readable). */ | |
79a45b7d | 7814 | if (opts.addressprint) |
ce78b96d JB |
7815 | ui_out_field_skip (uiout, "addr"); |
7816 | annotate_field (5); | |
7817 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7818 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7819 | { |
7820 | ui_out_text (uiout, ", process "); | |
7821 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7822 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7823 | ui_out_spaces (uiout, 1); |
7824 | } | |
8ac3646f TT |
7825 | |
7826 | if (ui_out_is_mi_like_p (uiout)) | |
7827 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7828 | } |
7829 | ||
7830 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7831 | catchpoints. */ | |
7832 | ||
7833 | static void | |
7834 | print_mention_catch_vfork (struct breakpoint *b) | |
7835 | { | |
7836 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7837 | } | |
7838 | ||
6149aea9 PA |
7839 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7840 | catchpoints. */ | |
7841 | ||
7842 | static void | |
7843 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7844 | { | |
7845 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7846 | print_recreate_thread (b, fp); |
6149aea9 PA |
7847 | } |
7848 | ||
ce78b96d JB |
7849 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7850 | ||
2060206e | 7851 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7852 | |
edcc5120 TT |
7853 | /* An instance of this type is used to represent an solib catchpoint. |
7854 | It includes a "struct breakpoint" as a kind of base class; users | |
7855 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7856 | really of this type iff its ops pointer points to | |
7857 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7858 | ||
7859 | struct solib_catchpoint | |
7860 | { | |
7861 | /* The base class. */ | |
7862 | struct breakpoint base; | |
7863 | ||
7864 | /* True for "catch load", false for "catch unload". */ | |
7865 | unsigned char is_load; | |
7866 | ||
7867 | /* Regular expression to match, if any. COMPILED is only valid when | |
7868 | REGEX is non-NULL. */ | |
7869 | char *regex; | |
7870 | regex_t compiled; | |
7871 | }; | |
7872 | ||
7873 | static void | |
7874 | dtor_catch_solib (struct breakpoint *b) | |
7875 | { | |
7876 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7877 | ||
7878 | if (self->regex) | |
7879 | regfree (&self->compiled); | |
7880 | xfree (self->regex); | |
7881 | ||
7882 | base_breakpoint_ops.dtor (b); | |
7883 | } | |
7884 | ||
7885 | static int | |
7886 | insert_catch_solib (struct bp_location *ignore) | |
7887 | { | |
7888 | return 0; | |
7889 | } | |
7890 | ||
7891 | static int | |
7892 | remove_catch_solib (struct bp_location *ignore) | |
7893 | { | |
7894 | return 0; | |
7895 | } | |
7896 | ||
7897 | static int | |
7898 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7899 | struct address_space *aspace, | |
7900 | CORE_ADDR bp_addr, | |
7901 | const struct target_waitstatus *ws) | |
7902 | { | |
7903 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7904 | struct breakpoint *other; | |
7905 | ||
7906 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7907 | return 1; | |
7908 | ||
7909 | ALL_BREAKPOINTS (other) | |
7910 | { | |
7911 | struct bp_location *other_bl; | |
7912 | ||
7913 | if (other == bl->owner) | |
7914 | continue; | |
7915 | ||
7916 | if (other->type != bp_shlib_event) | |
7917 | continue; | |
7918 | ||
7919 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7920 | continue; | |
7921 | ||
7922 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7923 | { | |
7924 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7925 | return 1; | |
7926 | } | |
7927 | } | |
7928 | ||
7929 | return 0; | |
7930 | } | |
7931 | ||
7932 | static void | |
7933 | check_status_catch_solib (struct bpstats *bs) | |
7934 | { | |
7935 | struct solib_catchpoint *self | |
7936 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7937 | int ix; | |
7938 | ||
7939 | if (self->is_load) | |
7940 | { | |
7941 | struct so_list *iter; | |
7942 | ||
7943 | for (ix = 0; | |
7944 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7945 | ix, iter); | |
7946 | ++ix) | |
7947 | { | |
7948 | if (!self->regex | |
7949 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7950 | return; | |
7951 | } | |
7952 | } | |
7953 | else | |
7954 | { | |
7955 | char *iter; | |
7956 | ||
7957 | for (ix = 0; | |
7958 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7959 | ix, iter); | |
7960 | ++ix) | |
7961 | { | |
7962 | if (!self->regex | |
7963 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7964 | return; | |
7965 | } | |
7966 | } | |
7967 | ||
7968 | bs->stop = 0; | |
7969 | bs->print_it = print_it_noop; | |
7970 | } | |
7971 | ||
7972 | static enum print_stop_action | |
7973 | print_it_catch_solib (bpstat bs) | |
7974 | { | |
7975 | struct breakpoint *b = bs->breakpoint_at; | |
7976 | struct ui_out *uiout = current_uiout; | |
7977 | ||
7978 | annotate_catchpoint (b->number); | |
7979 | if (b->disposition == disp_del) | |
7980 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7981 | else | |
7982 | ui_out_text (uiout, "\nCatchpoint "); | |
7983 | ui_out_field_int (uiout, "bkptno", b->number); | |
7984 | ui_out_text (uiout, "\n"); | |
7985 | if (ui_out_is_mi_like_p (uiout)) | |
7986 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7987 | print_solib_event (1); | |
7988 | return PRINT_SRC_AND_LOC; | |
7989 | } | |
7990 | ||
7991 | static void | |
7992 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7993 | { | |
7994 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7995 | struct value_print_options opts; | |
7996 | struct ui_out *uiout = current_uiout; | |
7997 | char *msg; | |
7998 | ||
7999 | get_user_print_options (&opts); | |
8000 | /* Field 4, the address, is omitted (which makes the columns not | |
8001 | line up too nicely with the headers, but the effect is relatively | |
8002 | readable). */ | |
8003 | if (opts.addressprint) | |
8004 | { | |
8005 | annotate_field (4); | |
8006 | ui_out_field_skip (uiout, "addr"); | |
8007 | } | |
8008 | ||
8009 | annotate_field (5); | |
8010 | if (self->is_load) | |
8011 | { | |
8012 | if (self->regex) | |
8013 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8014 | else | |
8015 | msg = xstrdup (_("load of library")); | |
8016 | } | |
8017 | else | |
8018 | { | |
8019 | if (self->regex) | |
8020 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8021 | else | |
8022 | msg = xstrdup (_("unload of library")); | |
8023 | } | |
8024 | ui_out_field_string (uiout, "what", msg); | |
8025 | xfree (msg); | |
8ac3646f TT |
8026 | |
8027 | if (ui_out_is_mi_like_p (uiout)) | |
8028 | ui_out_field_string (uiout, "catch-type", | |
8029 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8030 | } |
8031 | ||
8032 | static void | |
8033 | print_mention_catch_solib (struct breakpoint *b) | |
8034 | { | |
8035 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8036 | ||
8037 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8038 | self->is_load ? "load" : "unload"); | |
8039 | } | |
8040 | ||
8041 | static void | |
8042 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8043 | { | |
8044 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8045 | ||
8046 | fprintf_unfiltered (fp, "%s %s", | |
8047 | b->disposition == disp_del ? "tcatch" : "catch", | |
8048 | self->is_load ? "load" : "unload"); | |
8049 | if (self->regex) | |
8050 | fprintf_unfiltered (fp, " %s", self->regex); | |
8051 | fprintf_unfiltered (fp, "\n"); | |
8052 | } | |
8053 | ||
8054 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8055 | ||
91985142 MG |
8056 | /* Shared helper function (MI and CLI) for creating and installing |
8057 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8058 | the events to be caught are load events, otherwise they are | |
8059 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8060 | temporary one. If ENABLED is non-zero the catchpoint is | |
8061 | created in an enabled state. */ | |
edcc5120 | 8062 | |
91985142 MG |
8063 | void |
8064 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8065 | { |
8066 | struct solib_catchpoint *c; | |
8067 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8068 | struct cleanup *cleanup; |
8069 | ||
edcc5120 TT |
8070 | if (!arg) |
8071 | arg = ""; | |
8072 | arg = skip_spaces (arg); | |
8073 | ||
8074 | c = XCNEW (struct solib_catchpoint); | |
8075 | cleanup = make_cleanup (xfree, c); | |
8076 | ||
8077 | if (*arg != '\0') | |
8078 | { | |
8079 | int errcode; | |
8080 | ||
8081 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8082 | if (errcode != 0) | |
8083 | { | |
8084 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8085 | ||
8086 | make_cleanup (xfree, err); | |
8087 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8088 | } | |
8089 | c->regex = xstrdup (arg); | |
8090 | } | |
8091 | ||
8092 | c->is_load = is_load; | |
91985142 | 8093 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8094 | &catch_solib_breakpoint_ops); |
8095 | ||
91985142 MG |
8096 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8097 | ||
edcc5120 TT |
8098 | discard_cleanups (cleanup); |
8099 | install_breakpoint (0, &c->base, 1); | |
8100 | } | |
8101 | ||
91985142 MG |
8102 | /* A helper function that does all the work for "catch load" and |
8103 | "catch unload". */ | |
8104 | ||
8105 | static void | |
8106 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8107 | struct cmd_list_element *command) | |
8108 | { | |
8109 | int tempflag; | |
8110 | const int enabled = 1; | |
8111 | ||
8112 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8113 | ||
8114 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8115 | } | |
8116 | ||
edcc5120 TT |
8117 | static void |
8118 | catch_load_command_1 (char *arg, int from_tty, | |
8119 | struct cmd_list_element *command) | |
8120 | { | |
8121 | catch_load_or_unload (arg, from_tty, 1, command); | |
8122 | } | |
8123 | ||
8124 | static void | |
8125 | catch_unload_command_1 (char *arg, int from_tty, | |
8126 | struct cmd_list_element *command) | |
8127 | { | |
8128 | catch_load_or_unload (arg, from_tty, 0, command); | |
8129 | } | |
8130 | ||
be5c67c1 PA |
8131 | /* An instance of this type is used to represent a syscall catchpoint. |
8132 | It includes a "struct breakpoint" as a kind of base class; users | |
8133 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8134 | really of this type iff its ops pointer points to | |
8135 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8136 | ||
8137 | struct syscall_catchpoint | |
8138 | { | |
8139 | /* The base class. */ | |
8140 | struct breakpoint base; | |
8141 | ||
8142 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8143 | syscall has been specified for filtering, its value is NULL. | |
8144 | Otherwise, it holds a list of all syscalls to be caught. The | |
8145 | list elements are allocated with xmalloc. */ | |
8146 | VEC(int) *syscalls_to_be_caught; | |
8147 | }; | |
8148 | ||
8149 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8150 | catchpoints. */ | |
8151 | ||
8152 | static void | |
8153 | dtor_catch_syscall (struct breakpoint *b) | |
8154 | { | |
8155 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8156 | ||
8157 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8158 | |
2060206e | 8159 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8160 | } |
8161 | ||
fa3064dd YQ |
8162 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8163 | ||
8164 | struct catch_syscall_inferior_data | |
8165 | { | |
8166 | /* We keep a count of the number of times the user has requested a | |
8167 | particular syscall to be tracked, and pass this information to the | |
8168 | target. This lets capable targets implement filtering directly. */ | |
8169 | ||
8170 | /* Number of times that "any" syscall is requested. */ | |
8171 | int any_syscall_count; | |
8172 | ||
8173 | /* Count of each system call. */ | |
8174 | VEC(int) *syscalls_counts; | |
8175 | ||
8176 | /* This counts all syscall catch requests, so we can readily determine | |
8177 | if any catching is necessary. */ | |
8178 | int total_syscalls_count; | |
8179 | }; | |
8180 | ||
8181 | static struct catch_syscall_inferior_data* | |
8182 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8183 | { | |
8184 | struct catch_syscall_inferior_data *inf_data; | |
8185 | ||
8186 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8187 | if (inf_data == NULL) | |
8188 | { | |
8189 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
8190 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
8191 | } | |
8192 | ||
8193 | return inf_data; | |
8194 | } | |
8195 | ||
8196 | static void | |
8197 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8198 | { | |
8199 | xfree (arg); | |
8200 | } | |
8201 | ||
8202 | ||
a96d9b2e SDJ |
8203 | /* Implement the "insert" breakpoint_ops method for syscall |
8204 | catchpoints. */ | |
8205 | ||
77b06cd7 TJB |
8206 | static int |
8207 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8208 | { |
be5c67c1 | 8209 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8210 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8211 | struct catch_syscall_inferior_data *inf_data |
8212 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8213 | |
fa3064dd | 8214 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8215 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8216 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8217 | else |
8218 | { | |
8219 | int i, iter; | |
cc59ec59 | 8220 | |
a96d9b2e | 8221 | for (i = 0; |
be5c67c1 | 8222 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8223 | i++) |
8224 | { | |
8225 | int elem; | |
cc59ec59 | 8226 | |
fa3064dd | 8227 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8228 | { |
fa3064dd | 8229 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8230 | uintptr_t vec_addr_offset |
8231 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8232 | uintptr_t vec_addr; |
fa3064dd YQ |
8233 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8234 | vec_addr = ((uintptr_t) VEC_address (int, | |
8235 | inf_data->syscalls_counts) | |
8236 | + vec_addr_offset); | |
a96d9b2e SDJ |
8237 | memset ((void *) vec_addr, 0, |
8238 | (iter + 1 - old_size) * sizeof (int)); | |
8239 | } | |
fa3064dd YQ |
8240 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8241 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8242 | } |
8243 | } | |
8244 | ||
dfd4cc63 | 8245 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8246 | inf_data->total_syscalls_count != 0, |
8247 | inf_data->any_syscall_count, | |
8248 | VEC_length (int, | |
8249 | inf_data->syscalls_counts), | |
8250 | VEC_address (int, | |
8251 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8252 | } |
8253 | ||
8254 | /* Implement the "remove" breakpoint_ops method for syscall | |
8255 | catchpoints. */ | |
8256 | ||
8257 | static int | |
77b06cd7 | 8258 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8259 | { |
be5c67c1 | 8260 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8261 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8262 | struct catch_syscall_inferior_data *inf_data |
8263 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8264 | |
fa3064dd | 8265 | --inf_data->total_syscalls_count; |
be5c67c1 | 8266 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8267 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8268 | else |
8269 | { | |
8270 | int i, iter; | |
cc59ec59 | 8271 | |
a96d9b2e | 8272 | for (i = 0; |
be5c67c1 | 8273 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8274 | i++) |
8275 | { | |
8276 | int elem; | |
fa3064dd | 8277 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8278 | /* Shouldn't happen. */ |
8279 | continue; | |
fa3064dd YQ |
8280 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8281 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8282 | } |
8283 | } | |
8284 | ||
dfd4cc63 | 8285 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8286 | inf_data->total_syscalls_count != 0, |
8287 | inf_data->any_syscall_count, | |
8288 | VEC_length (int, | |
8289 | inf_data->syscalls_counts), | |
3e43a32a | 8290 | VEC_address (int, |
fa3064dd | 8291 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8292 | } |
8293 | ||
8294 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8295 | catchpoints. */ | |
8296 | ||
8297 | static int | |
f1310107 | 8298 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8299 | struct address_space *aspace, CORE_ADDR bp_addr, |
8300 | const struct target_waitstatus *ws) | |
a96d9b2e | 8301 | { |
4a64f543 MS |
8302 | /* We must check if we are catching specific syscalls in this |
8303 | breakpoint. If we are, then we must guarantee that the called | |
8304 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8305 | int syscall_number = 0; |
be5c67c1 PA |
8306 | const struct syscall_catchpoint *c |
8307 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8308 | |
f90263c1 TT |
8309 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8310 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8311 | return 0; |
8312 | ||
f90263c1 TT |
8313 | syscall_number = ws->value.syscall_number; |
8314 | ||
a96d9b2e | 8315 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8316 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8317 | { |
8318 | int i, iter; | |
cc59ec59 | 8319 | |
a96d9b2e | 8320 | for (i = 0; |
be5c67c1 | 8321 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8322 | i++) |
8323 | if (syscall_number == iter) | |
8324 | break; | |
8325 | /* Not the same. */ | |
8326 | if (!iter) | |
8327 | return 0; | |
8328 | } | |
8329 | ||
8330 | return 1; | |
8331 | } | |
8332 | ||
8333 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8334 | catchpoints. */ | |
8335 | ||
8336 | static enum print_stop_action | |
348d480f | 8337 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8338 | { |
36dfb11c | 8339 | struct ui_out *uiout = current_uiout; |
348d480f | 8340 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8341 | /* These are needed because we want to know in which state a |
8342 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8343 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8344 | must print "called syscall" or "returned from syscall". */ | |
8345 | ptid_t ptid; | |
8346 | struct target_waitstatus last; | |
8347 | struct syscall s; | |
a96d9b2e SDJ |
8348 | |
8349 | get_last_target_status (&ptid, &last); | |
8350 | ||
8351 | get_syscall_by_number (last.value.syscall_number, &s); | |
8352 | ||
8353 | annotate_catchpoint (b->number); | |
8354 | ||
36dfb11c TT |
8355 | if (b->disposition == disp_del) |
8356 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8357 | else |
36dfb11c TT |
8358 | ui_out_text (uiout, "\nCatchpoint "); |
8359 | if (ui_out_is_mi_like_p (uiout)) | |
8360 | { | |
8361 | ui_out_field_string (uiout, "reason", | |
8362 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8363 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8364 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8365 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8366 | } | |
8367 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8368 | |
8369 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8370 | ui_out_text (uiout, " (call to syscall "); |
8371 | else | |
8372 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8373 | |
36dfb11c TT |
8374 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8375 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8376 | if (s.name != NULL) | |
8377 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8378 | ||
8379 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8380 | |
8381 | return PRINT_SRC_AND_LOC; | |
8382 | } | |
8383 | ||
8384 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8385 | catchpoints. */ | |
8386 | ||
8387 | static void | |
8388 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8389 | struct bp_location **last_loc) |
a96d9b2e | 8390 | { |
be5c67c1 | 8391 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8392 | struct value_print_options opts; |
79a45e25 | 8393 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8394 | |
8395 | get_user_print_options (&opts); | |
4a64f543 MS |
8396 | /* Field 4, the address, is omitted (which makes the columns not |
8397 | line up too nicely with the headers, but the effect is relatively | |
8398 | readable). */ | |
a96d9b2e SDJ |
8399 | if (opts.addressprint) |
8400 | ui_out_field_skip (uiout, "addr"); | |
8401 | annotate_field (5); | |
8402 | ||
be5c67c1 PA |
8403 | if (c->syscalls_to_be_caught |
8404 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8405 | ui_out_text (uiout, "syscalls \""); |
8406 | else | |
8407 | ui_out_text (uiout, "syscall \""); | |
8408 | ||
be5c67c1 | 8409 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8410 | { |
8411 | int i, iter; | |
8412 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8413 | |
a96d9b2e | 8414 | for (i = 0; |
be5c67c1 | 8415 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8416 | i++) |
8417 | { | |
8418 | char *x = text; | |
8419 | struct syscall s; | |
8420 | get_syscall_by_number (iter, &s); | |
8421 | ||
8422 | if (s.name != NULL) | |
8423 | text = xstrprintf ("%s%s, ", text, s.name); | |
8424 | else | |
8425 | text = xstrprintf ("%s%d, ", text, iter); | |
8426 | ||
8427 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8428 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8429 | on every call. */ |
8430 | xfree (x); | |
8431 | } | |
8432 | /* Remove the last comma. */ | |
8433 | text[strlen (text) - 2] = '\0'; | |
8434 | ui_out_field_string (uiout, "what", text); | |
8435 | } | |
8436 | else | |
8437 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8438 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8439 | |
8440 | if (ui_out_is_mi_like_p (uiout)) | |
8441 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8442 | } |
8443 | ||
8444 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8445 | catchpoints. */ | |
8446 | ||
8447 | static void | |
8448 | print_mention_catch_syscall (struct breakpoint *b) | |
8449 | { | |
be5c67c1 PA |
8450 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8451 | ||
8452 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8453 | { |
8454 | int i, iter; | |
8455 | ||
be5c67c1 | 8456 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8457 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8458 | else | |
8459 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8460 | ||
8461 | for (i = 0; | |
be5c67c1 | 8462 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8463 | i++) |
8464 | { | |
8465 | struct syscall s; | |
8466 | get_syscall_by_number (iter, &s); | |
8467 | ||
8468 | if (s.name) | |
8469 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8470 | else | |
8471 | printf_filtered (" %d", s.number); | |
8472 | } | |
8473 | printf_filtered (")"); | |
8474 | } | |
8475 | else | |
8476 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8477 | b->number); | |
8478 | } | |
8479 | ||
6149aea9 PA |
8480 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8481 | catchpoints. */ | |
8482 | ||
8483 | static void | |
8484 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8485 | { | |
be5c67c1 PA |
8486 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8487 | ||
6149aea9 PA |
8488 | fprintf_unfiltered (fp, "catch syscall"); |
8489 | ||
be5c67c1 | 8490 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8491 | { |
8492 | int i, iter; | |
8493 | ||
8494 | for (i = 0; | |
be5c67c1 | 8495 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8496 | i++) |
8497 | { | |
8498 | struct syscall s; | |
8499 | ||
8500 | get_syscall_by_number (iter, &s); | |
8501 | if (s.name) | |
8502 | fprintf_unfiltered (fp, " %s", s.name); | |
8503 | else | |
8504 | fprintf_unfiltered (fp, " %d", s.number); | |
8505 | } | |
8506 | } | |
d9b3f62e | 8507 | print_recreate_thread (b, fp); |
6149aea9 PA |
8508 | } |
8509 | ||
a96d9b2e SDJ |
8510 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8511 | ||
2060206e | 8512 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8513 | |
8514 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8515 | ||
8516 | static int | |
8517 | syscall_catchpoint_p (struct breakpoint *b) | |
8518 | { | |
8519 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8520 | } | |
8521 | ||
346774a9 PA |
8522 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8523 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8524 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8525 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8526 | |
ab04a2af | 8527 | void |
346774a9 PA |
8528 | init_catchpoint (struct breakpoint *b, |
8529 | struct gdbarch *gdbarch, int tempflag, | |
8530 | char *cond_string, | |
c0a91b2b | 8531 | const struct breakpoint_ops *ops) |
c906108c | 8532 | { |
c5aa993b | 8533 | struct symtab_and_line sal; |
346774a9 | 8534 | |
fe39c653 | 8535 | init_sal (&sal); |
6c95b8df | 8536 | sal.pspace = current_program_space; |
c5aa993b | 8537 | |
28010a5d | 8538 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8539 | |
1b36a34b | 8540 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8541 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8542 | } |
8543 | ||
28010a5d | 8544 | void |
3ea46bff | 8545 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8546 | { |
8547 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8548 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8549 | if (is_tracepoint (b)) |
8550 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8551 | if (!internal) |
8552 | mention (b); | |
c56053d2 | 8553 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8554 | |
8555 | if (update_gll) | |
8556 | update_global_location_list (1); | |
c56053d2 PA |
8557 | } |
8558 | ||
9b70b993 | 8559 | static void |
a6d9a66e UW |
8560 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8561 | int tempflag, char *cond_string, | |
c0a91b2b | 8562 | const struct breakpoint_ops *ops) |
c906108c | 8563 | { |
e29a4733 | 8564 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8565 | |
e29a4733 PA |
8566 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8567 | ||
8568 | c->forked_inferior_pid = null_ptid; | |
8569 | ||
3ea46bff | 8570 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8571 | } |
8572 | ||
fe798b75 JB |
8573 | /* Exec catchpoints. */ |
8574 | ||
b4d90040 PA |
8575 | /* An instance of this type is used to represent an exec catchpoint. |
8576 | It includes a "struct breakpoint" as a kind of base class; users | |
8577 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8578 | really of this type iff its ops pointer points to | |
8579 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8580 | ||
8581 | struct exec_catchpoint | |
8582 | { | |
8583 | /* The base class. */ | |
8584 | struct breakpoint base; | |
8585 | ||
8586 | /* Filename of a program whose exec triggered this catchpoint. | |
8587 | This field is only valid immediately after this catchpoint has | |
8588 | triggered. */ | |
8589 | char *exec_pathname; | |
8590 | }; | |
8591 | ||
8592 | /* Implement the "dtor" breakpoint_ops method for exec | |
8593 | catchpoints. */ | |
8594 | ||
8595 | static void | |
8596 | dtor_catch_exec (struct breakpoint *b) | |
8597 | { | |
8598 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8599 | ||
8600 | xfree (c->exec_pathname); | |
348d480f | 8601 | |
2060206e | 8602 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8603 | } |
8604 | ||
77b06cd7 TJB |
8605 | static int |
8606 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8607 | { |
dfd4cc63 | 8608 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8609 | } |
c906108c | 8610 | |
fe798b75 | 8611 | static int |
77b06cd7 | 8612 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8613 | { |
dfd4cc63 | 8614 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8615 | } |
c906108c | 8616 | |
fe798b75 | 8617 | static int |
f1310107 | 8618 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8619 | struct address_space *aspace, CORE_ADDR bp_addr, |
8620 | const struct target_waitstatus *ws) | |
fe798b75 | 8621 | { |
b4d90040 PA |
8622 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8623 | ||
f90263c1 TT |
8624 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8625 | return 0; | |
8626 | ||
8627 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8628 | return 1; | |
fe798b75 | 8629 | } |
c906108c | 8630 | |
fe798b75 | 8631 | static enum print_stop_action |
348d480f | 8632 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8633 | { |
36dfb11c | 8634 | struct ui_out *uiout = current_uiout; |
348d480f | 8635 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8636 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8637 | ||
fe798b75 | 8638 | annotate_catchpoint (b->number); |
36dfb11c TT |
8639 | if (b->disposition == disp_del) |
8640 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8641 | else | |
8642 | ui_out_text (uiout, "\nCatchpoint "); | |
8643 | if (ui_out_is_mi_like_p (uiout)) | |
8644 | { | |
8645 | ui_out_field_string (uiout, "reason", | |
8646 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8647 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8648 | } | |
8649 | ui_out_field_int (uiout, "bkptno", b->number); | |
8650 | ui_out_text (uiout, " (exec'd "); | |
8651 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8652 | ui_out_text (uiout, "), "); | |
8653 | ||
fe798b75 | 8654 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8655 | } |
8656 | ||
fe798b75 | 8657 | static void |
a6d9a66e | 8658 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8659 | { |
b4d90040 | 8660 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8661 | struct value_print_options opts; |
79a45e25 | 8662 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8663 | |
8664 | get_user_print_options (&opts); | |
8665 | ||
8666 | /* Field 4, the address, is omitted (which makes the columns | |
8667 | not line up too nicely with the headers, but the effect | |
8668 | is relatively readable). */ | |
8669 | if (opts.addressprint) | |
8670 | ui_out_field_skip (uiout, "addr"); | |
8671 | annotate_field (5); | |
8672 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8673 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8674 | { |
8675 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8676 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8677 | ui_out_text (uiout, "\" "); |
8678 | } | |
8ac3646f TT |
8679 | |
8680 | if (ui_out_is_mi_like_p (uiout)) | |
8681 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8682 | } |
8683 | ||
8684 | static void | |
8685 | print_mention_catch_exec (struct breakpoint *b) | |
8686 | { | |
8687 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8688 | } | |
8689 | ||
6149aea9 PA |
8690 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8691 | catchpoints. */ | |
8692 | ||
8693 | static void | |
8694 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8695 | { | |
8696 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8697 | print_recreate_thread (b, fp); |
6149aea9 PA |
8698 | } |
8699 | ||
2060206e | 8700 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8701 | |
a96d9b2e SDJ |
8702 | static void |
8703 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8704 | const struct breakpoint_ops *ops) |
a96d9b2e | 8705 | { |
be5c67c1 | 8706 | struct syscall_catchpoint *c; |
a96d9b2e | 8707 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8708 | |
be5c67c1 PA |
8709 | c = XNEW (struct syscall_catchpoint); |
8710 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8711 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8712 | |
3ea46bff | 8713 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8714 | } |
8715 | ||
c906108c | 8716 | static int |
fba45db2 | 8717 | hw_breakpoint_used_count (void) |
c906108c | 8718 | { |
c906108c | 8719 | int i = 0; |
f1310107 TJB |
8720 | struct breakpoint *b; |
8721 | struct bp_location *bl; | |
c906108c SS |
8722 | |
8723 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8724 | { |
d6b74ac4 | 8725 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8726 | for (bl = b->loc; bl; bl = bl->next) |
8727 | { | |
8728 | /* Special types of hardware breakpoints may use more than | |
8729 | one register. */ | |
348d480f | 8730 | i += b->ops->resources_needed (bl); |
f1310107 | 8731 | } |
c5aa993b | 8732 | } |
c906108c SS |
8733 | |
8734 | return i; | |
8735 | } | |
8736 | ||
a1398e0c PA |
8737 | /* Returns the resources B would use if it were a hardware |
8738 | watchpoint. */ | |
8739 | ||
c906108c | 8740 | static int |
a1398e0c | 8741 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8742 | { |
c906108c | 8743 | int i = 0; |
e09342b5 | 8744 | struct bp_location *bl; |
c906108c | 8745 | |
a1398e0c PA |
8746 | if (!breakpoint_enabled (b)) |
8747 | return 0; | |
8748 | ||
8749 | for (bl = b->loc; bl; bl = bl->next) | |
8750 | { | |
8751 | /* Special types of hardware watchpoints may use more than | |
8752 | one register. */ | |
8753 | i += b->ops->resources_needed (bl); | |
8754 | } | |
8755 | ||
8756 | return i; | |
8757 | } | |
8758 | ||
8759 | /* Returns the sum the used resources of all hardware watchpoints of | |
8760 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8761 | the sum of the used resources of all hardware watchpoints of other | |
8762 | types _not_ TYPE. */ | |
8763 | ||
8764 | static int | |
8765 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8766 | enum bptype type, int *other_type_used) | |
8767 | { | |
8768 | int i = 0; | |
8769 | struct breakpoint *b; | |
8770 | ||
c906108c SS |
8771 | *other_type_used = 0; |
8772 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8773 | { |
a1398e0c PA |
8774 | if (b == except) |
8775 | continue; | |
e09342b5 TJB |
8776 | if (!breakpoint_enabled (b)) |
8777 | continue; | |
8778 | ||
a1398e0c PA |
8779 | if (b->type == type) |
8780 | i += hw_watchpoint_use_count (b); | |
8781 | else if (is_hardware_watchpoint (b)) | |
8782 | *other_type_used = 1; | |
e09342b5 TJB |
8783 | } |
8784 | ||
c906108c SS |
8785 | return i; |
8786 | } | |
8787 | ||
c906108c | 8788 | void |
fba45db2 | 8789 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8790 | { |
c5aa993b | 8791 | struct breakpoint *b; |
c906108c SS |
8792 | |
8793 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8794 | { |
cc60f2e3 | 8795 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8796 | { |
b5de0fa7 | 8797 | b->enable_state = bp_call_disabled; |
b60e7edf | 8798 | update_global_location_list (0); |
c5aa993b JM |
8799 | } |
8800 | } | |
c906108c SS |
8801 | } |
8802 | ||
8803 | void | |
fba45db2 | 8804 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8805 | { |
c5aa993b | 8806 | struct breakpoint *b; |
c906108c SS |
8807 | |
8808 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8809 | { |
cc60f2e3 | 8810 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8811 | { |
b5de0fa7 | 8812 | b->enable_state = bp_enabled; |
b60e7edf | 8813 | update_global_location_list (1); |
c5aa993b JM |
8814 | } |
8815 | } | |
c906108c SS |
8816 | } |
8817 | ||
8bea4e01 UW |
8818 | void |
8819 | disable_breakpoints_before_startup (void) | |
8820 | { | |
6c95b8df | 8821 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8822 | update_global_location_list (0); |
8bea4e01 UW |
8823 | } |
8824 | ||
8825 | void | |
8826 | enable_breakpoints_after_startup (void) | |
8827 | { | |
6c95b8df | 8828 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8829 | breakpoint_re_set (); |
8bea4e01 UW |
8830 | } |
8831 | ||
c906108c SS |
8832 | |
8833 | /* Set a breakpoint that will evaporate an end of command | |
8834 | at address specified by SAL. | |
8835 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8836 | ||
8837 | struct breakpoint * | |
a6d9a66e UW |
8838 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8839 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8840 | { |
52f0bd74 | 8841 | struct breakpoint *b; |
edb3359d | 8842 | |
193facb3 JK |
8843 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8844 | tail-called one. */ | |
8845 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8846 | |
06edf0c0 | 8847 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8848 | b->enable_state = bp_enabled; |
8849 | b->disposition = disp_donttouch; | |
818dd999 | 8850 | b->frame_id = frame_id; |
c906108c | 8851 | |
4a64f543 MS |
8852 | /* If we're debugging a multi-threaded program, then we want |
8853 | momentary breakpoints to be active in only a single thread of | |
8854 | control. */ | |
39f77062 KB |
8855 | if (in_thread_list (inferior_ptid)) |
8856 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8857 | |
b60e7edf | 8858 | update_global_location_list_nothrow (1); |
74960c60 | 8859 | |
c906108c SS |
8860 | return b; |
8861 | } | |
611c83ae | 8862 | |
06edf0c0 PA |
8863 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8864 | The new breakpoint will have type TYPE, and use OPS as it | |
8865 | breakpoint_ops. */ | |
e58b0e63 | 8866 | |
06edf0c0 PA |
8867 | static struct breakpoint * |
8868 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8869 | enum bptype type, | |
c0a91b2b | 8870 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8871 | { |
8872 | struct breakpoint *copy; | |
8873 | ||
06edf0c0 | 8874 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8875 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8876 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8877 | |
a6d9a66e | 8878 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8879 | copy->loc->requested_address = orig->loc->requested_address; |
8880 | copy->loc->address = orig->loc->address; | |
8881 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8882 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8883 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8884 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8885 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8886 | copy->frame_id = orig->frame_id; |
8887 | copy->thread = orig->thread; | |
6c95b8df | 8888 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8889 | |
8890 | copy->enable_state = bp_enabled; | |
8891 | copy->disposition = disp_donttouch; | |
8892 | copy->number = internal_breakpoint_number--; | |
8893 | ||
8894 | update_global_location_list_nothrow (0); | |
8895 | return copy; | |
8896 | } | |
8897 | ||
06edf0c0 PA |
8898 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8899 | ORIG is NULL. */ | |
8900 | ||
8901 | struct breakpoint * | |
8902 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8903 | { | |
8904 | /* If there's nothing to clone, then return nothing. */ | |
8905 | if (orig == NULL) | |
8906 | return NULL; | |
8907 | ||
8908 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8909 | } | |
8910 | ||
611c83ae | 8911 | struct breakpoint * |
a6d9a66e UW |
8912 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8913 | enum bptype type) | |
611c83ae PA |
8914 | { |
8915 | struct symtab_and_line sal; | |
8916 | ||
8917 | sal = find_pc_line (pc, 0); | |
8918 | sal.pc = pc; | |
8919 | sal.section = find_pc_overlay (pc); | |
8920 | sal.explicit_pc = 1; | |
8921 | ||
a6d9a66e | 8922 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8923 | } |
c906108c | 8924 | \f |
c5aa993b | 8925 | |
c906108c SS |
8926 | /* Tell the user we have just set a breakpoint B. */ |
8927 | ||
8928 | static void | |
fba45db2 | 8929 | mention (struct breakpoint *b) |
c906108c | 8930 | { |
348d480f | 8931 | b->ops->print_mention (b); |
79a45e25 | 8932 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8933 | return; |
c906108c SS |
8934 | printf_filtered ("\n"); |
8935 | } | |
c906108c | 8936 | \f |
c5aa993b | 8937 | |
0d381245 | 8938 | static struct bp_location * |
39d61571 | 8939 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8940 | const struct symtab_and_line *sal) |
8941 | { | |
8942 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8943 | CORE_ADDR adjusted_address; |
8944 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8945 | ||
8946 | if (loc_gdbarch == NULL) | |
8947 | loc_gdbarch = b->gdbarch; | |
8948 | ||
8949 | /* Adjust the breakpoint's address prior to allocating a location. | |
8950 | Once we call allocate_bp_location(), that mostly uninitialized | |
8951 | location will be placed on the location chain. Adjustment of the | |
8952 | breakpoint may cause target_read_memory() to be called and we do | |
8953 | not want its scan of the location chain to find a breakpoint and | |
8954 | location that's only been partially initialized. */ | |
8955 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8956 | sal->pc, b->type); | |
0d381245 | 8957 | |
d30113d4 | 8958 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8959 | loc = allocate_bp_location (b); |
d30113d4 JK |
8960 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8961 | tmp = &((*tmp)->next)) | |
0d381245 | 8962 | ; |
d30113d4 | 8963 | loc->next = *tmp; |
0d381245 | 8964 | *tmp = loc; |
3742cc8b | 8965 | |
0d381245 | 8966 | loc->requested_address = sal->pc; |
3742cc8b | 8967 | loc->address = adjusted_address; |
6c95b8df | 8968 | loc->pspace = sal->pspace; |
55aa24fb | 8969 | loc->probe = sal->probe; |
6c95b8df | 8970 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8971 | loc->section = sal->section; |
3742cc8b | 8972 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8973 | loc->line_number = sal->line; |
2f202fde | 8974 | loc->symtab = sal->symtab; |
f8eba3c6 | 8975 | |
0e30163f JK |
8976 | set_breakpoint_location_function (loc, |
8977 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8978 | return loc; |
8979 | } | |
514f746b AR |
8980 | \f |
8981 | ||
8982 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8983 | return 0 otherwise. */ | |
8984 | ||
8985 | static int | |
8986 | bp_loc_is_permanent (struct bp_location *loc) | |
8987 | { | |
8988 | int len; | |
8989 | CORE_ADDR addr; | |
1afeeb75 | 8990 | const gdb_byte *bpoint; |
514f746b | 8991 | gdb_byte *target_mem; |
939c61fa JK |
8992 | struct cleanup *cleanup; |
8993 | int retval = 0; | |
514f746b AR |
8994 | |
8995 | gdb_assert (loc != NULL); | |
8996 | ||
8997 | addr = loc->address; | |
1afeeb75 | 8998 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8999 | |
939c61fa | 9000 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9001 | if (bpoint == NULL) |
939c61fa JK |
9002 | return 0; |
9003 | ||
514f746b AR |
9004 | target_mem = alloca (len); |
9005 | ||
939c61fa JK |
9006 | /* Enable the automatic memory restoration from breakpoints while |
9007 | we read the memory. Otherwise we could say about our temporary | |
9008 | breakpoints they are permanent. */ | |
6c95b8df PA |
9009 | cleanup = save_current_space_and_thread (); |
9010 | ||
9011 | switch_to_program_space_and_thread (loc->pspace); | |
9012 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9013 | |
514f746b | 9014 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9015 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9016 | retval = 1; |
514f746b | 9017 | |
939c61fa JK |
9018 | do_cleanups (cleanup); |
9019 | ||
9020 | return retval; | |
514f746b AR |
9021 | } |
9022 | ||
e7e0cddf SS |
9023 | /* Build a command list for the dprintf corresponding to the current |
9024 | settings of the dprintf style options. */ | |
9025 | ||
9026 | static void | |
9027 | update_dprintf_command_list (struct breakpoint *b) | |
9028 | { | |
9029 | char *dprintf_args = b->extra_string; | |
9030 | char *printf_line = NULL; | |
9031 | ||
9032 | if (!dprintf_args) | |
9033 | return; | |
9034 | ||
9035 | dprintf_args = skip_spaces (dprintf_args); | |
9036 | ||
9037 | /* Allow a comma, as it may have terminated a location, but don't | |
9038 | insist on it. */ | |
9039 | if (*dprintf_args == ',') | |
9040 | ++dprintf_args; | |
9041 | dprintf_args = skip_spaces (dprintf_args); | |
9042 | ||
9043 | if (*dprintf_args != '"') | |
9044 | error (_("Bad format string, missing '\"'.")); | |
9045 | ||
d3ce09f5 | 9046 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9047 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9048 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9049 | { |
9050 | if (!dprintf_function) | |
9051 | error (_("No function supplied for dprintf call")); | |
9052 | ||
9053 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9054 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9055 | dprintf_function, | |
9056 | dprintf_channel, | |
9057 | dprintf_args); | |
9058 | else | |
9059 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9060 | dprintf_function, | |
9061 | dprintf_args); | |
9062 | } | |
d3ce09f5 SS |
9063 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9064 | { | |
9065 | if (target_can_run_breakpoint_commands ()) | |
9066 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9067 | else | |
9068 | { | |
9069 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9070 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9071 | } | |
9072 | } | |
e7e0cddf SS |
9073 | else |
9074 | internal_error (__FILE__, __LINE__, | |
9075 | _("Invalid dprintf style.")); | |
9076 | ||
f28045c2 | 9077 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9078 | /* Manufacture a printf sequence. */ |
f28045c2 | 9079 | { |
9d6e6e84 HZ |
9080 | struct command_line *printf_cmd_line |
9081 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9082 | |
f28045c2 YQ |
9083 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9084 | printf_cmd_line->control_type = simple_control; | |
9085 | printf_cmd_line->body_count = 0; | |
9086 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9087 | printf_cmd_line->next = NULL; |
f28045c2 | 9088 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9089 | |
f28045c2 YQ |
9090 | breakpoint_set_commands (b, printf_cmd_line); |
9091 | } | |
e7e0cddf SS |
9092 | } |
9093 | ||
9094 | /* Update all dprintf commands, making their command lists reflect | |
9095 | current style settings. */ | |
9096 | ||
9097 | static void | |
9098 | update_dprintf_commands (char *args, int from_tty, | |
9099 | struct cmd_list_element *c) | |
9100 | { | |
9101 | struct breakpoint *b; | |
9102 | ||
9103 | ALL_BREAKPOINTS (b) | |
9104 | { | |
9105 | if (b->type == bp_dprintf) | |
9106 | update_dprintf_command_list (b); | |
9107 | } | |
9108 | } | |
c3f6f71d | 9109 | |
018d34a4 VP |
9110 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9111 | as textual description of the location, and COND_STRING | |
db107f19 | 9112 | as condition expression. */ |
018d34a4 VP |
9113 | |
9114 | static void | |
d9b3f62e PA |
9115 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9116 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9117 | char *filter, char *cond_string, |
e7e0cddf | 9118 | char *extra_string, |
d9b3f62e PA |
9119 | enum bptype type, enum bpdisp disposition, |
9120 | int thread, int task, int ignore_count, | |
c0a91b2b | 9121 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9122 | int enabled, int internal, unsigned flags, |
9123 | int display_canonical) | |
018d34a4 | 9124 | { |
0d381245 | 9125 | int i; |
018d34a4 VP |
9126 | |
9127 | if (type == bp_hardware_breakpoint) | |
9128 | { | |
fbbd034e AS |
9129 | int target_resources_ok; |
9130 | ||
9131 | i = hw_breakpoint_used_count (); | |
9132 | target_resources_ok = | |
9133 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9134 | i + 1, 0); |
9135 | if (target_resources_ok == 0) | |
9136 | error (_("No hardware breakpoint support in the target.")); | |
9137 | else if (target_resources_ok < 0) | |
9138 | error (_("Hardware breakpoints used exceeds limit.")); | |
9139 | } | |
9140 | ||
6c95b8df PA |
9141 | gdb_assert (sals.nelts > 0); |
9142 | ||
0d381245 VP |
9143 | for (i = 0; i < sals.nelts; ++i) |
9144 | { | |
9145 | struct symtab_and_line sal = sals.sals[i]; | |
9146 | struct bp_location *loc; | |
9147 | ||
9148 | if (from_tty) | |
5af949e3 UW |
9149 | { |
9150 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9151 | if (!loc_gdbarch) | |
9152 | loc_gdbarch = gdbarch; | |
9153 | ||
9154 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9155 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9156 | } |
0d381245 VP |
9157 | |
9158 | if (i == 0) | |
9159 | { | |
d9b3f62e | 9160 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9161 | b->thread = thread; |
4a306c9a | 9162 | b->task = task; |
855a6e68 | 9163 | |
0d381245 | 9164 | b->cond_string = cond_string; |
e7e0cddf | 9165 | b->extra_string = extra_string; |
0d381245 | 9166 | b->ignore_count = ignore_count; |
41447f92 | 9167 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9168 | b->disposition = disposition; |
6c95b8df | 9169 | |
44f238bb PA |
9170 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9171 | b->loc->inserted = 1; | |
9172 | ||
0fb4aa4b PA |
9173 | if (type == bp_static_tracepoint) |
9174 | { | |
d9b3f62e | 9175 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9176 | struct static_tracepoint_marker marker; |
9177 | ||
983af33b | 9178 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9179 | { |
9180 | /* We already know the marker exists, otherwise, we | |
9181 | wouldn't see a sal for it. */ | |
9182 | char *p = &addr_string[3]; | |
9183 | char *endp; | |
9184 | char *marker_str; | |
0fb4aa4b | 9185 | |
e9cafbcc | 9186 | p = skip_spaces (p); |
0fb4aa4b | 9187 | |
e9cafbcc | 9188 | endp = skip_to_space (p); |
0fb4aa4b PA |
9189 | |
9190 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9191 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9192 | |
3e43a32a MS |
9193 | printf_filtered (_("Probed static tracepoint " |
9194 | "marker \"%s\"\n"), | |
d9b3f62e | 9195 | t->static_trace_marker_id); |
0fb4aa4b PA |
9196 | } |
9197 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9198 | { | |
d9b3f62e | 9199 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9200 | release_static_tracepoint_marker (&marker); |
9201 | ||
3e43a32a MS |
9202 | printf_filtered (_("Probed static tracepoint " |
9203 | "marker \"%s\"\n"), | |
d9b3f62e | 9204 | t->static_trace_marker_id); |
0fb4aa4b PA |
9205 | } |
9206 | else | |
3e43a32a MS |
9207 | warning (_("Couldn't determine the static " |
9208 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9209 | } |
9210 | ||
0d381245 VP |
9211 | loc = b->loc; |
9212 | } | |
9213 | else | |
018d34a4 | 9214 | { |
39d61571 | 9215 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9216 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9217 | loc->inserted = 1; | |
0d381245 VP |
9218 | } |
9219 | ||
514f746b AR |
9220 | if (bp_loc_is_permanent (loc)) |
9221 | make_breakpoint_permanent (b); | |
9222 | ||
0d381245 VP |
9223 | if (b->cond_string) |
9224 | { | |
bbc13ae3 KS |
9225 | const char *arg = b->cond_string; |
9226 | ||
1bb9788d TT |
9227 | loc->cond = parse_exp_1 (&arg, loc->address, |
9228 | block_for_pc (loc->address), 0); | |
0d381245 | 9229 | if (*arg) |
588ae58c | 9230 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9231 | } |
e7e0cddf SS |
9232 | |
9233 | /* Dynamic printf requires and uses additional arguments on the | |
9234 | command line, otherwise it's an error. */ | |
9235 | if (type == bp_dprintf) | |
9236 | { | |
9237 | if (b->extra_string) | |
9238 | update_dprintf_command_list (b); | |
9239 | else | |
9240 | error (_("Format string required")); | |
9241 | } | |
9242 | else if (b->extra_string) | |
588ae58c | 9243 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9244 | } |
018d34a4 | 9245 | |
56435ebe | 9246 | b->display_canonical = display_canonical; |
018d34a4 VP |
9247 | if (addr_string) |
9248 | b->addr_string = addr_string; | |
9249 | else | |
9250 | /* addr_string has to be used or breakpoint_re_set will delete | |
9251 | me. */ | |
5af949e3 UW |
9252 | b->addr_string |
9253 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9254 | b->filter = filter; |
d9b3f62e | 9255 | } |
018d34a4 | 9256 | |
d9b3f62e PA |
9257 | static void |
9258 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9259 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9260 | char *filter, char *cond_string, |
e7e0cddf | 9261 | char *extra_string, |
d9b3f62e PA |
9262 | enum bptype type, enum bpdisp disposition, |
9263 | int thread, int task, int ignore_count, | |
c0a91b2b | 9264 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9265 | int enabled, int internal, unsigned flags, |
9266 | int display_canonical) | |
d9b3f62e PA |
9267 | { |
9268 | struct breakpoint *b; | |
9269 | struct cleanup *old_chain; | |
9270 | ||
9271 | if (is_tracepoint_type (type)) | |
9272 | { | |
9273 | struct tracepoint *t; | |
9274 | ||
9275 | t = XCNEW (struct tracepoint); | |
9276 | b = &t->base; | |
9277 | } | |
9278 | else | |
9279 | b = XNEW (struct breakpoint); | |
9280 | ||
9281 | old_chain = make_cleanup (xfree, b); | |
9282 | ||
9283 | init_breakpoint_sal (b, gdbarch, | |
9284 | sals, addr_string, | |
e7e0cddf | 9285 | filter, cond_string, extra_string, |
d9b3f62e PA |
9286 | type, disposition, |
9287 | thread, task, ignore_count, | |
9288 | ops, from_tty, | |
44f238bb PA |
9289 | enabled, internal, flags, |
9290 | display_canonical); | |
d9b3f62e PA |
9291 | discard_cleanups (old_chain); |
9292 | ||
3ea46bff | 9293 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9294 | } |
9295 | ||
9296 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9297 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9298 | value. COND_STRING, if not NULL, specified the condition to be | |
9299 | used for all breakpoints. Essentially the only case where | |
9300 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9301 | function. In that case, it's still not possible to specify | |
9302 | separate conditions for different overloaded functions, so | |
9303 | we take just a single condition string. | |
9304 | ||
c3f6f71d | 9305 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9306 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9307 | array contents). If the function fails (error() is called), the |
9308 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9309 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9310 | |
9311 | static void | |
8cdf0e15 | 9312 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9313 | struct linespec_result *canonical, |
e7e0cddf | 9314 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9315 | enum bptype type, enum bpdisp disposition, |
9316 | int thread, int task, int ignore_count, | |
c0a91b2b | 9317 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9318 | int enabled, int internal, unsigned flags) |
c906108c | 9319 | { |
018d34a4 | 9320 | int i; |
f8eba3c6 | 9321 | struct linespec_sals *lsal; |
cc59ec59 | 9322 | |
f8eba3c6 TT |
9323 | if (canonical->pre_expanded) |
9324 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9325 | ||
9326 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9327 | { |
f8eba3c6 TT |
9328 | /* Note that 'addr_string' can be NULL in the case of a plain |
9329 | 'break', without arguments. */ | |
9330 | char *addr_string = (canonical->addr_string | |
9331 | ? xstrdup (canonical->addr_string) | |
9332 | : NULL); | |
9333 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9334 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9335 | |
f8eba3c6 TT |
9336 | make_cleanup (xfree, filter_string); |
9337 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9338 | addr_string, | |
9339 | filter_string, | |
e7e0cddf SS |
9340 | cond_string, extra_string, |
9341 | type, disposition, | |
84f4c1fe | 9342 | thread, task, ignore_count, ops, |
44f238bb | 9343 | from_tty, enabled, internal, flags, |
56435ebe | 9344 | canonical->special_display); |
f8eba3c6 | 9345 | discard_cleanups (inner); |
c3f6f71d | 9346 | } |
c3f6f71d | 9347 | } |
c906108c | 9348 | |
9998af43 | 9349 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9350 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9351 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9352 | address strings. ADDRESS points to the end of the SAL. |
9353 | ||
9354 | The array and the line spec strings are allocated on the heap, it is | |
9355 | the caller's responsibility to free them. */ | |
c906108c | 9356 | |
b9362cc7 | 9357 | static void |
c3f6f71d | 9358 | parse_breakpoint_sals (char **address, |
58438ac1 | 9359 | struct linespec_result *canonical) |
c3f6f71d | 9360 | { |
c3f6f71d | 9361 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9362 | breakpoint. */ |
c3f6f71d JM |
9363 | if ((*address) == NULL |
9364 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9365 | { |
1bfeeb0f JL |
9366 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9367 | address. */ | |
9368 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9369 | { |
f8eba3c6 | 9370 | struct linespec_sals lsal; |
c3f6f71d | 9371 | struct symtab_and_line sal; |
1c8cdcb1 | 9372 | CORE_ADDR pc; |
cc59ec59 | 9373 | |
4a64f543 | 9374 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9375 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9376 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9377 | |
9378 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9379 | corresponding to the last call to print_frame_info. |
9380 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9381 | as the breakpoint line number is inappropriate otherwise. | |
9382 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9383 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9384 | pc = sal.pc; |
9385 | sal = find_pc_line (pc, 0); | |
00903456 | 9386 | |
4a64f543 | 9387 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9388 | where PC is the last displayed codepoint's address. So |
9389 | make sure to set sal.explicit_pc to prevent GDB from | |
9390 | trying to expand the list of sals to include all other | |
9391 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9392 | sal.pc = pc; |
00903456 JK |
9393 | sal.explicit_pc = 1; |
9394 | ||
f8eba3c6 TT |
9395 | lsal.sals.sals[0] = sal; |
9396 | lsal.sals.nelts = 1; | |
9397 | lsal.canonical = NULL; | |
9398 | ||
9399 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9400 | } |
9401 | else | |
8a3fe4f8 | 9402 | error (_("No default breakpoint address now.")); |
c906108c SS |
9403 | } |
9404 | else | |
9405 | { | |
cc80f267 JK |
9406 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9407 | ||
c906108c | 9408 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9409 | current_source_symtab (which is decode_line_1's default). |
9410 | This should produce the results we want almost all of the | |
cc80f267 JK |
9411 | time while leaving default_breakpoint_* alone. |
9412 | ||
9413 | ObjC: However, don't match an Objective-C method name which | |
9414 | may have a '+' or '-' succeeded by a '['. */ | |
9415 | if (last_displayed_sal_is_valid () | |
9416 | && (!cursal.symtab | |
9417 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9418 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9419 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9420 | get_last_displayed_symtab (), | |
9421 | get_last_displayed_line (), | |
9422 | canonical, NULL, NULL); | |
c906108c | 9423 | else |
f8eba3c6 | 9424 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9425 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9426 | } |
c3f6f71d | 9427 | } |
c906108c | 9428 | |
c906108c | 9429 | |
c3f6f71d | 9430 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9431 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9432 | |
b9362cc7 | 9433 | static void |
23e7acfb | 9434 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9435 | { |
9436 | int i; | |
cc59ec59 | 9437 | |
c3f6f71d | 9438 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9439 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9440 | } |
9441 | ||
7a697b8d SS |
9442 | /* Fast tracepoints may have restrictions on valid locations. For |
9443 | instance, a fast tracepoint using a jump instead of a trap will | |
9444 | likely have to overwrite more bytes than a trap would, and so can | |
9445 | only be placed where the instruction is longer than the jump, or a | |
9446 | multi-instruction sequence does not have a jump into the middle of | |
9447 | it, etc. */ | |
9448 | ||
9449 | static void | |
9450 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9451 | struct symtabs_and_lines *sals) | |
9452 | { | |
9453 | int i, rslt; | |
9454 | struct symtab_and_line *sal; | |
9455 | char *msg; | |
9456 | struct cleanup *old_chain; | |
9457 | ||
9458 | for (i = 0; i < sals->nelts; i++) | |
9459 | { | |
f8eba3c6 TT |
9460 | struct gdbarch *sarch; |
9461 | ||
7a697b8d SS |
9462 | sal = &sals->sals[i]; |
9463 | ||
f8eba3c6 TT |
9464 | sarch = get_sal_arch (*sal); |
9465 | /* We fall back to GDBARCH if there is no architecture | |
9466 | associated with SAL. */ | |
9467 | if (sarch == NULL) | |
9468 | sarch = gdbarch; | |
9469 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9470 | NULL, &msg); |
9471 | old_chain = make_cleanup (xfree, msg); | |
9472 | ||
9473 | if (!rslt) | |
9474 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9475 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9476 | |
9477 | do_cleanups (old_chain); | |
9478 | } | |
9479 | } | |
9480 | ||
af4908ba KS |
9481 | /* Issue an invalid thread ID error. */ |
9482 | ||
9483 | static void ATTRIBUTE_NORETURN | |
9484 | invalid_thread_id_error (int id) | |
9485 | { | |
9486 | error (_("Unknown thread %d."), id); | |
9487 | } | |
9488 | ||
018d34a4 VP |
9489 | /* Given TOK, a string specification of condition and thread, as |
9490 | accepted by the 'break' command, extract the condition | |
9491 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9492 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9493 | If no condition is found, *COND_STRING is set to NULL. |
9494 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9495 | |
9496 | static void | |
bbc13ae3 | 9497 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9498 | char **cond_string, int *thread, int *task, |
9499 | char **rest) | |
018d34a4 VP |
9500 | { |
9501 | *cond_string = NULL; | |
9502 | *thread = -1; | |
ed1d1739 KS |
9503 | *task = 0; |
9504 | *rest = NULL; | |
9505 | ||
018d34a4 VP |
9506 | while (tok && *tok) |
9507 | { | |
bbc13ae3 | 9508 | const char *end_tok; |
018d34a4 | 9509 | int toklen; |
bbc13ae3 KS |
9510 | const char *cond_start = NULL; |
9511 | const char *cond_end = NULL; | |
cc59ec59 | 9512 | |
bbc13ae3 | 9513 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9514 | |
9515 | if ((*tok == '"' || *tok == ',') && rest) | |
9516 | { | |
9517 | *rest = savestring (tok, strlen (tok)); | |
9518 | return; | |
9519 | } | |
9520 | ||
bbc13ae3 | 9521 | end_tok = skip_to_space_const (tok); |
d634f2de | 9522 | |
018d34a4 | 9523 | toklen = end_tok - tok; |
d634f2de | 9524 | |
018d34a4 VP |
9525 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9526 | { | |
f7545552 TT |
9527 | struct expression *expr; |
9528 | ||
018d34a4 | 9529 | tok = cond_start = end_tok + 1; |
1bb9788d | 9530 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9531 | xfree (expr); |
018d34a4 | 9532 | cond_end = tok; |
d634f2de | 9533 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9534 | } |
9535 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9536 | { | |
9537 | char *tmptok; | |
d634f2de | 9538 | |
018d34a4 | 9539 | tok = end_tok + 1; |
bbc13ae3 | 9540 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9541 | if (tok == tmptok) |
9542 | error (_("Junk after thread keyword.")); | |
9543 | if (!valid_thread_id (*thread)) | |
af4908ba | 9544 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9545 | tok = tmptok; |
018d34a4 | 9546 | } |
4a306c9a JB |
9547 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9548 | { | |
9549 | char *tmptok; | |
9550 | ||
9551 | tok = end_tok + 1; | |
bbc13ae3 | 9552 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9553 | if (tok == tmptok) |
9554 | error (_("Junk after task keyword.")); | |
9555 | if (!valid_task_id (*task)) | |
b6199126 | 9556 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9557 | tok = tmptok; |
4a306c9a | 9558 | } |
e7e0cddf SS |
9559 | else if (rest) |
9560 | { | |
9561 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9562 | return; |
e7e0cddf | 9563 | } |
018d34a4 VP |
9564 | else |
9565 | error (_("Junk at end of arguments.")); | |
9566 | } | |
9567 | } | |
9568 | ||
0fb4aa4b PA |
9569 | /* Decode a static tracepoint marker spec. */ |
9570 | ||
9571 | static struct symtabs_and_lines | |
9572 | decode_static_tracepoint_spec (char **arg_p) | |
9573 | { | |
9574 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9575 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9576 | struct cleanup *old_chain; |
9577 | char *p = &(*arg_p)[3]; | |
9578 | char *endp; | |
9579 | char *marker_str; | |
9580 | int i; | |
9581 | ||
e9cafbcc | 9582 | p = skip_spaces (p); |
0fb4aa4b | 9583 | |
e9cafbcc | 9584 | endp = skip_to_space (p); |
0fb4aa4b PA |
9585 | |
9586 | marker_str = savestring (p, endp - p); | |
9587 | old_chain = make_cleanup (xfree, marker_str); | |
9588 | ||
9589 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9590 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9591 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9592 | ||
9593 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9594 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9595 | ||
9596 | for (i = 0; i < sals.nelts; i++) | |
9597 | { | |
9598 | struct static_tracepoint_marker *marker; | |
9599 | ||
9600 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9601 | ||
9602 | init_sal (&sals.sals[i]); | |
9603 | ||
9604 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9605 | sals.sals[i].pc = marker->address; | |
9606 | ||
9607 | release_static_tracepoint_marker (marker); | |
9608 | } | |
9609 | ||
9610 | do_cleanups (old_chain); | |
9611 | ||
9612 | *arg_p = endp; | |
9613 | return sals; | |
9614 | } | |
9615 | ||
fd9b8c24 PA |
9616 | /* Set a breakpoint. This function is shared between CLI and MI |
9617 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9618 | modes of operations, selected by the PARSE_ARG parameter. If |
9619 | non-zero, the function will parse ARG, extracting location, | |
9620 | condition, thread and extra string. Otherwise, ARG is just the | |
9621 | breakpoint's location, with condition, thread, and extra string | |
9622 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9623 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9624 | from the internal breakpoint count. Returns true if any breakpoint | |
9625 | was created; false otherwise. */ | |
0101ce28 | 9626 | |
8cdf0e15 VP |
9627 | int |
9628 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9629 | char *arg, char *cond_string, |
9630 | int thread, char *extra_string, | |
f6de8ec2 | 9631 | int parse_arg, |
0fb4aa4b | 9632 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9633 | int ignore_count, |
9634 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9635 | const struct breakpoint_ops *ops, |
44f238bb PA |
9636 | int from_tty, int enabled, int internal, |
9637 | unsigned flags) | |
c3f6f71d | 9638 | { |
b78a6381 | 9639 | volatile struct gdb_exception e; |
f8eba3c6 | 9640 | char *copy_arg = NULL; |
c3f6f71d | 9641 | char *addr_start = arg; |
7efd8fc2 | 9642 | struct linespec_result canonical; |
c3f6f71d | 9643 | struct cleanup *old_chain; |
80c99de1 | 9644 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9645 | int pending = 0; |
4a306c9a | 9646 | int task = 0; |
86b17b60 | 9647 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9648 | |
348d480f PA |
9649 | gdb_assert (ops != NULL); |
9650 | ||
7efd8fc2 | 9651 | init_linespec_result (&canonical); |
c3f6f71d | 9652 | |
b78a6381 TT |
9653 | TRY_CATCH (e, RETURN_MASK_ALL) |
9654 | { | |
983af33b SDJ |
9655 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9656 | addr_start, ©_arg); | |
b78a6381 | 9657 | } |
0101ce28 JJ |
9658 | |
9659 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9660 | switch (e.reason) |
0101ce28 | 9661 | { |
983af33b SDJ |
9662 | case GDB_NO_ERROR: |
9663 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9664 | return 0; | |
9665 | break; | |
05ff989b AC |
9666 | case RETURN_ERROR: |
9667 | switch (e.error) | |
0101ce28 | 9668 | { |
05ff989b | 9669 | case NOT_FOUND_ERROR: |
0101ce28 | 9670 | |
05ff989b AC |
9671 | /* If pending breakpoint support is turned off, throw |
9672 | error. */ | |
fa8d40ab JJ |
9673 | |
9674 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9675 | throw_exception (e); |
9676 | ||
9677 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9678 | |
05ff989b AC |
9679 | /* If pending breakpoint support is auto query and the user |
9680 | selects no, then simply return the error code. */ | |
059fb39f | 9681 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9682 | && !nquery (_("Make %s pending on future shared library load? "), |
9683 | bptype_string (type_wanted))) | |
fd9b8c24 | 9684 | return 0; |
fa8d40ab | 9685 | |
05ff989b AC |
9686 | /* At this point, either the user was queried about setting |
9687 | a pending breakpoint and selected yes, or pending | |
9688 | breakpoint behavior is on and thus a pending breakpoint | |
9689 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9690 | { |
9691 | struct linespec_sals lsal; | |
9692 | ||
9693 | copy_arg = xstrdup (addr_start); | |
9694 | lsal.canonical = xstrdup (copy_arg); | |
9695 | lsal.sals.nelts = 1; | |
9696 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9697 | init_sal (&lsal.sals.sals[0]); | |
9698 | pending = 1; | |
9699 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9700 | } | |
05ff989b AC |
9701 | break; |
9702 | default: | |
98deb0da | 9703 | throw_exception (e); |
0101ce28 | 9704 | } |
2abae994 | 9705 | break; |
05ff989b | 9706 | default: |
983af33b | 9707 | throw_exception (e); |
0101ce28 | 9708 | } |
c3f6f71d | 9709 | |
4a64f543 | 9710 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9711 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9712 | |
c3f6f71d JM |
9713 | /* ----------------------------- SNIP ----------------------------- |
9714 | Anything added to the cleanup chain beyond this point is assumed | |
9715 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9716 | then the memory is not reclaimed. */ |
9717 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9718 | |
c3f6f71d JM |
9719 | /* Resolve all line numbers to PC's and verify that the addresses |
9720 | are ok for the target. */ | |
0101ce28 | 9721 | if (!pending) |
f8eba3c6 TT |
9722 | { |
9723 | int ix; | |
9724 | struct linespec_sals *iter; | |
9725 | ||
9726 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9727 | breakpoint_sals_to_pc (&iter->sals); | |
9728 | } | |
c3f6f71d | 9729 | |
7a697b8d | 9730 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9731 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9732 | { |
9733 | int ix; | |
9734 | struct linespec_sals *iter; | |
9735 | ||
9736 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9737 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9738 | } | |
7a697b8d | 9739 | |
c3f6f71d JM |
9740 | /* Verify that condition can be parsed, before setting any |
9741 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9742 | breakpoint. */ |
0101ce28 | 9743 | if (!pending) |
c3f6f71d | 9744 | { |
f6de8ec2 | 9745 | if (parse_arg) |
72b2ff0e | 9746 | { |
0878d0fa | 9747 | char *rest; |
52d361e1 YQ |
9748 | struct linespec_sals *lsal; |
9749 | ||
9750 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9751 | ||
0878d0fa YQ |
9752 | /* Here we only parse 'arg' to separate condition |
9753 | from thread number, so parsing in context of first | |
9754 | sal is OK. When setting the breakpoint we'll | |
9755 | re-parse it in context of each sal. */ | |
9756 | ||
9757 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9758 | &thread, &task, &rest); | |
9759 | if (cond_string) | |
9760 | make_cleanup (xfree, cond_string); | |
9761 | if (rest) | |
9762 | make_cleanup (xfree, rest); | |
9763 | if (rest) | |
9764 | extra_string = rest; | |
72b2ff0e | 9765 | } |
2f069f6f | 9766 | else |
72b2ff0e | 9767 | { |
0878d0fa YQ |
9768 | if (*arg != '\0') |
9769 | error (_("Garbage '%s' at end of location"), arg); | |
9770 | ||
9771 | /* Create a private copy of condition string. */ | |
9772 | if (cond_string) | |
9773 | { | |
9774 | cond_string = xstrdup (cond_string); | |
9775 | make_cleanup (xfree, cond_string); | |
9776 | } | |
9777 | /* Create a private copy of any extra string. */ | |
9778 | if (extra_string) | |
9779 | { | |
9780 | extra_string = xstrdup (extra_string); | |
9781 | make_cleanup (xfree, extra_string); | |
9782 | } | |
72b2ff0e | 9783 | } |
0fb4aa4b | 9784 | |
52d361e1 | 9785 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9786 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9787 | tempflag ? disp_del : disp_donttouch, |
9788 | thread, task, ignore_count, ops, | |
44f238bb | 9789 | from_tty, enabled, internal, flags); |
c906108c | 9790 | } |
0101ce28 JJ |
9791 | else |
9792 | { | |
0101ce28 JJ |
9793 | struct breakpoint *b; |
9794 | ||
0101ce28 JJ |
9795 | make_cleanup (xfree, copy_arg); |
9796 | ||
bfccc43c YQ |
9797 | if (is_tracepoint_type (type_wanted)) |
9798 | { | |
9799 | struct tracepoint *t; | |
9800 | ||
9801 | t = XCNEW (struct tracepoint); | |
9802 | b = &t->base; | |
9803 | } | |
9804 | else | |
9805 | b = XNEW (struct breakpoint); | |
9806 | ||
9807 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9808 | ||
f8eba3c6 | 9809 | b->addr_string = copy_arg; |
f6de8ec2 | 9810 | if (parse_arg) |
e12c7713 MK |
9811 | b->cond_string = NULL; |
9812 | else | |
9813 | { | |
9814 | /* Create a private copy of condition string. */ | |
9815 | if (cond_string) | |
9816 | { | |
9817 | cond_string = xstrdup (cond_string); | |
9818 | make_cleanup (xfree, cond_string); | |
9819 | } | |
9820 | b->cond_string = cond_string; | |
9821 | } | |
e7e0cddf | 9822 | b->extra_string = NULL; |
0101ce28 | 9823 | b->ignore_count = ignore_count; |
0101ce28 | 9824 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9825 | b->condition_not_parsed = 1; |
41447f92 | 9826 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9827 | if ((type_wanted != bp_breakpoint |
9828 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9829 | b->pspace = current_program_space; |
8bea4e01 | 9830 | |
bfccc43c | 9831 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9832 | } |
9833 | ||
f8eba3c6 | 9834 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9835 | { |
3e43a32a MS |
9836 | warning (_("Multiple breakpoints were set.\nUse the " |
9837 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9838 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9839 | } |
9840 | ||
80c99de1 PA |
9841 | /* That's it. Discard the cleanups for data inserted into the |
9842 | breakpoint. */ | |
9843 | discard_cleanups (bkpt_chain); | |
9844 | /* But cleanup everything else. */ | |
c3f6f71d | 9845 | do_cleanups (old_chain); |
217dc9e2 | 9846 | |
80c99de1 | 9847 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9848 | update_global_location_list (1); |
fd9b8c24 PA |
9849 | |
9850 | return 1; | |
c3f6f71d | 9851 | } |
c906108c | 9852 | |
348d480f | 9853 | /* Set a breakpoint. |
72b2ff0e VP |
9854 | ARG is a string describing breakpoint address, |
9855 | condition, and thread. | |
9856 | FLAG specifies if a breakpoint is hardware on, | |
9857 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9858 | and BP_TEMPFLAG. */ | |
348d480f | 9859 | |
98deb0da | 9860 | static void |
72b2ff0e | 9861 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9862 | { |
72b2ff0e | 9863 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9864 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9865 | ? bp_hardware_breakpoint | |
9866 | : bp_breakpoint); | |
55aa24fb SDJ |
9867 | struct breakpoint_ops *ops; |
9868 | const char *arg_cp = arg; | |
9869 | ||
9870 | /* Matching breakpoints on probes. */ | |
9871 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9872 | ops = &bkpt_probe_breakpoint_ops; | |
9873 | else | |
9874 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9875 | |
8cdf0e15 VP |
9876 | create_breakpoint (get_current_arch (), |
9877 | arg, | |
e7e0cddf | 9878 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9879 | tempflag, type_wanted, |
8cdf0e15 VP |
9880 | 0 /* Ignore count */, |
9881 | pending_break_support, | |
55aa24fb | 9882 | ops, |
8cdf0e15 | 9883 | from_tty, |
84f4c1fe | 9884 | 1 /* enabled */, |
44f238bb PA |
9885 | 0 /* internal */, |
9886 | 0); | |
c906108c SS |
9887 | } |
9888 | ||
c906108c SS |
9889 | /* Helper function for break_command_1 and disassemble_command. */ |
9890 | ||
9891 | void | |
fba45db2 | 9892 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9893 | { |
9894 | CORE_ADDR pc; | |
9895 | ||
9896 | if (sal->pc == 0 && sal->symtab != NULL) | |
9897 | { | |
9898 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9899 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9900 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9901 | sal->pc = pc; |
6a048695 | 9902 | |
4a64f543 MS |
9903 | /* If this SAL corresponds to a breakpoint inserted using a line |
9904 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9905 | if (sal->explicit_line) |
059acae7 | 9906 | skip_prologue_sal (sal); |
c906108c SS |
9907 | } |
9908 | ||
9909 | if (sal->section == 0 && sal->symtab != NULL) | |
9910 | { | |
9911 | struct blockvector *bv; | |
c5aa993b JM |
9912 | struct block *b; |
9913 | struct symbol *sym; | |
c906108c | 9914 | |
801e3a5b | 9915 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9916 | if (bv != NULL) |
9917 | { | |
7f0df278 | 9918 | sym = block_linkage_function (b); |
c906108c SS |
9919 | if (sym != NULL) |
9920 | { | |
9921 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9922 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9923 | } |
9924 | else | |
9925 | { | |
4a64f543 MS |
9926 | /* It really is worthwhile to have the section, so we'll |
9927 | just have to look harder. This case can be executed | |
9928 | if we have line numbers but no functions (as can | |
9929 | happen in assembly source). */ | |
c906108c | 9930 | |
7cbd4a93 | 9931 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9932 | struct cleanup *old_chain = save_current_space_and_thread (); |
9933 | ||
9934 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9935 | |
9936 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9937 | if (msym.minsym) |
e27d198c | 9938 | sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9939 | |
9940 | do_cleanups (old_chain); | |
c906108c SS |
9941 | } |
9942 | } | |
9943 | } | |
9944 | } | |
9945 | ||
9946 | void | |
fba45db2 | 9947 | break_command (char *arg, int from_tty) |
c906108c | 9948 | { |
db107f19 | 9949 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9950 | } |
9951 | ||
c906108c | 9952 | void |
fba45db2 | 9953 | tbreak_command (char *arg, int from_tty) |
c906108c | 9954 | { |
db107f19 | 9955 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9956 | } |
9957 | ||
c906108c | 9958 | static void |
fba45db2 | 9959 | hbreak_command (char *arg, int from_tty) |
c906108c | 9960 | { |
db107f19 | 9961 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9962 | } |
9963 | ||
9964 | static void | |
fba45db2 | 9965 | thbreak_command (char *arg, int from_tty) |
c906108c | 9966 | { |
db107f19 | 9967 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9968 | } |
9969 | ||
9970 | static void | |
fba45db2 | 9971 | stop_command (char *arg, int from_tty) |
c906108c | 9972 | { |
a3f17187 | 9973 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9974 | Usage: stop in <function | address>\n\ |
a3f17187 | 9975 | stop at <line>\n")); |
c906108c SS |
9976 | } |
9977 | ||
9978 | static void | |
fba45db2 | 9979 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9980 | { |
9981 | int badInput = 0; | |
9982 | ||
c5aa993b | 9983 | if (arg == (char *) NULL) |
c906108c SS |
9984 | badInput = 1; |
9985 | else if (*arg != '*') | |
9986 | { | |
9987 | char *argptr = arg; | |
9988 | int hasColon = 0; | |
9989 | ||
4a64f543 | 9990 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9991 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9992 | function/method name. */ |
c906108c | 9993 | while (*argptr && !hasColon) |
c5aa993b JM |
9994 | { |
9995 | hasColon = (*argptr == ':'); | |
9996 | argptr++; | |
9997 | } | |
c906108c SS |
9998 | |
9999 | if (hasColon) | |
c5aa993b | 10000 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10001 | else |
c5aa993b | 10002 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10003 | } |
10004 | ||
10005 | if (badInput) | |
a3f17187 | 10006 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10007 | else |
db107f19 | 10008 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10009 | } |
10010 | ||
10011 | static void | |
fba45db2 | 10012 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10013 | { |
10014 | int badInput = 0; | |
10015 | ||
c5aa993b | 10016 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10017 | badInput = 1; |
10018 | else | |
10019 | { | |
10020 | char *argptr = arg; | |
10021 | int hasColon = 0; | |
10022 | ||
4a64f543 MS |
10023 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10024 | it is probably a line number. */ | |
c906108c | 10025 | while (*argptr && !hasColon) |
c5aa993b JM |
10026 | { |
10027 | hasColon = (*argptr == ':'); | |
10028 | argptr++; | |
10029 | } | |
c906108c SS |
10030 | |
10031 | if (hasColon) | |
c5aa993b | 10032 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10033 | else |
c5aa993b | 10034 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10035 | } |
10036 | ||
10037 | if (badInput) | |
a3f17187 | 10038 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10039 | else |
db107f19 | 10040 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10041 | } |
10042 | ||
e7e0cddf SS |
10043 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10044 | with a prewired command list consisting of a single output command, | |
10045 | built from extra arguments supplied on the dprintf command | |
10046 | line. */ | |
10047 | ||
da821c7b | 10048 | static void |
e7e0cddf SS |
10049 | dprintf_command (char *arg, int from_tty) |
10050 | { | |
10051 | create_breakpoint (get_current_arch (), | |
10052 | arg, | |
10053 | NULL, 0, NULL, 1 /* parse arg */, | |
10054 | 0, bp_dprintf, | |
10055 | 0 /* Ignore count */, | |
10056 | pending_break_support, | |
10057 | &dprintf_breakpoint_ops, | |
10058 | from_tty, | |
10059 | 1 /* enabled */, | |
10060 | 0 /* internal */, | |
10061 | 0); | |
10062 | } | |
10063 | ||
d3ce09f5 SS |
10064 | static void |
10065 | agent_printf_command (char *arg, int from_tty) | |
10066 | { | |
10067 | error (_("May only run agent-printf on the target")); | |
10068 | } | |
10069 | ||
f1310107 TJB |
10070 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10071 | ranged breakpoints. */ | |
10072 | ||
10073 | static int | |
10074 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10075 | struct address_space *aspace, | |
09ac7c10 TT |
10076 | CORE_ADDR bp_addr, |
10077 | const struct target_waitstatus *ws) | |
f1310107 | 10078 | { |
09ac7c10 | 10079 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10080 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10081 | return 0; |
10082 | ||
f1310107 TJB |
10083 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10084 | bl->length, aspace, bp_addr); | |
10085 | } | |
10086 | ||
10087 | /* Implement the "resources_needed" breakpoint_ops method for | |
10088 | ranged breakpoints. */ | |
10089 | ||
10090 | static int | |
10091 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10092 | { | |
10093 | return target_ranged_break_num_registers (); | |
10094 | } | |
10095 | ||
10096 | /* Implement the "print_it" breakpoint_ops method for | |
10097 | ranged breakpoints. */ | |
10098 | ||
10099 | static enum print_stop_action | |
348d480f | 10100 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10101 | { |
348d480f | 10102 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10103 | struct bp_location *bl = b->loc; |
79a45e25 | 10104 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10105 | |
10106 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10107 | ||
10108 | /* Ranged breakpoints have only one location. */ | |
10109 | gdb_assert (bl && bl->next == NULL); | |
10110 | ||
10111 | annotate_breakpoint (b->number); | |
10112 | if (b->disposition == disp_del) | |
10113 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10114 | else | |
10115 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10116 | if (ui_out_is_mi_like_p (uiout)) | |
10117 | { | |
10118 | ui_out_field_string (uiout, "reason", | |
10119 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10120 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10121 | } | |
10122 | ui_out_field_int (uiout, "bkptno", b->number); | |
10123 | ui_out_text (uiout, ", "); | |
10124 | ||
10125 | return PRINT_SRC_AND_LOC; | |
10126 | } | |
10127 | ||
10128 | /* Implement the "print_one" breakpoint_ops method for | |
10129 | ranged breakpoints. */ | |
10130 | ||
10131 | static void | |
10132 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10133 | struct bp_location **last_loc) | |
10134 | { | |
10135 | struct bp_location *bl = b->loc; | |
10136 | struct value_print_options opts; | |
79a45e25 | 10137 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10138 | |
10139 | /* Ranged breakpoints have only one location. */ | |
10140 | gdb_assert (bl && bl->next == NULL); | |
10141 | ||
10142 | get_user_print_options (&opts); | |
10143 | ||
10144 | if (opts.addressprint) | |
10145 | /* We don't print the address range here, it will be printed later | |
10146 | by print_one_detail_ranged_breakpoint. */ | |
10147 | ui_out_field_skip (uiout, "addr"); | |
10148 | annotate_field (5); | |
10149 | print_breakpoint_location (b, bl); | |
10150 | *last_loc = bl; | |
10151 | } | |
10152 | ||
10153 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10154 | ranged breakpoints. */ | |
10155 | ||
10156 | static void | |
10157 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10158 | struct ui_out *uiout) | |
10159 | { | |
10160 | CORE_ADDR address_start, address_end; | |
10161 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10162 | struct ui_file *stb = mem_fileopen (); |
10163 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10164 | |
10165 | gdb_assert (bl); | |
10166 | ||
10167 | address_start = bl->address; | |
10168 | address_end = address_start + bl->length - 1; | |
10169 | ||
10170 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10171 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10172 | print_core_address (bl->gdbarch, address_start), |
10173 | print_core_address (bl->gdbarch, address_end)); | |
10174 | ui_out_field_stream (uiout, "addr", stb); | |
10175 | ui_out_text (uiout, "\n"); | |
10176 | ||
10177 | do_cleanups (cleanup); | |
10178 | } | |
10179 | ||
10180 | /* Implement the "print_mention" breakpoint_ops method for | |
10181 | ranged breakpoints. */ | |
10182 | ||
10183 | static void | |
10184 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10185 | { | |
10186 | struct bp_location *bl = b->loc; | |
79a45e25 | 10187 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10188 | |
10189 | gdb_assert (bl); | |
10190 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10191 | ||
10192 | if (ui_out_is_mi_like_p (uiout)) | |
10193 | return; | |
10194 | ||
10195 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10196 | b->number, paddress (bl->gdbarch, bl->address), | |
10197 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10198 | } | |
10199 | ||
10200 | /* Implement the "print_recreate" breakpoint_ops method for | |
10201 | ranged breakpoints. */ | |
10202 | ||
10203 | static void | |
10204 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10205 | { | |
10206 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10207 | b->addr_string_range_end); | |
d9b3f62e | 10208 | print_recreate_thread (b, fp); |
f1310107 TJB |
10209 | } |
10210 | ||
10211 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10212 | ||
2060206e | 10213 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10214 | |
10215 | /* Find the address where the end of the breakpoint range should be | |
10216 | placed, given the SAL of the end of the range. This is so that if | |
10217 | the user provides a line number, the end of the range is set to the | |
10218 | last instruction of the given line. */ | |
10219 | ||
10220 | static CORE_ADDR | |
10221 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10222 | { | |
10223 | CORE_ADDR end; | |
10224 | ||
10225 | /* If the user provided a PC value, use it. Otherwise, | |
10226 | find the address of the end of the given location. */ | |
10227 | if (sal.explicit_pc) | |
10228 | end = sal.pc; | |
10229 | else | |
10230 | { | |
10231 | int ret; | |
10232 | CORE_ADDR start; | |
10233 | ||
10234 | ret = find_line_pc_range (sal, &start, &end); | |
10235 | if (!ret) | |
10236 | error (_("Could not find location of the end of the range.")); | |
10237 | ||
10238 | /* find_line_pc_range returns the start of the next line. */ | |
10239 | end--; | |
10240 | } | |
10241 | ||
10242 | return end; | |
10243 | } | |
10244 | ||
10245 | /* Implement the "break-range" CLI command. */ | |
10246 | ||
10247 | static void | |
10248 | break_range_command (char *arg, int from_tty) | |
10249 | { | |
10250 | char *arg_start, *addr_string_start, *addr_string_end; | |
10251 | struct linespec_result canonical_start, canonical_end; | |
10252 | int bp_count, can_use_bp, length; | |
10253 | CORE_ADDR end; | |
10254 | struct breakpoint *b; | |
10255 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10256 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10257 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10258 | |
10259 | /* We don't support software ranged breakpoints. */ | |
10260 | if (target_ranged_break_num_registers () < 0) | |
10261 | error (_("This target does not support hardware ranged breakpoints.")); | |
10262 | ||
10263 | bp_count = hw_breakpoint_used_count (); | |
10264 | bp_count += target_ranged_break_num_registers (); | |
10265 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10266 | bp_count, 0); | |
10267 | if (can_use_bp < 0) | |
10268 | error (_("Hardware breakpoints used exceeds limit.")); | |
10269 | ||
f8eba3c6 | 10270 | arg = skip_spaces (arg); |
f1310107 TJB |
10271 | if (arg == NULL || arg[0] == '\0') |
10272 | error(_("No address range specified.")); | |
10273 | ||
f1310107 TJB |
10274 | init_linespec_result (&canonical_start); |
10275 | ||
f8eba3c6 TT |
10276 | arg_start = arg; |
10277 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10278 | |
f8eba3c6 | 10279 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10280 | |
10281 | if (arg[0] != ',') | |
10282 | error (_("Too few arguments.")); | |
f8eba3c6 | 10283 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10284 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10285 | |
10286 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10287 | ||
10288 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10289 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10290 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10291 | ||
f8eba3c6 TT |
10292 | sal_start = lsal_start->sals.sals[0]; |
10293 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10294 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10295 | |
10296 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10297 | arg = skip_spaces (arg); |
f1310107 TJB |
10298 | |
10299 | /* Parse the end location. */ | |
10300 | ||
f1310107 TJB |
10301 | init_linespec_result (&canonical_end); |
10302 | arg_start = arg; | |
10303 | ||
f8eba3c6 | 10304 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10305 | parse_breakpoint_sals because we need to specify the start location's |
10306 | symtab and line as the default symtab and line for the end of the | |
10307 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10308 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10309 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10310 | sal_start.symtab, sal_start.line, | |
10311 | &canonical_end, NULL, NULL); | |
10312 | ||
10313 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10314 | |
f8eba3c6 | 10315 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10316 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10317 | |
10318 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10319 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10320 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10321 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10322 | ||
f8eba3c6 TT |
10323 | sal_end = lsal_end->sals.sals[0]; |
10324 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10325 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10326 | |
10327 | end = find_breakpoint_range_end (sal_end); | |
10328 | if (sal_start.pc > end) | |
177b42fe | 10329 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10330 | |
10331 | length = end - sal_start.pc + 1; | |
10332 | if (length < 0) | |
10333 | /* Length overflowed. */ | |
10334 | error (_("Address range too large.")); | |
10335 | else if (length == 1) | |
10336 | { | |
10337 | /* This range is simple enough to be handled by | |
10338 | the `hbreak' command. */ | |
10339 | hbreak_command (addr_string_start, 1); | |
10340 | ||
10341 | do_cleanups (cleanup_bkpt); | |
10342 | ||
10343 | return; | |
10344 | } | |
10345 | ||
10346 | /* Now set up the breakpoint. */ | |
10347 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10348 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10349 | set_breakpoint_count (breakpoint_count + 1); |
10350 | b->number = breakpoint_count; | |
10351 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10352 | b->addr_string = xstrdup (addr_string_start); |
10353 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10354 | b->loc->length = length; |
10355 | ||
f8eba3c6 | 10356 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10357 | |
10358 | mention (b); | |
8d3788bd | 10359 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10360 | update_global_location_list (1); |
10361 | } | |
10362 | ||
4a64f543 MS |
10363 | /* Return non-zero if EXP is verified as constant. Returned zero |
10364 | means EXP is variable. Also the constant detection may fail for | |
10365 | some constant expressions and in such case still falsely return | |
10366 | zero. */ | |
2e6e3d9c | 10367 | |
65d79d4b SDJ |
10368 | static int |
10369 | watchpoint_exp_is_const (const struct expression *exp) | |
10370 | { | |
10371 | int i = exp->nelts; | |
10372 | ||
10373 | while (i > 0) | |
10374 | { | |
10375 | int oplenp, argsp; | |
10376 | ||
10377 | /* We are only interested in the descriptor of each element. */ | |
10378 | operator_length (exp, i, &oplenp, &argsp); | |
10379 | i -= oplenp; | |
10380 | ||
10381 | switch (exp->elts[i].opcode) | |
10382 | { | |
10383 | case BINOP_ADD: | |
10384 | case BINOP_SUB: | |
10385 | case BINOP_MUL: | |
10386 | case BINOP_DIV: | |
10387 | case BINOP_REM: | |
10388 | case BINOP_MOD: | |
10389 | case BINOP_LSH: | |
10390 | case BINOP_RSH: | |
10391 | case BINOP_LOGICAL_AND: | |
10392 | case BINOP_LOGICAL_OR: | |
10393 | case BINOP_BITWISE_AND: | |
10394 | case BINOP_BITWISE_IOR: | |
10395 | case BINOP_BITWISE_XOR: | |
10396 | case BINOP_EQUAL: | |
10397 | case BINOP_NOTEQUAL: | |
10398 | case BINOP_LESS: | |
10399 | case BINOP_GTR: | |
10400 | case BINOP_LEQ: | |
10401 | case BINOP_GEQ: | |
10402 | case BINOP_REPEAT: | |
10403 | case BINOP_COMMA: | |
10404 | case BINOP_EXP: | |
10405 | case BINOP_MIN: | |
10406 | case BINOP_MAX: | |
10407 | case BINOP_INTDIV: | |
10408 | case BINOP_CONCAT: | |
10409 | case BINOP_IN: | |
10410 | case BINOP_RANGE: | |
10411 | case TERNOP_COND: | |
10412 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10413 | |
10414 | case OP_LONG: | |
10415 | case OP_DOUBLE: | |
10416 | case OP_DECFLOAT: | |
10417 | case OP_LAST: | |
10418 | case OP_COMPLEX: | |
10419 | case OP_STRING: | |
65d79d4b SDJ |
10420 | case OP_ARRAY: |
10421 | case OP_TYPE: | |
608b4967 TT |
10422 | case OP_TYPEOF: |
10423 | case OP_DECLTYPE: | |
6e72ca20 | 10424 | case OP_TYPEID: |
65d79d4b SDJ |
10425 | case OP_NAME: |
10426 | case OP_OBJC_NSSTRING: | |
10427 | ||
10428 | case UNOP_NEG: | |
10429 | case UNOP_LOGICAL_NOT: | |
10430 | case UNOP_COMPLEMENT: | |
10431 | case UNOP_ADDR: | |
10432 | case UNOP_HIGH: | |
aeaa2474 | 10433 | case UNOP_CAST: |
9eaf6705 TT |
10434 | |
10435 | case UNOP_CAST_TYPE: | |
10436 | case UNOP_REINTERPRET_CAST: | |
10437 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10438 | /* Unary, binary and ternary operators: We have to check |
10439 | their operands. If they are constant, then so is the | |
10440 | result of that operation. For instance, if A and B are | |
10441 | determined to be constants, then so is "A + B". | |
10442 | ||
10443 | UNOP_IND is one exception to the rule above, because the | |
10444 | value of *ADDR is not necessarily a constant, even when | |
10445 | ADDR is. */ | |
65d79d4b SDJ |
10446 | break; |
10447 | ||
10448 | case OP_VAR_VALUE: | |
10449 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10450 | |
65d79d4b | 10451 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10452 | possible that a buggy compiler could mark a variable as |
10453 | constant even when it is not, and TYPE_CONST would return | |
10454 | true in this case, while SYMBOL_CLASS wouldn't. | |
10455 | ||
10456 | We also have to check for function symbols because they | |
10457 | are always constant. */ | |
65d79d4b SDJ |
10458 | { |
10459 | struct symbol *s = exp->elts[i + 2].symbol; | |
10460 | ||
10461 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10462 | && SYMBOL_CLASS (s) != LOC_CONST | |
10463 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10464 | return 0; | |
10465 | break; | |
10466 | } | |
10467 | ||
10468 | /* The default action is to return 0 because we are using | |
10469 | the optimistic approach here: If we don't know something, | |
10470 | then it is not a constant. */ | |
10471 | default: | |
10472 | return 0; | |
10473 | } | |
10474 | } | |
10475 | ||
10476 | return 1; | |
10477 | } | |
10478 | ||
3a5c3e22 PA |
10479 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10480 | ||
10481 | static void | |
10482 | dtor_watchpoint (struct breakpoint *self) | |
10483 | { | |
10484 | struct watchpoint *w = (struct watchpoint *) self; | |
10485 | ||
10486 | xfree (w->cond_exp); | |
10487 | xfree (w->exp); | |
10488 | xfree (w->exp_string); | |
10489 | xfree (w->exp_string_reparse); | |
10490 | value_free (w->val); | |
10491 | ||
10492 | base_breakpoint_ops.dtor (self); | |
10493 | } | |
10494 | ||
348d480f PA |
10495 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10496 | ||
10497 | static void | |
10498 | re_set_watchpoint (struct breakpoint *b) | |
10499 | { | |
3a5c3e22 PA |
10500 | struct watchpoint *w = (struct watchpoint *) b; |
10501 | ||
348d480f PA |
10502 | /* Watchpoint can be either on expression using entirely global |
10503 | variables, or it can be on local variables. | |
10504 | ||
10505 | Watchpoints of the first kind are never auto-deleted, and even | |
10506 | persist across program restarts. Since they can use variables | |
10507 | from shared libraries, we need to reparse expression as libraries | |
10508 | are loaded and unloaded. | |
10509 | ||
10510 | Watchpoints on local variables can also change meaning as result | |
10511 | of solib event. For example, if a watchpoint uses both a local | |
10512 | and a global variables in expression, it's a local watchpoint, | |
10513 | but unloading of a shared library will make the expression | |
10514 | invalid. This is not a very common use case, but we still | |
10515 | re-evaluate expression, to avoid surprises to the user. | |
10516 | ||
10517 | Note that for local watchpoints, we re-evaluate it only if | |
10518 | watchpoints frame id is still valid. If it's not, it means the | |
10519 | watchpoint is out of scope and will be deleted soon. In fact, | |
10520 | I'm not sure we'll ever be called in this case. | |
10521 | ||
10522 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10523 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10524 | |
3a5c3e22 PA |
10525 | Don't do anything about disabled watchpoints, since they will be |
10526 | reevaluated again when enabled. */ | |
10527 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10528 | } |
10529 | ||
77b06cd7 TJB |
10530 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10531 | ||
10532 | static int | |
10533 | insert_watchpoint (struct bp_location *bl) | |
10534 | { | |
3a5c3e22 PA |
10535 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10536 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10537 | |
10538 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10539 | w->cond_exp); |
77b06cd7 TJB |
10540 | } |
10541 | ||
10542 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10543 | ||
10544 | static int | |
10545 | remove_watchpoint (struct bp_location *bl) | |
10546 | { | |
3a5c3e22 PA |
10547 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10548 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10549 | |
10550 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10551 | w->cond_exp); |
e09342b5 TJB |
10552 | } |
10553 | ||
e09342b5 | 10554 | static int |
348d480f | 10555 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10556 | struct address_space *aspace, CORE_ADDR bp_addr, |
10557 | const struct target_waitstatus *ws) | |
e09342b5 | 10558 | { |
348d480f | 10559 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10560 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10561 | |
348d480f PA |
10562 | /* Continuable hardware watchpoints are treated as non-existent if the |
10563 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10564 | some data address). Otherwise gdb won't stop on a break instruction | |
10565 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10566 | been defined. Also skip watchpoints which we know did not trigger | |
10567 | (did not match the data address). */ | |
10568 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10569 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10570 | return 0; |
9c06b0b4 | 10571 | |
348d480f | 10572 | return 1; |
9c06b0b4 TJB |
10573 | } |
10574 | ||
348d480f PA |
10575 | static void |
10576 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10577 | { |
348d480f | 10578 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10579 | |
348d480f | 10580 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10581 | } |
10582 | ||
10583 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10584 | hardware watchpoints. */ |
9c06b0b4 TJB |
10585 | |
10586 | static int | |
348d480f | 10587 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10588 | { |
3a5c3e22 PA |
10589 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10590 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10591 | |
10592 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10593 | } |
10594 | ||
10595 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10596 | hardware watchpoints. */ |
9c06b0b4 TJB |
10597 | |
10598 | static int | |
348d480f | 10599 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10600 | { |
efa80663 PA |
10601 | /* Read and access watchpoints only work with hardware support. */ |
10602 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10603 | } |
10604 | ||
9c06b0b4 | 10605 | static enum print_stop_action |
348d480f | 10606 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10607 | { |
348d480f PA |
10608 | struct cleanup *old_chain; |
10609 | struct breakpoint *b; | |
f99d8bf4 | 10610 | struct ui_file *stb; |
348d480f | 10611 | enum print_stop_action result; |
3a5c3e22 | 10612 | struct watchpoint *w; |
79a45e25 | 10613 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10614 | |
10615 | gdb_assert (bs->bp_location_at != NULL); | |
10616 | ||
348d480f | 10617 | b = bs->breakpoint_at; |
3a5c3e22 | 10618 | w = (struct watchpoint *) b; |
348d480f | 10619 | |
f99d8bf4 PA |
10620 | stb = mem_fileopen (); |
10621 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10622 | |
10623 | switch (b->type) | |
10624 | { | |
348d480f | 10625 | case bp_watchpoint: |
9c06b0b4 TJB |
10626 | case bp_hardware_watchpoint: |
10627 | annotate_watchpoint (b->number); | |
10628 | if (ui_out_is_mi_like_p (uiout)) | |
10629 | ui_out_field_string | |
10630 | (uiout, "reason", | |
10631 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10632 | mention (b); |
10633 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10634 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10635 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10636 | ui_out_field_stream (uiout, "old", stb); |
10637 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10638 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10639 | ui_out_field_stream (uiout, "new", stb); |
10640 | ui_out_text (uiout, "\n"); | |
10641 | /* More than one watchpoint may have been triggered. */ | |
10642 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10643 | break; |
10644 | ||
10645 | case bp_read_watchpoint: | |
10646 | if (ui_out_is_mi_like_p (uiout)) | |
10647 | ui_out_field_string | |
10648 | (uiout, "reason", | |
10649 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10650 | mention (b); |
10651 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10652 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10653 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10654 | ui_out_field_stream (uiout, "value", stb); |
10655 | ui_out_text (uiout, "\n"); | |
10656 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10657 | break; |
10658 | ||
10659 | case bp_access_watchpoint: | |
348d480f PA |
10660 | if (bs->old_val != NULL) |
10661 | { | |
10662 | annotate_watchpoint (b->number); | |
10663 | if (ui_out_is_mi_like_p (uiout)) | |
10664 | ui_out_field_string | |
10665 | (uiout, "reason", | |
10666 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10667 | mention (b); | |
10668 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10669 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10670 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10671 | ui_out_field_stream (uiout, "old", stb); |
10672 | ui_out_text (uiout, "\nNew value = "); | |
10673 | } | |
10674 | else | |
10675 | { | |
10676 | mention (b); | |
10677 | if (ui_out_is_mi_like_p (uiout)) | |
10678 | ui_out_field_string | |
10679 | (uiout, "reason", | |
10680 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10681 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10682 | ui_out_text (uiout, "\nValue = "); | |
10683 | } | |
f99d8bf4 | 10684 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10685 | ui_out_field_stream (uiout, "new", stb); |
10686 | ui_out_text (uiout, "\n"); | |
10687 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10688 | break; |
10689 | default: | |
348d480f | 10690 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10691 | } |
10692 | ||
348d480f PA |
10693 | do_cleanups (old_chain); |
10694 | return result; | |
10695 | } | |
10696 | ||
10697 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10698 | watchpoints. */ | |
10699 | ||
10700 | static void | |
10701 | print_mention_watchpoint (struct breakpoint *b) | |
10702 | { | |
10703 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10704 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10705 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10706 | |
10707 | switch (b->type) | |
10708 | { | |
10709 | case bp_watchpoint: | |
10710 | ui_out_text (uiout, "Watchpoint "); | |
10711 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10712 | break; | |
10713 | case bp_hardware_watchpoint: | |
10714 | ui_out_text (uiout, "Hardware watchpoint "); | |
10715 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10716 | break; | |
10717 | case bp_read_watchpoint: | |
10718 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10719 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10720 | break; | |
10721 | case bp_access_watchpoint: | |
10722 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10723 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10724 | break; | |
10725 | default: | |
10726 | internal_error (__FILE__, __LINE__, | |
10727 | _("Invalid hardware watchpoint type.")); | |
10728 | } | |
10729 | ||
10730 | ui_out_field_int (uiout, "number", b->number); | |
10731 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10732 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10733 | do_cleanups (ui_out_chain); |
10734 | } | |
10735 | ||
10736 | /* Implement the "print_recreate" breakpoint_ops method for | |
10737 | watchpoints. */ | |
10738 | ||
10739 | static void | |
10740 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10741 | { | |
3a5c3e22 PA |
10742 | struct watchpoint *w = (struct watchpoint *) b; |
10743 | ||
348d480f PA |
10744 | switch (b->type) |
10745 | { | |
10746 | case bp_watchpoint: | |
10747 | case bp_hardware_watchpoint: | |
10748 | fprintf_unfiltered (fp, "watch"); | |
10749 | break; | |
10750 | case bp_read_watchpoint: | |
10751 | fprintf_unfiltered (fp, "rwatch"); | |
10752 | break; | |
10753 | case bp_access_watchpoint: | |
10754 | fprintf_unfiltered (fp, "awatch"); | |
10755 | break; | |
10756 | default: | |
10757 | internal_error (__FILE__, __LINE__, | |
10758 | _("Invalid watchpoint type.")); | |
10759 | } | |
10760 | ||
3a5c3e22 | 10761 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10762 | print_recreate_thread (b, fp); |
348d480f PA |
10763 | } |
10764 | ||
427cd150 TT |
10765 | /* Implement the "explains_signal" breakpoint_ops method for |
10766 | watchpoints. */ | |
10767 | ||
10768 | static enum bpstat_signal_value | |
10769 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) | |
10770 | { | |
10771 | /* A software watchpoint cannot cause a signal other than | |
10772 | GDB_SIGNAL_TRAP. */ | |
10773 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
10774 | return BPSTAT_SIGNAL_NO; | |
10775 | ||
10776 | return BPSTAT_SIGNAL_HIDE; | |
10777 | } | |
10778 | ||
348d480f PA |
10779 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10780 | ||
2060206e | 10781 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10782 | |
10783 | /* Implement the "insert" breakpoint_ops method for | |
10784 | masked hardware watchpoints. */ | |
10785 | ||
10786 | static int | |
10787 | insert_masked_watchpoint (struct bp_location *bl) | |
10788 | { | |
3a5c3e22 PA |
10789 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10790 | ||
10791 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10792 | bl->watchpoint_type); |
10793 | } | |
10794 | ||
10795 | /* Implement the "remove" breakpoint_ops method for | |
10796 | masked hardware watchpoints. */ | |
10797 | ||
10798 | static int | |
10799 | remove_masked_watchpoint (struct bp_location *bl) | |
10800 | { | |
3a5c3e22 PA |
10801 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10802 | ||
10803 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10804 | bl->watchpoint_type); |
10805 | } | |
10806 | ||
10807 | /* Implement the "resources_needed" breakpoint_ops method for | |
10808 | masked hardware watchpoints. */ | |
10809 | ||
10810 | static int | |
10811 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10812 | { | |
3a5c3e22 PA |
10813 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10814 | ||
10815 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10816 | } |
10817 | ||
10818 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10819 | masked hardware watchpoints. */ | |
10820 | ||
10821 | static int | |
10822 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10823 | { | |
10824 | return 0; | |
10825 | } | |
10826 | ||
10827 | /* Implement the "print_it" breakpoint_ops method for | |
10828 | masked hardware watchpoints. */ | |
10829 | ||
10830 | static enum print_stop_action | |
10831 | print_it_masked_watchpoint (bpstat bs) | |
10832 | { | |
10833 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10834 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10835 | |
10836 | /* Masked watchpoints have only one location. */ | |
10837 | gdb_assert (b->loc && b->loc->next == NULL); | |
10838 | ||
10839 | switch (b->type) | |
10840 | { | |
10841 | case bp_hardware_watchpoint: | |
10842 | annotate_watchpoint (b->number); | |
10843 | if (ui_out_is_mi_like_p (uiout)) | |
10844 | ui_out_field_string | |
10845 | (uiout, "reason", | |
10846 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10847 | break; | |
10848 | ||
10849 | case bp_read_watchpoint: | |
10850 | if (ui_out_is_mi_like_p (uiout)) | |
10851 | ui_out_field_string | |
10852 | (uiout, "reason", | |
10853 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10854 | break; | |
10855 | ||
10856 | case bp_access_watchpoint: | |
10857 | if (ui_out_is_mi_like_p (uiout)) | |
10858 | ui_out_field_string | |
10859 | (uiout, "reason", | |
10860 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10861 | break; | |
10862 | default: | |
10863 | internal_error (__FILE__, __LINE__, | |
10864 | _("Invalid hardware watchpoint type.")); | |
10865 | } | |
10866 | ||
10867 | mention (b); | |
9c06b0b4 TJB |
10868 | ui_out_text (uiout, _("\n\ |
10869 | Check the underlying instruction at PC for the memory\n\ | |
10870 | address and value which triggered this watchpoint.\n")); | |
10871 | ui_out_text (uiout, "\n"); | |
10872 | ||
10873 | /* More than one watchpoint may have been triggered. */ | |
10874 | return PRINT_UNKNOWN; | |
10875 | } | |
10876 | ||
10877 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10878 | masked hardware watchpoints. */ | |
10879 | ||
10880 | static void | |
10881 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10882 | struct ui_out *uiout) | |
10883 | { | |
3a5c3e22 PA |
10884 | struct watchpoint *w = (struct watchpoint *) b; |
10885 | ||
9c06b0b4 TJB |
10886 | /* Masked watchpoints have only one location. */ |
10887 | gdb_assert (b->loc && b->loc->next == NULL); | |
10888 | ||
10889 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10890 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10891 | ui_out_text (uiout, "\n"); |
10892 | } | |
10893 | ||
10894 | /* Implement the "print_mention" breakpoint_ops method for | |
10895 | masked hardware watchpoints. */ | |
10896 | ||
10897 | static void | |
10898 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10899 | { | |
3a5c3e22 | 10900 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10901 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10902 | struct cleanup *ui_out_chain; |
10903 | ||
10904 | switch (b->type) | |
10905 | { | |
10906 | case bp_hardware_watchpoint: | |
10907 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10908 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10909 | break; | |
10910 | case bp_read_watchpoint: | |
10911 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10912 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10913 | break; | |
10914 | case bp_access_watchpoint: | |
10915 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10916 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10917 | break; | |
10918 | default: | |
10919 | internal_error (__FILE__, __LINE__, | |
10920 | _("Invalid hardware watchpoint type.")); | |
10921 | } | |
10922 | ||
10923 | ui_out_field_int (uiout, "number", b->number); | |
10924 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10925 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10926 | do_cleanups (ui_out_chain); |
10927 | } | |
10928 | ||
10929 | /* Implement the "print_recreate" breakpoint_ops method for | |
10930 | masked hardware watchpoints. */ | |
10931 | ||
10932 | static void | |
10933 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10934 | { | |
3a5c3e22 | 10935 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10936 | char tmp[40]; |
10937 | ||
10938 | switch (b->type) | |
10939 | { | |
10940 | case bp_hardware_watchpoint: | |
10941 | fprintf_unfiltered (fp, "watch"); | |
10942 | break; | |
10943 | case bp_read_watchpoint: | |
10944 | fprintf_unfiltered (fp, "rwatch"); | |
10945 | break; | |
10946 | case bp_access_watchpoint: | |
10947 | fprintf_unfiltered (fp, "awatch"); | |
10948 | break; | |
10949 | default: | |
10950 | internal_error (__FILE__, __LINE__, | |
10951 | _("Invalid hardware watchpoint type.")); | |
10952 | } | |
10953 | ||
3a5c3e22 PA |
10954 | sprintf_vma (tmp, w->hw_wp_mask); |
10955 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10956 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10957 | } |
10958 | ||
10959 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10960 | ||
2060206e | 10961 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10962 | |
10963 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10964 | ||
10965 | static int | |
10966 | is_masked_watchpoint (const struct breakpoint *b) | |
10967 | { | |
10968 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10969 | } | |
10970 | ||
53a5351d JM |
10971 | /* accessflag: hw_write: watch write, |
10972 | hw_read: watch read, | |
10973 | hw_access: watch access (read or write) */ | |
c906108c | 10974 | static void |
bbc13ae3 | 10975 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10976 | int just_location, int internal) |
c906108c | 10977 | { |
a9634178 | 10978 | volatile struct gdb_exception e; |
d983da9c | 10979 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10980 | struct expression *exp; |
270140bd | 10981 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10982 | struct value *val, *mark, *result; |
c906108c | 10983 | struct frame_info *frame; |
bbc13ae3 KS |
10984 | const char *exp_start = NULL; |
10985 | const char *exp_end = NULL; | |
10986 | const char *tok, *end_tok; | |
9c06b0b4 | 10987 | int toklen = -1; |
bbc13ae3 KS |
10988 | const char *cond_start = NULL; |
10989 | const char *cond_end = NULL; | |
c906108c | 10990 | enum bptype bp_type; |
37e4754d | 10991 | int thread = -1; |
0cf6dd15 | 10992 | int pc = 0; |
9c06b0b4 TJB |
10993 | /* Flag to indicate whether we are going to use masks for |
10994 | the hardware watchpoint. */ | |
10995 | int use_mask = 0; | |
10996 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10997 | struct watchpoint *w; |
bbc13ae3 KS |
10998 | char *expression; |
10999 | struct cleanup *back_to; | |
c906108c | 11000 | |
37e4754d LM |
11001 | /* Make sure that we actually have parameters to parse. */ |
11002 | if (arg != NULL && arg[0] != '\0') | |
11003 | { | |
bbc13ae3 KS |
11004 | const char *value_start; |
11005 | ||
11006 | exp_end = arg + strlen (arg); | |
37e4754d | 11007 | |
9c06b0b4 TJB |
11008 | /* Look for "parameter value" pairs at the end |
11009 | of the arguments string. */ | |
bbc13ae3 | 11010 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11011 | { |
11012 | /* Skip whitespace at the end of the argument list. */ | |
11013 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11014 | tok--; | |
11015 | ||
11016 | /* Find the beginning of the last token. | |
11017 | This is the value of the parameter. */ | |
11018 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11019 | tok--; | |
11020 | value_start = tok + 1; | |
11021 | ||
11022 | /* Skip whitespace. */ | |
11023 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11024 | tok--; | |
11025 | ||
11026 | end_tok = tok; | |
11027 | ||
11028 | /* Find the beginning of the second to last token. | |
11029 | This is the parameter itself. */ | |
11030 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11031 | tok--; | |
11032 | tok++; | |
11033 | toklen = end_tok - tok + 1; | |
11034 | ||
11035 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11036 | { | |
11037 | /* At this point we've found a "thread" token, which means | |
11038 | the user is trying to set a watchpoint that triggers | |
11039 | only in a specific thread. */ | |
11040 | char *endp; | |
37e4754d | 11041 | |
9c06b0b4 TJB |
11042 | if (thread != -1) |
11043 | error(_("You can specify only one thread.")); | |
37e4754d | 11044 | |
9c06b0b4 TJB |
11045 | /* Extract the thread ID from the next token. */ |
11046 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11047 | |
9c06b0b4 TJB |
11048 | /* Check if the user provided a valid numeric value for the |
11049 | thread ID. */ | |
11050 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11051 | error (_("Invalid thread ID specification %s."), value_start); | |
11052 | ||
11053 | /* Check if the thread actually exists. */ | |
11054 | if (!valid_thread_id (thread)) | |
af4908ba | 11055 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11056 | } |
11057 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11058 | { | |
11059 | /* We've found a "mask" token, which means the user wants to | |
11060 | create a hardware watchpoint that is going to have the mask | |
11061 | facility. */ | |
11062 | struct value *mask_value, *mark; | |
37e4754d | 11063 | |
9c06b0b4 TJB |
11064 | if (use_mask) |
11065 | error(_("You can specify only one mask.")); | |
37e4754d | 11066 | |
9c06b0b4 | 11067 | use_mask = just_location = 1; |
37e4754d | 11068 | |
9c06b0b4 TJB |
11069 | mark = value_mark (); |
11070 | mask_value = parse_to_comma_and_eval (&value_start); | |
11071 | mask = value_as_address (mask_value); | |
11072 | value_free_to_mark (mark); | |
11073 | } | |
11074 | else | |
11075 | /* We didn't recognize what we found. We should stop here. */ | |
11076 | break; | |
37e4754d | 11077 | |
9c06b0b4 TJB |
11078 | /* Truncate the string and get rid of the "parameter value" pair before |
11079 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11080 | exp_end = tok; |
9c06b0b4 | 11081 | } |
37e4754d | 11082 | } |
bbc13ae3 KS |
11083 | else |
11084 | exp_end = arg; | |
37e4754d | 11085 | |
bbc13ae3 KS |
11086 | /* Parse the rest of the arguments. From here on out, everything |
11087 | is in terms of a newly allocated string instead of the original | |
11088 | ARG. */ | |
c906108c | 11089 | innermost_block = NULL; |
bbc13ae3 KS |
11090 | expression = savestring (arg, exp_end - arg); |
11091 | back_to = make_cleanup (xfree, expression); | |
11092 | exp_start = arg = expression; | |
1bb9788d | 11093 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11094 | exp_end = arg; |
fa8a61dc TT |
11095 | /* Remove trailing whitespace from the expression before saving it. |
11096 | This makes the eventual display of the expression string a bit | |
11097 | prettier. */ | |
11098 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11099 | --exp_end; | |
11100 | ||
65d79d4b SDJ |
11101 | /* Checking if the expression is not constant. */ |
11102 | if (watchpoint_exp_is_const (exp)) | |
11103 | { | |
11104 | int len; | |
11105 | ||
11106 | len = exp_end - exp_start; | |
11107 | while (len > 0 && isspace (exp_start[len - 1])) | |
11108 | len--; | |
11109 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11110 | } | |
11111 | ||
c906108c SS |
11112 | exp_valid_block = innermost_block; |
11113 | mark = value_mark (); | |
3a1115a0 | 11114 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11115 | |
11116 | if (just_location) | |
11117 | { | |
9c06b0b4 TJB |
11118 | int ret; |
11119 | ||
06a64a0b | 11120 | exp_valid_block = NULL; |
a1442452 | 11121 | val = value_addr (result); |
06a64a0b TT |
11122 | release_value (val); |
11123 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11124 | |
11125 | if (use_mask) | |
11126 | { | |
11127 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11128 | mask); | |
11129 | if (ret == -1) | |
11130 | error (_("This target does not support masked watchpoints.")); | |
11131 | else if (ret == -2) | |
11132 | error (_("Invalid mask or memory region.")); | |
11133 | } | |
06a64a0b TT |
11134 | } |
11135 | else if (val != NULL) | |
fa4727a6 | 11136 | release_value (val); |
c906108c | 11137 | |
bbc13ae3 KS |
11138 | tok = skip_spaces_const (arg); |
11139 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11140 | |
11141 | toklen = end_tok - tok; | |
11142 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11143 | { | |
2d134ed3 PA |
11144 | struct expression *cond; |
11145 | ||
60e1c644 | 11146 | innermost_block = NULL; |
c906108c | 11147 | tok = cond_start = end_tok + 1; |
1bb9788d | 11148 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11149 | |
11150 | /* The watchpoint expression may not be local, but the condition | |
11151 | may still be. E.g.: `watch global if local > 0'. */ | |
11152 | cond_exp_valid_block = innermost_block; | |
11153 | ||
2d134ed3 | 11154 | xfree (cond); |
c906108c SS |
11155 | cond_end = tok; |
11156 | } | |
11157 | if (*tok) | |
8a3fe4f8 | 11158 | error (_("Junk at end of command.")); |
c906108c | 11159 | |
d983da9c | 11160 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11161 | |
11162 | /* If the expression is "local", then set up a "watchpoint scope" | |
11163 | breakpoint at the point where we've left the scope of the watchpoint | |
11164 | expression. Create the scope breakpoint before the watchpoint, so | |
11165 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11166 | if (exp_valid_block && frame) |
d983da9c | 11167 | { |
edb3359d DJ |
11168 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11169 | { | |
11170 | scope_breakpoint | |
a6d9a66e UW |
11171 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11172 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11173 | bp_watchpoint_scope, |
11174 | &momentary_breakpoint_ops); | |
d983da9c | 11175 | |
edb3359d | 11176 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11177 | |
edb3359d DJ |
11178 | /* Automatically delete the breakpoint when it hits. */ |
11179 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11180 | |
edb3359d DJ |
11181 | /* Only break in the proper frame (help with recursion). */ |
11182 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11183 | |
edb3359d | 11184 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11185 | scope_breakpoint->loc->gdbarch |
11186 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11187 | scope_breakpoint->loc->requested_address |
11188 | = frame_unwind_caller_pc (frame); | |
11189 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11190 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11191 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11192 | scope_breakpoint->type); |
11193 | } | |
d983da9c DJ |
11194 | } |
11195 | ||
e8369a73 AB |
11196 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11197 | watchpoints here even if hardware watchpoints are turned off, a call | |
11198 | to update_watchpoint later in this function will cause the type to | |
11199 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11200 | ||
11201 | if (accessflag == hw_read) | |
11202 | bp_type = bp_read_watchpoint; | |
11203 | else if (accessflag == hw_access) | |
11204 | bp_type = bp_access_watchpoint; | |
11205 | else | |
11206 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11207 | |
11208 | w = XCNEW (struct watchpoint); | |
11209 | b = &w->base; | |
348d480f | 11210 | if (use_mask) |
3a5c3e22 PA |
11211 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11212 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11213 | else |
3a5c3e22 PA |
11214 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11215 | &watchpoint_breakpoint_ops); | |
37e4754d | 11216 | b->thread = thread; |
b5de0fa7 | 11217 | b->disposition = disp_donttouch; |
348d480f | 11218 | b->pspace = current_program_space; |
3a5c3e22 PA |
11219 | w->exp = exp; |
11220 | w->exp_valid_block = exp_valid_block; | |
11221 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11222 | if (just_location) |
11223 | { | |
11224 | struct type *t = value_type (val); | |
11225 | CORE_ADDR addr = value_as_address (val); | |
11226 | char *name; | |
11227 | ||
11228 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11229 | name = type_to_string (t); | |
11230 | ||
3a5c3e22 | 11231 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11232 | core_addr_to_string (addr)); |
06a64a0b TT |
11233 | xfree (name); |
11234 | ||
3a5c3e22 | 11235 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11236 | (int) (exp_end - exp_start), exp_start); |
11237 | ||
06a64a0b TT |
11238 | /* The above expression is in C. */ |
11239 | b->language = language_c; | |
11240 | } | |
11241 | else | |
3a5c3e22 | 11242 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11243 | |
11244 | if (use_mask) | |
11245 | { | |
3a5c3e22 | 11246 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11247 | } |
11248 | else | |
11249 | { | |
3a5c3e22 PA |
11250 | w->val = val; |
11251 | w->val_valid = 1; | |
9c06b0b4 | 11252 | } |
77b06cd7 | 11253 | |
c906108c SS |
11254 | if (cond_start) |
11255 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11256 | else | |
11257 | b->cond_string = 0; | |
c5aa993b | 11258 | |
c906108c | 11259 | if (frame) |
f6bc2008 | 11260 | { |
3a5c3e22 PA |
11261 | w->watchpoint_frame = get_frame_id (frame); |
11262 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11263 | } |
c906108c | 11264 | else |
f6bc2008 | 11265 | { |
3a5c3e22 PA |
11266 | w->watchpoint_frame = null_frame_id; |
11267 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11268 | } |
c906108c | 11269 | |
d983da9c | 11270 | if (scope_breakpoint != NULL) |
c906108c | 11271 | { |
d983da9c DJ |
11272 | /* The scope breakpoint is related to the watchpoint. We will |
11273 | need to act on them together. */ | |
11274 | b->related_breakpoint = scope_breakpoint; | |
11275 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11276 | } |
d983da9c | 11277 | |
06a64a0b TT |
11278 | if (!just_location) |
11279 | value_free_to_mark (mark); | |
2d134ed3 | 11280 | |
a9634178 TJB |
11281 | TRY_CATCH (e, RETURN_MASK_ALL) |
11282 | { | |
11283 | /* Finally update the new watchpoint. This creates the locations | |
11284 | that should be inserted. */ | |
3a5c3e22 | 11285 | update_watchpoint (w, 1); |
a9634178 TJB |
11286 | } |
11287 | if (e.reason < 0) | |
11288 | { | |
11289 | delete_breakpoint (b); | |
11290 | throw_exception (e); | |
11291 | } | |
11292 | ||
3ea46bff | 11293 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11294 | do_cleanups (back_to); |
c906108c SS |
11295 | } |
11296 | ||
e09342b5 | 11297 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11298 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11299 | |
c906108c | 11300 | static int |
a9634178 | 11301 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11302 | { |
11303 | int found_memory_cnt = 0; | |
2e70b7b9 | 11304 | struct value *head = v; |
c906108c SS |
11305 | |
11306 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11307 | if (!can_use_hw_watchpoints) |
c906108c | 11308 | return 0; |
c5aa993b | 11309 | |
5c44784c JM |
11310 | /* Make sure that the value of the expression depends only upon |
11311 | memory contents, and values computed from them within GDB. If we | |
11312 | find any register references or function calls, we can't use a | |
11313 | hardware watchpoint. | |
11314 | ||
11315 | The idea here is that evaluating an expression generates a series | |
11316 | of values, one holding the value of every subexpression. (The | |
11317 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11318 | a*b+c.) GDB's values hold almost enough information to establish | |
11319 | the criteria given above --- they identify memory lvalues, | |
11320 | register lvalues, computed values, etcetera. So we can evaluate | |
11321 | the expression, and then scan the chain of values that leaves | |
11322 | behind to decide whether we can detect any possible change to the | |
11323 | expression's final value using only hardware watchpoints. | |
11324 | ||
11325 | However, I don't think that the values returned by inferior | |
11326 | function calls are special in any way. So this function may not | |
11327 | notice that an expression involving an inferior function call | |
11328 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11329 | for (; v; v = value_next (v)) |
c906108c | 11330 | { |
5c44784c | 11331 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11332 | { |
8464be76 DJ |
11333 | if (v != head && value_lazy (v)) |
11334 | /* A lazy memory lvalue in the chain is one that GDB never | |
11335 | needed to fetch; we either just used its address (e.g., | |
11336 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11337 | in `a,b'). This doesn't apply to HEAD; if that is | |
11338 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11339 | ; |
53a5351d | 11340 | else |
5c44784c JM |
11341 | { |
11342 | /* Ahh, memory we actually used! Check if we can cover | |
11343 | it with hardware watchpoints. */ | |
df407dfe | 11344 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11345 | |
11346 | /* We only watch structs and arrays if user asked for it | |
11347 | explicitly, never if they just happen to appear in a | |
11348 | middle of some value chain. */ | |
11349 | if (v == head | |
11350 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11351 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11352 | { | |
42ae5230 | 11353 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11354 | int len; |
11355 | int num_regs; | |
11356 | ||
a9634178 | 11357 | len = (target_exact_watchpoints |
e09342b5 TJB |
11358 | && is_scalar_type_recursive (vtype))? |
11359 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11360 | |
e09342b5 TJB |
11361 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11362 | if (!num_regs) | |
2e70b7b9 MS |
11363 | return 0; |
11364 | else | |
e09342b5 | 11365 | found_memory_cnt += num_regs; |
2e70b7b9 | 11366 | } |
5c44784c | 11367 | } |
c5aa993b | 11368 | } |
5086187c AC |
11369 | else if (VALUE_LVAL (v) != not_lval |
11370 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11371 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11372 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11373 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11374 | } |
11375 | ||
11376 | /* The expression itself looks suitable for using a hardware | |
11377 | watchpoint, but give the target machine a chance to reject it. */ | |
11378 | return found_memory_cnt; | |
11379 | } | |
11380 | ||
8b93c638 | 11381 | void |
84f4c1fe | 11382 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11383 | { |
84f4c1fe | 11384 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11385 | } |
11386 | ||
06a64a0b TT |
11387 | /* A helper function that looks for the "-location" argument and then |
11388 | calls watch_command_1. */ | |
11389 | ||
11390 | static void | |
11391 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11392 | { | |
11393 | int just_location = 0; | |
11394 | ||
11395 | if (arg | |
11396 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11397 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11398 | { | |
e9cafbcc | 11399 | arg = skip_spaces (arg); |
06a64a0b TT |
11400 | just_location = 1; |
11401 | } | |
11402 | ||
84f4c1fe | 11403 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11404 | } |
8926118c | 11405 | |
c5aa993b | 11406 | static void |
fba45db2 | 11407 | watch_command (char *arg, int from_tty) |
c906108c | 11408 | { |
06a64a0b | 11409 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11410 | } |
11411 | ||
8b93c638 | 11412 | void |
84f4c1fe | 11413 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11414 | { |
84f4c1fe | 11415 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11416 | } |
8926118c | 11417 | |
c5aa993b | 11418 | static void |
fba45db2 | 11419 | rwatch_command (char *arg, int from_tty) |
c906108c | 11420 | { |
06a64a0b | 11421 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11422 | } |
11423 | ||
8b93c638 | 11424 | void |
84f4c1fe | 11425 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11426 | { |
84f4c1fe | 11427 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11428 | } |
8926118c | 11429 | |
c5aa993b | 11430 | static void |
fba45db2 | 11431 | awatch_command (char *arg, int from_tty) |
c906108c | 11432 | { |
06a64a0b | 11433 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11434 | } |
c906108c | 11435 | \f |
c5aa993b | 11436 | |
43ff13b4 | 11437 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11438 | because it uses the mechanisms of breakpoints. */ |
11439 | ||
bfec99b2 PA |
11440 | struct until_break_command_continuation_args |
11441 | { | |
11442 | struct breakpoint *breakpoint; | |
11443 | struct breakpoint *breakpoint2; | |
186c406b | 11444 | int thread_num; |
bfec99b2 PA |
11445 | }; |
11446 | ||
43ff13b4 | 11447 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11448 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11449 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11450 | command. */ |
c2c6d25f | 11451 | static void |
fa4cd53f | 11452 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11453 | { |
bfec99b2 PA |
11454 | struct until_break_command_continuation_args *a = arg; |
11455 | ||
11456 | delete_breakpoint (a->breakpoint); | |
11457 | if (a->breakpoint2) | |
11458 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11459 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11460 | } |
11461 | ||
c906108c | 11462 | void |
ae66c1fc | 11463 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11464 | { |
11465 | struct symtabs_and_lines sals; | |
11466 | struct symtab_and_line sal; | |
8556afb4 PA |
11467 | struct frame_info *frame; |
11468 | struct gdbarch *frame_gdbarch; | |
11469 | struct frame_id stack_frame_id; | |
11470 | struct frame_id caller_frame_id; | |
c906108c | 11471 | struct breakpoint *breakpoint; |
f107f563 | 11472 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11473 | struct cleanup *old_chain; |
186c406b TT |
11474 | int thread; |
11475 | struct thread_info *tp; | |
c906108c SS |
11476 | |
11477 | clear_proceed_status (); | |
11478 | ||
11479 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11480 | this function. */ |
c5aa993b | 11481 | |
1bfeeb0f | 11482 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11483 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11484 | get_last_displayed_symtab (), |
f8eba3c6 | 11485 | get_last_displayed_line ()); |
c906108c | 11486 | else |
f8eba3c6 TT |
11487 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11488 | (struct symtab *) NULL, 0); | |
c5aa993b | 11489 | |
c906108c | 11490 | if (sals.nelts != 1) |
8a3fe4f8 | 11491 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11492 | |
c906108c | 11493 | sal = sals.sals[0]; |
4a64f543 | 11494 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11495 | |
c906108c | 11496 | if (*arg) |
8a3fe4f8 | 11497 | error (_("Junk at end of arguments.")); |
c5aa993b | 11498 | |
c906108c | 11499 | resolve_sal_pc (&sal); |
c5aa993b | 11500 | |
186c406b TT |
11501 | tp = inferior_thread (); |
11502 | thread = tp->num; | |
11503 | ||
883bc8d1 PA |
11504 | old_chain = make_cleanup (null_cleanup, NULL); |
11505 | ||
8556afb4 PA |
11506 | /* Note linespec handling above invalidates the frame chain. |
11507 | Installing a breakpoint also invalidates the frame chain (as it | |
11508 | may need to switch threads), so do any frame handling before | |
11509 | that. */ | |
11510 | ||
11511 | frame = get_selected_frame (NULL); | |
11512 | frame_gdbarch = get_frame_arch (frame); | |
11513 | stack_frame_id = get_stack_frame_id (frame); | |
11514 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11515 | |
ae66c1fc EZ |
11516 | /* Keep within the current frame, or in frames called by the current |
11517 | one. */ | |
edb3359d | 11518 | |
883bc8d1 | 11519 | if (frame_id_p (caller_frame_id)) |
c906108c | 11520 | { |
883bc8d1 PA |
11521 | struct symtab_and_line sal2; |
11522 | ||
11523 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11524 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11525 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11526 | sal2, |
11527 | caller_frame_id, | |
f107f563 VP |
11528 | bp_until); |
11529 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11530 | |
883bc8d1 | 11531 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11532 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11533 | } |
c5aa993b | 11534 | |
c70a6932 JK |
11535 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11536 | frame = NULL; | |
11537 | ||
883bc8d1 PA |
11538 | if (anywhere) |
11539 | /* If the user told us to continue until a specified location, | |
11540 | we don't specify a frame at which we need to stop. */ | |
11541 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11542 | null_frame_id, bp_until); | |
11543 | else | |
11544 | /* Otherwise, specify the selected frame, because we want to stop | |
11545 | only at the very same frame. */ | |
11546 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11547 | stack_frame_id, bp_until); | |
11548 | make_cleanup_delete_breakpoint (breakpoint); | |
11549 | ||
a493e3e2 | 11550 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11551 | |
4a64f543 MS |
11552 | /* If we are running asynchronously, and proceed call above has |
11553 | actually managed to start the target, arrange for breakpoints to | |
11554 | be deleted when the target stops. Otherwise, we're already | |
11555 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11556 | |
8ea051c5 | 11557 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11558 | { |
bfec99b2 PA |
11559 | struct until_break_command_continuation_args *args; |
11560 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11561 | |
bfec99b2 PA |
11562 | args->breakpoint = breakpoint; |
11563 | args->breakpoint2 = breakpoint2; | |
186c406b | 11564 | args->thread_num = thread; |
f107f563 VP |
11565 | |
11566 | discard_cleanups (old_chain); | |
95e54da7 PA |
11567 | add_continuation (inferior_thread (), |
11568 | until_break_command_continuation, args, | |
604ead4a | 11569 | xfree); |
f107f563 VP |
11570 | } |
11571 | else | |
c5aa993b | 11572 | do_cleanups (old_chain); |
c906108c | 11573 | } |
ae66c1fc | 11574 | |
c906108c SS |
11575 | /* This function attempts to parse an optional "if <cond>" clause |
11576 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11577 | |
c906108c SS |
11578 | Else, it returns a pointer to the condition string. (It does not |
11579 | attempt to evaluate the string against a particular block.) And, | |
11580 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11581 | if clause in the arg string. */ |
53a5351d | 11582 | |
916703c0 | 11583 | char * |
fba45db2 | 11584 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11585 | { |
c5aa993b JM |
11586 | char *cond_string; |
11587 | ||
11588 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11589 | return NULL; |
c5aa993b | 11590 | |
4a64f543 | 11591 | /* Skip the "if" keyword. */ |
c906108c | 11592 | (*arg) += 2; |
c5aa993b | 11593 | |
c906108c | 11594 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11595 | condition string. */ |
e9cafbcc | 11596 | *arg = skip_spaces (*arg); |
c906108c | 11597 | cond_string = *arg; |
c5aa993b | 11598 | |
4a64f543 MS |
11599 | /* Assume that the condition occupies the remainder of the arg |
11600 | string. */ | |
c906108c | 11601 | (*arg) += strlen (cond_string); |
c5aa993b | 11602 | |
c906108c SS |
11603 | return cond_string; |
11604 | } | |
c5aa993b | 11605 | |
c906108c SS |
11606 | /* Commands to deal with catching events, such as signals, exceptions, |
11607 | process start/exit, etc. */ | |
c5aa993b JM |
11608 | |
11609 | typedef enum | |
11610 | { | |
44feb3ce TT |
11611 | catch_fork_temporary, catch_vfork_temporary, |
11612 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11613 | } |
11614 | catch_fork_kind; | |
11615 | ||
c906108c | 11616 | static void |
cc59ec59 MS |
11617 | catch_fork_command_1 (char *arg, int from_tty, |
11618 | struct cmd_list_element *command) | |
c906108c | 11619 | { |
a6d9a66e | 11620 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11621 | char *cond_string = NULL; |
44feb3ce TT |
11622 | catch_fork_kind fork_kind; |
11623 | int tempflag; | |
11624 | ||
11625 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11626 | tempflag = (fork_kind == catch_fork_temporary | |
11627 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11628 | |
44feb3ce TT |
11629 | if (!arg) |
11630 | arg = ""; | |
e9cafbcc | 11631 | arg = skip_spaces (arg); |
c5aa993b | 11632 | |
c906108c | 11633 | /* The allowed syntax is: |
c5aa993b JM |
11634 | catch [v]fork |
11635 | catch [v]fork if <cond> | |
11636 | ||
4a64f543 | 11637 | First, check if there's an if clause. */ |
c906108c | 11638 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11639 | |
c906108c | 11640 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11641 | error (_("Junk at end of arguments.")); |
c5aa993b | 11642 | |
c906108c | 11643 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11644 | and enable reporting of such events. */ |
c5aa993b JM |
11645 | switch (fork_kind) |
11646 | { | |
44feb3ce TT |
11647 | case catch_fork_temporary: |
11648 | case catch_fork_permanent: | |
a6d9a66e | 11649 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11650 | &catch_fork_breakpoint_ops); |
c906108c | 11651 | break; |
44feb3ce TT |
11652 | case catch_vfork_temporary: |
11653 | case catch_vfork_permanent: | |
a6d9a66e | 11654 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11655 | &catch_vfork_breakpoint_ops); |
c906108c | 11656 | break; |
c5aa993b | 11657 | default: |
8a3fe4f8 | 11658 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11659 | break; |
c5aa993b | 11660 | } |
c906108c SS |
11661 | } |
11662 | ||
11663 | static void | |
cc59ec59 MS |
11664 | catch_exec_command_1 (char *arg, int from_tty, |
11665 | struct cmd_list_element *command) | |
c906108c | 11666 | { |
b4d90040 | 11667 | struct exec_catchpoint *c; |
a6d9a66e | 11668 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11669 | int tempflag; |
c5aa993b | 11670 | char *cond_string = NULL; |
c906108c | 11671 | |
44feb3ce TT |
11672 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11673 | ||
11674 | if (!arg) | |
11675 | arg = ""; | |
e9cafbcc | 11676 | arg = skip_spaces (arg); |
c906108c SS |
11677 | |
11678 | /* The allowed syntax is: | |
c5aa993b JM |
11679 | catch exec |
11680 | catch exec if <cond> | |
c906108c | 11681 | |
4a64f543 | 11682 | First, check if there's an if clause. */ |
c906108c SS |
11683 | cond_string = ep_parse_optional_if_clause (&arg); |
11684 | ||
11685 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11686 | error (_("Junk at end of arguments.")); |
c906108c | 11687 | |
b4d90040 PA |
11688 | c = XNEW (struct exec_catchpoint); |
11689 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11690 | &catch_exec_breakpoint_ops); | |
11691 | c->exec_pathname = NULL; | |
11692 | ||
3ea46bff | 11693 | install_breakpoint (0, &c->base, 1); |
c906108c | 11694 | } |
c5aa993b | 11695 | |
9ac4176b | 11696 | void |
28010a5d PA |
11697 | init_ada_exception_breakpoint (struct breakpoint *b, |
11698 | struct gdbarch *gdbarch, | |
11699 | struct symtab_and_line sal, | |
11700 | char *addr_string, | |
c0a91b2b | 11701 | const struct breakpoint_ops *ops, |
28010a5d | 11702 | int tempflag, |
349774ef | 11703 | int enabled, |
28010a5d | 11704 | int from_tty) |
f7f9143b | 11705 | { |
f7f9143b JB |
11706 | if (from_tty) |
11707 | { | |
5af949e3 UW |
11708 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11709 | if (!loc_gdbarch) | |
11710 | loc_gdbarch = gdbarch; | |
11711 | ||
6c95b8df PA |
11712 | describe_other_breakpoints (loc_gdbarch, |
11713 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11714 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11715 | version for exception catchpoints, because two catchpoints | |
11716 | used for different exception names will use the same address. | |
11717 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11718 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11719 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11720 | the user what type of catchpoint it is. The above is good |
11721 | enough for now, though. */ | |
11722 | } | |
11723 | ||
28010a5d | 11724 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11725 | |
349774ef | 11726 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11727 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11728 | b->addr_string = addr_string; |
11729 | b->language = language_ada; | |
f7f9143b JB |
11730 | } |
11731 | ||
a96d9b2e SDJ |
11732 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11733 | filter list, or NULL if no filtering is required. */ | |
11734 | static VEC(int) * | |
11735 | catch_syscall_split_args (char *arg) | |
11736 | { | |
11737 | VEC(int) *result = NULL; | |
29d0bb3d | 11738 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11739 | |
11740 | while (*arg != '\0') | |
11741 | { | |
11742 | int i, syscall_number; | |
11743 | char *endptr; | |
11744 | char cur_name[128]; | |
11745 | struct syscall s; | |
11746 | ||
11747 | /* Skip whitespace. */ | |
529480d0 | 11748 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11749 | |
11750 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11751 | cur_name[i] = arg[i]; | |
11752 | cur_name[i] = '\0'; | |
11753 | arg += i; | |
11754 | ||
11755 | /* Check if the user provided a syscall name or a number. */ | |
11756 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11757 | if (*endptr == '\0') | |
bccd0dd2 | 11758 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11759 | else |
11760 | { | |
11761 | /* We have a name. Let's check if it's valid and convert it | |
11762 | to a number. */ | |
11763 | get_syscall_by_name (cur_name, &s); | |
11764 | ||
11765 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11766 | /* Here we have to issue an error instead of a warning, |
11767 | because GDB cannot do anything useful if there's no | |
11768 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11769 | error (_("Unknown syscall name '%s'."), cur_name); |
11770 | } | |
11771 | ||
11772 | /* Ok, it's valid. */ | |
11773 | VEC_safe_push (int, result, s.number); | |
11774 | } | |
11775 | ||
11776 | discard_cleanups (cleanup); | |
11777 | return result; | |
11778 | } | |
11779 | ||
11780 | /* Implement the "catch syscall" command. */ | |
11781 | ||
11782 | static void | |
cc59ec59 MS |
11783 | catch_syscall_command_1 (char *arg, int from_tty, |
11784 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11785 | { |
11786 | int tempflag; | |
11787 | VEC(int) *filter; | |
11788 | struct syscall s; | |
11789 | struct gdbarch *gdbarch = get_current_arch (); | |
11790 | ||
11791 | /* Checking if the feature if supported. */ | |
11792 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11793 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11794 | this architecture yet.")); |
a96d9b2e SDJ |
11795 | |
11796 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11797 | ||
e9cafbcc | 11798 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11799 | |
11800 | /* We need to do this first "dummy" translation in order | |
11801 | to get the syscall XML file loaded or, most important, | |
11802 | to display a warning to the user if there's no XML file | |
11803 | for his/her architecture. */ | |
11804 | get_syscall_by_number (0, &s); | |
11805 | ||
11806 | /* The allowed syntax is: | |
11807 | catch syscall | |
11808 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11809 | ||
11810 | Let's check if there's a syscall name. */ | |
11811 | ||
11812 | if (arg != NULL) | |
11813 | filter = catch_syscall_split_args (arg); | |
11814 | else | |
11815 | filter = NULL; | |
11816 | ||
11817 | create_syscall_event_catchpoint (tempflag, filter, | |
11818 | &catch_syscall_breakpoint_ops); | |
11819 | } | |
11820 | ||
c906108c | 11821 | static void |
fba45db2 | 11822 | catch_command (char *arg, int from_tty) |
c906108c | 11823 | { |
44feb3ce | 11824 | error (_("Catch requires an event name.")); |
c906108c SS |
11825 | } |
11826 | \f | |
11827 | ||
11828 | static void | |
fba45db2 | 11829 | tcatch_command (char *arg, int from_tty) |
c906108c | 11830 | { |
44feb3ce | 11831 | error (_("Catch requires an event name.")); |
c906108c SS |
11832 | } |
11833 | ||
8a2c437b TT |
11834 | /* A qsort comparison function that sorts breakpoints in order. */ |
11835 | ||
11836 | static int | |
11837 | compare_breakpoints (const void *a, const void *b) | |
11838 | { | |
11839 | const breakpoint_p *ba = a; | |
11840 | uintptr_t ua = (uintptr_t) *ba; | |
11841 | const breakpoint_p *bb = b; | |
11842 | uintptr_t ub = (uintptr_t) *bb; | |
11843 | ||
11844 | if ((*ba)->number < (*bb)->number) | |
11845 | return -1; | |
11846 | else if ((*ba)->number > (*bb)->number) | |
11847 | return 1; | |
11848 | ||
11849 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11850 | the number 0. */ | |
11851 | if (ua < ub) | |
11852 | return -1; | |
94b0e70d | 11853 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11854 | } |
11855 | ||
80f8a6eb | 11856 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11857 | |
11858 | static void | |
fba45db2 | 11859 | clear_command (char *arg, int from_tty) |
c906108c | 11860 | { |
8a2c437b | 11861 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11862 | VEC(breakpoint_p) *found = 0; |
11863 | int ix; | |
c906108c SS |
11864 | int default_match; |
11865 | struct symtabs_and_lines sals; | |
11866 | struct symtab_and_line sal; | |
c906108c | 11867 | int i; |
8a2c437b | 11868 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11869 | |
11870 | if (arg) | |
11871 | { | |
39cf75f7 DE |
11872 | sals = decode_line_with_current_source (arg, |
11873 | (DECODE_LINE_FUNFIRSTLINE | |
11874 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11875 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11876 | default_match = 0; |
11877 | } | |
11878 | else | |
11879 | { | |
c5aa993b | 11880 | sals.sals = (struct symtab_and_line *) |
c906108c | 11881 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11882 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11883 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11884 | |
11885 | /* Set sal's line, symtab, pc, and pspace to the values | |
11886 | corresponding to the last call to print_frame_info. If the | |
11887 | codepoint is not valid, this will set all the fields to 0. */ | |
11888 | get_last_displayed_sal (&sal); | |
c906108c | 11889 | if (sal.symtab == 0) |
8a3fe4f8 | 11890 | error (_("No source file specified.")); |
c906108c SS |
11891 | |
11892 | sals.sals[0] = sal; | |
11893 | sals.nelts = 1; | |
11894 | ||
11895 | default_match = 1; | |
11896 | } | |
11897 | ||
4a64f543 MS |
11898 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11899 | seems, because all existing breakpoints typically have both | |
11900 | file/line and pc set. So, if clear is given file/line, we can | |
11901 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11902 | |
11903 | We only support clearing given the address explicitly | |
11904 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11905 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11906 | due to optimization, all in one block. |
4a64f543 MS |
11907 | |
11908 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11909 | PC corresponding to the same file:line, the breakpoint won't |
11910 | be cleared. We probably can still clear the breakpoint, but | |
11911 | since the other PC value is never presented to user, user | |
11912 | can only find it by guessing, and it does not seem important | |
11913 | to support that. */ | |
11914 | ||
4a64f543 MS |
11915 | /* For each line spec given, delete bps which correspond to it. Do |
11916 | it in two passes, solely to preserve the current behavior that | |
11917 | from_tty is forced true if we delete more than one | |
11918 | breakpoint. */ | |
c906108c | 11919 | |
80f8a6eb | 11920 | found = NULL; |
8a2c437b | 11921 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11922 | for (i = 0; i < sals.nelts; i++) |
11923 | { | |
05cba821 JK |
11924 | const char *sal_fullname; |
11925 | ||
c906108c | 11926 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11927 | If line given (pc == 0), clear all bpts on specified line. |
11928 | If defaulting, clear all bpts on default line | |
c906108c | 11929 | or at default pc. |
c5aa993b JM |
11930 | |
11931 | defaulting sal.pc != 0 tests to do | |
11932 | ||
11933 | 0 1 pc | |
11934 | 1 1 pc _and_ line | |
11935 | 0 0 line | |
11936 | 1 0 <can't happen> */ | |
c906108c SS |
11937 | |
11938 | sal = sals.sals[i]; | |
05cba821 JK |
11939 | sal_fullname = (sal.symtab == NULL |
11940 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11941 | |
4a64f543 | 11942 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11943 | ALL_BREAKPOINTS (b) |
c5aa993b | 11944 | { |
0d381245 | 11945 | int match = 0; |
4a64f543 | 11946 | /* Are we going to delete b? */ |
cc60f2e3 | 11947 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11948 | { |
11949 | struct bp_location *loc = b->loc; | |
11950 | for (; loc; loc = loc->next) | |
11951 | { | |
f8eba3c6 TT |
11952 | /* If the user specified file:line, don't allow a PC |
11953 | match. This matches historical gdb behavior. */ | |
11954 | int pc_match = (!sal.explicit_line | |
11955 | && sal.pc | |
11956 | && (loc->pspace == sal.pspace) | |
11957 | && (loc->address == sal.pc) | |
11958 | && (!section_is_overlay (loc->section) | |
11959 | || loc->section == sal.section)); | |
4aac40c8 TT |
11960 | int line_match = 0; |
11961 | ||
11962 | if ((default_match || sal.explicit_line) | |
2f202fde | 11963 | && loc->symtab != NULL |
05cba821 | 11964 | && sal_fullname != NULL |
4aac40c8 | 11965 | && sal.pspace == loc->pspace |
05cba821 JK |
11966 | && loc->line_number == sal.line |
11967 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11968 | sal_fullname) == 0) | |
11969 | line_match = 1; | |
4aac40c8 | 11970 | |
0d381245 VP |
11971 | if (pc_match || line_match) |
11972 | { | |
11973 | match = 1; | |
11974 | break; | |
11975 | } | |
11976 | } | |
11977 | } | |
11978 | ||
11979 | if (match) | |
d6e956e5 | 11980 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11981 | } |
80f8a6eb | 11982 | } |
8a2c437b | 11983 | |
80f8a6eb | 11984 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11985 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11986 | { |
11987 | if (arg) | |
8a3fe4f8 | 11988 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11989 | else |
8a3fe4f8 | 11990 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11991 | } |
c906108c | 11992 | |
8a2c437b TT |
11993 | /* Remove duplicates from the vec. */ |
11994 | qsort (VEC_address (breakpoint_p, found), | |
11995 | VEC_length (breakpoint_p, found), | |
11996 | sizeof (breakpoint_p), | |
11997 | compare_breakpoints); | |
11998 | prev = VEC_index (breakpoint_p, found, 0); | |
11999 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12000 | { | |
12001 | if (b == prev) | |
12002 | { | |
12003 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12004 | --ix; | |
12005 | } | |
12006 | } | |
12007 | ||
d6e956e5 | 12008 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12009 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12010 | if (from_tty) |
a3f17187 | 12011 | { |
d6e956e5 | 12012 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12013 | printf_unfiltered (_("Deleted breakpoint ")); |
12014 | else | |
12015 | printf_unfiltered (_("Deleted breakpoints ")); | |
12016 | } | |
d6e956e5 VP |
12017 | |
12018 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12019 | { |
c5aa993b | 12020 | if (from_tty) |
d6e956e5 VP |
12021 | printf_unfiltered ("%d ", b->number); |
12022 | delete_breakpoint (b); | |
c906108c | 12023 | } |
80f8a6eb MS |
12024 | if (from_tty) |
12025 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12026 | |
12027 | do_cleanups (cleanups); | |
c906108c SS |
12028 | } |
12029 | \f | |
12030 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12031 | all breakpoints that are marked for deletion, whether hit or not. | |
12032 | This is called after any breakpoint is hit, or after errors. */ | |
12033 | ||
12034 | void | |
fba45db2 | 12035 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12036 | { |
35df4500 | 12037 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12038 | |
12039 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12040 | if (bs->breakpoint_at |
12041 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12042 | && bs->stop) |
f431efe5 | 12043 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12044 | |
35df4500 | 12045 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12046 | { |
b5de0fa7 | 12047 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12048 | delete_breakpoint (b); |
12049 | } | |
c906108c SS |
12050 | } |
12051 | ||
4a64f543 MS |
12052 | /* A comparison function for bp_location AP and BP being interfaced to |
12053 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12054 | does breakpoint_address_is_meaningful say for its OWNER), | |
12055 | secondarily by ordering first bp_permanent OWNERed elements and | |
12056 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12057 | qsort being an unstable algorithm. */ |
876fa593 JK |
12058 | |
12059 | static int | |
494cfb0f | 12060 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12061 | { |
494cfb0f JK |
12062 | struct bp_location *a = *(void **) ap; |
12063 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12064 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12065 | int a_perm = a->owner->enable_state == bp_permanent; |
12066 | int b_perm = b->owner->enable_state == bp_permanent; | |
12067 | ||
12068 | if (a->address != b->address) | |
12069 | return (a->address > b->address) - (a->address < b->address); | |
12070 | ||
dea2aa5f LM |
12071 | /* Sort locations at the same address by their pspace number, keeping |
12072 | locations of the same inferior (in a multi-inferior environment) | |
12073 | grouped. */ | |
12074 | ||
12075 | if (a->pspace->num != b->pspace->num) | |
12076 | return ((a->pspace->num > b->pspace->num) | |
12077 | - (a->pspace->num < b->pspace->num)); | |
12078 | ||
876fa593 JK |
12079 | /* Sort permanent breakpoints first. */ |
12080 | if (a_perm != b_perm) | |
12081 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12082 | ||
c56a97f9 JK |
12083 | /* Make the internal GDB representation stable across GDB runs |
12084 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12085 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12086 | |
12087 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12088 | return ((a->owner->number > b->owner->number) |
12089 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12090 | |
12091 | return (a > b) - (a < b); | |
12092 | } | |
12093 | ||
876fa593 | 12094 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12095 | bp_location_shadow_len_after_address_max according to the current |
12096 | content of the bp_location array. */ | |
f7545552 TT |
12097 | |
12098 | static void | |
876fa593 | 12099 | bp_location_target_extensions_update (void) |
f7545552 | 12100 | { |
876fa593 JK |
12101 | struct bp_location *bl, **blp_tmp; |
12102 | ||
12103 | bp_location_placed_address_before_address_max = 0; | |
12104 | bp_location_shadow_len_after_address_max = 0; | |
12105 | ||
12106 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12107 | { | |
12108 | CORE_ADDR start, end, addr; | |
12109 | ||
12110 | if (!bp_location_has_shadow (bl)) | |
12111 | continue; | |
12112 | ||
12113 | start = bl->target_info.placed_address; | |
12114 | end = start + bl->target_info.shadow_len; | |
12115 | ||
12116 | gdb_assert (bl->address >= start); | |
12117 | addr = bl->address - start; | |
12118 | if (addr > bp_location_placed_address_before_address_max) | |
12119 | bp_location_placed_address_before_address_max = addr; | |
12120 | ||
12121 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12122 | ||
12123 | gdb_assert (bl->address < end); | |
12124 | addr = end - bl->address; | |
12125 | if (addr > bp_location_shadow_len_after_address_max) | |
12126 | bp_location_shadow_len_after_address_max = addr; | |
12127 | } | |
f7545552 TT |
12128 | } |
12129 | ||
1e4d1764 YQ |
12130 | /* Download tracepoint locations if they haven't been. */ |
12131 | ||
12132 | static void | |
12133 | download_tracepoint_locations (void) | |
12134 | { | |
7ed2c994 | 12135 | struct breakpoint *b; |
1e4d1764 YQ |
12136 | struct cleanup *old_chain; |
12137 | ||
12138 | if (!target_can_download_tracepoint ()) | |
12139 | return; | |
12140 | ||
12141 | old_chain = save_current_space_and_thread (); | |
12142 | ||
7ed2c994 | 12143 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12144 | { |
7ed2c994 | 12145 | struct bp_location *bl; |
1e4d1764 | 12146 | struct tracepoint *t; |
f2a8bc8a | 12147 | int bp_location_downloaded = 0; |
1e4d1764 | 12148 | |
7ed2c994 | 12149 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12150 | ? !may_insert_fast_tracepoints |
12151 | : !may_insert_tracepoints)) | |
12152 | continue; | |
12153 | ||
7ed2c994 YQ |
12154 | for (bl = b->loc; bl; bl = bl->next) |
12155 | { | |
12156 | /* In tracepoint, locations are _never_ duplicated, so | |
12157 | should_be_inserted is equivalent to | |
12158 | unduplicated_should_be_inserted. */ | |
12159 | if (!should_be_inserted (bl) || bl->inserted) | |
12160 | continue; | |
1e4d1764 | 12161 | |
7ed2c994 | 12162 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12163 | |
7ed2c994 | 12164 | target_download_tracepoint (bl); |
1e4d1764 | 12165 | |
7ed2c994 | 12166 | bl->inserted = 1; |
f2a8bc8a | 12167 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12168 | } |
12169 | t = (struct tracepoint *) b; | |
12170 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12171 | if (bp_location_downloaded) |
12172 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12173 | } |
12174 | ||
12175 | do_cleanups (old_chain); | |
12176 | } | |
12177 | ||
934709f0 PW |
12178 | /* Swap the insertion/duplication state between two locations. */ |
12179 | ||
12180 | static void | |
12181 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12182 | { | |
12183 | const int left_inserted = left->inserted; | |
12184 | const int left_duplicate = left->duplicate; | |
b775012e | 12185 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12186 | const struct bp_target_info left_target_info = left->target_info; |
12187 | ||
1e4d1764 YQ |
12188 | /* Locations of tracepoints can never be duplicated. */ |
12189 | if (is_tracepoint (left->owner)) | |
12190 | gdb_assert (!left->duplicate); | |
12191 | if (is_tracepoint (right->owner)) | |
12192 | gdb_assert (!right->duplicate); | |
12193 | ||
934709f0 PW |
12194 | left->inserted = right->inserted; |
12195 | left->duplicate = right->duplicate; | |
b775012e | 12196 | left->needs_update = right->needs_update; |
934709f0 PW |
12197 | left->target_info = right->target_info; |
12198 | right->inserted = left_inserted; | |
12199 | right->duplicate = left_duplicate; | |
b775012e | 12200 | right->needs_update = left_needs_update; |
934709f0 PW |
12201 | right->target_info = left_target_info; |
12202 | } | |
12203 | ||
b775012e LM |
12204 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12205 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12206 | conditions on the target's side. Such conditions need to be updated on | |
12207 | the target. */ | |
12208 | ||
12209 | static void | |
12210 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12211 | { | |
12212 | struct bp_location **locp = NULL, **loc2p; | |
12213 | struct bp_location *loc; | |
12214 | CORE_ADDR address = 0; | |
12215 | int pspace_num; | |
12216 | ||
12217 | address = bl->address; | |
12218 | pspace_num = bl->pspace->num; | |
12219 | ||
12220 | /* This is only meaningful if the target is | |
12221 | evaluating conditions and if the user has | |
12222 | opted for condition evaluation on the target's | |
12223 | side. */ | |
12224 | if (gdb_evaluates_breakpoint_condition_p () | |
12225 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12226 | return; | |
12227 | ||
12228 | /* Flag all breakpoint locations with this address and | |
12229 | the same program space as the location | |
12230 | as "its condition has changed". We need to | |
12231 | update the conditions on the target's side. */ | |
12232 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12233 | { | |
12234 | loc = *loc2p; | |
12235 | ||
12236 | if (!is_breakpoint (loc->owner) | |
12237 | || pspace_num != loc->pspace->num) | |
12238 | continue; | |
12239 | ||
12240 | /* Flag the location appropriately. We use a different state to | |
12241 | let everyone know that we already updated the set of locations | |
12242 | with addr bl->address and program space bl->pspace. This is so | |
12243 | we don't have to keep calling these functions just to mark locations | |
12244 | that have already been marked. */ | |
12245 | loc->condition_changed = condition_updated; | |
12246 | ||
12247 | /* Free the agent expression bytecode as well. We will compute | |
12248 | it later on. */ | |
12249 | if (loc->cond_bytecode) | |
12250 | { | |
12251 | free_agent_expr (loc->cond_bytecode); | |
12252 | loc->cond_bytecode = NULL; | |
12253 | } | |
12254 | } | |
12255 | } | |
12256 | ||
4cd9bd08 | 12257 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12258 | into the inferior, only remove already-inserted locations that no |
12259 | longer should be inserted. Functions that delete a breakpoint or | |
12260 | breakpoints should pass false, so that deleting a breakpoint | |
12261 | doesn't have the side effect of inserting the locations of other | |
12262 | breakpoints that are marked not-inserted, but should_be_inserted | |
12263 | returns true on them. | |
12264 | ||
12265 | This behaviour is useful is situations close to tear-down -- e.g., | |
12266 | after an exec, while the target still has execution, but breakpoint | |
12267 | shadows of the previous executable image should *NOT* be restored | |
12268 | to the new image; or before detaching, where the target still has | |
12269 | execution and wants to delete breakpoints from GDB's lists, and all | |
12270 | breakpoints had already been removed from the inferior. */ | |
12271 | ||
0d381245 | 12272 | static void |
b60e7edf | 12273 | update_global_location_list (int should_insert) |
0d381245 | 12274 | { |
74960c60 | 12275 | struct breakpoint *b; |
876fa593 | 12276 | struct bp_location **locp, *loc; |
f7545552 | 12277 | struct cleanup *cleanups; |
b775012e LM |
12278 | /* Last breakpoint location address that was marked for update. */ |
12279 | CORE_ADDR last_addr = 0; | |
12280 | /* Last breakpoint location program space that was marked for update. */ | |
12281 | int last_pspace_num = -1; | |
f7545552 | 12282 | |
2d134ed3 PA |
12283 | /* Used in the duplicates detection below. When iterating over all |
12284 | bp_locations, points to the first bp_location of a given address. | |
12285 | Breakpoints and watchpoints of different types are never | |
12286 | duplicates of each other. Keep one pointer for each type of | |
12287 | breakpoint/watchpoint, so we only need to loop over all locations | |
12288 | once. */ | |
12289 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12290 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12291 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12292 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12293 | |
4a64f543 MS |
12294 | /* Saved former bp_location array which we compare against the newly |
12295 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12296 | struct bp_location **old_location, **old_locp; |
12297 | unsigned old_location_count; | |
12298 | ||
12299 | old_location = bp_location; | |
12300 | old_location_count = bp_location_count; | |
12301 | bp_location = NULL; | |
12302 | bp_location_count = 0; | |
12303 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12304 | |
74960c60 | 12305 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12306 | for (loc = b->loc; loc; loc = loc->next) |
12307 | bp_location_count++; | |
12308 | ||
12309 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12310 | locp = bp_location; | |
12311 | ALL_BREAKPOINTS (b) | |
12312 | for (loc = b->loc; loc; loc = loc->next) | |
12313 | *locp++ = loc; | |
12314 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12315 | bp_location_compare); |
876fa593 JK |
12316 | |
12317 | bp_location_target_extensions_update (); | |
74960c60 | 12318 | |
4a64f543 MS |
12319 | /* Identify bp_location instances that are no longer present in the |
12320 | new list, and therefore should be freed. Note that it's not | |
12321 | necessary that those locations should be removed from inferior -- | |
12322 | if there's another location at the same address (previously | |
12323 | marked as duplicate), we don't need to remove/insert the | |
12324 | location. | |
876fa593 | 12325 | |
4a64f543 MS |
12326 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12327 | and former bp_location array state respectively. */ | |
876fa593 JK |
12328 | |
12329 | locp = bp_location; | |
12330 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12331 | old_locp++) | |
74960c60 | 12332 | { |
876fa593 | 12333 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12334 | struct bp_location **loc2p; |
876fa593 | 12335 | |
e5dd4106 | 12336 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12337 | not, we have to free it. */ |
c7d46a38 | 12338 | int found_object = 0; |
20874c92 VP |
12339 | /* Tells if the location should remain inserted in the target. */ |
12340 | int keep_in_target = 0; | |
12341 | int removed = 0; | |
876fa593 | 12342 | |
4a64f543 MS |
12343 | /* Skip LOCP entries which will definitely never be needed. |
12344 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12345 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12346 | && (*locp)->address < old_loc->address) |
876fa593 | 12347 | locp++; |
c7d46a38 PA |
12348 | |
12349 | for (loc2p = locp; | |
12350 | (loc2p < bp_location + bp_location_count | |
12351 | && (*loc2p)->address == old_loc->address); | |
12352 | loc2p++) | |
12353 | { | |
b775012e LM |
12354 | /* Check if this is a new/duplicated location or a duplicated |
12355 | location that had its condition modified. If so, we want to send | |
12356 | its condition to the target if evaluation of conditions is taking | |
12357 | place there. */ | |
12358 | if ((*loc2p)->condition_changed == condition_modified | |
12359 | && (last_addr != old_loc->address | |
12360 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12361 | { |
b775012e LM |
12362 | force_breakpoint_reinsertion (*loc2p); |
12363 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12364 | } |
b775012e LM |
12365 | |
12366 | if (*loc2p == old_loc) | |
12367 | found_object = 1; | |
c7d46a38 | 12368 | } |
74960c60 | 12369 | |
b775012e LM |
12370 | /* We have already handled this address, update it so that we don't |
12371 | have to go through updates again. */ | |
12372 | last_addr = old_loc->address; | |
12373 | ||
12374 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12375 | if (!found_object) | |
12376 | force_breakpoint_reinsertion (old_loc); | |
12377 | ||
4a64f543 MS |
12378 | /* If this location is no longer present, and inserted, look if |
12379 | there's maybe a new location at the same address. If so, | |
12380 | mark that one inserted, and don't remove this one. This is | |
12381 | needed so that we don't have a time window where a breakpoint | |
12382 | at certain location is not inserted. */ | |
74960c60 | 12383 | |
876fa593 | 12384 | if (old_loc->inserted) |
0d381245 | 12385 | { |
4a64f543 MS |
12386 | /* If the location is inserted now, we might have to remove |
12387 | it. */ | |
74960c60 | 12388 | |
876fa593 | 12389 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12390 | { |
4a64f543 MS |
12391 | /* The location is still present in the location list, |
12392 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12393 | keep_in_target = 1; |
74960c60 VP |
12394 | } |
12395 | else | |
12396 | { | |
b775012e LM |
12397 | /* This location still exists, but it won't be kept in the |
12398 | target since it may have been disabled. We proceed to | |
12399 | remove its target-side condition. */ | |
12400 | ||
4a64f543 MS |
12401 | /* The location is either no longer present, or got |
12402 | disabled. See if there's another location at the | |
12403 | same address, in which case we don't need to remove | |
12404 | this one from the target. */ | |
876fa593 | 12405 | |
2bdf28a0 | 12406 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12407 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12408 | { | |
876fa593 | 12409 | for (loc2p = locp; |
c7d46a38 PA |
12410 | (loc2p < bp_location + bp_location_count |
12411 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12412 | loc2p++) |
12413 | { | |
12414 | struct bp_location *loc2 = *loc2p; | |
12415 | ||
2d134ed3 | 12416 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12417 | { |
85d721b8 PA |
12418 | /* Read watchpoint locations are switched to |
12419 | access watchpoints, if the former are not | |
12420 | supported, but the latter are. */ | |
12421 | if (is_hardware_watchpoint (old_loc->owner)) | |
12422 | { | |
12423 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12424 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12425 | } | |
12426 | ||
934709f0 PW |
12427 | /* loc2 is a duplicated location. We need to check |
12428 | if it should be inserted in case it will be | |
12429 | unduplicated. */ | |
12430 | if (loc2 != old_loc | |
12431 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12432 | { |
934709f0 | 12433 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12434 | keep_in_target = 1; |
12435 | break; | |
12436 | } | |
876fa593 JK |
12437 | } |
12438 | } | |
12439 | } | |
74960c60 VP |
12440 | } |
12441 | ||
20874c92 VP |
12442 | if (!keep_in_target) |
12443 | { | |
876fa593 | 12444 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12445 | { |
4a64f543 MS |
12446 | /* This is just about all we can do. We could keep |
12447 | this location on the global list, and try to | |
12448 | remove it next time, but there's no particular | |
12449 | reason why we will succeed next time. | |
20874c92 | 12450 | |
4a64f543 MS |
12451 | Note that at this point, old_loc->owner is still |
12452 | valid, as delete_breakpoint frees the breakpoint | |
12453 | only after calling us. */ | |
3e43a32a MS |
12454 | printf_filtered (_("warning: Error removing " |
12455 | "breakpoint %d\n"), | |
876fa593 | 12456 | old_loc->owner->number); |
20874c92 VP |
12457 | } |
12458 | removed = 1; | |
12459 | } | |
0d381245 | 12460 | } |
74960c60 VP |
12461 | |
12462 | if (!found_object) | |
1c5cfe86 | 12463 | { |
db82e815 PA |
12464 | if (removed && non_stop |
12465 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12466 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12467 | { |
db82e815 PA |
12468 | /* This location was removed from the target. In |
12469 | non-stop mode, a race condition is possible where | |
12470 | we've removed a breakpoint, but stop events for that | |
12471 | breakpoint are already queued and will arrive later. | |
12472 | We apply an heuristic to be able to distinguish such | |
12473 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12474 | breakpoint location for a bit, and will retire it | |
12475 | after we see some number of events. The theory here | |
12476 | is that reporting of events should, "on the average", | |
12477 | be fair, so after a while we'll see events from all | |
12478 | threads that have anything of interest, and no longer | |
12479 | need to keep this breakpoint location around. We | |
12480 | don't hold locations forever so to reduce chances of | |
12481 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12482 | SIGTRAP. | |
12483 | ||
12484 | The heuristic failing can be disastrous on | |
12485 | decr_pc_after_break targets. | |
12486 | ||
12487 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12488 | if we fail to recognize a late breakpoint SIGTRAP, | |
12489 | because events_till_retirement has reached 0 too | |
12490 | soon, we'll fail to do the PC adjustment, and report | |
12491 | a random SIGTRAP to the user. When the user resumes | |
12492 | the inferior, it will most likely immediately crash | |
2dec564e | 12493 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12494 | corrupted, because of being resumed e.g., in the |
12495 | middle of a multi-byte instruction, or skipped a | |
12496 | one-byte instruction. This was actually seen happen | |
12497 | on native x86-linux, and should be less rare on | |
12498 | targets that do not support new thread events, like | |
12499 | remote, due to the heuristic depending on | |
12500 | thread_count. | |
12501 | ||
12502 | Mistaking a random SIGTRAP for a breakpoint trap | |
12503 | causes similar symptoms (PC adjustment applied when | |
12504 | it shouldn't), but then again, playing with SIGTRAPs | |
12505 | behind the debugger's back is asking for trouble. | |
12506 | ||
12507 | Since hardware watchpoint traps are always | |
12508 | distinguishable from other traps, so we don't need to | |
12509 | apply keep hardware watchpoint moribund locations | |
12510 | around. We simply always ignore hardware watchpoint | |
12511 | traps we can no longer explain. */ | |
12512 | ||
876fa593 JK |
12513 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12514 | old_loc->owner = NULL; | |
20874c92 | 12515 | |
876fa593 | 12516 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12517 | } |
12518 | else | |
f431efe5 PA |
12519 | { |
12520 | old_loc->owner = NULL; | |
12521 | decref_bp_location (&old_loc); | |
12522 | } | |
20874c92 | 12523 | } |
74960c60 | 12524 | } |
1c5cfe86 | 12525 | |
348d480f PA |
12526 | /* Rescan breakpoints at the same address and section, marking the |
12527 | first one as "first" and any others as "duplicates". This is so | |
12528 | that the bpt instruction is only inserted once. If we have a | |
12529 | permanent breakpoint at the same place as BPT, make that one the | |
12530 | official one, and the rest as duplicates. Permanent breakpoints | |
12531 | are sorted first for the same address. | |
12532 | ||
12533 | Do the same for hardware watchpoints, but also considering the | |
12534 | watchpoint's type (regular/access/read) and length. */ | |
12535 | ||
12536 | bp_loc_first = NULL; | |
12537 | wp_loc_first = NULL; | |
12538 | awp_loc_first = NULL; | |
12539 | rwp_loc_first = NULL; | |
12540 | ALL_BP_LOCATIONS (loc, locp) | |
12541 | { | |
12542 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12543 | non-NULL. */ | |
348d480f | 12544 | struct bp_location **loc_first_p; |
d3fbdd86 | 12545 | b = loc->owner; |
348d480f | 12546 | |
6f380991 | 12547 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12548 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12549 | /* Don't detect duplicate for tracepoint locations because they are |
12550 | never duplicated. See the comments in field `duplicate' of | |
12551 | `struct bp_location'. */ | |
348d480f | 12552 | || is_tracepoint (b)) |
b775012e LM |
12553 | { |
12554 | /* Clear the condition modification flag. */ | |
12555 | loc->condition_changed = condition_unchanged; | |
12556 | continue; | |
12557 | } | |
348d480f PA |
12558 | |
12559 | /* Permanent breakpoint should always be inserted. */ | |
12560 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12561 | internal_error (__FILE__, __LINE__, | |
12562 | _("allegedly permanent breakpoint is not " | |
12563 | "actually inserted")); | |
12564 | ||
12565 | if (b->type == bp_hardware_watchpoint) | |
12566 | loc_first_p = &wp_loc_first; | |
12567 | else if (b->type == bp_read_watchpoint) | |
12568 | loc_first_p = &rwp_loc_first; | |
12569 | else if (b->type == bp_access_watchpoint) | |
12570 | loc_first_p = &awp_loc_first; | |
12571 | else | |
12572 | loc_first_p = &bp_loc_first; | |
12573 | ||
12574 | if (*loc_first_p == NULL | |
12575 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12576 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12577 | { | |
12578 | *loc_first_p = loc; | |
12579 | loc->duplicate = 0; | |
b775012e LM |
12580 | |
12581 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12582 | { | |
12583 | loc->needs_update = 1; | |
12584 | /* Clear the condition modification flag. */ | |
12585 | loc->condition_changed = condition_unchanged; | |
12586 | } | |
348d480f PA |
12587 | continue; |
12588 | } | |
12589 | ||
934709f0 PW |
12590 | |
12591 | /* This and the above ensure the invariant that the first location | |
12592 | is not duplicated, and is the inserted one. | |
12593 | All following are marked as duplicated, and are not inserted. */ | |
12594 | if (loc->inserted) | |
12595 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12596 | loc->duplicate = 1; |
12597 | ||
b775012e LM |
12598 | /* Clear the condition modification flag. */ |
12599 | loc->condition_changed = condition_unchanged; | |
12600 | ||
348d480f PA |
12601 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12602 | && b->enable_state != bp_permanent) | |
12603 | internal_error (__FILE__, __LINE__, | |
12604 | _("another breakpoint was inserted on top of " | |
12605 | "a permanent breakpoint")); | |
12606 | } | |
12607 | ||
b775012e | 12608 | if (breakpoints_always_inserted_mode () |
348d480f | 12609 | && (have_live_inferiors () |
f5656ead | 12610 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12611 | { |
12612 | if (should_insert) | |
12613 | insert_breakpoint_locations (); | |
12614 | else | |
12615 | { | |
12616 | /* Though should_insert is false, we may need to update conditions | |
12617 | on the target's side if it is evaluating such conditions. We | |
12618 | only update conditions for locations that are marked | |
12619 | "needs_update". */ | |
12620 | update_inserted_breakpoint_locations (); | |
12621 | } | |
12622 | } | |
348d480f | 12623 | |
1e4d1764 YQ |
12624 | if (should_insert) |
12625 | download_tracepoint_locations (); | |
12626 | ||
348d480f PA |
12627 | do_cleanups (cleanups); |
12628 | } | |
12629 | ||
12630 | void | |
12631 | breakpoint_retire_moribund (void) | |
12632 | { | |
12633 | struct bp_location *loc; | |
12634 | int ix; | |
12635 | ||
12636 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12637 | if (--(loc->events_till_retirement) == 0) | |
12638 | { | |
12639 | decref_bp_location (&loc); | |
12640 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12641 | --ix; | |
12642 | } | |
12643 | } | |
12644 | ||
12645 | static void | |
12646 | update_global_location_list_nothrow (int inserting) | |
12647 | { | |
bfd189b1 | 12648 | volatile struct gdb_exception e; |
348d480f PA |
12649 | |
12650 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12651 | update_global_location_list (inserting); | |
12652 | } | |
12653 | ||
12654 | /* Clear BKP from a BPS. */ | |
12655 | ||
12656 | static void | |
12657 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12658 | { | |
12659 | bpstat bs; | |
12660 | ||
12661 | for (bs = bps; bs; bs = bs->next) | |
12662 | if (bs->breakpoint_at == bpt) | |
12663 | { | |
12664 | bs->breakpoint_at = NULL; | |
12665 | bs->old_val = NULL; | |
12666 | /* bs->commands will be freed later. */ | |
12667 | } | |
12668 | } | |
12669 | ||
12670 | /* Callback for iterate_over_threads. */ | |
12671 | static int | |
12672 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12673 | { | |
12674 | struct breakpoint *bpt = data; | |
12675 | ||
12676 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12677 | return 0; | |
12678 | } | |
12679 | ||
12680 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12681 | callbacks. */ | |
12682 | ||
12683 | static void | |
12684 | say_where (struct breakpoint *b) | |
12685 | { | |
12686 | struct value_print_options opts; | |
12687 | ||
12688 | get_user_print_options (&opts); | |
12689 | ||
12690 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12691 | single string. */ | |
12692 | if (b->loc == NULL) | |
12693 | { | |
12694 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12695 | } | |
12696 | else | |
12697 | { | |
2f202fde | 12698 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12699 | { |
12700 | printf_filtered (" at "); | |
12701 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12702 | gdb_stdout); | |
12703 | } | |
2f202fde | 12704 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12705 | { |
12706 | /* If there is a single location, we can print the location | |
12707 | more nicely. */ | |
12708 | if (b->loc->next == NULL) | |
12709 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12710 | symtab_to_filename_for_display (b->loc->symtab), |
12711 | b->loc->line_number); | |
f8eba3c6 TT |
12712 | else |
12713 | /* This is not ideal, but each location may have a | |
12714 | different file name, and this at least reflects the | |
12715 | real situation somewhat. */ | |
12716 | printf_filtered (": %s.", b->addr_string); | |
12717 | } | |
348d480f PA |
12718 | |
12719 | if (b->loc->next) | |
12720 | { | |
12721 | struct bp_location *loc = b->loc; | |
12722 | int n = 0; | |
12723 | for (; loc; loc = loc->next) | |
12724 | ++n; | |
12725 | printf_filtered (" (%d locations)", n); | |
12726 | } | |
12727 | } | |
12728 | } | |
12729 | ||
348d480f PA |
12730 | /* Default bp_location_ops methods. */ |
12731 | ||
12732 | static void | |
12733 | bp_location_dtor (struct bp_location *self) | |
12734 | { | |
12735 | xfree (self->cond); | |
b775012e LM |
12736 | if (self->cond_bytecode) |
12737 | free_agent_expr (self->cond_bytecode); | |
348d480f PA |
12738 | xfree (self->function_name); |
12739 | } | |
12740 | ||
12741 | static const struct bp_location_ops bp_location_ops = | |
12742 | { | |
12743 | bp_location_dtor | |
12744 | }; | |
12745 | ||
2060206e PA |
12746 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12747 | inherit from. */ | |
348d480f | 12748 | |
2060206e PA |
12749 | static void |
12750 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12751 | { |
12752 | decref_counted_command_line (&self->commands); | |
12753 | xfree (self->cond_string); | |
fb81d016 | 12754 | xfree (self->extra_string); |
348d480f | 12755 | xfree (self->addr_string); |
f8eba3c6 | 12756 | xfree (self->filter); |
348d480f | 12757 | xfree (self->addr_string_range_end); |
348d480f PA |
12758 | } |
12759 | ||
2060206e PA |
12760 | static struct bp_location * |
12761 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12762 | { |
12763 | struct bp_location *loc; | |
12764 | ||
12765 | loc = XNEW (struct bp_location); | |
12766 | init_bp_location (loc, &bp_location_ops, self); | |
12767 | return loc; | |
12768 | } | |
12769 | ||
2060206e PA |
12770 | static void |
12771 | base_breakpoint_re_set (struct breakpoint *b) | |
12772 | { | |
12773 | /* Nothing to re-set. */ | |
12774 | } | |
12775 | ||
12776 | #define internal_error_pure_virtual_called() \ | |
12777 | gdb_assert_not_reached ("pure virtual function called") | |
12778 | ||
12779 | static int | |
12780 | base_breakpoint_insert_location (struct bp_location *bl) | |
12781 | { | |
12782 | internal_error_pure_virtual_called (); | |
12783 | } | |
12784 | ||
12785 | static int | |
12786 | base_breakpoint_remove_location (struct bp_location *bl) | |
12787 | { | |
12788 | internal_error_pure_virtual_called (); | |
12789 | } | |
12790 | ||
12791 | static int | |
12792 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12793 | struct address_space *aspace, | |
09ac7c10 TT |
12794 | CORE_ADDR bp_addr, |
12795 | const struct target_waitstatus *ws) | |
2060206e PA |
12796 | { |
12797 | internal_error_pure_virtual_called (); | |
12798 | } | |
12799 | ||
12800 | static void | |
12801 | base_breakpoint_check_status (bpstat bs) | |
12802 | { | |
12803 | /* Always stop. */ | |
12804 | } | |
12805 | ||
12806 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12807 | errors. */ | |
12808 | ||
12809 | static int | |
12810 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12811 | { | |
12812 | internal_error_pure_virtual_called (); | |
12813 | } | |
12814 | ||
12815 | /* A "resources_needed" breakpoint_ops method that just internal | |
12816 | errors. */ | |
12817 | ||
12818 | static int | |
12819 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12820 | { | |
12821 | internal_error_pure_virtual_called (); | |
12822 | } | |
12823 | ||
12824 | static enum print_stop_action | |
12825 | base_breakpoint_print_it (bpstat bs) | |
12826 | { | |
12827 | internal_error_pure_virtual_called (); | |
12828 | } | |
12829 | ||
12830 | static void | |
12831 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12832 | struct ui_out *uiout) | |
12833 | { | |
12834 | /* nothing */ | |
12835 | } | |
12836 | ||
12837 | static void | |
12838 | base_breakpoint_print_mention (struct breakpoint *b) | |
12839 | { | |
12840 | internal_error_pure_virtual_called (); | |
12841 | } | |
12842 | ||
12843 | static void | |
12844 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12845 | { | |
12846 | internal_error_pure_virtual_called (); | |
12847 | } | |
12848 | ||
983af33b SDJ |
12849 | static void |
12850 | base_breakpoint_create_sals_from_address (char **arg, | |
12851 | struct linespec_result *canonical, | |
12852 | enum bptype type_wanted, | |
12853 | char *addr_start, | |
12854 | char **copy_arg) | |
12855 | { | |
12856 | internal_error_pure_virtual_called (); | |
12857 | } | |
12858 | ||
12859 | static void | |
12860 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12861 | struct linespec_result *c, | |
983af33b | 12862 | char *cond_string, |
e7e0cddf | 12863 | char *extra_string, |
983af33b SDJ |
12864 | enum bptype type_wanted, |
12865 | enum bpdisp disposition, | |
12866 | int thread, | |
12867 | int task, int ignore_count, | |
12868 | const struct breakpoint_ops *o, | |
12869 | int from_tty, int enabled, | |
44f238bb | 12870 | int internal, unsigned flags) |
983af33b SDJ |
12871 | { |
12872 | internal_error_pure_virtual_called (); | |
12873 | } | |
12874 | ||
12875 | static void | |
12876 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12877 | struct symtabs_and_lines *sals) | |
12878 | { | |
12879 | internal_error_pure_virtual_called (); | |
12880 | } | |
12881 | ||
ab04a2af TT |
12882 | /* The default 'explains_signal' method. */ |
12883 | ||
12884 | static enum bpstat_signal_value | |
427cd150 | 12885 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af TT |
12886 | { |
12887 | return BPSTAT_SIGNAL_HIDE; | |
12888 | } | |
12889 | ||
9d6e6e84 HZ |
12890 | /* The default "after_condition_true" method. */ |
12891 | ||
12892 | static void | |
12893 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12894 | { | |
12895 | /* Nothing to do. */ | |
12896 | } | |
12897 | ||
ab04a2af | 12898 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12899 | { |
12900 | base_breakpoint_dtor, | |
12901 | base_breakpoint_allocate_location, | |
12902 | base_breakpoint_re_set, | |
12903 | base_breakpoint_insert_location, | |
12904 | base_breakpoint_remove_location, | |
12905 | base_breakpoint_breakpoint_hit, | |
12906 | base_breakpoint_check_status, | |
12907 | base_breakpoint_resources_needed, | |
12908 | base_breakpoint_works_in_software_mode, | |
12909 | base_breakpoint_print_it, | |
12910 | NULL, | |
12911 | base_breakpoint_print_one_detail, | |
12912 | base_breakpoint_print_mention, | |
983af33b SDJ |
12913 | base_breakpoint_print_recreate, |
12914 | base_breakpoint_create_sals_from_address, | |
12915 | base_breakpoint_create_breakpoints_sal, | |
12916 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12917 | base_breakpoint_explains_signal, |
12918 | base_breakpoint_after_condition_true, | |
2060206e PA |
12919 | }; |
12920 | ||
12921 | /* Default breakpoint_ops methods. */ | |
12922 | ||
12923 | static void | |
348d480f PA |
12924 | bkpt_re_set (struct breakpoint *b) |
12925 | { | |
06edf0c0 PA |
12926 | /* FIXME: is this still reachable? */ |
12927 | if (b->addr_string == NULL) | |
12928 | { | |
12929 | /* Anything without a string can't be re-set. */ | |
348d480f | 12930 | delete_breakpoint (b); |
06edf0c0 | 12931 | return; |
348d480f | 12932 | } |
06edf0c0 PA |
12933 | |
12934 | breakpoint_re_set_default (b); | |
348d480f PA |
12935 | } |
12936 | ||
2060206e | 12937 | static int |
348d480f PA |
12938 | bkpt_insert_location (struct bp_location *bl) |
12939 | { | |
12940 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12941 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12942 | &bl->target_info); | |
12943 | else | |
12944 | return target_insert_breakpoint (bl->gdbarch, | |
12945 | &bl->target_info); | |
12946 | } | |
12947 | ||
2060206e | 12948 | static int |
348d480f PA |
12949 | bkpt_remove_location (struct bp_location *bl) |
12950 | { | |
12951 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12952 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12953 | else | |
12954 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12955 | } | |
12956 | ||
2060206e | 12957 | static int |
348d480f | 12958 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12959 | struct address_space *aspace, CORE_ADDR bp_addr, |
12960 | const struct target_waitstatus *ws) | |
348d480f | 12961 | { |
09ac7c10 | 12962 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12963 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12964 | return 0; |
12965 | ||
348d480f PA |
12966 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12967 | aspace, bp_addr)) | |
12968 | return 0; | |
12969 | ||
12970 | if (overlay_debugging /* unmapped overlay section */ | |
12971 | && section_is_overlay (bl->section) | |
12972 | && !section_is_mapped (bl->section)) | |
12973 | return 0; | |
12974 | ||
12975 | return 1; | |
12976 | } | |
12977 | ||
2060206e | 12978 | static int |
348d480f PA |
12979 | bkpt_resources_needed (const struct bp_location *bl) |
12980 | { | |
12981 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12982 | ||
12983 | return 1; | |
12984 | } | |
12985 | ||
2060206e | 12986 | static enum print_stop_action |
348d480f PA |
12987 | bkpt_print_it (bpstat bs) |
12988 | { | |
348d480f PA |
12989 | struct breakpoint *b; |
12990 | const struct bp_location *bl; | |
001c8c33 | 12991 | int bp_temp; |
79a45e25 | 12992 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12993 | |
12994 | gdb_assert (bs->bp_location_at != NULL); | |
12995 | ||
12996 | bl = bs->bp_location_at; | |
12997 | b = bs->breakpoint_at; | |
12998 | ||
001c8c33 PA |
12999 | bp_temp = b->disposition == disp_del; |
13000 | if (bl->address != bl->requested_address) | |
13001 | breakpoint_adjustment_warning (bl->requested_address, | |
13002 | bl->address, | |
13003 | b->number, 1); | |
13004 | annotate_breakpoint (b->number); | |
13005 | if (bp_temp) | |
13006 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13007 | else | |
13008 | ui_out_text (uiout, "\nBreakpoint "); | |
13009 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13010 | { |
001c8c33 PA |
13011 | ui_out_field_string (uiout, "reason", |
13012 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13013 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13014 | } |
001c8c33 PA |
13015 | ui_out_field_int (uiout, "bkptno", b->number); |
13016 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13017 | |
001c8c33 | 13018 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13019 | } |
13020 | ||
2060206e | 13021 | static void |
06edf0c0 PA |
13022 | bkpt_print_mention (struct breakpoint *b) |
13023 | { | |
79a45e25 | 13024 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13025 | return; |
13026 | ||
13027 | switch (b->type) | |
13028 | { | |
13029 | case bp_breakpoint: | |
13030 | case bp_gnu_ifunc_resolver: | |
13031 | if (b->disposition == disp_del) | |
13032 | printf_filtered (_("Temporary breakpoint")); | |
13033 | else | |
13034 | printf_filtered (_("Breakpoint")); | |
13035 | printf_filtered (_(" %d"), b->number); | |
13036 | if (b->type == bp_gnu_ifunc_resolver) | |
13037 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13038 | break; | |
13039 | case bp_hardware_breakpoint: | |
13040 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13041 | break; | |
e7e0cddf SS |
13042 | case bp_dprintf: |
13043 | printf_filtered (_("Dprintf %d"), b->number); | |
13044 | break; | |
06edf0c0 PA |
13045 | } |
13046 | ||
13047 | say_where (b); | |
13048 | } | |
13049 | ||
2060206e | 13050 | static void |
06edf0c0 PA |
13051 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13052 | { | |
13053 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13054 | fprintf_unfiltered (fp, "tbreak"); | |
13055 | else if (tp->type == bp_breakpoint) | |
13056 | fprintf_unfiltered (fp, "break"); | |
13057 | else if (tp->type == bp_hardware_breakpoint | |
13058 | && tp->disposition == disp_del) | |
13059 | fprintf_unfiltered (fp, "thbreak"); | |
13060 | else if (tp->type == bp_hardware_breakpoint) | |
13061 | fprintf_unfiltered (fp, "hbreak"); | |
13062 | else | |
13063 | internal_error (__FILE__, __LINE__, | |
13064 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13065 | ||
2060206e | 13066 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13067 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13068 | } |
13069 | ||
983af33b SDJ |
13070 | static void |
13071 | bkpt_create_sals_from_address (char **arg, | |
13072 | struct linespec_result *canonical, | |
13073 | enum bptype type_wanted, | |
13074 | char *addr_start, char **copy_arg) | |
13075 | { | |
13076 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13077 | addr_start, copy_arg); | |
13078 | } | |
13079 | ||
13080 | static void | |
13081 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13082 | struct linespec_result *canonical, | |
983af33b | 13083 | char *cond_string, |
e7e0cddf | 13084 | char *extra_string, |
983af33b SDJ |
13085 | enum bptype type_wanted, |
13086 | enum bpdisp disposition, | |
13087 | int thread, | |
13088 | int task, int ignore_count, | |
13089 | const struct breakpoint_ops *ops, | |
13090 | int from_tty, int enabled, | |
44f238bb | 13091 | int internal, unsigned flags) |
983af33b | 13092 | { |
023fa29b | 13093 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13094 | cond_string, extra_string, |
13095 | type_wanted, | |
983af33b SDJ |
13096 | disposition, thread, task, |
13097 | ignore_count, ops, from_tty, | |
44f238bb | 13098 | enabled, internal, flags); |
983af33b SDJ |
13099 | } |
13100 | ||
13101 | static void | |
13102 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13103 | struct symtabs_and_lines *sals) | |
13104 | { | |
13105 | decode_linespec_default (b, s, sals); | |
13106 | } | |
13107 | ||
06edf0c0 PA |
13108 | /* Virtual table for internal breakpoints. */ |
13109 | ||
13110 | static void | |
13111 | internal_bkpt_re_set (struct breakpoint *b) | |
13112 | { | |
13113 | switch (b->type) | |
13114 | { | |
13115 | /* Delete overlay event and longjmp master breakpoints; they | |
13116 | will be reset later by breakpoint_re_set. */ | |
13117 | case bp_overlay_event: | |
13118 | case bp_longjmp_master: | |
13119 | case bp_std_terminate_master: | |
13120 | case bp_exception_master: | |
13121 | delete_breakpoint (b); | |
13122 | break; | |
13123 | ||
13124 | /* This breakpoint is special, it's set up when the inferior | |
13125 | starts and we really don't want to touch it. */ | |
13126 | case bp_shlib_event: | |
13127 | ||
13128 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13129 | it is set up, we do not want to touch it. */ | |
13130 | case bp_thread_event: | |
13131 | break; | |
13132 | } | |
13133 | } | |
13134 | ||
13135 | static void | |
13136 | internal_bkpt_check_status (bpstat bs) | |
13137 | { | |
a9b3a50f PA |
13138 | if (bs->breakpoint_at->type == bp_shlib_event) |
13139 | { | |
13140 | /* If requested, stop when the dynamic linker notifies GDB of | |
13141 | events. This allows the user to get control and place | |
13142 | breakpoints in initializer routines for dynamically loaded | |
13143 | objects (among other things). */ | |
13144 | bs->stop = stop_on_solib_events; | |
13145 | bs->print = stop_on_solib_events; | |
13146 | } | |
13147 | else | |
13148 | bs->stop = 0; | |
06edf0c0 PA |
13149 | } |
13150 | ||
13151 | static enum print_stop_action | |
13152 | internal_bkpt_print_it (bpstat bs) | |
13153 | { | |
06edf0c0 | 13154 | struct breakpoint *b; |
06edf0c0 | 13155 | |
06edf0c0 PA |
13156 | b = bs->breakpoint_at; |
13157 | ||
06edf0c0 PA |
13158 | switch (b->type) |
13159 | { | |
348d480f PA |
13160 | case bp_shlib_event: |
13161 | /* Did we stop because the user set the stop_on_solib_events | |
13162 | variable? (If so, we report this as a generic, "Stopped due | |
13163 | to shlib event" message.) */ | |
edcc5120 | 13164 | print_solib_event (0); |
348d480f PA |
13165 | break; |
13166 | ||
13167 | case bp_thread_event: | |
13168 | /* Not sure how we will get here. | |
13169 | GDB should not stop for these breakpoints. */ | |
13170 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13171 | break; |
13172 | ||
13173 | case bp_overlay_event: | |
13174 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13175 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13176 | break; |
13177 | ||
13178 | case bp_longjmp_master: | |
13179 | /* These should never be enabled. */ | |
13180 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13181 | break; |
13182 | ||
13183 | case bp_std_terminate_master: | |
13184 | /* These should never be enabled. */ | |
13185 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13186 | "gdb should not stop!\n")); | |
348d480f PA |
13187 | break; |
13188 | ||
13189 | case bp_exception_master: | |
13190 | /* These should never be enabled. */ | |
13191 | printf_filtered (_("Exception Master Breakpoint: " | |
13192 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13193 | break; |
13194 | } | |
13195 | ||
001c8c33 | 13196 | return PRINT_NOTHING; |
06edf0c0 PA |
13197 | } |
13198 | ||
13199 | static void | |
13200 | internal_bkpt_print_mention (struct breakpoint *b) | |
13201 | { | |
13202 | /* Nothing to mention. These breakpoints are internal. */ | |
13203 | } | |
13204 | ||
06edf0c0 PA |
13205 | /* Virtual table for momentary breakpoints */ |
13206 | ||
13207 | static void | |
13208 | momentary_bkpt_re_set (struct breakpoint *b) | |
13209 | { | |
13210 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13211 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13212 | Otherwise these should have been blown away via the cleanup chain |
13213 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13214 | } | |
13215 | ||
13216 | static void | |
13217 | momentary_bkpt_check_status (bpstat bs) | |
13218 | { | |
13219 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13220 | } | |
13221 | ||
13222 | static enum print_stop_action | |
13223 | momentary_bkpt_print_it (bpstat bs) | |
13224 | { | |
79a45e25 PA |
13225 | struct ui_out *uiout = current_uiout; |
13226 | ||
001c8c33 | 13227 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13228 | { |
001c8c33 | 13229 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13230 | |
001c8c33 PA |
13231 | switch (b->type) |
13232 | { | |
13233 | case bp_finish: | |
13234 | ui_out_field_string | |
13235 | (uiout, "reason", | |
13236 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13237 | break; | |
348d480f | 13238 | |
001c8c33 PA |
13239 | case bp_until: |
13240 | ui_out_field_string | |
13241 | (uiout, "reason", | |
13242 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13243 | break; | |
13244 | } | |
348d480f PA |
13245 | } |
13246 | ||
001c8c33 | 13247 | return PRINT_UNKNOWN; |
348d480f PA |
13248 | } |
13249 | ||
06edf0c0 PA |
13250 | static void |
13251 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13252 | { |
06edf0c0 | 13253 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13254 | } |
13255 | ||
e2e4d78b JK |
13256 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13257 | ||
13258 | It gets cleared already on the removal of the first one of such placed | |
13259 | breakpoints. This is OK as they get all removed altogether. */ | |
13260 | ||
13261 | static void | |
13262 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13263 | { | |
13264 | struct thread_info *tp = find_thread_id (self->thread); | |
13265 | ||
13266 | if (tp) | |
13267 | tp->initiating_frame = null_frame_id; | |
13268 | ||
13269 | momentary_breakpoint_ops.dtor (self); | |
13270 | } | |
13271 | ||
55aa24fb SDJ |
13272 | /* Specific methods for probe breakpoints. */ |
13273 | ||
13274 | static int | |
13275 | bkpt_probe_insert_location (struct bp_location *bl) | |
13276 | { | |
13277 | int v = bkpt_insert_location (bl); | |
13278 | ||
13279 | if (v == 0) | |
13280 | { | |
13281 | /* The insertion was successful, now let's set the probe's semaphore | |
13282 | if needed. */ | |
13283 | bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch); | |
13284 | } | |
13285 | ||
13286 | return v; | |
13287 | } | |
13288 | ||
13289 | static int | |
13290 | bkpt_probe_remove_location (struct bp_location *bl) | |
13291 | { | |
13292 | /* Let's clear the semaphore before removing the location. */ | |
13293 | bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch); | |
13294 | ||
13295 | return bkpt_remove_location (bl); | |
13296 | } | |
13297 | ||
13298 | static void | |
13299 | bkpt_probe_create_sals_from_address (char **arg, | |
13300 | struct linespec_result *canonical, | |
13301 | enum bptype type_wanted, | |
13302 | char *addr_start, char **copy_arg) | |
13303 | { | |
13304 | struct linespec_sals lsal; | |
13305 | ||
13306 | lsal.sals = parse_probes (arg, canonical); | |
13307 | ||
13308 | *copy_arg = xstrdup (canonical->addr_string); | |
13309 | lsal.canonical = xstrdup (*copy_arg); | |
13310 | ||
13311 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13312 | } | |
13313 | ||
13314 | static void | |
13315 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13316 | struct symtabs_and_lines *sals) | |
13317 | { | |
13318 | *sals = parse_probes (s, NULL); | |
13319 | if (!sals->sals) | |
13320 | error (_("probe not found")); | |
13321 | } | |
13322 | ||
348d480f | 13323 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13324 | |
348d480f PA |
13325 | static void |
13326 | tracepoint_re_set (struct breakpoint *b) | |
13327 | { | |
13328 | breakpoint_re_set_default (b); | |
13329 | } | |
876fa593 | 13330 | |
348d480f PA |
13331 | static int |
13332 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13333 | struct address_space *aspace, CORE_ADDR bp_addr, |
13334 | const struct target_waitstatus *ws) | |
348d480f PA |
13335 | { |
13336 | /* By definition, the inferior does not report stops at | |
13337 | tracepoints. */ | |
13338 | return 0; | |
74960c60 VP |
13339 | } |
13340 | ||
13341 | static void | |
348d480f PA |
13342 | tracepoint_print_one_detail (const struct breakpoint *self, |
13343 | struct ui_out *uiout) | |
74960c60 | 13344 | { |
d9b3f62e PA |
13345 | struct tracepoint *tp = (struct tracepoint *) self; |
13346 | if (tp->static_trace_marker_id) | |
348d480f PA |
13347 | { |
13348 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13349 | |
348d480f PA |
13350 | ui_out_text (uiout, "\tmarker id is "); |
13351 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13352 | tp->static_trace_marker_id); |
348d480f PA |
13353 | ui_out_text (uiout, "\n"); |
13354 | } | |
0d381245 VP |
13355 | } |
13356 | ||
a474d7c2 | 13357 | static void |
348d480f | 13358 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13359 | { |
79a45e25 | 13360 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13361 | return; |
cc59ec59 | 13362 | |
348d480f PA |
13363 | switch (b->type) |
13364 | { | |
13365 | case bp_tracepoint: | |
13366 | printf_filtered (_("Tracepoint")); | |
13367 | printf_filtered (_(" %d"), b->number); | |
13368 | break; | |
13369 | case bp_fast_tracepoint: | |
13370 | printf_filtered (_("Fast tracepoint")); | |
13371 | printf_filtered (_(" %d"), b->number); | |
13372 | break; | |
13373 | case bp_static_tracepoint: | |
13374 | printf_filtered (_("Static tracepoint")); | |
13375 | printf_filtered (_(" %d"), b->number); | |
13376 | break; | |
13377 | default: | |
13378 | internal_error (__FILE__, __LINE__, | |
13379 | _("unhandled tracepoint type %d"), (int) b->type); | |
13380 | } | |
13381 | ||
13382 | say_where (b); | |
a474d7c2 PA |
13383 | } |
13384 | ||
348d480f | 13385 | static void |
d9b3f62e | 13386 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13387 | { |
d9b3f62e PA |
13388 | struct tracepoint *tp = (struct tracepoint *) self; |
13389 | ||
13390 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13391 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13392 | if (self->type == bp_static_tracepoint) |
348d480f | 13393 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13394 | else if (self->type == bp_tracepoint) |
348d480f PA |
13395 | fprintf_unfiltered (fp, "trace"); |
13396 | else | |
13397 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13398 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13399 | |
d9b3f62e PA |
13400 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13401 | print_recreate_thread (self, fp); | |
13402 | ||
13403 | if (tp->pass_count) | |
13404 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13405 | } |
13406 | ||
983af33b SDJ |
13407 | static void |
13408 | tracepoint_create_sals_from_address (char **arg, | |
13409 | struct linespec_result *canonical, | |
13410 | enum bptype type_wanted, | |
13411 | char *addr_start, char **copy_arg) | |
13412 | { | |
13413 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13414 | addr_start, copy_arg); | |
13415 | } | |
13416 | ||
13417 | static void | |
13418 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13419 | struct linespec_result *canonical, | |
983af33b | 13420 | char *cond_string, |
e7e0cddf | 13421 | char *extra_string, |
983af33b SDJ |
13422 | enum bptype type_wanted, |
13423 | enum bpdisp disposition, | |
13424 | int thread, | |
13425 | int task, int ignore_count, | |
13426 | const struct breakpoint_ops *ops, | |
13427 | int from_tty, int enabled, | |
44f238bb | 13428 | int internal, unsigned flags) |
983af33b | 13429 | { |
023fa29b | 13430 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13431 | cond_string, extra_string, |
13432 | type_wanted, | |
983af33b SDJ |
13433 | disposition, thread, task, |
13434 | ignore_count, ops, from_tty, | |
44f238bb | 13435 | enabled, internal, flags); |
983af33b SDJ |
13436 | } |
13437 | ||
13438 | static void | |
13439 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13440 | struct symtabs_and_lines *sals) | |
13441 | { | |
13442 | decode_linespec_default (b, s, sals); | |
13443 | } | |
13444 | ||
2060206e | 13445 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13446 | |
55aa24fb SDJ |
13447 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13448 | static probe. */ | |
13449 | ||
13450 | static void | |
13451 | tracepoint_probe_create_sals_from_address (char **arg, | |
13452 | struct linespec_result *canonical, | |
13453 | enum bptype type_wanted, | |
13454 | char *addr_start, char **copy_arg) | |
13455 | { | |
13456 | /* We use the same method for breakpoint on probes. */ | |
13457 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13458 | addr_start, copy_arg); | |
13459 | } | |
13460 | ||
13461 | static void | |
13462 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13463 | struct symtabs_and_lines *sals) | |
13464 | { | |
13465 | /* We use the same method for breakpoint on probes. */ | |
13466 | bkpt_probe_decode_linespec (b, s, sals); | |
13467 | } | |
13468 | ||
13469 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13470 | ||
5c2b4418 HZ |
13471 | /* Dprintf breakpoint_ops methods. */ |
13472 | ||
13473 | static void | |
13474 | dprintf_re_set (struct breakpoint *b) | |
13475 | { | |
13476 | breakpoint_re_set_default (b); | |
13477 | ||
13478 | /* This breakpoint could have been pending, and be resolved now, and | |
13479 | if so, we should now have the extra string. If we don't, the | |
13480 | dprintf was malformed when created, but we couldn't tell because | |
13481 | we can't extract the extra string until the location is | |
13482 | resolved. */ | |
13483 | if (b->loc != NULL && b->extra_string == NULL) | |
13484 | error (_("Format string required")); | |
13485 | ||
13486 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13487 | 2 - create a dprintf, which resolves fine. | |
13488 | 3 - disconnect from target 1 | |
13489 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13490 | ||
13491 | After steps #3/#4, you'll want the dprintf command list to | |
13492 | be updated, because target 1 and 2 may well return different | |
13493 | answers for target_can_run_breakpoint_commands(). | |
13494 | Given absence of finer grained resetting, we get to do | |
13495 | it all the time. */ | |
13496 | if (b->extra_string != NULL) | |
13497 | update_dprintf_command_list (b); | |
13498 | } | |
13499 | ||
2d9442cc HZ |
13500 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13501 | ||
13502 | static void | |
13503 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13504 | { | |
13505 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13506 | tp->extra_string); | |
13507 | print_recreate_thread (tp, fp); | |
13508 | } | |
13509 | ||
9d6e6e84 HZ |
13510 | /* Implement the "after_condition_true" breakpoint_ops method for |
13511 | dprintf. | |
13512 | ||
13513 | dprintf's are implemented with regular commands in their command | |
13514 | list, but we run the commands here instead of before presenting the | |
13515 | stop to the user, as dprintf's don't actually cause a stop. This | |
13516 | also makes it so that the commands of multiple dprintfs at the same | |
13517 | address are all handled. */ | |
13518 | ||
13519 | static void | |
13520 | dprintf_after_condition_true (struct bpstats *bs) | |
13521 | { | |
13522 | struct cleanup *old_chain; | |
13523 | struct bpstats tmp_bs = { NULL }; | |
13524 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13525 | ||
13526 | /* dprintf's never cause a stop. This wasn't set in the | |
13527 | check_status hook instead because that would make the dprintf's | |
13528 | condition not be evaluated. */ | |
13529 | bs->stop = 0; | |
13530 | ||
13531 | /* Run the command list here. Take ownership of it instead of | |
13532 | copying. We never want these commands to run later in | |
13533 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13534 | be set at same address as this dprintf, or even if running the | |
13535 | commands here throws. */ | |
13536 | tmp_bs.commands = bs->commands; | |
13537 | bs->commands = NULL; | |
13538 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13539 | ||
13540 | bpstat_do_actions_1 (&tmp_bs_p); | |
13541 | ||
13542 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13543 | bpstat_do_actions_1 may return early without processing the whole | |
13544 | list. */ | |
13545 | do_cleanups (old_chain); | |
13546 | } | |
13547 | ||
983af33b SDJ |
13548 | /* The breakpoint_ops structure to be used on static tracepoints with |
13549 | markers (`-m'). */ | |
13550 | ||
13551 | static void | |
13552 | strace_marker_create_sals_from_address (char **arg, | |
13553 | struct linespec_result *canonical, | |
13554 | enum bptype type_wanted, | |
13555 | char *addr_start, char **copy_arg) | |
13556 | { | |
13557 | struct linespec_sals lsal; | |
13558 | ||
13559 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13560 | ||
13561 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13562 | ||
13563 | canonical->addr_string = xstrdup (*copy_arg); | |
13564 | lsal.canonical = xstrdup (*copy_arg); | |
13565 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13566 | } | |
13567 | ||
13568 | static void | |
13569 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13570 | struct linespec_result *canonical, | |
983af33b | 13571 | char *cond_string, |
e7e0cddf | 13572 | char *extra_string, |
983af33b SDJ |
13573 | enum bptype type_wanted, |
13574 | enum bpdisp disposition, | |
13575 | int thread, | |
13576 | int task, int ignore_count, | |
13577 | const struct breakpoint_ops *ops, | |
13578 | int from_tty, int enabled, | |
44f238bb | 13579 | int internal, unsigned flags) |
983af33b SDJ |
13580 | { |
13581 | int i; | |
52d361e1 YQ |
13582 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13583 | canonical->sals, 0); | |
983af33b SDJ |
13584 | |
13585 | /* If the user is creating a static tracepoint by marker id | |
13586 | (strace -m MARKER_ID), then store the sals index, so that | |
13587 | breakpoint_re_set can try to match up which of the newly | |
13588 | found markers corresponds to this one, and, don't try to | |
13589 | expand multiple locations for each sal, given than SALS | |
13590 | already should contain all sals for MARKER_ID. */ | |
13591 | ||
13592 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13593 | { | |
13594 | struct symtabs_and_lines expanded; | |
13595 | struct tracepoint *tp; | |
13596 | struct cleanup *old_chain; | |
13597 | char *addr_string; | |
13598 | ||
13599 | expanded.nelts = 1; | |
13600 | expanded.sals = &lsal->sals.sals[i]; | |
13601 | ||
13602 | addr_string = xstrdup (canonical->addr_string); | |
13603 | old_chain = make_cleanup (xfree, addr_string); | |
13604 | ||
13605 | tp = XCNEW (struct tracepoint); | |
13606 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13607 | addr_string, NULL, | |
e7e0cddf SS |
13608 | cond_string, extra_string, |
13609 | type_wanted, disposition, | |
983af33b | 13610 | thread, task, ignore_count, ops, |
44f238bb | 13611 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13612 | canonical->special_display); |
13613 | /* Given that its possible to have multiple markers with | |
13614 | the same string id, if the user is creating a static | |
13615 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13616 | store the sals index, so that breakpoint_re_set can | |
13617 | try to match up which of the newly found markers | |
13618 | corresponds to this one */ | |
13619 | tp->static_trace_marker_id_idx = i; | |
13620 | ||
13621 | install_breakpoint (internal, &tp->base, 0); | |
13622 | ||
13623 | discard_cleanups (old_chain); | |
13624 | } | |
13625 | } | |
13626 | ||
13627 | static void | |
13628 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13629 | struct symtabs_and_lines *sals) | |
13630 | { | |
13631 | struct tracepoint *tp = (struct tracepoint *) b; | |
13632 | ||
13633 | *sals = decode_static_tracepoint_spec (s); | |
13634 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13635 | { | |
13636 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13637 | sals->nelts = 1; | |
13638 | } | |
13639 | else | |
13640 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13641 | } | |
13642 | ||
13643 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13644 | ||
13645 | static int | |
13646 | strace_marker_p (struct breakpoint *b) | |
13647 | { | |
13648 | return b->ops == &strace_marker_breakpoint_ops; | |
13649 | } | |
13650 | ||
53a5351d | 13651 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13652 | structures. */ |
c906108c SS |
13653 | |
13654 | void | |
fba45db2 | 13655 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13656 | { |
52f0bd74 | 13657 | struct breakpoint *b; |
c906108c | 13658 | |
8a3fe4f8 | 13659 | gdb_assert (bpt != NULL); |
c906108c | 13660 | |
4a64f543 MS |
13661 | /* Has this bp already been deleted? This can happen because |
13662 | multiple lists can hold pointers to bp's. bpstat lists are | |
13663 | especial culprits. | |
13664 | ||
13665 | One example of this happening is a watchpoint's scope bp. When | |
13666 | the scope bp triggers, we notice that the watchpoint is out of | |
13667 | scope, and delete it. We also delete its scope bp. But the | |
13668 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13669 | That bpstat is then checked for auto-deleting bp's, which are | |
13670 | deleted. | |
13671 | ||
13672 | A real solution to this problem might involve reference counts in | |
13673 | bp's, and/or giving them pointers back to their referencing | |
13674 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13675 | storage when no more references were extent. A cheaper bandaid | |
13676 | was chosen. */ | |
c906108c SS |
13677 | if (bpt->type == bp_none) |
13678 | return; | |
13679 | ||
4a64f543 MS |
13680 | /* At least avoid this stale reference until the reference counting |
13681 | of breakpoints gets resolved. */ | |
d0fb5eae | 13682 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13683 | { |
d0fb5eae | 13684 | struct breakpoint *related; |
3a5c3e22 | 13685 | struct watchpoint *w; |
d0fb5eae JK |
13686 | |
13687 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13688 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13689 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13690 | w = (struct watchpoint *) bpt; |
13691 | else | |
13692 | w = NULL; | |
13693 | if (w != NULL) | |
13694 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13695 | |
13696 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13697 | for (related = bpt; related->related_breakpoint != bpt; | |
13698 | related = related->related_breakpoint); | |
13699 | related->related_breakpoint = bpt->related_breakpoint; | |
13700 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13701 | } |
13702 | ||
a9634178 TJB |
13703 | /* watch_command_1 creates a watchpoint but only sets its number if |
13704 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13705 | a problem in that process, we'll be asked to delete the half-created | |
13706 | watchpoint. In that case, don't announce the deletion. */ | |
13707 | if (bpt->number) | |
13708 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13709 | |
c906108c SS |
13710 | if (breakpoint_chain == bpt) |
13711 | breakpoint_chain = bpt->next; | |
13712 | ||
c906108c SS |
13713 | ALL_BREAKPOINTS (b) |
13714 | if (b->next == bpt) | |
c5aa993b JM |
13715 | { |
13716 | b->next = bpt->next; | |
13717 | break; | |
13718 | } | |
c906108c | 13719 | |
f431efe5 PA |
13720 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13721 | been freed. */ | |
13722 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13723 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13724 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13725 | commands are associated with the bpstat; if we remove it here, | |
13726 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13727 | event-top.c won't do anything, and temporary breakpoints with | |
13728 | commands won't work. */ | |
13729 | ||
13730 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13731 | ||
4a64f543 MS |
13732 | /* Now that breakpoint is removed from breakpoint list, update the |
13733 | global location list. This will remove locations that used to | |
13734 | belong to this breakpoint. Do this before freeing the breakpoint | |
13735 | itself, since remove_breakpoint looks at location's owner. It | |
13736 | might be better design to have location completely | |
13737 | self-contained, but it's not the case now. */ | |
b60e7edf | 13738 | update_global_location_list (0); |
74960c60 | 13739 | |
348d480f | 13740 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13741 | /* On the chance that someone will soon try again to delete this |
13742 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13743 | bpt->type = bp_none; |
b8c9b27d | 13744 | xfree (bpt); |
c906108c SS |
13745 | } |
13746 | ||
4d6140d9 AC |
13747 | static void |
13748 | do_delete_breakpoint_cleanup (void *b) | |
13749 | { | |
13750 | delete_breakpoint (b); | |
13751 | } | |
13752 | ||
13753 | struct cleanup * | |
13754 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13755 | { | |
13756 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13757 | } | |
13758 | ||
51be5b68 PA |
13759 | /* Iterator function to call a user-provided callback function once |
13760 | for each of B and its related breakpoints. */ | |
13761 | ||
13762 | static void | |
13763 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13764 | void (*function) (struct breakpoint *, | |
13765 | void *), | |
13766 | void *data) | |
13767 | { | |
13768 | struct breakpoint *related; | |
13769 | ||
13770 | related = b; | |
13771 | do | |
13772 | { | |
13773 | struct breakpoint *next; | |
13774 | ||
13775 | /* FUNCTION may delete RELATED. */ | |
13776 | next = related->related_breakpoint; | |
13777 | ||
13778 | if (next == related) | |
13779 | { | |
13780 | /* RELATED is the last ring entry. */ | |
13781 | function (related, data); | |
13782 | ||
13783 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13784 | B. There's nothing left to do anyway, so just break | |
13785 | out. */ | |
13786 | break; | |
13787 | } | |
13788 | else | |
13789 | function (related, data); | |
13790 | ||
13791 | related = next; | |
13792 | } | |
13793 | while (related != b); | |
13794 | } | |
95a42b64 TT |
13795 | |
13796 | static void | |
13797 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13798 | { | |
13799 | delete_breakpoint (b); | |
13800 | } | |
13801 | ||
51be5b68 PA |
13802 | /* A callback for map_breakpoint_numbers that calls |
13803 | delete_breakpoint. */ | |
13804 | ||
13805 | static void | |
13806 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13807 | { | |
13808 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13809 | } | |
13810 | ||
c906108c | 13811 | void |
fba45db2 | 13812 | delete_command (char *arg, int from_tty) |
c906108c | 13813 | { |
35df4500 | 13814 | struct breakpoint *b, *b_tmp; |
c906108c | 13815 | |
ea9365bb TT |
13816 | dont_repeat (); |
13817 | ||
c906108c SS |
13818 | if (arg == 0) |
13819 | { | |
13820 | int breaks_to_delete = 0; | |
13821 | ||
46c6471b PA |
13822 | /* Delete all breakpoints if no argument. Do not delete |
13823 | internal breakpoints, these have to be deleted with an | |
13824 | explicit breakpoint number argument. */ | |
c5aa993b | 13825 | ALL_BREAKPOINTS (b) |
46c6471b | 13826 | if (user_breakpoint_p (b)) |
973d738b DJ |
13827 | { |
13828 | breaks_to_delete = 1; | |
13829 | break; | |
13830 | } | |
c906108c SS |
13831 | |
13832 | /* Ask user only if there are some breakpoints to delete. */ | |
13833 | if (!from_tty | |
e2e0b3e5 | 13834 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13835 | { |
35df4500 | 13836 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13837 | if (user_breakpoint_p (b)) |
c5aa993b | 13838 | delete_breakpoint (b); |
c906108c SS |
13839 | } |
13840 | } | |
13841 | else | |
51be5b68 | 13842 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13843 | } |
13844 | ||
0d381245 VP |
13845 | static int |
13846 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13847 | { |
0d381245 | 13848 | for (; loc; loc = loc->next) |
8645ff69 UW |
13849 | if (!loc->shlib_disabled |
13850 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13851 | return 0; |
13852 | return 1; | |
fe3f5fa8 VP |
13853 | } |
13854 | ||
776592bf DE |
13855 | /* Subroutine of update_breakpoint_locations to simplify it. |
13856 | Return non-zero if multiple fns in list LOC have the same name. | |
13857 | Null names are ignored. */ | |
13858 | ||
13859 | static int | |
13860 | ambiguous_names_p (struct bp_location *loc) | |
13861 | { | |
13862 | struct bp_location *l; | |
13863 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13864 | (int (*) (const void *, |
13865 | const void *)) streq, | |
776592bf DE |
13866 | NULL, xcalloc, xfree); |
13867 | ||
13868 | for (l = loc; l != NULL; l = l->next) | |
13869 | { | |
13870 | const char **slot; | |
13871 | const char *name = l->function_name; | |
13872 | ||
13873 | /* Allow for some names to be NULL, ignore them. */ | |
13874 | if (name == NULL) | |
13875 | continue; | |
13876 | ||
13877 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13878 | INSERT); | |
4a64f543 MS |
13879 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13880 | returns NULL. */ | |
776592bf DE |
13881 | if (*slot != NULL) |
13882 | { | |
13883 | htab_delete (htab); | |
13884 | return 1; | |
13885 | } | |
13886 | *slot = name; | |
13887 | } | |
13888 | ||
13889 | htab_delete (htab); | |
13890 | return 0; | |
13891 | } | |
13892 | ||
0fb4aa4b PA |
13893 | /* When symbols change, it probably means the sources changed as well, |
13894 | and it might mean the static tracepoint markers are no longer at | |
13895 | the same address or line numbers they used to be at last we | |
13896 | checked. Losing your static tracepoints whenever you rebuild is | |
13897 | undesirable. This function tries to resync/rematch gdb static | |
13898 | tracepoints with the markers on the target, for static tracepoints | |
13899 | that have not been set by marker id. Static tracepoint that have | |
13900 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13901 | The heuristic is: | |
13902 | ||
13903 | 1) For a tracepoint set at a specific address, look for a marker at | |
13904 | the old PC. If one is found there, assume to be the same marker. | |
13905 | If the name / string id of the marker found is different from the | |
13906 | previous known name, assume that means the user renamed the marker | |
13907 | in the sources, and output a warning. | |
13908 | ||
13909 | 2) For a tracepoint set at a given line number, look for a marker | |
13910 | at the new address of the old line number. If one is found there, | |
13911 | assume to be the same marker. If the name / string id of the | |
13912 | marker found is different from the previous known name, assume that | |
13913 | means the user renamed the marker in the sources, and output a | |
13914 | warning. | |
13915 | ||
13916 | 3) If a marker is no longer found at the same address or line, it | |
13917 | may mean the marker no longer exists. But it may also just mean | |
13918 | the code changed a bit. Maybe the user added a few lines of code | |
13919 | that made the marker move up or down (in line number terms). Ask | |
13920 | the target for info about the marker with the string id as we knew | |
13921 | it. If found, update line number and address in the matching | |
13922 | static tracepoint. This will get confused if there's more than one | |
13923 | marker with the same ID (possible in UST, although unadvised | |
13924 | precisely because it confuses tools). */ | |
13925 | ||
13926 | static struct symtab_and_line | |
13927 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13928 | { | |
d9b3f62e | 13929 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13930 | struct static_tracepoint_marker marker; |
13931 | CORE_ADDR pc; | |
0fb4aa4b PA |
13932 | |
13933 | pc = sal.pc; | |
13934 | if (sal.line) | |
13935 | find_line_pc (sal.symtab, sal.line, &pc); | |
13936 | ||
13937 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13938 | { | |
d9b3f62e | 13939 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13940 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13941 | b->number, | |
d9b3f62e | 13942 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13943 | |
d9b3f62e PA |
13944 | xfree (tp->static_trace_marker_id); |
13945 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13946 | release_static_tracepoint_marker (&marker); |
13947 | ||
13948 | return sal; | |
13949 | } | |
13950 | ||
13951 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13952 | by string ID. */ | |
13953 | if (!sal.explicit_pc | |
13954 | && sal.line != 0 | |
13955 | && sal.symtab != NULL | |
d9b3f62e | 13956 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13957 | { |
13958 | VEC(static_tracepoint_marker_p) *markers; | |
13959 | ||
13960 | markers | |
d9b3f62e | 13961 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13962 | |
13963 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13964 | { | |
80e1d417 | 13965 | struct symtab_and_line sal2; |
0fb4aa4b | 13966 | struct symbol *sym; |
80e1d417 | 13967 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13968 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 13969 | |
80e1d417 | 13970 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13971 | |
d9b3f62e | 13972 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13973 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13974 | |
13975 | warning (_("marker for static tracepoint %d (%s) not " | |
13976 | "found at previous line number"), | |
d9b3f62e | 13977 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13978 | |
80e1d417 | 13979 | init_sal (&sal2); |
0fb4aa4b | 13980 | |
80e1d417 | 13981 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13982 | |
80e1d417 AS |
13983 | sal2 = find_pc_line (tpmarker->address, 0); |
13984 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13985 | ui_out_text (uiout, "Now in "); |
13986 | if (sym) | |
13987 | { | |
13988 | ui_out_field_string (uiout, "func", | |
13989 | SYMBOL_PRINT_NAME (sym)); | |
13990 | ui_out_text (uiout, " at "); | |
13991 | } | |
05cba821 JK |
13992 | ui_out_field_string (uiout, "file", |
13993 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
13994 | ui_out_text (uiout, ":"); |
13995 | ||
13996 | if (ui_out_is_mi_like_p (uiout)) | |
13997 | { | |
0b0865da | 13998 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13999 | |
f35a17b5 | 14000 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14001 | } |
14002 | ||
80e1d417 | 14003 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14004 | ui_out_text (uiout, "\n"); |
14005 | ||
80e1d417 | 14006 | b->loc->line_number = sal2.line; |
2f202fde | 14007 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14008 | |
14009 | xfree (b->addr_string); | |
14010 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14011 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14012 | b->loc->line_number); |
0fb4aa4b PA |
14013 | |
14014 | /* Might be nice to check if function changed, and warn if | |
14015 | so. */ | |
14016 | ||
80e1d417 | 14017 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14018 | } |
14019 | } | |
14020 | return sal; | |
14021 | } | |
14022 | ||
8d3788bd VP |
14023 | /* Returns 1 iff locations A and B are sufficiently same that |
14024 | we don't need to report breakpoint as changed. */ | |
14025 | ||
14026 | static int | |
14027 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14028 | { | |
14029 | while (a && b) | |
14030 | { | |
14031 | if (a->address != b->address) | |
14032 | return 0; | |
14033 | ||
14034 | if (a->shlib_disabled != b->shlib_disabled) | |
14035 | return 0; | |
14036 | ||
14037 | if (a->enabled != b->enabled) | |
14038 | return 0; | |
14039 | ||
14040 | a = a->next; | |
14041 | b = b->next; | |
14042 | } | |
14043 | ||
14044 | if ((a == NULL) != (b == NULL)) | |
14045 | return 0; | |
14046 | ||
14047 | return 1; | |
14048 | } | |
14049 | ||
f1310107 TJB |
14050 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14051 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14052 | a ranged breakpoint. */ | |
14053 | ||
0e30163f | 14054 | void |
0d381245 | 14055 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14056 | struct symtabs_and_lines sals, |
14057 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14058 | { |
14059 | int i; | |
0d381245 VP |
14060 | struct bp_location *existing_locations = b->loc; |
14061 | ||
f8eba3c6 TT |
14062 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14063 | { | |
14064 | /* Ranged breakpoints have only one start location and one end | |
14065 | location. */ | |
14066 | b->enable_state = bp_disabled; | |
14067 | update_global_location_list (1); | |
14068 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14069 | "multiple locations found\n"), | |
14070 | b->number); | |
14071 | return; | |
14072 | } | |
f1310107 | 14073 | |
4a64f543 MS |
14074 | /* If there's no new locations, and all existing locations are |
14075 | pending, don't do anything. This optimizes the common case where | |
14076 | all locations are in the same shared library, that was unloaded. | |
14077 | We'd like to retain the location, so that when the library is | |
14078 | loaded again, we don't loose the enabled/disabled status of the | |
14079 | individual locations. */ | |
0d381245 | 14080 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14081 | return; |
14082 | ||
fe3f5fa8 VP |
14083 | b->loc = NULL; |
14084 | ||
0d381245 | 14085 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14086 | { |
f8eba3c6 TT |
14087 | struct bp_location *new_loc; |
14088 | ||
14089 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14090 | ||
14091 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14092 | |
0d381245 VP |
14093 | /* Reparse conditions, they might contain references to the |
14094 | old symtab. */ | |
14095 | if (b->cond_string != NULL) | |
14096 | { | |
bbc13ae3 | 14097 | const char *s; |
bfd189b1 | 14098 | volatile struct gdb_exception e; |
fe3f5fa8 | 14099 | |
0d381245 VP |
14100 | s = b->cond_string; |
14101 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14102 | { | |
1bb9788d TT |
14103 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14104 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14105 | 0); |
14106 | } | |
14107 | if (e.reason < 0) | |
14108 | { | |
3e43a32a MS |
14109 | warning (_("failed to reevaluate condition " |
14110 | "for breakpoint %d: %s"), | |
0d381245 VP |
14111 | b->number, e.message); |
14112 | new_loc->enabled = 0; | |
14113 | } | |
14114 | } | |
fe3f5fa8 | 14115 | |
f1310107 TJB |
14116 | if (sals_end.nelts) |
14117 | { | |
14118 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14119 | ||
14120 | new_loc->length = end - sals.sals[0].pc + 1; | |
14121 | } | |
0d381245 | 14122 | } |
fe3f5fa8 | 14123 | |
514f746b AR |
14124 | /* Update locations of permanent breakpoints. */ |
14125 | if (b->enable_state == bp_permanent) | |
14126 | make_breakpoint_permanent (b); | |
14127 | ||
4a64f543 MS |
14128 | /* If possible, carry over 'disable' status from existing |
14129 | breakpoints. */ | |
0d381245 VP |
14130 | { |
14131 | struct bp_location *e = existing_locations; | |
776592bf DE |
14132 | /* If there are multiple breakpoints with the same function name, |
14133 | e.g. for inline functions, comparing function names won't work. | |
14134 | Instead compare pc addresses; this is just a heuristic as things | |
14135 | may have moved, but in practice it gives the correct answer | |
14136 | often enough until a better solution is found. */ | |
14137 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14138 | ||
0d381245 VP |
14139 | for (; e; e = e->next) |
14140 | { | |
14141 | if (!e->enabled && e->function_name) | |
14142 | { | |
14143 | struct bp_location *l = b->loc; | |
776592bf DE |
14144 | if (have_ambiguous_names) |
14145 | { | |
14146 | for (; l; l = l->next) | |
f1310107 | 14147 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14148 | { |
14149 | l->enabled = 0; | |
14150 | break; | |
14151 | } | |
14152 | } | |
14153 | else | |
14154 | { | |
14155 | for (; l; l = l->next) | |
14156 | if (l->function_name | |
14157 | && strcmp (e->function_name, l->function_name) == 0) | |
14158 | { | |
14159 | l->enabled = 0; | |
14160 | break; | |
14161 | } | |
14162 | } | |
0d381245 VP |
14163 | } |
14164 | } | |
14165 | } | |
fe3f5fa8 | 14166 | |
8d3788bd VP |
14167 | if (!locations_are_equal (existing_locations, b->loc)) |
14168 | observer_notify_breakpoint_modified (b); | |
14169 | ||
b60e7edf | 14170 | update_global_location_list (1); |
fe3f5fa8 VP |
14171 | } |
14172 | ||
ef23e705 TJB |
14173 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14174 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14175 | ||
14176 | static struct symtabs_and_lines | |
14177 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14178 | { | |
14179 | char *s; | |
02d20e4a | 14180 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14181 | volatile struct gdb_exception e; |
ef23e705 | 14182 | |
983af33b | 14183 | gdb_assert (b->ops != NULL); |
ef23e705 | 14184 | s = addr_string; |
ef23e705 TJB |
14185 | |
14186 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14187 | { | |
983af33b | 14188 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14189 | } |
14190 | if (e.reason < 0) | |
14191 | { | |
14192 | int not_found_and_ok = 0; | |
14193 | /* For pending breakpoints, it's expected that parsing will | |
14194 | fail until the right shared library is loaded. User has | |
14195 | already told to create pending breakpoints and don't need | |
14196 | extra messages. If breakpoint is in bp_shlib_disabled | |
14197 | state, then user already saw the message about that | |
14198 | breakpoint being disabled, and don't want to see more | |
14199 | errors. */ | |
58438ac1 | 14200 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14201 | && (b->condition_not_parsed |
14202 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14203 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14204 | || b->enable_state == bp_disabled)) |
14205 | not_found_and_ok = 1; | |
14206 | ||
14207 | if (!not_found_and_ok) | |
14208 | { | |
14209 | /* We surely don't want to warn about the same breakpoint | |
14210 | 10 times. One solution, implemented here, is disable | |
14211 | the breakpoint on error. Another solution would be to | |
14212 | have separate 'warning emitted' flag. Since this | |
14213 | happens only when a binary has changed, I don't know | |
14214 | which approach is better. */ | |
14215 | b->enable_state = bp_disabled; | |
14216 | throw_exception (e); | |
14217 | } | |
14218 | } | |
14219 | ||
58438ac1 | 14220 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14221 | { |
f8eba3c6 | 14222 | int i; |
ef23e705 | 14223 | |
f8eba3c6 TT |
14224 | for (i = 0; i < sals.nelts; ++i) |
14225 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14226 | if (b->condition_not_parsed && s && s[0]) |
14227 | { | |
ed1d1739 KS |
14228 | char *cond_string, *extra_string; |
14229 | int thread, task; | |
ef23e705 TJB |
14230 | |
14231 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14232 | &cond_string, &thread, &task, |
14233 | &extra_string); | |
ef23e705 TJB |
14234 | if (cond_string) |
14235 | b->cond_string = cond_string; | |
14236 | b->thread = thread; | |
14237 | b->task = task; | |
e7e0cddf SS |
14238 | if (extra_string) |
14239 | b->extra_string = extra_string; | |
ef23e705 TJB |
14240 | b->condition_not_parsed = 0; |
14241 | } | |
14242 | ||
983af33b | 14243 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14244 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14245 | |
58438ac1 TT |
14246 | *found = 1; |
14247 | } | |
14248 | else | |
14249 | *found = 0; | |
ef23e705 TJB |
14250 | |
14251 | return sals; | |
14252 | } | |
14253 | ||
348d480f PA |
14254 | /* The default re_set method, for typical hardware or software |
14255 | breakpoints. Reevaluate the breakpoint and recreate its | |
14256 | locations. */ | |
14257 | ||
14258 | static void | |
28010a5d | 14259 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14260 | { |
14261 | int found; | |
f1310107 | 14262 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14263 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14264 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14265 | |
14266 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14267 | if (found) | |
14268 | { | |
14269 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14270 | expanded = sals; |
ef23e705 TJB |
14271 | } |
14272 | ||
f1310107 TJB |
14273 | if (b->addr_string_range_end) |
14274 | { | |
14275 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14276 | if (found) | |
14277 | { | |
14278 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14279 | expanded_end = sals_end; |
f1310107 TJB |
14280 | } |
14281 | } | |
14282 | ||
14283 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14284 | } |
14285 | ||
983af33b SDJ |
14286 | /* Default method for creating SALs from an address string. It basically |
14287 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14288 | ||
14289 | static void | |
14290 | create_sals_from_address_default (char **arg, | |
14291 | struct linespec_result *canonical, | |
14292 | enum bptype type_wanted, | |
14293 | char *addr_start, char **copy_arg) | |
14294 | { | |
14295 | parse_breakpoint_sals (arg, canonical); | |
14296 | } | |
14297 | ||
14298 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14299 | function for the `create_breakpoints_sal' method of | |
14300 | breakpoint_ops. */ | |
14301 | ||
14302 | static void | |
14303 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14304 | struct linespec_result *canonical, | |
983af33b | 14305 | char *cond_string, |
e7e0cddf | 14306 | char *extra_string, |
983af33b SDJ |
14307 | enum bptype type_wanted, |
14308 | enum bpdisp disposition, | |
14309 | int thread, | |
14310 | int task, int ignore_count, | |
14311 | const struct breakpoint_ops *ops, | |
14312 | int from_tty, int enabled, | |
44f238bb | 14313 | int internal, unsigned flags) |
983af33b SDJ |
14314 | { |
14315 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14316 | extra_string, |
983af33b SDJ |
14317 | type_wanted, disposition, |
14318 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14319 | enabled, internal, flags); |
983af33b SDJ |
14320 | } |
14321 | ||
14322 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14323 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14324 | ||
14325 | static void | |
14326 | decode_linespec_default (struct breakpoint *b, char **s, | |
14327 | struct symtabs_and_lines *sals) | |
14328 | { | |
14329 | struct linespec_result canonical; | |
14330 | ||
14331 | init_linespec_result (&canonical); | |
14332 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14333 | (struct symtab *) NULL, 0, | |
14334 | &canonical, multiple_symbols_all, | |
14335 | b->filter); | |
14336 | ||
14337 | /* We should get 0 or 1 resulting SALs. */ | |
14338 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14339 | ||
14340 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14341 | { | |
14342 | struct linespec_sals *lsal; | |
14343 | ||
14344 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14345 | *sals = lsal->sals; | |
14346 | /* Arrange it so the destructor does not free the | |
14347 | contents. */ | |
14348 | lsal->sals.sals = NULL; | |
14349 | } | |
14350 | ||
14351 | destroy_linespec_result (&canonical); | |
14352 | } | |
14353 | ||
28010a5d PA |
14354 | /* Prepare the global context for a re-set of breakpoint B. */ |
14355 | ||
14356 | static struct cleanup * | |
14357 | prepare_re_set_context (struct breakpoint *b) | |
14358 | { | |
14359 | struct cleanup *cleanups; | |
14360 | ||
14361 | input_radix = b->input_radix; | |
14362 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14363 | if (b->pspace != NULL) |
14364 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14365 | set_language (b->language); |
14366 | ||
14367 | return cleanups; | |
ef23e705 TJB |
14368 | } |
14369 | ||
c906108c SS |
14370 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14371 | The value we return ends up being the return value from catch_errors. | |
14372 | Unused in this case. */ | |
14373 | ||
14374 | static int | |
4efb68b1 | 14375 | breakpoint_re_set_one (void *bint) |
c906108c | 14376 | { |
4a64f543 | 14377 | /* Get past catch_errs. */ |
53a5351d | 14378 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14379 | struct cleanup *cleanups; |
c906108c | 14380 | |
348d480f PA |
14381 | cleanups = prepare_re_set_context (b); |
14382 | b->ops->re_set (b); | |
14383 | do_cleanups (cleanups); | |
c906108c SS |
14384 | return 0; |
14385 | } | |
14386 | ||
69de3c6a | 14387 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14388 | void |
69de3c6a | 14389 | breakpoint_re_set (void) |
c906108c | 14390 | { |
35df4500 | 14391 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14392 | enum language save_language; |
14393 | int save_input_radix; | |
6c95b8df | 14394 | struct cleanup *old_chain; |
c5aa993b | 14395 | |
c906108c SS |
14396 | save_language = current_language->la_language; |
14397 | save_input_radix = input_radix; | |
6c95b8df PA |
14398 | old_chain = save_current_program_space (); |
14399 | ||
35df4500 | 14400 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14401 | { |
4a64f543 | 14402 | /* Format possible error msg. */ |
fe3f5fa8 | 14403 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14404 | b->number); |
14405 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14406 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14407 | do_cleanups (cleanups); |
c5aa993b | 14408 | } |
c906108c SS |
14409 | set_language (save_language); |
14410 | input_radix = save_input_radix; | |
e62c965a | 14411 | |
0756c555 | 14412 | jit_breakpoint_re_set (); |
4efc6507 | 14413 | |
6c95b8df PA |
14414 | do_cleanups (old_chain); |
14415 | ||
af02033e PP |
14416 | create_overlay_event_breakpoint (); |
14417 | create_longjmp_master_breakpoint (); | |
14418 | create_std_terminate_master_breakpoint (); | |
186c406b | 14419 | create_exception_master_breakpoint (); |
c906108c SS |
14420 | } |
14421 | \f | |
c906108c SS |
14422 | /* Reset the thread number of this breakpoint: |
14423 | ||
14424 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14425 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14426 | void |
fba45db2 | 14427 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14428 | { |
14429 | if (b->thread != -1) | |
14430 | { | |
39f77062 KB |
14431 | if (in_thread_list (inferior_ptid)) |
14432 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14433 | |
14434 | /* We're being called after following a fork. The new fork is | |
14435 | selected as current, and unless this was a vfork will have a | |
14436 | different program space from the original thread. Reset that | |
14437 | as well. */ | |
14438 | b->loc->pspace = current_program_space; | |
c906108c SS |
14439 | } |
14440 | } | |
14441 | ||
03ac34d5 MS |
14442 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14443 | If from_tty is nonzero, it prints a message to that effect, | |
14444 | which ends with a period (no newline). */ | |
14445 | ||
c906108c | 14446 | void |
fba45db2 | 14447 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14448 | { |
52f0bd74 | 14449 | struct breakpoint *b; |
c906108c SS |
14450 | |
14451 | if (count < 0) | |
14452 | count = 0; | |
14453 | ||
14454 | ALL_BREAKPOINTS (b) | |
14455 | if (b->number == bptnum) | |
c5aa993b | 14456 | { |
d77f58be SS |
14457 | if (is_tracepoint (b)) |
14458 | { | |
14459 | if (from_tty && count != 0) | |
14460 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14461 | bptnum); | |
14462 | return; | |
14463 | } | |
14464 | ||
c5aa993b | 14465 | b->ignore_count = count; |
221ea385 KS |
14466 | if (from_tty) |
14467 | { | |
14468 | if (count == 0) | |
3e43a32a MS |
14469 | printf_filtered (_("Will stop next time " |
14470 | "breakpoint %d is reached."), | |
221ea385 KS |
14471 | bptnum); |
14472 | else if (count == 1) | |
a3f17187 | 14473 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14474 | bptnum); |
14475 | else | |
3e43a32a MS |
14476 | printf_filtered (_("Will ignore next %d " |
14477 | "crossings of breakpoint %d."), | |
221ea385 KS |
14478 | count, bptnum); |
14479 | } | |
8d3788bd | 14480 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14481 | return; |
14482 | } | |
c906108c | 14483 | |
8a3fe4f8 | 14484 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14485 | } |
14486 | ||
c906108c SS |
14487 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14488 | ||
14489 | static void | |
fba45db2 | 14490 | ignore_command (char *args, int from_tty) |
c906108c SS |
14491 | { |
14492 | char *p = args; | |
52f0bd74 | 14493 | int num; |
c906108c SS |
14494 | |
14495 | if (p == 0) | |
e2e0b3e5 | 14496 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14497 | |
c906108c | 14498 | num = get_number (&p); |
5c44784c | 14499 | if (num == 0) |
8a3fe4f8 | 14500 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14501 | if (*p == 0) |
8a3fe4f8 | 14502 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14503 | |
14504 | set_ignore_count (num, | |
14505 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14506 | from_tty); | |
221ea385 KS |
14507 | if (from_tty) |
14508 | printf_filtered ("\n"); | |
c906108c SS |
14509 | } |
14510 | \f | |
14511 | /* Call FUNCTION on each of the breakpoints | |
14512 | whose numbers are given in ARGS. */ | |
14513 | ||
14514 | static void | |
95a42b64 TT |
14515 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14516 | void *), | |
14517 | void *data) | |
c906108c | 14518 | { |
52f0bd74 AC |
14519 | int num; |
14520 | struct breakpoint *b, *tmp; | |
11cf8741 | 14521 | int match; |
197f0a60 | 14522 | struct get_number_or_range_state state; |
c906108c | 14523 | |
197f0a60 | 14524 | if (args == 0) |
e2e0b3e5 | 14525 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14526 | |
197f0a60 TT |
14527 | init_number_or_range (&state, args); |
14528 | ||
14529 | while (!state.finished) | |
c906108c | 14530 | { |
197f0a60 TT |
14531 | char *p = state.string; |
14532 | ||
11cf8741 | 14533 | match = 0; |
c5aa993b | 14534 | |
197f0a60 | 14535 | num = get_number_or_range (&state); |
5c44784c | 14536 | if (num == 0) |
c5aa993b | 14537 | { |
8a3fe4f8 | 14538 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14539 | } |
14540 | else | |
14541 | { | |
14542 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14543 | if (b->number == num) | |
14544 | { | |
11cf8741 | 14545 | match = 1; |
cdac0397 | 14546 | function (b, data); |
11cf8741 | 14547 | break; |
5c44784c | 14548 | } |
11cf8741 | 14549 | if (match == 0) |
a3f17187 | 14550 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14551 | } |
c906108c SS |
14552 | } |
14553 | } | |
14554 | ||
0d381245 VP |
14555 | static struct bp_location * |
14556 | find_location_by_number (char *number) | |
14557 | { | |
14558 | char *dot = strchr (number, '.'); | |
14559 | char *p1; | |
14560 | int bp_num; | |
14561 | int loc_num; | |
14562 | struct breakpoint *b; | |
14563 | struct bp_location *loc; | |
14564 | ||
14565 | *dot = '\0'; | |
14566 | ||
14567 | p1 = number; | |
197f0a60 | 14568 | bp_num = get_number (&p1); |
0d381245 VP |
14569 | if (bp_num == 0) |
14570 | error (_("Bad breakpoint number '%s'"), number); | |
14571 | ||
14572 | ALL_BREAKPOINTS (b) | |
14573 | if (b->number == bp_num) | |
14574 | { | |
14575 | break; | |
14576 | } | |
14577 | ||
14578 | if (!b || b->number != bp_num) | |
14579 | error (_("Bad breakpoint number '%s'"), number); | |
14580 | ||
14581 | p1 = dot+1; | |
197f0a60 | 14582 | loc_num = get_number (&p1); |
0d381245 VP |
14583 | if (loc_num == 0) |
14584 | error (_("Bad breakpoint location number '%s'"), number); | |
14585 | ||
14586 | --loc_num; | |
14587 | loc = b->loc; | |
14588 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14589 | ; | |
14590 | if (!loc) | |
14591 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14592 | ||
14593 | return loc; | |
14594 | } | |
14595 | ||
14596 | ||
1900040c MS |
14597 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14598 | If from_tty is nonzero, it prints a message to that effect, | |
14599 | which ends with a period (no newline). */ | |
14600 | ||
c906108c | 14601 | void |
fba45db2 | 14602 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14603 | { |
14604 | /* Never disable a watchpoint scope breakpoint; we want to | |
14605 | hit them when we leave scope so we can delete both the | |
14606 | watchpoint and its scope breakpoint at that time. */ | |
14607 | if (bpt->type == bp_watchpoint_scope) | |
14608 | return; | |
14609 | ||
c2c6d25f | 14610 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14611 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14612 | return; |
14613 | ||
b5de0fa7 | 14614 | bpt->enable_state = bp_disabled; |
c906108c | 14615 | |
b775012e LM |
14616 | /* Mark breakpoint locations modified. */ |
14617 | mark_breakpoint_modified (bpt); | |
14618 | ||
d248b706 KY |
14619 | if (target_supports_enable_disable_tracepoint () |
14620 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14621 | { | |
14622 | struct bp_location *location; | |
14623 | ||
14624 | for (location = bpt->loc; location; location = location->next) | |
14625 | target_disable_tracepoint (location); | |
14626 | } | |
14627 | ||
b60e7edf | 14628 | update_global_location_list (0); |
c906108c | 14629 | |
8d3788bd | 14630 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14631 | } |
14632 | ||
51be5b68 PA |
14633 | /* A callback for iterate_over_related_breakpoints. */ |
14634 | ||
14635 | static void | |
14636 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14637 | { | |
14638 | disable_breakpoint (b); | |
14639 | } | |
14640 | ||
95a42b64 TT |
14641 | /* A callback for map_breakpoint_numbers that calls |
14642 | disable_breakpoint. */ | |
14643 | ||
14644 | static void | |
14645 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14646 | { | |
51be5b68 | 14647 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14648 | } |
14649 | ||
c906108c | 14650 | static void |
fba45db2 | 14651 | disable_command (char *args, int from_tty) |
c906108c | 14652 | { |
c906108c | 14653 | if (args == 0) |
46c6471b PA |
14654 | { |
14655 | struct breakpoint *bpt; | |
14656 | ||
14657 | ALL_BREAKPOINTS (bpt) | |
14658 | if (user_breakpoint_p (bpt)) | |
14659 | disable_breakpoint (bpt); | |
14660 | } | |
9eaabc75 | 14661 | else |
0d381245 | 14662 | { |
9eaabc75 MW |
14663 | char *num = extract_arg (&args); |
14664 | ||
14665 | while (num) | |
d248b706 | 14666 | { |
9eaabc75 | 14667 | if (strchr (num, '.')) |
b775012e | 14668 | { |
9eaabc75 MW |
14669 | struct bp_location *loc = find_location_by_number (num); |
14670 | ||
14671 | if (loc) | |
14672 | { | |
14673 | if (loc->enabled) | |
14674 | { | |
14675 | loc->enabled = 0; | |
14676 | mark_breakpoint_location_modified (loc); | |
14677 | } | |
14678 | if (target_supports_enable_disable_tracepoint () | |
14679 | && current_trace_status ()->running && loc->owner | |
14680 | && is_tracepoint (loc->owner)) | |
14681 | target_disable_tracepoint (loc); | |
14682 | } | |
14683 | update_global_location_list (0); | |
b775012e | 14684 | } |
9eaabc75 MW |
14685 | else |
14686 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14687 | num = extract_arg (&args); | |
d248b706 | 14688 | } |
0d381245 | 14689 | } |
c906108c SS |
14690 | } |
14691 | ||
14692 | static void | |
816338b5 SS |
14693 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14694 | int count) | |
c906108c | 14695 | { |
afe38095 | 14696 | int target_resources_ok; |
c906108c SS |
14697 | |
14698 | if (bpt->type == bp_hardware_breakpoint) | |
14699 | { | |
14700 | int i; | |
c5aa993b | 14701 | i = hw_breakpoint_used_count (); |
53a5351d | 14702 | target_resources_ok = |
d92524f1 | 14703 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14704 | i + 1, 0); |
c906108c | 14705 | if (target_resources_ok == 0) |
8a3fe4f8 | 14706 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14707 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14708 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14709 | } |
14710 | ||
cc60f2e3 | 14711 | if (is_watchpoint (bpt)) |
c906108c | 14712 | { |
d07205c2 JK |
14713 | /* Initialize it just to avoid a GCC false warning. */ |
14714 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14715 | volatile struct gdb_exception e; |
dde02812 ES |
14716 | |
14717 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14718 | { |
3a5c3e22 PA |
14719 | struct watchpoint *w = (struct watchpoint *) bpt; |
14720 | ||
1e718ff1 TJB |
14721 | orig_enable_state = bpt->enable_state; |
14722 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14723 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14724 | } |
dde02812 | 14725 | if (e.reason < 0) |
c5aa993b | 14726 | { |
1e718ff1 | 14727 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14728 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14729 | bpt->number); | |
14730 | return; | |
c5aa993b | 14731 | } |
c906108c | 14732 | } |
0101ce28 | 14733 | |
b4c291bb KH |
14734 | if (bpt->enable_state != bp_permanent) |
14735 | bpt->enable_state = bp_enabled; | |
d248b706 | 14736 | |
b775012e LM |
14737 | bpt->enable_state = bp_enabled; |
14738 | ||
14739 | /* Mark breakpoint locations modified. */ | |
14740 | mark_breakpoint_modified (bpt); | |
14741 | ||
d248b706 KY |
14742 | if (target_supports_enable_disable_tracepoint () |
14743 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14744 | { | |
14745 | struct bp_location *location; | |
14746 | ||
14747 | for (location = bpt->loc; location; location = location->next) | |
14748 | target_enable_tracepoint (location); | |
14749 | } | |
14750 | ||
b4c291bb | 14751 | bpt->disposition = disposition; |
816338b5 | 14752 | bpt->enable_count = count; |
b60e7edf | 14753 | update_global_location_list (1); |
9c97429f | 14754 | |
8d3788bd | 14755 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14756 | } |
14757 | ||
fe3f5fa8 | 14758 | |
c906108c | 14759 | void |
fba45db2 | 14760 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14761 | { |
816338b5 | 14762 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14763 | } |
14764 | ||
14765 | static void | |
14766 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14767 | { | |
14768 | enable_breakpoint (bpt); | |
c906108c SS |
14769 | } |
14770 | ||
95a42b64 TT |
14771 | /* A callback for map_breakpoint_numbers that calls |
14772 | enable_breakpoint. */ | |
14773 | ||
14774 | static void | |
14775 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14776 | { | |
51be5b68 | 14777 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14778 | } |
14779 | ||
c906108c SS |
14780 | /* The enable command enables the specified breakpoints (or all defined |
14781 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14782 | in stopping the inferior. */ |
c906108c | 14783 | |
c906108c | 14784 | static void |
fba45db2 | 14785 | enable_command (char *args, int from_tty) |
c906108c | 14786 | { |
c906108c | 14787 | if (args == 0) |
46c6471b PA |
14788 | { |
14789 | struct breakpoint *bpt; | |
14790 | ||
14791 | ALL_BREAKPOINTS (bpt) | |
14792 | if (user_breakpoint_p (bpt)) | |
14793 | enable_breakpoint (bpt); | |
14794 | } | |
9eaabc75 | 14795 | else |
0d381245 | 14796 | { |
9eaabc75 MW |
14797 | char *num = extract_arg (&args); |
14798 | ||
14799 | while (num) | |
d248b706 | 14800 | { |
9eaabc75 | 14801 | if (strchr (num, '.')) |
b775012e | 14802 | { |
9eaabc75 MW |
14803 | struct bp_location *loc = find_location_by_number (num); |
14804 | ||
14805 | if (loc) | |
14806 | { | |
14807 | if (!loc->enabled) | |
14808 | { | |
14809 | loc->enabled = 1; | |
14810 | mark_breakpoint_location_modified (loc); | |
14811 | } | |
14812 | if (target_supports_enable_disable_tracepoint () | |
14813 | && current_trace_status ()->running && loc->owner | |
14814 | && is_tracepoint (loc->owner)) | |
14815 | target_enable_tracepoint (loc); | |
14816 | } | |
14817 | update_global_location_list (1); | |
b775012e | 14818 | } |
9eaabc75 MW |
14819 | else |
14820 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14821 | num = extract_arg (&args); | |
d248b706 | 14822 | } |
0d381245 | 14823 | } |
c906108c SS |
14824 | } |
14825 | ||
816338b5 SS |
14826 | /* This struct packages up disposition data for application to multiple |
14827 | breakpoints. */ | |
14828 | ||
14829 | struct disp_data | |
14830 | { | |
14831 | enum bpdisp disp; | |
14832 | int count; | |
14833 | }; | |
14834 | ||
c906108c | 14835 | static void |
51be5b68 PA |
14836 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14837 | { | |
816338b5 | 14838 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14839 | |
816338b5 | 14840 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14841 | } |
14842 | ||
14843 | static void | |
14844 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14845 | { |
816338b5 | 14846 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14847 | |
14848 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14849 | } |
14850 | ||
c906108c | 14851 | static void |
fba45db2 | 14852 | enable_once_command (char *args, int from_tty) |
c906108c | 14853 | { |
51be5b68 | 14854 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14855 | } |
14856 | ||
816338b5 SS |
14857 | static void |
14858 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14859 | { | |
14860 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14861 | ||
14862 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14863 | } | |
14864 | ||
14865 | static void | |
14866 | enable_count_command (char *args, int from_tty) | |
14867 | { | |
14868 | int count = get_number (&args); | |
14869 | ||
14870 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14871 | } | |
14872 | ||
c906108c | 14873 | static void |
51be5b68 | 14874 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14875 | { |
816338b5 | 14876 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14877 | |
14878 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14879 | } |
14880 | ||
c906108c | 14881 | static void |
fba45db2 | 14882 | enable_delete_command (char *args, int from_tty) |
c906108c | 14883 | { |
51be5b68 | 14884 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14885 | } |
14886 | \f | |
fa8d40ab JJ |
14887 | static void |
14888 | set_breakpoint_cmd (char *args, int from_tty) | |
14889 | { | |
14890 | } | |
14891 | ||
14892 | static void | |
14893 | show_breakpoint_cmd (char *args, int from_tty) | |
14894 | { | |
14895 | } | |
14896 | ||
1f3b5d1b PP |
14897 | /* Invalidate last known value of any hardware watchpoint if |
14898 | the memory which that value represents has been written to by | |
14899 | GDB itself. */ | |
14900 | ||
14901 | static void | |
8de0566d YQ |
14902 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14903 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14904 | const bfd_byte *data) |
14905 | { | |
14906 | struct breakpoint *bp; | |
14907 | ||
14908 | ALL_BREAKPOINTS (bp) | |
14909 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14910 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14911 | { |
3a5c3e22 | 14912 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14913 | |
3a5c3e22 PA |
14914 | if (wp->val_valid && wp->val) |
14915 | { | |
14916 | struct bp_location *loc; | |
14917 | ||
14918 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14919 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14920 | && loc->address + loc->length > addr | |
14921 | && addr + len > loc->address) | |
14922 | { | |
14923 | value_free (wp->val); | |
14924 | wp->val = NULL; | |
14925 | wp->val_valid = 0; | |
14926 | } | |
14927 | } | |
1f3b5d1b PP |
14928 | } |
14929 | } | |
14930 | ||
8181d85f DJ |
14931 | /* Create and insert a raw software breakpoint at PC. Return an |
14932 | identifier, which should be used to remove the breakpoint later. | |
14933 | In general, places which call this should be using something on the | |
14934 | breakpoint chain instead; this function should be eliminated | |
14935 | someday. */ | |
14936 | ||
14937 | void * | |
6c95b8df PA |
14938 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
14939 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
14940 | { |
14941 | struct bp_target_info *bp_tgt; | |
14942 | ||
6c95b8df | 14943 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 14944 | |
6c95b8df | 14945 | bp_tgt->placed_address_space = aspace; |
8181d85f | 14946 | bp_tgt->placed_address = pc; |
6c95b8df | 14947 | |
a6d9a66e | 14948 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
14949 | { |
14950 | /* Could not insert the breakpoint. */ | |
14951 | xfree (bp_tgt); | |
14952 | return NULL; | |
14953 | } | |
14954 | ||
14955 | return bp_tgt; | |
14956 | } | |
14957 | ||
4a64f543 MS |
14958 | /* Remove a breakpoint BP inserted by |
14959 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
14960 | |
14961 | int | |
a6d9a66e | 14962 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
14963 | { |
14964 | struct bp_target_info *bp_tgt = bp; | |
14965 | int ret; | |
14966 | ||
a6d9a66e | 14967 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
14968 | xfree (bp_tgt); |
14969 | ||
14970 | return ret; | |
14971 | } | |
14972 | ||
4a64f543 MS |
14973 | /* One (or perhaps two) breakpoints used for software single |
14974 | stepping. */ | |
8181d85f DJ |
14975 | |
14976 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 14977 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
14978 | |
14979 | /* Create and insert a breakpoint for software single step. */ | |
14980 | ||
14981 | void | |
6c95b8df | 14982 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14983 | struct address_space *aspace, |
14984 | CORE_ADDR next_pc) | |
8181d85f DJ |
14985 | { |
14986 | void **bpt_p; | |
14987 | ||
14988 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
14989 | { |
14990 | bpt_p = &single_step_breakpoints[0]; | |
14991 | single_step_gdbarch[0] = gdbarch; | |
14992 | } | |
8181d85f DJ |
14993 | else |
14994 | { | |
14995 | gdb_assert (single_step_breakpoints[1] == NULL); | |
14996 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 14997 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
14998 | } |
14999 | ||
4a64f543 MS |
15000 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15001 | be to only create the breakpoints once, and actually put them on | |
15002 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15003 | We could adjust the addresses each time they were needed. Doing | |
15004 | this requires corresponding changes elsewhere where single step | |
15005 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15006 | |
6c95b8df | 15007 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15008 | if (*bpt_p == NULL) |
5af949e3 UW |
15009 | error (_("Could not insert single-step breakpoint at %s"), |
15010 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15011 | } |
15012 | ||
f02253f1 HZ |
15013 | /* Check if the breakpoints used for software single stepping |
15014 | were inserted or not. */ | |
15015 | ||
15016 | int | |
15017 | single_step_breakpoints_inserted (void) | |
15018 | { | |
15019 | return (single_step_breakpoints[0] != NULL | |
15020 | || single_step_breakpoints[1] != NULL); | |
15021 | } | |
15022 | ||
8181d85f DJ |
15023 | /* Remove and delete any breakpoints used for software single step. */ |
15024 | ||
15025 | void | |
15026 | remove_single_step_breakpoints (void) | |
15027 | { | |
15028 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15029 | ||
15030 | /* See insert_single_step_breakpoint for more about this deprecated | |
15031 | call. */ | |
a6d9a66e UW |
15032 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15033 | single_step_breakpoints[0]); | |
15034 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15035 | single_step_breakpoints[0] = NULL; |
15036 | ||
15037 | if (single_step_breakpoints[1] != NULL) | |
15038 | { | |
a6d9a66e UW |
15039 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15040 | single_step_breakpoints[1]); | |
15041 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15042 | single_step_breakpoints[1] = NULL; |
15043 | } | |
15044 | } | |
15045 | ||
d03285ec UW |
15046 | /* Delete software single step breakpoints without removing them from |
15047 | the inferior. This is intended to be used if the inferior's address | |
15048 | space where they were inserted is already gone, e.g. after exit or | |
15049 | exec. */ | |
15050 | ||
15051 | void | |
15052 | cancel_single_step_breakpoints (void) | |
15053 | { | |
15054 | int i; | |
15055 | ||
15056 | for (i = 0; i < 2; i++) | |
15057 | if (single_step_breakpoints[i]) | |
15058 | { | |
15059 | xfree (single_step_breakpoints[i]); | |
15060 | single_step_breakpoints[i] = NULL; | |
15061 | single_step_gdbarch[i] = NULL; | |
15062 | } | |
15063 | } | |
15064 | ||
15065 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15066 | removing them. */ | |
15067 | ||
15068 | static void | |
15069 | detach_single_step_breakpoints (void) | |
15070 | { | |
15071 | int i; | |
15072 | ||
15073 | for (i = 0; i < 2; i++) | |
15074 | if (single_step_breakpoints[i]) | |
15075 | target_remove_breakpoint (single_step_gdbarch[i], | |
15076 | single_step_breakpoints[i]); | |
15077 | } | |
15078 | ||
4a64f543 MS |
15079 | /* Check whether a software single-step breakpoint is inserted at |
15080 | PC. */ | |
1aafd4da UW |
15081 | |
15082 | static int | |
cc59ec59 MS |
15083 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15084 | CORE_ADDR pc) | |
1aafd4da UW |
15085 | { |
15086 | int i; | |
15087 | ||
15088 | for (i = 0; i < 2; i++) | |
15089 | { | |
15090 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15091 | if (bp_tgt |
15092 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15093 | bp_tgt->placed_address, | |
15094 | aspace, pc)) | |
1aafd4da UW |
15095 | return 1; |
15096 | } | |
15097 | ||
15098 | return 0; | |
15099 | } | |
15100 | ||
a96d9b2e SDJ |
15101 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15102 | non-zero otherwise. */ | |
15103 | static int | |
15104 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15105 | { | |
15106 | if (syscall_catchpoint_p (bp) | |
15107 | && bp->enable_state != bp_disabled | |
15108 | && bp->enable_state != bp_call_disabled) | |
15109 | return 1; | |
15110 | else | |
15111 | return 0; | |
15112 | } | |
15113 | ||
15114 | int | |
15115 | catch_syscall_enabled (void) | |
15116 | { | |
fa3064dd YQ |
15117 | struct catch_syscall_inferior_data *inf_data |
15118 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15119 | |
fa3064dd | 15120 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15121 | } |
15122 | ||
15123 | int | |
15124 | catching_syscall_number (int syscall_number) | |
15125 | { | |
15126 | struct breakpoint *bp; | |
15127 | ||
15128 | ALL_BREAKPOINTS (bp) | |
15129 | if (is_syscall_catchpoint_enabled (bp)) | |
15130 | { | |
be5c67c1 PA |
15131 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15132 | ||
15133 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15134 | { |
15135 | int i, iter; | |
15136 | for (i = 0; | |
be5c67c1 | 15137 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15138 | i++) |
15139 | if (syscall_number == iter) | |
15140 | return 1; | |
15141 | } | |
15142 | else | |
15143 | return 1; | |
15144 | } | |
15145 | ||
15146 | return 0; | |
15147 | } | |
15148 | ||
15149 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15150 | static VEC (char_ptr) * |
a96d9b2e | 15151 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15152 | const char *text, const char *word) |
a96d9b2e SDJ |
15153 | { |
15154 | const char **list = get_syscall_names (); | |
49c4e619 | 15155 | VEC (char_ptr) *retlist |
b45627a0 | 15156 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15157 | |
c38eea1a MS |
15158 | xfree (list); |
15159 | return retlist; | |
a96d9b2e SDJ |
15160 | } |
15161 | ||
1042e4c0 SS |
15162 | /* Tracepoint-specific operations. */ |
15163 | ||
15164 | /* Set tracepoint count to NUM. */ | |
15165 | static void | |
15166 | set_tracepoint_count (int num) | |
15167 | { | |
15168 | tracepoint_count = num; | |
4fa62494 | 15169 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15170 | } |
15171 | ||
70221824 | 15172 | static void |
1042e4c0 SS |
15173 | trace_command (char *arg, int from_tty) |
15174 | { | |
55aa24fb SDJ |
15175 | struct breakpoint_ops *ops; |
15176 | const char *arg_cp = arg; | |
15177 | ||
15178 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15179 | ops = &tracepoint_probe_breakpoint_ops; | |
15180 | else | |
15181 | ops = &tracepoint_breakpoint_ops; | |
15182 | ||
558a9d82 YQ |
15183 | create_breakpoint (get_current_arch (), |
15184 | arg, | |
15185 | NULL, 0, NULL, 1 /* parse arg */, | |
15186 | 0 /* tempflag */, | |
15187 | bp_tracepoint /* type_wanted */, | |
15188 | 0 /* Ignore count */, | |
15189 | pending_break_support, | |
15190 | ops, | |
15191 | from_tty, | |
15192 | 1 /* enabled */, | |
15193 | 0 /* internal */, 0); | |
1042e4c0 SS |
15194 | } |
15195 | ||
70221824 | 15196 | static void |
7a697b8d SS |
15197 | ftrace_command (char *arg, int from_tty) |
15198 | { | |
558a9d82 YQ |
15199 | create_breakpoint (get_current_arch (), |
15200 | arg, | |
15201 | NULL, 0, NULL, 1 /* parse arg */, | |
15202 | 0 /* tempflag */, | |
15203 | bp_fast_tracepoint /* type_wanted */, | |
15204 | 0 /* Ignore count */, | |
15205 | pending_break_support, | |
15206 | &tracepoint_breakpoint_ops, | |
15207 | from_tty, | |
15208 | 1 /* enabled */, | |
15209 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15210 | } |
15211 | ||
15212 | /* strace command implementation. Creates a static tracepoint. */ | |
15213 | ||
70221824 | 15214 | static void |
0fb4aa4b PA |
15215 | strace_command (char *arg, int from_tty) |
15216 | { | |
983af33b SDJ |
15217 | struct breakpoint_ops *ops; |
15218 | ||
15219 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15220 | or with a normal static tracepoint. */ | |
15221 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15222 | ops = &strace_marker_breakpoint_ops; | |
15223 | else | |
15224 | ops = &tracepoint_breakpoint_ops; | |
15225 | ||
558a9d82 YQ |
15226 | create_breakpoint (get_current_arch (), |
15227 | arg, | |
15228 | NULL, 0, NULL, 1 /* parse arg */, | |
15229 | 0 /* tempflag */, | |
15230 | bp_static_tracepoint /* type_wanted */, | |
15231 | 0 /* Ignore count */, | |
15232 | pending_break_support, | |
15233 | ops, | |
15234 | from_tty, | |
15235 | 1 /* enabled */, | |
15236 | 0 /* internal */, 0); | |
7a697b8d SS |
15237 | } |
15238 | ||
409873ef SS |
15239 | /* Set up a fake reader function that gets command lines from a linked |
15240 | list that was acquired during tracepoint uploading. */ | |
15241 | ||
15242 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15243 | static int next_cmd; |
409873ef SS |
15244 | |
15245 | static char * | |
15246 | read_uploaded_action (void) | |
15247 | { | |
15248 | char *rslt; | |
15249 | ||
3149d8c1 | 15250 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15251 | |
3149d8c1 | 15252 | next_cmd++; |
409873ef SS |
15253 | |
15254 | return rslt; | |
15255 | } | |
15256 | ||
00bf0b85 SS |
15257 | /* Given information about a tracepoint as recorded on a target (which |
15258 | can be either a live system or a trace file), attempt to create an | |
15259 | equivalent GDB tracepoint. This is not a reliable process, since | |
15260 | the target does not necessarily have all the information used when | |
15261 | the tracepoint was originally defined. */ | |
15262 | ||
d9b3f62e | 15263 | struct tracepoint * |
00bf0b85 | 15264 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15265 | { |
409873ef | 15266 | char *addr_str, small_buf[100]; |
d9b3f62e | 15267 | struct tracepoint *tp; |
fd9b8c24 | 15268 | |
409873ef SS |
15269 | if (utp->at_string) |
15270 | addr_str = utp->at_string; | |
15271 | else | |
15272 | { | |
15273 | /* In the absence of a source location, fall back to raw | |
15274 | address. Since there is no way to confirm that the address | |
15275 | means the same thing as when the trace was started, warn the | |
15276 | user. */ | |
3e43a32a MS |
15277 | warning (_("Uploaded tracepoint %d has no " |
15278 | "source location, using raw address"), | |
409873ef | 15279 | utp->number); |
8c042590 | 15280 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15281 | addr_str = small_buf; |
15282 | } | |
15283 | ||
15284 | /* There's not much we can do with a sequence of bytecodes. */ | |
15285 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15286 | warning (_("Uploaded tracepoint %d condition " |
15287 | "has no source form, ignoring it"), | |
409873ef | 15288 | utp->number); |
d5551862 | 15289 | |
8cdf0e15 | 15290 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15291 | addr_str, |
e7e0cddf SS |
15292 | utp->cond_string, -1, NULL, |
15293 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15294 | 0 /* tempflag */, |
0fb4aa4b | 15295 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15296 | 0 /* Ignore count */, |
15297 | pending_break_support, | |
348d480f | 15298 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15299 | 0 /* from_tty */, |
84f4c1fe | 15300 | utp->enabled /* enabled */, |
44f238bb PA |
15301 | 0 /* internal */, |
15302 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15303 | return NULL; |
15304 | ||
409873ef | 15305 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15306 | tp = get_tracepoint (tracepoint_count); |
15307 | gdb_assert (tp != NULL); | |
d5551862 | 15308 | |
00bf0b85 SS |
15309 | if (utp->pass > 0) |
15310 | { | |
8c042590 PM |
15311 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15312 | tp->base.number); | |
00bf0b85 | 15313 | |
409873ef | 15314 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15315 | } |
15316 | ||
409873ef SS |
15317 | /* If we have uploaded versions of the original commands, set up a |
15318 | special-purpose "reader" function and call the usual command line | |
15319 | reader, then pass the result to the breakpoint command-setting | |
15320 | function. */ | |
3149d8c1 | 15321 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15322 | { |
409873ef | 15323 | struct command_line *cmd_list; |
00bf0b85 | 15324 | |
409873ef | 15325 | this_utp = utp; |
3149d8c1 | 15326 | next_cmd = 0; |
d5551862 | 15327 | |
409873ef SS |
15328 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15329 | ||
d9b3f62e | 15330 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15331 | } |
3149d8c1 SS |
15332 | else if (!VEC_empty (char_ptr, utp->actions) |
15333 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15334 | warning (_("Uploaded tracepoint %d actions " |
15335 | "have no source form, ignoring them"), | |
409873ef | 15336 | utp->number); |
00bf0b85 | 15337 | |
f196051f SS |
15338 | /* Copy any status information that might be available. */ |
15339 | tp->base.hit_count = utp->hit_count; | |
15340 | tp->traceframe_usage = utp->traceframe_usage; | |
15341 | ||
00bf0b85 | 15342 | return tp; |
d9b3f62e | 15343 | } |
00bf0b85 | 15344 | |
1042e4c0 SS |
15345 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15346 | omitted. */ | |
15347 | ||
15348 | static void | |
e5a67952 | 15349 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15350 | { |
79a45e25 | 15351 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15352 | int num_printed; |
1042e4c0 | 15353 | |
e5a67952 | 15354 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15355 | |
15356 | if (num_printed == 0) | |
1042e4c0 | 15357 | { |
e5a67952 | 15358 | if (args == NULL || *args == '\0') |
d77f58be SS |
15359 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15360 | else | |
e5a67952 | 15361 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15362 | } |
ad443146 SS |
15363 | |
15364 | default_collect_info (); | |
1042e4c0 SS |
15365 | } |
15366 | ||
4a64f543 | 15367 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15368 | Not supported by all targets. */ |
15369 | static void | |
15370 | enable_trace_command (char *args, int from_tty) | |
15371 | { | |
15372 | enable_command (args, from_tty); | |
15373 | } | |
15374 | ||
4a64f543 | 15375 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15376 | Not supported by all targets. */ |
15377 | static void | |
15378 | disable_trace_command (char *args, int from_tty) | |
15379 | { | |
15380 | disable_command (args, from_tty); | |
15381 | } | |
15382 | ||
4a64f543 | 15383 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15384 | static void |
15385 | delete_trace_command (char *arg, int from_tty) | |
15386 | { | |
35df4500 | 15387 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15388 | |
15389 | dont_repeat (); | |
15390 | ||
15391 | if (arg == 0) | |
15392 | { | |
15393 | int breaks_to_delete = 0; | |
15394 | ||
15395 | /* Delete all breakpoints if no argument. | |
15396 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15397 | have to be deleted with an explicit breakpoint number |
15398 | argument. */ | |
1042e4c0 | 15399 | ALL_TRACEPOINTS (b) |
46c6471b | 15400 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15401 | { |
15402 | breaks_to_delete = 1; | |
15403 | break; | |
15404 | } | |
1042e4c0 SS |
15405 | |
15406 | /* Ask user only if there are some breakpoints to delete. */ | |
15407 | if (!from_tty | |
15408 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15409 | { | |
35df4500 | 15410 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15411 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15412 | delete_breakpoint (b); |
1042e4c0 SS |
15413 | } |
15414 | } | |
15415 | else | |
51be5b68 | 15416 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15417 | } |
15418 | ||
197f0a60 TT |
15419 | /* Helper function for trace_pass_command. */ |
15420 | ||
15421 | static void | |
d9b3f62e | 15422 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15423 | { |
d9b3f62e | 15424 | tp->pass_count = count; |
6f6484cd | 15425 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15426 | if (from_tty) |
15427 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15428 | tp->base.number, count); |
197f0a60 TT |
15429 | } |
15430 | ||
1042e4c0 SS |
15431 | /* Set passcount for tracepoint. |
15432 | ||
15433 | First command argument is passcount, second is tracepoint number. | |
15434 | If tracepoint number omitted, apply to most recently defined. | |
15435 | Also accepts special argument "all". */ | |
15436 | ||
15437 | static void | |
15438 | trace_pass_command (char *args, int from_tty) | |
15439 | { | |
d9b3f62e | 15440 | struct tracepoint *t1; |
1042e4c0 | 15441 | unsigned int count; |
1042e4c0 SS |
15442 | |
15443 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15444 | error (_("passcount command requires an " |
15445 | "argument (count + optional TP num)")); | |
1042e4c0 | 15446 | |
4a64f543 | 15447 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15448 | |
529480d0 | 15449 | args = skip_spaces (args); |
1042e4c0 SS |
15450 | if (*args && strncasecmp (args, "all", 3) == 0) |
15451 | { | |
d9b3f62e PA |
15452 | struct breakpoint *b; |
15453 | ||
1042e4c0 | 15454 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15455 | if (*args) |
15456 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15457 | |
d9b3f62e | 15458 | ALL_TRACEPOINTS (b) |
197f0a60 | 15459 | { |
d9b3f62e | 15460 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15461 | trace_pass_set_count (t1, count, from_tty); |
15462 | } | |
15463 | } | |
15464 | else if (*args == '\0') | |
1042e4c0 | 15465 | { |
197f0a60 | 15466 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 15467 | if (t1) |
197f0a60 TT |
15468 | trace_pass_set_count (t1, count, from_tty); |
15469 | } | |
15470 | else | |
15471 | { | |
15472 | struct get_number_or_range_state state; | |
15473 | ||
15474 | init_number_or_range (&state, args); | |
15475 | while (!state.finished) | |
1042e4c0 | 15476 | { |
197f0a60 TT |
15477 | t1 = get_tracepoint_by_number (&args, &state, 1); |
15478 | if (t1) | |
15479 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15480 | } |
15481 | } | |
1042e4c0 SS |
15482 | } |
15483 | ||
d9b3f62e | 15484 | struct tracepoint * |
1042e4c0 SS |
15485 | get_tracepoint (int num) |
15486 | { | |
15487 | struct breakpoint *t; | |
15488 | ||
15489 | ALL_TRACEPOINTS (t) | |
15490 | if (t->number == num) | |
d9b3f62e | 15491 | return (struct tracepoint *) t; |
1042e4c0 SS |
15492 | |
15493 | return NULL; | |
15494 | } | |
15495 | ||
d5551862 SS |
15496 | /* Find the tracepoint with the given target-side number (which may be |
15497 | different from the tracepoint number after disconnecting and | |
15498 | reconnecting). */ | |
15499 | ||
d9b3f62e | 15500 | struct tracepoint * |
d5551862 SS |
15501 | get_tracepoint_by_number_on_target (int num) |
15502 | { | |
d9b3f62e | 15503 | struct breakpoint *b; |
d5551862 | 15504 | |
d9b3f62e PA |
15505 | ALL_TRACEPOINTS (b) |
15506 | { | |
15507 | struct tracepoint *t = (struct tracepoint *) b; | |
15508 | ||
15509 | if (t->number_on_target == num) | |
15510 | return t; | |
15511 | } | |
d5551862 SS |
15512 | |
15513 | return NULL; | |
15514 | } | |
15515 | ||
1042e4c0 | 15516 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
15517 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
15518 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 15519 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 15520 | struct tracepoint * |
197f0a60 TT |
15521 | get_tracepoint_by_number (char **arg, |
15522 | struct get_number_or_range_state *state, | |
15523 | int optional_p) | |
1042e4c0 | 15524 | { |
1042e4c0 SS |
15525 | struct breakpoint *t; |
15526 | int tpnum; | |
15527 | char *instring = arg == NULL ? NULL : *arg; | |
15528 | ||
197f0a60 TT |
15529 | if (state) |
15530 | { | |
15531 | gdb_assert (!state->finished); | |
15532 | tpnum = get_number_or_range (state); | |
15533 | } | |
15534 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
15535 | { |
15536 | if (optional_p) | |
15537 | tpnum = tracepoint_count; | |
15538 | else | |
15539 | error_no_arg (_("tracepoint number")); | |
15540 | } | |
15541 | else | |
197f0a60 | 15542 | tpnum = get_number (arg); |
1042e4c0 SS |
15543 | |
15544 | if (tpnum <= 0) | |
15545 | { | |
15546 | if (instring && *instring) | |
15547 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15548 | instring); | |
15549 | else | |
3e43a32a MS |
15550 | printf_filtered (_("Tracepoint argument missing " |
15551 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
15552 | return NULL; |
15553 | } | |
15554 | ||
15555 | ALL_TRACEPOINTS (t) | |
15556 | if (t->number == tpnum) | |
15557 | { | |
d9b3f62e | 15558 | return (struct tracepoint *) t; |
1042e4c0 SS |
15559 | } |
15560 | ||
1042e4c0 SS |
15561 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15562 | return NULL; | |
15563 | } | |
15564 | ||
d9b3f62e PA |
15565 | void |
15566 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15567 | { | |
15568 | if (b->thread != -1) | |
15569 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15570 | ||
15571 | if (b->task != 0) | |
15572 | fprintf_unfiltered (fp, " task %d", b->task); | |
15573 | ||
15574 | fprintf_unfiltered (fp, "\n"); | |
15575 | } | |
15576 | ||
6149aea9 PA |
15577 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15578 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15579 | on each breakpoint and only include the ones for which it returns | |
15580 | non-zero. */ | |
15581 | ||
1042e4c0 | 15582 | static void |
6149aea9 PA |
15583 | save_breakpoints (char *filename, int from_tty, |
15584 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15585 | { |
15586 | struct breakpoint *tp; | |
6149aea9 | 15587 | int any = 0; |
1042e4c0 | 15588 | struct cleanup *cleanup; |
a7bdde9e | 15589 | struct ui_file *fp; |
6149aea9 | 15590 | int extra_trace_bits = 0; |
1042e4c0 | 15591 | |
6149aea9 PA |
15592 | if (filename == 0 || *filename == 0) |
15593 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15594 | |
15595 | /* See if we have anything to save. */ | |
6149aea9 | 15596 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15597 | { |
6149aea9 | 15598 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15599 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15600 | continue; |
15601 | ||
15602 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15603 | if (filter && !filter (tp)) | |
15604 | continue; | |
15605 | ||
15606 | any = 1; | |
15607 | ||
15608 | if (is_tracepoint (tp)) | |
15609 | { | |
15610 | extra_trace_bits = 1; | |
15611 | ||
15612 | /* We can stop searching. */ | |
15613 | break; | |
15614 | } | |
1042e4c0 | 15615 | } |
6149aea9 PA |
15616 | |
15617 | if (!any) | |
1042e4c0 | 15618 | { |
6149aea9 | 15619 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15620 | return; |
15621 | } | |
15622 | ||
c718be47 PA |
15623 | filename = tilde_expand (filename); |
15624 | cleanup = make_cleanup (xfree, filename); | |
15625 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15626 | if (!fp) |
6149aea9 PA |
15627 | error (_("Unable to open file '%s' for saving (%s)"), |
15628 | filename, safe_strerror (errno)); | |
a7bdde9e | 15629 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15630 | |
6149aea9 PA |
15631 | if (extra_trace_bits) |
15632 | save_trace_state_variables (fp); | |
8bf6485c | 15633 | |
6149aea9 | 15634 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15635 | { |
6149aea9 | 15636 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15637 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15638 | continue; |
8bf6485c | 15639 | |
6149aea9 PA |
15640 | /* If we have a filter, only save the breakpoints it accepts. */ |
15641 | if (filter && !filter (tp)) | |
15642 | continue; | |
15643 | ||
348d480f | 15644 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15645 | |
6149aea9 PA |
15646 | /* Note, we can't rely on tp->number for anything, as we can't |
15647 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15648 | instead. */ | |
15649 | ||
15650 | if (tp->cond_string) | |
15651 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15652 | ||
15653 | if (tp->ignore_count) | |
15654 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15655 | ||
2d9442cc | 15656 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15657 | { |
a7bdde9e VP |
15658 | volatile struct gdb_exception ex; |
15659 | ||
6149aea9 | 15660 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15661 | |
79a45e25 | 15662 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15663 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15664 | { |
79a45e25 | 15665 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15666 | } |
79a45e25 | 15667 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15668 | |
a7bdde9e VP |
15669 | if (ex.reason < 0) |
15670 | throw_exception (ex); | |
1042e4c0 | 15671 | |
a7bdde9e | 15672 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15673 | } |
6149aea9 PA |
15674 | |
15675 | if (tp->enable_state == bp_disabled) | |
15676 | fprintf_unfiltered (fp, "disable\n"); | |
15677 | ||
15678 | /* If this is a multi-location breakpoint, check if the locations | |
15679 | should be individually disabled. Watchpoint locations are | |
15680 | special, and not user visible. */ | |
15681 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15682 | { | |
15683 | struct bp_location *loc; | |
15684 | int n = 1; | |
15685 | ||
15686 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15687 | if (!loc->enabled) | |
15688 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15689 | } | |
1042e4c0 | 15690 | } |
8bf6485c | 15691 | |
6149aea9 | 15692 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15693 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15694 | ||
1042e4c0 | 15695 | if (from_tty) |
6149aea9 | 15696 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15697 | do_cleanups (cleanup); |
6149aea9 PA |
15698 | } |
15699 | ||
15700 | /* The `save breakpoints' command. */ | |
15701 | ||
15702 | static void | |
15703 | save_breakpoints_command (char *args, int from_tty) | |
15704 | { | |
15705 | save_breakpoints (args, from_tty, NULL); | |
15706 | } | |
15707 | ||
15708 | /* The `save tracepoints' command. */ | |
15709 | ||
15710 | static void | |
15711 | save_tracepoints_command (char *args, int from_tty) | |
15712 | { | |
15713 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15714 | } |
15715 | ||
15716 | /* Create a vector of all tracepoints. */ | |
15717 | ||
15718 | VEC(breakpoint_p) * | |
eeae04df | 15719 | all_tracepoints (void) |
1042e4c0 SS |
15720 | { |
15721 | VEC(breakpoint_p) *tp_vec = 0; | |
15722 | struct breakpoint *tp; | |
15723 | ||
15724 | ALL_TRACEPOINTS (tp) | |
15725 | { | |
15726 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15727 | } | |
15728 | ||
15729 | return tp_vec; | |
15730 | } | |
15731 | ||
c906108c | 15732 | \f |
4a64f543 MS |
15733 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15734 | commands. It is defined as a macro to prevent duplication. | |
15735 | COMMAND should be a string constant containing the name of the | |
15736 | command. */ | |
31e2b00f | 15737 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15738 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15739 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15740 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15741 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15742 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15743 | If a line number is specified, break at start of code for that line.\n\ | |
15744 | If a function is specified, break at start of code for that function.\n\ | |
15745 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15746 | With no LOCATION, uses current execution address of the selected\n\ |
15747 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15748 | \n\ |
15749 | THREADNUM is the number from \"info threads\".\n\ | |
15750 | CONDITION is a boolean expression.\n\ | |
15751 | \n\ | |
d41c0fc8 PA |
15752 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15753 | conditions are different.\n\ | |
31e2b00f AS |
15754 | \n\ |
15755 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15756 | ||
44feb3ce TT |
15757 | /* List of subcommands for "catch". */ |
15758 | static struct cmd_list_element *catch_cmdlist; | |
15759 | ||
15760 | /* List of subcommands for "tcatch". */ | |
15761 | static struct cmd_list_element *tcatch_cmdlist; | |
15762 | ||
9ac4176b | 15763 | void |
44feb3ce TT |
15764 | add_catch_command (char *name, char *docstring, |
15765 | void (*sfunc) (char *args, int from_tty, | |
15766 | struct cmd_list_element *command), | |
625e8578 | 15767 | completer_ftype *completer, |
44feb3ce TT |
15768 | void *user_data_catch, |
15769 | void *user_data_tcatch) | |
15770 | { | |
15771 | struct cmd_list_element *command; | |
15772 | ||
15773 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15774 | &catch_cmdlist); | |
15775 | set_cmd_sfunc (command, sfunc); | |
15776 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15777 | set_cmd_completer (command, completer); |
44feb3ce TT |
15778 | |
15779 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15780 | &tcatch_cmdlist); | |
15781 | set_cmd_sfunc (command, sfunc); | |
15782 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15783 | set_cmd_completer (command, completer); |
44feb3ce TT |
15784 | } |
15785 | ||
6c95b8df | 15786 | static void |
a79b8f6e | 15787 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15788 | { |
fa3064dd YQ |
15789 | struct catch_syscall_inferior_data *inf_data |
15790 | = get_catch_syscall_inferior_data (inf); | |
15791 | ||
15792 | inf_data->total_syscalls_count = 0; | |
15793 | inf_data->any_syscall_count = 0; | |
15794 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15795 | } |
15796 | ||
6149aea9 PA |
15797 | static void |
15798 | save_command (char *arg, int from_tty) | |
15799 | { | |
3e43a32a MS |
15800 | printf_unfiltered (_("\"save\" must be followed by " |
15801 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15802 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15803 | } | |
15804 | ||
84f4c1fe PM |
15805 | struct breakpoint * |
15806 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15807 | void *data) | |
15808 | { | |
35df4500 | 15809 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15810 | |
35df4500 | 15811 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15812 | { |
15813 | if ((*callback) (b, data)) | |
15814 | return b; | |
15815 | } | |
15816 | ||
15817 | return NULL; | |
15818 | } | |
15819 | ||
0574c78f GB |
15820 | /* Zero if any of the breakpoint's locations could be a location where |
15821 | functions have been inlined, nonzero otherwise. */ | |
15822 | ||
15823 | static int | |
15824 | is_non_inline_function (struct breakpoint *b) | |
15825 | { | |
15826 | /* The shared library event breakpoint is set on the address of a | |
15827 | non-inline function. */ | |
15828 | if (b->type == bp_shlib_event) | |
15829 | return 1; | |
15830 | ||
15831 | return 0; | |
15832 | } | |
15833 | ||
15834 | /* Nonzero if the specified PC cannot be a location where functions | |
15835 | have been inlined. */ | |
15836 | ||
15837 | int | |
09ac7c10 TT |
15838 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15839 | const struct target_waitstatus *ws) | |
0574c78f GB |
15840 | { |
15841 | struct breakpoint *b; | |
15842 | struct bp_location *bl; | |
15843 | ||
15844 | ALL_BREAKPOINTS (b) | |
15845 | { | |
15846 | if (!is_non_inline_function (b)) | |
15847 | continue; | |
15848 | ||
15849 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15850 | { | |
15851 | if (!bl->shlib_disabled | |
09ac7c10 | 15852 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15853 | return 1; |
15854 | } | |
15855 | } | |
15856 | ||
15857 | return 0; | |
15858 | } | |
15859 | ||
2f202fde JK |
15860 | /* Remove any references to OBJFILE which is going to be freed. */ |
15861 | ||
15862 | void | |
15863 | breakpoint_free_objfile (struct objfile *objfile) | |
15864 | { | |
15865 | struct bp_location **locp, *loc; | |
15866 | ||
15867 | ALL_BP_LOCATIONS (loc, locp) | |
15868 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15869 | loc->symtab = NULL; | |
15870 | } | |
15871 | ||
2060206e PA |
15872 | void |
15873 | initialize_breakpoint_ops (void) | |
15874 | { | |
15875 | static int initialized = 0; | |
15876 | ||
15877 | struct breakpoint_ops *ops; | |
15878 | ||
15879 | if (initialized) | |
15880 | return; | |
15881 | initialized = 1; | |
15882 | ||
15883 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15884 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15885 | internal and momentary breakpoints, etc.). */ | |
15886 | ops = &bkpt_base_breakpoint_ops; | |
15887 | *ops = base_breakpoint_ops; | |
15888 | ops->re_set = bkpt_re_set; | |
15889 | ops->insert_location = bkpt_insert_location; | |
15890 | ops->remove_location = bkpt_remove_location; | |
15891 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15892 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15893 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15894 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15895 | |
15896 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15897 | ops = &bkpt_breakpoint_ops; | |
15898 | *ops = bkpt_base_breakpoint_ops; | |
15899 | ops->re_set = bkpt_re_set; | |
15900 | ops->resources_needed = bkpt_resources_needed; | |
15901 | ops->print_it = bkpt_print_it; | |
15902 | ops->print_mention = bkpt_print_mention; | |
15903 | ops->print_recreate = bkpt_print_recreate; | |
15904 | ||
15905 | /* Ranged breakpoints. */ | |
15906 | ops = &ranged_breakpoint_ops; | |
15907 | *ops = bkpt_breakpoint_ops; | |
15908 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15909 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15910 | ops->print_it = print_it_ranged_breakpoint; | |
15911 | ops->print_one = print_one_ranged_breakpoint; | |
15912 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15913 | ops->print_mention = print_mention_ranged_breakpoint; | |
15914 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15915 | ||
15916 | /* Internal breakpoints. */ | |
15917 | ops = &internal_breakpoint_ops; | |
15918 | *ops = bkpt_base_breakpoint_ops; | |
15919 | ops->re_set = internal_bkpt_re_set; | |
15920 | ops->check_status = internal_bkpt_check_status; | |
15921 | ops->print_it = internal_bkpt_print_it; | |
15922 | ops->print_mention = internal_bkpt_print_mention; | |
15923 | ||
15924 | /* Momentary breakpoints. */ | |
15925 | ops = &momentary_breakpoint_ops; | |
15926 | *ops = bkpt_base_breakpoint_ops; | |
15927 | ops->re_set = momentary_bkpt_re_set; | |
15928 | ops->check_status = momentary_bkpt_check_status; | |
15929 | ops->print_it = momentary_bkpt_print_it; | |
15930 | ops->print_mention = momentary_bkpt_print_mention; | |
15931 | ||
e2e4d78b JK |
15932 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15933 | ops = &longjmp_breakpoint_ops; | |
15934 | *ops = momentary_breakpoint_ops; | |
15935 | ops->dtor = longjmp_bkpt_dtor; | |
15936 | ||
55aa24fb SDJ |
15937 | /* Probe breakpoints. */ |
15938 | ops = &bkpt_probe_breakpoint_ops; | |
15939 | *ops = bkpt_breakpoint_ops; | |
15940 | ops->insert_location = bkpt_probe_insert_location; | |
15941 | ops->remove_location = bkpt_probe_remove_location; | |
15942 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
15943 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
15944 | ||
2060206e PA |
15945 | /* Watchpoints. */ |
15946 | ops = &watchpoint_breakpoint_ops; | |
15947 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15948 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15949 | ops->re_set = re_set_watchpoint; |
15950 | ops->insert_location = insert_watchpoint; | |
15951 | ops->remove_location = remove_watchpoint; | |
15952 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15953 | ops->check_status = check_status_watchpoint; | |
15954 | ops->resources_needed = resources_needed_watchpoint; | |
15955 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15956 | ops->print_it = print_it_watchpoint; | |
15957 | ops->print_mention = print_mention_watchpoint; | |
15958 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15959 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15960 | |
15961 | /* Masked watchpoints. */ | |
15962 | ops = &masked_watchpoint_breakpoint_ops; | |
15963 | *ops = watchpoint_breakpoint_ops; | |
15964 | ops->insert_location = insert_masked_watchpoint; | |
15965 | ops->remove_location = remove_masked_watchpoint; | |
15966 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15967 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15968 | ops->print_it = print_it_masked_watchpoint; | |
15969 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15970 | ops->print_mention = print_mention_masked_watchpoint; | |
15971 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15972 | ||
15973 | /* Tracepoints. */ | |
15974 | ops = &tracepoint_breakpoint_ops; | |
15975 | *ops = base_breakpoint_ops; | |
15976 | ops->re_set = tracepoint_re_set; | |
15977 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15978 | ops->print_one_detail = tracepoint_print_one_detail; | |
15979 | ops->print_mention = tracepoint_print_mention; | |
15980 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
15981 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
15982 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
15983 | ops->decode_linespec = tracepoint_decode_linespec; | |
15984 | ||
55aa24fb SDJ |
15985 | /* Probe tracepoints. */ |
15986 | ops = &tracepoint_probe_breakpoint_ops; | |
15987 | *ops = tracepoint_breakpoint_ops; | |
15988 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
15989 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
15990 | ||
983af33b SDJ |
15991 | /* Static tracepoints with marker (`-m'). */ |
15992 | ops = &strace_marker_breakpoint_ops; | |
15993 | *ops = tracepoint_breakpoint_ops; | |
15994 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
15995 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
15996 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
15997 | |
15998 | /* Fork catchpoints. */ | |
15999 | ops = &catch_fork_breakpoint_ops; | |
16000 | *ops = base_breakpoint_ops; | |
16001 | ops->insert_location = insert_catch_fork; | |
16002 | ops->remove_location = remove_catch_fork; | |
16003 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16004 | ops->print_it = print_it_catch_fork; | |
16005 | ops->print_one = print_one_catch_fork; | |
16006 | ops->print_mention = print_mention_catch_fork; | |
16007 | ops->print_recreate = print_recreate_catch_fork; | |
16008 | ||
16009 | /* Vfork catchpoints. */ | |
16010 | ops = &catch_vfork_breakpoint_ops; | |
16011 | *ops = base_breakpoint_ops; | |
16012 | ops->insert_location = insert_catch_vfork; | |
16013 | ops->remove_location = remove_catch_vfork; | |
16014 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16015 | ops->print_it = print_it_catch_vfork; | |
16016 | ops->print_one = print_one_catch_vfork; | |
16017 | ops->print_mention = print_mention_catch_vfork; | |
16018 | ops->print_recreate = print_recreate_catch_vfork; | |
16019 | ||
16020 | /* Exec catchpoints. */ | |
16021 | ops = &catch_exec_breakpoint_ops; | |
16022 | *ops = base_breakpoint_ops; | |
16023 | ops->dtor = dtor_catch_exec; | |
16024 | ops->insert_location = insert_catch_exec; | |
16025 | ops->remove_location = remove_catch_exec; | |
16026 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16027 | ops->print_it = print_it_catch_exec; | |
16028 | ops->print_one = print_one_catch_exec; | |
16029 | ops->print_mention = print_mention_catch_exec; | |
16030 | ops->print_recreate = print_recreate_catch_exec; | |
16031 | ||
16032 | /* Syscall catchpoints. */ | |
16033 | ops = &catch_syscall_breakpoint_ops; | |
16034 | *ops = base_breakpoint_ops; | |
16035 | ops->dtor = dtor_catch_syscall; | |
16036 | ops->insert_location = insert_catch_syscall; | |
16037 | ops->remove_location = remove_catch_syscall; | |
16038 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16039 | ops->print_it = print_it_catch_syscall; | |
16040 | ops->print_one = print_one_catch_syscall; | |
16041 | ops->print_mention = print_mention_catch_syscall; | |
16042 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16043 | |
16044 | /* Solib-related catchpoints. */ | |
16045 | ops = &catch_solib_breakpoint_ops; | |
16046 | *ops = base_breakpoint_ops; | |
16047 | ops->dtor = dtor_catch_solib; | |
16048 | ops->insert_location = insert_catch_solib; | |
16049 | ops->remove_location = remove_catch_solib; | |
16050 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16051 | ops->check_status = check_status_catch_solib; | |
16052 | ops->print_it = print_it_catch_solib; | |
16053 | ops->print_one = print_one_catch_solib; | |
16054 | ops->print_mention = print_mention_catch_solib; | |
16055 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16056 | |
16057 | ops = &dprintf_breakpoint_ops; | |
16058 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16059 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16060 | ops->resources_needed = bkpt_resources_needed; |
16061 | ops->print_it = bkpt_print_it; | |
16062 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16063 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16064 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16065 | } |
16066 | ||
8bfd80db YQ |
16067 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16068 | ||
16069 | static struct cmd_list_element *enablebreaklist = NULL; | |
16070 | ||
c906108c | 16071 | void |
fba45db2 | 16072 | _initialize_breakpoint (void) |
c906108c SS |
16073 | { |
16074 | struct cmd_list_element *c; | |
16075 | ||
2060206e PA |
16076 | initialize_breakpoint_ops (); |
16077 | ||
84acb35a | 16078 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16079 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16080 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16081 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16082 | |
55aa24fb SDJ |
16083 | breakpoint_objfile_key |
16084 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16085 | |
fa3064dd | 16086 | catch_syscall_inferior_data |
8e260fc0 TT |
16087 | = register_inferior_data_with_cleanup (NULL, |
16088 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16089 | |
c906108c SS |
16090 | breakpoint_chain = 0; |
16091 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16092 | before a breakpoint is set. */ | |
16093 | breakpoint_count = 0; | |
16094 | ||
1042e4c0 SS |
16095 | tracepoint_count = 0; |
16096 | ||
1bedd215 AC |
16097 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16098 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16099 | Usage is `ignore N COUNT'.")); | |
c906108c | 16100 | if (xdb_commands) |
c5aa993b | 16101 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16102 | |
1bedd215 AC |
16103 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16104 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16105 | Give breakpoint number as argument after \"commands\".\n\ |
16106 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16107 | The commands themselves follow starting on the next line.\n\ | |
16108 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16109 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16110 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16111 | |
d55637df | 16112 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16113 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16114 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16115 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16116 | set_cmd_completer (c, condition_completer); |
c906108c | 16117 | |
1bedd215 | 16118 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16119 | Set a temporary breakpoint.\n\ |
c906108c SS |
16120 | Like \"break\" except the breakpoint is only temporary,\n\ |
16121 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16122 | by using \"enable delete\" on the breakpoint number.\n\ |
16123 | \n" | |
16124 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16125 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16126 | |
1bedd215 | 16127 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16128 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16129 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16130 | some target hardware may not have this support.\n\ |
16131 | \n" | |
16132 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16133 | set_cmd_completer (c, location_completer); |
c906108c | 16134 | |
1bedd215 | 16135 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16136 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16137 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16138 | so it will be deleted when hit.\n\ |
16139 | \n" | |
16140 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16141 | set_cmd_completer (c, location_completer); |
c906108c | 16142 | |
1bedd215 AC |
16143 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16144 | Enable some breakpoints.\n\ | |
c906108c SS |
16145 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16146 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16147 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16148 | With a subcommand you can enable temporarily."), |
c906108c SS |
16149 | &enablelist, "enable ", 1, &cmdlist); |
16150 | if (xdb_commands) | |
1bedd215 AC |
16151 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16152 | Enable some breakpoints.\n\ | |
c906108c SS |
16153 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16154 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16155 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16156 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16157 | |
16158 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16159 | ||
84951ab5 | 16160 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16161 | Enable some breakpoints.\n\ |
c906108c SS |
16162 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16163 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16164 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16165 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16166 | |
1a966eab AC |
16167 | add_cmd ("once", no_class, enable_once_command, _("\ |
16168 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16169 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16170 | &enablebreaklist); |
16171 | ||
1a966eab AC |
16172 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16173 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16174 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16175 | &enablebreaklist); |
16176 | ||
816338b5 SS |
16177 | add_cmd ("count", no_class, enable_count_command, _("\ |
16178 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16179 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16180 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16181 | &enablebreaklist); | |
16182 | ||
1a966eab AC |
16183 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16184 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16185 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16186 | &enablelist); |
16187 | ||
1a966eab AC |
16188 | add_cmd ("once", no_class, enable_once_command, _("\ |
16189 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16190 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16191 | &enablelist); |
16192 | ||
16193 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16194 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16195 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16196 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16197 | &enablelist); |
16198 | ||
1bedd215 AC |
16199 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16200 | Disable some breakpoints.\n\ | |
c906108c SS |
16201 | Arguments are breakpoint numbers with spaces in between.\n\ |
16202 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16203 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16204 | &disablelist, "disable ", 1, &cmdlist); |
16205 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16206 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16207 | if (xdb_commands) | |
1bedd215 AC |
16208 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16209 | Disable some breakpoints.\n\ | |
c906108c SS |
16210 | Arguments are breakpoint numbers with spaces in between.\n\ |
16211 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16212 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16213 | |
1a966eab AC |
16214 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16215 | Disable some breakpoints.\n\ | |
c906108c SS |
16216 | Arguments are breakpoint numbers with spaces in between.\n\ |
16217 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16218 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16219 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16220 | &disablelist); |
16221 | ||
1bedd215 AC |
16222 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16223 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16224 | Arguments are breakpoint numbers with spaces in between.\n\ |
16225 | To delete all breakpoints, give no argument.\n\ | |
16226 | \n\ | |
16227 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16228 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16229 | &deletelist, "delete ", 1, &cmdlist); |
16230 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16231 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16232 | if (xdb_commands) |
1bedd215 AC |
16233 | add_com ("db", class_breakpoint, delete_command, _("\ |
16234 | Delete some breakpoints.\n\ | |
c906108c | 16235 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16236 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16237 | |
1a966eab AC |
16238 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16239 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16240 | Arguments are breakpoint numbers with spaces in between.\n\ |
16241 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16242 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16243 | &deletelist); |
16244 | ||
1bedd215 AC |
16245 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16246 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16247 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16248 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16249 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16250 | If an address is specified, breakpoints at that address are cleared.\n\ |
16251 | \n\ | |
16252 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16253 | is executing in.\n\ |
16254 | \n\ | |
1bedd215 | 16255 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16256 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16257 | |
1bedd215 | 16258 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16259 | Set breakpoint at specified line or function.\n" |
16260 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16261 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16262 | |
c906108c SS |
16263 | add_com_alias ("b", "break", class_run, 1); |
16264 | add_com_alias ("br", "break", class_run, 1); | |
16265 | add_com_alias ("bre", "break", class_run, 1); | |
16266 | add_com_alias ("brea", "break", class_run, 1); | |
16267 | ||
7681d515 PM |
16268 | if (xdb_commands) |
16269 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16270 | |
16271 | if (dbx_commands) | |
16272 | { | |
1bedd215 AC |
16273 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16274 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16275 | &stoplist, "stop ", 1, &cmdlist); |
16276 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16277 | _("Break in function or address."), &stoplist); |
c5aa993b | 16278 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16279 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16280 | add_com ("status", class_info, breakpoints_info, _("\ |
16281 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16282 | The \"Type\" column indicates one of:\n\ |
16283 | \tbreakpoint - normal breakpoint\n\ | |
16284 | \twatchpoint - watchpoint\n\ | |
16285 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16286 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16287 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16288 | address and file/line number respectively.\n\ |
16289 | \n\ | |
16290 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16291 | are set to the address of the last breakpoint listed unless the command\n\ |
16292 | is prefixed with \"server \".\n\n\ | |
c906108c | 16293 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16294 | breakpoint set.")); |
c906108c SS |
16295 | } |
16296 | ||
1bedd215 | 16297 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16298 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16299 | The \"Type\" column indicates one of:\n\ |
16300 | \tbreakpoint - normal breakpoint\n\ | |
16301 | \twatchpoint - watchpoint\n\ | |
16302 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16303 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16304 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16305 | address and file/line number respectively.\n\ |
16306 | \n\ | |
16307 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16308 | are set to the address of the last breakpoint listed unless the command\n\ |
16309 | is prefixed with \"server \".\n\n\ | |
c906108c | 16310 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16311 | breakpoint set.")); |
c906108c | 16312 | |
6b04bdb7 MS |
16313 | add_info_alias ("b", "breakpoints", 1); |
16314 | ||
c906108c | 16315 | if (xdb_commands) |
1bedd215 AC |
16316 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16317 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16318 | The \"Type\" column indicates one of:\n\ |
16319 | \tbreakpoint - normal breakpoint\n\ | |
16320 | \twatchpoint - watchpoint\n\ | |
16321 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16322 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16323 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16324 | address and file/line number respectively.\n\ |
16325 | \n\ | |
16326 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16327 | are set to the address of the last breakpoint listed unless the command\n\ |
16328 | is prefixed with \"server \".\n\n\ | |
c906108c | 16329 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16330 | breakpoint set.")); |
c906108c | 16331 | |
1a966eab AC |
16332 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16333 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16334 | The \"Type\" column indicates one of:\n\ |
16335 | \tbreakpoint - normal breakpoint\n\ | |
16336 | \twatchpoint - watchpoint\n\ | |
16337 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16338 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16339 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16340 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16341 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16342 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16343 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16344 | address and file/line number respectively.\n\ |
16345 | \n\ | |
16346 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16347 | are set to the address of the last breakpoint listed unless the command\n\ |
16348 | is prefixed with \"server \".\n\n\ | |
c906108c | 16349 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16350 | breakpoint set."), |
c906108c SS |
16351 | &maintenanceinfolist); |
16352 | ||
44feb3ce TT |
16353 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16354 | Set catchpoints to catch events."), | |
16355 | &catch_cmdlist, "catch ", | |
16356 | 0/*allow-unknown*/, &cmdlist); | |
16357 | ||
16358 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16359 | Set temporary catchpoints to catch events."), | |
16360 | &tcatch_cmdlist, "tcatch ", | |
16361 | 0/*allow-unknown*/, &cmdlist); | |
16362 | ||
44feb3ce TT |
16363 | add_catch_command ("fork", _("Catch calls to fork."), |
16364 | catch_fork_command_1, | |
a96d9b2e | 16365 | NULL, |
44feb3ce TT |
16366 | (void *) (uintptr_t) catch_fork_permanent, |
16367 | (void *) (uintptr_t) catch_fork_temporary); | |
16368 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16369 | catch_fork_command_1, | |
a96d9b2e | 16370 | NULL, |
44feb3ce TT |
16371 | (void *) (uintptr_t) catch_vfork_permanent, |
16372 | (void *) (uintptr_t) catch_vfork_temporary); | |
16373 | add_catch_command ("exec", _("Catch calls to exec."), | |
16374 | catch_exec_command_1, | |
a96d9b2e SDJ |
16375 | NULL, |
16376 | CATCH_PERMANENT, | |
16377 | CATCH_TEMPORARY); | |
edcc5120 TT |
16378 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16379 | Usage: catch load [REGEX]\n\ | |
16380 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16381 | catch_load_command_1, | |
16382 | NULL, | |
16383 | CATCH_PERMANENT, | |
16384 | CATCH_TEMPORARY); | |
16385 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16386 | Usage: catch unload [REGEX]\n\ | |
16387 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16388 | catch_unload_command_1, | |
16389 | NULL, | |
16390 | CATCH_PERMANENT, | |
16391 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16392 | add_catch_command ("syscall", _("\ |
16393 | Catch system calls by their names and/or numbers.\n\ | |
16394 | Arguments say which system calls to catch. If no arguments\n\ | |
16395 | are given, every system call will be caught.\n\ | |
16396 | Arguments, if given, should be one or more system call names\n\ | |
16397 | (if your system supports that), or system call numbers."), | |
16398 | catch_syscall_command_1, | |
16399 | catch_syscall_completer, | |
44feb3ce TT |
16400 | CATCH_PERMANENT, |
16401 | CATCH_TEMPORARY); | |
c5aa993b | 16402 | |
1bedd215 AC |
16403 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16404 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16405 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16406 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16407 | an expression changes.\n\ |
16408 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16409 | the memory to which it refers.")); | |
65d12d83 | 16410 | set_cmd_completer (c, expression_completer); |
c906108c | 16411 | |
1bedd215 AC |
16412 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16413 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16414 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16415 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16416 | an expression is read.\n\ |
16417 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16418 | the memory to which it refers.")); | |
65d12d83 | 16419 | set_cmd_completer (c, expression_completer); |
c906108c | 16420 | |
1bedd215 AC |
16421 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16422 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16423 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16424 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16425 | an expression is either read or written.\n\ |
16426 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16427 | the memory to which it refers.")); | |
65d12d83 | 16428 | set_cmd_completer (c, expression_completer); |
c906108c | 16429 | |
d77f58be | 16430 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16431 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16432 | |
920d2a44 AC |
16433 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16434 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16435 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16436 | &can_use_hw_watchpoints, _("\ | |
16437 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16438 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16439 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16440 | such is available. (However, any hardware watchpoints that were\n\ | |
16441 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16442 | hardware.)"), |
16443 | NULL, | |
920d2a44 | 16444 | show_can_use_hw_watchpoints, |
85c07804 | 16445 | &setlist, &showlist); |
c906108c SS |
16446 | |
16447 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16448 | |
1042e4c0 SS |
16449 | /* Tracepoint manipulation commands. */ |
16450 | ||
16451 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16452 | Set a tracepoint at specified line or function.\n\ | |
16453 | \n" | |
16454 | BREAK_ARGS_HELP ("trace") "\n\ | |
16455 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16456 | set_cmd_completer (c, location_completer); | |
16457 | ||
16458 | add_com_alias ("tp", "trace", class_alias, 0); | |
16459 | add_com_alias ("tr", "trace", class_alias, 1); | |
16460 | add_com_alias ("tra", "trace", class_alias, 1); | |
16461 | add_com_alias ("trac", "trace", class_alias, 1); | |
16462 | ||
7a697b8d SS |
16463 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16464 | Set a fast tracepoint at specified line or function.\n\ | |
16465 | \n" | |
16466 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16467 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16468 | set_cmd_completer (c, location_completer); | |
16469 | ||
0fb4aa4b PA |
16470 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16471 | Set a static tracepoint at specified line, function or marker.\n\ | |
16472 | \n\ | |
16473 | strace [LOCATION] [if CONDITION]\n\ | |
16474 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16475 | or -m MARKER_ID.\n\ | |
16476 | If a line number is specified, probe the marker at start of code\n\ | |
16477 | for that line. If a function is specified, probe the marker at start\n\ | |
16478 | of code for that function. If an address is specified, probe the marker\n\ | |
16479 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16480 | with that name. With no LOCATION, uses current execution address of\n\ | |
16481 | the selected stack frame.\n\ | |
16482 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16483 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16484 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16485 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16486 | \n\ | |
16487 | CONDITION is a boolean expression.\n\ | |
16488 | \n\ | |
d41c0fc8 PA |
16489 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16490 | conditions are different.\n\ | |
0fb4aa4b PA |
16491 | \n\ |
16492 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16493 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16494 | set_cmd_completer (c, location_completer); | |
16495 | ||
1042e4c0 | 16496 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16497 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16498 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16499 | last tracepoint set.")); | |
16500 | ||
16501 | add_info_alias ("tp", "tracepoints", 1); | |
16502 | ||
16503 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16504 | Delete specified tracepoints.\n\ | |
16505 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16506 | No argument means delete all tracepoints."), | |
16507 | &deletelist); | |
7e20dfcd | 16508 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16509 | |
16510 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16511 | Disable specified tracepoints.\n\ | |
16512 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16513 | No argument means disable all tracepoints."), | |
16514 | &disablelist); | |
16515 | deprecate_cmd (c, "disable"); | |
16516 | ||
16517 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16518 | Enable specified tracepoints.\n\ | |
16519 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16520 | No argument means enable all tracepoints."), | |
16521 | &enablelist); | |
16522 | deprecate_cmd (c, "enable"); | |
16523 | ||
16524 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16525 | Set the passcount for a tracepoint.\n\ | |
16526 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16527 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16528 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16529 | ||
6149aea9 PA |
16530 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16531 | _("Save breakpoint definitions as a script."), | |
16532 | &save_cmdlist, "save ", | |
16533 | 0/*allow-unknown*/, &cmdlist); | |
16534 | ||
16535 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16536 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16537 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16538 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16539 | session to restore them."), | |
16540 | &save_cmdlist); | |
16541 | set_cmd_completer (c, filename_completer); | |
16542 | ||
16543 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16544 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16545 | Use the 'source' command in another debug session to restore them."), |
16546 | &save_cmdlist); | |
1042e4c0 SS |
16547 | set_cmd_completer (c, filename_completer); |
16548 | ||
6149aea9 PA |
16549 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16550 | deprecate_cmd (c, "save tracepoints"); | |
16551 | ||
1bedd215 | 16552 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16553 | Breakpoint specific settings\n\ |
16554 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16555 | pending breakpoint behavior"), |
fa8d40ab JJ |
16556 | &breakpoint_set_cmdlist, "set breakpoint ", |
16557 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16558 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16559 | Breakpoint specific settings\n\ |
16560 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16561 | pending breakpoint behavior"), |
fa8d40ab JJ |
16562 | &breakpoint_show_cmdlist, "show breakpoint ", |
16563 | 0/*allow-unknown*/, &showlist); | |
16564 | ||
7915a72c AC |
16565 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16566 | &pending_break_support, _("\ | |
16567 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16568 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16569 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16570 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16571 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16572 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16573 | NULL, |
920d2a44 | 16574 | show_pending_break_support, |
6e1d7d6c AC |
16575 | &breakpoint_set_cmdlist, |
16576 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16577 | |
16578 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16579 | |
16580 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16581 | &automatic_hardware_breakpoints, _("\ | |
16582 | Set automatic usage of hardware breakpoints."), _("\ | |
16583 | Show automatic usage of hardware breakpoints."), _("\ | |
16584 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16585 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16586 | a warning will be emitted for such breakpoints."), | |
16587 | NULL, | |
16588 | show_automatic_hardware_breakpoints, | |
16589 | &breakpoint_set_cmdlist, | |
16590 | &breakpoint_show_cmdlist); | |
74960c60 | 16591 | |
72d0e2c5 YQ |
16592 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16593 | &always_inserted_mode, _("\ | |
74960c60 VP |
16594 | Set mode for inserting breakpoints."), _("\ |
16595 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16596 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16597 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16598 | breakpoints are inserted immediately and removed only when the user\n\ | |
16599 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16600 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16601 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16602 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16603 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16604 | NULL, |
16605 | &show_always_inserted_mode, | |
16606 | &breakpoint_set_cmdlist, | |
16607 | &breakpoint_show_cmdlist); | |
f1310107 | 16608 | |
b775012e LM |
16609 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16610 | condition_evaluation_enums, | |
16611 | &condition_evaluation_mode_1, _("\ | |
16612 | Set mode of breakpoint condition evaluation."), _("\ | |
16613 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16614 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16615 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16616 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16617 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16618 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16619 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16620 | be set to \"gdb\""), | |
16621 | &set_condition_evaluation_mode, | |
16622 | &show_condition_evaluation_mode, | |
16623 | &breakpoint_set_cmdlist, | |
16624 | &breakpoint_show_cmdlist); | |
16625 | ||
f1310107 TJB |
16626 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16627 | Set a breakpoint for an address range.\n\ | |
16628 | break-range START-LOCATION, END-LOCATION\n\ | |
16629 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16630 | LINENUM, for that line in the current file,\n\ | |
16631 | FILE:LINENUM, for that line in that file,\n\ | |
16632 | +OFFSET, for that number of lines after the current line\n\ | |
16633 | or the start of the range\n\ | |
16634 | FUNCTION, for the first line in that function,\n\ | |
16635 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16636 | *ADDRESS, for the instruction at that address.\n\ | |
16637 | \n\ | |
16638 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16639 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16640 | range (including START-LOCATION and END-LOCATION).")); | |
16641 | ||
e7e0cddf SS |
16642 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16643 | Set a dynamic printf at specified line or function.\n\ | |
16644 | dprintf location,format string,arg1,arg2,...\n\ | |
16645 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16646 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16647 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16648 | set_cmd_completer (c, location_completer); |
16649 | ||
16650 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16651 | dprintf_style_enums, &dprintf_style, _("\ | |
16652 | Set the style of usage for dynamic printf."), _("\ | |
16653 | Show the style of usage for dynamic printf."), _("\ | |
16654 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16655 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16656 | console, as with the \"printf\" command.\n\ | |
16657 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16658 | program; by default printf(), but you can choose a different function or\n\ | |
16659 | output stream by setting dprintf-function and dprintf-channel."), | |
16660 | update_dprintf_commands, NULL, | |
16661 | &setlist, &showlist); | |
16662 | ||
16663 | dprintf_function = xstrdup ("printf"); | |
16664 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16665 | &dprintf_function, _("\ | |
16666 | Set the function to use for dynamic printf"), _("\ | |
16667 | Show the function to use for dynamic printf"), NULL, | |
16668 | update_dprintf_commands, NULL, | |
16669 | &setlist, &showlist); | |
16670 | ||
16671 | dprintf_channel = xstrdup (""); | |
16672 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16673 | &dprintf_channel, _("\ | |
16674 | Set the channel to use for dynamic printf"), _("\ | |
16675 | Show the channel to use for dynamic printf"), NULL, | |
16676 | update_dprintf_commands, NULL, | |
16677 | &setlist, &showlist); | |
16678 | ||
d3ce09f5 SS |
16679 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16680 | &disconnected_dprintf, _("\ | |
16681 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16682 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16683 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16684 | even if GDB disconnects or detaches from the target."), | |
16685 | NULL, | |
16686 | NULL, | |
16687 | &setlist, &showlist); | |
16688 | ||
16689 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16690 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16691 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16692 | ||
765dc015 | 16693 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16694 | |
16695 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16696 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16697 | } |