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" | |
0e9f083f | 38 | #include <string.h> |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
55aa24fb SDJ |
63 | #include "gdb_regex.h" |
64 | #include "probe.h" | |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
be34f849 | 66 | #include "continuations.h" |
1bfeeb0f JL |
67 | #include "stack.h" |
68 | #include "skip.h" | |
edcc5120 | 69 | #include "gdb_regex.h" |
b775012e | 70 | #include "ax-gdb.h" |
e2e4d78b | 71 | #include "dummy-frame.h" |
c906108c | 72 | |
d3ce09f5 SS |
73 | #include "format.h" |
74 | ||
1042e4c0 SS |
75 | /* readline include files */ |
76 | #include "readline/readline.h" | |
77 | #include "readline/history.h" | |
78 | ||
79 | /* readline defines this. */ | |
80 | #undef savestring | |
81 | ||
034dad6f | 82 | #include "mi/mi-common.h" |
7371cf6d | 83 | #include "python/python.h" |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
95a42b64 TT |
105 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
106 | void *), | |
107 | void *); | |
c906108c | 108 | |
a14ed312 | 109 | static void ignore_command (char *, int); |
c906108c | 110 | |
4efb68b1 | 111 | static int breakpoint_re_set_one (void *); |
c906108c | 112 | |
348d480f PA |
113 | static void breakpoint_re_set_default (struct breakpoint *); |
114 | ||
983af33b SDJ |
115 | static void create_sals_from_address_default (char **, |
116 | struct linespec_result *, | |
117 | enum bptype, char *, | |
118 | char **); | |
119 | ||
120 | static void create_breakpoints_sal_default (struct gdbarch *, | |
121 | struct linespec_result *, | |
e7e0cddf | 122 | char *, char *, enum bptype, |
983af33b SDJ |
123 | enum bpdisp, int, int, |
124 | int, | |
125 | const struct breakpoint_ops *, | |
44f238bb | 126 | int, int, int, unsigned); |
983af33b SDJ |
127 | |
128 | static void decode_linespec_default (struct breakpoint *, char **, | |
129 | struct symtabs_and_lines *); | |
130 | ||
a14ed312 | 131 | static void clear_command (char *, int); |
c906108c | 132 | |
a14ed312 | 133 | static void catch_command (char *, int); |
c906108c | 134 | |
a9634178 | 135 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 136 | |
98deb0da | 137 | static void break_command_1 (char *, int, int); |
c906108c | 138 | |
a14ed312 | 139 | static void mention (struct breakpoint *); |
c906108c | 140 | |
348d480f PA |
141 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
142 | enum bptype, | |
c0a91b2b | 143 | const struct breakpoint_ops *); |
3742cc8b YQ |
144 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
145 | const struct symtab_and_line *); | |
146 | ||
4a64f543 MS |
147 | /* This function is used in gdbtk sources and thus can not be made |
148 | static. */ | |
63c252f8 | 149 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 150 | struct symtab_and_line, |
c0a91b2b TT |
151 | enum bptype, |
152 | const struct breakpoint_ops *); | |
c906108c | 153 | |
06edf0c0 PA |
154 | static struct breakpoint * |
155 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
156 | enum bptype type, | |
c0a91b2b | 157 | const struct breakpoint_ops *ops); |
06edf0c0 | 158 | |
76897487 KB |
159 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
160 | ||
a6d9a66e UW |
161 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
162 | CORE_ADDR bpaddr, | |
88f7da05 | 163 | enum bptype bptype); |
76897487 | 164 | |
6c95b8df PA |
165 | static void describe_other_breakpoints (struct gdbarch *, |
166 | struct program_space *, CORE_ADDR, | |
5af949e3 | 167 | struct obj_section *, int); |
c906108c | 168 | |
6c95b8df PA |
169 | static int breakpoint_address_match (struct address_space *aspace1, |
170 | CORE_ADDR addr1, | |
171 | struct address_space *aspace2, | |
172 | CORE_ADDR addr2); | |
173 | ||
85d721b8 PA |
174 | static int watchpoint_locations_match (struct bp_location *loc1, |
175 | struct bp_location *loc2); | |
176 | ||
f1310107 TJB |
177 | static int breakpoint_location_address_match (struct bp_location *bl, |
178 | struct address_space *aspace, | |
179 | CORE_ADDR addr); | |
180 | ||
a14ed312 | 181 | static void breakpoints_info (char *, int); |
c906108c | 182 | |
d77f58be SS |
183 | static void watchpoints_info (char *, int); |
184 | ||
e5a67952 MS |
185 | static int breakpoint_1 (char *, int, |
186 | int (*) (const struct breakpoint *)); | |
c906108c | 187 | |
4efb68b1 | 188 | static int breakpoint_cond_eval (void *); |
c906108c | 189 | |
4efb68b1 | 190 | static void cleanup_executing_breakpoints (void *); |
c906108c | 191 | |
a14ed312 | 192 | static void commands_command (char *, int); |
c906108c | 193 | |
a14ed312 | 194 | static void condition_command (char *, int); |
c906108c | 195 | |
c5aa993b JM |
196 | typedef enum |
197 | { | |
198 | mark_inserted, | |
199 | mark_uninserted | |
200 | } | |
201 | insertion_state_t; | |
c906108c | 202 | |
0bde7532 | 203 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 204 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 205 | |
e514a9d6 | 206 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 207 | |
4efb68b1 | 208 | static int watchpoint_check (void *); |
c906108c | 209 | |
a14ed312 | 210 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 211 | |
a14ed312 | 212 | static int hw_breakpoint_used_count (void); |
c906108c | 213 | |
a1398e0c PA |
214 | static int hw_watchpoint_use_count (struct breakpoint *); |
215 | ||
216 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
217 | enum bptype type, | |
218 | int *other_type_used); | |
c906108c | 219 | |
a14ed312 | 220 | static void hbreak_command (char *, int); |
c906108c | 221 | |
a14ed312 | 222 | static void thbreak_command (char *, int); |
c906108c | 223 | |
816338b5 SS |
224 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
225 | int count); | |
c906108c | 226 | |
a14ed312 | 227 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 228 | |
a14ed312 | 229 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 230 | |
a14ed312 | 231 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 232 | |
a14ed312 | 233 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 234 | |
d03285ec UW |
235 | static void detach_single_step_breakpoints (void); |
236 | ||
6c95b8df PA |
237 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
238 | CORE_ADDR pc); | |
1aafd4da | 239 | |
fe3f5fa8 | 240 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
241 | static void incref_bp_location (struct bp_location *loc); |
242 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 243 | |
39d61571 | 244 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 245 | |
b60e7edf | 246 | static void update_global_location_list (int); |
a5606eee | 247 | |
b60e7edf | 248 | static void update_global_location_list_nothrow (int); |
74960c60 | 249 | |
d77f58be | 250 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
251 | |
252 | static void insert_breakpoint_locations (void); | |
a5606eee | 253 | |
a96d9b2e SDJ |
254 | static int syscall_catchpoint_p (struct breakpoint *b); |
255 | ||
1042e4c0 SS |
256 | static void tracepoints_info (char *, int); |
257 | ||
258 | static void delete_trace_command (char *, int); | |
259 | ||
260 | static void enable_trace_command (char *, int); | |
261 | ||
262 | static void disable_trace_command (char *, int); | |
263 | ||
264 | static void trace_pass_command (char *, int); | |
265 | ||
558a9d82 YQ |
266 | static void set_tracepoint_count (int num); |
267 | ||
9c06b0b4 TJB |
268 | static int is_masked_watchpoint (const struct breakpoint *b); |
269 | ||
b775012e LM |
270 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
271 | ||
983af33b SDJ |
272 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
273 | otherwise. */ | |
274 | ||
275 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 276 | |
2060206e PA |
277 | /* The abstract base class all breakpoint_ops structures inherit |
278 | from. */ | |
ab04a2af | 279 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
280 | |
281 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
282 | that are implemented on top of software or hardware breakpoints | |
283 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
284 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
285 | ||
286 | /* Internal breakpoints class type. */ | |
06edf0c0 | 287 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
288 | |
289 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
290 | static struct breakpoint_ops momentary_breakpoint_ops; |
291 | ||
e2e4d78b JK |
292 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
293 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
294 | ||
2060206e PA |
295 | /* The breakpoint_ops structure to be used in regular user created |
296 | breakpoints. */ | |
297 | struct breakpoint_ops bkpt_breakpoint_ops; | |
298 | ||
55aa24fb SDJ |
299 | /* Breakpoints set on probes. */ |
300 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
301 | ||
e7e0cddf | 302 | /* Dynamic printf class type. */ |
c5867ab6 | 303 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 304 | |
d3ce09f5 SS |
305 | /* The style in which to perform a dynamic printf. This is a user |
306 | option because different output options have different tradeoffs; | |
307 | if GDB does the printing, there is better error handling if there | |
308 | is a problem with any of the arguments, but using an inferior | |
309 | function lets you have special-purpose printers and sending of | |
310 | output to the same place as compiled-in print functions. */ | |
311 | ||
312 | static const char dprintf_style_gdb[] = "gdb"; | |
313 | static const char dprintf_style_call[] = "call"; | |
314 | static const char dprintf_style_agent[] = "agent"; | |
315 | static const char *const dprintf_style_enums[] = { | |
316 | dprintf_style_gdb, | |
317 | dprintf_style_call, | |
318 | dprintf_style_agent, | |
319 | NULL | |
320 | }; | |
321 | static const char *dprintf_style = dprintf_style_gdb; | |
322 | ||
323 | /* The function to use for dynamic printf if the preferred style is to | |
324 | call into the inferior. The value is simply a string that is | |
325 | copied into the command, so it can be anything that GDB can | |
326 | evaluate to a callable address, not necessarily a function name. */ | |
327 | ||
328 | static char *dprintf_function = ""; | |
329 | ||
330 | /* The channel to use for dynamic printf if the preferred style is to | |
331 | call into the inferior; if a nonempty string, it will be passed to | |
332 | the call as the first argument, with the format string as the | |
333 | second. As with the dprintf function, this can be anything that | |
334 | GDB knows how to evaluate, so in addition to common choices like | |
335 | "stderr", this could be an app-specific expression like | |
336 | "mystreams[curlogger]". */ | |
337 | ||
338 | static char *dprintf_channel = ""; | |
339 | ||
340 | /* True if dprintf commands should continue to operate even if GDB | |
341 | has disconnected. */ | |
342 | static int disconnected_dprintf = 1; | |
343 | ||
5cea2a26 PA |
344 | /* A reference-counted struct command_line. This lets multiple |
345 | breakpoints share a single command list. */ | |
346 | struct counted_command_line | |
347 | { | |
348 | /* The reference count. */ | |
349 | int refc; | |
350 | ||
351 | /* The command list. */ | |
352 | struct command_line *commands; | |
353 | }; | |
354 | ||
355 | struct command_line * | |
356 | breakpoint_commands (struct breakpoint *b) | |
357 | { | |
358 | return b->commands ? b->commands->commands : NULL; | |
359 | } | |
3daf8fe5 | 360 | |
f3b1572e PA |
361 | /* Flag indicating that a command has proceeded the inferior past the |
362 | current breakpoint. */ | |
363 | ||
364 | static int breakpoint_proceeded; | |
365 | ||
956a9fb9 | 366 | const char * |
2cec12e5 AR |
367 | bpdisp_text (enum bpdisp disp) |
368 | { | |
4a64f543 MS |
369 | /* NOTE: the following values are a part of MI protocol and |
370 | represent values of 'disp' field returned when inferior stops at | |
371 | a breakpoint. */ | |
bc043ef3 | 372 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 373 | |
2cec12e5 AR |
374 | return bpdisps[(int) disp]; |
375 | } | |
c906108c | 376 | |
4a64f543 | 377 | /* Prototypes for exported functions. */ |
c906108c | 378 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 379 | if such is available. */ |
c906108c SS |
380 | static int can_use_hw_watchpoints; |
381 | ||
920d2a44 AC |
382 | static void |
383 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
384 | struct cmd_list_element *c, | |
385 | const char *value) | |
386 | { | |
3e43a32a MS |
387 | fprintf_filtered (file, |
388 | _("Debugger's willingness to use " | |
389 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
390 | value); |
391 | } | |
392 | ||
fa8d40ab JJ |
393 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
394 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 395 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
396 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
397 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
398 | static void |
399 | show_pending_break_support (struct ui_file *file, int from_tty, | |
400 | struct cmd_list_element *c, | |
401 | const char *value) | |
402 | { | |
3e43a32a MS |
403 | fprintf_filtered (file, |
404 | _("Debugger's behavior regarding " | |
405 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
406 | value); |
407 | } | |
fa8d40ab | 408 | |
765dc015 | 409 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 410 | set with "break" but falling in read-only memory. |
765dc015 VP |
411 | If 0, gdb will warn about such breakpoints, but won't automatically |
412 | use hardware breakpoints. */ | |
413 | static int automatic_hardware_breakpoints; | |
414 | static void | |
415 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
416 | struct cmd_list_element *c, | |
417 | const char *value) | |
418 | { | |
3e43a32a MS |
419 | fprintf_filtered (file, |
420 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
421 | value); |
422 | } | |
423 | ||
33e5cbd6 PA |
424 | /* If on, gdb will keep breakpoints inserted even as inferior is |
425 | stopped, and immediately insert any new breakpoints. If off, gdb | |
426 | will insert breakpoints into inferior only when resuming it, and | |
427 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
428 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
429 | ||
72d0e2c5 YQ |
430 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
431 | ||
33e5cbd6 | 432 | static void |
74960c60 | 433 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 434 | struct cmd_list_element *c, const char *value) |
74960c60 | 435 | { |
72d0e2c5 | 436 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
437 | fprintf_filtered (file, |
438 | _("Always inserted breakpoint " | |
439 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
440 | value, |
441 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
442 | else | |
3e43a32a MS |
443 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
444 | value); | |
74960c60 VP |
445 | } |
446 | ||
33e5cbd6 PA |
447 | int |
448 | breakpoints_always_inserted_mode (void) | |
449 | { | |
72d0e2c5 YQ |
450 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
451 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 452 | } |
765dc015 | 453 | |
b775012e LM |
454 | static const char condition_evaluation_both[] = "host or target"; |
455 | ||
456 | /* Modes for breakpoint condition evaluation. */ | |
457 | static const char condition_evaluation_auto[] = "auto"; | |
458 | static const char condition_evaluation_host[] = "host"; | |
459 | static const char condition_evaluation_target[] = "target"; | |
460 | static const char *const condition_evaluation_enums[] = { | |
461 | condition_evaluation_auto, | |
462 | condition_evaluation_host, | |
463 | condition_evaluation_target, | |
464 | NULL | |
465 | }; | |
466 | ||
467 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
468 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
469 | ||
470 | /* Global that we use to display information to the user (gets its value from | |
471 | condition_evaluation_mode_1. */ | |
472 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
473 | ||
474 | /* Translate a condition evaluation mode MODE into either "host" | |
475 | or "target". This is used mostly to translate from "auto" to the | |
476 | real setting that is being used. It returns the translated | |
477 | evaluation mode. */ | |
478 | ||
479 | static const char * | |
480 | translate_condition_evaluation_mode (const char *mode) | |
481 | { | |
482 | if (mode == condition_evaluation_auto) | |
483 | { | |
484 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
485 | return condition_evaluation_target; | |
486 | else | |
487 | return condition_evaluation_host; | |
488 | } | |
489 | else | |
490 | return mode; | |
491 | } | |
492 | ||
493 | /* Discovers what condition_evaluation_auto translates to. */ | |
494 | ||
495 | static const char * | |
496 | breakpoint_condition_evaluation_mode (void) | |
497 | { | |
498 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
499 | } | |
500 | ||
501 | /* Return true if GDB should evaluate breakpoint conditions or false | |
502 | otherwise. */ | |
503 | ||
504 | static int | |
505 | gdb_evaluates_breakpoint_condition_p (void) | |
506 | { | |
507 | const char *mode = breakpoint_condition_evaluation_mode (); | |
508 | ||
509 | return (mode == condition_evaluation_host); | |
510 | } | |
511 | ||
a14ed312 | 512 | void _initialize_breakpoint (void); |
c906108c | 513 | |
c906108c SS |
514 | /* Are we executing breakpoint commands? */ |
515 | static int executing_breakpoint_commands; | |
516 | ||
c02f5703 MS |
517 | /* Are overlay event breakpoints enabled? */ |
518 | static int overlay_events_enabled; | |
519 | ||
e09342b5 TJB |
520 | /* See description in breakpoint.h. */ |
521 | int target_exact_watchpoints = 0; | |
522 | ||
c906108c | 523 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 524 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 525 | current breakpoint. */ |
c906108c | 526 | |
5c44784c | 527 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 528 | |
5c44784c JM |
529 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
530 | for (B = breakpoint_chain; \ | |
531 | B ? (TMP=B->next, 1): 0; \ | |
532 | B = TMP) | |
c906108c | 533 | |
4a64f543 MS |
534 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
535 | not provided so update_global_location_list must not be called | |
536 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 537 | |
876fa593 JK |
538 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
539 | for (BP_TMP = bp_location; \ | |
540 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
541 | BP_TMP++) | |
7cc221ef | 542 | |
b775012e LM |
543 | /* Iterates through locations with address ADDRESS for the currently selected |
544 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
545 | to where the loop should start from. | |
546 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
547 | appropriate location to start with. */ | |
548 | ||
549 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
550 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
551 | BP_LOCP_TMP = BP_LOCP_START; \ | |
552 | BP_LOCP_START \ | |
553 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
554 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
555 | BP_LOCP_TMP++) | |
556 | ||
1042e4c0 SS |
557 | /* Iterator for tracepoints only. */ |
558 | ||
559 | #define ALL_TRACEPOINTS(B) \ | |
560 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 561 | if (is_tracepoint (B)) |
1042e4c0 | 562 | |
7cc221ef | 563 | /* Chains of all breakpoints defined. */ |
c906108c SS |
564 | |
565 | struct breakpoint *breakpoint_chain; | |
566 | ||
876fa593 JK |
567 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
568 | ||
569 | static struct bp_location **bp_location; | |
570 | ||
571 | /* Number of elements of BP_LOCATION. */ | |
572 | ||
573 | static unsigned bp_location_count; | |
574 | ||
4a64f543 MS |
575 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
576 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
577 | result from bp_location_has_shadow. You can use it for roughly | |
578 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
579 | an address you need to read. */ | |
876fa593 JK |
580 | |
581 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
582 | ||
4a64f543 MS |
583 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
584 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
585 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
586 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
587 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
588 | |
589 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 590 | |
4a64f543 MS |
591 | /* The locations that no longer correspond to any breakpoint, unlinked |
592 | from bp_location array, but for which a hit may still be reported | |
593 | by a target. */ | |
20874c92 VP |
594 | VEC(bp_location_p) *moribund_locations = NULL; |
595 | ||
c906108c SS |
596 | /* Number of last breakpoint made. */ |
597 | ||
95a42b64 TT |
598 | static int breakpoint_count; |
599 | ||
86b17b60 PA |
600 | /* The value of `breakpoint_count' before the last command that |
601 | created breakpoints. If the last (break-like) command created more | |
602 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
603 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
604 | static int prev_breakpoint_count; | |
c906108c | 605 | |
1042e4c0 SS |
606 | /* Number of last tracepoint made. */ |
607 | ||
95a42b64 | 608 | static int tracepoint_count; |
1042e4c0 | 609 | |
6149aea9 PA |
610 | static struct cmd_list_element *breakpoint_set_cmdlist; |
611 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 612 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 613 | |
468d015d JJ |
614 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
615 | static int | |
616 | breakpoint_enabled (struct breakpoint *b) | |
617 | { | |
0d381245 | 618 | return (b->enable_state == bp_enabled); |
468d015d JJ |
619 | } |
620 | ||
c906108c SS |
621 | /* Set breakpoint count to NUM. */ |
622 | ||
95a42b64 | 623 | static void |
fba45db2 | 624 | set_breakpoint_count (int num) |
c906108c | 625 | { |
86b17b60 | 626 | prev_breakpoint_count = breakpoint_count; |
c906108c | 627 | breakpoint_count = num; |
4fa62494 | 628 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
629 | } |
630 | ||
86b17b60 PA |
631 | /* Used by `start_rbreak_breakpoints' below, to record the current |
632 | breakpoint count before "rbreak" creates any breakpoint. */ | |
633 | static int rbreak_start_breakpoint_count; | |
634 | ||
95a42b64 TT |
635 | /* Called at the start an "rbreak" command to record the first |
636 | breakpoint made. */ | |
86b17b60 | 637 | |
95a42b64 TT |
638 | void |
639 | start_rbreak_breakpoints (void) | |
640 | { | |
86b17b60 | 641 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
642 | } |
643 | ||
644 | /* Called at the end of an "rbreak" command to record the last | |
645 | breakpoint made. */ | |
86b17b60 | 646 | |
95a42b64 TT |
647 | void |
648 | end_rbreak_breakpoints (void) | |
649 | { | |
86b17b60 | 650 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
651 | } |
652 | ||
4a64f543 | 653 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
654 | |
655 | void | |
fba45db2 | 656 | clear_breakpoint_hit_counts (void) |
c906108c SS |
657 | { |
658 | struct breakpoint *b; | |
659 | ||
660 | ALL_BREAKPOINTS (b) | |
661 | b->hit_count = 0; | |
662 | } | |
663 | ||
9add0f1b TT |
664 | /* Allocate a new counted_command_line with reference count of 1. |
665 | The new structure owns COMMANDS. */ | |
666 | ||
667 | static struct counted_command_line * | |
668 | alloc_counted_command_line (struct command_line *commands) | |
669 | { | |
670 | struct counted_command_line *result | |
671 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 672 | |
9add0f1b TT |
673 | result->refc = 1; |
674 | result->commands = commands; | |
675 | return result; | |
676 | } | |
677 | ||
678 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
679 | ||
680 | static void | |
681 | incref_counted_command_line (struct counted_command_line *cmd) | |
682 | { | |
683 | if (cmd) | |
684 | ++cmd->refc; | |
685 | } | |
686 | ||
687 | /* Decrement reference count. If the reference count reaches 0, | |
688 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
689 | nothing if *CMDP is NULL. */ | |
690 | ||
691 | static void | |
692 | decref_counted_command_line (struct counted_command_line **cmdp) | |
693 | { | |
694 | if (*cmdp) | |
695 | { | |
696 | if (--(*cmdp)->refc == 0) | |
697 | { | |
698 | free_command_lines (&(*cmdp)->commands); | |
699 | xfree (*cmdp); | |
700 | } | |
701 | *cmdp = NULL; | |
702 | } | |
703 | } | |
704 | ||
705 | /* A cleanup function that calls decref_counted_command_line. */ | |
706 | ||
707 | static void | |
708 | do_cleanup_counted_command_line (void *arg) | |
709 | { | |
710 | decref_counted_command_line (arg); | |
711 | } | |
712 | ||
713 | /* Create a cleanup that calls decref_counted_command_line on the | |
714 | argument. */ | |
715 | ||
716 | static struct cleanup * | |
717 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
718 | { | |
719 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
720 | } | |
721 | ||
c906108c | 722 | \f |
48cb2d85 VP |
723 | /* Return the breakpoint with the specified number, or NULL |
724 | if the number does not refer to an existing breakpoint. */ | |
725 | ||
726 | struct breakpoint * | |
727 | get_breakpoint (int num) | |
728 | { | |
729 | struct breakpoint *b; | |
730 | ||
731 | ALL_BREAKPOINTS (b) | |
732 | if (b->number == num) | |
733 | return b; | |
734 | ||
735 | return NULL; | |
736 | } | |
5c44784c | 737 | |
c906108c | 738 | \f |
adc36818 | 739 | |
b775012e LM |
740 | /* Mark locations as "conditions have changed" in case the target supports |
741 | evaluating conditions on its side. */ | |
742 | ||
743 | static void | |
744 | mark_breakpoint_modified (struct breakpoint *b) | |
745 | { | |
746 | struct bp_location *loc; | |
747 | ||
748 | /* This is only meaningful if the target is | |
749 | evaluating conditions and if the user has | |
750 | opted for condition evaluation on the target's | |
751 | side. */ | |
752 | if (gdb_evaluates_breakpoint_condition_p () | |
753 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
754 | return; | |
755 | ||
756 | if (!is_breakpoint (b)) | |
757 | return; | |
758 | ||
759 | for (loc = b->loc; loc; loc = loc->next) | |
760 | loc->condition_changed = condition_modified; | |
761 | } | |
762 | ||
763 | /* Mark location as "conditions have changed" in case the target supports | |
764 | evaluating conditions on its side. */ | |
765 | ||
766 | static void | |
767 | mark_breakpoint_location_modified (struct bp_location *loc) | |
768 | { | |
769 | /* This is only meaningful if the target is | |
770 | evaluating conditions and if the user has | |
771 | opted for condition evaluation on the target's | |
772 | side. */ | |
773 | if (gdb_evaluates_breakpoint_condition_p () | |
774 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
775 | ||
776 | return; | |
777 | ||
778 | if (!is_breakpoint (loc->owner)) | |
779 | return; | |
780 | ||
781 | loc->condition_changed = condition_modified; | |
782 | } | |
783 | ||
784 | /* Sets the condition-evaluation mode using the static global | |
785 | condition_evaluation_mode. */ | |
786 | ||
787 | static void | |
788 | set_condition_evaluation_mode (char *args, int from_tty, | |
789 | struct cmd_list_element *c) | |
790 | { | |
b775012e LM |
791 | const char *old_mode, *new_mode; |
792 | ||
793 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
794 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
795 | { | |
796 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
797 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
798 | "Using host evaluation mode instead.")); | |
799 | return; | |
800 | } | |
801 | ||
802 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
803 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
804 | ||
abf1152a JK |
805 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
806 | settings was "auto". */ | |
807 | condition_evaluation_mode = condition_evaluation_mode_1; | |
808 | ||
b775012e LM |
809 | /* Only update the mode if the user picked a different one. */ |
810 | if (new_mode != old_mode) | |
811 | { | |
812 | struct bp_location *loc, **loc_tmp; | |
813 | /* If the user switched to a different evaluation mode, we | |
814 | need to synch the changes with the target as follows: | |
815 | ||
816 | "host" -> "target": Send all (valid) conditions to the target. | |
817 | "target" -> "host": Remove all the conditions from the target. | |
818 | */ | |
819 | ||
b775012e LM |
820 | if (new_mode == condition_evaluation_target) |
821 | { | |
822 | /* Mark everything modified and synch conditions with the | |
823 | target. */ | |
824 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
825 | mark_breakpoint_location_modified (loc); | |
826 | } | |
827 | else | |
828 | { | |
829 | /* Manually mark non-duplicate locations to synch conditions | |
830 | with the target. We do this to remove all the conditions the | |
831 | target knows about. */ | |
832 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
833 | if (is_breakpoint (loc->owner) && loc->inserted) | |
834 | loc->needs_update = 1; | |
835 | } | |
836 | ||
837 | /* Do the update. */ | |
838 | update_global_location_list (1); | |
839 | } | |
840 | ||
841 | return; | |
842 | } | |
843 | ||
844 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
845 | what "auto" is translating to. */ | |
846 | ||
847 | static void | |
848 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
849 | struct cmd_list_element *c, const char *value) | |
850 | { | |
851 | if (condition_evaluation_mode == condition_evaluation_auto) | |
852 | fprintf_filtered (file, | |
853 | _("Breakpoint condition evaluation " | |
854 | "mode is %s (currently %s).\n"), | |
855 | value, | |
856 | breakpoint_condition_evaluation_mode ()); | |
857 | else | |
858 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
859 | value); | |
860 | } | |
861 | ||
862 | /* A comparison function for bp_location AP and BP that is used by | |
863 | bsearch. This comparison function only cares about addresses, unlike | |
864 | the more general bp_location_compare function. */ | |
865 | ||
866 | static int | |
867 | bp_location_compare_addrs (const void *ap, const void *bp) | |
868 | { | |
869 | struct bp_location *a = *(void **) ap; | |
870 | struct bp_location *b = *(void **) bp; | |
871 | ||
872 | if (a->address == b->address) | |
873 | return 0; | |
874 | else | |
875 | return ((a->address > b->address) - (a->address < b->address)); | |
876 | } | |
877 | ||
878 | /* Helper function to skip all bp_locations with addresses | |
879 | less than ADDRESS. It returns the first bp_location that | |
880 | is greater than or equal to ADDRESS. If none is found, just | |
881 | return NULL. */ | |
882 | ||
883 | static struct bp_location ** | |
884 | get_first_locp_gte_addr (CORE_ADDR address) | |
885 | { | |
886 | struct bp_location dummy_loc; | |
887 | struct bp_location *dummy_locp = &dummy_loc; | |
888 | struct bp_location **locp_found = NULL; | |
889 | ||
890 | /* Initialize the dummy location's address field. */ | |
891 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
892 | dummy_loc.address = address; | |
893 | ||
894 | /* Find a close match to the first location at ADDRESS. */ | |
895 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
896 | sizeof (struct bp_location **), | |
897 | bp_location_compare_addrs); | |
898 | ||
899 | /* Nothing was found, nothing left to do. */ | |
900 | if (locp_found == NULL) | |
901 | return NULL; | |
902 | ||
903 | /* We may have found a location that is at ADDRESS but is not the first in the | |
904 | location's list. Go backwards (if possible) and locate the first one. */ | |
905 | while ((locp_found - 1) >= bp_location | |
906 | && (*(locp_found - 1))->address == address) | |
907 | locp_found--; | |
908 | ||
909 | return locp_found; | |
910 | } | |
911 | ||
adc36818 PM |
912 | void |
913 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
914 | int from_tty) | |
915 | { | |
3a5c3e22 PA |
916 | xfree (b->cond_string); |
917 | b->cond_string = NULL; | |
adc36818 | 918 | |
3a5c3e22 | 919 | if (is_watchpoint (b)) |
adc36818 | 920 | { |
3a5c3e22 PA |
921 | struct watchpoint *w = (struct watchpoint *) b; |
922 | ||
923 | xfree (w->cond_exp); | |
924 | w->cond_exp = NULL; | |
925 | } | |
926 | else | |
927 | { | |
928 | struct bp_location *loc; | |
929 | ||
930 | for (loc = b->loc; loc; loc = loc->next) | |
931 | { | |
932 | xfree (loc->cond); | |
933 | loc->cond = NULL; | |
b775012e LM |
934 | |
935 | /* No need to free the condition agent expression | |
936 | bytecode (if we have one). We will handle this | |
937 | when we go through update_global_location_list. */ | |
3a5c3e22 | 938 | } |
adc36818 | 939 | } |
adc36818 PM |
940 | |
941 | if (*exp == 0) | |
942 | { | |
943 | if (from_tty) | |
944 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
945 | } | |
946 | else | |
947 | { | |
bbc13ae3 | 948 | const char *arg = exp; |
cc59ec59 | 949 | |
adc36818 PM |
950 | /* I don't know if it matters whether this is the string the user |
951 | typed in or the decompiled expression. */ | |
952 | b->cond_string = xstrdup (arg); | |
953 | b->condition_not_parsed = 0; | |
954 | ||
955 | if (is_watchpoint (b)) | |
956 | { | |
3a5c3e22 PA |
957 | struct watchpoint *w = (struct watchpoint *) b; |
958 | ||
adc36818 PM |
959 | innermost_block = NULL; |
960 | arg = exp; | |
1bb9788d | 961 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
962 | if (*arg) |
963 | error (_("Junk at end of expression")); | |
3a5c3e22 | 964 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
965 | } |
966 | else | |
967 | { | |
3a5c3e22 PA |
968 | struct bp_location *loc; |
969 | ||
adc36818 PM |
970 | for (loc = b->loc; loc; loc = loc->next) |
971 | { | |
972 | arg = exp; | |
973 | loc->cond = | |
1bb9788d TT |
974 | parse_exp_1 (&arg, loc->address, |
975 | block_for_pc (loc->address), 0); | |
adc36818 PM |
976 | if (*arg) |
977 | error (_("Junk at end of expression")); | |
978 | } | |
979 | } | |
980 | } | |
b775012e LM |
981 | mark_breakpoint_modified (b); |
982 | ||
8d3788bd | 983 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
984 | } |
985 | ||
d55637df TT |
986 | /* Completion for the "condition" command. */ |
987 | ||
988 | static VEC (char_ptr) * | |
6f937416 PA |
989 | condition_completer (struct cmd_list_element *cmd, |
990 | const char *text, const char *word) | |
d55637df | 991 | { |
6f937416 | 992 | const char *space; |
d55637df | 993 | |
6f937416 PA |
994 | text = skip_spaces_const (text); |
995 | space = skip_to_space_const (text); | |
d55637df TT |
996 | if (*space == '\0') |
997 | { | |
998 | int len; | |
999 | struct breakpoint *b; | |
1000 | VEC (char_ptr) *result = NULL; | |
1001 | ||
1002 | if (text[0] == '$') | |
1003 | { | |
1004 | /* We don't support completion of history indices. */ | |
1005 | if (isdigit (text[1])) | |
1006 | return NULL; | |
1007 | return complete_internalvar (&text[1]); | |
1008 | } | |
1009 | ||
1010 | /* We're completing the breakpoint number. */ | |
1011 | len = strlen (text); | |
1012 | ||
1013 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1014 | { |
1015 | char number[50]; | |
1016 | ||
1017 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1018 | ||
1019 | if (strncmp (number, text, len) == 0) | |
1020 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1021 | } | |
d55637df TT |
1022 | |
1023 | return result; | |
1024 | } | |
1025 | ||
1026 | /* We're completing the expression part. */ | |
6f937416 | 1027 | text = skip_spaces_const (space); |
d55637df TT |
1028 | return expression_completer (cmd, text, word); |
1029 | } | |
1030 | ||
c906108c SS |
1031 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1032 | ||
1033 | static void | |
fba45db2 | 1034 | condition_command (char *arg, int from_tty) |
c906108c | 1035 | { |
52f0bd74 | 1036 | struct breakpoint *b; |
c906108c | 1037 | char *p; |
52f0bd74 | 1038 | int bnum; |
c906108c SS |
1039 | |
1040 | if (arg == 0) | |
e2e0b3e5 | 1041 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1042 | |
1043 | p = arg; | |
1044 | bnum = get_number (&p); | |
5c44784c | 1045 | if (bnum == 0) |
8a3fe4f8 | 1046 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1047 | |
1048 | ALL_BREAKPOINTS (b) | |
1049 | if (b->number == bnum) | |
2f069f6f | 1050 | { |
7371cf6d PM |
1051 | /* Check if this breakpoint has a Python object assigned to |
1052 | it, and if it has a definition of the "stop" | |
1053 | method. This method and conditions entered into GDB from | |
1054 | the CLI are mutually exclusive. */ | |
1055 | if (b->py_bp_object | |
1056 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
1057 | error (_("Cannot set a condition where a Python 'stop' " | |
1058 | "method has been defined in the breakpoint.")); | |
2566ad2d | 1059 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1060 | |
1061 | if (is_breakpoint (b)) | |
1062 | update_global_location_list (1); | |
1063 | ||
2f069f6f JB |
1064 | return; |
1065 | } | |
c906108c | 1066 | |
8a3fe4f8 | 1067 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1068 | } |
1069 | ||
a7bdde9e VP |
1070 | /* Check that COMMAND do not contain commands that are suitable |
1071 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1072 | Throw if any such commands is found. */ |
1073 | ||
a7bdde9e VP |
1074 | static void |
1075 | check_no_tracepoint_commands (struct command_line *commands) | |
1076 | { | |
1077 | struct command_line *c; | |
cc59ec59 | 1078 | |
a7bdde9e VP |
1079 | for (c = commands; c; c = c->next) |
1080 | { | |
1081 | int i; | |
1082 | ||
1083 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1084 | error (_("The 'while-stepping' command can " |
1085 | "only be used for tracepoints")); | |
a7bdde9e VP |
1086 | |
1087 | for (i = 0; i < c->body_count; ++i) | |
1088 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1089 | ||
1090 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1091 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1092 | command directly. */ |
1093 | if (strstr (c->line, "collect ") == c->line) | |
1094 | error (_("The 'collect' command can only be used for tracepoints")); | |
1095 | ||
51661e93 VP |
1096 | if (strstr (c->line, "teval ") == c->line) |
1097 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1098 | } |
1099 | } | |
1100 | ||
d77f58be SS |
1101 | /* Encapsulate tests for different types of tracepoints. */ |
1102 | ||
d9b3f62e PA |
1103 | static int |
1104 | is_tracepoint_type (enum bptype type) | |
1105 | { | |
1106 | return (type == bp_tracepoint | |
1107 | || type == bp_fast_tracepoint | |
1108 | || type == bp_static_tracepoint); | |
1109 | } | |
1110 | ||
a7bdde9e | 1111 | int |
d77f58be | 1112 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1113 | { |
d9b3f62e | 1114 | return is_tracepoint_type (b->type); |
a7bdde9e | 1115 | } |
d9b3f62e | 1116 | |
e5dd4106 | 1117 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1118 | breakpoint. This function will throw an exception if a problem is |
1119 | found. */ | |
48cb2d85 | 1120 | |
95a42b64 TT |
1121 | static void |
1122 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1123 | struct command_line *commands) | |
48cb2d85 | 1124 | { |
d77f58be | 1125 | if (is_tracepoint (b)) |
a7bdde9e | 1126 | { |
c9a6ce02 | 1127 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1128 | struct command_line *c; |
1129 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1130 | |
1131 | /* Reset the while-stepping step count. The previous commands | |
1132 | might have included a while-stepping action, while the new | |
1133 | ones might not. */ | |
1134 | t->step_count = 0; | |
1135 | ||
1136 | /* We need to verify that each top-level element of commands is | |
1137 | valid for tracepoints, that there's at most one | |
1138 | while-stepping element, and that the while-stepping's body | |
1139 | has valid tracing commands excluding nested while-stepping. | |
1140 | We also need to validate the tracepoint action line in the | |
1141 | context of the tracepoint --- validate_actionline actually | |
1142 | has side effects, like setting the tracepoint's | |
1143 | while-stepping STEP_COUNT, in addition to checking if the | |
1144 | collect/teval actions parse and make sense in the | |
1145 | tracepoint's context. */ | |
a7bdde9e VP |
1146 | for (c = commands; c; c = c->next) |
1147 | { | |
a7bdde9e VP |
1148 | if (c->control_type == while_stepping_control) |
1149 | { | |
1150 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1151 | error (_("The 'while-stepping' command " |
1152 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1153 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1154 | error (_("The 'while-stepping' command " |
1155 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1156 | |
1157 | if (while_stepping) | |
3e43a32a MS |
1158 | error (_("The 'while-stepping' command " |
1159 | "can be used only once")); | |
a7bdde9e VP |
1160 | else |
1161 | while_stepping = c; | |
1162 | } | |
c9a6ce02 PA |
1163 | |
1164 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1165 | } |
1166 | if (while_stepping) | |
1167 | { | |
1168 | struct command_line *c2; | |
1169 | ||
1170 | gdb_assert (while_stepping->body_count == 1); | |
1171 | c2 = while_stepping->body_list[0]; | |
1172 | for (; c2; c2 = c2->next) | |
1173 | { | |
a7bdde9e VP |
1174 | if (c2->control_type == while_stepping_control) |
1175 | error (_("The 'while-stepping' command cannot be nested")); | |
1176 | } | |
1177 | } | |
1178 | } | |
1179 | else | |
1180 | { | |
1181 | check_no_tracepoint_commands (commands); | |
1182 | } | |
95a42b64 TT |
1183 | } |
1184 | ||
0fb4aa4b PA |
1185 | /* Return a vector of all the static tracepoints set at ADDR. The |
1186 | caller is responsible for releasing the vector. */ | |
1187 | ||
1188 | VEC(breakpoint_p) * | |
1189 | static_tracepoints_here (CORE_ADDR addr) | |
1190 | { | |
1191 | struct breakpoint *b; | |
1192 | VEC(breakpoint_p) *found = 0; | |
1193 | struct bp_location *loc; | |
1194 | ||
1195 | ALL_BREAKPOINTS (b) | |
1196 | if (b->type == bp_static_tracepoint) | |
1197 | { | |
1198 | for (loc = b->loc; loc; loc = loc->next) | |
1199 | if (loc->address == addr) | |
1200 | VEC_safe_push(breakpoint_p, found, b); | |
1201 | } | |
1202 | ||
1203 | return found; | |
1204 | } | |
1205 | ||
95a42b64 | 1206 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1207 | validate that only allowed commands are included. */ |
95a42b64 TT |
1208 | |
1209 | void | |
4a64f543 MS |
1210 | breakpoint_set_commands (struct breakpoint *b, |
1211 | struct command_line *commands) | |
95a42b64 TT |
1212 | { |
1213 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1214 | |
9add0f1b TT |
1215 | decref_counted_command_line (&b->commands); |
1216 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1217 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1218 | } |
1219 | ||
45a43567 TT |
1220 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1221 | is not the same as the "silent" that may appear in the breakpoint's | |
1222 | commands. */ | |
1223 | ||
1224 | void | |
1225 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1226 | { | |
1227 | int old_silent = b->silent; | |
1228 | ||
1229 | b->silent = silent; | |
1230 | if (old_silent != silent) | |
8d3788bd | 1231 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1232 | } |
1233 | ||
1234 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1235 | breakpoint work for any thread. */ | |
1236 | ||
1237 | void | |
1238 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1239 | { | |
1240 | int old_thread = b->thread; | |
1241 | ||
1242 | b->thread = thread; | |
1243 | if (old_thread != thread) | |
8d3788bd | 1244 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1245 | } |
1246 | ||
1247 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1248 | breakpoint work for any task. */ | |
1249 | ||
1250 | void | |
1251 | breakpoint_set_task (struct breakpoint *b, int task) | |
1252 | { | |
1253 | int old_task = b->task; | |
1254 | ||
1255 | b->task = task; | |
1256 | if (old_task != task) | |
8d3788bd | 1257 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1258 | } |
1259 | ||
95a42b64 TT |
1260 | void |
1261 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1262 | { |
1263 | struct breakpoint *b = closure; | |
cc59ec59 | 1264 | |
6f937416 | 1265 | validate_actionline (line, b); |
a7bdde9e VP |
1266 | } |
1267 | ||
95a42b64 TT |
1268 | /* A structure used to pass information through |
1269 | map_breakpoint_numbers. */ | |
1270 | ||
1271 | struct commands_info | |
1272 | { | |
1273 | /* True if the command was typed at a tty. */ | |
1274 | int from_tty; | |
86b17b60 PA |
1275 | |
1276 | /* The breakpoint range spec. */ | |
1277 | char *arg; | |
1278 | ||
95a42b64 TT |
1279 | /* Non-NULL if the body of the commands are being read from this |
1280 | already-parsed command. */ | |
1281 | struct command_line *control; | |
86b17b60 | 1282 | |
95a42b64 TT |
1283 | /* The command lines read from the user, or NULL if they have not |
1284 | yet been read. */ | |
1285 | struct counted_command_line *cmd; | |
1286 | }; | |
1287 | ||
1288 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1289 | commands_command. */ | |
1290 | ||
c906108c | 1291 | static void |
95a42b64 | 1292 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1293 | { |
95a42b64 | 1294 | struct commands_info *info = data; |
c906108c | 1295 | |
95a42b64 TT |
1296 | if (info->cmd == NULL) |
1297 | { | |
1298 | struct command_line *l; | |
5c44784c | 1299 | |
95a42b64 TT |
1300 | if (info->control != NULL) |
1301 | l = copy_command_lines (info->control->body_list[0]); | |
1302 | else | |
86b17b60 PA |
1303 | { |
1304 | struct cleanup *old_chain; | |
1305 | char *str; | |
c5aa993b | 1306 | |
3e43a32a MS |
1307 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1308 | "%s, one per line."), | |
86b17b60 PA |
1309 | info->arg); |
1310 | ||
1311 | old_chain = make_cleanup (xfree, str); | |
1312 | ||
1313 | l = read_command_lines (str, | |
1314 | info->from_tty, 1, | |
d77f58be | 1315 | (is_tracepoint (b) |
86b17b60 PA |
1316 | ? check_tracepoint_command : 0), |
1317 | b); | |
1318 | ||
1319 | do_cleanups (old_chain); | |
1320 | } | |
a7bdde9e | 1321 | |
95a42b64 TT |
1322 | info->cmd = alloc_counted_command_line (l); |
1323 | } | |
1324 | ||
1325 | /* If a breakpoint was on the list more than once, we don't need to | |
1326 | do anything. */ | |
1327 | if (b->commands != info->cmd) | |
1328 | { | |
1329 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1330 | incref_counted_command_line (info->cmd); | |
1331 | decref_counted_command_line (&b->commands); | |
1332 | b->commands = info->cmd; | |
8d3788bd | 1333 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1334 | } |
95a42b64 TT |
1335 | } |
1336 | ||
1337 | static void | |
4a64f543 MS |
1338 | commands_command_1 (char *arg, int from_tty, |
1339 | struct command_line *control) | |
95a42b64 TT |
1340 | { |
1341 | struct cleanup *cleanups; | |
1342 | struct commands_info info; | |
1343 | ||
1344 | info.from_tty = from_tty; | |
1345 | info.control = control; | |
1346 | info.cmd = NULL; | |
1347 | /* If we read command lines from the user, then `info' will hold an | |
1348 | extra reference to the commands that we must clean up. */ | |
1349 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1350 | ||
1351 | if (arg == NULL || !*arg) | |
1352 | { | |
86b17b60 | 1353 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1354 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1355 | breakpoint_count); | |
95a42b64 TT |
1356 | else if (breakpoint_count > 0) |
1357 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1358 | else |
1359 | { | |
1360 | /* So that we don't try to free the incoming non-NULL | |
1361 | argument in the cleanup below. Mapping breakpoint | |
1362 | numbers will fail in this case. */ | |
1363 | arg = NULL; | |
1364 | } | |
95a42b64 | 1365 | } |
9766ced4 SS |
1366 | else |
1367 | /* The command loop has some static state, so we need to preserve | |
1368 | our argument. */ | |
1369 | arg = xstrdup (arg); | |
86b17b60 PA |
1370 | |
1371 | if (arg != NULL) | |
1372 | make_cleanup (xfree, arg); | |
1373 | ||
1374 | info.arg = arg; | |
95a42b64 TT |
1375 | |
1376 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1377 | ||
1378 | if (info.cmd == NULL) | |
1379 | error (_("No breakpoints specified.")); | |
1380 | ||
1381 | do_cleanups (cleanups); | |
1382 | } | |
1383 | ||
1384 | static void | |
1385 | commands_command (char *arg, int from_tty) | |
1386 | { | |
1387 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1388 | } |
40c03ae8 EZ |
1389 | |
1390 | /* Like commands_command, but instead of reading the commands from | |
1391 | input stream, takes them from an already parsed command structure. | |
1392 | ||
1393 | This is used by cli-script.c to DTRT with breakpoint commands | |
1394 | that are part of if and while bodies. */ | |
1395 | enum command_control_type | |
1396 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1397 | { | |
95a42b64 TT |
1398 | commands_command_1 (arg, 0, cmd); |
1399 | return simple_control; | |
40c03ae8 | 1400 | } |
876fa593 JK |
1401 | |
1402 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1403 | ||
1404 | static int | |
1405 | bp_location_has_shadow (struct bp_location *bl) | |
1406 | { | |
1407 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1408 | return 0; | |
1409 | if (!bl->inserted) | |
1410 | return 0; | |
1411 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1412 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1413 | return 0; |
1414 | return 1; | |
1415 | } | |
1416 | ||
8defab1a | 1417 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1418 | by replacing any memory breakpoints with their shadowed contents. |
1419 | ||
35c63cd8 JB |
1420 | If READBUF is not NULL, this buffer must not overlap with any of |
1421 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1422 | a failed assertion internal error will be raised. | |
1423 | ||
876fa593 | 1424 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1425 | bl->address - bp_location_placed_address_before_address_max |
1426 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1427 | The range we were requested to resolve shadows for is: |
1428 | memaddr ... memaddr + len | |
1429 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1430 | memaddr + len <= (bl->address |
1431 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1432 | and: |
35df4500 | 1433 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1434 | |
8defab1a | 1435 | void |
f0ba3972 PA |
1436 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1437 | const gdb_byte *writebuf_org, | |
1438 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1439 | { |
4a64f543 MS |
1440 | /* Left boundary, right boundary and median element of our binary |
1441 | search. */ | |
876fa593 JK |
1442 | unsigned bc_l, bc_r, bc; |
1443 | ||
4a64f543 MS |
1444 | /* Find BC_L which is a leftmost element which may affect BUF |
1445 | content. It is safe to report lower value but a failure to | |
1446 | report higher one. */ | |
876fa593 JK |
1447 | |
1448 | bc_l = 0; | |
1449 | bc_r = bp_location_count; | |
1450 | while (bc_l + 1 < bc_r) | |
1451 | { | |
35df4500 | 1452 | struct bp_location *bl; |
876fa593 JK |
1453 | |
1454 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1455 | bl = bp_location[bc]; |
876fa593 | 1456 | |
4a64f543 MS |
1457 | /* Check first BL->ADDRESS will not overflow due to the added |
1458 | constant. Then advance the left boundary only if we are sure | |
1459 | the BC element can in no way affect the BUF content (MEMADDR | |
1460 | to MEMADDR + LEN range). | |
876fa593 | 1461 | |
4a64f543 MS |
1462 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1463 | offset so that we cannot miss a breakpoint with its shadow | |
1464 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1465 | |
35df4500 TJB |
1466 | if ((bl->address + bp_location_shadow_len_after_address_max |
1467 | >= bl->address) | |
1468 | && (bl->address + bp_location_shadow_len_after_address_max | |
1469 | <= memaddr)) | |
876fa593 JK |
1470 | bc_l = bc; |
1471 | else | |
1472 | bc_r = bc; | |
1473 | } | |
1474 | ||
128070bb PA |
1475 | /* Due to the binary search above, we need to make sure we pick the |
1476 | first location that's at BC_L's address. E.g., if there are | |
1477 | multiple locations at the same address, BC_L may end up pointing | |
1478 | at a duplicate location, and miss the "master"/"inserted" | |
1479 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1480 | B: | |
1481 | ||
1482 | L1@A, L2@A, L3@B, ... | |
1483 | ||
1484 | BC_L could end up pointing at location L2, while the "master" | |
1485 | location could be L1. Since the `loc->inserted' flag is only set | |
1486 | on "master" locations, we'd forget to restore the shadow of L1 | |
1487 | and L2. */ | |
1488 | while (bc_l > 0 | |
1489 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1490 | bc_l--; | |
1491 | ||
876fa593 JK |
1492 | /* Now do full processing of the found relevant range of elements. */ |
1493 | ||
1494 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1495 | { |
35df4500 | 1496 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1497 | CORE_ADDR bp_addr = 0; |
1498 | int bp_size = 0; | |
1499 | int bptoffset = 0; | |
1500 | ||
35df4500 TJB |
1501 | /* bp_location array has BL->OWNER always non-NULL. */ |
1502 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1503 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1504 | bl->owner->number); |
ffce0d52 | 1505 | |
e5dd4106 | 1506 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1507 | content. */ |
1508 | ||
35df4500 TJB |
1509 | if (bl->address >= bp_location_placed_address_before_address_max |
1510 | && memaddr + len <= (bl->address | |
1511 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1512 | break; |
1513 | ||
35df4500 | 1514 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1515 | continue; |
35df4500 | 1516 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1517 | current_program_space->aspace, 0)) |
1518 | continue; | |
1519 | ||
c5aa993b JM |
1520 | /* Addresses and length of the part of the breakpoint that |
1521 | we need to copy. */ | |
35df4500 TJB |
1522 | bp_addr = bl->target_info.placed_address; |
1523 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1524 | |
c5aa993b JM |
1525 | if (bp_addr + bp_size <= memaddr) |
1526 | /* The breakpoint is entirely before the chunk of memory we | |
1527 | are reading. */ | |
1528 | continue; | |
8defab1a | 1529 | |
c5aa993b JM |
1530 | if (bp_addr >= memaddr + len) |
1531 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1532 | reading. */ |
c5aa993b | 1533 | continue; |
c5aa993b | 1534 | |
8defab1a DJ |
1535 | /* Offset within shadow_contents. */ |
1536 | if (bp_addr < memaddr) | |
1537 | { | |
1538 | /* Only copy the second part of the breakpoint. */ | |
1539 | bp_size -= memaddr - bp_addr; | |
1540 | bptoffset = memaddr - bp_addr; | |
1541 | bp_addr = memaddr; | |
1542 | } | |
c5aa993b | 1543 | |
8defab1a DJ |
1544 | if (bp_addr + bp_size > memaddr + len) |
1545 | { | |
1546 | /* Only copy the first part of the breakpoint. */ | |
1547 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1548 | } | |
c5aa993b | 1549 | |
f0ba3972 PA |
1550 | if (readbuf != NULL) |
1551 | { | |
35c63cd8 JB |
1552 | /* Verify that the readbuf buffer does not overlap with |
1553 | the shadow_contents buffer. */ | |
1554 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1555 | || readbuf >= (bl->target_info.shadow_contents | |
1556 | + bl->target_info.shadow_len)); | |
1557 | ||
f0ba3972 PA |
1558 | /* Update the read buffer with this inserted breakpoint's |
1559 | shadow. */ | |
1560 | memcpy (readbuf + bp_addr - memaddr, | |
1561 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1562 | } | |
1563 | else | |
1564 | { | |
1565 | struct gdbarch *gdbarch = bl->gdbarch; | |
1566 | const unsigned char *bp; | |
1567 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
20ced3e4 | 1568 | int placed_size = bl->target_info.placed_size; |
f0ba3972 PA |
1569 | |
1570 | /* Update the shadow with what we want to write to memory. */ | |
1571 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1572 | writebuf_org + bp_addr - memaddr, bp_size); | |
1573 | ||
1574 | /* Determine appropriate breakpoint contents and size for this | |
1575 | address. */ | |
1576 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1577 | ||
1578 | /* Update the final write buffer with this inserted | |
1579 | breakpoint's INSN. */ | |
1580 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1581 | } | |
c5aa993b | 1582 | } |
c906108c | 1583 | } |
c906108c | 1584 | \f |
c5aa993b | 1585 | |
b775012e LM |
1586 | /* Return true if BPT is either a software breakpoint or a hardware |
1587 | breakpoint. */ | |
1588 | ||
1589 | int | |
1590 | is_breakpoint (const struct breakpoint *bpt) | |
1591 | { | |
1592 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1593 | || bpt->type == bp_hardware_breakpoint |
1594 | || bpt->type == bp_dprintf); | |
b775012e LM |
1595 | } |
1596 | ||
60e1c644 PA |
1597 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1598 | ||
a5606eee | 1599 | static int |
d77f58be | 1600 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1601 | { |
1602 | return (bpt->type == bp_hardware_watchpoint | |
1603 | || bpt->type == bp_read_watchpoint | |
1604 | || bpt->type == bp_access_watchpoint); | |
1605 | } | |
7270d8f2 | 1606 | |
60e1c644 PA |
1607 | /* Return true if BPT is of any watchpoint kind, hardware or |
1608 | software. */ | |
1609 | ||
3a5c3e22 | 1610 | int |
d77f58be | 1611 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1612 | { |
1613 | return (is_hardware_watchpoint (bpt) | |
1614 | || bpt->type == bp_watchpoint); | |
1615 | } | |
1616 | ||
3a5c3e22 PA |
1617 | /* Returns true if the current thread and its running state are safe |
1618 | to evaluate or update watchpoint B. Watchpoints on local | |
1619 | expressions need to be evaluated in the context of the thread that | |
1620 | was current when the watchpoint was created, and, that thread needs | |
1621 | to be stopped to be able to select the correct frame context. | |
1622 | Watchpoints on global expressions can be evaluated on any thread, | |
1623 | and in any state. It is presently left to the target allowing | |
1624 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1625 | |
1626 | static int | |
3a5c3e22 | 1627 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1628 | { |
d0d8b0c6 JK |
1629 | return (b->base.pspace == current_program_space |
1630 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1631 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1632 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1633 | } |
1634 | ||
d0fb5eae JK |
1635 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1636 | associated bp_watchpoint_scope breakpoint. */ | |
1637 | ||
1638 | static void | |
3a5c3e22 | 1639 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1640 | { |
3a5c3e22 | 1641 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1642 | |
1643 | if (b->related_breakpoint != b) | |
1644 | { | |
1645 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1646 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1647 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1648 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1649 | b->related_breakpoint = b; | |
1650 | } | |
1651 | b->disposition = disp_del_at_next_stop; | |
1652 | } | |
1653 | ||
567e1b4e JB |
1654 | /* Assuming that B is a watchpoint: |
1655 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1656 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1657 | - Evaluate the condition if there is one, and store the result |
1658 | in b->loc->cond. | |
a5606eee VP |
1659 | - Update the list of values that must be watched in B->loc. |
1660 | ||
4a64f543 MS |
1661 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1662 | nothing. If this is local watchpoint that is out of scope, delete | |
1663 | it. | |
1664 | ||
1665 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1666 | removed + inserted on each stop here. Normal breakpoints must | |
1667 | never be removed because they might be missed by a running thread | |
1668 | when debugging in non-stop mode. On the other hand, hardware | |
1669 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1670 | to each LWP since they are stored in each LWP's hardware debug | |
1671 | registers. Therefore, such LWP must be stopped first in order to | |
1672 | be able to modify its hardware watchpoints. | |
1673 | ||
1674 | Hardware watchpoints must be reset exactly once after being | |
1675 | presented to the user. It cannot be done sooner, because it would | |
1676 | reset the data used to present the watchpoint hit to the user. And | |
1677 | it must not be done later because it could display the same single | |
1678 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1679 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1680 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1681 | not user-visible - its hit is suppressed if the memory content has | |
1682 | not changed. | |
1683 | ||
1684 | The following constraints influence the location where we can reset | |
1685 | hardware watchpoints: | |
1686 | ||
1687 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1688 | called several times when GDB stops. | |
1689 | ||
1690 | [linux] | |
1691 | * Multiple hardware watchpoints can be hit at the same time, | |
1692 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1693 | hit at a time as the reason for stopping, and all the other hits | |
1694 | are presented later, one after the other, each time the user | |
1695 | requests the execution to be resumed. Execution is not resumed | |
1696 | for the threads still having pending hit event stored in | |
1697 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1698 | the inferior on the first stop the thread hit event is kept being | |
1699 | reported from its cached value by linux_nat_stopped_data_address | |
1700 | until the real thread resume happens after the watchpoint gets | |
1701 | presented and thus its LWP_INFO->STATUS gets reset. | |
1702 | ||
1703 | Therefore the hardware watchpoint hit can get safely reset on the | |
1704 | watchpoint removal from inferior. */ | |
a79d3c27 | 1705 | |
b40ce68a | 1706 | static void |
3a5c3e22 | 1707 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1708 | { |
a5606eee | 1709 | int within_current_scope; |
a5606eee | 1710 | struct frame_id saved_frame_id; |
66076460 | 1711 | int frame_saved; |
a5606eee | 1712 | |
f6bc2008 PA |
1713 | /* If this is a local watchpoint, we only want to check if the |
1714 | watchpoint frame is in scope if the current thread is the thread | |
1715 | that was used to create the watchpoint. */ | |
1716 | if (!watchpoint_in_thread_scope (b)) | |
1717 | return; | |
1718 | ||
3a5c3e22 | 1719 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1720 | return; |
1721 | ||
66076460 | 1722 | frame_saved = 0; |
a5606eee VP |
1723 | |
1724 | /* Determine if the watchpoint is within scope. */ | |
1725 | if (b->exp_valid_block == NULL) | |
1726 | within_current_scope = 1; | |
1727 | else | |
1728 | { | |
b5db5dfc UW |
1729 | struct frame_info *fi = get_current_frame (); |
1730 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1731 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1732 | ||
1733 | /* If we're in a function epilogue, unwinding may not work | |
1734 | properly, so do not attempt to recreate locations at this | |
1735 | point. See similar comments in watchpoint_check. */ | |
1736 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1737 | return; | |
66076460 DJ |
1738 | |
1739 | /* Save the current frame's ID so we can restore it after | |
1740 | evaluating the watchpoint expression on its own frame. */ | |
1741 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1742 | took a frame parameter, so that we didn't have to change the | |
1743 | selected frame. */ | |
1744 | frame_saved = 1; | |
1745 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1746 | ||
a5606eee VP |
1747 | fi = frame_find_by_id (b->watchpoint_frame); |
1748 | within_current_scope = (fi != NULL); | |
1749 | if (within_current_scope) | |
1750 | select_frame (fi); | |
1751 | } | |
1752 | ||
b5db5dfc UW |
1753 | /* We don't free locations. They are stored in the bp_location array |
1754 | and update_global_location_list will eventually delete them and | |
1755 | remove breakpoints if needed. */ | |
3a5c3e22 | 1756 | b->base.loc = NULL; |
b5db5dfc | 1757 | |
a5606eee VP |
1758 | if (within_current_scope && reparse) |
1759 | { | |
bbc13ae3 | 1760 | const char *s; |
d63d0675 | 1761 | |
a5606eee VP |
1762 | if (b->exp) |
1763 | { | |
1764 | xfree (b->exp); | |
1765 | b->exp = NULL; | |
1766 | } | |
d63d0675 | 1767 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1768 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1769 | /* If the meaning of expression itself changed, the old value is |
1770 | no longer relevant. We don't want to report a watchpoint hit | |
1771 | to the user when the old value and the new value may actually | |
1772 | be completely different objects. */ | |
1773 | value_free (b->val); | |
fa4727a6 DJ |
1774 | b->val = NULL; |
1775 | b->val_valid = 0; | |
60e1c644 PA |
1776 | |
1777 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1778 | expression is stored in the breakpoint object, not in the | |
1779 | locations (re)created below. */ | |
3a5c3e22 | 1780 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1781 | { |
1782 | if (b->cond_exp != NULL) | |
1783 | { | |
1784 | xfree (b->cond_exp); | |
1785 | b->cond_exp = NULL; | |
1786 | } | |
1787 | ||
3a5c3e22 | 1788 | s = b->base.cond_string; |
1bb9788d | 1789 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1790 | } |
a5606eee | 1791 | } |
a5606eee VP |
1792 | |
1793 | /* If we failed to parse the expression, for example because | |
1794 | it refers to a global variable in a not-yet-loaded shared library, | |
1795 | don't try to insert watchpoint. We don't automatically delete | |
1796 | such watchpoint, though, since failure to parse expression | |
1797 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1798 | if (!target_has_execution) |
2d134ed3 PA |
1799 | { |
1800 | /* Without execution, memory can't change. No use to try and | |
1801 | set watchpoint locations. The watchpoint will be reset when | |
1802 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1803 | if (!can_use_hw_watchpoints) |
1804 | { | |
1805 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1806 | b->base.type = bp_watchpoint; | |
1807 | else | |
638aa5a1 AB |
1808 | error (_("Can't set read/access watchpoint when " |
1809 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1810 | } |
2d134ed3 PA |
1811 | } |
1812 | else if (within_current_scope && b->exp) | |
a5606eee | 1813 | { |
0cf6dd15 | 1814 | int pc = 0; |
fa4727a6 | 1815 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1816 | struct program_space *frame_pspace; |
a5606eee | 1817 | |
3a1115a0 | 1818 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1819 | |
a5606eee VP |
1820 | /* Avoid setting b->val if it's already set. The meaning of |
1821 | b->val is 'the last value' user saw, and we should update | |
1822 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1823 | happens, the code that reports it updates b->val directly. |
1824 | We don't keep track of the memory value for masked | |
1825 | watchpoints. */ | |
3a5c3e22 | 1826 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1827 | { |
1828 | b->val = v; | |
1829 | b->val_valid = 1; | |
1830 | } | |
a5606eee | 1831 | |
2d134ed3 PA |
1832 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1833 | ||
a5606eee | 1834 | /* Look at each value on the value chain. */ |
9fa40276 | 1835 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1836 | { |
1837 | /* If it's a memory location, and GDB actually needed | |
1838 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1839 | must watch it. If the first value returned is |
1840 | still lazy, that means an error occurred reading it; | |
1841 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1842 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1843 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1844 | { |
1845 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1846 | |
a5606eee VP |
1847 | /* We only watch structs and arrays if user asked |
1848 | for it explicitly, never if they just happen to | |
1849 | appear in the middle of some value chain. */ | |
fa4727a6 | 1850 | if (v == result |
a5606eee VP |
1851 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1852 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1853 | { | |
1854 | CORE_ADDR addr; | |
744a8059 | 1855 | int type; |
a5606eee VP |
1856 | struct bp_location *loc, **tmp; |
1857 | ||
42ae5230 | 1858 | addr = value_address (v); |
a5606eee | 1859 | type = hw_write; |
3a5c3e22 | 1860 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1861 | type = hw_read; |
3a5c3e22 | 1862 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1863 | type = hw_access; |
3a5c3e22 PA |
1864 | |
1865 | loc = allocate_bp_location (&b->base); | |
1866 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1867 | ; |
1868 | *tmp = loc; | |
a6d9a66e | 1869 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1870 | |
1871 | loc->pspace = frame_pspace; | |
a5606eee | 1872 | loc->address = addr; |
744a8059 | 1873 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1874 | loc->watchpoint_type = type; |
1875 | } | |
1876 | } | |
9fa40276 TJB |
1877 | } |
1878 | ||
1879 | /* Change the type of breakpoint between hardware assisted or | |
1880 | an ordinary watchpoint depending on the hardware support | |
1881 | and free hardware slots. REPARSE is set when the inferior | |
1882 | is started. */ | |
a9634178 | 1883 | if (reparse) |
9fa40276 | 1884 | { |
e09342b5 | 1885 | int reg_cnt; |
9fa40276 TJB |
1886 | enum bp_loc_type loc_type; |
1887 | struct bp_location *bl; | |
a5606eee | 1888 | |
a9634178 | 1889 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1890 | |
1891 | if (reg_cnt) | |
9fa40276 TJB |
1892 | { |
1893 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1894 | enum bptype type; |
9fa40276 | 1895 | |
a9634178 TJB |
1896 | /* Use an exact watchpoint when there's only one memory region to be |
1897 | watched, and only one debug register is needed to watch it. */ | |
1898 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1899 | ||
9fa40276 | 1900 | /* We need to determine how many resources are already |
e09342b5 TJB |
1901 | used for all other hardware watchpoints plus this one |
1902 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1903 | this watchpoint in as well. */ |
1904 | ||
1905 | /* If this is a software watchpoint, we try to turn it | |
1906 | to a hardware one -- count resources as if B was of | |
1907 | hardware watchpoint type. */ | |
1908 | type = b->base.type; | |
1909 | if (type == bp_watchpoint) | |
1910 | type = bp_hardware_watchpoint; | |
1911 | ||
1912 | /* This watchpoint may or may not have been placed on | |
1913 | the list yet at this point (it won't be in the list | |
1914 | if we're trying to create it for the first time, | |
1915 | through watch_command), so always account for it | |
1916 | manually. */ | |
1917 | ||
1918 | /* Count resources used by all watchpoints except B. */ | |
1919 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1920 | ||
1921 | /* Add in the resources needed for B. */ | |
1922 | i += hw_watchpoint_use_count (&b->base); | |
1923 | ||
1924 | target_resources_ok | |
1925 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1926 | if (target_resources_ok <= 0) |
a9634178 | 1927 | { |
3a5c3e22 | 1928 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1929 | |
1930 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1931 | error (_("Target does not support this type of " |
1932 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1933 | else if (target_resources_ok < 0 && !sw_mode) |
1934 | error (_("There are not enough available hardware " | |
1935 | "resources for this watchpoint.")); | |
a1398e0c PA |
1936 | |
1937 | /* Downgrade to software watchpoint. */ | |
1938 | b->base.type = bp_watchpoint; | |
1939 | } | |
1940 | else | |
1941 | { | |
1942 | /* If this was a software watchpoint, we've just | |
1943 | found we have enough resources to turn it to a | |
1944 | hardware watchpoint. Otherwise, this is a | |
1945 | nop. */ | |
1946 | b->base.type = type; | |
a9634178 | 1947 | } |
9fa40276 | 1948 | } |
3a5c3e22 | 1949 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
1950 | { |
1951 | if (!can_use_hw_watchpoints) | |
1952 | error (_("Can't set read/access watchpoint when " | |
1953 | "hardware watchpoints are disabled.")); | |
1954 | else | |
1955 | error (_("Expression cannot be implemented with " | |
1956 | "read/access watchpoint.")); | |
1957 | } | |
9fa40276 | 1958 | else |
3a5c3e22 | 1959 | b->base.type = bp_watchpoint; |
9fa40276 | 1960 | |
3a5c3e22 | 1961 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1962 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1963 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1964 | bl->loc_type = loc_type; |
1965 | } | |
1966 | ||
1967 | for (v = val_chain; v; v = next) | |
1968 | { | |
a5606eee VP |
1969 | next = value_next (v); |
1970 | if (v != b->val) | |
1971 | value_free (v); | |
1972 | } | |
1973 | ||
c7437ca6 PA |
1974 | /* If a software watchpoint is not watching any memory, then the |
1975 | above left it without any location set up. But, | |
1976 | bpstat_stop_status requires a location to be able to report | |
1977 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1978 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1979 | { |
3a5c3e22 PA |
1980 | struct breakpoint *base = &b->base; |
1981 | base->loc = allocate_bp_location (base); | |
1982 | base->loc->pspace = frame_pspace; | |
1983 | base->loc->address = -1; | |
1984 | base->loc->length = -1; | |
1985 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1986 | } |
a5606eee VP |
1987 | } |
1988 | else if (!within_current_scope) | |
7270d8f2 | 1989 | { |
ac74f770 MS |
1990 | printf_filtered (_("\ |
1991 | Watchpoint %d deleted because the program has left the block\n\ | |
1992 | in which its expression is valid.\n"), | |
3a5c3e22 | 1993 | b->base.number); |
d0fb5eae | 1994 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1995 | } |
a5606eee VP |
1996 | |
1997 | /* Restore the selected frame. */ | |
66076460 DJ |
1998 | if (frame_saved) |
1999 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2000 | } |
2001 | ||
a5606eee | 2002 | |
74960c60 | 2003 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2004 | inserted in the inferior. We don't differentiate the type of BL's owner |
2005 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2006 | breakpoint_ops is not defined, because in insert_bp_location, | |
2007 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2008 | static int |
35df4500 | 2009 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2010 | { |
35df4500 | 2011 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2012 | return 0; |
2013 | ||
35df4500 | 2014 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2015 | return 0; |
2016 | ||
35df4500 | 2017 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2018 | return 0; |
2019 | ||
f8eba3c6 TT |
2020 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2021 | return 0; | |
2022 | ||
56710373 PA |
2023 | /* This is set for example, when we're attached to the parent of a |
2024 | vfork, and have detached from the child. The child is running | |
2025 | free, and we expect it to do an exec or exit, at which point the | |
2026 | OS makes the parent schedulable again (and the target reports | |
2027 | that the vfork is done). Until the child is done with the shared | |
2028 | memory region, do not insert breakpoints in the parent, otherwise | |
2029 | the child could still trip on the parent's breakpoints. Since | |
2030 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2031 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2032 | return 0; |
2033 | ||
74960c60 VP |
2034 | return 1; |
2035 | } | |
2036 | ||
934709f0 PW |
2037 | /* Same as should_be_inserted but does the check assuming |
2038 | that the location is not duplicated. */ | |
2039 | ||
2040 | static int | |
2041 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2042 | { | |
2043 | int result; | |
2044 | const int save_duplicate = bl->duplicate; | |
2045 | ||
2046 | bl->duplicate = 0; | |
2047 | result = should_be_inserted (bl); | |
2048 | bl->duplicate = save_duplicate; | |
2049 | return result; | |
2050 | } | |
2051 | ||
b775012e LM |
2052 | /* Parses a conditional described by an expression COND into an |
2053 | agent expression bytecode suitable for evaluation | |
2054 | by the bytecode interpreter. Return NULL if there was | |
2055 | any error during parsing. */ | |
2056 | ||
2057 | static struct agent_expr * | |
2058 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2059 | { | |
2060 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2061 | volatile struct gdb_exception ex; |
2062 | ||
2063 | if (!cond) | |
2064 | return NULL; | |
2065 | ||
2066 | /* We don't want to stop processing, so catch any errors | |
2067 | that may show up. */ | |
2068 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2069 | { | |
2070 | aexpr = gen_eval_for_expr (scope, cond); | |
2071 | } | |
2072 | ||
2073 | if (ex.reason < 0) | |
2074 | { | |
2075 | /* If we got here, it means the condition could not be parsed to a valid | |
2076 | bytecode expression and thus can't be evaluated on the target's side. | |
2077 | It's no use iterating through the conditions. */ | |
2078 | return NULL; | |
2079 | } | |
2080 | ||
2081 | /* We have a valid agent expression. */ | |
2082 | return aexpr; | |
2083 | } | |
2084 | ||
2085 | /* Based on location BL, create a list of breakpoint conditions to be | |
2086 | passed on to the target. If we have duplicated locations with different | |
2087 | conditions, we will add such conditions to the list. The idea is that the | |
2088 | target will evaluate the list of conditions and will only notify GDB when | |
2089 | one of them is true. */ | |
2090 | ||
2091 | static void | |
2092 | build_target_condition_list (struct bp_location *bl) | |
2093 | { | |
2094 | struct bp_location **locp = NULL, **loc2p; | |
2095 | int null_condition_or_parse_error = 0; | |
2096 | int modified = bl->needs_update; | |
2097 | struct bp_location *loc; | |
2098 | ||
8b4f3082 PA |
2099 | /* Release conditions left over from a previous insert. */ |
2100 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2101 | ||
b775012e LM |
2102 | /* This is only meaningful if the target is |
2103 | evaluating conditions and if the user has | |
2104 | opted for condition evaluation on the target's | |
2105 | side. */ | |
2106 | if (gdb_evaluates_breakpoint_condition_p () | |
2107 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2108 | return; | |
2109 | ||
2110 | /* Do a first pass to check for locations with no assigned | |
2111 | conditions or conditions that fail to parse to a valid agent expression | |
2112 | bytecode. If any of these happen, then it's no use to send conditions | |
2113 | to the target since this location will always trigger and generate a | |
2114 | response back to GDB. */ | |
2115 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2116 | { | |
2117 | loc = (*loc2p); | |
2118 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2119 | { | |
2120 | if (modified) | |
2121 | { | |
2122 | struct agent_expr *aexpr; | |
2123 | ||
2124 | /* Re-parse the conditions since something changed. In that | |
2125 | case we already freed the condition bytecodes (see | |
2126 | force_breakpoint_reinsertion). We just | |
2127 | need to parse the condition to bytecodes again. */ | |
2128 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2129 | loc->cond_bytecode = aexpr; | |
2130 | ||
2131 | /* Check if we managed to parse the conditional expression | |
2132 | correctly. If not, we will not send this condition | |
2133 | to the target. */ | |
2134 | if (aexpr) | |
2135 | continue; | |
2136 | } | |
2137 | ||
2138 | /* If we have a NULL bytecode expression, it means something | |
2139 | went wrong or we have a null condition expression. */ | |
2140 | if (!loc->cond_bytecode) | |
2141 | { | |
2142 | null_condition_or_parse_error = 1; | |
2143 | break; | |
2144 | } | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | /* If any of these happened, it means we will have to evaluate the conditions | |
2149 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2150 | for all the other duplicate locations, thus we free all of them here. | |
2151 | ||
2152 | This is so we have a finer control over which locations' conditions are | |
2153 | being evaluated by GDB or the remote stub. */ | |
2154 | if (null_condition_or_parse_error) | |
2155 | { | |
2156 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2157 | { | |
2158 | loc = (*loc2p); | |
2159 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2160 | { | |
2161 | /* Only go as far as the first NULL bytecode is | |
2162 | located. */ | |
2163 | if (!loc->cond_bytecode) | |
2164 | return; | |
2165 | ||
2166 | free_agent_expr (loc->cond_bytecode); | |
2167 | loc->cond_bytecode = NULL; | |
2168 | } | |
2169 | } | |
2170 | } | |
2171 | ||
2172 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2173 | for this location's address. */ | |
2174 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2175 | { | |
2176 | loc = (*loc2p); | |
2177 | if (loc->cond | |
2178 | && is_breakpoint (loc->owner) | |
2179 | && loc->pspace->num == bl->pspace->num | |
2180 | && loc->owner->enable_state == bp_enabled | |
2181 | && loc->enabled) | |
2182 | /* Add the condition to the vector. This will be used later to send the | |
2183 | conditions to the target. */ | |
2184 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2185 | loc->cond_bytecode); | |
2186 | } | |
2187 | ||
2188 | return; | |
2189 | } | |
2190 | ||
d3ce09f5 SS |
2191 | /* Parses a command described by string CMD into an agent expression |
2192 | bytecode suitable for evaluation by the bytecode interpreter. | |
2193 | Return NULL if there was any error during parsing. */ | |
2194 | ||
2195 | static struct agent_expr * | |
2196 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2197 | { | |
2198 | struct cleanup *old_cleanups = 0; | |
2199 | struct expression *expr, **argvec; | |
2200 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2201 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2202 | const char *cmdrest; |
2203 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2204 | struct format_piece *fpieces; |
2205 | int nargs; | |
2206 | struct gdbarch *gdbarch = get_current_arch (); | |
2207 | ||
2208 | if (!cmd) | |
2209 | return NULL; | |
2210 | ||
2211 | cmdrest = cmd; | |
2212 | ||
2213 | if (*cmdrest == ',') | |
2214 | ++cmdrest; | |
bbc13ae3 | 2215 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2216 | |
2217 | if (*cmdrest++ != '"') | |
2218 | error (_("No format string following the location")); | |
2219 | ||
2220 | format_start = cmdrest; | |
2221 | ||
2222 | fpieces = parse_format_string (&cmdrest); | |
2223 | ||
2224 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2225 | ||
2226 | format_end = cmdrest; | |
2227 | ||
2228 | if (*cmdrest++ != '"') | |
2229 | error (_("Bad format string, non-terminated '\"'.")); | |
2230 | ||
bbc13ae3 | 2231 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2232 | |
2233 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2234 | error (_("Invalid argument syntax")); | |
2235 | ||
2236 | if (*cmdrest == ',') | |
2237 | cmdrest++; | |
bbc13ae3 | 2238 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2239 | |
2240 | /* For each argument, make an expression. */ | |
2241 | ||
2242 | argvec = (struct expression **) alloca (strlen (cmd) | |
2243 | * sizeof (struct expression *)); | |
2244 | ||
2245 | nargs = 0; | |
2246 | while (*cmdrest != '\0') | |
2247 | { | |
bbc13ae3 | 2248 | const char *cmd1; |
d3ce09f5 SS |
2249 | |
2250 | cmd1 = cmdrest; | |
2251 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2252 | argvec[nargs++] = expr; | |
2253 | cmdrest = cmd1; | |
2254 | if (*cmdrest == ',') | |
2255 | ++cmdrest; | |
2256 | } | |
2257 | ||
2258 | /* We don't want to stop processing, so catch any errors | |
2259 | that may show up. */ | |
2260 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2261 | { | |
2262 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2263 | format_start, format_end - format_start, | |
2264 | fpieces, nargs, argvec); | |
2265 | } | |
2266 | ||
752eb8b4 TT |
2267 | do_cleanups (old_cleanups); |
2268 | ||
d3ce09f5 SS |
2269 | if (ex.reason < 0) |
2270 | { | |
2271 | /* If we got here, it means the command could not be parsed to a valid | |
2272 | bytecode expression and thus can't be evaluated on the target's side. | |
2273 | It's no use iterating through the other commands. */ | |
2274 | return NULL; | |
2275 | } | |
2276 | ||
d3ce09f5 SS |
2277 | /* We have a valid agent expression, return it. */ |
2278 | return aexpr; | |
2279 | } | |
2280 | ||
2281 | /* Based on location BL, create a list of breakpoint commands to be | |
2282 | passed on to the target. If we have duplicated locations with | |
2283 | different commands, we will add any such to the list. */ | |
2284 | ||
2285 | static void | |
2286 | build_target_command_list (struct bp_location *bl) | |
2287 | { | |
2288 | struct bp_location **locp = NULL, **loc2p; | |
2289 | int null_command_or_parse_error = 0; | |
2290 | int modified = bl->needs_update; | |
2291 | struct bp_location *loc; | |
2292 | ||
8b4f3082 PA |
2293 | /* Release commands left over from a previous insert. */ |
2294 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2295 | ||
d3ce09f5 SS |
2296 | /* For now, limit to agent-style dprintf breakpoints. */ |
2297 | if (bl->owner->type != bp_dprintf | |
2298 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2299 | return; | |
2300 | ||
2301 | if (!target_can_run_breakpoint_commands ()) | |
2302 | return; | |
2303 | ||
2304 | /* Do a first pass to check for locations with no assigned | |
2305 | conditions or conditions that fail to parse to a valid agent expression | |
2306 | bytecode. If any of these happen, then it's no use to send conditions | |
2307 | to the target since this location will always trigger and generate a | |
2308 | response back to GDB. */ | |
2309 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2310 | { | |
2311 | loc = (*loc2p); | |
2312 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2313 | { | |
2314 | if (modified) | |
2315 | { | |
2316 | struct agent_expr *aexpr; | |
2317 | ||
2318 | /* Re-parse the commands since something changed. In that | |
2319 | case we already freed the command bytecodes (see | |
2320 | force_breakpoint_reinsertion). We just | |
2321 | need to parse the command to bytecodes again. */ | |
2322 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2323 | loc->owner->extra_string); | |
2324 | loc->cmd_bytecode = aexpr; | |
2325 | ||
2326 | if (!aexpr) | |
2327 | continue; | |
2328 | } | |
2329 | ||
2330 | /* If we have a NULL bytecode expression, it means something | |
2331 | went wrong or we have a null command expression. */ | |
2332 | if (!loc->cmd_bytecode) | |
2333 | { | |
2334 | null_command_or_parse_error = 1; | |
2335 | break; | |
2336 | } | |
2337 | } | |
2338 | } | |
2339 | ||
2340 | /* If anything failed, then we're not doing target-side commands, | |
2341 | and so clean up. */ | |
2342 | if (null_command_or_parse_error) | |
2343 | { | |
2344 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2345 | { | |
2346 | loc = (*loc2p); | |
2347 | if (is_breakpoint (loc->owner) | |
2348 | && loc->pspace->num == bl->pspace->num) | |
2349 | { | |
2350 | /* Only go as far as the first NULL bytecode is | |
2351 | located. */ | |
40fb6c5e | 2352 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2353 | return; |
2354 | ||
40fb6c5e HZ |
2355 | free_agent_expr (loc->cmd_bytecode); |
2356 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2357 | } |
2358 | } | |
2359 | } | |
2360 | ||
2361 | /* No NULL commands or failed bytecode generation. Build a command list | |
2362 | for this location's address. */ | |
2363 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2364 | { | |
2365 | loc = (*loc2p); | |
2366 | if (loc->owner->extra_string | |
2367 | && is_breakpoint (loc->owner) | |
2368 | && loc->pspace->num == bl->pspace->num | |
2369 | && loc->owner->enable_state == bp_enabled | |
2370 | && loc->enabled) | |
2371 | /* Add the command to the vector. This will be used later | |
2372 | to send the commands to the target. */ | |
2373 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2374 | loc->cmd_bytecode); | |
2375 | } | |
2376 | ||
2377 | bl->target_info.persist = 0; | |
2378 | /* Maybe flag this location as persistent. */ | |
2379 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2380 | bl->target_info.persist = 1; | |
2381 | } | |
2382 | ||
35df4500 TJB |
2383 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2384 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2385 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2386 | Returns 0 for success, 1 if the bp_location type is not supported or |
2387 | -1 for failure. | |
879bfdc2 | 2388 | |
4a64f543 MS |
2389 | NOTE drow/2003-09-09: This routine could be broken down to an |
2390 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2391 | static int |
35df4500 | 2392 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2393 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2394 | int *disabled_breaks, |
dd61ec5c MW |
2395 | int *hw_breakpoint_error, |
2396 | int *hw_bp_error_explained_already) | |
879bfdc2 DJ |
2397 | { |
2398 | int val = 0; | |
b15e5c54 | 2399 | const char *hw_bp_err_string = NULL; |
dd61ec5c | 2400 | struct gdb_exception e; |
879bfdc2 | 2401 | |
b775012e | 2402 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2403 | return 0; |
2404 | ||
35c63cd8 JB |
2405 | /* Note we don't initialize bl->target_info, as that wipes out |
2406 | the breakpoint location's shadow_contents if the breakpoint | |
2407 | is still inserted at that location. This in turn breaks | |
2408 | target_read_memory which depends on these buffers when | |
2409 | a memory read is requested at the breakpoint location: | |
2410 | Once the target_info has been wiped, we fail to see that | |
2411 | we have a breakpoint inserted at that address and thus | |
2412 | read the breakpoint instead of returning the data saved in | |
2413 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2414 | bl->target_info.placed_address = bl->address; |
2415 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2416 | bl->target_info.length = bl->length; |
8181d85f | 2417 | |
b775012e LM |
2418 | /* When working with target-side conditions, we must pass all the conditions |
2419 | for the same breakpoint address down to the target since GDB will not | |
2420 | insert those locations. With a list of breakpoint conditions, the target | |
2421 | can decide when to stop and notify GDB. */ | |
2422 | ||
2423 | if (is_breakpoint (bl->owner)) | |
2424 | { | |
2425 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2426 | build_target_command_list (bl); |
2427 | /* Reset the modification marker. */ | |
b775012e LM |
2428 | bl->needs_update = 0; |
2429 | } | |
2430 | ||
35df4500 TJB |
2431 | if (bl->loc_type == bp_loc_software_breakpoint |
2432 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2433 | { |
35df4500 | 2434 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2435 | { |
2436 | /* If the explicitly specified breakpoint type | |
2437 | is not hardware breakpoint, check the memory map to see | |
2438 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2439 | |
765dc015 VP |
2440 | Two important cases are: |
2441 | - location type is not hardware breakpoint, memory | |
2442 | is readonly. We change the type of the location to | |
2443 | hardware breakpoint. | |
4a64f543 MS |
2444 | - location type is hardware breakpoint, memory is |
2445 | read-write. This means we've previously made the | |
2446 | location hardware one, but then the memory map changed, | |
2447 | so we undo. | |
765dc015 | 2448 | |
4a64f543 MS |
2449 | When breakpoints are removed, remove_breakpoints will use |
2450 | location types we've just set here, the only possible | |
2451 | problem is that memory map has changed during running | |
2452 | program, but it's not going to work anyway with current | |
2453 | gdb. */ | |
765dc015 | 2454 | struct mem_region *mr |
35df4500 | 2455 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2456 | |
2457 | if (mr) | |
2458 | { | |
2459 | if (automatic_hardware_breakpoints) | |
2460 | { | |
765dc015 VP |
2461 | enum bp_loc_type new_type; |
2462 | ||
2463 | if (mr->attrib.mode != MEM_RW) | |
2464 | new_type = bp_loc_hardware_breakpoint; | |
2465 | else | |
2466 | new_type = bp_loc_software_breakpoint; | |
2467 | ||
35df4500 | 2468 | if (new_type != bl->loc_type) |
765dc015 VP |
2469 | { |
2470 | static int said = 0; | |
cc59ec59 | 2471 | |
35df4500 | 2472 | bl->loc_type = new_type; |
765dc015 VP |
2473 | if (!said) |
2474 | { | |
3e43a32a MS |
2475 | fprintf_filtered (gdb_stdout, |
2476 | _("Note: automatically using " | |
2477 | "hardware breakpoints for " | |
2478 | "read-only addresses.\n")); | |
765dc015 VP |
2479 | said = 1; |
2480 | } | |
2481 | } | |
2482 | } | |
35df4500 | 2483 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2484 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2485 | warning (_("cannot set software breakpoint " |
2486 | "at readonly address %s"), | |
35df4500 | 2487 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2488 | } |
2489 | } | |
2490 | ||
879bfdc2 DJ |
2491 | /* First check to see if we have to handle an overlay. */ |
2492 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2493 | || bl->section == NULL |
2494 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2495 | { |
2496 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2497 | TRY_CATCH (e, RETURN_MASK_ALL) |
2498 | { | |
2499 | val = bl->owner->ops->insert_location (bl); | |
2500 | } | |
2501 | if (e.reason < 0) | |
2502 | { | |
2503 | val = 1; | |
b15e5c54 | 2504 | hw_bp_err_string = e.message; |
dd61ec5c | 2505 | } |
879bfdc2 DJ |
2506 | } |
2507 | else | |
2508 | { | |
4a64f543 | 2509 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2510 | Shall we set a breakpoint at the LMA? */ |
2511 | if (!overlay_events_enabled) | |
2512 | { | |
2513 | /* Yes -- overlay event support is not active, | |
2514 | so we must try to set a breakpoint at the LMA. | |
2515 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2516 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2517 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2518 | bl->owner->number); |
879bfdc2 DJ |
2519 | else |
2520 | { | |
35df4500 TJB |
2521 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2522 | bl->section); | |
879bfdc2 | 2523 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2524 | bl->overlay_target_info = bl->target_info; |
2525 | bl->overlay_target_info.placed_address = addr; | |
2526 | val = target_insert_breakpoint (bl->gdbarch, | |
2527 | &bl->overlay_target_info); | |
879bfdc2 | 2528 | if (val != 0) |
99361f52 | 2529 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2530 | "Overlay breakpoint %d " |
2531 | "failed: in ROM?\n", | |
35df4500 | 2532 | bl->owner->number); |
879bfdc2 DJ |
2533 | } |
2534 | } | |
2535 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2536 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2537 | { |
2538 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2539 | TRY_CATCH (e, RETURN_MASK_ALL) |
2540 | { | |
2541 | val = bl->owner->ops->insert_location (bl); | |
2542 | } | |
2543 | if (e.reason < 0) | |
2544 | { | |
2545 | val = 1; | |
b15e5c54 | 2546 | hw_bp_err_string = e.message; |
dd61ec5c | 2547 | } |
879bfdc2 DJ |
2548 | } |
2549 | else | |
2550 | { | |
2551 | /* No. This breakpoint will not be inserted. | |
2552 | No error, but do not mark the bp as 'inserted'. */ | |
2553 | return 0; | |
2554 | } | |
2555 | } | |
2556 | ||
2557 | if (val) | |
2558 | { | |
2559 | /* Can't set the breakpoint. */ | |
35df4500 | 2560 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 2561 | { |
4a64f543 | 2562 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 2563 | val = 0; |
35df4500 | 2564 | bl->shlib_disabled = 1; |
8d3788bd | 2565 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2566 | if (!*disabled_breaks) |
2567 | { | |
2568 | fprintf_unfiltered (tmp_error_stream, | |
2569 | "Cannot insert breakpoint %d.\n", | |
2570 | bl->owner->number); | |
2571 | fprintf_unfiltered (tmp_error_stream, | |
2572 | "Temporarily disabling shared " | |
2573 | "library breakpoints:\n"); | |
2574 | } | |
2575 | *disabled_breaks = 1; | |
879bfdc2 | 2576 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2577 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
2578 | } |
2579 | else | |
879bfdc2 | 2580 | { |
35df4500 | 2581 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2582 | { |
dd61ec5c MW |
2583 | *hw_breakpoint_error = 1; |
2584 | *hw_bp_error_explained_already = hw_bp_err_string != NULL; | |
2585 | fprintf_unfiltered (tmp_error_stream, | |
2586 | "Cannot insert hardware breakpoint %d%s", | |
2587 | bl->owner->number, hw_bp_err_string ? ":" : ".\n"); | |
2588 | if (hw_bp_err_string) | |
2589 | fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string); | |
879bfdc2 DJ |
2590 | } |
2591 | else | |
2592 | { | |
578d3588 PA |
2593 | char *message = memory_error_message (TARGET_XFER_E_IO, |
2594 | bl->gdbarch, bl->address); | |
2595 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2596 | ||
879bfdc2 | 2597 | fprintf_unfiltered (tmp_error_stream, |
578d3588 PA |
2598 | "Cannot insert breakpoint %d.\n" |
2599 | "%s\n", | |
2600 | bl->owner->number, message); | |
2601 | ||
2602 | do_cleanups (old_chain); | |
879bfdc2 DJ |
2603 | } |
2604 | ||
2605 | } | |
2606 | } | |
2607 | else | |
35df4500 | 2608 | bl->inserted = 1; |
879bfdc2 DJ |
2609 | |
2610 | return val; | |
2611 | } | |
2612 | ||
35df4500 | 2613 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2614 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2615 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2616 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2617 | { |
77b06cd7 TJB |
2618 | gdb_assert (bl->owner->ops != NULL |
2619 | && bl->owner->ops->insert_location != NULL); | |
2620 | ||
2621 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2622 | |
2623 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2624 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2625 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2626 | { |
2627 | struct bp_location *loc, **loc_temp; | |
2628 | ||
2629 | /* But don't try to insert it, if there's already another | |
2630 | hw_access location that would be considered a duplicate | |
2631 | of this one. */ | |
2632 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2633 | if (loc != bl |
85d721b8 | 2634 | && loc->watchpoint_type == hw_access |
35df4500 | 2635 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2636 | { |
35df4500 TJB |
2637 | bl->duplicate = 1; |
2638 | bl->inserted = 1; | |
2639 | bl->target_info = loc->target_info; | |
2640 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2641 | val = 0; |
2642 | break; | |
2643 | } | |
2644 | ||
2645 | if (val == 1) | |
2646 | { | |
77b06cd7 TJB |
2647 | bl->watchpoint_type = hw_access; |
2648 | val = bl->owner->ops->insert_location (bl); | |
2649 | ||
2650 | if (val) | |
2651 | /* Back to the original value. */ | |
2652 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2653 | } |
2654 | } | |
2655 | ||
35df4500 | 2656 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2657 | } |
2658 | ||
35df4500 | 2659 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2660 | { |
77b06cd7 TJB |
2661 | gdb_assert (bl->owner->ops != NULL |
2662 | && bl->owner->ops->insert_location != NULL); | |
2663 | ||
2664 | val = bl->owner->ops->insert_location (bl); | |
2665 | if (val) | |
2666 | { | |
2667 | bl->owner->enable_state = bp_disabled; | |
2668 | ||
2669 | if (val == 1) | |
2670 | warning (_("\ | |
2671 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2672 | of catchpoint."), bl->owner->number); | |
2673 | else | |
2674 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2675 | } | |
2676 | ||
2677 | bl->inserted = (val == 0); | |
1640b821 DJ |
2678 | |
2679 | /* We've already printed an error message if there was a problem | |
2680 | inserting this catchpoint, and we've disabled the catchpoint, | |
2681 | so just return success. */ | |
2682 | return 0; | |
879bfdc2 DJ |
2683 | } |
2684 | ||
2685 | return 0; | |
2686 | } | |
2687 | ||
6c95b8df PA |
2688 | /* This function is called when program space PSPACE is about to be |
2689 | deleted. It takes care of updating breakpoints to not reference | |
2690 | PSPACE anymore. */ | |
2691 | ||
2692 | void | |
2693 | breakpoint_program_space_exit (struct program_space *pspace) | |
2694 | { | |
2695 | struct breakpoint *b, *b_temp; | |
876fa593 | 2696 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2697 | |
2698 | /* Remove any breakpoint that was set through this program space. */ | |
2699 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2700 | { | |
2701 | if (b->pspace == pspace) | |
2702 | delete_breakpoint (b); | |
2703 | } | |
2704 | ||
2705 | /* Breakpoints set through other program spaces could have locations | |
2706 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2707 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2708 | { |
2709 | struct bp_location *tmp; | |
2710 | ||
2711 | if (loc->pspace == pspace) | |
2712 | { | |
2bdf28a0 | 2713 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2714 | if (loc->owner->loc == loc) |
2715 | loc->owner->loc = loc->next; | |
2716 | else | |
2717 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2718 | if (tmp->next == loc) | |
2719 | { | |
2720 | tmp->next = loc->next; | |
2721 | break; | |
2722 | } | |
2723 | } | |
2724 | } | |
2725 | ||
2726 | /* Now update the global location list to permanently delete the | |
2727 | removed locations above. */ | |
2728 | update_global_location_list (0); | |
2729 | } | |
2730 | ||
74960c60 VP |
2731 | /* Make sure all breakpoints are inserted in inferior. |
2732 | Throws exception on any error. | |
2733 | A breakpoint that is already inserted won't be inserted | |
2734 | again, so calling this function twice is safe. */ | |
2735 | void | |
2736 | insert_breakpoints (void) | |
2737 | { | |
2738 | struct breakpoint *bpt; | |
2739 | ||
2740 | ALL_BREAKPOINTS (bpt) | |
2741 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2742 | { |
2743 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2744 | ||
2745 | update_watchpoint (w, 0 /* don't reparse. */); | |
2746 | } | |
74960c60 | 2747 | |
b60e7edf | 2748 | update_global_location_list (1); |
74960c60 | 2749 | |
c35b1492 PA |
2750 | /* update_global_location_list does not insert breakpoints when |
2751 | always_inserted_mode is not enabled. Explicitly insert them | |
2752 | now. */ | |
2753 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2754 | insert_breakpoint_locations (); |
2755 | } | |
2756 | ||
20388dd6 YQ |
2757 | /* Invoke CALLBACK for each of bp_location. */ |
2758 | ||
2759 | void | |
2760 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2761 | { | |
2762 | struct bp_location *loc, **loc_tmp; | |
2763 | ||
2764 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2765 | { | |
2766 | callback (loc, NULL); | |
2767 | } | |
2768 | } | |
2769 | ||
b775012e LM |
2770 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2771 | target. It is the case with deleting and disabling of breakpoints when using | |
2772 | always-inserted mode. */ | |
2773 | ||
2774 | static void | |
2775 | update_inserted_breakpoint_locations (void) | |
2776 | { | |
2777 | struct bp_location *bl, **blp_tmp; | |
2778 | int error_flag = 0; | |
2779 | int val = 0; | |
2780 | int disabled_breaks = 0; | |
2781 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2782 | int hw_bp_details_reported = 0; |
b775012e LM |
2783 | |
2784 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2785 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2786 | ||
2787 | /* Explicitly mark the warning -- this will only be printed if | |
2788 | there was an error. */ | |
2789 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2790 | ||
2791 | save_current_space_and_thread (); | |
2792 | ||
2793 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2794 | { | |
2795 | /* We only want to update software breakpoints and hardware | |
2796 | breakpoints. */ | |
2797 | if (!is_breakpoint (bl->owner)) | |
2798 | continue; | |
2799 | ||
2800 | /* We only want to update locations that are already inserted | |
2801 | and need updating. This is to avoid unwanted insertion during | |
2802 | deletion of breakpoints. */ | |
2803 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2804 | continue; | |
2805 | ||
2806 | switch_to_program_space_and_thread (bl->pspace); | |
2807 | ||
2808 | /* For targets that support global breakpoints, there's no need | |
2809 | to select an inferior to insert breakpoint to. In fact, even | |
2810 | if we aren't attached to any process yet, we should still | |
2811 | insert breakpoints. */ | |
f5656ead | 2812 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2813 | && ptid_equal (inferior_ptid, null_ptid)) |
2814 | continue; | |
2815 | ||
2816 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2817 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2818 | if (val) |
2819 | error_flag = val; | |
2820 | } | |
2821 | ||
2822 | if (error_flag) | |
2823 | { | |
2824 | target_terminal_ours_for_output (); | |
2825 | error_stream (tmp_error_stream); | |
2826 | } | |
2827 | ||
2828 | do_cleanups (cleanups); | |
2829 | } | |
2830 | ||
c30eee59 | 2831 | /* Used when starting or continuing the program. */ |
c906108c | 2832 | |
74960c60 VP |
2833 | static void |
2834 | insert_breakpoint_locations (void) | |
c906108c | 2835 | { |
a5606eee | 2836 | struct breakpoint *bpt; |
35df4500 | 2837 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2838 | int error_flag = 0; |
c906108c | 2839 | int val = 0; |
3fbb6ffa | 2840 | int disabled_breaks = 0; |
81d0cc19 | 2841 | int hw_breakpoint_error = 0; |
dd61ec5c | 2842 | int hw_bp_error_explained_already = 0; |
c906108c | 2843 | |
81d0cc19 | 2844 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2845 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2846 | |
81d0cc19 GS |
2847 | /* Explicitly mark the warning -- this will only be printed if |
2848 | there was an error. */ | |
2849 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2850 | |
2851 | save_current_space_and_thread (); | |
2852 | ||
35df4500 | 2853 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2854 | { |
b775012e | 2855 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2856 | continue; |
2857 | ||
4a64f543 MS |
2858 | /* There is no point inserting thread-specific breakpoints if |
2859 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2860 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2861 | if (bl->owner->thread != -1 |
2862 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2863 | continue; |
2864 | ||
35df4500 | 2865 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2866 | |
2867 | /* For targets that support global breakpoints, there's no need | |
2868 | to select an inferior to insert breakpoint to. In fact, even | |
2869 | if we aren't attached to any process yet, we should still | |
2870 | insert breakpoints. */ | |
f5656ead | 2871 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2872 | && ptid_equal (inferior_ptid, null_ptid)) |
2873 | continue; | |
2874 | ||
3fbb6ffa | 2875 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2876 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2877 | if (val) |
eacd795a | 2878 | error_flag = val; |
879bfdc2 | 2879 | } |
c906108c | 2880 | |
4a64f543 MS |
2881 | /* If we failed to insert all locations of a watchpoint, remove |
2882 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2883 | ALL_BREAKPOINTS (bpt) |
2884 | { | |
2885 | int some_failed = 0; | |
2886 | struct bp_location *loc; | |
2887 | ||
2888 | if (!is_hardware_watchpoint (bpt)) | |
2889 | continue; | |
2890 | ||
d6b74ac4 | 2891 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2892 | continue; |
74960c60 VP |
2893 | |
2894 | if (bpt->disposition == disp_del_at_next_stop) | |
2895 | continue; | |
a5606eee VP |
2896 | |
2897 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2898 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2899 | { |
2900 | some_failed = 1; | |
2901 | break; | |
2902 | } | |
2903 | if (some_failed) | |
2904 | { | |
2905 | for (loc = bpt->loc; loc; loc = loc->next) | |
2906 | if (loc->inserted) | |
2907 | remove_breakpoint (loc, mark_uninserted); | |
2908 | ||
2909 | hw_breakpoint_error = 1; | |
2910 | fprintf_unfiltered (tmp_error_stream, | |
2911 | "Could not insert hardware watchpoint %d.\n", | |
2912 | bpt->number); | |
eacd795a | 2913 | error_flag = -1; |
a5606eee VP |
2914 | } |
2915 | } | |
2916 | ||
eacd795a | 2917 | if (error_flag) |
81d0cc19 GS |
2918 | { |
2919 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2920 | message about possibly exhausted resources. */ | |
dd61ec5c | 2921 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2922 | { |
c6510018 MS |
2923 | fprintf_unfiltered (tmp_error_stream, |
2924 | "Could not insert hardware breakpoints:\n\ | |
2925 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2926 | } |
81d0cc19 GS |
2927 | target_terminal_ours_for_output (); |
2928 | error_stream (tmp_error_stream); | |
2929 | } | |
f7545552 TT |
2930 | |
2931 | do_cleanups (cleanups); | |
c906108c SS |
2932 | } |
2933 | ||
c30eee59 TJB |
2934 | /* Used when the program stops. |
2935 | Returns zero if successful, or non-zero if there was a problem | |
2936 | removing a breakpoint location. */ | |
2937 | ||
c906108c | 2938 | int |
fba45db2 | 2939 | remove_breakpoints (void) |
c906108c | 2940 | { |
35df4500 | 2941 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2942 | int val = 0; |
c906108c | 2943 | |
35df4500 | 2944 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2945 | { |
1e4d1764 | 2946 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2947 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2948 | } |
3a1bae8e | 2949 | return val; |
c906108c SS |
2950 | } |
2951 | ||
49fa26b0 PA |
2952 | /* When a thread exits, remove breakpoints that are related to |
2953 | that thread. */ | |
2954 | ||
2955 | static void | |
2956 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
2957 | { | |
2958 | struct breakpoint *b, *b_tmp; | |
2959 | ||
2960 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
2961 | { | |
96181529 | 2962 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
2963 | { |
2964 | b->disposition = disp_del_at_next_stop; | |
2965 | ||
2966 | printf_filtered (_("\ | |
46ecd527 | 2967 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
2968 | b->number, tp->num); |
2969 | ||
2970 | /* Hide it from the user. */ | |
2971 | b->number = 0; | |
2972 | } | |
2973 | } | |
2974 | } | |
2975 | ||
6c95b8df PA |
2976 | /* Remove breakpoints of process PID. */ |
2977 | ||
2978 | int | |
2979 | remove_breakpoints_pid (int pid) | |
2980 | { | |
35df4500 | 2981 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2982 | int val; |
2983 | struct inferior *inf = find_inferior_pid (pid); | |
2984 | ||
35df4500 | 2985 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2986 | { |
35df4500 | 2987 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2988 | continue; |
2989 | ||
d3ce09f5 SS |
2990 | if (bl->owner->type == bp_dprintf) |
2991 | continue; | |
2992 | ||
35df4500 | 2993 | if (bl->inserted) |
6c95b8df | 2994 | { |
35df4500 | 2995 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2996 | if (val != 0) |
2997 | return val; | |
2998 | } | |
2999 | } | |
3000 | return 0; | |
3001 | } | |
3002 | ||
c906108c | 3003 | int |
fba45db2 | 3004 | reattach_breakpoints (int pid) |
c906108c | 3005 | { |
6c95b8df | 3006 | struct cleanup *old_chain; |
35df4500 | 3007 | struct bp_location *bl, **blp_tmp; |
c906108c | 3008 | int val; |
86b887df | 3009 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3010 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3011 | struct inferior *inf; |
3012 | struct thread_info *tp; | |
3013 | ||
3014 | tp = any_live_thread_of_process (pid); | |
3015 | if (tp == NULL) | |
3016 | return 1; | |
3017 | ||
3018 | inf = find_inferior_pid (pid); | |
3019 | old_chain = save_inferior_ptid (); | |
3020 | ||
3021 | inferior_ptid = tp->ptid; | |
a4954f26 | 3022 | |
86b887df | 3023 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3024 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3025 | |
35df4500 | 3026 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3027 | { |
35df4500 | 3028 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3029 | continue; |
3030 | ||
35df4500 | 3031 | if (bl->inserted) |
c5aa993b | 3032 | { |
35df4500 | 3033 | bl->inserted = 0; |
dd61ec5c | 3034 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3035 | if (val != 0) |
3036 | { | |
ce696e05 | 3037 | do_cleanups (old_chain); |
c5aa993b JM |
3038 | return val; |
3039 | } | |
3040 | } | |
3041 | } | |
ce696e05 | 3042 | do_cleanups (old_chain); |
c906108c SS |
3043 | return 0; |
3044 | } | |
3045 | ||
e58b0e63 PA |
3046 | static int internal_breakpoint_number = -1; |
3047 | ||
84f4c1fe PM |
3048 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3049 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3050 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3051 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3052 | breakpoint_count and that value incremented. Internal breakpoints |
3053 | do not set the internal var bpnum. */ | |
3054 | static void | |
3055 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3056 | { | |
3057 | if (internal) | |
3058 | b->number = internal_breakpoint_number--; | |
3059 | else | |
3060 | { | |
3061 | set_breakpoint_count (breakpoint_count + 1); | |
3062 | b->number = breakpoint_count; | |
3063 | } | |
3064 | } | |
3065 | ||
e62c965a | 3066 | static struct breakpoint * |
a6d9a66e | 3067 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3068 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3069 | const struct breakpoint_ops *ops) |
e62c965a | 3070 | { |
e62c965a PP |
3071 | struct symtab_and_line sal; |
3072 | struct breakpoint *b; | |
3073 | ||
4a64f543 | 3074 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3075 | |
3076 | sal.pc = address; | |
3077 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3078 | sal.pspace = current_program_space; |
e62c965a | 3079 | |
06edf0c0 | 3080 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3081 | b->number = internal_breakpoint_number--; |
3082 | b->disposition = disp_donttouch; | |
3083 | ||
3084 | return b; | |
3085 | } | |
3086 | ||
17450429 PP |
3087 | static const char *const longjmp_names[] = |
3088 | { | |
3089 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3090 | }; | |
3091 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3092 | ||
3093 | /* Per-objfile data private to breakpoint.c. */ | |
3094 | struct breakpoint_objfile_data | |
3095 | { | |
3096 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3097 | struct minimal_symbol *overlay_msym; | |
3098 | ||
3099 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3100 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
3101 | ||
28106bc2 SDJ |
3102 | /* True if we have looked for longjmp probes. */ |
3103 | int longjmp_searched; | |
3104 | ||
3105 | /* SystemTap probe points for longjmp (if any). */ | |
3106 | VEC (probe_p) *longjmp_probes; | |
3107 | ||
17450429 PP |
3108 | /* Minimal symbol for "std::terminate()" (if any). */ |
3109 | struct minimal_symbol *terminate_msym; | |
3110 | ||
3111 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3112 | struct minimal_symbol *exception_msym; | |
28106bc2 SDJ |
3113 | |
3114 | /* True if we have looked for exception probes. */ | |
3115 | int exception_searched; | |
3116 | ||
3117 | /* SystemTap probe points for unwinding (if any). */ | |
3118 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3119 | }; |
3120 | ||
3121 | static const struct objfile_data *breakpoint_objfile_key; | |
3122 | ||
3123 | /* Minimal symbol not found sentinel. */ | |
3124 | static struct minimal_symbol msym_not_found; | |
3125 | ||
3126 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3127 | ||
3128 | static int | |
3129 | msym_not_found_p (const struct minimal_symbol *msym) | |
3130 | { | |
3131 | return msym == &msym_not_found; | |
3132 | } | |
3133 | ||
3134 | /* Return per-objfile data needed by breakpoint.c. | |
3135 | Allocate the data if necessary. */ | |
3136 | ||
3137 | static struct breakpoint_objfile_data * | |
3138 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3139 | { | |
3140 | struct breakpoint_objfile_data *bp_objfile_data; | |
3141 | ||
3142 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3143 | if (bp_objfile_data == NULL) | |
3144 | { | |
3145 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3146 | sizeof (*bp_objfile_data)); | |
3147 | ||
3148 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3149 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3150 | } | |
3151 | return bp_objfile_data; | |
3152 | } | |
3153 | ||
28106bc2 SDJ |
3154 | static void |
3155 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3156 | { | |
3157 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3158 | ||
3159 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3160 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3161 | } | |
3162 | ||
e62c965a | 3163 | static void |
af02033e | 3164 | create_overlay_event_breakpoint (void) |
e62c965a | 3165 | { |
69de3c6a | 3166 | struct objfile *objfile; |
af02033e | 3167 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3168 | |
69de3c6a PP |
3169 | ALL_OBJFILES (objfile) |
3170 | { | |
3171 | struct breakpoint *b; | |
17450429 PP |
3172 | struct breakpoint_objfile_data *bp_objfile_data; |
3173 | CORE_ADDR addr; | |
69de3c6a | 3174 | |
17450429 PP |
3175 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3176 | ||
3177 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
3178 | continue; | |
3179 | ||
3180 | if (bp_objfile_data->overlay_msym == NULL) | |
3181 | { | |
3182 | struct minimal_symbol *m; | |
3183 | ||
3184 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3185 | if (m == NULL) | |
3186 | { | |
3187 | /* Avoid future lookups in this objfile. */ | |
3188 | bp_objfile_data->overlay_msym = &msym_not_found; | |
3189 | continue; | |
3190 | } | |
3191 | bp_objfile_data->overlay_msym = m; | |
3192 | } | |
e62c965a | 3193 | |
17450429 PP |
3194 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
3195 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3196 | bp_overlay_event, |
3197 | &internal_breakpoint_ops); | |
69de3c6a | 3198 | b->addr_string = xstrdup (func_name); |
e62c965a | 3199 | |
69de3c6a PP |
3200 | if (overlay_debugging == ovly_auto) |
3201 | { | |
3202 | b->enable_state = bp_enabled; | |
3203 | overlay_events_enabled = 1; | |
3204 | } | |
3205 | else | |
3206 | { | |
3207 | b->enable_state = bp_disabled; | |
3208 | overlay_events_enabled = 0; | |
3209 | } | |
e62c965a PP |
3210 | } |
3211 | update_global_location_list (1); | |
3212 | } | |
3213 | ||
0fd8e87f | 3214 | static void |
af02033e | 3215 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3216 | { |
6c95b8df | 3217 | struct program_space *pspace; |
6c95b8df PA |
3218 | struct cleanup *old_chain; |
3219 | ||
3220 | old_chain = save_current_program_space (); | |
0fd8e87f | 3221 | |
6c95b8df | 3222 | ALL_PSPACES (pspace) |
af02033e PP |
3223 | { |
3224 | struct objfile *objfile; | |
3225 | ||
3226 | set_current_program_space (pspace); | |
3227 | ||
3228 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3229 | { |
af02033e PP |
3230 | int i; |
3231 | struct gdbarch *gdbarch; | |
17450429 | 3232 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3233 | |
af02033e | 3234 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3235 | |
17450429 PP |
3236 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3237 | ||
28106bc2 SDJ |
3238 | if (!bp_objfile_data->longjmp_searched) |
3239 | { | |
25f9533e SDJ |
3240 | VEC (probe_p) *ret; |
3241 | ||
3242 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3243 | if (ret != NULL) | |
3244 | { | |
3245 | /* We are only interested in checking one element. */ | |
3246 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3247 | ||
3248 | if (!can_evaluate_probe_arguments (p)) | |
3249 | { | |
3250 | /* We cannot use the probe interface here, because it does | |
3251 | not know how to evaluate arguments. */ | |
3252 | VEC_free (probe_p, ret); | |
3253 | ret = NULL; | |
3254 | } | |
3255 | } | |
3256 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3257 | bp_objfile_data->longjmp_searched = 1; |
3258 | } | |
3259 | ||
3260 | if (bp_objfile_data->longjmp_probes != NULL) | |
3261 | { | |
3262 | int i; | |
3263 | struct probe *probe; | |
3264 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3265 | ||
3266 | for (i = 0; | |
3267 | VEC_iterate (probe_p, | |
3268 | bp_objfile_data->longjmp_probes, | |
3269 | i, probe); | |
3270 | ++i) | |
3271 | { | |
3272 | struct breakpoint *b; | |
3273 | ||
3274 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3275 | bp_longjmp_master, | |
3276 | &internal_breakpoint_ops); | |
3277 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3278 | b->enable_state = bp_disabled; | |
3279 | } | |
3280 | ||
3281 | continue; | |
3282 | } | |
3283 | ||
0569175e TSD |
3284 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3285 | continue; | |
3286 | ||
17450429 | 3287 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3288 | { |
3289 | struct breakpoint *b; | |
af02033e | 3290 | const char *func_name; |
17450429 | 3291 | CORE_ADDR addr; |
6c95b8df | 3292 | |
17450429 | 3293 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 3294 | continue; |
0fd8e87f | 3295 | |
17450429 PP |
3296 | func_name = longjmp_names[i]; |
3297 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
3298 | { | |
3299 | struct minimal_symbol *m; | |
3300 | ||
3301 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3302 | if (m == NULL) | |
3303 | { | |
3304 | /* Prevent future lookups in this objfile. */ | |
3305 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
3306 | continue; | |
3307 | } | |
3308 | bp_objfile_data->longjmp_msym[i] = m; | |
3309 | } | |
3310 | ||
3311 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
3312 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3313 | &internal_breakpoint_ops); | |
af02033e PP |
3314 | b->addr_string = xstrdup (func_name); |
3315 | b->enable_state = bp_disabled; | |
3316 | } | |
0fd8e87f | 3317 | } |
af02033e | 3318 | } |
0fd8e87f | 3319 | update_global_location_list (1); |
6c95b8df PA |
3320 | |
3321 | do_cleanups (old_chain); | |
0fd8e87f UW |
3322 | } |
3323 | ||
af02033e | 3324 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3325 | static void |
af02033e | 3326 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3327 | { |
3328 | struct program_space *pspace; | |
aa7d318d | 3329 | struct cleanup *old_chain; |
af02033e | 3330 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3331 | |
3332 | old_chain = save_current_program_space (); | |
3333 | ||
3334 | ALL_PSPACES (pspace) | |
17450429 PP |
3335 | { |
3336 | struct objfile *objfile; | |
3337 | CORE_ADDR addr; | |
3338 | ||
3339 | set_current_program_space (pspace); | |
3340 | ||
aa7d318d TT |
3341 | ALL_OBJFILES (objfile) |
3342 | { | |
3343 | struct breakpoint *b; | |
17450429 | 3344 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3345 | |
17450429 | 3346 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3347 | |
17450429 PP |
3348 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
3349 | continue; | |
3350 | ||
3351 | if (bp_objfile_data->terminate_msym == NULL) | |
3352 | { | |
3353 | struct minimal_symbol *m; | |
3354 | ||
3355 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3356 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
3357 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
3358 | { | |
3359 | /* Prevent future lookups in this objfile. */ | |
3360 | bp_objfile_data->terminate_msym = &msym_not_found; | |
3361 | continue; | |
3362 | } | |
3363 | bp_objfile_data->terminate_msym = m; | |
3364 | } | |
aa7d318d | 3365 | |
17450429 PP |
3366 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3367 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
3368 | bp_std_terminate_master, |
3369 | &internal_breakpoint_ops); | |
aa7d318d TT |
3370 | b->addr_string = xstrdup (func_name); |
3371 | b->enable_state = bp_disabled; | |
3372 | } | |
17450429 PP |
3373 | } |
3374 | ||
aa7d318d TT |
3375 | update_global_location_list (1); |
3376 | ||
3377 | do_cleanups (old_chain); | |
3378 | } | |
3379 | ||
186c406b TT |
3380 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3381 | ||
70221824 | 3382 | static void |
186c406b TT |
3383 | create_exception_master_breakpoint (void) |
3384 | { | |
3385 | struct objfile *objfile; | |
17450429 | 3386 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3387 | |
3388 | ALL_OBJFILES (objfile) | |
3389 | { | |
17450429 PP |
3390 | struct breakpoint *b; |
3391 | struct gdbarch *gdbarch; | |
3392 | struct breakpoint_objfile_data *bp_objfile_data; | |
3393 | CORE_ADDR addr; | |
3394 | ||
3395 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3396 | ||
28106bc2 SDJ |
3397 | /* We prefer the SystemTap probe point if it exists. */ |
3398 | if (!bp_objfile_data->exception_searched) | |
3399 | { | |
25f9533e SDJ |
3400 | VEC (probe_p) *ret; |
3401 | ||
3402 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3403 | ||
3404 | if (ret != NULL) | |
3405 | { | |
3406 | /* We are only interested in checking one element. */ | |
3407 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3408 | ||
3409 | if (!can_evaluate_probe_arguments (p)) | |
3410 | { | |
3411 | /* We cannot use the probe interface here, because it does | |
3412 | not know how to evaluate arguments. */ | |
3413 | VEC_free (probe_p, ret); | |
3414 | ret = NULL; | |
3415 | } | |
3416 | } | |
3417 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3418 | bp_objfile_data->exception_searched = 1; |
3419 | } | |
3420 | ||
3421 | if (bp_objfile_data->exception_probes != NULL) | |
3422 | { | |
3423 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3424 | int i; | |
3425 | struct probe *probe; | |
3426 | ||
3427 | for (i = 0; | |
3428 | VEC_iterate (probe_p, | |
3429 | bp_objfile_data->exception_probes, | |
3430 | i, probe); | |
3431 | ++i) | |
3432 | { | |
3433 | struct breakpoint *b; | |
3434 | ||
3435 | b = create_internal_breakpoint (gdbarch, probe->address, | |
3436 | bp_exception_master, | |
3437 | &internal_breakpoint_ops); | |
3438 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3439 | b->enable_state = bp_disabled; | |
3440 | } | |
3441 | ||
3442 | continue; | |
3443 | } | |
3444 | ||
3445 | /* Otherwise, try the hook function. */ | |
3446 | ||
17450429 PP |
3447 | if (msym_not_found_p (bp_objfile_data->exception_msym)) |
3448 | continue; | |
3449 | ||
3450 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3451 | |
17450429 | 3452 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 3453 | { |
17450429 | 3454 | struct minimal_symbol *debug_hook; |
186c406b | 3455 | |
17450429 PP |
3456 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3457 | if (debug_hook == NULL) | |
3458 | { | |
3459 | bp_objfile_data->exception_msym = &msym_not_found; | |
3460 | continue; | |
3461 | } | |
3462 | ||
3463 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3464 | } |
17450429 PP |
3465 | |
3466 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
3467 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
3468 | ¤t_target); | |
06edf0c0 PA |
3469 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3470 | &internal_breakpoint_ops); | |
17450429 PP |
3471 | b->addr_string = xstrdup (func_name); |
3472 | b->enable_state = bp_disabled; | |
186c406b TT |
3473 | } |
3474 | ||
3475 | update_global_location_list (1); | |
3476 | } | |
3477 | ||
c906108c | 3478 | void |
fba45db2 | 3479 | update_breakpoints_after_exec (void) |
c906108c | 3480 | { |
35df4500 | 3481 | struct breakpoint *b, *b_tmp; |
876fa593 | 3482 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3483 | |
25b22b0a PA |
3484 | /* We're about to delete breakpoints from GDB's lists. If the |
3485 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3486 | writing the breakpoints' "shadow contents" back into memory. The | |
3487 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3488 | do that. Instead, the target is responsible from marking | |
3489 | breakpoints out as soon as it detects an exec. We don't do that | |
3490 | here instead, because there may be other attempts to delete | |
3491 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3492 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3493 | if (bploc->pspace == current_program_space) |
3494 | gdb_assert (!bploc->inserted); | |
c906108c | 3495 | |
35df4500 | 3496 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3497 | { |
6c95b8df PA |
3498 | if (b->pspace != current_program_space) |
3499 | continue; | |
3500 | ||
4a64f543 | 3501 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3502 | if (b->type == bp_shlib_event) |
3503 | { | |
3504 | delete_breakpoint (b); | |
3505 | continue; | |
3506 | } | |
c906108c | 3507 | |
4a64f543 | 3508 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3509 | if (b->type == bp_jit_event) |
3510 | { | |
3511 | delete_breakpoint (b); | |
3512 | continue; | |
3513 | } | |
3514 | ||
1900040c | 3515 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3516 | as must overlay event and longjmp master breakpoints. */ |
3517 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3518 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3519 | || b->type == bp_exception_master) | |
c4093a6a JM |
3520 | { |
3521 | delete_breakpoint (b); | |
3522 | continue; | |
3523 | } | |
3524 | ||
4a64f543 | 3525 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3526 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3527 | { |
3528 | delete_breakpoint (b); | |
3529 | continue; | |
3530 | } | |
3531 | ||
611c83ae PA |
3532 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3533 | after an exec. */ | |
186c406b | 3534 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3535 | || b->type == bp_longjmp_call_dummy |
186c406b | 3536 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3537 | { |
3538 | delete_breakpoint (b); | |
3539 | continue; | |
3540 | } | |
3541 | ||
ce78b96d JB |
3542 | if (b->type == bp_catchpoint) |
3543 | { | |
3544 | /* For now, none of the bp_catchpoint breakpoints need to | |
3545 | do anything at this point. In the future, if some of | |
3546 | the catchpoints need to something, we will need to add | |
3547 | a new method, and call this method from here. */ | |
3548 | continue; | |
3549 | } | |
3550 | ||
c5aa993b JM |
3551 | /* bp_finish is a special case. The only way we ought to be able |
3552 | to see one of these when an exec() has happened, is if the user | |
3553 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3554 | carries them to the call-site of the current callee, by setting | |
3555 | a temporary bp there and resuming. But in this case, the finish | |
3556 | will carry them entirely through the vfork & exec. | |
3557 | ||
3558 | We don't want to allow a bp_finish to remain inserted now. But | |
3559 | we can't safely delete it, 'cause finish_command has a handle to | |
3560 | the bp on a bpstat, and will later want to delete it. There's a | |
3561 | chance (and I've seen it happen) that if we delete the bp_finish | |
3562 | here, that its storage will get reused by the time finish_command | |
3563 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3564 | We really must allow finish_command to delete a bp_finish. | |
3565 | ||
e5dd4106 | 3566 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3567 | it's safe to delete something others may have handles to?" |
3568 | problem, what we'll do here is just uninsert the bp_finish, and | |
3569 | let finish_command delete it. | |
3570 | ||
3571 | (We know the bp_finish is "doomed" in the sense that it's | |
3572 | momentary, and will be deleted as soon as finish_command sees | |
3573 | the inferior stopped. So it doesn't matter that the bp's | |
3574 | address is probably bogus in the new a.out, unlike e.g., the | |
3575 | solib breakpoints.) */ | |
c5aa993b | 3576 | |
c5aa993b JM |
3577 | if (b->type == bp_finish) |
3578 | { | |
3579 | continue; | |
3580 | } | |
3581 | ||
3582 | /* Without a symbolic address, we have little hope of the | |
3583 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3584 | a.out. */ |
c5aa993b JM |
3585 | if (b->addr_string == NULL) |
3586 | { | |
3587 | delete_breakpoint (b); | |
3588 | continue; | |
3589 | } | |
c5aa993b | 3590 | } |
1900040c | 3591 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3592 | create_overlay_event_breakpoint (); |
3593 | create_longjmp_master_breakpoint (); | |
3594 | create_std_terminate_master_breakpoint (); | |
186c406b | 3595 | create_exception_master_breakpoint (); |
c906108c SS |
3596 | } |
3597 | ||
3598 | int | |
d80ee84f | 3599 | detach_breakpoints (ptid_t ptid) |
c906108c | 3600 | { |
35df4500 | 3601 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3602 | int val = 0; |
ce696e05 | 3603 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3604 | struct inferior *inf = current_inferior (); |
c5aa993b | 3605 | |
dfd4cc63 | 3606 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3607 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3608 | |
6c95b8df | 3609 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3610 | inferior_ptid = ptid; |
35df4500 | 3611 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3612 | { |
35df4500 | 3613 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3614 | continue; |
3615 | ||
bd9673a4 PW |
3616 | /* This function must physically remove breakpoints locations |
3617 | from the specified ptid, without modifying the breakpoint | |
3618 | package's state. Locations of type bp_loc_other are only | |
3619 | maintained at GDB side. So, there is no need to remove | |
3620 | these bp_loc_other locations. Moreover, removing these | |
3621 | would modify the breakpoint package's state. */ | |
3622 | if (bl->loc_type == bp_loc_other) | |
3623 | continue; | |
3624 | ||
35df4500 TJB |
3625 | if (bl->inserted) |
3626 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3627 | } |
d03285ec UW |
3628 | |
3629 | /* Detach single-step breakpoints as well. */ | |
3630 | detach_single_step_breakpoints (); | |
3631 | ||
ce696e05 | 3632 | do_cleanups (old_chain); |
3a1bae8e | 3633 | return val; |
c906108c SS |
3634 | } |
3635 | ||
35df4500 | 3636 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3637 | Note that this is used to detach breakpoints from a child fork. |
3638 | When we get here, the child isn't in the inferior list, and neither | |
3639 | do we have objects to represent its address space --- we should | |
35df4500 | 3640 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3641 | |
c906108c | 3642 | static int |
35df4500 | 3643 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3644 | { |
3645 | int val; | |
c5aa993b | 3646 | |
35df4500 TJB |
3647 | /* BL is never in moribund_locations by our callers. */ |
3648 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3649 | |
35df4500 | 3650 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3651 | /* Permanent breakpoints cannot be inserted or removed. */ |
3652 | return 0; | |
3653 | ||
74960c60 VP |
3654 | /* The type of none suggests that owner is actually deleted. |
3655 | This should not ever happen. */ | |
35df4500 | 3656 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3657 | |
35df4500 TJB |
3658 | if (bl->loc_type == bp_loc_software_breakpoint |
3659 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3660 | { |
c02f5703 MS |
3661 | /* "Normal" instruction breakpoint: either the standard |
3662 | trap-instruction bp (bp_breakpoint), or a | |
3663 | bp_hardware_breakpoint. */ | |
3664 | ||
3665 | /* First check to see if we have to handle an overlay. */ | |
3666 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3667 | || bl->section == NULL |
3668 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3669 | { |
3670 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3671 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3672 | } |
c906108c SS |
3673 | else |
3674 | { | |
4a64f543 | 3675 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3676 | Did we set a breakpoint at the LMA? */ |
3677 | if (!overlay_events_enabled) | |
3678 | { | |
3679 | /* Yes -- overlay event support is not active, so we | |
3680 | should have set a breakpoint at the LMA. Remove it. | |
3681 | */ | |
c02f5703 MS |
3682 | /* Ignore any failures: if the LMA is in ROM, we will |
3683 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3684 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3685 | target_remove_hw_breakpoint (bl->gdbarch, | |
3686 | &bl->overlay_target_info); | |
c02f5703 | 3687 | else |
35df4500 TJB |
3688 | target_remove_breakpoint (bl->gdbarch, |
3689 | &bl->overlay_target_info); | |
c02f5703 MS |
3690 | } |
3691 | /* Did we set a breakpoint at the VMA? | |
3692 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3693 | if (bl->inserted) |
c906108c | 3694 | { |
c02f5703 MS |
3695 | /* Yes -- remove it. Previously we did not bother to |
3696 | remove the breakpoint if the section had been | |
3697 | unmapped, but let's not rely on that being safe. We | |
3698 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3699 | |
3700 | /* However, we should remove *software* breakpoints only | |
3701 | if the section is still mapped, or else we overwrite | |
3702 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3703 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3704 | || section_is_mapped (bl->section)) | |
3705 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3706 | else |
3707 | val = 0; | |
c906108c | 3708 | } |
c02f5703 MS |
3709 | else |
3710 | { | |
3711 | /* No -- not inserted, so no need to remove. No error. */ | |
3712 | val = 0; | |
3713 | } | |
c906108c | 3714 | } |
879d1e6b UW |
3715 | |
3716 | /* In some cases, we might not be able to remove a breakpoint | |
3717 | in a shared library that has already been removed, but we | |
3718 | have not yet processed the shlib unload event. */ | |
35df4500 | 3719 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3720 | val = 0; |
3721 | ||
c906108c SS |
3722 | if (val) |
3723 | return val; | |
35df4500 | 3724 | bl->inserted = (is == mark_inserted); |
c906108c | 3725 | } |
35df4500 | 3726 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3727 | { |
77b06cd7 TJB |
3728 | gdb_assert (bl->owner->ops != NULL |
3729 | && bl->owner->ops->remove_location != NULL); | |
3730 | ||
35df4500 | 3731 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3732 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3733 | |
c906108c | 3734 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3735 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3736 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3737 | bl->owner->number); |
c906108c | 3738 | } |
35df4500 TJB |
3739 | else if (bl->owner->type == bp_catchpoint |
3740 | && breakpoint_enabled (bl->owner) | |
3741 | && !bl->duplicate) | |
ce78b96d | 3742 | { |
77b06cd7 TJB |
3743 | gdb_assert (bl->owner->ops != NULL |
3744 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3745 | |
77b06cd7 | 3746 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3747 | if (val) |
3748 | return val; | |
77b06cd7 | 3749 | |
35df4500 | 3750 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3751 | } |
c906108c SS |
3752 | |
3753 | return 0; | |
3754 | } | |
3755 | ||
6c95b8df | 3756 | static int |
35df4500 | 3757 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3758 | { |
3759 | int ret; | |
3760 | struct cleanup *old_chain; | |
3761 | ||
35df4500 TJB |
3762 | /* BL is never in moribund_locations by our callers. */ |
3763 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3764 | |
35df4500 | 3765 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3766 | /* Permanent breakpoints cannot be inserted or removed. */ |
3767 | return 0; | |
3768 | ||
3769 | /* The type of none suggests that owner is actually deleted. | |
3770 | This should not ever happen. */ | |
35df4500 | 3771 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3772 | |
3773 | old_chain = save_current_space_and_thread (); | |
3774 | ||
35df4500 | 3775 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3776 | |
35df4500 | 3777 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3778 | |
3779 | do_cleanups (old_chain); | |
3780 | return ret; | |
3781 | } | |
3782 | ||
c906108c SS |
3783 | /* Clear the "inserted" flag in all breakpoints. */ |
3784 | ||
25b22b0a | 3785 | void |
fba45db2 | 3786 | mark_breakpoints_out (void) |
c906108c | 3787 | { |
35df4500 | 3788 | struct bp_location *bl, **blp_tmp; |
c906108c | 3789 | |
35df4500 TJB |
3790 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3791 | if (bl->pspace == current_program_space) | |
3792 | bl->inserted = 0; | |
c906108c SS |
3793 | } |
3794 | ||
53a5351d JM |
3795 | /* Clear the "inserted" flag in all breakpoints and delete any |
3796 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3797 | |
3798 | Plus other such housekeeping that has to be done for breakpoints | |
3799 | between runs. | |
3800 | ||
53a5351d JM |
3801 | Note: this function gets called at the end of a run (by |
3802 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3803 | init_wait_for_inferior). */ |
c906108c SS |
3804 | |
3805 | ||
3806 | ||
3807 | void | |
fba45db2 | 3808 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3809 | { |
35df4500 TJB |
3810 | struct breakpoint *b, *b_tmp; |
3811 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3812 | int ix; |
6c95b8df | 3813 | struct program_space *pspace = current_program_space; |
c906108c | 3814 | |
50c71eaf PA |
3815 | /* If breakpoint locations are shared across processes, then there's |
3816 | nothing to do. */ | |
f5656ead | 3817 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3818 | return; |
3819 | ||
35df4500 | 3820 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3821 | { |
35df4500 TJB |
3822 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3823 | if (bl->pspace == pspace | |
3824 | && bl->owner->enable_state != bp_permanent) | |
3825 | bl->inserted = 0; | |
6c95b8df | 3826 | } |
075f6582 | 3827 | |
35df4500 | 3828 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3829 | { |
6c95b8df PA |
3830 | if (b->loc && b->loc->pspace != pspace) |
3831 | continue; | |
3832 | ||
c5aa993b JM |
3833 | switch (b->type) |
3834 | { | |
3835 | case bp_call_dummy: | |
e2e4d78b | 3836 | case bp_longjmp_call_dummy: |
c906108c | 3837 | |
c5aa993b | 3838 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3839 | cause problems when the inferior is rerun, so we better get |
3840 | rid of it. */ | |
3841 | ||
3842 | case bp_watchpoint_scope: | |
3843 | ||
3844 | /* Also get rid of scope breakpoints. */ | |
3845 | ||
3846 | case bp_shlib_event: | |
3847 | ||
3848 | /* Also remove solib event breakpoints. Their addresses may | |
3849 | have changed since the last time we ran the program. | |
3850 | Actually we may now be debugging against different target; | |
3851 | and so the solib backend that installed this breakpoint may | |
3852 | not be used in by the target. E.g., | |
3853 | ||
3854 | (gdb) file prog-linux | |
3855 | (gdb) run # native linux target | |
3856 | ... | |
3857 | (gdb) kill | |
3858 | (gdb) file prog-win.exe | |
3859 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3860 | */ | |
c906108c | 3861 | |
f59f708a PA |
3862 | case bp_step_resume: |
3863 | ||
3864 | /* Also remove step-resume breakpoints. */ | |
3865 | ||
c5aa993b JM |
3866 | delete_breakpoint (b); |
3867 | break; | |
c906108c | 3868 | |
c5aa993b JM |
3869 | case bp_watchpoint: |
3870 | case bp_hardware_watchpoint: | |
3871 | case bp_read_watchpoint: | |
3872 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3873 | { |
3874 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3875 | |
3a5c3e22 PA |
3876 | /* Likewise for watchpoints on local expressions. */ |
3877 | if (w->exp_valid_block != NULL) | |
3878 | delete_breakpoint (b); | |
3879 | else if (context == inf_starting) | |
3880 | { | |
3881 | /* Reset val field to force reread of starting value in | |
3882 | insert_breakpoints. */ | |
3883 | if (w->val) | |
3884 | value_free (w->val); | |
3885 | w->val = NULL; | |
3886 | w->val_valid = 0; | |
c860120c | 3887 | } |
3a5c3e22 | 3888 | } |
c5aa993b JM |
3889 | break; |
3890 | default: | |
c5aa993b JM |
3891 | break; |
3892 | } | |
3893 | } | |
1c5cfe86 PA |
3894 | |
3895 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3896 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3897 | decref_bp_location (&bl); | |
1c5cfe86 | 3898 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3899 | } |
3900 | ||
6c95b8df PA |
3901 | /* These functions concern about actual breakpoints inserted in the |
3902 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3903 | we need to hop over the bkpt --- so we check for address space | |
3904 | match, not program space. */ | |
3905 | ||
c2c6d25f JM |
3906 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3907 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3908 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3909 | permanent breakpoint. | |
3910 | - When continuing from a location with an ordinary breakpoint, we | |
3911 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3912 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3913 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3914 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3915 | |
c2c6d25f | 3916 | enum breakpoint_here |
6c95b8df | 3917 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3918 | { |
35df4500 | 3919 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3920 | int any_breakpoint_here = 0; |
c906108c | 3921 | |
35df4500 | 3922 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3923 | { |
35df4500 TJB |
3924 | if (bl->loc_type != bp_loc_software_breakpoint |
3925 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3926 | continue; |
3927 | ||
f1310107 | 3928 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3929 | if ((breakpoint_enabled (bl->owner) |
3930 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3931 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3932 | { |
3933 | if (overlay_debugging | |
35df4500 TJB |
3934 | && section_is_overlay (bl->section) |
3935 | && !section_is_mapped (bl->section)) | |
075f6582 | 3936 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3937 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3938 | return permanent_breakpoint_here; |
3939 | else | |
3940 | any_breakpoint_here = 1; | |
3941 | } | |
3942 | } | |
c906108c | 3943 | |
c2c6d25f | 3944 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
3945 | } |
3946 | ||
1c5cfe86 PA |
3947 | /* Return true if there's a moribund breakpoint at PC. */ |
3948 | ||
3949 | int | |
6c95b8df | 3950 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
3951 | { |
3952 | struct bp_location *loc; | |
3953 | int ix; | |
3954 | ||
3955 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 3956 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3957 | return 1; |
3958 | ||
3959 | return 0; | |
3960 | } | |
c2c6d25f | 3961 | |
c36b740a | 3962 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
3963 | inserted using regular breakpoint_chain / bp_location array |
3964 | mechanism. This does not check for single-step breakpoints, which | |
3965 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
3966 | |
3967 | int | |
4a64f543 MS |
3968 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
3969 | CORE_ADDR pc) | |
c906108c | 3970 | { |
35df4500 | 3971 | struct bp_location *bl, **blp_tmp; |
c906108c | 3972 | |
35df4500 | 3973 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3974 | { |
35df4500 TJB |
3975 | if (bl->loc_type != bp_loc_software_breakpoint |
3976 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3977 | continue; |
3978 | ||
35df4500 | 3979 | if (bl->inserted |
f1310107 | 3980 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3981 | { |
3982 | if (overlay_debugging | |
35df4500 TJB |
3983 | && section_is_overlay (bl->section) |
3984 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
3985 | continue; /* unmapped overlay -- can't be a match */ |
3986 | else | |
3987 | return 1; | |
3988 | } | |
c5aa993b | 3989 | } |
c36b740a VP |
3990 | return 0; |
3991 | } | |
3992 | ||
3993 | /* Returns non-zero iff there's either regular breakpoint | |
3994 | or a single step breakpoint inserted at PC. */ | |
3995 | ||
3996 | int | |
6c95b8df | 3997 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 3998 | { |
6c95b8df | 3999 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4000 | return 1; |
c906108c | 4001 | |
6c95b8df | 4002 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4003 | return 1; |
4004 | ||
c906108c SS |
4005 | return 0; |
4006 | } | |
4007 | ||
4fa8626c DJ |
4008 | /* This function returns non-zero iff there is a software breakpoint |
4009 | inserted at PC. */ | |
4010 | ||
4011 | int | |
3e43a32a MS |
4012 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4013 | CORE_ADDR pc) | |
4fa8626c | 4014 | { |
35df4500 | 4015 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4016 | |
35df4500 | 4017 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4018 | { |
35df4500 | 4019 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4020 | continue; |
4021 | ||
35df4500 TJB |
4022 | if (bl->inserted |
4023 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4024 | aspace, pc)) |
4fa8626c DJ |
4025 | { |
4026 | if (overlay_debugging | |
35df4500 TJB |
4027 | && section_is_overlay (bl->section) |
4028 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4029 | continue; /* unmapped overlay -- can't be a match */ |
4030 | else | |
4031 | return 1; | |
4032 | } | |
4033 | } | |
4034 | ||
1aafd4da | 4035 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4036 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4037 | return 1; |
4038 | ||
4fa8626c DJ |
4039 | return 0; |
4040 | } | |
4041 | ||
9093389c PA |
4042 | int |
4043 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4044 | CORE_ADDR addr, ULONGEST len) | |
4045 | { | |
4046 | struct breakpoint *bpt; | |
4047 | ||
4048 | ALL_BREAKPOINTS (bpt) | |
4049 | { | |
4050 | struct bp_location *loc; | |
4051 | ||
4052 | if (bpt->type != bp_hardware_watchpoint | |
4053 | && bpt->type != bp_access_watchpoint) | |
4054 | continue; | |
4055 | ||
4056 | if (!breakpoint_enabled (bpt)) | |
4057 | continue; | |
4058 | ||
4059 | for (loc = bpt->loc; loc; loc = loc->next) | |
4060 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4061 | { | |
4062 | CORE_ADDR l, h; | |
4063 | ||
4064 | /* Check for intersection. */ | |
4065 | l = max (loc->address, addr); | |
4066 | h = min (loc->address + loc->length, addr + len); | |
4067 | if (l < h) | |
4068 | return 1; | |
4069 | } | |
4070 | } | |
4071 | return 0; | |
4072 | } | |
4073 | ||
075f6582 DJ |
4074 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4075 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4076 | |
4077 | int | |
6c95b8df PA |
4078 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4079 | ptid_t ptid) | |
c906108c | 4080 | { |
35df4500 | 4081 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4082 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4083 | int thread = -1; |
4a306c9a | 4084 | int task = 0; |
a6f1cd96 | 4085 | |
35df4500 | 4086 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4087 | { |
35df4500 TJB |
4088 | if (bl->loc_type != bp_loc_software_breakpoint |
4089 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4090 | continue; |
4091 | ||
35df4500 TJB |
4092 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4093 | if (!breakpoint_enabled (bl->owner) | |
4094 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4095 | continue; |
4096 | ||
f1310107 | 4097 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4098 | continue; |
4099 | ||
35df4500 | 4100 | if (bl->owner->thread != -1) |
075f6582 | 4101 | { |
a6f1cd96 JB |
4102 | /* This is a thread-specific breakpoint. Check that ptid |
4103 | matches that thread. If thread hasn't been computed yet, | |
4104 | it is now time to do so. */ | |
4105 | if (thread == -1) | |
4106 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4107 | if (bl->owner->thread != thread) |
a6f1cd96 | 4108 | continue; |
075f6582 | 4109 | } |
a6f1cd96 | 4110 | |
35df4500 | 4111 | if (bl->owner->task != 0) |
4a306c9a JB |
4112 | { |
4113 | /* This is a task-specific breakpoint. Check that ptid | |
4114 | matches that task. If task hasn't been computed yet, | |
4115 | it is now time to do so. */ | |
4116 | if (task == 0) | |
4117 | task = ada_get_task_number (ptid); | |
35df4500 | 4118 | if (bl->owner->task != task) |
4a306c9a JB |
4119 | continue; |
4120 | } | |
4121 | ||
a6f1cd96 | 4122 | if (overlay_debugging |
35df4500 TJB |
4123 | && section_is_overlay (bl->section) |
4124 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4125 | continue; /* unmapped overlay -- can't be a match */ |
4126 | ||
4127 | return 1; | |
c5aa993b | 4128 | } |
c906108c SS |
4129 | |
4130 | return 0; | |
4131 | } | |
c906108c | 4132 | \f |
c5aa993b | 4133 | |
c906108c SS |
4134 | /* bpstat stuff. External routines' interfaces are documented |
4135 | in breakpoint.h. */ | |
4136 | ||
4137 | int | |
c326b90e | 4138 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4139 | { |
533be4dd | 4140 | return (ep->type == bp_catchpoint); |
c906108c SS |
4141 | } |
4142 | ||
f431efe5 PA |
4143 | /* Frees any storage that is part of a bpstat. Does not walk the |
4144 | 'next' chain. */ | |
4145 | ||
4146 | static void | |
198757a8 VP |
4147 | bpstat_free (bpstat bs) |
4148 | { | |
4149 | if (bs->old_val != NULL) | |
4150 | value_free (bs->old_val); | |
9add0f1b | 4151 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4152 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4153 | xfree (bs); |
4154 | } | |
4155 | ||
c906108c SS |
4156 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4157 | Also free any storage that is part of a bpstat. */ | |
4158 | ||
4159 | void | |
fba45db2 | 4160 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4161 | { |
4162 | bpstat p; | |
4163 | bpstat q; | |
4164 | ||
4165 | if (bsp == 0) | |
4166 | return; | |
4167 | p = *bsp; | |
4168 | while (p != NULL) | |
4169 | { | |
4170 | q = p->next; | |
198757a8 | 4171 | bpstat_free (p); |
c906108c SS |
4172 | p = q; |
4173 | } | |
4174 | *bsp = NULL; | |
4175 | } | |
4176 | ||
4177 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4178 | is part of the bpstat is copied as well. */ | |
4179 | ||
4180 | bpstat | |
fba45db2 | 4181 | bpstat_copy (bpstat bs) |
c906108c SS |
4182 | { |
4183 | bpstat p = NULL; | |
4184 | bpstat tmp; | |
4185 | bpstat retval = NULL; | |
4186 | ||
4187 | if (bs == NULL) | |
4188 | return bs; | |
4189 | ||
4190 | for (; bs != NULL; bs = bs->next) | |
4191 | { | |
4192 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4193 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4194 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4195 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4196 | if (bs->old_val != NULL) |
3c3185ac JK |
4197 | { |
4198 | tmp->old_val = value_copy (bs->old_val); | |
4199 | release_value (tmp->old_val); | |
4200 | } | |
31cc81e9 | 4201 | |
c906108c SS |
4202 | if (p == NULL) |
4203 | /* This is the first thing in the chain. */ | |
4204 | retval = tmp; | |
4205 | else | |
4206 | p->next = tmp; | |
4207 | p = tmp; | |
4208 | } | |
4209 | p->next = NULL; | |
4210 | return retval; | |
4211 | } | |
4212 | ||
4a64f543 | 4213 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4214 | |
4215 | bpstat | |
fba45db2 | 4216 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4217 | { |
c5aa993b JM |
4218 | if (bsp == NULL) |
4219 | return NULL; | |
c906108c | 4220 | |
c5aa993b JM |
4221 | for (; bsp != NULL; bsp = bsp->next) |
4222 | { | |
f431efe5 | 4223 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4224 | return bsp; |
4225 | } | |
c906108c SS |
4226 | return NULL; |
4227 | } | |
4228 | ||
ab04a2af TT |
4229 | /* See breakpoint.h. */ |
4230 | ||
47591c29 | 4231 | int |
427cd150 | 4232 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4233 | { |
ab04a2af TT |
4234 | for (; bsp != NULL; bsp = bsp->next) |
4235 | { | |
427cd150 TT |
4236 | if (bsp->breakpoint_at == NULL) |
4237 | { | |
4238 | /* A moribund location can never explain a signal other than | |
4239 | GDB_SIGNAL_TRAP. */ | |
4240 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4241 | return 1; |
427cd150 TT |
4242 | } |
4243 | else | |
47591c29 PA |
4244 | { |
4245 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4246 | sig)) | |
4247 | return 1; | |
4248 | } | |
ab04a2af TT |
4249 | } |
4250 | ||
47591c29 | 4251 | return 0; |
ab04a2af TT |
4252 | } |
4253 | ||
4a64f543 MS |
4254 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4255 | stopped at. *BSP upon return is a bpstat which points to the | |
4256 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4257 | good for anything but further calls to bpstat_num). | |
4258 | ||
8671a17b PA |
4259 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4260 | Return -1 if stopped at a breakpoint that has been deleted since | |
4261 | we set it. | |
4262 | Return 1 otherwise. */ | |
c906108c SS |
4263 | |
4264 | int | |
8671a17b | 4265 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4266 | { |
4267 | struct breakpoint *b; | |
4268 | ||
4269 | if ((*bsp) == NULL) | |
4270 | return 0; /* No more breakpoint values */ | |
8671a17b | 4271 | |
4a64f543 MS |
4272 | /* We assume we'll never have several bpstats that correspond to a |
4273 | single breakpoint -- otherwise, this function might return the | |
4274 | same number more than once and this will look ugly. */ | |
f431efe5 | 4275 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4276 | *bsp = (*bsp)->next; |
4277 | if (b == NULL) | |
4278 | return -1; /* breakpoint that's been deleted since */ | |
4279 | ||
4280 | *num = b->number; /* We have its number */ | |
4281 | return 1; | |
c906108c SS |
4282 | } |
4283 | ||
e93ca019 | 4284 | /* See breakpoint.h. */ |
c906108c SS |
4285 | |
4286 | void | |
e93ca019 | 4287 | bpstat_clear_actions (void) |
c906108c | 4288 | { |
e93ca019 JK |
4289 | struct thread_info *tp; |
4290 | bpstat bs; | |
4291 | ||
4292 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4293 | return; | |
4294 | ||
4295 | tp = find_thread_ptid (inferior_ptid); | |
4296 | if (tp == NULL) | |
4297 | return; | |
4298 | ||
4299 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4300 | { |
9add0f1b | 4301 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4302 | |
c906108c SS |
4303 | if (bs->old_val != NULL) |
4304 | { | |
4305 | value_free (bs->old_val); | |
4306 | bs->old_val = NULL; | |
4307 | } | |
4308 | } | |
4309 | } | |
4310 | ||
f3b1572e PA |
4311 | /* Called when a command is about to proceed the inferior. */ |
4312 | ||
4313 | static void | |
4314 | breakpoint_about_to_proceed (void) | |
4315 | { | |
4316 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4317 | { | |
4318 | struct thread_info *tp = inferior_thread (); | |
4319 | ||
4320 | /* Allow inferior function calls in breakpoint commands to not | |
4321 | interrupt the command list. When the call finishes | |
4322 | successfully, the inferior will be standing at the same | |
4323 | breakpoint as if nothing happened. */ | |
16c381f0 | 4324 | if (tp->control.in_infcall) |
f3b1572e PA |
4325 | return; |
4326 | } | |
4327 | ||
4328 | breakpoint_proceeded = 1; | |
4329 | } | |
4330 | ||
4a64f543 MS |
4331 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4332 | command. */ | |
c906108c | 4333 | static void |
4efb68b1 | 4334 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4335 | { |
4336 | executing_breakpoint_commands = 0; | |
4337 | } | |
4338 | ||
abf85f46 JK |
4339 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4340 | or its equivalent. */ | |
4341 | ||
4342 | static int | |
4343 | command_line_is_silent (struct command_line *cmd) | |
4344 | { | |
4345 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4346 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4347 | } | |
4348 | ||
4a64f543 MS |
4349 | /* Execute all the commands associated with all the breakpoints at |
4350 | this location. Any of these commands could cause the process to | |
4351 | proceed beyond this point, etc. We look out for such changes by | |
4352 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4353 | |
347bddb7 PA |
4354 | Returns true if a breakpoint command resumed the inferior. In that |
4355 | case, it is the caller's responsibility to recall it again with the | |
4356 | bpstat of the current thread. */ | |
4357 | ||
4358 | static int | |
4359 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4360 | { |
4361 | bpstat bs; | |
4362 | struct cleanup *old_chain; | |
347bddb7 | 4363 | int again = 0; |
c906108c SS |
4364 | |
4365 | /* Avoid endless recursion if a `source' command is contained | |
4366 | in bs->commands. */ | |
4367 | if (executing_breakpoint_commands) | |
347bddb7 | 4368 | return 0; |
c906108c SS |
4369 | |
4370 | executing_breakpoint_commands = 1; | |
4371 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4372 | ||
cf6c5ffb TT |
4373 | prevent_dont_repeat (); |
4374 | ||
4a64f543 | 4375 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4376 | bs = *bsp; |
4377 | ||
4378 | breakpoint_proceeded = 0; | |
4379 | for (; bs != NULL; bs = bs->next) | |
4380 | { | |
9add0f1b | 4381 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4382 | struct command_line *cmd; |
4383 | struct cleanup *this_cmd_tree_chain; | |
4384 | ||
4385 | /* Take ownership of the BSP's command tree, if it has one. | |
4386 | ||
4387 | The command tree could legitimately contain commands like | |
4388 | 'step' and 'next', which call clear_proceed_status, which | |
4389 | frees stop_bpstat's command tree. To make sure this doesn't | |
4390 | free the tree we're executing out from under us, we need to | |
4391 | take ownership of the tree ourselves. Since a given bpstat's | |
4392 | commands are only executed once, we don't need to copy it; we | |
4393 | can clear the pointer in the bpstat, and make sure we free | |
4394 | the tree when we're done. */ | |
9add0f1b TT |
4395 | ccmd = bs->commands; |
4396 | bs->commands = NULL; | |
abf85f46 JK |
4397 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4398 | cmd = ccmd ? ccmd->commands : NULL; | |
4399 | if (command_line_is_silent (cmd)) | |
4400 | { | |
4401 | /* The action has been already done by bpstat_stop_status. */ | |
4402 | cmd = cmd->next; | |
4403 | } | |
6c50ab1c | 4404 | |
c906108c SS |
4405 | while (cmd != NULL) |
4406 | { | |
4407 | execute_control_command (cmd); | |
4408 | ||
4409 | if (breakpoint_proceeded) | |
4410 | break; | |
4411 | else | |
4412 | cmd = cmd->next; | |
4413 | } | |
6c50ab1c JB |
4414 | |
4415 | /* We can free this command tree now. */ | |
4416 | do_cleanups (this_cmd_tree_chain); | |
4417 | ||
c906108c | 4418 | if (breakpoint_proceeded) |
32c1e744 VP |
4419 | { |
4420 | if (target_can_async_p ()) | |
347bddb7 PA |
4421 | /* If we are in async mode, then the target might be still |
4422 | running, not stopped at any breakpoint, so nothing for | |
4423 | us to do here -- just return to the event loop. */ | |
4424 | ; | |
32c1e744 VP |
4425 | else |
4426 | /* In sync mode, when execute_control_command returns | |
4427 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4428 | Breakpoint commands for that stop were not run, since |
4429 | execute_command does not run breakpoint commands -- | |
4430 | only command_line_handler does, but that one is not | |
4431 | involved in execution of breakpoint commands. So, we | |
4432 | can now execute breakpoint commands. It should be | |
4433 | noted that making execute_command do bpstat actions is | |
4434 | not an option -- in this case we'll have recursive | |
4435 | invocation of bpstat for each breakpoint with a | |
4436 | command, and can easily blow up GDB stack. Instead, we | |
4437 | return true, which will trigger the caller to recall us | |
4438 | with the new stop_bpstat. */ | |
4439 | again = 1; | |
4440 | break; | |
32c1e744 | 4441 | } |
c906108c | 4442 | } |
c2b8ed2c | 4443 | do_cleanups (old_chain); |
347bddb7 PA |
4444 | return again; |
4445 | } | |
4446 | ||
4447 | void | |
4448 | bpstat_do_actions (void) | |
4449 | { | |
353d1d73 JK |
4450 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4451 | ||
347bddb7 PA |
4452 | /* Do any commands attached to breakpoint we are stopped at. */ |
4453 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4454 | && target_has_execution | |
4455 | && !is_exited (inferior_ptid) | |
4456 | && !is_executing (inferior_ptid)) | |
4457 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4458 | and only return when it is stopped at the next breakpoint, we | |
4459 | keep doing breakpoint actions until it returns false to | |
4460 | indicate the inferior was not resumed. */ | |
16c381f0 | 4461 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4462 | break; |
353d1d73 JK |
4463 | |
4464 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4465 | } |
4466 | ||
fa4727a6 DJ |
4467 | /* Print out the (old or new) value associated with a watchpoint. */ |
4468 | ||
4469 | static void | |
4470 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4471 | { | |
4472 | if (val == NULL) | |
4473 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4474 | else | |
79a45b7d TT |
4475 | { |
4476 | struct value_print_options opts; | |
4477 | get_user_print_options (&opts); | |
4478 | value_print (val, stream, &opts); | |
4479 | } | |
fa4727a6 DJ |
4480 | } |
4481 | ||
e514a9d6 | 4482 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4483 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4484 | 'print_it' in the bpstat structure. Under some circumstances we |
4485 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4486 | normal_stop(). */ |
e514a9d6 JM |
4487 | |
4488 | static enum print_stop_action | |
4489 | print_bp_stop_message (bpstat bs) | |
4490 | { | |
4491 | switch (bs->print_it) | |
4492 | { | |
4493 | case print_it_noop: | |
4a64f543 | 4494 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4495 | return PRINT_UNKNOWN; |
4496 | break; | |
4497 | ||
4498 | case print_it_done: | |
4499 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4500 | relevant messages. */ |
e514a9d6 JM |
4501 | return PRINT_SRC_AND_LOC; |
4502 | break; | |
4503 | ||
4504 | case print_it_normal: | |
4f8d1dc6 | 4505 | { |
f431efe5 PA |
4506 | struct breakpoint *b = bs->breakpoint_at; |
4507 | ||
1a6a67de TJB |
4508 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4509 | which has since been deleted. */ | |
4510 | if (b == NULL) | |
4511 | return PRINT_UNKNOWN; | |
4512 | ||
348d480f PA |
4513 | /* Normal case. Call the breakpoint's print_it method. */ |
4514 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4515 | } |
348d480f | 4516 | break; |
3086aeae | 4517 | |
e514a9d6 | 4518 | default: |
8e65ff28 | 4519 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4520 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4521 | break; |
c906108c | 4522 | } |
c906108c SS |
4523 | } |
4524 | ||
edcc5120 TT |
4525 | /* A helper function that prints a shared library stopped event. */ |
4526 | ||
4527 | static void | |
4528 | print_solib_event (int is_catchpoint) | |
4529 | { | |
4530 | int any_deleted | |
4531 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4532 | int any_added | |
4533 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4534 | ||
4535 | if (!is_catchpoint) | |
4536 | { | |
4537 | if (any_added || any_deleted) | |
4538 | ui_out_text (current_uiout, | |
4539 | _("Stopped due to shared library event:\n")); | |
4540 | else | |
4541 | ui_out_text (current_uiout, | |
4542 | _("Stopped due to shared library event (no " | |
4543 | "libraries added or removed)\n")); | |
4544 | } | |
4545 | ||
4546 | if (ui_out_is_mi_like_p (current_uiout)) | |
4547 | ui_out_field_string (current_uiout, "reason", | |
4548 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4549 | ||
4550 | if (any_deleted) | |
4551 | { | |
4552 | struct cleanup *cleanup; | |
4553 | char *name; | |
4554 | int ix; | |
4555 | ||
4556 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4557 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4558 | "removed"); | |
4559 | for (ix = 0; | |
4560 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4561 | ix, name); | |
4562 | ++ix) | |
4563 | { | |
4564 | if (ix > 0) | |
4565 | ui_out_text (current_uiout, " "); | |
4566 | ui_out_field_string (current_uiout, "library", name); | |
4567 | ui_out_text (current_uiout, "\n"); | |
4568 | } | |
4569 | ||
4570 | do_cleanups (cleanup); | |
4571 | } | |
4572 | ||
4573 | if (any_added) | |
4574 | { | |
4575 | struct so_list *iter; | |
4576 | int ix; | |
4577 | struct cleanup *cleanup; | |
4578 | ||
4579 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4580 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4581 | "added"); | |
4582 | for (ix = 0; | |
4583 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4584 | ix, iter); | |
4585 | ++ix) | |
4586 | { | |
4587 | if (ix > 0) | |
4588 | ui_out_text (current_uiout, " "); | |
4589 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4590 | ui_out_text (current_uiout, "\n"); | |
4591 | } | |
4592 | ||
4593 | do_cleanups (cleanup); | |
4594 | } | |
4595 | } | |
4596 | ||
e514a9d6 JM |
4597 | /* Print a message indicating what happened. This is called from |
4598 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4599 | list - a list of the eventpoints that caused this stop. KIND is |
4600 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4601 | routine calls the generic print routine for printing a message |
4602 | about reasons for stopping. This will print (for example) the | |
4603 | "Breakpoint n," part of the output. The return value of this | |
4604 | routine is one of: | |
c906108c | 4605 | |
4a64f543 | 4606 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4607 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4608 | code to print the location. An example is |
c5aa993b JM |
4609 | "Breakpoint 1, " which should be followed by |
4610 | the location. | |
917317f4 | 4611 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4612 | to also print the location part of the message. |
4613 | An example is the catch/throw messages, which | |
4a64f543 | 4614 | don't require a location appended to the end. |
917317f4 | 4615 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4616 | further info to be printed. */ |
c906108c | 4617 | |
917317f4 | 4618 | enum print_stop_action |
36dfb11c | 4619 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4620 | { |
4621 | int val; | |
c5aa993b | 4622 | |
c906108c | 4623 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4624 | (Currently all watchpoints go on the bpstat whether hit or not. |
4625 | That probably could (should) be changed, provided care is taken | |
c906108c | 4626 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4627 | for (; bs; bs = bs->next) |
4628 | { | |
4629 | val = print_bp_stop_message (bs); | |
4630 | if (val == PRINT_SRC_ONLY | |
4631 | || val == PRINT_SRC_AND_LOC | |
4632 | || val == PRINT_NOTHING) | |
4633 | return val; | |
4634 | } | |
c906108c | 4635 | |
36dfb11c TT |
4636 | /* If we had hit a shared library event breakpoint, |
4637 | print_bp_stop_message would print out this message. If we hit an | |
4638 | OS-level shared library event, do the same thing. */ | |
4639 | if (kind == TARGET_WAITKIND_LOADED) | |
4640 | { | |
edcc5120 | 4641 | print_solib_event (0); |
36dfb11c TT |
4642 | return PRINT_NOTHING; |
4643 | } | |
4644 | ||
e514a9d6 | 4645 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4646 | with and nothing was printed. */ |
917317f4 | 4647 | return PRINT_UNKNOWN; |
c906108c SS |
4648 | } |
4649 | ||
c42bd95a DE |
4650 | /* Evaluate the expression EXP and return 1 if value is zero. |
4651 | This returns the inverse of the condition because it is called | |
4652 | from catch_errors which returns 0 if an exception happened, and if an | |
4653 | exception happens we want execution to stop. | |
4a64f543 | 4654 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4655 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4656 | |
4657 | static int | |
4efb68b1 | 4658 | breakpoint_cond_eval (void *exp) |
c906108c | 4659 | { |
278cd55f | 4660 | struct value *mark = value_mark (); |
c5aa993b | 4661 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4662 | |
c906108c SS |
4663 | value_free_to_mark (mark); |
4664 | return i; | |
4665 | } | |
4666 | ||
5760d0ab | 4667 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4668 | |
4669 | static bpstat | |
5760d0ab | 4670 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4671 | { |
4672 | bpstat bs; | |
4673 | ||
4674 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4675 | bs->next = NULL; |
4676 | **bs_link_pointer = bs; | |
4677 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4678 | bs->breakpoint_at = bl->owner; |
4679 | bs->bp_location_at = bl; | |
4680 | incref_bp_location (bl); | |
c906108c SS |
4681 | /* If the condition is false, etc., don't do the commands. */ |
4682 | bs->commands = NULL; | |
4683 | bs->old_val = NULL; | |
4684 | bs->print_it = print_it_normal; | |
4685 | return bs; | |
4686 | } | |
4687 | \f | |
d983da9c DJ |
4688 | /* The target has stopped with waitstatus WS. Check if any hardware |
4689 | watchpoints have triggered, according to the target. */ | |
4690 | ||
4691 | int | |
4692 | watchpoints_triggered (struct target_waitstatus *ws) | |
4693 | { | |
d92524f1 | 4694 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4695 | CORE_ADDR addr; |
4696 | struct breakpoint *b; | |
4697 | ||
4698 | if (!stopped_by_watchpoint) | |
4699 | { | |
4700 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4701 | as not triggered. */ | |
4702 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4703 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4704 | { |
4705 | struct watchpoint *w = (struct watchpoint *) b; | |
4706 | ||
4707 | w->watchpoint_triggered = watch_triggered_no; | |
4708 | } | |
d983da9c DJ |
4709 | |
4710 | return 0; | |
4711 | } | |
4712 | ||
4713 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4714 | { | |
4715 | /* We were stopped by a watchpoint, but we don't know where. | |
4716 | Mark all watchpoints as unknown. */ | |
4717 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4718 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4719 | { |
4720 | struct watchpoint *w = (struct watchpoint *) b; | |
4721 | ||
4722 | w->watchpoint_triggered = watch_triggered_unknown; | |
4723 | } | |
d983da9c | 4724 | |
3c4797ba | 4725 | return 1; |
d983da9c DJ |
4726 | } |
4727 | ||
4728 | /* The target could report the data address. Mark watchpoints | |
4729 | affected by this data address as triggered, and all others as not | |
4730 | triggered. */ | |
4731 | ||
4732 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4733 | if (is_hardware_watchpoint (b)) |
d983da9c | 4734 | { |
3a5c3e22 | 4735 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4736 | struct bp_location *loc; |
d983da9c | 4737 | |
3a5c3e22 | 4738 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4739 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4740 | { |
3a5c3e22 | 4741 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4742 | { |
3a5c3e22 PA |
4743 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4744 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4745 | |
4746 | if (newaddr == start) | |
4747 | { | |
3a5c3e22 | 4748 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4749 | break; |
4750 | } | |
4751 | } | |
4752 | /* Exact match not required. Within range is sufficient. */ | |
4753 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4754 | addr, loc->address, | |
4755 | loc->length)) | |
4756 | { | |
3a5c3e22 | 4757 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4758 | break; |
4759 | } | |
4760 | } | |
d983da9c DJ |
4761 | } |
4762 | ||
4763 | return 1; | |
4764 | } | |
4765 | ||
c906108c SS |
4766 | /* Possible return values for watchpoint_check (this can't be an enum |
4767 | because of check_errors). */ | |
4768 | /* The watchpoint has been deleted. */ | |
4769 | #define WP_DELETED 1 | |
4770 | /* The value has changed. */ | |
4771 | #define WP_VALUE_CHANGED 2 | |
4772 | /* The value has not changed. */ | |
4773 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4774 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4775 | #define WP_IGNORE 4 | |
c906108c SS |
4776 | |
4777 | #define BP_TEMPFLAG 1 | |
4778 | #define BP_HARDWAREFLAG 2 | |
4779 | ||
4a64f543 MS |
4780 | /* Evaluate watchpoint condition expression and check if its value |
4781 | changed. | |
553e4c11 JB |
4782 | |
4783 | P should be a pointer to struct bpstat, but is defined as a void * | |
4784 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4785 | |
4786 | static int | |
4efb68b1 | 4787 | watchpoint_check (void *p) |
c906108c SS |
4788 | { |
4789 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4790 | struct watchpoint *b; |
c906108c SS |
4791 | struct frame_info *fr; |
4792 | int within_current_scope; | |
4793 | ||
f431efe5 | 4794 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4795 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4796 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4797 | |
f6bc2008 PA |
4798 | /* If this is a local watchpoint, we only want to check if the |
4799 | watchpoint frame is in scope if the current thread is the thread | |
4800 | that was used to create the watchpoint. */ | |
4801 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4802 | return WP_IGNORE; |
f6bc2008 | 4803 | |
c906108c SS |
4804 | if (b->exp_valid_block == NULL) |
4805 | within_current_scope = 1; | |
4806 | else | |
4807 | { | |
edb3359d DJ |
4808 | struct frame_info *frame = get_current_frame (); |
4809 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4810 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4811 | ||
4a64f543 MS |
4812 | /* in_function_epilogue_p() returns a non-zero value if we're |
4813 | still in the function but the stack frame has already been | |
4814 | invalidated. Since we can't rely on the values of local | |
4815 | variables after the stack has been destroyed, we are treating | |
4816 | the watchpoint in that state as `not changed' without further | |
4817 | checking. Don't mark watchpoints as changed if the current | |
4818 | frame is in an epilogue - even if they are in some other | |
4819 | frame, our view of the stack is likely to be wrong and | |
4820 | frame_find_by_id could error out. */ | |
a0f49112 | 4821 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4822 | return WP_IGNORE; |
a0f49112 | 4823 | |
101dcfbe | 4824 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4825 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4826 | |
4827 | /* If we've gotten confused in the unwinder, we might have | |
4828 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4829 | if (within_current_scope) |
4830 | { | |
4831 | struct symbol *function; | |
4832 | ||
4833 | function = get_frame_function (fr); | |
4834 | if (function == NULL | |
4835 | || !contained_in (b->exp_valid_block, | |
4836 | SYMBOL_BLOCK_VALUE (function))) | |
4837 | within_current_scope = 0; | |
4838 | } | |
69fbadd5 | 4839 | |
edb3359d | 4840 | if (within_current_scope) |
c906108c SS |
4841 | /* If we end up stopping, the current frame will get selected |
4842 | in normal_stop. So this call to select_frame won't affect | |
4843 | the user. */ | |
0f7d239c | 4844 | select_frame (fr); |
c906108c | 4845 | } |
c5aa993b | 4846 | |
c906108c SS |
4847 | if (within_current_scope) |
4848 | { | |
4a64f543 MS |
4849 | /* We use value_{,free_to_}mark because it could be a *long* |
4850 | time before we return to the command level and call | |
4851 | free_all_values. We can't call free_all_values because we | |
4852 | might be in the middle of evaluating a function call. */ | |
c906108c | 4853 | |
0cf6dd15 | 4854 | int pc = 0; |
9c06b0b4 | 4855 | struct value *mark; |
fa4727a6 DJ |
4856 | struct value *new_val; |
4857 | ||
3a5c3e22 | 4858 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4859 | /* Since we don't know the exact trigger address (from |
4860 | stopped_data_address), just tell the user we've triggered | |
4861 | a mask watchpoint. */ | |
4862 | return WP_VALUE_CHANGED; | |
4863 | ||
4864 | mark = value_mark (); | |
3a1115a0 | 4865 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4866 | |
4a64f543 MS |
4867 | /* We use value_equal_contents instead of value_equal because |
4868 | the latter coerces an array to a pointer, thus comparing just | |
4869 | the address of the array instead of its contents. This is | |
4870 | not what we want. */ | |
fa4727a6 | 4871 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4872 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4873 | { |
fa4727a6 DJ |
4874 | if (new_val != NULL) |
4875 | { | |
4876 | release_value (new_val); | |
4877 | value_free_to_mark (mark); | |
4878 | } | |
c906108c SS |
4879 | bs->old_val = b->val; |
4880 | b->val = new_val; | |
fa4727a6 | 4881 | b->val_valid = 1; |
c906108c SS |
4882 | return WP_VALUE_CHANGED; |
4883 | } | |
4884 | else | |
4885 | { | |
60e1c644 | 4886 | /* Nothing changed. */ |
c906108c | 4887 | value_free_to_mark (mark); |
c906108c SS |
4888 | return WP_VALUE_NOT_CHANGED; |
4889 | } | |
4890 | } | |
4891 | else | |
4892 | { | |
79a45e25 PA |
4893 | struct ui_out *uiout = current_uiout; |
4894 | ||
c906108c | 4895 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4896 | if we temporarily ignored the watchpoint, then when |
4897 | we reenter the block in which it is valid it contains | |
4898 | garbage (in the case of a function, it may have two | |
4899 | garbage values, one before and one after the prologue). | |
4900 | So we can't even detect the first assignment to it and | |
4901 | watch after that (since the garbage may or may not equal | |
4902 | the first value assigned). */ | |
348d480f PA |
4903 | /* We print all the stop information in |
4904 | breakpoint_ops->print_it, but in this case, by the time we | |
4905 | call breakpoint_ops->print_it this bp will be deleted | |
4906 | already. So we have no choice but print the information | |
4907 | here. */ | |
9dc5e2a9 | 4908 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4909 | ui_out_field_string |
4910 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4911 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4912 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4913 | ui_out_text (uiout, |
4914 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4915 | which its expression is valid.\n"); |
4ce44c66 | 4916 | |
cdac0397 | 4917 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4918 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4919 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4920 | |
4921 | return WP_DELETED; | |
4922 | } | |
4923 | } | |
4924 | ||
18a18393 | 4925 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4926 | breakpoint location BL. This function does not check if we should |
4927 | stop, only if BL explains the stop. */ | |
4928 | ||
18a18393 | 4929 | static int |
6c95b8df | 4930 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4931 | struct address_space *aspace, CORE_ADDR bp_addr, |
4932 | const struct target_waitstatus *ws) | |
18a18393 VP |
4933 | { |
4934 | struct breakpoint *b = bl->owner; | |
4935 | ||
348d480f | 4936 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4937 | gdb_assert (b != NULL); |
4938 | ||
09ac7c10 | 4939 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4940 | } |
4941 | ||
3a5c3e22 PA |
4942 | /* Determine if the watched values have actually changed, and we |
4943 | should stop. If not, set BS->stop to 0. */ | |
4944 | ||
18a18393 VP |
4945 | static void |
4946 | bpstat_check_watchpoint (bpstat bs) | |
4947 | { | |
2bdf28a0 | 4948 | const struct bp_location *bl; |
3a5c3e22 | 4949 | struct watchpoint *b; |
2bdf28a0 JK |
4950 | |
4951 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4952 | bl = bs->bp_location_at; |
2bdf28a0 | 4953 | gdb_assert (bl != NULL); |
3a5c3e22 | 4954 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4955 | gdb_assert (b != NULL); |
18a18393 | 4956 | |
18a18393 | 4957 | { |
18a18393 VP |
4958 | int must_check_value = 0; |
4959 | ||
3a5c3e22 | 4960 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
4961 | /* For a software watchpoint, we must always check the |
4962 | watched value. */ | |
4963 | must_check_value = 1; | |
4964 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4965 | /* We have a hardware watchpoint (read, write, or access) | |
4966 | and the target earlier reported an address watched by | |
4967 | this watchpoint. */ | |
4968 | must_check_value = 1; | |
4969 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 4970 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
4971 | /* We were stopped by a hardware watchpoint, but the target could |
4972 | not report the data address. We must check the watchpoint's | |
4973 | value. Access and read watchpoints are out of luck; without | |
4974 | a data address, we can't figure it out. */ | |
4975 | must_check_value = 1; | |
3a5c3e22 | 4976 | |
18a18393 VP |
4977 | if (must_check_value) |
4978 | { | |
3e43a32a MS |
4979 | char *message |
4980 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 4981 | b->base.number); |
18a18393 VP |
4982 | struct cleanup *cleanups = make_cleanup (xfree, message); |
4983 | int e = catch_errors (watchpoint_check, bs, message, | |
4984 | RETURN_MASK_ALL); | |
4985 | do_cleanups (cleanups); | |
4986 | switch (e) | |
4987 | { | |
4988 | case WP_DELETED: | |
4989 | /* We've already printed what needs to be printed. */ | |
4990 | bs->print_it = print_it_done; | |
4991 | /* Stop. */ | |
4992 | break; | |
60e1c644 PA |
4993 | case WP_IGNORE: |
4994 | bs->print_it = print_it_noop; | |
4995 | bs->stop = 0; | |
4996 | break; | |
18a18393 | 4997 | case WP_VALUE_CHANGED: |
3a5c3e22 | 4998 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 4999 | { |
85d721b8 PA |
5000 | /* There are two cases to consider here: |
5001 | ||
4a64f543 | 5002 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5003 | In that case, trust the target, and always report |
5004 | the watchpoint hit to the user. Even though | |
5005 | reads don't cause value changes, the value may | |
5006 | have changed since the last time it was read, and | |
5007 | since we're not trapping writes, we will not see | |
5008 | those, and as such we should ignore our notion of | |
5009 | old value. | |
5010 | ||
4a64f543 | 5011 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5012 | reads and writes. There are two ways this may |
5013 | happen: | |
5014 | ||
4a64f543 | 5015 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5016 | reads only, but can break on accesses (reads or |
5017 | writes), such as e.g., x86. We detect this case | |
5018 | at the time we try to insert read watchpoints. | |
5019 | ||
4a64f543 | 5020 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5021 | watchpoints, but, the user set an access or write |
5022 | watchpoint watching the same memory as this read | |
5023 | watchpoint. | |
5024 | ||
5025 | If we're watching memory writes as well as reads, | |
5026 | ignore watchpoint hits when we find that the | |
5027 | value hasn't changed, as reads don't cause | |
5028 | changes. This still gives false positives when | |
5029 | the program writes the same value to memory as | |
5030 | what there was already in memory (we will confuse | |
5031 | it for a read), but it's much better than | |
5032 | nothing. */ | |
5033 | ||
5034 | int other_write_watchpoint = 0; | |
5035 | ||
5036 | if (bl->watchpoint_type == hw_read) | |
5037 | { | |
5038 | struct breakpoint *other_b; | |
5039 | ||
5040 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5041 | if (other_b->type == bp_hardware_watchpoint |
5042 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5043 | { |
3a5c3e22 PA |
5044 | struct watchpoint *other_w = |
5045 | (struct watchpoint *) other_b; | |
5046 | ||
5047 | if (other_w->watchpoint_triggered | |
5048 | == watch_triggered_yes) | |
5049 | { | |
5050 | other_write_watchpoint = 1; | |
5051 | break; | |
5052 | } | |
85d721b8 PA |
5053 | } |
5054 | } | |
5055 | ||
5056 | if (other_write_watchpoint | |
5057 | || bl->watchpoint_type == hw_access) | |
5058 | { | |
5059 | /* We're watching the same memory for writes, | |
5060 | and the value changed since the last time we | |
5061 | updated it, so this trap must be for a write. | |
5062 | Ignore it. */ | |
5063 | bs->print_it = print_it_noop; | |
5064 | bs->stop = 0; | |
5065 | } | |
18a18393 VP |
5066 | } |
5067 | break; | |
5068 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5069 | if (b->base.type == bp_hardware_watchpoint |
5070 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5071 | { |
5072 | /* Don't stop: write watchpoints shouldn't fire if | |
5073 | the value hasn't changed. */ | |
5074 | bs->print_it = print_it_noop; | |
5075 | bs->stop = 0; | |
5076 | } | |
5077 | /* Stop. */ | |
5078 | break; | |
5079 | default: | |
5080 | /* Can't happen. */ | |
5081 | case 0: | |
5082 | /* Error from catch_errors. */ | |
3a5c3e22 | 5083 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5084 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5085 | /* We've already printed what needs to be printed. */ |
5086 | bs->print_it = print_it_done; | |
5087 | break; | |
5088 | } | |
5089 | } | |
5090 | else /* must_check_value == 0 */ | |
5091 | { | |
5092 | /* This is a case where some watchpoint(s) triggered, but | |
5093 | not at the address of this watchpoint, or else no | |
5094 | watchpoint triggered after all. So don't print | |
5095 | anything for this watchpoint. */ | |
5096 | bs->print_it = print_it_noop; | |
5097 | bs->stop = 0; | |
5098 | } | |
5099 | } | |
5100 | } | |
5101 | ||
7d4df6a4 DE |
5102 | /* For breakpoints that are currently marked as telling gdb to stop, |
5103 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5104 | of breakpoint referred to by BS. If we should not stop for this |
5105 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5106 | |
18a18393 VP |
5107 | static void |
5108 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5109 | { | |
5110 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
5111 | const struct bp_location *bl; |
5112 | struct breakpoint *b; | |
7d4df6a4 DE |
5113 | int value_is_zero = 0; |
5114 | struct expression *cond; | |
5115 | ||
5116 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5117 | |
5118 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5119 | bl = bs->bp_location_at; |
2bdf28a0 | 5120 | gdb_assert (bl != NULL); |
f431efe5 | 5121 | b = bs->breakpoint_at; |
2bdf28a0 | 5122 | gdb_assert (b != NULL); |
18a18393 | 5123 | |
b775012e LM |
5124 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5125 | need to do so again since GDB does not know if we stopped due to a | |
5126 | breakpoint or a single step breakpoint. */ | |
5127 | ||
18a18393 | 5128 | if (frame_id_p (b->frame_id) |
edb3359d | 5129 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5130 | { |
7d4df6a4 DE |
5131 | bs->stop = 0; |
5132 | return; | |
5133 | } | |
60e1c644 | 5134 | |
6c1b0f7b DE |
5135 | /* If this is a thread-specific breakpoint, don't waste cpu evaluating the |
5136 | condition if this isn't the specified thread. */ | |
5137 | if (b->thread != -1 && b->thread != thread_id) | |
5138 | { | |
5139 | bs->stop = 0; | |
5140 | return; | |
5141 | } | |
5142 | ||
7d4df6a4 DE |
5143 | /* Evaluate Python breakpoints that have a "stop" method implemented. */ |
5144 | if (b->py_bp_object) | |
5145 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
7371cf6d | 5146 | |
7d4df6a4 DE |
5147 | if (is_watchpoint (b)) |
5148 | { | |
5149 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5150 | |
7d4df6a4 DE |
5151 | cond = w->cond_exp; |
5152 | } | |
5153 | else | |
5154 | cond = bl->cond; | |
60e1c644 | 5155 | |
7d4df6a4 DE |
5156 | if (cond && b->disposition != disp_del_at_next_stop) |
5157 | { | |
5158 | int within_current_scope = 1; | |
5159 | struct watchpoint * w; | |
60e1c644 | 5160 | |
7d4df6a4 DE |
5161 | /* We use value_mark and value_free_to_mark because it could |
5162 | be a long time before we return to the command level and | |
5163 | call free_all_values. We can't call free_all_values | |
5164 | because we might be in the middle of evaluating a | |
5165 | function call. */ | |
5166 | struct value *mark = value_mark (); | |
5167 | ||
5168 | if (is_watchpoint (b)) | |
5169 | w = (struct watchpoint *) b; | |
5170 | else | |
5171 | w = NULL; | |
5172 | ||
5173 | /* Need to select the frame, with all that implies so that | |
5174 | the conditions will have the right context. Because we | |
5175 | use the frame, we will not see an inlined function's | |
5176 | variables when we arrive at a breakpoint at the start | |
5177 | of the inlined function; the current frame will be the | |
5178 | call site. */ | |
5179 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5180 | select_frame (get_current_frame ()); | |
5181 | else | |
18a18393 | 5182 | { |
7d4df6a4 DE |
5183 | struct frame_info *frame; |
5184 | ||
5185 | /* For local watchpoint expressions, which particular | |
5186 | instance of a local is being watched matters, so we | |
5187 | keep track of the frame to evaluate the expression | |
5188 | in. To evaluate the condition however, it doesn't | |
5189 | really matter which instantiation of the function | |
5190 | where the condition makes sense triggers the | |
5191 | watchpoint. This allows an expression like "watch | |
5192 | global if q > 10" set in `func', catch writes to | |
5193 | global on all threads that call `func', or catch | |
5194 | writes on all recursive calls of `func' by a single | |
5195 | thread. We simply always evaluate the condition in | |
5196 | the innermost frame that's executing where it makes | |
5197 | sense to evaluate the condition. It seems | |
5198 | intuitive. */ | |
5199 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5200 | if (frame != NULL) | |
5201 | select_frame (frame); | |
5202 | else | |
5203 | within_current_scope = 0; | |
18a18393 | 5204 | } |
7d4df6a4 DE |
5205 | if (within_current_scope) |
5206 | value_is_zero | |
5207 | = catch_errors (breakpoint_cond_eval, cond, | |
5208 | "Error in testing breakpoint condition:\n", | |
5209 | RETURN_MASK_ALL); | |
5210 | else | |
18a18393 | 5211 | { |
7d4df6a4 DE |
5212 | warning (_("Watchpoint condition cannot be tested " |
5213 | "in the current scope")); | |
5214 | /* If we failed to set the right context for this | |
5215 | watchpoint, unconditionally report it. */ | |
5216 | value_is_zero = 0; | |
18a18393 | 5217 | } |
7d4df6a4 DE |
5218 | /* FIXME-someday, should give breakpoint #. */ |
5219 | value_free_to_mark (mark); | |
18a18393 | 5220 | } |
7d4df6a4 DE |
5221 | |
5222 | if (cond && value_is_zero) | |
5223 | { | |
5224 | bs->stop = 0; | |
5225 | } | |
7d4df6a4 DE |
5226 | else if (b->ignore_count > 0) |
5227 | { | |
5228 | b->ignore_count--; | |
5229 | bs->stop = 0; | |
5230 | /* Increase the hit count even though we don't stop. */ | |
5231 | ++(b->hit_count); | |
5232 | observer_notify_breakpoint_modified (b); | |
5233 | } | |
18a18393 VP |
5234 | } |
5235 | ||
5236 | ||
9709f61c | 5237 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5238 | BP_ADDR in thread PTID. |
c906108c | 5239 | |
d983da9c | 5240 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5241 | don't understand this stop. Result is a chain of bpstat's such |
5242 | that: | |
c906108c | 5243 | |
c5aa993b | 5244 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5245 | |
c5aa993b | 5246 | if we understand why we stopped, the result is not null. |
c906108c | 5247 | |
c5aa993b JM |
5248 | Each element of the chain refers to a particular breakpoint or |
5249 | watchpoint at which we have stopped. (We may have stopped for | |
5250 | several reasons concurrently.) | |
c906108c | 5251 | |
c5aa993b JM |
5252 | Each element of the chain has valid next, breakpoint_at, |
5253 | commands, FIXME??? fields. */ | |
c906108c SS |
5254 | |
5255 | bpstat | |
6c95b8df | 5256 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5257 | CORE_ADDR bp_addr, ptid_t ptid, |
5258 | const struct target_waitstatus *ws) | |
c906108c | 5259 | { |
0d381245 | 5260 | struct breakpoint *b = NULL; |
afe38095 | 5261 | struct bp_location *bl; |
20874c92 | 5262 | struct bp_location *loc; |
5760d0ab JK |
5263 | /* First item of allocated bpstat's. */ |
5264 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5265 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5266 | bpstat bs; |
20874c92 | 5267 | int ix; |
429374b8 | 5268 | int need_remove_insert; |
f431efe5 | 5269 | int removed_any; |
c906108c | 5270 | |
f431efe5 PA |
5271 | /* First, build the bpstat chain with locations that explain a |
5272 | target stop, while being careful to not set the target running, | |
5273 | as that may invalidate locations (in particular watchpoint | |
5274 | locations are recreated). Resuming will happen here with | |
5275 | breakpoint conditions or watchpoint expressions that include | |
5276 | inferior function calls. */ | |
c5aa993b | 5277 | |
429374b8 JK |
5278 | ALL_BREAKPOINTS (b) |
5279 | { | |
5280 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5281 | continue; | |
a5606eee | 5282 | |
429374b8 JK |
5283 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5284 | { | |
4a64f543 MS |
5285 | /* For hardware watchpoints, we look only at the first |
5286 | location. The watchpoint_check function will work on the | |
5287 | entire expression, not the individual locations. For | |
5288 | read watchpoints, the watchpoints_triggered function has | |
5289 | checked all locations already. */ | |
429374b8 JK |
5290 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5291 | break; | |
18a18393 | 5292 | |
f6592439 | 5293 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5294 | continue; |
c5aa993b | 5295 | |
09ac7c10 | 5296 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5297 | continue; |
c5aa993b | 5298 | |
4a64f543 MS |
5299 | /* Come here if it's a watchpoint, or if the break address |
5300 | matches. */ | |
c5aa993b | 5301 | |
4a64f543 MS |
5302 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5303 | explain stop. */ | |
c5aa993b | 5304 | |
f431efe5 PA |
5305 | /* Assume we stop. Should we find a watchpoint that is not |
5306 | actually triggered, or if the condition of the breakpoint | |
5307 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5308 | bs->stop = 1; |
5309 | bs->print = 1; | |
d983da9c | 5310 | |
f431efe5 PA |
5311 | /* If this is a scope breakpoint, mark the associated |
5312 | watchpoint as triggered so that we will handle the | |
5313 | out-of-scope event. We'll get to the watchpoint next | |
5314 | iteration. */ | |
d0fb5eae | 5315 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5316 | { |
5317 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5318 | ||
5319 | w->watchpoint_triggered = watch_triggered_yes; | |
5320 | } | |
f431efe5 PA |
5321 | } |
5322 | } | |
5323 | ||
5324 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5325 | { | |
f1310107 | 5326 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5327 | { |
5760d0ab | 5328 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5329 | /* For hits of moribund locations, we should just proceed. */ |
5330 | bs->stop = 0; | |
5331 | bs->print = 0; | |
5332 | bs->print_it = print_it_noop; | |
5333 | } | |
5334 | } | |
5335 | ||
edcc5120 TT |
5336 | /* A bit of special processing for shlib breakpoints. We need to |
5337 | process solib loading here, so that the lists of loaded and | |
5338 | unloaded libraries are correct before we handle "catch load" and | |
5339 | "catch unload". */ | |
5340 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5341 | { | |
5d268276 | 5342 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5343 | { |
5344 | handle_solib_event (); | |
5345 | break; | |
5346 | } | |
5347 | } | |
5348 | ||
f431efe5 PA |
5349 | /* Now go through the locations that caused the target to stop, and |
5350 | check whether we're interested in reporting this stop to higher | |
5351 | layers, or whether we should resume the target transparently. */ | |
5352 | ||
5353 | removed_any = 0; | |
5354 | ||
5760d0ab | 5355 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5356 | { |
5357 | if (!bs->stop) | |
5358 | continue; | |
5359 | ||
f431efe5 | 5360 | b = bs->breakpoint_at; |
348d480f PA |
5361 | b->ops->check_status (bs); |
5362 | if (bs->stop) | |
28010a5d | 5363 | { |
348d480f | 5364 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5365 | |
429374b8 JK |
5366 | if (bs->stop) |
5367 | { | |
5368 | ++(b->hit_count); | |
8d3788bd | 5369 | observer_notify_breakpoint_modified (b); |
c906108c | 5370 | |
4a64f543 | 5371 | /* We will stop here. */ |
429374b8 JK |
5372 | if (b->disposition == disp_disable) |
5373 | { | |
816338b5 SS |
5374 | --(b->enable_count); |
5375 | if (b->enable_count <= 0 | |
5376 | && b->enable_state != bp_permanent) | |
429374b8 | 5377 | b->enable_state = bp_disabled; |
f431efe5 | 5378 | removed_any = 1; |
429374b8 JK |
5379 | } |
5380 | if (b->silent) | |
5381 | bs->print = 0; | |
5382 | bs->commands = b->commands; | |
9add0f1b | 5383 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5384 | if (command_line_is_silent (bs->commands |
5385 | ? bs->commands->commands : NULL)) | |
5386 | bs->print = 0; | |
9d6e6e84 HZ |
5387 | |
5388 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5389 | } |
5390 | ||
348d480f | 5391 | } |
a9b3a50f PA |
5392 | |
5393 | /* Print nothing for this entry if we don't stop or don't | |
5394 | print. */ | |
5395 | if (!bs->stop || !bs->print) | |
5396 | bs->print_it = print_it_noop; | |
429374b8 | 5397 | } |
876fa593 | 5398 | |
d983da9c DJ |
5399 | /* If we aren't stopping, the value of some hardware watchpoint may |
5400 | not have changed, but the intermediate memory locations we are | |
5401 | watching may have. Don't bother if we're stopping; this will get | |
5402 | done later. */ | |
d832cb68 | 5403 | need_remove_insert = 0; |
5760d0ab JK |
5404 | if (! bpstat_causes_stop (bs_head)) |
5405 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5406 | if (!bs->stop |
f431efe5 PA |
5407 | && bs->breakpoint_at |
5408 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5409 | { |
3a5c3e22 PA |
5410 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5411 | ||
5412 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5413 | need_remove_insert = 1; |
d983da9c DJ |
5414 | } |
5415 | ||
d832cb68 | 5416 | if (need_remove_insert) |
2d134ed3 | 5417 | update_global_location_list (1); |
f431efe5 PA |
5418 | else if (removed_any) |
5419 | update_global_location_list (0); | |
d832cb68 | 5420 | |
5760d0ab | 5421 | return bs_head; |
c906108c | 5422 | } |
628fe4e4 JK |
5423 | |
5424 | static void | |
5425 | handle_jit_event (void) | |
5426 | { | |
5427 | struct frame_info *frame; | |
5428 | struct gdbarch *gdbarch; | |
5429 | ||
5430 | /* Switch terminal for any messages produced by | |
5431 | breakpoint_re_set. */ | |
5432 | target_terminal_ours_for_output (); | |
5433 | ||
5434 | frame = get_current_frame (); | |
5435 | gdbarch = get_frame_arch (frame); | |
5436 | ||
5437 | jit_event_handler (gdbarch); | |
5438 | ||
5439 | target_terminal_inferior (); | |
5440 | } | |
5441 | ||
5442 | /* Prepare WHAT final decision for infrun. */ | |
5443 | ||
5444 | /* Decide what infrun needs to do with this bpstat. */ | |
5445 | ||
c906108c | 5446 | struct bpstat_what |
0e30163f | 5447 | bpstat_what (bpstat bs_head) |
c906108c | 5448 | { |
c906108c | 5449 | struct bpstat_what retval; |
628fe4e4 | 5450 | int jit_event = 0; |
0e30163f | 5451 | bpstat bs; |
c906108c | 5452 | |
628fe4e4 | 5453 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5454 | retval.call_dummy = STOP_NONE; |
186c406b | 5455 | retval.is_longjmp = 0; |
628fe4e4 | 5456 | |
0e30163f | 5457 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5458 | { |
628fe4e4 JK |
5459 | /* Extract this BS's action. After processing each BS, we check |
5460 | if its action overrides all we've seem so far. */ | |
5461 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5462 | enum bptype bptype; | |
5463 | ||
c906108c | 5464 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5465 | { |
5466 | /* I suspect this can happen if it was a momentary | |
5467 | breakpoint which has since been deleted. */ | |
5468 | bptype = bp_none; | |
5469 | } | |
20874c92 | 5470 | else |
f431efe5 | 5471 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5472 | |
5473 | switch (bptype) | |
c906108c SS |
5474 | { |
5475 | case bp_none: | |
628fe4e4 | 5476 | break; |
c906108c SS |
5477 | case bp_breakpoint: |
5478 | case bp_hardware_breakpoint: | |
5479 | case bp_until: | |
5480 | case bp_finish: | |
a9b3a50f | 5481 | case bp_shlib_event: |
c906108c SS |
5482 | if (bs->stop) |
5483 | { | |
5484 | if (bs->print) | |
628fe4e4 | 5485 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5486 | else |
628fe4e4 | 5487 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5488 | } |
5489 | else | |
628fe4e4 | 5490 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5491 | break; |
5492 | case bp_watchpoint: | |
5493 | case bp_hardware_watchpoint: | |
5494 | case bp_read_watchpoint: | |
5495 | case bp_access_watchpoint: | |
5496 | if (bs->stop) | |
5497 | { | |
5498 | if (bs->print) | |
628fe4e4 | 5499 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5500 | else |
628fe4e4 | 5501 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5502 | } |
5503 | else | |
628fe4e4 JK |
5504 | { |
5505 | /* There was a watchpoint, but we're not stopping. | |
5506 | This requires no further action. */ | |
5507 | } | |
c906108c SS |
5508 | break; |
5509 | case bp_longjmp: | |
e2e4d78b | 5510 | case bp_longjmp_call_dummy: |
186c406b | 5511 | case bp_exception: |
628fe4e4 | 5512 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5513 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5514 | break; |
5515 | case bp_longjmp_resume: | |
186c406b | 5516 | case bp_exception_resume: |
628fe4e4 | 5517 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5518 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5519 | break; |
5520 | case bp_step_resume: | |
5521 | if (bs->stop) | |
628fe4e4 JK |
5522 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5523 | else | |
c906108c | 5524 | { |
628fe4e4 JK |
5525 | /* It is for the wrong frame. */ |
5526 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5527 | } |
c906108c | 5528 | break; |
2c03e5be PA |
5529 | case bp_hp_step_resume: |
5530 | if (bs->stop) | |
5531 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5532 | else | |
5533 | { | |
5534 | /* It is for the wrong frame. */ | |
5535 | this_action = BPSTAT_WHAT_SINGLE; | |
5536 | } | |
5537 | break; | |
c906108c | 5538 | case bp_watchpoint_scope: |
c4093a6a | 5539 | case bp_thread_event: |
1900040c | 5540 | case bp_overlay_event: |
0fd8e87f | 5541 | case bp_longjmp_master: |
aa7d318d | 5542 | case bp_std_terminate_master: |
186c406b | 5543 | case bp_exception_master: |
628fe4e4 | 5544 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5545 | break; |
ce78b96d | 5546 | case bp_catchpoint: |
c5aa993b JM |
5547 | if (bs->stop) |
5548 | { | |
5549 | if (bs->print) | |
628fe4e4 | 5550 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5551 | else |
628fe4e4 | 5552 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5553 | } |
5554 | else | |
628fe4e4 JK |
5555 | { |
5556 | /* There was a catchpoint, but we're not stopping. | |
5557 | This requires no further action. */ | |
5558 | } | |
5559 | break; | |
628fe4e4 JK |
5560 | case bp_jit_event: |
5561 | jit_event = 1; | |
5562 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5563 | break; |
c906108c | 5564 | case bp_call_dummy: |
53a5351d JM |
5565 | /* Make sure the action is stop (silent or noisy), |
5566 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5567 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5568 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5569 | break; |
5570 | case bp_std_terminate: | |
5571 | /* Make sure the action is stop (silent or noisy), | |
5572 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5573 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5574 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5575 | break; |
1042e4c0 | 5576 | case bp_tracepoint: |
7a697b8d | 5577 | case bp_fast_tracepoint: |
0fb4aa4b | 5578 | case bp_static_tracepoint: |
1042e4c0 SS |
5579 | /* Tracepoint hits should not be reported back to GDB, and |
5580 | if one got through somehow, it should have been filtered | |
5581 | out already. */ | |
5582 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5583 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5584 | break; |
5585 | case bp_gnu_ifunc_resolver: | |
5586 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5587 | this_action = BPSTAT_WHAT_SINGLE; | |
5588 | break; | |
5589 | case bp_gnu_ifunc_resolver_return: | |
5590 | /* The breakpoint will be removed, execution will restart from the | |
5591 | PC of the former breakpoint. */ | |
5592 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5593 | break; | |
e7e0cddf SS |
5594 | |
5595 | case bp_dprintf: | |
a11cfd87 HZ |
5596 | if (bs->stop) |
5597 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5598 | else | |
5599 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5600 | break; |
5601 | ||
628fe4e4 JK |
5602 | default: |
5603 | internal_error (__FILE__, __LINE__, | |
5604 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5605 | } |
628fe4e4 JK |
5606 | |
5607 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5608 | } |
628fe4e4 | 5609 | |
0e30163f JK |
5610 | /* These operations may affect the bs->breakpoint_at state so they are |
5611 | delayed after MAIN_ACTION is decided above. */ | |
5612 | ||
628fe4e4 JK |
5613 | if (jit_event) |
5614 | { | |
5615 | if (debug_infrun) | |
5616 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5617 | ||
5618 | handle_jit_event (); | |
5619 | } | |
5620 | ||
0e30163f JK |
5621 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5622 | { | |
5623 | struct breakpoint *b = bs->breakpoint_at; | |
5624 | ||
5625 | if (b == NULL) | |
5626 | continue; | |
5627 | switch (b->type) | |
5628 | { | |
5629 | case bp_gnu_ifunc_resolver: | |
5630 | gnu_ifunc_resolver_stop (b); | |
5631 | break; | |
5632 | case bp_gnu_ifunc_resolver_return: | |
5633 | gnu_ifunc_resolver_return_stop (b); | |
5634 | break; | |
5635 | } | |
5636 | } | |
5637 | ||
c906108c SS |
5638 | return retval; |
5639 | } | |
5640 | ||
5641 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5642 | without hardware support). This isn't related to a specific bpstat, | |
5643 | just to things like whether watchpoints are set. */ | |
5644 | ||
c5aa993b | 5645 | int |
fba45db2 | 5646 | bpstat_should_step (void) |
c906108c SS |
5647 | { |
5648 | struct breakpoint *b; | |
cc59ec59 | 5649 | |
c906108c | 5650 | ALL_BREAKPOINTS (b) |
717a8278 | 5651 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5652 | return 1; |
c906108c SS |
5653 | return 0; |
5654 | } | |
5655 | ||
67822962 PA |
5656 | int |
5657 | bpstat_causes_stop (bpstat bs) | |
5658 | { | |
5659 | for (; bs != NULL; bs = bs->next) | |
5660 | if (bs->stop) | |
5661 | return 1; | |
5662 | ||
5663 | return 0; | |
5664 | } | |
5665 | ||
c906108c | 5666 | \f |
c5aa993b | 5667 | |
170b53b2 UW |
5668 | /* Compute a string of spaces suitable to indent the next line |
5669 | so it starts at the position corresponding to the table column | |
5670 | named COL_NAME in the currently active table of UIOUT. */ | |
5671 | ||
5672 | static char * | |
5673 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5674 | { | |
5675 | static char wrap_indent[80]; | |
5676 | int i, total_width, width, align; | |
5677 | char *text; | |
5678 | ||
5679 | total_width = 0; | |
5680 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5681 | { | |
5682 | if (strcmp (text, col_name) == 0) | |
5683 | { | |
5684 | gdb_assert (total_width < sizeof wrap_indent); | |
5685 | memset (wrap_indent, ' ', total_width); | |
5686 | wrap_indent[total_width] = 0; | |
5687 | ||
5688 | return wrap_indent; | |
5689 | } | |
5690 | ||
5691 | total_width += width + 1; | |
5692 | } | |
5693 | ||
5694 | return NULL; | |
5695 | } | |
5696 | ||
b775012e LM |
5697 | /* Determine if the locations of this breakpoint will have their conditions |
5698 | evaluated by the target, host or a mix of both. Returns the following: | |
5699 | ||
5700 | "host": Host evals condition. | |
5701 | "host or target": Host or Target evals condition. | |
5702 | "target": Target evals condition. | |
5703 | */ | |
5704 | ||
5705 | static const char * | |
5706 | bp_condition_evaluator (struct breakpoint *b) | |
5707 | { | |
5708 | struct bp_location *bl; | |
5709 | char host_evals = 0; | |
5710 | char target_evals = 0; | |
5711 | ||
5712 | if (!b) | |
5713 | return NULL; | |
5714 | ||
5715 | if (!is_breakpoint (b)) | |
5716 | return NULL; | |
5717 | ||
5718 | if (gdb_evaluates_breakpoint_condition_p () | |
5719 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5720 | return condition_evaluation_host; | |
5721 | ||
5722 | for (bl = b->loc; bl; bl = bl->next) | |
5723 | { | |
5724 | if (bl->cond_bytecode) | |
5725 | target_evals++; | |
5726 | else | |
5727 | host_evals++; | |
5728 | } | |
5729 | ||
5730 | if (host_evals && target_evals) | |
5731 | return condition_evaluation_both; | |
5732 | else if (target_evals) | |
5733 | return condition_evaluation_target; | |
5734 | else | |
5735 | return condition_evaluation_host; | |
5736 | } | |
5737 | ||
5738 | /* Determine the breakpoint location's condition evaluator. This is | |
5739 | similar to bp_condition_evaluator, but for locations. */ | |
5740 | ||
5741 | static const char * | |
5742 | bp_location_condition_evaluator (struct bp_location *bl) | |
5743 | { | |
5744 | if (bl && !is_breakpoint (bl->owner)) | |
5745 | return NULL; | |
5746 | ||
5747 | if (gdb_evaluates_breakpoint_condition_p () | |
5748 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5749 | return condition_evaluation_host; | |
5750 | ||
5751 | if (bl && bl->cond_bytecode) | |
5752 | return condition_evaluation_target; | |
5753 | else | |
5754 | return condition_evaluation_host; | |
5755 | } | |
5756 | ||
859825b8 JK |
5757 | /* Print the LOC location out of the list of B->LOC locations. */ |
5758 | ||
170b53b2 UW |
5759 | static void |
5760 | print_breakpoint_location (struct breakpoint *b, | |
5761 | struct bp_location *loc) | |
0d381245 | 5762 | { |
79a45e25 | 5763 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5764 | struct cleanup *old_chain = save_current_program_space (); |
5765 | ||
859825b8 JK |
5766 | if (loc != NULL && loc->shlib_disabled) |
5767 | loc = NULL; | |
5768 | ||
6c95b8df PA |
5769 | if (loc != NULL) |
5770 | set_current_program_space (loc->pspace); | |
5771 | ||
56435ebe TT |
5772 | if (b->display_canonical) |
5773 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5774 | else if (loc && loc->symtab) |
0d381245 VP |
5775 | { |
5776 | struct symbol *sym | |
5777 | = find_pc_sect_function (loc->address, loc->section); | |
5778 | if (sym) | |
5779 | { | |
5780 | ui_out_text (uiout, "in "); | |
5781 | ui_out_field_string (uiout, "func", | |
5782 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5783 | ui_out_text (uiout, " "); |
5784 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5785 | ui_out_text (uiout, "at "); | |
0d381245 | 5786 | } |
05cba821 JK |
5787 | ui_out_field_string (uiout, "file", |
5788 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5789 | ui_out_text (uiout, ":"); |
05cba821 | 5790 | |
0d381245 | 5791 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5792 | ui_out_field_string (uiout, "fullname", |
5793 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5794 | |
f8eba3c6 | 5795 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5796 | } |
859825b8 | 5797 | else if (loc) |
0d381245 | 5798 | { |
f99d8bf4 PA |
5799 | struct ui_file *stb = mem_fileopen (); |
5800 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5801 | |
f99d8bf4 | 5802 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5803 | demangle, ""); |
0d381245 | 5804 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5805 | |
5806 | do_cleanups (stb_chain); | |
0d381245 | 5807 | } |
859825b8 JK |
5808 | else |
5809 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5810 | |
b775012e LM |
5811 | if (loc && is_breakpoint (b) |
5812 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5813 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5814 | { | |
5815 | ui_out_text (uiout, " ("); | |
5816 | ui_out_field_string (uiout, "evaluated-by", | |
5817 | bp_location_condition_evaluator (loc)); | |
5818 | ui_out_text (uiout, ")"); | |
5819 | } | |
5820 | ||
6c95b8df | 5821 | do_cleanups (old_chain); |
0d381245 VP |
5822 | } |
5823 | ||
269b11a2 PA |
5824 | static const char * |
5825 | bptype_string (enum bptype type) | |
c906108c | 5826 | { |
c4093a6a JM |
5827 | struct ep_type_description |
5828 | { | |
5829 | enum bptype type; | |
5830 | char *description; | |
5831 | }; | |
5832 | static struct ep_type_description bptypes[] = | |
c906108c | 5833 | { |
c5aa993b JM |
5834 | {bp_none, "?deleted?"}, |
5835 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5836 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5837 | {bp_until, "until"}, |
5838 | {bp_finish, "finish"}, | |
5839 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5840 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5841 | {bp_read_watchpoint, "read watchpoint"}, |
5842 | {bp_access_watchpoint, "acc watchpoint"}, | |
5843 | {bp_longjmp, "longjmp"}, | |
5844 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5845 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5846 | {bp_exception, "exception"}, |
5847 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5848 | {bp_step_resume, "step resume"}, |
2c03e5be | 5849 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5850 | {bp_watchpoint_scope, "watchpoint scope"}, |
5851 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5852 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5853 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5854 | {bp_thread_event, "thread events"}, |
1900040c | 5855 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5856 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5857 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5858 | {bp_exception_master, "exception master"}, |
ce78b96d | 5859 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5860 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5861 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5862 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5863 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5864 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5865 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5866 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5867 | }; |
269b11a2 PA |
5868 | |
5869 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5870 | || ((int) type != bptypes[(int) type].type)) | |
5871 | internal_error (__FILE__, __LINE__, | |
5872 | _("bptypes table does not describe type #%d."), | |
5873 | (int) type); | |
5874 | ||
5875 | return bptypes[(int) type].description; | |
5876 | } | |
5877 | ||
998580f1 MK |
5878 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5879 | For CLI, prefix the list with the string 'inf'. */ | |
5880 | ||
5881 | static void | |
5882 | output_thread_groups (struct ui_out *uiout, | |
5883 | const char *field_name, | |
5884 | VEC(int) *inf_num, | |
5885 | int mi_only) | |
5886 | { | |
752eb8b4 | 5887 | struct cleanup *back_to; |
998580f1 MK |
5888 | int is_mi = ui_out_is_mi_like_p (uiout); |
5889 | int inf; | |
5890 | int i; | |
5891 | ||
5892 | /* For backward compatibility, don't display inferiors in CLI unless | |
5893 | there are several. Always display them for MI. */ | |
5894 | if (!is_mi && mi_only) | |
5895 | return; | |
5896 | ||
752eb8b4 TT |
5897 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
5898 | ||
998580f1 MK |
5899 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
5900 | { | |
5901 | if (is_mi) | |
5902 | { | |
5903 | char mi_group[10]; | |
5904 | ||
5905 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5906 | ui_out_field_string (uiout, NULL, mi_group); | |
5907 | } | |
5908 | else | |
5909 | { | |
5910 | if (i == 0) | |
5911 | ui_out_text (uiout, " inf "); | |
5912 | else | |
5913 | ui_out_text (uiout, ", "); | |
5914 | ||
5915 | ui_out_text (uiout, plongest (inf)); | |
5916 | } | |
5917 | } | |
5918 | ||
5919 | do_cleanups (back_to); | |
5920 | } | |
5921 | ||
269b11a2 PA |
5922 | /* Print B to gdb_stdout. */ |
5923 | ||
5924 | static void | |
5925 | print_one_breakpoint_location (struct breakpoint *b, | |
5926 | struct bp_location *loc, | |
5927 | int loc_number, | |
5928 | struct bp_location **last_loc, | |
269b11a2 PA |
5929 | int allflag) |
5930 | { | |
5931 | struct command_line *l; | |
c2c6d25f | 5932 | static char bpenables[] = "nynny"; |
c906108c | 5933 | |
79a45e25 | 5934 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5935 | int header_of_multiple = 0; |
5936 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5937 | struct value_print_options opts; |
5938 | ||
5939 | get_user_print_options (&opts); | |
0d381245 VP |
5940 | |
5941 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5942 | /* See comment in print_one_breakpoint concerning treatment of |
5943 | breakpoints with single disabled location. */ | |
0d381245 VP |
5944 | if (loc == NULL |
5945 | && (b->loc != NULL | |
5946 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5947 | header_of_multiple = 1; | |
5948 | if (loc == NULL) | |
5949 | loc = b->loc; | |
5950 | ||
c4093a6a JM |
5951 | annotate_record (); |
5952 | ||
5953 | /* 1 */ | |
5954 | annotate_field (0); | |
0d381245 VP |
5955 | if (part_of_multiple) |
5956 | { | |
5957 | char *formatted; | |
0c6773c1 | 5958 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
5959 | ui_out_field_string (uiout, "number", formatted); |
5960 | xfree (formatted); | |
5961 | } | |
5962 | else | |
5963 | { | |
5964 | ui_out_field_int (uiout, "number", b->number); | |
5965 | } | |
c4093a6a JM |
5966 | |
5967 | /* 2 */ | |
5968 | annotate_field (1); | |
0d381245 VP |
5969 | if (part_of_multiple) |
5970 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
5971 | else |
5972 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
5973 | |
5974 | /* 3 */ | |
5975 | annotate_field (2); | |
0d381245 VP |
5976 | if (part_of_multiple) |
5977 | ui_out_field_skip (uiout, "disp"); | |
5978 | else | |
2cec12e5 | 5979 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 5980 | |
c4093a6a JM |
5981 | |
5982 | /* 4 */ | |
5983 | annotate_field (3); | |
0d381245 | 5984 | if (part_of_multiple) |
54e52265 | 5985 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 5986 | else |
4a64f543 MS |
5987 | ui_out_field_fmt (uiout, "enabled", "%c", |
5988 | bpenables[(int) b->enable_state]); | |
54e52265 | 5989 | ui_out_spaces (uiout, 2); |
0d381245 | 5990 | |
c4093a6a JM |
5991 | |
5992 | /* 5 and 6 */ | |
3086aeae | 5993 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 5994 | { |
4a64f543 MS |
5995 | /* Although the print_one can possibly print all locations, |
5996 | calling it here is not likely to get any nice result. So, | |
5997 | make sure there's just one location. */ | |
0d381245 | 5998 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 5999 | b->ops->print_one (b, last_loc); |
0d381245 | 6000 | } |
3086aeae DJ |
6001 | else |
6002 | switch (b->type) | |
6003 | { | |
6004 | case bp_none: | |
6005 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6006 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6007 | break; |
c906108c | 6008 | |
3086aeae DJ |
6009 | case bp_watchpoint: |
6010 | case bp_hardware_watchpoint: | |
6011 | case bp_read_watchpoint: | |
6012 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6013 | { |
6014 | struct watchpoint *w = (struct watchpoint *) b; | |
6015 | ||
6016 | /* Field 4, the address, is omitted (which makes the columns | |
6017 | not line up too nicely with the headers, but the effect | |
6018 | is relatively readable). */ | |
6019 | if (opts.addressprint) | |
6020 | ui_out_field_skip (uiout, "addr"); | |
6021 | annotate_field (5); | |
6022 | ui_out_field_string (uiout, "what", w->exp_string); | |
6023 | } | |
3086aeae DJ |
6024 | break; |
6025 | ||
3086aeae DJ |
6026 | case bp_breakpoint: |
6027 | case bp_hardware_breakpoint: | |
6028 | case bp_until: | |
6029 | case bp_finish: | |
6030 | case bp_longjmp: | |
6031 | case bp_longjmp_resume: | |
e2e4d78b | 6032 | case bp_longjmp_call_dummy: |
186c406b TT |
6033 | case bp_exception: |
6034 | case bp_exception_resume: | |
3086aeae | 6035 | case bp_step_resume: |
2c03e5be | 6036 | case bp_hp_step_resume: |
3086aeae DJ |
6037 | case bp_watchpoint_scope: |
6038 | case bp_call_dummy: | |
aa7d318d | 6039 | case bp_std_terminate: |
3086aeae DJ |
6040 | case bp_shlib_event: |
6041 | case bp_thread_event: | |
6042 | case bp_overlay_event: | |
0fd8e87f | 6043 | case bp_longjmp_master: |
aa7d318d | 6044 | case bp_std_terminate_master: |
186c406b | 6045 | case bp_exception_master: |
1042e4c0 | 6046 | case bp_tracepoint: |
7a697b8d | 6047 | case bp_fast_tracepoint: |
0fb4aa4b | 6048 | case bp_static_tracepoint: |
e7e0cddf | 6049 | case bp_dprintf: |
4efc6507 | 6050 | case bp_jit_event: |
0e30163f JK |
6051 | case bp_gnu_ifunc_resolver: |
6052 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6053 | if (opts.addressprint) |
3086aeae DJ |
6054 | { |
6055 | annotate_field (4); | |
54e52265 | 6056 | if (header_of_multiple) |
0d381245 | 6057 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6058 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6059 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6060 | else |
5af949e3 UW |
6061 | ui_out_field_core_addr (uiout, "addr", |
6062 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6063 | } |
6064 | annotate_field (5); | |
0d381245 | 6065 | if (!header_of_multiple) |
170b53b2 | 6066 | print_breakpoint_location (b, loc); |
0d381245 | 6067 | if (b->loc) |
a6d9a66e | 6068 | *last_loc = b->loc; |
3086aeae DJ |
6069 | break; |
6070 | } | |
c906108c | 6071 | |
6c95b8df | 6072 | |
998580f1 | 6073 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6074 | { |
6075 | struct inferior *inf; | |
998580f1 MK |
6076 | VEC(int) *inf_num = NULL; |
6077 | int mi_only = 1; | |
6c95b8df | 6078 | |
998580f1 | 6079 | ALL_INFERIORS (inf) |
6c95b8df PA |
6080 | { |
6081 | if (inf->pspace == loc->pspace) | |
998580f1 | 6082 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6083 | } |
998580f1 MK |
6084 | |
6085 | /* For backward compatibility, don't display inferiors in CLI unless | |
6086 | there are several. Always display for MI. */ | |
6087 | if (allflag | |
6088 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6089 | && (number_of_program_spaces () > 1 | |
6090 | || number_of_inferiors () > 1) | |
6091 | /* LOC is for existing B, it cannot be in | |
6092 | moribund_locations and thus having NULL OWNER. */ | |
6093 | && loc->owner->type != bp_catchpoint)) | |
6094 | mi_only = 0; | |
6095 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6096 | VEC_free (int, inf_num); | |
6c95b8df PA |
6097 | } |
6098 | ||
4a306c9a | 6099 | if (!part_of_multiple) |
c4093a6a | 6100 | { |
4a306c9a JB |
6101 | if (b->thread != -1) |
6102 | { | |
6103 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6104 | "stop only in" line a little further down. */ |
4a306c9a JB |
6105 | ui_out_text (uiout, " thread "); |
6106 | ui_out_field_int (uiout, "thread", b->thread); | |
6107 | } | |
6108 | else if (b->task != 0) | |
6109 | { | |
6110 | ui_out_text (uiout, " task "); | |
6111 | ui_out_field_int (uiout, "task", b->task); | |
6112 | } | |
c4093a6a | 6113 | } |
f1310107 | 6114 | |
8b93c638 | 6115 | ui_out_text (uiout, "\n"); |
f1310107 | 6116 | |
348d480f | 6117 | if (!part_of_multiple) |
f1310107 TJB |
6118 | b->ops->print_one_detail (b, uiout); |
6119 | ||
0d381245 | 6120 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6121 | { |
6122 | annotate_field (6); | |
8b93c638 | 6123 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6124 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6125 | the frame ID. */ |
5af949e3 UW |
6126 | ui_out_field_core_addr (uiout, "frame", |
6127 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6128 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6129 | } |
6130 | ||
28010a5d | 6131 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6132 | { |
6133 | annotate_field (7); | |
d77f58be | 6134 | if (is_tracepoint (b)) |
1042e4c0 SS |
6135 | ui_out_text (uiout, "\ttrace only if "); |
6136 | else | |
6137 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6138 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6139 | |
6140 | /* Print whether the target is doing the breakpoint's condition | |
6141 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6142 | if (is_breakpoint (b) | |
6143 | && breakpoint_condition_evaluation_mode () | |
6144 | == condition_evaluation_target) | |
6145 | { | |
6146 | ui_out_text (uiout, " ("); | |
6147 | ui_out_field_string (uiout, "evaluated-by", | |
6148 | bp_condition_evaluator (b)); | |
6149 | ui_out_text (uiout, " evals)"); | |
6150 | } | |
0101ce28 JJ |
6151 | ui_out_text (uiout, "\n"); |
6152 | } | |
6153 | ||
0d381245 | 6154 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6155 | { |
4a64f543 | 6156 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6157 | ui_out_text (uiout, "\tstop only in thread "); |
6158 | ui_out_field_int (uiout, "thread", b->thread); | |
6159 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6160 | } |
6161 | ||
556ec64d YQ |
6162 | if (!part_of_multiple) |
6163 | { | |
6164 | if (b->hit_count) | |
31f56a27 YQ |
6165 | { |
6166 | /* FIXME should make an annotation for this. */ | |
6167 | if (is_catchpoint (b)) | |
6168 | ui_out_text (uiout, "\tcatchpoint"); | |
6169 | else if (is_tracepoint (b)) | |
6170 | ui_out_text (uiout, "\ttracepoint"); | |
6171 | else | |
6172 | ui_out_text (uiout, "\tbreakpoint"); | |
6173 | ui_out_text (uiout, " already hit "); | |
6174 | ui_out_field_int (uiout, "times", b->hit_count); | |
6175 | if (b->hit_count == 1) | |
6176 | ui_out_text (uiout, " time\n"); | |
6177 | else | |
6178 | ui_out_text (uiout, " times\n"); | |
6179 | } | |
556ec64d YQ |
6180 | else |
6181 | { | |
31f56a27 YQ |
6182 | /* Output the count also if it is zero, but only if this is mi. */ |
6183 | if (ui_out_is_mi_like_p (uiout)) | |
6184 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6185 | } |
6186 | } | |
8b93c638 | 6187 | |
0d381245 | 6188 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6189 | { |
6190 | annotate_field (8); | |
8b93c638 JM |
6191 | ui_out_text (uiout, "\tignore next "); |
6192 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6193 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6194 | } |
059fb39f | 6195 | |
816338b5 SS |
6196 | /* Note that an enable count of 1 corresponds to "enable once" |
6197 | behavior, which is reported by the combination of enablement and | |
6198 | disposition, so we don't need to mention it here. */ | |
6199 | if (!part_of_multiple && b->enable_count > 1) | |
6200 | { | |
6201 | annotate_field (8); | |
6202 | ui_out_text (uiout, "\tdisable after "); | |
6203 | /* Tweak the wording to clarify that ignore and enable counts | |
6204 | are distinct, and have additive effect. */ | |
6205 | if (b->ignore_count) | |
6206 | ui_out_text (uiout, "additional "); | |
6207 | else | |
6208 | ui_out_text (uiout, "next "); | |
6209 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6210 | ui_out_text (uiout, " hits\n"); | |
6211 | } | |
6212 | ||
f196051f SS |
6213 | if (!part_of_multiple && is_tracepoint (b)) |
6214 | { | |
6215 | struct tracepoint *tp = (struct tracepoint *) b; | |
6216 | ||
6217 | if (tp->traceframe_usage) | |
6218 | { | |
6219 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6220 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6221 | ui_out_text (uiout, " bytes\n"); | |
6222 | } | |
6223 | } | |
d3ce09f5 | 6224 | |
9add0f1b | 6225 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6226 | if (!part_of_multiple && l) |
c4093a6a | 6227 | { |
3b31d625 EZ |
6228 | struct cleanup *script_chain; |
6229 | ||
c4093a6a | 6230 | annotate_field (9); |
3b31d625 | 6231 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6232 | print_command_lines (uiout, l, 4); |
3b31d625 | 6233 | do_cleanups (script_chain); |
c4093a6a | 6234 | } |
d24317b4 | 6235 | |
d9b3f62e | 6236 | if (is_tracepoint (b)) |
1042e4c0 | 6237 | { |
d9b3f62e PA |
6238 | struct tracepoint *t = (struct tracepoint *) b; |
6239 | ||
6240 | if (!part_of_multiple && t->pass_count) | |
6241 | { | |
6242 | annotate_field (10); | |
6243 | ui_out_text (uiout, "\tpass count "); | |
6244 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6245 | ui_out_text (uiout, " \n"); | |
6246 | } | |
f2a8bc8a YQ |
6247 | |
6248 | /* Don't display it when tracepoint or tracepoint location is | |
6249 | pending. */ | |
6250 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6251 | { | |
6252 | annotate_field (11); | |
6253 | ||
6254 | if (ui_out_is_mi_like_p (uiout)) | |
6255 | ui_out_field_string (uiout, "installed", | |
6256 | loc->inserted ? "y" : "n"); | |
6257 | else | |
6258 | { | |
6259 | if (loc->inserted) | |
6260 | ui_out_text (uiout, "\t"); | |
6261 | else | |
6262 | ui_out_text (uiout, "\tnot "); | |
6263 | ui_out_text (uiout, "installed on target\n"); | |
6264 | } | |
6265 | } | |
1042e4c0 SS |
6266 | } |
6267 | ||
d24317b4 VP |
6268 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6269 | { | |
3a5c3e22 PA |
6270 | if (is_watchpoint (b)) |
6271 | { | |
6272 | struct watchpoint *w = (struct watchpoint *) b; | |
6273 | ||
6274 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6275 | } | |
6276 | else if (b->addr_string) | |
d24317b4 | 6277 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6278 | } |
c4093a6a | 6279 | } |
c5aa993b | 6280 | |
0d381245 VP |
6281 | static void |
6282 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6283 | struct bp_location **last_loc, |
6c95b8df | 6284 | int allflag) |
0d381245 | 6285 | { |
8d3788bd | 6286 | struct cleanup *bkpt_chain; |
79a45e25 | 6287 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6288 | |
6289 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6290 | ||
12c5a436 | 6291 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6292 | do_cleanups (bkpt_chain); |
0d381245 VP |
6293 | |
6294 | /* If this breakpoint has custom print function, | |
6295 | it's already printed. Otherwise, print individual | |
6296 | locations, if any. */ | |
6297 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6298 | { | |
4a64f543 MS |
6299 | /* If breakpoint has a single location that is disabled, we |
6300 | print it as if it had several locations, since otherwise it's | |
6301 | hard to represent "breakpoint enabled, location disabled" | |
6302 | situation. | |
6303 | ||
6304 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6305 | internally, that's not a property exposed to user. */ |
0d381245 | 6306 | if (b->loc |
a5606eee | 6307 | && !is_hardware_watchpoint (b) |
8d3788bd | 6308 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6309 | { |
6310 | struct bp_location *loc; | |
6311 | int n = 1; | |
8d3788bd | 6312 | |
0d381245 | 6313 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6314 | { |
6315 | struct cleanup *inner2 = | |
6316 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6317 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6318 | do_cleanups (inner2); | |
6319 | } | |
0d381245 VP |
6320 | } |
6321 | } | |
6322 | } | |
6323 | ||
a6d9a66e UW |
6324 | static int |
6325 | breakpoint_address_bits (struct breakpoint *b) | |
6326 | { | |
6327 | int print_address_bits = 0; | |
6328 | struct bp_location *loc; | |
6329 | ||
6330 | for (loc = b->loc; loc; loc = loc->next) | |
6331 | { | |
c7437ca6 PA |
6332 | int addr_bit; |
6333 | ||
6334 | /* Software watchpoints that aren't watching memory don't have | |
6335 | an address to print. */ | |
6336 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6337 | continue; | |
6338 | ||
6339 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6340 | if (addr_bit > print_address_bits) |
6341 | print_address_bits = addr_bit; | |
6342 | } | |
6343 | ||
6344 | return print_address_bits; | |
6345 | } | |
0d381245 | 6346 | |
c4093a6a JM |
6347 | struct captured_breakpoint_query_args |
6348 | { | |
6349 | int bnum; | |
6350 | }; | |
c5aa993b | 6351 | |
c4093a6a | 6352 | static int |
2b65245e | 6353 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6354 | { |
6355 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6356 | struct breakpoint *b; |
a6d9a66e | 6357 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6358 | |
c4093a6a JM |
6359 | ALL_BREAKPOINTS (b) |
6360 | { | |
6361 | if (args->bnum == b->number) | |
c5aa993b | 6362 | { |
12c5a436 | 6363 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6364 | return GDB_RC_OK; |
c5aa993b | 6365 | } |
c4093a6a JM |
6366 | } |
6367 | return GDB_RC_NONE; | |
6368 | } | |
c5aa993b | 6369 | |
c4093a6a | 6370 | enum gdb_rc |
4a64f543 MS |
6371 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6372 | char **error_message) | |
c4093a6a JM |
6373 | { |
6374 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6375 | |
c4093a6a JM |
6376 | args.bnum = bnum; |
6377 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6378 | an error. */ |
b0b13bb4 DJ |
6379 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6380 | error_message, RETURN_MASK_ALL) < 0) | |
6381 | return GDB_RC_FAIL; | |
6382 | else | |
6383 | return GDB_RC_OK; | |
c4093a6a | 6384 | } |
c5aa993b | 6385 | |
09d682a4 TT |
6386 | /* Return true if this breakpoint was set by the user, false if it is |
6387 | internal or momentary. */ | |
6388 | ||
6389 | int | |
6390 | user_breakpoint_p (struct breakpoint *b) | |
6391 | { | |
46c6471b | 6392 | return b->number > 0; |
09d682a4 TT |
6393 | } |
6394 | ||
7f3b0473 | 6395 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6396 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6397 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6398 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6399 | ones for which it returns non-zero. Return the total number of | |
6400 | breakpoints listed. */ | |
c906108c | 6401 | |
d77f58be | 6402 | static int |
e5a67952 | 6403 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6404 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6405 | { |
52f0bd74 | 6406 | struct breakpoint *b; |
a6d9a66e | 6407 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6408 | int nr_printable_breakpoints; |
3b31d625 | 6409 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6410 | struct value_print_options opts; |
a6d9a66e | 6411 | int print_address_bits = 0; |
269b11a2 | 6412 | int print_type_col_width = 14; |
79a45e25 | 6413 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6414 | |
79a45b7d TT |
6415 | get_user_print_options (&opts); |
6416 | ||
4a64f543 MS |
6417 | /* Compute the number of rows in the table, as well as the size |
6418 | required for address fields. */ | |
7f3b0473 AC |
6419 | nr_printable_breakpoints = 0; |
6420 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6421 | { |
6422 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6423 | if (filter && !filter (b)) | |
6424 | continue; | |
6425 | ||
6426 | /* If we have an "args" string, it is a list of breakpoints to | |
6427 | accept. Skip the others. */ | |
6428 | if (args != NULL && *args != '\0') | |
6429 | { | |
6430 | if (allflag && parse_and_eval_long (args) != b->number) | |
6431 | continue; | |
6432 | if (!allflag && !number_is_in_list (args, b->number)) | |
6433 | continue; | |
6434 | } | |
269b11a2 | 6435 | |
e5a67952 MS |
6436 | if (allflag || user_breakpoint_p (b)) |
6437 | { | |
6438 | int addr_bit, type_len; | |
a6d9a66e | 6439 | |
e5a67952 MS |
6440 | addr_bit = breakpoint_address_bits (b); |
6441 | if (addr_bit > print_address_bits) | |
6442 | print_address_bits = addr_bit; | |
269b11a2 | 6443 | |
e5a67952 MS |
6444 | type_len = strlen (bptype_string (b->type)); |
6445 | if (type_len > print_type_col_width) | |
6446 | print_type_col_width = type_len; | |
6447 | ||
6448 | nr_printable_breakpoints++; | |
6449 | } | |
6450 | } | |
7f3b0473 | 6451 | |
79a45b7d | 6452 | if (opts.addressprint) |
3b31d625 | 6453 | bkpttbl_chain |
3e43a32a MS |
6454 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6455 | nr_printable_breakpoints, | |
3b31d625 | 6456 | "BreakpointTable"); |
8b93c638 | 6457 | else |
3b31d625 | 6458 | bkpttbl_chain |
3e43a32a MS |
6459 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6460 | nr_printable_breakpoints, | |
3b31d625 | 6461 | "BreakpointTable"); |
8b93c638 | 6462 | |
7f3b0473 | 6463 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6464 | annotate_breakpoints_headers (); |
6465 | if (nr_printable_breakpoints > 0) | |
6466 | annotate_field (0); | |
4a64f543 | 6467 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6468 | if (nr_printable_breakpoints > 0) |
6469 | annotate_field (1); | |
269b11a2 | 6470 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6471 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6472 | if (nr_printable_breakpoints > 0) |
6473 | annotate_field (2); | |
4a64f543 | 6474 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6475 | if (nr_printable_breakpoints > 0) |
6476 | annotate_field (3); | |
54e52265 | 6477 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6478 | if (opts.addressprint) |
e5a67952 MS |
6479 | { |
6480 | if (nr_printable_breakpoints > 0) | |
6481 | annotate_field (4); | |
6482 | if (print_address_bits <= 32) | |
6483 | ui_out_table_header (uiout, 10, ui_left, | |
6484 | "addr", "Address"); /* 5 */ | |
6485 | else | |
6486 | ui_out_table_header (uiout, 18, ui_left, | |
6487 | "addr", "Address"); /* 5 */ | |
6488 | } | |
d7faa9e7 AC |
6489 | if (nr_printable_breakpoints > 0) |
6490 | annotate_field (5); | |
6491 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6492 | ui_out_table_body (uiout); | |
6493 | if (nr_printable_breakpoints > 0) | |
6494 | annotate_breakpoints_table (); | |
7f3b0473 | 6495 | |
c4093a6a | 6496 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6497 | { |
6498 | QUIT; | |
6499 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6500 | if (filter && !filter (b)) | |
6501 | continue; | |
6502 | ||
6503 | /* If we have an "args" string, it is a list of breakpoints to | |
6504 | accept. Skip the others. */ | |
6505 | ||
6506 | if (args != NULL && *args != '\0') | |
6507 | { | |
6508 | if (allflag) /* maintenance info breakpoint */ | |
6509 | { | |
6510 | if (parse_and_eval_long (args) != b->number) | |
6511 | continue; | |
6512 | } | |
6513 | else /* all others */ | |
6514 | { | |
6515 | if (!number_is_in_list (args, b->number)) | |
6516 | continue; | |
6517 | } | |
6518 | } | |
6519 | /* We only print out user settable breakpoints unless the | |
6520 | allflag is set. */ | |
6521 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6522 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6523 | } |
6524 | ||
3b31d625 | 6525 | do_cleanups (bkpttbl_chain); |
698384cd | 6526 | |
7f3b0473 | 6527 | if (nr_printable_breakpoints == 0) |
c906108c | 6528 | { |
4a64f543 MS |
6529 | /* If there's a filter, let the caller decide how to report |
6530 | empty list. */ | |
d77f58be SS |
6531 | if (!filter) |
6532 | { | |
e5a67952 | 6533 | if (args == NULL || *args == '\0') |
d77f58be SS |
6534 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6535 | else | |
4a64f543 | 6536 | ui_out_message (uiout, 0, |
e5a67952 MS |
6537 | "No breakpoint or watchpoint matching '%s'.\n", |
6538 | args); | |
d77f58be | 6539 | } |
c906108c SS |
6540 | } |
6541 | else | |
c4093a6a | 6542 | { |
a6d9a66e UW |
6543 | if (last_loc && !server_command) |
6544 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6545 | } |
c906108c | 6546 | |
4a64f543 | 6547 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6548 | there have been breakpoints? */ |
c906108c | 6549 | annotate_breakpoints_table_end (); |
d77f58be SS |
6550 | |
6551 | return nr_printable_breakpoints; | |
c906108c SS |
6552 | } |
6553 | ||
ad443146 SS |
6554 | /* Display the value of default-collect in a way that is generally |
6555 | compatible with the breakpoint list. */ | |
6556 | ||
6557 | static void | |
6558 | default_collect_info (void) | |
6559 | { | |
79a45e25 PA |
6560 | struct ui_out *uiout = current_uiout; |
6561 | ||
ad443146 SS |
6562 | /* If it has no value (which is frequently the case), say nothing; a |
6563 | message like "No default-collect." gets in user's face when it's | |
6564 | not wanted. */ | |
6565 | if (!*default_collect) | |
6566 | return; | |
6567 | ||
6568 | /* The following phrase lines up nicely with per-tracepoint collect | |
6569 | actions. */ | |
6570 | ui_out_text (uiout, "default collect "); | |
6571 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6572 | ui_out_text (uiout, " \n"); | |
6573 | } | |
6574 | ||
c906108c | 6575 | static void |
e5a67952 | 6576 | breakpoints_info (char *args, int from_tty) |
c906108c | 6577 | { |
e5a67952 | 6578 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6579 | |
6580 | default_collect_info (); | |
d77f58be SS |
6581 | } |
6582 | ||
6583 | static void | |
e5a67952 | 6584 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6585 | { |
e5a67952 | 6586 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6587 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6588 | |
6589 | if (num_printed == 0) | |
6590 | { | |
e5a67952 | 6591 | if (args == NULL || *args == '\0') |
d77f58be SS |
6592 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6593 | else | |
e5a67952 | 6594 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6595 | } |
c906108c SS |
6596 | } |
6597 | ||
7a292a7a | 6598 | static void |
e5a67952 | 6599 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6600 | { |
e5a67952 | 6601 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6602 | |
6603 | default_collect_info (); | |
c906108c SS |
6604 | } |
6605 | ||
0d381245 | 6606 | static int |
714835d5 | 6607 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6608 | struct program_space *pspace, |
714835d5 | 6609 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6610 | { |
6611 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6612 | |
0d381245 VP |
6613 | for (; bl; bl = bl->next) |
6614 | { | |
6c95b8df PA |
6615 | if (bl->pspace == pspace |
6616 | && bl->address == pc | |
0d381245 VP |
6617 | && (!overlay_debugging || bl->section == section)) |
6618 | return 1; | |
6619 | } | |
6620 | return 0; | |
6621 | } | |
6622 | ||
672f9b60 | 6623 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6624 | concerns with logical breakpoints, so we match program spaces, not |
6625 | address spaces. */ | |
c906108c SS |
6626 | |
6627 | static void | |
6c95b8df PA |
6628 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6629 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6630 | struct obj_section *section, int thread) |
c906108c | 6631 | { |
52f0bd74 AC |
6632 | int others = 0; |
6633 | struct breakpoint *b; | |
c906108c SS |
6634 | |
6635 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6636 | others += (user_breakpoint_p (b) |
6637 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6638 | if (others > 0) |
6639 | { | |
a3f17187 AC |
6640 | if (others == 1) |
6641 | printf_filtered (_("Note: breakpoint ")); | |
6642 | else /* if (others == ???) */ | |
6643 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6644 | ALL_BREAKPOINTS (b) |
672f9b60 | 6645 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6646 | { |
6647 | others--; | |
6648 | printf_filtered ("%d", b->number); | |
6649 | if (b->thread == -1 && thread != -1) | |
6650 | printf_filtered (" (all threads)"); | |
6651 | else if (b->thread != -1) | |
6652 | printf_filtered (" (thread %d)", b->thread); | |
6653 | printf_filtered ("%s%s ", | |
059fb39f | 6654 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6655 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6656 | ? " (disabled)" |
6657 | : b->enable_state == bp_permanent | |
6658 | ? " (permanent)" | |
6659 | : ""), | |
6660 | (others > 1) ? "," | |
6661 | : ((others == 1) ? " and" : "")); | |
6662 | } | |
a3f17187 | 6663 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6664 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6665 | printf_filtered (".\n"); |
6666 | } | |
6667 | } | |
6668 | \f | |
c906108c | 6669 | |
e4f237da KB |
6670 | /* Return true iff it is meaningful to use the address member of |
6671 | BPT. For some breakpoint types, the address member is irrelevant | |
6672 | and it makes no sense to attempt to compare it to other addresses | |
6673 | (or use it for any other purpose either). | |
6674 | ||
4a64f543 MS |
6675 | More specifically, each of the following breakpoint types will |
6676 | always have a zero valued address and we don't want to mark | |
6677 | breakpoints of any of these types to be a duplicate of an actual | |
6678 | breakpoint at address zero: | |
e4f237da KB |
6679 | |
6680 | bp_watchpoint | |
2d134ed3 PA |
6681 | bp_catchpoint |
6682 | ||
6683 | */ | |
e4f237da KB |
6684 | |
6685 | static int | |
6686 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6687 | { | |
6688 | enum bptype type = bpt->type; | |
6689 | ||
2d134ed3 PA |
6690 | return (type != bp_watchpoint && type != bp_catchpoint); |
6691 | } | |
6692 | ||
6693 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6694 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6695 | ||
6696 | static int | |
4a64f543 MS |
6697 | watchpoint_locations_match (struct bp_location *loc1, |
6698 | struct bp_location *loc2) | |
2d134ed3 | 6699 | { |
3a5c3e22 PA |
6700 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6701 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6702 | ||
6703 | /* Both of them must exist. */ | |
6704 | gdb_assert (w1 != NULL); | |
6705 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6706 | |
4a64f543 MS |
6707 | /* If the target can evaluate the condition expression in hardware, |
6708 | then we we need to insert both watchpoints even if they are at | |
6709 | the same place. Otherwise the watchpoint will only trigger when | |
6710 | the condition of whichever watchpoint was inserted evaluates to | |
6711 | true, not giving a chance for GDB to check the condition of the | |
6712 | other watchpoint. */ | |
3a5c3e22 | 6713 | if ((w1->cond_exp |
4a64f543 MS |
6714 | && target_can_accel_watchpoint_condition (loc1->address, |
6715 | loc1->length, | |
0cf6dd15 | 6716 | loc1->watchpoint_type, |
3a5c3e22 PA |
6717 | w1->cond_exp)) |
6718 | || (w2->cond_exp | |
4a64f543 MS |
6719 | && target_can_accel_watchpoint_condition (loc2->address, |
6720 | loc2->length, | |
0cf6dd15 | 6721 | loc2->watchpoint_type, |
3a5c3e22 | 6722 | w2->cond_exp))) |
0cf6dd15 TJB |
6723 | return 0; |
6724 | ||
85d721b8 PA |
6725 | /* Note that this checks the owner's type, not the location's. In |
6726 | case the target does not support read watchpoints, but does | |
6727 | support access watchpoints, we'll have bp_read_watchpoint | |
6728 | watchpoints with hw_access locations. Those should be considered | |
6729 | duplicates of hw_read locations. The hw_read locations will | |
6730 | become hw_access locations later. */ | |
2d134ed3 PA |
6731 | return (loc1->owner->type == loc2->owner->type |
6732 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6733 | && loc1->address == loc2->address | |
6734 | && loc1->length == loc2->length); | |
e4f237da KB |
6735 | } |
6736 | ||
6c95b8df PA |
6737 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
6738 | same breakpoint location. In most targets, this can only be true | |
6739 | if ASPACE1 matches ASPACE2. On targets that have global | |
6740 | breakpoints, the address space doesn't really matter. */ | |
6741 | ||
6742 | static int | |
6743 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
6744 | struct address_space *aspace2, CORE_ADDR addr2) | |
6745 | { | |
f5656ead | 6746 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6747 | || aspace1 == aspace2) |
6748 | && addr1 == addr2); | |
6749 | } | |
6750 | ||
f1310107 TJB |
6751 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6752 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6753 | matches ASPACE2. On targets that have global breakpoints, the address | |
6754 | space doesn't really matter. */ | |
6755 | ||
6756 | static int | |
6757 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6758 | int len1, struct address_space *aspace2, | |
6759 | CORE_ADDR addr2) | |
6760 | { | |
f5656ead | 6761 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6762 | || aspace1 == aspace2) |
6763 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6764 | } | |
6765 | ||
6766 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6767 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6768 | matches the breakpoint's address space. On targets that have global | |
6769 | breakpoints, the address space doesn't really matter. */ | |
6770 | ||
6771 | static int | |
6772 | breakpoint_location_address_match (struct bp_location *bl, | |
6773 | struct address_space *aspace, | |
6774 | CORE_ADDR addr) | |
6775 | { | |
6776 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6777 | aspace, addr) | |
6778 | || (bl->length | |
6779 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6780 | bl->address, bl->length, | |
6781 | aspace, addr))); | |
6782 | } | |
6783 | ||
1e4d1764 YQ |
6784 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6785 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6786 | true, otherwise returns false. */ | |
6787 | ||
6788 | static int | |
6789 | tracepoint_locations_match (struct bp_location *loc1, | |
6790 | struct bp_location *loc2) | |
6791 | { | |
6792 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6793 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6794 | locations at the same address of different tracepoints are regarded as | |
6795 | different locations. */ | |
6796 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6797 | else | |
6798 | return 0; | |
6799 | } | |
6800 | ||
2d134ed3 PA |
6801 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6802 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6803 | represent the same location. */ | |
6804 | ||
6805 | static int | |
4a64f543 MS |
6806 | breakpoint_locations_match (struct bp_location *loc1, |
6807 | struct bp_location *loc2) | |
2d134ed3 | 6808 | { |
2bdf28a0 JK |
6809 | int hw_point1, hw_point2; |
6810 | ||
6811 | /* Both of them must not be in moribund_locations. */ | |
6812 | gdb_assert (loc1->owner != NULL); | |
6813 | gdb_assert (loc2->owner != NULL); | |
6814 | ||
6815 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6816 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6817 | |
6818 | if (hw_point1 != hw_point2) | |
6819 | return 0; | |
6820 | else if (hw_point1) | |
6821 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6822 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6823 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6824 | else |
f1310107 TJB |
6825 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6826 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6827 | loc2->pspace->aspace, loc2->address) | |
6828 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6829 | } |
6830 | ||
76897487 KB |
6831 | static void |
6832 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6833 | int bnum, int have_bnum) | |
6834 | { | |
f63fbe86 MS |
6835 | /* The longest string possibly returned by hex_string_custom |
6836 | is 50 chars. These must be at least that big for safety. */ | |
6837 | char astr1[64]; | |
6838 | char astr2[64]; | |
76897487 | 6839 | |
bb599908 PH |
6840 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6841 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6842 | if (have_bnum) |
8a3fe4f8 | 6843 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6844 | bnum, astr1, astr2); |
6845 | else | |
8a3fe4f8 | 6846 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6847 | } |
6848 | ||
4a64f543 MS |
6849 | /* Adjust a breakpoint's address to account for architectural |
6850 | constraints on breakpoint placement. Return the adjusted address. | |
6851 | Note: Very few targets require this kind of adjustment. For most | |
6852 | targets, this function is simply the identity function. */ | |
76897487 KB |
6853 | |
6854 | static CORE_ADDR | |
a6d9a66e UW |
6855 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6856 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6857 | { |
a6d9a66e | 6858 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6859 | { |
6860 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6861 | return bpaddr; | |
6862 | } | |
88f7da05 KB |
6863 | else if (bptype == bp_watchpoint |
6864 | || bptype == bp_hardware_watchpoint | |
6865 | || bptype == bp_read_watchpoint | |
6866 | || bptype == bp_access_watchpoint | |
fe798b75 | 6867 | || bptype == bp_catchpoint) |
88f7da05 KB |
6868 | { |
6869 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6870 | have their addresses modified. */ | |
6871 | return bpaddr; | |
6872 | } | |
76897487 KB |
6873 | else |
6874 | { | |
6875 | CORE_ADDR adjusted_bpaddr; | |
6876 | ||
6877 | /* Some targets have architectural constraints on the placement | |
6878 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6879 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6880 | |
6881 | /* An adjusted breakpoint address can significantly alter | |
6882 | a user's expectations. Print a warning if an adjustment | |
6883 | is required. */ | |
6884 | if (adjusted_bpaddr != bpaddr) | |
6885 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6886 | ||
6887 | return adjusted_bpaddr; | |
6888 | } | |
6889 | } | |
6890 | ||
28010a5d PA |
6891 | void |
6892 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6893 | struct breakpoint *owner) | |
7cc221ef | 6894 | { |
7cc221ef DJ |
6895 | memset (loc, 0, sizeof (*loc)); |
6896 | ||
348d480f PA |
6897 | gdb_assert (ops != NULL); |
6898 | ||
28010a5d PA |
6899 | loc->ops = ops; |
6900 | loc->owner = owner; | |
511a6cd4 | 6901 | loc->cond = NULL; |
b775012e | 6902 | loc->cond_bytecode = NULL; |
0d381245 VP |
6903 | loc->shlib_disabled = 0; |
6904 | loc->enabled = 1; | |
e049a4b5 | 6905 | |
28010a5d | 6906 | switch (owner->type) |
e049a4b5 DJ |
6907 | { |
6908 | case bp_breakpoint: | |
6909 | case bp_until: | |
6910 | case bp_finish: | |
6911 | case bp_longjmp: | |
6912 | case bp_longjmp_resume: | |
e2e4d78b | 6913 | case bp_longjmp_call_dummy: |
186c406b TT |
6914 | case bp_exception: |
6915 | case bp_exception_resume: | |
e049a4b5 | 6916 | case bp_step_resume: |
2c03e5be | 6917 | case bp_hp_step_resume: |
e049a4b5 DJ |
6918 | case bp_watchpoint_scope: |
6919 | case bp_call_dummy: | |
aa7d318d | 6920 | case bp_std_terminate: |
e049a4b5 DJ |
6921 | case bp_shlib_event: |
6922 | case bp_thread_event: | |
6923 | case bp_overlay_event: | |
4efc6507 | 6924 | case bp_jit_event: |
0fd8e87f | 6925 | case bp_longjmp_master: |
aa7d318d | 6926 | case bp_std_terminate_master: |
186c406b | 6927 | case bp_exception_master: |
0e30163f JK |
6928 | case bp_gnu_ifunc_resolver: |
6929 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6930 | case bp_dprintf: |
e049a4b5 | 6931 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6932 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6933 | break; |
6934 | case bp_hardware_breakpoint: | |
6935 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6936 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6937 | break; |
6938 | case bp_hardware_watchpoint: | |
6939 | case bp_read_watchpoint: | |
6940 | case bp_access_watchpoint: | |
6941 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6942 | break; | |
6943 | case bp_watchpoint: | |
ce78b96d | 6944 | case bp_catchpoint: |
15c3d785 PA |
6945 | case bp_tracepoint: |
6946 | case bp_fast_tracepoint: | |
0fb4aa4b | 6947 | case bp_static_tracepoint: |
e049a4b5 DJ |
6948 | loc->loc_type = bp_loc_other; |
6949 | break; | |
6950 | default: | |
e2e0b3e5 | 6951 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
6952 | } |
6953 | ||
f431efe5 | 6954 | loc->refc = 1; |
28010a5d PA |
6955 | } |
6956 | ||
6957 | /* Allocate a struct bp_location. */ | |
6958 | ||
6959 | static struct bp_location * | |
6960 | allocate_bp_location (struct breakpoint *bpt) | |
6961 | { | |
348d480f PA |
6962 | return bpt->ops->allocate_location (bpt); |
6963 | } | |
7cc221ef | 6964 | |
f431efe5 PA |
6965 | static void |
6966 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6967 | { |
348d480f | 6968 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
6969 | xfree (loc); |
6970 | } | |
6971 | ||
f431efe5 PA |
6972 | /* Increment reference count. */ |
6973 | ||
6974 | static void | |
6975 | incref_bp_location (struct bp_location *bl) | |
6976 | { | |
6977 | ++bl->refc; | |
6978 | } | |
6979 | ||
6980 | /* Decrement reference count. If the reference count reaches 0, | |
6981 | destroy the bp_location. Sets *BLP to NULL. */ | |
6982 | ||
6983 | static void | |
6984 | decref_bp_location (struct bp_location **blp) | |
6985 | { | |
0807b50c PA |
6986 | gdb_assert ((*blp)->refc > 0); |
6987 | ||
f431efe5 PA |
6988 | if (--(*blp)->refc == 0) |
6989 | free_bp_location (*blp); | |
6990 | *blp = NULL; | |
6991 | } | |
6992 | ||
346774a9 | 6993 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 6994 | |
346774a9 PA |
6995 | static void |
6996 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 6997 | { |
346774a9 | 6998 | struct breakpoint *b1; |
c906108c | 6999 | |
346774a9 PA |
7000 | /* Add this breakpoint to the end of the chain so that a list of |
7001 | breakpoints will come out in order of increasing numbers. */ | |
7002 | ||
7003 | b1 = breakpoint_chain; | |
7004 | if (b1 == 0) | |
7005 | breakpoint_chain = b; | |
7006 | else | |
7007 | { | |
7008 | while (b1->next) | |
7009 | b1 = b1->next; | |
7010 | b1->next = b; | |
7011 | } | |
7012 | } | |
7013 | ||
7014 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7015 | ||
7016 | static void | |
7017 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7018 | struct gdbarch *gdbarch, | |
28010a5d | 7019 | enum bptype bptype, |
c0a91b2b | 7020 | const struct breakpoint_ops *ops) |
346774a9 | 7021 | { |
c906108c | 7022 | memset (b, 0, sizeof (*b)); |
2219d63c | 7023 | |
348d480f PA |
7024 | gdb_assert (ops != NULL); |
7025 | ||
28010a5d | 7026 | b->ops = ops; |
4d28f7a8 | 7027 | b->type = bptype; |
a6d9a66e | 7028 | b->gdbarch = gdbarch; |
c906108c SS |
7029 | b->language = current_language->la_language; |
7030 | b->input_radix = input_radix; | |
7031 | b->thread = -1; | |
b5de0fa7 | 7032 | b->enable_state = bp_enabled; |
c906108c SS |
7033 | b->next = 0; |
7034 | b->silent = 0; | |
7035 | b->ignore_count = 0; | |
7036 | b->commands = NULL; | |
818dd999 | 7037 | b->frame_id = null_frame_id; |
0d381245 | 7038 | b->condition_not_parsed = 0; |
84f4c1fe | 7039 | b->py_bp_object = NULL; |
d0fb5eae | 7040 | b->related_breakpoint = b; |
346774a9 PA |
7041 | } |
7042 | ||
7043 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7044 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7045 | |
7046 | static struct breakpoint * | |
7047 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7048 | enum bptype bptype, |
c0a91b2b | 7049 | const struct breakpoint_ops *ops) |
346774a9 PA |
7050 | { |
7051 | struct breakpoint *b = XNEW (struct breakpoint); | |
7052 | ||
348d480f | 7053 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7054 | add_to_breakpoint_chain (b); |
0d381245 VP |
7055 | return b; |
7056 | } | |
7057 | ||
0e30163f JK |
7058 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7059 | resolutions should be made as the user specified the location explicitly | |
7060 | enough. */ | |
7061 | ||
0d381245 | 7062 | static void |
0e30163f | 7063 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7064 | { |
2bdf28a0 JK |
7065 | gdb_assert (loc->owner != NULL); |
7066 | ||
0d381245 | 7067 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7068 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7069 | || is_tracepoint (loc->owner)) |
0d381245 | 7070 | { |
0e30163f | 7071 | int is_gnu_ifunc; |
2c02bd72 | 7072 | const char *function_name; |
6a3a010b | 7073 | CORE_ADDR func_addr; |
0e30163f | 7074 | |
2c02bd72 | 7075 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7076 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7077 | |
7078 | if (is_gnu_ifunc && !explicit_loc) | |
7079 | { | |
7080 | struct breakpoint *b = loc->owner; | |
7081 | ||
7082 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7083 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7084 | &loc->requested_address)) |
7085 | { | |
7086 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7087 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7088 | loc->requested_address, | |
7089 | b->type); | |
7090 | } | |
7091 | else if (b->type == bp_breakpoint && b->loc == loc | |
7092 | && loc->next == NULL && b->related_breakpoint == b) | |
7093 | { | |
7094 | /* Create only the whole new breakpoint of this type but do not | |
7095 | mess more complicated breakpoints with multiple locations. */ | |
7096 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7097 | /* Remember the resolver's address for use by the return |
7098 | breakpoint. */ | |
7099 | loc->related_address = func_addr; | |
0e30163f JK |
7100 | } |
7101 | } | |
7102 | ||
2c02bd72 DE |
7103 | if (function_name) |
7104 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7105 | } |
7106 | } | |
7107 | ||
a6d9a66e | 7108 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7109 | struct gdbarch * |
a6d9a66e UW |
7110 | get_sal_arch (struct symtab_and_line sal) |
7111 | { | |
7112 | if (sal.section) | |
7113 | return get_objfile_arch (sal.section->objfile); | |
7114 | if (sal.symtab) | |
7115 | return get_objfile_arch (sal.symtab->objfile); | |
7116 | ||
7117 | return NULL; | |
7118 | } | |
7119 | ||
346774a9 PA |
7120 | /* Low level routine for partially initializing a breakpoint of type |
7121 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7122 | file name, and line number are provided by SAL. |
0d381245 VP |
7123 | |
7124 | It is expected that the caller will complete the initialization of | |
7125 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7126 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7127 | |
346774a9 PA |
7128 | static void |
7129 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7130 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7131 | const struct breakpoint_ops *ops) |
0d381245 | 7132 | { |
28010a5d | 7133 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7134 | |
3742cc8b | 7135 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7136 | |
6c95b8df PA |
7137 | if (bptype != bp_catchpoint) |
7138 | gdb_assert (sal.pspace != NULL); | |
7139 | ||
f8eba3c6 TT |
7140 | /* Store the program space that was used to set the breakpoint, |
7141 | except for ordinary breakpoints, which are independent of the | |
7142 | program space. */ | |
7143 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7144 | b->pspace = sal.pspace; | |
346774a9 | 7145 | } |
c906108c | 7146 | |
346774a9 PA |
7147 | /* set_raw_breakpoint is a low level routine for allocating and |
7148 | partially initializing a breakpoint of type BPTYPE. The newly | |
7149 | created breakpoint's address, section, source file name, and line | |
7150 | number are provided by SAL. The newly created and partially | |
7151 | initialized breakpoint is added to the breakpoint chain and | |
7152 | is also returned as the value of this function. | |
7153 | ||
7154 | It is expected that the caller will complete the initialization of | |
7155 | the newly created breakpoint struct as well as output any status | |
7156 | information regarding the creation of a new breakpoint. In | |
7157 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7158 | number! Care should be taken to not allow an error to occur | |
7159 | prior to completing the initialization of the breakpoint. If this | |
7160 | should happen, a bogus breakpoint will be left on the chain. */ | |
7161 | ||
7162 | struct breakpoint * | |
7163 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7164 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7165 | const struct breakpoint_ops *ops) |
346774a9 PA |
7166 | { |
7167 | struct breakpoint *b = XNEW (struct breakpoint); | |
7168 | ||
348d480f | 7169 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7170 | add_to_breakpoint_chain (b); |
c906108c SS |
7171 | return b; |
7172 | } | |
7173 | ||
c2c6d25f JM |
7174 | |
7175 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7176 | instruction, hard-wired into the inferior's code. */ | |
7177 | void | |
7178 | make_breakpoint_permanent (struct breakpoint *b) | |
7179 | { | |
0d381245 | 7180 | struct bp_location *bl; |
cc59ec59 | 7181 | |
b5de0fa7 | 7182 | b->enable_state = bp_permanent; |
c2c6d25f | 7183 | |
4a64f543 MS |
7184 | /* By definition, permanent breakpoints are already present in the |
7185 | code. Mark all locations as inserted. For now, | |
7186 | make_breakpoint_permanent is called in just one place, so it's | |
7187 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7188 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7189 | for (bl = b->loc; bl; bl = bl->next) |
7190 | bl->inserted = 1; | |
c2c6d25f JM |
7191 | } |
7192 | ||
53a5351d | 7193 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7194 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7195 | initiated the operation. */ | |
c906108c SS |
7196 | |
7197 | void | |
186c406b | 7198 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7199 | { |
35df4500 | 7200 | struct breakpoint *b, *b_tmp; |
186c406b | 7201 | int thread = tp->num; |
0fd8e87f UW |
7202 | |
7203 | /* To avoid having to rescan all objfile symbols at every step, | |
7204 | we maintain a list of continually-inserted but always disabled | |
7205 | longjmp "master" breakpoints. Here, we simply create momentary | |
7206 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7207 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7208 | if (b->pspace == current_program_space |
186c406b TT |
7209 | && (b->type == bp_longjmp_master |
7210 | || b->type == bp_exception_master)) | |
0fd8e87f | 7211 | { |
06edf0c0 PA |
7212 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7213 | struct breakpoint *clone; | |
cc59ec59 | 7214 | |
e2e4d78b JK |
7215 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7216 | after their removal. */ | |
06edf0c0 | 7217 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7218 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7219 | clone->thread = thread; |
7220 | } | |
186c406b TT |
7221 | |
7222 | tp->initiating_frame = frame; | |
c906108c SS |
7223 | } |
7224 | ||
611c83ae | 7225 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7226 | void |
611c83ae | 7227 | delete_longjmp_breakpoint (int thread) |
c906108c | 7228 | { |
35df4500 | 7229 | struct breakpoint *b, *b_tmp; |
c906108c | 7230 | |
35df4500 | 7231 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7232 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7233 | { |
7234 | if (b->thread == thread) | |
7235 | delete_breakpoint (b); | |
7236 | } | |
c906108c SS |
7237 | } |
7238 | ||
f59f708a PA |
7239 | void |
7240 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7241 | { | |
7242 | struct breakpoint *b, *b_tmp; | |
7243 | ||
7244 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7245 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7246 | { | |
7247 | if (b->thread == thread) | |
7248 | b->disposition = disp_del_at_next_stop; | |
7249 | } | |
7250 | } | |
7251 | ||
e2e4d78b JK |
7252 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7253 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7254 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7255 | breakpoints. */ | |
7256 | ||
7257 | struct breakpoint * | |
7258 | set_longjmp_breakpoint_for_call_dummy (void) | |
7259 | { | |
7260 | struct breakpoint *b, *retval = NULL; | |
7261 | ||
7262 | ALL_BREAKPOINTS (b) | |
7263 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7264 | { | |
7265 | struct breakpoint *new_b; | |
7266 | ||
7267 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7268 | &momentary_breakpoint_ops); | |
7269 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7270 | ||
7271 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7272 | ||
7273 | gdb_assert (new_b->related_breakpoint == new_b); | |
7274 | if (retval == NULL) | |
7275 | retval = new_b; | |
7276 | new_b->related_breakpoint = retval; | |
7277 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7278 | retval = retval->related_breakpoint; | |
7279 | retval->related_breakpoint = new_b; | |
7280 | } | |
7281 | ||
7282 | return retval; | |
7283 | } | |
7284 | ||
7285 | /* Verify all existing dummy frames and their associated breakpoints for | |
7286 | THREAD. Remove those which can no longer be found in the current frame | |
7287 | stack. | |
7288 | ||
7289 | You should call this function only at places where it is safe to currently | |
7290 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7291 | frames. */ | |
7292 | ||
7293 | void | |
7294 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7295 | { | |
7296 | struct breakpoint *b, *b_tmp; | |
7297 | ||
7298 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7299 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7300 | { | |
7301 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7302 | ||
7303 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7304 | dummy_b = dummy_b->related_breakpoint; | |
7305 | if (dummy_b->type != bp_call_dummy | |
7306 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7307 | continue; | |
7308 | ||
7309 | dummy_frame_discard (dummy_b->frame_id); | |
7310 | ||
7311 | while (b->related_breakpoint != b) | |
7312 | { | |
7313 | if (b_tmp == b->related_breakpoint) | |
7314 | b_tmp = b->related_breakpoint->next; | |
7315 | delete_breakpoint (b->related_breakpoint); | |
7316 | } | |
7317 | delete_breakpoint (b); | |
7318 | } | |
7319 | } | |
7320 | ||
1900040c MS |
7321 | void |
7322 | enable_overlay_breakpoints (void) | |
7323 | { | |
52f0bd74 | 7324 | struct breakpoint *b; |
1900040c MS |
7325 | |
7326 | ALL_BREAKPOINTS (b) | |
7327 | if (b->type == bp_overlay_event) | |
7328 | { | |
7329 | b->enable_state = bp_enabled; | |
b60e7edf | 7330 | update_global_location_list (1); |
c02f5703 | 7331 | overlay_events_enabled = 1; |
1900040c MS |
7332 | } |
7333 | } | |
7334 | ||
7335 | void | |
7336 | disable_overlay_breakpoints (void) | |
7337 | { | |
52f0bd74 | 7338 | struct breakpoint *b; |
1900040c MS |
7339 | |
7340 | ALL_BREAKPOINTS (b) | |
7341 | if (b->type == bp_overlay_event) | |
7342 | { | |
7343 | b->enable_state = bp_disabled; | |
b60e7edf | 7344 | update_global_location_list (0); |
c02f5703 | 7345 | overlay_events_enabled = 0; |
1900040c MS |
7346 | } |
7347 | } | |
7348 | ||
aa7d318d TT |
7349 | /* Set an active std::terminate breakpoint for each std::terminate |
7350 | master breakpoint. */ | |
7351 | void | |
7352 | set_std_terminate_breakpoint (void) | |
7353 | { | |
35df4500 | 7354 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7355 | |
35df4500 | 7356 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7357 | if (b->pspace == current_program_space |
7358 | && b->type == bp_std_terminate_master) | |
7359 | { | |
06edf0c0 PA |
7360 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7361 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7362 | } |
7363 | } | |
7364 | ||
7365 | /* Delete all the std::terminate breakpoints. */ | |
7366 | void | |
7367 | delete_std_terminate_breakpoint (void) | |
7368 | { | |
35df4500 | 7369 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7370 | |
35df4500 | 7371 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7372 | if (b->type == bp_std_terminate) |
7373 | delete_breakpoint (b); | |
7374 | } | |
7375 | ||
c4093a6a | 7376 | struct breakpoint * |
a6d9a66e | 7377 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7378 | { |
7379 | struct breakpoint *b; | |
c4093a6a | 7380 | |
06edf0c0 PA |
7381 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7382 | &internal_breakpoint_ops); | |
7383 | ||
b5de0fa7 | 7384 | b->enable_state = bp_enabled; |
c4093a6a | 7385 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7386 | b->addr_string |
7387 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7388 | |
b60e7edf | 7389 | update_global_location_list_nothrow (1); |
74960c60 | 7390 | |
c4093a6a JM |
7391 | return b; |
7392 | } | |
7393 | ||
7394 | void | |
7395 | remove_thread_event_breakpoints (void) | |
7396 | { | |
35df4500 | 7397 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7398 | |
35df4500 | 7399 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7400 | if (b->type == bp_thread_event |
7401 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7402 | delete_breakpoint (b); |
7403 | } | |
7404 | ||
0101ce28 JJ |
7405 | struct lang_and_radix |
7406 | { | |
7407 | enum language lang; | |
7408 | int radix; | |
7409 | }; | |
7410 | ||
4efc6507 DE |
7411 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7412 | ||
7413 | struct breakpoint * | |
7414 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7415 | { | |
7416 | struct breakpoint *b; | |
7417 | ||
06edf0c0 PA |
7418 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7419 | &internal_breakpoint_ops); | |
4efc6507 DE |
7420 | update_global_location_list_nothrow (1); |
7421 | return b; | |
7422 | } | |
0101ce28 | 7423 | |
03673fc7 PP |
7424 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7425 | ||
7426 | void | |
7427 | remove_jit_event_breakpoints (void) | |
7428 | { | |
7429 | struct breakpoint *b, *b_tmp; | |
7430 | ||
7431 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7432 | if (b->type == bp_jit_event | |
7433 | && b->loc->pspace == current_program_space) | |
7434 | delete_breakpoint (b); | |
7435 | } | |
7436 | ||
cae688ec JJ |
7437 | void |
7438 | remove_solib_event_breakpoints (void) | |
7439 | { | |
35df4500 | 7440 | struct breakpoint *b, *b_tmp; |
cae688ec | 7441 | |
35df4500 | 7442 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7443 | if (b->type == bp_shlib_event |
7444 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7445 | delete_breakpoint (b); |
7446 | } | |
7447 | ||
7448 | struct breakpoint * | |
a6d9a66e | 7449 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7450 | { |
7451 | struct breakpoint *b; | |
7452 | ||
06edf0c0 PA |
7453 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7454 | &internal_breakpoint_ops); | |
b60e7edf | 7455 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7456 | return b; |
7457 | } | |
7458 | ||
7459 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7460 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7461 | ||
7462 | void | |
cb851954 | 7463 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7464 | { |
876fa593 | 7465 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7466 | |
876fa593 | 7467 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7468 | { |
2bdf28a0 | 7469 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7470 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7471 | |
4a64f543 MS |
7472 | /* We apply the check to all breakpoints, including disabled for |
7473 | those with loc->duplicate set. This is so that when breakpoint | |
7474 | becomes enabled, or the duplicate is removed, gdb will try to | |
7475 | insert all breakpoints. If we don't set shlib_disabled here, | |
7476 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7477 | if (((b->type == bp_breakpoint) |
508ccb1f | 7478 | || (b->type == bp_jit_event) |
1042e4c0 | 7479 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7480 | || (is_tracepoint (b))) |
6c95b8df | 7481 | && loc->pspace == current_program_space |
0d381245 | 7482 | && !loc->shlib_disabled |
6c95b8df | 7483 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7484 | ) |
0d381245 VP |
7485 | { |
7486 | loc->shlib_disabled = 1; | |
7487 | } | |
cae688ec JJ |
7488 | } |
7489 | } | |
7490 | ||
63644780 NB |
7491 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7492 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7493 | disabled ones can just stay disabled. */ | |
84acb35a | 7494 | |
75149521 | 7495 | static void |
84acb35a JJ |
7496 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7497 | { | |
876fa593 | 7498 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7499 | int disabled_shlib_breaks = 0; |
7500 | ||
c86cf029 VP |
7501 | /* SunOS a.out shared libraries are always mapped, so do not |
7502 | disable breakpoints; they will only be reported as unloaded | |
7503 | through clear_solib when GDB discards its shared library | |
7504 | list. See clear_solib for more information. */ | |
7505 | if (exec_bfd != NULL | |
7506 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7507 | return; | |
7508 | ||
876fa593 | 7509 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7510 | { |
2bdf28a0 | 7511 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7512 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7513 | |
1e4d1764 | 7514 | if (solib->pspace == loc->pspace |
e2dd7057 | 7515 | && !loc->shlib_disabled |
1e4d1764 YQ |
7516 | && (((b->type == bp_breakpoint |
7517 | || b->type == bp_jit_event | |
7518 | || b->type == bp_hardware_breakpoint) | |
7519 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7520 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7521 | || is_tracepoint (b)) | |
e2dd7057 | 7522 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7523 | { |
e2dd7057 PP |
7524 | loc->shlib_disabled = 1; |
7525 | /* At this point, we cannot rely on remove_breakpoint | |
7526 | succeeding so we must mark the breakpoint as not inserted | |
7527 | to prevent future errors occurring in remove_breakpoints. */ | |
7528 | loc->inserted = 0; | |
8d3788bd VP |
7529 | |
7530 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7531 | observer_notify_breakpoint_modified (b); | |
7532 | ||
e2dd7057 PP |
7533 | if (!disabled_shlib_breaks) |
7534 | { | |
7535 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7536 | warning (_("Temporarily disabling breakpoints " |
7537 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7538 | solib->so_name); |
84acb35a | 7539 | } |
e2dd7057 | 7540 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7541 | } |
7542 | } | |
84acb35a JJ |
7543 | } |
7544 | ||
63644780 NB |
7545 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7546 | notification of free_objfile. Only apply to enabled breakpoints, | |
7547 | disabled ones can just stay disabled. */ | |
7548 | ||
7549 | static void | |
7550 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7551 | { | |
7552 | struct breakpoint *b; | |
7553 | ||
7554 | if (objfile == NULL) | |
7555 | return; | |
7556 | ||
7557 | /* If the file is a shared library not loaded by the user then | |
7558 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7559 | was called. In that case there is no need to take action again. */ | |
7560 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7561 | return; | |
7562 | ||
7563 | ALL_BREAKPOINTS (b) | |
7564 | { | |
7565 | struct bp_location *loc; | |
7566 | int bp_modified = 0; | |
7567 | ||
7568 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7569 | continue; | |
7570 | ||
7571 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7572 | { | |
7573 | CORE_ADDR loc_addr = loc->address; | |
7574 | ||
7575 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7576 | && loc->loc_type != bp_loc_software_breakpoint) | |
7577 | continue; | |
7578 | ||
7579 | if (loc->shlib_disabled != 0) | |
7580 | continue; | |
7581 | ||
7582 | if (objfile->pspace != loc->pspace) | |
7583 | continue; | |
7584 | ||
7585 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7586 | && loc->loc_type != bp_loc_software_breakpoint) | |
7587 | continue; | |
7588 | ||
7589 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7590 | { | |
7591 | loc->shlib_disabled = 1; | |
7592 | loc->inserted = 0; | |
7593 | ||
7594 | mark_breakpoint_location_modified (loc); | |
7595 | ||
7596 | bp_modified = 1; | |
7597 | } | |
7598 | } | |
7599 | ||
7600 | if (bp_modified) | |
7601 | observer_notify_breakpoint_modified (b); | |
7602 | } | |
7603 | } | |
7604 | ||
ce78b96d JB |
7605 | /* FORK & VFORK catchpoints. */ |
7606 | ||
e29a4733 PA |
7607 | /* An instance of this type is used to represent a fork or vfork |
7608 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7609 | class; users downcast to "struct breakpoint *" when needed. A | |
7610 | breakpoint is really of this type iff its ops pointer points to | |
7611 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7612 | ||
7613 | struct fork_catchpoint | |
7614 | { | |
7615 | /* The base class. */ | |
7616 | struct breakpoint base; | |
7617 | ||
7618 | /* Process id of a child process whose forking triggered this | |
7619 | catchpoint. This field is only valid immediately after this | |
7620 | catchpoint has triggered. */ | |
7621 | ptid_t forked_inferior_pid; | |
7622 | }; | |
7623 | ||
4a64f543 MS |
7624 | /* Implement the "insert" breakpoint_ops method for fork |
7625 | catchpoints. */ | |
ce78b96d | 7626 | |
77b06cd7 TJB |
7627 | static int |
7628 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7629 | { |
dfd4cc63 | 7630 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7631 | } |
7632 | ||
4a64f543 MS |
7633 | /* Implement the "remove" breakpoint_ops method for fork |
7634 | catchpoints. */ | |
ce78b96d JB |
7635 | |
7636 | static int | |
77b06cd7 | 7637 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7638 | { |
dfd4cc63 | 7639 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7640 | } |
7641 | ||
7642 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7643 | catchpoints. */ | |
7644 | ||
7645 | static int | |
f1310107 | 7646 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7647 | struct address_space *aspace, CORE_ADDR bp_addr, |
7648 | const struct target_waitstatus *ws) | |
ce78b96d | 7649 | { |
e29a4733 PA |
7650 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7651 | ||
f90263c1 TT |
7652 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7653 | return 0; | |
7654 | ||
7655 | c->forked_inferior_pid = ws->value.related_pid; | |
7656 | return 1; | |
ce78b96d JB |
7657 | } |
7658 | ||
4a64f543 MS |
7659 | /* Implement the "print_it" breakpoint_ops method for fork |
7660 | catchpoints. */ | |
ce78b96d JB |
7661 | |
7662 | static enum print_stop_action | |
348d480f | 7663 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7664 | { |
36dfb11c | 7665 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7666 | struct breakpoint *b = bs->breakpoint_at; |
7667 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7668 | |
ce78b96d | 7669 | annotate_catchpoint (b->number); |
36dfb11c TT |
7670 | if (b->disposition == disp_del) |
7671 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7672 | else | |
7673 | ui_out_text (uiout, "\nCatchpoint "); | |
7674 | if (ui_out_is_mi_like_p (uiout)) | |
7675 | { | |
7676 | ui_out_field_string (uiout, "reason", | |
7677 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7678 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7679 | } | |
7680 | ui_out_field_int (uiout, "bkptno", b->number); | |
7681 | ui_out_text (uiout, " (forked process "); | |
7682 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7683 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7684 | return PRINT_SRC_AND_LOC; |
7685 | } | |
7686 | ||
4a64f543 MS |
7687 | /* Implement the "print_one" breakpoint_ops method for fork |
7688 | catchpoints. */ | |
ce78b96d JB |
7689 | |
7690 | static void | |
a6d9a66e | 7691 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7692 | { |
e29a4733 | 7693 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7694 | struct value_print_options opts; |
79a45e25 | 7695 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7696 | |
7697 | get_user_print_options (&opts); | |
7698 | ||
4a64f543 MS |
7699 | /* Field 4, the address, is omitted (which makes the columns not |
7700 | line up too nicely with the headers, but the effect is relatively | |
7701 | readable). */ | |
79a45b7d | 7702 | if (opts.addressprint) |
ce78b96d JB |
7703 | ui_out_field_skip (uiout, "addr"); |
7704 | annotate_field (5); | |
7705 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7706 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7707 | { |
7708 | ui_out_text (uiout, ", process "); | |
7709 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7710 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7711 | ui_out_spaces (uiout, 1); |
7712 | } | |
8ac3646f TT |
7713 | |
7714 | if (ui_out_is_mi_like_p (uiout)) | |
7715 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7716 | } |
7717 | ||
7718 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7719 | catchpoints. */ | |
7720 | ||
7721 | static void | |
7722 | print_mention_catch_fork (struct breakpoint *b) | |
7723 | { | |
7724 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7725 | } | |
7726 | ||
6149aea9 PA |
7727 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7728 | catchpoints. */ | |
7729 | ||
7730 | static void | |
7731 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7732 | { | |
7733 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7734 | print_recreate_thread (b, fp); |
6149aea9 PA |
7735 | } |
7736 | ||
ce78b96d JB |
7737 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7738 | ||
2060206e | 7739 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7740 | |
4a64f543 MS |
7741 | /* Implement the "insert" breakpoint_ops method for vfork |
7742 | catchpoints. */ | |
ce78b96d | 7743 | |
77b06cd7 TJB |
7744 | static int |
7745 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7746 | { |
dfd4cc63 | 7747 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7748 | } |
7749 | ||
4a64f543 MS |
7750 | /* Implement the "remove" breakpoint_ops method for vfork |
7751 | catchpoints. */ | |
ce78b96d JB |
7752 | |
7753 | static int | |
77b06cd7 | 7754 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7755 | { |
dfd4cc63 | 7756 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7757 | } |
7758 | ||
7759 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7760 | catchpoints. */ | |
7761 | ||
7762 | static int | |
f1310107 | 7763 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7764 | struct address_space *aspace, CORE_ADDR bp_addr, |
7765 | const struct target_waitstatus *ws) | |
ce78b96d | 7766 | { |
e29a4733 PA |
7767 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7768 | ||
f90263c1 TT |
7769 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7770 | return 0; | |
7771 | ||
7772 | c->forked_inferior_pid = ws->value.related_pid; | |
7773 | return 1; | |
ce78b96d JB |
7774 | } |
7775 | ||
4a64f543 MS |
7776 | /* Implement the "print_it" breakpoint_ops method for vfork |
7777 | catchpoints. */ | |
ce78b96d JB |
7778 | |
7779 | static enum print_stop_action | |
348d480f | 7780 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7781 | { |
36dfb11c | 7782 | struct ui_out *uiout = current_uiout; |
348d480f | 7783 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7784 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7785 | ||
ce78b96d | 7786 | annotate_catchpoint (b->number); |
36dfb11c TT |
7787 | if (b->disposition == disp_del) |
7788 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7789 | else | |
7790 | ui_out_text (uiout, "\nCatchpoint "); | |
7791 | if (ui_out_is_mi_like_p (uiout)) | |
7792 | { | |
7793 | ui_out_field_string (uiout, "reason", | |
7794 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7795 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7796 | } | |
7797 | ui_out_field_int (uiout, "bkptno", b->number); | |
7798 | ui_out_text (uiout, " (vforked process "); | |
7799 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7800 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7801 | return PRINT_SRC_AND_LOC; |
7802 | } | |
7803 | ||
4a64f543 MS |
7804 | /* Implement the "print_one" breakpoint_ops method for vfork |
7805 | catchpoints. */ | |
ce78b96d JB |
7806 | |
7807 | static void | |
a6d9a66e | 7808 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7809 | { |
e29a4733 | 7810 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7811 | struct value_print_options opts; |
79a45e25 | 7812 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7813 | |
7814 | get_user_print_options (&opts); | |
4a64f543 MS |
7815 | /* Field 4, the address, is omitted (which makes the columns not |
7816 | line up too nicely with the headers, but the effect is relatively | |
7817 | readable). */ | |
79a45b7d | 7818 | if (opts.addressprint) |
ce78b96d JB |
7819 | ui_out_field_skip (uiout, "addr"); |
7820 | annotate_field (5); | |
7821 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7822 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7823 | { |
7824 | ui_out_text (uiout, ", process "); | |
7825 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7826 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7827 | ui_out_spaces (uiout, 1); |
7828 | } | |
8ac3646f TT |
7829 | |
7830 | if (ui_out_is_mi_like_p (uiout)) | |
7831 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7832 | } |
7833 | ||
7834 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7835 | catchpoints. */ | |
7836 | ||
7837 | static void | |
7838 | print_mention_catch_vfork (struct breakpoint *b) | |
7839 | { | |
7840 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7841 | } | |
7842 | ||
6149aea9 PA |
7843 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7844 | catchpoints. */ | |
7845 | ||
7846 | static void | |
7847 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7848 | { | |
7849 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7850 | print_recreate_thread (b, fp); |
6149aea9 PA |
7851 | } |
7852 | ||
ce78b96d JB |
7853 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7854 | ||
2060206e | 7855 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7856 | |
edcc5120 TT |
7857 | /* An instance of this type is used to represent an solib catchpoint. |
7858 | It includes a "struct breakpoint" as a kind of base class; users | |
7859 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7860 | really of this type iff its ops pointer points to | |
7861 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7862 | ||
7863 | struct solib_catchpoint | |
7864 | { | |
7865 | /* The base class. */ | |
7866 | struct breakpoint base; | |
7867 | ||
7868 | /* True for "catch load", false for "catch unload". */ | |
7869 | unsigned char is_load; | |
7870 | ||
7871 | /* Regular expression to match, if any. COMPILED is only valid when | |
7872 | REGEX is non-NULL. */ | |
7873 | char *regex; | |
7874 | regex_t compiled; | |
7875 | }; | |
7876 | ||
7877 | static void | |
7878 | dtor_catch_solib (struct breakpoint *b) | |
7879 | { | |
7880 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7881 | ||
7882 | if (self->regex) | |
7883 | regfree (&self->compiled); | |
7884 | xfree (self->regex); | |
7885 | ||
7886 | base_breakpoint_ops.dtor (b); | |
7887 | } | |
7888 | ||
7889 | static int | |
7890 | insert_catch_solib (struct bp_location *ignore) | |
7891 | { | |
7892 | return 0; | |
7893 | } | |
7894 | ||
7895 | static int | |
7896 | remove_catch_solib (struct bp_location *ignore) | |
7897 | { | |
7898 | return 0; | |
7899 | } | |
7900 | ||
7901 | static int | |
7902 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7903 | struct address_space *aspace, | |
7904 | CORE_ADDR bp_addr, | |
7905 | const struct target_waitstatus *ws) | |
7906 | { | |
7907 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7908 | struct breakpoint *other; | |
7909 | ||
7910 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7911 | return 1; | |
7912 | ||
7913 | ALL_BREAKPOINTS (other) | |
7914 | { | |
7915 | struct bp_location *other_bl; | |
7916 | ||
7917 | if (other == bl->owner) | |
7918 | continue; | |
7919 | ||
7920 | if (other->type != bp_shlib_event) | |
7921 | continue; | |
7922 | ||
7923 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7924 | continue; | |
7925 | ||
7926 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7927 | { | |
7928 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7929 | return 1; | |
7930 | } | |
7931 | } | |
7932 | ||
7933 | return 0; | |
7934 | } | |
7935 | ||
7936 | static void | |
7937 | check_status_catch_solib (struct bpstats *bs) | |
7938 | { | |
7939 | struct solib_catchpoint *self | |
7940 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7941 | int ix; | |
7942 | ||
7943 | if (self->is_load) | |
7944 | { | |
7945 | struct so_list *iter; | |
7946 | ||
7947 | for (ix = 0; | |
7948 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
7949 | ix, iter); | |
7950 | ++ix) | |
7951 | { | |
7952 | if (!self->regex | |
7953 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
7954 | return; | |
7955 | } | |
7956 | } | |
7957 | else | |
7958 | { | |
7959 | char *iter; | |
7960 | ||
7961 | for (ix = 0; | |
7962 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
7963 | ix, iter); | |
7964 | ++ix) | |
7965 | { | |
7966 | if (!self->regex | |
7967 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
7968 | return; | |
7969 | } | |
7970 | } | |
7971 | ||
7972 | bs->stop = 0; | |
7973 | bs->print_it = print_it_noop; | |
7974 | } | |
7975 | ||
7976 | static enum print_stop_action | |
7977 | print_it_catch_solib (bpstat bs) | |
7978 | { | |
7979 | struct breakpoint *b = bs->breakpoint_at; | |
7980 | struct ui_out *uiout = current_uiout; | |
7981 | ||
7982 | annotate_catchpoint (b->number); | |
7983 | if (b->disposition == disp_del) | |
7984 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7985 | else | |
7986 | ui_out_text (uiout, "\nCatchpoint "); | |
7987 | ui_out_field_int (uiout, "bkptno", b->number); | |
7988 | ui_out_text (uiout, "\n"); | |
7989 | if (ui_out_is_mi_like_p (uiout)) | |
7990 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7991 | print_solib_event (1); | |
7992 | return PRINT_SRC_AND_LOC; | |
7993 | } | |
7994 | ||
7995 | static void | |
7996 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7997 | { | |
7998 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7999 | struct value_print_options opts; | |
8000 | struct ui_out *uiout = current_uiout; | |
8001 | char *msg; | |
8002 | ||
8003 | get_user_print_options (&opts); | |
8004 | /* Field 4, the address, is omitted (which makes the columns not | |
8005 | line up too nicely with the headers, but the effect is relatively | |
8006 | readable). */ | |
8007 | if (opts.addressprint) | |
8008 | { | |
8009 | annotate_field (4); | |
8010 | ui_out_field_skip (uiout, "addr"); | |
8011 | } | |
8012 | ||
8013 | annotate_field (5); | |
8014 | if (self->is_load) | |
8015 | { | |
8016 | if (self->regex) | |
8017 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8018 | else | |
8019 | msg = xstrdup (_("load of library")); | |
8020 | } | |
8021 | else | |
8022 | { | |
8023 | if (self->regex) | |
8024 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8025 | else | |
8026 | msg = xstrdup (_("unload of library")); | |
8027 | } | |
8028 | ui_out_field_string (uiout, "what", msg); | |
8029 | xfree (msg); | |
8ac3646f TT |
8030 | |
8031 | if (ui_out_is_mi_like_p (uiout)) | |
8032 | ui_out_field_string (uiout, "catch-type", | |
8033 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8034 | } |
8035 | ||
8036 | static void | |
8037 | print_mention_catch_solib (struct breakpoint *b) | |
8038 | { | |
8039 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8040 | ||
8041 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8042 | self->is_load ? "load" : "unload"); | |
8043 | } | |
8044 | ||
8045 | static void | |
8046 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8047 | { | |
8048 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8049 | ||
8050 | fprintf_unfiltered (fp, "%s %s", | |
8051 | b->disposition == disp_del ? "tcatch" : "catch", | |
8052 | self->is_load ? "load" : "unload"); | |
8053 | if (self->regex) | |
8054 | fprintf_unfiltered (fp, " %s", self->regex); | |
8055 | fprintf_unfiltered (fp, "\n"); | |
8056 | } | |
8057 | ||
8058 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8059 | ||
91985142 MG |
8060 | /* Shared helper function (MI and CLI) for creating and installing |
8061 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8062 | the events to be caught are load events, otherwise they are | |
8063 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8064 | temporary one. If ENABLED is non-zero the catchpoint is | |
8065 | created in an enabled state. */ | |
edcc5120 | 8066 | |
91985142 MG |
8067 | void |
8068 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8069 | { |
8070 | struct solib_catchpoint *c; | |
8071 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8072 | struct cleanup *cleanup; |
8073 | ||
edcc5120 TT |
8074 | if (!arg) |
8075 | arg = ""; | |
8076 | arg = skip_spaces (arg); | |
8077 | ||
8078 | c = XCNEW (struct solib_catchpoint); | |
8079 | cleanup = make_cleanup (xfree, c); | |
8080 | ||
8081 | if (*arg != '\0') | |
8082 | { | |
8083 | int errcode; | |
8084 | ||
8085 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8086 | if (errcode != 0) | |
8087 | { | |
8088 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8089 | ||
8090 | make_cleanup (xfree, err); | |
8091 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8092 | } | |
8093 | c->regex = xstrdup (arg); | |
8094 | } | |
8095 | ||
8096 | c->is_load = is_load; | |
91985142 | 8097 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8098 | &catch_solib_breakpoint_ops); |
8099 | ||
91985142 MG |
8100 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8101 | ||
edcc5120 TT |
8102 | discard_cleanups (cleanup); |
8103 | install_breakpoint (0, &c->base, 1); | |
8104 | } | |
8105 | ||
91985142 MG |
8106 | /* A helper function that does all the work for "catch load" and |
8107 | "catch unload". */ | |
8108 | ||
8109 | static void | |
8110 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8111 | struct cmd_list_element *command) | |
8112 | { | |
8113 | int tempflag; | |
8114 | const int enabled = 1; | |
8115 | ||
8116 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8117 | ||
8118 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8119 | } | |
8120 | ||
edcc5120 TT |
8121 | static void |
8122 | catch_load_command_1 (char *arg, int from_tty, | |
8123 | struct cmd_list_element *command) | |
8124 | { | |
8125 | catch_load_or_unload (arg, from_tty, 1, command); | |
8126 | } | |
8127 | ||
8128 | static void | |
8129 | catch_unload_command_1 (char *arg, int from_tty, | |
8130 | struct cmd_list_element *command) | |
8131 | { | |
8132 | catch_load_or_unload (arg, from_tty, 0, command); | |
8133 | } | |
8134 | ||
be5c67c1 PA |
8135 | /* An instance of this type is used to represent a syscall catchpoint. |
8136 | It includes a "struct breakpoint" as a kind of base class; users | |
8137 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8138 | really of this type iff its ops pointer points to | |
8139 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8140 | ||
8141 | struct syscall_catchpoint | |
8142 | { | |
8143 | /* The base class. */ | |
8144 | struct breakpoint base; | |
8145 | ||
8146 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8147 | syscall has been specified for filtering, its value is NULL. | |
8148 | Otherwise, it holds a list of all syscalls to be caught. The | |
8149 | list elements are allocated with xmalloc. */ | |
8150 | VEC(int) *syscalls_to_be_caught; | |
8151 | }; | |
8152 | ||
8153 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8154 | catchpoints. */ | |
8155 | ||
8156 | static void | |
8157 | dtor_catch_syscall (struct breakpoint *b) | |
8158 | { | |
8159 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8160 | ||
8161 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8162 | |
2060206e | 8163 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8164 | } |
8165 | ||
fa3064dd YQ |
8166 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8167 | ||
8168 | struct catch_syscall_inferior_data | |
8169 | { | |
8170 | /* We keep a count of the number of times the user has requested a | |
8171 | particular syscall to be tracked, and pass this information to the | |
8172 | target. This lets capable targets implement filtering directly. */ | |
8173 | ||
8174 | /* Number of times that "any" syscall is requested. */ | |
8175 | int any_syscall_count; | |
8176 | ||
8177 | /* Count of each system call. */ | |
8178 | VEC(int) *syscalls_counts; | |
8179 | ||
8180 | /* This counts all syscall catch requests, so we can readily determine | |
8181 | if any catching is necessary. */ | |
8182 | int total_syscalls_count; | |
8183 | }; | |
8184 | ||
8185 | static struct catch_syscall_inferior_data* | |
8186 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8187 | { | |
8188 | struct catch_syscall_inferior_data *inf_data; | |
8189 | ||
8190 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8191 | if (inf_data == NULL) | |
8192 | { | |
8193 | inf_data = XZALLOC (struct catch_syscall_inferior_data); | |
8194 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); | |
8195 | } | |
8196 | ||
8197 | return inf_data; | |
8198 | } | |
8199 | ||
8200 | static void | |
8201 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8202 | { | |
8203 | xfree (arg); | |
8204 | } | |
8205 | ||
8206 | ||
a96d9b2e SDJ |
8207 | /* Implement the "insert" breakpoint_ops method for syscall |
8208 | catchpoints. */ | |
8209 | ||
77b06cd7 TJB |
8210 | static int |
8211 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8212 | { |
be5c67c1 | 8213 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8214 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8215 | struct catch_syscall_inferior_data *inf_data |
8216 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8217 | |
fa3064dd | 8218 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8219 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8220 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8221 | else |
8222 | { | |
8223 | int i, iter; | |
cc59ec59 | 8224 | |
a96d9b2e | 8225 | for (i = 0; |
be5c67c1 | 8226 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8227 | i++) |
8228 | { | |
8229 | int elem; | |
cc59ec59 | 8230 | |
fa3064dd | 8231 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8232 | { |
fa3064dd | 8233 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8234 | uintptr_t vec_addr_offset |
8235 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8236 | uintptr_t vec_addr; |
fa3064dd YQ |
8237 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8238 | vec_addr = ((uintptr_t) VEC_address (int, | |
8239 | inf_data->syscalls_counts) | |
8240 | + vec_addr_offset); | |
a96d9b2e SDJ |
8241 | memset ((void *) vec_addr, 0, |
8242 | (iter + 1 - old_size) * sizeof (int)); | |
8243 | } | |
fa3064dd YQ |
8244 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8245 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8246 | } |
8247 | } | |
8248 | ||
dfd4cc63 | 8249 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8250 | inf_data->total_syscalls_count != 0, |
8251 | inf_data->any_syscall_count, | |
8252 | VEC_length (int, | |
8253 | inf_data->syscalls_counts), | |
8254 | VEC_address (int, | |
8255 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8256 | } |
8257 | ||
8258 | /* Implement the "remove" breakpoint_ops method for syscall | |
8259 | catchpoints. */ | |
8260 | ||
8261 | static int | |
77b06cd7 | 8262 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8263 | { |
be5c67c1 | 8264 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8265 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8266 | struct catch_syscall_inferior_data *inf_data |
8267 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8268 | |
fa3064dd | 8269 | --inf_data->total_syscalls_count; |
be5c67c1 | 8270 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8271 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8272 | else |
8273 | { | |
8274 | int i, iter; | |
cc59ec59 | 8275 | |
a96d9b2e | 8276 | for (i = 0; |
be5c67c1 | 8277 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8278 | i++) |
8279 | { | |
8280 | int elem; | |
fa3064dd | 8281 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8282 | /* Shouldn't happen. */ |
8283 | continue; | |
fa3064dd YQ |
8284 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8285 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8286 | } |
8287 | } | |
8288 | ||
dfd4cc63 | 8289 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8290 | inf_data->total_syscalls_count != 0, |
8291 | inf_data->any_syscall_count, | |
8292 | VEC_length (int, | |
8293 | inf_data->syscalls_counts), | |
3e43a32a | 8294 | VEC_address (int, |
fa3064dd | 8295 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8296 | } |
8297 | ||
8298 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8299 | catchpoints. */ | |
8300 | ||
8301 | static int | |
f1310107 | 8302 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8303 | struct address_space *aspace, CORE_ADDR bp_addr, |
8304 | const struct target_waitstatus *ws) | |
a96d9b2e | 8305 | { |
4a64f543 MS |
8306 | /* We must check if we are catching specific syscalls in this |
8307 | breakpoint. If we are, then we must guarantee that the called | |
8308 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8309 | int syscall_number = 0; |
be5c67c1 PA |
8310 | const struct syscall_catchpoint *c |
8311 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8312 | |
f90263c1 TT |
8313 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8314 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8315 | return 0; |
8316 | ||
f90263c1 TT |
8317 | syscall_number = ws->value.syscall_number; |
8318 | ||
a96d9b2e | 8319 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8320 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8321 | { |
8322 | int i, iter; | |
cc59ec59 | 8323 | |
a96d9b2e | 8324 | for (i = 0; |
be5c67c1 | 8325 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8326 | i++) |
8327 | if (syscall_number == iter) | |
4924df79 GKB |
8328 | return 1; |
8329 | ||
8330 | return 0; | |
a96d9b2e SDJ |
8331 | } |
8332 | ||
8333 | return 1; | |
8334 | } | |
8335 | ||
8336 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8337 | catchpoints. */ | |
8338 | ||
8339 | static enum print_stop_action | |
348d480f | 8340 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8341 | { |
36dfb11c | 8342 | struct ui_out *uiout = current_uiout; |
348d480f | 8343 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8344 | /* These are needed because we want to know in which state a |
8345 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8346 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8347 | must print "called syscall" or "returned from syscall". */ | |
8348 | ptid_t ptid; | |
8349 | struct target_waitstatus last; | |
8350 | struct syscall s; | |
a96d9b2e SDJ |
8351 | |
8352 | get_last_target_status (&ptid, &last); | |
8353 | ||
8354 | get_syscall_by_number (last.value.syscall_number, &s); | |
8355 | ||
8356 | annotate_catchpoint (b->number); | |
8357 | ||
36dfb11c TT |
8358 | if (b->disposition == disp_del) |
8359 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8360 | else |
36dfb11c TT |
8361 | ui_out_text (uiout, "\nCatchpoint "); |
8362 | if (ui_out_is_mi_like_p (uiout)) | |
8363 | { | |
8364 | ui_out_field_string (uiout, "reason", | |
8365 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8366 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8367 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8368 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8369 | } | |
8370 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8371 | |
8372 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8373 | ui_out_text (uiout, " (call to syscall "); |
8374 | else | |
8375 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8376 | |
36dfb11c TT |
8377 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8378 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8379 | if (s.name != NULL) | |
8380 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8381 | ||
8382 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8383 | |
8384 | return PRINT_SRC_AND_LOC; | |
8385 | } | |
8386 | ||
8387 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8388 | catchpoints. */ | |
8389 | ||
8390 | static void | |
8391 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8392 | struct bp_location **last_loc) |
a96d9b2e | 8393 | { |
be5c67c1 | 8394 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8395 | struct value_print_options opts; |
79a45e25 | 8396 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8397 | |
8398 | get_user_print_options (&opts); | |
4a64f543 MS |
8399 | /* Field 4, the address, is omitted (which makes the columns not |
8400 | line up too nicely with the headers, but the effect is relatively | |
8401 | readable). */ | |
a96d9b2e SDJ |
8402 | if (opts.addressprint) |
8403 | ui_out_field_skip (uiout, "addr"); | |
8404 | annotate_field (5); | |
8405 | ||
be5c67c1 PA |
8406 | if (c->syscalls_to_be_caught |
8407 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8408 | ui_out_text (uiout, "syscalls \""); |
8409 | else | |
8410 | ui_out_text (uiout, "syscall \""); | |
8411 | ||
be5c67c1 | 8412 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8413 | { |
8414 | int i, iter; | |
8415 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8416 | |
a96d9b2e | 8417 | for (i = 0; |
be5c67c1 | 8418 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8419 | i++) |
8420 | { | |
8421 | char *x = text; | |
8422 | struct syscall s; | |
8423 | get_syscall_by_number (iter, &s); | |
8424 | ||
8425 | if (s.name != NULL) | |
8426 | text = xstrprintf ("%s%s, ", text, s.name); | |
8427 | else | |
8428 | text = xstrprintf ("%s%d, ", text, iter); | |
8429 | ||
8430 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8431 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8432 | on every call. */ |
8433 | xfree (x); | |
8434 | } | |
8435 | /* Remove the last comma. */ | |
8436 | text[strlen (text) - 2] = '\0'; | |
8437 | ui_out_field_string (uiout, "what", text); | |
8438 | } | |
8439 | else | |
8440 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8441 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8442 | |
8443 | if (ui_out_is_mi_like_p (uiout)) | |
8444 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8445 | } |
8446 | ||
8447 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8448 | catchpoints. */ | |
8449 | ||
8450 | static void | |
8451 | print_mention_catch_syscall (struct breakpoint *b) | |
8452 | { | |
be5c67c1 PA |
8453 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8454 | ||
8455 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8456 | { |
8457 | int i, iter; | |
8458 | ||
be5c67c1 | 8459 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8460 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8461 | else | |
8462 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8463 | ||
8464 | for (i = 0; | |
be5c67c1 | 8465 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8466 | i++) |
8467 | { | |
8468 | struct syscall s; | |
8469 | get_syscall_by_number (iter, &s); | |
8470 | ||
8471 | if (s.name) | |
8472 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8473 | else | |
8474 | printf_filtered (" %d", s.number); | |
8475 | } | |
8476 | printf_filtered (")"); | |
8477 | } | |
8478 | else | |
8479 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8480 | b->number); | |
8481 | } | |
8482 | ||
6149aea9 PA |
8483 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8484 | catchpoints. */ | |
8485 | ||
8486 | static void | |
8487 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8488 | { | |
be5c67c1 PA |
8489 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8490 | ||
6149aea9 PA |
8491 | fprintf_unfiltered (fp, "catch syscall"); |
8492 | ||
be5c67c1 | 8493 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8494 | { |
8495 | int i, iter; | |
8496 | ||
8497 | for (i = 0; | |
be5c67c1 | 8498 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8499 | i++) |
8500 | { | |
8501 | struct syscall s; | |
8502 | ||
8503 | get_syscall_by_number (iter, &s); | |
8504 | if (s.name) | |
8505 | fprintf_unfiltered (fp, " %s", s.name); | |
8506 | else | |
8507 | fprintf_unfiltered (fp, " %d", s.number); | |
8508 | } | |
8509 | } | |
d9b3f62e | 8510 | print_recreate_thread (b, fp); |
6149aea9 PA |
8511 | } |
8512 | ||
a96d9b2e SDJ |
8513 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8514 | ||
2060206e | 8515 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8516 | |
8517 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8518 | ||
8519 | static int | |
8520 | syscall_catchpoint_p (struct breakpoint *b) | |
8521 | { | |
8522 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8523 | } | |
8524 | ||
346774a9 PA |
8525 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8526 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8527 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8528 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8529 | |
ab04a2af | 8530 | void |
346774a9 PA |
8531 | init_catchpoint (struct breakpoint *b, |
8532 | struct gdbarch *gdbarch, int tempflag, | |
8533 | char *cond_string, | |
c0a91b2b | 8534 | const struct breakpoint_ops *ops) |
c906108c | 8535 | { |
c5aa993b | 8536 | struct symtab_and_line sal; |
346774a9 | 8537 | |
fe39c653 | 8538 | init_sal (&sal); |
6c95b8df | 8539 | sal.pspace = current_program_space; |
c5aa993b | 8540 | |
28010a5d | 8541 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8542 | |
1b36a34b | 8543 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8544 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8545 | } |
8546 | ||
28010a5d | 8547 | void |
3ea46bff | 8548 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8549 | { |
8550 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8551 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8552 | if (is_tracepoint (b)) |
8553 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8554 | if (!internal) |
8555 | mention (b); | |
c56053d2 | 8556 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8557 | |
8558 | if (update_gll) | |
8559 | update_global_location_list (1); | |
c56053d2 PA |
8560 | } |
8561 | ||
9b70b993 | 8562 | static void |
a6d9a66e UW |
8563 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8564 | int tempflag, char *cond_string, | |
c0a91b2b | 8565 | const struct breakpoint_ops *ops) |
c906108c | 8566 | { |
e29a4733 | 8567 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8568 | |
e29a4733 PA |
8569 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8570 | ||
8571 | c->forked_inferior_pid = null_ptid; | |
8572 | ||
3ea46bff | 8573 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8574 | } |
8575 | ||
fe798b75 JB |
8576 | /* Exec catchpoints. */ |
8577 | ||
b4d90040 PA |
8578 | /* An instance of this type is used to represent an exec catchpoint. |
8579 | It includes a "struct breakpoint" as a kind of base class; users | |
8580 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8581 | really of this type iff its ops pointer points to | |
8582 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8583 | ||
8584 | struct exec_catchpoint | |
8585 | { | |
8586 | /* The base class. */ | |
8587 | struct breakpoint base; | |
8588 | ||
8589 | /* Filename of a program whose exec triggered this catchpoint. | |
8590 | This field is only valid immediately after this catchpoint has | |
8591 | triggered. */ | |
8592 | char *exec_pathname; | |
8593 | }; | |
8594 | ||
8595 | /* Implement the "dtor" breakpoint_ops method for exec | |
8596 | catchpoints. */ | |
8597 | ||
8598 | static void | |
8599 | dtor_catch_exec (struct breakpoint *b) | |
8600 | { | |
8601 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8602 | ||
8603 | xfree (c->exec_pathname); | |
348d480f | 8604 | |
2060206e | 8605 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8606 | } |
8607 | ||
77b06cd7 TJB |
8608 | static int |
8609 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8610 | { |
dfd4cc63 | 8611 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8612 | } |
c906108c | 8613 | |
fe798b75 | 8614 | static int |
77b06cd7 | 8615 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8616 | { |
dfd4cc63 | 8617 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8618 | } |
c906108c | 8619 | |
fe798b75 | 8620 | static int |
f1310107 | 8621 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8622 | struct address_space *aspace, CORE_ADDR bp_addr, |
8623 | const struct target_waitstatus *ws) | |
fe798b75 | 8624 | { |
b4d90040 PA |
8625 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8626 | ||
f90263c1 TT |
8627 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8628 | return 0; | |
8629 | ||
8630 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8631 | return 1; | |
fe798b75 | 8632 | } |
c906108c | 8633 | |
fe798b75 | 8634 | static enum print_stop_action |
348d480f | 8635 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8636 | { |
36dfb11c | 8637 | struct ui_out *uiout = current_uiout; |
348d480f | 8638 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8639 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8640 | ||
fe798b75 | 8641 | annotate_catchpoint (b->number); |
36dfb11c TT |
8642 | if (b->disposition == disp_del) |
8643 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8644 | else | |
8645 | ui_out_text (uiout, "\nCatchpoint "); | |
8646 | if (ui_out_is_mi_like_p (uiout)) | |
8647 | { | |
8648 | ui_out_field_string (uiout, "reason", | |
8649 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8650 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8651 | } | |
8652 | ui_out_field_int (uiout, "bkptno", b->number); | |
8653 | ui_out_text (uiout, " (exec'd "); | |
8654 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8655 | ui_out_text (uiout, "), "); | |
8656 | ||
fe798b75 | 8657 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8658 | } |
8659 | ||
fe798b75 | 8660 | static void |
a6d9a66e | 8661 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8662 | { |
b4d90040 | 8663 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8664 | struct value_print_options opts; |
79a45e25 | 8665 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8666 | |
8667 | get_user_print_options (&opts); | |
8668 | ||
8669 | /* Field 4, the address, is omitted (which makes the columns | |
8670 | not line up too nicely with the headers, but the effect | |
8671 | is relatively readable). */ | |
8672 | if (opts.addressprint) | |
8673 | ui_out_field_skip (uiout, "addr"); | |
8674 | annotate_field (5); | |
8675 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8676 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8677 | { |
8678 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8679 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8680 | ui_out_text (uiout, "\" "); |
8681 | } | |
8ac3646f TT |
8682 | |
8683 | if (ui_out_is_mi_like_p (uiout)) | |
8684 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8685 | } |
8686 | ||
8687 | static void | |
8688 | print_mention_catch_exec (struct breakpoint *b) | |
8689 | { | |
8690 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8691 | } | |
8692 | ||
6149aea9 PA |
8693 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8694 | catchpoints. */ | |
8695 | ||
8696 | static void | |
8697 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8698 | { | |
8699 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8700 | print_recreate_thread (b, fp); |
6149aea9 PA |
8701 | } |
8702 | ||
2060206e | 8703 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8704 | |
a96d9b2e SDJ |
8705 | static void |
8706 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8707 | const struct breakpoint_ops *ops) |
a96d9b2e | 8708 | { |
be5c67c1 | 8709 | struct syscall_catchpoint *c; |
a96d9b2e | 8710 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8711 | |
be5c67c1 PA |
8712 | c = XNEW (struct syscall_catchpoint); |
8713 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8714 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8715 | |
3ea46bff | 8716 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8717 | } |
8718 | ||
c906108c | 8719 | static int |
fba45db2 | 8720 | hw_breakpoint_used_count (void) |
c906108c | 8721 | { |
c906108c | 8722 | int i = 0; |
f1310107 TJB |
8723 | struct breakpoint *b; |
8724 | struct bp_location *bl; | |
c906108c SS |
8725 | |
8726 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8727 | { |
d6b74ac4 | 8728 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8729 | for (bl = b->loc; bl; bl = bl->next) |
8730 | { | |
8731 | /* Special types of hardware breakpoints may use more than | |
8732 | one register. */ | |
348d480f | 8733 | i += b->ops->resources_needed (bl); |
f1310107 | 8734 | } |
c5aa993b | 8735 | } |
c906108c SS |
8736 | |
8737 | return i; | |
8738 | } | |
8739 | ||
a1398e0c PA |
8740 | /* Returns the resources B would use if it were a hardware |
8741 | watchpoint. */ | |
8742 | ||
c906108c | 8743 | static int |
a1398e0c | 8744 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8745 | { |
c906108c | 8746 | int i = 0; |
e09342b5 | 8747 | struct bp_location *bl; |
c906108c | 8748 | |
a1398e0c PA |
8749 | if (!breakpoint_enabled (b)) |
8750 | return 0; | |
8751 | ||
8752 | for (bl = b->loc; bl; bl = bl->next) | |
8753 | { | |
8754 | /* Special types of hardware watchpoints may use more than | |
8755 | one register. */ | |
8756 | i += b->ops->resources_needed (bl); | |
8757 | } | |
8758 | ||
8759 | return i; | |
8760 | } | |
8761 | ||
8762 | /* Returns the sum the used resources of all hardware watchpoints of | |
8763 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8764 | the sum of the used resources of all hardware watchpoints of other | |
8765 | types _not_ TYPE. */ | |
8766 | ||
8767 | static int | |
8768 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8769 | enum bptype type, int *other_type_used) | |
8770 | { | |
8771 | int i = 0; | |
8772 | struct breakpoint *b; | |
8773 | ||
c906108c SS |
8774 | *other_type_used = 0; |
8775 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8776 | { |
a1398e0c PA |
8777 | if (b == except) |
8778 | continue; | |
e09342b5 TJB |
8779 | if (!breakpoint_enabled (b)) |
8780 | continue; | |
8781 | ||
a1398e0c PA |
8782 | if (b->type == type) |
8783 | i += hw_watchpoint_use_count (b); | |
8784 | else if (is_hardware_watchpoint (b)) | |
8785 | *other_type_used = 1; | |
e09342b5 TJB |
8786 | } |
8787 | ||
c906108c SS |
8788 | return i; |
8789 | } | |
8790 | ||
c906108c | 8791 | void |
fba45db2 | 8792 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8793 | { |
c5aa993b | 8794 | struct breakpoint *b; |
c906108c SS |
8795 | |
8796 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8797 | { |
cc60f2e3 | 8798 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8799 | { |
b5de0fa7 | 8800 | b->enable_state = bp_call_disabled; |
b60e7edf | 8801 | update_global_location_list (0); |
c5aa993b JM |
8802 | } |
8803 | } | |
c906108c SS |
8804 | } |
8805 | ||
8806 | void | |
fba45db2 | 8807 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8808 | { |
c5aa993b | 8809 | struct breakpoint *b; |
c906108c SS |
8810 | |
8811 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8812 | { |
cc60f2e3 | 8813 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8814 | { |
b5de0fa7 | 8815 | b->enable_state = bp_enabled; |
b60e7edf | 8816 | update_global_location_list (1); |
c5aa993b JM |
8817 | } |
8818 | } | |
c906108c SS |
8819 | } |
8820 | ||
8bea4e01 UW |
8821 | void |
8822 | disable_breakpoints_before_startup (void) | |
8823 | { | |
6c95b8df | 8824 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8825 | update_global_location_list (0); |
8bea4e01 UW |
8826 | } |
8827 | ||
8828 | void | |
8829 | enable_breakpoints_after_startup (void) | |
8830 | { | |
6c95b8df | 8831 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8832 | breakpoint_re_set (); |
8bea4e01 UW |
8833 | } |
8834 | ||
c906108c SS |
8835 | |
8836 | /* Set a breakpoint that will evaporate an end of command | |
8837 | at address specified by SAL. | |
8838 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8839 | ||
8840 | struct breakpoint * | |
a6d9a66e UW |
8841 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8842 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8843 | { |
52f0bd74 | 8844 | struct breakpoint *b; |
edb3359d | 8845 | |
193facb3 JK |
8846 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8847 | tail-called one. */ | |
8848 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8849 | |
06edf0c0 | 8850 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8851 | b->enable_state = bp_enabled; |
8852 | b->disposition = disp_donttouch; | |
818dd999 | 8853 | b->frame_id = frame_id; |
c906108c | 8854 | |
4a64f543 MS |
8855 | /* If we're debugging a multi-threaded program, then we want |
8856 | momentary breakpoints to be active in only a single thread of | |
8857 | control. */ | |
39f77062 KB |
8858 | if (in_thread_list (inferior_ptid)) |
8859 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8860 | |
b60e7edf | 8861 | update_global_location_list_nothrow (1); |
74960c60 | 8862 | |
c906108c SS |
8863 | return b; |
8864 | } | |
611c83ae | 8865 | |
06edf0c0 PA |
8866 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8867 | The new breakpoint will have type TYPE, and use OPS as it | |
8868 | breakpoint_ops. */ | |
e58b0e63 | 8869 | |
06edf0c0 PA |
8870 | static struct breakpoint * |
8871 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8872 | enum bptype type, | |
c0a91b2b | 8873 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8874 | { |
8875 | struct breakpoint *copy; | |
8876 | ||
06edf0c0 | 8877 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8878 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8879 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8880 | |
a6d9a66e | 8881 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8882 | copy->loc->requested_address = orig->loc->requested_address; |
8883 | copy->loc->address = orig->loc->address; | |
8884 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8885 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8886 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8887 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8888 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8889 | copy->frame_id = orig->frame_id; |
8890 | copy->thread = orig->thread; | |
6c95b8df | 8891 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8892 | |
8893 | copy->enable_state = bp_enabled; | |
8894 | copy->disposition = disp_donttouch; | |
8895 | copy->number = internal_breakpoint_number--; | |
8896 | ||
8897 | update_global_location_list_nothrow (0); | |
8898 | return copy; | |
8899 | } | |
8900 | ||
06edf0c0 PA |
8901 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8902 | ORIG is NULL. */ | |
8903 | ||
8904 | struct breakpoint * | |
8905 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8906 | { | |
8907 | /* If there's nothing to clone, then return nothing. */ | |
8908 | if (orig == NULL) | |
8909 | return NULL; | |
8910 | ||
8911 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8912 | } | |
8913 | ||
611c83ae | 8914 | struct breakpoint * |
a6d9a66e UW |
8915 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8916 | enum bptype type) | |
611c83ae PA |
8917 | { |
8918 | struct symtab_and_line sal; | |
8919 | ||
8920 | sal = find_pc_line (pc, 0); | |
8921 | sal.pc = pc; | |
8922 | sal.section = find_pc_overlay (pc); | |
8923 | sal.explicit_pc = 1; | |
8924 | ||
a6d9a66e | 8925 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8926 | } |
c906108c | 8927 | \f |
c5aa993b | 8928 | |
c906108c SS |
8929 | /* Tell the user we have just set a breakpoint B. */ |
8930 | ||
8931 | static void | |
fba45db2 | 8932 | mention (struct breakpoint *b) |
c906108c | 8933 | { |
348d480f | 8934 | b->ops->print_mention (b); |
79a45e25 | 8935 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8936 | return; |
c906108c SS |
8937 | printf_filtered ("\n"); |
8938 | } | |
c906108c | 8939 | \f |
c5aa993b | 8940 | |
0d381245 | 8941 | static struct bp_location * |
39d61571 | 8942 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8943 | const struct symtab_and_line *sal) |
8944 | { | |
8945 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8946 | CORE_ADDR adjusted_address; |
8947 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8948 | ||
8949 | if (loc_gdbarch == NULL) | |
8950 | loc_gdbarch = b->gdbarch; | |
8951 | ||
8952 | /* Adjust the breakpoint's address prior to allocating a location. | |
8953 | Once we call allocate_bp_location(), that mostly uninitialized | |
8954 | location will be placed on the location chain. Adjustment of the | |
8955 | breakpoint may cause target_read_memory() to be called and we do | |
8956 | not want its scan of the location chain to find a breakpoint and | |
8957 | location that's only been partially initialized. */ | |
8958 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8959 | sal->pc, b->type); | |
0d381245 | 8960 | |
d30113d4 | 8961 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8962 | loc = allocate_bp_location (b); |
d30113d4 JK |
8963 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8964 | tmp = &((*tmp)->next)) | |
0d381245 | 8965 | ; |
d30113d4 | 8966 | loc->next = *tmp; |
0d381245 | 8967 | *tmp = loc; |
3742cc8b | 8968 | |
0d381245 | 8969 | loc->requested_address = sal->pc; |
3742cc8b | 8970 | loc->address = adjusted_address; |
6c95b8df | 8971 | loc->pspace = sal->pspace; |
55aa24fb | 8972 | loc->probe = sal->probe; |
6c95b8df | 8973 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8974 | loc->section = sal->section; |
3742cc8b | 8975 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8976 | loc->line_number = sal->line; |
2f202fde | 8977 | loc->symtab = sal->symtab; |
f8eba3c6 | 8978 | |
0e30163f JK |
8979 | set_breakpoint_location_function (loc, |
8980 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
8981 | return loc; |
8982 | } | |
514f746b AR |
8983 | \f |
8984 | ||
8985 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8986 | return 0 otherwise. */ | |
8987 | ||
8988 | static int | |
8989 | bp_loc_is_permanent (struct bp_location *loc) | |
8990 | { | |
8991 | int len; | |
8992 | CORE_ADDR addr; | |
1afeeb75 | 8993 | const gdb_byte *bpoint; |
514f746b | 8994 | gdb_byte *target_mem; |
939c61fa JK |
8995 | struct cleanup *cleanup; |
8996 | int retval = 0; | |
514f746b AR |
8997 | |
8998 | gdb_assert (loc != NULL); | |
8999 | ||
9000 | addr = loc->address; | |
1afeeb75 | 9001 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9002 | |
939c61fa | 9003 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9004 | if (bpoint == NULL) |
939c61fa JK |
9005 | return 0; |
9006 | ||
514f746b AR |
9007 | target_mem = alloca (len); |
9008 | ||
939c61fa JK |
9009 | /* Enable the automatic memory restoration from breakpoints while |
9010 | we read the memory. Otherwise we could say about our temporary | |
9011 | breakpoints they are permanent. */ | |
6c95b8df PA |
9012 | cleanup = save_current_space_and_thread (); |
9013 | ||
9014 | switch_to_program_space_and_thread (loc->pspace); | |
9015 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9016 | |
514f746b | 9017 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9018 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9019 | retval = 1; |
514f746b | 9020 | |
939c61fa JK |
9021 | do_cleanups (cleanup); |
9022 | ||
9023 | return retval; | |
514f746b AR |
9024 | } |
9025 | ||
e7e0cddf SS |
9026 | /* Build a command list for the dprintf corresponding to the current |
9027 | settings of the dprintf style options. */ | |
9028 | ||
9029 | static void | |
9030 | update_dprintf_command_list (struct breakpoint *b) | |
9031 | { | |
9032 | char *dprintf_args = b->extra_string; | |
9033 | char *printf_line = NULL; | |
9034 | ||
9035 | if (!dprintf_args) | |
9036 | return; | |
9037 | ||
9038 | dprintf_args = skip_spaces (dprintf_args); | |
9039 | ||
9040 | /* Allow a comma, as it may have terminated a location, but don't | |
9041 | insist on it. */ | |
9042 | if (*dprintf_args == ',') | |
9043 | ++dprintf_args; | |
9044 | dprintf_args = skip_spaces (dprintf_args); | |
9045 | ||
9046 | if (*dprintf_args != '"') | |
9047 | error (_("Bad format string, missing '\"'.")); | |
9048 | ||
d3ce09f5 | 9049 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9050 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9051 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9052 | { |
9053 | if (!dprintf_function) | |
9054 | error (_("No function supplied for dprintf call")); | |
9055 | ||
9056 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9057 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9058 | dprintf_function, | |
9059 | dprintf_channel, | |
9060 | dprintf_args); | |
9061 | else | |
9062 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9063 | dprintf_function, | |
9064 | dprintf_args); | |
9065 | } | |
d3ce09f5 SS |
9066 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9067 | { | |
9068 | if (target_can_run_breakpoint_commands ()) | |
9069 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9070 | else | |
9071 | { | |
9072 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9073 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9074 | } | |
9075 | } | |
e7e0cddf SS |
9076 | else |
9077 | internal_error (__FILE__, __LINE__, | |
9078 | _("Invalid dprintf style.")); | |
9079 | ||
f28045c2 | 9080 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9081 | /* Manufacture a printf sequence. */ |
f28045c2 | 9082 | { |
9d6e6e84 HZ |
9083 | struct command_line *printf_cmd_line |
9084 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9085 | |
f28045c2 YQ |
9086 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9087 | printf_cmd_line->control_type = simple_control; | |
9088 | printf_cmd_line->body_count = 0; | |
9089 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9090 | printf_cmd_line->next = NULL; |
f28045c2 | 9091 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9092 | |
f28045c2 YQ |
9093 | breakpoint_set_commands (b, printf_cmd_line); |
9094 | } | |
e7e0cddf SS |
9095 | } |
9096 | ||
9097 | /* Update all dprintf commands, making their command lists reflect | |
9098 | current style settings. */ | |
9099 | ||
9100 | static void | |
9101 | update_dprintf_commands (char *args, int from_tty, | |
9102 | struct cmd_list_element *c) | |
9103 | { | |
9104 | struct breakpoint *b; | |
9105 | ||
9106 | ALL_BREAKPOINTS (b) | |
9107 | { | |
9108 | if (b->type == bp_dprintf) | |
9109 | update_dprintf_command_list (b); | |
9110 | } | |
9111 | } | |
c3f6f71d | 9112 | |
018d34a4 VP |
9113 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9114 | as textual description of the location, and COND_STRING | |
db107f19 | 9115 | as condition expression. */ |
018d34a4 VP |
9116 | |
9117 | static void | |
d9b3f62e PA |
9118 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9119 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9120 | char *filter, char *cond_string, |
e7e0cddf | 9121 | char *extra_string, |
d9b3f62e PA |
9122 | enum bptype type, enum bpdisp disposition, |
9123 | int thread, int task, int ignore_count, | |
c0a91b2b | 9124 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9125 | int enabled, int internal, unsigned flags, |
9126 | int display_canonical) | |
018d34a4 | 9127 | { |
0d381245 | 9128 | int i; |
018d34a4 VP |
9129 | |
9130 | if (type == bp_hardware_breakpoint) | |
9131 | { | |
fbbd034e AS |
9132 | int target_resources_ok; |
9133 | ||
9134 | i = hw_breakpoint_used_count (); | |
9135 | target_resources_ok = | |
9136 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9137 | i + 1, 0); |
9138 | if (target_resources_ok == 0) | |
9139 | error (_("No hardware breakpoint support in the target.")); | |
9140 | else if (target_resources_ok < 0) | |
9141 | error (_("Hardware breakpoints used exceeds limit.")); | |
9142 | } | |
9143 | ||
6c95b8df PA |
9144 | gdb_assert (sals.nelts > 0); |
9145 | ||
0d381245 VP |
9146 | for (i = 0; i < sals.nelts; ++i) |
9147 | { | |
9148 | struct symtab_and_line sal = sals.sals[i]; | |
9149 | struct bp_location *loc; | |
9150 | ||
9151 | if (from_tty) | |
5af949e3 UW |
9152 | { |
9153 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9154 | if (!loc_gdbarch) | |
9155 | loc_gdbarch = gdbarch; | |
9156 | ||
9157 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9158 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9159 | } |
0d381245 VP |
9160 | |
9161 | if (i == 0) | |
9162 | { | |
d9b3f62e | 9163 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9164 | b->thread = thread; |
4a306c9a | 9165 | b->task = task; |
855a6e68 | 9166 | |
0d381245 | 9167 | b->cond_string = cond_string; |
e7e0cddf | 9168 | b->extra_string = extra_string; |
0d381245 | 9169 | b->ignore_count = ignore_count; |
41447f92 | 9170 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9171 | b->disposition = disposition; |
6c95b8df | 9172 | |
44f238bb PA |
9173 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9174 | b->loc->inserted = 1; | |
9175 | ||
0fb4aa4b PA |
9176 | if (type == bp_static_tracepoint) |
9177 | { | |
d9b3f62e | 9178 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9179 | struct static_tracepoint_marker marker; |
9180 | ||
983af33b | 9181 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9182 | { |
9183 | /* We already know the marker exists, otherwise, we | |
9184 | wouldn't see a sal for it. */ | |
9185 | char *p = &addr_string[3]; | |
9186 | char *endp; | |
9187 | char *marker_str; | |
0fb4aa4b | 9188 | |
e9cafbcc | 9189 | p = skip_spaces (p); |
0fb4aa4b | 9190 | |
e9cafbcc | 9191 | endp = skip_to_space (p); |
0fb4aa4b PA |
9192 | |
9193 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9194 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9195 | |
3e43a32a MS |
9196 | printf_filtered (_("Probed static tracepoint " |
9197 | "marker \"%s\"\n"), | |
d9b3f62e | 9198 | t->static_trace_marker_id); |
0fb4aa4b PA |
9199 | } |
9200 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9201 | { | |
d9b3f62e | 9202 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9203 | release_static_tracepoint_marker (&marker); |
9204 | ||
3e43a32a MS |
9205 | printf_filtered (_("Probed static tracepoint " |
9206 | "marker \"%s\"\n"), | |
d9b3f62e | 9207 | t->static_trace_marker_id); |
0fb4aa4b PA |
9208 | } |
9209 | else | |
3e43a32a MS |
9210 | warning (_("Couldn't determine the static " |
9211 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9212 | } |
9213 | ||
0d381245 VP |
9214 | loc = b->loc; |
9215 | } | |
9216 | else | |
018d34a4 | 9217 | { |
39d61571 | 9218 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9219 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9220 | loc->inserted = 1; | |
0d381245 VP |
9221 | } |
9222 | ||
514f746b AR |
9223 | if (bp_loc_is_permanent (loc)) |
9224 | make_breakpoint_permanent (b); | |
9225 | ||
0d381245 VP |
9226 | if (b->cond_string) |
9227 | { | |
bbc13ae3 KS |
9228 | const char *arg = b->cond_string; |
9229 | ||
1bb9788d TT |
9230 | loc->cond = parse_exp_1 (&arg, loc->address, |
9231 | block_for_pc (loc->address), 0); | |
0d381245 | 9232 | if (*arg) |
588ae58c | 9233 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9234 | } |
e7e0cddf SS |
9235 | |
9236 | /* Dynamic printf requires and uses additional arguments on the | |
9237 | command line, otherwise it's an error. */ | |
9238 | if (type == bp_dprintf) | |
9239 | { | |
9240 | if (b->extra_string) | |
9241 | update_dprintf_command_list (b); | |
9242 | else | |
9243 | error (_("Format string required")); | |
9244 | } | |
9245 | else if (b->extra_string) | |
588ae58c | 9246 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9247 | } |
018d34a4 | 9248 | |
56435ebe | 9249 | b->display_canonical = display_canonical; |
018d34a4 VP |
9250 | if (addr_string) |
9251 | b->addr_string = addr_string; | |
9252 | else | |
9253 | /* addr_string has to be used or breakpoint_re_set will delete | |
9254 | me. */ | |
5af949e3 UW |
9255 | b->addr_string |
9256 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9257 | b->filter = filter; |
d9b3f62e | 9258 | } |
018d34a4 | 9259 | |
d9b3f62e PA |
9260 | static void |
9261 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9262 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9263 | char *filter, char *cond_string, |
e7e0cddf | 9264 | char *extra_string, |
d9b3f62e PA |
9265 | enum bptype type, enum bpdisp disposition, |
9266 | int thread, int task, int ignore_count, | |
c0a91b2b | 9267 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9268 | int enabled, int internal, unsigned flags, |
9269 | int display_canonical) | |
d9b3f62e PA |
9270 | { |
9271 | struct breakpoint *b; | |
9272 | struct cleanup *old_chain; | |
9273 | ||
9274 | if (is_tracepoint_type (type)) | |
9275 | { | |
9276 | struct tracepoint *t; | |
9277 | ||
9278 | t = XCNEW (struct tracepoint); | |
9279 | b = &t->base; | |
9280 | } | |
9281 | else | |
9282 | b = XNEW (struct breakpoint); | |
9283 | ||
9284 | old_chain = make_cleanup (xfree, b); | |
9285 | ||
9286 | init_breakpoint_sal (b, gdbarch, | |
9287 | sals, addr_string, | |
e7e0cddf | 9288 | filter, cond_string, extra_string, |
d9b3f62e PA |
9289 | type, disposition, |
9290 | thread, task, ignore_count, | |
9291 | ops, from_tty, | |
44f238bb PA |
9292 | enabled, internal, flags, |
9293 | display_canonical); | |
d9b3f62e PA |
9294 | discard_cleanups (old_chain); |
9295 | ||
3ea46bff | 9296 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9297 | } |
9298 | ||
9299 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9300 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9301 | value. COND_STRING, if not NULL, specified the condition to be | |
9302 | used for all breakpoints. Essentially the only case where | |
9303 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9304 | function. In that case, it's still not possible to specify | |
9305 | separate conditions for different overloaded functions, so | |
9306 | we take just a single condition string. | |
9307 | ||
c3f6f71d | 9308 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9309 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9310 | array contents). If the function fails (error() is called), the |
9311 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9312 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9313 | |
9314 | static void | |
8cdf0e15 | 9315 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9316 | struct linespec_result *canonical, |
e7e0cddf | 9317 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9318 | enum bptype type, enum bpdisp disposition, |
9319 | int thread, int task, int ignore_count, | |
c0a91b2b | 9320 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9321 | int enabled, int internal, unsigned flags) |
c906108c | 9322 | { |
018d34a4 | 9323 | int i; |
f8eba3c6 | 9324 | struct linespec_sals *lsal; |
cc59ec59 | 9325 | |
f8eba3c6 TT |
9326 | if (canonical->pre_expanded) |
9327 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9328 | ||
9329 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9330 | { |
f8eba3c6 TT |
9331 | /* Note that 'addr_string' can be NULL in the case of a plain |
9332 | 'break', without arguments. */ | |
9333 | char *addr_string = (canonical->addr_string | |
9334 | ? xstrdup (canonical->addr_string) | |
9335 | : NULL); | |
9336 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9337 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9338 | |
f8eba3c6 TT |
9339 | make_cleanup (xfree, filter_string); |
9340 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9341 | addr_string, | |
9342 | filter_string, | |
e7e0cddf SS |
9343 | cond_string, extra_string, |
9344 | type, disposition, | |
84f4c1fe | 9345 | thread, task, ignore_count, ops, |
44f238bb | 9346 | from_tty, enabled, internal, flags, |
56435ebe | 9347 | canonical->special_display); |
f8eba3c6 | 9348 | discard_cleanups (inner); |
c3f6f71d | 9349 | } |
c3f6f71d | 9350 | } |
c906108c | 9351 | |
9998af43 | 9352 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9353 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9354 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9355 | address strings. ADDRESS points to the end of the SAL. |
9356 | ||
9357 | The array and the line spec strings are allocated on the heap, it is | |
9358 | the caller's responsibility to free them. */ | |
c906108c | 9359 | |
b9362cc7 | 9360 | static void |
c3f6f71d | 9361 | parse_breakpoint_sals (char **address, |
58438ac1 | 9362 | struct linespec_result *canonical) |
c3f6f71d | 9363 | { |
c3f6f71d | 9364 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9365 | breakpoint. */ |
c3f6f71d JM |
9366 | if ((*address) == NULL |
9367 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9368 | { |
1bfeeb0f JL |
9369 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9370 | address. */ | |
9371 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9372 | { |
f8eba3c6 | 9373 | struct linespec_sals lsal; |
c3f6f71d | 9374 | struct symtab_and_line sal; |
1c8cdcb1 | 9375 | CORE_ADDR pc; |
cc59ec59 | 9376 | |
4a64f543 | 9377 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9378 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9379 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9380 | |
9381 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9382 | corresponding to the last call to print_frame_info. |
9383 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9384 | as the breakpoint line number is inappropriate otherwise. | |
9385 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9386 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9387 | pc = sal.pc; |
9388 | sal = find_pc_line (pc, 0); | |
00903456 | 9389 | |
4a64f543 | 9390 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9391 | where PC is the last displayed codepoint's address. So |
9392 | make sure to set sal.explicit_pc to prevent GDB from | |
9393 | trying to expand the list of sals to include all other | |
9394 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9395 | sal.pc = pc; |
00903456 JK |
9396 | sal.explicit_pc = 1; |
9397 | ||
f8eba3c6 TT |
9398 | lsal.sals.sals[0] = sal; |
9399 | lsal.sals.nelts = 1; | |
9400 | lsal.canonical = NULL; | |
9401 | ||
9402 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9403 | } |
9404 | else | |
8a3fe4f8 | 9405 | error (_("No default breakpoint address now.")); |
c906108c SS |
9406 | } |
9407 | else | |
9408 | { | |
cc80f267 JK |
9409 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9410 | ||
c906108c | 9411 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9412 | current_source_symtab (which is decode_line_1's default). |
9413 | This should produce the results we want almost all of the | |
cc80f267 JK |
9414 | time while leaving default_breakpoint_* alone. |
9415 | ||
9416 | ObjC: However, don't match an Objective-C method name which | |
9417 | may have a '+' or '-' succeeded by a '['. */ | |
9418 | if (last_displayed_sal_is_valid () | |
9419 | && (!cursal.symtab | |
9420 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9421 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9422 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9423 | get_last_displayed_symtab (), | |
9424 | get_last_displayed_line (), | |
9425 | canonical, NULL, NULL); | |
c906108c | 9426 | else |
f8eba3c6 | 9427 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9428 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9429 | } |
c3f6f71d | 9430 | } |
c906108c | 9431 | |
c906108c | 9432 | |
c3f6f71d | 9433 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9434 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9435 | |
b9362cc7 | 9436 | static void |
23e7acfb | 9437 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9438 | { |
9439 | int i; | |
cc59ec59 | 9440 | |
c3f6f71d | 9441 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9442 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9443 | } |
9444 | ||
7a697b8d SS |
9445 | /* Fast tracepoints may have restrictions on valid locations. For |
9446 | instance, a fast tracepoint using a jump instead of a trap will | |
9447 | likely have to overwrite more bytes than a trap would, and so can | |
9448 | only be placed where the instruction is longer than the jump, or a | |
9449 | multi-instruction sequence does not have a jump into the middle of | |
9450 | it, etc. */ | |
9451 | ||
9452 | static void | |
9453 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9454 | struct symtabs_and_lines *sals) | |
9455 | { | |
9456 | int i, rslt; | |
9457 | struct symtab_and_line *sal; | |
9458 | char *msg; | |
9459 | struct cleanup *old_chain; | |
9460 | ||
9461 | for (i = 0; i < sals->nelts; i++) | |
9462 | { | |
f8eba3c6 TT |
9463 | struct gdbarch *sarch; |
9464 | ||
7a697b8d SS |
9465 | sal = &sals->sals[i]; |
9466 | ||
f8eba3c6 TT |
9467 | sarch = get_sal_arch (*sal); |
9468 | /* We fall back to GDBARCH if there is no architecture | |
9469 | associated with SAL. */ | |
9470 | if (sarch == NULL) | |
9471 | sarch = gdbarch; | |
9472 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9473 | NULL, &msg); |
9474 | old_chain = make_cleanup (xfree, msg); | |
9475 | ||
9476 | if (!rslt) | |
9477 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9478 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9479 | |
9480 | do_cleanups (old_chain); | |
9481 | } | |
9482 | } | |
9483 | ||
af4908ba KS |
9484 | /* Issue an invalid thread ID error. */ |
9485 | ||
9486 | static void ATTRIBUTE_NORETURN | |
9487 | invalid_thread_id_error (int id) | |
9488 | { | |
9489 | error (_("Unknown thread %d."), id); | |
9490 | } | |
9491 | ||
018d34a4 VP |
9492 | /* Given TOK, a string specification of condition and thread, as |
9493 | accepted by the 'break' command, extract the condition | |
9494 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9495 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9496 | If no condition is found, *COND_STRING is set to NULL. |
9497 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9498 | |
9499 | static void | |
bbc13ae3 | 9500 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9501 | char **cond_string, int *thread, int *task, |
9502 | char **rest) | |
018d34a4 VP |
9503 | { |
9504 | *cond_string = NULL; | |
9505 | *thread = -1; | |
ed1d1739 KS |
9506 | *task = 0; |
9507 | *rest = NULL; | |
9508 | ||
018d34a4 VP |
9509 | while (tok && *tok) |
9510 | { | |
bbc13ae3 | 9511 | const char *end_tok; |
018d34a4 | 9512 | int toklen; |
bbc13ae3 KS |
9513 | const char *cond_start = NULL; |
9514 | const char *cond_end = NULL; | |
cc59ec59 | 9515 | |
bbc13ae3 | 9516 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9517 | |
9518 | if ((*tok == '"' || *tok == ',') && rest) | |
9519 | { | |
9520 | *rest = savestring (tok, strlen (tok)); | |
9521 | return; | |
9522 | } | |
9523 | ||
bbc13ae3 | 9524 | end_tok = skip_to_space_const (tok); |
d634f2de | 9525 | |
018d34a4 | 9526 | toklen = end_tok - tok; |
d634f2de | 9527 | |
018d34a4 VP |
9528 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9529 | { | |
f7545552 TT |
9530 | struct expression *expr; |
9531 | ||
018d34a4 | 9532 | tok = cond_start = end_tok + 1; |
1bb9788d | 9533 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9534 | xfree (expr); |
018d34a4 | 9535 | cond_end = tok; |
d634f2de | 9536 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9537 | } |
9538 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9539 | { | |
9540 | char *tmptok; | |
d634f2de | 9541 | |
018d34a4 | 9542 | tok = end_tok + 1; |
bbc13ae3 | 9543 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9544 | if (tok == tmptok) |
9545 | error (_("Junk after thread keyword.")); | |
9546 | if (!valid_thread_id (*thread)) | |
af4908ba | 9547 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9548 | tok = tmptok; |
018d34a4 | 9549 | } |
4a306c9a JB |
9550 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9551 | { | |
9552 | char *tmptok; | |
9553 | ||
9554 | tok = end_tok + 1; | |
bbc13ae3 | 9555 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9556 | if (tok == tmptok) |
9557 | error (_("Junk after task keyword.")); | |
9558 | if (!valid_task_id (*task)) | |
b6199126 | 9559 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9560 | tok = tmptok; |
4a306c9a | 9561 | } |
e7e0cddf SS |
9562 | else if (rest) |
9563 | { | |
9564 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9565 | return; |
e7e0cddf | 9566 | } |
018d34a4 VP |
9567 | else |
9568 | error (_("Junk at end of arguments.")); | |
9569 | } | |
9570 | } | |
9571 | ||
0fb4aa4b PA |
9572 | /* Decode a static tracepoint marker spec. */ |
9573 | ||
9574 | static struct symtabs_and_lines | |
9575 | decode_static_tracepoint_spec (char **arg_p) | |
9576 | { | |
9577 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9578 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9579 | struct cleanup *old_chain; |
9580 | char *p = &(*arg_p)[3]; | |
9581 | char *endp; | |
9582 | char *marker_str; | |
9583 | int i; | |
9584 | ||
e9cafbcc | 9585 | p = skip_spaces (p); |
0fb4aa4b | 9586 | |
e9cafbcc | 9587 | endp = skip_to_space (p); |
0fb4aa4b PA |
9588 | |
9589 | marker_str = savestring (p, endp - p); | |
9590 | old_chain = make_cleanup (xfree, marker_str); | |
9591 | ||
9592 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9593 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9594 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9595 | ||
9596 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9597 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9598 | ||
9599 | for (i = 0; i < sals.nelts; i++) | |
9600 | { | |
9601 | struct static_tracepoint_marker *marker; | |
9602 | ||
9603 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9604 | ||
9605 | init_sal (&sals.sals[i]); | |
9606 | ||
9607 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9608 | sals.sals[i].pc = marker->address; | |
9609 | ||
9610 | release_static_tracepoint_marker (marker); | |
9611 | } | |
9612 | ||
9613 | do_cleanups (old_chain); | |
9614 | ||
9615 | *arg_p = endp; | |
9616 | return sals; | |
9617 | } | |
9618 | ||
fd9b8c24 PA |
9619 | /* Set a breakpoint. This function is shared between CLI and MI |
9620 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9621 | modes of operations, selected by the PARSE_ARG parameter. If |
9622 | non-zero, the function will parse ARG, extracting location, | |
9623 | condition, thread and extra string. Otherwise, ARG is just the | |
9624 | breakpoint's location, with condition, thread, and extra string | |
9625 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9626 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9627 | from the internal breakpoint count. Returns true if any breakpoint | |
9628 | was created; false otherwise. */ | |
0101ce28 | 9629 | |
8cdf0e15 VP |
9630 | int |
9631 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9632 | char *arg, char *cond_string, |
9633 | int thread, char *extra_string, | |
f6de8ec2 | 9634 | int parse_arg, |
0fb4aa4b | 9635 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9636 | int ignore_count, |
9637 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9638 | const struct breakpoint_ops *ops, |
44f238bb PA |
9639 | int from_tty, int enabled, int internal, |
9640 | unsigned flags) | |
c3f6f71d | 9641 | { |
b78a6381 | 9642 | volatile struct gdb_exception e; |
f8eba3c6 | 9643 | char *copy_arg = NULL; |
c3f6f71d | 9644 | char *addr_start = arg; |
7efd8fc2 | 9645 | struct linespec_result canonical; |
c3f6f71d | 9646 | struct cleanup *old_chain; |
80c99de1 | 9647 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9648 | int pending = 0; |
4a306c9a | 9649 | int task = 0; |
86b17b60 | 9650 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9651 | |
348d480f PA |
9652 | gdb_assert (ops != NULL); |
9653 | ||
7efd8fc2 | 9654 | init_linespec_result (&canonical); |
c3f6f71d | 9655 | |
b78a6381 TT |
9656 | TRY_CATCH (e, RETURN_MASK_ALL) |
9657 | { | |
983af33b SDJ |
9658 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9659 | addr_start, ©_arg); | |
b78a6381 | 9660 | } |
0101ce28 JJ |
9661 | |
9662 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9663 | switch (e.reason) |
0101ce28 | 9664 | { |
983af33b SDJ |
9665 | case GDB_NO_ERROR: |
9666 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9667 | return 0; | |
9668 | break; | |
05ff989b AC |
9669 | case RETURN_ERROR: |
9670 | switch (e.error) | |
0101ce28 | 9671 | { |
05ff989b | 9672 | case NOT_FOUND_ERROR: |
0101ce28 | 9673 | |
05ff989b AC |
9674 | /* If pending breakpoint support is turned off, throw |
9675 | error. */ | |
fa8d40ab JJ |
9676 | |
9677 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9678 | throw_exception (e); |
9679 | ||
9680 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9681 | |
05ff989b AC |
9682 | /* If pending breakpoint support is auto query and the user |
9683 | selects no, then simply return the error code. */ | |
059fb39f | 9684 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9685 | && !nquery (_("Make %s pending on future shared library load? "), |
9686 | bptype_string (type_wanted))) | |
fd9b8c24 | 9687 | return 0; |
fa8d40ab | 9688 | |
05ff989b AC |
9689 | /* At this point, either the user was queried about setting |
9690 | a pending breakpoint and selected yes, or pending | |
9691 | breakpoint behavior is on and thus a pending breakpoint | |
9692 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9693 | { |
9694 | struct linespec_sals lsal; | |
9695 | ||
9696 | copy_arg = xstrdup (addr_start); | |
9697 | lsal.canonical = xstrdup (copy_arg); | |
9698 | lsal.sals.nelts = 1; | |
9699 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9700 | init_sal (&lsal.sals.sals[0]); | |
9701 | pending = 1; | |
9702 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9703 | } | |
05ff989b AC |
9704 | break; |
9705 | default: | |
98deb0da | 9706 | throw_exception (e); |
0101ce28 | 9707 | } |
2abae994 | 9708 | break; |
05ff989b | 9709 | default: |
983af33b | 9710 | throw_exception (e); |
0101ce28 | 9711 | } |
c3f6f71d | 9712 | |
4a64f543 | 9713 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9714 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9715 | |
c3f6f71d JM |
9716 | /* ----------------------------- SNIP ----------------------------- |
9717 | Anything added to the cleanup chain beyond this point is assumed | |
9718 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9719 | then the memory is not reclaimed. */ |
9720 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9721 | |
c3f6f71d JM |
9722 | /* Resolve all line numbers to PC's and verify that the addresses |
9723 | are ok for the target. */ | |
0101ce28 | 9724 | if (!pending) |
f8eba3c6 TT |
9725 | { |
9726 | int ix; | |
9727 | struct linespec_sals *iter; | |
9728 | ||
9729 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9730 | breakpoint_sals_to_pc (&iter->sals); | |
9731 | } | |
c3f6f71d | 9732 | |
7a697b8d | 9733 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9734 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9735 | { |
9736 | int ix; | |
9737 | struct linespec_sals *iter; | |
9738 | ||
9739 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9740 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9741 | } | |
7a697b8d | 9742 | |
c3f6f71d JM |
9743 | /* Verify that condition can be parsed, before setting any |
9744 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9745 | breakpoint. */ |
0101ce28 | 9746 | if (!pending) |
c3f6f71d | 9747 | { |
f6de8ec2 | 9748 | if (parse_arg) |
72b2ff0e | 9749 | { |
0878d0fa | 9750 | char *rest; |
52d361e1 YQ |
9751 | struct linespec_sals *lsal; |
9752 | ||
9753 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9754 | ||
0878d0fa YQ |
9755 | /* Here we only parse 'arg' to separate condition |
9756 | from thread number, so parsing in context of first | |
9757 | sal is OK. When setting the breakpoint we'll | |
9758 | re-parse it in context of each sal. */ | |
9759 | ||
9760 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9761 | &thread, &task, &rest); | |
9762 | if (cond_string) | |
9763 | make_cleanup (xfree, cond_string); | |
9764 | if (rest) | |
9765 | make_cleanup (xfree, rest); | |
9766 | if (rest) | |
9767 | extra_string = rest; | |
72b2ff0e | 9768 | } |
2f069f6f | 9769 | else |
72b2ff0e | 9770 | { |
0878d0fa YQ |
9771 | if (*arg != '\0') |
9772 | error (_("Garbage '%s' at end of location"), arg); | |
9773 | ||
9774 | /* Create a private copy of condition string. */ | |
9775 | if (cond_string) | |
9776 | { | |
9777 | cond_string = xstrdup (cond_string); | |
9778 | make_cleanup (xfree, cond_string); | |
9779 | } | |
9780 | /* Create a private copy of any extra string. */ | |
9781 | if (extra_string) | |
9782 | { | |
9783 | extra_string = xstrdup (extra_string); | |
9784 | make_cleanup (xfree, extra_string); | |
9785 | } | |
72b2ff0e | 9786 | } |
0fb4aa4b | 9787 | |
52d361e1 | 9788 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9789 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9790 | tempflag ? disp_del : disp_donttouch, |
9791 | thread, task, ignore_count, ops, | |
44f238bb | 9792 | from_tty, enabled, internal, flags); |
c906108c | 9793 | } |
0101ce28 JJ |
9794 | else |
9795 | { | |
0101ce28 JJ |
9796 | struct breakpoint *b; |
9797 | ||
0101ce28 JJ |
9798 | make_cleanup (xfree, copy_arg); |
9799 | ||
bfccc43c YQ |
9800 | if (is_tracepoint_type (type_wanted)) |
9801 | { | |
9802 | struct tracepoint *t; | |
9803 | ||
9804 | t = XCNEW (struct tracepoint); | |
9805 | b = &t->base; | |
9806 | } | |
9807 | else | |
9808 | b = XNEW (struct breakpoint); | |
9809 | ||
9810 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9811 | ||
f8eba3c6 | 9812 | b->addr_string = copy_arg; |
f6de8ec2 | 9813 | if (parse_arg) |
e12c7713 MK |
9814 | b->cond_string = NULL; |
9815 | else | |
9816 | { | |
9817 | /* Create a private copy of condition string. */ | |
9818 | if (cond_string) | |
9819 | { | |
9820 | cond_string = xstrdup (cond_string); | |
9821 | make_cleanup (xfree, cond_string); | |
9822 | } | |
9823 | b->cond_string = cond_string; | |
9824 | } | |
e7e0cddf | 9825 | b->extra_string = NULL; |
0101ce28 | 9826 | b->ignore_count = ignore_count; |
0101ce28 | 9827 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9828 | b->condition_not_parsed = 1; |
41447f92 | 9829 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9830 | if ((type_wanted != bp_breakpoint |
9831 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9832 | b->pspace = current_program_space; |
8bea4e01 | 9833 | |
bfccc43c | 9834 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9835 | } |
9836 | ||
f8eba3c6 | 9837 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9838 | { |
3e43a32a MS |
9839 | warning (_("Multiple breakpoints were set.\nUse the " |
9840 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9841 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9842 | } |
9843 | ||
80c99de1 PA |
9844 | /* That's it. Discard the cleanups for data inserted into the |
9845 | breakpoint. */ | |
9846 | discard_cleanups (bkpt_chain); | |
9847 | /* But cleanup everything else. */ | |
c3f6f71d | 9848 | do_cleanups (old_chain); |
217dc9e2 | 9849 | |
80c99de1 | 9850 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9851 | update_global_location_list (1); |
fd9b8c24 PA |
9852 | |
9853 | return 1; | |
c3f6f71d | 9854 | } |
c906108c | 9855 | |
348d480f | 9856 | /* Set a breakpoint. |
72b2ff0e VP |
9857 | ARG is a string describing breakpoint address, |
9858 | condition, and thread. | |
9859 | FLAG specifies if a breakpoint is hardware on, | |
9860 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9861 | and BP_TEMPFLAG. */ | |
348d480f | 9862 | |
98deb0da | 9863 | static void |
72b2ff0e | 9864 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9865 | { |
72b2ff0e | 9866 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9867 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9868 | ? bp_hardware_breakpoint | |
9869 | : bp_breakpoint); | |
55aa24fb SDJ |
9870 | struct breakpoint_ops *ops; |
9871 | const char *arg_cp = arg; | |
9872 | ||
9873 | /* Matching breakpoints on probes. */ | |
9874 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9875 | ops = &bkpt_probe_breakpoint_ops; | |
9876 | else | |
9877 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9878 | |
8cdf0e15 VP |
9879 | create_breakpoint (get_current_arch (), |
9880 | arg, | |
e7e0cddf | 9881 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9882 | tempflag, type_wanted, |
8cdf0e15 VP |
9883 | 0 /* Ignore count */, |
9884 | pending_break_support, | |
55aa24fb | 9885 | ops, |
8cdf0e15 | 9886 | from_tty, |
84f4c1fe | 9887 | 1 /* enabled */, |
44f238bb PA |
9888 | 0 /* internal */, |
9889 | 0); | |
c906108c SS |
9890 | } |
9891 | ||
c906108c SS |
9892 | /* Helper function for break_command_1 and disassemble_command. */ |
9893 | ||
9894 | void | |
fba45db2 | 9895 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9896 | { |
9897 | CORE_ADDR pc; | |
9898 | ||
9899 | if (sal->pc == 0 && sal->symtab != NULL) | |
9900 | { | |
9901 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9902 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9903 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9904 | sal->pc = pc; |
6a048695 | 9905 | |
4a64f543 MS |
9906 | /* If this SAL corresponds to a breakpoint inserted using a line |
9907 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9908 | if (sal->explicit_line) |
059acae7 | 9909 | skip_prologue_sal (sal); |
c906108c SS |
9910 | } |
9911 | ||
9912 | if (sal->section == 0 && sal->symtab != NULL) | |
9913 | { | |
9914 | struct blockvector *bv; | |
c5aa993b JM |
9915 | struct block *b; |
9916 | struct symbol *sym; | |
c906108c | 9917 | |
801e3a5b | 9918 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9919 | if (bv != NULL) |
9920 | { | |
7f0df278 | 9921 | sym = block_linkage_function (b); |
c906108c SS |
9922 | if (sym != NULL) |
9923 | { | |
9924 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9925 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9926 | } |
9927 | else | |
9928 | { | |
4a64f543 MS |
9929 | /* It really is worthwhile to have the section, so we'll |
9930 | just have to look harder. This case can be executed | |
9931 | if we have line numbers but no functions (as can | |
9932 | happen in assembly source). */ | |
c906108c | 9933 | |
7cbd4a93 | 9934 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9935 | struct cleanup *old_chain = save_current_space_and_thread (); |
9936 | ||
9937 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9938 | |
9939 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9940 | if (msym.minsym) |
e27d198c | 9941 | sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9942 | |
9943 | do_cleanups (old_chain); | |
c906108c SS |
9944 | } |
9945 | } | |
9946 | } | |
9947 | } | |
9948 | ||
9949 | void | |
fba45db2 | 9950 | break_command (char *arg, int from_tty) |
c906108c | 9951 | { |
db107f19 | 9952 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9953 | } |
9954 | ||
c906108c | 9955 | void |
fba45db2 | 9956 | tbreak_command (char *arg, int from_tty) |
c906108c | 9957 | { |
db107f19 | 9958 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9959 | } |
9960 | ||
c906108c | 9961 | static void |
fba45db2 | 9962 | hbreak_command (char *arg, int from_tty) |
c906108c | 9963 | { |
db107f19 | 9964 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9965 | } |
9966 | ||
9967 | static void | |
fba45db2 | 9968 | thbreak_command (char *arg, int from_tty) |
c906108c | 9969 | { |
db107f19 | 9970 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9971 | } |
9972 | ||
9973 | static void | |
fba45db2 | 9974 | stop_command (char *arg, int from_tty) |
c906108c | 9975 | { |
a3f17187 | 9976 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9977 | Usage: stop in <function | address>\n\ |
a3f17187 | 9978 | stop at <line>\n")); |
c906108c SS |
9979 | } |
9980 | ||
9981 | static void | |
fba45db2 | 9982 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9983 | { |
9984 | int badInput = 0; | |
9985 | ||
c5aa993b | 9986 | if (arg == (char *) NULL) |
c906108c SS |
9987 | badInput = 1; |
9988 | else if (*arg != '*') | |
9989 | { | |
9990 | char *argptr = arg; | |
9991 | int hasColon = 0; | |
9992 | ||
4a64f543 | 9993 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9994 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9995 | function/method name. */ |
c906108c | 9996 | while (*argptr && !hasColon) |
c5aa993b JM |
9997 | { |
9998 | hasColon = (*argptr == ':'); | |
9999 | argptr++; | |
10000 | } | |
c906108c SS |
10001 | |
10002 | if (hasColon) | |
c5aa993b | 10003 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10004 | else |
c5aa993b | 10005 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10006 | } |
10007 | ||
10008 | if (badInput) | |
a3f17187 | 10009 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10010 | else |
db107f19 | 10011 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10012 | } |
10013 | ||
10014 | static void | |
fba45db2 | 10015 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10016 | { |
10017 | int badInput = 0; | |
10018 | ||
c5aa993b | 10019 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10020 | badInput = 1; |
10021 | else | |
10022 | { | |
10023 | char *argptr = arg; | |
10024 | int hasColon = 0; | |
10025 | ||
4a64f543 MS |
10026 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10027 | it is probably a line number. */ | |
c906108c | 10028 | while (*argptr && !hasColon) |
c5aa993b JM |
10029 | { |
10030 | hasColon = (*argptr == ':'); | |
10031 | argptr++; | |
10032 | } | |
c906108c SS |
10033 | |
10034 | if (hasColon) | |
c5aa993b | 10035 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10036 | else |
c5aa993b | 10037 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10038 | } |
10039 | ||
10040 | if (badInput) | |
a3f17187 | 10041 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10042 | else |
db107f19 | 10043 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10044 | } |
10045 | ||
e7e0cddf SS |
10046 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10047 | with a prewired command list consisting of a single output command, | |
10048 | built from extra arguments supplied on the dprintf command | |
10049 | line. */ | |
10050 | ||
da821c7b | 10051 | static void |
e7e0cddf SS |
10052 | dprintf_command (char *arg, int from_tty) |
10053 | { | |
10054 | create_breakpoint (get_current_arch (), | |
10055 | arg, | |
10056 | NULL, 0, NULL, 1 /* parse arg */, | |
10057 | 0, bp_dprintf, | |
10058 | 0 /* Ignore count */, | |
10059 | pending_break_support, | |
10060 | &dprintf_breakpoint_ops, | |
10061 | from_tty, | |
10062 | 1 /* enabled */, | |
10063 | 0 /* internal */, | |
10064 | 0); | |
10065 | } | |
10066 | ||
d3ce09f5 SS |
10067 | static void |
10068 | agent_printf_command (char *arg, int from_tty) | |
10069 | { | |
10070 | error (_("May only run agent-printf on the target")); | |
10071 | } | |
10072 | ||
f1310107 TJB |
10073 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10074 | ranged breakpoints. */ | |
10075 | ||
10076 | static int | |
10077 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10078 | struct address_space *aspace, | |
09ac7c10 TT |
10079 | CORE_ADDR bp_addr, |
10080 | const struct target_waitstatus *ws) | |
f1310107 | 10081 | { |
09ac7c10 | 10082 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10083 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10084 | return 0; |
10085 | ||
f1310107 TJB |
10086 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10087 | bl->length, aspace, bp_addr); | |
10088 | } | |
10089 | ||
10090 | /* Implement the "resources_needed" breakpoint_ops method for | |
10091 | ranged breakpoints. */ | |
10092 | ||
10093 | static int | |
10094 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10095 | { | |
10096 | return target_ranged_break_num_registers (); | |
10097 | } | |
10098 | ||
10099 | /* Implement the "print_it" breakpoint_ops method for | |
10100 | ranged breakpoints. */ | |
10101 | ||
10102 | static enum print_stop_action | |
348d480f | 10103 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10104 | { |
348d480f | 10105 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10106 | struct bp_location *bl = b->loc; |
79a45e25 | 10107 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10108 | |
10109 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10110 | ||
10111 | /* Ranged breakpoints have only one location. */ | |
10112 | gdb_assert (bl && bl->next == NULL); | |
10113 | ||
10114 | annotate_breakpoint (b->number); | |
10115 | if (b->disposition == disp_del) | |
10116 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10117 | else | |
10118 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10119 | if (ui_out_is_mi_like_p (uiout)) | |
10120 | { | |
10121 | ui_out_field_string (uiout, "reason", | |
10122 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10123 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10124 | } | |
10125 | ui_out_field_int (uiout, "bkptno", b->number); | |
10126 | ui_out_text (uiout, ", "); | |
10127 | ||
10128 | return PRINT_SRC_AND_LOC; | |
10129 | } | |
10130 | ||
10131 | /* Implement the "print_one" breakpoint_ops method for | |
10132 | ranged breakpoints. */ | |
10133 | ||
10134 | static void | |
10135 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10136 | struct bp_location **last_loc) | |
10137 | { | |
10138 | struct bp_location *bl = b->loc; | |
10139 | struct value_print_options opts; | |
79a45e25 | 10140 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10141 | |
10142 | /* Ranged breakpoints have only one location. */ | |
10143 | gdb_assert (bl && bl->next == NULL); | |
10144 | ||
10145 | get_user_print_options (&opts); | |
10146 | ||
10147 | if (opts.addressprint) | |
10148 | /* We don't print the address range here, it will be printed later | |
10149 | by print_one_detail_ranged_breakpoint. */ | |
10150 | ui_out_field_skip (uiout, "addr"); | |
10151 | annotate_field (5); | |
10152 | print_breakpoint_location (b, bl); | |
10153 | *last_loc = bl; | |
10154 | } | |
10155 | ||
10156 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10157 | ranged breakpoints. */ | |
10158 | ||
10159 | static void | |
10160 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10161 | struct ui_out *uiout) | |
10162 | { | |
10163 | CORE_ADDR address_start, address_end; | |
10164 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10165 | struct ui_file *stb = mem_fileopen (); |
10166 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10167 | |
10168 | gdb_assert (bl); | |
10169 | ||
10170 | address_start = bl->address; | |
10171 | address_end = address_start + bl->length - 1; | |
10172 | ||
10173 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10174 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10175 | print_core_address (bl->gdbarch, address_start), |
10176 | print_core_address (bl->gdbarch, address_end)); | |
10177 | ui_out_field_stream (uiout, "addr", stb); | |
10178 | ui_out_text (uiout, "\n"); | |
10179 | ||
10180 | do_cleanups (cleanup); | |
10181 | } | |
10182 | ||
10183 | /* Implement the "print_mention" breakpoint_ops method for | |
10184 | ranged breakpoints. */ | |
10185 | ||
10186 | static void | |
10187 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10188 | { | |
10189 | struct bp_location *bl = b->loc; | |
79a45e25 | 10190 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10191 | |
10192 | gdb_assert (bl); | |
10193 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10194 | ||
10195 | if (ui_out_is_mi_like_p (uiout)) | |
10196 | return; | |
10197 | ||
10198 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10199 | b->number, paddress (bl->gdbarch, bl->address), | |
10200 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10201 | } | |
10202 | ||
10203 | /* Implement the "print_recreate" breakpoint_ops method for | |
10204 | ranged breakpoints. */ | |
10205 | ||
10206 | static void | |
10207 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10208 | { | |
10209 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10210 | b->addr_string_range_end); | |
d9b3f62e | 10211 | print_recreate_thread (b, fp); |
f1310107 TJB |
10212 | } |
10213 | ||
10214 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10215 | ||
2060206e | 10216 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10217 | |
10218 | /* Find the address where the end of the breakpoint range should be | |
10219 | placed, given the SAL of the end of the range. This is so that if | |
10220 | the user provides a line number, the end of the range is set to the | |
10221 | last instruction of the given line. */ | |
10222 | ||
10223 | static CORE_ADDR | |
10224 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10225 | { | |
10226 | CORE_ADDR end; | |
10227 | ||
10228 | /* If the user provided a PC value, use it. Otherwise, | |
10229 | find the address of the end of the given location. */ | |
10230 | if (sal.explicit_pc) | |
10231 | end = sal.pc; | |
10232 | else | |
10233 | { | |
10234 | int ret; | |
10235 | CORE_ADDR start; | |
10236 | ||
10237 | ret = find_line_pc_range (sal, &start, &end); | |
10238 | if (!ret) | |
10239 | error (_("Could not find location of the end of the range.")); | |
10240 | ||
10241 | /* find_line_pc_range returns the start of the next line. */ | |
10242 | end--; | |
10243 | } | |
10244 | ||
10245 | return end; | |
10246 | } | |
10247 | ||
10248 | /* Implement the "break-range" CLI command. */ | |
10249 | ||
10250 | static void | |
10251 | break_range_command (char *arg, int from_tty) | |
10252 | { | |
10253 | char *arg_start, *addr_string_start, *addr_string_end; | |
10254 | struct linespec_result canonical_start, canonical_end; | |
10255 | int bp_count, can_use_bp, length; | |
10256 | CORE_ADDR end; | |
10257 | struct breakpoint *b; | |
10258 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10259 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10260 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10261 | |
10262 | /* We don't support software ranged breakpoints. */ | |
10263 | if (target_ranged_break_num_registers () < 0) | |
10264 | error (_("This target does not support hardware ranged breakpoints.")); | |
10265 | ||
10266 | bp_count = hw_breakpoint_used_count (); | |
10267 | bp_count += target_ranged_break_num_registers (); | |
10268 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10269 | bp_count, 0); | |
10270 | if (can_use_bp < 0) | |
10271 | error (_("Hardware breakpoints used exceeds limit.")); | |
10272 | ||
f8eba3c6 | 10273 | arg = skip_spaces (arg); |
f1310107 TJB |
10274 | if (arg == NULL || arg[0] == '\0') |
10275 | error(_("No address range specified.")); | |
10276 | ||
f1310107 TJB |
10277 | init_linespec_result (&canonical_start); |
10278 | ||
f8eba3c6 TT |
10279 | arg_start = arg; |
10280 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10281 | |
f8eba3c6 | 10282 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10283 | |
10284 | if (arg[0] != ',') | |
10285 | error (_("Too few arguments.")); | |
f8eba3c6 | 10286 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10287 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10288 | |
10289 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10290 | ||
10291 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10292 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10293 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10294 | ||
f8eba3c6 TT |
10295 | sal_start = lsal_start->sals.sals[0]; |
10296 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10297 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10298 | |
10299 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10300 | arg = skip_spaces (arg); |
f1310107 TJB |
10301 | |
10302 | /* Parse the end location. */ | |
10303 | ||
f1310107 TJB |
10304 | init_linespec_result (&canonical_end); |
10305 | arg_start = arg; | |
10306 | ||
f8eba3c6 | 10307 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10308 | parse_breakpoint_sals because we need to specify the start location's |
10309 | symtab and line as the default symtab and line for the end of the | |
10310 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10311 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10312 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10313 | sal_start.symtab, sal_start.line, | |
10314 | &canonical_end, NULL, NULL); | |
10315 | ||
10316 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10317 | |
f8eba3c6 | 10318 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10319 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10320 | |
10321 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10322 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10323 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10324 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10325 | ||
f8eba3c6 TT |
10326 | sal_end = lsal_end->sals.sals[0]; |
10327 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10328 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10329 | |
10330 | end = find_breakpoint_range_end (sal_end); | |
10331 | if (sal_start.pc > end) | |
177b42fe | 10332 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10333 | |
10334 | length = end - sal_start.pc + 1; | |
10335 | if (length < 0) | |
10336 | /* Length overflowed. */ | |
10337 | error (_("Address range too large.")); | |
10338 | else if (length == 1) | |
10339 | { | |
10340 | /* This range is simple enough to be handled by | |
10341 | the `hbreak' command. */ | |
10342 | hbreak_command (addr_string_start, 1); | |
10343 | ||
10344 | do_cleanups (cleanup_bkpt); | |
10345 | ||
10346 | return; | |
10347 | } | |
10348 | ||
10349 | /* Now set up the breakpoint. */ | |
10350 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10351 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10352 | set_breakpoint_count (breakpoint_count + 1); |
10353 | b->number = breakpoint_count; | |
10354 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10355 | b->addr_string = xstrdup (addr_string_start); |
10356 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10357 | b->loc->length = length; |
10358 | ||
f8eba3c6 | 10359 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10360 | |
10361 | mention (b); | |
8d3788bd | 10362 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10363 | update_global_location_list (1); |
10364 | } | |
10365 | ||
4a64f543 MS |
10366 | /* Return non-zero if EXP is verified as constant. Returned zero |
10367 | means EXP is variable. Also the constant detection may fail for | |
10368 | some constant expressions and in such case still falsely return | |
10369 | zero. */ | |
2e6e3d9c | 10370 | |
65d79d4b SDJ |
10371 | static int |
10372 | watchpoint_exp_is_const (const struct expression *exp) | |
10373 | { | |
10374 | int i = exp->nelts; | |
10375 | ||
10376 | while (i > 0) | |
10377 | { | |
10378 | int oplenp, argsp; | |
10379 | ||
10380 | /* We are only interested in the descriptor of each element. */ | |
10381 | operator_length (exp, i, &oplenp, &argsp); | |
10382 | i -= oplenp; | |
10383 | ||
10384 | switch (exp->elts[i].opcode) | |
10385 | { | |
10386 | case BINOP_ADD: | |
10387 | case BINOP_SUB: | |
10388 | case BINOP_MUL: | |
10389 | case BINOP_DIV: | |
10390 | case BINOP_REM: | |
10391 | case BINOP_MOD: | |
10392 | case BINOP_LSH: | |
10393 | case BINOP_RSH: | |
10394 | case BINOP_LOGICAL_AND: | |
10395 | case BINOP_LOGICAL_OR: | |
10396 | case BINOP_BITWISE_AND: | |
10397 | case BINOP_BITWISE_IOR: | |
10398 | case BINOP_BITWISE_XOR: | |
10399 | case BINOP_EQUAL: | |
10400 | case BINOP_NOTEQUAL: | |
10401 | case BINOP_LESS: | |
10402 | case BINOP_GTR: | |
10403 | case BINOP_LEQ: | |
10404 | case BINOP_GEQ: | |
10405 | case BINOP_REPEAT: | |
10406 | case BINOP_COMMA: | |
10407 | case BINOP_EXP: | |
10408 | case BINOP_MIN: | |
10409 | case BINOP_MAX: | |
10410 | case BINOP_INTDIV: | |
10411 | case BINOP_CONCAT: | |
10412 | case BINOP_IN: | |
10413 | case BINOP_RANGE: | |
10414 | case TERNOP_COND: | |
10415 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10416 | |
10417 | case OP_LONG: | |
10418 | case OP_DOUBLE: | |
10419 | case OP_DECFLOAT: | |
10420 | case OP_LAST: | |
10421 | case OP_COMPLEX: | |
10422 | case OP_STRING: | |
65d79d4b SDJ |
10423 | case OP_ARRAY: |
10424 | case OP_TYPE: | |
608b4967 TT |
10425 | case OP_TYPEOF: |
10426 | case OP_DECLTYPE: | |
6e72ca20 | 10427 | case OP_TYPEID: |
65d79d4b SDJ |
10428 | case OP_NAME: |
10429 | case OP_OBJC_NSSTRING: | |
10430 | ||
10431 | case UNOP_NEG: | |
10432 | case UNOP_LOGICAL_NOT: | |
10433 | case UNOP_COMPLEMENT: | |
10434 | case UNOP_ADDR: | |
10435 | case UNOP_HIGH: | |
aeaa2474 | 10436 | case UNOP_CAST: |
9eaf6705 TT |
10437 | |
10438 | case UNOP_CAST_TYPE: | |
10439 | case UNOP_REINTERPRET_CAST: | |
10440 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10441 | /* Unary, binary and ternary operators: We have to check |
10442 | their operands. If they are constant, then so is the | |
10443 | result of that operation. For instance, if A and B are | |
10444 | determined to be constants, then so is "A + B". | |
10445 | ||
10446 | UNOP_IND is one exception to the rule above, because the | |
10447 | value of *ADDR is not necessarily a constant, even when | |
10448 | ADDR is. */ | |
65d79d4b SDJ |
10449 | break; |
10450 | ||
10451 | case OP_VAR_VALUE: | |
10452 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10453 | |
65d79d4b | 10454 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10455 | possible that a buggy compiler could mark a variable as |
10456 | constant even when it is not, and TYPE_CONST would return | |
10457 | true in this case, while SYMBOL_CLASS wouldn't. | |
10458 | ||
10459 | We also have to check for function symbols because they | |
10460 | are always constant. */ | |
65d79d4b SDJ |
10461 | { |
10462 | struct symbol *s = exp->elts[i + 2].symbol; | |
10463 | ||
10464 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10465 | && SYMBOL_CLASS (s) != LOC_CONST | |
10466 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10467 | return 0; | |
10468 | break; | |
10469 | } | |
10470 | ||
10471 | /* The default action is to return 0 because we are using | |
10472 | the optimistic approach here: If we don't know something, | |
10473 | then it is not a constant. */ | |
10474 | default: | |
10475 | return 0; | |
10476 | } | |
10477 | } | |
10478 | ||
10479 | return 1; | |
10480 | } | |
10481 | ||
3a5c3e22 PA |
10482 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10483 | ||
10484 | static void | |
10485 | dtor_watchpoint (struct breakpoint *self) | |
10486 | { | |
10487 | struct watchpoint *w = (struct watchpoint *) self; | |
10488 | ||
10489 | xfree (w->cond_exp); | |
10490 | xfree (w->exp); | |
10491 | xfree (w->exp_string); | |
10492 | xfree (w->exp_string_reparse); | |
10493 | value_free (w->val); | |
10494 | ||
10495 | base_breakpoint_ops.dtor (self); | |
10496 | } | |
10497 | ||
348d480f PA |
10498 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10499 | ||
10500 | static void | |
10501 | re_set_watchpoint (struct breakpoint *b) | |
10502 | { | |
3a5c3e22 PA |
10503 | struct watchpoint *w = (struct watchpoint *) b; |
10504 | ||
348d480f PA |
10505 | /* Watchpoint can be either on expression using entirely global |
10506 | variables, or it can be on local variables. | |
10507 | ||
10508 | Watchpoints of the first kind are never auto-deleted, and even | |
10509 | persist across program restarts. Since they can use variables | |
10510 | from shared libraries, we need to reparse expression as libraries | |
10511 | are loaded and unloaded. | |
10512 | ||
10513 | Watchpoints on local variables can also change meaning as result | |
10514 | of solib event. For example, if a watchpoint uses both a local | |
10515 | and a global variables in expression, it's a local watchpoint, | |
10516 | but unloading of a shared library will make the expression | |
10517 | invalid. This is not a very common use case, but we still | |
10518 | re-evaluate expression, to avoid surprises to the user. | |
10519 | ||
10520 | Note that for local watchpoints, we re-evaluate it only if | |
10521 | watchpoints frame id is still valid. If it's not, it means the | |
10522 | watchpoint is out of scope and will be deleted soon. In fact, | |
10523 | I'm not sure we'll ever be called in this case. | |
10524 | ||
10525 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10526 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10527 | |
3a5c3e22 PA |
10528 | Don't do anything about disabled watchpoints, since they will be |
10529 | reevaluated again when enabled. */ | |
10530 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10531 | } |
10532 | ||
77b06cd7 TJB |
10533 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10534 | ||
10535 | static int | |
10536 | insert_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_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10542 | w->cond_exp); |
77b06cd7 TJB |
10543 | } |
10544 | ||
10545 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10546 | ||
10547 | static int | |
10548 | remove_watchpoint (struct bp_location *bl) | |
10549 | { | |
3a5c3e22 PA |
10550 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10551 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10552 | |
10553 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10554 | w->cond_exp); |
e09342b5 TJB |
10555 | } |
10556 | ||
e09342b5 | 10557 | static int |
348d480f | 10558 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10559 | struct address_space *aspace, CORE_ADDR bp_addr, |
10560 | const struct target_waitstatus *ws) | |
e09342b5 | 10561 | { |
348d480f | 10562 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10563 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10564 | |
348d480f PA |
10565 | /* Continuable hardware watchpoints are treated as non-existent if the |
10566 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10567 | some data address). Otherwise gdb won't stop on a break instruction | |
10568 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10569 | been defined. Also skip watchpoints which we know did not trigger | |
10570 | (did not match the data address). */ | |
10571 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10572 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10573 | return 0; |
9c06b0b4 | 10574 | |
348d480f | 10575 | return 1; |
9c06b0b4 TJB |
10576 | } |
10577 | ||
348d480f PA |
10578 | static void |
10579 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10580 | { |
348d480f | 10581 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10582 | |
348d480f | 10583 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10584 | } |
10585 | ||
10586 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10587 | hardware watchpoints. */ |
9c06b0b4 TJB |
10588 | |
10589 | static int | |
348d480f | 10590 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10591 | { |
3a5c3e22 PA |
10592 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10593 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10594 | |
10595 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10596 | } |
10597 | ||
10598 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10599 | hardware watchpoints. */ |
9c06b0b4 TJB |
10600 | |
10601 | static int | |
348d480f | 10602 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10603 | { |
efa80663 PA |
10604 | /* Read and access watchpoints only work with hardware support. */ |
10605 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10606 | } |
10607 | ||
9c06b0b4 | 10608 | static enum print_stop_action |
348d480f | 10609 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10610 | { |
348d480f PA |
10611 | struct cleanup *old_chain; |
10612 | struct breakpoint *b; | |
f99d8bf4 | 10613 | struct ui_file *stb; |
348d480f | 10614 | enum print_stop_action result; |
3a5c3e22 | 10615 | struct watchpoint *w; |
79a45e25 | 10616 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10617 | |
10618 | gdb_assert (bs->bp_location_at != NULL); | |
10619 | ||
348d480f | 10620 | b = bs->breakpoint_at; |
3a5c3e22 | 10621 | w = (struct watchpoint *) b; |
348d480f | 10622 | |
f99d8bf4 PA |
10623 | stb = mem_fileopen (); |
10624 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10625 | |
10626 | switch (b->type) | |
10627 | { | |
348d480f | 10628 | case bp_watchpoint: |
9c06b0b4 TJB |
10629 | case bp_hardware_watchpoint: |
10630 | annotate_watchpoint (b->number); | |
10631 | if (ui_out_is_mi_like_p (uiout)) | |
10632 | ui_out_field_string | |
10633 | (uiout, "reason", | |
10634 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10635 | mention (b); |
10636 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10637 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10638 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10639 | ui_out_field_stream (uiout, "old", stb); |
10640 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10641 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10642 | ui_out_field_stream (uiout, "new", stb); |
10643 | ui_out_text (uiout, "\n"); | |
10644 | /* More than one watchpoint may have been triggered. */ | |
10645 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10646 | break; |
10647 | ||
10648 | case bp_read_watchpoint: | |
10649 | if (ui_out_is_mi_like_p (uiout)) | |
10650 | ui_out_field_string | |
10651 | (uiout, "reason", | |
10652 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10653 | mention (b); |
10654 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10655 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10656 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10657 | ui_out_field_stream (uiout, "value", stb); |
10658 | ui_out_text (uiout, "\n"); | |
10659 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10660 | break; |
10661 | ||
10662 | case bp_access_watchpoint: | |
348d480f PA |
10663 | if (bs->old_val != NULL) |
10664 | { | |
10665 | annotate_watchpoint (b->number); | |
10666 | if (ui_out_is_mi_like_p (uiout)) | |
10667 | ui_out_field_string | |
10668 | (uiout, "reason", | |
10669 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10670 | mention (b); | |
10671 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10672 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10673 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10674 | ui_out_field_stream (uiout, "old", stb); |
10675 | ui_out_text (uiout, "\nNew value = "); | |
10676 | } | |
10677 | else | |
10678 | { | |
10679 | mention (b); | |
10680 | if (ui_out_is_mi_like_p (uiout)) | |
10681 | ui_out_field_string | |
10682 | (uiout, "reason", | |
10683 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10684 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10685 | ui_out_text (uiout, "\nValue = "); | |
10686 | } | |
f99d8bf4 | 10687 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10688 | ui_out_field_stream (uiout, "new", stb); |
10689 | ui_out_text (uiout, "\n"); | |
10690 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10691 | break; |
10692 | default: | |
348d480f | 10693 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10694 | } |
10695 | ||
348d480f PA |
10696 | do_cleanups (old_chain); |
10697 | return result; | |
10698 | } | |
10699 | ||
10700 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10701 | watchpoints. */ | |
10702 | ||
10703 | static void | |
10704 | print_mention_watchpoint (struct breakpoint *b) | |
10705 | { | |
10706 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10707 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10708 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10709 | |
10710 | switch (b->type) | |
10711 | { | |
10712 | case bp_watchpoint: | |
10713 | ui_out_text (uiout, "Watchpoint "); | |
10714 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10715 | break; | |
10716 | case bp_hardware_watchpoint: | |
10717 | ui_out_text (uiout, "Hardware watchpoint "); | |
10718 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10719 | break; | |
10720 | case bp_read_watchpoint: | |
10721 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10722 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10723 | break; | |
10724 | case bp_access_watchpoint: | |
10725 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10726 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10727 | break; | |
10728 | default: | |
10729 | internal_error (__FILE__, __LINE__, | |
10730 | _("Invalid hardware watchpoint type.")); | |
10731 | } | |
10732 | ||
10733 | ui_out_field_int (uiout, "number", b->number); | |
10734 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10735 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10736 | do_cleanups (ui_out_chain); |
10737 | } | |
10738 | ||
10739 | /* Implement the "print_recreate" breakpoint_ops method for | |
10740 | watchpoints. */ | |
10741 | ||
10742 | static void | |
10743 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10744 | { | |
3a5c3e22 PA |
10745 | struct watchpoint *w = (struct watchpoint *) b; |
10746 | ||
348d480f PA |
10747 | switch (b->type) |
10748 | { | |
10749 | case bp_watchpoint: | |
10750 | case bp_hardware_watchpoint: | |
10751 | fprintf_unfiltered (fp, "watch"); | |
10752 | break; | |
10753 | case bp_read_watchpoint: | |
10754 | fprintf_unfiltered (fp, "rwatch"); | |
10755 | break; | |
10756 | case bp_access_watchpoint: | |
10757 | fprintf_unfiltered (fp, "awatch"); | |
10758 | break; | |
10759 | default: | |
10760 | internal_error (__FILE__, __LINE__, | |
10761 | _("Invalid watchpoint type.")); | |
10762 | } | |
10763 | ||
3a5c3e22 | 10764 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10765 | print_recreate_thread (b, fp); |
348d480f PA |
10766 | } |
10767 | ||
427cd150 TT |
10768 | /* Implement the "explains_signal" breakpoint_ops method for |
10769 | watchpoints. */ | |
10770 | ||
47591c29 | 10771 | static int |
427cd150 TT |
10772 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10773 | { | |
10774 | /* A software watchpoint cannot cause a signal other than | |
10775 | GDB_SIGNAL_TRAP. */ | |
10776 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10777 | return 0; |
427cd150 | 10778 | |
47591c29 | 10779 | return 1; |
427cd150 TT |
10780 | } |
10781 | ||
348d480f PA |
10782 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10783 | ||
2060206e | 10784 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10785 | |
10786 | /* Implement the "insert" breakpoint_ops method for | |
10787 | masked hardware watchpoints. */ | |
10788 | ||
10789 | static int | |
10790 | insert_masked_watchpoint (struct bp_location *bl) | |
10791 | { | |
3a5c3e22 PA |
10792 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10793 | ||
10794 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10795 | bl->watchpoint_type); |
10796 | } | |
10797 | ||
10798 | /* Implement the "remove" breakpoint_ops method for | |
10799 | masked hardware watchpoints. */ | |
10800 | ||
10801 | static int | |
10802 | remove_masked_watchpoint (struct bp_location *bl) | |
10803 | { | |
3a5c3e22 PA |
10804 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10805 | ||
10806 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10807 | bl->watchpoint_type); |
10808 | } | |
10809 | ||
10810 | /* Implement the "resources_needed" breakpoint_ops method for | |
10811 | masked hardware watchpoints. */ | |
10812 | ||
10813 | static int | |
10814 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10815 | { | |
3a5c3e22 PA |
10816 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10817 | ||
10818 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10819 | } |
10820 | ||
10821 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10822 | masked hardware watchpoints. */ | |
10823 | ||
10824 | static int | |
10825 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10826 | { | |
10827 | return 0; | |
10828 | } | |
10829 | ||
10830 | /* Implement the "print_it" breakpoint_ops method for | |
10831 | masked hardware watchpoints. */ | |
10832 | ||
10833 | static enum print_stop_action | |
10834 | print_it_masked_watchpoint (bpstat bs) | |
10835 | { | |
10836 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10837 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10838 | |
10839 | /* Masked watchpoints have only one location. */ | |
10840 | gdb_assert (b->loc && b->loc->next == NULL); | |
10841 | ||
10842 | switch (b->type) | |
10843 | { | |
10844 | case bp_hardware_watchpoint: | |
10845 | annotate_watchpoint (b->number); | |
10846 | if (ui_out_is_mi_like_p (uiout)) | |
10847 | ui_out_field_string | |
10848 | (uiout, "reason", | |
10849 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10850 | break; | |
10851 | ||
10852 | case bp_read_watchpoint: | |
10853 | if (ui_out_is_mi_like_p (uiout)) | |
10854 | ui_out_field_string | |
10855 | (uiout, "reason", | |
10856 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10857 | break; | |
10858 | ||
10859 | case bp_access_watchpoint: | |
10860 | if (ui_out_is_mi_like_p (uiout)) | |
10861 | ui_out_field_string | |
10862 | (uiout, "reason", | |
10863 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10864 | break; | |
10865 | default: | |
10866 | internal_error (__FILE__, __LINE__, | |
10867 | _("Invalid hardware watchpoint type.")); | |
10868 | } | |
10869 | ||
10870 | mention (b); | |
9c06b0b4 TJB |
10871 | ui_out_text (uiout, _("\n\ |
10872 | Check the underlying instruction at PC for the memory\n\ | |
10873 | address and value which triggered this watchpoint.\n")); | |
10874 | ui_out_text (uiout, "\n"); | |
10875 | ||
10876 | /* More than one watchpoint may have been triggered. */ | |
10877 | return PRINT_UNKNOWN; | |
10878 | } | |
10879 | ||
10880 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10881 | masked hardware watchpoints. */ | |
10882 | ||
10883 | static void | |
10884 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10885 | struct ui_out *uiout) | |
10886 | { | |
3a5c3e22 PA |
10887 | struct watchpoint *w = (struct watchpoint *) b; |
10888 | ||
9c06b0b4 TJB |
10889 | /* Masked watchpoints have only one location. */ |
10890 | gdb_assert (b->loc && b->loc->next == NULL); | |
10891 | ||
10892 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10893 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10894 | ui_out_text (uiout, "\n"); |
10895 | } | |
10896 | ||
10897 | /* Implement the "print_mention" breakpoint_ops method for | |
10898 | masked hardware watchpoints. */ | |
10899 | ||
10900 | static void | |
10901 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10902 | { | |
3a5c3e22 | 10903 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10904 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10905 | struct cleanup *ui_out_chain; |
10906 | ||
10907 | switch (b->type) | |
10908 | { | |
10909 | case bp_hardware_watchpoint: | |
10910 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10911 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10912 | break; | |
10913 | case bp_read_watchpoint: | |
10914 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10915 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10916 | break; | |
10917 | case bp_access_watchpoint: | |
10918 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10919 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10920 | break; | |
10921 | default: | |
10922 | internal_error (__FILE__, __LINE__, | |
10923 | _("Invalid hardware watchpoint type.")); | |
10924 | } | |
10925 | ||
10926 | ui_out_field_int (uiout, "number", b->number); | |
10927 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10928 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10929 | do_cleanups (ui_out_chain); |
10930 | } | |
10931 | ||
10932 | /* Implement the "print_recreate" breakpoint_ops method for | |
10933 | masked hardware watchpoints. */ | |
10934 | ||
10935 | static void | |
10936 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10937 | { | |
3a5c3e22 | 10938 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10939 | char tmp[40]; |
10940 | ||
10941 | switch (b->type) | |
10942 | { | |
10943 | case bp_hardware_watchpoint: | |
10944 | fprintf_unfiltered (fp, "watch"); | |
10945 | break; | |
10946 | case bp_read_watchpoint: | |
10947 | fprintf_unfiltered (fp, "rwatch"); | |
10948 | break; | |
10949 | case bp_access_watchpoint: | |
10950 | fprintf_unfiltered (fp, "awatch"); | |
10951 | break; | |
10952 | default: | |
10953 | internal_error (__FILE__, __LINE__, | |
10954 | _("Invalid hardware watchpoint type.")); | |
10955 | } | |
10956 | ||
3a5c3e22 PA |
10957 | sprintf_vma (tmp, w->hw_wp_mask); |
10958 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10959 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10960 | } |
10961 | ||
10962 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10963 | ||
2060206e | 10964 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10965 | |
10966 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10967 | ||
10968 | static int | |
10969 | is_masked_watchpoint (const struct breakpoint *b) | |
10970 | { | |
10971 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10972 | } | |
10973 | ||
53a5351d JM |
10974 | /* accessflag: hw_write: watch write, |
10975 | hw_read: watch read, | |
10976 | hw_access: watch access (read or write) */ | |
c906108c | 10977 | static void |
bbc13ae3 | 10978 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10979 | int just_location, int internal) |
c906108c | 10980 | { |
a9634178 | 10981 | volatile struct gdb_exception e; |
d983da9c | 10982 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10983 | struct expression *exp; |
270140bd | 10984 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10985 | struct value *val, *mark, *result; |
c906108c | 10986 | struct frame_info *frame; |
bbc13ae3 KS |
10987 | const char *exp_start = NULL; |
10988 | const char *exp_end = NULL; | |
10989 | const char *tok, *end_tok; | |
9c06b0b4 | 10990 | int toklen = -1; |
bbc13ae3 KS |
10991 | const char *cond_start = NULL; |
10992 | const char *cond_end = NULL; | |
c906108c | 10993 | enum bptype bp_type; |
37e4754d | 10994 | int thread = -1; |
0cf6dd15 | 10995 | int pc = 0; |
9c06b0b4 TJB |
10996 | /* Flag to indicate whether we are going to use masks for |
10997 | the hardware watchpoint. */ | |
10998 | int use_mask = 0; | |
10999 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11000 | struct watchpoint *w; |
bbc13ae3 KS |
11001 | char *expression; |
11002 | struct cleanup *back_to; | |
c906108c | 11003 | |
37e4754d LM |
11004 | /* Make sure that we actually have parameters to parse. */ |
11005 | if (arg != NULL && arg[0] != '\0') | |
11006 | { | |
bbc13ae3 KS |
11007 | const char *value_start; |
11008 | ||
11009 | exp_end = arg + strlen (arg); | |
37e4754d | 11010 | |
9c06b0b4 TJB |
11011 | /* Look for "parameter value" pairs at the end |
11012 | of the arguments string. */ | |
bbc13ae3 | 11013 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11014 | { |
11015 | /* Skip whitespace at the end of the argument list. */ | |
11016 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11017 | tok--; | |
11018 | ||
11019 | /* Find the beginning of the last token. | |
11020 | This is the value of the parameter. */ | |
11021 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11022 | tok--; | |
11023 | value_start = tok + 1; | |
11024 | ||
11025 | /* Skip whitespace. */ | |
11026 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11027 | tok--; | |
11028 | ||
11029 | end_tok = tok; | |
11030 | ||
11031 | /* Find the beginning of the second to last token. | |
11032 | This is the parameter itself. */ | |
11033 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11034 | tok--; | |
11035 | tok++; | |
11036 | toklen = end_tok - tok + 1; | |
11037 | ||
11038 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11039 | { | |
11040 | /* At this point we've found a "thread" token, which means | |
11041 | the user is trying to set a watchpoint that triggers | |
11042 | only in a specific thread. */ | |
11043 | char *endp; | |
37e4754d | 11044 | |
9c06b0b4 TJB |
11045 | if (thread != -1) |
11046 | error(_("You can specify only one thread.")); | |
37e4754d | 11047 | |
9c06b0b4 TJB |
11048 | /* Extract the thread ID from the next token. */ |
11049 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11050 | |
9c06b0b4 TJB |
11051 | /* Check if the user provided a valid numeric value for the |
11052 | thread ID. */ | |
11053 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11054 | error (_("Invalid thread ID specification %s."), value_start); | |
11055 | ||
11056 | /* Check if the thread actually exists. */ | |
11057 | if (!valid_thread_id (thread)) | |
af4908ba | 11058 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11059 | } |
11060 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11061 | { | |
11062 | /* We've found a "mask" token, which means the user wants to | |
11063 | create a hardware watchpoint that is going to have the mask | |
11064 | facility. */ | |
11065 | struct value *mask_value, *mark; | |
37e4754d | 11066 | |
9c06b0b4 TJB |
11067 | if (use_mask) |
11068 | error(_("You can specify only one mask.")); | |
37e4754d | 11069 | |
9c06b0b4 | 11070 | use_mask = just_location = 1; |
37e4754d | 11071 | |
9c06b0b4 TJB |
11072 | mark = value_mark (); |
11073 | mask_value = parse_to_comma_and_eval (&value_start); | |
11074 | mask = value_as_address (mask_value); | |
11075 | value_free_to_mark (mark); | |
11076 | } | |
11077 | else | |
11078 | /* We didn't recognize what we found. We should stop here. */ | |
11079 | break; | |
37e4754d | 11080 | |
9c06b0b4 TJB |
11081 | /* Truncate the string and get rid of the "parameter value" pair before |
11082 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11083 | exp_end = tok; |
9c06b0b4 | 11084 | } |
37e4754d | 11085 | } |
bbc13ae3 KS |
11086 | else |
11087 | exp_end = arg; | |
37e4754d | 11088 | |
bbc13ae3 KS |
11089 | /* Parse the rest of the arguments. From here on out, everything |
11090 | is in terms of a newly allocated string instead of the original | |
11091 | ARG. */ | |
c906108c | 11092 | innermost_block = NULL; |
bbc13ae3 KS |
11093 | expression = savestring (arg, exp_end - arg); |
11094 | back_to = make_cleanup (xfree, expression); | |
11095 | exp_start = arg = expression; | |
1bb9788d | 11096 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11097 | exp_end = arg; |
fa8a61dc TT |
11098 | /* Remove trailing whitespace from the expression before saving it. |
11099 | This makes the eventual display of the expression string a bit | |
11100 | prettier. */ | |
11101 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11102 | --exp_end; | |
11103 | ||
65d79d4b SDJ |
11104 | /* Checking if the expression is not constant. */ |
11105 | if (watchpoint_exp_is_const (exp)) | |
11106 | { | |
11107 | int len; | |
11108 | ||
11109 | len = exp_end - exp_start; | |
11110 | while (len > 0 && isspace (exp_start[len - 1])) | |
11111 | len--; | |
11112 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11113 | } | |
11114 | ||
c906108c SS |
11115 | exp_valid_block = innermost_block; |
11116 | mark = value_mark (); | |
3a1115a0 | 11117 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11118 | |
11119 | if (just_location) | |
11120 | { | |
9c06b0b4 TJB |
11121 | int ret; |
11122 | ||
06a64a0b | 11123 | exp_valid_block = NULL; |
a1442452 | 11124 | val = value_addr (result); |
06a64a0b TT |
11125 | release_value (val); |
11126 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11127 | |
11128 | if (use_mask) | |
11129 | { | |
11130 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11131 | mask); | |
11132 | if (ret == -1) | |
11133 | error (_("This target does not support masked watchpoints.")); | |
11134 | else if (ret == -2) | |
11135 | error (_("Invalid mask or memory region.")); | |
11136 | } | |
06a64a0b TT |
11137 | } |
11138 | else if (val != NULL) | |
fa4727a6 | 11139 | release_value (val); |
c906108c | 11140 | |
bbc13ae3 KS |
11141 | tok = skip_spaces_const (arg); |
11142 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11143 | |
11144 | toklen = end_tok - tok; | |
11145 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11146 | { | |
2d134ed3 PA |
11147 | struct expression *cond; |
11148 | ||
60e1c644 | 11149 | innermost_block = NULL; |
c906108c | 11150 | tok = cond_start = end_tok + 1; |
1bb9788d | 11151 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11152 | |
11153 | /* The watchpoint expression may not be local, but the condition | |
11154 | may still be. E.g.: `watch global if local > 0'. */ | |
11155 | cond_exp_valid_block = innermost_block; | |
11156 | ||
2d134ed3 | 11157 | xfree (cond); |
c906108c SS |
11158 | cond_end = tok; |
11159 | } | |
11160 | if (*tok) | |
8a3fe4f8 | 11161 | error (_("Junk at end of command.")); |
c906108c | 11162 | |
d983da9c | 11163 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11164 | |
11165 | /* If the expression is "local", then set up a "watchpoint scope" | |
11166 | breakpoint at the point where we've left the scope of the watchpoint | |
11167 | expression. Create the scope breakpoint before the watchpoint, so | |
11168 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11169 | if (exp_valid_block && frame) |
d983da9c | 11170 | { |
edb3359d DJ |
11171 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11172 | { | |
11173 | scope_breakpoint | |
a6d9a66e UW |
11174 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11175 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11176 | bp_watchpoint_scope, |
11177 | &momentary_breakpoint_ops); | |
d983da9c | 11178 | |
edb3359d | 11179 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11180 | |
edb3359d DJ |
11181 | /* Automatically delete the breakpoint when it hits. */ |
11182 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11183 | |
edb3359d DJ |
11184 | /* Only break in the proper frame (help with recursion). */ |
11185 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11186 | |
edb3359d | 11187 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11188 | scope_breakpoint->loc->gdbarch |
11189 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11190 | scope_breakpoint->loc->requested_address |
11191 | = frame_unwind_caller_pc (frame); | |
11192 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11193 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11194 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11195 | scope_breakpoint->type); |
11196 | } | |
d983da9c DJ |
11197 | } |
11198 | ||
e8369a73 AB |
11199 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11200 | watchpoints here even if hardware watchpoints are turned off, a call | |
11201 | to update_watchpoint later in this function will cause the type to | |
11202 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11203 | ||
11204 | if (accessflag == hw_read) | |
11205 | bp_type = bp_read_watchpoint; | |
11206 | else if (accessflag == hw_access) | |
11207 | bp_type = bp_access_watchpoint; | |
11208 | else | |
11209 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11210 | |
11211 | w = XCNEW (struct watchpoint); | |
11212 | b = &w->base; | |
348d480f | 11213 | if (use_mask) |
3a5c3e22 PA |
11214 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11215 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11216 | else |
3a5c3e22 PA |
11217 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11218 | &watchpoint_breakpoint_ops); | |
37e4754d | 11219 | b->thread = thread; |
b5de0fa7 | 11220 | b->disposition = disp_donttouch; |
348d480f | 11221 | b->pspace = current_program_space; |
3a5c3e22 PA |
11222 | w->exp = exp; |
11223 | w->exp_valid_block = exp_valid_block; | |
11224 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11225 | if (just_location) |
11226 | { | |
11227 | struct type *t = value_type (val); | |
11228 | CORE_ADDR addr = value_as_address (val); | |
11229 | char *name; | |
11230 | ||
11231 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11232 | name = type_to_string (t); | |
11233 | ||
3a5c3e22 | 11234 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11235 | core_addr_to_string (addr)); |
06a64a0b TT |
11236 | xfree (name); |
11237 | ||
3a5c3e22 | 11238 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11239 | (int) (exp_end - exp_start), exp_start); |
11240 | ||
06a64a0b TT |
11241 | /* The above expression is in C. */ |
11242 | b->language = language_c; | |
11243 | } | |
11244 | else | |
3a5c3e22 | 11245 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11246 | |
11247 | if (use_mask) | |
11248 | { | |
3a5c3e22 | 11249 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11250 | } |
11251 | else | |
11252 | { | |
3a5c3e22 PA |
11253 | w->val = val; |
11254 | w->val_valid = 1; | |
9c06b0b4 | 11255 | } |
77b06cd7 | 11256 | |
c906108c SS |
11257 | if (cond_start) |
11258 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11259 | else | |
11260 | b->cond_string = 0; | |
c5aa993b | 11261 | |
c906108c | 11262 | if (frame) |
f6bc2008 | 11263 | { |
3a5c3e22 PA |
11264 | w->watchpoint_frame = get_frame_id (frame); |
11265 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11266 | } |
c906108c | 11267 | else |
f6bc2008 | 11268 | { |
3a5c3e22 PA |
11269 | w->watchpoint_frame = null_frame_id; |
11270 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11271 | } |
c906108c | 11272 | |
d983da9c | 11273 | if (scope_breakpoint != NULL) |
c906108c | 11274 | { |
d983da9c DJ |
11275 | /* The scope breakpoint is related to the watchpoint. We will |
11276 | need to act on them together. */ | |
11277 | b->related_breakpoint = scope_breakpoint; | |
11278 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11279 | } |
d983da9c | 11280 | |
06a64a0b TT |
11281 | if (!just_location) |
11282 | value_free_to_mark (mark); | |
2d134ed3 | 11283 | |
a9634178 TJB |
11284 | TRY_CATCH (e, RETURN_MASK_ALL) |
11285 | { | |
11286 | /* Finally update the new watchpoint. This creates the locations | |
11287 | that should be inserted. */ | |
3a5c3e22 | 11288 | update_watchpoint (w, 1); |
a9634178 TJB |
11289 | } |
11290 | if (e.reason < 0) | |
11291 | { | |
11292 | delete_breakpoint (b); | |
11293 | throw_exception (e); | |
11294 | } | |
11295 | ||
3ea46bff | 11296 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11297 | do_cleanups (back_to); |
c906108c SS |
11298 | } |
11299 | ||
e09342b5 | 11300 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11301 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11302 | |
c906108c | 11303 | static int |
a9634178 | 11304 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11305 | { |
11306 | int found_memory_cnt = 0; | |
2e70b7b9 | 11307 | struct value *head = v; |
c906108c SS |
11308 | |
11309 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11310 | if (!can_use_hw_watchpoints) |
c906108c | 11311 | return 0; |
c5aa993b | 11312 | |
5c44784c JM |
11313 | /* Make sure that the value of the expression depends only upon |
11314 | memory contents, and values computed from them within GDB. If we | |
11315 | find any register references or function calls, we can't use a | |
11316 | hardware watchpoint. | |
11317 | ||
11318 | The idea here is that evaluating an expression generates a series | |
11319 | of values, one holding the value of every subexpression. (The | |
11320 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11321 | a*b+c.) GDB's values hold almost enough information to establish | |
11322 | the criteria given above --- they identify memory lvalues, | |
11323 | register lvalues, computed values, etcetera. So we can evaluate | |
11324 | the expression, and then scan the chain of values that leaves | |
11325 | behind to decide whether we can detect any possible change to the | |
11326 | expression's final value using only hardware watchpoints. | |
11327 | ||
11328 | However, I don't think that the values returned by inferior | |
11329 | function calls are special in any way. So this function may not | |
11330 | notice that an expression involving an inferior function call | |
11331 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11332 | for (; v; v = value_next (v)) |
c906108c | 11333 | { |
5c44784c | 11334 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11335 | { |
8464be76 DJ |
11336 | if (v != head && value_lazy (v)) |
11337 | /* A lazy memory lvalue in the chain is one that GDB never | |
11338 | needed to fetch; we either just used its address (e.g., | |
11339 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11340 | in `a,b'). This doesn't apply to HEAD; if that is | |
11341 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11342 | ; |
53a5351d | 11343 | else |
5c44784c JM |
11344 | { |
11345 | /* Ahh, memory we actually used! Check if we can cover | |
11346 | it with hardware watchpoints. */ | |
df407dfe | 11347 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11348 | |
11349 | /* We only watch structs and arrays if user asked for it | |
11350 | explicitly, never if they just happen to appear in a | |
11351 | middle of some value chain. */ | |
11352 | if (v == head | |
11353 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11354 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11355 | { | |
42ae5230 | 11356 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11357 | int len; |
11358 | int num_regs; | |
11359 | ||
a9634178 | 11360 | len = (target_exact_watchpoints |
e09342b5 TJB |
11361 | && is_scalar_type_recursive (vtype))? |
11362 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11363 | |
e09342b5 TJB |
11364 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11365 | if (!num_regs) | |
2e70b7b9 MS |
11366 | return 0; |
11367 | else | |
e09342b5 | 11368 | found_memory_cnt += num_regs; |
2e70b7b9 | 11369 | } |
5c44784c | 11370 | } |
c5aa993b | 11371 | } |
5086187c AC |
11372 | else if (VALUE_LVAL (v) != not_lval |
11373 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11374 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11375 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11376 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11377 | } |
11378 | ||
11379 | /* The expression itself looks suitable for using a hardware | |
11380 | watchpoint, but give the target machine a chance to reject it. */ | |
11381 | return found_memory_cnt; | |
11382 | } | |
11383 | ||
8b93c638 | 11384 | void |
84f4c1fe | 11385 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11386 | { |
84f4c1fe | 11387 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11388 | } |
11389 | ||
06a64a0b TT |
11390 | /* A helper function that looks for the "-location" argument and then |
11391 | calls watch_command_1. */ | |
11392 | ||
11393 | static void | |
11394 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11395 | { | |
11396 | int just_location = 0; | |
11397 | ||
11398 | if (arg | |
11399 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11400 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11401 | { | |
e9cafbcc | 11402 | arg = skip_spaces (arg); |
06a64a0b TT |
11403 | just_location = 1; |
11404 | } | |
11405 | ||
84f4c1fe | 11406 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11407 | } |
8926118c | 11408 | |
c5aa993b | 11409 | static void |
fba45db2 | 11410 | watch_command (char *arg, int from_tty) |
c906108c | 11411 | { |
06a64a0b | 11412 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11413 | } |
11414 | ||
8b93c638 | 11415 | void |
84f4c1fe | 11416 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11417 | { |
84f4c1fe | 11418 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11419 | } |
8926118c | 11420 | |
c5aa993b | 11421 | static void |
fba45db2 | 11422 | rwatch_command (char *arg, int from_tty) |
c906108c | 11423 | { |
06a64a0b | 11424 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11425 | } |
11426 | ||
8b93c638 | 11427 | void |
84f4c1fe | 11428 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11429 | { |
84f4c1fe | 11430 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11431 | } |
8926118c | 11432 | |
c5aa993b | 11433 | static void |
fba45db2 | 11434 | awatch_command (char *arg, int from_tty) |
c906108c | 11435 | { |
06a64a0b | 11436 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11437 | } |
c906108c | 11438 | \f |
c5aa993b | 11439 | |
43ff13b4 | 11440 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11441 | because it uses the mechanisms of breakpoints. */ |
11442 | ||
bfec99b2 PA |
11443 | struct until_break_command_continuation_args |
11444 | { | |
11445 | struct breakpoint *breakpoint; | |
11446 | struct breakpoint *breakpoint2; | |
186c406b | 11447 | int thread_num; |
bfec99b2 PA |
11448 | }; |
11449 | ||
43ff13b4 | 11450 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11451 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11452 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11453 | command. */ |
c2c6d25f | 11454 | static void |
fa4cd53f | 11455 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11456 | { |
bfec99b2 PA |
11457 | struct until_break_command_continuation_args *a = arg; |
11458 | ||
11459 | delete_breakpoint (a->breakpoint); | |
11460 | if (a->breakpoint2) | |
11461 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11462 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11463 | } |
11464 | ||
c906108c | 11465 | void |
ae66c1fc | 11466 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11467 | { |
11468 | struct symtabs_and_lines sals; | |
11469 | struct symtab_and_line sal; | |
8556afb4 PA |
11470 | struct frame_info *frame; |
11471 | struct gdbarch *frame_gdbarch; | |
11472 | struct frame_id stack_frame_id; | |
11473 | struct frame_id caller_frame_id; | |
c906108c | 11474 | struct breakpoint *breakpoint; |
f107f563 | 11475 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11476 | struct cleanup *old_chain; |
186c406b TT |
11477 | int thread; |
11478 | struct thread_info *tp; | |
c906108c SS |
11479 | |
11480 | clear_proceed_status (); | |
11481 | ||
11482 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11483 | this function. */ |
c5aa993b | 11484 | |
1bfeeb0f | 11485 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11486 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11487 | get_last_displayed_symtab (), |
f8eba3c6 | 11488 | get_last_displayed_line ()); |
c906108c | 11489 | else |
f8eba3c6 TT |
11490 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11491 | (struct symtab *) NULL, 0); | |
c5aa993b | 11492 | |
c906108c | 11493 | if (sals.nelts != 1) |
8a3fe4f8 | 11494 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11495 | |
c906108c | 11496 | sal = sals.sals[0]; |
4a64f543 | 11497 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11498 | |
c906108c | 11499 | if (*arg) |
8a3fe4f8 | 11500 | error (_("Junk at end of arguments.")); |
c5aa993b | 11501 | |
c906108c | 11502 | resolve_sal_pc (&sal); |
c5aa993b | 11503 | |
186c406b TT |
11504 | tp = inferior_thread (); |
11505 | thread = tp->num; | |
11506 | ||
883bc8d1 PA |
11507 | old_chain = make_cleanup (null_cleanup, NULL); |
11508 | ||
8556afb4 PA |
11509 | /* Note linespec handling above invalidates the frame chain. |
11510 | Installing a breakpoint also invalidates the frame chain (as it | |
11511 | may need to switch threads), so do any frame handling before | |
11512 | that. */ | |
11513 | ||
11514 | frame = get_selected_frame (NULL); | |
11515 | frame_gdbarch = get_frame_arch (frame); | |
11516 | stack_frame_id = get_stack_frame_id (frame); | |
11517 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11518 | |
ae66c1fc EZ |
11519 | /* Keep within the current frame, or in frames called by the current |
11520 | one. */ | |
edb3359d | 11521 | |
883bc8d1 | 11522 | if (frame_id_p (caller_frame_id)) |
c906108c | 11523 | { |
883bc8d1 PA |
11524 | struct symtab_and_line sal2; |
11525 | ||
11526 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11527 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11528 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11529 | sal2, |
11530 | caller_frame_id, | |
f107f563 VP |
11531 | bp_until); |
11532 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11533 | |
883bc8d1 | 11534 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11535 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11536 | } |
c5aa993b | 11537 | |
c70a6932 JK |
11538 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11539 | frame = NULL; | |
11540 | ||
883bc8d1 PA |
11541 | if (anywhere) |
11542 | /* If the user told us to continue until a specified location, | |
11543 | we don't specify a frame at which we need to stop. */ | |
11544 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11545 | null_frame_id, bp_until); | |
11546 | else | |
11547 | /* Otherwise, specify the selected frame, because we want to stop | |
11548 | only at the very same frame. */ | |
11549 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11550 | stack_frame_id, bp_until); | |
11551 | make_cleanup_delete_breakpoint (breakpoint); | |
11552 | ||
a493e3e2 | 11553 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11554 | |
4a64f543 MS |
11555 | /* If we are running asynchronously, and proceed call above has |
11556 | actually managed to start the target, arrange for breakpoints to | |
11557 | be deleted when the target stops. Otherwise, we're already | |
11558 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11559 | |
8ea051c5 | 11560 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11561 | { |
bfec99b2 PA |
11562 | struct until_break_command_continuation_args *args; |
11563 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11564 | |
bfec99b2 PA |
11565 | args->breakpoint = breakpoint; |
11566 | args->breakpoint2 = breakpoint2; | |
186c406b | 11567 | args->thread_num = thread; |
f107f563 VP |
11568 | |
11569 | discard_cleanups (old_chain); | |
95e54da7 PA |
11570 | add_continuation (inferior_thread (), |
11571 | until_break_command_continuation, args, | |
604ead4a | 11572 | xfree); |
f107f563 VP |
11573 | } |
11574 | else | |
c5aa993b | 11575 | do_cleanups (old_chain); |
c906108c | 11576 | } |
ae66c1fc | 11577 | |
c906108c SS |
11578 | /* This function attempts to parse an optional "if <cond>" clause |
11579 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11580 | |
c906108c SS |
11581 | Else, it returns a pointer to the condition string. (It does not |
11582 | attempt to evaluate the string against a particular block.) And, | |
11583 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11584 | if clause in the arg string. */ |
53a5351d | 11585 | |
916703c0 | 11586 | char * |
fba45db2 | 11587 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11588 | { |
c5aa993b JM |
11589 | char *cond_string; |
11590 | ||
11591 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11592 | return NULL; |
c5aa993b | 11593 | |
4a64f543 | 11594 | /* Skip the "if" keyword. */ |
c906108c | 11595 | (*arg) += 2; |
c5aa993b | 11596 | |
c906108c | 11597 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11598 | condition string. */ |
e9cafbcc | 11599 | *arg = skip_spaces (*arg); |
c906108c | 11600 | cond_string = *arg; |
c5aa993b | 11601 | |
4a64f543 MS |
11602 | /* Assume that the condition occupies the remainder of the arg |
11603 | string. */ | |
c906108c | 11604 | (*arg) += strlen (cond_string); |
c5aa993b | 11605 | |
c906108c SS |
11606 | return cond_string; |
11607 | } | |
c5aa993b | 11608 | |
c906108c SS |
11609 | /* Commands to deal with catching events, such as signals, exceptions, |
11610 | process start/exit, etc. */ | |
c5aa993b JM |
11611 | |
11612 | typedef enum | |
11613 | { | |
44feb3ce TT |
11614 | catch_fork_temporary, catch_vfork_temporary, |
11615 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11616 | } |
11617 | catch_fork_kind; | |
11618 | ||
c906108c | 11619 | static void |
cc59ec59 MS |
11620 | catch_fork_command_1 (char *arg, int from_tty, |
11621 | struct cmd_list_element *command) | |
c906108c | 11622 | { |
a6d9a66e | 11623 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11624 | char *cond_string = NULL; |
44feb3ce TT |
11625 | catch_fork_kind fork_kind; |
11626 | int tempflag; | |
11627 | ||
11628 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11629 | tempflag = (fork_kind == catch_fork_temporary | |
11630 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11631 | |
44feb3ce TT |
11632 | if (!arg) |
11633 | arg = ""; | |
e9cafbcc | 11634 | arg = skip_spaces (arg); |
c5aa993b | 11635 | |
c906108c | 11636 | /* The allowed syntax is: |
c5aa993b JM |
11637 | catch [v]fork |
11638 | catch [v]fork if <cond> | |
11639 | ||
4a64f543 | 11640 | First, check if there's an if clause. */ |
c906108c | 11641 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11642 | |
c906108c | 11643 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11644 | error (_("Junk at end of arguments.")); |
c5aa993b | 11645 | |
c906108c | 11646 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11647 | and enable reporting of such events. */ |
c5aa993b JM |
11648 | switch (fork_kind) |
11649 | { | |
44feb3ce TT |
11650 | case catch_fork_temporary: |
11651 | case catch_fork_permanent: | |
a6d9a66e | 11652 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11653 | &catch_fork_breakpoint_ops); |
c906108c | 11654 | break; |
44feb3ce TT |
11655 | case catch_vfork_temporary: |
11656 | case catch_vfork_permanent: | |
a6d9a66e | 11657 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11658 | &catch_vfork_breakpoint_ops); |
c906108c | 11659 | break; |
c5aa993b | 11660 | default: |
8a3fe4f8 | 11661 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11662 | break; |
c5aa993b | 11663 | } |
c906108c SS |
11664 | } |
11665 | ||
11666 | static void | |
cc59ec59 MS |
11667 | catch_exec_command_1 (char *arg, int from_tty, |
11668 | struct cmd_list_element *command) | |
c906108c | 11669 | { |
b4d90040 | 11670 | struct exec_catchpoint *c; |
a6d9a66e | 11671 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11672 | int tempflag; |
c5aa993b | 11673 | char *cond_string = NULL; |
c906108c | 11674 | |
44feb3ce TT |
11675 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11676 | ||
11677 | if (!arg) | |
11678 | arg = ""; | |
e9cafbcc | 11679 | arg = skip_spaces (arg); |
c906108c SS |
11680 | |
11681 | /* The allowed syntax is: | |
c5aa993b JM |
11682 | catch exec |
11683 | catch exec if <cond> | |
c906108c | 11684 | |
4a64f543 | 11685 | First, check if there's an if clause. */ |
c906108c SS |
11686 | cond_string = ep_parse_optional_if_clause (&arg); |
11687 | ||
11688 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11689 | error (_("Junk at end of arguments.")); |
c906108c | 11690 | |
b4d90040 PA |
11691 | c = XNEW (struct exec_catchpoint); |
11692 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11693 | &catch_exec_breakpoint_ops); | |
11694 | c->exec_pathname = NULL; | |
11695 | ||
3ea46bff | 11696 | install_breakpoint (0, &c->base, 1); |
c906108c | 11697 | } |
c5aa993b | 11698 | |
9ac4176b | 11699 | void |
28010a5d PA |
11700 | init_ada_exception_breakpoint (struct breakpoint *b, |
11701 | struct gdbarch *gdbarch, | |
11702 | struct symtab_and_line sal, | |
11703 | char *addr_string, | |
c0a91b2b | 11704 | const struct breakpoint_ops *ops, |
28010a5d | 11705 | int tempflag, |
349774ef | 11706 | int enabled, |
28010a5d | 11707 | int from_tty) |
f7f9143b | 11708 | { |
f7f9143b JB |
11709 | if (from_tty) |
11710 | { | |
5af949e3 UW |
11711 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11712 | if (!loc_gdbarch) | |
11713 | loc_gdbarch = gdbarch; | |
11714 | ||
6c95b8df PA |
11715 | describe_other_breakpoints (loc_gdbarch, |
11716 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11717 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11718 | version for exception catchpoints, because two catchpoints | |
11719 | used for different exception names will use the same address. | |
11720 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11721 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11722 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11723 | the user what type of catchpoint it is. The above is good |
11724 | enough for now, though. */ | |
11725 | } | |
11726 | ||
28010a5d | 11727 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11728 | |
349774ef | 11729 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11730 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11731 | b->addr_string = addr_string; |
11732 | b->language = language_ada; | |
f7f9143b JB |
11733 | } |
11734 | ||
a96d9b2e SDJ |
11735 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11736 | filter list, or NULL if no filtering is required. */ | |
11737 | static VEC(int) * | |
11738 | catch_syscall_split_args (char *arg) | |
11739 | { | |
11740 | VEC(int) *result = NULL; | |
29d0bb3d | 11741 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11742 | |
11743 | while (*arg != '\0') | |
11744 | { | |
11745 | int i, syscall_number; | |
11746 | char *endptr; | |
11747 | char cur_name[128]; | |
11748 | struct syscall s; | |
11749 | ||
11750 | /* Skip whitespace. */ | |
529480d0 | 11751 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11752 | |
11753 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11754 | cur_name[i] = arg[i]; | |
11755 | cur_name[i] = '\0'; | |
11756 | arg += i; | |
11757 | ||
11758 | /* Check if the user provided a syscall name or a number. */ | |
11759 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11760 | if (*endptr == '\0') | |
bccd0dd2 | 11761 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11762 | else |
11763 | { | |
11764 | /* We have a name. Let's check if it's valid and convert it | |
11765 | to a number. */ | |
11766 | get_syscall_by_name (cur_name, &s); | |
11767 | ||
11768 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11769 | /* Here we have to issue an error instead of a warning, |
11770 | because GDB cannot do anything useful if there's no | |
11771 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11772 | error (_("Unknown syscall name '%s'."), cur_name); |
11773 | } | |
11774 | ||
11775 | /* Ok, it's valid. */ | |
11776 | VEC_safe_push (int, result, s.number); | |
11777 | } | |
11778 | ||
11779 | discard_cleanups (cleanup); | |
11780 | return result; | |
11781 | } | |
11782 | ||
11783 | /* Implement the "catch syscall" command. */ | |
11784 | ||
11785 | static void | |
cc59ec59 MS |
11786 | catch_syscall_command_1 (char *arg, int from_tty, |
11787 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11788 | { |
11789 | int tempflag; | |
11790 | VEC(int) *filter; | |
11791 | struct syscall s; | |
11792 | struct gdbarch *gdbarch = get_current_arch (); | |
11793 | ||
11794 | /* Checking if the feature if supported. */ | |
11795 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11796 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11797 | this architecture yet.")); |
a96d9b2e SDJ |
11798 | |
11799 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11800 | ||
e9cafbcc | 11801 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11802 | |
11803 | /* We need to do this first "dummy" translation in order | |
11804 | to get the syscall XML file loaded or, most important, | |
11805 | to display a warning to the user if there's no XML file | |
11806 | for his/her architecture. */ | |
11807 | get_syscall_by_number (0, &s); | |
11808 | ||
11809 | /* The allowed syntax is: | |
11810 | catch syscall | |
11811 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11812 | ||
11813 | Let's check if there's a syscall name. */ | |
11814 | ||
11815 | if (arg != NULL) | |
11816 | filter = catch_syscall_split_args (arg); | |
11817 | else | |
11818 | filter = NULL; | |
11819 | ||
11820 | create_syscall_event_catchpoint (tempflag, filter, | |
11821 | &catch_syscall_breakpoint_ops); | |
11822 | } | |
11823 | ||
c906108c | 11824 | static void |
fba45db2 | 11825 | catch_command (char *arg, int from_tty) |
c906108c | 11826 | { |
44feb3ce | 11827 | error (_("Catch requires an event name.")); |
c906108c SS |
11828 | } |
11829 | \f | |
11830 | ||
11831 | static void | |
fba45db2 | 11832 | tcatch_command (char *arg, int from_tty) |
c906108c | 11833 | { |
44feb3ce | 11834 | error (_("Catch requires an event name.")); |
c906108c SS |
11835 | } |
11836 | ||
8a2c437b TT |
11837 | /* A qsort comparison function that sorts breakpoints in order. */ |
11838 | ||
11839 | static int | |
11840 | compare_breakpoints (const void *a, const void *b) | |
11841 | { | |
11842 | const breakpoint_p *ba = a; | |
11843 | uintptr_t ua = (uintptr_t) *ba; | |
11844 | const breakpoint_p *bb = b; | |
11845 | uintptr_t ub = (uintptr_t) *bb; | |
11846 | ||
11847 | if ((*ba)->number < (*bb)->number) | |
11848 | return -1; | |
11849 | else if ((*ba)->number > (*bb)->number) | |
11850 | return 1; | |
11851 | ||
11852 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11853 | the number 0. */ | |
11854 | if (ua < ub) | |
11855 | return -1; | |
94b0e70d | 11856 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11857 | } |
11858 | ||
80f8a6eb | 11859 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11860 | |
11861 | static void | |
fba45db2 | 11862 | clear_command (char *arg, int from_tty) |
c906108c | 11863 | { |
8a2c437b | 11864 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11865 | VEC(breakpoint_p) *found = 0; |
11866 | int ix; | |
c906108c SS |
11867 | int default_match; |
11868 | struct symtabs_and_lines sals; | |
11869 | struct symtab_and_line sal; | |
c906108c | 11870 | int i; |
8a2c437b | 11871 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11872 | |
11873 | if (arg) | |
11874 | { | |
39cf75f7 DE |
11875 | sals = decode_line_with_current_source (arg, |
11876 | (DECODE_LINE_FUNFIRSTLINE | |
11877 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11878 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11879 | default_match = 0; |
11880 | } | |
11881 | else | |
11882 | { | |
c5aa993b | 11883 | sals.sals = (struct symtab_and_line *) |
c906108c | 11884 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11885 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11886 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11887 | |
11888 | /* Set sal's line, symtab, pc, and pspace to the values | |
11889 | corresponding to the last call to print_frame_info. If the | |
11890 | codepoint is not valid, this will set all the fields to 0. */ | |
11891 | get_last_displayed_sal (&sal); | |
c906108c | 11892 | if (sal.symtab == 0) |
8a3fe4f8 | 11893 | error (_("No source file specified.")); |
c906108c SS |
11894 | |
11895 | sals.sals[0] = sal; | |
11896 | sals.nelts = 1; | |
11897 | ||
11898 | default_match = 1; | |
11899 | } | |
11900 | ||
4a64f543 MS |
11901 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11902 | seems, because all existing breakpoints typically have both | |
11903 | file/line and pc set. So, if clear is given file/line, we can | |
11904 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11905 | |
11906 | We only support clearing given the address explicitly | |
11907 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11908 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11909 | due to optimization, all in one block. |
4a64f543 MS |
11910 | |
11911 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11912 | PC corresponding to the same file:line, the breakpoint won't |
11913 | be cleared. We probably can still clear the breakpoint, but | |
11914 | since the other PC value is never presented to user, user | |
11915 | can only find it by guessing, and it does not seem important | |
11916 | to support that. */ | |
11917 | ||
4a64f543 MS |
11918 | /* For each line spec given, delete bps which correspond to it. Do |
11919 | it in two passes, solely to preserve the current behavior that | |
11920 | from_tty is forced true if we delete more than one | |
11921 | breakpoint. */ | |
c906108c | 11922 | |
80f8a6eb | 11923 | found = NULL; |
8a2c437b | 11924 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11925 | for (i = 0; i < sals.nelts; i++) |
11926 | { | |
05cba821 JK |
11927 | const char *sal_fullname; |
11928 | ||
c906108c | 11929 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11930 | If line given (pc == 0), clear all bpts on specified line. |
11931 | If defaulting, clear all bpts on default line | |
c906108c | 11932 | or at default pc. |
c5aa993b JM |
11933 | |
11934 | defaulting sal.pc != 0 tests to do | |
11935 | ||
11936 | 0 1 pc | |
11937 | 1 1 pc _and_ line | |
11938 | 0 0 line | |
11939 | 1 0 <can't happen> */ | |
c906108c SS |
11940 | |
11941 | sal = sals.sals[i]; | |
05cba821 JK |
11942 | sal_fullname = (sal.symtab == NULL |
11943 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11944 | |
4a64f543 | 11945 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11946 | ALL_BREAKPOINTS (b) |
c5aa993b | 11947 | { |
0d381245 | 11948 | int match = 0; |
4a64f543 | 11949 | /* Are we going to delete b? */ |
cc60f2e3 | 11950 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11951 | { |
11952 | struct bp_location *loc = b->loc; | |
11953 | for (; loc; loc = loc->next) | |
11954 | { | |
f8eba3c6 TT |
11955 | /* If the user specified file:line, don't allow a PC |
11956 | match. This matches historical gdb behavior. */ | |
11957 | int pc_match = (!sal.explicit_line | |
11958 | && sal.pc | |
11959 | && (loc->pspace == sal.pspace) | |
11960 | && (loc->address == sal.pc) | |
11961 | && (!section_is_overlay (loc->section) | |
11962 | || loc->section == sal.section)); | |
4aac40c8 TT |
11963 | int line_match = 0; |
11964 | ||
11965 | if ((default_match || sal.explicit_line) | |
2f202fde | 11966 | && loc->symtab != NULL |
05cba821 | 11967 | && sal_fullname != NULL |
4aac40c8 | 11968 | && sal.pspace == loc->pspace |
05cba821 JK |
11969 | && loc->line_number == sal.line |
11970 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11971 | sal_fullname) == 0) | |
11972 | line_match = 1; | |
4aac40c8 | 11973 | |
0d381245 VP |
11974 | if (pc_match || line_match) |
11975 | { | |
11976 | match = 1; | |
11977 | break; | |
11978 | } | |
11979 | } | |
11980 | } | |
11981 | ||
11982 | if (match) | |
d6e956e5 | 11983 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11984 | } |
80f8a6eb | 11985 | } |
8a2c437b | 11986 | |
80f8a6eb | 11987 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11988 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11989 | { |
11990 | if (arg) | |
8a3fe4f8 | 11991 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11992 | else |
8a3fe4f8 | 11993 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11994 | } |
c906108c | 11995 | |
8a2c437b TT |
11996 | /* Remove duplicates from the vec. */ |
11997 | qsort (VEC_address (breakpoint_p, found), | |
11998 | VEC_length (breakpoint_p, found), | |
11999 | sizeof (breakpoint_p), | |
12000 | compare_breakpoints); | |
12001 | prev = VEC_index (breakpoint_p, found, 0); | |
12002 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12003 | { | |
12004 | if (b == prev) | |
12005 | { | |
12006 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12007 | --ix; | |
12008 | } | |
12009 | } | |
12010 | ||
d6e956e5 | 12011 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12012 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12013 | if (from_tty) |
a3f17187 | 12014 | { |
d6e956e5 | 12015 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12016 | printf_unfiltered (_("Deleted breakpoint ")); |
12017 | else | |
12018 | printf_unfiltered (_("Deleted breakpoints ")); | |
12019 | } | |
d6e956e5 VP |
12020 | |
12021 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12022 | { |
c5aa993b | 12023 | if (from_tty) |
d6e956e5 VP |
12024 | printf_unfiltered ("%d ", b->number); |
12025 | delete_breakpoint (b); | |
c906108c | 12026 | } |
80f8a6eb MS |
12027 | if (from_tty) |
12028 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12029 | |
12030 | do_cleanups (cleanups); | |
c906108c SS |
12031 | } |
12032 | \f | |
12033 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12034 | all breakpoints that are marked for deletion, whether hit or not. | |
12035 | This is called after any breakpoint is hit, or after errors. */ | |
12036 | ||
12037 | void | |
fba45db2 | 12038 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12039 | { |
35df4500 | 12040 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12041 | |
12042 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12043 | if (bs->breakpoint_at |
12044 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12045 | && bs->stop) |
f431efe5 | 12046 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12047 | |
35df4500 | 12048 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12049 | { |
b5de0fa7 | 12050 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12051 | delete_breakpoint (b); |
12052 | } | |
c906108c SS |
12053 | } |
12054 | ||
4a64f543 MS |
12055 | /* A comparison function for bp_location AP and BP being interfaced to |
12056 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12057 | does breakpoint_address_is_meaningful say for its OWNER), | |
12058 | secondarily by ordering first bp_permanent OWNERed elements and | |
12059 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12060 | qsort being an unstable algorithm. */ |
876fa593 JK |
12061 | |
12062 | static int | |
494cfb0f | 12063 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12064 | { |
494cfb0f JK |
12065 | struct bp_location *a = *(void **) ap; |
12066 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12067 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12068 | int a_perm = a->owner->enable_state == bp_permanent; |
12069 | int b_perm = b->owner->enable_state == bp_permanent; | |
12070 | ||
12071 | if (a->address != b->address) | |
12072 | return (a->address > b->address) - (a->address < b->address); | |
12073 | ||
dea2aa5f LM |
12074 | /* Sort locations at the same address by their pspace number, keeping |
12075 | locations of the same inferior (in a multi-inferior environment) | |
12076 | grouped. */ | |
12077 | ||
12078 | if (a->pspace->num != b->pspace->num) | |
12079 | return ((a->pspace->num > b->pspace->num) | |
12080 | - (a->pspace->num < b->pspace->num)); | |
12081 | ||
876fa593 JK |
12082 | /* Sort permanent breakpoints first. */ |
12083 | if (a_perm != b_perm) | |
12084 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12085 | ||
c56a97f9 JK |
12086 | /* Make the internal GDB representation stable across GDB runs |
12087 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12088 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12089 | |
12090 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12091 | return ((a->owner->number > b->owner->number) |
12092 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12093 | |
12094 | return (a > b) - (a < b); | |
12095 | } | |
12096 | ||
876fa593 | 12097 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12098 | bp_location_shadow_len_after_address_max according to the current |
12099 | content of the bp_location array. */ | |
f7545552 TT |
12100 | |
12101 | static void | |
876fa593 | 12102 | bp_location_target_extensions_update (void) |
f7545552 | 12103 | { |
876fa593 JK |
12104 | struct bp_location *bl, **blp_tmp; |
12105 | ||
12106 | bp_location_placed_address_before_address_max = 0; | |
12107 | bp_location_shadow_len_after_address_max = 0; | |
12108 | ||
12109 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12110 | { | |
12111 | CORE_ADDR start, end, addr; | |
12112 | ||
12113 | if (!bp_location_has_shadow (bl)) | |
12114 | continue; | |
12115 | ||
12116 | start = bl->target_info.placed_address; | |
12117 | end = start + bl->target_info.shadow_len; | |
12118 | ||
12119 | gdb_assert (bl->address >= start); | |
12120 | addr = bl->address - start; | |
12121 | if (addr > bp_location_placed_address_before_address_max) | |
12122 | bp_location_placed_address_before_address_max = addr; | |
12123 | ||
12124 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12125 | ||
12126 | gdb_assert (bl->address < end); | |
12127 | addr = end - bl->address; | |
12128 | if (addr > bp_location_shadow_len_after_address_max) | |
12129 | bp_location_shadow_len_after_address_max = addr; | |
12130 | } | |
f7545552 TT |
12131 | } |
12132 | ||
1e4d1764 YQ |
12133 | /* Download tracepoint locations if they haven't been. */ |
12134 | ||
12135 | static void | |
12136 | download_tracepoint_locations (void) | |
12137 | { | |
7ed2c994 | 12138 | struct breakpoint *b; |
1e4d1764 YQ |
12139 | struct cleanup *old_chain; |
12140 | ||
12141 | if (!target_can_download_tracepoint ()) | |
12142 | return; | |
12143 | ||
12144 | old_chain = save_current_space_and_thread (); | |
12145 | ||
7ed2c994 | 12146 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12147 | { |
7ed2c994 | 12148 | struct bp_location *bl; |
1e4d1764 | 12149 | struct tracepoint *t; |
f2a8bc8a | 12150 | int bp_location_downloaded = 0; |
1e4d1764 | 12151 | |
7ed2c994 | 12152 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12153 | ? !may_insert_fast_tracepoints |
12154 | : !may_insert_tracepoints)) | |
12155 | continue; | |
12156 | ||
7ed2c994 YQ |
12157 | for (bl = b->loc; bl; bl = bl->next) |
12158 | { | |
12159 | /* In tracepoint, locations are _never_ duplicated, so | |
12160 | should_be_inserted is equivalent to | |
12161 | unduplicated_should_be_inserted. */ | |
12162 | if (!should_be_inserted (bl) || bl->inserted) | |
12163 | continue; | |
1e4d1764 | 12164 | |
7ed2c994 | 12165 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12166 | |
7ed2c994 | 12167 | target_download_tracepoint (bl); |
1e4d1764 | 12168 | |
7ed2c994 | 12169 | bl->inserted = 1; |
f2a8bc8a | 12170 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12171 | } |
12172 | t = (struct tracepoint *) b; | |
12173 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12174 | if (bp_location_downloaded) |
12175 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12176 | } |
12177 | ||
12178 | do_cleanups (old_chain); | |
12179 | } | |
12180 | ||
934709f0 PW |
12181 | /* Swap the insertion/duplication state between two locations. */ |
12182 | ||
12183 | static void | |
12184 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12185 | { | |
12186 | const int left_inserted = left->inserted; | |
12187 | const int left_duplicate = left->duplicate; | |
b775012e | 12188 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12189 | const struct bp_target_info left_target_info = left->target_info; |
12190 | ||
1e4d1764 YQ |
12191 | /* Locations of tracepoints can never be duplicated. */ |
12192 | if (is_tracepoint (left->owner)) | |
12193 | gdb_assert (!left->duplicate); | |
12194 | if (is_tracepoint (right->owner)) | |
12195 | gdb_assert (!right->duplicate); | |
12196 | ||
934709f0 PW |
12197 | left->inserted = right->inserted; |
12198 | left->duplicate = right->duplicate; | |
b775012e | 12199 | left->needs_update = right->needs_update; |
934709f0 PW |
12200 | left->target_info = right->target_info; |
12201 | right->inserted = left_inserted; | |
12202 | right->duplicate = left_duplicate; | |
b775012e | 12203 | right->needs_update = left_needs_update; |
934709f0 PW |
12204 | right->target_info = left_target_info; |
12205 | } | |
12206 | ||
b775012e LM |
12207 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12208 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12209 | conditions on the target's side. Such conditions need to be updated on | |
12210 | the target. */ | |
12211 | ||
12212 | static void | |
12213 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12214 | { | |
12215 | struct bp_location **locp = NULL, **loc2p; | |
12216 | struct bp_location *loc; | |
12217 | CORE_ADDR address = 0; | |
12218 | int pspace_num; | |
12219 | ||
12220 | address = bl->address; | |
12221 | pspace_num = bl->pspace->num; | |
12222 | ||
12223 | /* This is only meaningful if the target is | |
12224 | evaluating conditions and if the user has | |
12225 | opted for condition evaluation on the target's | |
12226 | side. */ | |
12227 | if (gdb_evaluates_breakpoint_condition_p () | |
12228 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12229 | return; | |
12230 | ||
12231 | /* Flag all breakpoint locations with this address and | |
12232 | the same program space as the location | |
12233 | as "its condition has changed". We need to | |
12234 | update the conditions on the target's side. */ | |
12235 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12236 | { | |
12237 | loc = *loc2p; | |
12238 | ||
12239 | if (!is_breakpoint (loc->owner) | |
12240 | || pspace_num != loc->pspace->num) | |
12241 | continue; | |
12242 | ||
12243 | /* Flag the location appropriately. We use a different state to | |
12244 | let everyone know that we already updated the set of locations | |
12245 | with addr bl->address and program space bl->pspace. This is so | |
12246 | we don't have to keep calling these functions just to mark locations | |
12247 | that have already been marked. */ | |
12248 | loc->condition_changed = condition_updated; | |
12249 | ||
12250 | /* Free the agent expression bytecode as well. We will compute | |
12251 | it later on. */ | |
12252 | if (loc->cond_bytecode) | |
12253 | { | |
12254 | free_agent_expr (loc->cond_bytecode); | |
12255 | loc->cond_bytecode = NULL; | |
12256 | } | |
12257 | } | |
12258 | } | |
12259 | ||
4cd9bd08 | 12260 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12261 | into the inferior, only remove already-inserted locations that no |
12262 | longer should be inserted. Functions that delete a breakpoint or | |
12263 | breakpoints should pass false, so that deleting a breakpoint | |
12264 | doesn't have the side effect of inserting the locations of other | |
12265 | breakpoints that are marked not-inserted, but should_be_inserted | |
12266 | returns true on them. | |
12267 | ||
12268 | This behaviour is useful is situations close to tear-down -- e.g., | |
12269 | after an exec, while the target still has execution, but breakpoint | |
12270 | shadows of the previous executable image should *NOT* be restored | |
12271 | to the new image; or before detaching, where the target still has | |
12272 | execution and wants to delete breakpoints from GDB's lists, and all | |
12273 | breakpoints had already been removed from the inferior. */ | |
12274 | ||
0d381245 | 12275 | static void |
b60e7edf | 12276 | update_global_location_list (int should_insert) |
0d381245 | 12277 | { |
74960c60 | 12278 | struct breakpoint *b; |
876fa593 | 12279 | struct bp_location **locp, *loc; |
f7545552 | 12280 | struct cleanup *cleanups; |
b775012e LM |
12281 | /* Last breakpoint location address that was marked for update. */ |
12282 | CORE_ADDR last_addr = 0; | |
12283 | /* Last breakpoint location program space that was marked for update. */ | |
12284 | int last_pspace_num = -1; | |
f7545552 | 12285 | |
2d134ed3 PA |
12286 | /* Used in the duplicates detection below. When iterating over all |
12287 | bp_locations, points to the first bp_location of a given address. | |
12288 | Breakpoints and watchpoints of different types are never | |
12289 | duplicates of each other. Keep one pointer for each type of | |
12290 | breakpoint/watchpoint, so we only need to loop over all locations | |
12291 | once. */ | |
12292 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12293 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12294 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12295 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12296 | |
4a64f543 MS |
12297 | /* Saved former bp_location array which we compare against the newly |
12298 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12299 | struct bp_location **old_location, **old_locp; |
12300 | unsigned old_location_count; | |
12301 | ||
12302 | old_location = bp_location; | |
12303 | old_location_count = bp_location_count; | |
12304 | bp_location = NULL; | |
12305 | bp_location_count = 0; | |
12306 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12307 | |
74960c60 | 12308 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12309 | for (loc = b->loc; loc; loc = loc->next) |
12310 | bp_location_count++; | |
12311 | ||
12312 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12313 | locp = bp_location; | |
12314 | ALL_BREAKPOINTS (b) | |
12315 | for (loc = b->loc; loc; loc = loc->next) | |
12316 | *locp++ = loc; | |
12317 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12318 | bp_location_compare); |
876fa593 JK |
12319 | |
12320 | bp_location_target_extensions_update (); | |
74960c60 | 12321 | |
4a64f543 MS |
12322 | /* Identify bp_location instances that are no longer present in the |
12323 | new list, and therefore should be freed. Note that it's not | |
12324 | necessary that those locations should be removed from inferior -- | |
12325 | if there's another location at the same address (previously | |
12326 | marked as duplicate), we don't need to remove/insert the | |
12327 | location. | |
876fa593 | 12328 | |
4a64f543 MS |
12329 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12330 | and former bp_location array state respectively. */ | |
876fa593 JK |
12331 | |
12332 | locp = bp_location; | |
12333 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12334 | old_locp++) | |
74960c60 | 12335 | { |
876fa593 | 12336 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12337 | struct bp_location **loc2p; |
876fa593 | 12338 | |
e5dd4106 | 12339 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12340 | not, we have to free it. */ |
c7d46a38 | 12341 | int found_object = 0; |
20874c92 VP |
12342 | /* Tells if the location should remain inserted in the target. */ |
12343 | int keep_in_target = 0; | |
12344 | int removed = 0; | |
876fa593 | 12345 | |
4a64f543 MS |
12346 | /* Skip LOCP entries which will definitely never be needed. |
12347 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12348 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12349 | && (*locp)->address < old_loc->address) |
876fa593 | 12350 | locp++; |
c7d46a38 PA |
12351 | |
12352 | for (loc2p = locp; | |
12353 | (loc2p < bp_location + bp_location_count | |
12354 | && (*loc2p)->address == old_loc->address); | |
12355 | loc2p++) | |
12356 | { | |
b775012e LM |
12357 | /* Check if this is a new/duplicated location or a duplicated |
12358 | location that had its condition modified. If so, we want to send | |
12359 | its condition to the target if evaluation of conditions is taking | |
12360 | place there. */ | |
12361 | if ((*loc2p)->condition_changed == condition_modified | |
12362 | && (last_addr != old_loc->address | |
12363 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12364 | { |
b775012e LM |
12365 | force_breakpoint_reinsertion (*loc2p); |
12366 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12367 | } |
b775012e LM |
12368 | |
12369 | if (*loc2p == old_loc) | |
12370 | found_object = 1; | |
c7d46a38 | 12371 | } |
74960c60 | 12372 | |
b775012e LM |
12373 | /* We have already handled this address, update it so that we don't |
12374 | have to go through updates again. */ | |
12375 | last_addr = old_loc->address; | |
12376 | ||
12377 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12378 | if (!found_object) | |
12379 | force_breakpoint_reinsertion (old_loc); | |
12380 | ||
4a64f543 MS |
12381 | /* If this location is no longer present, and inserted, look if |
12382 | there's maybe a new location at the same address. If so, | |
12383 | mark that one inserted, and don't remove this one. This is | |
12384 | needed so that we don't have a time window where a breakpoint | |
12385 | at certain location is not inserted. */ | |
74960c60 | 12386 | |
876fa593 | 12387 | if (old_loc->inserted) |
0d381245 | 12388 | { |
4a64f543 MS |
12389 | /* If the location is inserted now, we might have to remove |
12390 | it. */ | |
74960c60 | 12391 | |
876fa593 | 12392 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12393 | { |
4a64f543 MS |
12394 | /* The location is still present in the location list, |
12395 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12396 | keep_in_target = 1; |
74960c60 VP |
12397 | } |
12398 | else | |
12399 | { | |
b775012e LM |
12400 | /* This location still exists, but it won't be kept in the |
12401 | target since it may have been disabled. We proceed to | |
12402 | remove its target-side condition. */ | |
12403 | ||
4a64f543 MS |
12404 | /* The location is either no longer present, or got |
12405 | disabled. See if there's another location at the | |
12406 | same address, in which case we don't need to remove | |
12407 | this one from the target. */ | |
876fa593 | 12408 | |
2bdf28a0 | 12409 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12410 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12411 | { | |
876fa593 | 12412 | for (loc2p = locp; |
c7d46a38 PA |
12413 | (loc2p < bp_location + bp_location_count |
12414 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12415 | loc2p++) |
12416 | { | |
12417 | struct bp_location *loc2 = *loc2p; | |
12418 | ||
2d134ed3 | 12419 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12420 | { |
85d721b8 PA |
12421 | /* Read watchpoint locations are switched to |
12422 | access watchpoints, if the former are not | |
12423 | supported, but the latter are. */ | |
12424 | if (is_hardware_watchpoint (old_loc->owner)) | |
12425 | { | |
12426 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12427 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12428 | } | |
12429 | ||
934709f0 PW |
12430 | /* loc2 is a duplicated location. We need to check |
12431 | if it should be inserted in case it will be | |
12432 | unduplicated. */ | |
12433 | if (loc2 != old_loc | |
12434 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12435 | { |
934709f0 | 12436 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12437 | keep_in_target = 1; |
12438 | break; | |
12439 | } | |
876fa593 JK |
12440 | } |
12441 | } | |
12442 | } | |
74960c60 VP |
12443 | } |
12444 | ||
20874c92 VP |
12445 | if (!keep_in_target) |
12446 | { | |
876fa593 | 12447 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12448 | { |
4a64f543 MS |
12449 | /* This is just about all we can do. We could keep |
12450 | this location on the global list, and try to | |
12451 | remove it next time, but there's no particular | |
12452 | reason why we will succeed next time. | |
20874c92 | 12453 | |
4a64f543 MS |
12454 | Note that at this point, old_loc->owner is still |
12455 | valid, as delete_breakpoint frees the breakpoint | |
12456 | only after calling us. */ | |
3e43a32a MS |
12457 | printf_filtered (_("warning: Error removing " |
12458 | "breakpoint %d\n"), | |
876fa593 | 12459 | old_loc->owner->number); |
20874c92 VP |
12460 | } |
12461 | removed = 1; | |
12462 | } | |
0d381245 | 12463 | } |
74960c60 VP |
12464 | |
12465 | if (!found_object) | |
1c5cfe86 | 12466 | { |
db82e815 PA |
12467 | if (removed && non_stop |
12468 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12469 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12470 | { |
db82e815 PA |
12471 | /* This location was removed from the target. In |
12472 | non-stop mode, a race condition is possible where | |
12473 | we've removed a breakpoint, but stop events for that | |
12474 | breakpoint are already queued and will arrive later. | |
12475 | We apply an heuristic to be able to distinguish such | |
12476 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12477 | breakpoint location for a bit, and will retire it | |
12478 | after we see some number of events. The theory here | |
12479 | is that reporting of events should, "on the average", | |
12480 | be fair, so after a while we'll see events from all | |
12481 | threads that have anything of interest, and no longer | |
12482 | need to keep this breakpoint location around. We | |
12483 | don't hold locations forever so to reduce chances of | |
12484 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12485 | SIGTRAP. | |
12486 | ||
12487 | The heuristic failing can be disastrous on | |
12488 | decr_pc_after_break targets. | |
12489 | ||
12490 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12491 | if we fail to recognize a late breakpoint SIGTRAP, | |
12492 | because events_till_retirement has reached 0 too | |
12493 | soon, we'll fail to do the PC adjustment, and report | |
12494 | a random SIGTRAP to the user. When the user resumes | |
12495 | the inferior, it will most likely immediately crash | |
2dec564e | 12496 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12497 | corrupted, because of being resumed e.g., in the |
12498 | middle of a multi-byte instruction, or skipped a | |
12499 | one-byte instruction. This was actually seen happen | |
12500 | on native x86-linux, and should be less rare on | |
12501 | targets that do not support new thread events, like | |
12502 | remote, due to the heuristic depending on | |
12503 | thread_count. | |
12504 | ||
12505 | Mistaking a random SIGTRAP for a breakpoint trap | |
12506 | causes similar symptoms (PC adjustment applied when | |
12507 | it shouldn't), but then again, playing with SIGTRAPs | |
12508 | behind the debugger's back is asking for trouble. | |
12509 | ||
12510 | Since hardware watchpoint traps are always | |
12511 | distinguishable from other traps, so we don't need to | |
12512 | apply keep hardware watchpoint moribund locations | |
12513 | around. We simply always ignore hardware watchpoint | |
12514 | traps we can no longer explain. */ | |
12515 | ||
876fa593 JK |
12516 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12517 | old_loc->owner = NULL; | |
20874c92 | 12518 | |
876fa593 | 12519 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12520 | } |
12521 | else | |
f431efe5 PA |
12522 | { |
12523 | old_loc->owner = NULL; | |
12524 | decref_bp_location (&old_loc); | |
12525 | } | |
20874c92 | 12526 | } |
74960c60 | 12527 | } |
1c5cfe86 | 12528 | |
348d480f PA |
12529 | /* Rescan breakpoints at the same address and section, marking the |
12530 | first one as "first" and any others as "duplicates". This is so | |
12531 | that the bpt instruction is only inserted once. If we have a | |
12532 | permanent breakpoint at the same place as BPT, make that one the | |
12533 | official one, and the rest as duplicates. Permanent breakpoints | |
12534 | are sorted first for the same address. | |
12535 | ||
12536 | Do the same for hardware watchpoints, but also considering the | |
12537 | watchpoint's type (regular/access/read) and length. */ | |
12538 | ||
12539 | bp_loc_first = NULL; | |
12540 | wp_loc_first = NULL; | |
12541 | awp_loc_first = NULL; | |
12542 | rwp_loc_first = NULL; | |
12543 | ALL_BP_LOCATIONS (loc, locp) | |
12544 | { | |
12545 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12546 | non-NULL. */ | |
348d480f | 12547 | struct bp_location **loc_first_p; |
d3fbdd86 | 12548 | b = loc->owner; |
348d480f | 12549 | |
6f380991 | 12550 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12551 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12552 | /* Don't detect duplicate for tracepoint locations because they are |
12553 | never duplicated. See the comments in field `duplicate' of | |
12554 | `struct bp_location'. */ | |
348d480f | 12555 | || is_tracepoint (b)) |
b775012e LM |
12556 | { |
12557 | /* Clear the condition modification flag. */ | |
12558 | loc->condition_changed = condition_unchanged; | |
12559 | continue; | |
12560 | } | |
348d480f PA |
12561 | |
12562 | /* Permanent breakpoint should always be inserted. */ | |
12563 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12564 | internal_error (__FILE__, __LINE__, | |
12565 | _("allegedly permanent breakpoint is not " | |
12566 | "actually inserted")); | |
12567 | ||
12568 | if (b->type == bp_hardware_watchpoint) | |
12569 | loc_first_p = &wp_loc_first; | |
12570 | else if (b->type == bp_read_watchpoint) | |
12571 | loc_first_p = &rwp_loc_first; | |
12572 | else if (b->type == bp_access_watchpoint) | |
12573 | loc_first_p = &awp_loc_first; | |
12574 | else | |
12575 | loc_first_p = &bp_loc_first; | |
12576 | ||
12577 | if (*loc_first_p == NULL | |
12578 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12579 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12580 | { | |
12581 | *loc_first_p = loc; | |
12582 | loc->duplicate = 0; | |
b775012e LM |
12583 | |
12584 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12585 | { | |
12586 | loc->needs_update = 1; | |
12587 | /* Clear the condition modification flag. */ | |
12588 | loc->condition_changed = condition_unchanged; | |
12589 | } | |
348d480f PA |
12590 | continue; |
12591 | } | |
12592 | ||
934709f0 PW |
12593 | |
12594 | /* This and the above ensure the invariant that the first location | |
12595 | is not duplicated, and is the inserted one. | |
12596 | All following are marked as duplicated, and are not inserted. */ | |
12597 | if (loc->inserted) | |
12598 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12599 | loc->duplicate = 1; |
12600 | ||
b775012e LM |
12601 | /* Clear the condition modification flag. */ |
12602 | loc->condition_changed = condition_unchanged; | |
12603 | ||
348d480f PA |
12604 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12605 | && b->enable_state != bp_permanent) | |
12606 | internal_error (__FILE__, __LINE__, | |
12607 | _("another breakpoint was inserted on top of " | |
12608 | "a permanent breakpoint")); | |
12609 | } | |
12610 | ||
b775012e | 12611 | if (breakpoints_always_inserted_mode () |
348d480f | 12612 | && (have_live_inferiors () |
f5656ead | 12613 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12614 | { |
12615 | if (should_insert) | |
12616 | insert_breakpoint_locations (); | |
12617 | else | |
12618 | { | |
12619 | /* Though should_insert is false, we may need to update conditions | |
12620 | on the target's side if it is evaluating such conditions. We | |
12621 | only update conditions for locations that are marked | |
12622 | "needs_update". */ | |
12623 | update_inserted_breakpoint_locations (); | |
12624 | } | |
12625 | } | |
348d480f | 12626 | |
1e4d1764 YQ |
12627 | if (should_insert) |
12628 | download_tracepoint_locations (); | |
12629 | ||
348d480f PA |
12630 | do_cleanups (cleanups); |
12631 | } | |
12632 | ||
12633 | void | |
12634 | breakpoint_retire_moribund (void) | |
12635 | { | |
12636 | struct bp_location *loc; | |
12637 | int ix; | |
12638 | ||
12639 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12640 | if (--(loc->events_till_retirement) == 0) | |
12641 | { | |
12642 | decref_bp_location (&loc); | |
12643 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12644 | --ix; | |
12645 | } | |
12646 | } | |
12647 | ||
12648 | static void | |
12649 | update_global_location_list_nothrow (int inserting) | |
12650 | { | |
bfd189b1 | 12651 | volatile struct gdb_exception e; |
348d480f PA |
12652 | |
12653 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12654 | update_global_location_list (inserting); | |
12655 | } | |
12656 | ||
12657 | /* Clear BKP from a BPS. */ | |
12658 | ||
12659 | static void | |
12660 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12661 | { | |
12662 | bpstat bs; | |
12663 | ||
12664 | for (bs = bps; bs; bs = bs->next) | |
12665 | if (bs->breakpoint_at == bpt) | |
12666 | { | |
12667 | bs->breakpoint_at = NULL; | |
12668 | bs->old_val = NULL; | |
12669 | /* bs->commands will be freed later. */ | |
12670 | } | |
12671 | } | |
12672 | ||
12673 | /* Callback for iterate_over_threads. */ | |
12674 | static int | |
12675 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12676 | { | |
12677 | struct breakpoint *bpt = data; | |
12678 | ||
12679 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12680 | return 0; | |
12681 | } | |
12682 | ||
12683 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12684 | callbacks. */ | |
12685 | ||
12686 | static void | |
12687 | say_where (struct breakpoint *b) | |
12688 | { | |
12689 | struct value_print_options opts; | |
12690 | ||
12691 | get_user_print_options (&opts); | |
12692 | ||
12693 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12694 | single string. */ | |
12695 | if (b->loc == NULL) | |
12696 | { | |
12697 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12698 | } | |
12699 | else | |
12700 | { | |
2f202fde | 12701 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12702 | { |
12703 | printf_filtered (" at "); | |
12704 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12705 | gdb_stdout); | |
12706 | } | |
2f202fde | 12707 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12708 | { |
12709 | /* If there is a single location, we can print the location | |
12710 | more nicely. */ | |
12711 | if (b->loc->next == NULL) | |
12712 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12713 | symtab_to_filename_for_display (b->loc->symtab), |
12714 | b->loc->line_number); | |
f8eba3c6 TT |
12715 | else |
12716 | /* This is not ideal, but each location may have a | |
12717 | different file name, and this at least reflects the | |
12718 | real situation somewhat. */ | |
12719 | printf_filtered (": %s.", b->addr_string); | |
12720 | } | |
348d480f PA |
12721 | |
12722 | if (b->loc->next) | |
12723 | { | |
12724 | struct bp_location *loc = b->loc; | |
12725 | int n = 0; | |
12726 | for (; loc; loc = loc->next) | |
12727 | ++n; | |
12728 | printf_filtered (" (%d locations)", n); | |
12729 | } | |
12730 | } | |
12731 | } | |
12732 | ||
348d480f PA |
12733 | /* Default bp_location_ops methods. */ |
12734 | ||
12735 | static void | |
12736 | bp_location_dtor (struct bp_location *self) | |
12737 | { | |
12738 | xfree (self->cond); | |
b775012e LM |
12739 | if (self->cond_bytecode) |
12740 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12741 | xfree (self->function_name); |
8b4f3082 PA |
12742 | |
12743 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12744 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12745 | } |
12746 | ||
12747 | static const struct bp_location_ops bp_location_ops = | |
12748 | { | |
12749 | bp_location_dtor | |
12750 | }; | |
12751 | ||
2060206e PA |
12752 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12753 | inherit from. */ | |
348d480f | 12754 | |
2060206e PA |
12755 | static void |
12756 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12757 | { |
12758 | decref_counted_command_line (&self->commands); | |
12759 | xfree (self->cond_string); | |
fb81d016 | 12760 | xfree (self->extra_string); |
348d480f | 12761 | xfree (self->addr_string); |
f8eba3c6 | 12762 | xfree (self->filter); |
348d480f | 12763 | xfree (self->addr_string_range_end); |
348d480f PA |
12764 | } |
12765 | ||
2060206e PA |
12766 | static struct bp_location * |
12767 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12768 | { |
12769 | struct bp_location *loc; | |
12770 | ||
12771 | loc = XNEW (struct bp_location); | |
12772 | init_bp_location (loc, &bp_location_ops, self); | |
12773 | return loc; | |
12774 | } | |
12775 | ||
2060206e PA |
12776 | static void |
12777 | base_breakpoint_re_set (struct breakpoint *b) | |
12778 | { | |
12779 | /* Nothing to re-set. */ | |
12780 | } | |
12781 | ||
12782 | #define internal_error_pure_virtual_called() \ | |
12783 | gdb_assert_not_reached ("pure virtual function called") | |
12784 | ||
12785 | static int | |
12786 | base_breakpoint_insert_location (struct bp_location *bl) | |
12787 | { | |
12788 | internal_error_pure_virtual_called (); | |
12789 | } | |
12790 | ||
12791 | static int | |
12792 | base_breakpoint_remove_location (struct bp_location *bl) | |
12793 | { | |
12794 | internal_error_pure_virtual_called (); | |
12795 | } | |
12796 | ||
12797 | static int | |
12798 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12799 | struct address_space *aspace, | |
09ac7c10 TT |
12800 | CORE_ADDR bp_addr, |
12801 | const struct target_waitstatus *ws) | |
2060206e PA |
12802 | { |
12803 | internal_error_pure_virtual_called (); | |
12804 | } | |
12805 | ||
12806 | static void | |
12807 | base_breakpoint_check_status (bpstat bs) | |
12808 | { | |
12809 | /* Always stop. */ | |
12810 | } | |
12811 | ||
12812 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12813 | errors. */ | |
12814 | ||
12815 | static int | |
12816 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12817 | { | |
12818 | internal_error_pure_virtual_called (); | |
12819 | } | |
12820 | ||
12821 | /* A "resources_needed" breakpoint_ops method that just internal | |
12822 | errors. */ | |
12823 | ||
12824 | static int | |
12825 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12826 | { | |
12827 | internal_error_pure_virtual_called (); | |
12828 | } | |
12829 | ||
12830 | static enum print_stop_action | |
12831 | base_breakpoint_print_it (bpstat bs) | |
12832 | { | |
12833 | internal_error_pure_virtual_called (); | |
12834 | } | |
12835 | ||
12836 | static void | |
12837 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12838 | struct ui_out *uiout) | |
12839 | { | |
12840 | /* nothing */ | |
12841 | } | |
12842 | ||
12843 | static void | |
12844 | base_breakpoint_print_mention (struct breakpoint *b) | |
12845 | { | |
12846 | internal_error_pure_virtual_called (); | |
12847 | } | |
12848 | ||
12849 | static void | |
12850 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12851 | { | |
12852 | internal_error_pure_virtual_called (); | |
12853 | } | |
12854 | ||
983af33b SDJ |
12855 | static void |
12856 | base_breakpoint_create_sals_from_address (char **arg, | |
12857 | struct linespec_result *canonical, | |
12858 | enum bptype type_wanted, | |
12859 | char *addr_start, | |
12860 | char **copy_arg) | |
12861 | { | |
12862 | internal_error_pure_virtual_called (); | |
12863 | } | |
12864 | ||
12865 | static void | |
12866 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12867 | struct linespec_result *c, | |
983af33b | 12868 | char *cond_string, |
e7e0cddf | 12869 | char *extra_string, |
983af33b SDJ |
12870 | enum bptype type_wanted, |
12871 | enum bpdisp disposition, | |
12872 | int thread, | |
12873 | int task, int ignore_count, | |
12874 | const struct breakpoint_ops *o, | |
12875 | int from_tty, int enabled, | |
44f238bb | 12876 | int internal, unsigned flags) |
983af33b SDJ |
12877 | { |
12878 | internal_error_pure_virtual_called (); | |
12879 | } | |
12880 | ||
12881 | static void | |
12882 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12883 | struct symtabs_and_lines *sals) | |
12884 | { | |
12885 | internal_error_pure_virtual_called (); | |
12886 | } | |
12887 | ||
ab04a2af TT |
12888 | /* The default 'explains_signal' method. */ |
12889 | ||
47591c29 | 12890 | static int |
427cd150 | 12891 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12892 | { |
47591c29 | 12893 | return 1; |
ab04a2af TT |
12894 | } |
12895 | ||
9d6e6e84 HZ |
12896 | /* The default "after_condition_true" method. */ |
12897 | ||
12898 | static void | |
12899 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12900 | { | |
12901 | /* Nothing to do. */ | |
12902 | } | |
12903 | ||
ab04a2af | 12904 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12905 | { |
12906 | base_breakpoint_dtor, | |
12907 | base_breakpoint_allocate_location, | |
12908 | base_breakpoint_re_set, | |
12909 | base_breakpoint_insert_location, | |
12910 | base_breakpoint_remove_location, | |
12911 | base_breakpoint_breakpoint_hit, | |
12912 | base_breakpoint_check_status, | |
12913 | base_breakpoint_resources_needed, | |
12914 | base_breakpoint_works_in_software_mode, | |
12915 | base_breakpoint_print_it, | |
12916 | NULL, | |
12917 | base_breakpoint_print_one_detail, | |
12918 | base_breakpoint_print_mention, | |
983af33b SDJ |
12919 | base_breakpoint_print_recreate, |
12920 | base_breakpoint_create_sals_from_address, | |
12921 | base_breakpoint_create_breakpoints_sal, | |
12922 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12923 | base_breakpoint_explains_signal, |
12924 | base_breakpoint_after_condition_true, | |
2060206e PA |
12925 | }; |
12926 | ||
12927 | /* Default breakpoint_ops methods. */ | |
12928 | ||
12929 | static void | |
348d480f PA |
12930 | bkpt_re_set (struct breakpoint *b) |
12931 | { | |
06edf0c0 PA |
12932 | /* FIXME: is this still reachable? */ |
12933 | if (b->addr_string == NULL) | |
12934 | { | |
12935 | /* Anything without a string can't be re-set. */ | |
348d480f | 12936 | delete_breakpoint (b); |
06edf0c0 | 12937 | return; |
348d480f | 12938 | } |
06edf0c0 PA |
12939 | |
12940 | breakpoint_re_set_default (b); | |
348d480f PA |
12941 | } |
12942 | ||
2060206e | 12943 | static int |
348d480f PA |
12944 | bkpt_insert_location (struct bp_location *bl) |
12945 | { | |
12946 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12947 | return target_insert_hw_breakpoint (bl->gdbarch, | |
12948 | &bl->target_info); | |
12949 | else | |
12950 | return target_insert_breakpoint (bl->gdbarch, | |
12951 | &bl->target_info); | |
12952 | } | |
12953 | ||
2060206e | 12954 | static int |
348d480f PA |
12955 | bkpt_remove_location (struct bp_location *bl) |
12956 | { | |
12957 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12958 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12959 | else | |
12960 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
12961 | } | |
12962 | ||
2060206e | 12963 | static int |
348d480f | 12964 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12965 | struct address_space *aspace, CORE_ADDR bp_addr, |
12966 | const struct target_waitstatus *ws) | |
348d480f | 12967 | { |
09ac7c10 | 12968 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12969 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12970 | return 0; |
12971 | ||
348d480f PA |
12972 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12973 | aspace, bp_addr)) | |
12974 | return 0; | |
12975 | ||
12976 | if (overlay_debugging /* unmapped overlay section */ | |
12977 | && section_is_overlay (bl->section) | |
12978 | && !section_is_mapped (bl->section)) | |
12979 | return 0; | |
12980 | ||
12981 | return 1; | |
12982 | } | |
12983 | ||
2060206e | 12984 | static int |
348d480f PA |
12985 | bkpt_resources_needed (const struct bp_location *bl) |
12986 | { | |
12987 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12988 | ||
12989 | return 1; | |
12990 | } | |
12991 | ||
2060206e | 12992 | static enum print_stop_action |
348d480f PA |
12993 | bkpt_print_it (bpstat bs) |
12994 | { | |
348d480f PA |
12995 | struct breakpoint *b; |
12996 | const struct bp_location *bl; | |
001c8c33 | 12997 | int bp_temp; |
79a45e25 | 12998 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12999 | |
13000 | gdb_assert (bs->bp_location_at != NULL); | |
13001 | ||
13002 | bl = bs->bp_location_at; | |
13003 | b = bs->breakpoint_at; | |
13004 | ||
001c8c33 PA |
13005 | bp_temp = b->disposition == disp_del; |
13006 | if (bl->address != bl->requested_address) | |
13007 | breakpoint_adjustment_warning (bl->requested_address, | |
13008 | bl->address, | |
13009 | b->number, 1); | |
13010 | annotate_breakpoint (b->number); | |
13011 | if (bp_temp) | |
13012 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13013 | else | |
13014 | ui_out_text (uiout, "\nBreakpoint "); | |
13015 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13016 | { |
001c8c33 PA |
13017 | ui_out_field_string (uiout, "reason", |
13018 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13019 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13020 | } |
001c8c33 PA |
13021 | ui_out_field_int (uiout, "bkptno", b->number); |
13022 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13023 | |
001c8c33 | 13024 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13025 | } |
13026 | ||
2060206e | 13027 | static void |
06edf0c0 PA |
13028 | bkpt_print_mention (struct breakpoint *b) |
13029 | { | |
79a45e25 | 13030 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13031 | return; |
13032 | ||
13033 | switch (b->type) | |
13034 | { | |
13035 | case bp_breakpoint: | |
13036 | case bp_gnu_ifunc_resolver: | |
13037 | if (b->disposition == disp_del) | |
13038 | printf_filtered (_("Temporary breakpoint")); | |
13039 | else | |
13040 | printf_filtered (_("Breakpoint")); | |
13041 | printf_filtered (_(" %d"), b->number); | |
13042 | if (b->type == bp_gnu_ifunc_resolver) | |
13043 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13044 | break; | |
13045 | case bp_hardware_breakpoint: | |
13046 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13047 | break; | |
e7e0cddf SS |
13048 | case bp_dprintf: |
13049 | printf_filtered (_("Dprintf %d"), b->number); | |
13050 | break; | |
06edf0c0 PA |
13051 | } |
13052 | ||
13053 | say_where (b); | |
13054 | } | |
13055 | ||
2060206e | 13056 | static void |
06edf0c0 PA |
13057 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13058 | { | |
13059 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13060 | fprintf_unfiltered (fp, "tbreak"); | |
13061 | else if (tp->type == bp_breakpoint) | |
13062 | fprintf_unfiltered (fp, "break"); | |
13063 | else if (tp->type == bp_hardware_breakpoint | |
13064 | && tp->disposition == disp_del) | |
13065 | fprintf_unfiltered (fp, "thbreak"); | |
13066 | else if (tp->type == bp_hardware_breakpoint) | |
13067 | fprintf_unfiltered (fp, "hbreak"); | |
13068 | else | |
13069 | internal_error (__FILE__, __LINE__, | |
13070 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13071 | ||
2060206e | 13072 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13073 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13074 | } |
13075 | ||
983af33b SDJ |
13076 | static void |
13077 | bkpt_create_sals_from_address (char **arg, | |
13078 | struct linespec_result *canonical, | |
13079 | enum bptype type_wanted, | |
13080 | char *addr_start, char **copy_arg) | |
13081 | { | |
13082 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13083 | addr_start, copy_arg); | |
13084 | } | |
13085 | ||
13086 | static void | |
13087 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13088 | struct linespec_result *canonical, | |
983af33b | 13089 | char *cond_string, |
e7e0cddf | 13090 | char *extra_string, |
983af33b SDJ |
13091 | enum bptype type_wanted, |
13092 | enum bpdisp disposition, | |
13093 | int thread, | |
13094 | int task, int ignore_count, | |
13095 | const struct breakpoint_ops *ops, | |
13096 | int from_tty, int enabled, | |
44f238bb | 13097 | int internal, unsigned flags) |
983af33b | 13098 | { |
023fa29b | 13099 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13100 | cond_string, extra_string, |
13101 | type_wanted, | |
983af33b SDJ |
13102 | disposition, thread, task, |
13103 | ignore_count, ops, from_tty, | |
44f238bb | 13104 | enabled, internal, flags); |
983af33b SDJ |
13105 | } |
13106 | ||
13107 | static void | |
13108 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13109 | struct symtabs_and_lines *sals) | |
13110 | { | |
13111 | decode_linespec_default (b, s, sals); | |
13112 | } | |
13113 | ||
06edf0c0 PA |
13114 | /* Virtual table for internal breakpoints. */ |
13115 | ||
13116 | static void | |
13117 | internal_bkpt_re_set (struct breakpoint *b) | |
13118 | { | |
13119 | switch (b->type) | |
13120 | { | |
13121 | /* Delete overlay event and longjmp master breakpoints; they | |
13122 | will be reset later by breakpoint_re_set. */ | |
13123 | case bp_overlay_event: | |
13124 | case bp_longjmp_master: | |
13125 | case bp_std_terminate_master: | |
13126 | case bp_exception_master: | |
13127 | delete_breakpoint (b); | |
13128 | break; | |
13129 | ||
13130 | /* This breakpoint is special, it's set up when the inferior | |
13131 | starts and we really don't want to touch it. */ | |
13132 | case bp_shlib_event: | |
13133 | ||
13134 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13135 | it is set up, we do not want to touch it. */ | |
13136 | case bp_thread_event: | |
13137 | break; | |
13138 | } | |
13139 | } | |
13140 | ||
13141 | static void | |
13142 | internal_bkpt_check_status (bpstat bs) | |
13143 | { | |
a9b3a50f PA |
13144 | if (bs->breakpoint_at->type == bp_shlib_event) |
13145 | { | |
13146 | /* If requested, stop when the dynamic linker notifies GDB of | |
13147 | events. This allows the user to get control and place | |
13148 | breakpoints in initializer routines for dynamically loaded | |
13149 | objects (among other things). */ | |
13150 | bs->stop = stop_on_solib_events; | |
13151 | bs->print = stop_on_solib_events; | |
13152 | } | |
13153 | else | |
13154 | bs->stop = 0; | |
06edf0c0 PA |
13155 | } |
13156 | ||
13157 | static enum print_stop_action | |
13158 | internal_bkpt_print_it (bpstat bs) | |
13159 | { | |
06edf0c0 | 13160 | struct breakpoint *b; |
06edf0c0 | 13161 | |
06edf0c0 PA |
13162 | b = bs->breakpoint_at; |
13163 | ||
06edf0c0 PA |
13164 | switch (b->type) |
13165 | { | |
348d480f PA |
13166 | case bp_shlib_event: |
13167 | /* Did we stop because the user set the stop_on_solib_events | |
13168 | variable? (If so, we report this as a generic, "Stopped due | |
13169 | to shlib event" message.) */ | |
edcc5120 | 13170 | print_solib_event (0); |
348d480f PA |
13171 | break; |
13172 | ||
13173 | case bp_thread_event: | |
13174 | /* Not sure how we will get here. | |
13175 | GDB should not stop for these breakpoints. */ | |
13176 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13177 | break; |
13178 | ||
13179 | case bp_overlay_event: | |
13180 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13181 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13182 | break; |
13183 | ||
13184 | case bp_longjmp_master: | |
13185 | /* These should never be enabled. */ | |
13186 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13187 | break; |
13188 | ||
13189 | case bp_std_terminate_master: | |
13190 | /* These should never be enabled. */ | |
13191 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13192 | "gdb should not stop!\n")); | |
348d480f PA |
13193 | break; |
13194 | ||
13195 | case bp_exception_master: | |
13196 | /* These should never be enabled. */ | |
13197 | printf_filtered (_("Exception Master Breakpoint: " | |
13198 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13199 | break; |
13200 | } | |
13201 | ||
001c8c33 | 13202 | return PRINT_NOTHING; |
06edf0c0 PA |
13203 | } |
13204 | ||
13205 | static void | |
13206 | internal_bkpt_print_mention (struct breakpoint *b) | |
13207 | { | |
13208 | /* Nothing to mention. These breakpoints are internal. */ | |
13209 | } | |
13210 | ||
06edf0c0 PA |
13211 | /* Virtual table for momentary breakpoints */ |
13212 | ||
13213 | static void | |
13214 | momentary_bkpt_re_set (struct breakpoint *b) | |
13215 | { | |
13216 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13217 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13218 | Otherwise these should have been blown away via the cleanup chain |
13219 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13220 | } | |
13221 | ||
13222 | static void | |
13223 | momentary_bkpt_check_status (bpstat bs) | |
13224 | { | |
13225 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13226 | } | |
13227 | ||
13228 | static enum print_stop_action | |
13229 | momentary_bkpt_print_it (bpstat bs) | |
13230 | { | |
79a45e25 PA |
13231 | struct ui_out *uiout = current_uiout; |
13232 | ||
001c8c33 | 13233 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13234 | { |
001c8c33 | 13235 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13236 | |
001c8c33 PA |
13237 | switch (b->type) |
13238 | { | |
13239 | case bp_finish: | |
13240 | ui_out_field_string | |
13241 | (uiout, "reason", | |
13242 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13243 | break; | |
348d480f | 13244 | |
001c8c33 PA |
13245 | case bp_until: |
13246 | ui_out_field_string | |
13247 | (uiout, "reason", | |
13248 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13249 | break; | |
13250 | } | |
348d480f PA |
13251 | } |
13252 | ||
001c8c33 | 13253 | return PRINT_UNKNOWN; |
348d480f PA |
13254 | } |
13255 | ||
06edf0c0 PA |
13256 | static void |
13257 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13258 | { |
06edf0c0 | 13259 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13260 | } |
13261 | ||
e2e4d78b JK |
13262 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13263 | ||
13264 | It gets cleared already on the removal of the first one of such placed | |
13265 | breakpoints. This is OK as they get all removed altogether. */ | |
13266 | ||
13267 | static void | |
13268 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13269 | { | |
13270 | struct thread_info *tp = find_thread_id (self->thread); | |
13271 | ||
13272 | if (tp) | |
13273 | tp->initiating_frame = null_frame_id; | |
13274 | ||
13275 | momentary_breakpoint_ops.dtor (self); | |
13276 | } | |
13277 | ||
55aa24fb SDJ |
13278 | /* Specific methods for probe breakpoints. */ |
13279 | ||
13280 | static int | |
13281 | bkpt_probe_insert_location (struct bp_location *bl) | |
13282 | { | |
13283 | int v = bkpt_insert_location (bl); | |
13284 | ||
13285 | if (v == 0) | |
13286 | { | |
13287 | /* The insertion was successful, now let's set the probe's semaphore | |
13288 | if needed. */ | |
13289 | bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch); | |
13290 | } | |
13291 | ||
13292 | return v; | |
13293 | } | |
13294 | ||
13295 | static int | |
13296 | bkpt_probe_remove_location (struct bp_location *bl) | |
13297 | { | |
13298 | /* Let's clear the semaphore before removing the location. */ | |
13299 | bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch); | |
13300 | ||
13301 | return bkpt_remove_location (bl); | |
13302 | } | |
13303 | ||
13304 | static void | |
13305 | bkpt_probe_create_sals_from_address (char **arg, | |
13306 | struct linespec_result *canonical, | |
13307 | enum bptype type_wanted, | |
13308 | char *addr_start, char **copy_arg) | |
13309 | { | |
13310 | struct linespec_sals lsal; | |
13311 | ||
13312 | lsal.sals = parse_probes (arg, canonical); | |
13313 | ||
13314 | *copy_arg = xstrdup (canonical->addr_string); | |
13315 | lsal.canonical = xstrdup (*copy_arg); | |
13316 | ||
13317 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13318 | } | |
13319 | ||
13320 | static void | |
13321 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13322 | struct symtabs_and_lines *sals) | |
13323 | { | |
13324 | *sals = parse_probes (s, NULL); | |
13325 | if (!sals->sals) | |
13326 | error (_("probe not found")); | |
13327 | } | |
13328 | ||
348d480f | 13329 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13330 | |
348d480f PA |
13331 | static void |
13332 | tracepoint_re_set (struct breakpoint *b) | |
13333 | { | |
13334 | breakpoint_re_set_default (b); | |
13335 | } | |
876fa593 | 13336 | |
348d480f PA |
13337 | static int |
13338 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13339 | struct address_space *aspace, CORE_ADDR bp_addr, |
13340 | const struct target_waitstatus *ws) | |
348d480f PA |
13341 | { |
13342 | /* By definition, the inferior does not report stops at | |
13343 | tracepoints. */ | |
13344 | return 0; | |
74960c60 VP |
13345 | } |
13346 | ||
13347 | static void | |
348d480f PA |
13348 | tracepoint_print_one_detail (const struct breakpoint *self, |
13349 | struct ui_out *uiout) | |
74960c60 | 13350 | { |
d9b3f62e PA |
13351 | struct tracepoint *tp = (struct tracepoint *) self; |
13352 | if (tp->static_trace_marker_id) | |
348d480f PA |
13353 | { |
13354 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13355 | |
348d480f PA |
13356 | ui_out_text (uiout, "\tmarker id is "); |
13357 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13358 | tp->static_trace_marker_id); |
348d480f PA |
13359 | ui_out_text (uiout, "\n"); |
13360 | } | |
0d381245 VP |
13361 | } |
13362 | ||
a474d7c2 | 13363 | static void |
348d480f | 13364 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13365 | { |
79a45e25 | 13366 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13367 | return; |
cc59ec59 | 13368 | |
348d480f PA |
13369 | switch (b->type) |
13370 | { | |
13371 | case bp_tracepoint: | |
13372 | printf_filtered (_("Tracepoint")); | |
13373 | printf_filtered (_(" %d"), b->number); | |
13374 | break; | |
13375 | case bp_fast_tracepoint: | |
13376 | printf_filtered (_("Fast tracepoint")); | |
13377 | printf_filtered (_(" %d"), b->number); | |
13378 | break; | |
13379 | case bp_static_tracepoint: | |
13380 | printf_filtered (_("Static tracepoint")); | |
13381 | printf_filtered (_(" %d"), b->number); | |
13382 | break; | |
13383 | default: | |
13384 | internal_error (__FILE__, __LINE__, | |
13385 | _("unhandled tracepoint type %d"), (int) b->type); | |
13386 | } | |
13387 | ||
13388 | say_where (b); | |
a474d7c2 PA |
13389 | } |
13390 | ||
348d480f | 13391 | static void |
d9b3f62e | 13392 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13393 | { |
d9b3f62e PA |
13394 | struct tracepoint *tp = (struct tracepoint *) self; |
13395 | ||
13396 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13397 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13398 | if (self->type == bp_static_tracepoint) |
348d480f | 13399 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13400 | else if (self->type == bp_tracepoint) |
348d480f PA |
13401 | fprintf_unfiltered (fp, "trace"); |
13402 | else | |
13403 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13404 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13405 | |
d9b3f62e PA |
13406 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13407 | print_recreate_thread (self, fp); | |
13408 | ||
13409 | if (tp->pass_count) | |
13410 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13411 | } |
13412 | ||
983af33b SDJ |
13413 | static void |
13414 | tracepoint_create_sals_from_address (char **arg, | |
13415 | struct linespec_result *canonical, | |
13416 | enum bptype type_wanted, | |
13417 | char *addr_start, char **copy_arg) | |
13418 | { | |
13419 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13420 | addr_start, copy_arg); | |
13421 | } | |
13422 | ||
13423 | static void | |
13424 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13425 | struct linespec_result *canonical, | |
983af33b | 13426 | char *cond_string, |
e7e0cddf | 13427 | char *extra_string, |
983af33b SDJ |
13428 | enum bptype type_wanted, |
13429 | enum bpdisp disposition, | |
13430 | int thread, | |
13431 | int task, int ignore_count, | |
13432 | const struct breakpoint_ops *ops, | |
13433 | int from_tty, int enabled, | |
44f238bb | 13434 | int internal, unsigned flags) |
983af33b | 13435 | { |
023fa29b | 13436 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13437 | cond_string, extra_string, |
13438 | type_wanted, | |
983af33b SDJ |
13439 | disposition, thread, task, |
13440 | ignore_count, ops, from_tty, | |
44f238bb | 13441 | enabled, internal, flags); |
983af33b SDJ |
13442 | } |
13443 | ||
13444 | static void | |
13445 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13446 | struct symtabs_and_lines *sals) | |
13447 | { | |
13448 | decode_linespec_default (b, s, sals); | |
13449 | } | |
13450 | ||
2060206e | 13451 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13452 | |
55aa24fb SDJ |
13453 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13454 | static probe. */ | |
13455 | ||
13456 | static void | |
13457 | tracepoint_probe_create_sals_from_address (char **arg, | |
13458 | struct linespec_result *canonical, | |
13459 | enum bptype type_wanted, | |
13460 | char *addr_start, char **copy_arg) | |
13461 | { | |
13462 | /* We use the same method for breakpoint on probes. */ | |
13463 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13464 | addr_start, copy_arg); | |
13465 | } | |
13466 | ||
13467 | static void | |
13468 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13469 | struct symtabs_and_lines *sals) | |
13470 | { | |
13471 | /* We use the same method for breakpoint on probes. */ | |
13472 | bkpt_probe_decode_linespec (b, s, sals); | |
13473 | } | |
13474 | ||
13475 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13476 | ||
5c2b4418 HZ |
13477 | /* Dprintf breakpoint_ops methods. */ |
13478 | ||
13479 | static void | |
13480 | dprintf_re_set (struct breakpoint *b) | |
13481 | { | |
13482 | breakpoint_re_set_default (b); | |
13483 | ||
13484 | /* This breakpoint could have been pending, and be resolved now, and | |
13485 | if so, we should now have the extra string. If we don't, the | |
13486 | dprintf was malformed when created, but we couldn't tell because | |
13487 | we can't extract the extra string until the location is | |
13488 | resolved. */ | |
13489 | if (b->loc != NULL && b->extra_string == NULL) | |
13490 | error (_("Format string required")); | |
13491 | ||
13492 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13493 | 2 - create a dprintf, which resolves fine. | |
13494 | 3 - disconnect from target 1 | |
13495 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13496 | ||
13497 | After steps #3/#4, you'll want the dprintf command list to | |
13498 | be updated, because target 1 and 2 may well return different | |
13499 | answers for target_can_run_breakpoint_commands(). | |
13500 | Given absence of finer grained resetting, we get to do | |
13501 | it all the time. */ | |
13502 | if (b->extra_string != NULL) | |
13503 | update_dprintf_command_list (b); | |
13504 | } | |
13505 | ||
2d9442cc HZ |
13506 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13507 | ||
13508 | static void | |
13509 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13510 | { | |
13511 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13512 | tp->extra_string); | |
13513 | print_recreate_thread (tp, fp); | |
13514 | } | |
13515 | ||
9d6e6e84 HZ |
13516 | /* Implement the "after_condition_true" breakpoint_ops method for |
13517 | dprintf. | |
13518 | ||
13519 | dprintf's are implemented with regular commands in their command | |
13520 | list, but we run the commands here instead of before presenting the | |
13521 | stop to the user, as dprintf's don't actually cause a stop. This | |
13522 | also makes it so that the commands of multiple dprintfs at the same | |
13523 | address are all handled. */ | |
13524 | ||
13525 | static void | |
13526 | dprintf_after_condition_true (struct bpstats *bs) | |
13527 | { | |
13528 | struct cleanup *old_chain; | |
13529 | struct bpstats tmp_bs = { NULL }; | |
13530 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13531 | ||
13532 | /* dprintf's never cause a stop. This wasn't set in the | |
13533 | check_status hook instead because that would make the dprintf's | |
13534 | condition not be evaluated. */ | |
13535 | bs->stop = 0; | |
13536 | ||
13537 | /* Run the command list here. Take ownership of it instead of | |
13538 | copying. We never want these commands to run later in | |
13539 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13540 | be set at same address as this dprintf, or even if running the | |
13541 | commands here throws. */ | |
13542 | tmp_bs.commands = bs->commands; | |
13543 | bs->commands = NULL; | |
13544 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13545 | ||
13546 | bpstat_do_actions_1 (&tmp_bs_p); | |
13547 | ||
13548 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13549 | bpstat_do_actions_1 may return early without processing the whole | |
13550 | list. */ | |
13551 | do_cleanups (old_chain); | |
13552 | } | |
13553 | ||
983af33b SDJ |
13554 | /* The breakpoint_ops structure to be used on static tracepoints with |
13555 | markers (`-m'). */ | |
13556 | ||
13557 | static void | |
13558 | strace_marker_create_sals_from_address (char **arg, | |
13559 | struct linespec_result *canonical, | |
13560 | enum bptype type_wanted, | |
13561 | char *addr_start, char **copy_arg) | |
13562 | { | |
13563 | struct linespec_sals lsal; | |
13564 | ||
13565 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13566 | ||
13567 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13568 | ||
13569 | canonical->addr_string = xstrdup (*copy_arg); | |
13570 | lsal.canonical = xstrdup (*copy_arg); | |
13571 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13572 | } | |
13573 | ||
13574 | static void | |
13575 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13576 | struct linespec_result *canonical, | |
983af33b | 13577 | char *cond_string, |
e7e0cddf | 13578 | char *extra_string, |
983af33b SDJ |
13579 | enum bptype type_wanted, |
13580 | enum bpdisp disposition, | |
13581 | int thread, | |
13582 | int task, int ignore_count, | |
13583 | const struct breakpoint_ops *ops, | |
13584 | int from_tty, int enabled, | |
44f238bb | 13585 | int internal, unsigned flags) |
983af33b SDJ |
13586 | { |
13587 | int i; | |
52d361e1 YQ |
13588 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13589 | canonical->sals, 0); | |
983af33b SDJ |
13590 | |
13591 | /* If the user is creating a static tracepoint by marker id | |
13592 | (strace -m MARKER_ID), then store the sals index, so that | |
13593 | breakpoint_re_set can try to match up which of the newly | |
13594 | found markers corresponds to this one, and, don't try to | |
13595 | expand multiple locations for each sal, given than SALS | |
13596 | already should contain all sals for MARKER_ID. */ | |
13597 | ||
13598 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13599 | { | |
13600 | struct symtabs_and_lines expanded; | |
13601 | struct tracepoint *tp; | |
13602 | struct cleanup *old_chain; | |
13603 | char *addr_string; | |
13604 | ||
13605 | expanded.nelts = 1; | |
13606 | expanded.sals = &lsal->sals.sals[i]; | |
13607 | ||
13608 | addr_string = xstrdup (canonical->addr_string); | |
13609 | old_chain = make_cleanup (xfree, addr_string); | |
13610 | ||
13611 | tp = XCNEW (struct tracepoint); | |
13612 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13613 | addr_string, NULL, | |
e7e0cddf SS |
13614 | cond_string, extra_string, |
13615 | type_wanted, disposition, | |
983af33b | 13616 | thread, task, ignore_count, ops, |
44f238bb | 13617 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13618 | canonical->special_display); |
13619 | /* Given that its possible to have multiple markers with | |
13620 | the same string id, if the user is creating a static | |
13621 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13622 | store the sals index, so that breakpoint_re_set can | |
13623 | try to match up which of the newly found markers | |
13624 | corresponds to this one */ | |
13625 | tp->static_trace_marker_id_idx = i; | |
13626 | ||
13627 | install_breakpoint (internal, &tp->base, 0); | |
13628 | ||
13629 | discard_cleanups (old_chain); | |
13630 | } | |
13631 | } | |
13632 | ||
13633 | static void | |
13634 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13635 | struct symtabs_and_lines *sals) | |
13636 | { | |
13637 | struct tracepoint *tp = (struct tracepoint *) b; | |
13638 | ||
13639 | *sals = decode_static_tracepoint_spec (s); | |
13640 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13641 | { | |
13642 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13643 | sals->nelts = 1; | |
13644 | } | |
13645 | else | |
13646 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13647 | } | |
13648 | ||
13649 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13650 | ||
13651 | static int | |
13652 | strace_marker_p (struct breakpoint *b) | |
13653 | { | |
13654 | return b->ops == &strace_marker_breakpoint_ops; | |
13655 | } | |
13656 | ||
53a5351d | 13657 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13658 | structures. */ |
c906108c SS |
13659 | |
13660 | void | |
fba45db2 | 13661 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13662 | { |
52f0bd74 | 13663 | struct breakpoint *b; |
c906108c | 13664 | |
8a3fe4f8 | 13665 | gdb_assert (bpt != NULL); |
c906108c | 13666 | |
4a64f543 MS |
13667 | /* Has this bp already been deleted? This can happen because |
13668 | multiple lists can hold pointers to bp's. bpstat lists are | |
13669 | especial culprits. | |
13670 | ||
13671 | One example of this happening is a watchpoint's scope bp. When | |
13672 | the scope bp triggers, we notice that the watchpoint is out of | |
13673 | scope, and delete it. We also delete its scope bp. But the | |
13674 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13675 | That bpstat is then checked for auto-deleting bp's, which are | |
13676 | deleted. | |
13677 | ||
13678 | A real solution to this problem might involve reference counts in | |
13679 | bp's, and/or giving them pointers back to their referencing | |
13680 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13681 | storage when no more references were extent. A cheaper bandaid | |
13682 | was chosen. */ | |
c906108c SS |
13683 | if (bpt->type == bp_none) |
13684 | return; | |
13685 | ||
4a64f543 MS |
13686 | /* At least avoid this stale reference until the reference counting |
13687 | of breakpoints gets resolved. */ | |
d0fb5eae | 13688 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13689 | { |
d0fb5eae | 13690 | struct breakpoint *related; |
3a5c3e22 | 13691 | struct watchpoint *w; |
d0fb5eae JK |
13692 | |
13693 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13694 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13695 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13696 | w = (struct watchpoint *) bpt; |
13697 | else | |
13698 | w = NULL; | |
13699 | if (w != NULL) | |
13700 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13701 | |
13702 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13703 | for (related = bpt; related->related_breakpoint != bpt; | |
13704 | related = related->related_breakpoint); | |
13705 | related->related_breakpoint = bpt->related_breakpoint; | |
13706 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13707 | } |
13708 | ||
a9634178 TJB |
13709 | /* watch_command_1 creates a watchpoint but only sets its number if |
13710 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13711 | a problem in that process, we'll be asked to delete the half-created | |
13712 | watchpoint. In that case, don't announce the deletion. */ | |
13713 | if (bpt->number) | |
13714 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13715 | |
c906108c SS |
13716 | if (breakpoint_chain == bpt) |
13717 | breakpoint_chain = bpt->next; | |
13718 | ||
c906108c SS |
13719 | ALL_BREAKPOINTS (b) |
13720 | if (b->next == bpt) | |
c5aa993b JM |
13721 | { |
13722 | b->next = bpt->next; | |
13723 | break; | |
13724 | } | |
c906108c | 13725 | |
f431efe5 PA |
13726 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13727 | been freed. */ | |
13728 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13729 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13730 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13731 | commands are associated with the bpstat; if we remove it here, | |
13732 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13733 | event-top.c won't do anything, and temporary breakpoints with | |
13734 | commands won't work. */ | |
13735 | ||
13736 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13737 | ||
4a64f543 MS |
13738 | /* Now that breakpoint is removed from breakpoint list, update the |
13739 | global location list. This will remove locations that used to | |
13740 | belong to this breakpoint. Do this before freeing the breakpoint | |
13741 | itself, since remove_breakpoint looks at location's owner. It | |
13742 | might be better design to have location completely | |
13743 | self-contained, but it's not the case now. */ | |
b60e7edf | 13744 | update_global_location_list (0); |
74960c60 | 13745 | |
348d480f | 13746 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13747 | /* On the chance that someone will soon try again to delete this |
13748 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13749 | bpt->type = bp_none; |
b8c9b27d | 13750 | xfree (bpt); |
c906108c SS |
13751 | } |
13752 | ||
4d6140d9 AC |
13753 | static void |
13754 | do_delete_breakpoint_cleanup (void *b) | |
13755 | { | |
13756 | delete_breakpoint (b); | |
13757 | } | |
13758 | ||
13759 | struct cleanup * | |
13760 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13761 | { | |
13762 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13763 | } | |
13764 | ||
51be5b68 PA |
13765 | /* Iterator function to call a user-provided callback function once |
13766 | for each of B and its related breakpoints. */ | |
13767 | ||
13768 | static void | |
13769 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13770 | void (*function) (struct breakpoint *, | |
13771 | void *), | |
13772 | void *data) | |
13773 | { | |
13774 | struct breakpoint *related; | |
13775 | ||
13776 | related = b; | |
13777 | do | |
13778 | { | |
13779 | struct breakpoint *next; | |
13780 | ||
13781 | /* FUNCTION may delete RELATED. */ | |
13782 | next = related->related_breakpoint; | |
13783 | ||
13784 | if (next == related) | |
13785 | { | |
13786 | /* RELATED is the last ring entry. */ | |
13787 | function (related, data); | |
13788 | ||
13789 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13790 | B. There's nothing left to do anyway, so just break | |
13791 | out. */ | |
13792 | break; | |
13793 | } | |
13794 | else | |
13795 | function (related, data); | |
13796 | ||
13797 | related = next; | |
13798 | } | |
13799 | while (related != b); | |
13800 | } | |
95a42b64 TT |
13801 | |
13802 | static void | |
13803 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13804 | { | |
13805 | delete_breakpoint (b); | |
13806 | } | |
13807 | ||
51be5b68 PA |
13808 | /* A callback for map_breakpoint_numbers that calls |
13809 | delete_breakpoint. */ | |
13810 | ||
13811 | static void | |
13812 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13813 | { | |
13814 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13815 | } | |
13816 | ||
c906108c | 13817 | void |
fba45db2 | 13818 | delete_command (char *arg, int from_tty) |
c906108c | 13819 | { |
35df4500 | 13820 | struct breakpoint *b, *b_tmp; |
c906108c | 13821 | |
ea9365bb TT |
13822 | dont_repeat (); |
13823 | ||
c906108c SS |
13824 | if (arg == 0) |
13825 | { | |
13826 | int breaks_to_delete = 0; | |
13827 | ||
46c6471b PA |
13828 | /* Delete all breakpoints if no argument. Do not delete |
13829 | internal breakpoints, these have to be deleted with an | |
13830 | explicit breakpoint number argument. */ | |
c5aa993b | 13831 | ALL_BREAKPOINTS (b) |
46c6471b | 13832 | if (user_breakpoint_p (b)) |
973d738b DJ |
13833 | { |
13834 | breaks_to_delete = 1; | |
13835 | break; | |
13836 | } | |
c906108c SS |
13837 | |
13838 | /* Ask user only if there are some breakpoints to delete. */ | |
13839 | if (!from_tty | |
e2e0b3e5 | 13840 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13841 | { |
35df4500 | 13842 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13843 | if (user_breakpoint_p (b)) |
c5aa993b | 13844 | delete_breakpoint (b); |
c906108c SS |
13845 | } |
13846 | } | |
13847 | else | |
51be5b68 | 13848 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13849 | } |
13850 | ||
0d381245 VP |
13851 | static int |
13852 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13853 | { |
0d381245 | 13854 | for (; loc; loc = loc->next) |
8645ff69 UW |
13855 | if (!loc->shlib_disabled |
13856 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13857 | return 0; |
13858 | return 1; | |
fe3f5fa8 VP |
13859 | } |
13860 | ||
776592bf DE |
13861 | /* Subroutine of update_breakpoint_locations to simplify it. |
13862 | Return non-zero if multiple fns in list LOC have the same name. | |
13863 | Null names are ignored. */ | |
13864 | ||
13865 | static int | |
13866 | ambiguous_names_p (struct bp_location *loc) | |
13867 | { | |
13868 | struct bp_location *l; | |
13869 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13870 | (int (*) (const void *, |
13871 | const void *)) streq, | |
776592bf DE |
13872 | NULL, xcalloc, xfree); |
13873 | ||
13874 | for (l = loc; l != NULL; l = l->next) | |
13875 | { | |
13876 | const char **slot; | |
13877 | const char *name = l->function_name; | |
13878 | ||
13879 | /* Allow for some names to be NULL, ignore them. */ | |
13880 | if (name == NULL) | |
13881 | continue; | |
13882 | ||
13883 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13884 | INSERT); | |
4a64f543 MS |
13885 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13886 | returns NULL. */ | |
776592bf DE |
13887 | if (*slot != NULL) |
13888 | { | |
13889 | htab_delete (htab); | |
13890 | return 1; | |
13891 | } | |
13892 | *slot = name; | |
13893 | } | |
13894 | ||
13895 | htab_delete (htab); | |
13896 | return 0; | |
13897 | } | |
13898 | ||
0fb4aa4b PA |
13899 | /* When symbols change, it probably means the sources changed as well, |
13900 | and it might mean the static tracepoint markers are no longer at | |
13901 | the same address or line numbers they used to be at last we | |
13902 | checked. Losing your static tracepoints whenever you rebuild is | |
13903 | undesirable. This function tries to resync/rematch gdb static | |
13904 | tracepoints with the markers on the target, for static tracepoints | |
13905 | that have not been set by marker id. Static tracepoint that have | |
13906 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13907 | The heuristic is: | |
13908 | ||
13909 | 1) For a tracepoint set at a specific address, look for a marker at | |
13910 | the old PC. If one is found there, assume to be the same marker. | |
13911 | If the name / string id of the marker found is different from the | |
13912 | previous known name, assume that means the user renamed the marker | |
13913 | in the sources, and output a warning. | |
13914 | ||
13915 | 2) For a tracepoint set at a given line number, look for a marker | |
13916 | at the new address of the old line number. If one is found there, | |
13917 | assume to be the same marker. If the name / string id of the | |
13918 | marker found is different from the previous known name, assume that | |
13919 | means the user renamed the marker in the sources, and output a | |
13920 | warning. | |
13921 | ||
13922 | 3) If a marker is no longer found at the same address or line, it | |
13923 | may mean the marker no longer exists. But it may also just mean | |
13924 | the code changed a bit. Maybe the user added a few lines of code | |
13925 | that made the marker move up or down (in line number terms). Ask | |
13926 | the target for info about the marker with the string id as we knew | |
13927 | it. If found, update line number and address in the matching | |
13928 | static tracepoint. This will get confused if there's more than one | |
13929 | marker with the same ID (possible in UST, although unadvised | |
13930 | precisely because it confuses tools). */ | |
13931 | ||
13932 | static struct symtab_and_line | |
13933 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13934 | { | |
d9b3f62e | 13935 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13936 | struct static_tracepoint_marker marker; |
13937 | CORE_ADDR pc; | |
0fb4aa4b PA |
13938 | |
13939 | pc = sal.pc; | |
13940 | if (sal.line) | |
13941 | find_line_pc (sal.symtab, sal.line, &pc); | |
13942 | ||
13943 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13944 | { | |
d9b3f62e | 13945 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13946 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13947 | b->number, | |
d9b3f62e | 13948 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13949 | |
d9b3f62e PA |
13950 | xfree (tp->static_trace_marker_id); |
13951 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13952 | release_static_tracepoint_marker (&marker); |
13953 | ||
13954 | return sal; | |
13955 | } | |
13956 | ||
13957 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13958 | by string ID. */ | |
13959 | if (!sal.explicit_pc | |
13960 | && sal.line != 0 | |
13961 | && sal.symtab != NULL | |
d9b3f62e | 13962 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13963 | { |
13964 | VEC(static_tracepoint_marker_p) *markers; | |
13965 | ||
13966 | markers | |
d9b3f62e | 13967 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13968 | |
13969 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13970 | { | |
80e1d417 | 13971 | struct symtab_and_line sal2; |
0fb4aa4b | 13972 | struct symbol *sym; |
80e1d417 | 13973 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13974 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 13975 | |
80e1d417 | 13976 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13977 | |
d9b3f62e | 13978 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13979 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13980 | |
13981 | warning (_("marker for static tracepoint %d (%s) not " | |
13982 | "found at previous line number"), | |
d9b3f62e | 13983 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13984 | |
80e1d417 | 13985 | init_sal (&sal2); |
0fb4aa4b | 13986 | |
80e1d417 | 13987 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13988 | |
80e1d417 AS |
13989 | sal2 = find_pc_line (tpmarker->address, 0); |
13990 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13991 | ui_out_text (uiout, "Now in "); |
13992 | if (sym) | |
13993 | { | |
13994 | ui_out_field_string (uiout, "func", | |
13995 | SYMBOL_PRINT_NAME (sym)); | |
13996 | ui_out_text (uiout, " at "); | |
13997 | } | |
05cba821 JK |
13998 | ui_out_field_string (uiout, "file", |
13999 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14000 | ui_out_text (uiout, ":"); |
14001 | ||
14002 | if (ui_out_is_mi_like_p (uiout)) | |
14003 | { | |
0b0865da | 14004 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14005 | |
f35a17b5 | 14006 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14007 | } |
14008 | ||
80e1d417 | 14009 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14010 | ui_out_text (uiout, "\n"); |
14011 | ||
80e1d417 | 14012 | b->loc->line_number = sal2.line; |
2f202fde | 14013 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14014 | |
14015 | xfree (b->addr_string); | |
14016 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14017 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14018 | b->loc->line_number); |
0fb4aa4b PA |
14019 | |
14020 | /* Might be nice to check if function changed, and warn if | |
14021 | so. */ | |
14022 | ||
80e1d417 | 14023 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14024 | } |
14025 | } | |
14026 | return sal; | |
14027 | } | |
14028 | ||
8d3788bd VP |
14029 | /* Returns 1 iff locations A and B are sufficiently same that |
14030 | we don't need to report breakpoint as changed. */ | |
14031 | ||
14032 | static int | |
14033 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14034 | { | |
14035 | while (a && b) | |
14036 | { | |
14037 | if (a->address != b->address) | |
14038 | return 0; | |
14039 | ||
14040 | if (a->shlib_disabled != b->shlib_disabled) | |
14041 | return 0; | |
14042 | ||
14043 | if (a->enabled != b->enabled) | |
14044 | return 0; | |
14045 | ||
14046 | a = a->next; | |
14047 | b = b->next; | |
14048 | } | |
14049 | ||
14050 | if ((a == NULL) != (b == NULL)) | |
14051 | return 0; | |
14052 | ||
14053 | return 1; | |
14054 | } | |
14055 | ||
f1310107 TJB |
14056 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14057 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14058 | a ranged breakpoint. */ | |
14059 | ||
0e30163f | 14060 | void |
0d381245 | 14061 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14062 | struct symtabs_and_lines sals, |
14063 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14064 | { |
14065 | int i; | |
0d381245 VP |
14066 | struct bp_location *existing_locations = b->loc; |
14067 | ||
f8eba3c6 TT |
14068 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14069 | { | |
14070 | /* Ranged breakpoints have only one start location and one end | |
14071 | location. */ | |
14072 | b->enable_state = bp_disabled; | |
14073 | update_global_location_list (1); | |
14074 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14075 | "multiple locations found\n"), | |
14076 | b->number); | |
14077 | return; | |
14078 | } | |
f1310107 | 14079 | |
4a64f543 MS |
14080 | /* If there's no new locations, and all existing locations are |
14081 | pending, don't do anything. This optimizes the common case where | |
14082 | all locations are in the same shared library, that was unloaded. | |
14083 | We'd like to retain the location, so that when the library is | |
14084 | loaded again, we don't loose the enabled/disabled status of the | |
14085 | individual locations. */ | |
0d381245 | 14086 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14087 | return; |
14088 | ||
fe3f5fa8 VP |
14089 | b->loc = NULL; |
14090 | ||
0d381245 | 14091 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14092 | { |
f8eba3c6 TT |
14093 | struct bp_location *new_loc; |
14094 | ||
14095 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14096 | ||
14097 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14098 | |
0d381245 VP |
14099 | /* Reparse conditions, they might contain references to the |
14100 | old symtab. */ | |
14101 | if (b->cond_string != NULL) | |
14102 | { | |
bbc13ae3 | 14103 | const char *s; |
bfd189b1 | 14104 | volatile struct gdb_exception e; |
fe3f5fa8 | 14105 | |
0d381245 VP |
14106 | s = b->cond_string; |
14107 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14108 | { | |
1bb9788d TT |
14109 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14110 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14111 | 0); |
14112 | } | |
14113 | if (e.reason < 0) | |
14114 | { | |
3e43a32a MS |
14115 | warning (_("failed to reevaluate condition " |
14116 | "for breakpoint %d: %s"), | |
0d381245 VP |
14117 | b->number, e.message); |
14118 | new_loc->enabled = 0; | |
14119 | } | |
14120 | } | |
fe3f5fa8 | 14121 | |
f1310107 TJB |
14122 | if (sals_end.nelts) |
14123 | { | |
14124 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14125 | ||
14126 | new_loc->length = end - sals.sals[0].pc + 1; | |
14127 | } | |
0d381245 | 14128 | } |
fe3f5fa8 | 14129 | |
514f746b AR |
14130 | /* Update locations of permanent breakpoints. */ |
14131 | if (b->enable_state == bp_permanent) | |
14132 | make_breakpoint_permanent (b); | |
14133 | ||
4a64f543 MS |
14134 | /* If possible, carry over 'disable' status from existing |
14135 | breakpoints. */ | |
0d381245 VP |
14136 | { |
14137 | struct bp_location *e = existing_locations; | |
776592bf DE |
14138 | /* If there are multiple breakpoints with the same function name, |
14139 | e.g. for inline functions, comparing function names won't work. | |
14140 | Instead compare pc addresses; this is just a heuristic as things | |
14141 | may have moved, but in practice it gives the correct answer | |
14142 | often enough until a better solution is found. */ | |
14143 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14144 | ||
0d381245 VP |
14145 | for (; e; e = e->next) |
14146 | { | |
14147 | if (!e->enabled && e->function_name) | |
14148 | { | |
14149 | struct bp_location *l = b->loc; | |
776592bf DE |
14150 | if (have_ambiguous_names) |
14151 | { | |
14152 | for (; l; l = l->next) | |
f1310107 | 14153 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14154 | { |
14155 | l->enabled = 0; | |
14156 | break; | |
14157 | } | |
14158 | } | |
14159 | else | |
14160 | { | |
14161 | for (; l; l = l->next) | |
14162 | if (l->function_name | |
14163 | && strcmp (e->function_name, l->function_name) == 0) | |
14164 | { | |
14165 | l->enabled = 0; | |
14166 | break; | |
14167 | } | |
14168 | } | |
0d381245 VP |
14169 | } |
14170 | } | |
14171 | } | |
fe3f5fa8 | 14172 | |
8d3788bd VP |
14173 | if (!locations_are_equal (existing_locations, b->loc)) |
14174 | observer_notify_breakpoint_modified (b); | |
14175 | ||
b60e7edf | 14176 | update_global_location_list (1); |
fe3f5fa8 VP |
14177 | } |
14178 | ||
ef23e705 TJB |
14179 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14180 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14181 | ||
14182 | static struct symtabs_and_lines | |
14183 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14184 | { | |
14185 | char *s; | |
02d20e4a | 14186 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14187 | volatile struct gdb_exception e; |
ef23e705 | 14188 | |
983af33b | 14189 | gdb_assert (b->ops != NULL); |
ef23e705 | 14190 | s = addr_string; |
ef23e705 TJB |
14191 | |
14192 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14193 | { | |
983af33b | 14194 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14195 | } |
14196 | if (e.reason < 0) | |
14197 | { | |
14198 | int not_found_and_ok = 0; | |
14199 | /* For pending breakpoints, it's expected that parsing will | |
14200 | fail until the right shared library is loaded. User has | |
14201 | already told to create pending breakpoints and don't need | |
14202 | extra messages. If breakpoint is in bp_shlib_disabled | |
14203 | state, then user already saw the message about that | |
14204 | breakpoint being disabled, and don't want to see more | |
14205 | errors. */ | |
58438ac1 | 14206 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14207 | && (b->condition_not_parsed |
14208 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14209 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14210 | || b->enable_state == bp_disabled)) |
14211 | not_found_and_ok = 1; | |
14212 | ||
14213 | if (!not_found_and_ok) | |
14214 | { | |
14215 | /* We surely don't want to warn about the same breakpoint | |
14216 | 10 times. One solution, implemented here, is disable | |
14217 | the breakpoint on error. Another solution would be to | |
14218 | have separate 'warning emitted' flag. Since this | |
14219 | happens only when a binary has changed, I don't know | |
14220 | which approach is better. */ | |
14221 | b->enable_state = bp_disabled; | |
14222 | throw_exception (e); | |
14223 | } | |
14224 | } | |
14225 | ||
58438ac1 | 14226 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14227 | { |
f8eba3c6 | 14228 | int i; |
ef23e705 | 14229 | |
f8eba3c6 TT |
14230 | for (i = 0; i < sals.nelts; ++i) |
14231 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14232 | if (b->condition_not_parsed && s && s[0]) |
14233 | { | |
ed1d1739 KS |
14234 | char *cond_string, *extra_string; |
14235 | int thread, task; | |
ef23e705 TJB |
14236 | |
14237 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14238 | &cond_string, &thread, &task, |
14239 | &extra_string); | |
ef23e705 TJB |
14240 | if (cond_string) |
14241 | b->cond_string = cond_string; | |
14242 | b->thread = thread; | |
14243 | b->task = task; | |
e7e0cddf SS |
14244 | if (extra_string) |
14245 | b->extra_string = extra_string; | |
ef23e705 TJB |
14246 | b->condition_not_parsed = 0; |
14247 | } | |
14248 | ||
983af33b | 14249 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14250 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14251 | |
58438ac1 TT |
14252 | *found = 1; |
14253 | } | |
14254 | else | |
14255 | *found = 0; | |
ef23e705 TJB |
14256 | |
14257 | return sals; | |
14258 | } | |
14259 | ||
348d480f PA |
14260 | /* The default re_set method, for typical hardware or software |
14261 | breakpoints. Reevaluate the breakpoint and recreate its | |
14262 | locations. */ | |
14263 | ||
14264 | static void | |
28010a5d | 14265 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14266 | { |
14267 | int found; | |
f1310107 | 14268 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14269 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14270 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14271 | |
14272 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14273 | if (found) | |
14274 | { | |
14275 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14276 | expanded = sals; |
ef23e705 TJB |
14277 | } |
14278 | ||
f1310107 TJB |
14279 | if (b->addr_string_range_end) |
14280 | { | |
14281 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14282 | if (found) | |
14283 | { | |
14284 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14285 | expanded_end = sals_end; |
f1310107 TJB |
14286 | } |
14287 | } | |
14288 | ||
14289 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14290 | } |
14291 | ||
983af33b SDJ |
14292 | /* Default method for creating SALs from an address string. It basically |
14293 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14294 | ||
14295 | static void | |
14296 | create_sals_from_address_default (char **arg, | |
14297 | struct linespec_result *canonical, | |
14298 | enum bptype type_wanted, | |
14299 | char *addr_start, char **copy_arg) | |
14300 | { | |
14301 | parse_breakpoint_sals (arg, canonical); | |
14302 | } | |
14303 | ||
14304 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14305 | function for the `create_breakpoints_sal' method of | |
14306 | breakpoint_ops. */ | |
14307 | ||
14308 | static void | |
14309 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14310 | struct linespec_result *canonical, | |
983af33b | 14311 | char *cond_string, |
e7e0cddf | 14312 | char *extra_string, |
983af33b SDJ |
14313 | enum bptype type_wanted, |
14314 | enum bpdisp disposition, | |
14315 | int thread, | |
14316 | int task, int ignore_count, | |
14317 | const struct breakpoint_ops *ops, | |
14318 | int from_tty, int enabled, | |
44f238bb | 14319 | int internal, unsigned flags) |
983af33b SDJ |
14320 | { |
14321 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14322 | extra_string, |
983af33b SDJ |
14323 | type_wanted, disposition, |
14324 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14325 | enabled, internal, flags); |
983af33b SDJ |
14326 | } |
14327 | ||
14328 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14329 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14330 | ||
14331 | static void | |
14332 | decode_linespec_default (struct breakpoint *b, char **s, | |
14333 | struct symtabs_and_lines *sals) | |
14334 | { | |
14335 | struct linespec_result canonical; | |
14336 | ||
14337 | init_linespec_result (&canonical); | |
14338 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14339 | (struct symtab *) NULL, 0, | |
14340 | &canonical, multiple_symbols_all, | |
14341 | b->filter); | |
14342 | ||
14343 | /* We should get 0 or 1 resulting SALs. */ | |
14344 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14345 | ||
14346 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14347 | { | |
14348 | struct linespec_sals *lsal; | |
14349 | ||
14350 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14351 | *sals = lsal->sals; | |
14352 | /* Arrange it so the destructor does not free the | |
14353 | contents. */ | |
14354 | lsal->sals.sals = NULL; | |
14355 | } | |
14356 | ||
14357 | destroy_linespec_result (&canonical); | |
14358 | } | |
14359 | ||
28010a5d PA |
14360 | /* Prepare the global context for a re-set of breakpoint B. */ |
14361 | ||
14362 | static struct cleanup * | |
14363 | prepare_re_set_context (struct breakpoint *b) | |
14364 | { | |
14365 | struct cleanup *cleanups; | |
14366 | ||
14367 | input_radix = b->input_radix; | |
14368 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14369 | if (b->pspace != NULL) |
14370 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14371 | set_language (b->language); |
14372 | ||
14373 | return cleanups; | |
ef23e705 TJB |
14374 | } |
14375 | ||
c906108c SS |
14376 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14377 | The value we return ends up being the return value from catch_errors. | |
14378 | Unused in this case. */ | |
14379 | ||
14380 | static int | |
4efb68b1 | 14381 | breakpoint_re_set_one (void *bint) |
c906108c | 14382 | { |
4a64f543 | 14383 | /* Get past catch_errs. */ |
53a5351d | 14384 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14385 | struct cleanup *cleanups; |
c906108c | 14386 | |
348d480f PA |
14387 | cleanups = prepare_re_set_context (b); |
14388 | b->ops->re_set (b); | |
14389 | do_cleanups (cleanups); | |
c906108c SS |
14390 | return 0; |
14391 | } | |
14392 | ||
69de3c6a | 14393 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14394 | void |
69de3c6a | 14395 | breakpoint_re_set (void) |
c906108c | 14396 | { |
35df4500 | 14397 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14398 | enum language save_language; |
14399 | int save_input_radix; | |
6c95b8df | 14400 | struct cleanup *old_chain; |
c5aa993b | 14401 | |
c906108c SS |
14402 | save_language = current_language->la_language; |
14403 | save_input_radix = input_radix; | |
6c95b8df PA |
14404 | old_chain = save_current_program_space (); |
14405 | ||
35df4500 | 14406 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14407 | { |
4a64f543 | 14408 | /* Format possible error msg. */ |
fe3f5fa8 | 14409 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14410 | b->number); |
14411 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14412 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14413 | do_cleanups (cleanups); |
c5aa993b | 14414 | } |
c906108c SS |
14415 | set_language (save_language); |
14416 | input_radix = save_input_radix; | |
e62c965a | 14417 | |
0756c555 | 14418 | jit_breakpoint_re_set (); |
4efc6507 | 14419 | |
6c95b8df PA |
14420 | do_cleanups (old_chain); |
14421 | ||
af02033e PP |
14422 | create_overlay_event_breakpoint (); |
14423 | create_longjmp_master_breakpoint (); | |
14424 | create_std_terminate_master_breakpoint (); | |
186c406b | 14425 | create_exception_master_breakpoint (); |
c906108c SS |
14426 | } |
14427 | \f | |
c906108c SS |
14428 | /* Reset the thread number of this breakpoint: |
14429 | ||
14430 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14431 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14432 | void |
fba45db2 | 14433 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14434 | { |
14435 | if (b->thread != -1) | |
14436 | { | |
39f77062 KB |
14437 | if (in_thread_list (inferior_ptid)) |
14438 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14439 | |
14440 | /* We're being called after following a fork. The new fork is | |
14441 | selected as current, and unless this was a vfork will have a | |
14442 | different program space from the original thread. Reset that | |
14443 | as well. */ | |
14444 | b->loc->pspace = current_program_space; | |
c906108c SS |
14445 | } |
14446 | } | |
14447 | ||
03ac34d5 MS |
14448 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14449 | If from_tty is nonzero, it prints a message to that effect, | |
14450 | which ends with a period (no newline). */ | |
14451 | ||
c906108c | 14452 | void |
fba45db2 | 14453 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14454 | { |
52f0bd74 | 14455 | struct breakpoint *b; |
c906108c SS |
14456 | |
14457 | if (count < 0) | |
14458 | count = 0; | |
14459 | ||
14460 | ALL_BREAKPOINTS (b) | |
14461 | if (b->number == bptnum) | |
c5aa993b | 14462 | { |
d77f58be SS |
14463 | if (is_tracepoint (b)) |
14464 | { | |
14465 | if (from_tty && count != 0) | |
14466 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14467 | bptnum); | |
14468 | return; | |
14469 | } | |
14470 | ||
c5aa993b | 14471 | b->ignore_count = count; |
221ea385 KS |
14472 | if (from_tty) |
14473 | { | |
14474 | if (count == 0) | |
3e43a32a MS |
14475 | printf_filtered (_("Will stop next time " |
14476 | "breakpoint %d is reached."), | |
221ea385 KS |
14477 | bptnum); |
14478 | else if (count == 1) | |
a3f17187 | 14479 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14480 | bptnum); |
14481 | else | |
3e43a32a MS |
14482 | printf_filtered (_("Will ignore next %d " |
14483 | "crossings of breakpoint %d."), | |
221ea385 KS |
14484 | count, bptnum); |
14485 | } | |
8d3788bd | 14486 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14487 | return; |
14488 | } | |
c906108c | 14489 | |
8a3fe4f8 | 14490 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14491 | } |
14492 | ||
c906108c SS |
14493 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14494 | ||
14495 | static void | |
fba45db2 | 14496 | ignore_command (char *args, int from_tty) |
c906108c SS |
14497 | { |
14498 | char *p = args; | |
52f0bd74 | 14499 | int num; |
c906108c SS |
14500 | |
14501 | if (p == 0) | |
e2e0b3e5 | 14502 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14503 | |
c906108c | 14504 | num = get_number (&p); |
5c44784c | 14505 | if (num == 0) |
8a3fe4f8 | 14506 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14507 | if (*p == 0) |
8a3fe4f8 | 14508 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14509 | |
14510 | set_ignore_count (num, | |
14511 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14512 | from_tty); | |
221ea385 KS |
14513 | if (from_tty) |
14514 | printf_filtered ("\n"); | |
c906108c SS |
14515 | } |
14516 | \f | |
14517 | /* Call FUNCTION on each of the breakpoints | |
14518 | whose numbers are given in ARGS. */ | |
14519 | ||
14520 | static void | |
95a42b64 TT |
14521 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14522 | void *), | |
14523 | void *data) | |
c906108c | 14524 | { |
52f0bd74 AC |
14525 | int num; |
14526 | struct breakpoint *b, *tmp; | |
11cf8741 | 14527 | int match; |
197f0a60 | 14528 | struct get_number_or_range_state state; |
c906108c | 14529 | |
197f0a60 | 14530 | if (args == 0) |
e2e0b3e5 | 14531 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14532 | |
197f0a60 TT |
14533 | init_number_or_range (&state, args); |
14534 | ||
14535 | while (!state.finished) | |
c906108c | 14536 | { |
197f0a60 TT |
14537 | char *p = state.string; |
14538 | ||
11cf8741 | 14539 | match = 0; |
c5aa993b | 14540 | |
197f0a60 | 14541 | num = get_number_or_range (&state); |
5c44784c | 14542 | if (num == 0) |
c5aa993b | 14543 | { |
8a3fe4f8 | 14544 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14545 | } |
14546 | else | |
14547 | { | |
14548 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14549 | if (b->number == num) | |
14550 | { | |
11cf8741 | 14551 | match = 1; |
cdac0397 | 14552 | function (b, data); |
11cf8741 | 14553 | break; |
5c44784c | 14554 | } |
11cf8741 | 14555 | if (match == 0) |
a3f17187 | 14556 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14557 | } |
c906108c SS |
14558 | } |
14559 | } | |
14560 | ||
0d381245 VP |
14561 | static struct bp_location * |
14562 | find_location_by_number (char *number) | |
14563 | { | |
14564 | char *dot = strchr (number, '.'); | |
14565 | char *p1; | |
14566 | int bp_num; | |
14567 | int loc_num; | |
14568 | struct breakpoint *b; | |
14569 | struct bp_location *loc; | |
14570 | ||
14571 | *dot = '\0'; | |
14572 | ||
14573 | p1 = number; | |
197f0a60 | 14574 | bp_num = get_number (&p1); |
0d381245 VP |
14575 | if (bp_num == 0) |
14576 | error (_("Bad breakpoint number '%s'"), number); | |
14577 | ||
14578 | ALL_BREAKPOINTS (b) | |
14579 | if (b->number == bp_num) | |
14580 | { | |
14581 | break; | |
14582 | } | |
14583 | ||
14584 | if (!b || b->number != bp_num) | |
14585 | error (_("Bad breakpoint number '%s'"), number); | |
14586 | ||
14587 | p1 = dot+1; | |
197f0a60 | 14588 | loc_num = get_number (&p1); |
0d381245 VP |
14589 | if (loc_num == 0) |
14590 | error (_("Bad breakpoint location number '%s'"), number); | |
14591 | ||
14592 | --loc_num; | |
14593 | loc = b->loc; | |
14594 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14595 | ; | |
14596 | if (!loc) | |
14597 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14598 | ||
14599 | return loc; | |
14600 | } | |
14601 | ||
14602 | ||
1900040c MS |
14603 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14604 | If from_tty is nonzero, it prints a message to that effect, | |
14605 | which ends with a period (no newline). */ | |
14606 | ||
c906108c | 14607 | void |
fba45db2 | 14608 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14609 | { |
14610 | /* Never disable a watchpoint scope breakpoint; we want to | |
14611 | hit them when we leave scope so we can delete both the | |
14612 | watchpoint and its scope breakpoint at that time. */ | |
14613 | if (bpt->type == bp_watchpoint_scope) | |
14614 | return; | |
14615 | ||
c2c6d25f | 14616 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14617 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14618 | return; |
14619 | ||
b5de0fa7 | 14620 | bpt->enable_state = bp_disabled; |
c906108c | 14621 | |
b775012e LM |
14622 | /* Mark breakpoint locations modified. */ |
14623 | mark_breakpoint_modified (bpt); | |
14624 | ||
d248b706 KY |
14625 | if (target_supports_enable_disable_tracepoint () |
14626 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14627 | { | |
14628 | struct bp_location *location; | |
14629 | ||
14630 | for (location = bpt->loc; location; location = location->next) | |
14631 | target_disable_tracepoint (location); | |
14632 | } | |
14633 | ||
b60e7edf | 14634 | update_global_location_list (0); |
c906108c | 14635 | |
8d3788bd | 14636 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14637 | } |
14638 | ||
51be5b68 PA |
14639 | /* A callback for iterate_over_related_breakpoints. */ |
14640 | ||
14641 | static void | |
14642 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14643 | { | |
14644 | disable_breakpoint (b); | |
14645 | } | |
14646 | ||
95a42b64 TT |
14647 | /* A callback for map_breakpoint_numbers that calls |
14648 | disable_breakpoint. */ | |
14649 | ||
14650 | static void | |
14651 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14652 | { | |
51be5b68 | 14653 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14654 | } |
14655 | ||
c906108c | 14656 | static void |
fba45db2 | 14657 | disable_command (char *args, int from_tty) |
c906108c | 14658 | { |
c906108c | 14659 | if (args == 0) |
46c6471b PA |
14660 | { |
14661 | struct breakpoint *bpt; | |
14662 | ||
14663 | ALL_BREAKPOINTS (bpt) | |
14664 | if (user_breakpoint_p (bpt)) | |
14665 | disable_breakpoint (bpt); | |
14666 | } | |
9eaabc75 | 14667 | else |
0d381245 | 14668 | { |
9eaabc75 MW |
14669 | char *num = extract_arg (&args); |
14670 | ||
14671 | while (num) | |
d248b706 | 14672 | { |
9eaabc75 | 14673 | if (strchr (num, '.')) |
b775012e | 14674 | { |
9eaabc75 MW |
14675 | struct bp_location *loc = find_location_by_number (num); |
14676 | ||
14677 | if (loc) | |
14678 | { | |
14679 | if (loc->enabled) | |
14680 | { | |
14681 | loc->enabled = 0; | |
14682 | mark_breakpoint_location_modified (loc); | |
14683 | } | |
14684 | if (target_supports_enable_disable_tracepoint () | |
14685 | && current_trace_status ()->running && loc->owner | |
14686 | && is_tracepoint (loc->owner)) | |
14687 | target_disable_tracepoint (loc); | |
14688 | } | |
14689 | update_global_location_list (0); | |
b775012e | 14690 | } |
9eaabc75 MW |
14691 | else |
14692 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14693 | num = extract_arg (&args); | |
d248b706 | 14694 | } |
0d381245 | 14695 | } |
c906108c SS |
14696 | } |
14697 | ||
14698 | static void | |
816338b5 SS |
14699 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14700 | int count) | |
c906108c | 14701 | { |
afe38095 | 14702 | int target_resources_ok; |
c906108c SS |
14703 | |
14704 | if (bpt->type == bp_hardware_breakpoint) | |
14705 | { | |
14706 | int i; | |
c5aa993b | 14707 | i = hw_breakpoint_used_count (); |
53a5351d | 14708 | target_resources_ok = |
d92524f1 | 14709 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14710 | i + 1, 0); |
c906108c | 14711 | if (target_resources_ok == 0) |
8a3fe4f8 | 14712 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14713 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14714 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14715 | } |
14716 | ||
cc60f2e3 | 14717 | if (is_watchpoint (bpt)) |
c906108c | 14718 | { |
d07205c2 JK |
14719 | /* Initialize it just to avoid a GCC false warning. */ |
14720 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14721 | volatile struct gdb_exception e; |
dde02812 ES |
14722 | |
14723 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14724 | { |
3a5c3e22 PA |
14725 | struct watchpoint *w = (struct watchpoint *) bpt; |
14726 | ||
1e718ff1 TJB |
14727 | orig_enable_state = bpt->enable_state; |
14728 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14729 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14730 | } |
dde02812 | 14731 | if (e.reason < 0) |
c5aa993b | 14732 | { |
1e718ff1 | 14733 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14734 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14735 | bpt->number); | |
14736 | return; | |
c5aa993b | 14737 | } |
c906108c | 14738 | } |
0101ce28 | 14739 | |
b4c291bb KH |
14740 | if (bpt->enable_state != bp_permanent) |
14741 | bpt->enable_state = bp_enabled; | |
d248b706 | 14742 | |
b775012e LM |
14743 | bpt->enable_state = bp_enabled; |
14744 | ||
14745 | /* Mark breakpoint locations modified. */ | |
14746 | mark_breakpoint_modified (bpt); | |
14747 | ||
d248b706 KY |
14748 | if (target_supports_enable_disable_tracepoint () |
14749 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14750 | { | |
14751 | struct bp_location *location; | |
14752 | ||
14753 | for (location = bpt->loc; location; location = location->next) | |
14754 | target_enable_tracepoint (location); | |
14755 | } | |
14756 | ||
b4c291bb | 14757 | bpt->disposition = disposition; |
816338b5 | 14758 | bpt->enable_count = count; |
b60e7edf | 14759 | update_global_location_list (1); |
9c97429f | 14760 | |
8d3788bd | 14761 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14762 | } |
14763 | ||
fe3f5fa8 | 14764 | |
c906108c | 14765 | void |
fba45db2 | 14766 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14767 | { |
816338b5 | 14768 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14769 | } |
14770 | ||
14771 | static void | |
14772 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14773 | { | |
14774 | enable_breakpoint (bpt); | |
c906108c SS |
14775 | } |
14776 | ||
95a42b64 TT |
14777 | /* A callback for map_breakpoint_numbers that calls |
14778 | enable_breakpoint. */ | |
14779 | ||
14780 | static void | |
14781 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14782 | { | |
51be5b68 | 14783 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14784 | } |
14785 | ||
c906108c SS |
14786 | /* The enable command enables the specified breakpoints (or all defined |
14787 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14788 | in stopping the inferior. */ |
c906108c | 14789 | |
c906108c | 14790 | static void |
fba45db2 | 14791 | enable_command (char *args, int from_tty) |
c906108c | 14792 | { |
c906108c | 14793 | if (args == 0) |
46c6471b PA |
14794 | { |
14795 | struct breakpoint *bpt; | |
14796 | ||
14797 | ALL_BREAKPOINTS (bpt) | |
14798 | if (user_breakpoint_p (bpt)) | |
14799 | enable_breakpoint (bpt); | |
14800 | } | |
9eaabc75 | 14801 | else |
0d381245 | 14802 | { |
9eaabc75 MW |
14803 | char *num = extract_arg (&args); |
14804 | ||
14805 | while (num) | |
d248b706 | 14806 | { |
9eaabc75 | 14807 | if (strchr (num, '.')) |
b775012e | 14808 | { |
9eaabc75 MW |
14809 | struct bp_location *loc = find_location_by_number (num); |
14810 | ||
14811 | if (loc) | |
14812 | { | |
14813 | if (!loc->enabled) | |
14814 | { | |
14815 | loc->enabled = 1; | |
14816 | mark_breakpoint_location_modified (loc); | |
14817 | } | |
14818 | if (target_supports_enable_disable_tracepoint () | |
14819 | && current_trace_status ()->running && loc->owner | |
14820 | && is_tracepoint (loc->owner)) | |
14821 | target_enable_tracepoint (loc); | |
14822 | } | |
14823 | update_global_location_list (1); | |
b775012e | 14824 | } |
9eaabc75 MW |
14825 | else |
14826 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14827 | num = extract_arg (&args); | |
d248b706 | 14828 | } |
0d381245 | 14829 | } |
c906108c SS |
14830 | } |
14831 | ||
816338b5 SS |
14832 | /* This struct packages up disposition data for application to multiple |
14833 | breakpoints. */ | |
14834 | ||
14835 | struct disp_data | |
14836 | { | |
14837 | enum bpdisp disp; | |
14838 | int count; | |
14839 | }; | |
14840 | ||
c906108c | 14841 | static void |
51be5b68 PA |
14842 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14843 | { | |
816338b5 | 14844 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14845 | |
816338b5 | 14846 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14847 | } |
14848 | ||
14849 | static void | |
14850 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14851 | { |
816338b5 | 14852 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14853 | |
14854 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14855 | } |
14856 | ||
c906108c | 14857 | static void |
fba45db2 | 14858 | enable_once_command (char *args, int from_tty) |
c906108c | 14859 | { |
51be5b68 | 14860 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14861 | } |
14862 | ||
816338b5 SS |
14863 | static void |
14864 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14865 | { | |
14866 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14867 | ||
14868 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14869 | } | |
14870 | ||
14871 | static void | |
14872 | enable_count_command (char *args, int from_tty) | |
14873 | { | |
14874 | int count = get_number (&args); | |
14875 | ||
14876 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14877 | } | |
14878 | ||
c906108c | 14879 | static void |
51be5b68 | 14880 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14881 | { |
816338b5 | 14882 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14883 | |
14884 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14885 | } |
14886 | ||
c906108c | 14887 | static void |
fba45db2 | 14888 | enable_delete_command (char *args, int from_tty) |
c906108c | 14889 | { |
51be5b68 | 14890 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14891 | } |
14892 | \f | |
fa8d40ab JJ |
14893 | static void |
14894 | set_breakpoint_cmd (char *args, int from_tty) | |
14895 | { | |
14896 | } | |
14897 | ||
14898 | static void | |
14899 | show_breakpoint_cmd (char *args, int from_tty) | |
14900 | { | |
14901 | } | |
14902 | ||
1f3b5d1b PP |
14903 | /* Invalidate last known value of any hardware watchpoint if |
14904 | the memory which that value represents has been written to by | |
14905 | GDB itself. */ | |
14906 | ||
14907 | static void | |
8de0566d YQ |
14908 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14909 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14910 | const bfd_byte *data) |
14911 | { | |
14912 | struct breakpoint *bp; | |
14913 | ||
14914 | ALL_BREAKPOINTS (bp) | |
14915 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14916 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14917 | { |
3a5c3e22 | 14918 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14919 | |
3a5c3e22 PA |
14920 | if (wp->val_valid && wp->val) |
14921 | { | |
14922 | struct bp_location *loc; | |
14923 | ||
14924 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14925 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14926 | && loc->address + loc->length > addr | |
14927 | && addr + len > loc->address) | |
14928 | { | |
14929 | value_free (wp->val); | |
14930 | wp->val = NULL; | |
14931 | wp->val_valid = 0; | |
14932 | } | |
14933 | } | |
1f3b5d1b PP |
14934 | } |
14935 | } | |
14936 | ||
8181d85f DJ |
14937 | /* Create and insert a raw software breakpoint at PC. Return an |
14938 | identifier, which should be used to remove the breakpoint later. | |
14939 | In general, places which call this should be using something on the | |
14940 | breakpoint chain instead; this function should be eliminated | |
14941 | someday. */ | |
14942 | ||
14943 | void * | |
6c95b8df PA |
14944 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
14945 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
14946 | { |
14947 | struct bp_target_info *bp_tgt; | |
14948 | ||
6c95b8df | 14949 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 14950 | |
6c95b8df | 14951 | bp_tgt->placed_address_space = aspace; |
8181d85f | 14952 | bp_tgt->placed_address = pc; |
6c95b8df | 14953 | |
a6d9a66e | 14954 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
14955 | { |
14956 | /* Could not insert the breakpoint. */ | |
14957 | xfree (bp_tgt); | |
14958 | return NULL; | |
14959 | } | |
14960 | ||
14961 | return bp_tgt; | |
14962 | } | |
14963 | ||
4a64f543 MS |
14964 | /* Remove a breakpoint BP inserted by |
14965 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
14966 | |
14967 | int | |
a6d9a66e | 14968 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
14969 | { |
14970 | struct bp_target_info *bp_tgt = bp; | |
14971 | int ret; | |
14972 | ||
a6d9a66e | 14973 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
14974 | xfree (bp_tgt); |
14975 | ||
14976 | return ret; | |
14977 | } | |
14978 | ||
4a64f543 MS |
14979 | /* One (or perhaps two) breakpoints used for software single |
14980 | stepping. */ | |
8181d85f DJ |
14981 | |
14982 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 14983 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
14984 | |
14985 | /* Create and insert a breakpoint for software single step. */ | |
14986 | ||
14987 | void | |
6c95b8df | 14988 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14989 | struct address_space *aspace, |
14990 | CORE_ADDR next_pc) | |
8181d85f DJ |
14991 | { |
14992 | void **bpt_p; | |
14993 | ||
14994 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
14995 | { |
14996 | bpt_p = &single_step_breakpoints[0]; | |
14997 | single_step_gdbarch[0] = gdbarch; | |
14998 | } | |
8181d85f DJ |
14999 | else |
15000 | { | |
15001 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15002 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15003 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15004 | } |
15005 | ||
4a64f543 MS |
15006 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15007 | be to only create the breakpoints once, and actually put them on | |
15008 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15009 | We could adjust the addresses each time they were needed. Doing | |
15010 | this requires corresponding changes elsewhere where single step | |
15011 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15012 | |
6c95b8df | 15013 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15014 | if (*bpt_p == NULL) |
5af949e3 UW |
15015 | error (_("Could not insert single-step breakpoint at %s"), |
15016 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15017 | } |
15018 | ||
f02253f1 HZ |
15019 | /* Check if the breakpoints used for software single stepping |
15020 | were inserted or not. */ | |
15021 | ||
15022 | int | |
15023 | single_step_breakpoints_inserted (void) | |
15024 | { | |
15025 | return (single_step_breakpoints[0] != NULL | |
15026 | || single_step_breakpoints[1] != NULL); | |
15027 | } | |
15028 | ||
8181d85f DJ |
15029 | /* Remove and delete any breakpoints used for software single step. */ |
15030 | ||
15031 | void | |
15032 | remove_single_step_breakpoints (void) | |
15033 | { | |
15034 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15035 | ||
15036 | /* See insert_single_step_breakpoint for more about this deprecated | |
15037 | call. */ | |
a6d9a66e UW |
15038 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15039 | single_step_breakpoints[0]); | |
15040 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15041 | single_step_breakpoints[0] = NULL; |
15042 | ||
15043 | if (single_step_breakpoints[1] != NULL) | |
15044 | { | |
a6d9a66e UW |
15045 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15046 | single_step_breakpoints[1]); | |
15047 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15048 | single_step_breakpoints[1] = NULL; |
15049 | } | |
15050 | } | |
15051 | ||
d03285ec UW |
15052 | /* Delete software single step breakpoints without removing them from |
15053 | the inferior. This is intended to be used if the inferior's address | |
15054 | space where they were inserted is already gone, e.g. after exit or | |
15055 | exec. */ | |
15056 | ||
15057 | void | |
15058 | cancel_single_step_breakpoints (void) | |
15059 | { | |
15060 | int i; | |
15061 | ||
15062 | for (i = 0; i < 2; i++) | |
15063 | if (single_step_breakpoints[i]) | |
15064 | { | |
15065 | xfree (single_step_breakpoints[i]); | |
15066 | single_step_breakpoints[i] = NULL; | |
15067 | single_step_gdbarch[i] = NULL; | |
15068 | } | |
15069 | } | |
15070 | ||
15071 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15072 | removing them. */ | |
15073 | ||
15074 | static void | |
15075 | detach_single_step_breakpoints (void) | |
15076 | { | |
15077 | int i; | |
15078 | ||
15079 | for (i = 0; i < 2; i++) | |
15080 | if (single_step_breakpoints[i]) | |
15081 | target_remove_breakpoint (single_step_gdbarch[i], | |
15082 | single_step_breakpoints[i]); | |
15083 | } | |
15084 | ||
4a64f543 MS |
15085 | /* Check whether a software single-step breakpoint is inserted at |
15086 | PC. */ | |
1aafd4da UW |
15087 | |
15088 | static int | |
cc59ec59 MS |
15089 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15090 | CORE_ADDR pc) | |
1aafd4da UW |
15091 | { |
15092 | int i; | |
15093 | ||
15094 | for (i = 0; i < 2; i++) | |
15095 | { | |
15096 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15097 | if (bp_tgt |
15098 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15099 | bp_tgt->placed_address, | |
15100 | aspace, pc)) | |
1aafd4da UW |
15101 | return 1; |
15102 | } | |
15103 | ||
15104 | return 0; | |
15105 | } | |
15106 | ||
a96d9b2e SDJ |
15107 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15108 | non-zero otherwise. */ | |
15109 | static int | |
15110 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15111 | { | |
15112 | if (syscall_catchpoint_p (bp) | |
15113 | && bp->enable_state != bp_disabled | |
15114 | && bp->enable_state != bp_call_disabled) | |
15115 | return 1; | |
15116 | else | |
15117 | return 0; | |
15118 | } | |
15119 | ||
15120 | int | |
15121 | catch_syscall_enabled (void) | |
15122 | { | |
fa3064dd YQ |
15123 | struct catch_syscall_inferior_data *inf_data |
15124 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15125 | |
fa3064dd | 15126 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15127 | } |
15128 | ||
15129 | int | |
15130 | catching_syscall_number (int syscall_number) | |
15131 | { | |
15132 | struct breakpoint *bp; | |
15133 | ||
15134 | ALL_BREAKPOINTS (bp) | |
15135 | if (is_syscall_catchpoint_enabled (bp)) | |
15136 | { | |
be5c67c1 PA |
15137 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15138 | ||
15139 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15140 | { |
15141 | int i, iter; | |
15142 | for (i = 0; | |
be5c67c1 | 15143 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15144 | i++) |
15145 | if (syscall_number == iter) | |
15146 | return 1; | |
15147 | } | |
15148 | else | |
15149 | return 1; | |
15150 | } | |
15151 | ||
15152 | return 0; | |
15153 | } | |
15154 | ||
15155 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15156 | static VEC (char_ptr) * |
a96d9b2e | 15157 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15158 | const char *text, const char *word) |
a96d9b2e SDJ |
15159 | { |
15160 | const char **list = get_syscall_names (); | |
49c4e619 | 15161 | VEC (char_ptr) *retlist |
b45627a0 | 15162 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15163 | |
c38eea1a MS |
15164 | xfree (list); |
15165 | return retlist; | |
a96d9b2e SDJ |
15166 | } |
15167 | ||
1042e4c0 SS |
15168 | /* Tracepoint-specific operations. */ |
15169 | ||
15170 | /* Set tracepoint count to NUM. */ | |
15171 | static void | |
15172 | set_tracepoint_count (int num) | |
15173 | { | |
15174 | tracepoint_count = num; | |
4fa62494 | 15175 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15176 | } |
15177 | ||
70221824 | 15178 | static void |
1042e4c0 SS |
15179 | trace_command (char *arg, int from_tty) |
15180 | { | |
55aa24fb SDJ |
15181 | struct breakpoint_ops *ops; |
15182 | const char *arg_cp = arg; | |
15183 | ||
15184 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15185 | ops = &tracepoint_probe_breakpoint_ops; | |
15186 | else | |
15187 | ops = &tracepoint_breakpoint_ops; | |
15188 | ||
558a9d82 YQ |
15189 | create_breakpoint (get_current_arch (), |
15190 | arg, | |
15191 | NULL, 0, NULL, 1 /* parse arg */, | |
15192 | 0 /* tempflag */, | |
15193 | bp_tracepoint /* type_wanted */, | |
15194 | 0 /* Ignore count */, | |
15195 | pending_break_support, | |
15196 | ops, | |
15197 | from_tty, | |
15198 | 1 /* enabled */, | |
15199 | 0 /* internal */, 0); | |
1042e4c0 SS |
15200 | } |
15201 | ||
70221824 | 15202 | static void |
7a697b8d SS |
15203 | ftrace_command (char *arg, int from_tty) |
15204 | { | |
558a9d82 YQ |
15205 | create_breakpoint (get_current_arch (), |
15206 | arg, | |
15207 | NULL, 0, NULL, 1 /* parse arg */, | |
15208 | 0 /* tempflag */, | |
15209 | bp_fast_tracepoint /* type_wanted */, | |
15210 | 0 /* Ignore count */, | |
15211 | pending_break_support, | |
15212 | &tracepoint_breakpoint_ops, | |
15213 | from_tty, | |
15214 | 1 /* enabled */, | |
15215 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15216 | } |
15217 | ||
15218 | /* strace command implementation. Creates a static tracepoint. */ | |
15219 | ||
70221824 | 15220 | static void |
0fb4aa4b PA |
15221 | strace_command (char *arg, int from_tty) |
15222 | { | |
983af33b SDJ |
15223 | struct breakpoint_ops *ops; |
15224 | ||
15225 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15226 | or with a normal static tracepoint. */ | |
15227 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15228 | ops = &strace_marker_breakpoint_ops; | |
15229 | else | |
15230 | ops = &tracepoint_breakpoint_ops; | |
15231 | ||
558a9d82 YQ |
15232 | create_breakpoint (get_current_arch (), |
15233 | arg, | |
15234 | NULL, 0, NULL, 1 /* parse arg */, | |
15235 | 0 /* tempflag */, | |
15236 | bp_static_tracepoint /* type_wanted */, | |
15237 | 0 /* Ignore count */, | |
15238 | pending_break_support, | |
15239 | ops, | |
15240 | from_tty, | |
15241 | 1 /* enabled */, | |
15242 | 0 /* internal */, 0); | |
7a697b8d SS |
15243 | } |
15244 | ||
409873ef SS |
15245 | /* Set up a fake reader function that gets command lines from a linked |
15246 | list that was acquired during tracepoint uploading. */ | |
15247 | ||
15248 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15249 | static int next_cmd; |
409873ef SS |
15250 | |
15251 | static char * | |
15252 | read_uploaded_action (void) | |
15253 | { | |
15254 | char *rslt; | |
15255 | ||
3149d8c1 | 15256 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15257 | |
3149d8c1 | 15258 | next_cmd++; |
409873ef SS |
15259 | |
15260 | return rslt; | |
15261 | } | |
15262 | ||
00bf0b85 SS |
15263 | /* Given information about a tracepoint as recorded on a target (which |
15264 | can be either a live system or a trace file), attempt to create an | |
15265 | equivalent GDB tracepoint. This is not a reliable process, since | |
15266 | the target does not necessarily have all the information used when | |
15267 | the tracepoint was originally defined. */ | |
15268 | ||
d9b3f62e | 15269 | struct tracepoint * |
00bf0b85 | 15270 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15271 | { |
409873ef | 15272 | char *addr_str, small_buf[100]; |
d9b3f62e | 15273 | struct tracepoint *tp; |
fd9b8c24 | 15274 | |
409873ef SS |
15275 | if (utp->at_string) |
15276 | addr_str = utp->at_string; | |
15277 | else | |
15278 | { | |
15279 | /* In the absence of a source location, fall back to raw | |
15280 | address. Since there is no way to confirm that the address | |
15281 | means the same thing as when the trace was started, warn the | |
15282 | user. */ | |
3e43a32a MS |
15283 | warning (_("Uploaded tracepoint %d has no " |
15284 | "source location, using raw address"), | |
409873ef | 15285 | utp->number); |
8c042590 | 15286 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15287 | addr_str = small_buf; |
15288 | } | |
15289 | ||
15290 | /* There's not much we can do with a sequence of bytecodes. */ | |
15291 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15292 | warning (_("Uploaded tracepoint %d condition " |
15293 | "has no source form, ignoring it"), | |
409873ef | 15294 | utp->number); |
d5551862 | 15295 | |
8cdf0e15 | 15296 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15297 | addr_str, |
e7e0cddf SS |
15298 | utp->cond_string, -1, NULL, |
15299 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15300 | 0 /* tempflag */, |
0fb4aa4b | 15301 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15302 | 0 /* Ignore count */, |
15303 | pending_break_support, | |
348d480f | 15304 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15305 | 0 /* from_tty */, |
84f4c1fe | 15306 | utp->enabled /* enabled */, |
44f238bb PA |
15307 | 0 /* internal */, |
15308 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15309 | return NULL; |
15310 | ||
409873ef | 15311 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15312 | tp = get_tracepoint (tracepoint_count); |
15313 | gdb_assert (tp != NULL); | |
d5551862 | 15314 | |
00bf0b85 SS |
15315 | if (utp->pass > 0) |
15316 | { | |
8c042590 PM |
15317 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15318 | tp->base.number); | |
00bf0b85 | 15319 | |
409873ef | 15320 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15321 | } |
15322 | ||
409873ef SS |
15323 | /* If we have uploaded versions of the original commands, set up a |
15324 | special-purpose "reader" function and call the usual command line | |
15325 | reader, then pass the result to the breakpoint command-setting | |
15326 | function. */ | |
3149d8c1 | 15327 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15328 | { |
409873ef | 15329 | struct command_line *cmd_list; |
00bf0b85 | 15330 | |
409873ef | 15331 | this_utp = utp; |
3149d8c1 | 15332 | next_cmd = 0; |
d5551862 | 15333 | |
409873ef SS |
15334 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15335 | ||
d9b3f62e | 15336 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15337 | } |
3149d8c1 SS |
15338 | else if (!VEC_empty (char_ptr, utp->actions) |
15339 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15340 | warning (_("Uploaded tracepoint %d actions " |
15341 | "have no source form, ignoring them"), | |
409873ef | 15342 | utp->number); |
00bf0b85 | 15343 | |
f196051f SS |
15344 | /* Copy any status information that might be available. */ |
15345 | tp->base.hit_count = utp->hit_count; | |
15346 | tp->traceframe_usage = utp->traceframe_usage; | |
15347 | ||
00bf0b85 | 15348 | return tp; |
d9b3f62e | 15349 | } |
00bf0b85 | 15350 | |
1042e4c0 SS |
15351 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15352 | omitted. */ | |
15353 | ||
15354 | static void | |
e5a67952 | 15355 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15356 | { |
79a45e25 | 15357 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15358 | int num_printed; |
1042e4c0 | 15359 | |
e5a67952 | 15360 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15361 | |
15362 | if (num_printed == 0) | |
1042e4c0 | 15363 | { |
e5a67952 | 15364 | if (args == NULL || *args == '\0') |
d77f58be SS |
15365 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15366 | else | |
e5a67952 | 15367 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15368 | } |
ad443146 SS |
15369 | |
15370 | default_collect_info (); | |
1042e4c0 SS |
15371 | } |
15372 | ||
4a64f543 | 15373 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15374 | Not supported by all targets. */ |
15375 | static void | |
15376 | enable_trace_command (char *args, int from_tty) | |
15377 | { | |
15378 | enable_command (args, from_tty); | |
15379 | } | |
15380 | ||
4a64f543 | 15381 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15382 | Not supported by all targets. */ |
15383 | static void | |
15384 | disable_trace_command (char *args, int from_tty) | |
15385 | { | |
15386 | disable_command (args, from_tty); | |
15387 | } | |
15388 | ||
4a64f543 | 15389 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15390 | static void |
15391 | delete_trace_command (char *arg, int from_tty) | |
15392 | { | |
35df4500 | 15393 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15394 | |
15395 | dont_repeat (); | |
15396 | ||
15397 | if (arg == 0) | |
15398 | { | |
15399 | int breaks_to_delete = 0; | |
15400 | ||
15401 | /* Delete all breakpoints if no argument. | |
15402 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15403 | have to be deleted with an explicit breakpoint number |
15404 | argument. */ | |
1042e4c0 | 15405 | ALL_TRACEPOINTS (b) |
46c6471b | 15406 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15407 | { |
15408 | breaks_to_delete = 1; | |
15409 | break; | |
15410 | } | |
1042e4c0 SS |
15411 | |
15412 | /* Ask user only if there are some breakpoints to delete. */ | |
15413 | if (!from_tty | |
15414 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15415 | { | |
35df4500 | 15416 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15417 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15418 | delete_breakpoint (b); |
1042e4c0 SS |
15419 | } |
15420 | } | |
15421 | else | |
51be5b68 | 15422 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15423 | } |
15424 | ||
197f0a60 TT |
15425 | /* Helper function for trace_pass_command. */ |
15426 | ||
15427 | static void | |
d9b3f62e | 15428 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15429 | { |
d9b3f62e | 15430 | tp->pass_count = count; |
6f6484cd | 15431 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15432 | if (from_tty) |
15433 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15434 | tp->base.number, count); |
197f0a60 TT |
15435 | } |
15436 | ||
1042e4c0 SS |
15437 | /* Set passcount for tracepoint. |
15438 | ||
15439 | First command argument is passcount, second is tracepoint number. | |
15440 | If tracepoint number omitted, apply to most recently defined. | |
15441 | Also accepts special argument "all". */ | |
15442 | ||
15443 | static void | |
15444 | trace_pass_command (char *args, int from_tty) | |
15445 | { | |
d9b3f62e | 15446 | struct tracepoint *t1; |
1042e4c0 | 15447 | unsigned int count; |
1042e4c0 SS |
15448 | |
15449 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15450 | error (_("passcount command requires an " |
15451 | "argument (count + optional TP num)")); | |
1042e4c0 | 15452 | |
4a64f543 | 15453 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15454 | |
529480d0 | 15455 | args = skip_spaces (args); |
1042e4c0 SS |
15456 | if (*args && strncasecmp (args, "all", 3) == 0) |
15457 | { | |
d9b3f62e PA |
15458 | struct breakpoint *b; |
15459 | ||
1042e4c0 | 15460 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15461 | if (*args) |
15462 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15463 | |
d9b3f62e | 15464 | ALL_TRACEPOINTS (b) |
197f0a60 | 15465 | { |
d9b3f62e | 15466 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15467 | trace_pass_set_count (t1, count, from_tty); |
15468 | } | |
15469 | } | |
15470 | else if (*args == '\0') | |
1042e4c0 | 15471 | { |
197f0a60 | 15472 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 15473 | if (t1) |
197f0a60 TT |
15474 | trace_pass_set_count (t1, count, from_tty); |
15475 | } | |
15476 | else | |
15477 | { | |
15478 | struct get_number_or_range_state state; | |
15479 | ||
15480 | init_number_or_range (&state, args); | |
15481 | while (!state.finished) | |
1042e4c0 | 15482 | { |
197f0a60 TT |
15483 | t1 = get_tracepoint_by_number (&args, &state, 1); |
15484 | if (t1) | |
15485 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15486 | } |
15487 | } | |
1042e4c0 SS |
15488 | } |
15489 | ||
d9b3f62e | 15490 | struct tracepoint * |
1042e4c0 SS |
15491 | get_tracepoint (int num) |
15492 | { | |
15493 | struct breakpoint *t; | |
15494 | ||
15495 | ALL_TRACEPOINTS (t) | |
15496 | if (t->number == num) | |
d9b3f62e | 15497 | return (struct tracepoint *) t; |
1042e4c0 SS |
15498 | |
15499 | return NULL; | |
15500 | } | |
15501 | ||
d5551862 SS |
15502 | /* Find the tracepoint with the given target-side number (which may be |
15503 | different from the tracepoint number after disconnecting and | |
15504 | reconnecting). */ | |
15505 | ||
d9b3f62e | 15506 | struct tracepoint * |
d5551862 SS |
15507 | get_tracepoint_by_number_on_target (int num) |
15508 | { | |
d9b3f62e | 15509 | struct breakpoint *b; |
d5551862 | 15510 | |
d9b3f62e PA |
15511 | ALL_TRACEPOINTS (b) |
15512 | { | |
15513 | struct tracepoint *t = (struct tracepoint *) b; | |
15514 | ||
15515 | if (t->number_on_target == num) | |
15516 | return t; | |
15517 | } | |
d5551862 SS |
15518 | |
15519 | return NULL; | |
15520 | } | |
15521 | ||
1042e4c0 | 15522 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
15523 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
15524 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 15525 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 15526 | struct tracepoint * |
197f0a60 TT |
15527 | get_tracepoint_by_number (char **arg, |
15528 | struct get_number_or_range_state *state, | |
15529 | int optional_p) | |
1042e4c0 | 15530 | { |
1042e4c0 SS |
15531 | struct breakpoint *t; |
15532 | int tpnum; | |
15533 | char *instring = arg == NULL ? NULL : *arg; | |
15534 | ||
197f0a60 TT |
15535 | if (state) |
15536 | { | |
15537 | gdb_assert (!state->finished); | |
15538 | tpnum = get_number_or_range (state); | |
15539 | } | |
15540 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
15541 | { |
15542 | if (optional_p) | |
15543 | tpnum = tracepoint_count; | |
15544 | else | |
15545 | error_no_arg (_("tracepoint number")); | |
15546 | } | |
15547 | else | |
197f0a60 | 15548 | tpnum = get_number (arg); |
1042e4c0 SS |
15549 | |
15550 | if (tpnum <= 0) | |
15551 | { | |
15552 | if (instring && *instring) | |
15553 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15554 | instring); | |
15555 | else | |
3e43a32a MS |
15556 | printf_filtered (_("Tracepoint argument missing " |
15557 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
15558 | return NULL; |
15559 | } | |
15560 | ||
15561 | ALL_TRACEPOINTS (t) | |
15562 | if (t->number == tpnum) | |
15563 | { | |
d9b3f62e | 15564 | return (struct tracepoint *) t; |
1042e4c0 SS |
15565 | } |
15566 | ||
1042e4c0 SS |
15567 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15568 | return NULL; | |
15569 | } | |
15570 | ||
d9b3f62e PA |
15571 | void |
15572 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15573 | { | |
15574 | if (b->thread != -1) | |
15575 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15576 | ||
15577 | if (b->task != 0) | |
15578 | fprintf_unfiltered (fp, " task %d", b->task); | |
15579 | ||
15580 | fprintf_unfiltered (fp, "\n"); | |
15581 | } | |
15582 | ||
6149aea9 PA |
15583 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15584 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15585 | on each breakpoint and only include the ones for which it returns | |
15586 | non-zero. */ | |
15587 | ||
1042e4c0 | 15588 | static void |
6149aea9 PA |
15589 | save_breakpoints (char *filename, int from_tty, |
15590 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15591 | { |
15592 | struct breakpoint *tp; | |
6149aea9 | 15593 | int any = 0; |
1042e4c0 | 15594 | struct cleanup *cleanup; |
a7bdde9e | 15595 | struct ui_file *fp; |
6149aea9 | 15596 | int extra_trace_bits = 0; |
1042e4c0 | 15597 | |
6149aea9 PA |
15598 | if (filename == 0 || *filename == 0) |
15599 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15600 | |
15601 | /* See if we have anything to save. */ | |
6149aea9 | 15602 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15603 | { |
6149aea9 | 15604 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15605 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15606 | continue; |
15607 | ||
15608 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15609 | if (filter && !filter (tp)) | |
15610 | continue; | |
15611 | ||
15612 | any = 1; | |
15613 | ||
15614 | if (is_tracepoint (tp)) | |
15615 | { | |
15616 | extra_trace_bits = 1; | |
15617 | ||
15618 | /* We can stop searching. */ | |
15619 | break; | |
15620 | } | |
1042e4c0 | 15621 | } |
6149aea9 PA |
15622 | |
15623 | if (!any) | |
1042e4c0 | 15624 | { |
6149aea9 | 15625 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15626 | return; |
15627 | } | |
15628 | ||
c718be47 PA |
15629 | filename = tilde_expand (filename); |
15630 | cleanup = make_cleanup (xfree, filename); | |
15631 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15632 | if (!fp) |
6149aea9 PA |
15633 | error (_("Unable to open file '%s' for saving (%s)"), |
15634 | filename, safe_strerror (errno)); | |
a7bdde9e | 15635 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15636 | |
6149aea9 PA |
15637 | if (extra_trace_bits) |
15638 | save_trace_state_variables (fp); | |
8bf6485c | 15639 | |
6149aea9 | 15640 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15641 | { |
6149aea9 | 15642 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15643 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15644 | continue; |
8bf6485c | 15645 | |
6149aea9 PA |
15646 | /* If we have a filter, only save the breakpoints it accepts. */ |
15647 | if (filter && !filter (tp)) | |
15648 | continue; | |
15649 | ||
348d480f | 15650 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15651 | |
6149aea9 PA |
15652 | /* Note, we can't rely on tp->number for anything, as we can't |
15653 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15654 | instead. */ | |
15655 | ||
15656 | if (tp->cond_string) | |
15657 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15658 | ||
15659 | if (tp->ignore_count) | |
15660 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15661 | ||
2d9442cc | 15662 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15663 | { |
a7bdde9e VP |
15664 | volatile struct gdb_exception ex; |
15665 | ||
6149aea9 | 15666 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15667 | |
79a45e25 | 15668 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15669 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15670 | { |
79a45e25 | 15671 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15672 | } |
79a45e25 | 15673 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15674 | |
a7bdde9e VP |
15675 | if (ex.reason < 0) |
15676 | throw_exception (ex); | |
1042e4c0 | 15677 | |
a7bdde9e | 15678 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15679 | } |
6149aea9 PA |
15680 | |
15681 | if (tp->enable_state == bp_disabled) | |
15682 | fprintf_unfiltered (fp, "disable\n"); | |
15683 | ||
15684 | /* If this is a multi-location breakpoint, check if the locations | |
15685 | should be individually disabled. Watchpoint locations are | |
15686 | special, and not user visible. */ | |
15687 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15688 | { | |
15689 | struct bp_location *loc; | |
15690 | int n = 1; | |
15691 | ||
15692 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15693 | if (!loc->enabled) | |
15694 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15695 | } | |
1042e4c0 | 15696 | } |
8bf6485c | 15697 | |
6149aea9 | 15698 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15699 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15700 | ||
1042e4c0 | 15701 | if (from_tty) |
6149aea9 | 15702 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15703 | do_cleanups (cleanup); |
6149aea9 PA |
15704 | } |
15705 | ||
15706 | /* The `save breakpoints' command. */ | |
15707 | ||
15708 | static void | |
15709 | save_breakpoints_command (char *args, int from_tty) | |
15710 | { | |
15711 | save_breakpoints (args, from_tty, NULL); | |
15712 | } | |
15713 | ||
15714 | /* The `save tracepoints' command. */ | |
15715 | ||
15716 | static void | |
15717 | save_tracepoints_command (char *args, int from_tty) | |
15718 | { | |
15719 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15720 | } |
15721 | ||
15722 | /* Create a vector of all tracepoints. */ | |
15723 | ||
15724 | VEC(breakpoint_p) * | |
eeae04df | 15725 | all_tracepoints (void) |
1042e4c0 SS |
15726 | { |
15727 | VEC(breakpoint_p) *tp_vec = 0; | |
15728 | struct breakpoint *tp; | |
15729 | ||
15730 | ALL_TRACEPOINTS (tp) | |
15731 | { | |
15732 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15733 | } | |
15734 | ||
15735 | return tp_vec; | |
15736 | } | |
15737 | ||
c906108c | 15738 | \f |
4a64f543 MS |
15739 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15740 | commands. It is defined as a macro to prevent duplication. | |
15741 | COMMAND should be a string constant containing the name of the | |
15742 | command. */ | |
31e2b00f | 15743 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15744 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15745 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15746 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15747 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15748 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15749 | If a line number is specified, break at start of code for that line.\n\ | |
15750 | If a function is specified, break at start of code for that function.\n\ | |
15751 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15752 | With no LOCATION, uses current execution address of the selected\n\ |
15753 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15754 | \n\ |
15755 | THREADNUM is the number from \"info threads\".\n\ | |
15756 | CONDITION is a boolean expression.\n\ | |
15757 | \n\ | |
d41c0fc8 PA |
15758 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15759 | conditions are different.\n\ | |
31e2b00f AS |
15760 | \n\ |
15761 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15762 | ||
44feb3ce TT |
15763 | /* List of subcommands for "catch". */ |
15764 | static struct cmd_list_element *catch_cmdlist; | |
15765 | ||
15766 | /* List of subcommands for "tcatch". */ | |
15767 | static struct cmd_list_element *tcatch_cmdlist; | |
15768 | ||
9ac4176b | 15769 | void |
44feb3ce TT |
15770 | add_catch_command (char *name, char *docstring, |
15771 | void (*sfunc) (char *args, int from_tty, | |
15772 | struct cmd_list_element *command), | |
625e8578 | 15773 | completer_ftype *completer, |
44feb3ce TT |
15774 | void *user_data_catch, |
15775 | void *user_data_tcatch) | |
15776 | { | |
15777 | struct cmd_list_element *command; | |
15778 | ||
15779 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15780 | &catch_cmdlist); | |
15781 | set_cmd_sfunc (command, sfunc); | |
15782 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15783 | set_cmd_completer (command, completer); |
44feb3ce TT |
15784 | |
15785 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15786 | &tcatch_cmdlist); | |
15787 | set_cmd_sfunc (command, sfunc); | |
15788 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15789 | set_cmd_completer (command, completer); |
44feb3ce TT |
15790 | } |
15791 | ||
6c95b8df | 15792 | static void |
a79b8f6e | 15793 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15794 | { |
fa3064dd YQ |
15795 | struct catch_syscall_inferior_data *inf_data |
15796 | = get_catch_syscall_inferior_data (inf); | |
15797 | ||
15798 | inf_data->total_syscalls_count = 0; | |
15799 | inf_data->any_syscall_count = 0; | |
15800 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15801 | } |
15802 | ||
6149aea9 PA |
15803 | static void |
15804 | save_command (char *arg, int from_tty) | |
15805 | { | |
3e43a32a MS |
15806 | printf_unfiltered (_("\"save\" must be followed by " |
15807 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15808 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15809 | } | |
15810 | ||
84f4c1fe PM |
15811 | struct breakpoint * |
15812 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15813 | void *data) | |
15814 | { | |
35df4500 | 15815 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15816 | |
35df4500 | 15817 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15818 | { |
15819 | if ((*callback) (b, data)) | |
15820 | return b; | |
15821 | } | |
15822 | ||
15823 | return NULL; | |
15824 | } | |
15825 | ||
0574c78f GB |
15826 | /* Zero if any of the breakpoint's locations could be a location where |
15827 | functions have been inlined, nonzero otherwise. */ | |
15828 | ||
15829 | static int | |
15830 | is_non_inline_function (struct breakpoint *b) | |
15831 | { | |
15832 | /* The shared library event breakpoint is set on the address of a | |
15833 | non-inline function. */ | |
15834 | if (b->type == bp_shlib_event) | |
15835 | return 1; | |
15836 | ||
15837 | return 0; | |
15838 | } | |
15839 | ||
15840 | /* Nonzero if the specified PC cannot be a location where functions | |
15841 | have been inlined. */ | |
15842 | ||
15843 | int | |
09ac7c10 TT |
15844 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15845 | const struct target_waitstatus *ws) | |
0574c78f GB |
15846 | { |
15847 | struct breakpoint *b; | |
15848 | struct bp_location *bl; | |
15849 | ||
15850 | ALL_BREAKPOINTS (b) | |
15851 | { | |
15852 | if (!is_non_inline_function (b)) | |
15853 | continue; | |
15854 | ||
15855 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15856 | { | |
15857 | if (!bl->shlib_disabled | |
09ac7c10 | 15858 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15859 | return 1; |
15860 | } | |
15861 | } | |
15862 | ||
15863 | return 0; | |
15864 | } | |
15865 | ||
2f202fde JK |
15866 | /* Remove any references to OBJFILE which is going to be freed. */ |
15867 | ||
15868 | void | |
15869 | breakpoint_free_objfile (struct objfile *objfile) | |
15870 | { | |
15871 | struct bp_location **locp, *loc; | |
15872 | ||
15873 | ALL_BP_LOCATIONS (loc, locp) | |
15874 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15875 | loc->symtab = NULL; | |
15876 | } | |
15877 | ||
2060206e PA |
15878 | void |
15879 | initialize_breakpoint_ops (void) | |
15880 | { | |
15881 | static int initialized = 0; | |
15882 | ||
15883 | struct breakpoint_ops *ops; | |
15884 | ||
15885 | if (initialized) | |
15886 | return; | |
15887 | initialized = 1; | |
15888 | ||
15889 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15890 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15891 | internal and momentary breakpoints, etc.). */ | |
15892 | ops = &bkpt_base_breakpoint_ops; | |
15893 | *ops = base_breakpoint_ops; | |
15894 | ops->re_set = bkpt_re_set; | |
15895 | ops->insert_location = bkpt_insert_location; | |
15896 | ops->remove_location = bkpt_remove_location; | |
15897 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15898 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15899 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15900 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15901 | |
15902 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15903 | ops = &bkpt_breakpoint_ops; | |
15904 | *ops = bkpt_base_breakpoint_ops; | |
15905 | ops->re_set = bkpt_re_set; | |
15906 | ops->resources_needed = bkpt_resources_needed; | |
15907 | ops->print_it = bkpt_print_it; | |
15908 | ops->print_mention = bkpt_print_mention; | |
15909 | ops->print_recreate = bkpt_print_recreate; | |
15910 | ||
15911 | /* Ranged breakpoints. */ | |
15912 | ops = &ranged_breakpoint_ops; | |
15913 | *ops = bkpt_breakpoint_ops; | |
15914 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15915 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15916 | ops->print_it = print_it_ranged_breakpoint; | |
15917 | ops->print_one = print_one_ranged_breakpoint; | |
15918 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15919 | ops->print_mention = print_mention_ranged_breakpoint; | |
15920 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15921 | ||
15922 | /* Internal breakpoints. */ | |
15923 | ops = &internal_breakpoint_ops; | |
15924 | *ops = bkpt_base_breakpoint_ops; | |
15925 | ops->re_set = internal_bkpt_re_set; | |
15926 | ops->check_status = internal_bkpt_check_status; | |
15927 | ops->print_it = internal_bkpt_print_it; | |
15928 | ops->print_mention = internal_bkpt_print_mention; | |
15929 | ||
15930 | /* Momentary breakpoints. */ | |
15931 | ops = &momentary_breakpoint_ops; | |
15932 | *ops = bkpt_base_breakpoint_ops; | |
15933 | ops->re_set = momentary_bkpt_re_set; | |
15934 | ops->check_status = momentary_bkpt_check_status; | |
15935 | ops->print_it = momentary_bkpt_print_it; | |
15936 | ops->print_mention = momentary_bkpt_print_mention; | |
15937 | ||
e2e4d78b JK |
15938 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15939 | ops = &longjmp_breakpoint_ops; | |
15940 | *ops = momentary_breakpoint_ops; | |
15941 | ops->dtor = longjmp_bkpt_dtor; | |
15942 | ||
55aa24fb SDJ |
15943 | /* Probe breakpoints. */ |
15944 | ops = &bkpt_probe_breakpoint_ops; | |
15945 | *ops = bkpt_breakpoint_ops; | |
15946 | ops->insert_location = bkpt_probe_insert_location; | |
15947 | ops->remove_location = bkpt_probe_remove_location; | |
15948 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
15949 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
15950 | ||
2060206e PA |
15951 | /* Watchpoints. */ |
15952 | ops = &watchpoint_breakpoint_ops; | |
15953 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15954 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15955 | ops->re_set = re_set_watchpoint; |
15956 | ops->insert_location = insert_watchpoint; | |
15957 | ops->remove_location = remove_watchpoint; | |
15958 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15959 | ops->check_status = check_status_watchpoint; | |
15960 | ops->resources_needed = resources_needed_watchpoint; | |
15961 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15962 | ops->print_it = print_it_watchpoint; | |
15963 | ops->print_mention = print_mention_watchpoint; | |
15964 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15965 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15966 | |
15967 | /* Masked watchpoints. */ | |
15968 | ops = &masked_watchpoint_breakpoint_ops; | |
15969 | *ops = watchpoint_breakpoint_ops; | |
15970 | ops->insert_location = insert_masked_watchpoint; | |
15971 | ops->remove_location = remove_masked_watchpoint; | |
15972 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15973 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15974 | ops->print_it = print_it_masked_watchpoint; | |
15975 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15976 | ops->print_mention = print_mention_masked_watchpoint; | |
15977 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15978 | ||
15979 | /* Tracepoints. */ | |
15980 | ops = &tracepoint_breakpoint_ops; | |
15981 | *ops = base_breakpoint_ops; | |
15982 | ops->re_set = tracepoint_re_set; | |
15983 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15984 | ops->print_one_detail = tracepoint_print_one_detail; | |
15985 | ops->print_mention = tracepoint_print_mention; | |
15986 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
15987 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
15988 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
15989 | ops->decode_linespec = tracepoint_decode_linespec; | |
15990 | ||
55aa24fb SDJ |
15991 | /* Probe tracepoints. */ |
15992 | ops = &tracepoint_probe_breakpoint_ops; | |
15993 | *ops = tracepoint_breakpoint_ops; | |
15994 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
15995 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
15996 | ||
983af33b SDJ |
15997 | /* Static tracepoints with marker (`-m'). */ |
15998 | ops = &strace_marker_breakpoint_ops; | |
15999 | *ops = tracepoint_breakpoint_ops; | |
16000 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16001 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16002 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16003 | |
16004 | /* Fork catchpoints. */ | |
16005 | ops = &catch_fork_breakpoint_ops; | |
16006 | *ops = base_breakpoint_ops; | |
16007 | ops->insert_location = insert_catch_fork; | |
16008 | ops->remove_location = remove_catch_fork; | |
16009 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16010 | ops->print_it = print_it_catch_fork; | |
16011 | ops->print_one = print_one_catch_fork; | |
16012 | ops->print_mention = print_mention_catch_fork; | |
16013 | ops->print_recreate = print_recreate_catch_fork; | |
16014 | ||
16015 | /* Vfork catchpoints. */ | |
16016 | ops = &catch_vfork_breakpoint_ops; | |
16017 | *ops = base_breakpoint_ops; | |
16018 | ops->insert_location = insert_catch_vfork; | |
16019 | ops->remove_location = remove_catch_vfork; | |
16020 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16021 | ops->print_it = print_it_catch_vfork; | |
16022 | ops->print_one = print_one_catch_vfork; | |
16023 | ops->print_mention = print_mention_catch_vfork; | |
16024 | ops->print_recreate = print_recreate_catch_vfork; | |
16025 | ||
16026 | /* Exec catchpoints. */ | |
16027 | ops = &catch_exec_breakpoint_ops; | |
16028 | *ops = base_breakpoint_ops; | |
16029 | ops->dtor = dtor_catch_exec; | |
16030 | ops->insert_location = insert_catch_exec; | |
16031 | ops->remove_location = remove_catch_exec; | |
16032 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16033 | ops->print_it = print_it_catch_exec; | |
16034 | ops->print_one = print_one_catch_exec; | |
16035 | ops->print_mention = print_mention_catch_exec; | |
16036 | ops->print_recreate = print_recreate_catch_exec; | |
16037 | ||
16038 | /* Syscall catchpoints. */ | |
16039 | ops = &catch_syscall_breakpoint_ops; | |
16040 | *ops = base_breakpoint_ops; | |
16041 | ops->dtor = dtor_catch_syscall; | |
16042 | ops->insert_location = insert_catch_syscall; | |
16043 | ops->remove_location = remove_catch_syscall; | |
16044 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16045 | ops->print_it = print_it_catch_syscall; | |
16046 | ops->print_one = print_one_catch_syscall; | |
16047 | ops->print_mention = print_mention_catch_syscall; | |
16048 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16049 | |
16050 | /* Solib-related catchpoints. */ | |
16051 | ops = &catch_solib_breakpoint_ops; | |
16052 | *ops = base_breakpoint_ops; | |
16053 | ops->dtor = dtor_catch_solib; | |
16054 | ops->insert_location = insert_catch_solib; | |
16055 | ops->remove_location = remove_catch_solib; | |
16056 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16057 | ops->check_status = check_status_catch_solib; | |
16058 | ops->print_it = print_it_catch_solib; | |
16059 | ops->print_one = print_one_catch_solib; | |
16060 | ops->print_mention = print_mention_catch_solib; | |
16061 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16062 | |
16063 | ops = &dprintf_breakpoint_ops; | |
16064 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16065 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16066 | ops->resources_needed = bkpt_resources_needed; |
16067 | ops->print_it = bkpt_print_it; | |
16068 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16069 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16070 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16071 | } |
16072 | ||
8bfd80db YQ |
16073 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16074 | ||
16075 | static struct cmd_list_element *enablebreaklist = NULL; | |
16076 | ||
c906108c | 16077 | void |
fba45db2 | 16078 | _initialize_breakpoint (void) |
c906108c SS |
16079 | { |
16080 | struct cmd_list_element *c; | |
16081 | ||
2060206e PA |
16082 | initialize_breakpoint_ops (); |
16083 | ||
84acb35a | 16084 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16085 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16086 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16087 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16088 | |
55aa24fb SDJ |
16089 | breakpoint_objfile_key |
16090 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16091 | |
fa3064dd | 16092 | catch_syscall_inferior_data |
8e260fc0 TT |
16093 | = register_inferior_data_with_cleanup (NULL, |
16094 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16095 | |
c906108c SS |
16096 | breakpoint_chain = 0; |
16097 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16098 | before a breakpoint is set. */ | |
16099 | breakpoint_count = 0; | |
16100 | ||
1042e4c0 SS |
16101 | tracepoint_count = 0; |
16102 | ||
1bedd215 AC |
16103 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16104 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16105 | Usage is `ignore N COUNT'.")); | |
c906108c | 16106 | if (xdb_commands) |
c5aa993b | 16107 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16108 | |
1bedd215 AC |
16109 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16110 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16111 | Give breakpoint number as argument after \"commands\".\n\ |
16112 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16113 | The commands themselves follow starting on the next line.\n\ | |
16114 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16115 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16116 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16117 | |
d55637df | 16118 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16119 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16120 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16121 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16122 | set_cmd_completer (c, condition_completer); |
c906108c | 16123 | |
1bedd215 | 16124 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16125 | Set a temporary breakpoint.\n\ |
c906108c SS |
16126 | Like \"break\" except the breakpoint is only temporary,\n\ |
16127 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16128 | by using \"enable delete\" on the breakpoint number.\n\ |
16129 | \n" | |
16130 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16131 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16132 | |
1bedd215 | 16133 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16134 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16135 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16136 | some target hardware may not have this support.\n\ |
16137 | \n" | |
16138 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16139 | set_cmd_completer (c, location_completer); |
c906108c | 16140 | |
1bedd215 | 16141 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16142 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16143 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16144 | so it will be deleted when hit.\n\ |
16145 | \n" | |
16146 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16147 | set_cmd_completer (c, location_completer); |
c906108c | 16148 | |
1bedd215 AC |
16149 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16150 | Enable some breakpoints.\n\ | |
c906108c SS |
16151 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16152 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16153 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16154 | With a subcommand you can enable temporarily."), |
c906108c SS |
16155 | &enablelist, "enable ", 1, &cmdlist); |
16156 | if (xdb_commands) | |
1bedd215 AC |
16157 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16158 | Enable some breakpoints.\n\ | |
c906108c SS |
16159 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16160 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16161 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16162 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16163 | |
16164 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16165 | ||
84951ab5 | 16166 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16167 | Enable some breakpoints.\n\ |
c906108c SS |
16168 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16169 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16170 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16171 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16172 | |
1a966eab AC |
16173 | add_cmd ("once", no_class, enable_once_command, _("\ |
16174 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16175 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16176 | &enablebreaklist); |
16177 | ||
1a966eab AC |
16178 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16179 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16180 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16181 | &enablebreaklist); |
16182 | ||
816338b5 SS |
16183 | add_cmd ("count", no_class, enable_count_command, _("\ |
16184 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16185 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16186 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16187 | &enablebreaklist); | |
16188 | ||
1a966eab AC |
16189 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16190 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16191 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16192 | &enablelist); |
16193 | ||
1a966eab AC |
16194 | add_cmd ("once", no_class, enable_once_command, _("\ |
16195 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16196 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16197 | &enablelist); |
16198 | ||
16199 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16200 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16201 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16202 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16203 | &enablelist); |
16204 | ||
1bedd215 AC |
16205 | add_prefix_cmd ("disable", class_breakpoint, 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."), |
c906108c SS |
16210 | &disablelist, "disable ", 1, &cmdlist); |
16211 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16212 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16213 | if (xdb_commands) | |
1bedd215 AC |
16214 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16215 | Disable some breakpoints.\n\ | |
c906108c SS |
16216 | Arguments are breakpoint numbers with spaces in between.\n\ |
16217 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16218 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16219 | |
1a966eab AC |
16220 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16221 | Disable some breakpoints.\n\ | |
c906108c SS |
16222 | Arguments are breakpoint numbers with spaces in between.\n\ |
16223 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16224 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16225 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16226 | &disablelist); |
16227 | ||
1bedd215 AC |
16228 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16229 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16230 | Arguments are breakpoint numbers with spaces in between.\n\ |
16231 | To delete all breakpoints, give no argument.\n\ | |
16232 | \n\ | |
16233 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16234 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16235 | &deletelist, "delete ", 1, &cmdlist); |
16236 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16237 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16238 | if (xdb_commands) |
1bedd215 AC |
16239 | add_com ("db", class_breakpoint, delete_command, _("\ |
16240 | Delete some breakpoints.\n\ | |
c906108c | 16241 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16242 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16243 | |
1a966eab AC |
16244 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16245 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16246 | Arguments are breakpoint numbers with spaces in between.\n\ |
16247 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16248 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16249 | &deletelist); |
16250 | ||
1bedd215 AC |
16251 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16252 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16253 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16254 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16255 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16256 | If an address is specified, breakpoints at that address are cleared.\n\ |
16257 | \n\ | |
16258 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16259 | is executing in.\n\ |
16260 | \n\ | |
1bedd215 | 16261 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16262 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16263 | |
1bedd215 | 16264 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16265 | Set breakpoint at specified line or function.\n" |
16266 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16267 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16268 | |
c906108c SS |
16269 | add_com_alias ("b", "break", class_run, 1); |
16270 | add_com_alias ("br", "break", class_run, 1); | |
16271 | add_com_alias ("bre", "break", class_run, 1); | |
16272 | add_com_alias ("brea", "break", class_run, 1); | |
16273 | ||
7681d515 PM |
16274 | if (xdb_commands) |
16275 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16276 | |
16277 | if (dbx_commands) | |
16278 | { | |
1bedd215 AC |
16279 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16280 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16281 | &stoplist, "stop ", 1, &cmdlist); |
16282 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16283 | _("Break in function or address."), &stoplist); |
c5aa993b | 16284 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16285 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16286 | add_com ("status", class_info, breakpoints_info, _("\ |
16287 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16288 | The \"Type\" column indicates one of:\n\ |
16289 | \tbreakpoint - normal breakpoint\n\ | |
16290 | \twatchpoint - watchpoint\n\ | |
16291 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16292 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16293 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16294 | address and file/line number respectively.\n\ |
16295 | \n\ | |
16296 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16297 | are set to the address of the last breakpoint listed unless the command\n\ |
16298 | is prefixed with \"server \".\n\n\ | |
c906108c | 16299 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16300 | breakpoint set.")); |
c906108c SS |
16301 | } |
16302 | ||
1bedd215 | 16303 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16304 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16305 | The \"Type\" column indicates one of:\n\ |
16306 | \tbreakpoint - normal breakpoint\n\ | |
16307 | \twatchpoint - watchpoint\n\ | |
16308 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16309 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16310 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16311 | address and file/line number respectively.\n\ |
16312 | \n\ | |
16313 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16314 | are set to the address of the last breakpoint listed unless the command\n\ |
16315 | is prefixed with \"server \".\n\n\ | |
c906108c | 16316 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16317 | breakpoint set.")); |
c906108c | 16318 | |
6b04bdb7 MS |
16319 | add_info_alias ("b", "breakpoints", 1); |
16320 | ||
c906108c | 16321 | if (xdb_commands) |
1bedd215 AC |
16322 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16323 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16324 | The \"Type\" column indicates one of:\n\ |
16325 | \tbreakpoint - normal breakpoint\n\ | |
16326 | \twatchpoint - watchpoint\n\ | |
16327 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16328 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16329 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16330 | address and file/line number respectively.\n\ |
16331 | \n\ | |
16332 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16333 | are set to the address of the last breakpoint listed unless the command\n\ |
16334 | is prefixed with \"server \".\n\n\ | |
c906108c | 16335 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16336 | breakpoint set.")); |
c906108c | 16337 | |
1a966eab AC |
16338 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16339 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16340 | The \"Type\" column indicates one of:\n\ |
16341 | \tbreakpoint - normal breakpoint\n\ | |
16342 | \twatchpoint - watchpoint\n\ | |
16343 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16344 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16345 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16346 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16347 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16348 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16349 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16350 | address and file/line number respectively.\n\ |
16351 | \n\ | |
16352 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16353 | are set to the address of the last breakpoint listed unless the command\n\ |
16354 | is prefixed with \"server \".\n\n\ | |
c906108c | 16355 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16356 | breakpoint set."), |
c906108c SS |
16357 | &maintenanceinfolist); |
16358 | ||
44feb3ce TT |
16359 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16360 | Set catchpoints to catch events."), | |
16361 | &catch_cmdlist, "catch ", | |
16362 | 0/*allow-unknown*/, &cmdlist); | |
16363 | ||
16364 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16365 | Set temporary catchpoints to catch events."), | |
16366 | &tcatch_cmdlist, "tcatch ", | |
16367 | 0/*allow-unknown*/, &cmdlist); | |
16368 | ||
44feb3ce TT |
16369 | add_catch_command ("fork", _("Catch calls to fork."), |
16370 | catch_fork_command_1, | |
a96d9b2e | 16371 | NULL, |
44feb3ce TT |
16372 | (void *) (uintptr_t) catch_fork_permanent, |
16373 | (void *) (uintptr_t) catch_fork_temporary); | |
16374 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16375 | catch_fork_command_1, | |
a96d9b2e | 16376 | NULL, |
44feb3ce TT |
16377 | (void *) (uintptr_t) catch_vfork_permanent, |
16378 | (void *) (uintptr_t) catch_vfork_temporary); | |
16379 | add_catch_command ("exec", _("Catch calls to exec."), | |
16380 | catch_exec_command_1, | |
a96d9b2e SDJ |
16381 | NULL, |
16382 | CATCH_PERMANENT, | |
16383 | CATCH_TEMPORARY); | |
edcc5120 TT |
16384 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16385 | Usage: catch load [REGEX]\n\ | |
16386 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16387 | catch_load_command_1, | |
16388 | NULL, | |
16389 | CATCH_PERMANENT, | |
16390 | CATCH_TEMPORARY); | |
16391 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16392 | Usage: catch unload [REGEX]\n\ | |
16393 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16394 | catch_unload_command_1, | |
16395 | NULL, | |
16396 | CATCH_PERMANENT, | |
16397 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16398 | add_catch_command ("syscall", _("\ |
16399 | Catch system calls by their names and/or numbers.\n\ | |
16400 | Arguments say which system calls to catch. If no arguments\n\ | |
16401 | are given, every system call will be caught.\n\ | |
16402 | Arguments, if given, should be one or more system call names\n\ | |
16403 | (if your system supports that), or system call numbers."), | |
16404 | catch_syscall_command_1, | |
16405 | catch_syscall_completer, | |
44feb3ce TT |
16406 | CATCH_PERMANENT, |
16407 | CATCH_TEMPORARY); | |
c5aa993b | 16408 | |
1bedd215 AC |
16409 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16410 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16411 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16412 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16413 | an expression changes.\n\ |
16414 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16415 | the memory to which it refers.")); | |
65d12d83 | 16416 | set_cmd_completer (c, expression_completer); |
c906108c | 16417 | |
1bedd215 AC |
16418 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16419 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16420 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16421 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16422 | an expression is read.\n\ |
16423 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16424 | the memory to which it refers.")); | |
65d12d83 | 16425 | set_cmd_completer (c, expression_completer); |
c906108c | 16426 | |
1bedd215 AC |
16427 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16428 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16429 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16430 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16431 | an expression is either read or written.\n\ |
16432 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16433 | the memory to which it refers.")); | |
65d12d83 | 16434 | set_cmd_completer (c, expression_completer); |
c906108c | 16435 | |
d77f58be | 16436 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16437 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16438 | |
920d2a44 AC |
16439 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16440 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16441 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16442 | &can_use_hw_watchpoints, _("\ | |
16443 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16444 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16445 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16446 | such is available. (However, any hardware watchpoints that were\n\ | |
16447 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16448 | hardware.)"), |
16449 | NULL, | |
920d2a44 | 16450 | show_can_use_hw_watchpoints, |
85c07804 | 16451 | &setlist, &showlist); |
c906108c SS |
16452 | |
16453 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16454 | |
1042e4c0 SS |
16455 | /* Tracepoint manipulation commands. */ |
16456 | ||
16457 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16458 | Set a tracepoint at specified line or function.\n\ | |
16459 | \n" | |
16460 | BREAK_ARGS_HELP ("trace") "\n\ | |
16461 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16462 | set_cmd_completer (c, location_completer); | |
16463 | ||
16464 | add_com_alias ("tp", "trace", class_alias, 0); | |
16465 | add_com_alias ("tr", "trace", class_alias, 1); | |
16466 | add_com_alias ("tra", "trace", class_alias, 1); | |
16467 | add_com_alias ("trac", "trace", class_alias, 1); | |
16468 | ||
7a697b8d SS |
16469 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16470 | Set a fast tracepoint at specified line or function.\n\ | |
16471 | \n" | |
16472 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16473 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16474 | set_cmd_completer (c, location_completer); | |
16475 | ||
0fb4aa4b PA |
16476 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16477 | Set a static tracepoint at specified line, function or marker.\n\ | |
16478 | \n\ | |
16479 | strace [LOCATION] [if CONDITION]\n\ | |
16480 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16481 | or -m MARKER_ID.\n\ | |
16482 | If a line number is specified, probe the marker at start of code\n\ | |
16483 | for that line. If a function is specified, probe the marker at start\n\ | |
16484 | of code for that function. If an address is specified, probe the marker\n\ | |
16485 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16486 | with that name. With no LOCATION, uses current execution address of\n\ | |
16487 | the selected stack frame.\n\ | |
16488 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16489 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16490 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16491 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16492 | \n\ | |
16493 | CONDITION is a boolean expression.\n\ | |
16494 | \n\ | |
d41c0fc8 PA |
16495 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16496 | conditions are different.\n\ | |
0fb4aa4b PA |
16497 | \n\ |
16498 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16499 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16500 | set_cmd_completer (c, location_completer); | |
16501 | ||
1042e4c0 | 16502 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16503 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16504 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16505 | last tracepoint set.")); | |
16506 | ||
16507 | add_info_alias ("tp", "tracepoints", 1); | |
16508 | ||
16509 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16510 | Delete specified tracepoints.\n\ | |
16511 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16512 | No argument means delete all tracepoints."), | |
16513 | &deletelist); | |
7e20dfcd | 16514 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16515 | |
16516 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16517 | Disable specified tracepoints.\n\ | |
16518 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16519 | No argument means disable all tracepoints."), | |
16520 | &disablelist); | |
16521 | deprecate_cmd (c, "disable"); | |
16522 | ||
16523 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16524 | Enable specified tracepoints.\n\ | |
16525 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16526 | No argument means enable all tracepoints."), | |
16527 | &enablelist); | |
16528 | deprecate_cmd (c, "enable"); | |
16529 | ||
16530 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16531 | Set the passcount for a tracepoint.\n\ | |
16532 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16533 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16534 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16535 | ||
6149aea9 PA |
16536 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16537 | _("Save breakpoint definitions as a script."), | |
16538 | &save_cmdlist, "save ", | |
16539 | 0/*allow-unknown*/, &cmdlist); | |
16540 | ||
16541 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16542 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16543 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16544 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16545 | session to restore them."), | |
16546 | &save_cmdlist); | |
16547 | set_cmd_completer (c, filename_completer); | |
16548 | ||
16549 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16550 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16551 | Use the 'source' command in another debug session to restore them."), |
16552 | &save_cmdlist); | |
1042e4c0 SS |
16553 | set_cmd_completer (c, filename_completer); |
16554 | ||
6149aea9 PA |
16555 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16556 | deprecate_cmd (c, "save tracepoints"); | |
16557 | ||
1bedd215 | 16558 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16559 | Breakpoint specific settings\n\ |
16560 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16561 | pending breakpoint behavior"), |
fa8d40ab JJ |
16562 | &breakpoint_set_cmdlist, "set breakpoint ", |
16563 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16564 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16565 | Breakpoint specific settings\n\ |
16566 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16567 | pending breakpoint behavior"), |
fa8d40ab JJ |
16568 | &breakpoint_show_cmdlist, "show breakpoint ", |
16569 | 0/*allow-unknown*/, &showlist); | |
16570 | ||
7915a72c AC |
16571 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16572 | &pending_break_support, _("\ | |
16573 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16574 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16575 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16576 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16577 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16578 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16579 | NULL, |
920d2a44 | 16580 | show_pending_break_support, |
6e1d7d6c AC |
16581 | &breakpoint_set_cmdlist, |
16582 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16583 | |
16584 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16585 | |
16586 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16587 | &automatic_hardware_breakpoints, _("\ | |
16588 | Set automatic usage of hardware breakpoints."), _("\ | |
16589 | Show automatic usage of hardware breakpoints."), _("\ | |
16590 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16591 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16592 | a warning will be emitted for such breakpoints."), | |
16593 | NULL, | |
16594 | show_automatic_hardware_breakpoints, | |
16595 | &breakpoint_set_cmdlist, | |
16596 | &breakpoint_show_cmdlist); | |
74960c60 | 16597 | |
72d0e2c5 YQ |
16598 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16599 | &always_inserted_mode, _("\ | |
74960c60 VP |
16600 | Set mode for inserting breakpoints."), _("\ |
16601 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16602 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16603 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16604 | breakpoints are inserted immediately and removed only when the user\n\ | |
16605 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16606 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16607 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16608 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16609 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16610 | NULL, |
16611 | &show_always_inserted_mode, | |
16612 | &breakpoint_set_cmdlist, | |
16613 | &breakpoint_show_cmdlist); | |
f1310107 | 16614 | |
b775012e LM |
16615 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16616 | condition_evaluation_enums, | |
16617 | &condition_evaluation_mode_1, _("\ | |
16618 | Set mode of breakpoint condition evaluation."), _("\ | |
16619 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16620 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16621 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16622 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16623 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16624 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16625 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16626 | be set to \"gdb\""), | |
16627 | &set_condition_evaluation_mode, | |
16628 | &show_condition_evaluation_mode, | |
16629 | &breakpoint_set_cmdlist, | |
16630 | &breakpoint_show_cmdlist); | |
16631 | ||
f1310107 TJB |
16632 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16633 | Set a breakpoint for an address range.\n\ | |
16634 | break-range START-LOCATION, END-LOCATION\n\ | |
16635 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16636 | LINENUM, for that line in the current file,\n\ | |
16637 | FILE:LINENUM, for that line in that file,\n\ | |
16638 | +OFFSET, for that number of lines after the current line\n\ | |
16639 | or the start of the range\n\ | |
16640 | FUNCTION, for the first line in that function,\n\ | |
16641 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16642 | *ADDRESS, for the instruction at that address.\n\ | |
16643 | \n\ | |
16644 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16645 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16646 | range (including START-LOCATION and END-LOCATION).")); | |
16647 | ||
e7e0cddf SS |
16648 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16649 | Set a dynamic printf at specified line or function.\n\ | |
16650 | dprintf location,format string,arg1,arg2,...\n\ | |
16651 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16652 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16653 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16654 | set_cmd_completer (c, location_completer); |
16655 | ||
16656 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16657 | dprintf_style_enums, &dprintf_style, _("\ | |
16658 | Set the style of usage for dynamic printf."), _("\ | |
16659 | Show the style of usage for dynamic printf."), _("\ | |
16660 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16661 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16662 | console, as with the \"printf\" command.\n\ | |
16663 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16664 | program; by default printf(), but you can choose a different function or\n\ | |
16665 | output stream by setting dprintf-function and dprintf-channel."), | |
16666 | update_dprintf_commands, NULL, | |
16667 | &setlist, &showlist); | |
16668 | ||
16669 | dprintf_function = xstrdup ("printf"); | |
16670 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16671 | &dprintf_function, _("\ | |
16672 | Set the function to use for dynamic printf"), _("\ | |
16673 | Show the function to use for dynamic printf"), NULL, | |
16674 | update_dprintf_commands, NULL, | |
16675 | &setlist, &showlist); | |
16676 | ||
16677 | dprintf_channel = xstrdup (""); | |
16678 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16679 | &dprintf_channel, _("\ | |
16680 | Set the channel to use for dynamic printf"), _("\ | |
16681 | Show the channel to use for dynamic printf"), NULL, | |
16682 | update_dprintf_commands, NULL, | |
16683 | &setlist, &showlist); | |
16684 | ||
d3ce09f5 SS |
16685 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16686 | &disconnected_dprintf, _("\ | |
16687 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16688 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16689 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16690 | even if GDB disconnects or detaches from the target."), | |
16691 | NULL, | |
16692 | NULL, | |
16693 | &setlist, &showlist); | |
16694 | ||
16695 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16696 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16697 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16698 | ||
765dc015 | 16699 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16700 | |
16701 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16702 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16703 | } |