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 | |
1808 | error (_("Software read/access watchpoints not supported.")); | |
1809 | } | |
2d134ed3 PA |
1810 | } |
1811 | else if (within_current_scope && b->exp) | |
a5606eee | 1812 | { |
0cf6dd15 | 1813 | int pc = 0; |
fa4727a6 | 1814 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1815 | struct program_space *frame_pspace; |
a5606eee | 1816 | |
3a1115a0 | 1817 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1818 | |
a5606eee VP |
1819 | /* Avoid setting b->val if it's already set. The meaning of |
1820 | b->val is 'the last value' user saw, and we should update | |
1821 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1822 | happens, the code that reports it updates b->val directly. |
1823 | We don't keep track of the memory value for masked | |
1824 | watchpoints. */ | |
3a5c3e22 | 1825 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1826 | { |
1827 | b->val = v; | |
1828 | b->val_valid = 1; | |
1829 | } | |
a5606eee | 1830 | |
2d134ed3 PA |
1831 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1832 | ||
a5606eee | 1833 | /* Look at each value on the value chain. */ |
9fa40276 | 1834 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1835 | { |
1836 | /* If it's a memory location, and GDB actually needed | |
1837 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1838 | must watch it. If the first value returned is |
1839 | still lazy, that means an error occurred reading it; | |
1840 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1841 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1842 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1843 | { |
1844 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1845 | |
a5606eee VP |
1846 | /* We only watch structs and arrays if user asked |
1847 | for it explicitly, never if they just happen to | |
1848 | appear in the middle of some value chain. */ | |
fa4727a6 | 1849 | if (v == result |
a5606eee VP |
1850 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1851 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1852 | { | |
1853 | CORE_ADDR addr; | |
744a8059 | 1854 | int type; |
a5606eee VP |
1855 | struct bp_location *loc, **tmp; |
1856 | ||
42ae5230 | 1857 | addr = value_address (v); |
a5606eee | 1858 | type = hw_write; |
3a5c3e22 | 1859 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1860 | type = hw_read; |
3a5c3e22 | 1861 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1862 | type = hw_access; |
3a5c3e22 PA |
1863 | |
1864 | loc = allocate_bp_location (&b->base); | |
1865 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1866 | ; |
1867 | *tmp = loc; | |
a6d9a66e | 1868 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1869 | |
1870 | loc->pspace = frame_pspace; | |
a5606eee | 1871 | loc->address = addr; |
744a8059 | 1872 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1873 | loc->watchpoint_type = type; |
1874 | } | |
1875 | } | |
9fa40276 TJB |
1876 | } |
1877 | ||
1878 | /* Change the type of breakpoint between hardware assisted or | |
1879 | an ordinary watchpoint depending on the hardware support | |
1880 | and free hardware slots. REPARSE is set when the inferior | |
1881 | is started. */ | |
a9634178 | 1882 | if (reparse) |
9fa40276 | 1883 | { |
e09342b5 | 1884 | int reg_cnt; |
9fa40276 TJB |
1885 | enum bp_loc_type loc_type; |
1886 | struct bp_location *bl; | |
a5606eee | 1887 | |
a9634178 | 1888 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1889 | |
1890 | if (reg_cnt) | |
9fa40276 TJB |
1891 | { |
1892 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1893 | enum bptype type; |
9fa40276 | 1894 | |
a9634178 TJB |
1895 | /* Use an exact watchpoint when there's only one memory region to be |
1896 | watched, and only one debug register is needed to watch it. */ | |
1897 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1898 | ||
9fa40276 | 1899 | /* We need to determine how many resources are already |
e09342b5 TJB |
1900 | used for all other hardware watchpoints plus this one |
1901 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1902 | this watchpoint in as well. */ |
1903 | ||
1904 | /* If this is a software watchpoint, we try to turn it | |
1905 | to a hardware one -- count resources as if B was of | |
1906 | hardware watchpoint type. */ | |
1907 | type = b->base.type; | |
1908 | if (type == bp_watchpoint) | |
1909 | type = bp_hardware_watchpoint; | |
1910 | ||
1911 | /* This watchpoint may or may not have been placed on | |
1912 | the list yet at this point (it won't be in the list | |
1913 | if we're trying to create it for the first time, | |
1914 | through watch_command), so always account for it | |
1915 | manually. */ | |
1916 | ||
1917 | /* Count resources used by all watchpoints except B. */ | |
1918 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1919 | ||
1920 | /* Add in the resources needed for B. */ | |
1921 | i += hw_watchpoint_use_count (&b->base); | |
1922 | ||
1923 | target_resources_ok | |
1924 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1925 | if (target_resources_ok <= 0) |
a9634178 | 1926 | { |
3a5c3e22 | 1927 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1928 | |
1929 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1930 | error (_("Target does not support this type of " |
1931 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1932 | else if (target_resources_ok < 0 && !sw_mode) |
1933 | error (_("There are not enough available hardware " | |
1934 | "resources for this watchpoint.")); | |
a1398e0c PA |
1935 | |
1936 | /* Downgrade to software watchpoint. */ | |
1937 | b->base.type = bp_watchpoint; | |
1938 | } | |
1939 | else | |
1940 | { | |
1941 | /* If this was a software watchpoint, we've just | |
1942 | found we have enough resources to turn it to a | |
1943 | hardware watchpoint. Otherwise, this is a | |
1944 | nop. */ | |
1945 | b->base.type = type; | |
a9634178 | 1946 | } |
9fa40276 | 1947 | } |
3a5c3e22 | 1948 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1949 | error (_("Expression cannot be implemented with " |
1950 | "read/access watchpoint.")); | |
9fa40276 | 1951 | else |
3a5c3e22 | 1952 | b->base.type = bp_watchpoint; |
9fa40276 | 1953 | |
3a5c3e22 | 1954 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1955 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1956 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1957 | bl->loc_type = loc_type; |
1958 | } | |
1959 | ||
1960 | for (v = val_chain; v; v = next) | |
1961 | { | |
a5606eee VP |
1962 | next = value_next (v); |
1963 | if (v != b->val) | |
1964 | value_free (v); | |
1965 | } | |
1966 | ||
c7437ca6 PA |
1967 | /* If a software watchpoint is not watching any memory, then the |
1968 | above left it without any location set up. But, | |
1969 | bpstat_stop_status requires a location to be able to report | |
1970 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1971 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1972 | { |
3a5c3e22 PA |
1973 | struct breakpoint *base = &b->base; |
1974 | base->loc = allocate_bp_location (base); | |
1975 | base->loc->pspace = frame_pspace; | |
1976 | base->loc->address = -1; | |
1977 | base->loc->length = -1; | |
1978 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1979 | } |
a5606eee VP |
1980 | } |
1981 | else if (!within_current_scope) | |
7270d8f2 | 1982 | { |
ac74f770 MS |
1983 | printf_filtered (_("\ |
1984 | Watchpoint %d deleted because the program has left the block\n\ | |
1985 | in which its expression is valid.\n"), | |
3a5c3e22 | 1986 | b->base.number); |
d0fb5eae | 1987 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1988 | } |
a5606eee VP |
1989 | |
1990 | /* Restore the selected frame. */ | |
66076460 DJ |
1991 | if (frame_saved) |
1992 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1993 | } |
1994 | ||
a5606eee | 1995 | |
74960c60 | 1996 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1997 | inserted in the inferior. We don't differentiate the type of BL's owner |
1998 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1999 | breakpoint_ops is not defined, because in insert_bp_location, | |
2000 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2001 | static int |
35df4500 | 2002 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2003 | { |
35df4500 | 2004 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2005 | return 0; |
2006 | ||
35df4500 | 2007 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2008 | return 0; |
2009 | ||
35df4500 | 2010 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2011 | return 0; |
2012 | ||
f8eba3c6 TT |
2013 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2014 | return 0; | |
2015 | ||
56710373 PA |
2016 | /* This is set for example, when we're attached to the parent of a |
2017 | vfork, and have detached from the child. The child is running | |
2018 | free, and we expect it to do an exec or exit, at which point the | |
2019 | OS makes the parent schedulable again (and the target reports | |
2020 | that the vfork is done). Until the child is done with the shared | |
2021 | memory region, do not insert breakpoints in the parent, otherwise | |
2022 | the child could still trip on the parent's breakpoints. Since | |
2023 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2024 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2025 | return 0; |
2026 | ||
74960c60 VP |
2027 | return 1; |
2028 | } | |
2029 | ||
934709f0 PW |
2030 | /* Same as should_be_inserted but does the check assuming |
2031 | that the location is not duplicated. */ | |
2032 | ||
2033 | static int | |
2034 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2035 | { | |
2036 | int result; | |
2037 | const int save_duplicate = bl->duplicate; | |
2038 | ||
2039 | bl->duplicate = 0; | |
2040 | result = should_be_inserted (bl); | |
2041 | bl->duplicate = save_duplicate; | |
2042 | return result; | |
2043 | } | |
2044 | ||
b775012e LM |
2045 | /* Parses a conditional described by an expression COND into an |
2046 | agent expression bytecode suitable for evaluation | |
2047 | by the bytecode interpreter. Return NULL if there was | |
2048 | any error during parsing. */ | |
2049 | ||
2050 | static struct agent_expr * | |
2051 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2052 | { | |
2053 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2054 | volatile struct gdb_exception ex; |
2055 | ||
2056 | if (!cond) | |
2057 | return NULL; | |
2058 | ||
2059 | /* We don't want to stop processing, so catch any errors | |
2060 | that may show up. */ | |
2061 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2062 | { | |
2063 | aexpr = gen_eval_for_expr (scope, cond); | |
2064 | } | |
2065 | ||
2066 | if (ex.reason < 0) | |
2067 | { | |
2068 | /* If we got here, it means the condition could not be parsed to a valid | |
2069 | bytecode expression and thus can't be evaluated on the target's side. | |
2070 | It's no use iterating through the conditions. */ | |
2071 | return NULL; | |
2072 | } | |
2073 | ||
2074 | /* We have a valid agent expression. */ | |
2075 | return aexpr; | |
2076 | } | |
2077 | ||
2078 | /* Based on location BL, create a list of breakpoint conditions to be | |
2079 | passed on to the target. If we have duplicated locations with different | |
2080 | conditions, we will add such conditions to the list. The idea is that the | |
2081 | target will evaluate the list of conditions and will only notify GDB when | |
2082 | one of them is true. */ | |
2083 | ||
2084 | static void | |
2085 | build_target_condition_list (struct bp_location *bl) | |
2086 | { | |
2087 | struct bp_location **locp = NULL, **loc2p; | |
2088 | int null_condition_or_parse_error = 0; | |
2089 | int modified = bl->needs_update; | |
2090 | struct bp_location *loc; | |
2091 | ||
2092 | /* This is only meaningful if the target is | |
2093 | evaluating conditions and if the user has | |
2094 | opted for condition evaluation on the target's | |
2095 | side. */ | |
2096 | if (gdb_evaluates_breakpoint_condition_p () | |
2097 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2098 | return; | |
2099 | ||
2100 | /* Do a first pass to check for locations with no assigned | |
2101 | conditions or conditions that fail to parse to a valid agent expression | |
2102 | bytecode. If any of these happen, then it's no use to send conditions | |
2103 | to the target since this location will always trigger and generate a | |
2104 | response back to GDB. */ | |
2105 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2106 | { | |
2107 | loc = (*loc2p); | |
2108 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2109 | { | |
2110 | if (modified) | |
2111 | { | |
2112 | struct agent_expr *aexpr; | |
2113 | ||
2114 | /* Re-parse the conditions since something changed. In that | |
2115 | case we already freed the condition bytecodes (see | |
2116 | force_breakpoint_reinsertion). We just | |
2117 | need to parse the condition to bytecodes again. */ | |
2118 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2119 | loc->cond_bytecode = aexpr; | |
2120 | ||
2121 | /* Check if we managed to parse the conditional expression | |
2122 | correctly. If not, we will not send this condition | |
2123 | to the target. */ | |
2124 | if (aexpr) | |
2125 | continue; | |
2126 | } | |
2127 | ||
2128 | /* If we have a NULL bytecode expression, it means something | |
2129 | went wrong or we have a null condition expression. */ | |
2130 | if (!loc->cond_bytecode) | |
2131 | { | |
2132 | null_condition_or_parse_error = 1; | |
2133 | break; | |
2134 | } | |
2135 | } | |
2136 | } | |
2137 | ||
2138 | /* If any of these happened, it means we will have to evaluate the conditions | |
2139 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2140 | for all the other duplicate locations, thus we free all of them here. | |
2141 | ||
2142 | This is so we have a finer control over which locations' conditions are | |
2143 | being evaluated by GDB or the remote stub. */ | |
2144 | if (null_condition_or_parse_error) | |
2145 | { | |
2146 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2147 | { | |
2148 | loc = (*loc2p); | |
2149 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2150 | { | |
2151 | /* Only go as far as the first NULL bytecode is | |
2152 | located. */ | |
2153 | if (!loc->cond_bytecode) | |
2154 | return; | |
2155 | ||
2156 | free_agent_expr (loc->cond_bytecode); | |
2157 | loc->cond_bytecode = NULL; | |
2158 | } | |
2159 | } | |
2160 | } | |
2161 | ||
2162 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2163 | for this location's address. */ | |
2164 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2165 | { | |
2166 | loc = (*loc2p); | |
2167 | if (loc->cond | |
2168 | && is_breakpoint (loc->owner) | |
2169 | && loc->pspace->num == bl->pspace->num | |
2170 | && loc->owner->enable_state == bp_enabled | |
2171 | && loc->enabled) | |
2172 | /* Add the condition to the vector. This will be used later to send the | |
2173 | conditions to the target. */ | |
2174 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2175 | loc->cond_bytecode); | |
2176 | } | |
2177 | ||
2178 | return; | |
2179 | } | |
2180 | ||
d3ce09f5 SS |
2181 | /* Parses a command described by string CMD into an agent expression |
2182 | bytecode suitable for evaluation by the bytecode interpreter. | |
2183 | Return NULL if there was any error during parsing. */ | |
2184 | ||
2185 | static struct agent_expr * | |
2186 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2187 | { | |
2188 | struct cleanup *old_cleanups = 0; | |
2189 | struct expression *expr, **argvec; | |
2190 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2191 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2192 | const char *cmdrest; |
2193 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2194 | struct format_piece *fpieces; |
2195 | int nargs; | |
2196 | struct gdbarch *gdbarch = get_current_arch (); | |
2197 | ||
2198 | if (!cmd) | |
2199 | return NULL; | |
2200 | ||
2201 | cmdrest = cmd; | |
2202 | ||
2203 | if (*cmdrest == ',') | |
2204 | ++cmdrest; | |
bbc13ae3 | 2205 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2206 | |
2207 | if (*cmdrest++ != '"') | |
2208 | error (_("No format string following the location")); | |
2209 | ||
2210 | format_start = cmdrest; | |
2211 | ||
2212 | fpieces = parse_format_string (&cmdrest); | |
2213 | ||
2214 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2215 | ||
2216 | format_end = cmdrest; | |
2217 | ||
2218 | if (*cmdrest++ != '"') | |
2219 | error (_("Bad format string, non-terminated '\"'.")); | |
2220 | ||
bbc13ae3 | 2221 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2222 | |
2223 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2224 | error (_("Invalid argument syntax")); | |
2225 | ||
2226 | if (*cmdrest == ',') | |
2227 | cmdrest++; | |
bbc13ae3 | 2228 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2229 | |
2230 | /* For each argument, make an expression. */ | |
2231 | ||
2232 | argvec = (struct expression **) alloca (strlen (cmd) | |
2233 | * sizeof (struct expression *)); | |
2234 | ||
2235 | nargs = 0; | |
2236 | while (*cmdrest != '\0') | |
2237 | { | |
bbc13ae3 | 2238 | const char *cmd1; |
d3ce09f5 SS |
2239 | |
2240 | cmd1 = cmdrest; | |
2241 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2242 | argvec[nargs++] = expr; | |
2243 | cmdrest = cmd1; | |
2244 | if (*cmdrest == ',') | |
2245 | ++cmdrest; | |
2246 | } | |
2247 | ||
2248 | /* We don't want to stop processing, so catch any errors | |
2249 | that may show up. */ | |
2250 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2251 | { | |
2252 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2253 | format_start, format_end - format_start, | |
2254 | fpieces, nargs, argvec); | |
2255 | } | |
2256 | ||
752eb8b4 TT |
2257 | do_cleanups (old_cleanups); |
2258 | ||
d3ce09f5 SS |
2259 | if (ex.reason < 0) |
2260 | { | |
2261 | /* If we got here, it means the command could not be parsed to a valid | |
2262 | bytecode expression and thus can't be evaluated on the target's side. | |
2263 | It's no use iterating through the other commands. */ | |
2264 | return NULL; | |
2265 | } | |
2266 | ||
d3ce09f5 SS |
2267 | /* We have a valid agent expression, return it. */ |
2268 | return aexpr; | |
2269 | } | |
2270 | ||
2271 | /* Based on location BL, create a list of breakpoint commands to be | |
2272 | passed on to the target. If we have duplicated locations with | |
2273 | different commands, we will add any such to the list. */ | |
2274 | ||
2275 | static void | |
2276 | build_target_command_list (struct bp_location *bl) | |
2277 | { | |
2278 | struct bp_location **locp = NULL, **loc2p; | |
2279 | int null_command_or_parse_error = 0; | |
2280 | int modified = bl->needs_update; | |
2281 | struct bp_location *loc; | |
2282 | ||
2283 | /* For now, limit to agent-style dprintf breakpoints. */ | |
2284 | if (bl->owner->type != bp_dprintf | |
2285 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2286 | return; | |
2287 | ||
2288 | if (!target_can_run_breakpoint_commands ()) | |
2289 | return; | |
2290 | ||
2291 | /* Do a first pass to check for locations with no assigned | |
2292 | conditions or conditions that fail to parse to a valid agent expression | |
2293 | bytecode. If any of these happen, then it's no use to send conditions | |
2294 | to the target since this location will always trigger and generate a | |
2295 | response back to GDB. */ | |
2296 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2297 | { | |
2298 | loc = (*loc2p); | |
2299 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2300 | { | |
2301 | if (modified) | |
2302 | { | |
2303 | struct agent_expr *aexpr; | |
2304 | ||
2305 | /* Re-parse the commands since something changed. In that | |
2306 | case we already freed the command bytecodes (see | |
2307 | force_breakpoint_reinsertion). We just | |
2308 | need to parse the command to bytecodes again. */ | |
2309 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2310 | loc->owner->extra_string); | |
2311 | loc->cmd_bytecode = aexpr; | |
2312 | ||
2313 | if (!aexpr) | |
2314 | continue; | |
2315 | } | |
2316 | ||
2317 | /* If we have a NULL bytecode expression, it means something | |
2318 | went wrong or we have a null command expression. */ | |
2319 | if (!loc->cmd_bytecode) | |
2320 | { | |
2321 | null_command_or_parse_error = 1; | |
2322 | break; | |
2323 | } | |
2324 | } | |
2325 | } | |
2326 | ||
2327 | /* If anything failed, then we're not doing target-side commands, | |
2328 | and so clean up. */ | |
2329 | if (null_command_or_parse_error) | |
2330 | { | |
2331 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2332 | { | |
2333 | loc = (*loc2p); | |
2334 | if (is_breakpoint (loc->owner) | |
2335 | && loc->pspace->num == bl->pspace->num) | |
2336 | { | |
2337 | /* Only go as far as the first NULL bytecode is | |
2338 | located. */ | |
40fb6c5e | 2339 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2340 | return; |
2341 | ||
40fb6c5e HZ |
2342 | free_agent_expr (loc->cmd_bytecode); |
2343 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2344 | } |
2345 | } | |
2346 | } | |
2347 | ||
2348 | /* No NULL commands or failed bytecode generation. Build a command list | |
2349 | for this location's address. */ | |
2350 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2351 | { | |
2352 | loc = (*loc2p); | |
2353 | if (loc->owner->extra_string | |
2354 | && is_breakpoint (loc->owner) | |
2355 | && loc->pspace->num == bl->pspace->num | |
2356 | && loc->owner->enable_state == bp_enabled | |
2357 | && loc->enabled) | |
2358 | /* Add the command to the vector. This will be used later | |
2359 | to send the commands to the target. */ | |
2360 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2361 | loc->cmd_bytecode); | |
2362 | } | |
2363 | ||
2364 | bl->target_info.persist = 0; | |
2365 | /* Maybe flag this location as persistent. */ | |
2366 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2367 | bl->target_info.persist = 1; | |
2368 | } | |
2369 | ||
35df4500 TJB |
2370 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2371 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2372 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2373 | Returns 0 for success, 1 if the bp_location type is not supported or |
2374 | -1 for failure. | |
879bfdc2 | 2375 | |
4a64f543 MS |
2376 | NOTE drow/2003-09-09: This routine could be broken down to an |
2377 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2378 | static int |
35df4500 | 2379 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2380 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2381 | int *disabled_breaks, |
dd61ec5c MW |
2382 | int *hw_breakpoint_error, |
2383 | int *hw_bp_error_explained_already) | |
879bfdc2 DJ |
2384 | { |
2385 | int val = 0; | |
dd61ec5c MW |
2386 | char *hw_bp_err_string = NULL; |
2387 | struct gdb_exception e; | |
879bfdc2 | 2388 | |
b775012e | 2389 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2390 | return 0; |
2391 | ||
35c63cd8 JB |
2392 | /* Note we don't initialize bl->target_info, as that wipes out |
2393 | the breakpoint location's shadow_contents if the breakpoint | |
2394 | is still inserted at that location. This in turn breaks | |
2395 | target_read_memory which depends on these buffers when | |
2396 | a memory read is requested at the breakpoint location: | |
2397 | Once the target_info has been wiped, we fail to see that | |
2398 | we have a breakpoint inserted at that address and thus | |
2399 | read the breakpoint instead of returning the data saved in | |
2400 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2401 | bl->target_info.placed_address = bl->address; |
2402 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2403 | bl->target_info.length = bl->length; |
8181d85f | 2404 | |
b775012e LM |
2405 | /* When working with target-side conditions, we must pass all the conditions |
2406 | for the same breakpoint address down to the target since GDB will not | |
2407 | insert those locations. With a list of breakpoint conditions, the target | |
2408 | can decide when to stop and notify GDB. */ | |
2409 | ||
2410 | if (is_breakpoint (bl->owner)) | |
2411 | { | |
2412 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2413 | build_target_command_list (bl); |
2414 | /* Reset the modification marker. */ | |
b775012e LM |
2415 | bl->needs_update = 0; |
2416 | } | |
2417 | ||
35df4500 TJB |
2418 | if (bl->loc_type == bp_loc_software_breakpoint |
2419 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2420 | { |
35df4500 | 2421 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2422 | { |
2423 | /* If the explicitly specified breakpoint type | |
2424 | is not hardware breakpoint, check the memory map to see | |
2425 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2426 | |
765dc015 VP |
2427 | Two important cases are: |
2428 | - location type is not hardware breakpoint, memory | |
2429 | is readonly. We change the type of the location to | |
2430 | hardware breakpoint. | |
4a64f543 MS |
2431 | - location type is hardware breakpoint, memory is |
2432 | read-write. This means we've previously made the | |
2433 | location hardware one, but then the memory map changed, | |
2434 | so we undo. | |
765dc015 | 2435 | |
4a64f543 MS |
2436 | When breakpoints are removed, remove_breakpoints will use |
2437 | location types we've just set here, the only possible | |
2438 | problem is that memory map has changed during running | |
2439 | program, but it's not going to work anyway with current | |
2440 | gdb. */ | |
765dc015 | 2441 | struct mem_region *mr |
35df4500 | 2442 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2443 | |
2444 | if (mr) | |
2445 | { | |
2446 | if (automatic_hardware_breakpoints) | |
2447 | { | |
765dc015 VP |
2448 | enum bp_loc_type new_type; |
2449 | ||
2450 | if (mr->attrib.mode != MEM_RW) | |
2451 | new_type = bp_loc_hardware_breakpoint; | |
2452 | else | |
2453 | new_type = bp_loc_software_breakpoint; | |
2454 | ||
35df4500 | 2455 | if (new_type != bl->loc_type) |
765dc015 VP |
2456 | { |
2457 | static int said = 0; | |
cc59ec59 | 2458 | |
35df4500 | 2459 | bl->loc_type = new_type; |
765dc015 VP |
2460 | if (!said) |
2461 | { | |
3e43a32a MS |
2462 | fprintf_filtered (gdb_stdout, |
2463 | _("Note: automatically using " | |
2464 | "hardware breakpoints for " | |
2465 | "read-only addresses.\n")); | |
765dc015 VP |
2466 | said = 1; |
2467 | } | |
2468 | } | |
2469 | } | |
35df4500 | 2470 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2471 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2472 | warning (_("cannot set software breakpoint " |
2473 | "at readonly address %s"), | |
35df4500 | 2474 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2475 | } |
2476 | } | |
2477 | ||
879bfdc2 DJ |
2478 | /* First check to see if we have to handle an overlay. */ |
2479 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2480 | || bl->section == NULL |
2481 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2482 | { |
2483 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2484 | TRY_CATCH (e, RETURN_MASK_ALL) |
2485 | { | |
2486 | val = bl->owner->ops->insert_location (bl); | |
2487 | } | |
2488 | if (e.reason < 0) | |
2489 | { | |
2490 | val = 1; | |
2491 | hw_bp_err_string = (char *) e.message; | |
2492 | } | |
879bfdc2 DJ |
2493 | } |
2494 | else | |
2495 | { | |
4a64f543 | 2496 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2497 | Shall we set a breakpoint at the LMA? */ |
2498 | if (!overlay_events_enabled) | |
2499 | { | |
2500 | /* Yes -- overlay event support is not active, | |
2501 | so we must try to set a breakpoint at the LMA. | |
2502 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2503 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2504 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2505 | bl->owner->number); |
879bfdc2 DJ |
2506 | else |
2507 | { | |
35df4500 TJB |
2508 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2509 | bl->section); | |
879bfdc2 | 2510 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2511 | bl->overlay_target_info = bl->target_info; |
2512 | bl->overlay_target_info.placed_address = addr; | |
2513 | val = target_insert_breakpoint (bl->gdbarch, | |
2514 | &bl->overlay_target_info); | |
879bfdc2 | 2515 | if (val != 0) |
99361f52 | 2516 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2517 | "Overlay breakpoint %d " |
2518 | "failed: in ROM?\n", | |
35df4500 | 2519 | bl->owner->number); |
879bfdc2 DJ |
2520 | } |
2521 | } | |
2522 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2523 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2524 | { |
2525 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2526 | TRY_CATCH (e, RETURN_MASK_ALL) |
2527 | { | |
2528 | val = bl->owner->ops->insert_location (bl); | |
2529 | } | |
2530 | if (e.reason < 0) | |
2531 | { | |
2532 | val = 1; | |
2533 | hw_bp_err_string = (char *) e.message; | |
2534 | } | |
879bfdc2 DJ |
2535 | } |
2536 | else | |
2537 | { | |
2538 | /* No. This breakpoint will not be inserted. | |
2539 | No error, but do not mark the bp as 'inserted'. */ | |
2540 | return 0; | |
2541 | } | |
2542 | } | |
2543 | ||
2544 | if (val) | |
2545 | { | |
2546 | /* Can't set the breakpoint. */ | |
35df4500 | 2547 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2548 | { |
4a64f543 | 2549 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2550 | val = 0; |
35df4500 | 2551 | bl->shlib_disabled = 1; |
8d3788bd | 2552 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2553 | if (!*disabled_breaks) |
2554 | { | |
2555 | fprintf_unfiltered (tmp_error_stream, | |
2556 | "Cannot insert breakpoint %d.\n", | |
2557 | bl->owner->number); | |
2558 | fprintf_unfiltered (tmp_error_stream, | |
2559 | "Temporarily disabling shared " | |
2560 | "library breakpoints:\n"); | |
2561 | } | |
2562 | *disabled_breaks = 1; | |
879bfdc2 | 2563 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2564 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2565 | } |
2566 | else | |
879bfdc2 | 2567 | { |
35df4500 | 2568 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2569 | { |
dd61ec5c MW |
2570 | *hw_breakpoint_error = 1; |
2571 | *hw_bp_error_explained_already = hw_bp_err_string != NULL; | |
2572 | fprintf_unfiltered (tmp_error_stream, | |
2573 | "Cannot insert hardware breakpoint %d%s", | |
2574 | bl->owner->number, hw_bp_err_string ? ":" : ".\n"); | |
2575 | if (hw_bp_err_string) | |
2576 | fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string); | |
879bfdc2 DJ |
2577 | } |
2578 | else | |
2579 | { | |
578d3588 PA |
2580 | char *message = memory_error_message (TARGET_XFER_E_IO, |
2581 | bl->gdbarch, bl->address); | |
2582 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2583 | ||
879bfdc2 | 2584 | fprintf_unfiltered (tmp_error_stream, |
578d3588 PA |
2585 | "Cannot insert breakpoint %d.\n" |
2586 | "%s\n", | |
2587 | bl->owner->number, message); | |
2588 | ||
2589 | do_cleanups (old_chain); | |
879bfdc2 DJ |
2590 | } |
2591 | ||
2592 | } | |
2593 | } | |
2594 | else | |
35df4500 | 2595 | bl->inserted = 1; |
879bfdc2 DJ |
2596 | |
2597 | return val; | |
2598 | } | |
2599 | ||
35df4500 | 2600 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2601 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2602 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2603 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2604 | { |
77b06cd7 TJB |
2605 | gdb_assert (bl->owner->ops != NULL |
2606 | && bl->owner->ops->insert_location != NULL); | |
2607 | ||
2608 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2609 | |
2610 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2611 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2612 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2613 | { |
2614 | struct bp_location *loc, **loc_temp; | |
2615 | ||
2616 | /* But don't try to insert it, if there's already another | |
2617 | hw_access location that would be considered a duplicate | |
2618 | of this one. */ | |
2619 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2620 | if (loc != bl |
85d721b8 | 2621 | && loc->watchpoint_type == hw_access |
35df4500 | 2622 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2623 | { |
35df4500 TJB |
2624 | bl->duplicate = 1; |
2625 | bl->inserted = 1; | |
2626 | bl->target_info = loc->target_info; | |
2627 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2628 | val = 0; |
2629 | break; | |
2630 | } | |
2631 | ||
2632 | if (val == 1) | |
2633 | { | |
77b06cd7 TJB |
2634 | bl->watchpoint_type = hw_access; |
2635 | val = bl->owner->ops->insert_location (bl); | |
2636 | ||
2637 | if (val) | |
2638 | /* Back to the original value. */ | |
2639 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2640 | } |
2641 | } | |
2642 | ||
35df4500 | 2643 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2644 | } |
2645 | ||
35df4500 | 2646 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2647 | { |
77b06cd7 TJB |
2648 | gdb_assert (bl->owner->ops != NULL |
2649 | && bl->owner->ops->insert_location != NULL); | |
2650 | ||
2651 | val = bl->owner->ops->insert_location (bl); | |
2652 | if (val) | |
2653 | { | |
2654 | bl->owner->enable_state = bp_disabled; | |
2655 | ||
2656 | if (val == 1) | |
2657 | warning (_("\ | |
2658 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2659 | of catchpoint."), bl->owner->number); | |
2660 | else | |
2661 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2662 | } | |
2663 | ||
2664 | bl->inserted = (val == 0); | |
1640b821 DJ |
2665 | |
2666 | /* We've already printed an error message if there was a problem | |
2667 | inserting this catchpoint, and we've disabled the catchpoint, | |
2668 | so just return success. */ | |
2669 | return 0; | |
879bfdc2 DJ |
2670 | } |
2671 | ||
2672 | return 0; | |
2673 | } | |
2674 | ||
6c95b8df PA |
2675 | /* This function is called when program space PSPACE is about to be |
2676 | deleted. It takes care of updating breakpoints to not reference | |
2677 | PSPACE anymore. */ | |
2678 | ||
2679 | void | |
2680 | breakpoint_program_space_exit (struct program_space *pspace) | |
2681 | { | |
2682 | struct breakpoint *b, *b_temp; | |
876fa593 | 2683 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2684 | |
2685 | /* Remove any breakpoint that was set through this program space. */ | |
2686 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2687 | { | |
2688 | if (b->pspace == pspace) | |
2689 | delete_breakpoint (b); | |
2690 | } | |
2691 | ||
2692 | /* Breakpoints set through other program spaces could have locations | |
2693 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2694 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2695 | { |
2696 | struct bp_location *tmp; | |
2697 | ||
2698 | if (loc->pspace == pspace) | |
2699 | { | |
2bdf28a0 | 2700 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2701 | if (loc->owner->loc == loc) |
2702 | loc->owner->loc = loc->next; | |
2703 | else | |
2704 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2705 | if (tmp->next == loc) | |
2706 | { | |
2707 | tmp->next = loc->next; | |
2708 | break; | |
2709 | } | |
2710 | } | |
2711 | } | |
2712 | ||
2713 | /* Now update the global location list to permanently delete the | |
2714 | removed locations above. */ | |
2715 | update_global_location_list (0); | |
2716 | } | |
2717 | ||
74960c60 VP |
2718 | /* Make sure all breakpoints are inserted in inferior. |
2719 | Throws exception on any error. | |
2720 | A breakpoint that is already inserted won't be inserted | |
2721 | again, so calling this function twice is safe. */ | |
2722 | void | |
2723 | insert_breakpoints (void) | |
2724 | { | |
2725 | struct breakpoint *bpt; | |
2726 | ||
2727 | ALL_BREAKPOINTS (bpt) | |
2728 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2729 | { |
2730 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2731 | ||
2732 | update_watchpoint (w, 0 /* don't reparse. */); | |
2733 | } | |
74960c60 | 2734 | |
b60e7edf | 2735 | update_global_location_list (1); |
74960c60 | 2736 | |
c35b1492 PA |
2737 | /* update_global_location_list does not insert breakpoints when |
2738 | always_inserted_mode is not enabled. Explicitly insert them | |
2739 | now. */ | |
2740 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2741 | insert_breakpoint_locations (); |
2742 | } | |
2743 | ||
20388dd6 YQ |
2744 | /* Invoke CALLBACK for each of bp_location. */ |
2745 | ||
2746 | void | |
2747 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2748 | { | |
2749 | struct bp_location *loc, **loc_tmp; | |
2750 | ||
2751 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2752 | { | |
2753 | callback (loc, NULL); | |
2754 | } | |
2755 | } | |
2756 | ||
b775012e LM |
2757 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2758 | target. It is the case with deleting and disabling of breakpoints when using | |
2759 | always-inserted mode. */ | |
2760 | ||
2761 | static void | |
2762 | update_inserted_breakpoint_locations (void) | |
2763 | { | |
2764 | struct bp_location *bl, **blp_tmp; | |
2765 | int error_flag = 0; | |
2766 | int val = 0; | |
2767 | int disabled_breaks = 0; | |
2768 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2769 | int hw_bp_details_reported = 0; |
b775012e LM |
2770 | |
2771 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2772 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2773 | ||
2774 | /* Explicitly mark the warning -- this will only be printed if | |
2775 | there was an error. */ | |
2776 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2777 | ||
2778 | save_current_space_and_thread (); | |
2779 | ||
2780 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2781 | { | |
2782 | /* We only want to update software breakpoints and hardware | |
2783 | breakpoints. */ | |
2784 | if (!is_breakpoint (bl->owner)) | |
2785 | continue; | |
2786 | ||
2787 | /* We only want to update locations that are already inserted | |
2788 | and need updating. This is to avoid unwanted insertion during | |
2789 | deletion of breakpoints. */ | |
2790 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2791 | continue; | |
2792 | ||
2793 | switch_to_program_space_and_thread (bl->pspace); | |
2794 | ||
2795 | /* For targets that support global breakpoints, there's no need | |
2796 | to select an inferior to insert breakpoint to. In fact, even | |
2797 | if we aren't attached to any process yet, we should still | |
2798 | insert breakpoints. */ | |
f5656ead | 2799 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2800 | && ptid_equal (inferior_ptid, null_ptid)) |
2801 | continue; | |
2802 | ||
2803 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2804 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2805 | if (val) |
2806 | error_flag = val; | |
2807 | } | |
2808 | ||
2809 | if (error_flag) | |
2810 | { | |
2811 | target_terminal_ours_for_output (); | |
2812 | error_stream (tmp_error_stream); | |
2813 | } | |
2814 | ||
2815 | do_cleanups (cleanups); | |
2816 | } | |
2817 | ||
c30eee59 | 2818 | /* Used when starting or continuing the program. */ |
c906108c | 2819 | |
74960c60 VP |
2820 | static void |
2821 | insert_breakpoint_locations (void) | |
c906108c | 2822 | { |
a5606eee | 2823 | struct breakpoint *bpt; |
35df4500 | 2824 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2825 | int error_flag = 0; |
c906108c | 2826 | int val = 0; |
3fbb6ffa | 2827 | int disabled_breaks = 0; |
81d0cc19 | 2828 | int hw_breakpoint_error = 0; |
dd61ec5c | 2829 | int hw_bp_error_explained_already = 0; |
c906108c | 2830 | |
81d0cc19 | 2831 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2832 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2833 | |
81d0cc19 GS |
2834 | /* Explicitly mark the warning -- this will only be printed if |
2835 | there was an error. */ | |
2836 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2837 | |
2838 | save_current_space_and_thread (); | |
2839 | ||
35df4500 | 2840 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2841 | { |
b775012e | 2842 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2843 | continue; |
2844 | ||
4a64f543 MS |
2845 | /* There is no point inserting thread-specific breakpoints if |
2846 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2847 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2848 | if (bl->owner->thread != -1 |
2849 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2850 | continue; |
2851 | ||
35df4500 | 2852 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2853 | |
2854 | /* For targets that support global breakpoints, there's no need | |
2855 | to select an inferior to insert breakpoint to. In fact, even | |
2856 | if we aren't attached to any process yet, we should still | |
2857 | insert breakpoints. */ | |
f5656ead | 2858 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2859 | && ptid_equal (inferior_ptid, null_ptid)) |
2860 | continue; | |
2861 | ||
3fbb6ffa | 2862 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2863 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2864 | if (val) |
eacd795a | 2865 | error_flag = val; |
879bfdc2 | 2866 | } |
c906108c | 2867 | |
4a64f543 MS |
2868 | /* If we failed to insert all locations of a watchpoint, remove |
2869 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2870 | ALL_BREAKPOINTS (bpt) |
2871 | { | |
2872 | int some_failed = 0; | |
2873 | struct bp_location *loc; | |
2874 | ||
2875 | if (!is_hardware_watchpoint (bpt)) | |
2876 | continue; | |
2877 | ||
d6b74ac4 | 2878 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2879 | continue; |
74960c60 VP |
2880 | |
2881 | if (bpt->disposition == disp_del_at_next_stop) | |
2882 | continue; | |
a5606eee VP |
2883 | |
2884 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2885 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2886 | { |
2887 | some_failed = 1; | |
2888 | break; | |
2889 | } | |
2890 | if (some_failed) | |
2891 | { | |
2892 | for (loc = bpt->loc; loc; loc = loc->next) | |
2893 | if (loc->inserted) | |
2894 | remove_breakpoint (loc, mark_uninserted); | |
2895 | ||
2896 | hw_breakpoint_error = 1; | |
2897 | fprintf_unfiltered (tmp_error_stream, | |
2898 | "Could not insert hardware watchpoint %d.\n", | |
2899 | bpt->number); | |
eacd795a | 2900 | error_flag = -1; |
a5606eee VP |
2901 | } |
2902 | } | |
2903 | ||
eacd795a | 2904 | if (error_flag) |
81d0cc19 GS |
2905 | { |
2906 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2907 | message about possibly exhausted resources. */ | |
dd61ec5c | 2908 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2909 | { |
c6510018 MS |
2910 | fprintf_unfiltered (tmp_error_stream, |
2911 | "Could not insert hardware breakpoints:\n\ | |
2912 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2913 | } |
81d0cc19 GS |
2914 | target_terminal_ours_for_output (); |
2915 | error_stream (tmp_error_stream); | |
2916 | } | |
f7545552 TT |
2917 | |
2918 | do_cleanups (cleanups); | |
c906108c SS |
2919 | } |
2920 | ||
c30eee59 TJB |
2921 | /* Used when the program stops. |
2922 | Returns zero if successful, or non-zero if there was a problem | |
2923 | removing a breakpoint location. */ | |
2924 | ||
c906108c | 2925 | int |
fba45db2 | 2926 | remove_breakpoints (void) |
c906108c | 2927 | { |
35df4500 | 2928 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2929 | int val = 0; |
c906108c | 2930 | |
35df4500 | 2931 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2932 | { |
1e4d1764 | 2933 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2934 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2935 | } |
3a1bae8e | 2936 | return val; |
c906108c SS |
2937 | } |
2938 | ||
49fa26b0 PA |
2939 | /* When a thread exits, remove breakpoints that are related to |
2940 | that thread. */ | |
2941 | ||
2942 | static void | |
2943 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
2944 | { | |
2945 | struct breakpoint *b, *b_tmp; | |
2946 | ||
2947 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
2948 | { | |
96181529 | 2949 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
2950 | { |
2951 | b->disposition = disp_del_at_next_stop; | |
2952 | ||
2953 | printf_filtered (_("\ | |
46ecd527 | 2954 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
2955 | b->number, tp->num); |
2956 | ||
2957 | /* Hide it from the user. */ | |
2958 | b->number = 0; | |
2959 | } | |
2960 | } | |
2961 | } | |
2962 | ||
6c95b8df PA |
2963 | /* Remove breakpoints of process PID. */ |
2964 | ||
2965 | int | |
2966 | remove_breakpoints_pid (int pid) | |
2967 | { | |
35df4500 | 2968 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2969 | int val; |
2970 | struct inferior *inf = find_inferior_pid (pid); | |
2971 | ||
35df4500 | 2972 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2973 | { |
35df4500 | 2974 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2975 | continue; |
2976 | ||
d3ce09f5 SS |
2977 | if (bl->owner->type == bp_dprintf) |
2978 | continue; | |
2979 | ||
35df4500 | 2980 | if (bl->inserted) |
6c95b8df | 2981 | { |
35df4500 | 2982 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2983 | if (val != 0) |
2984 | return val; | |
2985 | } | |
2986 | } | |
2987 | return 0; | |
2988 | } | |
2989 | ||
c906108c | 2990 | int |
fba45db2 | 2991 | reattach_breakpoints (int pid) |
c906108c | 2992 | { |
6c95b8df | 2993 | struct cleanup *old_chain; |
35df4500 | 2994 | struct bp_location *bl, **blp_tmp; |
c906108c | 2995 | int val; |
86b887df | 2996 | struct ui_file *tmp_error_stream; |
dd61ec5c | 2997 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
2998 | struct inferior *inf; |
2999 | struct thread_info *tp; | |
3000 | ||
3001 | tp = any_live_thread_of_process (pid); | |
3002 | if (tp == NULL) | |
3003 | return 1; | |
3004 | ||
3005 | inf = find_inferior_pid (pid); | |
3006 | old_chain = save_inferior_ptid (); | |
3007 | ||
3008 | inferior_ptid = tp->ptid; | |
a4954f26 | 3009 | |
86b887df | 3010 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3011 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3012 | |
35df4500 | 3013 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3014 | { |
35df4500 | 3015 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3016 | continue; |
3017 | ||
35df4500 | 3018 | if (bl->inserted) |
c5aa993b | 3019 | { |
35df4500 | 3020 | bl->inserted = 0; |
dd61ec5c | 3021 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3022 | if (val != 0) |
3023 | { | |
ce696e05 | 3024 | do_cleanups (old_chain); |
c5aa993b JM |
3025 | return val; |
3026 | } | |
3027 | } | |
3028 | } | |
ce696e05 | 3029 | do_cleanups (old_chain); |
c906108c SS |
3030 | return 0; |
3031 | } | |
3032 | ||
e58b0e63 PA |
3033 | static int internal_breakpoint_number = -1; |
3034 | ||
84f4c1fe PM |
3035 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3036 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3037 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3038 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3039 | breakpoint_count and that value incremented. Internal breakpoints |
3040 | do not set the internal var bpnum. */ | |
3041 | static void | |
3042 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3043 | { | |
3044 | if (internal) | |
3045 | b->number = internal_breakpoint_number--; | |
3046 | else | |
3047 | { | |
3048 | set_breakpoint_count (breakpoint_count + 1); | |
3049 | b->number = breakpoint_count; | |
3050 | } | |
3051 | } | |
3052 | ||
e62c965a | 3053 | static struct breakpoint * |
a6d9a66e | 3054 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3055 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3056 | const struct breakpoint_ops *ops) |
e62c965a | 3057 | { |
e62c965a PP |
3058 | struct symtab_and_line sal; |
3059 | struct breakpoint *b; | |
3060 | ||
4a64f543 | 3061 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3062 | |
3063 | sal.pc = address; | |
3064 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3065 | sal.pspace = current_program_space; |
e62c965a | 3066 | |
06edf0c0 | 3067 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3068 | b->number = internal_breakpoint_number--; |
3069 | b->disposition = disp_donttouch; | |
3070 | ||
3071 | return b; | |
3072 | } | |
3073 | ||
17450429 PP |
3074 | static const char *const longjmp_names[] = |
3075 | { | |
3076 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3077 | }; | |
3078 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3079 | ||
3080 | /* Per-objfile data private to breakpoint.c. */ | |
3081 | struct breakpoint_objfile_data | |
3082 | { | |
3083 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3084 | struct minimal_symbol *overlay_msym; | |
3085 | ||
3086 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3087 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
3088 | ||
28106bc2 SDJ |
3089 | /* True if we have looked for longjmp probes. */ |
3090 | int longjmp_searched; | |
3091 | ||
3092 | /* SystemTap probe points for longjmp (if any). */ | |
3093 | VEC (probe_p) *longjmp_probes; | |
3094 | ||
17450429 PP |
3095 | /* Minimal symbol for "std::terminate()" (if any). */ |
3096 | struct minimal_symbol *terminate_msym; | |
3097 | ||
3098 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3099 | struct minimal_symbol *exception_msym; | |
28106bc2 SDJ |
3100 | |
3101 | /* True if we have looked for exception probes. */ | |
3102 | int exception_searched; | |
3103 | ||
3104 | /* SystemTap probe points for unwinding (if any). */ | |
3105 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3106 | }; |
3107 | ||
3108 | static const struct objfile_data *breakpoint_objfile_key; | |
3109 | ||
3110 | /* Minimal symbol not found sentinel. */ | |
3111 | static struct minimal_symbol msym_not_found; | |
3112 | ||
3113 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3114 | ||
3115 | static int | |
3116 | msym_not_found_p (const struct minimal_symbol *msym) | |
3117 | { | |
3118 | return msym == &msym_not_found; | |
3119 | } | |
3120 | ||
3121 | /* Return per-objfile data needed by breakpoint.c. | |
3122 | Allocate the data if necessary. */ | |
3123 | ||
3124 | static struct breakpoint_objfile_data * | |
3125 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3126 | { | |
3127 | struct breakpoint_objfile_data *bp_objfile_data; | |
3128 | ||
3129 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3130 | if (bp_objfile_data == NULL) | |
3131 | { | |
3132 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3133 | sizeof (*bp_objfile_data)); | |
3134 | ||
3135 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3136 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3137 | } | |
3138 | return bp_objfile_data; | |
3139 | } | |
3140 | ||
28106bc2 SDJ |
3141 | static void |
3142 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3143 | { | |
3144 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3145 | ||
3146 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3147 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3148 | } | |
3149 | ||
e62c965a | 3150 | static void |
af02033e | 3151 | create_overlay_event_breakpoint (void) |
e62c965a | 3152 | { |
69de3c6a | 3153 | struct objfile *objfile; |
af02033e | 3154 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3155 | |
69de3c6a PP |
3156 | ALL_OBJFILES (objfile) |
3157 | { | |
3158 | struct breakpoint *b; | |
17450429 PP |
3159 | struct breakpoint_objfile_data *bp_objfile_data; |
3160 | CORE_ADDR addr; | |
69de3c6a | 3161 | |
17450429 PP |
3162 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3163 | ||
3164 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
3165 | continue; | |
3166 | ||
3167 | if (bp_objfile_data->overlay_msym == NULL) | |
3168 | { | |
3169 | struct minimal_symbol *m; | |
3170 | ||
3171 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3172 | if (m == NULL) | |
3173 | { | |
3174 | /* Avoid future lookups in this objfile. */ | |
3175 | bp_objfile_data->overlay_msym = &msym_not_found; | |
3176 | continue; | |
3177 | } | |
3178 | bp_objfile_data->overlay_msym = m; | |
3179 | } | |
e62c965a | 3180 | |
17450429 PP |
3181 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
3182 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3183 | bp_overlay_event, |
3184 | &internal_breakpoint_ops); | |
69de3c6a | 3185 | b->addr_string = xstrdup (func_name); |
e62c965a | 3186 | |
69de3c6a PP |
3187 | if (overlay_debugging == ovly_auto) |
3188 | { | |
3189 | b->enable_state = bp_enabled; | |
3190 | overlay_events_enabled = 1; | |
3191 | } | |
3192 | else | |
3193 | { | |
3194 | b->enable_state = bp_disabled; | |
3195 | overlay_events_enabled = 0; | |
3196 | } | |
e62c965a PP |
3197 | } |
3198 | update_global_location_list (1); | |
3199 | } | |
3200 | ||
0fd8e87f | 3201 | static void |
af02033e | 3202 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3203 | { |
6c95b8df | 3204 | struct program_space *pspace; |
6c95b8df PA |
3205 | struct cleanup *old_chain; |
3206 | ||
3207 | old_chain = save_current_program_space (); | |
0fd8e87f | 3208 | |
6c95b8df | 3209 | ALL_PSPACES (pspace) |
af02033e PP |
3210 | { |
3211 | struct objfile *objfile; | |
3212 | ||
3213 | set_current_program_space (pspace); | |
3214 | ||
3215 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3216 | { |
af02033e PP |
3217 | int i; |
3218 | struct gdbarch *gdbarch; | |
17450429 | 3219 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3220 | |
af02033e PP |
3221 | gdbarch = get_objfile_arch (objfile); |
3222 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
3223 | continue; |
3224 | ||
17450429 PP |
3225 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3226 | ||
28106bc2 SDJ |
3227 | if (!bp_objfile_data->longjmp_searched) |
3228 | { | |
25f9533e SDJ |
3229 | VEC (probe_p) *ret; |
3230 | ||
3231 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3232 | if (ret != NULL) | |
3233 | { | |
3234 | /* We are only interested in checking one element. */ | |
3235 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3236 | ||
3237 | if (!can_evaluate_probe_arguments (p)) | |
3238 | { | |
3239 | /* We cannot use the probe interface here, because it does | |
3240 | not know how to evaluate arguments. */ | |
3241 | VEC_free (probe_p, ret); | |
3242 | ret = NULL; | |
3243 | } | |
3244 | } | |
3245 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3246 | bp_objfile_data->longjmp_searched = 1; |
3247 | } | |
3248 | ||
3249 | if (bp_objfile_data->longjmp_probes != NULL) | |
3250 | { | |
3251 | int i; | |
3252 | struct probe *probe; | |
3253 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3254 | ||
3255 | for (i = 0; | |
3256 | VEC_iterate (probe_p, | |
3257 | bp_objfile_data->longjmp_probes, | |
3258 | i, probe); | |
3259 | ++i) | |
3260 | { | |
3261 | struct breakpoint *b; | |
3262 | ||
3263 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3264 | bp_longjmp_master, | |
3265 | &internal_breakpoint_ops); | |
3266 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3267 | b->enable_state = bp_disabled; | |
3268 | } | |
3269 | ||
3270 | continue; | |
3271 | } | |
3272 | ||
17450429 | 3273 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3274 | { |
3275 | struct breakpoint *b; | |
af02033e | 3276 | const char *func_name; |
17450429 | 3277 | CORE_ADDR addr; |
6c95b8df | 3278 | |
17450429 | 3279 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 3280 | continue; |
0fd8e87f | 3281 | |
17450429 PP |
3282 | func_name = longjmp_names[i]; |
3283 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
3284 | { | |
3285 | struct minimal_symbol *m; | |
3286 | ||
3287 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3288 | if (m == NULL) | |
3289 | { | |
3290 | /* Prevent future lookups in this objfile. */ | |
3291 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
3292 | continue; | |
3293 | } | |
3294 | bp_objfile_data->longjmp_msym[i] = m; | |
3295 | } | |
3296 | ||
3297 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
3298 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3299 | &internal_breakpoint_ops); | |
af02033e PP |
3300 | b->addr_string = xstrdup (func_name); |
3301 | b->enable_state = bp_disabled; | |
3302 | } | |
0fd8e87f | 3303 | } |
af02033e | 3304 | } |
0fd8e87f | 3305 | update_global_location_list (1); |
6c95b8df PA |
3306 | |
3307 | do_cleanups (old_chain); | |
0fd8e87f UW |
3308 | } |
3309 | ||
af02033e | 3310 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3311 | static void |
af02033e | 3312 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3313 | { |
3314 | struct program_space *pspace; | |
aa7d318d | 3315 | struct cleanup *old_chain; |
af02033e | 3316 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3317 | |
3318 | old_chain = save_current_program_space (); | |
3319 | ||
3320 | ALL_PSPACES (pspace) | |
17450429 PP |
3321 | { |
3322 | struct objfile *objfile; | |
3323 | CORE_ADDR addr; | |
3324 | ||
3325 | set_current_program_space (pspace); | |
3326 | ||
aa7d318d TT |
3327 | ALL_OBJFILES (objfile) |
3328 | { | |
3329 | struct breakpoint *b; | |
17450429 | 3330 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3331 | |
17450429 | 3332 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3333 | |
17450429 PP |
3334 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
3335 | continue; | |
3336 | ||
3337 | if (bp_objfile_data->terminate_msym == NULL) | |
3338 | { | |
3339 | struct minimal_symbol *m; | |
3340 | ||
3341 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3342 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
3343 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
3344 | { | |
3345 | /* Prevent future lookups in this objfile. */ | |
3346 | bp_objfile_data->terminate_msym = &msym_not_found; | |
3347 | continue; | |
3348 | } | |
3349 | bp_objfile_data->terminate_msym = m; | |
3350 | } | |
aa7d318d | 3351 | |
17450429 PP |
3352 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3353 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3354 | bp_std_terminate_master, |
3355 | &internal_breakpoint_ops); | |
aa7d318d TT |
3356 | b->addr_string = xstrdup (func_name); |
3357 | b->enable_state = bp_disabled; | |
3358 | } | |
17450429 PP |
3359 | } |
3360 | ||
aa7d318d TT |
3361 | update_global_location_list (1); |
3362 | ||
3363 | do_cleanups (old_chain); | |
3364 | } | |
3365 | ||
186c406b TT |
3366 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3367 | ||
70221824 | 3368 | static void |
186c406b TT |
3369 | create_exception_master_breakpoint (void) |
3370 | { | |
3371 | struct objfile *objfile; | |
17450429 | 3372 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3373 | |
3374 | ALL_OBJFILES (objfile) | |
3375 | { | |
17450429 PP |
3376 | struct breakpoint *b; |
3377 | struct gdbarch *gdbarch; | |
3378 | struct breakpoint_objfile_data *bp_objfile_data; | |
3379 | CORE_ADDR addr; | |
3380 | ||
3381 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3382 | ||
28106bc2 SDJ |
3383 | /* We prefer the SystemTap probe point if it exists. */ |
3384 | if (!bp_objfile_data->exception_searched) | |
3385 | { | |
25f9533e SDJ |
3386 | VEC (probe_p) *ret; |
3387 | ||
3388 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3389 | ||
3390 | if (ret != NULL) | |
3391 | { | |
3392 | /* We are only interested in checking one element. */ | |
3393 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3394 | ||
3395 | if (!can_evaluate_probe_arguments (p)) | |
3396 | { | |
3397 | /* We cannot use the probe interface here, because it does | |
3398 | not know how to evaluate arguments. */ | |
3399 | VEC_free (probe_p, ret); | |
3400 | ret = NULL; | |
3401 | } | |
3402 | } | |
3403 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3404 | bp_objfile_data->exception_searched = 1; |
3405 | } | |
3406 | ||
3407 | if (bp_objfile_data->exception_probes != NULL) | |
3408 | { | |
3409 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3410 | int i; | |
3411 | struct probe *probe; | |
3412 | ||
3413 | for (i = 0; | |
3414 | VEC_iterate (probe_p, | |
3415 | bp_objfile_data->exception_probes, | |
3416 | i, probe); | |
3417 | ++i) | |
3418 | { | |
3419 | struct breakpoint *b; | |
3420 | ||
3421 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3422 | bp_exception_master, | |
3423 | &internal_breakpoint_ops); | |
3424 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3425 | b->enable_state = bp_disabled; | |
3426 | } | |
3427 | ||
3428 | continue; | |
3429 | } | |
3430 | ||
3431 | /* Otherwise, try the hook function. */ | |
3432 | ||
17450429 PP |
3433 | if (msym_not_found_p (bp_objfile_data->exception_msym)) |
3434 | continue; | |
3435 | ||
3436 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3437 | |
17450429 | 3438 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 3439 | { |
17450429 | 3440 | struct minimal_symbol *debug_hook; |
186c406b | 3441 | |
17450429 PP |
3442 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3443 | if (debug_hook == NULL) | |
3444 | { | |
3445 | bp_objfile_data->exception_msym = &msym_not_found; | |
3446 | continue; | |
3447 | } | |
3448 | ||
3449 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3450 | } |
17450429 PP |
3451 | |
3452 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
3453 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
3454 | ¤t_target); | |
06edf0c0 PA |
3455 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3456 | &internal_breakpoint_ops); | |
17450429 PP |
3457 | b->addr_string = xstrdup (func_name); |
3458 | b->enable_state = bp_disabled; | |
186c406b TT |
3459 | } |
3460 | ||
3461 | update_global_location_list (1); | |
3462 | } | |
3463 | ||
c906108c | 3464 | void |
fba45db2 | 3465 | update_breakpoints_after_exec (void) |
c906108c | 3466 | { |
35df4500 | 3467 | struct breakpoint *b, *b_tmp; |
876fa593 | 3468 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3469 | |
25b22b0a PA |
3470 | /* We're about to delete breakpoints from GDB's lists. If the |
3471 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3472 | writing the breakpoints' "shadow contents" back into memory. The | |
3473 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3474 | do that. Instead, the target is responsible from marking | |
3475 | breakpoints out as soon as it detects an exec. We don't do that | |
3476 | here instead, because there may be other attempts to delete | |
3477 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3478 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3479 | if (bploc->pspace == current_program_space) |
3480 | gdb_assert (!bploc->inserted); | |
c906108c | 3481 | |
35df4500 | 3482 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3483 | { |
6c95b8df PA |
3484 | if (b->pspace != current_program_space) |
3485 | continue; | |
3486 | ||
4a64f543 | 3487 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3488 | if (b->type == bp_shlib_event) |
3489 | { | |
3490 | delete_breakpoint (b); | |
3491 | continue; | |
3492 | } | |
c906108c | 3493 | |
4a64f543 | 3494 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3495 | if (b->type == bp_jit_event) |
3496 | { | |
3497 | delete_breakpoint (b); | |
3498 | continue; | |
3499 | } | |
3500 | ||
1900040c | 3501 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3502 | as must overlay event and longjmp master breakpoints. */ |
3503 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3504 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3505 | || b->type == bp_exception_master) | |
c4093a6a JM |
3506 | { |
3507 | delete_breakpoint (b); | |
3508 | continue; | |
3509 | } | |
3510 | ||
4a64f543 | 3511 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3512 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3513 | { |
3514 | delete_breakpoint (b); | |
3515 | continue; | |
3516 | } | |
3517 | ||
611c83ae PA |
3518 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3519 | after an exec. */ | |
186c406b | 3520 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3521 | || b->type == bp_longjmp_call_dummy |
186c406b | 3522 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3523 | { |
3524 | delete_breakpoint (b); | |
3525 | continue; | |
3526 | } | |
3527 | ||
ce78b96d JB |
3528 | if (b->type == bp_catchpoint) |
3529 | { | |
3530 | /* For now, none of the bp_catchpoint breakpoints need to | |
3531 | do anything at this point. In the future, if some of | |
3532 | the catchpoints need to something, we will need to add | |
3533 | a new method, and call this method from here. */ | |
3534 | continue; | |
3535 | } | |
3536 | ||
c5aa993b JM |
3537 | /* bp_finish is a special case. The only way we ought to be able |
3538 | to see one of these when an exec() has happened, is if the user | |
3539 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3540 | carries them to the call-site of the current callee, by setting | |
3541 | a temporary bp there and resuming. But in this case, the finish | |
3542 | will carry them entirely through the vfork & exec. | |
3543 | ||
3544 | We don't want to allow a bp_finish to remain inserted now. But | |
3545 | we can't safely delete it, 'cause finish_command has a handle to | |
3546 | the bp on a bpstat, and will later want to delete it. There's a | |
3547 | chance (and I've seen it happen) that if we delete the bp_finish | |
3548 | here, that its storage will get reused by the time finish_command | |
3549 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3550 | We really must allow finish_command to delete a bp_finish. | |
3551 | ||
e5dd4106 | 3552 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3553 | it's safe to delete something others may have handles to?" |
3554 | problem, what we'll do here is just uninsert the bp_finish, and | |
3555 | let finish_command delete it. | |
3556 | ||
3557 | (We know the bp_finish is "doomed" in the sense that it's | |
3558 | momentary, and will be deleted as soon as finish_command sees | |
3559 | the inferior stopped. So it doesn't matter that the bp's | |
3560 | address is probably bogus in the new a.out, unlike e.g., the | |
3561 | solib breakpoints.) */ | |
c5aa993b | 3562 | |
c5aa993b JM |
3563 | if (b->type == bp_finish) |
3564 | { | |
3565 | continue; | |
3566 | } | |
3567 | ||
3568 | /* Without a symbolic address, we have little hope of the | |
3569 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3570 | a.out. */ |
c5aa993b JM |
3571 | if (b->addr_string == NULL) |
3572 | { | |
3573 | delete_breakpoint (b); | |
3574 | continue; | |
3575 | } | |
c5aa993b | 3576 | } |
1900040c | 3577 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3578 | create_overlay_event_breakpoint (); |
3579 | create_longjmp_master_breakpoint (); | |
3580 | create_std_terminate_master_breakpoint (); | |
186c406b | 3581 | create_exception_master_breakpoint (); |
c906108c SS |
3582 | } |
3583 | ||
3584 | int | |
d80ee84f | 3585 | detach_breakpoints (ptid_t ptid) |
c906108c | 3586 | { |
35df4500 | 3587 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3588 | int val = 0; |
ce696e05 | 3589 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3590 | struct inferior *inf = current_inferior (); |
c5aa993b | 3591 | |
dfd4cc63 | 3592 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3593 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3594 | |
6c95b8df | 3595 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3596 | inferior_ptid = ptid; |
35df4500 | 3597 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3598 | { |
35df4500 | 3599 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3600 | continue; |
3601 | ||
bd9673a4 PW |
3602 | /* This function must physically remove breakpoints locations |
3603 | from the specified ptid, without modifying the breakpoint | |
3604 | package's state. Locations of type bp_loc_other are only | |
3605 | maintained at GDB side. So, there is no need to remove | |
3606 | these bp_loc_other locations. Moreover, removing these | |
3607 | would modify the breakpoint package's state. */ | |
3608 | if (bl->loc_type == bp_loc_other) | |
3609 | continue; | |
3610 | ||
35df4500 TJB |
3611 | if (bl->inserted) |
3612 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3613 | } |
d03285ec UW |
3614 | |
3615 | /* Detach single-step breakpoints as well. */ | |
3616 | detach_single_step_breakpoints (); | |
3617 | ||
ce696e05 | 3618 | do_cleanups (old_chain); |
3a1bae8e | 3619 | return val; |
c906108c SS |
3620 | } |
3621 | ||
35df4500 | 3622 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3623 | Note that this is used to detach breakpoints from a child fork. |
3624 | When we get here, the child isn't in the inferior list, and neither | |
3625 | do we have objects to represent its address space --- we should | |
35df4500 | 3626 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3627 | |
c906108c | 3628 | static int |
35df4500 | 3629 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3630 | { |
3631 | int val; | |
c5aa993b | 3632 | |
35df4500 TJB |
3633 | /* BL is never in moribund_locations by our callers. */ |
3634 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3635 | |
35df4500 | 3636 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3637 | /* Permanent breakpoints cannot be inserted or removed. */ |
3638 | return 0; | |
3639 | ||
74960c60 VP |
3640 | /* The type of none suggests that owner is actually deleted. |
3641 | This should not ever happen. */ | |
35df4500 | 3642 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3643 | |
35df4500 TJB |
3644 | if (bl->loc_type == bp_loc_software_breakpoint |
3645 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3646 | { |
c02f5703 MS |
3647 | /* "Normal" instruction breakpoint: either the standard |
3648 | trap-instruction bp (bp_breakpoint), or a | |
3649 | bp_hardware_breakpoint. */ | |
3650 | ||
3651 | /* First check to see if we have to handle an overlay. */ | |
3652 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3653 | || bl->section == NULL |
3654 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3655 | { |
3656 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3657 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3658 | } |
c906108c SS |
3659 | else |
3660 | { | |
4a64f543 | 3661 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3662 | Did we set a breakpoint at the LMA? */ |
3663 | if (!overlay_events_enabled) | |
3664 | { | |
3665 | /* Yes -- overlay event support is not active, so we | |
3666 | should have set a breakpoint at the LMA. Remove it. | |
3667 | */ | |
c02f5703 MS |
3668 | /* Ignore any failures: if the LMA is in ROM, we will |
3669 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3670 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3671 | target_remove_hw_breakpoint (bl->gdbarch, | |
3672 | &bl->overlay_target_info); | |
c02f5703 | 3673 | else |
35df4500 TJB |
3674 | target_remove_breakpoint (bl->gdbarch, |
3675 | &bl->overlay_target_info); | |
c02f5703 MS |
3676 | } |
3677 | /* Did we set a breakpoint at the VMA? | |
3678 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3679 | if (bl->inserted) |
c906108c | 3680 | { |
c02f5703 MS |
3681 | /* Yes -- remove it. Previously we did not bother to |
3682 | remove the breakpoint if the section had been | |
3683 | unmapped, but let's not rely on that being safe. We | |
3684 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3685 | |
3686 | /* However, we should remove *software* breakpoints only | |
3687 | if the section is still mapped, or else we overwrite | |
3688 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3689 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3690 | || section_is_mapped (bl->section)) | |
3691 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3692 | else |
3693 | val = 0; | |
c906108c | 3694 | } |
c02f5703 MS |
3695 | else |
3696 | { | |
3697 | /* No -- not inserted, so no need to remove. No error. */ | |
3698 | val = 0; | |
3699 | } | |
c906108c | 3700 | } |
879d1e6b UW |
3701 | |
3702 | /* In some cases, we might not be able to remove a breakpoint | |
3703 | in a shared library that has already been removed, but we | |
3704 | have not yet processed the shlib unload event. */ | |
35df4500 | 3705 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3706 | val = 0; |
3707 | ||
c906108c SS |
3708 | if (val) |
3709 | return val; | |
35df4500 | 3710 | bl->inserted = (is == mark_inserted); |
c906108c | 3711 | } |
35df4500 | 3712 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3713 | { |
77b06cd7 TJB |
3714 | gdb_assert (bl->owner->ops != NULL |
3715 | && bl->owner->ops->remove_location != NULL); | |
3716 | ||
35df4500 | 3717 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3718 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3719 | |
c906108c | 3720 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3721 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3722 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3723 | bl->owner->number); |
c906108c | 3724 | } |
35df4500 TJB |
3725 | else if (bl->owner->type == bp_catchpoint |
3726 | && breakpoint_enabled (bl->owner) | |
3727 | && !bl->duplicate) | |
ce78b96d | 3728 | { |
77b06cd7 TJB |
3729 | gdb_assert (bl->owner->ops != NULL |
3730 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3731 | |
77b06cd7 | 3732 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3733 | if (val) |
3734 | return val; | |
77b06cd7 | 3735 | |
35df4500 | 3736 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3737 | } |
c906108c SS |
3738 | |
3739 | return 0; | |
3740 | } | |
3741 | ||
6c95b8df | 3742 | static int |
35df4500 | 3743 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3744 | { |
3745 | int ret; | |
3746 | struct cleanup *old_chain; | |
3747 | ||
35df4500 TJB |
3748 | /* BL is never in moribund_locations by our callers. */ |
3749 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3750 | |
35df4500 | 3751 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3752 | /* Permanent breakpoints cannot be inserted or removed. */ |
3753 | return 0; | |
3754 | ||
3755 | /* The type of none suggests that owner is actually deleted. | |
3756 | This should not ever happen. */ | |
35df4500 | 3757 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3758 | |
3759 | old_chain = save_current_space_and_thread (); | |
3760 | ||
35df4500 | 3761 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3762 | |
35df4500 | 3763 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3764 | |
3765 | do_cleanups (old_chain); | |
3766 | return ret; | |
3767 | } | |
3768 | ||
c906108c SS |
3769 | /* Clear the "inserted" flag in all breakpoints. */ |
3770 | ||
25b22b0a | 3771 | void |
fba45db2 | 3772 | mark_breakpoints_out (void) |
c906108c | 3773 | { |
35df4500 | 3774 | struct bp_location *bl, **blp_tmp; |
c906108c | 3775 | |
35df4500 TJB |
3776 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3777 | if (bl->pspace == current_program_space) | |
3778 | bl->inserted = 0; | |
c906108c SS |
3779 | } |
3780 | ||
53a5351d JM |
3781 | /* Clear the "inserted" flag in all breakpoints and delete any |
3782 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3783 | |
3784 | Plus other such housekeeping that has to be done for breakpoints | |
3785 | between runs. | |
3786 | ||
53a5351d JM |
3787 | Note: this function gets called at the end of a run (by |
3788 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3789 | init_wait_for_inferior). */ |
c906108c SS |
3790 | |
3791 | ||
3792 | ||
3793 | void | |
fba45db2 | 3794 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3795 | { |
35df4500 TJB |
3796 | struct breakpoint *b, *b_tmp; |
3797 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3798 | int ix; |
6c95b8df | 3799 | struct program_space *pspace = current_program_space; |
c906108c | 3800 | |
50c71eaf PA |
3801 | /* If breakpoint locations are shared across processes, then there's |
3802 | nothing to do. */ | |
f5656ead | 3803 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3804 | return; |
3805 | ||
35df4500 | 3806 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3807 | { |
35df4500 TJB |
3808 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3809 | if (bl->pspace == pspace | |
3810 | && bl->owner->enable_state != bp_permanent) | |
3811 | bl->inserted = 0; | |
6c95b8df | 3812 | } |
075f6582 | 3813 | |
35df4500 | 3814 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3815 | { |
6c95b8df PA |
3816 | if (b->loc && b->loc->pspace != pspace) |
3817 | continue; | |
3818 | ||
c5aa993b JM |
3819 | switch (b->type) |
3820 | { | |
3821 | case bp_call_dummy: | |
e2e4d78b | 3822 | case bp_longjmp_call_dummy: |
c906108c | 3823 | |
c5aa993b | 3824 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3825 | cause problems when the inferior is rerun, so we better get |
3826 | rid of it. */ | |
3827 | ||
3828 | case bp_watchpoint_scope: | |
3829 | ||
3830 | /* Also get rid of scope breakpoints. */ | |
3831 | ||
3832 | case bp_shlib_event: | |
3833 | ||
3834 | /* Also remove solib event breakpoints. Their addresses may | |
3835 | have changed since the last time we ran the program. | |
3836 | Actually we may now be debugging against different target; | |
3837 | and so the solib backend that installed this breakpoint may | |
3838 | not be used in by the target. E.g., | |
3839 | ||
3840 | (gdb) file prog-linux | |
3841 | (gdb) run # native linux target | |
3842 | ... | |
3843 | (gdb) kill | |
3844 | (gdb) file prog-win.exe | |
3845 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3846 | */ | |
c906108c | 3847 | |
f59f708a PA |
3848 | case bp_step_resume: |
3849 | ||
3850 | /* Also remove step-resume breakpoints. */ | |
3851 | ||
c5aa993b JM |
3852 | delete_breakpoint (b); |
3853 | break; | |
c906108c | 3854 | |
c5aa993b JM |
3855 | case bp_watchpoint: |
3856 | case bp_hardware_watchpoint: | |
3857 | case bp_read_watchpoint: | |
3858 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3859 | { |
3860 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3861 | |
3a5c3e22 PA |
3862 | /* Likewise for watchpoints on local expressions. */ |
3863 | if (w->exp_valid_block != NULL) | |
3864 | delete_breakpoint (b); | |
3865 | else if (context == inf_starting) | |
3866 | { | |
3867 | /* Reset val field to force reread of starting value in | |
3868 | insert_breakpoints. */ | |
3869 | if (w->val) | |
3870 | value_free (w->val); | |
3871 | w->val = NULL; | |
3872 | w->val_valid = 0; | |
c860120c | 3873 | } |
3a5c3e22 | 3874 | } |
c5aa993b JM |
3875 | break; |
3876 | default: | |
c5aa993b JM |
3877 | break; |
3878 | } | |
3879 | } | |
1c5cfe86 PA |
3880 | |
3881 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3882 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3883 | decref_bp_location (&bl); | |
1c5cfe86 | 3884 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3885 | } |
3886 | ||
6c95b8df PA |
3887 | /* These functions concern about actual breakpoints inserted in the |
3888 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3889 | we need to hop over the bkpt --- so we check for address space | |
3890 | match, not program space. */ | |
3891 | ||
c2c6d25f JM |
3892 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3893 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3894 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3895 | permanent breakpoint. | |
3896 | - When continuing from a location with an ordinary breakpoint, we | |
3897 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3898 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3899 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3900 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3901 | |
c2c6d25f | 3902 | enum breakpoint_here |
6c95b8df | 3903 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3904 | { |
35df4500 | 3905 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3906 | int any_breakpoint_here = 0; |
c906108c | 3907 | |
35df4500 | 3908 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3909 | { |
35df4500 TJB |
3910 | if (bl->loc_type != bp_loc_software_breakpoint |
3911 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3912 | continue; |
3913 | ||
f1310107 | 3914 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3915 | if ((breakpoint_enabled (bl->owner) |
3916 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3917 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3918 | { |
3919 | if (overlay_debugging | |
35df4500 TJB |
3920 | && section_is_overlay (bl->section) |
3921 | && !section_is_mapped (bl->section)) | |
075f6582 | 3922 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3923 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3924 | return permanent_breakpoint_here; |
3925 | else | |
3926 | any_breakpoint_here = 1; | |
3927 | } | |
3928 | } | |
c906108c | 3929 | |
c2c6d25f | 3930 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3931 | } |
3932 | ||
1c5cfe86 PA |
3933 | /* Return true if there's a moribund breakpoint at PC. */ |
3934 | ||
3935 | int | |
6c95b8df | 3936 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3937 | { |
3938 | struct bp_location *loc; | |
3939 | int ix; | |
3940 | ||
3941 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3942 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3943 | return 1; |
3944 | ||
3945 | return 0; | |
3946 | } | |
c2c6d25f | 3947 | |
c36b740a | 3948 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3949 | inserted using regular breakpoint_chain / bp_location array |
3950 | mechanism. This does not check for single-step breakpoints, which | |
3951 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3952 | |
3953 | int | |
4a64f543 MS |
3954 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3955 | CORE_ADDR pc) | |
c906108c | 3956 | { |
35df4500 | 3957 | struct bp_location *bl, **blp_tmp; |
c906108c | 3958 | |
35df4500 | 3959 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3960 | { |
35df4500 TJB |
3961 | if (bl->loc_type != bp_loc_software_breakpoint |
3962 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3963 | continue; |
3964 | ||
35df4500 | 3965 | if (bl->inserted |
f1310107 | 3966 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3967 | { |
3968 | if (overlay_debugging | |
35df4500 TJB |
3969 | && section_is_overlay (bl->section) |
3970 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3971 | continue; /* unmapped overlay -- can't be a match */ |
3972 | else | |
3973 | return 1; | |
3974 | } | |
c5aa993b | 3975 | } |
c36b740a VP |
3976 | return 0; |
3977 | } | |
3978 | ||
3979 | /* Returns non-zero iff there's either regular breakpoint | |
3980 | or a single step breakpoint inserted at PC. */ | |
3981 | ||
3982 | int | |
6c95b8df | 3983 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3984 | { |
6c95b8df | 3985 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 3986 | return 1; |
c906108c | 3987 | |
6c95b8df | 3988 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
3989 | return 1; |
3990 | ||
c906108c SS |
3991 | return 0; |
3992 | } | |
3993 | ||
4fa8626c DJ |
3994 | /* This function returns non-zero iff there is a software breakpoint |
3995 | inserted at PC. */ | |
3996 | ||
3997 | int | |
3e43a32a MS |
3998 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
3999 | CORE_ADDR pc) | |
4fa8626c | 4000 | { |
35df4500 | 4001 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4002 | |
35df4500 | 4003 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4004 | { |
35df4500 | 4005 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4006 | continue; |
4007 | ||
35df4500 TJB |
4008 | if (bl->inserted |
4009 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4010 | aspace, pc)) |
4fa8626c DJ |
4011 | { |
4012 | if (overlay_debugging | |
35df4500 TJB |
4013 | && section_is_overlay (bl->section) |
4014 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4015 | continue; /* unmapped overlay -- can't be a match */ |
4016 | else | |
4017 | return 1; | |
4018 | } | |
4019 | } | |
4020 | ||
1aafd4da | 4021 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4022 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4023 | return 1; |
4024 | ||
4fa8626c DJ |
4025 | return 0; |
4026 | } | |
4027 | ||
9093389c PA |
4028 | int |
4029 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4030 | CORE_ADDR addr, ULONGEST len) | |
4031 | { | |
4032 | struct breakpoint *bpt; | |
4033 | ||
4034 | ALL_BREAKPOINTS (bpt) | |
4035 | { | |
4036 | struct bp_location *loc; | |
4037 | ||
4038 | if (bpt->type != bp_hardware_watchpoint | |
4039 | && bpt->type != bp_access_watchpoint) | |
4040 | continue; | |
4041 | ||
4042 | if (!breakpoint_enabled (bpt)) | |
4043 | continue; | |
4044 | ||
4045 | for (loc = bpt->loc; loc; loc = loc->next) | |
4046 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4047 | { | |
4048 | CORE_ADDR l, h; | |
4049 | ||
4050 | /* Check for intersection. */ | |
4051 | l = max (loc->address, addr); | |
4052 | h = min (loc->address + loc->length, addr + len); | |
4053 | if (l < h) | |
4054 | return 1; | |
4055 | } | |
4056 | } | |
4057 | return 0; | |
4058 | } | |
4059 | ||
075f6582 DJ |
4060 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4061 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4062 | |
4063 | int | |
6c95b8df PA |
4064 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4065 | ptid_t ptid) | |
c906108c | 4066 | { |
35df4500 | 4067 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4068 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4069 | int thread = -1; |
4a306c9a | 4070 | int task = 0; |
a6f1cd96 | 4071 | |
35df4500 | 4072 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4073 | { |
35df4500 TJB |
4074 | if (bl->loc_type != bp_loc_software_breakpoint |
4075 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4076 | continue; |
4077 | ||
35df4500 TJB |
4078 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4079 | if (!breakpoint_enabled (bl->owner) | |
4080 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4081 | continue; |
4082 | ||
f1310107 | 4083 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4084 | continue; |
4085 | ||
35df4500 | 4086 | if (bl->owner->thread != -1) |
075f6582 | 4087 | { |
a6f1cd96 JB |
4088 | /* This is a thread-specific breakpoint. Check that ptid |
4089 | matches that thread. If thread hasn't been computed yet, | |
4090 | it is now time to do so. */ | |
4091 | if (thread == -1) | |
4092 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4093 | if (bl->owner->thread != thread) |
a6f1cd96 | 4094 | continue; |
075f6582 | 4095 | } |
a6f1cd96 | 4096 | |
35df4500 | 4097 | if (bl->owner->task != 0) |
4a306c9a JB |
4098 | { |
4099 | /* This is a task-specific breakpoint. Check that ptid | |
4100 | matches that task. If task hasn't been computed yet, | |
4101 | it is now time to do so. */ | |
4102 | if (task == 0) | |
4103 | task = ada_get_task_number (ptid); | |
35df4500 | 4104 | if (bl->owner->task != task) |
4a306c9a JB |
4105 | continue; |
4106 | } | |
4107 | ||
a6f1cd96 | 4108 | if (overlay_debugging |
35df4500 TJB |
4109 | && section_is_overlay (bl->section) |
4110 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4111 | continue; /* unmapped overlay -- can't be a match */ |
4112 | ||
4113 | return 1; | |
c5aa993b | 4114 | } |
c906108c SS |
4115 | |
4116 | return 0; | |
4117 | } | |
c906108c | 4118 | \f |
c5aa993b | 4119 | |
c906108c SS |
4120 | /* bpstat stuff. External routines' interfaces are documented |
4121 | in breakpoint.h. */ | |
4122 | ||
4123 | int | |
c326b90e | 4124 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4125 | { |
533be4dd | 4126 | return (ep->type == bp_catchpoint); |
c906108c SS |
4127 | } |
4128 | ||
f431efe5 PA |
4129 | /* Frees any storage that is part of a bpstat. Does not walk the |
4130 | 'next' chain. */ | |
4131 | ||
4132 | static void | |
198757a8 VP |
4133 | bpstat_free (bpstat bs) |
4134 | { | |
4135 | if (bs->old_val != NULL) | |
4136 | value_free (bs->old_val); | |
9add0f1b | 4137 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4138 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4139 | xfree (bs); |
4140 | } | |
4141 | ||
c906108c SS |
4142 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4143 | Also free any storage that is part of a bpstat. */ | |
4144 | ||
4145 | void | |
fba45db2 | 4146 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4147 | { |
4148 | bpstat p; | |
4149 | bpstat q; | |
4150 | ||
4151 | if (bsp == 0) | |
4152 | return; | |
4153 | p = *bsp; | |
4154 | while (p != NULL) | |
4155 | { | |
4156 | q = p->next; | |
198757a8 | 4157 | bpstat_free (p); |
c906108c SS |
4158 | p = q; |
4159 | } | |
4160 | *bsp = NULL; | |
4161 | } | |
4162 | ||
4163 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4164 | is part of the bpstat is copied as well. */ | |
4165 | ||
4166 | bpstat | |
fba45db2 | 4167 | bpstat_copy (bpstat bs) |
c906108c SS |
4168 | { |
4169 | bpstat p = NULL; | |
4170 | bpstat tmp; | |
4171 | bpstat retval = NULL; | |
4172 | ||
4173 | if (bs == NULL) | |
4174 | return bs; | |
4175 | ||
4176 | for (; bs != NULL; bs = bs->next) | |
4177 | { | |
4178 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4179 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4180 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4181 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4182 | if (bs->old_val != NULL) |
3c3185ac JK |
4183 | { |
4184 | tmp->old_val = value_copy (bs->old_val); | |
4185 | release_value (tmp->old_val); | |
4186 | } | |
31cc81e9 | 4187 | |
c906108c SS |
4188 | if (p == NULL) |
4189 | /* This is the first thing in the chain. */ | |
4190 | retval = tmp; | |
4191 | else | |
4192 | p->next = tmp; | |
4193 | p = tmp; | |
4194 | } | |
4195 | p->next = NULL; | |
4196 | return retval; | |
4197 | } | |
4198 | ||
4a64f543 | 4199 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4200 | |
4201 | bpstat | |
fba45db2 | 4202 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4203 | { |
c5aa993b JM |
4204 | if (bsp == NULL) |
4205 | return NULL; | |
c906108c | 4206 | |
c5aa993b JM |
4207 | for (; bsp != NULL; bsp = bsp->next) |
4208 | { | |
f431efe5 | 4209 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4210 | return bsp; |
4211 | } | |
c906108c SS |
4212 | return NULL; |
4213 | } | |
4214 | ||
ab04a2af TT |
4215 | /* See breakpoint.h. */ |
4216 | ||
4217 | enum bpstat_signal_value | |
427cd150 | 4218 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af TT |
4219 | { |
4220 | enum bpstat_signal_value result = BPSTAT_SIGNAL_NO; | |
4221 | ||
4222 | for (; bsp != NULL; bsp = bsp->next) | |
4223 | { | |
4224 | /* Ensure that, if we ever entered this loop, then we at least | |
4225 | return BPSTAT_SIGNAL_HIDE. */ | |
427cd150 | 4226 | enum bpstat_signal_value newval; |
ab04a2af | 4227 | |
427cd150 TT |
4228 | if (bsp->breakpoint_at == NULL) |
4229 | { | |
4230 | /* A moribund location can never explain a signal other than | |
4231 | GDB_SIGNAL_TRAP. */ | |
4232 | if (sig == GDB_SIGNAL_TRAP) | |
4233 | newval = BPSTAT_SIGNAL_HIDE; | |
4234 | else | |
4235 | newval = BPSTAT_SIGNAL_NO; | |
4236 | } | |
4237 | else | |
4238 | newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4239 | sig); | |
ab04a2af TT |
4240 | |
4241 | if (newval > result) | |
4242 | result = newval; | |
4243 | } | |
4244 | ||
4245 | return result; | |
4246 | } | |
4247 | ||
4a64f543 MS |
4248 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4249 | stopped at. *BSP upon return is a bpstat which points to the | |
4250 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4251 | good for anything but further calls to bpstat_num). | |
4252 | ||
8671a17b PA |
4253 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4254 | Return -1 if stopped at a breakpoint that has been deleted since | |
4255 | we set it. | |
4256 | Return 1 otherwise. */ | |
c906108c SS |
4257 | |
4258 | int | |
8671a17b | 4259 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4260 | { |
4261 | struct breakpoint *b; | |
4262 | ||
4263 | if ((*bsp) == NULL) | |
4264 | return 0; /* No more breakpoint values */ | |
8671a17b | 4265 | |
4a64f543 MS |
4266 | /* We assume we'll never have several bpstats that correspond to a |
4267 | single breakpoint -- otherwise, this function might return the | |
4268 | same number more than once and this will look ugly. */ | |
f431efe5 | 4269 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4270 | *bsp = (*bsp)->next; |
4271 | if (b == NULL) | |
4272 | return -1; /* breakpoint that's been deleted since */ | |
4273 | ||
4274 | *num = b->number; /* We have its number */ | |
4275 | return 1; | |
c906108c SS |
4276 | } |
4277 | ||
e93ca019 | 4278 | /* See breakpoint.h. */ |
c906108c SS |
4279 | |
4280 | void | |
e93ca019 | 4281 | bpstat_clear_actions (void) |
c906108c | 4282 | { |
e93ca019 JK |
4283 | struct thread_info *tp; |
4284 | bpstat bs; | |
4285 | ||
4286 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4287 | return; | |
4288 | ||
4289 | tp = find_thread_ptid (inferior_ptid); | |
4290 | if (tp == NULL) | |
4291 | return; | |
4292 | ||
4293 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4294 | { |
9add0f1b | 4295 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4296 | |
c906108c SS |
4297 | if (bs->old_val != NULL) |
4298 | { | |
4299 | value_free (bs->old_val); | |
4300 | bs->old_val = NULL; | |
4301 | } | |
4302 | } | |
4303 | } | |
4304 | ||
f3b1572e PA |
4305 | /* Called when a command is about to proceed the inferior. */ |
4306 | ||
4307 | static void | |
4308 | breakpoint_about_to_proceed (void) | |
4309 | { | |
4310 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4311 | { | |
4312 | struct thread_info *tp = inferior_thread (); | |
4313 | ||
4314 | /* Allow inferior function calls in breakpoint commands to not | |
4315 | interrupt the command list. When the call finishes | |
4316 | successfully, the inferior will be standing at the same | |
4317 | breakpoint as if nothing happened. */ | |
16c381f0 | 4318 | if (tp->control.in_infcall) |
f3b1572e PA |
4319 | return; |
4320 | } | |
4321 | ||
4322 | breakpoint_proceeded = 1; | |
4323 | } | |
4324 | ||
4a64f543 MS |
4325 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4326 | command. */ | |
c906108c | 4327 | static void |
4efb68b1 | 4328 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4329 | { |
4330 | executing_breakpoint_commands = 0; | |
4331 | } | |
4332 | ||
abf85f46 JK |
4333 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4334 | or its equivalent. */ | |
4335 | ||
4336 | static int | |
4337 | command_line_is_silent (struct command_line *cmd) | |
4338 | { | |
4339 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4340 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4341 | } | |
4342 | ||
4a64f543 MS |
4343 | /* Execute all the commands associated with all the breakpoints at |
4344 | this location. Any of these commands could cause the process to | |
4345 | proceed beyond this point, etc. We look out for such changes by | |
4346 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4347 | |
347bddb7 PA |
4348 | Returns true if a breakpoint command resumed the inferior. In that |
4349 | case, it is the caller's responsibility to recall it again with the | |
4350 | bpstat of the current thread. */ | |
4351 | ||
4352 | static int | |
4353 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4354 | { |
4355 | bpstat bs; | |
4356 | struct cleanup *old_chain; | |
347bddb7 | 4357 | int again = 0; |
c906108c SS |
4358 | |
4359 | /* Avoid endless recursion if a `source' command is contained | |
4360 | in bs->commands. */ | |
4361 | if (executing_breakpoint_commands) | |
347bddb7 | 4362 | return 0; |
c906108c SS |
4363 | |
4364 | executing_breakpoint_commands = 1; | |
4365 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4366 | ||
cf6c5ffb TT |
4367 | prevent_dont_repeat (); |
4368 | ||
4a64f543 | 4369 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4370 | bs = *bsp; |
4371 | ||
4372 | breakpoint_proceeded = 0; | |
4373 | for (; bs != NULL; bs = bs->next) | |
4374 | { | |
9add0f1b | 4375 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4376 | struct command_line *cmd; |
4377 | struct cleanup *this_cmd_tree_chain; | |
4378 | ||
4379 | /* Take ownership of the BSP's command tree, if it has one. | |
4380 | ||
4381 | The command tree could legitimately contain commands like | |
4382 | 'step' and 'next', which call clear_proceed_status, which | |
4383 | frees stop_bpstat's command tree. To make sure this doesn't | |
4384 | free the tree we're executing out from under us, we need to | |
4385 | take ownership of the tree ourselves. Since a given bpstat's | |
4386 | commands are only executed once, we don't need to copy it; we | |
4387 | can clear the pointer in the bpstat, and make sure we free | |
4388 | the tree when we're done. */ | |
9add0f1b TT |
4389 | ccmd = bs->commands; |
4390 | bs->commands = NULL; | |
abf85f46 JK |
4391 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4392 | cmd = ccmd ? ccmd->commands : NULL; | |
4393 | if (command_line_is_silent (cmd)) | |
4394 | { | |
4395 | /* The action has been already done by bpstat_stop_status. */ | |
4396 | cmd = cmd->next; | |
4397 | } | |
6c50ab1c | 4398 | |
c906108c SS |
4399 | while (cmd != NULL) |
4400 | { | |
4401 | execute_control_command (cmd); | |
4402 | ||
4403 | if (breakpoint_proceeded) | |
4404 | break; | |
4405 | else | |
4406 | cmd = cmd->next; | |
4407 | } | |
6c50ab1c JB |
4408 | |
4409 | /* We can free this command tree now. */ | |
4410 | do_cleanups (this_cmd_tree_chain); | |
4411 | ||
c906108c | 4412 | if (breakpoint_proceeded) |
32c1e744 VP |
4413 | { |
4414 | if (target_can_async_p ()) | |
347bddb7 PA |
4415 | /* If we are in async mode, then the target might be still |
4416 | running, not stopped at any breakpoint, so nothing for | |
4417 | us to do here -- just return to the event loop. */ | |
4418 | ; | |
32c1e744 VP |
4419 | else |
4420 | /* In sync mode, when execute_control_command returns | |
4421 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4422 | Breakpoint commands for that stop were not run, since |
4423 | execute_command does not run breakpoint commands -- | |
4424 | only command_line_handler does, but that one is not | |
4425 | involved in execution of breakpoint commands. So, we | |
4426 | can now execute breakpoint commands. It should be | |
4427 | noted that making execute_command do bpstat actions is | |
4428 | not an option -- in this case we'll have recursive | |
4429 | invocation of bpstat for each breakpoint with a | |
4430 | command, and can easily blow up GDB stack. Instead, we | |
4431 | return true, which will trigger the caller to recall us | |
4432 | with the new stop_bpstat. */ | |
4433 | again = 1; | |
4434 | break; | |
32c1e744 | 4435 | } |
c906108c | 4436 | } |
c2b8ed2c | 4437 | do_cleanups (old_chain); |
347bddb7 PA |
4438 | return again; |
4439 | } | |
4440 | ||
4441 | void | |
4442 | bpstat_do_actions (void) | |
4443 | { | |
353d1d73 JK |
4444 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4445 | ||
347bddb7 PA |
4446 | /* Do any commands attached to breakpoint we are stopped at. */ |
4447 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4448 | && target_has_execution | |
4449 | && !is_exited (inferior_ptid) | |
4450 | && !is_executing (inferior_ptid)) | |
4451 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4452 | and only return when it is stopped at the next breakpoint, we | |
4453 | keep doing breakpoint actions until it returns false to | |
4454 | indicate the inferior was not resumed. */ | |
16c381f0 | 4455 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4456 | break; |
353d1d73 JK |
4457 | |
4458 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4459 | } |
4460 | ||
fa4727a6 DJ |
4461 | /* Print out the (old or new) value associated with a watchpoint. */ |
4462 | ||
4463 | static void | |
4464 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4465 | { | |
4466 | if (val == NULL) | |
4467 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4468 | else | |
79a45b7d TT |
4469 | { |
4470 | struct value_print_options opts; | |
4471 | get_user_print_options (&opts); | |
4472 | value_print (val, stream, &opts); | |
4473 | } | |
fa4727a6 DJ |
4474 | } |
4475 | ||
e514a9d6 | 4476 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4477 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4478 | 'print_it' in the bpstat structure. Under some circumstances we |
4479 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4480 | normal_stop(). */ |
e514a9d6 JM |
4481 | |
4482 | static enum print_stop_action | |
4483 | print_bp_stop_message (bpstat bs) | |
4484 | { | |
4485 | switch (bs->print_it) | |
4486 | { | |
4487 | case print_it_noop: | |
4a64f543 | 4488 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4489 | return PRINT_UNKNOWN; |
4490 | break; | |
4491 | ||
4492 | case print_it_done: | |
4493 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4494 | relevant messages. */ |
e514a9d6 JM |
4495 | return PRINT_SRC_AND_LOC; |
4496 | break; | |
4497 | ||
4498 | case print_it_normal: | |
4f8d1dc6 | 4499 | { |
f431efe5 PA |
4500 | struct breakpoint *b = bs->breakpoint_at; |
4501 | ||
1a6a67de TJB |
4502 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4503 | which has since been deleted. */ | |
4504 | if (b == NULL) | |
4505 | return PRINT_UNKNOWN; | |
4506 | ||
348d480f PA |
4507 | /* Normal case. Call the breakpoint's print_it method. */ |
4508 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4509 | } |
348d480f | 4510 | break; |
3086aeae | 4511 | |
e514a9d6 | 4512 | default: |
8e65ff28 | 4513 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4514 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4515 | break; |
c906108c | 4516 | } |
c906108c SS |
4517 | } |
4518 | ||
edcc5120 TT |
4519 | /* A helper function that prints a shared library stopped event. */ |
4520 | ||
4521 | static void | |
4522 | print_solib_event (int is_catchpoint) | |
4523 | { | |
4524 | int any_deleted | |
4525 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4526 | int any_added | |
4527 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4528 | ||
4529 | if (!is_catchpoint) | |
4530 | { | |
4531 | if (any_added || any_deleted) | |
4532 | ui_out_text (current_uiout, | |
4533 | _("Stopped due to shared library event:\n")); | |
4534 | else | |
4535 | ui_out_text (current_uiout, | |
4536 | _("Stopped due to shared library event (no " | |
4537 | "libraries added or removed)\n")); | |
4538 | } | |
4539 | ||
4540 | if (ui_out_is_mi_like_p (current_uiout)) | |
4541 | ui_out_field_string (current_uiout, "reason", | |
4542 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4543 | ||
4544 | if (any_deleted) | |
4545 | { | |
4546 | struct cleanup *cleanup; | |
4547 | char *name; | |
4548 | int ix; | |
4549 | ||
4550 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4551 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4552 | "removed"); | |
4553 | for (ix = 0; | |
4554 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4555 | ix, name); | |
4556 | ++ix) | |
4557 | { | |
4558 | if (ix > 0) | |
4559 | ui_out_text (current_uiout, " "); | |
4560 | ui_out_field_string (current_uiout, "library", name); | |
4561 | ui_out_text (current_uiout, "\n"); | |
4562 | } | |
4563 | ||
4564 | do_cleanups (cleanup); | |
4565 | } | |
4566 | ||
4567 | if (any_added) | |
4568 | { | |
4569 | struct so_list *iter; | |
4570 | int ix; | |
4571 | struct cleanup *cleanup; | |
4572 | ||
4573 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4574 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4575 | "added"); | |
4576 | for (ix = 0; | |
4577 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4578 | ix, iter); | |
4579 | ++ix) | |
4580 | { | |
4581 | if (ix > 0) | |
4582 | ui_out_text (current_uiout, " "); | |
4583 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4584 | ui_out_text (current_uiout, "\n"); | |
4585 | } | |
4586 | ||
4587 | do_cleanups (cleanup); | |
4588 | } | |
4589 | } | |
4590 | ||
e514a9d6 JM |
4591 | /* Print a message indicating what happened. This is called from |
4592 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4593 | list - a list of the eventpoints that caused this stop. KIND is |
4594 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4595 | routine calls the generic print routine for printing a message |
4596 | about reasons for stopping. This will print (for example) the | |
4597 | "Breakpoint n," part of the output. The return value of this | |
4598 | routine is one of: | |
c906108c | 4599 | |
4a64f543 | 4600 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4601 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4602 | code to print the location. An example is |
c5aa993b JM |
4603 | "Breakpoint 1, " which should be followed by |
4604 | the location. | |
917317f4 | 4605 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4606 | to also print the location part of the message. |
4607 | An example is the catch/throw messages, which | |
4a64f543 | 4608 | don't require a location appended to the end. |
917317f4 | 4609 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4610 | further info to be printed. */ |
c906108c | 4611 | |
917317f4 | 4612 | enum print_stop_action |
36dfb11c | 4613 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4614 | { |
4615 | int val; | |
c5aa993b | 4616 | |
c906108c | 4617 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4618 | (Currently all watchpoints go on the bpstat whether hit or not. |
4619 | That probably could (should) be changed, provided care is taken | |
c906108c | 4620 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4621 | for (; bs; bs = bs->next) |
4622 | { | |
4623 | val = print_bp_stop_message (bs); | |
4624 | if (val == PRINT_SRC_ONLY | |
4625 | || val == PRINT_SRC_AND_LOC | |
4626 | || val == PRINT_NOTHING) | |
4627 | return val; | |
4628 | } | |
c906108c | 4629 | |
36dfb11c TT |
4630 | /* If we had hit a shared library event breakpoint, |
4631 | print_bp_stop_message would print out this message. If we hit an | |
4632 | OS-level shared library event, do the same thing. */ | |
4633 | if (kind == TARGET_WAITKIND_LOADED) | |
4634 | { | |
edcc5120 | 4635 | print_solib_event (0); |
36dfb11c TT |
4636 | return PRINT_NOTHING; |
4637 | } | |
4638 | ||
e514a9d6 | 4639 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4640 | with and nothing was printed. */ |
917317f4 | 4641 | return PRINT_UNKNOWN; |
c906108c SS |
4642 | } |
4643 | ||
4a64f543 MS |
4644 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
4645 | used inside a catch_errors to evaluate the breakpoint condition. | |
4646 | The argument is a "struct expression *" that has been cast to a | |
4647 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
4648 | |
4649 | static int | |
4efb68b1 | 4650 | breakpoint_cond_eval (void *exp) |
c906108c | 4651 | { |
278cd55f | 4652 | struct value *mark = value_mark (); |
c5aa993b | 4653 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4654 | |
c906108c SS |
4655 | value_free_to_mark (mark); |
4656 | return i; | |
4657 | } | |
4658 | ||
5760d0ab | 4659 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4660 | |
4661 | static bpstat | |
5760d0ab | 4662 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4663 | { |
4664 | bpstat bs; | |
4665 | ||
4666 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4667 | bs->next = NULL; |
4668 | **bs_link_pointer = bs; | |
4669 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4670 | bs->breakpoint_at = bl->owner; |
4671 | bs->bp_location_at = bl; | |
4672 | incref_bp_location (bl); | |
c906108c SS |
4673 | /* If the condition is false, etc., don't do the commands. */ |
4674 | bs->commands = NULL; | |
4675 | bs->old_val = NULL; | |
4676 | bs->print_it = print_it_normal; | |
4677 | return bs; | |
4678 | } | |
4679 | \f | |
d983da9c DJ |
4680 | /* The target has stopped with waitstatus WS. Check if any hardware |
4681 | watchpoints have triggered, according to the target. */ | |
4682 | ||
4683 | int | |
4684 | watchpoints_triggered (struct target_waitstatus *ws) | |
4685 | { | |
d92524f1 | 4686 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4687 | CORE_ADDR addr; |
4688 | struct breakpoint *b; | |
4689 | ||
4690 | if (!stopped_by_watchpoint) | |
4691 | { | |
4692 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4693 | as not triggered. */ | |
4694 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4695 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4696 | { |
4697 | struct watchpoint *w = (struct watchpoint *) b; | |
4698 | ||
4699 | w->watchpoint_triggered = watch_triggered_no; | |
4700 | } | |
d983da9c DJ |
4701 | |
4702 | return 0; | |
4703 | } | |
4704 | ||
4705 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4706 | { | |
4707 | /* We were stopped by a watchpoint, but we don't know where. | |
4708 | Mark all watchpoints as unknown. */ | |
4709 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4710 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4711 | { |
4712 | struct watchpoint *w = (struct watchpoint *) b; | |
4713 | ||
4714 | w->watchpoint_triggered = watch_triggered_unknown; | |
4715 | } | |
d983da9c | 4716 | |
3c4797ba | 4717 | return 1; |
d983da9c DJ |
4718 | } |
4719 | ||
4720 | /* The target could report the data address. Mark watchpoints | |
4721 | affected by this data address as triggered, and all others as not | |
4722 | triggered. */ | |
4723 | ||
4724 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4725 | if (is_hardware_watchpoint (b)) |
d983da9c | 4726 | { |
3a5c3e22 | 4727 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4728 | struct bp_location *loc; |
d983da9c | 4729 | |
3a5c3e22 | 4730 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4731 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4732 | { |
3a5c3e22 | 4733 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4734 | { |
3a5c3e22 PA |
4735 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4736 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4737 | |
4738 | if (newaddr == start) | |
4739 | { | |
3a5c3e22 | 4740 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4741 | break; |
4742 | } | |
4743 | } | |
4744 | /* Exact match not required. Within range is sufficient. */ | |
4745 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4746 | addr, loc->address, | |
4747 | loc->length)) | |
4748 | { | |
3a5c3e22 | 4749 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4750 | break; |
4751 | } | |
4752 | } | |
d983da9c DJ |
4753 | } |
4754 | ||
4755 | return 1; | |
4756 | } | |
4757 | ||
c906108c SS |
4758 | /* Possible return values for watchpoint_check (this can't be an enum |
4759 | because of check_errors). */ | |
4760 | /* The watchpoint has been deleted. */ | |
4761 | #define WP_DELETED 1 | |
4762 | /* The value has changed. */ | |
4763 | #define WP_VALUE_CHANGED 2 | |
4764 | /* The value has not changed. */ | |
4765 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4766 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4767 | #define WP_IGNORE 4 | |
c906108c SS |
4768 | |
4769 | #define BP_TEMPFLAG 1 | |
4770 | #define BP_HARDWAREFLAG 2 | |
4771 | ||
4a64f543 MS |
4772 | /* Evaluate watchpoint condition expression and check if its value |
4773 | changed. | |
553e4c11 JB |
4774 | |
4775 | P should be a pointer to struct bpstat, but is defined as a void * | |
4776 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4777 | |
4778 | static int | |
4efb68b1 | 4779 | watchpoint_check (void *p) |
c906108c SS |
4780 | { |
4781 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4782 | struct watchpoint *b; |
c906108c SS |
4783 | struct frame_info *fr; |
4784 | int within_current_scope; | |
4785 | ||
f431efe5 | 4786 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4787 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4788 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4789 | |
f6bc2008 PA |
4790 | /* If this is a local watchpoint, we only want to check if the |
4791 | watchpoint frame is in scope if the current thread is the thread | |
4792 | that was used to create the watchpoint. */ | |
4793 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4794 | return WP_IGNORE; |
f6bc2008 | 4795 | |
c906108c SS |
4796 | if (b->exp_valid_block == NULL) |
4797 | within_current_scope = 1; | |
4798 | else | |
4799 | { | |
edb3359d DJ |
4800 | struct frame_info *frame = get_current_frame (); |
4801 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4802 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4803 | ||
4a64f543 MS |
4804 | /* in_function_epilogue_p() returns a non-zero value if we're |
4805 | still in the function but the stack frame has already been | |
4806 | invalidated. Since we can't rely on the values of local | |
4807 | variables after the stack has been destroyed, we are treating | |
4808 | the watchpoint in that state as `not changed' without further | |
4809 | checking. Don't mark watchpoints as changed if the current | |
4810 | frame is in an epilogue - even if they are in some other | |
4811 | frame, our view of the stack is likely to be wrong and | |
4812 | frame_find_by_id could error out. */ | |
a0f49112 | 4813 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4814 | return WP_IGNORE; |
a0f49112 | 4815 | |
101dcfbe | 4816 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4817 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4818 | |
4819 | /* If we've gotten confused in the unwinder, we might have | |
4820 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4821 | if (within_current_scope) |
4822 | { | |
4823 | struct symbol *function; | |
4824 | ||
4825 | function = get_frame_function (fr); | |
4826 | if (function == NULL | |
4827 | || !contained_in (b->exp_valid_block, | |
4828 | SYMBOL_BLOCK_VALUE (function))) | |
4829 | within_current_scope = 0; | |
4830 | } | |
69fbadd5 | 4831 | |
edb3359d | 4832 | if (within_current_scope) |
c906108c SS |
4833 | /* If we end up stopping, the current frame will get selected |
4834 | in normal_stop. So this call to select_frame won't affect | |
4835 | the user. */ | |
0f7d239c | 4836 | select_frame (fr); |
c906108c | 4837 | } |
c5aa993b | 4838 | |
c906108c SS |
4839 | if (within_current_scope) |
4840 | { | |
4a64f543 MS |
4841 | /* We use value_{,free_to_}mark because it could be a *long* |
4842 | time before we return to the command level and call | |
4843 | free_all_values. We can't call free_all_values because we | |
4844 | might be in the middle of evaluating a function call. */ | |
c906108c | 4845 | |
0cf6dd15 | 4846 | int pc = 0; |
9c06b0b4 | 4847 | struct value *mark; |
fa4727a6 DJ |
4848 | struct value *new_val; |
4849 | ||
3a5c3e22 | 4850 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4851 | /* Since we don't know the exact trigger address (from |
4852 | stopped_data_address), just tell the user we've triggered | |
4853 | a mask watchpoint. */ | |
4854 | return WP_VALUE_CHANGED; | |
4855 | ||
4856 | mark = value_mark (); | |
3a1115a0 | 4857 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4858 | |
4a64f543 MS |
4859 | /* We use value_equal_contents instead of value_equal because |
4860 | the latter coerces an array to a pointer, thus comparing just | |
4861 | the address of the array instead of its contents. This is | |
4862 | not what we want. */ | |
fa4727a6 | 4863 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4864 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4865 | { |
fa4727a6 DJ |
4866 | if (new_val != NULL) |
4867 | { | |
4868 | release_value (new_val); | |
4869 | value_free_to_mark (mark); | |
4870 | } | |
c906108c SS |
4871 | bs->old_val = b->val; |
4872 | b->val = new_val; | |
fa4727a6 | 4873 | b->val_valid = 1; |
c906108c SS |
4874 | return WP_VALUE_CHANGED; |
4875 | } | |
4876 | else | |
4877 | { | |
60e1c644 | 4878 | /* Nothing changed. */ |
c906108c | 4879 | value_free_to_mark (mark); |
c906108c SS |
4880 | return WP_VALUE_NOT_CHANGED; |
4881 | } | |
4882 | } | |
4883 | else | |
4884 | { | |
79a45e25 PA |
4885 | struct ui_out *uiout = current_uiout; |
4886 | ||
c906108c | 4887 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4888 | if we temporarily ignored the watchpoint, then when |
4889 | we reenter the block in which it is valid it contains | |
4890 | garbage (in the case of a function, it may have two | |
4891 | garbage values, one before and one after the prologue). | |
4892 | So we can't even detect the first assignment to it and | |
4893 | watch after that (since the garbage may or may not equal | |
4894 | the first value assigned). */ | |
348d480f PA |
4895 | /* We print all the stop information in |
4896 | breakpoint_ops->print_it, but in this case, by the time we | |
4897 | call breakpoint_ops->print_it this bp will be deleted | |
4898 | already. So we have no choice but print the information | |
4899 | here. */ | |
9dc5e2a9 | 4900 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4901 | ui_out_field_string |
4902 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4903 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4904 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4905 | ui_out_text (uiout, |
4906 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4907 | which its expression is valid.\n"); |
4ce44c66 | 4908 | |
cdac0397 | 4909 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4910 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4911 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4912 | |
4913 | return WP_DELETED; | |
4914 | } | |
4915 | } | |
4916 | ||
18a18393 | 4917 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4918 | breakpoint location BL. This function does not check if we should |
4919 | stop, only if BL explains the stop. */ | |
4920 | ||
18a18393 | 4921 | static int |
6c95b8df | 4922 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4923 | struct address_space *aspace, CORE_ADDR bp_addr, |
4924 | const struct target_waitstatus *ws) | |
18a18393 VP |
4925 | { |
4926 | struct breakpoint *b = bl->owner; | |
4927 | ||
348d480f | 4928 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4929 | gdb_assert (b != NULL); |
4930 | ||
09ac7c10 | 4931 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4932 | } |
4933 | ||
3a5c3e22 PA |
4934 | /* Determine if the watched values have actually changed, and we |
4935 | should stop. If not, set BS->stop to 0. */ | |
4936 | ||
18a18393 VP |
4937 | static void |
4938 | bpstat_check_watchpoint (bpstat bs) | |
4939 | { | |
2bdf28a0 | 4940 | const struct bp_location *bl; |
3a5c3e22 | 4941 | struct watchpoint *b; |
2bdf28a0 JK |
4942 | |
4943 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4944 | bl = bs->bp_location_at; |
2bdf28a0 | 4945 | gdb_assert (bl != NULL); |
3a5c3e22 | 4946 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4947 | gdb_assert (b != NULL); |
18a18393 | 4948 | |
18a18393 | 4949 | { |
18a18393 VP |
4950 | int must_check_value = 0; |
4951 | ||
3a5c3e22 | 4952 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4953 | /* For a software watchpoint, we must always check the |
4954 | watched value. */ | |
4955 | must_check_value = 1; | |
4956 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4957 | /* We have a hardware watchpoint (read, write, or access) | |
4958 | and the target earlier reported an address watched by | |
4959 | this watchpoint. */ | |
4960 | must_check_value = 1; | |
4961 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4962 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4963 | /* We were stopped by a hardware watchpoint, but the target could |
4964 | not report the data address. We must check the watchpoint's | |
4965 | value. Access and read watchpoints are out of luck; without | |
4966 | a data address, we can't figure it out. */ | |
4967 | must_check_value = 1; | |
3a5c3e22 | 4968 | |
18a18393 VP |
4969 | if (must_check_value) |
4970 | { | |
3e43a32a MS |
4971 | char *message |
4972 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4973 | b->base.number); |
18a18393 VP |
4974 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4975 | int e = catch_errors (watchpoint_check, bs, message, | |
4976 | RETURN_MASK_ALL); | |
4977 | do_cleanups (cleanups); | |
4978 | switch (e) | |
4979 | { | |
4980 | case WP_DELETED: | |
4981 | /* We've already printed what needs to be printed. */ | |
4982 | bs->print_it = print_it_done; | |
4983 | /* Stop. */ | |
4984 | break; | |
60e1c644 PA |
4985 | case WP_IGNORE: |
4986 | bs->print_it = print_it_noop; | |
4987 | bs->stop = 0; | |
4988 | break; | |
18a18393 | 4989 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4990 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4991 | { |
85d721b8 PA |
4992 | /* There are two cases to consider here: |
4993 | ||
4a64f543 | 4994 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4995 | In that case, trust the target, and always report |
4996 | the watchpoint hit to the user. Even though | |
4997 | reads don't cause value changes, the value may | |
4998 | have changed since the last time it was read, and | |
4999 | since we're not trapping writes, we will not see | |
5000 | those, and as such we should ignore our notion of | |
5001 | old value. | |
5002 | ||
4a64f543 | 5003 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5004 | reads and writes. There are two ways this may |
5005 | happen: | |
5006 | ||
4a64f543 | 5007 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5008 | reads only, but can break on accesses (reads or |
5009 | writes), such as e.g., x86. We detect this case | |
5010 | at the time we try to insert read watchpoints. | |
5011 | ||
4a64f543 | 5012 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5013 | watchpoints, but, the user set an access or write |
5014 | watchpoint watching the same memory as this read | |
5015 | watchpoint. | |
5016 | ||
5017 | If we're watching memory writes as well as reads, | |
5018 | ignore watchpoint hits when we find that the | |
5019 | value hasn't changed, as reads don't cause | |
5020 | changes. This still gives false positives when | |
5021 | the program writes the same value to memory as | |
5022 | what there was already in memory (we will confuse | |
5023 | it for a read), but it's much better than | |
5024 | nothing. */ | |
5025 | ||
5026 | int other_write_watchpoint = 0; | |
5027 | ||
5028 | if (bl->watchpoint_type == hw_read) | |
5029 | { | |
5030 | struct breakpoint *other_b; | |
5031 | ||
5032 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5033 | if (other_b->type == bp_hardware_watchpoint |
5034 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5035 | { |
3a5c3e22 PA |
5036 | struct watchpoint *other_w = |
5037 | (struct watchpoint *) other_b; | |
5038 | ||
5039 | if (other_w->watchpoint_triggered | |
5040 | == watch_triggered_yes) | |
5041 | { | |
5042 | other_write_watchpoint = 1; | |
5043 | break; | |
5044 | } | |
85d721b8 PA |
5045 | } |
5046 | } | |
5047 | ||
5048 | if (other_write_watchpoint | |
5049 | || bl->watchpoint_type == hw_access) | |
5050 | { | |
5051 | /* We're watching the same memory for writes, | |
5052 | and the value changed since the last time we | |
5053 | updated it, so this trap must be for a write. | |
5054 | Ignore it. */ | |
5055 | bs->print_it = print_it_noop; | |
5056 | bs->stop = 0; | |
5057 | } | |
18a18393 VP |
5058 | } |
5059 | break; | |
5060 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5061 | if (b->base.type == bp_hardware_watchpoint |
5062 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5063 | { |
5064 | /* Don't stop: write watchpoints shouldn't fire if | |
5065 | the value hasn't changed. */ | |
5066 | bs->print_it = print_it_noop; | |
5067 | bs->stop = 0; | |
5068 | } | |
5069 | /* Stop. */ | |
5070 | break; | |
5071 | default: | |
5072 | /* Can't happen. */ | |
5073 | case 0: | |
5074 | /* Error from catch_errors. */ | |
3a5c3e22 | 5075 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5076 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5077 | /* We've already printed what needs to be printed. */ |
5078 | bs->print_it = print_it_done; | |
5079 | break; | |
5080 | } | |
5081 | } | |
5082 | else /* must_check_value == 0 */ | |
5083 | { | |
5084 | /* This is a case where some watchpoint(s) triggered, but | |
5085 | not at the address of this watchpoint, or else no | |
5086 | watchpoint triggered after all. So don't print | |
5087 | anything for this watchpoint. */ | |
5088 | bs->print_it = print_it_noop; | |
5089 | bs->stop = 0; | |
5090 | } | |
5091 | } | |
5092 | } | |
5093 | ||
5094 | ||
5095 | /* Check conditions (condition proper, frame, thread and ignore count) | |
5096 | of breakpoint referred to by BS. If we should not stop for this | |
5097 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5098 | |
18a18393 VP |
5099 | static void |
5100 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5101 | { | |
5102 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
5103 | const struct bp_location *bl; |
5104 | struct breakpoint *b; | |
5105 | ||
5106 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5107 | bl = bs->bp_location_at; |
2bdf28a0 | 5108 | gdb_assert (bl != NULL); |
f431efe5 | 5109 | b = bs->breakpoint_at; |
2bdf28a0 | 5110 | gdb_assert (b != NULL); |
18a18393 | 5111 | |
b775012e LM |
5112 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5113 | need to do so again since GDB does not know if we stopped due to a | |
5114 | breakpoint or a single step breakpoint. */ | |
5115 | ||
18a18393 | 5116 | if (frame_id_p (b->frame_id) |
edb3359d | 5117 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
5118 | bs->stop = 0; |
5119 | else if (bs->stop) | |
5120 | { | |
5121 | int value_is_zero = 0; | |
60e1c644 PA |
5122 | struct expression *cond; |
5123 | ||
7371cf6d PM |
5124 | /* Evaluate Python breakpoints that have a "stop" |
5125 | method implemented. */ | |
5126 | if (b->py_bp_object) | |
5127 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
5128 | ||
60e1c644 | 5129 | if (is_watchpoint (b)) |
3a5c3e22 PA |
5130 | { |
5131 | struct watchpoint *w = (struct watchpoint *) b; | |
5132 | ||
5133 | cond = w->cond_exp; | |
5134 | } | |
60e1c644 PA |
5135 | else |
5136 | cond = bl->cond; | |
5137 | ||
f431efe5 | 5138 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 5139 | { |
60e1c644 | 5140 | int within_current_scope = 1; |
3a5c3e22 | 5141 | struct watchpoint * w; |
60e1c644 | 5142 | |
c5bc3a77 DJ |
5143 | /* We use value_mark and value_free_to_mark because it could |
5144 | be a long time before we return to the command level and | |
5145 | call free_all_values. We can't call free_all_values | |
5146 | because we might be in the middle of evaluating a | |
5147 | function call. */ | |
5148 | struct value *mark = value_mark (); | |
5149 | ||
3a5c3e22 PA |
5150 | if (is_watchpoint (b)) |
5151 | w = (struct watchpoint *) b; | |
5152 | else | |
5153 | w = NULL; | |
5154 | ||
edb3359d DJ |
5155 | /* Need to select the frame, with all that implies so that |
5156 | the conditions will have the right context. Because we | |
5157 | use the frame, we will not see an inlined function's | |
5158 | variables when we arrive at a breakpoint at the start | |
5159 | of the inlined function; the current frame will be the | |
5160 | call site. */ | |
3a5c3e22 | 5161 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
5162 | select_frame (get_current_frame ()); |
5163 | else | |
5164 | { | |
5165 | struct frame_info *frame; | |
5166 | ||
5167 | /* For local watchpoint expressions, which particular | |
5168 | instance of a local is being watched matters, so we | |
5169 | keep track of the frame to evaluate the expression | |
5170 | in. To evaluate the condition however, it doesn't | |
5171 | really matter which instantiation of the function | |
5172 | where the condition makes sense triggers the | |
5173 | watchpoint. This allows an expression like "watch | |
5174 | global if q > 10" set in `func', catch writes to | |
5175 | global on all threads that call `func', or catch | |
5176 | writes on all recursive calls of `func' by a single | |
5177 | thread. We simply always evaluate the condition in | |
5178 | the innermost frame that's executing where it makes | |
5179 | sense to evaluate the condition. It seems | |
5180 | intuitive. */ | |
3a5c3e22 | 5181 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
5182 | if (frame != NULL) |
5183 | select_frame (frame); | |
5184 | else | |
5185 | within_current_scope = 0; | |
5186 | } | |
5187 | if (within_current_scope) | |
5188 | value_is_zero | |
5189 | = catch_errors (breakpoint_cond_eval, cond, | |
5190 | "Error in testing breakpoint condition:\n", | |
5191 | RETURN_MASK_ALL); | |
5192 | else | |
5193 | { | |
5194 | warning (_("Watchpoint condition cannot be tested " | |
5195 | "in the current scope")); | |
5196 | /* If we failed to set the right context for this | |
5197 | watchpoint, unconditionally report it. */ | |
5198 | value_is_zero = 0; | |
5199 | } | |
4a64f543 | 5200 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 5201 | value_free_to_mark (mark); |
18a18393 | 5202 | } |
60e1c644 PA |
5203 | |
5204 | if (cond && value_is_zero) | |
18a18393 VP |
5205 | { |
5206 | bs->stop = 0; | |
5207 | } | |
5208 | else if (b->thread != -1 && b->thread != thread_id) | |
5209 | { | |
5210 | bs->stop = 0; | |
5211 | } | |
5212 | else if (b->ignore_count > 0) | |
5213 | { | |
5214 | b->ignore_count--; | |
18a18393 | 5215 | bs->stop = 0; |
4a64f543 | 5216 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 5217 | ++(b->hit_count); |
8d3788bd | 5218 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
5219 | } |
5220 | } | |
5221 | } | |
5222 | ||
5223 | ||
9709f61c | 5224 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5225 | BP_ADDR in thread PTID. |
c906108c | 5226 | |
d983da9c | 5227 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5228 | don't understand this stop. Result is a chain of bpstat's such |
5229 | that: | |
c906108c | 5230 | |
c5aa993b | 5231 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5232 | |
c5aa993b | 5233 | if we understand why we stopped, the result is not null. |
c906108c | 5234 | |
c5aa993b JM |
5235 | Each element of the chain refers to a particular breakpoint or |
5236 | watchpoint at which we have stopped. (We may have stopped for | |
5237 | several reasons concurrently.) | |
c906108c | 5238 | |
c5aa993b JM |
5239 | Each element of the chain has valid next, breakpoint_at, |
5240 | commands, FIXME??? fields. */ | |
c906108c SS |
5241 | |
5242 | bpstat | |
6c95b8df | 5243 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5244 | CORE_ADDR bp_addr, ptid_t ptid, |
5245 | const struct target_waitstatus *ws) | |
c906108c | 5246 | { |
0d381245 | 5247 | struct breakpoint *b = NULL; |
afe38095 | 5248 | struct bp_location *bl; |
20874c92 | 5249 | struct bp_location *loc; |
5760d0ab JK |
5250 | /* First item of allocated bpstat's. */ |
5251 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5252 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5253 | bpstat bs; |
20874c92 | 5254 | int ix; |
429374b8 | 5255 | int need_remove_insert; |
f431efe5 | 5256 | int removed_any; |
c906108c | 5257 | |
f431efe5 PA |
5258 | /* First, build the bpstat chain with locations that explain a |
5259 | target stop, while being careful to not set the target running, | |
5260 | as that may invalidate locations (in particular watchpoint | |
5261 | locations are recreated). Resuming will happen here with | |
5262 | breakpoint conditions or watchpoint expressions that include | |
5263 | inferior function calls. */ | |
c5aa993b | 5264 | |
429374b8 JK |
5265 | ALL_BREAKPOINTS (b) |
5266 | { | |
5267 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5268 | continue; | |
a5606eee | 5269 | |
429374b8 JK |
5270 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5271 | { | |
4a64f543 MS |
5272 | /* For hardware watchpoints, we look only at the first |
5273 | location. The watchpoint_check function will work on the | |
5274 | entire expression, not the individual locations. For | |
5275 | read watchpoints, the watchpoints_triggered function has | |
5276 | checked all locations already. */ | |
429374b8 JK |
5277 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5278 | break; | |
18a18393 | 5279 | |
f6592439 | 5280 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5281 | continue; |
c5aa993b | 5282 | |
09ac7c10 | 5283 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5284 | continue; |
c5aa993b | 5285 | |
4a64f543 MS |
5286 | /* Come here if it's a watchpoint, or if the break address |
5287 | matches. */ | |
c5aa993b | 5288 | |
4a64f543 MS |
5289 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5290 | explain stop. */ | |
c5aa993b | 5291 | |
f431efe5 PA |
5292 | /* Assume we stop. Should we find a watchpoint that is not |
5293 | actually triggered, or if the condition of the breakpoint | |
5294 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5295 | bs->stop = 1; |
5296 | bs->print = 1; | |
d983da9c | 5297 | |
f431efe5 PA |
5298 | /* If this is a scope breakpoint, mark the associated |
5299 | watchpoint as triggered so that we will handle the | |
5300 | out-of-scope event. We'll get to the watchpoint next | |
5301 | iteration. */ | |
d0fb5eae | 5302 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5303 | { |
5304 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5305 | ||
5306 | w->watchpoint_triggered = watch_triggered_yes; | |
5307 | } | |
f431efe5 PA |
5308 | } |
5309 | } | |
5310 | ||
5311 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5312 | { | |
f1310107 | 5313 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5314 | { |
5760d0ab | 5315 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5316 | /* For hits of moribund locations, we should just proceed. */ |
5317 | bs->stop = 0; | |
5318 | bs->print = 0; | |
5319 | bs->print_it = print_it_noop; | |
5320 | } | |
5321 | } | |
5322 | ||
edcc5120 TT |
5323 | /* A bit of special processing for shlib breakpoints. We need to |
5324 | process solib loading here, so that the lists of loaded and | |
5325 | unloaded libraries are correct before we handle "catch load" and | |
5326 | "catch unload". */ | |
5327 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5328 | { | |
5d268276 | 5329 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5330 | { |
5331 | handle_solib_event (); | |
5332 | break; | |
5333 | } | |
5334 | } | |
5335 | ||
f431efe5 PA |
5336 | /* Now go through the locations that caused the target to stop, and |
5337 | check whether we're interested in reporting this stop to higher | |
5338 | layers, or whether we should resume the target transparently. */ | |
5339 | ||
5340 | removed_any = 0; | |
5341 | ||
5760d0ab | 5342 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5343 | { |
5344 | if (!bs->stop) | |
5345 | continue; | |
5346 | ||
f431efe5 | 5347 | b = bs->breakpoint_at; |
348d480f PA |
5348 | b->ops->check_status (bs); |
5349 | if (bs->stop) | |
28010a5d | 5350 | { |
348d480f | 5351 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5352 | |
429374b8 JK |
5353 | if (bs->stop) |
5354 | { | |
5355 | ++(b->hit_count); | |
8d3788bd | 5356 | observer_notify_breakpoint_modified (b); |
c906108c | 5357 | |
4a64f543 | 5358 | /* We will stop here. */ |
429374b8 JK |
5359 | if (b->disposition == disp_disable) |
5360 | { | |
816338b5 SS |
5361 | --(b->enable_count); |
5362 | if (b->enable_count <= 0 | |
5363 | && b->enable_state != bp_permanent) | |
429374b8 | 5364 | b->enable_state = bp_disabled; |
f431efe5 | 5365 | removed_any = 1; |
429374b8 JK |
5366 | } |
5367 | if (b->silent) | |
5368 | bs->print = 0; | |
5369 | bs->commands = b->commands; | |
9add0f1b | 5370 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5371 | if (command_line_is_silent (bs->commands |
5372 | ? bs->commands->commands : NULL)) | |
5373 | bs->print = 0; | |
9d6e6e84 HZ |
5374 | |
5375 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5376 | } |
5377 | ||
348d480f | 5378 | } |
a9b3a50f PA |
5379 | |
5380 | /* Print nothing for this entry if we don't stop or don't | |
5381 | print. */ | |
5382 | if (!bs->stop || !bs->print) | |
5383 | bs->print_it = print_it_noop; | |
429374b8 | 5384 | } |
876fa593 | 5385 | |
d983da9c DJ |
5386 | /* If we aren't stopping, the value of some hardware watchpoint may |
5387 | not have changed, but the intermediate memory locations we are | |
5388 | watching may have. Don't bother if we're stopping; this will get | |
5389 | done later. */ | |
d832cb68 | 5390 | need_remove_insert = 0; |
5760d0ab JK |
5391 | if (! bpstat_causes_stop (bs_head)) |
5392 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5393 | if (!bs->stop |
f431efe5 PA |
5394 | && bs->breakpoint_at |
5395 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5396 | { |
3a5c3e22 PA |
5397 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5398 | ||
5399 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5400 | need_remove_insert = 1; |
d983da9c DJ |
5401 | } |
5402 | ||
d832cb68 | 5403 | if (need_remove_insert) |
2d134ed3 | 5404 | update_global_location_list (1); |
f431efe5 PA |
5405 | else if (removed_any) |
5406 | update_global_location_list (0); | |
d832cb68 | 5407 | |
5760d0ab | 5408 | return bs_head; |
c906108c | 5409 | } |
628fe4e4 JK |
5410 | |
5411 | static void | |
5412 | handle_jit_event (void) | |
5413 | { | |
5414 | struct frame_info *frame; | |
5415 | struct gdbarch *gdbarch; | |
5416 | ||
5417 | /* Switch terminal for any messages produced by | |
5418 | breakpoint_re_set. */ | |
5419 | target_terminal_ours_for_output (); | |
5420 | ||
5421 | frame = get_current_frame (); | |
5422 | gdbarch = get_frame_arch (frame); | |
5423 | ||
5424 | jit_event_handler (gdbarch); | |
5425 | ||
5426 | target_terminal_inferior (); | |
5427 | } | |
5428 | ||
5429 | /* Prepare WHAT final decision for infrun. */ | |
5430 | ||
5431 | /* Decide what infrun needs to do with this bpstat. */ | |
5432 | ||
c906108c | 5433 | struct bpstat_what |
0e30163f | 5434 | bpstat_what (bpstat bs_head) |
c906108c | 5435 | { |
c906108c | 5436 | struct bpstat_what retval; |
628fe4e4 | 5437 | int jit_event = 0; |
0e30163f | 5438 | bpstat bs; |
c906108c | 5439 | |
628fe4e4 | 5440 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5441 | retval.call_dummy = STOP_NONE; |
186c406b | 5442 | retval.is_longjmp = 0; |
628fe4e4 | 5443 | |
0e30163f | 5444 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5445 | { |
628fe4e4 JK |
5446 | /* Extract this BS's action. After processing each BS, we check |
5447 | if its action overrides all we've seem so far. */ | |
5448 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5449 | enum bptype bptype; | |
5450 | ||
c906108c | 5451 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5452 | { |
5453 | /* I suspect this can happen if it was a momentary | |
5454 | breakpoint which has since been deleted. */ | |
5455 | bptype = bp_none; | |
5456 | } | |
20874c92 | 5457 | else |
f431efe5 | 5458 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5459 | |
5460 | switch (bptype) | |
c906108c SS |
5461 | { |
5462 | case bp_none: | |
628fe4e4 | 5463 | break; |
c906108c SS |
5464 | case bp_breakpoint: |
5465 | case bp_hardware_breakpoint: | |
5466 | case bp_until: | |
5467 | case bp_finish: | |
a9b3a50f | 5468 | case bp_shlib_event: |
c906108c SS |
5469 | if (bs->stop) |
5470 | { | |
5471 | if (bs->print) | |
628fe4e4 | 5472 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5473 | else |
628fe4e4 | 5474 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5475 | } |
5476 | else | |
628fe4e4 | 5477 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5478 | break; |
5479 | case bp_watchpoint: | |
5480 | case bp_hardware_watchpoint: | |
5481 | case bp_read_watchpoint: | |
5482 | case bp_access_watchpoint: | |
5483 | if (bs->stop) | |
5484 | { | |
5485 | if (bs->print) | |
628fe4e4 | 5486 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5487 | else |
628fe4e4 | 5488 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5489 | } |
5490 | else | |
628fe4e4 JK |
5491 | { |
5492 | /* There was a watchpoint, but we're not stopping. | |
5493 | This requires no further action. */ | |
5494 | } | |
c906108c SS |
5495 | break; |
5496 | case bp_longjmp: | |
e2e4d78b | 5497 | case bp_longjmp_call_dummy: |
186c406b | 5498 | case bp_exception: |
628fe4e4 | 5499 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5500 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5501 | break; |
5502 | case bp_longjmp_resume: | |
186c406b | 5503 | case bp_exception_resume: |
628fe4e4 | 5504 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5505 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5506 | break; |
5507 | case bp_step_resume: | |
5508 | if (bs->stop) | |
628fe4e4 JK |
5509 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5510 | else | |
c906108c | 5511 | { |
628fe4e4 JK |
5512 | /* It is for the wrong frame. */ |
5513 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5514 | } |
c906108c | 5515 | break; |
2c03e5be PA |
5516 | case bp_hp_step_resume: |
5517 | if (bs->stop) | |
5518 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5519 | else | |
5520 | { | |
5521 | /* It is for the wrong frame. */ | |
5522 | this_action = BPSTAT_WHAT_SINGLE; | |
5523 | } | |
5524 | break; | |
c906108c | 5525 | case bp_watchpoint_scope: |
c4093a6a | 5526 | case bp_thread_event: |
1900040c | 5527 | case bp_overlay_event: |
0fd8e87f | 5528 | case bp_longjmp_master: |
aa7d318d | 5529 | case bp_std_terminate_master: |
186c406b | 5530 | case bp_exception_master: |
628fe4e4 | 5531 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5532 | break; |
ce78b96d | 5533 | case bp_catchpoint: |
c5aa993b JM |
5534 | if (bs->stop) |
5535 | { | |
5536 | if (bs->print) | |
628fe4e4 | 5537 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5538 | else |
628fe4e4 | 5539 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5540 | } |
5541 | else | |
628fe4e4 JK |
5542 | { |
5543 | /* There was a catchpoint, but we're not stopping. | |
5544 | This requires no further action. */ | |
5545 | } | |
5546 | break; | |
628fe4e4 JK |
5547 | case bp_jit_event: |
5548 | jit_event = 1; | |
5549 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5550 | break; |
c906108c | 5551 | case bp_call_dummy: |
53a5351d JM |
5552 | /* Make sure the action is stop (silent or noisy), |
5553 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5554 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5555 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5556 | break; |
5557 | case bp_std_terminate: | |
5558 | /* Make sure the action is stop (silent or noisy), | |
5559 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5560 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5561 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5562 | break; |
1042e4c0 | 5563 | case bp_tracepoint: |
7a697b8d | 5564 | case bp_fast_tracepoint: |
0fb4aa4b | 5565 | case bp_static_tracepoint: |
1042e4c0 SS |
5566 | /* Tracepoint hits should not be reported back to GDB, and |
5567 | if one got through somehow, it should have been filtered | |
5568 | out already. */ | |
5569 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5570 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5571 | break; |
5572 | case bp_gnu_ifunc_resolver: | |
5573 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5574 | this_action = BPSTAT_WHAT_SINGLE; | |
5575 | break; | |
5576 | case bp_gnu_ifunc_resolver_return: | |
5577 | /* The breakpoint will be removed, execution will restart from the | |
5578 | PC of the former breakpoint. */ | |
5579 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5580 | break; | |
e7e0cddf SS |
5581 | |
5582 | case bp_dprintf: | |
a11cfd87 HZ |
5583 | if (bs->stop) |
5584 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5585 | else | |
5586 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5587 | break; |
5588 | ||
628fe4e4 JK |
5589 | default: |
5590 | internal_error (__FILE__, __LINE__, | |
5591 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5592 | } |
628fe4e4 JK |
5593 | |
5594 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5595 | } |
628fe4e4 | 5596 | |
0e30163f JK |
5597 | /* These operations may affect the bs->breakpoint_at state so they are |
5598 | delayed after MAIN_ACTION is decided above. */ | |
5599 | ||
628fe4e4 JK |
5600 | if (jit_event) |
5601 | { | |
5602 | if (debug_infrun) | |
5603 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5604 | ||
5605 | handle_jit_event (); | |
5606 | } | |
5607 | ||
0e30163f JK |
5608 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5609 | { | |
5610 | struct breakpoint *b = bs->breakpoint_at; | |
5611 | ||
5612 | if (b == NULL) | |
5613 | continue; | |
5614 | switch (b->type) | |
5615 | { | |
5616 | case bp_gnu_ifunc_resolver: | |
5617 | gnu_ifunc_resolver_stop (b); | |
5618 | break; | |
5619 | case bp_gnu_ifunc_resolver_return: | |
5620 | gnu_ifunc_resolver_return_stop (b); | |
5621 | break; | |
5622 | } | |
5623 | } | |
5624 | ||
c906108c SS |
5625 | return retval; |
5626 | } | |
5627 | ||
5628 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5629 | without hardware support). This isn't related to a specific bpstat, | |
5630 | just to things like whether watchpoints are set. */ | |
5631 | ||
c5aa993b | 5632 | int |
fba45db2 | 5633 | bpstat_should_step (void) |
c906108c SS |
5634 | { |
5635 | struct breakpoint *b; | |
cc59ec59 | 5636 | |
c906108c | 5637 | ALL_BREAKPOINTS (b) |
717a8278 | 5638 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5639 | return 1; |
c906108c SS |
5640 | return 0; |
5641 | } | |
5642 | ||
67822962 PA |
5643 | int |
5644 | bpstat_causes_stop (bpstat bs) | |
5645 | { | |
5646 | for (; bs != NULL; bs = bs->next) | |
5647 | if (bs->stop) | |
5648 | return 1; | |
5649 | ||
5650 | return 0; | |
5651 | } | |
5652 | ||
c906108c | 5653 | \f |
c5aa993b | 5654 | |
170b53b2 UW |
5655 | /* Compute a string of spaces suitable to indent the next line |
5656 | so it starts at the position corresponding to the table column | |
5657 | named COL_NAME in the currently active table of UIOUT. */ | |
5658 | ||
5659 | static char * | |
5660 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5661 | { | |
5662 | static char wrap_indent[80]; | |
5663 | int i, total_width, width, align; | |
5664 | char *text; | |
5665 | ||
5666 | total_width = 0; | |
5667 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5668 | { | |
5669 | if (strcmp (text, col_name) == 0) | |
5670 | { | |
5671 | gdb_assert (total_width < sizeof wrap_indent); | |
5672 | memset (wrap_indent, ' ', total_width); | |
5673 | wrap_indent[total_width] = 0; | |
5674 | ||
5675 | return wrap_indent; | |
5676 | } | |
5677 | ||
5678 | total_width += width + 1; | |
5679 | } | |
5680 | ||
5681 | return NULL; | |
5682 | } | |
5683 | ||
b775012e LM |
5684 | /* Determine if the locations of this breakpoint will have their conditions |
5685 | evaluated by the target, host or a mix of both. Returns the following: | |
5686 | ||
5687 | "host": Host evals condition. | |
5688 | "host or target": Host or Target evals condition. | |
5689 | "target": Target evals condition. | |
5690 | */ | |
5691 | ||
5692 | static const char * | |
5693 | bp_condition_evaluator (struct breakpoint *b) | |
5694 | { | |
5695 | struct bp_location *bl; | |
5696 | char host_evals = 0; | |
5697 | char target_evals = 0; | |
5698 | ||
5699 | if (!b) | |
5700 | return NULL; | |
5701 | ||
5702 | if (!is_breakpoint (b)) | |
5703 | return NULL; | |
5704 | ||
5705 | if (gdb_evaluates_breakpoint_condition_p () | |
5706 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5707 | return condition_evaluation_host; | |
5708 | ||
5709 | for (bl = b->loc; bl; bl = bl->next) | |
5710 | { | |
5711 | if (bl->cond_bytecode) | |
5712 | target_evals++; | |
5713 | else | |
5714 | host_evals++; | |
5715 | } | |
5716 | ||
5717 | if (host_evals && target_evals) | |
5718 | return condition_evaluation_both; | |
5719 | else if (target_evals) | |
5720 | return condition_evaluation_target; | |
5721 | else | |
5722 | return condition_evaluation_host; | |
5723 | } | |
5724 | ||
5725 | /* Determine the breakpoint location's condition evaluator. This is | |
5726 | similar to bp_condition_evaluator, but for locations. */ | |
5727 | ||
5728 | static const char * | |
5729 | bp_location_condition_evaluator (struct bp_location *bl) | |
5730 | { | |
5731 | if (bl && !is_breakpoint (bl->owner)) | |
5732 | return NULL; | |
5733 | ||
5734 | if (gdb_evaluates_breakpoint_condition_p () | |
5735 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5736 | return condition_evaluation_host; | |
5737 | ||
5738 | if (bl && bl->cond_bytecode) | |
5739 | return condition_evaluation_target; | |
5740 | else | |
5741 | return condition_evaluation_host; | |
5742 | } | |
5743 | ||
859825b8 JK |
5744 | /* Print the LOC location out of the list of B->LOC locations. */ |
5745 | ||
170b53b2 UW |
5746 | static void |
5747 | print_breakpoint_location (struct breakpoint *b, | |
5748 | struct bp_location *loc) | |
0d381245 | 5749 | { |
79a45e25 | 5750 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5751 | struct cleanup *old_chain = save_current_program_space (); |
5752 | ||
859825b8 JK |
5753 | if (loc != NULL && loc->shlib_disabled) |
5754 | loc = NULL; | |
5755 | ||
6c95b8df PA |
5756 | if (loc != NULL) |
5757 | set_current_program_space (loc->pspace); | |
5758 | ||
56435ebe TT |
5759 | if (b->display_canonical) |
5760 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5761 | else if (loc && loc->symtab) |
0d381245 VP |
5762 | { |
5763 | struct symbol *sym | |
5764 | = find_pc_sect_function (loc->address, loc->section); | |
5765 | if (sym) | |
5766 | { | |
5767 | ui_out_text (uiout, "in "); | |
5768 | ui_out_field_string (uiout, "func", | |
5769 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5770 | ui_out_text (uiout, " "); |
5771 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5772 | ui_out_text (uiout, "at "); | |
0d381245 | 5773 | } |
05cba821 JK |
5774 | ui_out_field_string (uiout, "file", |
5775 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5776 | ui_out_text (uiout, ":"); |
05cba821 | 5777 | |
0d381245 | 5778 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5779 | ui_out_field_string (uiout, "fullname", |
5780 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5781 | |
f8eba3c6 | 5782 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5783 | } |
859825b8 | 5784 | else if (loc) |
0d381245 | 5785 | { |
f99d8bf4 PA |
5786 | struct ui_file *stb = mem_fileopen (); |
5787 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5788 | |
f99d8bf4 | 5789 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5790 | demangle, ""); |
0d381245 | 5791 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5792 | |
5793 | do_cleanups (stb_chain); | |
0d381245 | 5794 | } |
859825b8 JK |
5795 | else |
5796 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5797 | |
b775012e LM |
5798 | if (loc && is_breakpoint (b) |
5799 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5800 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5801 | { | |
5802 | ui_out_text (uiout, " ("); | |
5803 | ui_out_field_string (uiout, "evaluated-by", | |
5804 | bp_location_condition_evaluator (loc)); | |
5805 | ui_out_text (uiout, ")"); | |
5806 | } | |
5807 | ||
6c95b8df | 5808 | do_cleanups (old_chain); |
0d381245 VP |
5809 | } |
5810 | ||
269b11a2 PA |
5811 | static const char * |
5812 | bptype_string (enum bptype type) | |
c906108c | 5813 | { |
c4093a6a JM |
5814 | struct ep_type_description |
5815 | { | |
5816 | enum bptype type; | |
5817 | char *description; | |
5818 | }; | |
5819 | static struct ep_type_description bptypes[] = | |
c906108c | 5820 | { |
c5aa993b JM |
5821 | {bp_none, "?deleted?"}, |
5822 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5823 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5824 | {bp_until, "until"}, |
5825 | {bp_finish, "finish"}, | |
5826 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5827 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5828 | {bp_read_watchpoint, "read watchpoint"}, |
5829 | {bp_access_watchpoint, "acc watchpoint"}, | |
5830 | {bp_longjmp, "longjmp"}, | |
5831 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5832 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5833 | {bp_exception, "exception"}, |
5834 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5835 | {bp_step_resume, "step resume"}, |
2c03e5be | 5836 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5837 | {bp_watchpoint_scope, "watchpoint scope"}, |
5838 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5839 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5840 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5841 | {bp_thread_event, "thread events"}, |
1900040c | 5842 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5843 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5844 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5845 | {bp_exception_master, "exception master"}, |
ce78b96d | 5846 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5847 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5848 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5849 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5850 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5851 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5852 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5853 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5854 | }; |
269b11a2 PA |
5855 | |
5856 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5857 | || ((int) type != bptypes[(int) type].type)) | |
5858 | internal_error (__FILE__, __LINE__, | |
5859 | _("bptypes table does not describe type #%d."), | |
5860 | (int) type); | |
5861 | ||
5862 | return bptypes[(int) type].description; | |
5863 | } | |
5864 | ||
998580f1 MK |
5865 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5866 | For CLI, prefix the list with the string 'inf'. */ | |
5867 | ||
5868 | static void | |
5869 | output_thread_groups (struct ui_out *uiout, | |
5870 | const char *field_name, | |
5871 | VEC(int) *inf_num, | |
5872 | int mi_only) | |
5873 | { | |
752eb8b4 | 5874 | struct cleanup *back_to; |
998580f1 MK |
5875 | int is_mi = ui_out_is_mi_like_p (uiout); |
5876 | int inf; | |
5877 | int i; | |
5878 | ||
5879 | /* For backward compatibility, don't display inferiors in CLI unless | |
5880 | there are several. Always display them for MI. */ | |
5881 | if (!is_mi && mi_only) | |
5882 | return; | |
5883 | ||
752eb8b4 TT |
5884 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
5885 | ||
998580f1 MK |
5886 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
5887 | { | |
5888 | if (is_mi) | |
5889 | { | |
5890 | char mi_group[10]; | |
5891 | ||
5892 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5893 | ui_out_field_string (uiout, NULL, mi_group); | |
5894 | } | |
5895 | else | |
5896 | { | |
5897 | if (i == 0) | |
5898 | ui_out_text (uiout, " inf "); | |
5899 | else | |
5900 | ui_out_text (uiout, ", "); | |
5901 | ||
5902 | ui_out_text (uiout, plongest (inf)); | |
5903 | } | |
5904 | } | |
5905 | ||
5906 | do_cleanups (back_to); | |
5907 | } | |
5908 | ||
269b11a2 PA |
5909 | /* Print B to gdb_stdout. */ |
5910 | ||
5911 | static void | |
5912 | print_one_breakpoint_location (struct breakpoint *b, | |
5913 | struct bp_location *loc, | |
5914 | int loc_number, | |
5915 | struct bp_location **last_loc, | |
269b11a2 PA |
5916 | int allflag) |
5917 | { | |
5918 | struct command_line *l; | |
c2c6d25f | 5919 | static char bpenables[] = "nynny"; |
c906108c | 5920 | |
79a45e25 | 5921 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5922 | int header_of_multiple = 0; |
5923 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5924 | struct value_print_options opts; |
5925 | ||
5926 | get_user_print_options (&opts); | |
0d381245 VP |
5927 | |
5928 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5929 | /* See comment in print_one_breakpoint concerning treatment of |
5930 | breakpoints with single disabled location. */ | |
0d381245 VP |
5931 | if (loc == NULL |
5932 | && (b->loc != NULL | |
5933 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5934 | header_of_multiple = 1; | |
5935 | if (loc == NULL) | |
5936 | loc = b->loc; | |
5937 | ||
c4093a6a JM |
5938 | annotate_record (); |
5939 | ||
5940 | /* 1 */ | |
5941 | annotate_field (0); | |
0d381245 VP |
5942 | if (part_of_multiple) |
5943 | { | |
5944 | char *formatted; | |
0c6773c1 | 5945 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5946 | ui_out_field_string (uiout, "number", formatted); |
5947 | xfree (formatted); | |
5948 | } | |
5949 | else | |
5950 | { | |
5951 | ui_out_field_int (uiout, "number", b->number); | |
5952 | } | |
c4093a6a JM |
5953 | |
5954 | /* 2 */ | |
5955 | annotate_field (1); | |
0d381245 VP |
5956 | if (part_of_multiple) |
5957 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5958 | else |
5959 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5960 | |
5961 | /* 3 */ | |
5962 | annotate_field (2); | |
0d381245 VP |
5963 | if (part_of_multiple) |
5964 | ui_out_field_skip (uiout, "disp"); | |
5965 | else | |
2cec12e5 | 5966 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5967 | |
c4093a6a JM |
5968 | |
5969 | /* 4 */ | |
5970 | annotate_field (3); | |
0d381245 | 5971 | if (part_of_multiple) |
54e52265 | 5972 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5973 | else |
4a64f543 MS |
5974 | ui_out_field_fmt (uiout, "enabled", "%c", |
5975 | bpenables[(int) b->enable_state]); | |
54e52265 | 5976 | ui_out_spaces (uiout, 2); |
0d381245 | 5977 | |
c4093a6a JM |
5978 | |
5979 | /* 5 and 6 */ | |
3086aeae | 5980 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5981 | { |
4a64f543 MS |
5982 | /* Although the print_one can possibly print all locations, |
5983 | calling it here is not likely to get any nice result. So, | |
5984 | make sure there's just one location. */ | |
0d381245 | 5985 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5986 | b->ops->print_one (b, last_loc); |
0d381245 | 5987 | } |
3086aeae DJ |
5988 | else |
5989 | switch (b->type) | |
5990 | { | |
5991 | case bp_none: | |
5992 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 5993 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 5994 | break; |
c906108c | 5995 | |
3086aeae DJ |
5996 | case bp_watchpoint: |
5997 | case bp_hardware_watchpoint: | |
5998 | case bp_read_watchpoint: | |
5999 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6000 | { |
6001 | struct watchpoint *w = (struct watchpoint *) b; | |
6002 | ||
6003 | /* Field 4, the address, is omitted (which makes the columns | |
6004 | not line up too nicely with the headers, but the effect | |
6005 | is relatively readable). */ | |
6006 | if (opts.addressprint) | |
6007 | ui_out_field_skip (uiout, "addr"); | |
6008 | annotate_field (5); | |
6009 | ui_out_field_string (uiout, "what", w->exp_string); | |
6010 | } | |
3086aeae DJ |
6011 | break; |
6012 | ||
3086aeae DJ |
6013 | case bp_breakpoint: |
6014 | case bp_hardware_breakpoint: | |
6015 | case bp_until: | |
6016 | case bp_finish: | |
6017 | case bp_longjmp: | |
6018 | case bp_longjmp_resume: | |
e2e4d78b | 6019 | case bp_longjmp_call_dummy: |
186c406b TT |
6020 | case bp_exception: |
6021 | case bp_exception_resume: | |
3086aeae | 6022 | case bp_step_resume: |
2c03e5be | 6023 | case bp_hp_step_resume: |
3086aeae DJ |
6024 | case bp_watchpoint_scope: |
6025 | case bp_call_dummy: | |
aa7d318d | 6026 | case bp_std_terminate: |
3086aeae DJ |
6027 | case bp_shlib_event: |
6028 | case bp_thread_event: | |
6029 | case bp_overlay_event: | |
0fd8e87f | 6030 | case bp_longjmp_master: |
aa7d318d | 6031 | case bp_std_terminate_master: |
186c406b | 6032 | case bp_exception_master: |
1042e4c0 | 6033 | case bp_tracepoint: |
7a697b8d | 6034 | case bp_fast_tracepoint: |
0fb4aa4b | 6035 | case bp_static_tracepoint: |
e7e0cddf | 6036 | case bp_dprintf: |
4efc6507 | 6037 | case bp_jit_event: |
0e30163f JK |
6038 | case bp_gnu_ifunc_resolver: |
6039 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6040 | if (opts.addressprint) |
3086aeae DJ |
6041 | { |
6042 | annotate_field (4); | |
54e52265 | 6043 | if (header_of_multiple) |
0d381245 | 6044 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6045 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6046 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6047 | else |
5af949e3 UW |
6048 | ui_out_field_core_addr (uiout, "addr", |
6049 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6050 | } |
6051 | annotate_field (5); | |
0d381245 | 6052 | if (!header_of_multiple) |
170b53b2 | 6053 | print_breakpoint_location (b, loc); |
0d381245 | 6054 | if (b->loc) |
a6d9a66e | 6055 | *last_loc = b->loc; |
3086aeae DJ |
6056 | break; |
6057 | } | |
c906108c | 6058 | |
6c95b8df | 6059 | |
998580f1 | 6060 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6061 | { |
6062 | struct inferior *inf; | |
998580f1 MK |
6063 | VEC(int) *inf_num = NULL; |
6064 | int mi_only = 1; | |
6c95b8df | 6065 | |
998580f1 | 6066 | ALL_INFERIORS (inf) |
6c95b8df PA |
6067 | { |
6068 | if (inf->pspace == loc->pspace) | |
998580f1 | 6069 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6070 | } |
998580f1 MK |
6071 | |
6072 | /* For backward compatibility, don't display inferiors in CLI unless | |
6073 | there are several. Always display for MI. */ | |
6074 | if (allflag | |
6075 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6076 | && (number_of_program_spaces () > 1 | |
6077 | || number_of_inferiors () > 1) | |
6078 | /* LOC is for existing B, it cannot be in | |
6079 | moribund_locations and thus having NULL OWNER. */ | |
6080 | && loc->owner->type != bp_catchpoint)) | |
6081 | mi_only = 0; | |
6082 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6083 | VEC_free (int, inf_num); | |
6c95b8df PA |
6084 | } |
6085 | ||
4a306c9a | 6086 | if (!part_of_multiple) |
c4093a6a | 6087 | { |
4a306c9a JB |
6088 | if (b->thread != -1) |
6089 | { | |
6090 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6091 | "stop only in" line a little further down. */ |
4a306c9a JB |
6092 | ui_out_text (uiout, " thread "); |
6093 | ui_out_field_int (uiout, "thread", b->thread); | |
6094 | } | |
6095 | else if (b->task != 0) | |
6096 | { | |
6097 | ui_out_text (uiout, " task "); | |
6098 | ui_out_field_int (uiout, "task", b->task); | |
6099 | } | |
c4093a6a | 6100 | } |
f1310107 | 6101 | |
8b93c638 | 6102 | ui_out_text (uiout, "\n"); |
f1310107 | 6103 | |
348d480f | 6104 | if (!part_of_multiple) |
f1310107 TJB |
6105 | b->ops->print_one_detail (b, uiout); |
6106 | ||
0d381245 | 6107 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6108 | { |
6109 | annotate_field (6); | |
8b93c638 | 6110 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6111 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6112 | the frame ID. */ |
5af949e3 UW |
6113 | ui_out_field_core_addr (uiout, "frame", |
6114 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6115 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6116 | } |
6117 | ||
28010a5d | 6118 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6119 | { |
6120 | annotate_field (7); | |
d77f58be | 6121 | if (is_tracepoint (b)) |
1042e4c0 SS |
6122 | ui_out_text (uiout, "\ttrace only if "); |
6123 | else | |
6124 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6125 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6126 | |
6127 | /* Print whether the target is doing the breakpoint's condition | |
6128 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6129 | if (is_breakpoint (b) | |
6130 | && breakpoint_condition_evaluation_mode () | |
6131 | == condition_evaluation_target) | |
6132 | { | |
6133 | ui_out_text (uiout, " ("); | |
6134 | ui_out_field_string (uiout, "evaluated-by", | |
6135 | bp_condition_evaluator (b)); | |
6136 | ui_out_text (uiout, " evals)"); | |
6137 | } | |
0101ce28 JJ |
6138 | ui_out_text (uiout, "\n"); |
6139 | } | |
6140 | ||
0d381245 | 6141 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6142 | { |
4a64f543 | 6143 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6144 | ui_out_text (uiout, "\tstop only in thread "); |
6145 | ui_out_field_int (uiout, "thread", b->thread); | |
6146 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6147 | } |
6148 | ||
556ec64d YQ |
6149 | if (!part_of_multiple) |
6150 | { | |
6151 | if (b->hit_count) | |
31f56a27 YQ |
6152 | { |
6153 | /* FIXME should make an annotation for this. */ | |
6154 | if (is_catchpoint (b)) | |
6155 | ui_out_text (uiout, "\tcatchpoint"); | |
6156 | else if (is_tracepoint (b)) | |
6157 | ui_out_text (uiout, "\ttracepoint"); | |
6158 | else | |
6159 | ui_out_text (uiout, "\tbreakpoint"); | |
6160 | ui_out_text (uiout, " already hit "); | |
6161 | ui_out_field_int (uiout, "times", b->hit_count); | |
6162 | if (b->hit_count == 1) | |
6163 | ui_out_text (uiout, " time\n"); | |
6164 | else | |
6165 | ui_out_text (uiout, " times\n"); | |
6166 | } | |
556ec64d YQ |
6167 | else |
6168 | { | |
31f56a27 YQ |
6169 | /* Output the count also if it is zero, but only if this is mi. */ |
6170 | if (ui_out_is_mi_like_p (uiout)) | |
6171 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6172 | } |
6173 | } | |
8b93c638 | 6174 | |
0d381245 | 6175 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6176 | { |
6177 | annotate_field (8); | |
8b93c638 JM |
6178 | ui_out_text (uiout, "\tignore next "); |
6179 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6180 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6181 | } |
059fb39f | 6182 | |
816338b5 SS |
6183 | /* Note that an enable count of 1 corresponds to "enable once" |
6184 | behavior, which is reported by the combination of enablement and | |
6185 | disposition, so we don't need to mention it here. */ | |
6186 | if (!part_of_multiple && b->enable_count > 1) | |
6187 | { | |
6188 | annotate_field (8); | |
6189 | ui_out_text (uiout, "\tdisable after "); | |
6190 | /* Tweak the wording to clarify that ignore and enable counts | |
6191 | are distinct, and have additive effect. */ | |
6192 | if (b->ignore_count) | |
6193 | ui_out_text (uiout, "additional "); | |
6194 | else | |
6195 | ui_out_text (uiout, "next "); | |
6196 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6197 | ui_out_text (uiout, " hits\n"); | |
6198 | } | |
6199 | ||
f196051f SS |
6200 | if (!part_of_multiple && is_tracepoint (b)) |
6201 | { | |
6202 | struct tracepoint *tp = (struct tracepoint *) b; | |
6203 | ||
6204 | if (tp->traceframe_usage) | |
6205 | { | |
6206 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6207 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6208 | ui_out_text (uiout, " bytes\n"); | |
6209 | } | |
6210 | } | |
d3ce09f5 | 6211 | |
9add0f1b | 6212 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6213 | if (!part_of_multiple && l) |
c4093a6a | 6214 | { |
3b31d625 EZ |
6215 | struct cleanup *script_chain; |
6216 | ||
c4093a6a | 6217 | annotate_field (9); |
3b31d625 | 6218 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6219 | print_command_lines (uiout, l, 4); |
3b31d625 | 6220 | do_cleanups (script_chain); |
c4093a6a | 6221 | } |
d24317b4 | 6222 | |
d9b3f62e | 6223 | if (is_tracepoint (b)) |
1042e4c0 | 6224 | { |
d9b3f62e PA |
6225 | struct tracepoint *t = (struct tracepoint *) b; |
6226 | ||
6227 | if (!part_of_multiple && t->pass_count) | |
6228 | { | |
6229 | annotate_field (10); | |
6230 | ui_out_text (uiout, "\tpass count "); | |
6231 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6232 | ui_out_text (uiout, " \n"); | |
6233 | } | |
f2a8bc8a YQ |
6234 | |
6235 | /* Don't display it when tracepoint or tracepoint location is | |
6236 | pending. */ | |
6237 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6238 | { | |
6239 | annotate_field (11); | |
6240 | ||
6241 | if (ui_out_is_mi_like_p (uiout)) | |
6242 | ui_out_field_string (uiout, "installed", | |
6243 | loc->inserted ? "y" : "n"); | |
6244 | else | |
6245 | { | |
6246 | if (loc->inserted) | |
6247 | ui_out_text (uiout, "\t"); | |
6248 | else | |
6249 | ui_out_text (uiout, "\tnot "); | |
6250 | ui_out_text (uiout, "installed on target\n"); | |
6251 | } | |
6252 | } | |
1042e4c0 SS |
6253 | } |
6254 | ||
d24317b4 VP |
6255 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6256 | { | |
3a5c3e22 PA |
6257 | if (is_watchpoint (b)) |
6258 | { | |
6259 | struct watchpoint *w = (struct watchpoint *) b; | |
6260 | ||
6261 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6262 | } | |
6263 | else if (b->addr_string) | |
d24317b4 | 6264 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6265 | } |
c4093a6a | 6266 | } |
c5aa993b | 6267 | |
0d381245 VP |
6268 | static void |
6269 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6270 | struct bp_location **last_loc, |
6c95b8df | 6271 | int allflag) |
0d381245 | 6272 | { |
8d3788bd | 6273 | struct cleanup *bkpt_chain; |
79a45e25 | 6274 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6275 | |
6276 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6277 | ||
12c5a436 | 6278 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6279 | do_cleanups (bkpt_chain); |
0d381245 VP |
6280 | |
6281 | /* If this breakpoint has custom print function, | |
6282 | it's already printed. Otherwise, print individual | |
6283 | locations, if any. */ | |
6284 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6285 | { | |
4a64f543 MS |
6286 | /* If breakpoint has a single location that is disabled, we |
6287 | print it as if it had several locations, since otherwise it's | |
6288 | hard to represent "breakpoint enabled, location disabled" | |
6289 | situation. | |
6290 | ||
6291 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6292 | internally, that's not a property exposed to user. */ |
0d381245 | 6293 | if (b->loc |
a5606eee | 6294 | && !is_hardware_watchpoint (b) |
8d3788bd | 6295 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6296 | { |
6297 | struct bp_location *loc; | |
6298 | int n = 1; | |
8d3788bd | 6299 | |
0d381245 | 6300 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6301 | { |
6302 | struct cleanup *inner2 = | |
6303 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6304 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6305 | do_cleanups (inner2); | |
6306 | } | |
0d381245 VP |
6307 | } |
6308 | } | |
6309 | } | |
6310 | ||
a6d9a66e UW |
6311 | static int |
6312 | breakpoint_address_bits (struct breakpoint *b) | |
6313 | { | |
6314 | int print_address_bits = 0; | |
6315 | struct bp_location *loc; | |
6316 | ||
6317 | for (loc = b->loc; loc; loc = loc->next) | |
6318 | { | |
c7437ca6 PA |
6319 | int addr_bit; |
6320 | ||
6321 | /* Software watchpoints that aren't watching memory don't have | |
6322 | an address to print. */ | |
6323 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6324 | continue; | |
6325 | ||
6326 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6327 | if (addr_bit > print_address_bits) |
6328 | print_address_bits = addr_bit; | |
6329 | } | |
6330 | ||
6331 | return print_address_bits; | |
6332 | } | |
0d381245 | 6333 | |
c4093a6a JM |
6334 | struct captured_breakpoint_query_args |
6335 | { | |
6336 | int bnum; | |
6337 | }; | |
c5aa993b | 6338 | |
c4093a6a | 6339 | static int |
2b65245e | 6340 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6341 | { |
6342 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6343 | struct breakpoint *b; |
a6d9a66e | 6344 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6345 | |
c4093a6a JM |
6346 | ALL_BREAKPOINTS (b) |
6347 | { | |
6348 | if (args->bnum == b->number) | |
c5aa993b | 6349 | { |
12c5a436 | 6350 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6351 | return GDB_RC_OK; |
c5aa993b | 6352 | } |
c4093a6a JM |
6353 | } |
6354 | return GDB_RC_NONE; | |
6355 | } | |
c5aa993b | 6356 | |
c4093a6a | 6357 | enum gdb_rc |
4a64f543 MS |
6358 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6359 | char **error_message) | |
c4093a6a JM |
6360 | { |
6361 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6362 | |
c4093a6a JM |
6363 | args.bnum = bnum; |
6364 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6365 | an error. */ |
b0b13bb4 DJ |
6366 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6367 | error_message, RETURN_MASK_ALL) < 0) | |
6368 | return GDB_RC_FAIL; | |
6369 | else | |
6370 | return GDB_RC_OK; | |
c4093a6a | 6371 | } |
c5aa993b | 6372 | |
09d682a4 TT |
6373 | /* Return true if this breakpoint was set by the user, false if it is |
6374 | internal or momentary. */ | |
6375 | ||
6376 | int | |
6377 | user_breakpoint_p (struct breakpoint *b) | |
6378 | { | |
46c6471b | 6379 | return b->number > 0; |
09d682a4 TT |
6380 | } |
6381 | ||
7f3b0473 | 6382 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6383 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6384 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6385 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6386 | ones for which it returns non-zero. Return the total number of | |
6387 | breakpoints listed. */ | |
c906108c | 6388 | |
d77f58be | 6389 | static int |
e5a67952 | 6390 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6391 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6392 | { |
52f0bd74 | 6393 | struct breakpoint *b; |
a6d9a66e | 6394 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6395 | int nr_printable_breakpoints; |
3b31d625 | 6396 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6397 | struct value_print_options opts; |
a6d9a66e | 6398 | int print_address_bits = 0; |
269b11a2 | 6399 | int print_type_col_width = 14; |
79a45e25 | 6400 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6401 | |
79a45b7d TT |
6402 | get_user_print_options (&opts); |
6403 | ||
4a64f543 MS |
6404 | /* Compute the number of rows in the table, as well as the size |
6405 | required for address fields. */ | |
7f3b0473 AC |
6406 | nr_printable_breakpoints = 0; |
6407 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6408 | { |
6409 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6410 | if (filter && !filter (b)) | |
6411 | continue; | |
6412 | ||
6413 | /* If we have an "args" string, it is a list of breakpoints to | |
6414 | accept. Skip the others. */ | |
6415 | if (args != NULL && *args != '\0') | |
6416 | { | |
6417 | if (allflag && parse_and_eval_long (args) != b->number) | |
6418 | continue; | |
6419 | if (!allflag && !number_is_in_list (args, b->number)) | |
6420 | continue; | |
6421 | } | |
269b11a2 | 6422 | |
e5a67952 MS |
6423 | if (allflag || user_breakpoint_p (b)) |
6424 | { | |
6425 | int addr_bit, type_len; | |
a6d9a66e | 6426 | |
e5a67952 MS |
6427 | addr_bit = breakpoint_address_bits (b); |
6428 | if (addr_bit > print_address_bits) | |
6429 | print_address_bits = addr_bit; | |
269b11a2 | 6430 | |
e5a67952 MS |
6431 | type_len = strlen (bptype_string (b->type)); |
6432 | if (type_len > print_type_col_width) | |
6433 | print_type_col_width = type_len; | |
6434 | ||
6435 | nr_printable_breakpoints++; | |
6436 | } | |
6437 | } | |
7f3b0473 | 6438 | |
79a45b7d | 6439 | if (opts.addressprint) |
3b31d625 | 6440 | bkpttbl_chain |
3e43a32a MS |
6441 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6442 | nr_printable_breakpoints, | |
3b31d625 | 6443 | "BreakpointTable"); |
8b93c638 | 6444 | else |
3b31d625 | 6445 | bkpttbl_chain |
3e43a32a MS |
6446 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6447 | nr_printable_breakpoints, | |
3b31d625 | 6448 | "BreakpointTable"); |
8b93c638 | 6449 | |
7f3b0473 | 6450 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6451 | annotate_breakpoints_headers (); |
6452 | if (nr_printable_breakpoints > 0) | |
6453 | annotate_field (0); | |
4a64f543 | 6454 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6455 | if (nr_printable_breakpoints > 0) |
6456 | annotate_field (1); | |
269b11a2 | 6457 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6458 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6459 | if (nr_printable_breakpoints > 0) |
6460 | annotate_field (2); | |
4a64f543 | 6461 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6462 | if (nr_printable_breakpoints > 0) |
6463 | annotate_field (3); | |
54e52265 | 6464 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6465 | if (opts.addressprint) |
e5a67952 MS |
6466 | { |
6467 | if (nr_printable_breakpoints > 0) | |
6468 | annotate_field (4); | |
6469 | if (print_address_bits <= 32) | |
6470 | ui_out_table_header (uiout, 10, ui_left, | |
6471 | "addr", "Address"); /* 5 */ | |
6472 | else | |
6473 | ui_out_table_header (uiout, 18, ui_left, | |
6474 | "addr", "Address"); /* 5 */ | |
6475 | } | |
d7faa9e7 AC |
6476 | if (nr_printable_breakpoints > 0) |
6477 | annotate_field (5); | |
6478 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6479 | ui_out_table_body (uiout); | |
6480 | if (nr_printable_breakpoints > 0) | |
6481 | annotate_breakpoints_table (); | |
7f3b0473 | 6482 | |
c4093a6a | 6483 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6484 | { |
6485 | QUIT; | |
6486 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6487 | if (filter && !filter (b)) | |
6488 | continue; | |
6489 | ||
6490 | /* If we have an "args" string, it is a list of breakpoints to | |
6491 | accept. Skip the others. */ | |
6492 | ||
6493 | if (args != NULL && *args != '\0') | |
6494 | { | |
6495 | if (allflag) /* maintenance info breakpoint */ | |
6496 | { | |
6497 | if (parse_and_eval_long (args) != b->number) | |
6498 | continue; | |
6499 | } | |
6500 | else /* all others */ | |
6501 | { | |
6502 | if (!number_is_in_list (args, b->number)) | |
6503 | continue; | |
6504 | } | |
6505 | } | |
6506 | /* We only print out user settable breakpoints unless the | |
6507 | allflag is set. */ | |
6508 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6509 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6510 | } |
6511 | ||
3b31d625 | 6512 | do_cleanups (bkpttbl_chain); |
698384cd | 6513 | |
7f3b0473 | 6514 | if (nr_printable_breakpoints == 0) |
c906108c | 6515 | { |
4a64f543 MS |
6516 | /* If there's a filter, let the caller decide how to report |
6517 | empty list. */ | |
d77f58be SS |
6518 | if (!filter) |
6519 | { | |
e5a67952 | 6520 | if (args == NULL || *args == '\0') |
d77f58be SS |
6521 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6522 | else | |
4a64f543 | 6523 | ui_out_message (uiout, 0, |
e5a67952 MS |
6524 | "No breakpoint or watchpoint matching '%s'.\n", |
6525 | args); | |
d77f58be | 6526 | } |
c906108c SS |
6527 | } |
6528 | else | |
c4093a6a | 6529 | { |
a6d9a66e UW |
6530 | if (last_loc && !server_command) |
6531 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6532 | } |
c906108c | 6533 | |
4a64f543 | 6534 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6535 | there have been breakpoints? */ |
c906108c | 6536 | annotate_breakpoints_table_end (); |
d77f58be SS |
6537 | |
6538 | return nr_printable_breakpoints; | |
c906108c SS |
6539 | } |
6540 | ||
ad443146 SS |
6541 | /* Display the value of default-collect in a way that is generally |
6542 | compatible with the breakpoint list. */ | |
6543 | ||
6544 | static void | |
6545 | default_collect_info (void) | |
6546 | { | |
79a45e25 PA |
6547 | struct ui_out *uiout = current_uiout; |
6548 | ||
ad443146 SS |
6549 | /* If it has no value (which is frequently the case), say nothing; a |
6550 | message like "No default-collect." gets in user's face when it's | |
6551 | not wanted. */ | |
6552 | if (!*default_collect) | |
6553 | return; | |
6554 | ||
6555 | /* The following phrase lines up nicely with per-tracepoint collect | |
6556 | actions. */ | |
6557 | ui_out_text (uiout, "default collect "); | |
6558 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6559 | ui_out_text (uiout, " \n"); | |
6560 | } | |
6561 | ||
c906108c | 6562 | static void |
e5a67952 | 6563 | breakpoints_info (char *args, int from_tty) |
c906108c | 6564 | { |
e5a67952 | 6565 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6566 | |
6567 | default_collect_info (); | |
d77f58be SS |
6568 | } |
6569 | ||
6570 | static void | |
e5a67952 | 6571 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6572 | { |
e5a67952 | 6573 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6574 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6575 | |
6576 | if (num_printed == 0) | |
6577 | { | |
e5a67952 | 6578 | if (args == NULL || *args == '\0') |
d77f58be SS |
6579 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6580 | else | |
e5a67952 | 6581 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6582 | } |
c906108c SS |
6583 | } |
6584 | ||
7a292a7a | 6585 | static void |
e5a67952 | 6586 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6587 | { |
e5a67952 | 6588 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6589 | |
6590 | default_collect_info (); | |
c906108c SS |
6591 | } |
6592 | ||
0d381245 | 6593 | static int |
714835d5 | 6594 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6595 | struct program_space *pspace, |
714835d5 | 6596 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6597 | { |
6598 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6599 | |
0d381245 VP |
6600 | for (; bl; bl = bl->next) |
6601 | { | |
6c95b8df PA |
6602 | if (bl->pspace == pspace |
6603 | && bl->address == pc | |
0d381245 VP |
6604 | && (!overlay_debugging || bl->section == section)) |
6605 | return 1; | |
6606 | } | |
6607 | return 0; | |
6608 | } | |
6609 | ||
672f9b60 | 6610 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6611 | concerns with logical breakpoints, so we match program spaces, not |
6612 | address spaces. */ | |
c906108c SS |
6613 | |
6614 | static void | |
6c95b8df PA |
6615 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6616 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6617 | struct obj_section *section, int thread) |
c906108c | 6618 | { |
52f0bd74 AC |
6619 | int others = 0; |
6620 | struct breakpoint *b; | |
c906108c SS |
6621 | |
6622 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6623 | others += (user_breakpoint_p (b) |
6624 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6625 | if (others > 0) |
6626 | { | |
a3f17187 AC |
6627 | if (others == 1) |
6628 | printf_filtered (_("Note: breakpoint ")); | |
6629 | else /* if (others == ???) */ | |
6630 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6631 | ALL_BREAKPOINTS (b) |
672f9b60 | 6632 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6633 | { |
6634 | others--; | |
6635 | printf_filtered ("%d", b->number); | |
6636 | if (b->thread == -1 && thread != -1) | |
6637 | printf_filtered (" (all threads)"); | |
6638 | else if (b->thread != -1) | |
6639 | printf_filtered (" (thread %d)", b->thread); | |
6640 | printf_filtered ("%s%s ", | |
059fb39f | 6641 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6642 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6643 | ? " (disabled)" |
6644 | : b->enable_state == bp_permanent | |
6645 | ? " (permanent)" | |
6646 | : ""), | |
6647 | (others > 1) ? "," | |
6648 | : ((others == 1) ? " and" : "")); | |
6649 | } | |
a3f17187 | 6650 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6651 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6652 | printf_filtered (".\n"); |
6653 | } | |
6654 | } | |
6655 | \f | |
c906108c | 6656 | |
e4f237da KB |
6657 | /* Return true iff it is meaningful to use the address member of |
6658 | BPT. For some breakpoint types, the address member is irrelevant | |
6659 | and it makes no sense to attempt to compare it to other addresses | |
6660 | (or use it for any other purpose either). | |
6661 | ||
4a64f543 MS |
6662 | More specifically, each of the following breakpoint types will |
6663 | always have a zero valued address and we don't want to mark | |
6664 | breakpoints of any of these types to be a duplicate of an actual | |
6665 | breakpoint at address zero: | |
e4f237da KB |
6666 | |
6667 | bp_watchpoint | |
2d134ed3 PA |
6668 | bp_catchpoint |
6669 | ||
6670 | */ | |
e4f237da KB |
6671 | |
6672 | static int | |
6673 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6674 | { | |
6675 | enum bptype type = bpt->type; | |
6676 | ||
2d134ed3 PA |
6677 | return (type != bp_watchpoint && type != bp_catchpoint); |
6678 | } | |
6679 | ||
6680 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6681 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6682 | ||
6683 | static int | |
4a64f543 MS |
6684 | watchpoint_locations_match (struct bp_location *loc1, |
6685 | struct bp_location *loc2) | |
2d134ed3 | 6686 | { |
3a5c3e22 PA |
6687 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6688 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6689 | ||
6690 | /* Both of them must exist. */ | |
6691 | gdb_assert (w1 != NULL); | |
6692 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6693 | |
4a64f543 MS |
6694 | /* If the target can evaluate the condition expression in hardware, |
6695 | then we we need to insert both watchpoints even if they are at | |
6696 | the same place. Otherwise the watchpoint will only trigger when | |
6697 | the condition of whichever watchpoint was inserted evaluates to | |
6698 | true, not giving a chance for GDB to check the condition of the | |
6699 | other watchpoint. */ | |
3a5c3e22 | 6700 | if ((w1->cond_exp |
4a64f543 MS |
6701 | && target_can_accel_watchpoint_condition (loc1->address, |
6702 | loc1->length, | |
0cf6dd15 | 6703 | loc1->watchpoint_type, |
3a5c3e22 PA |
6704 | w1->cond_exp)) |
6705 | || (w2->cond_exp | |
4a64f543 MS |
6706 | && target_can_accel_watchpoint_condition (loc2->address, |
6707 | loc2->length, | |
0cf6dd15 | 6708 | loc2->watchpoint_type, |
3a5c3e22 | 6709 | w2->cond_exp))) |
0cf6dd15 TJB |
6710 | return 0; |
6711 | ||
85d721b8 PA |
6712 | /* Note that this checks the owner's type, not the location's. In |
6713 | case the target does not support read watchpoints, but does | |
6714 | support access watchpoints, we'll have bp_read_watchpoint | |
6715 | watchpoints with hw_access locations. Those should be considered | |
6716 | duplicates of hw_read locations. The hw_read locations will | |
6717 | become hw_access locations later. */ | |
2d134ed3 PA |
6718 | return (loc1->owner->type == loc2->owner->type |
6719 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6720 | && loc1->address == loc2->address | |
6721 | && loc1->length == loc2->length); | |
e4f237da KB |
6722 | } |
6723 | ||
6c95b8df PA |
6724 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6725 | same breakpoint location. In most targets, this can only be true | |
6726 | if ASPACE1 matches ASPACE2. On targets that have global | |
6727 | breakpoints, the address space doesn't really matter. */ | |
6728 | ||
6729 | static int | |
6730 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6731 | struct address_space *aspace2, CORE_ADDR addr2) | |
6732 | { | |
f5656ead | 6733 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6734 | || aspace1 == aspace2) |
6735 | && addr1 == addr2); | |
6736 | } | |
6737 | ||
f1310107 TJB |
6738 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6739 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6740 | matches ASPACE2. On targets that have global breakpoints, the address | |
6741 | space doesn't really matter. */ | |
6742 | ||
6743 | static int | |
6744 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6745 | int len1, struct address_space *aspace2, | |
6746 | CORE_ADDR addr2) | |
6747 | { | |
f5656ead | 6748 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6749 | || aspace1 == aspace2) |
6750 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6751 | } | |
6752 | ||
6753 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6754 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6755 | matches the breakpoint's address space. On targets that have global | |
6756 | breakpoints, the address space doesn't really matter. */ | |
6757 | ||
6758 | static int | |
6759 | breakpoint_location_address_match (struct bp_location *bl, | |
6760 | struct address_space *aspace, | |
6761 | CORE_ADDR addr) | |
6762 | { | |
6763 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6764 | aspace, addr) | |
6765 | || (bl->length | |
6766 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6767 | bl->address, bl->length, | |
6768 | aspace, addr))); | |
6769 | } | |
6770 | ||
1e4d1764 YQ |
6771 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6772 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6773 | true, otherwise returns false. */ | |
6774 | ||
6775 | static int | |
6776 | tracepoint_locations_match (struct bp_location *loc1, | |
6777 | struct bp_location *loc2) | |
6778 | { | |
6779 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6780 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6781 | locations at the same address of different tracepoints are regarded as | |
6782 | different locations. */ | |
6783 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6784 | else | |
6785 | return 0; | |
6786 | } | |
6787 | ||
2d134ed3 PA |
6788 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6789 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6790 | represent the same location. */ | |
6791 | ||
6792 | static int | |
4a64f543 MS |
6793 | breakpoint_locations_match (struct bp_location *loc1, |
6794 | struct bp_location *loc2) | |
2d134ed3 | 6795 | { |
2bdf28a0 JK |
6796 | int hw_point1, hw_point2; |
6797 | ||
6798 | /* Both of them must not be in moribund_locations. */ | |
6799 | gdb_assert (loc1->owner != NULL); | |
6800 | gdb_assert (loc2->owner != NULL); | |
6801 | ||
6802 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6803 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6804 | |
6805 | if (hw_point1 != hw_point2) | |
6806 | return 0; | |
6807 | else if (hw_point1) | |
6808 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6809 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6810 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6811 | else |
f1310107 TJB |
6812 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6813 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6814 | loc2->pspace->aspace, loc2->address) | |
6815 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6816 | } |
6817 | ||
76897487 KB |
6818 | static void |
6819 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6820 | int bnum, int have_bnum) | |
6821 | { | |
f63fbe86 MS |
6822 | /* The longest string possibly returned by hex_string_custom |
6823 | is 50 chars. These must be at least that big for safety. */ | |
6824 | char astr1[64]; | |
6825 | char astr2[64]; | |
76897487 | 6826 | |
bb599908 PH |
6827 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6828 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6829 | if (have_bnum) |
8a3fe4f8 | 6830 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6831 | bnum, astr1, astr2); |
6832 | else | |
8a3fe4f8 | 6833 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6834 | } |
6835 | ||
4a64f543 MS |
6836 | /* Adjust a breakpoint's address to account for architectural |
6837 | constraints on breakpoint placement. Return the adjusted address. | |
6838 | Note: Very few targets require this kind of adjustment. For most | |
6839 | targets, this function is simply the identity function. */ | |
76897487 KB |
6840 | |
6841 | static CORE_ADDR | |
a6d9a66e UW |
6842 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6843 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6844 | { |
a6d9a66e | 6845 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6846 | { |
6847 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6848 | return bpaddr; | |
6849 | } | |
88f7da05 KB |
6850 | else if (bptype == bp_watchpoint |
6851 | || bptype == bp_hardware_watchpoint | |
6852 | || bptype == bp_read_watchpoint | |
6853 | || bptype == bp_access_watchpoint | |
fe798b75 | 6854 | || bptype == bp_catchpoint) |
88f7da05 KB |
6855 | { |
6856 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6857 | have their addresses modified. */ | |
6858 | return bpaddr; | |
6859 | } | |
76897487 KB |
6860 | else |
6861 | { | |
6862 | CORE_ADDR adjusted_bpaddr; | |
6863 | ||
6864 | /* Some targets have architectural constraints on the placement | |
6865 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6866 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6867 | |
6868 | /* An adjusted breakpoint address can significantly alter | |
6869 | a user's expectations. Print a warning if an adjustment | |
6870 | is required. */ | |
6871 | if (adjusted_bpaddr != bpaddr) | |
6872 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6873 | ||
6874 | return adjusted_bpaddr; | |
6875 | } | |
6876 | } | |
6877 | ||
28010a5d PA |
6878 | void |
6879 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6880 | struct breakpoint *owner) | |
7cc221ef | 6881 | { |
7cc221ef DJ |
6882 | memset (loc, 0, sizeof (*loc)); |
6883 | ||
348d480f PA |
6884 | gdb_assert (ops != NULL); |
6885 | ||
28010a5d PA |
6886 | loc->ops = ops; |
6887 | loc->owner = owner; | |
511a6cd4 | 6888 | loc->cond = NULL; |
b775012e | 6889 | loc->cond_bytecode = NULL; |
0d381245 VP |
6890 | loc->shlib_disabled = 0; |
6891 | loc->enabled = 1; | |
e049a4b5 | 6892 | |
28010a5d | 6893 | switch (owner->type) |
e049a4b5 DJ |
6894 | { |
6895 | case bp_breakpoint: | |
6896 | case bp_until: | |
6897 | case bp_finish: | |
6898 | case bp_longjmp: | |
6899 | case bp_longjmp_resume: | |
e2e4d78b | 6900 | case bp_longjmp_call_dummy: |
186c406b TT |
6901 | case bp_exception: |
6902 | case bp_exception_resume: | |
e049a4b5 | 6903 | case bp_step_resume: |
2c03e5be | 6904 | case bp_hp_step_resume: |
e049a4b5 DJ |
6905 | case bp_watchpoint_scope: |
6906 | case bp_call_dummy: | |
aa7d318d | 6907 | case bp_std_terminate: |
e049a4b5 DJ |
6908 | case bp_shlib_event: |
6909 | case bp_thread_event: | |
6910 | case bp_overlay_event: | |
4efc6507 | 6911 | case bp_jit_event: |
0fd8e87f | 6912 | case bp_longjmp_master: |
aa7d318d | 6913 | case bp_std_terminate_master: |
186c406b | 6914 | case bp_exception_master: |
0e30163f JK |
6915 | case bp_gnu_ifunc_resolver: |
6916 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6917 | case bp_dprintf: |
e049a4b5 | 6918 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6919 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6920 | break; |
6921 | case bp_hardware_breakpoint: | |
6922 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6923 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6924 | break; |
6925 | case bp_hardware_watchpoint: | |
6926 | case bp_read_watchpoint: | |
6927 | case bp_access_watchpoint: | |
6928 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6929 | break; | |
6930 | case bp_watchpoint: | |
ce78b96d | 6931 | case bp_catchpoint: |
15c3d785 PA |
6932 | case bp_tracepoint: |
6933 | case bp_fast_tracepoint: | |
0fb4aa4b | 6934 | case bp_static_tracepoint: |
e049a4b5 DJ |
6935 | loc->loc_type = bp_loc_other; |
6936 | break; | |
6937 | default: | |
e2e0b3e5 | 6938 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6939 | } |
6940 | ||
f431efe5 | 6941 | loc->refc = 1; |
28010a5d PA |
6942 | } |
6943 | ||
6944 | /* Allocate a struct bp_location. */ | |
6945 | ||
6946 | static struct bp_location * | |
6947 | allocate_bp_location (struct breakpoint *bpt) | |
6948 | { | |
348d480f PA |
6949 | return bpt->ops->allocate_location (bpt); |
6950 | } | |
7cc221ef | 6951 | |
f431efe5 PA |
6952 | static void |
6953 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6954 | { |
348d480f | 6955 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6956 | xfree (loc); |
6957 | } | |
6958 | ||
f431efe5 PA |
6959 | /* Increment reference count. */ |
6960 | ||
6961 | static void | |
6962 | incref_bp_location (struct bp_location *bl) | |
6963 | { | |
6964 | ++bl->refc; | |
6965 | } | |
6966 | ||
6967 | /* Decrement reference count. If the reference count reaches 0, | |
6968 | destroy the bp_location. Sets *BLP to NULL. */ | |
6969 | ||
6970 | static void | |
6971 | decref_bp_location (struct bp_location **blp) | |
6972 | { | |
0807b50c PA |
6973 | gdb_assert ((*blp)->refc > 0); |
6974 | ||
f431efe5 PA |
6975 | if (--(*blp)->refc == 0) |
6976 | free_bp_location (*blp); | |
6977 | *blp = NULL; | |
6978 | } | |
6979 | ||
346774a9 | 6980 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6981 | |
346774a9 PA |
6982 | static void |
6983 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6984 | { |
346774a9 | 6985 | struct breakpoint *b1; |
c906108c | 6986 | |
346774a9 PA |
6987 | /* Add this breakpoint to the end of the chain so that a list of |
6988 | breakpoints will come out in order of increasing numbers. */ | |
6989 | ||
6990 | b1 = breakpoint_chain; | |
6991 | if (b1 == 0) | |
6992 | breakpoint_chain = b; | |
6993 | else | |
6994 | { | |
6995 | while (b1->next) | |
6996 | b1 = b1->next; | |
6997 | b1->next = b; | |
6998 | } | |
6999 | } | |
7000 | ||
7001 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7002 | ||
7003 | static void | |
7004 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7005 | struct gdbarch *gdbarch, | |
28010a5d | 7006 | enum bptype bptype, |
c0a91b2b | 7007 | const struct breakpoint_ops *ops) |
346774a9 | 7008 | { |
c906108c | 7009 | memset (b, 0, sizeof (*b)); |
2219d63c | 7010 | |
348d480f PA |
7011 | gdb_assert (ops != NULL); |
7012 | ||
28010a5d | 7013 | b->ops = ops; |
4d28f7a8 | 7014 | b->type = bptype; |
a6d9a66e | 7015 | b->gdbarch = gdbarch; |
c906108c SS |
7016 | b->language = current_language->la_language; |
7017 | b->input_radix = input_radix; | |
7018 | b->thread = -1; | |
b5de0fa7 | 7019 | b->enable_state = bp_enabled; |
c906108c SS |
7020 | b->next = 0; |
7021 | b->silent = 0; | |
7022 | b->ignore_count = 0; | |
7023 | b->commands = NULL; | |
818dd999 | 7024 | b->frame_id = null_frame_id; |
0d381245 | 7025 | b->condition_not_parsed = 0; |
84f4c1fe | 7026 | b->py_bp_object = NULL; |
d0fb5eae | 7027 | b->related_breakpoint = b; |
346774a9 PA |
7028 | } |
7029 | ||
7030 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7031 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7032 | |
7033 | static struct breakpoint * | |
7034 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7035 | enum bptype bptype, |
c0a91b2b | 7036 | const struct breakpoint_ops *ops) |
346774a9 PA |
7037 | { |
7038 | struct breakpoint *b = XNEW (struct breakpoint); | |
7039 | ||
348d480f | 7040 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7041 | add_to_breakpoint_chain (b); |
0d381245 VP |
7042 | return b; |
7043 | } | |
7044 | ||
0e30163f JK |
7045 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7046 | resolutions should be made as the user specified the location explicitly | |
7047 | enough. */ | |
7048 | ||
0d381245 | 7049 | static void |
0e30163f | 7050 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7051 | { |
2bdf28a0 JK |
7052 | gdb_assert (loc->owner != NULL); |
7053 | ||
0d381245 | 7054 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7055 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7056 | || is_tracepoint (loc->owner)) |
0d381245 | 7057 | { |
0e30163f | 7058 | int is_gnu_ifunc; |
2c02bd72 | 7059 | const char *function_name; |
6a3a010b | 7060 | CORE_ADDR func_addr; |
0e30163f | 7061 | |
2c02bd72 | 7062 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7063 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7064 | |
7065 | if (is_gnu_ifunc && !explicit_loc) | |
7066 | { | |
7067 | struct breakpoint *b = loc->owner; | |
7068 | ||
7069 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7070 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7071 | &loc->requested_address)) |
7072 | { | |
7073 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7074 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7075 | loc->requested_address, | |
7076 | b->type); | |
7077 | } | |
7078 | else if (b->type == bp_breakpoint && b->loc == loc | |
7079 | && loc->next == NULL && b->related_breakpoint == b) | |
7080 | { | |
7081 | /* Create only the whole new breakpoint of this type but do not | |
7082 | mess more complicated breakpoints with multiple locations. */ | |
7083 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7084 | /* Remember the resolver's address for use by the return |
7085 | breakpoint. */ | |
7086 | loc->related_address = func_addr; | |
0e30163f JK |
7087 | } |
7088 | } | |
7089 | ||
2c02bd72 DE |
7090 | if (function_name) |
7091 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7092 | } |
7093 | } | |
7094 | ||
a6d9a66e | 7095 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7096 | struct gdbarch * |
a6d9a66e UW |
7097 | get_sal_arch (struct symtab_and_line sal) |
7098 | { | |
7099 | if (sal.section) | |
7100 | return get_objfile_arch (sal.section->objfile); | |
7101 | if (sal.symtab) | |
7102 | return get_objfile_arch (sal.symtab->objfile); | |
7103 | ||
7104 | return NULL; | |
7105 | } | |
7106 | ||
346774a9 PA |
7107 | /* Low level routine for partially initializing a breakpoint of type |
7108 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7109 | file name, and line number are provided by SAL. |
0d381245 VP |
7110 | |
7111 | It is expected that the caller will complete the initialization of | |
7112 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7113 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7114 | |
346774a9 PA |
7115 | static void |
7116 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7117 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7118 | const struct breakpoint_ops *ops) |
0d381245 | 7119 | { |
28010a5d | 7120 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7121 | |
3742cc8b | 7122 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7123 | |
6c95b8df PA |
7124 | if (bptype != bp_catchpoint) |
7125 | gdb_assert (sal.pspace != NULL); | |
7126 | ||
f8eba3c6 TT |
7127 | /* Store the program space that was used to set the breakpoint, |
7128 | except for ordinary breakpoints, which are independent of the | |
7129 | program space. */ | |
7130 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7131 | b->pspace = sal.pspace; | |
346774a9 | 7132 | } |
c906108c | 7133 | |
346774a9 PA |
7134 | /* set_raw_breakpoint is a low level routine for allocating and |
7135 | partially initializing a breakpoint of type BPTYPE. The newly | |
7136 | created breakpoint's address, section, source file name, and line | |
7137 | number are provided by SAL. The newly created and partially | |
7138 | initialized breakpoint is added to the breakpoint chain and | |
7139 | is also returned as the value of this function. | |
7140 | ||
7141 | It is expected that the caller will complete the initialization of | |
7142 | the newly created breakpoint struct as well as output any status | |
7143 | information regarding the creation of a new breakpoint. In | |
7144 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7145 | number! Care should be taken to not allow an error to occur | |
7146 | prior to completing the initialization of the breakpoint. If this | |
7147 | should happen, a bogus breakpoint will be left on the chain. */ | |
7148 | ||
7149 | struct breakpoint * | |
7150 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7151 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7152 | const struct breakpoint_ops *ops) |
346774a9 PA |
7153 | { |
7154 | struct breakpoint *b = XNEW (struct breakpoint); | |
7155 | ||
348d480f | 7156 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7157 | add_to_breakpoint_chain (b); |
c906108c SS |
7158 | return b; |
7159 | } | |
7160 | ||
c2c6d25f JM |
7161 | |
7162 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7163 | instruction, hard-wired into the inferior's code. */ | |
7164 | void | |
7165 | make_breakpoint_permanent (struct breakpoint *b) | |
7166 | { | |
0d381245 | 7167 | struct bp_location *bl; |
cc59ec59 | 7168 | |
b5de0fa7 | 7169 | b->enable_state = bp_permanent; |
c2c6d25f | 7170 | |
4a64f543 MS |
7171 | /* By definition, permanent breakpoints are already present in the |
7172 | code. Mark all locations as inserted. For now, | |
7173 | make_breakpoint_permanent is called in just one place, so it's | |
7174 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7175 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7176 | for (bl = b->loc; bl; bl = bl->next) |
7177 | bl->inserted = 1; | |
c2c6d25f JM |
7178 | } |
7179 | ||
53a5351d | 7180 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7181 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7182 | initiated the operation. */ | |
c906108c SS |
7183 | |
7184 | void | |
186c406b | 7185 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7186 | { |
35df4500 | 7187 | struct breakpoint *b, *b_tmp; |
186c406b | 7188 | int thread = tp->num; |
0fd8e87f UW |
7189 | |
7190 | /* To avoid having to rescan all objfile symbols at every step, | |
7191 | we maintain a list of continually-inserted but always disabled | |
7192 | longjmp "master" breakpoints. Here, we simply create momentary | |
7193 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7194 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7195 | if (b->pspace == current_program_space |
186c406b TT |
7196 | && (b->type == bp_longjmp_master |
7197 | || b->type == bp_exception_master)) | |
0fd8e87f | 7198 | { |
06edf0c0 PA |
7199 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7200 | struct breakpoint *clone; | |
cc59ec59 | 7201 | |
e2e4d78b JK |
7202 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7203 | after their removal. */ | |
06edf0c0 | 7204 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7205 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7206 | clone->thread = thread; |
7207 | } | |
186c406b TT |
7208 | |
7209 | tp->initiating_frame = frame; | |
c906108c SS |
7210 | } |
7211 | ||
611c83ae | 7212 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7213 | void |
611c83ae | 7214 | delete_longjmp_breakpoint (int thread) |
c906108c | 7215 | { |
35df4500 | 7216 | struct breakpoint *b, *b_tmp; |
c906108c | 7217 | |
35df4500 | 7218 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7219 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7220 | { |
7221 | if (b->thread == thread) | |
7222 | delete_breakpoint (b); | |
7223 | } | |
c906108c SS |
7224 | } |
7225 | ||
f59f708a PA |
7226 | void |
7227 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7228 | { | |
7229 | struct breakpoint *b, *b_tmp; | |
7230 | ||
7231 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7232 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7233 | { | |
7234 | if (b->thread == thread) | |
7235 | b->disposition = disp_del_at_next_stop; | |
7236 | } | |
7237 | } | |
7238 | ||
e2e4d78b JK |
7239 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7240 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7241 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7242 | breakpoints. */ | |
7243 | ||
7244 | struct breakpoint * | |
7245 | set_longjmp_breakpoint_for_call_dummy (void) | |
7246 | { | |
7247 | struct breakpoint *b, *retval = NULL; | |
7248 | ||
7249 | ALL_BREAKPOINTS (b) | |
7250 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7251 | { | |
7252 | struct breakpoint *new_b; | |
7253 | ||
7254 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7255 | &momentary_breakpoint_ops); | |
7256 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7257 | ||
7258 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7259 | ||
7260 | gdb_assert (new_b->related_breakpoint == new_b); | |
7261 | if (retval == NULL) | |
7262 | retval = new_b; | |
7263 | new_b->related_breakpoint = retval; | |
7264 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7265 | retval = retval->related_breakpoint; | |
7266 | retval->related_breakpoint = new_b; | |
7267 | } | |
7268 | ||
7269 | return retval; | |
7270 | } | |
7271 | ||
7272 | /* Verify all existing dummy frames and their associated breakpoints for | |
7273 | THREAD. Remove those which can no longer be found in the current frame | |
7274 | stack. | |
7275 | ||
7276 | You should call this function only at places where it is safe to currently | |
7277 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7278 | frames. */ | |
7279 | ||
7280 | void | |
7281 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7282 | { | |
7283 | struct breakpoint *b, *b_tmp; | |
7284 | ||
7285 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7286 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7287 | { | |
7288 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7289 | ||
7290 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7291 | dummy_b = dummy_b->related_breakpoint; | |
7292 | if (dummy_b->type != bp_call_dummy | |
7293 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7294 | continue; | |
7295 | ||
7296 | dummy_frame_discard (dummy_b->frame_id); | |
7297 | ||
7298 | while (b->related_breakpoint != b) | |
7299 | { | |
7300 | if (b_tmp == b->related_breakpoint) | |
7301 | b_tmp = b->related_breakpoint->next; | |
7302 | delete_breakpoint (b->related_breakpoint); | |
7303 | } | |
7304 | delete_breakpoint (b); | |
7305 | } | |
7306 | } | |
7307 | ||
1900040c MS |
7308 | void |
7309 | enable_overlay_breakpoints (void) | |
7310 | { | |
52f0bd74 | 7311 | struct breakpoint *b; |
1900040c MS |
7312 | |
7313 | ALL_BREAKPOINTS (b) | |
7314 | if (b->type == bp_overlay_event) | |
7315 | { | |
7316 | b->enable_state = bp_enabled; | |
b60e7edf | 7317 | update_global_location_list (1); |
c02f5703 | 7318 | overlay_events_enabled = 1; |
1900040c MS |
7319 | } |
7320 | } | |
7321 | ||
7322 | void | |
7323 | disable_overlay_breakpoints (void) | |
7324 | { | |
52f0bd74 | 7325 | struct breakpoint *b; |
1900040c MS |
7326 | |
7327 | ALL_BREAKPOINTS (b) | |
7328 | if (b->type == bp_overlay_event) | |
7329 | { | |
7330 | b->enable_state = bp_disabled; | |
b60e7edf | 7331 | update_global_location_list (0); |
c02f5703 | 7332 | overlay_events_enabled = 0; |
1900040c MS |
7333 | } |
7334 | } | |
7335 | ||
aa7d318d TT |
7336 | /* Set an active std::terminate breakpoint for each std::terminate |
7337 | master breakpoint. */ | |
7338 | void | |
7339 | set_std_terminate_breakpoint (void) | |
7340 | { | |
35df4500 | 7341 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7342 | |
35df4500 | 7343 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7344 | if (b->pspace == current_program_space |
7345 | && b->type == bp_std_terminate_master) | |
7346 | { | |
06edf0c0 PA |
7347 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7348 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7349 | } |
7350 | } | |
7351 | ||
7352 | /* Delete all the std::terminate breakpoints. */ | |
7353 | void | |
7354 | delete_std_terminate_breakpoint (void) | |
7355 | { | |
35df4500 | 7356 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7357 | |
35df4500 | 7358 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7359 | if (b->type == bp_std_terminate) |
7360 | delete_breakpoint (b); | |
7361 | } | |
7362 | ||
c4093a6a | 7363 | struct breakpoint * |
a6d9a66e | 7364 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7365 | { |
7366 | struct breakpoint *b; | |
c4093a6a | 7367 | |
06edf0c0 PA |
7368 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7369 | &internal_breakpoint_ops); | |
7370 | ||
b5de0fa7 | 7371 | b->enable_state = bp_enabled; |
c4093a6a | 7372 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7373 | b->addr_string |
7374 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7375 | |
b60e7edf | 7376 | update_global_location_list_nothrow (1); |
74960c60 | 7377 | |
c4093a6a JM |
7378 | return b; |
7379 | } | |
7380 | ||
7381 | void | |
7382 | remove_thread_event_breakpoints (void) | |
7383 | { | |
35df4500 | 7384 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7385 | |
35df4500 | 7386 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7387 | if (b->type == bp_thread_event |
7388 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7389 | delete_breakpoint (b); |
7390 | } | |
7391 | ||
0101ce28 JJ |
7392 | struct lang_and_radix |
7393 | { | |
7394 | enum language lang; | |
7395 | int radix; | |
7396 | }; | |
7397 | ||
4efc6507 DE |
7398 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7399 | ||
7400 | struct breakpoint * | |
7401 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7402 | { | |
7403 | struct breakpoint *b; | |
7404 | ||
06edf0c0 PA |
7405 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7406 | &internal_breakpoint_ops); | |
4efc6507 DE |
7407 | update_global_location_list_nothrow (1); |
7408 | return b; | |
7409 | } | |
0101ce28 | 7410 | |
03673fc7 PP |
7411 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7412 | ||
7413 | void | |
7414 | remove_jit_event_breakpoints (void) | |
7415 | { | |
7416 | struct breakpoint *b, *b_tmp; | |
7417 | ||
7418 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7419 | if (b->type == bp_jit_event | |
7420 | && b->loc->pspace == current_program_space) | |
7421 | delete_breakpoint (b); | |
7422 | } | |
7423 | ||
cae688ec JJ |
7424 | void |
7425 | remove_solib_event_breakpoints (void) | |
7426 | { | |
35df4500 | 7427 | struct breakpoint *b, *b_tmp; |
cae688ec | 7428 | |
35df4500 | 7429 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7430 | if (b->type == bp_shlib_event |
7431 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7432 | delete_breakpoint (b); |
7433 | } | |
7434 | ||
7435 | struct breakpoint * | |
a6d9a66e | 7436 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7437 | { |
7438 | struct breakpoint *b; | |
7439 | ||
06edf0c0 PA |
7440 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7441 | &internal_breakpoint_ops); | |
b60e7edf | 7442 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7443 | return b; |
7444 | } | |
7445 | ||
7446 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7447 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7448 | ||
7449 | void | |
cb851954 | 7450 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7451 | { |
876fa593 | 7452 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7453 | |
876fa593 | 7454 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7455 | { |
2bdf28a0 | 7456 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7457 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7458 | |
4a64f543 MS |
7459 | /* We apply the check to all breakpoints, including disabled for |
7460 | those with loc->duplicate set. This is so that when breakpoint | |
7461 | becomes enabled, or the duplicate is removed, gdb will try to | |
7462 | insert all breakpoints. If we don't set shlib_disabled here, | |
7463 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7464 | if (((b->type == bp_breakpoint) |
508ccb1f | 7465 | || (b->type == bp_jit_event) |
1042e4c0 | 7466 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7467 | || (is_tracepoint (b))) |
6c95b8df | 7468 | && loc->pspace == current_program_space |
0d381245 | 7469 | && !loc->shlib_disabled |
6c95b8df | 7470 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7471 | ) |
0d381245 VP |
7472 | { |
7473 | loc->shlib_disabled = 1; | |
7474 | } | |
cae688ec JJ |
7475 | } |
7476 | } | |
7477 | ||
63644780 NB |
7478 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7479 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7480 | disabled ones can just stay disabled. */ | |
84acb35a | 7481 | |
75149521 | 7482 | static void |
84acb35a JJ |
7483 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7484 | { | |
876fa593 | 7485 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7486 | int disabled_shlib_breaks = 0; |
7487 | ||
c86cf029 VP |
7488 | /* SunOS a.out shared libraries are always mapped, so do not |
7489 | disable breakpoints; they will only be reported as unloaded | |
7490 | through clear_solib when GDB discards its shared library | |
7491 | list. See clear_solib for more information. */ | |
7492 | if (exec_bfd != NULL | |
7493 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7494 | return; | |
7495 | ||
876fa593 | 7496 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7497 | { |
2bdf28a0 | 7498 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7499 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7500 | |
1e4d1764 | 7501 | if (solib->pspace == loc->pspace |
e2dd7057 | 7502 | && !loc->shlib_disabled |
1e4d1764 YQ |
7503 | && (((b->type == bp_breakpoint |
7504 | || b->type == bp_jit_event | |
7505 | || b->type == bp_hardware_breakpoint) | |
7506 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7507 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7508 | || is_tracepoint (b)) | |
e2dd7057 | 7509 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7510 | { |
e2dd7057 PP |
7511 | loc->shlib_disabled = 1; |
7512 | /* At this point, we cannot rely on remove_breakpoint | |
7513 | succeeding so we must mark the breakpoint as not inserted | |
7514 | to prevent future errors occurring in remove_breakpoints. */ | |
7515 | loc->inserted = 0; | |
8d3788bd VP |
7516 | |
7517 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7518 | observer_notify_breakpoint_modified (b); | |
7519 | ||
e2dd7057 PP |
7520 | if (!disabled_shlib_breaks) |
7521 | { | |
7522 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7523 | warning (_("Temporarily disabling breakpoints " |
7524 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7525 | solib->so_name); |
84acb35a | 7526 | } |
e2dd7057 | 7527 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7528 | } |
7529 | } | |
84acb35a JJ |
7530 | } |
7531 | ||
63644780 NB |
7532 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7533 | notification of free_objfile. Only apply to enabled breakpoints, | |
7534 | disabled ones can just stay disabled. */ | |
7535 | ||
7536 | static void | |
7537 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7538 | { | |
7539 | struct breakpoint *b; | |
7540 | ||
7541 | if (objfile == NULL) | |
7542 | return; | |
7543 | ||
7544 | /* If the file is a shared library not loaded by the user then | |
7545 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7546 | was called. In that case there is no need to take action again. */ | |
7547 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7548 | return; | |
7549 | ||
7550 | ALL_BREAKPOINTS (b) | |
7551 | { | |
7552 | struct bp_location *loc; | |
7553 | int bp_modified = 0; | |
7554 | ||
7555 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7556 | continue; | |
7557 | ||
7558 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7559 | { | |
7560 | CORE_ADDR loc_addr = loc->address; | |
7561 | ||
7562 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7563 | && loc->loc_type != bp_loc_software_breakpoint) | |
7564 | continue; | |
7565 | ||
7566 | if (loc->shlib_disabled != 0) | |
7567 | continue; | |
7568 | ||
7569 | if (objfile->pspace != loc->pspace) | |
7570 | continue; | |
7571 | ||
7572 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7573 | && loc->loc_type != bp_loc_software_breakpoint) | |
7574 | continue; | |
7575 | ||
7576 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7577 | { | |
7578 | loc->shlib_disabled = 1; | |
7579 | loc->inserted = 0; | |
7580 | ||
7581 | mark_breakpoint_location_modified (loc); | |
7582 | ||
7583 | bp_modified = 1; | |
7584 | } | |
7585 | } | |
7586 | ||
7587 | if (bp_modified) | |
7588 | observer_notify_breakpoint_modified (b); | |
7589 | } | |
7590 | } | |
7591 | ||
ce78b96d JB |
7592 | /* FORK & VFORK catchpoints. */ |
7593 | ||
e29a4733 PA |
7594 | /* An instance of this type is used to represent a fork or vfork |
7595 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7596 | class; users downcast to "struct breakpoint *" when needed. A | |
7597 | breakpoint is really of this type iff its ops pointer points to | |
7598 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7599 | ||
7600 | struct fork_catchpoint | |
7601 | { | |
7602 | /* The base class. */ | |
7603 | struct breakpoint base; | |
7604 | ||
7605 | /* Process id of a child process whose forking triggered this | |
7606 | catchpoint. This field is only valid immediately after this | |
7607 | catchpoint has triggered. */ | |
7608 | ptid_t forked_inferior_pid; | |
7609 | }; | |
7610 | ||
4a64f543 MS |
7611 | /* Implement the "insert" breakpoint_ops method for fork |
7612 | catchpoints. */ | |
ce78b96d | 7613 | |
77b06cd7 TJB |
7614 | static int |
7615 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7616 | { |
dfd4cc63 | 7617 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7618 | } |
7619 | ||
4a64f543 MS |
7620 | /* Implement the "remove" breakpoint_ops method for fork |
7621 | catchpoints. */ | |
ce78b96d JB |
7622 | |
7623 | static int | |
77b06cd7 | 7624 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7625 | { |
dfd4cc63 | 7626 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7627 | } |
7628 | ||
7629 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7630 | catchpoints. */ | |
7631 | ||
7632 | static int | |
f1310107 | 7633 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7634 | struct address_space *aspace, CORE_ADDR bp_addr, |
7635 | const struct target_waitstatus *ws) | |
ce78b96d | 7636 | { |
e29a4733 PA |
7637 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7638 | ||
f90263c1 TT |
7639 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7640 | return 0; | |
7641 | ||
7642 | c->forked_inferior_pid = ws->value.related_pid; | |
7643 | return 1; | |
ce78b96d JB |
7644 | } |
7645 | ||
4a64f543 MS |
7646 | /* Implement the "print_it" breakpoint_ops method for fork |
7647 | catchpoints. */ | |
ce78b96d JB |
7648 | |
7649 | static enum print_stop_action | |
348d480f | 7650 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7651 | { |
36dfb11c | 7652 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7653 | struct breakpoint *b = bs->breakpoint_at; |
7654 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7655 | |
ce78b96d | 7656 | annotate_catchpoint (b->number); |
36dfb11c TT |
7657 | if (b->disposition == disp_del) |
7658 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7659 | else | |
7660 | ui_out_text (uiout, "\nCatchpoint "); | |
7661 | if (ui_out_is_mi_like_p (uiout)) | |
7662 | { | |
7663 | ui_out_field_string (uiout, "reason", | |
7664 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7665 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7666 | } | |
7667 | ui_out_field_int (uiout, "bkptno", b->number); | |
7668 | ui_out_text (uiout, " (forked process "); | |
7669 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7670 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7671 | return PRINT_SRC_AND_LOC; |
7672 | } | |
7673 | ||
4a64f543 MS |
7674 | /* Implement the "print_one" breakpoint_ops method for fork |
7675 | catchpoints. */ | |
ce78b96d JB |
7676 | |
7677 | static void | |
a6d9a66e | 7678 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7679 | { |
e29a4733 | 7680 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7681 | struct value_print_options opts; |
79a45e25 | 7682 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7683 | |
7684 | get_user_print_options (&opts); | |
7685 | ||
4a64f543 MS |
7686 | /* Field 4, the address, is omitted (which makes the columns not |
7687 | line up too nicely with the headers, but the effect is relatively | |
7688 | readable). */ | |
79a45b7d | 7689 | if (opts.addressprint) |
ce78b96d JB |
7690 | ui_out_field_skip (uiout, "addr"); |
7691 | annotate_field (5); | |
7692 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7693 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7694 | { |
7695 | ui_out_text (uiout, ", process "); | |
7696 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7697 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7698 | ui_out_spaces (uiout, 1); |
7699 | } | |
8ac3646f TT |
7700 | |
7701 | if (ui_out_is_mi_like_p (uiout)) | |
7702 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7703 | } |
7704 | ||
7705 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7706 | catchpoints. */ | |
7707 | ||
7708 | static void | |
7709 | print_mention_catch_fork (struct breakpoint *b) | |
7710 | { | |
7711 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7712 | } | |
7713 | ||
6149aea9 PA |
7714 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7715 | catchpoints. */ | |
7716 | ||
7717 | static void | |
7718 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7719 | { | |
7720 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7721 | print_recreate_thread (b, fp); |
6149aea9 PA |
7722 | } |
7723 | ||
ce78b96d JB |
7724 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7725 | ||
2060206e | 7726 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7727 | |
4a64f543 MS |
7728 | /* Implement the "insert" breakpoint_ops method for vfork |
7729 | catchpoints. */ | |
ce78b96d | 7730 | |
77b06cd7 TJB |
7731 | static int |
7732 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7733 | { |
dfd4cc63 | 7734 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7735 | } |
7736 | ||
4a64f543 MS |
7737 | /* Implement the "remove" breakpoint_ops method for vfork |
7738 | catchpoints. */ | |
ce78b96d JB |
7739 | |
7740 | static int | |
77b06cd7 | 7741 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7742 | { |
dfd4cc63 | 7743 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7744 | } |
7745 | ||
7746 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7747 | catchpoints. */ | |
7748 | ||
7749 | static int | |
f1310107 | 7750 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7751 | struct address_space *aspace, CORE_ADDR bp_addr, |
7752 | const struct target_waitstatus *ws) | |
ce78b96d | 7753 | { |
e29a4733 PA |
7754 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7755 | ||
f90263c1 TT |
7756 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7757 | return 0; | |
7758 | ||
7759 | c->forked_inferior_pid = ws->value.related_pid; | |
7760 | return 1; | |
ce78b96d JB |
7761 | } |
7762 | ||
4a64f543 MS |
7763 | /* Implement the "print_it" breakpoint_ops method for vfork |
7764 | catchpoints. */ | |
ce78b96d JB |
7765 | |
7766 | static enum print_stop_action | |
348d480f | 7767 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7768 | { |
36dfb11c | 7769 | struct ui_out *uiout = current_uiout; |
348d480f | 7770 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7771 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7772 | ||
ce78b96d | 7773 | annotate_catchpoint (b->number); |
36dfb11c TT |
7774 | if (b->disposition == disp_del) |
7775 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7776 | else | |
7777 | ui_out_text (uiout, "\nCatchpoint "); | |
7778 | if (ui_out_is_mi_like_p (uiout)) | |
7779 | { | |
7780 | ui_out_field_string (uiout, "reason", | |
7781 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7782 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7783 | } | |
7784 | ui_out_field_int (uiout, "bkptno", b->number); | |
7785 | ui_out_text (uiout, " (vforked process "); | |
7786 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7787 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7788 | return PRINT_SRC_AND_LOC; |
7789 | } | |
7790 | ||
4a64f543 MS |
7791 | /* Implement the "print_one" breakpoint_ops method for vfork |
7792 | catchpoints. */ | |
ce78b96d JB |
7793 | |
7794 | static void | |
a6d9a66e | 7795 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7796 | { |
e29a4733 | 7797 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7798 | struct value_print_options opts; |
79a45e25 | 7799 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7800 | |
7801 | get_user_print_options (&opts); | |
4a64f543 MS |
7802 | /* Field 4, the address, is omitted (which makes the columns not |
7803 | line up too nicely with the headers, but the effect is relatively | |
7804 | readable). */ | |
79a45b7d | 7805 | if (opts.addressprint) |
ce78b96d JB |
7806 | ui_out_field_skip (uiout, "addr"); |
7807 | annotate_field (5); | |
7808 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7809 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7810 | { |
7811 | ui_out_text (uiout, ", process "); | |
7812 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7813 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7814 | ui_out_spaces (uiout, 1); |
7815 | } | |
8ac3646f TT |
7816 | |
7817 | if (ui_out_is_mi_like_p (uiout)) | |
7818 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7819 | } |
7820 | ||
7821 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7822 | catchpoints. */ | |
7823 | ||
7824 | static void | |
7825 | print_mention_catch_vfork (struct breakpoint *b) | |
7826 | { | |
7827 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7828 | } | |
7829 | ||
6149aea9 PA |
7830 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7831 | catchpoints. */ | |
7832 | ||
7833 | static void | |
7834 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7835 | { | |
7836 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7837 | print_recreate_thread (b, fp); |
6149aea9 PA |
7838 | } |
7839 | ||
ce78b96d JB |
7840 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7841 | ||
2060206e | 7842 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7843 | |
edcc5120 TT |
7844 | /* An instance of this type is used to represent an solib catchpoint. |
7845 | It includes a "struct breakpoint" as a kind of base class; users | |
7846 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7847 | really of this type iff its ops pointer points to | |
7848 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7849 | ||
7850 | struct solib_catchpoint | |
7851 | { | |
7852 | /* The base class. */ | |
7853 | struct breakpoint base; | |
7854 | ||
7855 | /* True for "catch load", false for "catch unload". */ | |
7856 | unsigned char is_load; | |
7857 | ||
7858 | /* Regular expression to match, if any. COMPILED is only valid when | |
7859 | REGEX is non-NULL. */ | |
7860 | char *regex; | |
7861 | regex_t compiled; | |
7862 | }; | |
7863 | ||
7864 | static void | |
7865 | dtor_catch_solib (struct breakpoint *b) | |
7866 | { | |
7867 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7868 | ||
7869 | if (self->regex) | |
7870 | regfree (&self->compiled); | |
7871 | xfree (self->regex); | |
7872 | ||
7873 | base_breakpoint_ops.dtor (b); | |
7874 | } | |
7875 | ||
7876 | static int | |
7877 | insert_catch_solib (struct bp_location *ignore) | |
7878 | { | |
7879 | return 0; | |
7880 | } | |
7881 | ||
7882 | static int | |
7883 | remove_catch_solib (struct bp_location *ignore) | |
7884 | { | |
7885 | return 0; | |
7886 | } | |
7887 | ||
7888 | static int | |
7889 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7890 | struct address_space *aspace, | |
7891 | CORE_ADDR bp_addr, | |
7892 | const struct target_waitstatus *ws) | |
7893 | { | |
7894 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7895 | struct breakpoint *other; | |
7896 | ||
7897 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7898 | return 1; | |
7899 | ||
7900 | ALL_BREAKPOINTS (other) | |
7901 | { | |
7902 | struct bp_location *other_bl; | |
7903 | ||
7904 | if (other == bl->owner) | |
7905 | continue; | |
7906 | ||
7907 | if (other->type != bp_shlib_event) | |
7908 | continue; | |
7909 | ||
7910 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7911 | continue; | |
7912 | ||
7913 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7914 | { | |
7915 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7916 | return 1; | |
7917 | } | |
7918 | } | |
7919 | ||
7920 | return 0; | |
7921 | } | |
7922 | ||
7923 | static void | |
7924 | check_status_catch_solib (struct bpstats *bs) | |
7925 | { | |
7926 | struct solib_catchpoint *self | |
7927 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7928 | int ix; | |
7929 | ||
7930 | if (self->is_load) | |
7931 | { | |
7932 | struct so_list *iter; | |
7933 | ||
7934 | for (ix = 0; | |
7935 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7936 | ix, iter); | |
7937 | ++ix) | |
7938 | { | |
7939 | if (!self->regex | |
7940 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7941 | return; | |
7942 | } | |
7943 | } | |
7944 | else | |
7945 | { | |
7946 | char *iter; | |
7947 | ||
7948 | for (ix = 0; | |
7949 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7950 | ix, iter); | |
7951 | ++ix) | |
7952 | { | |
7953 | if (!self->regex | |
7954 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7955 | return; | |
7956 | } | |
7957 | } | |
7958 | ||
7959 | bs->stop = 0; | |
7960 | bs->print_it = print_it_noop; | |
7961 | } | |
7962 | ||
7963 | static enum print_stop_action | |
7964 | print_it_catch_solib (bpstat bs) | |
7965 | { | |
7966 | struct breakpoint *b = bs->breakpoint_at; | |
7967 | struct ui_out *uiout = current_uiout; | |
7968 | ||
7969 | annotate_catchpoint (b->number); | |
7970 | if (b->disposition == disp_del) | |
7971 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7972 | else | |
7973 | ui_out_text (uiout, "\nCatchpoint "); | |
7974 | ui_out_field_int (uiout, "bkptno", b->number); | |
7975 | ui_out_text (uiout, "\n"); | |
7976 | if (ui_out_is_mi_like_p (uiout)) | |
7977 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7978 | print_solib_event (1); | |
7979 | return PRINT_SRC_AND_LOC; | |
7980 | } | |
7981 | ||
7982 | static void | |
7983 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7984 | { | |
7985 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7986 | struct value_print_options opts; | |
7987 | struct ui_out *uiout = current_uiout; | |
7988 | char *msg; | |
7989 | ||
7990 | get_user_print_options (&opts); | |
7991 | /* Field 4, the address, is omitted (which makes the columns not | |
7992 | line up too nicely with the headers, but the effect is relatively | |
7993 | readable). */ | |
7994 | if (opts.addressprint) | |
7995 | { | |
7996 | annotate_field (4); | |
7997 | ui_out_field_skip (uiout, "addr"); | |
7998 | } | |
7999 | ||
8000 | annotate_field (5); | |
8001 | if (self->is_load) | |
8002 | { | |
8003 | if (self->regex) | |
8004 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8005 | else | |
8006 | msg = xstrdup (_("load of library")); | |
8007 | } | |
8008 | else | |
8009 | { | |
8010 | if (self->regex) | |
8011 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8012 | else | |
8013 | msg = xstrdup (_("unload of library")); | |
8014 | } | |
8015 | ui_out_field_string (uiout, "what", msg); | |
8016 | xfree (msg); | |
8ac3646f TT |
8017 | |
8018 | if (ui_out_is_mi_like_p (uiout)) | |
8019 | ui_out_field_string (uiout, "catch-type", | |
8020 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8021 | } |
8022 | ||
8023 | static void | |
8024 | print_mention_catch_solib (struct breakpoint *b) | |
8025 | { | |
8026 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8027 | ||
8028 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8029 | self->is_load ? "load" : "unload"); | |
8030 | } | |
8031 | ||
8032 | static void | |
8033 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8034 | { | |
8035 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8036 | ||
8037 | fprintf_unfiltered (fp, "%s %s", | |
8038 | b->disposition == disp_del ? "tcatch" : "catch", | |
8039 | self->is_load ? "load" : "unload"); | |
8040 | if (self->regex) | |
8041 | fprintf_unfiltered (fp, " %s", self->regex); | |
8042 | fprintf_unfiltered (fp, "\n"); | |
8043 | } | |
8044 | ||
8045 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8046 | ||
91985142 MG |
8047 | /* Shared helper function (MI and CLI) for creating and installing |
8048 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8049 | the events to be caught are load events, otherwise they are | |
8050 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8051 | temporary one. If ENABLED is non-zero the catchpoint is | |
8052 | created in an enabled state. */ | |
edcc5120 | 8053 | |
91985142 MG |
8054 | void |
8055 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8056 | { |
8057 | struct solib_catchpoint *c; | |
8058 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8059 | struct cleanup *cleanup; |
8060 | ||
edcc5120 TT |
8061 | if (!arg) |
8062 | arg = ""; | |
8063 | arg = skip_spaces (arg); | |
8064 | ||
8065 | c = XCNEW (struct solib_catchpoint); | |
8066 | cleanup = make_cleanup (xfree, c); | |
8067 | ||
8068 | if (*arg != '\0') | |
8069 | { | |
8070 | int errcode; | |
8071 | ||
8072 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8073 | if (errcode != 0) | |
8074 | { | |
8075 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8076 | ||
8077 | make_cleanup (xfree, err); | |
8078 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8079 | } | |
8080 | c->regex = xstrdup (arg); | |
8081 | } | |
8082 | ||
8083 | c->is_load = is_load; | |
91985142 | 8084 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8085 | &catch_solib_breakpoint_ops); |
8086 | ||
91985142 MG |
8087 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8088 | ||
edcc5120 TT |
8089 | discard_cleanups (cleanup); |
8090 | install_breakpoint (0, &c->base, 1); | |
8091 | } | |
8092 | ||
91985142 MG |
8093 | /* A helper function that does all the work for "catch load" and |
8094 | "catch unload". */ | |
8095 | ||
8096 | static void | |
8097 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8098 | struct cmd_list_element *command) | |
8099 | { | |
8100 | int tempflag; | |
8101 | const int enabled = 1; | |
8102 | ||
8103 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8104 | ||
8105 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8106 | } | |
8107 | ||
edcc5120 TT |
8108 | static void |
8109 | catch_load_command_1 (char *arg, int from_tty, | |
8110 | struct cmd_list_element *command) | |
8111 | { | |
8112 | catch_load_or_unload (arg, from_tty, 1, command); | |
8113 | } | |
8114 | ||
8115 | static void | |
8116 | catch_unload_command_1 (char *arg, int from_tty, | |
8117 | struct cmd_list_element *command) | |
8118 | { | |
8119 | catch_load_or_unload (arg, from_tty, 0, command); | |
8120 | } | |
8121 | ||
be5c67c1 PA |
8122 | /* An instance of this type is used to represent a syscall catchpoint. |
8123 | It includes a "struct breakpoint" as a kind of base class; users | |
8124 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8125 | really of this type iff its ops pointer points to | |
8126 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8127 | ||
8128 | struct syscall_catchpoint | |
8129 | { | |
8130 | /* The base class. */ | |
8131 | struct breakpoint base; | |
8132 | ||
8133 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8134 | syscall has been specified for filtering, its value is NULL. | |
8135 | Otherwise, it holds a list of all syscalls to be caught. The | |
8136 | list elements are allocated with xmalloc. */ | |
8137 | VEC(int) *syscalls_to_be_caught; | |
8138 | }; | |
8139 | ||
8140 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8141 | catchpoints. */ | |
8142 | ||
8143 | static void | |
8144 | dtor_catch_syscall (struct breakpoint *b) | |
8145 | { | |
8146 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8147 | ||
8148 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8149 | |
2060206e | 8150 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8151 | } |
8152 | ||
fa3064dd YQ |
8153 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8154 | ||
8155 | struct catch_syscall_inferior_data | |
8156 | { | |
8157 | /* We keep a count of the number of times the user has requested a | |
8158 | particular syscall to be tracked, and pass this information to the | |
8159 | target. This lets capable targets implement filtering directly. */ | |
8160 | ||
8161 | /* Number of times that "any" syscall is requested. */ | |
8162 | int any_syscall_count; | |
8163 | ||
8164 | /* Count of each system call. */ | |
8165 | VEC(int) *syscalls_counts; | |
8166 | ||
8167 | /* This counts all syscall catch requests, so we can readily determine | |
8168 | if any catching is necessary. */ | |
8169 | int total_syscalls_count; | |
8170 | }; | |
8171 | ||
8172 | static struct catch_syscall_inferior_data* | |
8173 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8174 | { | |
8175 | struct catch_syscall_inferior_data *inf_data; | |
8176 | ||
8177 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8178 | if (inf_data == NULL) | |
8179 | { | |
8180 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
8181 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
8182 | } | |
8183 | ||
8184 | return inf_data; | |
8185 | } | |
8186 | ||
8187 | static void | |
8188 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8189 | { | |
8190 | xfree (arg); | |
8191 | } | |
8192 | ||
8193 | ||
a96d9b2e SDJ |
8194 | /* Implement the "insert" breakpoint_ops method for syscall |
8195 | catchpoints. */ | |
8196 | ||
77b06cd7 TJB |
8197 | static int |
8198 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8199 | { |
be5c67c1 | 8200 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8201 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8202 | struct catch_syscall_inferior_data *inf_data |
8203 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8204 | |
fa3064dd | 8205 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8206 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8207 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8208 | else |
8209 | { | |
8210 | int i, iter; | |
cc59ec59 | 8211 | |
a96d9b2e | 8212 | for (i = 0; |
be5c67c1 | 8213 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8214 | i++) |
8215 | { | |
8216 | int elem; | |
cc59ec59 | 8217 | |
fa3064dd | 8218 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8219 | { |
fa3064dd | 8220 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8221 | uintptr_t vec_addr_offset |
8222 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8223 | uintptr_t vec_addr; |
fa3064dd YQ |
8224 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8225 | vec_addr = ((uintptr_t) VEC_address (int, | |
8226 | inf_data->syscalls_counts) | |
8227 | + vec_addr_offset); | |
a96d9b2e SDJ |
8228 | memset ((void *) vec_addr, 0, |
8229 | (iter + 1 - old_size) * sizeof (int)); | |
8230 | } | |
fa3064dd YQ |
8231 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8232 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8233 | } |
8234 | } | |
8235 | ||
dfd4cc63 | 8236 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8237 | inf_data->total_syscalls_count != 0, |
8238 | inf_data->any_syscall_count, | |
8239 | VEC_length (int, | |
8240 | inf_data->syscalls_counts), | |
8241 | VEC_address (int, | |
8242 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8243 | } |
8244 | ||
8245 | /* Implement the "remove" breakpoint_ops method for syscall | |
8246 | catchpoints. */ | |
8247 | ||
8248 | static int | |
77b06cd7 | 8249 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8250 | { |
be5c67c1 | 8251 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8252 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8253 | struct catch_syscall_inferior_data *inf_data |
8254 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8255 | |
fa3064dd | 8256 | --inf_data->total_syscalls_count; |
be5c67c1 | 8257 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8258 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8259 | else |
8260 | { | |
8261 | int i, iter; | |
cc59ec59 | 8262 | |
a96d9b2e | 8263 | for (i = 0; |
be5c67c1 | 8264 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8265 | i++) |
8266 | { | |
8267 | int elem; | |
fa3064dd | 8268 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8269 | /* Shouldn't happen. */ |
8270 | continue; | |
fa3064dd YQ |
8271 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8272 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8273 | } |
8274 | } | |
8275 | ||
dfd4cc63 | 8276 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8277 | inf_data->total_syscalls_count != 0, |
8278 | inf_data->any_syscall_count, | |
8279 | VEC_length (int, | |
8280 | inf_data->syscalls_counts), | |
3e43a32a | 8281 | VEC_address (int, |
fa3064dd | 8282 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8283 | } |
8284 | ||
8285 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8286 | catchpoints. */ | |
8287 | ||
8288 | static int | |
f1310107 | 8289 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8290 | struct address_space *aspace, CORE_ADDR bp_addr, |
8291 | const struct target_waitstatus *ws) | |
a96d9b2e | 8292 | { |
4a64f543 MS |
8293 | /* We must check if we are catching specific syscalls in this |
8294 | breakpoint. If we are, then we must guarantee that the called | |
8295 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8296 | int syscall_number = 0; |
be5c67c1 PA |
8297 | const struct syscall_catchpoint *c |
8298 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8299 | |
f90263c1 TT |
8300 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8301 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8302 | return 0; |
8303 | ||
f90263c1 TT |
8304 | syscall_number = ws->value.syscall_number; |
8305 | ||
a96d9b2e | 8306 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8307 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8308 | { |
8309 | int i, iter; | |
cc59ec59 | 8310 | |
a96d9b2e | 8311 | for (i = 0; |
be5c67c1 | 8312 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8313 | i++) |
8314 | if (syscall_number == iter) | |
8315 | break; | |
8316 | /* Not the same. */ | |
8317 | if (!iter) | |
8318 | return 0; | |
8319 | } | |
8320 | ||
8321 | return 1; | |
8322 | } | |
8323 | ||
8324 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8325 | catchpoints. */ | |
8326 | ||
8327 | static enum print_stop_action | |
348d480f | 8328 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8329 | { |
36dfb11c | 8330 | struct ui_out *uiout = current_uiout; |
348d480f | 8331 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8332 | /* These are needed because we want to know in which state a |
8333 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8334 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8335 | must print "called syscall" or "returned from syscall". */ | |
8336 | ptid_t ptid; | |
8337 | struct target_waitstatus last; | |
8338 | struct syscall s; | |
a96d9b2e SDJ |
8339 | |
8340 | get_last_target_status (&ptid, &last); | |
8341 | ||
8342 | get_syscall_by_number (last.value.syscall_number, &s); | |
8343 | ||
8344 | annotate_catchpoint (b->number); | |
8345 | ||
36dfb11c TT |
8346 | if (b->disposition == disp_del) |
8347 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8348 | else |
36dfb11c TT |
8349 | ui_out_text (uiout, "\nCatchpoint "); |
8350 | if (ui_out_is_mi_like_p (uiout)) | |
8351 | { | |
8352 | ui_out_field_string (uiout, "reason", | |
8353 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8354 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8355 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8356 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8357 | } | |
8358 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8359 | |
8360 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8361 | ui_out_text (uiout, " (call to syscall "); |
8362 | else | |
8363 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8364 | |
36dfb11c TT |
8365 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8366 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8367 | if (s.name != NULL) | |
8368 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8369 | ||
8370 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8371 | |
8372 | return PRINT_SRC_AND_LOC; | |
8373 | } | |
8374 | ||
8375 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8376 | catchpoints. */ | |
8377 | ||
8378 | static void | |
8379 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8380 | struct bp_location **last_loc) |
a96d9b2e | 8381 | { |
be5c67c1 | 8382 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8383 | struct value_print_options opts; |
79a45e25 | 8384 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8385 | |
8386 | get_user_print_options (&opts); | |
4a64f543 MS |
8387 | /* Field 4, the address, is omitted (which makes the columns not |
8388 | line up too nicely with the headers, but the effect is relatively | |
8389 | readable). */ | |
a96d9b2e SDJ |
8390 | if (opts.addressprint) |
8391 | ui_out_field_skip (uiout, "addr"); | |
8392 | annotate_field (5); | |
8393 | ||
be5c67c1 PA |
8394 | if (c->syscalls_to_be_caught |
8395 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8396 | ui_out_text (uiout, "syscalls \""); |
8397 | else | |
8398 | ui_out_text (uiout, "syscall \""); | |
8399 | ||
be5c67c1 | 8400 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8401 | { |
8402 | int i, iter; | |
8403 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8404 | |
a96d9b2e | 8405 | for (i = 0; |
be5c67c1 | 8406 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8407 | i++) |
8408 | { | |
8409 | char *x = text; | |
8410 | struct syscall s; | |
8411 | get_syscall_by_number (iter, &s); | |
8412 | ||
8413 | if (s.name != NULL) | |
8414 | text = xstrprintf ("%s%s, ", text, s.name); | |
8415 | else | |
8416 | text = xstrprintf ("%s%d, ", text, iter); | |
8417 | ||
8418 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8419 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8420 | on every call. */ |
8421 | xfree (x); | |
8422 | } | |
8423 | /* Remove the last comma. */ | |
8424 | text[strlen (text) - 2] = '\0'; | |
8425 | ui_out_field_string (uiout, "what", text); | |
8426 | } | |
8427 | else | |
8428 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8429 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8430 | |
8431 | if (ui_out_is_mi_like_p (uiout)) | |
8432 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8433 | } |
8434 | ||
8435 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8436 | catchpoints. */ | |
8437 | ||
8438 | static void | |
8439 | print_mention_catch_syscall (struct breakpoint *b) | |
8440 | { | |
be5c67c1 PA |
8441 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8442 | ||
8443 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8444 | { |
8445 | int i, iter; | |
8446 | ||
be5c67c1 | 8447 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8448 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8449 | else | |
8450 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8451 | ||
8452 | for (i = 0; | |
be5c67c1 | 8453 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8454 | i++) |
8455 | { | |
8456 | struct syscall s; | |
8457 | get_syscall_by_number (iter, &s); | |
8458 | ||
8459 | if (s.name) | |
8460 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8461 | else | |
8462 | printf_filtered (" %d", s.number); | |
8463 | } | |
8464 | printf_filtered (")"); | |
8465 | } | |
8466 | else | |
8467 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8468 | b->number); | |
8469 | } | |
8470 | ||
6149aea9 PA |
8471 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8472 | catchpoints. */ | |
8473 | ||
8474 | static void | |
8475 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8476 | { | |
be5c67c1 PA |
8477 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8478 | ||
6149aea9 PA |
8479 | fprintf_unfiltered (fp, "catch syscall"); |
8480 | ||
be5c67c1 | 8481 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8482 | { |
8483 | int i, iter; | |
8484 | ||
8485 | for (i = 0; | |
be5c67c1 | 8486 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8487 | i++) |
8488 | { | |
8489 | struct syscall s; | |
8490 | ||
8491 | get_syscall_by_number (iter, &s); | |
8492 | if (s.name) | |
8493 | fprintf_unfiltered (fp, " %s", s.name); | |
8494 | else | |
8495 | fprintf_unfiltered (fp, " %d", s.number); | |
8496 | } | |
8497 | } | |
d9b3f62e | 8498 | print_recreate_thread (b, fp); |
6149aea9 PA |
8499 | } |
8500 | ||
a96d9b2e SDJ |
8501 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8502 | ||
2060206e | 8503 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8504 | |
8505 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8506 | ||
8507 | static int | |
8508 | syscall_catchpoint_p (struct breakpoint *b) | |
8509 | { | |
8510 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8511 | } | |
8512 | ||
346774a9 PA |
8513 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8514 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8515 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8516 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8517 | |
ab04a2af | 8518 | void |
346774a9 PA |
8519 | init_catchpoint (struct breakpoint *b, |
8520 | struct gdbarch *gdbarch, int tempflag, | |
8521 | char *cond_string, | |
c0a91b2b | 8522 | const struct breakpoint_ops *ops) |
c906108c | 8523 | { |
c5aa993b | 8524 | struct symtab_and_line sal; |
346774a9 | 8525 | |
fe39c653 | 8526 | init_sal (&sal); |
6c95b8df | 8527 | sal.pspace = current_program_space; |
c5aa993b | 8528 | |
28010a5d | 8529 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8530 | |
1b36a34b | 8531 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8532 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8533 | } |
8534 | ||
28010a5d | 8535 | void |
3ea46bff | 8536 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8537 | { |
8538 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8539 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8540 | if (is_tracepoint (b)) |
8541 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8542 | if (!internal) |
8543 | mention (b); | |
c56053d2 | 8544 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8545 | |
8546 | if (update_gll) | |
8547 | update_global_location_list (1); | |
c56053d2 PA |
8548 | } |
8549 | ||
9b70b993 | 8550 | static void |
a6d9a66e UW |
8551 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8552 | int tempflag, char *cond_string, | |
c0a91b2b | 8553 | const struct breakpoint_ops *ops) |
c906108c | 8554 | { |
e29a4733 | 8555 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8556 | |
e29a4733 PA |
8557 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8558 | ||
8559 | c->forked_inferior_pid = null_ptid; | |
8560 | ||
3ea46bff | 8561 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8562 | } |
8563 | ||
fe798b75 JB |
8564 | /* Exec catchpoints. */ |
8565 | ||
b4d90040 PA |
8566 | /* An instance of this type is used to represent an exec catchpoint. |
8567 | It includes a "struct breakpoint" as a kind of base class; users | |
8568 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8569 | really of this type iff its ops pointer points to | |
8570 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8571 | ||
8572 | struct exec_catchpoint | |
8573 | { | |
8574 | /* The base class. */ | |
8575 | struct breakpoint base; | |
8576 | ||
8577 | /* Filename of a program whose exec triggered this catchpoint. | |
8578 | This field is only valid immediately after this catchpoint has | |
8579 | triggered. */ | |
8580 | char *exec_pathname; | |
8581 | }; | |
8582 | ||
8583 | /* Implement the "dtor" breakpoint_ops method for exec | |
8584 | catchpoints. */ | |
8585 | ||
8586 | static void | |
8587 | dtor_catch_exec (struct breakpoint *b) | |
8588 | { | |
8589 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8590 | ||
8591 | xfree (c->exec_pathname); | |
348d480f | 8592 | |
2060206e | 8593 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8594 | } |
8595 | ||
77b06cd7 TJB |
8596 | static int |
8597 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8598 | { |
dfd4cc63 | 8599 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8600 | } |
c906108c | 8601 | |
fe798b75 | 8602 | static int |
77b06cd7 | 8603 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8604 | { |
dfd4cc63 | 8605 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8606 | } |
c906108c | 8607 | |
fe798b75 | 8608 | static int |
f1310107 | 8609 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8610 | struct address_space *aspace, CORE_ADDR bp_addr, |
8611 | const struct target_waitstatus *ws) | |
fe798b75 | 8612 | { |
b4d90040 PA |
8613 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8614 | ||
f90263c1 TT |
8615 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8616 | return 0; | |
8617 | ||
8618 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8619 | return 1; | |
fe798b75 | 8620 | } |
c906108c | 8621 | |
fe798b75 | 8622 | static enum print_stop_action |
348d480f | 8623 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8624 | { |
36dfb11c | 8625 | struct ui_out *uiout = current_uiout; |
348d480f | 8626 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8627 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8628 | ||
fe798b75 | 8629 | annotate_catchpoint (b->number); |
36dfb11c TT |
8630 | if (b->disposition == disp_del) |
8631 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8632 | else | |
8633 | ui_out_text (uiout, "\nCatchpoint "); | |
8634 | if (ui_out_is_mi_like_p (uiout)) | |
8635 | { | |
8636 | ui_out_field_string (uiout, "reason", | |
8637 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8638 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8639 | } | |
8640 | ui_out_field_int (uiout, "bkptno", b->number); | |
8641 | ui_out_text (uiout, " (exec'd "); | |
8642 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8643 | ui_out_text (uiout, "), "); | |
8644 | ||
fe798b75 | 8645 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8646 | } |
8647 | ||
fe798b75 | 8648 | static void |
a6d9a66e | 8649 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8650 | { |
b4d90040 | 8651 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8652 | struct value_print_options opts; |
79a45e25 | 8653 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8654 | |
8655 | get_user_print_options (&opts); | |
8656 | ||
8657 | /* Field 4, the address, is omitted (which makes the columns | |
8658 | not line up too nicely with the headers, but the effect | |
8659 | is relatively readable). */ | |
8660 | if (opts.addressprint) | |
8661 | ui_out_field_skip (uiout, "addr"); | |
8662 | annotate_field (5); | |
8663 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8664 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8665 | { |
8666 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8667 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8668 | ui_out_text (uiout, "\" "); |
8669 | } | |
8ac3646f TT |
8670 | |
8671 | if (ui_out_is_mi_like_p (uiout)) | |
8672 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8673 | } |
8674 | ||
8675 | static void | |
8676 | print_mention_catch_exec (struct breakpoint *b) | |
8677 | { | |
8678 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8679 | } | |
8680 | ||
6149aea9 PA |
8681 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8682 | catchpoints. */ | |
8683 | ||
8684 | static void | |
8685 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8686 | { | |
8687 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8688 | print_recreate_thread (b, fp); |
6149aea9 PA |
8689 | } |
8690 | ||
2060206e | 8691 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8692 | |
a96d9b2e SDJ |
8693 | static void |
8694 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8695 | const struct breakpoint_ops *ops) |
a96d9b2e | 8696 | { |
be5c67c1 | 8697 | struct syscall_catchpoint *c; |
a96d9b2e | 8698 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8699 | |
be5c67c1 PA |
8700 | c = XNEW (struct syscall_catchpoint); |
8701 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8702 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8703 | |
3ea46bff | 8704 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8705 | } |
8706 | ||
c906108c | 8707 | static int |
fba45db2 | 8708 | hw_breakpoint_used_count (void) |
c906108c | 8709 | { |
c906108c | 8710 | int i = 0; |
f1310107 TJB |
8711 | struct breakpoint *b; |
8712 | struct bp_location *bl; | |
c906108c SS |
8713 | |
8714 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8715 | { |
d6b74ac4 | 8716 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8717 | for (bl = b->loc; bl; bl = bl->next) |
8718 | { | |
8719 | /* Special types of hardware breakpoints may use more than | |
8720 | one register. */ | |
348d480f | 8721 | i += b->ops->resources_needed (bl); |
f1310107 | 8722 | } |
c5aa993b | 8723 | } |
c906108c SS |
8724 | |
8725 | return i; | |
8726 | } | |
8727 | ||
a1398e0c PA |
8728 | /* Returns the resources B would use if it were a hardware |
8729 | watchpoint. */ | |
8730 | ||
c906108c | 8731 | static int |
a1398e0c | 8732 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8733 | { |
c906108c | 8734 | int i = 0; |
e09342b5 | 8735 | struct bp_location *bl; |
c906108c | 8736 | |
a1398e0c PA |
8737 | if (!breakpoint_enabled (b)) |
8738 | return 0; | |
8739 | ||
8740 | for (bl = b->loc; bl; bl = bl->next) | |
8741 | { | |
8742 | /* Special types of hardware watchpoints may use more than | |
8743 | one register. */ | |
8744 | i += b->ops->resources_needed (bl); | |
8745 | } | |
8746 | ||
8747 | return i; | |
8748 | } | |
8749 | ||
8750 | /* Returns the sum the used resources of all hardware watchpoints of | |
8751 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8752 | the sum of the used resources of all hardware watchpoints of other | |
8753 | types _not_ TYPE. */ | |
8754 | ||
8755 | static int | |
8756 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8757 | enum bptype type, int *other_type_used) | |
8758 | { | |
8759 | int i = 0; | |
8760 | struct breakpoint *b; | |
8761 | ||
c906108c SS |
8762 | *other_type_used = 0; |
8763 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8764 | { |
a1398e0c PA |
8765 | if (b == except) |
8766 | continue; | |
e09342b5 TJB |
8767 | if (!breakpoint_enabled (b)) |
8768 | continue; | |
8769 | ||
a1398e0c PA |
8770 | if (b->type == type) |
8771 | i += hw_watchpoint_use_count (b); | |
8772 | else if (is_hardware_watchpoint (b)) | |
8773 | *other_type_used = 1; | |
e09342b5 TJB |
8774 | } |
8775 | ||
c906108c SS |
8776 | return i; |
8777 | } | |
8778 | ||
c906108c | 8779 | void |
fba45db2 | 8780 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8781 | { |
c5aa993b | 8782 | struct breakpoint *b; |
c906108c SS |
8783 | |
8784 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8785 | { |
cc60f2e3 | 8786 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8787 | { |
b5de0fa7 | 8788 | b->enable_state = bp_call_disabled; |
b60e7edf | 8789 | update_global_location_list (0); |
c5aa993b JM |
8790 | } |
8791 | } | |
c906108c SS |
8792 | } |
8793 | ||
8794 | void | |
fba45db2 | 8795 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8796 | { |
c5aa993b | 8797 | struct breakpoint *b; |
c906108c SS |
8798 | |
8799 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8800 | { |
cc60f2e3 | 8801 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8802 | { |
b5de0fa7 | 8803 | b->enable_state = bp_enabled; |
b60e7edf | 8804 | update_global_location_list (1); |
c5aa993b JM |
8805 | } |
8806 | } | |
c906108c SS |
8807 | } |
8808 | ||
8bea4e01 UW |
8809 | void |
8810 | disable_breakpoints_before_startup (void) | |
8811 | { | |
6c95b8df | 8812 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8813 | update_global_location_list (0); |
8bea4e01 UW |
8814 | } |
8815 | ||
8816 | void | |
8817 | enable_breakpoints_after_startup (void) | |
8818 | { | |
6c95b8df | 8819 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8820 | breakpoint_re_set (); |
8bea4e01 UW |
8821 | } |
8822 | ||
c906108c SS |
8823 | |
8824 | /* Set a breakpoint that will evaporate an end of command | |
8825 | at address specified by SAL. | |
8826 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8827 | ||
8828 | struct breakpoint * | |
a6d9a66e UW |
8829 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8830 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8831 | { |
52f0bd74 | 8832 | struct breakpoint *b; |
edb3359d | 8833 | |
193facb3 JK |
8834 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8835 | tail-called one. */ | |
8836 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8837 | |
06edf0c0 | 8838 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8839 | b->enable_state = bp_enabled; |
8840 | b->disposition = disp_donttouch; | |
818dd999 | 8841 | b->frame_id = frame_id; |
c906108c | 8842 | |
4a64f543 MS |
8843 | /* If we're debugging a multi-threaded program, then we want |
8844 | momentary breakpoints to be active in only a single thread of | |
8845 | control. */ | |
39f77062 KB |
8846 | if (in_thread_list (inferior_ptid)) |
8847 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8848 | |
b60e7edf | 8849 | update_global_location_list_nothrow (1); |
74960c60 | 8850 | |
c906108c SS |
8851 | return b; |
8852 | } | |
611c83ae | 8853 | |
06edf0c0 PA |
8854 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8855 | The new breakpoint will have type TYPE, and use OPS as it | |
8856 | breakpoint_ops. */ | |
e58b0e63 | 8857 | |
06edf0c0 PA |
8858 | static struct breakpoint * |
8859 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8860 | enum bptype type, | |
c0a91b2b | 8861 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8862 | { |
8863 | struct breakpoint *copy; | |
8864 | ||
06edf0c0 | 8865 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8866 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8867 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8868 | |
a6d9a66e | 8869 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8870 | copy->loc->requested_address = orig->loc->requested_address; |
8871 | copy->loc->address = orig->loc->address; | |
8872 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8873 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8874 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8875 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8876 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8877 | copy->frame_id = orig->frame_id; |
8878 | copy->thread = orig->thread; | |
6c95b8df | 8879 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8880 | |
8881 | copy->enable_state = bp_enabled; | |
8882 | copy->disposition = disp_donttouch; | |
8883 | copy->number = internal_breakpoint_number--; | |
8884 | ||
8885 | update_global_location_list_nothrow (0); | |
8886 | return copy; | |
8887 | } | |
8888 | ||
06edf0c0 PA |
8889 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8890 | ORIG is NULL. */ | |
8891 | ||
8892 | struct breakpoint * | |
8893 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8894 | { | |
8895 | /* If there's nothing to clone, then return nothing. */ | |
8896 | if (orig == NULL) | |
8897 | return NULL; | |
8898 | ||
8899 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8900 | } | |
8901 | ||
611c83ae | 8902 | struct breakpoint * |
a6d9a66e UW |
8903 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8904 | enum bptype type) | |
611c83ae PA |
8905 | { |
8906 | struct symtab_and_line sal; | |
8907 | ||
8908 | sal = find_pc_line (pc, 0); | |
8909 | sal.pc = pc; | |
8910 | sal.section = find_pc_overlay (pc); | |
8911 | sal.explicit_pc = 1; | |
8912 | ||
a6d9a66e | 8913 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8914 | } |
c906108c | 8915 | \f |
c5aa993b | 8916 | |
c906108c SS |
8917 | /* Tell the user we have just set a breakpoint B. */ |
8918 | ||
8919 | static void | |
fba45db2 | 8920 | mention (struct breakpoint *b) |
c906108c | 8921 | { |
348d480f | 8922 | b->ops->print_mention (b); |
79a45e25 | 8923 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8924 | return; |
c906108c SS |
8925 | printf_filtered ("\n"); |
8926 | } | |
c906108c | 8927 | \f |
c5aa993b | 8928 | |
0d381245 | 8929 | static struct bp_location * |
39d61571 | 8930 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8931 | const struct symtab_and_line *sal) |
8932 | { | |
8933 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8934 | CORE_ADDR adjusted_address; |
8935 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8936 | ||
8937 | if (loc_gdbarch == NULL) | |
8938 | loc_gdbarch = b->gdbarch; | |
8939 | ||
8940 | /* Adjust the breakpoint's address prior to allocating a location. | |
8941 | Once we call allocate_bp_location(), that mostly uninitialized | |
8942 | location will be placed on the location chain. Adjustment of the | |
8943 | breakpoint may cause target_read_memory() to be called and we do | |
8944 | not want its scan of the location chain to find a breakpoint and | |
8945 | location that's only been partially initialized. */ | |
8946 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8947 | sal->pc, b->type); | |
0d381245 | 8948 | |
d30113d4 | 8949 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8950 | loc = allocate_bp_location (b); |
d30113d4 JK |
8951 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8952 | tmp = &((*tmp)->next)) | |
0d381245 | 8953 | ; |
d30113d4 | 8954 | loc->next = *tmp; |
0d381245 | 8955 | *tmp = loc; |
3742cc8b | 8956 | |
0d381245 | 8957 | loc->requested_address = sal->pc; |
3742cc8b | 8958 | loc->address = adjusted_address; |
6c95b8df | 8959 | loc->pspace = sal->pspace; |
55aa24fb | 8960 | loc->probe = sal->probe; |
6c95b8df | 8961 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8962 | loc->section = sal->section; |
3742cc8b | 8963 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8964 | loc->line_number = sal->line; |
2f202fde | 8965 | loc->symtab = sal->symtab; |
f8eba3c6 | 8966 | |
0e30163f JK |
8967 | set_breakpoint_location_function (loc, |
8968 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8969 | return loc; |
8970 | } | |
514f746b AR |
8971 | \f |
8972 | ||
8973 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8974 | return 0 otherwise. */ | |
8975 | ||
8976 | static int | |
8977 | bp_loc_is_permanent (struct bp_location *loc) | |
8978 | { | |
8979 | int len; | |
8980 | CORE_ADDR addr; | |
1afeeb75 | 8981 | const gdb_byte *bpoint; |
514f746b | 8982 | gdb_byte *target_mem; |
939c61fa JK |
8983 | struct cleanup *cleanup; |
8984 | int retval = 0; | |
514f746b AR |
8985 | |
8986 | gdb_assert (loc != NULL); | |
8987 | ||
8988 | addr = loc->address; | |
1afeeb75 | 8989 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 8990 | |
939c61fa | 8991 | /* Software breakpoints unsupported? */ |
1afeeb75 | 8992 | if (bpoint == NULL) |
939c61fa JK |
8993 | return 0; |
8994 | ||
514f746b AR |
8995 | target_mem = alloca (len); |
8996 | ||
939c61fa JK |
8997 | /* Enable the automatic memory restoration from breakpoints while |
8998 | we read the memory. Otherwise we could say about our temporary | |
8999 | breakpoints they are permanent. */ | |
6c95b8df PA |
9000 | cleanup = save_current_space_and_thread (); |
9001 | ||
9002 | switch_to_program_space_and_thread (loc->pspace); | |
9003 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9004 | |
514f746b | 9005 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9006 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9007 | retval = 1; |
514f746b | 9008 | |
939c61fa JK |
9009 | do_cleanups (cleanup); |
9010 | ||
9011 | return retval; | |
514f746b AR |
9012 | } |
9013 | ||
e7e0cddf SS |
9014 | /* Build a command list for the dprintf corresponding to the current |
9015 | settings of the dprintf style options. */ | |
9016 | ||
9017 | static void | |
9018 | update_dprintf_command_list (struct breakpoint *b) | |
9019 | { | |
9020 | char *dprintf_args = b->extra_string; | |
9021 | char *printf_line = NULL; | |
9022 | ||
9023 | if (!dprintf_args) | |
9024 | return; | |
9025 | ||
9026 | dprintf_args = skip_spaces (dprintf_args); | |
9027 | ||
9028 | /* Allow a comma, as it may have terminated a location, but don't | |
9029 | insist on it. */ | |
9030 | if (*dprintf_args == ',') | |
9031 | ++dprintf_args; | |
9032 | dprintf_args = skip_spaces (dprintf_args); | |
9033 | ||
9034 | if (*dprintf_args != '"') | |
9035 | error (_("Bad format string, missing '\"'.")); | |
9036 | ||
d3ce09f5 | 9037 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9038 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9039 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9040 | { |
9041 | if (!dprintf_function) | |
9042 | error (_("No function supplied for dprintf call")); | |
9043 | ||
9044 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9045 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9046 | dprintf_function, | |
9047 | dprintf_channel, | |
9048 | dprintf_args); | |
9049 | else | |
9050 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9051 | dprintf_function, | |
9052 | dprintf_args); | |
9053 | } | |
d3ce09f5 SS |
9054 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9055 | { | |
9056 | if (target_can_run_breakpoint_commands ()) | |
9057 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9058 | else | |
9059 | { | |
9060 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9061 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9062 | } | |
9063 | } | |
e7e0cddf SS |
9064 | else |
9065 | internal_error (__FILE__, __LINE__, | |
9066 | _("Invalid dprintf style.")); | |
9067 | ||
f28045c2 | 9068 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9069 | /* Manufacture a printf sequence. */ |
f28045c2 | 9070 | { |
9d6e6e84 HZ |
9071 | struct command_line *printf_cmd_line |
9072 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9073 | |
f28045c2 YQ |
9074 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9075 | printf_cmd_line->control_type = simple_control; | |
9076 | printf_cmd_line->body_count = 0; | |
9077 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9078 | printf_cmd_line->next = NULL; |
f28045c2 | 9079 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9080 | |
f28045c2 YQ |
9081 | breakpoint_set_commands (b, printf_cmd_line); |
9082 | } | |
e7e0cddf SS |
9083 | } |
9084 | ||
9085 | /* Update all dprintf commands, making their command lists reflect | |
9086 | current style settings. */ | |
9087 | ||
9088 | static void | |
9089 | update_dprintf_commands (char *args, int from_tty, | |
9090 | struct cmd_list_element *c) | |
9091 | { | |
9092 | struct breakpoint *b; | |
9093 | ||
9094 | ALL_BREAKPOINTS (b) | |
9095 | { | |
9096 | if (b->type == bp_dprintf) | |
9097 | update_dprintf_command_list (b); | |
9098 | } | |
9099 | } | |
c3f6f71d | 9100 | |
018d34a4 VP |
9101 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9102 | as textual description of the location, and COND_STRING | |
db107f19 | 9103 | as condition expression. */ |
018d34a4 VP |
9104 | |
9105 | static void | |
d9b3f62e PA |
9106 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9107 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9108 | char *filter, char *cond_string, |
e7e0cddf | 9109 | char *extra_string, |
d9b3f62e PA |
9110 | enum bptype type, enum bpdisp disposition, |
9111 | int thread, int task, int ignore_count, | |
c0a91b2b | 9112 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9113 | int enabled, int internal, unsigned flags, |
9114 | int display_canonical) | |
018d34a4 | 9115 | { |
0d381245 | 9116 | int i; |
018d34a4 VP |
9117 | |
9118 | if (type == bp_hardware_breakpoint) | |
9119 | { | |
fbbd034e AS |
9120 | int target_resources_ok; |
9121 | ||
9122 | i = hw_breakpoint_used_count (); | |
9123 | target_resources_ok = | |
9124 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9125 | i + 1, 0); |
9126 | if (target_resources_ok == 0) | |
9127 | error (_("No hardware breakpoint support in the target.")); | |
9128 | else if (target_resources_ok < 0) | |
9129 | error (_("Hardware breakpoints used exceeds limit.")); | |
9130 | } | |
9131 | ||
6c95b8df PA |
9132 | gdb_assert (sals.nelts > 0); |
9133 | ||
0d381245 VP |
9134 | for (i = 0; i < sals.nelts; ++i) |
9135 | { | |
9136 | struct symtab_and_line sal = sals.sals[i]; | |
9137 | struct bp_location *loc; | |
9138 | ||
9139 | if (from_tty) | |
5af949e3 UW |
9140 | { |
9141 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9142 | if (!loc_gdbarch) | |
9143 | loc_gdbarch = gdbarch; | |
9144 | ||
9145 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9146 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9147 | } |
0d381245 VP |
9148 | |
9149 | if (i == 0) | |
9150 | { | |
d9b3f62e | 9151 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9152 | b->thread = thread; |
4a306c9a | 9153 | b->task = task; |
855a6e68 | 9154 | |
0d381245 | 9155 | b->cond_string = cond_string; |
e7e0cddf | 9156 | b->extra_string = extra_string; |
0d381245 | 9157 | b->ignore_count = ignore_count; |
41447f92 | 9158 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9159 | b->disposition = disposition; |
6c95b8df | 9160 | |
44f238bb PA |
9161 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9162 | b->loc->inserted = 1; | |
9163 | ||
0fb4aa4b PA |
9164 | if (type == bp_static_tracepoint) |
9165 | { | |
d9b3f62e | 9166 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9167 | struct static_tracepoint_marker marker; |
9168 | ||
983af33b | 9169 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9170 | { |
9171 | /* We already know the marker exists, otherwise, we | |
9172 | wouldn't see a sal for it. */ | |
9173 | char *p = &addr_string[3]; | |
9174 | char *endp; | |
9175 | char *marker_str; | |
0fb4aa4b | 9176 | |
e9cafbcc | 9177 | p = skip_spaces (p); |
0fb4aa4b | 9178 | |
e9cafbcc | 9179 | endp = skip_to_space (p); |
0fb4aa4b PA |
9180 | |
9181 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9182 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9183 | |
3e43a32a MS |
9184 | printf_filtered (_("Probed static tracepoint " |
9185 | "marker \"%s\"\n"), | |
d9b3f62e | 9186 | t->static_trace_marker_id); |
0fb4aa4b PA |
9187 | } |
9188 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9189 | { | |
d9b3f62e | 9190 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9191 | release_static_tracepoint_marker (&marker); |
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 | |
3e43a32a MS |
9198 | warning (_("Couldn't determine the static " |
9199 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9200 | } |
9201 | ||
0d381245 VP |
9202 | loc = b->loc; |
9203 | } | |
9204 | else | |
018d34a4 | 9205 | { |
39d61571 | 9206 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9207 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9208 | loc->inserted = 1; | |
0d381245 VP |
9209 | } |
9210 | ||
514f746b AR |
9211 | if (bp_loc_is_permanent (loc)) |
9212 | make_breakpoint_permanent (b); | |
9213 | ||
0d381245 VP |
9214 | if (b->cond_string) |
9215 | { | |
bbc13ae3 KS |
9216 | const char *arg = b->cond_string; |
9217 | ||
1bb9788d TT |
9218 | loc->cond = parse_exp_1 (&arg, loc->address, |
9219 | block_for_pc (loc->address), 0); | |
0d381245 | 9220 | if (*arg) |
588ae58c | 9221 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9222 | } |
e7e0cddf SS |
9223 | |
9224 | /* Dynamic printf requires and uses additional arguments on the | |
9225 | command line, otherwise it's an error. */ | |
9226 | if (type == bp_dprintf) | |
9227 | { | |
9228 | if (b->extra_string) | |
9229 | update_dprintf_command_list (b); | |
9230 | else | |
9231 | error (_("Format string required")); | |
9232 | } | |
9233 | else if (b->extra_string) | |
588ae58c | 9234 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9235 | } |
018d34a4 | 9236 | |
56435ebe | 9237 | b->display_canonical = display_canonical; |
018d34a4 VP |
9238 | if (addr_string) |
9239 | b->addr_string = addr_string; | |
9240 | else | |
9241 | /* addr_string has to be used or breakpoint_re_set will delete | |
9242 | me. */ | |
5af949e3 UW |
9243 | b->addr_string |
9244 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9245 | b->filter = filter; |
d9b3f62e | 9246 | } |
018d34a4 | 9247 | |
d9b3f62e PA |
9248 | static void |
9249 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9250 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9251 | char *filter, char *cond_string, |
e7e0cddf | 9252 | char *extra_string, |
d9b3f62e PA |
9253 | enum bptype type, enum bpdisp disposition, |
9254 | int thread, int task, int ignore_count, | |
c0a91b2b | 9255 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9256 | int enabled, int internal, unsigned flags, |
9257 | int display_canonical) | |
d9b3f62e PA |
9258 | { |
9259 | struct breakpoint *b; | |
9260 | struct cleanup *old_chain; | |
9261 | ||
9262 | if (is_tracepoint_type (type)) | |
9263 | { | |
9264 | struct tracepoint *t; | |
9265 | ||
9266 | t = XCNEW (struct tracepoint); | |
9267 | b = &t->base; | |
9268 | } | |
9269 | else | |
9270 | b = XNEW (struct breakpoint); | |
9271 | ||
9272 | old_chain = make_cleanup (xfree, b); | |
9273 | ||
9274 | init_breakpoint_sal (b, gdbarch, | |
9275 | sals, addr_string, | |
e7e0cddf | 9276 | filter, cond_string, extra_string, |
d9b3f62e PA |
9277 | type, disposition, |
9278 | thread, task, ignore_count, | |
9279 | ops, from_tty, | |
44f238bb PA |
9280 | enabled, internal, flags, |
9281 | display_canonical); | |
d9b3f62e PA |
9282 | discard_cleanups (old_chain); |
9283 | ||
3ea46bff | 9284 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9285 | } |
9286 | ||
9287 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9288 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9289 | value. COND_STRING, if not NULL, specified the condition to be | |
9290 | used for all breakpoints. Essentially the only case where | |
9291 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9292 | function. In that case, it's still not possible to specify | |
9293 | separate conditions for different overloaded functions, so | |
9294 | we take just a single condition string. | |
9295 | ||
c3f6f71d | 9296 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9297 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9298 | array contents). If the function fails (error() is called), the |
9299 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9300 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9301 | |
9302 | static void | |
8cdf0e15 | 9303 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9304 | struct linespec_result *canonical, |
e7e0cddf | 9305 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9306 | enum bptype type, enum bpdisp disposition, |
9307 | int thread, int task, int ignore_count, | |
c0a91b2b | 9308 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9309 | int enabled, int internal, unsigned flags) |
c906108c | 9310 | { |
018d34a4 | 9311 | int i; |
f8eba3c6 | 9312 | struct linespec_sals *lsal; |
cc59ec59 | 9313 | |
f8eba3c6 TT |
9314 | if (canonical->pre_expanded) |
9315 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9316 | ||
9317 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9318 | { |
f8eba3c6 TT |
9319 | /* Note that 'addr_string' can be NULL in the case of a plain |
9320 | 'break', without arguments. */ | |
9321 | char *addr_string = (canonical->addr_string | |
9322 | ? xstrdup (canonical->addr_string) | |
9323 | : NULL); | |
9324 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9325 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9326 | |
f8eba3c6 TT |
9327 | make_cleanup (xfree, filter_string); |
9328 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9329 | addr_string, | |
9330 | filter_string, | |
e7e0cddf SS |
9331 | cond_string, extra_string, |
9332 | type, disposition, | |
84f4c1fe | 9333 | thread, task, ignore_count, ops, |
44f238bb | 9334 | from_tty, enabled, internal, flags, |
56435ebe | 9335 | canonical->special_display); |
f8eba3c6 | 9336 | discard_cleanups (inner); |
c3f6f71d | 9337 | } |
c3f6f71d | 9338 | } |
c906108c | 9339 | |
9998af43 | 9340 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9341 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9342 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9343 | address strings. ADDRESS points to the end of the SAL. |
9344 | ||
9345 | The array and the line spec strings are allocated on the heap, it is | |
9346 | the caller's responsibility to free them. */ | |
c906108c | 9347 | |
b9362cc7 | 9348 | static void |
c3f6f71d | 9349 | parse_breakpoint_sals (char **address, |
58438ac1 | 9350 | struct linespec_result *canonical) |
c3f6f71d | 9351 | { |
c3f6f71d | 9352 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9353 | breakpoint. */ |
c3f6f71d JM |
9354 | if ((*address) == NULL |
9355 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9356 | { |
1bfeeb0f JL |
9357 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9358 | address. */ | |
9359 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9360 | { |
f8eba3c6 | 9361 | struct linespec_sals lsal; |
c3f6f71d | 9362 | struct symtab_and_line sal; |
1c8cdcb1 | 9363 | CORE_ADDR pc; |
cc59ec59 | 9364 | |
4a64f543 | 9365 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9366 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9367 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9368 | |
9369 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9370 | corresponding to the last call to print_frame_info. |
9371 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9372 | as the breakpoint line number is inappropriate otherwise. | |
9373 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9374 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9375 | pc = sal.pc; |
9376 | sal = find_pc_line (pc, 0); | |
00903456 | 9377 | |
4a64f543 | 9378 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9379 | where PC is the last displayed codepoint's address. So |
9380 | make sure to set sal.explicit_pc to prevent GDB from | |
9381 | trying to expand the list of sals to include all other | |
9382 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9383 | sal.pc = pc; |
00903456 JK |
9384 | sal.explicit_pc = 1; |
9385 | ||
f8eba3c6 TT |
9386 | lsal.sals.sals[0] = sal; |
9387 | lsal.sals.nelts = 1; | |
9388 | lsal.canonical = NULL; | |
9389 | ||
9390 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9391 | } |
9392 | else | |
8a3fe4f8 | 9393 | error (_("No default breakpoint address now.")); |
c906108c SS |
9394 | } |
9395 | else | |
9396 | { | |
cc80f267 JK |
9397 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9398 | ||
c906108c | 9399 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9400 | current_source_symtab (which is decode_line_1's default). |
9401 | This should produce the results we want almost all of the | |
cc80f267 JK |
9402 | time while leaving default_breakpoint_* alone. |
9403 | ||
9404 | ObjC: However, don't match an Objective-C method name which | |
9405 | may have a '+' or '-' succeeded by a '['. */ | |
9406 | if (last_displayed_sal_is_valid () | |
9407 | && (!cursal.symtab | |
9408 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9409 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9410 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9411 | get_last_displayed_symtab (), | |
9412 | get_last_displayed_line (), | |
9413 | canonical, NULL, NULL); | |
c906108c | 9414 | else |
f8eba3c6 | 9415 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9416 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9417 | } |
c3f6f71d | 9418 | } |
c906108c | 9419 | |
c906108c | 9420 | |
c3f6f71d | 9421 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9422 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9423 | |
b9362cc7 | 9424 | static void |
23e7acfb | 9425 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9426 | { |
9427 | int i; | |
cc59ec59 | 9428 | |
c3f6f71d | 9429 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9430 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9431 | } |
9432 | ||
7a697b8d SS |
9433 | /* Fast tracepoints may have restrictions on valid locations. For |
9434 | instance, a fast tracepoint using a jump instead of a trap will | |
9435 | likely have to overwrite more bytes than a trap would, and so can | |
9436 | only be placed where the instruction is longer than the jump, or a | |
9437 | multi-instruction sequence does not have a jump into the middle of | |
9438 | it, etc. */ | |
9439 | ||
9440 | static void | |
9441 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9442 | struct symtabs_and_lines *sals) | |
9443 | { | |
9444 | int i, rslt; | |
9445 | struct symtab_and_line *sal; | |
9446 | char *msg; | |
9447 | struct cleanup *old_chain; | |
9448 | ||
9449 | for (i = 0; i < sals->nelts; i++) | |
9450 | { | |
f8eba3c6 TT |
9451 | struct gdbarch *sarch; |
9452 | ||
7a697b8d SS |
9453 | sal = &sals->sals[i]; |
9454 | ||
f8eba3c6 TT |
9455 | sarch = get_sal_arch (*sal); |
9456 | /* We fall back to GDBARCH if there is no architecture | |
9457 | associated with SAL. */ | |
9458 | if (sarch == NULL) | |
9459 | sarch = gdbarch; | |
9460 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9461 | NULL, &msg); |
9462 | old_chain = make_cleanup (xfree, msg); | |
9463 | ||
9464 | if (!rslt) | |
9465 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9466 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9467 | |
9468 | do_cleanups (old_chain); | |
9469 | } | |
9470 | } | |
9471 | ||
af4908ba KS |
9472 | /* Issue an invalid thread ID error. */ |
9473 | ||
9474 | static void ATTRIBUTE_NORETURN | |
9475 | invalid_thread_id_error (int id) | |
9476 | { | |
9477 | error (_("Unknown thread %d."), id); | |
9478 | } | |
9479 | ||
018d34a4 VP |
9480 | /* Given TOK, a string specification of condition and thread, as |
9481 | accepted by the 'break' command, extract the condition | |
9482 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9483 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9484 | If no condition is found, *COND_STRING is set to NULL. |
9485 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9486 | |
9487 | static void | |
bbc13ae3 | 9488 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9489 | char **cond_string, int *thread, int *task, |
9490 | char **rest) | |
018d34a4 VP |
9491 | { |
9492 | *cond_string = NULL; | |
9493 | *thread = -1; | |
ed1d1739 KS |
9494 | *task = 0; |
9495 | *rest = NULL; | |
9496 | ||
018d34a4 VP |
9497 | while (tok && *tok) |
9498 | { | |
bbc13ae3 | 9499 | const char *end_tok; |
018d34a4 | 9500 | int toklen; |
bbc13ae3 KS |
9501 | const char *cond_start = NULL; |
9502 | const char *cond_end = NULL; | |
cc59ec59 | 9503 | |
bbc13ae3 | 9504 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9505 | |
9506 | if ((*tok == '"' || *tok == ',') && rest) | |
9507 | { | |
9508 | *rest = savestring (tok, strlen (tok)); | |
9509 | return; | |
9510 | } | |
9511 | ||
bbc13ae3 | 9512 | end_tok = skip_to_space_const (tok); |
d634f2de | 9513 | |
018d34a4 | 9514 | toklen = end_tok - tok; |
d634f2de | 9515 | |
018d34a4 VP |
9516 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9517 | { | |
f7545552 TT |
9518 | struct expression *expr; |
9519 | ||
018d34a4 | 9520 | tok = cond_start = end_tok + 1; |
1bb9788d | 9521 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9522 | xfree (expr); |
018d34a4 | 9523 | cond_end = tok; |
d634f2de | 9524 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9525 | } |
9526 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9527 | { | |
9528 | char *tmptok; | |
d634f2de | 9529 | |
018d34a4 | 9530 | tok = end_tok + 1; |
bbc13ae3 | 9531 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9532 | if (tok == tmptok) |
9533 | error (_("Junk after thread keyword.")); | |
9534 | if (!valid_thread_id (*thread)) | |
af4908ba | 9535 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9536 | tok = tmptok; |
018d34a4 | 9537 | } |
4a306c9a JB |
9538 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9539 | { | |
9540 | char *tmptok; | |
9541 | ||
9542 | tok = end_tok + 1; | |
bbc13ae3 | 9543 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9544 | if (tok == tmptok) |
9545 | error (_("Junk after task keyword.")); | |
9546 | if (!valid_task_id (*task)) | |
b6199126 | 9547 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9548 | tok = tmptok; |
4a306c9a | 9549 | } |
e7e0cddf SS |
9550 | else if (rest) |
9551 | { | |
9552 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9553 | return; |
e7e0cddf | 9554 | } |
018d34a4 VP |
9555 | else |
9556 | error (_("Junk at end of arguments.")); | |
9557 | } | |
9558 | } | |
9559 | ||
0fb4aa4b PA |
9560 | /* Decode a static tracepoint marker spec. */ |
9561 | ||
9562 | static struct symtabs_and_lines | |
9563 | decode_static_tracepoint_spec (char **arg_p) | |
9564 | { | |
9565 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9566 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9567 | struct cleanup *old_chain; |
9568 | char *p = &(*arg_p)[3]; | |
9569 | char *endp; | |
9570 | char *marker_str; | |
9571 | int i; | |
9572 | ||
e9cafbcc | 9573 | p = skip_spaces (p); |
0fb4aa4b | 9574 | |
e9cafbcc | 9575 | endp = skip_to_space (p); |
0fb4aa4b PA |
9576 | |
9577 | marker_str = savestring (p, endp - p); | |
9578 | old_chain = make_cleanup (xfree, marker_str); | |
9579 | ||
9580 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9581 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9582 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9583 | ||
9584 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9585 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9586 | ||
9587 | for (i = 0; i < sals.nelts; i++) | |
9588 | { | |
9589 | struct static_tracepoint_marker *marker; | |
9590 | ||
9591 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9592 | ||
9593 | init_sal (&sals.sals[i]); | |
9594 | ||
9595 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9596 | sals.sals[i].pc = marker->address; | |
9597 | ||
9598 | release_static_tracepoint_marker (marker); | |
9599 | } | |
9600 | ||
9601 | do_cleanups (old_chain); | |
9602 | ||
9603 | *arg_p = endp; | |
9604 | return sals; | |
9605 | } | |
9606 | ||
fd9b8c24 PA |
9607 | /* Set a breakpoint. This function is shared between CLI and MI |
9608 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9609 | modes of operations, selected by the PARSE_ARG parameter. If |
9610 | non-zero, the function will parse ARG, extracting location, | |
9611 | condition, thread and extra string. Otherwise, ARG is just the | |
9612 | breakpoint's location, with condition, thread, and extra string | |
9613 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9614 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9615 | from the internal breakpoint count. Returns true if any breakpoint | |
9616 | was created; false otherwise. */ | |
0101ce28 | 9617 | |
8cdf0e15 VP |
9618 | int |
9619 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9620 | char *arg, char *cond_string, |
9621 | int thread, char *extra_string, | |
f6de8ec2 | 9622 | int parse_arg, |
0fb4aa4b | 9623 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9624 | int ignore_count, |
9625 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9626 | const struct breakpoint_ops *ops, |
44f238bb PA |
9627 | int from_tty, int enabled, int internal, |
9628 | unsigned flags) | |
c3f6f71d | 9629 | { |
b78a6381 | 9630 | volatile struct gdb_exception e; |
f8eba3c6 | 9631 | char *copy_arg = NULL; |
c3f6f71d | 9632 | char *addr_start = arg; |
7efd8fc2 | 9633 | struct linespec_result canonical; |
c3f6f71d | 9634 | struct cleanup *old_chain; |
80c99de1 | 9635 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9636 | int pending = 0; |
4a306c9a | 9637 | int task = 0; |
86b17b60 | 9638 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9639 | |
348d480f PA |
9640 | gdb_assert (ops != NULL); |
9641 | ||
7efd8fc2 | 9642 | init_linespec_result (&canonical); |
c3f6f71d | 9643 | |
b78a6381 TT |
9644 | TRY_CATCH (e, RETURN_MASK_ALL) |
9645 | { | |
983af33b SDJ |
9646 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9647 | addr_start, ©_arg); | |
b78a6381 | 9648 | } |
0101ce28 JJ |
9649 | |
9650 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9651 | switch (e.reason) |
0101ce28 | 9652 | { |
983af33b SDJ |
9653 | case GDB_NO_ERROR: |
9654 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9655 | return 0; | |
9656 | break; | |
05ff989b AC |
9657 | case RETURN_ERROR: |
9658 | switch (e.error) | |
0101ce28 | 9659 | { |
05ff989b | 9660 | case NOT_FOUND_ERROR: |
0101ce28 | 9661 | |
05ff989b AC |
9662 | /* If pending breakpoint support is turned off, throw |
9663 | error. */ | |
fa8d40ab JJ |
9664 | |
9665 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9666 | throw_exception (e); |
9667 | ||
9668 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9669 | |
05ff989b AC |
9670 | /* If pending breakpoint support is auto query and the user |
9671 | selects no, then simply return the error code. */ | |
059fb39f | 9672 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9673 | && !nquery (_("Make %s pending on future shared library load? "), |
9674 | bptype_string (type_wanted))) | |
fd9b8c24 | 9675 | return 0; |
fa8d40ab | 9676 | |
05ff989b AC |
9677 | /* At this point, either the user was queried about setting |
9678 | a pending breakpoint and selected yes, or pending | |
9679 | breakpoint behavior is on and thus a pending breakpoint | |
9680 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9681 | { |
9682 | struct linespec_sals lsal; | |
9683 | ||
9684 | copy_arg = xstrdup (addr_start); | |
9685 | lsal.canonical = xstrdup (copy_arg); | |
9686 | lsal.sals.nelts = 1; | |
9687 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9688 | init_sal (&lsal.sals.sals[0]); | |
9689 | pending = 1; | |
9690 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9691 | } | |
05ff989b AC |
9692 | break; |
9693 | default: | |
98deb0da | 9694 | throw_exception (e); |
0101ce28 | 9695 | } |
2abae994 | 9696 | break; |
05ff989b | 9697 | default: |
983af33b | 9698 | throw_exception (e); |
0101ce28 | 9699 | } |
c3f6f71d | 9700 | |
4a64f543 | 9701 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9702 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9703 | |
c3f6f71d JM |
9704 | /* ----------------------------- SNIP ----------------------------- |
9705 | Anything added to the cleanup chain beyond this point is assumed | |
9706 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9707 | then the memory is not reclaimed. */ |
9708 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9709 | |
c3f6f71d JM |
9710 | /* Resolve all line numbers to PC's and verify that the addresses |
9711 | are ok for the target. */ | |
0101ce28 | 9712 | if (!pending) |
f8eba3c6 TT |
9713 | { |
9714 | int ix; | |
9715 | struct linespec_sals *iter; | |
9716 | ||
9717 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9718 | breakpoint_sals_to_pc (&iter->sals); | |
9719 | } | |
c3f6f71d | 9720 | |
7a697b8d | 9721 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9722 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9723 | { |
9724 | int ix; | |
9725 | struct linespec_sals *iter; | |
9726 | ||
9727 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9728 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9729 | } | |
7a697b8d | 9730 | |
c3f6f71d JM |
9731 | /* Verify that condition can be parsed, before setting any |
9732 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9733 | breakpoint. */ |
0101ce28 | 9734 | if (!pending) |
c3f6f71d | 9735 | { |
f6de8ec2 | 9736 | if (parse_arg) |
72b2ff0e | 9737 | { |
0878d0fa | 9738 | char *rest; |
52d361e1 YQ |
9739 | struct linespec_sals *lsal; |
9740 | ||
9741 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9742 | ||
0878d0fa YQ |
9743 | /* Here we only parse 'arg' to separate condition |
9744 | from thread number, so parsing in context of first | |
9745 | sal is OK. When setting the breakpoint we'll | |
9746 | re-parse it in context of each sal. */ | |
9747 | ||
9748 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9749 | &thread, &task, &rest); | |
9750 | if (cond_string) | |
9751 | make_cleanup (xfree, cond_string); | |
9752 | if (rest) | |
9753 | make_cleanup (xfree, rest); | |
9754 | if (rest) | |
9755 | extra_string = rest; | |
72b2ff0e | 9756 | } |
2f069f6f | 9757 | else |
72b2ff0e | 9758 | { |
0878d0fa YQ |
9759 | if (*arg != '\0') |
9760 | error (_("Garbage '%s' at end of location"), arg); | |
9761 | ||
9762 | /* Create a private copy of condition string. */ | |
9763 | if (cond_string) | |
9764 | { | |
9765 | cond_string = xstrdup (cond_string); | |
9766 | make_cleanup (xfree, cond_string); | |
9767 | } | |
9768 | /* Create a private copy of any extra string. */ | |
9769 | if (extra_string) | |
9770 | { | |
9771 | extra_string = xstrdup (extra_string); | |
9772 | make_cleanup (xfree, extra_string); | |
9773 | } | |
72b2ff0e | 9774 | } |
0fb4aa4b | 9775 | |
52d361e1 | 9776 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9777 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9778 | tempflag ? disp_del : disp_donttouch, |
9779 | thread, task, ignore_count, ops, | |
44f238bb | 9780 | from_tty, enabled, internal, flags); |
c906108c | 9781 | } |
0101ce28 JJ |
9782 | else |
9783 | { | |
0101ce28 JJ |
9784 | struct breakpoint *b; |
9785 | ||
0101ce28 JJ |
9786 | make_cleanup (xfree, copy_arg); |
9787 | ||
bfccc43c YQ |
9788 | if (is_tracepoint_type (type_wanted)) |
9789 | { | |
9790 | struct tracepoint *t; | |
9791 | ||
9792 | t = XCNEW (struct tracepoint); | |
9793 | b = &t->base; | |
9794 | } | |
9795 | else | |
9796 | b = XNEW (struct breakpoint); | |
9797 | ||
9798 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9799 | ||
f8eba3c6 | 9800 | b->addr_string = copy_arg; |
f6de8ec2 | 9801 | if (parse_arg) |
e12c7713 MK |
9802 | b->cond_string = NULL; |
9803 | else | |
9804 | { | |
9805 | /* Create a private copy of condition string. */ | |
9806 | if (cond_string) | |
9807 | { | |
9808 | cond_string = xstrdup (cond_string); | |
9809 | make_cleanup (xfree, cond_string); | |
9810 | } | |
9811 | b->cond_string = cond_string; | |
9812 | } | |
e7e0cddf | 9813 | b->extra_string = NULL; |
0101ce28 | 9814 | b->ignore_count = ignore_count; |
0101ce28 | 9815 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9816 | b->condition_not_parsed = 1; |
41447f92 | 9817 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9818 | if ((type_wanted != bp_breakpoint |
9819 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9820 | b->pspace = current_program_space; |
8bea4e01 | 9821 | |
bfccc43c | 9822 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9823 | } |
9824 | ||
f8eba3c6 | 9825 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9826 | { |
3e43a32a MS |
9827 | warning (_("Multiple breakpoints were set.\nUse the " |
9828 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9829 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9830 | } |
9831 | ||
80c99de1 PA |
9832 | /* That's it. Discard the cleanups for data inserted into the |
9833 | breakpoint. */ | |
9834 | discard_cleanups (bkpt_chain); | |
9835 | /* But cleanup everything else. */ | |
c3f6f71d | 9836 | do_cleanups (old_chain); |
217dc9e2 | 9837 | |
80c99de1 | 9838 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9839 | update_global_location_list (1); |
fd9b8c24 PA |
9840 | |
9841 | return 1; | |
c3f6f71d | 9842 | } |
c906108c | 9843 | |
348d480f | 9844 | /* Set a breakpoint. |
72b2ff0e VP |
9845 | ARG is a string describing breakpoint address, |
9846 | condition, and thread. | |
9847 | FLAG specifies if a breakpoint is hardware on, | |
9848 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9849 | and BP_TEMPFLAG. */ | |
348d480f | 9850 | |
98deb0da | 9851 | static void |
72b2ff0e | 9852 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9853 | { |
72b2ff0e | 9854 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9855 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9856 | ? bp_hardware_breakpoint | |
9857 | : bp_breakpoint); | |
55aa24fb SDJ |
9858 | struct breakpoint_ops *ops; |
9859 | const char *arg_cp = arg; | |
9860 | ||
9861 | /* Matching breakpoints on probes. */ | |
9862 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9863 | ops = &bkpt_probe_breakpoint_ops; | |
9864 | else | |
9865 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9866 | |
8cdf0e15 VP |
9867 | create_breakpoint (get_current_arch (), |
9868 | arg, | |
e7e0cddf | 9869 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9870 | tempflag, type_wanted, |
8cdf0e15 VP |
9871 | 0 /* Ignore count */, |
9872 | pending_break_support, | |
55aa24fb | 9873 | ops, |
8cdf0e15 | 9874 | from_tty, |
84f4c1fe | 9875 | 1 /* enabled */, |
44f238bb PA |
9876 | 0 /* internal */, |
9877 | 0); | |
c906108c SS |
9878 | } |
9879 | ||
c906108c SS |
9880 | /* Helper function for break_command_1 and disassemble_command. */ |
9881 | ||
9882 | void | |
fba45db2 | 9883 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9884 | { |
9885 | CORE_ADDR pc; | |
9886 | ||
9887 | if (sal->pc == 0 && sal->symtab != NULL) | |
9888 | { | |
9889 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9890 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9891 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9892 | sal->pc = pc; |
6a048695 | 9893 | |
4a64f543 MS |
9894 | /* If this SAL corresponds to a breakpoint inserted using a line |
9895 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9896 | if (sal->explicit_line) |
059acae7 | 9897 | skip_prologue_sal (sal); |
c906108c SS |
9898 | } |
9899 | ||
9900 | if (sal->section == 0 && sal->symtab != NULL) | |
9901 | { | |
9902 | struct blockvector *bv; | |
c5aa993b JM |
9903 | struct block *b; |
9904 | struct symbol *sym; | |
c906108c | 9905 | |
801e3a5b | 9906 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9907 | if (bv != NULL) |
9908 | { | |
7f0df278 | 9909 | sym = block_linkage_function (b); |
c906108c SS |
9910 | if (sym != NULL) |
9911 | { | |
9912 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9913 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9914 | } |
9915 | else | |
9916 | { | |
4a64f543 MS |
9917 | /* It really is worthwhile to have the section, so we'll |
9918 | just have to look harder. This case can be executed | |
9919 | if we have line numbers but no functions (as can | |
9920 | happen in assembly source). */ | |
c906108c | 9921 | |
7cbd4a93 | 9922 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9923 | struct cleanup *old_chain = save_current_space_and_thread (); |
9924 | ||
9925 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9926 | |
9927 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9928 | if (msym.minsym) |
e27d198c | 9929 | sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9930 | |
9931 | do_cleanups (old_chain); | |
c906108c SS |
9932 | } |
9933 | } | |
9934 | } | |
9935 | } | |
9936 | ||
9937 | void | |
fba45db2 | 9938 | break_command (char *arg, int from_tty) |
c906108c | 9939 | { |
db107f19 | 9940 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9941 | } |
9942 | ||
c906108c | 9943 | void |
fba45db2 | 9944 | tbreak_command (char *arg, int from_tty) |
c906108c | 9945 | { |
db107f19 | 9946 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9947 | } |
9948 | ||
c906108c | 9949 | static void |
fba45db2 | 9950 | hbreak_command (char *arg, int from_tty) |
c906108c | 9951 | { |
db107f19 | 9952 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9953 | } |
9954 | ||
9955 | static void | |
fba45db2 | 9956 | thbreak_command (char *arg, int from_tty) |
c906108c | 9957 | { |
db107f19 | 9958 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9959 | } |
9960 | ||
9961 | static void | |
fba45db2 | 9962 | stop_command (char *arg, int from_tty) |
c906108c | 9963 | { |
a3f17187 | 9964 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9965 | Usage: stop in <function | address>\n\ |
a3f17187 | 9966 | stop at <line>\n")); |
c906108c SS |
9967 | } |
9968 | ||
9969 | static void | |
fba45db2 | 9970 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9971 | { |
9972 | int badInput = 0; | |
9973 | ||
c5aa993b | 9974 | if (arg == (char *) NULL) |
c906108c SS |
9975 | badInput = 1; |
9976 | else if (*arg != '*') | |
9977 | { | |
9978 | char *argptr = arg; | |
9979 | int hasColon = 0; | |
9980 | ||
4a64f543 | 9981 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9982 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9983 | function/method name. */ |
c906108c | 9984 | while (*argptr && !hasColon) |
c5aa993b JM |
9985 | { |
9986 | hasColon = (*argptr == ':'); | |
9987 | argptr++; | |
9988 | } | |
c906108c SS |
9989 | |
9990 | if (hasColon) | |
c5aa993b | 9991 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9992 | else |
c5aa993b | 9993 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9994 | } |
9995 | ||
9996 | if (badInput) | |
a3f17187 | 9997 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9998 | else |
db107f19 | 9999 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10000 | } |
10001 | ||
10002 | static void | |
fba45db2 | 10003 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10004 | { |
10005 | int badInput = 0; | |
10006 | ||
c5aa993b | 10007 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10008 | badInput = 1; |
10009 | else | |
10010 | { | |
10011 | char *argptr = arg; | |
10012 | int hasColon = 0; | |
10013 | ||
4a64f543 MS |
10014 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10015 | it is probably a line number. */ | |
c906108c | 10016 | while (*argptr && !hasColon) |
c5aa993b JM |
10017 | { |
10018 | hasColon = (*argptr == ':'); | |
10019 | argptr++; | |
10020 | } | |
c906108c SS |
10021 | |
10022 | if (hasColon) | |
c5aa993b | 10023 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10024 | else |
c5aa993b | 10025 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10026 | } |
10027 | ||
10028 | if (badInput) | |
a3f17187 | 10029 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10030 | else |
db107f19 | 10031 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10032 | } |
10033 | ||
e7e0cddf SS |
10034 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10035 | with a prewired command list consisting of a single output command, | |
10036 | built from extra arguments supplied on the dprintf command | |
10037 | line. */ | |
10038 | ||
da821c7b | 10039 | static void |
e7e0cddf SS |
10040 | dprintf_command (char *arg, int from_tty) |
10041 | { | |
10042 | create_breakpoint (get_current_arch (), | |
10043 | arg, | |
10044 | NULL, 0, NULL, 1 /* parse arg */, | |
10045 | 0, bp_dprintf, | |
10046 | 0 /* Ignore count */, | |
10047 | pending_break_support, | |
10048 | &dprintf_breakpoint_ops, | |
10049 | from_tty, | |
10050 | 1 /* enabled */, | |
10051 | 0 /* internal */, | |
10052 | 0); | |
10053 | } | |
10054 | ||
d3ce09f5 SS |
10055 | static void |
10056 | agent_printf_command (char *arg, int from_tty) | |
10057 | { | |
10058 | error (_("May only run agent-printf on the target")); | |
10059 | } | |
10060 | ||
f1310107 TJB |
10061 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10062 | ranged breakpoints. */ | |
10063 | ||
10064 | static int | |
10065 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10066 | struct address_space *aspace, | |
09ac7c10 TT |
10067 | CORE_ADDR bp_addr, |
10068 | const struct target_waitstatus *ws) | |
f1310107 | 10069 | { |
09ac7c10 | 10070 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10071 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10072 | return 0; |
10073 | ||
f1310107 TJB |
10074 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10075 | bl->length, aspace, bp_addr); | |
10076 | } | |
10077 | ||
10078 | /* Implement the "resources_needed" breakpoint_ops method for | |
10079 | ranged breakpoints. */ | |
10080 | ||
10081 | static int | |
10082 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10083 | { | |
10084 | return target_ranged_break_num_registers (); | |
10085 | } | |
10086 | ||
10087 | /* Implement the "print_it" breakpoint_ops method for | |
10088 | ranged breakpoints. */ | |
10089 | ||
10090 | static enum print_stop_action | |
348d480f | 10091 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10092 | { |
348d480f | 10093 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10094 | struct bp_location *bl = b->loc; |
79a45e25 | 10095 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10096 | |
10097 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10098 | ||
10099 | /* Ranged breakpoints have only one location. */ | |
10100 | gdb_assert (bl && bl->next == NULL); | |
10101 | ||
10102 | annotate_breakpoint (b->number); | |
10103 | if (b->disposition == disp_del) | |
10104 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10105 | else | |
10106 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10107 | if (ui_out_is_mi_like_p (uiout)) | |
10108 | { | |
10109 | ui_out_field_string (uiout, "reason", | |
10110 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10111 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10112 | } | |
10113 | ui_out_field_int (uiout, "bkptno", b->number); | |
10114 | ui_out_text (uiout, ", "); | |
10115 | ||
10116 | return PRINT_SRC_AND_LOC; | |
10117 | } | |
10118 | ||
10119 | /* Implement the "print_one" breakpoint_ops method for | |
10120 | ranged breakpoints. */ | |
10121 | ||
10122 | static void | |
10123 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10124 | struct bp_location **last_loc) | |
10125 | { | |
10126 | struct bp_location *bl = b->loc; | |
10127 | struct value_print_options opts; | |
79a45e25 | 10128 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10129 | |
10130 | /* Ranged breakpoints have only one location. */ | |
10131 | gdb_assert (bl && bl->next == NULL); | |
10132 | ||
10133 | get_user_print_options (&opts); | |
10134 | ||
10135 | if (opts.addressprint) | |
10136 | /* We don't print the address range here, it will be printed later | |
10137 | by print_one_detail_ranged_breakpoint. */ | |
10138 | ui_out_field_skip (uiout, "addr"); | |
10139 | annotate_field (5); | |
10140 | print_breakpoint_location (b, bl); | |
10141 | *last_loc = bl; | |
10142 | } | |
10143 | ||
10144 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10145 | ranged breakpoints. */ | |
10146 | ||
10147 | static void | |
10148 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10149 | struct ui_out *uiout) | |
10150 | { | |
10151 | CORE_ADDR address_start, address_end; | |
10152 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10153 | struct ui_file *stb = mem_fileopen (); |
10154 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10155 | |
10156 | gdb_assert (bl); | |
10157 | ||
10158 | address_start = bl->address; | |
10159 | address_end = address_start + bl->length - 1; | |
10160 | ||
10161 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10162 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10163 | print_core_address (bl->gdbarch, address_start), |
10164 | print_core_address (bl->gdbarch, address_end)); | |
10165 | ui_out_field_stream (uiout, "addr", stb); | |
10166 | ui_out_text (uiout, "\n"); | |
10167 | ||
10168 | do_cleanups (cleanup); | |
10169 | } | |
10170 | ||
10171 | /* Implement the "print_mention" breakpoint_ops method for | |
10172 | ranged breakpoints. */ | |
10173 | ||
10174 | static void | |
10175 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10176 | { | |
10177 | struct bp_location *bl = b->loc; | |
79a45e25 | 10178 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10179 | |
10180 | gdb_assert (bl); | |
10181 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10182 | ||
10183 | if (ui_out_is_mi_like_p (uiout)) | |
10184 | return; | |
10185 | ||
10186 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10187 | b->number, paddress (bl->gdbarch, bl->address), | |
10188 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10189 | } | |
10190 | ||
10191 | /* Implement the "print_recreate" breakpoint_ops method for | |
10192 | ranged breakpoints. */ | |
10193 | ||
10194 | static void | |
10195 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10196 | { | |
10197 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10198 | b->addr_string_range_end); | |
d9b3f62e | 10199 | print_recreate_thread (b, fp); |
f1310107 TJB |
10200 | } |
10201 | ||
10202 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10203 | ||
2060206e | 10204 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10205 | |
10206 | /* Find the address where the end of the breakpoint range should be | |
10207 | placed, given the SAL of the end of the range. This is so that if | |
10208 | the user provides a line number, the end of the range is set to the | |
10209 | last instruction of the given line. */ | |
10210 | ||
10211 | static CORE_ADDR | |
10212 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10213 | { | |
10214 | CORE_ADDR end; | |
10215 | ||
10216 | /* If the user provided a PC value, use it. Otherwise, | |
10217 | find the address of the end of the given location. */ | |
10218 | if (sal.explicit_pc) | |
10219 | end = sal.pc; | |
10220 | else | |
10221 | { | |
10222 | int ret; | |
10223 | CORE_ADDR start; | |
10224 | ||
10225 | ret = find_line_pc_range (sal, &start, &end); | |
10226 | if (!ret) | |
10227 | error (_("Could not find location of the end of the range.")); | |
10228 | ||
10229 | /* find_line_pc_range returns the start of the next line. */ | |
10230 | end--; | |
10231 | } | |
10232 | ||
10233 | return end; | |
10234 | } | |
10235 | ||
10236 | /* Implement the "break-range" CLI command. */ | |
10237 | ||
10238 | static void | |
10239 | break_range_command (char *arg, int from_tty) | |
10240 | { | |
10241 | char *arg_start, *addr_string_start, *addr_string_end; | |
10242 | struct linespec_result canonical_start, canonical_end; | |
10243 | int bp_count, can_use_bp, length; | |
10244 | CORE_ADDR end; | |
10245 | struct breakpoint *b; | |
10246 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10247 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10248 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10249 | |
10250 | /* We don't support software ranged breakpoints. */ | |
10251 | if (target_ranged_break_num_registers () < 0) | |
10252 | error (_("This target does not support hardware ranged breakpoints.")); | |
10253 | ||
10254 | bp_count = hw_breakpoint_used_count (); | |
10255 | bp_count += target_ranged_break_num_registers (); | |
10256 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10257 | bp_count, 0); | |
10258 | if (can_use_bp < 0) | |
10259 | error (_("Hardware breakpoints used exceeds limit.")); | |
10260 | ||
f8eba3c6 | 10261 | arg = skip_spaces (arg); |
f1310107 TJB |
10262 | if (arg == NULL || arg[0] == '\0') |
10263 | error(_("No address range specified.")); | |
10264 | ||
f1310107 TJB |
10265 | init_linespec_result (&canonical_start); |
10266 | ||
f8eba3c6 TT |
10267 | arg_start = arg; |
10268 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10269 | |
f8eba3c6 | 10270 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10271 | |
10272 | if (arg[0] != ',') | |
10273 | error (_("Too few arguments.")); | |
f8eba3c6 | 10274 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10275 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10276 | |
10277 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10278 | ||
10279 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10280 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10281 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10282 | ||
f8eba3c6 TT |
10283 | sal_start = lsal_start->sals.sals[0]; |
10284 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10285 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10286 | |
10287 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10288 | arg = skip_spaces (arg); |
f1310107 TJB |
10289 | |
10290 | /* Parse the end location. */ | |
10291 | ||
f1310107 TJB |
10292 | init_linespec_result (&canonical_end); |
10293 | arg_start = arg; | |
10294 | ||
f8eba3c6 | 10295 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10296 | parse_breakpoint_sals because we need to specify the start location's |
10297 | symtab and line as the default symtab and line for the end of the | |
10298 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10299 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10300 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10301 | sal_start.symtab, sal_start.line, | |
10302 | &canonical_end, NULL, NULL); | |
10303 | ||
10304 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10305 | |
f8eba3c6 | 10306 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10307 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10308 | |
10309 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10310 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10311 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10312 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10313 | ||
f8eba3c6 TT |
10314 | sal_end = lsal_end->sals.sals[0]; |
10315 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10316 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10317 | |
10318 | end = find_breakpoint_range_end (sal_end); | |
10319 | if (sal_start.pc > end) | |
177b42fe | 10320 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10321 | |
10322 | length = end - sal_start.pc + 1; | |
10323 | if (length < 0) | |
10324 | /* Length overflowed. */ | |
10325 | error (_("Address range too large.")); | |
10326 | else if (length == 1) | |
10327 | { | |
10328 | /* This range is simple enough to be handled by | |
10329 | the `hbreak' command. */ | |
10330 | hbreak_command (addr_string_start, 1); | |
10331 | ||
10332 | do_cleanups (cleanup_bkpt); | |
10333 | ||
10334 | return; | |
10335 | } | |
10336 | ||
10337 | /* Now set up the breakpoint. */ | |
10338 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10339 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10340 | set_breakpoint_count (breakpoint_count + 1); |
10341 | b->number = breakpoint_count; | |
10342 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10343 | b->addr_string = xstrdup (addr_string_start); |
10344 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10345 | b->loc->length = length; |
10346 | ||
f8eba3c6 | 10347 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10348 | |
10349 | mention (b); | |
8d3788bd | 10350 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10351 | update_global_location_list (1); |
10352 | } | |
10353 | ||
4a64f543 MS |
10354 | /* Return non-zero if EXP is verified as constant. Returned zero |
10355 | means EXP is variable. Also the constant detection may fail for | |
10356 | some constant expressions and in such case still falsely return | |
10357 | zero. */ | |
2e6e3d9c | 10358 | |
65d79d4b SDJ |
10359 | static int |
10360 | watchpoint_exp_is_const (const struct expression *exp) | |
10361 | { | |
10362 | int i = exp->nelts; | |
10363 | ||
10364 | while (i > 0) | |
10365 | { | |
10366 | int oplenp, argsp; | |
10367 | ||
10368 | /* We are only interested in the descriptor of each element. */ | |
10369 | operator_length (exp, i, &oplenp, &argsp); | |
10370 | i -= oplenp; | |
10371 | ||
10372 | switch (exp->elts[i].opcode) | |
10373 | { | |
10374 | case BINOP_ADD: | |
10375 | case BINOP_SUB: | |
10376 | case BINOP_MUL: | |
10377 | case BINOP_DIV: | |
10378 | case BINOP_REM: | |
10379 | case BINOP_MOD: | |
10380 | case BINOP_LSH: | |
10381 | case BINOP_RSH: | |
10382 | case BINOP_LOGICAL_AND: | |
10383 | case BINOP_LOGICAL_OR: | |
10384 | case BINOP_BITWISE_AND: | |
10385 | case BINOP_BITWISE_IOR: | |
10386 | case BINOP_BITWISE_XOR: | |
10387 | case BINOP_EQUAL: | |
10388 | case BINOP_NOTEQUAL: | |
10389 | case BINOP_LESS: | |
10390 | case BINOP_GTR: | |
10391 | case BINOP_LEQ: | |
10392 | case BINOP_GEQ: | |
10393 | case BINOP_REPEAT: | |
10394 | case BINOP_COMMA: | |
10395 | case BINOP_EXP: | |
10396 | case BINOP_MIN: | |
10397 | case BINOP_MAX: | |
10398 | case BINOP_INTDIV: | |
10399 | case BINOP_CONCAT: | |
10400 | case BINOP_IN: | |
10401 | case BINOP_RANGE: | |
10402 | case TERNOP_COND: | |
10403 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10404 | |
10405 | case OP_LONG: | |
10406 | case OP_DOUBLE: | |
10407 | case OP_DECFLOAT: | |
10408 | case OP_LAST: | |
10409 | case OP_COMPLEX: | |
10410 | case OP_STRING: | |
65d79d4b SDJ |
10411 | case OP_ARRAY: |
10412 | case OP_TYPE: | |
608b4967 TT |
10413 | case OP_TYPEOF: |
10414 | case OP_DECLTYPE: | |
6e72ca20 | 10415 | case OP_TYPEID: |
65d79d4b SDJ |
10416 | case OP_NAME: |
10417 | case OP_OBJC_NSSTRING: | |
10418 | ||
10419 | case UNOP_NEG: | |
10420 | case UNOP_LOGICAL_NOT: | |
10421 | case UNOP_COMPLEMENT: | |
10422 | case UNOP_ADDR: | |
10423 | case UNOP_HIGH: | |
aeaa2474 | 10424 | case UNOP_CAST: |
9eaf6705 TT |
10425 | |
10426 | case UNOP_CAST_TYPE: | |
10427 | case UNOP_REINTERPRET_CAST: | |
10428 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10429 | /* Unary, binary and ternary operators: We have to check |
10430 | their operands. If they are constant, then so is the | |
10431 | result of that operation. For instance, if A and B are | |
10432 | determined to be constants, then so is "A + B". | |
10433 | ||
10434 | UNOP_IND is one exception to the rule above, because the | |
10435 | value of *ADDR is not necessarily a constant, even when | |
10436 | ADDR is. */ | |
65d79d4b SDJ |
10437 | break; |
10438 | ||
10439 | case OP_VAR_VALUE: | |
10440 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10441 | |
65d79d4b | 10442 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10443 | possible that a buggy compiler could mark a variable as |
10444 | constant even when it is not, and TYPE_CONST would return | |
10445 | true in this case, while SYMBOL_CLASS wouldn't. | |
10446 | ||
10447 | We also have to check for function symbols because they | |
10448 | are always constant. */ | |
65d79d4b SDJ |
10449 | { |
10450 | struct symbol *s = exp->elts[i + 2].symbol; | |
10451 | ||
10452 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10453 | && SYMBOL_CLASS (s) != LOC_CONST | |
10454 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10455 | return 0; | |
10456 | break; | |
10457 | } | |
10458 | ||
10459 | /* The default action is to return 0 because we are using | |
10460 | the optimistic approach here: If we don't know something, | |
10461 | then it is not a constant. */ | |
10462 | default: | |
10463 | return 0; | |
10464 | } | |
10465 | } | |
10466 | ||
10467 | return 1; | |
10468 | } | |
10469 | ||
3a5c3e22 PA |
10470 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10471 | ||
10472 | static void | |
10473 | dtor_watchpoint (struct breakpoint *self) | |
10474 | { | |
10475 | struct watchpoint *w = (struct watchpoint *) self; | |
10476 | ||
10477 | xfree (w->cond_exp); | |
10478 | xfree (w->exp); | |
10479 | xfree (w->exp_string); | |
10480 | xfree (w->exp_string_reparse); | |
10481 | value_free (w->val); | |
10482 | ||
10483 | base_breakpoint_ops.dtor (self); | |
10484 | } | |
10485 | ||
348d480f PA |
10486 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10487 | ||
10488 | static void | |
10489 | re_set_watchpoint (struct breakpoint *b) | |
10490 | { | |
3a5c3e22 PA |
10491 | struct watchpoint *w = (struct watchpoint *) b; |
10492 | ||
348d480f PA |
10493 | /* Watchpoint can be either on expression using entirely global |
10494 | variables, or it can be on local variables. | |
10495 | ||
10496 | Watchpoints of the first kind are never auto-deleted, and even | |
10497 | persist across program restarts. Since they can use variables | |
10498 | from shared libraries, we need to reparse expression as libraries | |
10499 | are loaded and unloaded. | |
10500 | ||
10501 | Watchpoints on local variables can also change meaning as result | |
10502 | of solib event. For example, if a watchpoint uses both a local | |
10503 | and a global variables in expression, it's a local watchpoint, | |
10504 | but unloading of a shared library will make the expression | |
10505 | invalid. This is not a very common use case, but we still | |
10506 | re-evaluate expression, to avoid surprises to the user. | |
10507 | ||
10508 | Note that for local watchpoints, we re-evaluate it only if | |
10509 | watchpoints frame id is still valid. If it's not, it means the | |
10510 | watchpoint is out of scope and will be deleted soon. In fact, | |
10511 | I'm not sure we'll ever be called in this case. | |
10512 | ||
10513 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10514 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10515 | |
3a5c3e22 PA |
10516 | Don't do anything about disabled watchpoints, since they will be |
10517 | reevaluated again when enabled. */ | |
10518 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10519 | } |
10520 | ||
77b06cd7 TJB |
10521 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10522 | ||
10523 | static int | |
10524 | insert_watchpoint (struct bp_location *bl) | |
10525 | { | |
3a5c3e22 PA |
10526 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10527 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10528 | |
10529 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10530 | w->cond_exp); |
77b06cd7 TJB |
10531 | } |
10532 | ||
10533 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10534 | ||
10535 | static int | |
10536 | remove_watchpoint (struct bp_location *bl) | |
10537 | { | |
3a5c3e22 PA |
10538 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10539 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10540 | |
10541 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10542 | w->cond_exp); |
e09342b5 TJB |
10543 | } |
10544 | ||
e09342b5 | 10545 | static int |
348d480f | 10546 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10547 | struct address_space *aspace, CORE_ADDR bp_addr, |
10548 | const struct target_waitstatus *ws) | |
e09342b5 | 10549 | { |
348d480f | 10550 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10551 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10552 | |
348d480f PA |
10553 | /* Continuable hardware watchpoints are treated as non-existent if the |
10554 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10555 | some data address). Otherwise gdb won't stop on a break instruction | |
10556 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10557 | been defined. Also skip watchpoints which we know did not trigger | |
10558 | (did not match the data address). */ | |
10559 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10560 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10561 | return 0; |
9c06b0b4 | 10562 | |
348d480f | 10563 | return 1; |
9c06b0b4 TJB |
10564 | } |
10565 | ||
348d480f PA |
10566 | static void |
10567 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10568 | { |
348d480f | 10569 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10570 | |
348d480f | 10571 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10572 | } |
10573 | ||
10574 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10575 | hardware watchpoints. */ |
9c06b0b4 TJB |
10576 | |
10577 | static int | |
348d480f | 10578 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10579 | { |
3a5c3e22 PA |
10580 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10581 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10582 | |
10583 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10584 | } |
10585 | ||
10586 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10587 | hardware watchpoints. */ |
9c06b0b4 TJB |
10588 | |
10589 | static int | |
348d480f | 10590 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10591 | { |
efa80663 PA |
10592 | /* Read and access watchpoints only work with hardware support. */ |
10593 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10594 | } |
10595 | ||
9c06b0b4 | 10596 | static enum print_stop_action |
348d480f | 10597 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10598 | { |
348d480f PA |
10599 | struct cleanup *old_chain; |
10600 | struct breakpoint *b; | |
f99d8bf4 | 10601 | struct ui_file *stb; |
348d480f | 10602 | enum print_stop_action result; |
3a5c3e22 | 10603 | struct watchpoint *w; |
79a45e25 | 10604 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10605 | |
10606 | gdb_assert (bs->bp_location_at != NULL); | |
10607 | ||
348d480f | 10608 | b = bs->breakpoint_at; |
3a5c3e22 | 10609 | w = (struct watchpoint *) b; |
348d480f | 10610 | |
f99d8bf4 PA |
10611 | stb = mem_fileopen (); |
10612 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10613 | |
10614 | switch (b->type) | |
10615 | { | |
348d480f | 10616 | case bp_watchpoint: |
9c06b0b4 TJB |
10617 | case bp_hardware_watchpoint: |
10618 | annotate_watchpoint (b->number); | |
10619 | if (ui_out_is_mi_like_p (uiout)) | |
10620 | ui_out_field_string | |
10621 | (uiout, "reason", | |
10622 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10623 | mention (b); |
10624 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10625 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10626 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10627 | ui_out_field_stream (uiout, "old", stb); |
10628 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10629 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10630 | ui_out_field_stream (uiout, "new", stb); |
10631 | ui_out_text (uiout, "\n"); | |
10632 | /* More than one watchpoint may have been triggered. */ | |
10633 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10634 | break; |
10635 | ||
10636 | case bp_read_watchpoint: | |
10637 | if (ui_out_is_mi_like_p (uiout)) | |
10638 | ui_out_field_string | |
10639 | (uiout, "reason", | |
10640 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10641 | mention (b); |
10642 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10643 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10644 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10645 | ui_out_field_stream (uiout, "value", stb); |
10646 | ui_out_text (uiout, "\n"); | |
10647 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10648 | break; |
10649 | ||
10650 | case bp_access_watchpoint: | |
348d480f PA |
10651 | if (bs->old_val != NULL) |
10652 | { | |
10653 | annotate_watchpoint (b->number); | |
10654 | if (ui_out_is_mi_like_p (uiout)) | |
10655 | ui_out_field_string | |
10656 | (uiout, "reason", | |
10657 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10658 | mention (b); | |
10659 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10660 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10661 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10662 | ui_out_field_stream (uiout, "old", stb); |
10663 | ui_out_text (uiout, "\nNew value = "); | |
10664 | } | |
10665 | else | |
10666 | { | |
10667 | mention (b); | |
10668 | if (ui_out_is_mi_like_p (uiout)) | |
10669 | ui_out_field_string | |
10670 | (uiout, "reason", | |
10671 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10672 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10673 | ui_out_text (uiout, "\nValue = "); | |
10674 | } | |
f99d8bf4 | 10675 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10676 | ui_out_field_stream (uiout, "new", stb); |
10677 | ui_out_text (uiout, "\n"); | |
10678 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10679 | break; |
10680 | default: | |
348d480f | 10681 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10682 | } |
10683 | ||
348d480f PA |
10684 | do_cleanups (old_chain); |
10685 | return result; | |
10686 | } | |
10687 | ||
10688 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10689 | watchpoints. */ | |
10690 | ||
10691 | static void | |
10692 | print_mention_watchpoint (struct breakpoint *b) | |
10693 | { | |
10694 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10695 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10696 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10697 | |
10698 | switch (b->type) | |
10699 | { | |
10700 | case bp_watchpoint: | |
10701 | ui_out_text (uiout, "Watchpoint "); | |
10702 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10703 | break; | |
10704 | case bp_hardware_watchpoint: | |
10705 | ui_out_text (uiout, "Hardware watchpoint "); | |
10706 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10707 | break; | |
10708 | case bp_read_watchpoint: | |
10709 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10710 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10711 | break; | |
10712 | case bp_access_watchpoint: | |
10713 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10714 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10715 | break; | |
10716 | default: | |
10717 | internal_error (__FILE__, __LINE__, | |
10718 | _("Invalid hardware watchpoint type.")); | |
10719 | } | |
10720 | ||
10721 | ui_out_field_int (uiout, "number", b->number); | |
10722 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10723 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10724 | do_cleanups (ui_out_chain); |
10725 | } | |
10726 | ||
10727 | /* Implement the "print_recreate" breakpoint_ops method for | |
10728 | watchpoints. */ | |
10729 | ||
10730 | static void | |
10731 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10732 | { | |
3a5c3e22 PA |
10733 | struct watchpoint *w = (struct watchpoint *) b; |
10734 | ||
348d480f PA |
10735 | switch (b->type) |
10736 | { | |
10737 | case bp_watchpoint: | |
10738 | case bp_hardware_watchpoint: | |
10739 | fprintf_unfiltered (fp, "watch"); | |
10740 | break; | |
10741 | case bp_read_watchpoint: | |
10742 | fprintf_unfiltered (fp, "rwatch"); | |
10743 | break; | |
10744 | case bp_access_watchpoint: | |
10745 | fprintf_unfiltered (fp, "awatch"); | |
10746 | break; | |
10747 | default: | |
10748 | internal_error (__FILE__, __LINE__, | |
10749 | _("Invalid watchpoint type.")); | |
10750 | } | |
10751 | ||
3a5c3e22 | 10752 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10753 | print_recreate_thread (b, fp); |
348d480f PA |
10754 | } |
10755 | ||
427cd150 TT |
10756 | /* Implement the "explains_signal" breakpoint_ops method for |
10757 | watchpoints. */ | |
10758 | ||
10759 | static enum bpstat_signal_value | |
10760 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) | |
10761 | { | |
10762 | /* A software watchpoint cannot cause a signal other than | |
10763 | GDB_SIGNAL_TRAP. */ | |
10764 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
10765 | return BPSTAT_SIGNAL_NO; | |
10766 | ||
10767 | return BPSTAT_SIGNAL_HIDE; | |
10768 | } | |
10769 | ||
348d480f PA |
10770 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10771 | ||
2060206e | 10772 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10773 | |
10774 | /* Implement the "insert" breakpoint_ops method for | |
10775 | masked hardware watchpoints. */ | |
10776 | ||
10777 | static int | |
10778 | insert_masked_watchpoint (struct bp_location *bl) | |
10779 | { | |
3a5c3e22 PA |
10780 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10781 | ||
10782 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10783 | bl->watchpoint_type); |
10784 | } | |
10785 | ||
10786 | /* Implement the "remove" breakpoint_ops method for | |
10787 | masked hardware watchpoints. */ | |
10788 | ||
10789 | static int | |
10790 | remove_masked_watchpoint (struct bp_location *bl) | |
10791 | { | |
3a5c3e22 PA |
10792 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10793 | ||
10794 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10795 | bl->watchpoint_type); |
10796 | } | |
10797 | ||
10798 | /* Implement the "resources_needed" breakpoint_ops method for | |
10799 | masked hardware watchpoints. */ | |
10800 | ||
10801 | static int | |
10802 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10803 | { | |
3a5c3e22 PA |
10804 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10805 | ||
10806 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10807 | } |
10808 | ||
10809 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10810 | masked hardware watchpoints. */ | |
10811 | ||
10812 | static int | |
10813 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10814 | { | |
10815 | return 0; | |
10816 | } | |
10817 | ||
10818 | /* Implement the "print_it" breakpoint_ops method for | |
10819 | masked hardware watchpoints. */ | |
10820 | ||
10821 | static enum print_stop_action | |
10822 | print_it_masked_watchpoint (bpstat bs) | |
10823 | { | |
10824 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10825 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10826 | |
10827 | /* Masked watchpoints have only one location. */ | |
10828 | gdb_assert (b->loc && b->loc->next == NULL); | |
10829 | ||
10830 | switch (b->type) | |
10831 | { | |
10832 | case bp_hardware_watchpoint: | |
10833 | annotate_watchpoint (b->number); | |
10834 | if (ui_out_is_mi_like_p (uiout)) | |
10835 | ui_out_field_string | |
10836 | (uiout, "reason", | |
10837 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10838 | break; | |
10839 | ||
10840 | case bp_read_watchpoint: | |
10841 | if (ui_out_is_mi_like_p (uiout)) | |
10842 | ui_out_field_string | |
10843 | (uiout, "reason", | |
10844 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10845 | break; | |
10846 | ||
10847 | case bp_access_watchpoint: | |
10848 | if (ui_out_is_mi_like_p (uiout)) | |
10849 | ui_out_field_string | |
10850 | (uiout, "reason", | |
10851 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10852 | break; | |
10853 | default: | |
10854 | internal_error (__FILE__, __LINE__, | |
10855 | _("Invalid hardware watchpoint type.")); | |
10856 | } | |
10857 | ||
10858 | mention (b); | |
9c06b0b4 TJB |
10859 | ui_out_text (uiout, _("\n\ |
10860 | Check the underlying instruction at PC for the memory\n\ | |
10861 | address and value which triggered this watchpoint.\n")); | |
10862 | ui_out_text (uiout, "\n"); | |
10863 | ||
10864 | /* More than one watchpoint may have been triggered. */ | |
10865 | return PRINT_UNKNOWN; | |
10866 | } | |
10867 | ||
10868 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10869 | masked hardware watchpoints. */ | |
10870 | ||
10871 | static void | |
10872 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10873 | struct ui_out *uiout) | |
10874 | { | |
3a5c3e22 PA |
10875 | struct watchpoint *w = (struct watchpoint *) b; |
10876 | ||
9c06b0b4 TJB |
10877 | /* Masked watchpoints have only one location. */ |
10878 | gdb_assert (b->loc && b->loc->next == NULL); | |
10879 | ||
10880 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10881 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10882 | ui_out_text (uiout, "\n"); |
10883 | } | |
10884 | ||
10885 | /* Implement the "print_mention" breakpoint_ops method for | |
10886 | masked hardware watchpoints. */ | |
10887 | ||
10888 | static void | |
10889 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10890 | { | |
3a5c3e22 | 10891 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10892 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10893 | struct cleanup *ui_out_chain; |
10894 | ||
10895 | switch (b->type) | |
10896 | { | |
10897 | case bp_hardware_watchpoint: | |
10898 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10899 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10900 | break; | |
10901 | case bp_read_watchpoint: | |
10902 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10903 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10904 | break; | |
10905 | case bp_access_watchpoint: | |
10906 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10907 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10908 | break; | |
10909 | default: | |
10910 | internal_error (__FILE__, __LINE__, | |
10911 | _("Invalid hardware watchpoint type.")); | |
10912 | } | |
10913 | ||
10914 | ui_out_field_int (uiout, "number", b->number); | |
10915 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10916 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10917 | do_cleanups (ui_out_chain); |
10918 | } | |
10919 | ||
10920 | /* Implement the "print_recreate" breakpoint_ops method for | |
10921 | masked hardware watchpoints. */ | |
10922 | ||
10923 | static void | |
10924 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10925 | { | |
3a5c3e22 | 10926 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10927 | char tmp[40]; |
10928 | ||
10929 | switch (b->type) | |
10930 | { | |
10931 | case bp_hardware_watchpoint: | |
10932 | fprintf_unfiltered (fp, "watch"); | |
10933 | break; | |
10934 | case bp_read_watchpoint: | |
10935 | fprintf_unfiltered (fp, "rwatch"); | |
10936 | break; | |
10937 | case bp_access_watchpoint: | |
10938 | fprintf_unfiltered (fp, "awatch"); | |
10939 | break; | |
10940 | default: | |
10941 | internal_error (__FILE__, __LINE__, | |
10942 | _("Invalid hardware watchpoint type.")); | |
10943 | } | |
10944 | ||
3a5c3e22 PA |
10945 | sprintf_vma (tmp, w->hw_wp_mask); |
10946 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10947 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10948 | } |
10949 | ||
10950 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10951 | ||
2060206e | 10952 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10953 | |
10954 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10955 | ||
10956 | static int | |
10957 | is_masked_watchpoint (const struct breakpoint *b) | |
10958 | { | |
10959 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10960 | } | |
10961 | ||
53a5351d JM |
10962 | /* accessflag: hw_write: watch write, |
10963 | hw_read: watch read, | |
10964 | hw_access: watch access (read or write) */ | |
c906108c | 10965 | static void |
bbc13ae3 | 10966 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10967 | int just_location, int internal) |
c906108c | 10968 | { |
a9634178 | 10969 | volatile struct gdb_exception e; |
d983da9c | 10970 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10971 | struct expression *exp; |
270140bd | 10972 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10973 | struct value *val, *mark, *result; |
c906108c | 10974 | struct frame_info *frame; |
bbc13ae3 KS |
10975 | const char *exp_start = NULL; |
10976 | const char *exp_end = NULL; | |
10977 | const char *tok, *end_tok; | |
9c06b0b4 | 10978 | int toklen = -1; |
bbc13ae3 KS |
10979 | const char *cond_start = NULL; |
10980 | const char *cond_end = NULL; | |
c906108c | 10981 | enum bptype bp_type; |
37e4754d | 10982 | int thread = -1; |
0cf6dd15 | 10983 | int pc = 0; |
9c06b0b4 TJB |
10984 | /* Flag to indicate whether we are going to use masks for |
10985 | the hardware watchpoint. */ | |
10986 | int use_mask = 0; | |
10987 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10988 | struct watchpoint *w; |
bbc13ae3 KS |
10989 | char *expression; |
10990 | struct cleanup *back_to; | |
c906108c | 10991 | |
37e4754d LM |
10992 | /* Make sure that we actually have parameters to parse. */ |
10993 | if (arg != NULL && arg[0] != '\0') | |
10994 | { | |
bbc13ae3 KS |
10995 | const char *value_start; |
10996 | ||
10997 | exp_end = arg + strlen (arg); | |
37e4754d | 10998 | |
9c06b0b4 TJB |
10999 | /* Look for "parameter value" pairs at the end |
11000 | of the arguments string. */ | |
bbc13ae3 | 11001 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11002 | { |
11003 | /* Skip whitespace at the end of the argument list. */ | |
11004 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11005 | tok--; | |
11006 | ||
11007 | /* Find the beginning of the last token. | |
11008 | This is the value of the parameter. */ | |
11009 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11010 | tok--; | |
11011 | value_start = tok + 1; | |
11012 | ||
11013 | /* Skip whitespace. */ | |
11014 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11015 | tok--; | |
11016 | ||
11017 | end_tok = tok; | |
11018 | ||
11019 | /* Find the beginning of the second to last token. | |
11020 | This is the parameter itself. */ | |
11021 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11022 | tok--; | |
11023 | tok++; | |
11024 | toklen = end_tok - tok + 1; | |
11025 | ||
11026 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11027 | { | |
11028 | /* At this point we've found a "thread" token, which means | |
11029 | the user is trying to set a watchpoint that triggers | |
11030 | only in a specific thread. */ | |
11031 | char *endp; | |
37e4754d | 11032 | |
9c06b0b4 TJB |
11033 | if (thread != -1) |
11034 | error(_("You can specify only one thread.")); | |
37e4754d | 11035 | |
9c06b0b4 TJB |
11036 | /* Extract the thread ID from the next token. */ |
11037 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11038 | |
9c06b0b4 TJB |
11039 | /* Check if the user provided a valid numeric value for the |
11040 | thread ID. */ | |
11041 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11042 | error (_("Invalid thread ID specification %s."), value_start); | |
11043 | ||
11044 | /* Check if the thread actually exists. */ | |
11045 | if (!valid_thread_id (thread)) | |
af4908ba | 11046 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11047 | } |
11048 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11049 | { | |
11050 | /* We've found a "mask" token, which means the user wants to | |
11051 | create a hardware watchpoint that is going to have the mask | |
11052 | facility. */ | |
11053 | struct value *mask_value, *mark; | |
37e4754d | 11054 | |
9c06b0b4 TJB |
11055 | if (use_mask) |
11056 | error(_("You can specify only one mask.")); | |
37e4754d | 11057 | |
9c06b0b4 | 11058 | use_mask = just_location = 1; |
37e4754d | 11059 | |
9c06b0b4 TJB |
11060 | mark = value_mark (); |
11061 | mask_value = parse_to_comma_and_eval (&value_start); | |
11062 | mask = value_as_address (mask_value); | |
11063 | value_free_to_mark (mark); | |
11064 | } | |
11065 | else | |
11066 | /* We didn't recognize what we found. We should stop here. */ | |
11067 | break; | |
37e4754d | 11068 | |
9c06b0b4 TJB |
11069 | /* Truncate the string and get rid of the "parameter value" pair before |
11070 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11071 | exp_end = tok; |
9c06b0b4 | 11072 | } |
37e4754d | 11073 | } |
bbc13ae3 KS |
11074 | else |
11075 | exp_end = arg; | |
37e4754d | 11076 | |
bbc13ae3 KS |
11077 | /* Parse the rest of the arguments. From here on out, everything |
11078 | is in terms of a newly allocated string instead of the original | |
11079 | ARG. */ | |
c906108c | 11080 | innermost_block = NULL; |
bbc13ae3 KS |
11081 | expression = savestring (arg, exp_end - arg); |
11082 | back_to = make_cleanup (xfree, expression); | |
11083 | exp_start = arg = expression; | |
1bb9788d | 11084 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11085 | exp_end = arg; |
fa8a61dc TT |
11086 | /* Remove trailing whitespace from the expression before saving it. |
11087 | This makes the eventual display of the expression string a bit | |
11088 | prettier. */ | |
11089 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11090 | --exp_end; | |
11091 | ||
65d79d4b SDJ |
11092 | /* Checking if the expression is not constant. */ |
11093 | if (watchpoint_exp_is_const (exp)) | |
11094 | { | |
11095 | int len; | |
11096 | ||
11097 | len = exp_end - exp_start; | |
11098 | while (len > 0 && isspace (exp_start[len - 1])) | |
11099 | len--; | |
11100 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11101 | } | |
11102 | ||
c906108c SS |
11103 | exp_valid_block = innermost_block; |
11104 | mark = value_mark (); | |
3a1115a0 | 11105 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11106 | |
11107 | if (just_location) | |
11108 | { | |
9c06b0b4 TJB |
11109 | int ret; |
11110 | ||
06a64a0b | 11111 | exp_valid_block = NULL; |
a1442452 | 11112 | val = value_addr (result); |
06a64a0b TT |
11113 | release_value (val); |
11114 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11115 | |
11116 | if (use_mask) | |
11117 | { | |
11118 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11119 | mask); | |
11120 | if (ret == -1) | |
11121 | error (_("This target does not support masked watchpoints.")); | |
11122 | else if (ret == -2) | |
11123 | error (_("Invalid mask or memory region.")); | |
11124 | } | |
06a64a0b TT |
11125 | } |
11126 | else if (val != NULL) | |
fa4727a6 | 11127 | release_value (val); |
c906108c | 11128 | |
bbc13ae3 KS |
11129 | tok = skip_spaces_const (arg); |
11130 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11131 | |
11132 | toklen = end_tok - tok; | |
11133 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11134 | { | |
2d134ed3 PA |
11135 | struct expression *cond; |
11136 | ||
60e1c644 | 11137 | innermost_block = NULL; |
c906108c | 11138 | tok = cond_start = end_tok + 1; |
1bb9788d | 11139 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11140 | |
11141 | /* The watchpoint expression may not be local, but the condition | |
11142 | may still be. E.g.: `watch global if local > 0'. */ | |
11143 | cond_exp_valid_block = innermost_block; | |
11144 | ||
2d134ed3 | 11145 | xfree (cond); |
c906108c SS |
11146 | cond_end = tok; |
11147 | } | |
11148 | if (*tok) | |
8a3fe4f8 | 11149 | error (_("Junk at end of command.")); |
c906108c | 11150 | |
d983da9c | 11151 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11152 | |
11153 | /* If the expression is "local", then set up a "watchpoint scope" | |
11154 | breakpoint at the point where we've left the scope of the watchpoint | |
11155 | expression. Create the scope breakpoint before the watchpoint, so | |
11156 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11157 | if (exp_valid_block && frame) |
d983da9c | 11158 | { |
edb3359d DJ |
11159 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11160 | { | |
11161 | scope_breakpoint | |
a6d9a66e UW |
11162 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11163 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11164 | bp_watchpoint_scope, |
11165 | &momentary_breakpoint_ops); | |
d983da9c | 11166 | |
edb3359d | 11167 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11168 | |
edb3359d DJ |
11169 | /* Automatically delete the breakpoint when it hits. */ |
11170 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11171 | |
edb3359d DJ |
11172 | /* Only break in the proper frame (help with recursion). */ |
11173 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11174 | |
edb3359d | 11175 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11176 | scope_breakpoint->loc->gdbarch |
11177 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11178 | scope_breakpoint->loc->requested_address |
11179 | = frame_unwind_caller_pc (frame); | |
11180 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11181 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11182 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11183 | scope_breakpoint->type); |
11184 | } | |
d983da9c DJ |
11185 | } |
11186 | ||
e8369a73 AB |
11187 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11188 | watchpoints here even if hardware watchpoints are turned off, a call | |
11189 | to update_watchpoint later in this function will cause the type to | |
11190 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11191 | ||
11192 | if (accessflag == hw_read) | |
11193 | bp_type = bp_read_watchpoint; | |
11194 | else if (accessflag == hw_access) | |
11195 | bp_type = bp_access_watchpoint; | |
11196 | else | |
11197 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11198 | |
11199 | w = XCNEW (struct watchpoint); | |
11200 | b = &w->base; | |
348d480f | 11201 | if (use_mask) |
3a5c3e22 PA |
11202 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11203 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11204 | else |
3a5c3e22 PA |
11205 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11206 | &watchpoint_breakpoint_ops); | |
37e4754d | 11207 | b->thread = thread; |
b5de0fa7 | 11208 | b->disposition = disp_donttouch; |
348d480f | 11209 | b->pspace = current_program_space; |
3a5c3e22 PA |
11210 | w->exp = exp; |
11211 | w->exp_valid_block = exp_valid_block; | |
11212 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11213 | if (just_location) |
11214 | { | |
11215 | struct type *t = value_type (val); | |
11216 | CORE_ADDR addr = value_as_address (val); | |
11217 | char *name; | |
11218 | ||
11219 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11220 | name = type_to_string (t); | |
11221 | ||
3a5c3e22 | 11222 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11223 | core_addr_to_string (addr)); |
06a64a0b TT |
11224 | xfree (name); |
11225 | ||
3a5c3e22 | 11226 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11227 | (int) (exp_end - exp_start), exp_start); |
11228 | ||
06a64a0b TT |
11229 | /* The above expression is in C. */ |
11230 | b->language = language_c; | |
11231 | } | |
11232 | else | |
3a5c3e22 | 11233 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11234 | |
11235 | if (use_mask) | |
11236 | { | |
3a5c3e22 | 11237 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11238 | } |
11239 | else | |
11240 | { | |
3a5c3e22 PA |
11241 | w->val = val; |
11242 | w->val_valid = 1; | |
9c06b0b4 | 11243 | } |
77b06cd7 | 11244 | |
c906108c SS |
11245 | if (cond_start) |
11246 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11247 | else | |
11248 | b->cond_string = 0; | |
c5aa993b | 11249 | |
c906108c | 11250 | if (frame) |
f6bc2008 | 11251 | { |
3a5c3e22 PA |
11252 | w->watchpoint_frame = get_frame_id (frame); |
11253 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11254 | } |
c906108c | 11255 | else |
f6bc2008 | 11256 | { |
3a5c3e22 PA |
11257 | w->watchpoint_frame = null_frame_id; |
11258 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11259 | } |
c906108c | 11260 | |
d983da9c | 11261 | if (scope_breakpoint != NULL) |
c906108c | 11262 | { |
d983da9c DJ |
11263 | /* The scope breakpoint is related to the watchpoint. We will |
11264 | need to act on them together. */ | |
11265 | b->related_breakpoint = scope_breakpoint; | |
11266 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11267 | } |
d983da9c | 11268 | |
06a64a0b TT |
11269 | if (!just_location) |
11270 | value_free_to_mark (mark); | |
2d134ed3 | 11271 | |
a9634178 TJB |
11272 | TRY_CATCH (e, RETURN_MASK_ALL) |
11273 | { | |
11274 | /* Finally update the new watchpoint. This creates the locations | |
11275 | that should be inserted. */ | |
3a5c3e22 | 11276 | update_watchpoint (w, 1); |
a9634178 TJB |
11277 | } |
11278 | if (e.reason < 0) | |
11279 | { | |
11280 | delete_breakpoint (b); | |
11281 | throw_exception (e); | |
11282 | } | |
11283 | ||
3ea46bff | 11284 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11285 | do_cleanups (back_to); |
c906108c SS |
11286 | } |
11287 | ||
e09342b5 | 11288 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11289 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11290 | |
c906108c | 11291 | static int |
a9634178 | 11292 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11293 | { |
11294 | int found_memory_cnt = 0; | |
2e70b7b9 | 11295 | struct value *head = v; |
c906108c SS |
11296 | |
11297 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11298 | if (!can_use_hw_watchpoints) |
c906108c | 11299 | return 0; |
c5aa993b | 11300 | |
5c44784c JM |
11301 | /* Make sure that the value of the expression depends only upon |
11302 | memory contents, and values computed from them within GDB. If we | |
11303 | find any register references or function calls, we can't use a | |
11304 | hardware watchpoint. | |
11305 | ||
11306 | The idea here is that evaluating an expression generates a series | |
11307 | of values, one holding the value of every subexpression. (The | |
11308 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11309 | a*b+c.) GDB's values hold almost enough information to establish | |
11310 | the criteria given above --- they identify memory lvalues, | |
11311 | register lvalues, computed values, etcetera. So we can evaluate | |
11312 | the expression, and then scan the chain of values that leaves | |
11313 | behind to decide whether we can detect any possible change to the | |
11314 | expression's final value using only hardware watchpoints. | |
11315 | ||
11316 | However, I don't think that the values returned by inferior | |
11317 | function calls are special in any way. So this function may not | |
11318 | notice that an expression involving an inferior function call | |
11319 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11320 | for (; v; v = value_next (v)) |
c906108c | 11321 | { |
5c44784c | 11322 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11323 | { |
8464be76 DJ |
11324 | if (v != head && value_lazy (v)) |
11325 | /* A lazy memory lvalue in the chain is one that GDB never | |
11326 | needed to fetch; we either just used its address (e.g., | |
11327 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11328 | in `a,b'). This doesn't apply to HEAD; if that is | |
11329 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11330 | ; |
53a5351d | 11331 | else |
5c44784c JM |
11332 | { |
11333 | /* Ahh, memory we actually used! Check if we can cover | |
11334 | it with hardware watchpoints. */ | |
df407dfe | 11335 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11336 | |
11337 | /* We only watch structs and arrays if user asked for it | |
11338 | explicitly, never if they just happen to appear in a | |
11339 | middle of some value chain. */ | |
11340 | if (v == head | |
11341 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11342 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11343 | { | |
42ae5230 | 11344 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11345 | int len; |
11346 | int num_regs; | |
11347 | ||
a9634178 | 11348 | len = (target_exact_watchpoints |
e09342b5 TJB |
11349 | && is_scalar_type_recursive (vtype))? |
11350 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11351 | |
e09342b5 TJB |
11352 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11353 | if (!num_regs) | |
2e70b7b9 MS |
11354 | return 0; |
11355 | else | |
e09342b5 | 11356 | found_memory_cnt += num_regs; |
2e70b7b9 | 11357 | } |
5c44784c | 11358 | } |
c5aa993b | 11359 | } |
5086187c AC |
11360 | else if (VALUE_LVAL (v) != not_lval |
11361 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11362 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11363 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11364 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11365 | } |
11366 | ||
11367 | /* The expression itself looks suitable for using a hardware | |
11368 | watchpoint, but give the target machine a chance to reject it. */ | |
11369 | return found_memory_cnt; | |
11370 | } | |
11371 | ||
8b93c638 | 11372 | void |
84f4c1fe | 11373 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11374 | { |
84f4c1fe | 11375 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11376 | } |
11377 | ||
06a64a0b TT |
11378 | /* A helper function that looks for the "-location" argument and then |
11379 | calls watch_command_1. */ | |
11380 | ||
11381 | static void | |
11382 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11383 | { | |
11384 | int just_location = 0; | |
11385 | ||
11386 | if (arg | |
11387 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11388 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11389 | { | |
e9cafbcc | 11390 | arg = skip_spaces (arg); |
06a64a0b TT |
11391 | just_location = 1; |
11392 | } | |
11393 | ||
84f4c1fe | 11394 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11395 | } |
8926118c | 11396 | |
c5aa993b | 11397 | static void |
fba45db2 | 11398 | watch_command (char *arg, int from_tty) |
c906108c | 11399 | { |
06a64a0b | 11400 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11401 | } |
11402 | ||
8b93c638 | 11403 | void |
84f4c1fe | 11404 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11405 | { |
84f4c1fe | 11406 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11407 | } |
8926118c | 11408 | |
c5aa993b | 11409 | static void |
fba45db2 | 11410 | rwatch_command (char *arg, int from_tty) |
c906108c | 11411 | { |
06a64a0b | 11412 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11413 | } |
11414 | ||
8b93c638 | 11415 | void |
84f4c1fe | 11416 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11417 | { |
84f4c1fe | 11418 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11419 | } |
8926118c | 11420 | |
c5aa993b | 11421 | static void |
fba45db2 | 11422 | awatch_command (char *arg, int from_tty) |
c906108c | 11423 | { |
06a64a0b | 11424 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11425 | } |
c906108c | 11426 | \f |
c5aa993b | 11427 | |
43ff13b4 | 11428 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11429 | because it uses the mechanisms of breakpoints. */ |
11430 | ||
bfec99b2 PA |
11431 | struct until_break_command_continuation_args |
11432 | { | |
11433 | struct breakpoint *breakpoint; | |
11434 | struct breakpoint *breakpoint2; | |
186c406b | 11435 | int thread_num; |
bfec99b2 PA |
11436 | }; |
11437 | ||
43ff13b4 | 11438 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11439 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11440 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11441 | command. */ |
c2c6d25f | 11442 | static void |
fa4cd53f | 11443 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11444 | { |
bfec99b2 PA |
11445 | struct until_break_command_continuation_args *a = arg; |
11446 | ||
11447 | delete_breakpoint (a->breakpoint); | |
11448 | if (a->breakpoint2) | |
11449 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11450 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11451 | } |
11452 | ||
c906108c | 11453 | void |
ae66c1fc | 11454 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11455 | { |
11456 | struct symtabs_and_lines sals; | |
11457 | struct symtab_and_line sal; | |
8556afb4 PA |
11458 | struct frame_info *frame; |
11459 | struct gdbarch *frame_gdbarch; | |
11460 | struct frame_id stack_frame_id; | |
11461 | struct frame_id caller_frame_id; | |
c906108c | 11462 | struct breakpoint *breakpoint; |
f107f563 | 11463 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11464 | struct cleanup *old_chain; |
186c406b TT |
11465 | int thread; |
11466 | struct thread_info *tp; | |
c906108c SS |
11467 | |
11468 | clear_proceed_status (); | |
11469 | ||
11470 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11471 | this function. */ |
c5aa993b | 11472 | |
1bfeeb0f | 11473 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11474 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11475 | get_last_displayed_symtab (), |
f8eba3c6 | 11476 | get_last_displayed_line ()); |
c906108c | 11477 | else |
f8eba3c6 TT |
11478 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11479 | (struct symtab *) NULL, 0); | |
c5aa993b | 11480 | |
c906108c | 11481 | if (sals.nelts != 1) |
8a3fe4f8 | 11482 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11483 | |
c906108c | 11484 | sal = sals.sals[0]; |
4a64f543 | 11485 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11486 | |
c906108c | 11487 | if (*arg) |
8a3fe4f8 | 11488 | error (_("Junk at end of arguments.")); |
c5aa993b | 11489 | |
c906108c | 11490 | resolve_sal_pc (&sal); |
c5aa993b | 11491 | |
186c406b TT |
11492 | tp = inferior_thread (); |
11493 | thread = tp->num; | |
11494 | ||
883bc8d1 PA |
11495 | old_chain = make_cleanup (null_cleanup, NULL); |
11496 | ||
8556afb4 PA |
11497 | /* Note linespec handling above invalidates the frame chain. |
11498 | Installing a breakpoint also invalidates the frame chain (as it | |
11499 | may need to switch threads), so do any frame handling before | |
11500 | that. */ | |
11501 | ||
11502 | frame = get_selected_frame (NULL); | |
11503 | frame_gdbarch = get_frame_arch (frame); | |
11504 | stack_frame_id = get_stack_frame_id (frame); | |
11505 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11506 | |
ae66c1fc EZ |
11507 | /* Keep within the current frame, or in frames called by the current |
11508 | one. */ | |
edb3359d | 11509 | |
883bc8d1 | 11510 | if (frame_id_p (caller_frame_id)) |
c906108c | 11511 | { |
883bc8d1 PA |
11512 | struct symtab_and_line sal2; |
11513 | ||
11514 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11515 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11516 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11517 | sal2, |
11518 | caller_frame_id, | |
f107f563 VP |
11519 | bp_until); |
11520 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11521 | |
883bc8d1 | 11522 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11523 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11524 | } |
c5aa993b | 11525 | |
c70a6932 JK |
11526 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11527 | frame = NULL; | |
11528 | ||
883bc8d1 PA |
11529 | if (anywhere) |
11530 | /* If the user told us to continue until a specified location, | |
11531 | we don't specify a frame at which we need to stop. */ | |
11532 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11533 | null_frame_id, bp_until); | |
11534 | else | |
11535 | /* Otherwise, specify the selected frame, because we want to stop | |
11536 | only at the very same frame. */ | |
11537 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11538 | stack_frame_id, bp_until); | |
11539 | make_cleanup_delete_breakpoint (breakpoint); | |
11540 | ||
a493e3e2 | 11541 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11542 | |
4a64f543 MS |
11543 | /* If we are running asynchronously, and proceed call above has |
11544 | actually managed to start the target, arrange for breakpoints to | |
11545 | be deleted when the target stops. Otherwise, we're already | |
11546 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11547 | |
8ea051c5 | 11548 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11549 | { |
bfec99b2 PA |
11550 | struct until_break_command_continuation_args *args; |
11551 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11552 | |
bfec99b2 PA |
11553 | args->breakpoint = breakpoint; |
11554 | args->breakpoint2 = breakpoint2; | |
186c406b | 11555 | args->thread_num = thread; |
f107f563 VP |
11556 | |
11557 | discard_cleanups (old_chain); | |
95e54da7 PA |
11558 | add_continuation (inferior_thread (), |
11559 | until_break_command_continuation, args, | |
604ead4a | 11560 | xfree); |
f107f563 VP |
11561 | } |
11562 | else | |
c5aa993b | 11563 | do_cleanups (old_chain); |
c906108c | 11564 | } |
ae66c1fc | 11565 | |
c906108c SS |
11566 | /* This function attempts to parse an optional "if <cond>" clause |
11567 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11568 | |
c906108c SS |
11569 | Else, it returns a pointer to the condition string. (It does not |
11570 | attempt to evaluate the string against a particular block.) And, | |
11571 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11572 | if clause in the arg string. */ |
53a5351d | 11573 | |
916703c0 | 11574 | char * |
fba45db2 | 11575 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11576 | { |
c5aa993b JM |
11577 | char *cond_string; |
11578 | ||
11579 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11580 | return NULL; |
c5aa993b | 11581 | |
4a64f543 | 11582 | /* Skip the "if" keyword. */ |
c906108c | 11583 | (*arg) += 2; |
c5aa993b | 11584 | |
c906108c | 11585 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11586 | condition string. */ |
e9cafbcc | 11587 | *arg = skip_spaces (*arg); |
c906108c | 11588 | cond_string = *arg; |
c5aa993b | 11589 | |
4a64f543 MS |
11590 | /* Assume that the condition occupies the remainder of the arg |
11591 | string. */ | |
c906108c | 11592 | (*arg) += strlen (cond_string); |
c5aa993b | 11593 | |
c906108c SS |
11594 | return cond_string; |
11595 | } | |
c5aa993b | 11596 | |
c906108c SS |
11597 | /* Commands to deal with catching events, such as signals, exceptions, |
11598 | process start/exit, etc. */ | |
c5aa993b JM |
11599 | |
11600 | typedef enum | |
11601 | { | |
44feb3ce TT |
11602 | catch_fork_temporary, catch_vfork_temporary, |
11603 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11604 | } |
11605 | catch_fork_kind; | |
11606 | ||
c906108c | 11607 | static void |
cc59ec59 MS |
11608 | catch_fork_command_1 (char *arg, int from_tty, |
11609 | struct cmd_list_element *command) | |
c906108c | 11610 | { |
a6d9a66e | 11611 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11612 | char *cond_string = NULL; |
44feb3ce TT |
11613 | catch_fork_kind fork_kind; |
11614 | int tempflag; | |
11615 | ||
11616 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11617 | tempflag = (fork_kind == catch_fork_temporary | |
11618 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11619 | |
44feb3ce TT |
11620 | if (!arg) |
11621 | arg = ""; | |
e9cafbcc | 11622 | arg = skip_spaces (arg); |
c5aa993b | 11623 | |
c906108c | 11624 | /* The allowed syntax is: |
c5aa993b JM |
11625 | catch [v]fork |
11626 | catch [v]fork if <cond> | |
11627 | ||
4a64f543 | 11628 | First, check if there's an if clause. */ |
c906108c | 11629 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11630 | |
c906108c | 11631 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11632 | error (_("Junk at end of arguments.")); |
c5aa993b | 11633 | |
c906108c | 11634 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11635 | and enable reporting of such events. */ |
c5aa993b JM |
11636 | switch (fork_kind) |
11637 | { | |
44feb3ce TT |
11638 | case catch_fork_temporary: |
11639 | case catch_fork_permanent: | |
a6d9a66e | 11640 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11641 | &catch_fork_breakpoint_ops); |
c906108c | 11642 | break; |
44feb3ce TT |
11643 | case catch_vfork_temporary: |
11644 | case catch_vfork_permanent: | |
a6d9a66e | 11645 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11646 | &catch_vfork_breakpoint_ops); |
c906108c | 11647 | break; |
c5aa993b | 11648 | default: |
8a3fe4f8 | 11649 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11650 | break; |
c5aa993b | 11651 | } |
c906108c SS |
11652 | } |
11653 | ||
11654 | static void | |
cc59ec59 MS |
11655 | catch_exec_command_1 (char *arg, int from_tty, |
11656 | struct cmd_list_element *command) | |
c906108c | 11657 | { |
b4d90040 | 11658 | struct exec_catchpoint *c; |
a6d9a66e | 11659 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11660 | int tempflag; |
c5aa993b | 11661 | char *cond_string = NULL; |
c906108c | 11662 | |
44feb3ce TT |
11663 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11664 | ||
11665 | if (!arg) | |
11666 | arg = ""; | |
e9cafbcc | 11667 | arg = skip_spaces (arg); |
c906108c SS |
11668 | |
11669 | /* The allowed syntax is: | |
c5aa993b JM |
11670 | catch exec |
11671 | catch exec if <cond> | |
c906108c | 11672 | |
4a64f543 | 11673 | First, check if there's an if clause. */ |
c906108c SS |
11674 | cond_string = ep_parse_optional_if_clause (&arg); |
11675 | ||
11676 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11677 | error (_("Junk at end of arguments.")); |
c906108c | 11678 | |
b4d90040 PA |
11679 | c = XNEW (struct exec_catchpoint); |
11680 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11681 | &catch_exec_breakpoint_ops); | |
11682 | c->exec_pathname = NULL; | |
11683 | ||
3ea46bff | 11684 | install_breakpoint (0, &c->base, 1); |
c906108c | 11685 | } |
c5aa993b | 11686 | |
9ac4176b | 11687 | void |
28010a5d PA |
11688 | init_ada_exception_breakpoint (struct breakpoint *b, |
11689 | struct gdbarch *gdbarch, | |
11690 | struct symtab_and_line sal, | |
11691 | char *addr_string, | |
c0a91b2b | 11692 | const struct breakpoint_ops *ops, |
28010a5d | 11693 | int tempflag, |
349774ef | 11694 | int enabled, |
28010a5d | 11695 | int from_tty) |
f7f9143b | 11696 | { |
f7f9143b JB |
11697 | if (from_tty) |
11698 | { | |
5af949e3 UW |
11699 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11700 | if (!loc_gdbarch) | |
11701 | loc_gdbarch = gdbarch; | |
11702 | ||
6c95b8df PA |
11703 | describe_other_breakpoints (loc_gdbarch, |
11704 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11705 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11706 | version for exception catchpoints, because two catchpoints | |
11707 | used for different exception names will use the same address. | |
11708 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11709 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11710 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11711 | the user what type of catchpoint it is. The above is good |
11712 | enough for now, though. */ | |
11713 | } | |
11714 | ||
28010a5d | 11715 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11716 | |
349774ef | 11717 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11718 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11719 | b->addr_string = addr_string; |
11720 | b->language = language_ada; | |
f7f9143b JB |
11721 | } |
11722 | ||
a96d9b2e SDJ |
11723 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11724 | filter list, or NULL if no filtering is required. */ | |
11725 | static VEC(int) * | |
11726 | catch_syscall_split_args (char *arg) | |
11727 | { | |
11728 | VEC(int) *result = NULL; | |
29d0bb3d | 11729 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11730 | |
11731 | while (*arg != '\0') | |
11732 | { | |
11733 | int i, syscall_number; | |
11734 | char *endptr; | |
11735 | char cur_name[128]; | |
11736 | struct syscall s; | |
11737 | ||
11738 | /* Skip whitespace. */ | |
529480d0 | 11739 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11740 | |
11741 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11742 | cur_name[i] = arg[i]; | |
11743 | cur_name[i] = '\0'; | |
11744 | arg += i; | |
11745 | ||
11746 | /* Check if the user provided a syscall name or a number. */ | |
11747 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11748 | if (*endptr == '\0') | |
bccd0dd2 | 11749 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11750 | else |
11751 | { | |
11752 | /* We have a name. Let's check if it's valid and convert it | |
11753 | to a number. */ | |
11754 | get_syscall_by_name (cur_name, &s); | |
11755 | ||
11756 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11757 | /* Here we have to issue an error instead of a warning, |
11758 | because GDB cannot do anything useful if there's no | |
11759 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11760 | error (_("Unknown syscall name '%s'."), cur_name); |
11761 | } | |
11762 | ||
11763 | /* Ok, it's valid. */ | |
11764 | VEC_safe_push (int, result, s.number); | |
11765 | } | |
11766 | ||
11767 | discard_cleanups (cleanup); | |
11768 | return result; | |
11769 | } | |
11770 | ||
11771 | /* Implement the "catch syscall" command. */ | |
11772 | ||
11773 | static void | |
cc59ec59 MS |
11774 | catch_syscall_command_1 (char *arg, int from_tty, |
11775 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11776 | { |
11777 | int tempflag; | |
11778 | VEC(int) *filter; | |
11779 | struct syscall s; | |
11780 | struct gdbarch *gdbarch = get_current_arch (); | |
11781 | ||
11782 | /* Checking if the feature if supported. */ | |
11783 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11784 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11785 | this architecture yet.")); |
a96d9b2e SDJ |
11786 | |
11787 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11788 | ||
e9cafbcc | 11789 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11790 | |
11791 | /* We need to do this first "dummy" translation in order | |
11792 | to get the syscall XML file loaded or, most important, | |
11793 | to display a warning to the user if there's no XML file | |
11794 | for his/her architecture. */ | |
11795 | get_syscall_by_number (0, &s); | |
11796 | ||
11797 | /* The allowed syntax is: | |
11798 | catch syscall | |
11799 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11800 | ||
11801 | Let's check if there's a syscall name. */ | |
11802 | ||
11803 | if (arg != NULL) | |
11804 | filter = catch_syscall_split_args (arg); | |
11805 | else | |
11806 | filter = NULL; | |
11807 | ||
11808 | create_syscall_event_catchpoint (tempflag, filter, | |
11809 | &catch_syscall_breakpoint_ops); | |
11810 | } | |
11811 | ||
c906108c | 11812 | static void |
fba45db2 | 11813 | catch_command (char *arg, int from_tty) |
c906108c | 11814 | { |
44feb3ce | 11815 | error (_("Catch requires an event name.")); |
c906108c SS |
11816 | } |
11817 | \f | |
11818 | ||
11819 | static void | |
fba45db2 | 11820 | tcatch_command (char *arg, int from_tty) |
c906108c | 11821 | { |
44feb3ce | 11822 | error (_("Catch requires an event name.")); |
c906108c SS |
11823 | } |
11824 | ||
8a2c437b TT |
11825 | /* A qsort comparison function that sorts breakpoints in order. */ |
11826 | ||
11827 | static int | |
11828 | compare_breakpoints (const void *a, const void *b) | |
11829 | { | |
11830 | const breakpoint_p *ba = a; | |
11831 | uintptr_t ua = (uintptr_t) *ba; | |
11832 | const breakpoint_p *bb = b; | |
11833 | uintptr_t ub = (uintptr_t) *bb; | |
11834 | ||
11835 | if ((*ba)->number < (*bb)->number) | |
11836 | return -1; | |
11837 | else if ((*ba)->number > (*bb)->number) | |
11838 | return 1; | |
11839 | ||
11840 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11841 | the number 0. */ | |
11842 | if (ua < ub) | |
11843 | return -1; | |
94b0e70d | 11844 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11845 | } |
11846 | ||
80f8a6eb | 11847 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11848 | |
11849 | static void | |
fba45db2 | 11850 | clear_command (char *arg, int from_tty) |
c906108c | 11851 | { |
8a2c437b | 11852 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11853 | VEC(breakpoint_p) *found = 0; |
11854 | int ix; | |
c906108c SS |
11855 | int default_match; |
11856 | struct symtabs_and_lines sals; | |
11857 | struct symtab_and_line sal; | |
c906108c | 11858 | int i; |
8a2c437b | 11859 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11860 | |
11861 | if (arg) | |
11862 | { | |
39cf75f7 DE |
11863 | sals = decode_line_with_current_source (arg, |
11864 | (DECODE_LINE_FUNFIRSTLINE | |
11865 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11866 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11867 | default_match = 0; |
11868 | } | |
11869 | else | |
11870 | { | |
c5aa993b | 11871 | sals.sals = (struct symtab_and_line *) |
c906108c | 11872 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11873 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11874 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11875 | |
11876 | /* Set sal's line, symtab, pc, and pspace to the values | |
11877 | corresponding to the last call to print_frame_info. If the | |
11878 | codepoint is not valid, this will set all the fields to 0. */ | |
11879 | get_last_displayed_sal (&sal); | |
c906108c | 11880 | if (sal.symtab == 0) |
8a3fe4f8 | 11881 | error (_("No source file specified.")); |
c906108c SS |
11882 | |
11883 | sals.sals[0] = sal; | |
11884 | sals.nelts = 1; | |
11885 | ||
11886 | default_match = 1; | |
11887 | } | |
11888 | ||
4a64f543 MS |
11889 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11890 | seems, because all existing breakpoints typically have both | |
11891 | file/line and pc set. So, if clear is given file/line, we can | |
11892 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11893 | |
11894 | We only support clearing given the address explicitly | |
11895 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11896 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11897 | due to optimization, all in one block. |
4a64f543 MS |
11898 | |
11899 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11900 | PC corresponding to the same file:line, the breakpoint won't |
11901 | be cleared. We probably can still clear the breakpoint, but | |
11902 | since the other PC value is never presented to user, user | |
11903 | can only find it by guessing, and it does not seem important | |
11904 | to support that. */ | |
11905 | ||
4a64f543 MS |
11906 | /* For each line spec given, delete bps which correspond to it. Do |
11907 | it in two passes, solely to preserve the current behavior that | |
11908 | from_tty is forced true if we delete more than one | |
11909 | breakpoint. */ | |
c906108c | 11910 | |
80f8a6eb | 11911 | found = NULL; |
8a2c437b | 11912 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11913 | for (i = 0; i < sals.nelts; i++) |
11914 | { | |
05cba821 JK |
11915 | const char *sal_fullname; |
11916 | ||
c906108c | 11917 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11918 | If line given (pc == 0), clear all bpts on specified line. |
11919 | If defaulting, clear all bpts on default line | |
c906108c | 11920 | or at default pc. |
c5aa993b JM |
11921 | |
11922 | defaulting sal.pc != 0 tests to do | |
11923 | ||
11924 | 0 1 pc | |
11925 | 1 1 pc _and_ line | |
11926 | 0 0 line | |
11927 | 1 0 <can't happen> */ | |
c906108c SS |
11928 | |
11929 | sal = sals.sals[i]; | |
05cba821 JK |
11930 | sal_fullname = (sal.symtab == NULL |
11931 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11932 | |
4a64f543 | 11933 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11934 | ALL_BREAKPOINTS (b) |
c5aa993b | 11935 | { |
0d381245 | 11936 | int match = 0; |
4a64f543 | 11937 | /* Are we going to delete b? */ |
cc60f2e3 | 11938 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11939 | { |
11940 | struct bp_location *loc = b->loc; | |
11941 | for (; loc; loc = loc->next) | |
11942 | { | |
f8eba3c6 TT |
11943 | /* If the user specified file:line, don't allow a PC |
11944 | match. This matches historical gdb behavior. */ | |
11945 | int pc_match = (!sal.explicit_line | |
11946 | && sal.pc | |
11947 | && (loc->pspace == sal.pspace) | |
11948 | && (loc->address == sal.pc) | |
11949 | && (!section_is_overlay (loc->section) | |
11950 | || loc->section == sal.section)); | |
4aac40c8 TT |
11951 | int line_match = 0; |
11952 | ||
11953 | if ((default_match || sal.explicit_line) | |
2f202fde | 11954 | && loc->symtab != NULL |
05cba821 | 11955 | && sal_fullname != NULL |
4aac40c8 | 11956 | && sal.pspace == loc->pspace |
05cba821 JK |
11957 | && loc->line_number == sal.line |
11958 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11959 | sal_fullname) == 0) | |
11960 | line_match = 1; | |
4aac40c8 | 11961 | |
0d381245 VP |
11962 | if (pc_match || line_match) |
11963 | { | |
11964 | match = 1; | |
11965 | break; | |
11966 | } | |
11967 | } | |
11968 | } | |
11969 | ||
11970 | if (match) | |
d6e956e5 | 11971 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11972 | } |
80f8a6eb | 11973 | } |
8a2c437b | 11974 | |
80f8a6eb | 11975 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11976 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11977 | { |
11978 | if (arg) | |
8a3fe4f8 | 11979 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11980 | else |
8a3fe4f8 | 11981 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11982 | } |
c906108c | 11983 | |
8a2c437b TT |
11984 | /* Remove duplicates from the vec. */ |
11985 | qsort (VEC_address (breakpoint_p, found), | |
11986 | VEC_length (breakpoint_p, found), | |
11987 | sizeof (breakpoint_p), | |
11988 | compare_breakpoints); | |
11989 | prev = VEC_index (breakpoint_p, found, 0); | |
11990 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11991 | { | |
11992 | if (b == prev) | |
11993 | { | |
11994 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11995 | --ix; | |
11996 | } | |
11997 | } | |
11998 | ||
d6e956e5 | 11999 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12000 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12001 | if (from_tty) |
a3f17187 | 12002 | { |
d6e956e5 | 12003 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12004 | printf_unfiltered (_("Deleted breakpoint ")); |
12005 | else | |
12006 | printf_unfiltered (_("Deleted breakpoints ")); | |
12007 | } | |
d6e956e5 VP |
12008 | |
12009 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12010 | { |
c5aa993b | 12011 | if (from_tty) |
d6e956e5 VP |
12012 | printf_unfiltered ("%d ", b->number); |
12013 | delete_breakpoint (b); | |
c906108c | 12014 | } |
80f8a6eb MS |
12015 | if (from_tty) |
12016 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12017 | |
12018 | do_cleanups (cleanups); | |
c906108c SS |
12019 | } |
12020 | \f | |
12021 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12022 | all breakpoints that are marked for deletion, whether hit or not. | |
12023 | This is called after any breakpoint is hit, or after errors. */ | |
12024 | ||
12025 | void | |
fba45db2 | 12026 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12027 | { |
35df4500 | 12028 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12029 | |
12030 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12031 | if (bs->breakpoint_at |
12032 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12033 | && bs->stop) |
f431efe5 | 12034 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12035 | |
35df4500 | 12036 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12037 | { |
b5de0fa7 | 12038 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12039 | delete_breakpoint (b); |
12040 | } | |
c906108c SS |
12041 | } |
12042 | ||
4a64f543 MS |
12043 | /* A comparison function for bp_location AP and BP being interfaced to |
12044 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12045 | does breakpoint_address_is_meaningful say for its OWNER), | |
12046 | secondarily by ordering first bp_permanent OWNERed elements and | |
12047 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12048 | qsort being an unstable algorithm. */ |
876fa593 JK |
12049 | |
12050 | static int | |
494cfb0f | 12051 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12052 | { |
494cfb0f JK |
12053 | struct bp_location *a = *(void **) ap; |
12054 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12055 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12056 | int a_perm = a->owner->enable_state == bp_permanent; |
12057 | int b_perm = b->owner->enable_state == bp_permanent; | |
12058 | ||
12059 | if (a->address != b->address) | |
12060 | return (a->address > b->address) - (a->address < b->address); | |
12061 | ||
dea2aa5f LM |
12062 | /* Sort locations at the same address by their pspace number, keeping |
12063 | locations of the same inferior (in a multi-inferior environment) | |
12064 | grouped. */ | |
12065 | ||
12066 | if (a->pspace->num != b->pspace->num) | |
12067 | return ((a->pspace->num > b->pspace->num) | |
12068 | - (a->pspace->num < b->pspace->num)); | |
12069 | ||
876fa593 JK |
12070 | /* Sort permanent breakpoints first. */ |
12071 | if (a_perm != b_perm) | |
12072 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12073 | ||
c56a97f9 JK |
12074 | /* Make the internal GDB representation stable across GDB runs |
12075 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12076 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12077 | |
12078 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12079 | return ((a->owner->number > b->owner->number) |
12080 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12081 | |
12082 | return (a > b) - (a < b); | |
12083 | } | |
12084 | ||
876fa593 | 12085 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12086 | bp_location_shadow_len_after_address_max according to the current |
12087 | content of the bp_location array. */ | |
f7545552 TT |
12088 | |
12089 | static void | |
876fa593 | 12090 | bp_location_target_extensions_update (void) |
f7545552 | 12091 | { |
876fa593 JK |
12092 | struct bp_location *bl, **blp_tmp; |
12093 | ||
12094 | bp_location_placed_address_before_address_max = 0; | |
12095 | bp_location_shadow_len_after_address_max = 0; | |
12096 | ||
12097 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12098 | { | |
12099 | CORE_ADDR start, end, addr; | |
12100 | ||
12101 | if (!bp_location_has_shadow (bl)) | |
12102 | continue; | |
12103 | ||
12104 | start = bl->target_info.placed_address; | |
12105 | end = start + bl->target_info.shadow_len; | |
12106 | ||
12107 | gdb_assert (bl->address >= start); | |
12108 | addr = bl->address - start; | |
12109 | if (addr > bp_location_placed_address_before_address_max) | |
12110 | bp_location_placed_address_before_address_max = addr; | |
12111 | ||
12112 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12113 | ||
12114 | gdb_assert (bl->address < end); | |
12115 | addr = end - bl->address; | |
12116 | if (addr > bp_location_shadow_len_after_address_max) | |
12117 | bp_location_shadow_len_after_address_max = addr; | |
12118 | } | |
f7545552 TT |
12119 | } |
12120 | ||
1e4d1764 YQ |
12121 | /* Download tracepoint locations if they haven't been. */ |
12122 | ||
12123 | static void | |
12124 | download_tracepoint_locations (void) | |
12125 | { | |
7ed2c994 | 12126 | struct breakpoint *b; |
1e4d1764 YQ |
12127 | struct cleanup *old_chain; |
12128 | ||
12129 | if (!target_can_download_tracepoint ()) | |
12130 | return; | |
12131 | ||
12132 | old_chain = save_current_space_and_thread (); | |
12133 | ||
7ed2c994 | 12134 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12135 | { |
7ed2c994 | 12136 | struct bp_location *bl; |
1e4d1764 | 12137 | struct tracepoint *t; |
f2a8bc8a | 12138 | int bp_location_downloaded = 0; |
1e4d1764 | 12139 | |
7ed2c994 | 12140 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12141 | ? !may_insert_fast_tracepoints |
12142 | : !may_insert_tracepoints)) | |
12143 | continue; | |
12144 | ||
7ed2c994 YQ |
12145 | for (bl = b->loc; bl; bl = bl->next) |
12146 | { | |
12147 | /* In tracepoint, locations are _never_ duplicated, so | |
12148 | should_be_inserted is equivalent to | |
12149 | unduplicated_should_be_inserted. */ | |
12150 | if (!should_be_inserted (bl) || bl->inserted) | |
12151 | continue; | |
1e4d1764 | 12152 | |
7ed2c994 | 12153 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12154 | |
7ed2c994 | 12155 | target_download_tracepoint (bl); |
1e4d1764 | 12156 | |
7ed2c994 | 12157 | bl->inserted = 1; |
f2a8bc8a | 12158 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12159 | } |
12160 | t = (struct tracepoint *) b; | |
12161 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12162 | if (bp_location_downloaded) |
12163 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12164 | } |
12165 | ||
12166 | do_cleanups (old_chain); | |
12167 | } | |
12168 | ||
934709f0 PW |
12169 | /* Swap the insertion/duplication state between two locations. */ |
12170 | ||
12171 | static void | |
12172 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12173 | { | |
12174 | const int left_inserted = left->inserted; | |
12175 | const int left_duplicate = left->duplicate; | |
b775012e | 12176 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12177 | const struct bp_target_info left_target_info = left->target_info; |
12178 | ||
1e4d1764 YQ |
12179 | /* Locations of tracepoints can never be duplicated. */ |
12180 | if (is_tracepoint (left->owner)) | |
12181 | gdb_assert (!left->duplicate); | |
12182 | if (is_tracepoint (right->owner)) | |
12183 | gdb_assert (!right->duplicate); | |
12184 | ||
934709f0 PW |
12185 | left->inserted = right->inserted; |
12186 | left->duplicate = right->duplicate; | |
b775012e | 12187 | left->needs_update = right->needs_update; |
934709f0 PW |
12188 | left->target_info = right->target_info; |
12189 | right->inserted = left_inserted; | |
12190 | right->duplicate = left_duplicate; | |
b775012e | 12191 | right->needs_update = left_needs_update; |
934709f0 PW |
12192 | right->target_info = left_target_info; |
12193 | } | |
12194 | ||
b775012e LM |
12195 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12196 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12197 | conditions on the target's side. Such conditions need to be updated on | |
12198 | the target. */ | |
12199 | ||
12200 | static void | |
12201 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12202 | { | |
12203 | struct bp_location **locp = NULL, **loc2p; | |
12204 | struct bp_location *loc; | |
12205 | CORE_ADDR address = 0; | |
12206 | int pspace_num; | |
12207 | ||
12208 | address = bl->address; | |
12209 | pspace_num = bl->pspace->num; | |
12210 | ||
12211 | /* This is only meaningful if the target is | |
12212 | evaluating conditions and if the user has | |
12213 | opted for condition evaluation on the target's | |
12214 | side. */ | |
12215 | if (gdb_evaluates_breakpoint_condition_p () | |
12216 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12217 | return; | |
12218 | ||
12219 | /* Flag all breakpoint locations with this address and | |
12220 | the same program space as the location | |
12221 | as "its condition has changed". We need to | |
12222 | update the conditions on the target's side. */ | |
12223 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12224 | { | |
12225 | loc = *loc2p; | |
12226 | ||
12227 | if (!is_breakpoint (loc->owner) | |
12228 | || pspace_num != loc->pspace->num) | |
12229 | continue; | |
12230 | ||
12231 | /* Flag the location appropriately. We use a different state to | |
12232 | let everyone know that we already updated the set of locations | |
12233 | with addr bl->address and program space bl->pspace. This is so | |
12234 | we don't have to keep calling these functions just to mark locations | |
12235 | that have already been marked. */ | |
12236 | loc->condition_changed = condition_updated; | |
12237 | ||
12238 | /* Free the agent expression bytecode as well. We will compute | |
12239 | it later on. */ | |
12240 | if (loc->cond_bytecode) | |
12241 | { | |
12242 | free_agent_expr (loc->cond_bytecode); | |
12243 | loc->cond_bytecode = NULL; | |
12244 | } | |
12245 | } | |
12246 | } | |
12247 | ||
4cd9bd08 | 12248 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12249 | into the inferior, only remove already-inserted locations that no |
12250 | longer should be inserted. Functions that delete a breakpoint or | |
12251 | breakpoints should pass false, so that deleting a breakpoint | |
12252 | doesn't have the side effect of inserting the locations of other | |
12253 | breakpoints that are marked not-inserted, but should_be_inserted | |
12254 | returns true on them. | |
12255 | ||
12256 | This behaviour is useful is situations close to tear-down -- e.g., | |
12257 | after an exec, while the target still has execution, but breakpoint | |
12258 | shadows of the previous executable image should *NOT* be restored | |
12259 | to the new image; or before detaching, where the target still has | |
12260 | execution and wants to delete breakpoints from GDB's lists, and all | |
12261 | breakpoints had already been removed from the inferior. */ | |
12262 | ||
0d381245 | 12263 | static void |
b60e7edf | 12264 | update_global_location_list (int should_insert) |
0d381245 | 12265 | { |
74960c60 | 12266 | struct breakpoint *b; |
876fa593 | 12267 | struct bp_location **locp, *loc; |
f7545552 | 12268 | struct cleanup *cleanups; |
b775012e LM |
12269 | /* Last breakpoint location address that was marked for update. */ |
12270 | CORE_ADDR last_addr = 0; | |
12271 | /* Last breakpoint location program space that was marked for update. */ | |
12272 | int last_pspace_num = -1; | |
f7545552 | 12273 | |
2d134ed3 PA |
12274 | /* Used in the duplicates detection below. When iterating over all |
12275 | bp_locations, points to the first bp_location of a given address. | |
12276 | Breakpoints and watchpoints of different types are never | |
12277 | duplicates of each other. Keep one pointer for each type of | |
12278 | breakpoint/watchpoint, so we only need to loop over all locations | |
12279 | once. */ | |
12280 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12281 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12282 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12283 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12284 | |
4a64f543 MS |
12285 | /* Saved former bp_location array which we compare against the newly |
12286 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12287 | struct bp_location **old_location, **old_locp; |
12288 | unsigned old_location_count; | |
12289 | ||
12290 | old_location = bp_location; | |
12291 | old_location_count = bp_location_count; | |
12292 | bp_location = NULL; | |
12293 | bp_location_count = 0; | |
12294 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12295 | |
74960c60 | 12296 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12297 | for (loc = b->loc; loc; loc = loc->next) |
12298 | bp_location_count++; | |
12299 | ||
12300 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12301 | locp = bp_location; | |
12302 | ALL_BREAKPOINTS (b) | |
12303 | for (loc = b->loc; loc; loc = loc->next) | |
12304 | *locp++ = loc; | |
12305 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12306 | bp_location_compare); |
876fa593 JK |
12307 | |
12308 | bp_location_target_extensions_update (); | |
74960c60 | 12309 | |
4a64f543 MS |
12310 | /* Identify bp_location instances that are no longer present in the |
12311 | new list, and therefore should be freed. Note that it's not | |
12312 | necessary that those locations should be removed from inferior -- | |
12313 | if there's another location at the same address (previously | |
12314 | marked as duplicate), we don't need to remove/insert the | |
12315 | location. | |
876fa593 | 12316 | |
4a64f543 MS |
12317 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12318 | and former bp_location array state respectively. */ | |
876fa593 JK |
12319 | |
12320 | locp = bp_location; | |
12321 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12322 | old_locp++) | |
74960c60 | 12323 | { |
876fa593 | 12324 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12325 | struct bp_location **loc2p; |
876fa593 | 12326 | |
e5dd4106 | 12327 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12328 | not, we have to free it. */ |
c7d46a38 | 12329 | int found_object = 0; |
20874c92 VP |
12330 | /* Tells if the location should remain inserted in the target. */ |
12331 | int keep_in_target = 0; | |
12332 | int removed = 0; | |
876fa593 | 12333 | |
4a64f543 MS |
12334 | /* Skip LOCP entries which will definitely never be needed. |
12335 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12336 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12337 | && (*locp)->address < old_loc->address) |
876fa593 | 12338 | locp++; |
c7d46a38 PA |
12339 | |
12340 | for (loc2p = locp; | |
12341 | (loc2p < bp_location + bp_location_count | |
12342 | && (*loc2p)->address == old_loc->address); | |
12343 | loc2p++) | |
12344 | { | |
b775012e LM |
12345 | /* Check if this is a new/duplicated location or a duplicated |
12346 | location that had its condition modified. If so, we want to send | |
12347 | its condition to the target if evaluation of conditions is taking | |
12348 | place there. */ | |
12349 | if ((*loc2p)->condition_changed == condition_modified | |
12350 | && (last_addr != old_loc->address | |
12351 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12352 | { |
b775012e LM |
12353 | force_breakpoint_reinsertion (*loc2p); |
12354 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12355 | } |
b775012e LM |
12356 | |
12357 | if (*loc2p == old_loc) | |
12358 | found_object = 1; | |
c7d46a38 | 12359 | } |
74960c60 | 12360 | |
b775012e LM |
12361 | /* We have already handled this address, update it so that we don't |
12362 | have to go through updates again. */ | |
12363 | last_addr = old_loc->address; | |
12364 | ||
12365 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12366 | if (!found_object) | |
12367 | force_breakpoint_reinsertion (old_loc); | |
12368 | ||
4a64f543 MS |
12369 | /* If this location is no longer present, and inserted, look if |
12370 | there's maybe a new location at the same address. If so, | |
12371 | mark that one inserted, and don't remove this one. This is | |
12372 | needed so that we don't have a time window where a breakpoint | |
12373 | at certain location is not inserted. */ | |
74960c60 | 12374 | |
876fa593 | 12375 | if (old_loc->inserted) |
0d381245 | 12376 | { |
4a64f543 MS |
12377 | /* If the location is inserted now, we might have to remove |
12378 | it. */ | |
74960c60 | 12379 | |
876fa593 | 12380 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12381 | { |
4a64f543 MS |
12382 | /* The location is still present in the location list, |
12383 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12384 | keep_in_target = 1; |
74960c60 VP |
12385 | } |
12386 | else | |
12387 | { | |
b775012e LM |
12388 | /* This location still exists, but it won't be kept in the |
12389 | target since it may have been disabled. We proceed to | |
12390 | remove its target-side condition. */ | |
12391 | ||
4a64f543 MS |
12392 | /* The location is either no longer present, or got |
12393 | disabled. See if there's another location at the | |
12394 | same address, in which case we don't need to remove | |
12395 | this one from the target. */ | |
876fa593 | 12396 | |
2bdf28a0 | 12397 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12398 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12399 | { | |
876fa593 | 12400 | for (loc2p = locp; |
c7d46a38 PA |
12401 | (loc2p < bp_location + bp_location_count |
12402 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12403 | loc2p++) |
12404 | { | |
12405 | struct bp_location *loc2 = *loc2p; | |
12406 | ||
2d134ed3 | 12407 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12408 | { |
85d721b8 PA |
12409 | /* Read watchpoint locations are switched to |
12410 | access watchpoints, if the former are not | |
12411 | supported, but the latter are. */ | |
12412 | if (is_hardware_watchpoint (old_loc->owner)) | |
12413 | { | |
12414 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12415 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12416 | } | |
12417 | ||
934709f0 PW |
12418 | /* loc2 is a duplicated location. We need to check |
12419 | if it should be inserted in case it will be | |
12420 | unduplicated. */ | |
12421 | if (loc2 != old_loc | |
12422 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12423 | { |
934709f0 | 12424 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12425 | keep_in_target = 1; |
12426 | break; | |
12427 | } | |
876fa593 JK |
12428 | } |
12429 | } | |
12430 | } | |
74960c60 VP |
12431 | } |
12432 | ||
20874c92 VP |
12433 | if (!keep_in_target) |
12434 | { | |
876fa593 | 12435 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12436 | { |
4a64f543 MS |
12437 | /* This is just about all we can do. We could keep |
12438 | this location on the global list, and try to | |
12439 | remove it next time, but there's no particular | |
12440 | reason why we will succeed next time. | |
20874c92 | 12441 | |
4a64f543 MS |
12442 | Note that at this point, old_loc->owner is still |
12443 | valid, as delete_breakpoint frees the breakpoint | |
12444 | only after calling us. */ | |
3e43a32a MS |
12445 | printf_filtered (_("warning: Error removing " |
12446 | "breakpoint %d\n"), | |
876fa593 | 12447 | old_loc->owner->number); |
20874c92 VP |
12448 | } |
12449 | removed = 1; | |
12450 | } | |
0d381245 | 12451 | } |
74960c60 VP |
12452 | |
12453 | if (!found_object) | |
1c5cfe86 | 12454 | { |
db82e815 PA |
12455 | if (removed && non_stop |
12456 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12457 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12458 | { |
db82e815 PA |
12459 | /* This location was removed from the target. In |
12460 | non-stop mode, a race condition is possible where | |
12461 | we've removed a breakpoint, but stop events for that | |
12462 | breakpoint are already queued and will arrive later. | |
12463 | We apply an heuristic to be able to distinguish such | |
12464 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12465 | breakpoint location for a bit, and will retire it | |
12466 | after we see some number of events. The theory here | |
12467 | is that reporting of events should, "on the average", | |
12468 | be fair, so after a while we'll see events from all | |
12469 | threads that have anything of interest, and no longer | |
12470 | need to keep this breakpoint location around. We | |
12471 | don't hold locations forever so to reduce chances of | |
12472 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12473 | SIGTRAP. | |
12474 | ||
12475 | The heuristic failing can be disastrous on | |
12476 | decr_pc_after_break targets. | |
12477 | ||
12478 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12479 | if we fail to recognize a late breakpoint SIGTRAP, | |
12480 | because events_till_retirement has reached 0 too | |
12481 | soon, we'll fail to do the PC adjustment, and report | |
12482 | a random SIGTRAP to the user. When the user resumes | |
12483 | the inferior, it will most likely immediately crash | |
2dec564e | 12484 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12485 | corrupted, because of being resumed e.g., in the |
12486 | middle of a multi-byte instruction, or skipped a | |
12487 | one-byte instruction. This was actually seen happen | |
12488 | on native x86-linux, and should be less rare on | |
12489 | targets that do not support new thread events, like | |
12490 | remote, due to the heuristic depending on | |
12491 | thread_count. | |
12492 | ||
12493 | Mistaking a random SIGTRAP for a breakpoint trap | |
12494 | causes similar symptoms (PC adjustment applied when | |
12495 | it shouldn't), but then again, playing with SIGTRAPs | |
12496 | behind the debugger's back is asking for trouble. | |
12497 | ||
12498 | Since hardware watchpoint traps are always | |
12499 | distinguishable from other traps, so we don't need to | |
12500 | apply keep hardware watchpoint moribund locations | |
12501 | around. We simply always ignore hardware watchpoint | |
12502 | traps we can no longer explain. */ | |
12503 | ||
876fa593 JK |
12504 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12505 | old_loc->owner = NULL; | |
20874c92 | 12506 | |
876fa593 | 12507 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12508 | } |
12509 | else | |
f431efe5 PA |
12510 | { |
12511 | old_loc->owner = NULL; | |
12512 | decref_bp_location (&old_loc); | |
12513 | } | |
20874c92 | 12514 | } |
74960c60 | 12515 | } |
1c5cfe86 | 12516 | |
348d480f PA |
12517 | /* Rescan breakpoints at the same address and section, marking the |
12518 | first one as "first" and any others as "duplicates". This is so | |
12519 | that the bpt instruction is only inserted once. If we have a | |
12520 | permanent breakpoint at the same place as BPT, make that one the | |
12521 | official one, and the rest as duplicates. Permanent breakpoints | |
12522 | are sorted first for the same address. | |
12523 | ||
12524 | Do the same for hardware watchpoints, but also considering the | |
12525 | watchpoint's type (regular/access/read) and length. */ | |
12526 | ||
12527 | bp_loc_first = NULL; | |
12528 | wp_loc_first = NULL; | |
12529 | awp_loc_first = NULL; | |
12530 | rwp_loc_first = NULL; | |
12531 | ALL_BP_LOCATIONS (loc, locp) | |
12532 | { | |
12533 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12534 | non-NULL. */ | |
348d480f | 12535 | struct bp_location **loc_first_p; |
d3fbdd86 | 12536 | b = loc->owner; |
348d480f | 12537 | |
6f380991 | 12538 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12539 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12540 | /* Don't detect duplicate for tracepoint locations because they are |
12541 | never duplicated. See the comments in field `duplicate' of | |
12542 | `struct bp_location'. */ | |
348d480f | 12543 | || is_tracepoint (b)) |
b775012e LM |
12544 | { |
12545 | /* Clear the condition modification flag. */ | |
12546 | loc->condition_changed = condition_unchanged; | |
12547 | continue; | |
12548 | } | |
348d480f PA |
12549 | |
12550 | /* Permanent breakpoint should always be inserted. */ | |
12551 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12552 | internal_error (__FILE__, __LINE__, | |
12553 | _("allegedly permanent breakpoint is not " | |
12554 | "actually inserted")); | |
12555 | ||
12556 | if (b->type == bp_hardware_watchpoint) | |
12557 | loc_first_p = &wp_loc_first; | |
12558 | else if (b->type == bp_read_watchpoint) | |
12559 | loc_first_p = &rwp_loc_first; | |
12560 | else if (b->type == bp_access_watchpoint) | |
12561 | loc_first_p = &awp_loc_first; | |
12562 | else | |
12563 | loc_first_p = &bp_loc_first; | |
12564 | ||
12565 | if (*loc_first_p == NULL | |
12566 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12567 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12568 | { | |
12569 | *loc_first_p = loc; | |
12570 | loc->duplicate = 0; | |
b775012e LM |
12571 | |
12572 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12573 | { | |
12574 | loc->needs_update = 1; | |
12575 | /* Clear the condition modification flag. */ | |
12576 | loc->condition_changed = condition_unchanged; | |
12577 | } | |
348d480f PA |
12578 | continue; |
12579 | } | |
12580 | ||
934709f0 PW |
12581 | |
12582 | /* This and the above ensure the invariant that the first location | |
12583 | is not duplicated, and is the inserted one. | |
12584 | All following are marked as duplicated, and are not inserted. */ | |
12585 | if (loc->inserted) | |
12586 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12587 | loc->duplicate = 1; |
12588 | ||
b775012e LM |
12589 | /* Clear the condition modification flag. */ |
12590 | loc->condition_changed = condition_unchanged; | |
12591 | ||
348d480f PA |
12592 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12593 | && b->enable_state != bp_permanent) | |
12594 | internal_error (__FILE__, __LINE__, | |
12595 | _("another breakpoint was inserted on top of " | |
12596 | "a permanent breakpoint")); | |
12597 | } | |
12598 | ||
b775012e | 12599 | if (breakpoints_always_inserted_mode () |
348d480f | 12600 | && (have_live_inferiors () |
f5656ead | 12601 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12602 | { |
12603 | if (should_insert) | |
12604 | insert_breakpoint_locations (); | |
12605 | else | |
12606 | { | |
12607 | /* Though should_insert is false, we may need to update conditions | |
12608 | on the target's side if it is evaluating such conditions. We | |
12609 | only update conditions for locations that are marked | |
12610 | "needs_update". */ | |
12611 | update_inserted_breakpoint_locations (); | |
12612 | } | |
12613 | } | |
348d480f | 12614 | |
1e4d1764 YQ |
12615 | if (should_insert) |
12616 | download_tracepoint_locations (); | |
12617 | ||
348d480f PA |
12618 | do_cleanups (cleanups); |
12619 | } | |
12620 | ||
12621 | void | |
12622 | breakpoint_retire_moribund (void) | |
12623 | { | |
12624 | struct bp_location *loc; | |
12625 | int ix; | |
12626 | ||
12627 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12628 | if (--(loc->events_till_retirement) == 0) | |
12629 | { | |
12630 | decref_bp_location (&loc); | |
12631 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12632 | --ix; | |
12633 | } | |
12634 | } | |
12635 | ||
12636 | static void | |
12637 | update_global_location_list_nothrow (int inserting) | |
12638 | { | |
bfd189b1 | 12639 | volatile struct gdb_exception e; |
348d480f PA |
12640 | |
12641 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12642 | update_global_location_list (inserting); | |
12643 | } | |
12644 | ||
12645 | /* Clear BKP from a BPS. */ | |
12646 | ||
12647 | static void | |
12648 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12649 | { | |
12650 | bpstat bs; | |
12651 | ||
12652 | for (bs = bps; bs; bs = bs->next) | |
12653 | if (bs->breakpoint_at == bpt) | |
12654 | { | |
12655 | bs->breakpoint_at = NULL; | |
12656 | bs->old_val = NULL; | |
12657 | /* bs->commands will be freed later. */ | |
12658 | } | |
12659 | } | |
12660 | ||
12661 | /* Callback for iterate_over_threads. */ | |
12662 | static int | |
12663 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12664 | { | |
12665 | struct breakpoint *bpt = data; | |
12666 | ||
12667 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12668 | return 0; | |
12669 | } | |
12670 | ||
12671 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12672 | callbacks. */ | |
12673 | ||
12674 | static void | |
12675 | say_where (struct breakpoint *b) | |
12676 | { | |
12677 | struct value_print_options opts; | |
12678 | ||
12679 | get_user_print_options (&opts); | |
12680 | ||
12681 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12682 | single string. */ | |
12683 | if (b->loc == NULL) | |
12684 | { | |
12685 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12686 | } | |
12687 | else | |
12688 | { | |
2f202fde | 12689 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12690 | { |
12691 | printf_filtered (" at "); | |
12692 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12693 | gdb_stdout); | |
12694 | } | |
2f202fde | 12695 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12696 | { |
12697 | /* If there is a single location, we can print the location | |
12698 | more nicely. */ | |
12699 | if (b->loc->next == NULL) | |
12700 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12701 | symtab_to_filename_for_display (b->loc->symtab), |
12702 | b->loc->line_number); | |
f8eba3c6 TT |
12703 | else |
12704 | /* This is not ideal, but each location may have a | |
12705 | different file name, and this at least reflects the | |
12706 | real situation somewhat. */ | |
12707 | printf_filtered (": %s.", b->addr_string); | |
12708 | } | |
348d480f PA |
12709 | |
12710 | if (b->loc->next) | |
12711 | { | |
12712 | struct bp_location *loc = b->loc; | |
12713 | int n = 0; | |
12714 | for (; loc; loc = loc->next) | |
12715 | ++n; | |
12716 | printf_filtered (" (%d locations)", n); | |
12717 | } | |
12718 | } | |
12719 | } | |
12720 | ||
348d480f PA |
12721 | /* Default bp_location_ops methods. */ |
12722 | ||
12723 | static void | |
12724 | bp_location_dtor (struct bp_location *self) | |
12725 | { | |
12726 | xfree (self->cond); | |
b775012e LM |
12727 | if (self->cond_bytecode) |
12728 | free_agent_expr (self->cond_bytecode); | |
348d480f PA |
12729 | xfree (self->function_name); |
12730 | } | |
12731 | ||
12732 | static const struct bp_location_ops bp_location_ops = | |
12733 | { | |
12734 | bp_location_dtor | |
12735 | }; | |
12736 | ||
2060206e PA |
12737 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12738 | inherit from. */ | |
348d480f | 12739 | |
2060206e PA |
12740 | static void |
12741 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12742 | { |
12743 | decref_counted_command_line (&self->commands); | |
12744 | xfree (self->cond_string); | |
fb81d016 | 12745 | xfree (self->extra_string); |
348d480f | 12746 | xfree (self->addr_string); |
f8eba3c6 | 12747 | xfree (self->filter); |
348d480f | 12748 | xfree (self->addr_string_range_end); |
348d480f PA |
12749 | } |
12750 | ||
2060206e PA |
12751 | static struct bp_location * |
12752 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12753 | { |
12754 | struct bp_location *loc; | |
12755 | ||
12756 | loc = XNEW (struct bp_location); | |
12757 | init_bp_location (loc, &bp_location_ops, self); | |
12758 | return loc; | |
12759 | } | |
12760 | ||
2060206e PA |
12761 | static void |
12762 | base_breakpoint_re_set (struct breakpoint *b) | |
12763 | { | |
12764 | /* Nothing to re-set. */ | |
12765 | } | |
12766 | ||
12767 | #define internal_error_pure_virtual_called() \ | |
12768 | gdb_assert_not_reached ("pure virtual function called") | |
12769 | ||
12770 | static int | |
12771 | base_breakpoint_insert_location (struct bp_location *bl) | |
12772 | { | |
12773 | internal_error_pure_virtual_called (); | |
12774 | } | |
12775 | ||
12776 | static int | |
12777 | base_breakpoint_remove_location (struct bp_location *bl) | |
12778 | { | |
12779 | internal_error_pure_virtual_called (); | |
12780 | } | |
12781 | ||
12782 | static int | |
12783 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12784 | struct address_space *aspace, | |
09ac7c10 TT |
12785 | CORE_ADDR bp_addr, |
12786 | const struct target_waitstatus *ws) | |
2060206e PA |
12787 | { |
12788 | internal_error_pure_virtual_called (); | |
12789 | } | |
12790 | ||
12791 | static void | |
12792 | base_breakpoint_check_status (bpstat bs) | |
12793 | { | |
12794 | /* Always stop. */ | |
12795 | } | |
12796 | ||
12797 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12798 | errors. */ | |
12799 | ||
12800 | static int | |
12801 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12802 | { | |
12803 | internal_error_pure_virtual_called (); | |
12804 | } | |
12805 | ||
12806 | /* A "resources_needed" breakpoint_ops method that just internal | |
12807 | errors. */ | |
12808 | ||
12809 | static int | |
12810 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12811 | { | |
12812 | internal_error_pure_virtual_called (); | |
12813 | } | |
12814 | ||
12815 | static enum print_stop_action | |
12816 | base_breakpoint_print_it (bpstat bs) | |
12817 | { | |
12818 | internal_error_pure_virtual_called (); | |
12819 | } | |
12820 | ||
12821 | static void | |
12822 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12823 | struct ui_out *uiout) | |
12824 | { | |
12825 | /* nothing */ | |
12826 | } | |
12827 | ||
12828 | static void | |
12829 | base_breakpoint_print_mention (struct breakpoint *b) | |
12830 | { | |
12831 | internal_error_pure_virtual_called (); | |
12832 | } | |
12833 | ||
12834 | static void | |
12835 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12836 | { | |
12837 | internal_error_pure_virtual_called (); | |
12838 | } | |
12839 | ||
983af33b SDJ |
12840 | static void |
12841 | base_breakpoint_create_sals_from_address (char **arg, | |
12842 | struct linespec_result *canonical, | |
12843 | enum bptype type_wanted, | |
12844 | char *addr_start, | |
12845 | char **copy_arg) | |
12846 | { | |
12847 | internal_error_pure_virtual_called (); | |
12848 | } | |
12849 | ||
12850 | static void | |
12851 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12852 | struct linespec_result *c, | |
983af33b | 12853 | char *cond_string, |
e7e0cddf | 12854 | char *extra_string, |
983af33b SDJ |
12855 | enum bptype type_wanted, |
12856 | enum bpdisp disposition, | |
12857 | int thread, | |
12858 | int task, int ignore_count, | |
12859 | const struct breakpoint_ops *o, | |
12860 | int from_tty, int enabled, | |
44f238bb | 12861 | int internal, unsigned flags) |
983af33b SDJ |
12862 | { |
12863 | internal_error_pure_virtual_called (); | |
12864 | } | |
12865 | ||
12866 | static void | |
12867 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12868 | struct symtabs_and_lines *sals) | |
12869 | { | |
12870 | internal_error_pure_virtual_called (); | |
12871 | } | |
12872 | ||
ab04a2af TT |
12873 | /* The default 'explains_signal' method. */ |
12874 | ||
12875 | static enum bpstat_signal_value | |
427cd150 | 12876 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af TT |
12877 | { |
12878 | return BPSTAT_SIGNAL_HIDE; | |
12879 | } | |
12880 | ||
9d6e6e84 HZ |
12881 | /* The default "after_condition_true" method. */ |
12882 | ||
12883 | static void | |
12884 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12885 | { | |
12886 | /* Nothing to do. */ | |
12887 | } | |
12888 | ||
ab04a2af | 12889 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12890 | { |
12891 | base_breakpoint_dtor, | |
12892 | base_breakpoint_allocate_location, | |
12893 | base_breakpoint_re_set, | |
12894 | base_breakpoint_insert_location, | |
12895 | base_breakpoint_remove_location, | |
12896 | base_breakpoint_breakpoint_hit, | |
12897 | base_breakpoint_check_status, | |
12898 | base_breakpoint_resources_needed, | |
12899 | base_breakpoint_works_in_software_mode, | |
12900 | base_breakpoint_print_it, | |
12901 | NULL, | |
12902 | base_breakpoint_print_one_detail, | |
12903 | base_breakpoint_print_mention, | |
983af33b SDJ |
12904 | base_breakpoint_print_recreate, |
12905 | base_breakpoint_create_sals_from_address, | |
12906 | base_breakpoint_create_breakpoints_sal, | |
12907 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12908 | base_breakpoint_explains_signal, |
12909 | base_breakpoint_after_condition_true, | |
2060206e PA |
12910 | }; |
12911 | ||
12912 | /* Default breakpoint_ops methods. */ | |
12913 | ||
12914 | static void | |
348d480f PA |
12915 | bkpt_re_set (struct breakpoint *b) |
12916 | { | |
06edf0c0 PA |
12917 | /* FIXME: is this still reachable? */ |
12918 | if (b->addr_string == NULL) | |
12919 | { | |
12920 | /* Anything without a string can't be re-set. */ | |
348d480f | 12921 | delete_breakpoint (b); |
06edf0c0 | 12922 | return; |
348d480f | 12923 | } |
06edf0c0 PA |
12924 | |
12925 | breakpoint_re_set_default (b); | |
348d480f PA |
12926 | } |
12927 | ||
2060206e | 12928 | static int |
348d480f PA |
12929 | bkpt_insert_location (struct bp_location *bl) |
12930 | { | |
12931 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12932 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12933 | &bl->target_info); | |
12934 | else | |
12935 | return target_insert_breakpoint (bl->gdbarch, | |
12936 | &bl->target_info); | |
12937 | } | |
12938 | ||
2060206e | 12939 | static int |
348d480f PA |
12940 | bkpt_remove_location (struct bp_location *bl) |
12941 | { | |
12942 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12943 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12944 | else | |
12945 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12946 | } | |
12947 | ||
2060206e | 12948 | static int |
348d480f | 12949 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12950 | struct address_space *aspace, CORE_ADDR bp_addr, |
12951 | const struct target_waitstatus *ws) | |
348d480f | 12952 | { |
09ac7c10 | 12953 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12954 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12955 | return 0; |
12956 | ||
348d480f PA |
12957 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12958 | aspace, bp_addr)) | |
12959 | return 0; | |
12960 | ||
12961 | if (overlay_debugging /* unmapped overlay section */ | |
12962 | && section_is_overlay (bl->section) | |
12963 | && !section_is_mapped (bl->section)) | |
12964 | return 0; | |
12965 | ||
12966 | return 1; | |
12967 | } | |
12968 | ||
2060206e | 12969 | static int |
348d480f PA |
12970 | bkpt_resources_needed (const struct bp_location *bl) |
12971 | { | |
12972 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12973 | ||
12974 | return 1; | |
12975 | } | |
12976 | ||
2060206e | 12977 | static enum print_stop_action |
348d480f PA |
12978 | bkpt_print_it (bpstat bs) |
12979 | { | |
348d480f PA |
12980 | struct breakpoint *b; |
12981 | const struct bp_location *bl; | |
001c8c33 | 12982 | int bp_temp; |
79a45e25 | 12983 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12984 | |
12985 | gdb_assert (bs->bp_location_at != NULL); | |
12986 | ||
12987 | bl = bs->bp_location_at; | |
12988 | b = bs->breakpoint_at; | |
12989 | ||
001c8c33 PA |
12990 | bp_temp = b->disposition == disp_del; |
12991 | if (bl->address != bl->requested_address) | |
12992 | breakpoint_adjustment_warning (bl->requested_address, | |
12993 | bl->address, | |
12994 | b->number, 1); | |
12995 | annotate_breakpoint (b->number); | |
12996 | if (bp_temp) | |
12997 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12998 | else | |
12999 | ui_out_text (uiout, "\nBreakpoint "); | |
13000 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13001 | { |
001c8c33 PA |
13002 | ui_out_field_string (uiout, "reason", |
13003 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13004 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13005 | } |
001c8c33 PA |
13006 | ui_out_field_int (uiout, "bkptno", b->number); |
13007 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13008 | |
001c8c33 | 13009 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13010 | } |
13011 | ||
2060206e | 13012 | static void |
06edf0c0 PA |
13013 | bkpt_print_mention (struct breakpoint *b) |
13014 | { | |
79a45e25 | 13015 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13016 | return; |
13017 | ||
13018 | switch (b->type) | |
13019 | { | |
13020 | case bp_breakpoint: | |
13021 | case bp_gnu_ifunc_resolver: | |
13022 | if (b->disposition == disp_del) | |
13023 | printf_filtered (_("Temporary breakpoint")); | |
13024 | else | |
13025 | printf_filtered (_("Breakpoint")); | |
13026 | printf_filtered (_(" %d"), b->number); | |
13027 | if (b->type == bp_gnu_ifunc_resolver) | |
13028 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13029 | break; | |
13030 | case bp_hardware_breakpoint: | |
13031 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13032 | break; | |
e7e0cddf SS |
13033 | case bp_dprintf: |
13034 | printf_filtered (_("Dprintf %d"), b->number); | |
13035 | break; | |
06edf0c0 PA |
13036 | } |
13037 | ||
13038 | say_where (b); | |
13039 | } | |
13040 | ||
2060206e | 13041 | static void |
06edf0c0 PA |
13042 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13043 | { | |
13044 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13045 | fprintf_unfiltered (fp, "tbreak"); | |
13046 | else if (tp->type == bp_breakpoint) | |
13047 | fprintf_unfiltered (fp, "break"); | |
13048 | else if (tp->type == bp_hardware_breakpoint | |
13049 | && tp->disposition == disp_del) | |
13050 | fprintf_unfiltered (fp, "thbreak"); | |
13051 | else if (tp->type == bp_hardware_breakpoint) | |
13052 | fprintf_unfiltered (fp, "hbreak"); | |
13053 | else | |
13054 | internal_error (__FILE__, __LINE__, | |
13055 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13056 | ||
2060206e | 13057 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13058 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13059 | } |
13060 | ||
983af33b SDJ |
13061 | static void |
13062 | bkpt_create_sals_from_address (char **arg, | |
13063 | struct linespec_result *canonical, | |
13064 | enum bptype type_wanted, | |
13065 | char *addr_start, char **copy_arg) | |
13066 | { | |
13067 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13068 | addr_start, copy_arg); | |
13069 | } | |
13070 | ||
13071 | static void | |
13072 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13073 | struct linespec_result *canonical, | |
983af33b | 13074 | char *cond_string, |
e7e0cddf | 13075 | char *extra_string, |
983af33b SDJ |
13076 | enum bptype type_wanted, |
13077 | enum bpdisp disposition, | |
13078 | int thread, | |
13079 | int task, int ignore_count, | |
13080 | const struct breakpoint_ops *ops, | |
13081 | int from_tty, int enabled, | |
44f238bb | 13082 | int internal, unsigned flags) |
983af33b | 13083 | { |
023fa29b | 13084 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13085 | cond_string, extra_string, |
13086 | type_wanted, | |
983af33b SDJ |
13087 | disposition, thread, task, |
13088 | ignore_count, ops, from_tty, | |
44f238bb | 13089 | enabled, internal, flags); |
983af33b SDJ |
13090 | } |
13091 | ||
13092 | static void | |
13093 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13094 | struct symtabs_and_lines *sals) | |
13095 | { | |
13096 | decode_linespec_default (b, s, sals); | |
13097 | } | |
13098 | ||
06edf0c0 PA |
13099 | /* Virtual table for internal breakpoints. */ |
13100 | ||
13101 | static void | |
13102 | internal_bkpt_re_set (struct breakpoint *b) | |
13103 | { | |
13104 | switch (b->type) | |
13105 | { | |
13106 | /* Delete overlay event and longjmp master breakpoints; they | |
13107 | will be reset later by breakpoint_re_set. */ | |
13108 | case bp_overlay_event: | |
13109 | case bp_longjmp_master: | |
13110 | case bp_std_terminate_master: | |
13111 | case bp_exception_master: | |
13112 | delete_breakpoint (b); | |
13113 | break; | |
13114 | ||
13115 | /* This breakpoint is special, it's set up when the inferior | |
13116 | starts and we really don't want to touch it. */ | |
13117 | case bp_shlib_event: | |
13118 | ||
13119 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13120 | it is set up, we do not want to touch it. */ | |
13121 | case bp_thread_event: | |
13122 | break; | |
13123 | } | |
13124 | } | |
13125 | ||
13126 | static void | |
13127 | internal_bkpt_check_status (bpstat bs) | |
13128 | { | |
a9b3a50f PA |
13129 | if (bs->breakpoint_at->type == bp_shlib_event) |
13130 | { | |
13131 | /* If requested, stop when the dynamic linker notifies GDB of | |
13132 | events. This allows the user to get control and place | |
13133 | breakpoints in initializer routines for dynamically loaded | |
13134 | objects (among other things). */ | |
13135 | bs->stop = stop_on_solib_events; | |
13136 | bs->print = stop_on_solib_events; | |
13137 | } | |
13138 | else | |
13139 | bs->stop = 0; | |
06edf0c0 PA |
13140 | } |
13141 | ||
13142 | static enum print_stop_action | |
13143 | internal_bkpt_print_it (bpstat bs) | |
13144 | { | |
06edf0c0 | 13145 | struct breakpoint *b; |
06edf0c0 | 13146 | |
06edf0c0 PA |
13147 | b = bs->breakpoint_at; |
13148 | ||
06edf0c0 PA |
13149 | switch (b->type) |
13150 | { | |
348d480f PA |
13151 | case bp_shlib_event: |
13152 | /* Did we stop because the user set the stop_on_solib_events | |
13153 | variable? (If so, we report this as a generic, "Stopped due | |
13154 | to shlib event" message.) */ | |
edcc5120 | 13155 | print_solib_event (0); |
348d480f PA |
13156 | break; |
13157 | ||
13158 | case bp_thread_event: | |
13159 | /* Not sure how we will get here. | |
13160 | GDB should not stop for these breakpoints. */ | |
13161 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13162 | break; |
13163 | ||
13164 | case bp_overlay_event: | |
13165 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13166 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13167 | break; |
13168 | ||
13169 | case bp_longjmp_master: | |
13170 | /* These should never be enabled. */ | |
13171 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13172 | break; |
13173 | ||
13174 | case bp_std_terminate_master: | |
13175 | /* These should never be enabled. */ | |
13176 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13177 | "gdb should not stop!\n")); | |
348d480f PA |
13178 | break; |
13179 | ||
13180 | case bp_exception_master: | |
13181 | /* These should never be enabled. */ | |
13182 | printf_filtered (_("Exception Master Breakpoint: " | |
13183 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13184 | break; |
13185 | } | |
13186 | ||
001c8c33 | 13187 | return PRINT_NOTHING; |
06edf0c0 PA |
13188 | } |
13189 | ||
13190 | static void | |
13191 | internal_bkpt_print_mention (struct breakpoint *b) | |
13192 | { | |
13193 | /* Nothing to mention. These breakpoints are internal. */ | |
13194 | } | |
13195 | ||
06edf0c0 PA |
13196 | /* Virtual table for momentary breakpoints */ |
13197 | ||
13198 | static void | |
13199 | momentary_bkpt_re_set (struct breakpoint *b) | |
13200 | { | |
13201 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13202 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13203 | Otherwise these should have been blown away via the cleanup chain |
13204 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13205 | } | |
13206 | ||
13207 | static void | |
13208 | momentary_bkpt_check_status (bpstat bs) | |
13209 | { | |
13210 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13211 | } | |
13212 | ||
13213 | static enum print_stop_action | |
13214 | momentary_bkpt_print_it (bpstat bs) | |
13215 | { | |
79a45e25 PA |
13216 | struct ui_out *uiout = current_uiout; |
13217 | ||
001c8c33 | 13218 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13219 | { |
001c8c33 | 13220 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13221 | |
001c8c33 PA |
13222 | switch (b->type) |
13223 | { | |
13224 | case bp_finish: | |
13225 | ui_out_field_string | |
13226 | (uiout, "reason", | |
13227 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13228 | break; | |
348d480f | 13229 | |
001c8c33 PA |
13230 | case bp_until: |
13231 | ui_out_field_string | |
13232 | (uiout, "reason", | |
13233 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13234 | break; | |
13235 | } | |
348d480f PA |
13236 | } |
13237 | ||
001c8c33 | 13238 | return PRINT_UNKNOWN; |
348d480f PA |
13239 | } |
13240 | ||
06edf0c0 PA |
13241 | static void |
13242 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13243 | { |
06edf0c0 | 13244 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13245 | } |
13246 | ||
e2e4d78b JK |
13247 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13248 | ||
13249 | It gets cleared already on the removal of the first one of such placed | |
13250 | breakpoints. This is OK as they get all removed altogether. */ | |
13251 | ||
13252 | static void | |
13253 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13254 | { | |
13255 | struct thread_info *tp = find_thread_id (self->thread); | |
13256 | ||
13257 | if (tp) | |
13258 | tp->initiating_frame = null_frame_id; | |
13259 | ||
13260 | momentary_breakpoint_ops.dtor (self); | |
13261 | } | |
13262 | ||
55aa24fb SDJ |
13263 | /* Specific methods for probe breakpoints. */ |
13264 | ||
13265 | static int | |
13266 | bkpt_probe_insert_location (struct bp_location *bl) | |
13267 | { | |
13268 | int v = bkpt_insert_location (bl); | |
13269 | ||
13270 | if (v == 0) | |
13271 | { | |
13272 | /* The insertion was successful, now let's set the probe's semaphore | |
13273 | if needed. */ | |
13274 | bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch); | |
13275 | } | |
13276 | ||
13277 | return v; | |
13278 | } | |
13279 | ||
13280 | static int | |
13281 | bkpt_probe_remove_location (struct bp_location *bl) | |
13282 | { | |
13283 | /* Let's clear the semaphore before removing the location. */ | |
13284 | bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch); | |
13285 | ||
13286 | return bkpt_remove_location (bl); | |
13287 | } | |
13288 | ||
13289 | static void | |
13290 | bkpt_probe_create_sals_from_address (char **arg, | |
13291 | struct linespec_result *canonical, | |
13292 | enum bptype type_wanted, | |
13293 | char *addr_start, char **copy_arg) | |
13294 | { | |
13295 | struct linespec_sals lsal; | |
13296 | ||
13297 | lsal.sals = parse_probes (arg, canonical); | |
13298 | ||
13299 | *copy_arg = xstrdup (canonical->addr_string); | |
13300 | lsal.canonical = xstrdup (*copy_arg); | |
13301 | ||
13302 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13303 | } | |
13304 | ||
13305 | static void | |
13306 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13307 | struct symtabs_and_lines *sals) | |
13308 | { | |
13309 | *sals = parse_probes (s, NULL); | |
13310 | if (!sals->sals) | |
13311 | error (_("probe not found")); | |
13312 | } | |
13313 | ||
348d480f | 13314 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13315 | |
348d480f PA |
13316 | static void |
13317 | tracepoint_re_set (struct breakpoint *b) | |
13318 | { | |
13319 | breakpoint_re_set_default (b); | |
13320 | } | |
876fa593 | 13321 | |
348d480f PA |
13322 | static int |
13323 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13324 | struct address_space *aspace, CORE_ADDR bp_addr, |
13325 | const struct target_waitstatus *ws) | |
348d480f PA |
13326 | { |
13327 | /* By definition, the inferior does not report stops at | |
13328 | tracepoints. */ | |
13329 | return 0; | |
74960c60 VP |
13330 | } |
13331 | ||
13332 | static void | |
348d480f PA |
13333 | tracepoint_print_one_detail (const struct breakpoint *self, |
13334 | struct ui_out *uiout) | |
74960c60 | 13335 | { |
d9b3f62e PA |
13336 | struct tracepoint *tp = (struct tracepoint *) self; |
13337 | if (tp->static_trace_marker_id) | |
348d480f PA |
13338 | { |
13339 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13340 | |
348d480f PA |
13341 | ui_out_text (uiout, "\tmarker id is "); |
13342 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13343 | tp->static_trace_marker_id); |
348d480f PA |
13344 | ui_out_text (uiout, "\n"); |
13345 | } | |
0d381245 VP |
13346 | } |
13347 | ||
a474d7c2 | 13348 | static void |
348d480f | 13349 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13350 | { |
79a45e25 | 13351 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13352 | return; |
cc59ec59 | 13353 | |
348d480f PA |
13354 | switch (b->type) |
13355 | { | |
13356 | case bp_tracepoint: | |
13357 | printf_filtered (_("Tracepoint")); | |
13358 | printf_filtered (_(" %d"), b->number); | |
13359 | break; | |
13360 | case bp_fast_tracepoint: | |
13361 | printf_filtered (_("Fast tracepoint")); | |
13362 | printf_filtered (_(" %d"), b->number); | |
13363 | break; | |
13364 | case bp_static_tracepoint: | |
13365 | printf_filtered (_("Static tracepoint")); | |
13366 | printf_filtered (_(" %d"), b->number); | |
13367 | break; | |
13368 | default: | |
13369 | internal_error (__FILE__, __LINE__, | |
13370 | _("unhandled tracepoint type %d"), (int) b->type); | |
13371 | } | |
13372 | ||
13373 | say_where (b); | |
a474d7c2 PA |
13374 | } |
13375 | ||
348d480f | 13376 | static void |
d9b3f62e | 13377 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13378 | { |
d9b3f62e PA |
13379 | struct tracepoint *tp = (struct tracepoint *) self; |
13380 | ||
13381 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13382 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13383 | if (self->type == bp_static_tracepoint) |
348d480f | 13384 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13385 | else if (self->type == bp_tracepoint) |
348d480f PA |
13386 | fprintf_unfiltered (fp, "trace"); |
13387 | else | |
13388 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13389 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13390 | |
d9b3f62e PA |
13391 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13392 | print_recreate_thread (self, fp); | |
13393 | ||
13394 | if (tp->pass_count) | |
13395 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13396 | } |
13397 | ||
983af33b SDJ |
13398 | static void |
13399 | tracepoint_create_sals_from_address (char **arg, | |
13400 | struct linespec_result *canonical, | |
13401 | enum bptype type_wanted, | |
13402 | char *addr_start, char **copy_arg) | |
13403 | { | |
13404 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13405 | addr_start, copy_arg); | |
13406 | } | |
13407 | ||
13408 | static void | |
13409 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13410 | struct linespec_result *canonical, | |
983af33b | 13411 | char *cond_string, |
e7e0cddf | 13412 | char *extra_string, |
983af33b SDJ |
13413 | enum bptype type_wanted, |
13414 | enum bpdisp disposition, | |
13415 | int thread, | |
13416 | int task, int ignore_count, | |
13417 | const struct breakpoint_ops *ops, | |
13418 | int from_tty, int enabled, | |
44f238bb | 13419 | int internal, unsigned flags) |
983af33b | 13420 | { |
023fa29b | 13421 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13422 | cond_string, extra_string, |
13423 | type_wanted, | |
983af33b SDJ |
13424 | disposition, thread, task, |
13425 | ignore_count, ops, from_tty, | |
44f238bb | 13426 | enabled, internal, flags); |
983af33b SDJ |
13427 | } |
13428 | ||
13429 | static void | |
13430 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13431 | struct symtabs_and_lines *sals) | |
13432 | { | |
13433 | decode_linespec_default (b, s, sals); | |
13434 | } | |
13435 | ||
2060206e | 13436 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13437 | |
55aa24fb SDJ |
13438 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13439 | static probe. */ | |
13440 | ||
13441 | static void | |
13442 | tracepoint_probe_create_sals_from_address (char **arg, | |
13443 | struct linespec_result *canonical, | |
13444 | enum bptype type_wanted, | |
13445 | char *addr_start, char **copy_arg) | |
13446 | { | |
13447 | /* We use the same method for breakpoint on probes. */ | |
13448 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13449 | addr_start, copy_arg); | |
13450 | } | |
13451 | ||
13452 | static void | |
13453 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13454 | struct symtabs_and_lines *sals) | |
13455 | { | |
13456 | /* We use the same method for breakpoint on probes. */ | |
13457 | bkpt_probe_decode_linespec (b, s, sals); | |
13458 | } | |
13459 | ||
13460 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13461 | ||
5c2b4418 HZ |
13462 | /* Dprintf breakpoint_ops methods. */ |
13463 | ||
13464 | static void | |
13465 | dprintf_re_set (struct breakpoint *b) | |
13466 | { | |
13467 | breakpoint_re_set_default (b); | |
13468 | ||
13469 | /* This breakpoint could have been pending, and be resolved now, and | |
13470 | if so, we should now have the extra string. If we don't, the | |
13471 | dprintf was malformed when created, but we couldn't tell because | |
13472 | we can't extract the extra string until the location is | |
13473 | resolved. */ | |
13474 | if (b->loc != NULL && b->extra_string == NULL) | |
13475 | error (_("Format string required")); | |
13476 | ||
13477 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13478 | 2 - create a dprintf, which resolves fine. | |
13479 | 3 - disconnect from target 1 | |
13480 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13481 | ||
13482 | After steps #3/#4, you'll want the dprintf command list to | |
13483 | be updated, because target 1 and 2 may well return different | |
13484 | answers for target_can_run_breakpoint_commands(). | |
13485 | Given absence of finer grained resetting, we get to do | |
13486 | it all the time. */ | |
13487 | if (b->extra_string != NULL) | |
13488 | update_dprintf_command_list (b); | |
13489 | } | |
13490 | ||
2d9442cc HZ |
13491 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13492 | ||
13493 | static void | |
13494 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13495 | { | |
13496 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13497 | tp->extra_string); | |
13498 | print_recreate_thread (tp, fp); | |
13499 | } | |
13500 | ||
9d6e6e84 HZ |
13501 | /* Implement the "after_condition_true" breakpoint_ops method for |
13502 | dprintf. | |
13503 | ||
13504 | dprintf's are implemented with regular commands in their command | |
13505 | list, but we run the commands here instead of before presenting the | |
13506 | stop to the user, as dprintf's don't actually cause a stop. This | |
13507 | also makes it so that the commands of multiple dprintfs at the same | |
13508 | address are all handled. */ | |
13509 | ||
13510 | static void | |
13511 | dprintf_after_condition_true (struct bpstats *bs) | |
13512 | { | |
13513 | struct cleanup *old_chain; | |
13514 | struct bpstats tmp_bs = { NULL }; | |
13515 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13516 | ||
13517 | /* dprintf's never cause a stop. This wasn't set in the | |
13518 | check_status hook instead because that would make the dprintf's | |
13519 | condition not be evaluated. */ | |
13520 | bs->stop = 0; | |
13521 | ||
13522 | /* Run the command list here. Take ownership of it instead of | |
13523 | copying. We never want these commands to run later in | |
13524 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13525 | be set at same address as this dprintf, or even if running the | |
13526 | commands here throws. */ | |
13527 | tmp_bs.commands = bs->commands; | |
13528 | bs->commands = NULL; | |
13529 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13530 | ||
13531 | bpstat_do_actions_1 (&tmp_bs_p); | |
13532 | ||
13533 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13534 | bpstat_do_actions_1 may return early without processing the whole | |
13535 | list. */ | |
13536 | do_cleanups (old_chain); | |
13537 | } | |
13538 | ||
983af33b SDJ |
13539 | /* The breakpoint_ops structure to be used on static tracepoints with |
13540 | markers (`-m'). */ | |
13541 | ||
13542 | static void | |
13543 | strace_marker_create_sals_from_address (char **arg, | |
13544 | struct linespec_result *canonical, | |
13545 | enum bptype type_wanted, | |
13546 | char *addr_start, char **copy_arg) | |
13547 | { | |
13548 | struct linespec_sals lsal; | |
13549 | ||
13550 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13551 | ||
13552 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13553 | ||
13554 | canonical->addr_string = xstrdup (*copy_arg); | |
13555 | lsal.canonical = xstrdup (*copy_arg); | |
13556 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13557 | } | |
13558 | ||
13559 | static void | |
13560 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13561 | struct linespec_result *canonical, | |
983af33b | 13562 | char *cond_string, |
e7e0cddf | 13563 | char *extra_string, |
983af33b SDJ |
13564 | enum bptype type_wanted, |
13565 | enum bpdisp disposition, | |
13566 | int thread, | |
13567 | int task, int ignore_count, | |
13568 | const struct breakpoint_ops *ops, | |
13569 | int from_tty, int enabled, | |
44f238bb | 13570 | int internal, unsigned flags) |
983af33b SDJ |
13571 | { |
13572 | int i; | |
52d361e1 YQ |
13573 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13574 | canonical->sals, 0); | |
983af33b SDJ |
13575 | |
13576 | /* If the user is creating a static tracepoint by marker id | |
13577 | (strace -m MARKER_ID), then store the sals index, so that | |
13578 | breakpoint_re_set can try to match up which of the newly | |
13579 | found markers corresponds to this one, and, don't try to | |
13580 | expand multiple locations for each sal, given than SALS | |
13581 | already should contain all sals for MARKER_ID. */ | |
13582 | ||
13583 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13584 | { | |
13585 | struct symtabs_and_lines expanded; | |
13586 | struct tracepoint *tp; | |
13587 | struct cleanup *old_chain; | |
13588 | char *addr_string; | |
13589 | ||
13590 | expanded.nelts = 1; | |
13591 | expanded.sals = &lsal->sals.sals[i]; | |
13592 | ||
13593 | addr_string = xstrdup (canonical->addr_string); | |
13594 | old_chain = make_cleanup (xfree, addr_string); | |
13595 | ||
13596 | tp = XCNEW (struct tracepoint); | |
13597 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13598 | addr_string, NULL, | |
e7e0cddf SS |
13599 | cond_string, extra_string, |
13600 | type_wanted, disposition, | |
983af33b | 13601 | thread, task, ignore_count, ops, |
44f238bb | 13602 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13603 | canonical->special_display); |
13604 | /* Given that its possible to have multiple markers with | |
13605 | the same string id, if the user is creating a static | |
13606 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13607 | store the sals index, so that breakpoint_re_set can | |
13608 | try to match up which of the newly found markers | |
13609 | corresponds to this one */ | |
13610 | tp->static_trace_marker_id_idx = i; | |
13611 | ||
13612 | install_breakpoint (internal, &tp->base, 0); | |
13613 | ||
13614 | discard_cleanups (old_chain); | |
13615 | } | |
13616 | } | |
13617 | ||
13618 | static void | |
13619 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13620 | struct symtabs_and_lines *sals) | |
13621 | { | |
13622 | struct tracepoint *tp = (struct tracepoint *) b; | |
13623 | ||
13624 | *sals = decode_static_tracepoint_spec (s); | |
13625 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13626 | { | |
13627 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13628 | sals->nelts = 1; | |
13629 | } | |
13630 | else | |
13631 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13632 | } | |
13633 | ||
13634 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13635 | ||
13636 | static int | |
13637 | strace_marker_p (struct breakpoint *b) | |
13638 | { | |
13639 | return b->ops == &strace_marker_breakpoint_ops; | |
13640 | } | |
13641 | ||
53a5351d | 13642 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13643 | structures. */ |
c906108c SS |
13644 | |
13645 | void | |
fba45db2 | 13646 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13647 | { |
52f0bd74 | 13648 | struct breakpoint *b; |
c906108c | 13649 | |
8a3fe4f8 | 13650 | gdb_assert (bpt != NULL); |
c906108c | 13651 | |
4a64f543 MS |
13652 | /* Has this bp already been deleted? This can happen because |
13653 | multiple lists can hold pointers to bp's. bpstat lists are | |
13654 | especial culprits. | |
13655 | ||
13656 | One example of this happening is a watchpoint's scope bp. When | |
13657 | the scope bp triggers, we notice that the watchpoint is out of | |
13658 | scope, and delete it. We also delete its scope bp. But the | |
13659 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13660 | That bpstat is then checked for auto-deleting bp's, which are | |
13661 | deleted. | |
13662 | ||
13663 | A real solution to this problem might involve reference counts in | |
13664 | bp's, and/or giving them pointers back to their referencing | |
13665 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13666 | storage when no more references were extent. A cheaper bandaid | |
13667 | was chosen. */ | |
c906108c SS |
13668 | if (bpt->type == bp_none) |
13669 | return; | |
13670 | ||
4a64f543 MS |
13671 | /* At least avoid this stale reference until the reference counting |
13672 | of breakpoints gets resolved. */ | |
d0fb5eae | 13673 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13674 | { |
d0fb5eae | 13675 | struct breakpoint *related; |
3a5c3e22 | 13676 | struct watchpoint *w; |
d0fb5eae JK |
13677 | |
13678 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13679 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13680 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13681 | w = (struct watchpoint *) bpt; |
13682 | else | |
13683 | w = NULL; | |
13684 | if (w != NULL) | |
13685 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13686 | |
13687 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13688 | for (related = bpt; related->related_breakpoint != bpt; | |
13689 | related = related->related_breakpoint); | |
13690 | related->related_breakpoint = bpt->related_breakpoint; | |
13691 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13692 | } |
13693 | ||
a9634178 TJB |
13694 | /* watch_command_1 creates a watchpoint but only sets its number if |
13695 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13696 | a problem in that process, we'll be asked to delete the half-created | |
13697 | watchpoint. In that case, don't announce the deletion. */ | |
13698 | if (bpt->number) | |
13699 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13700 | |
c906108c SS |
13701 | if (breakpoint_chain == bpt) |
13702 | breakpoint_chain = bpt->next; | |
13703 | ||
c906108c SS |
13704 | ALL_BREAKPOINTS (b) |
13705 | if (b->next == bpt) | |
c5aa993b JM |
13706 | { |
13707 | b->next = bpt->next; | |
13708 | break; | |
13709 | } | |
c906108c | 13710 | |
f431efe5 PA |
13711 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13712 | been freed. */ | |
13713 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13714 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13715 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13716 | commands are associated with the bpstat; if we remove it here, | |
13717 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13718 | event-top.c won't do anything, and temporary breakpoints with | |
13719 | commands won't work. */ | |
13720 | ||
13721 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13722 | ||
4a64f543 MS |
13723 | /* Now that breakpoint is removed from breakpoint list, update the |
13724 | global location list. This will remove locations that used to | |
13725 | belong to this breakpoint. Do this before freeing the breakpoint | |
13726 | itself, since remove_breakpoint looks at location's owner. It | |
13727 | might be better design to have location completely | |
13728 | self-contained, but it's not the case now. */ | |
b60e7edf | 13729 | update_global_location_list (0); |
74960c60 | 13730 | |
348d480f | 13731 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13732 | /* On the chance that someone will soon try again to delete this |
13733 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13734 | bpt->type = bp_none; |
b8c9b27d | 13735 | xfree (bpt); |
c906108c SS |
13736 | } |
13737 | ||
4d6140d9 AC |
13738 | static void |
13739 | do_delete_breakpoint_cleanup (void *b) | |
13740 | { | |
13741 | delete_breakpoint (b); | |
13742 | } | |
13743 | ||
13744 | struct cleanup * | |
13745 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13746 | { | |
13747 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13748 | } | |
13749 | ||
51be5b68 PA |
13750 | /* Iterator function to call a user-provided callback function once |
13751 | for each of B and its related breakpoints. */ | |
13752 | ||
13753 | static void | |
13754 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13755 | void (*function) (struct breakpoint *, | |
13756 | void *), | |
13757 | void *data) | |
13758 | { | |
13759 | struct breakpoint *related; | |
13760 | ||
13761 | related = b; | |
13762 | do | |
13763 | { | |
13764 | struct breakpoint *next; | |
13765 | ||
13766 | /* FUNCTION may delete RELATED. */ | |
13767 | next = related->related_breakpoint; | |
13768 | ||
13769 | if (next == related) | |
13770 | { | |
13771 | /* RELATED is the last ring entry. */ | |
13772 | function (related, data); | |
13773 | ||
13774 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13775 | B. There's nothing left to do anyway, so just break | |
13776 | out. */ | |
13777 | break; | |
13778 | } | |
13779 | else | |
13780 | function (related, data); | |
13781 | ||
13782 | related = next; | |
13783 | } | |
13784 | while (related != b); | |
13785 | } | |
95a42b64 TT |
13786 | |
13787 | static void | |
13788 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13789 | { | |
13790 | delete_breakpoint (b); | |
13791 | } | |
13792 | ||
51be5b68 PA |
13793 | /* A callback for map_breakpoint_numbers that calls |
13794 | delete_breakpoint. */ | |
13795 | ||
13796 | static void | |
13797 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13798 | { | |
13799 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13800 | } | |
13801 | ||
c906108c | 13802 | void |
fba45db2 | 13803 | delete_command (char *arg, int from_tty) |
c906108c | 13804 | { |
35df4500 | 13805 | struct breakpoint *b, *b_tmp; |
c906108c | 13806 | |
ea9365bb TT |
13807 | dont_repeat (); |
13808 | ||
c906108c SS |
13809 | if (arg == 0) |
13810 | { | |
13811 | int breaks_to_delete = 0; | |
13812 | ||
46c6471b PA |
13813 | /* Delete all breakpoints if no argument. Do not delete |
13814 | internal breakpoints, these have to be deleted with an | |
13815 | explicit breakpoint number argument. */ | |
c5aa993b | 13816 | ALL_BREAKPOINTS (b) |
46c6471b | 13817 | if (user_breakpoint_p (b)) |
973d738b DJ |
13818 | { |
13819 | breaks_to_delete = 1; | |
13820 | break; | |
13821 | } | |
c906108c SS |
13822 | |
13823 | /* Ask user only if there are some breakpoints to delete. */ | |
13824 | if (!from_tty | |
e2e0b3e5 | 13825 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13826 | { |
35df4500 | 13827 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13828 | if (user_breakpoint_p (b)) |
c5aa993b | 13829 | delete_breakpoint (b); |
c906108c SS |
13830 | } |
13831 | } | |
13832 | else | |
51be5b68 | 13833 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13834 | } |
13835 | ||
0d381245 VP |
13836 | static int |
13837 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13838 | { |
0d381245 | 13839 | for (; loc; loc = loc->next) |
8645ff69 UW |
13840 | if (!loc->shlib_disabled |
13841 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13842 | return 0; |
13843 | return 1; | |
fe3f5fa8 VP |
13844 | } |
13845 | ||
776592bf DE |
13846 | /* Subroutine of update_breakpoint_locations to simplify it. |
13847 | Return non-zero if multiple fns in list LOC have the same name. | |
13848 | Null names are ignored. */ | |
13849 | ||
13850 | static int | |
13851 | ambiguous_names_p (struct bp_location *loc) | |
13852 | { | |
13853 | struct bp_location *l; | |
13854 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13855 | (int (*) (const void *, |
13856 | const void *)) streq, | |
776592bf DE |
13857 | NULL, xcalloc, xfree); |
13858 | ||
13859 | for (l = loc; l != NULL; l = l->next) | |
13860 | { | |
13861 | const char **slot; | |
13862 | const char *name = l->function_name; | |
13863 | ||
13864 | /* Allow for some names to be NULL, ignore them. */ | |
13865 | if (name == NULL) | |
13866 | continue; | |
13867 | ||
13868 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13869 | INSERT); | |
4a64f543 MS |
13870 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13871 | returns NULL. */ | |
776592bf DE |
13872 | if (*slot != NULL) |
13873 | { | |
13874 | htab_delete (htab); | |
13875 | return 1; | |
13876 | } | |
13877 | *slot = name; | |
13878 | } | |
13879 | ||
13880 | htab_delete (htab); | |
13881 | return 0; | |
13882 | } | |
13883 | ||
0fb4aa4b PA |
13884 | /* When symbols change, it probably means the sources changed as well, |
13885 | and it might mean the static tracepoint markers are no longer at | |
13886 | the same address or line numbers they used to be at last we | |
13887 | checked. Losing your static tracepoints whenever you rebuild is | |
13888 | undesirable. This function tries to resync/rematch gdb static | |
13889 | tracepoints with the markers on the target, for static tracepoints | |
13890 | that have not been set by marker id. Static tracepoint that have | |
13891 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13892 | The heuristic is: | |
13893 | ||
13894 | 1) For a tracepoint set at a specific address, look for a marker at | |
13895 | the old PC. If one is found there, assume to be the same marker. | |
13896 | If the name / string id of the marker found is different from the | |
13897 | previous known name, assume that means the user renamed the marker | |
13898 | in the sources, and output a warning. | |
13899 | ||
13900 | 2) For a tracepoint set at a given line number, look for a marker | |
13901 | at the new address of the old line number. If one is found there, | |
13902 | assume to be the same marker. If the name / string id of the | |
13903 | marker found is different from the previous known name, assume that | |
13904 | means the user renamed the marker in the sources, and output a | |
13905 | warning. | |
13906 | ||
13907 | 3) If a marker is no longer found at the same address or line, it | |
13908 | may mean the marker no longer exists. But it may also just mean | |
13909 | the code changed a bit. Maybe the user added a few lines of code | |
13910 | that made the marker move up or down (in line number terms). Ask | |
13911 | the target for info about the marker with the string id as we knew | |
13912 | it. If found, update line number and address in the matching | |
13913 | static tracepoint. This will get confused if there's more than one | |
13914 | marker with the same ID (possible in UST, although unadvised | |
13915 | precisely because it confuses tools). */ | |
13916 | ||
13917 | static struct symtab_and_line | |
13918 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13919 | { | |
d9b3f62e | 13920 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13921 | struct static_tracepoint_marker marker; |
13922 | CORE_ADDR pc; | |
0fb4aa4b PA |
13923 | |
13924 | pc = sal.pc; | |
13925 | if (sal.line) | |
13926 | find_line_pc (sal.symtab, sal.line, &pc); | |
13927 | ||
13928 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13929 | { | |
d9b3f62e | 13930 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13931 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13932 | b->number, | |
d9b3f62e | 13933 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13934 | |
d9b3f62e PA |
13935 | xfree (tp->static_trace_marker_id); |
13936 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13937 | release_static_tracepoint_marker (&marker); |
13938 | ||
13939 | return sal; | |
13940 | } | |
13941 | ||
13942 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13943 | by string ID. */ | |
13944 | if (!sal.explicit_pc | |
13945 | && sal.line != 0 | |
13946 | && sal.symtab != NULL | |
d9b3f62e | 13947 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13948 | { |
13949 | VEC(static_tracepoint_marker_p) *markers; | |
13950 | ||
13951 | markers | |
d9b3f62e | 13952 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13953 | |
13954 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13955 | { | |
80e1d417 | 13956 | struct symtab_and_line sal2; |
0fb4aa4b | 13957 | struct symbol *sym; |
80e1d417 | 13958 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13959 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 13960 | |
80e1d417 | 13961 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13962 | |
d9b3f62e | 13963 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13964 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13965 | |
13966 | warning (_("marker for static tracepoint %d (%s) not " | |
13967 | "found at previous line number"), | |
d9b3f62e | 13968 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13969 | |
80e1d417 | 13970 | init_sal (&sal2); |
0fb4aa4b | 13971 | |
80e1d417 | 13972 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13973 | |
80e1d417 AS |
13974 | sal2 = find_pc_line (tpmarker->address, 0); |
13975 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13976 | ui_out_text (uiout, "Now in "); |
13977 | if (sym) | |
13978 | { | |
13979 | ui_out_field_string (uiout, "func", | |
13980 | SYMBOL_PRINT_NAME (sym)); | |
13981 | ui_out_text (uiout, " at "); | |
13982 | } | |
05cba821 JK |
13983 | ui_out_field_string (uiout, "file", |
13984 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
13985 | ui_out_text (uiout, ":"); |
13986 | ||
13987 | if (ui_out_is_mi_like_p (uiout)) | |
13988 | { | |
0b0865da | 13989 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13990 | |
f35a17b5 | 13991 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
13992 | } |
13993 | ||
80e1d417 | 13994 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13995 | ui_out_text (uiout, "\n"); |
13996 | ||
80e1d417 | 13997 | b->loc->line_number = sal2.line; |
2f202fde | 13998 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
13999 | |
14000 | xfree (b->addr_string); | |
14001 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14002 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14003 | b->loc->line_number); |
0fb4aa4b PA |
14004 | |
14005 | /* Might be nice to check if function changed, and warn if | |
14006 | so. */ | |
14007 | ||
80e1d417 | 14008 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14009 | } |
14010 | } | |
14011 | return sal; | |
14012 | } | |
14013 | ||
8d3788bd VP |
14014 | /* Returns 1 iff locations A and B are sufficiently same that |
14015 | we don't need to report breakpoint as changed. */ | |
14016 | ||
14017 | static int | |
14018 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14019 | { | |
14020 | while (a && b) | |
14021 | { | |
14022 | if (a->address != b->address) | |
14023 | return 0; | |
14024 | ||
14025 | if (a->shlib_disabled != b->shlib_disabled) | |
14026 | return 0; | |
14027 | ||
14028 | if (a->enabled != b->enabled) | |
14029 | return 0; | |
14030 | ||
14031 | a = a->next; | |
14032 | b = b->next; | |
14033 | } | |
14034 | ||
14035 | if ((a == NULL) != (b == NULL)) | |
14036 | return 0; | |
14037 | ||
14038 | return 1; | |
14039 | } | |
14040 | ||
f1310107 TJB |
14041 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14042 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14043 | a ranged breakpoint. */ | |
14044 | ||
0e30163f | 14045 | void |
0d381245 | 14046 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14047 | struct symtabs_and_lines sals, |
14048 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14049 | { |
14050 | int i; | |
0d381245 VP |
14051 | struct bp_location *existing_locations = b->loc; |
14052 | ||
f8eba3c6 TT |
14053 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14054 | { | |
14055 | /* Ranged breakpoints have only one start location and one end | |
14056 | location. */ | |
14057 | b->enable_state = bp_disabled; | |
14058 | update_global_location_list (1); | |
14059 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14060 | "multiple locations found\n"), | |
14061 | b->number); | |
14062 | return; | |
14063 | } | |
f1310107 | 14064 | |
4a64f543 MS |
14065 | /* If there's no new locations, and all existing locations are |
14066 | pending, don't do anything. This optimizes the common case where | |
14067 | all locations are in the same shared library, that was unloaded. | |
14068 | We'd like to retain the location, so that when the library is | |
14069 | loaded again, we don't loose the enabled/disabled status of the | |
14070 | individual locations. */ | |
0d381245 | 14071 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14072 | return; |
14073 | ||
fe3f5fa8 VP |
14074 | b->loc = NULL; |
14075 | ||
0d381245 | 14076 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14077 | { |
f8eba3c6 TT |
14078 | struct bp_location *new_loc; |
14079 | ||
14080 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14081 | ||
14082 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14083 | |
0d381245 VP |
14084 | /* Reparse conditions, they might contain references to the |
14085 | old symtab. */ | |
14086 | if (b->cond_string != NULL) | |
14087 | { | |
bbc13ae3 | 14088 | const char *s; |
bfd189b1 | 14089 | volatile struct gdb_exception e; |
fe3f5fa8 | 14090 | |
0d381245 VP |
14091 | s = b->cond_string; |
14092 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14093 | { | |
1bb9788d TT |
14094 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14095 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14096 | 0); |
14097 | } | |
14098 | if (e.reason < 0) | |
14099 | { | |
3e43a32a MS |
14100 | warning (_("failed to reevaluate condition " |
14101 | "for breakpoint %d: %s"), | |
0d381245 VP |
14102 | b->number, e.message); |
14103 | new_loc->enabled = 0; | |
14104 | } | |
14105 | } | |
fe3f5fa8 | 14106 | |
f1310107 TJB |
14107 | if (sals_end.nelts) |
14108 | { | |
14109 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14110 | ||
14111 | new_loc->length = end - sals.sals[0].pc + 1; | |
14112 | } | |
0d381245 | 14113 | } |
fe3f5fa8 | 14114 | |
514f746b AR |
14115 | /* Update locations of permanent breakpoints. */ |
14116 | if (b->enable_state == bp_permanent) | |
14117 | make_breakpoint_permanent (b); | |
14118 | ||
4a64f543 MS |
14119 | /* If possible, carry over 'disable' status from existing |
14120 | breakpoints. */ | |
0d381245 VP |
14121 | { |
14122 | struct bp_location *e = existing_locations; | |
776592bf DE |
14123 | /* If there are multiple breakpoints with the same function name, |
14124 | e.g. for inline functions, comparing function names won't work. | |
14125 | Instead compare pc addresses; this is just a heuristic as things | |
14126 | may have moved, but in practice it gives the correct answer | |
14127 | often enough until a better solution is found. */ | |
14128 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14129 | ||
0d381245 VP |
14130 | for (; e; e = e->next) |
14131 | { | |
14132 | if (!e->enabled && e->function_name) | |
14133 | { | |
14134 | struct bp_location *l = b->loc; | |
776592bf DE |
14135 | if (have_ambiguous_names) |
14136 | { | |
14137 | for (; l; l = l->next) | |
f1310107 | 14138 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14139 | { |
14140 | l->enabled = 0; | |
14141 | break; | |
14142 | } | |
14143 | } | |
14144 | else | |
14145 | { | |
14146 | for (; l; l = l->next) | |
14147 | if (l->function_name | |
14148 | && strcmp (e->function_name, l->function_name) == 0) | |
14149 | { | |
14150 | l->enabled = 0; | |
14151 | break; | |
14152 | } | |
14153 | } | |
0d381245 VP |
14154 | } |
14155 | } | |
14156 | } | |
fe3f5fa8 | 14157 | |
8d3788bd VP |
14158 | if (!locations_are_equal (existing_locations, b->loc)) |
14159 | observer_notify_breakpoint_modified (b); | |
14160 | ||
b60e7edf | 14161 | update_global_location_list (1); |
fe3f5fa8 VP |
14162 | } |
14163 | ||
ef23e705 TJB |
14164 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14165 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14166 | ||
14167 | static struct symtabs_and_lines | |
14168 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14169 | { | |
14170 | char *s; | |
02d20e4a | 14171 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14172 | volatile struct gdb_exception e; |
ef23e705 | 14173 | |
983af33b | 14174 | gdb_assert (b->ops != NULL); |
ef23e705 | 14175 | s = addr_string; |
ef23e705 TJB |
14176 | |
14177 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14178 | { | |
983af33b | 14179 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14180 | } |
14181 | if (e.reason < 0) | |
14182 | { | |
14183 | int not_found_and_ok = 0; | |
14184 | /* For pending breakpoints, it's expected that parsing will | |
14185 | fail until the right shared library is loaded. User has | |
14186 | already told to create pending breakpoints and don't need | |
14187 | extra messages. If breakpoint is in bp_shlib_disabled | |
14188 | state, then user already saw the message about that | |
14189 | breakpoint being disabled, and don't want to see more | |
14190 | errors. */ | |
58438ac1 | 14191 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14192 | && (b->condition_not_parsed |
14193 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14194 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14195 | || b->enable_state == bp_disabled)) |
14196 | not_found_and_ok = 1; | |
14197 | ||
14198 | if (!not_found_and_ok) | |
14199 | { | |
14200 | /* We surely don't want to warn about the same breakpoint | |
14201 | 10 times. One solution, implemented here, is disable | |
14202 | the breakpoint on error. Another solution would be to | |
14203 | have separate 'warning emitted' flag. Since this | |
14204 | happens only when a binary has changed, I don't know | |
14205 | which approach is better. */ | |
14206 | b->enable_state = bp_disabled; | |
14207 | throw_exception (e); | |
14208 | } | |
14209 | } | |
14210 | ||
58438ac1 | 14211 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14212 | { |
f8eba3c6 | 14213 | int i; |
ef23e705 | 14214 | |
f8eba3c6 TT |
14215 | for (i = 0; i < sals.nelts; ++i) |
14216 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14217 | if (b->condition_not_parsed && s && s[0]) |
14218 | { | |
ed1d1739 KS |
14219 | char *cond_string, *extra_string; |
14220 | int thread, task; | |
ef23e705 TJB |
14221 | |
14222 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14223 | &cond_string, &thread, &task, |
14224 | &extra_string); | |
ef23e705 TJB |
14225 | if (cond_string) |
14226 | b->cond_string = cond_string; | |
14227 | b->thread = thread; | |
14228 | b->task = task; | |
e7e0cddf SS |
14229 | if (extra_string) |
14230 | b->extra_string = extra_string; | |
ef23e705 TJB |
14231 | b->condition_not_parsed = 0; |
14232 | } | |
14233 | ||
983af33b | 14234 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14235 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14236 | |
58438ac1 TT |
14237 | *found = 1; |
14238 | } | |
14239 | else | |
14240 | *found = 0; | |
ef23e705 TJB |
14241 | |
14242 | return sals; | |
14243 | } | |
14244 | ||
348d480f PA |
14245 | /* The default re_set method, for typical hardware or software |
14246 | breakpoints. Reevaluate the breakpoint and recreate its | |
14247 | locations. */ | |
14248 | ||
14249 | static void | |
28010a5d | 14250 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14251 | { |
14252 | int found; | |
f1310107 | 14253 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14254 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14255 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14256 | |
14257 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14258 | if (found) | |
14259 | { | |
14260 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14261 | expanded = sals; |
ef23e705 TJB |
14262 | } |
14263 | ||
f1310107 TJB |
14264 | if (b->addr_string_range_end) |
14265 | { | |
14266 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14267 | if (found) | |
14268 | { | |
14269 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14270 | expanded_end = sals_end; |
f1310107 TJB |
14271 | } |
14272 | } | |
14273 | ||
14274 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14275 | } |
14276 | ||
983af33b SDJ |
14277 | /* Default method for creating SALs from an address string. It basically |
14278 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14279 | ||
14280 | static void | |
14281 | create_sals_from_address_default (char **arg, | |
14282 | struct linespec_result *canonical, | |
14283 | enum bptype type_wanted, | |
14284 | char *addr_start, char **copy_arg) | |
14285 | { | |
14286 | parse_breakpoint_sals (arg, canonical); | |
14287 | } | |
14288 | ||
14289 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14290 | function for the `create_breakpoints_sal' method of | |
14291 | breakpoint_ops. */ | |
14292 | ||
14293 | static void | |
14294 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14295 | struct linespec_result *canonical, | |
983af33b | 14296 | char *cond_string, |
e7e0cddf | 14297 | char *extra_string, |
983af33b SDJ |
14298 | enum bptype type_wanted, |
14299 | enum bpdisp disposition, | |
14300 | int thread, | |
14301 | int task, int ignore_count, | |
14302 | const struct breakpoint_ops *ops, | |
14303 | int from_tty, int enabled, | |
44f238bb | 14304 | int internal, unsigned flags) |
983af33b SDJ |
14305 | { |
14306 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14307 | extra_string, |
983af33b SDJ |
14308 | type_wanted, disposition, |
14309 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14310 | enabled, internal, flags); |
983af33b SDJ |
14311 | } |
14312 | ||
14313 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14314 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14315 | ||
14316 | static void | |
14317 | decode_linespec_default (struct breakpoint *b, char **s, | |
14318 | struct symtabs_and_lines *sals) | |
14319 | { | |
14320 | struct linespec_result canonical; | |
14321 | ||
14322 | init_linespec_result (&canonical); | |
14323 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14324 | (struct symtab *) NULL, 0, | |
14325 | &canonical, multiple_symbols_all, | |
14326 | b->filter); | |
14327 | ||
14328 | /* We should get 0 or 1 resulting SALs. */ | |
14329 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14330 | ||
14331 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14332 | { | |
14333 | struct linespec_sals *lsal; | |
14334 | ||
14335 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14336 | *sals = lsal->sals; | |
14337 | /* Arrange it so the destructor does not free the | |
14338 | contents. */ | |
14339 | lsal->sals.sals = NULL; | |
14340 | } | |
14341 | ||
14342 | destroy_linespec_result (&canonical); | |
14343 | } | |
14344 | ||
28010a5d PA |
14345 | /* Prepare the global context for a re-set of breakpoint B. */ |
14346 | ||
14347 | static struct cleanup * | |
14348 | prepare_re_set_context (struct breakpoint *b) | |
14349 | { | |
14350 | struct cleanup *cleanups; | |
14351 | ||
14352 | input_radix = b->input_radix; | |
14353 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14354 | if (b->pspace != NULL) |
14355 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14356 | set_language (b->language); |
14357 | ||
14358 | return cleanups; | |
ef23e705 TJB |
14359 | } |
14360 | ||
c906108c SS |
14361 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14362 | The value we return ends up being the return value from catch_errors. | |
14363 | Unused in this case. */ | |
14364 | ||
14365 | static int | |
4efb68b1 | 14366 | breakpoint_re_set_one (void *bint) |
c906108c | 14367 | { |
4a64f543 | 14368 | /* Get past catch_errs. */ |
53a5351d | 14369 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14370 | struct cleanup *cleanups; |
c906108c | 14371 | |
348d480f PA |
14372 | cleanups = prepare_re_set_context (b); |
14373 | b->ops->re_set (b); | |
14374 | do_cleanups (cleanups); | |
c906108c SS |
14375 | return 0; |
14376 | } | |
14377 | ||
69de3c6a | 14378 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14379 | void |
69de3c6a | 14380 | breakpoint_re_set (void) |
c906108c | 14381 | { |
35df4500 | 14382 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14383 | enum language save_language; |
14384 | int save_input_radix; | |
6c95b8df | 14385 | struct cleanup *old_chain; |
c5aa993b | 14386 | |
c906108c SS |
14387 | save_language = current_language->la_language; |
14388 | save_input_radix = input_radix; | |
6c95b8df PA |
14389 | old_chain = save_current_program_space (); |
14390 | ||
35df4500 | 14391 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14392 | { |
4a64f543 | 14393 | /* Format possible error msg. */ |
fe3f5fa8 | 14394 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14395 | b->number); |
14396 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14397 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14398 | do_cleanups (cleanups); |
c5aa993b | 14399 | } |
c906108c SS |
14400 | set_language (save_language); |
14401 | input_radix = save_input_radix; | |
e62c965a | 14402 | |
0756c555 | 14403 | jit_breakpoint_re_set (); |
4efc6507 | 14404 | |
6c95b8df PA |
14405 | do_cleanups (old_chain); |
14406 | ||
af02033e PP |
14407 | create_overlay_event_breakpoint (); |
14408 | create_longjmp_master_breakpoint (); | |
14409 | create_std_terminate_master_breakpoint (); | |
186c406b | 14410 | create_exception_master_breakpoint (); |
c906108c SS |
14411 | } |
14412 | \f | |
c906108c SS |
14413 | /* Reset the thread number of this breakpoint: |
14414 | ||
14415 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14416 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14417 | void |
fba45db2 | 14418 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14419 | { |
14420 | if (b->thread != -1) | |
14421 | { | |
39f77062 KB |
14422 | if (in_thread_list (inferior_ptid)) |
14423 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14424 | |
14425 | /* We're being called after following a fork. The new fork is | |
14426 | selected as current, and unless this was a vfork will have a | |
14427 | different program space from the original thread. Reset that | |
14428 | as well. */ | |
14429 | b->loc->pspace = current_program_space; | |
c906108c SS |
14430 | } |
14431 | } | |
14432 | ||
03ac34d5 MS |
14433 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14434 | If from_tty is nonzero, it prints a message to that effect, | |
14435 | which ends with a period (no newline). */ | |
14436 | ||
c906108c | 14437 | void |
fba45db2 | 14438 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14439 | { |
52f0bd74 | 14440 | struct breakpoint *b; |
c906108c SS |
14441 | |
14442 | if (count < 0) | |
14443 | count = 0; | |
14444 | ||
14445 | ALL_BREAKPOINTS (b) | |
14446 | if (b->number == bptnum) | |
c5aa993b | 14447 | { |
d77f58be SS |
14448 | if (is_tracepoint (b)) |
14449 | { | |
14450 | if (from_tty && count != 0) | |
14451 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14452 | bptnum); | |
14453 | return; | |
14454 | } | |
14455 | ||
c5aa993b | 14456 | b->ignore_count = count; |
221ea385 KS |
14457 | if (from_tty) |
14458 | { | |
14459 | if (count == 0) | |
3e43a32a MS |
14460 | printf_filtered (_("Will stop next time " |
14461 | "breakpoint %d is reached."), | |
221ea385 KS |
14462 | bptnum); |
14463 | else if (count == 1) | |
a3f17187 | 14464 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14465 | bptnum); |
14466 | else | |
3e43a32a MS |
14467 | printf_filtered (_("Will ignore next %d " |
14468 | "crossings of breakpoint %d."), | |
221ea385 KS |
14469 | count, bptnum); |
14470 | } | |
8d3788bd | 14471 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14472 | return; |
14473 | } | |
c906108c | 14474 | |
8a3fe4f8 | 14475 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14476 | } |
14477 | ||
c906108c SS |
14478 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14479 | ||
14480 | static void | |
fba45db2 | 14481 | ignore_command (char *args, int from_tty) |
c906108c SS |
14482 | { |
14483 | char *p = args; | |
52f0bd74 | 14484 | int num; |
c906108c SS |
14485 | |
14486 | if (p == 0) | |
e2e0b3e5 | 14487 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14488 | |
c906108c | 14489 | num = get_number (&p); |
5c44784c | 14490 | if (num == 0) |
8a3fe4f8 | 14491 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14492 | if (*p == 0) |
8a3fe4f8 | 14493 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14494 | |
14495 | set_ignore_count (num, | |
14496 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14497 | from_tty); | |
221ea385 KS |
14498 | if (from_tty) |
14499 | printf_filtered ("\n"); | |
c906108c SS |
14500 | } |
14501 | \f | |
14502 | /* Call FUNCTION on each of the breakpoints | |
14503 | whose numbers are given in ARGS. */ | |
14504 | ||
14505 | static void | |
95a42b64 TT |
14506 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14507 | void *), | |
14508 | void *data) | |
c906108c | 14509 | { |
52f0bd74 AC |
14510 | int num; |
14511 | struct breakpoint *b, *tmp; | |
11cf8741 | 14512 | int match; |
197f0a60 | 14513 | struct get_number_or_range_state state; |
c906108c | 14514 | |
197f0a60 | 14515 | if (args == 0) |
e2e0b3e5 | 14516 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14517 | |
197f0a60 TT |
14518 | init_number_or_range (&state, args); |
14519 | ||
14520 | while (!state.finished) | |
c906108c | 14521 | { |
197f0a60 TT |
14522 | char *p = state.string; |
14523 | ||
11cf8741 | 14524 | match = 0; |
c5aa993b | 14525 | |
197f0a60 | 14526 | num = get_number_or_range (&state); |
5c44784c | 14527 | if (num == 0) |
c5aa993b | 14528 | { |
8a3fe4f8 | 14529 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14530 | } |
14531 | else | |
14532 | { | |
14533 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14534 | if (b->number == num) | |
14535 | { | |
11cf8741 | 14536 | match = 1; |
cdac0397 | 14537 | function (b, data); |
11cf8741 | 14538 | break; |
5c44784c | 14539 | } |
11cf8741 | 14540 | if (match == 0) |
a3f17187 | 14541 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14542 | } |
c906108c SS |
14543 | } |
14544 | } | |
14545 | ||
0d381245 VP |
14546 | static struct bp_location * |
14547 | find_location_by_number (char *number) | |
14548 | { | |
14549 | char *dot = strchr (number, '.'); | |
14550 | char *p1; | |
14551 | int bp_num; | |
14552 | int loc_num; | |
14553 | struct breakpoint *b; | |
14554 | struct bp_location *loc; | |
14555 | ||
14556 | *dot = '\0'; | |
14557 | ||
14558 | p1 = number; | |
197f0a60 | 14559 | bp_num = get_number (&p1); |
0d381245 VP |
14560 | if (bp_num == 0) |
14561 | error (_("Bad breakpoint number '%s'"), number); | |
14562 | ||
14563 | ALL_BREAKPOINTS (b) | |
14564 | if (b->number == bp_num) | |
14565 | { | |
14566 | break; | |
14567 | } | |
14568 | ||
14569 | if (!b || b->number != bp_num) | |
14570 | error (_("Bad breakpoint number '%s'"), number); | |
14571 | ||
14572 | p1 = dot+1; | |
197f0a60 | 14573 | loc_num = get_number (&p1); |
0d381245 VP |
14574 | if (loc_num == 0) |
14575 | error (_("Bad breakpoint location number '%s'"), number); | |
14576 | ||
14577 | --loc_num; | |
14578 | loc = b->loc; | |
14579 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14580 | ; | |
14581 | if (!loc) | |
14582 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14583 | ||
14584 | return loc; | |
14585 | } | |
14586 | ||
14587 | ||
1900040c MS |
14588 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14589 | If from_tty is nonzero, it prints a message to that effect, | |
14590 | which ends with a period (no newline). */ | |
14591 | ||
c906108c | 14592 | void |
fba45db2 | 14593 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14594 | { |
14595 | /* Never disable a watchpoint scope breakpoint; we want to | |
14596 | hit them when we leave scope so we can delete both the | |
14597 | watchpoint and its scope breakpoint at that time. */ | |
14598 | if (bpt->type == bp_watchpoint_scope) | |
14599 | return; | |
14600 | ||
c2c6d25f | 14601 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14602 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14603 | return; |
14604 | ||
b5de0fa7 | 14605 | bpt->enable_state = bp_disabled; |
c906108c | 14606 | |
b775012e LM |
14607 | /* Mark breakpoint locations modified. */ |
14608 | mark_breakpoint_modified (bpt); | |
14609 | ||
d248b706 KY |
14610 | if (target_supports_enable_disable_tracepoint () |
14611 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14612 | { | |
14613 | struct bp_location *location; | |
14614 | ||
14615 | for (location = bpt->loc; location; location = location->next) | |
14616 | target_disable_tracepoint (location); | |
14617 | } | |
14618 | ||
b60e7edf | 14619 | update_global_location_list (0); |
c906108c | 14620 | |
8d3788bd | 14621 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14622 | } |
14623 | ||
51be5b68 PA |
14624 | /* A callback for iterate_over_related_breakpoints. */ |
14625 | ||
14626 | static void | |
14627 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14628 | { | |
14629 | disable_breakpoint (b); | |
14630 | } | |
14631 | ||
95a42b64 TT |
14632 | /* A callback for map_breakpoint_numbers that calls |
14633 | disable_breakpoint. */ | |
14634 | ||
14635 | static void | |
14636 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14637 | { | |
51be5b68 | 14638 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14639 | } |
14640 | ||
c906108c | 14641 | static void |
fba45db2 | 14642 | disable_command (char *args, int from_tty) |
c906108c | 14643 | { |
c906108c | 14644 | if (args == 0) |
46c6471b PA |
14645 | { |
14646 | struct breakpoint *bpt; | |
14647 | ||
14648 | ALL_BREAKPOINTS (bpt) | |
14649 | if (user_breakpoint_p (bpt)) | |
14650 | disable_breakpoint (bpt); | |
14651 | } | |
9eaabc75 | 14652 | else |
0d381245 | 14653 | { |
9eaabc75 MW |
14654 | char *num = extract_arg (&args); |
14655 | ||
14656 | while (num) | |
d248b706 | 14657 | { |
9eaabc75 | 14658 | if (strchr (num, '.')) |
b775012e | 14659 | { |
9eaabc75 MW |
14660 | struct bp_location *loc = find_location_by_number (num); |
14661 | ||
14662 | if (loc) | |
14663 | { | |
14664 | if (loc->enabled) | |
14665 | { | |
14666 | loc->enabled = 0; | |
14667 | mark_breakpoint_location_modified (loc); | |
14668 | } | |
14669 | if (target_supports_enable_disable_tracepoint () | |
14670 | && current_trace_status ()->running && loc->owner | |
14671 | && is_tracepoint (loc->owner)) | |
14672 | target_disable_tracepoint (loc); | |
14673 | } | |
14674 | update_global_location_list (0); | |
b775012e | 14675 | } |
9eaabc75 MW |
14676 | else |
14677 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14678 | num = extract_arg (&args); | |
d248b706 | 14679 | } |
0d381245 | 14680 | } |
c906108c SS |
14681 | } |
14682 | ||
14683 | static void | |
816338b5 SS |
14684 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14685 | int count) | |
c906108c | 14686 | { |
afe38095 | 14687 | int target_resources_ok; |
c906108c SS |
14688 | |
14689 | if (bpt->type == bp_hardware_breakpoint) | |
14690 | { | |
14691 | int i; | |
c5aa993b | 14692 | i = hw_breakpoint_used_count (); |
53a5351d | 14693 | target_resources_ok = |
d92524f1 | 14694 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14695 | i + 1, 0); |
c906108c | 14696 | if (target_resources_ok == 0) |
8a3fe4f8 | 14697 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14698 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14699 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14700 | } |
14701 | ||
cc60f2e3 | 14702 | if (is_watchpoint (bpt)) |
c906108c | 14703 | { |
d07205c2 JK |
14704 | /* Initialize it just to avoid a GCC false warning. */ |
14705 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14706 | volatile struct gdb_exception e; |
dde02812 ES |
14707 | |
14708 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14709 | { |
3a5c3e22 PA |
14710 | struct watchpoint *w = (struct watchpoint *) bpt; |
14711 | ||
1e718ff1 TJB |
14712 | orig_enable_state = bpt->enable_state; |
14713 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14714 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14715 | } |
dde02812 | 14716 | if (e.reason < 0) |
c5aa993b | 14717 | { |
1e718ff1 | 14718 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14719 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14720 | bpt->number); | |
14721 | return; | |
c5aa993b | 14722 | } |
c906108c | 14723 | } |
0101ce28 | 14724 | |
b4c291bb KH |
14725 | if (bpt->enable_state != bp_permanent) |
14726 | bpt->enable_state = bp_enabled; | |
d248b706 | 14727 | |
b775012e LM |
14728 | bpt->enable_state = bp_enabled; |
14729 | ||
14730 | /* Mark breakpoint locations modified. */ | |
14731 | mark_breakpoint_modified (bpt); | |
14732 | ||
d248b706 KY |
14733 | if (target_supports_enable_disable_tracepoint () |
14734 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14735 | { | |
14736 | struct bp_location *location; | |
14737 | ||
14738 | for (location = bpt->loc; location; location = location->next) | |
14739 | target_enable_tracepoint (location); | |
14740 | } | |
14741 | ||
b4c291bb | 14742 | bpt->disposition = disposition; |
816338b5 | 14743 | bpt->enable_count = count; |
b60e7edf | 14744 | update_global_location_list (1); |
9c97429f | 14745 | |
8d3788bd | 14746 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14747 | } |
14748 | ||
fe3f5fa8 | 14749 | |
c906108c | 14750 | void |
fba45db2 | 14751 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14752 | { |
816338b5 | 14753 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14754 | } |
14755 | ||
14756 | static void | |
14757 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14758 | { | |
14759 | enable_breakpoint (bpt); | |
c906108c SS |
14760 | } |
14761 | ||
95a42b64 TT |
14762 | /* A callback for map_breakpoint_numbers that calls |
14763 | enable_breakpoint. */ | |
14764 | ||
14765 | static void | |
14766 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14767 | { | |
51be5b68 | 14768 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14769 | } |
14770 | ||
c906108c SS |
14771 | /* The enable command enables the specified breakpoints (or all defined |
14772 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14773 | in stopping the inferior. */ |
c906108c | 14774 | |
c906108c | 14775 | static void |
fba45db2 | 14776 | enable_command (char *args, int from_tty) |
c906108c | 14777 | { |
c906108c | 14778 | if (args == 0) |
46c6471b PA |
14779 | { |
14780 | struct breakpoint *bpt; | |
14781 | ||
14782 | ALL_BREAKPOINTS (bpt) | |
14783 | if (user_breakpoint_p (bpt)) | |
14784 | enable_breakpoint (bpt); | |
14785 | } | |
9eaabc75 | 14786 | else |
0d381245 | 14787 | { |
9eaabc75 MW |
14788 | char *num = extract_arg (&args); |
14789 | ||
14790 | while (num) | |
d248b706 | 14791 | { |
9eaabc75 | 14792 | if (strchr (num, '.')) |
b775012e | 14793 | { |
9eaabc75 MW |
14794 | struct bp_location *loc = find_location_by_number (num); |
14795 | ||
14796 | if (loc) | |
14797 | { | |
14798 | if (!loc->enabled) | |
14799 | { | |
14800 | loc->enabled = 1; | |
14801 | mark_breakpoint_location_modified (loc); | |
14802 | } | |
14803 | if (target_supports_enable_disable_tracepoint () | |
14804 | && current_trace_status ()->running && loc->owner | |
14805 | && is_tracepoint (loc->owner)) | |
14806 | target_enable_tracepoint (loc); | |
14807 | } | |
14808 | update_global_location_list (1); | |
b775012e | 14809 | } |
9eaabc75 MW |
14810 | else |
14811 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14812 | num = extract_arg (&args); | |
d248b706 | 14813 | } |
0d381245 | 14814 | } |
c906108c SS |
14815 | } |
14816 | ||
816338b5 SS |
14817 | /* This struct packages up disposition data for application to multiple |
14818 | breakpoints. */ | |
14819 | ||
14820 | struct disp_data | |
14821 | { | |
14822 | enum bpdisp disp; | |
14823 | int count; | |
14824 | }; | |
14825 | ||
c906108c | 14826 | static void |
51be5b68 PA |
14827 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14828 | { | |
816338b5 | 14829 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14830 | |
816338b5 | 14831 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14832 | } |
14833 | ||
14834 | static void | |
14835 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14836 | { |
816338b5 | 14837 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14838 | |
14839 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14840 | } |
14841 | ||
c906108c | 14842 | static void |
fba45db2 | 14843 | enable_once_command (char *args, int from_tty) |
c906108c | 14844 | { |
51be5b68 | 14845 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14846 | } |
14847 | ||
816338b5 SS |
14848 | static void |
14849 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14850 | { | |
14851 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14852 | ||
14853 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14854 | } | |
14855 | ||
14856 | static void | |
14857 | enable_count_command (char *args, int from_tty) | |
14858 | { | |
14859 | int count = get_number (&args); | |
14860 | ||
14861 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14862 | } | |
14863 | ||
c906108c | 14864 | static void |
51be5b68 | 14865 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14866 | { |
816338b5 | 14867 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14868 | |
14869 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14870 | } |
14871 | ||
c906108c | 14872 | static void |
fba45db2 | 14873 | enable_delete_command (char *args, int from_tty) |
c906108c | 14874 | { |
51be5b68 | 14875 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14876 | } |
14877 | \f | |
fa8d40ab JJ |
14878 | static void |
14879 | set_breakpoint_cmd (char *args, int from_tty) | |
14880 | { | |
14881 | } | |
14882 | ||
14883 | static void | |
14884 | show_breakpoint_cmd (char *args, int from_tty) | |
14885 | { | |
14886 | } | |
14887 | ||
1f3b5d1b PP |
14888 | /* Invalidate last known value of any hardware watchpoint if |
14889 | the memory which that value represents has been written to by | |
14890 | GDB itself. */ | |
14891 | ||
14892 | static void | |
8de0566d YQ |
14893 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14894 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14895 | const bfd_byte *data) |
14896 | { | |
14897 | struct breakpoint *bp; | |
14898 | ||
14899 | ALL_BREAKPOINTS (bp) | |
14900 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14901 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14902 | { |
3a5c3e22 | 14903 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14904 | |
3a5c3e22 PA |
14905 | if (wp->val_valid && wp->val) |
14906 | { | |
14907 | struct bp_location *loc; | |
14908 | ||
14909 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14910 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14911 | && loc->address + loc->length > addr | |
14912 | && addr + len > loc->address) | |
14913 | { | |
14914 | value_free (wp->val); | |
14915 | wp->val = NULL; | |
14916 | wp->val_valid = 0; | |
14917 | } | |
14918 | } | |
1f3b5d1b PP |
14919 | } |
14920 | } | |
14921 | ||
8181d85f DJ |
14922 | /* Create and insert a raw software breakpoint at PC. Return an |
14923 | identifier, which should be used to remove the breakpoint later. | |
14924 | In general, places which call this should be using something on the | |
14925 | breakpoint chain instead; this function should be eliminated | |
14926 | someday. */ | |
14927 | ||
14928 | void * | |
6c95b8df PA |
14929 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
14930 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
14931 | { |
14932 | struct bp_target_info *bp_tgt; | |
14933 | ||
6c95b8df | 14934 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 14935 | |
6c95b8df | 14936 | bp_tgt->placed_address_space = aspace; |
8181d85f | 14937 | bp_tgt->placed_address = pc; |
6c95b8df | 14938 | |
a6d9a66e | 14939 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
14940 | { |
14941 | /* Could not insert the breakpoint. */ | |
14942 | xfree (bp_tgt); | |
14943 | return NULL; | |
14944 | } | |
14945 | ||
14946 | return bp_tgt; | |
14947 | } | |
14948 | ||
4a64f543 MS |
14949 | /* Remove a breakpoint BP inserted by |
14950 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
14951 | |
14952 | int | |
a6d9a66e | 14953 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
14954 | { |
14955 | struct bp_target_info *bp_tgt = bp; | |
14956 | int ret; | |
14957 | ||
a6d9a66e | 14958 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
14959 | xfree (bp_tgt); |
14960 | ||
14961 | return ret; | |
14962 | } | |
14963 | ||
4a64f543 MS |
14964 | /* One (or perhaps two) breakpoints used for software single |
14965 | stepping. */ | |
8181d85f DJ |
14966 | |
14967 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 14968 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
14969 | |
14970 | /* Create and insert a breakpoint for software single step. */ | |
14971 | ||
14972 | void | |
6c95b8df | 14973 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14974 | struct address_space *aspace, |
14975 | CORE_ADDR next_pc) | |
8181d85f DJ |
14976 | { |
14977 | void **bpt_p; | |
14978 | ||
14979 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
14980 | { |
14981 | bpt_p = &single_step_breakpoints[0]; | |
14982 | single_step_gdbarch[0] = gdbarch; | |
14983 | } | |
8181d85f DJ |
14984 | else |
14985 | { | |
14986 | gdb_assert (single_step_breakpoints[1] == NULL); | |
14987 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 14988 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
14989 | } |
14990 | ||
4a64f543 MS |
14991 | /* NOTE drow/2006-04-11: A future improvement to this function would |
14992 | be to only create the breakpoints once, and actually put them on | |
14993 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
14994 | We could adjust the addresses each time they were needed. Doing | |
14995 | this requires corresponding changes elsewhere where single step | |
14996 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 14997 | |
6c95b8df | 14998 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 14999 | if (*bpt_p == NULL) |
5af949e3 UW |
15000 | error (_("Could not insert single-step breakpoint at %s"), |
15001 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15002 | } |
15003 | ||
f02253f1 HZ |
15004 | /* Check if the breakpoints used for software single stepping |
15005 | were inserted or not. */ | |
15006 | ||
15007 | int | |
15008 | single_step_breakpoints_inserted (void) | |
15009 | { | |
15010 | return (single_step_breakpoints[0] != NULL | |
15011 | || single_step_breakpoints[1] != NULL); | |
15012 | } | |
15013 | ||
8181d85f DJ |
15014 | /* Remove and delete any breakpoints used for software single step. */ |
15015 | ||
15016 | void | |
15017 | remove_single_step_breakpoints (void) | |
15018 | { | |
15019 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15020 | ||
15021 | /* See insert_single_step_breakpoint for more about this deprecated | |
15022 | call. */ | |
a6d9a66e UW |
15023 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15024 | single_step_breakpoints[0]); | |
15025 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15026 | single_step_breakpoints[0] = NULL; |
15027 | ||
15028 | if (single_step_breakpoints[1] != NULL) | |
15029 | { | |
a6d9a66e UW |
15030 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15031 | single_step_breakpoints[1]); | |
15032 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15033 | single_step_breakpoints[1] = NULL; |
15034 | } | |
15035 | } | |
15036 | ||
d03285ec UW |
15037 | /* Delete software single step breakpoints without removing them from |
15038 | the inferior. This is intended to be used if the inferior's address | |
15039 | space where they were inserted is already gone, e.g. after exit or | |
15040 | exec. */ | |
15041 | ||
15042 | void | |
15043 | cancel_single_step_breakpoints (void) | |
15044 | { | |
15045 | int i; | |
15046 | ||
15047 | for (i = 0; i < 2; i++) | |
15048 | if (single_step_breakpoints[i]) | |
15049 | { | |
15050 | xfree (single_step_breakpoints[i]); | |
15051 | single_step_breakpoints[i] = NULL; | |
15052 | single_step_gdbarch[i] = NULL; | |
15053 | } | |
15054 | } | |
15055 | ||
15056 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15057 | removing them. */ | |
15058 | ||
15059 | static void | |
15060 | detach_single_step_breakpoints (void) | |
15061 | { | |
15062 | int i; | |
15063 | ||
15064 | for (i = 0; i < 2; i++) | |
15065 | if (single_step_breakpoints[i]) | |
15066 | target_remove_breakpoint (single_step_gdbarch[i], | |
15067 | single_step_breakpoints[i]); | |
15068 | } | |
15069 | ||
4a64f543 MS |
15070 | /* Check whether a software single-step breakpoint is inserted at |
15071 | PC. */ | |
1aafd4da UW |
15072 | |
15073 | static int | |
cc59ec59 MS |
15074 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15075 | CORE_ADDR pc) | |
1aafd4da UW |
15076 | { |
15077 | int i; | |
15078 | ||
15079 | for (i = 0; i < 2; i++) | |
15080 | { | |
15081 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15082 | if (bp_tgt |
15083 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15084 | bp_tgt->placed_address, | |
15085 | aspace, pc)) | |
1aafd4da UW |
15086 | return 1; |
15087 | } | |
15088 | ||
15089 | return 0; | |
15090 | } | |
15091 | ||
a96d9b2e SDJ |
15092 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15093 | non-zero otherwise. */ | |
15094 | static int | |
15095 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15096 | { | |
15097 | if (syscall_catchpoint_p (bp) | |
15098 | && bp->enable_state != bp_disabled | |
15099 | && bp->enable_state != bp_call_disabled) | |
15100 | return 1; | |
15101 | else | |
15102 | return 0; | |
15103 | } | |
15104 | ||
15105 | int | |
15106 | catch_syscall_enabled (void) | |
15107 | { | |
fa3064dd YQ |
15108 | struct catch_syscall_inferior_data *inf_data |
15109 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15110 | |
fa3064dd | 15111 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15112 | } |
15113 | ||
15114 | int | |
15115 | catching_syscall_number (int syscall_number) | |
15116 | { | |
15117 | struct breakpoint *bp; | |
15118 | ||
15119 | ALL_BREAKPOINTS (bp) | |
15120 | if (is_syscall_catchpoint_enabled (bp)) | |
15121 | { | |
be5c67c1 PA |
15122 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15123 | ||
15124 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15125 | { |
15126 | int i, iter; | |
15127 | for (i = 0; | |
be5c67c1 | 15128 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15129 | i++) |
15130 | if (syscall_number == iter) | |
15131 | return 1; | |
15132 | } | |
15133 | else | |
15134 | return 1; | |
15135 | } | |
15136 | ||
15137 | return 0; | |
15138 | } | |
15139 | ||
15140 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15141 | static VEC (char_ptr) * |
a96d9b2e | 15142 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15143 | const char *text, const char *word) |
a96d9b2e SDJ |
15144 | { |
15145 | const char **list = get_syscall_names (); | |
49c4e619 | 15146 | VEC (char_ptr) *retlist |
b45627a0 | 15147 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15148 | |
c38eea1a MS |
15149 | xfree (list); |
15150 | return retlist; | |
a96d9b2e SDJ |
15151 | } |
15152 | ||
1042e4c0 SS |
15153 | /* Tracepoint-specific operations. */ |
15154 | ||
15155 | /* Set tracepoint count to NUM. */ | |
15156 | static void | |
15157 | set_tracepoint_count (int num) | |
15158 | { | |
15159 | tracepoint_count = num; | |
4fa62494 | 15160 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15161 | } |
15162 | ||
70221824 | 15163 | static void |
1042e4c0 SS |
15164 | trace_command (char *arg, int from_tty) |
15165 | { | |
55aa24fb SDJ |
15166 | struct breakpoint_ops *ops; |
15167 | const char *arg_cp = arg; | |
15168 | ||
15169 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15170 | ops = &tracepoint_probe_breakpoint_ops; | |
15171 | else | |
15172 | ops = &tracepoint_breakpoint_ops; | |
15173 | ||
558a9d82 YQ |
15174 | create_breakpoint (get_current_arch (), |
15175 | arg, | |
15176 | NULL, 0, NULL, 1 /* parse arg */, | |
15177 | 0 /* tempflag */, | |
15178 | bp_tracepoint /* type_wanted */, | |
15179 | 0 /* Ignore count */, | |
15180 | pending_break_support, | |
15181 | ops, | |
15182 | from_tty, | |
15183 | 1 /* enabled */, | |
15184 | 0 /* internal */, 0); | |
1042e4c0 SS |
15185 | } |
15186 | ||
70221824 | 15187 | static void |
7a697b8d SS |
15188 | ftrace_command (char *arg, int from_tty) |
15189 | { | |
558a9d82 YQ |
15190 | create_breakpoint (get_current_arch (), |
15191 | arg, | |
15192 | NULL, 0, NULL, 1 /* parse arg */, | |
15193 | 0 /* tempflag */, | |
15194 | bp_fast_tracepoint /* type_wanted */, | |
15195 | 0 /* Ignore count */, | |
15196 | pending_break_support, | |
15197 | &tracepoint_breakpoint_ops, | |
15198 | from_tty, | |
15199 | 1 /* enabled */, | |
15200 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15201 | } |
15202 | ||
15203 | /* strace command implementation. Creates a static tracepoint. */ | |
15204 | ||
70221824 | 15205 | static void |
0fb4aa4b PA |
15206 | strace_command (char *arg, int from_tty) |
15207 | { | |
983af33b SDJ |
15208 | struct breakpoint_ops *ops; |
15209 | ||
15210 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15211 | or with a normal static tracepoint. */ | |
15212 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15213 | ops = &strace_marker_breakpoint_ops; | |
15214 | else | |
15215 | ops = &tracepoint_breakpoint_ops; | |
15216 | ||
558a9d82 YQ |
15217 | create_breakpoint (get_current_arch (), |
15218 | arg, | |
15219 | NULL, 0, NULL, 1 /* parse arg */, | |
15220 | 0 /* tempflag */, | |
15221 | bp_static_tracepoint /* type_wanted */, | |
15222 | 0 /* Ignore count */, | |
15223 | pending_break_support, | |
15224 | ops, | |
15225 | from_tty, | |
15226 | 1 /* enabled */, | |
15227 | 0 /* internal */, 0); | |
7a697b8d SS |
15228 | } |
15229 | ||
409873ef SS |
15230 | /* Set up a fake reader function that gets command lines from a linked |
15231 | list that was acquired during tracepoint uploading. */ | |
15232 | ||
15233 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15234 | static int next_cmd; |
409873ef SS |
15235 | |
15236 | static char * | |
15237 | read_uploaded_action (void) | |
15238 | { | |
15239 | char *rslt; | |
15240 | ||
3149d8c1 | 15241 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15242 | |
3149d8c1 | 15243 | next_cmd++; |
409873ef SS |
15244 | |
15245 | return rslt; | |
15246 | } | |
15247 | ||
00bf0b85 SS |
15248 | /* Given information about a tracepoint as recorded on a target (which |
15249 | can be either a live system or a trace file), attempt to create an | |
15250 | equivalent GDB tracepoint. This is not a reliable process, since | |
15251 | the target does not necessarily have all the information used when | |
15252 | the tracepoint was originally defined. */ | |
15253 | ||
d9b3f62e | 15254 | struct tracepoint * |
00bf0b85 | 15255 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15256 | { |
409873ef | 15257 | char *addr_str, small_buf[100]; |
d9b3f62e | 15258 | struct tracepoint *tp; |
fd9b8c24 | 15259 | |
409873ef SS |
15260 | if (utp->at_string) |
15261 | addr_str = utp->at_string; | |
15262 | else | |
15263 | { | |
15264 | /* In the absence of a source location, fall back to raw | |
15265 | address. Since there is no way to confirm that the address | |
15266 | means the same thing as when the trace was started, warn the | |
15267 | user. */ | |
3e43a32a MS |
15268 | warning (_("Uploaded tracepoint %d has no " |
15269 | "source location, using raw address"), | |
409873ef | 15270 | utp->number); |
8c042590 | 15271 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15272 | addr_str = small_buf; |
15273 | } | |
15274 | ||
15275 | /* There's not much we can do with a sequence of bytecodes. */ | |
15276 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15277 | warning (_("Uploaded tracepoint %d condition " |
15278 | "has no source form, ignoring it"), | |
409873ef | 15279 | utp->number); |
d5551862 | 15280 | |
8cdf0e15 | 15281 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15282 | addr_str, |
e7e0cddf SS |
15283 | utp->cond_string, -1, NULL, |
15284 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15285 | 0 /* tempflag */, |
0fb4aa4b | 15286 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15287 | 0 /* Ignore count */, |
15288 | pending_break_support, | |
348d480f | 15289 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15290 | 0 /* from_tty */, |
84f4c1fe | 15291 | utp->enabled /* enabled */, |
44f238bb PA |
15292 | 0 /* internal */, |
15293 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15294 | return NULL; |
15295 | ||
409873ef | 15296 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15297 | tp = get_tracepoint (tracepoint_count); |
15298 | gdb_assert (tp != NULL); | |
d5551862 | 15299 | |
00bf0b85 SS |
15300 | if (utp->pass > 0) |
15301 | { | |
8c042590 PM |
15302 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15303 | tp->base.number); | |
00bf0b85 | 15304 | |
409873ef | 15305 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15306 | } |
15307 | ||
409873ef SS |
15308 | /* If we have uploaded versions of the original commands, set up a |
15309 | special-purpose "reader" function and call the usual command line | |
15310 | reader, then pass the result to the breakpoint command-setting | |
15311 | function. */ | |
3149d8c1 | 15312 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15313 | { |
409873ef | 15314 | struct command_line *cmd_list; |
00bf0b85 | 15315 | |
409873ef | 15316 | this_utp = utp; |
3149d8c1 | 15317 | next_cmd = 0; |
d5551862 | 15318 | |
409873ef SS |
15319 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15320 | ||
d9b3f62e | 15321 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15322 | } |
3149d8c1 SS |
15323 | else if (!VEC_empty (char_ptr, utp->actions) |
15324 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15325 | warning (_("Uploaded tracepoint %d actions " |
15326 | "have no source form, ignoring them"), | |
409873ef | 15327 | utp->number); |
00bf0b85 | 15328 | |
f196051f SS |
15329 | /* Copy any status information that might be available. */ |
15330 | tp->base.hit_count = utp->hit_count; | |
15331 | tp->traceframe_usage = utp->traceframe_usage; | |
15332 | ||
00bf0b85 | 15333 | return tp; |
d9b3f62e | 15334 | } |
00bf0b85 | 15335 | |
1042e4c0 SS |
15336 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15337 | omitted. */ | |
15338 | ||
15339 | static void | |
e5a67952 | 15340 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15341 | { |
79a45e25 | 15342 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15343 | int num_printed; |
1042e4c0 | 15344 | |
e5a67952 | 15345 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15346 | |
15347 | if (num_printed == 0) | |
1042e4c0 | 15348 | { |
e5a67952 | 15349 | if (args == NULL || *args == '\0') |
d77f58be SS |
15350 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15351 | else | |
e5a67952 | 15352 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15353 | } |
ad443146 SS |
15354 | |
15355 | default_collect_info (); | |
1042e4c0 SS |
15356 | } |
15357 | ||
4a64f543 | 15358 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15359 | Not supported by all targets. */ |
15360 | static void | |
15361 | enable_trace_command (char *args, int from_tty) | |
15362 | { | |
15363 | enable_command (args, from_tty); | |
15364 | } | |
15365 | ||
4a64f543 | 15366 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15367 | Not supported by all targets. */ |
15368 | static void | |
15369 | disable_trace_command (char *args, int from_tty) | |
15370 | { | |
15371 | disable_command (args, from_tty); | |
15372 | } | |
15373 | ||
4a64f543 | 15374 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15375 | static void |
15376 | delete_trace_command (char *arg, int from_tty) | |
15377 | { | |
35df4500 | 15378 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15379 | |
15380 | dont_repeat (); | |
15381 | ||
15382 | if (arg == 0) | |
15383 | { | |
15384 | int breaks_to_delete = 0; | |
15385 | ||
15386 | /* Delete all breakpoints if no argument. | |
15387 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15388 | have to be deleted with an explicit breakpoint number |
15389 | argument. */ | |
1042e4c0 | 15390 | ALL_TRACEPOINTS (b) |
46c6471b | 15391 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15392 | { |
15393 | breaks_to_delete = 1; | |
15394 | break; | |
15395 | } | |
1042e4c0 SS |
15396 | |
15397 | /* Ask user only if there are some breakpoints to delete. */ | |
15398 | if (!from_tty | |
15399 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15400 | { | |
35df4500 | 15401 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15402 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15403 | delete_breakpoint (b); |
1042e4c0 SS |
15404 | } |
15405 | } | |
15406 | else | |
51be5b68 | 15407 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15408 | } |
15409 | ||
197f0a60 TT |
15410 | /* Helper function for trace_pass_command. */ |
15411 | ||
15412 | static void | |
d9b3f62e | 15413 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15414 | { |
d9b3f62e | 15415 | tp->pass_count = count; |
6f6484cd | 15416 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15417 | if (from_tty) |
15418 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15419 | tp->base.number, count); |
197f0a60 TT |
15420 | } |
15421 | ||
1042e4c0 SS |
15422 | /* Set passcount for tracepoint. |
15423 | ||
15424 | First command argument is passcount, second is tracepoint number. | |
15425 | If tracepoint number omitted, apply to most recently defined. | |
15426 | Also accepts special argument "all". */ | |
15427 | ||
15428 | static void | |
15429 | trace_pass_command (char *args, int from_tty) | |
15430 | { | |
d9b3f62e | 15431 | struct tracepoint *t1; |
1042e4c0 | 15432 | unsigned int count; |
1042e4c0 SS |
15433 | |
15434 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15435 | error (_("passcount command requires an " |
15436 | "argument (count + optional TP num)")); | |
1042e4c0 | 15437 | |
4a64f543 | 15438 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15439 | |
529480d0 | 15440 | args = skip_spaces (args); |
1042e4c0 SS |
15441 | if (*args && strncasecmp (args, "all", 3) == 0) |
15442 | { | |
d9b3f62e PA |
15443 | struct breakpoint *b; |
15444 | ||
1042e4c0 | 15445 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15446 | if (*args) |
15447 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15448 | |
d9b3f62e | 15449 | ALL_TRACEPOINTS (b) |
197f0a60 | 15450 | { |
d9b3f62e | 15451 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15452 | trace_pass_set_count (t1, count, from_tty); |
15453 | } | |
15454 | } | |
15455 | else if (*args == '\0') | |
1042e4c0 | 15456 | { |
197f0a60 | 15457 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 15458 | if (t1) |
197f0a60 TT |
15459 | trace_pass_set_count (t1, count, from_tty); |
15460 | } | |
15461 | else | |
15462 | { | |
15463 | struct get_number_or_range_state state; | |
15464 | ||
15465 | init_number_or_range (&state, args); | |
15466 | while (!state.finished) | |
1042e4c0 | 15467 | { |
197f0a60 TT |
15468 | t1 = get_tracepoint_by_number (&args, &state, 1); |
15469 | if (t1) | |
15470 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15471 | } |
15472 | } | |
1042e4c0 SS |
15473 | } |
15474 | ||
d9b3f62e | 15475 | struct tracepoint * |
1042e4c0 SS |
15476 | get_tracepoint (int num) |
15477 | { | |
15478 | struct breakpoint *t; | |
15479 | ||
15480 | ALL_TRACEPOINTS (t) | |
15481 | if (t->number == num) | |
d9b3f62e | 15482 | return (struct tracepoint *) t; |
1042e4c0 SS |
15483 | |
15484 | return NULL; | |
15485 | } | |
15486 | ||
d5551862 SS |
15487 | /* Find the tracepoint with the given target-side number (which may be |
15488 | different from the tracepoint number after disconnecting and | |
15489 | reconnecting). */ | |
15490 | ||
d9b3f62e | 15491 | struct tracepoint * |
d5551862 SS |
15492 | get_tracepoint_by_number_on_target (int num) |
15493 | { | |
d9b3f62e | 15494 | struct breakpoint *b; |
d5551862 | 15495 | |
d9b3f62e PA |
15496 | ALL_TRACEPOINTS (b) |
15497 | { | |
15498 | struct tracepoint *t = (struct tracepoint *) b; | |
15499 | ||
15500 | if (t->number_on_target == num) | |
15501 | return t; | |
15502 | } | |
d5551862 SS |
15503 | |
15504 | return NULL; | |
15505 | } | |
15506 | ||
1042e4c0 | 15507 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
15508 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
15509 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 15510 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 15511 | struct tracepoint * |
197f0a60 TT |
15512 | get_tracepoint_by_number (char **arg, |
15513 | struct get_number_or_range_state *state, | |
15514 | int optional_p) | |
1042e4c0 | 15515 | { |
1042e4c0 SS |
15516 | struct breakpoint *t; |
15517 | int tpnum; | |
15518 | char *instring = arg == NULL ? NULL : *arg; | |
15519 | ||
197f0a60 TT |
15520 | if (state) |
15521 | { | |
15522 | gdb_assert (!state->finished); | |
15523 | tpnum = get_number_or_range (state); | |
15524 | } | |
15525 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
15526 | { |
15527 | if (optional_p) | |
15528 | tpnum = tracepoint_count; | |
15529 | else | |
15530 | error_no_arg (_("tracepoint number")); | |
15531 | } | |
15532 | else | |
197f0a60 | 15533 | tpnum = get_number (arg); |
1042e4c0 SS |
15534 | |
15535 | if (tpnum <= 0) | |
15536 | { | |
15537 | if (instring && *instring) | |
15538 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15539 | instring); | |
15540 | else | |
3e43a32a MS |
15541 | printf_filtered (_("Tracepoint argument missing " |
15542 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
15543 | return NULL; |
15544 | } | |
15545 | ||
15546 | ALL_TRACEPOINTS (t) | |
15547 | if (t->number == tpnum) | |
15548 | { | |
d9b3f62e | 15549 | return (struct tracepoint *) t; |
1042e4c0 SS |
15550 | } |
15551 | ||
1042e4c0 SS |
15552 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15553 | return NULL; | |
15554 | } | |
15555 | ||
d9b3f62e PA |
15556 | void |
15557 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15558 | { | |
15559 | if (b->thread != -1) | |
15560 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15561 | ||
15562 | if (b->task != 0) | |
15563 | fprintf_unfiltered (fp, " task %d", b->task); | |
15564 | ||
15565 | fprintf_unfiltered (fp, "\n"); | |
15566 | } | |
15567 | ||
6149aea9 PA |
15568 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15569 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15570 | on each breakpoint and only include the ones for which it returns | |
15571 | non-zero. */ | |
15572 | ||
1042e4c0 | 15573 | static void |
6149aea9 PA |
15574 | save_breakpoints (char *filename, int from_tty, |
15575 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15576 | { |
15577 | struct breakpoint *tp; | |
6149aea9 | 15578 | int any = 0; |
1042e4c0 | 15579 | struct cleanup *cleanup; |
a7bdde9e | 15580 | struct ui_file *fp; |
6149aea9 | 15581 | int extra_trace_bits = 0; |
1042e4c0 | 15582 | |
6149aea9 PA |
15583 | if (filename == 0 || *filename == 0) |
15584 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15585 | |
15586 | /* See if we have anything to save. */ | |
6149aea9 | 15587 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15588 | { |
6149aea9 | 15589 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15590 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15591 | continue; |
15592 | ||
15593 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15594 | if (filter && !filter (tp)) | |
15595 | continue; | |
15596 | ||
15597 | any = 1; | |
15598 | ||
15599 | if (is_tracepoint (tp)) | |
15600 | { | |
15601 | extra_trace_bits = 1; | |
15602 | ||
15603 | /* We can stop searching. */ | |
15604 | break; | |
15605 | } | |
1042e4c0 | 15606 | } |
6149aea9 PA |
15607 | |
15608 | if (!any) | |
1042e4c0 | 15609 | { |
6149aea9 | 15610 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15611 | return; |
15612 | } | |
15613 | ||
c718be47 PA |
15614 | filename = tilde_expand (filename); |
15615 | cleanup = make_cleanup (xfree, filename); | |
15616 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15617 | if (!fp) |
6149aea9 PA |
15618 | error (_("Unable to open file '%s' for saving (%s)"), |
15619 | filename, safe_strerror (errno)); | |
a7bdde9e | 15620 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15621 | |
6149aea9 PA |
15622 | if (extra_trace_bits) |
15623 | save_trace_state_variables (fp); | |
8bf6485c | 15624 | |
6149aea9 | 15625 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15626 | { |
6149aea9 | 15627 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15628 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15629 | continue; |
8bf6485c | 15630 | |
6149aea9 PA |
15631 | /* If we have a filter, only save the breakpoints it accepts. */ |
15632 | if (filter && !filter (tp)) | |
15633 | continue; | |
15634 | ||
348d480f | 15635 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15636 | |
6149aea9 PA |
15637 | /* Note, we can't rely on tp->number for anything, as we can't |
15638 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15639 | instead. */ | |
15640 | ||
15641 | if (tp->cond_string) | |
15642 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15643 | ||
15644 | if (tp->ignore_count) | |
15645 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15646 | ||
2d9442cc | 15647 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15648 | { |
a7bdde9e VP |
15649 | volatile struct gdb_exception ex; |
15650 | ||
6149aea9 | 15651 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15652 | |
79a45e25 | 15653 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15654 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15655 | { |
79a45e25 | 15656 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15657 | } |
79a45e25 | 15658 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15659 | |
a7bdde9e VP |
15660 | if (ex.reason < 0) |
15661 | throw_exception (ex); | |
1042e4c0 | 15662 | |
a7bdde9e | 15663 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15664 | } |
6149aea9 PA |
15665 | |
15666 | if (tp->enable_state == bp_disabled) | |
15667 | fprintf_unfiltered (fp, "disable\n"); | |
15668 | ||
15669 | /* If this is a multi-location breakpoint, check if the locations | |
15670 | should be individually disabled. Watchpoint locations are | |
15671 | special, and not user visible. */ | |
15672 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15673 | { | |
15674 | struct bp_location *loc; | |
15675 | int n = 1; | |
15676 | ||
15677 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15678 | if (!loc->enabled) | |
15679 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15680 | } | |
1042e4c0 | 15681 | } |
8bf6485c | 15682 | |
6149aea9 | 15683 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15684 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15685 | ||
1042e4c0 | 15686 | if (from_tty) |
6149aea9 | 15687 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15688 | do_cleanups (cleanup); |
6149aea9 PA |
15689 | } |
15690 | ||
15691 | /* The `save breakpoints' command. */ | |
15692 | ||
15693 | static void | |
15694 | save_breakpoints_command (char *args, int from_tty) | |
15695 | { | |
15696 | save_breakpoints (args, from_tty, NULL); | |
15697 | } | |
15698 | ||
15699 | /* The `save tracepoints' command. */ | |
15700 | ||
15701 | static void | |
15702 | save_tracepoints_command (char *args, int from_tty) | |
15703 | { | |
15704 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15705 | } |
15706 | ||
15707 | /* Create a vector of all tracepoints. */ | |
15708 | ||
15709 | VEC(breakpoint_p) * | |
eeae04df | 15710 | all_tracepoints (void) |
1042e4c0 SS |
15711 | { |
15712 | VEC(breakpoint_p) *tp_vec = 0; | |
15713 | struct breakpoint *tp; | |
15714 | ||
15715 | ALL_TRACEPOINTS (tp) | |
15716 | { | |
15717 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15718 | } | |
15719 | ||
15720 | return tp_vec; | |
15721 | } | |
15722 | ||
c906108c | 15723 | \f |
4a64f543 MS |
15724 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15725 | commands. It is defined as a macro to prevent duplication. | |
15726 | COMMAND should be a string constant containing the name of the | |
15727 | command. */ | |
31e2b00f | 15728 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15729 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15730 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15731 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15732 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15733 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15734 | If a line number is specified, break at start of code for that line.\n\ | |
15735 | If a function is specified, break at start of code for that function.\n\ | |
15736 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15737 | With no LOCATION, uses current execution address of the selected\n\ |
15738 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15739 | \n\ |
15740 | THREADNUM is the number from \"info threads\".\n\ | |
15741 | CONDITION is a boolean expression.\n\ | |
15742 | \n\ | |
d41c0fc8 PA |
15743 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15744 | conditions are different.\n\ | |
31e2b00f AS |
15745 | \n\ |
15746 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15747 | ||
44feb3ce TT |
15748 | /* List of subcommands for "catch". */ |
15749 | static struct cmd_list_element *catch_cmdlist; | |
15750 | ||
15751 | /* List of subcommands for "tcatch". */ | |
15752 | static struct cmd_list_element *tcatch_cmdlist; | |
15753 | ||
9ac4176b | 15754 | void |
44feb3ce TT |
15755 | add_catch_command (char *name, char *docstring, |
15756 | void (*sfunc) (char *args, int from_tty, | |
15757 | struct cmd_list_element *command), | |
625e8578 | 15758 | completer_ftype *completer, |
44feb3ce TT |
15759 | void *user_data_catch, |
15760 | void *user_data_tcatch) | |
15761 | { | |
15762 | struct cmd_list_element *command; | |
15763 | ||
15764 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15765 | &catch_cmdlist); | |
15766 | set_cmd_sfunc (command, sfunc); | |
15767 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15768 | set_cmd_completer (command, completer); |
44feb3ce TT |
15769 | |
15770 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15771 | &tcatch_cmdlist); | |
15772 | set_cmd_sfunc (command, sfunc); | |
15773 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15774 | set_cmd_completer (command, completer); |
44feb3ce TT |
15775 | } |
15776 | ||
6c95b8df | 15777 | static void |
a79b8f6e | 15778 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15779 | { |
fa3064dd YQ |
15780 | struct catch_syscall_inferior_data *inf_data |
15781 | = get_catch_syscall_inferior_data (inf); | |
15782 | ||
15783 | inf_data->total_syscalls_count = 0; | |
15784 | inf_data->any_syscall_count = 0; | |
15785 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15786 | } |
15787 | ||
6149aea9 PA |
15788 | static void |
15789 | save_command (char *arg, int from_tty) | |
15790 | { | |
3e43a32a MS |
15791 | printf_unfiltered (_("\"save\" must be followed by " |
15792 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15793 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15794 | } | |
15795 | ||
84f4c1fe PM |
15796 | struct breakpoint * |
15797 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15798 | void *data) | |
15799 | { | |
35df4500 | 15800 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15801 | |
35df4500 | 15802 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15803 | { |
15804 | if ((*callback) (b, data)) | |
15805 | return b; | |
15806 | } | |
15807 | ||
15808 | return NULL; | |
15809 | } | |
15810 | ||
0574c78f GB |
15811 | /* Zero if any of the breakpoint's locations could be a location where |
15812 | functions have been inlined, nonzero otherwise. */ | |
15813 | ||
15814 | static int | |
15815 | is_non_inline_function (struct breakpoint *b) | |
15816 | { | |
15817 | /* The shared library event breakpoint is set on the address of a | |
15818 | non-inline function. */ | |
15819 | if (b->type == bp_shlib_event) | |
15820 | return 1; | |
15821 | ||
15822 | return 0; | |
15823 | } | |
15824 | ||
15825 | /* Nonzero if the specified PC cannot be a location where functions | |
15826 | have been inlined. */ | |
15827 | ||
15828 | int | |
09ac7c10 TT |
15829 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15830 | const struct target_waitstatus *ws) | |
0574c78f GB |
15831 | { |
15832 | struct breakpoint *b; | |
15833 | struct bp_location *bl; | |
15834 | ||
15835 | ALL_BREAKPOINTS (b) | |
15836 | { | |
15837 | if (!is_non_inline_function (b)) | |
15838 | continue; | |
15839 | ||
15840 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15841 | { | |
15842 | if (!bl->shlib_disabled | |
09ac7c10 | 15843 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15844 | return 1; |
15845 | } | |
15846 | } | |
15847 | ||
15848 | return 0; | |
15849 | } | |
15850 | ||
2f202fde JK |
15851 | /* Remove any references to OBJFILE which is going to be freed. */ |
15852 | ||
15853 | void | |
15854 | breakpoint_free_objfile (struct objfile *objfile) | |
15855 | { | |
15856 | struct bp_location **locp, *loc; | |
15857 | ||
15858 | ALL_BP_LOCATIONS (loc, locp) | |
15859 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15860 | loc->symtab = NULL; | |
15861 | } | |
15862 | ||
2060206e PA |
15863 | void |
15864 | initialize_breakpoint_ops (void) | |
15865 | { | |
15866 | static int initialized = 0; | |
15867 | ||
15868 | struct breakpoint_ops *ops; | |
15869 | ||
15870 | if (initialized) | |
15871 | return; | |
15872 | initialized = 1; | |
15873 | ||
15874 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15875 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15876 | internal and momentary breakpoints, etc.). */ | |
15877 | ops = &bkpt_base_breakpoint_ops; | |
15878 | *ops = base_breakpoint_ops; | |
15879 | ops->re_set = bkpt_re_set; | |
15880 | ops->insert_location = bkpt_insert_location; | |
15881 | ops->remove_location = bkpt_remove_location; | |
15882 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15883 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15884 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15885 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15886 | |
15887 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15888 | ops = &bkpt_breakpoint_ops; | |
15889 | *ops = bkpt_base_breakpoint_ops; | |
15890 | ops->re_set = bkpt_re_set; | |
15891 | ops->resources_needed = bkpt_resources_needed; | |
15892 | ops->print_it = bkpt_print_it; | |
15893 | ops->print_mention = bkpt_print_mention; | |
15894 | ops->print_recreate = bkpt_print_recreate; | |
15895 | ||
15896 | /* Ranged breakpoints. */ | |
15897 | ops = &ranged_breakpoint_ops; | |
15898 | *ops = bkpt_breakpoint_ops; | |
15899 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15900 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15901 | ops->print_it = print_it_ranged_breakpoint; | |
15902 | ops->print_one = print_one_ranged_breakpoint; | |
15903 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15904 | ops->print_mention = print_mention_ranged_breakpoint; | |
15905 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15906 | ||
15907 | /* Internal breakpoints. */ | |
15908 | ops = &internal_breakpoint_ops; | |
15909 | *ops = bkpt_base_breakpoint_ops; | |
15910 | ops->re_set = internal_bkpt_re_set; | |
15911 | ops->check_status = internal_bkpt_check_status; | |
15912 | ops->print_it = internal_bkpt_print_it; | |
15913 | ops->print_mention = internal_bkpt_print_mention; | |
15914 | ||
15915 | /* Momentary breakpoints. */ | |
15916 | ops = &momentary_breakpoint_ops; | |
15917 | *ops = bkpt_base_breakpoint_ops; | |
15918 | ops->re_set = momentary_bkpt_re_set; | |
15919 | ops->check_status = momentary_bkpt_check_status; | |
15920 | ops->print_it = momentary_bkpt_print_it; | |
15921 | ops->print_mention = momentary_bkpt_print_mention; | |
15922 | ||
e2e4d78b JK |
15923 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15924 | ops = &longjmp_breakpoint_ops; | |
15925 | *ops = momentary_breakpoint_ops; | |
15926 | ops->dtor = longjmp_bkpt_dtor; | |
15927 | ||
55aa24fb SDJ |
15928 | /* Probe breakpoints. */ |
15929 | ops = &bkpt_probe_breakpoint_ops; | |
15930 | *ops = bkpt_breakpoint_ops; | |
15931 | ops->insert_location = bkpt_probe_insert_location; | |
15932 | ops->remove_location = bkpt_probe_remove_location; | |
15933 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
15934 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
15935 | ||
2060206e PA |
15936 | /* Watchpoints. */ |
15937 | ops = &watchpoint_breakpoint_ops; | |
15938 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15939 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15940 | ops->re_set = re_set_watchpoint; |
15941 | ops->insert_location = insert_watchpoint; | |
15942 | ops->remove_location = remove_watchpoint; | |
15943 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15944 | ops->check_status = check_status_watchpoint; | |
15945 | ops->resources_needed = resources_needed_watchpoint; | |
15946 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15947 | ops->print_it = print_it_watchpoint; | |
15948 | ops->print_mention = print_mention_watchpoint; | |
15949 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15950 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15951 | |
15952 | /* Masked watchpoints. */ | |
15953 | ops = &masked_watchpoint_breakpoint_ops; | |
15954 | *ops = watchpoint_breakpoint_ops; | |
15955 | ops->insert_location = insert_masked_watchpoint; | |
15956 | ops->remove_location = remove_masked_watchpoint; | |
15957 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15958 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15959 | ops->print_it = print_it_masked_watchpoint; | |
15960 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15961 | ops->print_mention = print_mention_masked_watchpoint; | |
15962 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15963 | ||
15964 | /* Tracepoints. */ | |
15965 | ops = &tracepoint_breakpoint_ops; | |
15966 | *ops = base_breakpoint_ops; | |
15967 | ops->re_set = tracepoint_re_set; | |
15968 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15969 | ops->print_one_detail = tracepoint_print_one_detail; | |
15970 | ops->print_mention = tracepoint_print_mention; | |
15971 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
15972 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
15973 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
15974 | ops->decode_linespec = tracepoint_decode_linespec; | |
15975 | ||
55aa24fb SDJ |
15976 | /* Probe tracepoints. */ |
15977 | ops = &tracepoint_probe_breakpoint_ops; | |
15978 | *ops = tracepoint_breakpoint_ops; | |
15979 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
15980 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
15981 | ||
983af33b SDJ |
15982 | /* Static tracepoints with marker (`-m'). */ |
15983 | ops = &strace_marker_breakpoint_ops; | |
15984 | *ops = tracepoint_breakpoint_ops; | |
15985 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
15986 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
15987 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
15988 | |
15989 | /* Fork catchpoints. */ | |
15990 | ops = &catch_fork_breakpoint_ops; | |
15991 | *ops = base_breakpoint_ops; | |
15992 | ops->insert_location = insert_catch_fork; | |
15993 | ops->remove_location = remove_catch_fork; | |
15994 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15995 | ops->print_it = print_it_catch_fork; | |
15996 | ops->print_one = print_one_catch_fork; | |
15997 | ops->print_mention = print_mention_catch_fork; | |
15998 | ops->print_recreate = print_recreate_catch_fork; | |
15999 | ||
16000 | /* Vfork catchpoints. */ | |
16001 | ops = &catch_vfork_breakpoint_ops; | |
16002 | *ops = base_breakpoint_ops; | |
16003 | ops->insert_location = insert_catch_vfork; | |
16004 | ops->remove_location = remove_catch_vfork; | |
16005 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16006 | ops->print_it = print_it_catch_vfork; | |
16007 | ops->print_one = print_one_catch_vfork; | |
16008 | ops->print_mention = print_mention_catch_vfork; | |
16009 | ops->print_recreate = print_recreate_catch_vfork; | |
16010 | ||
16011 | /* Exec catchpoints. */ | |
16012 | ops = &catch_exec_breakpoint_ops; | |
16013 | *ops = base_breakpoint_ops; | |
16014 | ops->dtor = dtor_catch_exec; | |
16015 | ops->insert_location = insert_catch_exec; | |
16016 | ops->remove_location = remove_catch_exec; | |
16017 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16018 | ops->print_it = print_it_catch_exec; | |
16019 | ops->print_one = print_one_catch_exec; | |
16020 | ops->print_mention = print_mention_catch_exec; | |
16021 | ops->print_recreate = print_recreate_catch_exec; | |
16022 | ||
16023 | /* Syscall catchpoints. */ | |
16024 | ops = &catch_syscall_breakpoint_ops; | |
16025 | *ops = base_breakpoint_ops; | |
16026 | ops->dtor = dtor_catch_syscall; | |
16027 | ops->insert_location = insert_catch_syscall; | |
16028 | ops->remove_location = remove_catch_syscall; | |
16029 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16030 | ops->print_it = print_it_catch_syscall; | |
16031 | ops->print_one = print_one_catch_syscall; | |
16032 | ops->print_mention = print_mention_catch_syscall; | |
16033 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16034 | |
16035 | /* Solib-related catchpoints. */ | |
16036 | ops = &catch_solib_breakpoint_ops; | |
16037 | *ops = base_breakpoint_ops; | |
16038 | ops->dtor = dtor_catch_solib; | |
16039 | ops->insert_location = insert_catch_solib; | |
16040 | ops->remove_location = remove_catch_solib; | |
16041 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16042 | ops->check_status = check_status_catch_solib; | |
16043 | ops->print_it = print_it_catch_solib; | |
16044 | ops->print_one = print_one_catch_solib; | |
16045 | ops->print_mention = print_mention_catch_solib; | |
16046 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16047 | |
16048 | ops = &dprintf_breakpoint_ops; | |
16049 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16050 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16051 | ops->resources_needed = bkpt_resources_needed; |
16052 | ops->print_it = bkpt_print_it; | |
16053 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16054 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16055 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16056 | } |
16057 | ||
8bfd80db YQ |
16058 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16059 | ||
16060 | static struct cmd_list_element *enablebreaklist = NULL; | |
16061 | ||
c906108c | 16062 | void |
fba45db2 | 16063 | _initialize_breakpoint (void) |
c906108c SS |
16064 | { |
16065 | struct cmd_list_element *c; | |
16066 | ||
2060206e PA |
16067 | initialize_breakpoint_ops (); |
16068 | ||
84acb35a | 16069 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16070 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16071 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16072 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16073 | |
55aa24fb SDJ |
16074 | breakpoint_objfile_key |
16075 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16076 | |
fa3064dd | 16077 | catch_syscall_inferior_data |
8e260fc0 TT |
16078 | = register_inferior_data_with_cleanup (NULL, |
16079 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16080 | |
c906108c SS |
16081 | breakpoint_chain = 0; |
16082 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16083 | before a breakpoint is set. */ | |
16084 | breakpoint_count = 0; | |
16085 | ||
1042e4c0 SS |
16086 | tracepoint_count = 0; |
16087 | ||
1bedd215 AC |
16088 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16089 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16090 | Usage is `ignore N COUNT'.")); | |
c906108c | 16091 | if (xdb_commands) |
c5aa993b | 16092 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16093 | |
1bedd215 AC |
16094 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16095 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16096 | Give breakpoint number as argument after \"commands\".\n\ |
16097 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16098 | The commands themselves follow starting on the next line.\n\ | |
16099 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16100 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16101 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16102 | |
d55637df | 16103 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16104 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16105 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16106 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16107 | set_cmd_completer (c, condition_completer); |
c906108c | 16108 | |
1bedd215 | 16109 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16110 | Set a temporary breakpoint.\n\ |
c906108c SS |
16111 | Like \"break\" except the breakpoint is only temporary,\n\ |
16112 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16113 | by using \"enable delete\" on the breakpoint number.\n\ |
16114 | \n" | |
16115 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16116 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16117 | |
1bedd215 | 16118 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16119 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16120 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16121 | some target hardware may not have this support.\n\ |
16122 | \n" | |
16123 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16124 | set_cmd_completer (c, location_completer); |
c906108c | 16125 | |
1bedd215 | 16126 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16127 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16128 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16129 | so it will be deleted when hit.\n\ |
16130 | \n" | |
16131 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16132 | set_cmd_completer (c, location_completer); |
c906108c | 16133 | |
1bedd215 AC |
16134 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16135 | Enable some breakpoints.\n\ | |
c906108c SS |
16136 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16137 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16138 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16139 | With a subcommand you can enable temporarily."), |
c906108c SS |
16140 | &enablelist, "enable ", 1, &cmdlist); |
16141 | if (xdb_commands) | |
1bedd215 AC |
16142 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16143 | Enable some breakpoints.\n\ | |
c906108c SS |
16144 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16145 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16146 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16147 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16148 | |
16149 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16150 | ||
84951ab5 | 16151 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16152 | Enable some breakpoints.\n\ |
c906108c SS |
16153 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16154 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16155 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16156 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16157 | |
1a966eab AC |
16158 | add_cmd ("once", no_class, enable_once_command, _("\ |
16159 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16160 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16161 | &enablebreaklist); |
16162 | ||
1a966eab AC |
16163 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16164 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16165 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16166 | &enablebreaklist); |
16167 | ||
816338b5 SS |
16168 | add_cmd ("count", no_class, enable_count_command, _("\ |
16169 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16170 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16171 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16172 | &enablebreaklist); | |
16173 | ||
1a966eab AC |
16174 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16175 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16176 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16177 | &enablelist); |
16178 | ||
1a966eab AC |
16179 | add_cmd ("once", no_class, enable_once_command, _("\ |
16180 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16181 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16182 | &enablelist); |
16183 | ||
16184 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16185 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16186 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16187 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16188 | &enablelist); |
16189 | ||
1bedd215 AC |
16190 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16191 | Disable some breakpoints.\n\ | |
c906108c SS |
16192 | Arguments are breakpoint numbers with spaces in between.\n\ |
16193 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16194 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16195 | &disablelist, "disable ", 1, &cmdlist); |
16196 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16197 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16198 | if (xdb_commands) | |
1bedd215 AC |
16199 | add_com ("sb", 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 | 16204 | |
1a966eab AC |
16205 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16206 | Disable some breakpoints.\n\ | |
c906108c SS |
16207 | Arguments are breakpoint numbers with spaces in between.\n\ |
16208 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16209 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16210 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16211 | &disablelist); |
16212 | ||
1bedd215 AC |
16213 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16214 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16215 | Arguments are breakpoint numbers with spaces in between.\n\ |
16216 | To delete all breakpoints, give no argument.\n\ | |
16217 | \n\ | |
16218 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16219 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16220 | &deletelist, "delete ", 1, &cmdlist); |
16221 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16222 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16223 | if (xdb_commands) |
1bedd215 AC |
16224 | add_com ("db", class_breakpoint, delete_command, _("\ |
16225 | Delete some breakpoints.\n\ | |
c906108c | 16226 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16227 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16228 | |
1a966eab AC |
16229 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16230 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16231 | Arguments are breakpoint numbers with spaces in between.\n\ |
16232 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16233 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16234 | &deletelist); |
16235 | ||
1bedd215 AC |
16236 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16237 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16238 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16239 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16240 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16241 | If an address is specified, breakpoints at that address are cleared.\n\ |
16242 | \n\ | |
16243 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16244 | is executing in.\n\ |
16245 | \n\ | |
1bedd215 | 16246 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16247 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16248 | |
1bedd215 | 16249 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16250 | Set breakpoint at specified line or function.\n" |
16251 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16252 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16253 | |
c906108c SS |
16254 | add_com_alias ("b", "break", class_run, 1); |
16255 | add_com_alias ("br", "break", class_run, 1); | |
16256 | add_com_alias ("bre", "break", class_run, 1); | |
16257 | add_com_alias ("brea", "break", class_run, 1); | |
16258 | ||
7681d515 PM |
16259 | if (xdb_commands) |
16260 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16261 | |
16262 | if (dbx_commands) | |
16263 | { | |
1bedd215 AC |
16264 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16265 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16266 | &stoplist, "stop ", 1, &cmdlist); |
16267 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16268 | _("Break in function or address."), &stoplist); |
c5aa993b | 16269 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16270 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16271 | add_com ("status", class_info, breakpoints_info, _("\ |
16272 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16273 | The \"Type\" column indicates one of:\n\ |
16274 | \tbreakpoint - normal breakpoint\n\ | |
16275 | \twatchpoint - watchpoint\n\ | |
16276 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16277 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16278 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16279 | address and file/line number respectively.\n\ |
16280 | \n\ | |
16281 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16282 | are set to the address of the last breakpoint listed unless the command\n\ |
16283 | is prefixed with \"server \".\n\n\ | |
c906108c | 16284 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16285 | breakpoint set.")); |
c906108c SS |
16286 | } |
16287 | ||
1bedd215 | 16288 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16289 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16290 | The \"Type\" column indicates one of:\n\ |
16291 | \tbreakpoint - normal breakpoint\n\ | |
16292 | \twatchpoint - watchpoint\n\ | |
16293 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16294 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16295 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16296 | address and file/line number respectively.\n\ |
16297 | \n\ | |
16298 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16299 | are set to the address of the last breakpoint listed unless the command\n\ |
16300 | is prefixed with \"server \".\n\n\ | |
c906108c | 16301 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16302 | breakpoint set.")); |
c906108c | 16303 | |
6b04bdb7 MS |
16304 | add_info_alias ("b", "breakpoints", 1); |
16305 | ||
c906108c | 16306 | if (xdb_commands) |
1bedd215 AC |
16307 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16308 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16309 | The \"Type\" column indicates one of:\n\ |
16310 | \tbreakpoint - normal breakpoint\n\ | |
16311 | \twatchpoint - watchpoint\n\ | |
16312 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16313 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16314 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16315 | address and file/line number respectively.\n\ |
16316 | \n\ | |
16317 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16318 | are set to the address of the last breakpoint listed unless the command\n\ |
16319 | is prefixed with \"server \".\n\n\ | |
c906108c | 16320 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16321 | breakpoint set.")); |
c906108c | 16322 | |
1a966eab AC |
16323 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16324 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16325 | The \"Type\" column indicates one of:\n\ |
16326 | \tbreakpoint - normal breakpoint\n\ | |
16327 | \twatchpoint - watchpoint\n\ | |
16328 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16329 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16330 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16331 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16332 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16333 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16334 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16335 | address and file/line number respectively.\n\ |
16336 | \n\ | |
16337 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16338 | are set to the address of the last breakpoint listed unless the command\n\ |
16339 | is prefixed with \"server \".\n\n\ | |
c906108c | 16340 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16341 | breakpoint set."), |
c906108c SS |
16342 | &maintenanceinfolist); |
16343 | ||
44feb3ce TT |
16344 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16345 | Set catchpoints to catch events."), | |
16346 | &catch_cmdlist, "catch ", | |
16347 | 0/*allow-unknown*/, &cmdlist); | |
16348 | ||
16349 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16350 | Set temporary catchpoints to catch events."), | |
16351 | &tcatch_cmdlist, "tcatch ", | |
16352 | 0/*allow-unknown*/, &cmdlist); | |
16353 | ||
44feb3ce TT |
16354 | add_catch_command ("fork", _("Catch calls to fork."), |
16355 | catch_fork_command_1, | |
a96d9b2e | 16356 | NULL, |
44feb3ce TT |
16357 | (void *) (uintptr_t) catch_fork_permanent, |
16358 | (void *) (uintptr_t) catch_fork_temporary); | |
16359 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16360 | catch_fork_command_1, | |
a96d9b2e | 16361 | NULL, |
44feb3ce TT |
16362 | (void *) (uintptr_t) catch_vfork_permanent, |
16363 | (void *) (uintptr_t) catch_vfork_temporary); | |
16364 | add_catch_command ("exec", _("Catch calls to exec."), | |
16365 | catch_exec_command_1, | |
a96d9b2e SDJ |
16366 | NULL, |
16367 | CATCH_PERMANENT, | |
16368 | CATCH_TEMPORARY); | |
edcc5120 TT |
16369 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16370 | Usage: catch load [REGEX]\n\ | |
16371 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16372 | catch_load_command_1, | |
16373 | NULL, | |
16374 | CATCH_PERMANENT, | |
16375 | CATCH_TEMPORARY); | |
16376 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16377 | Usage: catch unload [REGEX]\n\ | |
16378 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16379 | catch_unload_command_1, | |
16380 | NULL, | |
16381 | CATCH_PERMANENT, | |
16382 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16383 | add_catch_command ("syscall", _("\ |
16384 | Catch system calls by their names and/or numbers.\n\ | |
16385 | Arguments say which system calls to catch. If no arguments\n\ | |
16386 | are given, every system call will be caught.\n\ | |
16387 | Arguments, if given, should be one or more system call names\n\ | |
16388 | (if your system supports that), or system call numbers."), | |
16389 | catch_syscall_command_1, | |
16390 | catch_syscall_completer, | |
44feb3ce TT |
16391 | CATCH_PERMANENT, |
16392 | CATCH_TEMPORARY); | |
c5aa993b | 16393 | |
1bedd215 AC |
16394 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16395 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16396 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16397 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16398 | an expression changes.\n\ |
16399 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16400 | the memory to which it refers.")); | |
65d12d83 | 16401 | set_cmd_completer (c, expression_completer); |
c906108c | 16402 | |
1bedd215 AC |
16403 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16404 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16405 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16406 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16407 | an expression is read.\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 ("awatch", class_breakpoint, awatch_command, _("\ |
16413 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16414 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16415 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16416 | an expression is either read or written.\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 | |
d77f58be | 16421 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16422 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16423 | |
920d2a44 AC |
16424 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16425 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16426 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16427 | &can_use_hw_watchpoints, _("\ | |
16428 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16429 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16430 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16431 | such is available. (However, any hardware watchpoints that were\n\ | |
16432 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16433 | hardware.)"), |
16434 | NULL, | |
920d2a44 | 16435 | show_can_use_hw_watchpoints, |
85c07804 | 16436 | &setlist, &showlist); |
c906108c SS |
16437 | |
16438 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16439 | |
1042e4c0 SS |
16440 | /* Tracepoint manipulation commands. */ |
16441 | ||
16442 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16443 | Set a tracepoint at specified line or function.\n\ | |
16444 | \n" | |
16445 | BREAK_ARGS_HELP ("trace") "\n\ | |
16446 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16447 | set_cmd_completer (c, location_completer); | |
16448 | ||
16449 | add_com_alias ("tp", "trace", class_alias, 0); | |
16450 | add_com_alias ("tr", "trace", class_alias, 1); | |
16451 | add_com_alias ("tra", "trace", class_alias, 1); | |
16452 | add_com_alias ("trac", "trace", class_alias, 1); | |
16453 | ||
7a697b8d SS |
16454 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16455 | Set a fast tracepoint at specified line or function.\n\ | |
16456 | \n" | |
16457 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16458 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16459 | set_cmd_completer (c, location_completer); | |
16460 | ||
0fb4aa4b PA |
16461 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16462 | Set a static tracepoint at specified line, function or marker.\n\ | |
16463 | \n\ | |
16464 | strace [LOCATION] [if CONDITION]\n\ | |
16465 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16466 | or -m MARKER_ID.\n\ | |
16467 | If a line number is specified, probe the marker at start of code\n\ | |
16468 | for that line. If a function is specified, probe the marker at start\n\ | |
16469 | of code for that function. If an address is specified, probe the marker\n\ | |
16470 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16471 | with that name. With no LOCATION, uses current execution address of\n\ | |
16472 | the selected stack frame.\n\ | |
16473 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16474 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16475 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16476 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16477 | \n\ | |
16478 | CONDITION is a boolean expression.\n\ | |
16479 | \n\ | |
d41c0fc8 PA |
16480 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16481 | conditions are different.\n\ | |
0fb4aa4b PA |
16482 | \n\ |
16483 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16484 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16485 | set_cmd_completer (c, location_completer); | |
16486 | ||
1042e4c0 | 16487 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16488 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16489 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16490 | last tracepoint set.")); | |
16491 | ||
16492 | add_info_alias ("tp", "tracepoints", 1); | |
16493 | ||
16494 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16495 | Delete specified tracepoints.\n\ | |
16496 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16497 | No argument means delete all tracepoints."), | |
16498 | &deletelist); | |
7e20dfcd | 16499 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16500 | |
16501 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16502 | Disable specified tracepoints.\n\ | |
16503 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16504 | No argument means disable all tracepoints."), | |
16505 | &disablelist); | |
16506 | deprecate_cmd (c, "disable"); | |
16507 | ||
16508 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16509 | Enable specified tracepoints.\n\ | |
16510 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16511 | No argument means enable all tracepoints."), | |
16512 | &enablelist); | |
16513 | deprecate_cmd (c, "enable"); | |
16514 | ||
16515 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16516 | Set the passcount for a tracepoint.\n\ | |
16517 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16518 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16519 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16520 | ||
6149aea9 PA |
16521 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16522 | _("Save breakpoint definitions as a script."), | |
16523 | &save_cmdlist, "save ", | |
16524 | 0/*allow-unknown*/, &cmdlist); | |
16525 | ||
16526 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16527 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16528 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16529 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16530 | session to restore them."), | |
16531 | &save_cmdlist); | |
16532 | set_cmd_completer (c, filename_completer); | |
16533 | ||
16534 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16535 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16536 | Use the 'source' command in another debug session to restore them."), |
16537 | &save_cmdlist); | |
1042e4c0 SS |
16538 | set_cmd_completer (c, filename_completer); |
16539 | ||
6149aea9 PA |
16540 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16541 | deprecate_cmd (c, "save tracepoints"); | |
16542 | ||
1bedd215 | 16543 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16544 | Breakpoint specific settings\n\ |
16545 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16546 | pending breakpoint behavior"), |
fa8d40ab JJ |
16547 | &breakpoint_set_cmdlist, "set breakpoint ", |
16548 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16549 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16550 | Breakpoint specific settings\n\ |
16551 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16552 | pending breakpoint behavior"), |
fa8d40ab JJ |
16553 | &breakpoint_show_cmdlist, "show breakpoint ", |
16554 | 0/*allow-unknown*/, &showlist); | |
16555 | ||
7915a72c AC |
16556 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16557 | &pending_break_support, _("\ | |
16558 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16559 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16560 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16561 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16562 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16563 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16564 | NULL, |
920d2a44 | 16565 | show_pending_break_support, |
6e1d7d6c AC |
16566 | &breakpoint_set_cmdlist, |
16567 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16568 | |
16569 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16570 | |
16571 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16572 | &automatic_hardware_breakpoints, _("\ | |
16573 | Set automatic usage of hardware breakpoints."), _("\ | |
16574 | Show automatic usage of hardware breakpoints."), _("\ | |
16575 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16576 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16577 | a warning will be emitted for such breakpoints."), | |
16578 | NULL, | |
16579 | show_automatic_hardware_breakpoints, | |
16580 | &breakpoint_set_cmdlist, | |
16581 | &breakpoint_show_cmdlist); | |
74960c60 | 16582 | |
72d0e2c5 YQ |
16583 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16584 | &always_inserted_mode, _("\ | |
74960c60 VP |
16585 | Set mode for inserting breakpoints."), _("\ |
16586 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16587 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16588 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16589 | breakpoints are inserted immediately and removed only when the user\n\ | |
16590 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16591 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16592 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16593 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16594 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16595 | NULL, |
16596 | &show_always_inserted_mode, | |
16597 | &breakpoint_set_cmdlist, | |
16598 | &breakpoint_show_cmdlist); | |
f1310107 | 16599 | |
b775012e LM |
16600 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16601 | condition_evaluation_enums, | |
16602 | &condition_evaluation_mode_1, _("\ | |
16603 | Set mode of breakpoint condition evaluation."), _("\ | |
16604 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16605 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16606 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16607 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16608 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16609 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16610 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16611 | be set to \"gdb\""), | |
16612 | &set_condition_evaluation_mode, | |
16613 | &show_condition_evaluation_mode, | |
16614 | &breakpoint_set_cmdlist, | |
16615 | &breakpoint_show_cmdlist); | |
16616 | ||
f1310107 TJB |
16617 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16618 | Set a breakpoint for an address range.\n\ | |
16619 | break-range START-LOCATION, END-LOCATION\n\ | |
16620 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16621 | LINENUM, for that line in the current file,\n\ | |
16622 | FILE:LINENUM, for that line in that file,\n\ | |
16623 | +OFFSET, for that number of lines after the current line\n\ | |
16624 | or the start of the range\n\ | |
16625 | FUNCTION, for the first line in that function,\n\ | |
16626 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16627 | *ADDRESS, for the instruction at that address.\n\ | |
16628 | \n\ | |
16629 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16630 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16631 | range (including START-LOCATION and END-LOCATION).")); | |
16632 | ||
e7e0cddf SS |
16633 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16634 | Set a dynamic printf at specified line or function.\n\ | |
16635 | dprintf location,format string,arg1,arg2,...\n\ | |
16636 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16637 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16638 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16639 | set_cmd_completer (c, location_completer); |
16640 | ||
16641 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16642 | dprintf_style_enums, &dprintf_style, _("\ | |
16643 | Set the style of usage for dynamic printf."), _("\ | |
16644 | Show the style of usage for dynamic printf."), _("\ | |
16645 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16646 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16647 | console, as with the \"printf\" command.\n\ | |
16648 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16649 | program; by default printf(), but you can choose a different function or\n\ | |
16650 | output stream by setting dprintf-function and dprintf-channel."), | |
16651 | update_dprintf_commands, NULL, | |
16652 | &setlist, &showlist); | |
16653 | ||
16654 | dprintf_function = xstrdup ("printf"); | |
16655 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16656 | &dprintf_function, _("\ | |
16657 | Set the function to use for dynamic printf"), _("\ | |
16658 | Show the function to use for dynamic printf"), NULL, | |
16659 | update_dprintf_commands, NULL, | |
16660 | &setlist, &showlist); | |
16661 | ||
16662 | dprintf_channel = xstrdup (""); | |
16663 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16664 | &dprintf_channel, _("\ | |
16665 | Set the channel to use for dynamic printf"), _("\ | |
16666 | Show the channel to use for dynamic printf"), NULL, | |
16667 | update_dprintf_commands, NULL, | |
16668 | &setlist, &showlist); | |
16669 | ||
d3ce09f5 SS |
16670 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16671 | &disconnected_dprintf, _("\ | |
16672 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16673 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16674 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16675 | even if GDB disconnects or detaches from the target."), | |
16676 | NULL, | |
16677 | NULL, | |
16678 | &setlist, &showlist); | |
16679 | ||
16680 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16681 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16682 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16683 | ||
765dc015 | 16684 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16685 | |
16686 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16687 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16688 | } |