Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
35 | #include "gdbthread.h" | |
36 | #include "target.h" | |
37 | #include "language.h" | |
0e9f083f | 38 | #include <string.h> |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
0225421b | 50 | #include "gdb_assert.h" |
fe898f56 | 51 | #include "block.h" |
a77053c2 | 52 | #include "solib.h" |
84acb35a JJ |
53 | #include "solist.h" |
54 | #include "observer.h" | |
60250e8b | 55 | #include "exceptions.h" |
765dc015 | 56 | #include "memattr.h" |
f7f9143b | 57 | #include "ada-lang.h" |
d1aa2f50 | 58 | #include "top.h" |
79a45b7d | 59 | #include "valprint.h" |
4efc6507 | 60 | #include "jit.h" |
a96d9b2e | 61 | #include "xml-syscall.h" |
65d79d4b | 62 | #include "parser-defs.h" |
55aa24fb SDJ |
63 | #include "gdb_regex.h" |
64 | #include "probe.h" | |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
be34f849 | 66 | #include "continuations.h" |
1bfeeb0f JL |
67 | #include "stack.h" |
68 | #include "skip.h" | |
b775012e | 69 | #include "ax-gdb.h" |
e2e4d78b | 70 | #include "dummy-frame.h" |
c906108c | 71 | |
d3ce09f5 SS |
72 | #include "format.h" |
73 | ||
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
104c1213 | 83 | |
e7e8980f YQ |
84 | /* Enums for exception-handling support. */ |
85 | enum exception_event_kind | |
86 | { | |
87 | EX_EVENT_THROW, | |
591f19e8 | 88 | EX_EVENT_RETHROW, |
e7e8980f YQ |
89 | EX_EVENT_CATCH |
90 | }; | |
91 | ||
4a64f543 | 92 | /* Prototypes for local functions. */ |
c906108c | 93 | |
a14ed312 | 94 | static void enable_delete_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void enable_once_command (char *, int); |
c906108c | 97 | |
816338b5 SS |
98 | static void enable_count_command (char *, int); |
99 | ||
a14ed312 | 100 | static void disable_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void enable_command (char *, int); |
c906108c | 103 | |
95a42b64 TT |
104 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
105 | void *), | |
106 | void *); | |
c906108c | 107 | |
a14ed312 | 108 | static void ignore_command (char *, int); |
c906108c | 109 | |
4efb68b1 | 110 | static int breakpoint_re_set_one (void *); |
c906108c | 111 | |
348d480f PA |
112 | static void breakpoint_re_set_default (struct breakpoint *); |
113 | ||
983af33b SDJ |
114 | static void create_sals_from_address_default (char **, |
115 | struct linespec_result *, | |
116 | enum bptype, char *, | |
117 | char **); | |
118 | ||
119 | static void create_breakpoints_sal_default (struct gdbarch *, | |
120 | struct linespec_result *, | |
e7e0cddf | 121 | char *, char *, enum bptype, |
983af33b SDJ |
122 | enum bpdisp, int, int, |
123 | int, | |
124 | const struct breakpoint_ops *, | |
44f238bb | 125 | int, int, int, unsigned); |
983af33b SDJ |
126 | |
127 | static void decode_linespec_default (struct breakpoint *, char **, | |
128 | struct symtabs_and_lines *); | |
129 | ||
a14ed312 | 130 | static void clear_command (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void catch_command (char *, int); |
c906108c | 133 | |
a9634178 | 134 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 135 | |
98deb0da | 136 | static void break_command_1 (char *, int, int); |
c906108c | 137 | |
a14ed312 | 138 | static void mention (struct breakpoint *); |
c906108c | 139 | |
348d480f PA |
140 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
141 | enum bptype, | |
c0a91b2b | 142 | const struct breakpoint_ops *); |
3742cc8b YQ |
143 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
144 | const struct symtab_and_line *); | |
145 | ||
4a64f543 MS |
146 | /* This function is used in gdbtk sources and thus can not be made |
147 | static. */ | |
63c252f8 | 148 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 149 | struct symtab_and_line, |
c0a91b2b TT |
150 | enum bptype, |
151 | const struct breakpoint_ops *); | |
c906108c | 152 | |
06edf0c0 PA |
153 | static struct breakpoint * |
154 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
155 | enum bptype type, | |
c0a91b2b | 156 | const struct breakpoint_ops *ops); |
06edf0c0 | 157 | |
76897487 KB |
158 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
159 | ||
a6d9a66e UW |
160 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
161 | CORE_ADDR bpaddr, | |
88f7da05 | 162 | enum bptype bptype); |
76897487 | 163 | |
6c95b8df PA |
164 | static void describe_other_breakpoints (struct gdbarch *, |
165 | struct program_space *, CORE_ADDR, | |
5af949e3 | 166 | struct obj_section *, int); |
c906108c | 167 | |
85d721b8 PA |
168 | static int watchpoint_locations_match (struct bp_location *loc1, |
169 | struct bp_location *loc2); | |
170 | ||
f1310107 TJB |
171 | static int breakpoint_location_address_match (struct bp_location *bl, |
172 | struct address_space *aspace, | |
173 | CORE_ADDR addr); | |
174 | ||
a14ed312 | 175 | static void breakpoints_info (char *, int); |
c906108c | 176 | |
d77f58be SS |
177 | static void watchpoints_info (char *, int); |
178 | ||
e5a67952 MS |
179 | static int breakpoint_1 (char *, int, |
180 | int (*) (const struct breakpoint *)); | |
c906108c | 181 | |
4efb68b1 | 182 | static int breakpoint_cond_eval (void *); |
c906108c | 183 | |
4efb68b1 | 184 | static void cleanup_executing_breakpoints (void *); |
c906108c | 185 | |
a14ed312 | 186 | static void commands_command (char *, int); |
c906108c | 187 | |
a14ed312 | 188 | static void condition_command (char *, int); |
c906108c | 189 | |
c5aa993b JM |
190 | typedef enum |
191 | { | |
192 | mark_inserted, | |
193 | mark_uninserted | |
194 | } | |
195 | insertion_state_t; | |
c906108c | 196 | |
0bde7532 | 197 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 198 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 199 | |
e514a9d6 | 200 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 201 | |
4efb68b1 | 202 | static int watchpoint_check (void *); |
c906108c | 203 | |
a14ed312 | 204 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 205 | |
a14ed312 | 206 | static int hw_breakpoint_used_count (void); |
c906108c | 207 | |
a1398e0c PA |
208 | static int hw_watchpoint_use_count (struct breakpoint *); |
209 | ||
210 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
211 | enum bptype type, | |
212 | int *other_type_used); | |
c906108c | 213 | |
a14ed312 | 214 | static void hbreak_command (char *, int); |
c906108c | 215 | |
a14ed312 | 216 | static void thbreak_command (char *, int); |
c906108c | 217 | |
816338b5 SS |
218 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
219 | int count); | |
c906108c | 220 | |
a14ed312 | 221 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 222 | |
a14ed312 | 223 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 228 | |
d03285ec UW |
229 | static void detach_single_step_breakpoints (void); |
230 | ||
6c95b8df PA |
231 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
232 | CORE_ADDR pc); | |
1aafd4da | 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 | |
d3ce09f5 SS |
299 | /* The style in which to perform a dynamic printf. This is a user |
300 | option because different output options have different tradeoffs; | |
301 | if GDB does the printing, there is better error handling if there | |
302 | is a problem with any of the arguments, but using an inferior | |
303 | function lets you have special-purpose printers and sending of | |
304 | output to the same place as compiled-in print functions. */ | |
305 | ||
306 | static const char dprintf_style_gdb[] = "gdb"; | |
307 | static const char dprintf_style_call[] = "call"; | |
308 | static const char dprintf_style_agent[] = "agent"; | |
309 | static const char *const dprintf_style_enums[] = { | |
310 | dprintf_style_gdb, | |
311 | dprintf_style_call, | |
312 | dprintf_style_agent, | |
313 | NULL | |
314 | }; | |
315 | static const char *dprintf_style = dprintf_style_gdb; | |
316 | ||
317 | /* The function to use for dynamic printf if the preferred style is to | |
318 | call into the inferior. The value is simply a string that is | |
319 | copied into the command, so it can be anything that GDB can | |
320 | evaluate to a callable address, not necessarily a function name. */ | |
321 | ||
322 | static char *dprintf_function = ""; | |
323 | ||
324 | /* The channel to use for dynamic printf if the preferred style is to | |
325 | call into the inferior; if a nonempty string, it will be passed to | |
326 | the call as the first argument, with the format string as the | |
327 | second. As with the dprintf function, this can be anything that | |
328 | GDB knows how to evaluate, so in addition to common choices like | |
329 | "stderr", this could be an app-specific expression like | |
330 | "mystreams[curlogger]". */ | |
331 | ||
332 | static char *dprintf_channel = ""; | |
333 | ||
334 | /* True if dprintf commands should continue to operate even if GDB | |
335 | has disconnected. */ | |
336 | static int disconnected_dprintf = 1; | |
337 | ||
5cea2a26 PA |
338 | /* A reference-counted struct command_line. This lets multiple |
339 | breakpoints share a single command list. */ | |
340 | struct counted_command_line | |
341 | { | |
342 | /* The reference count. */ | |
343 | int refc; | |
344 | ||
345 | /* The command list. */ | |
346 | struct command_line *commands; | |
347 | }; | |
348 | ||
349 | struct command_line * | |
350 | breakpoint_commands (struct breakpoint *b) | |
351 | { | |
352 | return b->commands ? b->commands->commands : NULL; | |
353 | } | |
3daf8fe5 | 354 | |
f3b1572e PA |
355 | /* Flag indicating that a command has proceeded the inferior past the |
356 | current breakpoint. */ | |
357 | ||
358 | static int breakpoint_proceeded; | |
359 | ||
956a9fb9 | 360 | const char * |
2cec12e5 AR |
361 | bpdisp_text (enum bpdisp disp) |
362 | { | |
4a64f543 MS |
363 | /* NOTE: the following values are a part of MI protocol and |
364 | represent values of 'disp' field returned when inferior stops at | |
365 | a breakpoint. */ | |
bc043ef3 | 366 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 367 | |
2cec12e5 AR |
368 | return bpdisps[(int) disp]; |
369 | } | |
c906108c | 370 | |
4a64f543 | 371 | /* Prototypes for exported functions. */ |
c906108c | 372 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 373 | if such is available. */ |
c906108c SS |
374 | static int can_use_hw_watchpoints; |
375 | ||
920d2a44 AC |
376 | static void |
377 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
378 | struct cmd_list_element *c, | |
379 | const char *value) | |
380 | { | |
3e43a32a MS |
381 | fprintf_filtered (file, |
382 | _("Debugger's willingness to use " | |
383 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
384 | value); |
385 | } | |
386 | ||
fa8d40ab JJ |
387 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
388 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 389 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
390 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
391 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
392 | static void |
393 | show_pending_break_support (struct ui_file *file, int from_tty, | |
394 | struct cmd_list_element *c, | |
395 | const char *value) | |
396 | { | |
3e43a32a MS |
397 | fprintf_filtered (file, |
398 | _("Debugger's behavior regarding " | |
399 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
400 | value); |
401 | } | |
fa8d40ab | 402 | |
765dc015 | 403 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 404 | set with "break" but falling in read-only memory. |
765dc015 VP |
405 | If 0, gdb will warn about such breakpoints, but won't automatically |
406 | use hardware breakpoints. */ | |
407 | static int automatic_hardware_breakpoints; | |
408 | static void | |
409 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
410 | struct cmd_list_element *c, | |
411 | const char *value) | |
412 | { | |
3e43a32a MS |
413 | fprintf_filtered (file, |
414 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
415 | value); |
416 | } | |
417 | ||
33e5cbd6 PA |
418 | /* If on, gdb will keep breakpoints inserted even as inferior is |
419 | stopped, and immediately insert any new breakpoints. If off, gdb | |
420 | will insert breakpoints into inferior only when resuming it, and | |
421 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
422 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
423 | ||
72d0e2c5 YQ |
424 | static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; |
425 | ||
33e5cbd6 | 426 | static void |
74960c60 | 427 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 428 | struct cmd_list_element *c, const char *value) |
74960c60 | 429 | { |
72d0e2c5 | 430 | if (always_inserted_mode == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
431 | fprintf_filtered (file, |
432 | _("Always inserted breakpoint " | |
433 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
434 | value, |
435 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
436 | else | |
3e43a32a MS |
437 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
438 | value); | |
74960c60 VP |
439 | } |
440 | ||
33e5cbd6 PA |
441 | int |
442 | breakpoints_always_inserted_mode (void) | |
443 | { | |
72d0e2c5 YQ |
444 | return (always_inserted_mode == AUTO_BOOLEAN_TRUE |
445 | || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); | |
33e5cbd6 | 446 | } |
765dc015 | 447 | |
b775012e LM |
448 | static const char condition_evaluation_both[] = "host or target"; |
449 | ||
450 | /* Modes for breakpoint condition evaluation. */ | |
451 | static const char condition_evaluation_auto[] = "auto"; | |
452 | static const char condition_evaluation_host[] = "host"; | |
453 | static const char condition_evaluation_target[] = "target"; | |
454 | static const char *const condition_evaluation_enums[] = { | |
455 | condition_evaluation_auto, | |
456 | condition_evaluation_host, | |
457 | condition_evaluation_target, | |
458 | NULL | |
459 | }; | |
460 | ||
461 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
462 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
463 | ||
464 | /* Global that we use to display information to the user (gets its value from | |
465 | condition_evaluation_mode_1. */ | |
466 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
467 | ||
468 | /* Translate a condition evaluation mode MODE into either "host" | |
469 | or "target". This is used mostly to translate from "auto" to the | |
470 | real setting that is being used. It returns the translated | |
471 | evaluation mode. */ | |
472 | ||
473 | static const char * | |
474 | translate_condition_evaluation_mode (const char *mode) | |
475 | { | |
476 | if (mode == condition_evaluation_auto) | |
477 | { | |
478 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
479 | return condition_evaluation_target; | |
480 | else | |
481 | return condition_evaluation_host; | |
482 | } | |
483 | else | |
484 | return mode; | |
485 | } | |
486 | ||
487 | /* Discovers what condition_evaluation_auto translates to. */ | |
488 | ||
489 | static const char * | |
490 | breakpoint_condition_evaluation_mode (void) | |
491 | { | |
492 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
493 | } | |
494 | ||
495 | /* Return true if GDB should evaluate breakpoint conditions or false | |
496 | otherwise. */ | |
497 | ||
498 | static int | |
499 | gdb_evaluates_breakpoint_condition_p (void) | |
500 | { | |
501 | const char *mode = breakpoint_condition_evaluation_mode (); | |
502 | ||
503 | return (mode == condition_evaluation_host); | |
504 | } | |
505 | ||
a14ed312 | 506 | void _initialize_breakpoint (void); |
c906108c | 507 | |
c906108c SS |
508 | /* Are we executing breakpoint commands? */ |
509 | static int executing_breakpoint_commands; | |
510 | ||
c02f5703 MS |
511 | /* Are overlay event breakpoints enabled? */ |
512 | static int overlay_events_enabled; | |
513 | ||
e09342b5 TJB |
514 | /* See description in breakpoint.h. */ |
515 | int target_exact_watchpoints = 0; | |
516 | ||
c906108c | 517 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 518 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 519 | current breakpoint. */ |
c906108c | 520 | |
5c44784c | 521 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 522 | |
5c44784c JM |
523 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
524 | for (B = breakpoint_chain; \ | |
525 | B ? (TMP=B->next, 1): 0; \ | |
526 | B = TMP) | |
c906108c | 527 | |
4a64f543 MS |
528 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
529 | not provided so update_global_location_list must not be called | |
530 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 531 | |
876fa593 JK |
532 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
533 | for (BP_TMP = bp_location; \ | |
534 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
535 | BP_TMP++) | |
7cc221ef | 536 | |
b775012e LM |
537 | /* Iterates through locations with address ADDRESS for the currently selected |
538 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
539 | to where the loop should start from. | |
540 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
541 | appropriate location to start with. */ | |
542 | ||
543 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
544 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
545 | BP_LOCP_TMP = BP_LOCP_START; \ | |
546 | BP_LOCP_START \ | |
547 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
548 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
549 | BP_LOCP_TMP++) | |
550 | ||
1042e4c0 SS |
551 | /* Iterator for tracepoints only. */ |
552 | ||
553 | #define ALL_TRACEPOINTS(B) \ | |
554 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 555 | if (is_tracepoint (B)) |
1042e4c0 | 556 | |
7cc221ef | 557 | /* Chains of all breakpoints defined. */ |
c906108c SS |
558 | |
559 | struct breakpoint *breakpoint_chain; | |
560 | ||
876fa593 JK |
561 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
562 | ||
563 | static struct bp_location **bp_location; | |
564 | ||
565 | /* Number of elements of BP_LOCATION. */ | |
566 | ||
567 | static unsigned bp_location_count; | |
568 | ||
4a64f543 MS |
569 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
570 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
571 | result from bp_location_has_shadow. You can use it for roughly | |
572 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
573 | an address you need to read. */ | |
876fa593 JK |
574 | |
575 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
576 | ||
4a64f543 MS |
577 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
578 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
579 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
580 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
581 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
582 | |
583 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 584 | |
4a64f543 MS |
585 | /* The locations that no longer correspond to any breakpoint, unlinked |
586 | from bp_location array, but for which a hit may still be reported | |
587 | by a target. */ | |
20874c92 VP |
588 | VEC(bp_location_p) *moribund_locations = NULL; |
589 | ||
c906108c SS |
590 | /* Number of last breakpoint made. */ |
591 | ||
95a42b64 TT |
592 | static int breakpoint_count; |
593 | ||
86b17b60 PA |
594 | /* The value of `breakpoint_count' before the last command that |
595 | created breakpoints. If the last (break-like) command created more | |
596 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
597 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
598 | static int prev_breakpoint_count; | |
c906108c | 599 | |
1042e4c0 SS |
600 | /* Number of last tracepoint made. */ |
601 | ||
95a42b64 | 602 | static int tracepoint_count; |
1042e4c0 | 603 | |
6149aea9 PA |
604 | static struct cmd_list_element *breakpoint_set_cmdlist; |
605 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 606 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 607 | |
468d015d JJ |
608 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
609 | static int | |
610 | breakpoint_enabled (struct breakpoint *b) | |
611 | { | |
0d381245 | 612 | return (b->enable_state == bp_enabled); |
468d015d JJ |
613 | } |
614 | ||
c906108c SS |
615 | /* Set breakpoint count to NUM. */ |
616 | ||
95a42b64 | 617 | static void |
fba45db2 | 618 | set_breakpoint_count (int num) |
c906108c | 619 | { |
86b17b60 | 620 | prev_breakpoint_count = breakpoint_count; |
c906108c | 621 | breakpoint_count = num; |
4fa62494 | 622 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
623 | } |
624 | ||
86b17b60 PA |
625 | /* Used by `start_rbreak_breakpoints' below, to record the current |
626 | breakpoint count before "rbreak" creates any breakpoint. */ | |
627 | static int rbreak_start_breakpoint_count; | |
628 | ||
95a42b64 TT |
629 | /* Called at the start an "rbreak" command to record the first |
630 | breakpoint made. */ | |
86b17b60 | 631 | |
95a42b64 TT |
632 | void |
633 | start_rbreak_breakpoints (void) | |
634 | { | |
86b17b60 | 635 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
636 | } |
637 | ||
638 | /* Called at the end of an "rbreak" command to record the last | |
639 | breakpoint made. */ | |
86b17b60 | 640 | |
95a42b64 TT |
641 | void |
642 | end_rbreak_breakpoints (void) | |
643 | { | |
86b17b60 | 644 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
645 | } |
646 | ||
4a64f543 | 647 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
648 | |
649 | void | |
fba45db2 | 650 | clear_breakpoint_hit_counts (void) |
c906108c SS |
651 | { |
652 | struct breakpoint *b; | |
653 | ||
654 | ALL_BREAKPOINTS (b) | |
655 | b->hit_count = 0; | |
656 | } | |
657 | ||
9add0f1b TT |
658 | /* Allocate a new counted_command_line with reference count of 1. |
659 | The new structure owns COMMANDS. */ | |
660 | ||
661 | static struct counted_command_line * | |
662 | alloc_counted_command_line (struct command_line *commands) | |
663 | { | |
664 | struct counted_command_line *result | |
665 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 666 | |
9add0f1b TT |
667 | result->refc = 1; |
668 | result->commands = commands; | |
669 | return result; | |
670 | } | |
671 | ||
672 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
673 | ||
674 | static void | |
675 | incref_counted_command_line (struct counted_command_line *cmd) | |
676 | { | |
677 | if (cmd) | |
678 | ++cmd->refc; | |
679 | } | |
680 | ||
681 | /* Decrement reference count. If the reference count reaches 0, | |
682 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
683 | nothing if *CMDP is NULL. */ | |
684 | ||
685 | static void | |
686 | decref_counted_command_line (struct counted_command_line **cmdp) | |
687 | { | |
688 | if (*cmdp) | |
689 | { | |
690 | if (--(*cmdp)->refc == 0) | |
691 | { | |
692 | free_command_lines (&(*cmdp)->commands); | |
693 | xfree (*cmdp); | |
694 | } | |
695 | *cmdp = NULL; | |
696 | } | |
697 | } | |
698 | ||
699 | /* A cleanup function that calls decref_counted_command_line. */ | |
700 | ||
701 | static void | |
702 | do_cleanup_counted_command_line (void *arg) | |
703 | { | |
704 | decref_counted_command_line (arg); | |
705 | } | |
706 | ||
707 | /* Create a cleanup that calls decref_counted_command_line on the | |
708 | argument. */ | |
709 | ||
710 | static struct cleanup * | |
711 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
712 | { | |
713 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
714 | } | |
715 | ||
c906108c | 716 | \f |
48cb2d85 VP |
717 | /* Return the breakpoint with the specified number, or NULL |
718 | if the number does not refer to an existing breakpoint. */ | |
719 | ||
720 | struct breakpoint * | |
721 | get_breakpoint (int num) | |
722 | { | |
723 | struct breakpoint *b; | |
724 | ||
725 | ALL_BREAKPOINTS (b) | |
726 | if (b->number == num) | |
727 | return b; | |
728 | ||
729 | return NULL; | |
730 | } | |
5c44784c | 731 | |
c906108c | 732 | \f |
adc36818 | 733 | |
b775012e LM |
734 | /* Mark locations as "conditions have changed" in case the target supports |
735 | evaluating conditions on its side. */ | |
736 | ||
737 | static void | |
738 | mark_breakpoint_modified (struct breakpoint *b) | |
739 | { | |
740 | struct bp_location *loc; | |
741 | ||
742 | /* This is only meaningful if the target is | |
743 | evaluating conditions and if the user has | |
744 | opted for condition evaluation on the target's | |
745 | side. */ | |
746 | if (gdb_evaluates_breakpoint_condition_p () | |
747 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
748 | return; | |
749 | ||
750 | if (!is_breakpoint (b)) | |
751 | return; | |
752 | ||
753 | for (loc = b->loc; loc; loc = loc->next) | |
754 | loc->condition_changed = condition_modified; | |
755 | } | |
756 | ||
757 | /* Mark location as "conditions have changed" in case the target supports | |
758 | evaluating conditions on its side. */ | |
759 | ||
760 | static void | |
761 | mark_breakpoint_location_modified (struct bp_location *loc) | |
762 | { | |
763 | /* This is only meaningful if the target is | |
764 | evaluating conditions and if the user has | |
765 | opted for condition evaluation on the target's | |
766 | side. */ | |
767 | if (gdb_evaluates_breakpoint_condition_p () | |
768 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
769 | ||
770 | return; | |
771 | ||
772 | if (!is_breakpoint (loc->owner)) | |
773 | return; | |
774 | ||
775 | loc->condition_changed = condition_modified; | |
776 | } | |
777 | ||
778 | /* Sets the condition-evaluation mode using the static global | |
779 | condition_evaluation_mode. */ | |
780 | ||
781 | static void | |
782 | set_condition_evaluation_mode (char *args, int from_tty, | |
783 | struct cmd_list_element *c) | |
784 | { | |
b775012e LM |
785 | const char *old_mode, *new_mode; |
786 | ||
787 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
788 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
789 | { | |
790 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
791 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
792 | "Using host evaluation mode instead.")); | |
793 | return; | |
794 | } | |
795 | ||
796 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
797 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
798 | ||
abf1152a JK |
799 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
800 | settings was "auto". */ | |
801 | condition_evaluation_mode = condition_evaluation_mode_1; | |
802 | ||
b775012e LM |
803 | /* Only update the mode if the user picked a different one. */ |
804 | if (new_mode != old_mode) | |
805 | { | |
806 | struct bp_location *loc, **loc_tmp; | |
807 | /* If the user switched to a different evaluation mode, we | |
808 | need to synch the changes with the target as follows: | |
809 | ||
810 | "host" -> "target": Send all (valid) conditions to the target. | |
811 | "target" -> "host": Remove all the conditions from the target. | |
812 | */ | |
813 | ||
b775012e LM |
814 | if (new_mode == condition_evaluation_target) |
815 | { | |
816 | /* Mark everything modified and synch conditions with the | |
817 | target. */ | |
818 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
819 | mark_breakpoint_location_modified (loc); | |
820 | } | |
821 | else | |
822 | { | |
823 | /* Manually mark non-duplicate locations to synch conditions | |
824 | with the target. We do this to remove all the conditions the | |
825 | target knows about. */ | |
826 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
827 | if (is_breakpoint (loc->owner) && loc->inserted) | |
828 | loc->needs_update = 1; | |
829 | } | |
830 | ||
831 | /* Do the update. */ | |
832 | update_global_location_list (1); | |
833 | } | |
834 | ||
835 | return; | |
836 | } | |
837 | ||
838 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
839 | what "auto" is translating to. */ | |
840 | ||
841 | static void | |
842 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
843 | struct cmd_list_element *c, const char *value) | |
844 | { | |
845 | if (condition_evaluation_mode == condition_evaluation_auto) | |
846 | fprintf_filtered (file, | |
847 | _("Breakpoint condition evaluation " | |
848 | "mode is %s (currently %s).\n"), | |
849 | value, | |
850 | breakpoint_condition_evaluation_mode ()); | |
851 | else | |
852 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
853 | value); | |
854 | } | |
855 | ||
856 | /* A comparison function for bp_location AP and BP that is used by | |
857 | bsearch. This comparison function only cares about addresses, unlike | |
858 | the more general bp_location_compare function. */ | |
859 | ||
860 | static int | |
861 | bp_location_compare_addrs (const void *ap, const void *bp) | |
862 | { | |
863 | struct bp_location *a = *(void **) ap; | |
864 | struct bp_location *b = *(void **) bp; | |
865 | ||
866 | if (a->address == b->address) | |
867 | return 0; | |
868 | else | |
869 | return ((a->address > b->address) - (a->address < b->address)); | |
870 | } | |
871 | ||
872 | /* Helper function to skip all bp_locations with addresses | |
873 | less than ADDRESS. It returns the first bp_location that | |
874 | is greater than or equal to ADDRESS. If none is found, just | |
875 | return NULL. */ | |
876 | ||
877 | static struct bp_location ** | |
878 | get_first_locp_gte_addr (CORE_ADDR address) | |
879 | { | |
880 | struct bp_location dummy_loc; | |
881 | struct bp_location *dummy_locp = &dummy_loc; | |
882 | struct bp_location **locp_found = NULL; | |
883 | ||
884 | /* Initialize the dummy location's address field. */ | |
885 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
886 | dummy_loc.address = address; | |
887 | ||
888 | /* Find a close match to the first location at ADDRESS. */ | |
889 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
890 | sizeof (struct bp_location **), | |
891 | bp_location_compare_addrs); | |
892 | ||
893 | /* Nothing was found, nothing left to do. */ | |
894 | if (locp_found == NULL) | |
895 | return NULL; | |
896 | ||
897 | /* We may have found a location that is at ADDRESS but is not the first in the | |
898 | location's list. Go backwards (if possible) and locate the first one. */ | |
899 | while ((locp_found - 1) >= bp_location | |
900 | && (*(locp_found - 1))->address == address) | |
901 | locp_found--; | |
902 | ||
903 | return locp_found; | |
904 | } | |
905 | ||
adc36818 PM |
906 | void |
907 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
908 | int from_tty) | |
909 | { | |
3a5c3e22 PA |
910 | xfree (b->cond_string); |
911 | b->cond_string = NULL; | |
adc36818 | 912 | |
3a5c3e22 | 913 | if (is_watchpoint (b)) |
adc36818 | 914 | { |
3a5c3e22 PA |
915 | struct watchpoint *w = (struct watchpoint *) b; |
916 | ||
917 | xfree (w->cond_exp); | |
918 | w->cond_exp = NULL; | |
919 | } | |
920 | else | |
921 | { | |
922 | struct bp_location *loc; | |
923 | ||
924 | for (loc = b->loc; loc; loc = loc->next) | |
925 | { | |
926 | xfree (loc->cond); | |
927 | loc->cond = NULL; | |
b775012e LM |
928 | |
929 | /* No need to free the condition agent expression | |
930 | bytecode (if we have one). We will handle this | |
931 | when we go through update_global_location_list. */ | |
3a5c3e22 | 932 | } |
adc36818 | 933 | } |
adc36818 PM |
934 | |
935 | if (*exp == 0) | |
936 | { | |
937 | if (from_tty) | |
938 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
939 | } | |
940 | else | |
941 | { | |
bbc13ae3 | 942 | const char *arg = exp; |
cc59ec59 | 943 | |
adc36818 PM |
944 | /* I don't know if it matters whether this is the string the user |
945 | typed in or the decompiled expression. */ | |
946 | b->cond_string = xstrdup (arg); | |
947 | b->condition_not_parsed = 0; | |
948 | ||
949 | if (is_watchpoint (b)) | |
950 | { | |
3a5c3e22 PA |
951 | struct watchpoint *w = (struct watchpoint *) b; |
952 | ||
adc36818 PM |
953 | innermost_block = NULL; |
954 | arg = exp; | |
1bb9788d | 955 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
956 | if (*arg) |
957 | error (_("Junk at end of expression")); | |
3a5c3e22 | 958 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
959 | } |
960 | else | |
961 | { | |
3a5c3e22 PA |
962 | struct bp_location *loc; |
963 | ||
adc36818 PM |
964 | for (loc = b->loc; loc; loc = loc->next) |
965 | { | |
966 | arg = exp; | |
967 | loc->cond = | |
1bb9788d TT |
968 | parse_exp_1 (&arg, loc->address, |
969 | block_for_pc (loc->address), 0); | |
adc36818 PM |
970 | if (*arg) |
971 | error (_("Junk at end of expression")); | |
972 | } | |
973 | } | |
974 | } | |
b775012e LM |
975 | mark_breakpoint_modified (b); |
976 | ||
8d3788bd | 977 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
978 | } |
979 | ||
d55637df TT |
980 | /* Completion for the "condition" command. */ |
981 | ||
982 | static VEC (char_ptr) * | |
6f937416 PA |
983 | condition_completer (struct cmd_list_element *cmd, |
984 | const char *text, const char *word) | |
d55637df | 985 | { |
6f937416 | 986 | const char *space; |
d55637df | 987 | |
6f937416 PA |
988 | text = skip_spaces_const (text); |
989 | space = skip_to_space_const (text); | |
d55637df TT |
990 | if (*space == '\0') |
991 | { | |
992 | int len; | |
993 | struct breakpoint *b; | |
994 | VEC (char_ptr) *result = NULL; | |
995 | ||
996 | if (text[0] == '$') | |
997 | { | |
998 | /* We don't support completion of history indices. */ | |
999 | if (isdigit (text[1])) | |
1000 | return NULL; | |
1001 | return complete_internalvar (&text[1]); | |
1002 | } | |
1003 | ||
1004 | /* We're completing the breakpoint number. */ | |
1005 | len = strlen (text); | |
1006 | ||
1007 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1008 | { |
1009 | char number[50]; | |
1010 | ||
1011 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1012 | ||
1013 | if (strncmp (number, text, len) == 0) | |
1014 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1015 | } | |
d55637df TT |
1016 | |
1017 | return result; | |
1018 | } | |
1019 | ||
1020 | /* We're completing the expression part. */ | |
6f937416 | 1021 | text = skip_spaces_const (space); |
d55637df TT |
1022 | return expression_completer (cmd, text, word); |
1023 | } | |
1024 | ||
c906108c SS |
1025 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1026 | ||
1027 | static void | |
fba45db2 | 1028 | condition_command (char *arg, int from_tty) |
c906108c | 1029 | { |
52f0bd74 | 1030 | struct breakpoint *b; |
c906108c | 1031 | char *p; |
52f0bd74 | 1032 | int bnum; |
c906108c SS |
1033 | |
1034 | if (arg == 0) | |
e2e0b3e5 | 1035 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1036 | |
1037 | p = arg; | |
1038 | bnum = get_number (&p); | |
5c44784c | 1039 | if (bnum == 0) |
8a3fe4f8 | 1040 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1041 | |
1042 | ALL_BREAKPOINTS (b) | |
1043 | if (b->number == bnum) | |
2f069f6f | 1044 | { |
6dddc817 DE |
1045 | /* Check if this breakpoint has a "stop" method implemented in an |
1046 | extension language. This method and conditions entered into GDB | |
1047 | from the CLI are mutually exclusive. */ | |
1048 | const struct extension_language_defn *extlang | |
1049 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1050 | ||
1051 | if (extlang != NULL) | |
1052 | { | |
1053 | error (_("Only one stop condition allowed. There is currently" | |
1054 | " a %s stop condition defined for this breakpoint."), | |
1055 | ext_lang_capitalized_name (extlang)); | |
1056 | } | |
2566ad2d | 1057 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1058 | |
1059 | if (is_breakpoint (b)) | |
1060 | update_global_location_list (1); | |
1061 | ||
2f069f6f JB |
1062 | return; |
1063 | } | |
c906108c | 1064 | |
8a3fe4f8 | 1065 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1066 | } |
1067 | ||
a7bdde9e VP |
1068 | /* Check that COMMAND do not contain commands that are suitable |
1069 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1070 | Throw if any such commands is found. */ |
1071 | ||
a7bdde9e VP |
1072 | static void |
1073 | check_no_tracepoint_commands (struct command_line *commands) | |
1074 | { | |
1075 | struct command_line *c; | |
cc59ec59 | 1076 | |
a7bdde9e VP |
1077 | for (c = commands; c; c = c->next) |
1078 | { | |
1079 | int i; | |
1080 | ||
1081 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1082 | error (_("The 'while-stepping' command can " |
1083 | "only be used for tracepoints")); | |
a7bdde9e VP |
1084 | |
1085 | for (i = 0; i < c->body_count; ++i) | |
1086 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1087 | ||
1088 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1089 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1090 | command directly. */ |
1091 | if (strstr (c->line, "collect ") == c->line) | |
1092 | error (_("The 'collect' command can only be used for tracepoints")); | |
1093 | ||
51661e93 VP |
1094 | if (strstr (c->line, "teval ") == c->line) |
1095 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1096 | } |
1097 | } | |
1098 | ||
d77f58be SS |
1099 | /* Encapsulate tests for different types of tracepoints. */ |
1100 | ||
d9b3f62e PA |
1101 | static int |
1102 | is_tracepoint_type (enum bptype type) | |
1103 | { | |
1104 | return (type == bp_tracepoint | |
1105 | || type == bp_fast_tracepoint | |
1106 | || type == bp_static_tracepoint); | |
1107 | } | |
1108 | ||
a7bdde9e | 1109 | int |
d77f58be | 1110 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1111 | { |
d9b3f62e | 1112 | return is_tracepoint_type (b->type); |
a7bdde9e | 1113 | } |
d9b3f62e | 1114 | |
e5dd4106 | 1115 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1116 | breakpoint. This function will throw an exception if a problem is |
1117 | found. */ | |
48cb2d85 | 1118 | |
95a42b64 TT |
1119 | static void |
1120 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1121 | struct command_line *commands) | |
48cb2d85 | 1122 | { |
d77f58be | 1123 | if (is_tracepoint (b)) |
a7bdde9e | 1124 | { |
c9a6ce02 | 1125 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1126 | struct command_line *c; |
1127 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1128 | |
1129 | /* Reset the while-stepping step count. The previous commands | |
1130 | might have included a while-stepping action, while the new | |
1131 | ones might not. */ | |
1132 | t->step_count = 0; | |
1133 | ||
1134 | /* We need to verify that each top-level element of commands is | |
1135 | valid for tracepoints, that there's at most one | |
1136 | while-stepping element, and that the while-stepping's body | |
1137 | has valid tracing commands excluding nested while-stepping. | |
1138 | We also need to validate the tracepoint action line in the | |
1139 | context of the tracepoint --- validate_actionline actually | |
1140 | has side effects, like setting the tracepoint's | |
1141 | while-stepping STEP_COUNT, in addition to checking if the | |
1142 | collect/teval actions parse and make sense in the | |
1143 | tracepoint's context. */ | |
a7bdde9e VP |
1144 | for (c = commands; c; c = c->next) |
1145 | { | |
a7bdde9e VP |
1146 | if (c->control_type == while_stepping_control) |
1147 | { | |
1148 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1149 | error (_("The 'while-stepping' command " |
1150 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1151 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1152 | error (_("The 'while-stepping' command " |
1153 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1154 | |
1155 | if (while_stepping) | |
3e43a32a MS |
1156 | error (_("The 'while-stepping' command " |
1157 | "can be used only once")); | |
a7bdde9e VP |
1158 | else |
1159 | while_stepping = c; | |
1160 | } | |
c9a6ce02 PA |
1161 | |
1162 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1163 | } |
1164 | if (while_stepping) | |
1165 | { | |
1166 | struct command_line *c2; | |
1167 | ||
1168 | gdb_assert (while_stepping->body_count == 1); | |
1169 | c2 = while_stepping->body_list[0]; | |
1170 | for (; c2; c2 = c2->next) | |
1171 | { | |
a7bdde9e VP |
1172 | if (c2->control_type == while_stepping_control) |
1173 | error (_("The 'while-stepping' command cannot be nested")); | |
1174 | } | |
1175 | } | |
1176 | } | |
1177 | else | |
1178 | { | |
1179 | check_no_tracepoint_commands (commands); | |
1180 | } | |
95a42b64 TT |
1181 | } |
1182 | ||
0fb4aa4b PA |
1183 | /* Return a vector of all the static tracepoints set at ADDR. The |
1184 | caller is responsible for releasing the vector. */ | |
1185 | ||
1186 | VEC(breakpoint_p) * | |
1187 | static_tracepoints_here (CORE_ADDR addr) | |
1188 | { | |
1189 | struct breakpoint *b; | |
1190 | VEC(breakpoint_p) *found = 0; | |
1191 | struct bp_location *loc; | |
1192 | ||
1193 | ALL_BREAKPOINTS (b) | |
1194 | if (b->type == bp_static_tracepoint) | |
1195 | { | |
1196 | for (loc = b->loc; loc; loc = loc->next) | |
1197 | if (loc->address == addr) | |
1198 | VEC_safe_push(breakpoint_p, found, b); | |
1199 | } | |
1200 | ||
1201 | return found; | |
1202 | } | |
1203 | ||
95a42b64 | 1204 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1205 | validate that only allowed commands are included. */ |
95a42b64 TT |
1206 | |
1207 | void | |
4a64f543 MS |
1208 | breakpoint_set_commands (struct breakpoint *b, |
1209 | struct command_line *commands) | |
95a42b64 TT |
1210 | { |
1211 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1212 | |
9add0f1b TT |
1213 | decref_counted_command_line (&b->commands); |
1214 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1215 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1216 | } |
1217 | ||
45a43567 TT |
1218 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1219 | is not the same as the "silent" that may appear in the breakpoint's | |
1220 | commands. */ | |
1221 | ||
1222 | void | |
1223 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1224 | { | |
1225 | int old_silent = b->silent; | |
1226 | ||
1227 | b->silent = silent; | |
1228 | if (old_silent != silent) | |
8d3788bd | 1229 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1230 | } |
1231 | ||
1232 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1233 | breakpoint work for any thread. */ | |
1234 | ||
1235 | void | |
1236 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1237 | { | |
1238 | int old_thread = b->thread; | |
1239 | ||
1240 | b->thread = thread; | |
1241 | if (old_thread != thread) | |
8d3788bd | 1242 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1243 | } |
1244 | ||
1245 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1246 | breakpoint work for any task. */ | |
1247 | ||
1248 | void | |
1249 | breakpoint_set_task (struct breakpoint *b, int task) | |
1250 | { | |
1251 | int old_task = b->task; | |
1252 | ||
1253 | b->task = task; | |
1254 | if (old_task != task) | |
8d3788bd | 1255 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1256 | } |
1257 | ||
95a42b64 TT |
1258 | void |
1259 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1260 | { |
1261 | struct breakpoint *b = closure; | |
cc59ec59 | 1262 | |
6f937416 | 1263 | validate_actionline (line, b); |
a7bdde9e VP |
1264 | } |
1265 | ||
95a42b64 TT |
1266 | /* A structure used to pass information through |
1267 | map_breakpoint_numbers. */ | |
1268 | ||
1269 | struct commands_info | |
1270 | { | |
1271 | /* True if the command was typed at a tty. */ | |
1272 | int from_tty; | |
86b17b60 PA |
1273 | |
1274 | /* The breakpoint range spec. */ | |
1275 | char *arg; | |
1276 | ||
95a42b64 TT |
1277 | /* Non-NULL if the body of the commands are being read from this |
1278 | already-parsed command. */ | |
1279 | struct command_line *control; | |
86b17b60 | 1280 | |
95a42b64 TT |
1281 | /* The command lines read from the user, or NULL if they have not |
1282 | yet been read. */ | |
1283 | struct counted_command_line *cmd; | |
1284 | }; | |
1285 | ||
1286 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1287 | commands_command. */ | |
1288 | ||
c906108c | 1289 | static void |
95a42b64 | 1290 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1291 | { |
95a42b64 | 1292 | struct commands_info *info = data; |
c906108c | 1293 | |
95a42b64 TT |
1294 | if (info->cmd == NULL) |
1295 | { | |
1296 | struct command_line *l; | |
5c44784c | 1297 | |
95a42b64 TT |
1298 | if (info->control != NULL) |
1299 | l = copy_command_lines (info->control->body_list[0]); | |
1300 | else | |
86b17b60 PA |
1301 | { |
1302 | struct cleanup *old_chain; | |
1303 | char *str; | |
c5aa993b | 1304 | |
3e43a32a MS |
1305 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1306 | "%s, one per line."), | |
86b17b60 PA |
1307 | info->arg); |
1308 | ||
1309 | old_chain = make_cleanup (xfree, str); | |
1310 | ||
1311 | l = read_command_lines (str, | |
1312 | info->from_tty, 1, | |
d77f58be | 1313 | (is_tracepoint (b) |
86b17b60 PA |
1314 | ? check_tracepoint_command : 0), |
1315 | b); | |
1316 | ||
1317 | do_cleanups (old_chain); | |
1318 | } | |
a7bdde9e | 1319 | |
95a42b64 TT |
1320 | info->cmd = alloc_counted_command_line (l); |
1321 | } | |
1322 | ||
1323 | /* If a breakpoint was on the list more than once, we don't need to | |
1324 | do anything. */ | |
1325 | if (b->commands != info->cmd) | |
1326 | { | |
1327 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1328 | incref_counted_command_line (info->cmd); | |
1329 | decref_counted_command_line (&b->commands); | |
1330 | b->commands = info->cmd; | |
8d3788bd | 1331 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1332 | } |
95a42b64 TT |
1333 | } |
1334 | ||
1335 | static void | |
4a64f543 MS |
1336 | commands_command_1 (char *arg, int from_tty, |
1337 | struct command_line *control) | |
95a42b64 TT |
1338 | { |
1339 | struct cleanup *cleanups; | |
1340 | struct commands_info info; | |
1341 | ||
1342 | info.from_tty = from_tty; | |
1343 | info.control = control; | |
1344 | info.cmd = NULL; | |
1345 | /* If we read command lines from the user, then `info' will hold an | |
1346 | extra reference to the commands that we must clean up. */ | |
1347 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1348 | ||
1349 | if (arg == NULL || !*arg) | |
1350 | { | |
86b17b60 | 1351 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1352 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1353 | breakpoint_count); | |
95a42b64 TT |
1354 | else if (breakpoint_count > 0) |
1355 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1356 | else |
1357 | { | |
1358 | /* So that we don't try to free the incoming non-NULL | |
1359 | argument in the cleanup below. Mapping breakpoint | |
1360 | numbers will fail in this case. */ | |
1361 | arg = NULL; | |
1362 | } | |
95a42b64 | 1363 | } |
9766ced4 SS |
1364 | else |
1365 | /* The command loop has some static state, so we need to preserve | |
1366 | our argument. */ | |
1367 | arg = xstrdup (arg); | |
86b17b60 PA |
1368 | |
1369 | if (arg != NULL) | |
1370 | make_cleanup (xfree, arg); | |
1371 | ||
1372 | info.arg = arg; | |
95a42b64 TT |
1373 | |
1374 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1375 | ||
1376 | if (info.cmd == NULL) | |
1377 | error (_("No breakpoints specified.")); | |
1378 | ||
1379 | do_cleanups (cleanups); | |
1380 | } | |
1381 | ||
1382 | static void | |
1383 | commands_command (char *arg, int from_tty) | |
1384 | { | |
1385 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1386 | } |
40c03ae8 EZ |
1387 | |
1388 | /* Like commands_command, but instead of reading the commands from | |
1389 | input stream, takes them from an already parsed command structure. | |
1390 | ||
1391 | This is used by cli-script.c to DTRT with breakpoint commands | |
1392 | that are part of if and while bodies. */ | |
1393 | enum command_control_type | |
1394 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1395 | { | |
95a42b64 TT |
1396 | commands_command_1 (arg, 0, cmd); |
1397 | return simple_control; | |
40c03ae8 | 1398 | } |
876fa593 JK |
1399 | |
1400 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1401 | ||
1402 | static int | |
1403 | bp_location_has_shadow (struct bp_location *bl) | |
1404 | { | |
1405 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1406 | return 0; | |
1407 | if (!bl->inserted) | |
1408 | return 0; | |
1409 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1410 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1411 | return 0; |
1412 | return 1; | |
1413 | } | |
1414 | ||
8defab1a | 1415 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1416 | by replacing any memory breakpoints with their shadowed contents. |
1417 | ||
35c63cd8 JB |
1418 | If READBUF is not NULL, this buffer must not overlap with any of |
1419 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1420 | a failed assertion internal error will be raised. | |
1421 | ||
876fa593 | 1422 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1423 | bl->address - bp_location_placed_address_before_address_max |
1424 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1425 | The range we were requested to resolve shadows for is: |
1426 | memaddr ... memaddr + len | |
1427 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1428 | memaddr + len <= (bl->address |
1429 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1430 | and: |
35df4500 | 1431 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1432 | |
8defab1a | 1433 | void |
f0ba3972 PA |
1434 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1435 | const gdb_byte *writebuf_org, | |
1436 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1437 | { |
4a64f543 MS |
1438 | /* Left boundary, right boundary and median element of our binary |
1439 | search. */ | |
876fa593 JK |
1440 | unsigned bc_l, bc_r, bc; |
1441 | ||
4a64f543 MS |
1442 | /* Find BC_L which is a leftmost element which may affect BUF |
1443 | content. It is safe to report lower value but a failure to | |
1444 | report higher one. */ | |
876fa593 JK |
1445 | |
1446 | bc_l = 0; | |
1447 | bc_r = bp_location_count; | |
1448 | while (bc_l + 1 < bc_r) | |
1449 | { | |
35df4500 | 1450 | struct bp_location *bl; |
876fa593 JK |
1451 | |
1452 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1453 | bl = bp_location[bc]; |
876fa593 | 1454 | |
4a64f543 MS |
1455 | /* Check first BL->ADDRESS will not overflow due to the added |
1456 | constant. Then advance the left boundary only if we are sure | |
1457 | the BC element can in no way affect the BUF content (MEMADDR | |
1458 | to MEMADDR + LEN range). | |
876fa593 | 1459 | |
4a64f543 MS |
1460 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1461 | offset so that we cannot miss a breakpoint with its shadow | |
1462 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1463 | |
35df4500 TJB |
1464 | if ((bl->address + bp_location_shadow_len_after_address_max |
1465 | >= bl->address) | |
1466 | && (bl->address + bp_location_shadow_len_after_address_max | |
1467 | <= memaddr)) | |
876fa593 JK |
1468 | bc_l = bc; |
1469 | else | |
1470 | bc_r = bc; | |
1471 | } | |
1472 | ||
128070bb PA |
1473 | /* Due to the binary search above, we need to make sure we pick the |
1474 | first location that's at BC_L's address. E.g., if there are | |
1475 | multiple locations at the same address, BC_L may end up pointing | |
1476 | at a duplicate location, and miss the "master"/"inserted" | |
1477 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1478 | B: | |
1479 | ||
1480 | L1@A, L2@A, L3@B, ... | |
1481 | ||
1482 | BC_L could end up pointing at location L2, while the "master" | |
1483 | location could be L1. Since the `loc->inserted' flag is only set | |
1484 | on "master" locations, we'd forget to restore the shadow of L1 | |
1485 | and L2. */ | |
1486 | while (bc_l > 0 | |
1487 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1488 | bc_l--; | |
1489 | ||
876fa593 JK |
1490 | /* Now do full processing of the found relevant range of elements. */ |
1491 | ||
1492 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1493 | { |
35df4500 | 1494 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1495 | CORE_ADDR bp_addr = 0; |
1496 | int bp_size = 0; | |
1497 | int bptoffset = 0; | |
1498 | ||
35df4500 TJB |
1499 | /* bp_location array has BL->OWNER always non-NULL. */ |
1500 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1501 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1502 | bl->owner->number); |
ffce0d52 | 1503 | |
e5dd4106 | 1504 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1505 | content. */ |
1506 | ||
35df4500 TJB |
1507 | if (bl->address >= bp_location_placed_address_before_address_max |
1508 | && memaddr + len <= (bl->address | |
1509 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1510 | break; |
1511 | ||
35df4500 | 1512 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1513 | continue; |
35df4500 | 1514 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1515 | current_program_space->aspace, 0)) |
1516 | continue; | |
1517 | ||
c5aa993b JM |
1518 | /* Addresses and length of the part of the breakpoint that |
1519 | we need to copy. */ | |
35df4500 TJB |
1520 | bp_addr = bl->target_info.placed_address; |
1521 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1522 | |
c5aa993b JM |
1523 | if (bp_addr + bp_size <= memaddr) |
1524 | /* The breakpoint is entirely before the chunk of memory we | |
1525 | are reading. */ | |
1526 | continue; | |
8defab1a | 1527 | |
c5aa993b JM |
1528 | if (bp_addr >= memaddr + len) |
1529 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1530 | reading. */ |
c5aa993b | 1531 | continue; |
c5aa993b | 1532 | |
8defab1a DJ |
1533 | /* Offset within shadow_contents. */ |
1534 | if (bp_addr < memaddr) | |
1535 | { | |
1536 | /* Only copy the second part of the breakpoint. */ | |
1537 | bp_size -= memaddr - bp_addr; | |
1538 | bptoffset = memaddr - bp_addr; | |
1539 | bp_addr = memaddr; | |
1540 | } | |
c5aa993b | 1541 | |
8defab1a DJ |
1542 | if (bp_addr + bp_size > memaddr + len) |
1543 | { | |
1544 | /* Only copy the first part of the breakpoint. */ | |
1545 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1546 | } | |
c5aa993b | 1547 | |
f0ba3972 PA |
1548 | if (readbuf != NULL) |
1549 | { | |
35c63cd8 JB |
1550 | /* Verify that the readbuf buffer does not overlap with |
1551 | the shadow_contents buffer. */ | |
1552 | gdb_assert (bl->target_info.shadow_contents >= readbuf + len | |
1553 | || readbuf >= (bl->target_info.shadow_contents | |
1554 | + bl->target_info.shadow_len)); | |
1555 | ||
f0ba3972 PA |
1556 | /* Update the read buffer with this inserted breakpoint's |
1557 | shadow. */ | |
1558 | memcpy (readbuf + bp_addr - memaddr, | |
1559 | bl->target_info.shadow_contents + bptoffset, bp_size); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | struct gdbarch *gdbarch = bl->gdbarch; | |
1564 | const unsigned char *bp; | |
1565 | CORE_ADDR placed_address = bl->target_info.placed_address; | |
20ced3e4 | 1566 | int placed_size = bl->target_info.placed_size; |
f0ba3972 PA |
1567 | |
1568 | /* Update the shadow with what we want to write to memory. */ | |
1569 | memcpy (bl->target_info.shadow_contents + bptoffset, | |
1570 | writebuf_org + bp_addr - memaddr, bp_size); | |
1571 | ||
1572 | /* Determine appropriate breakpoint contents and size for this | |
1573 | address. */ | |
1574 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); | |
1575 | ||
1576 | /* Update the final write buffer with this inserted | |
1577 | breakpoint's INSN. */ | |
1578 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1579 | } | |
c5aa993b | 1580 | } |
c906108c | 1581 | } |
c906108c | 1582 | \f |
c5aa993b | 1583 | |
b775012e LM |
1584 | /* Return true if BPT is either a software breakpoint or a hardware |
1585 | breakpoint. */ | |
1586 | ||
1587 | int | |
1588 | is_breakpoint (const struct breakpoint *bpt) | |
1589 | { | |
1590 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1591 | || bpt->type == bp_hardware_breakpoint |
1592 | || bpt->type == bp_dprintf); | |
b775012e LM |
1593 | } |
1594 | ||
60e1c644 PA |
1595 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1596 | ||
a5606eee | 1597 | static int |
d77f58be | 1598 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1599 | { |
1600 | return (bpt->type == bp_hardware_watchpoint | |
1601 | || bpt->type == bp_read_watchpoint | |
1602 | || bpt->type == bp_access_watchpoint); | |
1603 | } | |
7270d8f2 | 1604 | |
60e1c644 PA |
1605 | /* Return true if BPT is of any watchpoint kind, hardware or |
1606 | software. */ | |
1607 | ||
3a5c3e22 | 1608 | int |
d77f58be | 1609 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1610 | { |
1611 | return (is_hardware_watchpoint (bpt) | |
1612 | || bpt->type == bp_watchpoint); | |
1613 | } | |
1614 | ||
3a5c3e22 PA |
1615 | /* Returns true if the current thread and its running state are safe |
1616 | to evaluate or update watchpoint B. Watchpoints on local | |
1617 | expressions need to be evaluated in the context of the thread that | |
1618 | was current when the watchpoint was created, and, that thread needs | |
1619 | to be stopped to be able to select the correct frame context. | |
1620 | Watchpoints on global expressions can be evaluated on any thread, | |
1621 | and in any state. It is presently left to the target allowing | |
1622 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1623 | |
1624 | static int | |
3a5c3e22 | 1625 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1626 | { |
d0d8b0c6 JK |
1627 | return (b->base.pspace == current_program_space |
1628 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1629 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1630 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1631 | } |
1632 | ||
d0fb5eae JK |
1633 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1634 | associated bp_watchpoint_scope breakpoint. */ | |
1635 | ||
1636 | static void | |
3a5c3e22 | 1637 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1638 | { |
3a5c3e22 | 1639 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1640 | |
1641 | if (b->related_breakpoint != b) | |
1642 | { | |
1643 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1644 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1645 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1646 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1647 | b->related_breakpoint = b; | |
1648 | } | |
1649 | b->disposition = disp_del_at_next_stop; | |
1650 | } | |
1651 | ||
567e1b4e JB |
1652 | /* Assuming that B is a watchpoint: |
1653 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1654 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1655 | - Evaluate the condition if there is one, and store the result |
1656 | in b->loc->cond. | |
a5606eee VP |
1657 | - Update the list of values that must be watched in B->loc. |
1658 | ||
4a64f543 MS |
1659 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1660 | nothing. If this is local watchpoint that is out of scope, delete | |
1661 | it. | |
1662 | ||
1663 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1664 | removed + inserted on each stop here. Normal breakpoints must | |
1665 | never be removed because they might be missed by a running thread | |
1666 | when debugging in non-stop mode. On the other hand, hardware | |
1667 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1668 | to each LWP since they are stored in each LWP's hardware debug | |
1669 | registers. Therefore, such LWP must be stopped first in order to | |
1670 | be able to modify its hardware watchpoints. | |
1671 | ||
1672 | Hardware watchpoints must be reset exactly once after being | |
1673 | presented to the user. It cannot be done sooner, because it would | |
1674 | reset the data used to present the watchpoint hit to the user. And | |
1675 | it must not be done later because it could display the same single | |
1676 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1677 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1678 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1679 | not user-visible - its hit is suppressed if the memory content has | |
1680 | not changed. | |
1681 | ||
1682 | The following constraints influence the location where we can reset | |
1683 | hardware watchpoints: | |
1684 | ||
1685 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1686 | called several times when GDB stops. | |
1687 | ||
1688 | [linux] | |
1689 | * Multiple hardware watchpoints can be hit at the same time, | |
1690 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1691 | hit at a time as the reason for stopping, and all the other hits | |
1692 | are presented later, one after the other, each time the user | |
1693 | requests the execution to be resumed. Execution is not resumed | |
1694 | for the threads still having pending hit event stored in | |
1695 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1696 | the inferior on the first stop the thread hit event is kept being | |
1697 | reported from its cached value by linux_nat_stopped_data_address | |
1698 | until the real thread resume happens after the watchpoint gets | |
1699 | presented and thus its LWP_INFO->STATUS gets reset. | |
1700 | ||
1701 | Therefore the hardware watchpoint hit can get safely reset on the | |
1702 | watchpoint removal from inferior. */ | |
a79d3c27 | 1703 | |
b40ce68a | 1704 | static void |
3a5c3e22 | 1705 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1706 | { |
a5606eee | 1707 | int within_current_scope; |
a5606eee | 1708 | struct frame_id saved_frame_id; |
66076460 | 1709 | int frame_saved; |
a5606eee | 1710 | |
f6bc2008 PA |
1711 | /* If this is a local watchpoint, we only want to check if the |
1712 | watchpoint frame is in scope if the current thread is the thread | |
1713 | that was used to create the watchpoint. */ | |
1714 | if (!watchpoint_in_thread_scope (b)) | |
1715 | return; | |
1716 | ||
3a5c3e22 | 1717 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1718 | return; |
1719 | ||
66076460 | 1720 | frame_saved = 0; |
a5606eee VP |
1721 | |
1722 | /* Determine if the watchpoint is within scope. */ | |
1723 | if (b->exp_valid_block == NULL) | |
1724 | within_current_scope = 1; | |
1725 | else | |
1726 | { | |
b5db5dfc UW |
1727 | struct frame_info *fi = get_current_frame (); |
1728 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1729 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1730 | ||
1731 | /* If we're in a function epilogue, unwinding may not work | |
1732 | properly, so do not attempt to recreate locations at this | |
1733 | point. See similar comments in watchpoint_check. */ | |
1734 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1735 | return; | |
66076460 DJ |
1736 | |
1737 | /* Save the current frame's ID so we can restore it after | |
1738 | evaluating the watchpoint expression on its own frame. */ | |
1739 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1740 | took a frame parameter, so that we didn't have to change the | |
1741 | selected frame. */ | |
1742 | frame_saved = 1; | |
1743 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1744 | ||
a5606eee VP |
1745 | fi = frame_find_by_id (b->watchpoint_frame); |
1746 | within_current_scope = (fi != NULL); | |
1747 | if (within_current_scope) | |
1748 | select_frame (fi); | |
1749 | } | |
1750 | ||
b5db5dfc UW |
1751 | /* We don't free locations. They are stored in the bp_location array |
1752 | and update_global_location_list will eventually delete them and | |
1753 | remove breakpoints if needed. */ | |
3a5c3e22 | 1754 | b->base.loc = NULL; |
b5db5dfc | 1755 | |
a5606eee VP |
1756 | if (within_current_scope && reparse) |
1757 | { | |
bbc13ae3 | 1758 | const char *s; |
d63d0675 | 1759 | |
a5606eee VP |
1760 | if (b->exp) |
1761 | { | |
1762 | xfree (b->exp); | |
1763 | b->exp = NULL; | |
1764 | } | |
d63d0675 | 1765 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1766 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1767 | /* If the meaning of expression itself changed, the old value is |
1768 | no longer relevant. We don't want to report a watchpoint hit | |
1769 | to the user when the old value and the new value may actually | |
1770 | be completely different objects. */ | |
1771 | value_free (b->val); | |
fa4727a6 DJ |
1772 | b->val = NULL; |
1773 | b->val_valid = 0; | |
60e1c644 PA |
1774 | |
1775 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1776 | expression is stored in the breakpoint object, not in the | |
1777 | locations (re)created below. */ | |
3a5c3e22 | 1778 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1779 | { |
1780 | if (b->cond_exp != NULL) | |
1781 | { | |
1782 | xfree (b->cond_exp); | |
1783 | b->cond_exp = NULL; | |
1784 | } | |
1785 | ||
3a5c3e22 | 1786 | s = b->base.cond_string; |
1bb9788d | 1787 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1788 | } |
a5606eee | 1789 | } |
a5606eee VP |
1790 | |
1791 | /* If we failed to parse the expression, for example because | |
1792 | it refers to a global variable in a not-yet-loaded shared library, | |
1793 | don't try to insert watchpoint. We don't automatically delete | |
1794 | such watchpoint, though, since failure to parse expression | |
1795 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1796 | if (!target_has_execution) |
2d134ed3 PA |
1797 | { |
1798 | /* Without execution, memory can't change. No use to try and | |
1799 | set watchpoint locations. The watchpoint will be reset when | |
1800 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1801 | if (!can_use_hw_watchpoints) |
1802 | { | |
1803 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1804 | b->base.type = bp_watchpoint; | |
1805 | else | |
638aa5a1 AB |
1806 | error (_("Can't set read/access watchpoint when " |
1807 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1808 | } |
2d134ed3 PA |
1809 | } |
1810 | else if (within_current_scope && b->exp) | |
a5606eee | 1811 | { |
0cf6dd15 | 1812 | int pc = 0; |
fa4727a6 | 1813 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1814 | struct program_space *frame_pspace; |
a5606eee | 1815 | |
3a1115a0 | 1816 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1817 | |
a5606eee VP |
1818 | /* Avoid setting b->val if it's already set. The meaning of |
1819 | b->val is 'the last value' user saw, and we should update | |
1820 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1821 | happens, the code that reports it updates b->val directly. |
1822 | We don't keep track of the memory value for masked | |
1823 | watchpoints. */ | |
3a5c3e22 | 1824 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1825 | { |
1826 | b->val = v; | |
1827 | b->val_valid = 1; | |
1828 | } | |
a5606eee | 1829 | |
2d134ed3 PA |
1830 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1831 | ||
a5606eee | 1832 | /* Look at each value on the value chain. */ |
9fa40276 | 1833 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1834 | { |
1835 | /* If it's a memory location, and GDB actually needed | |
1836 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1837 | must watch it. If the first value returned is |
1838 | still lazy, that means an error occurred reading it; | |
1839 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1840 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1841 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1842 | { |
1843 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1844 | |
a5606eee VP |
1845 | /* We only watch structs and arrays if user asked |
1846 | for it explicitly, never if they just happen to | |
1847 | appear in the middle of some value chain. */ | |
fa4727a6 | 1848 | if (v == result |
a5606eee VP |
1849 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1850 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1851 | { | |
1852 | CORE_ADDR addr; | |
744a8059 | 1853 | int type; |
a5606eee VP |
1854 | struct bp_location *loc, **tmp; |
1855 | ||
42ae5230 | 1856 | addr = value_address (v); |
a5606eee | 1857 | type = hw_write; |
3a5c3e22 | 1858 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1859 | type = hw_read; |
3a5c3e22 | 1860 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1861 | type = hw_access; |
3a5c3e22 PA |
1862 | |
1863 | loc = allocate_bp_location (&b->base); | |
1864 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1865 | ; |
1866 | *tmp = loc; | |
a6d9a66e | 1867 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1868 | |
1869 | loc->pspace = frame_pspace; | |
a5606eee | 1870 | loc->address = addr; |
744a8059 | 1871 | loc->length = TYPE_LENGTH (value_type (v)); |
a5606eee VP |
1872 | loc->watchpoint_type = type; |
1873 | } | |
1874 | } | |
9fa40276 TJB |
1875 | } |
1876 | ||
1877 | /* Change the type of breakpoint between hardware assisted or | |
1878 | an ordinary watchpoint depending on the hardware support | |
1879 | and free hardware slots. REPARSE is set when the inferior | |
1880 | is started. */ | |
a9634178 | 1881 | if (reparse) |
9fa40276 | 1882 | { |
e09342b5 | 1883 | int reg_cnt; |
9fa40276 TJB |
1884 | enum bp_loc_type loc_type; |
1885 | struct bp_location *bl; | |
a5606eee | 1886 | |
a9634178 | 1887 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1888 | |
1889 | if (reg_cnt) | |
9fa40276 TJB |
1890 | { |
1891 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1892 | enum bptype type; |
9fa40276 | 1893 | |
a9634178 TJB |
1894 | /* Use an exact watchpoint when there's only one memory region to be |
1895 | watched, and only one debug register is needed to watch it. */ | |
1896 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1897 | ||
9fa40276 | 1898 | /* We need to determine how many resources are already |
e09342b5 TJB |
1899 | used for all other hardware watchpoints plus this one |
1900 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1901 | this watchpoint in as well. */ |
1902 | ||
1903 | /* If this is a software watchpoint, we try to turn it | |
1904 | to a hardware one -- count resources as if B was of | |
1905 | hardware watchpoint type. */ | |
1906 | type = b->base.type; | |
1907 | if (type == bp_watchpoint) | |
1908 | type = bp_hardware_watchpoint; | |
1909 | ||
1910 | /* This watchpoint may or may not have been placed on | |
1911 | the list yet at this point (it won't be in the list | |
1912 | if we're trying to create it for the first time, | |
1913 | through watch_command), so always account for it | |
1914 | manually. */ | |
1915 | ||
1916 | /* Count resources used by all watchpoints except B. */ | |
1917 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1918 | ||
1919 | /* Add in the resources needed for B. */ | |
1920 | i += hw_watchpoint_use_count (&b->base); | |
1921 | ||
1922 | target_resources_ok | |
1923 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1924 | if (target_resources_ok <= 0) |
a9634178 | 1925 | { |
3a5c3e22 | 1926 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1927 | |
1928 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1929 | error (_("Target does not support this type of " |
1930 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1931 | else if (target_resources_ok < 0 && !sw_mode) |
1932 | error (_("There are not enough available hardware " | |
1933 | "resources for this watchpoint.")); | |
a1398e0c PA |
1934 | |
1935 | /* Downgrade to software watchpoint. */ | |
1936 | b->base.type = bp_watchpoint; | |
1937 | } | |
1938 | else | |
1939 | { | |
1940 | /* If this was a software watchpoint, we've just | |
1941 | found we have enough resources to turn it to a | |
1942 | hardware watchpoint. Otherwise, this is a | |
1943 | nop. */ | |
1944 | b->base.type = type; | |
a9634178 | 1945 | } |
9fa40276 | 1946 | } |
3a5c3e22 | 1947 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
1948 | { |
1949 | if (!can_use_hw_watchpoints) | |
1950 | error (_("Can't set read/access watchpoint when " | |
1951 | "hardware watchpoints are disabled.")); | |
1952 | else | |
1953 | error (_("Expression cannot be implemented with " | |
1954 | "read/access watchpoint.")); | |
1955 | } | |
9fa40276 | 1956 | else |
3a5c3e22 | 1957 | b->base.type = bp_watchpoint; |
9fa40276 | 1958 | |
3a5c3e22 | 1959 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1960 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1961 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1962 | bl->loc_type = loc_type; |
1963 | } | |
1964 | ||
1965 | for (v = val_chain; v; v = next) | |
1966 | { | |
a5606eee VP |
1967 | next = value_next (v); |
1968 | if (v != b->val) | |
1969 | value_free (v); | |
1970 | } | |
1971 | ||
c7437ca6 PA |
1972 | /* If a software watchpoint is not watching any memory, then the |
1973 | above left it without any location set up. But, | |
1974 | bpstat_stop_status requires a location to be able to report | |
1975 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1976 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1977 | { |
3a5c3e22 PA |
1978 | struct breakpoint *base = &b->base; |
1979 | base->loc = allocate_bp_location (base); | |
1980 | base->loc->pspace = frame_pspace; | |
1981 | base->loc->address = -1; | |
1982 | base->loc->length = -1; | |
1983 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1984 | } |
a5606eee VP |
1985 | } |
1986 | else if (!within_current_scope) | |
7270d8f2 | 1987 | { |
ac74f770 MS |
1988 | printf_filtered (_("\ |
1989 | Watchpoint %d deleted because the program has left the block\n\ | |
1990 | in which its expression is valid.\n"), | |
3a5c3e22 | 1991 | b->base.number); |
d0fb5eae | 1992 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1993 | } |
a5606eee VP |
1994 | |
1995 | /* Restore the selected frame. */ | |
66076460 DJ |
1996 | if (frame_saved) |
1997 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1998 | } |
1999 | ||
a5606eee | 2000 | |
74960c60 | 2001 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2002 | inserted in the inferior. We don't differentiate the type of BL's owner |
2003 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2004 | breakpoint_ops is not defined, because in insert_bp_location, | |
2005 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2006 | static int |
35df4500 | 2007 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2008 | { |
35df4500 | 2009 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2010 | return 0; |
2011 | ||
35df4500 | 2012 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2013 | return 0; |
2014 | ||
35df4500 | 2015 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2016 | return 0; |
2017 | ||
f8eba3c6 TT |
2018 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2019 | return 0; | |
2020 | ||
56710373 PA |
2021 | /* This is set for example, when we're attached to the parent of a |
2022 | vfork, and have detached from the child. The child is running | |
2023 | free, and we expect it to do an exec or exit, at which point the | |
2024 | OS makes the parent schedulable again (and the target reports | |
2025 | that the vfork is done). Until the child is done with the shared | |
2026 | memory region, do not insert breakpoints in the parent, otherwise | |
2027 | the child could still trip on the parent's breakpoints. Since | |
2028 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2029 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2030 | return 0; |
2031 | ||
31e77af2 PA |
2032 | /* Don't insert a breakpoint if we're trying to step past its |
2033 | location. */ | |
2034 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2035 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2036 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2037 | bl->address)) | |
2038 | return 0; | |
2039 | ||
74960c60 VP |
2040 | return 1; |
2041 | } | |
2042 | ||
934709f0 PW |
2043 | /* Same as should_be_inserted but does the check assuming |
2044 | that the location is not duplicated. */ | |
2045 | ||
2046 | static int | |
2047 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2048 | { | |
2049 | int result; | |
2050 | const int save_duplicate = bl->duplicate; | |
2051 | ||
2052 | bl->duplicate = 0; | |
2053 | result = should_be_inserted (bl); | |
2054 | bl->duplicate = save_duplicate; | |
2055 | return result; | |
2056 | } | |
2057 | ||
b775012e LM |
2058 | /* Parses a conditional described by an expression COND into an |
2059 | agent expression bytecode suitable for evaluation | |
2060 | by the bytecode interpreter. Return NULL if there was | |
2061 | any error during parsing. */ | |
2062 | ||
2063 | static struct agent_expr * | |
2064 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2065 | { | |
2066 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2067 | volatile struct gdb_exception ex; |
2068 | ||
2069 | if (!cond) | |
2070 | return NULL; | |
2071 | ||
2072 | /* We don't want to stop processing, so catch any errors | |
2073 | that may show up. */ | |
2074 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2075 | { | |
2076 | aexpr = gen_eval_for_expr (scope, cond); | |
2077 | } | |
2078 | ||
2079 | if (ex.reason < 0) | |
2080 | { | |
2081 | /* If we got here, it means the condition could not be parsed to a valid | |
2082 | bytecode expression and thus can't be evaluated on the target's side. | |
2083 | It's no use iterating through the conditions. */ | |
2084 | return NULL; | |
2085 | } | |
2086 | ||
2087 | /* We have a valid agent expression. */ | |
2088 | return aexpr; | |
2089 | } | |
2090 | ||
2091 | /* Based on location BL, create a list of breakpoint conditions to be | |
2092 | passed on to the target. If we have duplicated locations with different | |
2093 | conditions, we will add such conditions to the list. The idea is that the | |
2094 | target will evaluate the list of conditions and will only notify GDB when | |
2095 | one of them is true. */ | |
2096 | ||
2097 | static void | |
2098 | build_target_condition_list (struct bp_location *bl) | |
2099 | { | |
2100 | struct bp_location **locp = NULL, **loc2p; | |
2101 | int null_condition_or_parse_error = 0; | |
2102 | int modified = bl->needs_update; | |
2103 | struct bp_location *loc; | |
2104 | ||
8b4f3082 PA |
2105 | /* Release conditions left over from a previous insert. */ |
2106 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2107 | ||
b775012e LM |
2108 | /* This is only meaningful if the target is |
2109 | evaluating conditions and if the user has | |
2110 | opted for condition evaluation on the target's | |
2111 | side. */ | |
2112 | if (gdb_evaluates_breakpoint_condition_p () | |
2113 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2114 | return; | |
2115 | ||
2116 | /* Do a first pass to check for locations with no assigned | |
2117 | conditions or conditions that fail to parse to a valid agent expression | |
2118 | bytecode. If any of these happen, then it's no use to send conditions | |
2119 | to the target since this location will always trigger and generate a | |
2120 | response back to GDB. */ | |
2121 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2122 | { | |
2123 | loc = (*loc2p); | |
2124 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2125 | { | |
2126 | if (modified) | |
2127 | { | |
2128 | struct agent_expr *aexpr; | |
2129 | ||
2130 | /* Re-parse the conditions since something changed. In that | |
2131 | case we already freed the condition bytecodes (see | |
2132 | force_breakpoint_reinsertion). We just | |
2133 | need to parse the condition to bytecodes again. */ | |
2134 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2135 | loc->cond_bytecode = aexpr; | |
2136 | ||
2137 | /* Check if we managed to parse the conditional expression | |
2138 | correctly. If not, we will not send this condition | |
2139 | to the target. */ | |
2140 | if (aexpr) | |
2141 | continue; | |
2142 | } | |
2143 | ||
2144 | /* If we have a NULL bytecode expression, it means something | |
2145 | went wrong or we have a null condition expression. */ | |
2146 | if (!loc->cond_bytecode) | |
2147 | { | |
2148 | null_condition_or_parse_error = 1; | |
2149 | break; | |
2150 | } | |
2151 | } | |
2152 | } | |
2153 | ||
2154 | /* If any of these happened, it means we will have to evaluate the conditions | |
2155 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2156 | for all the other duplicate locations, thus we free all of them here. | |
2157 | ||
2158 | This is so we have a finer control over which locations' conditions are | |
2159 | being evaluated by GDB or the remote stub. */ | |
2160 | if (null_condition_or_parse_error) | |
2161 | { | |
2162 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2163 | { | |
2164 | loc = (*loc2p); | |
2165 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2166 | { | |
2167 | /* Only go as far as the first NULL bytecode is | |
2168 | located. */ | |
2169 | if (!loc->cond_bytecode) | |
2170 | return; | |
2171 | ||
2172 | free_agent_expr (loc->cond_bytecode); | |
2173 | loc->cond_bytecode = NULL; | |
2174 | } | |
2175 | } | |
2176 | } | |
2177 | ||
2178 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2179 | for this location's address. */ | |
2180 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2181 | { | |
2182 | loc = (*loc2p); | |
2183 | if (loc->cond | |
2184 | && is_breakpoint (loc->owner) | |
2185 | && loc->pspace->num == bl->pspace->num | |
2186 | && loc->owner->enable_state == bp_enabled | |
2187 | && loc->enabled) | |
2188 | /* Add the condition to the vector. This will be used later to send the | |
2189 | conditions to the target. */ | |
2190 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2191 | loc->cond_bytecode); | |
2192 | } | |
2193 | ||
2194 | return; | |
2195 | } | |
2196 | ||
d3ce09f5 SS |
2197 | /* Parses a command described by string CMD into an agent expression |
2198 | bytecode suitable for evaluation by the bytecode interpreter. | |
2199 | Return NULL if there was any error during parsing. */ | |
2200 | ||
2201 | static struct agent_expr * | |
2202 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2203 | { | |
2204 | struct cleanup *old_cleanups = 0; | |
2205 | struct expression *expr, **argvec; | |
2206 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2207 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2208 | const char *cmdrest; |
2209 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2210 | struct format_piece *fpieces; |
2211 | int nargs; | |
2212 | struct gdbarch *gdbarch = get_current_arch (); | |
2213 | ||
2214 | if (!cmd) | |
2215 | return NULL; | |
2216 | ||
2217 | cmdrest = cmd; | |
2218 | ||
2219 | if (*cmdrest == ',') | |
2220 | ++cmdrest; | |
bbc13ae3 | 2221 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2222 | |
2223 | if (*cmdrest++ != '"') | |
2224 | error (_("No format string following the location")); | |
2225 | ||
2226 | format_start = cmdrest; | |
2227 | ||
2228 | fpieces = parse_format_string (&cmdrest); | |
2229 | ||
2230 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2231 | ||
2232 | format_end = cmdrest; | |
2233 | ||
2234 | if (*cmdrest++ != '"') | |
2235 | error (_("Bad format string, non-terminated '\"'.")); | |
2236 | ||
bbc13ae3 | 2237 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2238 | |
2239 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2240 | error (_("Invalid argument syntax")); | |
2241 | ||
2242 | if (*cmdrest == ',') | |
2243 | cmdrest++; | |
bbc13ae3 | 2244 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2245 | |
2246 | /* For each argument, make an expression. */ | |
2247 | ||
2248 | argvec = (struct expression **) alloca (strlen (cmd) | |
2249 | * sizeof (struct expression *)); | |
2250 | ||
2251 | nargs = 0; | |
2252 | while (*cmdrest != '\0') | |
2253 | { | |
bbc13ae3 | 2254 | const char *cmd1; |
d3ce09f5 SS |
2255 | |
2256 | cmd1 = cmdrest; | |
2257 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2258 | argvec[nargs++] = expr; | |
2259 | cmdrest = cmd1; | |
2260 | if (*cmdrest == ',') | |
2261 | ++cmdrest; | |
2262 | } | |
2263 | ||
2264 | /* We don't want to stop processing, so catch any errors | |
2265 | that may show up. */ | |
2266 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2267 | { | |
2268 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2269 | format_start, format_end - format_start, | |
2270 | fpieces, nargs, argvec); | |
2271 | } | |
2272 | ||
752eb8b4 TT |
2273 | do_cleanups (old_cleanups); |
2274 | ||
d3ce09f5 SS |
2275 | if (ex.reason < 0) |
2276 | { | |
2277 | /* If we got here, it means the command could not be parsed to a valid | |
2278 | bytecode expression and thus can't be evaluated on the target's side. | |
2279 | It's no use iterating through the other commands. */ | |
2280 | return NULL; | |
2281 | } | |
2282 | ||
d3ce09f5 SS |
2283 | /* We have a valid agent expression, return it. */ |
2284 | return aexpr; | |
2285 | } | |
2286 | ||
2287 | /* Based on location BL, create a list of breakpoint commands to be | |
2288 | passed on to the target. If we have duplicated locations with | |
2289 | different commands, we will add any such to the list. */ | |
2290 | ||
2291 | static void | |
2292 | build_target_command_list (struct bp_location *bl) | |
2293 | { | |
2294 | struct bp_location **locp = NULL, **loc2p; | |
2295 | int null_command_or_parse_error = 0; | |
2296 | int modified = bl->needs_update; | |
2297 | struct bp_location *loc; | |
2298 | ||
8b4f3082 PA |
2299 | /* Release commands left over from a previous insert. */ |
2300 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2301 | ||
d3ce09f5 SS |
2302 | /* For now, limit to agent-style dprintf breakpoints. */ |
2303 | if (bl->owner->type != bp_dprintf | |
2304 | || strcmp (dprintf_style, dprintf_style_agent) != 0) | |
2305 | return; | |
2306 | ||
2307 | if (!target_can_run_breakpoint_commands ()) | |
2308 | return; | |
2309 | ||
2310 | /* Do a first pass to check for locations with no assigned | |
2311 | conditions or conditions that fail to parse to a valid agent expression | |
2312 | bytecode. If any of these happen, then it's no use to send conditions | |
2313 | to the target since this location will always trigger and generate a | |
2314 | response back to GDB. */ | |
2315 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2316 | { | |
2317 | loc = (*loc2p); | |
2318 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2319 | { | |
2320 | if (modified) | |
2321 | { | |
2322 | struct agent_expr *aexpr; | |
2323 | ||
2324 | /* Re-parse the commands since something changed. In that | |
2325 | case we already freed the command bytecodes (see | |
2326 | force_breakpoint_reinsertion). We just | |
2327 | need to parse the command to bytecodes again. */ | |
2328 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2329 | loc->owner->extra_string); | |
2330 | loc->cmd_bytecode = aexpr; | |
2331 | ||
2332 | if (!aexpr) | |
2333 | continue; | |
2334 | } | |
2335 | ||
2336 | /* If we have a NULL bytecode expression, it means something | |
2337 | went wrong or we have a null command expression. */ | |
2338 | if (!loc->cmd_bytecode) | |
2339 | { | |
2340 | null_command_or_parse_error = 1; | |
2341 | break; | |
2342 | } | |
2343 | } | |
2344 | } | |
2345 | ||
2346 | /* If anything failed, then we're not doing target-side commands, | |
2347 | and so clean up. */ | |
2348 | if (null_command_or_parse_error) | |
2349 | { | |
2350 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2351 | { | |
2352 | loc = (*loc2p); | |
2353 | if (is_breakpoint (loc->owner) | |
2354 | && loc->pspace->num == bl->pspace->num) | |
2355 | { | |
2356 | /* Only go as far as the first NULL bytecode is | |
2357 | located. */ | |
40fb6c5e | 2358 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2359 | return; |
2360 | ||
40fb6c5e HZ |
2361 | free_agent_expr (loc->cmd_bytecode); |
2362 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2363 | } |
2364 | } | |
2365 | } | |
2366 | ||
2367 | /* No NULL commands or failed bytecode generation. Build a command list | |
2368 | for this location's address. */ | |
2369 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2370 | { | |
2371 | loc = (*loc2p); | |
2372 | if (loc->owner->extra_string | |
2373 | && is_breakpoint (loc->owner) | |
2374 | && loc->pspace->num == bl->pspace->num | |
2375 | && loc->owner->enable_state == bp_enabled | |
2376 | && loc->enabled) | |
2377 | /* Add the command to the vector. This will be used later | |
2378 | to send the commands to the target. */ | |
2379 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2380 | loc->cmd_bytecode); | |
2381 | } | |
2382 | ||
2383 | bl->target_info.persist = 0; | |
2384 | /* Maybe flag this location as persistent. */ | |
2385 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2386 | bl->target_info.persist = 1; | |
2387 | } | |
2388 | ||
35df4500 TJB |
2389 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2390 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2391 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2392 | Returns 0 for success, 1 if the bp_location type is not supported or |
2393 | -1 for failure. | |
879bfdc2 | 2394 | |
4a64f543 MS |
2395 | NOTE drow/2003-09-09: This routine could be broken down to an |
2396 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2397 | static int |
35df4500 | 2398 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2399 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2400 | int *disabled_breaks, |
dd61ec5c MW |
2401 | int *hw_breakpoint_error, |
2402 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2403 | { |
0000e5cc PA |
2404 | enum errors bp_err = GDB_NO_ERROR; |
2405 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2406 | volatile struct gdb_exception e; |
879bfdc2 | 2407 | |
b775012e | 2408 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2409 | return 0; |
2410 | ||
35c63cd8 JB |
2411 | /* Note we don't initialize bl->target_info, as that wipes out |
2412 | the breakpoint location's shadow_contents if the breakpoint | |
2413 | is still inserted at that location. This in turn breaks | |
2414 | target_read_memory which depends on these buffers when | |
2415 | a memory read is requested at the breakpoint location: | |
2416 | Once the target_info has been wiped, we fail to see that | |
2417 | we have a breakpoint inserted at that address and thus | |
2418 | read the breakpoint instead of returning the data saved in | |
2419 | the breakpoint location's shadow contents. */ | |
35df4500 TJB |
2420 | bl->target_info.placed_address = bl->address; |
2421 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 2422 | bl->target_info.length = bl->length; |
8181d85f | 2423 | |
b775012e LM |
2424 | /* When working with target-side conditions, we must pass all the conditions |
2425 | for the same breakpoint address down to the target since GDB will not | |
2426 | insert those locations. With a list of breakpoint conditions, the target | |
2427 | can decide when to stop and notify GDB. */ | |
2428 | ||
2429 | if (is_breakpoint (bl->owner)) | |
2430 | { | |
2431 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2432 | build_target_command_list (bl); |
2433 | /* Reset the modification marker. */ | |
b775012e LM |
2434 | bl->needs_update = 0; |
2435 | } | |
2436 | ||
35df4500 TJB |
2437 | if (bl->loc_type == bp_loc_software_breakpoint |
2438 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2439 | { |
35df4500 | 2440 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2441 | { |
2442 | /* If the explicitly specified breakpoint type | |
2443 | is not hardware breakpoint, check the memory map to see | |
2444 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2445 | |
765dc015 VP |
2446 | Two important cases are: |
2447 | - location type is not hardware breakpoint, memory | |
2448 | is readonly. We change the type of the location to | |
2449 | hardware breakpoint. | |
4a64f543 MS |
2450 | - location type is hardware breakpoint, memory is |
2451 | read-write. This means we've previously made the | |
2452 | location hardware one, but then the memory map changed, | |
2453 | so we undo. | |
765dc015 | 2454 | |
4a64f543 MS |
2455 | When breakpoints are removed, remove_breakpoints will use |
2456 | location types we've just set here, the only possible | |
2457 | problem is that memory map has changed during running | |
2458 | program, but it's not going to work anyway with current | |
2459 | gdb. */ | |
765dc015 | 2460 | struct mem_region *mr |
35df4500 | 2461 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
2462 | |
2463 | if (mr) | |
2464 | { | |
2465 | if (automatic_hardware_breakpoints) | |
2466 | { | |
765dc015 VP |
2467 | enum bp_loc_type new_type; |
2468 | ||
2469 | if (mr->attrib.mode != MEM_RW) | |
2470 | new_type = bp_loc_hardware_breakpoint; | |
2471 | else | |
2472 | new_type = bp_loc_software_breakpoint; | |
2473 | ||
35df4500 | 2474 | if (new_type != bl->loc_type) |
765dc015 VP |
2475 | { |
2476 | static int said = 0; | |
cc59ec59 | 2477 | |
35df4500 | 2478 | bl->loc_type = new_type; |
765dc015 VP |
2479 | if (!said) |
2480 | { | |
3e43a32a MS |
2481 | fprintf_filtered (gdb_stdout, |
2482 | _("Note: automatically using " | |
2483 | "hardware breakpoints for " | |
2484 | "read-only addresses.\n")); | |
765dc015 VP |
2485 | said = 1; |
2486 | } | |
2487 | } | |
2488 | } | |
35df4500 | 2489 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 2490 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
2491 | warning (_("cannot set software breakpoint " |
2492 | "at readonly address %s"), | |
35df4500 | 2493 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
2494 | } |
2495 | } | |
2496 | ||
879bfdc2 DJ |
2497 | /* First check to see if we have to handle an overlay. */ |
2498 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2499 | || bl->section == NULL |
2500 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2501 | { |
2502 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2503 | TRY_CATCH (e, RETURN_MASK_ALL) |
2504 | { | |
0000e5cc PA |
2505 | int val; |
2506 | ||
dd61ec5c | 2507 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2508 | if (val) |
2509 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2510 | } |
2511 | if (e.reason < 0) | |
2512 | { | |
0000e5cc PA |
2513 | bp_err = e.error; |
2514 | bp_err_message = e.message; | |
dd61ec5c | 2515 | } |
879bfdc2 DJ |
2516 | } |
2517 | else | |
2518 | { | |
4a64f543 | 2519 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2520 | Shall we set a breakpoint at the LMA? */ |
2521 | if (!overlay_events_enabled) | |
2522 | { | |
2523 | /* Yes -- overlay event support is not active, | |
2524 | so we must try to set a breakpoint at the LMA. | |
2525 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2526 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2527 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2528 | bl->owner->number); |
879bfdc2 DJ |
2529 | else |
2530 | { | |
35df4500 TJB |
2531 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2532 | bl->section); | |
879bfdc2 | 2533 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
2534 | bl->overlay_target_info = bl->target_info; |
2535 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2536 | |
2537 | /* No overlay handling: just set the breakpoint. */ | |
2538 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2539 | { | |
2540 | int val; | |
2541 | ||
2542 | val = target_insert_breakpoint (bl->gdbarch, | |
2543 | &bl->overlay_target_info); | |
2544 | if (val) | |
2545 | bp_err = GENERIC_ERROR; | |
2546 | } | |
2547 | if (e.reason < 0) | |
2548 | { | |
2549 | bp_err = e.error; | |
2550 | bp_err_message = e.message; | |
2551 | } | |
2552 | ||
2553 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2554 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2555 | "Overlay breakpoint %d " |
2556 | "failed: in ROM?\n", | |
35df4500 | 2557 | bl->owner->number); |
879bfdc2 DJ |
2558 | } |
2559 | } | |
2560 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2561 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2562 | { |
2563 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2564 | TRY_CATCH (e, RETURN_MASK_ALL) |
2565 | { | |
0000e5cc PA |
2566 | int val; |
2567 | ||
dd61ec5c | 2568 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2569 | if (val) |
2570 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2571 | } |
2572 | if (e.reason < 0) | |
2573 | { | |
0000e5cc PA |
2574 | bp_err = e.error; |
2575 | bp_err_message = e.message; | |
dd61ec5c | 2576 | } |
879bfdc2 DJ |
2577 | } |
2578 | else | |
2579 | { | |
2580 | /* No. This breakpoint will not be inserted. | |
2581 | No error, but do not mark the bp as 'inserted'. */ | |
2582 | return 0; | |
2583 | } | |
2584 | } | |
2585 | ||
0000e5cc | 2586 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2587 | { |
2588 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2589 | |
2590 | /* In some cases, we might not be able to insert a | |
2591 | breakpoint in a shared library that has already been | |
2592 | removed, but we have not yet processed the shlib unload | |
2593 | event. Unfortunately, some targets that implement | |
2594 | breakpoint insertion themselves (necessary if this is a | |
2595 | HW breakpoint, but SW breakpoints likewise) can't tell | |
2596 | why the breakpoint insertion failed (e.g., the remote | |
2597 | target doesn't define error codes), so we must treat | |
2598 | generic errors as memory errors. */ | |
2599 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) | |
2600 | && solib_name_from_address (bl->pspace, bl->address)) | |
879bfdc2 | 2601 | { |
4a64f543 | 2602 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2603 | bl->shlib_disabled = 1; |
8d3788bd | 2604 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2605 | if (!*disabled_breaks) |
2606 | { | |
2607 | fprintf_unfiltered (tmp_error_stream, | |
2608 | "Cannot insert breakpoint %d.\n", | |
2609 | bl->owner->number); | |
2610 | fprintf_unfiltered (tmp_error_stream, | |
2611 | "Temporarily disabling shared " | |
2612 | "library breakpoints:\n"); | |
2613 | } | |
2614 | *disabled_breaks = 1; | |
879bfdc2 | 2615 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2616 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2617 | return 0; |
879bfdc2 DJ |
2618 | } |
2619 | else | |
879bfdc2 | 2620 | { |
35df4500 | 2621 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2622 | { |
0000e5cc PA |
2623 | *hw_breakpoint_error = 1; |
2624 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2625 | fprintf_unfiltered (tmp_error_stream, |
2626 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2627 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2628 | if (bp_err_message != NULL) | |
2629 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2630 | } |
2631 | else | |
2632 | { | |
0000e5cc PA |
2633 | if (bp_err_message == NULL) |
2634 | { | |
2635 | char *message | |
2636 | = memory_error_message (TARGET_XFER_E_IO, | |
2637 | bl->gdbarch, bl->address); | |
2638 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2639 | ||
2640 | fprintf_unfiltered (tmp_error_stream, | |
2641 | "Cannot insert breakpoint %d.\n" | |
2642 | "%s\n", | |
2643 | bl->owner->number, message); | |
2644 | do_cleanups (old_chain); | |
2645 | } | |
2646 | else | |
2647 | { | |
2648 | fprintf_unfiltered (tmp_error_stream, | |
2649 | "Cannot insert breakpoint %d: %s\n", | |
2650 | bl->owner->number, | |
2651 | bp_err_message); | |
2652 | } | |
879bfdc2 | 2653 | } |
0000e5cc | 2654 | return 1; |
879bfdc2 DJ |
2655 | |
2656 | } | |
2657 | } | |
2658 | else | |
35df4500 | 2659 | bl->inserted = 1; |
879bfdc2 | 2660 | |
0000e5cc | 2661 | return 0; |
879bfdc2 DJ |
2662 | } |
2663 | ||
35df4500 | 2664 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2665 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2666 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2667 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2668 | { |
0000e5cc PA |
2669 | int val; |
2670 | ||
77b06cd7 TJB |
2671 | gdb_assert (bl->owner->ops != NULL |
2672 | && bl->owner->ops->insert_location != NULL); | |
2673 | ||
2674 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2675 | |
2676 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2677 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2678 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2679 | { |
2680 | struct bp_location *loc, **loc_temp; | |
2681 | ||
2682 | /* But don't try to insert it, if there's already another | |
2683 | hw_access location that would be considered a duplicate | |
2684 | of this one. */ | |
2685 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2686 | if (loc != bl |
85d721b8 | 2687 | && loc->watchpoint_type == hw_access |
35df4500 | 2688 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2689 | { |
35df4500 TJB |
2690 | bl->duplicate = 1; |
2691 | bl->inserted = 1; | |
2692 | bl->target_info = loc->target_info; | |
2693 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2694 | val = 0; |
2695 | break; | |
2696 | } | |
2697 | ||
2698 | if (val == 1) | |
2699 | { | |
77b06cd7 TJB |
2700 | bl->watchpoint_type = hw_access; |
2701 | val = bl->owner->ops->insert_location (bl); | |
2702 | ||
2703 | if (val) | |
2704 | /* Back to the original value. */ | |
2705 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2706 | } |
2707 | } | |
2708 | ||
35df4500 | 2709 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2710 | } |
2711 | ||
35df4500 | 2712 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2713 | { |
0000e5cc PA |
2714 | int val; |
2715 | ||
77b06cd7 TJB |
2716 | gdb_assert (bl->owner->ops != NULL |
2717 | && bl->owner->ops->insert_location != NULL); | |
2718 | ||
2719 | val = bl->owner->ops->insert_location (bl); | |
2720 | if (val) | |
2721 | { | |
2722 | bl->owner->enable_state = bp_disabled; | |
2723 | ||
2724 | if (val == 1) | |
2725 | warning (_("\ | |
2726 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2727 | of catchpoint."), bl->owner->number); | |
2728 | else | |
2729 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2730 | } | |
2731 | ||
2732 | bl->inserted = (val == 0); | |
1640b821 DJ |
2733 | |
2734 | /* We've already printed an error message if there was a problem | |
2735 | inserting this catchpoint, and we've disabled the catchpoint, | |
2736 | so just return success. */ | |
2737 | return 0; | |
879bfdc2 DJ |
2738 | } |
2739 | ||
2740 | return 0; | |
2741 | } | |
2742 | ||
6c95b8df PA |
2743 | /* This function is called when program space PSPACE is about to be |
2744 | deleted. It takes care of updating breakpoints to not reference | |
2745 | PSPACE anymore. */ | |
2746 | ||
2747 | void | |
2748 | breakpoint_program_space_exit (struct program_space *pspace) | |
2749 | { | |
2750 | struct breakpoint *b, *b_temp; | |
876fa593 | 2751 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2752 | |
2753 | /* Remove any breakpoint that was set through this program space. */ | |
2754 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2755 | { | |
2756 | if (b->pspace == pspace) | |
2757 | delete_breakpoint (b); | |
2758 | } | |
2759 | ||
2760 | /* Breakpoints set through other program spaces could have locations | |
2761 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2762 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2763 | { |
2764 | struct bp_location *tmp; | |
2765 | ||
2766 | if (loc->pspace == pspace) | |
2767 | { | |
2bdf28a0 | 2768 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2769 | if (loc->owner->loc == loc) |
2770 | loc->owner->loc = loc->next; | |
2771 | else | |
2772 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2773 | if (tmp->next == loc) | |
2774 | { | |
2775 | tmp->next = loc->next; | |
2776 | break; | |
2777 | } | |
2778 | } | |
2779 | } | |
2780 | ||
2781 | /* Now update the global location list to permanently delete the | |
2782 | removed locations above. */ | |
2783 | update_global_location_list (0); | |
2784 | } | |
2785 | ||
74960c60 VP |
2786 | /* Make sure all breakpoints are inserted in inferior. |
2787 | Throws exception on any error. | |
2788 | A breakpoint that is already inserted won't be inserted | |
2789 | again, so calling this function twice is safe. */ | |
2790 | void | |
2791 | insert_breakpoints (void) | |
2792 | { | |
2793 | struct breakpoint *bpt; | |
2794 | ||
2795 | ALL_BREAKPOINTS (bpt) | |
2796 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2797 | { |
2798 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2799 | ||
2800 | update_watchpoint (w, 0 /* don't reparse. */); | |
2801 | } | |
74960c60 | 2802 | |
b60e7edf | 2803 | update_global_location_list (1); |
74960c60 | 2804 | |
c35b1492 PA |
2805 | /* update_global_location_list does not insert breakpoints when |
2806 | always_inserted_mode is not enabled. Explicitly insert them | |
2807 | now. */ | |
2808 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
2809 | insert_breakpoint_locations (); |
2810 | } | |
2811 | ||
20388dd6 YQ |
2812 | /* Invoke CALLBACK for each of bp_location. */ |
2813 | ||
2814 | void | |
2815 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2816 | { | |
2817 | struct bp_location *loc, **loc_tmp; | |
2818 | ||
2819 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2820 | { | |
2821 | callback (loc, NULL); | |
2822 | } | |
2823 | } | |
2824 | ||
b775012e LM |
2825 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2826 | target. It is the case with deleting and disabling of breakpoints when using | |
2827 | always-inserted mode. */ | |
2828 | ||
2829 | static void | |
2830 | update_inserted_breakpoint_locations (void) | |
2831 | { | |
2832 | struct bp_location *bl, **blp_tmp; | |
2833 | int error_flag = 0; | |
2834 | int val = 0; | |
2835 | int disabled_breaks = 0; | |
2836 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2837 | int hw_bp_details_reported = 0; |
b775012e LM |
2838 | |
2839 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
2840 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
2841 | ||
2842 | /* Explicitly mark the warning -- this will only be printed if | |
2843 | there was an error. */ | |
2844 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
2845 | ||
2846 | save_current_space_and_thread (); | |
2847 | ||
2848 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2849 | { | |
2850 | /* We only want to update software breakpoints and hardware | |
2851 | breakpoints. */ | |
2852 | if (!is_breakpoint (bl->owner)) | |
2853 | continue; | |
2854 | ||
2855 | /* We only want to update locations that are already inserted | |
2856 | and need updating. This is to avoid unwanted insertion during | |
2857 | deletion of breakpoints. */ | |
2858 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2859 | continue; | |
2860 | ||
2861 | switch_to_program_space_and_thread (bl->pspace); | |
2862 | ||
2863 | /* For targets that support global breakpoints, there's no need | |
2864 | to select an inferior to insert breakpoint to. In fact, even | |
2865 | if we aren't attached to any process yet, we should still | |
2866 | insert breakpoints. */ | |
f5656ead | 2867 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
2868 | && ptid_equal (inferior_ptid, null_ptid)) |
2869 | continue; | |
2870 | ||
2871 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 2872 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2873 | if (val) |
2874 | error_flag = val; | |
2875 | } | |
2876 | ||
2877 | if (error_flag) | |
2878 | { | |
2879 | target_terminal_ours_for_output (); | |
2880 | error_stream (tmp_error_stream); | |
2881 | } | |
2882 | ||
2883 | do_cleanups (cleanups); | |
2884 | } | |
2885 | ||
c30eee59 | 2886 | /* Used when starting or continuing the program. */ |
c906108c | 2887 | |
74960c60 VP |
2888 | static void |
2889 | insert_breakpoint_locations (void) | |
c906108c | 2890 | { |
a5606eee | 2891 | struct breakpoint *bpt; |
35df4500 | 2892 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2893 | int error_flag = 0; |
c906108c | 2894 | int val = 0; |
3fbb6ffa | 2895 | int disabled_breaks = 0; |
81d0cc19 | 2896 | int hw_breakpoint_error = 0; |
dd61ec5c | 2897 | int hw_bp_error_explained_already = 0; |
c906108c | 2898 | |
81d0cc19 | 2899 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 2900 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 2901 | |
81d0cc19 GS |
2902 | /* Explicitly mark the warning -- this will only be printed if |
2903 | there was an error. */ | |
2904 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2905 | |
2906 | save_current_space_and_thread (); | |
2907 | ||
35df4500 | 2908 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2909 | { |
b775012e | 2910 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2911 | continue; |
2912 | ||
4a64f543 MS |
2913 | /* There is no point inserting thread-specific breakpoints if |
2914 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2915 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2916 | if (bl->owner->thread != -1 |
2917 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2918 | continue; |
2919 | ||
35df4500 | 2920 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2921 | |
2922 | /* For targets that support global breakpoints, there's no need | |
2923 | to select an inferior to insert breakpoint to. In fact, even | |
2924 | if we aren't attached to any process yet, we should still | |
2925 | insert breakpoints. */ | |
f5656ead | 2926 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
2927 | && ptid_equal (inferior_ptid, null_ptid)) |
2928 | continue; | |
2929 | ||
3fbb6ffa | 2930 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2931 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2932 | if (val) |
eacd795a | 2933 | error_flag = val; |
879bfdc2 | 2934 | } |
c906108c | 2935 | |
4a64f543 MS |
2936 | /* If we failed to insert all locations of a watchpoint, remove |
2937 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2938 | ALL_BREAKPOINTS (bpt) |
2939 | { | |
2940 | int some_failed = 0; | |
2941 | struct bp_location *loc; | |
2942 | ||
2943 | if (!is_hardware_watchpoint (bpt)) | |
2944 | continue; | |
2945 | ||
d6b74ac4 | 2946 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2947 | continue; |
74960c60 VP |
2948 | |
2949 | if (bpt->disposition == disp_del_at_next_stop) | |
2950 | continue; | |
a5606eee VP |
2951 | |
2952 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2953 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2954 | { |
2955 | some_failed = 1; | |
2956 | break; | |
2957 | } | |
2958 | if (some_failed) | |
2959 | { | |
2960 | for (loc = bpt->loc; loc; loc = loc->next) | |
2961 | if (loc->inserted) | |
2962 | remove_breakpoint (loc, mark_uninserted); | |
2963 | ||
2964 | hw_breakpoint_error = 1; | |
2965 | fprintf_unfiltered (tmp_error_stream, | |
2966 | "Could not insert hardware watchpoint %d.\n", | |
2967 | bpt->number); | |
eacd795a | 2968 | error_flag = -1; |
a5606eee VP |
2969 | } |
2970 | } | |
2971 | ||
eacd795a | 2972 | if (error_flag) |
81d0cc19 GS |
2973 | { |
2974 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2975 | message about possibly exhausted resources. */ | |
dd61ec5c | 2976 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2977 | { |
c6510018 MS |
2978 | fprintf_unfiltered (tmp_error_stream, |
2979 | "Could not insert hardware breakpoints:\n\ | |
2980 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2981 | } |
81d0cc19 GS |
2982 | target_terminal_ours_for_output (); |
2983 | error_stream (tmp_error_stream); | |
2984 | } | |
f7545552 TT |
2985 | |
2986 | do_cleanups (cleanups); | |
c906108c SS |
2987 | } |
2988 | ||
c30eee59 TJB |
2989 | /* Used when the program stops. |
2990 | Returns zero if successful, or non-zero if there was a problem | |
2991 | removing a breakpoint location. */ | |
2992 | ||
c906108c | 2993 | int |
fba45db2 | 2994 | remove_breakpoints (void) |
c906108c | 2995 | { |
35df4500 | 2996 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2997 | int val = 0; |
c906108c | 2998 | |
35df4500 | 2999 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3000 | { |
1e4d1764 | 3001 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3002 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3003 | } |
3a1bae8e | 3004 | return val; |
c906108c SS |
3005 | } |
3006 | ||
49fa26b0 PA |
3007 | /* When a thread exits, remove breakpoints that are related to |
3008 | that thread. */ | |
3009 | ||
3010 | static void | |
3011 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3012 | { | |
3013 | struct breakpoint *b, *b_tmp; | |
3014 | ||
3015 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3016 | { | |
96181529 | 3017 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3018 | { |
3019 | b->disposition = disp_del_at_next_stop; | |
3020 | ||
3021 | printf_filtered (_("\ | |
46ecd527 | 3022 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3023 | b->number, tp->num); |
3024 | ||
3025 | /* Hide it from the user. */ | |
3026 | b->number = 0; | |
3027 | } | |
3028 | } | |
3029 | } | |
3030 | ||
6c95b8df PA |
3031 | /* Remove breakpoints of process PID. */ |
3032 | ||
3033 | int | |
3034 | remove_breakpoints_pid (int pid) | |
3035 | { | |
35df4500 | 3036 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3037 | int val; |
3038 | struct inferior *inf = find_inferior_pid (pid); | |
3039 | ||
35df4500 | 3040 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3041 | { |
35df4500 | 3042 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3043 | continue; |
3044 | ||
d3ce09f5 SS |
3045 | if (bl->owner->type == bp_dprintf) |
3046 | continue; | |
3047 | ||
35df4500 | 3048 | if (bl->inserted) |
6c95b8df | 3049 | { |
35df4500 | 3050 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3051 | if (val != 0) |
3052 | return val; | |
3053 | } | |
3054 | } | |
3055 | return 0; | |
3056 | } | |
3057 | ||
c906108c | 3058 | int |
fba45db2 | 3059 | reattach_breakpoints (int pid) |
c906108c | 3060 | { |
6c95b8df | 3061 | struct cleanup *old_chain; |
35df4500 | 3062 | struct bp_location *bl, **blp_tmp; |
c906108c | 3063 | int val; |
86b887df | 3064 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3065 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3066 | struct inferior *inf; |
3067 | struct thread_info *tp; | |
3068 | ||
3069 | tp = any_live_thread_of_process (pid); | |
3070 | if (tp == NULL) | |
3071 | return 1; | |
3072 | ||
3073 | inf = find_inferior_pid (pid); | |
3074 | old_chain = save_inferior_ptid (); | |
3075 | ||
3076 | inferior_ptid = tp->ptid; | |
a4954f26 | 3077 | |
86b887df | 3078 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3079 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3080 | |
35df4500 | 3081 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3082 | { |
35df4500 | 3083 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3084 | continue; |
3085 | ||
35df4500 | 3086 | if (bl->inserted) |
c5aa993b | 3087 | { |
35df4500 | 3088 | bl->inserted = 0; |
dd61ec5c | 3089 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3090 | if (val != 0) |
3091 | { | |
ce696e05 | 3092 | do_cleanups (old_chain); |
c5aa993b JM |
3093 | return val; |
3094 | } | |
3095 | } | |
3096 | } | |
ce696e05 | 3097 | do_cleanups (old_chain); |
c906108c SS |
3098 | return 0; |
3099 | } | |
3100 | ||
e58b0e63 PA |
3101 | static int internal_breakpoint_number = -1; |
3102 | ||
84f4c1fe PM |
3103 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3104 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3105 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3106 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3107 | breakpoint_count and that value incremented. Internal breakpoints |
3108 | do not set the internal var bpnum. */ | |
3109 | static void | |
3110 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3111 | { | |
3112 | if (internal) | |
3113 | b->number = internal_breakpoint_number--; | |
3114 | else | |
3115 | { | |
3116 | set_breakpoint_count (breakpoint_count + 1); | |
3117 | b->number = breakpoint_count; | |
3118 | } | |
3119 | } | |
3120 | ||
e62c965a | 3121 | static struct breakpoint * |
a6d9a66e | 3122 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3123 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3124 | const struct breakpoint_ops *ops) |
e62c965a | 3125 | { |
e62c965a PP |
3126 | struct symtab_and_line sal; |
3127 | struct breakpoint *b; | |
3128 | ||
4a64f543 | 3129 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3130 | |
3131 | sal.pc = address; | |
3132 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3133 | sal.pspace = current_program_space; |
e62c965a | 3134 | |
06edf0c0 | 3135 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3136 | b->number = internal_breakpoint_number--; |
3137 | b->disposition = disp_donttouch; | |
3138 | ||
3139 | return b; | |
3140 | } | |
3141 | ||
17450429 PP |
3142 | static const char *const longjmp_names[] = |
3143 | { | |
3144 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3145 | }; | |
3146 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3147 | ||
3148 | /* Per-objfile data private to breakpoint.c. */ | |
3149 | struct breakpoint_objfile_data | |
3150 | { | |
3151 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3152 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3153 | |
3154 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3155 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3156 | |
28106bc2 SDJ |
3157 | /* True if we have looked for longjmp probes. */ |
3158 | int longjmp_searched; | |
3159 | ||
3160 | /* SystemTap probe points for longjmp (if any). */ | |
3161 | VEC (probe_p) *longjmp_probes; | |
3162 | ||
17450429 | 3163 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3164 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3165 | |
3166 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3167 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3168 | |
3169 | /* True if we have looked for exception probes. */ | |
3170 | int exception_searched; | |
3171 | ||
3172 | /* SystemTap probe points for unwinding (if any). */ | |
3173 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3174 | }; |
3175 | ||
3176 | static const struct objfile_data *breakpoint_objfile_key; | |
3177 | ||
3178 | /* Minimal symbol not found sentinel. */ | |
3179 | static struct minimal_symbol msym_not_found; | |
3180 | ||
3181 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3182 | ||
3183 | static int | |
3184 | msym_not_found_p (const struct minimal_symbol *msym) | |
3185 | { | |
3186 | return msym == &msym_not_found; | |
3187 | } | |
3188 | ||
3189 | /* Return per-objfile data needed by breakpoint.c. | |
3190 | Allocate the data if necessary. */ | |
3191 | ||
3192 | static struct breakpoint_objfile_data * | |
3193 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3194 | { | |
3195 | struct breakpoint_objfile_data *bp_objfile_data; | |
3196 | ||
3197 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3198 | if (bp_objfile_data == NULL) | |
3199 | { | |
3200 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3201 | sizeof (*bp_objfile_data)); | |
3202 | ||
3203 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3204 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3205 | } | |
3206 | return bp_objfile_data; | |
3207 | } | |
3208 | ||
28106bc2 SDJ |
3209 | static void |
3210 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3211 | { | |
3212 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3213 | ||
3214 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3215 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3216 | } | |
3217 | ||
e62c965a | 3218 | static void |
af02033e | 3219 | create_overlay_event_breakpoint (void) |
e62c965a | 3220 | { |
69de3c6a | 3221 | struct objfile *objfile; |
af02033e | 3222 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3223 | |
69de3c6a PP |
3224 | ALL_OBJFILES (objfile) |
3225 | { | |
3226 | struct breakpoint *b; | |
17450429 PP |
3227 | struct breakpoint_objfile_data *bp_objfile_data; |
3228 | CORE_ADDR addr; | |
69de3c6a | 3229 | |
17450429 PP |
3230 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3231 | ||
3b7344d5 | 3232 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3233 | continue; |
3234 | ||
3b7344d5 | 3235 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3236 | { |
3b7344d5 | 3237 | struct bound_minimal_symbol m; |
17450429 PP |
3238 | |
3239 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3240 | if (m.minsym == NULL) |
17450429 PP |
3241 | { |
3242 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3243 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3244 | continue; |
3245 | } | |
3246 | bp_objfile_data->overlay_msym = m; | |
3247 | } | |
e62c965a | 3248 | |
77e371c0 | 3249 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3250 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3251 | bp_overlay_event, |
3252 | &internal_breakpoint_ops); | |
69de3c6a | 3253 | b->addr_string = xstrdup (func_name); |
e62c965a | 3254 | |
69de3c6a PP |
3255 | if (overlay_debugging == ovly_auto) |
3256 | { | |
3257 | b->enable_state = bp_enabled; | |
3258 | overlay_events_enabled = 1; | |
3259 | } | |
3260 | else | |
3261 | { | |
3262 | b->enable_state = bp_disabled; | |
3263 | overlay_events_enabled = 0; | |
3264 | } | |
e62c965a PP |
3265 | } |
3266 | update_global_location_list (1); | |
3267 | } | |
3268 | ||
0fd8e87f | 3269 | static void |
af02033e | 3270 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3271 | { |
6c95b8df | 3272 | struct program_space *pspace; |
6c95b8df PA |
3273 | struct cleanup *old_chain; |
3274 | ||
3275 | old_chain = save_current_program_space (); | |
0fd8e87f | 3276 | |
6c95b8df | 3277 | ALL_PSPACES (pspace) |
af02033e PP |
3278 | { |
3279 | struct objfile *objfile; | |
3280 | ||
3281 | set_current_program_space (pspace); | |
3282 | ||
3283 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3284 | { |
af02033e PP |
3285 | int i; |
3286 | struct gdbarch *gdbarch; | |
17450429 | 3287 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3288 | |
af02033e | 3289 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3290 | |
17450429 PP |
3291 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3292 | ||
28106bc2 SDJ |
3293 | if (!bp_objfile_data->longjmp_searched) |
3294 | { | |
25f9533e SDJ |
3295 | VEC (probe_p) *ret; |
3296 | ||
3297 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3298 | if (ret != NULL) | |
3299 | { | |
3300 | /* We are only interested in checking one element. */ | |
3301 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3302 | ||
3303 | if (!can_evaluate_probe_arguments (p)) | |
3304 | { | |
3305 | /* We cannot use the probe interface here, because it does | |
3306 | not know how to evaluate arguments. */ | |
3307 | VEC_free (probe_p, ret); | |
3308 | ret = NULL; | |
3309 | } | |
3310 | } | |
3311 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3312 | bp_objfile_data->longjmp_searched = 1; |
3313 | } | |
3314 | ||
3315 | if (bp_objfile_data->longjmp_probes != NULL) | |
3316 | { | |
3317 | int i; | |
3318 | struct probe *probe; | |
3319 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3320 | ||
3321 | for (i = 0; | |
3322 | VEC_iterate (probe_p, | |
3323 | bp_objfile_data->longjmp_probes, | |
3324 | i, probe); | |
3325 | ++i) | |
3326 | { | |
3327 | struct breakpoint *b; | |
3328 | ||
729662a5 TT |
3329 | b = create_internal_breakpoint (gdbarch, |
3330 | get_probe_address (probe, | |
3331 | objfile), | |
28106bc2 SDJ |
3332 | bp_longjmp_master, |
3333 | &internal_breakpoint_ops); | |
3334 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3335 | b->enable_state = bp_disabled; | |
3336 | } | |
3337 | ||
3338 | continue; | |
3339 | } | |
3340 | ||
0569175e TSD |
3341 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3342 | continue; | |
3343 | ||
17450429 | 3344 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3345 | { |
3346 | struct breakpoint *b; | |
af02033e | 3347 | const char *func_name; |
17450429 | 3348 | CORE_ADDR addr; |
6c95b8df | 3349 | |
3b7344d5 | 3350 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3351 | continue; |
0fd8e87f | 3352 | |
17450429 | 3353 | func_name = longjmp_names[i]; |
3b7344d5 | 3354 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3355 | { |
3b7344d5 | 3356 | struct bound_minimal_symbol m; |
17450429 PP |
3357 | |
3358 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3359 | if (m.minsym == NULL) |
17450429 PP |
3360 | { |
3361 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3362 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3363 | continue; |
3364 | } | |
3365 | bp_objfile_data->longjmp_msym[i] = m; | |
3366 | } | |
3367 | ||
77e371c0 | 3368 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3369 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3370 | &internal_breakpoint_ops); | |
af02033e PP |
3371 | b->addr_string = xstrdup (func_name); |
3372 | b->enable_state = bp_disabled; | |
3373 | } | |
0fd8e87f | 3374 | } |
af02033e | 3375 | } |
0fd8e87f | 3376 | update_global_location_list (1); |
6c95b8df PA |
3377 | |
3378 | do_cleanups (old_chain); | |
0fd8e87f UW |
3379 | } |
3380 | ||
af02033e | 3381 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3382 | static void |
af02033e | 3383 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3384 | { |
3385 | struct program_space *pspace; | |
aa7d318d | 3386 | struct cleanup *old_chain; |
af02033e | 3387 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3388 | |
3389 | old_chain = save_current_program_space (); | |
3390 | ||
3391 | ALL_PSPACES (pspace) | |
17450429 PP |
3392 | { |
3393 | struct objfile *objfile; | |
3394 | CORE_ADDR addr; | |
3395 | ||
3396 | set_current_program_space (pspace); | |
3397 | ||
aa7d318d TT |
3398 | ALL_OBJFILES (objfile) |
3399 | { | |
3400 | struct breakpoint *b; | |
17450429 | 3401 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3402 | |
17450429 | 3403 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3404 | |
3b7344d5 | 3405 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3406 | continue; |
3407 | ||
3b7344d5 | 3408 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3409 | { |
3b7344d5 | 3410 | struct bound_minimal_symbol m; |
17450429 PP |
3411 | |
3412 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3413 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3414 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3415 | { |
3416 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3417 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3418 | continue; |
3419 | } | |
3420 | bp_objfile_data->terminate_msym = m; | |
3421 | } | |
aa7d318d | 3422 | |
77e371c0 | 3423 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3424 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3425 | bp_std_terminate_master, |
3426 | &internal_breakpoint_ops); | |
aa7d318d TT |
3427 | b->addr_string = xstrdup (func_name); |
3428 | b->enable_state = bp_disabled; | |
3429 | } | |
17450429 PP |
3430 | } |
3431 | ||
aa7d318d TT |
3432 | update_global_location_list (1); |
3433 | ||
3434 | do_cleanups (old_chain); | |
3435 | } | |
3436 | ||
186c406b TT |
3437 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3438 | ||
70221824 | 3439 | static void |
186c406b TT |
3440 | create_exception_master_breakpoint (void) |
3441 | { | |
3442 | struct objfile *objfile; | |
17450429 | 3443 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3444 | |
3445 | ALL_OBJFILES (objfile) | |
3446 | { | |
17450429 PP |
3447 | struct breakpoint *b; |
3448 | struct gdbarch *gdbarch; | |
3449 | struct breakpoint_objfile_data *bp_objfile_data; | |
3450 | CORE_ADDR addr; | |
3451 | ||
3452 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3453 | ||
28106bc2 SDJ |
3454 | /* We prefer the SystemTap probe point if it exists. */ |
3455 | if (!bp_objfile_data->exception_searched) | |
3456 | { | |
25f9533e SDJ |
3457 | VEC (probe_p) *ret; |
3458 | ||
3459 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3460 | ||
3461 | if (ret != NULL) | |
3462 | { | |
3463 | /* We are only interested in checking one element. */ | |
3464 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3465 | ||
3466 | if (!can_evaluate_probe_arguments (p)) | |
3467 | { | |
3468 | /* We cannot use the probe interface here, because it does | |
3469 | not know how to evaluate arguments. */ | |
3470 | VEC_free (probe_p, ret); | |
3471 | ret = NULL; | |
3472 | } | |
3473 | } | |
3474 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3475 | bp_objfile_data->exception_searched = 1; |
3476 | } | |
3477 | ||
3478 | if (bp_objfile_data->exception_probes != NULL) | |
3479 | { | |
3480 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3481 | int i; | |
3482 | struct probe *probe; | |
3483 | ||
3484 | for (i = 0; | |
3485 | VEC_iterate (probe_p, | |
3486 | bp_objfile_data->exception_probes, | |
3487 | i, probe); | |
3488 | ++i) | |
3489 | { | |
3490 | struct breakpoint *b; | |
3491 | ||
729662a5 TT |
3492 | b = create_internal_breakpoint (gdbarch, |
3493 | get_probe_address (probe, | |
3494 | objfile), | |
28106bc2 SDJ |
3495 | bp_exception_master, |
3496 | &internal_breakpoint_ops); | |
3497 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3498 | b->enable_state = bp_disabled; | |
3499 | } | |
3500 | ||
3501 | continue; | |
3502 | } | |
3503 | ||
3504 | /* Otherwise, try the hook function. */ | |
3505 | ||
3b7344d5 | 3506 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3507 | continue; |
3508 | ||
3509 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3510 | |
3b7344d5 | 3511 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3512 | { |
3b7344d5 | 3513 | struct bound_minimal_symbol debug_hook; |
186c406b | 3514 | |
17450429 | 3515 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3516 | if (debug_hook.minsym == NULL) |
17450429 | 3517 | { |
3b7344d5 | 3518 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3519 | continue; |
3520 | } | |
3521 | ||
3522 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3523 | } |
17450429 | 3524 | |
77e371c0 | 3525 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3526 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3527 | ¤t_target); | |
06edf0c0 PA |
3528 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3529 | &internal_breakpoint_ops); | |
17450429 PP |
3530 | b->addr_string = xstrdup (func_name); |
3531 | b->enable_state = bp_disabled; | |
186c406b TT |
3532 | } |
3533 | ||
3534 | update_global_location_list (1); | |
3535 | } | |
3536 | ||
c906108c | 3537 | void |
fba45db2 | 3538 | update_breakpoints_after_exec (void) |
c906108c | 3539 | { |
35df4500 | 3540 | struct breakpoint *b, *b_tmp; |
876fa593 | 3541 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3542 | |
25b22b0a PA |
3543 | /* We're about to delete breakpoints from GDB's lists. If the |
3544 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3545 | writing the breakpoints' "shadow contents" back into memory. The | |
3546 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3547 | do that. Instead, the target is responsible from marking | |
3548 | breakpoints out as soon as it detects an exec. We don't do that | |
3549 | here instead, because there may be other attempts to delete | |
3550 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3551 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3552 | if (bploc->pspace == current_program_space) |
3553 | gdb_assert (!bploc->inserted); | |
c906108c | 3554 | |
35df4500 | 3555 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3556 | { |
6c95b8df PA |
3557 | if (b->pspace != current_program_space) |
3558 | continue; | |
3559 | ||
4a64f543 | 3560 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3561 | if (b->type == bp_shlib_event) |
3562 | { | |
3563 | delete_breakpoint (b); | |
3564 | continue; | |
3565 | } | |
c906108c | 3566 | |
4a64f543 | 3567 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3568 | if (b->type == bp_jit_event) |
3569 | { | |
3570 | delete_breakpoint (b); | |
3571 | continue; | |
3572 | } | |
3573 | ||
1900040c | 3574 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3575 | as must overlay event and longjmp master breakpoints. */ |
3576 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3577 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3578 | || b->type == bp_exception_master) | |
c4093a6a JM |
3579 | { |
3580 | delete_breakpoint (b); | |
3581 | continue; | |
3582 | } | |
3583 | ||
4a64f543 | 3584 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3585 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3586 | { |
3587 | delete_breakpoint (b); | |
3588 | continue; | |
3589 | } | |
3590 | ||
611c83ae PA |
3591 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3592 | after an exec. */ | |
186c406b | 3593 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3594 | || b->type == bp_longjmp_call_dummy |
186c406b | 3595 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3596 | { |
3597 | delete_breakpoint (b); | |
3598 | continue; | |
3599 | } | |
3600 | ||
ce78b96d JB |
3601 | if (b->type == bp_catchpoint) |
3602 | { | |
3603 | /* For now, none of the bp_catchpoint breakpoints need to | |
3604 | do anything at this point. In the future, if some of | |
3605 | the catchpoints need to something, we will need to add | |
3606 | a new method, and call this method from here. */ | |
3607 | continue; | |
3608 | } | |
3609 | ||
c5aa993b JM |
3610 | /* bp_finish is a special case. The only way we ought to be able |
3611 | to see one of these when an exec() has happened, is if the user | |
3612 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3613 | carries them to the call-site of the current callee, by setting | |
3614 | a temporary bp there and resuming. But in this case, the finish | |
3615 | will carry them entirely through the vfork & exec. | |
3616 | ||
3617 | We don't want to allow a bp_finish to remain inserted now. But | |
3618 | we can't safely delete it, 'cause finish_command has a handle to | |
3619 | the bp on a bpstat, and will later want to delete it. There's a | |
3620 | chance (and I've seen it happen) that if we delete the bp_finish | |
3621 | here, that its storage will get reused by the time finish_command | |
3622 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3623 | We really must allow finish_command to delete a bp_finish. | |
3624 | ||
e5dd4106 | 3625 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3626 | it's safe to delete something others may have handles to?" |
3627 | problem, what we'll do here is just uninsert the bp_finish, and | |
3628 | let finish_command delete it. | |
3629 | ||
3630 | (We know the bp_finish is "doomed" in the sense that it's | |
3631 | momentary, and will be deleted as soon as finish_command sees | |
3632 | the inferior stopped. So it doesn't matter that the bp's | |
3633 | address is probably bogus in the new a.out, unlike e.g., the | |
3634 | solib breakpoints.) */ | |
c5aa993b | 3635 | |
c5aa993b JM |
3636 | if (b->type == bp_finish) |
3637 | { | |
3638 | continue; | |
3639 | } | |
3640 | ||
3641 | /* Without a symbolic address, we have little hope of the | |
3642 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3643 | a.out. */ |
c5aa993b JM |
3644 | if (b->addr_string == NULL) |
3645 | { | |
3646 | delete_breakpoint (b); | |
3647 | continue; | |
3648 | } | |
c5aa993b | 3649 | } |
1900040c | 3650 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
3651 | create_overlay_event_breakpoint (); |
3652 | create_longjmp_master_breakpoint (); | |
3653 | create_std_terminate_master_breakpoint (); | |
186c406b | 3654 | create_exception_master_breakpoint (); |
c906108c SS |
3655 | } |
3656 | ||
3657 | int | |
d80ee84f | 3658 | detach_breakpoints (ptid_t ptid) |
c906108c | 3659 | { |
35df4500 | 3660 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3661 | int val = 0; |
ce696e05 | 3662 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3663 | struct inferior *inf = current_inferior (); |
c5aa993b | 3664 | |
dfd4cc63 | 3665 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3666 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3667 | |
6c95b8df | 3668 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3669 | inferior_ptid = ptid; |
35df4500 | 3670 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3671 | { |
35df4500 | 3672 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3673 | continue; |
3674 | ||
bd9673a4 PW |
3675 | /* This function must physically remove breakpoints locations |
3676 | from the specified ptid, without modifying the breakpoint | |
3677 | package's state. Locations of type bp_loc_other are only | |
3678 | maintained at GDB side. So, there is no need to remove | |
3679 | these bp_loc_other locations. Moreover, removing these | |
3680 | would modify the breakpoint package's state. */ | |
3681 | if (bl->loc_type == bp_loc_other) | |
3682 | continue; | |
3683 | ||
35df4500 TJB |
3684 | if (bl->inserted) |
3685 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3686 | } |
d03285ec UW |
3687 | |
3688 | /* Detach single-step breakpoints as well. */ | |
3689 | detach_single_step_breakpoints (); | |
3690 | ||
ce696e05 | 3691 | do_cleanups (old_chain); |
3a1bae8e | 3692 | return val; |
c906108c SS |
3693 | } |
3694 | ||
35df4500 | 3695 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3696 | Note that this is used to detach breakpoints from a child fork. |
3697 | When we get here, the child isn't in the inferior list, and neither | |
3698 | do we have objects to represent its address space --- we should | |
35df4500 | 3699 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3700 | |
c906108c | 3701 | static int |
35df4500 | 3702 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3703 | { |
3704 | int val; | |
c5aa993b | 3705 | |
35df4500 TJB |
3706 | /* BL is never in moribund_locations by our callers. */ |
3707 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3708 | |
35df4500 | 3709 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3710 | /* Permanent breakpoints cannot be inserted or removed. */ |
3711 | return 0; | |
3712 | ||
74960c60 VP |
3713 | /* The type of none suggests that owner is actually deleted. |
3714 | This should not ever happen. */ | |
35df4500 | 3715 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3716 | |
35df4500 TJB |
3717 | if (bl->loc_type == bp_loc_software_breakpoint |
3718 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3719 | { |
c02f5703 MS |
3720 | /* "Normal" instruction breakpoint: either the standard |
3721 | trap-instruction bp (bp_breakpoint), or a | |
3722 | bp_hardware_breakpoint. */ | |
3723 | ||
3724 | /* First check to see if we have to handle an overlay. */ | |
3725 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3726 | || bl->section == NULL |
3727 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3728 | { |
3729 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 3730 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 3731 | } |
c906108c SS |
3732 | else |
3733 | { | |
4a64f543 | 3734 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3735 | Did we set a breakpoint at the LMA? */ |
3736 | if (!overlay_events_enabled) | |
3737 | { | |
3738 | /* Yes -- overlay event support is not active, so we | |
3739 | should have set a breakpoint at the LMA. Remove it. | |
3740 | */ | |
c02f5703 MS |
3741 | /* Ignore any failures: if the LMA is in ROM, we will |
3742 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3743 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3744 | target_remove_hw_breakpoint (bl->gdbarch, | |
3745 | &bl->overlay_target_info); | |
c02f5703 | 3746 | else |
35df4500 TJB |
3747 | target_remove_breakpoint (bl->gdbarch, |
3748 | &bl->overlay_target_info); | |
c02f5703 MS |
3749 | } |
3750 | /* Did we set a breakpoint at the VMA? | |
3751 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3752 | if (bl->inserted) |
c906108c | 3753 | { |
c02f5703 MS |
3754 | /* Yes -- remove it. Previously we did not bother to |
3755 | remove the breakpoint if the section had been | |
3756 | unmapped, but let's not rely on that being safe. We | |
3757 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3758 | |
3759 | /* However, we should remove *software* breakpoints only | |
3760 | if the section is still mapped, or else we overwrite | |
3761 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3762 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3763 | || section_is_mapped (bl->section)) | |
3764 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3765 | else |
3766 | val = 0; | |
c906108c | 3767 | } |
c02f5703 MS |
3768 | else |
3769 | { | |
3770 | /* No -- not inserted, so no need to remove. No error. */ | |
3771 | val = 0; | |
3772 | } | |
c906108c | 3773 | } |
879d1e6b UW |
3774 | |
3775 | /* In some cases, we might not be able to remove a breakpoint | |
3776 | in a shared library that has already been removed, but we | |
3777 | have not yet processed the shlib unload event. */ | |
35df4500 | 3778 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
3779 | val = 0; |
3780 | ||
c906108c SS |
3781 | if (val) |
3782 | return val; | |
35df4500 | 3783 | bl->inserted = (is == mark_inserted); |
c906108c | 3784 | } |
35df4500 | 3785 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3786 | { |
77b06cd7 TJB |
3787 | gdb_assert (bl->owner->ops != NULL |
3788 | && bl->owner->ops->remove_location != NULL); | |
3789 | ||
35df4500 | 3790 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 3791 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 3792 | |
c906108c | 3793 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 3794 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 3795 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3796 | bl->owner->number); |
c906108c | 3797 | } |
35df4500 TJB |
3798 | else if (bl->owner->type == bp_catchpoint |
3799 | && breakpoint_enabled (bl->owner) | |
3800 | && !bl->duplicate) | |
ce78b96d | 3801 | { |
77b06cd7 TJB |
3802 | gdb_assert (bl->owner->ops != NULL |
3803 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3804 | |
77b06cd7 | 3805 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
3806 | if (val) |
3807 | return val; | |
77b06cd7 | 3808 | |
35df4500 | 3809 | bl->inserted = (is == mark_inserted); |
ce78b96d | 3810 | } |
c906108c SS |
3811 | |
3812 | return 0; | |
3813 | } | |
3814 | ||
6c95b8df | 3815 | static int |
35df4500 | 3816 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
3817 | { |
3818 | int ret; | |
3819 | struct cleanup *old_chain; | |
3820 | ||
35df4500 TJB |
3821 | /* BL is never in moribund_locations by our callers. */ |
3822 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3823 | |
35df4500 | 3824 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
3825 | /* Permanent breakpoints cannot be inserted or removed. */ |
3826 | return 0; | |
3827 | ||
3828 | /* The type of none suggests that owner is actually deleted. | |
3829 | This should not ever happen. */ | |
35df4500 | 3830 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
3831 | |
3832 | old_chain = save_current_space_and_thread (); | |
3833 | ||
35df4500 | 3834 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3835 | |
35df4500 | 3836 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
3837 | |
3838 | do_cleanups (old_chain); | |
3839 | return ret; | |
3840 | } | |
3841 | ||
c906108c SS |
3842 | /* Clear the "inserted" flag in all breakpoints. */ |
3843 | ||
25b22b0a | 3844 | void |
fba45db2 | 3845 | mark_breakpoints_out (void) |
c906108c | 3846 | { |
35df4500 | 3847 | struct bp_location *bl, **blp_tmp; |
c906108c | 3848 | |
35df4500 TJB |
3849 | ALL_BP_LOCATIONS (bl, blp_tmp) |
3850 | if (bl->pspace == current_program_space) | |
3851 | bl->inserted = 0; | |
c906108c SS |
3852 | } |
3853 | ||
53a5351d JM |
3854 | /* Clear the "inserted" flag in all breakpoints and delete any |
3855 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3856 | |
3857 | Plus other such housekeeping that has to be done for breakpoints | |
3858 | between runs. | |
3859 | ||
53a5351d JM |
3860 | Note: this function gets called at the end of a run (by |
3861 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3862 | init_wait_for_inferior). */ |
c906108c SS |
3863 | |
3864 | ||
3865 | ||
3866 | void | |
fba45db2 | 3867 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3868 | { |
35df4500 TJB |
3869 | struct breakpoint *b, *b_tmp; |
3870 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 3871 | int ix; |
6c95b8df | 3872 | struct program_space *pspace = current_program_space; |
c906108c | 3873 | |
50c71eaf PA |
3874 | /* If breakpoint locations are shared across processes, then there's |
3875 | nothing to do. */ | |
f5656ead | 3876 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3877 | return; |
3878 | ||
35df4500 | 3879 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3880 | { |
35df4500 TJB |
3881 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
3882 | if (bl->pspace == pspace | |
3883 | && bl->owner->enable_state != bp_permanent) | |
3884 | bl->inserted = 0; | |
6c95b8df | 3885 | } |
075f6582 | 3886 | |
35df4500 | 3887 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3888 | { |
6c95b8df PA |
3889 | if (b->loc && b->loc->pspace != pspace) |
3890 | continue; | |
3891 | ||
c5aa993b JM |
3892 | switch (b->type) |
3893 | { | |
3894 | case bp_call_dummy: | |
e2e4d78b | 3895 | case bp_longjmp_call_dummy: |
c906108c | 3896 | |
c5aa993b | 3897 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3898 | cause problems when the inferior is rerun, so we better get |
3899 | rid of it. */ | |
3900 | ||
3901 | case bp_watchpoint_scope: | |
3902 | ||
3903 | /* Also get rid of scope breakpoints. */ | |
3904 | ||
3905 | case bp_shlib_event: | |
3906 | ||
3907 | /* Also remove solib event breakpoints. Their addresses may | |
3908 | have changed since the last time we ran the program. | |
3909 | Actually we may now be debugging against different target; | |
3910 | and so the solib backend that installed this breakpoint may | |
3911 | not be used in by the target. E.g., | |
3912 | ||
3913 | (gdb) file prog-linux | |
3914 | (gdb) run # native linux target | |
3915 | ... | |
3916 | (gdb) kill | |
3917 | (gdb) file prog-win.exe | |
3918 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3919 | */ | |
c906108c | 3920 | |
f59f708a PA |
3921 | case bp_step_resume: |
3922 | ||
3923 | /* Also remove step-resume breakpoints. */ | |
3924 | ||
c5aa993b JM |
3925 | delete_breakpoint (b); |
3926 | break; | |
c906108c | 3927 | |
c5aa993b JM |
3928 | case bp_watchpoint: |
3929 | case bp_hardware_watchpoint: | |
3930 | case bp_read_watchpoint: | |
3931 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3932 | { |
3933 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3934 | |
3a5c3e22 PA |
3935 | /* Likewise for watchpoints on local expressions. */ |
3936 | if (w->exp_valid_block != NULL) | |
3937 | delete_breakpoint (b); | |
3938 | else if (context == inf_starting) | |
3939 | { | |
3940 | /* Reset val field to force reread of starting value in | |
3941 | insert_breakpoints. */ | |
3942 | if (w->val) | |
3943 | value_free (w->val); | |
3944 | w->val = NULL; | |
3945 | w->val_valid = 0; | |
c860120c | 3946 | } |
3a5c3e22 | 3947 | } |
c5aa993b JM |
3948 | break; |
3949 | default: | |
c5aa993b JM |
3950 | break; |
3951 | } | |
3952 | } | |
1c5cfe86 PA |
3953 | |
3954 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
3955 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
3956 | decref_bp_location (&bl); | |
1c5cfe86 | 3957 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
3958 | } |
3959 | ||
6c95b8df PA |
3960 | /* These functions concern about actual breakpoints inserted in the |
3961 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3962 | we need to hop over the bkpt --- so we check for address space | |
3963 | match, not program space. */ | |
3964 | ||
c2c6d25f JM |
3965 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3966 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3967 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3968 | permanent breakpoint. | |
3969 | - When continuing from a location with an ordinary breakpoint, we | |
3970 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3971 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3972 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3973 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3974 | |
c2c6d25f | 3975 | enum breakpoint_here |
6c95b8df | 3976 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 3977 | { |
35df4500 | 3978 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3979 | int any_breakpoint_here = 0; |
c906108c | 3980 | |
35df4500 | 3981 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3982 | { |
35df4500 TJB |
3983 | if (bl->loc_type != bp_loc_software_breakpoint |
3984 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3985 | continue; |
3986 | ||
f1310107 | 3987 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
3988 | if ((breakpoint_enabled (bl->owner) |
3989 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 3990 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3991 | { |
3992 | if (overlay_debugging | |
35df4500 TJB |
3993 | && section_is_overlay (bl->section) |
3994 | && !section_is_mapped (bl->section)) | |
075f6582 | 3995 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 3996 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
3997 | return permanent_breakpoint_here; |
3998 | else | |
3999 | any_breakpoint_here = 1; | |
4000 | } | |
4001 | } | |
c906108c | 4002 | |
c2c6d25f | 4003 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4004 | } |
4005 | ||
1c5cfe86 PA |
4006 | /* Return true if there's a moribund breakpoint at PC. */ |
4007 | ||
4008 | int | |
6c95b8df | 4009 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4010 | { |
4011 | struct bp_location *loc; | |
4012 | int ix; | |
4013 | ||
4014 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4015 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4016 | return 1; |
4017 | ||
4018 | return 0; | |
4019 | } | |
c2c6d25f | 4020 | |
c36b740a | 4021 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
4022 | inserted using regular breakpoint_chain / bp_location array |
4023 | mechanism. This does not check for single-step breakpoints, which | |
4024 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
4025 | |
4026 | int | |
4a64f543 MS |
4027 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
4028 | CORE_ADDR pc) | |
c906108c | 4029 | { |
35df4500 | 4030 | struct bp_location *bl, **blp_tmp; |
c906108c | 4031 | |
35df4500 | 4032 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4033 | { |
35df4500 TJB |
4034 | if (bl->loc_type != bp_loc_software_breakpoint |
4035 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4036 | continue; |
4037 | ||
35df4500 | 4038 | if (bl->inserted |
f1310107 | 4039 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4040 | { |
4041 | if (overlay_debugging | |
35df4500 TJB |
4042 | && section_is_overlay (bl->section) |
4043 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4044 | continue; /* unmapped overlay -- can't be a match */ |
4045 | else | |
4046 | return 1; | |
4047 | } | |
c5aa993b | 4048 | } |
c36b740a VP |
4049 | return 0; |
4050 | } | |
4051 | ||
4052 | /* Returns non-zero iff there's either regular breakpoint | |
4053 | or a single step breakpoint inserted at PC. */ | |
4054 | ||
4055 | int | |
6c95b8df | 4056 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 4057 | { |
6c95b8df | 4058 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4059 | return 1; |
c906108c | 4060 | |
6c95b8df | 4061 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4062 | return 1; |
4063 | ||
c906108c SS |
4064 | return 0; |
4065 | } | |
4066 | ||
4fa8626c DJ |
4067 | /* This function returns non-zero iff there is a software breakpoint |
4068 | inserted at PC. */ | |
4069 | ||
4070 | int | |
3e43a32a MS |
4071 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4072 | CORE_ADDR pc) | |
4fa8626c | 4073 | { |
35df4500 | 4074 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4075 | |
35df4500 | 4076 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4077 | { |
35df4500 | 4078 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4079 | continue; |
4080 | ||
35df4500 TJB |
4081 | if (bl->inserted |
4082 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4083 | aspace, pc)) |
4fa8626c DJ |
4084 | { |
4085 | if (overlay_debugging | |
35df4500 TJB |
4086 | && section_is_overlay (bl->section) |
4087 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4088 | continue; /* unmapped overlay -- can't be a match */ |
4089 | else | |
4090 | return 1; | |
4091 | } | |
4092 | } | |
4093 | ||
1aafd4da | 4094 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4095 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4096 | return 1; |
4097 | ||
4fa8626c DJ |
4098 | return 0; |
4099 | } | |
4100 | ||
9093389c PA |
4101 | int |
4102 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4103 | CORE_ADDR addr, ULONGEST len) | |
4104 | { | |
4105 | struct breakpoint *bpt; | |
4106 | ||
4107 | ALL_BREAKPOINTS (bpt) | |
4108 | { | |
4109 | struct bp_location *loc; | |
4110 | ||
4111 | if (bpt->type != bp_hardware_watchpoint | |
4112 | && bpt->type != bp_access_watchpoint) | |
4113 | continue; | |
4114 | ||
4115 | if (!breakpoint_enabled (bpt)) | |
4116 | continue; | |
4117 | ||
4118 | for (loc = bpt->loc; loc; loc = loc->next) | |
4119 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4120 | { | |
4121 | CORE_ADDR l, h; | |
4122 | ||
4123 | /* Check for intersection. */ | |
4124 | l = max (loc->address, addr); | |
4125 | h = min (loc->address + loc->length, addr + len); | |
4126 | if (l < h) | |
4127 | return 1; | |
4128 | } | |
4129 | } | |
4130 | return 0; | |
4131 | } | |
4132 | ||
075f6582 DJ |
4133 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4134 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4135 | |
4136 | int | |
6c95b8df PA |
4137 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4138 | ptid_t ptid) | |
c906108c | 4139 | { |
35df4500 | 4140 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4141 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4142 | int thread = -1; |
4a306c9a | 4143 | int task = 0; |
a6f1cd96 | 4144 | |
35df4500 | 4145 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4146 | { |
35df4500 TJB |
4147 | if (bl->loc_type != bp_loc_software_breakpoint |
4148 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4149 | continue; |
4150 | ||
35df4500 TJB |
4151 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4152 | if (!breakpoint_enabled (bl->owner) | |
4153 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4154 | continue; |
4155 | ||
f1310107 | 4156 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4157 | continue; |
4158 | ||
35df4500 | 4159 | if (bl->owner->thread != -1) |
075f6582 | 4160 | { |
a6f1cd96 JB |
4161 | /* This is a thread-specific breakpoint. Check that ptid |
4162 | matches that thread. If thread hasn't been computed yet, | |
4163 | it is now time to do so. */ | |
4164 | if (thread == -1) | |
4165 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4166 | if (bl->owner->thread != thread) |
a6f1cd96 | 4167 | continue; |
075f6582 | 4168 | } |
a6f1cd96 | 4169 | |
35df4500 | 4170 | if (bl->owner->task != 0) |
4a306c9a JB |
4171 | { |
4172 | /* This is a task-specific breakpoint. Check that ptid | |
4173 | matches that task. If task hasn't been computed yet, | |
4174 | it is now time to do so. */ | |
4175 | if (task == 0) | |
4176 | task = ada_get_task_number (ptid); | |
35df4500 | 4177 | if (bl->owner->task != task) |
4a306c9a JB |
4178 | continue; |
4179 | } | |
4180 | ||
a6f1cd96 | 4181 | if (overlay_debugging |
35df4500 TJB |
4182 | && section_is_overlay (bl->section) |
4183 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4184 | continue; /* unmapped overlay -- can't be a match */ |
4185 | ||
4186 | return 1; | |
c5aa993b | 4187 | } |
c906108c SS |
4188 | |
4189 | return 0; | |
4190 | } | |
c906108c | 4191 | \f |
c5aa993b | 4192 | |
c906108c SS |
4193 | /* bpstat stuff. External routines' interfaces are documented |
4194 | in breakpoint.h. */ | |
4195 | ||
4196 | int | |
c326b90e | 4197 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4198 | { |
533be4dd | 4199 | return (ep->type == bp_catchpoint); |
c906108c SS |
4200 | } |
4201 | ||
f431efe5 PA |
4202 | /* Frees any storage that is part of a bpstat. Does not walk the |
4203 | 'next' chain. */ | |
4204 | ||
4205 | static void | |
198757a8 VP |
4206 | bpstat_free (bpstat bs) |
4207 | { | |
4208 | if (bs->old_val != NULL) | |
4209 | value_free (bs->old_val); | |
9add0f1b | 4210 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4211 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4212 | xfree (bs); |
4213 | } | |
4214 | ||
c906108c SS |
4215 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4216 | Also free any storage that is part of a bpstat. */ | |
4217 | ||
4218 | void | |
fba45db2 | 4219 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4220 | { |
4221 | bpstat p; | |
4222 | bpstat q; | |
4223 | ||
4224 | if (bsp == 0) | |
4225 | return; | |
4226 | p = *bsp; | |
4227 | while (p != NULL) | |
4228 | { | |
4229 | q = p->next; | |
198757a8 | 4230 | bpstat_free (p); |
c906108c SS |
4231 | p = q; |
4232 | } | |
4233 | *bsp = NULL; | |
4234 | } | |
4235 | ||
4236 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4237 | is part of the bpstat is copied as well. */ | |
4238 | ||
4239 | bpstat | |
fba45db2 | 4240 | bpstat_copy (bpstat bs) |
c906108c SS |
4241 | { |
4242 | bpstat p = NULL; | |
4243 | bpstat tmp; | |
4244 | bpstat retval = NULL; | |
4245 | ||
4246 | if (bs == NULL) | |
4247 | return bs; | |
4248 | ||
4249 | for (; bs != NULL; bs = bs->next) | |
4250 | { | |
4251 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4252 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4253 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4254 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4255 | if (bs->old_val != NULL) |
3c3185ac JK |
4256 | { |
4257 | tmp->old_val = value_copy (bs->old_val); | |
4258 | release_value (tmp->old_val); | |
4259 | } | |
31cc81e9 | 4260 | |
c906108c SS |
4261 | if (p == NULL) |
4262 | /* This is the first thing in the chain. */ | |
4263 | retval = tmp; | |
4264 | else | |
4265 | p->next = tmp; | |
4266 | p = tmp; | |
4267 | } | |
4268 | p->next = NULL; | |
4269 | return retval; | |
4270 | } | |
4271 | ||
4a64f543 | 4272 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4273 | |
4274 | bpstat | |
fba45db2 | 4275 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4276 | { |
c5aa993b JM |
4277 | if (bsp == NULL) |
4278 | return NULL; | |
c906108c | 4279 | |
c5aa993b JM |
4280 | for (; bsp != NULL; bsp = bsp->next) |
4281 | { | |
f431efe5 | 4282 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4283 | return bsp; |
4284 | } | |
c906108c SS |
4285 | return NULL; |
4286 | } | |
4287 | ||
ab04a2af TT |
4288 | /* See breakpoint.h. */ |
4289 | ||
47591c29 | 4290 | int |
427cd150 | 4291 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4292 | { |
ab04a2af TT |
4293 | for (; bsp != NULL; bsp = bsp->next) |
4294 | { | |
427cd150 TT |
4295 | if (bsp->breakpoint_at == NULL) |
4296 | { | |
4297 | /* A moribund location can never explain a signal other than | |
4298 | GDB_SIGNAL_TRAP. */ | |
4299 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4300 | return 1; |
427cd150 TT |
4301 | } |
4302 | else | |
47591c29 PA |
4303 | { |
4304 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4305 | sig)) | |
4306 | return 1; | |
4307 | } | |
ab04a2af TT |
4308 | } |
4309 | ||
47591c29 | 4310 | return 0; |
ab04a2af TT |
4311 | } |
4312 | ||
4a64f543 MS |
4313 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4314 | stopped at. *BSP upon return is a bpstat which points to the | |
4315 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4316 | good for anything but further calls to bpstat_num). | |
4317 | ||
8671a17b PA |
4318 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4319 | Return -1 if stopped at a breakpoint that has been deleted since | |
4320 | we set it. | |
4321 | Return 1 otherwise. */ | |
c906108c SS |
4322 | |
4323 | int | |
8671a17b | 4324 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4325 | { |
4326 | struct breakpoint *b; | |
4327 | ||
4328 | if ((*bsp) == NULL) | |
4329 | return 0; /* No more breakpoint values */ | |
8671a17b | 4330 | |
4a64f543 MS |
4331 | /* We assume we'll never have several bpstats that correspond to a |
4332 | single breakpoint -- otherwise, this function might return the | |
4333 | same number more than once and this will look ugly. */ | |
f431efe5 | 4334 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4335 | *bsp = (*bsp)->next; |
4336 | if (b == NULL) | |
4337 | return -1; /* breakpoint that's been deleted since */ | |
4338 | ||
4339 | *num = b->number; /* We have its number */ | |
4340 | return 1; | |
c906108c SS |
4341 | } |
4342 | ||
e93ca019 | 4343 | /* See breakpoint.h. */ |
c906108c SS |
4344 | |
4345 | void | |
e93ca019 | 4346 | bpstat_clear_actions (void) |
c906108c | 4347 | { |
e93ca019 JK |
4348 | struct thread_info *tp; |
4349 | bpstat bs; | |
4350 | ||
4351 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4352 | return; | |
4353 | ||
4354 | tp = find_thread_ptid (inferior_ptid); | |
4355 | if (tp == NULL) | |
4356 | return; | |
4357 | ||
4358 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4359 | { |
9add0f1b | 4360 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4361 | |
c906108c SS |
4362 | if (bs->old_val != NULL) |
4363 | { | |
4364 | value_free (bs->old_val); | |
4365 | bs->old_val = NULL; | |
4366 | } | |
4367 | } | |
4368 | } | |
4369 | ||
f3b1572e PA |
4370 | /* Called when a command is about to proceed the inferior. */ |
4371 | ||
4372 | static void | |
4373 | breakpoint_about_to_proceed (void) | |
4374 | { | |
4375 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4376 | { | |
4377 | struct thread_info *tp = inferior_thread (); | |
4378 | ||
4379 | /* Allow inferior function calls in breakpoint commands to not | |
4380 | interrupt the command list. When the call finishes | |
4381 | successfully, the inferior will be standing at the same | |
4382 | breakpoint as if nothing happened. */ | |
16c381f0 | 4383 | if (tp->control.in_infcall) |
f3b1572e PA |
4384 | return; |
4385 | } | |
4386 | ||
4387 | breakpoint_proceeded = 1; | |
4388 | } | |
4389 | ||
4a64f543 MS |
4390 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4391 | command. */ | |
c906108c | 4392 | static void |
4efb68b1 | 4393 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4394 | { |
4395 | executing_breakpoint_commands = 0; | |
4396 | } | |
4397 | ||
abf85f46 JK |
4398 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4399 | or its equivalent. */ | |
4400 | ||
4401 | static int | |
4402 | command_line_is_silent (struct command_line *cmd) | |
4403 | { | |
4404 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4405 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4406 | } | |
4407 | ||
4a64f543 MS |
4408 | /* Execute all the commands associated with all the breakpoints at |
4409 | this location. Any of these commands could cause the process to | |
4410 | proceed beyond this point, etc. We look out for such changes by | |
4411 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4412 | |
347bddb7 PA |
4413 | Returns true if a breakpoint command resumed the inferior. In that |
4414 | case, it is the caller's responsibility to recall it again with the | |
4415 | bpstat of the current thread. */ | |
4416 | ||
4417 | static int | |
4418 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4419 | { |
4420 | bpstat bs; | |
4421 | struct cleanup *old_chain; | |
347bddb7 | 4422 | int again = 0; |
c906108c SS |
4423 | |
4424 | /* Avoid endless recursion if a `source' command is contained | |
4425 | in bs->commands. */ | |
4426 | if (executing_breakpoint_commands) | |
347bddb7 | 4427 | return 0; |
c906108c SS |
4428 | |
4429 | executing_breakpoint_commands = 1; | |
4430 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4431 | ||
cf6c5ffb TT |
4432 | prevent_dont_repeat (); |
4433 | ||
4a64f543 | 4434 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4435 | bs = *bsp; |
4436 | ||
4437 | breakpoint_proceeded = 0; | |
4438 | for (; bs != NULL; bs = bs->next) | |
4439 | { | |
9add0f1b | 4440 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4441 | struct command_line *cmd; |
4442 | struct cleanup *this_cmd_tree_chain; | |
4443 | ||
4444 | /* Take ownership of the BSP's command tree, if it has one. | |
4445 | ||
4446 | The command tree could legitimately contain commands like | |
4447 | 'step' and 'next', which call clear_proceed_status, which | |
4448 | frees stop_bpstat's command tree. To make sure this doesn't | |
4449 | free the tree we're executing out from under us, we need to | |
4450 | take ownership of the tree ourselves. Since a given bpstat's | |
4451 | commands are only executed once, we don't need to copy it; we | |
4452 | can clear the pointer in the bpstat, and make sure we free | |
4453 | the tree when we're done. */ | |
9add0f1b TT |
4454 | ccmd = bs->commands; |
4455 | bs->commands = NULL; | |
abf85f46 JK |
4456 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4457 | cmd = ccmd ? ccmd->commands : NULL; | |
4458 | if (command_line_is_silent (cmd)) | |
4459 | { | |
4460 | /* The action has been already done by bpstat_stop_status. */ | |
4461 | cmd = cmd->next; | |
4462 | } | |
6c50ab1c | 4463 | |
c906108c SS |
4464 | while (cmd != NULL) |
4465 | { | |
4466 | execute_control_command (cmd); | |
4467 | ||
4468 | if (breakpoint_proceeded) | |
4469 | break; | |
4470 | else | |
4471 | cmd = cmd->next; | |
4472 | } | |
6c50ab1c JB |
4473 | |
4474 | /* We can free this command tree now. */ | |
4475 | do_cleanups (this_cmd_tree_chain); | |
4476 | ||
c906108c | 4477 | if (breakpoint_proceeded) |
32c1e744 VP |
4478 | { |
4479 | if (target_can_async_p ()) | |
347bddb7 PA |
4480 | /* If we are in async mode, then the target might be still |
4481 | running, not stopped at any breakpoint, so nothing for | |
4482 | us to do here -- just return to the event loop. */ | |
4483 | ; | |
32c1e744 VP |
4484 | else |
4485 | /* In sync mode, when execute_control_command returns | |
4486 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4487 | Breakpoint commands for that stop were not run, since |
4488 | execute_command does not run breakpoint commands -- | |
4489 | only command_line_handler does, but that one is not | |
4490 | involved in execution of breakpoint commands. So, we | |
4491 | can now execute breakpoint commands. It should be | |
4492 | noted that making execute_command do bpstat actions is | |
4493 | not an option -- in this case we'll have recursive | |
4494 | invocation of bpstat for each breakpoint with a | |
4495 | command, and can easily blow up GDB stack. Instead, we | |
4496 | return true, which will trigger the caller to recall us | |
4497 | with the new stop_bpstat. */ | |
4498 | again = 1; | |
4499 | break; | |
32c1e744 | 4500 | } |
c906108c | 4501 | } |
c2b8ed2c | 4502 | do_cleanups (old_chain); |
347bddb7 PA |
4503 | return again; |
4504 | } | |
4505 | ||
4506 | void | |
4507 | bpstat_do_actions (void) | |
4508 | { | |
353d1d73 JK |
4509 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4510 | ||
347bddb7 PA |
4511 | /* Do any commands attached to breakpoint we are stopped at. */ |
4512 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4513 | && target_has_execution | |
4514 | && !is_exited (inferior_ptid) | |
4515 | && !is_executing (inferior_ptid)) | |
4516 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4517 | and only return when it is stopped at the next breakpoint, we | |
4518 | keep doing breakpoint actions until it returns false to | |
4519 | indicate the inferior was not resumed. */ | |
16c381f0 | 4520 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4521 | break; |
353d1d73 JK |
4522 | |
4523 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4524 | } |
4525 | ||
fa4727a6 DJ |
4526 | /* Print out the (old or new) value associated with a watchpoint. */ |
4527 | ||
4528 | static void | |
4529 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4530 | { | |
4531 | if (val == NULL) | |
4532 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4533 | else | |
79a45b7d TT |
4534 | { |
4535 | struct value_print_options opts; | |
4536 | get_user_print_options (&opts); | |
4537 | value_print (val, stream, &opts); | |
4538 | } | |
fa4727a6 DJ |
4539 | } |
4540 | ||
e514a9d6 | 4541 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4542 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4543 | 'print_it' in the bpstat structure. Under some circumstances we |
4544 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4545 | normal_stop(). */ |
e514a9d6 JM |
4546 | |
4547 | static enum print_stop_action | |
4548 | print_bp_stop_message (bpstat bs) | |
4549 | { | |
4550 | switch (bs->print_it) | |
4551 | { | |
4552 | case print_it_noop: | |
4a64f543 | 4553 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4554 | return PRINT_UNKNOWN; |
4555 | break; | |
4556 | ||
4557 | case print_it_done: | |
4558 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4559 | relevant messages. */ |
e514a9d6 JM |
4560 | return PRINT_SRC_AND_LOC; |
4561 | break; | |
4562 | ||
4563 | case print_it_normal: | |
4f8d1dc6 | 4564 | { |
f431efe5 PA |
4565 | struct breakpoint *b = bs->breakpoint_at; |
4566 | ||
1a6a67de TJB |
4567 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4568 | which has since been deleted. */ | |
4569 | if (b == NULL) | |
4570 | return PRINT_UNKNOWN; | |
4571 | ||
348d480f PA |
4572 | /* Normal case. Call the breakpoint's print_it method. */ |
4573 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4574 | } |
348d480f | 4575 | break; |
3086aeae | 4576 | |
e514a9d6 | 4577 | default: |
8e65ff28 | 4578 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4579 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4580 | break; |
c906108c | 4581 | } |
c906108c SS |
4582 | } |
4583 | ||
edcc5120 TT |
4584 | /* A helper function that prints a shared library stopped event. */ |
4585 | ||
4586 | static void | |
4587 | print_solib_event (int is_catchpoint) | |
4588 | { | |
4589 | int any_deleted | |
4590 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4591 | int any_added | |
4592 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4593 | ||
4594 | if (!is_catchpoint) | |
4595 | { | |
4596 | if (any_added || any_deleted) | |
4597 | ui_out_text (current_uiout, | |
4598 | _("Stopped due to shared library event:\n")); | |
4599 | else | |
4600 | ui_out_text (current_uiout, | |
4601 | _("Stopped due to shared library event (no " | |
4602 | "libraries added or removed)\n")); | |
4603 | } | |
4604 | ||
4605 | if (ui_out_is_mi_like_p (current_uiout)) | |
4606 | ui_out_field_string (current_uiout, "reason", | |
4607 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4608 | ||
4609 | if (any_deleted) | |
4610 | { | |
4611 | struct cleanup *cleanup; | |
4612 | char *name; | |
4613 | int ix; | |
4614 | ||
4615 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4616 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4617 | "removed"); | |
4618 | for (ix = 0; | |
4619 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4620 | ix, name); | |
4621 | ++ix) | |
4622 | { | |
4623 | if (ix > 0) | |
4624 | ui_out_text (current_uiout, " "); | |
4625 | ui_out_field_string (current_uiout, "library", name); | |
4626 | ui_out_text (current_uiout, "\n"); | |
4627 | } | |
4628 | ||
4629 | do_cleanups (cleanup); | |
4630 | } | |
4631 | ||
4632 | if (any_added) | |
4633 | { | |
4634 | struct so_list *iter; | |
4635 | int ix; | |
4636 | struct cleanup *cleanup; | |
4637 | ||
4638 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4639 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4640 | "added"); | |
4641 | for (ix = 0; | |
4642 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4643 | ix, iter); | |
4644 | ++ix) | |
4645 | { | |
4646 | if (ix > 0) | |
4647 | ui_out_text (current_uiout, " "); | |
4648 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4649 | ui_out_text (current_uiout, "\n"); | |
4650 | } | |
4651 | ||
4652 | do_cleanups (cleanup); | |
4653 | } | |
4654 | } | |
4655 | ||
e514a9d6 JM |
4656 | /* Print a message indicating what happened. This is called from |
4657 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4658 | list - a list of the eventpoints that caused this stop. KIND is |
4659 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4660 | routine calls the generic print routine for printing a message |
4661 | about reasons for stopping. This will print (for example) the | |
4662 | "Breakpoint n," part of the output. The return value of this | |
4663 | routine is one of: | |
c906108c | 4664 | |
4a64f543 | 4665 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4666 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4667 | code to print the location. An example is |
c5aa993b JM |
4668 | "Breakpoint 1, " which should be followed by |
4669 | the location. | |
917317f4 | 4670 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4671 | to also print the location part of the message. |
4672 | An example is the catch/throw messages, which | |
4a64f543 | 4673 | don't require a location appended to the end. |
917317f4 | 4674 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4675 | further info to be printed. */ |
c906108c | 4676 | |
917317f4 | 4677 | enum print_stop_action |
36dfb11c | 4678 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4679 | { |
4680 | int val; | |
c5aa993b | 4681 | |
c906108c | 4682 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4683 | (Currently all watchpoints go on the bpstat whether hit or not. |
4684 | That probably could (should) be changed, provided care is taken | |
c906108c | 4685 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4686 | for (; bs; bs = bs->next) |
4687 | { | |
4688 | val = print_bp_stop_message (bs); | |
4689 | if (val == PRINT_SRC_ONLY | |
4690 | || val == PRINT_SRC_AND_LOC | |
4691 | || val == PRINT_NOTHING) | |
4692 | return val; | |
4693 | } | |
c906108c | 4694 | |
36dfb11c TT |
4695 | /* If we had hit a shared library event breakpoint, |
4696 | print_bp_stop_message would print out this message. If we hit an | |
4697 | OS-level shared library event, do the same thing. */ | |
4698 | if (kind == TARGET_WAITKIND_LOADED) | |
4699 | { | |
edcc5120 | 4700 | print_solib_event (0); |
36dfb11c TT |
4701 | return PRINT_NOTHING; |
4702 | } | |
4703 | ||
e514a9d6 | 4704 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4705 | with and nothing was printed. */ |
917317f4 | 4706 | return PRINT_UNKNOWN; |
c906108c SS |
4707 | } |
4708 | ||
c42bd95a DE |
4709 | /* Evaluate the expression EXP and return 1 if value is zero. |
4710 | This returns the inverse of the condition because it is called | |
4711 | from catch_errors which returns 0 if an exception happened, and if an | |
4712 | exception happens we want execution to stop. | |
4a64f543 | 4713 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4714 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4715 | |
4716 | static int | |
4efb68b1 | 4717 | breakpoint_cond_eval (void *exp) |
c906108c | 4718 | { |
278cd55f | 4719 | struct value *mark = value_mark (); |
c5aa993b | 4720 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4721 | |
c906108c SS |
4722 | value_free_to_mark (mark); |
4723 | return i; | |
4724 | } | |
4725 | ||
5760d0ab | 4726 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4727 | |
4728 | static bpstat | |
5760d0ab | 4729 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4730 | { |
4731 | bpstat bs; | |
4732 | ||
4733 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4734 | bs->next = NULL; |
4735 | **bs_link_pointer = bs; | |
4736 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4737 | bs->breakpoint_at = bl->owner; |
4738 | bs->bp_location_at = bl; | |
4739 | incref_bp_location (bl); | |
c906108c SS |
4740 | /* If the condition is false, etc., don't do the commands. */ |
4741 | bs->commands = NULL; | |
4742 | bs->old_val = NULL; | |
4743 | bs->print_it = print_it_normal; | |
4744 | return bs; | |
4745 | } | |
4746 | \f | |
d983da9c DJ |
4747 | /* The target has stopped with waitstatus WS. Check if any hardware |
4748 | watchpoints have triggered, according to the target. */ | |
4749 | ||
4750 | int | |
4751 | watchpoints_triggered (struct target_waitstatus *ws) | |
4752 | { | |
d92524f1 | 4753 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4754 | CORE_ADDR addr; |
4755 | struct breakpoint *b; | |
4756 | ||
4757 | if (!stopped_by_watchpoint) | |
4758 | { | |
4759 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4760 | as not triggered. */ | |
4761 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4762 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4763 | { |
4764 | struct watchpoint *w = (struct watchpoint *) b; | |
4765 | ||
4766 | w->watchpoint_triggered = watch_triggered_no; | |
4767 | } | |
d983da9c DJ |
4768 | |
4769 | return 0; | |
4770 | } | |
4771 | ||
4772 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4773 | { | |
4774 | /* We were stopped by a watchpoint, but we don't know where. | |
4775 | Mark all watchpoints as unknown. */ | |
4776 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4777 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4778 | { |
4779 | struct watchpoint *w = (struct watchpoint *) b; | |
4780 | ||
4781 | w->watchpoint_triggered = watch_triggered_unknown; | |
4782 | } | |
d983da9c | 4783 | |
3c4797ba | 4784 | return 1; |
d983da9c DJ |
4785 | } |
4786 | ||
4787 | /* The target could report the data address. Mark watchpoints | |
4788 | affected by this data address as triggered, and all others as not | |
4789 | triggered. */ | |
4790 | ||
4791 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4792 | if (is_hardware_watchpoint (b)) |
d983da9c | 4793 | { |
3a5c3e22 | 4794 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4795 | struct bp_location *loc; |
d983da9c | 4796 | |
3a5c3e22 | 4797 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4798 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4799 | { |
3a5c3e22 | 4800 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4801 | { |
3a5c3e22 PA |
4802 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4803 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4804 | |
4805 | if (newaddr == start) | |
4806 | { | |
3a5c3e22 | 4807 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4808 | break; |
4809 | } | |
4810 | } | |
4811 | /* Exact match not required. Within range is sufficient. */ | |
4812 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4813 | addr, loc->address, | |
4814 | loc->length)) | |
4815 | { | |
3a5c3e22 | 4816 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4817 | break; |
4818 | } | |
4819 | } | |
d983da9c DJ |
4820 | } |
4821 | ||
4822 | return 1; | |
4823 | } | |
4824 | ||
c906108c SS |
4825 | /* Possible return values for watchpoint_check (this can't be an enum |
4826 | because of check_errors). */ | |
4827 | /* The watchpoint has been deleted. */ | |
4828 | #define WP_DELETED 1 | |
4829 | /* The value has changed. */ | |
4830 | #define WP_VALUE_CHANGED 2 | |
4831 | /* The value has not changed. */ | |
4832 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4833 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4834 | #define WP_IGNORE 4 | |
c906108c SS |
4835 | |
4836 | #define BP_TEMPFLAG 1 | |
4837 | #define BP_HARDWAREFLAG 2 | |
4838 | ||
4a64f543 MS |
4839 | /* Evaluate watchpoint condition expression and check if its value |
4840 | changed. | |
553e4c11 JB |
4841 | |
4842 | P should be a pointer to struct bpstat, but is defined as a void * | |
4843 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4844 | |
4845 | static int | |
4efb68b1 | 4846 | watchpoint_check (void *p) |
c906108c SS |
4847 | { |
4848 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4849 | struct watchpoint *b; |
c906108c SS |
4850 | struct frame_info *fr; |
4851 | int within_current_scope; | |
4852 | ||
f431efe5 | 4853 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4854 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4855 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4856 | |
f6bc2008 PA |
4857 | /* If this is a local watchpoint, we only want to check if the |
4858 | watchpoint frame is in scope if the current thread is the thread | |
4859 | that was used to create the watchpoint. */ | |
4860 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4861 | return WP_IGNORE; |
f6bc2008 | 4862 | |
c906108c SS |
4863 | if (b->exp_valid_block == NULL) |
4864 | within_current_scope = 1; | |
4865 | else | |
4866 | { | |
edb3359d DJ |
4867 | struct frame_info *frame = get_current_frame (); |
4868 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4869 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4870 | ||
4a64f543 MS |
4871 | /* in_function_epilogue_p() returns a non-zero value if we're |
4872 | still in the function but the stack frame has already been | |
4873 | invalidated. Since we can't rely on the values of local | |
4874 | variables after the stack has been destroyed, we are treating | |
4875 | the watchpoint in that state as `not changed' without further | |
4876 | checking. Don't mark watchpoints as changed if the current | |
4877 | frame is in an epilogue - even if they are in some other | |
4878 | frame, our view of the stack is likely to be wrong and | |
4879 | frame_find_by_id could error out. */ | |
a0f49112 | 4880 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 4881 | return WP_IGNORE; |
a0f49112 | 4882 | |
101dcfbe | 4883 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4884 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4885 | |
4886 | /* If we've gotten confused in the unwinder, we might have | |
4887 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4888 | if (within_current_scope) |
4889 | { | |
4890 | struct symbol *function; | |
4891 | ||
4892 | function = get_frame_function (fr); | |
4893 | if (function == NULL | |
4894 | || !contained_in (b->exp_valid_block, | |
4895 | SYMBOL_BLOCK_VALUE (function))) | |
4896 | within_current_scope = 0; | |
4897 | } | |
69fbadd5 | 4898 | |
edb3359d | 4899 | if (within_current_scope) |
c906108c SS |
4900 | /* If we end up stopping, the current frame will get selected |
4901 | in normal_stop. So this call to select_frame won't affect | |
4902 | the user. */ | |
0f7d239c | 4903 | select_frame (fr); |
c906108c | 4904 | } |
c5aa993b | 4905 | |
c906108c SS |
4906 | if (within_current_scope) |
4907 | { | |
4a64f543 MS |
4908 | /* We use value_{,free_to_}mark because it could be a *long* |
4909 | time before we return to the command level and call | |
4910 | free_all_values. We can't call free_all_values because we | |
4911 | might be in the middle of evaluating a function call. */ | |
c906108c | 4912 | |
0cf6dd15 | 4913 | int pc = 0; |
9c06b0b4 | 4914 | struct value *mark; |
fa4727a6 DJ |
4915 | struct value *new_val; |
4916 | ||
3a5c3e22 | 4917 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
4918 | /* Since we don't know the exact trigger address (from |
4919 | stopped_data_address), just tell the user we've triggered | |
4920 | a mask watchpoint. */ | |
4921 | return WP_VALUE_CHANGED; | |
4922 | ||
4923 | mark = value_mark (); | |
3a1115a0 | 4924 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4925 | |
4a64f543 MS |
4926 | /* We use value_equal_contents instead of value_equal because |
4927 | the latter coerces an array to a pointer, thus comparing just | |
4928 | the address of the array instead of its contents. This is | |
4929 | not what we want. */ | |
fa4727a6 | 4930 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 4931 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 4932 | { |
fa4727a6 DJ |
4933 | if (new_val != NULL) |
4934 | { | |
4935 | release_value (new_val); | |
4936 | value_free_to_mark (mark); | |
4937 | } | |
c906108c SS |
4938 | bs->old_val = b->val; |
4939 | b->val = new_val; | |
fa4727a6 | 4940 | b->val_valid = 1; |
c906108c SS |
4941 | return WP_VALUE_CHANGED; |
4942 | } | |
4943 | else | |
4944 | { | |
60e1c644 | 4945 | /* Nothing changed. */ |
c906108c | 4946 | value_free_to_mark (mark); |
c906108c SS |
4947 | return WP_VALUE_NOT_CHANGED; |
4948 | } | |
4949 | } | |
4950 | else | |
4951 | { | |
79a45e25 PA |
4952 | struct ui_out *uiout = current_uiout; |
4953 | ||
c906108c | 4954 | /* This seems like the only logical thing to do because |
c5aa993b JM |
4955 | if we temporarily ignored the watchpoint, then when |
4956 | we reenter the block in which it is valid it contains | |
4957 | garbage (in the case of a function, it may have two | |
4958 | garbage values, one before and one after the prologue). | |
4959 | So we can't even detect the first assignment to it and | |
4960 | watch after that (since the garbage may or may not equal | |
4961 | the first value assigned). */ | |
348d480f PA |
4962 | /* We print all the stop information in |
4963 | breakpoint_ops->print_it, but in this case, by the time we | |
4964 | call breakpoint_ops->print_it this bp will be deleted | |
4965 | already. So we have no choice but print the information | |
4966 | here. */ | |
9dc5e2a9 | 4967 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4968 | ui_out_field_string |
4969 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 4970 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 4971 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
4972 | ui_out_text (uiout, |
4973 | " deleted because the program has left the block in\n\ | |
8b93c638 | 4974 | which its expression is valid.\n"); |
4ce44c66 | 4975 | |
cdac0397 | 4976 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 4977 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 4978 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4979 | |
4980 | return WP_DELETED; | |
4981 | } | |
4982 | } | |
4983 | ||
18a18393 | 4984 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4985 | breakpoint location BL. This function does not check if we should |
4986 | stop, only if BL explains the stop. */ | |
4987 | ||
18a18393 | 4988 | static int |
6c95b8df | 4989 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
4990 | struct address_space *aspace, CORE_ADDR bp_addr, |
4991 | const struct target_waitstatus *ws) | |
18a18393 VP |
4992 | { |
4993 | struct breakpoint *b = bl->owner; | |
4994 | ||
348d480f | 4995 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4996 | gdb_assert (b != NULL); |
4997 | ||
09ac7c10 | 4998 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4999 | } |
5000 | ||
3a5c3e22 PA |
5001 | /* Determine if the watched values have actually changed, and we |
5002 | should stop. If not, set BS->stop to 0. */ | |
5003 | ||
18a18393 VP |
5004 | static void |
5005 | bpstat_check_watchpoint (bpstat bs) | |
5006 | { | |
2bdf28a0 | 5007 | const struct bp_location *bl; |
3a5c3e22 | 5008 | struct watchpoint *b; |
2bdf28a0 JK |
5009 | |
5010 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5011 | bl = bs->bp_location_at; |
2bdf28a0 | 5012 | gdb_assert (bl != NULL); |
3a5c3e22 | 5013 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5014 | gdb_assert (b != NULL); |
18a18393 | 5015 | |
18a18393 | 5016 | { |
18a18393 VP |
5017 | int must_check_value = 0; |
5018 | ||
3a5c3e22 | 5019 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5020 | /* For a software watchpoint, we must always check the |
5021 | watched value. */ | |
5022 | must_check_value = 1; | |
5023 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5024 | /* We have a hardware watchpoint (read, write, or access) | |
5025 | and the target earlier reported an address watched by | |
5026 | this watchpoint. */ | |
5027 | must_check_value = 1; | |
5028 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5029 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5030 | /* We were stopped by a hardware watchpoint, but the target could |
5031 | not report the data address. We must check the watchpoint's | |
5032 | value. Access and read watchpoints are out of luck; without | |
5033 | a data address, we can't figure it out. */ | |
5034 | must_check_value = 1; | |
3a5c3e22 | 5035 | |
18a18393 VP |
5036 | if (must_check_value) |
5037 | { | |
3e43a32a MS |
5038 | char *message |
5039 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5040 | b->base.number); |
18a18393 VP |
5041 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5042 | int e = catch_errors (watchpoint_check, bs, message, | |
5043 | RETURN_MASK_ALL); | |
5044 | do_cleanups (cleanups); | |
5045 | switch (e) | |
5046 | { | |
5047 | case WP_DELETED: | |
5048 | /* We've already printed what needs to be printed. */ | |
5049 | bs->print_it = print_it_done; | |
5050 | /* Stop. */ | |
5051 | break; | |
60e1c644 PA |
5052 | case WP_IGNORE: |
5053 | bs->print_it = print_it_noop; | |
5054 | bs->stop = 0; | |
5055 | break; | |
18a18393 | 5056 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5057 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5058 | { |
85d721b8 PA |
5059 | /* There are two cases to consider here: |
5060 | ||
4a64f543 | 5061 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5062 | In that case, trust the target, and always report |
5063 | the watchpoint hit to the user. Even though | |
5064 | reads don't cause value changes, the value may | |
5065 | have changed since the last time it was read, and | |
5066 | since we're not trapping writes, we will not see | |
5067 | those, and as such we should ignore our notion of | |
5068 | old value. | |
5069 | ||
4a64f543 | 5070 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5071 | reads and writes. There are two ways this may |
5072 | happen: | |
5073 | ||
4a64f543 | 5074 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5075 | reads only, but can break on accesses (reads or |
5076 | writes), such as e.g., x86. We detect this case | |
5077 | at the time we try to insert read watchpoints. | |
5078 | ||
4a64f543 | 5079 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5080 | watchpoints, but, the user set an access or write |
5081 | watchpoint watching the same memory as this read | |
5082 | watchpoint. | |
5083 | ||
5084 | If we're watching memory writes as well as reads, | |
5085 | ignore watchpoint hits when we find that the | |
5086 | value hasn't changed, as reads don't cause | |
5087 | changes. This still gives false positives when | |
5088 | the program writes the same value to memory as | |
5089 | what there was already in memory (we will confuse | |
5090 | it for a read), but it's much better than | |
5091 | nothing. */ | |
5092 | ||
5093 | int other_write_watchpoint = 0; | |
5094 | ||
5095 | if (bl->watchpoint_type == hw_read) | |
5096 | { | |
5097 | struct breakpoint *other_b; | |
5098 | ||
5099 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5100 | if (other_b->type == bp_hardware_watchpoint |
5101 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5102 | { |
3a5c3e22 PA |
5103 | struct watchpoint *other_w = |
5104 | (struct watchpoint *) other_b; | |
5105 | ||
5106 | if (other_w->watchpoint_triggered | |
5107 | == watch_triggered_yes) | |
5108 | { | |
5109 | other_write_watchpoint = 1; | |
5110 | break; | |
5111 | } | |
85d721b8 PA |
5112 | } |
5113 | } | |
5114 | ||
5115 | if (other_write_watchpoint | |
5116 | || bl->watchpoint_type == hw_access) | |
5117 | { | |
5118 | /* We're watching the same memory for writes, | |
5119 | and the value changed since the last time we | |
5120 | updated it, so this trap must be for a write. | |
5121 | Ignore it. */ | |
5122 | bs->print_it = print_it_noop; | |
5123 | bs->stop = 0; | |
5124 | } | |
18a18393 VP |
5125 | } |
5126 | break; | |
5127 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5128 | if (b->base.type == bp_hardware_watchpoint |
5129 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5130 | { |
5131 | /* Don't stop: write watchpoints shouldn't fire if | |
5132 | the value hasn't changed. */ | |
5133 | bs->print_it = print_it_noop; | |
5134 | bs->stop = 0; | |
5135 | } | |
5136 | /* Stop. */ | |
5137 | break; | |
5138 | default: | |
5139 | /* Can't happen. */ | |
5140 | case 0: | |
5141 | /* Error from catch_errors. */ | |
3a5c3e22 | 5142 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5143 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5144 | /* We've already printed what needs to be printed. */ |
5145 | bs->print_it = print_it_done; | |
5146 | break; | |
5147 | } | |
5148 | } | |
5149 | else /* must_check_value == 0 */ | |
5150 | { | |
5151 | /* This is a case where some watchpoint(s) triggered, but | |
5152 | not at the address of this watchpoint, or else no | |
5153 | watchpoint triggered after all. So don't print | |
5154 | anything for this watchpoint. */ | |
5155 | bs->print_it = print_it_noop; | |
5156 | bs->stop = 0; | |
5157 | } | |
5158 | } | |
5159 | } | |
5160 | ||
7d4df6a4 DE |
5161 | /* For breakpoints that are currently marked as telling gdb to stop, |
5162 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5163 | of breakpoint referred to by BS. If we should not stop for this |
5164 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5165 | |
18a18393 VP |
5166 | static void |
5167 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5168 | { | |
2bdf28a0 JK |
5169 | const struct bp_location *bl; |
5170 | struct breakpoint *b; | |
7d4df6a4 DE |
5171 | int value_is_zero = 0; |
5172 | struct expression *cond; | |
5173 | ||
5174 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5175 | |
5176 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5177 | bl = bs->bp_location_at; |
2bdf28a0 | 5178 | gdb_assert (bl != NULL); |
f431efe5 | 5179 | b = bs->breakpoint_at; |
2bdf28a0 | 5180 | gdb_assert (b != NULL); |
18a18393 | 5181 | |
b775012e LM |
5182 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5183 | need to do so again since GDB does not know if we stopped due to a | |
5184 | breakpoint or a single step breakpoint. */ | |
5185 | ||
18a18393 | 5186 | if (frame_id_p (b->frame_id) |
edb3359d | 5187 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5188 | { |
7d4df6a4 DE |
5189 | bs->stop = 0; |
5190 | return; | |
5191 | } | |
60e1c644 | 5192 | |
12ab52e9 PA |
5193 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5194 | evaluating the condition if this isn't the specified | |
5195 | thread/task. */ | |
5196 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5197 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5198 | ||
6c1b0f7b DE |
5199 | { |
5200 | bs->stop = 0; | |
5201 | return; | |
5202 | } | |
5203 | ||
6dddc817 DE |
5204 | /* Evaluate extension language breakpoints that have a "stop" method |
5205 | implemented. */ | |
5206 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5207 | |
7d4df6a4 DE |
5208 | if (is_watchpoint (b)) |
5209 | { | |
5210 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5211 | |
7d4df6a4 DE |
5212 | cond = w->cond_exp; |
5213 | } | |
5214 | else | |
5215 | cond = bl->cond; | |
60e1c644 | 5216 | |
7d4df6a4 DE |
5217 | if (cond && b->disposition != disp_del_at_next_stop) |
5218 | { | |
5219 | int within_current_scope = 1; | |
5220 | struct watchpoint * w; | |
60e1c644 | 5221 | |
7d4df6a4 DE |
5222 | /* We use value_mark and value_free_to_mark because it could |
5223 | be a long time before we return to the command level and | |
5224 | call free_all_values. We can't call free_all_values | |
5225 | because we might be in the middle of evaluating a | |
5226 | function call. */ | |
5227 | struct value *mark = value_mark (); | |
5228 | ||
5229 | if (is_watchpoint (b)) | |
5230 | w = (struct watchpoint *) b; | |
5231 | else | |
5232 | w = NULL; | |
5233 | ||
5234 | /* Need to select the frame, with all that implies so that | |
5235 | the conditions will have the right context. Because we | |
5236 | use the frame, we will not see an inlined function's | |
5237 | variables when we arrive at a breakpoint at the start | |
5238 | of the inlined function; the current frame will be the | |
5239 | call site. */ | |
5240 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5241 | select_frame (get_current_frame ()); | |
5242 | else | |
18a18393 | 5243 | { |
7d4df6a4 DE |
5244 | struct frame_info *frame; |
5245 | ||
5246 | /* For local watchpoint expressions, which particular | |
5247 | instance of a local is being watched matters, so we | |
5248 | keep track of the frame to evaluate the expression | |
5249 | in. To evaluate the condition however, it doesn't | |
5250 | really matter which instantiation of the function | |
5251 | where the condition makes sense triggers the | |
5252 | watchpoint. This allows an expression like "watch | |
5253 | global if q > 10" set in `func', catch writes to | |
5254 | global on all threads that call `func', or catch | |
5255 | writes on all recursive calls of `func' by a single | |
5256 | thread. We simply always evaluate the condition in | |
5257 | the innermost frame that's executing where it makes | |
5258 | sense to evaluate the condition. It seems | |
5259 | intuitive. */ | |
5260 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5261 | if (frame != NULL) | |
5262 | select_frame (frame); | |
5263 | else | |
5264 | within_current_scope = 0; | |
18a18393 | 5265 | } |
7d4df6a4 DE |
5266 | if (within_current_scope) |
5267 | value_is_zero | |
5268 | = catch_errors (breakpoint_cond_eval, cond, | |
5269 | "Error in testing breakpoint condition:\n", | |
5270 | RETURN_MASK_ALL); | |
5271 | else | |
18a18393 | 5272 | { |
7d4df6a4 DE |
5273 | warning (_("Watchpoint condition cannot be tested " |
5274 | "in the current scope")); | |
5275 | /* If we failed to set the right context for this | |
5276 | watchpoint, unconditionally report it. */ | |
5277 | value_is_zero = 0; | |
18a18393 | 5278 | } |
7d4df6a4 DE |
5279 | /* FIXME-someday, should give breakpoint #. */ |
5280 | value_free_to_mark (mark); | |
18a18393 | 5281 | } |
7d4df6a4 DE |
5282 | |
5283 | if (cond && value_is_zero) | |
5284 | { | |
5285 | bs->stop = 0; | |
5286 | } | |
7d4df6a4 DE |
5287 | else if (b->ignore_count > 0) |
5288 | { | |
5289 | b->ignore_count--; | |
5290 | bs->stop = 0; | |
5291 | /* Increase the hit count even though we don't stop. */ | |
5292 | ++(b->hit_count); | |
5293 | observer_notify_breakpoint_modified (b); | |
5294 | } | |
18a18393 VP |
5295 | } |
5296 | ||
5297 | ||
9709f61c | 5298 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5299 | BP_ADDR in thread PTID. |
c906108c | 5300 | |
d983da9c | 5301 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5302 | don't understand this stop. Result is a chain of bpstat's such |
5303 | that: | |
c906108c | 5304 | |
c5aa993b | 5305 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5306 | |
c5aa993b | 5307 | if we understand why we stopped, the result is not null. |
c906108c | 5308 | |
c5aa993b JM |
5309 | Each element of the chain refers to a particular breakpoint or |
5310 | watchpoint at which we have stopped. (We may have stopped for | |
5311 | several reasons concurrently.) | |
c906108c | 5312 | |
c5aa993b JM |
5313 | Each element of the chain has valid next, breakpoint_at, |
5314 | commands, FIXME??? fields. */ | |
c906108c SS |
5315 | |
5316 | bpstat | |
6c95b8df | 5317 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5318 | CORE_ADDR bp_addr, ptid_t ptid, |
5319 | const struct target_waitstatus *ws) | |
c906108c | 5320 | { |
0d381245 | 5321 | struct breakpoint *b = NULL; |
afe38095 | 5322 | struct bp_location *bl; |
20874c92 | 5323 | struct bp_location *loc; |
5760d0ab JK |
5324 | /* First item of allocated bpstat's. */ |
5325 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5326 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5327 | bpstat bs; |
20874c92 | 5328 | int ix; |
429374b8 | 5329 | int need_remove_insert; |
f431efe5 | 5330 | int removed_any; |
c906108c | 5331 | |
f431efe5 PA |
5332 | /* First, build the bpstat chain with locations that explain a |
5333 | target stop, while being careful to not set the target running, | |
5334 | as that may invalidate locations (in particular watchpoint | |
5335 | locations are recreated). Resuming will happen here with | |
5336 | breakpoint conditions or watchpoint expressions that include | |
5337 | inferior function calls. */ | |
c5aa993b | 5338 | |
429374b8 JK |
5339 | ALL_BREAKPOINTS (b) |
5340 | { | |
5341 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5342 | continue; | |
a5606eee | 5343 | |
429374b8 JK |
5344 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5345 | { | |
4a64f543 MS |
5346 | /* For hardware watchpoints, we look only at the first |
5347 | location. The watchpoint_check function will work on the | |
5348 | entire expression, not the individual locations. For | |
5349 | read watchpoints, the watchpoints_triggered function has | |
5350 | checked all locations already. */ | |
429374b8 JK |
5351 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5352 | break; | |
18a18393 | 5353 | |
f6592439 | 5354 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5355 | continue; |
c5aa993b | 5356 | |
09ac7c10 | 5357 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5358 | continue; |
c5aa993b | 5359 | |
4a64f543 MS |
5360 | /* Come here if it's a watchpoint, or if the break address |
5361 | matches. */ | |
c5aa993b | 5362 | |
4a64f543 MS |
5363 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5364 | explain stop. */ | |
c5aa993b | 5365 | |
f431efe5 PA |
5366 | /* Assume we stop. Should we find a watchpoint that is not |
5367 | actually triggered, or if the condition of the breakpoint | |
5368 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5369 | bs->stop = 1; |
5370 | bs->print = 1; | |
d983da9c | 5371 | |
f431efe5 PA |
5372 | /* If this is a scope breakpoint, mark the associated |
5373 | watchpoint as triggered so that we will handle the | |
5374 | out-of-scope event. We'll get to the watchpoint next | |
5375 | iteration. */ | |
d0fb5eae | 5376 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5377 | { |
5378 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5379 | ||
5380 | w->watchpoint_triggered = watch_triggered_yes; | |
5381 | } | |
f431efe5 PA |
5382 | } |
5383 | } | |
5384 | ||
5385 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5386 | { | |
f1310107 | 5387 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5388 | { |
5760d0ab | 5389 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5390 | /* For hits of moribund locations, we should just proceed. */ |
5391 | bs->stop = 0; | |
5392 | bs->print = 0; | |
5393 | bs->print_it = print_it_noop; | |
5394 | } | |
5395 | } | |
5396 | ||
edcc5120 TT |
5397 | /* A bit of special processing for shlib breakpoints. We need to |
5398 | process solib loading here, so that the lists of loaded and | |
5399 | unloaded libraries are correct before we handle "catch load" and | |
5400 | "catch unload". */ | |
5401 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5402 | { | |
5d268276 | 5403 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5404 | { |
5405 | handle_solib_event (); | |
5406 | break; | |
5407 | } | |
5408 | } | |
5409 | ||
f431efe5 PA |
5410 | /* Now go through the locations that caused the target to stop, and |
5411 | check whether we're interested in reporting this stop to higher | |
5412 | layers, or whether we should resume the target transparently. */ | |
5413 | ||
5414 | removed_any = 0; | |
5415 | ||
5760d0ab | 5416 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5417 | { |
5418 | if (!bs->stop) | |
5419 | continue; | |
5420 | ||
f431efe5 | 5421 | b = bs->breakpoint_at; |
348d480f PA |
5422 | b->ops->check_status (bs); |
5423 | if (bs->stop) | |
28010a5d | 5424 | { |
348d480f | 5425 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5426 | |
429374b8 JK |
5427 | if (bs->stop) |
5428 | { | |
5429 | ++(b->hit_count); | |
8d3788bd | 5430 | observer_notify_breakpoint_modified (b); |
c906108c | 5431 | |
4a64f543 | 5432 | /* We will stop here. */ |
429374b8 JK |
5433 | if (b->disposition == disp_disable) |
5434 | { | |
816338b5 SS |
5435 | --(b->enable_count); |
5436 | if (b->enable_count <= 0 | |
5437 | && b->enable_state != bp_permanent) | |
429374b8 | 5438 | b->enable_state = bp_disabled; |
f431efe5 | 5439 | removed_any = 1; |
429374b8 JK |
5440 | } |
5441 | if (b->silent) | |
5442 | bs->print = 0; | |
5443 | bs->commands = b->commands; | |
9add0f1b | 5444 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5445 | if (command_line_is_silent (bs->commands |
5446 | ? bs->commands->commands : NULL)) | |
5447 | bs->print = 0; | |
9d6e6e84 HZ |
5448 | |
5449 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5450 | } |
5451 | ||
348d480f | 5452 | } |
a9b3a50f PA |
5453 | |
5454 | /* Print nothing for this entry if we don't stop or don't | |
5455 | print. */ | |
5456 | if (!bs->stop || !bs->print) | |
5457 | bs->print_it = print_it_noop; | |
429374b8 | 5458 | } |
876fa593 | 5459 | |
d983da9c DJ |
5460 | /* If we aren't stopping, the value of some hardware watchpoint may |
5461 | not have changed, but the intermediate memory locations we are | |
5462 | watching may have. Don't bother if we're stopping; this will get | |
5463 | done later. */ | |
d832cb68 | 5464 | need_remove_insert = 0; |
5760d0ab JK |
5465 | if (! bpstat_causes_stop (bs_head)) |
5466 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5467 | if (!bs->stop |
f431efe5 PA |
5468 | && bs->breakpoint_at |
5469 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5470 | { |
3a5c3e22 PA |
5471 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5472 | ||
5473 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5474 | need_remove_insert = 1; |
d983da9c DJ |
5475 | } |
5476 | ||
d832cb68 | 5477 | if (need_remove_insert) |
2d134ed3 | 5478 | update_global_location_list (1); |
f431efe5 PA |
5479 | else if (removed_any) |
5480 | update_global_location_list (0); | |
d832cb68 | 5481 | |
5760d0ab | 5482 | return bs_head; |
c906108c | 5483 | } |
628fe4e4 JK |
5484 | |
5485 | static void | |
5486 | handle_jit_event (void) | |
5487 | { | |
5488 | struct frame_info *frame; | |
5489 | struct gdbarch *gdbarch; | |
5490 | ||
5491 | /* Switch terminal for any messages produced by | |
5492 | breakpoint_re_set. */ | |
5493 | target_terminal_ours_for_output (); | |
5494 | ||
5495 | frame = get_current_frame (); | |
5496 | gdbarch = get_frame_arch (frame); | |
5497 | ||
5498 | jit_event_handler (gdbarch); | |
5499 | ||
5500 | target_terminal_inferior (); | |
5501 | } | |
5502 | ||
5503 | /* Prepare WHAT final decision for infrun. */ | |
5504 | ||
5505 | /* Decide what infrun needs to do with this bpstat. */ | |
5506 | ||
c906108c | 5507 | struct bpstat_what |
0e30163f | 5508 | bpstat_what (bpstat bs_head) |
c906108c | 5509 | { |
c906108c | 5510 | struct bpstat_what retval; |
628fe4e4 | 5511 | int jit_event = 0; |
0e30163f | 5512 | bpstat bs; |
c906108c | 5513 | |
628fe4e4 | 5514 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5515 | retval.call_dummy = STOP_NONE; |
186c406b | 5516 | retval.is_longjmp = 0; |
628fe4e4 | 5517 | |
0e30163f | 5518 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5519 | { |
628fe4e4 JK |
5520 | /* Extract this BS's action. After processing each BS, we check |
5521 | if its action overrides all we've seem so far. */ | |
5522 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5523 | enum bptype bptype; | |
5524 | ||
c906108c | 5525 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5526 | { |
5527 | /* I suspect this can happen if it was a momentary | |
5528 | breakpoint which has since been deleted. */ | |
5529 | bptype = bp_none; | |
5530 | } | |
20874c92 | 5531 | else |
f431efe5 | 5532 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5533 | |
5534 | switch (bptype) | |
c906108c SS |
5535 | { |
5536 | case bp_none: | |
628fe4e4 | 5537 | break; |
c906108c SS |
5538 | case bp_breakpoint: |
5539 | case bp_hardware_breakpoint: | |
5540 | case bp_until: | |
5541 | case bp_finish: | |
a9b3a50f | 5542 | case bp_shlib_event: |
c906108c SS |
5543 | if (bs->stop) |
5544 | { | |
5545 | if (bs->print) | |
628fe4e4 | 5546 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5547 | else |
628fe4e4 | 5548 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5549 | } |
5550 | else | |
628fe4e4 | 5551 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5552 | break; |
5553 | case bp_watchpoint: | |
5554 | case bp_hardware_watchpoint: | |
5555 | case bp_read_watchpoint: | |
5556 | case bp_access_watchpoint: | |
5557 | if (bs->stop) | |
5558 | { | |
5559 | if (bs->print) | |
628fe4e4 | 5560 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5561 | else |
628fe4e4 | 5562 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5563 | } |
5564 | else | |
628fe4e4 JK |
5565 | { |
5566 | /* There was a watchpoint, but we're not stopping. | |
5567 | This requires no further action. */ | |
5568 | } | |
c906108c SS |
5569 | break; |
5570 | case bp_longjmp: | |
e2e4d78b | 5571 | case bp_longjmp_call_dummy: |
186c406b | 5572 | case bp_exception: |
628fe4e4 | 5573 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5574 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5575 | break; |
5576 | case bp_longjmp_resume: | |
186c406b | 5577 | case bp_exception_resume: |
628fe4e4 | 5578 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5579 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5580 | break; |
5581 | case bp_step_resume: | |
5582 | if (bs->stop) | |
628fe4e4 JK |
5583 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5584 | else | |
c906108c | 5585 | { |
628fe4e4 JK |
5586 | /* It is for the wrong frame. */ |
5587 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5588 | } |
c906108c | 5589 | break; |
2c03e5be PA |
5590 | case bp_hp_step_resume: |
5591 | if (bs->stop) | |
5592 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5593 | else | |
5594 | { | |
5595 | /* It is for the wrong frame. */ | |
5596 | this_action = BPSTAT_WHAT_SINGLE; | |
5597 | } | |
5598 | break; | |
c906108c | 5599 | case bp_watchpoint_scope: |
c4093a6a | 5600 | case bp_thread_event: |
1900040c | 5601 | case bp_overlay_event: |
0fd8e87f | 5602 | case bp_longjmp_master: |
aa7d318d | 5603 | case bp_std_terminate_master: |
186c406b | 5604 | case bp_exception_master: |
628fe4e4 | 5605 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5606 | break; |
ce78b96d | 5607 | case bp_catchpoint: |
c5aa993b JM |
5608 | if (bs->stop) |
5609 | { | |
5610 | if (bs->print) | |
628fe4e4 | 5611 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5612 | else |
628fe4e4 | 5613 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5614 | } |
5615 | else | |
628fe4e4 JK |
5616 | { |
5617 | /* There was a catchpoint, but we're not stopping. | |
5618 | This requires no further action. */ | |
5619 | } | |
5620 | break; | |
628fe4e4 JK |
5621 | case bp_jit_event: |
5622 | jit_event = 1; | |
5623 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5624 | break; |
c906108c | 5625 | case bp_call_dummy: |
53a5351d JM |
5626 | /* Make sure the action is stop (silent or noisy), |
5627 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5628 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5629 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5630 | break; |
5631 | case bp_std_terminate: | |
5632 | /* Make sure the action is stop (silent or noisy), | |
5633 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5634 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5635 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5636 | break; |
1042e4c0 | 5637 | case bp_tracepoint: |
7a697b8d | 5638 | case bp_fast_tracepoint: |
0fb4aa4b | 5639 | case bp_static_tracepoint: |
1042e4c0 SS |
5640 | /* Tracepoint hits should not be reported back to GDB, and |
5641 | if one got through somehow, it should have been filtered | |
5642 | out already. */ | |
5643 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5644 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5645 | break; |
5646 | case bp_gnu_ifunc_resolver: | |
5647 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5648 | this_action = BPSTAT_WHAT_SINGLE; | |
5649 | break; | |
5650 | case bp_gnu_ifunc_resolver_return: | |
5651 | /* The breakpoint will be removed, execution will restart from the | |
5652 | PC of the former breakpoint. */ | |
5653 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5654 | break; | |
e7e0cddf SS |
5655 | |
5656 | case bp_dprintf: | |
a11cfd87 HZ |
5657 | if (bs->stop) |
5658 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5659 | else | |
5660 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5661 | break; |
5662 | ||
628fe4e4 JK |
5663 | default: |
5664 | internal_error (__FILE__, __LINE__, | |
5665 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5666 | } |
628fe4e4 JK |
5667 | |
5668 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5669 | } |
628fe4e4 | 5670 | |
0e30163f JK |
5671 | /* These operations may affect the bs->breakpoint_at state so they are |
5672 | delayed after MAIN_ACTION is decided above. */ | |
5673 | ||
628fe4e4 JK |
5674 | if (jit_event) |
5675 | { | |
5676 | if (debug_infrun) | |
5677 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5678 | ||
5679 | handle_jit_event (); | |
5680 | } | |
5681 | ||
0e30163f JK |
5682 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5683 | { | |
5684 | struct breakpoint *b = bs->breakpoint_at; | |
5685 | ||
5686 | if (b == NULL) | |
5687 | continue; | |
5688 | switch (b->type) | |
5689 | { | |
5690 | case bp_gnu_ifunc_resolver: | |
5691 | gnu_ifunc_resolver_stop (b); | |
5692 | break; | |
5693 | case bp_gnu_ifunc_resolver_return: | |
5694 | gnu_ifunc_resolver_return_stop (b); | |
5695 | break; | |
5696 | } | |
5697 | } | |
5698 | ||
c906108c SS |
5699 | return retval; |
5700 | } | |
5701 | ||
5702 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5703 | without hardware support). This isn't related to a specific bpstat, | |
5704 | just to things like whether watchpoints are set. */ | |
5705 | ||
c5aa993b | 5706 | int |
fba45db2 | 5707 | bpstat_should_step (void) |
c906108c SS |
5708 | { |
5709 | struct breakpoint *b; | |
cc59ec59 | 5710 | |
c906108c | 5711 | ALL_BREAKPOINTS (b) |
717a8278 | 5712 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5713 | return 1; |
c906108c SS |
5714 | return 0; |
5715 | } | |
5716 | ||
67822962 PA |
5717 | int |
5718 | bpstat_causes_stop (bpstat bs) | |
5719 | { | |
5720 | for (; bs != NULL; bs = bs->next) | |
5721 | if (bs->stop) | |
5722 | return 1; | |
5723 | ||
5724 | return 0; | |
5725 | } | |
5726 | ||
c906108c | 5727 | \f |
c5aa993b | 5728 | |
170b53b2 UW |
5729 | /* Compute a string of spaces suitable to indent the next line |
5730 | so it starts at the position corresponding to the table column | |
5731 | named COL_NAME in the currently active table of UIOUT. */ | |
5732 | ||
5733 | static char * | |
5734 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5735 | { | |
5736 | static char wrap_indent[80]; | |
5737 | int i, total_width, width, align; | |
5738 | char *text; | |
5739 | ||
5740 | total_width = 0; | |
5741 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5742 | { | |
5743 | if (strcmp (text, col_name) == 0) | |
5744 | { | |
5745 | gdb_assert (total_width < sizeof wrap_indent); | |
5746 | memset (wrap_indent, ' ', total_width); | |
5747 | wrap_indent[total_width] = 0; | |
5748 | ||
5749 | return wrap_indent; | |
5750 | } | |
5751 | ||
5752 | total_width += width + 1; | |
5753 | } | |
5754 | ||
5755 | return NULL; | |
5756 | } | |
5757 | ||
b775012e LM |
5758 | /* Determine if the locations of this breakpoint will have their conditions |
5759 | evaluated by the target, host or a mix of both. Returns the following: | |
5760 | ||
5761 | "host": Host evals condition. | |
5762 | "host or target": Host or Target evals condition. | |
5763 | "target": Target evals condition. | |
5764 | */ | |
5765 | ||
5766 | static const char * | |
5767 | bp_condition_evaluator (struct breakpoint *b) | |
5768 | { | |
5769 | struct bp_location *bl; | |
5770 | char host_evals = 0; | |
5771 | char target_evals = 0; | |
5772 | ||
5773 | if (!b) | |
5774 | return NULL; | |
5775 | ||
5776 | if (!is_breakpoint (b)) | |
5777 | return NULL; | |
5778 | ||
5779 | if (gdb_evaluates_breakpoint_condition_p () | |
5780 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5781 | return condition_evaluation_host; | |
5782 | ||
5783 | for (bl = b->loc; bl; bl = bl->next) | |
5784 | { | |
5785 | if (bl->cond_bytecode) | |
5786 | target_evals++; | |
5787 | else | |
5788 | host_evals++; | |
5789 | } | |
5790 | ||
5791 | if (host_evals && target_evals) | |
5792 | return condition_evaluation_both; | |
5793 | else if (target_evals) | |
5794 | return condition_evaluation_target; | |
5795 | else | |
5796 | return condition_evaluation_host; | |
5797 | } | |
5798 | ||
5799 | /* Determine the breakpoint location's condition evaluator. This is | |
5800 | similar to bp_condition_evaluator, but for locations. */ | |
5801 | ||
5802 | static const char * | |
5803 | bp_location_condition_evaluator (struct bp_location *bl) | |
5804 | { | |
5805 | if (bl && !is_breakpoint (bl->owner)) | |
5806 | return NULL; | |
5807 | ||
5808 | if (gdb_evaluates_breakpoint_condition_p () | |
5809 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5810 | return condition_evaluation_host; | |
5811 | ||
5812 | if (bl && bl->cond_bytecode) | |
5813 | return condition_evaluation_target; | |
5814 | else | |
5815 | return condition_evaluation_host; | |
5816 | } | |
5817 | ||
859825b8 JK |
5818 | /* Print the LOC location out of the list of B->LOC locations. */ |
5819 | ||
170b53b2 UW |
5820 | static void |
5821 | print_breakpoint_location (struct breakpoint *b, | |
5822 | struct bp_location *loc) | |
0d381245 | 5823 | { |
79a45e25 | 5824 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5825 | struct cleanup *old_chain = save_current_program_space (); |
5826 | ||
859825b8 JK |
5827 | if (loc != NULL && loc->shlib_disabled) |
5828 | loc = NULL; | |
5829 | ||
6c95b8df PA |
5830 | if (loc != NULL) |
5831 | set_current_program_space (loc->pspace); | |
5832 | ||
56435ebe TT |
5833 | if (b->display_canonical) |
5834 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5835 | else if (loc && loc->symtab) |
0d381245 VP |
5836 | { |
5837 | struct symbol *sym | |
5838 | = find_pc_sect_function (loc->address, loc->section); | |
5839 | if (sym) | |
5840 | { | |
5841 | ui_out_text (uiout, "in "); | |
5842 | ui_out_field_string (uiout, "func", | |
5843 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5844 | ui_out_text (uiout, " "); |
5845 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5846 | ui_out_text (uiout, "at "); | |
0d381245 | 5847 | } |
05cba821 JK |
5848 | ui_out_field_string (uiout, "file", |
5849 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5850 | ui_out_text (uiout, ":"); |
05cba821 | 5851 | |
0d381245 | 5852 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5853 | ui_out_field_string (uiout, "fullname", |
5854 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5855 | |
f8eba3c6 | 5856 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5857 | } |
859825b8 | 5858 | else if (loc) |
0d381245 | 5859 | { |
f99d8bf4 PA |
5860 | struct ui_file *stb = mem_fileopen (); |
5861 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5862 | |
f99d8bf4 | 5863 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5864 | demangle, ""); |
0d381245 | 5865 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5866 | |
5867 | do_cleanups (stb_chain); | |
0d381245 | 5868 | } |
859825b8 JK |
5869 | else |
5870 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 5871 | |
b775012e LM |
5872 | if (loc && is_breakpoint (b) |
5873 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5874 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5875 | { | |
5876 | ui_out_text (uiout, " ("); | |
5877 | ui_out_field_string (uiout, "evaluated-by", | |
5878 | bp_location_condition_evaluator (loc)); | |
5879 | ui_out_text (uiout, ")"); | |
5880 | } | |
5881 | ||
6c95b8df | 5882 | do_cleanups (old_chain); |
0d381245 VP |
5883 | } |
5884 | ||
269b11a2 PA |
5885 | static const char * |
5886 | bptype_string (enum bptype type) | |
c906108c | 5887 | { |
c4093a6a JM |
5888 | struct ep_type_description |
5889 | { | |
5890 | enum bptype type; | |
5891 | char *description; | |
5892 | }; | |
5893 | static struct ep_type_description bptypes[] = | |
c906108c | 5894 | { |
c5aa993b JM |
5895 | {bp_none, "?deleted?"}, |
5896 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5897 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
5898 | {bp_until, "until"}, |
5899 | {bp_finish, "finish"}, | |
5900 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5901 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5902 | {bp_read_watchpoint, "read watchpoint"}, |
5903 | {bp_access_watchpoint, "acc watchpoint"}, | |
5904 | {bp_longjmp, "longjmp"}, | |
5905 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5906 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5907 | {bp_exception, "exception"}, |
5908 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5909 | {bp_step_resume, "step resume"}, |
2c03e5be | 5910 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5911 | {bp_watchpoint_scope, "watchpoint scope"}, |
5912 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5913 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5914 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5915 | {bp_thread_event, "thread events"}, |
1900040c | 5916 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5917 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5918 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5919 | {bp_exception_master, "exception master"}, |
ce78b96d | 5920 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5921 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5922 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5923 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5924 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5925 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5926 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5927 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5928 | }; |
269b11a2 PA |
5929 | |
5930 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5931 | || ((int) type != bptypes[(int) type].type)) | |
5932 | internal_error (__FILE__, __LINE__, | |
5933 | _("bptypes table does not describe type #%d."), | |
5934 | (int) type); | |
5935 | ||
5936 | return bptypes[(int) type].description; | |
5937 | } | |
5938 | ||
998580f1 MK |
5939 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5940 | For CLI, prefix the list with the string 'inf'. */ | |
5941 | ||
5942 | static void | |
5943 | output_thread_groups (struct ui_out *uiout, | |
5944 | const char *field_name, | |
5945 | VEC(int) *inf_num, | |
5946 | int mi_only) | |
5947 | { | |
752eb8b4 | 5948 | struct cleanup *back_to; |
998580f1 MK |
5949 | int is_mi = ui_out_is_mi_like_p (uiout); |
5950 | int inf; | |
5951 | int i; | |
5952 | ||
5953 | /* For backward compatibility, don't display inferiors in CLI unless | |
5954 | there are several. Always display them for MI. */ | |
5955 | if (!is_mi && mi_only) | |
5956 | return; | |
5957 | ||
752eb8b4 TT |
5958 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
5959 | ||
998580f1 MK |
5960 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
5961 | { | |
5962 | if (is_mi) | |
5963 | { | |
5964 | char mi_group[10]; | |
5965 | ||
5966 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
5967 | ui_out_field_string (uiout, NULL, mi_group); | |
5968 | } | |
5969 | else | |
5970 | { | |
5971 | if (i == 0) | |
5972 | ui_out_text (uiout, " inf "); | |
5973 | else | |
5974 | ui_out_text (uiout, ", "); | |
5975 | ||
5976 | ui_out_text (uiout, plongest (inf)); | |
5977 | } | |
5978 | } | |
5979 | ||
5980 | do_cleanups (back_to); | |
5981 | } | |
5982 | ||
269b11a2 PA |
5983 | /* Print B to gdb_stdout. */ |
5984 | ||
5985 | static void | |
5986 | print_one_breakpoint_location (struct breakpoint *b, | |
5987 | struct bp_location *loc, | |
5988 | int loc_number, | |
5989 | struct bp_location **last_loc, | |
269b11a2 PA |
5990 | int allflag) |
5991 | { | |
5992 | struct command_line *l; | |
c2c6d25f | 5993 | static char bpenables[] = "nynny"; |
c906108c | 5994 | |
79a45e25 | 5995 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5996 | int header_of_multiple = 0; |
5997 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5998 | struct value_print_options opts; |
5999 | ||
6000 | get_user_print_options (&opts); | |
0d381245 VP |
6001 | |
6002 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6003 | /* See comment in print_one_breakpoint concerning treatment of |
6004 | breakpoints with single disabled location. */ | |
0d381245 VP |
6005 | if (loc == NULL |
6006 | && (b->loc != NULL | |
6007 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6008 | header_of_multiple = 1; | |
6009 | if (loc == NULL) | |
6010 | loc = b->loc; | |
6011 | ||
c4093a6a JM |
6012 | annotate_record (); |
6013 | ||
6014 | /* 1 */ | |
6015 | annotate_field (0); | |
0d381245 VP |
6016 | if (part_of_multiple) |
6017 | { | |
6018 | char *formatted; | |
0c6773c1 | 6019 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6020 | ui_out_field_string (uiout, "number", formatted); |
6021 | xfree (formatted); | |
6022 | } | |
6023 | else | |
6024 | { | |
6025 | ui_out_field_int (uiout, "number", b->number); | |
6026 | } | |
c4093a6a JM |
6027 | |
6028 | /* 2 */ | |
6029 | annotate_field (1); | |
0d381245 VP |
6030 | if (part_of_multiple) |
6031 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6032 | else |
6033 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6034 | |
6035 | /* 3 */ | |
6036 | annotate_field (2); | |
0d381245 VP |
6037 | if (part_of_multiple) |
6038 | ui_out_field_skip (uiout, "disp"); | |
6039 | else | |
2cec12e5 | 6040 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6041 | |
c4093a6a JM |
6042 | |
6043 | /* 4 */ | |
6044 | annotate_field (3); | |
0d381245 | 6045 | if (part_of_multiple) |
54e52265 | 6046 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6047 | else |
4a64f543 MS |
6048 | ui_out_field_fmt (uiout, "enabled", "%c", |
6049 | bpenables[(int) b->enable_state]); | |
54e52265 | 6050 | ui_out_spaces (uiout, 2); |
0d381245 | 6051 | |
c4093a6a JM |
6052 | |
6053 | /* 5 and 6 */ | |
3086aeae | 6054 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6055 | { |
4a64f543 MS |
6056 | /* Although the print_one can possibly print all locations, |
6057 | calling it here is not likely to get any nice result. So, | |
6058 | make sure there's just one location. */ | |
0d381245 | 6059 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6060 | b->ops->print_one (b, last_loc); |
0d381245 | 6061 | } |
3086aeae DJ |
6062 | else |
6063 | switch (b->type) | |
6064 | { | |
6065 | case bp_none: | |
6066 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6067 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6068 | break; |
c906108c | 6069 | |
3086aeae DJ |
6070 | case bp_watchpoint: |
6071 | case bp_hardware_watchpoint: | |
6072 | case bp_read_watchpoint: | |
6073 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6074 | { |
6075 | struct watchpoint *w = (struct watchpoint *) b; | |
6076 | ||
6077 | /* Field 4, the address, is omitted (which makes the columns | |
6078 | not line up too nicely with the headers, but the effect | |
6079 | is relatively readable). */ | |
6080 | if (opts.addressprint) | |
6081 | ui_out_field_skip (uiout, "addr"); | |
6082 | annotate_field (5); | |
6083 | ui_out_field_string (uiout, "what", w->exp_string); | |
6084 | } | |
3086aeae DJ |
6085 | break; |
6086 | ||
3086aeae DJ |
6087 | case bp_breakpoint: |
6088 | case bp_hardware_breakpoint: | |
6089 | case bp_until: | |
6090 | case bp_finish: | |
6091 | case bp_longjmp: | |
6092 | case bp_longjmp_resume: | |
e2e4d78b | 6093 | case bp_longjmp_call_dummy: |
186c406b TT |
6094 | case bp_exception: |
6095 | case bp_exception_resume: | |
3086aeae | 6096 | case bp_step_resume: |
2c03e5be | 6097 | case bp_hp_step_resume: |
3086aeae DJ |
6098 | case bp_watchpoint_scope: |
6099 | case bp_call_dummy: | |
aa7d318d | 6100 | case bp_std_terminate: |
3086aeae DJ |
6101 | case bp_shlib_event: |
6102 | case bp_thread_event: | |
6103 | case bp_overlay_event: | |
0fd8e87f | 6104 | case bp_longjmp_master: |
aa7d318d | 6105 | case bp_std_terminate_master: |
186c406b | 6106 | case bp_exception_master: |
1042e4c0 | 6107 | case bp_tracepoint: |
7a697b8d | 6108 | case bp_fast_tracepoint: |
0fb4aa4b | 6109 | case bp_static_tracepoint: |
e7e0cddf | 6110 | case bp_dprintf: |
4efc6507 | 6111 | case bp_jit_event: |
0e30163f JK |
6112 | case bp_gnu_ifunc_resolver: |
6113 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6114 | if (opts.addressprint) |
3086aeae DJ |
6115 | { |
6116 | annotate_field (4); | |
54e52265 | 6117 | if (header_of_multiple) |
0d381245 | 6118 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6119 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6120 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6121 | else |
5af949e3 UW |
6122 | ui_out_field_core_addr (uiout, "addr", |
6123 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6124 | } |
6125 | annotate_field (5); | |
0d381245 | 6126 | if (!header_of_multiple) |
170b53b2 | 6127 | print_breakpoint_location (b, loc); |
0d381245 | 6128 | if (b->loc) |
a6d9a66e | 6129 | *last_loc = b->loc; |
3086aeae DJ |
6130 | break; |
6131 | } | |
c906108c | 6132 | |
6c95b8df | 6133 | |
998580f1 | 6134 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6135 | { |
6136 | struct inferior *inf; | |
998580f1 MK |
6137 | VEC(int) *inf_num = NULL; |
6138 | int mi_only = 1; | |
6c95b8df | 6139 | |
998580f1 | 6140 | ALL_INFERIORS (inf) |
6c95b8df PA |
6141 | { |
6142 | if (inf->pspace == loc->pspace) | |
998580f1 | 6143 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6144 | } |
998580f1 MK |
6145 | |
6146 | /* For backward compatibility, don't display inferiors in CLI unless | |
6147 | there are several. Always display for MI. */ | |
6148 | if (allflag | |
6149 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6150 | && (number_of_program_spaces () > 1 | |
6151 | || number_of_inferiors () > 1) | |
6152 | /* LOC is for existing B, it cannot be in | |
6153 | moribund_locations and thus having NULL OWNER. */ | |
6154 | && loc->owner->type != bp_catchpoint)) | |
6155 | mi_only = 0; | |
6156 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6157 | VEC_free (int, inf_num); | |
6c95b8df PA |
6158 | } |
6159 | ||
4a306c9a | 6160 | if (!part_of_multiple) |
c4093a6a | 6161 | { |
4a306c9a JB |
6162 | if (b->thread != -1) |
6163 | { | |
6164 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6165 | "stop only in" line a little further down. */ |
4a306c9a JB |
6166 | ui_out_text (uiout, " thread "); |
6167 | ui_out_field_int (uiout, "thread", b->thread); | |
6168 | } | |
6169 | else if (b->task != 0) | |
6170 | { | |
6171 | ui_out_text (uiout, " task "); | |
6172 | ui_out_field_int (uiout, "task", b->task); | |
6173 | } | |
c4093a6a | 6174 | } |
f1310107 | 6175 | |
8b93c638 | 6176 | ui_out_text (uiout, "\n"); |
f1310107 | 6177 | |
348d480f | 6178 | if (!part_of_multiple) |
f1310107 TJB |
6179 | b->ops->print_one_detail (b, uiout); |
6180 | ||
0d381245 | 6181 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6182 | { |
6183 | annotate_field (6); | |
8b93c638 | 6184 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6185 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6186 | the frame ID. */ |
5af949e3 UW |
6187 | ui_out_field_core_addr (uiout, "frame", |
6188 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6189 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6190 | } |
6191 | ||
28010a5d | 6192 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6193 | { |
6194 | annotate_field (7); | |
d77f58be | 6195 | if (is_tracepoint (b)) |
1042e4c0 SS |
6196 | ui_out_text (uiout, "\ttrace only if "); |
6197 | else | |
6198 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6199 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6200 | |
6201 | /* Print whether the target is doing the breakpoint's condition | |
6202 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6203 | if (is_breakpoint (b) | |
6204 | && breakpoint_condition_evaluation_mode () | |
6205 | == condition_evaluation_target) | |
6206 | { | |
6207 | ui_out_text (uiout, " ("); | |
6208 | ui_out_field_string (uiout, "evaluated-by", | |
6209 | bp_condition_evaluator (b)); | |
6210 | ui_out_text (uiout, " evals)"); | |
6211 | } | |
0101ce28 JJ |
6212 | ui_out_text (uiout, "\n"); |
6213 | } | |
6214 | ||
0d381245 | 6215 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6216 | { |
4a64f543 | 6217 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6218 | ui_out_text (uiout, "\tstop only in thread "); |
6219 | ui_out_field_int (uiout, "thread", b->thread); | |
6220 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6221 | } |
6222 | ||
556ec64d YQ |
6223 | if (!part_of_multiple) |
6224 | { | |
6225 | if (b->hit_count) | |
31f56a27 YQ |
6226 | { |
6227 | /* FIXME should make an annotation for this. */ | |
6228 | if (is_catchpoint (b)) | |
6229 | ui_out_text (uiout, "\tcatchpoint"); | |
6230 | else if (is_tracepoint (b)) | |
6231 | ui_out_text (uiout, "\ttracepoint"); | |
6232 | else | |
6233 | ui_out_text (uiout, "\tbreakpoint"); | |
6234 | ui_out_text (uiout, " already hit "); | |
6235 | ui_out_field_int (uiout, "times", b->hit_count); | |
6236 | if (b->hit_count == 1) | |
6237 | ui_out_text (uiout, " time\n"); | |
6238 | else | |
6239 | ui_out_text (uiout, " times\n"); | |
6240 | } | |
556ec64d YQ |
6241 | else |
6242 | { | |
31f56a27 YQ |
6243 | /* Output the count also if it is zero, but only if this is mi. */ |
6244 | if (ui_out_is_mi_like_p (uiout)) | |
6245 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6246 | } |
6247 | } | |
8b93c638 | 6248 | |
0d381245 | 6249 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6250 | { |
6251 | annotate_field (8); | |
8b93c638 JM |
6252 | ui_out_text (uiout, "\tignore next "); |
6253 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6254 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6255 | } |
059fb39f | 6256 | |
816338b5 SS |
6257 | /* Note that an enable count of 1 corresponds to "enable once" |
6258 | behavior, which is reported by the combination of enablement and | |
6259 | disposition, so we don't need to mention it here. */ | |
6260 | if (!part_of_multiple && b->enable_count > 1) | |
6261 | { | |
6262 | annotate_field (8); | |
6263 | ui_out_text (uiout, "\tdisable after "); | |
6264 | /* Tweak the wording to clarify that ignore and enable counts | |
6265 | are distinct, and have additive effect. */ | |
6266 | if (b->ignore_count) | |
6267 | ui_out_text (uiout, "additional "); | |
6268 | else | |
6269 | ui_out_text (uiout, "next "); | |
6270 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6271 | ui_out_text (uiout, " hits\n"); | |
6272 | } | |
6273 | ||
f196051f SS |
6274 | if (!part_of_multiple && is_tracepoint (b)) |
6275 | { | |
6276 | struct tracepoint *tp = (struct tracepoint *) b; | |
6277 | ||
6278 | if (tp->traceframe_usage) | |
6279 | { | |
6280 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6281 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6282 | ui_out_text (uiout, " bytes\n"); | |
6283 | } | |
6284 | } | |
d3ce09f5 | 6285 | |
9add0f1b | 6286 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6287 | if (!part_of_multiple && l) |
c4093a6a | 6288 | { |
3b31d625 EZ |
6289 | struct cleanup *script_chain; |
6290 | ||
c4093a6a | 6291 | annotate_field (9); |
3b31d625 | 6292 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6293 | print_command_lines (uiout, l, 4); |
3b31d625 | 6294 | do_cleanups (script_chain); |
c4093a6a | 6295 | } |
d24317b4 | 6296 | |
d9b3f62e | 6297 | if (is_tracepoint (b)) |
1042e4c0 | 6298 | { |
d9b3f62e PA |
6299 | struct tracepoint *t = (struct tracepoint *) b; |
6300 | ||
6301 | if (!part_of_multiple && t->pass_count) | |
6302 | { | |
6303 | annotate_field (10); | |
6304 | ui_out_text (uiout, "\tpass count "); | |
6305 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6306 | ui_out_text (uiout, " \n"); | |
6307 | } | |
f2a8bc8a YQ |
6308 | |
6309 | /* Don't display it when tracepoint or tracepoint location is | |
6310 | pending. */ | |
6311 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6312 | { | |
6313 | annotate_field (11); | |
6314 | ||
6315 | if (ui_out_is_mi_like_p (uiout)) | |
6316 | ui_out_field_string (uiout, "installed", | |
6317 | loc->inserted ? "y" : "n"); | |
6318 | else | |
6319 | { | |
6320 | if (loc->inserted) | |
6321 | ui_out_text (uiout, "\t"); | |
6322 | else | |
6323 | ui_out_text (uiout, "\tnot "); | |
6324 | ui_out_text (uiout, "installed on target\n"); | |
6325 | } | |
6326 | } | |
1042e4c0 SS |
6327 | } |
6328 | ||
d24317b4 VP |
6329 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6330 | { | |
3a5c3e22 PA |
6331 | if (is_watchpoint (b)) |
6332 | { | |
6333 | struct watchpoint *w = (struct watchpoint *) b; | |
6334 | ||
6335 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6336 | } | |
6337 | else if (b->addr_string) | |
d24317b4 | 6338 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6339 | } |
c4093a6a | 6340 | } |
c5aa993b | 6341 | |
0d381245 VP |
6342 | static void |
6343 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6344 | struct bp_location **last_loc, |
6c95b8df | 6345 | int allflag) |
0d381245 | 6346 | { |
8d3788bd | 6347 | struct cleanup *bkpt_chain; |
79a45e25 | 6348 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6349 | |
6350 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6351 | ||
12c5a436 | 6352 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6353 | do_cleanups (bkpt_chain); |
0d381245 VP |
6354 | |
6355 | /* If this breakpoint has custom print function, | |
6356 | it's already printed. Otherwise, print individual | |
6357 | locations, if any. */ | |
6358 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6359 | { | |
4a64f543 MS |
6360 | /* If breakpoint has a single location that is disabled, we |
6361 | print it as if it had several locations, since otherwise it's | |
6362 | hard to represent "breakpoint enabled, location disabled" | |
6363 | situation. | |
6364 | ||
6365 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6366 | internally, that's not a property exposed to user. */ |
0d381245 | 6367 | if (b->loc |
a5606eee | 6368 | && !is_hardware_watchpoint (b) |
8d3788bd | 6369 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6370 | { |
6371 | struct bp_location *loc; | |
6372 | int n = 1; | |
8d3788bd | 6373 | |
0d381245 | 6374 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6375 | { |
6376 | struct cleanup *inner2 = | |
6377 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6378 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6379 | do_cleanups (inner2); | |
6380 | } | |
0d381245 VP |
6381 | } |
6382 | } | |
6383 | } | |
6384 | ||
a6d9a66e UW |
6385 | static int |
6386 | breakpoint_address_bits (struct breakpoint *b) | |
6387 | { | |
6388 | int print_address_bits = 0; | |
6389 | struct bp_location *loc; | |
6390 | ||
6391 | for (loc = b->loc; loc; loc = loc->next) | |
6392 | { | |
c7437ca6 PA |
6393 | int addr_bit; |
6394 | ||
6395 | /* Software watchpoints that aren't watching memory don't have | |
6396 | an address to print. */ | |
6397 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6398 | continue; | |
6399 | ||
6400 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6401 | if (addr_bit > print_address_bits) |
6402 | print_address_bits = addr_bit; | |
6403 | } | |
6404 | ||
6405 | return print_address_bits; | |
6406 | } | |
0d381245 | 6407 | |
c4093a6a JM |
6408 | struct captured_breakpoint_query_args |
6409 | { | |
6410 | int bnum; | |
6411 | }; | |
c5aa993b | 6412 | |
c4093a6a | 6413 | static int |
2b65245e | 6414 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6415 | { |
6416 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6417 | struct breakpoint *b; |
a6d9a66e | 6418 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6419 | |
c4093a6a JM |
6420 | ALL_BREAKPOINTS (b) |
6421 | { | |
6422 | if (args->bnum == b->number) | |
c5aa993b | 6423 | { |
12c5a436 | 6424 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6425 | return GDB_RC_OK; |
c5aa993b | 6426 | } |
c4093a6a JM |
6427 | } |
6428 | return GDB_RC_NONE; | |
6429 | } | |
c5aa993b | 6430 | |
c4093a6a | 6431 | enum gdb_rc |
4a64f543 MS |
6432 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6433 | char **error_message) | |
c4093a6a JM |
6434 | { |
6435 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6436 | |
c4093a6a JM |
6437 | args.bnum = bnum; |
6438 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6439 | an error. */ |
b0b13bb4 DJ |
6440 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6441 | error_message, RETURN_MASK_ALL) < 0) | |
6442 | return GDB_RC_FAIL; | |
6443 | else | |
6444 | return GDB_RC_OK; | |
c4093a6a | 6445 | } |
c5aa993b | 6446 | |
09d682a4 TT |
6447 | /* Return true if this breakpoint was set by the user, false if it is |
6448 | internal or momentary. */ | |
6449 | ||
6450 | int | |
6451 | user_breakpoint_p (struct breakpoint *b) | |
6452 | { | |
46c6471b | 6453 | return b->number > 0; |
09d682a4 TT |
6454 | } |
6455 | ||
7f3b0473 | 6456 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6457 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6458 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6459 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6460 | ones for which it returns non-zero. Return the total number of | |
6461 | breakpoints listed. */ | |
c906108c | 6462 | |
d77f58be | 6463 | static int |
e5a67952 | 6464 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6465 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6466 | { |
52f0bd74 | 6467 | struct breakpoint *b; |
a6d9a66e | 6468 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6469 | int nr_printable_breakpoints; |
3b31d625 | 6470 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6471 | struct value_print_options opts; |
a6d9a66e | 6472 | int print_address_bits = 0; |
269b11a2 | 6473 | int print_type_col_width = 14; |
79a45e25 | 6474 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6475 | |
79a45b7d TT |
6476 | get_user_print_options (&opts); |
6477 | ||
4a64f543 MS |
6478 | /* Compute the number of rows in the table, as well as the size |
6479 | required for address fields. */ | |
7f3b0473 AC |
6480 | nr_printable_breakpoints = 0; |
6481 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6482 | { |
6483 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6484 | if (filter && !filter (b)) | |
6485 | continue; | |
6486 | ||
6487 | /* If we have an "args" string, it is a list of breakpoints to | |
6488 | accept. Skip the others. */ | |
6489 | if (args != NULL && *args != '\0') | |
6490 | { | |
6491 | if (allflag && parse_and_eval_long (args) != b->number) | |
6492 | continue; | |
6493 | if (!allflag && !number_is_in_list (args, b->number)) | |
6494 | continue; | |
6495 | } | |
269b11a2 | 6496 | |
e5a67952 MS |
6497 | if (allflag || user_breakpoint_p (b)) |
6498 | { | |
6499 | int addr_bit, type_len; | |
a6d9a66e | 6500 | |
e5a67952 MS |
6501 | addr_bit = breakpoint_address_bits (b); |
6502 | if (addr_bit > print_address_bits) | |
6503 | print_address_bits = addr_bit; | |
269b11a2 | 6504 | |
e5a67952 MS |
6505 | type_len = strlen (bptype_string (b->type)); |
6506 | if (type_len > print_type_col_width) | |
6507 | print_type_col_width = type_len; | |
6508 | ||
6509 | nr_printable_breakpoints++; | |
6510 | } | |
6511 | } | |
7f3b0473 | 6512 | |
79a45b7d | 6513 | if (opts.addressprint) |
3b31d625 | 6514 | bkpttbl_chain |
3e43a32a MS |
6515 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6516 | nr_printable_breakpoints, | |
3b31d625 | 6517 | "BreakpointTable"); |
8b93c638 | 6518 | else |
3b31d625 | 6519 | bkpttbl_chain |
3e43a32a MS |
6520 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6521 | nr_printable_breakpoints, | |
3b31d625 | 6522 | "BreakpointTable"); |
8b93c638 | 6523 | |
7f3b0473 | 6524 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6525 | annotate_breakpoints_headers (); |
6526 | if (nr_printable_breakpoints > 0) | |
6527 | annotate_field (0); | |
4a64f543 | 6528 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6529 | if (nr_printable_breakpoints > 0) |
6530 | annotate_field (1); | |
269b11a2 | 6531 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6532 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6533 | if (nr_printable_breakpoints > 0) |
6534 | annotate_field (2); | |
4a64f543 | 6535 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6536 | if (nr_printable_breakpoints > 0) |
6537 | annotate_field (3); | |
54e52265 | 6538 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6539 | if (opts.addressprint) |
e5a67952 MS |
6540 | { |
6541 | if (nr_printable_breakpoints > 0) | |
6542 | annotate_field (4); | |
6543 | if (print_address_bits <= 32) | |
6544 | ui_out_table_header (uiout, 10, ui_left, | |
6545 | "addr", "Address"); /* 5 */ | |
6546 | else | |
6547 | ui_out_table_header (uiout, 18, ui_left, | |
6548 | "addr", "Address"); /* 5 */ | |
6549 | } | |
d7faa9e7 AC |
6550 | if (nr_printable_breakpoints > 0) |
6551 | annotate_field (5); | |
6552 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6553 | ui_out_table_body (uiout); | |
6554 | if (nr_printable_breakpoints > 0) | |
6555 | annotate_breakpoints_table (); | |
7f3b0473 | 6556 | |
c4093a6a | 6557 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6558 | { |
6559 | QUIT; | |
6560 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6561 | if (filter && !filter (b)) | |
6562 | continue; | |
6563 | ||
6564 | /* If we have an "args" string, it is a list of breakpoints to | |
6565 | accept. Skip the others. */ | |
6566 | ||
6567 | if (args != NULL && *args != '\0') | |
6568 | { | |
6569 | if (allflag) /* maintenance info breakpoint */ | |
6570 | { | |
6571 | if (parse_and_eval_long (args) != b->number) | |
6572 | continue; | |
6573 | } | |
6574 | else /* all others */ | |
6575 | { | |
6576 | if (!number_is_in_list (args, b->number)) | |
6577 | continue; | |
6578 | } | |
6579 | } | |
6580 | /* We only print out user settable breakpoints unless the | |
6581 | allflag is set. */ | |
6582 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6583 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6584 | } |
6585 | ||
3b31d625 | 6586 | do_cleanups (bkpttbl_chain); |
698384cd | 6587 | |
7f3b0473 | 6588 | if (nr_printable_breakpoints == 0) |
c906108c | 6589 | { |
4a64f543 MS |
6590 | /* If there's a filter, let the caller decide how to report |
6591 | empty list. */ | |
d77f58be SS |
6592 | if (!filter) |
6593 | { | |
e5a67952 | 6594 | if (args == NULL || *args == '\0') |
d77f58be SS |
6595 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6596 | else | |
4a64f543 | 6597 | ui_out_message (uiout, 0, |
e5a67952 MS |
6598 | "No breakpoint or watchpoint matching '%s'.\n", |
6599 | args); | |
d77f58be | 6600 | } |
c906108c SS |
6601 | } |
6602 | else | |
c4093a6a | 6603 | { |
a6d9a66e UW |
6604 | if (last_loc && !server_command) |
6605 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6606 | } |
c906108c | 6607 | |
4a64f543 | 6608 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6609 | there have been breakpoints? */ |
c906108c | 6610 | annotate_breakpoints_table_end (); |
d77f58be SS |
6611 | |
6612 | return nr_printable_breakpoints; | |
c906108c SS |
6613 | } |
6614 | ||
ad443146 SS |
6615 | /* Display the value of default-collect in a way that is generally |
6616 | compatible with the breakpoint list. */ | |
6617 | ||
6618 | static void | |
6619 | default_collect_info (void) | |
6620 | { | |
79a45e25 PA |
6621 | struct ui_out *uiout = current_uiout; |
6622 | ||
ad443146 SS |
6623 | /* If it has no value (which is frequently the case), say nothing; a |
6624 | message like "No default-collect." gets in user's face when it's | |
6625 | not wanted. */ | |
6626 | if (!*default_collect) | |
6627 | return; | |
6628 | ||
6629 | /* The following phrase lines up nicely with per-tracepoint collect | |
6630 | actions. */ | |
6631 | ui_out_text (uiout, "default collect "); | |
6632 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6633 | ui_out_text (uiout, " \n"); | |
6634 | } | |
6635 | ||
c906108c | 6636 | static void |
e5a67952 | 6637 | breakpoints_info (char *args, int from_tty) |
c906108c | 6638 | { |
e5a67952 | 6639 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6640 | |
6641 | default_collect_info (); | |
d77f58be SS |
6642 | } |
6643 | ||
6644 | static void | |
e5a67952 | 6645 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6646 | { |
e5a67952 | 6647 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6648 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6649 | |
6650 | if (num_printed == 0) | |
6651 | { | |
e5a67952 | 6652 | if (args == NULL || *args == '\0') |
d77f58be SS |
6653 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6654 | else | |
e5a67952 | 6655 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6656 | } |
c906108c SS |
6657 | } |
6658 | ||
7a292a7a | 6659 | static void |
e5a67952 | 6660 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6661 | { |
e5a67952 | 6662 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6663 | |
6664 | default_collect_info (); | |
c906108c SS |
6665 | } |
6666 | ||
0d381245 | 6667 | static int |
714835d5 | 6668 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6669 | struct program_space *pspace, |
714835d5 | 6670 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6671 | { |
6672 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6673 | |
0d381245 VP |
6674 | for (; bl; bl = bl->next) |
6675 | { | |
6c95b8df PA |
6676 | if (bl->pspace == pspace |
6677 | && bl->address == pc | |
0d381245 VP |
6678 | && (!overlay_debugging || bl->section == section)) |
6679 | return 1; | |
6680 | } | |
6681 | return 0; | |
6682 | } | |
6683 | ||
672f9b60 | 6684 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6685 | concerns with logical breakpoints, so we match program spaces, not |
6686 | address spaces. */ | |
c906108c SS |
6687 | |
6688 | static void | |
6c95b8df PA |
6689 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6690 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6691 | struct obj_section *section, int thread) |
c906108c | 6692 | { |
52f0bd74 AC |
6693 | int others = 0; |
6694 | struct breakpoint *b; | |
c906108c SS |
6695 | |
6696 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6697 | others += (user_breakpoint_p (b) |
6698 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6699 | if (others > 0) |
6700 | { | |
a3f17187 AC |
6701 | if (others == 1) |
6702 | printf_filtered (_("Note: breakpoint ")); | |
6703 | else /* if (others == ???) */ | |
6704 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6705 | ALL_BREAKPOINTS (b) |
672f9b60 | 6706 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6707 | { |
6708 | others--; | |
6709 | printf_filtered ("%d", b->number); | |
6710 | if (b->thread == -1 && thread != -1) | |
6711 | printf_filtered (" (all threads)"); | |
6712 | else if (b->thread != -1) | |
6713 | printf_filtered (" (thread %d)", b->thread); | |
6714 | printf_filtered ("%s%s ", | |
059fb39f | 6715 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6716 | || b->enable_state == bp_call_disabled) |
0d381245 VP |
6717 | ? " (disabled)" |
6718 | : b->enable_state == bp_permanent | |
6719 | ? " (permanent)" | |
6720 | : ""), | |
6721 | (others > 1) ? "," | |
6722 | : ((others == 1) ? " and" : "")); | |
6723 | } | |
a3f17187 | 6724 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6725 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6726 | printf_filtered (".\n"); |
6727 | } | |
6728 | } | |
6729 | \f | |
c906108c | 6730 | |
e4f237da KB |
6731 | /* Return true iff it is meaningful to use the address member of |
6732 | BPT. For some breakpoint types, the address member is irrelevant | |
6733 | and it makes no sense to attempt to compare it to other addresses | |
6734 | (or use it for any other purpose either). | |
6735 | ||
4a64f543 MS |
6736 | More specifically, each of the following breakpoint types will |
6737 | always have a zero valued address and we don't want to mark | |
6738 | breakpoints of any of these types to be a duplicate of an actual | |
6739 | breakpoint at address zero: | |
e4f237da KB |
6740 | |
6741 | bp_watchpoint | |
2d134ed3 PA |
6742 | bp_catchpoint |
6743 | ||
6744 | */ | |
e4f237da KB |
6745 | |
6746 | static int | |
6747 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6748 | { | |
6749 | enum bptype type = bpt->type; | |
6750 | ||
2d134ed3 PA |
6751 | return (type != bp_watchpoint && type != bp_catchpoint); |
6752 | } | |
6753 | ||
6754 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6755 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6756 | ||
6757 | static int | |
4a64f543 MS |
6758 | watchpoint_locations_match (struct bp_location *loc1, |
6759 | struct bp_location *loc2) | |
2d134ed3 | 6760 | { |
3a5c3e22 PA |
6761 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6762 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6763 | ||
6764 | /* Both of them must exist. */ | |
6765 | gdb_assert (w1 != NULL); | |
6766 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6767 | |
4a64f543 MS |
6768 | /* If the target can evaluate the condition expression in hardware, |
6769 | then we we need to insert both watchpoints even if they are at | |
6770 | the same place. Otherwise the watchpoint will only trigger when | |
6771 | the condition of whichever watchpoint was inserted evaluates to | |
6772 | true, not giving a chance for GDB to check the condition of the | |
6773 | other watchpoint. */ | |
3a5c3e22 | 6774 | if ((w1->cond_exp |
4a64f543 MS |
6775 | && target_can_accel_watchpoint_condition (loc1->address, |
6776 | loc1->length, | |
0cf6dd15 | 6777 | loc1->watchpoint_type, |
3a5c3e22 PA |
6778 | w1->cond_exp)) |
6779 | || (w2->cond_exp | |
4a64f543 MS |
6780 | && target_can_accel_watchpoint_condition (loc2->address, |
6781 | loc2->length, | |
0cf6dd15 | 6782 | loc2->watchpoint_type, |
3a5c3e22 | 6783 | w2->cond_exp))) |
0cf6dd15 TJB |
6784 | return 0; |
6785 | ||
85d721b8 PA |
6786 | /* Note that this checks the owner's type, not the location's. In |
6787 | case the target does not support read watchpoints, but does | |
6788 | support access watchpoints, we'll have bp_read_watchpoint | |
6789 | watchpoints with hw_access locations. Those should be considered | |
6790 | duplicates of hw_read locations. The hw_read locations will | |
6791 | become hw_access locations later. */ | |
2d134ed3 PA |
6792 | return (loc1->owner->type == loc2->owner->type |
6793 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6794 | && loc1->address == loc2->address | |
6795 | && loc1->length == loc2->length); | |
e4f237da KB |
6796 | } |
6797 | ||
31e77af2 | 6798 | /* See breakpoint.h. */ |
6c95b8df | 6799 | |
31e77af2 | 6800 | int |
6c95b8df PA |
6801 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6802 | struct address_space *aspace2, CORE_ADDR addr2) | |
6803 | { | |
f5656ead | 6804 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6805 | || aspace1 == aspace2) |
6806 | && addr1 == addr2); | |
6807 | } | |
6808 | ||
f1310107 TJB |
6809 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6810 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6811 | matches ASPACE2. On targets that have global breakpoints, the address | |
6812 | space doesn't really matter. */ | |
6813 | ||
6814 | static int | |
6815 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6816 | int len1, struct address_space *aspace2, | |
6817 | CORE_ADDR addr2) | |
6818 | { | |
f5656ead | 6819 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6820 | || aspace1 == aspace2) |
6821 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6822 | } | |
6823 | ||
6824 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6825 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6826 | matches the breakpoint's address space. On targets that have global | |
6827 | breakpoints, the address space doesn't really matter. */ | |
6828 | ||
6829 | static int | |
6830 | breakpoint_location_address_match (struct bp_location *bl, | |
6831 | struct address_space *aspace, | |
6832 | CORE_ADDR addr) | |
6833 | { | |
6834 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6835 | aspace, addr) | |
6836 | || (bl->length | |
6837 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6838 | bl->address, bl->length, | |
6839 | aspace, addr))); | |
6840 | } | |
6841 | ||
1e4d1764 YQ |
6842 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6843 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6844 | true, otherwise returns false. */ | |
6845 | ||
6846 | static int | |
6847 | tracepoint_locations_match (struct bp_location *loc1, | |
6848 | struct bp_location *loc2) | |
6849 | { | |
6850 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6851 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6852 | locations at the same address of different tracepoints are regarded as | |
6853 | different locations. */ | |
6854 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6855 | else | |
6856 | return 0; | |
6857 | } | |
6858 | ||
2d134ed3 PA |
6859 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6860 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6861 | represent the same location. */ | |
6862 | ||
6863 | static int | |
4a64f543 MS |
6864 | breakpoint_locations_match (struct bp_location *loc1, |
6865 | struct bp_location *loc2) | |
2d134ed3 | 6866 | { |
2bdf28a0 JK |
6867 | int hw_point1, hw_point2; |
6868 | ||
6869 | /* Both of them must not be in moribund_locations. */ | |
6870 | gdb_assert (loc1->owner != NULL); | |
6871 | gdb_assert (loc2->owner != NULL); | |
6872 | ||
6873 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6874 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6875 | |
6876 | if (hw_point1 != hw_point2) | |
6877 | return 0; | |
6878 | else if (hw_point1) | |
6879 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6880 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6881 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6882 | else |
f1310107 TJB |
6883 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6884 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6885 | loc2->pspace->aspace, loc2->address) | |
6886 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6887 | } |
6888 | ||
76897487 KB |
6889 | static void |
6890 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6891 | int bnum, int have_bnum) | |
6892 | { | |
f63fbe86 MS |
6893 | /* The longest string possibly returned by hex_string_custom |
6894 | is 50 chars. These must be at least that big for safety. */ | |
6895 | char astr1[64]; | |
6896 | char astr2[64]; | |
76897487 | 6897 | |
bb599908 PH |
6898 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6899 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6900 | if (have_bnum) |
8a3fe4f8 | 6901 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6902 | bnum, astr1, astr2); |
6903 | else | |
8a3fe4f8 | 6904 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6905 | } |
6906 | ||
4a64f543 MS |
6907 | /* Adjust a breakpoint's address to account for architectural |
6908 | constraints on breakpoint placement. Return the adjusted address. | |
6909 | Note: Very few targets require this kind of adjustment. For most | |
6910 | targets, this function is simply the identity function. */ | |
76897487 KB |
6911 | |
6912 | static CORE_ADDR | |
a6d9a66e UW |
6913 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6914 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6915 | { |
a6d9a66e | 6916 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
6917 | { |
6918 | /* Very few targets need any kind of breakpoint adjustment. */ | |
6919 | return bpaddr; | |
6920 | } | |
88f7da05 KB |
6921 | else if (bptype == bp_watchpoint |
6922 | || bptype == bp_hardware_watchpoint | |
6923 | || bptype == bp_read_watchpoint | |
6924 | || bptype == bp_access_watchpoint | |
fe798b75 | 6925 | || bptype == bp_catchpoint) |
88f7da05 KB |
6926 | { |
6927 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6928 | have their addresses modified. */ | |
6929 | return bpaddr; | |
6930 | } | |
76897487 KB |
6931 | else |
6932 | { | |
6933 | CORE_ADDR adjusted_bpaddr; | |
6934 | ||
6935 | /* Some targets have architectural constraints on the placement | |
6936 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 6937 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
6938 | |
6939 | /* An adjusted breakpoint address can significantly alter | |
6940 | a user's expectations. Print a warning if an adjustment | |
6941 | is required. */ | |
6942 | if (adjusted_bpaddr != bpaddr) | |
6943 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6944 | ||
6945 | return adjusted_bpaddr; | |
6946 | } | |
6947 | } | |
6948 | ||
28010a5d PA |
6949 | void |
6950 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
6951 | struct breakpoint *owner) | |
7cc221ef | 6952 | { |
7cc221ef DJ |
6953 | memset (loc, 0, sizeof (*loc)); |
6954 | ||
348d480f PA |
6955 | gdb_assert (ops != NULL); |
6956 | ||
28010a5d PA |
6957 | loc->ops = ops; |
6958 | loc->owner = owner; | |
511a6cd4 | 6959 | loc->cond = NULL; |
b775012e | 6960 | loc->cond_bytecode = NULL; |
0d381245 VP |
6961 | loc->shlib_disabled = 0; |
6962 | loc->enabled = 1; | |
e049a4b5 | 6963 | |
28010a5d | 6964 | switch (owner->type) |
e049a4b5 DJ |
6965 | { |
6966 | case bp_breakpoint: | |
6967 | case bp_until: | |
6968 | case bp_finish: | |
6969 | case bp_longjmp: | |
6970 | case bp_longjmp_resume: | |
e2e4d78b | 6971 | case bp_longjmp_call_dummy: |
186c406b TT |
6972 | case bp_exception: |
6973 | case bp_exception_resume: | |
e049a4b5 | 6974 | case bp_step_resume: |
2c03e5be | 6975 | case bp_hp_step_resume: |
e049a4b5 DJ |
6976 | case bp_watchpoint_scope: |
6977 | case bp_call_dummy: | |
aa7d318d | 6978 | case bp_std_terminate: |
e049a4b5 DJ |
6979 | case bp_shlib_event: |
6980 | case bp_thread_event: | |
6981 | case bp_overlay_event: | |
4efc6507 | 6982 | case bp_jit_event: |
0fd8e87f | 6983 | case bp_longjmp_master: |
aa7d318d | 6984 | case bp_std_terminate_master: |
186c406b | 6985 | case bp_exception_master: |
0e30163f JK |
6986 | case bp_gnu_ifunc_resolver: |
6987 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6988 | case bp_dprintf: |
e049a4b5 | 6989 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6990 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6991 | break; |
6992 | case bp_hardware_breakpoint: | |
6993 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6994 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6995 | break; |
6996 | case bp_hardware_watchpoint: | |
6997 | case bp_read_watchpoint: | |
6998 | case bp_access_watchpoint: | |
6999 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7000 | break; | |
7001 | case bp_watchpoint: | |
ce78b96d | 7002 | case bp_catchpoint: |
15c3d785 PA |
7003 | case bp_tracepoint: |
7004 | case bp_fast_tracepoint: | |
0fb4aa4b | 7005 | case bp_static_tracepoint: |
e049a4b5 DJ |
7006 | loc->loc_type = bp_loc_other; |
7007 | break; | |
7008 | default: | |
e2e0b3e5 | 7009 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7010 | } |
7011 | ||
f431efe5 | 7012 | loc->refc = 1; |
28010a5d PA |
7013 | } |
7014 | ||
7015 | /* Allocate a struct bp_location. */ | |
7016 | ||
7017 | static struct bp_location * | |
7018 | allocate_bp_location (struct breakpoint *bpt) | |
7019 | { | |
348d480f PA |
7020 | return bpt->ops->allocate_location (bpt); |
7021 | } | |
7cc221ef | 7022 | |
f431efe5 PA |
7023 | static void |
7024 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7025 | { |
348d480f | 7026 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7027 | xfree (loc); |
7028 | } | |
7029 | ||
f431efe5 PA |
7030 | /* Increment reference count. */ |
7031 | ||
7032 | static void | |
7033 | incref_bp_location (struct bp_location *bl) | |
7034 | { | |
7035 | ++bl->refc; | |
7036 | } | |
7037 | ||
7038 | /* Decrement reference count. If the reference count reaches 0, | |
7039 | destroy the bp_location. Sets *BLP to NULL. */ | |
7040 | ||
7041 | static void | |
7042 | decref_bp_location (struct bp_location **blp) | |
7043 | { | |
0807b50c PA |
7044 | gdb_assert ((*blp)->refc > 0); |
7045 | ||
f431efe5 PA |
7046 | if (--(*blp)->refc == 0) |
7047 | free_bp_location (*blp); | |
7048 | *blp = NULL; | |
7049 | } | |
7050 | ||
346774a9 | 7051 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7052 | |
346774a9 PA |
7053 | static void |
7054 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7055 | { |
346774a9 | 7056 | struct breakpoint *b1; |
c906108c | 7057 | |
346774a9 PA |
7058 | /* Add this breakpoint to the end of the chain so that a list of |
7059 | breakpoints will come out in order of increasing numbers. */ | |
7060 | ||
7061 | b1 = breakpoint_chain; | |
7062 | if (b1 == 0) | |
7063 | breakpoint_chain = b; | |
7064 | else | |
7065 | { | |
7066 | while (b1->next) | |
7067 | b1 = b1->next; | |
7068 | b1->next = b; | |
7069 | } | |
7070 | } | |
7071 | ||
7072 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7073 | ||
7074 | static void | |
7075 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7076 | struct gdbarch *gdbarch, | |
28010a5d | 7077 | enum bptype bptype, |
c0a91b2b | 7078 | const struct breakpoint_ops *ops) |
346774a9 | 7079 | { |
c906108c | 7080 | memset (b, 0, sizeof (*b)); |
2219d63c | 7081 | |
348d480f PA |
7082 | gdb_assert (ops != NULL); |
7083 | ||
28010a5d | 7084 | b->ops = ops; |
4d28f7a8 | 7085 | b->type = bptype; |
a6d9a66e | 7086 | b->gdbarch = gdbarch; |
c906108c SS |
7087 | b->language = current_language->la_language; |
7088 | b->input_radix = input_radix; | |
7089 | b->thread = -1; | |
b5de0fa7 | 7090 | b->enable_state = bp_enabled; |
c906108c SS |
7091 | b->next = 0; |
7092 | b->silent = 0; | |
7093 | b->ignore_count = 0; | |
7094 | b->commands = NULL; | |
818dd999 | 7095 | b->frame_id = null_frame_id; |
0d381245 | 7096 | b->condition_not_parsed = 0; |
84f4c1fe | 7097 | b->py_bp_object = NULL; |
d0fb5eae | 7098 | b->related_breakpoint = b; |
346774a9 PA |
7099 | } |
7100 | ||
7101 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7102 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7103 | |
7104 | static struct breakpoint * | |
7105 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7106 | enum bptype bptype, |
c0a91b2b | 7107 | const struct breakpoint_ops *ops) |
346774a9 PA |
7108 | { |
7109 | struct breakpoint *b = XNEW (struct breakpoint); | |
7110 | ||
348d480f | 7111 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7112 | add_to_breakpoint_chain (b); |
0d381245 VP |
7113 | return b; |
7114 | } | |
7115 | ||
0e30163f JK |
7116 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7117 | resolutions should be made as the user specified the location explicitly | |
7118 | enough. */ | |
7119 | ||
0d381245 | 7120 | static void |
0e30163f | 7121 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7122 | { |
2bdf28a0 JK |
7123 | gdb_assert (loc->owner != NULL); |
7124 | ||
0d381245 | 7125 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7126 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7127 | || is_tracepoint (loc->owner)) |
0d381245 | 7128 | { |
0e30163f | 7129 | int is_gnu_ifunc; |
2c02bd72 | 7130 | const char *function_name; |
6a3a010b | 7131 | CORE_ADDR func_addr; |
0e30163f | 7132 | |
2c02bd72 | 7133 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7134 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7135 | |
7136 | if (is_gnu_ifunc && !explicit_loc) | |
7137 | { | |
7138 | struct breakpoint *b = loc->owner; | |
7139 | ||
7140 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7141 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7142 | &loc->requested_address)) |
7143 | { | |
7144 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7145 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7146 | loc->requested_address, | |
7147 | b->type); | |
7148 | } | |
7149 | else if (b->type == bp_breakpoint && b->loc == loc | |
7150 | && loc->next == NULL && b->related_breakpoint == b) | |
7151 | { | |
7152 | /* Create only the whole new breakpoint of this type but do not | |
7153 | mess more complicated breakpoints with multiple locations. */ | |
7154 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7155 | /* Remember the resolver's address for use by the return |
7156 | breakpoint. */ | |
7157 | loc->related_address = func_addr; | |
0e30163f JK |
7158 | } |
7159 | } | |
7160 | ||
2c02bd72 DE |
7161 | if (function_name) |
7162 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7163 | } |
7164 | } | |
7165 | ||
a6d9a66e | 7166 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7167 | struct gdbarch * |
a6d9a66e UW |
7168 | get_sal_arch (struct symtab_and_line sal) |
7169 | { | |
7170 | if (sal.section) | |
7171 | return get_objfile_arch (sal.section->objfile); | |
7172 | if (sal.symtab) | |
7173 | return get_objfile_arch (sal.symtab->objfile); | |
7174 | ||
7175 | return NULL; | |
7176 | } | |
7177 | ||
346774a9 PA |
7178 | /* Low level routine for partially initializing a breakpoint of type |
7179 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7180 | file name, and line number are provided by SAL. |
0d381245 VP |
7181 | |
7182 | It is expected that the caller will complete the initialization of | |
7183 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7184 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7185 | |
346774a9 PA |
7186 | static void |
7187 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7188 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7189 | const struct breakpoint_ops *ops) |
0d381245 | 7190 | { |
28010a5d | 7191 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7192 | |
3742cc8b | 7193 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7194 | |
6c95b8df PA |
7195 | if (bptype != bp_catchpoint) |
7196 | gdb_assert (sal.pspace != NULL); | |
7197 | ||
f8eba3c6 TT |
7198 | /* Store the program space that was used to set the breakpoint, |
7199 | except for ordinary breakpoints, which are independent of the | |
7200 | program space. */ | |
7201 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7202 | b->pspace = sal.pspace; | |
346774a9 | 7203 | } |
c906108c | 7204 | |
346774a9 PA |
7205 | /* set_raw_breakpoint is a low level routine for allocating and |
7206 | partially initializing a breakpoint of type BPTYPE. The newly | |
7207 | created breakpoint's address, section, source file name, and line | |
7208 | number are provided by SAL. The newly created and partially | |
7209 | initialized breakpoint is added to the breakpoint chain and | |
7210 | is also returned as the value of this function. | |
7211 | ||
7212 | It is expected that the caller will complete the initialization of | |
7213 | the newly created breakpoint struct as well as output any status | |
7214 | information regarding the creation of a new breakpoint. In | |
7215 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7216 | number! Care should be taken to not allow an error to occur | |
7217 | prior to completing the initialization of the breakpoint. If this | |
7218 | should happen, a bogus breakpoint will be left on the chain. */ | |
7219 | ||
7220 | struct breakpoint * | |
7221 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7222 | struct symtab_and_line sal, 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 (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7228 | add_to_breakpoint_chain (b); |
c906108c SS |
7229 | return b; |
7230 | } | |
7231 | ||
c2c6d25f JM |
7232 | |
7233 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7234 | instruction, hard-wired into the inferior's code. */ | |
7235 | void | |
7236 | make_breakpoint_permanent (struct breakpoint *b) | |
7237 | { | |
0d381245 | 7238 | struct bp_location *bl; |
cc59ec59 | 7239 | |
b5de0fa7 | 7240 | b->enable_state = bp_permanent; |
c2c6d25f | 7241 | |
4a64f543 MS |
7242 | /* By definition, permanent breakpoints are already present in the |
7243 | code. Mark all locations as inserted. For now, | |
7244 | make_breakpoint_permanent is called in just one place, so it's | |
7245 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7246 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7247 | for (bl = b->loc; bl; bl = bl->next) |
7248 | bl->inserted = 1; | |
c2c6d25f JM |
7249 | } |
7250 | ||
53a5351d | 7251 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7252 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7253 | initiated the operation. */ | |
c906108c SS |
7254 | |
7255 | void | |
186c406b | 7256 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7257 | { |
35df4500 | 7258 | struct breakpoint *b, *b_tmp; |
186c406b | 7259 | int thread = tp->num; |
0fd8e87f UW |
7260 | |
7261 | /* To avoid having to rescan all objfile symbols at every step, | |
7262 | we maintain a list of continually-inserted but always disabled | |
7263 | longjmp "master" breakpoints. Here, we simply create momentary | |
7264 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7265 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7266 | if (b->pspace == current_program_space |
186c406b TT |
7267 | && (b->type == bp_longjmp_master |
7268 | || b->type == bp_exception_master)) | |
0fd8e87f | 7269 | { |
06edf0c0 PA |
7270 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7271 | struct breakpoint *clone; | |
cc59ec59 | 7272 | |
e2e4d78b JK |
7273 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7274 | after their removal. */ | |
06edf0c0 | 7275 | clone = momentary_breakpoint_from_master (b, type, |
e2e4d78b | 7276 | &longjmp_breakpoint_ops); |
0fd8e87f UW |
7277 | clone->thread = thread; |
7278 | } | |
186c406b TT |
7279 | |
7280 | tp->initiating_frame = frame; | |
c906108c SS |
7281 | } |
7282 | ||
611c83ae | 7283 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7284 | void |
611c83ae | 7285 | delete_longjmp_breakpoint (int thread) |
c906108c | 7286 | { |
35df4500 | 7287 | struct breakpoint *b, *b_tmp; |
c906108c | 7288 | |
35df4500 | 7289 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7290 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7291 | { |
7292 | if (b->thread == thread) | |
7293 | delete_breakpoint (b); | |
7294 | } | |
c906108c SS |
7295 | } |
7296 | ||
f59f708a PA |
7297 | void |
7298 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7299 | { | |
7300 | struct breakpoint *b, *b_tmp; | |
7301 | ||
7302 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7303 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7304 | { | |
7305 | if (b->thread == thread) | |
7306 | b->disposition = disp_del_at_next_stop; | |
7307 | } | |
7308 | } | |
7309 | ||
e2e4d78b JK |
7310 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7311 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7312 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7313 | breakpoints. */ | |
7314 | ||
7315 | struct breakpoint * | |
7316 | set_longjmp_breakpoint_for_call_dummy (void) | |
7317 | { | |
7318 | struct breakpoint *b, *retval = NULL; | |
7319 | ||
7320 | ALL_BREAKPOINTS (b) | |
7321 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7322 | { | |
7323 | struct breakpoint *new_b; | |
7324 | ||
7325 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
7326 | &momentary_breakpoint_ops); | |
7327 | new_b->thread = pid_to_thread_id (inferior_ptid); | |
7328 | ||
7329 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7330 | ||
7331 | gdb_assert (new_b->related_breakpoint == new_b); | |
7332 | if (retval == NULL) | |
7333 | retval = new_b; | |
7334 | new_b->related_breakpoint = retval; | |
7335 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7336 | retval = retval->related_breakpoint; | |
7337 | retval->related_breakpoint = new_b; | |
7338 | } | |
7339 | ||
7340 | return retval; | |
7341 | } | |
7342 | ||
7343 | /* Verify all existing dummy frames and their associated breakpoints for | |
7344 | THREAD. Remove those which can no longer be found in the current frame | |
7345 | stack. | |
7346 | ||
7347 | You should call this function only at places where it is safe to currently | |
7348 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7349 | frames. */ | |
7350 | ||
7351 | void | |
7352 | check_longjmp_breakpoint_for_call_dummy (int thread) | |
7353 | { | |
7354 | struct breakpoint *b, *b_tmp; | |
7355 | ||
7356 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7357 | if (b->type == bp_longjmp_call_dummy && b->thread == thread) | |
7358 | { | |
7359 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7360 | ||
7361 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7362 | dummy_b = dummy_b->related_breakpoint; | |
7363 | if (dummy_b->type != bp_call_dummy | |
7364 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7365 | continue; | |
7366 | ||
7367 | dummy_frame_discard (dummy_b->frame_id); | |
7368 | ||
7369 | while (b->related_breakpoint != b) | |
7370 | { | |
7371 | if (b_tmp == b->related_breakpoint) | |
7372 | b_tmp = b->related_breakpoint->next; | |
7373 | delete_breakpoint (b->related_breakpoint); | |
7374 | } | |
7375 | delete_breakpoint (b); | |
7376 | } | |
7377 | } | |
7378 | ||
1900040c MS |
7379 | void |
7380 | enable_overlay_breakpoints (void) | |
7381 | { | |
52f0bd74 | 7382 | struct breakpoint *b; |
1900040c MS |
7383 | |
7384 | ALL_BREAKPOINTS (b) | |
7385 | if (b->type == bp_overlay_event) | |
7386 | { | |
7387 | b->enable_state = bp_enabled; | |
b60e7edf | 7388 | update_global_location_list (1); |
c02f5703 | 7389 | overlay_events_enabled = 1; |
1900040c MS |
7390 | } |
7391 | } | |
7392 | ||
7393 | void | |
7394 | disable_overlay_breakpoints (void) | |
7395 | { | |
52f0bd74 | 7396 | struct breakpoint *b; |
1900040c MS |
7397 | |
7398 | ALL_BREAKPOINTS (b) | |
7399 | if (b->type == bp_overlay_event) | |
7400 | { | |
7401 | b->enable_state = bp_disabled; | |
b60e7edf | 7402 | update_global_location_list (0); |
c02f5703 | 7403 | overlay_events_enabled = 0; |
1900040c MS |
7404 | } |
7405 | } | |
7406 | ||
aa7d318d TT |
7407 | /* Set an active std::terminate breakpoint for each std::terminate |
7408 | master breakpoint. */ | |
7409 | void | |
7410 | set_std_terminate_breakpoint (void) | |
7411 | { | |
35df4500 | 7412 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7413 | |
35df4500 | 7414 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7415 | if (b->pspace == current_program_space |
7416 | && b->type == bp_std_terminate_master) | |
7417 | { | |
06edf0c0 PA |
7418 | momentary_breakpoint_from_master (b, bp_std_terminate, |
7419 | &momentary_breakpoint_ops); | |
aa7d318d TT |
7420 | } |
7421 | } | |
7422 | ||
7423 | /* Delete all the std::terminate breakpoints. */ | |
7424 | void | |
7425 | delete_std_terminate_breakpoint (void) | |
7426 | { | |
35df4500 | 7427 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7428 | |
35df4500 | 7429 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7430 | if (b->type == bp_std_terminate) |
7431 | delete_breakpoint (b); | |
7432 | } | |
7433 | ||
c4093a6a | 7434 | struct breakpoint * |
a6d9a66e | 7435 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7436 | { |
7437 | struct breakpoint *b; | |
c4093a6a | 7438 | |
06edf0c0 PA |
7439 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7440 | &internal_breakpoint_ops); | |
7441 | ||
b5de0fa7 | 7442 | b->enable_state = bp_enabled; |
c4093a6a | 7443 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7444 | b->addr_string |
7445 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7446 | |
b60e7edf | 7447 | update_global_location_list_nothrow (1); |
74960c60 | 7448 | |
c4093a6a JM |
7449 | return b; |
7450 | } | |
7451 | ||
7452 | void | |
7453 | remove_thread_event_breakpoints (void) | |
7454 | { | |
35df4500 | 7455 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7456 | |
35df4500 | 7457 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7458 | if (b->type == bp_thread_event |
7459 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7460 | delete_breakpoint (b); |
7461 | } | |
7462 | ||
0101ce28 JJ |
7463 | struct lang_and_radix |
7464 | { | |
7465 | enum language lang; | |
7466 | int radix; | |
7467 | }; | |
7468 | ||
4efc6507 DE |
7469 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7470 | ||
7471 | struct breakpoint * | |
7472 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7473 | { | |
7474 | struct breakpoint *b; | |
7475 | ||
06edf0c0 PA |
7476 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7477 | &internal_breakpoint_ops); | |
4efc6507 DE |
7478 | update_global_location_list_nothrow (1); |
7479 | return b; | |
7480 | } | |
0101ce28 | 7481 | |
03673fc7 PP |
7482 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7483 | ||
7484 | void | |
7485 | remove_jit_event_breakpoints (void) | |
7486 | { | |
7487 | struct breakpoint *b, *b_tmp; | |
7488 | ||
7489 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7490 | if (b->type == bp_jit_event | |
7491 | && b->loc->pspace == current_program_space) | |
7492 | delete_breakpoint (b); | |
7493 | } | |
7494 | ||
cae688ec JJ |
7495 | void |
7496 | remove_solib_event_breakpoints (void) | |
7497 | { | |
35df4500 | 7498 | struct breakpoint *b, *b_tmp; |
cae688ec | 7499 | |
35df4500 | 7500 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7501 | if (b->type == bp_shlib_event |
7502 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7503 | delete_breakpoint (b); |
7504 | } | |
7505 | ||
7506 | struct breakpoint * | |
a6d9a66e | 7507 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
7508 | { |
7509 | struct breakpoint *b; | |
7510 | ||
06edf0c0 PA |
7511 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7512 | &internal_breakpoint_ops); | |
b60e7edf | 7513 | update_global_location_list_nothrow (1); |
cae688ec JJ |
7514 | return b; |
7515 | } | |
7516 | ||
7517 | /* Disable any breakpoints that are on code in shared libraries. Only | |
7518 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7519 | ||
7520 | void | |
cb851954 | 7521 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7522 | { |
876fa593 | 7523 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7524 | |
876fa593 | 7525 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7526 | { |
2bdf28a0 | 7527 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7528 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7529 | |
4a64f543 MS |
7530 | /* We apply the check to all breakpoints, including disabled for |
7531 | those with loc->duplicate set. This is so that when breakpoint | |
7532 | becomes enabled, or the duplicate is removed, gdb will try to | |
7533 | insert all breakpoints. If we don't set shlib_disabled here, | |
7534 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7535 | if (((b->type == bp_breakpoint) |
508ccb1f | 7536 | || (b->type == bp_jit_event) |
1042e4c0 | 7537 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7538 | || (is_tracepoint (b))) |
6c95b8df | 7539 | && loc->pspace == current_program_space |
0d381245 | 7540 | && !loc->shlib_disabled |
6c95b8df | 7541 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7542 | ) |
0d381245 VP |
7543 | { |
7544 | loc->shlib_disabled = 1; | |
7545 | } | |
cae688ec JJ |
7546 | } |
7547 | } | |
7548 | ||
63644780 NB |
7549 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7550 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7551 | disabled ones can just stay disabled. */ | |
84acb35a | 7552 | |
75149521 | 7553 | static void |
84acb35a JJ |
7554 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7555 | { | |
876fa593 | 7556 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7557 | int disabled_shlib_breaks = 0; |
7558 | ||
c86cf029 VP |
7559 | /* SunOS a.out shared libraries are always mapped, so do not |
7560 | disable breakpoints; they will only be reported as unloaded | |
7561 | through clear_solib when GDB discards its shared library | |
7562 | list. See clear_solib for more information. */ | |
7563 | if (exec_bfd != NULL | |
7564 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7565 | return; | |
7566 | ||
876fa593 | 7567 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7568 | { |
2bdf28a0 | 7569 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7570 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7571 | |
1e4d1764 | 7572 | if (solib->pspace == loc->pspace |
e2dd7057 | 7573 | && !loc->shlib_disabled |
1e4d1764 YQ |
7574 | && (((b->type == bp_breakpoint |
7575 | || b->type == bp_jit_event | |
7576 | || b->type == bp_hardware_breakpoint) | |
7577 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7578 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7579 | || is_tracepoint (b)) | |
e2dd7057 | 7580 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7581 | { |
e2dd7057 PP |
7582 | loc->shlib_disabled = 1; |
7583 | /* At this point, we cannot rely on remove_breakpoint | |
7584 | succeeding so we must mark the breakpoint as not inserted | |
7585 | to prevent future errors occurring in remove_breakpoints. */ | |
7586 | loc->inserted = 0; | |
8d3788bd VP |
7587 | |
7588 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7589 | observer_notify_breakpoint_modified (b); | |
7590 | ||
e2dd7057 PP |
7591 | if (!disabled_shlib_breaks) |
7592 | { | |
7593 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7594 | warning (_("Temporarily disabling breakpoints " |
7595 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7596 | solib->so_name); |
84acb35a | 7597 | } |
e2dd7057 | 7598 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7599 | } |
7600 | } | |
84acb35a JJ |
7601 | } |
7602 | ||
63644780 NB |
7603 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7604 | notification of free_objfile. Only apply to enabled breakpoints, | |
7605 | disabled ones can just stay disabled. */ | |
7606 | ||
7607 | static void | |
7608 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7609 | { | |
7610 | struct breakpoint *b; | |
7611 | ||
7612 | if (objfile == NULL) | |
7613 | return; | |
7614 | ||
7615 | /* If the file is a shared library not loaded by the user then | |
7616 | solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib | |
7617 | was called. In that case there is no need to take action again. */ | |
7618 | if ((objfile->flags & OBJF_SHARED) && !(objfile->flags & OBJF_USERLOADED)) | |
7619 | return; | |
7620 | ||
7621 | ALL_BREAKPOINTS (b) | |
7622 | { | |
7623 | struct bp_location *loc; | |
7624 | int bp_modified = 0; | |
7625 | ||
7626 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7627 | continue; | |
7628 | ||
7629 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7630 | { | |
7631 | CORE_ADDR loc_addr = loc->address; | |
7632 | ||
7633 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7634 | && loc->loc_type != bp_loc_software_breakpoint) | |
7635 | continue; | |
7636 | ||
7637 | if (loc->shlib_disabled != 0) | |
7638 | continue; | |
7639 | ||
7640 | if (objfile->pspace != loc->pspace) | |
7641 | continue; | |
7642 | ||
7643 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7644 | && loc->loc_type != bp_loc_software_breakpoint) | |
7645 | continue; | |
7646 | ||
7647 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7648 | { | |
7649 | loc->shlib_disabled = 1; | |
7650 | loc->inserted = 0; | |
7651 | ||
7652 | mark_breakpoint_location_modified (loc); | |
7653 | ||
7654 | bp_modified = 1; | |
7655 | } | |
7656 | } | |
7657 | ||
7658 | if (bp_modified) | |
7659 | observer_notify_breakpoint_modified (b); | |
7660 | } | |
7661 | } | |
7662 | ||
ce78b96d JB |
7663 | /* FORK & VFORK catchpoints. */ |
7664 | ||
e29a4733 PA |
7665 | /* An instance of this type is used to represent a fork or vfork |
7666 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7667 | class; users downcast to "struct breakpoint *" when needed. A | |
7668 | breakpoint is really of this type iff its ops pointer points to | |
7669 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7670 | ||
7671 | struct fork_catchpoint | |
7672 | { | |
7673 | /* The base class. */ | |
7674 | struct breakpoint base; | |
7675 | ||
7676 | /* Process id of a child process whose forking triggered this | |
7677 | catchpoint. This field is only valid immediately after this | |
7678 | catchpoint has triggered. */ | |
7679 | ptid_t forked_inferior_pid; | |
7680 | }; | |
7681 | ||
4a64f543 MS |
7682 | /* Implement the "insert" breakpoint_ops method for fork |
7683 | catchpoints. */ | |
ce78b96d | 7684 | |
77b06cd7 TJB |
7685 | static int |
7686 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7687 | { |
dfd4cc63 | 7688 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7689 | } |
7690 | ||
4a64f543 MS |
7691 | /* Implement the "remove" breakpoint_ops method for fork |
7692 | catchpoints. */ | |
ce78b96d JB |
7693 | |
7694 | static int | |
77b06cd7 | 7695 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7696 | { |
dfd4cc63 | 7697 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7698 | } |
7699 | ||
7700 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7701 | catchpoints. */ | |
7702 | ||
7703 | static int | |
f1310107 | 7704 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7705 | struct address_space *aspace, CORE_ADDR bp_addr, |
7706 | const struct target_waitstatus *ws) | |
ce78b96d | 7707 | { |
e29a4733 PA |
7708 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7709 | ||
f90263c1 TT |
7710 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7711 | return 0; | |
7712 | ||
7713 | c->forked_inferior_pid = ws->value.related_pid; | |
7714 | return 1; | |
ce78b96d JB |
7715 | } |
7716 | ||
4a64f543 MS |
7717 | /* Implement the "print_it" breakpoint_ops method for fork |
7718 | catchpoints. */ | |
ce78b96d JB |
7719 | |
7720 | static enum print_stop_action | |
348d480f | 7721 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7722 | { |
36dfb11c | 7723 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7724 | struct breakpoint *b = bs->breakpoint_at; |
7725 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7726 | |
ce78b96d | 7727 | annotate_catchpoint (b->number); |
36dfb11c TT |
7728 | if (b->disposition == disp_del) |
7729 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7730 | else | |
7731 | ui_out_text (uiout, "\nCatchpoint "); | |
7732 | if (ui_out_is_mi_like_p (uiout)) | |
7733 | { | |
7734 | ui_out_field_string (uiout, "reason", | |
7735 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7736 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7737 | } | |
7738 | ui_out_field_int (uiout, "bkptno", b->number); | |
7739 | ui_out_text (uiout, " (forked process "); | |
7740 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7741 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7742 | return PRINT_SRC_AND_LOC; |
7743 | } | |
7744 | ||
4a64f543 MS |
7745 | /* Implement the "print_one" breakpoint_ops method for fork |
7746 | catchpoints. */ | |
ce78b96d JB |
7747 | |
7748 | static void | |
a6d9a66e | 7749 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7750 | { |
e29a4733 | 7751 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7752 | struct value_print_options opts; |
79a45e25 | 7753 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7754 | |
7755 | get_user_print_options (&opts); | |
7756 | ||
4a64f543 MS |
7757 | /* Field 4, the address, is omitted (which makes the columns not |
7758 | line up too nicely with the headers, but the effect is relatively | |
7759 | readable). */ | |
79a45b7d | 7760 | if (opts.addressprint) |
ce78b96d JB |
7761 | ui_out_field_skip (uiout, "addr"); |
7762 | annotate_field (5); | |
7763 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7764 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7765 | { |
7766 | ui_out_text (uiout, ", process "); | |
7767 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7768 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7769 | ui_out_spaces (uiout, 1); |
7770 | } | |
8ac3646f TT |
7771 | |
7772 | if (ui_out_is_mi_like_p (uiout)) | |
7773 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7774 | } |
7775 | ||
7776 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7777 | catchpoints. */ | |
7778 | ||
7779 | static void | |
7780 | print_mention_catch_fork (struct breakpoint *b) | |
7781 | { | |
7782 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7783 | } | |
7784 | ||
6149aea9 PA |
7785 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7786 | catchpoints. */ | |
7787 | ||
7788 | static void | |
7789 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7790 | { | |
7791 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7792 | print_recreate_thread (b, fp); |
6149aea9 PA |
7793 | } |
7794 | ||
ce78b96d JB |
7795 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7796 | ||
2060206e | 7797 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7798 | |
4a64f543 MS |
7799 | /* Implement the "insert" breakpoint_ops method for vfork |
7800 | catchpoints. */ | |
ce78b96d | 7801 | |
77b06cd7 TJB |
7802 | static int |
7803 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7804 | { |
dfd4cc63 | 7805 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7806 | } |
7807 | ||
4a64f543 MS |
7808 | /* Implement the "remove" breakpoint_ops method for vfork |
7809 | catchpoints. */ | |
ce78b96d JB |
7810 | |
7811 | static int | |
77b06cd7 | 7812 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 7813 | { |
dfd4cc63 | 7814 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7815 | } |
7816 | ||
7817 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7818 | catchpoints. */ | |
7819 | ||
7820 | static int | |
f1310107 | 7821 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
7822 | struct address_space *aspace, CORE_ADDR bp_addr, |
7823 | const struct target_waitstatus *ws) | |
ce78b96d | 7824 | { |
e29a4733 PA |
7825 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7826 | ||
f90263c1 TT |
7827 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7828 | return 0; | |
7829 | ||
7830 | c->forked_inferior_pid = ws->value.related_pid; | |
7831 | return 1; | |
ce78b96d JB |
7832 | } |
7833 | ||
4a64f543 MS |
7834 | /* Implement the "print_it" breakpoint_ops method for vfork |
7835 | catchpoints. */ | |
ce78b96d JB |
7836 | |
7837 | static enum print_stop_action | |
348d480f | 7838 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7839 | { |
36dfb11c | 7840 | struct ui_out *uiout = current_uiout; |
348d480f | 7841 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7842 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7843 | ||
ce78b96d | 7844 | annotate_catchpoint (b->number); |
36dfb11c TT |
7845 | if (b->disposition == disp_del) |
7846 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7847 | else | |
7848 | ui_out_text (uiout, "\nCatchpoint "); | |
7849 | if (ui_out_is_mi_like_p (uiout)) | |
7850 | { | |
7851 | ui_out_field_string (uiout, "reason", | |
7852 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
7853 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7854 | } | |
7855 | ui_out_field_int (uiout, "bkptno", b->number); | |
7856 | ui_out_text (uiout, " (vforked process "); | |
7857 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7858 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7859 | return PRINT_SRC_AND_LOC; |
7860 | } | |
7861 | ||
4a64f543 MS |
7862 | /* Implement the "print_one" breakpoint_ops method for vfork |
7863 | catchpoints. */ | |
ce78b96d JB |
7864 | |
7865 | static void | |
a6d9a66e | 7866 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7867 | { |
e29a4733 | 7868 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7869 | struct value_print_options opts; |
79a45e25 | 7870 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7871 | |
7872 | get_user_print_options (&opts); | |
4a64f543 MS |
7873 | /* Field 4, the address, is omitted (which makes the columns not |
7874 | line up too nicely with the headers, but the effect is relatively | |
7875 | readable). */ | |
79a45b7d | 7876 | if (opts.addressprint) |
ce78b96d JB |
7877 | ui_out_field_skip (uiout, "addr"); |
7878 | annotate_field (5); | |
7879 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 7880 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7881 | { |
7882 | ui_out_text (uiout, ", process "); | |
7883 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7884 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7885 | ui_out_spaces (uiout, 1); |
7886 | } | |
8ac3646f TT |
7887 | |
7888 | if (ui_out_is_mi_like_p (uiout)) | |
7889 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
7890 | } |
7891 | ||
7892 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7893 | catchpoints. */ | |
7894 | ||
7895 | static void | |
7896 | print_mention_catch_vfork (struct breakpoint *b) | |
7897 | { | |
7898 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7899 | } | |
7900 | ||
6149aea9 PA |
7901 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7902 | catchpoints. */ | |
7903 | ||
7904 | static void | |
7905 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7906 | { | |
7907 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7908 | print_recreate_thread (b, fp); |
6149aea9 PA |
7909 | } |
7910 | ||
ce78b96d JB |
7911 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7912 | ||
2060206e | 7913 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7914 | |
edcc5120 TT |
7915 | /* An instance of this type is used to represent an solib catchpoint. |
7916 | It includes a "struct breakpoint" as a kind of base class; users | |
7917 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
7918 | really of this type iff its ops pointer points to | |
7919 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
7920 | ||
7921 | struct solib_catchpoint | |
7922 | { | |
7923 | /* The base class. */ | |
7924 | struct breakpoint base; | |
7925 | ||
7926 | /* True for "catch load", false for "catch unload". */ | |
7927 | unsigned char is_load; | |
7928 | ||
7929 | /* Regular expression to match, if any. COMPILED is only valid when | |
7930 | REGEX is non-NULL. */ | |
7931 | char *regex; | |
7932 | regex_t compiled; | |
7933 | }; | |
7934 | ||
7935 | static void | |
7936 | dtor_catch_solib (struct breakpoint *b) | |
7937 | { | |
7938 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7939 | ||
7940 | if (self->regex) | |
7941 | regfree (&self->compiled); | |
7942 | xfree (self->regex); | |
7943 | ||
7944 | base_breakpoint_ops.dtor (b); | |
7945 | } | |
7946 | ||
7947 | static int | |
7948 | insert_catch_solib (struct bp_location *ignore) | |
7949 | { | |
7950 | return 0; | |
7951 | } | |
7952 | ||
7953 | static int | |
7954 | remove_catch_solib (struct bp_location *ignore) | |
7955 | { | |
7956 | return 0; | |
7957 | } | |
7958 | ||
7959 | static int | |
7960 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
7961 | struct address_space *aspace, | |
7962 | CORE_ADDR bp_addr, | |
7963 | const struct target_waitstatus *ws) | |
7964 | { | |
7965 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7966 | struct breakpoint *other; | |
7967 | ||
7968 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7969 | return 1; | |
7970 | ||
7971 | ALL_BREAKPOINTS (other) | |
7972 | { | |
7973 | struct bp_location *other_bl; | |
7974 | ||
7975 | if (other == bl->owner) | |
7976 | continue; | |
7977 | ||
7978 | if (other->type != bp_shlib_event) | |
7979 | continue; | |
7980 | ||
7981 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
7982 | continue; | |
7983 | ||
7984 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7985 | { | |
7986 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7987 | return 1; | |
7988 | } | |
7989 | } | |
7990 | ||
7991 | return 0; | |
7992 | } | |
7993 | ||
7994 | static void | |
7995 | check_status_catch_solib (struct bpstats *bs) | |
7996 | { | |
7997 | struct solib_catchpoint *self | |
7998 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
7999 | int ix; | |
8000 | ||
8001 | if (self->is_load) | |
8002 | { | |
8003 | struct so_list *iter; | |
8004 | ||
8005 | for (ix = 0; | |
8006 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8007 | ix, iter); | |
8008 | ++ix) | |
8009 | { | |
8010 | if (!self->regex | |
8011 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8012 | return; | |
8013 | } | |
8014 | } | |
8015 | else | |
8016 | { | |
8017 | char *iter; | |
8018 | ||
8019 | for (ix = 0; | |
8020 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8021 | ix, iter); | |
8022 | ++ix) | |
8023 | { | |
8024 | if (!self->regex | |
8025 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8026 | return; | |
8027 | } | |
8028 | } | |
8029 | ||
8030 | bs->stop = 0; | |
8031 | bs->print_it = print_it_noop; | |
8032 | } | |
8033 | ||
8034 | static enum print_stop_action | |
8035 | print_it_catch_solib (bpstat bs) | |
8036 | { | |
8037 | struct breakpoint *b = bs->breakpoint_at; | |
8038 | struct ui_out *uiout = current_uiout; | |
8039 | ||
8040 | annotate_catchpoint (b->number); | |
8041 | if (b->disposition == disp_del) | |
8042 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8043 | else | |
8044 | ui_out_text (uiout, "\nCatchpoint "); | |
8045 | ui_out_field_int (uiout, "bkptno", b->number); | |
8046 | ui_out_text (uiout, "\n"); | |
8047 | if (ui_out_is_mi_like_p (uiout)) | |
8048 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8049 | print_solib_event (1); | |
8050 | return PRINT_SRC_AND_LOC; | |
8051 | } | |
8052 | ||
8053 | static void | |
8054 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8055 | { | |
8056 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8057 | struct value_print_options opts; | |
8058 | struct ui_out *uiout = current_uiout; | |
8059 | char *msg; | |
8060 | ||
8061 | get_user_print_options (&opts); | |
8062 | /* Field 4, the address, is omitted (which makes the columns not | |
8063 | line up too nicely with the headers, but the effect is relatively | |
8064 | readable). */ | |
8065 | if (opts.addressprint) | |
8066 | { | |
8067 | annotate_field (4); | |
8068 | ui_out_field_skip (uiout, "addr"); | |
8069 | } | |
8070 | ||
8071 | annotate_field (5); | |
8072 | if (self->is_load) | |
8073 | { | |
8074 | if (self->regex) | |
8075 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8076 | else | |
8077 | msg = xstrdup (_("load of library")); | |
8078 | } | |
8079 | else | |
8080 | { | |
8081 | if (self->regex) | |
8082 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8083 | else | |
8084 | msg = xstrdup (_("unload of library")); | |
8085 | } | |
8086 | ui_out_field_string (uiout, "what", msg); | |
8087 | xfree (msg); | |
8ac3646f TT |
8088 | |
8089 | if (ui_out_is_mi_like_p (uiout)) | |
8090 | ui_out_field_string (uiout, "catch-type", | |
8091 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8092 | } |
8093 | ||
8094 | static void | |
8095 | print_mention_catch_solib (struct breakpoint *b) | |
8096 | { | |
8097 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8098 | ||
8099 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8100 | self->is_load ? "load" : "unload"); | |
8101 | } | |
8102 | ||
8103 | static void | |
8104 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8105 | { | |
8106 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8107 | ||
8108 | fprintf_unfiltered (fp, "%s %s", | |
8109 | b->disposition == disp_del ? "tcatch" : "catch", | |
8110 | self->is_load ? "load" : "unload"); | |
8111 | if (self->regex) | |
8112 | fprintf_unfiltered (fp, " %s", self->regex); | |
8113 | fprintf_unfiltered (fp, "\n"); | |
8114 | } | |
8115 | ||
8116 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8117 | ||
91985142 MG |
8118 | /* Shared helper function (MI and CLI) for creating and installing |
8119 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8120 | the events to be caught are load events, otherwise they are | |
8121 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8122 | temporary one. If ENABLED is non-zero the catchpoint is | |
8123 | created in an enabled state. */ | |
edcc5120 | 8124 | |
91985142 MG |
8125 | void |
8126 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8127 | { |
8128 | struct solib_catchpoint *c; | |
8129 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8130 | struct cleanup *cleanup; |
8131 | ||
edcc5120 TT |
8132 | if (!arg) |
8133 | arg = ""; | |
8134 | arg = skip_spaces (arg); | |
8135 | ||
8136 | c = XCNEW (struct solib_catchpoint); | |
8137 | cleanup = make_cleanup (xfree, c); | |
8138 | ||
8139 | if (*arg != '\0') | |
8140 | { | |
8141 | int errcode; | |
8142 | ||
8143 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8144 | if (errcode != 0) | |
8145 | { | |
8146 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8147 | ||
8148 | make_cleanup (xfree, err); | |
8149 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8150 | } | |
8151 | c->regex = xstrdup (arg); | |
8152 | } | |
8153 | ||
8154 | c->is_load = is_load; | |
91985142 | 8155 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8156 | &catch_solib_breakpoint_ops); |
8157 | ||
91985142 MG |
8158 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8159 | ||
edcc5120 TT |
8160 | discard_cleanups (cleanup); |
8161 | install_breakpoint (0, &c->base, 1); | |
8162 | } | |
8163 | ||
91985142 MG |
8164 | /* A helper function that does all the work for "catch load" and |
8165 | "catch unload". */ | |
8166 | ||
8167 | static void | |
8168 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8169 | struct cmd_list_element *command) | |
8170 | { | |
8171 | int tempflag; | |
8172 | const int enabled = 1; | |
8173 | ||
8174 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8175 | ||
8176 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8177 | } | |
8178 | ||
edcc5120 TT |
8179 | static void |
8180 | catch_load_command_1 (char *arg, int from_tty, | |
8181 | struct cmd_list_element *command) | |
8182 | { | |
8183 | catch_load_or_unload (arg, from_tty, 1, command); | |
8184 | } | |
8185 | ||
8186 | static void | |
8187 | catch_unload_command_1 (char *arg, int from_tty, | |
8188 | struct cmd_list_element *command) | |
8189 | { | |
8190 | catch_load_or_unload (arg, from_tty, 0, command); | |
8191 | } | |
8192 | ||
be5c67c1 PA |
8193 | /* An instance of this type is used to represent a syscall catchpoint. |
8194 | It includes a "struct breakpoint" as a kind of base class; users | |
8195 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8196 | really of this type iff its ops pointer points to | |
8197 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8198 | ||
8199 | struct syscall_catchpoint | |
8200 | { | |
8201 | /* The base class. */ | |
8202 | struct breakpoint base; | |
8203 | ||
8204 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8205 | syscall has been specified for filtering, its value is NULL. | |
8206 | Otherwise, it holds a list of all syscalls to be caught. The | |
8207 | list elements are allocated with xmalloc. */ | |
8208 | VEC(int) *syscalls_to_be_caught; | |
8209 | }; | |
8210 | ||
8211 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8212 | catchpoints. */ | |
8213 | ||
8214 | static void | |
8215 | dtor_catch_syscall (struct breakpoint *b) | |
8216 | { | |
8217 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8218 | ||
8219 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8220 | |
2060206e | 8221 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8222 | } |
8223 | ||
fa3064dd YQ |
8224 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8225 | ||
8226 | struct catch_syscall_inferior_data | |
8227 | { | |
8228 | /* We keep a count of the number of times the user has requested a | |
8229 | particular syscall to be tracked, and pass this information to the | |
8230 | target. This lets capable targets implement filtering directly. */ | |
8231 | ||
8232 | /* Number of times that "any" syscall is requested. */ | |
8233 | int any_syscall_count; | |
8234 | ||
8235 | /* Count of each system call. */ | |
8236 | VEC(int) *syscalls_counts; | |
8237 | ||
8238 | /* This counts all syscall catch requests, so we can readily determine | |
8239 | if any catching is necessary. */ | |
8240 | int total_syscalls_count; | |
8241 | }; | |
8242 | ||
8243 | static struct catch_syscall_inferior_data* | |
8244 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8245 | { | |
8246 | struct catch_syscall_inferior_data *inf_data; | |
8247 | ||
8248 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8249 | if (inf_data == NULL) | |
8250 | { | |
41bf6aca | 8251 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8252 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8253 | } | |
8254 | ||
8255 | return inf_data; | |
8256 | } | |
8257 | ||
8258 | static void | |
8259 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8260 | { | |
8261 | xfree (arg); | |
8262 | } | |
8263 | ||
8264 | ||
a96d9b2e SDJ |
8265 | /* Implement the "insert" breakpoint_ops method for syscall |
8266 | catchpoints. */ | |
8267 | ||
77b06cd7 TJB |
8268 | static int |
8269 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8270 | { |
be5c67c1 | 8271 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8272 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8273 | struct catch_syscall_inferior_data *inf_data |
8274 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8275 | |
fa3064dd | 8276 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8277 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8278 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8279 | else |
8280 | { | |
8281 | int i, iter; | |
cc59ec59 | 8282 | |
a96d9b2e | 8283 | for (i = 0; |
be5c67c1 | 8284 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8285 | i++) |
8286 | { | |
8287 | int elem; | |
cc59ec59 | 8288 | |
fa3064dd | 8289 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8290 | { |
fa3064dd | 8291 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8292 | uintptr_t vec_addr_offset |
8293 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8294 | uintptr_t vec_addr; |
fa3064dd YQ |
8295 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8296 | vec_addr = ((uintptr_t) VEC_address (int, | |
8297 | inf_data->syscalls_counts) | |
8298 | + vec_addr_offset); | |
a96d9b2e SDJ |
8299 | memset ((void *) vec_addr, 0, |
8300 | (iter + 1 - old_size) * sizeof (int)); | |
8301 | } | |
fa3064dd YQ |
8302 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8303 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8304 | } |
8305 | } | |
8306 | ||
dfd4cc63 | 8307 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8308 | inf_data->total_syscalls_count != 0, |
8309 | inf_data->any_syscall_count, | |
8310 | VEC_length (int, | |
8311 | inf_data->syscalls_counts), | |
8312 | VEC_address (int, | |
8313 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8314 | } |
8315 | ||
8316 | /* Implement the "remove" breakpoint_ops method for syscall | |
8317 | catchpoints. */ | |
8318 | ||
8319 | static int | |
77b06cd7 | 8320 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8321 | { |
be5c67c1 | 8322 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8323 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8324 | struct catch_syscall_inferior_data *inf_data |
8325 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8326 | |
fa3064dd | 8327 | --inf_data->total_syscalls_count; |
be5c67c1 | 8328 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8329 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8330 | else |
8331 | { | |
8332 | int i, iter; | |
cc59ec59 | 8333 | |
a96d9b2e | 8334 | for (i = 0; |
be5c67c1 | 8335 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8336 | i++) |
8337 | { | |
8338 | int elem; | |
fa3064dd | 8339 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8340 | /* Shouldn't happen. */ |
8341 | continue; | |
fa3064dd YQ |
8342 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8343 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8344 | } |
8345 | } | |
8346 | ||
dfd4cc63 | 8347 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8348 | inf_data->total_syscalls_count != 0, |
8349 | inf_data->any_syscall_count, | |
8350 | VEC_length (int, | |
8351 | inf_data->syscalls_counts), | |
3e43a32a | 8352 | VEC_address (int, |
fa3064dd | 8353 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8354 | } |
8355 | ||
8356 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8357 | catchpoints. */ | |
8358 | ||
8359 | static int | |
f1310107 | 8360 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8361 | struct address_space *aspace, CORE_ADDR bp_addr, |
8362 | const struct target_waitstatus *ws) | |
a96d9b2e | 8363 | { |
4a64f543 MS |
8364 | /* We must check if we are catching specific syscalls in this |
8365 | breakpoint. If we are, then we must guarantee that the called | |
8366 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8367 | int syscall_number = 0; |
be5c67c1 PA |
8368 | const struct syscall_catchpoint *c |
8369 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8370 | |
f90263c1 TT |
8371 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8372 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8373 | return 0; |
8374 | ||
f90263c1 TT |
8375 | syscall_number = ws->value.syscall_number; |
8376 | ||
a96d9b2e | 8377 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8378 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8379 | { |
8380 | int i, iter; | |
cc59ec59 | 8381 | |
a96d9b2e | 8382 | for (i = 0; |
be5c67c1 | 8383 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8384 | i++) |
8385 | if (syscall_number == iter) | |
4924df79 GKB |
8386 | return 1; |
8387 | ||
8388 | return 0; | |
a96d9b2e SDJ |
8389 | } |
8390 | ||
8391 | return 1; | |
8392 | } | |
8393 | ||
8394 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8395 | catchpoints. */ | |
8396 | ||
8397 | static enum print_stop_action | |
348d480f | 8398 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8399 | { |
36dfb11c | 8400 | struct ui_out *uiout = current_uiout; |
348d480f | 8401 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8402 | /* These are needed because we want to know in which state a |
8403 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8404 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8405 | must print "called syscall" or "returned from syscall". */ | |
8406 | ptid_t ptid; | |
8407 | struct target_waitstatus last; | |
8408 | struct syscall s; | |
a96d9b2e SDJ |
8409 | |
8410 | get_last_target_status (&ptid, &last); | |
8411 | ||
8412 | get_syscall_by_number (last.value.syscall_number, &s); | |
8413 | ||
8414 | annotate_catchpoint (b->number); | |
8415 | ||
36dfb11c TT |
8416 | if (b->disposition == disp_del) |
8417 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8418 | else |
36dfb11c TT |
8419 | ui_out_text (uiout, "\nCatchpoint "); |
8420 | if (ui_out_is_mi_like_p (uiout)) | |
8421 | { | |
8422 | ui_out_field_string (uiout, "reason", | |
8423 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8424 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8425 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8426 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8427 | } | |
8428 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8429 | |
8430 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8431 | ui_out_text (uiout, " (call to syscall "); |
8432 | else | |
8433 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8434 | |
36dfb11c TT |
8435 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8436 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8437 | if (s.name != NULL) | |
8438 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8439 | ||
8440 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8441 | |
8442 | return PRINT_SRC_AND_LOC; | |
8443 | } | |
8444 | ||
8445 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8446 | catchpoints. */ | |
8447 | ||
8448 | static void | |
8449 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8450 | struct bp_location **last_loc) |
a96d9b2e | 8451 | { |
be5c67c1 | 8452 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8453 | struct value_print_options opts; |
79a45e25 | 8454 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8455 | |
8456 | get_user_print_options (&opts); | |
4a64f543 MS |
8457 | /* Field 4, the address, is omitted (which makes the columns not |
8458 | line up too nicely with the headers, but the effect is relatively | |
8459 | readable). */ | |
a96d9b2e SDJ |
8460 | if (opts.addressprint) |
8461 | ui_out_field_skip (uiout, "addr"); | |
8462 | annotate_field (5); | |
8463 | ||
be5c67c1 PA |
8464 | if (c->syscalls_to_be_caught |
8465 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8466 | ui_out_text (uiout, "syscalls \""); |
8467 | else | |
8468 | ui_out_text (uiout, "syscall \""); | |
8469 | ||
be5c67c1 | 8470 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8471 | { |
8472 | int i, iter; | |
8473 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8474 | |
a96d9b2e | 8475 | for (i = 0; |
be5c67c1 | 8476 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8477 | i++) |
8478 | { | |
8479 | char *x = text; | |
8480 | struct syscall s; | |
8481 | get_syscall_by_number (iter, &s); | |
8482 | ||
8483 | if (s.name != NULL) | |
8484 | text = xstrprintf ("%s%s, ", text, s.name); | |
8485 | else | |
8486 | text = xstrprintf ("%s%d, ", text, iter); | |
8487 | ||
8488 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8489 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8490 | on every call. */ |
8491 | xfree (x); | |
8492 | } | |
8493 | /* Remove the last comma. */ | |
8494 | text[strlen (text) - 2] = '\0'; | |
8495 | ui_out_field_string (uiout, "what", text); | |
8496 | } | |
8497 | else | |
8498 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8499 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8500 | |
8501 | if (ui_out_is_mi_like_p (uiout)) | |
8502 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8503 | } |
8504 | ||
8505 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8506 | catchpoints. */ | |
8507 | ||
8508 | static void | |
8509 | print_mention_catch_syscall (struct breakpoint *b) | |
8510 | { | |
be5c67c1 PA |
8511 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8512 | ||
8513 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8514 | { |
8515 | int i, iter; | |
8516 | ||
be5c67c1 | 8517 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8518 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8519 | else | |
8520 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8521 | ||
8522 | for (i = 0; | |
be5c67c1 | 8523 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8524 | i++) |
8525 | { | |
8526 | struct syscall s; | |
8527 | get_syscall_by_number (iter, &s); | |
8528 | ||
8529 | if (s.name) | |
8530 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8531 | else | |
8532 | printf_filtered (" %d", s.number); | |
8533 | } | |
8534 | printf_filtered (")"); | |
8535 | } | |
8536 | else | |
8537 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8538 | b->number); | |
8539 | } | |
8540 | ||
6149aea9 PA |
8541 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8542 | catchpoints. */ | |
8543 | ||
8544 | static void | |
8545 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8546 | { | |
be5c67c1 PA |
8547 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8548 | ||
6149aea9 PA |
8549 | fprintf_unfiltered (fp, "catch syscall"); |
8550 | ||
be5c67c1 | 8551 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8552 | { |
8553 | int i, iter; | |
8554 | ||
8555 | for (i = 0; | |
be5c67c1 | 8556 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8557 | i++) |
8558 | { | |
8559 | struct syscall s; | |
8560 | ||
8561 | get_syscall_by_number (iter, &s); | |
8562 | if (s.name) | |
8563 | fprintf_unfiltered (fp, " %s", s.name); | |
8564 | else | |
8565 | fprintf_unfiltered (fp, " %d", s.number); | |
8566 | } | |
8567 | } | |
d9b3f62e | 8568 | print_recreate_thread (b, fp); |
6149aea9 PA |
8569 | } |
8570 | ||
a96d9b2e SDJ |
8571 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8572 | ||
2060206e | 8573 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8574 | |
8575 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8576 | ||
8577 | static int | |
8578 | syscall_catchpoint_p (struct breakpoint *b) | |
8579 | { | |
8580 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8581 | } | |
8582 | ||
346774a9 PA |
8583 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8584 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8585 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8586 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8587 | |
ab04a2af | 8588 | void |
346774a9 PA |
8589 | init_catchpoint (struct breakpoint *b, |
8590 | struct gdbarch *gdbarch, int tempflag, | |
8591 | char *cond_string, | |
c0a91b2b | 8592 | const struct breakpoint_ops *ops) |
c906108c | 8593 | { |
c5aa993b | 8594 | struct symtab_and_line sal; |
346774a9 | 8595 | |
fe39c653 | 8596 | init_sal (&sal); |
6c95b8df | 8597 | sal.pspace = current_program_space; |
c5aa993b | 8598 | |
28010a5d | 8599 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8600 | |
1b36a34b | 8601 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8602 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8603 | } |
8604 | ||
28010a5d | 8605 | void |
3ea46bff | 8606 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8607 | { |
8608 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8609 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8610 | if (is_tracepoint (b)) |
8611 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8612 | if (!internal) |
8613 | mention (b); | |
c56053d2 | 8614 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8615 | |
8616 | if (update_gll) | |
8617 | update_global_location_list (1); | |
c56053d2 PA |
8618 | } |
8619 | ||
9b70b993 | 8620 | static void |
a6d9a66e UW |
8621 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8622 | int tempflag, char *cond_string, | |
c0a91b2b | 8623 | const struct breakpoint_ops *ops) |
c906108c | 8624 | { |
e29a4733 | 8625 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8626 | |
e29a4733 PA |
8627 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8628 | ||
8629 | c->forked_inferior_pid = null_ptid; | |
8630 | ||
3ea46bff | 8631 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8632 | } |
8633 | ||
fe798b75 JB |
8634 | /* Exec catchpoints. */ |
8635 | ||
b4d90040 PA |
8636 | /* An instance of this type is used to represent an exec catchpoint. |
8637 | It includes a "struct breakpoint" as a kind of base class; users | |
8638 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8639 | really of this type iff its ops pointer points to | |
8640 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8641 | ||
8642 | struct exec_catchpoint | |
8643 | { | |
8644 | /* The base class. */ | |
8645 | struct breakpoint base; | |
8646 | ||
8647 | /* Filename of a program whose exec triggered this catchpoint. | |
8648 | This field is only valid immediately after this catchpoint has | |
8649 | triggered. */ | |
8650 | char *exec_pathname; | |
8651 | }; | |
8652 | ||
8653 | /* Implement the "dtor" breakpoint_ops method for exec | |
8654 | catchpoints. */ | |
8655 | ||
8656 | static void | |
8657 | dtor_catch_exec (struct breakpoint *b) | |
8658 | { | |
8659 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8660 | ||
8661 | xfree (c->exec_pathname); | |
348d480f | 8662 | |
2060206e | 8663 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8664 | } |
8665 | ||
77b06cd7 TJB |
8666 | static int |
8667 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8668 | { |
dfd4cc63 | 8669 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8670 | } |
c906108c | 8671 | |
fe798b75 | 8672 | static int |
77b06cd7 | 8673 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8674 | { |
dfd4cc63 | 8675 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8676 | } |
c906108c | 8677 | |
fe798b75 | 8678 | static int |
f1310107 | 8679 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8680 | struct address_space *aspace, CORE_ADDR bp_addr, |
8681 | const struct target_waitstatus *ws) | |
fe798b75 | 8682 | { |
b4d90040 PA |
8683 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8684 | ||
f90263c1 TT |
8685 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8686 | return 0; | |
8687 | ||
8688 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8689 | return 1; | |
fe798b75 | 8690 | } |
c906108c | 8691 | |
fe798b75 | 8692 | static enum print_stop_action |
348d480f | 8693 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8694 | { |
36dfb11c | 8695 | struct ui_out *uiout = current_uiout; |
348d480f | 8696 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8697 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8698 | ||
fe798b75 | 8699 | annotate_catchpoint (b->number); |
36dfb11c TT |
8700 | if (b->disposition == disp_del) |
8701 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8702 | else | |
8703 | ui_out_text (uiout, "\nCatchpoint "); | |
8704 | if (ui_out_is_mi_like_p (uiout)) | |
8705 | { | |
8706 | ui_out_field_string (uiout, "reason", | |
8707 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8708 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8709 | } | |
8710 | ui_out_field_int (uiout, "bkptno", b->number); | |
8711 | ui_out_text (uiout, " (exec'd "); | |
8712 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8713 | ui_out_text (uiout, "), "); | |
8714 | ||
fe798b75 | 8715 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8716 | } |
8717 | ||
fe798b75 | 8718 | static void |
a6d9a66e | 8719 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8720 | { |
b4d90040 | 8721 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8722 | struct value_print_options opts; |
79a45e25 | 8723 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8724 | |
8725 | get_user_print_options (&opts); | |
8726 | ||
8727 | /* Field 4, the address, is omitted (which makes the columns | |
8728 | not line up too nicely with the headers, but the effect | |
8729 | is relatively readable). */ | |
8730 | if (opts.addressprint) | |
8731 | ui_out_field_skip (uiout, "addr"); | |
8732 | annotate_field (5); | |
8733 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8734 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8735 | { |
8736 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8737 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8738 | ui_out_text (uiout, "\" "); |
8739 | } | |
8ac3646f TT |
8740 | |
8741 | if (ui_out_is_mi_like_p (uiout)) | |
8742 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8743 | } |
8744 | ||
8745 | static void | |
8746 | print_mention_catch_exec (struct breakpoint *b) | |
8747 | { | |
8748 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8749 | } | |
8750 | ||
6149aea9 PA |
8751 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8752 | catchpoints. */ | |
8753 | ||
8754 | static void | |
8755 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8756 | { | |
8757 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8758 | print_recreate_thread (b, fp); |
6149aea9 PA |
8759 | } |
8760 | ||
2060206e | 8761 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8762 | |
a96d9b2e SDJ |
8763 | static void |
8764 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8765 | const struct breakpoint_ops *ops) |
a96d9b2e | 8766 | { |
be5c67c1 | 8767 | struct syscall_catchpoint *c; |
a96d9b2e | 8768 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8769 | |
be5c67c1 PA |
8770 | c = XNEW (struct syscall_catchpoint); |
8771 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8772 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8773 | |
3ea46bff | 8774 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8775 | } |
8776 | ||
c906108c | 8777 | static int |
fba45db2 | 8778 | hw_breakpoint_used_count (void) |
c906108c | 8779 | { |
c906108c | 8780 | int i = 0; |
f1310107 TJB |
8781 | struct breakpoint *b; |
8782 | struct bp_location *bl; | |
c906108c SS |
8783 | |
8784 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8785 | { |
d6b74ac4 | 8786 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8787 | for (bl = b->loc; bl; bl = bl->next) |
8788 | { | |
8789 | /* Special types of hardware breakpoints may use more than | |
8790 | one register. */ | |
348d480f | 8791 | i += b->ops->resources_needed (bl); |
f1310107 | 8792 | } |
c5aa993b | 8793 | } |
c906108c SS |
8794 | |
8795 | return i; | |
8796 | } | |
8797 | ||
a1398e0c PA |
8798 | /* Returns the resources B would use if it were a hardware |
8799 | watchpoint. */ | |
8800 | ||
c906108c | 8801 | static int |
a1398e0c | 8802 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8803 | { |
c906108c | 8804 | int i = 0; |
e09342b5 | 8805 | struct bp_location *bl; |
c906108c | 8806 | |
a1398e0c PA |
8807 | if (!breakpoint_enabled (b)) |
8808 | return 0; | |
8809 | ||
8810 | for (bl = b->loc; bl; bl = bl->next) | |
8811 | { | |
8812 | /* Special types of hardware watchpoints may use more than | |
8813 | one register. */ | |
8814 | i += b->ops->resources_needed (bl); | |
8815 | } | |
8816 | ||
8817 | return i; | |
8818 | } | |
8819 | ||
8820 | /* Returns the sum the used resources of all hardware watchpoints of | |
8821 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8822 | the sum of the used resources of all hardware watchpoints of other | |
8823 | types _not_ TYPE. */ | |
8824 | ||
8825 | static int | |
8826 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8827 | enum bptype type, int *other_type_used) | |
8828 | { | |
8829 | int i = 0; | |
8830 | struct breakpoint *b; | |
8831 | ||
c906108c SS |
8832 | *other_type_used = 0; |
8833 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8834 | { |
a1398e0c PA |
8835 | if (b == except) |
8836 | continue; | |
e09342b5 TJB |
8837 | if (!breakpoint_enabled (b)) |
8838 | continue; | |
8839 | ||
a1398e0c PA |
8840 | if (b->type == type) |
8841 | i += hw_watchpoint_use_count (b); | |
8842 | else if (is_hardware_watchpoint (b)) | |
8843 | *other_type_used = 1; | |
e09342b5 TJB |
8844 | } |
8845 | ||
c906108c SS |
8846 | return i; |
8847 | } | |
8848 | ||
c906108c | 8849 | void |
fba45db2 | 8850 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8851 | { |
c5aa993b | 8852 | struct breakpoint *b; |
c906108c SS |
8853 | |
8854 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8855 | { |
cc60f2e3 | 8856 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8857 | { |
b5de0fa7 | 8858 | b->enable_state = bp_call_disabled; |
b60e7edf | 8859 | update_global_location_list (0); |
c5aa993b JM |
8860 | } |
8861 | } | |
c906108c SS |
8862 | } |
8863 | ||
8864 | void | |
fba45db2 | 8865 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8866 | { |
c5aa993b | 8867 | struct breakpoint *b; |
c906108c SS |
8868 | |
8869 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8870 | { |
cc60f2e3 | 8871 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8872 | { |
b5de0fa7 | 8873 | b->enable_state = bp_enabled; |
b60e7edf | 8874 | update_global_location_list (1); |
c5aa993b JM |
8875 | } |
8876 | } | |
c906108c SS |
8877 | } |
8878 | ||
8bea4e01 UW |
8879 | void |
8880 | disable_breakpoints_before_startup (void) | |
8881 | { | |
6c95b8df | 8882 | current_program_space->executing_startup = 1; |
f8eba3c6 | 8883 | update_global_location_list (0); |
8bea4e01 UW |
8884 | } |
8885 | ||
8886 | void | |
8887 | enable_breakpoints_after_startup (void) | |
8888 | { | |
6c95b8df | 8889 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8890 | breakpoint_re_set (); |
8bea4e01 UW |
8891 | } |
8892 | ||
c906108c SS |
8893 | |
8894 | /* Set a breakpoint that will evaporate an end of command | |
8895 | at address specified by SAL. | |
8896 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
8897 | ||
8898 | struct breakpoint * | |
a6d9a66e UW |
8899 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8900 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8901 | { |
52f0bd74 | 8902 | struct breakpoint *b; |
edb3359d | 8903 | |
193facb3 JK |
8904 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8905 | tail-called one. */ | |
8906 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8907 | |
06edf0c0 | 8908 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8909 | b->enable_state = bp_enabled; |
8910 | b->disposition = disp_donttouch; | |
818dd999 | 8911 | b->frame_id = frame_id; |
c906108c | 8912 | |
4a64f543 MS |
8913 | /* If we're debugging a multi-threaded program, then we want |
8914 | momentary breakpoints to be active in only a single thread of | |
8915 | control. */ | |
39f77062 KB |
8916 | if (in_thread_list (inferior_ptid)) |
8917 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8918 | |
b60e7edf | 8919 | update_global_location_list_nothrow (1); |
74960c60 | 8920 | |
c906108c SS |
8921 | return b; |
8922 | } | |
611c83ae | 8923 | |
06edf0c0 PA |
8924 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
8925 | The new breakpoint will have type TYPE, and use OPS as it | |
8926 | breakpoint_ops. */ | |
e58b0e63 | 8927 | |
06edf0c0 PA |
8928 | static struct breakpoint * |
8929 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8930 | enum bptype type, | |
c0a91b2b | 8931 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
8932 | { |
8933 | struct breakpoint *copy; | |
8934 | ||
06edf0c0 | 8935 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8936 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8937 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8938 | |
a6d9a66e | 8939 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8940 | copy->loc->requested_address = orig->loc->requested_address; |
8941 | copy->loc->address = orig->loc->address; | |
8942 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8943 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8944 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8945 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8946 | copy->loc->symtab = orig->loc->symtab; |
e58b0e63 PA |
8947 | copy->frame_id = orig->frame_id; |
8948 | copy->thread = orig->thread; | |
6c95b8df | 8949 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8950 | |
8951 | copy->enable_state = bp_enabled; | |
8952 | copy->disposition = disp_donttouch; | |
8953 | copy->number = internal_breakpoint_number--; | |
8954 | ||
8955 | update_global_location_list_nothrow (0); | |
8956 | return copy; | |
8957 | } | |
8958 | ||
06edf0c0 PA |
8959 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8960 | ORIG is NULL. */ | |
8961 | ||
8962 | struct breakpoint * | |
8963 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8964 | { | |
8965 | /* If there's nothing to clone, then return nothing. */ | |
8966 | if (orig == NULL) | |
8967 | return NULL; | |
8968 | ||
8969 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
8970 | } | |
8971 | ||
611c83ae | 8972 | struct breakpoint * |
a6d9a66e UW |
8973 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8974 | enum bptype type) | |
611c83ae PA |
8975 | { |
8976 | struct symtab_and_line sal; | |
8977 | ||
8978 | sal = find_pc_line (pc, 0); | |
8979 | sal.pc = pc; | |
8980 | sal.section = find_pc_overlay (pc); | |
8981 | sal.explicit_pc = 1; | |
8982 | ||
a6d9a66e | 8983 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8984 | } |
c906108c | 8985 | \f |
c5aa993b | 8986 | |
c906108c SS |
8987 | /* Tell the user we have just set a breakpoint B. */ |
8988 | ||
8989 | static void | |
fba45db2 | 8990 | mention (struct breakpoint *b) |
c906108c | 8991 | { |
348d480f | 8992 | b->ops->print_mention (b); |
79a45e25 | 8993 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8994 | return; |
c906108c SS |
8995 | printf_filtered ("\n"); |
8996 | } | |
c906108c | 8997 | \f |
c5aa993b | 8998 | |
0d381245 | 8999 | static struct bp_location * |
39d61571 | 9000 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9001 | const struct symtab_and_line *sal) |
9002 | { | |
9003 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9004 | CORE_ADDR adjusted_address; |
9005 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9006 | ||
9007 | if (loc_gdbarch == NULL) | |
9008 | loc_gdbarch = b->gdbarch; | |
9009 | ||
9010 | /* Adjust the breakpoint's address prior to allocating a location. | |
9011 | Once we call allocate_bp_location(), that mostly uninitialized | |
9012 | location will be placed on the location chain. Adjustment of the | |
9013 | breakpoint may cause target_read_memory() to be called and we do | |
9014 | not want its scan of the location chain to find a breakpoint and | |
9015 | location that's only been partially initialized. */ | |
9016 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9017 | sal->pc, b->type); | |
0d381245 | 9018 | |
d30113d4 | 9019 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9020 | loc = allocate_bp_location (b); |
d30113d4 JK |
9021 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9022 | tmp = &((*tmp)->next)) | |
0d381245 | 9023 | ; |
d30113d4 | 9024 | loc->next = *tmp; |
0d381245 | 9025 | *tmp = loc; |
3742cc8b | 9026 | |
0d381245 | 9027 | loc->requested_address = sal->pc; |
3742cc8b | 9028 | loc->address = adjusted_address; |
6c95b8df | 9029 | loc->pspace = sal->pspace; |
729662a5 TT |
9030 | loc->probe.probe = sal->probe; |
9031 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9032 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9033 | loc->section = sal->section; |
3742cc8b | 9034 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9035 | loc->line_number = sal->line; |
2f202fde | 9036 | loc->symtab = sal->symtab; |
f8eba3c6 | 9037 | |
0e30163f JK |
9038 | set_breakpoint_location_function (loc, |
9039 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
9040 | return loc; |
9041 | } | |
514f746b AR |
9042 | \f |
9043 | ||
9044 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9045 | return 0 otherwise. */ | |
9046 | ||
9047 | static int | |
9048 | bp_loc_is_permanent (struct bp_location *loc) | |
9049 | { | |
9050 | int len; | |
9051 | CORE_ADDR addr; | |
1afeeb75 | 9052 | const gdb_byte *bpoint; |
514f746b | 9053 | gdb_byte *target_mem; |
939c61fa JK |
9054 | struct cleanup *cleanup; |
9055 | int retval = 0; | |
514f746b AR |
9056 | |
9057 | gdb_assert (loc != NULL); | |
9058 | ||
9059 | addr = loc->address; | |
1afeeb75 | 9060 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9061 | |
939c61fa | 9062 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9063 | if (bpoint == NULL) |
939c61fa JK |
9064 | return 0; |
9065 | ||
514f746b AR |
9066 | target_mem = alloca (len); |
9067 | ||
939c61fa JK |
9068 | /* Enable the automatic memory restoration from breakpoints while |
9069 | we read the memory. Otherwise we could say about our temporary | |
9070 | breakpoints they are permanent. */ | |
6c95b8df PA |
9071 | cleanup = save_current_space_and_thread (); |
9072 | ||
9073 | switch_to_program_space_and_thread (loc->pspace); | |
9074 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9075 | |
514f746b | 9076 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9077 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9078 | retval = 1; |
514f746b | 9079 | |
939c61fa JK |
9080 | do_cleanups (cleanup); |
9081 | ||
9082 | return retval; | |
514f746b AR |
9083 | } |
9084 | ||
e7e0cddf SS |
9085 | /* Build a command list for the dprintf corresponding to the current |
9086 | settings of the dprintf style options. */ | |
9087 | ||
9088 | static void | |
9089 | update_dprintf_command_list (struct breakpoint *b) | |
9090 | { | |
9091 | char *dprintf_args = b->extra_string; | |
9092 | char *printf_line = NULL; | |
9093 | ||
9094 | if (!dprintf_args) | |
9095 | return; | |
9096 | ||
9097 | dprintf_args = skip_spaces (dprintf_args); | |
9098 | ||
9099 | /* Allow a comma, as it may have terminated a location, but don't | |
9100 | insist on it. */ | |
9101 | if (*dprintf_args == ',') | |
9102 | ++dprintf_args; | |
9103 | dprintf_args = skip_spaces (dprintf_args); | |
9104 | ||
9105 | if (*dprintf_args != '"') | |
9106 | error (_("Bad format string, missing '\"'.")); | |
9107 | ||
d3ce09f5 | 9108 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9109 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9110 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9111 | { |
9112 | if (!dprintf_function) | |
9113 | error (_("No function supplied for dprintf call")); | |
9114 | ||
9115 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9116 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9117 | dprintf_function, | |
9118 | dprintf_channel, | |
9119 | dprintf_args); | |
9120 | else | |
9121 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9122 | dprintf_function, | |
9123 | dprintf_args); | |
9124 | } | |
d3ce09f5 SS |
9125 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9126 | { | |
9127 | if (target_can_run_breakpoint_commands ()) | |
9128 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9129 | else | |
9130 | { | |
9131 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9132 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9133 | } | |
9134 | } | |
e7e0cddf SS |
9135 | else |
9136 | internal_error (__FILE__, __LINE__, | |
9137 | _("Invalid dprintf style.")); | |
9138 | ||
f28045c2 | 9139 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9140 | /* Manufacture a printf sequence. */ |
f28045c2 | 9141 | { |
9d6e6e84 HZ |
9142 | struct command_line *printf_cmd_line |
9143 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9144 | |
f28045c2 YQ |
9145 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9146 | printf_cmd_line->control_type = simple_control; | |
9147 | printf_cmd_line->body_count = 0; | |
9148 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9149 | printf_cmd_line->next = NULL; |
f28045c2 | 9150 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9151 | |
f28045c2 YQ |
9152 | breakpoint_set_commands (b, printf_cmd_line); |
9153 | } | |
e7e0cddf SS |
9154 | } |
9155 | ||
9156 | /* Update all dprintf commands, making their command lists reflect | |
9157 | current style settings. */ | |
9158 | ||
9159 | static void | |
9160 | update_dprintf_commands (char *args, int from_tty, | |
9161 | struct cmd_list_element *c) | |
9162 | { | |
9163 | struct breakpoint *b; | |
9164 | ||
9165 | ALL_BREAKPOINTS (b) | |
9166 | { | |
9167 | if (b->type == bp_dprintf) | |
9168 | update_dprintf_command_list (b); | |
9169 | } | |
9170 | } | |
c3f6f71d | 9171 | |
018d34a4 VP |
9172 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9173 | as textual description of the location, and COND_STRING | |
db107f19 | 9174 | as condition expression. */ |
018d34a4 VP |
9175 | |
9176 | static void | |
d9b3f62e PA |
9177 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9178 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9179 | char *filter, char *cond_string, |
e7e0cddf | 9180 | char *extra_string, |
d9b3f62e PA |
9181 | enum bptype type, enum bpdisp disposition, |
9182 | int thread, int task, int ignore_count, | |
c0a91b2b | 9183 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9184 | int enabled, int internal, unsigned flags, |
9185 | int display_canonical) | |
018d34a4 | 9186 | { |
0d381245 | 9187 | int i; |
018d34a4 VP |
9188 | |
9189 | if (type == bp_hardware_breakpoint) | |
9190 | { | |
fbbd034e AS |
9191 | int target_resources_ok; |
9192 | ||
9193 | i = hw_breakpoint_used_count (); | |
9194 | target_resources_ok = | |
9195 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9196 | i + 1, 0); |
9197 | if (target_resources_ok == 0) | |
9198 | error (_("No hardware breakpoint support in the target.")); | |
9199 | else if (target_resources_ok < 0) | |
9200 | error (_("Hardware breakpoints used exceeds limit.")); | |
9201 | } | |
9202 | ||
6c95b8df PA |
9203 | gdb_assert (sals.nelts > 0); |
9204 | ||
0d381245 VP |
9205 | for (i = 0; i < sals.nelts; ++i) |
9206 | { | |
9207 | struct symtab_and_line sal = sals.sals[i]; | |
9208 | struct bp_location *loc; | |
9209 | ||
9210 | if (from_tty) | |
5af949e3 UW |
9211 | { |
9212 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9213 | if (!loc_gdbarch) | |
9214 | loc_gdbarch = gdbarch; | |
9215 | ||
9216 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9217 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9218 | } |
0d381245 VP |
9219 | |
9220 | if (i == 0) | |
9221 | { | |
d9b3f62e | 9222 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9223 | b->thread = thread; |
4a306c9a | 9224 | b->task = task; |
855a6e68 | 9225 | |
0d381245 | 9226 | b->cond_string = cond_string; |
e7e0cddf | 9227 | b->extra_string = extra_string; |
0d381245 | 9228 | b->ignore_count = ignore_count; |
41447f92 | 9229 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9230 | b->disposition = disposition; |
6c95b8df | 9231 | |
44f238bb PA |
9232 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9233 | b->loc->inserted = 1; | |
9234 | ||
0fb4aa4b PA |
9235 | if (type == bp_static_tracepoint) |
9236 | { | |
d9b3f62e | 9237 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9238 | struct static_tracepoint_marker marker; |
9239 | ||
983af33b | 9240 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9241 | { |
9242 | /* We already know the marker exists, otherwise, we | |
9243 | wouldn't see a sal for it. */ | |
9244 | char *p = &addr_string[3]; | |
9245 | char *endp; | |
9246 | char *marker_str; | |
0fb4aa4b | 9247 | |
e9cafbcc | 9248 | p = skip_spaces (p); |
0fb4aa4b | 9249 | |
e9cafbcc | 9250 | endp = skip_to_space (p); |
0fb4aa4b PA |
9251 | |
9252 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9253 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9254 | |
3e43a32a MS |
9255 | printf_filtered (_("Probed static tracepoint " |
9256 | "marker \"%s\"\n"), | |
d9b3f62e | 9257 | t->static_trace_marker_id); |
0fb4aa4b PA |
9258 | } |
9259 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9260 | { | |
d9b3f62e | 9261 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9262 | release_static_tracepoint_marker (&marker); |
9263 | ||
3e43a32a MS |
9264 | printf_filtered (_("Probed static tracepoint " |
9265 | "marker \"%s\"\n"), | |
d9b3f62e | 9266 | t->static_trace_marker_id); |
0fb4aa4b PA |
9267 | } |
9268 | else | |
3e43a32a MS |
9269 | warning (_("Couldn't determine the static " |
9270 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9271 | } |
9272 | ||
0d381245 VP |
9273 | loc = b->loc; |
9274 | } | |
9275 | else | |
018d34a4 | 9276 | { |
39d61571 | 9277 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9278 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9279 | loc->inserted = 1; | |
0d381245 VP |
9280 | } |
9281 | ||
514f746b AR |
9282 | if (bp_loc_is_permanent (loc)) |
9283 | make_breakpoint_permanent (b); | |
9284 | ||
0d381245 VP |
9285 | if (b->cond_string) |
9286 | { | |
bbc13ae3 KS |
9287 | const char *arg = b->cond_string; |
9288 | ||
1bb9788d TT |
9289 | loc->cond = parse_exp_1 (&arg, loc->address, |
9290 | block_for_pc (loc->address), 0); | |
0d381245 | 9291 | if (*arg) |
588ae58c | 9292 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9293 | } |
e7e0cddf SS |
9294 | |
9295 | /* Dynamic printf requires and uses additional arguments on the | |
9296 | command line, otherwise it's an error. */ | |
9297 | if (type == bp_dprintf) | |
9298 | { | |
9299 | if (b->extra_string) | |
9300 | update_dprintf_command_list (b); | |
9301 | else | |
9302 | error (_("Format string required")); | |
9303 | } | |
9304 | else if (b->extra_string) | |
588ae58c | 9305 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9306 | } |
018d34a4 | 9307 | |
56435ebe | 9308 | b->display_canonical = display_canonical; |
018d34a4 VP |
9309 | if (addr_string) |
9310 | b->addr_string = addr_string; | |
9311 | else | |
9312 | /* addr_string has to be used or breakpoint_re_set will delete | |
9313 | me. */ | |
5af949e3 UW |
9314 | b->addr_string |
9315 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9316 | b->filter = filter; |
d9b3f62e | 9317 | } |
018d34a4 | 9318 | |
d9b3f62e PA |
9319 | static void |
9320 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9321 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9322 | char *filter, char *cond_string, |
e7e0cddf | 9323 | char *extra_string, |
d9b3f62e PA |
9324 | enum bptype type, enum bpdisp disposition, |
9325 | int thread, int task, int ignore_count, | |
c0a91b2b | 9326 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9327 | int enabled, int internal, unsigned flags, |
9328 | int display_canonical) | |
d9b3f62e PA |
9329 | { |
9330 | struct breakpoint *b; | |
9331 | struct cleanup *old_chain; | |
9332 | ||
9333 | if (is_tracepoint_type (type)) | |
9334 | { | |
9335 | struct tracepoint *t; | |
9336 | ||
9337 | t = XCNEW (struct tracepoint); | |
9338 | b = &t->base; | |
9339 | } | |
9340 | else | |
9341 | b = XNEW (struct breakpoint); | |
9342 | ||
9343 | old_chain = make_cleanup (xfree, b); | |
9344 | ||
9345 | init_breakpoint_sal (b, gdbarch, | |
9346 | sals, addr_string, | |
e7e0cddf | 9347 | filter, cond_string, extra_string, |
d9b3f62e PA |
9348 | type, disposition, |
9349 | thread, task, ignore_count, | |
9350 | ops, from_tty, | |
44f238bb PA |
9351 | enabled, internal, flags, |
9352 | display_canonical); | |
d9b3f62e PA |
9353 | discard_cleanups (old_chain); |
9354 | ||
3ea46bff | 9355 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9356 | } |
9357 | ||
9358 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9359 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9360 | value. COND_STRING, if not NULL, specified the condition to be | |
9361 | used for all breakpoints. Essentially the only case where | |
9362 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9363 | function. In that case, it's still not possible to specify | |
9364 | separate conditions for different overloaded functions, so | |
9365 | we take just a single condition string. | |
9366 | ||
c3f6f71d | 9367 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9368 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9369 | array contents). If the function fails (error() is called), the |
9370 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9371 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9372 | |
9373 | static void | |
8cdf0e15 | 9374 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9375 | struct linespec_result *canonical, |
e7e0cddf | 9376 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9377 | enum bptype type, enum bpdisp disposition, |
9378 | int thread, int task, int ignore_count, | |
c0a91b2b | 9379 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9380 | int enabled, int internal, unsigned flags) |
c906108c | 9381 | { |
018d34a4 | 9382 | int i; |
f8eba3c6 | 9383 | struct linespec_sals *lsal; |
cc59ec59 | 9384 | |
f8eba3c6 TT |
9385 | if (canonical->pre_expanded) |
9386 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9387 | ||
9388 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9389 | { |
f8eba3c6 TT |
9390 | /* Note that 'addr_string' can be NULL in the case of a plain |
9391 | 'break', without arguments. */ | |
9392 | char *addr_string = (canonical->addr_string | |
9393 | ? xstrdup (canonical->addr_string) | |
9394 | : NULL); | |
9395 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9396 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9397 | |
f8eba3c6 TT |
9398 | make_cleanup (xfree, filter_string); |
9399 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9400 | addr_string, | |
9401 | filter_string, | |
e7e0cddf SS |
9402 | cond_string, extra_string, |
9403 | type, disposition, | |
84f4c1fe | 9404 | thread, task, ignore_count, ops, |
44f238bb | 9405 | from_tty, enabled, internal, flags, |
56435ebe | 9406 | canonical->special_display); |
f8eba3c6 | 9407 | discard_cleanups (inner); |
c3f6f71d | 9408 | } |
c3f6f71d | 9409 | } |
c906108c | 9410 | |
9998af43 | 9411 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9412 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9413 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9414 | address strings. ADDRESS points to the end of the SAL. |
9415 | ||
9416 | The array and the line spec strings are allocated on the heap, it is | |
9417 | the caller's responsibility to free them. */ | |
c906108c | 9418 | |
b9362cc7 | 9419 | static void |
c3f6f71d | 9420 | parse_breakpoint_sals (char **address, |
58438ac1 | 9421 | struct linespec_result *canonical) |
c3f6f71d | 9422 | { |
c3f6f71d | 9423 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9424 | breakpoint. */ |
c3f6f71d JM |
9425 | if ((*address) == NULL |
9426 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9427 | { |
1bfeeb0f JL |
9428 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9429 | address. */ | |
9430 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9431 | { |
f8eba3c6 | 9432 | struct linespec_sals lsal; |
c3f6f71d | 9433 | struct symtab_and_line sal; |
1c8cdcb1 | 9434 | CORE_ADDR pc; |
cc59ec59 | 9435 | |
4a64f543 | 9436 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9437 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9438 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9439 | |
9440 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9441 | corresponding to the last call to print_frame_info. |
9442 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9443 | as the breakpoint line number is inappropriate otherwise. | |
9444 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9445 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9446 | pc = sal.pc; |
9447 | sal = find_pc_line (pc, 0); | |
00903456 | 9448 | |
4a64f543 | 9449 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9450 | where PC is the last displayed codepoint's address. So |
9451 | make sure to set sal.explicit_pc to prevent GDB from | |
9452 | trying to expand the list of sals to include all other | |
9453 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9454 | sal.pc = pc; |
00903456 JK |
9455 | sal.explicit_pc = 1; |
9456 | ||
f8eba3c6 TT |
9457 | lsal.sals.sals[0] = sal; |
9458 | lsal.sals.nelts = 1; | |
9459 | lsal.canonical = NULL; | |
9460 | ||
9461 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9462 | } |
9463 | else | |
8a3fe4f8 | 9464 | error (_("No default breakpoint address now.")); |
c906108c SS |
9465 | } |
9466 | else | |
9467 | { | |
cc80f267 JK |
9468 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9469 | ||
c906108c | 9470 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9471 | current_source_symtab (which is decode_line_1's default). |
9472 | This should produce the results we want almost all of the | |
cc80f267 JK |
9473 | time while leaving default_breakpoint_* alone. |
9474 | ||
9475 | ObjC: However, don't match an Objective-C method name which | |
9476 | may have a '+' or '-' succeeded by a '['. */ | |
9477 | if (last_displayed_sal_is_valid () | |
9478 | && (!cursal.symtab | |
9479 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9480 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9481 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9482 | get_last_displayed_symtab (), | |
9483 | get_last_displayed_line (), | |
9484 | canonical, NULL, NULL); | |
c906108c | 9485 | else |
f8eba3c6 | 9486 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9487 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9488 | } |
c3f6f71d | 9489 | } |
c906108c | 9490 | |
c906108c | 9491 | |
c3f6f71d | 9492 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9493 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9494 | |
b9362cc7 | 9495 | static void |
23e7acfb | 9496 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9497 | { |
9498 | int i; | |
cc59ec59 | 9499 | |
c3f6f71d | 9500 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9501 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9502 | } |
9503 | ||
7a697b8d SS |
9504 | /* Fast tracepoints may have restrictions on valid locations. For |
9505 | instance, a fast tracepoint using a jump instead of a trap will | |
9506 | likely have to overwrite more bytes than a trap would, and so can | |
9507 | only be placed where the instruction is longer than the jump, or a | |
9508 | multi-instruction sequence does not have a jump into the middle of | |
9509 | it, etc. */ | |
9510 | ||
9511 | static void | |
9512 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9513 | struct symtabs_and_lines *sals) | |
9514 | { | |
9515 | int i, rslt; | |
9516 | struct symtab_and_line *sal; | |
9517 | char *msg; | |
9518 | struct cleanup *old_chain; | |
9519 | ||
9520 | for (i = 0; i < sals->nelts; i++) | |
9521 | { | |
f8eba3c6 TT |
9522 | struct gdbarch *sarch; |
9523 | ||
7a697b8d SS |
9524 | sal = &sals->sals[i]; |
9525 | ||
f8eba3c6 TT |
9526 | sarch = get_sal_arch (*sal); |
9527 | /* We fall back to GDBARCH if there is no architecture | |
9528 | associated with SAL. */ | |
9529 | if (sarch == NULL) | |
9530 | sarch = gdbarch; | |
9531 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9532 | NULL, &msg); |
9533 | old_chain = make_cleanup (xfree, msg); | |
9534 | ||
9535 | if (!rslt) | |
9536 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9537 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9538 | |
9539 | do_cleanups (old_chain); | |
9540 | } | |
9541 | } | |
9542 | ||
af4908ba KS |
9543 | /* Issue an invalid thread ID error. */ |
9544 | ||
9545 | static void ATTRIBUTE_NORETURN | |
9546 | invalid_thread_id_error (int id) | |
9547 | { | |
9548 | error (_("Unknown thread %d."), id); | |
9549 | } | |
9550 | ||
018d34a4 VP |
9551 | /* Given TOK, a string specification of condition and thread, as |
9552 | accepted by the 'break' command, extract the condition | |
9553 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9554 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9555 | If no condition is found, *COND_STRING is set to NULL. |
9556 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9557 | |
9558 | static void | |
bbc13ae3 | 9559 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9560 | char **cond_string, int *thread, int *task, |
9561 | char **rest) | |
018d34a4 VP |
9562 | { |
9563 | *cond_string = NULL; | |
9564 | *thread = -1; | |
ed1d1739 KS |
9565 | *task = 0; |
9566 | *rest = NULL; | |
9567 | ||
018d34a4 VP |
9568 | while (tok && *tok) |
9569 | { | |
bbc13ae3 | 9570 | const char *end_tok; |
018d34a4 | 9571 | int toklen; |
bbc13ae3 KS |
9572 | const char *cond_start = NULL; |
9573 | const char *cond_end = NULL; | |
cc59ec59 | 9574 | |
bbc13ae3 | 9575 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9576 | |
9577 | if ((*tok == '"' || *tok == ',') && rest) | |
9578 | { | |
9579 | *rest = savestring (tok, strlen (tok)); | |
9580 | return; | |
9581 | } | |
9582 | ||
bbc13ae3 | 9583 | end_tok = skip_to_space_const (tok); |
d634f2de | 9584 | |
018d34a4 | 9585 | toklen = end_tok - tok; |
d634f2de | 9586 | |
018d34a4 VP |
9587 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9588 | { | |
f7545552 TT |
9589 | struct expression *expr; |
9590 | ||
018d34a4 | 9591 | tok = cond_start = end_tok + 1; |
1bb9788d | 9592 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9593 | xfree (expr); |
018d34a4 | 9594 | cond_end = tok; |
d634f2de | 9595 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9596 | } |
9597 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9598 | { | |
9599 | char *tmptok; | |
d634f2de | 9600 | |
018d34a4 | 9601 | tok = end_tok + 1; |
bbc13ae3 | 9602 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9603 | if (tok == tmptok) |
9604 | error (_("Junk after thread keyword.")); | |
9605 | if (!valid_thread_id (*thread)) | |
af4908ba | 9606 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9607 | tok = tmptok; |
018d34a4 | 9608 | } |
4a306c9a JB |
9609 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9610 | { | |
9611 | char *tmptok; | |
9612 | ||
9613 | tok = end_tok + 1; | |
bbc13ae3 | 9614 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9615 | if (tok == tmptok) |
9616 | error (_("Junk after task keyword.")); | |
9617 | if (!valid_task_id (*task)) | |
b6199126 | 9618 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9619 | tok = tmptok; |
4a306c9a | 9620 | } |
e7e0cddf SS |
9621 | else if (rest) |
9622 | { | |
9623 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9624 | return; |
e7e0cddf | 9625 | } |
018d34a4 VP |
9626 | else |
9627 | error (_("Junk at end of arguments.")); | |
9628 | } | |
9629 | } | |
9630 | ||
0fb4aa4b PA |
9631 | /* Decode a static tracepoint marker spec. */ |
9632 | ||
9633 | static struct symtabs_and_lines | |
9634 | decode_static_tracepoint_spec (char **arg_p) | |
9635 | { | |
9636 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9637 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9638 | struct cleanup *old_chain; |
9639 | char *p = &(*arg_p)[3]; | |
9640 | char *endp; | |
9641 | char *marker_str; | |
9642 | int i; | |
9643 | ||
e9cafbcc | 9644 | p = skip_spaces (p); |
0fb4aa4b | 9645 | |
e9cafbcc | 9646 | endp = skip_to_space (p); |
0fb4aa4b PA |
9647 | |
9648 | marker_str = savestring (p, endp - p); | |
9649 | old_chain = make_cleanup (xfree, marker_str); | |
9650 | ||
9651 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9652 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9653 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9654 | ||
9655 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9656 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9657 | ||
9658 | for (i = 0; i < sals.nelts; i++) | |
9659 | { | |
9660 | struct static_tracepoint_marker *marker; | |
9661 | ||
9662 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9663 | ||
9664 | init_sal (&sals.sals[i]); | |
9665 | ||
9666 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9667 | sals.sals[i].pc = marker->address; | |
9668 | ||
9669 | release_static_tracepoint_marker (marker); | |
9670 | } | |
9671 | ||
9672 | do_cleanups (old_chain); | |
9673 | ||
9674 | *arg_p = endp; | |
9675 | return sals; | |
9676 | } | |
9677 | ||
fd9b8c24 PA |
9678 | /* Set a breakpoint. This function is shared between CLI and MI |
9679 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9680 | modes of operations, selected by the PARSE_ARG parameter. If |
9681 | non-zero, the function will parse ARG, extracting location, | |
9682 | condition, thread and extra string. Otherwise, ARG is just the | |
9683 | breakpoint's location, with condition, thread, and extra string | |
9684 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9685 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9686 | from the internal breakpoint count. Returns true if any breakpoint | |
9687 | was created; false otherwise. */ | |
0101ce28 | 9688 | |
8cdf0e15 VP |
9689 | int |
9690 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9691 | char *arg, char *cond_string, |
9692 | int thread, char *extra_string, | |
f6de8ec2 | 9693 | int parse_arg, |
0fb4aa4b | 9694 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9695 | int ignore_count, |
9696 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9697 | const struct breakpoint_ops *ops, |
44f238bb PA |
9698 | int from_tty, int enabled, int internal, |
9699 | unsigned flags) | |
c3f6f71d | 9700 | { |
b78a6381 | 9701 | volatile struct gdb_exception e; |
f8eba3c6 | 9702 | char *copy_arg = NULL; |
c3f6f71d | 9703 | char *addr_start = arg; |
7efd8fc2 | 9704 | struct linespec_result canonical; |
c3f6f71d | 9705 | struct cleanup *old_chain; |
80c99de1 | 9706 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9707 | int pending = 0; |
4a306c9a | 9708 | int task = 0; |
86b17b60 | 9709 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9710 | |
348d480f PA |
9711 | gdb_assert (ops != NULL); |
9712 | ||
7efd8fc2 | 9713 | init_linespec_result (&canonical); |
c3f6f71d | 9714 | |
b78a6381 TT |
9715 | TRY_CATCH (e, RETURN_MASK_ALL) |
9716 | { | |
983af33b SDJ |
9717 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9718 | addr_start, ©_arg); | |
b78a6381 | 9719 | } |
0101ce28 JJ |
9720 | |
9721 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9722 | switch (e.reason) |
0101ce28 | 9723 | { |
983af33b SDJ |
9724 | case GDB_NO_ERROR: |
9725 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9726 | return 0; | |
9727 | break; | |
05ff989b AC |
9728 | case RETURN_ERROR: |
9729 | switch (e.error) | |
0101ce28 | 9730 | { |
05ff989b | 9731 | case NOT_FOUND_ERROR: |
0101ce28 | 9732 | |
05ff989b AC |
9733 | /* If pending breakpoint support is turned off, throw |
9734 | error. */ | |
fa8d40ab JJ |
9735 | |
9736 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9737 | throw_exception (e); |
9738 | ||
9739 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9740 | |
05ff989b AC |
9741 | /* If pending breakpoint support is auto query and the user |
9742 | selects no, then simply return the error code. */ | |
059fb39f | 9743 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9744 | && !nquery (_("Make %s pending on future shared library load? "), |
9745 | bptype_string (type_wanted))) | |
fd9b8c24 | 9746 | return 0; |
fa8d40ab | 9747 | |
05ff989b AC |
9748 | /* At this point, either the user was queried about setting |
9749 | a pending breakpoint and selected yes, or pending | |
9750 | breakpoint behavior is on and thus a pending breakpoint | |
9751 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9752 | { |
9753 | struct linespec_sals lsal; | |
9754 | ||
9755 | copy_arg = xstrdup (addr_start); | |
9756 | lsal.canonical = xstrdup (copy_arg); | |
9757 | lsal.sals.nelts = 1; | |
9758 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9759 | init_sal (&lsal.sals.sals[0]); | |
9760 | pending = 1; | |
9761 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9762 | } | |
05ff989b AC |
9763 | break; |
9764 | default: | |
98deb0da | 9765 | throw_exception (e); |
0101ce28 | 9766 | } |
2abae994 | 9767 | break; |
05ff989b | 9768 | default: |
983af33b | 9769 | throw_exception (e); |
0101ce28 | 9770 | } |
c3f6f71d | 9771 | |
4a64f543 | 9772 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9773 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9774 | |
c3f6f71d JM |
9775 | /* ----------------------------- SNIP ----------------------------- |
9776 | Anything added to the cleanup chain beyond this point is assumed | |
9777 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9778 | then the memory is not reclaimed. */ |
9779 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9780 | |
c3f6f71d JM |
9781 | /* Resolve all line numbers to PC's and verify that the addresses |
9782 | are ok for the target. */ | |
0101ce28 | 9783 | if (!pending) |
f8eba3c6 TT |
9784 | { |
9785 | int ix; | |
9786 | struct linespec_sals *iter; | |
9787 | ||
9788 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9789 | breakpoint_sals_to_pc (&iter->sals); | |
9790 | } | |
c3f6f71d | 9791 | |
7a697b8d | 9792 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9793 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9794 | { |
9795 | int ix; | |
9796 | struct linespec_sals *iter; | |
9797 | ||
9798 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9799 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9800 | } | |
7a697b8d | 9801 | |
c3f6f71d JM |
9802 | /* Verify that condition can be parsed, before setting any |
9803 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9804 | breakpoint. */ |
0101ce28 | 9805 | if (!pending) |
c3f6f71d | 9806 | { |
f6de8ec2 | 9807 | if (parse_arg) |
72b2ff0e | 9808 | { |
0878d0fa | 9809 | char *rest; |
52d361e1 YQ |
9810 | struct linespec_sals *lsal; |
9811 | ||
9812 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9813 | ||
0878d0fa YQ |
9814 | /* Here we only parse 'arg' to separate condition |
9815 | from thread number, so parsing in context of first | |
9816 | sal is OK. When setting the breakpoint we'll | |
9817 | re-parse it in context of each sal. */ | |
9818 | ||
9819 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9820 | &thread, &task, &rest); | |
9821 | if (cond_string) | |
9822 | make_cleanup (xfree, cond_string); | |
9823 | if (rest) | |
9824 | make_cleanup (xfree, rest); | |
9825 | if (rest) | |
9826 | extra_string = rest; | |
72b2ff0e | 9827 | } |
2f069f6f | 9828 | else |
72b2ff0e | 9829 | { |
0878d0fa YQ |
9830 | if (*arg != '\0') |
9831 | error (_("Garbage '%s' at end of location"), arg); | |
9832 | ||
9833 | /* Create a private copy of condition string. */ | |
9834 | if (cond_string) | |
9835 | { | |
9836 | cond_string = xstrdup (cond_string); | |
9837 | make_cleanup (xfree, cond_string); | |
9838 | } | |
9839 | /* Create a private copy of any extra string. */ | |
9840 | if (extra_string) | |
9841 | { | |
9842 | extra_string = xstrdup (extra_string); | |
9843 | make_cleanup (xfree, extra_string); | |
9844 | } | |
72b2ff0e | 9845 | } |
0fb4aa4b | 9846 | |
52d361e1 | 9847 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9848 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9849 | tempflag ? disp_del : disp_donttouch, |
9850 | thread, task, ignore_count, ops, | |
44f238bb | 9851 | from_tty, enabled, internal, flags); |
c906108c | 9852 | } |
0101ce28 JJ |
9853 | else |
9854 | { | |
0101ce28 JJ |
9855 | struct breakpoint *b; |
9856 | ||
0101ce28 JJ |
9857 | make_cleanup (xfree, copy_arg); |
9858 | ||
bfccc43c YQ |
9859 | if (is_tracepoint_type (type_wanted)) |
9860 | { | |
9861 | struct tracepoint *t; | |
9862 | ||
9863 | t = XCNEW (struct tracepoint); | |
9864 | b = &t->base; | |
9865 | } | |
9866 | else | |
9867 | b = XNEW (struct breakpoint); | |
9868 | ||
9869 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9870 | ||
f8eba3c6 | 9871 | b->addr_string = copy_arg; |
f6de8ec2 | 9872 | if (parse_arg) |
e12c7713 MK |
9873 | b->cond_string = NULL; |
9874 | else | |
9875 | { | |
9876 | /* Create a private copy of condition string. */ | |
9877 | if (cond_string) | |
9878 | { | |
9879 | cond_string = xstrdup (cond_string); | |
9880 | make_cleanup (xfree, cond_string); | |
9881 | } | |
9882 | b->cond_string = cond_string; | |
9883 | } | |
e7e0cddf | 9884 | b->extra_string = NULL; |
0101ce28 | 9885 | b->ignore_count = ignore_count; |
0101ce28 | 9886 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9887 | b->condition_not_parsed = 1; |
41447f92 | 9888 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9889 | if ((type_wanted != bp_breakpoint |
9890 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9891 | b->pspace = current_program_space; |
8bea4e01 | 9892 | |
bfccc43c | 9893 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9894 | } |
9895 | ||
f8eba3c6 | 9896 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9897 | { |
3e43a32a MS |
9898 | warning (_("Multiple breakpoints were set.\nUse the " |
9899 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9900 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9901 | } |
9902 | ||
80c99de1 PA |
9903 | /* That's it. Discard the cleanups for data inserted into the |
9904 | breakpoint. */ | |
9905 | discard_cleanups (bkpt_chain); | |
9906 | /* But cleanup everything else. */ | |
c3f6f71d | 9907 | do_cleanups (old_chain); |
217dc9e2 | 9908 | |
80c99de1 | 9909 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 9910 | update_global_location_list (1); |
fd9b8c24 PA |
9911 | |
9912 | return 1; | |
c3f6f71d | 9913 | } |
c906108c | 9914 | |
348d480f | 9915 | /* Set a breakpoint. |
72b2ff0e VP |
9916 | ARG is a string describing breakpoint address, |
9917 | condition, and thread. | |
9918 | FLAG specifies if a breakpoint is hardware on, | |
9919 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9920 | and BP_TEMPFLAG. */ | |
348d480f | 9921 | |
98deb0da | 9922 | static void |
72b2ff0e | 9923 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9924 | { |
72b2ff0e | 9925 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9926 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9927 | ? bp_hardware_breakpoint | |
9928 | : bp_breakpoint); | |
55aa24fb SDJ |
9929 | struct breakpoint_ops *ops; |
9930 | const char *arg_cp = arg; | |
9931 | ||
9932 | /* Matching breakpoints on probes. */ | |
9933 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9934 | ops = &bkpt_probe_breakpoint_ops; | |
9935 | else | |
9936 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9937 | |
8cdf0e15 VP |
9938 | create_breakpoint (get_current_arch (), |
9939 | arg, | |
e7e0cddf | 9940 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9941 | tempflag, type_wanted, |
8cdf0e15 VP |
9942 | 0 /* Ignore count */, |
9943 | pending_break_support, | |
55aa24fb | 9944 | ops, |
8cdf0e15 | 9945 | from_tty, |
84f4c1fe | 9946 | 1 /* enabled */, |
44f238bb PA |
9947 | 0 /* internal */, |
9948 | 0); | |
c906108c SS |
9949 | } |
9950 | ||
c906108c SS |
9951 | /* Helper function for break_command_1 and disassemble_command. */ |
9952 | ||
9953 | void | |
fba45db2 | 9954 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9955 | { |
9956 | CORE_ADDR pc; | |
9957 | ||
9958 | if (sal->pc == 0 && sal->symtab != NULL) | |
9959 | { | |
9960 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9961 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9962 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9963 | sal->pc = pc; |
6a048695 | 9964 | |
4a64f543 MS |
9965 | /* If this SAL corresponds to a breakpoint inserted using a line |
9966 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9967 | if (sal->explicit_line) |
059acae7 | 9968 | skip_prologue_sal (sal); |
c906108c SS |
9969 | } |
9970 | ||
9971 | if (sal->section == 0 && sal->symtab != NULL) | |
9972 | { | |
9973 | struct blockvector *bv; | |
c5aa993b JM |
9974 | struct block *b; |
9975 | struct symbol *sym; | |
c906108c | 9976 | |
801e3a5b | 9977 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
9978 | if (bv != NULL) |
9979 | { | |
7f0df278 | 9980 | sym = block_linkage_function (b); |
c906108c SS |
9981 | if (sym != NULL) |
9982 | { | |
9983 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 9984 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
9985 | } |
9986 | else | |
9987 | { | |
4a64f543 MS |
9988 | /* It really is worthwhile to have the section, so we'll |
9989 | just have to look harder. This case can be executed | |
9990 | if we have line numbers but no functions (as can | |
9991 | happen in assembly source). */ | |
c906108c | 9992 | |
7cbd4a93 | 9993 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9994 | struct cleanup *old_chain = save_current_space_and_thread (); |
9995 | ||
9996 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9997 | |
9998 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9999 | if (msym.minsym) |
efd66ac6 | 10000 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10001 | |
10002 | do_cleanups (old_chain); | |
c906108c SS |
10003 | } |
10004 | } | |
10005 | } | |
10006 | } | |
10007 | ||
10008 | void | |
fba45db2 | 10009 | break_command (char *arg, int from_tty) |
c906108c | 10010 | { |
db107f19 | 10011 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10012 | } |
10013 | ||
c906108c | 10014 | void |
fba45db2 | 10015 | tbreak_command (char *arg, int from_tty) |
c906108c | 10016 | { |
db107f19 | 10017 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10018 | } |
10019 | ||
c906108c | 10020 | static void |
fba45db2 | 10021 | hbreak_command (char *arg, int from_tty) |
c906108c | 10022 | { |
db107f19 | 10023 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10024 | } |
10025 | ||
10026 | static void | |
fba45db2 | 10027 | thbreak_command (char *arg, int from_tty) |
c906108c | 10028 | { |
db107f19 | 10029 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10030 | } |
10031 | ||
10032 | static void | |
fba45db2 | 10033 | stop_command (char *arg, int from_tty) |
c906108c | 10034 | { |
a3f17187 | 10035 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10036 | Usage: stop in <function | address>\n\ |
a3f17187 | 10037 | stop at <line>\n")); |
c906108c SS |
10038 | } |
10039 | ||
10040 | static void | |
fba45db2 | 10041 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10042 | { |
10043 | int badInput = 0; | |
10044 | ||
c5aa993b | 10045 | if (arg == (char *) NULL) |
c906108c SS |
10046 | badInput = 1; |
10047 | else if (*arg != '*') | |
10048 | { | |
10049 | char *argptr = arg; | |
10050 | int hasColon = 0; | |
10051 | ||
4a64f543 | 10052 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10053 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10054 | function/method name. */ |
c906108c | 10055 | while (*argptr && !hasColon) |
c5aa993b JM |
10056 | { |
10057 | hasColon = (*argptr == ':'); | |
10058 | argptr++; | |
10059 | } | |
c906108c SS |
10060 | |
10061 | if (hasColon) | |
c5aa993b | 10062 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10063 | else |
c5aa993b | 10064 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10065 | } |
10066 | ||
10067 | if (badInput) | |
a3f17187 | 10068 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10069 | else |
db107f19 | 10070 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10071 | } |
10072 | ||
10073 | static void | |
fba45db2 | 10074 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10075 | { |
10076 | int badInput = 0; | |
10077 | ||
c5aa993b | 10078 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10079 | badInput = 1; |
10080 | else | |
10081 | { | |
10082 | char *argptr = arg; | |
10083 | int hasColon = 0; | |
10084 | ||
4a64f543 MS |
10085 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10086 | it is probably a line number. */ | |
c906108c | 10087 | while (*argptr && !hasColon) |
c5aa993b JM |
10088 | { |
10089 | hasColon = (*argptr == ':'); | |
10090 | argptr++; | |
10091 | } | |
c906108c SS |
10092 | |
10093 | if (hasColon) | |
c5aa993b | 10094 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10095 | else |
c5aa993b | 10096 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10097 | } |
10098 | ||
10099 | if (badInput) | |
a3f17187 | 10100 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10101 | else |
db107f19 | 10102 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10103 | } |
10104 | ||
e7e0cddf SS |
10105 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10106 | with a prewired command list consisting of a single output command, | |
10107 | built from extra arguments supplied on the dprintf command | |
10108 | line. */ | |
10109 | ||
da821c7b | 10110 | static void |
e7e0cddf SS |
10111 | dprintf_command (char *arg, int from_tty) |
10112 | { | |
10113 | create_breakpoint (get_current_arch (), | |
10114 | arg, | |
10115 | NULL, 0, NULL, 1 /* parse arg */, | |
10116 | 0, bp_dprintf, | |
10117 | 0 /* Ignore count */, | |
10118 | pending_break_support, | |
10119 | &dprintf_breakpoint_ops, | |
10120 | from_tty, | |
10121 | 1 /* enabled */, | |
10122 | 0 /* internal */, | |
10123 | 0); | |
10124 | } | |
10125 | ||
d3ce09f5 SS |
10126 | static void |
10127 | agent_printf_command (char *arg, int from_tty) | |
10128 | { | |
10129 | error (_("May only run agent-printf on the target")); | |
10130 | } | |
10131 | ||
f1310107 TJB |
10132 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10133 | ranged breakpoints. */ | |
10134 | ||
10135 | static int | |
10136 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10137 | struct address_space *aspace, | |
09ac7c10 TT |
10138 | CORE_ADDR bp_addr, |
10139 | const struct target_waitstatus *ws) | |
f1310107 | 10140 | { |
09ac7c10 | 10141 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10142 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10143 | return 0; |
10144 | ||
f1310107 TJB |
10145 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10146 | bl->length, aspace, bp_addr); | |
10147 | } | |
10148 | ||
10149 | /* Implement the "resources_needed" breakpoint_ops method for | |
10150 | ranged breakpoints. */ | |
10151 | ||
10152 | static int | |
10153 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10154 | { | |
10155 | return target_ranged_break_num_registers (); | |
10156 | } | |
10157 | ||
10158 | /* Implement the "print_it" breakpoint_ops method for | |
10159 | ranged breakpoints. */ | |
10160 | ||
10161 | static enum print_stop_action | |
348d480f | 10162 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10163 | { |
348d480f | 10164 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10165 | struct bp_location *bl = b->loc; |
79a45e25 | 10166 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10167 | |
10168 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10169 | ||
10170 | /* Ranged breakpoints have only one location. */ | |
10171 | gdb_assert (bl && bl->next == NULL); | |
10172 | ||
10173 | annotate_breakpoint (b->number); | |
10174 | if (b->disposition == disp_del) | |
10175 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10176 | else | |
10177 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10178 | if (ui_out_is_mi_like_p (uiout)) | |
10179 | { | |
10180 | ui_out_field_string (uiout, "reason", | |
10181 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10182 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10183 | } | |
10184 | ui_out_field_int (uiout, "bkptno", b->number); | |
10185 | ui_out_text (uiout, ", "); | |
10186 | ||
10187 | return PRINT_SRC_AND_LOC; | |
10188 | } | |
10189 | ||
10190 | /* Implement the "print_one" breakpoint_ops method for | |
10191 | ranged breakpoints. */ | |
10192 | ||
10193 | static void | |
10194 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10195 | struct bp_location **last_loc) | |
10196 | { | |
10197 | struct bp_location *bl = b->loc; | |
10198 | struct value_print_options opts; | |
79a45e25 | 10199 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10200 | |
10201 | /* Ranged breakpoints have only one location. */ | |
10202 | gdb_assert (bl && bl->next == NULL); | |
10203 | ||
10204 | get_user_print_options (&opts); | |
10205 | ||
10206 | if (opts.addressprint) | |
10207 | /* We don't print the address range here, it will be printed later | |
10208 | by print_one_detail_ranged_breakpoint. */ | |
10209 | ui_out_field_skip (uiout, "addr"); | |
10210 | annotate_field (5); | |
10211 | print_breakpoint_location (b, bl); | |
10212 | *last_loc = bl; | |
10213 | } | |
10214 | ||
10215 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10216 | ranged breakpoints. */ | |
10217 | ||
10218 | static void | |
10219 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10220 | struct ui_out *uiout) | |
10221 | { | |
10222 | CORE_ADDR address_start, address_end; | |
10223 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10224 | struct ui_file *stb = mem_fileopen (); |
10225 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10226 | |
10227 | gdb_assert (bl); | |
10228 | ||
10229 | address_start = bl->address; | |
10230 | address_end = address_start + bl->length - 1; | |
10231 | ||
10232 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10233 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10234 | print_core_address (bl->gdbarch, address_start), |
10235 | print_core_address (bl->gdbarch, address_end)); | |
10236 | ui_out_field_stream (uiout, "addr", stb); | |
10237 | ui_out_text (uiout, "\n"); | |
10238 | ||
10239 | do_cleanups (cleanup); | |
10240 | } | |
10241 | ||
10242 | /* Implement the "print_mention" breakpoint_ops method for | |
10243 | ranged breakpoints. */ | |
10244 | ||
10245 | static void | |
10246 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10247 | { | |
10248 | struct bp_location *bl = b->loc; | |
79a45e25 | 10249 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10250 | |
10251 | gdb_assert (bl); | |
10252 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10253 | ||
10254 | if (ui_out_is_mi_like_p (uiout)) | |
10255 | return; | |
10256 | ||
10257 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10258 | b->number, paddress (bl->gdbarch, bl->address), | |
10259 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10260 | } | |
10261 | ||
10262 | /* Implement the "print_recreate" breakpoint_ops method for | |
10263 | ranged breakpoints. */ | |
10264 | ||
10265 | static void | |
10266 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10267 | { | |
10268 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10269 | b->addr_string_range_end); | |
d9b3f62e | 10270 | print_recreate_thread (b, fp); |
f1310107 TJB |
10271 | } |
10272 | ||
10273 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10274 | ||
2060206e | 10275 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10276 | |
10277 | /* Find the address where the end of the breakpoint range should be | |
10278 | placed, given the SAL of the end of the range. This is so that if | |
10279 | the user provides a line number, the end of the range is set to the | |
10280 | last instruction of the given line. */ | |
10281 | ||
10282 | static CORE_ADDR | |
10283 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10284 | { | |
10285 | CORE_ADDR end; | |
10286 | ||
10287 | /* If the user provided a PC value, use it. Otherwise, | |
10288 | find the address of the end of the given location. */ | |
10289 | if (sal.explicit_pc) | |
10290 | end = sal.pc; | |
10291 | else | |
10292 | { | |
10293 | int ret; | |
10294 | CORE_ADDR start; | |
10295 | ||
10296 | ret = find_line_pc_range (sal, &start, &end); | |
10297 | if (!ret) | |
10298 | error (_("Could not find location of the end of the range.")); | |
10299 | ||
10300 | /* find_line_pc_range returns the start of the next line. */ | |
10301 | end--; | |
10302 | } | |
10303 | ||
10304 | return end; | |
10305 | } | |
10306 | ||
10307 | /* Implement the "break-range" CLI command. */ | |
10308 | ||
10309 | static void | |
10310 | break_range_command (char *arg, int from_tty) | |
10311 | { | |
10312 | char *arg_start, *addr_string_start, *addr_string_end; | |
10313 | struct linespec_result canonical_start, canonical_end; | |
10314 | int bp_count, can_use_bp, length; | |
10315 | CORE_ADDR end; | |
10316 | struct breakpoint *b; | |
10317 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10318 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10319 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10320 | |
10321 | /* We don't support software ranged breakpoints. */ | |
10322 | if (target_ranged_break_num_registers () < 0) | |
10323 | error (_("This target does not support hardware ranged breakpoints.")); | |
10324 | ||
10325 | bp_count = hw_breakpoint_used_count (); | |
10326 | bp_count += target_ranged_break_num_registers (); | |
10327 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10328 | bp_count, 0); | |
10329 | if (can_use_bp < 0) | |
10330 | error (_("Hardware breakpoints used exceeds limit.")); | |
10331 | ||
f8eba3c6 | 10332 | arg = skip_spaces (arg); |
f1310107 TJB |
10333 | if (arg == NULL || arg[0] == '\0') |
10334 | error(_("No address range specified.")); | |
10335 | ||
f1310107 TJB |
10336 | init_linespec_result (&canonical_start); |
10337 | ||
f8eba3c6 TT |
10338 | arg_start = arg; |
10339 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10340 | |
f8eba3c6 | 10341 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10342 | |
10343 | if (arg[0] != ',') | |
10344 | error (_("Too few arguments.")); | |
f8eba3c6 | 10345 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10346 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10347 | |
10348 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10349 | ||
10350 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10351 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10352 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10353 | ||
f8eba3c6 TT |
10354 | sal_start = lsal_start->sals.sals[0]; |
10355 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10356 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10357 | |
10358 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10359 | arg = skip_spaces (arg); |
f1310107 TJB |
10360 | |
10361 | /* Parse the end location. */ | |
10362 | ||
f1310107 TJB |
10363 | init_linespec_result (&canonical_end); |
10364 | arg_start = arg; | |
10365 | ||
f8eba3c6 | 10366 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10367 | parse_breakpoint_sals because we need to specify the start location's |
10368 | symtab and line as the default symtab and line for the end of the | |
10369 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10370 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10371 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10372 | sal_start.symtab, sal_start.line, | |
10373 | &canonical_end, NULL, NULL); | |
10374 | ||
10375 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10376 | |
f8eba3c6 | 10377 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10378 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10379 | |
10380 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10381 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10382 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10383 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10384 | ||
f8eba3c6 TT |
10385 | sal_end = lsal_end->sals.sals[0]; |
10386 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10387 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10388 | |
10389 | end = find_breakpoint_range_end (sal_end); | |
10390 | if (sal_start.pc > end) | |
177b42fe | 10391 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10392 | |
10393 | length = end - sal_start.pc + 1; | |
10394 | if (length < 0) | |
10395 | /* Length overflowed. */ | |
10396 | error (_("Address range too large.")); | |
10397 | else if (length == 1) | |
10398 | { | |
10399 | /* This range is simple enough to be handled by | |
10400 | the `hbreak' command. */ | |
10401 | hbreak_command (addr_string_start, 1); | |
10402 | ||
10403 | do_cleanups (cleanup_bkpt); | |
10404 | ||
10405 | return; | |
10406 | } | |
10407 | ||
10408 | /* Now set up the breakpoint. */ | |
10409 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10410 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10411 | set_breakpoint_count (breakpoint_count + 1); |
10412 | b->number = breakpoint_count; | |
10413 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10414 | b->addr_string = xstrdup (addr_string_start); |
10415 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10416 | b->loc->length = length; |
10417 | ||
f8eba3c6 | 10418 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10419 | |
10420 | mention (b); | |
8d3788bd | 10421 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
10422 | update_global_location_list (1); |
10423 | } | |
10424 | ||
4a64f543 MS |
10425 | /* Return non-zero if EXP is verified as constant. Returned zero |
10426 | means EXP is variable. Also the constant detection may fail for | |
10427 | some constant expressions and in such case still falsely return | |
10428 | zero. */ | |
2e6e3d9c | 10429 | |
65d79d4b SDJ |
10430 | static int |
10431 | watchpoint_exp_is_const (const struct expression *exp) | |
10432 | { | |
10433 | int i = exp->nelts; | |
10434 | ||
10435 | while (i > 0) | |
10436 | { | |
10437 | int oplenp, argsp; | |
10438 | ||
10439 | /* We are only interested in the descriptor of each element. */ | |
10440 | operator_length (exp, i, &oplenp, &argsp); | |
10441 | i -= oplenp; | |
10442 | ||
10443 | switch (exp->elts[i].opcode) | |
10444 | { | |
10445 | case BINOP_ADD: | |
10446 | case BINOP_SUB: | |
10447 | case BINOP_MUL: | |
10448 | case BINOP_DIV: | |
10449 | case BINOP_REM: | |
10450 | case BINOP_MOD: | |
10451 | case BINOP_LSH: | |
10452 | case BINOP_RSH: | |
10453 | case BINOP_LOGICAL_AND: | |
10454 | case BINOP_LOGICAL_OR: | |
10455 | case BINOP_BITWISE_AND: | |
10456 | case BINOP_BITWISE_IOR: | |
10457 | case BINOP_BITWISE_XOR: | |
10458 | case BINOP_EQUAL: | |
10459 | case BINOP_NOTEQUAL: | |
10460 | case BINOP_LESS: | |
10461 | case BINOP_GTR: | |
10462 | case BINOP_LEQ: | |
10463 | case BINOP_GEQ: | |
10464 | case BINOP_REPEAT: | |
10465 | case BINOP_COMMA: | |
10466 | case BINOP_EXP: | |
10467 | case BINOP_MIN: | |
10468 | case BINOP_MAX: | |
10469 | case BINOP_INTDIV: | |
10470 | case BINOP_CONCAT: | |
10471 | case BINOP_IN: | |
10472 | case BINOP_RANGE: | |
10473 | case TERNOP_COND: | |
10474 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10475 | |
10476 | case OP_LONG: | |
10477 | case OP_DOUBLE: | |
10478 | case OP_DECFLOAT: | |
10479 | case OP_LAST: | |
10480 | case OP_COMPLEX: | |
10481 | case OP_STRING: | |
65d79d4b SDJ |
10482 | case OP_ARRAY: |
10483 | case OP_TYPE: | |
608b4967 TT |
10484 | case OP_TYPEOF: |
10485 | case OP_DECLTYPE: | |
6e72ca20 | 10486 | case OP_TYPEID: |
65d79d4b SDJ |
10487 | case OP_NAME: |
10488 | case OP_OBJC_NSSTRING: | |
10489 | ||
10490 | case UNOP_NEG: | |
10491 | case UNOP_LOGICAL_NOT: | |
10492 | case UNOP_COMPLEMENT: | |
10493 | case UNOP_ADDR: | |
10494 | case UNOP_HIGH: | |
aeaa2474 | 10495 | case UNOP_CAST: |
9eaf6705 TT |
10496 | |
10497 | case UNOP_CAST_TYPE: | |
10498 | case UNOP_REINTERPRET_CAST: | |
10499 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10500 | /* Unary, binary and ternary operators: We have to check |
10501 | their operands. If they are constant, then so is the | |
10502 | result of that operation. For instance, if A and B are | |
10503 | determined to be constants, then so is "A + B". | |
10504 | ||
10505 | UNOP_IND is one exception to the rule above, because the | |
10506 | value of *ADDR is not necessarily a constant, even when | |
10507 | ADDR is. */ | |
65d79d4b SDJ |
10508 | break; |
10509 | ||
10510 | case OP_VAR_VALUE: | |
10511 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10512 | |
65d79d4b | 10513 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10514 | possible that a buggy compiler could mark a variable as |
10515 | constant even when it is not, and TYPE_CONST would return | |
10516 | true in this case, while SYMBOL_CLASS wouldn't. | |
10517 | ||
10518 | We also have to check for function symbols because they | |
10519 | are always constant. */ | |
65d79d4b SDJ |
10520 | { |
10521 | struct symbol *s = exp->elts[i + 2].symbol; | |
10522 | ||
10523 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10524 | && SYMBOL_CLASS (s) != LOC_CONST | |
10525 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10526 | return 0; | |
10527 | break; | |
10528 | } | |
10529 | ||
10530 | /* The default action is to return 0 because we are using | |
10531 | the optimistic approach here: If we don't know something, | |
10532 | then it is not a constant. */ | |
10533 | default: | |
10534 | return 0; | |
10535 | } | |
10536 | } | |
10537 | ||
10538 | return 1; | |
10539 | } | |
10540 | ||
3a5c3e22 PA |
10541 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10542 | ||
10543 | static void | |
10544 | dtor_watchpoint (struct breakpoint *self) | |
10545 | { | |
10546 | struct watchpoint *w = (struct watchpoint *) self; | |
10547 | ||
10548 | xfree (w->cond_exp); | |
10549 | xfree (w->exp); | |
10550 | xfree (w->exp_string); | |
10551 | xfree (w->exp_string_reparse); | |
10552 | value_free (w->val); | |
10553 | ||
10554 | base_breakpoint_ops.dtor (self); | |
10555 | } | |
10556 | ||
348d480f PA |
10557 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10558 | ||
10559 | static void | |
10560 | re_set_watchpoint (struct breakpoint *b) | |
10561 | { | |
3a5c3e22 PA |
10562 | struct watchpoint *w = (struct watchpoint *) b; |
10563 | ||
348d480f PA |
10564 | /* Watchpoint can be either on expression using entirely global |
10565 | variables, or it can be on local variables. | |
10566 | ||
10567 | Watchpoints of the first kind are never auto-deleted, and even | |
10568 | persist across program restarts. Since they can use variables | |
10569 | from shared libraries, we need to reparse expression as libraries | |
10570 | are loaded and unloaded. | |
10571 | ||
10572 | Watchpoints on local variables can also change meaning as result | |
10573 | of solib event. For example, if a watchpoint uses both a local | |
10574 | and a global variables in expression, it's a local watchpoint, | |
10575 | but unloading of a shared library will make the expression | |
10576 | invalid. This is not a very common use case, but we still | |
10577 | re-evaluate expression, to avoid surprises to the user. | |
10578 | ||
10579 | Note that for local watchpoints, we re-evaluate it only if | |
10580 | watchpoints frame id is still valid. If it's not, it means the | |
10581 | watchpoint is out of scope and will be deleted soon. In fact, | |
10582 | I'm not sure we'll ever be called in this case. | |
10583 | ||
10584 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10585 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10586 | |
3a5c3e22 PA |
10587 | Don't do anything about disabled watchpoints, since they will be |
10588 | reevaluated again when enabled. */ | |
10589 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10590 | } |
10591 | ||
77b06cd7 TJB |
10592 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10593 | ||
10594 | static int | |
10595 | insert_watchpoint (struct bp_location *bl) | |
10596 | { | |
3a5c3e22 PA |
10597 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10598 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10599 | |
10600 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10601 | w->cond_exp); |
77b06cd7 TJB |
10602 | } |
10603 | ||
10604 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10605 | ||
10606 | static int | |
10607 | remove_watchpoint (struct bp_location *bl) | |
10608 | { | |
3a5c3e22 PA |
10609 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10610 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10611 | |
10612 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10613 | w->cond_exp); |
e09342b5 TJB |
10614 | } |
10615 | ||
e09342b5 | 10616 | static int |
348d480f | 10617 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10618 | struct address_space *aspace, CORE_ADDR bp_addr, |
10619 | const struct target_waitstatus *ws) | |
e09342b5 | 10620 | { |
348d480f | 10621 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10622 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10623 | |
348d480f PA |
10624 | /* Continuable hardware watchpoints are treated as non-existent if the |
10625 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10626 | some data address). Otherwise gdb won't stop on a break instruction | |
10627 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10628 | been defined. Also skip watchpoints which we know did not trigger | |
10629 | (did not match the data address). */ | |
10630 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10631 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10632 | return 0; |
9c06b0b4 | 10633 | |
348d480f | 10634 | return 1; |
9c06b0b4 TJB |
10635 | } |
10636 | ||
348d480f PA |
10637 | static void |
10638 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10639 | { |
348d480f | 10640 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10641 | |
348d480f | 10642 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10643 | } |
10644 | ||
10645 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10646 | hardware watchpoints. */ |
9c06b0b4 TJB |
10647 | |
10648 | static int | |
348d480f | 10649 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10650 | { |
3a5c3e22 PA |
10651 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10652 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10653 | |
10654 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10655 | } |
10656 | ||
10657 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10658 | hardware watchpoints. */ |
9c06b0b4 TJB |
10659 | |
10660 | static int | |
348d480f | 10661 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10662 | { |
efa80663 PA |
10663 | /* Read and access watchpoints only work with hardware support. */ |
10664 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10665 | } |
10666 | ||
9c06b0b4 | 10667 | static enum print_stop_action |
348d480f | 10668 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10669 | { |
348d480f PA |
10670 | struct cleanup *old_chain; |
10671 | struct breakpoint *b; | |
f99d8bf4 | 10672 | struct ui_file *stb; |
348d480f | 10673 | enum print_stop_action result; |
3a5c3e22 | 10674 | struct watchpoint *w; |
79a45e25 | 10675 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10676 | |
10677 | gdb_assert (bs->bp_location_at != NULL); | |
10678 | ||
348d480f | 10679 | b = bs->breakpoint_at; |
3a5c3e22 | 10680 | w = (struct watchpoint *) b; |
348d480f | 10681 | |
f99d8bf4 PA |
10682 | stb = mem_fileopen (); |
10683 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10684 | |
10685 | switch (b->type) | |
10686 | { | |
348d480f | 10687 | case bp_watchpoint: |
9c06b0b4 TJB |
10688 | case bp_hardware_watchpoint: |
10689 | annotate_watchpoint (b->number); | |
10690 | if (ui_out_is_mi_like_p (uiout)) | |
10691 | ui_out_field_string | |
10692 | (uiout, "reason", | |
10693 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10694 | mention (b); |
10695 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10696 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10697 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10698 | ui_out_field_stream (uiout, "old", stb); |
10699 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10700 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10701 | ui_out_field_stream (uiout, "new", stb); |
10702 | ui_out_text (uiout, "\n"); | |
10703 | /* More than one watchpoint may have been triggered. */ | |
10704 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10705 | break; |
10706 | ||
10707 | case bp_read_watchpoint: | |
10708 | if (ui_out_is_mi_like_p (uiout)) | |
10709 | ui_out_field_string | |
10710 | (uiout, "reason", | |
10711 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10712 | mention (b); |
10713 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10714 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10715 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10716 | ui_out_field_stream (uiout, "value", stb); |
10717 | ui_out_text (uiout, "\n"); | |
10718 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10719 | break; |
10720 | ||
10721 | case bp_access_watchpoint: | |
348d480f PA |
10722 | if (bs->old_val != NULL) |
10723 | { | |
10724 | annotate_watchpoint (b->number); | |
10725 | if (ui_out_is_mi_like_p (uiout)) | |
10726 | ui_out_field_string | |
10727 | (uiout, "reason", | |
10728 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10729 | mention (b); | |
10730 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10731 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10732 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10733 | ui_out_field_stream (uiout, "old", stb); |
10734 | ui_out_text (uiout, "\nNew value = "); | |
10735 | } | |
10736 | else | |
10737 | { | |
10738 | mention (b); | |
10739 | if (ui_out_is_mi_like_p (uiout)) | |
10740 | ui_out_field_string | |
10741 | (uiout, "reason", | |
10742 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10743 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10744 | ui_out_text (uiout, "\nValue = "); | |
10745 | } | |
f99d8bf4 | 10746 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10747 | ui_out_field_stream (uiout, "new", stb); |
10748 | ui_out_text (uiout, "\n"); | |
10749 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10750 | break; |
10751 | default: | |
348d480f | 10752 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10753 | } |
10754 | ||
348d480f PA |
10755 | do_cleanups (old_chain); |
10756 | return result; | |
10757 | } | |
10758 | ||
10759 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10760 | watchpoints. */ | |
10761 | ||
10762 | static void | |
10763 | print_mention_watchpoint (struct breakpoint *b) | |
10764 | { | |
10765 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10766 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10767 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10768 | |
10769 | switch (b->type) | |
10770 | { | |
10771 | case bp_watchpoint: | |
10772 | ui_out_text (uiout, "Watchpoint "); | |
10773 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10774 | break; | |
10775 | case bp_hardware_watchpoint: | |
10776 | ui_out_text (uiout, "Hardware watchpoint "); | |
10777 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10778 | break; | |
10779 | case bp_read_watchpoint: | |
10780 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10781 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10782 | break; | |
10783 | case bp_access_watchpoint: | |
10784 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10785 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10786 | break; | |
10787 | default: | |
10788 | internal_error (__FILE__, __LINE__, | |
10789 | _("Invalid hardware watchpoint type.")); | |
10790 | } | |
10791 | ||
10792 | ui_out_field_int (uiout, "number", b->number); | |
10793 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10794 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10795 | do_cleanups (ui_out_chain); |
10796 | } | |
10797 | ||
10798 | /* Implement the "print_recreate" breakpoint_ops method for | |
10799 | watchpoints. */ | |
10800 | ||
10801 | static void | |
10802 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10803 | { | |
3a5c3e22 PA |
10804 | struct watchpoint *w = (struct watchpoint *) b; |
10805 | ||
348d480f PA |
10806 | switch (b->type) |
10807 | { | |
10808 | case bp_watchpoint: | |
10809 | case bp_hardware_watchpoint: | |
10810 | fprintf_unfiltered (fp, "watch"); | |
10811 | break; | |
10812 | case bp_read_watchpoint: | |
10813 | fprintf_unfiltered (fp, "rwatch"); | |
10814 | break; | |
10815 | case bp_access_watchpoint: | |
10816 | fprintf_unfiltered (fp, "awatch"); | |
10817 | break; | |
10818 | default: | |
10819 | internal_error (__FILE__, __LINE__, | |
10820 | _("Invalid watchpoint type.")); | |
10821 | } | |
10822 | ||
3a5c3e22 | 10823 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10824 | print_recreate_thread (b, fp); |
348d480f PA |
10825 | } |
10826 | ||
427cd150 TT |
10827 | /* Implement the "explains_signal" breakpoint_ops method for |
10828 | watchpoints. */ | |
10829 | ||
47591c29 | 10830 | static int |
427cd150 TT |
10831 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10832 | { | |
10833 | /* A software watchpoint cannot cause a signal other than | |
10834 | GDB_SIGNAL_TRAP. */ | |
10835 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10836 | return 0; |
427cd150 | 10837 | |
47591c29 | 10838 | return 1; |
427cd150 TT |
10839 | } |
10840 | ||
348d480f PA |
10841 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10842 | ||
2060206e | 10843 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10844 | |
10845 | /* Implement the "insert" breakpoint_ops method for | |
10846 | masked hardware watchpoints. */ | |
10847 | ||
10848 | static int | |
10849 | insert_masked_watchpoint (struct bp_location *bl) | |
10850 | { | |
3a5c3e22 PA |
10851 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10852 | ||
10853 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10854 | bl->watchpoint_type); |
10855 | } | |
10856 | ||
10857 | /* Implement the "remove" breakpoint_ops method for | |
10858 | masked hardware watchpoints. */ | |
10859 | ||
10860 | static int | |
10861 | remove_masked_watchpoint (struct bp_location *bl) | |
10862 | { | |
3a5c3e22 PA |
10863 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10864 | ||
10865 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10866 | bl->watchpoint_type); |
10867 | } | |
10868 | ||
10869 | /* Implement the "resources_needed" breakpoint_ops method for | |
10870 | masked hardware watchpoints. */ | |
10871 | ||
10872 | static int | |
10873 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10874 | { | |
3a5c3e22 PA |
10875 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10876 | ||
10877 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10878 | } |
10879 | ||
10880 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10881 | masked hardware watchpoints. */ | |
10882 | ||
10883 | static int | |
10884 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10885 | { | |
10886 | return 0; | |
10887 | } | |
10888 | ||
10889 | /* Implement the "print_it" breakpoint_ops method for | |
10890 | masked hardware watchpoints. */ | |
10891 | ||
10892 | static enum print_stop_action | |
10893 | print_it_masked_watchpoint (bpstat bs) | |
10894 | { | |
10895 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10896 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10897 | |
10898 | /* Masked watchpoints have only one location. */ | |
10899 | gdb_assert (b->loc && b->loc->next == NULL); | |
10900 | ||
10901 | switch (b->type) | |
10902 | { | |
10903 | case bp_hardware_watchpoint: | |
10904 | annotate_watchpoint (b->number); | |
10905 | if (ui_out_is_mi_like_p (uiout)) | |
10906 | ui_out_field_string | |
10907 | (uiout, "reason", | |
10908 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10909 | break; | |
10910 | ||
10911 | case bp_read_watchpoint: | |
10912 | if (ui_out_is_mi_like_p (uiout)) | |
10913 | ui_out_field_string | |
10914 | (uiout, "reason", | |
10915 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10916 | break; | |
10917 | ||
10918 | case bp_access_watchpoint: | |
10919 | if (ui_out_is_mi_like_p (uiout)) | |
10920 | ui_out_field_string | |
10921 | (uiout, "reason", | |
10922 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10923 | break; | |
10924 | default: | |
10925 | internal_error (__FILE__, __LINE__, | |
10926 | _("Invalid hardware watchpoint type.")); | |
10927 | } | |
10928 | ||
10929 | mention (b); | |
9c06b0b4 TJB |
10930 | ui_out_text (uiout, _("\n\ |
10931 | Check the underlying instruction at PC for the memory\n\ | |
10932 | address and value which triggered this watchpoint.\n")); | |
10933 | ui_out_text (uiout, "\n"); | |
10934 | ||
10935 | /* More than one watchpoint may have been triggered. */ | |
10936 | return PRINT_UNKNOWN; | |
10937 | } | |
10938 | ||
10939 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10940 | masked hardware watchpoints. */ | |
10941 | ||
10942 | static void | |
10943 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10944 | struct ui_out *uiout) | |
10945 | { | |
3a5c3e22 PA |
10946 | struct watchpoint *w = (struct watchpoint *) b; |
10947 | ||
9c06b0b4 TJB |
10948 | /* Masked watchpoints have only one location. */ |
10949 | gdb_assert (b->loc && b->loc->next == NULL); | |
10950 | ||
10951 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10952 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10953 | ui_out_text (uiout, "\n"); |
10954 | } | |
10955 | ||
10956 | /* Implement the "print_mention" breakpoint_ops method for | |
10957 | masked hardware watchpoints. */ | |
10958 | ||
10959 | static void | |
10960 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10961 | { | |
3a5c3e22 | 10962 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10963 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10964 | struct cleanup *ui_out_chain; |
10965 | ||
10966 | switch (b->type) | |
10967 | { | |
10968 | case bp_hardware_watchpoint: | |
10969 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10970 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10971 | break; | |
10972 | case bp_read_watchpoint: | |
10973 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10974 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10975 | break; | |
10976 | case bp_access_watchpoint: | |
10977 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10978 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10979 | break; | |
10980 | default: | |
10981 | internal_error (__FILE__, __LINE__, | |
10982 | _("Invalid hardware watchpoint type.")); | |
10983 | } | |
10984 | ||
10985 | ui_out_field_int (uiout, "number", b->number); | |
10986 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10987 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10988 | do_cleanups (ui_out_chain); |
10989 | } | |
10990 | ||
10991 | /* Implement the "print_recreate" breakpoint_ops method for | |
10992 | masked hardware watchpoints. */ | |
10993 | ||
10994 | static void | |
10995 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10996 | { | |
3a5c3e22 | 10997 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10998 | char tmp[40]; |
10999 | ||
11000 | switch (b->type) | |
11001 | { | |
11002 | case bp_hardware_watchpoint: | |
11003 | fprintf_unfiltered (fp, "watch"); | |
11004 | break; | |
11005 | case bp_read_watchpoint: | |
11006 | fprintf_unfiltered (fp, "rwatch"); | |
11007 | break; | |
11008 | case bp_access_watchpoint: | |
11009 | fprintf_unfiltered (fp, "awatch"); | |
11010 | break; | |
11011 | default: | |
11012 | internal_error (__FILE__, __LINE__, | |
11013 | _("Invalid hardware watchpoint type.")); | |
11014 | } | |
11015 | ||
3a5c3e22 PA |
11016 | sprintf_vma (tmp, w->hw_wp_mask); |
11017 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11018 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11019 | } |
11020 | ||
11021 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11022 | ||
2060206e | 11023 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11024 | |
11025 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11026 | ||
11027 | static int | |
11028 | is_masked_watchpoint (const struct breakpoint *b) | |
11029 | { | |
11030 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11031 | } | |
11032 | ||
53a5351d JM |
11033 | /* accessflag: hw_write: watch write, |
11034 | hw_read: watch read, | |
11035 | hw_access: watch access (read or write) */ | |
c906108c | 11036 | static void |
bbc13ae3 | 11037 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11038 | int just_location, int internal) |
c906108c | 11039 | { |
a9634178 | 11040 | volatile struct gdb_exception e; |
d983da9c | 11041 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11042 | struct expression *exp; |
270140bd | 11043 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11044 | struct value *val, *mark, *result; |
c906108c | 11045 | struct frame_info *frame; |
bbc13ae3 KS |
11046 | const char *exp_start = NULL; |
11047 | const char *exp_end = NULL; | |
11048 | const char *tok, *end_tok; | |
9c06b0b4 | 11049 | int toklen = -1; |
bbc13ae3 KS |
11050 | const char *cond_start = NULL; |
11051 | const char *cond_end = NULL; | |
c906108c | 11052 | enum bptype bp_type; |
37e4754d | 11053 | int thread = -1; |
0cf6dd15 | 11054 | int pc = 0; |
9c06b0b4 TJB |
11055 | /* Flag to indicate whether we are going to use masks for |
11056 | the hardware watchpoint. */ | |
11057 | int use_mask = 0; | |
11058 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11059 | struct watchpoint *w; |
bbc13ae3 KS |
11060 | char *expression; |
11061 | struct cleanup *back_to; | |
c906108c | 11062 | |
37e4754d LM |
11063 | /* Make sure that we actually have parameters to parse. */ |
11064 | if (arg != NULL && arg[0] != '\0') | |
11065 | { | |
bbc13ae3 KS |
11066 | const char *value_start; |
11067 | ||
11068 | exp_end = arg + strlen (arg); | |
37e4754d | 11069 | |
9c06b0b4 TJB |
11070 | /* Look for "parameter value" pairs at the end |
11071 | of the arguments string. */ | |
bbc13ae3 | 11072 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11073 | { |
11074 | /* Skip whitespace at the end of the argument list. */ | |
11075 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11076 | tok--; | |
11077 | ||
11078 | /* Find the beginning of the last token. | |
11079 | This is the value of the parameter. */ | |
11080 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11081 | tok--; | |
11082 | value_start = tok + 1; | |
11083 | ||
11084 | /* Skip whitespace. */ | |
11085 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11086 | tok--; | |
11087 | ||
11088 | end_tok = tok; | |
11089 | ||
11090 | /* Find the beginning of the second to last token. | |
11091 | This is the parameter itself. */ | |
11092 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11093 | tok--; | |
11094 | tok++; | |
11095 | toklen = end_tok - tok + 1; | |
11096 | ||
11097 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11098 | { | |
11099 | /* At this point we've found a "thread" token, which means | |
11100 | the user is trying to set a watchpoint that triggers | |
11101 | only in a specific thread. */ | |
11102 | char *endp; | |
37e4754d | 11103 | |
9c06b0b4 TJB |
11104 | if (thread != -1) |
11105 | error(_("You can specify only one thread.")); | |
37e4754d | 11106 | |
9c06b0b4 TJB |
11107 | /* Extract the thread ID from the next token. */ |
11108 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11109 | |
9c06b0b4 TJB |
11110 | /* Check if the user provided a valid numeric value for the |
11111 | thread ID. */ | |
11112 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11113 | error (_("Invalid thread ID specification %s."), value_start); | |
11114 | ||
11115 | /* Check if the thread actually exists. */ | |
11116 | if (!valid_thread_id (thread)) | |
af4908ba | 11117 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11118 | } |
11119 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11120 | { | |
11121 | /* We've found a "mask" token, which means the user wants to | |
11122 | create a hardware watchpoint that is going to have the mask | |
11123 | facility. */ | |
11124 | struct value *mask_value, *mark; | |
37e4754d | 11125 | |
9c06b0b4 TJB |
11126 | if (use_mask) |
11127 | error(_("You can specify only one mask.")); | |
37e4754d | 11128 | |
9c06b0b4 | 11129 | use_mask = just_location = 1; |
37e4754d | 11130 | |
9c06b0b4 TJB |
11131 | mark = value_mark (); |
11132 | mask_value = parse_to_comma_and_eval (&value_start); | |
11133 | mask = value_as_address (mask_value); | |
11134 | value_free_to_mark (mark); | |
11135 | } | |
11136 | else | |
11137 | /* We didn't recognize what we found. We should stop here. */ | |
11138 | break; | |
37e4754d | 11139 | |
9c06b0b4 TJB |
11140 | /* Truncate the string and get rid of the "parameter value" pair before |
11141 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11142 | exp_end = tok; |
9c06b0b4 | 11143 | } |
37e4754d | 11144 | } |
bbc13ae3 KS |
11145 | else |
11146 | exp_end = arg; | |
37e4754d | 11147 | |
bbc13ae3 KS |
11148 | /* Parse the rest of the arguments. From here on out, everything |
11149 | is in terms of a newly allocated string instead of the original | |
11150 | ARG. */ | |
c906108c | 11151 | innermost_block = NULL; |
bbc13ae3 KS |
11152 | expression = savestring (arg, exp_end - arg); |
11153 | back_to = make_cleanup (xfree, expression); | |
11154 | exp_start = arg = expression; | |
1bb9788d | 11155 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11156 | exp_end = arg; |
fa8a61dc TT |
11157 | /* Remove trailing whitespace from the expression before saving it. |
11158 | This makes the eventual display of the expression string a bit | |
11159 | prettier. */ | |
11160 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11161 | --exp_end; | |
11162 | ||
65d79d4b SDJ |
11163 | /* Checking if the expression is not constant. */ |
11164 | if (watchpoint_exp_is_const (exp)) | |
11165 | { | |
11166 | int len; | |
11167 | ||
11168 | len = exp_end - exp_start; | |
11169 | while (len > 0 && isspace (exp_start[len - 1])) | |
11170 | len--; | |
11171 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11172 | } | |
11173 | ||
c906108c SS |
11174 | exp_valid_block = innermost_block; |
11175 | mark = value_mark (); | |
3a1115a0 | 11176 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b TT |
11177 | |
11178 | if (just_location) | |
11179 | { | |
9c06b0b4 TJB |
11180 | int ret; |
11181 | ||
06a64a0b | 11182 | exp_valid_block = NULL; |
a1442452 | 11183 | val = value_addr (result); |
06a64a0b TT |
11184 | release_value (val); |
11185 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11186 | |
11187 | if (use_mask) | |
11188 | { | |
11189 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11190 | mask); | |
11191 | if (ret == -1) | |
11192 | error (_("This target does not support masked watchpoints.")); | |
11193 | else if (ret == -2) | |
11194 | error (_("Invalid mask or memory region.")); | |
11195 | } | |
06a64a0b TT |
11196 | } |
11197 | else if (val != NULL) | |
fa4727a6 | 11198 | release_value (val); |
c906108c | 11199 | |
bbc13ae3 KS |
11200 | tok = skip_spaces_const (arg); |
11201 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11202 | |
11203 | toklen = end_tok - tok; | |
11204 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11205 | { | |
2d134ed3 PA |
11206 | struct expression *cond; |
11207 | ||
60e1c644 | 11208 | innermost_block = NULL; |
c906108c | 11209 | tok = cond_start = end_tok + 1; |
1bb9788d | 11210 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11211 | |
11212 | /* The watchpoint expression may not be local, but the condition | |
11213 | may still be. E.g.: `watch global if local > 0'. */ | |
11214 | cond_exp_valid_block = innermost_block; | |
11215 | ||
2d134ed3 | 11216 | xfree (cond); |
c906108c SS |
11217 | cond_end = tok; |
11218 | } | |
11219 | if (*tok) | |
8a3fe4f8 | 11220 | error (_("Junk at end of command.")); |
c906108c | 11221 | |
d983da9c | 11222 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11223 | |
11224 | /* If the expression is "local", then set up a "watchpoint scope" | |
11225 | breakpoint at the point where we've left the scope of the watchpoint | |
11226 | expression. Create the scope breakpoint before the watchpoint, so | |
11227 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11228 | if (exp_valid_block && frame) |
d983da9c | 11229 | { |
edb3359d DJ |
11230 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11231 | { | |
11232 | scope_breakpoint | |
a6d9a66e UW |
11233 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11234 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11235 | bp_watchpoint_scope, |
11236 | &momentary_breakpoint_ops); | |
d983da9c | 11237 | |
edb3359d | 11238 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11239 | |
edb3359d DJ |
11240 | /* Automatically delete the breakpoint when it hits. */ |
11241 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11242 | |
edb3359d DJ |
11243 | /* Only break in the proper frame (help with recursion). */ |
11244 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11245 | |
edb3359d | 11246 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11247 | scope_breakpoint->loc->gdbarch |
11248 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11249 | scope_breakpoint->loc->requested_address |
11250 | = frame_unwind_caller_pc (frame); | |
11251 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11252 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11253 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11254 | scope_breakpoint->type); |
11255 | } | |
d983da9c DJ |
11256 | } |
11257 | ||
e8369a73 AB |
11258 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11259 | watchpoints here even if hardware watchpoints are turned off, a call | |
11260 | to update_watchpoint later in this function will cause the type to | |
11261 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11262 | ||
11263 | if (accessflag == hw_read) | |
11264 | bp_type = bp_read_watchpoint; | |
11265 | else if (accessflag == hw_access) | |
11266 | bp_type = bp_access_watchpoint; | |
11267 | else | |
11268 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11269 | |
11270 | w = XCNEW (struct watchpoint); | |
11271 | b = &w->base; | |
348d480f | 11272 | if (use_mask) |
3a5c3e22 PA |
11273 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11274 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11275 | else |
3a5c3e22 PA |
11276 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11277 | &watchpoint_breakpoint_ops); | |
37e4754d | 11278 | b->thread = thread; |
b5de0fa7 | 11279 | b->disposition = disp_donttouch; |
348d480f | 11280 | b->pspace = current_program_space; |
3a5c3e22 PA |
11281 | w->exp = exp; |
11282 | w->exp_valid_block = exp_valid_block; | |
11283 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11284 | if (just_location) |
11285 | { | |
11286 | struct type *t = value_type (val); | |
11287 | CORE_ADDR addr = value_as_address (val); | |
11288 | char *name; | |
11289 | ||
11290 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11291 | name = type_to_string (t); | |
11292 | ||
3a5c3e22 | 11293 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11294 | core_addr_to_string (addr)); |
06a64a0b TT |
11295 | xfree (name); |
11296 | ||
3a5c3e22 | 11297 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11298 | (int) (exp_end - exp_start), exp_start); |
11299 | ||
06a64a0b TT |
11300 | /* The above expression is in C. */ |
11301 | b->language = language_c; | |
11302 | } | |
11303 | else | |
3a5c3e22 | 11304 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11305 | |
11306 | if (use_mask) | |
11307 | { | |
3a5c3e22 | 11308 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11309 | } |
11310 | else | |
11311 | { | |
3a5c3e22 PA |
11312 | w->val = val; |
11313 | w->val_valid = 1; | |
9c06b0b4 | 11314 | } |
77b06cd7 | 11315 | |
c906108c SS |
11316 | if (cond_start) |
11317 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11318 | else | |
11319 | b->cond_string = 0; | |
c5aa993b | 11320 | |
c906108c | 11321 | if (frame) |
f6bc2008 | 11322 | { |
3a5c3e22 PA |
11323 | w->watchpoint_frame = get_frame_id (frame); |
11324 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11325 | } |
c906108c | 11326 | else |
f6bc2008 | 11327 | { |
3a5c3e22 PA |
11328 | w->watchpoint_frame = null_frame_id; |
11329 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11330 | } |
c906108c | 11331 | |
d983da9c | 11332 | if (scope_breakpoint != NULL) |
c906108c | 11333 | { |
d983da9c DJ |
11334 | /* The scope breakpoint is related to the watchpoint. We will |
11335 | need to act on them together. */ | |
11336 | b->related_breakpoint = scope_breakpoint; | |
11337 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11338 | } |
d983da9c | 11339 | |
06a64a0b TT |
11340 | if (!just_location) |
11341 | value_free_to_mark (mark); | |
2d134ed3 | 11342 | |
a9634178 TJB |
11343 | TRY_CATCH (e, RETURN_MASK_ALL) |
11344 | { | |
11345 | /* Finally update the new watchpoint. This creates the locations | |
11346 | that should be inserted. */ | |
3a5c3e22 | 11347 | update_watchpoint (w, 1); |
a9634178 TJB |
11348 | } |
11349 | if (e.reason < 0) | |
11350 | { | |
11351 | delete_breakpoint (b); | |
11352 | throw_exception (e); | |
11353 | } | |
11354 | ||
3ea46bff | 11355 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11356 | do_cleanups (back_to); |
c906108c SS |
11357 | } |
11358 | ||
e09342b5 | 11359 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11360 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11361 | |
c906108c | 11362 | static int |
a9634178 | 11363 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11364 | { |
11365 | int found_memory_cnt = 0; | |
2e70b7b9 | 11366 | struct value *head = v; |
c906108c SS |
11367 | |
11368 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11369 | if (!can_use_hw_watchpoints) |
c906108c | 11370 | return 0; |
c5aa993b | 11371 | |
5c44784c JM |
11372 | /* Make sure that the value of the expression depends only upon |
11373 | memory contents, and values computed from them within GDB. If we | |
11374 | find any register references or function calls, we can't use a | |
11375 | hardware watchpoint. | |
11376 | ||
11377 | The idea here is that evaluating an expression generates a series | |
11378 | of values, one holding the value of every subexpression. (The | |
11379 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11380 | a*b+c.) GDB's values hold almost enough information to establish | |
11381 | the criteria given above --- they identify memory lvalues, | |
11382 | register lvalues, computed values, etcetera. So we can evaluate | |
11383 | the expression, and then scan the chain of values that leaves | |
11384 | behind to decide whether we can detect any possible change to the | |
11385 | expression's final value using only hardware watchpoints. | |
11386 | ||
11387 | However, I don't think that the values returned by inferior | |
11388 | function calls are special in any way. So this function may not | |
11389 | notice that an expression involving an inferior function call | |
11390 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11391 | for (; v; v = value_next (v)) |
c906108c | 11392 | { |
5c44784c | 11393 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11394 | { |
8464be76 DJ |
11395 | if (v != head && value_lazy (v)) |
11396 | /* A lazy memory lvalue in the chain is one that GDB never | |
11397 | needed to fetch; we either just used its address (e.g., | |
11398 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11399 | in `a,b'). This doesn't apply to HEAD; if that is | |
11400 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11401 | ; |
53a5351d | 11402 | else |
5c44784c JM |
11403 | { |
11404 | /* Ahh, memory we actually used! Check if we can cover | |
11405 | it with hardware watchpoints. */ | |
df407dfe | 11406 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11407 | |
11408 | /* We only watch structs and arrays if user asked for it | |
11409 | explicitly, never if they just happen to appear in a | |
11410 | middle of some value chain. */ | |
11411 | if (v == head | |
11412 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11413 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11414 | { | |
42ae5230 | 11415 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11416 | int len; |
11417 | int num_regs; | |
11418 | ||
a9634178 | 11419 | len = (target_exact_watchpoints |
e09342b5 TJB |
11420 | && is_scalar_type_recursive (vtype))? |
11421 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11422 | |
e09342b5 TJB |
11423 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11424 | if (!num_regs) | |
2e70b7b9 MS |
11425 | return 0; |
11426 | else | |
e09342b5 | 11427 | found_memory_cnt += num_regs; |
2e70b7b9 | 11428 | } |
5c44784c | 11429 | } |
c5aa993b | 11430 | } |
5086187c AC |
11431 | else if (VALUE_LVAL (v) != not_lval |
11432 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11433 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11434 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11435 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11436 | } |
11437 | ||
11438 | /* The expression itself looks suitable for using a hardware | |
11439 | watchpoint, but give the target machine a chance to reject it. */ | |
11440 | return found_memory_cnt; | |
11441 | } | |
11442 | ||
8b93c638 | 11443 | void |
84f4c1fe | 11444 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11445 | { |
84f4c1fe | 11446 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11447 | } |
11448 | ||
06a64a0b TT |
11449 | /* A helper function that looks for the "-location" argument and then |
11450 | calls watch_command_1. */ | |
11451 | ||
11452 | static void | |
11453 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11454 | { | |
11455 | int just_location = 0; | |
11456 | ||
11457 | if (arg | |
11458 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11459 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11460 | { | |
e9cafbcc | 11461 | arg = skip_spaces (arg); |
06a64a0b TT |
11462 | just_location = 1; |
11463 | } | |
11464 | ||
84f4c1fe | 11465 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11466 | } |
8926118c | 11467 | |
c5aa993b | 11468 | static void |
fba45db2 | 11469 | watch_command (char *arg, int from_tty) |
c906108c | 11470 | { |
06a64a0b | 11471 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11472 | } |
11473 | ||
8b93c638 | 11474 | void |
84f4c1fe | 11475 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11476 | { |
84f4c1fe | 11477 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11478 | } |
8926118c | 11479 | |
c5aa993b | 11480 | static void |
fba45db2 | 11481 | rwatch_command (char *arg, int from_tty) |
c906108c | 11482 | { |
06a64a0b | 11483 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11484 | } |
11485 | ||
8b93c638 | 11486 | void |
84f4c1fe | 11487 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11488 | { |
84f4c1fe | 11489 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11490 | } |
8926118c | 11491 | |
c5aa993b | 11492 | static void |
fba45db2 | 11493 | awatch_command (char *arg, int from_tty) |
c906108c | 11494 | { |
06a64a0b | 11495 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11496 | } |
c906108c | 11497 | \f |
c5aa993b | 11498 | |
43ff13b4 | 11499 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11500 | because it uses the mechanisms of breakpoints. */ |
11501 | ||
bfec99b2 PA |
11502 | struct until_break_command_continuation_args |
11503 | { | |
11504 | struct breakpoint *breakpoint; | |
11505 | struct breakpoint *breakpoint2; | |
186c406b | 11506 | int thread_num; |
bfec99b2 PA |
11507 | }; |
11508 | ||
43ff13b4 | 11509 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11510 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11511 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11512 | command. */ |
c2c6d25f | 11513 | static void |
fa4cd53f | 11514 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11515 | { |
bfec99b2 PA |
11516 | struct until_break_command_continuation_args *a = arg; |
11517 | ||
11518 | delete_breakpoint (a->breakpoint); | |
11519 | if (a->breakpoint2) | |
11520 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11521 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11522 | } |
11523 | ||
c906108c | 11524 | void |
ae66c1fc | 11525 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11526 | { |
11527 | struct symtabs_and_lines sals; | |
11528 | struct symtab_and_line sal; | |
8556afb4 PA |
11529 | struct frame_info *frame; |
11530 | struct gdbarch *frame_gdbarch; | |
11531 | struct frame_id stack_frame_id; | |
11532 | struct frame_id caller_frame_id; | |
c906108c | 11533 | struct breakpoint *breakpoint; |
f107f563 | 11534 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11535 | struct cleanup *old_chain; |
186c406b TT |
11536 | int thread; |
11537 | struct thread_info *tp; | |
c906108c SS |
11538 | |
11539 | clear_proceed_status (); | |
11540 | ||
11541 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11542 | this function. */ |
c5aa993b | 11543 | |
1bfeeb0f | 11544 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11545 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11546 | get_last_displayed_symtab (), |
f8eba3c6 | 11547 | get_last_displayed_line ()); |
c906108c | 11548 | else |
f8eba3c6 TT |
11549 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11550 | (struct symtab *) NULL, 0); | |
c5aa993b | 11551 | |
c906108c | 11552 | if (sals.nelts != 1) |
8a3fe4f8 | 11553 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11554 | |
c906108c | 11555 | sal = sals.sals[0]; |
4a64f543 | 11556 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11557 | |
c906108c | 11558 | if (*arg) |
8a3fe4f8 | 11559 | error (_("Junk at end of arguments.")); |
c5aa993b | 11560 | |
c906108c | 11561 | resolve_sal_pc (&sal); |
c5aa993b | 11562 | |
186c406b TT |
11563 | tp = inferior_thread (); |
11564 | thread = tp->num; | |
11565 | ||
883bc8d1 PA |
11566 | old_chain = make_cleanup (null_cleanup, NULL); |
11567 | ||
8556afb4 PA |
11568 | /* Note linespec handling above invalidates the frame chain. |
11569 | Installing a breakpoint also invalidates the frame chain (as it | |
11570 | may need to switch threads), so do any frame handling before | |
11571 | that. */ | |
11572 | ||
11573 | frame = get_selected_frame (NULL); | |
11574 | frame_gdbarch = get_frame_arch (frame); | |
11575 | stack_frame_id = get_stack_frame_id (frame); | |
11576 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11577 | |
ae66c1fc EZ |
11578 | /* Keep within the current frame, or in frames called by the current |
11579 | one. */ | |
edb3359d | 11580 | |
883bc8d1 | 11581 | if (frame_id_p (caller_frame_id)) |
c906108c | 11582 | { |
883bc8d1 PA |
11583 | struct symtab_and_line sal2; |
11584 | ||
11585 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11586 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11587 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11588 | sal2, |
11589 | caller_frame_id, | |
f107f563 VP |
11590 | bp_until); |
11591 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11592 | |
883bc8d1 | 11593 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11594 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11595 | } |
c5aa993b | 11596 | |
c70a6932 JK |
11597 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11598 | frame = NULL; | |
11599 | ||
883bc8d1 PA |
11600 | if (anywhere) |
11601 | /* If the user told us to continue until a specified location, | |
11602 | we don't specify a frame at which we need to stop. */ | |
11603 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11604 | null_frame_id, bp_until); | |
11605 | else | |
11606 | /* Otherwise, specify the selected frame, because we want to stop | |
11607 | only at the very same frame. */ | |
11608 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11609 | stack_frame_id, bp_until); | |
11610 | make_cleanup_delete_breakpoint (breakpoint); | |
11611 | ||
a493e3e2 | 11612 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11613 | |
4a64f543 MS |
11614 | /* If we are running asynchronously, and proceed call above has |
11615 | actually managed to start the target, arrange for breakpoints to | |
11616 | be deleted when the target stops. Otherwise, we're already | |
11617 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11618 | |
8ea051c5 | 11619 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11620 | { |
bfec99b2 PA |
11621 | struct until_break_command_continuation_args *args; |
11622 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11623 | |
bfec99b2 PA |
11624 | args->breakpoint = breakpoint; |
11625 | args->breakpoint2 = breakpoint2; | |
186c406b | 11626 | args->thread_num = thread; |
f107f563 VP |
11627 | |
11628 | discard_cleanups (old_chain); | |
95e54da7 PA |
11629 | add_continuation (inferior_thread (), |
11630 | until_break_command_continuation, args, | |
604ead4a | 11631 | xfree); |
f107f563 VP |
11632 | } |
11633 | else | |
c5aa993b | 11634 | do_cleanups (old_chain); |
c906108c | 11635 | } |
ae66c1fc | 11636 | |
c906108c SS |
11637 | /* This function attempts to parse an optional "if <cond>" clause |
11638 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11639 | |
c906108c SS |
11640 | Else, it returns a pointer to the condition string. (It does not |
11641 | attempt to evaluate the string against a particular block.) And, | |
11642 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11643 | if clause in the arg string. */ |
53a5351d | 11644 | |
916703c0 | 11645 | char * |
fba45db2 | 11646 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11647 | { |
c5aa993b JM |
11648 | char *cond_string; |
11649 | ||
11650 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11651 | return NULL; |
c5aa993b | 11652 | |
4a64f543 | 11653 | /* Skip the "if" keyword. */ |
c906108c | 11654 | (*arg) += 2; |
c5aa993b | 11655 | |
c906108c | 11656 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11657 | condition string. */ |
e9cafbcc | 11658 | *arg = skip_spaces (*arg); |
c906108c | 11659 | cond_string = *arg; |
c5aa993b | 11660 | |
4a64f543 MS |
11661 | /* Assume that the condition occupies the remainder of the arg |
11662 | string. */ | |
c906108c | 11663 | (*arg) += strlen (cond_string); |
c5aa993b | 11664 | |
c906108c SS |
11665 | return cond_string; |
11666 | } | |
c5aa993b | 11667 | |
c906108c SS |
11668 | /* Commands to deal with catching events, such as signals, exceptions, |
11669 | process start/exit, etc. */ | |
c5aa993b JM |
11670 | |
11671 | typedef enum | |
11672 | { | |
44feb3ce TT |
11673 | catch_fork_temporary, catch_vfork_temporary, |
11674 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11675 | } |
11676 | catch_fork_kind; | |
11677 | ||
c906108c | 11678 | static void |
cc59ec59 MS |
11679 | catch_fork_command_1 (char *arg, int from_tty, |
11680 | struct cmd_list_element *command) | |
c906108c | 11681 | { |
a6d9a66e | 11682 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11683 | char *cond_string = NULL; |
44feb3ce TT |
11684 | catch_fork_kind fork_kind; |
11685 | int tempflag; | |
11686 | ||
11687 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11688 | tempflag = (fork_kind == catch_fork_temporary | |
11689 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11690 | |
44feb3ce TT |
11691 | if (!arg) |
11692 | arg = ""; | |
e9cafbcc | 11693 | arg = skip_spaces (arg); |
c5aa993b | 11694 | |
c906108c | 11695 | /* The allowed syntax is: |
c5aa993b JM |
11696 | catch [v]fork |
11697 | catch [v]fork if <cond> | |
11698 | ||
4a64f543 | 11699 | First, check if there's an if clause. */ |
c906108c | 11700 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11701 | |
c906108c | 11702 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11703 | error (_("Junk at end of arguments.")); |
c5aa993b | 11704 | |
c906108c | 11705 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11706 | and enable reporting of such events. */ |
c5aa993b JM |
11707 | switch (fork_kind) |
11708 | { | |
44feb3ce TT |
11709 | case catch_fork_temporary: |
11710 | case catch_fork_permanent: | |
a6d9a66e | 11711 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11712 | &catch_fork_breakpoint_ops); |
c906108c | 11713 | break; |
44feb3ce TT |
11714 | case catch_vfork_temporary: |
11715 | case catch_vfork_permanent: | |
a6d9a66e | 11716 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11717 | &catch_vfork_breakpoint_ops); |
c906108c | 11718 | break; |
c5aa993b | 11719 | default: |
8a3fe4f8 | 11720 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11721 | break; |
c5aa993b | 11722 | } |
c906108c SS |
11723 | } |
11724 | ||
11725 | static void | |
cc59ec59 MS |
11726 | catch_exec_command_1 (char *arg, int from_tty, |
11727 | struct cmd_list_element *command) | |
c906108c | 11728 | { |
b4d90040 | 11729 | struct exec_catchpoint *c; |
a6d9a66e | 11730 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11731 | int tempflag; |
c5aa993b | 11732 | char *cond_string = NULL; |
c906108c | 11733 | |
44feb3ce TT |
11734 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11735 | ||
11736 | if (!arg) | |
11737 | arg = ""; | |
e9cafbcc | 11738 | arg = skip_spaces (arg); |
c906108c SS |
11739 | |
11740 | /* The allowed syntax is: | |
c5aa993b JM |
11741 | catch exec |
11742 | catch exec if <cond> | |
c906108c | 11743 | |
4a64f543 | 11744 | First, check if there's an if clause. */ |
c906108c SS |
11745 | cond_string = ep_parse_optional_if_clause (&arg); |
11746 | ||
11747 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11748 | error (_("Junk at end of arguments.")); |
c906108c | 11749 | |
b4d90040 PA |
11750 | c = XNEW (struct exec_catchpoint); |
11751 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11752 | &catch_exec_breakpoint_ops); | |
11753 | c->exec_pathname = NULL; | |
11754 | ||
3ea46bff | 11755 | install_breakpoint (0, &c->base, 1); |
c906108c | 11756 | } |
c5aa993b | 11757 | |
9ac4176b | 11758 | void |
28010a5d PA |
11759 | init_ada_exception_breakpoint (struct breakpoint *b, |
11760 | struct gdbarch *gdbarch, | |
11761 | struct symtab_and_line sal, | |
11762 | char *addr_string, | |
c0a91b2b | 11763 | const struct breakpoint_ops *ops, |
28010a5d | 11764 | int tempflag, |
349774ef | 11765 | int enabled, |
28010a5d | 11766 | int from_tty) |
f7f9143b | 11767 | { |
f7f9143b JB |
11768 | if (from_tty) |
11769 | { | |
5af949e3 UW |
11770 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11771 | if (!loc_gdbarch) | |
11772 | loc_gdbarch = gdbarch; | |
11773 | ||
6c95b8df PA |
11774 | describe_other_breakpoints (loc_gdbarch, |
11775 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11776 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11777 | version for exception catchpoints, because two catchpoints | |
11778 | used for different exception names will use the same address. | |
11779 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11780 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11781 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11782 | the user what type of catchpoint it is. The above is good |
11783 | enough for now, though. */ | |
11784 | } | |
11785 | ||
28010a5d | 11786 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11787 | |
349774ef | 11788 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11789 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11790 | b->addr_string = addr_string; |
11791 | b->language = language_ada; | |
f7f9143b JB |
11792 | } |
11793 | ||
a96d9b2e SDJ |
11794 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
11795 | filter list, or NULL if no filtering is required. */ | |
11796 | static VEC(int) * | |
11797 | catch_syscall_split_args (char *arg) | |
11798 | { | |
11799 | VEC(int) *result = NULL; | |
29d0bb3d | 11800 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
11801 | |
11802 | while (*arg != '\0') | |
11803 | { | |
11804 | int i, syscall_number; | |
11805 | char *endptr; | |
11806 | char cur_name[128]; | |
11807 | struct syscall s; | |
11808 | ||
11809 | /* Skip whitespace. */ | |
529480d0 | 11810 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11811 | |
11812 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
11813 | cur_name[i] = arg[i]; | |
11814 | cur_name[i] = '\0'; | |
11815 | arg += i; | |
11816 | ||
11817 | /* Check if the user provided a syscall name or a number. */ | |
11818 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
11819 | if (*endptr == '\0') | |
bccd0dd2 | 11820 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
11821 | else |
11822 | { | |
11823 | /* We have a name. Let's check if it's valid and convert it | |
11824 | to a number. */ | |
11825 | get_syscall_by_name (cur_name, &s); | |
11826 | ||
11827 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
11828 | /* Here we have to issue an error instead of a warning, |
11829 | because GDB cannot do anything useful if there's no | |
11830 | syscall number to be caught. */ | |
a96d9b2e SDJ |
11831 | error (_("Unknown syscall name '%s'."), cur_name); |
11832 | } | |
11833 | ||
11834 | /* Ok, it's valid. */ | |
11835 | VEC_safe_push (int, result, s.number); | |
11836 | } | |
11837 | ||
11838 | discard_cleanups (cleanup); | |
11839 | return result; | |
11840 | } | |
11841 | ||
11842 | /* Implement the "catch syscall" command. */ | |
11843 | ||
11844 | static void | |
cc59ec59 MS |
11845 | catch_syscall_command_1 (char *arg, int from_tty, |
11846 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
11847 | { |
11848 | int tempflag; | |
11849 | VEC(int) *filter; | |
11850 | struct syscall s; | |
11851 | struct gdbarch *gdbarch = get_current_arch (); | |
11852 | ||
11853 | /* Checking if the feature if supported. */ | |
11854 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
11855 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 11856 | this architecture yet.")); |
a96d9b2e SDJ |
11857 | |
11858 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
11859 | ||
e9cafbcc | 11860 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
11861 | |
11862 | /* We need to do this first "dummy" translation in order | |
11863 | to get the syscall XML file loaded or, most important, | |
11864 | to display a warning to the user if there's no XML file | |
11865 | for his/her architecture. */ | |
11866 | get_syscall_by_number (0, &s); | |
11867 | ||
11868 | /* The allowed syntax is: | |
11869 | catch syscall | |
11870 | catch syscall <name | number> [<name | number> ... <name | number>] | |
11871 | ||
11872 | Let's check if there's a syscall name. */ | |
11873 | ||
11874 | if (arg != NULL) | |
11875 | filter = catch_syscall_split_args (arg); | |
11876 | else | |
11877 | filter = NULL; | |
11878 | ||
11879 | create_syscall_event_catchpoint (tempflag, filter, | |
11880 | &catch_syscall_breakpoint_ops); | |
11881 | } | |
11882 | ||
c906108c | 11883 | static void |
fba45db2 | 11884 | catch_command (char *arg, int from_tty) |
c906108c | 11885 | { |
44feb3ce | 11886 | error (_("Catch requires an event name.")); |
c906108c SS |
11887 | } |
11888 | \f | |
11889 | ||
11890 | static void | |
fba45db2 | 11891 | tcatch_command (char *arg, int from_tty) |
c906108c | 11892 | { |
44feb3ce | 11893 | error (_("Catch requires an event name.")); |
c906108c SS |
11894 | } |
11895 | ||
8a2c437b TT |
11896 | /* A qsort comparison function that sorts breakpoints in order. */ |
11897 | ||
11898 | static int | |
11899 | compare_breakpoints (const void *a, const void *b) | |
11900 | { | |
11901 | const breakpoint_p *ba = a; | |
11902 | uintptr_t ua = (uintptr_t) *ba; | |
11903 | const breakpoint_p *bb = b; | |
11904 | uintptr_t ub = (uintptr_t) *bb; | |
11905 | ||
11906 | if ((*ba)->number < (*bb)->number) | |
11907 | return -1; | |
11908 | else if ((*ba)->number > (*bb)->number) | |
11909 | return 1; | |
11910 | ||
11911 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11912 | the number 0. */ | |
11913 | if (ua < ub) | |
11914 | return -1; | |
94b0e70d | 11915 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11916 | } |
11917 | ||
80f8a6eb | 11918 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11919 | |
11920 | static void | |
fba45db2 | 11921 | clear_command (char *arg, int from_tty) |
c906108c | 11922 | { |
8a2c437b | 11923 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11924 | VEC(breakpoint_p) *found = 0; |
11925 | int ix; | |
c906108c SS |
11926 | int default_match; |
11927 | struct symtabs_and_lines sals; | |
11928 | struct symtab_and_line sal; | |
c906108c | 11929 | int i; |
8a2c437b | 11930 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11931 | |
11932 | if (arg) | |
11933 | { | |
39cf75f7 DE |
11934 | sals = decode_line_with_current_source (arg, |
11935 | (DECODE_LINE_FUNFIRSTLINE | |
11936 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11937 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11938 | default_match = 0; |
11939 | } | |
11940 | else | |
11941 | { | |
c5aa993b | 11942 | sals.sals = (struct symtab_and_line *) |
c906108c | 11943 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11944 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11945 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11946 | |
11947 | /* Set sal's line, symtab, pc, and pspace to the values | |
11948 | corresponding to the last call to print_frame_info. If the | |
11949 | codepoint is not valid, this will set all the fields to 0. */ | |
11950 | get_last_displayed_sal (&sal); | |
c906108c | 11951 | if (sal.symtab == 0) |
8a3fe4f8 | 11952 | error (_("No source file specified.")); |
c906108c SS |
11953 | |
11954 | sals.sals[0] = sal; | |
11955 | sals.nelts = 1; | |
11956 | ||
11957 | default_match = 1; | |
11958 | } | |
11959 | ||
4a64f543 MS |
11960 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11961 | seems, because all existing breakpoints typically have both | |
11962 | file/line and pc set. So, if clear is given file/line, we can | |
11963 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11964 | |
11965 | We only support clearing given the address explicitly | |
11966 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11967 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11968 | due to optimization, all in one block. |
4a64f543 MS |
11969 | |
11970 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11971 | PC corresponding to the same file:line, the breakpoint won't |
11972 | be cleared. We probably can still clear the breakpoint, but | |
11973 | since the other PC value is never presented to user, user | |
11974 | can only find it by guessing, and it does not seem important | |
11975 | to support that. */ | |
11976 | ||
4a64f543 MS |
11977 | /* For each line spec given, delete bps which correspond to it. Do |
11978 | it in two passes, solely to preserve the current behavior that | |
11979 | from_tty is forced true if we delete more than one | |
11980 | breakpoint. */ | |
c906108c | 11981 | |
80f8a6eb | 11982 | found = NULL; |
8a2c437b | 11983 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11984 | for (i = 0; i < sals.nelts; i++) |
11985 | { | |
05cba821 JK |
11986 | const char *sal_fullname; |
11987 | ||
c906108c | 11988 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11989 | If line given (pc == 0), clear all bpts on specified line. |
11990 | If defaulting, clear all bpts on default line | |
c906108c | 11991 | or at default pc. |
c5aa993b JM |
11992 | |
11993 | defaulting sal.pc != 0 tests to do | |
11994 | ||
11995 | 0 1 pc | |
11996 | 1 1 pc _and_ line | |
11997 | 0 0 line | |
11998 | 1 0 <can't happen> */ | |
c906108c SS |
11999 | |
12000 | sal = sals.sals[i]; | |
05cba821 JK |
12001 | sal_fullname = (sal.symtab == NULL |
12002 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12003 | |
4a64f543 | 12004 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12005 | ALL_BREAKPOINTS (b) |
c5aa993b | 12006 | { |
0d381245 | 12007 | int match = 0; |
4a64f543 | 12008 | /* Are we going to delete b? */ |
cc60f2e3 | 12009 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12010 | { |
12011 | struct bp_location *loc = b->loc; | |
12012 | for (; loc; loc = loc->next) | |
12013 | { | |
f8eba3c6 TT |
12014 | /* If the user specified file:line, don't allow a PC |
12015 | match. This matches historical gdb behavior. */ | |
12016 | int pc_match = (!sal.explicit_line | |
12017 | && sal.pc | |
12018 | && (loc->pspace == sal.pspace) | |
12019 | && (loc->address == sal.pc) | |
12020 | && (!section_is_overlay (loc->section) | |
12021 | || loc->section == sal.section)); | |
4aac40c8 TT |
12022 | int line_match = 0; |
12023 | ||
12024 | if ((default_match || sal.explicit_line) | |
2f202fde | 12025 | && loc->symtab != NULL |
05cba821 | 12026 | && sal_fullname != NULL |
4aac40c8 | 12027 | && sal.pspace == loc->pspace |
05cba821 JK |
12028 | && loc->line_number == sal.line |
12029 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12030 | sal_fullname) == 0) | |
12031 | line_match = 1; | |
4aac40c8 | 12032 | |
0d381245 VP |
12033 | if (pc_match || line_match) |
12034 | { | |
12035 | match = 1; | |
12036 | break; | |
12037 | } | |
12038 | } | |
12039 | } | |
12040 | ||
12041 | if (match) | |
d6e956e5 | 12042 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12043 | } |
80f8a6eb | 12044 | } |
8a2c437b | 12045 | |
80f8a6eb | 12046 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12047 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12048 | { |
12049 | if (arg) | |
8a3fe4f8 | 12050 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12051 | else |
8a3fe4f8 | 12052 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12053 | } |
c906108c | 12054 | |
8a2c437b TT |
12055 | /* Remove duplicates from the vec. */ |
12056 | qsort (VEC_address (breakpoint_p, found), | |
12057 | VEC_length (breakpoint_p, found), | |
12058 | sizeof (breakpoint_p), | |
12059 | compare_breakpoints); | |
12060 | prev = VEC_index (breakpoint_p, found, 0); | |
12061 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12062 | { | |
12063 | if (b == prev) | |
12064 | { | |
12065 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12066 | --ix; | |
12067 | } | |
12068 | } | |
12069 | ||
d6e956e5 | 12070 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12071 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12072 | if (from_tty) |
a3f17187 | 12073 | { |
d6e956e5 | 12074 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12075 | printf_unfiltered (_("Deleted breakpoint ")); |
12076 | else | |
12077 | printf_unfiltered (_("Deleted breakpoints ")); | |
12078 | } | |
d6e956e5 VP |
12079 | |
12080 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12081 | { |
c5aa993b | 12082 | if (from_tty) |
d6e956e5 VP |
12083 | printf_unfiltered ("%d ", b->number); |
12084 | delete_breakpoint (b); | |
c906108c | 12085 | } |
80f8a6eb MS |
12086 | if (from_tty) |
12087 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12088 | |
12089 | do_cleanups (cleanups); | |
c906108c SS |
12090 | } |
12091 | \f | |
12092 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12093 | all breakpoints that are marked for deletion, whether hit or not. | |
12094 | This is called after any breakpoint is hit, or after errors. */ | |
12095 | ||
12096 | void | |
fba45db2 | 12097 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12098 | { |
35df4500 | 12099 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12100 | |
12101 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12102 | if (bs->breakpoint_at |
12103 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12104 | && bs->stop) |
f431efe5 | 12105 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12106 | |
35df4500 | 12107 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12108 | { |
b5de0fa7 | 12109 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12110 | delete_breakpoint (b); |
12111 | } | |
c906108c SS |
12112 | } |
12113 | ||
4a64f543 MS |
12114 | /* A comparison function for bp_location AP and BP being interfaced to |
12115 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12116 | does breakpoint_address_is_meaningful say for its OWNER), | |
12117 | secondarily by ordering first bp_permanent OWNERed elements and | |
12118 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12119 | qsort being an unstable algorithm. */ |
876fa593 JK |
12120 | |
12121 | static int | |
494cfb0f | 12122 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12123 | { |
494cfb0f JK |
12124 | struct bp_location *a = *(void **) ap; |
12125 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12126 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12127 | int a_perm = a->owner->enable_state == bp_permanent; |
12128 | int b_perm = b->owner->enable_state == bp_permanent; | |
12129 | ||
12130 | if (a->address != b->address) | |
12131 | return (a->address > b->address) - (a->address < b->address); | |
12132 | ||
dea2aa5f LM |
12133 | /* Sort locations at the same address by their pspace number, keeping |
12134 | locations of the same inferior (in a multi-inferior environment) | |
12135 | grouped. */ | |
12136 | ||
12137 | if (a->pspace->num != b->pspace->num) | |
12138 | return ((a->pspace->num > b->pspace->num) | |
12139 | - (a->pspace->num < b->pspace->num)); | |
12140 | ||
876fa593 JK |
12141 | /* Sort permanent breakpoints first. */ |
12142 | if (a_perm != b_perm) | |
12143 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12144 | ||
c56a97f9 JK |
12145 | /* Make the internal GDB representation stable across GDB runs |
12146 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12147 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12148 | |
12149 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12150 | return ((a->owner->number > b->owner->number) |
12151 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12152 | |
12153 | return (a > b) - (a < b); | |
12154 | } | |
12155 | ||
876fa593 | 12156 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12157 | bp_location_shadow_len_after_address_max according to the current |
12158 | content of the bp_location array. */ | |
f7545552 TT |
12159 | |
12160 | static void | |
876fa593 | 12161 | bp_location_target_extensions_update (void) |
f7545552 | 12162 | { |
876fa593 JK |
12163 | struct bp_location *bl, **blp_tmp; |
12164 | ||
12165 | bp_location_placed_address_before_address_max = 0; | |
12166 | bp_location_shadow_len_after_address_max = 0; | |
12167 | ||
12168 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12169 | { | |
12170 | CORE_ADDR start, end, addr; | |
12171 | ||
12172 | if (!bp_location_has_shadow (bl)) | |
12173 | continue; | |
12174 | ||
12175 | start = bl->target_info.placed_address; | |
12176 | end = start + bl->target_info.shadow_len; | |
12177 | ||
12178 | gdb_assert (bl->address >= start); | |
12179 | addr = bl->address - start; | |
12180 | if (addr > bp_location_placed_address_before_address_max) | |
12181 | bp_location_placed_address_before_address_max = addr; | |
12182 | ||
12183 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12184 | ||
12185 | gdb_assert (bl->address < end); | |
12186 | addr = end - bl->address; | |
12187 | if (addr > bp_location_shadow_len_after_address_max) | |
12188 | bp_location_shadow_len_after_address_max = addr; | |
12189 | } | |
f7545552 TT |
12190 | } |
12191 | ||
1e4d1764 YQ |
12192 | /* Download tracepoint locations if they haven't been. */ |
12193 | ||
12194 | static void | |
12195 | download_tracepoint_locations (void) | |
12196 | { | |
7ed2c994 | 12197 | struct breakpoint *b; |
1e4d1764 YQ |
12198 | struct cleanup *old_chain; |
12199 | ||
12200 | if (!target_can_download_tracepoint ()) | |
12201 | return; | |
12202 | ||
12203 | old_chain = save_current_space_and_thread (); | |
12204 | ||
7ed2c994 | 12205 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12206 | { |
7ed2c994 | 12207 | struct bp_location *bl; |
1e4d1764 | 12208 | struct tracepoint *t; |
f2a8bc8a | 12209 | int bp_location_downloaded = 0; |
1e4d1764 | 12210 | |
7ed2c994 | 12211 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12212 | ? !may_insert_fast_tracepoints |
12213 | : !may_insert_tracepoints)) | |
12214 | continue; | |
12215 | ||
7ed2c994 YQ |
12216 | for (bl = b->loc; bl; bl = bl->next) |
12217 | { | |
12218 | /* In tracepoint, locations are _never_ duplicated, so | |
12219 | should_be_inserted is equivalent to | |
12220 | unduplicated_should_be_inserted. */ | |
12221 | if (!should_be_inserted (bl) || bl->inserted) | |
12222 | continue; | |
1e4d1764 | 12223 | |
7ed2c994 | 12224 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12225 | |
7ed2c994 | 12226 | target_download_tracepoint (bl); |
1e4d1764 | 12227 | |
7ed2c994 | 12228 | bl->inserted = 1; |
f2a8bc8a | 12229 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12230 | } |
12231 | t = (struct tracepoint *) b; | |
12232 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12233 | if (bp_location_downloaded) |
12234 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12235 | } |
12236 | ||
12237 | do_cleanups (old_chain); | |
12238 | } | |
12239 | ||
934709f0 PW |
12240 | /* Swap the insertion/duplication state between two locations. */ |
12241 | ||
12242 | static void | |
12243 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12244 | { | |
12245 | const int left_inserted = left->inserted; | |
12246 | const int left_duplicate = left->duplicate; | |
b775012e | 12247 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12248 | const struct bp_target_info left_target_info = left->target_info; |
12249 | ||
1e4d1764 YQ |
12250 | /* Locations of tracepoints can never be duplicated. */ |
12251 | if (is_tracepoint (left->owner)) | |
12252 | gdb_assert (!left->duplicate); | |
12253 | if (is_tracepoint (right->owner)) | |
12254 | gdb_assert (!right->duplicate); | |
12255 | ||
934709f0 PW |
12256 | left->inserted = right->inserted; |
12257 | left->duplicate = right->duplicate; | |
b775012e | 12258 | left->needs_update = right->needs_update; |
934709f0 PW |
12259 | left->target_info = right->target_info; |
12260 | right->inserted = left_inserted; | |
12261 | right->duplicate = left_duplicate; | |
b775012e | 12262 | right->needs_update = left_needs_update; |
934709f0 PW |
12263 | right->target_info = left_target_info; |
12264 | } | |
12265 | ||
b775012e LM |
12266 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12267 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12268 | conditions on the target's side. Such conditions need to be updated on | |
12269 | the target. */ | |
12270 | ||
12271 | static void | |
12272 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12273 | { | |
12274 | struct bp_location **locp = NULL, **loc2p; | |
12275 | struct bp_location *loc; | |
12276 | CORE_ADDR address = 0; | |
12277 | int pspace_num; | |
12278 | ||
12279 | address = bl->address; | |
12280 | pspace_num = bl->pspace->num; | |
12281 | ||
12282 | /* This is only meaningful if the target is | |
12283 | evaluating conditions and if the user has | |
12284 | opted for condition evaluation on the target's | |
12285 | side. */ | |
12286 | if (gdb_evaluates_breakpoint_condition_p () | |
12287 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12288 | return; | |
12289 | ||
12290 | /* Flag all breakpoint locations with this address and | |
12291 | the same program space as the location | |
12292 | as "its condition has changed". We need to | |
12293 | update the conditions on the target's side. */ | |
12294 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12295 | { | |
12296 | loc = *loc2p; | |
12297 | ||
12298 | if (!is_breakpoint (loc->owner) | |
12299 | || pspace_num != loc->pspace->num) | |
12300 | continue; | |
12301 | ||
12302 | /* Flag the location appropriately. We use a different state to | |
12303 | let everyone know that we already updated the set of locations | |
12304 | with addr bl->address and program space bl->pspace. This is so | |
12305 | we don't have to keep calling these functions just to mark locations | |
12306 | that have already been marked. */ | |
12307 | loc->condition_changed = condition_updated; | |
12308 | ||
12309 | /* Free the agent expression bytecode as well. We will compute | |
12310 | it later on. */ | |
12311 | if (loc->cond_bytecode) | |
12312 | { | |
12313 | free_agent_expr (loc->cond_bytecode); | |
12314 | loc->cond_bytecode = NULL; | |
12315 | } | |
12316 | } | |
12317 | } | |
12318 | ||
4cd9bd08 | 12319 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
12320 | into the inferior, only remove already-inserted locations that no |
12321 | longer should be inserted. Functions that delete a breakpoint or | |
12322 | breakpoints should pass false, so that deleting a breakpoint | |
12323 | doesn't have the side effect of inserting the locations of other | |
12324 | breakpoints that are marked not-inserted, but should_be_inserted | |
12325 | returns true on them. | |
12326 | ||
12327 | This behaviour is useful is situations close to tear-down -- e.g., | |
12328 | after an exec, while the target still has execution, but breakpoint | |
12329 | shadows of the previous executable image should *NOT* be restored | |
12330 | to the new image; or before detaching, where the target still has | |
12331 | execution and wants to delete breakpoints from GDB's lists, and all | |
12332 | breakpoints had already been removed from the inferior. */ | |
12333 | ||
0d381245 | 12334 | static void |
b60e7edf | 12335 | update_global_location_list (int should_insert) |
0d381245 | 12336 | { |
74960c60 | 12337 | struct breakpoint *b; |
876fa593 | 12338 | struct bp_location **locp, *loc; |
f7545552 | 12339 | struct cleanup *cleanups; |
b775012e LM |
12340 | /* Last breakpoint location address that was marked for update. */ |
12341 | CORE_ADDR last_addr = 0; | |
12342 | /* Last breakpoint location program space that was marked for update. */ | |
12343 | int last_pspace_num = -1; | |
f7545552 | 12344 | |
2d134ed3 PA |
12345 | /* Used in the duplicates detection below. When iterating over all |
12346 | bp_locations, points to the first bp_location of a given address. | |
12347 | Breakpoints and watchpoints of different types are never | |
12348 | duplicates of each other. Keep one pointer for each type of | |
12349 | breakpoint/watchpoint, so we only need to loop over all locations | |
12350 | once. */ | |
12351 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12352 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12353 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12354 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12355 | |
4a64f543 MS |
12356 | /* Saved former bp_location array which we compare against the newly |
12357 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12358 | struct bp_location **old_location, **old_locp; |
12359 | unsigned old_location_count; | |
12360 | ||
12361 | old_location = bp_location; | |
12362 | old_location_count = bp_location_count; | |
12363 | bp_location = NULL; | |
12364 | bp_location_count = 0; | |
12365 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12366 | |
74960c60 | 12367 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12368 | for (loc = b->loc; loc; loc = loc->next) |
12369 | bp_location_count++; | |
12370 | ||
12371 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12372 | locp = bp_location; | |
12373 | ALL_BREAKPOINTS (b) | |
12374 | for (loc = b->loc; loc; loc = loc->next) | |
12375 | *locp++ = loc; | |
12376 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12377 | bp_location_compare); |
876fa593 JK |
12378 | |
12379 | bp_location_target_extensions_update (); | |
74960c60 | 12380 | |
4a64f543 MS |
12381 | /* Identify bp_location instances that are no longer present in the |
12382 | new list, and therefore should be freed. Note that it's not | |
12383 | necessary that those locations should be removed from inferior -- | |
12384 | if there's another location at the same address (previously | |
12385 | marked as duplicate), we don't need to remove/insert the | |
12386 | location. | |
876fa593 | 12387 | |
4a64f543 MS |
12388 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12389 | and former bp_location array state respectively. */ | |
876fa593 JK |
12390 | |
12391 | locp = bp_location; | |
12392 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12393 | old_locp++) | |
74960c60 | 12394 | { |
876fa593 | 12395 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12396 | struct bp_location **loc2p; |
876fa593 | 12397 | |
e5dd4106 | 12398 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12399 | not, we have to free it. */ |
c7d46a38 | 12400 | int found_object = 0; |
20874c92 VP |
12401 | /* Tells if the location should remain inserted in the target. */ |
12402 | int keep_in_target = 0; | |
12403 | int removed = 0; | |
876fa593 | 12404 | |
4a64f543 MS |
12405 | /* Skip LOCP entries which will definitely never be needed. |
12406 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12407 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12408 | && (*locp)->address < old_loc->address) |
876fa593 | 12409 | locp++; |
c7d46a38 PA |
12410 | |
12411 | for (loc2p = locp; | |
12412 | (loc2p < bp_location + bp_location_count | |
12413 | && (*loc2p)->address == old_loc->address); | |
12414 | loc2p++) | |
12415 | { | |
b775012e LM |
12416 | /* Check if this is a new/duplicated location or a duplicated |
12417 | location that had its condition modified. If so, we want to send | |
12418 | its condition to the target if evaluation of conditions is taking | |
12419 | place there. */ | |
12420 | if ((*loc2p)->condition_changed == condition_modified | |
12421 | && (last_addr != old_loc->address | |
12422 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12423 | { |
b775012e LM |
12424 | force_breakpoint_reinsertion (*loc2p); |
12425 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12426 | } |
b775012e LM |
12427 | |
12428 | if (*loc2p == old_loc) | |
12429 | found_object = 1; | |
c7d46a38 | 12430 | } |
74960c60 | 12431 | |
b775012e LM |
12432 | /* We have already handled this address, update it so that we don't |
12433 | have to go through updates again. */ | |
12434 | last_addr = old_loc->address; | |
12435 | ||
12436 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12437 | if (!found_object) | |
12438 | force_breakpoint_reinsertion (old_loc); | |
12439 | ||
4a64f543 MS |
12440 | /* If this location is no longer present, and inserted, look if |
12441 | there's maybe a new location at the same address. If so, | |
12442 | mark that one inserted, and don't remove this one. This is | |
12443 | needed so that we don't have a time window where a breakpoint | |
12444 | at certain location is not inserted. */ | |
74960c60 | 12445 | |
876fa593 | 12446 | if (old_loc->inserted) |
0d381245 | 12447 | { |
4a64f543 MS |
12448 | /* If the location is inserted now, we might have to remove |
12449 | it. */ | |
74960c60 | 12450 | |
876fa593 | 12451 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12452 | { |
4a64f543 MS |
12453 | /* The location is still present in the location list, |
12454 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12455 | keep_in_target = 1; |
74960c60 VP |
12456 | } |
12457 | else | |
12458 | { | |
b775012e LM |
12459 | /* This location still exists, but it won't be kept in the |
12460 | target since it may have been disabled. We proceed to | |
12461 | remove its target-side condition. */ | |
12462 | ||
4a64f543 MS |
12463 | /* The location is either no longer present, or got |
12464 | disabled. See if there's another location at the | |
12465 | same address, in which case we don't need to remove | |
12466 | this one from the target. */ | |
876fa593 | 12467 | |
2bdf28a0 | 12468 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12469 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12470 | { | |
876fa593 | 12471 | for (loc2p = locp; |
c7d46a38 PA |
12472 | (loc2p < bp_location + bp_location_count |
12473 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12474 | loc2p++) |
12475 | { | |
12476 | struct bp_location *loc2 = *loc2p; | |
12477 | ||
2d134ed3 | 12478 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12479 | { |
85d721b8 PA |
12480 | /* Read watchpoint locations are switched to |
12481 | access watchpoints, if the former are not | |
12482 | supported, but the latter are. */ | |
12483 | if (is_hardware_watchpoint (old_loc->owner)) | |
12484 | { | |
12485 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12486 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12487 | } | |
12488 | ||
934709f0 PW |
12489 | /* loc2 is a duplicated location. We need to check |
12490 | if it should be inserted in case it will be | |
12491 | unduplicated. */ | |
12492 | if (loc2 != old_loc | |
12493 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12494 | { |
934709f0 | 12495 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12496 | keep_in_target = 1; |
12497 | break; | |
12498 | } | |
876fa593 JK |
12499 | } |
12500 | } | |
12501 | } | |
74960c60 VP |
12502 | } |
12503 | ||
20874c92 VP |
12504 | if (!keep_in_target) |
12505 | { | |
876fa593 | 12506 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12507 | { |
4a64f543 MS |
12508 | /* This is just about all we can do. We could keep |
12509 | this location on the global list, and try to | |
12510 | remove it next time, but there's no particular | |
12511 | reason why we will succeed next time. | |
20874c92 | 12512 | |
4a64f543 MS |
12513 | Note that at this point, old_loc->owner is still |
12514 | valid, as delete_breakpoint frees the breakpoint | |
12515 | only after calling us. */ | |
3e43a32a MS |
12516 | printf_filtered (_("warning: Error removing " |
12517 | "breakpoint %d\n"), | |
876fa593 | 12518 | old_loc->owner->number); |
20874c92 VP |
12519 | } |
12520 | removed = 1; | |
12521 | } | |
0d381245 | 12522 | } |
74960c60 VP |
12523 | |
12524 | if (!found_object) | |
1c5cfe86 | 12525 | { |
db82e815 PA |
12526 | if (removed && non_stop |
12527 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12528 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12529 | { |
db82e815 PA |
12530 | /* This location was removed from the target. In |
12531 | non-stop mode, a race condition is possible where | |
12532 | we've removed a breakpoint, but stop events for that | |
12533 | breakpoint are already queued and will arrive later. | |
12534 | We apply an heuristic to be able to distinguish such | |
12535 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12536 | breakpoint location for a bit, and will retire it | |
12537 | after we see some number of events. The theory here | |
12538 | is that reporting of events should, "on the average", | |
12539 | be fair, so after a while we'll see events from all | |
12540 | threads that have anything of interest, and no longer | |
12541 | need to keep this breakpoint location around. We | |
12542 | don't hold locations forever so to reduce chances of | |
12543 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12544 | SIGTRAP. | |
12545 | ||
12546 | The heuristic failing can be disastrous on | |
12547 | decr_pc_after_break targets. | |
12548 | ||
12549 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12550 | if we fail to recognize a late breakpoint SIGTRAP, | |
12551 | because events_till_retirement has reached 0 too | |
12552 | soon, we'll fail to do the PC adjustment, and report | |
12553 | a random SIGTRAP to the user. When the user resumes | |
12554 | the inferior, it will most likely immediately crash | |
2dec564e | 12555 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12556 | corrupted, because of being resumed e.g., in the |
12557 | middle of a multi-byte instruction, or skipped a | |
12558 | one-byte instruction. This was actually seen happen | |
12559 | on native x86-linux, and should be less rare on | |
12560 | targets that do not support new thread events, like | |
12561 | remote, due to the heuristic depending on | |
12562 | thread_count. | |
12563 | ||
12564 | Mistaking a random SIGTRAP for a breakpoint trap | |
12565 | causes similar symptoms (PC adjustment applied when | |
12566 | it shouldn't), but then again, playing with SIGTRAPs | |
12567 | behind the debugger's back is asking for trouble. | |
12568 | ||
12569 | Since hardware watchpoint traps are always | |
12570 | distinguishable from other traps, so we don't need to | |
12571 | apply keep hardware watchpoint moribund locations | |
12572 | around. We simply always ignore hardware watchpoint | |
12573 | traps we can no longer explain. */ | |
12574 | ||
876fa593 JK |
12575 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12576 | old_loc->owner = NULL; | |
20874c92 | 12577 | |
876fa593 | 12578 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12579 | } |
12580 | else | |
f431efe5 PA |
12581 | { |
12582 | old_loc->owner = NULL; | |
12583 | decref_bp_location (&old_loc); | |
12584 | } | |
20874c92 | 12585 | } |
74960c60 | 12586 | } |
1c5cfe86 | 12587 | |
348d480f PA |
12588 | /* Rescan breakpoints at the same address and section, marking the |
12589 | first one as "first" and any others as "duplicates". This is so | |
12590 | that the bpt instruction is only inserted once. If we have a | |
12591 | permanent breakpoint at the same place as BPT, make that one the | |
12592 | official one, and the rest as duplicates. Permanent breakpoints | |
12593 | are sorted first for the same address. | |
12594 | ||
12595 | Do the same for hardware watchpoints, but also considering the | |
12596 | watchpoint's type (regular/access/read) and length. */ | |
12597 | ||
12598 | bp_loc_first = NULL; | |
12599 | wp_loc_first = NULL; | |
12600 | awp_loc_first = NULL; | |
12601 | rwp_loc_first = NULL; | |
12602 | ALL_BP_LOCATIONS (loc, locp) | |
12603 | { | |
12604 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12605 | non-NULL. */ | |
348d480f | 12606 | struct bp_location **loc_first_p; |
d3fbdd86 | 12607 | b = loc->owner; |
348d480f | 12608 | |
6f380991 | 12609 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12610 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12611 | /* Don't detect duplicate for tracepoint locations because they are |
12612 | never duplicated. See the comments in field `duplicate' of | |
12613 | `struct bp_location'. */ | |
348d480f | 12614 | || is_tracepoint (b)) |
b775012e LM |
12615 | { |
12616 | /* Clear the condition modification flag. */ | |
12617 | loc->condition_changed = condition_unchanged; | |
12618 | continue; | |
12619 | } | |
348d480f PA |
12620 | |
12621 | /* Permanent breakpoint should always be inserted. */ | |
12622 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12623 | internal_error (__FILE__, __LINE__, | |
12624 | _("allegedly permanent breakpoint is not " | |
12625 | "actually inserted")); | |
12626 | ||
12627 | if (b->type == bp_hardware_watchpoint) | |
12628 | loc_first_p = &wp_loc_first; | |
12629 | else if (b->type == bp_read_watchpoint) | |
12630 | loc_first_p = &rwp_loc_first; | |
12631 | else if (b->type == bp_access_watchpoint) | |
12632 | loc_first_p = &awp_loc_first; | |
12633 | else | |
12634 | loc_first_p = &bp_loc_first; | |
12635 | ||
12636 | if (*loc_first_p == NULL | |
12637 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12638 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12639 | { | |
12640 | *loc_first_p = loc; | |
12641 | loc->duplicate = 0; | |
b775012e LM |
12642 | |
12643 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12644 | { | |
12645 | loc->needs_update = 1; | |
12646 | /* Clear the condition modification flag. */ | |
12647 | loc->condition_changed = condition_unchanged; | |
12648 | } | |
348d480f PA |
12649 | continue; |
12650 | } | |
12651 | ||
934709f0 PW |
12652 | |
12653 | /* This and the above ensure the invariant that the first location | |
12654 | is not duplicated, and is the inserted one. | |
12655 | All following are marked as duplicated, and are not inserted. */ | |
12656 | if (loc->inserted) | |
12657 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12658 | loc->duplicate = 1; |
12659 | ||
b775012e LM |
12660 | /* Clear the condition modification flag. */ |
12661 | loc->condition_changed = condition_unchanged; | |
12662 | ||
348d480f PA |
12663 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12664 | && b->enable_state != bp_permanent) | |
12665 | internal_error (__FILE__, __LINE__, | |
12666 | _("another breakpoint was inserted on top of " | |
12667 | "a permanent breakpoint")); | |
12668 | } | |
12669 | ||
b775012e | 12670 | if (breakpoints_always_inserted_mode () |
348d480f | 12671 | && (have_live_inferiors () |
f5656ead | 12672 | || (gdbarch_has_global_breakpoints (target_gdbarch ())))) |
b775012e LM |
12673 | { |
12674 | if (should_insert) | |
12675 | insert_breakpoint_locations (); | |
12676 | else | |
12677 | { | |
12678 | /* Though should_insert is false, we may need to update conditions | |
12679 | on the target's side if it is evaluating such conditions. We | |
12680 | only update conditions for locations that are marked | |
12681 | "needs_update". */ | |
12682 | update_inserted_breakpoint_locations (); | |
12683 | } | |
12684 | } | |
348d480f | 12685 | |
1e4d1764 YQ |
12686 | if (should_insert) |
12687 | download_tracepoint_locations (); | |
12688 | ||
348d480f PA |
12689 | do_cleanups (cleanups); |
12690 | } | |
12691 | ||
12692 | void | |
12693 | breakpoint_retire_moribund (void) | |
12694 | { | |
12695 | struct bp_location *loc; | |
12696 | int ix; | |
12697 | ||
12698 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12699 | if (--(loc->events_till_retirement) == 0) | |
12700 | { | |
12701 | decref_bp_location (&loc); | |
12702 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12703 | --ix; | |
12704 | } | |
12705 | } | |
12706 | ||
12707 | static void | |
12708 | update_global_location_list_nothrow (int inserting) | |
12709 | { | |
bfd189b1 | 12710 | volatile struct gdb_exception e; |
348d480f PA |
12711 | |
12712 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
12713 | update_global_location_list (inserting); | |
12714 | } | |
12715 | ||
12716 | /* Clear BKP from a BPS. */ | |
12717 | ||
12718 | static void | |
12719 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12720 | { | |
12721 | bpstat bs; | |
12722 | ||
12723 | for (bs = bps; bs; bs = bs->next) | |
12724 | if (bs->breakpoint_at == bpt) | |
12725 | { | |
12726 | bs->breakpoint_at = NULL; | |
12727 | bs->old_val = NULL; | |
12728 | /* bs->commands will be freed later. */ | |
12729 | } | |
12730 | } | |
12731 | ||
12732 | /* Callback for iterate_over_threads. */ | |
12733 | static int | |
12734 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12735 | { | |
12736 | struct breakpoint *bpt = data; | |
12737 | ||
12738 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12739 | return 0; | |
12740 | } | |
12741 | ||
12742 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12743 | callbacks. */ | |
12744 | ||
12745 | static void | |
12746 | say_where (struct breakpoint *b) | |
12747 | { | |
12748 | struct value_print_options opts; | |
12749 | ||
12750 | get_user_print_options (&opts); | |
12751 | ||
12752 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12753 | single string. */ | |
12754 | if (b->loc == NULL) | |
12755 | { | |
12756 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12757 | } | |
12758 | else | |
12759 | { | |
2f202fde | 12760 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12761 | { |
12762 | printf_filtered (" at "); | |
12763 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12764 | gdb_stdout); | |
12765 | } | |
2f202fde | 12766 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12767 | { |
12768 | /* If there is a single location, we can print the location | |
12769 | more nicely. */ | |
12770 | if (b->loc->next == NULL) | |
12771 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12772 | symtab_to_filename_for_display (b->loc->symtab), |
12773 | b->loc->line_number); | |
f8eba3c6 TT |
12774 | else |
12775 | /* This is not ideal, but each location may have a | |
12776 | different file name, and this at least reflects the | |
12777 | real situation somewhat. */ | |
12778 | printf_filtered (": %s.", b->addr_string); | |
12779 | } | |
348d480f PA |
12780 | |
12781 | if (b->loc->next) | |
12782 | { | |
12783 | struct bp_location *loc = b->loc; | |
12784 | int n = 0; | |
12785 | for (; loc; loc = loc->next) | |
12786 | ++n; | |
12787 | printf_filtered (" (%d locations)", n); | |
12788 | } | |
12789 | } | |
12790 | } | |
12791 | ||
348d480f PA |
12792 | /* Default bp_location_ops methods. */ |
12793 | ||
12794 | static void | |
12795 | bp_location_dtor (struct bp_location *self) | |
12796 | { | |
12797 | xfree (self->cond); | |
b775012e LM |
12798 | if (self->cond_bytecode) |
12799 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12800 | xfree (self->function_name); |
8b4f3082 PA |
12801 | |
12802 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12803 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12804 | } |
12805 | ||
12806 | static const struct bp_location_ops bp_location_ops = | |
12807 | { | |
12808 | bp_location_dtor | |
12809 | }; | |
12810 | ||
2060206e PA |
12811 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12812 | inherit from. */ | |
348d480f | 12813 | |
2060206e PA |
12814 | static void |
12815 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12816 | { |
12817 | decref_counted_command_line (&self->commands); | |
12818 | xfree (self->cond_string); | |
fb81d016 | 12819 | xfree (self->extra_string); |
348d480f | 12820 | xfree (self->addr_string); |
f8eba3c6 | 12821 | xfree (self->filter); |
348d480f | 12822 | xfree (self->addr_string_range_end); |
348d480f PA |
12823 | } |
12824 | ||
2060206e PA |
12825 | static struct bp_location * |
12826 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12827 | { |
12828 | struct bp_location *loc; | |
12829 | ||
12830 | loc = XNEW (struct bp_location); | |
12831 | init_bp_location (loc, &bp_location_ops, self); | |
12832 | return loc; | |
12833 | } | |
12834 | ||
2060206e PA |
12835 | static void |
12836 | base_breakpoint_re_set (struct breakpoint *b) | |
12837 | { | |
12838 | /* Nothing to re-set. */ | |
12839 | } | |
12840 | ||
12841 | #define internal_error_pure_virtual_called() \ | |
12842 | gdb_assert_not_reached ("pure virtual function called") | |
12843 | ||
12844 | static int | |
12845 | base_breakpoint_insert_location (struct bp_location *bl) | |
12846 | { | |
12847 | internal_error_pure_virtual_called (); | |
12848 | } | |
12849 | ||
12850 | static int | |
12851 | base_breakpoint_remove_location (struct bp_location *bl) | |
12852 | { | |
12853 | internal_error_pure_virtual_called (); | |
12854 | } | |
12855 | ||
12856 | static int | |
12857 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12858 | struct address_space *aspace, | |
09ac7c10 TT |
12859 | CORE_ADDR bp_addr, |
12860 | const struct target_waitstatus *ws) | |
2060206e PA |
12861 | { |
12862 | internal_error_pure_virtual_called (); | |
12863 | } | |
12864 | ||
12865 | static void | |
12866 | base_breakpoint_check_status (bpstat bs) | |
12867 | { | |
12868 | /* Always stop. */ | |
12869 | } | |
12870 | ||
12871 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12872 | errors. */ | |
12873 | ||
12874 | static int | |
12875 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12876 | { | |
12877 | internal_error_pure_virtual_called (); | |
12878 | } | |
12879 | ||
12880 | /* A "resources_needed" breakpoint_ops method that just internal | |
12881 | errors. */ | |
12882 | ||
12883 | static int | |
12884 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12885 | { | |
12886 | internal_error_pure_virtual_called (); | |
12887 | } | |
12888 | ||
12889 | static enum print_stop_action | |
12890 | base_breakpoint_print_it (bpstat bs) | |
12891 | { | |
12892 | internal_error_pure_virtual_called (); | |
12893 | } | |
12894 | ||
12895 | static void | |
12896 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12897 | struct ui_out *uiout) | |
12898 | { | |
12899 | /* nothing */ | |
12900 | } | |
12901 | ||
12902 | static void | |
12903 | base_breakpoint_print_mention (struct breakpoint *b) | |
12904 | { | |
12905 | internal_error_pure_virtual_called (); | |
12906 | } | |
12907 | ||
12908 | static void | |
12909 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12910 | { | |
12911 | internal_error_pure_virtual_called (); | |
12912 | } | |
12913 | ||
983af33b SDJ |
12914 | static void |
12915 | base_breakpoint_create_sals_from_address (char **arg, | |
12916 | struct linespec_result *canonical, | |
12917 | enum bptype type_wanted, | |
12918 | char *addr_start, | |
12919 | char **copy_arg) | |
12920 | { | |
12921 | internal_error_pure_virtual_called (); | |
12922 | } | |
12923 | ||
12924 | static void | |
12925 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12926 | struct linespec_result *c, | |
983af33b | 12927 | char *cond_string, |
e7e0cddf | 12928 | char *extra_string, |
983af33b SDJ |
12929 | enum bptype type_wanted, |
12930 | enum bpdisp disposition, | |
12931 | int thread, | |
12932 | int task, int ignore_count, | |
12933 | const struct breakpoint_ops *o, | |
12934 | int from_tty, int enabled, | |
44f238bb | 12935 | int internal, unsigned flags) |
983af33b SDJ |
12936 | { |
12937 | internal_error_pure_virtual_called (); | |
12938 | } | |
12939 | ||
12940 | static void | |
12941 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12942 | struct symtabs_and_lines *sals) | |
12943 | { | |
12944 | internal_error_pure_virtual_called (); | |
12945 | } | |
12946 | ||
ab04a2af TT |
12947 | /* The default 'explains_signal' method. */ |
12948 | ||
47591c29 | 12949 | static int |
427cd150 | 12950 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12951 | { |
47591c29 | 12952 | return 1; |
ab04a2af TT |
12953 | } |
12954 | ||
9d6e6e84 HZ |
12955 | /* The default "after_condition_true" method. */ |
12956 | ||
12957 | static void | |
12958 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12959 | { | |
12960 | /* Nothing to do. */ | |
12961 | } | |
12962 | ||
ab04a2af | 12963 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12964 | { |
12965 | base_breakpoint_dtor, | |
12966 | base_breakpoint_allocate_location, | |
12967 | base_breakpoint_re_set, | |
12968 | base_breakpoint_insert_location, | |
12969 | base_breakpoint_remove_location, | |
12970 | base_breakpoint_breakpoint_hit, | |
12971 | base_breakpoint_check_status, | |
12972 | base_breakpoint_resources_needed, | |
12973 | base_breakpoint_works_in_software_mode, | |
12974 | base_breakpoint_print_it, | |
12975 | NULL, | |
12976 | base_breakpoint_print_one_detail, | |
12977 | base_breakpoint_print_mention, | |
983af33b SDJ |
12978 | base_breakpoint_print_recreate, |
12979 | base_breakpoint_create_sals_from_address, | |
12980 | base_breakpoint_create_breakpoints_sal, | |
12981 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12982 | base_breakpoint_explains_signal, |
12983 | base_breakpoint_after_condition_true, | |
2060206e PA |
12984 | }; |
12985 | ||
12986 | /* Default breakpoint_ops methods. */ | |
12987 | ||
12988 | static void | |
348d480f PA |
12989 | bkpt_re_set (struct breakpoint *b) |
12990 | { | |
06edf0c0 PA |
12991 | /* FIXME: is this still reachable? */ |
12992 | if (b->addr_string == NULL) | |
12993 | { | |
12994 | /* Anything without a string can't be re-set. */ | |
348d480f | 12995 | delete_breakpoint (b); |
06edf0c0 | 12996 | return; |
348d480f | 12997 | } |
06edf0c0 PA |
12998 | |
12999 | breakpoint_re_set_default (b); | |
348d480f PA |
13000 | } |
13001 | ||
2060206e | 13002 | static int |
348d480f PA |
13003 | bkpt_insert_location (struct bp_location *bl) |
13004 | { | |
13005 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13006 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13007 | &bl->target_info); | |
13008 | else | |
13009 | return target_insert_breakpoint (bl->gdbarch, | |
13010 | &bl->target_info); | |
13011 | } | |
13012 | ||
2060206e | 13013 | static int |
348d480f PA |
13014 | bkpt_remove_location (struct bp_location *bl) |
13015 | { | |
13016 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13017 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13018 | else | |
13019 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
13020 | } | |
13021 | ||
2060206e | 13022 | static int |
348d480f | 13023 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13024 | struct address_space *aspace, CORE_ADDR bp_addr, |
13025 | const struct target_waitstatus *ws) | |
348d480f | 13026 | { |
09ac7c10 | 13027 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13028 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13029 | return 0; |
13030 | ||
348d480f PA |
13031 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13032 | aspace, bp_addr)) | |
13033 | return 0; | |
13034 | ||
13035 | if (overlay_debugging /* unmapped overlay section */ | |
13036 | && section_is_overlay (bl->section) | |
13037 | && !section_is_mapped (bl->section)) | |
13038 | return 0; | |
13039 | ||
13040 | return 1; | |
13041 | } | |
13042 | ||
2060206e | 13043 | static int |
348d480f PA |
13044 | bkpt_resources_needed (const struct bp_location *bl) |
13045 | { | |
13046 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13047 | ||
13048 | return 1; | |
13049 | } | |
13050 | ||
2060206e | 13051 | static enum print_stop_action |
348d480f PA |
13052 | bkpt_print_it (bpstat bs) |
13053 | { | |
348d480f PA |
13054 | struct breakpoint *b; |
13055 | const struct bp_location *bl; | |
001c8c33 | 13056 | int bp_temp; |
79a45e25 | 13057 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13058 | |
13059 | gdb_assert (bs->bp_location_at != NULL); | |
13060 | ||
13061 | bl = bs->bp_location_at; | |
13062 | b = bs->breakpoint_at; | |
13063 | ||
001c8c33 PA |
13064 | bp_temp = b->disposition == disp_del; |
13065 | if (bl->address != bl->requested_address) | |
13066 | breakpoint_adjustment_warning (bl->requested_address, | |
13067 | bl->address, | |
13068 | b->number, 1); | |
13069 | annotate_breakpoint (b->number); | |
13070 | if (bp_temp) | |
13071 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13072 | else | |
13073 | ui_out_text (uiout, "\nBreakpoint "); | |
13074 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13075 | { |
001c8c33 PA |
13076 | ui_out_field_string (uiout, "reason", |
13077 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13078 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13079 | } |
001c8c33 PA |
13080 | ui_out_field_int (uiout, "bkptno", b->number); |
13081 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13082 | |
001c8c33 | 13083 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13084 | } |
13085 | ||
2060206e | 13086 | static void |
06edf0c0 PA |
13087 | bkpt_print_mention (struct breakpoint *b) |
13088 | { | |
79a45e25 | 13089 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13090 | return; |
13091 | ||
13092 | switch (b->type) | |
13093 | { | |
13094 | case bp_breakpoint: | |
13095 | case bp_gnu_ifunc_resolver: | |
13096 | if (b->disposition == disp_del) | |
13097 | printf_filtered (_("Temporary breakpoint")); | |
13098 | else | |
13099 | printf_filtered (_("Breakpoint")); | |
13100 | printf_filtered (_(" %d"), b->number); | |
13101 | if (b->type == bp_gnu_ifunc_resolver) | |
13102 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13103 | break; | |
13104 | case bp_hardware_breakpoint: | |
13105 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13106 | break; | |
e7e0cddf SS |
13107 | case bp_dprintf: |
13108 | printf_filtered (_("Dprintf %d"), b->number); | |
13109 | break; | |
06edf0c0 PA |
13110 | } |
13111 | ||
13112 | say_where (b); | |
13113 | } | |
13114 | ||
2060206e | 13115 | static void |
06edf0c0 PA |
13116 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13117 | { | |
13118 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13119 | fprintf_unfiltered (fp, "tbreak"); | |
13120 | else if (tp->type == bp_breakpoint) | |
13121 | fprintf_unfiltered (fp, "break"); | |
13122 | else if (tp->type == bp_hardware_breakpoint | |
13123 | && tp->disposition == disp_del) | |
13124 | fprintf_unfiltered (fp, "thbreak"); | |
13125 | else if (tp->type == bp_hardware_breakpoint) | |
13126 | fprintf_unfiltered (fp, "hbreak"); | |
13127 | else | |
13128 | internal_error (__FILE__, __LINE__, | |
13129 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13130 | ||
2060206e | 13131 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13132 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13133 | } |
13134 | ||
983af33b SDJ |
13135 | static void |
13136 | bkpt_create_sals_from_address (char **arg, | |
13137 | struct linespec_result *canonical, | |
13138 | enum bptype type_wanted, | |
13139 | char *addr_start, char **copy_arg) | |
13140 | { | |
13141 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13142 | addr_start, copy_arg); | |
13143 | } | |
13144 | ||
13145 | static void | |
13146 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13147 | struct linespec_result *canonical, | |
983af33b | 13148 | char *cond_string, |
e7e0cddf | 13149 | char *extra_string, |
983af33b SDJ |
13150 | enum bptype type_wanted, |
13151 | enum bpdisp disposition, | |
13152 | int thread, | |
13153 | int task, int ignore_count, | |
13154 | const struct breakpoint_ops *ops, | |
13155 | int from_tty, int enabled, | |
44f238bb | 13156 | int internal, unsigned flags) |
983af33b | 13157 | { |
023fa29b | 13158 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13159 | cond_string, extra_string, |
13160 | type_wanted, | |
983af33b SDJ |
13161 | disposition, thread, task, |
13162 | ignore_count, ops, from_tty, | |
44f238bb | 13163 | enabled, internal, flags); |
983af33b SDJ |
13164 | } |
13165 | ||
13166 | static void | |
13167 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13168 | struct symtabs_and_lines *sals) | |
13169 | { | |
13170 | decode_linespec_default (b, s, sals); | |
13171 | } | |
13172 | ||
06edf0c0 PA |
13173 | /* Virtual table for internal breakpoints. */ |
13174 | ||
13175 | static void | |
13176 | internal_bkpt_re_set (struct breakpoint *b) | |
13177 | { | |
13178 | switch (b->type) | |
13179 | { | |
13180 | /* Delete overlay event and longjmp master breakpoints; they | |
13181 | will be reset later by breakpoint_re_set. */ | |
13182 | case bp_overlay_event: | |
13183 | case bp_longjmp_master: | |
13184 | case bp_std_terminate_master: | |
13185 | case bp_exception_master: | |
13186 | delete_breakpoint (b); | |
13187 | break; | |
13188 | ||
13189 | /* This breakpoint is special, it's set up when the inferior | |
13190 | starts and we really don't want to touch it. */ | |
13191 | case bp_shlib_event: | |
13192 | ||
13193 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13194 | it is set up, we do not want to touch it. */ | |
13195 | case bp_thread_event: | |
13196 | break; | |
13197 | } | |
13198 | } | |
13199 | ||
13200 | static void | |
13201 | internal_bkpt_check_status (bpstat bs) | |
13202 | { | |
a9b3a50f PA |
13203 | if (bs->breakpoint_at->type == bp_shlib_event) |
13204 | { | |
13205 | /* If requested, stop when the dynamic linker notifies GDB of | |
13206 | events. This allows the user to get control and place | |
13207 | breakpoints in initializer routines for dynamically loaded | |
13208 | objects (among other things). */ | |
13209 | bs->stop = stop_on_solib_events; | |
13210 | bs->print = stop_on_solib_events; | |
13211 | } | |
13212 | else | |
13213 | bs->stop = 0; | |
06edf0c0 PA |
13214 | } |
13215 | ||
13216 | static enum print_stop_action | |
13217 | internal_bkpt_print_it (bpstat bs) | |
13218 | { | |
06edf0c0 | 13219 | struct breakpoint *b; |
06edf0c0 | 13220 | |
06edf0c0 PA |
13221 | b = bs->breakpoint_at; |
13222 | ||
06edf0c0 PA |
13223 | switch (b->type) |
13224 | { | |
348d480f PA |
13225 | case bp_shlib_event: |
13226 | /* Did we stop because the user set the stop_on_solib_events | |
13227 | variable? (If so, we report this as a generic, "Stopped due | |
13228 | to shlib event" message.) */ | |
edcc5120 | 13229 | print_solib_event (0); |
348d480f PA |
13230 | break; |
13231 | ||
13232 | case bp_thread_event: | |
13233 | /* Not sure how we will get here. | |
13234 | GDB should not stop for these breakpoints. */ | |
13235 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13236 | break; |
13237 | ||
13238 | case bp_overlay_event: | |
13239 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13240 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13241 | break; |
13242 | ||
13243 | case bp_longjmp_master: | |
13244 | /* These should never be enabled. */ | |
13245 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13246 | break; |
13247 | ||
13248 | case bp_std_terminate_master: | |
13249 | /* These should never be enabled. */ | |
13250 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13251 | "gdb should not stop!\n")); | |
348d480f PA |
13252 | break; |
13253 | ||
13254 | case bp_exception_master: | |
13255 | /* These should never be enabled. */ | |
13256 | printf_filtered (_("Exception Master Breakpoint: " | |
13257 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13258 | break; |
13259 | } | |
13260 | ||
001c8c33 | 13261 | return PRINT_NOTHING; |
06edf0c0 PA |
13262 | } |
13263 | ||
13264 | static void | |
13265 | internal_bkpt_print_mention (struct breakpoint *b) | |
13266 | { | |
13267 | /* Nothing to mention. These breakpoints are internal. */ | |
13268 | } | |
13269 | ||
06edf0c0 PA |
13270 | /* Virtual table for momentary breakpoints */ |
13271 | ||
13272 | static void | |
13273 | momentary_bkpt_re_set (struct breakpoint *b) | |
13274 | { | |
13275 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13276 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13277 | Otherwise these should have been blown away via the cleanup chain |
13278 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13279 | } | |
13280 | ||
13281 | static void | |
13282 | momentary_bkpt_check_status (bpstat bs) | |
13283 | { | |
13284 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13285 | } | |
13286 | ||
13287 | static enum print_stop_action | |
13288 | momentary_bkpt_print_it (bpstat bs) | |
13289 | { | |
79a45e25 PA |
13290 | struct ui_out *uiout = current_uiout; |
13291 | ||
001c8c33 | 13292 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13293 | { |
001c8c33 | 13294 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13295 | |
001c8c33 PA |
13296 | switch (b->type) |
13297 | { | |
13298 | case bp_finish: | |
13299 | ui_out_field_string | |
13300 | (uiout, "reason", | |
13301 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13302 | break; | |
348d480f | 13303 | |
001c8c33 PA |
13304 | case bp_until: |
13305 | ui_out_field_string | |
13306 | (uiout, "reason", | |
13307 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13308 | break; | |
13309 | } | |
348d480f PA |
13310 | } |
13311 | ||
001c8c33 | 13312 | return PRINT_UNKNOWN; |
348d480f PA |
13313 | } |
13314 | ||
06edf0c0 PA |
13315 | static void |
13316 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13317 | { |
06edf0c0 | 13318 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13319 | } |
13320 | ||
e2e4d78b JK |
13321 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13322 | ||
13323 | It gets cleared already on the removal of the first one of such placed | |
13324 | breakpoints. This is OK as they get all removed altogether. */ | |
13325 | ||
13326 | static void | |
13327 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13328 | { | |
13329 | struct thread_info *tp = find_thread_id (self->thread); | |
13330 | ||
13331 | if (tp) | |
13332 | tp->initiating_frame = null_frame_id; | |
13333 | ||
13334 | momentary_breakpoint_ops.dtor (self); | |
13335 | } | |
13336 | ||
55aa24fb SDJ |
13337 | /* Specific methods for probe breakpoints. */ |
13338 | ||
13339 | static int | |
13340 | bkpt_probe_insert_location (struct bp_location *bl) | |
13341 | { | |
13342 | int v = bkpt_insert_location (bl); | |
13343 | ||
13344 | if (v == 0) | |
13345 | { | |
13346 | /* The insertion was successful, now let's set the probe's semaphore | |
13347 | if needed. */ | |
729662a5 TT |
13348 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
13349 | bl->probe.objfile, | |
13350 | bl->gdbarch); | |
55aa24fb SDJ |
13351 | } |
13352 | ||
13353 | return v; | |
13354 | } | |
13355 | ||
13356 | static int | |
13357 | bkpt_probe_remove_location (struct bp_location *bl) | |
13358 | { | |
13359 | /* Let's clear the semaphore before removing the location. */ | |
729662a5 TT |
13360 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
13361 | bl->probe.objfile, | |
13362 | bl->gdbarch); | |
55aa24fb SDJ |
13363 | |
13364 | return bkpt_remove_location (bl); | |
13365 | } | |
13366 | ||
13367 | static void | |
13368 | bkpt_probe_create_sals_from_address (char **arg, | |
13369 | struct linespec_result *canonical, | |
13370 | enum bptype type_wanted, | |
13371 | char *addr_start, char **copy_arg) | |
13372 | { | |
13373 | struct linespec_sals lsal; | |
13374 | ||
13375 | lsal.sals = parse_probes (arg, canonical); | |
13376 | ||
13377 | *copy_arg = xstrdup (canonical->addr_string); | |
13378 | lsal.canonical = xstrdup (*copy_arg); | |
13379 | ||
13380 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13381 | } | |
13382 | ||
13383 | static void | |
13384 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13385 | struct symtabs_and_lines *sals) | |
13386 | { | |
13387 | *sals = parse_probes (s, NULL); | |
13388 | if (!sals->sals) | |
13389 | error (_("probe not found")); | |
13390 | } | |
13391 | ||
348d480f | 13392 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13393 | |
348d480f PA |
13394 | static void |
13395 | tracepoint_re_set (struct breakpoint *b) | |
13396 | { | |
13397 | breakpoint_re_set_default (b); | |
13398 | } | |
876fa593 | 13399 | |
348d480f PA |
13400 | static int |
13401 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13402 | struct address_space *aspace, CORE_ADDR bp_addr, |
13403 | const struct target_waitstatus *ws) | |
348d480f PA |
13404 | { |
13405 | /* By definition, the inferior does not report stops at | |
13406 | tracepoints. */ | |
13407 | return 0; | |
74960c60 VP |
13408 | } |
13409 | ||
13410 | static void | |
348d480f PA |
13411 | tracepoint_print_one_detail (const struct breakpoint *self, |
13412 | struct ui_out *uiout) | |
74960c60 | 13413 | { |
d9b3f62e PA |
13414 | struct tracepoint *tp = (struct tracepoint *) self; |
13415 | if (tp->static_trace_marker_id) | |
348d480f PA |
13416 | { |
13417 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13418 | |
348d480f PA |
13419 | ui_out_text (uiout, "\tmarker id is "); |
13420 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13421 | tp->static_trace_marker_id); |
348d480f PA |
13422 | ui_out_text (uiout, "\n"); |
13423 | } | |
0d381245 VP |
13424 | } |
13425 | ||
a474d7c2 | 13426 | static void |
348d480f | 13427 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13428 | { |
79a45e25 | 13429 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13430 | return; |
cc59ec59 | 13431 | |
348d480f PA |
13432 | switch (b->type) |
13433 | { | |
13434 | case bp_tracepoint: | |
13435 | printf_filtered (_("Tracepoint")); | |
13436 | printf_filtered (_(" %d"), b->number); | |
13437 | break; | |
13438 | case bp_fast_tracepoint: | |
13439 | printf_filtered (_("Fast tracepoint")); | |
13440 | printf_filtered (_(" %d"), b->number); | |
13441 | break; | |
13442 | case bp_static_tracepoint: | |
13443 | printf_filtered (_("Static tracepoint")); | |
13444 | printf_filtered (_(" %d"), b->number); | |
13445 | break; | |
13446 | default: | |
13447 | internal_error (__FILE__, __LINE__, | |
13448 | _("unhandled tracepoint type %d"), (int) b->type); | |
13449 | } | |
13450 | ||
13451 | say_where (b); | |
a474d7c2 PA |
13452 | } |
13453 | ||
348d480f | 13454 | static void |
d9b3f62e | 13455 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13456 | { |
d9b3f62e PA |
13457 | struct tracepoint *tp = (struct tracepoint *) self; |
13458 | ||
13459 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13460 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13461 | if (self->type == bp_static_tracepoint) |
348d480f | 13462 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13463 | else if (self->type == bp_tracepoint) |
348d480f PA |
13464 | fprintf_unfiltered (fp, "trace"); |
13465 | else | |
13466 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13467 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13468 | |
d9b3f62e PA |
13469 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13470 | print_recreate_thread (self, fp); | |
13471 | ||
13472 | if (tp->pass_count) | |
13473 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13474 | } |
13475 | ||
983af33b SDJ |
13476 | static void |
13477 | tracepoint_create_sals_from_address (char **arg, | |
13478 | struct linespec_result *canonical, | |
13479 | enum bptype type_wanted, | |
13480 | char *addr_start, char **copy_arg) | |
13481 | { | |
13482 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13483 | addr_start, copy_arg); | |
13484 | } | |
13485 | ||
13486 | static void | |
13487 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13488 | struct linespec_result *canonical, | |
983af33b | 13489 | char *cond_string, |
e7e0cddf | 13490 | char *extra_string, |
983af33b SDJ |
13491 | enum bptype type_wanted, |
13492 | enum bpdisp disposition, | |
13493 | int thread, | |
13494 | int task, int ignore_count, | |
13495 | const struct breakpoint_ops *ops, | |
13496 | int from_tty, int enabled, | |
44f238bb | 13497 | int internal, unsigned flags) |
983af33b | 13498 | { |
023fa29b | 13499 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13500 | cond_string, extra_string, |
13501 | type_wanted, | |
983af33b SDJ |
13502 | disposition, thread, task, |
13503 | ignore_count, ops, from_tty, | |
44f238bb | 13504 | enabled, internal, flags); |
983af33b SDJ |
13505 | } |
13506 | ||
13507 | static void | |
13508 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13509 | struct symtabs_and_lines *sals) | |
13510 | { | |
13511 | decode_linespec_default (b, s, sals); | |
13512 | } | |
13513 | ||
2060206e | 13514 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13515 | |
55aa24fb SDJ |
13516 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13517 | static probe. */ | |
13518 | ||
13519 | static void | |
13520 | tracepoint_probe_create_sals_from_address (char **arg, | |
13521 | struct linespec_result *canonical, | |
13522 | enum bptype type_wanted, | |
13523 | char *addr_start, char **copy_arg) | |
13524 | { | |
13525 | /* We use the same method for breakpoint on probes. */ | |
13526 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13527 | addr_start, copy_arg); | |
13528 | } | |
13529 | ||
13530 | static void | |
13531 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13532 | struct symtabs_and_lines *sals) | |
13533 | { | |
13534 | /* We use the same method for breakpoint on probes. */ | |
13535 | bkpt_probe_decode_linespec (b, s, sals); | |
13536 | } | |
13537 | ||
13538 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13539 | ||
5c2b4418 HZ |
13540 | /* Dprintf breakpoint_ops methods. */ |
13541 | ||
13542 | static void | |
13543 | dprintf_re_set (struct breakpoint *b) | |
13544 | { | |
13545 | breakpoint_re_set_default (b); | |
13546 | ||
13547 | /* This breakpoint could have been pending, and be resolved now, and | |
13548 | if so, we should now have the extra string. If we don't, the | |
13549 | dprintf was malformed when created, but we couldn't tell because | |
13550 | we can't extract the extra string until the location is | |
13551 | resolved. */ | |
13552 | if (b->loc != NULL && b->extra_string == NULL) | |
13553 | error (_("Format string required")); | |
13554 | ||
13555 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13556 | 2 - create a dprintf, which resolves fine. | |
13557 | 3 - disconnect from target 1 | |
13558 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13559 | ||
13560 | After steps #3/#4, you'll want the dprintf command list to | |
13561 | be updated, because target 1 and 2 may well return different | |
13562 | answers for target_can_run_breakpoint_commands(). | |
13563 | Given absence of finer grained resetting, we get to do | |
13564 | it all the time. */ | |
13565 | if (b->extra_string != NULL) | |
13566 | update_dprintf_command_list (b); | |
13567 | } | |
13568 | ||
2d9442cc HZ |
13569 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13570 | ||
13571 | static void | |
13572 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13573 | { | |
13574 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13575 | tp->extra_string); | |
13576 | print_recreate_thread (tp, fp); | |
13577 | } | |
13578 | ||
9d6e6e84 HZ |
13579 | /* Implement the "after_condition_true" breakpoint_ops method for |
13580 | dprintf. | |
13581 | ||
13582 | dprintf's are implemented with regular commands in their command | |
13583 | list, but we run the commands here instead of before presenting the | |
13584 | stop to the user, as dprintf's don't actually cause a stop. This | |
13585 | also makes it so that the commands of multiple dprintfs at the same | |
13586 | address are all handled. */ | |
13587 | ||
13588 | static void | |
13589 | dprintf_after_condition_true (struct bpstats *bs) | |
13590 | { | |
13591 | struct cleanup *old_chain; | |
13592 | struct bpstats tmp_bs = { NULL }; | |
13593 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13594 | ||
13595 | /* dprintf's never cause a stop. This wasn't set in the | |
13596 | check_status hook instead because that would make the dprintf's | |
13597 | condition not be evaluated. */ | |
13598 | bs->stop = 0; | |
13599 | ||
13600 | /* Run the command list here. Take ownership of it instead of | |
13601 | copying. We never want these commands to run later in | |
13602 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13603 | be set at same address as this dprintf, or even if running the | |
13604 | commands here throws. */ | |
13605 | tmp_bs.commands = bs->commands; | |
13606 | bs->commands = NULL; | |
13607 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13608 | ||
13609 | bpstat_do_actions_1 (&tmp_bs_p); | |
13610 | ||
13611 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13612 | bpstat_do_actions_1 may return early without processing the whole | |
13613 | list. */ | |
13614 | do_cleanups (old_chain); | |
13615 | } | |
13616 | ||
983af33b SDJ |
13617 | /* The breakpoint_ops structure to be used on static tracepoints with |
13618 | markers (`-m'). */ | |
13619 | ||
13620 | static void | |
13621 | strace_marker_create_sals_from_address (char **arg, | |
13622 | struct linespec_result *canonical, | |
13623 | enum bptype type_wanted, | |
13624 | char *addr_start, char **copy_arg) | |
13625 | { | |
13626 | struct linespec_sals lsal; | |
13627 | ||
13628 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13629 | ||
13630 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13631 | ||
13632 | canonical->addr_string = xstrdup (*copy_arg); | |
13633 | lsal.canonical = xstrdup (*copy_arg); | |
13634 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13635 | } | |
13636 | ||
13637 | static void | |
13638 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13639 | struct linespec_result *canonical, | |
983af33b | 13640 | char *cond_string, |
e7e0cddf | 13641 | char *extra_string, |
983af33b SDJ |
13642 | enum bptype type_wanted, |
13643 | enum bpdisp disposition, | |
13644 | int thread, | |
13645 | int task, int ignore_count, | |
13646 | const struct breakpoint_ops *ops, | |
13647 | int from_tty, int enabled, | |
44f238bb | 13648 | int internal, unsigned flags) |
983af33b SDJ |
13649 | { |
13650 | int i; | |
52d361e1 YQ |
13651 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13652 | canonical->sals, 0); | |
983af33b SDJ |
13653 | |
13654 | /* If the user is creating a static tracepoint by marker id | |
13655 | (strace -m MARKER_ID), then store the sals index, so that | |
13656 | breakpoint_re_set can try to match up which of the newly | |
13657 | found markers corresponds to this one, and, don't try to | |
13658 | expand multiple locations for each sal, given than SALS | |
13659 | already should contain all sals for MARKER_ID. */ | |
13660 | ||
13661 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13662 | { | |
13663 | struct symtabs_and_lines expanded; | |
13664 | struct tracepoint *tp; | |
13665 | struct cleanup *old_chain; | |
13666 | char *addr_string; | |
13667 | ||
13668 | expanded.nelts = 1; | |
13669 | expanded.sals = &lsal->sals.sals[i]; | |
13670 | ||
13671 | addr_string = xstrdup (canonical->addr_string); | |
13672 | old_chain = make_cleanup (xfree, addr_string); | |
13673 | ||
13674 | tp = XCNEW (struct tracepoint); | |
13675 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13676 | addr_string, NULL, | |
e7e0cddf SS |
13677 | cond_string, extra_string, |
13678 | type_wanted, disposition, | |
983af33b | 13679 | thread, task, ignore_count, ops, |
44f238bb | 13680 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13681 | canonical->special_display); |
13682 | /* Given that its possible to have multiple markers with | |
13683 | the same string id, if the user is creating a static | |
13684 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13685 | store the sals index, so that breakpoint_re_set can | |
13686 | try to match up which of the newly found markers | |
13687 | corresponds to this one */ | |
13688 | tp->static_trace_marker_id_idx = i; | |
13689 | ||
13690 | install_breakpoint (internal, &tp->base, 0); | |
13691 | ||
13692 | discard_cleanups (old_chain); | |
13693 | } | |
13694 | } | |
13695 | ||
13696 | static void | |
13697 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13698 | struct symtabs_and_lines *sals) | |
13699 | { | |
13700 | struct tracepoint *tp = (struct tracepoint *) b; | |
13701 | ||
13702 | *sals = decode_static_tracepoint_spec (s); | |
13703 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13704 | { | |
13705 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13706 | sals->nelts = 1; | |
13707 | } | |
13708 | else | |
13709 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13710 | } | |
13711 | ||
13712 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13713 | ||
13714 | static int | |
13715 | strace_marker_p (struct breakpoint *b) | |
13716 | { | |
13717 | return b->ops == &strace_marker_breakpoint_ops; | |
13718 | } | |
13719 | ||
53a5351d | 13720 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13721 | structures. */ |
c906108c SS |
13722 | |
13723 | void | |
fba45db2 | 13724 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13725 | { |
52f0bd74 | 13726 | struct breakpoint *b; |
c906108c | 13727 | |
8a3fe4f8 | 13728 | gdb_assert (bpt != NULL); |
c906108c | 13729 | |
4a64f543 MS |
13730 | /* Has this bp already been deleted? This can happen because |
13731 | multiple lists can hold pointers to bp's. bpstat lists are | |
13732 | especial culprits. | |
13733 | ||
13734 | One example of this happening is a watchpoint's scope bp. When | |
13735 | the scope bp triggers, we notice that the watchpoint is out of | |
13736 | scope, and delete it. We also delete its scope bp. But the | |
13737 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13738 | That bpstat is then checked for auto-deleting bp's, which are | |
13739 | deleted. | |
13740 | ||
13741 | A real solution to this problem might involve reference counts in | |
13742 | bp's, and/or giving them pointers back to their referencing | |
13743 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13744 | storage when no more references were extent. A cheaper bandaid | |
13745 | was chosen. */ | |
c906108c SS |
13746 | if (bpt->type == bp_none) |
13747 | return; | |
13748 | ||
4a64f543 MS |
13749 | /* At least avoid this stale reference until the reference counting |
13750 | of breakpoints gets resolved. */ | |
d0fb5eae | 13751 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13752 | { |
d0fb5eae | 13753 | struct breakpoint *related; |
3a5c3e22 | 13754 | struct watchpoint *w; |
d0fb5eae JK |
13755 | |
13756 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13757 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13758 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13759 | w = (struct watchpoint *) bpt; |
13760 | else | |
13761 | w = NULL; | |
13762 | if (w != NULL) | |
13763 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13764 | |
13765 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13766 | for (related = bpt; related->related_breakpoint != bpt; | |
13767 | related = related->related_breakpoint); | |
13768 | related->related_breakpoint = bpt->related_breakpoint; | |
13769 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13770 | } |
13771 | ||
a9634178 TJB |
13772 | /* watch_command_1 creates a watchpoint but only sets its number if |
13773 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13774 | a problem in that process, we'll be asked to delete the half-created | |
13775 | watchpoint. In that case, don't announce the deletion. */ | |
13776 | if (bpt->number) | |
13777 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13778 | |
c906108c SS |
13779 | if (breakpoint_chain == bpt) |
13780 | breakpoint_chain = bpt->next; | |
13781 | ||
c906108c SS |
13782 | ALL_BREAKPOINTS (b) |
13783 | if (b->next == bpt) | |
c5aa993b JM |
13784 | { |
13785 | b->next = bpt->next; | |
13786 | break; | |
13787 | } | |
c906108c | 13788 | |
f431efe5 PA |
13789 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13790 | been freed. */ | |
13791 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13792 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13793 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13794 | commands are associated with the bpstat; if we remove it here, | |
13795 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13796 | event-top.c won't do anything, and temporary breakpoints with | |
13797 | commands won't work. */ | |
13798 | ||
13799 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13800 | ||
4a64f543 MS |
13801 | /* Now that breakpoint is removed from breakpoint list, update the |
13802 | global location list. This will remove locations that used to | |
13803 | belong to this breakpoint. Do this before freeing the breakpoint | |
13804 | itself, since remove_breakpoint looks at location's owner. It | |
13805 | might be better design to have location completely | |
13806 | self-contained, but it's not the case now. */ | |
b60e7edf | 13807 | update_global_location_list (0); |
74960c60 | 13808 | |
348d480f | 13809 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13810 | /* On the chance that someone will soon try again to delete this |
13811 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13812 | bpt->type = bp_none; |
b8c9b27d | 13813 | xfree (bpt); |
c906108c SS |
13814 | } |
13815 | ||
4d6140d9 AC |
13816 | static void |
13817 | do_delete_breakpoint_cleanup (void *b) | |
13818 | { | |
13819 | delete_breakpoint (b); | |
13820 | } | |
13821 | ||
13822 | struct cleanup * | |
13823 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13824 | { | |
13825 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13826 | } | |
13827 | ||
51be5b68 PA |
13828 | /* Iterator function to call a user-provided callback function once |
13829 | for each of B and its related breakpoints. */ | |
13830 | ||
13831 | static void | |
13832 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13833 | void (*function) (struct breakpoint *, | |
13834 | void *), | |
13835 | void *data) | |
13836 | { | |
13837 | struct breakpoint *related; | |
13838 | ||
13839 | related = b; | |
13840 | do | |
13841 | { | |
13842 | struct breakpoint *next; | |
13843 | ||
13844 | /* FUNCTION may delete RELATED. */ | |
13845 | next = related->related_breakpoint; | |
13846 | ||
13847 | if (next == related) | |
13848 | { | |
13849 | /* RELATED is the last ring entry. */ | |
13850 | function (related, data); | |
13851 | ||
13852 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13853 | B. There's nothing left to do anyway, so just break | |
13854 | out. */ | |
13855 | break; | |
13856 | } | |
13857 | else | |
13858 | function (related, data); | |
13859 | ||
13860 | related = next; | |
13861 | } | |
13862 | while (related != b); | |
13863 | } | |
95a42b64 TT |
13864 | |
13865 | static void | |
13866 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13867 | { | |
13868 | delete_breakpoint (b); | |
13869 | } | |
13870 | ||
51be5b68 PA |
13871 | /* A callback for map_breakpoint_numbers that calls |
13872 | delete_breakpoint. */ | |
13873 | ||
13874 | static void | |
13875 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13876 | { | |
13877 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13878 | } | |
13879 | ||
c906108c | 13880 | void |
fba45db2 | 13881 | delete_command (char *arg, int from_tty) |
c906108c | 13882 | { |
35df4500 | 13883 | struct breakpoint *b, *b_tmp; |
c906108c | 13884 | |
ea9365bb TT |
13885 | dont_repeat (); |
13886 | ||
c906108c SS |
13887 | if (arg == 0) |
13888 | { | |
13889 | int breaks_to_delete = 0; | |
13890 | ||
46c6471b PA |
13891 | /* Delete all breakpoints if no argument. Do not delete |
13892 | internal breakpoints, these have to be deleted with an | |
13893 | explicit breakpoint number argument. */ | |
c5aa993b | 13894 | ALL_BREAKPOINTS (b) |
46c6471b | 13895 | if (user_breakpoint_p (b)) |
973d738b DJ |
13896 | { |
13897 | breaks_to_delete = 1; | |
13898 | break; | |
13899 | } | |
c906108c SS |
13900 | |
13901 | /* Ask user only if there are some breakpoints to delete. */ | |
13902 | if (!from_tty | |
e2e0b3e5 | 13903 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13904 | { |
35df4500 | 13905 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13906 | if (user_breakpoint_p (b)) |
c5aa993b | 13907 | delete_breakpoint (b); |
c906108c SS |
13908 | } |
13909 | } | |
13910 | else | |
51be5b68 | 13911 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13912 | } |
13913 | ||
0d381245 VP |
13914 | static int |
13915 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13916 | { |
0d381245 | 13917 | for (; loc; loc = loc->next) |
8645ff69 UW |
13918 | if (!loc->shlib_disabled |
13919 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13920 | return 0; |
13921 | return 1; | |
fe3f5fa8 VP |
13922 | } |
13923 | ||
776592bf DE |
13924 | /* Subroutine of update_breakpoint_locations to simplify it. |
13925 | Return non-zero if multiple fns in list LOC have the same name. | |
13926 | Null names are ignored. */ | |
13927 | ||
13928 | static int | |
13929 | ambiguous_names_p (struct bp_location *loc) | |
13930 | { | |
13931 | struct bp_location *l; | |
13932 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13933 | (int (*) (const void *, |
13934 | const void *)) streq, | |
776592bf DE |
13935 | NULL, xcalloc, xfree); |
13936 | ||
13937 | for (l = loc; l != NULL; l = l->next) | |
13938 | { | |
13939 | const char **slot; | |
13940 | const char *name = l->function_name; | |
13941 | ||
13942 | /* Allow for some names to be NULL, ignore them. */ | |
13943 | if (name == NULL) | |
13944 | continue; | |
13945 | ||
13946 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13947 | INSERT); | |
4a64f543 MS |
13948 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13949 | returns NULL. */ | |
776592bf DE |
13950 | if (*slot != NULL) |
13951 | { | |
13952 | htab_delete (htab); | |
13953 | return 1; | |
13954 | } | |
13955 | *slot = name; | |
13956 | } | |
13957 | ||
13958 | htab_delete (htab); | |
13959 | return 0; | |
13960 | } | |
13961 | ||
0fb4aa4b PA |
13962 | /* When symbols change, it probably means the sources changed as well, |
13963 | and it might mean the static tracepoint markers are no longer at | |
13964 | the same address or line numbers they used to be at last we | |
13965 | checked. Losing your static tracepoints whenever you rebuild is | |
13966 | undesirable. This function tries to resync/rematch gdb static | |
13967 | tracepoints with the markers on the target, for static tracepoints | |
13968 | that have not been set by marker id. Static tracepoint that have | |
13969 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13970 | The heuristic is: | |
13971 | ||
13972 | 1) For a tracepoint set at a specific address, look for a marker at | |
13973 | the old PC. If one is found there, assume to be the same marker. | |
13974 | If the name / string id of the marker found is different from the | |
13975 | previous known name, assume that means the user renamed the marker | |
13976 | in the sources, and output a warning. | |
13977 | ||
13978 | 2) For a tracepoint set at a given line number, look for a marker | |
13979 | at the new address of the old line number. If one is found there, | |
13980 | assume to be the same marker. If the name / string id of the | |
13981 | marker found is different from the previous known name, assume that | |
13982 | means the user renamed the marker in the sources, and output a | |
13983 | warning. | |
13984 | ||
13985 | 3) If a marker is no longer found at the same address or line, it | |
13986 | may mean the marker no longer exists. But it may also just mean | |
13987 | the code changed a bit. Maybe the user added a few lines of code | |
13988 | that made the marker move up or down (in line number terms). Ask | |
13989 | the target for info about the marker with the string id as we knew | |
13990 | it. If found, update line number and address in the matching | |
13991 | static tracepoint. This will get confused if there's more than one | |
13992 | marker with the same ID (possible in UST, although unadvised | |
13993 | precisely because it confuses tools). */ | |
13994 | ||
13995 | static struct symtab_and_line | |
13996 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13997 | { | |
d9b3f62e | 13998 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13999 | struct static_tracepoint_marker marker; |
14000 | CORE_ADDR pc; | |
0fb4aa4b PA |
14001 | |
14002 | pc = sal.pc; | |
14003 | if (sal.line) | |
14004 | find_line_pc (sal.symtab, sal.line, &pc); | |
14005 | ||
14006 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14007 | { | |
d9b3f62e | 14008 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14009 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14010 | b->number, | |
d9b3f62e | 14011 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14012 | |
d9b3f62e PA |
14013 | xfree (tp->static_trace_marker_id); |
14014 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14015 | release_static_tracepoint_marker (&marker); |
14016 | ||
14017 | return sal; | |
14018 | } | |
14019 | ||
14020 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14021 | by string ID. */ | |
14022 | if (!sal.explicit_pc | |
14023 | && sal.line != 0 | |
14024 | && sal.symtab != NULL | |
d9b3f62e | 14025 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14026 | { |
14027 | VEC(static_tracepoint_marker_p) *markers; | |
14028 | ||
14029 | markers | |
d9b3f62e | 14030 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14031 | |
14032 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14033 | { | |
80e1d417 | 14034 | struct symtab_and_line sal2; |
0fb4aa4b | 14035 | struct symbol *sym; |
80e1d417 | 14036 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14037 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14038 | |
80e1d417 | 14039 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14040 | |
d9b3f62e | 14041 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14042 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14043 | |
14044 | warning (_("marker for static tracepoint %d (%s) not " | |
14045 | "found at previous line number"), | |
d9b3f62e | 14046 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14047 | |
80e1d417 | 14048 | init_sal (&sal2); |
0fb4aa4b | 14049 | |
80e1d417 | 14050 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14051 | |
80e1d417 AS |
14052 | sal2 = find_pc_line (tpmarker->address, 0); |
14053 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14054 | ui_out_text (uiout, "Now in "); |
14055 | if (sym) | |
14056 | { | |
14057 | ui_out_field_string (uiout, "func", | |
14058 | SYMBOL_PRINT_NAME (sym)); | |
14059 | ui_out_text (uiout, " at "); | |
14060 | } | |
05cba821 JK |
14061 | ui_out_field_string (uiout, "file", |
14062 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14063 | ui_out_text (uiout, ":"); |
14064 | ||
14065 | if (ui_out_is_mi_like_p (uiout)) | |
14066 | { | |
0b0865da | 14067 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14068 | |
f35a17b5 | 14069 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14070 | } |
14071 | ||
80e1d417 | 14072 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14073 | ui_out_text (uiout, "\n"); |
14074 | ||
80e1d417 | 14075 | b->loc->line_number = sal2.line; |
2f202fde | 14076 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14077 | |
14078 | xfree (b->addr_string); | |
14079 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14080 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14081 | b->loc->line_number); |
0fb4aa4b PA |
14082 | |
14083 | /* Might be nice to check if function changed, and warn if | |
14084 | so. */ | |
14085 | ||
80e1d417 | 14086 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14087 | } |
14088 | } | |
14089 | return sal; | |
14090 | } | |
14091 | ||
8d3788bd VP |
14092 | /* Returns 1 iff locations A and B are sufficiently same that |
14093 | we don't need to report breakpoint as changed. */ | |
14094 | ||
14095 | static int | |
14096 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14097 | { | |
14098 | while (a && b) | |
14099 | { | |
14100 | if (a->address != b->address) | |
14101 | return 0; | |
14102 | ||
14103 | if (a->shlib_disabled != b->shlib_disabled) | |
14104 | return 0; | |
14105 | ||
14106 | if (a->enabled != b->enabled) | |
14107 | return 0; | |
14108 | ||
14109 | a = a->next; | |
14110 | b = b->next; | |
14111 | } | |
14112 | ||
14113 | if ((a == NULL) != (b == NULL)) | |
14114 | return 0; | |
14115 | ||
14116 | return 1; | |
14117 | } | |
14118 | ||
f1310107 TJB |
14119 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14120 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14121 | a ranged breakpoint. */ | |
14122 | ||
0e30163f | 14123 | void |
0d381245 | 14124 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14125 | struct symtabs_and_lines sals, |
14126 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14127 | { |
14128 | int i; | |
0d381245 VP |
14129 | struct bp_location *existing_locations = b->loc; |
14130 | ||
f8eba3c6 TT |
14131 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14132 | { | |
14133 | /* Ranged breakpoints have only one start location and one end | |
14134 | location. */ | |
14135 | b->enable_state = bp_disabled; | |
14136 | update_global_location_list (1); | |
14137 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " | |
14138 | "multiple locations found\n"), | |
14139 | b->number); | |
14140 | return; | |
14141 | } | |
f1310107 | 14142 | |
4a64f543 MS |
14143 | /* If there's no new locations, and all existing locations are |
14144 | pending, don't do anything. This optimizes the common case where | |
14145 | all locations are in the same shared library, that was unloaded. | |
14146 | We'd like to retain the location, so that when the library is | |
14147 | loaded again, we don't loose the enabled/disabled status of the | |
14148 | individual locations. */ | |
0d381245 | 14149 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14150 | return; |
14151 | ||
fe3f5fa8 VP |
14152 | b->loc = NULL; |
14153 | ||
0d381245 | 14154 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14155 | { |
f8eba3c6 TT |
14156 | struct bp_location *new_loc; |
14157 | ||
14158 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14159 | ||
14160 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14161 | |
0d381245 VP |
14162 | /* Reparse conditions, they might contain references to the |
14163 | old symtab. */ | |
14164 | if (b->cond_string != NULL) | |
14165 | { | |
bbc13ae3 | 14166 | const char *s; |
bfd189b1 | 14167 | volatile struct gdb_exception e; |
fe3f5fa8 | 14168 | |
0d381245 VP |
14169 | s = b->cond_string; |
14170 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14171 | { | |
1bb9788d TT |
14172 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14173 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14174 | 0); |
14175 | } | |
14176 | if (e.reason < 0) | |
14177 | { | |
3e43a32a MS |
14178 | warning (_("failed to reevaluate condition " |
14179 | "for breakpoint %d: %s"), | |
0d381245 VP |
14180 | b->number, e.message); |
14181 | new_loc->enabled = 0; | |
14182 | } | |
14183 | } | |
fe3f5fa8 | 14184 | |
f1310107 TJB |
14185 | if (sals_end.nelts) |
14186 | { | |
14187 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14188 | ||
14189 | new_loc->length = end - sals.sals[0].pc + 1; | |
14190 | } | |
0d381245 | 14191 | } |
fe3f5fa8 | 14192 | |
514f746b AR |
14193 | /* Update locations of permanent breakpoints. */ |
14194 | if (b->enable_state == bp_permanent) | |
14195 | make_breakpoint_permanent (b); | |
14196 | ||
4a64f543 MS |
14197 | /* If possible, carry over 'disable' status from existing |
14198 | breakpoints. */ | |
0d381245 VP |
14199 | { |
14200 | struct bp_location *e = existing_locations; | |
776592bf DE |
14201 | /* If there are multiple breakpoints with the same function name, |
14202 | e.g. for inline functions, comparing function names won't work. | |
14203 | Instead compare pc addresses; this is just a heuristic as things | |
14204 | may have moved, but in practice it gives the correct answer | |
14205 | often enough until a better solution is found. */ | |
14206 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14207 | ||
0d381245 VP |
14208 | for (; e; e = e->next) |
14209 | { | |
14210 | if (!e->enabled && e->function_name) | |
14211 | { | |
14212 | struct bp_location *l = b->loc; | |
776592bf DE |
14213 | if (have_ambiguous_names) |
14214 | { | |
14215 | for (; l; l = l->next) | |
f1310107 | 14216 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14217 | { |
14218 | l->enabled = 0; | |
14219 | break; | |
14220 | } | |
14221 | } | |
14222 | else | |
14223 | { | |
14224 | for (; l; l = l->next) | |
14225 | if (l->function_name | |
14226 | && strcmp (e->function_name, l->function_name) == 0) | |
14227 | { | |
14228 | l->enabled = 0; | |
14229 | break; | |
14230 | } | |
14231 | } | |
0d381245 VP |
14232 | } |
14233 | } | |
14234 | } | |
fe3f5fa8 | 14235 | |
8d3788bd VP |
14236 | if (!locations_are_equal (existing_locations, b->loc)) |
14237 | observer_notify_breakpoint_modified (b); | |
14238 | ||
b60e7edf | 14239 | update_global_location_list (1); |
fe3f5fa8 VP |
14240 | } |
14241 | ||
ef23e705 TJB |
14242 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14243 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14244 | ||
14245 | static struct symtabs_and_lines | |
14246 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14247 | { | |
14248 | char *s; | |
02d20e4a | 14249 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14250 | volatile struct gdb_exception e; |
ef23e705 | 14251 | |
983af33b | 14252 | gdb_assert (b->ops != NULL); |
ef23e705 | 14253 | s = addr_string; |
ef23e705 TJB |
14254 | |
14255 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14256 | { | |
983af33b | 14257 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14258 | } |
14259 | if (e.reason < 0) | |
14260 | { | |
14261 | int not_found_and_ok = 0; | |
14262 | /* For pending breakpoints, it's expected that parsing will | |
14263 | fail until the right shared library is loaded. User has | |
14264 | already told to create pending breakpoints and don't need | |
14265 | extra messages. If breakpoint is in bp_shlib_disabled | |
14266 | state, then user already saw the message about that | |
14267 | breakpoint being disabled, and don't want to see more | |
14268 | errors. */ | |
58438ac1 | 14269 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14270 | && (b->condition_not_parsed |
14271 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14272 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14273 | || b->enable_state == bp_disabled)) |
14274 | not_found_and_ok = 1; | |
14275 | ||
14276 | if (!not_found_and_ok) | |
14277 | { | |
14278 | /* We surely don't want to warn about the same breakpoint | |
14279 | 10 times. One solution, implemented here, is disable | |
14280 | the breakpoint on error. Another solution would be to | |
14281 | have separate 'warning emitted' flag. Since this | |
14282 | happens only when a binary has changed, I don't know | |
14283 | which approach is better. */ | |
14284 | b->enable_state = bp_disabled; | |
14285 | throw_exception (e); | |
14286 | } | |
14287 | } | |
14288 | ||
58438ac1 | 14289 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14290 | { |
f8eba3c6 | 14291 | int i; |
ef23e705 | 14292 | |
f8eba3c6 TT |
14293 | for (i = 0; i < sals.nelts; ++i) |
14294 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14295 | if (b->condition_not_parsed && s && s[0]) |
14296 | { | |
ed1d1739 KS |
14297 | char *cond_string, *extra_string; |
14298 | int thread, task; | |
ef23e705 TJB |
14299 | |
14300 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14301 | &cond_string, &thread, &task, |
14302 | &extra_string); | |
ef23e705 TJB |
14303 | if (cond_string) |
14304 | b->cond_string = cond_string; | |
14305 | b->thread = thread; | |
14306 | b->task = task; | |
e7e0cddf SS |
14307 | if (extra_string) |
14308 | b->extra_string = extra_string; | |
ef23e705 TJB |
14309 | b->condition_not_parsed = 0; |
14310 | } | |
14311 | ||
983af33b | 14312 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14313 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14314 | |
58438ac1 TT |
14315 | *found = 1; |
14316 | } | |
14317 | else | |
14318 | *found = 0; | |
ef23e705 TJB |
14319 | |
14320 | return sals; | |
14321 | } | |
14322 | ||
348d480f PA |
14323 | /* The default re_set method, for typical hardware or software |
14324 | breakpoints. Reevaluate the breakpoint and recreate its | |
14325 | locations. */ | |
14326 | ||
14327 | static void | |
28010a5d | 14328 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14329 | { |
14330 | int found; | |
f1310107 | 14331 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14332 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14333 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14334 | |
14335 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14336 | if (found) | |
14337 | { | |
14338 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14339 | expanded = sals; |
ef23e705 TJB |
14340 | } |
14341 | ||
f1310107 TJB |
14342 | if (b->addr_string_range_end) |
14343 | { | |
14344 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14345 | if (found) | |
14346 | { | |
14347 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14348 | expanded_end = sals_end; |
f1310107 TJB |
14349 | } |
14350 | } | |
14351 | ||
14352 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14353 | } |
14354 | ||
983af33b SDJ |
14355 | /* Default method for creating SALs from an address string. It basically |
14356 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14357 | ||
14358 | static void | |
14359 | create_sals_from_address_default (char **arg, | |
14360 | struct linespec_result *canonical, | |
14361 | enum bptype type_wanted, | |
14362 | char *addr_start, char **copy_arg) | |
14363 | { | |
14364 | parse_breakpoint_sals (arg, canonical); | |
14365 | } | |
14366 | ||
14367 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14368 | function for the `create_breakpoints_sal' method of | |
14369 | breakpoint_ops. */ | |
14370 | ||
14371 | static void | |
14372 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14373 | struct linespec_result *canonical, | |
983af33b | 14374 | char *cond_string, |
e7e0cddf | 14375 | char *extra_string, |
983af33b SDJ |
14376 | enum bptype type_wanted, |
14377 | enum bpdisp disposition, | |
14378 | int thread, | |
14379 | int task, int ignore_count, | |
14380 | const struct breakpoint_ops *ops, | |
14381 | int from_tty, int enabled, | |
44f238bb | 14382 | int internal, unsigned flags) |
983af33b SDJ |
14383 | { |
14384 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14385 | extra_string, |
983af33b SDJ |
14386 | type_wanted, disposition, |
14387 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14388 | enabled, internal, flags); |
983af33b SDJ |
14389 | } |
14390 | ||
14391 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14392 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14393 | ||
14394 | static void | |
14395 | decode_linespec_default (struct breakpoint *b, char **s, | |
14396 | struct symtabs_and_lines *sals) | |
14397 | { | |
14398 | struct linespec_result canonical; | |
14399 | ||
14400 | init_linespec_result (&canonical); | |
14401 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14402 | (struct symtab *) NULL, 0, | |
14403 | &canonical, multiple_symbols_all, | |
14404 | b->filter); | |
14405 | ||
14406 | /* We should get 0 or 1 resulting SALs. */ | |
14407 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14408 | ||
14409 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14410 | { | |
14411 | struct linespec_sals *lsal; | |
14412 | ||
14413 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14414 | *sals = lsal->sals; | |
14415 | /* Arrange it so the destructor does not free the | |
14416 | contents. */ | |
14417 | lsal->sals.sals = NULL; | |
14418 | } | |
14419 | ||
14420 | destroy_linespec_result (&canonical); | |
14421 | } | |
14422 | ||
28010a5d PA |
14423 | /* Prepare the global context for a re-set of breakpoint B. */ |
14424 | ||
14425 | static struct cleanup * | |
14426 | prepare_re_set_context (struct breakpoint *b) | |
14427 | { | |
14428 | struct cleanup *cleanups; | |
14429 | ||
14430 | input_radix = b->input_radix; | |
14431 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14432 | if (b->pspace != NULL) |
14433 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14434 | set_language (b->language); |
14435 | ||
14436 | return cleanups; | |
ef23e705 TJB |
14437 | } |
14438 | ||
c906108c SS |
14439 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14440 | The value we return ends up being the return value from catch_errors. | |
14441 | Unused in this case. */ | |
14442 | ||
14443 | static int | |
4efb68b1 | 14444 | breakpoint_re_set_one (void *bint) |
c906108c | 14445 | { |
4a64f543 | 14446 | /* Get past catch_errs. */ |
53a5351d | 14447 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14448 | struct cleanup *cleanups; |
c906108c | 14449 | |
348d480f PA |
14450 | cleanups = prepare_re_set_context (b); |
14451 | b->ops->re_set (b); | |
14452 | do_cleanups (cleanups); | |
c906108c SS |
14453 | return 0; |
14454 | } | |
14455 | ||
69de3c6a | 14456 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14457 | void |
69de3c6a | 14458 | breakpoint_re_set (void) |
c906108c | 14459 | { |
35df4500 | 14460 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14461 | enum language save_language; |
14462 | int save_input_radix; | |
6c95b8df | 14463 | struct cleanup *old_chain; |
c5aa993b | 14464 | |
c906108c SS |
14465 | save_language = current_language->la_language; |
14466 | save_input_radix = input_radix; | |
6c95b8df PA |
14467 | old_chain = save_current_program_space (); |
14468 | ||
35df4500 | 14469 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14470 | { |
4a64f543 | 14471 | /* Format possible error msg. */ |
fe3f5fa8 | 14472 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14473 | b->number); |
14474 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14475 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14476 | do_cleanups (cleanups); |
c5aa993b | 14477 | } |
c906108c SS |
14478 | set_language (save_language); |
14479 | input_radix = save_input_radix; | |
e62c965a | 14480 | |
0756c555 | 14481 | jit_breakpoint_re_set (); |
4efc6507 | 14482 | |
6c95b8df PA |
14483 | do_cleanups (old_chain); |
14484 | ||
af02033e PP |
14485 | create_overlay_event_breakpoint (); |
14486 | create_longjmp_master_breakpoint (); | |
14487 | create_std_terminate_master_breakpoint (); | |
186c406b | 14488 | create_exception_master_breakpoint (); |
c906108c SS |
14489 | } |
14490 | \f | |
c906108c SS |
14491 | /* Reset the thread number of this breakpoint: |
14492 | ||
14493 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14494 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14495 | void |
fba45db2 | 14496 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14497 | { |
14498 | if (b->thread != -1) | |
14499 | { | |
39f77062 KB |
14500 | if (in_thread_list (inferior_ptid)) |
14501 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14502 | |
14503 | /* We're being called after following a fork. The new fork is | |
14504 | selected as current, and unless this was a vfork will have a | |
14505 | different program space from the original thread. Reset that | |
14506 | as well. */ | |
14507 | b->loc->pspace = current_program_space; | |
c906108c SS |
14508 | } |
14509 | } | |
14510 | ||
03ac34d5 MS |
14511 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14512 | If from_tty is nonzero, it prints a message to that effect, | |
14513 | which ends with a period (no newline). */ | |
14514 | ||
c906108c | 14515 | void |
fba45db2 | 14516 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14517 | { |
52f0bd74 | 14518 | struct breakpoint *b; |
c906108c SS |
14519 | |
14520 | if (count < 0) | |
14521 | count = 0; | |
14522 | ||
14523 | ALL_BREAKPOINTS (b) | |
14524 | if (b->number == bptnum) | |
c5aa993b | 14525 | { |
d77f58be SS |
14526 | if (is_tracepoint (b)) |
14527 | { | |
14528 | if (from_tty && count != 0) | |
14529 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14530 | bptnum); | |
14531 | return; | |
14532 | } | |
14533 | ||
c5aa993b | 14534 | b->ignore_count = count; |
221ea385 KS |
14535 | if (from_tty) |
14536 | { | |
14537 | if (count == 0) | |
3e43a32a MS |
14538 | printf_filtered (_("Will stop next time " |
14539 | "breakpoint %d is reached."), | |
221ea385 KS |
14540 | bptnum); |
14541 | else if (count == 1) | |
a3f17187 | 14542 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14543 | bptnum); |
14544 | else | |
3e43a32a MS |
14545 | printf_filtered (_("Will ignore next %d " |
14546 | "crossings of breakpoint %d."), | |
221ea385 KS |
14547 | count, bptnum); |
14548 | } | |
8d3788bd | 14549 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14550 | return; |
14551 | } | |
c906108c | 14552 | |
8a3fe4f8 | 14553 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14554 | } |
14555 | ||
c906108c SS |
14556 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14557 | ||
14558 | static void | |
fba45db2 | 14559 | ignore_command (char *args, int from_tty) |
c906108c SS |
14560 | { |
14561 | char *p = args; | |
52f0bd74 | 14562 | int num; |
c906108c SS |
14563 | |
14564 | if (p == 0) | |
e2e0b3e5 | 14565 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14566 | |
c906108c | 14567 | num = get_number (&p); |
5c44784c | 14568 | if (num == 0) |
8a3fe4f8 | 14569 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14570 | if (*p == 0) |
8a3fe4f8 | 14571 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14572 | |
14573 | set_ignore_count (num, | |
14574 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14575 | from_tty); | |
221ea385 KS |
14576 | if (from_tty) |
14577 | printf_filtered ("\n"); | |
c906108c SS |
14578 | } |
14579 | \f | |
14580 | /* Call FUNCTION on each of the breakpoints | |
14581 | whose numbers are given in ARGS. */ | |
14582 | ||
14583 | static void | |
95a42b64 TT |
14584 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14585 | void *), | |
14586 | void *data) | |
c906108c | 14587 | { |
52f0bd74 AC |
14588 | int num; |
14589 | struct breakpoint *b, *tmp; | |
11cf8741 | 14590 | int match; |
197f0a60 | 14591 | struct get_number_or_range_state state; |
c906108c | 14592 | |
197f0a60 | 14593 | if (args == 0) |
e2e0b3e5 | 14594 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14595 | |
197f0a60 TT |
14596 | init_number_or_range (&state, args); |
14597 | ||
14598 | while (!state.finished) | |
c906108c | 14599 | { |
197f0a60 TT |
14600 | char *p = state.string; |
14601 | ||
11cf8741 | 14602 | match = 0; |
c5aa993b | 14603 | |
197f0a60 | 14604 | num = get_number_or_range (&state); |
5c44784c | 14605 | if (num == 0) |
c5aa993b | 14606 | { |
8a3fe4f8 | 14607 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14608 | } |
14609 | else | |
14610 | { | |
14611 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14612 | if (b->number == num) | |
14613 | { | |
11cf8741 | 14614 | match = 1; |
cdac0397 | 14615 | function (b, data); |
11cf8741 | 14616 | break; |
5c44784c | 14617 | } |
11cf8741 | 14618 | if (match == 0) |
a3f17187 | 14619 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14620 | } |
c906108c SS |
14621 | } |
14622 | } | |
14623 | ||
0d381245 VP |
14624 | static struct bp_location * |
14625 | find_location_by_number (char *number) | |
14626 | { | |
14627 | char *dot = strchr (number, '.'); | |
14628 | char *p1; | |
14629 | int bp_num; | |
14630 | int loc_num; | |
14631 | struct breakpoint *b; | |
14632 | struct bp_location *loc; | |
14633 | ||
14634 | *dot = '\0'; | |
14635 | ||
14636 | p1 = number; | |
197f0a60 | 14637 | bp_num = get_number (&p1); |
0d381245 VP |
14638 | if (bp_num == 0) |
14639 | error (_("Bad breakpoint number '%s'"), number); | |
14640 | ||
14641 | ALL_BREAKPOINTS (b) | |
14642 | if (b->number == bp_num) | |
14643 | { | |
14644 | break; | |
14645 | } | |
14646 | ||
14647 | if (!b || b->number != bp_num) | |
14648 | error (_("Bad breakpoint number '%s'"), number); | |
14649 | ||
14650 | p1 = dot+1; | |
197f0a60 | 14651 | loc_num = get_number (&p1); |
0d381245 VP |
14652 | if (loc_num == 0) |
14653 | error (_("Bad breakpoint location number '%s'"), number); | |
14654 | ||
14655 | --loc_num; | |
14656 | loc = b->loc; | |
14657 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14658 | ; | |
14659 | if (!loc) | |
14660 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14661 | ||
14662 | return loc; | |
14663 | } | |
14664 | ||
14665 | ||
1900040c MS |
14666 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14667 | If from_tty is nonzero, it prints a message to that effect, | |
14668 | which ends with a period (no newline). */ | |
14669 | ||
c906108c | 14670 | void |
fba45db2 | 14671 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14672 | { |
14673 | /* Never disable a watchpoint scope breakpoint; we want to | |
14674 | hit them when we leave scope so we can delete both the | |
14675 | watchpoint and its scope breakpoint at that time. */ | |
14676 | if (bpt->type == bp_watchpoint_scope) | |
14677 | return; | |
14678 | ||
c2c6d25f | 14679 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 14680 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
14681 | return; |
14682 | ||
b5de0fa7 | 14683 | bpt->enable_state = bp_disabled; |
c906108c | 14684 | |
b775012e LM |
14685 | /* Mark breakpoint locations modified. */ |
14686 | mark_breakpoint_modified (bpt); | |
14687 | ||
d248b706 KY |
14688 | if (target_supports_enable_disable_tracepoint () |
14689 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14690 | { | |
14691 | struct bp_location *location; | |
14692 | ||
14693 | for (location = bpt->loc; location; location = location->next) | |
14694 | target_disable_tracepoint (location); | |
14695 | } | |
14696 | ||
b60e7edf | 14697 | update_global_location_list (0); |
c906108c | 14698 | |
8d3788bd | 14699 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14700 | } |
14701 | ||
51be5b68 PA |
14702 | /* A callback for iterate_over_related_breakpoints. */ |
14703 | ||
14704 | static void | |
14705 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14706 | { | |
14707 | disable_breakpoint (b); | |
14708 | } | |
14709 | ||
95a42b64 TT |
14710 | /* A callback for map_breakpoint_numbers that calls |
14711 | disable_breakpoint. */ | |
14712 | ||
14713 | static void | |
14714 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14715 | { | |
51be5b68 | 14716 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14717 | } |
14718 | ||
c906108c | 14719 | static void |
fba45db2 | 14720 | disable_command (char *args, int from_tty) |
c906108c | 14721 | { |
c906108c | 14722 | if (args == 0) |
46c6471b PA |
14723 | { |
14724 | struct breakpoint *bpt; | |
14725 | ||
14726 | ALL_BREAKPOINTS (bpt) | |
14727 | if (user_breakpoint_p (bpt)) | |
14728 | disable_breakpoint (bpt); | |
14729 | } | |
9eaabc75 | 14730 | else |
0d381245 | 14731 | { |
9eaabc75 MW |
14732 | char *num = extract_arg (&args); |
14733 | ||
14734 | while (num) | |
d248b706 | 14735 | { |
9eaabc75 | 14736 | if (strchr (num, '.')) |
b775012e | 14737 | { |
9eaabc75 MW |
14738 | struct bp_location *loc = find_location_by_number (num); |
14739 | ||
14740 | if (loc) | |
14741 | { | |
14742 | if (loc->enabled) | |
14743 | { | |
14744 | loc->enabled = 0; | |
14745 | mark_breakpoint_location_modified (loc); | |
14746 | } | |
14747 | if (target_supports_enable_disable_tracepoint () | |
14748 | && current_trace_status ()->running && loc->owner | |
14749 | && is_tracepoint (loc->owner)) | |
14750 | target_disable_tracepoint (loc); | |
14751 | } | |
14752 | update_global_location_list (0); | |
b775012e | 14753 | } |
9eaabc75 MW |
14754 | else |
14755 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14756 | num = extract_arg (&args); | |
d248b706 | 14757 | } |
0d381245 | 14758 | } |
c906108c SS |
14759 | } |
14760 | ||
14761 | static void | |
816338b5 SS |
14762 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14763 | int count) | |
c906108c | 14764 | { |
afe38095 | 14765 | int target_resources_ok; |
c906108c SS |
14766 | |
14767 | if (bpt->type == bp_hardware_breakpoint) | |
14768 | { | |
14769 | int i; | |
c5aa993b | 14770 | i = hw_breakpoint_used_count (); |
53a5351d | 14771 | target_resources_ok = |
d92524f1 | 14772 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14773 | i + 1, 0); |
c906108c | 14774 | if (target_resources_ok == 0) |
8a3fe4f8 | 14775 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14776 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14777 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14778 | } |
14779 | ||
cc60f2e3 | 14780 | if (is_watchpoint (bpt)) |
c906108c | 14781 | { |
d07205c2 JK |
14782 | /* Initialize it just to avoid a GCC false warning. */ |
14783 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 14784 | volatile struct gdb_exception e; |
dde02812 ES |
14785 | |
14786 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 14787 | { |
3a5c3e22 PA |
14788 | struct watchpoint *w = (struct watchpoint *) bpt; |
14789 | ||
1e718ff1 TJB |
14790 | orig_enable_state = bpt->enable_state; |
14791 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14792 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14793 | } |
dde02812 | 14794 | if (e.reason < 0) |
c5aa993b | 14795 | { |
1e718ff1 | 14796 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14797 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14798 | bpt->number); | |
14799 | return; | |
c5aa993b | 14800 | } |
c906108c | 14801 | } |
0101ce28 | 14802 | |
b4c291bb KH |
14803 | if (bpt->enable_state != bp_permanent) |
14804 | bpt->enable_state = bp_enabled; | |
d248b706 | 14805 | |
b775012e LM |
14806 | bpt->enable_state = bp_enabled; |
14807 | ||
14808 | /* Mark breakpoint locations modified. */ | |
14809 | mark_breakpoint_modified (bpt); | |
14810 | ||
d248b706 KY |
14811 | if (target_supports_enable_disable_tracepoint () |
14812 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14813 | { | |
14814 | struct bp_location *location; | |
14815 | ||
14816 | for (location = bpt->loc; location; location = location->next) | |
14817 | target_enable_tracepoint (location); | |
14818 | } | |
14819 | ||
b4c291bb | 14820 | bpt->disposition = disposition; |
816338b5 | 14821 | bpt->enable_count = count; |
b60e7edf | 14822 | update_global_location_list (1); |
9c97429f | 14823 | |
8d3788bd | 14824 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14825 | } |
14826 | ||
fe3f5fa8 | 14827 | |
c906108c | 14828 | void |
fba45db2 | 14829 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14830 | { |
816338b5 | 14831 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14832 | } |
14833 | ||
14834 | static void | |
14835 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14836 | { | |
14837 | enable_breakpoint (bpt); | |
c906108c SS |
14838 | } |
14839 | ||
95a42b64 TT |
14840 | /* A callback for map_breakpoint_numbers that calls |
14841 | enable_breakpoint. */ | |
14842 | ||
14843 | static void | |
14844 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14845 | { | |
51be5b68 | 14846 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14847 | } |
14848 | ||
c906108c SS |
14849 | /* The enable command enables the specified breakpoints (or all defined |
14850 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14851 | in stopping the inferior. */ |
c906108c | 14852 | |
c906108c | 14853 | static void |
fba45db2 | 14854 | enable_command (char *args, int from_tty) |
c906108c | 14855 | { |
c906108c | 14856 | if (args == 0) |
46c6471b PA |
14857 | { |
14858 | struct breakpoint *bpt; | |
14859 | ||
14860 | ALL_BREAKPOINTS (bpt) | |
14861 | if (user_breakpoint_p (bpt)) | |
14862 | enable_breakpoint (bpt); | |
14863 | } | |
9eaabc75 | 14864 | else |
0d381245 | 14865 | { |
9eaabc75 MW |
14866 | char *num = extract_arg (&args); |
14867 | ||
14868 | while (num) | |
d248b706 | 14869 | { |
9eaabc75 | 14870 | if (strchr (num, '.')) |
b775012e | 14871 | { |
9eaabc75 MW |
14872 | struct bp_location *loc = find_location_by_number (num); |
14873 | ||
14874 | if (loc) | |
14875 | { | |
14876 | if (!loc->enabled) | |
14877 | { | |
14878 | loc->enabled = 1; | |
14879 | mark_breakpoint_location_modified (loc); | |
14880 | } | |
14881 | if (target_supports_enable_disable_tracepoint () | |
14882 | && current_trace_status ()->running && loc->owner | |
14883 | && is_tracepoint (loc->owner)) | |
14884 | target_enable_tracepoint (loc); | |
14885 | } | |
14886 | update_global_location_list (1); | |
b775012e | 14887 | } |
9eaabc75 MW |
14888 | else |
14889 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14890 | num = extract_arg (&args); | |
d248b706 | 14891 | } |
0d381245 | 14892 | } |
c906108c SS |
14893 | } |
14894 | ||
816338b5 SS |
14895 | /* This struct packages up disposition data for application to multiple |
14896 | breakpoints. */ | |
14897 | ||
14898 | struct disp_data | |
14899 | { | |
14900 | enum bpdisp disp; | |
14901 | int count; | |
14902 | }; | |
14903 | ||
c906108c | 14904 | static void |
51be5b68 PA |
14905 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14906 | { | |
816338b5 | 14907 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14908 | |
816338b5 | 14909 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14910 | } |
14911 | ||
14912 | static void | |
14913 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14914 | { |
816338b5 | 14915 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14916 | |
14917 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14918 | } |
14919 | ||
c906108c | 14920 | static void |
fba45db2 | 14921 | enable_once_command (char *args, int from_tty) |
c906108c | 14922 | { |
51be5b68 | 14923 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14924 | } |
14925 | ||
816338b5 SS |
14926 | static void |
14927 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14928 | { | |
14929 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14930 | ||
14931 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14932 | } | |
14933 | ||
14934 | static void | |
14935 | enable_count_command (char *args, int from_tty) | |
14936 | { | |
14937 | int count = get_number (&args); | |
14938 | ||
14939 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14940 | } | |
14941 | ||
c906108c | 14942 | static void |
51be5b68 | 14943 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14944 | { |
816338b5 | 14945 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14946 | |
14947 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14948 | } |
14949 | ||
c906108c | 14950 | static void |
fba45db2 | 14951 | enable_delete_command (char *args, int from_tty) |
c906108c | 14952 | { |
51be5b68 | 14953 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14954 | } |
14955 | \f | |
fa8d40ab JJ |
14956 | static void |
14957 | set_breakpoint_cmd (char *args, int from_tty) | |
14958 | { | |
14959 | } | |
14960 | ||
14961 | static void | |
14962 | show_breakpoint_cmd (char *args, int from_tty) | |
14963 | { | |
14964 | } | |
14965 | ||
1f3b5d1b PP |
14966 | /* Invalidate last known value of any hardware watchpoint if |
14967 | the memory which that value represents has been written to by | |
14968 | GDB itself. */ | |
14969 | ||
14970 | static void | |
8de0566d YQ |
14971 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14972 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14973 | const bfd_byte *data) |
14974 | { | |
14975 | struct breakpoint *bp; | |
14976 | ||
14977 | ALL_BREAKPOINTS (bp) | |
14978 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14979 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14980 | { |
3a5c3e22 | 14981 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14982 | |
3a5c3e22 PA |
14983 | if (wp->val_valid && wp->val) |
14984 | { | |
14985 | struct bp_location *loc; | |
14986 | ||
14987 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14988 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14989 | && loc->address + loc->length > addr | |
14990 | && addr + len > loc->address) | |
14991 | { | |
14992 | value_free (wp->val); | |
14993 | wp->val = NULL; | |
14994 | wp->val_valid = 0; | |
14995 | } | |
14996 | } | |
1f3b5d1b PP |
14997 | } |
14998 | } | |
14999 | ||
8181d85f DJ |
15000 | /* Create and insert a raw software breakpoint at PC. Return an |
15001 | identifier, which should be used to remove the breakpoint later. | |
15002 | In general, places which call this should be using something on the | |
15003 | breakpoint chain instead; this function should be eliminated | |
15004 | someday. */ | |
15005 | ||
15006 | void * | |
6c95b8df PA |
15007 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
15008 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
15009 | { |
15010 | struct bp_target_info *bp_tgt; | |
15011 | ||
41bf6aca | 15012 | bp_tgt = XCNEW (struct bp_target_info); |
8181d85f | 15013 | |
6c95b8df | 15014 | bp_tgt->placed_address_space = aspace; |
8181d85f | 15015 | bp_tgt->placed_address = pc; |
6c95b8df | 15016 | |
a6d9a66e | 15017 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
15018 | { |
15019 | /* Could not insert the breakpoint. */ | |
15020 | xfree (bp_tgt); | |
15021 | return NULL; | |
15022 | } | |
15023 | ||
15024 | return bp_tgt; | |
15025 | } | |
15026 | ||
4a64f543 MS |
15027 | /* Remove a breakpoint BP inserted by |
15028 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
15029 | |
15030 | int | |
a6d9a66e | 15031 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
15032 | { |
15033 | struct bp_target_info *bp_tgt = bp; | |
15034 | int ret; | |
15035 | ||
a6d9a66e | 15036 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
15037 | xfree (bp_tgt); |
15038 | ||
15039 | return ret; | |
15040 | } | |
15041 | ||
4a64f543 MS |
15042 | /* One (or perhaps two) breakpoints used for software single |
15043 | stepping. */ | |
8181d85f DJ |
15044 | |
15045 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 15046 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
15047 | |
15048 | /* Create and insert a breakpoint for software single step. */ | |
15049 | ||
15050 | void | |
6c95b8df | 15051 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15052 | struct address_space *aspace, |
15053 | CORE_ADDR next_pc) | |
8181d85f DJ |
15054 | { |
15055 | void **bpt_p; | |
15056 | ||
15057 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15058 | { |
15059 | bpt_p = &single_step_breakpoints[0]; | |
15060 | single_step_gdbarch[0] = gdbarch; | |
15061 | } | |
8181d85f DJ |
15062 | else |
15063 | { | |
15064 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15065 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15066 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15067 | } |
15068 | ||
4a64f543 MS |
15069 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15070 | be to only create the breakpoints once, and actually put them on | |
15071 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15072 | We could adjust the addresses each time they were needed. Doing | |
15073 | this requires corresponding changes elsewhere where single step | |
15074 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15075 | |
6c95b8df | 15076 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15077 | if (*bpt_p == NULL) |
5af949e3 UW |
15078 | error (_("Could not insert single-step breakpoint at %s"), |
15079 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15080 | } |
15081 | ||
f02253f1 HZ |
15082 | /* Check if the breakpoints used for software single stepping |
15083 | were inserted or not. */ | |
15084 | ||
15085 | int | |
15086 | single_step_breakpoints_inserted (void) | |
15087 | { | |
15088 | return (single_step_breakpoints[0] != NULL | |
15089 | || single_step_breakpoints[1] != NULL); | |
15090 | } | |
15091 | ||
8181d85f DJ |
15092 | /* Remove and delete any breakpoints used for software single step. */ |
15093 | ||
15094 | void | |
15095 | remove_single_step_breakpoints (void) | |
15096 | { | |
15097 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15098 | ||
15099 | /* See insert_single_step_breakpoint for more about this deprecated | |
15100 | call. */ | |
a6d9a66e UW |
15101 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15102 | single_step_breakpoints[0]); | |
15103 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15104 | single_step_breakpoints[0] = NULL; |
15105 | ||
15106 | if (single_step_breakpoints[1] != NULL) | |
15107 | { | |
a6d9a66e UW |
15108 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15109 | single_step_breakpoints[1]); | |
15110 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15111 | single_step_breakpoints[1] = NULL; |
15112 | } | |
15113 | } | |
15114 | ||
d03285ec UW |
15115 | /* Delete software single step breakpoints without removing them from |
15116 | the inferior. This is intended to be used if the inferior's address | |
15117 | space where they were inserted is already gone, e.g. after exit or | |
15118 | exec. */ | |
15119 | ||
15120 | void | |
15121 | cancel_single_step_breakpoints (void) | |
15122 | { | |
15123 | int i; | |
15124 | ||
15125 | for (i = 0; i < 2; i++) | |
15126 | if (single_step_breakpoints[i]) | |
15127 | { | |
15128 | xfree (single_step_breakpoints[i]); | |
15129 | single_step_breakpoints[i] = NULL; | |
15130 | single_step_gdbarch[i] = NULL; | |
15131 | } | |
15132 | } | |
15133 | ||
15134 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15135 | removing them. */ | |
15136 | ||
15137 | static void | |
15138 | detach_single_step_breakpoints (void) | |
15139 | { | |
15140 | int i; | |
15141 | ||
15142 | for (i = 0; i < 2; i++) | |
15143 | if (single_step_breakpoints[i]) | |
15144 | target_remove_breakpoint (single_step_gdbarch[i], | |
15145 | single_step_breakpoints[i]); | |
15146 | } | |
15147 | ||
4a64f543 MS |
15148 | /* Check whether a software single-step breakpoint is inserted at |
15149 | PC. */ | |
1aafd4da UW |
15150 | |
15151 | static int | |
cc59ec59 MS |
15152 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
15153 | CORE_ADDR pc) | |
1aafd4da UW |
15154 | { |
15155 | int i; | |
15156 | ||
15157 | for (i = 0; i < 2; i++) | |
15158 | { | |
15159 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15160 | if (bp_tgt |
15161 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
15162 | bp_tgt->placed_address, | |
15163 | aspace, pc)) | |
1aafd4da UW |
15164 | return 1; |
15165 | } | |
15166 | ||
15167 | return 0; | |
15168 | } | |
15169 | ||
a96d9b2e SDJ |
15170 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15171 | non-zero otherwise. */ | |
15172 | static int | |
15173 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15174 | { | |
15175 | if (syscall_catchpoint_p (bp) | |
15176 | && bp->enable_state != bp_disabled | |
15177 | && bp->enable_state != bp_call_disabled) | |
15178 | return 1; | |
15179 | else | |
15180 | return 0; | |
15181 | } | |
15182 | ||
15183 | int | |
15184 | catch_syscall_enabled (void) | |
15185 | { | |
fa3064dd YQ |
15186 | struct catch_syscall_inferior_data *inf_data |
15187 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15188 | |
fa3064dd | 15189 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15190 | } |
15191 | ||
15192 | int | |
15193 | catching_syscall_number (int syscall_number) | |
15194 | { | |
15195 | struct breakpoint *bp; | |
15196 | ||
15197 | ALL_BREAKPOINTS (bp) | |
15198 | if (is_syscall_catchpoint_enabled (bp)) | |
15199 | { | |
be5c67c1 PA |
15200 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15201 | ||
15202 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15203 | { |
15204 | int i, iter; | |
15205 | for (i = 0; | |
be5c67c1 | 15206 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15207 | i++) |
15208 | if (syscall_number == iter) | |
15209 | return 1; | |
15210 | } | |
15211 | else | |
15212 | return 1; | |
15213 | } | |
15214 | ||
15215 | return 0; | |
15216 | } | |
15217 | ||
15218 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15219 | static VEC (char_ptr) * |
a96d9b2e | 15220 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15221 | const char *text, const char *word) |
a96d9b2e SDJ |
15222 | { |
15223 | const char **list = get_syscall_names (); | |
49c4e619 | 15224 | VEC (char_ptr) *retlist |
b45627a0 | 15225 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15226 | |
c38eea1a MS |
15227 | xfree (list); |
15228 | return retlist; | |
a96d9b2e SDJ |
15229 | } |
15230 | ||
1042e4c0 SS |
15231 | /* Tracepoint-specific operations. */ |
15232 | ||
15233 | /* Set tracepoint count to NUM. */ | |
15234 | static void | |
15235 | set_tracepoint_count (int num) | |
15236 | { | |
15237 | tracepoint_count = num; | |
4fa62494 | 15238 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15239 | } |
15240 | ||
70221824 | 15241 | static void |
1042e4c0 SS |
15242 | trace_command (char *arg, int from_tty) |
15243 | { | |
55aa24fb SDJ |
15244 | struct breakpoint_ops *ops; |
15245 | const char *arg_cp = arg; | |
15246 | ||
15247 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15248 | ops = &tracepoint_probe_breakpoint_ops; | |
15249 | else | |
15250 | ops = &tracepoint_breakpoint_ops; | |
15251 | ||
558a9d82 YQ |
15252 | create_breakpoint (get_current_arch (), |
15253 | arg, | |
15254 | NULL, 0, NULL, 1 /* parse arg */, | |
15255 | 0 /* tempflag */, | |
15256 | bp_tracepoint /* type_wanted */, | |
15257 | 0 /* Ignore count */, | |
15258 | pending_break_support, | |
15259 | ops, | |
15260 | from_tty, | |
15261 | 1 /* enabled */, | |
15262 | 0 /* internal */, 0); | |
1042e4c0 SS |
15263 | } |
15264 | ||
70221824 | 15265 | static void |
7a697b8d SS |
15266 | ftrace_command (char *arg, int from_tty) |
15267 | { | |
558a9d82 YQ |
15268 | create_breakpoint (get_current_arch (), |
15269 | arg, | |
15270 | NULL, 0, NULL, 1 /* parse arg */, | |
15271 | 0 /* tempflag */, | |
15272 | bp_fast_tracepoint /* type_wanted */, | |
15273 | 0 /* Ignore count */, | |
15274 | pending_break_support, | |
15275 | &tracepoint_breakpoint_ops, | |
15276 | from_tty, | |
15277 | 1 /* enabled */, | |
15278 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15279 | } |
15280 | ||
15281 | /* strace command implementation. Creates a static tracepoint. */ | |
15282 | ||
70221824 | 15283 | static void |
0fb4aa4b PA |
15284 | strace_command (char *arg, int from_tty) |
15285 | { | |
983af33b SDJ |
15286 | struct breakpoint_ops *ops; |
15287 | ||
15288 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15289 | or with a normal static tracepoint. */ | |
15290 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15291 | ops = &strace_marker_breakpoint_ops; | |
15292 | else | |
15293 | ops = &tracepoint_breakpoint_ops; | |
15294 | ||
558a9d82 YQ |
15295 | create_breakpoint (get_current_arch (), |
15296 | arg, | |
15297 | NULL, 0, NULL, 1 /* parse arg */, | |
15298 | 0 /* tempflag */, | |
15299 | bp_static_tracepoint /* type_wanted */, | |
15300 | 0 /* Ignore count */, | |
15301 | pending_break_support, | |
15302 | ops, | |
15303 | from_tty, | |
15304 | 1 /* enabled */, | |
15305 | 0 /* internal */, 0); | |
7a697b8d SS |
15306 | } |
15307 | ||
409873ef SS |
15308 | /* Set up a fake reader function that gets command lines from a linked |
15309 | list that was acquired during tracepoint uploading. */ | |
15310 | ||
15311 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15312 | static int next_cmd; |
409873ef SS |
15313 | |
15314 | static char * | |
15315 | read_uploaded_action (void) | |
15316 | { | |
15317 | char *rslt; | |
15318 | ||
3149d8c1 | 15319 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15320 | |
3149d8c1 | 15321 | next_cmd++; |
409873ef SS |
15322 | |
15323 | return rslt; | |
15324 | } | |
15325 | ||
00bf0b85 SS |
15326 | /* Given information about a tracepoint as recorded on a target (which |
15327 | can be either a live system or a trace file), attempt to create an | |
15328 | equivalent GDB tracepoint. This is not a reliable process, since | |
15329 | the target does not necessarily have all the information used when | |
15330 | the tracepoint was originally defined. */ | |
15331 | ||
d9b3f62e | 15332 | struct tracepoint * |
00bf0b85 | 15333 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15334 | { |
409873ef | 15335 | char *addr_str, small_buf[100]; |
d9b3f62e | 15336 | struct tracepoint *tp; |
fd9b8c24 | 15337 | |
409873ef SS |
15338 | if (utp->at_string) |
15339 | addr_str = utp->at_string; | |
15340 | else | |
15341 | { | |
15342 | /* In the absence of a source location, fall back to raw | |
15343 | address. Since there is no way to confirm that the address | |
15344 | means the same thing as when the trace was started, warn the | |
15345 | user. */ | |
3e43a32a MS |
15346 | warning (_("Uploaded tracepoint %d has no " |
15347 | "source location, using raw address"), | |
409873ef | 15348 | utp->number); |
8c042590 | 15349 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15350 | addr_str = small_buf; |
15351 | } | |
15352 | ||
15353 | /* There's not much we can do with a sequence of bytecodes. */ | |
15354 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15355 | warning (_("Uploaded tracepoint %d condition " |
15356 | "has no source form, ignoring it"), | |
409873ef | 15357 | utp->number); |
d5551862 | 15358 | |
8cdf0e15 | 15359 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15360 | addr_str, |
e7e0cddf SS |
15361 | utp->cond_string, -1, NULL, |
15362 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15363 | 0 /* tempflag */, |
0fb4aa4b | 15364 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15365 | 0 /* Ignore count */, |
15366 | pending_break_support, | |
348d480f | 15367 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15368 | 0 /* from_tty */, |
84f4c1fe | 15369 | utp->enabled /* enabled */, |
44f238bb PA |
15370 | 0 /* internal */, |
15371 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15372 | return NULL; |
15373 | ||
409873ef | 15374 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15375 | tp = get_tracepoint (tracepoint_count); |
15376 | gdb_assert (tp != NULL); | |
d5551862 | 15377 | |
00bf0b85 SS |
15378 | if (utp->pass > 0) |
15379 | { | |
8c042590 PM |
15380 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15381 | tp->base.number); | |
00bf0b85 | 15382 | |
409873ef | 15383 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15384 | } |
15385 | ||
409873ef SS |
15386 | /* If we have uploaded versions of the original commands, set up a |
15387 | special-purpose "reader" function and call the usual command line | |
15388 | reader, then pass the result to the breakpoint command-setting | |
15389 | function. */ | |
3149d8c1 | 15390 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15391 | { |
409873ef | 15392 | struct command_line *cmd_list; |
00bf0b85 | 15393 | |
409873ef | 15394 | this_utp = utp; |
3149d8c1 | 15395 | next_cmd = 0; |
d5551862 | 15396 | |
409873ef SS |
15397 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15398 | ||
d9b3f62e | 15399 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15400 | } |
3149d8c1 SS |
15401 | else if (!VEC_empty (char_ptr, utp->actions) |
15402 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15403 | warning (_("Uploaded tracepoint %d actions " |
15404 | "have no source form, ignoring them"), | |
409873ef | 15405 | utp->number); |
00bf0b85 | 15406 | |
f196051f SS |
15407 | /* Copy any status information that might be available. */ |
15408 | tp->base.hit_count = utp->hit_count; | |
15409 | tp->traceframe_usage = utp->traceframe_usage; | |
15410 | ||
00bf0b85 | 15411 | return tp; |
d9b3f62e | 15412 | } |
00bf0b85 | 15413 | |
1042e4c0 SS |
15414 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15415 | omitted. */ | |
15416 | ||
15417 | static void | |
e5a67952 | 15418 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15419 | { |
79a45e25 | 15420 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15421 | int num_printed; |
1042e4c0 | 15422 | |
e5a67952 | 15423 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15424 | |
15425 | if (num_printed == 0) | |
1042e4c0 | 15426 | { |
e5a67952 | 15427 | if (args == NULL || *args == '\0') |
d77f58be SS |
15428 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15429 | else | |
e5a67952 | 15430 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15431 | } |
ad443146 SS |
15432 | |
15433 | default_collect_info (); | |
1042e4c0 SS |
15434 | } |
15435 | ||
4a64f543 | 15436 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15437 | Not supported by all targets. */ |
15438 | static void | |
15439 | enable_trace_command (char *args, int from_tty) | |
15440 | { | |
15441 | enable_command (args, from_tty); | |
15442 | } | |
15443 | ||
4a64f543 | 15444 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15445 | Not supported by all targets. */ |
15446 | static void | |
15447 | disable_trace_command (char *args, int from_tty) | |
15448 | { | |
15449 | disable_command (args, from_tty); | |
15450 | } | |
15451 | ||
4a64f543 | 15452 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15453 | static void |
15454 | delete_trace_command (char *arg, int from_tty) | |
15455 | { | |
35df4500 | 15456 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15457 | |
15458 | dont_repeat (); | |
15459 | ||
15460 | if (arg == 0) | |
15461 | { | |
15462 | int breaks_to_delete = 0; | |
15463 | ||
15464 | /* Delete all breakpoints if no argument. | |
15465 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15466 | have to be deleted with an explicit breakpoint number |
15467 | argument. */ | |
1042e4c0 | 15468 | ALL_TRACEPOINTS (b) |
46c6471b | 15469 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15470 | { |
15471 | breaks_to_delete = 1; | |
15472 | break; | |
15473 | } | |
1042e4c0 SS |
15474 | |
15475 | /* Ask user only if there are some breakpoints to delete. */ | |
15476 | if (!from_tty | |
15477 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15478 | { | |
35df4500 | 15479 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15480 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15481 | delete_breakpoint (b); |
1042e4c0 SS |
15482 | } |
15483 | } | |
15484 | else | |
51be5b68 | 15485 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15486 | } |
15487 | ||
197f0a60 TT |
15488 | /* Helper function for trace_pass_command. */ |
15489 | ||
15490 | static void | |
d9b3f62e | 15491 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15492 | { |
d9b3f62e | 15493 | tp->pass_count = count; |
6f6484cd | 15494 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15495 | if (from_tty) |
15496 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15497 | tp->base.number, count); |
197f0a60 TT |
15498 | } |
15499 | ||
1042e4c0 SS |
15500 | /* Set passcount for tracepoint. |
15501 | ||
15502 | First command argument is passcount, second is tracepoint number. | |
15503 | If tracepoint number omitted, apply to most recently defined. | |
15504 | Also accepts special argument "all". */ | |
15505 | ||
15506 | static void | |
15507 | trace_pass_command (char *args, int from_tty) | |
15508 | { | |
d9b3f62e | 15509 | struct tracepoint *t1; |
1042e4c0 | 15510 | unsigned int count; |
1042e4c0 SS |
15511 | |
15512 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15513 | error (_("passcount command requires an " |
15514 | "argument (count + optional TP num)")); | |
1042e4c0 | 15515 | |
4a64f543 | 15516 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15517 | |
529480d0 | 15518 | args = skip_spaces (args); |
1042e4c0 SS |
15519 | if (*args && strncasecmp (args, "all", 3) == 0) |
15520 | { | |
d9b3f62e PA |
15521 | struct breakpoint *b; |
15522 | ||
1042e4c0 | 15523 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15524 | if (*args) |
15525 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15526 | |
d9b3f62e | 15527 | ALL_TRACEPOINTS (b) |
197f0a60 | 15528 | { |
d9b3f62e | 15529 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15530 | trace_pass_set_count (t1, count, from_tty); |
15531 | } | |
15532 | } | |
15533 | else if (*args == '\0') | |
1042e4c0 | 15534 | { |
5fa1d40e | 15535 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15536 | if (t1) |
197f0a60 TT |
15537 | trace_pass_set_count (t1, count, from_tty); |
15538 | } | |
15539 | else | |
15540 | { | |
15541 | struct get_number_or_range_state state; | |
15542 | ||
15543 | init_number_or_range (&state, args); | |
15544 | while (!state.finished) | |
1042e4c0 | 15545 | { |
5fa1d40e | 15546 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15547 | if (t1) |
15548 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15549 | } |
15550 | } | |
1042e4c0 SS |
15551 | } |
15552 | ||
d9b3f62e | 15553 | struct tracepoint * |
1042e4c0 SS |
15554 | get_tracepoint (int num) |
15555 | { | |
15556 | struct breakpoint *t; | |
15557 | ||
15558 | ALL_TRACEPOINTS (t) | |
15559 | if (t->number == num) | |
d9b3f62e | 15560 | return (struct tracepoint *) t; |
1042e4c0 SS |
15561 | |
15562 | return NULL; | |
15563 | } | |
15564 | ||
d5551862 SS |
15565 | /* Find the tracepoint with the given target-side number (which may be |
15566 | different from the tracepoint number after disconnecting and | |
15567 | reconnecting). */ | |
15568 | ||
d9b3f62e | 15569 | struct tracepoint * |
d5551862 SS |
15570 | get_tracepoint_by_number_on_target (int num) |
15571 | { | |
d9b3f62e | 15572 | struct breakpoint *b; |
d5551862 | 15573 | |
d9b3f62e PA |
15574 | ALL_TRACEPOINTS (b) |
15575 | { | |
15576 | struct tracepoint *t = (struct tracepoint *) b; | |
15577 | ||
15578 | if (t->number_on_target == num) | |
15579 | return t; | |
15580 | } | |
d5551862 SS |
15581 | |
15582 | return NULL; | |
15583 | } | |
15584 | ||
1042e4c0 | 15585 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15586 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15587 | If the argument is missing, the most recent tracepoint |
15588 | (tracepoint_count) is returned. */ | |
15589 | ||
d9b3f62e | 15590 | struct tracepoint * |
197f0a60 | 15591 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15592 | struct get_number_or_range_state *state) |
1042e4c0 | 15593 | { |
1042e4c0 SS |
15594 | struct breakpoint *t; |
15595 | int tpnum; | |
15596 | char *instring = arg == NULL ? NULL : *arg; | |
15597 | ||
197f0a60 TT |
15598 | if (state) |
15599 | { | |
15600 | gdb_assert (!state->finished); | |
15601 | tpnum = get_number_or_range (state); | |
15602 | } | |
15603 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15604 | tpnum = tracepoint_count; |
1042e4c0 | 15605 | else |
197f0a60 | 15606 | tpnum = get_number (arg); |
1042e4c0 SS |
15607 | |
15608 | if (tpnum <= 0) | |
15609 | { | |
15610 | if (instring && *instring) | |
15611 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15612 | instring); | |
15613 | else | |
5fa1d40e | 15614 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15615 | return NULL; |
15616 | } | |
15617 | ||
15618 | ALL_TRACEPOINTS (t) | |
15619 | if (t->number == tpnum) | |
15620 | { | |
d9b3f62e | 15621 | return (struct tracepoint *) t; |
1042e4c0 SS |
15622 | } |
15623 | ||
1042e4c0 SS |
15624 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15625 | return NULL; | |
15626 | } | |
15627 | ||
d9b3f62e PA |
15628 | void |
15629 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15630 | { | |
15631 | if (b->thread != -1) | |
15632 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15633 | ||
15634 | if (b->task != 0) | |
15635 | fprintf_unfiltered (fp, " task %d", b->task); | |
15636 | ||
15637 | fprintf_unfiltered (fp, "\n"); | |
15638 | } | |
15639 | ||
6149aea9 PA |
15640 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15641 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15642 | on each breakpoint and only include the ones for which it returns | |
15643 | non-zero. */ | |
15644 | ||
1042e4c0 | 15645 | static void |
6149aea9 PA |
15646 | save_breakpoints (char *filename, int from_tty, |
15647 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15648 | { |
15649 | struct breakpoint *tp; | |
6149aea9 | 15650 | int any = 0; |
1042e4c0 | 15651 | struct cleanup *cleanup; |
a7bdde9e | 15652 | struct ui_file *fp; |
6149aea9 | 15653 | int extra_trace_bits = 0; |
1042e4c0 | 15654 | |
6149aea9 PA |
15655 | if (filename == 0 || *filename == 0) |
15656 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15657 | |
15658 | /* See if we have anything to save. */ | |
6149aea9 | 15659 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15660 | { |
6149aea9 | 15661 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15662 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15663 | continue; |
15664 | ||
15665 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15666 | if (filter && !filter (tp)) | |
15667 | continue; | |
15668 | ||
15669 | any = 1; | |
15670 | ||
15671 | if (is_tracepoint (tp)) | |
15672 | { | |
15673 | extra_trace_bits = 1; | |
15674 | ||
15675 | /* We can stop searching. */ | |
15676 | break; | |
15677 | } | |
1042e4c0 | 15678 | } |
6149aea9 PA |
15679 | |
15680 | if (!any) | |
1042e4c0 | 15681 | { |
6149aea9 | 15682 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15683 | return; |
15684 | } | |
15685 | ||
c718be47 PA |
15686 | filename = tilde_expand (filename); |
15687 | cleanup = make_cleanup (xfree, filename); | |
15688 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15689 | if (!fp) |
6149aea9 PA |
15690 | error (_("Unable to open file '%s' for saving (%s)"), |
15691 | filename, safe_strerror (errno)); | |
a7bdde9e | 15692 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15693 | |
6149aea9 PA |
15694 | if (extra_trace_bits) |
15695 | save_trace_state_variables (fp); | |
8bf6485c | 15696 | |
6149aea9 | 15697 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15698 | { |
6149aea9 | 15699 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15700 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15701 | continue; |
8bf6485c | 15702 | |
6149aea9 PA |
15703 | /* If we have a filter, only save the breakpoints it accepts. */ |
15704 | if (filter && !filter (tp)) | |
15705 | continue; | |
15706 | ||
348d480f | 15707 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15708 | |
6149aea9 PA |
15709 | /* Note, we can't rely on tp->number for anything, as we can't |
15710 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15711 | instead. */ | |
15712 | ||
15713 | if (tp->cond_string) | |
15714 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15715 | ||
15716 | if (tp->ignore_count) | |
15717 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15718 | ||
2d9442cc | 15719 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15720 | { |
a7bdde9e VP |
15721 | volatile struct gdb_exception ex; |
15722 | ||
6149aea9 | 15723 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15724 | |
79a45e25 | 15725 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15726 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15727 | { |
79a45e25 | 15728 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15729 | } |
79a45e25 | 15730 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15731 | |
a7bdde9e VP |
15732 | if (ex.reason < 0) |
15733 | throw_exception (ex); | |
1042e4c0 | 15734 | |
a7bdde9e | 15735 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15736 | } |
6149aea9 PA |
15737 | |
15738 | if (tp->enable_state == bp_disabled) | |
15739 | fprintf_unfiltered (fp, "disable\n"); | |
15740 | ||
15741 | /* If this is a multi-location breakpoint, check if the locations | |
15742 | should be individually disabled. Watchpoint locations are | |
15743 | special, and not user visible. */ | |
15744 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15745 | { | |
15746 | struct bp_location *loc; | |
15747 | int n = 1; | |
15748 | ||
15749 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15750 | if (!loc->enabled) | |
15751 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15752 | } | |
1042e4c0 | 15753 | } |
8bf6485c | 15754 | |
6149aea9 | 15755 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15756 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15757 | ||
1042e4c0 | 15758 | if (from_tty) |
6149aea9 | 15759 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15760 | do_cleanups (cleanup); |
6149aea9 PA |
15761 | } |
15762 | ||
15763 | /* The `save breakpoints' command. */ | |
15764 | ||
15765 | static void | |
15766 | save_breakpoints_command (char *args, int from_tty) | |
15767 | { | |
15768 | save_breakpoints (args, from_tty, NULL); | |
15769 | } | |
15770 | ||
15771 | /* The `save tracepoints' command. */ | |
15772 | ||
15773 | static void | |
15774 | save_tracepoints_command (char *args, int from_tty) | |
15775 | { | |
15776 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15777 | } |
15778 | ||
15779 | /* Create a vector of all tracepoints. */ | |
15780 | ||
15781 | VEC(breakpoint_p) * | |
eeae04df | 15782 | all_tracepoints (void) |
1042e4c0 SS |
15783 | { |
15784 | VEC(breakpoint_p) *tp_vec = 0; | |
15785 | struct breakpoint *tp; | |
15786 | ||
15787 | ALL_TRACEPOINTS (tp) | |
15788 | { | |
15789 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15790 | } | |
15791 | ||
15792 | return tp_vec; | |
15793 | } | |
15794 | ||
c906108c | 15795 | \f |
4a64f543 MS |
15796 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15797 | commands. It is defined as a macro to prevent duplication. | |
15798 | COMMAND should be a string constant containing the name of the | |
15799 | command. */ | |
31e2b00f | 15800 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15801 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15802 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15803 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15804 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15805 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15806 | If a line number is specified, break at start of code for that line.\n\ | |
15807 | If a function is specified, break at start of code for that function.\n\ | |
15808 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15809 | With no LOCATION, uses current execution address of the selected\n\ |
15810 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15811 | \n\ |
15812 | THREADNUM is the number from \"info threads\".\n\ | |
15813 | CONDITION is a boolean expression.\n\ | |
15814 | \n\ | |
d41c0fc8 PA |
15815 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15816 | conditions are different.\n\ | |
31e2b00f AS |
15817 | \n\ |
15818 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15819 | ||
44feb3ce TT |
15820 | /* List of subcommands for "catch". */ |
15821 | static struct cmd_list_element *catch_cmdlist; | |
15822 | ||
15823 | /* List of subcommands for "tcatch". */ | |
15824 | static struct cmd_list_element *tcatch_cmdlist; | |
15825 | ||
9ac4176b | 15826 | void |
44feb3ce TT |
15827 | add_catch_command (char *name, char *docstring, |
15828 | void (*sfunc) (char *args, int from_tty, | |
15829 | struct cmd_list_element *command), | |
625e8578 | 15830 | completer_ftype *completer, |
44feb3ce TT |
15831 | void *user_data_catch, |
15832 | void *user_data_tcatch) | |
15833 | { | |
15834 | struct cmd_list_element *command; | |
15835 | ||
15836 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15837 | &catch_cmdlist); | |
15838 | set_cmd_sfunc (command, sfunc); | |
15839 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15840 | set_cmd_completer (command, completer); |
44feb3ce TT |
15841 | |
15842 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15843 | &tcatch_cmdlist); | |
15844 | set_cmd_sfunc (command, sfunc); | |
15845 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15846 | set_cmd_completer (command, completer); |
44feb3ce TT |
15847 | } |
15848 | ||
6c95b8df | 15849 | static void |
a79b8f6e | 15850 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15851 | { |
fa3064dd YQ |
15852 | struct catch_syscall_inferior_data *inf_data |
15853 | = get_catch_syscall_inferior_data (inf); | |
15854 | ||
15855 | inf_data->total_syscalls_count = 0; | |
15856 | inf_data->any_syscall_count = 0; | |
15857 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15858 | } |
15859 | ||
6149aea9 PA |
15860 | static void |
15861 | save_command (char *arg, int from_tty) | |
15862 | { | |
3e43a32a MS |
15863 | printf_unfiltered (_("\"save\" must be followed by " |
15864 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
15865 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
15866 | } | |
15867 | ||
84f4c1fe PM |
15868 | struct breakpoint * |
15869 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15870 | void *data) | |
15871 | { | |
35df4500 | 15872 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15873 | |
35df4500 | 15874 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15875 | { |
15876 | if ((*callback) (b, data)) | |
15877 | return b; | |
15878 | } | |
15879 | ||
15880 | return NULL; | |
15881 | } | |
15882 | ||
0574c78f GB |
15883 | /* Zero if any of the breakpoint's locations could be a location where |
15884 | functions have been inlined, nonzero otherwise. */ | |
15885 | ||
15886 | static int | |
15887 | is_non_inline_function (struct breakpoint *b) | |
15888 | { | |
15889 | /* The shared library event breakpoint is set on the address of a | |
15890 | non-inline function. */ | |
15891 | if (b->type == bp_shlib_event) | |
15892 | return 1; | |
15893 | ||
15894 | return 0; | |
15895 | } | |
15896 | ||
15897 | /* Nonzero if the specified PC cannot be a location where functions | |
15898 | have been inlined. */ | |
15899 | ||
15900 | int | |
09ac7c10 TT |
15901 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15902 | const struct target_waitstatus *ws) | |
0574c78f GB |
15903 | { |
15904 | struct breakpoint *b; | |
15905 | struct bp_location *bl; | |
15906 | ||
15907 | ALL_BREAKPOINTS (b) | |
15908 | { | |
15909 | if (!is_non_inline_function (b)) | |
15910 | continue; | |
15911 | ||
15912 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15913 | { | |
15914 | if (!bl->shlib_disabled | |
09ac7c10 | 15915 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15916 | return 1; |
15917 | } | |
15918 | } | |
15919 | ||
15920 | return 0; | |
15921 | } | |
15922 | ||
2f202fde JK |
15923 | /* Remove any references to OBJFILE which is going to be freed. */ |
15924 | ||
15925 | void | |
15926 | breakpoint_free_objfile (struct objfile *objfile) | |
15927 | { | |
15928 | struct bp_location **locp, *loc; | |
15929 | ||
15930 | ALL_BP_LOCATIONS (loc, locp) | |
15931 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
15932 | loc->symtab = NULL; | |
15933 | } | |
15934 | ||
2060206e PA |
15935 | void |
15936 | initialize_breakpoint_ops (void) | |
15937 | { | |
15938 | static int initialized = 0; | |
15939 | ||
15940 | struct breakpoint_ops *ops; | |
15941 | ||
15942 | if (initialized) | |
15943 | return; | |
15944 | initialized = 1; | |
15945 | ||
15946 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15947 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15948 | internal and momentary breakpoints, etc.). */ | |
15949 | ops = &bkpt_base_breakpoint_ops; | |
15950 | *ops = base_breakpoint_ops; | |
15951 | ops->re_set = bkpt_re_set; | |
15952 | ops->insert_location = bkpt_insert_location; | |
15953 | ops->remove_location = bkpt_remove_location; | |
15954 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15955 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15956 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15957 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15958 | |
15959 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15960 | ops = &bkpt_breakpoint_ops; | |
15961 | *ops = bkpt_base_breakpoint_ops; | |
15962 | ops->re_set = bkpt_re_set; | |
15963 | ops->resources_needed = bkpt_resources_needed; | |
15964 | ops->print_it = bkpt_print_it; | |
15965 | ops->print_mention = bkpt_print_mention; | |
15966 | ops->print_recreate = bkpt_print_recreate; | |
15967 | ||
15968 | /* Ranged breakpoints. */ | |
15969 | ops = &ranged_breakpoint_ops; | |
15970 | *ops = bkpt_breakpoint_ops; | |
15971 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15972 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15973 | ops->print_it = print_it_ranged_breakpoint; | |
15974 | ops->print_one = print_one_ranged_breakpoint; | |
15975 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15976 | ops->print_mention = print_mention_ranged_breakpoint; | |
15977 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15978 | ||
15979 | /* Internal breakpoints. */ | |
15980 | ops = &internal_breakpoint_ops; | |
15981 | *ops = bkpt_base_breakpoint_ops; | |
15982 | ops->re_set = internal_bkpt_re_set; | |
15983 | ops->check_status = internal_bkpt_check_status; | |
15984 | ops->print_it = internal_bkpt_print_it; | |
15985 | ops->print_mention = internal_bkpt_print_mention; | |
15986 | ||
15987 | /* Momentary breakpoints. */ | |
15988 | ops = &momentary_breakpoint_ops; | |
15989 | *ops = bkpt_base_breakpoint_ops; | |
15990 | ops->re_set = momentary_bkpt_re_set; | |
15991 | ops->check_status = momentary_bkpt_check_status; | |
15992 | ops->print_it = momentary_bkpt_print_it; | |
15993 | ops->print_mention = momentary_bkpt_print_mention; | |
15994 | ||
e2e4d78b JK |
15995 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15996 | ops = &longjmp_breakpoint_ops; | |
15997 | *ops = momentary_breakpoint_ops; | |
15998 | ops->dtor = longjmp_bkpt_dtor; | |
15999 | ||
55aa24fb SDJ |
16000 | /* Probe breakpoints. */ |
16001 | ops = &bkpt_probe_breakpoint_ops; | |
16002 | *ops = bkpt_breakpoint_ops; | |
16003 | ops->insert_location = bkpt_probe_insert_location; | |
16004 | ops->remove_location = bkpt_probe_remove_location; | |
16005 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16006 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16007 | ||
2060206e PA |
16008 | /* Watchpoints. */ |
16009 | ops = &watchpoint_breakpoint_ops; | |
16010 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16011 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16012 | ops->re_set = re_set_watchpoint; |
16013 | ops->insert_location = insert_watchpoint; | |
16014 | ops->remove_location = remove_watchpoint; | |
16015 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16016 | ops->check_status = check_status_watchpoint; | |
16017 | ops->resources_needed = resources_needed_watchpoint; | |
16018 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16019 | ops->print_it = print_it_watchpoint; | |
16020 | ops->print_mention = print_mention_watchpoint; | |
16021 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16022 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16023 | |
16024 | /* Masked watchpoints. */ | |
16025 | ops = &masked_watchpoint_breakpoint_ops; | |
16026 | *ops = watchpoint_breakpoint_ops; | |
16027 | ops->insert_location = insert_masked_watchpoint; | |
16028 | ops->remove_location = remove_masked_watchpoint; | |
16029 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16030 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16031 | ops->print_it = print_it_masked_watchpoint; | |
16032 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16033 | ops->print_mention = print_mention_masked_watchpoint; | |
16034 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16035 | ||
16036 | /* Tracepoints. */ | |
16037 | ops = &tracepoint_breakpoint_ops; | |
16038 | *ops = base_breakpoint_ops; | |
16039 | ops->re_set = tracepoint_re_set; | |
16040 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16041 | ops->print_one_detail = tracepoint_print_one_detail; | |
16042 | ops->print_mention = tracepoint_print_mention; | |
16043 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16044 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16045 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16046 | ops->decode_linespec = tracepoint_decode_linespec; | |
16047 | ||
55aa24fb SDJ |
16048 | /* Probe tracepoints. */ |
16049 | ops = &tracepoint_probe_breakpoint_ops; | |
16050 | *ops = tracepoint_breakpoint_ops; | |
16051 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16052 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16053 | ||
983af33b SDJ |
16054 | /* Static tracepoints with marker (`-m'). */ |
16055 | ops = &strace_marker_breakpoint_ops; | |
16056 | *ops = tracepoint_breakpoint_ops; | |
16057 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16058 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16059 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16060 | |
16061 | /* Fork catchpoints. */ | |
16062 | ops = &catch_fork_breakpoint_ops; | |
16063 | *ops = base_breakpoint_ops; | |
16064 | ops->insert_location = insert_catch_fork; | |
16065 | ops->remove_location = remove_catch_fork; | |
16066 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16067 | ops->print_it = print_it_catch_fork; | |
16068 | ops->print_one = print_one_catch_fork; | |
16069 | ops->print_mention = print_mention_catch_fork; | |
16070 | ops->print_recreate = print_recreate_catch_fork; | |
16071 | ||
16072 | /* Vfork catchpoints. */ | |
16073 | ops = &catch_vfork_breakpoint_ops; | |
16074 | *ops = base_breakpoint_ops; | |
16075 | ops->insert_location = insert_catch_vfork; | |
16076 | ops->remove_location = remove_catch_vfork; | |
16077 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16078 | ops->print_it = print_it_catch_vfork; | |
16079 | ops->print_one = print_one_catch_vfork; | |
16080 | ops->print_mention = print_mention_catch_vfork; | |
16081 | ops->print_recreate = print_recreate_catch_vfork; | |
16082 | ||
16083 | /* Exec catchpoints. */ | |
16084 | ops = &catch_exec_breakpoint_ops; | |
16085 | *ops = base_breakpoint_ops; | |
16086 | ops->dtor = dtor_catch_exec; | |
16087 | ops->insert_location = insert_catch_exec; | |
16088 | ops->remove_location = remove_catch_exec; | |
16089 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16090 | ops->print_it = print_it_catch_exec; | |
16091 | ops->print_one = print_one_catch_exec; | |
16092 | ops->print_mention = print_mention_catch_exec; | |
16093 | ops->print_recreate = print_recreate_catch_exec; | |
16094 | ||
16095 | /* Syscall catchpoints. */ | |
16096 | ops = &catch_syscall_breakpoint_ops; | |
16097 | *ops = base_breakpoint_ops; | |
16098 | ops->dtor = dtor_catch_syscall; | |
16099 | ops->insert_location = insert_catch_syscall; | |
16100 | ops->remove_location = remove_catch_syscall; | |
16101 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16102 | ops->print_it = print_it_catch_syscall; | |
16103 | ops->print_one = print_one_catch_syscall; | |
16104 | ops->print_mention = print_mention_catch_syscall; | |
16105 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16106 | |
16107 | /* Solib-related catchpoints. */ | |
16108 | ops = &catch_solib_breakpoint_ops; | |
16109 | *ops = base_breakpoint_ops; | |
16110 | ops->dtor = dtor_catch_solib; | |
16111 | ops->insert_location = insert_catch_solib; | |
16112 | ops->remove_location = remove_catch_solib; | |
16113 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16114 | ops->check_status = check_status_catch_solib; | |
16115 | ops->print_it = print_it_catch_solib; | |
16116 | ops->print_one = print_one_catch_solib; | |
16117 | ops->print_mention = print_mention_catch_solib; | |
16118 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16119 | |
16120 | ops = &dprintf_breakpoint_ops; | |
16121 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16122 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16123 | ops->resources_needed = bkpt_resources_needed; |
16124 | ops->print_it = bkpt_print_it; | |
16125 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16126 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16127 | ops->after_condition_true = dprintf_after_condition_true; |
2060206e PA |
16128 | } |
16129 | ||
8bfd80db YQ |
16130 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16131 | ||
16132 | static struct cmd_list_element *enablebreaklist = NULL; | |
16133 | ||
c906108c | 16134 | void |
fba45db2 | 16135 | _initialize_breakpoint (void) |
c906108c SS |
16136 | { |
16137 | struct cmd_list_element *c; | |
16138 | ||
2060206e PA |
16139 | initialize_breakpoint_ops (); |
16140 | ||
84acb35a | 16141 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16142 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16143 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16144 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16145 | |
55aa24fb SDJ |
16146 | breakpoint_objfile_key |
16147 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16148 | |
fa3064dd | 16149 | catch_syscall_inferior_data |
8e260fc0 TT |
16150 | = register_inferior_data_with_cleanup (NULL, |
16151 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16152 | |
c906108c SS |
16153 | breakpoint_chain = 0; |
16154 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16155 | before a breakpoint is set. */ | |
16156 | breakpoint_count = 0; | |
16157 | ||
1042e4c0 SS |
16158 | tracepoint_count = 0; |
16159 | ||
1bedd215 AC |
16160 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16161 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16162 | Usage is `ignore N COUNT'.")); | |
c906108c | 16163 | if (xdb_commands) |
c5aa993b | 16164 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16165 | |
1bedd215 AC |
16166 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16167 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16168 | Give breakpoint number as argument after \"commands\".\n\ |
16169 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16170 | The commands themselves follow starting on the next line.\n\ | |
16171 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16172 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16173 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16174 | |
d55637df | 16175 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16176 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16177 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16178 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16179 | set_cmd_completer (c, condition_completer); |
c906108c | 16180 | |
1bedd215 | 16181 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16182 | Set a temporary breakpoint.\n\ |
c906108c SS |
16183 | Like \"break\" except the breakpoint is only temporary,\n\ |
16184 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16185 | by using \"enable delete\" on the breakpoint number.\n\ |
16186 | \n" | |
16187 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16188 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16189 | |
1bedd215 | 16190 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16191 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16192 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16193 | some target hardware may not have this support.\n\ |
16194 | \n" | |
16195 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16196 | set_cmd_completer (c, location_completer); |
c906108c | 16197 | |
1bedd215 | 16198 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16199 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16200 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16201 | so it will be deleted when hit.\n\ |
16202 | \n" | |
16203 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16204 | set_cmd_completer (c, location_completer); |
c906108c | 16205 | |
1bedd215 AC |
16206 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16207 | Enable some breakpoints.\n\ | |
c906108c SS |
16208 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16209 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16210 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16211 | With a subcommand you can enable temporarily."), |
c906108c SS |
16212 | &enablelist, "enable ", 1, &cmdlist); |
16213 | if (xdb_commands) | |
1bedd215 AC |
16214 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16215 | Enable some breakpoints.\n\ | |
c906108c SS |
16216 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16217 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16218 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16219 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16220 | |
16221 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16222 | ||
84951ab5 | 16223 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16224 | Enable some breakpoints.\n\ |
c906108c SS |
16225 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16226 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16227 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16228 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16229 | |
1a966eab AC |
16230 | add_cmd ("once", no_class, enable_once_command, _("\ |
16231 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16232 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16233 | &enablebreaklist); |
16234 | ||
1a966eab AC |
16235 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16236 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16237 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16238 | &enablebreaklist); |
16239 | ||
816338b5 SS |
16240 | add_cmd ("count", no_class, enable_count_command, _("\ |
16241 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16242 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16243 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16244 | &enablebreaklist); | |
16245 | ||
1a966eab AC |
16246 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16247 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16248 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16249 | &enablelist); |
16250 | ||
1a966eab AC |
16251 | add_cmd ("once", no_class, enable_once_command, _("\ |
16252 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16253 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16254 | &enablelist); |
16255 | ||
16256 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16257 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16258 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16259 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16260 | &enablelist); |
16261 | ||
1bedd215 AC |
16262 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16263 | Disable some breakpoints.\n\ | |
c906108c SS |
16264 | Arguments are breakpoint numbers with spaces in between.\n\ |
16265 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16266 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16267 | &disablelist, "disable ", 1, &cmdlist); |
16268 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16269 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16270 | if (xdb_commands) | |
1bedd215 AC |
16271 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16272 | Disable some breakpoints.\n\ | |
c906108c SS |
16273 | Arguments are breakpoint numbers with spaces in between.\n\ |
16274 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16275 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16276 | |
1a966eab AC |
16277 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16278 | Disable some breakpoints.\n\ | |
c906108c SS |
16279 | Arguments are breakpoint numbers with spaces in between.\n\ |
16280 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16281 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16282 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16283 | &disablelist); |
16284 | ||
1bedd215 AC |
16285 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16286 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16287 | Arguments are breakpoint numbers with spaces in between.\n\ |
16288 | To delete all breakpoints, give no argument.\n\ | |
16289 | \n\ | |
16290 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16291 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16292 | &deletelist, "delete ", 1, &cmdlist); |
16293 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16294 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16295 | if (xdb_commands) |
1bedd215 AC |
16296 | add_com ("db", class_breakpoint, delete_command, _("\ |
16297 | Delete some breakpoints.\n\ | |
c906108c | 16298 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16299 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16300 | |
1a966eab AC |
16301 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16302 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16303 | Arguments are breakpoint numbers with spaces in between.\n\ |
16304 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16305 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16306 | &deletelist); |
16307 | ||
1bedd215 AC |
16308 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16309 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16310 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16311 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16312 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16313 | If an address is specified, breakpoints at that address are cleared.\n\ |
16314 | \n\ | |
16315 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16316 | is executing in.\n\ |
16317 | \n\ | |
1bedd215 | 16318 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16319 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16320 | |
1bedd215 | 16321 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16322 | Set breakpoint at specified line or function.\n" |
16323 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16324 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16325 | |
c906108c SS |
16326 | add_com_alias ("b", "break", class_run, 1); |
16327 | add_com_alias ("br", "break", class_run, 1); | |
16328 | add_com_alias ("bre", "break", class_run, 1); | |
16329 | add_com_alias ("brea", "break", class_run, 1); | |
16330 | ||
7681d515 PM |
16331 | if (xdb_commands) |
16332 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16333 | |
16334 | if (dbx_commands) | |
16335 | { | |
1bedd215 AC |
16336 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16337 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16338 | &stoplist, "stop ", 1, &cmdlist); |
16339 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16340 | _("Break in function or address."), &stoplist); |
c5aa993b | 16341 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16342 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16343 | add_com ("status", class_info, breakpoints_info, _("\ |
16344 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16345 | The \"Type\" column indicates one of:\n\ |
16346 | \tbreakpoint - normal breakpoint\n\ | |
16347 | \twatchpoint - watchpoint\n\ | |
16348 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16349 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16350 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16351 | address and file/line number respectively.\n\ |
16352 | \n\ | |
16353 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16354 | are set to the address of the last breakpoint listed unless the command\n\ |
16355 | is prefixed with \"server \".\n\n\ | |
c906108c | 16356 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16357 | breakpoint set.")); |
c906108c SS |
16358 | } |
16359 | ||
1bedd215 | 16360 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16361 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16362 | The \"Type\" column indicates one of:\n\ |
16363 | \tbreakpoint - normal breakpoint\n\ | |
16364 | \twatchpoint - watchpoint\n\ | |
16365 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16366 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16367 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16368 | address and file/line number respectively.\n\ |
16369 | \n\ | |
16370 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16371 | are set to the address of the last breakpoint listed unless the command\n\ |
16372 | is prefixed with \"server \".\n\n\ | |
c906108c | 16373 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16374 | breakpoint set.")); |
c906108c | 16375 | |
6b04bdb7 MS |
16376 | add_info_alias ("b", "breakpoints", 1); |
16377 | ||
c906108c | 16378 | if (xdb_commands) |
1bedd215 AC |
16379 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16380 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16381 | The \"Type\" column indicates one of:\n\ |
16382 | \tbreakpoint - normal breakpoint\n\ | |
16383 | \twatchpoint - watchpoint\n\ | |
16384 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16385 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16386 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16387 | address and file/line number respectively.\n\ |
16388 | \n\ | |
16389 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16390 | are set to the address of the last breakpoint listed unless the command\n\ |
16391 | is prefixed with \"server \".\n\n\ | |
c906108c | 16392 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16393 | breakpoint set.")); |
c906108c | 16394 | |
1a966eab AC |
16395 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16396 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16397 | The \"Type\" column indicates one of:\n\ |
16398 | \tbreakpoint - normal breakpoint\n\ | |
16399 | \twatchpoint - watchpoint\n\ | |
16400 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16401 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16402 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16403 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16404 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16405 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16406 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16407 | address and file/line number respectively.\n\ |
16408 | \n\ | |
16409 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16410 | are set to the address of the last breakpoint listed unless the command\n\ |
16411 | is prefixed with \"server \".\n\n\ | |
c906108c | 16412 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16413 | breakpoint set."), |
c906108c SS |
16414 | &maintenanceinfolist); |
16415 | ||
44feb3ce TT |
16416 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16417 | Set catchpoints to catch events."), | |
16418 | &catch_cmdlist, "catch ", | |
16419 | 0/*allow-unknown*/, &cmdlist); | |
16420 | ||
16421 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16422 | Set temporary catchpoints to catch events."), | |
16423 | &tcatch_cmdlist, "tcatch ", | |
16424 | 0/*allow-unknown*/, &cmdlist); | |
16425 | ||
44feb3ce TT |
16426 | add_catch_command ("fork", _("Catch calls to fork."), |
16427 | catch_fork_command_1, | |
a96d9b2e | 16428 | NULL, |
44feb3ce TT |
16429 | (void *) (uintptr_t) catch_fork_permanent, |
16430 | (void *) (uintptr_t) catch_fork_temporary); | |
16431 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16432 | catch_fork_command_1, | |
a96d9b2e | 16433 | NULL, |
44feb3ce TT |
16434 | (void *) (uintptr_t) catch_vfork_permanent, |
16435 | (void *) (uintptr_t) catch_vfork_temporary); | |
16436 | add_catch_command ("exec", _("Catch calls to exec."), | |
16437 | catch_exec_command_1, | |
a96d9b2e SDJ |
16438 | NULL, |
16439 | CATCH_PERMANENT, | |
16440 | CATCH_TEMPORARY); | |
edcc5120 TT |
16441 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16442 | Usage: catch load [REGEX]\n\ | |
16443 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16444 | catch_load_command_1, | |
16445 | NULL, | |
16446 | CATCH_PERMANENT, | |
16447 | CATCH_TEMPORARY); | |
16448 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16449 | Usage: catch unload [REGEX]\n\ | |
16450 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16451 | catch_unload_command_1, | |
16452 | NULL, | |
16453 | CATCH_PERMANENT, | |
16454 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16455 | add_catch_command ("syscall", _("\ |
16456 | Catch system calls by their names and/or numbers.\n\ | |
16457 | Arguments say which system calls to catch. If no arguments\n\ | |
16458 | are given, every system call will be caught.\n\ | |
16459 | Arguments, if given, should be one or more system call names\n\ | |
16460 | (if your system supports that), or system call numbers."), | |
16461 | catch_syscall_command_1, | |
16462 | catch_syscall_completer, | |
44feb3ce TT |
16463 | CATCH_PERMANENT, |
16464 | CATCH_TEMPORARY); | |
c5aa993b | 16465 | |
1bedd215 AC |
16466 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16467 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16468 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16469 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16470 | an expression changes.\n\ |
16471 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16472 | the memory to which it refers.")); | |
65d12d83 | 16473 | set_cmd_completer (c, expression_completer); |
c906108c | 16474 | |
1bedd215 AC |
16475 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16476 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16477 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16478 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16479 | an expression is read.\n\ |
16480 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16481 | the memory to which it refers.")); | |
65d12d83 | 16482 | set_cmd_completer (c, expression_completer); |
c906108c | 16483 | |
1bedd215 AC |
16484 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16485 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16486 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16487 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16488 | an expression is either read or written.\n\ |
16489 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16490 | the memory to which it refers.")); | |
65d12d83 | 16491 | set_cmd_completer (c, expression_completer); |
c906108c | 16492 | |
d77f58be | 16493 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16494 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16495 | |
920d2a44 AC |
16496 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16497 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16498 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16499 | &can_use_hw_watchpoints, _("\ | |
16500 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16501 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16502 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16503 | such is available. (However, any hardware watchpoints that were\n\ | |
16504 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16505 | hardware.)"), |
16506 | NULL, | |
920d2a44 | 16507 | show_can_use_hw_watchpoints, |
85c07804 | 16508 | &setlist, &showlist); |
c906108c SS |
16509 | |
16510 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16511 | |
1042e4c0 SS |
16512 | /* Tracepoint manipulation commands. */ |
16513 | ||
16514 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16515 | Set a tracepoint at specified line or function.\n\ | |
16516 | \n" | |
16517 | BREAK_ARGS_HELP ("trace") "\n\ | |
16518 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16519 | set_cmd_completer (c, location_completer); | |
16520 | ||
16521 | add_com_alias ("tp", "trace", class_alias, 0); | |
16522 | add_com_alias ("tr", "trace", class_alias, 1); | |
16523 | add_com_alias ("tra", "trace", class_alias, 1); | |
16524 | add_com_alias ("trac", "trace", class_alias, 1); | |
16525 | ||
7a697b8d SS |
16526 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16527 | Set a fast tracepoint at specified line or function.\n\ | |
16528 | \n" | |
16529 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16530 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16531 | set_cmd_completer (c, location_completer); | |
16532 | ||
0fb4aa4b PA |
16533 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16534 | Set a static tracepoint at specified line, function or marker.\n\ | |
16535 | \n\ | |
16536 | strace [LOCATION] [if CONDITION]\n\ | |
16537 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16538 | or -m MARKER_ID.\n\ | |
16539 | If a line number is specified, probe the marker at start of code\n\ | |
16540 | for that line. If a function is specified, probe the marker at start\n\ | |
16541 | of code for that function. If an address is specified, probe the marker\n\ | |
16542 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16543 | with that name. With no LOCATION, uses current execution address of\n\ | |
16544 | the selected stack frame.\n\ | |
16545 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16546 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16547 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16548 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16549 | \n\ | |
16550 | CONDITION is a boolean expression.\n\ | |
16551 | \n\ | |
d41c0fc8 PA |
16552 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16553 | conditions are different.\n\ | |
0fb4aa4b PA |
16554 | \n\ |
16555 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16556 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16557 | set_cmd_completer (c, location_completer); | |
16558 | ||
1042e4c0 | 16559 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16560 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16561 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16562 | last tracepoint set.")); | |
16563 | ||
16564 | add_info_alias ("tp", "tracepoints", 1); | |
16565 | ||
16566 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16567 | Delete specified tracepoints.\n\ | |
16568 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16569 | No argument means delete all tracepoints."), | |
16570 | &deletelist); | |
7e20dfcd | 16571 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16572 | |
16573 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16574 | Disable specified tracepoints.\n\ | |
16575 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16576 | No argument means disable all tracepoints."), | |
16577 | &disablelist); | |
16578 | deprecate_cmd (c, "disable"); | |
16579 | ||
16580 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16581 | Enable specified tracepoints.\n\ | |
16582 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16583 | No argument means enable all tracepoints."), | |
16584 | &enablelist); | |
16585 | deprecate_cmd (c, "enable"); | |
16586 | ||
16587 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16588 | Set the passcount for a tracepoint.\n\ | |
16589 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16590 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16591 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16592 | ||
6149aea9 PA |
16593 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16594 | _("Save breakpoint definitions as a script."), | |
16595 | &save_cmdlist, "save ", | |
16596 | 0/*allow-unknown*/, &cmdlist); | |
16597 | ||
16598 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16599 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16600 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16601 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16602 | session to restore them."), | |
16603 | &save_cmdlist); | |
16604 | set_cmd_completer (c, filename_completer); | |
16605 | ||
16606 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16607 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16608 | Use the 'source' command in another debug session to restore them."), |
16609 | &save_cmdlist); | |
1042e4c0 SS |
16610 | set_cmd_completer (c, filename_completer); |
16611 | ||
6149aea9 PA |
16612 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16613 | deprecate_cmd (c, "save tracepoints"); | |
16614 | ||
1bedd215 | 16615 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16616 | Breakpoint specific settings\n\ |
16617 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16618 | pending breakpoint behavior"), |
fa8d40ab JJ |
16619 | &breakpoint_set_cmdlist, "set breakpoint ", |
16620 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16621 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16622 | Breakpoint specific settings\n\ |
16623 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16624 | pending breakpoint behavior"), |
fa8d40ab JJ |
16625 | &breakpoint_show_cmdlist, "show breakpoint ", |
16626 | 0/*allow-unknown*/, &showlist); | |
16627 | ||
7915a72c AC |
16628 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16629 | &pending_break_support, _("\ | |
16630 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16631 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16632 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16633 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16634 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16635 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16636 | NULL, |
920d2a44 | 16637 | show_pending_break_support, |
6e1d7d6c AC |
16638 | &breakpoint_set_cmdlist, |
16639 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16640 | |
16641 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16642 | |
16643 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16644 | &automatic_hardware_breakpoints, _("\ | |
16645 | Set automatic usage of hardware breakpoints."), _("\ | |
16646 | Show automatic usage of hardware breakpoints."), _("\ | |
16647 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16648 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16649 | a warning will be emitted for such breakpoints."), | |
16650 | NULL, | |
16651 | show_automatic_hardware_breakpoints, | |
16652 | &breakpoint_set_cmdlist, | |
16653 | &breakpoint_show_cmdlist); | |
74960c60 | 16654 | |
72d0e2c5 YQ |
16655 | add_setshow_auto_boolean_cmd ("always-inserted", class_support, |
16656 | &always_inserted_mode, _("\ | |
74960c60 VP |
16657 | Set mode for inserting breakpoints."), _("\ |
16658 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
16659 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
16660 | resumed, and removed when execution stops. When this mode is on,\n\ | |
16661 | breakpoints are inserted immediately and removed only when the user\n\ | |
16662 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
16663 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
16664 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
16665 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
16666 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
72d0e2c5 YQ |
16667 | NULL, |
16668 | &show_always_inserted_mode, | |
16669 | &breakpoint_set_cmdlist, | |
16670 | &breakpoint_show_cmdlist); | |
f1310107 | 16671 | |
b775012e LM |
16672 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16673 | condition_evaluation_enums, | |
16674 | &condition_evaluation_mode_1, _("\ | |
16675 | Set mode of breakpoint condition evaluation."), _("\ | |
16676 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16677 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16678 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16679 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16680 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16681 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16682 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16683 | be set to \"gdb\""), | |
16684 | &set_condition_evaluation_mode, | |
16685 | &show_condition_evaluation_mode, | |
16686 | &breakpoint_set_cmdlist, | |
16687 | &breakpoint_show_cmdlist); | |
16688 | ||
f1310107 TJB |
16689 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16690 | Set a breakpoint for an address range.\n\ | |
16691 | break-range START-LOCATION, END-LOCATION\n\ | |
16692 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16693 | LINENUM, for that line in the current file,\n\ | |
16694 | FILE:LINENUM, for that line in that file,\n\ | |
16695 | +OFFSET, for that number of lines after the current line\n\ | |
16696 | or the start of the range\n\ | |
16697 | FUNCTION, for the first line in that function,\n\ | |
16698 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16699 | *ADDRESS, for the instruction at that address.\n\ | |
16700 | \n\ | |
16701 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16702 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16703 | range (including START-LOCATION and END-LOCATION).")); | |
16704 | ||
e7e0cddf SS |
16705 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16706 | Set a dynamic printf at specified line or function.\n\ | |
16707 | dprintf location,format string,arg1,arg2,...\n\ | |
16708 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16709 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16710 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16711 | set_cmd_completer (c, location_completer); |
16712 | ||
16713 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16714 | dprintf_style_enums, &dprintf_style, _("\ | |
16715 | Set the style of usage for dynamic printf."), _("\ | |
16716 | Show the style of usage for dynamic printf."), _("\ | |
16717 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16718 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16719 | console, as with the \"printf\" command.\n\ | |
16720 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16721 | program; by default printf(), but you can choose a different function or\n\ | |
16722 | output stream by setting dprintf-function and dprintf-channel."), | |
16723 | update_dprintf_commands, NULL, | |
16724 | &setlist, &showlist); | |
16725 | ||
16726 | dprintf_function = xstrdup ("printf"); | |
16727 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16728 | &dprintf_function, _("\ | |
16729 | Set the function to use for dynamic printf"), _("\ | |
16730 | Show the function to use for dynamic printf"), NULL, | |
16731 | update_dprintf_commands, NULL, | |
16732 | &setlist, &showlist); | |
16733 | ||
16734 | dprintf_channel = xstrdup (""); | |
16735 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16736 | &dprintf_channel, _("\ | |
16737 | Set the channel to use for dynamic printf"), _("\ | |
16738 | Show the channel to use for dynamic printf"), NULL, | |
16739 | update_dprintf_commands, NULL, | |
16740 | &setlist, &showlist); | |
16741 | ||
d3ce09f5 SS |
16742 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16743 | &disconnected_dprintf, _("\ | |
16744 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16745 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16746 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16747 | even if GDB disconnects or detaches from the target."), | |
16748 | NULL, | |
16749 | NULL, | |
16750 | &setlist, &showlist); | |
16751 | ||
16752 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16753 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16754 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16755 | ||
765dc015 | 16756 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16757 | |
16758 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16759 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16760 | } |