Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.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" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
60250e8b | 54 | #include "exceptions.h" |
765dc015 | 55 | #include "memattr.h" |
f7f9143b | 56 | #include "ada-lang.h" |
d1aa2f50 | 57 | #include "top.h" |
79a45b7d | 58 | #include "valprint.h" |
4efc6507 | 59 | #include "jit.h" |
a96d9b2e | 60 | #include "xml-syscall.h" |
65d79d4b | 61 | #include "parser-defs.h" |
55aa24fb SDJ |
62 | #include "gdb_regex.h" |
63 | #include "probe.h" | |
e9cafbcc | 64 | #include "cli/cli-utils.h" |
be34f849 | 65 | #include "continuations.h" |
1bfeeb0f JL |
66 | #include "stack.h" |
67 | #include "skip.h" | |
b775012e | 68 | #include "ax-gdb.h" |
e2e4d78b | 69 | #include "dummy-frame.h" |
c906108c | 70 | |
d3ce09f5 SS |
71 | #include "format.h" |
72 | ||
1042e4c0 SS |
73 | /* readline include files */ |
74 | #include "readline/readline.h" | |
75 | #include "readline/history.h" | |
76 | ||
77 | /* readline defines this. */ | |
78 | #undef savestring | |
79 | ||
034dad6f | 80 | #include "mi/mi-common.h" |
6dddc817 | 81 | #include "extension.h" |
104c1213 | 82 | |
e7e8980f YQ |
83 | /* Enums for exception-handling support. */ |
84 | enum exception_event_kind | |
85 | { | |
86 | EX_EVENT_THROW, | |
591f19e8 | 87 | EX_EVENT_RETHROW, |
e7e8980f YQ |
88 | EX_EVENT_CATCH |
89 | }; | |
90 | ||
4a64f543 | 91 | /* Prototypes for local functions. */ |
c906108c | 92 | |
a14ed312 | 93 | static void enable_delete_command (char *, int); |
c906108c | 94 | |
a14ed312 | 95 | static void enable_once_command (char *, int); |
c906108c | 96 | |
816338b5 SS |
97 | static void enable_count_command (char *, int); |
98 | ||
a14ed312 | 99 | static void disable_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void enable_command (char *, int); |
c906108c | 102 | |
95a42b64 TT |
103 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
104 | void *), | |
105 | void *); | |
c906108c | 106 | |
a14ed312 | 107 | static void ignore_command (char *, int); |
c906108c | 108 | |
4efb68b1 | 109 | static int breakpoint_re_set_one (void *); |
c906108c | 110 | |
348d480f PA |
111 | static void breakpoint_re_set_default (struct breakpoint *); |
112 | ||
983af33b SDJ |
113 | static void create_sals_from_address_default (char **, |
114 | struct linespec_result *, | |
115 | enum bptype, char *, | |
116 | char **); | |
117 | ||
118 | static void create_breakpoints_sal_default (struct gdbarch *, | |
119 | struct linespec_result *, | |
e7e0cddf | 120 | char *, char *, enum bptype, |
983af33b SDJ |
121 | enum bpdisp, int, int, |
122 | int, | |
123 | const struct breakpoint_ops *, | |
44f238bb | 124 | int, int, int, unsigned); |
983af33b SDJ |
125 | |
126 | static void decode_linespec_default (struct breakpoint *, char **, | |
127 | struct symtabs_and_lines *); | |
128 | ||
a14ed312 | 129 | static void clear_command (char *, int); |
c906108c | 130 | |
a14ed312 | 131 | static void catch_command (char *, int); |
c906108c | 132 | |
a9634178 | 133 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 134 | |
98deb0da | 135 | static void break_command_1 (char *, int, int); |
c906108c | 136 | |
a14ed312 | 137 | static void mention (struct breakpoint *); |
c906108c | 138 | |
348d480f PA |
139 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
140 | enum bptype, | |
c0a91b2b | 141 | const struct breakpoint_ops *); |
3742cc8b YQ |
142 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
143 | const struct symtab_and_line *); | |
144 | ||
4a64f543 MS |
145 | /* This function is used in gdbtk sources and thus can not be made |
146 | static. */ | |
63c252f8 | 147 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 148 | struct symtab_and_line, |
c0a91b2b TT |
149 | enum bptype, |
150 | const struct breakpoint_ops *); | |
c906108c | 151 | |
06edf0c0 PA |
152 | static struct breakpoint * |
153 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
154 | enum bptype type, | |
a1aa2221 LM |
155 | const struct breakpoint_ops *ops, |
156 | int loc_enabled); | |
06edf0c0 | 157 | |
76897487 KB |
158 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
159 | ||
a6d9a66e UW |
160 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
161 | CORE_ADDR bpaddr, | |
88f7da05 | 162 | enum bptype bptype); |
76897487 | 163 | |
6c95b8df PA |
164 | static void describe_other_breakpoints (struct gdbarch *, |
165 | struct program_space *, CORE_ADDR, | |
5af949e3 | 166 | struct obj_section *, int); |
c906108c | 167 | |
85d721b8 PA |
168 | static int watchpoint_locations_match (struct bp_location *loc1, |
169 | struct bp_location *loc2); | |
170 | ||
f1310107 TJB |
171 | static int breakpoint_location_address_match (struct bp_location *bl, |
172 | struct address_space *aspace, | |
173 | CORE_ADDR addr); | |
174 | ||
a14ed312 | 175 | static void breakpoints_info (char *, int); |
c906108c | 176 | |
d77f58be SS |
177 | static void watchpoints_info (char *, int); |
178 | ||
e5a67952 MS |
179 | static int breakpoint_1 (char *, int, |
180 | int (*) (const struct breakpoint *)); | |
c906108c | 181 | |
4efb68b1 | 182 | static int breakpoint_cond_eval (void *); |
c906108c | 183 | |
4efb68b1 | 184 | static void cleanup_executing_breakpoints (void *); |
c906108c | 185 | |
a14ed312 | 186 | static void commands_command (char *, int); |
c906108c | 187 | |
a14ed312 | 188 | static void condition_command (char *, int); |
c906108c | 189 | |
c5aa993b JM |
190 | typedef enum |
191 | { | |
192 | mark_inserted, | |
193 | mark_uninserted | |
194 | } | |
195 | insertion_state_t; | |
c906108c | 196 | |
0bde7532 | 197 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 198 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 199 | |
e514a9d6 | 200 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 201 | |
4efb68b1 | 202 | static int watchpoint_check (void *); |
c906108c | 203 | |
a14ed312 | 204 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 205 | |
a14ed312 | 206 | static int hw_breakpoint_used_count (void); |
c906108c | 207 | |
a1398e0c PA |
208 | static int hw_watchpoint_use_count (struct breakpoint *); |
209 | ||
210 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
211 | enum bptype type, | |
212 | int *other_type_used); | |
c906108c | 213 | |
a14ed312 | 214 | static void hbreak_command (char *, int); |
c906108c | 215 | |
a14ed312 | 216 | static void thbreak_command (char *, int); |
c906108c | 217 | |
816338b5 SS |
218 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
219 | int count); | |
c906108c | 220 | |
a14ed312 | 221 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 222 | |
a14ed312 | 223 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 228 | |
d03285ec UW |
229 | static void detach_single_step_breakpoints (void); |
230 | ||
ef370185 JB |
231 | static int find_single_step_breakpoint (struct address_space *aspace, |
232 | CORE_ADDR pc); | |
233 | ||
fe3f5fa8 | 234 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
235 | static void incref_bp_location (struct bp_location *loc); |
236 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 237 | |
39d61571 | 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 239 | |
b60e7edf | 240 | static void update_global_location_list (int); |
a5606eee | 241 | |
b60e7edf | 242 | static void update_global_location_list_nothrow (int); |
74960c60 | 243 | |
d77f58be | 244 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
245 | |
246 | static void insert_breakpoint_locations (void); | |
a5606eee | 247 | |
a96d9b2e SDJ |
248 | static int syscall_catchpoint_p (struct breakpoint *b); |
249 | ||
1042e4c0 SS |
250 | static void tracepoints_info (char *, int); |
251 | ||
252 | static void delete_trace_command (char *, int); | |
253 | ||
254 | static void enable_trace_command (char *, int); | |
255 | ||
256 | static void disable_trace_command (char *, int); | |
257 | ||
258 | static void trace_pass_command (char *, int); | |
259 | ||
558a9d82 YQ |
260 | static void set_tracepoint_count (int num); |
261 | ||
9c06b0b4 TJB |
262 | static int is_masked_watchpoint (const struct breakpoint *b); |
263 | ||
b775012e LM |
264 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
265 | ||
983af33b SDJ |
266 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
267 | otherwise. */ | |
268 | ||
269 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 270 | |
2060206e PA |
271 | /* The abstract base class all breakpoint_ops structures inherit |
272 | from. */ | |
ab04a2af | 273 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
274 | |
275 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
276 | that are implemented on top of software or hardware breakpoints | |
277 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
278 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
279 | ||
280 | /* Internal breakpoints class type. */ | |
06edf0c0 | 281 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
282 | |
283 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
284 | static struct breakpoint_ops momentary_breakpoint_ops; |
285 | ||
e2e4d78b JK |
286 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
287 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
288 | ||
2060206e PA |
289 | /* The breakpoint_ops structure to be used in regular user created |
290 | breakpoints. */ | |
291 | struct breakpoint_ops bkpt_breakpoint_ops; | |
292 | ||
55aa24fb SDJ |
293 | /* Breakpoints set on probes. */ |
294 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
295 | ||
e7e0cddf | 296 | /* Dynamic printf class type. */ |
c5867ab6 | 297 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 298 | |
9d497a19 PA |
299 | /* One (or perhaps two) breakpoints used for software single |
300 | stepping. */ | |
301 | ||
302 | static void *single_step_breakpoints[2]; | |
303 | static struct gdbarch *single_step_gdbarch[2]; | |
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 | { |
6dddc817 DE |
1051 | /* Check if this breakpoint has a "stop" method implemented in an |
1052 | extension language. This method and conditions entered into GDB | |
1053 | from the CLI are mutually exclusive. */ | |
1054 | const struct extension_language_defn *extlang | |
1055 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1056 | ||
1057 | if (extlang != NULL) | |
1058 | { | |
1059 | error (_("Only one stop condition allowed. There is currently" | |
1060 | " a %s stop condition defined for this breakpoint."), | |
1061 | ext_lang_capitalized_name (extlang)); | |
1062 | } | |
2566ad2d | 1063 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1064 | |
1065 | if (is_breakpoint (b)) | |
1066 | update_global_location_list (1); | |
1067 | ||
2f069f6f JB |
1068 | return; |
1069 | } | |
c906108c | 1070 | |
8a3fe4f8 | 1071 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1072 | } |
1073 | ||
a7bdde9e VP |
1074 | /* Check that COMMAND do not contain commands that are suitable |
1075 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1076 | Throw if any such commands is found. */ |
1077 | ||
a7bdde9e VP |
1078 | static void |
1079 | check_no_tracepoint_commands (struct command_line *commands) | |
1080 | { | |
1081 | struct command_line *c; | |
cc59ec59 | 1082 | |
a7bdde9e VP |
1083 | for (c = commands; c; c = c->next) |
1084 | { | |
1085 | int i; | |
1086 | ||
1087 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1088 | error (_("The 'while-stepping' command can " |
1089 | "only be used for tracepoints")); | |
a7bdde9e VP |
1090 | |
1091 | for (i = 0; i < c->body_count; ++i) | |
1092 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1093 | ||
1094 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1095 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1096 | command directly. */ |
1097 | if (strstr (c->line, "collect ") == c->line) | |
1098 | error (_("The 'collect' command can only be used for tracepoints")); | |
1099 | ||
51661e93 VP |
1100 | if (strstr (c->line, "teval ") == c->line) |
1101 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1102 | } |
1103 | } | |
1104 | ||
d77f58be SS |
1105 | /* Encapsulate tests for different types of tracepoints. */ |
1106 | ||
d9b3f62e PA |
1107 | static int |
1108 | is_tracepoint_type (enum bptype type) | |
1109 | { | |
1110 | return (type == bp_tracepoint | |
1111 | || type == bp_fast_tracepoint | |
1112 | || type == bp_static_tracepoint); | |
1113 | } | |
1114 | ||
a7bdde9e | 1115 | int |
d77f58be | 1116 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1117 | { |
d9b3f62e | 1118 | return is_tracepoint_type (b->type); |
a7bdde9e | 1119 | } |
d9b3f62e | 1120 | |
e5dd4106 | 1121 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1122 | breakpoint. This function will throw an exception if a problem is |
1123 | found. */ | |
48cb2d85 | 1124 | |
95a42b64 TT |
1125 | static void |
1126 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1127 | struct command_line *commands) | |
48cb2d85 | 1128 | { |
d77f58be | 1129 | if (is_tracepoint (b)) |
a7bdde9e | 1130 | { |
c9a6ce02 | 1131 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1132 | struct command_line *c; |
1133 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1134 | |
1135 | /* Reset the while-stepping step count. The previous commands | |
1136 | might have included a while-stepping action, while the new | |
1137 | ones might not. */ | |
1138 | t->step_count = 0; | |
1139 | ||
1140 | /* We need to verify that each top-level element of commands is | |
1141 | valid for tracepoints, that there's at most one | |
1142 | while-stepping element, and that the while-stepping's body | |
1143 | has valid tracing commands excluding nested while-stepping. | |
1144 | We also need to validate the tracepoint action line in the | |
1145 | context of the tracepoint --- validate_actionline actually | |
1146 | has side effects, like setting the tracepoint's | |
1147 | while-stepping STEP_COUNT, in addition to checking if the | |
1148 | collect/teval actions parse and make sense in the | |
1149 | tracepoint's context. */ | |
a7bdde9e VP |
1150 | for (c = commands; c; c = c->next) |
1151 | { | |
a7bdde9e VP |
1152 | if (c->control_type == while_stepping_control) |
1153 | { | |
1154 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1155 | error (_("The 'while-stepping' command " |
1156 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1157 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1158 | error (_("The 'while-stepping' command " |
1159 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1160 | |
1161 | if (while_stepping) | |
3e43a32a MS |
1162 | error (_("The 'while-stepping' command " |
1163 | "can be used only once")); | |
a7bdde9e VP |
1164 | else |
1165 | while_stepping = c; | |
1166 | } | |
c9a6ce02 PA |
1167 | |
1168 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1169 | } |
1170 | if (while_stepping) | |
1171 | { | |
1172 | struct command_line *c2; | |
1173 | ||
1174 | gdb_assert (while_stepping->body_count == 1); | |
1175 | c2 = while_stepping->body_list[0]; | |
1176 | for (; c2; c2 = c2->next) | |
1177 | { | |
a7bdde9e VP |
1178 | if (c2->control_type == while_stepping_control) |
1179 | error (_("The 'while-stepping' command cannot be nested")); | |
1180 | } | |
1181 | } | |
1182 | } | |
1183 | else | |
1184 | { | |
1185 | check_no_tracepoint_commands (commands); | |
1186 | } | |
95a42b64 TT |
1187 | } |
1188 | ||
0fb4aa4b PA |
1189 | /* Return a vector of all the static tracepoints set at ADDR. The |
1190 | caller is responsible for releasing the vector. */ | |
1191 | ||
1192 | VEC(breakpoint_p) * | |
1193 | static_tracepoints_here (CORE_ADDR addr) | |
1194 | { | |
1195 | struct breakpoint *b; | |
1196 | VEC(breakpoint_p) *found = 0; | |
1197 | struct bp_location *loc; | |
1198 | ||
1199 | ALL_BREAKPOINTS (b) | |
1200 | if (b->type == bp_static_tracepoint) | |
1201 | { | |
1202 | for (loc = b->loc; loc; loc = loc->next) | |
1203 | if (loc->address == addr) | |
1204 | VEC_safe_push(breakpoint_p, found, b); | |
1205 | } | |
1206 | ||
1207 | return found; | |
1208 | } | |
1209 | ||
95a42b64 | 1210 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1211 | validate that only allowed commands are included. */ |
95a42b64 TT |
1212 | |
1213 | void | |
4a64f543 MS |
1214 | breakpoint_set_commands (struct breakpoint *b, |
1215 | struct command_line *commands) | |
95a42b64 TT |
1216 | { |
1217 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1218 | |
9add0f1b TT |
1219 | decref_counted_command_line (&b->commands); |
1220 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1221 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1222 | } |
1223 | ||
45a43567 TT |
1224 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1225 | is not the same as the "silent" that may appear in the breakpoint's | |
1226 | commands. */ | |
1227 | ||
1228 | void | |
1229 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1230 | { | |
1231 | int old_silent = b->silent; | |
1232 | ||
1233 | b->silent = silent; | |
1234 | if (old_silent != silent) | |
8d3788bd | 1235 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1236 | } |
1237 | ||
1238 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1239 | breakpoint work for any thread. */ | |
1240 | ||
1241 | void | |
1242 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1243 | { | |
1244 | int old_thread = b->thread; | |
1245 | ||
1246 | b->thread = thread; | |
1247 | if (old_thread != thread) | |
8d3788bd | 1248 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1249 | } |
1250 | ||
1251 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1252 | breakpoint work for any task. */ | |
1253 | ||
1254 | void | |
1255 | breakpoint_set_task (struct breakpoint *b, int task) | |
1256 | { | |
1257 | int old_task = b->task; | |
1258 | ||
1259 | b->task = task; | |
1260 | if (old_task != task) | |
8d3788bd | 1261 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1262 | } |
1263 | ||
95a42b64 TT |
1264 | void |
1265 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1266 | { |
1267 | struct breakpoint *b = closure; | |
cc59ec59 | 1268 | |
6f937416 | 1269 | validate_actionline (line, b); |
a7bdde9e VP |
1270 | } |
1271 | ||
95a42b64 TT |
1272 | /* A structure used to pass information through |
1273 | map_breakpoint_numbers. */ | |
1274 | ||
1275 | struct commands_info | |
1276 | { | |
1277 | /* True if the command was typed at a tty. */ | |
1278 | int from_tty; | |
86b17b60 PA |
1279 | |
1280 | /* The breakpoint range spec. */ | |
1281 | char *arg; | |
1282 | ||
95a42b64 TT |
1283 | /* Non-NULL if the body of the commands are being read from this |
1284 | already-parsed command. */ | |
1285 | struct command_line *control; | |
86b17b60 | 1286 | |
95a42b64 TT |
1287 | /* The command lines read from the user, or NULL if they have not |
1288 | yet been read. */ | |
1289 | struct counted_command_line *cmd; | |
1290 | }; | |
1291 | ||
1292 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1293 | commands_command. */ | |
1294 | ||
c906108c | 1295 | static void |
95a42b64 | 1296 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1297 | { |
95a42b64 | 1298 | struct commands_info *info = data; |
c906108c | 1299 | |
95a42b64 TT |
1300 | if (info->cmd == NULL) |
1301 | { | |
1302 | struct command_line *l; | |
5c44784c | 1303 | |
95a42b64 TT |
1304 | if (info->control != NULL) |
1305 | l = copy_command_lines (info->control->body_list[0]); | |
1306 | else | |
86b17b60 PA |
1307 | { |
1308 | struct cleanup *old_chain; | |
1309 | char *str; | |
c5aa993b | 1310 | |
3e43a32a MS |
1311 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1312 | "%s, one per line."), | |
86b17b60 PA |
1313 | info->arg); |
1314 | ||
1315 | old_chain = make_cleanup (xfree, str); | |
1316 | ||
1317 | l = read_command_lines (str, | |
1318 | info->from_tty, 1, | |
d77f58be | 1319 | (is_tracepoint (b) |
86b17b60 PA |
1320 | ? check_tracepoint_command : 0), |
1321 | b); | |
1322 | ||
1323 | do_cleanups (old_chain); | |
1324 | } | |
a7bdde9e | 1325 | |
95a42b64 TT |
1326 | info->cmd = alloc_counted_command_line (l); |
1327 | } | |
1328 | ||
1329 | /* If a breakpoint was on the list more than once, we don't need to | |
1330 | do anything. */ | |
1331 | if (b->commands != info->cmd) | |
1332 | { | |
1333 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1334 | incref_counted_command_line (info->cmd); | |
1335 | decref_counted_command_line (&b->commands); | |
1336 | b->commands = info->cmd; | |
8d3788bd | 1337 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1338 | } |
95a42b64 TT |
1339 | } |
1340 | ||
1341 | static void | |
4a64f543 MS |
1342 | commands_command_1 (char *arg, int from_tty, |
1343 | struct command_line *control) | |
95a42b64 TT |
1344 | { |
1345 | struct cleanup *cleanups; | |
1346 | struct commands_info info; | |
1347 | ||
1348 | info.from_tty = from_tty; | |
1349 | info.control = control; | |
1350 | info.cmd = NULL; | |
1351 | /* If we read command lines from the user, then `info' will hold an | |
1352 | extra reference to the commands that we must clean up. */ | |
1353 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1354 | ||
1355 | if (arg == NULL || !*arg) | |
1356 | { | |
86b17b60 | 1357 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1358 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1359 | breakpoint_count); | |
95a42b64 TT |
1360 | else if (breakpoint_count > 0) |
1361 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1362 | else |
1363 | { | |
1364 | /* So that we don't try to free the incoming non-NULL | |
1365 | argument in the cleanup below. Mapping breakpoint | |
1366 | numbers will fail in this case. */ | |
1367 | arg = NULL; | |
1368 | } | |
95a42b64 | 1369 | } |
9766ced4 SS |
1370 | else |
1371 | /* The command loop has some static state, so we need to preserve | |
1372 | our argument. */ | |
1373 | arg = xstrdup (arg); | |
86b17b60 PA |
1374 | |
1375 | if (arg != NULL) | |
1376 | make_cleanup (xfree, arg); | |
1377 | ||
1378 | info.arg = arg; | |
95a42b64 TT |
1379 | |
1380 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1381 | ||
1382 | if (info.cmd == NULL) | |
1383 | error (_("No breakpoints specified.")); | |
1384 | ||
1385 | do_cleanups (cleanups); | |
1386 | } | |
1387 | ||
1388 | static void | |
1389 | commands_command (char *arg, int from_tty) | |
1390 | { | |
1391 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1392 | } |
40c03ae8 EZ |
1393 | |
1394 | /* Like commands_command, but instead of reading the commands from | |
1395 | input stream, takes them from an already parsed command structure. | |
1396 | ||
1397 | This is used by cli-script.c to DTRT with breakpoint commands | |
1398 | that are part of if and while bodies. */ | |
1399 | enum command_control_type | |
1400 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1401 | { | |
95a42b64 TT |
1402 | commands_command_1 (arg, 0, cmd); |
1403 | return simple_control; | |
40c03ae8 | 1404 | } |
876fa593 JK |
1405 | |
1406 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1407 | ||
1408 | static int | |
1409 | bp_location_has_shadow (struct bp_location *bl) | |
1410 | { | |
1411 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1412 | return 0; | |
1413 | if (!bl->inserted) | |
1414 | return 0; | |
1415 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1416 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1417 | return 0; |
1418 | return 1; | |
1419 | } | |
1420 | ||
9d497a19 PA |
1421 | /* Update BUF, which is LEN bytes read from the target address |
1422 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1423 | contents. | |
1424 | ||
1425 | If READBUF is not NULL, this buffer must not overlap with the of | |
1426 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1427 | failed assertion internal error will be raised. */ | |
1428 | ||
1429 | static void | |
1430 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1431 | const gdb_byte *writebuf_org, | |
1432 | ULONGEST memaddr, LONGEST len, | |
1433 | struct bp_target_info *target_info, | |
1434 | struct gdbarch *gdbarch) | |
1435 | { | |
1436 | /* Now do full processing of the found relevant range of elements. */ | |
1437 | CORE_ADDR bp_addr = 0; | |
1438 | int bp_size = 0; | |
1439 | int bptoffset = 0; | |
1440 | ||
1441 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1442 | current_program_space->aspace, 0)) | |
1443 | { | |
1444 | /* The breakpoint is inserted in a different address space. */ | |
1445 | return; | |
1446 | } | |
1447 | ||
1448 | /* Addresses and length of the part of the breakpoint that | |
1449 | we need to copy. */ | |
1450 | bp_addr = target_info->placed_address; | |
1451 | bp_size = target_info->shadow_len; | |
1452 | ||
1453 | if (bp_addr + bp_size <= memaddr) | |
1454 | { | |
1455 | /* The breakpoint is entirely before the chunk of memory we are | |
1456 | reading. */ | |
1457 | return; | |
1458 | } | |
1459 | ||
1460 | if (bp_addr >= memaddr + len) | |
1461 | { | |
1462 | /* The breakpoint is entirely after the chunk of memory we are | |
1463 | reading. */ | |
1464 | return; | |
1465 | } | |
1466 | ||
1467 | /* Offset within shadow_contents. */ | |
1468 | if (bp_addr < memaddr) | |
1469 | { | |
1470 | /* Only copy the second part of the breakpoint. */ | |
1471 | bp_size -= memaddr - bp_addr; | |
1472 | bptoffset = memaddr - bp_addr; | |
1473 | bp_addr = memaddr; | |
1474 | } | |
1475 | ||
1476 | if (bp_addr + bp_size > memaddr + len) | |
1477 | { | |
1478 | /* Only copy the first part of the breakpoint. */ | |
1479 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1480 | } | |
1481 | ||
1482 | if (readbuf != NULL) | |
1483 | { | |
1484 | /* Verify that the readbuf buffer does not overlap with the | |
1485 | shadow_contents buffer. */ | |
1486 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1487 | || readbuf >= (target_info->shadow_contents | |
1488 | + target_info->shadow_len)); | |
1489 | ||
1490 | /* Update the read buffer with this inserted breakpoint's | |
1491 | shadow. */ | |
1492 | memcpy (readbuf + bp_addr - memaddr, | |
1493 | target_info->shadow_contents + bptoffset, bp_size); | |
1494 | } | |
1495 | else | |
1496 | { | |
1497 | const unsigned char *bp; | |
1498 | CORE_ADDR placed_address = target_info->placed_address; | |
1499 | int placed_size = target_info->placed_size; | |
1500 | ||
1501 | /* Update the shadow with what we want to write to memory. */ | |
1502 | memcpy (target_info->shadow_contents + bptoffset, | |
1503 | writebuf_org + bp_addr - memaddr, bp_size); | |
1504 | ||
1505 | /* Determine appropriate breakpoint contents and size for this | |
1506 | address. */ | |
1507 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1508 | ||
1509 | /* Update the final write buffer with this inserted | |
1510 | breakpoint's INSN. */ | |
1511 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1512 | } | |
1513 | } | |
1514 | ||
8defab1a | 1515 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1516 | by replacing any memory breakpoints with their shadowed contents. |
1517 | ||
35c63cd8 JB |
1518 | If READBUF is not NULL, this buffer must not overlap with any of |
1519 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1520 | a failed assertion internal error will be raised. | |
1521 | ||
876fa593 | 1522 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1523 | bl->address - bp_location_placed_address_before_address_max |
1524 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1525 | The range we were requested to resolve shadows for is: |
1526 | memaddr ... memaddr + len | |
1527 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1528 | memaddr + len <= (bl->address |
1529 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1530 | and: |
35df4500 | 1531 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1532 | |
8defab1a | 1533 | void |
f0ba3972 PA |
1534 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1535 | const gdb_byte *writebuf_org, | |
1536 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1537 | { |
4a64f543 MS |
1538 | /* Left boundary, right boundary and median element of our binary |
1539 | search. */ | |
876fa593 | 1540 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1541 | size_t i; |
876fa593 | 1542 | |
4a64f543 MS |
1543 | /* Find BC_L which is a leftmost element which may affect BUF |
1544 | content. It is safe to report lower value but a failure to | |
1545 | report higher one. */ | |
876fa593 JK |
1546 | |
1547 | bc_l = 0; | |
1548 | bc_r = bp_location_count; | |
1549 | while (bc_l + 1 < bc_r) | |
1550 | { | |
35df4500 | 1551 | struct bp_location *bl; |
876fa593 JK |
1552 | |
1553 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1554 | bl = bp_location[bc]; |
876fa593 | 1555 | |
4a64f543 MS |
1556 | /* Check first BL->ADDRESS will not overflow due to the added |
1557 | constant. Then advance the left boundary only if we are sure | |
1558 | the BC element can in no way affect the BUF content (MEMADDR | |
1559 | to MEMADDR + LEN range). | |
876fa593 | 1560 | |
4a64f543 MS |
1561 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1562 | offset so that we cannot miss a breakpoint with its shadow | |
1563 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1564 | |
35df4500 TJB |
1565 | if ((bl->address + bp_location_shadow_len_after_address_max |
1566 | >= bl->address) | |
1567 | && (bl->address + bp_location_shadow_len_after_address_max | |
1568 | <= memaddr)) | |
876fa593 JK |
1569 | bc_l = bc; |
1570 | else | |
1571 | bc_r = bc; | |
1572 | } | |
1573 | ||
128070bb PA |
1574 | /* Due to the binary search above, we need to make sure we pick the |
1575 | first location that's at BC_L's address. E.g., if there are | |
1576 | multiple locations at the same address, BC_L may end up pointing | |
1577 | at a duplicate location, and miss the "master"/"inserted" | |
1578 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1579 | B: | |
1580 | ||
1581 | L1@A, L2@A, L3@B, ... | |
1582 | ||
1583 | BC_L could end up pointing at location L2, while the "master" | |
1584 | location could be L1. Since the `loc->inserted' flag is only set | |
1585 | on "master" locations, we'd forget to restore the shadow of L1 | |
1586 | and L2. */ | |
1587 | while (bc_l > 0 | |
1588 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1589 | bc_l--; | |
1590 | ||
876fa593 JK |
1591 | /* Now do full processing of the found relevant range of elements. */ |
1592 | ||
1593 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1594 | { |
35df4500 | 1595 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1596 | CORE_ADDR bp_addr = 0; |
1597 | int bp_size = 0; | |
1598 | int bptoffset = 0; | |
1599 | ||
35df4500 TJB |
1600 | /* bp_location array has BL->OWNER always non-NULL. */ |
1601 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1602 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1603 | bl->owner->number); |
ffce0d52 | 1604 | |
e5dd4106 | 1605 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1606 | content. */ |
1607 | ||
35df4500 TJB |
1608 | if (bl->address >= bp_location_placed_address_before_address_max |
1609 | && memaddr + len <= (bl->address | |
1610 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1611 | break; |
1612 | ||
35df4500 | 1613 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1614 | continue; |
6c95b8df | 1615 | |
9d497a19 PA |
1616 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1617 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1618 | } | |
c5aa993b | 1619 | |
9d497a19 PA |
1620 | /* Now process single-step breakpoints. These are not found in the |
1621 | bp_location array. */ | |
1622 | for (i = 0; i < 2; i++) | |
1623 | { | |
1624 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
c5aa993b | 1625 | |
9d497a19 PA |
1626 | if (bp_tgt != NULL) |
1627 | { | |
1628 | struct gdbarch *gdbarch = single_step_gdbarch[i]; | |
c5aa993b | 1629 | |
9d497a19 PA |
1630 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1631 | memaddr, len, bp_tgt, gdbarch); | |
1632 | } | |
1633 | } | |
c906108c | 1634 | } |
9d497a19 | 1635 | |
c906108c | 1636 | \f |
c5aa993b | 1637 | |
b775012e LM |
1638 | /* Return true if BPT is either a software breakpoint or a hardware |
1639 | breakpoint. */ | |
1640 | ||
1641 | int | |
1642 | is_breakpoint (const struct breakpoint *bpt) | |
1643 | { | |
1644 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1645 | || bpt->type == bp_hardware_breakpoint |
1646 | || bpt->type == bp_dprintf); | |
b775012e LM |
1647 | } |
1648 | ||
60e1c644 PA |
1649 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1650 | ||
a5606eee | 1651 | static int |
d77f58be | 1652 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1653 | { |
1654 | return (bpt->type == bp_hardware_watchpoint | |
1655 | || bpt->type == bp_read_watchpoint | |
1656 | || bpt->type == bp_access_watchpoint); | |
1657 | } | |
7270d8f2 | 1658 | |
60e1c644 PA |
1659 | /* Return true if BPT is of any watchpoint kind, hardware or |
1660 | software. */ | |
1661 | ||
3a5c3e22 | 1662 | int |
d77f58be | 1663 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1664 | { |
1665 | return (is_hardware_watchpoint (bpt) | |
1666 | || bpt->type == bp_watchpoint); | |
1667 | } | |
1668 | ||
3a5c3e22 PA |
1669 | /* Returns true if the current thread and its running state are safe |
1670 | to evaluate or update watchpoint B. Watchpoints on local | |
1671 | expressions need to be evaluated in the context of the thread that | |
1672 | was current when the watchpoint was created, and, that thread needs | |
1673 | to be stopped to be able to select the correct frame context. | |
1674 | Watchpoints on global expressions can be evaluated on any thread, | |
1675 | and in any state. It is presently left to the target allowing | |
1676 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1677 | |
1678 | static int | |
3a5c3e22 | 1679 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1680 | { |
d0d8b0c6 JK |
1681 | return (b->base.pspace == current_program_space |
1682 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1683 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1684 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1685 | } |
1686 | ||
d0fb5eae JK |
1687 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1688 | associated bp_watchpoint_scope breakpoint. */ | |
1689 | ||
1690 | static void | |
3a5c3e22 | 1691 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1692 | { |
3a5c3e22 | 1693 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1694 | |
1695 | if (b->related_breakpoint != b) | |
1696 | { | |
1697 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1698 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1699 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1700 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1701 | b->related_breakpoint = b; | |
1702 | } | |
1703 | b->disposition = disp_del_at_next_stop; | |
1704 | } | |
1705 | ||
567e1b4e JB |
1706 | /* Assuming that B is a watchpoint: |
1707 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1708 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1709 | - Evaluate the condition if there is one, and store the result |
1710 | in b->loc->cond. | |
a5606eee VP |
1711 | - Update the list of values that must be watched in B->loc. |
1712 | ||
4a64f543 MS |
1713 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1714 | nothing. If this is local watchpoint that is out of scope, delete | |
1715 | it. | |
1716 | ||
1717 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1718 | removed + inserted on each stop here. Normal breakpoints must | |
1719 | never be removed because they might be missed by a running thread | |
1720 | when debugging in non-stop mode. On the other hand, hardware | |
1721 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1722 | to each LWP since they are stored in each LWP's hardware debug | |
1723 | registers. Therefore, such LWP must be stopped first in order to | |
1724 | be able to modify its hardware watchpoints. | |
1725 | ||
1726 | Hardware watchpoints must be reset exactly once after being | |
1727 | presented to the user. It cannot be done sooner, because it would | |
1728 | reset the data used to present the watchpoint hit to the user. And | |
1729 | it must not be done later because it could display the same single | |
1730 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1731 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1732 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1733 | not user-visible - its hit is suppressed if the memory content has | |
1734 | not changed. | |
1735 | ||
1736 | The following constraints influence the location where we can reset | |
1737 | hardware watchpoints: | |
1738 | ||
1739 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1740 | called several times when GDB stops. | |
1741 | ||
1742 | [linux] | |
1743 | * Multiple hardware watchpoints can be hit at the same time, | |
1744 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1745 | hit at a time as the reason for stopping, and all the other hits | |
1746 | are presented later, one after the other, each time the user | |
1747 | requests the execution to be resumed. Execution is not resumed | |
1748 | for the threads still having pending hit event stored in | |
1749 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1750 | the inferior on the first stop the thread hit event is kept being | |
1751 | reported from its cached value by linux_nat_stopped_data_address | |
1752 | until the real thread resume happens after the watchpoint gets | |
1753 | presented and thus its LWP_INFO->STATUS gets reset. | |
1754 | ||
1755 | Therefore the hardware watchpoint hit can get safely reset on the | |
1756 | watchpoint removal from inferior. */ | |
a79d3c27 | 1757 | |
b40ce68a | 1758 | static void |
3a5c3e22 | 1759 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1760 | { |
a5606eee | 1761 | int within_current_scope; |
a5606eee | 1762 | struct frame_id saved_frame_id; |
66076460 | 1763 | int frame_saved; |
a5606eee | 1764 | |
f6bc2008 PA |
1765 | /* If this is a local watchpoint, we only want to check if the |
1766 | watchpoint frame is in scope if the current thread is the thread | |
1767 | that was used to create the watchpoint. */ | |
1768 | if (!watchpoint_in_thread_scope (b)) | |
1769 | return; | |
1770 | ||
3a5c3e22 | 1771 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1772 | return; |
1773 | ||
66076460 | 1774 | frame_saved = 0; |
a5606eee VP |
1775 | |
1776 | /* Determine if the watchpoint is within scope. */ | |
1777 | if (b->exp_valid_block == NULL) | |
1778 | within_current_scope = 1; | |
1779 | else | |
1780 | { | |
b5db5dfc UW |
1781 | struct frame_info *fi = get_current_frame (); |
1782 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1783 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1784 | ||
1785 | /* If we're in a function epilogue, unwinding may not work | |
1786 | properly, so do not attempt to recreate locations at this | |
1787 | point. See similar comments in watchpoint_check. */ | |
1788 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1789 | return; | |
66076460 DJ |
1790 | |
1791 | /* Save the current frame's ID so we can restore it after | |
1792 | evaluating the watchpoint expression on its own frame. */ | |
1793 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1794 | took a frame parameter, so that we didn't have to change the | |
1795 | selected frame. */ | |
1796 | frame_saved = 1; | |
1797 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1798 | ||
a5606eee VP |
1799 | fi = frame_find_by_id (b->watchpoint_frame); |
1800 | within_current_scope = (fi != NULL); | |
1801 | if (within_current_scope) | |
1802 | select_frame (fi); | |
1803 | } | |
1804 | ||
b5db5dfc UW |
1805 | /* We don't free locations. They are stored in the bp_location array |
1806 | and update_global_location_list will eventually delete them and | |
1807 | remove breakpoints if needed. */ | |
3a5c3e22 | 1808 | b->base.loc = NULL; |
b5db5dfc | 1809 | |
a5606eee VP |
1810 | if (within_current_scope && reparse) |
1811 | { | |
bbc13ae3 | 1812 | const char *s; |
d63d0675 | 1813 | |
a5606eee VP |
1814 | if (b->exp) |
1815 | { | |
1816 | xfree (b->exp); | |
1817 | b->exp = NULL; | |
1818 | } | |
d63d0675 | 1819 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1820 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1821 | /* If the meaning of expression itself changed, the old value is |
1822 | no longer relevant. We don't want to report a watchpoint hit | |
1823 | to the user when the old value and the new value may actually | |
1824 | be completely different objects. */ | |
1825 | value_free (b->val); | |
fa4727a6 DJ |
1826 | b->val = NULL; |
1827 | b->val_valid = 0; | |
60e1c644 PA |
1828 | |
1829 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1830 | expression is stored in the breakpoint object, not in the | |
1831 | locations (re)created below. */ | |
3a5c3e22 | 1832 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1833 | { |
1834 | if (b->cond_exp != NULL) | |
1835 | { | |
1836 | xfree (b->cond_exp); | |
1837 | b->cond_exp = NULL; | |
1838 | } | |
1839 | ||
3a5c3e22 | 1840 | s = b->base.cond_string; |
1bb9788d | 1841 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1842 | } |
a5606eee | 1843 | } |
a5606eee VP |
1844 | |
1845 | /* If we failed to parse the expression, for example because | |
1846 | it refers to a global variable in a not-yet-loaded shared library, | |
1847 | don't try to insert watchpoint. We don't automatically delete | |
1848 | such watchpoint, though, since failure to parse expression | |
1849 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1850 | if (!target_has_execution) |
2d134ed3 PA |
1851 | { |
1852 | /* Without execution, memory can't change. No use to try and | |
1853 | set watchpoint locations. The watchpoint will be reset when | |
1854 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1855 | if (!can_use_hw_watchpoints) |
1856 | { | |
1857 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1858 | b->base.type = bp_watchpoint; | |
1859 | else | |
638aa5a1 AB |
1860 | error (_("Can't set read/access watchpoint when " |
1861 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1862 | } |
2d134ed3 PA |
1863 | } |
1864 | else if (within_current_scope && b->exp) | |
a5606eee | 1865 | { |
0cf6dd15 | 1866 | int pc = 0; |
fa4727a6 | 1867 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1868 | struct program_space *frame_pspace; |
a5606eee | 1869 | |
3a1115a0 | 1870 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1871 | |
a5606eee VP |
1872 | /* Avoid setting b->val if it's already set. The meaning of |
1873 | b->val is 'the last value' user saw, and we should update | |
1874 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1875 | happens, the code that reports it updates b->val directly. |
1876 | We don't keep track of the memory value for masked | |
1877 | watchpoints. */ | |
3a5c3e22 | 1878 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1879 | { |
1880 | b->val = v; | |
1881 | b->val_valid = 1; | |
1882 | } | |
a5606eee | 1883 | |
2d134ed3 PA |
1884 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1885 | ||
a5606eee | 1886 | /* Look at each value on the value chain. */ |
9fa40276 | 1887 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1888 | { |
1889 | /* If it's a memory location, and GDB actually needed | |
1890 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1891 | must watch it. If the first value returned is |
1892 | still lazy, that means an error occurred reading it; | |
1893 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1894 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1895 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1896 | { |
1897 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1898 | |
a5606eee VP |
1899 | /* We only watch structs and arrays if user asked |
1900 | for it explicitly, never if they just happen to | |
1901 | appear in the middle of some value chain. */ | |
fa4727a6 | 1902 | if (v == result |
a5606eee VP |
1903 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1904 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1905 | { | |
1906 | CORE_ADDR addr; | |
744a8059 | 1907 | int type; |
a5606eee VP |
1908 | struct bp_location *loc, **tmp; |
1909 | ||
42ae5230 | 1910 | addr = value_address (v); |
a5606eee | 1911 | type = hw_write; |
3a5c3e22 | 1912 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1913 | type = hw_read; |
3a5c3e22 | 1914 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1915 | type = hw_access; |
3a5c3e22 PA |
1916 | |
1917 | loc = allocate_bp_location (&b->base); | |
1918 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1919 | ; |
1920 | *tmp = loc; | |
a6d9a66e | 1921 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1922 | |
1923 | loc->pspace = frame_pspace; | |
a5606eee | 1924 | loc->address = addr; |
744a8059 | 1925 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1926 | loc->watchpoint_type = type; |
1927 | } | |
1928 | } | |
9fa40276 TJB |
1929 | } |
1930 | ||
1931 | /* Change the type of breakpoint between hardware assisted or | |
1932 | an ordinary watchpoint depending on the hardware support | |
1933 | and free hardware slots. REPARSE is set when the inferior | |
1934 | is started. */ | |
a9634178 | 1935 | if (reparse) |
9fa40276 | 1936 | { |
e09342b5 | 1937 | int reg_cnt; |
9fa40276 TJB |
1938 | enum bp_loc_type loc_type; |
1939 | struct bp_location *bl; | |
a5606eee | 1940 | |
a9634178 | 1941 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1942 | |
1943 | if (reg_cnt) | |
9fa40276 TJB |
1944 | { |
1945 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1946 | enum bptype type; |
9fa40276 | 1947 | |
a9634178 TJB |
1948 | /* Use an exact watchpoint when there's only one memory region to be |
1949 | watched, and only one debug register is needed to watch it. */ | |
1950 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1951 | ||
9fa40276 | 1952 | /* We need to determine how many resources are already |
e09342b5 TJB |
1953 | used for all other hardware watchpoints plus this one |
1954 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1955 | this watchpoint in as well. */ |
1956 | ||
1957 | /* If this is a software watchpoint, we try to turn it | |
1958 | to a hardware one -- count resources as if B was of | |
1959 | hardware watchpoint type. */ | |
1960 | type = b->base.type; | |
1961 | if (type == bp_watchpoint) | |
1962 | type = bp_hardware_watchpoint; | |
1963 | ||
1964 | /* This watchpoint may or may not have been placed on | |
1965 | the list yet at this point (it won't be in the list | |
1966 | if we're trying to create it for the first time, | |
1967 | through watch_command), so always account for it | |
1968 | manually. */ | |
1969 | ||
1970 | /* Count resources used by all watchpoints except B. */ | |
1971 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1972 | ||
1973 | /* Add in the resources needed for B. */ | |
1974 | i += hw_watchpoint_use_count (&b->base); | |
1975 | ||
1976 | target_resources_ok | |
1977 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1978 | if (target_resources_ok <= 0) |
a9634178 | 1979 | { |
3a5c3e22 | 1980 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1981 | |
1982 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1983 | error (_("Target does not support this type of " |
1984 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1985 | else if (target_resources_ok < 0 && !sw_mode) |
1986 | error (_("There are not enough available hardware " | |
1987 | "resources for this watchpoint.")); | |
a1398e0c PA |
1988 | |
1989 | /* Downgrade to software watchpoint. */ | |
1990 | b->base.type = bp_watchpoint; | |
1991 | } | |
1992 | else | |
1993 | { | |
1994 | /* If this was a software watchpoint, we've just | |
1995 | found we have enough resources to turn it to a | |
1996 | hardware watchpoint. Otherwise, this is a | |
1997 | nop. */ | |
1998 | b->base.type = type; | |
a9634178 | 1999 | } |
9fa40276 | 2000 | } |
3a5c3e22 | 2001 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2002 | { |
2003 | if (!can_use_hw_watchpoints) | |
2004 | error (_("Can't set read/access watchpoint when " | |
2005 | "hardware watchpoints are disabled.")); | |
2006 | else | |
2007 | error (_("Expression cannot be implemented with " | |
2008 | "read/access watchpoint.")); | |
2009 | } | |
9fa40276 | 2010 | else |
3a5c3e22 | 2011 | b->base.type = bp_watchpoint; |
9fa40276 | 2012 | |
3a5c3e22 | 2013 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2014 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2015 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2016 | bl->loc_type = loc_type; |
2017 | } | |
2018 | ||
2019 | for (v = val_chain; v; v = next) | |
2020 | { | |
a5606eee VP |
2021 | next = value_next (v); |
2022 | if (v != b->val) | |
2023 | value_free (v); | |
2024 | } | |
2025 | ||
c7437ca6 PA |
2026 | /* If a software watchpoint is not watching any memory, then the |
2027 | above left it without any location set up. But, | |
2028 | bpstat_stop_status requires a location to be able to report | |
2029 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2030 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2031 | { |
3a5c3e22 PA |
2032 | struct breakpoint *base = &b->base; |
2033 | base->loc = allocate_bp_location (base); | |
2034 | base->loc->pspace = frame_pspace; | |
2035 | base->loc->address = -1; | |
2036 | base->loc->length = -1; | |
2037 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2038 | } |
a5606eee VP |
2039 | } |
2040 | else if (!within_current_scope) | |
7270d8f2 | 2041 | { |
ac74f770 MS |
2042 | printf_filtered (_("\ |
2043 | Watchpoint %d deleted because the program has left the block\n\ | |
2044 | in which its expression is valid.\n"), | |
3a5c3e22 | 2045 | b->base.number); |
d0fb5eae | 2046 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2047 | } |
a5606eee VP |
2048 | |
2049 | /* Restore the selected frame. */ | |
66076460 DJ |
2050 | if (frame_saved) |
2051 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2052 | } |
2053 | ||
a5606eee | 2054 | |
74960c60 | 2055 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2056 | inserted in the inferior. We don't differentiate the type of BL's owner |
2057 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2058 | breakpoint_ops is not defined, because in insert_bp_location, | |
2059 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2060 | static int |
35df4500 | 2061 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2062 | { |
35df4500 | 2063 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2064 | return 0; |
2065 | ||
35df4500 | 2066 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2067 | return 0; |
2068 | ||
35df4500 | 2069 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2070 | return 0; |
2071 | ||
f8eba3c6 TT |
2072 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2073 | return 0; | |
2074 | ||
56710373 PA |
2075 | /* This is set for example, when we're attached to the parent of a |
2076 | vfork, and have detached from the child. The child is running | |
2077 | free, and we expect it to do an exec or exit, at which point the | |
2078 | OS makes the parent schedulable again (and the target reports | |
2079 | that the vfork is done). Until the child is done with the shared | |
2080 | memory region, do not insert breakpoints in the parent, otherwise | |
2081 | the child could still trip on the parent's breakpoints. Since | |
2082 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2083 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2084 | return 0; |
2085 | ||
31e77af2 PA |
2086 | /* Don't insert a breakpoint if we're trying to step past its |
2087 | location. */ | |
2088 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2089 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2090 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2091 | bl->address)) | |
2092 | return 0; | |
2093 | ||
74960c60 VP |
2094 | return 1; |
2095 | } | |
2096 | ||
934709f0 PW |
2097 | /* Same as should_be_inserted but does the check assuming |
2098 | that the location is not duplicated. */ | |
2099 | ||
2100 | static int | |
2101 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2102 | { | |
2103 | int result; | |
2104 | const int save_duplicate = bl->duplicate; | |
2105 | ||
2106 | bl->duplicate = 0; | |
2107 | result = should_be_inserted (bl); | |
2108 | bl->duplicate = save_duplicate; | |
2109 | return result; | |
2110 | } | |
2111 | ||
b775012e LM |
2112 | /* Parses a conditional described by an expression COND into an |
2113 | agent expression bytecode suitable for evaluation | |
2114 | by the bytecode interpreter. Return NULL if there was | |
2115 | any error during parsing. */ | |
2116 | ||
2117 | static struct agent_expr * | |
2118 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2119 | { | |
2120 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2121 | volatile struct gdb_exception ex; |
2122 | ||
2123 | if (!cond) | |
2124 | return NULL; | |
2125 | ||
2126 | /* We don't want to stop processing, so catch any errors | |
2127 | that may show up. */ | |
2128 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2129 | { | |
2130 | aexpr = gen_eval_for_expr (scope, cond); | |
2131 | } | |
2132 | ||
2133 | if (ex.reason < 0) | |
2134 | { | |
2135 | /* If we got here, it means the condition could not be parsed to a valid | |
2136 | bytecode expression and thus can't be evaluated on the target's side. | |
2137 | It's no use iterating through the conditions. */ | |
2138 | return NULL; | |
2139 | } | |
2140 | ||
2141 | /* We have a valid agent expression. */ | |
2142 | return aexpr; | |
2143 | } | |
2144 | ||
2145 | /* Based on location BL, create a list of breakpoint conditions to be | |
2146 | passed on to the target. If we have duplicated locations with different | |
2147 | conditions, we will add such conditions to the list. The idea is that the | |
2148 | target will evaluate the list of conditions and will only notify GDB when | |
2149 | one of them is true. */ | |
2150 | ||
2151 | static void | |
2152 | build_target_condition_list (struct bp_location *bl) | |
2153 | { | |
2154 | struct bp_location **locp = NULL, **loc2p; | |
2155 | int null_condition_or_parse_error = 0; | |
2156 | int modified = bl->needs_update; | |
2157 | struct bp_location *loc; | |
2158 | ||
8b4f3082 PA |
2159 | /* Release conditions left over from a previous insert. */ |
2160 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2161 | ||
b775012e LM |
2162 | /* This is only meaningful if the target is |
2163 | evaluating conditions and if the user has | |
2164 | opted for condition evaluation on the target's | |
2165 | side. */ | |
2166 | if (gdb_evaluates_breakpoint_condition_p () | |
2167 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2168 | return; | |
2169 | ||
2170 | /* Do a first pass to check for locations with no assigned | |
2171 | conditions or conditions that fail to parse to a valid agent expression | |
2172 | bytecode. If any of these happen, then it's no use to send conditions | |
2173 | to the target since this location will always trigger and generate a | |
2174 | response back to GDB. */ | |
2175 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2176 | { | |
2177 | loc = (*loc2p); | |
2178 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2179 | { | |
2180 | if (modified) | |
2181 | { | |
2182 | struct agent_expr *aexpr; | |
2183 | ||
2184 | /* Re-parse the conditions since something changed. In that | |
2185 | case we already freed the condition bytecodes (see | |
2186 | force_breakpoint_reinsertion). We just | |
2187 | need to parse the condition to bytecodes again. */ | |
2188 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2189 | loc->cond_bytecode = aexpr; | |
2190 | ||
2191 | /* Check if we managed to parse the conditional expression | |
2192 | correctly. If not, we will not send this condition | |
2193 | to the target. */ | |
2194 | if (aexpr) | |
2195 | continue; | |
2196 | } | |
2197 | ||
2198 | /* If we have a NULL bytecode expression, it means something | |
2199 | went wrong or we have a null condition expression. */ | |
2200 | if (!loc->cond_bytecode) | |
2201 | { | |
2202 | null_condition_or_parse_error = 1; | |
2203 | break; | |
2204 | } | |
2205 | } | |
2206 | } | |
2207 | ||
2208 | /* If any of these happened, it means we will have to evaluate the conditions | |
2209 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2210 | for all the other duplicate locations, thus we free all of them here. | |
2211 | ||
2212 | This is so we have a finer control over which locations' conditions are | |
2213 | being evaluated by GDB or the remote stub. */ | |
2214 | if (null_condition_or_parse_error) | |
2215 | { | |
2216 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2217 | { | |
2218 | loc = (*loc2p); | |
2219 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2220 | { | |
2221 | /* Only go as far as the first NULL bytecode is | |
2222 | located. */ | |
2223 | if (!loc->cond_bytecode) | |
2224 | return; | |
2225 | ||
2226 | free_agent_expr (loc->cond_bytecode); | |
2227 | loc->cond_bytecode = NULL; | |
2228 | } | |
2229 | } | |
2230 | } | |
2231 | ||
2232 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2233 | for this location's address. */ | |
2234 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2235 | { | |
2236 | loc = (*loc2p); | |
2237 | if (loc->cond | |
2238 | && is_breakpoint (loc->owner) | |
2239 | && loc->pspace->num == bl->pspace->num | |
2240 | && loc->owner->enable_state == bp_enabled | |
2241 | && loc->enabled) | |
2242 | /* Add the condition to the vector. This will be used later to send the | |
2243 | conditions to the target. */ | |
2244 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2245 | loc->cond_bytecode); | |
2246 | } | |
2247 | ||
2248 | return; | |
2249 | } | |
2250 | ||
d3ce09f5 SS |
2251 | /* Parses a command described by string CMD into an agent expression |
2252 | bytecode suitable for evaluation by the bytecode interpreter. | |
2253 | Return NULL if there was any error during parsing. */ | |
2254 | ||
2255 | static struct agent_expr * | |
2256 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2257 | { | |
2258 | struct cleanup *old_cleanups = 0; | |
2259 | struct expression *expr, **argvec; | |
2260 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2261 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2262 | const char *cmdrest; |
2263 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2264 | struct format_piece *fpieces; |
2265 | int nargs; | |
2266 | struct gdbarch *gdbarch = get_current_arch (); | |
2267 | ||
2268 | if (!cmd) | |
2269 | return NULL; | |
2270 | ||
2271 | cmdrest = cmd; | |
2272 | ||
2273 | if (*cmdrest == ',') | |
2274 | ++cmdrest; | |
bbc13ae3 | 2275 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2276 | |
2277 | if (*cmdrest++ != '"') | |
2278 | error (_("No format string following the location")); | |
2279 | ||
2280 | format_start = cmdrest; | |
2281 | ||
2282 | fpieces = parse_format_string (&cmdrest); | |
2283 | ||
2284 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2285 | ||
2286 | format_end = cmdrest; | |
2287 | ||
2288 | if (*cmdrest++ != '"') | |
2289 | error (_("Bad format string, non-terminated '\"'.")); | |
2290 | ||
bbc13ae3 | 2291 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2292 | |
2293 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2294 | error (_("Invalid argument syntax")); | |
2295 | ||
2296 | if (*cmdrest == ',') | |
2297 | cmdrest++; | |
bbc13ae3 | 2298 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2299 | |
2300 | /* For each argument, make an expression. */ | |
2301 | ||
2302 | argvec = (struct expression **) alloca (strlen (cmd) | |
2303 | * sizeof (struct expression *)); | |
2304 | ||
2305 | nargs = 0; | |
2306 | while (*cmdrest != '\0') | |
2307 | { | |
bbc13ae3 | 2308 | const char *cmd1; |
d3ce09f5 SS |
2309 | |
2310 | cmd1 = cmdrest; | |
2311 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2312 | argvec[nargs++] = expr; | |
2313 | cmdrest = cmd1; | |
2314 | if (*cmdrest == ',') | |
2315 | ++cmdrest; | |
2316 | } | |
2317 | ||
2318 | /* We don't want to stop processing, so catch any errors | |
2319 | that may show up. */ | |
2320 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2321 | { | |
2322 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2323 | format_start, format_end - format_start, | |
2324 | fpieces, nargs, argvec); | |
2325 | } | |
2326 | ||
752eb8b4 TT |
2327 | do_cleanups (old_cleanups); |
2328 | ||
d3ce09f5 SS |
2329 | if (ex.reason < 0) |
2330 | { | |
2331 | /* If we got here, it means the command could not be parsed to a valid | |
2332 | bytecode expression and thus can't be evaluated on the target's side. | |
2333 | It's no use iterating through the other commands. */ | |
2334 | return NULL; | |
2335 | } | |
2336 | ||
d3ce09f5 SS |
2337 | /* We have a valid agent expression, return it. */ |
2338 | return aexpr; | |
2339 | } | |
2340 | ||
2341 | /* Based on location BL, create a list of breakpoint commands to be | |
2342 | passed on to the target. If we have duplicated locations with | |
2343 | different commands, we will add any such to the list. */ | |
2344 | ||
2345 | static void | |
2346 | build_target_command_list (struct bp_location *bl) | |
2347 | { | |
2348 | struct bp_location **locp = NULL, **loc2p; | |
2349 | int null_command_or_parse_error = 0; | |
2350 | int modified = bl->needs_update; | |
2351 | struct bp_location *loc; | |
2352 | ||
8b4f3082 PA |
2353 | /* Release commands left over from a previous insert. */ |
2354 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2355 | ||
41fac0cf | 2356 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2357 | return; |
2358 | ||
41fac0cf PA |
2359 | /* For now, limit to agent-style dprintf breakpoints. */ |
2360 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2361 | return; |
2362 | ||
41fac0cf PA |
2363 | /* For now, if we have any duplicate location that isn't a dprintf, |
2364 | don't install the target-side commands, as that would make the | |
2365 | breakpoint not be reported to the core, and we'd lose | |
2366 | control. */ | |
2367 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2368 | { | |
2369 | loc = (*loc2p); | |
2370 | if (is_breakpoint (loc->owner) | |
2371 | && loc->pspace->num == bl->pspace->num | |
2372 | && loc->owner->type != bp_dprintf) | |
2373 | return; | |
2374 | } | |
2375 | ||
d3ce09f5 SS |
2376 | /* Do a first pass to check for locations with no assigned |
2377 | conditions or conditions that fail to parse to a valid agent expression | |
2378 | bytecode. If any of these happen, then it's no use to send conditions | |
2379 | to the target since this location will always trigger and generate a | |
2380 | response back to GDB. */ | |
2381 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2382 | { | |
2383 | loc = (*loc2p); | |
2384 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2385 | { | |
2386 | if (modified) | |
2387 | { | |
2388 | struct agent_expr *aexpr; | |
2389 | ||
2390 | /* Re-parse the commands since something changed. In that | |
2391 | case we already freed the command bytecodes (see | |
2392 | force_breakpoint_reinsertion). We just | |
2393 | need to parse the command to bytecodes again. */ | |
2394 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2395 | loc->owner->extra_string); | |
2396 | loc->cmd_bytecode = aexpr; | |
2397 | ||
2398 | if (!aexpr) | |
2399 | continue; | |
2400 | } | |
2401 | ||
2402 | /* If we have a NULL bytecode expression, it means something | |
2403 | went wrong or we have a null command expression. */ | |
2404 | if (!loc->cmd_bytecode) | |
2405 | { | |
2406 | null_command_or_parse_error = 1; | |
2407 | break; | |
2408 | } | |
2409 | } | |
2410 | } | |
2411 | ||
2412 | /* If anything failed, then we're not doing target-side commands, | |
2413 | and so clean up. */ | |
2414 | if (null_command_or_parse_error) | |
2415 | { | |
2416 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2417 | { | |
2418 | loc = (*loc2p); | |
2419 | if (is_breakpoint (loc->owner) | |
2420 | && loc->pspace->num == bl->pspace->num) | |
2421 | { | |
2422 | /* Only go as far as the first NULL bytecode is | |
2423 | located. */ | |
40fb6c5e | 2424 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2425 | return; |
2426 | ||
40fb6c5e HZ |
2427 | free_agent_expr (loc->cmd_bytecode); |
2428 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2429 | } |
2430 | } | |
2431 | } | |
2432 | ||
2433 | /* No NULL commands or failed bytecode generation. Build a command list | |
2434 | for this location's address. */ | |
2435 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2436 | { | |
2437 | loc = (*loc2p); | |
2438 | if (loc->owner->extra_string | |
2439 | && is_breakpoint (loc->owner) | |
2440 | && loc->pspace->num == bl->pspace->num | |
2441 | && loc->owner->enable_state == bp_enabled | |
2442 | && loc->enabled) | |
2443 | /* Add the command to the vector. This will be used later | |
2444 | to send the commands to the target. */ | |
2445 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2446 | loc->cmd_bytecode); | |
2447 | } | |
2448 | ||
2449 | bl->target_info.persist = 0; | |
2450 | /* Maybe flag this location as persistent. */ | |
2451 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2452 | bl->target_info.persist = 1; | |
2453 | } | |
2454 | ||
35df4500 TJB |
2455 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2456 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2457 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2458 | Returns 0 for success, 1 if the bp_location type is not supported or |
2459 | -1 for failure. | |
879bfdc2 | 2460 | |
4a64f543 MS |
2461 | NOTE drow/2003-09-09: This routine could be broken down to an |
2462 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2463 | static int |
35df4500 | 2464 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2465 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2466 | int *disabled_breaks, |
dd61ec5c MW |
2467 | int *hw_breakpoint_error, |
2468 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2469 | { |
0000e5cc PA |
2470 | enum errors bp_err = GDB_NO_ERROR; |
2471 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2472 | volatile struct gdb_exception e; |
879bfdc2 | 2473 | |
b775012e | 2474 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2475 | return 0; |
2476 | ||
35c63cd8 JB |
2477 | /* Note we don't initialize bl->target_info, as that wipes out |
2478 | the breakpoint location's shadow_contents if the breakpoint | |
2479 | is still inserted at that location. This in turn breaks | |
2480 | target_read_memory which depends on these buffers when | |
2481 | a memory read is requested at the breakpoint location: | |
2482 | Once the target_info has been wiped, we fail to see that | |
2483 | we have a breakpoint inserted at that address and thus | |
2484 | read the breakpoint instead of returning the data saved in | |
2485 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2486 | bl->target_info.placed_address = bl->address; |
2487 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2488 | bl->target_info.length = bl->length; |
8181d85f | 2489 | |
b775012e LM |
2490 | /* When working with target-side conditions, we must pass all the conditions |
2491 | for the same breakpoint address down to the target since GDB will not | |
2492 | insert those locations. With a list of breakpoint conditions, the target | |
2493 | can decide when to stop and notify GDB. */ | |
2494 | ||
2495 | if (is_breakpoint (bl->owner)) | |
2496 | { | |
2497 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2498 | build_target_command_list (bl); |
2499 | /* Reset the modification marker. */ | |
b775012e LM |
2500 | bl->needs_update = 0; |
2501 | } | |
2502 | ||
35df4500 TJB |
2503 | if (bl->loc_type == bp_loc_software_breakpoint |
2504 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2505 | { |
35df4500 | 2506 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2507 | { |
2508 | /* If the explicitly specified breakpoint type | |
2509 | is not hardware breakpoint, check the memory map to see | |
2510 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2511 | |
765dc015 VP |
2512 | Two important cases are: |
2513 | - location type is not hardware breakpoint, memory | |
2514 | is readonly. We change the type of the location to | |
2515 | hardware breakpoint. | |
4a64f543 MS |
2516 | - location type is hardware breakpoint, memory is |
2517 | read-write. This means we've previously made the | |
2518 | location hardware one, but then the memory map changed, | |
2519 | so we undo. | |
765dc015 | 2520 | |
4a64f543 MS |
2521 | When breakpoints are removed, remove_breakpoints will use |
2522 | location types we've just set here, the only possible | |
2523 | problem is that memory map has changed during running | |
2524 | program, but it's not going to work anyway with current | |
2525 | gdb. */ | |
765dc015 | 2526 | struct mem_region *mr |
35df4500 | 2527 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2528 | |
2529 | if (mr) | |
2530 | { | |
2531 | if (automatic_hardware_breakpoints) | |
2532 | { | |
765dc015 VP |
2533 | enum bp_loc_type new_type; |
2534 | ||
2535 | if (mr->attrib.mode != MEM_RW) | |
2536 | new_type = bp_loc_hardware_breakpoint; | |
2537 | else | |
2538 | new_type = bp_loc_software_breakpoint; | |
2539 | ||
35df4500 | 2540 | if (new_type != bl->loc_type) |
765dc015 VP |
2541 | { |
2542 | static int said = 0; | |
cc59ec59 | 2543 | |
35df4500 | 2544 | bl->loc_type = new_type; |
765dc015 VP |
2545 | if (!said) |
2546 | { | |
3e43a32a MS |
2547 | fprintf_filtered (gdb_stdout, |
2548 | _("Note: automatically using " | |
2549 | "hardware breakpoints for " | |
2550 | "read-only addresses.\n")); | |
765dc015 VP |
2551 | said = 1; |
2552 | } | |
2553 | } | |
2554 | } | |
35df4500 | 2555 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2556 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2557 | warning (_("cannot set software breakpoint " |
2558 | "at readonly address %s"), | |
35df4500 | 2559 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2560 | } |
2561 | } | |
2562 | ||
879bfdc2 DJ |
2563 | /* First check to see if we have to handle an overlay. */ |
2564 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2565 | || bl->section == NULL |
2566 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2567 | { |
2568 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2569 | TRY_CATCH (e, RETURN_MASK_ALL) |
2570 | { | |
0000e5cc PA |
2571 | int val; |
2572 | ||
dd61ec5c | 2573 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2574 | if (val) |
2575 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2576 | } |
2577 | if (e.reason < 0) | |
2578 | { | |
0000e5cc PA |
2579 | bp_err = e.error; |
2580 | bp_err_message = e.message; | |
dd61ec5c | 2581 | } |
879bfdc2 DJ |
2582 | } |
2583 | else | |
2584 | { | |
4a64f543 | 2585 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2586 | Shall we set a breakpoint at the LMA? */ |
2587 | if (!overlay_events_enabled) | |
2588 | { | |
2589 | /* Yes -- overlay event support is not active, | |
2590 | so we must try to set a breakpoint at the LMA. | |
2591 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2592 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2593 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2594 | bl->owner->number); |
879bfdc2 DJ |
2595 | else |
2596 | { | |
35df4500 TJB |
2597 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2598 | bl->section); | |
879bfdc2 | 2599 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2600 | bl->overlay_target_info = bl->target_info; |
2601 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2602 | |
2603 | /* No overlay handling: just set the breakpoint. */ | |
2604 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2605 | { | |
2606 | int val; | |
2607 | ||
2608 | val = target_insert_breakpoint (bl->gdbarch, | |
2609 | &bl->overlay_target_info); | |
2610 | if (val) | |
2611 | bp_err = GENERIC_ERROR; | |
2612 | } | |
2613 | if (e.reason < 0) | |
2614 | { | |
2615 | bp_err = e.error; | |
2616 | bp_err_message = e.message; | |
2617 | } | |
2618 | ||
2619 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2620 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2621 | "Overlay breakpoint %d " |
2622 | "failed: in ROM?\n", | |
35df4500 | 2623 | bl->owner->number); |
879bfdc2 DJ |
2624 | } |
2625 | } | |
2626 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2627 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2628 | { |
2629 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2630 | TRY_CATCH (e, RETURN_MASK_ALL) |
2631 | { | |
0000e5cc PA |
2632 | int val; |
2633 | ||
dd61ec5c | 2634 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2635 | if (val) |
2636 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2637 | } |
2638 | if (e.reason < 0) | |
2639 | { | |
0000e5cc PA |
2640 | bp_err = e.error; |
2641 | bp_err_message = e.message; | |
dd61ec5c | 2642 | } |
879bfdc2 DJ |
2643 | } |
2644 | else | |
2645 | { | |
2646 | /* No. This breakpoint will not be inserted. | |
2647 | No error, but do not mark the bp as 'inserted'. */ | |
2648 | return 0; | |
2649 | } | |
2650 | } | |
2651 | ||
0000e5cc | 2652 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2653 | { |
2654 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2655 | |
2656 | /* In some cases, we might not be able to insert a | |
2657 | breakpoint in a shared library that has already been | |
2658 | removed, but we have not yet processed the shlib unload | |
2659 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2660 | breakpoint insertion themselves can't tell why the |
2661 | breakpoint insertion failed (e.g., the remote target | |
2662 | doesn't define error codes), so we must treat generic | |
2663 | errors as memory errors. */ | |
0000e5cc | 2664 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2665 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2666 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2667 | || shared_objfile_contains_address_p (bl->pspace, |
2668 | bl->address))) | |
879bfdc2 | 2669 | { |
4a64f543 | 2670 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2671 | bl->shlib_disabled = 1; |
8d3788bd | 2672 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2673 | if (!*disabled_breaks) |
2674 | { | |
2675 | fprintf_unfiltered (tmp_error_stream, | |
2676 | "Cannot insert breakpoint %d.\n", | |
2677 | bl->owner->number); | |
2678 | fprintf_unfiltered (tmp_error_stream, | |
2679 | "Temporarily disabling shared " | |
2680 | "library breakpoints:\n"); | |
2681 | } | |
2682 | *disabled_breaks = 1; | |
879bfdc2 | 2683 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2684 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2685 | return 0; |
879bfdc2 DJ |
2686 | } |
2687 | else | |
879bfdc2 | 2688 | { |
35df4500 | 2689 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2690 | { |
0000e5cc PA |
2691 | *hw_breakpoint_error = 1; |
2692 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2693 | fprintf_unfiltered (tmp_error_stream, |
2694 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2695 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2696 | if (bp_err_message != NULL) | |
2697 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2698 | } |
2699 | else | |
2700 | { | |
0000e5cc PA |
2701 | if (bp_err_message == NULL) |
2702 | { | |
2703 | char *message | |
2704 | = memory_error_message (TARGET_XFER_E_IO, | |
2705 | bl->gdbarch, bl->address); | |
2706 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2707 | ||
2708 | fprintf_unfiltered (tmp_error_stream, | |
2709 | "Cannot insert breakpoint %d.\n" | |
2710 | "%s\n", | |
2711 | bl->owner->number, message); | |
2712 | do_cleanups (old_chain); | |
2713 | } | |
2714 | else | |
2715 | { | |
2716 | fprintf_unfiltered (tmp_error_stream, | |
2717 | "Cannot insert breakpoint %d: %s\n", | |
2718 | bl->owner->number, | |
2719 | bp_err_message); | |
2720 | } | |
879bfdc2 | 2721 | } |
0000e5cc | 2722 | return 1; |
879bfdc2 DJ |
2723 | |
2724 | } | |
2725 | } | |
2726 | else | |
35df4500 | 2727 | bl->inserted = 1; |
879bfdc2 | 2728 | |
0000e5cc | 2729 | return 0; |
879bfdc2 DJ |
2730 | } |
2731 | ||
35df4500 | 2732 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2733 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2734 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2735 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2736 | { |
0000e5cc PA |
2737 | int val; |
2738 | ||
77b06cd7 TJB |
2739 | gdb_assert (bl->owner->ops != NULL |
2740 | && bl->owner->ops->insert_location != NULL); | |
2741 | ||
2742 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2743 | |
2744 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2745 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2746 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2747 | { |
2748 | struct bp_location *loc, **loc_temp; | |
2749 | ||
2750 | /* But don't try to insert it, if there's already another | |
2751 | hw_access location that would be considered a duplicate | |
2752 | of this one. */ | |
2753 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2754 | if (loc != bl |
85d721b8 | 2755 | && loc->watchpoint_type == hw_access |
35df4500 | 2756 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2757 | { |
35df4500 TJB |
2758 | bl->duplicate = 1; |
2759 | bl->inserted = 1; | |
2760 | bl->target_info = loc->target_info; | |
2761 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2762 | val = 0; |
2763 | break; | |
2764 | } | |
2765 | ||
2766 | if (val == 1) | |
2767 | { | |
77b06cd7 TJB |
2768 | bl->watchpoint_type = hw_access; |
2769 | val = bl->owner->ops->insert_location (bl); | |
2770 | ||
2771 | if (val) | |
2772 | /* Back to the original value. */ | |
2773 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2774 | } |
2775 | } | |
2776 | ||
35df4500 | 2777 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2778 | } |
2779 | ||
35df4500 | 2780 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2781 | { |
0000e5cc PA |
2782 | int val; |
2783 | ||
77b06cd7 TJB |
2784 | gdb_assert (bl->owner->ops != NULL |
2785 | && bl->owner->ops->insert_location != NULL); | |
2786 | ||
2787 | val = bl->owner->ops->insert_location (bl); | |
2788 | if (val) | |
2789 | { | |
2790 | bl->owner->enable_state = bp_disabled; | |
2791 | ||
2792 | if (val == 1) | |
2793 | warning (_("\ | |
2794 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2795 | of catchpoint."), bl->owner->number); | |
2796 | else | |
2797 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2798 | } | |
2799 | ||
2800 | bl->inserted = (val == 0); | |
1640b821 DJ |
2801 | |
2802 | /* We've already printed an error message if there was a problem | |
2803 | inserting this catchpoint, and we've disabled the catchpoint, | |
2804 | so just return success. */ | |
2805 | return 0; | |
879bfdc2 DJ |
2806 | } |
2807 | ||
2808 | return 0; | |
2809 | } | |
2810 | ||
6c95b8df PA |
2811 | /* This function is called when program space PSPACE is about to be |
2812 | deleted. It takes care of updating breakpoints to not reference | |
2813 | PSPACE anymore. */ | |
2814 | ||
2815 | void | |
2816 | breakpoint_program_space_exit (struct program_space *pspace) | |
2817 | { | |
2818 | struct breakpoint *b, *b_temp; | |
876fa593 | 2819 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2820 | |
2821 | /* Remove any breakpoint that was set through this program space. */ | |
2822 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2823 | { | |
2824 | if (b->pspace == pspace) | |
2825 | delete_breakpoint (b); | |
2826 | } | |
2827 | ||
2828 | /* Breakpoints set through other program spaces could have locations | |
2829 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2830 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2831 | { |
2832 | struct bp_location *tmp; | |
2833 | ||
2834 | if (loc->pspace == pspace) | |
2835 | { | |
2bdf28a0 | 2836 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2837 | if (loc->owner->loc == loc) |
2838 | loc->owner->loc = loc->next; | |
2839 | else | |
2840 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2841 | if (tmp->next == loc) | |
2842 | { | |
2843 | tmp->next = loc->next; | |
2844 | break; | |
2845 | } | |
2846 | } | |
2847 | } | |
2848 | ||
2849 | /* Now update the global location list to permanently delete the | |
2850 | removed locations above. */ | |
2851 | update_global_location_list (0); | |
2852 | } | |
2853 | ||
74960c60 VP |
2854 | /* Make sure all breakpoints are inserted in inferior. |
2855 | Throws exception on any error. | |
2856 | A breakpoint that is already inserted won't be inserted | |
2857 | again, so calling this function twice is safe. */ | |
2858 | void | |
2859 | insert_breakpoints (void) | |
2860 | { | |
2861 | struct breakpoint *bpt; | |
2862 | ||
2863 | ALL_BREAKPOINTS (bpt) | |
2864 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2865 | { |
2866 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2867 | ||
2868 | update_watchpoint (w, 0 /* don't reparse. */); | |
2869 | } | |
74960c60 | 2870 | |
b60e7edf | 2871 | update_global_location_list (1); |
74960c60 | 2872 | |
c35b1492 PA |
2873 | /* update_global_location_list does not insert breakpoints when |
2874 | always_inserted_mode is not enabled. Explicitly insert them | |
2875 | now. */ | |
2876 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2877 | insert_breakpoint_locations (); |
2878 | } | |
2879 | ||
20388dd6 YQ |
2880 | /* Invoke CALLBACK for each of bp_location. */ |
2881 | ||
2882 | void | |
2883 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2884 | { | |
2885 | struct bp_location *loc, **loc_tmp; | |
2886 | ||
2887 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2888 | { | |
2889 | callback (loc, NULL); | |
2890 | } | |
2891 | } | |
2892 | ||
b775012e LM |
2893 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2894 | target. It is the case with deleting and disabling of breakpoints when using | |
2895 | always-inserted mode. */ | |
2896 | ||
2897 | static void | |
2898 | update_inserted_breakpoint_locations (void) | |
2899 | { | |
2900 | struct bp_location *bl, **blp_tmp; | |
2901 | int error_flag = 0; | |
2902 | int val = 0; | |
2903 | int disabled_breaks = 0; | |
2904 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2905 | int hw_bp_details_reported = 0; |
b775012e LM |
2906 | |
2907 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2908 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2909 | ||
2910 | /* Explicitly mark the warning -- this will only be printed if | |
2911 | there was an error. */ | |
2912 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2913 | ||
2914 | save_current_space_and_thread (); | |
2915 | ||
2916 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2917 | { | |
2918 | /* We only want to update software breakpoints and hardware | |
2919 | breakpoints. */ | |
2920 | if (!is_breakpoint (bl->owner)) | |
2921 | continue; | |
2922 | ||
2923 | /* We only want to update locations that are already inserted | |
2924 | and need updating. This is to avoid unwanted insertion during | |
2925 | deletion of breakpoints. */ | |
2926 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2927 | continue; | |
2928 | ||
2929 | switch_to_program_space_and_thread (bl->pspace); | |
2930 | ||
2931 | /* For targets that support global breakpoints, there's no need | |
2932 | to select an inferior to insert breakpoint to. In fact, even | |
2933 | if we aren't attached to any process yet, we should still | |
2934 | insert breakpoints. */ | |
f5656ead | 2935 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2936 | && ptid_equal (inferior_ptid, null_ptid)) |
2937 | continue; | |
2938 | ||
2939 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2940 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2941 | if (val) |
2942 | error_flag = val; | |
2943 | } | |
2944 | ||
2945 | if (error_flag) | |
2946 | { | |
2947 | target_terminal_ours_for_output (); | |
2948 | error_stream (tmp_error_stream); | |
2949 | } | |
2950 | ||
2951 | do_cleanups (cleanups); | |
2952 | } | |
2953 | ||
c30eee59 | 2954 | /* Used when starting or continuing the program. */ |
c906108c | 2955 | |
74960c60 VP |
2956 | static void |
2957 | insert_breakpoint_locations (void) | |
c906108c | 2958 | { |
a5606eee | 2959 | struct breakpoint *bpt; |
35df4500 | 2960 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2961 | int error_flag = 0; |
c906108c | 2962 | int val = 0; |
3fbb6ffa | 2963 | int disabled_breaks = 0; |
81d0cc19 | 2964 | int hw_breakpoint_error = 0; |
dd61ec5c | 2965 | int hw_bp_error_explained_already = 0; |
c906108c | 2966 | |
81d0cc19 | 2967 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2968 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2969 | |
81d0cc19 GS |
2970 | /* Explicitly mark the warning -- this will only be printed if |
2971 | there was an error. */ | |
2972 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2973 | |
2974 | save_current_space_and_thread (); | |
2975 | ||
35df4500 | 2976 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2977 | { |
b775012e | 2978 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2979 | continue; |
2980 | ||
4a64f543 MS |
2981 | /* There is no point inserting thread-specific breakpoints if |
2982 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2983 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2984 | if (bl->owner->thread != -1 |
2985 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2986 | continue; |
2987 | ||
35df4500 | 2988 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2989 | |
2990 | /* For targets that support global breakpoints, there's no need | |
2991 | to select an inferior to insert breakpoint to. In fact, even | |
2992 | if we aren't attached to any process yet, we should still | |
2993 | insert breakpoints. */ | |
f5656ead | 2994 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2995 | && ptid_equal (inferior_ptid, null_ptid)) |
2996 | continue; | |
2997 | ||
3fbb6ffa | 2998 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2999 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3000 | if (val) |
eacd795a | 3001 | error_flag = val; |
879bfdc2 | 3002 | } |
c906108c | 3003 | |
4a64f543 MS |
3004 | /* If we failed to insert all locations of a watchpoint, remove |
3005 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3006 | ALL_BREAKPOINTS (bpt) |
3007 | { | |
3008 | int some_failed = 0; | |
3009 | struct bp_location *loc; | |
3010 | ||
3011 | if (!is_hardware_watchpoint (bpt)) | |
3012 | continue; | |
3013 | ||
d6b74ac4 | 3014 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3015 | continue; |
74960c60 VP |
3016 | |
3017 | if (bpt->disposition == disp_del_at_next_stop) | |
3018 | continue; | |
a5606eee VP |
3019 | |
3020 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3021 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3022 | { |
3023 | some_failed = 1; | |
3024 | break; | |
3025 | } | |
3026 | if (some_failed) | |
3027 | { | |
3028 | for (loc = bpt->loc; loc; loc = loc->next) | |
3029 | if (loc->inserted) | |
3030 | remove_breakpoint (loc, mark_uninserted); | |
3031 | ||
3032 | hw_breakpoint_error = 1; | |
3033 | fprintf_unfiltered (tmp_error_stream, | |
3034 | "Could not insert hardware watchpoint %d.\n", | |
3035 | bpt->number); | |
eacd795a | 3036 | error_flag = -1; |
a5606eee VP |
3037 | } |
3038 | } | |
3039 | ||
eacd795a | 3040 | if (error_flag) |
81d0cc19 GS |
3041 | { |
3042 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3043 | message about possibly exhausted resources. */ | |
dd61ec5c | 3044 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3045 | { |
c6510018 MS |
3046 | fprintf_unfiltered (tmp_error_stream, |
3047 | "Could not insert hardware breakpoints:\n\ | |
3048 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3049 | } |
81d0cc19 GS |
3050 | target_terminal_ours_for_output (); |
3051 | error_stream (tmp_error_stream); | |
3052 | } | |
f7545552 TT |
3053 | |
3054 | do_cleanups (cleanups); | |
c906108c SS |
3055 | } |
3056 | ||
c30eee59 TJB |
3057 | /* Used when the program stops. |
3058 | Returns zero if successful, or non-zero if there was a problem | |
3059 | removing a breakpoint location. */ | |
3060 | ||
c906108c | 3061 | int |
fba45db2 | 3062 | remove_breakpoints (void) |
c906108c | 3063 | { |
35df4500 | 3064 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3065 | int val = 0; |
c906108c | 3066 | |
35df4500 | 3067 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3068 | { |
1e4d1764 | 3069 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3070 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3071 | } |
3a1bae8e | 3072 | return val; |
c906108c SS |
3073 | } |
3074 | ||
49fa26b0 PA |
3075 | /* When a thread exits, remove breakpoints that are related to |
3076 | that thread. */ | |
3077 | ||
3078 | static void | |
3079 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3080 | { | |
3081 | struct breakpoint *b, *b_tmp; | |
3082 | ||
3083 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3084 | { | |
96181529 | 3085 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3086 | { |
3087 | b->disposition = disp_del_at_next_stop; | |
3088 | ||
3089 | printf_filtered (_("\ | |
46ecd527 | 3090 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3091 | b->number, tp->num); |
3092 | ||
3093 | /* Hide it from the user. */ | |
3094 | b->number = 0; | |
3095 | } | |
3096 | } | |
3097 | } | |
3098 | ||
6c95b8df PA |
3099 | /* Remove breakpoints of process PID. */ |
3100 | ||
3101 | int | |
3102 | remove_breakpoints_pid (int pid) | |
3103 | { | |
35df4500 | 3104 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3105 | int val; |
3106 | struct inferior *inf = find_inferior_pid (pid); | |
3107 | ||
35df4500 | 3108 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3109 | { |
35df4500 | 3110 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3111 | continue; |
3112 | ||
d3ce09f5 SS |
3113 | if (bl->owner->type == bp_dprintf) |
3114 | continue; | |
3115 | ||
35df4500 | 3116 | if (bl->inserted) |
6c95b8df | 3117 | { |
35df4500 | 3118 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3119 | if (val != 0) |
3120 | return val; | |
3121 | } | |
3122 | } | |
3123 | return 0; | |
3124 | } | |
3125 | ||
c906108c | 3126 | int |
fba45db2 | 3127 | reattach_breakpoints (int pid) |
c906108c | 3128 | { |
6c95b8df | 3129 | struct cleanup *old_chain; |
35df4500 | 3130 | struct bp_location *bl, **blp_tmp; |
c906108c | 3131 | int val; |
86b887df | 3132 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3133 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3134 | struct inferior *inf; |
3135 | struct thread_info *tp; | |
3136 | ||
3137 | tp = any_live_thread_of_process (pid); | |
3138 | if (tp == NULL) | |
3139 | return 1; | |
3140 | ||
3141 | inf = find_inferior_pid (pid); | |
3142 | old_chain = save_inferior_ptid (); | |
3143 | ||
3144 | inferior_ptid = tp->ptid; | |
a4954f26 | 3145 | |
86b887df | 3146 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3147 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3148 | |
35df4500 | 3149 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3150 | { |
35df4500 | 3151 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3152 | continue; |
3153 | ||
35df4500 | 3154 | if (bl->inserted) |
c5aa993b | 3155 | { |
35df4500 | 3156 | bl->inserted = 0; |
dd61ec5c | 3157 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3158 | if (val != 0) |
3159 | { | |
ce696e05 | 3160 | do_cleanups (old_chain); |
c5aa993b JM |
3161 | return val; |
3162 | } | |
3163 | } | |
3164 | } | |
ce696e05 | 3165 | do_cleanups (old_chain); |
c906108c SS |
3166 | return 0; |
3167 | } | |
3168 | ||
e58b0e63 PA |
3169 | static int internal_breakpoint_number = -1; |
3170 | ||
84f4c1fe PM |
3171 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3172 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3173 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3174 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3175 | breakpoint_count and that value incremented. Internal breakpoints |
3176 | do not set the internal var bpnum. */ | |
3177 | static void | |
3178 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3179 | { | |
3180 | if (internal) | |
3181 | b->number = internal_breakpoint_number--; | |
3182 | else | |
3183 | { | |
3184 | set_breakpoint_count (breakpoint_count + 1); | |
3185 | b->number = breakpoint_count; | |
3186 | } | |
3187 | } | |
3188 | ||
e62c965a | 3189 | static struct breakpoint * |
a6d9a66e | 3190 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3191 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3192 | const struct breakpoint_ops *ops) |
e62c965a | 3193 | { |
e62c965a PP |
3194 | struct symtab_and_line sal; |
3195 | struct breakpoint *b; | |
3196 | ||
4a64f543 | 3197 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3198 | |
3199 | sal.pc = address; | |
3200 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3201 | sal.pspace = current_program_space; |
e62c965a | 3202 | |
06edf0c0 | 3203 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3204 | b->number = internal_breakpoint_number--; |
3205 | b->disposition = disp_donttouch; | |
3206 | ||
3207 | return b; | |
3208 | } | |
3209 | ||
17450429 PP |
3210 | static const char *const longjmp_names[] = |
3211 | { | |
3212 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3213 | }; | |
3214 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3215 | ||
3216 | /* Per-objfile data private to breakpoint.c. */ | |
3217 | struct breakpoint_objfile_data | |
3218 | { | |
3219 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3220 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3221 | |
3222 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3223 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3224 | |
28106bc2 SDJ |
3225 | /* True if we have looked for longjmp probes. */ |
3226 | int longjmp_searched; | |
3227 | ||
3228 | /* SystemTap probe points for longjmp (if any). */ | |
3229 | VEC (probe_p) *longjmp_probes; | |
3230 | ||
17450429 | 3231 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3232 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3233 | |
3234 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3235 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3236 | |
3237 | /* True if we have looked for exception probes. */ | |
3238 | int exception_searched; | |
3239 | ||
3240 | /* SystemTap probe points for unwinding (if any). */ | |
3241 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3242 | }; |
3243 | ||
3244 | static const struct objfile_data *breakpoint_objfile_key; | |
3245 | ||
3246 | /* Minimal symbol not found sentinel. */ | |
3247 | static struct minimal_symbol msym_not_found; | |
3248 | ||
3249 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3250 | ||
3251 | static int | |
3252 | msym_not_found_p (const struct minimal_symbol *msym) | |
3253 | { | |
3254 | return msym == &msym_not_found; | |
3255 | } | |
3256 | ||
3257 | /* Return per-objfile data needed by breakpoint.c. | |
3258 | Allocate the data if necessary. */ | |
3259 | ||
3260 | static struct breakpoint_objfile_data * | |
3261 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3262 | { | |
3263 | struct breakpoint_objfile_data *bp_objfile_data; | |
3264 | ||
3265 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3266 | if (bp_objfile_data == NULL) | |
3267 | { | |
3268 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3269 | sizeof (*bp_objfile_data)); | |
3270 | ||
3271 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3272 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3273 | } | |
3274 | return bp_objfile_data; | |
3275 | } | |
3276 | ||
28106bc2 SDJ |
3277 | static void |
3278 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3279 | { | |
3280 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3281 | ||
3282 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3283 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3284 | } | |
3285 | ||
e62c965a | 3286 | static void |
af02033e | 3287 | create_overlay_event_breakpoint (void) |
e62c965a | 3288 | { |
69de3c6a | 3289 | struct objfile *objfile; |
af02033e | 3290 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3291 | |
69de3c6a PP |
3292 | ALL_OBJFILES (objfile) |
3293 | { | |
3294 | struct breakpoint *b; | |
17450429 PP |
3295 | struct breakpoint_objfile_data *bp_objfile_data; |
3296 | CORE_ADDR addr; | |
69de3c6a | 3297 | |
17450429 PP |
3298 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3299 | ||
3b7344d5 | 3300 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3301 | continue; |
3302 | ||
3b7344d5 | 3303 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3304 | { |
3b7344d5 | 3305 | struct bound_minimal_symbol m; |
17450429 PP |
3306 | |
3307 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3308 | if (m.minsym == NULL) |
17450429 PP |
3309 | { |
3310 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3311 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3312 | continue; |
3313 | } | |
3314 | bp_objfile_data->overlay_msym = m; | |
3315 | } | |
e62c965a | 3316 | |
77e371c0 | 3317 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3318 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3319 | bp_overlay_event, |
3320 | &internal_breakpoint_ops); | |
69de3c6a | 3321 | b->addr_string = xstrdup (func_name); |
e62c965a | 3322 | |
69de3c6a PP |
3323 | if (overlay_debugging == ovly_auto) |
3324 | { | |
3325 | b->enable_state = bp_enabled; | |
3326 | overlay_events_enabled = 1; | |
3327 | } | |
3328 | else | |
3329 | { | |
3330 | b->enable_state = bp_disabled; | |
3331 | overlay_events_enabled = 0; | |
3332 | } | |
e62c965a PP |
3333 | } |
3334 | update_global_location_list (1); | |
3335 | } | |
3336 | ||
0fd8e87f | 3337 | static void |
af02033e | 3338 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3339 | { |
6c95b8df | 3340 | struct program_space *pspace; |
6c95b8df PA |
3341 | struct cleanup *old_chain; |
3342 | ||
3343 | old_chain = save_current_program_space (); | |
0fd8e87f | 3344 | |
6c95b8df | 3345 | ALL_PSPACES (pspace) |
af02033e PP |
3346 | { |
3347 | struct objfile *objfile; | |
3348 | ||
3349 | set_current_program_space (pspace); | |
3350 | ||
3351 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3352 | { |
af02033e PP |
3353 | int i; |
3354 | struct gdbarch *gdbarch; | |
17450429 | 3355 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3356 | |
af02033e | 3357 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3358 | |
17450429 PP |
3359 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3360 | ||
28106bc2 SDJ |
3361 | if (!bp_objfile_data->longjmp_searched) |
3362 | { | |
25f9533e SDJ |
3363 | VEC (probe_p) *ret; |
3364 | ||
3365 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3366 | if (ret != NULL) | |
3367 | { | |
3368 | /* We are only interested in checking one element. */ | |
3369 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3370 | ||
3371 | if (!can_evaluate_probe_arguments (p)) | |
3372 | { | |
3373 | /* We cannot use the probe interface here, because it does | |
3374 | not know how to evaluate arguments. */ | |
3375 | VEC_free (probe_p, ret); | |
3376 | ret = NULL; | |
3377 | } | |
3378 | } | |
3379 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3380 | bp_objfile_data->longjmp_searched = 1; |
3381 | } | |
3382 | ||
3383 | if (bp_objfile_data->longjmp_probes != NULL) | |
3384 | { | |
3385 | int i; | |
3386 | struct probe *probe; | |
3387 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3388 | ||
3389 | for (i = 0; | |
3390 | VEC_iterate (probe_p, | |
3391 | bp_objfile_data->longjmp_probes, | |
3392 | i, probe); | |
3393 | ++i) | |
3394 | { | |
3395 | struct breakpoint *b; | |
3396 | ||
729662a5 TT |
3397 | b = create_internal_breakpoint (gdbarch, |
3398 | get_probe_address (probe, | |
3399 | objfile), | |
28106bc2 SDJ |
3400 | bp_longjmp_master, |
3401 | &internal_breakpoint_ops); | |
3402 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3403 | b->enable_state = bp_disabled; | |
3404 | } | |
3405 | ||
3406 | continue; | |
3407 | } | |
3408 | ||
0569175e TSD |
3409 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3410 | continue; | |
3411 | ||
17450429 | 3412 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3413 | { |
3414 | struct breakpoint *b; | |
af02033e | 3415 | const char *func_name; |
17450429 | 3416 | CORE_ADDR addr; |
6c95b8df | 3417 | |
3b7344d5 | 3418 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3419 | continue; |
0fd8e87f | 3420 | |
17450429 | 3421 | func_name = longjmp_names[i]; |
3b7344d5 | 3422 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3423 | { |
3b7344d5 | 3424 | struct bound_minimal_symbol m; |
17450429 PP |
3425 | |
3426 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3427 | if (m.minsym == NULL) |
17450429 PP |
3428 | { |
3429 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3430 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3431 | continue; |
3432 | } | |
3433 | bp_objfile_data->longjmp_msym[i] = m; | |
3434 | } | |
3435 | ||
77e371c0 | 3436 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3437 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3438 | &internal_breakpoint_ops); | |
af02033e PP |
3439 | b->addr_string = xstrdup (func_name); |
3440 | b->enable_state = bp_disabled; | |
3441 | } | |
0fd8e87f | 3442 | } |
af02033e | 3443 | } |
0fd8e87f | 3444 | update_global_location_list (1); |
6c95b8df PA |
3445 | |
3446 | do_cleanups (old_chain); | |
0fd8e87f UW |
3447 | } |
3448 | ||
af02033e | 3449 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3450 | static void |
af02033e | 3451 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3452 | { |
3453 | struct program_space *pspace; | |
aa7d318d | 3454 | struct cleanup *old_chain; |
af02033e | 3455 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3456 | |
3457 | old_chain = save_current_program_space (); | |
3458 | ||
3459 | ALL_PSPACES (pspace) | |
17450429 PP |
3460 | { |
3461 | struct objfile *objfile; | |
3462 | CORE_ADDR addr; | |
3463 | ||
3464 | set_current_program_space (pspace); | |
3465 | ||
aa7d318d TT |
3466 | ALL_OBJFILES (objfile) |
3467 | { | |
3468 | struct breakpoint *b; | |
17450429 | 3469 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3470 | |
17450429 | 3471 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3472 | |
3b7344d5 | 3473 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3474 | continue; |
3475 | ||
3b7344d5 | 3476 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3477 | { |
3b7344d5 | 3478 | struct bound_minimal_symbol m; |
17450429 PP |
3479 | |
3480 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3481 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3482 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3483 | { |
3484 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3485 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3486 | continue; |
3487 | } | |
3488 | bp_objfile_data->terminate_msym = m; | |
3489 | } | |
aa7d318d | 3490 | |
77e371c0 | 3491 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3492 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3493 | bp_std_terminate_master, |
3494 | &internal_breakpoint_ops); | |
aa7d318d TT |
3495 | b->addr_string = xstrdup (func_name); |
3496 | b->enable_state = bp_disabled; | |
3497 | } | |
17450429 PP |
3498 | } |
3499 | ||
aa7d318d TT |
3500 | update_global_location_list (1); |
3501 | ||
3502 | do_cleanups (old_chain); | |
3503 | } | |
3504 | ||
186c406b TT |
3505 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3506 | ||
70221824 | 3507 | static void |
186c406b TT |
3508 | create_exception_master_breakpoint (void) |
3509 | { | |
3510 | struct objfile *objfile; | |
17450429 | 3511 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3512 | |
3513 | ALL_OBJFILES (objfile) | |
3514 | { | |
17450429 PP |
3515 | struct breakpoint *b; |
3516 | struct gdbarch *gdbarch; | |
3517 | struct breakpoint_objfile_data *bp_objfile_data; | |
3518 | CORE_ADDR addr; | |
3519 | ||
3520 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3521 | ||
28106bc2 SDJ |
3522 | /* We prefer the SystemTap probe point if it exists. */ |
3523 | if (!bp_objfile_data->exception_searched) | |
3524 | { | |
25f9533e SDJ |
3525 | VEC (probe_p) *ret; |
3526 | ||
3527 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3528 | ||
3529 | if (ret != NULL) | |
3530 | { | |
3531 | /* We are only interested in checking one element. */ | |
3532 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3533 | ||
3534 | if (!can_evaluate_probe_arguments (p)) | |
3535 | { | |
3536 | /* We cannot use the probe interface here, because it does | |
3537 | not know how to evaluate arguments. */ | |
3538 | VEC_free (probe_p, ret); | |
3539 | ret = NULL; | |
3540 | } | |
3541 | } | |
3542 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3543 | bp_objfile_data->exception_searched = 1; |
3544 | } | |
3545 | ||
3546 | if (bp_objfile_data->exception_probes != NULL) | |
3547 | { | |
3548 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3549 | int i; | |
3550 | struct probe *probe; | |
3551 | ||
3552 | for (i = 0; | |
3553 | VEC_iterate (probe_p, | |
3554 | bp_objfile_data->exception_probes, | |
3555 | i, probe); | |
3556 | ++i) | |
3557 | { | |
3558 | struct breakpoint *b; | |
3559 | ||
729662a5 TT |
3560 | b = create_internal_breakpoint (gdbarch, |
3561 | get_probe_address (probe, | |
3562 | objfile), | |
28106bc2 SDJ |
3563 | bp_exception_master, |
3564 | &internal_breakpoint_ops); | |
3565 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3566 | b->enable_state = bp_disabled; | |
3567 | } | |
3568 | ||
3569 | continue; | |
3570 | } | |
3571 | ||
3572 | /* Otherwise, try the hook function. */ | |
3573 | ||
3b7344d5 | 3574 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3575 | continue; |
3576 | ||
3577 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3578 | |
3b7344d5 | 3579 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3580 | { |
3b7344d5 | 3581 | struct bound_minimal_symbol debug_hook; |
186c406b | 3582 | |
17450429 | 3583 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3584 | if (debug_hook.minsym == NULL) |
17450429 | 3585 | { |
3b7344d5 | 3586 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3587 | continue; |
3588 | } | |
3589 | ||
3590 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3591 | } |
17450429 | 3592 | |
77e371c0 | 3593 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3594 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3595 | ¤t_target); | |
06edf0c0 PA |
3596 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3597 | &internal_breakpoint_ops); | |
17450429 PP |
3598 | b->addr_string = xstrdup (func_name); |
3599 | b->enable_state = bp_disabled; | |
186c406b TT |
3600 | } |
3601 | ||
3602 | update_global_location_list (1); | |
3603 | } | |
3604 | ||
c906108c | 3605 | void |
fba45db2 | 3606 | update_breakpoints_after_exec (void) |
c906108c | 3607 | { |
35df4500 | 3608 | struct breakpoint *b, *b_tmp; |
876fa593 | 3609 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3610 | |
25b22b0a PA |
3611 | /* We're about to delete breakpoints from GDB's lists. If the |
3612 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3613 | writing the breakpoints' "shadow contents" back into memory. The | |
3614 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3615 | do that. Instead, the target is responsible from marking | |
3616 | breakpoints out as soon as it detects an exec. We don't do that | |
3617 | here instead, because there may be other attempts to delete | |
3618 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3619 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3620 | if (bploc->pspace == current_program_space) |
3621 | gdb_assert (!bploc->inserted); | |
c906108c | 3622 | |
35df4500 | 3623 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3624 | { |
6c95b8df PA |
3625 | if (b->pspace != current_program_space) |
3626 | continue; | |
3627 | ||
4a64f543 | 3628 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3629 | if (b->type == bp_shlib_event) |
3630 | { | |
3631 | delete_breakpoint (b); | |
3632 | continue; | |
3633 | } | |
c906108c | 3634 | |
4a64f543 | 3635 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3636 | if (b->type == bp_jit_event) |
3637 | { | |
3638 | delete_breakpoint (b); | |
3639 | continue; | |
3640 | } | |
3641 | ||
1900040c | 3642 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3643 | as must overlay event and longjmp master breakpoints. */ |
3644 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3645 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3646 | || b->type == bp_exception_master) | |
c4093a6a JM |
3647 | { |
3648 | delete_breakpoint (b); | |
3649 | continue; | |
3650 | } | |
3651 | ||
4a64f543 | 3652 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3653 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3654 | { |
3655 | delete_breakpoint (b); | |
3656 | continue; | |
3657 | } | |
3658 | ||
611c83ae PA |
3659 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3660 | after an exec. */ | |
186c406b | 3661 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3662 | || b->type == bp_longjmp_call_dummy |
186c406b | 3663 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3664 | { |
3665 | delete_breakpoint (b); | |
3666 | continue; | |
3667 | } | |
3668 | ||
ce78b96d JB |
3669 | if (b->type == bp_catchpoint) |
3670 | { | |
3671 | /* For now, none of the bp_catchpoint breakpoints need to | |
3672 | do anything at this point. In the future, if some of | |
3673 | the catchpoints need to something, we will need to add | |
3674 | a new method, and call this method from here. */ | |
3675 | continue; | |
3676 | } | |
3677 | ||
c5aa993b JM |
3678 | /* bp_finish is a special case. The only way we ought to be able |
3679 | to see one of these when an exec() has happened, is if the user | |
3680 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3681 | carries them to the call-site of the current callee, by setting | |
3682 | a temporary bp there and resuming. But in this case, the finish | |
3683 | will carry them entirely through the vfork & exec. | |
3684 | ||
3685 | We don't want to allow a bp_finish to remain inserted now. But | |
3686 | we can't safely delete it, 'cause finish_command has a handle to | |
3687 | the bp on a bpstat, and will later want to delete it. There's a | |
3688 | chance (and I've seen it happen) that if we delete the bp_finish | |
3689 | here, that its storage will get reused by the time finish_command | |
3690 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3691 | We really must allow finish_command to delete a bp_finish. | |
3692 | ||
e5dd4106 | 3693 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3694 | it's safe to delete something others may have handles to?" |
3695 | problem, what we'll do here is just uninsert the bp_finish, and | |
3696 | let finish_command delete it. | |
3697 | ||
3698 | (We know the bp_finish is "doomed" in the sense that it's | |
3699 | momentary, and will be deleted as soon as finish_command sees | |
3700 | the inferior stopped. So it doesn't matter that the bp's | |
3701 | address is probably bogus in the new a.out, unlike e.g., the | |
3702 | solib breakpoints.) */ | |
c5aa993b | 3703 | |
c5aa993b JM |
3704 | if (b->type == bp_finish) |
3705 | { | |
3706 | continue; | |
3707 | } | |
3708 | ||
3709 | /* Without a symbolic address, we have little hope of the | |
3710 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3711 | a.out. */ |
c5aa993b JM |
3712 | if (b->addr_string == NULL) |
3713 | { | |
3714 | delete_breakpoint (b); | |
3715 | continue; | |
3716 | } | |
c5aa993b | 3717 | } |
1900040c | 3718 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3719 | create_overlay_event_breakpoint (); |
3720 | create_longjmp_master_breakpoint (); | |
3721 | create_std_terminate_master_breakpoint (); | |
186c406b | 3722 | create_exception_master_breakpoint (); |
c906108c SS |
3723 | } |
3724 | ||
3725 | int | |
d80ee84f | 3726 | detach_breakpoints (ptid_t ptid) |
c906108c | 3727 | { |
35df4500 | 3728 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3729 | int val = 0; |
ce696e05 | 3730 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3731 | struct inferior *inf = current_inferior (); |
c5aa993b | 3732 | |
dfd4cc63 | 3733 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3734 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3735 | |
6c95b8df | 3736 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3737 | inferior_ptid = ptid; |
35df4500 | 3738 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3739 | { |
35df4500 | 3740 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3741 | continue; |
3742 | ||
bd9673a4 PW |
3743 | /* This function must physically remove breakpoints locations |
3744 | from the specified ptid, without modifying the breakpoint | |
3745 | package's state. Locations of type bp_loc_other are only | |
3746 | maintained at GDB side. So, there is no need to remove | |
3747 | these bp_loc_other locations. Moreover, removing these | |
3748 | would modify the breakpoint package's state. */ | |
3749 | if (bl->loc_type == bp_loc_other) | |
3750 | continue; | |
3751 | ||
35df4500 TJB |
3752 | if (bl->inserted) |
3753 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3754 | } |
d03285ec UW |
3755 | |
3756 | /* Detach single-step breakpoints as well. */ | |
3757 | detach_single_step_breakpoints (); | |
3758 | ||
ce696e05 | 3759 | do_cleanups (old_chain); |
3a1bae8e | 3760 | return val; |
c906108c SS |
3761 | } |
3762 | ||
35df4500 | 3763 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3764 | Note that this is used to detach breakpoints from a child fork. |
3765 | When we get here, the child isn't in the inferior list, and neither | |
3766 | do we have objects to represent its address space --- we should | |
35df4500 | 3767 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3768 | |
c906108c | 3769 | static int |
35df4500 | 3770 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3771 | { |
3772 | int val; | |
c5aa993b | 3773 | |
35df4500 TJB |
3774 | /* BL is never in moribund_locations by our callers. */ |
3775 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3776 | |
35df4500 | 3777 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3778 | /* Permanent breakpoints cannot be inserted or removed. */ |
3779 | return 0; | |
3780 | ||
74960c60 VP |
3781 | /* The type of none suggests that owner is actually deleted. |
3782 | This should not ever happen. */ | |
35df4500 | 3783 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3784 | |
35df4500 TJB |
3785 | if (bl->loc_type == bp_loc_software_breakpoint |
3786 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3787 | { |
c02f5703 MS |
3788 | /* "Normal" instruction breakpoint: either the standard |
3789 | trap-instruction bp (bp_breakpoint), or a | |
3790 | bp_hardware_breakpoint. */ | |
3791 | ||
3792 | /* First check to see if we have to handle an overlay. */ | |
3793 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3794 | || bl->section == NULL |
3795 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3796 | { |
3797 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3798 | |
3799 | /* If we're trying to uninsert a memory breakpoint that we | |
3800 | know is set in a dynamic object that is marked | |
3801 | shlib_disabled, then either the dynamic object was | |
3802 | removed with "remove-symbol-file" or with | |
3803 | "nosharedlibrary". In the former case, we don't know | |
3804 | whether another dynamic object might have loaded over the | |
3805 | breakpoint's address -- the user might well let us know | |
3806 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3807 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3808 | list of dynamically loaded objects). If we have the |
3809 | breakpoint's shadow memory, that is, this is a software | |
3810 | breakpoint managed by GDB, check whether the breakpoint | |
3811 | is still inserted in memory, to avoid overwriting wrong | |
3812 | code with stale saved shadow contents. Note that HW | |
3813 | breakpoints don't have shadow memory, as they're | |
3814 | implemented using a mechanism that is not dependent on | |
3815 | being able to modify the target's memory, and as such | |
3816 | they should always be removed. */ | |
3817 | if (bl->shlib_disabled | |
3818 | && bl->target_info.shadow_len != 0 | |
3819 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3820 | val = 0; | |
3821 | else | |
3822 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3823 | } |
c906108c SS |
3824 | else |
3825 | { | |
4a64f543 | 3826 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3827 | Did we set a breakpoint at the LMA? */ |
3828 | if (!overlay_events_enabled) | |
3829 | { | |
3830 | /* Yes -- overlay event support is not active, so we | |
3831 | should have set a breakpoint at the LMA. Remove it. | |
3832 | */ | |
c02f5703 MS |
3833 | /* Ignore any failures: if the LMA is in ROM, we will |
3834 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3835 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3836 | target_remove_hw_breakpoint (bl->gdbarch, | |
3837 | &bl->overlay_target_info); | |
c02f5703 | 3838 | else |
35df4500 TJB |
3839 | target_remove_breakpoint (bl->gdbarch, |
3840 | &bl->overlay_target_info); | |
c02f5703 MS |
3841 | } |
3842 | /* Did we set a breakpoint at the VMA? | |
3843 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3844 | if (bl->inserted) |
c906108c | 3845 | { |
c02f5703 MS |
3846 | /* Yes -- remove it. Previously we did not bother to |
3847 | remove the breakpoint if the section had been | |
3848 | unmapped, but let's not rely on that being safe. We | |
3849 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3850 | |
3851 | /* However, we should remove *software* breakpoints only | |
3852 | if the section is still mapped, or else we overwrite | |
3853 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3854 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3855 | || section_is_mapped (bl->section)) | |
3856 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3857 | else |
3858 | val = 0; | |
c906108c | 3859 | } |
c02f5703 MS |
3860 | else |
3861 | { | |
3862 | /* No -- not inserted, so no need to remove. No error. */ | |
3863 | val = 0; | |
3864 | } | |
c906108c | 3865 | } |
879d1e6b | 3866 | |
08351840 PA |
3867 | /* In some cases, we might not be able to remove a breakpoint in |
3868 | a shared library that has already been removed, but we have | |
3869 | not yet processed the shlib unload event. Similarly for an | |
3870 | unloaded add-symbol-file object - the user might not yet have | |
3871 | had the chance to remove-symbol-file it. shlib_disabled will | |
3872 | be set if the library/object has already been removed, but | |
3873 | the breakpoint hasn't been uninserted yet, e.g., after | |
3874 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3875 | always-inserted mode. */ | |
076855f9 | 3876 | if (val |
08351840 PA |
3877 | && (bl->loc_type == bp_loc_software_breakpoint |
3878 | && (bl->shlib_disabled | |
3879 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3880 | || shared_objfile_contains_address_p (bl->pspace, |
3881 | bl->address)))) | |
879d1e6b UW |
3882 | val = 0; |
3883 | ||
c906108c SS |
3884 | if (val) |
3885 | return val; | |
35df4500 | 3886 | bl->inserted = (is == mark_inserted); |
c906108c | 3887 | } |
35df4500 | 3888 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3889 | { |
77b06cd7 TJB |
3890 | gdb_assert (bl->owner->ops != NULL |
3891 | && bl->owner->ops->remove_location != NULL); | |
3892 | ||
35df4500 | 3893 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3894 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3895 | |
c906108c | 3896 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3897 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3898 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3899 | bl->owner->number); |
c906108c | 3900 | } |
35df4500 TJB |
3901 | else if (bl->owner->type == bp_catchpoint |
3902 | && breakpoint_enabled (bl->owner) | |
3903 | && !bl->duplicate) | |
ce78b96d | 3904 | { |
77b06cd7 TJB |
3905 | gdb_assert (bl->owner->ops != NULL |
3906 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3907 | |
77b06cd7 | 3908 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3909 | if (val) |
3910 | return val; | |
77b06cd7 | 3911 | |
35df4500 | 3912 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3913 | } |
c906108c SS |
3914 | |
3915 | return 0; | |
3916 | } | |
3917 | ||
6c95b8df | 3918 | static int |
35df4500 | 3919 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3920 | { |
3921 | int ret; | |
3922 | struct cleanup *old_chain; | |
3923 | ||
35df4500 TJB |
3924 | /* BL is never in moribund_locations by our callers. */ |
3925 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3926 | |
35df4500 | 3927 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3928 | /* Permanent breakpoints cannot be inserted or removed. */ |
3929 | return 0; | |
3930 | ||
3931 | /* The type of none suggests that owner is actually deleted. | |
3932 | This should not ever happen. */ | |
35df4500 | 3933 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3934 | |
3935 | old_chain = save_current_space_and_thread (); | |
3936 | ||
35df4500 | 3937 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3938 | |
35df4500 | 3939 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3940 | |
3941 | do_cleanups (old_chain); | |
3942 | return ret; | |
3943 | } | |
3944 | ||
c906108c SS |
3945 | /* Clear the "inserted" flag in all breakpoints. */ |
3946 | ||
25b22b0a | 3947 | void |
fba45db2 | 3948 | mark_breakpoints_out (void) |
c906108c | 3949 | { |
35df4500 | 3950 | struct bp_location *bl, **blp_tmp; |
c906108c | 3951 | |
35df4500 TJB |
3952 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3953 | if (bl->pspace == current_program_space) | |
3954 | bl->inserted = 0; | |
c906108c SS |
3955 | } |
3956 | ||
53a5351d JM |
3957 | /* Clear the "inserted" flag in all breakpoints and delete any |
3958 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3959 | |
3960 | Plus other such housekeeping that has to be done for breakpoints | |
3961 | between runs. | |
3962 | ||
53a5351d JM |
3963 | Note: this function gets called at the end of a run (by |
3964 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3965 | init_wait_for_inferior). */ |
c906108c SS |
3966 | |
3967 | ||
3968 | ||
3969 | void | |
fba45db2 | 3970 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3971 | { |
35df4500 TJB |
3972 | struct breakpoint *b, *b_tmp; |
3973 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3974 | int ix; |
6c95b8df | 3975 | struct program_space *pspace = current_program_space; |
c906108c | 3976 | |
50c71eaf PA |
3977 | /* If breakpoint locations are shared across processes, then there's |
3978 | nothing to do. */ | |
f5656ead | 3979 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3980 | return; |
3981 | ||
35df4500 | 3982 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3983 | { |
35df4500 TJB |
3984 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3985 | if (bl->pspace == pspace | |
3986 | && bl->owner->enable_state != bp_permanent) | |
3987 | bl->inserted = 0; | |
6c95b8df | 3988 | } |
075f6582 | 3989 | |
35df4500 | 3990 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3991 | { |
6c95b8df PA |
3992 | if (b->loc && b->loc->pspace != pspace) |
3993 | continue; | |
3994 | ||
c5aa993b JM |
3995 | switch (b->type) |
3996 | { | |
3997 | case bp_call_dummy: | |
e2e4d78b | 3998 | case bp_longjmp_call_dummy: |
c906108c | 3999 | |
c5aa993b | 4000 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4001 | cause problems when the inferior is rerun, so we better get |
4002 | rid of it. */ | |
4003 | ||
4004 | case bp_watchpoint_scope: | |
4005 | ||
4006 | /* Also get rid of scope breakpoints. */ | |
4007 | ||
4008 | case bp_shlib_event: | |
4009 | ||
4010 | /* Also remove solib event breakpoints. Their addresses may | |
4011 | have changed since the last time we ran the program. | |
4012 | Actually we may now be debugging against different target; | |
4013 | and so the solib backend that installed this breakpoint may | |
4014 | not be used in by the target. E.g., | |
4015 | ||
4016 | (gdb) file prog-linux | |
4017 | (gdb) run # native linux target | |
4018 | ... | |
4019 | (gdb) kill | |
4020 | (gdb) file prog-win.exe | |
4021 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4022 | */ | |
c906108c | 4023 | |
f59f708a PA |
4024 | case bp_step_resume: |
4025 | ||
4026 | /* Also remove step-resume breakpoints. */ | |
4027 | ||
c5aa993b JM |
4028 | delete_breakpoint (b); |
4029 | break; | |
c906108c | 4030 | |
c5aa993b JM |
4031 | case bp_watchpoint: |
4032 | case bp_hardware_watchpoint: | |
4033 | case bp_read_watchpoint: | |
4034 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4035 | { |
4036 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4037 | |
3a5c3e22 PA |
4038 | /* Likewise for watchpoints on local expressions. */ |
4039 | if (w->exp_valid_block != NULL) | |
4040 | delete_breakpoint (b); | |
4041 | else if (context == inf_starting) | |
4042 | { | |
4043 | /* Reset val field to force reread of starting value in | |
4044 | insert_breakpoints. */ | |
4045 | if (w->val) | |
4046 | value_free (w->val); | |
4047 | w->val = NULL; | |
4048 | w->val_valid = 0; | |
c860120c | 4049 | } |
3a5c3e22 | 4050 | } |
c5aa993b JM |
4051 | break; |
4052 | default: | |
c5aa993b JM |
4053 | break; |
4054 | } | |
4055 | } | |
1c5cfe86 PA |
4056 | |
4057 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4058 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4059 | decref_bp_location (&bl); | |
1c5cfe86 | 4060 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4061 | } |
4062 | ||
6c95b8df PA |
4063 | /* These functions concern about actual breakpoints inserted in the |
4064 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4065 | we need to hop over the bkpt --- so we check for address space | |
4066 | match, not program space. */ | |
4067 | ||
c2c6d25f JM |
4068 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4069 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4070 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4071 | permanent breakpoint. | |
4072 | - When continuing from a location with an ordinary breakpoint, we | |
4073 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4074 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4075 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4076 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4077 | |
c2c6d25f | 4078 | enum breakpoint_here |
6c95b8df | 4079 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4080 | { |
35df4500 | 4081 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4082 | int any_breakpoint_here = 0; |
c906108c | 4083 | |
35df4500 | 4084 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4085 | { |
35df4500 TJB |
4086 | if (bl->loc_type != bp_loc_software_breakpoint |
4087 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4088 | continue; |
4089 | ||
f1310107 | 4090 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
4091 | if ((breakpoint_enabled (bl->owner) |
4092 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 4093 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4094 | { |
4095 | if (overlay_debugging | |
35df4500 TJB |
4096 | && section_is_overlay (bl->section) |
4097 | && !section_is_mapped (bl->section)) | |
075f6582 | 4098 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 4099 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
4100 | return permanent_breakpoint_here; |
4101 | else | |
4102 | any_breakpoint_here = 1; | |
4103 | } | |
4104 | } | |
c906108c | 4105 | |
c2c6d25f | 4106 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4107 | } |
4108 | ||
1c5cfe86 PA |
4109 | /* Return true if there's a moribund breakpoint at PC. */ |
4110 | ||
4111 | int | |
6c95b8df | 4112 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4113 | { |
4114 | struct bp_location *loc; | |
4115 | int ix; | |
4116 | ||
4117 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4118 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4119 | return 1; |
4120 | ||
4121 | return 0; | |
4122 | } | |
c2c6d25f | 4123 | |
c36b740a | 4124 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
4125 | inserted using regular breakpoint_chain / bp_location array |
4126 | mechanism. This does not check for single-step breakpoints, which | |
4127 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
4128 | |
4129 | int | |
4a64f543 MS |
4130 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
4131 | CORE_ADDR pc) | |
c906108c | 4132 | { |
35df4500 | 4133 | struct bp_location *bl, **blp_tmp; |
c906108c | 4134 | |
35df4500 | 4135 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4136 | { |
35df4500 TJB |
4137 | if (bl->loc_type != bp_loc_software_breakpoint |
4138 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4139 | continue; |
4140 | ||
35df4500 | 4141 | if (bl->inserted |
f1310107 | 4142 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4143 | { |
4144 | if (overlay_debugging | |
35df4500 TJB |
4145 | && section_is_overlay (bl->section) |
4146 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4147 | continue; /* unmapped overlay -- can't be a match */ |
4148 | else | |
4149 | return 1; | |
4150 | } | |
c5aa993b | 4151 | } |
c36b740a VP |
4152 | return 0; |
4153 | } | |
4154 | ||
4155 | /* Returns non-zero iff there's either regular breakpoint | |
4156 | or a single step breakpoint inserted at PC. */ | |
4157 | ||
4158 | int | |
6c95b8df | 4159 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 4160 | { |
6c95b8df | 4161 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4162 | return 1; |
c906108c | 4163 | |
6c95b8df | 4164 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4165 | return 1; |
4166 | ||
c906108c SS |
4167 | return 0; |
4168 | } | |
4169 | ||
ef370185 JB |
4170 | /* Ignoring deprecated raw breakpoints, return non-zero iff there is a |
4171 | software breakpoint inserted at PC. */ | |
4fa8626c | 4172 | |
ef370185 JB |
4173 | static struct bp_location * |
4174 | find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace, | |
4175 | CORE_ADDR pc) | |
4fa8626c | 4176 | { |
35df4500 | 4177 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4178 | |
35df4500 | 4179 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4180 | { |
35df4500 | 4181 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4182 | continue; |
4183 | ||
35df4500 TJB |
4184 | if (bl->inserted |
4185 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4186 | aspace, pc)) |
4fa8626c DJ |
4187 | { |
4188 | if (overlay_debugging | |
35df4500 TJB |
4189 | && section_is_overlay (bl->section) |
4190 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4191 | continue; /* unmapped overlay -- can't be a match */ |
4192 | else | |
ef370185 | 4193 | return bl; |
4fa8626c DJ |
4194 | } |
4195 | } | |
4196 | ||
ef370185 JB |
4197 | return NULL; |
4198 | } | |
4199 | ||
4200 | /* This function returns non-zero iff there is a software breakpoint | |
4201 | inserted at PC. */ | |
4202 | ||
4203 | int | |
4204 | software_breakpoint_inserted_here_p (struct address_space *aspace, | |
4205 | CORE_ADDR pc) | |
4206 | { | |
4207 | if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL) | |
4208 | return 1; | |
4209 | ||
1aafd4da | 4210 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4211 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4212 | return 1; |
4213 | ||
4fa8626c DJ |
4214 | return 0; |
4215 | } | |
4216 | ||
9093389c PA |
4217 | int |
4218 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4219 | CORE_ADDR addr, ULONGEST len) | |
4220 | { | |
4221 | struct breakpoint *bpt; | |
4222 | ||
4223 | ALL_BREAKPOINTS (bpt) | |
4224 | { | |
4225 | struct bp_location *loc; | |
4226 | ||
4227 | if (bpt->type != bp_hardware_watchpoint | |
4228 | && bpt->type != bp_access_watchpoint) | |
4229 | continue; | |
4230 | ||
4231 | if (!breakpoint_enabled (bpt)) | |
4232 | continue; | |
4233 | ||
4234 | for (loc = bpt->loc; loc; loc = loc->next) | |
4235 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4236 | { | |
4237 | CORE_ADDR l, h; | |
4238 | ||
4239 | /* Check for intersection. */ | |
4240 | l = max (loc->address, addr); | |
4241 | h = min (loc->address + loc->length, addr + len); | |
4242 | if (l < h) | |
4243 | return 1; | |
4244 | } | |
4245 | } | |
4246 | return 0; | |
4247 | } | |
4248 | ||
075f6582 DJ |
4249 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4250 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4251 | |
4252 | int | |
6c95b8df PA |
4253 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4254 | ptid_t ptid) | |
c906108c | 4255 | { |
35df4500 | 4256 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4257 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4258 | int thread = -1; |
4a306c9a | 4259 | int task = 0; |
a6f1cd96 | 4260 | |
35df4500 | 4261 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4262 | { |
35df4500 TJB |
4263 | if (bl->loc_type != bp_loc_software_breakpoint |
4264 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4265 | continue; |
4266 | ||
35df4500 TJB |
4267 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4268 | if (!breakpoint_enabled (bl->owner) | |
4269 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4270 | continue; |
4271 | ||
f1310107 | 4272 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4273 | continue; |
4274 | ||
35df4500 | 4275 | if (bl->owner->thread != -1) |
075f6582 | 4276 | { |
a6f1cd96 JB |
4277 | /* This is a thread-specific breakpoint. Check that ptid |
4278 | matches that thread. If thread hasn't been computed yet, | |
4279 | it is now time to do so. */ | |
4280 | if (thread == -1) | |
4281 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4282 | if (bl->owner->thread != thread) |
a6f1cd96 | 4283 | continue; |
075f6582 | 4284 | } |
a6f1cd96 | 4285 | |
35df4500 | 4286 | if (bl->owner->task != 0) |
4a306c9a JB |
4287 | { |
4288 | /* This is a task-specific breakpoint. Check that ptid | |
4289 | matches that task. If task hasn't been computed yet, | |
4290 | it is now time to do so. */ | |
4291 | if (task == 0) | |
4292 | task = ada_get_task_number (ptid); | |
35df4500 | 4293 | if (bl->owner->task != task) |
4a306c9a JB |
4294 | continue; |
4295 | } | |
4296 | ||
a6f1cd96 | 4297 | if (overlay_debugging |
35df4500 TJB |
4298 | && section_is_overlay (bl->section) |
4299 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4300 | continue; /* unmapped overlay -- can't be a match */ |
4301 | ||
4302 | return 1; | |
c5aa993b | 4303 | } |
c906108c SS |
4304 | |
4305 | return 0; | |
4306 | } | |
c906108c | 4307 | \f |
c5aa993b | 4308 | |
c906108c SS |
4309 | /* bpstat stuff. External routines' interfaces are documented |
4310 | in breakpoint.h. */ | |
4311 | ||
4312 | int | |
c326b90e | 4313 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4314 | { |
533be4dd | 4315 | return (ep->type == bp_catchpoint); |
c906108c SS |
4316 | } |
4317 | ||
f431efe5 PA |
4318 | /* Frees any storage that is part of a bpstat. Does not walk the |
4319 | 'next' chain. */ | |
4320 | ||
4321 | static void | |
198757a8 VP |
4322 | bpstat_free (bpstat bs) |
4323 | { | |
4324 | if (bs->old_val != NULL) | |
4325 | value_free (bs->old_val); | |
9add0f1b | 4326 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4327 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4328 | xfree (bs); |
4329 | } | |
4330 | ||
c906108c SS |
4331 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4332 | Also free any storage that is part of a bpstat. */ | |
4333 | ||
4334 | void | |
fba45db2 | 4335 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4336 | { |
4337 | bpstat p; | |
4338 | bpstat q; | |
4339 | ||
4340 | if (bsp == 0) | |
4341 | return; | |
4342 | p = *bsp; | |
4343 | while (p != NULL) | |
4344 | { | |
4345 | q = p->next; | |
198757a8 | 4346 | bpstat_free (p); |
c906108c SS |
4347 | p = q; |
4348 | } | |
4349 | *bsp = NULL; | |
4350 | } | |
4351 | ||
4352 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4353 | is part of the bpstat is copied as well. */ | |
4354 | ||
4355 | bpstat | |
fba45db2 | 4356 | bpstat_copy (bpstat bs) |
c906108c SS |
4357 | { |
4358 | bpstat p = NULL; | |
4359 | bpstat tmp; | |
4360 | bpstat retval = NULL; | |
4361 | ||
4362 | if (bs == NULL) | |
4363 | return bs; | |
4364 | ||
4365 | for (; bs != NULL; bs = bs->next) | |
4366 | { | |
4367 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4368 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4369 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4370 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4371 | if (bs->old_val != NULL) |
3c3185ac JK |
4372 | { |
4373 | tmp->old_val = value_copy (bs->old_val); | |
4374 | release_value (tmp->old_val); | |
4375 | } | |
31cc81e9 | 4376 | |
c906108c SS |
4377 | if (p == NULL) |
4378 | /* This is the first thing in the chain. */ | |
4379 | retval = tmp; | |
4380 | else | |
4381 | p->next = tmp; | |
4382 | p = tmp; | |
4383 | } | |
4384 | p->next = NULL; | |
4385 | return retval; | |
4386 | } | |
4387 | ||
4a64f543 | 4388 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4389 | |
4390 | bpstat | |
fba45db2 | 4391 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4392 | { |
c5aa993b JM |
4393 | if (bsp == NULL) |
4394 | return NULL; | |
c906108c | 4395 | |
c5aa993b JM |
4396 | for (; bsp != NULL; bsp = bsp->next) |
4397 | { | |
f431efe5 | 4398 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4399 | return bsp; |
4400 | } | |
c906108c SS |
4401 | return NULL; |
4402 | } | |
4403 | ||
ab04a2af TT |
4404 | /* See breakpoint.h. */ |
4405 | ||
47591c29 | 4406 | int |
427cd150 | 4407 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4408 | { |
ab04a2af TT |
4409 | for (; bsp != NULL; bsp = bsp->next) |
4410 | { | |
427cd150 TT |
4411 | if (bsp->breakpoint_at == NULL) |
4412 | { | |
4413 | /* A moribund location can never explain a signal other than | |
4414 | GDB_SIGNAL_TRAP. */ | |
4415 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4416 | return 1; |
427cd150 TT |
4417 | } |
4418 | else | |
47591c29 PA |
4419 | { |
4420 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4421 | sig)) | |
4422 | return 1; | |
4423 | } | |
ab04a2af TT |
4424 | } |
4425 | ||
47591c29 | 4426 | return 0; |
ab04a2af TT |
4427 | } |
4428 | ||
4a64f543 MS |
4429 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4430 | stopped at. *BSP upon return is a bpstat which points to the | |
4431 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4432 | good for anything but further calls to bpstat_num). | |
4433 | ||
8671a17b PA |
4434 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4435 | Return -1 if stopped at a breakpoint that has been deleted since | |
4436 | we set it. | |
4437 | Return 1 otherwise. */ | |
c906108c SS |
4438 | |
4439 | int | |
8671a17b | 4440 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4441 | { |
4442 | struct breakpoint *b; | |
4443 | ||
4444 | if ((*bsp) == NULL) | |
4445 | return 0; /* No more breakpoint values */ | |
8671a17b | 4446 | |
4a64f543 MS |
4447 | /* We assume we'll never have several bpstats that correspond to a |
4448 | single breakpoint -- otherwise, this function might return the | |
4449 | same number more than once and this will look ugly. */ | |
f431efe5 | 4450 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4451 | *bsp = (*bsp)->next; |
4452 | if (b == NULL) | |
4453 | return -1; /* breakpoint that's been deleted since */ | |
4454 | ||
4455 | *num = b->number; /* We have its number */ | |
4456 | return 1; | |
c906108c SS |
4457 | } |
4458 | ||
e93ca019 | 4459 | /* See breakpoint.h. */ |
c906108c SS |
4460 | |
4461 | void | |
e93ca019 | 4462 | bpstat_clear_actions (void) |
c906108c | 4463 | { |
e93ca019 JK |
4464 | struct thread_info *tp; |
4465 | bpstat bs; | |
4466 | ||
4467 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4468 | return; | |
4469 | ||
4470 | tp = find_thread_ptid (inferior_ptid); | |
4471 | if (tp == NULL) | |
4472 | return; | |
4473 | ||
4474 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4475 | { |
9add0f1b | 4476 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4477 | |
c906108c SS |
4478 | if (bs->old_val != NULL) |
4479 | { | |
4480 | value_free (bs->old_val); | |
4481 | bs->old_val = NULL; | |
4482 | } | |
4483 | } | |
4484 | } | |
4485 | ||
f3b1572e PA |
4486 | /* Called when a command is about to proceed the inferior. */ |
4487 | ||
4488 | static void | |
4489 | breakpoint_about_to_proceed (void) | |
4490 | { | |
4491 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4492 | { | |
4493 | struct thread_info *tp = inferior_thread (); | |
4494 | ||
4495 | /* Allow inferior function calls in breakpoint commands to not | |
4496 | interrupt the command list. When the call finishes | |
4497 | successfully, the inferior will be standing at the same | |
4498 | breakpoint as if nothing happened. */ | |
16c381f0 | 4499 | if (tp->control.in_infcall) |
f3b1572e PA |
4500 | return; |
4501 | } | |
4502 | ||
4503 | breakpoint_proceeded = 1; | |
4504 | } | |
4505 | ||
4a64f543 MS |
4506 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4507 | command. */ | |
c906108c | 4508 | static void |
4efb68b1 | 4509 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4510 | { |
4511 | executing_breakpoint_commands = 0; | |
4512 | } | |
4513 | ||
abf85f46 JK |
4514 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4515 | or its equivalent. */ | |
4516 | ||
4517 | static int | |
4518 | command_line_is_silent (struct command_line *cmd) | |
4519 | { | |
4520 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4521 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4522 | } | |
4523 | ||
4a64f543 MS |
4524 | /* Execute all the commands associated with all the breakpoints at |
4525 | this location. Any of these commands could cause the process to | |
4526 | proceed beyond this point, etc. We look out for such changes by | |
4527 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4528 | |
347bddb7 PA |
4529 | Returns true if a breakpoint command resumed the inferior. In that |
4530 | case, it is the caller's responsibility to recall it again with the | |
4531 | bpstat of the current thread. */ | |
4532 | ||
4533 | static int | |
4534 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4535 | { |
4536 | bpstat bs; | |
4537 | struct cleanup *old_chain; | |
347bddb7 | 4538 | int again = 0; |
c906108c SS |
4539 | |
4540 | /* Avoid endless recursion if a `source' command is contained | |
4541 | in bs->commands. */ | |
4542 | if (executing_breakpoint_commands) | |
347bddb7 | 4543 | return 0; |
c906108c SS |
4544 | |
4545 | executing_breakpoint_commands = 1; | |
4546 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4547 | ||
cf6c5ffb TT |
4548 | prevent_dont_repeat (); |
4549 | ||
4a64f543 | 4550 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4551 | bs = *bsp; |
4552 | ||
4553 | breakpoint_proceeded = 0; | |
4554 | for (; bs != NULL; bs = bs->next) | |
4555 | { | |
9add0f1b | 4556 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4557 | struct command_line *cmd; |
4558 | struct cleanup *this_cmd_tree_chain; | |
4559 | ||
4560 | /* Take ownership of the BSP's command tree, if it has one. | |
4561 | ||
4562 | The command tree could legitimately contain commands like | |
4563 | 'step' and 'next', which call clear_proceed_status, which | |
4564 | frees stop_bpstat's command tree. To make sure this doesn't | |
4565 | free the tree we're executing out from under us, we need to | |
4566 | take ownership of the tree ourselves. Since a given bpstat's | |
4567 | commands are only executed once, we don't need to copy it; we | |
4568 | can clear the pointer in the bpstat, and make sure we free | |
4569 | the tree when we're done. */ | |
9add0f1b TT |
4570 | ccmd = bs->commands; |
4571 | bs->commands = NULL; | |
abf85f46 JK |
4572 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4573 | cmd = ccmd ? ccmd->commands : NULL; | |
4574 | if (command_line_is_silent (cmd)) | |
4575 | { | |
4576 | /* The action has been already done by bpstat_stop_status. */ | |
4577 | cmd = cmd->next; | |
4578 | } | |
6c50ab1c | 4579 | |
c906108c SS |
4580 | while (cmd != NULL) |
4581 | { | |
4582 | execute_control_command (cmd); | |
4583 | ||
4584 | if (breakpoint_proceeded) | |
4585 | break; | |
4586 | else | |
4587 | cmd = cmd->next; | |
4588 | } | |
6c50ab1c JB |
4589 | |
4590 | /* We can free this command tree now. */ | |
4591 | do_cleanups (this_cmd_tree_chain); | |
4592 | ||
c906108c | 4593 | if (breakpoint_proceeded) |
32c1e744 VP |
4594 | { |
4595 | if (target_can_async_p ()) | |
347bddb7 PA |
4596 | /* If we are in async mode, then the target might be still |
4597 | running, not stopped at any breakpoint, so nothing for | |
4598 | us to do here -- just return to the event loop. */ | |
4599 | ; | |
32c1e744 VP |
4600 | else |
4601 | /* In sync mode, when execute_control_command returns | |
4602 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4603 | Breakpoint commands for that stop were not run, since |
4604 | execute_command does not run breakpoint commands -- | |
4605 | only command_line_handler does, but that one is not | |
4606 | involved in execution of breakpoint commands. So, we | |
4607 | can now execute breakpoint commands. It should be | |
4608 | noted that making execute_command do bpstat actions is | |
4609 | not an option -- in this case we'll have recursive | |
4610 | invocation of bpstat for each breakpoint with a | |
4611 | command, and can easily blow up GDB stack. Instead, we | |
4612 | return true, which will trigger the caller to recall us | |
4613 | with the new stop_bpstat. */ | |
4614 | again = 1; | |
4615 | break; | |
32c1e744 | 4616 | } |
c906108c | 4617 | } |
c2b8ed2c | 4618 | do_cleanups (old_chain); |
347bddb7 PA |
4619 | return again; |
4620 | } | |
4621 | ||
4622 | void | |
4623 | bpstat_do_actions (void) | |
4624 | { | |
353d1d73 JK |
4625 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4626 | ||
347bddb7 PA |
4627 | /* Do any commands attached to breakpoint we are stopped at. */ |
4628 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4629 | && target_has_execution | |
4630 | && !is_exited (inferior_ptid) | |
4631 | && !is_executing (inferior_ptid)) | |
4632 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4633 | and only return when it is stopped at the next breakpoint, we | |
4634 | keep doing breakpoint actions until it returns false to | |
4635 | indicate the inferior was not resumed. */ | |
16c381f0 | 4636 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4637 | break; |
353d1d73 JK |
4638 | |
4639 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4640 | } |
4641 | ||
fa4727a6 DJ |
4642 | /* Print out the (old or new) value associated with a watchpoint. */ |
4643 | ||
4644 | static void | |
4645 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4646 | { | |
4647 | if (val == NULL) | |
4648 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4649 | else | |
79a45b7d TT |
4650 | { |
4651 | struct value_print_options opts; | |
4652 | get_user_print_options (&opts); | |
4653 | value_print (val, stream, &opts); | |
4654 | } | |
fa4727a6 DJ |
4655 | } |
4656 | ||
e514a9d6 | 4657 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4658 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4659 | 'print_it' in the bpstat structure. Under some circumstances we |
4660 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4661 | normal_stop(). */ |
e514a9d6 JM |
4662 | |
4663 | static enum print_stop_action | |
4664 | print_bp_stop_message (bpstat bs) | |
4665 | { | |
4666 | switch (bs->print_it) | |
4667 | { | |
4668 | case print_it_noop: | |
4a64f543 | 4669 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4670 | return PRINT_UNKNOWN; |
4671 | break; | |
4672 | ||
4673 | case print_it_done: | |
4674 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4675 | relevant messages. */ |
e514a9d6 JM |
4676 | return PRINT_SRC_AND_LOC; |
4677 | break; | |
4678 | ||
4679 | case print_it_normal: | |
4f8d1dc6 | 4680 | { |
f431efe5 PA |
4681 | struct breakpoint *b = bs->breakpoint_at; |
4682 | ||
1a6a67de TJB |
4683 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4684 | which has since been deleted. */ | |
4685 | if (b == NULL) | |
4686 | return PRINT_UNKNOWN; | |
4687 | ||
348d480f PA |
4688 | /* Normal case. Call the breakpoint's print_it method. */ |
4689 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4690 | } |
348d480f | 4691 | break; |
3086aeae | 4692 | |
e514a9d6 | 4693 | default: |
8e65ff28 | 4694 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4695 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4696 | break; |
c906108c | 4697 | } |
c906108c SS |
4698 | } |
4699 | ||
edcc5120 TT |
4700 | /* A helper function that prints a shared library stopped event. */ |
4701 | ||
4702 | static void | |
4703 | print_solib_event (int is_catchpoint) | |
4704 | { | |
4705 | int any_deleted | |
4706 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4707 | int any_added | |
4708 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4709 | ||
4710 | if (!is_catchpoint) | |
4711 | { | |
4712 | if (any_added || any_deleted) | |
4713 | ui_out_text (current_uiout, | |
4714 | _("Stopped due to shared library event:\n")); | |
4715 | else | |
4716 | ui_out_text (current_uiout, | |
4717 | _("Stopped due to shared library event (no " | |
4718 | "libraries added or removed)\n")); | |
4719 | } | |
4720 | ||
4721 | if (ui_out_is_mi_like_p (current_uiout)) | |
4722 | ui_out_field_string (current_uiout, "reason", | |
4723 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4724 | ||
4725 | if (any_deleted) | |
4726 | { | |
4727 | struct cleanup *cleanup; | |
4728 | char *name; | |
4729 | int ix; | |
4730 | ||
4731 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4732 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4733 | "removed"); | |
4734 | for (ix = 0; | |
4735 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4736 | ix, name); | |
4737 | ++ix) | |
4738 | { | |
4739 | if (ix > 0) | |
4740 | ui_out_text (current_uiout, " "); | |
4741 | ui_out_field_string (current_uiout, "library", name); | |
4742 | ui_out_text (current_uiout, "\n"); | |
4743 | } | |
4744 | ||
4745 | do_cleanups (cleanup); | |
4746 | } | |
4747 | ||
4748 | if (any_added) | |
4749 | { | |
4750 | struct so_list *iter; | |
4751 | int ix; | |
4752 | struct cleanup *cleanup; | |
4753 | ||
4754 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4755 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4756 | "added"); | |
4757 | for (ix = 0; | |
4758 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4759 | ix, iter); | |
4760 | ++ix) | |
4761 | { | |
4762 | if (ix > 0) | |
4763 | ui_out_text (current_uiout, " "); | |
4764 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4765 | ui_out_text (current_uiout, "\n"); | |
4766 | } | |
4767 | ||
4768 | do_cleanups (cleanup); | |
4769 | } | |
4770 | } | |
4771 | ||
e514a9d6 JM |
4772 | /* Print a message indicating what happened. This is called from |
4773 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4774 | list - a list of the eventpoints that caused this stop. KIND is |
4775 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4776 | routine calls the generic print routine for printing a message |
4777 | about reasons for stopping. This will print (for example) the | |
4778 | "Breakpoint n," part of the output. The return value of this | |
4779 | routine is one of: | |
c906108c | 4780 | |
4a64f543 | 4781 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4782 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4783 | code to print the location. An example is |
c5aa993b JM |
4784 | "Breakpoint 1, " which should be followed by |
4785 | the location. | |
917317f4 | 4786 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4787 | to also print the location part of the message. |
4788 | An example is the catch/throw messages, which | |
4a64f543 | 4789 | don't require a location appended to the end. |
917317f4 | 4790 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4791 | further info to be printed. */ |
c906108c | 4792 | |
917317f4 | 4793 | enum print_stop_action |
36dfb11c | 4794 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4795 | { |
4796 | int val; | |
c5aa993b | 4797 | |
c906108c | 4798 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4799 | (Currently all watchpoints go on the bpstat whether hit or not. |
4800 | That probably could (should) be changed, provided care is taken | |
c906108c | 4801 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4802 | for (; bs; bs = bs->next) |
4803 | { | |
4804 | val = print_bp_stop_message (bs); | |
4805 | if (val == PRINT_SRC_ONLY | |
4806 | || val == PRINT_SRC_AND_LOC | |
4807 | || val == PRINT_NOTHING) | |
4808 | return val; | |
4809 | } | |
c906108c | 4810 | |
36dfb11c TT |
4811 | /* If we had hit a shared library event breakpoint, |
4812 | print_bp_stop_message would print out this message. If we hit an | |
4813 | OS-level shared library event, do the same thing. */ | |
4814 | if (kind == TARGET_WAITKIND_LOADED) | |
4815 | { | |
edcc5120 | 4816 | print_solib_event (0); |
36dfb11c TT |
4817 | return PRINT_NOTHING; |
4818 | } | |
4819 | ||
e514a9d6 | 4820 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4821 | with and nothing was printed. */ |
917317f4 | 4822 | return PRINT_UNKNOWN; |
c906108c SS |
4823 | } |
4824 | ||
c42bd95a DE |
4825 | /* Evaluate the expression EXP and return 1 if value is zero. |
4826 | This returns the inverse of the condition because it is called | |
4827 | from catch_errors which returns 0 if an exception happened, and if an | |
4828 | exception happens we want execution to stop. | |
4a64f543 | 4829 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4830 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4831 | |
4832 | static int | |
4efb68b1 | 4833 | breakpoint_cond_eval (void *exp) |
c906108c | 4834 | { |
278cd55f | 4835 | struct value *mark = value_mark (); |
c5aa993b | 4836 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4837 | |
c906108c SS |
4838 | value_free_to_mark (mark); |
4839 | return i; | |
4840 | } | |
4841 | ||
5760d0ab | 4842 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4843 | |
4844 | static bpstat | |
5760d0ab | 4845 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4846 | { |
4847 | bpstat bs; | |
4848 | ||
4849 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4850 | bs->next = NULL; |
4851 | **bs_link_pointer = bs; | |
4852 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4853 | bs->breakpoint_at = bl->owner; |
4854 | bs->bp_location_at = bl; | |
4855 | incref_bp_location (bl); | |
c906108c SS |
4856 | /* If the condition is false, etc., don't do the commands. */ |
4857 | bs->commands = NULL; | |
4858 | bs->old_val = NULL; | |
4859 | bs->print_it = print_it_normal; | |
4860 | return bs; | |
4861 | } | |
4862 | \f | |
d983da9c DJ |
4863 | /* The target has stopped with waitstatus WS. Check if any hardware |
4864 | watchpoints have triggered, according to the target. */ | |
4865 | ||
4866 | int | |
4867 | watchpoints_triggered (struct target_waitstatus *ws) | |
4868 | { | |
d92524f1 | 4869 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4870 | CORE_ADDR addr; |
4871 | struct breakpoint *b; | |
4872 | ||
4873 | if (!stopped_by_watchpoint) | |
4874 | { | |
4875 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4876 | as not triggered. */ | |
4877 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4878 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4879 | { |
4880 | struct watchpoint *w = (struct watchpoint *) b; | |
4881 | ||
4882 | w->watchpoint_triggered = watch_triggered_no; | |
4883 | } | |
d983da9c DJ |
4884 | |
4885 | return 0; | |
4886 | } | |
4887 | ||
4888 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4889 | { | |
4890 | /* We were stopped by a watchpoint, but we don't know where. | |
4891 | Mark all watchpoints as unknown. */ | |
4892 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4893 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4894 | { |
4895 | struct watchpoint *w = (struct watchpoint *) b; | |
4896 | ||
4897 | w->watchpoint_triggered = watch_triggered_unknown; | |
4898 | } | |
d983da9c | 4899 | |
3c4797ba | 4900 | return 1; |
d983da9c DJ |
4901 | } |
4902 | ||
4903 | /* The target could report the data address. Mark watchpoints | |
4904 | affected by this data address as triggered, and all others as not | |
4905 | triggered. */ | |
4906 | ||
4907 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4908 | if (is_hardware_watchpoint (b)) |
d983da9c | 4909 | { |
3a5c3e22 | 4910 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4911 | struct bp_location *loc; |
d983da9c | 4912 | |
3a5c3e22 | 4913 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4914 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4915 | { |
3a5c3e22 | 4916 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4917 | { |
3a5c3e22 PA |
4918 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4919 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4920 | |
4921 | if (newaddr == start) | |
4922 | { | |
3a5c3e22 | 4923 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4924 | break; |
4925 | } | |
4926 | } | |
4927 | /* Exact match not required. Within range is sufficient. */ | |
4928 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4929 | addr, loc->address, | |
4930 | loc->length)) | |
4931 | { | |
3a5c3e22 | 4932 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4933 | break; |
4934 | } | |
4935 | } | |
d983da9c DJ |
4936 | } |
4937 | ||
4938 | return 1; | |
4939 | } | |
4940 | ||
c906108c SS |
4941 | /* Possible return values for watchpoint_check (this can't be an enum |
4942 | because of check_errors). */ | |
4943 | /* The watchpoint has been deleted. */ | |
4944 | #define WP_DELETED 1 | |
4945 | /* The value has changed. */ | |
4946 | #define WP_VALUE_CHANGED 2 | |
4947 | /* The value has not changed. */ | |
4948 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4949 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4950 | #define WP_IGNORE 4 | |
c906108c SS |
4951 | |
4952 | #define BP_TEMPFLAG 1 | |
4953 | #define BP_HARDWAREFLAG 2 | |
4954 | ||
4a64f543 MS |
4955 | /* Evaluate watchpoint condition expression and check if its value |
4956 | changed. | |
553e4c11 JB |
4957 | |
4958 | P should be a pointer to struct bpstat, but is defined as a void * | |
4959 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4960 | |
4961 | static int | |
4efb68b1 | 4962 | watchpoint_check (void *p) |
c906108c SS |
4963 | { |
4964 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4965 | struct watchpoint *b; |
c906108c SS |
4966 | struct frame_info *fr; |
4967 | int within_current_scope; | |
4968 | ||
f431efe5 | 4969 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4970 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4971 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4972 | |
f6bc2008 PA |
4973 | /* If this is a local watchpoint, we only want to check if the |
4974 | watchpoint frame is in scope if the current thread is the thread | |
4975 | that was used to create the watchpoint. */ | |
4976 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4977 | return WP_IGNORE; |
f6bc2008 | 4978 | |
c906108c SS |
4979 | if (b->exp_valid_block == NULL) |
4980 | within_current_scope = 1; | |
4981 | else | |
4982 | { | |
edb3359d DJ |
4983 | struct frame_info *frame = get_current_frame (); |
4984 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4985 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4986 | ||
4a64f543 MS |
4987 | /* in_function_epilogue_p() returns a non-zero value if we're |
4988 | still in the function but the stack frame has already been | |
4989 | invalidated. Since we can't rely on the values of local | |
4990 | variables after the stack has been destroyed, we are treating | |
4991 | the watchpoint in that state as `not changed' without further | |
4992 | checking. Don't mark watchpoints as changed if the current | |
4993 | frame is in an epilogue - even if they are in some other | |
4994 | frame, our view of the stack is likely to be wrong and | |
4995 | frame_find_by_id could error out. */ | |
a0f49112 | 4996 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4997 | return WP_IGNORE; |
a0f49112 | 4998 | |
101dcfbe | 4999 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5000 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5001 | |
5002 | /* If we've gotten confused in the unwinder, we might have | |
5003 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5004 | if (within_current_scope) |
5005 | { | |
5006 | struct symbol *function; | |
5007 | ||
5008 | function = get_frame_function (fr); | |
5009 | if (function == NULL | |
5010 | || !contained_in (b->exp_valid_block, | |
5011 | SYMBOL_BLOCK_VALUE (function))) | |
5012 | within_current_scope = 0; | |
5013 | } | |
69fbadd5 | 5014 | |
edb3359d | 5015 | if (within_current_scope) |
c906108c SS |
5016 | /* If we end up stopping, the current frame will get selected |
5017 | in normal_stop. So this call to select_frame won't affect | |
5018 | the user. */ | |
0f7d239c | 5019 | select_frame (fr); |
c906108c | 5020 | } |
c5aa993b | 5021 | |
c906108c SS |
5022 | if (within_current_scope) |
5023 | { | |
4a64f543 MS |
5024 | /* We use value_{,free_to_}mark because it could be a *long* |
5025 | time before we return to the command level and call | |
5026 | free_all_values. We can't call free_all_values because we | |
5027 | might be in the middle of evaluating a function call. */ | |
c906108c | 5028 | |
0cf6dd15 | 5029 | int pc = 0; |
9c06b0b4 | 5030 | struct value *mark; |
fa4727a6 DJ |
5031 | struct value *new_val; |
5032 | ||
3a5c3e22 | 5033 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5034 | /* Since we don't know the exact trigger address (from |
5035 | stopped_data_address), just tell the user we've triggered | |
5036 | a mask watchpoint. */ | |
5037 | return WP_VALUE_CHANGED; | |
5038 | ||
5039 | mark = value_mark (); | |
3a1115a0 | 5040 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5041 | |
4a64f543 MS |
5042 | /* We use value_equal_contents instead of value_equal because |
5043 | the latter coerces an array to a pointer, thus comparing just | |
5044 | the address of the array instead of its contents. This is | |
5045 | not what we want. */ | |
fa4727a6 | 5046 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5047 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5048 | { |
fa4727a6 DJ |
5049 | if (new_val != NULL) |
5050 | { | |
5051 | release_value (new_val); | |
5052 | value_free_to_mark (mark); | |
5053 | } | |
c906108c SS |
5054 | bs->old_val = b->val; |
5055 | b->val = new_val; | |
fa4727a6 | 5056 | b->val_valid = 1; |
c906108c SS |
5057 | return WP_VALUE_CHANGED; |
5058 | } | |
5059 | else | |
5060 | { | |
60e1c644 | 5061 | /* Nothing changed. */ |
c906108c | 5062 | value_free_to_mark (mark); |
c906108c SS |
5063 | return WP_VALUE_NOT_CHANGED; |
5064 | } | |
5065 | } | |
5066 | else | |
5067 | { | |
79a45e25 PA |
5068 | struct ui_out *uiout = current_uiout; |
5069 | ||
c906108c | 5070 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5071 | if we temporarily ignored the watchpoint, then when |
5072 | we reenter the block in which it is valid it contains | |
5073 | garbage (in the case of a function, it may have two | |
5074 | garbage values, one before and one after the prologue). | |
5075 | So we can't even detect the first assignment to it and | |
5076 | watch after that (since the garbage may or may not equal | |
5077 | the first value assigned). */ | |
348d480f PA |
5078 | /* We print all the stop information in |
5079 | breakpoint_ops->print_it, but in this case, by the time we | |
5080 | call breakpoint_ops->print_it this bp will be deleted | |
5081 | already. So we have no choice but print the information | |
5082 | here. */ | |
9dc5e2a9 | 5083 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5084 | ui_out_field_string |
5085 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5086 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5087 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5088 | ui_out_text (uiout, |
5089 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5090 | which its expression is valid.\n"); |
4ce44c66 | 5091 | |
cdac0397 | 5092 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5093 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5094 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5095 | |
5096 | return WP_DELETED; | |
5097 | } | |
5098 | } | |
5099 | ||
18a18393 | 5100 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5101 | breakpoint location BL. This function does not check if we should |
5102 | stop, only if BL explains the stop. */ | |
5103 | ||
18a18393 | 5104 | static int |
6c95b8df | 5105 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5106 | struct address_space *aspace, CORE_ADDR bp_addr, |
5107 | const struct target_waitstatus *ws) | |
18a18393 VP |
5108 | { |
5109 | struct breakpoint *b = bl->owner; | |
5110 | ||
348d480f | 5111 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5112 | gdb_assert (b != NULL); |
5113 | ||
09ac7c10 | 5114 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5115 | } |
5116 | ||
3a5c3e22 PA |
5117 | /* Determine if the watched values have actually changed, and we |
5118 | should stop. If not, set BS->stop to 0. */ | |
5119 | ||
18a18393 VP |
5120 | static void |
5121 | bpstat_check_watchpoint (bpstat bs) | |
5122 | { | |
2bdf28a0 | 5123 | const struct bp_location *bl; |
3a5c3e22 | 5124 | struct watchpoint *b; |
2bdf28a0 JK |
5125 | |
5126 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5127 | bl = bs->bp_location_at; |
2bdf28a0 | 5128 | gdb_assert (bl != NULL); |
3a5c3e22 | 5129 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5130 | gdb_assert (b != NULL); |
18a18393 | 5131 | |
18a18393 | 5132 | { |
18a18393 VP |
5133 | int must_check_value = 0; |
5134 | ||
3a5c3e22 | 5135 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5136 | /* For a software watchpoint, we must always check the |
5137 | watched value. */ | |
5138 | must_check_value = 1; | |
5139 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5140 | /* We have a hardware watchpoint (read, write, or access) | |
5141 | and the target earlier reported an address watched by | |
5142 | this watchpoint. */ | |
5143 | must_check_value = 1; | |
5144 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5145 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5146 | /* We were stopped by a hardware watchpoint, but the target could |
5147 | not report the data address. We must check the watchpoint's | |
5148 | value. Access and read watchpoints are out of luck; without | |
5149 | a data address, we can't figure it out. */ | |
5150 | must_check_value = 1; | |
3a5c3e22 | 5151 | |
18a18393 VP |
5152 | if (must_check_value) |
5153 | { | |
3e43a32a MS |
5154 | char *message |
5155 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5156 | b->base.number); |
18a18393 VP |
5157 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5158 | int e = catch_errors (watchpoint_check, bs, message, | |
5159 | RETURN_MASK_ALL); | |
5160 | do_cleanups (cleanups); | |
5161 | switch (e) | |
5162 | { | |
5163 | case WP_DELETED: | |
5164 | /* We've already printed what needs to be printed. */ | |
5165 | bs->print_it = print_it_done; | |
5166 | /* Stop. */ | |
5167 | break; | |
60e1c644 PA |
5168 | case WP_IGNORE: |
5169 | bs->print_it = print_it_noop; | |
5170 | bs->stop = 0; | |
5171 | break; | |
18a18393 | 5172 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5173 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5174 | { |
85d721b8 PA |
5175 | /* There are two cases to consider here: |
5176 | ||
4a64f543 | 5177 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5178 | In that case, trust the target, and always report |
5179 | the watchpoint hit to the user. Even though | |
5180 | reads don't cause value changes, the value may | |
5181 | have changed since the last time it was read, and | |
5182 | since we're not trapping writes, we will not see | |
5183 | those, and as such we should ignore our notion of | |
5184 | old value. | |
5185 | ||
4a64f543 | 5186 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5187 | reads and writes. There are two ways this may |
5188 | happen: | |
5189 | ||
4a64f543 | 5190 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5191 | reads only, but can break on accesses (reads or |
5192 | writes), such as e.g., x86. We detect this case | |
5193 | at the time we try to insert read watchpoints. | |
5194 | ||
4a64f543 | 5195 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5196 | watchpoints, but, the user set an access or write |
5197 | watchpoint watching the same memory as this read | |
5198 | watchpoint. | |
5199 | ||
5200 | If we're watching memory writes as well as reads, | |
5201 | ignore watchpoint hits when we find that the | |
5202 | value hasn't changed, as reads don't cause | |
5203 | changes. This still gives false positives when | |
5204 | the program writes the same value to memory as | |
5205 | what there was already in memory (we will confuse | |
5206 | it for a read), but it's much better than | |
5207 | nothing. */ | |
5208 | ||
5209 | int other_write_watchpoint = 0; | |
5210 | ||
5211 | if (bl->watchpoint_type == hw_read) | |
5212 | { | |
5213 | struct breakpoint *other_b; | |
5214 | ||
5215 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5216 | if (other_b->type == bp_hardware_watchpoint |
5217 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5218 | { |
3a5c3e22 PA |
5219 | struct watchpoint *other_w = |
5220 | (struct watchpoint *) other_b; | |
5221 | ||
5222 | if (other_w->watchpoint_triggered | |
5223 | == watch_triggered_yes) | |
5224 | { | |
5225 | other_write_watchpoint = 1; | |
5226 | break; | |
5227 | } | |
85d721b8 PA |
5228 | } |
5229 | } | |
5230 | ||
5231 | if (other_write_watchpoint | |
5232 | || bl->watchpoint_type == hw_access) | |
5233 | { | |
5234 | /* We're watching the same memory for writes, | |
5235 | and the value changed since the last time we | |
5236 | updated it, so this trap must be for a write. | |
5237 | Ignore it. */ | |
5238 | bs->print_it = print_it_noop; | |
5239 | bs->stop = 0; | |
5240 | } | |
18a18393 VP |
5241 | } |
5242 | break; | |
5243 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5244 | if (b->base.type == bp_hardware_watchpoint |
5245 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5246 | { |
5247 | /* Don't stop: write watchpoints shouldn't fire if | |
5248 | the value hasn't changed. */ | |
5249 | bs->print_it = print_it_noop; | |
5250 | bs->stop = 0; | |
5251 | } | |
5252 | /* Stop. */ | |
5253 | break; | |
5254 | default: | |
5255 | /* Can't happen. */ | |
5256 | case 0: | |
5257 | /* Error from catch_errors. */ | |
3a5c3e22 | 5258 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5259 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5260 | /* We've already printed what needs to be printed. */ |
5261 | bs->print_it = print_it_done; | |
5262 | break; | |
5263 | } | |
5264 | } | |
5265 | else /* must_check_value == 0 */ | |
5266 | { | |
5267 | /* This is a case where some watchpoint(s) triggered, but | |
5268 | not at the address of this watchpoint, or else no | |
5269 | watchpoint triggered after all. So don't print | |
5270 | anything for this watchpoint. */ | |
5271 | bs->print_it = print_it_noop; | |
5272 | bs->stop = 0; | |
5273 | } | |
5274 | } | |
5275 | } | |
5276 | ||
7d4df6a4 DE |
5277 | /* For breakpoints that are currently marked as telling gdb to stop, |
5278 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5279 | of breakpoint referred to by BS. If we should not stop for this |
5280 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5281 | |
18a18393 VP |
5282 | static void |
5283 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5284 | { | |
2bdf28a0 JK |
5285 | const struct bp_location *bl; |
5286 | struct breakpoint *b; | |
7d4df6a4 DE |
5287 | int value_is_zero = 0; |
5288 | struct expression *cond; | |
5289 | ||
5290 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5291 | |
5292 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5293 | bl = bs->bp_location_at; |
2bdf28a0 | 5294 | gdb_assert (bl != NULL); |
f431efe5 | 5295 | b = bs->breakpoint_at; |
2bdf28a0 | 5296 | gdb_assert (b != NULL); |
18a18393 | 5297 | |
b775012e LM |
5298 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5299 | need to do so again since GDB does not know if we stopped due to a | |
5300 | breakpoint or a single step breakpoint. */ | |
5301 | ||
18a18393 | 5302 | if (frame_id_p (b->frame_id) |
edb3359d | 5303 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5304 | { |
7d4df6a4 DE |
5305 | bs->stop = 0; |
5306 | return; | |
5307 | } | |
60e1c644 | 5308 | |
12ab52e9 PA |
5309 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5310 | evaluating the condition if this isn't the specified | |
5311 | thread/task. */ | |
5312 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5313 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5314 | ||
6c1b0f7b DE |
5315 | { |
5316 | bs->stop = 0; | |
5317 | return; | |
5318 | } | |
5319 | ||
6dddc817 DE |
5320 | /* Evaluate extension language breakpoints that have a "stop" method |
5321 | implemented. */ | |
5322 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5323 | |
7d4df6a4 DE |
5324 | if (is_watchpoint (b)) |
5325 | { | |
5326 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5327 | |
7d4df6a4 DE |
5328 | cond = w->cond_exp; |
5329 | } | |
5330 | else | |
5331 | cond = bl->cond; | |
60e1c644 | 5332 | |
7d4df6a4 DE |
5333 | if (cond && b->disposition != disp_del_at_next_stop) |
5334 | { | |
5335 | int within_current_scope = 1; | |
5336 | struct watchpoint * w; | |
60e1c644 | 5337 | |
7d4df6a4 DE |
5338 | /* We use value_mark and value_free_to_mark because it could |
5339 | be a long time before we return to the command level and | |
5340 | call free_all_values. We can't call free_all_values | |
5341 | because we might be in the middle of evaluating a | |
5342 | function call. */ | |
5343 | struct value *mark = value_mark (); | |
5344 | ||
5345 | if (is_watchpoint (b)) | |
5346 | w = (struct watchpoint *) b; | |
5347 | else | |
5348 | w = NULL; | |
5349 | ||
5350 | /* Need to select the frame, with all that implies so that | |
5351 | the conditions will have the right context. Because we | |
5352 | use the frame, we will not see an inlined function's | |
5353 | variables when we arrive at a breakpoint at the start | |
5354 | of the inlined function; the current frame will be the | |
5355 | call site. */ | |
5356 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5357 | select_frame (get_current_frame ()); | |
5358 | else | |
18a18393 | 5359 | { |
7d4df6a4 DE |
5360 | struct frame_info *frame; |
5361 | ||
5362 | /* For local watchpoint expressions, which particular | |
5363 | instance of a local is being watched matters, so we | |
5364 | keep track of the frame to evaluate the expression | |
5365 | in. To evaluate the condition however, it doesn't | |
5366 | really matter which instantiation of the function | |
5367 | where the condition makes sense triggers the | |
5368 | watchpoint. This allows an expression like "watch | |
5369 | global if q > 10" set in `func', catch writes to | |
5370 | global on all threads that call `func', or catch | |
5371 | writes on all recursive calls of `func' by a single | |
5372 | thread. We simply always evaluate the condition in | |
5373 | the innermost frame that's executing where it makes | |
5374 | sense to evaluate the condition. It seems | |
5375 | intuitive. */ | |
5376 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5377 | if (frame != NULL) | |
5378 | select_frame (frame); | |
5379 | else | |
5380 | within_current_scope = 0; | |
18a18393 | 5381 | } |
7d4df6a4 DE |
5382 | if (within_current_scope) |
5383 | value_is_zero | |
5384 | = catch_errors (breakpoint_cond_eval, cond, | |
5385 | "Error in testing breakpoint condition:\n", | |
5386 | RETURN_MASK_ALL); | |
5387 | else | |
18a18393 | 5388 | { |
7d4df6a4 DE |
5389 | warning (_("Watchpoint condition cannot be tested " |
5390 | "in the current scope")); | |
5391 | /* If we failed to set the right context for this | |
5392 | watchpoint, unconditionally report it. */ | |
5393 | value_is_zero = 0; | |
18a18393 | 5394 | } |
7d4df6a4 DE |
5395 | /* FIXME-someday, should give breakpoint #. */ |
5396 | value_free_to_mark (mark); | |
18a18393 | 5397 | } |
7d4df6a4 DE |
5398 | |
5399 | if (cond && value_is_zero) | |
5400 | { | |
5401 | bs->stop = 0; | |
5402 | } | |
7d4df6a4 DE |
5403 | else if (b->ignore_count > 0) |
5404 | { | |
5405 | b->ignore_count--; | |
5406 | bs->stop = 0; | |
5407 | /* Increase the hit count even though we don't stop. */ | |
5408 | ++(b->hit_count); | |
5409 | observer_notify_breakpoint_modified (b); | |
5410 | } | |
18a18393 VP |
5411 | } |
5412 | ||
5413 | ||
9709f61c | 5414 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5415 | BP_ADDR in thread PTID. |
c906108c | 5416 | |
d983da9c | 5417 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5418 | don't understand this stop. Result is a chain of bpstat's such |
5419 | that: | |
c906108c | 5420 | |
c5aa993b | 5421 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5422 | |
c5aa993b | 5423 | if we understand why we stopped, the result is not null. |
c906108c | 5424 | |
c5aa993b JM |
5425 | Each element of the chain refers to a particular breakpoint or |
5426 | watchpoint at which we have stopped. (We may have stopped for | |
5427 | several reasons concurrently.) | |
c906108c | 5428 | |
c5aa993b JM |
5429 | Each element of the chain has valid next, breakpoint_at, |
5430 | commands, FIXME??? fields. */ | |
c906108c SS |
5431 | |
5432 | bpstat | |
6c95b8df | 5433 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5434 | CORE_ADDR bp_addr, ptid_t ptid, |
5435 | const struct target_waitstatus *ws) | |
c906108c | 5436 | { |
0d381245 | 5437 | struct breakpoint *b = NULL; |
afe38095 | 5438 | struct bp_location *bl; |
20874c92 | 5439 | struct bp_location *loc; |
5760d0ab JK |
5440 | /* First item of allocated bpstat's. */ |
5441 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5442 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5443 | bpstat bs; |
20874c92 | 5444 | int ix; |
429374b8 | 5445 | int need_remove_insert; |
f431efe5 | 5446 | int removed_any; |
c906108c | 5447 | |
f431efe5 PA |
5448 | /* First, build the bpstat chain with locations that explain a |
5449 | target stop, while being careful to not set the target running, | |
5450 | as that may invalidate locations (in particular watchpoint | |
5451 | locations are recreated). Resuming will happen here with | |
5452 | breakpoint conditions or watchpoint expressions that include | |
5453 | inferior function calls. */ | |
c5aa993b | 5454 | |
429374b8 JK |
5455 | ALL_BREAKPOINTS (b) |
5456 | { | |
5457 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5458 | continue; | |
a5606eee | 5459 | |
429374b8 JK |
5460 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5461 | { | |
4a64f543 MS |
5462 | /* For hardware watchpoints, we look only at the first |
5463 | location. The watchpoint_check function will work on the | |
5464 | entire expression, not the individual locations. For | |
5465 | read watchpoints, the watchpoints_triggered function has | |
5466 | checked all locations already. */ | |
429374b8 JK |
5467 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5468 | break; | |
18a18393 | 5469 | |
f6592439 | 5470 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5471 | continue; |
c5aa993b | 5472 | |
09ac7c10 | 5473 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5474 | continue; |
c5aa993b | 5475 | |
4a64f543 MS |
5476 | /* Come here if it's a watchpoint, or if the break address |
5477 | matches. */ | |
c5aa993b | 5478 | |
4a64f543 MS |
5479 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5480 | explain stop. */ | |
c5aa993b | 5481 | |
f431efe5 PA |
5482 | /* Assume we stop. Should we find a watchpoint that is not |
5483 | actually triggered, or if the condition of the breakpoint | |
5484 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5485 | bs->stop = 1; |
5486 | bs->print = 1; | |
d983da9c | 5487 | |
f431efe5 PA |
5488 | /* If this is a scope breakpoint, mark the associated |
5489 | watchpoint as triggered so that we will handle the | |
5490 | out-of-scope event. We'll get to the watchpoint next | |
5491 | iteration. */ | |
d0fb5eae | 5492 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5493 | { |
5494 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5495 | ||
5496 | w->watchpoint_triggered = watch_triggered_yes; | |
5497 | } | |
f431efe5 PA |
5498 | } |
5499 | } | |
5500 | ||
5501 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5502 | { | |
f1310107 | 5503 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5504 | { |
5760d0ab | 5505 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5506 | /* For hits of moribund locations, we should just proceed. */ |
5507 | bs->stop = 0; | |
5508 | bs->print = 0; | |
5509 | bs->print_it = print_it_noop; | |
5510 | } | |
5511 | } | |
5512 | ||
edcc5120 TT |
5513 | /* A bit of special processing for shlib breakpoints. We need to |
5514 | process solib loading here, so that the lists of loaded and | |
5515 | unloaded libraries are correct before we handle "catch load" and | |
5516 | "catch unload". */ | |
5517 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5518 | { | |
5d268276 | 5519 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5520 | { |
5521 | handle_solib_event (); | |
5522 | break; | |
5523 | } | |
5524 | } | |
5525 | ||
f431efe5 PA |
5526 | /* Now go through the locations that caused the target to stop, and |
5527 | check whether we're interested in reporting this stop to higher | |
5528 | layers, or whether we should resume the target transparently. */ | |
5529 | ||
5530 | removed_any = 0; | |
5531 | ||
5760d0ab | 5532 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5533 | { |
5534 | if (!bs->stop) | |
5535 | continue; | |
5536 | ||
f431efe5 | 5537 | b = bs->breakpoint_at; |
348d480f PA |
5538 | b->ops->check_status (bs); |
5539 | if (bs->stop) | |
28010a5d | 5540 | { |
348d480f | 5541 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5542 | |
429374b8 JK |
5543 | if (bs->stop) |
5544 | { | |
5545 | ++(b->hit_count); | |
8d3788bd | 5546 | observer_notify_breakpoint_modified (b); |
c906108c | 5547 | |
4a64f543 | 5548 | /* We will stop here. */ |
429374b8 JK |
5549 | if (b->disposition == disp_disable) |
5550 | { | |
816338b5 SS |
5551 | --(b->enable_count); |
5552 | if (b->enable_count <= 0 | |
5553 | && b->enable_state != bp_permanent) | |
429374b8 | 5554 | b->enable_state = bp_disabled; |
f431efe5 | 5555 | removed_any = 1; |
429374b8 JK |
5556 | } |
5557 | if (b->silent) | |
5558 | bs->print = 0; | |
5559 | bs->commands = b->commands; | |
9add0f1b | 5560 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5561 | if (command_line_is_silent (bs->commands |
5562 | ? bs->commands->commands : NULL)) | |
5563 | bs->print = 0; | |
9d6e6e84 HZ |
5564 | |
5565 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5566 | } |
5567 | ||
348d480f | 5568 | } |
a9b3a50f PA |
5569 | |
5570 | /* Print nothing for this entry if we don't stop or don't | |
5571 | print. */ | |
5572 | if (!bs->stop || !bs->print) | |
5573 | bs->print_it = print_it_noop; | |
429374b8 | 5574 | } |
876fa593 | 5575 | |
d983da9c DJ |
5576 | /* If we aren't stopping, the value of some hardware watchpoint may |
5577 | not have changed, but the intermediate memory locations we are | |
5578 | watching may have. Don't bother if we're stopping; this will get | |
5579 | done later. */ | |
d832cb68 | 5580 | need_remove_insert = 0; |
5760d0ab JK |
5581 | if (! bpstat_causes_stop (bs_head)) |
5582 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5583 | if (!bs->stop |
f431efe5 PA |
5584 | && bs->breakpoint_at |
5585 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5586 | { |
3a5c3e22 PA |
5587 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5588 | ||
5589 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5590 | need_remove_insert = 1; |
d983da9c DJ |
5591 | } |
5592 | ||
d832cb68 | 5593 | if (need_remove_insert) |
2d134ed3 | 5594 | update_global_location_list (1); |
f431efe5 PA |
5595 | else if (removed_any) |
5596 | update_global_location_list (0); | |
d832cb68 | 5597 | |
5760d0ab | 5598 | return bs_head; |
c906108c | 5599 | } |
628fe4e4 JK |
5600 | |
5601 | static void | |
5602 | handle_jit_event (void) | |
5603 | { | |
5604 | struct frame_info *frame; | |
5605 | struct gdbarch *gdbarch; | |
5606 | ||
5607 | /* Switch terminal for any messages produced by | |
5608 | breakpoint_re_set. */ | |
5609 | target_terminal_ours_for_output (); | |
5610 | ||
5611 | frame = get_current_frame (); | |
5612 | gdbarch = get_frame_arch (frame); | |
5613 | ||
5614 | jit_event_handler (gdbarch); | |
5615 | ||
5616 | target_terminal_inferior (); | |
5617 | } | |
5618 | ||
5619 | /* Prepare WHAT final decision for infrun. */ | |
5620 | ||
5621 | /* Decide what infrun needs to do with this bpstat. */ | |
5622 | ||
c906108c | 5623 | struct bpstat_what |
0e30163f | 5624 | bpstat_what (bpstat bs_head) |
c906108c | 5625 | { |
c906108c | 5626 | struct bpstat_what retval; |
628fe4e4 | 5627 | int jit_event = 0; |
0e30163f | 5628 | bpstat bs; |
c906108c | 5629 | |
628fe4e4 | 5630 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5631 | retval.call_dummy = STOP_NONE; |
186c406b | 5632 | retval.is_longjmp = 0; |
628fe4e4 | 5633 | |
0e30163f | 5634 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5635 | { |
628fe4e4 JK |
5636 | /* Extract this BS's action. After processing each BS, we check |
5637 | if its action overrides all we've seem so far. */ | |
5638 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5639 | enum bptype bptype; | |
5640 | ||
c906108c | 5641 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5642 | { |
5643 | /* I suspect this can happen if it was a momentary | |
5644 | breakpoint which has since been deleted. */ | |
5645 | bptype = bp_none; | |
5646 | } | |
20874c92 | 5647 | else |
f431efe5 | 5648 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5649 | |
5650 | switch (bptype) | |
c906108c SS |
5651 | { |
5652 | case bp_none: | |
628fe4e4 | 5653 | break; |
c906108c SS |
5654 | case bp_breakpoint: |
5655 | case bp_hardware_breakpoint: | |
5656 | case bp_until: | |
5657 | case bp_finish: | |
a9b3a50f | 5658 | case bp_shlib_event: |
c906108c SS |
5659 | if (bs->stop) |
5660 | { | |
5661 | if (bs->print) | |
628fe4e4 | 5662 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5663 | else |
628fe4e4 | 5664 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5665 | } |
5666 | else | |
628fe4e4 | 5667 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5668 | break; |
5669 | case bp_watchpoint: | |
5670 | case bp_hardware_watchpoint: | |
5671 | case bp_read_watchpoint: | |
5672 | case bp_access_watchpoint: | |
5673 | if (bs->stop) | |
5674 | { | |
5675 | if (bs->print) | |
628fe4e4 | 5676 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5677 | else |
628fe4e4 | 5678 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5679 | } |
5680 | else | |
628fe4e4 JK |
5681 | { |
5682 | /* There was a watchpoint, but we're not stopping. | |
5683 | This requires no further action. */ | |
5684 | } | |
c906108c SS |
5685 | break; |
5686 | case bp_longjmp: | |
e2e4d78b | 5687 | case bp_longjmp_call_dummy: |
186c406b | 5688 | case bp_exception: |
628fe4e4 | 5689 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5690 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5691 | break; |
5692 | case bp_longjmp_resume: | |
186c406b | 5693 | case bp_exception_resume: |
628fe4e4 | 5694 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5695 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5696 | break; |
5697 | case bp_step_resume: | |
5698 | if (bs->stop) | |
628fe4e4 JK |
5699 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5700 | else | |
c906108c | 5701 | { |
628fe4e4 JK |
5702 | /* It is for the wrong frame. */ |
5703 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5704 | } |
c906108c | 5705 | break; |
2c03e5be PA |
5706 | case bp_hp_step_resume: |
5707 | if (bs->stop) | |
5708 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5709 | else | |
5710 | { | |
5711 | /* It is for the wrong frame. */ | |
5712 | this_action = BPSTAT_WHAT_SINGLE; | |
5713 | } | |
5714 | break; | |
c906108c | 5715 | case bp_watchpoint_scope: |
c4093a6a | 5716 | case bp_thread_event: |
1900040c | 5717 | case bp_overlay_event: |
0fd8e87f | 5718 | case bp_longjmp_master: |
aa7d318d | 5719 | case bp_std_terminate_master: |
186c406b | 5720 | case bp_exception_master: |
628fe4e4 | 5721 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5722 | break; |
ce78b96d | 5723 | case bp_catchpoint: |
c5aa993b JM |
5724 | if (bs->stop) |
5725 | { | |
5726 | if (bs->print) | |
628fe4e4 | 5727 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5728 | else |
628fe4e4 | 5729 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5730 | } |
5731 | else | |
628fe4e4 JK |
5732 | { |
5733 | /* There was a catchpoint, but we're not stopping. | |
5734 | This requires no further action. */ | |
5735 | } | |
5736 | break; | |
628fe4e4 JK |
5737 | case bp_jit_event: |
5738 | jit_event = 1; | |
5739 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5740 | break; |
c906108c | 5741 | case bp_call_dummy: |
53a5351d JM |
5742 | /* Make sure the action is stop (silent or noisy), |
5743 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5744 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5745 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5746 | break; |
5747 | case bp_std_terminate: | |
5748 | /* Make sure the action is stop (silent or noisy), | |
5749 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5750 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5751 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5752 | break; |
1042e4c0 | 5753 | case bp_tracepoint: |
7a697b8d | 5754 | case bp_fast_tracepoint: |
0fb4aa4b | 5755 | case bp_static_tracepoint: |
1042e4c0 SS |
5756 | /* Tracepoint hits should not be reported back to GDB, and |
5757 | if one got through somehow, it should have been filtered | |
5758 | out already. */ | |
5759 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5760 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5761 | break; |
5762 | case bp_gnu_ifunc_resolver: | |
5763 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5764 | this_action = BPSTAT_WHAT_SINGLE; | |
5765 | break; | |
5766 | case bp_gnu_ifunc_resolver_return: | |
5767 | /* The breakpoint will be removed, execution will restart from the | |
5768 | PC of the former breakpoint. */ | |
5769 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5770 | break; | |
e7e0cddf SS |
5771 | |
5772 | case bp_dprintf: | |
a11cfd87 HZ |
5773 | if (bs->stop) |
5774 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5775 | else | |
5776 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5777 | break; |
5778 | ||
628fe4e4 JK |
5779 | default: |
5780 | internal_error (__FILE__, __LINE__, | |
5781 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5782 | } |
628fe4e4 JK |
5783 | |
5784 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5785 | } |
628fe4e4 | 5786 | |
0e30163f JK |
5787 | /* These operations may affect the bs->breakpoint_at state so they are |
5788 | delayed after MAIN_ACTION is decided above. */ | |
5789 | ||
628fe4e4 JK |
5790 | if (jit_event) |
5791 | { | |
5792 | if (debug_infrun) | |
5793 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5794 | ||
5795 | handle_jit_event (); | |
5796 | } | |
5797 | ||
0e30163f JK |
5798 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5799 | { | |
5800 | struct breakpoint *b = bs->breakpoint_at; | |
5801 | ||
5802 | if (b == NULL) | |
5803 | continue; | |
5804 | switch (b->type) | |
5805 | { | |
5806 | case bp_gnu_ifunc_resolver: | |
5807 | gnu_ifunc_resolver_stop (b); | |
5808 | break; | |
5809 | case bp_gnu_ifunc_resolver_return: | |
5810 | gnu_ifunc_resolver_return_stop (b); | |
5811 | break; | |
5812 | } | |
5813 | } | |
5814 | ||
c906108c SS |
5815 | return retval; |
5816 | } | |
5817 | ||
5818 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5819 | without hardware support). This isn't related to a specific bpstat, | |
5820 | just to things like whether watchpoints are set. */ | |
5821 | ||
c5aa993b | 5822 | int |
fba45db2 | 5823 | bpstat_should_step (void) |
c906108c SS |
5824 | { |
5825 | struct breakpoint *b; | |
cc59ec59 | 5826 | |
c906108c | 5827 | ALL_BREAKPOINTS (b) |
717a8278 | 5828 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5829 | return 1; |
c906108c SS |
5830 | return 0; |
5831 | } | |
5832 | ||
67822962 PA |
5833 | int |
5834 | bpstat_causes_stop (bpstat bs) | |
5835 | { | |
5836 | for (; bs != NULL; bs = bs->next) | |
5837 | if (bs->stop) | |
5838 | return 1; | |
5839 | ||
5840 | return 0; | |
5841 | } | |
5842 | ||
c906108c | 5843 | \f |
c5aa993b | 5844 | |
170b53b2 UW |
5845 | /* Compute a string of spaces suitable to indent the next line |
5846 | so it starts at the position corresponding to the table column | |
5847 | named COL_NAME in the currently active table of UIOUT. */ | |
5848 | ||
5849 | static char * | |
5850 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5851 | { | |
5852 | static char wrap_indent[80]; | |
5853 | int i, total_width, width, align; | |
5854 | char *text; | |
5855 | ||
5856 | total_width = 0; | |
5857 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5858 | { | |
5859 | if (strcmp (text, col_name) == 0) | |
5860 | { | |
5861 | gdb_assert (total_width < sizeof wrap_indent); | |
5862 | memset (wrap_indent, ' ', total_width); | |
5863 | wrap_indent[total_width] = 0; | |
5864 | ||
5865 | return wrap_indent; | |
5866 | } | |
5867 | ||
5868 | total_width += width + 1; | |
5869 | } | |
5870 | ||
5871 | return NULL; | |
5872 | } | |
5873 | ||
b775012e LM |
5874 | /* Determine if the locations of this breakpoint will have their conditions |
5875 | evaluated by the target, host or a mix of both. Returns the following: | |
5876 | ||
5877 | "host": Host evals condition. | |
5878 | "host or target": Host or Target evals condition. | |
5879 | "target": Target evals condition. | |
5880 | */ | |
5881 | ||
5882 | static const char * | |
5883 | bp_condition_evaluator (struct breakpoint *b) | |
5884 | { | |
5885 | struct bp_location *bl; | |
5886 | char host_evals = 0; | |
5887 | char target_evals = 0; | |
5888 | ||
5889 | if (!b) | |
5890 | return NULL; | |
5891 | ||
5892 | if (!is_breakpoint (b)) | |
5893 | return NULL; | |
5894 | ||
5895 | if (gdb_evaluates_breakpoint_condition_p () | |
5896 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5897 | return condition_evaluation_host; | |
5898 | ||
5899 | for (bl = b->loc; bl; bl = bl->next) | |
5900 | { | |
5901 | if (bl->cond_bytecode) | |
5902 | target_evals++; | |
5903 | else | |
5904 | host_evals++; | |
5905 | } | |
5906 | ||
5907 | if (host_evals && target_evals) | |
5908 | return condition_evaluation_both; | |
5909 | else if (target_evals) | |
5910 | return condition_evaluation_target; | |
5911 | else | |
5912 | return condition_evaluation_host; | |
5913 | } | |
5914 | ||
5915 | /* Determine the breakpoint location's condition evaluator. This is | |
5916 | similar to bp_condition_evaluator, but for locations. */ | |
5917 | ||
5918 | static const char * | |
5919 | bp_location_condition_evaluator (struct bp_location *bl) | |
5920 | { | |
5921 | if (bl && !is_breakpoint (bl->owner)) | |
5922 | return NULL; | |
5923 | ||
5924 | if (gdb_evaluates_breakpoint_condition_p () | |
5925 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5926 | return condition_evaluation_host; | |
5927 | ||
5928 | if (bl && bl->cond_bytecode) | |
5929 | return condition_evaluation_target; | |
5930 | else | |
5931 | return condition_evaluation_host; | |
5932 | } | |
5933 | ||
859825b8 JK |
5934 | /* Print the LOC location out of the list of B->LOC locations. */ |
5935 | ||
170b53b2 UW |
5936 | static void |
5937 | print_breakpoint_location (struct breakpoint *b, | |
5938 | struct bp_location *loc) | |
0d381245 | 5939 | { |
79a45e25 | 5940 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5941 | struct cleanup *old_chain = save_current_program_space (); |
5942 | ||
859825b8 JK |
5943 | if (loc != NULL && loc->shlib_disabled) |
5944 | loc = NULL; | |
5945 | ||
6c95b8df PA |
5946 | if (loc != NULL) |
5947 | set_current_program_space (loc->pspace); | |
5948 | ||
56435ebe TT |
5949 | if (b->display_canonical) |
5950 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5951 | else if (loc && loc->symtab) |
0d381245 VP |
5952 | { |
5953 | struct symbol *sym | |
5954 | = find_pc_sect_function (loc->address, loc->section); | |
5955 | if (sym) | |
5956 | { | |
5957 | ui_out_text (uiout, "in "); | |
5958 | ui_out_field_string (uiout, "func", | |
5959 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5960 | ui_out_text (uiout, " "); |
5961 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5962 | ui_out_text (uiout, "at "); | |
0d381245 | 5963 | } |
05cba821 JK |
5964 | ui_out_field_string (uiout, "file", |
5965 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5966 | ui_out_text (uiout, ":"); |
05cba821 | 5967 | |
0d381245 | 5968 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5969 | ui_out_field_string (uiout, "fullname", |
5970 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5971 | |
f8eba3c6 | 5972 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5973 | } |
859825b8 | 5974 | else if (loc) |
0d381245 | 5975 | { |
f99d8bf4 PA |
5976 | struct ui_file *stb = mem_fileopen (); |
5977 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5978 | |
f99d8bf4 | 5979 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5980 | demangle, ""); |
0d381245 | 5981 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5982 | |
5983 | do_cleanups (stb_chain); | |
0d381245 | 5984 | } |
859825b8 JK |
5985 | else |
5986 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5987 | |
b775012e LM |
5988 | if (loc && is_breakpoint (b) |
5989 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5990 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5991 | { | |
5992 | ui_out_text (uiout, " ("); | |
5993 | ui_out_field_string (uiout, "evaluated-by", | |
5994 | bp_location_condition_evaluator (loc)); | |
5995 | ui_out_text (uiout, ")"); | |
5996 | } | |
5997 | ||
6c95b8df | 5998 | do_cleanups (old_chain); |
0d381245 VP |
5999 | } |
6000 | ||
269b11a2 PA |
6001 | static const char * |
6002 | bptype_string (enum bptype type) | |
c906108c | 6003 | { |
c4093a6a JM |
6004 | struct ep_type_description |
6005 | { | |
6006 | enum bptype type; | |
6007 | char *description; | |
6008 | }; | |
6009 | static struct ep_type_description bptypes[] = | |
c906108c | 6010 | { |
c5aa993b JM |
6011 | {bp_none, "?deleted?"}, |
6012 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6013 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
6014 | {bp_until, "until"}, |
6015 | {bp_finish, "finish"}, | |
6016 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6017 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6018 | {bp_read_watchpoint, "read watchpoint"}, |
6019 | {bp_access_watchpoint, "acc watchpoint"}, | |
6020 | {bp_longjmp, "longjmp"}, | |
6021 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6022 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6023 | {bp_exception, "exception"}, |
6024 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6025 | {bp_step_resume, "step resume"}, |
2c03e5be | 6026 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6027 | {bp_watchpoint_scope, "watchpoint scope"}, |
6028 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6029 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6030 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6031 | {bp_thread_event, "thread events"}, |
1900040c | 6032 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6033 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6034 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6035 | {bp_exception_master, "exception master"}, |
ce78b96d | 6036 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6037 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6038 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6039 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6040 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6041 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6042 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6043 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6044 | }; |
269b11a2 PA |
6045 | |
6046 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6047 | || ((int) type != bptypes[(int) type].type)) | |
6048 | internal_error (__FILE__, __LINE__, | |
6049 | _("bptypes table does not describe type #%d."), | |
6050 | (int) type); | |
6051 | ||
6052 | return bptypes[(int) type].description; | |
6053 | } | |
6054 | ||
998580f1 MK |
6055 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6056 | For CLI, prefix the list with the string 'inf'. */ | |
6057 | ||
6058 | static void | |
6059 | output_thread_groups (struct ui_out *uiout, | |
6060 | const char *field_name, | |
6061 | VEC(int) *inf_num, | |
6062 | int mi_only) | |
6063 | { | |
752eb8b4 | 6064 | struct cleanup *back_to; |
998580f1 MK |
6065 | int is_mi = ui_out_is_mi_like_p (uiout); |
6066 | int inf; | |
6067 | int i; | |
6068 | ||
6069 | /* For backward compatibility, don't display inferiors in CLI unless | |
6070 | there are several. Always display them for MI. */ | |
6071 | if (!is_mi && mi_only) | |
6072 | return; | |
6073 | ||
752eb8b4 TT |
6074 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6075 | ||
998580f1 MK |
6076 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6077 | { | |
6078 | if (is_mi) | |
6079 | { | |
6080 | char mi_group[10]; | |
6081 | ||
6082 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6083 | ui_out_field_string (uiout, NULL, mi_group); | |
6084 | } | |
6085 | else | |
6086 | { | |
6087 | if (i == 0) | |
6088 | ui_out_text (uiout, " inf "); | |
6089 | else | |
6090 | ui_out_text (uiout, ", "); | |
6091 | ||
6092 | ui_out_text (uiout, plongest (inf)); | |
6093 | } | |
6094 | } | |
6095 | ||
6096 | do_cleanups (back_to); | |
6097 | } | |
6098 | ||
269b11a2 PA |
6099 | /* Print B to gdb_stdout. */ |
6100 | ||
6101 | static void | |
6102 | print_one_breakpoint_location (struct breakpoint *b, | |
6103 | struct bp_location *loc, | |
6104 | int loc_number, | |
6105 | struct bp_location **last_loc, | |
269b11a2 PA |
6106 | int allflag) |
6107 | { | |
6108 | struct command_line *l; | |
c2c6d25f | 6109 | static char bpenables[] = "nynny"; |
c906108c | 6110 | |
79a45e25 | 6111 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6112 | int header_of_multiple = 0; |
6113 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6114 | struct value_print_options opts; |
6115 | ||
6116 | get_user_print_options (&opts); | |
0d381245 VP |
6117 | |
6118 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6119 | /* See comment in print_one_breakpoint concerning treatment of |
6120 | breakpoints with single disabled location. */ | |
0d381245 VP |
6121 | if (loc == NULL |
6122 | && (b->loc != NULL | |
6123 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6124 | header_of_multiple = 1; | |
6125 | if (loc == NULL) | |
6126 | loc = b->loc; | |
6127 | ||
c4093a6a JM |
6128 | annotate_record (); |
6129 | ||
6130 | /* 1 */ | |
6131 | annotate_field (0); | |
0d381245 VP |
6132 | if (part_of_multiple) |
6133 | { | |
6134 | char *formatted; | |
0c6773c1 | 6135 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6136 | ui_out_field_string (uiout, "number", formatted); |
6137 | xfree (formatted); | |
6138 | } | |
6139 | else | |
6140 | { | |
6141 | ui_out_field_int (uiout, "number", b->number); | |
6142 | } | |
c4093a6a JM |
6143 | |
6144 | /* 2 */ | |
6145 | annotate_field (1); | |
0d381245 VP |
6146 | if (part_of_multiple) |
6147 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6148 | else |
6149 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6150 | |
6151 | /* 3 */ | |
6152 | annotate_field (2); | |
0d381245 VP |
6153 | if (part_of_multiple) |
6154 | ui_out_field_skip (uiout, "disp"); | |
6155 | else | |
2cec12e5 | 6156 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6157 | |
c4093a6a JM |
6158 | |
6159 | /* 4 */ | |
6160 | annotate_field (3); | |
0d381245 | 6161 | if (part_of_multiple) |
54e52265 | 6162 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6163 | else |
4a64f543 MS |
6164 | ui_out_field_fmt (uiout, "enabled", "%c", |
6165 | bpenables[(int) b->enable_state]); | |
54e52265 | 6166 | ui_out_spaces (uiout, 2); |
0d381245 | 6167 | |
c4093a6a JM |
6168 | |
6169 | /* 5 and 6 */ | |
3086aeae | 6170 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6171 | { |
4a64f543 MS |
6172 | /* Although the print_one can possibly print all locations, |
6173 | calling it here is not likely to get any nice result. So, | |
6174 | make sure there's just one location. */ | |
0d381245 | 6175 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6176 | b->ops->print_one (b, last_loc); |
0d381245 | 6177 | } |
3086aeae DJ |
6178 | else |
6179 | switch (b->type) | |
6180 | { | |
6181 | case bp_none: | |
6182 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6183 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6184 | break; |
c906108c | 6185 | |
3086aeae DJ |
6186 | case bp_watchpoint: |
6187 | case bp_hardware_watchpoint: | |
6188 | case bp_read_watchpoint: | |
6189 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6190 | { |
6191 | struct watchpoint *w = (struct watchpoint *) b; | |
6192 | ||
6193 | /* Field 4, the address, is omitted (which makes the columns | |
6194 | not line up too nicely with the headers, but the effect | |
6195 | is relatively readable). */ | |
6196 | if (opts.addressprint) | |
6197 | ui_out_field_skip (uiout, "addr"); | |
6198 | annotate_field (5); | |
6199 | ui_out_field_string (uiout, "what", w->exp_string); | |
6200 | } | |
3086aeae DJ |
6201 | break; |
6202 | ||
3086aeae DJ |
6203 | case bp_breakpoint: |
6204 | case bp_hardware_breakpoint: | |
6205 | case bp_until: | |
6206 | case bp_finish: | |
6207 | case bp_longjmp: | |
6208 | case bp_longjmp_resume: | |
e2e4d78b | 6209 | case bp_longjmp_call_dummy: |
186c406b TT |
6210 | case bp_exception: |
6211 | case bp_exception_resume: | |
3086aeae | 6212 | case bp_step_resume: |
2c03e5be | 6213 | case bp_hp_step_resume: |
3086aeae DJ |
6214 | case bp_watchpoint_scope: |
6215 | case bp_call_dummy: | |
aa7d318d | 6216 | case bp_std_terminate: |
3086aeae DJ |
6217 | case bp_shlib_event: |
6218 | case bp_thread_event: | |
6219 | case bp_overlay_event: | |
0fd8e87f | 6220 | case bp_longjmp_master: |
aa7d318d | 6221 | case bp_std_terminate_master: |
186c406b | 6222 | case bp_exception_master: |
1042e4c0 | 6223 | case bp_tracepoint: |
7a697b8d | 6224 | case bp_fast_tracepoint: |
0fb4aa4b | 6225 | case bp_static_tracepoint: |
e7e0cddf | 6226 | case bp_dprintf: |
4efc6507 | 6227 | case bp_jit_event: |
0e30163f JK |
6228 | case bp_gnu_ifunc_resolver: |
6229 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6230 | if (opts.addressprint) |
3086aeae DJ |
6231 | { |
6232 | annotate_field (4); | |
54e52265 | 6233 | if (header_of_multiple) |
0d381245 | 6234 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6235 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6236 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6237 | else |
5af949e3 UW |
6238 | ui_out_field_core_addr (uiout, "addr", |
6239 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6240 | } |
6241 | annotate_field (5); | |
0d381245 | 6242 | if (!header_of_multiple) |
170b53b2 | 6243 | print_breakpoint_location (b, loc); |
0d381245 | 6244 | if (b->loc) |
a6d9a66e | 6245 | *last_loc = b->loc; |
3086aeae DJ |
6246 | break; |
6247 | } | |
c906108c | 6248 | |
6c95b8df | 6249 | |
998580f1 | 6250 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6251 | { |
6252 | struct inferior *inf; | |
998580f1 MK |
6253 | VEC(int) *inf_num = NULL; |
6254 | int mi_only = 1; | |
6c95b8df | 6255 | |
998580f1 | 6256 | ALL_INFERIORS (inf) |
6c95b8df PA |
6257 | { |
6258 | if (inf->pspace == loc->pspace) | |
998580f1 | 6259 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6260 | } |
998580f1 MK |
6261 | |
6262 | /* For backward compatibility, don't display inferiors in CLI unless | |
6263 | there are several. Always display for MI. */ | |
6264 | if (allflag | |
6265 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6266 | && (number_of_program_spaces () > 1 | |
6267 | || number_of_inferiors () > 1) | |
6268 | /* LOC is for existing B, it cannot be in | |
6269 | moribund_locations and thus having NULL OWNER. */ | |
6270 | && loc->owner->type != bp_catchpoint)) | |
6271 | mi_only = 0; | |
6272 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6273 | VEC_free (int, inf_num); | |
6c95b8df PA |
6274 | } |
6275 | ||
4a306c9a | 6276 | if (!part_of_multiple) |
c4093a6a | 6277 | { |
4a306c9a JB |
6278 | if (b->thread != -1) |
6279 | { | |
6280 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6281 | "stop only in" line a little further down. */ |
4a306c9a JB |
6282 | ui_out_text (uiout, " thread "); |
6283 | ui_out_field_int (uiout, "thread", b->thread); | |
6284 | } | |
6285 | else if (b->task != 0) | |
6286 | { | |
6287 | ui_out_text (uiout, " task "); | |
6288 | ui_out_field_int (uiout, "task", b->task); | |
6289 | } | |
c4093a6a | 6290 | } |
f1310107 | 6291 | |
8b93c638 | 6292 | ui_out_text (uiout, "\n"); |
f1310107 | 6293 | |
348d480f | 6294 | if (!part_of_multiple) |
f1310107 TJB |
6295 | b->ops->print_one_detail (b, uiout); |
6296 | ||
0d381245 | 6297 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6298 | { |
6299 | annotate_field (6); | |
8b93c638 | 6300 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6301 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6302 | the frame ID. */ |
5af949e3 UW |
6303 | ui_out_field_core_addr (uiout, "frame", |
6304 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6305 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6306 | } |
6307 | ||
28010a5d | 6308 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6309 | { |
6310 | annotate_field (7); | |
d77f58be | 6311 | if (is_tracepoint (b)) |
1042e4c0 SS |
6312 | ui_out_text (uiout, "\ttrace only if "); |
6313 | else | |
6314 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6315 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6316 | |
6317 | /* Print whether the target is doing the breakpoint's condition | |
6318 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6319 | if (is_breakpoint (b) | |
6320 | && breakpoint_condition_evaluation_mode () | |
6321 | == condition_evaluation_target) | |
6322 | { | |
6323 | ui_out_text (uiout, " ("); | |
6324 | ui_out_field_string (uiout, "evaluated-by", | |
6325 | bp_condition_evaluator (b)); | |
6326 | ui_out_text (uiout, " evals)"); | |
6327 | } | |
0101ce28 JJ |
6328 | ui_out_text (uiout, "\n"); |
6329 | } | |
6330 | ||
0d381245 | 6331 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6332 | { |
4a64f543 | 6333 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6334 | ui_out_text (uiout, "\tstop only in thread "); |
6335 | ui_out_field_int (uiout, "thread", b->thread); | |
6336 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6337 | } |
6338 | ||
556ec64d YQ |
6339 | if (!part_of_multiple) |
6340 | { | |
6341 | if (b->hit_count) | |
31f56a27 YQ |
6342 | { |
6343 | /* FIXME should make an annotation for this. */ | |
6344 | if (is_catchpoint (b)) | |
6345 | ui_out_text (uiout, "\tcatchpoint"); | |
6346 | else if (is_tracepoint (b)) | |
6347 | ui_out_text (uiout, "\ttracepoint"); | |
6348 | else | |
6349 | ui_out_text (uiout, "\tbreakpoint"); | |
6350 | ui_out_text (uiout, " already hit "); | |
6351 | ui_out_field_int (uiout, "times", b->hit_count); | |
6352 | if (b->hit_count == 1) | |
6353 | ui_out_text (uiout, " time\n"); | |
6354 | else | |
6355 | ui_out_text (uiout, " times\n"); | |
6356 | } | |
556ec64d YQ |
6357 | else |
6358 | { | |
31f56a27 YQ |
6359 | /* Output the count also if it is zero, but only if this is mi. */ |
6360 | if (ui_out_is_mi_like_p (uiout)) | |
6361 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6362 | } |
6363 | } | |
8b93c638 | 6364 | |
0d381245 | 6365 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6366 | { |
6367 | annotate_field (8); | |
8b93c638 JM |
6368 | ui_out_text (uiout, "\tignore next "); |
6369 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6370 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6371 | } |
059fb39f | 6372 | |
816338b5 SS |
6373 | /* Note that an enable count of 1 corresponds to "enable once" |
6374 | behavior, which is reported by the combination of enablement and | |
6375 | disposition, so we don't need to mention it here. */ | |
6376 | if (!part_of_multiple && b->enable_count > 1) | |
6377 | { | |
6378 | annotate_field (8); | |
6379 | ui_out_text (uiout, "\tdisable after "); | |
6380 | /* Tweak the wording to clarify that ignore and enable counts | |
6381 | are distinct, and have additive effect. */ | |
6382 | if (b->ignore_count) | |
6383 | ui_out_text (uiout, "additional "); | |
6384 | else | |
6385 | ui_out_text (uiout, "next "); | |
6386 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6387 | ui_out_text (uiout, " hits\n"); | |
6388 | } | |
6389 | ||
f196051f SS |
6390 | if (!part_of_multiple && is_tracepoint (b)) |
6391 | { | |
6392 | struct tracepoint *tp = (struct tracepoint *) b; | |
6393 | ||
6394 | if (tp->traceframe_usage) | |
6395 | { | |
6396 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6397 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6398 | ui_out_text (uiout, " bytes\n"); | |
6399 | } | |
6400 | } | |
d3ce09f5 | 6401 | |
9add0f1b | 6402 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6403 | if (!part_of_multiple && l) |
c4093a6a | 6404 | { |
3b31d625 EZ |
6405 | struct cleanup *script_chain; |
6406 | ||
c4093a6a | 6407 | annotate_field (9); |
3b31d625 | 6408 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6409 | print_command_lines (uiout, l, 4); |
3b31d625 | 6410 | do_cleanups (script_chain); |
c4093a6a | 6411 | } |
d24317b4 | 6412 | |
d9b3f62e | 6413 | if (is_tracepoint (b)) |
1042e4c0 | 6414 | { |
d9b3f62e PA |
6415 | struct tracepoint *t = (struct tracepoint *) b; |
6416 | ||
6417 | if (!part_of_multiple && t->pass_count) | |
6418 | { | |
6419 | annotate_field (10); | |
6420 | ui_out_text (uiout, "\tpass count "); | |
6421 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6422 | ui_out_text (uiout, " \n"); | |
6423 | } | |
f2a8bc8a YQ |
6424 | |
6425 | /* Don't display it when tracepoint or tracepoint location is | |
6426 | pending. */ | |
6427 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6428 | { | |
6429 | annotate_field (11); | |
6430 | ||
6431 | if (ui_out_is_mi_like_p (uiout)) | |
6432 | ui_out_field_string (uiout, "installed", | |
6433 | loc->inserted ? "y" : "n"); | |
6434 | else | |
6435 | { | |
6436 | if (loc->inserted) | |
6437 | ui_out_text (uiout, "\t"); | |
6438 | else | |
6439 | ui_out_text (uiout, "\tnot "); | |
6440 | ui_out_text (uiout, "installed on target\n"); | |
6441 | } | |
6442 | } | |
1042e4c0 SS |
6443 | } |
6444 | ||
d24317b4 VP |
6445 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6446 | { | |
3a5c3e22 PA |
6447 | if (is_watchpoint (b)) |
6448 | { | |
6449 | struct watchpoint *w = (struct watchpoint *) b; | |
6450 | ||
6451 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6452 | } | |
6453 | else if (b->addr_string) | |
d24317b4 | 6454 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6455 | } |
c4093a6a | 6456 | } |
c5aa993b | 6457 | |
0d381245 VP |
6458 | static void |
6459 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6460 | struct bp_location **last_loc, |
6c95b8df | 6461 | int allflag) |
0d381245 | 6462 | { |
8d3788bd | 6463 | struct cleanup *bkpt_chain; |
79a45e25 | 6464 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6465 | |
6466 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6467 | ||
12c5a436 | 6468 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6469 | do_cleanups (bkpt_chain); |
0d381245 VP |
6470 | |
6471 | /* If this breakpoint has custom print function, | |
6472 | it's already printed. Otherwise, print individual | |
6473 | locations, if any. */ | |
6474 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6475 | { | |
4a64f543 MS |
6476 | /* If breakpoint has a single location that is disabled, we |
6477 | print it as if it had several locations, since otherwise it's | |
6478 | hard to represent "breakpoint enabled, location disabled" | |
6479 | situation. | |
6480 | ||
6481 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6482 | internally, that's not a property exposed to user. */ |
0d381245 | 6483 | if (b->loc |
a5606eee | 6484 | && !is_hardware_watchpoint (b) |
8d3788bd | 6485 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6486 | { |
6487 | struct bp_location *loc; | |
6488 | int n = 1; | |
8d3788bd | 6489 | |
0d381245 | 6490 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6491 | { |
6492 | struct cleanup *inner2 = | |
6493 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6494 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6495 | do_cleanups (inner2); | |
6496 | } | |
0d381245 VP |
6497 | } |
6498 | } | |
6499 | } | |
6500 | ||
a6d9a66e UW |
6501 | static int |
6502 | breakpoint_address_bits (struct breakpoint *b) | |
6503 | { | |
6504 | int print_address_bits = 0; | |
6505 | struct bp_location *loc; | |
6506 | ||
6507 | for (loc = b->loc; loc; loc = loc->next) | |
6508 | { | |
c7437ca6 PA |
6509 | int addr_bit; |
6510 | ||
6511 | /* Software watchpoints that aren't watching memory don't have | |
6512 | an address to print. */ | |
6513 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6514 | continue; | |
6515 | ||
6516 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6517 | if (addr_bit > print_address_bits) |
6518 | print_address_bits = addr_bit; | |
6519 | } | |
6520 | ||
6521 | return print_address_bits; | |
6522 | } | |
0d381245 | 6523 | |
c4093a6a JM |
6524 | struct captured_breakpoint_query_args |
6525 | { | |
6526 | int bnum; | |
6527 | }; | |
c5aa993b | 6528 | |
c4093a6a | 6529 | static int |
2b65245e | 6530 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6531 | { |
6532 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6533 | struct breakpoint *b; |
a6d9a66e | 6534 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6535 | |
c4093a6a JM |
6536 | ALL_BREAKPOINTS (b) |
6537 | { | |
6538 | if (args->bnum == b->number) | |
c5aa993b | 6539 | { |
12c5a436 | 6540 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6541 | return GDB_RC_OK; |
c5aa993b | 6542 | } |
c4093a6a JM |
6543 | } |
6544 | return GDB_RC_NONE; | |
6545 | } | |
c5aa993b | 6546 | |
c4093a6a | 6547 | enum gdb_rc |
4a64f543 MS |
6548 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6549 | char **error_message) | |
c4093a6a JM |
6550 | { |
6551 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6552 | |
c4093a6a JM |
6553 | args.bnum = bnum; |
6554 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6555 | an error. */ |
b0b13bb4 DJ |
6556 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6557 | error_message, RETURN_MASK_ALL) < 0) | |
6558 | return GDB_RC_FAIL; | |
6559 | else | |
6560 | return GDB_RC_OK; | |
c4093a6a | 6561 | } |
c5aa993b | 6562 | |
09d682a4 TT |
6563 | /* Return true if this breakpoint was set by the user, false if it is |
6564 | internal or momentary. */ | |
6565 | ||
6566 | int | |
6567 | user_breakpoint_p (struct breakpoint *b) | |
6568 | { | |
46c6471b | 6569 | return b->number > 0; |
09d682a4 TT |
6570 | } |
6571 | ||
7f3b0473 | 6572 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6573 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6574 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6575 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6576 | ones for which it returns non-zero. Return the total number of | |
6577 | breakpoints listed. */ | |
c906108c | 6578 | |
d77f58be | 6579 | static int |
e5a67952 | 6580 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6581 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6582 | { |
52f0bd74 | 6583 | struct breakpoint *b; |
a6d9a66e | 6584 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6585 | int nr_printable_breakpoints; |
3b31d625 | 6586 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6587 | struct value_print_options opts; |
a6d9a66e | 6588 | int print_address_bits = 0; |
269b11a2 | 6589 | int print_type_col_width = 14; |
79a45e25 | 6590 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6591 | |
79a45b7d TT |
6592 | get_user_print_options (&opts); |
6593 | ||
4a64f543 MS |
6594 | /* Compute the number of rows in the table, as well as the size |
6595 | required for address fields. */ | |
7f3b0473 AC |
6596 | nr_printable_breakpoints = 0; |
6597 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6598 | { |
6599 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6600 | if (filter && !filter (b)) | |
6601 | continue; | |
6602 | ||
6603 | /* If we have an "args" string, it is a list of breakpoints to | |
6604 | accept. Skip the others. */ | |
6605 | if (args != NULL && *args != '\0') | |
6606 | { | |
6607 | if (allflag && parse_and_eval_long (args) != b->number) | |
6608 | continue; | |
6609 | if (!allflag && !number_is_in_list (args, b->number)) | |
6610 | continue; | |
6611 | } | |
269b11a2 | 6612 | |
e5a67952 MS |
6613 | if (allflag || user_breakpoint_p (b)) |
6614 | { | |
6615 | int addr_bit, type_len; | |
a6d9a66e | 6616 | |
e5a67952 MS |
6617 | addr_bit = breakpoint_address_bits (b); |
6618 | if (addr_bit > print_address_bits) | |
6619 | print_address_bits = addr_bit; | |
269b11a2 | 6620 | |
e5a67952 MS |
6621 | type_len = strlen (bptype_string (b->type)); |
6622 | if (type_len > print_type_col_width) | |
6623 | print_type_col_width = type_len; | |
6624 | ||
6625 | nr_printable_breakpoints++; | |
6626 | } | |
6627 | } | |
7f3b0473 | 6628 | |
79a45b7d | 6629 | if (opts.addressprint) |
3b31d625 | 6630 | bkpttbl_chain |
3e43a32a MS |
6631 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6632 | nr_printable_breakpoints, | |
3b31d625 | 6633 | "BreakpointTable"); |
8b93c638 | 6634 | else |
3b31d625 | 6635 | bkpttbl_chain |
3e43a32a MS |
6636 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6637 | nr_printable_breakpoints, | |
3b31d625 | 6638 | "BreakpointTable"); |
8b93c638 | 6639 | |
7f3b0473 | 6640 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6641 | annotate_breakpoints_headers (); |
6642 | if (nr_printable_breakpoints > 0) | |
6643 | annotate_field (0); | |
4a64f543 | 6644 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6645 | if (nr_printable_breakpoints > 0) |
6646 | annotate_field (1); | |
269b11a2 | 6647 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6648 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6649 | if (nr_printable_breakpoints > 0) |
6650 | annotate_field (2); | |
4a64f543 | 6651 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6652 | if (nr_printable_breakpoints > 0) |
6653 | annotate_field (3); | |
54e52265 | 6654 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6655 | if (opts.addressprint) |
e5a67952 MS |
6656 | { |
6657 | if (nr_printable_breakpoints > 0) | |
6658 | annotate_field (4); | |
6659 | if (print_address_bits <= 32) | |
6660 | ui_out_table_header (uiout, 10, ui_left, | |
6661 | "addr", "Address"); /* 5 */ | |
6662 | else | |
6663 | ui_out_table_header (uiout, 18, ui_left, | |
6664 | "addr", "Address"); /* 5 */ | |
6665 | } | |
d7faa9e7 AC |
6666 | if (nr_printable_breakpoints > 0) |
6667 | annotate_field (5); | |
6668 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6669 | ui_out_table_body (uiout); | |
6670 | if (nr_printable_breakpoints > 0) | |
6671 | annotate_breakpoints_table (); | |
7f3b0473 | 6672 | |
c4093a6a | 6673 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6674 | { |
6675 | QUIT; | |
6676 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6677 | if (filter && !filter (b)) | |
6678 | continue; | |
6679 | ||
6680 | /* If we have an "args" string, it is a list of breakpoints to | |
6681 | accept. Skip the others. */ | |
6682 | ||
6683 | if (args != NULL && *args != '\0') | |
6684 | { | |
6685 | if (allflag) /* maintenance info breakpoint */ | |
6686 | { | |
6687 | if (parse_and_eval_long (args) != b->number) | |
6688 | continue; | |
6689 | } | |
6690 | else /* all others */ | |
6691 | { | |
6692 | if (!number_is_in_list (args, b->number)) | |
6693 | continue; | |
6694 | } | |
6695 | } | |
6696 | /* We only print out user settable breakpoints unless the | |
6697 | allflag is set. */ | |
6698 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6699 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6700 | } |
6701 | ||
3b31d625 | 6702 | do_cleanups (bkpttbl_chain); |
698384cd | 6703 | |
7f3b0473 | 6704 | if (nr_printable_breakpoints == 0) |
c906108c | 6705 | { |
4a64f543 MS |
6706 | /* If there's a filter, let the caller decide how to report |
6707 | empty list. */ | |
d77f58be SS |
6708 | if (!filter) |
6709 | { | |
e5a67952 | 6710 | if (args == NULL || *args == '\0') |
d77f58be SS |
6711 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6712 | else | |
4a64f543 | 6713 | ui_out_message (uiout, 0, |
e5a67952 MS |
6714 | "No breakpoint or watchpoint matching '%s'.\n", |
6715 | args); | |
d77f58be | 6716 | } |
c906108c SS |
6717 | } |
6718 | else | |
c4093a6a | 6719 | { |
a6d9a66e UW |
6720 | if (last_loc && !server_command) |
6721 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6722 | } |
c906108c | 6723 | |
4a64f543 | 6724 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6725 | there have been breakpoints? */ |
c906108c | 6726 | annotate_breakpoints_table_end (); |
d77f58be SS |
6727 | |
6728 | return nr_printable_breakpoints; | |
c906108c SS |
6729 | } |
6730 | ||
ad443146 SS |
6731 | /* Display the value of default-collect in a way that is generally |
6732 | compatible with the breakpoint list. */ | |
6733 | ||
6734 | static void | |
6735 | default_collect_info (void) | |
6736 | { | |
79a45e25 PA |
6737 | struct ui_out *uiout = current_uiout; |
6738 | ||
ad443146 SS |
6739 | /* If it has no value (which is frequently the case), say nothing; a |
6740 | message like "No default-collect." gets in user's face when it's | |
6741 | not wanted. */ | |
6742 | if (!*default_collect) | |
6743 | return; | |
6744 | ||
6745 | /* The following phrase lines up nicely with per-tracepoint collect | |
6746 | actions. */ | |
6747 | ui_out_text (uiout, "default collect "); | |
6748 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6749 | ui_out_text (uiout, " \n"); | |
6750 | } | |
6751 | ||
c906108c | 6752 | static void |
e5a67952 | 6753 | breakpoints_info (char *args, int from_tty) |
c906108c | 6754 | { |
e5a67952 | 6755 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6756 | |
6757 | default_collect_info (); | |
d77f58be SS |
6758 | } |
6759 | ||
6760 | static void | |
e5a67952 | 6761 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6762 | { |
e5a67952 | 6763 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6764 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6765 | |
6766 | if (num_printed == 0) | |
6767 | { | |
e5a67952 | 6768 | if (args == NULL || *args == '\0') |
d77f58be SS |
6769 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6770 | else | |
e5a67952 | 6771 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6772 | } |
c906108c SS |
6773 | } |
6774 | ||
7a292a7a | 6775 | static void |
e5a67952 | 6776 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6777 | { |
e5a67952 | 6778 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6779 | |
6780 | default_collect_info (); | |
c906108c SS |
6781 | } |
6782 | ||
0d381245 | 6783 | static int |
714835d5 | 6784 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6785 | struct program_space *pspace, |
714835d5 | 6786 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6787 | { |
6788 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6789 | |
0d381245 VP |
6790 | for (; bl; bl = bl->next) |
6791 | { | |
6c95b8df PA |
6792 | if (bl->pspace == pspace |
6793 | && bl->address == pc | |
0d381245 VP |
6794 | && (!overlay_debugging || bl->section == section)) |
6795 | return 1; | |
6796 | } | |
6797 | return 0; | |
6798 | } | |
6799 | ||
672f9b60 | 6800 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6801 | concerns with logical breakpoints, so we match program spaces, not |
6802 | address spaces. */ | |
c906108c SS |
6803 | |
6804 | static void | |
6c95b8df PA |
6805 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6806 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6807 | struct obj_section *section, int thread) |
c906108c | 6808 | { |
52f0bd74 AC |
6809 | int others = 0; |
6810 | struct breakpoint *b; | |
c906108c SS |
6811 | |
6812 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6813 | others += (user_breakpoint_p (b) |
6814 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6815 | if (others > 0) |
6816 | { | |
a3f17187 AC |
6817 | if (others == 1) |
6818 | printf_filtered (_("Note: breakpoint ")); | |
6819 | else /* if (others == ???) */ | |
6820 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6821 | ALL_BREAKPOINTS (b) |
672f9b60 | 6822 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6823 | { |
6824 | others--; | |
6825 | printf_filtered ("%d", b->number); | |
6826 | if (b->thread == -1 && thread != -1) | |
6827 | printf_filtered (" (all threads)"); | |
6828 | else if (b->thread != -1) | |
6829 | printf_filtered (" (thread %d)", b->thread); | |
6830 | printf_filtered ("%s%s ", | |
059fb39f | 6831 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6832 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6833 | ? " (disabled)" |
6834 | : b->enable_state == bp_permanent | |
6835 | ? " (permanent)" | |
6836 | : ""), | |
6837 | (others > 1) ? "," | |
6838 | : ((others == 1) ? " and" : "")); | |
6839 | } | |
a3f17187 | 6840 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6841 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6842 | printf_filtered (".\n"); |
6843 | } | |
6844 | } | |
6845 | \f | |
c906108c | 6846 | |
e4f237da KB |
6847 | /* Return true iff it is meaningful to use the address member of |
6848 | BPT. For some breakpoint types, the address member is irrelevant | |
6849 | and it makes no sense to attempt to compare it to other addresses | |
6850 | (or use it for any other purpose either). | |
6851 | ||
4a64f543 MS |
6852 | More specifically, each of the following breakpoint types will |
6853 | always have a zero valued address and we don't want to mark | |
6854 | breakpoints of any of these types to be a duplicate of an actual | |
6855 | breakpoint at address zero: | |
e4f237da KB |
6856 | |
6857 | bp_watchpoint | |
2d134ed3 PA |
6858 | bp_catchpoint |
6859 | ||
6860 | */ | |
e4f237da KB |
6861 | |
6862 | static int | |
6863 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6864 | { | |
6865 | enum bptype type = bpt->type; | |
6866 | ||
2d134ed3 PA |
6867 | return (type != bp_watchpoint && type != bp_catchpoint); |
6868 | } | |
6869 | ||
6870 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6871 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6872 | ||
6873 | static int | |
4a64f543 MS |
6874 | watchpoint_locations_match (struct bp_location *loc1, |
6875 | struct bp_location *loc2) | |
2d134ed3 | 6876 | { |
3a5c3e22 PA |
6877 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6878 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6879 | ||
6880 | /* Both of them must exist. */ | |
6881 | gdb_assert (w1 != NULL); | |
6882 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6883 | |
4a64f543 MS |
6884 | /* If the target can evaluate the condition expression in hardware, |
6885 | then we we need to insert both watchpoints even if they are at | |
6886 | the same place. Otherwise the watchpoint will only trigger when | |
6887 | the condition of whichever watchpoint was inserted evaluates to | |
6888 | true, not giving a chance for GDB to check the condition of the | |
6889 | other watchpoint. */ | |
3a5c3e22 | 6890 | if ((w1->cond_exp |
4a64f543 MS |
6891 | && target_can_accel_watchpoint_condition (loc1->address, |
6892 | loc1->length, | |
0cf6dd15 | 6893 | loc1->watchpoint_type, |
3a5c3e22 PA |
6894 | w1->cond_exp)) |
6895 | || (w2->cond_exp | |
4a64f543 MS |
6896 | && target_can_accel_watchpoint_condition (loc2->address, |
6897 | loc2->length, | |
0cf6dd15 | 6898 | loc2->watchpoint_type, |
3a5c3e22 | 6899 | w2->cond_exp))) |
0cf6dd15 TJB |
6900 | return 0; |
6901 | ||
85d721b8 PA |
6902 | /* Note that this checks the owner's type, not the location's. In |
6903 | case the target does not support read watchpoints, but does | |
6904 | support access watchpoints, we'll have bp_read_watchpoint | |
6905 | watchpoints with hw_access locations. Those should be considered | |
6906 | duplicates of hw_read locations. The hw_read locations will | |
6907 | become hw_access locations later. */ | |
2d134ed3 PA |
6908 | return (loc1->owner->type == loc2->owner->type |
6909 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6910 | && loc1->address == loc2->address | |
6911 | && loc1->length == loc2->length); | |
e4f237da KB |
6912 | } |
6913 | ||
31e77af2 | 6914 | /* See breakpoint.h. */ |
6c95b8df | 6915 | |
31e77af2 | 6916 | int |
6c95b8df PA |
6917 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6918 | struct address_space *aspace2, CORE_ADDR addr2) | |
6919 | { | |
f5656ead | 6920 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6921 | || aspace1 == aspace2) |
6922 | && addr1 == addr2); | |
6923 | } | |
6924 | ||
f1310107 TJB |
6925 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6926 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6927 | matches ASPACE2. On targets that have global breakpoints, the address | |
6928 | space doesn't really matter. */ | |
6929 | ||
6930 | static int | |
6931 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6932 | int len1, struct address_space *aspace2, | |
6933 | CORE_ADDR addr2) | |
6934 | { | |
f5656ead | 6935 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6936 | || aspace1 == aspace2) |
6937 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6938 | } | |
6939 | ||
6940 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6941 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6942 | matches the breakpoint's address space. On targets that have global | |
6943 | breakpoints, the address space doesn't really matter. */ | |
6944 | ||
6945 | static int | |
6946 | breakpoint_location_address_match (struct bp_location *bl, | |
6947 | struct address_space *aspace, | |
6948 | CORE_ADDR addr) | |
6949 | { | |
6950 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6951 | aspace, addr) | |
6952 | || (bl->length | |
6953 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6954 | bl->address, bl->length, | |
6955 | aspace, addr))); | |
6956 | } | |
6957 | ||
1e4d1764 YQ |
6958 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6959 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6960 | true, otherwise returns false. */ | |
6961 | ||
6962 | static int | |
6963 | tracepoint_locations_match (struct bp_location *loc1, | |
6964 | struct bp_location *loc2) | |
6965 | { | |
6966 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6967 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6968 | locations at the same address of different tracepoints are regarded as | |
6969 | different locations. */ | |
6970 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6971 | else | |
6972 | return 0; | |
6973 | } | |
6974 | ||
2d134ed3 PA |
6975 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6976 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6977 | represent the same location. */ | |
6978 | ||
6979 | static int | |
4a64f543 MS |
6980 | breakpoint_locations_match (struct bp_location *loc1, |
6981 | struct bp_location *loc2) | |
2d134ed3 | 6982 | { |
2bdf28a0 JK |
6983 | int hw_point1, hw_point2; |
6984 | ||
6985 | /* Both of them must not be in moribund_locations. */ | |
6986 | gdb_assert (loc1->owner != NULL); | |
6987 | gdb_assert (loc2->owner != NULL); | |
6988 | ||
6989 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6990 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6991 | |
6992 | if (hw_point1 != hw_point2) | |
6993 | return 0; | |
6994 | else if (hw_point1) | |
6995 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6996 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6997 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6998 | else |
f1310107 TJB |
6999 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7000 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7001 | loc2->pspace->aspace, loc2->address) | |
7002 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7003 | } |
7004 | ||
76897487 KB |
7005 | static void |
7006 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7007 | int bnum, int have_bnum) | |
7008 | { | |
f63fbe86 MS |
7009 | /* The longest string possibly returned by hex_string_custom |
7010 | is 50 chars. These must be at least that big for safety. */ | |
7011 | char astr1[64]; | |
7012 | char astr2[64]; | |
76897487 | 7013 | |
bb599908 PH |
7014 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7015 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7016 | if (have_bnum) |
8a3fe4f8 | 7017 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7018 | bnum, astr1, astr2); |
7019 | else | |
8a3fe4f8 | 7020 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7021 | } |
7022 | ||
4a64f543 MS |
7023 | /* Adjust a breakpoint's address to account for architectural |
7024 | constraints on breakpoint placement. Return the adjusted address. | |
7025 | Note: Very few targets require this kind of adjustment. For most | |
7026 | targets, this function is simply the identity function. */ | |
76897487 KB |
7027 | |
7028 | static CORE_ADDR | |
a6d9a66e UW |
7029 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7030 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7031 | { |
a6d9a66e | 7032 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7033 | { |
7034 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7035 | return bpaddr; | |
7036 | } | |
88f7da05 KB |
7037 | else if (bptype == bp_watchpoint |
7038 | || bptype == bp_hardware_watchpoint | |
7039 | || bptype == bp_read_watchpoint | |
7040 | || bptype == bp_access_watchpoint | |
fe798b75 | 7041 | || bptype == bp_catchpoint) |
88f7da05 KB |
7042 | { |
7043 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7044 | have their addresses modified. */ | |
7045 | return bpaddr; | |
7046 | } | |
76897487 KB |
7047 | else |
7048 | { | |
7049 | CORE_ADDR adjusted_bpaddr; | |
7050 | ||
7051 | /* Some targets have architectural constraints on the placement | |
7052 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7053 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7054 | |
7055 | /* An adjusted breakpoint address can significantly alter | |
7056 | a user's expectations. Print a warning if an adjustment | |
7057 | is required. */ | |
7058 | if (adjusted_bpaddr != bpaddr) | |
7059 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7060 | ||
7061 | return adjusted_bpaddr; | |
7062 | } | |
7063 | } | |
7064 | ||
28010a5d PA |
7065 | void |
7066 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7067 | struct breakpoint *owner) | |
7cc221ef | 7068 | { |
7cc221ef DJ |
7069 | memset (loc, 0, sizeof (*loc)); |
7070 | ||
348d480f PA |
7071 | gdb_assert (ops != NULL); |
7072 | ||
28010a5d PA |
7073 | loc->ops = ops; |
7074 | loc->owner = owner; | |
511a6cd4 | 7075 | loc->cond = NULL; |
b775012e | 7076 | loc->cond_bytecode = NULL; |
0d381245 VP |
7077 | loc->shlib_disabled = 0; |
7078 | loc->enabled = 1; | |
e049a4b5 | 7079 | |
28010a5d | 7080 | switch (owner->type) |
e049a4b5 DJ |
7081 | { |
7082 | case bp_breakpoint: | |
7083 | case bp_until: | |
7084 | case bp_finish: | |
7085 | case bp_longjmp: | |
7086 | case bp_longjmp_resume: | |
e2e4d78b | 7087 | case bp_longjmp_call_dummy: |
186c406b TT |
7088 | case bp_exception: |
7089 | case bp_exception_resume: | |
e049a4b5 | 7090 | case bp_step_resume: |
2c03e5be | 7091 | case bp_hp_step_resume: |
e049a4b5 DJ |
7092 | case bp_watchpoint_scope: |
7093 | case bp_call_dummy: | |
aa7d318d | 7094 | case bp_std_terminate: |
e049a4b5 DJ |
7095 | case bp_shlib_event: |
7096 | case bp_thread_event: | |
7097 | case bp_overlay_event: | |
4efc6507 | 7098 | case bp_jit_event: |
0fd8e87f | 7099 | case bp_longjmp_master: |
aa7d318d | 7100 | case bp_std_terminate_master: |
186c406b | 7101 | case bp_exception_master: |
0e30163f JK |
7102 | case bp_gnu_ifunc_resolver: |
7103 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7104 | case bp_dprintf: |
e049a4b5 | 7105 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7106 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7107 | break; |
7108 | case bp_hardware_breakpoint: | |
7109 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7110 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7111 | break; |
7112 | case bp_hardware_watchpoint: | |
7113 | case bp_read_watchpoint: | |
7114 | case bp_access_watchpoint: | |
7115 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7116 | break; | |
7117 | case bp_watchpoint: | |
ce78b96d | 7118 | case bp_catchpoint: |
15c3d785 PA |
7119 | case bp_tracepoint: |
7120 | case bp_fast_tracepoint: | |
0fb4aa4b | 7121 | case bp_static_tracepoint: |
e049a4b5 DJ |
7122 | loc->loc_type = bp_loc_other; |
7123 | break; | |
7124 | default: | |
e2e0b3e5 | 7125 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7126 | } |
7127 | ||
f431efe5 | 7128 | loc->refc = 1; |
28010a5d PA |
7129 | } |
7130 | ||
7131 | /* Allocate a struct bp_location. */ | |
7132 | ||
7133 | static struct bp_location * | |
7134 | allocate_bp_location (struct breakpoint *bpt) | |
7135 | { | |
348d480f PA |
7136 | return bpt->ops->allocate_location (bpt); |
7137 | } | |
7cc221ef | 7138 | |
f431efe5 PA |
7139 | static void |
7140 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7141 | { |
348d480f | 7142 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7143 | xfree (loc); |
7144 | } | |
7145 | ||
f431efe5 PA |
7146 | /* Increment reference count. */ |
7147 | ||
7148 | static void | |
7149 | incref_bp_location (struct bp_location *bl) | |
7150 | { | |
7151 | ++bl->refc; | |
7152 | } | |
7153 | ||
7154 | /* Decrement reference count. If the reference count reaches 0, | |
7155 | destroy the bp_location. Sets *BLP to NULL. */ | |
7156 | ||
7157 | static void | |
7158 | decref_bp_location (struct bp_location **blp) | |
7159 | { | |
0807b50c PA |
7160 | gdb_assert ((*blp)->refc > 0); |
7161 | ||
f431efe5 PA |
7162 | if (--(*blp)->refc == 0) |
7163 | free_bp_location (*blp); | |
7164 | *blp = NULL; | |
7165 | } | |
7166 | ||
346774a9 | 7167 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7168 | |
346774a9 PA |
7169 | static void |
7170 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7171 | { |
346774a9 | 7172 | struct breakpoint *b1; |
c906108c | 7173 | |
346774a9 PA |
7174 | /* Add this breakpoint to the end of the chain so that a list of |
7175 | breakpoints will come out in order of increasing numbers. */ | |
7176 | ||
7177 | b1 = breakpoint_chain; | |
7178 | if (b1 == 0) | |
7179 | breakpoint_chain = b; | |
7180 | else | |
7181 | { | |
7182 | while (b1->next) | |
7183 | b1 = b1->next; | |
7184 | b1->next = b; | |
7185 | } | |
7186 | } | |
7187 | ||
7188 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7189 | ||
7190 | static void | |
7191 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7192 | struct gdbarch *gdbarch, | |
28010a5d | 7193 | enum bptype bptype, |
c0a91b2b | 7194 | const struct breakpoint_ops *ops) |
346774a9 | 7195 | { |
c906108c | 7196 | memset (b, 0, sizeof (*b)); |
2219d63c | 7197 | |
348d480f PA |
7198 | gdb_assert (ops != NULL); |
7199 | ||
28010a5d | 7200 | b->ops = ops; |
4d28f7a8 | 7201 | b->type = bptype; |
a6d9a66e | 7202 | b->gdbarch = gdbarch; |
c906108c SS |
7203 | b->language = current_language->la_language; |
7204 | b->input_radix = input_radix; | |
7205 | b->thread = -1; | |
b5de0fa7 | 7206 | b->enable_state = bp_enabled; |
c906108c SS |
7207 | b->next = 0; |
7208 | b->silent = 0; | |
7209 | b->ignore_count = 0; | |
7210 | b->commands = NULL; | |
818dd999 | 7211 | b->frame_id = null_frame_id; |
0d381245 | 7212 | b->condition_not_parsed = 0; |
84f4c1fe | 7213 | b->py_bp_object = NULL; |
d0fb5eae | 7214 | b->related_breakpoint = b; |
346774a9 PA |
7215 | } |
7216 | ||
7217 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7218 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7219 | |
7220 | static struct breakpoint * | |
7221 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7222 | enum bptype bptype, |
c0a91b2b | 7223 | const struct breakpoint_ops *ops) |
346774a9 PA |
7224 | { |
7225 | struct breakpoint *b = XNEW (struct breakpoint); | |
7226 | ||
348d480f | 7227 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7228 | add_to_breakpoint_chain (b); |
0d381245 VP |
7229 | return b; |
7230 | } | |
7231 | ||
0e30163f JK |
7232 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7233 | resolutions should be made as the user specified the location explicitly | |
7234 | enough. */ | |
7235 | ||
0d381245 | 7236 | static void |
0e30163f | 7237 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7238 | { |
2bdf28a0 JK |
7239 | gdb_assert (loc->owner != NULL); |
7240 | ||
0d381245 | 7241 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7242 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7243 | || is_tracepoint (loc->owner)) |
0d381245 | 7244 | { |
0e30163f | 7245 | int is_gnu_ifunc; |
2c02bd72 | 7246 | const char *function_name; |
6a3a010b | 7247 | CORE_ADDR func_addr; |
0e30163f | 7248 | |
2c02bd72 | 7249 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7250 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7251 | |
7252 | if (is_gnu_ifunc && !explicit_loc) | |
7253 | { | |
7254 | struct breakpoint *b = loc->owner; | |
7255 | ||
7256 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7257 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7258 | &loc->requested_address)) |
7259 | { | |
7260 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7261 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7262 | loc->requested_address, | |
7263 | b->type); | |
7264 | } | |
7265 | else if (b->type == bp_breakpoint && b->loc == loc | |
7266 | && loc->next == NULL && b->related_breakpoint == b) | |
7267 | { | |
7268 | /* Create only the whole new breakpoint of this type but do not | |
7269 | mess more complicated breakpoints with multiple locations. */ | |
7270 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7271 | /* Remember the resolver's address for use by the return |
7272 | breakpoint. */ | |
7273 | loc->related_address = func_addr; | |
0e30163f JK |
7274 | } |
7275 | } | |
7276 | ||
2c02bd72 DE |
7277 | if (function_name) |
7278 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7279 | } |
7280 | } | |
7281 | ||
a6d9a66e | 7282 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7283 | struct gdbarch * |
a6d9a66e UW |
7284 | get_sal_arch (struct symtab_and_line sal) |
7285 | { | |
7286 | if (sal.section) | |
7287 | return get_objfile_arch (sal.section->objfile); | |
7288 | if (sal.symtab) | |
7289 | return get_objfile_arch (sal.symtab->objfile); | |
7290 | ||
7291 | return NULL; | |
7292 | } | |
7293 | ||
346774a9 PA |
7294 | /* Low level routine for partially initializing a breakpoint of type |
7295 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7296 | file name, and line number are provided by SAL. |
0d381245 VP |
7297 | |
7298 | It is expected that the caller will complete the initialization of | |
7299 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7300 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7301 | |
346774a9 PA |
7302 | static void |
7303 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7304 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7305 | const struct breakpoint_ops *ops) |
0d381245 | 7306 | { |
28010a5d | 7307 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7308 | |
3742cc8b | 7309 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7310 | |
6c95b8df PA |
7311 | if (bptype != bp_catchpoint) |
7312 | gdb_assert (sal.pspace != NULL); | |
7313 | ||
f8eba3c6 TT |
7314 | /* Store the program space that was used to set the breakpoint, |
7315 | except for ordinary breakpoints, which are independent of the | |
7316 | program space. */ | |
7317 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7318 | b->pspace = sal.pspace; | |
346774a9 | 7319 | } |
c906108c | 7320 | |
346774a9 PA |
7321 | /* set_raw_breakpoint is a low level routine for allocating and |
7322 | partially initializing a breakpoint of type BPTYPE. The newly | |
7323 | created breakpoint's address, section, source file name, and line | |
7324 | number are provided by SAL. The newly created and partially | |
7325 | initialized breakpoint is added to the breakpoint chain and | |
7326 | is also returned as the value of this function. | |
7327 | ||
7328 | It is expected that the caller will complete the initialization of | |
7329 | the newly created breakpoint struct as well as output any status | |
7330 | information regarding the creation of a new breakpoint. In | |
7331 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7332 | number! Care should be taken to not allow an error to occur | |
7333 | prior to completing the initialization of the breakpoint. If this | |
7334 | should happen, a bogus breakpoint will be left on the chain. */ | |
7335 | ||
7336 | struct breakpoint * | |
7337 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7338 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7339 | const struct breakpoint_ops *ops) |
346774a9 PA |
7340 | { |
7341 | struct breakpoint *b = XNEW (struct breakpoint); | |
7342 | ||
348d480f | 7343 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7344 | add_to_breakpoint_chain (b); |
c906108c SS |
7345 | return b; |
7346 | } | |
7347 | ||
c2c6d25f JM |
7348 | |
7349 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7350 | instruction, hard-wired into the inferior's code. */ | |
7351 | void | |
7352 | make_breakpoint_permanent (struct breakpoint *b) | |
7353 | { | |
0d381245 | 7354 | struct bp_location *bl; |
cc59ec59 | 7355 | |
b5de0fa7 | 7356 | b->enable_state = bp_permanent; |
c2c6d25f | 7357 | |
4a64f543 MS |
7358 | /* By definition, permanent breakpoints are already present in the |
7359 | code. Mark all locations as inserted. For now, | |
7360 | make_breakpoint_permanent is called in just one place, so it's | |
7361 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7362 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7363 | for (bl = b->loc; bl; bl = bl->next) |
7364 | bl->inserted = 1; | |
c2c6d25f JM |
7365 | } |
7366 | ||
53a5351d | 7367 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7368 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7369 | initiated the operation. */ | |
c906108c SS |
7370 | |
7371 | void | |
186c406b | 7372 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7373 | { |
35df4500 | 7374 | struct breakpoint *b, *b_tmp; |
186c406b | 7375 | int thread = tp->num; |
0fd8e87f UW |
7376 | |
7377 | /* To avoid having to rescan all objfile symbols at every step, | |
7378 | we maintain a list of continually-inserted but always disabled | |
7379 | longjmp "master" breakpoints. Here, we simply create momentary | |
7380 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7381 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7382 | if (b->pspace == current_program_space |
186c406b TT |
7383 | && (b->type == bp_longjmp_master |
7384 | || b->type == bp_exception_master)) | |
0fd8e87f | 7385 | { |
06edf0c0 PA |
7386 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7387 | struct breakpoint *clone; | |
cc59ec59 | 7388 | |
e2e4d78b JK |
7389 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7390 | after their removal. */ | |
06edf0c0 | 7391 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7392 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7393 | clone->thread = thread; |
7394 | } | |
186c406b TT |
7395 | |
7396 | tp->initiating_frame = frame; | |
c906108c SS |
7397 | } |
7398 | ||
611c83ae | 7399 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7400 | void |
611c83ae | 7401 | delete_longjmp_breakpoint (int thread) |
c906108c | 7402 | { |
35df4500 | 7403 | struct breakpoint *b, *b_tmp; |
c906108c | 7404 | |
35df4500 | 7405 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7406 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7407 | { |
7408 | if (b->thread == thread) | |
7409 | delete_breakpoint (b); | |
7410 | } | |
c906108c SS |
7411 | } |
7412 | ||
f59f708a PA |
7413 | void |
7414 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7415 | { | |
7416 | struct breakpoint *b, *b_tmp; | |
7417 | ||
7418 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7419 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7420 | { | |
7421 | if (b->thread == thread) | |
7422 | b->disposition = disp_del_at_next_stop; | |
7423 | } | |
7424 | } | |
7425 | ||
e2e4d78b JK |
7426 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7427 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7428 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7429 | breakpoints. */ | |
7430 | ||
7431 | struct breakpoint * | |
7432 | set_longjmp_breakpoint_for_call_dummy (void) | |
7433 | { | |
7434 | struct breakpoint *b, *retval = NULL; | |
7435 | ||
7436 | ALL_BREAKPOINTS (b) | |
7437 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7438 | { | |
7439 | struct breakpoint *new_b; | |
7440 | ||
7441 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7442 | &momentary_breakpoint_ops, |
7443 | 1); | |
e2e4d78b JK |
7444 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7445 | ||
7446 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7447 | ||
7448 | gdb_assert (new_b->related_breakpoint == new_b); | |
7449 | if (retval == NULL) | |
7450 | retval = new_b; | |
7451 | new_b->related_breakpoint = retval; | |
7452 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7453 | retval = retval->related_breakpoint; | |
7454 | retval->related_breakpoint = new_b; | |
7455 | } | |
7456 | ||
7457 | return retval; | |
7458 | } | |
7459 | ||
7460 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7461 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7462 | stack. |
7463 | ||
7464 | You should call this function only at places where it is safe to currently | |
7465 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7466 | frames. */ | |
7467 | ||
7468 | void | |
b67a2c6f | 7469 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7470 | { |
7471 | struct breakpoint *b, *b_tmp; | |
7472 | ||
7473 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7474 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7475 | { |
7476 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7477 | ||
7478 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7479 | dummy_b = dummy_b->related_breakpoint; | |
7480 | if (dummy_b->type != bp_call_dummy | |
7481 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7482 | continue; | |
7483 | ||
b67a2c6f | 7484 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7485 | |
7486 | while (b->related_breakpoint != b) | |
7487 | { | |
7488 | if (b_tmp == b->related_breakpoint) | |
7489 | b_tmp = b->related_breakpoint->next; | |
7490 | delete_breakpoint (b->related_breakpoint); | |
7491 | } | |
7492 | delete_breakpoint (b); | |
7493 | } | |
7494 | } | |
7495 | ||
1900040c MS |
7496 | void |
7497 | enable_overlay_breakpoints (void) | |
7498 | { | |
52f0bd74 | 7499 | struct breakpoint *b; |
1900040c MS |
7500 | |
7501 | ALL_BREAKPOINTS (b) | |
7502 | if (b->type == bp_overlay_event) | |
7503 | { | |
7504 | b->enable_state = bp_enabled; | |
b60e7edf | 7505 | update_global_location_list (1); |
c02f5703 | 7506 | overlay_events_enabled = 1; |
1900040c MS |
7507 | } |
7508 | } | |
7509 | ||
7510 | void | |
7511 | disable_overlay_breakpoints (void) | |
7512 | { | |
52f0bd74 | 7513 | struct breakpoint *b; |
1900040c MS |
7514 | |
7515 | ALL_BREAKPOINTS (b) | |
7516 | if (b->type == bp_overlay_event) | |
7517 | { | |
7518 | b->enable_state = bp_disabled; | |
b60e7edf | 7519 | update_global_location_list (0); |
c02f5703 | 7520 | overlay_events_enabled = 0; |
1900040c MS |
7521 | } |
7522 | } | |
7523 | ||
aa7d318d TT |
7524 | /* Set an active std::terminate breakpoint for each std::terminate |
7525 | master breakpoint. */ | |
7526 | void | |
7527 | set_std_terminate_breakpoint (void) | |
7528 | { | |
35df4500 | 7529 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7530 | |
35df4500 | 7531 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7532 | if (b->pspace == current_program_space |
7533 | && b->type == bp_std_terminate_master) | |
7534 | { | |
06edf0c0 | 7535 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7536 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7537 | } |
7538 | } | |
7539 | ||
7540 | /* Delete all the std::terminate breakpoints. */ | |
7541 | void | |
7542 | delete_std_terminate_breakpoint (void) | |
7543 | { | |
35df4500 | 7544 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7545 | |
35df4500 | 7546 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7547 | if (b->type == bp_std_terminate) |
7548 | delete_breakpoint (b); | |
7549 | } | |
7550 | ||
c4093a6a | 7551 | struct breakpoint * |
a6d9a66e | 7552 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7553 | { |
7554 | struct breakpoint *b; | |
c4093a6a | 7555 | |
06edf0c0 PA |
7556 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7557 | &internal_breakpoint_ops); | |
7558 | ||
b5de0fa7 | 7559 | b->enable_state = bp_enabled; |
c4093a6a | 7560 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7561 | b->addr_string |
7562 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7563 | |
b60e7edf | 7564 | update_global_location_list_nothrow (1); |
74960c60 | 7565 | |
c4093a6a JM |
7566 | return b; |
7567 | } | |
7568 | ||
7569 | void | |
7570 | remove_thread_event_breakpoints (void) | |
7571 | { | |
35df4500 | 7572 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7573 | |
35df4500 | 7574 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7575 | if (b->type == bp_thread_event |
7576 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7577 | delete_breakpoint (b); |
7578 | } | |
7579 | ||
0101ce28 JJ |
7580 | struct lang_and_radix |
7581 | { | |
7582 | enum language lang; | |
7583 | int radix; | |
7584 | }; | |
7585 | ||
4efc6507 DE |
7586 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7587 | ||
7588 | struct breakpoint * | |
7589 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7590 | { | |
7591 | struct breakpoint *b; | |
7592 | ||
06edf0c0 PA |
7593 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7594 | &internal_breakpoint_ops); | |
4efc6507 DE |
7595 | update_global_location_list_nothrow (1); |
7596 | return b; | |
7597 | } | |
0101ce28 | 7598 | |
03673fc7 PP |
7599 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7600 | ||
7601 | void | |
7602 | remove_jit_event_breakpoints (void) | |
7603 | { | |
7604 | struct breakpoint *b, *b_tmp; | |
7605 | ||
7606 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7607 | if (b->type == bp_jit_event | |
7608 | && b->loc->pspace == current_program_space) | |
7609 | delete_breakpoint (b); | |
7610 | } | |
7611 | ||
cae688ec JJ |
7612 | void |
7613 | remove_solib_event_breakpoints (void) | |
7614 | { | |
35df4500 | 7615 | struct breakpoint *b, *b_tmp; |
cae688ec | 7616 | |
35df4500 | 7617 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7618 | if (b->type == bp_shlib_event |
7619 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7620 | delete_breakpoint (b); |
7621 | } | |
7622 | ||
f37f681c PA |
7623 | /* See breakpoint.h. */ |
7624 | ||
7625 | void | |
7626 | remove_solib_event_breakpoints_at_next_stop (void) | |
7627 | { | |
7628 | struct breakpoint *b, *b_tmp; | |
7629 | ||
7630 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7631 | if (b->type == bp_shlib_event | |
7632 | && b->loc->pspace == current_program_space) | |
7633 | b->disposition = disp_del_at_next_stop; | |
7634 | } | |
7635 | ||
cae688ec | 7636 | struct breakpoint * |
a6d9a66e | 7637 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7638 | { |
7639 | struct breakpoint *b; | |
7640 | ||
06edf0c0 PA |
7641 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7642 | &internal_breakpoint_ops); | |
b60e7edf | 7643 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7644 | return b; |
7645 | } | |
7646 | ||
f37f681c PA |
7647 | /* See breakpoint.h. */ |
7648 | ||
7649 | struct breakpoint * | |
7650 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7651 | { | |
7652 | struct breakpoint *b; | |
7653 | ||
7654 | b = create_solib_event_breakpoint (gdbarch, address); | |
7655 | if (!breakpoints_always_inserted_mode ()) | |
7656 | insert_breakpoint_locations (); | |
7657 | if (!b->loc->inserted) | |
7658 | { | |
7659 | delete_breakpoint (b); | |
7660 | return NULL; | |
7661 | } | |
7662 | return b; | |
7663 | } | |
7664 | ||
cae688ec JJ |
7665 | /* Disable any breakpoints that are on code in shared libraries. Only |
7666 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7667 | ||
7668 | void | |
cb851954 | 7669 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7670 | { |
876fa593 | 7671 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7672 | |
876fa593 | 7673 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7674 | { |
2bdf28a0 | 7675 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7676 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7677 | |
4a64f543 MS |
7678 | /* We apply the check to all breakpoints, including disabled for |
7679 | those with loc->duplicate set. This is so that when breakpoint | |
7680 | becomes enabled, or the duplicate is removed, gdb will try to | |
7681 | insert all breakpoints. If we don't set shlib_disabled here, | |
7682 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7683 | if (((b->type == bp_breakpoint) |
508ccb1f | 7684 | || (b->type == bp_jit_event) |
1042e4c0 | 7685 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7686 | || (is_tracepoint (b))) |
6c95b8df | 7687 | && loc->pspace == current_program_space |
0d381245 | 7688 | && !loc->shlib_disabled |
6c95b8df | 7689 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7690 | ) |
0d381245 VP |
7691 | { |
7692 | loc->shlib_disabled = 1; | |
7693 | } | |
cae688ec JJ |
7694 | } |
7695 | } | |
7696 | ||
63644780 NB |
7697 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7698 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7699 | disabled ones can just stay disabled. */ | |
84acb35a | 7700 | |
75149521 | 7701 | static void |
84acb35a JJ |
7702 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7703 | { | |
876fa593 | 7704 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7705 | int disabled_shlib_breaks = 0; |
7706 | ||
c86cf029 VP |
7707 | /* SunOS a.out shared libraries are always mapped, so do not |
7708 | disable breakpoints; they will only be reported as unloaded | |
7709 | through clear_solib when GDB discards its shared library | |
7710 | list. See clear_solib for more information. */ | |
7711 | if (exec_bfd != NULL | |
7712 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7713 | return; | |
7714 | ||
876fa593 | 7715 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7716 | { |
2bdf28a0 | 7717 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7718 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7719 | |
1e4d1764 | 7720 | if (solib->pspace == loc->pspace |
e2dd7057 | 7721 | && !loc->shlib_disabled |
1e4d1764 YQ |
7722 | && (((b->type == bp_breakpoint |
7723 | || b->type == bp_jit_event | |
7724 | || b->type == bp_hardware_breakpoint) | |
7725 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7726 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7727 | || is_tracepoint (b)) | |
e2dd7057 | 7728 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7729 | { |
e2dd7057 PP |
7730 | loc->shlib_disabled = 1; |
7731 | /* At this point, we cannot rely on remove_breakpoint | |
7732 | succeeding so we must mark the breakpoint as not inserted | |
7733 | to prevent future errors occurring in remove_breakpoints. */ | |
7734 | loc->inserted = 0; | |
8d3788bd VP |
7735 | |
7736 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7737 | observer_notify_breakpoint_modified (b); | |
7738 | ||
e2dd7057 PP |
7739 | if (!disabled_shlib_breaks) |
7740 | { | |
7741 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7742 | warning (_("Temporarily disabling breakpoints " |
7743 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7744 | solib->so_name); |
84acb35a | 7745 | } |
e2dd7057 | 7746 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7747 | } |
7748 | } | |
84acb35a JJ |
7749 | } |
7750 | ||
63644780 NB |
7751 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7752 | notification of free_objfile. Only apply to enabled breakpoints, | |
7753 | disabled ones can just stay disabled. */ | |
7754 | ||
7755 | static void | |
7756 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7757 | { | |
7758 | struct breakpoint *b; | |
7759 | ||
7760 | if (objfile == NULL) | |
7761 | return; | |
7762 | ||
d03de421 PA |
7763 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7764 | managed by the user with add-symbol-file/remove-symbol-file. | |
7765 | Similarly to how breakpoints in shared libraries are handled in | |
7766 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7767 | shlib_disabled so they end up uninserted on the next global |
7768 | location list update. Shared libraries not loaded by the user | |
7769 | aren't handled here -- they're already handled in | |
7770 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7771 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7772 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7773 | main objfile). */ | |
7774 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7775 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7776 | return; |
7777 | ||
7778 | ALL_BREAKPOINTS (b) | |
7779 | { | |
7780 | struct bp_location *loc; | |
7781 | int bp_modified = 0; | |
7782 | ||
7783 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7784 | continue; | |
7785 | ||
7786 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7787 | { | |
7788 | CORE_ADDR loc_addr = loc->address; | |
7789 | ||
7790 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7791 | && loc->loc_type != bp_loc_software_breakpoint) | |
7792 | continue; | |
7793 | ||
7794 | if (loc->shlib_disabled != 0) | |
7795 | continue; | |
7796 | ||
7797 | if (objfile->pspace != loc->pspace) | |
7798 | continue; | |
7799 | ||
7800 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7801 | && loc->loc_type != bp_loc_software_breakpoint) | |
7802 | continue; | |
7803 | ||
7804 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7805 | { | |
7806 | loc->shlib_disabled = 1; | |
08351840 PA |
7807 | /* At this point, we don't know whether the object was |
7808 | unmapped from the inferior or not, so leave the | |
7809 | inserted flag alone. We'll handle failure to | |
7810 | uninsert quietly, in case the object was indeed | |
7811 | unmapped. */ | |
63644780 NB |
7812 | |
7813 | mark_breakpoint_location_modified (loc); | |
7814 | ||
7815 | bp_modified = 1; | |
7816 | } | |
7817 | } | |
7818 | ||
7819 | if (bp_modified) | |
7820 | observer_notify_breakpoint_modified (b); | |
7821 | } | |
7822 | } | |
7823 | ||
ce78b96d JB |
7824 | /* FORK & VFORK catchpoints. */ |
7825 | ||
e29a4733 PA |
7826 | /* An instance of this type is used to represent a fork or vfork |
7827 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7828 | class; users downcast to "struct breakpoint *" when needed. A | |
7829 | breakpoint is really of this type iff its ops pointer points to | |
7830 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7831 | ||
7832 | struct fork_catchpoint | |
7833 | { | |
7834 | /* The base class. */ | |
7835 | struct breakpoint base; | |
7836 | ||
7837 | /* Process id of a child process whose forking triggered this | |
7838 | catchpoint. This field is only valid immediately after this | |
7839 | catchpoint has triggered. */ | |
7840 | ptid_t forked_inferior_pid; | |
7841 | }; | |
7842 | ||
4a64f543 MS |
7843 | /* Implement the "insert" breakpoint_ops method for fork |
7844 | catchpoints. */ | |
ce78b96d | 7845 | |
77b06cd7 TJB |
7846 | static int |
7847 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7848 | { |
dfd4cc63 | 7849 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7850 | } |
7851 | ||
4a64f543 MS |
7852 | /* Implement the "remove" breakpoint_ops method for fork |
7853 | catchpoints. */ | |
ce78b96d JB |
7854 | |
7855 | static int | |
77b06cd7 | 7856 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7857 | { |
dfd4cc63 | 7858 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7859 | } |
7860 | ||
7861 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7862 | catchpoints. */ | |
7863 | ||
7864 | static int | |
f1310107 | 7865 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7866 | struct address_space *aspace, CORE_ADDR bp_addr, |
7867 | const struct target_waitstatus *ws) | |
ce78b96d | 7868 | { |
e29a4733 PA |
7869 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7870 | ||
f90263c1 TT |
7871 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7872 | return 0; | |
7873 | ||
7874 | c->forked_inferior_pid = ws->value.related_pid; | |
7875 | return 1; | |
ce78b96d JB |
7876 | } |
7877 | ||
4a64f543 MS |
7878 | /* Implement the "print_it" breakpoint_ops method for fork |
7879 | catchpoints. */ | |
ce78b96d JB |
7880 | |
7881 | static enum print_stop_action | |
348d480f | 7882 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7883 | { |
36dfb11c | 7884 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7885 | struct breakpoint *b = bs->breakpoint_at; |
7886 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7887 | |
ce78b96d | 7888 | annotate_catchpoint (b->number); |
36dfb11c TT |
7889 | if (b->disposition == disp_del) |
7890 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7891 | else | |
7892 | ui_out_text (uiout, "\nCatchpoint "); | |
7893 | if (ui_out_is_mi_like_p (uiout)) | |
7894 | { | |
7895 | ui_out_field_string (uiout, "reason", | |
7896 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7897 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7898 | } | |
7899 | ui_out_field_int (uiout, "bkptno", b->number); | |
7900 | ui_out_text (uiout, " (forked process "); | |
7901 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7902 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7903 | return PRINT_SRC_AND_LOC; |
7904 | } | |
7905 | ||
4a64f543 MS |
7906 | /* Implement the "print_one" breakpoint_ops method for fork |
7907 | catchpoints. */ | |
ce78b96d JB |
7908 | |
7909 | static void | |
a6d9a66e | 7910 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7911 | { |
e29a4733 | 7912 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7913 | struct value_print_options opts; |
79a45e25 | 7914 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7915 | |
7916 | get_user_print_options (&opts); | |
7917 | ||
4a64f543 MS |
7918 | /* Field 4, the address, is omitted (which makes the columns not |
7919 | line up too nicely with the headers, but the effect is relatively | |
7920 | readable). */ | |
79a45b7d | 7921 | if (opts.addressprint) |
ce78b96d JB |
7922 | ui_out_field_skip (uiout, "addr"); |
7923 | annotate_field (5); | |
7924 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7925 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7926 | { |
7927 | ui_out_text (uiout, ", process "); | |
7928 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7929 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7930 | ui_out_spaces (uiout, 1); |
7931 | } | |
8ac3646f TT |
7932 | |
7933 | if (ui_out_is_mi_like_p (uiout)) | |
7934 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7935 | } |
7936 | ||
7937 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7938 | catchpoints. */ | |
7939 | ||
7940 | static void | |
7941 | print_mention_catch_fork (struct breakpoint *b) | |
7942 | { | |
7943 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7944 | } | |
7945 | ||
6149aea9 PA |
7946 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7947 | catchpoints. */ | |
7948 | ||
7949 | static void | |
7950 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7951 | { | |
7952 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7953 | print_recreate_thread (b, fp); |
6149aea9 PA |
7954 | } |
7955 | ||
ce78b96d JB |
7956 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7957 | ||
2060206e | 7958 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7959 | |
4a64f543 MS |
7960 | /* Implement the "insert" breakpoint_ops method for vfork |
7961 | catchpoints. */ | |
ce78b96d | 7962 | |
77b06cd7 TJB |
7963 | static int |
7964 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7965 | { |
dfd4cc63 | 7966 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7967 | } |
7968 | ||
4a64f543 MS |
7969 | /* Implement the "remove" breakpoint_ops method for vfork |
7970 | catchpoints. */ | |
ce78b96d JB |
7971 | |
7972 | static int | |
77b06cd7 | 7973 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7974 | { |
dfd4cc63 | 7975 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7976 | } |
7977 | ||
7978 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7979 | catchpoints. */ | |
7980 | ||
7981 | static int | |
f1310107 | 7982 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7983 | struct address_space *aspace, CORE_ADDR bp_addr, |
7984 | const struct target_waitstatus *ws) | |
ce78b96d | 7985 | { |
e29a4733 PA |
7986 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7987 | ||
f90263c1 TT |
7988 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7989 | return 0; | |
7990 | ||
7991 | c->forked_inferior_pid = ws->value.related_pid; | |
7992 | return 1; | |
ce78b96d JB |
7993 | } |
7994 | ||
4a64f543 MS |
7995 | /* Implement the "print_it" breakpoint_ops method for vfork |
7996 | catchpoints. */ | |
ce78b96d JB |
7997 | |
7998 | static enum print_stop_action | |
348d480f | 7999 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8000 | { |
36dfb11c | 8001 | struct ui_out *uiout = current_uiout; |
348d480f | 8002 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8003 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8004 | ||
ce78b96d | 8005 | annotate_catchpoint (b->number); |
36dfb11c TT |
8006 | if (b->disposition == disp_del) |
8007 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8008 | else | |
8009 | ui_out_text (uiout, "\nCatchpoint "); | |
8010 | if (ui_out_is_mi_like_p (uiout)) | |
8011 | { | |
8012 | ui_out_field_string (uiout, "reason", | |
8013 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8014 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8015 | } | |
8016 | ui_out_field_int (uiout, "bkptno", b->number); | |
8017 | ui_out_text (uiout, " (vforked process "); | |
8018 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8019 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8020 | return PRINT_SRC_AND_LOC; |
8021 | } | |
8022 | ||
4a64f543 MS |
8023 | /* Implement the "print_one" breakpoint_ops method for vfork |
8024 | catchpoints. */ | |
ce78b96d JB |
8025 | |
8026 | static void | |
a6d9a66e | 8027 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8028 | { |
e29a4733 | 8029 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8030 | struct value_print_options opts; |
79a45e25 | 8031 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8032 | |
8033 | get_user_print_options (&opts); | |
4a64f543 MS |
8034 | /* Field 4, the address, is omitted (which makes the columns not |
8035 | line up too nicely with the headers, but the effect is relatively | |
8036 | readable). */ | |
79a45b7d | 8037 | if (opts.addressprint) |
ce78b96d JB |
8038 | ui_out_field_skip (uiout, "addr"); |
8039 | annotate_field (5); | |
8040 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8041 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8042 | { |
8043 | ui_out_text (uiout, ", process "); | |
8044 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8045 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8046 | ui_out_spaces (uiout, 1); |
8047 | } | |
8ac3646f TT |
8048 | |
8049 | if (ui_out_is_mi_like_p (uiout)) | |
8050 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8051 | } |
8052 | ||
8053 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8054 | catchpoints. */ | |
8055 | ||
8056 | static void | |
8057 | print_mention_catch_vfork (struct breakpoint *b) | |
8058 | { | |
8059 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8060 | } | |
8061 | ||
6149aea9 PA |
8062 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8063 | catchpoints. */ | |
8064 | ||
8065 | static void | |
8066 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8067 | { | |
8068 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8069 | print_recreate_thread (b, fp); |
6149aea9 PA |
8070 | } |
8071 | ||
ce78b96d JB |
8072 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8073 | ||
2060206e | 8074 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8075 | |
edcc5120 TT |
8076 | /* An instance of this type is used to represent an solib catchpoint. |
8077 | It includes a "struct breakpoint" as a kind of base class; users | |
8078 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8079 | really of this type iff its ops pointer points to | |
8080 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8081 | ||
8082 | struct solib_catchpoint | |
8083 | { | |
8084 | /* The base class. */ | |
8085 | struct breakpoint base; | |
8086 | ||
8087 | /* True for "catch load", false for "catch unload". */ | |
8088 | unsigned char is_load; | |
8089 | ||
8090 | /* Regular expression to match, if any. COMPILED is only valid when | |
8091 | REGEX is non-NULL. */ | |
8092 | char *regex; | |
8093 | regex_t compiled; | |
8094 | }; | |
8095 | ||
8096 | static void | |
8097 | dtor_catch_solib (struct breakpoint *b) | |
8098 | { | |
8099 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8100 | ||
8101 | if (self->regex) | |
8102 | regfree (&self->compiled); | |
8103 | xfree (self->regex); | |
8104 | ||
8105 | base_breakpoint_ops.dtor (b); | |
8106 | } | |
8107 | ||
8108 | static int | |
8109 | insert_catch_solib (struct bp_location *ignore) | |
8110 | { | |
8111 | return 0; | |
8112 | } | |
8113 | ||
8114 | static int | |
8115 | remove_catch_solib (struct bp_location *ignore) | |
8116 | { | |
8117 | return 0; | |
8118 | } | |
8119 | ||
8120 | static int | |
8121 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8122 | struct address_space *aspace, | |
8123 | CORE_ADDR bp_addr, | |
8124 | const struct target_waitstatus *ws) | |
8125 | { | |
8126 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8127 | struct breakpoint *other; | |
8128 | ||
8129 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8130 | return 1; | |
8131 | ||
8132 | ALL_BREAKPOINTS (other) | |
8133 | { | |
8134 | struct bp_location *other_bl; | |
8135 | ||
8136 | if (other == bl->owner) | |
8137 | continue; | |
8138 | ||
8139 | if (other->type != bp_shlib_event) | |
8140 | continue; | |
8141 | ||
8142 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8143 | continue; | |
8144 | ||
8145 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8146 | { | |
8147 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8148 | return 1; | |
8149 | } | |
8150 | } | |
8151 | ||
8152 | return 0; | |
8153 | } | |
8154 | ||
8155 | static void | |
8156 | check_status_catch_solib (struct bpstats *bs) | |
8157 | { | |
8158 | struct solib_catchpoint *self | |
8159 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8160 | int ix; | |
8161 | ||
8162 | if (self->is_load) | |
8163 | { | |
8164 | struct so_list *iter; | |
8165 | ||
8166 | for (ix = 0; | |
8167 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8168 | ix, iter); | |
8169 | ++ix) | |
8170 | { | |
8171 | if (!self->regex | |
8172 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8173 | return; | |
8174 | } | |
8175 | } | |
8176 | else | |
8177 | { | |
8178 | char *iter; | |
8179 | ||
8180 | for (ix = 0; | |
8181 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8182 | ix, iter); | |
8183 | ++ix) | |
8184 | { | |
8185 | if (!self->regex | |
8186 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8187 | return; | |
8188 | } | |
8189 | } | |
8190 | ||
8191 | bs->stop = 0; | |
8192 | bs->print_it = print_it_noop; | |
8193 | } | |
8194 | ||
8195 | static enum print_stop_action | |
8196 | print_it_catch_solib (bpstat bs) | |
8197 | { | |
8198 | struct breakpoint *b = bs->breakpoint_at; | |
8199 | struct ui_out *uiout = current_uiout; | |
8200 | ||
8201 | annotate_catchpoint (b->number); | |
8202 | if (b->disposition == disp_del) | |
8203 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8204 | else | |
8205 | ui_out_text (uiout, "\nCatchpoint "); | |
8206 | ui_out_field_int (uiout, "bkptno", b->number); | |
8207 | ui_out_text (uiout, "\n"); | |
8208 | if (ui_out_is_mi_like_p (uiout)) | |
8209 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8210 | print_solib_event (1); | |
8211 | return PRINT_SRC_AND_LOC; | |
8212 | } | |
8213 | ||
8214 | static void | |
8215 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8216 | { | |
8217 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8218 | struct value_print_options opts; | |
8219 | struct ui_out *uiout = current_uiout; | |
8220 | char *msg; | |
8221 | ||
8222 | get_user_print_options (&opts); | |
8223 | /* Field 4, the address, is omitted (which makes the columns not | |
8224 | line up too nicely with the headers, but the effect is relatively | |
8225 | readable). */ | |
8226 | if (opts.addressprint) | |
8227 | { | |
8228 | annotate_field (4); | |
8229 | ui_out_field_skip (uiout, "addr"); | |
8230 | } | |
8231 | ||
8232 | annotate_field (5); | |
8233 | if (self->is_load) | |
8234 | { | |
8235 | if (self->regex) | |
8236 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8237 | else | |
8238 | msg = xstrdup (_("load of library")); | |
8239 | } | |
8240 | else | |
8241 | { | |
8242 | if (self->regex) | |
8243 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8244 | else | |
8245 | msg = xstrdup (_("unload of library")); | |
8246 | } | |
8247 | ui_out_field_string (uiout, "what", msg); | |
8248 | xfree (msg); | |
8ac3646f TT |
8249 | |
8250 | if (ui_out_is_mi_like_p (uiout)) | |
8251 | ui_out_field_string (uiout, "catch-type", | |
8252 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8253 | } |
8254 | ||
8255 | static void | |
8256 | print_mention_catch_solib (struct breakpoint *b) | |
8257 | { | |
8258 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8259 | ||
8260 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8261 | self->is_load ? "load" : "unload"); | |
8262 | } | |
8263 | ||
8264 | static void | |
8265 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8266 | { | |
8267 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8268 | ||
8269 | fprintf_unfiltered (fp, "%s %s", | |
8270 | b->disposition == disp_del ? "tcatch" : "catch", | |
8271 | self->is_load ? "load" : "unload"); | |
8272 | if (self->regex) | |
8273 | fprintf_unfiltered (fp, " %s", self->regex); | |
8274 | fprintf_unfiltered (fp, "\n"); | |
8275 | } | |
8276 | ||
8277 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8278 | ||
91985142 MG |
8279 | /* Shared helper function (MI and CLI) for creating and installing |
8280 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8281 | the events to be caught are load events, otherwise they are | |
8282 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8283 | temporary one. If ENABLED is non-zero the catchpoint is | |
8284 | created in an enabled state. */ | |
edcc5120 | 8285 | |
91985142 MG |
8286 | void |
8287 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8288 | { |
8289 | struct solib_catchpoint *c; | |
8290 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8291 | struct cleanup *cleanup; |
8292 | ||
edcc5120 TT |
8293 | if (!arg) |
8294 | arg = ""; | |
8295 | arg = skip_spaces (arg); | |
8296 | ||
8297 | c = XCNEW (struct solib_catchpoint); | |
8298 | cleanup = make_cleanup (xfree, c); | |
8299 | ||
8300 | if (*arg != '\0') | |
8301 | { | |
8302 | int errcode; | |
8303 | ||
8304 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8305 | if (errcode != 0) | |
8306 | { | |
8307 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8308 | ||
8309 | make_cleanup (xfree, err); | |
8310 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8311 | } | |
8312 | c->regex = xstrdup (arg); | |
8313 | } | |
8314 | ||
8315 | c->is_load = is_load; | |
91985142 | 8316 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8317 | &catch_solib_breakpoint_ops); |
8318 | ||
91985142 MG |
8319 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8320 | ||
edcc5120 TT |
8321 | discard_cleanups (cleanup); |
8322 | install_breakpoint (0, &c->base, 1); | |
8323 | } | |
8324 | ||
91985142 MG |
8325 | /* A helper function that does all the work for "catch load" and |
8326 | "catch unload". */ | |
8327 | ||
8328 | static void | |
8329 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8330 | struct cmd_list_element *command) | |
8331 | { | |
8332 | int tempflag; | |
8333 | const int enabled = 1; | |
8334 | ||
8335 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8336 | ||
8337 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8338 | } | |
8339 | ||
edcc5120 TT |
8340 | static void |
8341 | catch_load_command_1 (char *arg, int from_tty, | |
8342 | struct cmd_list_element *command) | |
8343 | { | |
8344 | catch_load_or_unload (arg, from_tty, 1, command); | |
8345 | } | |
8346 | ||
8347 | static void | |
8348 | catch_unload_command_1 (char *arg, int from_tty, | |
8349 | struct cmd_list_element *command) | |
8350 | { | |
8351 | catch_load_or_unload (arg, from_tty, 0, command); | |
8352 | } | |
8353 | ||
be5c67c1 PA |
8354 | /* An instance of this type is used to represent a syscall catchpoint. |
8355 | It includes a "struct breakpoint" as a kind of base class; users | |
8356 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8357 | really of this type iff its ops pointer points to | |
8358 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8359 | ||
8360 | struct syscall_catchpoint | |
8361 | { | |
8362 | /* The base class. */ | |
8363 | struct breakpoint base; | |
8364 | ||
8365 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8366 | syscall has been specified for filtering, its value is NULL. | |
8367 | Otherwise, it holds a list of all syscalls to be caught. The | |
8368 | list elements are allocated with xmalloc. */ | |
8369 | VEC(int) *syscalls_to_be_caught; | |
8370 | }; | |
8371 | ||
8372 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8373 | catchpoints. */ | |
8374 | ||
8375 | static void | |
8376 | dtor_catch_syscall (struct breakpoint *b) | |
8377 | { | |
8378 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8379 | ||
8380 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8381 | |
2060206e | 8382 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8383 | } |
8384 | ||
fa3064dd YQ |
8385 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8386 | ||
8387 | struct catch_syscall_inferior_data | |
8388 | { | |
8389 | /* We keep a count of the number of times the user has requested a | |
8390 | particular syscall to be tracked, and pass this information to the | |
8391 | target. This lets capable targets implement filtering directly. */ | |
8392 | ||
8393 | /* Number of times that "any" syscall is requested. */ | |
8394 | int any_syscall_count; | |
8395 | ||
8396 | /* Count of each system call. */ | |
8397 | VEC(int) *syscalls_counts; | |
8398 | ||
8399 | /* This counts all syscall catch requests, so we can readily determine | |
8400 | if any catching is necessary. */ | |
8401 | int total_syscalls_count; | |
8402 | }; | |
8403 | ||
8404 | static struct catch_syscall_inferior_data* | |
8405 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8406 | { | |
8407 | struct catch_syscall_inferior_data *inf_data; | |
8408 | ||
8409 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8410 | if (inf_data == NULL) | |
8411 | { | |
41bf6aca | 8412 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8413 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8414 | } | |
8415 | ||
8416 | return inf_data; | |
8417 | } | |
8418 | ||
8419 | static void | |
8420 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8421 | { | |
8422 | xfree (arg); | |
8423 | } | |
8424 | ||
8425 | ||
a96d9b2e SDJ |
8426 | /* Implement the "insert" breakpoint_ops method for syscall |
8427 | catchpoints. */ | |
8428 | ||
77b06cd7 TJB |
8429 | static int |
8430 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8431 | { |
be5c67c1 | 8432 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8433 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8434 | struct catch_syscall_inferior_data *inf_data |
8435 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8436 | |
fa3064dd | 8437 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8438 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8439 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8440 | else |
8441 | { | |
8442 | int i, iter; | |
cc59ec59 | 8443 | |
a96d9b2e | 8444 | for (i = 0; |
be5c67c1 | 8445 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8446 | i++) |
8447 | { | |
8448 | int elem; | |
cc59ec59 | 8449 | |
fa3064dd | 8450 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8451 | { |
fa3064dd | 8452 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8453 | uintptr_t vec_addr_offset |
8454 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8455 | uintptr_t vec_addr; |
fa3064dd YQ |
8456 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8457 | vec_addr = ((uintptr_t) VEC_address (int, | |
8458 | inf_data->syscalls_counts) | |
8459 | + vec_addr_offset); | |
a96d9b2e SDJ |
8460 | memset ((void *) vec_addr, 0, |
8461 | (iter + 1 - old_size) * sizeof (int)); | |
8462 | } | |
fa3064dd YQ |
8463 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8464 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8465 | } |
8466 | } | |
8467 | ||
dfd4cc63 | 8468 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8469 | inf_data->total_syscalls_count != 0, |
8470 | inf_data->any_syscall_count, | |
8471 | VEC_length (int, | |
8472 | inf_data->syscalls_counts), | |
8473 | VEC_address (int, | |
8474 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8475 | } |
8476 | ||
8477 | /* Implement the "remove" breakpoint_ops method for syscall | |
8478 | catchpoints. */ | |
8479 | ||
8480 | static int | |
77b06cd7 | 8481 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8482 | { |
be5c67c1 | 8483 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8484 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8485 | struct catch_syscall_inferior_data *inf_data |
8486 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8487 | |
fa3064dd | 8488 | --inf_data->total_syscalls_count; |
be5c67c1 | 8489 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8490 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8491 | else |
8492 | { | |
8493 | int i, iter; | |
cc59ec59 | 8494 | |
a96d9b2e | 8495 | for (i = 0; |
be5c67c1 | 8496 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8497 | i++) |
8498 | { | |
8499 | int elem; | |
fa3064dd | 8500 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8501 | /* Shouldn't happen. */ |
8502 | continue; | |
fa3064dd YQ |
8503 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8504 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8505 | } |
8506 | } | |
8507 | ||
dfd4cc63 | 8508 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8509 | inf_data->total_syscalls_count != 0, |
8510 | inf_data->any_syscall_count, | |
8511 | VEC_length (int, | |
8512 | inf_data->syscalls_counts), | |
3e43a32a | 8513 | VEC_address (int, |
fa3064dd | 8514 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8515 | } |
8516 | ||
8517 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8518 | catchpoints. */ | |
8519 | ||
8520 | static int | |
f1310107 | 8521 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8522 | struct address_space *aspace, CORE_ADDR bp_addr, |
8523 | const struct target_waitstatus *ws) | |
a96d9b2e | 8524 | { |
4a64f543 MS |
8525 | /* We must check if we are catching specific syscalls in this |
8526 | breakpoint. If we are, then we must guarantee that the called | |
8527 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8528 | int syscall_number = 0; |
be5c67c1 PA |
8529 | const struct syscall_catchpoint *c |
8530 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8531 | |
f90263c1 TT |
8532 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8533 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8534 | return 0; |
8535 | ||
f90263c1 TT |
8536 | syscall_number = ws->value.syscall_number; |
8537 | ||
a96d9b2e | 8538 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8539 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8540 | { |
8541 | int i, iter; | |
cc59ec59 | 8542 | |
a96d9b2e | 8543 | for (i = 0; |
be5c67c1 | 8544 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8545 | i++) |
8546 | if (syscall_number == iter) | |
4924df79 GKB |
8547 | return 1; |
8548 | ||
8549 | return 0; | |
a96d9b2e SDJ |
8550 | } |
8551 | ||
8552 | return 1; | |
8553 | } | |
8554 | ||
8555 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8556 | catchpoints. */ | |
8557 | ||
8558 | static enum print_stop_action | |
348d480f | 8559 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8560 | { |
36dfb11c | 8561 | struct ui_out *uiout = current_uiout; |
348d480f | 8562 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8563 | /* These are needed because we want to know in which state a |
8564 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8565 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8566 | must print "called syscall" or "returned from syscall". */ | |
8567 | ptid_t ptid; | |
8568 | struct target_waitstatus last; | |
8569 | struct syscall s; | |
a96d9b2e SDJ |
8570 | |
8571 | get_last_target_status (&ptid, &last); | |
8572 | ||
8573 | get_syscall_by_number (last.value.syscall_number, &s); | |
8574 | ||
8575 | annotate_catchpoint (b->number); | |
8576 | ||
36dfb11c TT |
8577 | if (b->disposition == disp_del) |
8578 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8579 | else |
36dfb11c TT |
8580 | ui_out_text (uiout, "\nCatchpoint "); |
8581 | if (ui_out_is_mi_like_p (uiout)) | |
8582 | { | |
8583 | ui_out_field_string (uiout, "reason", | |
8584 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8585 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8586 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8587 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8588 | } | |
8589 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8590 | |
8591 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8592 | ui_out_text (uiout, " (call to syscall "); |
8593 | else | |
8594 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8595 | |
36dfb11c TT |
8596 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8597 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8598 | if (s.name != NULL) | |
8599 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8600 | ||
8601 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8602 | |
8603 | return PRINT_SRC_AND_LOC; | |
8604 | } | |
8605 | ||
8606 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8607 | catchpoints. */ | |
8608 | ||
8609 | static void | |
8610 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8611 | struct bp_location **last_loc) |
a96d9b2e | 8612 | { |
be5c67c1 | 8613 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8614 | struct value_print_options opts; |
79a45e25 | 8615 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8616 | |
8617 | get_user_print_options (&opts); | |
4a64f543 MS |
8618 | /* Field 4, the address, is omitted (which makes the columns not |
8619 | line up too nicely with the headers, but the effect is relatively | |
8620 | readable). */ | |
a96d9b2e SDJ |
8621 | if (opts.addressprint) |
8622 | ui_out_field_skip (uiout, "addr"); | |
8623 | annotate_field (5); | |
8624 | ||
be5c67c1 PA |
8625 | if (c->syscalls_to_be_caught |
8626 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8627 | ui_out_text (uiout, "syscalls \""); |
8628 | else | |
8629 | ui_out_text (uiout, "syscall \""); | |
8630 | ||
be5c67c1 | 8631 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8632 | { |
8633 | int i, iter; | |
8634 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8635 | |
a96d9b2e | 8636 | for (i = 0; |
be5c67c1 | 8637 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8638 | i++) |
8639 | { | |
8640 | char *x = text; | |
8641 | struct syscall s; | |
8642 | get_syscall_by_number (iter, &s); | |
8643 | ||
8644 | if (s.name != NULL) | |
8645 | text = xstrprintf ("%s%s, ", text, s.name); | |
8646 | else | |
8647 | text = xstrprintf ("%s%d, ", text, iter); | |
8648 | ||
8649 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8650 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8651 | on every call. */ |
8652 | xfree (x); | |
8653 | } | |
8654 | /* Remove the last comma. */ | |
8655 | text[strlen (text) - 2] = '\0'; | |
8656 | ui_out_field_string (uiout, "what", text); | |
8657 | } | |
8658 | else | |
8659 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8660 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8661 | |
8662 | if (ui_out_is_mi_like_p (uiout)) | |
8663 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8664 | } |
8665 | ||
8666 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8667 | catchpoints. */ | |
8668 | ||
8669 | static void | |
8670 | print_mention_catch_syscall (struct breakpoint *b) | |
8671 | { | |
be5c67c1 PA |
8672 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8673 | ||
8674 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8675 | { |
8676 | int i, iter; | |
8677 | ||
be5c67c1 | 8678 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8679 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8680 | else | |
8681 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8682 | ||
8683 | for (i = 0; | |
be5c67c1 | 8684 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8685 | i++) |
8686 | { | |
8687 | struct syscall s; | |
8688 | get_syscall_by_number (iter, &s); | |
8689 | ||
8690 | if (s.name) | |
8691 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8692 | else | |
8693 | printf_filtered (" %d", s.number); | |
8694 | } | |
8695 | printf_filtered (")"); | |
8696 | } | |
8697 | else | |
8698 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8699 | b->number); | |
8700 | } | |
8701 | ||
6149aea9 PA |
8702 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8703 | catchpoints. */ | |
8704 | ||
8705 | static void | |
8706 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8707 | { | |
be5c67c1 PA |
8708 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8709 | ||
6149aea9 PA |
8710 | fprintf_unfiltered (fp, "catch syscall"); |
8711 | ||
be5c67c1 | 8712 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8713 | { |
8714 | int i, iter; | |
8715 | ||
8716 | for (i = 0; | |
be5c67c1 | 8717 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8718 | i++) |
8719 | { | |
8720 | struct syscall s; | |
8721 | ||
8722 | get_syscall_by_number (iter, &s); | |
8723 | if (s.name) | |
8724 | fprintf_unfiltered (fp, " %s", s.name); | |
8725 | else | |
8726 | fprintf_unfiltered (fp, " %d", s.number); | |
8727 | } | |
8728 | } | |
d9b3f62e | 8729 | print_recreate_thread (b, fp); |
6149aea9 PA |
8730 | } |
8731 | ||
a96d9b2e SDJ |
8732 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8733 | ||
2060206e | 8734 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8735 | |
8736 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8737 | ||
8738 | static int | |
8739 | syscall_catchpoint_p (struct breakpoint *b) | |
8740 | { | |
8741 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8742 | } | |
8743 | ||
346774a9 PA |
8744 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8745 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8746 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8747 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8748 | |
ab04a2af | 8749 | void |
346774a9 PA |
8750 | init_catchpoint (struct breakpoint *b, |
8751 | struct gdbarch *gdbarch, int tempflag, | |
8752 | char *cond_string, | |
c0a91b2b | 8753 | const struct breakpoint_ops *ops) |
c906108c | 8754 | { |
c5aa993b | 8755 | struct symtab_and_line sal; |
346774a9 | 8756 | |
fe39c653 | 8757 | init_sal (&sal); |
6c95b8df | 8758 | sal.pspace = current_program_space; |
c5aa993b | 8759 | |
28010a5d | 8760 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8761 | |
1b36a34b | 8762 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8763 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8764 | } |
8765 | ||
28010a5d | 8766 | void |
3ea46bff | 8767 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8768 | { |
8769 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8770 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8771 | if (is_tracepoint (b)) |
8772 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8773 | if (!internal) |
8774 | mention (b); | |
c56053d2 | 8775 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8776 | |
8777 | if (update_gll) | |
8778 | update_global_location_list (1); | |
c56053d2 PA |
8779 | } |
8780 | ||
9b70b993 | 8781 | static void |
a6d9a66e UW |
8782 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8783 | int tempflag, char *cond_string, | |
c0a91b2b | 8784 | const struct breakpoint_ops *ops) |
c906108c | 8785 | { |
e29a4733 | 8786 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8787 | |
e29a4733 PA |
8788 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8789 | ||
8790 | c->forked_inferior_pid = null_ptid; | |
8791 | ||
3ea46bff | 8792 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8793 | } |
8794 | ||
fe798b75 JB |
8795 | /* Exec catchpoints. */ |
8796 | ||
b4d90040 PA |
8797 | /* An instance of this type is used to represent an exec catchpoint. |
8798 | It includes a "struct breakpoint" as a kind of base class; users | |
8799 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8800 | really of this type iff its ops pointer points to | |
8801 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8802 | ||
8803 | struct exec_catchpoint | |
8804 | { | |
8805 | /* The base class. */ | |
8806 | struct breakpoint base; | |
8807 | ||
8808 | /* Filename of a program whose exec triggered this catchpoint. | |
8809 | This field is only valid immediately after this catchpoint has | |
8810 | triggered. */ | |
8811 | char *exec_pathname; | |
8812 | }; | |
8813 | ||
8814 | /* Implement the "dtor" breakpoint_ops method for exec | |
8815 | catchpoints. */ | |
8816 | ||
8817 | static void | |
8818 | dtor_catch_exec (struct breakpoint *b) | |
8819 | { | |
8820 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8821 | ||
8822 | xfree (c->exec_pathname); | |
348d480f | 8823 | |
2060206e | 8824 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8825 | } |
8826 | ||
77b06cd7 TJB |
8827 | static int |
8828 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8829 | { |
dfd4cc63 | 8830 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8831 | } |
c906108c | 8832 | |
fe798b75 | 8833 | static int |
77b06cd7 | 8834 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8835 | { |
dfd4cc63 | 8836 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8837 | } |
c906108c | 8838 | |
fe798b75 | 8839 | static int |
f1310107 | 8840 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8841 | struct address_space *aspace, CORE_ADDR bp_addr, |
8842 | const struct target_waitstatus *ws) | |
fe798b75 | 8843 | { |
b4d90040 PA |
8844 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8845 | ||
f90263c1 TT |
8846 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8847 | return 0; | |
8848 | ||
8849 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8850 | return 1; | |
fe798b75 | 8851 | } |
c906108c | 8852 | |
fe798b75 | 8853 | static enum print_stop_action |
348d480f | 8854 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8855 | { |
36dfb11c | 8856 | struct ui_out *uiout = current_uiout; |
348d480f | 8857 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8858 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8859 | ||
fe798b75 | 8860 | annotate_catchpoint (b->number); |
36dfb11c TT |
8861 | if (b->disposition == disp_del) |
8862 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8863 | else | |
8864 | ui_out_text (uiout, "\nCatchpoint "); | |
8865 | if (ui_out_is_mi_like_p (uiout)) | |
8866 | { | |
8867 | ui_out_field_string (uiout, "reason", | |
8868 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8869 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8870 | } | |
8871 | ui_out_field_int (uiout, "bkptno", b->number); | |
8872 | ui_out_text (uiout, " (exec'd "); | |
8873 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8874 | ui_out_text (uiout, "), "); | |
8875 | ||
fe798b75 | 8876 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8877 | } |
8878 | ||
fe798b75 | 8879 | static void |
a6d9a66e | 8880 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8881 | { |
b4d90040 | 8882 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8883 | struct value_print_options opts; |
79a45e25 | 8884 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8885 | |
8886 | get_user_print_options (&opts); | |
8887 | ||
8888 | /* Field 4, the address, is omitted (which makes the columns | |
8889 | not line up too nicely with the headers, but the effect | |
8890 | is relatively readable). */ | |
8891 | if (opts.addressprint) | |
8892 | ui_out_field_skip (uiout, "addr"); | |
8893 | annotate_field (5); | |
8894 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8895 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8896 | { |
8897 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8898 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8899 | ui_out_text (uiout, "\" "); |
8900 | } | |
8ac3646f TT |
8901 | |
8902 | if (ui_out_is_mi_like_p (uiout)) | |
8903 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8904 | } |
8905 | ||
8906 | static void | |
8907 | print_mention_catch_exec (struct breakpoint *b) | |
8908 | { | |
8909 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8910 | } | |
8911 | ||
6149aea9 PA |
8912 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8913 | catchpoints. */ | |
8914 | ||
8915 | static void | |
8916 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8917 | { | |
8918 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8919 | print_recreate_thread (b, fp); |
6149aea9 PA |
8920 | } |
8921 | ||
2060206e | 8922 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8923 | |
a96d9b2e SDJ |
8924 | static void |
8925 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8926 | const struct breakpoint_ops *ops) |
a96d9b2e | 8927 | { |
be5c67c1 | 8928 | struct syscall_catchpoint *c; |
a96d9b2e | 8929 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8930 | |
be5c67c1 PA |
8931 | c = XNEW (struct syscall_catchpoint); |
8932 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8933 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8934 | |
3ea46bff | 8935 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8936 | } |
8937 | ||
c906108c | 8938 | static int |
fba45db2 | 8939 | hw_breakpoint_used_count (void) |
c906108c | 8940 | { |
c906108c | 8941 | int i = 0; |
f1310107 TJB |
8942 | struct breakpoint *b; |
8943 | struct bp_location *bl; | |
c906108c SS |
8944 | |
8945 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8946 | { |
d6b74ac4 | 8947 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8948 | for (bl = b->loc; bl; bl = bl->next) |
8949 | { | |
8950 | /* Special types of hardware breakpoints may use more than | |
8951 | one register. */ | |
348d480f | 8952 | i += b->ops->resources_needed (bl); |
f1310107 | 8953 | } |
c5aa993b | 8954 | } |
c906108c SS |
8955 | |
8956 | return i; | |
8957 | } | |
8958 | ||
a1398e0c PA |
8959 | /* Returns the resources B would use if it were a hardware |
8960 | watchpoint. */ | |
8961 | ||
c906108c | 8962 | static int |
a1398e0c | 8963 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8964 | { |
c906108c | 8965 | int i = 0; |
e09342b5 | 8966 | struct bp_location *bl; |
c906108c | 8967 | |
a1398e0c PA |
8968 | if (!breakpoint_enabled (b)) |
8969 | return 0; | |
8970 | ||
8971 | for (bl = b->loc; bl; bl = bl->next) | |
8972 | { | |
8973 | /* Special types of hardware watchpoints may use more than | |
8974 | one register. */ | |
8975 | i += b->ops->resources_needed (bl); | |
8976 | } | |
8977 | ||
8978 | return i; | |
8979 | } | |
8980 | ||
8981 | /* Returns the sum the used resources of all hardware watchpoints of | |
8982 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8983 | the sum of the used resources of all hardware watchpoints of other | |
8984 | types _not_ TYPE. */ | |
8985 | ||
8986 | static int | |
8987 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8988 | enum bptype type, int *other_type_used) | |
8989 | { | |
8990 | int i = 0; | |
8991 | struct breakpoint *b; | |
8992 | ||
c906108c SS |
8993 | *other_type_used = 0; |
8994 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8995 | { |
a1398e0c PA |
8996 | if (b == except) |
8997 | continue; | |
e09342b5 TJB |
8998 | if (!breakpoint_enabled (b)) |
8999 | continue; | |
9000 | ||
a1398e0c PA |
9001 | if (b->type == type) |
9002 | i += hw_watchpoint_use_count (b); | |
9003 | else if (is_hardware_watchpoint (b)) | |
9004 | *other_type_used = 1; | |
e09342b5 TJB |
9005 | } |
9006 | ||
c906108c SS |
9007 | return i; |
9008 | } | |
9009 | ||
c906108c | 9010 | void |
fba45db2 | 9011 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 9012 | { |
c5aa993b | 9013 | struct breakpoint *b; |
c906108c SS |
9014 | |
9015 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9016 | { |
cc60f2e3 | 9017 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 9018 | { |
b5de0fa7 | 9019 | b->enable_state = bp_call_disabled; |
b60e7edf | 9020 | update_global_location_list (0); |
c5aa993b JM |
9021 | } |
9022 | } | |
c906108c SS |
9023 | } |
9024 | ||
9025 | void | |
fba45db2 | 9026 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 9027 | { |
c5aa993b | 9028 | struct breakpoint *b; |
c906108c SS |
9029 | |
9030 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9031 | { |
cc60f2e3 | 9032 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 9033 | { |
b5de0fa7 | 9034 | b->enable_state = bp_enabled; |
b60e7edf | 9035 | update_global_location_list (1); |
c5aa993b JM |
9036 | } |
9037 | } | |
c906108c SS |
9038 | } |
9039 | ||
8bea4e01 UW |
9040 | void |
9041 | disable_breakpoints_before_startup (void) | |
9042 | { | |
6c95b8df | 9043 | current_program_space->executing_startup = 1; |
f8eba3c6 | 9044 | update_global_location_list (0); |
8bea4e01 UW |
9045 | } |
9046 | ||
9047 | void | |
9048 | enable_breakpoints_after_startup (void) | |
9049 | { | |
6c95b8df | 9050 | current_program_space->executing_startup = 0; |
f8eba3c6 | 9051 | breakpoint_re_set (); |
8bea4e01 UW |
9052 | } |
9053 | ||
c906108c SS |
9054 | |
9055 | /* Set a breakpoint that will evaporate an end of command | |
9056 | at address specified by SAL. | |
9057 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
9058 | ||
9059 | struct breakpoint * | |
a6d9a66e UW |
9060 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
9061 | struct frame_id frame_id, enum bptype type) | |
c906108c | 9062 | { |
52f0bd74 | 9063 | struct breakpoint *b; |
edb3359d | 9064 | |
193facb3 JK |
9065 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
9066 | tail-called one. */ | |
9067 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 9068 | |
06edf0c0 | 9069 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
9070 | b->enable_state = bp_enabled; |
9071 | b->disposition = disp_donttouch; | |
818dd999 | 9072 | b->frame_id = frame_id; |
c906108c | 9073 | |
4a64f543 MS |
9074 | /* If we're debugging a multi-threaded program, then we want |
9075 | momentary breakpoints to be active in only a single thread of | |
9076 | control. */ | |
39f77062 KB |
9077 | if (in_thread_list (inferior_ptid)) |
9078 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 9079 | |
b60e7edf | 9080 | update_global_location_list_nothrow (1); |
74960c60 | 9081 | |
c906108c SS |
9082 | return b; |
9083 | } | |
611c83ae | 9084 | |
06edf0c0 | 9085 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
9086 | The new breakpoint will have type TYPE, use OPS as its |
9087 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 9088 | |
06edf0c0 PA |
9089 | static struct breakpoint * |
9090 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
9091 | enum bptype type, | |
a1aa2221 LM |
9092 | const struct breakpoint_ops *ops, |
9093 | int loc_enabled) | |
e58b0e63 PA |
9094 | { |
9095 | struct breakpoint *copy; | |
9096 | ||
06edf0c0 | 9097 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 9098 | copy->loc = allocate_bp_location (copy); |
0e30163f | 9099 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 9100 | |
a6d9a66e | 9101 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
9102 | copy->loc->requested_address = orig->loc->requested_address; |
9103 | copy->loc->address = orig->loc->address; | |
9104 | copy->loc->section = orig->loc->section; | |
6c95b8df | 9105 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 9106 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 9107 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 9108 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 9109 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9110 | copy->frame_id = orig->frame_id; |
9111 | copy->thread = orig->thread; | |
6c95b8df | 9112 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9113 | |
9114 | copy->enable_state = bp_enabled; | |
9115 | copy->disposition = disp_donttouch; | |
9116 | copy->number = internal_breakpoint_number--; | |
9117 | ||
9118 | update_global_location_list_nothrow (0); | |
9119 | return copy; | |
9120 | } | |
9121 | ||
06edf0c0 PA |
9122 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9123 | ORIG is NULL. */ | |
9124 | ||
9125 | struct breakpoint * | |
9126 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9127 | { | |
9128 | /* If there's nothing to clone, then return nothing. */ | |
9129 | if (orig == NULL) | |
9130 | return NULL; | |
9131 | ||
a1aa2221 | 9132 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9133 | } |
9134 | ||
611c83ae | 9135 | struct breakpoint * |
a6d9a66e UW |
9136 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9137 | enum bptype type) | |
611c83ae PA |
9138 | { |
9139 | struct symtab_and_line sal; | |
9140 | ||
9141 | sal = find_pc_line (pc, 0); | |
9142 | sal.pc = pc; | |
9143 | sal.section = find_pc_overlay (pc); | |
9144 | sal.explicit_pc = 1; | |
9145 | ||
a6d9a66e | 9146 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9147 | } |
c906108c | 9148 | \f |
c5aa993b | 9149 | |
c906108c SS |
9150 | /* Tell the user we have just set a breakpoint B. */ |
9151 | ||
9152 | static void | |
fba45db2 | 9153 | mention (struct breakpoint *b) |
c906108c | 9154 | { |
348d480f | 9155 | b->ops->print_mention (b); |
79a45e25 | 9156 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9157 | return; |
c906108c SS |
9158 | printf_filtered ("\n"); |
9159 | } | |
c906108c | 9160 | \f |
c5aa993b | 9161 | |
0d381245 | 9162 | static struct bp_location * |
39d61571 | 9163 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9164 | const struct symtab_and_line *sal) |
9165 | { | |
9166 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9167 | CORE_ADDR adjusted_address; |
9168 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9169 | ||
9170 | if (loc_gdbarch == NULL) | |
9171 | loc_gdbarch = b->gdbarch; | |
9172 | ||
9173 | /* Adjust the breakpoint's address prior to allocating a location. | |
9174 | Once we call allocate_bp_location(), that mostly uninitialized | |
9175 | location will be placed on the location chain. Adjustment of the | |
9176 | breakpoint may cause target_read_memory() to be called and we do | |
9177 | not want its scan of the location chain to find a breakpoint and | |
9178 | location that's only been partially initialized. */ | |
9179 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9180 | sal->pc, b->type); | |
0d381245 | 9181 | |
d30113d4 | 9182 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9183 | loc = allocate_bp_location (b); |
d30113d4 JK |
9184 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9185 | tmp = &((*tmp)->next)) | |
0d381245 | 9186 | ; |
d30113d4 | 9187 | loc->next = *tmp; |
0d381245 | 9188 | *tmp = loc; |
3742cc8b | 9189 | |
0d381245 | 9190 | loc->requested_address = sal->pc; |
3742cc8b | 9191 | loc->address = adjusted_address; |
6c95b8df | 9192 | loc->pspace = sal->pspace; |
729662a5 TT |
9193 | loc->probe.probe = sal->probe; |
9194 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9195 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9196 | loc->section = sal->section; |
3742cc8b | 9197 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9198 | loc->line_number = sal->line; |
2f202fde | 9199 | loc->symtab = sal->symtab; |
f8eba3c6 | 9200 | |
0e30163f JK |
9201 | set_breakpoint_location_function (loc, |
9202 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
9203 | return loc; |
9204 | } | |
514f746b AR |
9205 | \f |
9206 | ||
9207 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9208 | return 0 otherwise. */ | |
9209 | ||
9210 | static int | |
9211 | bp_loc_is_permanent (struct bp_location *loc) | |
9212 | { | |
9213 | int len; | |
9214 | CORE_ADDR addr; | |
1afeeb75 | 9215 | const gdb_byte *bpoint; |
514f746b | 9216 | gdb_byte *target_mem; |
939c61fa JK |
9217 | struct cleanup *cleanup; |
9218 | int retval = 0; | |
514f746b AR |
9219 | |
9220 | gdb_assert (loc != NULL); | |
9221 | ||
9222 | addr = loc->address; | |
1afeeb75 | 9223 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9224 | |
939c61fa | 9225 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9226 | if (bpoint == NULL) |
939c61fa JK |
9227 | return 0; |
9228 | ||
514f746b AR |
9229 | target_mem = alloca (len); |
9230 | ||
939c61fa JK |
9231 | /* Enable the automatic memory restoration from breakpoints while |
9232 | we read the memory. Otherwise we could say about our temporary | |
9233 | breakpoints they are permanent. */ | |
6c95b8df PA |
9234 | cleanup = save_current_space_and_thread (); |
9235 | ||
9236 | switch_to_program_space_and_thread (loc->pspace); | |
9237 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9238 | |
514f746b | 9239 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9240 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9241 | retval = 1; |
514f746b | 9242 | |
939c61fa JK |
9243 | do_cleanups (cleanup); |
9244 | ||
9245 | return retval; | |
514f746b AR |
9246 | } |
9247 | ||
e7e0cddf SS |
9248 | /* Build a command list for the dprintf corresponding to the current |
9249 | settings of the dprintf style options. */ | |
9250 | ||
9251 | static void | |
9252 | update_dprintf_command_list (struct breakpoint *b) | |
9253 | { | |
9254 | char *dprintf_args = b->extra_string; | |
9255 | char *printf_line = NULL; | |
9256 | ||
9257 | if (!dprintf_args) | |
9258 | return; | |
9259 | ||
9260 | dprintf_args = skip_spaces (dprintf_args); | |
9261 | ||
9262 | /* Allow a comma, as it may have terminated a location, but don't | |
9263 | insist on it. */ | |
9264 | if (*dprintf_args == ',') | |
9265 | ++dprintf_args; | |
9266 | dprintf_args = skip_spaces (dprintf_args); | |
9267 | ||
9268 | if (*dprintf_args != '"') | |
9269 | error (_("Bad format string, missing '\"'.")); | |
9270 | ||
d3ce09f5 | 9271 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9272 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9273 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9274 | { |
9275 | if (!dprintf_function) | |
9276 | error (_("No function supplied for dprintf call")); | |
9277 | ||
9278 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9279 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9280 | dprintf_function, | |
9281 | dprintf_channel, | |
9282 | dprintf_args); | |
9283 | else | |
9284 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9285 | dprintf_function, | |
9286 | dprintf_args); | |
9287 | } | |
d3ce09f5 SS |
9288 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9289 | { | |
9290 | if (target_can_run_breakpoint_commands ()) | |
9291 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9292 | else | |
9293 | { | |
9294 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9295 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9296 | } | |
9297 | } | |
e7e0cddf SS |
9298 | else |
9299 | internal_error (__FILE__, __LINE__, | |
9300 | _("Invalid dprintf style.")); | |
9301 | ||
f28045c2 | 9302 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9303 | /* Manufacture a printf sequence. */ |
f28045c2 | 9304 | { |
9d6e6e84 HZ |
9305 | struct command_line *printf_cmd_line |
9306 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9307 | |
f28045c2 YQ |
9308 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9309 | printf_cmd_line->control_type = simple_control; | |
9310 | printf_cmd_line->body_count = 0; | |
9311 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9312 | printf_cmd_line->next = NULL; |
f28045c2 | 9313 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9314 | |
f28045c2 YQ |
9315 | breakpoint_set_commands (b, printf_cmd_line); |
9316 | } | |
e7e0cddf SS |
9317 | } |
9318 | ||
9319 | /* Update all dprintf commands, making their command lists reflect | |
9320 | current style settings. */ | |
9321 | ||
9322 | static void | |
9323 | update_dprintf_commands (char *args, int from_tty, | |
9324 | struct cmd_list_element *c) | |
9325 | { | |
9326 | struct breakpoint *b; | |
9327 | ||
9328 | ALL_BREAKPOINTS (b) | |
9329 | { | |
9330 | if (b->type == bp_dprintf) | |
9331 | update_dprintf_command_list (b); | |
9332 | } | |
9333 | } | |
c3f6f71d | 9334 | |
018d34a4 VP |
9335 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9336 | as textual description of the location, and COND_STRING | |
db107f19 | 9337 | as condition expression. */ |
018d34a4 VP |
9338 | |
9339 | static void | |
d9b3f62e PA |
9340 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9341 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9342 | char *filter, char *cond_string, |
e7e0cddf | 9343 | char *extra_string, |
d9b3f62e PA |
9344 | enum bptype type, enum bpdisp disposition, |
9345 | int thread, int task, int ignore_count, | |
c0a91b2b | 9346 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9347 | int enabled, int internal, unsigned flags, |
9348 | int display_canonical) | |
018d34a4 | 9349 | { |
0d381245 | 9350 | int i; |
018d34a4 VP |
9351 | |
9352 | if (type == bp_hardware_breakpoint) | |
9353 | { | |
fbbd034e AS |
9354 | int target_resources_ok; |
9355 | ||
9356 | i = hw_breakpoint_used_count (); | |
9357 | target_resources_ok = | |
9358 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9359 | i + 1, 0); |
9360 | if (target_resources_ok == 0) | |
9361 | error (_("No hardware breakpoint support in the target.")); | |
9362 | else if (target_resources_ok < 0) | |
9363 | error (_("Hardware breakpoints used exceeds limit.")); | |
9364 | } | |
9365 | ||
6c95b8df PA |
9366 | gdb_assert (sals.nelts > 0); |
9367 | ||
0d381245 VP |
9368 | for (i = 0; i < sals.nelts; ++i) |
9369 | { | |
9370 | struct symtab_and_line sal = sals.sals[i]; | |
9371 | struct bp_location *loc; | |
9372 | ||
9373 | if (from_tty) | |
5af949e3 UW |
9374 | { |
9375 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9376 | if (!loc_gdbarch) | |
9377 | loc_gdbarch = gdbarch; | |
9378 | ||
9379 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9380 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9381 | } |
0d381245 VP |
9382 | |
9383 | if (i == 0) | |
9384 | { | |
d9b3f62e | 9385 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9386 | b->thread = thread; |
4a306c9a | 9387 | b->task = task; |
855a6e68 | 9388 | |
0d381245 | 9389 | b->cond_string = cond_string; |
e7e0cddf | 9390 | b->extra_string = extra_string; |
0d381245 | 9391 | b->ignore_count = ignore_count; |
41447f92 | 9392 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9393 | b->disposition = disposition; |
6c95b8df | 9394 | |
44f238bb PA |
9395 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9396 | b->loc->inserted = 1; | |
9397 | ||
0fb4aa4b PA |
9398 | if (type == bp_static_tracepoint) |
9399 | { | |
d9b3f62e | 9400 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9401 | struct static_tracepoint_marker marker; |
9402 | ||
983af33b | 9403 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9404 | { |
9405 | /* We already know the marker exists, otherwise, we | |
9406 | wouldn't see a sal for it. */ | |
9407 | char *p = &addr_string[3]; | |
9408 | char *endp; | |
9409 | char *marker_str; | |
0fb4aa4b | 9410 | |
e9cafbcc | 9411 | p = skip_spaces (p); |
0fb4aa4b | 9412 | |
e9cafbcc | 9413 | endp = skip_to_space (p); |
0fb4aa4b PA |
9414 | |
9415 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9416 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9417 | |
3e43a32a MS |
9418 | printf_filtered (_("Probed static tracepoint " |
9419 | "marker \"%s\"\n"), | |
d9b3f62e | 9420 | t->static_trace_marker_id); |
0fb4aa4b PA |
9421 | } |
9422 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9423 | { | |
d9b3f62e | 9424 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9425 | release_static_tracepoint_marker (&marker); |
9426 | ||
3e43a32a MS |
9427 | printf_filtered (_("Probed static tracepoint " |
9428 | "marker \"%s\"\n"), | |
d9b3f62e | 9429 | t->static_trace_marker_id); |
0fb4aa4b PA |
9430 | } |
9431 | else | |
3e43a32a MS |
9432 | warning (_("Couldn't determine the static " |
9433 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9434 | } |
9435 | ||
0d381245 VP |
9436 | loc = b->loc; |
9437 | } | |
9438 | else | |
018d34a4 | 9439 | { |
39d61571 | 9440 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9441 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9442 | loc->inserted = 1; | |
0d381245 VP |
9443 | } |
9444 | ||
514f746b AR |
9445 | if (bp_loc_is_permanent (loc)) |
9446 | make_breakpoint_permanent (b); | |
9447 | ||
0d381245 VP |
9448 | if (b->cond_string) |
9449 | { | |
bbc13ae3 KS |
9450 | const char *arg = b->cond_string; |
9451 | ||
1bb9788d TT |
9452 | loc->cond = parse_exp_1 (&arg, loc->address, |
9453 | block_for_pc (loc->address), 0); | |
0d381245 | 9454 | if (*arg) |
588ae58c | 9455 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9456 | } |
e7e0cddf SS |
9457 | |
9458 | /* Dynamic printf requires and uses additional arguments on the | |
9459 | command line, otherwise it's an error. */ | |
9460 | if (type == bp_dprintf) | |
9461 | { | |
9462 | if (b->extra_string) | |
9463 | update_dprintf_command_list (b); | |
9464 | else | |
9465 | error (_("Format string required")); | |
9466 | } | |
9467 | else if (b->extra_string) | |
588ae58c | 9468 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9469 | } |
018d34a4 | 9470 | |
56435ebe | 9471 | b->display_canonical = display_canonical; |
018d34a4 VP |
9472 | if (addr_string) |
9473 | b->addr_string = addr_string; | |
9474 | else | |
9475 | /* addr_string has to be used or breakpoint_re_set will delete | |
9476 | me. */ | |
5af949e3 UW |
9477 | b->addr_string |
9478 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9479 | b->filter = filter; |
d9b3f62e | 9480 | } |
018d34a4 | 9481 | |
d9b3f62e PA |
9482 | static void |
9483 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9484 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9485 | char *filter, char *cond_string, |
e7e0cddf | 9486 | char *extra_string, |
d9b3f62e PA |
9487 | enum bptype type, enum bpdisp disposition, |
9488 | int thread, int task, int ignore_count, | |
c0a91b2b | 9489 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9490 | int enabled, int internal, unsigned flags, |
9491 | int display_canonical) | |
d9b3f62e PA |
9492 | { |
9493 | struct breakpoint *b; | |
9494 | struct cleanup *old_chain; | |
9495 | ||
9496 | if (is_tracepoint_type (type)) | |
9497 | { | |
9498 | struct tracepoint *t; | |
9499 | ||
9500 | t = XCNEW (struct tracepoint); | |
9501 | b = &t->base; | |
9502 | } | |
9503 | else | |
9504 | b = XNEW (struct breakpoint); | |
9505 | ||
9506 | old_chain = make_cleanup (xfree, b); | |
9507 | ||
9508 | init_breakpoint_sal (b, gdbarch, | |
9509 | sals, addr_string, | |
e7e0cddf | 9510 | filter, cond_string, extra_string, |
d9b3f62e PA |
9511 | type, disposition, |
9512 | thread, task, ignore_count, | |
9513 | ops, from_tty, | |
44f238bb PA |
9514 | enabled, internal, flags, |
9515 | display_canonical); | |
d9b3f62e PA |
9516 | discard_cleanups (old_chain); |
9517 | ||
3ea46bff | 9518 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9519 | } |
9520 | ||
9521 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9522 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9523 | value. COND_STRING, if not NULL, specified the condition to be | |
9524 | used for all breakpoints. Essentially the only case where | |
9525 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9526 | function. In that case, it's still not possible to specify | |
9527 | separate conditions for different overloaded functions, so | |
9528 | we take just a single condition string. | |
9529 | ||
c3f6f71d | 9530 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9531 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9532 | array contents). If the function fails (error() is called), the |
9533 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9534 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9535 | |
9536 | static void | |
8cdf0e15 | 9537 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9538 | struct linespec_result *canonical, |
e7e0cddf | 9539 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9540 | enum bptype type, enum bpdisp disposition, |
9541 | int thread, int task, int ignore_count, | |
c0a91b2b | 9542 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9543 | int enabled, int internal, unsigned flags) |
c906108c | 9544 | { |
018d34a4 | 9545 | int i; |
f8eba3c6 | 9546 | struct linespec_sals *lsal; |
cc59ec59 | 9547 | |
f8eba3c6 TT |
9548 | if (canonical->pre_expanded) |
9549 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9550 | ||
9551 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9552 | { |
f8eba3c6 TT |
9553 | /* Note that 'addr_string' can be NULL in the case of a plain |
9554 | 'break', without arguments. */ | |
9555 | char *addr_string = (canonical->addr_string | |
9556 | ? xstrdup (canonical->addr_string) | |
9557 | : NULL); | |
9558 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9559 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9560 | |
f8eba3c6 TT |
9561 | make_cleanup (xfree, filter_string); |
9562 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9563 | addr_string, | |
9564 | filter_string, | |
e7e0cddf SS |
9565 | cond_string, extra_string, |
9566 | type, disposition, | |
84f4c1fe | 9567 | thread, task, ignore_count, ops, |
44f238bb | 9568 | from_tty, enabled, internal, flags, |
56435ebe | 9569 | canonical->special_display); |
f8eba3c6 | 9570 | discard_cleanups (inner); |
c3f6f71d | 9571 | } |
c3f6f71d | 9572 | } |
c906108c | 9573 | |
9998af43 | 9574 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9575 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9576 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9577 | address strings. ADDRESS points to the end of the SAL. |
9578 | ||
9579 | The array and the line spec strings are allocated on the heap, it is | |
9580 | the caller's responsibility to free them. */ | |
c906108c | 9581 | |
b9362cc7 | 9582 | static void |
c3f6f71d | 9583 | parse_breakpoint_sals (char **address, |
58438ac1 | 9584 | struct linespec_result *canonical) |
c3f6f71d | 9585 | { |
c3f6f71d | 9586 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9587 | breakpoint. */ |
c3f6f71d JM |
9588 | if ((*address) == NULL |
9589 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9590 | { |
1bfeeb0f JL |
9591 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9592 | address. */ | |
9593 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9594 | { |
f8eba3c6 | 9595 | struct linespec_sals lsal; |
c3f6f71d | 9596 | struct symtab_and_line sal; |
1c8cdcb1 | 9597 | CORE_ADDR pc; |
cc59ec59 | 9598 | |
4a64f543 | 9599 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9600 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9601 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9602 | |
9603 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9604 | corresponding to the last call to print_frame_info. |
9605 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9606 | as the breakpoint line number is inappropriate otherwise. | |
9607 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9608 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9609 | pc = sal.pc; |
9610 | sal = find_pc_line (pc, 0); | |
00903456 | 9611 | |
4a64f543 | 9612 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9613 | where PC is the last displayed codepoint's address. So |
9614 | make sure to set sal.explicit_pc to prevent GDB from | |
9615 | trying to expand the list of sals to include all other | |
9616 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9617 | sal.pc = pc; |
00903456 JK |
9618 | sal.explicit_pc = 1; |
9619 | ||
f8eba3c6 TT |
9620 | lsal.sals.sals[0] = sal; |
9621 | lsal.sals.nelts = 1; | |
9622 | lsal.canonical = NULL; | |
9623 | ||
9624 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9625 | } |
9626 | else | |
8a3fe4f8 | 9627 | error (_("No default breakpoint address now.")); |
c906108c SS |
9628 | } |
9629 | else | |
9630 | { | |
cc80f267 JK |
9631 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9632 | ||
c906108c | 9633 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9634 | current_source_symtab (which is decode_line_1's default). |
9635 | This should produce the results we want almost all of the | |
cc80f267 JK |
9636 | time while leaving default_breakpoint_* alone. |
9637 | ||
9638 | ObjC: However, don't match an Objective-C method name which | |
9639 | may have a '+' or '-' succeeded by a '['. */ | |
9640 | if (last_displayed_sal_is_valid () | |
9641 | && (!cursal.symtab | |
9642 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9643 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9644 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9645 | get_last_displayed_symtab (), | |
9646 | get_last_displayed_line (), | |
9647 | canonical, NULL, NULL); | |
c906108c | 9648 | else |
f8eba3c6 | 9649 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9650 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9651 | } |
c3f6f71d | 9652 | } |
c906108c | 9653 | |
c906108c | 9654 | |
c3f6f71d | 9655 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9656 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9657 | |
b9362cc7 | 9658 | static void |
23e7acfb | 9659 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9660 | { |
9661 | int i; | |
cc59ec59 | 9662 | |
c3f6f71d | 9663 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9664 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9665 | } |
9666 | ||
7a697b8d SS |
9667 | /* Fast tracepoints may have restrictions on valid locations. For |
9668 | instance, a fast tracepoint using a jump instead of a trap will | |
9669 | likely have to overwrite more bytes than a trap would, and so can | |
9670 | only be placed where the instruction is longer than the jump, or a | |
9671 | multi-instruction sequence does not have a jump into the middle of | |
9672 | it, etc. */ | |
9673 | ||
9674 | static void | |
9675 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9676 | struct symtabs_and_lines *sals) | |
9677 | { | |
9678 | int i, rslt; | |
9679 | struct symtab_and_line *sal; | |
9680 | char *msg; | |
9681 | struct cleanup *old_chain; | |
9682 | ||
9683 | for (i = 0; i < sals->nelts; i++) | |
9684 | { | |
f8eba3c6 TT |
9685 | struct gdbarch *sarch; |
9686 | ||
7a697b8d SS |
9687 | sal = &sals->sals[i]; |
9688 | ||
f8eba3c6 TT |
9689 | sarch = get_sal_arch (*sal); |
9690 | /* We fall back to GDBARCH if there is no architecture | |
9691 | associated with SAL. */ | |
9692 | if (sarch == NULL) | |
9693 | sarch = gdbarch; | |
9694 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9695 | NULL, &msg); |
9696 | old_chain = make_cleanup (xfree, msg); | |
9697 | ||
9698 | if (!rslt) | |
9699 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9700 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9701 | |
9702 | do_cleanups (old_chain); | |
9703 | } | |
9704 | } | |
9705 | ||
af4908ba KS |
9706 | /* Issue an invalid thread ID error. */ |
9707 | ||
9708 | static void ATTRIBUTE_NORETURN | |
9709 | invalid_thread_id_error (int id) | |
9710 | { | |
9711 | error (_("Unknown thread %d."), id); | |
9712 | } | |
9713 | ||
018d34a4 VP |
9714 | /* Given TOK, a string specification of condition and thread, as |
9715 | accepted by the 'break' command, extract the condition | |
9716 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9717 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9718 | If no condition is found, *COND_STRING is set to NULL. |
9719 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9720 | |
9721 | static void | |
bbc13ae3 | 9722 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9723 | char **cond_string, int *thread, int *task, |
9724 | char **rest) | |
018d34a4 VP |
9725 | { |
9726 | *cond_string = NULL; | |
9727 | *thread = -1; | |
ed1d1739 KS |
9728 | *task = 0; |
9729 | *rest = NULL; | |
9730 | ||
018d34a4 VP |
9731 | while (tok && *tok) |
9732 | { | |
bbc13ae3 | 9733 | const char *end_tok; |
018d34a4 | 9734 | int toklen; |
bbc13ae3 KS |
9735 | const char *cond_start = NULL; |
9736 | const char *cond_end = NULL; | |
cc59ec59 | 9737 | |
bbc13ae3 | 9738 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9739 | |
9740 | if ((*tok == '"' || *tok == ',') && rest) | |
9741 | { | |
9742 | *rest = savestring (tok, strlen (tok)); | |
9743 | return; | |
9744 | } | |
9745 | ||
bbc13ae3 | 9746 | end_tok = skip_to_space_const (tok); |
d634f2de | 9747 | |
018d34a4 | 9748 | toklen = end_tok - tok; |
d634f2de | 9749 | |
018d34a4 VP |
9750 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9751 | { | |
f7545552 TT |
9752 | struct expression *expr; |
9753 | ||
018d34a4 | 9754 | tok = cond_start = end_tok + 1; |
1bb9788d | 9755 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9756 | xfree (expr); |
018d34a4 | 9757 | cond_end = tok; |
d634f2de | 9758 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9759 | } |
9760 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9761 | { | |
9762 | char *tmptok; | |
d634f2de | 9763 | |
018d34a4 | 9764 | tok = end_tok + 1; |
bbc13ae3 | 9765 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9766 | if (tok == tmptok) |
9767 | error (_("Junk after thread keyword.")); | |
9768 | if (!valid_thread_id (*thread)) | |
af4908ba | 9769 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9770 | tok = tmptok; |
018d34a4 | 9771 | } |
4a306c9a JB |
9772 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9773 | { | |
9774 | char *tmptok; | |
9775 | ||
9776 | tok = end_tok + 1; | |
bbc13ae3 | 9777 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9778 | if (tok == tmptok) |
9779 | error (_("Junk after task keyword.")); | |
9780 | if (!valid_task_id (*task)) | |
b6199126 | 9781 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9782 | tok = tmptok; |
4a306c9a | 9783 | } |
e7e0cddf SS |
9784 | else if (rest) |
9785 | { | |
9786 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9787 | return; |
e7e0cddf | 9788 | } |
018d34a4 VP |
9789 | else |
9790 | error (_("Junk at end of arguments.")); | |
9791 | } | |
9792 | } | |
9793 | ||
0fb4aa4b PA |
9794 | /* Decode a static tracepoint marker spec. */ |
9795 | ||
9796 | static struct symtabs_and_lines | |
9797 | decode_static_tracepoint_spec (char **arg_p) | |
9798 | { | |
9799 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9800 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9801 | struct cleanup *old_chain; |
9802 | char *p = &(*arg_p)[3]; | |
9803 | char *endp; | |
9804 | char *marker_str; | |
9805 | int i; | |
9806 | ||
e9cafbcc | 9807 | p = skip_spaces (p); |
0fb4aa4b | 9808 | |
e9cafbcc | 9809 | endp = skip_to_space (p); |
0fb4aa4b PA |
9810 | |
9811 | marker_str = savestring (p, endp - p); | |
9812 | old_chain = make_cleanup (xfree, marker_str); | |
9813 | ||
9814 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9815 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9816 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9817 | ||
9818 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9819 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9820 | ||
9821 | for (i = 0; i < sals.nelts; i++) | |
9822 | { | |
9823 | struct static_tracepoint_marker *marker; | |
9824 | ||
9825 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9826 | ||
9827 | init_sal (&sals.sals[i]); | |
9828 | ||
9829 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9830 | sals.sals[i].pc = marker->address; | |
9831 | ||
9832 | release_static_tracepoint_marker (marker); | |
9833 | } | |
9834 | ||
9835 | do_cleanups (old_chain); | |
9836 | ||
9837 | *arg_p = endp; | |
9838 | return sals; | |
9839 | } | |
9840 | ||
fd9b8c24 PA |
9841 | /* Set a breakpoint. This function is shared between CLI and MI |
9842 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9843 | modes of operations, selected by the PARSE_ARG parameter. If |
9844 | non-zero, the function will parse ARG, extracting location, | |
9845 | condition, thread and extra string. Otherwise, ARG is just the | |
9846 | breakpoint's location, with condition, thread, and extra string | |
9847 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9848 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9849 | from the internal breakpoint count. Returns true if any breakpoint | |
9850 | was created; false otherwise. */ | |
0101ce28 | 9851 | |
8cdf0e15 VP |
9852 | int |
9853 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9854 | char *arg, char *cond_string, |
9855 | int thread, char *extra_string, | |
f6de8ec2 | 9856 | int parse_arg, |
0fb4aa4b | 9857 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9858 | int ignore_count, |
9859 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9860 | const struct breakpoint_ops *ops, |
44f238bb PA |
9861 | int from_tty, int enabled, int internal, |
9862 | unsigned flags) | |
c3f6f71d | 9863 | { |
b78a6381 | 9864 | volatile struct gdb_exception e; |
f8eba3c6 | 9865 | char *copy_arg = NULL; |
c3f6f71d | 9866 | char *addr_start = arg; |
7efd8fc2 | 9867 | struct linespec_result canonical; |
c3f6f71d | 9868 | struct cleanup *old_chain; |
80c99de1 | 9869 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9870 | int pending = 0; |
4a306c9a | 9871 | int task = 0; |
86b17b60 | 9872 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9873 | |
348d480f PA |
9874 | gdb_assert (ops != NULL); |
9875 | ||
7efd8fc2 | 9876 | init_linespec_result (&canonical); |
c3f6f71d | 9877 | |
b78a6381 TT |
9878 | TRY_CATCH (e, RETURN_MASK_ALL) |
9879 | { | |
983af33b SDJ |
9880 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9881 | addr_start, ©_arg); | |
b78a6381 | 9882 | } |
0101ce28 JJ |
9883 | |
9884 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9885 | switch (e.reason) |
0101ce28 | 9886 | { |
983af33b SDJ |
9887 | case GDB_NO_ERROR: |
9888 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9889 | return 0; | |
9890 | break; | |
05ff989b AC |
9891 | case RETURN_ERROR: |
9892 | switch (e.error) | |
0101ce28 | 9893 | { |
05ff989b | 9894 | case NOT_FOUND_ERROR: |
0101ce28 | 9895 | |
05ff989b AC |
9896 | /* If pending breakpoint support is turned off, throw |
9897 | error. */ | |
fa8d40ab JJ |
9898 | |
9899 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9900 | throw_exception (e); |
9901 | ||
9902 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9903 | |
05ff989b AC |
9904 | /* If pending breakpoint support is auto query and the user |
9905 | selects no, then simply return the error code. */ | |
059fb39f | 9906 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9907 | && !nquery (_("Make %s pending on future shared library load? "), |
9908 | bptype_string (type_wanted))) | |
fd9b8c24 | 9909 | return 0; |
fa8d40ab | 9910 | |
05ff989b AC |
9911 | /* At this point, either the user was queried about setting |
9912 | a pending breakpoint and selected yes, or pending | |
9913 | breakpoint behavior is on and thus a pending breakpoint | |
9914 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9915 | { |
9916 | struct linespec_sals lsal; | |
9917 | ||
9918 | copy_arg = xstrdup (addr_start); | |
9919 | lsal.canonical = xstrdup (copy_arg); | |
9920 | lsal.sals.nelts = 1; | |
9921 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9922 | init_sal (&lsal.sals.sals[0]); | |
9923 | pending = 1; | |
9924 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9925 | } | |
05ff989b AC |
9926 | break; |
9927 | default: | |
98deb0da | 9928 | throw_exception (e); |
0101ce28 | 9929 | } |
2abae994 | 9930 | break; |
05ff989b | 9931 | default: |
983af33b | 9932 | throw_exception (e); |
0101ce28 | 9933 | } |
c3f6f71d | 9934 | |
4a64f543 | 9935 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9936 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9937 | |
c3f6f71d JM |
9938 | /* ----------------------------- SNIP ----------------------------- |
9939 | Anything added to the cleanup chain beyond this point is assumed | |
9940 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9941 | then the memory is not reclaimed. */ |
9942 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9943 | |
c3f6f71d JM |
9944 | /* Resolve all line numbers to PC's and verify that the addresses |
9945 | are ok for the target. */ | |
0101ce28 | 9946 | if (!pending) |
f8eba3c6 TT |
9947 | { |
9948 | int ix; | |
9949 | struct linespec_sals *iter; | |
9950 | ||
9951 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9952 | breakpoint_sals_to_pc (&iter->sals); | |
9953 | } | |
c3f6f71d | 9954 | |
7a697b8d | 9955 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9956 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9957 | { |
9958 | int ix; | |
9959 | struct linespec_sals *iter; | |
9960 | ||
9961 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9962 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9963 | } | |
7a697b8d | 9964 | |
c3f6f71d JM |
9965 | /* Verify that condition can be parsed, before setting any |
9966 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9967 | breakpoint. */ |
0101ce28 | 9968 | if (!pending) |
c3f6f71d | 9969 | { |
f6de8ec2 | 9970 | if (parse_arg) |
72b2ff0e | 9971 | { |
0878d0fa | 9972 | char *rest; |
52d361e1 YQ |
9973 | struct linespec_sals *lsal; |
9974 | ||
9975 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9976 | ||
0878d0fa YQ |
9977 | /* Here we only parse 'arg' to separate condition |
9978 | from thread number, so parsing in context of first | |
9979 | sal is OK. When setting the breakpoint we'll | |
9980 | re-parse it in context of each sal. */ | |
9981 | ||
9982 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9983 | &thread, &task, &rest); | |
9984 | if (cond_string) | |
9985 | make_cleanup (xfree, cond_string); | |
9986 | if (rest) | |
9987 | make_cleanup (xfree, rest); | |
9988 | if (rest) | |
9989 | extra_string = rest; | |
72b2ff0e | 9990 | } |
2f069f6f | 9991 | else |
72b2ff0e | 9992 | { |
0878d0fa YQ |
9993 | if (*arg != '\0') |
9994 | error (_("Garbage '%s' at end of location"), arg); | |
9995 | ||
9996 | /* Create a private copy of condition string. */ | |
9997 | if (cond_string) | |
9998 | { | |
9999 | cond_string = xstrdup (cond_string); | |
10000 | make_cleanup (xfree, cond_string); | |
10001 | } | |
10002 | /* Create a private copy of any extra string. */ | |
10003 | if (extra_string) | |
10004 | { | |
10005 | extra_string = xstrdup (extra_string); | |
10006 | make_cleanup (xfree, extra_string); | |
10007 | } | |
72b2ff0e | 10008 | } |
0fb4aa4b | 10009 | |
52d361e1 | 10010 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 10011 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
10012 | tempflag ? disp_del : disp_donttouch, |
10013 | thread, task, ignore_count, ops, | |
44f238bb | 10014 | from_tty, enabled, internal, flags); |
c906108c | 10015 | } |
0101ce28 JJ |
10016 | else |
10017 | { | |
0101ce28 JJ |
10018 | struct breakpoint *b; |
10019 | ||
0101ce28 JJ |
10020 | make_cleanup (xfree, copy_arg); |
10021 | ||
bfccc43c YQ |
10022 | if (is_tracepoint_type (type_wanted)) |
10023 | { | |
10024 | struct tracepoint *t; | |
10025 | ||
10026 | t = XCNEW (struct tracepoint); | |
10027 | b = &t->base; | |
10028 | } | |
10029 | else | |
10030 | b = XNEW (struct breakpoint); | |
10031 | ||
10032 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
10033 | ||
f8eba3c6 | 10034 | b->addr_string = copy_arg; |
f6de8ec2 | 10035 | if (parse_arg) |
e12c7713 MK |
10036 | b->cond_string = NULL; |
10037 | else | |
10038 | { | |
10039 | /* Create a private copy of condition string. */ | |
10040 | if (cond_string) | |
10041 | { | |
10042 | cond_string = xstrdup (cond_string); | |
10043 | make_cleanup (xfree, cond_string); | |
10044 | } | |
10045 | b->cond_string = cond_string; | |
10046 | } | |
e7e0cddf | 10047 | b->extra_string = NULL; |
0101ce28 | 10048 | b->ignore_count = ignore_count; |
0101ce28 | 10049 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 10050 | b->condition_not_parsed = 1; |
41447f92 | 10051 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
10052 | if ((type_wanted != bp_breakpoint |
10053 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 10054 | b->pspace = current_program_space; |
8bea4e01 | 10055 | |
bfccc43c | 10056 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
10057 | } |
10058 | ||
f8eba3c6 | 10059 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 10060 | { |
3e43a32a MS |
10061 | warning (_("Multiple breakpoints were set.\nUse the " |
10062 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 10063 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
10064 | } |
10065 | ||
80c99de1 PA |
10066 | /* That's it. Discard the cleanups for data inserted into the |
10067 | breakpoint. */ | |
10068 | discard_cleanups (bkpt_chain); | |
10069 | /* But cleanup everything else. */ | |
c3f6f71d | 10070 | do_cleanups (old_chain); |
217dc9e2 | 10071 | |
80c99de1 | 10072 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 10073 | update_global_location_list (1); |
fd9b8c24 PA |
10074 | |
10075 | return 1; | |
c3f6f71d | 10076 | } |
c906108c | 10077 | |
348d480f | 10078 | /* Set a breakpoint. |
72b2ff0e VP |
10079 | ARG is a string describing breakpoint address, |
10080 | condition, and thread. | |
10081 | FLAG specifies if a breakpoint is hardware on, | |
10082 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10083 | and BP_TEMPFLAG. */ | |
348d480f | 10084 | |
98deb0da | 10085 | static void |
72b2ff0e | 10086 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10087 | { |
72b2ff0e | 10088 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10089 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10090 | ? bp_hardware_breakpoint | |
10091 | : bp_breakpoint); | |
55aa24fb SDJ |
10092 | struct breakpoint_ops *ops; |
10093 | const char *arg_cp = arg; | |
10094 | ||
10095 | /* Matching breakpoints on probes. */ | |
10096 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
10097 | ops = &bkpt_probe_breakpoint_ops; | |
10098 | else | |
10099 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10100 | |
8cdf0e15 VP |
10101 | create_breakpoint (get_current_arch (), |
10102 | arg, | |
e7e0cddf | 10103 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 10104 | tempflag, type_wanted, |
8cdf0e15 VP |
10105 | 0 /* Ignore count */, |
10106 | pending_break_support, | |
55aa24fb | 10107 | ops, |
8cdf0e15 | 10108 | from_tty, |
84f4c1fe | 10109 | 1 /* enabled */, |
44f238bb PA |
10110 | 0 /* internal */, |
10111 | 0); | |
c906108c SS |
10112 | } |
10113 | ||
c906108c SS |
10114 | /* Helper function for break_command_1 and disassemble_command. */ |
10115 | ||
10116 | void | |
fba45db2 | 10117 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10118 | { |
10119 | CORE_ADDR pc; | |
10120 | ||
10121 | if (sal->pc == 0 && sal->symtab != NULL) | |
10122 | { | |
10123 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10124 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10125 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10126 | sal->pc = pc; |
6a048695 | 10127 | |
4a64f543 MS |
10128 | /* If this SAL corresponds to a breakpoint inserted using a line |
10129 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10130 | if (sal->explicit_line) |
059acae7 | 10131 | skip_prologue_sal (sal); |
c906108c SS |
10132 | } |
10133 | ||
10134 | if (sal->section == 0 && sal->symtab != NULL) | |
10135 | { | |
346d1dfe | 10136 | const struct blockvector *bv; |
3977b71f | 10137 | const struct block *b; |
c5aa993b | 10138 | struct symbol *sym; |
c906108c | 10139 | |
801e3a5b | 10140 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
10141 | if (bv != NULL) |
10142 | { | |
7f0df278 | 10143 | sym = block_linkage_function (b); |
c906108c SS |
10144 | if (sym != NULL) |
10145 | { | |
10146 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 10147 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
10148 | } |
10149 | else | |
10150 | { | |
4a64f543 MS |
10151 | /* It really is worthwhile to have the section, so we'll |
10152 | just have to look harder. This case can be executed | |
10153 | if we have line numbers but no functions (as can | |
10154 | happen in assembly source). */ | |
c906108c | 10155 | |
7cbd4a93 | 10156 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10157 | struct cleanup *old_chain = save_current_space_and_thread (); |
10158 | ||
10159 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10160 | |
10161 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10162 | if (msym.minsym) |
efd66ac6 | 10163 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10164 | |
10165 | do_cleanups (old_chain); | |
c906108c SS |
10166 | } |
10167 | } | |
10168 | } | |
10169 | } | |
10170 | ||
10171 | void | |
fba45db2 | 10172 | break_command (char *arg, int from_tty) |
c906108c | 10173 | { |
db107f19 | 10174 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10175 | } |
10176 | ||
c906108c | 10177 | void |
fba45db2 | 10178 | tbreak_command (char *arg, int from_tty) |
c906108c | 10179 | { |
db107f19 | 10180 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10181 | } |
10182 | ||
c906108c | 10183 | static void |
fba45db2 | 10184 | hbreak_command (char *arg, int from_tty) |
c906108c | 10185 | { |
db107f19 | 10186 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10187 | } |
10188 | ||
10189 | static void | |
fba45db2 | 10190 | thbreak_command (char *arg, int from_tty) |
c906108c | 10191 | { |
db107f19 | 10192 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10193 | } |
10194 | ||
10195 | static void | |
fba45db2 | 10196 | stop_command (char *arg, int from_tty) |
c906108c | 10197 | { |
a3f17187 | 10198 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10199 | Usage: stop in <function | address>\n\ |
a3f17187 | 10200 | stop at <line>\n")); |
c906108c SS |
10201 | } |
10202 | ||
10203 | static void | |
fba45db2 | 10204 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10205 | { |
10206 | int badInput = 0; | |
10207 | ||
c5aa993b | 10208 | if (arg == (char *) NULL) |
c906108c SS |
10209 | badInput = 1; |
10210 | else if (*arg != '*') | |
10211 | { | |
10212 | char *argptr = arg; | |
10213 | int hasColon = 0; | |
10214 | ||
4a64f543 | 10215 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10216 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10217 | function/method name. */ |
c906108c | 10218 | while (*argptr && !hasColon) |
c5aa993b JM |
10219 | { |
10220 | hasColon = (*argptr == ':'); | |
10221 | argptr++; | |
10222 | } | |
c906108c SS |
10223 | |
10224 | if (hasColon) | |
c5aa993b | 10225 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10226 | else |
c5aa993b | 10227 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10228 | } |
10229 | ||
10230 | if (badInput) | |
a3f17187 | 10231 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10232 | else |
db107f19 | 10233 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10234 | } |
10235 | ||
10236 | static void | |
fba45db2 | 10237 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10238 | { |
10239 | int badInput = 0; | |
10240 | ||
c5aa993b | 10241 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10242 | badInput = 1; |
10243 | else | |
10244 | { | |
10245 | char *argptr = arg; | |
10246 | int hasColon = 0; | |
10247 | ||
4a64f543 MS |
10248 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10249 | it is probably a line number. */ | |
c906108c | 10250 | while (*argptr && !hasColon) |
c5aa993b JM |
10251 | { |
10252 | hasColon = (*argptr == ':'); | |
10253 | argptr++; | |
10254 | } | |
c906108c SS |
10255 | |
10256 | if (hasColon) | |
c5aa993b | 10257 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10258 | else |
c5aa993b | 10259 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10260 | } |
10261 | ||
10262 | if (badInput) | |
a3f17187 | 10263 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10264 | else |
db107f19 | 10265 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10266 | } |
10267 | ||
e7e0cddf SS |
10268 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10269 | with a prewired command list consisting of a single output command, | |
10270 | built from extra arguments supplied on the dprintf command | |
10271 | line. */ | |
10272 | ||
da821c7b | 10273 | static void |
e7e0cddf SS |
10274 | dprintf_command (char *arg, int from_tty) |
10275 | { | |
10276 | create_breakpoint (get_current_arch (), | |
10277 | arg, | |
10278 | NULL, 0, NULL, 1 /* parse arg */, | |
10279 | 0, bp_dprintf, | |
10280 | 0 /* Ignore count */, | |
10281 | pending_break_support, | |
10282 | &dprintf_breakpoint_ops, | |
10283 | from_tty, | |
10284 | 1 /* enabled */, | |
10285 | 0 /* internal */, | |
10286 | 0); | |
10287 | } | |
10288 | ||
d3ce09f5 SS |
10289 | static void |
10290 | agent_printf_command (char *arg, int from_tty) | |
10291 | { | |
10292 | error (_("May only run agent-printf on the target")); | |
10293 | } | |
10294 | ||
f1310107 TJB |
10295 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10296 | ranged breakpoints. */ | |
10297 | ||
10298 | static int | |
10299 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10300 | struct address_space *aspace, | |
09ac7c10 TT |
10301 | CORE_ADDR bp_addr, |
10302 | const struct target_waitstatus *ws) | |
f1310107 | 10303 | { |
09ac7c10 | 10304 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10305 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10306 | return 0; |
10307 | ||
f1310107 TJB |
10308 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10309 | bl->length, aspace, bp_addr); | |
10310 | } | |
10311 | ||
10312 | /* Implement the "resources_needed" breakpoint_ops method for | |
10313 | ranged breakpoints. */ | |
10314 | ||
10315 | static int | |
10316 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10317 | { | |
10318 | return target_ranged_break_num_registers (); | |
10319 | } | |
10320 | ||
10321 | /* Implement the "print_it" breakpoint_ops method for | |
10322 | ranged breakpoints. */ | |
10323 | ||
10324 | static enum print_stop_action | |
348d480f | 10325 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10326 | { |
348d480f | 10327 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10328 | struct bp_location *bl = b->loc; |
79a45e25 | 10329 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10330 | |
10331 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10332 | ||
10333 | /* Ranged breakpoints have only one location. */ | |
10334 | gdb_assert (bl && bl->next == NULL); | |
10335 | ||
10336 | annotate_breakpoint (b->number); | |
10337 | if (b->disposition == disp_del) | |
10338 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10339 | else | |
10340 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10341 | if (ui_out_is_mi_like_p (uiout)) | |
10342 | { | |
10343 | ui_out_field_string (uiout, "reason", | |
10344 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10345 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10346 | } | |
10347 | ui_out_field_int (uiout, "bkptno", b->number); | |
10348 | ui_out_text (uiout, ", "); | |
10349 | ||
10350 | return PRINT_SRC_AND_LOC; | |
10351 | } | |
10352 | ||
10353 | /* Implement the "print_one" breakpoint_ops method for | |
10354 | ranged breakpoints. */ | |
10355 | ||
10356 | static void | |
10357 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10358 | struct bp_location **last_loc) | |
10359 | { | |
10360 | struct bp_location *bl = b->loc; | |
10361 | struct value_print_options opts; | |
79a45e25 | 10362 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10363 | |
10364 | /* Ranged breakpoints have only one location. */ | |
10365 | gdb_assert (bl && bl->next == NULL); | |
10366 | ||
10367 | get_user_print_options (&opts); | |
10368 | ||
10369 | if (opts.addressprint) | |
10370 | /* We don't print the address range here, it will be printed later | |
10371 | by print_one_detail_ranged_breakpoint. */ | |
10372 | ui_out_field_skip (uiout, "addr"); | |
10373 | annotate_field (5); | |
10374 | print_breakpoint_location (b, bl); | |
10375 | *last_loc = bl; | |
10376 | } | |
10377 | ||
10378 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10379 | ranged breakpoints. */ | |
10380 | ||
10381 | static void | |
10382 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10383 | struct ui_out *uiout) | |
10384 | { | |
10385 | CORE_ADDR address_start, address_end; | |
10386 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10387 | struct ui_file *stb = mem_fileopen (); |
10388 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10389 | |
10390 | gdb_assert (bl); | |
10391 | ||
10392 | address_start = bl->address; | |
10393 | address_end = address_start + bl->length - 1; | |
10394 | ||
10395 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10396 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10397 | print_core_address (bl->gdbarch, address_start), |
10398 | print_core_address (bl->gdbarch, address_end)); | |
10399 | ui_out_field_stream (uiout, "addr", stb); | |
10400 | ui_out_text (uiout, "\n"); | |
10401 | ||
10402 | do_cleanups (cleanup); | |
10403 | } | |
10404 | ||
10405 | /* Implement the "print_mention" breakpoint_ops method for | |
10406 | ranged breakpoints. */ | |
10407 | ||
10408 | static void | |
10409 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10410 | { | |
10411 | struct bp_location *bl = b->loc; | |
79a45e25 | 10412 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10413 | |
10414 | gdb_assert (bl); | |
10415 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10416 | ||
10417 | if (ui_out_is_mi_like_p (uiout)) | |
10418 | return; | |
10419 | ||
10420 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10421 | b->number, paddress (bl->gdbarch, bl->address), | |
10422 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10423 | } | |
10424 | ||
10425 | /* Implement the "print_recreate" breakpoint_ops method for | |
10426 | ranged breakpoints. */ | |
10427 | ||
10428 | static void | |
10429 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10430 | { | |
10431 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10432 | b->addr_string_range_end); | |
d9b3f62e | 10433 | print_recreate_thread (b, fp); |
f1310107 TJB |
10434 | } |
10435 | ||
10436 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10437 | ||
2060206e | 10438 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10439 | |
10440 | /* Find the address where the end of the breakpoint range should be | |
10441 | placed, given the SAL of the end of the range. This is so that if | |
10442 | the user provides a line number, the end of the range is set to the | |
10443 | last instruction of the given line. */ | |
10444 | ||
10445 | static CORE_ADDR | |
10446 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10447 | { | |
10448 | CORE_ADDR end; | |
10449 | ||
10450 | /* If the user provided a PC value, use it. Otherwise, | |
10451 | find the address of the end of the given location. */ | |
10452 | if (sal.explicit_pc) | |
10453 | end = sal.pc; | |
10454 | else | |
10455 | { | |
10456 | int ret; | |
10457 | CORE_ADDR start; | |
10458 | ||
10459 | ret = find_line_pc_range (sal, &start, &end); | |
10460 | if (!ret) | |
10461 | error (_("Could not find location of the end of the range.")); | |
10462 | ||
10463 | /* find_line_pc_range returns the start of the next line. */ | |
10464 | end--; | |
10465 | } | |
10466 | ||
10467 | return end; | |
10468 | } | |
10469 | ||
10470 | /* Implement the "break-range" CLI command. */ | |
10471 | ||
10472 | static void | |
10473 | break_range_command (char *arg, int from_tty) | |
10474 | { | |
10475 | char *arg_start, *addr_string_start, *addr_string_end; | |
10476 | struct linespec_result canonical_start, canonical_end; | |
10477 | int bp_count, can_use_bp, length; | |
10478 | CORE_ADDR end; | |
10479 | struct breakpoint *b; | |
10480 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10481 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10482 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10483 | |
10484 | /* We don't support software ranged breakpoints. */ | |
10485 | if (target_ranged_break_num_registers () < 0) | |
10486 | error (_("This target does not support hardware ranged breakpoints.")); | |
10487 | ||
10488 | bp_count = hw_breakpoint_used_count (); | |
10489 | bp_count += target_ranged_break_num_registers (); | |
10490 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10491 | bp_count, 0); | |
10492 | if (can_use_bp < 0) | |
10493 | error (_("Hardware breakpoints used exceeds limit.")); | |
10494 | ||
f8eba3c6 | 10495 | arg = skip_spaces (arg); |
f1310107 TJB |
10496 | if (arg == NULL || arg[0] == '\0') |
10497 | error(_("No address range specified.")); | |
10498 | ||
f1310107 TJB |
10499 | init_linespec_result (&canonical_start); |
10500 | ||
f8eba3c6 TT |
10501 | arg_start = arg; |
10502 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10503 | |
f8eba3c6 | 10504 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10505 | |
10506 | if (arg[0] != ',') | |
10507 | error (_("Too few arguments.")); | |
f8eba3c6 | 10508 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10509 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10510 | |
10511 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10512 | ||
10513 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10514 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10515 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10516 | ||
f8eba3c6 TT |
10517 | sal_start = lsal_start->sals.sals[0]; |
10518 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10519 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10520 | |
10521 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10522 | arg = skip_spaces (arg); |
f1310107 TJB |
10523 | |
10524 | /* Parse the end location. */ | |
10525 | ||
f1310107 TJB |
10526 | init_linespec_result (&canonical_end); |
10527 | arg_start = arg; | |
10528 | ||
f8eba3c6 | 10529 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10530 | parse_breakpoint_sals because we need to specify the start location's |
10531 | symtab and line as the default symtab and line for the end of the | |
10532 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10533 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10534 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10535 | sal_start.symtab, sal_start.line, | |
10536 | &canonical_end, NULL, NULL); | |
10537 | ||
10538 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10539 | |
f8eba3c6 | 10540 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10541 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10542 | |
10543 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10544 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10545 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10546 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10547 | ||
f8eba3c6 TT |
10548 | sal_end = lsal_end->sals.sals[0]; |
10549 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10550 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10551 | |
10552 | end = find_breakpoint_range_end (sal_end); | |
10553 | if (sal_start.pc > end) | |
177b42fe | 10554 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10555 | |
10556 | length = end - sal_start.pc + 1; | |
10557 | if (length < 0) | |
10558 | /* Length overflowed. */ | |
10559 | error (_("Address range too large.")); | |
10560 | else if (length == 1) | |
10561 | { | |
10562 | /* This range is simple enough to be handled by | |
10563 | the `hbreak' command. */ | |
10564 | hbreak_command (addr_string_start, 1); | |
10565 | ||
10566 | do_cleanups (cleanup_bkpt); | |
10567 | ||
10568 | return; | |
10569 | } | |
10570 | ||
10571 | /* Now set up the breakpoint. */ | |
10572 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10573 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10574 | set_breakpoint_count (breakpoint_count + 1); |
10575 | b->number = breakpoint_count; | |
10576 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10577 | b->addr_string = xstrdup (addr_string_start); |
10578 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10579 | b->loc->length = length; |
10580 | ||
f8eba3c6 | 10581 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10582 | |
10583 | mention (b); | |
8d3788bd | 10584 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10585 | update_global_location_list (1); |
10586 | } | |
10587 | ||
4a64f543 MS |
10588 | /* Return non-zero if EXP is verified as constant. Returned zero |
10589 | means EXP is variable. Also the constant detection may fail for | |
10590 | some constant expressions and in such case still falsely return | |
10591 | zero. */ | |
2e6e3d9c | 10592 | |
65d79d4b SDJ |
10593 | static int |
10594 | watchpoint_exp_is_const (const struct expression *exp) | |
10595 | { | |
10596 | int i = exp->nelts; | |
10597 | ||
10598 | while (i > 0) | |
10599 | { | |
10600 | int oplenp, argsp; | |
10601 | ||
10602 | /* We are only interested in the descriptor of each element. */ | |
10603 | operator_length (exp, i, &oplenp, &argsp); | |
10604 | i -= oplenp; | |
10605 | ||
10606 | switch (exp->elts[i].opcode) | |
10607 | { | |
10608 | case BINOP_ADD: | |
10609 | case BINOP_SUB: | |
10610 | case BINOP_MUL: | |
10611 | case BINOP_DIV: | |
10612 | case BINOP_REM: | |
10613 | case BINOP_MOD: | |
10614 | case BINOP_LSH: | |
10615 | case BINOP_RSH: | |
10616 | case BINOP_LOGICAL_AND: | |
10617 | case BINOP_LOGICAL_OR: | |
10618 | case BINOP_BITWISE_AND: | |
10619 | case BINOP_BITWISE_IOR: | |
10620 | case BINOP_BITWISE_XOR: | |
10621 | case BINOP_EQUAL: | |
10622 | case BINOP_NOTEQUAL: | |
10623 | case BINOP_LESS: | |
10624 | case BINOP_GTR: | |
10625 | case BINOP_LEQ: | |
10626 | case BINOP_GEQ: | |
10627 | case BINOP_REPEAT: | |
10628 | case BINOP_COMMA: | |
10629 | case BINOP_EXP: | |
10630 | case BINOP_MIN: | |
10631 | case BINOP_MAX: | |
10632 | case BINOP_INTDIV: | |
10633 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10634 | case TERNOP_COND: |
10635 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10636 | |
10637 | case OP_LONG: | |
10638 | case OP_DOUBLE: | |
10639 | case OP_DECFLOAT: | |
10640 | case OP_LAST: | |
10641 | case OP_COMPLEX: | |
10642 | case OP_STRING: | |
65d79d4b SDJ |
10643 | case OP_ARRAY: |
10644 | case OP_TYPE: | |
608b4967 TT |
10645 | case OP_TYPEOF: |
10646 | case OP_DECLTYPE: | |
6e72ca20 | 10647 | case OP_TYPEID: |
65d79d4b SDJ |
10648 | case OP_NAME: |
10649 | case OP_OBJC_NSSTRING: | |
10650 | ||
10651 | case UNOP_NEG: | |
10652 | case UNOP_LOGICAL_NOT: | |
10653 | case UNOP_COMPLEMENT: | |
10654 | case UNOP_ADDR: | |
10655 | case UNOP_HIGH: | |
aeaa2474 | 10656 | case UNOP_CAST: |
9eaf6705 TT |
10657 | |
10658 | case UNOP_CAST_TYPE: | |
10659 | case UNOP_REINTERPRET_CAST: | |
10660 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10661 | /* Unary, binary and ternary operators: We have to check |
10662 | their operands. If they are constant, then so is the | |
10663 | result of that operation. For instance, if A and B are | |
10664 | determined to be constants, then so is "A + B". | |
10665 | ||
10666 | UNOP_IND is one exception to the rule above, because the | |
10667 | value of *ADDR is not necessarily a constant, even when | |
10668 | ADDR is. */ | |
65d79d4b SDJ |
10669 | break; |
10670 | ||
10671 | case OP_VAR_VALUE: | |
10672 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10673 | |
65d79d4b | 10674 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10675 | possible that a buggy compiler could mark a variable as |
10676 | constant even when it is not, and TYPE_CONST would return | |
10677 | true in this case, while SYMBOL_CLASS wouldn't. | |
10678 | ||
10679 | We also have to check for function symbols because they | |
10680 | are always constant. */ | |
65d79d4b SDJ |
10681 | { |
10682 | struct symbol *s = exp->elts[i + 2].symbol; | |
10683 | ||
10684 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10685 | && SYMBOL_CLASS (s) != LOC_CONST | |
10686 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10687 | return 0; | |
10688 | break; | |
10689 | } | |
10690 | ||
10691 | /* The default action is to return 0 because we are using | |
10692 | the optimistic approach here: If we don't know something, | |
10693 | then it is not a constant. */ | |
10694 | default: | |
10695 | return 0; | |
10696 | } | |
10697 | } | |
10698 | ||
10699 | return 1; | |
10700 | } | |
10701 | ||
3a5c3e22 PA |
10702 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10703 | ||
10704 | static void | |
10705 | dtor_watchpoint (struct breakpoint *self) | |
10706 | { | |
10707 | struct watchpoint *w = (struct watchpoint *) self; | |
10708 | ||
10709 | xfree (w->cond_exp); | |
10710 | xfree (w->exp); | |
10711 | xfree (w->exp_string); | |
10712 | xfree (w->exp_string_reparse); | |
10713 | value_free (w->val); | |
10714 | ||
10715 | base_breakpoint_ops.dtor (self); | |
10716 | } | |
10717 | ||
348d480f PA |
10718 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10719 | ||
10720 | static void | |
10721 | re_set_watchpoint (struct breakpoint *b) | |
10722 | { | |
3a5c3e22 PA |
10723 | struct watchpoint *w = (struct watchpoint *) b; |
10724 | ||
348d480f PA |
10725 | /* Watchpoint can be either on expression using entirely global |
10726 | variables, or it can be on local variables. | |
10727 | ||
10728 | Watchpoints of the first kind are never auto-deleted, and even | |
10729 | persist across program restarts. Since they can use variables | |
10730 | from shared libraries, we need to reparse expression as libraries | |
10731 | are loaded and unloaded. | |
10732 | ||
10733 | Watchpoints on local variables can also change meaning as result | |
10734 | of solib event. For example, if a watchpoint uses both a local | |
10735 | and a global variables in expression, it's a local watchpoint, | |
10736 | but unloading of a shared library will make the expression | |
10737 | invalid. This is not a very common use case, but we still | |
10738 | re-evaluate expression, to avoid surprises to the user. | |
10739 | ||
10740 | Note that for local watchpoints, we re-evaluate it only if | |
10741 | watchpoints frame id is still valid. If it's not, it means the | |
10742 | watchpoint is out of scope and will be deleted soon. In fact, | |
10743 | I'm not sure we'll ever be called in this case. | |
10744 | ||
10745 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10746 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10747 | |
3a5c3e22 PA |
10748 | Don't do anything about disabled watchpoints, since they will be |
10749 | reevaluated again when enabled. */ | |
10750 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10751 | } |
10752 | ||
77b06cd7 TJB |
10753 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10754 | ||
10755 | static int | |
10756 | insert_watchpoint (struct bp_location *bl) | |
10757 | { | |
3a5c3e22 PA |
10758 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10759 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10760 | |
10761 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10762 | w->cond_exp); |
77b06cd7 TJB |
10763 | } |
10764 | ||
10765 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10766 | ||
10767 | static int | |
10768 | remove_watchpoint (struct bp_location *bl) | |
10769 | { | |
3a5c3e22 PA |
10770 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10771 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10772 | |
10773 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10774 | w->cond_exp); |
e09342b5 TJB |
10775 | } |
10776 | ||
e09342b5 | 10777 | static int |
348d480f | 10778 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10779 | struct address_space *aspace, CORE_ADDR bp_addr, |
10780 | const struct target_waitstatus *ws) | |
e09342b5 | 10781 | { |
348d480f | 10782 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10783 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10784 | |
348d480f PA |
10785 | /* Continuable hardware watchpoints are treated as non-existent if the |
10786 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10787 | some data address). Otherwise gdb won't stop on a break instruction | |
10788 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10789 | been defined. Also skip watchpoints which we know did not trigger | |
10790 | (did not match the data address). */ | |
10791 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10792 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10793 | return 0; |
9c06b0b4 | 10794 | |
348d480f | 10795 | return 1; |
9c06b0b4 TJB |
10796 | } |
10797 | ||
348d480f PA |
10798 | static void |
10799 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10800 | { |
348d480f | 10801 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10802 | |
348d480f | 10803 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10804 | } |
10805 | ||
10806 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10807 | hardware watchpoints. */ |
9c06b0b4 TJB |
10808 | |
10809 | static int | |
348d480f | 10810 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10811 | { |
3a5c3e22 PA |
10812 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10813 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10814 | |
10815 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10816 | } |
10817 | ||
10818 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10819 | hardware watchpoints. */ |
9c06b0b4 TJB |
10820 | |
10821 | static int | |
348d480f | 10822 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10823 | { |
efa80663 PA |
10824 | /* Read and access watchpoints only work with hardware support. */ |
10825 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10826 | } |
10827 | ||
9c06b0b4 | 10828 | static enum print_stop_action |
348d480f | 10829 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10830 | { |
348d480f PA |
10831 | struct cleanup *old_chain; |
10832 | struct breakpoint *b; | |
f99d8bf4 | 10833 | struct ui_file *stb; |
348d480f | 10834 | enum print_stop_action result; |
3a5c3e22 | 10835 | struct watchpoint *w; |
79a45e25 | 10836 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10837 | |
10838 | gdb_assert (bs->bp_location_at != NULL); | |
10839 | ||
348d480f | 10840 | b = bs->breakpoint_at; |
3a5c3e22 | 10841 | w = (struct watchpoint *) b; |
348d480f | 10842 | |
f99d8bf4 PA |
10843 | stb = mem_fileopen (); |
10844 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10845 | |
10846 | switch (b->type) | |
10847 | { | |
348d480f | 10848 | case bp_watchpoint: |
9c06b0b4 TJB |
10849 | case bp_hardware_watchpoint: |
10850 | annotate_watchpoint (b->number); | |
10851 | if (ui_out_is_mi_like_p (uiout)) | |
10852 | ui_out_field_string | |
10853 | (uiout, "reason", | |
10854 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10855 | mention (b); |
10856 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10857 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10858 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10859 | ui_out_field_stream (uiout, "old", stb); |
10860 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10861 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10862 | ui_out_field_stream (uiout, "new", stb); |
10863 | ui_out_text (uiout, "\n"); | |
10864 | /* More than one watchpoint may have been triggered. */ | |
10865 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10866 | break; |
10867 | ||
10868 | case bp_read_watchpoint: | |
10869 | if (ui_out_is_mi_like_p (uiout)) | |
10870 | ui_out_field_string | |
10871 | (uiout, "reason", | |
10872 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10873 | mention (b); |
10874 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10875 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10876 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10877 | ui_out_field_stream (uiout, "value", stb); |
10878 | ui_out_text (uiout, "\n"); | |
10879 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10880 | break; |
10881 | ||
10882 | case bp_access_watchpoint: | |
348d480f PA |
10883 | if (bs->old_val != NULL) |
10884 | { | |
10885 | annotate_watchpoint (b->number); | |
10886 | if (ui_out_is_mi_like_p (uiout)) | |
10887 | ui_out_field_string | |
10888 | (uiout, "reason", | |
10889 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10890 | mention (b); | |
10891 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10892 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10893 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10894 | ui_out_field_stream (uiout, "old", stb); |
10895 | ui_out_text (uiout, "\nNew value = "); | |
10896 | } | |
10897 | else | |
10898 | { | |
10899 | mention (b); | |
10900 | if (ui_out_is_mi_like_p (uiout)) | |
10901 | ui_out_field_string | |
10902 | (uiout, "reason", | |
10903 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10904 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10905 | ui_out_text (uiout, "\nValue = "); | |
10906 | } | |
f99d8bf4 | 10907 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10908 | ui_out_field_stream (uiout, "new", stb); |
10909 | ui_out_text (uiout, "\n"); | |
10910 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10911 | break; |
10912 | default: | |
348d480f | 10913 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10914 | } |
10915 | ||
348d480f PA |
10916 | do_cleanups (old_chain); |
10917 | return result; | |
10918 | } | |
10919 | ||
10920 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10921 | watchpoints. */ | |
10922 | ||
10923 | static void | |
10924 | print_mention_watchpoint (struct breakpoint *b) | |
10925 | { | |
10926 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10927 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10928 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10929 | |
10930 | switch (b->type) | |
10931 | { | |
10932 | case bp_watchpoint: | |
10933 | ui_out_text (uiout, "Watchpoint "); | |
10934 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10935 | break; | |
10936 | case bp_hardware_watchpoint: | |
10937 | ui_out_text (uiout, "Hardware watchpoint "); | |
10938 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10939 | break; | |
10940 | case bp_read_watchpoint: | |
10941 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10942 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10943 | break; | |
10944 | case bp_access_watchpoint: | |
10945 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10946 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10947 | break; | |
10948 | default: | |
10949 | internal_error (__FILE__, __LINE__, | |
10950 | _("Invalid hardware watchpoint type.")); | |
10951 | } | |
10952 | ||
10953 | ui_out_field_int (uiout, "number", b->number); | |
10954 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10955 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10956 | do_cleanups (ui_out_chain); |
10957 | } | |
10958 | ||
10959 | /* Implement the "print_recreate" breakpoint_ops method for | |
10960 | watchpoints. */ | |
10961 | ||
10962 | static void | |
10963 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10964 | { | |
3a5c3e22 PA |
10965 | struct watchpoint *w = (struct watchpoint *) b; |
10966 | ||
348d480f PA |
10967 | switch (b->type) |
10968 | { | |
10969 | case bp_watchpoint: | |
10970 | case bp_hardware_watchpoint: | |
10971 | fprintf_unfiltered (fp, "watch"); | |
10972 | break; | |
10973 | case bp_read_watchpoint: | |
10974 | fprintf_unfiltered (fp, "rwatch"); | |
10975 | break; | |
10976 | case bp_access_watchpoint: | |
10977 | fprintf_unfiltered (fp, "awatch"); | |
10978 | break; | |
10979 | default: | |
10980 | internal_error (__FILE__, __LINE__, | |
10981 | _("Invalid watchpoint type.")); | |
10982 | } | |
10983 | ||
3a5c3e22 | 10984 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10985 | print_recreate_thread (b, fp); |
348d480f PA |
10986 | } |
10987 | ||
427cd150 TT |
10988 | /* Implement the "explains_signal" breakpoint_ops method for |
10989 | watchpoints. */ | |
10990 | ||
47591c29 | 10991 | static int |
427cd150 TT |
10992 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10993 | { | |
10994 | /* A software watchpoint cannot cause a signal other than | |
10995 | GDB_SIGNAL_TRAP. */ | |
10996 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10997 | return 0; |
427cd150 | 10998 | |
47591c29 | 10999 | return 1; |
427cd150 TT |
11000 | } |
11001 | ||
348d480f PA |
11002 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
11003 | ||
2060206e | 11004 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
11005 | |
11006 | /* Implement the "insert" breakpoint_ops method for | |
11007 | masked hardware watchpoints. */ | |
11008 | ||
11009 | static int | |
11010 | insert_masked_watchpoint (struct bp_location *bl) | |
11011 | { | |
3a5c3e22 PA |
11012 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11013 | ||
11014 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11015 | bl->watchpoint_type); |
11016 | } | |
11017 | ||
11018 | /* Implement the "remove" breakpoint_ops method for | |
11019 | masked hardware watchpoints. */ | |
11020 | ||
11021 | static int | |
11022 | remove_masked_watchpoint (struct bp_location *bl) | |
11023 | { | |
3a5c3e22 PA |
11024 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11025 | ||
11026 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11027 | bl->watchpoint_type); |
11028 | } | |
11029 | ||
11030 | /* Implement the "resources_needed" breakpoint_ops method for | |
11031 | masked hardware watchpoints. */ | |
11032 | ||
11033 | static int | |
11034 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
11035 | { | |
3a5c3e22 PA |
11036 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11037 | ||
11038 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
11039 | } |
11040 | ||
11041 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11042 | masked hardware watchpoints. */ | |
11043 | ||
11044 | static int | |
11045 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11046 | { | |
11047 | return 0; | |
11048 | } | |
11049 | ||
11050 | /* Implement the "print_it" breakpoint_ops method for | |
11051 | masked hardware watchpoints. */ | |
11052 | ||
11053 | static enum print_stop_action | |
11054 | print_it_masked_watchpoint (bpstat bs) | |
11055 | { | |
11056 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11057 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11058 | |
11059 | /* Masked watchpoints have only one location. */ | |
11060 | gdb_assert (b->loc && b->loc->next == NULL); | |
11061 | ||
11062 | switch (b->type) | |
11063 | { | |
11064 | case bp_hardware_watchpoint: | |
11065 | annotate_watchpoint (b->number); | |
11066 | if (ui_out_is_mi_like_p (uiout)) | |
11067 | ui_out_field_string | |
11068 | (uiout, "reason", | |
11069 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11070 | break; | |
11071 | ||
11072 | case bp_read_watchpoint: | |
11073 | if (ui_out_is_mi_like_p (uiout)) | |
11074 | ui_out_field_string | |
11075 | (uiout, "reason", | |
11076 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11077 | break; | |
11078 | ||
11079 | case bp_access_watchpoint: | |
11080 | if (ui_out_is_mi_like_p (uiout)) | |
11081 | ui_out_field_string | |
11082 | (uiout, "reason", | |
11083 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11084 | break; | |
11085 | default: | |
11086 | internal_error (__FILE__, __LINE__, | |
11087 | _("Invalid hardware watchpoint type.")); | |
11088 | } | |
11089 | ||
11090 | mention (b); | |
9c06b0b4 TJB |
11091 | ui_out_text (uiout, _("\n\ |
11092 | Check the underlying instruction at PC for the memory\n\ | |
11093 | address and value which triggered this watchpoint.\n")); | |
11094 | ui_out_text (uiout, "\n"); | |
11095 | ||
11096 | /* More than one watchpoint may have been triggered. */ | |
11097 | return PRINT_UNKNOWN; | |
11098 | } | |
11099 | ||
11100 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11101 | masked hardware watchpoints. */ | |
11102 | ||
11103 | static void | |
11104 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11105 | struct ui_out *uiout) | |
11106 | { | |
3a5c3e22 PA |
11107 | struct watchpoint *w = (struct watchpoint *) b; |
11108 | ||
9c06b0b4 TJB |
11109 | /* Masked watchpoints have only one location. */ |
11110 | gdb_assert (b->loc && b->loc->next == NULL); | |
11111 | ||
11112 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11113 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11114 | ui_out_text (uiout, "\n"); |
11115 | } | |
11116 | ||
11117 | /* Implement the "print_mention" breakpoint_ops method for | |
11118 | masked hardware watchpoints. */ | |
11119 | ||
11120 | static void | |
11121 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11122 | { | |
3a5c3e22 | 11123 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11124 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11125 | struct cleanup *ui_out_chain; |
11126 | ||
11127 | switch (b->type) | |
11128 | { | |
11129 | case bp_hardware_watchpoint: | |
11130 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11131 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11132 | break; | |
11133 | case bp_read_watchpoint: | |
11134 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11135 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11136 | break; | |
11137 | case bp_access_watchpoint: | |
11138 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11139 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11140 | break; | |
11141 | default: | |
11142 | internal_error (__FILE__, __LINE__, | |
11143 | _("Invalid hardware watchpoint type.")); | |
11144 | } | |
11145 | ||
11146 | ui_out_field_int (uiout, "number", b->number); | |
11147 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11148 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11149 | do_cleanups (ui_out_chain); |
11150 | } | |
11151 | ||
11152 | /* Implement the "print_recreate" breakpoint_ops method for | |
11153 | masked hardware watchpoints. */ | |
11154 | ||
11155 | static void | |
11156 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11157 | { | |
3a5c3e22 | 11158 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11159 | char tmp[40]; |
11160 | ||
11161 | switch (b->type) | |
11162 | { | |
11163 | case bp_hardware_watchpoint: | |
11164 | fprintf_unfiltered (fp, "watch"); | |
11165 | break; | |
11166 | case bp_read_watchpoint: | |
11167 | fprintf_unfiltered (fp, "rwatch"); | |
11168 | break; | |
11169 | case bp_access_watchpoint: | |
11170 | fprintf_unfiltered (fp, "awatch"); | |
11171 | break; | |
11172 | default: | |
11173 | internal_error (__FILE__, __LINE__, | |
11174 | _("Invalid hardware watchpoint type.")); | |
11175 | } | |
11176 | ||
3a5c3e22 PA |
11177 | sprintf_vma (tmp, w->hw_wp_mask); |
11178 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11179 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11180 | } |
11181 | ||
11182 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11183 | ||
2060206e | 11184 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11185 | |
11186 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11187 | ||
11188 | static int | |
11189 | is_masked_watchpoint (const struct breakpoint *b) | |
11190 | { | |
11191 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11192 | } | |
11193 | ||
53a5351d JM |
11194 | /* accessflag: hw_write: watch write, |
11195 | hw_read: watch read, | |
11196 | hw_access: watch access (read or write) */ | |
c906108c | 11197 | static void |
bbc13ae3 | 11198 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11199 | int just_location, int internal) |
c906108c | 11200 | { |
a9634178 | 11201 | volatile struct gdb_exception e; |
d983da9c | 11202 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11203 | struct expression *exp; |
270140bd | 11204 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11205 | struct value *val, *mark, *result; |
c906108c | 11206 | struct frame_info *frame; |
bbc13ae3 KS |
11207 | const char *exp_start = NULL; |
11208 | const char *exp_end = NULL; | |
11209 | const char *tok, *end_tok; | |
9c06b0b4 | 11210 | int toklen = -1; |
bbc13ae3 KS |
11211 | const char *cond_start = NULL; |
11212 | const char *cond_end = NULL; | |
c906108c | 11213 | enum bptype bp_type; |
37e4754d | 11214 | int thread = -1; |
0cf6dd15 | 11215 | int pc = 0; |
9c06b0b4 TJB |
11216 | /* Flag to indicate whether we are going to use masks for |
11217 | the hardware watchpoint. */ | |
11218 | int use_mask = 0; | |
11219 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11220 | struct watchpoint *w; |
bbc13ae3 KS |
11221 | char *expression; |
11222 | struct cleanup *back_to; | |
c906108c | 11223 | |
37e4754d LM |
11224 | /* Make sure that we actually have parameters to parse. */ |
11225 | if (arg != NULL && arg[0] != '\0') | |
11226 | { | |
bbc13ae3 KS |
11227 | const char *value_start; |
11228 | ||
11229 | exp_end = arg + strlen (arg); | |
37e4754d | 11230 | |
9c06b0b4 TJB |
11231 | /* Look for "parameter value" pairs at the end |
11232 | of the arguments string. */ | |
bbc13ae3 | 11233 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11234 | { |
11235 | /* Skip whitespace at the end of the argument list. */ | |
11236 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11237 | tok--; | |
11238 | ||
11239 | /* Find the beginning of the last token. | |
11240 | This is the value of the parameter. */ | |
11241 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11242 | tok--; | |
11243 | value_start = tok + 1; | |
11244 | ||
11245 | /* Skip whitespace. */ | |
11246 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11247 | tok--; | |
11248 | ||
11249 | end_tok = tok; | |
11250 | ||
11251 | /* Find the beginning of the second to last token. | |
11252 | This is the parameter itself. */ | |
11253 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11254 | tok--; | |
11255 | tok++; | |
11256 | toklen = end_tok - tok + 1; | |
11257 | ||
11258 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11259 | { | |
11260 | /* At this point we've found a "thread" token, which means | |
11261 | the user is trying to set a watchpoint that triggers | |
11262 | only in a specific thread. */ | |
11263 | char *endp; | |
37e4754d | 11264 | |
9c06b0b4 TJB |
11265 | if (thread != -1) |
11266 | error(_("You can specify only one thread.")); | |
37e4754d | 11267 | |
9c06b0b4 TJB |
11268 | /* Extract the thread ID from the next token. */ |
11269 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11270 | |
9c06b0b4 TJB |
11271 | /* Check if the user provided a valid numeric value for the |
11272 | thread ID. */ | |
11273 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11274 | error (_("Invalid thread ID specification %s."), value_start); | |
11275 | ||
11276 | /* Check if the thread actually exists. */ | |
11277 | if (!valid_thread_id (thread)) | |
af4908ba | 11278 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11279 | } |
11280 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11281 | { | |
11282 | /* We've found a "mask" token, which means the user wants to | |
11283 | create a hardware watchpoint that is going to have the mask | |
11284 | facility. */ | |
11285 | struct value *mask_value, *mark; | |
37e4754d | 11286 | |
9c06b0b4 TJB |
11287 | if (use_mask) |
11288 | error(_("You can specify only one mask.")); | |
37e4754d | 11289 | |
9c06b0b4 | 11290 | use_mask = just_location = 1; |
37e4754d | 11291 | |
9c06b0b4 TJB |
11292 | mark = value_mark (); |
11293 | mask_value = parse_to_comma_and_eval (&value_start); | |
11294 | mask = value_as_address (mask_value); | |
11295 | value_free_to_mark (mark); | |
11296 | } | |
11297 | else | |
11298 | /* We didn't recognize what we found. We should stop here. */ | |
11299 | break; | |
37e4754d | 11300 | |
9c06b0b4 TJB |
11301 | /* Truncate the string and get rid of the "parameter value" pair before |
11302 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11303 | exp_end = tok; |
9c06b0b4 | 11304 | } |
37e4754d | 11305 | } |
bbc13ae3 KS |
11306 | else |
11307 | exp_end = arg; | |
37e4754d | 11308 | |
bbc13ae3 KS |
11309 | /* Parse the rest of the arguments. From here on out, everything |
11310 | is in terms of a newly allocated string instead of the original | |
11311 | ARG. */ | |
c906108c | 11312 | innermost_block = NULL; |
bbc13ae3 KS |
11313 | expression = savestring (arg, exp_end - arg); |
11314 | back_to = make_cleanup (xfree, expression); | |
11315 | exp_start = arg = expression; | |
1bb9788d | 11316 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11317 | exp_end = arg; |
fa8a61dc TT |
11318 | /* Remove trailing whitespace from the expression before saving it. |
11319 | This makes the eventual display of the expression string a bit | |
11320 | prettier. */ | |
11321 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11322 | --exp_end; | |
11323 | ||
65d79d4b SDJ |
11324 | /* Checking if the expression is not constant. */ |
11325 | if (watchpoint_exp_is_const (exp)) | |
11326 | { | |
11327 | int len; | |
11328 | ||
11329 | len = exp_end - exp_start; | |
11330 | while (len > 0 && isspace (exp_start[len - 1])) | |
11331 | len--; | |
11332 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11333 | } | |
11334 | ||
c906108c SS |
11335 | exp_valid_block = innermost_block; |
11336 | mark = value_mark (); | |
3a1115a0 | 11337 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11338 | |
11339 | if (just_location) | |
11340 | { | |
9c06b0b4 TJB |
11341 | int ret; |
11342 | ||
06a64a0b | 11343 | exp_valid_block = NULL; |
a1442452 | 11344 | val = value_addr (result); |
06a64a0b TT |
11345 | release_value (val); |
11346 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11347 | |
11348 | if (use_mask) | |
11349 | { | |
11350 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11351 | mask); | |
11352 | if (ret == -1) | |
11353 | error (_("This target does not support masked watchpoints.")); | |
11354 | else if (ret == -2) | |
11355 | error (_("Invalid mask or memory region.")); | |
11356 | } | |
06a64a0b TT |
11357 | } |
11358 | else if (val != NULL) | |
fa4727a6 | 11359 | release_value (val); |
c906108c | 11360 | |
bbc13ae3 KS |
11361 | tok = skip_spaces_const (arg); |
11362 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11363 | |
11364 | toklen = end_tok - tok; | |
11365 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11366 | { | |
2d134ed3 PA |
11367 | struct expression *cond; |
11368 | ||
60e1c644 | 11369 | innermost_block = NULL; |
c906108c | 11370 | tok = cond_start = end_tok + 1; |
1bb9788d | 11371 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11372 | |
11373 | /* The watchpoint expression may not be local, but the condition | |
11374 | may still be. E.g.: `watch global if local > 0'. */ | |
11375 | cond_exp_valid_block = innermost_block; | |
11376 | ||
2d134ed3 | 11377 | xfree (cond); |
c906108c SS |
11378 | cond_end = tok; |
11379 | } | |
11380 | if (*tok) | |
8a3fe4f8 | 11381 | error (_("Junk at end of command.")); |
c906108c | 11382 | |
d983da9c | 11383 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11384 | |
11385 | /* If the expression is "local", then set up a "watchpoint scope" | |
11386 | breakpoint at the point where we've left the scope of the watchpoint | |
11387 | expression. Create the scope breakpoint before the watchpoint, so | |
11388 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11389 | if (exp_valid_block && frame) |
d983da9c | 11390 | { |
edb3359d DJ |
11391 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11392 | { | |
11393 | scope_breakpoint | |
a6d9a66e UW |
11394 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11395 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11396 | bp_watchpoint_scope, |
11397 | &momentary_breakpoint_ops); | |
d983da9c | 11398 | |
edb3359d | 11399 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11400 | |
edb3359d DJ |
11401 | /* Automatically delete the breakpoint when it hits. */ |
11402 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11403 | |
edb3359d DJ |
11404 | /* Only break in the proper frame (help with recursion). */ |
11405 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11406 | |
edb3359d | 11407 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11408 | scope_breakpoint->loc->gdbarch |
11409 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11410 | scope_breakpoint->loc->requested_address |
11411 | = frame_unwind_caller_pc (frame); | |
11412 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11413 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11414 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11415 | scope_breakpoint->type); |
11416 | } | |
d983da9c DJ |
11417 | } |
11418 | ||
e8369a73 AB |
11419 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11420 | watchpoints here even if hardware watchpoints are turned off, a call | |
11421 | to update_watchpoint later in this function will cause the type to | |
11422 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11423 | ||
11424 | if (accessflag == hw_read) | |
11425 | bp_type = bp_read_watchpoint; | |
11426 | else if (accessflag == hw_access) | |
11427 | bp_type = bp_access_watchpoint; | |
11428 | else | |
11429 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11430 | |
11431 | w = XCNEW (struct watchpoint); | |
11432 | b = &w->base; | |
348d480f | 11433 | if (use_mask) |
3a5c3e22 PA |
11434 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11435 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11436 | else |
3a5c3e22 PA |
11437 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11438 | &watchpoint_breakpoint_ops); | |
37e4754d | 11439 | b->thread = thread; |
b5de0fa7 | 11440 | b->disposition = disp_donttouch; |
348d480f | 11441 | b->pspace = current_program_space; |
3a5c3e22 PA |
11442 | w->exp = exp; |
11443 | w->exp_valid_block = exp_valid_block; | |
11444 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11445 | if (just_location) |
11446 | { | |
11447 | struct type *t = value_type (val); | |
11448 | CORE_ADDR addr = value_as_address (val); | |
11449 | char *name; | |
11450 | ||
11451 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11452 | name = type_to_string (t); | |
11453 | ||
3a5c3e22 | 11454 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11455 | core_addr_to_string (addr)); |
06a64a0b TT |
11456 | xfree (name); |
11457 | ||
3a5c3e22 | 11458 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11459 | (int) (exp_end - exp_start), exp_start); |
11460 | ||
06a64a0b TT |
11461 | /* The above expression is in C. */ |
11462 | b->language = language_c; | |
11463 | } | |
11464 | else | |
3a5c3e22 | 11465 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11466 | |
11467 | if (use_mask) | |
11468 | { | |
3a5c3e22 | 11469 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11470 | } |
11471 | else | |
11472 | { | |
3a5c3e22 PA |
11473 | w->val = val; |
11474 | w->val_valid = 1; | |
9c06b0b4 | 11475 | } |
77b06cd7 | 11476 | |
c906108c SS |
11477 | if (cond_start) |
11478 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11479 | else | |
11480 | b->cond_string = 0; | |
c5aa993b | 11481 | |
c906108c | 11482 | if (frame) |
f6bc2008 | 11483 | { |
3a5c3e22 PA |
11484 | w->watchpoint_frame = get_frame_id (frame); |
11485 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11486 | } |
c906108c | 11487 | else |
f6bc2008 | 11488 | { |
3a5c3e22 PA |
11489 | w->watchpoint_frame = null_frame_id; |
11490 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11491 | } |
c906108c | 11492 | |
d983da9c | 11493 | if (scope_breakpoint != NULL) |
c906108c | 11494 | { |
d983da9c DJ |
11495 | /* The scope breakpoint is related to the watchpoint. We will |
11496 | need to act on them together. */ | |
11497 | b->related_breakpoint = scope_breakpoint; | |
11498 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11499 | } |
d983da9c | 11500 | |
06a64a0b TT |
11501 | if (!just_location) |
11502 | value_free_to_mark (mark); | |
2d134ed3 | 11503 | |
a9634178 TJB |
11504 | TRY_CATCH (e, RETURN_MASK_ALL) |
11505 | { | |
11506 | /* Finally update the new watchpoint. This creates the locations | |
11507 | that should be inserted. */ | |
3a5c3e22 | 11508 | update_watchpoint (w, 1); |
a9634178 TJB |
11509 | } |
11510 | if (e.reason < 0) | |
11511 | { | |
11512 | delete_breakpoint (b); | |
11513 | throw_exception (e); | |
11514 | } | |
11515 | ||
3ea46bff | 11516 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11517 | do_cleanups (back_to); |
c906108c SS |
11518 | } |
11519 | ||
e09342b5 | 11520 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11521 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11522 | |
c906108c | 11523 | static int |
a9634178 | 11524 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11525 | { |
11526 | int found_memory_cnt = 0; | |
2e70b7b9 | 11527 | struct value *head = v; |
c906108c SS |
11528 | |
11529 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11530 | if (!can_use_hw_watchpoints) |
c906108c | 11531 | return 0; |
c5aa993b | 11532 | |
5c44784c JM |
11533 | /* Make sure that the value of the expression depends only upon |
11534 | memory contents, and values computed from them within GDB. If we | |
11535 | find any register references or function calls, we can't use a | |
11536 | hardware watchpoint. | |
11537 | ||
11538 | The idea here is that evaluating an expression generates a series | |
11539 | of values, one holding the value of every subexpression. (The | |
11540 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11541 | a*b+c.) GDB's values hold almost enough information to establish | |
11542 | the criteria given above --- they identify memory lvalues, | |
11543 | register lvalues, computed values, etcetera. So we can evaluate | |
11544 | the expression, and then scan the chain of values that leaves | |
11545 | behind to decide whether we can detect any possible change to the | |
11546 | expression's final value using only hardware watchpoints. | |
11547 | ||
11548 | However, I don't think that the values returned by inferior | |
11549 | function calls are special in any way. So this function may not | |
11550 | notice that an expression involving an inferior function call | |
11551 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11552 | for (; v; v = value_next (v)) |
c906108c | 11553 | { |
5c44784c | 11554 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11555 | { |
8464be76 DJ |
11556 | if (v != head && value_lazy (v)) |
11557 | /* A lazy memory lvalue in the chain is one that GDB never | |
11558 | needed to fetch; we either just used its address (e.g., | |
11559 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11560 | in `a,b'). This doesn't apply to HEAD; if that is | |
11561 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11562 | ; |
53a5351d | 11563 | else |
5c44784c JM |
11564 | { |
11565 | /* Ahh, memory we actually used! Check if we can cover | |
11566 | it with hardware watchpoints. */ | |
df407dfe | 11567 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11568 | |
11569 | /* We only watch structs and arrays if user asked for it | |
11570 | explicitly, never if they just happen to appear in a | |
11571 | middle of some value chain. */ | |
11572 | if (v == head | |
11573 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11574 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11575 | { | |
42ae5230 | 11576 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11577 | int len; |
11578 | int num_regs; | |
11579 | ||
a9634178 | 11580 | len = (target_exact_watchpoints |
e09342b5 TJB |
11581 | && is_scalar_type_recursive (vtype))? |
11582 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11583 | |
e09342b5 TJB |
11584 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11585 | if (!num_regs) | |
2e70b7b9 MS |
11586 | return 0; |
11587 | else | |
e09342b5 | 11588 | found_memory_cnt += num_regs; |
2e70b7b9 | 11589 | } |
5c44784c | 11590 | } |
c5aa993b | 11591 | } |
5086187c AC |
11592 | else if (VALUE_LVAL (v) != not_lval |
11593 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11594 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11595 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11596 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11597 | } |
11598 | ||
11599 | /* The expression itself looks suitable for using a hardware | |
11600 | watchpoint, but give the target machine a chance to reject it. */ | |
11601 | return found_memory_cnt; | |
11602 | } | |
11603 | ||
8b93c638 | 11604 | void |
84f4c1fe | 11605 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11606 | { |
84f4c1fe | 11607 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11608 | } |
11609 | ||
06a64a0b TT |
11610 | /* A helper function that looks for the "-location" argument and then |
11611 | calls watch_command_1. */ | |
11612 | ||
11613 | static void | |
11614 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11615 | { | |
11616 | int just_location = 0; | |
11617 | ||
11618 | if (arg | |
11619 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11620 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11621 | { | |
e9cafbcc | 11622 | arg = skip_spaces (arg); |
06a64a0b TT |
11623 | just_location = 1; |
11624 | } | |
11625 | ||
84f4c1fe | 11626 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11627 | } |
8926118c | 11628 | |
c5aa993b | 11629 | static void |
fba45db2 | 11630 | watch_command (char *arg, int from_tty) |
c906108c | 11631 | { |
06a64a0b | 11632 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11633 | } |
11634 | ||
8b93c638 | 11635 | void |
84f4c1fe | 11636 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11637 | { |
84f4c1fe | 11638 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11639 | } |
8926118c | 11640 | |
c5aa993b | 11641 | static void |
fba45db2 | 11642 | rwatch_command (char *arg, int from_tty) |
c906108c | 11643 | { |
06a64a0b | 11644 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11645 | } |
11646 | ||
8b93c638 | 11647 | void |
84f4c1fe | 11648 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11649 | { |
84f4c1fe | 11650 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11651 | } |
8926118c | 11652 | |
c5aa993b | 11653 | static void |
fba45db2 | 11654 | awatch_command (char *arg, int from_tty) |
c906108c | 11655 | { |
06a64a0b | 11656 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11657 | } |
c906108c | 11658 | \f |
c5aa993b | 11659 | |
43ff13b4 | 11660 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11661 | because it uses the mechanisms of breakpoints. */ |
11662 | ||
bfec99b2 PA |
11663 | struct until_break_command_continuation_args |
11664 | { | |
11665 | struct breakpoint *breakpoint; | |
11666 | struct breakpoint *breakpoint2; | |
186c406b | 11667 | int thread_num; |
bfec99b2 PA |
11668 | }; |
11669 | ||
43ff13b4 | 11670 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11671 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11672 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11673 | command. */ |
c2c6d25f | 11674 | static void |
fa4cd53f | 11675 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11676 | { |
bfec99b2 PA |
11677 | struct until_break_command_continuation_args *a = arg; |
11678 | ||
11679 | delete_breakpoint (a->breakpoint); | |
11680 | if (a->breakpoint2) | |
11681 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11682 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11683 | } |
11684 | ||
c906108c | 11685 | void |
ae66c1fc | 11686 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11687 | { |
11688 | struct symtabs_and_lines sals; | |
11689 | struct symtab_and_line sal; | |
8556afb4 PA |
11690 | struct frame_info *frame; |
11691 | struct gdbarch *frame_gdbarch; | |
11692 | struct frame_id stack_frame_id; | |
11693 | struct frame_id caller_frame_id; | |
c906108c | 11694 | struct breakpoint *breakpoint; |
f107f563 | 11695 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11696 | struct cleanup *old_chain; |
186c406b TT |
11697 | int thread; |
11698 | struct thread_info *tp; | |
c906108c | 11699 | |
70509625 | 11700 | clear_proceed_status (0); |
c906108c SS |
11701 | |
11702 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11703 | this function. */ |
c5aa993b | 11704 | |
1bfeeb0f | 11705 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11706 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11707 | get_last_displayed_symtab (), |
f8eba3c6 | 11708 | get_last_displayed_line ()); |
c906108c | 11709 | else |
f8eba3c6 TT |
11710 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11711 | (struct symtab *) NULL, 0); | |
c5aa993b | 11712 | |
c906108c | 11713 | if (sals.nelts != 1) |
8a3fe4f8 | 11714 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11715 | |
c906108c | 11716 | sal = sals.sals[0]; |
4a64f543 | 11717 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11718 | |
c906108c | 11719 | if (*arg) |
8a3fe4f8 | 11720 | error (_("Junk at end of arguments.")); |
c5aa993b | 11721 | |
c906108c | 11722 | resolve_sal_pc (&sal); |
c5aa993b | 11723 | |
186c406b TT |
11724 | tp = inferior_thread (); |
11725 | thread = tp->num; | |
11726 | ||
883bc8d1 PA |
11727 | old_chain = make_cleanup (null_cleanup, NULL); |
11728 | ||
8556afb4 PA |
11729 | /* Note linespec handling above invalidates the frame chain. |
11730 | Installing a breakpoint also invalidates the frame chain (as it | |
11731 | may need to switch threads), so do any frame handling before | |
11732 | that. */ | |
11733 | ||
11734 | frame = get_selected_frame (NULL); | |
11735 | frame_gdbarch = get_frame_arch (frame); | |
11736 | stack_frame_id = get_stack_frame_id (frame); | |
11737 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11738 | |
ae66c1fc EZ |
11739 | /* Keep within the current frame, or in frames called by the current |
11740 | one. */ | |
edb3359d | 11741 | |
883bc8d1 | 11742 | if (frame_id_p (caller_frame_id)) |
c906108c | 11743 | { |
883bc8d1 PA |
11744 | struct symtab_and_line sal2; |
11745 | ||
11746 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11747 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11748 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11749 | sal2, |
11750 | caller_frame_id, | |
f107f563 VP |
11751 | bp_until); |
11752 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11753 | |
883bc8d1 | 11754 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11755 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11756 | } |
c5aa993b | 11757 | |
c70a6932 JK |
11758 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11759 | frame = NULL; | |
11760 | ||
883bc8d1 PA |
11761 | if (anywhere) |
11762 | /* If the user told us to continue until a specified location, | |
11763 | we don't specify a frame at which we need to stop. */ | |
11764 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11765 | null_frame_id, bp_until); | |
11766 | else | |
11767 | /* Otherwise, specify the selected frame, because we want to stop | |
11768 | only at the very same frame. */ | |
11769 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11770 | stack_frame_id, bp_until); | |
11771 | make_cleanup_delete_breakpoint (breakpoint); | |
11772 | ||
a493e3e2 | 11773 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11774 | |
4a64f543 MS |
11775 | /* If we are running asynchronously, and proceed call above has |
11776 | actually managed to start the target, arrange for breakpoints to | |
11777 | be deleted when the target stops. Otherwise, we're already | |
11778 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11779 | |
8ea051c5 | 11780 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11781 | { |
bfec99b2 PA |
11782 | struct until_break_command_continuation_args *args; |
11783 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11784 | |
bfec99b2 PA |
11785 | args->breakpoint = breakpoint; |
11786 | args->breakpoint2 = breakpoint2; | |
186c406b | 11787 | args->thread_num = thread; |
f107f563 VP |
11788 | |
11789 | discard_cleanups (old_chain); | |
95e54da7 PA |
11790 | add_continuation (inferior_thread (), |
11791 | until_break_command_continuation, args, | |
604ead4a | 11792 | xfree); |
f107f563 VP |
11793 | } |
11794 | else | |
c5aa993b | 11795 | do_cleanups (old_chain); |
c906108c | 11796 | } |
ae66c1fc | 11797 | |
c906108c SS |
11798 | /* This function attempts to parse an optional "if <cond>" clause |
11799 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11800 | |
c906108c SS |
11801 | Else, it returns a pointer to the condition string. (It does not |
11802 | attempt to evaluate the string against a particular block.) And, | |
11803 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11804 | if clause in the arg string. */ |
53a5351d | 11805 | |
916703c0 | 11806 | char * |
fba45db2 | 11807 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11808 | { |
c5aa993b JM |
11809 | char *cond_string; |
11810 | ||
11811 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11812 | return NULL; |
c5aa993b | 11813 | |
4a64f543 | 11814 | /* Skip the "if" keyword. */ |
c906108c | 11815 | (*arg) += 2; |
c5aa993b | 11816 | |
c906108c | 11817 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11818 | condition string. */ |
e9cafbcc | 11819 | *arg = skip_spaces (*arg); |
c906108c | 11820 | cond_string = *arg; |
c5aa993b | 11821 | |
4a64f543 MS |
11822 | /* Assume that the condition occupies the remainder of the arg |
11823 | string. */ | |
c906108c | 11824 | (*arg) += strlen (cond_string); |
c5aa993b | 11825 | |
c906108c SS |
11826 | return cond_string; |
11827 | } | |
c5aa993b | 11828 | |
c906108c SS |
11829 | /* Commands to deal with catching events, such as signals, exceptions, |
11830 | process start/exit, etc. */ | |
c5aa993b JM |
11831 | |
11832 | typedef enum | |
11833 | { | |
44feb3ce TT |
11834 | catch_fork_temporary, catch_vfork_temporary, |
11835 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11836 | } |
11837 | catch_fork_kind; | |
11838 | ||
c906108c | 11839 | static void |
cc59ec59 MS |
11840 | catch_fork_command_1 (char *arg, int from_tty, |
11841 | struct cmd_list_element *command) | |
c906108c | 11842 | { |
a6d9a66e | 11843 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11844 | char *cond_string = NULL; |
44feb3ce TT |
11845 | catch_fork_kind fork_kind; |
11846 | int tempflag; | |
11847 | ||
11848 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11849 | tempflag = (fork_kind == catch_fork_temporary | |
11850 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11851 | |
44feb3ce TT |
11852 | if (!arg) |
11853 | arg = ""; | |
e9cafbcc | 11854 | arg = skip_spaces (arg); |
c5aa993b | 11855 | |
c906108c | 11856 | /* The allowed syntax is: |
c5aa993b JM |
11857 | catch [v]fork |
11858 | catch [v]fork if <cond> | |
11859 | ||
4a64f543 | 11860 | First, check if there's an if clause. */ |
c906108c | 11861 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11862 | |
c906108c | 11863 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11864 | error (_("Junk at end of arguments.")); |
c5aa993b | 11865 | |
c906108c | 11866 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11867 | and enable reporting of such events. */ |
c5aa993b JM |
11868 | switch (fork_kind) |
11869 | { | |
44feb3ce TT |
11870 | case catch_fork_temporary: |
11871 | case catch_fork_permanent: | |
a6d9a66e | 11872 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11873 | &catch_fork_breakpoint_ops); |
c906108c | 11874 | break; |
44feb3ce TT |
11875 | case catch_vfork_temporary: |
11876 | case catch_vfork_permanent: | |
a6d9a66e | 11877 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11878 | &catch_vfork_breakpoint_ops); |
c906108c | 11879 | break; |
c5aa993b | 11880 | default: |
8a3fe4f8 | 11881 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11882 | break; |
c5aa993b | 11883 | } |
c906108c SS |
11884 | } |
11885 | ||
11886 | static void | |
cc59ec59 MS |
11887 | catch_exec_command_1 (char *arg, int from_tty, |
11888 | struct cmd_list_element *command) | |
c906108c | 11889 | { |
b4d90040 | 11890 | struct exec_catchpoint *c; |
a6d9a66e | 11891 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11892 | int tempflag; |
c5aa993b | 11893 | char *cond_string = NULL; |
c906108c | 11894 | |
44feb3ce TT |
11895 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11896 | ||
11897 | if (!arg) | |
11898 | arg = ""; | |
e9cafbcc | 11899 | arg = skip_spaces (arg); |
c906108c SS |
11900 | |
11901 | /* The allowed syntax is: | |
c5aa993b JM |
11902 | catch exec |
11903 | catch exec if <cond> | |
c906108c | 11904 | |
4a64f543 | 11905 | First, check if there's an if clause. */ |
c906108c SS |
11906 | cond_string = ep_parse_optional_if_clause (&arg); |
11907 | ||
11908 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11909 | error (_("Junk at end of arguments.")); |
c906108c | 11910 | |
b4d90040 PA |
11911 | c = XNEW (struct exec_catchpoint); |
11912 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11913 | &catch_exec_breakpoint_ops); | |
11914 | c->exec_pathname = NULL; | |
11915 | ||
3ea46bff | 11916 | install_breakpoint (0, &c->base, 1); |
c906108c | 11917 | } |
c5aa993b | 11918 | |
9ac4176b | 11919 | void |
28010a5d PA |
11920 | init_ada_exception_breakpoint (struct breakpoint *b, |
11921 | struct gdbarch *gdbarch, | |
11922 | struct symtab_and_line sal, | |
11923 | char *addr_string, | |
c0a91b2b | 11924 | const struct breakpoint_ops *ops, |
28010a5d | 11925 | int tempflag, |
349774ef | 11926 | int enabled, |
28010a5d | 11927 | int from_tty) |
f7f9143b | 11928 | { |
f7f9143b JB |
11929 | if (from_tty) |
11930 | { | |
5af949e3 UW |
11931 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11932 | if (!loc_gdbarch) | |
11933 | loc_gdbarch = gdbarch; | |
11934 | ||
6c95b8df PA |
11935 | describe_other_breakpoints (loc_gdbarch, |
11936 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11937 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11938 | version for exception catchpoints, because two catchpoints | |
11939 | used for different exception names will use the same address. | |
11940 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11941 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11942 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11943 | the user what type of catchpoint it is. The above is good |
11944 | enough for now, though. */ | |
11945 | } | |
11946 | ||
28010a5d | 11947 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11948 | |
349774ef | 11949 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11950 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11951 | b->addr_string = addr_string; |
11952 | b->language = language_ada; | |
f7f9143b JB |
11953 | } |
11954 | ||
a96d9b2e SDJ |
11955 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11956 | filter list, or NULL if no filtering is required. */ | |
11957 | static VEC(int) * | |
11958 | catch_syscall_split_args (char *arg) | |
11959 | { | |
11960 | VEC(int) *result = NULL; | |
29d0bb3d | 11961 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11962 | |
11963 | while (*arg != '\0') | |
11964 | { | |
11965 | int i, syscall_number; | |
11966 | char *endptr; | |
11967 | char cur_name[128]; | |
11968 | struct syscall s; | |
11969 | ||
11970 | /* Skip whitespace. */ | |
529480d0 | 11971 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11972 | |
11973 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11974 | cur_name[i] = arg[i]; | |
11975 | cur_name[i] = '\0'; | |
11976 | arg += i; | |
11977 | ||
11978 | /* Check if the user provided a syscall name or a number. */ | |
11979 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11980 | if (*endptr == '\0') | |
bccd0dd2 | 11981 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11982 | else |
11983 | { | |
11984 | /* We have a name. Let's check if it's valid and convert it | |
11985 | to a number. */ | |
11986 | get_syscall_by_name (cur_name, &s); | |
11987 | ||
11988 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11989 | /* Here we have to issue an error instead of a warning, |
11990 | because GDB cannot do anything useful if there's no | |
11991 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11992 | error (_("Unknown syscall name '%s'."), cur_name); |
11993 | } | |
11994 | ||
11995 | /* Ok, it's valid. */ | |
11996 | VEC_safe_push (int, result, s.number); | |
11997 | } | |
11998 | ||
11999 | discard_cleanups (cleanup); | |
12000 | return result; | |
12001 | } | |
12002 | ||
12003 | /* Implement the "catch syscall" command. */ | |
12004 | ||
12005 | static void | |
cc59ec59 MS |
12006 | catch_syscall_command_1 (char *arg, int from_tty, |
12007 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
12008 | { |
12009 | int tempflag; | |
12010 | VEC(int) *filter; | |
12011 | struct syscall s; | |
12012 | struct gdbarch *gdbarch = get_current_arch (); | |
12013 | ||
12014 | /* Checking if the feature if supported. */ | |
12015 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
12016 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 12017 | this architecture yet.")); |
a96d9b2e SDJ |
12018 | |
12019 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
12020 | ||
e9cafbcc | 12021 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12022 | |
12023 | /* We need to do this first "dummy" translation in order | |
12024 | to get the syscall XML file loaded or, most important, | |
12025 | to display a warning to the user if there's no XML file | |
12026 | for his/her architecture. */ | |
12027 | get_syscall_by_number (0, &s); | |
12028 | ||
12029 | /* The allowed syntax is: | |
12030 | catch syscall | |
12031 | catch syscall <name | number> [<name | number> ... <name | number>] | |
12032 | ||
12033 | Let's check if there's a syscall name. */ | |
12034 | ||
12035 | if (arg != NULL) | |
12036 | filter = catch_syscall_split_args (arg); | |
12037 | else | |
12038 | filter = NULL; | |
12039 | ||
12040 | create_syscall_event_catchpoint (tempflag, filter, | |
12041 | &catch_syscall_breakpoint_ops); | |
12042 | } | |
12043 | ||
c906108c | 12044 | static void |
fba45db2 | 12045 | catch_command (char *arg, int from_tty) |
c906108c | 12046 | { |
44feb3ce | 12047 | error (_("Catch requires an event name.")); |
c906108c SS |
12048 | } |
12049 | \f | |
12050 | ||
12051 | static void | |
fba45db2 | 12052 | tcatch_command (char *arg, int from_tty) |
c906108c | 12053 | { |
44feb3ce | 12054 | error (_("Catch requires an event name.")); |
c906108c SS |
12055 | } |
12056 | ||
8a2c437b TT |
12057 | /* A qsort comparison function that sorts breakpoints in order. */ |
12058 | ||
12059 | static int | |
12060 | compare_breakpoints (const void *a, const void *b) | |
12061 | { | |
12062 | const breakpoint_p *ba = a; | |
12063 | uintptr_t ua = (uintptr_t) *ba; | |
12064 | const breakpoint_p *bb = b; | |
12065 | uintptr_t ub = (uintptr_t) *bb; | |
12066 | ||
12067 | if ((*ba)->number < (*bb)->number) | |
12068 | return -1; | |
12069 | else if ((*ba)->number > (*bb)->number) | |
12070 | return 1; | |
12071 | ||
12072 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12073 | the number 0. */ | |
12074 | if (ua < ub) | |
12075 | return -1; | |
94b0e70d | 12076 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12077 | } |
12078 | ||
80f8a6eb | 12079 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12080 | |
12081 | static void | |
fba45db2 | 12082 | clear_command (char *arg, int from_tty) |
c906108c | 12083 | { |
8a2c437b | 12084 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12085 | VEC(breakpoint_p) *found = 0; |
12086 | int ix; | |
c906108c SS |
12087 | int default_match; |
12088 | struct symtabs_and_lines sals; | |
12089 | struct symtab_and_line sal; | |
c906108c | 12090 | int i; |
8a2c437b | 12091 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12092 | |
12093 | if (arg) | |
12094 | { | |
39cf75f7 DE |
12095 | sals = decode_line_with_current_source (arg, |
12096 | (DECODE_LINE_FUNFIRSTLINE | |
12097 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12098 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12099 | default_match = 0; |
12100 | } | |
12101 | else | |
12102 | { | |
c5aa993b | 12103 | sals.sals = (struct symtab_and_line *) |
c906108c | 12104 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 12105 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12106 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12107 | |
12108 | /* Set sal's line, symtab, pc, and pspace to the values | |
12109 | corresponding to the last call to print_frame_info. If the | |
12110 | codepoint is not valid, this will set all the fields to 0. */ | |
12111 | get_last_displayed_sal (&sal); | |
c906108c | 12112 | if (sal.symtab == 0) |
8a3fe4f8 | 12113 | error (_("No source file specified.")); |
c906108c SS |
12114 | |
12115 | sals.sals[0] = sal; | |
12116 | sals.nelts = 1; | |
12117 | ||
12118 | default_match = 1; | |
12119 | } | |
12120 | ||
4a64f543 MS |
12121 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12122 | seems, because all existing breakpoints typically have both | |
12123 | file/line and pc set. So, if clear is given file/line, we can | |
12124 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12125 | |
12126 | We only support clearing given the address explicitly | |
12127 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12128 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12129 | due to optimization, all in one block. |
4a64f543 MS |
12130 | |
12131 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12132 | PC corresponding to the same file:line, the breakpoint won't |
12133 | be cleared. We probably can still clear the breakpoint, but | |
12134 | since the other PC value is never presented to user, user | |
12135 | can only find it by guessing, and it does not seem important | |
12136 | to support that. */ | |
12137 | ||
4a64f543 MS |
12138 | /* For each line spec given, delete bps which correspond to it. Do |
12139 | it in two passes, solely to preserve the current behavior that | |
12140 | from_tty is forced true if we delete more than one | |
12141 | breakpoint. */ | |
c906108c | 12142 | |
80f8a6eb | 12143 | found = NULL; |
8a2c437b | 12144 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12145 | for (i = 0; i < sals.nelts; i++) |
12146 | { | |
05cba821 JK |
12147 | const char *sal_fullname; |
12148 | ||
c906108c | 12149 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12150 | If line given (pc == 0), clear all bpts on specified line. |
12151 | If defaulting, clear all bpts on default line | |
c906108c | 12152 | or at default pc. |
c5aa993b JM |
12153 | |
12154 | defaulting sal.pc != 0 tests to do | |
12155 | ||
12156 | 0 1 pc | |
12157 | 1 1 pc _and_ line | |
12158 | 0 0 line | |
12159 | 1 0 <can't happen> */ | |
c906108c SS |
12160 | |
12161 | sal = sals.sals[i]; | |
05cba821 JK |
12162 | sal_fullname = (sal.symtab == NULL |
12163 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12164 | |
4a64f543 | 12165 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12166 | ALL_BREAKPOINTS (b) |
c5aa993b | 12167 | { |
0d381245 | 12168 | int match = 0; |
4a64f543 | 12169 | /* Are we going to delete b? */ |
cc60f2e3 | 12170 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12171 | { |
12172 | struct bp_location *loc = b->loc; | |
12173 | for (; loc; loc = loc->next) | |
12174 | { | |
f8eba3c6 TT |
12175 | /* If the user specified file:line, don't allow a PC |
12176 | match. This matches historical gdb behavior. */ | |
12177 | int pc_match = (!sal.explicit_line | |
12178 | && sal.pc | |
12179 | && (loc->pspace == sal.pspace) | |
12180 | && (loc->address == sal.pc) | |
12181 | && (!section_is_overlay (loc->section) | |
12182 | || loc->section == sal.section)); | |
4aac40c8 TT |
12183 | int line_match = 0; |
12184 | ||
12185 | if ((default_match || sal.explicit_line) | |
2f202fde | 12186 | && loc->symtab != NULL |
05cba821 | 12187 | && sal_fullname != NULL |
4aac40c8 | 12188 | && sal.pspace == loc->pspace |
05cba821 JK |
12189 | && loc->line_number == sal.line |
12190 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12191 | sal_fullname) == 0) | |
12192 | line_match = 1; | |
4aac40c8 | 12193 | |
0d381245 VP |
12194 | if (pc_match || line_match) |
12195 | { | |
12196 | match = 1; | |
12197 | break; | |
12198 | } | |
12199 | } | |
12200 | } | |
12201 | ||
12202 | if (match) | |
d6e956e5 | 12203 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12204 | } |
80f8a6eb | 12205 | } |
8a2c437b | 12206 | |
80f8a6eb | 12207 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12208 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12209 | { |
12210 | if (arg) | |
8a3fe4f8 | 12211 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12212 | else |
8a3fe4f8 | 12213 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12214 | } |
c906108c | 12215 | |
8a2c437b TT |
12216 | /* Remove duplicates from the vec. */ |
12217 | qsort (VEC_address (breakpoint_p, found), | |
12218 | VEC_length (breakpoint_p, found), | |
12219 | sizeof (breakpoint_p), | |
12220 | compare_breakpoints); | |
12221 | prev = VEC_index (breakpoint_p, found, 0); | |
12222 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12223 | { | |
12224 | if (b == prev) | |
12225 | { | |
12226 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12227 | --ix; | |
12228 | } | |
12229 | } | |
12230 | ||
d6e956e5 | 12231 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12232 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12233 | if (from_tty) |
a3f17187 | 12234 | { |
d6e956e5 | 12235 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12236 | printf_unfiltered (_("Deleted breakpoint ")); |
12237 | else | |
12238 | printf_unfiltered (_("Deleted breakpoints ")); | |
12239 | } | |
d6e956e5 VP |
12240 | |
12241 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12242 | { |
c5aa993b | 12243 | if (from_tty) |
d6e956e5 VP |
12244 | printf_unfiltered ("%d ", b->number); |
12245 | delete_breakpoint (b); | |
c906108c | 12246 | } |
80f8a6eb MS |
12247 | if (from_tty) |
12248 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12249 | |
12250 | do_cleanups (cleanups); | |
c906108c SS |
12251 | } |
12252 | \f | |
12253 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12254 | all breakpoints that are marked for deletion, whether hit or not. | |
12255 | This is called after any breakpoint is hit, or after errors. */ | |
12256 | ||
12257 | void | |
fba45db2 | 12258 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12259 | { |
35df4500 | 12260 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12261 | |
12262 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12263 | if (bs->breakpoint_at |
12264 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12265 | && bs->stop) |
f431efe5 | 12266 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12267 | |
35df4500 | 12268 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12269 | { |
b5de0fa7 | 12270 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12271 | delete_breakpoint (b); |
12272 | } | |
c906108c SS |
12273 | } |
12274 | ||
4a64f543 MS |
12275 | /* A comparison function for bp_location AP and BP being interfaced to |
12276 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12277 | does breakpoint_address_is_meaningful say for its OWNER), | |
12278 | secondarily by ordering first bp_permanent OWNERed elements and | |
12279 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12280 | qsort being an unstable algorithm. */ |
876fa593 JK |
12281 | |
12282 | static int | |
494cfb0f | 12283 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12284 | { |
494cfb0f JK |
12285 | struct bp_location *a = *(void **) ap; |
12286 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12287 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12288 | int a_perm = a->owner->enable_state == bp_permanent; |
12289 | int b_perm = b->owner->enable_state == bp_permanent; | |
12290 | ||
12291 | if (a->address != b->address) | |
12292 | return (a->address > b->address) - (a->address < b->address); | |
12293 | ||
dea2aa5f LM |
12294 | /* Sort locations at the same address by their pspace number, keeping |
12295 | locations of the same inferior (in a multi-inferior environment) | |
12296 | grouped. */ | |
12297 | ||
12298 | if (a->pspace->num != b->pspace->num) | |
12299 | return ((a->pspace->num > b->pspace->num) | |
12300 | - (a->pspace->num < b->pspace->num)); | |
12301 | ||
876fa593 JK |
12302 | /* Sort permanent breakpoints first. */ |
12303 | if (a_perm != b_perm) | |
12304 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12305 | ||
c56a97f9 JK |
12306 | /* Make the internal GDB representation stable across GDB runs |
12307 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12308 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12309 | |
12310 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12311 | return ((a->owner->number > b->owner->number) |
12312 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12313 | |
12314 | return (a > b) - (a < b); | |
12315 | } | |
12316 | ||
876fa593 | 12317 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12318 | bp_location_shadow_len_after_address_max according to the current |
12319 | content of the bp_location array. */ | |
f7545552 TT |
12320 | |
12321 | static void | |
876fa593 | 12322 | bp_location_target_extensions_update (void) |
f7545552 | 12323 | { |
876fa593 JK |
12324 | struct bp_location *bl, **blp_tmp; |
12325 | ||
12326 | bp_location_placed_address_before_address_max = 0; | |
12327 | bp_location_shadow_len_after_address_max = 0; | |
12328 | ||
12329 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12330 | { | |
12331 | CORE_ADDR start, end, addr; | |
12332 | ||
12333 | if (!bp_location_has_shadow (bl)) | |
12334 | continue; | |
12335 | ||
12336 | start = bl->target_info.placed_address; | |
12337 | end = start + bl->target_info.shadow_len; | |
12338 | ||
12339 | gdb_assert (bl->address >= start); | |
12340 | addr = bl->address - start; | |
12341 | if (addr > bp_location_placed_address_before_address_max) | |
12342 | bp_location_placed_address_before_address_max = addr; | |
12343 | ||
12344 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12345 | ||
12346 | gdb_assert (bl->address < end); | |
12347 | addr = end - bl->address; | |
12348 | if (addr > bp_location_shadow_len_after_address_max) | |
12349 | bp_location_shadow_len_after_address_max = addr; | |
12350 | } | |
f7545552 TT |
12351 | } |
12352 | ||
1e4d1764 YQ |
12353 | /* Download tracepoint locations if they haven't been. */ |
12354 | ||
12355 | static void | |
12356 | download_tracepoint_locations (void) | |
12357 | { | |
7ed2c994 | 12358 | struct breakpoint *b; |
1e4d1764 YQ |
12359 | struct cleanup *old_chain; |
12360 | ||
12361 | if (!target_can_download_tracepoint ()) | |
12362 | return; | |
12363 | ||
12364 | old_chain = save_current_space_and_thread (); | |
12365 | ||
7ed2c994 | 12366 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12367 | { |
7ed2c994 | 12368 | struct bp_location *bl; |
1e4d1764 | 12369 | struct tracepoint *t; |
f2a8bc8a | 12370 | int bp_location_downloaded = 0; |
1e4d1764 | 12371 | |
7ed2c994 | 12372 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12373 | ? !may_insert_fast_tracepoints |
12374 | : !may_insert_tracepoints)) | |
12375 | continue; | |
12376 | ||
7ed2c994 YQ |
12377 | for (bl = b->loc; bl; bl = bl->next) |
12378 | { | |
12379 | /* In tracepoint, locations are _never_ duplicated, so | |
12380 | should_be_inserted is equivalent to | |
12381 | unduplicated_should_be_inserted. */ | |
12382 | if (!should_be_inserted (bl) || bl->inserted) | |
12383 | continue; | |
1e4d1764 | 12384 | |
7ed2c994 | 12385 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12386 | |
7ed2c994 | 12387 | target_download_tracepoint (bl); |
1e4d1764 | 12388 | |
7ed2c994 | 12389 | bl->inserted = 1; |
f2a8bc8a | 12390 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12391 | } |
12392 | t = (struct tracepoint *) b; | |
12393 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12394 | if (bp_location_downloaded) |
12395 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12396 | } |
12397 | ||
12398 | do_cleanups (old_chain); | |
12399 | } | |
12400 | ||
934709f0 PW |
12401 | /* Swap the insertion/duplication state between two locations. */ |
12402 | ||
12403 | static void | |
12404 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12405 | { | |
12406 | const int left_inserted = left->inserted; | |
12407 | const int left_duplicate = left->duplicate; | |
b775012e | 12408 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12409 | const struct bp_target_info left_target_info = left->target_info; |
12410 | ||
1e4d1764 YQ |
12411 | /* Locations of tracepoints can never be duplicated. */ |
12412 | if (is_tracepoint (left->owner)) | |
12413 | gdb_assert (!left->duplicate); | |
12414 | if (is_tracepoint (right->owner)) | |
12415 | gdb_assert (!right->duplicate); | |
12416 | ||
934709f0 PW |
12417 | left->inserted = right->inserted; |
12418 | left->duplicate = right->duplicate; | |
b775012e | 12419 | left->needs_update = right->needs_update; |
934709f0 PW |
12420 | left->target_info = right->target_info; |
12421 | right->inserted = left_inserted; | |
12422 | right->duplicate = left_duplicate; | |
b775012e | 12423 | right->needs_update = left_needs_update; |
934709f0 PW |
12424 | right->target_info = left_target_info; |
12425 | } | |
12426 | ||
b775012e LM |
12427 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12428 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12429 | conditions on the target's side. Such conditions need to be updated on | |
12430 | the target. */ | |
12431 | ||
12432 | static void | |
12433 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12434 | { | |
12435 | struct bp_location **locp = NULL, **loc2p; | |
12436 | struct bp_location *loc; | |
12437 | CORE_ADDR address = 0; | |
12438 | int pspace_num; | |
12439 | ||
12440 | address = bl->address; | |
12441 | pspace_num = bl->pspace->num; | |
12442 | ||
12443 | /* This is only meaningful if the target is | |
12444 | evaluating conditions and if the user has | |
12445 | opted for condition evaluation on the target's | |
12446 | side. */ | |
12447 | if (gdb_evaluates_breakpoint_condition_p () | |
12448 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12449 | return; | |
12450 | ||
12451 | /* Flag all breakpoint locations with this address and | |
12452 | the same program space as the location | |
12453 | as "its condition has changed". We need to | |
12454 | update the conditions on the target's side. */ | |
12455 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12456 | { | |
12457 | loc = *loc2p; | |
12458 | ||
12459 | if (!is_breakpoint (loc->owner) | |
12460 | || pspace_num != loc->pspace->num) | |
12461 | continue; | |
12462 | ||
12463 | /* Flag the location appropriately. We use a different state to | |
12464 | let everyone know that we already updated the set of locations | |
12465 | with addr bl->address and program space bl->pspace. This is so | |
12466 | we don't have to keep calling these functions just to mark locations | |
12467 | that have already been marked. */ | |
12468 | loc->condition_changed = condition_updated; | |
12469 | ||
12470 | /* Free the agent expression bytecode as well. We will compute | |
12471 | it later on. */ | |
12472 | if (loc->cond_bytecode) | |
12473 | { | |
12474 | free_agent_expr (loc->cond_bytecode); | |
12475 | loc->cond_bytecode = NULL; | |
12476 | } | |
12477 | } | |
12478 | } | |
12479 | ||
4cd9bd08 | 12480 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12481 | into the inferior, only remove already-inserted locations that no |
12482 | longer should be inserted. Functions that delete a breakpoint or | |
12483 | breakpoints should pass false, so that deleting a breakpoint | |
12484 | doesn't have the side effect of inserting the locations of other | |
12485 | breakpoints that are marked not-inserted, but should_be_inserted | |
12486 | returns true on them. | |
12487 | ||
12488 | This behaviour is useful is situations close to tear-down -- e.g., | |
12489 | after an exec, while the target still has execution, but breakpoint | |
12490 | shadows of the previous executable image should *NOT* be restored | |
12491 | to the new image; or before detaching, where the target still has | |
12492 | execution and wants to delete breakpoints from GDB's lists, and all | |
12493 | breakpoints had already been removed from the inferior. */ | |
12494 | ||
0d381245 | 12495 | static void |
b60e7edf | 12496 | update_global_location_list (int should_insert) |
0d381245 | 12497 | { |
74960c60 | 12498 | struct breakpoint *b; |
876fa593 | 12499 | struct bp_location **locp, *loc; |
f7545552 | 12500 | struct cleanup *cleanups; |
b775012e LM |
12501 | /* Last breakpoint location address that was marked for update. */ |
12502 | CORE_ADDR last_addr = 0; | |
12503 | /* Last breakpoint location program space that was marked for update. */ | |
12504 | int last_pspace_num = -1; | |
f7545552 | 12505 | |
2d134ed3 PA |
12506 | /* Used in the duplicates detection below. When iterating over all |
12507 | bp_locations, points to the first bp_location of a given address. | |
12508 | Breakpoints and watchpoints of different types are never | |
12509 | duplicates of each other. Keep one pointer for each type of | |
12510 | breakpoint/watchpoint, so we only need to loop over all locations | |
12511 | once. */ | |
12512 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12513 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12514 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12515 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12516 | |
4a64f543 MS |
12517 | /* Saved former bp_location array which we compare against the newly |
12518 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12519 | struct bp_location **old_location, **old_locp; |
12520 | unsigned old_location_count; | |
12521 | ||
12522 | old_location = bp_location; | |
12523 | old_location_count = bp_location_count; | |
12524 | bp_location = NULL; | |
12525 | bp_location_count = 0; | |
12526 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12527 | |
74960c60 | 12528 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12529 | for (loc = b->loc; loc; loc = loc->next) |
12530 | bp_location_count++; | |
12531 | ||
12532 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12533 | locp = bp_location; | |
12534 | ALL_BREAKPOINTS (b) | |
12535 | for (loc = b->loc; loc; loc = loc->next) | |
12536 | *locp++ = loc; | |
12537 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12538 | bp_location_compare); |
876fa593 JK |
12539 | |
12540 | bp_location_target_extensions_update (); | |
74960c60 | 12541 | |
4a64f543 MS |
12542 | /* Identify bp_location instances that are no longer present in the |
12543 | new list, and therefore should be freed. Note that it's not | |
12544 | necessary that those locations should be removed from inferior -- | |
12545 | if there's another location at the same address (previously | |
12546 | marked as duplicate), we don't need to remove/insert the | |
12547 | location. | |
876fa593 | 12548 | |
4a64f543 MS |
12549 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12550 | and former bp_location array state respectively. */ | |
876fa593 JK |
12551 | |
12552 | locp = bp_location; | |
12553 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12554 | old_locp++) | |
74960c60 | 12555 | { |
876fa593 | 12556 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12557 | struct bp_location **loc2p; |
876fa593 | 12558 | |
e5dd4106 | 12559 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12560 | not, we have to free it. */ |
c7d46a38 | 12561 | int found_object = 0; |
20874c92 VP |
12562 | /* Tells if the location should remain inserted in the target. */ |
12563 | int keep_in_target = 0; | |
12564 | int removed = 0; | |
876fa593 | 12565 | |
4a64f543 MS |
12566 | /* Skip LOCP entries which will definitely never be needed. |
12567 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12568 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12569 | && (*locp)->address < old_loc->address) |
876fa593 | 12570 | locp++; |
c7d46a38 PA |
12571 | |
12572 | for (loc2p = locp; | |
12573 | (loc2p < bp_location + bp_location_count | |
12574 | && (*loc2p)->address == old_loc->address); | |
12575 | loc2p++) | |
12576 | { | |
b775012e LM |
12577 | /* Check if this is a new/duplicated location or a duplicated |
12578 | location that had its condition modified. If so, we want to send | |
12579 | its condition to the target if evaluation of conditions is taking | |
12580 | place there. */ | |
12581 | if ((*loc2p)->condition_changed == condition_modified | |
12582 | && (last_addr != old_loc->address | |
12583 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12584 | { |
b775012e LM |
12585 | force_breakpoint_reinsertion (*loc2p); |
12586 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12587 | } |
b775012e LM |
12588 | |
12589 | if (*loc2p == old_loc) | |
12590 | found_object = 1; | |
c7d46a38 | 12591 | } |
74960c60 | 12592 | |
b775012e LM |
12593 | /* We have already handled this address, update it so that we don't |
12594 | have to go through updates again. */ | |
12595 | last_addr = old_loc->address; | |
12596 | ||
12597 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12598 | if (!found_object) | |
12599 | force_breakpoint_reinsertion (old_loc); | |
12600 | ||
4a64f543 MS |
12601 | /* If this location is no longer present, and inserted, look if |
12602 | there's maybe a new location at the same address. If so, | |
12603 | mark that one inserted, and don't remove this one. This is | |
12604 | needed so that we don't have a time window where a breakpoint | |
12605 | at certain location is not inserted. */ | |
74960c60 | 12606 | |
876fa593 | 12607 | if (old_loc->inserted) |
0d381245 | 12608 | { |
4a64f543 MS |
12609 | /* If the location is inserted now, we might have to remove |
12610 | it. */ | |
74960c60 | 12611 | |
876fa593 | 12612 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12613 | { |
4a64f543 MS |
12614 | /* The location is still present in the location list, |
12615 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12616 | keep_in_target = 1; |
74960c60 VP |
12617 | } |
12618 | else | |
12619 | { | |
b775012e LM |
12620 | /* This location still exists, but it won't be kept in the |
12621 | target since it may have been disabled. We proceed to | |
12622 | remove its target-side condition. */ | |
12623 | ||
4a64f543 MS |
12624 | /* The location is either no longer present, or got |
12625 | disabled. See if there's another location at the | |
12626 | same address, in which case we don't need to remove | |
12627 | this one from the target. */ | |
876fa593 | 12628 | |
2bdf28a0 | 12629 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12630 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12631 | { | |
876fa593 | 12632 | for (loc2p = locp; |
c7d46a38 PA |
12633 | (loc2p < bp_location + bp_location_count |
12634 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12635 | loc2p++) |
12636 | { | |
12637 | struct bp_location *loc2 = *loc2p; | |
12638 | ||
2d134ed3 | 12639 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12640 | { |
85d721b8 PA |
12641 | /* Read watchpoint locations are switched to |
12642 | access watchpoints, if the former are not | |
12643 | supported, but the latter are. */ | |
12644 | if (is_hardware_watchpoint (old_loc->owner)) | |
12645 | { | |
12646 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12647 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12648 | } | |
12649 | ||
934709f0 PW |
12650 | /* loc2 is a duplicated location. We need to check |
12651 | if it should be inserted in case it will be | |
12652 | unduplicated. */ | |
12653 | if (loc2 != old_loc | |
12654 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12655 | { |
934709f0 | 12656 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12657 | keep_in_target = 1; |
12658 | break; | |
12659 | } | |
876fa593 JK |
12660 | } |
12661 | } | |
12662 | } | |
74960c60 VP |
12663 | } |
12664 | ||
20874c92 VP |
12665 | if (!keep_in_target) |
12666 | { | |
876fa593 | 12667 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12668 | { |
4a64f543 MS |
12669 | /* This is just about all we can do. We could keep |
12670 | this location on the global list, and try to | |
12671 | remove it next time, but there's no particular | |
12672 | reason why we will succeed next time. | |
20874c92 | 12673 | |
4a64f543 MS |
12674 | Note that at this point, old_loc->owner is still |
12675 | valid, as delete_breakpoint frees the breakpoint | |
12676 | only after calling us. */ | |
3e43a32a MS |
12677 | printf_filtered (_("warning: Error removing " |
12678 | "breakpoint %d\n"), | |
876fa593 | 12679 | old_loc->owner->number); |
20874c92 VP |
12680 | } |
12681 | removed = 1; | |
12682 | } | |
0d381245 | 12683 | } |
74960c60 VP |
12684 | |
12685 | if (!found_object) | |
1c5cfe86 | 12686 | { |
db82e815 PA |
12687 | if (removed && non_stop |
12688 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12689 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12690 | { |
db82e815 PA |
12691 | /* This location was removed from the target. In |
12692 | non-stop mode, a race condition is possible where | |
12693 | we've removed a breakpoint, but stop events for that | |
12694 | breakpoint are already queued and will arrive later. | |
12695 | We apply an heuristic to be able to distinguish such | |
12696 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12697 | breakpoint location for a bit, and will retire it | |
12698 | after we see some number of events. The theory here | |
12699 | is that reporting of events should, "on the average", | |
12700 | be fair, so after a while we'll see events from all | |
12701 | threads that have anything of interest, and no longer | |
12702 | need to keep this breakpoint location around. We | |
12703 | don't hold locations forever so to reduce chances of | |
12704 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12705 | SIGTRAP. | |
12706 | ||
12707 | The heuristic failing can be disastrous on | |
12708 | decr_pc_after_break targets. | |
12709 | ||
12710 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12711 | if we fail to recognize a late breakpoint SIGTRAP, | |
12712 | because events_till_retirement has reached 0 too | |
12713 | soon, we'll fail to do the PC adjustment, and report | |
12714 | a random SIGTRAP to the user. When the user resumes | |
12715 | the inferior, it will most likely immediately crash | |
2dec564e | 12716 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12717 | corrupted, because of being resumed e.g., in the |
12718 | middle of a multi-byte instruction, or skipped a | |
12719 | one-byte instruction. This was actually seen happen | |
12720 | on native x86-linux, and should be less rare on | |
12721 | targets that do not support new thread events, like | |
12722 | remote, due to the heuristic depending on | |
12723 | thread_count. | |
12724 | ||
12725 | Mistaking a random SIGTRAP for a breakpoint trap | |
12726 | causes similar symptoms (PC adjustment applied when | |
12727 | it shouldn't), but then again, playing with SIGTRAPs | |
12728 | behind the debugger's back is asking for trouble. | |
12729 | ||
12730 | Since hardware watchpoint traps are always | |
12731 | distinguishable from other traps, so we don't need to | |
12732 | apply keep hardware watchpoint moribund locations | |
12733 | around. We simply always ignore hardware watchpoint | |
12734 | traps we can no longer explain. */ | |
12735 | ||
876fa593 JK |
12736 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12737 | old_loc->owner = NULL; | |
20874c92 | 12738 | |
876fa593 | 12739 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12740 | } |
12741 | else | |
f431efe5 PA |
12742 | { |
12743 | old_loc->owner = NULL; | |
12744 | decref_bp_location (&old_loc); | |
12745 | } | |
20874c92 | 12746 | } |
74960c60 | 12747 | } |
1c5cfe86 | 12748 | |
348d480f PA |
12749 | /* Rescan breakpoints at the same address and section, marking the |
12750 | first one as "first" and any others as "duplicates". This is so | |
12751 | that the bpt instruction is only inserted once. If we have a | |
12752 | permanent breakpoint at the same place as BPT, make that one the | |
12753 | official one, and the rest as duplicates. Permanent breakpoints | |
12754 | are sorted first for the same address. | |
12755 | ||
12756 | Do the same for hardware watchpoints, but also considering the | |
12757 | watchpoint's type (regular/access/read) and length. */ | |
12758 | ||
12759 | bp_loc_first = NULL; | |
12760 | wp_loc_first = NULL; | |
12761 | awp_loc_first = NULL; | |
12762 | rwp_loc_first = NULL; | |
12763 | ALL_BP_LOCATIONS (loc, locp) | |
12764 | { | |
12765 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12766 | non-NULL. */ | |
348d480f | 12767 | struct bp_location **loc_first_p; |
d3fbdd86 | 12768 | b = loc->owner; |
348d480f | 12769 | |
6f380991 | 12770 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12771 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12772 | /* Don't detect duplicate for tracepoint locations because they are |
12773 | never duplicated. See the comments in field `duplicate' of | |
12774 | `struct bp_location'. */ | |
348d480f | 12775 | || is_tracepoint (b)) |
b775012e LM |
12776 | { |
12777 | /* Clear the condition modification flag. */ | |
12778 | loc->condition_changed = condition_unchanged; | |
12779 | continue; | |
12780 | } | |
348d480f PA |
12781 | |
12782 | /* Permanent breakpoint should always be inserted. */ | |
12783 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12784 | internal_error (__FILE__, __LINE__, | |
12785 | _("allegedly permanent breakpoint is not " | |
12786 | "actually inserted")); | |
12787 | ||
12788 | if (b->type == bp_hardware_watchpoint) | |
12789 | loc_first_p = &wp_loc_first; | |
12790 | else if (b->type == bp_read_watchpoint) | |
12791 | loc_first_p = &rwp_loc_first; | |
12792 | else if (b->type == bp_access_watchpoint) | |
12793 | loc_first_p = &awp_loc_first; | |
12794 | else | |
12795 | loc_first_p = &bp_loc_first; | |
12796 | ||
12797 | if (*loc_first_p == NULL | |
12798 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12799 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12800 | { | |
12801 | *loc_first_p = loc; | |
12802 | loc->duplicate = 0; | |
b775012e LM |
12803 | |
12804 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12805 | { | |
12806 | loc->needs_update = 1; | |
12807 | /* Clear the condition modification flag. */ | |
12808 | loc->condition_changed = condition_unchanged; | |
12809 | } | |
348d480f PA |
12810 | continue; |
12811 | } | |
12812 | ||
934709f0 PW |
12813 | |
12814 | /* This and the above ensure the invariant that the first location | |
12815 | is not duplicated, and is the inserted one. | |
12816 | All following are marked as duplicated, and are not inserted. */ | |
12817 | if (loc->inserted) | |
12818 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12819 | loc->duplicate = 1; |
12820 | ||
b775012e LM |
12821 | /* Clear the condition modification flag. */ |
12822 | loc->condition_changed = condition_unchanged; | |
12823 | ||
348d480f PA |
12824 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12825 | && b->enable_state != bp_permanent) | |
12826 | internal_error (__FILE__, __LINE__, | |
12827 | _("another breakpoint was inserted on top of " | |
12828 | "a permanent breakpoint")); | |
12829 | } | |
12830 | ||
b775012e | 12831 | if (breakpoints_always_inserted_mode () |
348d480f | 12832 | && (have_live_inferiors () |
f5656ead | 12833 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12834 | { |
12835 | if (should_insert) | |
12836 | insert_breakpoint_locations (); | |
12837 | else | |
12838 | { | |
12839 | /* Though should_insert is false, we may need to update conditions | |
12840 | on the target's side if it is evaluating such conditions. We | |
12841 | only update conditions for locations that are marked | |
12842 | "needs_update". */ | |
12843 | update_inserted_breakpoint_locations (); | |
12844 | } | |
12845 | } | |
348d480f | 12846 | |
1e4d1764 YQ |
12847 | if (should_insert) |
12848 | download_tracepoint_locations (); | |
12849 | ||
348d480f PA |
12850 | do_cleanups (cleanups); |
12851 | } | |
12852 | ||
12853 | void | |
12854 | breakpoint_retire_moribund (void) | |
12855 | { | |
12856 | struct bp_location *loc; | |
12857 | int ix; | |
12858 | ||
12859 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12860 | if (--(loc->events_till_retirement) == 0) | |
12861 | { | |
12862 | decref_bp_location (&loc); | |
12863 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12864 | --ix; | |
12865 | } | |
12866 | } | |
12867 | ||
12868 | static void | |
12869 | update_global_location_list_nothrow (int inserting) | |
12870 | { | |
bfd189b1 | 12871 | volatile struct gdb_exception e; |
348d480f PA |
12872 | |
12873 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12874 | update_global_location_list (inserting); | |
12875 | } | |
12876 | ||
12877 | /* Clear BKP from a BPS. */ | |
12878 | ||
12879 | static void | |
12880 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12881 | { | |
12882 | bpstat bs; | |
12883 | ||
12884 | for (bs = bps; bs; bs = bs->next) | |
12885 | if (bs->breakpoint_at == bpt) | |
12886 | { | |
12887 | bs->breakpoint_at = NULL; | |
12888 | bs->old_val = NULL; | |
12889 | /* bs->commands will be freed later. */ | |
12890 | } | |
12891 | } | |
12892 | ||
12893 | /* Callback for iterate_over_threads. */ | |
12894 | static int | |
12895 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12896 | { | |
12897 | struct breakpoint *bpt = data; | |
12898 | ||
12899 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12900 | return 0; | |
12901 | } | |
12902 | ||
12903 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12904 | callbacks. */ | |
12905 | ||
12906 | static void | |
12907 | say_where (struct breakpoint *b) | |
12908 | { | |
12909 | struct value_print_options opts; | |
12910 | ||
12911 | get_user_print_options (&opts); | |
12912 | ||
12913 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12914 | single string. */ | |
12915 | if (b->loc == NULL) | |
12916 | { | |
12917 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12918 | } | |
12919 | else | |
12920 | { | |
2f202fde | 12921 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12922 | { |
12923 | printf_filtered (" at "); | |
12924 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12925 | gdb_stdout); | |
12926 | } | |
2f202fde | 12927 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12928 | { |
12929 | /* If there is a single location, we can print the location | |
12930 | more nicely. */ | |
12931 | if (b->loc->next == NULL) | |
12932 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12933 | symtab_to_filename_for_display (b->loc->symtab), |
12934 | b->loc->line_number); | |
f8eba3c6 TT |
12935 | else |
12936 | /* This is not ideal, but each location may have a | |
12937 | different file name, and this at least reflects the | |
12938 | real situation somewhat. */ | |
12939 | printf_filtered (": %s.", b->addr_string); | |
12940 | } | |
348d480f PA |
12941 | |
12942 | if (b->loc->next) | |
12943 | { | |
12944 | struct bp_location *loc = b->loc; | |
12945 | int n = 0; | |
12946 | for (; loc; loc = loc->next) | |
12947 | ++n; | |
12948 | printf_filtered (" (%d locations)", n); | |
12949 | } | |
12950 | } | |
12951 | } | |
12952 | ||
348d480f PA |
12953 | /* Default bp_location_ops methods. */ |
12954 | ||
12955 | static void | |
12956 | bp_location_dtor (struct bp_location *self) | |
12957 | { | |
12958 | xfree (self->cond); | |
b775012e LM |
12959 | if (self->cond_bytecode) |
12960 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12961 | xfree (self->function_name); |
8b4f3082 PA |
12962 | |
12963 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12964 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12965 | } |
12966 | ||
12967 | static const struct bp_location_ops bp_location_ops = | |
12968 | { | |
12969 | bp_location_dtor | |
12970 | }; | |
12971 | ||
2060206e PA |
12972 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12973 | inherit from. */ | |
348d480f | 12974 | |
2060206e PA |
12975 | static void |
12976 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12977 | { |
12978 | decref_counted_command_line (&self->commands); | |
12979 | xfree (self->cond_string); | |
fb81d016 | 12980 | xfree (self->extra_string); |
348d480f | 12981 | xfree (self->addr_string); |
f8eba3c6 | 12982 | xfree (self->filter); |
348d480f | 12983 | xfree (self->addr_string_range_end); |
348d480f PA |
12984 | } |
12985 | ||
2060206e PA |
12986 | static struct bp_location * |
12987 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12988 | { |
12989 | struct bp_location *loc; | |
12990 | ||
12991 | loc = XNEW (struct bp_location); | |
12992 | init_bp_location (loc, &bp_location_ops, self); | |
12993 | return loc; | |
12994 | } | |
12995 | ||
2060206e PA |
12996 | static void |
12997 | base_breakpoint_re_set (struct breakpoint *b) | |
12998 | { | |
12999 | /* Nothing to re-set. */ | |
13000 | } | |
13001 | ||
13002 | #define internal_error_pure_virtual_called() \ | |
13003 | gdb_assert_not_reached ("pure virtual function called") | |
13004 | ||
13005 | static int | |
13006 | base_breakpoint_insert_location (struct bp_location *bl) | |
13007 | { | |
13008 | internal_error_pure_virtual_called (); | |
13009 | } | |
13010 | ||
13011 | static int | |
13012 | base_breakpoint_remove_location (struct bp_location *bl) | |
13013 | { | |
13014 | internal_error_pure_virtual_called (); | |
13015 | } | |
13016 | ||
13017 | static int | |
13018 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
13019 | struct address_space *aspace, | |
09ac7c10 TT |
13020 | CORE_ADDR bp_addr, |
13021 | const struct target_waitstatus *ws) | |
2060206e PA |
13022 | { |
13023 | internal_error_pure_virtual_called (); | |
13024 | } | |
13025 | ||
13026 | static void | |
13027 | base_breakpoint_check_status (bpstat bs) | |
13028 | { | |
13029 | /* Always stop. */ | |
13030 | } | |
13031 | ||
13032 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
13033 | errors. */ | |
13034 | ||
13035 | static int | |
13036 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13037 | { | |
13038 | internal_error_pure_virtual_called (); | |
13039 | } | |
13040 | ||
13041 | /* A "resources_needed" breakpoint_ops method that just internal | |
13042 | errors. */ | |
13043 | ||
13044 | static int | |
13045 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13046 | { | |
13047 | internal_error_pure_virtual_called (); | |
13048 | } | |
13049 | ||
13050 | static enum print_stop_action | |
13051 | base_breakpoint_print_it (bpstat bs) | |
13052 | { | |
13053 | internal_error_pure_virtual_called (); | |
13054 | } | |
13055 | ||
13056 | static void | |
13057 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13058 | struct ui_out *uiout) | |
13059 | { | |
13060 | /* nothing */ | |
13061 | } | |
13062 | ||
13063 | static void | |
13064 | base_breakpoint_print_mention (struct breakpoint *b) | |
13065 | { | |
13066 | internal_error_pure_virtual_called (); | |
13067 | } | |
13068 | ||
13069 | static void | |
13070 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13071 | { | |
13072 | internal_error_pure_virtual_called (); | |
13073 | } | |
13074 | ||
983af33b SDJ |
13075 | static void |
13076 | base_breakpoint_create_sals_from_address (char **arg, | |
13077 | struct linespec_result *canonical, | |
13078 | enum bptype type_wanted, | |
13079 | char *addr_start, | |
13080 | char **copy_arg) | |
13081 | { | |
13082 | internal_error_pure_virtual_called (); | |
13083 | } | |
13084 | ||
13085 | static void | |
13086 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13087 | struct linespec_result *c, | |
983af33b | 13088 | char *cond_string, |
e7e0cddf | 13089 | char *extra_string, |
983af33b SDJ |
13090 | enum bptype type_wanted, |
13091 | enum bpdisp disposition, | |
13092 | int thread, | |
13093 | int task, int ignore_count, | |
13094 | const struct breakpoint_ops *o, | |
13095 | int from_tty, int enabled, | |
44f238bb | 13096 | int internal, unsigned flags) |
983af33b SDJ |
13097 | { |
13098 | internal_error_pure_virtual_called (); | |
13099 | } | |
13100 | ||
13101 | static void | |
13102 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
13103 | struct symtabs_and_lines *sals) | |
13104 | { | |
13105 | internal_error_pure_virtual_called (); | |
13106 | } | |
13107 | ||
ab04a2af TT |
13108 | /* The default 'explains_signal' method. */ |
13109 | ||
47591c29 | 13110 | static int |
427cd150 | 13111 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13112 | { |
47591c29 | 13113 | return 1; |
ab04a2af TT |
13114 | } |
13115 | ||
9d6e6e84 HZ |
13116 | /* The default "after_condition_true" method. */ |
13117 | ||
13118 | static void | |
13119 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13120 | { | |
13121 | /* Nothing to do. */ | |
13122 | } | |
13123 | ||
ab04a2af | 13124 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13125 | { |
13126 | base_breakpoint_dtor, | |
13127 | base_breakpoint_allocate_location, | |
13128 | base_breakpoint_re_set, | |
13129 | base_breakpoint_insert_location, | |
13130 | base_breakpoint_remove_location, | |
13131 | base_breakpoint_breakpoint_hit, | |
13132 | base_breakpoint_check_status, | |
13133 | base_breakpoint_resources_needed, | |
13134 | base_breakpoint_works_in_software_mode, | |
13135 | base_breakpoint_print_it, | |
13136 | NULL, | |
13137 | base_breakpoint_print_one_detail, | |
13138 | base_breakpoint_print_mention, | |
983af33b SDJ |
13139 | base_breakpoint_print_recreate, |
13140 | base_breakpoint_create_sals_from_address, | |
13141 | base_breakpoint_create_breakpoints_sal, | |
13142 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
13143 | base_breakpoint_explains_signal, |
13144 | base_breakpoint_after_condition_true, | |
2060206e PA |
13145 | }; |
13146 | ||
13147 | /* Default breakpoint_ops methods. */ | |
13148 | ||
13149 | static void | |
348d480f PA |
13150 | bkpt_re_set (struct breakpoint *b) |
13151 | { | |
06edf0c0 PA |
13152 | /* FIXME: is this still reachable? */ |
13153 | if (b->addr_string == NULL) | |
13154 | { | |
13155 | /* Anything without a string can't be re-set. */ | |
348d480f | 13156 | delete_breakpoint (b); |
06edf0c0 | 13157 | return; |
348d480f | 13158 | } |
06edf0c0 PA |
13159 | |
13160 | breakpoint_re_set_default (b); | |
348d480f PA |
13161 | } |
13162 | ||
ef370185 JB |
13163 | /* Copy SRC's shadow buffer and whatever else we'd set if we actually |
13164 | inserted DEST, so we can remove it later, in case SRC is removed | |
13165 | first. */ | |
13166 | ||
13167 | static void | |
13168 | bp_target_info_copy_insertion_state (struct bp_target_info *dest, | |
13169 | const struct bp_target_info *src) | |
13170 | { | |
13171 | dest->shadow_len = src->shadow_len; | |
13172 | memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len); | |
13173 | dest->placed_size = src->placed_size; | |
13174 | } | |
13175 | ||
2060206e | 13176 | static int |
348d480f PA |
13177 | bkpt_insert_location (struct bp_location *bl) |
13178 | { | |
13179 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13180 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13181 | &bl->target_info); | |
13182 | else | |
ef370185 JB |
13183 | { |
13184 | struct bp_target_info *bp_tgt = &bl->target_info; | |
13185 | int ret; | |
13186 | int sss_slot; | |
13187 | ||
13188 | /* There is no need to insert a breakpoint if an unconditional | |
13189 | raw/sss breakpoint is already inserted at that location. */ | |
13190 | sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space, | |
13191 | bp_tgt->placed_address); | |
13192 | if (sss_slot >= 0) | |
13193 | { | |
13194 | struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot]; | |
13195 | ||
13196 | bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt); | |
13197 | return 0; | |
13198 | } | |
13199 | ||
13200 | return target_insert_breakpoint (bl->gdbarch, bp_tgt); | |
13201 | } | |
348d480f PA |
13202 | } |
13203 | ||
2060206e | 13204 | static int |
348d480f PA |
13205 | bkpt_remove_location (struct bp_location *bl) |
13206 | { | |
13207 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13208 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13209 | else | |
ef370185 JB |
13210 | { |
13211 | struct bp_target_info *bp_tgt = &bl->target_info; | |
13212 | struct address_space *aspace = bp_tgt->placed_address_space; | |
13213 | CORE_ADDR address = bp_tgt->placed_address; | |
13214 | ||
13215 | /* Only remove the breakpoint if there is no raw/sss breakpoint | |
13216 | still inserted at this location. Otherwise, we would be | |
13217 | effectively disabling the raw/sss breakpoint. */ | |
13218 | if (single_step_breakpoint_inserted_here_p (aspace, address)) | |
13219 | return 0; | |
13220 | ||
13221 | return target_remove_breakpoint (bl->gdbarch, bp_tgt); | |
13222 | } | |
348d480f PA |
13223 | } |
13224 | ||
2060206e | 13225 | static int |
348d480f | 13226 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13227 | struct address_space *aspace, CORE_ADDR bp_addr, |
13228 | const struct target_waitstatus *ws) | |
348d480f | 13229 | { |
09ac7c10 | 13230 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13231 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13232 | return 0; |
13233 | ||
348d480f PA |
13234 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13235 | aspace, bp_addr)) | |
13236 | return 0; | |
13237 | ||
13238 | if (overlay_debugging /* unmapped overlay section */ | |
13239 | && section_is_overlay (bl->section) | |
13240 | && !section_is_mapped (bl->section)) | |
13241 | return 0; | |
13242 | ||
13243 | return 1; | |
13244 | } | |
13245 | ||
cd1608cc PA |
13246 | static int |
13247 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13248 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13249 | const struct target_waitstatus *ws) | |
13250 | { | |
13251 | if (dprintf_style == dprintf_style_agent | |
13252 | && target_can_run_breakpoint_commands ()) | |
13253 | { | |
13254 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13255 | for this address it must be for a breakpoint that happens to | |
13256 | be set at the same address. */ | |
13257 | return 0; | |
13258 | } | |
13259 | ||
13260 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13261 | } | |
13262 | ||
2060206e | 13263 | static int |
348d480f PA |
13264 | bkpt_resources_needed (const struct bp_location *bl) |
13265 | { | |
13266 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13267 | ||
13268 | return 1; | |
13269 | } | |
13270 | ||
2060206e | 13271 | static enum print_stop_action |
348d480f PA |
13272 | bkpt_print_it (bpstat bs) |
13273 | { | |
348d480f PA |
13274 | struct breakpoint *b; |
13275 | const struct bp_location *bl; | |
001c8c33 | 13276 | int bp_temp; |
79a45e25 | 13277 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13278 | |
13279 | gdb_assert (bs->bp_location_at != NULL); | |
13280 | ||
13281 | bl = bs->bp_location_at; | |
13282 | b = bs->breakpoint_at; | |
13283 | ||
001c8c33 PA |
13284 | bp_temp = b->disposition == disp_del; |
13285 | if (bl->address != bl->requested_address) | |
13286 | breakpoint_adjustment_warning (bl->requested_address, | |
13287 | bl->address, | |
13288 | b->number, 1); | |
13289 | annotate_breakpoint (b->number); | |
13290 | if (bp_temp) | |
13291 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13292 | else | |
13293 | ui_out_text (uiout, "\nBreakpoint "); | |
13294 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13295 | { |
001c8c33 PA |
13296 | ui_out_field_string (uiout, "reason", |
13297 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13298 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13299 | } |
001c8c33 PA |
13300 | ui_out_field_int (uiout, "bkptno", b->number); |
13301 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13302 | |
001c8c33 | 13303 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13304 | } |
13305 | ||
2060206e | 13306 | static void |
06edf0c0 PA |
13307 | bkpt_print_mention (struct breakpoint *b) |
13308 | { | |
79a45e25 | 13309 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13310 | return; |
13311 | ||
13312 | switch (b->type) | |
13313 | { | |
13314 | case bp_breakpoint: | |
13315 | case bp_gnu_ifunc_resolver: | |
13316 | if (b->disposition == disp_del) | |
13317 | printf_filtered (_("Temporary breakpoint")); | |
13318 | else | |
13319 | printf_filtered (_("Breakpoint")); | |
13320 | printf_filtered (_(" %d"), b->number); | |
13321 | if (b->type == bp_gnu_ifunc_resolver) | |
13322 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13323 | break; | |
13324 | case bp_hardware_breakpoint: | |
13325 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13326 | break; | |
e7e0cddf SS |
13327 | case bp_dprintf: |
13328 | printf_filtered (_("Dprintf %d"), b->number); | |
13329 | break; | |
06edf0c0 PA |
13330 | } |
13331 | ||
13332 | say_where (b); | |
13333 | } | |
13334 | ||
2060206e | 13335 | static void |
06edf0c0 PA |
13336 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13337 | { | |
13338 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13339 | fprintf_unfiltered (fp, "tbreak"); | |
13340 | else if (tp->type == bp_breakpoint) | |
13341 | fprintf_unfiltered (fp, "break"); | |
13342 | else if (tp->type == bp_hardware_breakpoint | |
13343 | && tp->disposition == disp_del) | |
13344 | fprintf_unfiltered (fp, "thbreak"); | |
13345 | else if (tp->type == bp_hardware_breakpoint) | |
13346 | fprintf_unfiltered (fp, "hbreak"); | |
13347 | else | |
13348 | internal_error (__FILE__, __LINE__, | |
13349 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13350 | ||
2060206e | 13351 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13352 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13353 | } |
13354 | ||
983af33b SDJ |
13355 | static void |
13356 | bkpt_create_sals_from_address (char **arg, | |
13357 | struct linespec_result *canonical, | |
13358 | enum bptype type_wanted, | |
13359 | char *addr_start, char **copy_arg) | |
13360 | { | |
13361 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13362 | addr_start, copy_arg); | |
13363 | } | |
13364 | ||
13365 | static void | |
13366 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13367 | struct linespec_result *canonical, | |
983af33b | 13368 | char *cond_string, |
e7e0cddf | 13369 | char *extra_string, |
983af33b SDJ |
13370 | enum bptype type_wanted, |
13371 | enum bpdisp disposition, | |
13372 | int thread, | |
13373 | int task, int ignore_count, | |
13374 | const struct breakpoint_ops *ops, | |
13375 | int from_tty, int enabled, | |
44f238bb | 13376 | int internal, unsigned flags) |
983af33b | 13377 | { |
023fa29b | 13378 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13379 | cond_string, extra_string, |
13380 | type_wanted, | |
983af33b SDJ |
13381 | disposition, thread, task, |
13382 | ignore_count, ops, from_tty, | |
44f238bb | 13383 | enabled, internal, flags); |
983af33b SDJ |
13384 | } |
13385 | ||
13386 | static void | |
13387 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13388 | struct symtabs_and_lines *sals) | |
13389 | { | |
13390 | decode_linespec_default (b, s, sals); | |
13391 | } | |
13392 | ||
06edf0c0 PA |
13393 | /* Virtual table for internal breakpoints. */ |
13394 | ||
13395 | static void | |
13396 | internal_bkpt_re_set (struct breakpoint *b) | |
13397 | { | |
13398 | switch (b->type) | |
13399 | { | |
13400 | /* Delete overlay event and longjmp master breakpoints; they | |
13401 | will be reset later by breakpoint_re_set. */ | |
13402 | case bp_overlay_event: | |
13403 | case bp_longjmp_master: | |
13404 | case bp_std_terminate_master: | |
13405 | case bp_exception_master: | |
13406 | delete_breakpoint (b); | |
13407 | break; | |
13408 | ||
13409 | /* This breakpoint is special, it's set up when the inferior | |
13410 | starts and we really don't want to touch it. */ | |
13411 | case bp_shlib_event: | |
13412 | ||
13413 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13414 | it is set up, we do not want to touch it. */ | |
13415 | case bp_thread_event: | |
13416 | break; | |
13417 | } | |
13418 | } | |
13419 | ||
13420 | static void | |
13421 | internal_bkpt_check_status (bpstat bs) | |
13422 | { | |
a9b3a50f PA |
13423 | if (bs->breakpoint_at->type == bp_shlib_event) |
13424 | { | |
13425 | /* If requested, stop when the dynamic linker notifies GDB of | |
13426 | events. This allows the user to get control and place | |
13427 | breakpoints in initializer routines for dynamically loaded | |
13428 | objects (among other things). */ | |
13429 | bs->stop = stop_on_solib_events; | |
13430 | bs->print = stop_on_solib_events; | |
13431 | } | |
13432 | else | |
13433 | bs->stop = 0; | |
06edf0c0 PA |
13434 | } |
13435 | ||
13436 | static enum print_stop_action | |
13437 | internal_bkpt_print_it (bpstat bs) | |
13438 | { | |
06edf0c0 | 13439 | struct breakpoint *b; |
06edf0c0 | 13440 | |
06edf0c0 PA |
13441 | b = bs->breakpoint_at; |
13442 | ||
06edf0c0 PA |
13443 | switch (b->type) |
13444 | { | |
348d480f PA |
13445 | case bp_shlib_event: |
13446 | /* Did we stop because the user set the stop_on_solib_events | |
13447 | variable? (If so, we report this as a generic, "Stopped due | |
13448 | to shlib event" message.) */ | |
edcc5120 | 13449 | print_solib_event (0); |
348d480f PA |
13450 | break; |
13451 | ||
13452 | case bp_thread_event: | |
13453 | /* Not sure how we will get here. | |
13454 | GDB should not stop for these breakpoints. */ | |
13455 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13456 | break; |
13457 | ||
13458 | case bp_overlay_event: | |
13459 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13460 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13461 | break; |
13462 | ||
13463 | case bp_longjmp_master: | |
13464 | /* These should never be enabled. */ | |
13465 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13466 | break; |
13467 | ||
13468 | case bp_std_terminate_master: | |
13469 | /* These should never be enabled. */ | |
13470 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13471 | "gdb should not stop!\n")); | |
348d480f PA |
13472 | break; |
13473 | ||
13474 | case bp_exception_master: | |
13475 | /* These should never be enabled. */ | |
13476 | printf_filtered (_("Exception Master Breakpoint: " | |
13477 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13478 | break; |
13479 | } | |
13480 | ||
001c8c33 | 13481 | return PRINT_NOTHING; |
06edf0c0 PA |
13482 | } |
13483 | ||
13484 | static void | |
13485 | internal_bkpt_print_mention (struct breakpoint *b) | |
13486 | { | |
13487 | /* Nothing to mention. These breakpoints are internal. */ | |
13488 | } | |
13489 | ||
06edf0c0 PA |
13490 | /* Virtual table for momentary breakpoints */ |
13491 | ||
13492 | static void | |
13493 | momentary_bkpt_re_set (struct breakpoint *b) | |
13494 | { | |
13495 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13496 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13497 | Otherwise these should have been blown away via the cleanup chain |
13498 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13499 | } | |
13500 | ||
13501 | static void | |
13502 | momentary_bkpt_check_status (bpstat bs) | |
13503 | { | |
13504 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13505 | } | |
13506 | ||
13507 | static enum print_stop_action | |
13508 | momentary_bkpt_print_it (bpstat bs) | |
13509 | { | |
79a45e25 PA |
13510 | struct ui_out *uiout = current_uiout; |
13511 | ||
001c8c33 | 13512 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13513 | { |
001c8c33 | 13514 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13515 | |
001c8c33 PA |
13516 | switch (b->type) |
13517 | { | |
13518 | case bp_finish: | |
13519 | ui_out_field_string | |
13520 | (uiout, "reason", | |
13521 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13522 | break; | |
348d480f | 13523 | |
001c8c33 PA |
13524 | case bp_until: |
13525 | ui_out_field_string | |
13526 | (uiout, "reason", | |
13527 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13528 | break; | |
13529 | } | |
348d480f PA |
13530 | } |
13531 | ||
001c8c33 | 13532 | return PRINT_UNKNOWN; |
348d480f PA |
13533 | } |
13534 | ||
06edf0c0 PA |
13535 | static void |
13536 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13537 | { |
06edf0c0 | 13538 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13539 | } |
13540 | ||
e2e4d78b JK |
13541 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13542 | ||
13543 | It gets cleared already on the removal of the first one of such placed | |
13544 | breakpoints. This is OK as they get all removed altogether. */ | |
13545 | ||
13546 | static void | |
13547 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13548 | { | |
13549 | struct thread_info *tp = find_thread_id (self->thread); | |
13550 | ||
13551 | if (tp) | |
13552 | tp->initiating_frame = null_frame_id; | |
13553 | ||
13554 | momentary_breakpoint_ops.dtor (self); | |
13555 | } | |
13556 | ||
55aa24fb SDJ |
13557 | /* Specific methods for probe breakpoints. */ |
13558 | ||
13559 | static int | |
13560 | bkpt_probe_insert_location (struct bp_location *bl) | |
13561 | { | |
13562 | int v = bkpt_insert_location (bl); | |
13563 | ||
13564 | if (v == 0) | |
13565 | { | |
13566 | /* The insertion was successful, now let's set the probe's semaphore | |
13567 | if needed. */ | |
729662a5 TT |
13568 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
13569 | bl->probe.objfile, | |
13570 | bl->gdbarch); | |
55aa24fb SDJ |
13571 | } |
13572 | ||
13573 | return v; | |
13574 | } | |
13575 | ||
13576 | static int | |
13577 | bkpt_probe_remove_location (struct bp_location *bl) | |
13578 | { | |
13579 | /* Let's clear the semaphore before removing the location. */ | |
729662a5 TT |
13580 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
13581 | bl->probe.objfile, | |
13582 | bl->gdbarch); | |
55aa24fb SDJ |
13583 | |
13584 | return bkpt_remove_location (bl); | |
13585 | } | |
13586 | ||
13587 | static void | |
13588 | bkpt_probe_create_sals_from_address (char **arg, | |
13589 | struct linespec_result *canonical, | |
13590 | enum bptype type_wanted, | |
13591 | char *addr_start, char **copy_arg) | |
13592 | { | |
13593 | struct linespec_sals lsal; | |
13594 | ||
13595 | lsal.sals = parse_probes (arg, canonical); | |
13596 | ||
13597 | *copy_arg = xstrdup (canonical->addr_string); | |
13598 | lsal.canonical = xstrdup (*copy_arg); | |
13599 | ||
13600 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13601 | } | |
13602 | ||
13603 | static void | |
13604 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13605 | struct symtabs_and_lines *sals) | |
13606 | { | |
13607 | *sals = parse_probes (s, NULL); | |
13608 | if (!sals->sals) | |
13609 | error (_("probe not found")); | |
13610 | } | |
13611 | ||
348d480f | 13612 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13613 | |
348d480f PA |
13614 | static void |
13615 | tracepoint_re_set (struct breakpoint *b) | |
13616 | { | |
13617 | breakpoint_re_set_default (b); | |
13618 | } | |
876fa593 | 13619 | |
348d480f PA |
13620 | static int |
13621 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13622 | struct address_space *aspace, CORE_ADDR bp_addr, |
13623 | const struct target_waitstatus *ws) | |
348d480f PA |
13624 | { |
13625 | /* By definition, the inferior does not report stops at | |
13626 | tracepoints. */ | |
13627 | return 0; | |
74960c60 VP |
13628 | } |
13629 | ||
13630 | static void | |
348d480f PA |
13631 | tracepoint_print_one_detail (const struct breakpoint *self, |
13632 | struct ui_out *uiout) | |
74960c60 | 13633 | { |
d9b3f62e PA |
13634 | struct tracepoint *tp = (struct tracepoint *) self; |
13635 | if (tp->static_trace_marker_id) | |
348d480f PA |
13636 | { |
13637 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13638 | |
348d480f PA |
13639 | ui_out_text (uiout, "\tmarker id is "); |
13640 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13641 | tp->static_trace_marker_id); |
348d480f PA |
13642 | ui_out_text (uiout, "\n"); |
13643 | } | |
0d381245 VP |
13644 | } |
13645 | ||
a474d7c2 | 13646 | static void |
348d480f | 13647 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13648 | { |
79a45e25 | 13649 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13650 | return; |
cc59ec59 | 13651 | |
348d480f PA |
13652 | switch (b->type) |
13653 | { | |
13654 | case bp_tracepoint: | |
13655 | printf_filtered (_("Tracepoint")); | |
13656 | printf_filtered (_(" %d"), b->number); | |
13657 | break; | |
13658 | case bp_fast_tracepoint: | |
13659 | printf_filtered (_("Fast tracepoint")); | |
13660 | printf_filtered (_(" %d"), b->number); | |
13661 | break; | |
13662 | case bp_static_tracepoint: | |
13663 | printf_filtered (_("Static tracepoint")); | |
13664 | printf_filtered (_(" %d"), b->number); | |
13665 | break; | |
13666 | default: | |
13667 | internal_error (__FILE__, __LINE__, | |
13668 | _("unhandled tracepoint type %d"), (int) b->type); | |
13669 | } | |
13670 | ||
13671 | say_where (b); | |
a474d7c2 PA |
13672 | } |
13673 | ||
348d480f | 13674 | static void |
d9b3f62e | 13675 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13676 | { |
d9b3f62e PA |
13677 | struct tracepoint *tp = (struct tracepoint *) self; |
13678 | ||
13679 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13680 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13681 | if (self->type == bp_static_tracepoint) |
348d480f | 13682 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13683 | else if (self->type == bp_tracepoint) |
348d480f PA |
13684 | fprintf_unfiltered (fp, "trace"); |
13685 | else | |
13686 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13687 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13688 | |
d9b3f62e PA |
13689 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13690 | print_recreate_thread (self, fp); | |
13691 | ||
13692 | if (tp->pass_count) | |
13693 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13694 | } |
13695 | ||
983af33b SDJ |
13696 | static void |
13697 | tracepoint_create_sals_from_address (char **arg, | |
13698 | struct linespec_result *canonical, | |
13699 | enum bptype type_wanted, | |
13700 | char *addr_start, char **copy_arg) | |
13701 | { | |
13702 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13703 | addr_start, copy_arg); | |
13704 | } | |
13705 | ||
13706 | static void | |
13707 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13708 | struct linespec_result *canonical, | |
983af33b | 13709 | char *cond_string, |
e7e0cddf | 13710 | char *extra_string, |
983af33b SDJ |
13711 | enum bptype type_wanted, |
13712 | enum bpdisp disposition, | |
13713 | int thread, | |
13714 | int task, int ignore_count, | |
13715 | const struct breakpoint_ops *ops, | |
13716 | int from_tty, int enabled, | |
44f238bb | 13717 | int internal, unsigned flags) |
983af33b | 13718 | { |
023fa29b | 13719 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13720 | cond_string, extra_string, |
13721 | type_wanted, | |
983af33b SDJ |
13722 | disposition, thread, task, |
13723 | ignore_count, ops, from_tty, | |
44f238bb | 13724 | enabled, internal, flags); |
983af33b SDJ |
13725 | } |
13726 | ||
13727 | static void | |
13728 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13729 | struct symtabs_and_lines *sals) | |
13730 | { | |
13731 | decode_linespec_default (b, s, sals); | |
13732 | } | |
13733 | ||
2060206e | 13734 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13735 | |
55aa24fb SDJ |
13736 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13737 | static probe. */ | |
13738 | ||
13739 | static void | |
13740 | tracepoint_probe_create_sals_from_address (char **arg, | |
13741 | struct linespec_result *canonical, | |
13742 | enum bptype type_wanted, | |
13743 | char *addr_start, char **copy_arg) | |
13744 | { | |
13745 | /* We use the same method for breakpoint on probes. */ | |
13746 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13747 | addr_start, copy_arg); | |
13748 | } | |
13749 | ||
13750 | static void | |
13751 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13752 | struct symtabs_and_lines *sals) | |
13753 | { | |
13754 | /* We use the same method for breakpoint on probes. */ | |
13755 | bkpt_probe_decode_linespec (b, s, sals); | |
13756 | } | |
13757 | ||
13758 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13759 | ||
5c2b4418 HZ |
13760 | /* Dprintf breakpoint_ops methods. */ |
13761 | ||
13762 | static void | |
13763 | dprintf_re_set (struct breakpoint *b) | |
13764 | { | |
13765 | breakpoint_re_set_default (b); | |
13766 | ||
13767 | /* This breakpoint could have been pending, and be resolved now, and | |
13768 | if so, we should now have the extra string. If we don't, the | |
13769 | dprintf was malformed when created, but we couldn't tell because | |
13770 | we can't extract the extra string until the location is | |
13771 | resolved. */ | |
13772 | if (b->loc != NULL && b->extra_string == NULL) | |
13773 | error (_("Format string required")); | |
13774 | ||
13775 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13776 | 2 - create a dprintf, which resolves fine. | |
13777 | 3 - disconnect from target 1 | |
13778 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13779 | ||
13780 | After steps #3/#4, you'll want the dprintf command list to | |
13781 | be updated, because target 1 and 2 may well return different | |
13782 | answers for target_can_run_breakpoint_commands(). | |
13783 | Given absence of finer grained resetting, we get to do | |
13784 | it all the time. */ | |
13785 | if (b->extra_string != NULL) | |
13786 | update_dprintf_command_list (b); | |
13787 | } | |
13788 | ||
2d9442cc HZ |
13789 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13790 | ||
13791 | static void | |
13792 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13793 | { | |
13794 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13795 | tp->extra_string); | |
13796 | print_recreate_thread (tp, fp); | |
13797 | } | |
13798 | ||
9d6e6e84 HZ |
13799 | /* Implement the "after_condition_true" breakpoint_ops method for |
13800 | dprintf. | |
13801 | ||
13802 | dprintf's are implemented with regular commands in their command | |
13803 | list, but we run the commands here instead of before presenting the | |
13804 | stop to the user, as dprintf's don't actually cause a stop. This | |
13805 | also makes it so that the commands of multiple dprintfs at the same | |
13806 | address are all handled. */ | |
13807 | ||
13808 | static void | |
13809 | dprintf_after_condition_true (struct bpstats *bs) | |
13810 | { | |
13811 | struct cleanup *old_chain; | |
13812 | struct bpstats tmp_bs = { NULL }; | |
13813 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13814 | ||
13815 | /* dprintf's never cause a stop. This wasn't set in the | |
13816 | check_status hook instead because that would make the dprintf's | |
13817 | condition not be evaluated. */ | |
13818 | bs->stop = 0; | |
13819 | ||
13820 | /* Run the command list here. Take ownership of it instead of | |
13821 | copying. We never want these commands to run later in | |
13822 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13823 | be set at same address as this dprintf, or even if running the | |
13824 | commands here throws. */ | |
13825 | tmp_bs.commands = bs->commands; | |
13826 | bs->commands = NULL; | |
13827 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13828 | ||
13829 | bpstat_do_actions_1 (&tmp_bs_p); | |
13830 | ||
13831 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13832 | bpstat_do_actions_1 may return early without processing the whole | |
13833 | list. */ | |
13834 | do_cleanups (old_chain); | |
13835 | } | |
13836 | ||
983af33b SDJ |
13837 | /* The breakpoint_ops structure to be used on static tracepoints with |
13838 | markers (`-m'). */ | |
13839 | ||
13840 | static void | |
13841 | strace_marker_create_sals_from_address (char **arg, | |
13842 | struct linespec_result *canonical, | |
13843 | enum bptype type_wanted, | |
13844 | char *addr_start, char **copy_arg) | |
13845 | { | |
13846 | struct linespec_sals lsal; | |
13847 | ||
13848 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13849 | ||
13850 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13851 | ||
13852 | canonical->addr_string = xstrdup (*copy_arg); | |
13853 | lsal.canonical = xstrdup (*copy_arg); | |
13854 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13855 | } | |
13856 | ||
13857 | static void | |
13858 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13859 | struct linespec_result *canonical, | |
983af33b | 13860 | char *cond_string, |
e7e0cddf | 13861 | char *extra_string, |
983af33b SDJ |
13862 | enum bptype type_wanted, |
13863 | enum bpdisp disposition, | |
13864 | int thread, | |
13865 | int task, int ignore_count, | |
13866 | const struct breakpoint_ops *ops, | |
13867 | int from_tty, int enabled, | |
44f238bb | 13868 | int internal, unsigned flags) |
983af33b SDJ |
13869 | { |
13870 | int i; | |
52d361e1 YQ |
13871 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13872 | canonical->sals, 0); | |
983af33b SDJ |
13873 | |
13874 | /* If the user is creating a static tracepoint by marker id | |
13875 | (strace -m MARKER_ID), then store the sals index, so that | |
13876 | breakpoint_re_set can try to match up which of the newly | |
13877 | found markers corresponds to this one, and, don't try to | |
13878 | expand multiple locations for each sal, given than SALS | |
13879 | already should contain all sals for MARKER_ID. */ | |
13880 | ||
13881 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13882 | { | |
13883 | struct symtabs_and_lines expanded; | |
13884 | struct tracepoint *tp; | |
13885 | struct cleanup *old_chain; | |
13886 | char *addr_string; | |
13887 | ||
13888 | expanded.nelts = 1; | |
13889 | expanded.sals = &lsal->sals.sals[i]; | |
13890 | ||
13891 | addr_string = xstrdup (canonical->addr_string); | |
13892 | old_chain = make_cleanup (xfree, addr_string); | |
13893 | ||
13894 | tp = XCNEW (struct tracepoint); | |
13895 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13896 | addr_string, NULL, | |
e7e0cddf SS |
13897 | cond_string, extra_string, |
13898 | type_wanted, disposition, | |
983af33b | 13899 | thread, task, ignore_count, ops, |
44f238bb | 13900 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13901 | canonical->special_display); |
13902 | /* Given that its possible to have multiple markers with | |
13903 | the same string id, if the user is creating a static | |
13904 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13905 | store the sals index, so that breakpoint_re_set can | |
13906 | try to match up which of the newly found markers | |
13907 | corresponds to this one */ | |
13908 | tp->static_trace_marker_id_idx = i; | |
13909 | ||
13910 | install_breakpoint (internal, &tp->base, 0); | |
13911 | ||
13912 | discard_cleanups (old_chain); | |
13913 | } | |
13914 | } | |
13915 | ||
13916 | static void | |
13917 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13918 | struct symtabs_and_lines *sals) | |
13919 | { | |
13920 | struct tracepoint *tp = (struct tracepoint *) b; | |
13921 | ||
13922 | *sals = decode_static_tracepoint_spec (s); | |
13923 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13924 | { | |
13925 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13926 | sals->nelts = 1; | |
13927 | } | |
13928 | else | |
13929 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13930 | } | |
13931 | ||
13932 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13933 | ||
13934 | static int | |
13935 | strace_marker_p (struct breakpoint *b) | |
13936 | { | |
13937 | return b->ops == &strace_marker_breakpoint_ops; | |
13938 | } | |
13939 | ||
53a5351d | 13940 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13941 | structures. */ |
c906108c SS |
13942 | |
13943 | void | |
fba45db2 | 13944 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13945 | { |
52f0bd74 | 13946 | struct breakpoint *b; |
c906108c | 13947 | |
8a3fe4f8 | 13948 | gdb_assert (bpt != NULL); |
c906108c | 13949 | |
4a64f543 MS |
13950 | /* Has this bp already been deleted? This can happen because |
13951 | multiple lists can hold pointers to bp's. bpstat lists are | |
13952 | especial culprits. | |
13953 | ||
13954 | One example of this happening is a watchpoint's scope bp. When | |
13955 | the scope bp triggers, we notice that the watchpoint is out of | |
13956 | scope, and delete it. We also delete its scope bp. But the | |
13957 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13958 | That bpstat is then checked for auto-deleting bp's, which are | |
13959 | deleted. | |
13960 | ||
13961 | A real solution to this problem might involve reference counts in | |
13962 | bp's, and/or giving them pointers back to their referencing | |
13963 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13964 | storage when no more references were extent. A cheaper bandaid | |
13965 | was chosen. */ | |
c906108c SS |
13966 | if (bpt->type == bp_none) |
13967 | return; | |
13968 | ||
4a64f543 MS |
13969 | /* At least avoid this stale reference until the reference counting |
13970 | of breakpoints gets resolved. */ | |
d0fb5eae | 13971 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13972 | { |
d0fb5eae | 13973 | struct breakpoint *related; |
3a5c3e22 | 13974 | struct watchpoint *w; |
d0fb5eae JK |
13975 | |
13976 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13977 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13978 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13979 | w = (struct watchpoint *) bpt; |
13980 | else | |
13981 | w = NULL; | |
13982 | if (w != NULL) | |
13983 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13984 | |
13985 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13986 | for (related = bpt; related->related_breakpoint != bpt; | |
13987 | related = related->related_breakpoint); | |
13988 | related->related_breakpoint = bpt->related_breakpoint; | |
13989 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13990 | } |
13991 | ||
a9634178 TJB |
13992 | /* watch_command_1 creates a watchpoint but only sets its number if |
13993 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13994 | a problem in that process, we'll be asked to delete the half-created | |
13995 | watchpoint. In that case, don't announce the deletion. */ | |
13996 | if (bpt->number) | |
13997 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13998 | |
c906108c SS |
13999 | if (breakpoint_chain == bpt) |
14000 | breakpoint_chain = bpt->next; | |
14001 | ||
c906108c SS |
14002 | ALL_BREAKPOINTS (b) |
14003 | if (b->next == bpt) | |
c5aa993b JM |
14004 | { |
14005 | b->next = bpt->next; | |
14006 | break; | |
14007 | } | |
c906108c | 14008 | |
f431efe5 PA |
14009 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
14010 | been freed. */ | |
14011 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 14012 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
14013 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
14014 | commands are associated with the bpstat; if we remove it here, | |
14015 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
14016 | event-top.c won't do anything, and temporary breakpoints with | |
14017 | commands won't work. */ | |
14018 | ||
14019 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
14020 | ||
4a64f543 MS |
14021 | /* Now that breakpoint is removed from breakpoint list, update the |
14022 | global location list. This will remove locations that used to | |
14023 | belong to this breakpoint. Do this before freeing the breakpoint | |
14024 | itself, since remove_breakpoint looks at location's owner. It | |
14025 | might be better design to have location completely | |
14026 | self-contained, but it's not the case now. */ | |
b60e7edf | 14027 | update_global_location_list (0); |
74960c60 | 14028 | |
348d480f | 14029 | bpt->ops->dtor (bpt); |
4a64f543 MS |
14030 | /* On the chance that someone will soon try again to delete this |
14031 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 14032 | bpt->type = bp_none; |
b8c9b27d | 14033 | xfree (bpt); |
c906108c SS |
14034 | } |
14035 | ||
4d6140d9 AC |
14036 | static void |
14037 | do_delete_breakpoint_cleanup (void *b) | |
14038 | { | |
14039 | delete_breakpoint (b); | |
14040 | } | |
14041 | ||
14042 | struct cleanup * | |
14043 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
14044 | { | |
14045 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
14046 | } | |
14047 | ||
51be5b68 PA |
14048 | /* Iterator function to call a user-provided callback function once |
14049 | for each of B and its related breakpoints. */ | |
14050 | ||
14051 | static void | |
14052 | iterate_over_related_breakpoints (struct breakpoint *b, | |
14053 | void (*function) (struct breakpoint *, | |
14054 | void *), | |
14055 | void *data) | |
14056 | { | |
14057 | struct breakpoint *related; | |
14058 | ||
14059 | related = b; | |
14060 | do | |
14061 | { | |
14062 | struct breakpoint *next; | |
14063 | ||
14064 | /* FUNCTION may delete RELATED. */ | |
14065 | next = related->related_breakpoint; | |
14066 | ||
14067 | if (next == related) | |
14068 | { | |
14069 | /* RELATED is the last ring entry. */ | |
14070 | function (related, data); | |
14071 | ||
14072 | /* FUNCTION may have deleted it, so we'd never reach back to | |
14073 | B. There's nothing left to do anyway, so just break | |
14074 | out. */ | |
14075 | break; | |
14076 | } | |
14077 | else | |
14078 | function (related, data); | |
14079 | ||
14080 | related = next; | |
14081 | } | |
14082 | while (related != b); | |
14083 | } | |
95a42b64 TT |
14084 | |
14085 | static void | |
14086 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14087 | { | |
14088 | delete_breakpoint (b); | |
14089 | } | |
14090 | ||
51be5b68 PA |
14091 | /* A callback for map_breakpoint_numbers that calls |
14092 | delete_breakpoint. */ | |
14093 | ||
14094 | static void | |
14095 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14096 | { | |
14097 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14098 | } | |
14099 | ||
c906108c | 14100 | void |
fba45db2 | 14101 | delete_command (char *arg, int from_tty) |
c906108c | 14102 | { |
35df4500 | 14103 | struct breakpoint *b, *b_tmp; |
c906108c | 14104 | |
ea9365bb TT |
14105 | dont_repeat (); |
14106 | ||
c906108c SS |
14107 | if (arg == 0) |
14108 | { | |
14109 | int breaks_to_delete = 0; | |
14110 | ||
46c6471b PA |
14111 | /* Delete all breakpoints if no argument. Do not delete |
14112 | internal breakpoints, these have to be deleted with an | |
14113 | explicit breakpoint number argument. */ | |
c5aa993b | 14114 | ALL_BREAKPOINTS (b) |
46c6471b | 14115 | if (user_breakpoint_p (b)) |
973d738b DJ |
14116 | { |
14117 | breaks_to_delete = 1; | |
14118 | break; | |
14119 | } | |
c906108c SS |
14120 | |
14121 | /* Ask user only if there are some breakpoints to delete. */ | |
14122 | if (!from_tty | |
e2e0b3e5 | 14123 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14124 | { |
35df4500 | 14125 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14126 | if (user_breakpoint_p (b)) |
c5aa993b | 14127 | delete_breakpoint (b); |
c906108c SS |
14128 | } |
14129 | } | |
14130 | else | |
51be5b68 | 14131 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14132 | } |
14133 | ||
0d381245 VP |
14134 | static int |
14135 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 14136 | { |
0d381245 | 14137 | for (; loc; loc = loc->next) |
8645ff69 UW |
14138 | if (!loc->shlib_disabled |
14139 | && !loc->pspace->executing_startup) | |
0d381245 VP |
14140 | return 0; |
14141 | return 1; | |
fe3f5fa8 VP |
14142 | } |
14143 | ||
776592bf DE |
14144 | /* Subroutine of update_breakpoint_locations to simplify it. |
14145 | Return non-zero if multiple fns in list LOC have the same name. | |
14146 | Null names are ignored. */ | |
14147 | ||
14148 | static int | |
14149 | ambiguous_names_p (struct bp_location *loc) | |
14150 | { | |
14151 | struct bp_location *l; | |
14152 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14153 | (int (*) (const void *, |
14154 | const void *)) streq, | |
776592bf DE |
14155 | NULL, xcalloc, xfree); |
14156 | ||
14157 | for (l = loc; l != NULL; l = l->next) | |
14158 | { | |
14159 | const char **slot; | |
14160 | const char *name = l->function_name; | |
14161 | ||
14162 | /* Allow for some names to be NULL, ignore them. */ | |
14163 | if (name == NULL) | |
14164 | continue; | |
14165 | ||
14166 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14167 | INSERT); | |
4a64f543 MS |
14168 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14169 | returns NULL. */ | |
776592bf DE |
14170 | if (*slot != NULL) |
14171 | { | |
14172 | htab_delete (htab); | |
14173 | return 1; | |
14174 | } | |
14175 | *slot = name; | |
14176 | } | |
14177 | ||
14178 | htab_delete (htab); | |
14179 | return 0; | |
14180 | } | |
14181 | ||
0fb4aa4b PA |
14182 | /* When symbols change, it probably means the sources changed as well, |
14183 | and it might mean the static tracepoint markers are no longer at | |
14184 | the same address or line numbers they used to be at last we | |
14185 | checked. Losing your static tracepoints whenever you rebuild is | |
14186 | undesirable. This function tries to resync/rematch gdb static | |
14187 | tracepoints with the markers on the target, for static tracepoints | |
14188 | that have not been set by marker id. Static tracepoint that have | |
14189 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14190 | The heuristic is: | |
14191 | ||
14192 | 1) For a tracepoint set at a specific address, look for a marker at | |
14193 | the old PC. If one is found there, assume to be the same marker. | |
14194 | If the name / string id of the marker found is different from the | |
14195 | previous known name, assume that means the user renamed the marker | |
14196 | in the sources, and output a warning. | |
14197 | ||
14198 | 2) For a tracepoint set at a given line number, look for a marker | |
14199 | at the new address of the old line number. If one is found there, | |
14200 | assume to be the same marker. If the name / string id of the | |
14201 | marker found is different from the previous known name, assume that | |
14202 | means the user renamed the marker in the sources, and output a | |
14203 | warning. | |
14204 | ||
14205 | 3) If a marker is no longer found at the same address or line, it | |
14206 | may mean the marker no longer exists. But it may also just mean | |
14207 | the code changed a bit. Maybe the user added a few lines of code | |
14208 | that made the marker move up or down (in line number terms). Ask | |
14209 | the target for info about the marker with the string id as we knew | |
14210 | it. If found, update line number and address in the matching | |
14211 | static tracepoint. This will get confused if there's more than one | |
14212 | marker with the same ID (possible in UST, although unadvised | |
14213 | precisely because it confuses tools). */ | |
14214 | ||
14215 | static struct symtab_and_line | |
14216 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14217 | { | |
d9b3f62e | 14218 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14219 | struct static_tracepoint_marker marker; |
14220 | CORE_ADDR pc; | |
0fb4aa4b PA |
14221 | |
14222 | pc = sal.pc; | |
14223 | if (sal.line) | |
14224 | find_line_pc (sal.symtab, sal.line, &pc); | |
14225 | ||
14226 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14227 | { | |
d9b3f62e | 14228 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14229 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14230 | b->number, | |
d9b3f62e | 14231 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14232 | |
d9b3f62e PA |
14233 | xfree (tp->static_trace_marker_id); |
14234 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14235 | release_static_tracepoint_marker (&marker); |
14236 | ||
14237 | return sal; | |
14238 | } | |
14239 | ||
14240 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14241 | by string ID. */ | |
14242 | if (!sal.explicit_pc | |
14243 | && sal.line != 0 | |
14244 | && sal.symtab != NULL | |
d9b3f62e | 14245 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14246 | { |
14247 | VEC(static_tracepoint_marker_p) *markers; | |
14248 | ||
14249 | markers | |
d9b3f62e | 14250 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14251 | |
14252 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14253 | { | |
80e1d417 | 14254 | struct symtab_and_line sal2; |
0fb4aa4b | 14255 | struct symbol *sym; |
80e1d417 | 14256 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14257 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14258 | |
80e1d417 | 14259 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14260 | |
d9b3f62e | 14261 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14262 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14263 | |
14264 | warning (_("marker for static tracepoint %d (%s) not " | |
14265 | "found at previous line number"), | |
d9b3f62e | 14266 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14267 | |
80e1d417 | 14268 | init_sal (&sal2); |
0fb4aa4b | 14269 | |
80e1d417 | 14270 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14271 | |
80e1d417 AS |
14272 | sal2 = find_pc_line (tpmarker->address, 0); |
14273 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14274 | ui_out_text (uiout, "Now in "); |
14275 | if (sym) | |
14276 | { | |
14277 | ui_out_field_string (uiout, "func", | |
14278 | SYMBOL_PRINT_NAME (sym)); | |
14279 | ui_out_text (uiout, " at "); | |
14280 | } | |
05cba821 JK |
14281 | ui_out_field_string (uiout, "file", |
14282 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14283 | ui_out_text (uiout, ":"); |
14284 | ||
14285 | if (ui_out_is_mi_like_p (uiout)) | |
14286 | { | |
0b0865da | 14287 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14288 | |
f35a17b5 | 14289 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14290 | } |
14291 | ||
80e1d417 | 14292 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14293 | ui_out_text (uiout, "\n"); |
14294 | ||
80e1d417 | 14295 | b->loc->line_number = sal2.line; |
2f202fde | 14296 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14297 | |
14298 | xfree (b->addr_string); | |
14299 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14300 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14301 | b->loc->line_number); |
0fb4aa4b PA |
14302 | |
14303 | /* Might be nice to check if function changed, and warn if | |
14304 | so. */ | |
14305 | ||
80e1d417 | 14306 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14307 | } |
14308 | } | |
14309 | return sal; | |
14310 | } | |
14311 | ||
8d3788bd VP |
14312 | /* Returns 1 iff locations A and B are sufficiently same that |
14313 | we don't need to report breakpoint as changed. */ | |
14314 | ||
14315 | static int | |
14316 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14317 | { | |
14318 | while (a && b) | |
14319 | { | |
14320 | if (a->address != b->address) | |
14321 | return 0; | |
14322 | ||
14323 | if (a->shlib_disabled != b->shlib_disabled) | |
14324 | return 0; | |
14325 | ||
14326 | if (a->enabled != b->enabled) | |
14327 | return 0; | |
14328 | ||
14329 | a = a->next; | |
14330 | b = b->next; | |
14331 | } | |
14332 | ||
14333 | if ((a == NULL) != (b == NULL)) | |
14334 | return 0; | |
14335 | ||
14336 | return 1; | |
14337 | } | |
14338 | ||
f1310107 TJB |
14339 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14340 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14341 | a ranged breakpoint. */ | |
14342 | ||
0e30163f | 14343 | void |
0d381245 | 14344 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14345 | struct symtabs_and_lines sals, |
14346 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14347 | { |
14348 | int i; | |
0d381245 VP |
14349 | struct bp_location *existing_locations = b->loc; |
14350 | ||
f8eba3c6 TT |
14351 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14352 | { | |
14353 | /* Ranged breakpoints have only one start location and one end | |
14354 | location. */ | |
14355 | b->enable_state = bp_disabled; | |
14356 | update_global_location_list (1); | |
14357 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14358 | "multiple locations found\n"), | |
14359 | b->number); | |
14360 | return; | |
14361 | } | |
f1310107 | 14362 | |
4a64f543 MS |
14363 | /* If there's no new locations, and all existing locations are |
14364 | pending, don't do anything. This optimizes the common case where | |
14365 | all locations are in the same shared library, that was unloaded. | |
14366 | We'd like to retain the location, so that when the library is | |
14367 | loaded again, we don't loose the enabled/disabled status of the | |
14368 | individual locations. */ | |
0d381245 | 14369 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14370 | return; |
14371 | ||
fe3f5fa8 VP |
14372 | b->loc = NULL; |
14373 | ||
0d381245 | 14374 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14375 | { |
f8eba3c6 TT |
14376 | struct bp_location *new_loc; |
14377 | ||
14378 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14379 | ||
14380 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14381 | |
0d381245 VP |
14382 | /* Reparse conditions, they might contain references to the |
14383 | old symtab. */ | |
14384 | if (b->cond_string != NULL) | |
14385 | { | |
bbc13ae3 | 14386 | const char *s; |
bfd189b1 | 14387 | volatile struct gdb_exception e; |
fe3f5fa8 | 14388 | |
0d381245 VP |
14389 | s = b->cond_string; |
14390 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14391 | { | |
1bb9788d TT |
14392 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14393 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14394 | 0); |
14395 | } | |
14396 | if (e.reason < 0) | |
14397 | { | |
3e43a32a MS |
14398 | warning (_("failed to reevaluate condition " |
14399 | "for breakpoint %d: %s"), | |
0d381245 VP |
14400 | b->number, e.message); |
14401 | new_loc->enabled = 0; | |
14402 | } | |
14403 | } | |
fe3f5fa8 | 14404 | |
f1310107 TJB |
14405 | if (sals_end.nelts) |
14406 | { | |
14407 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14408 | ||
14409 | new_loc->length = end - sals.sals[0].pc + 1; | |
14410 | } | |
0d381245 | 14411 | } |
fe3f5fa8 | 14412 | |
514f746b AR |
14413 | /* Update locations of permanent breakpoints. */ |
14414 | if (b->enable_state == bp_permanent) | |
14415 | make_breakpoint_permanent (b); | |
14416 | ||
4a64f543 MS |
14417 | /* If possible, carry over 'disable' status from existing |
14418 | breakpoints. */ | |
0d381245 VP |
14419 | { |
14420 | struct bp_location *e = existing_locations; | |
776592bf DE |
14421 | /* If there are multiple breakpoints with the same function name, |
14422 | e.g. for inline functions, comparing function names won't work. | |
14423 | Instead compare pc addresses; this is just a heuristic as things | |
14424 | may have moved, but in practice it gives the correct answer | |
14425 | often enough until a better solution is found. */ | |
14426 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14427 | ||
0d381245 VP |
14428 | for (; e; e = e->next) |
14429 | { | |
14430 | if (!e->enabled && e->function_name) | |
14431 | { | |
14432 | struct bp_location *l = b->loc; | |
776592bf DE |
14433 | if (have_ambiguous_names) |
14434 | { | |
14435 | for (; l; l = l->next) | |
f1310107 | 14436 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14437 | { |
14438 | l->enabled = 0; | |
14439 | break; | |
14440 | } | |
14441 | } | |
14442 | else | |
14443 | { | |
14444 | for (; l; l = l->next) | |
14445 | if (l->function_name | |
14446 | && strcmp (e->function_name, l->function_name) == 0) | |
14447 | { | |
14448 | l->enabled = 0; | |
14449 | break; | |
14450 | } | |
14451 | } | |
0d381245 VP |
14452 | } |
14453 | } | |
14454 | } | |
fe3f5fa8 | 14455 | |
8d3788bd VP |
14456 | if (!locations_are_equal (existing_locations, b->loc)) |
14457 | observer_notify_breakpoint_modified (b); | |
14458 | ||
b60e7edf | 14459 | update_global_location_list (1); |
fe3f5fa8 VP |
14460 | } |
14461 | ||
ef23e705 TJB |
14462 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14463 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14464 | ||
14465 | static struct symtabs_and_lines | |
14466 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14467 | { | |
14468 | char *s; | |
02d20e4a | 14469 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14470 | volatile struct gdb_exception e; |
ef23e705 | 14471 | |
983af33b | 14472 | gdb_assert (b->ops != NULL); |
ef23e705 | 14473 | s = addr_string; |
ef23e705 TJB |
14474 | |
14475 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14476 | { | |
983af33b | 14477 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14478 | } |
14479 | if (e.reason < 0) | |
14480 | { | |
14481 | int not_found_and_ok = 0; | |
14482 | /* For pending breakpoints, it's expected that parsing will | |
14483 | fail until the right shared library is loaded. User has | |
14484 | already told to create pending breakpoints and don't need | |
14485 | extra messages. If breakpoint is in bp_shlib_disabled | |
14486 | state, then user already saw the message about that | |
14487 | breakpoint being disabled, and don't want to see more | |
14488 | errors. */ | |
58438ac1 | 14489 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14490 | && (b->condition_not_parsed |
14491 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14492 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14493 | || b->enable_state == bp_disabled)) |
14494 | not_found_and_ok = 1; | |
14495 | ||
14496 | if (!not_found_and_ok) | |
14497 | { | |
14498 | /* We surely don't want to warn about the same breakpoint | |
14499 | 10 times. One solution, implemented here, is disable | |
14500 | the breakpoint on error. Another solution would be to | |
14501 | have separate 'warning emitted' flag. Since this | |
14502 | happens only when a binary has changed, I don't know | |
14503 | which approach is better. */ | |
14504 | b->enable_state = bp_disabled; | |
14505 | throw_exception (e); | |
14506 | } | |
14507 | } | |
14508 | ||
58438ac1 | 14509 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14510 | { |
f8eba3c6 | 14511 | int i; |
ef23e705 | 14512 | |
f8eba3c6 TT |
14513 | for (i = 0; i < sals.nelts; ++i) |
14514 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14515 | if (b->condition_not_parsed && s && s[0]) |
14516 | { | |
ed1d1739 KS |
14517 | char *cond_string, *extra_string; |
14518 | int thread, task; | |
ef23e705 TJB |
14519 | |
14520 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14521 | &cond_string, &thread, &task, |
14522 | &extra_string); | |
ef23e705 TJB |
14523 | if (cond_string) |
14524 | b->cond_string = cond_string; | |
14525 | b->thread = thread; | |
14526 | b->task = task; | |
e7e0cddf SS |
14527 | if (extra_string) |
14528 | b->extra_string = extra_string; | |
ef23e705 TJB |
14529 | b->condition_not_parsed = 0; |
14530 | } | |
14531 | ||
983af33b | 14532 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14533 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14534 | |
58438ac1 TT |
14535 | *found = 1; |
14536 | } | |
14537 | else | |
14538 | *found = 0; | |
ef23e705 TJB |
14539 | |
14540 | return sals; | |
14541 | } | |
14542 | ||
348d480f PA |
14543 | /* The default re_set method, for typical hardware or software |
14544 | breakpoints. Reevaluate the breakpoint and recreate its | |
14545 | locations. */ | |
14546 | ||
14547 | static void | |
28010a5d | 14548 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14549 | { |
14550 | int found; | |
f1310107 | 14551 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14552 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14553 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14554 | |
14555 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14556 | if (found) | |
14557 | { | |
14558 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14559 | expanded = sals; |
ef23e705 TJB |
14560 | } |
14561 | ||
f1310107 TJB |
14562 | if (b->addr_string_range_end) |
14563 | { | |
14564 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14565 | if (found) | |
14566 | { | |
14567 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14568 | expanded_end = sals_end; |
f1310107 TJB |
14569 | } |
14570 | } | |
14571 | ||
14572 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14573 | } |
14574 | ||
983af33b SDJ |
14575 | /* Default method for creating SALs from an address string. It basically |
14576 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14577 | ||
14578 | static void | |
14579 | create_sals_from_address_default (char **arg, | |
14580 | struct linespec_result *canonical, | |
14581 | enum bptype type_wanted, | |
14582 | char *addr_start, char **copy_arg) | |
14583 | { | |
14584 | parse_breakpoint_sals (arg, canonical); | |
14585 | } | |
14586 | ||
14587 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14588 | function for the `create_breakpoints_sal' method of | |
14589 | breakpoint_ops. */ | |
14590 | ||
14591 | static void | |
14592 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14593 | struct linespec_result *canonical, | |
983af33b | 14594 | char *cond_string, |
e7e0cddf | 14595 | char *extra_string, |
983af33b SDJ |
14596 | enum bptype type_wanted, |
14597 | enum bpdisp disposition, | |
14598 | int thread, | |
14599 | int task, int ignore_count, | |
14600 | const struct breakpoint_ops *ops, | |
14601 | int from_tty, int enabled, | |
44f238bb | 14602 | int internal, unsigned flags) |
983af33b SDJ |
14603 | { |
14604 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14605 | extra_string, |
983af33b SDJ |
14606 | type_wanted, disposition, |
14607 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14608 | enabled, internal, flags); |
983af33b SDJ |
14609 | } |
14610 | ||
14611 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14612 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14613 | ||
14614 | static void | |
14615 | decode_linespec_default (struct breakpoint *b, char **s, | |
14616 | struct symtabs_and_lines *sals) | |
14617 | { | |
14618 | struct linespec_result canonical; | |
14619 | ||
14620 | init_linespec_result (&canonical); | |
14621 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14622 | (struct symtab *) NULL, 0, | |
14623 | &canonical, multiple_symbols_all, | |
14624 | b->filter); | |
14625 | ||
14626 | /* We should get 0 or 1 resulting SALs. */ | |
14627 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14628 | ||
14629 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14630 | { | |
14631 | struct linespec_sals *lsal; | |
14632 | ||
14633 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14634 | *sals = lsal->sals; | |
14635 | /* Arrange it so the destructor does not free the | |
14636 | contents. */ | |
14637 | lsal->sals.sals = NULL; | |
14638 | } | |
14639 | ||
14640 | destroy_linespec_result (&canonical); | |
14641 | } | |
14642 | ||
28010a5d PA |
14643 | /* Prepare the global context for a re-set of breakpoint B. */ |
14644 | ||
14645 | static struct cleanup * | |
14646 | prepare_re_set_context (struct breakpoint *b) | |
14647 | { | |
14648 | struct cleanup *cleanups; | |
14649 | ||
14650 | input_radix = b->input_radix; | |
14651 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14652 | if (b->pspace != NULL) |
14653 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14654 | set_language (b->language); |
14655 | ||
14656 | return cleanups; | |
ef23e705 TJB |
14657 | } |
14658 | ||
c906108c SS |
14659 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14660 | The value we return ends up being the return value from catch_errors. | |
14661 | Unused in this case. */ | |
14662 | ||
14663 | static int | |
4efb68b1 | 14664 | breakpoint_re_set_one (void *bint) |
c906108c | 14665 | { |
4a64f543 | 14666 | /* Get past catch_errs. */ |
53a5351d | 14667 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14668 | struct cleanup *cleanups; |
c906108c | 14669 | |
348d480f PA |
14670 | cleanups = prepare_re_set_context (b); |
14671 | b->ops->re_set (b); | |
14672 | do_cleanups (cleanups); | |
c906108c SS |
14673 | return 0; |
14674 | } | |
14675 | ||
69de3c6a | 14676 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14677 | void |
69de3c6a | 14678 | breakpoint_re_set (void) |
c906108c | 14679 | { |
35df4500 | 14680 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14681 | enum language save_language; |
14682 | int save_input_radix; | |
6c95b8df | 14683 | struct cleanup *old_chain; |
c5aa993b | 14684 | |
c906108c SS |
14685 | save_language = current_language->la_language; |
14686 | save_input_radix = input_radix; | |
6c95b8df PA |
14687 | old_chain = save_current_program_space (); |
14688 | ||
35df4500 | 14689 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14690 | { |
4a64f543 | 14691 | /* Format possible error msg. */ |
fe3f5fa8 | 14692 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14693 | b->number); |
14694 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14695 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14696 | do_cleanups (cleanups); |
c5aa993b | 14697 | } |
c906108c SS |
14698 | set_language (save_language); |
14699 | input_radix = save_input_radix; | |
e62c965a | 14700 | |
0756c555 | 14701 | jit_breakpoint_re_set (); |
4efc6507 | 14702 | |
6c95b8df PA |
14703 | do_cleanups (old_chain); |
14704 | ||
af02033e PP |
14705 | create_overlay_event_breakpoint (); |
14706 | create_longjmp_master_breakpoint (); | |
14707 | create_std_terminate_master_breakpoint (); | |
186c406b | 14708 | create_exception_master_breakpoint (); |
c906108c SS |
14709 | } |
14710 | \f | |
c906108c SS |
14711 | /* Reset the thread number of this breakpoint: |
14712 | ||
14713 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14714 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14715 | void |
fba45db2 | 14716 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14717 | { |
14718 | if (b->thread != -1) | |
14719 | { | |
39f77062 KB |
14720 | if (in_thread_list (inferior_ptid)) |
14721 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14722 | |
14723 | /* We're being called after following a fork. The new fork is | |
14724 | selected as current, and unless this was a vfork will have a | |
14725 | different program space from the original thread. Reset that | |
14726 | as well. */ | |
14727 | b->loc->pspace = current_program_space; | |
c906108c SS |
14728 | } |
14729 | } | |
14730 | ||
03ac34d5 MS |
14731 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14732 | If from_tty is nonzero, it prints a message to that effect, | |
14733 | which ends with a period (no newline). */ | |
14734 | ||
c906108c | 14735 | void |
fba45db2 | 14736 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14737 | { |
52f0bd74 | 14738 | struct breakpoint *b; |
c906108c SS |
14739 | |
14740 | if (count < 0) | |
14741 | count = 0; | |
14742 | ||
14743 | ALL_BREAKPOINTS (b) | |
14744 | if (b->number == bptnum) | |
c5aa993b | 14745 | { |
d77f58be SS |
14746 | if (is_tracepoint (b)) |
14747 | { | |
14748 | if (from_tty && count != 0) | |
14749 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14750 | bptnum); | |
14751 | return; | |
14752 | } | |
14753 | ||
c5aa993b | 14754 | b->ignore_count = count; |
221ea385 KS |
14755 | if (from_tty) |
14756 | { | |
14757 | if (count == 0) | |
3e43a32a MS |
14758 | printf_filtered (_("Will stop next time " |
14759 | "breakpoint %d is reached."), | |
221ea385 KS |
14760 | bptnum); |
14761 | else if (count == 1) | |
a3f17187 | 14762 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14763 | bptnum); |
14764 | else | |
3e43a32a MS |
14765 | printf_filtered (_("Will ignore next %d " |
14766 | "crossings of breakpoint %d."), | |
221ea385 KS |
14767 | count, bptnum); |
14768 | } | |
8d3788bd | 14769 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14770 | return; |
14771 | } | |
c906108c | 14772 | |
8a3fe4f8 | 14773 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14774 | } |
14775 | ||
c906108c SS |
14776 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14777 | ||
14778 | static void | |
fba45db2 | 14779 | ignore_command (char *args, int from_tty) |
c906108c SS |
14780 | { |
14781 | char *p = args; | |
52f0bd74 | 14782 | int num; |
c906108c SS |
14783 | |
14784 | if (p == 0) | |
e2e0b3e5 | 14785 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14786 | |
c906108c | 14787 | num = get_number (&p); |
5c44784c | 14788 | if (num == 0) |
8a3fe4f8 | 14789 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14790 | if (*p == 0) |
8a3fe4f8 | 14791 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14792 | |
14793 | set_ignore_count (num, | |
14794 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14795 | from_tty); | |
221ea385 KS |
14796 | if (from_tty) |
14797 | printf_filtered ("\n"); | |
c906108c SS |
14798 | } |
14799 | \f | |
14800 | /* Call FUNCTION on each of the breakpoints | |
14801 | whose numbers are given in ARGS. */ | |
14802 | ||
14803 | static void | |
95a42b64 TT |
14804 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14805 | void *), | |
14806 | void *data) | |
c906108c | 14807 | { |
52f0bd74 AC |
14808 | int num; |
14809 | struct breakpoint *b, *tmp; | |
11cf8741 | 14810 | int match; |
197f0a60 | 14811 | struct get_number_or_range_state state; |
c906108c | 14812 | |
197f0a60 | 14813 | if (args == 0) |
e2e0b3e5 | 14814 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14815 | |
197f0a60 TT |
14816 | init_number_or_range (&state, args); |
14817 | ||
14818 | while (!state.finished) | |
c906108c | 14819 | { |
e799154c | 14820 | const char *p = state.string; |
197f0a60 | 14821 | |
11cf8741 | 14822 | match = 0; |
c5aa993b | 14823 | |
197f0a60 | 14824 | num = get_number_or_range (&state); |
5c44784c | 14825 | if (num == 0) |
c5aa993b | 14826 | { |
8a3fe4f8 | 14827 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14828 | } |
14829 | else | |
14830 | { | |
14831 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14832 | if (b->number == num) | |
14833 | { | |
11cf8741 | 14834 | match = 1; |
cdac0397 | 14835 | function (b, data); |
11cf8741 | 14836 | break; |
5c44784c | 14837 | } |
11cf8741 | 14838 | if (match == 0) |
a3f17187 | 14839 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14840 | } |
c906108c SS |
14841 | } |
14842 | } | |
14843 | ||
0d381245 VP |
14844 | static struct bp_location * |
14845 | find_location_by_number (char *number) | |
14846 | { | |
14847 | char *dot = strchr (number, '.'); | |
14848 | char *p1; | |
14849 | int bp_num; | |
14850 | int loc_num; | |
14851 | struct breakpoint *b; | |
14852 | struct bp_location *loc; | |
14853 | ||
14854 | *dot = '\0'; | |
14855 | ||
14856 | p1 = number; | |
197f0a60 | 14857 | bp_num = get_number (&p1); |
0d381245 VP |
14858 | if (bp_num == 0) |
14859 | error (_("Bad breakpoint number '%s'"), number); | |
14860 | ||
14861 | ALL_BREAKPOINTS (b) | |
14862 | if (b->number == bp_num) | |
14863 | { | |
14864 | break; | |
14865 | } | |
14866 | ||
14867 | if (!b || b->number != bp_num) | |
14868 | error (_("Bad breakpoint number '%s'"), number); | |
14869 | ||
14870 | p1 = dot+1; | |
197f0a60 | 14871 | loc_num = get_number (&p1); |
0d381245 VP |
14872 | if (loc_num == 0) |
14873 | error (_("Bad breakpoint location number '%s'"), number); | |
14874 | ||
14875 | --loc_num; | |
14876 | loc = b->loc; | |
14877 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14878 | ; | |
14879 | if (!loc) | |
14880 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14881 | ||
14882 | return loc; | |
14883 | } | |
14884 | ||
14885 | ||
1900040c MS |
14886 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14887 | If from_tty is nonzero, it prints a message to that effect, | |
14888 | which ends with a period (no newline). */ | |
14889 | ||
c906108c | 14890 | void |
fba45db2 | 14891 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14892 | { |
14893 | /* Never disable a watchpoint scope breakpoint; we want to | |
14894 | hit them when we leave scope so we can delete both the | |
14895 | watchpoint and its scope breakpoint at that time. */ | |
14896 | if (bpt->type == bp_watchpoint_scope) | |
14897 | return; | |
14898 | ||
c2c6d25f | 14899 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14900 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14901 | return; |
14902 | ||
b5de0fa7 | 14903 | bpt->enable_state = bp_disabled; |
c906108c | 14904 | |
b775012e LM |
14905 | /* Mark breakpoint locations modified. */ |
14906 | mark_breakpoint_modified (bpt); | |
14907 | ||
d248b706 KY |
14908 | if (target_supports_enable_disable_tracepoint () |
14909 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14910 | { | |
14911 | struct bp_location *location; | |
14912 | ||
14913 | for (location = bpt->loc; location; location = location->next) | |
14914 | target_disable_tracepoint (location); | |
14915 | } | |
14916 | ||
b60e7edf | 14917 | update_global_location_list (0); |
c906108c | 14918 | |
8d3788bd | 14919 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14920 | } |
14921 | ||
51be5b68 PA |
14922 | /* A callback for iterate_over_related_breakpoints. */ |
14923 | ||
14924 | static void | |
14925 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14926 | { | |
14927 | disable_breakpoint (b); | |
14928 | } | |
14929 | ||
95a42b64 TT |
14930 | /* A callback for map_breakpoint_numbers that calls |
14931 | disable_breakpoint. */ | |
14932 | ||
14933 | static void | |
14934 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14935 | { | |
51be5b68 | 14936 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14937 | } |
14938 | ||
c906108c | 14939 | static void |
fba45db2 | 14940 | disable_command (char *args, int from_tty) |
c906108c | 14941 | { |
c906108c | 14942 | if (args == 0) |
46c6471b PA |
14943 | { |
14944 | struct breakpoint *bpt; | |
14945 | ||
14946 | ALL_BREAKPOINTS (bpt) | |
14947 | if (user_breakpoint_p (bpt)) | |
14948 | disable_breakpoint (bpt); | |
14949 | } | |
9eaabc75 | 14950 | else |
0d381245 | 14951 | { |
9eaabc75 MW |
14952 | char *num = extract_arg (&args); |
14953 | ||
14954 | while (num) | |
d248b706 | 14955 | { |
9eaabc75 | 14956 | if (strchr (num, '.')) |
b775012e | 14957 | { |
9eaabc75 MW |
14958 | struct bp_location *loc = find_location_by_number (num); |
14959 | ||
14960 | if (loc) | |
14961 | { | |
14962 | if (loc->enabled) | |
14963 | { | |
14964 | loc->enabled = 0; | |
14965 | mark_breakpoint_location_modified (loc); | |
14966 | } | |
14967 | if (target_supports_enable_disable_tracepoint () | |
14968 | && current_trace_status ()->running && loc->owner | |
14969 | && is_tracepoint (loc->owner)) | |
14970 | target_disable_tracepoint (loc); | |
14971 | } | |
14972 | update_global_location_list (0); | |
b775012e | 14973 | } |
9eaabc75 MW |
14974 | else |
14975 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14976 | num = extract_arg (&args); | |
d248b706 | 14977 | } |
0d381245 | 14978 | } |
c906108c SS |
14979 | } |
14980 | ||
14981 | static void | |
816338b5 SS |
14982 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14983 | int count) | |
c906108c | 14984 | { |
afe38095 | 14985 | int target_resources_ok; |
c906108c SS |
14986 | |
14987 | if (bpt->type == bp_hardware_breakpoint) | |
14988 | { | |
14989 | int i; | |
c5aa993b | 14990 | i = hw_breakpoint_used_count (); |
53a5351d | 14991 | target_resources_ok = |
d92524f1 | 14992 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14993 | i + 1, 0); |
c906108c | 14994 | if (target_resources_ok == 0) |
8a3fe4f8 | 14995 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14996 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14997 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14998 | } |
14999 | ||
cc60f2e3 | 15000 | if (is_watchpoint (bpt)) |
c906108c | 15001 | { |
d07205c2 JK |
15002 | /* Initialize it just to avoid a GCC false warning. */ |
15003 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 15004 | volatile struct gdb_exception e; |
dde02812 ES |
15005 | |
15006 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 15007 | { |
3a5c3e22 PA |
15008 | struct watchpoint *w = (struct watchpoint *) bpt; |
15009 | ||
1e718ff1 TJB |
15010 | orig_enable_state = bpt->enable_state; |
15011 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 15012 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 15013 | } |
dde02812 | 15014 | if (e.reason < 0) |
c5aa993b | 15015 | { |
1e718ff1 | 15016 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
15017 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
15018 | bpt->number); | |
15019 | return; | |
c5aa993b | 15020 | } |
c906108c | 15021 | } |
0101ce28 | 15022 | |
b4c291bb KH |
15023 | if (bpt->enable_state != bp_permanent) |
15024 | bpt->enable_state = bp_enabled; | |
d248b706 | 15025 | |
b775012e LM |
15026 | bpt->enable_state = bp_enabled; |
15027 | ||
15028 | /* Mark breakpoint locations modified. */ | |
15029 | mark_breakpoint_modified (bpt); | |
15030 | ||
d248b706 KY |
15031 | if (target_supports_enable_disable_tracepoint () |
15032 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15033 | { | |
15034 | struct bp_location *location; | |
15035 | ||
15036 | for (location = bpt->loc; location; location = location->next) | |
15037 | target_enable_tracepoint (location); | |
15038 | } | |
15039 | ||
b4c291bb | 15040 | bpt->disposition = disposition; |
816338b5 | 15041 | bpt->enable_count = count; |
b60e7edf | 15042 | update_global_location_list (1); |
9c97429f | 15043 | |
8d3788bd | 15044 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15045 | } |
15046 | ||
fe3f5fa8 | 15047 | |
c906108c | 15048 | void |
fba45db2 | 15049 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15050 | { |
816338b5 | 15051 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15052 | } |
15053 | ||
15054 | static void | |
15055 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15056 | { | |
15057 | enable_breakpoint (bpt); | |
c906108c SS |
15058 | } |
15059 | ||
95a42b64 TT |
15060 | /* A callback for map_breakpoint_numbers that calls |
15061 | enable_breakpoint. */ | |
15062 | ||
15063 | static void | |
15064 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15065 | { | |
51be5b68 | 15066 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15067 | } |
15068 | ||
c906108c SS |
15069 | /* The enable command enables the specified breakpoints (or all defined |
15070 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15071 | in stopping the inferior. */ |
c906108c | 15072 | |
c906108c | 15073 | static void |
fba45db2 | 15074 | enable_command (char *args, int from_tty) |
c906108c | 15075 | { |
c906108c | 15076 | if (args == 0) |
46c6471b PA |
15077 | { |
15078 | struct breakpoint *bpt; | |
15079 | ||
15080 | ALL_BREAKPOINTS (bpt) | |
15081 | if (user_breakpoint_p (bpt)) | |
15082 | enable_breakpoint (bpt); | |
15083 | } | |
9eaabc75 | 15084 | else |
0d381245 | 15085 | { |
9eaabc75 MW |
15086 | char *num = extract_arg (&args); |
15087 | ||
15088 | while (num) | |
d248b706 | 15089 | { |
9eaabc75 | 15090 | if (strchr (num, '.')) |
b775012e | 15091 | { |
9eaabc75 MW |
15092 | struct bp_location *loc = find_location_by_number (num); |
15093 | ||
15094 | if (loc) | |
15095 | { | |
15096 | if (!loc->enabled) | |
15097 | { | |
15098 | loc->enabled = 1; | |
15099 | mark_breakpoint_location_modified (loc); | |
15100 | } | |
15101 | if (target_supports_enable_disable_tracepoint () | |
15102 | && current_trace_status ()->running && loc->owner | |
15103 | && is_tracepoint (loc->owner)) | |
15104 | target_enable_tracepoint (loc); | |
15105 | } | |
15106 | update_global_location_list (1); | |
b775012e | 15107 | } |
9eaabc75 MW |
15108 | else |
15109 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15110 | num = extract_arg (&args); | |
d248b706 | 15111 | } |
0d381245 | 15112 | } |
c906108c SS |
15113 | } |
15114 | ||
816338b5 SS |
15115 | /* This struct packages up disposition data for application to multiple |
15116 | breakpoints. */ | |
15117 | ||
15118 | struct disp_data | |
15119 | { | |
15120 | enum bpdisp disp; | |
15121 | int count; | |
15122 | }; | |
15123 | ||
c906108c | 15124 | static void |
51be5b68 PA |
15125 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15126 | { | |
816338b5 | 15127 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15128 | |
816338b5 | 15129 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15130 | } |
15131 | ||
15132 | static void | |
15133 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15134 | { |
816338b5 | 15135 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15136 | |
15137 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15138 | } |
15139 | ||
c906108c | 15140 | static void |
fba45db2 | 15141 | enable_once_command (char *args, int from_tty) |
c906108c | 15142 | { |
51be5b68 | 15143 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15144 | } |
15145 | ||
816338b5 SS |
15146 | static void |
15147 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15148 | { | |
15149 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15150 | ||
15151 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15152 | } | |
15153 | ||
15154 | static void | |
15155 | enable_count_command (char *args, int from_tty) | |
15156 | { | |
15157 | int count = get_number (&args); | |
15158 | ||
15159 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15160 | } | |
15161 | ||
c906108c | 15162 | static void |
51be5b68 | 15163 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15164 | { |
816338b5 | 15165 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15166 | |
15167 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15168 | } |
15169 | ||
c906108c | 15170 | static void |
fba45db2 | 15171 | enable_delete_command (char *args, int from_tty) |
c906108c | 15172 | { |
51be5b68 | 15173 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15174 | } |
15175 | \f | |
fa8d40ab JJ |
15176 | static void |
15177 | set_breakpoint_cmd (char *args, int from_tty) | |
15178 | { | |
15179 | } | |
15180 | ||
15181 | static void | |
15182 | show_breakpoint_cmd (char *args, int from_tty) | |
15183 | { | |
15184 | } | |
15185 | ||
1f3b5d1b PP |
15186 | /* Invalidate last known value of any hardware watchpoint if |
15187 | the memory which that value represents has been written to by | |
15188 | GDB itself. */ | |
15189 | ||
15190 | static void | |
8de0566d YQ |
15191 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15192 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15193 | const bfd_byte *data) |
15194 | { | |
15195 | struct breakpoint *bp; | |
15196 | ||
15197 | ALL_BREAKPOINTS (bp) | |
15198 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15199 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15200 | { |
3a5c3e22 | 15201 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15202 | |
3a5c3e22 PA |
15203 | if (wp->val_valid && wp->val) |
15204 | { | |
15205 | struct bp_location *loc; | |
15206 | ||
15207 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15208 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15209 | && loc->address + loc->length > addr | |
15210 | && addr + len > loc->address) | |
15211 | { | |
15212 | value_free (wp->val); | |
15213 | wp->val = NULL; | |
15214 | wp->val_valid = 0; | |
15215 | } | |
15216 | } | |
1f3b5d1b PP |
15217 | } |
15218 | } | |
15219 | ||
8181d85f DJ |
15220 | /* Create and insert a raw software breakpoint at PC. Return an |
15221 | identifier, which should be used to remove the breakpoint later. | |
15222 | In general, places which call this should be using something on the | |
15223 | breakpoint chain instead; this function should be eliminated | |
15224 | someday. */ | |
15225 | ||
15226 | void * | |
6c95b8df PA |
15227 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
15228 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
15229 | { |
15230 | struct bp_target_info *bp_tgt; | |
ef370185 | 15231 | struct bp_location *bl; |
8181d85f | 15232 | |
41bf6aca | 15233 | bp_tgt = XCNEW (struct bp_target_info); |
8181d85f | 15234 | |
6c95b8df | 15235 | bp_tgt->placed_address_space = aspace; |
8181d85f | 15236 | bp_tgt->placed_address = pc; |
6c95b8df | 15237 | |
ef370185 JB |
15238 | /* If an unconditional non-raw breakpoint is already inserted at |
15239 | that location, there's no need to insert another. However, with | |
15240 | target-side evaluation of breakpoint conditions, if the | |
15241 | breakpoint that is currently inserted on the target is | |
15242 | conditional, we need to make it unconditional. Note that a | |
15243 | breakpoint with target-side commands is not reported even if | |
15244 | unconditional, so we need to remove the commands from the target | |
15245 | as well. */ | |
15246 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc); | |
15247 | if (bl != NULL | |
15248 | && VEC_empty (agent_expr_p, bl->target_info.conditions) | |
15249 | && VEC_empty (agent_expr_p, bl->target_info.tcommands)) | |
15250 | { | |
15251 | bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info); | |
15252 | return bp_tgt; | |
15253 | } | |
15254 | ||
a6d9a66e | 15255 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
15256 | { |
15257 | /* Could not insert the breakpoint. */ | |
15258 | xfree (bp_tgt); | |
15259 | return NULL; | |
15260 | } | |
15261 | ||
15262 | return bp_tgt; | |
15263 | } | |
15264 | ||
4a64f543 MS |
15265 | /* Remove a breakpoint BP inserted by |
15266 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
15267 | |
15268 | int | |
a6d9a66e | 15269 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
15270 | { |
15271 | struct bp_target_info *bp_tgt = bp; | |
ef370185 JB |
15272 | struct address_space *aspace = bp_tgt->placed_address_space; |
15273 | CORE_ADDR address = bp_tgt->placed_address; | |
15274 | struct bp_location *bl; | |
8181d85f DJ |
15275 | int ret; |
15276 | ||
ef370185 JB |
15277 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, address); |
15278 | ||
15279 | /* Only remove the raw breakpoint if there are no other non-raw | |
15280 | breakpoints still inserted at this location. Otherwise, we would | |
15281 | be effectively disabling those breakpoints. */ | |
15282 | if (bl == NULL) | |
15283 | ret = target_remove_breakpoint (gdbarch, bp_tgt); | |
15284 | else if (!VEC_empty (agent_expr_p, bl->target_info.conditions) | |
15285 | || !VEC_empty (agent_expr_p, bl->target_info.tcommands)) | |
15286 | { | |
15287 | /* The target is evaluating conditions, and when we inserted the | |
15288 | software single-step breakpoint, we had made the breakpoint | |
15289 | unconditional and command-less on the target side. Reinsert | |
15290 | to restore the conditions/commands. */ | |
15291 | ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info); | |
15292 | } | |
15293 | else | |
15294 | ret = 0; | |
15295 | ||
8181d85f DJ |
15296 | xfree (bp_tgt); |
15297 | ||
15298 | return ret; | |
15299 | } | |
15300 | ||
8181d85f DJ |
15301 | /* Create and insert a breakpoint for software single step. */ |
15302 | ||
15303 | void | |
6c95b8df | 15304 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15305 | struct address_space *aspace, |
15306 | CORE_ADDR next_pc) | |
8181d85f DJ |
15307 | { |
15308 | void **bpt_p; | |
15309 | ||
15310 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15311 | { |
15312 | bpt_p = &single_step_breakpoints[0]; | |
15313 | single_step_gdbarch[0] = gdbarch; | |
15314 | } | |
8181d85f DJ |
15315 | else |
15316 | { | |
15317 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15318 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15319 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15320 | } |
15321 | ||
4a64f543 MS |
15322 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15323 | be to only create the breakpoints once, and actually put them on | |
15324 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15325 | We could adjust the addresses each time they were needed. Doing | |
15326 | this requires corresponding changes elsewhere where single step | |
15327 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15328 | |
6c95b8df | 15329 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15330 | if (*bpt_p == NULL) |
5af949e3 UW |
15331 | error (_("Could not insert single-step breakpoint at %s"), |
15332 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15333 | } |
15334 | ||
f02253f1 HZ |
15335 | /* Check if the breakpoints used for software single stepping |
15336 | were inserted or not. */ | |
15337 | ||
15338 | int | |
15339 | single_step_breakpoints_inserted (void) | |
15340 | { | |
15341 | return (single_step_breakpoints[0] != NULL | |
15342 | || single_step_breakpoints[1] != NULL); | |
15343 | } | |
15344 | ||
8181d85f DJ |
15345 | /* Remove and delete any breakpoints used for software single step. */ |
15346 | ||
15347 | void | |
15348 | remove_single_step_breakpoints (void) | |
15349 | { | |
15350 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15351 | ||
15352 | /* See insert_single_step_breakpoint for more about this deprecated | |
15353 | call. */ | |
a6d9a66e UW |
15354 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15355 | single_step_breakpoints[0]); | |
15356 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15357 | single_step_breakpoints[0] = NULL; |
15358 | ||
15359 | if (single_step_breakpoints[1] != NULL) | |
15360 | { | |
a6d9a66e UW |
15361 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15362 | single_step_breakpoints[1]); | |
15363 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15364 | single_step_breakpoints[1] = NULL; |
15365 | } | |
15366 | } | |
15367 | ||
d03285ec UW |
15368 | /* Delete software single step breakpoints without removing them from |
15369 | the inferior. This is intended to be used if the inferior's address | |
15370 | space where they were inserted is already gone, e.g. after exit or | |
15371 | exec. */ | |
15372 | ||
15373 | void | |
15374 | cancel_single_step_breakpoints (void) | |
15375 | { | |
15376 | int i; | |
15377 | ||
15378 | for (i = 0; i < 2; i++) | |
15379 | if (single_step_breakpoints[i]) | |
15380 | { | |
15381 | xfree (single_step_breakpoints[i]); | |
15382 | single_step_breakpoints[i] = NULL; | |
15383 | single_step_gdbarch[i] = NULL; | |
15384 | } | |
15385 | } | |
15386 | ||
15387 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15388 | removing them. */ | |
15389 | ||
15390 | static void | |
15391 | detach_single_step_breakpoints (void) | |
15392 | { | |
15393 | int i; | |
15394 | ||
15395 | for (i = 0; i < 2; i++) | |
15396 | if (single_step_breakpoints[i]) | |
15397 | target_remove_breakpoint (single_step_gdbarch[i], | |
15398 | single_step_breakpoints[i]); | |
15399 | } | |
15400 | ||
ef370185 JB |
15401 | /* Find the software single-step breakpoint that inserted at PC. |
15402 | Returns its slot if found, and -1 if not found. */ | |
1aafd4da | 15403 | |
ef370185 JB |
15404 | static int |
15405 | find_single_step_breakpoint (struct address_space *aspace, | |
15406 | CORE_ADDR pc) | |
1aafd4da UW |
15407 | { |
15408 | int i; | |
15409 | ||
15410 | for (i = 0; i < 2; i++) | |
15411 | { | |
15412 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15413 | if (bp_tgt |
15414 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15415 | bp_tgt->placed_address, | |
15416 | aspace, pc)) | |
ef370185 | 15417 | return i; |
1aafd4da UW |
15418 | } |
15419 | ||
ef370185 JB |
15420 | return -1; |
15421 | } | |
15422 | ||
15423 | /* Check whether a software single-step breakpoint is inserted at | |
15424 | PC. */ | |
15425 | ||
15426 | int | |
15427 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15428 | CORE_ADDR pc) | |
15429 | { | |
15430 | return find_single_step_breakpoint (aspace, pc) >= 0; | |
1aafd4da UW |
15431 | } |
15432 | ||
a96d9b2e SDJ |
15433 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15434 | non-zero otherwise. */ | |
15435 | static int | |
15436 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15437 | { | |
15438 | if (syscall_catchpoint_p (bp) | |
15439 | && bp->enable_state != bp_disabled | |
15440 | && bp->enable_state != bp_call_disabled) | |
15441 | return 1; | |
15442 | else | |
15443 | return 0; | |
15444 | } | |
15445 | ||
15446 | int | |
15447 | catch_syscall_enabled (void) | |
15448 | { | |
fa3064dd YQ |
15449 | struct catch_syscall_inferior_data *inf_data |
15450 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15451 | |
fa3064dd | 15452 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15453 | } |
15454 | ||
15455 | int | |
15456 | catching_syscall_number (int syscall_number) | |
15457 | { | |
15458 | struct breakpoint *bp; | |
15459 | ||
15460 | ALL_BREAKPOINTS (bp) | |
15461 | if (is_syscall_catchpoint_enabled (bp)) | |
15462 | { | |
be5c67c1 PA |
15463 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15464 | ||
15465 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15466 | { |
15467 | int i, iter; | |
15468 | for (i = 0; | |
be5c67c1 | 15469 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15470 | i++) |
15471 | if (syscall_number == iter) | |
15472 | return 1; | |
15473 | } | |
15474 | else | |
15475 | return 1; | |
15476 | } | |
15477 | ||
15478 | return 0; | |
15479 | } | |
15480 | ||
15481 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15482 | static VEC (char_ptr) * |
a96d9b2e | 15483 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15484 | const char *text, const char *word) |
a96d9b2e SDJ |
15485 | { |
15486 | const char **list = get_syscall_names (); | |
49c4e619 | 15487 | VEC (char_ptr) *retlist |
b45627a0 | 15488 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15489 | |
c38eea1a MS |
15490 | xfree (list); |
15491 | return retlist; | |
a96d9b2e SDJ |
15492 | } |
15493 | ||
1042e4c0 SS |
15494 | /* Tracepoint-specific operations. */ |
15495 | ||
15496 | /* Set tracepoint count to NUM. */ | |
15497 | static void | |
15498 | set_tracepoint_count (int num) | |
15499 | { | |
15500 | tracepoint_count = num; | |
4fa62494 | 15501 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15502 | } |
15503 | ||
70221824 | 15504 | static void |
1042e4c0 SS |
15505 | trace_command (char *arg, int from_tty) |
15506 | { | |
55aa24fb SDJ |
15507 | struct breakpoint_ops *ops; |
15508 | const char *arg_cp = arg; | |
15509 | ||
15510 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15511 | ops = &tracepoint_probe_breakpoint_ops; | |
15512 | else | |
15513 | ops = &tracepoint_breakpoint_ops; | |
15514 | ||
558a9d82 YQ |
15515 | create_breakpoint (get_current_arch (), |
15516 | arg, | |
15517 | NULL, 0, NULL, 1 /* parse arg */, | |
15518 | 0 /* tempflag */, | |
15519 | bp_tracepoint /* type_wanted */, | |
15520 | 0 /* Ignore count */, | |
15521 | pending_break_support, | |
15522 | ops, | |
15523 | from_tty, | |
15524 | 1 /* enabled */, | |
15525 | 0 /* internal */, 0); | |
1042e4c0 SS |
15526 | } |
15527 | ||
70221824 | 15528 | static void |
7a697b8d SS |
15529 | ftrace_command (char *arg, int from_tty) |
15530 | { | |
558a9d82 YQ |
15531 | create_breakpoint (get_current_arch (), |
15532 | arg, | |
15533 | NULL, 0, NULL, 1 /* parse arg */, | |
15534 | 0 /* tempflag */, | |
15535 | bp_fast_tracepoint /* type_wanted */, | |
15536 | 0 /* Ignore count */, | |
15537 | pending_break_support, | |
15538 | &tracepoint_breakpoint_ops, | |
15539 | from_tty, | |
15540 | 1 /* enabled */, | |
15541 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15542 | } |
15543 | ||
15544 | /* strace command implementation. Creates a static tracepoint. */ | |
15545 | ||
70221824 | 15546 | static void |
0fb4aa4b PA |
15547 | strace_command (char *arg, int from_tty) |
15548 | { | |
983af33b SDJ |
15549 | struct breakpoint_ops *ops; |
15550 | ||
15551 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15552 | or with a normal static tracepoint. */ | |
15553 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15554 | ops = &strace_marker_breakpoint_ops; | |
15555 | else | |
15556 | ops = &tracepoint_breakpoint_ops; | |
15557 | ||
558a9d82 YQ |
15558 | create_breakpoint (get_current_arch (), |
15559 | arg, | |
15560 | NULL, 0, NULL, 1 /* parse arg */, | |
15561 | 0 /* tempflag */, | |
15562 | bp_static_tracepoint /* type_wanted */, | |
15563 | 0 /* Ignore count */, | |
15564 | pending_break_support, | |
15565 | ops, | |
15566 | from_tty, | |
15567 | 1 /* enabled */, | |
15568 | 0 /* internal */, 0); | |
7a697b8d SS |
15569 | } |
15570 | ||
409873ef SS |
15571 | /* Set up a fake reader function that gets command lines from a linked |
15572 | list that was acquired during tracepoint uploading. */ | |
15573 | ||
15574 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15575 | static int next_cmd; |
409873ef SS |
15576 | |
15577 | static char * | |
15578 | read_uploaded_action (void) | |
15579 | { | |
15580 | char *rslt; | |
15581 | ||
3149d8c1 | 15582 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15583 | |
3149d8c1 | 15584 | next_cmd++; |
409873ef SS |
15585 | |
15586 | return rslt; | |
15587 | } | |
15588 | ||
00bf0b85 SS |
15589 | /* Given information about a tracepoint as recorded on a target (which |
15590 | can be either a live system or a trace file), attempt to create an | |
15591 | equivalent GDB tracepoint. This is not a reliable process, since | |
15592 | the target does not necessarily have all the information used when | |
15593 | the tracepoint was originally defined. */ | |
15594 | ||
d9b3f62e | 15595 | struct tracepoint * |
00bf0b85 | 15596 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15597 | { |
409873ef | 15598 | char *addr_str, small_buf[100]; |
d9b3f62e | 15599 | struct tracepoint *tp; |
fd9b8c24 | 15600 | |
409873ef SS |
15601 | if (utp->at_string) |
15602 | addr_str = utp->at_string; | |
15603 | else | |
15604 | { | |
15605 | /* In the absence of a source location, fall back to raw | |
15606 | address. Since there is no way to confirm that the address | |
15607 | means the same thing as when the trace was started, warn the | |
15608 | user. */ | |
3e43a32a MS |
15609 | warning (_("Uploaded tracepoint %d has no " |
15610 | "source location, using raw address"), | |
409873ef | 15611 | utp->number); |
8c042590 | 15612 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15613 | addr_str = small_buf; |
15614 | } | |
15615 | ||
15616 | /* There's not much we can do with a sequence of bytecodes. */ | |
15617 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15618 | warning (_("Uploaded tracepoint %d condition " |
15619 | "has no source form, ignoring it"), | |
409873ef | 15620 | utp->number); |
d5551862 | 15621 | |
8cdf0e15 | 15622 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15623 | addr_str, |
e7e0cddf SS |
15624 | utp->cond_string, -1, NULL, |
15625 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15626 | 0 /* tempflag */, |
0fb4aa4b | 15627 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15628 | 0 /* Ignore count */, |
15629 | pending_break_support, | |
348d480f | 15630 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15631 | 0 /* from_tty */, |
84f4c1fe | 15632 | utp->enabled /* enabled */, |
44f238bb PA |
15633 | 0 /* internal */, |
15634 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15635 | return NULL; |
15636 | ||
409873ef | 15637 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15638 | tp = get_tracepoint (tracepoint_count); |
15639 | gdb_assert (tp != NULL); | |
d5551862 | 15640 | |
00bf0b85 SS |
15641 | if (utp->pass > 0) |
15642 | { | |
8c042590 PM |
15643 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15644 | tp->base.number); | |
00bf0b85 | 15645 | |
409873ef | 15646 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15647 | } |
15648 | ||
409873ef SS |
15649 | /* If we have uploaded versions of the original commands, set up a |
15650 | special-purpose "reader" function and call the usual command line | |
15651 | reader, then pass the result to the breakpoint command-setting | |
15652 | function. */ | |
3149d8c1 | 15653 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15654 | { |
409873ef | 15655 | struct command_line *cmd_list; |
00bf0b85 | 15656 | |
409873ef | 15657 | this_utp = utp; |
3149d8c1 | 15658 | next_cmd = 0; |
d5551862 | 15659 | |
409873ef SS |
15660 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15661 | ||
d9b3f62e | 15662 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15663 | } |
3149d8c1 SS |
15664 | else if (!VEC_empty (char_ptr, utp->actions) |
15665 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15666 | warning (_("Uploaded tracepoint %d actions " |
15667 | "have no source form, ignoring them"), | |
409873ef | 15668 | utp->number); |
00bf0b85 | 15669 | |
f196051f SS |
15670 | /* Copy any status information that might be available. */ |
15671 | tp->base.hit_count = utp->hit_count; | |
15672 | tp->traceframe_usage = utp->traceframe_usage; | |
15673 | ||
00bf0b85 | 15674 | return tp; |
d9b3f62e | 15675 | } |
00bf0b85 | 15676 | |
1042e4c0 SS |
15677 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15678 | omitted. */ | |
15679 | ||
15680 | static void | |
e5a67952 | 15681 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15682 | { |
79a45e25 | 15683 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15684 | int num_printed; |
1042e4c0 | 15685 | |
e5a67952 | 15686 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15687 | |
15688 | if (num_printed == 0) | |
1042e4c0 | 15689 | { |
e5a67952 | 15690 | if (args == NULL || *args == '\0') |
d77f58be SS |
15691 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15692 | else | |
e5a67952 | 15693 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15694 | } |
ad443146 SS |
15695 | |
15696 | default_collect_info (); | |
1042e4c0 SS |
15697 | } |
15698 | ||
4a64f543 | 15699 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15700 | Not supported by all targets. */ |
15701 | static void | |
15702 | enable_trace_command (char *args, int from_tty) | |
15703 | { | |
15704 | enable_command (args, from_tty); | |
15705 | } | |
15706 | ||
4a64f543 | 15707 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15708 | Not supported by all targets. */ |
15709 | static void | |
15710 | disable_trace_command (char *args, int from_tty) | |
15711 | { | |
15712 | disable_command (args, from_tty); | |
15713 | } | |
15714 | ||
4a64f543 | 15715 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15716 | static void |
15717 | delete_trace_command (char *arg, int from_tty) | |
15718 | { | |
35df4500 | 15719 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15720 | |
15721 | dont_repeat (); | |
15722 | ||
15723 | if (arg == 0) | |
15724 | { | |
15725 | int breaks_to_delete = 0; | |
15726 | ||
15727 | /* Delete all breakpoints if no argument. | |
15728 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15729 | have to be deleted with an explicit breakpoint number |
15730 | argument. */ | |
1042e4c0 | 15731 | ALL_TRACEPOINTS (b) |
46c6471b | 15732 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15733 | { |
15734 | breaks_to_delete = 1; | |
15735 | break; | |
15736 | } | |
1042e4c0 SS |
15737 | |
15738 | /* Ask user only if there are some breakpoints to delete. */ | |
15739 | if (!from_tty | |
15740 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15741 | { | |
35df4500 | 15742 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15743 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15744 | delete_breakpoint (b); |
1042e4c0 SS |
15745 | } |
15746 | } | |
15747 | else | |
51be5b68 | 15748 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15749 | } |
15750 | ||
197f0a60 TT |
15751 | /* Helper function for trace_pass_command. */ |
15752 | ||
15753 | static void | |
d9b3f62e | 15754 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15755 | { |
d9b3f62e | 15756 | tp->pass_count = count; |
6f6484cd | 15757 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15758 | if (from_tty) |
15759 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15760 | tp->base.number, count); |
197f0a60 TT |
15761 | } |
15762 | ||
1042e4c0 SS |
15763 | /* Set passcount for tracepoint. |
15764 | ||
15765 | First command argument is passcount, second is tracepoint number. | |
15766 | If tracepoint number omitted, apply to most recently defined. | |
15767 | Also accepts special argument "all". */ | |
15768 | ||
15769 | static void | |
15770 | trace_pass_command (char *args, int from_tty) | |
15771 | { | |
d9b3f62e | 15772 | struct tracepoint *t1; |
1042e4c0 | 15773 | unsigned int count; |
1042e4c0 SS |
15774 | |
15775 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15776 | error (_("passcount command requires an " |
15777 | "argument (count + optional TP num)")); | |
1042e4c0 | 15778 | |
4a64f543 | 15779 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15780 | |
529480d0 | 15781 | args = skip_spaces (args); |
1042e4c0 SS |
15782 | if (*args && strncasecmp (args, "all", 3) == 0) |
15783 | { | |
d9b3f62e PA |
15784 | struct breakpoint *b; |
15785 | ||
1042e4c0 | 15786 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15787 | if (*args) |
15788 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15789 | |
d9b3f62e | 15790 | ALL_TRACEPOINTS (b) |
197f0a60 | 15791 | { |
d9b3f62e | 15792 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15793 | trace_pass_set_count (t1, count, from_tty); |
15794 | } | |
15795 | } | |
15796 | else if (*args == '\0') | |
1042e4c0 | 15797 | { |
5fa1d40e | 15798 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15799 | if (t1) |
197f0a60 TT |
15800 | trace_pass_set_count (t1, count, from_tty); |
15801 | } | |
15802 | else | |
15803 | { | |
15804 | struct get_number_or_range_state state; | |
15805 | ||
15806 | init_number_or_range (&state, args); | |
15807 | while (!state.finished) | |
1042e4c0 | 15808 | { |
5fa1d40e | 15809 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15810 | if (t1) |
15811 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15812 | } |
15813 | } | |
1042e4c0 SS |
15814 | } |
15815 | ||
d9b3f62e | 15816 | struct tracepoint * |
1042e4c0 SS |
15817 | get_tracepoint (int num) |
15818 | { | |
15819 | struct breakpoint *t; | |
15820 | ||
15821 | ALL_TRACEPOINTS (t) | |
15822 | if (t->number == num) | |
d9b3f62e | 15823 | return (struct tracepoint *) t; |
1042e4c0 SS |
15824 | |
15825 | return NULL; | |
15826 | } | |
15827 | ||
d5551862 SS |
15828 | /* Find the tracepoint with the given target-side number (which may be |
15829 | different from the tracepoint number after disconnecting and | |
15830 | reconnecting). */ | |
15831 | ||
d9b3f62e | 15832 | struct tracepoint * |
d5551862 SS |
15833 | get_tracepoint_by_number_on_target (int num) |
15834 | { | |
d9b3f62e | 15835 | struct breakpoint *b; |
d5551862 | 15836 | |
d9b3f62e PA |
15837 | ALL_TRACEPOINTS (b) |
15838 | { | |
15839 | struct tracepoint *t = (struct tracepoint *) b; | |
15840 | ||
15841 | if (t->number_on_target == num) | |
15842 | return t; | |
15843 | } | |
d5551862 SS |
15844 | |
15845 | return NULL; | |
15846 | } | |
15847 | ||
1042e4c0 | 15848 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15849 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15850 | If the argument is missing, the most recent tracepoint |
15851 | (tracepoint_count) is returned. */ | |
15852 | ||
d9b3f62e | 15853 | struct tracepoint * |
197f0a60 | 15854 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15855 | struct get_number_or_range_state *state) |
1042e4c0 | 15856 | { |
1042e4c0 SS |
15857 | struct breakpoint *t; |
15858 | int tpnum; | |
15859 | char *instring = arg == NULL ? NULL : *arg; | |
15860 | ||
197f0a60 TT |
15861 | if (state) |
15862 | { | |
15863 | gdb_assert (!state->finished); | |
15864 | tpnum = get_number_or_range (state); | |
15865 | } | |
15866 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15867 | tpnum = tracepoint_count; |
1042e4c0 | 15868 | else |
197f0a60 | 15869 | tpnum = get_number (arg); |
1042e4c0 SS |
15870 | |
15871 | if (tpnum <= 0) | |
15872 | { | |
15873 | if (instring && *instring) | |
15874 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15875 | instring); | |
15876 | else | |
5fa1d40e | 15877 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15878 | return NULL; |
15879 | } | |
15880 | ||
15881 | ALL_TRACEPOINTS (t) | |
15882 | if (t->number == tpnum) | |
15883 | { | |
d9b3f62e | 15884 | return (struct tracepoint *) t; |
1042e4c0 SS |
15885 | } |
15886 | ||
1042e4c0 SS |
15887 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15888 | return NULL; | |
15889 | } | |
15890 | ||
d9b3f62e PA |
15891 | void |
15892 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15893 | { | |
15894 | if (b->thread != -1) | |
15895 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15896 | ||
15897 | if (b->task != 0) | |
15898 | fprintf_unfiltered (fp, " task %d", b->task); | |
15899 | ||
15900 | fprintf_unfiltered (fp, "\n"); | |
15901 | } | |
15902 | ||
6149aea9 PA |
15903 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15904 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15905 | on each breakpoint and only include the ones for which it returns | |
15906 | non-zero. */ | |
15907 | ||
1042e4c0 | 15908 | static void |
6149aea9 PA |
15909 | save_breakpoints (char *filename, int from_tty, |
15910 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15911 | { |
15912 | struct breakpoint *tp; | |
6149aea9 | 15913 | int any = 0; |
1042e4c0 | 15914 | struct cleanup *cleanup; |
a7bdde9e | 15915 | struct ui_file *fp; |
6149aea9 | 15916 | int extra_trace_bits = 0; |
1042e4c0 | 15917 | |
6149aea9 PA |
15918 | if (filename == 0 || *filename == 0) |
15919 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15920 | |
15921 | /* See if we have anything to save. */ | |
6149aea9 | 15922 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15923 | { |
6149aea9 | 15924 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15925 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15926 | continue; |
15927 | ||
15928 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15929 | if (filter && !filter (tp)) | |
15930 | continue; | |
15931 | ||
15932 | any = 1; | |
15933 | ||
15934 | if (is_tracepoint (tp)) | |
15935 | { | |
15936 | extra_trace_bits = 1; | |
15937 | ||
15938 | /* We can stop searching. */ | |
15939 | break; | |
15940 | } | |
1042e4c0 | 15941 | } |
6149aea9 PA |
15942 | |
15943 | if (!any) | |
1042e4c0 | 15944 | { |
6149aea9 | 15945 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15946 | return; |
15947 | } | |
15948 | ||
c718be47 PA |
15949 | filename = tilde_expand (filename); |
15950 | cleanup = make_cleanup (xfree, filename); | |
15951 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15952 | if (!fp) |
6149aea9 PA |
15953 | error (_("Unable to open file '%s' for saving (%s)"), |
15954 | filename, safe_strerror (errno)); | |
a7bdde9e | 15955 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15956 | |
6149aea9 PA |
15957 | if (extra_trace_bits) |
15958 | save_trace_state_variables (fp); | |
8bf6485c | 15959 | |
6149aea9 | 15960 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15961 | { |
6149aea9 | 15962 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15963 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15964 | continue; |
8bf6485c | 15965 | |
6149aea9 PA |
15966 | /* If we have a filter, only save the breakpoints it accepts. */ |
15967 | if (filter && !filter (tp)) | |
15968 | continue; | |
15969 | ||
348d480f | 15970 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15971 | |
6149aea9 PA |
15972 | /* Note, we can't rely on tp->number for anything, as we can't |
15973 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15974 | instead. */ | |
15975 | ||
15976 | if (tp->cond_string) | |
15977 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15978 | ||
15979 | if (tp->ignore_count) | |
15980 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15981 | ||
2d9442cc | 15982 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15983 | { |
a7bdde9e VP |
15984 | volatile struct gdb_exception ex; |
15985 | ||
6149aea9 | 15986 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15987 | |
79a45e25 | 15988 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15989 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15990 | { |
79a45e25 | 15991 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15992 | } |
79a45e25 | 15993 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15994 | |
a7bdde9e VP |
15995 | if (ex.reason < 0) |
15996 | throw_exception (ex); | |
1042e4c0 | 15997 | |
a7bdde9e | 15998 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15999 | } |
6149aea9 PA |
16000 | |
16001 | if (tp->enable_state == bp_disabled) | |
16002 | fprintf_unfiltered (fp, "disable\n"); | |
16003 | ||
16004 | /* If this is a multi-location breakpoint, check if the locations | |
16005 | should be individually disabled. Watchpoint locations are | |
16006 | special, and not user visible. */ | |
16007 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
16008 | { | |
16009 | struct bp_location *loc; | |
16010 | int n = 1; | |
16011 | ||
16012 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
16013 | if (!loc->enabled) | |
16014 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
16015 | } | |
1042e4c0 | 16016 | } |
8bf6485c | 16017 | |
6149aea9 | 16018 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
16019 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
16020 | ||
1042e4c0 | 16021 | if (from_tty) |
6149aea9 | 16022 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 16023 | do_cleanups (cleanup); |
6149aea9 PA |
16024 | } |
16025 | ||
16026 | /* The `save breakpoints' command. */ | |
16027 | ||
16028 | static void | |
16029 | save_breakpoints_command (char *args, int from_tty) | |
16030 | { | |
16031 | save_breakpoints (args, from_tty, NULL); | |
16032 | } | |
16033 | ||
16034 | /* The `save tracepoints' command. */ | |
16035 | ||
16036 | static void | |
16037 | save_tracepoints_command (char *args, int from_tty) | |
16038 | { | |
16039 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
16040 | } |
16041 | ||
16042 | /* Create a vector of all tracepoints. */ | |
16043 | ||
16044 | VEC(breakpoint_p) * | |
eeae04df | 16045 | all_tracepoints (void) |
1042e4c0 SS |
16046 | { |
16047 | VEC(breakpoint_p) *tp_vec = 0; | |
16048 | struct breakpoint *tp; | |
16049 | ||
16050 | ALL_TRACEPOINTS (tp) | |
16051 | { | |
16052 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
16053 | } | |
16054 | ||
16055 | return tp_vec; | |
16056 | } | |
16057 | ||
c906108c | 16058 | \f |
4a64f543 MS |
16059 | /* This help string is used for the break, hbreak, tbreak and thbreak |
16060 | commands. It is defined as a macro to prevent duplication. | |
16061 | COMMAND should be a string constant containing the name of the | |
16062 | command. */ | |
31e2b00f | 16063 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
16064 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
16065 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
16066 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
16067 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
16068 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
16069 | If a line number is specified, break at start of code for that line.\n\ | |
16070 | If a function is specified, break at start of code for that function.\n\ | |
16071 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
16072 | With no LOCATION, uses current execution address of the selected\n\ |
16073 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
16074 | \n\ |
16075 | THREADNUM is the number from \"info threads\".\n\ | |
16076 | CONDITION is a boolean expression.\n\ | |
16077 | \n\ | |
d41c0fc8 PA |
16078 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
16079 | conditions are different.\n\ | |
31e2b00f AS |
16080 | \n\ |
16081 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
16082 | ||
44feb3ce TT |
16083 | /* List of subcommands for "catch". */ |
16084 | static struct cmd_list_element *catch_cmdlist; | |
16085 | ||
16086 | /* List of subcommands for "tcatch". */ | |
16087 | static struct cmd_list_element *tcatch_cmdlist; | |
16088 | ||
9ac4176b | 16089 | void |
44feb3ce | 16090 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 16091 | cmd_sfunc_ftype *sfunc, |
625e8578 | 16092 | completer_ftype *completer, |
44feb3ce TT |
16093 | void *user_data_catch, |
16094 | void *user_data_tcatch) | |
16095 | { | |
16096 | struct cmd_list_element *command; | |
16097 | ||
16098 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16099 | &catch_cmdlist); | |
16100 | set_cmd_sfunc (command, sfunc); | |
16101 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 16102 | set_cmd_completer (command, completer); |
44feb3ce TT |
16103 | |
16104 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16105 | &tcatch_cmdlist); | |
16106 | set_cmd_sfunc (command, sfunc); | |
16107 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 16108 | set_cmd_completer (command, completer); |
44feb3ce TT |
16109 | } |
16110 | ||
6c95b8df | 16111 | static void |
a79b8f6e | 16112 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 16113 | { |
fa3064dd YQ |
16114 | struct catch_syscall_inferior_data *inf_data |
16115 | = get_catch_syscall_inferior_data (inf); | |
16116 | ||
16117 | inf_data->total_syscalls_count = 0; | |
16118 | inf_data->any_syscall_count = 0; | |
16119 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
16120 | } |
16121 | ||
6149aea9 PA |
16122 | static void |
16123 | save_command (char *arg, int from_tty) | |
16124 | { | |
3e43a32a MS |
16125 | printf_unfiltered (_("\"save\" must be followed by " |
16126 | "the name of a save subcommand.\n")); | |
635c7e8a | 16127 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
16128 | } |
16129 | ||
84f4c1fe PM |
16130 | struct breakpoint * |
16131 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
16132 | void *data) | |
16133 | { | |
35df4500 | 16134 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 16135 | |
35df4500 | 16136 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
16137 | { |
16138 | if ((*callback) (b, data)) | |
16139 | return b; | |
16140 | } | |
16141 | ||
16142 | return NULL; | |
16143 | } | |
16144 | ||
0574c78f GB |
16145 | /* Zero if any of the breakpoint's locations could be a location where |
16146 | functions have been inlined, nonzero otherwise. */ | |
16147 | ||
16148 | static int | |
16149 | is_non_inline_function (struct breakpoint *b) | |
16150 | { | |
16151 | /* The shared library event breakpoint is set on the address of a | |
16152 | non-inline function. */ | |
16153 | if (b->type == bp_shlib_event) | |
16154 | return 1; | |
16155 | ||
16156 | return 0; | |
16157 | } | |
16158 | ||
16159 | /* Nonzero if the specified PC cannot be a location where functions | |
16160 | have been inlined. */ | |
16161 | ||
16162 | int | |
09ac7c10 TT |
16163 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
16164 | const struct target_waitstatus *ws) | |
0574c78f GB |
16165 | { |
16166 | struct breakpoint *b; | |
16167 | struct bp_location *bl; | |
16168 | ||
16169 | ALL_BREAKPOINTS (b) | |
16170 | { | |
16171 | if (!is_non_inline_function (b)) | |
16172 | continue; | |
16173 | ||
16174 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
16175 | { | |
16176 | if (!bl->shlib_disabled | |
09ac7c10 | 16177 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
16178 | return 1; |
16179 | } | |
16180 | } | |
16181 | ||
16182 | return 0; | |
16183 | } | |
16184 | ||
2f202fde JK |
16185 | /* Remove any references to OBJFILE which is going to be freed. */ |
16186 | ||
16187 | void | |
16188 | breakpoint_free_objfile (struct objfile *objfile) | |
16189 | { | |
16190 | struct bp_location **locp, *loc; | |
16191 | ||
16192 | ALL_BP_LOCATIONS (loc, locp) | |
16193 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
16194 | loc->symtab = NULL; | |
16195 | } | |
16196 | ||
2060206e PA |
16197 | void |
16198 | initialize_breakpoint_ops (void) | |
16199 | { | |
16200 | static int initialized = 0; | |
16201 | ||
16202 | struct breakpoint_ops *ops; | |
16203 | ||
16204 | if (initialized) | |
16205 | return; | |
16206 | initialized = 1; | |
16207 | ||
16208 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16209 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16210 | internal and momentary breakpoints, etc.). */ | |
16211 | ops = &bkpt_base_breakpoint_ops; | |
16212 | *ops = base_breakpoint_ops; | |
16213 | ops->re_set = bkpt_re_set; | |
16214 | ops->insert_location = bkpt_insert_location; | |
16215 | ops->remove_location = bkpt_remove_location; | |
16216 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
16217 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
16218 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
16219 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
16220 | |
16221 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16222 | ops = &bkpt_breakpoint_ops; | |
16223 | *ops = bkpt_base_breakpoint_ops; | |
16224 | ops->re_set = bkpt_re_set; | |
16225 | ops->resources_needed = bkpt_resources_needed; | |
16226 | ops->print_it = bkpt_print_it; | |
16227 | ops->print_mention = bkpt_print_mention; | |
16228 | ops->print_recreate = bkpt_print_recreate; | |
16229 | ||
16230 | /* Ranged breakpoints. */ | |
16231 | ops = &ranged_breakpoint_ops; | |
16232 | *ops = bkpt_breakpoint_ops; | |
16233 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16234 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16235 | ops->print_it = print_it_ranged_breakpoint; | |
16236 | ops->print_one = print_one_ranged_breakpoint; | |
16237 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16238 | ops->print_mention = print_mention_ranged_breakpoint; | |
16239 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16240 | ||
16241 | /* Internal breakpoints. */ | |
16242 | ops = &internal_breakpoint_ops; | |
16243 | *ops = bkpt_base_breakpoint_ops; | |
16244 | ops->re_set = internal_bkpt_re_set; | |
16245 | ops->check_status = internal_bkpt_check_status; | |
16246 | ops->print_it = internal_bkpt_print_it; | |
16247 | ops->print_mention = internal_bkpt_print_mention; | |
16248 | ||
16249 | /* Momentary breakpoints. */ | |
16250 | ops = &momentary_breakpoint_ops; | |
16251 | *ops = bkpt_base_breakpoint_ops; | |
16252 | ops->re_set = momentary_bkpt_re_set; | |
16253 | ops->check_status = momentary_bkpt_check_status; | |
16254 | ops->print_it = momentary_bkpt_print_it; | |
16255 | ops->print_mention = momentary_bkpt_print_mention; | |
16256 | ||
e2e4d78b JK |
16257 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16258 | ops = &longjmp_breakpoint_ops; | |
16259 | *ops = momentary_breakpoint_ops; | |
16260 | ops->dtor = longjmp_bkpt_dtor; | |
16261 | ||
55aa24fb SDJ |
16262 | /* Probe breakpoints. */ |
16263 | ops = &bkpt_probe_breakpoint_ops; | |
16264 | *ops = bkpt_breakpoint_ops; | |
16265 | ops->insert_location = bkpt_probe_insert_location; | |
16266 | ops->remove_location = bkpt_probe_remove_location; | |
16267 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16268 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16269 | ||
2060206e PA |
16270 | /* Watchpoints. */ |
16271 | ops = &watchpoint_breakpoint_ops; | |
16272 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16273 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16274 | ops->re_set = re_set_watchpoint; |
16275 | ops->insert_location = insert_watchpoint; | |
16276 | ops->remove_location = remove_watchpoint; | |
16277 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16278 | ops->check_status = check_status_watchpoint; | |
16279 | ops->resources_needed = resources_needed_watchpoint; | |
16280 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16281 | ops->print_it = print_it_watchpoint; | |
16282 | ops->print_mention = print_mention_watchpoint; | |
16283 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16284 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16285 | |
16286 | /* Masked watchpoints. */ | |
16287 | ops = &masked_watchpoint_breakpoint_ops; | |
16288 | *ops = watchpoint_breakpoint_ops; | |
16289 | ops->insert_location = insert_masked_watchpoint; | |
16290 | ops->remove_location = remove_masked_watchpoint; | |
16291 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16292 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16293 | ops->print_it = print_it_masked_watchpoint; | |
16294 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16295 | ops->print_mention = print_mention_masked_watchpoint; | |
16296 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16297 | ||
16298 | /* Tracepoints. */ | |
16299 | ops = &tracepoint_breakpoint_ops; | |
16300 | *ops = base_breakpoint_ops; | |
16301 | ops->re_set = tracepoint_re_set; | |
16302 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16303 | ops->print_one_detail = tracepoint_print_one_detail; | |
16304 | ops->print_mention = tracepoint_print_mention; | |
16305 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16306 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16307 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16308 | ops->decode_linespec = tracepoint_decode_linespec; | |
16309 | ||
55aa24fb SDJ |
16310 | /* Probe tracepoints. */ |
16311 | ops = &tracepoint_probe_breakpoint_ops; | |
16312 | *ops = tracepoint_breakpoint_ops; | |
16313 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16314 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16315 | ||
983af33b SDJ |
16316 | /* Static tracepoints with marker (`-m'). */ |
16317 | ops = &strace_marker_breakpoint_ops; | |
16318 | *ops = tracepoint_breakpoint_ops; | |
16319 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16320 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16321 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16322 | |
16323 | /* Fork catchpoints. */ | |
16324 | ops = &catch_fork_breakpoint_ops; | |
16325 | *ops = base_breakpoint_ops; | |
16326 | ops->insert_location = insert_catch_fork; | |
16327 | ops->remove_location = remove_catch_fork; | |
16328 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16329 | ops->print_it = print_it_catch_fork; | |
16330 | ops->print_one = print_one_catch_fork; | |
16331 | ops->print_mention = print_mention_catch_fork; | |
16332 | ops->print_recreate = print_recreate_catch_fork; | |
16333 | ||
16334 | /* Vfork catchpoints. */ | |
16335 | ops = &catch_vfork_breakpoint_ops; | |
16336 | *ops = base_breakpoint_ops; | |
16337 | ops->insert_location = insert_catch_vfork; | |
16338 | ops->remove_location = remove_catch_vfork; | |
16339 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16340 | ops->print_it = print_it_catch_vfork; | |
16341 | ops->print_one = print_one_catch_vfork; | |
16342 | ops->print_mention = print_mention_catch_vfork; | |
16343 | ops->print_recreate = print_recreate_catch_vfork; | |
16344 | ||
16345 | /* Exec catchpoints. */ | |
16346 | ops = &catch_exec_breakpoint_ops; | |
16347 | *ops = base_breakpoint_ops; | |
16348 | ops->dtor = dtor_catch_exec; | |
16349 | ops->insert_location = insert_catch_exec; | |
16350 | ops->remove_location = remove_catch_exec; | |
16351 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16352 | ops->print_it = print_it_catch_exec; | |
16353 | ops->print_one = print_one_catch_exec; | |
16354 | ops->print_mention = print_mention_catch_exec; | |
16355 | ops->print_recreate = print_recreate_catch_exec; | |
16356 | ||
16357 | /* Syscall catchpoints. */ | |
16358 | ops = &catch_syscall_breakpoint_ops; | |
16359 | *ops = base_breakpoint_ops; | |
16360 | ops->dtor = dtor_catch_syscall; | |
16361 | ops->insert_location = insert_catch_syscall; | |
16362 | ops->remove_location = remove_catch_syscall; | |
16363 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16364 | ops->print_it = print_it_catch_syscall; | |
16365 | ops->print_one = print_one_catch_syscall; | |
16366 | ops->print_mention = print_mention_catch_syscall; | |
16367 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16368 | |
16369 | /* Solib-related catchpoints. */ | |
16370 | ops = &catch_solib_breakpoint_ops; | |
16371 | *ops = base_breakpoint_ops; | |
16372 | ops->dtor = dtor_catch_solib; | |
16373 | ops->insert_location = insert_catch_solib; | |
16374 | ops->remove_location = remove_catch_solib; | |
16375 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16376 | ops->check_status = check_status_catch_solib; | |
16377 | ops->print_it = print_it_catch_solib; | |
16378 | ops->print_one = print_one_catch_solib; | |
16379 | ops->print_mention = print_mention_catch_solib; | |
16380 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16381 | |
16382 | ops = &dprintf_breakpoint_ops; | |
16383 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16384 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16385 | ops->resources_needed = bkpt_resources_needed; |
16386 | ops->print_it = bkpt_print_it; | |
16387 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16388 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16389 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16390 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16391 | } |
16392 | ||
8bfd80db YQ |
16393 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16394 | ||
16395 | static struct cmd_list_element *enablebreaklist = NULL; | |
16396 | ||
c906108c | 16397 | void |
fba45db2 | 16398 | _initialize_breakpoint (void) |
c906108c SS |
16399 | { |
16400 | struct cmd_list_element *c; | |
16401 | ||
2060206e PA |
16402 | initialize_breakpoint_ops (); |
16403 | ||
84acb35a | 16404 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16405 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16406 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16407 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16408 | |
55aa24fb SDJ |
16409 | breakpoint_objfile_key |
16410 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16411 | |
fa3064dd | 16412 | catch_syscall_inferior_data |
8e260fc0 TT |
16413 | = register_inferior_data_with_cleanup (NULL, |
16414 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16415 | |
c906108c SS |
16416 | breakpoint_chain = 0; |
16417 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16418 | before a breakpoint is set. */ | |
16419 | breakpoint_count = 0; | |
16420 | ||
1042e4c0 SS |
16421 | tracepoint_count = 0; |
16422 | ||
1bedd215 AC |
16423 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16424 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16425 | Usage is `ignore N COUNT'.")); | |
c906108c | 16426 | if (xdb_commands) |
c5aa993b | 16427 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16428 | |
1bedd215 AC |
16429 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16430 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16431 | Give breakpoint number as argument after \"commands\".\n\ |
16432 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16433 | The commands themselves follow starting on the next line.\n\ | |
16434 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16435 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16436 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16437 | |
d55637df | 16438 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16439 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16440 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16441 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16442 | set_cmd_completer (c, condition_completer); |
c906108c | 16443 | |
1bedd215 | 16444 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16445 | Set a temporary breakpoint.\n\ |
c906108c SS |
16446 | Like \"break\" except the breakpoint is only temporary,\n\ |
16447 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16448 | by using \"enable delete\" on the breakpoint number.\n\ |
16449 | \n" | |
16450 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16451 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16452 | |
1bedd215 | 16453 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16454 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16455 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16456 | some target hardware may not have this support.\n\ |
16457 | \n" | |
16458 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16459 | set_cmd_completer (c, location_completer); |
c906108c | 16460 | |
1bedd215 | 16461 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16462 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16463 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16464 | so it will be deleted when hit.\n\ |
16465 | \n" | |
16466 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16467 | set_cmd_completer (c, location_completer); |
c906108c | 16468 | |
1bedd215 AC |
16469 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16470 | Enable some breakpoints.\n\ | |
c906108c SS |
16471 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16472 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16473 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16474 | With a subcommand you can enable temporarily."), |
c906108c SS |
16475 | &enablelist, "enable ", 1, &cmdlist); |
16476 | if (xdb_commands) | |
1bedd215 AC |
16477 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16478 | Enable some breakpoints.\n\ | |
c906108c SS |
16479 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16480 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16481 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16482 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16483 | |
16484 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16485 | ||
84951ab5 | 16486 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16487 | Enable some breakpoints.\n\ |
c906108c SS |
16488 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16489 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16490 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16491 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16492 | |
1a966eab AC |
16493 | add_cmd ("once", no_class, enable_once_command, _("\ |
16494 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16495 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16496 | &enablebreaklist); |
16497 | ||
1a966eab AC |
16498 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16499 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16500 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16501 | &enablebreaklist); |
16502 | ||
816338b5 SS |
16503 | add_cmd ("count", no_class, enable_count_command, _("\ |
16504 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16505 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16506 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16507 | &enablebreaklist); | |
16508 | ||
1a966eab AC |
16509 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16510 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16511 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16512 | &enablelist); |
16513 | ||
1a966eab AC |
16514 | add_cmd ("once", no_class, enable_once_command, _("\ |
16515 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16516 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16517 | &enablelist); |
16518 | ||
16519 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16520 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16521 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16522 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16523 | &enablelist); |
16524 | ||
1bedd215 AC |
16525 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16526 | Disable some breakpoints.\n\ | |
c906108c SS |
16527 | Arguments are breakpoint numbers with spaces in between.\n\ |
16528 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16529 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16530 | &disablelist, "disable ", 1, &cmdlist); |
16531 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16532 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16533 | if (xdb_commands) | |
1bedd215 AC |
16534 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16535 | Disable some breakpoints.\n\ | |
c906108c SS |
16536 | Arguments are breakpoint numbers with spaces in between.\n\ |
16537 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16538 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16539 | |
1a966eab AC |
16540 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16541 | Disable some breakpoints.\n\ | |
c906108c SS |
16542 | Arguments are breakpoint numbers with spaces in between.\n\ |
16543 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16544 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16545 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16546 | &disablelist); |
16547 | ||
1bedd215 AC |
16548 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16549 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16550 | Arguments are breakpoint numbers with spaces in between.\n\ |
16551 | To delete all breakpoints, give no argument.\n\ | |
16552 | \n\ | |
16553 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16554 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16555 | &deletelist, "delete ", 1, &cmdlist); |
16556 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16557 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16558 | if (xdb_commands) |
1bedd215 AC |
16559 | add_com ("db", class_breakpoint, delete_command, _("\ |
16560 | Delete some breakpoints.\n\ | |
c906108c | 16561 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16562 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16563 | |
1a966eab AC |
16564 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16565 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16566 | Arguments are breakpoint numbers with spaces in between.\n\ |
16567 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16568 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16569 | &deletelist); |
16570 | ||
1bedd215 AC |
16571 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16572 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16573 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16574 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16575 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16576 | If an address is specified, breakpoints at that address are cleared.\n\ |
16577 | \n\ | |
16578 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16579 | is executing in.\n\ |
16580 | \n\ | |
1bedd215 | 16581 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16582 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16583 | |
1bedd215 | 16584 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16585 | Set breakpoint at specified line or function.\n" |
16586 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16587 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16588 | |
c906108c SS |
16589 | add_com_alias ("b", "break", class_run, 1); |
16590 | add_com_alias ("br", "break", class_run, 1); | |
16591 | add_com_alias ("bre", "break", class_run, 1); | |
16592 | add_com_alias ("brea", "break", class_run, 1); | |
16593 | ||
7681d515 PM |
16594 | if (xdb_commands) |
16595 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16596 | |
16597 | if (dbx_commands) | |
16598 | { | |
1bedd215 AC |
16599 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16600 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16601 | &stoplist, "stop ", 1, &cmdlist); |
16602 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16603 | _("Break in function or address."), &stoplist); |
c5aa993b | 16604 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16605 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16606 | add_com ("status", class_info, breakpoints_info, _("\ |
16607 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16608 | The \"Type\" column indicates one of:\n\ |
16609 | \tbreakpoint - normal breakpoint\n\ | |
16610 | \twatchpoint - watchpoint\n\ | |
16611 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16612 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16613 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16614 | address and file/line number respectively.\n\ |
16615 | \n\ | |
16616 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16617 | are set to the address of the last breakpoint listed unless the command\n\ |
16618 | is prefixed with \"server \".\n\n\ | |
c906108c | 16619 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16620 | breakpoint set.")); |
c906108c SS |
16621 | } |
16622 | ||
1bedd215 | 16623 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16624 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16625 | The \"Type\" column indicates one of:\n\ |
16626 | \tbreakpoint - normal breakpoint\n\ | |
16627 | \twatchpoint - watchpoint\n\ | |
16628 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16629 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16630 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16631 | address and file/line number respectively.\n\ |
16632 | \n\ | |
16633 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16634 | are set to the address of the last breakpoint listed unless the command\n\ |
16635 | is prefixed with \"server \".\n\n\ | |
c906108c | 16636 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16637 | breakpoint set.")); |
c906108c | 16638 | |
6b04bdb7 MS |
16639 | add_info_alias ("b", "breakpoints", 1); |
16640 | ||
c906108c | 16641 | if (xdb_commands) |
1bedd215 AC |
16642 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16643 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16644 | The \"Type\" column indicates one of:\n\ |
16645 | \tbreakpoint - normal breakpoint\n\ | |
16646 | \twatchpoint - watchpoint\n\ | |
16647 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16648 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16649 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16650 | address and file/line number respectively.\n\ |
16651 | \n\ | |
16652 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16653 | are set to the address of the last breakpoint listed unless the command\n\ |
16654 | is prefixed with \"server \".\n\n\ | |
c906108c | 16655 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16656 | breakpoint set.")); |
c906108c | 16657 | |
1a966eab AC |
16658 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16659 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16660 | The \"Type\" column indicates one of:\n\ |
16661 | \tbreakpoint - normal breakpoint\n\ | |
16662 | \twatchpoint - watchpoint\n\ | |
16663 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16664 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16665 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16666 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16667 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16668 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16669 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16670 | address and file/line number respectively.\n\ |
16671 | \n\ | |
16672 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16673 | are set to the address of the last breakpoint listed unless the command\n\ |
16674 | is prefixed with \"server \".\n\n\ | |
c906108c | 16675 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16676 | breakpoint set."), |
c906108c SS |
16677 | &maintenanceinfolist); |
16678 | ||
44feb3ce TT |
16679 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16680 | Set catchpoints to catch events."), | |
16681 | &catch_cmdlist, "catch ", | |
16682 | 0/*allow-unknown*/, &cmdlist); | |
16683 | ||
16684 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16685 | Set temporary catchpoints to catch events."), | |
16686 | &tcatch_cmdlist, "tcatch ", | |
16687 | 0/*allow-unknown*/, &cmdlist); | |
16688 | ||
44feb3ce TT |
16689 | add_catch_command ("fork", _("Catch calls to fork."), |
16690 | catch_fork_command_1, | |
a96d9b2e | 16691 | NULL, |
44feb3ce TT |
16692 | (void *) (uintptr_t) catch_fork_permanent, |
16693 | (void *) (uintptr_t) catch_fork_temporary); | |
16694 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16695 | catch_fork_command_1, | |
a96d9b2e | 16696 | NULL, |
44feb3ce TT |
16697 | (void *) (uintptr_t) catch_vfork_permanent, |
16698 | (void *) (uintptr_t) catch_vfork_temporary); | |
16699 | add_catch_command ("exec", _("Catch calls to exec."), | |
16700 | catch_exec_command_1, | |
a96d9b2e SDJ |
16701 | NULL, |
16702 | CATCH_PERMANENT, | |
16703 | CATCH_TEMPORARY); | |
edcc5120 TT |
16704 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16705 | Usage: catch load [REGEX]\n\ | |
16706 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16707 | catch_load_command_1, | |
16708 | NULL, | |
16709 | CATCH_PERMANENT, | |
16710 | CATCH_TEMPORARY); | |
16711 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16712 | Usage: catch unload [REGEX]\n\ | |
16713 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16714 | catch_unload_command_1, | |
16715 | NULL, | |
16716 | CATCH_PERMANENT, | |
16717 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16718 | add_catch_command ("syscall", _("\ |
16719 | Catch system calls by their names and/or numbers.\n\ | |
16720 | Arguments say which system calls to catch. If no arguments\n\ | |
16721 | are given, every system call will be caught.\n\ | |
16722 | Arguments, if given, should be one or more system call names\n\ | |
16723 | (if your system supports that), or system call numbers."), | |
16724 | catch_syscall_command_1, | |
16725 | catch_syscall_completer, | |
44feb3ce TT |
16726 | CATCH_PERMANENT, |
16727 | CATCH_TEMPORARY); | |
c5aa993b | 16728 | |
1bedd215 AC |
16729 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16730 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16731 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16732 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16733 | an expression changes.\n\ |
16734 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16735 | the memory to which it refers.")); | |
65d12d83 | 16736 | set_cmd_completer (c, expression_completer); |
c906108c | 16737 | |
1bedd215 AC |
16738 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16739 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16740 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16741 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16742 | an expression is read.\n\ |
16743 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16744 | the memory to which it refers.")); | |
65d12d83 | 16745 | set_cmd_completer (c, expression_completer); |
c906108c | 16746 | |
1bedd215 AC |
16747 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16748 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16749 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16750 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16751 | an expression is either read or written.\n\ |
16752 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16753 | the memory to which it refers.")); | |
65d12d83 | 16754 | set_cmd_completer (c, expression_completer); |
c906108c | 16755 | |
d77f58be | 16756 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16757 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16758 | |
920d2a44 AC |
16759 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16760 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16761 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16762 | &can_use_hw_watchpoints, _("\ | |
16763 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16764 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16765 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16766 | such is available. (However, any hardware watchpoints that were\n\ | |
16767 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16768 | hardware.)"), |
16769 | NULL, | |
920d2a44 | 16770 | show_can_use_hw_watchpoints, |
85c07804 | 16771 | &setlist, &showlist); |
c906108c SS |
16772 | |
16773 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16774 | |
1042e4c0 SS |
16775 | /* Tracepoint manipulation commands. */ |
16776 | ||
16777 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16778 | Set a tracepoint at specified line or function.\n\ | |
16779 | \n" | |
16780 | BREAK_ARGS_HELP ("trace") "\n\ | |
16781 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16782 | set_cmd_completer (c, location_completer); | |
16783 | ||
16784 | add_com_alias ("tp", "trace", class_alias, 0); | |
16785 | add_com_alias ("tr", "trace", class_alias, 1); | |
16786 | add_com_alias ("tra", "trace", class_alias, 1); | |
16787 | add_com_alias ("trac", "trace", class_alias, 1); | |
16788 | ||
7a697b8d SS |
16789 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16790 | Set a fast tracepoint at specified line or function.\n\ | |
16791 | \n" | |
16792 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16793 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16794 | set_cmd_completer (c, location_completer); | |
16795 | ||
0fb4aa4b PA |
16796 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16797 | Set a static tracepoint at specified line, function or marker.\n\ | |
16798 | \n\ | |
16799 | strace [LOCATION] [if CONDITION]\n\ | |
16800 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16801 | or -m MARKER_ID.\n\ | |
16802 | If a line number is specified, probe the marker at start of code\n\ | |
16803 | for that line. If a function is specified, probe the marker at start\n\ | |
16804 | of code for that function. If an address is specified, probe the marker\n\ | |
16805 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16806 | with that name. With no LOCATION, uses current execution address of\n\ | |
16807 | the selected stack frame.\n\ | |
16808 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16809 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16810 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16811 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16812 | \n\ | |
16813 | CONDITION is a boolean expression.\n\ | |
16814 | \n\ | |
d41c0fc8 PA |
16815 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16816 | conditions are different.\n\ | |
0fb4aa4b PA |
16817 | \n\ |
16818 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16819 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16820 | set_cmd_completer (c, location_completer); | |
16821 | ||
1042e4c0 | 16822 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16823 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16824 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16825 | last tracepoint set.")); | |
16826 | ||
16827 | add_info_alias ("tp", "tracepoints", 1); | |
16828 | ||
16829 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16830 | Delete specified tracepoints.\n\ | |
16831 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16832 | No argument means delete all tracepoints."), | |
16833 | &deletelist); | |
7e20dfcd | 16834 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16835 | |
16836 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16837 | Disable specified tracepoints.\n\ | |
16838 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16839 | No argument means disable all tracepoints."), | |
16840 | &disablelist); | |
16841 | deprecate_cmd (c, "disable"); | |
16842 | ||
16843 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16844 | Enable specified tracepoints.\n\ | |
16845 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16846 | No argument means enable all tracepoints."), | |
16847 | &enablelist); | |
16848 | deprecate_cmd (c, "enable"); | |
16849 | ||
16850 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16851 | Set the passcount for a tracepoint.\n\ | |
16852 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16853 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16854 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16855 | ||
6149aea9 PA |
16856 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16857 | _("Save breakpoint definitions as a script."), | |
16858 | &save_cmdlist, "save ", | |
16859 | 0/*allow-unknown*/, &cmdlist); | |
16860 | ||
16861 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16862 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16863 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16864 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16865 | session to restore them."), | |
16866 | &save_cmdlist); | |
16867 | set_cmd_completer (c, filename_completer); | |
16868 | ||
16869 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16870 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16871 | Use the 'source' command in another debug session to restore them."), |
16872 | &save_cmdlist); | |
1042e4c0 SS |
16873 | set_cmd_completer (c, filename_completer); |
16874 | ||
6149aea9 PA |
16875 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16876 | deprecate_cmd (c, "save tracepoints"); | |
16877 | ||
1bedd215 | 16878 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16879 | Breakpoint specific settings\n\ |
16880 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16881 | pending breakpoint behavior"), |
fa8d40ab JJ |
16882 | &breakpoint_set_cmdlist, "set breakpoint ", |
16883 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16884 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16885 | Breakpoint specific settings\n\ |
16886 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16887 | pending breakpoint behavior"), |
fa8d40ab JJ |
16888 | &breakpoint_show_cmdlist, "show breakpoint ", |
16889 | 0/*allow-unknown*/, &showlist); | |
16890 | ||
7915a72c AC |
16891 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16892 | &pending_break_support, _("\ | |
16893 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16894 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16895 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16896 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16897 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16898 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16899 | NULL, |
920d2a44 | 16900 | show_pending_break_support, |
6e1d7d6c AC |
16901 | &breakpoint_set_cmdlist, |
16902 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16903 | |
16904 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16905 | |
16906 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16907 | &automatic_hardware_breakpoints, _("\ | |
16908 | Set automatic usage of hardware breakpoints."), _("\ | |
16909 | Show automatic usage of hardware breakpoints."), _("\ | |
16910 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16911 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16912 | a warning will be emitted for such breakpoints."), | |
16913 | NULL, | |
16914 | show_automatic_hardware_breakpoints, | |
16915 | &breakpoint_set_cmdlist, | |
16916 | &breakpoint_show_cmdlist); | |
74960c60 | 16917 | |
72d0e2c5 YQ |
16918 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16919 | &always_inserted_mode, _("\ | |
74960c60 VP |
16920 | Set mode for inserting breakpoints."), _("\ |
16921 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16922 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16923 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16924 | breakpoints are inserted immediately and removed only when the user\n\ | |
16925 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16926 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16927 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16928 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16929 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16930 | NULL, |
16931 | &show_always_inserted_mode, | |
16932 | &breakpoint_set_cmdlist, | |
16933 | &breakpoint_show_cmdlist); | |
f1310107 | 16934 | |
b775012e LM |
16935 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16936 | condition_evaluation_enums, | |
16937 | &condition_evaluation_mode_1, _("\ | |
16938 | Set mode of breakpoint condition evaluation."), _("\ | |
16939 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16940 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16941 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16942 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16943 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16944 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16945 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16946 | be set to \"gdb\""), | |
16947 | &set_condition_evaluation_mode, | |
16948 | &show_condition_evaluation_mode, | |
16949 | &breakpoint_set_cmdlist, | |
16950 | &breakpoint_show_cmdlist); | |
16951 | ||
f1310107 TJB |
16952 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16953 | Set a breakpoint for an address range.\n\ | |
16954 | break-range START-LOCATION, END-LOCATION\n\ | |
16955 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16956 | LINENUM, for that line in the current file,\n\ | |
16957 | FILE:LINENUM, for that line in that file,\n\ | |
16958 | +OFFSET, for that number of lines after the current line\n\ | |
16959 | or the start of the range\n\ | |
16960 | FUNCTION, for the first line in that function,\n\ | |
16961 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16962 | *ADDRESS, for the instruction at that address.\n\ | |
16963 | \n\ | |
16964 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16965 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16966 | range (including START-LOCATION and END-LOCATION).")); | |
16967 | ||
e7e0cddf SS |
16968 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16969 | Set a dynamic printf at specified line or function.\n\ | |
16970 | dprintf location,format string,arg1,arg2,...\n\ | |
16971 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16972 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16973 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16974 | set_cmd_completer (c, location_completer); |
16975 | ||
16976 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16977 | dprintf_style_enums, &dprintf_style, _("\ | |
16978 | Set the style of usage for dynamic printf."), _("\ | |
16979 | Show the style of usage for dynamic printf."), _("\ | |
16980 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16981 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16982 | console, as with the \"printf\" command.\n\ | |
16983 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16984 | program; by default printf(), but you can choose a different function or\n\ | |
16985 | output stream by setting dprintf-function and dprintf-channel."), | |
16986 | update_dprintf_commands, NULL, | |
16987 | &setlist, &showlist); | |
16988 | ||
16989 | dprintf_function = xstrdup ("printf"); | |
16990 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16991 | &dprintf_function, _("\ | |
16992 | Set the function to use for dynamic printf"), _("\ | |
16993 | Show the function to use for dynamic printf"), NULL, | |
16994 | update_dprintf_commands, NULL, | |
16995 | &setlist, &showlist); | |
16996 | ||
16997 | dprintf_channel = xstrdup (""); | |
16998 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16999 | &dprintf_channel, _("\ | |
17000 | Set the channel to use for dynamic printf"), _("\ | |
17001 | Show the channel to use for dynamic printf"), NULL, | |
17002 | update_dprintf_commands, NULL, | |
17003 | &setlist, &showlist); | |
17004 | ||
d3ce09f5 SS |
17005 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
17006 | &disconnected_dprintf, _("\ | |
17007 | Set whether dprintf continues after GDB disconnects."), _("\ | |
17008 | Show whether dprintf continues after GDB disconnects."), _("\ | |
17009 | Use this to let dprintf commands continue to hit and produce output\n\ | |
17010 | even if GDB disconnects or detaches from the target."), | |
17011 | NULL, | |
17012 | NULL, | |
17013 | &setlist, &showlist); | |
17014 | ||
17015 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
17016 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
17017 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
17018 | ||
765dc015 | 17019 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
17020 | |
17021 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 17022 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 17023 | } |