Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
618f726f | 3 | Copyright (C) 1986-2016 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
f00aae0f | 70 | #include "location.h" |
cfc31633 | 71 | #include "thread-fsm.h" |
5d5658a1 | 72 | #include "tid-parse.h" |
d3ce09f5 | 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 | ||
f00aae0f KS |
114 | static void |
115 | create_sals_from_location_default (const struct event_location *location, | |
116 | struct linespec_result *canonical, | |
117 | enum bptype type_wanted); | |
983af33b SDJ |
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 | 126 | |
f00aae0f KS |
127 | static void decode_location_default (struct breakpoint *b, |
128 | const struct event_location *location, | |
c2f4122d | 129 | struct program_space *search_pspace, |
f00aae0f | 130 | struct symtabs_and_lines *sals); |
983af33b | 131 | |
a14ed312 | 132 | static void clear_command (char *, int); |
c906108c | 133 | |
a14ed312 | 134 | static void catch_command (char *, int); |
c906108c | 135 | |
a9634178 | 136 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 137 | |
98deb0da | 138 | static void break_command_1 (char *, int, int); |
c906108c | 139 | |
a14ed312 | 140 | static void mention (struct breakpoint *); |
c906108c | 141 | |
348d480f PA |
142 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
143 | enum bptype, | |
c0a91b2b | 144 | const struct breakpoint_ops *); |
3742cc8b YQ |
145 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
146 | const struct symtab_and_line *); | |
147 | ||
4a64f543 MS |
148 | /* This function is used in gdbtk sources and thus can not be made |
149 | static. */ | |
63c252f8 | 150 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 151 | struct symtab_and_line, |
c0a91b2b TT |
152 | enum bptype, |
153 | const struct breakpoint_ops *); | |
c906108c | 154 | |
06edf0c0 PA |
155 | static struct breakpoint * |
156 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
157 | enum bptype type, | |
a1aa2221 LM |
158 | const struct breakpoint_ops *ops, |
159 | int loc_enabled); | |
06edf0c0 | 160 | |
76897487 KB |
161 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
162 | ||
a6d9a66e UW |
163 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
164 | CORE_ADDR bpaddr, | |
88f7da05 | 165 | enum bptype bptype); |
76897487 | 166 | |
6c95b8df PA |
167 | static void describe_other_breakpoints (struct gdbarch *, |
168 | struct program_space *, CORE_ADDR, | |
5af949e3 | 169 | struct obj_section *, int); |
c906108c | 170 | |
85d721b8 PA |
171 | static int watchpoint_locations_match (struct bp_location *loc1, |
172 | struct bp_location *loc2); | |
173 | ||
f1310107 TJB |
174 | static int breakpoint_location_address_match (struct bp_location *bl, |
175 | struct address_space *aspace, | |
176 | CORE_ADDR addr); | |
177 | ||
d35ae833 PA |
178 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
179 | struct address_space *, | |
180 | CORE_ADDR, int); | |
181 | ||
a14ed312 | 182 | static void breakpoints_info (char *, int); |
c906108c | 183 | |
d77f58be SS |
184 | static void watchpoints_info (char *, int); |
185 | ||
e5a67952 MS |
186 | static int breakpoint_1 (char *, int, |
187 | int (*) (const struct breakpoint *)); | |
c906108c | 188 | |
4efb68b1 | 189 | static int breakpoint_cond_eval (void *); |
c906108c | 190 | |
4efb68b1 | 191 | static void cleanup_executing_breakpoints (void *); |
c906108c | 192 | |
a14ed312 | 193 | static void commands_command (char *, int); |
c906108c | 194 | |
a14ed312 | 195 | static void condition_command (char *, int); |
c906108c | 196 | |
c5aa993b JM |
197 | typedef enum |
198 | { | |
199 | mark_inserted, | |
200 | mark_uninserted | |
201 | } | |
202 | insertion_state_t; | |
c906108c | 203 | |
834c0d03 | 204 | static int remove_breakpoint (struct bp_location *); |
6c95b8df | 205 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 206 | |
e514a9d6 | 207 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 208 | |
4efb68b1 | 209 | static int watchpoint_check (void *); |
c906108c | 210 | |
a14ed312 | 211 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 212 | |
a14ed312 | 213 | static int hw_breakpoint_used_count (void); |
c906108c | 214 | |
a1398e0c PA |
215 | static int hw_watchpoint_use_count (struct breakpoint *); |
216 | ||
217 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
218 | enum bptype type, | |
219 | int *other_type_used); | |
c906108c | 220 | |
a14ed312 | 221 | static void hbreak_command (char *, int); |
c906108c | 222 | |
a14ed312 | 223 | static void thbreak_command (char *, int); |
c906108c | 224 | |
816338b5 SS |
225 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
226 | int count); | |
c906108c | 227 | |
a14ed312 | 228 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 231 | |
a14ed312 | 232 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 233 | |
a14ed312 | 234 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 235 | |
fe3f5fa8 | 236 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
237 | static void incref_bp_location (struct bp_location *loc); |
238 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 239 | |
39d61571 | 240 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 241 | |
44702360 PA |
242 | /* update_global_location_list's modes of operation wrt to whether to |
243 | insert locations now. */ | |
244 | enum ugll_insert_mode | |
245 | { | |
246 | /* Don't insert any breakpoint locations into the inferior, only | |
247 | remove already-inserted locations that no longer should be | |
248 | inserted. Functions that delete a breakpoint or breakpoints | |
249 | should specify this mode, so that deleting a breakpoint doesn't | |
250 | have the side effect of inserting the locations of other | |
251 | breakpoints that are marked not-inserted, but should_be_inserted | |
252 | returns true on them. | |
253 | ||
254 | This behavior is useful is situations close to tear-down -- e.g., | |
255 | after an exec, while the target still has execution, but | |
256 | breakpoint shadows of the previous executable image should *NOT* | |
257 | be restored to the new image; or before detaching, where the | |
258 | target still has execution and wants to delete breakpoints from | |
259 | GDB's lists, and all breakpoints had already been removed from | |
260 | the inferior. */ | |
261 | UGLL_DONT_INSERT, | |
262 | ||
a25a5a45 PA |
263 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
264 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
265 | UGLL_MAY_INSERT, |
266 | ||
a25a5a45 PA |
267 | /* Insert locations now, irrespective of |
268 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
269 | stopped right now, and the user did "continue". We need to | |
270 | insert breakpoints _before_ resuming the target, but | |
271 | UGLL_MAY_INSERT wouldn't insert them, because | |
272 | breakpoints_should_be_inserted_now returns false at that point, | |
273 | as no thread is running yet. */ | |
04086b45 | 274 | UGLL_INSERT |
44702360 PA |
275 | }; |
276 | ||
277 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 278 | |
44702360 | 279 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 280 | |
d77f58be | 281 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
282 | |
283 | static void insert_breakpoint_locations (void); | |
a5606eee | 284 | |
1042e4c0 SS |
285 | static void tracepoints_info (char *, int); |
286 | ||
287 | static void delete_trace_command (char *, int); | |
288 | ||
289 | static void enable_trace_command (char *, int); | |
290 | ||
291 | static void disable_trace_command (char *, int); | |
292 | ||
293 | static void trace_pass_command (char *, int); | |
294 | ||
558a9d82 YQ |
295 | static void set_tracepoint_count (int num); |
296 | ||
9c06b0b4 TJB |
297 | static int is_masked_watchpoint (const struct breakpoint *b); |
298 | ||
b775012e LM |
299 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
300 | ||
983af33b SDJ |
301 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
302 | otherwise. */ | |
303 | ||
304 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 305 | |
2060206e PA |
306 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
307 | that are implemented on top of software or hardware breakpoints | |
308 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
309 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
310 | ||
311 | /* Internal breakpoints class type. */ | |
06edf0c0 | 312 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
313 | |
314 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
315 | static struct breakpoint_ops momentary_breakpoint_ops; |
316 | ||
e2e4d78b JK |
317 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
318 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
319 | ||
2060206e PA |
320 | /* The breakpoint_ops structure to be used in regular user created |
321 | breakpoints. */ | |
322 | struct breakpoint_ops bkpt_breakpoint_ops; | |
323 | ||
55aa24fb SDJ |
324 | /* Breakpoints set on probes. */ |
325 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
326 | ||
e7e0cddf | 327 | /* Dynamic printf class type. */ |
c5867ab6 | 328 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 329 | |
d3ce09f5 SS |
330 | /* The style in which to perform a dynamic printf. This is a user |
331 | option because different output options have different tradeoffs; | |
332 | if GDB does the printing, there is better error handling if there | |
333 | is a problem with any of the arguments, but using an inferior | |
334 | function lets you have special-purpose printers and sending of | |
335 | output to the same place as compiled-in print functions. */ | |
336 | ||
337 | static const char dprintf_style_gdb[] = "gdb"; | |
338 | static const char dprintf_style_call[] = "call"; | |
339 | static const char dprintf_style_agent[] = "agent"; | |
340 | static const char *const dprintf_style_enums[] = { | |
341 | dprintf_style_gdb, | |
342 | dprintf_style_call, | |
343 | dprintf_style_agent, | |
344 | NULL | |
345 | }; | |
346 | static const char *dprintf_style = dprintf_style_gdb; | |
347 | ||
348 | /* The function to use for dynamic printf if the preferred style is to | |
349 | call into the inferior. The value is simply a string that is | |
350 | copied into the command, so it can be anything that GDB can | |
351 | evaluate to a callable address, not necessarily a function name. */ | |
352 | ||
353 | static char *dprintf_function = ""; | |
354 | ||
355 | /* The channel to use for dynamic printf if the preferred style is to | |
356 | call into the inferior; if a nonempty string, it will be passed to | |
357 | the call as the first argument, with the format string as the | |
358 | second. As with the dprintf function, this can be anything that | |
359 | GDB knows how to evaluate, so in addition to common choices like | |
360 | "stderr", this could be an app-specific expression like | |
361 | "mystreams[curlogger]". */ | |
362 | ||
363 | static char *dprintf_channel = ""; | |
364 | ||
365 | /* True if dprintf commands should continue to operate even if GDB | |
366 | has disconnected. */ | |
367 | static int disconnected_dprintf = 1; | |
368 | ||
5cea2a26 PA |
369 | /* A reference-counted struct command_line. This lets multiple |
370 | breakpoints share a single command list. */ | |
371 | struct counted_command_line | |
372 | { | |
373 | /* The reference count. */ | |
374 | int refc; | |
375 | ||
376 | /* The command list. */ | |
377 | struct command_line *commands; | |
378 | }; | |
379 | ||
380 | struct command_line * | |
381 | breakpoint_commands (struct breakpoint *b) | |
382 | { | |
383 | return b->commands ? b->commands->commands : NULL; | |
384 | } | |
3daf8fe5 | 385 | |
f3b1572e PA |
386 | /* Flag indicating that a command has proceeded the inferior past the |
387 | current breakpoint. */ | |
388 | ||
389 | static int breakpoint_proceeded; | |
390 | ||
956a9fb9 | 391 | const char * |
2cec12e5 AR |
392 | bpdisp_text (enum bpdisp disp) |
393 | { | |
4a64f543 MS |
394 | /* NOTE: the following values are a part of MI protocol and |
395 | represent values of 'disp' field returned when inferior stops at | |
396 | a breakpoint. */ | |
bc043ef3 | 397 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 398 | |
2cec12e5 AR |
399 | return bpdisps[(int) disp]; |
400 | } | |
c906108c | 401 | |
4a64f543 | 402 | /* Prototypes for exported functions. */ |
c906108c | 403 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 404 | if such is available. */ |
c906108c SS |
405 | static int can_use_hw_watchpoints; |
406 | ||
920d2a44 AC |
407 | static void |
408 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
409 | struct cmd_list_element *c, | |
410 | const char *value) | |
411 | { | |
3e43a32a MS |
412 | fprintf_filtered (file, |
413 | _("Debugger's willingness to use " | |
414 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
415 | value); |
416 | } | |
417 | ||
fa8d40ab JJ |
418 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
419 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 420 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
421 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
422 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
423 | static void |
424 | show_pending_break_support (struct ui_file *file, int from_tty, | |
425 | struct cmd_list_element *c, | |
426 | const char *value) | |
427 | { | |
3e43a32a MS |
428 | fprintf_filtered (file, |
429 | _("Debugger's behavior regarding " | |
430 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
431 | value); |
432 | } | |
fa8d40ab | 433 | |
765dc015 | 434 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 435 | set with "break" but falling in read-only memory. |
765dc015 VP |
436 | If 0, gdb will warn about such breakpoints, but won't automatically |
437 | use hardware breakpoints. */ | |
438 | static int automatic_hardware_breakpoints; | |
439 | static void | |
440 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
441 | struct cmd_list_element *c, | |
442 | const char *value) | |
443 | { | |
3e43a32a MS |
444 | fprintf_filtered (file, |
445 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
446 | value); |
447 | } | |
448 | ||
a25a5a45 PA |
449 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
450 | stopped, and immediately inserts any new breakpoints as soon as | |
451 | they're created. If off (default), GDB keeps breakpoints off of | |
452 | the target as long as possible. That is, it delays inserting | |
453 | breakpoints until the next resume, and removes them again when the | |
454 | target fully stops. This is a bit safer in case GDB crashes while | |
455 | processing user input. */ | |
456 | static int always_inserted_mode = 0; | |
72d0e2c5 | 457 | |
33e5cbd6 | 458 | static void |
74960c60 | 459 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 460 | struct cmd_list_element *c, const char *value) |
74960c60 | 461 | { |
a25a5a45 PA |
462 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
463 | value); | |
74960c60 VP |
464 | } |
465 | ||
b57bacec PA |
466 | /* See breakpoint.h. */ |
467 | ||
33e5cbd6 | 468 | int |
a25a5a45 | 469 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 470 | { |
a25a5a45 PA |
471 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
472 | { | |
473 | /* If breakpoints are global, they should be inserted even if no | |
474 | thread under gdb's control is running, or even if there are | |
475 | no threads under GDB's control yet. */ | |
476 | return 1; | |
477 | } | |
478 | else if (target_has_execution) | |
479 | { | |
372316f1 PA |
480 | struct thread_info *tp; |
481 | ||
a25a5a45 PA |
482 | if (always_inserted_mode) |
483 | { | |
484 | /* The user wants breakpoints inserted even if all threads | |
485 | are stopped. */ | |
486 | return 1; | |
487 | } | |
488 | ||
b57bacec PA |
489 | if (threads_are_executing ()) |
490 | return 1; | |
372316f1 PA |
491 | |
492 | /* Don't remove breakpoints yet if, even though all threads are | |
493 | stopped, we still have events to process. */ | |
494 | ALL_NON_EXITED_THREADS (tp) | |
495 | if (tp->resumed | |
496 | && tp->suspend.waitstatus_pending_p) | |
497 | return 1; | |
a25a5a45 PA |
498 | } |
499 | return 0; | |
33e5cbd6 | 500 | } |
765dc015 | 501 | |
b775012e LM |
502 | static const char condition_evaluation_both[] = "host or target"; |
503 | ||
504 | /* Modes for breakpoint condition evaluation. */ | |
505 | static const char condition_evaluation_auto[] = "auto"; | |
506 | static const char condition_evaluation_host[] = "host"; | |
507 | static const char condition_evaluation_target[] = "target"; | |
508 | static const char *const condition_evaluation_enums[] = { | |
509 | condition_evaluation_auto, | |
510 | condition_evaluation_host, | |
511 | condition_evaluation_target, | |
512 | NULL | |
513 | }; | |
514 | ||
515 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
516 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
517 | ||
518 | /* Global that we use to display information to the user (gets its value from | |
519 | condition_evaluation_mode_1. */ | |
520 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
521 | ||
522 | /* Translate a condition evaluation mode MODE into either "host" | |
523 | or "target". This is used mostly to translate from "auto" to the | |
524 | real setting that is being used. It returns the translated | |
525 | evaluation mode. */ | |
526 | ||
527 | static const char * | |
528 | translate_condition_evaluation_mode (const char *mode) | |
529 | { | |
530 | if (mode == condition_evaluation_auto) | |
531 | { | |
532 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
533 | return condition_evaluation_target; | |
534 | else | |
535 | return condition_evaluation_host; | |
536 | } | |
537 | else | |
538 | return mode; | |
539 | } | |
540 | ||
541 | /* Discovers what condition_evaluation_auto translates to. */ | |
542 | ||
543 | static const char * | |
544 | breakpoint_condition_evaluation_mode (void) | |
545 | { | |
546 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
547 | } | |
548 | ||
549 | /* Return true if GDB should evaluate breakpoint conditions or false | |
550 | otherwise. */ | |
551 | ||
552 | static int | |
553 | gdb_evaluates_breakpoint_condition_p (void) | |
554 | { | |
555 | const char *mode = breakpoint_condition_evaluation_mode (); | |
556 | ||
557 | return (mode == condition_evaluation_host); | |
558 | } | |
559 | ||
a14ed312 | 560 | void _initialize_breakpoint (void); |
c906108c | 561 | |
c906108c SS |
562 | /* Are we executing breakpoint commands? */ |
563 | static int executing_breakpoint_commands; | |
564 | ||
c02f5703 MS |
565 | /* Are overlay event breakpoints enabled? */ |
566 | static int overlay_events_enabled; | |
567 | ||
e09342b5 TJB |
568 | /* See description in breakpoint.h. */ |
569 | int target_exact_watchpoints = 0; | |
570 | ||
c906108c | 571 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 572 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 573 | current breakpoint. */ |
c906108c | 574 | |
5c44784c | 575 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 576 | |
5c44784c JM |
577 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
578 | for (B = breakpoint_chain; \ | |
579 | B ? (TMP=B->next, 1): 0; \ | |
580 | B = TMP) | |
c906108c | 581 | |
4a64f543 MS |
582 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
583 | not provided so update_global_location_list must not be called | |
584 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 585 | |
876fa593 JK |
586 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
587 | for (BP_TMP = bp_location; \ | |
588 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
589 | BP_TMP++) | |
7cc221ef | 590 | |
b775012e LM |
591 | /* Iterates through locations with address ADDRESS for the currently selected |
592 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
593 | to where the loop should start from. | |
594 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
595 | appropriate location to start with. */ | |
596 | ||
597 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
598 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
599 | BP_LOCP_TMP = BP_LOCP_START; \ | |
600 | BP_LOCP_START \ | |
601 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
602 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
603 | BP_LOCP_TMP++) | |
604 | ||
1042e4c0 SS |
605 | /* Iterator for tracepoints only. */ |
606 | ||
607 | #define ALL_TRACEPOINTS(B) \ | |
608 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 609 | if (is_tracepoint (B)) |
1042e4c0 | 610 | |
7cc221ef | 611 | /* Chains of all breakpoints defined. */ |
c906108c SS |
612 | |
613 | struct breakpoint *breakpoint_chain; | |
614 | ||
876fa593 JK |
615 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
616 | ||
617 | static struct bp_location **bp_location; | |
618 | ||
619 | /* Number of elements of BP_LOCATION. */ | |
620 | ||
621 | static unsigned bp_location_count; | |
622 | ||
4a64f543 MS |
623 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
624 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
625 | result from bp_location_has_shadow. You can use it for roughly | |
626 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
627 | an address you need to read. */ | |
876fa593 JK |
628 | |
629 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
630 | ||
4a64f543 MS |
631 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
632 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
633 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
634 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
635 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
636 | |
637 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 638 | |
4a64f543 MS |
639 | /* The locations that no longer correspond to any breakpoint, unlinked |
640 | from bp_location array, but for which a hit may still be reported | |
641 | by a target. */ | |
20874c92 VP |
642 | VEC(bp_location_p) *moribund_locations = NULL; |
643 | ||
c906108c SS |
644 | /* Number of last breakpoint made. */ |
645 | ||
95a42b64 TT |
646 | static int breakpoint_count; |
647 | ||
86b17b60 PA |
648 | /* The value of `breakpoint_count' before the last command that |
649 | created breakpoints. If the last (break-like) command created more | |
650 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
651 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
652 | static int prev_breakpoint_count; | |
c906108c | 653 | |
1042e4c0 SS |
654 | /* Number of last tracepoint made. */ |
655 | ||
95a42b64 | 656 | static int tracepoint_count; |
1042e4c0 | 657 | |
6149aea9 PA |
658 | static struct cmd_list_element *breakpoint_set_cmdlist; |
659 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 660 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 661 | |
badd37ce SDJ |
662 | /* See declaration at breakpoint.h. */ |
663 | ||
664 | struct breakpoint * | |
665 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
666 | void *user_data) | |
667 | { | |
668 | struct breakpoint *b = NULL; | |
669 | ||
670 | ALL_BREAKPOINTS (b) | |
671 | { | |
672 | if (func (b, user_data) != 0) | |
673 | break; | |
674 | } | |
675 | ||
676 | return b; | |
677 | } | |
678 | ||
468d015d JJ |
679 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
680 | static int | |
681 | breakpoint_enabled (struct breakpoint *b) | |
682 | { | |
0d381245 | 683 | return (b->enable_state == bp_enabled); |
468d015d JJ |
684 | } |
685 | ||
c906108c SS |
686 | /* Set breakpoint count to NUM. */ |
687 | ||
95a42b64 | 688 | static void |
fba45db2 | 689 | set_breakpoint_count (int num) |
c906108c | 690 | { |
86b17b60 | 691 | prev_breakpoint_count = breakpoint_count; |
c906108c | 692 | breakpoint_count = num; |
4fa62494 | 693 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
694 | } |
695 | ||
86b17b60 PA |
696 | /* Used by `start_rbreak_breakpoints' below, to record the current |
697 | breakpoint count before "rbreak" creates any breakpoint. */ | |
698 | static int rbreak_start_breakpoint_count; | |
699 | ||
95a42b64 TT |
700 | /* Called at the start an "rbreak" command to record the first |
701 | breakpoint made. */ | |
86b17b60 | 702 | |
95a42b64 TT |
703 | void |
704 | start_rbreak_breakpoints (void) | |
705 | { | |
86b17b60 | 706 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
707 | } |
708 | ||
709 | /* Called at the end of an "rbreak" command to record the last | |
710 | breakpoint made. */ | |
86b17b60 | 711 | |
95a42b64 TT |
712 | void |
713 | end_rbreak_breakpoints (void) | |
714 | { | |
86b17b60 | 715 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
716 | } |
717 | ||
4a64f543 | 718 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
719 | |
720 | void | |
fba45db2 | 721 | clear_breakpoint_hit_counts (void) |
c906108c SS |
722 | { |
723 | struct breakpoint *b; | |
724 | ||
725 | ALL_BREAKPOINTS (b) | |
726 | b->hit_count = 0; | |
727 | } | |
728 | ||
9add0f1b TT |
729 | /* Allocate a new counted_command_line with reference count of 1. |
730 | The new structure owns COMMANDS. */ | |
731 | ||
732 | static struct counted_command_line * | |
733 | alloc_counted_command_line (struct command_line *commands) | |
734 | { | |
8d749320 | 735 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 736 | |
9add0f1b TT |
737 | result->refc = 1; |
738 | result->commands = commands; | |
8d749320 | 739 | |
9add0f1b TT |
740 | return result; |
741 | } | |
742 | ||
743 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
744 | ||
745 | static void | |
746 | incref_counted_command_line (struct counted_command_line *cmd) | |
747 | { | |
748 | if (cmd) | |
749 | ++cmd->refc; | |
750 | } | |
751 | ||
752 | /* Decrement reference count. If the reference count reaches 0, | |
753 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
754 | nothing if *CMDP is NULL. */ | |
755 | ||
756 | static void | |
757 | decref_counted_command_line (struct counted_command_line **cmdp) | |
758 | { | |
759 | if (*cmdp) | |
760 | { | |
761 | if (--(*cmdp)->refc == 0) | |
762 | { | |
763 | free_command_lines (&(*cmdp)->commands); | |
764 | xfree (*cmdp); | |
765 | } | |
766 | *cmdp = NULL; | |
767 | } | |
768 | } | |
769 | ||
770 | /* A cleanup function that calls decref_counted_command_line. */ | |
771 | ||
772 | static void | |
773 | do_cleanup_counted_command_line (void *arg) | |
774 | { | |
9a3c8263 | 775 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
776 | } |
777 | ||
778 | /* Create a cleanup that calls decref_counted_command_line on the | |
779 | argument. */ | |
780 | ||
781 | static struct cleanup * | |
782 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
783 | { | |
784 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
785 | } | |
786 | ||
c906108c | 787 | \f |
48cb2d85 VP |
788 | /* Return the breakpoint with the specified number, or NULL |
789 | if the number does not refer to an existing breakpoint. */ | |
790 | ||
791 | struct breakpoint * | |
792 | get_breakpoint (int num) | |
793 | { | |
794 | struct breakpoint *b; | |
795 | ||
796 | ALL_BREAKPOINTS (b) | |
797 | if (b->number == num) | |
798 | return b; | |
799 | ||
800 | return NULL; | |
801 | } | |
5c44784c | 802 | |
c906108c | 803 | \f |
adc36818 | 804 | |
b775012e LM |
805 | /* Mark locations as "conditions have changed" in case the target supports |
806 | evaluating conditions on its side. */ | |
807 | ||
808 | static void | |
809 | mark_breakpoint_modified (struct breakpoint *b) | |
810 | { | |
811 | struct bp_location *loc; | |
812 | ||
813 | /* This is only meaningful if the target is | |
814 | evaluating conditions and if the user has | |
815 | opted for condition evaluation on the target's | |
816 | side. */ | |
817 | if (gdb_evaluates_breakpoint_condition_p () | |
818 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
819 | return; | |
820 | ||
821 | if (!is_breakpoint (b)) | |
822 | return; | |
823 | ||
824 | for (loc = b->loc; loc; loc = loc->next) | |
825 | loc->condition_changed = condition_modified; | |
826 | } | |
827 | ||
828 | /* Mark location as "conditions have changed" in case the target supports | |
829 | evaluating conditions on its side. */ | |
830 | ||
831 | static void | |
832 | mark_breakpoint_location_modified (struct bp_location *loc) | |
833 | { | |
834 | /* This is only meaningful if the target is | |
835 | evaluating conditions and if the user has | |
836 | opted for condition evaluation on the target's | |
837 | side. */ | |
838 | if (gdb_evaluates_breakpoint_condition_p () | |
839 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
840 | ||
841 | return; | |
842 | ||
843 | if (!is_breakpoint (loc->owner)) | |
844 | return; | |
845 | ||
846 | loc->condition_changed = condition_modified; | |
847 | } | |
848 | ||
849 | /* Sets the condition-evaluation mode using the static global | |
850 | condition_evaluation_mode. */ | |
851 | ||
852 | static void | |
853 | set_condition_evaluation_mode (char *args, int from_tty, | |
854 | struct cmd_list_element *c) | |
855 | { | |
b775012e LM |
856 | const char *old_mode, *new_mode; |
857 | ||
858 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
859 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
860 | { | |
861 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
862 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
863 | "Using host evaluation mode instead.")); | |
864 | return; | |
865 | } | |
866 | ||
867 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
868 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
869 | ||
abf1152a JK |
870 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
871 | settings was "auto". */ | |
872 | condition_evaluation_mode = condition_evaluation_mode_1; | |
873 | ||
b775012e LM |
874 | /* Only update the mode if the user picked a different one. */ |
875 | if (new_mode != old_mode) | |
876 | { | |
877 | struct bp_location *loc, **loc_tmp; | |
878 | /* If the user switched to a different evaluation mode, we | |
879 | need to synch the changes with the target as follows: | |
880 | ||
881 | "host" -> "target": Send all (valid) conditions to the target. | |
882 | "target" -> "host": Remove all the conditions from the target. | |
883 | */ | |
884 | ||
b775012e LM |
885 | if (new_mode == condition_evaluation_target) |
886 | { | |
887 | /* Mark everything modified and synch conditions with the | |
888 | target. */ | |
889 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
890 | mark_breakpoint_location_modified (loc); | |
891 | } | |
892 | else | |
893 | { | |
894 | /* Manually mark non-duplicate locations to synch conditions | |
895 | with the target. We do this to remove all the conditions the | |
896 | target knows about. */ | |
897 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
898 | if (is_breakpoint (loc->owner) && loc->inserted) | |
899 | loc->needs_update = 1; | |
900 | } | |
901 | ||
902 | /* Do the update. */ | |
44702360 | 903 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
904 | } |
905 | ||
906 | return; | |
907 | } | |
908 | ||
909 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
910 | what "auto" is translating to. */ | |
911 | ||
912 | static void | |
913 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
914 | struct cmd_list_element *c, const char *value) | |
915 | { | |
916 | if (condition_evaluation_mode == condition_evaluation_auto) | |
917 | fprintf_filtered (file, | |
918 | _("Breakpoint condition evaluation " | |
919 | "mode is %s (currently %s).\n"), | |
920 | value, | |
921 | breakpoint_condition_evaluation_mode ()); | |
922 | else | |
923 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
924 | value); | |
925 | } | |
926 | ||
927 | /* A comparison function for bp_location AP and BP that is used by | |
928 | bsearch. This comparison function only cares about addresses, unlike | |
929 | the more general bp_location_compare function. */ | |
930 | ||
931 | static int | |
932 | bp_location_compare_addrs (const void *ap, const void *bp) | |
933 | { | |
9a3c8263 SM |
934 | const struct bp_location *a = *(const struct bp_location **) ap; |
935 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
936 | |
937 | if (a->address == b->address) | |
938 | return 0; | |
939 | else | |
940 | return ((a->address > b->address) - (a->address < b->address)); | |
941 | } | |
942 | ||
943 | /* Helper function to skip all bp_locations with addresses | |
944 | less than ADDRESS. It returns the first bp_location that | |
945 | is greater than or equal to ADDRESS. If none is found, just | |
946 | return NULL. */ | |
947 | ||
948 | static struct bp_location ** | |
949 | get_first_locp_gte_addr (CORE_ADDR address) | |
950 | { | |
951 | struct bp_location dummy_loc; | |
952 | struct bp_location *dummy_locp = &dummy_loc; | |
953 | struct bp_location **locp_found = NULL; | |
954 | ||
955 | /* Initialize the dummy location's address field. */ | |
956 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
957 | dummy_loc.address = address; | |
958 | ||
959 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 SM |
960 | locp_found = ((struct bp_location **) |
961 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
962 | sizeof (struct bp_location **), | |
963 | bp_location_compare_addrs)); | |
b775012e LM |
964 | |
965 | /* Nothing was found, nothing left to do. */ | |
966 | if (locp_found == NULL) | |
967 | return NULL; | |
968 | ||
969 | /* We may have found a location that is at ADDRESS but is not the first in the | |
970 | location's list. Go backwards (if possible) and locate the first one. */ | |
971 | while ((locp_found - 1) >= bp_location | |
972 | && (*(locp_found - 1))->address == address) | |
973 | locp_found--; | |
974 | ||
975 | return locp_found; | |
976 | } | |
977 | ||
adc36818 | 978 | void |
7a26bd4d | 979 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
980 | int from_tty) |
981 | { | |
3a5c3e22 PA |
982 | xfree (b->cond_string); |
983 | b->cond_string = NULL; | |
adc36818 | 984 | |
3a5c3e22 | 985 | if (is_watchpoint (b)) |
adc36818 | 986 | { |
3a5c3e22 PA |
987 | struct watchpoint *w = (struct watchpoint *) b; |
988 | ||
989 | xfree (w->cond_exp); | |
990 | w->cond_exp = NULL; | |
991 | } | |
992 | else | |
993 | { | |
994 | struct bp_location *loc; | |
995 | ||
996 | for (loc = b->loc; loc; loc = loc->next) | |
997 | { | |
998 | xfree (loc->cond); | |
999 | loc->cond = NULL; | |
b775012e LM |
1000 | |
1001 | /* No need to free the condition agent expression | |
1002 | bytecode (if we have one). We will handle this | |
1003 | when we go through update_global_location_list. */ | |
3a5c3e22 | 1004 | } |
adc36818 | 1005 | } |
adc36818 PM |
1006 | |
1007 | if (*exp == 0) | |
1008 | { | |
1009 | if (from_tty) | |
1010 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1011 | } | |
1012 | else | |
1013 | { | |
bbc13ae3 | 1014 | const char *arg = exp; |
cc59ec59 | 1015 | |
adc36818 PM |
1016 | /* I don't know if it matters whether this is the string the user |
1017 | typed in or the decompiled expression. */ | |
1018 | b->cond_string = xstrdup (arg); | |
1019 | b->condition_not_parsed = 0; | |
1020 | ||
1021 | if (is_watchpoint (b)) | |
1022 | { | |
3a5c3e22 PA |
1023 | struct watchpoint *w = (struct watchpoint *) b; |
1024 | ||
adc36818 PM |
1025 | innermost_block = NULL; |
1026 | arg = exp; | |
1bb9788d | 1027 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1028 | if (*arg) |
1029 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1030 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1031 | } |
1032 | else | |
1033 | { | |
3a5c3e22 PA |
1034 | struct bp_location *loc; |
1035 | ||
adc36818 PM |
1036 | for (loc = b->loc; loc; loc = loc->next) |
1037 | { | |
1038 | arg = exp; | |
1039 | loc->cond = | |
1bb9788d TT |
1040 | parse_exp_1 (&arg, loc->address, |
1041 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1042 | if (*arg) |
1043 | error (_("Junk at end of expression")); | |
1044 | } | |
1045 | } | |
1046 | } | |
b775012e LM |
1047 | mark_breakpoint_modified (b); |
1048 | ||
8d3788bd | 1049 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1050 | } |
1051 | ||
d55637df TT |
1052 | /* Completion for the "condition" command. */ |
1053 | ||
1054 | static VEC (char_ptr) * | |
6f937416 PA |
1055 | condition_completer (struct cmd_list_element *cmd, |
1056 | const char *text, const char *word) | |
d55637df | 1057 | { |
6f937416 | 1058 | const char *space; |
d55637df | 1059 | |
6f937416 PA |
1060 | text = skip_spaces_const (text); |
1061 | space = skip_to_space_const (text); | |
d55637df TT |
1062 | if (*space == '\0') |
1063 | { | |
1064 | int len; | |
1065 | struct breakpoint *b; | |
1066 | VEC (char_ptr) *result = NULL; | |
1067 | ||
1068 | if (text[0] == '$') | |
1069 | { | |
1070 | /* We don't support completion of history indices. */ | |
1071 | if (isdigit (text[1])) | |
1072 | return NULL; | |
1073 | return complete_internalvar (&text[1]); | |
1074 | } | |
1075 | ||
1076 | /* We're completing the breakpoint number. */ | |
1077 | len = strlen (text); | |
1078 | ||
1079 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1080 | { |
1081 | char number[50]; | |
1082 | ||
1083 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1084 | ||
1085 | if (strncmp (number, text, len) == 0) | |
1086 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1087 | } | |
d55637df TT |
1088 | |
1089 | return result; | |
1090 | } | |
1091 | ||
1092 | /* We're completing the expression part. */ | |
6f937416 | 1093 | text = skip_spaces_const (space); |
d55637df TT |
1094 | return expression_completer (cmd, text, word); |
1095 | } | |
1096 | ||
c906108c SS |
1097 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1098 | ||
1099 | static void | |
fba45db2 | 1100 | condition_command (char *arg, int from_tty) |
c906108c | 1101 | { |
52f0bd74 | 1102 | struct breakpoint *b; |
c906108c | 1103 | char *p; |
52f0bd74 | 1104 | int bnum; |
c906108c SS |
1105 | |
1106 | if (arg == 0) | |
e2e0b3e5 | 1107 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1108 | |
1109 | p = arg; | |
1110 | bnum = get_number (&p); | |
5c44784c | 1111 | if (bnum == 0) |
8a3fe4f8 | 1112 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1113 | |
1114 | ALL_BREAKPOINTS (b) | |
1115 | if (b->number == bnum) | |
2f069f6f | 1116 | { |
6dddc817 DE |
1117 | /* Check if this breakpoint has a "stop" method implemented in an |
1118 | extension language. This method and conditions entered into GDB | |
1119 | from the CLI are mutually exclusive. */ | |
1120 | const struct extension_language_defn *extlang | |
1121 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1122 | ||
1123 | if (extlang != NULL) | |
1124 | { | |
1125 | error (_("Only one stop condition allowed. There is currently" | |
1126 | " a %s stop condition defined for this breakpoint."), | |
1127 | ext_lang_capitalized_name (extlang)); | |
1128 | } | |
2566ad2d | 1129 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1130 | |
1131 | if (is_breakpoint (b)) | |
44702360 | 1132 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1133 | |
2f069f6f JB |
1134 | return; |
1135 | } | |
c906108c | 1136 | |
8a3fe4f8 | 1137 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1138 | } |
1139 | ||
a7bdde9e VP |
1140 | /* Check that COMMAND do not contain commands that are suitable |
1141 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1142 | Throw if any such commands is found. */ |
1143 | ||
a7bdde9e VP |
1144 | static void |
1145 | check_no_tracepoint_commands (struct command_line *commands) | |
1146 | { | |
1147 | struct command_line *c; | |
cc59ec59 | 1148 | |
a7bdde9e VP |
1149 | for (c = commands; c; c = c->next) |
1150 | { | |
1151 | int i; | |
1152 | ||
1153 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1154 | error (_("The 'while-stepping' command can " |
1155 | "only be used for tracepoints")); | |
a7bdde9e VP |
1156 | |
1157 | for (i = 0; i < c->body_count; ++i) | |
1158 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1159 | ||
1160 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1161 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1162 | command directly. */ |
1163 | if (strstr (c->line, "collect ") == c->line) | |
1164 | error (_("The 'collect' command can only be used for tracepoints")); | |
1165 | ||
51661e93 VP |
1166 | if (strstr (c->line, "teval ") == c->line) |
1167 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1168 | } |
1169 | } | |
1170 | ||
d77f58be SS |
1171 | /* Encapsulate tests for different types of tracepoints. */ |
1172 | ||
d9b3f62e PA |
1173 | static int |
1174 | is_tracepoint_type (enum bptype type) | |
1175 | { | |
1176 | return (type == bp_tracepoint | |
1177 | || type == bp_fast_tracepoint | |
1178 | || type == bp_static_tracepoint); | |
1179 | } | |
1180 | ||
a7bdde9e | 1181 | int |
d77f58be | 1182 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1183 | { |
d9b3f62e | 1184 | return is_tracepoint_type (b->type); |
a7bdde9e | 1185 | } |
d9b3f62e | 1186 | |
e5dd4106 | 1187 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1188 | breakpoint. This function will throw an exception if a problem is |
1189 | found. */ | |
48cb2d85 | 1190 | |
95a42b64 TT |
1191 | static void |
1192 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1193 | struct command_line *commands) | |
48cb2d85 | 1194 | { |
d77f58be | 1195 | if (is_tracepoint (b)) |
a7bdde9e | 1196 | { |
c9a6ce02 | 1197 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1198 | struct command_line *c; |
1199 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1200 | |
1201 | /* Reset the while-stepping step count. The previous commands | |
1202 | might have included a while-stepping action, while the new | |
1203 | ones might not. */ | |
1204 | t->step_count = 0; | |
1205 | ||
1206 | /* We need to verify that each top-level element of commands is | |
1207 | valid for tracepoints, that there's at most one | |
1208 | while-stepping element, and that the while-stepping's body | |
1209 | has valid tracing commands excluding nested while-stepping. | |
1210 | We also need to validate the tracepoint action line in the | |
1211 | context of the tracepoint --- validate_actionline actually | |
1212 | has side effects, like setting the tracepoint's | |
1213 | while-stepping STEP_COUNT, in addition to checking if the | |
1214 | collect/teval actions parse and make sense in the | |
1215 | tracepoint's context. */ | |
a7bdde9e VP |
1216 | for (c = commands; c; c = c->next) |
1217 | { | |
a7bdde9e VP |
1218 | if (c->control_type == while_stepping_control) |
1219 | { | |
1220 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1221 | error (_("The 'while-stepping' command " |
1222 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1223 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1224 | error (_("The 'while-stepping' command " |
1225 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1226 | |
1227 | if (while_stepping) | |
3e43a32a MS |
1228 | error (_("The 'while-stepping' command " |
1229 | "can be used only once")); | |
a7bdde9e VP |
1230 | else |
1231 | while_stepping = c; | |
1232 | } | |
c9a6ce02 PA |
1233 | |
1234 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1235 | } |
1236 | if (while_stepping) | |
1237 | { | |
1238 | struct command_line *c2; | |
1239 | ||
1240 | gdb_assert (while_stepping->body_count == 1); | |
1241 | c2 = while_stepping->body_list[0]; | |
1242 | for (; c2; c2 = c2->next) | |
1243 | { | |
a7bdde9e VP |
1244 | if (c2->control_type == while_stepping_control) |
1245 | error (_("The 'while-stepping' command cannot be nested")); | |
1246 | } | |
1247 | } | |
1248 | } | |
1249 | else | |
1250 | { | |
1251 | check_no_tracepoint_commands (commands); | |
1252 | } | |
95a42b64 TT |
1253 | } |
1254 | ||
0fb4aa4b PA |
1255 | /* Return a vector of all the static tracepoints set at ADDR. The |
1256 | caller is responsible for releasing the vector. */ | |
1257 | ||
1258 | VEC(breakpoint_p) * | |
1259 | static_tracepoints_here (CORE_ADDR addr) | |
1260 | { | |
1261 | struct breakpoint *b; | |
1262 | VEC(breakpoint_p) *found = 0; | |
1263 | struct bp_location *loc; | |
1264 | ||
1265 | ALL_BREAKPOINTS (b) | |
1266 | if (b->type == bp_static_tracepoint) | |
1267 | { | |
1268 | for (loc = b->loc; loc; loc = loc->next) | |
1269 | if (loc->address == addr) | |
1270 | VEC_safe_push(breakpoint_p, found, b); | |
1271 | } | |
1272 | ||
1273 | return found; | |
1274 | } | |
1275 | ||
95a42b64 | 1276 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1277 | validate that only allowed commands are included. */ |
95a42b64 TT |
1278 | |
1279 | void | |
4a64f543 MS |
1280 | breakpoint_set_commands (struct breakpoint *b, |
1281 | struct command_line *commands) | |
95a42b64 TT |
1282 | { |
1283 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1284 | |
9add0f1b TT |
1285 | decref_counted_command_line (&b->commands); |
1286 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1287 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1288 | } |
1289 | ||
45a43567 TT |
1290 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1291 | is not the same as the "silent" that may appear in the breakpoint's | |
1292 | commands. */ | |
1293 | ||
1294 | void | |
1295 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1296 | { | |
1297 | int old_silent = b->silent; | |
1298 | ||
1299 | b->silent = silent; | |
1300 | if (old_silent != silent) | |
8d3788bd | 1301 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1302 | } |
1303 | ||
1304 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1305 | breakpoint work for any thread. */ | |
1306 | ||
1307 | void | |
1308 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1309 | { | |
1310 | int old_thread = b->thread; | |
1311 | ||
1312 | b->thread = thread; | |
1313 | if (old_thread != thread) | |
8d3788bd | 1314 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1315 | } |
1316 | ||
1317 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1318 | breakpoint work for any task. */ | |
1319 | ||
1320 | void | |
1321 | breakpoint_set_task (struct breakpoint *b, int task) | |
1322 | { | |
1323 | int old_task = b->task; | |
1324 | ||
1325 | b->task = task; | |
1326 | if (old_task != task) | |
8d3788bd | 1327 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1328 | } |
1329 | ||
95a42b64 TT |
1330 | void |
1331 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1332 | { |
9a3c8263 | 1333 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1334 | |
6f937416 | 1335 | validate_actionline (line, b); |
a7bdde9e VP |
1336 | } |
1337 | ||
95a42b64 TT |
1338 | /* A structure used to pass information through |
1339 | map_breakpoint_numbers. */ | |
1340 | ||
1341 | struct commands_info | |
1342 | { | |
1343 | /* True if the command was typed at a tty. */ | |
1344 | int from_tty; | |
86b17b60 PA |
1345 | |
1346 | /* The breakpoint range spec. */ | |
1347 | char *arg; | |
1348 | ||
95a42b64 TT |
1349 | /* Non-NULL if the body of the commands are being read from this |
1350 | already-parsed command. */ | |
1351 | struct command_line *control; | |
86b17b60 | 1352 | |
95a42b64 TT |
1353 | /* The command lines read from the user, or NULL if they have not |
1354 | yet been read. */ | |
1355 | struct counted_command_line *cmd; | |
1356 | }; | |
1357 | ||
1358 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1359 | commands_command. */ | |
1360 | ||
c906108c | 1361 | static void |
95a42b64 | 1362 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1363 | { |
9a3c8263 | 1364 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1365 | |
95a42b64 TT |
1366 | if (info->cmd == NULL) |
1367 | { | |
1368 | struct command_line *l; | |
5c44784c | 1369 | |
95a42b64 TT |
1370 | if (info->control != NULL) |
1371 | l = copy_command_lines (info->control->body_list[0]); | |
1372 | else | |
86b17b60 PA |
1373 | { |
1374 | struct cleanup *old_chain; | |
1375 | char *str; | |
c5aa993b | 1376 | |
3e43a32a MS |
1377 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1378 | "%s, one per line."), | |
86b17b60 PA |
1379 | info->arg); |
1380 | ||
1381 | old_chain = make_cleanup (xfree, str); | |
1382 | ||
1383 | l = read_command_lines (str, | |
1384 | info->from_tty, 1, | |
d77f58be | 1385 | (is_tracepoint (b) |
86b17b60 PA |
1386 | ? check_tracepoint_command : 0), |
1387 | b); | |
1388 | ||
1389 | do_cleanups (old_chain); | |
1390 | } | |
a7bdde9e | 1391 | |
95a42b64 TT |
1392 | info->cmd = alloc_counted_command_line (l); |
1393 | } | |
1394 | ||
1395 | /* If a breakpoint was on the list more than once, we don't need to | |
1396 | do anything. */ | |
1397 | if (b->commands != info->cmd) | |
1398 | { | |
1399 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1400 | incref_counted_command_line (info->cmd); | |
1401 | decref_counted_command_line (&b->commands); | |
1402 | b->commands = info->cmd; | |
8d3788bd | 1403 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1404 | } |
95a42b64 TT |
1405 | } |
1406 | ||
1407 | static void | |
4a64f543 MS |
1408 | commands_command_1 (char *arg, int from_tty, |
1409 | struct command_line *control) | |
95a42b64 TT |
1410 | { |
1411 | struct cleanup *cleanups; | |
1412 | struct commands_info info; | |
1413 | ||
1414 | info.from_tty = from_tty; | |
1415 | info.control = control; | |
1416 | info.cmd = NULL; | |
1417 | /* If we read command lines from the user, then `info' will hold an | |
1418 | extra reference to the commands that we must clean up. */ | |
1419 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1420 | ||
1421 | if (arg == NULL || !*arg) | |
1422 | { | |
86b17b60 | 1423 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1424 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1425 | breakpoint_count); | |
95a42b64 TT |
1426 | else if (breakpoint_count > 0) |
1427 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1428 | else |
1429 | { | |
1430 | /* So that we don't try to free the incoming non-NULL | |
1431 | argument in the cleanup below. Mapping breakpoint | |
1432 | numbers will fail in this case. */ | |
1433 | arg = NULL; | |
1434 | } | |
95a42b64 | 1435 | } |
9766ced4 SS |
1436 | else |
1437 | /* The command loop has some static state, so we need to preserve | |
1438 | our argument. */ | |
1439 | arg = xstrdup (arg); | |
86b17b60 PA |
1440 | |
1441 | if (arg != NULL) | |
1442 | make_cleanup (xfree, arg); | |
1443 | ||
1444 | info.arg = arg; | |
95a42b64 TT |
1445 | |
1446 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1447 | ||
1448 | if (info.cmd == NULL) | |
1449 | error (_("No breakpoints specified.")); | |
1450 | ||
1451 | do_cleanups (cleanups); | |
1452 | } | |
1453 | ||
1454 | static void | |
1455 | commands_command (char *arg, int from_tty) | |
1456 | { | |
1457 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1458 | } |
40c03ae8 EZ |
1459 | |
1460 | /* Like commands_command, but instead of reading the commands from | |
1461 | input stream, takes them from an already parsed command structure. | |
1462 | ||
1463 | This is used by cli-script.c to DTRT with breakpoint commands | |
1464 | that are part of if and while bodies. */ | |
1465 | enum command_control_type | |
1466 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1467 | { | |
95a42b64 TT |
1468 | commands_command_1 (arg, 0, cmd); |
1469 | return simple_control; | |
40c03ae8 | 1470 | } |
876fa593 JK |
1471 | |
1472 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1473 | ||
1474 | static int | |
1475 | bp_location_has_shadow (struct bp_location *bl) | |
1476 | { | |
1477 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1478 | return 0; | |
1479 | if (!bl->inserted) | |
1480 | return 0; | |
1481 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1482 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1483 | return 0; |
1484 | return 1; | |
1485 | } | |
1486 | ||
9d497a19 PA |
1487 | /* Update BUF, which is LEN bytes read from the target address |
1488 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1489 | contents. | |
1490 | ||
1491 | If READBUF is not NULL, this buffer must not overlap with the of | |
1492 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1493 | failed assertion internal error will be raised. */ | |
1494 | ||
1495 | static void | |
1496 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1497 | const gdb_byte *writebuf_org, | |
1498 | ULONGEST memaddr, LONGEST len, | |
1499 | struct bp_target_info *target_info, | |
1500 | struct gdbarch *gdbarch) | |
1501 | { | |
1502 | /* Now do full processing of the found relevant range of elements. */ | |
1503 | CORE_ADDR bp_addr = 0; | |
1504 | int bp_size = 0; | |
1505 | int bptoffset = 0; | |
1506 | ||
1507 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1508 | current_program_space->aspace, 0)) | |
1509 | { | |
1510 | /* The breakpoint is inserted in a different address space. */ | |
1511 | return; | |
1512 | } | |
1513 | ||
1514 | /* Addresses and length of the part of the breakpoint that | |
1515 | we need to copy. */ | |
1516 | bp_addr = target_info->placed_address; | |
1517 | bp_size = target_info->shadow_len; | |
1518 | ||
1519 | if (bp_addr + bp_size <= memaddr) | |
1520 | { | |
1521 | /* The breakpoint is entirely before the chunk of memory we are | |
1522 | reading. */ | |
1523 | return; | |
1524 | } | |
1525 | ||
1526 | if (bp_addr >= memaddr + len) | |
1527 | { | |
1528 | /* The breakpoint is entirely after the chunk of memory we are | |
1529 | reading. */ | |
1530 | return; | |
1531 | } | |
1532 | ||
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 | } | |
1541 | ||
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 | } | |
1547 | ||
1548 | if (readbuf != NULL) | |
1549 | { | |
1550 | /* Verify that the readbuf buffer does not overlap with the | |
1551 | shadow_contents buffer. */ | |
1552 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1553 | || readbuf >= (target_info->shadow_contents | |
1554 | + target_info->shadow_len)); | |
1555 | ||
1556 | /* Update the read buffer with this inserted breakpoint's | |
1557 | shadow. */ | |
1558 | memcpy (readbuf + bp_addr - memaddr, | |
1559 | target_info->shadow_contents + bptoffset, bp_size); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | const unsigned char *bp; | |
0d5ed153 MR |
1564 | CORE_ADDR addr = target_info->reqstd_address; |
1565 | int placed_size; | |
9d497a19 PA |
1566 | |
1567 | /* Update the shadow with what we want to write to memory. */ | |
1568 | memcpy (target_info->shadow_contents + bptoffset, | |
1569 | writebuf_org + bp_addr - memaddr, bp_size); | |
1570 | ||
1571 | /* Determine appropriate breakpoint contents and size for this | |
1572 | address. */ | |
0d5ed153 | 1573 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1574 | |
1575 | /* Update the final write buffer with this inserted | |
1576 | breakpoint's INSN. */ | |
1577 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1578 | } | |
1579 | } | |
1580 | ||
8defab1a | 1581 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1582 | by replacing any memory breakpoints with their shadowed contents. |
1583 | ||
35c63cd8 JB |
1584 | If READBUF is not NULL, this buffer must not overlap with any of |
1585 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1586 | a failed assertion internal error will be raised. | |
1587 | ||
876fa593 | 1588 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1589 | bl->address - bp_location_placed_address_before_address_max |
1590 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1591 | The range we were requested to resolve shadows for is: |
1592 | memaddr ... memaddr + len | |
1593 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1594 | memaddr + len <= (bl->address |
1595 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1596 | and: |
35df4500 | 1597 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1598 | |
8defab1a | 1599 | void |
f0ba3972 PA |
1600 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1601 | const gdb_byte *writebuf_org, | |
1602 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1603 | { |
4a64f543 MS |
1604 | /* Left boundary, right boundary and median element of our binary |
1605 | search. */ | |
876fa593 JK |
1606 | unsigned bc_l, bc_r, bc; |
1607 | ||
4a64f543 MS |
1608 | /* Find BC_L which is a leftmost element which may affect BUF |
1609 | content. It is safe to report lower value but a failure to | |
1610 | report higher one. */ | |
876fa593 JK |
1611 | |
1612 | bc_l = 0; | |
1613 | bc_r = bp_location_count; | |
1614 | while (bc_l + 1 < bc_r) | |
1615 | { | |
35df4500 | 1616 | struct bp_location *bl; |
876fa593 JK |
1617 | |
1618 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1619 | bl = bp_location[bc]; |
876fa593 | 1620 | |
4a64f543 MS |
1621 | /* Check first BL->ADDRESS will not overflow due to the added |
1622 | constant. Then advance the left boundary only if we are sure | |
1623 | the BC element can in no way affect the BUF content (MEMADDR | |
1624 | to MEMADDR + LEN range). | |
876fa593 | 1625 | |
4a64f543 MS |
1626 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1627 | offset so that we cannot miss a breakpoint with its shadow | |
1628 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1629 | |
35df4500 TJB |
1630 | if ((bl->address + bp_location_shadow_len_after_address_max |
1631 | >= bl->address) | |
1632 | && (bl->address + bp_location_shadow_len_after_address_max | |
1633 | <= memaddr)) | |
876fa593 JK |
1634 | bc_l = bc; |
1635 | else | |
1636 | bc_r = bc; | |
1637 | } | |
1638 | ||
128070bb PA |
1639 | /* Due to the binary search above, we need to make sure we pick the |
1640 | first location that's at BC_L's address. E.g., if there are | |
1641 | multiple locations at the same address, BC_L may end up pointing | |
1642 | at a duplicate location, and miss the "master"/"inserted" | |
1643 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1644 | B: | |
1645 | ||
1646 | L1@A, L2@A, L3@B, ... | |
1647 | ||
1648 | BC_L could end up pointing at location L2, while the "master" | |
1649 | location could be L1. Since the `loc->inserted' flag is only set | |
1650 | on "master" locations, we'd forget to restore the shadow of L1 | |
1651 | and L2. */ | |
1652 | while (bc_l > 0 | |
1653 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1654 | bc_l--; | |
1655 | ||
876fa593 JK |
1656 | /* Now do full processing of the found relevant range of elements. */ |
1657 | ||
1658 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1659 | { |
35df4500 | 1660 | struct bp_location *bl = bp_location[bc]; |
876fa593 | 1661 | |
35df4500 TJB |
1662 | /* bp_location array has BL->OWNER always non-NULL. */ |
1663 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1664 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1665 | bl->owner->number); |
ffce0d52 | 1666 | |
e5dd4106 | 1667 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1668 | content. */ |
1669 | ||
35df4500 TJB |
1670 | if (bl->address >= bp_location_placed_address_before_address_max |
1671 | && memaddr + len <= (bl->address | |
1672 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1673 | break; |
1674 | ||
35df4500 | 1675 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1676 | continue; |
6c95b8df | 1677 | |
9d497a19 PA |
1678 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1679 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1680 | } | |
c906108c | 1681 | } |
9d497a19 | 1682 | |
c906108c | 1683 | \f |
c5aa993b | 1684 | |
b775012e LM |
1685 | /* Return true if BPT is either a software breakpoint or a hardware |
1686 | breakpoint. */ | |
1687 | ||
1688 | int | |
1689 | is_breakpoint (const struct breakpoint *bpt) | |
1690 | { | |
1691 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1692 | || bpt->type == bp_hardware_breakpoint |
1693 | || bpt->type == bp_dprintf); | |
b775012e LM |
1694 | } |
1695 | ||
60e1c644 PA |
1696 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1697 | ||
a5606eee | 1698 | static int |
d77f58be | 1699 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1700 | { |
1701 | return (bpt->type == bp_hardware_watchpoint | |
1702 | || bpt->type == bp_read_watchpoint | |
1703 | || bpt->type == bp_access_watchpoint); | |
1704 | } | |
7270d8f2 | 1705 | |
60e1c644 PA |
1706 | /* Return true if BPT is of any watchpoint kind, hardware or |
1707 | software. */ | |
1708 | ||
3a5c3e22 | 1709 | int |
d77f58be | 1710 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1711 | { |
1712 | return (is_hardware_watchpoint (bpt) | |
1713 | || bpt->type == bp_watchpoint); | |
1714 | } | |
1715 | ||
3a5c3e22 PA |
1716 | /* Returns true if the current thread and its running state are safe |
1717 | to evaluate or update watchpoint B. Watchpoints on local | |
1718 | expressions need to be evaluated in the context of the thread that | |
1719 | was current when the watchpoint was created, and, that thread needs | |
1720 | to be stopped to be able to select the correct frame context. | |
1721 | Watchpoints on global expressions can be evaluated on any thread, | |
1722 | and in any state. It is presently left to the target allowing | |
1723 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1724 | |
1725 | static int | |
3a5c3e22 | 1726 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1727 | { |
d0d8b0c6 JK |
1728 | return (b->base.pspace == current_program_space |
1729 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1730 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1731 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1732 | } |
1733 | ||
d0fb5eae JK |
1734 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1735 | associated bp_watchpoint_scope breakpoint. */ | |
1736 | ||
1737 | static void | |
3a5c3e22 | 1738 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1739 | { |
3a5c3e22 | 1740 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1741 | |
1742 | if (b->related_breakpoint != b) | |
1743 | { | |
1744 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1745 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1746 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1747 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1748 | b->related_breakpoint = b; | |
1749 | } | |
1750 | b->disposition = disp_del_at_next_stop; | |
1751 | } | |
1752 | ||
bb9d5f81 PP |
1753 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1754 | watchpoint W. */ | |
1755 | ||
1756 | static struct value * | |
1757 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1758 | { | |
1759 | struct value *bit_val; | |
1760 | ||
1761 | if (val == NULL) | |
1762 | return NULL; | |
1763 | ||
1764 | bit_val = allocate_value (value_type (val)); | |
1765 | ||
1766 | unpack_value_bitfield (bit_val, | |
1767 | w->val_bitpos, | |
1768 | w->val_bitsize, | |
1769 | value_contents_for_printing (val), | |
1770 | value_offset (val), | |
1771 | val); | |
1772 | ||
1773 | return bit_val; | |
1774 | } | |
1775 | ||
c6d81124 PA |
1776 | /* Allocate a dummy location and add it to B, which must be a software |
1777 | watchpoint. This is required because even if a software watchpoint | |
1778 | is not watching any memory, bpstat_stop_status requires a location | |
1779 | to be able to report stops. */ | |
1780 | ||
1781 | static void | |
1782 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1783 | struct program_space *pspace) | |
1784 | { | |
1785 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1786 | ||
1787 | b->loc = allocate_bp_location (b); | |
1788 | b->loc->pspace = pspace; | |
1789 | b->loc->address = -1; | |
1790 | b->loc->length = -1; | |
1791 | } | |
1792 | ||
1793 | /* Returns true if B is a software watchpoint that is not watching any | |
1794 | memory (e.g., "watch $pc"). */ | |
1795 | ||
1796 | static int | |
1797 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1798 | { | |
1799 | return (b->type == bp_watchpoint | |
1800 | && b->loc != NULL | |
1801 | && b->loc->next == NULL | |
1802 | && b->loc->address == -1 | |
1803 | && b->loc->length == -1); | |
1804 | } | |
1805 | ||
567e1b4e JB |
1806 | /* Assuming that B is a watchpoint: |
1807 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1808 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1809 | - Evaluate the condition if there is one, and store the result |
1810 | in b->loc->cond. | |
a5606eee VP |
1811 | - Update the list of values that must be watched in B->loc. |
1812 | ||
4a64f543 MS |
1813 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1814 | nothing. If this is local watchpoint that is out of scope, delete | |
1815 | it. | |
1816 | ||
1817 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1818 | removed + inserted on each stop here. Normal breakpoints must | |
1819 | never be removed because they might be missed by a running thread | |
1820 | when debugging in non-stop mode. On the other hand, hardware | |
1821 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1822 | to each LWP since they are stored in each LWP's hardware debug | |
1823 | registers. Therefore, such LWP must be stopped first in order to | |
1824 | be able to modify its hardware watchpoints. | |
1825 | ||
1826 | Hardware watchpoints must be reset exactly once after being | |
1827 | presented to the user. It cannot be done sooner, because it would | |
1828 | reset the data used to present the watchpoint hit to the user. And | |
1829 | it must not be done later because it could display the same single | |
1830 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1831 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1832 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1833 | not user-visible - its hit is suppressed if the memory content has | |
1834 | not changed. | |
1835 | ||
1836 | The following constraints influence the location where we can reset | |
1837 | hardware watchpoints: | |
1838 | ||
1839 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1840 | called several times when GDB stops. | |
1841 | ||
1842 | [linux] | |
1843 | * Multiple hardware watchpoints can be hit at the same time, | |
1844 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1845 | hit at a time as the reason for stopping, and all the other hits | |
1846 | are presented later, one after the other, each time the user | |
1847 | requests the execution to be resumed. Execution is not resumed | |
1848 | for the threads still having pending hit event stored in | |
1849 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1850 | the inferior on the first stop the thread hit event is kept being | |
1851 | reported from its cached value by linux_nat_stopped_data_address | |
1852 | until the real thread resume happens after the watchpoint gets | |
1853 | presented and thus its LWP_INFO->STATUS gets reset. | |
1854 | ||
1855 | Therefore the hardware watchpoint hit can get safely reset on the | |
1856 | watchpoint removal from inferior. */ | |
a79d3c27 | 1857 | |
b40ce68a | 1858 | static void |
3a5c3e22 | 1859 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1860 | { |
a5606eee | 1861 | int within_current_scope; |
a5606eee | 1862 | struct frame_id saved_frame_id; |
66076460 | 1863 | int frame_saved; |
a5606eee | 1864 | |
f6bc2008 PA |
1865 | /* If this is a local watchpoint, we only want to check if the |
1866 | watchpoint frame is in scope if the current thread is the thread | |
1867 | that was used to create the watchpoint. */ | |
1868 | if (!watchpoint_in_thread_scope (b)) | |
1869 | return; | |
1870 | ||
3a5c3e22 | 1871 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1872 | return; |
1873 | ||
66076460 | 1874 | frame_saved = 0; |
a5606eee VP |
1875 | |
1876 | /* Determine if the watchpoint is within scope. */ | |
1877 | if (b->exp_valid_block == NULL) | |
1878 | within_current_scope = 1; | |
1879 | else | |
1880 | { | |
b5db5dfc UW |
1881 | struct frame_info *fi = get_current_frame (); |
1882 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1883 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1884 | ||
c9cf6e20 MG |
1885 | /* If we're at a point where the stack has been destroyed |
1886 | (e.g. in a function epilogue), unwinding may not work | |
1887 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1888 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1889 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1890 | return; |
66076460 DJ |
1891 | |
1892 | /* Save the current frame's ID so we can restore it after | |
1893 | evaluating the watchpoint expression on its own frame. */ | |
1894 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1895 | took a frame parameter, so that we didn't have to change the | |
1896 | selected frame. */ | |
1897 | frame_saved = 1; | |
1898 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1899 | ||
a5606eee VP |
1900 | fi = frame_find_by_id (b->watchpoint_frame); |
1901 | within_current_scope = (fi != NULL); | |
1902 | if (within_current_scope) | |
1903 | select_frame (fi); | |
1904 | } | |
1905 | ||
b5db5dfc UW |
1906 | /* We don't free locations. They are stored in the bp_location array |
1907 | and update_global_location_list will eventually delete them and | |
1908 | remove breakpoints if needed. */ | |
3a5c3e22 | 1909 | b->base.loc = NULL; |
b5db5dfc | 1910 | |
a5606eee VP |
1911 | if (within_current_scope && reparse) |
1912 | { | |
bbc13ae3 | 1913 | const char *s; |
d63d0675 | 1914 | |
a5606eee VP |
1915 | if (b->exp) |
1916 | { | |
1917 | xfree (b->exp); | |
1918 | b->exp = NULL; | |
1919 | } | |
d63d0675 | 1920 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1921 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1922 | /* If the meaning of expression itself changed, the old value is |
1923 | no longer relevant. We don't want to report a watchpoint hit | |
1924 | to the user when the old value and the new value may actually | |
1925 | be completely different objects. */ | |
1926 | value_free (b->val); | |
fa4727a6 DJ |
1927 | b->val = NULL; |
1928 | b->val_valid = 0; | |
60e1c644 PA |
1929 | |
1930 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1931 | expression is stored in the breakpoint object, not in the | |
1932 | locations (re)created below. */ | |
3a5c3e22 | 1933 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1934 | { |
1935 | if (b->cond_exp != NULL) | |
1936 | { | |
1937 | xfree (b->cond_exp); | |
1938 | b->cond_exp = NULL; | |
1939 | } | |
1940 | ||
3a5c3e22 | 1941 | s = b->base.cond_string; |
1bb9788d | 1942 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1943 | } |
a5606eee | 1944 | } |
a5606eee VP |
1945 | |
1946 | /* If we failed to parse the expression, for example because | |
1947 | it refers to a global variable in a not-yet-loaded shared library, | |
1948 | don't try to insert watchpoint. We don't automatically delete | |
1949 | such watchpoint, though, since failure to parse expression | |
1950 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1951 | if (!target_has_execution) |
2d134ed3 PA |
1952 | { |
1953 | /* Without execution, memory can't change. No use to try and | |
1954 | set watchpoint locations. The watchpoint will be reset when | |
1955 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1956 | if (!can_use_hw_watchpoints) |
1957 | { | |
1958 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1959 | b->base.type = bp_watchpoint; | |
1960 | else | |
638aa5a1 AB |
1961 | error (_("Can't set read/access watchpoint when " |
1962 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1963 | } |
2d134ed3 PA |
1964 | } |
1965 | else if (within_current_scope && b->exp) | |
a5606eee | 1966 | { |
0cf6dd15 | 1967 | int pc = 0; |
fa4727a6 | 1968 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1969 | struct program_space *frame_pspace; |
a5606eee | 1970 | |
3a1115a0 | 1971 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1972 | |
a5606eee VP |
1973 | /* Avoid setting b->val if it's already set. The meaning of |
1974 | b->val is 'the last value' user saw, and we should update | |
1975 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1976 | happens, the code that reports it updates b->val directly. |
1977 | We don't keep track of the memory value for masked | |
1978 | watchpoints. */ | |
3a5c3e22 | 1979 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1980 | { |
bb9d5f81 PP |
1981 | if (b->val_bitsize != 0) |
1982 | { | |
1983 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1984 | if (v != NULL) | |
1985 | release_value (v); | |
1986 | } | |
fa4727a6 DJ |
1987 | b->val = v; |
1988 | b->val_valid = 1; | |
1989 | } | |
a5606eee | 1990 | |
2d134ed3 PA |
1991 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1992 | ||
a5606eee | 1993 | /* Look at each value on the value chain. */ |
9fa40276 | 1994 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1995 | { |
1996 | /* If it's a memory location, and GDB actually needed | |
1997 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1998 | must watch it. If the first value returned is |
1999 | still lazy, that means an error occurred reading it; | |
2000 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2001 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2002 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2003 | { |
2004 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2005 | |
a5606eee VP |
2006 | /* We only watch structs and arrays if user asked |
2007 | for it explicitly, never if they just happen to | |
2008 | appear in the middle of some value chain. */ | |
fa4727a6 | 2009 | if (v == result |
a5606eee VP |
2010 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2011 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2012 | { | |
2013 | CORE_ADDR addr; | |
f486487f | 2014 | enum target_hw_bp_type type; |
a5606eee | 2015 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2016 | int bitpos = 0, bitsize = 0; |
2017 | ||
2018 | if (value_bitsize (v) != 0) | |
2019 | { | |
2020 | /* Extract the bit parameters out from the bitfield | |
2021 | sub-expression. */ | |
2022 | bitpos = value_bitpos (v); | |
2023 | bitsize = value_bitsize (v); | |
2024 | } | |
2025 | else if (v == result && b->val_bitsize != 0) | |
2026 | { | |
2027 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2028 | lvalue whose bit parameters are saved in the fields | |
2029 | VAL_BITPOS and VAL_BITSIZE. */ | |
2030 | bitpos = b->val_bitpos; | |
2031 | bitsize = b->val_bitsize; | |
2032 | } | |
a5606eee | 2033 | |
42ae5230 | 2034 | addr = value_address (v); |
bb9d5f81 PP |
2035 | if (bitsize != 0) |
2036 | { | |
2037 | /* Skip the bytes that don't contain the bitfield. */ | |
2038 | addr += bitpos / 8; | |
2039 | } | |
2040 | ||
a5606eee | 2041 | type = hw_write; |
3a5c3e22 | 2042 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2043 | type = hw_read; |
3a5c3e22 | 2044 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2045 | type = hw_access; |
3a5c3e22 PA |
2046 | |
2047 | loc = allocate_bp_location (&b->base); | |
2048 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2049 | ; |
2050 | *tmp = loc; | |
a6d9a66e | 2051 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2052 | |
2053 | loc->pspace = frame_pspace; | |
a5606eee | 2054 | loc->address = addr; |
bb9d5f81 PP |
2055 | |
2056 | if (bitsize != 0) | |
2057 | { | |
2058 | /* Just cover the bytes that make up the bitfield. */ | |
2059 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2060 | } | |
2061 | else | |
2062 | loc->length = TYPE_LENGTH (value_type (v)); | |
2063 | ||
a5606eee VP |
2064 | loc->watchpoint_type = type; |
2065 | } | |
2066 | } | |
9fa40276 TJB |
2067 | } |
2068 | ||
2069 | /* Change the type of breakpoint between hardware assisted or | |
2070 | an ordinary watchpoint depending on the hardware support | |
2071 | and free hardware slots. REPARSE is set when the inferior | |
2072 | is started. */ | |
a9634178 | 2073 | if (reparse) |
9fa40276 | 2074 | { |
e09342b5 | 2075 | int reg_cnt; |
9fa40276 TJB |
2076 | enum bp_loc_type loc_type; |
2077 | struct bp_location *bl; | |
a5606eee | 2078 | |
a9634178 | 2079 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2080 | |
2081 | if (reg_cnt) | |
9fa40276 TJB |
2082 | { |
2083 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2084 | enum bptype type; |
9fa40276 | 2085 | |
a9634178 TJB |
2086 | /* Use an exact watchpoint when there's only one memory region to be |
2087 | watched, and only one debug register is needed to watch it. */ | |
2088 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2089 | ||
9fa40276 | 2090 | /* We need to determine how many resources are already |
e09342b5 TJB |
2091 | used for all other hardware watchpoints plus this one |
2092 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2093 | this watchpoint in as well. */ |
2094 | ||
2095 | /* If this is a software watchpoint, we try to turn it | |
2096 | to a hardware one -- count resources as if B was of | |
2097 | hardware watchpoint type. */ | |
2098 | type = b->base.type; | |
2099 | if (type == bp_watchpoint) | |
2100 | type = bp_hardware_watchpoint; | |
2101 | ||
2102 | /* This watchpoint may or may not have been placed on | |
2103 | the list yet at this point (it won't be in the list | |
2104 | if we're trying to create it for the first time, | |
2105 | through watch_command), so always account for it | |
2106 | manually. */ | |
2107 | ||
2108 | /* Count resources used by all watchpoints except B. */ | |
2109 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2110 | ||
2111 | /* Add in the resources needed for B. */ | |
2112 | i += hw_watchpoint_use_count (&b->base); | |
2113 | ||
2114 | target_resources_ok | |
2115 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2116 | if (target_resources_ok <= 0) |
a9634178 | 2117 | { |
3a5c3e22 | 2118 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2119 | |
2120 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2121 | error (_("Target does not support this type of " |
2122 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2123 | else if (target_resources_ok < 0 && !sw_mode) |
2124 | error (_("There are not enough available hardware " | |
2125 | "resources for this watchpoint.")); | |
a1398e0c PA |
2126 | |
2127 | /* Downgrade to software watchpoint. */ | |
2128 | b->base.type = bp_watchpoint; | |
2129 | } | |
2130 | else | |
2131 | { | |
2132 | /* If this was a software watchpoint, we've just | |
2133 | found we have enough resources to turn it to a | |
2134 | hardware watchpoint. Otherwise, this is a | |
2135 | nop. */ | |
2136 | b->base.type = type; | |
a9634178 | 2137 | } |
9fa40276 | 2138 | } |
3a5c3e22 | 2139 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2140 | { |
2141 | if (!can_use_hw_watchpoints) | |
2142 | error (_("Can't set read/access watchpoint when " | |
2143 | "hardware watchpoints are disabled.")); | |
2144 | else | |
2145 | error (_("Expression cannot be implemented with " | |
2146 | "read/access watchpoint.")); | |
2147 | } | |
9fa40276 | 2148 | else |
3a5c3e22 | 2149 | b->base.type = bp_watchpoint; |
9fa40276 | 2150 | |
3a5c3e22 | 2151 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2152 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2153 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2154 | bl->loc_type = loc_type; |
2155 | } | |
2156 | ||
2157 | for (v = val_chain; v; v = next) | |
2158 | { | |
a5606eee VP |
2159 | next = value_next (v); |
2160 | if (v != b->val) | |
2161 | value_free (v); | |
2162 | } | |
2163 | ||
c7437ca6 PA |
2164 | /* If a software watchpoint is not watching any memory, then the |
2165 | above left it without any location set up. But, | |
2166 | bpstat_stop_status requires a location to be able to report | |
2167 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2168 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2169 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2170 | } |
2171 | else if (!within_current_scope) | |
7270d8f2 | 2172 | { |
ac74f770 MS |
2173 | printf_filtered (_("\ |
2174 | Watchpoint %d deleted because the program has left the block\n\ | |
2175 | in which its expression is valid.\n"), | |
3a5c3e22 | 2176 | b->base.number); |
d0fb5eae | 2177 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2178 | } |
a5606eee VP |
2179 | |
2180 | /* Restore the selected frame. */ | |
66076460 DJ |
2181 | if (frame_saved) |
2182 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2183 | } |
2184 | ||
a5606eee | 2185 | |
74960c60 | 2186 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2187 | inserted in the inferior. We don't differentiate the type of BL's owner |
2188 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2189 | breakpoint_ops is not defined, because in insert_bp_location, | |
2190 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2191 | static int |
35df4500 | 2192 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2193 | { |
35df4500 | 2194 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2195 | return 0; |
2196 | ||
35df4500 | 2197 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2198 | return 0; |
2199 | ||
35df4500 | 2200 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2201 | return 0; |
2202 | ||
f8eba3c6 TT |
2203 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2204 | return 0; | |
2205 | ||
56710373 PA |
2206 | /* This is set for example, when we're attached to the parent of a |
2207 | vfork, and have detached from the child. The child is running | |
2208 | free, and we expect it to do an exec or exit, at which point the | |
2209 | OS makes the parent schedulable again (and the target reports | |
2210 | that the vfork is done). Until the child is done with the shared | |
2211 | memory region, do not insert breakpoints in the parent, otherwise | |
2212 | the child could still trip on the parent's breakpoints. Since | |
2213 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2214 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2215 | return 0; |
2216 | ||
31e77af2 | 2217 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2218 | location, except if the breakpoint is a single-step breakpoint, |
2219 | and the breakpoint's thread is the thread which is stepping past | |
2220 | a breakpoint. */ | |
31e77af2 PA |
2221 | if ((bl->loc_type == bp_loc_software_breakpoint |
2222 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2223 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2224 | bl->address) |
2225 | /* The single-step breakpoint may be inserted at the location | |
2226 | we're trying to step if the instruction branches to itself. | |
2227 | However, the instruction won't be executed at all and it may | |
2228 | break the semantics of the instruction, for example, the | |
2229 | instruction is a conditional branch or updates some flags. | |
2230 | We can't fix it unless GDB is able to emulate the instruction | |
2231 | or switch to displaced stepping. */ | |
2232 | && !(bl->owner->type == bp_single_step | |
2233 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2234 | { |
2235 | if (debug_infrun) | |
2236 | { | |
2237 | fprintf_unfiltered (gdb_stdlog, | |
2238 | "infrun: skipping breakpoint: " | |
2239 | "stepping past insn at: %s\n", | |
2240 | paddress (bl->gdbarch, bl->address)); | |
2241 | } | |
2242 | return 0; | |
2243 | } | |
31e77af2 | 2244 | |
963f9c80 PA |
2245 | /* Don't insert watchpoints if we're trying to step past the |
2246 | instruction that triggered one. */ | |
2247 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2248 | && stepping_past_nonsteppable_watchpoint ()) | |
2249 | { | |
2250 | if (debug_infrun) | |
2251 | { | |
2252 | fprintf_unfiltered (gdb_stdlog, | |
2253 | "infrun: stepping past non-steppable watchpoint. " | |
2254 | "skipping watchpoint at %s:%d\n", | |
2255 | paddress (bl->gdbarch, bl->address), | |
2256 | bl->length); | |
2257 | } | |
2258 | return 0; | |
2259 | } | |
2260 | ||
74960c60 VP |
2261 | return 1; |
2262 | } | |
2263 | ||
934709f0 PW |
2264 | /* Same as should_be_inserted but does the check assuming |
2265 | that the location is not duplicated. */ | |
2266 | ||
2267 | static int | |
2268 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2269 | { | |
2270 | int result; | |
2271 | const int save_duplicate = bl->duplicate; | |
2272 | ||
2273 | bl->duplicate = 0; | |
2274 | result = should_be_inserted (bl); | |
2275 | bl->duplicate = save_duplicate; | |
2276 | return result; | |
2277 | } | |
2278 | ||
b775012e LM |
2279 | /* Parses a conditional described by an expression COND into an |
2280 | agent expression bytecode suitable for evaluation | |
2281 | by the bytecode interpreter. Return NULL if there was | |
2282 | any error during parsing. */ | |
2283 | ||
2284 | static struct agent_expr * | |
2285 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2286 | { | |
2287 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2288 | |
2289 | if (!cond) | |
2290 | return NULL; | |
2291 | ||
2292 | /* We don't want to stop processing, so catch any errors | |
2293 | that may show up. */ | |
492d29ea | 2294 | TRY |
b775012e LM |
2295 | { |
2296 | aexpr = gen_eval_for_expr (scope, cond); | |
2297 | } | |
2298 | ||
492d29ea | 2299 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2300 | { |
2301 | /* If we got here, it means the condition could not be parsed to a valid | |
2302 | bytecode expression and thus can't be evaluated on the target's side. | |
2303 | It's no use iterating through the conditions. */ | |
2304 | return NULL; | |
2305 | } | |
492d29ea | 2306 | END_CATCH |
b775012e LM |
2307 | |
2308 | /* We have a valid agent expression. */ | |
2309 | return aexpr; | |
2310 | } | |
2311 | ||
2312 | /* Based on location BL, create a list of breakpoint conditions to be | |
2313 | passed on to the target. If we have duplicated locations with different | |
2314 | conditions, we will add such conditions to the list. The idea is that the | |
2315 | target will evaluate the list of conditions and will only notify GDB when | |
2316 | one of them is true. */ | |
2317 | ||
2318 | static void | |
2319 | build_target_condition_list (struct bp_location *bl) | |
2320 | { | |
2321 | struct bp_location **locp = NULL, **loc2p; | |
2322 | int null_condition_or_parse_error = 0; | |
2323 | int modified = bl->needs_update; | |
2324 | struct bp_location *loc; | |
2325 | ||
8b4f3082 PA |
2326 | /* Release conditions left over from a previous insert. */ |
2327 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2328 | ||
b775012e LM |
2329 | /* This is only meaningful if the target is |
2330 | evaluating conditions and if the user has | |
2331 | opted for condition evaluation on the target's | |
2332 | side. */ | |
2333 | if (gdb_evaluates_breakpoint_condition_p () | |
2334 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2335 | return; | |
2336 | ||
2337 | /* Do a first pass to check for locations with no assigned | |
2338 | conditions or conditions that fail to parse to a valid agent expression | |
2339 | bytecode. If any of these happen, then it's no use to send conditions | |
2340 | to the target since this location will always trigger and generate a | |
2341 | response back to GDB. */ | |
2342 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2343 | { | |
2344 | loc = (*loc2p); | |
2345 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2346 | { | |
2347 | if (modified) | |
2348 | { | |
2349 | struct agent_expr *aexpr; | |
2350 | ||
2351 | /* Re-parse the conditions since something changed. In that | |
2352 | case we already freed the condition bytecodes (see | |
2353 | force_breakpoint_reinsertion). We just | |
2354 | need to parse the condition to bytecodes again. */ | |
2355 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2356 | loc->cond_bytecode = aexpr; | |
b775012e LM |
2357 | } |
2358 | ||
2359 | /* If we have a NULL bytecode expression, it means something | |
2360 | went wrong or we have a null condition expression. */ | |
2361 | if (!loc->cond_bytecode) | |
2362 | { | |
2363 | null_condition_or_parse_error = 1; | |
2364 | break; | |
2365 | } | |
2366 | } | |
2367 | } | |
2368 | ||
2369 | /* If any of these happened, it means we will have to evaluate the conditions | |
2370 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2371 | for all the other duplicate locations, thus we free all of them here. | |
2372 | ||
2373 | This is so we have a finer control over which locations' conditions are | |
2374 | being evaluated by GDB or the remote stub. */ | |
2375 | if (null_condition_or_parse_error) | |
2376 | { | |
2377 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2378 | { | |
2379 | loc = (*loc2p); | |
2380 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2381 | { | |
2382 | /* Only go as far as the first NULL bytecode is | |
2383 | located. */ | |
2384 | if (!loc->cond_bytecode) | |
2385 | return; | |
2386 | ||
2387 | free_agent_expr (loc->cond_bytecode); | |
2388 | loc->cond_bytecode = NULL; | |
2389 | } | |
2390 | } | |
2391 | } | |
2392 | ||
2393 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2394 | for this location's address. */ | |
2395 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2396 | { | |
2397 | loc = (*loc2p); | |
2398 | if (loc->cond | |
2399 | && is_breakpoint (loc->owner) | |
2400 | && loc->pspace->num == bl->pspace->num | |
2401 | && loc->owner->enable_state == bp_enabled | |
2402 | && loc->enabled) | |
2403 | /* Add the condition to the vector. This will be used later to send the | |
2404 | conditions to the target. */ | |
2405 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2406 | loc->cond_bytecode); | |
2407 | } | |
2408 | ||
2409 | return; | |
2410 | } | |
2411 | ||
d3ce09f5 SS |
2412 | /* Parses a command described by string CMD into an agent expression |
2413 | bytecode suitable for evaluation by the bytecode interpreter. | |
2414 | Return NULL if there was any error during parsing. */ | |
2415 | ||
2416 | static struct agent_expr * | |
2417 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2418 | { | |
2419 | struct cleanup *old_cleanups = 0; | |
2420 | struct expression *expr, **argvec; | |
2421 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2422 | const char *cmdrest; |
2423 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2424 | struct format_piece *fpieces; |
2425 | int nargs; | |
2426 | struct gdbarch *gdbarch = get_current_arch (); | |
2427 | ||
2428 | if (!cmd) | |
2429 | return NULL; | |
2430 | ||
2431 | cmdrest = cmd; | |
2432 | ||
2433 | if (*cmdrest == ',') | |
2434 | ++cmdrest; | |
bbc13ae3 | 2435 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2436 | |
2437 | if (*cmdrest++ != '"') | |
2438 | error (_("No format string following the location")); | |
2439 | ||
2440 | format_start = cmdrest; | |
2441 | ||
2442 | fpieces = parse_format_string (&cmdrest); | |
2443 | ||
2444 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2445 | ||
2446 | format_end = cmdrest; | |
2447 | ||
2448 | if (*cmdrest++ != '"') | |
2449 | error (_("Bad format string, non-terminated '\"'.")); | |
2450 | ||
bbc13ae3 | 2451 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2452 | |
2453 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2454 | error (_("Invalid argument syntax")); | |
2455 | ||
2456 | if (*cmdrest == ',') | |
2457 | cmdrest++; | |
bbc13ae3 | 2458 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2459 | |
2460 | /* For each argument, make an expression. */ | |
2461 | ||
2462 | argvec = (struct expression **) alloca (strlen (cmd) | |
2463 | * sizeof (struct expression *)); | |
2464 | ||
2465 | nargs = 0; | |
2466 | while (*cmdrest != '\0') | |
2467 | { | |
bbc13ae3 | 2468 | const char *cmd1; |
d3ce09f5 SS |
2469 | |
2470 | cmd1 = cmdrest; | |
2471 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2472 | argvec[nargs++] = expr; | |
2473 | cmdrest = cmd1; | |
2474 | if (*cmdrest == ',') | |
2475 | ++cmdrest; | |
2476 | } | |
2477 | ||
2478 | /* We don't want to stop processing, so catch any errors | |
2479 | that may show up. */ | |
492d29ea | 2480 | TRY |
d3ce09f5 SS |
2481 | { |
2482 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2483 | format_start, format_end - format_start, | |
2484 | fpieces, nargs, argvec); | |
2485 | } | |
492d29ea | 2486 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2487 | { |
2488 | /* If we got here, it means the command could not be parsed to a valid | |
2489 | bytecode expression and thus can't be evaluated on the target's side. | |
2490 | It's no use iterating through the other commands. */ | |
492d29ea | 2491 | aexpr = NULL; |
d3ce09f5 | 2492 | } |
492d29ea PA |
2493 | END_CATCH |
2494 | ||
2495 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2496 | |
d3ce09f5 SS |
2497 | /* We have a valid agent expression, return it. */ |
2498 | return aexpr; | |
2499 | } | |
2500 | ||
2501 | /* Based on location BL, create a list of breakpoint commands to be | |
2502 | passed on to the target. If we have duplicated locations with | |
2503 | different commands, we will add any such to the list. */ | |
2504 | ||
2505 | static void | |
2506 | build_target_command_list (struct bp_location *bl) | |
2507 | { | |
2508 | struct bp_location **locp = NULL, **loc2p; | |
2509 | int null_command_or_parse_error = 0; | |
2510 | int modified = bl->needs_update; | |
2511 | struct bp_location *loc; | |
2512 | ||
8b4f3082 PA |
2513 | /* Release commands left over from a previous insert. */ |
2514 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2515 | ||
41fac0cf | 2516 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2517 | return; |
2518 | ||
41fac0cf PA |
2519 | /* For now, limit to agent-style dprintf breakpoints. */ |
2520 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2521 | return; |
2522 | ||
41fac0cf PA |
2523 | /* For now, if we have any duplicate location that isn't a dprintf, |
2524 | don't install the target-side commands, as that would make the | |
2525 | breakpoint not be reported to the core, and we'd lose | |
2526 | control. */ | |
2527 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2528 | { | |
2529 | loc = (*loc2p); | |
2530 | if (is_breakpoint (loc->owner) | |
2531 | && loc->pspace->num == bl->pspace->num | |
2532 | && loc->owner->type != bp_dprintf) | |
2533 | return; | |
2534 | } | |
2535 | ||
d3ce09f5 SS |
2536 | /* Do a first pass to check for locations with no assigned |
2537 | conditions or conditions that fail to parse to a valid agent expression | |
2538 | bytecode. If any of these happen, then it's no use to send conditions | |
2539 | to the target since this location will always trigger and generate a | |
2540 | response back to GDB. */ | |
2541 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2542 | { | |
2543 | loc = (*loc2p); | |
2544 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2545 | { | |
2546 | if (modified) | |
2547 | { | |
2548 | struct agent_expr *aexpr; | |
2549 | ||
2550 | /* Re-parse the commands since something changed. In that | |
2551 | case we already freed the command bytecodes (see | |
2552 | force_breakpoint_reinsertion). We just | |
2553 | need to parse the command to bytecodes again. */ | |
2554 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2555 | loc->owner->extra_string); | |
2556 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2557 | } |
2558 | ||
2559 | /* If we have a NULL bytecode expression, it means something | |
2560 | went wrong or we have a null command expression. */ | |
2561 | if (!loc->cmd_bytecode) | |
2562 | { | |
2563 | null_command_or_parse_error = 1; | |
2564 | break; | |
2565 | } | |
2566 | } | |
2567 | } | |
2568 | ||
2569 | /* If anything failed, then we're not doing target-side commands, | |
2570 | and so clean up. */ | |
2571 | if (null_command_or_parse_error) | |
2572 | { | |
2573 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2574 | { | |
2575 | loc = (*loc2p); | |
2576 | if (is_breakpoint (loc->owner) | |
2577 | && loc->pspace->num == bl->pspace->num) | |
2578 | { | |
2579 | /* Only go as far as the first NULL bytecode is | |
2580 | located. */ | |
40fb6c5e | 2581 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2582 | return; |
2583 | ||
40fb6c5e HZ |
2584 | free_agent_expr (loc->cmd_bytecode); |
2585 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2586 | } |
2587 | } | |
2588 | } | |
2589 | ||
2590 | /* No NULL commands or failed bytecode generation. Build a command list | |
2591 | for this location's address. */ | |
2592 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2593 | { | |
2594 | loc = (*loc2p); | |
2595 | if (loc->owner->extra_string | |
2596 | && is_breakpoint (loc->owner) | |
2597 | && loc->pspace->num == bl->pspace->num | |
2598 | && loc->owner->enable_state == bp_enabled | |
2599 | && loc->enabled) | |
2600 | /* Add the command to the vector. This will be used later | |
2601 | to send the commands to the target. */ | |
2602 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2603 | loc->cmd_bytecode); | |
2604 | } | |
2605 | ||
2606 | bl->target_info.persist = 0; | |
2607 | /* Maybe flag this location as persistent. */ | |
2608 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2609 | bl->target_info.persist = 1; | |
2610 | } | |
2611 | ||
35df4500 TJB |
2612 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2613 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2614 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2615 | Returns 0 for success, 1 if the bp_location type is not supported or |
2616 | -1 for failure. | |
879bfdc2 | 2617 | |
4a64f543 MS |
2618 | NOTE drow/2003-09-09: This routine could be broken down to an |
2619 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2620 | static int |
35df4500 | 2621 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2622 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2623 | int *disabled_breaks, |
dd61ec5c MW |
2624 | int *hw_breakpoint_error, |
2625 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2626 | { |
0000e5cc PA |
2627 | enum errors bp_err = GDB_NO_ERROR; |
2628 | const char *bp_err_message = NULL; | |
879bfdc2 | 2629 | |
b775012e | 2630 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2631 | return 0; |
2632 | ||
35c63cd8 JB |
2633 | /* Note we don't initialize bl->target_info, as that wipes out |
2634 | the breakpoint location's shadow_contents if the breakpoint | |
2635 | is still inserted at that location. This in turn breaks | |
2636 | target_read_memory which depends on these buffers when | |
2637 | a memory read is requested at the breakpoint location: | |
2638 | Once the target_info has been wiped, we fail to see that | |
2639 | we have a breakpoint inserted at that address and thus | |
2640 | read the breakpoint instead of returning the data saved in | |
2641 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2642 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2643 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2644 | bl->target_info.length = bl->length; |
8181d85f | 2645 | |
b775012e LM |
2646 | /* When working with target-side conditions, we must pass all the conditions |
2647 | for the same breakpoint address down to the target since GDB will not | |
2648 | insert those locations. With a list of breakpoint conditions, the target | |
2649 | can decide when to stop and notify GDB. */ | |
2650 | ||
2651 | if (is_breakpoint (bl->owner)) | |
2652 | { | |
2653 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2654 | build_target_command_list (bl); |
2655 | /* Reset the modification marker. */ | |
b775012e LM |
2656 | bl->needs_update = 0; |
2657 | } | |
2658 | ||
35df4500 TJB |
2659 | if (bl->loc_type == bp_loc_software_breakpoint |
2660 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2661 | { |
35df4500 | 2662 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2663 | { |
2664 | /* If the explicitly specified breakpoint type | |
2665 | is not hardware breakpoint, check the memory map to see | |
2666 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2667 | |
765dc015 VP |
2668 | Two important cases are: |
2669 | - location type is not hardware breakpoint, memory | |
2670 | is readonly. We change the type of the location to | |
2671 | hardware breakpoint. | |
4a64f543 MS |
2672 | - location type is hardware breakpoint, memory is |
2673 | read-write. This means we've previously made the | |
2674 | location hardware one, but then the memory map changed, | |
2675 | so we undo. | |
765dc015 | 2676 | |
4a64f543 MS |
2677 | When breakpoints are removed, remove_breakpoints will use |
2678 | location types we've just set here, the only possible | |
2679 | problem is that memory map has changed during running | |
2680 | program, but it's not going to work anyway with current | |
2681 | gdb. */ | |
765dc015 | 2682 | struct mem_region *mr |
0d5ed153 | 2683 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2684 | |
2685 | if (mr) | |
2686 | { | |
2687 | if (automatic_hardware_breakpoints) | |
2688 | { | |
765dc015 VP |
2689 | enum bp_loc_type new_type; |
2690 | ||
2691 | if (mr->attrib.mode != MEM_RW) | |
2692 | new_type = bp_loc_hardware_breakpoint; | |
2693 | else | |
2694 | new_type = bp_loc_software_breakpoint; | |
2695 | ||
35df4500 | 2696 | if (new_type != bl->loc_type) |
765dc015 VP |
2697 | { |
2698 | static int said = 0; | |
cc59ec59 | 2699 | |
35df4500 | 2700 | bl->loc_type = new_type; |
765dc015 VP |
2701 | if (!said) |
2702 | { | |
3e43a32a MS |
2703 | fprintf_filtered (gdb_stdout, |
2704 | _("Note: automatically using " | |
2705 | "hardware breakpoints for " | |
2706 | "read-only addresses.\n")); | |
765dc015 VP |
2707 | said = 1; |
2708 | } | |
2709 | } | |
2710 | } | |
35df4500 | 2711 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2712 | && mr->attrib.mode != MEM_RW) |
2713 | { | |
2714 | fprintf_unfiltered (tmp_error_stream, | |
2715 | _("Cannot insert breakpoint %d.\n" | |
2716 | "Cannot set software breakpoint " | |
2717 | "at read-only address %s\n"), | |
2718 | bl->owner->number, | |
2719 | paddress (bl->gdbarch, bl->address)); | |
2720 | return 1; | |
2721 | } | |
765dc015 VP |
2722 | } |
2723 | } | |
2724 | ||
879bfdc2 DJ |
2725 | /* First check to see if we have to handle an overlay. */ |
2726 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2727 | || bl->section == NULL |
2728 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2729 | { |
2730 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2731 | TRY |
dd61ec5c | 2732 | { |
0000e5cc PA |
2733 | int val; |
2734 | ||
dd61ec5c | 2735 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2736 | if (val) |
2737 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2738 | } |
492d29ea | 2739 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2740 | { |
0000e5cc PA |
2741 | bp_err = e.error; |
2742 | bp_err_message = e.message; | |
dd61ec5c | 2743 | } |
492d29ea | 2744 | END_CATCH |
879bfdc2 DJ |
2745 | } |
2746 | else | |
2747 | { | |
4a64f543 | 2748 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2749 | Shall we set a breakpoint at the LMA? */ |
2750 | if (!overlay_events_enabled) | |
2751 | { | |
2752 | /* Yes -- overlay event support is not active, | |
2753 | so we must try to set a breakpoint at the LMA. | |
2754 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2755 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2756 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2757 | bl->owner->number); |
879bfdc2 DJ |
2758 | else |
2759 | { | |
35df4500 TJB |
2760 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2761 | bl->section); | |
879bfdc2 | 2762 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2763 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2764 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2765 | |
2766 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2767 | TRY |
0000e5cc PA |
2768 | { |
2769 | int val; | |
2770 | ||
2771 | val = target_insert_breakpoint (bl->gdbarch, | |
2772 | &bl->overlay_target_info); | |
2773 | if (val) | |
2774 | bp_err = GENERIC_ERROR; | |
2775 | } | |
492d29ea | 2776 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2777 | { |
2778 | bp_err = e.error; | |
2779 | bp_err_message = e.message; | |
2780 | } | |
492d29ea | 2781 | END_CATCH |
0000e5cc PA |
2782 | |
2783 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2784 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2785 | "Overlay breakpoint %d " |
2786 | "failed: in ROM?\n", | |
35df4500 | 2787 | bl->owner->number); |
879bfdc2 DJ |
2788 | } |
2789 | } | |
2790 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2791 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2792 | { |
2793 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2794 | TRY |
dd61ec5c | 2795 | { |
0000e5cc PA |
2796 | int val; |
2797 | ||
dd61ec5c | 2798 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2799 | if (val) |
2800 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2801 | } |
492d29ea | 2802 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2803 | { |
0000e5cc PA |
2804 | bp_err = e.error; |
2805 | bp_err_message = e.message; | |
dd61ec5c | 2806 | } |
492d29ea | 2807 | END_CATCH |
879bfdc2 DJ |
2808 | } |
2809 | else | |
2810 | { | |
2811 | /* No. This breakpoint will not be inserted. | |
2812 | No error, but do not mark the bp as 'inserted'. */ | |
2813 | return 0; | |
2814 | } | |
2815 | } | |
2816 | ||
0000e5cc | 2817 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2818 | { |
2819 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2820 | |
2821 | /* In some cases, we might not be able to insert a | |
2822 | breakpoint in a shared library that has already been | |
2823 | removed, but we have not yet processed the shlib unload | |
2824 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2825 | breakpoint insertion themselves can't tell why the |
2826 | breakpoint insertion failed (e.g., the remote target | |
2827 | doesn't define error codes), so we must treat generic | |
2828 | errors as memory errors. */ | |
0000e5cc | 2829 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2830 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2831 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2832 | || shared_objfile_contains_address_p (bl->pspace, |
2833 | bl->address))) | |
879bfdc2 | 2834 | { |
4a64f543 | 2835 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2836 | bl->shlib_disabled = 1; |
8d3788bd | 2837 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2838 | if (!*disabled_breaks) |
2839 | { | |
2840 | fprintf_unfiltered (tmp_error_stream, | |
2841 | "Cannot insert breakpoint %d.\n", | |
2842 | bl->owner->number); | |
2843 | fprintf_unfiltered (tmp_error_stream, | |
2844 | "Temporarily disabling shared " | |
2845 | "library breakpoints:\n"); | |
2846 | } | |
2847 | *disabled_breaks = 1; | |
879bfdc2 | 2848 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2849 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2850 | return 0; |
879bfdc2 DJ |
2851 | } |
2852 | else | |
879bfdc2 | 2853 | { |
35df4500 | 2854 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2855 | { |
0000e5cc PA |
2856 | *hw_breakpoint_error = 1; |
2857 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2858 | fprintf_unfiltered (tmp_error_stream, |
2859 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2860 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2861 | if (bp_err_message != NULL) | |
2862 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2863 | } |
2864 | else | |
2865 | { | |
0000e5cc PA |
2866 | if (bp_err_message == NULL) |
2867 | { | |
2868 | char *message | |
2869 | = memory_error_message (TARGET_XFER_E_IO, | |
2870 | bl->gdbarch, bl->address); | |
2871 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2872 | ||
2873 | fprintf_unfiltered (tmp_error_stream, | |
2874 | "Cannot insert breakpoint %d.\n" | |
2875 | "%s\n", | |
2876 | bl->owner->number, message); | |
2877 | do_cleanups (old_chain); | |
2878 | } | |
2879 | else | |
2880 | { | |
2881 | fprintf_unfiltered (tmp_error_stream, | |
2882 | "Cannot insert breakpoint %d: %s\n", | |
2883 | bl->owner->number, | |
2884 | bp_err_message); | |
2885 | } | |
879bfdc2 | 2886 | } |
0000e5cc | 2887 | return 1; |
879bfdc2 DJ |
2888 | |
2889 | } | |
2890 | } | |
2891 | else | |
35df4500 | 2892 | bl->inserted = 1; |
879bfdc2 | 2893 | |
0000e5cc | 2894 | return 0; |
879bfdc2 DJ |
2895 | } |
2896 | ||
35df4500 | 2897 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2898 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2899 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2900 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2901 | { |
0000e5cc PA |
2902 | int val; |
2903 | ||
77b06cd7 TJB |
2904 | gdb_assert (bl->owner->ops != NULL |
2905 | && bl->owner->ops->insert_location != NULL); | |
2906 | ||
2907 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2908 | |
2909 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2910 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2911 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2912 | { |
2913 | struct bp_location *loc, **loc_temp; | |
2914 | ||
2915 | /* But don't try to insert it, if there's already another | |
2916 | hw_access location that would be considered a duplicate | |
2917 | of this one. */ | |
2918 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2919 | if (loc != bl |
85d721b8 | 2920 | && loc->watchpoint_type == hw_access |
35df4500 | 2921 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2922 | { |
35df4500 TJB |
2923 | bl->duplicate = 1; |
2924 | bl->inserted = 1; | |
2925 | bl->target_info = loc->target_info; | |
2926 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2927 | val = 0; |
2928 | break; | |
2929 | } | |
2930 | ||
2931 | if (val == 1) | |
2932 | { | |
77b06cd7 TJB |
2933 | bl->watchpoint_type = hw_access; |
2934 | val = bl->owner->ops->insert_location (bl); | |
2935 | ||
2936 | if (val) | |
2937 | /* Back to the original value. */ | |
2938 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2939 | } |
2940 | } | |
2941 | ||
35df4500 | 2942 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2943 | } |
2944 | ||
35df4500 | 2945 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2946 | { |
0000e5cc PA |
2947 | int val; |
2948 | ||
77b06cd7 TJB |
2949 | gdb_assert (bl->owner->ops != NULL |
2950 | && bl->owner->ops->insert_location != NULL); | |
2951 | ||
2952 | val = bl->owner->ops->insert_location (bl); | |
2953 | if (val) | |
2954 | { | |
2955 | bl->owner->enable_state = bp_disabled; | |
2956 | ||
2957 | if (val == 1) | |
2958 | warning (_("\ | |
2959 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2960 | of catchpoint."), bl->owner->number); | |
2961 | else | |
2962 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2963 | } | |
2964 | ||
2965 | bl->inserted = (val == 0); | |
1640b821 DJ |
2966 | |
2967 | /* We've already printed an error message if there was a problem | |
2968 | inserting this catchpoint, and we've disabled the catchpoint, | |
2969 | so just return success. */ | |
2970 | return 0; | |
879bfdc2 DJ |
2971 | } |
2972 | ||
2973 | return 0; | |
2974 | } | |
2975 | ||
6c95b8df PA |
2976 | /* This function is called when program space PSPACE is about to be |
2977 | deleted. It takes care of updating breakpoints to not reference | |
2978 | PSPACE anymore. */ | |
2979 | ||
2980 | void | |
2981 | breakpoint_program_space_exit (struct program_space *pspace) | |
2982 | { | |
2983 | struct breakpoint *b, *b_temp; | |
876fa593 | 2984 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2985 | |
2986 | /* Remove any breakpoint that was set through this program space. */ | |
2987 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2988 | { | |
2989 | if (b->pspace == pspace) | |
2990 | delete_breakpoint (b); | |
2991 | } | |
2992 | ||
2993 | /* Breakpoints set through other program spaces could have locations | |
2994 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2995 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2996 | { |
2997 | struct bp_location *tmp; | |
2998 | ||
2999 | if (loc->pspace == pspace) | |
3000 | { | |
2bdf28a0 | 3001 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3002 | if (loc->owner->loc == loc) |
3003 | loc->owner->loc = loc->next; | |
3004 | else | |
3005 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3006 | if (tmp->next == loc) | |
3007 | { | |
3008 | tmp->next = loc->next; | |
3009 | break; | |
3010 | } | |
3011 | } | |
3012 | } | |
3013 | ||
3014 | /* Now update the global location list to permanently delete the | |
3015 | removed locations above. */ | |
44702360 | 3016 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3017 | } |
3018 | ||
74960c60 VP |
3019 | /* Make sure all breakpoints are inserted in inferior. |
3020 | Throws exception on any error. | |
3021 | A breakpoint that is already inserted won't be inserted | |
3022 | again, so calling this function twice is safe. */ | |
3023 | void | |
3024 | insert_breakpoints (void) | |
3025 | { | |
3026 | struct breakpoint *bpt; | |
3027 | ||
3028 | ALL_BREAKPOINTS (bpt) | |
3029 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3030 | { |
3031 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3032 | ||
3033 | update_watchpoint (w, 0 /* don't reparse. */); | |
3034 | } | |
74960c60 | 3035 | |
04086b45 PA |
3036 | /* Updating watchpoints creates new locations, so update the global |
3037 | location list. Explicitly tell ugll to insert locations and | |
3038 | ignore breakpoints_always_inserted_mode. */ | |
3039 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3040 | } |
3041 | ||
20388dd6 YQ |
3042 | /* Invoke CALLBACK for each of bp_location. */ |
3043 | ||
3044 | void | |
3045 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3046 | { | |
3047 | struct bp_location *loc, **loc_tmp; | |
3048 | ||
3049 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3050 | { | |
3051 | callback (loc, NULL); | |
3052 | } | |
3053 | } | |
3054 | ||
b775012e LM |
3055 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3056 | target. It is the case with deleting and disabling of breakpoints when using | |
3057 | always-inserted mode. */ | |
3058 | ||
3059 | static void | |
3060 | update_inserted_breakpoint_locations (void) | |
3061 | { | |
3062 | struct bp_location *bl, **blp_tmp; | |
3063 | int error_flag = 0; | |
3064 | int val = 0; | |
3065 | int disabled_breaks = 0; | |
3066 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3067 | int hw_bp_details_reported = 0; |
b775012e LM |
3068 | |
3069 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3070 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3071 | ||
3072 | /* Explicitly mark the warning -- this will only be printed if | |
3073 | there was an error. */ | |
3074 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3075 | ||
3076 | save_current_space_and_thread (); | |
3077 | ||
3078 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3079 | { | |
3080 | /* We only want to update software breakpoints and hardware | |
3081 | breakpoints. */ | |
3082 | if (!is_breakpoint (bl->owner)) | |
3083 | continue; | |
3084 | ||
3085 | /* We only want to update locations that are already inserted | |
3086 | and need updating. This is to avoid unwanted insertion during | |
3087 | deletion of breakpoints. */ | |
3088 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3089 | continue; | |
3090 | ||
3091 | switch_to_program_space_and_thread (bl->pspace); | |
3092 | ||
3093 | /* For targets that support global breakpoints, there's no need | |
3094 | to select an inferior to insert breakpoint to. In fact, even | |
3095 | if we aren't attached to any process yet, we should still | |
3096 | insert breakpoints. */ | |
f5656ead | 3097 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3098 | && ptid_equal (inferior_ptid, null_ptid)) |
3099 | continue; | |
3100 | ||
3101 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3102 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3103 | if (val) |
3104 | error_flag = val; | |
3105 | } | |
3106 | ||
3107 | if (error_flag) | |
3108 | { | |
3109 | target_terminal_ours_for_output (); | |
3110 | error_stream (tmp_error_stream); | |
3111 | } | |
3112 | ||
3113 | do_cleanups (cleanups); | |
3114 | } | |
3115 | ||
c30eee59 | 3116 | /* Used when starting or continuing the program. */ |
c906108c | 3117 | |
74960c60 VP |
3118 | static void |
3119 | insert_breakpoint_locations (void) | |
c906108c | 3120 | { |
a5606eee | 3121 | struct breakpoint *bpt; |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3123 | int error_flag = 0; |
c906108c | 3124 | int val = 0; |
3fbb6ffa | 3125 | int disabled_breaks = 0; |
81d0cc19 | 3126 | int hw_breakpoint_error = 0; |
dd61ec5c | 3127 | int hw_bp_error_explained_already = 0; |
c906108c | 3128 | |
81d0cc19 | 3129 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3130 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3131 | |
81d0cc19 GS |
3132 | /* Explicitly mark the warning -- this will only be printed if |
3133 | there was an error. */ | |
3134 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3135 | |
3136 | save_current_space_and_thread (); | |
3137 | ||
35df4500 | 3138 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3139 | { |
b775012e | 3140 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3141 | continue; |
3142 | ||
4a64f543 MS |
3143 | /* There is no point inserting thread-specific breakpoints if |
3144 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3145 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3146 | if (bl->owner->thread != -1 |
5d5658a1 | 3147 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3148 | continue; |
3149 | ||
35df4500 | 3150 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3151 | |
3152 | /* For targets that support global breakpoints, there's no need | |
3153 | to select an inferior to insert breakpoint to. In fact, even | |
3154 | if we aren't attached to any process yet, we should still | |
3155 | insert breakpoints. */ | |
f5656ead | 3156 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3157 | && ptid_equal (inferior_ptid, null_ptid)) |
3158 | continue; | |
3159 | ||
3fbb6ffa | 3160 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3161 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3162 | if (val) |
eacd795a | 3163 | error_flag = val; |
879bfdc2 | 3164 | } |
c906108c | 3165 | |
4a64f543 MS |
3166 | /* If we failed to insert all locations of a watchpoint, remove |
3167 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3168 | ALL_BREAKPOINTS (bpt) |
3169 | { | |
3170 | int some_failed = 0; | |
3171 | struct bp_location *loc; | |
3172 | ||
3173 | if (!is_hardware_watchpoint (bpt)) | |
3174 | continue; | |
3175 | ||
d6b74ac4 | 3176 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3177 | continue; |
74960c60 VP |
3178 | |
3179 | if (bpt->disposition == disp_del_at_next_stop) | |
3180 | continue; | |
a5606eee VP |
3181 | |
3182 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3183 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3184 | { |
3185 | some_failed = 1; | |
3186 | break; | |
3187 | } | |
3188 | if (some_failed) | |
3189 | { | |
3190 | for (loc = bpt->loc; loc; loc = loc->next) | |
3191 | if (loc->inserted) | |
834c0d03 | 3192 | remove_breakpoint (loc); |
a5606eee VP |
3193 | |
3194 | hw_breakpoint_error = 1; | |
3195 | fprintf_unfiltered (tmp_error_stream, | |
3196 | "Could not insert hardware watchpoint %d.\n", | |
3197 | bpt->number); | |
eacd795a | 3198 | error_flag = -1; |
a5606eee VP |
3199 | } |
3200 | } | |
3201 | ||
eacd795a | 3202 | if (error_flag) |
81d0cc19 GS |
3203 | { |
3204 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3205 | message about possibly exhausted resources. */ | |
dd61ec5c | 3206 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3207 | { |
c6510018 MS |
3208 | fprintf_unfiltered (tmp_error_stream, |
3209 | "Could not insert hardware breakpoints:\n\ | |
3210 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3211 | } |
81d0cc19 GS |
3212 | target_terminal_ours_for_output (); |
3213 | error_stream (tmp_error_stream); | |
3214 | } | |
f7545552 TT |
3215 | |
3216 | do_cleanups (cleanups); | |
c906108c SS |
3217 | } |
3218 | ||
c30eee59 TJB |
3219 | /* Used when the program stops. |
3220 | Returns zero if successful, or non-zero if there was a problem | |
3221 | removing a breakpoint location. */ | |
3222 | ||
c906108c | 3223 | int |
fba45db2 | 3224 | remove_breakpoints (void) |
c906108c | 3225 | { |
35df4500 | 3226 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3227 | int val = 0; |
c906108c | 3228 | |
35df4500 | 3229 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3230 | { |
1e4d1764 | 3231 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3232 | val |= remove_breakpoint (bl); |
c5aa993b | 3233 | } |
3a1bae8e | 3234 | return val; |
c906108c SS |
3235 | } |
3236 | ||
49fa26b0 PA |
3237 | /* When a thread exits, remove breakpoints that are related to |
3238 | that thread. */ | |
3239 | ||
3240 | static void | |
3241 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3242 | { | |
3243 | struct breakpoint *b, *b_tmp; | |
3244 | ||
3245 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3246 | { | |
5d5658a1 | 3247 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3248 | { |
3249 | b->disposition = disp_del_at_next_stop; | |
3250 | ||
3251 | printf_filtered (_("\ | |
43792cf0 PA |
3252 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3253 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3254 | |
3255 | /* Hide it from the user. */ | |
3256 | b->number = 0; | |
3257 | } | |
3258 | } | |
3259 | } | |
3260 | ||
6c95b8df PA |
3261 | /* Remove breakpoints of process PID. */ |
3262 | ||
3263 | int | |
3264 | remove_breakpoints_pid (int pid) | |
3265 | { | |
35df4500 | 3266 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3267 | int val; |
3268 | struct inferior *inf = find_inferior_pid (pid); | |
3269 | ||
35df4500 | 3270 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3271 | { |
35df4500 | 3272 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3273 | continue; |
3274 | ||
fc126975 | 3275 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3276 | { |
834c0d03 | 3277 | val = remove_breakpoint (bl); |
6c95b8df PA |
3278 | if (val != 0) |
3279 | return val; | |
3280 | } | |
3281 | } | |
3282 | return 0; | |
3283 | } | |
3284 | ||
c906108c | 3285 | int |
fba45db2 | 3286 | reattach_breakpoints (int pid) |
c906108c | 3287 | { |
6c95b8df | 3288 | struct cleanup *old_chain; |
35df4500 | 3289 | struct bp_location *bl, **blp_tmp; |
c906108c | 3290 | int val; |
86b887df | 3291 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3292 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3293 | struct inferior *inf; |
3294 | struct thread_info *tp; | |
3295 | ||
3296 | tp = any_live_thread_of_process (pid); | |
3297 | if (tp == NULL) | |
3298 | return 1; | |
3299 | ||
3300 | inf = find_inferior_pid (pid); | |
3301 | old_chain = save_inferior_ptid (); | |
3302 | ||
3303 | inferior_ptid = tp->ptid; | |
a4954f26 | 3304 | |
86b887df | 3305 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3306 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3307 | |
35df4500 | 3308 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3309 | { |
35df4500 | 3310 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3311 | continue; |
3312 | ||
35df4500 | 3313 | if (bl->inserted) |
c5aa993b | 3314 | { |
35df4500 | 3315 | bl->inserted = 0; |
dd61ec5c | 3316 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3317 | if (val != 0) |
3318 | { | |
ce696e05 | 3319 | do_cleanups (old_chain); |
c5aa993b JM |
3320 | return val; |
3321 | } | |
3322 | } | |
3323 | } | |
ce696e05 | 3324 | do_cleanups (old_chain); |
c906108c SS |
3325 | return 0; |
3326 | } | |
3327 | ||
e58b0e63 PA |
3328 | static int internal_breakpoint_number = -1; |
3329 | ||
84f4c1fe PM |
3330 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3331 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3332 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3333 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3334 | breakpoint_count and that value incremented. Internal breakpoints |
3335 | do not set the internal var bpnum. */ | |
3336 | static void | |
3337 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3338 | { | |
3339 | if (internal) | |
3340 | b->number = internal_breakpoint_number--; | |
3341 | else | |
3342 | { | |
3343 | set_breakpoint_count (breakpoint_count + 1); | |
3344 | b->number = breakpoint_count; | |
3345 | } | |
3346 | } | |
3347 | ||
e62c965a | 3348 | static struct breakpoint * |
a6d9a66e | 3349 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3350 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3351 | const struct breakpoint_ops *ops) |
e62c965a | 3352 | { |
e62c965a PP |
3353 | struct symtab_and_line sal; |
3354 | struct breakpoint *b; | |
3355 | ||
4a64f543 | 3356 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3357 | |
3358 | sal.pc = address; | |
3359 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3360 | sal.pspace = current_program_space; |
e62c965a | 3361 | |
06edf0c0 | 3362 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3363 | b->number = internal_breakpoint_number--; |
3364 | b->disposition = disp_donttouch; | |
3365 | ||
3366 | return b; | |
3367 | } | |
3368 | ||
17450429 PP |
3369 | static const char *const longjmp_names[] = |
3370 | { | |
3371 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3372 | }; | |
3373 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3374 | ||
3375 | /* Per-objfile data private to breakpoint.c. */ | |
3376 | struct breakpoint_objfile_data | |
3377 | { | |
3378 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3379 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3380 | |
3381 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3382 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3383 | |
28106bc2 SDJ |
3384 | /* True if we have looked for longjmp probes. */ |
3385 | int longjmp_searched; | |
3386 | ||
3387 | /* SystemTap probe points for longjmp (if any). */ | |
3388 | VEC (probe_p) *longjmp_probes; | |
3389 | ||
17450429 | 3390 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3391 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3392 | |
3393 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3394 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3395 | |
3396 | /* True if we have looked for exception probes. */ | |
3397 | int exception_searched; | |
3398 | ||
3399 | /* SystemTap probe points for unwinding (if any). */ | |
3400 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3401 | }; |
3402 | ||
3403 | static const struct objfile_data *breakpoint_objfile_key; | |
3404 | ||
3405 | /* Minimal symbol not found sentinel. */ | |
3406 | static struct minimal_symbol msym_not_found; | |
3407 | ||
3408 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3409 | ||
3410 | static int | |
3411 | msym_not_found_p (const struct minimal_symbol *msym) | |
3412 | { | |
3413 | return msym == &msym_not_found; | |
3414 | } | |
3415 | ||
3416 | /* Return per-objfile data needed by breakpoint.c. | |
3417 | Allocate the data if necessary. */ | |
3418 | ||
3419 | static struct breakpoint_objfile_data * | |
3420 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3421 | { | |
3422 | struct breakpoint_objfile_data *bp_objfile_data; | |
3423 | ||
9a3c8263 SM |
3424 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3425 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3426 | if (bp_objfile_data == NULL) |
3427 | { | |
8d749320 SM |
3428 | bp_objfile_data = |
3429 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3430 | |
3431 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3432 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3433 | } | |
3434 | return bp_objfile_data; | |
3435 | } | |
3436 | ||
28106bc2 SDJ |
3437 | static void |
3438 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3439 | { | |
9a3c8263 SM |
3440 | struct breakpoint_objfile_data *bp_objfile_data |
3441 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3442 | |
3443 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3444 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3445 | } | |
3446 | ||
e62c965a | 3447 | static void |
af02033e | 3448 | create_overlay_event_breakpoint (void) |
e62c965a | 3449 | { |
69de3c6a | 3450 | struct objfile *objfile; |
af02033e | 3451 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3452 | |
69de3c6a PP |
3453 | ALL_OBJFILES (objfile) |
3454 | { | |
3455 | struct breakpoint *b; | |
17450429 PP |
3456 | struct breakpoint_objfile_data *bp_objfile_data; |
3457 | CORE_ADDR addr; | |
67994074 | 3458 | struct explicit_location explicit_loc; |
69de3c6a | 3459 | |
17450429 PP |
3460 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3461 | ||
3b7344d5 | 3462 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3463 | continue; |
3464 | ||
3b7344d5 | 3465 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3466 | { |
3b7344d5 | 3467 | struct bound_minimal_symbol m; |
17450429 PP |
3468 | |
3469 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3470 | if (m.minsym == NULL) |
17450429 PP |
3471 | { |
3472 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3473 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3474 | continue; |
3475 | } | |
3476 | bp_objfile_data->overlay_msym = m; | |
3477 | } | |
e62c965a | 3478 | |
77e371c0 | 3479 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3480 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3481 | bp_overlay_event, |
3482 | &internal_breakpoint_ops); | |
67994074 KS |
3483 | initialize_explicit_location (&explicit_loc); |
3484 | explicit_loc.function_name = ASTRDUP (func_name); | |
3485 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3486 | |
69de3c6a PP |
3487 | if (overlay_debugging == ovly_auto) |
3488 | { | |
3489 | b->enable_state = bp_enabled; | |
3490 | overlay_events_enabled = 1; | |
3491 | } | |
3492 | else | |
3493 | { | |
3494 | b->enable_state = bp_disabled; | |
3495 | overlay_events_enabled = 0; | |
3496 | } | |
e62c965a | 3497 | } |
e62c965a PP |
3498 | } |
3499 | ||
0fd8e87f | 3500 | static void |
af02033e | 3501 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3502 | { |
6c95b8df | 3503 | struct program_space *pspace; |
6c95b8df PA |
3504 | struct cleanup *old_chain; |
3505 | ||
3506 | old_chain = save_current_program_space (); | |
0fd8e87f | 3507 | |
6c95b8df | 3508 | ALL_PSPACES (pspace) |
af02033e PP |
3509 | { |
3510 | struct objfile *objfile; | |
3511 | ||
3512 | set_current_program_space (pspace); | |
3513 | ||
3514 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3515 | { |
af02033e PP |
3516 | int i; |
3517 | struct gdbarch *gdbarch; | |
17450429 | 3518 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3519 | |
af02033e | 3520 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3521 | |
17450429 PP |
3522 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3523 | ||
28106bc2 SDJ |
3524 | if (!bp_objfile_data->longjmp_searched) |
3525 | { | |
25f9533e SDJ |
3526 | VEC (probe_p) *ret; |
3527 | ||
3528 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3529 | if (ret != NULL) | |
3530 | { | |
3531 | /* We are only interested in checking one element. */ | |
3532 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3533 | ||
3534 | if (!can_evaluate_probe_arguments (p)) | |
3535 | { | |
3536 | /* We cannot use the probe interface here, because it does | |
3537 | not know how to evaluate arguments. */ | |
3538 | VEC_free (probe_p, ret); | |
3539 | ret = NULL; | |
3540 | } | |
3541 | } | |
3542 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3543 | bp_objfile_data->longjmp_searched = 1; |
3544 | } | |
3545 | ||
3546 | if (bp_objfile_data->longjmp_probes != NULL) | |
3547 | { | |
3548 | int i; | |
3549 | struct probe *probe; | |
3550 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3551 | ||
3552 | for (i = 0; | |
3553 | VEC_iterate (probe_p, | |
3554 | bp_objfile_data->longjmp_probes, | |
3555 | i, probe); | |
3556 | ++i) | |
3557 | { | |
3558 | struct breakpoint *b; | |
3559 | ||
729662a5 TT |
3560 | b = create_internal_breakpoint (gdbarch, |
3561 | get_probe_address (probe, | |
3562 | objfile), | |
28106bc2 SDJ |
3563 | bp_longjmp_master, |
3564 | &internal_breakpoint_ops); | |
5b56227b KS |
3565 | b->location |
3566 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3567 | b->enable_state = bp_disabled; |
3568 | } | |
3569 | ||
3570 | continue; | |
3571 | } | |
3572 | ||
0569175e TSD |
3573 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3574 | continue; | |
3575 | ||
17450429 | 3576 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3577 | { |
3578 | struct breakpoint *b; | |
af02033e | 3579 | const char *func_name; |
17450429 | 3580 | CORE_ADDR addr; |
67994074 | 3581 | struct explicit_location explicit_loc; |
6c95b8df | 3582 | |
3b7344d5 | 3583 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3584 | continue; |
0fd8e87f | 3585 | |
17450429 | 3586 | func_name = longjmp_names[i]; |
3b7344d5 | 3587 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3588 | { |
3b7344d5 | 3589 | struct bound_minimal_symbol m; |
17450429 PP |
3590 | |
3591 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3592 | if (m.minsym == NULL) |
17450429 PP |
3593 | { |
3594 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3595 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3596 | continue; |
3597 | } | |
3598 | bp_objfile_data->longjmp_msym[i] = m; | |
3599 | } | |
3600 | ||
77e371c0 | 3601 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3602 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3603 | &internal_breakpoint_ops); | |
67994074 KS |
3604 | initialize_explicit_location (&explicit_loc); |
3605 | explicit_loc.function_name = ASTRDUP (func_name); | |
3606 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3607 | b->enable_state = bp_disabled; |
3608 | } | |
0fd8e87f | 3609 | } |
af02033e | 3610 | } |
6c95b8df PA |
3611 | |
3612 | do_cleanups (old_chain); | |
0fd8e87f UW |
3613 | } |
3614 | ||
af02033e | 3615 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3616 | static void |
af02033e | 3617 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3618 | { |
3619 | struct program_space *pspace; | |
aa7d318d | 3620 | struct cleanup *old_chain; |
af02033e | 3621 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3622 | |
3623 | old_chain = save_current_program_space (); | |
3624 | ||
3625 | ALL_PSPACES (pspace) | |
17450429 PP |
3626 | { |
3627 | struct objfile *objfile; | |
3628 | CORE_ADDR addr; | |
3629 | ||
3630 | set_current_program_space (pspace); | |
3631 | ||
aa7d318d TT |
3632 | ALL_OBJFILES (objfile) |
3633 | { | |
3634 | struct breakpoint *b; | |
17450429 | 3635 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3636 | struct explicit_location explicit_loc; |
aa7d318d | 3637 | |
17450429 | 3638 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3639 | |
3b7344d5 | 3640 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3641 | continue; |
3642 | ||
3b7344d5 | 3643 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3644 | { |
3b7344d5 | 3645 | struct bound_minimal_symbol m; |
17450429 PP |
3646 | |
3647 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3648 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3649 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3650 | { |
3651 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3652 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3653 | continue; |
3654 | } | |
3655 | bp_objfile_data->terminate_msym = m; | |
3656 | } | |
aa7d318d | 3657 | |
77e371c0 | 3658 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3659 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3660 | bp_std_terminate_master, |
3661 | &internal_breakpoint_ops); | |
67994074 KS |
3662 | initialize_explicit_location (&explicit_loc); |
3663 | explicit_loc.function_name = ASTRDUP (func_name); | |
3664 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3665 | b->enable_state = bp_disabled; |
3666 | } | |
17450429 PP |
3667 | } |
3668 | ||
aa7d318d TT |
3669 | do_cleanups (old_chain); |
3670 | } | |
3671 | ||
186c406b TT |
3672 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3673 | ||
70221824 | 3674 | static void |
186c406b TT |
3675 | create_exception_master_breakpoint (void) |
3676 | { | |
3677 | struct objfile *objfile; | |
17450429 | 3678 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3679 | |
3680 | ALL_OBJFILES (objfile) | |
3681 | { | |
17450429 PP |
3682 | struct breakpoint *b; |
3683 | struct gdbarch *gdbarch; | |
3684 | struct breakpoint_objfile_data *bp_objfile_data; | |
3685 | CORE_ADDR addr; | |
67994074 | 3686 | struct explicit_location explicit_loc; |
17450429 PP |
3687 | |
3688 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3689 | ||
28106bc2 SDJ |
3690 | /* We prefer the SystemTap probe point if it exists. */ |
3691 | if (!bp_objfile_data->exception_searched) | |
3692 | { | |
25f9533e SDJ |
3693 | VEC (probe_p) *ret; |
3694 | ||
3695 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3696 | ||
3697 | if (ret != NULL) | |
3698 | { | |
3699 | /* We are only interested in checking one element. */ | |
3700 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3701 | ||
3702 | if (!can_evaluate_probe_arguments (p)) | |
3703 | { | |
3704 | /* We cannot use the probe interface here, because it does | |
3705 | not know how to evaluate arguments. */ | |
3706 | VEC_free (probe_p, ret); | |
3707 | ret = NULL; | |
3708 | } | |
3709 | } | |
3710 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3711 | bp_objfile_data->exception_searched = 1; |
3712 | } | |
3713 | ||
3714 | if (bp_objfile_data->exception_probes != NULL) | |
3715 | { | |
3716 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3717 | int i; | |
3718 | struct probe *probe; | |
3719 | ||
3720 | for (i = 0; | |
3721 | VEC_iterate (probe_p, | |
3722 | bp_objfile_data->exception_probes, | |
3723 | i, probe); | |
3724 | ++i) | |
3725 | { | |
3726 | struct breakpoint *b; | |
3727 | ||
729662a5 TT |
3728 | b = create_internal_breakpoint (gdbarch, |
3729 | get_probe_address (probe, | |
3730 | objfile), | |
28106bc2 SDJ |
3731 | bp_exception_master, |
3732 | &internal_breakpoint_ops); | |
5b56227b KS |
3733 | b->location |
3734 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3735 | b->enable_state = bp_disabled; |
3736 | } | |
3737 | ||
3738 | continue; | |
3739 | } | |
3740 | ||
3741 | /* Otherwise, try the hook function. */ | |
3742 | ||
3b7344d5 | 3743 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3744 | continue; |
3745 | ||
3746 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3747 | |
3b7344d5 | 3748 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3749 | { |
3b7344d5 | 3750 | struct bound_minimal_symbol debug_hook; |
186c406b | 3751 | |
17450429 | 3752 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3753 | if (debug_hook.minsym == NULL) |
17450429 | 3754 | { |
3b7344d5 | 3755 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3756 | continue; |
3757 | } | |
3758 | ||
3759 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3760 | } |
17450429 | 3761 | |
77e371c0 | 3762 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3763 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3764 | ¤t_target); | |
06edf0c0 PA |
3765 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3766 | &internal_breakpoint_ops); | |
67994074 KS |
3767 | initialize_explicit_location (&explicit_loc); |
3768 | explicit_loc.function_name = ASTRDUP (func_name); | |
3769 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3770 | b->enable_state = bp_disabled; |
186c406b | 3771 | } |
186c406b TT |
3772 | } |
3773 | ||
9ef9e6a6 KS |
3774 | /* Does B have a location spec? */ |
3775 | ||
3776 | static int | |
3777 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3778 | { | |
3779 | return b->location != NULL && event_location_empty_p (b->location); | |
3780 | } | |
3781 | ||
c906108c | 3782 | void |
fba45db2 | 3783 | update_breakpoints_after_exec (void) |
c906108c | 3784 | { |
35df4500 | 3785 | struct breakpoint *b, *b_tmp; |
876fa593 | 3786 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3787 | |
25b22b0a PA |
3788 | /* We're about to delete breakpoints from GDB's lists. If the |
3789 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3790 | writing the breakpoints' "shadow contents" back into memory. The | |
3791 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3792 | do that. Instead, the target is responsible from marking | |
3793 | breakpoints out as soon as it detects an exec. We don't do that | |
3794 | here instead, because there may be other attempts to delete | |
3795 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3796 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3797 | if (bploc->pspace == current_program_space) |
3798 | gdb_assert (!bploc->inserted); | |
c906108c | 3799 | |
35df4500 | 3800 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3801 | { |
6c95b8df PA |
3802 | if (b->pspace != current_program_space) |
3803 | continue; | |
3804 | ||
4a64f543 | 3805 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3806 | if (b->type == bp_shlib_event) |
3807 | { | |
3808 | delete_breakpoint (b); | |
3809 | continue; | |
3810 | } | |
c906108c | 3811 | |
4a64f543 | 3812 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3813 | if (b->type == bp_jit_event) |
3814 | { | |
3815 | delete_breakpoint (b); | |
3816 | continue; | |
3817 | } | |
3818 | ||
1900040c | 3819 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3820 | as must overlay event and longjmp master breakpoints. */ |
3821 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3822 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3823 | || b->type == bp_exception_master) | |
c4093a6a JM |
3824 | { |
3825 | delete_breakpoint (b); | |
3826 | continue; | |
3827 | } | |
3828 | ||
4a64f543 | 3829 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3830 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3831 | { |
3832 | delete_breakpoint (b); | |
3833 | continue; | |
3834 | } | |
3835 | ||
7c16b83e PA |
3836 | /* Just like single-step breakpoints. */ |
3837 | if (b->type == bp_single_step) | |
3838 | { | |
3839 | delete_breakpoint (b); | |
3840 | continue; | |
3841 | } | |
3842 | ||
611c83ae PA |
3843 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3844 | after an exec. */ | |
186c406b | 3845 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3846 | || b->type == bp_longjmp_call_dummy |
186c406b | 3847 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3848 | { |
3849 | delete_breakpoint (b); | |
3850 | continue; | |
3851 | } | |
3852 | ||
ce78b96d JB |
3853 | if (b->type == bp_catchpoint) |
3854 | { | |
3855 | /* For now, none of the bp_catchpoint breakpoints need to | |
3856 | do anything at this point. In the future, if some of | |
3857 | the catchpoints need to something, we will need to add | |
3858 | a new method, and call this method from here. */ | |
3859 | continue; | |
3860 | } | |
3861 | ||
c5aa993b JM |
3862 | /* bp_finish is a special case. The only way we ought to be able |
3863 | to see one of these when an exec() has happened, is if the user | |
3864 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3865 | carries them to the call-site of the current callee, by setting | |
3866 | a temporary bp there and resuming. But in this case, the finish | |
3867 | will carry them entirely through the vfork & exec. | |
3868 | ||
3869 | We don't want to allow a bp_finish to remain inserted now. But | |
3870 | we can't safely delete it, 'cause finish_command has a handle to | |
3871 | the bp on a bpstat, and will later want to delete it. There's a | |
3872 | chance (and I've seen it happen) that if we delete the bp_finish | |
3873 | here, that its storage will get reused by the time finish_command | |
3874 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3875 | We really must allow finish_command to delete a bp_finish. | |
3876 | ||
e5dd4106 | 3877 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3878 | it's safe to delete something others may have handles to?" |
3879 | problem, what we'll do here is just uninsert the bp_finish, and | |
3880 | let finish_command delete it. | |
3881 | ||
3882 | (We know the bp_finish is "doomed" in the sense that it's | |
3883 | momentary, and will be deleted as soon as finish_command sees | |
3884 | the inferior stopped. So it doesn't matter that the bp's | |
3885 | address is probably bogus in the new a.out, unlike e.g., the | |
3886 | solib breakpoints.) */ | |
c5aa993b | 3887 | |
c5aa993b JM |
3888 | if (b->type == bp_finish) |
3889 | { | |
3890 | continue; | |
3891 | } | |
3892 | ||
3893 | /* Without a symbolic address, we have little hope of the | |
3894 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3895 | a.out. */ |
9ef9e6a6 | 3896 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3897 | { |
3898 | delete_breakpoint (b); | |
3899 | continue; | |
3900 | } | |
c5aa993b | 3901 | } |
c906108c SS |
3902 | } |
3903 | ||
3904 | int | |
d80ee84f | 3905 | detach_breakpoints (ptid_t ptid) |
c906108c | 3906 | { |
35df4500 | 3907 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3908 | int val = 0; |
ce696e05 | 3909 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3910 | struct inferior *inf = current_inferior (); |
c5aa993b | 3911 | |
dfd4cc63 | 3912 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3913 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3914 | |
6c95b8df | 3915 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3916 | inferior_ptid = ptid; |
35df4500 | 3917 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3918 | { |
35df4500 | 3919 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3920 | continue; |
3921 | ||
bd9673a4 PW |
3922 | /* This function must physically remove breakpoints locations |
3923 | from the specified ptid, without modifying the breakpoint | |
3924 | package's state. Locations of type bp_loc_other are only | |
3925 | maintained at GDB side. So, there is no need to remove | |
3926 | these bp_loc_other locations. Moreover, removing these | |
3927 | would modify the breakpoint package's state. */ | |
3928 | if (bl->loc_type == bp_loc_other) | |
3929 | continue; | |
3930 | ||
35df4500 TJB |
3931 | if (bl->inserted) |
3932 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3933 | } |
d03285ec | 3934 | |
ce696e05 | 3935 | do_cleanups (old_chain); |
3a1bae8e | 3936 | return val; |
c906108c SS |
3937 | } |
3938 | ||
35df4500 | 3939 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3940 | Note that this is used to detach breakpoints from a child fork. |
3941 | When we get here, the child isn't in the inferior list, and neither | |
3942 | do we have objects to represent its address space --- we should | |
35df4500 | 3943 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3944 | |
c906108c | 3945 | static int |
35df4500 | 3946 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3947 | { |
3948 | int val; | |
c5aa993b | 3949 | |
35df4500 TJB |
3950 | /* BL is never in moribund_locations by our callers. */ |
3951 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3952 | |
74960c60 VP |
3953 | /* The type of none suggests that owner is actually deleted. |
3954 | This should not ever happen. */ | |
35df4500 | 3955 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3956 | |
35df4500 TJB |
3957 | if (bl->loc_type == bp_loc_software_breakpoint |
3958 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3959 | { |
c02f5703 MS |
3960 | /* "Normal" instruction breakpoint: either the standard |
3961 | trap-instruction bp (bp_breakpoint), or a | |
3962 | bp_hardware_breakpoint. */ | |
3963 | ||
3964 | /* First check to see if we have to handle an overlay. */ | |
3965 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3966 | || bl->section == NULL |
3967 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3968 | { |
3969 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3970 | |
3971 | /* If we're trying to uninsert a memory breakpoint that we | |
3972 | know is set in a dynamic object that is marked | |
3973 | shlib_disabled, then either the dynamic object was | |
3974 | removed with "remove-symbol-file" or with | |
3975 | "nosharedlibrary". In the former case, we don't know | |
3976 | whether another dynamic object might have loaded over the | |
3977 | breakpoint's address -- the user might well let us know | |
3978 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3979 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3980 | list of dynamically loaded objects). If we have the |
3981 | breakpoint's shadow memory, that is, this is a software | |
3982 | breakpoint managed by GDB, check whether the breakpoint | |
3983 | is still inserted in memory, to avoid overwriting wrong | |
3984 | code with stale saved shadow contents. Note that HW | |
3985 | breakpoints don't have shadow memory, as they're | |
3986 | implemented using a mechanism that is not dependent on | |
3987 | being able to modify the target's memory, and as such | |
3988 | they should always be removed. */ | |
3989 | if (bl->shlib_disabled | |
3990 | && bl->target_info.shadow_len != 0 | |
3991 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3992 | val = 0; | |
3993 | else | |
3994 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3995 | } |
c906108c SS |
3996 | else |
3997 | { | |
4a64f543 | 3998 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3999 | Did we set a breakpoint at the LMA? */ |
4000 | if (!overlay_events_enabled) | |
4001 | { | |
4002 | /* Yes -- overlay event support is not active, so we | |
4003 | should have set a breakpoint at the LMA. Remove it. | |
4004 | */ | |
c02f5703 MS |
4005 | /* Ignore any failures: if the LMA is in ROM, we will |
4006 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4007 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4008 | target_remove_hw_breakpoint (bl->gdbarch, | |
4009 | &bl->overlay_target_info); | |
c02f5703 | 4010 | else |
35df4500 TJB |
4011 | target_remove_breakpoint (bl->gdbarch, |
4012 | &bl->overlay_target_info); | |
c02f5703 MS |
4013 | } |
4014 | /* Did we set a breakpoint at the VMA? | |
4015 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4016 | if (bl->inserted) |
c906108c | 4017 | { |
c02f5703 MS |
4018 | /* Yes -- remove it. Previously we did not bother to |
4019 | remove the breakpoint if the section had been | |
4020 | unmapped, but let's not rely on that being safe. We | |
4021 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4022 | |
4023 | /* However, we should remove *software* breakpoints only | |
4024 | if the section is still mapped, or else we overwrite | |
4025 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4026 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4027 | || section_is_mapped (bl->section)) | |
4028 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
4029 | else |
4030 | val = 0; | |
c906108c | 4031 | } |
c02f5703 MS |
4032 | else |
4033 | { | |
4034 | /* No -- not inserted, so no need to remove. No error. */ | |
4035 | val = 0; | |
4036 | } | |
c906108c | 4037 | } |
879d1e6b | 4038 | |
08351840 PA |
4039 | /* In some cases, we might not be able to remove a breakpoint in |
4040 | a shared library that has already been removed, but we have | |
4041 | not yet processed the shlib unload event. Similarly for an | |
4042 | unloaded add-symbol-file object - the user might not yet have | |
4043 | had the chance to remove-symbol-file it. shlib_disabled will | |
4044 | be set if the library/object has already been removed, but | |
4045 | the breakpoint hasn't been uninserted yet, e.g., after | |
4046 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4047 | always-inserted mode. */ | |
076855f9 | 4048 | if (val |
08351840 PA |
4049 | && (bl->loc_type == bp_loc_software_breakpoint |
4050 | && (bl->shlib_disabled | |
4051 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4052 | || shared_objfile_contains_address_p (bl->pspace, |
4053 | bl->address)))) | |
879d1e6b UW |
4054 | val = 0; |
4055 | ||
c906108c SS |
4056 | if (val) |
4057 | return val; | |
35df4500 | 4058 | bl->inserted = (is == mark_inserted); |
c906108c | 4059 | } |
35df4500 | 4060 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4061 | { |
77b06cd7 TJB |
4062 | gdb_assert (bl->owner->ops != NULL |
4063 | && bl->owner->ops->remove_location != NULL); | |
4064 | ||
35df4500 | 4065 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4066 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4067 | |
c906108c | 4068 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4069 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4070 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4071 | bl->owner->number); |
c906108c | 4072 | } |
35df4500 TJB |
4073 | else if (bl->owner->type == bp_catchpoint |
4074 | && breakpoint_enabled (bl->owner) | |
4075 | && !bl->duplicate) | |
ce78b96d | 4076 | { |
77b06cd7 TJB |
4077 | gdb_assert (bl->owner->ops != NULL |
4078 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4079 | |
77b06cd7 | 4080 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4081 | if (val) |
4082 | return val; | |
77b06cd7 | 4083 | |
35df4500 | 4084 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4085 | } |
c906108c SS |
4086 | |
4087 | return 0; | |
4088 | } | |
4089 | ||
6c95b8df | 4090 | static int |
834c0d03 | 4091 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4092 | { |
4093 | int ret; | |
4094 | struct cleanup *old_chain; | |
4095 | ||
35df4500 TJB |
4096 | /* BL is never in moribund_locations by our callers. */ |
4097 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4098 | |
6c95b8df PA |
4099 | /* The type of none suggests that owner is actually deleted. |
4100 | This should not ever happen. */ | |
35df4500 | 4101 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4102 | |
4103 | old_chain = save_current_space_and_thread (); | |
4104 | ||
35df4500 | 4105 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4106 | |
834c0d03 | 4107 | ret = remove_breakpoint_1 (bl, mark_uninserted); |
6c95b8df PA |
4108 | |
4109 | do_cleanups (old_chain); | |
4110 | return ret; | |
4111 | } | |
4112 | ||
c906108c SS |
4113 | /* Clear the "inserted" flag in all breakpoints. */ |
4114 | ||
25b22b0a | 4115 | void |
fba45db2 | 4116 | mark_breakpoints_out (void) |
c906108c | 4117 | { |
35df4500 | 4118 | struct bp_location *bl, **blp_tmp; |
c906108c | 4119 | |
35df4500 | 4120 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4121 | if (bl->pspace == current_program_space) |
35df4500 | 4122 | bl->inserted = 0; |
c906108c SS |
4123 | } |
4124 | ||
53a5351d JM |
4125 | /* Clear the "inserted" flag in all breakpoints and delete any |
4126 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4127 | |
4128 | Plus other such housekeeping that has to be done for breakpoints | |
4129 | between runs. | |
4130 | ||
53a5351d JM |
4131 | Note: this function gets called at the end of a run (by |
4132 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4133 | init_wait_for_inferior). */ |
c906108c SS |
4134 | |
4135 | ||
4136 | ||
4137 | void | |
fba45db2 | 4138 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4139 | { |
35df4500 | 4140 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4141 | struct bp_location *bl; |
1c5cfe86 | 4142 | int ix; |
6c95b8df | 4143 | struct program_space *pspace = current_program_space; |
c906108c | 4144 | |
50c71eaf PA |
4145 | /* If breakpoint locations are shared across processes, then there's |
4146 | nothing to do. */ | |
f5656ead | 4147 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4148 | return; |
4149 | ||
1a853c52 | 4150 | mark_breakpoints_out (); |
075f6582 | 4151 | |
35df4500 | 4152 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4153 | { |
6c95b8df PA |
4154 | if (b->loc && b->loc->pspace != pspace) |
4155 | continue; | |
4156 | ||
c5aa993b JM |
4157 | switch (b->type) |
4158 | { | |
4159 | case bp_call_dummy: | |
e2e4d78b | 4160 | case bp_longjmp_call_dummy: |
c906108c | 4161 | |
c5aa993b | 4162 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4163 | cause problems when the inferior is rerun, so we better get |
4164 | rid of it. */ | |
4165 | ||
4166 | case bp_watchpoint_scope: | |
4167 | ||
4168 | /* Also get rid of scope breakpoints. */ | |
4169 | ||
4170 | case bp_shlib_event: | |
4171 | ||
4172 | /* Also remove solib event breakpoints. Their addresses may | |
4173 | have changed since the last time we ran the program. | |
4174 | Actually we may now be debugging against different target; | |
4175 | and so the solib backend that installed this breakpoint may | |
4176 | not be used in by the target. E.g., | |
4177 | ||
4178 | (gdb) file prog-linux | |
4179 | (gdb) run # native linux target | |
4180 | ... | |
4181 | (gdb) kill | |
4182 | (gdb) file prog-win.exe | |
4183 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4184 | */ | |
c906108c | 4185 | |
f59f708a PA |
4186 | case bp_step_resume: |
4187 | ||
4188 | /* Also remove step-resume breakpoints. */ | |
4189 | ||
7c16b83e PA |
4190 | case bp_single_step: |
4191 | ||
4192 | /* Also remove single-step breakpoints. */ | |
4193 | ||
c5aa993b JM |
4194 | delete_breakpoint (b); |
4195 | break; | |
c906108c | 4196 | |
c5aa993b JM |
4197 | case bp_watchpoint: |
4198 | case bp_hardware_watchpoint: | |
4199 | case bp_read_watchpoint: | |
4200 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4201 | { |
4202 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4203 | |
3a5c3e22 PA |
4204 | /* Likewise for watchpoints on local expressions. */ |
4205 | if (w->exp_valid_block != NULL) | |
4206 | delete_breakpoint (b); | |
63000888 | 4207 | else |
3a5c3e22 | 4208 | { |
63000888 PA |
4209 | /* Get rid of existing locations, which are no longer |
4210 | valid. New ones will be created in | |
4211 | update_watchpoint, when the inferior is restarted. | |
4212 | The next update_global_location_list call will | |
4213 | garbage collect them. */ | |
4214 | b->loc = NULL; | |
4215 | ||
4216 | if (context == inf_starting) | |
4217 | { | |
4218 | /* Reset val field to force reread of starting value in | |
4219 | insert_breakpoints. */ | |
4220 | if (w->val) | |
4221 | value_free (w->val); | |
4222 | w->val = NULL; | |
4223 | w->val_valid = 0; | |
4224 | } | |
4225 | } | |
3a5c3e22 | 4226 | } |
c5aa993b JM |
4227 | break; |
4228 | default: | |
c5aa993b JM |
4229 | break; |
4230 | } | |
4231 | } | |
1c5cfe86 PA |
4232 | |
4233 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4234 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4235 | decref_bp_location (&bl); | |
1c5cfe86 | 4236 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4237 | } |
4238 | ||
6c95b8df PA |
4239 | /* These functions concern about actual breakpoints inserted in the |
4240 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4241 | we need to hop over the bkpt --- so we check for address space | |
4242 | match, not program space. */ | |
4243 | ||
c2c6d25f JM |
4244 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4245 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4246 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4247 | permanent breakpoint. | |
4248 | - When continuing from a location with an ordinary breakpoint, we | |
4249 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4250 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4251 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4252 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4253 | |
c2c6d25f | 4254 | enum breakpoint_here |
6c95b8df | 4255 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4256 | { |
35df4500 | 4257 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4258 | int any_breakpoint_here = 0; |
c906108c | 4259 | |
35df4500 | 4260 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4261 | { |
35df4500 TJB |
4262 | if (bl->loc_type != bp_loc_software_breakpoint |
4263 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4264 | continue; |
4265 | ||
f1310107 | 4266 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4267 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4268 | || bl->permanent) |
f1310107 | 4269 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4270 | { |
4271 | if (overlay_debugging | |
35df4500 TJB |
4272 | && section_is_overlay (bl->section) |
4273 | && !section_is_mapped (bl->section)) | |
075f6582 | 4274 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4275 | else if (bl->permanent) |
075f6582 DJ |
4276 | return permanent_breakpoint_here; |
4277 | else | |
4278 | any_breakpoint_here = 1; | |
4279 | } | |
4280 | } | |
c906108c | 4281 | |
f486487f | 4282 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4283 | } |
4284 | ||
d35ae833 PA |
4285 | /* See breakpoint.h. */ |
4286 | ||
4287 | int | |
4288 | breakpoint_in_range_p (struct address_space *aspace, | |
4289 | CORE_ADDR addr, ULONGEST len) | |
4290 | { | |
4291 | struct bp_location *bl, **blp_tmp; | |
4292 | ||
4293 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4294 | { | |
4295 | if (bl->loc_type != bp_loc_software_breakpoint | |
4296 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4297 | continue; | |
4298 | ||
4299 | if ((breakpoint_enabled (bl->owner) | |
4300 | || bl->permanent) | |
4301 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4302 | addr, len)) | |
4303 | { | |
4304 | if (overlay_debugging | |
4305 | && section_is_overlay (bl->section) | |
4306 | && !section_is_mapped (bl->section)) | |
4307 | { | |
4308 | /* Unmapped overlay -- can't be a match. */ | |
4309 | continue; | |
4310 | } | |
4311 | ||
4312 | return 1; | |
4313 | } | |
4314 | } | |
4315 | ||
4316 | return 0; | |
4317 | } | |
4318 | ||
1c5cfe86 PA |
4319 | /* Return true if there's a moribund breakpoint at PC. */ |
4320 | ||
4321 | int | |
6c95b8df | 4322 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4323 | { |
4324 | struct bp_location *loc; | |
4325 | int ix; | |
4326 | ||
4327 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4328 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4329 | return 1; |
4330 | ||
4331 | return 0; | |
4332 | } | |
c2c6d25f | 4333 | |
f7ce857f PA |
4334 | /* Returns non-zero iff BL is inserted at PC, in address space |
4335 | ASPACE. */ | |
4336 | ||
4337 | static int | |
4338 | bp_location_inserted_here_p (struct bp_location *bl, | |
4339 | struct address_space *aspace, CORE_ADDR pc) | |
4340 | { | |
4341 | if (bl->inserted | |
4342 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4343 | aspace, pc)) | |
4344 | { | |
4345 | if (overlay_debugging | |
4346 | && section_is_overlay (bl->section) | |
4347 | && !section_is_mapped (bl->section)) | |
4348 | return 0; /* unmapped overlay -- can't be a match */ | |
4349 | else | |
4350 | return 1; | |
4351 | } | |
4352 | return 0; | |
4353 | } | |
4354 | ||
a1fd2fa5 | 4355 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4356 | |
4357 | int | |
a1fd2fa5 | 4358 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4359 | { |
f7ce857f | 4360 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4361 | |
f7ce857f | 4362 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4363 | { |
f7ce857f PA |
4364 | struct bp_location *bl = *blp; |
4365 | ||
35df4500 TJB |
4366 | if (bl->loc_type != bp_loc_software_breakpoint |
4367 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4368 | continue; |
4369 | ||
f7ce857f PA |
4370 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4371 | return 1; | |
c5aa993b | 4372 | } |
c36b740a VP |
4373 | return 0; |
4374 | } | |
4375 | ||
a1fd2fa5 PA |
4376 | /* This function returns non-zero iff there is a software breakpoint |
4377 | inserted at PC. */ | |
c36b740a VP |
4378 | |
4379 | int | |
a1fd2fa5 PA |
4380 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4381 | CORE_ADDR pc) | |
4fa8626c | 4382 | { |
f7ce857f | 4383 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4384 | |
f7ce857f | 4385 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4386 | { |
f7ce857f PA |
4387 | struct bp_location *bl = *blp; |
4388 | ||
35df4500 | 4389 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4390 | continue; |
4391 | ||
f7ce857f PA |
4392 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4393 | return 1; | |
4fa8626c DJ |
4394 | } |
4395 | ||
4396 | return 0; | |
9c02b525 PA |
4397 | } |
4398 | ||
4399 | /* See breakpoint.h. */ | |
4400 | ||
4401 | int | |
4402 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4403 | CORE_ADDR pc) | |
4404 | { | |
4405 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4406 | |
4407 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4408 | { | |
4409 | struct bp_location *bl = *blp; | |
4410 | ||
4411 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4412 | continue; | |
4413 | ||
4414 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4415 | return 1; | |
4416 | } | |
4417 | ||
4418 | return 0; | |
4fa8626c DJ |
4419 | } |
4420 | ||
9093389c PA |
4421 | int |
4422 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4423 | CORE_ADDR addr, ULONGEST len) | |
4424 | { | |
4425 | struct breakpoint *bpt; | |
4426 | ||
4427 | ALL_BREAKPOINTS (bpt) | |
4428 | { | |
4429 | struct bp_location *loc; | |
4430 | ||
4431 | if (bpt->type != bp_hardware_watchpoint | |
4432 | && bpt->type != bp_access_watchpoint) | |
4433 | continue; | |
4434 | ||
4435 | if (!breakpoint_enabled (bpt)) | |
4436 | continue; | |
4437 | ||
4438 | for (loc = bpt->loc; loc; loc = loc->next) | |
4439 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4440 | { | |
4441 | CORE_ADDR l, h; | |
4442 | ||
4443 | /* Check for intersection. */ | |
4444 | l = max (loc->address, addr); | |
4445 | h = min (loc->address + loc->length, addr + len); | |
4446 | if (l < h) | |
4447 | return 1; | |
4448 | } | |
4449 | } | |
4450 | return 0; | |
4451 | } | |
c906108c | 4452 | \f |
c5aa993b | 4453 | |
c906108c SS |
4454 | /* bpstat stuff. External routines' interfaces are documented |
4455 | in breakpoint.h. */ | |
4456 | ||
4457 | int | |
c326b90e | 4458 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4459 | { |
533be4dd | 4460 | return (ep->type == bp_catchpoint); |
c906108c SS |
4461 | } |
4462 | ||
f431efe5 PA |
4463 | /* Frees any storage that is part of a bpstat. Does not walk the |
4464 | 'next' chain. */ | |
4465 | ||
4466 | static void | |
198757a8 VP |
4467 | bpstat_free (bpstat bs) |
4468 | { | |
4469 | if (bs->old_val != NULL) | |
4470 | value_free (bs->old_val); | |
9add0f1b | 4471 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4472 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4473 | xfree (bs); |
4474 | } | |
4475 | ||
c906108c SS |
4476 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4477 | Also free any storage that is part of a bpstat. */ | |
4478 | ||
4479 | void | |
fba45db2 | 4480 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4481 | { |
4482 | bpstat p; | |
4483 | bpstat q; | |
4484 | ||
4485 | if (bsp == 0) | |
4486 | return; | |
4487 | p = *bsp; | |
4488 | while (p != NULL) | |
4489 | { | |
4490 | q = p->next; | |
198757a8 | 4491 | bpstat_free (p); |
c906108c SS |
4492 | p = q; |
4493 | } | |
4494 | *bsp = NULL; | |
4495 | } | |
4496 | ||
4497 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4498 | is part of the bpstat is copied as well. */ | |
4499 | ||
4500 | bpstat | |
fba45db2 | 4501 | bpstat_copy (bpstat bs) |
c906108c SS |
4502 | { |
4503 | bpstat p = NULL; | |
4504 | bpstat tmp; | |
4505 | bpstat retval = NULL; | |
4506 | ||
4507 | if (bs == NULL) | |
4508 | return bs; | |
4509 | ||
4510 | for (; bs != NULL; bs = bs->next) | |
4511 | { | |
4512 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4513 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4514 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4515 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4516 | if (bs->old_val != NULL) |
3c3185ac JK |
4517 | { |
4518 | tmp->old_val = value_copy (bs->old_val); | |
4519 | release_value (tmp->old_val); | |
4520 | } | |
31cc81e9 | 4521 | |
c906108c SS |
4522 | if (p == NULL) |
4523 | /* This is the first thing in the chain. */ | |
4524 | retval = tmp; | |
4525 | else | |
4526 | p->next = tmp; | |
4527 | p = tmp; | |
4528 | } | |
4529 | p->next = NULL; | |
4530 | return retval; | |
4531 | } | |
4532 | ||
4a64f543 | 4533 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4534 | |
4535 | bpstat | |
fba45db2 | 4536 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4537 | { |
c5aa993b JM |
4538 | if (bsp == NULL) |
4539 | return NULL; | |
c906108c | 4540 | |
c5aa993b JM |
4541 | for (; bsp != NULL; bsp = bsp->next) |
4542 | { | |
f431efe5 | 4543 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4544 | return bsp; |
4545 | } | |
c906108c SS |
4546 | return NULL; |
4547 | } | |
4548 | ||
ab04a2af TT |
4549 | /* See breakpoint.h. */ |
4550 | ||
47591c29 | 4551 | int |
427cd150 | 4552 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4553 | { |
ab04a2af TT |
4554 | for (; bsp != NULL; bsp = bsp->next) |
4555 | { | |
427cd150 TT |
4556 | if (bsp->breakpoint_at == NULL) |
4557 | { | |
4558 | /* A moribund location can never explain a signal other than | |
4559 | GDB_SIGNAL_TRAP. */ | |
4560 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4561 | return 1; |
427cd150 TT |
4562 | } |
4563 | else | |
47591c29 PA |
4564 | { |
4565 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4566 | sig)) | |
4567 | return 1; | |
4568 | } | |
ab04a2af TT |
4569 | } |
4570 | ||
47591c29 | 4571 | return 0; |
ab04a2af TT |
4572 | } |
4573 | ||
4a64f543 MS |
4574 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4575 | stopped at. *BSP upon return is a bpstat which points to the | |
4576 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4577 | good for anything but further calls to bpstat_num). | |
4578 | ||
8671a17b PA |
4579 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4580 | Return -1 if stopped at a breakpoint that has been deleted since | |
4581 | we set it. | |
4582 | Return 1 otherwise. */ | |
c906108c SS |
4583 | |
4584 | int | |
8671a17b | 4585 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4586 | { |
4587 | struct breakpoint *b; | |
4588 | ||
4589 | if ((*bsp) == NULL) | |
4590 | return 0; /* No more breakpoint values */ | |
8671a17b | 4591 | |
4a64f543 MS |
4592 | /* We assume we'll never have several bpstats that correspond to a |
4593 | single breakpoint -- otherwise, this function might return the | |
4594 | same number more than once and this will look ugly. */ | |
f431efe5 | 4595 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4596 | *bsp = (*bsp)->next; |
4597 | if (b == NULL) | |
4598 | return -1; /* breakpoint that's been deleted since */ | |
4599 | ||
4600 | *num = b->number; /* We have its number */ | |
4601 | return 1; | |
c906108c SS |
4602 | } |
4603 | ||
e93ca019 | 4604 | /* See breakpoint.h. */ |
c906108c SS |
4605 | |
4606 | void | |
e93ca019 | 4607 | bpstat_clear_actions (void) |
c906108c | 4608 | { |
e93ca019 JK |
4609 | struct thread_info *tp; |
4610 | bpstat bs; | |
4611 | ||
4612 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4613 | return; | |
4614 | ||
4615 | tp = find_thread_ptid (inferior_ptid); | |
4616 | if (tp == NULL) | |
4617 | return; | |
4618 | ||
4619 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4620 | { |
9add0f1b | 4621 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4622 | |
c906108c SS |
4623 | if (bs->old_val != NULL) |
4624 | { | |
4625 | value_free (bs->old_val); | |
4626 | bs->old_val = NULL; | |
4627 | } | |
4628 | } | |
4629 | } | |
4630 | ||
f3b1572e PA |
4631 | /* Called when a command is about to proceed the inferior. */ |
4632 | ||
4633 | static void | |
4634 | breakpoint_about_to_proceed (void) | |
4635 | { | |
4636 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4637 | { | |
4638 | struct thread_info *tp = inferior_thread (); | |
4639 | ||
4640 | /* Allow inferior function calls in breakpoint commands to not | |
4641 | interrupt the command list. When the call finishes | |
4642 | successfully, the inferior will be standing at the same | |
4643 | breakpoint as if nothing happened. */ | |
16c381f0 | 4644 | if (tp->control.in_infcall) |
f3b1572e PA |
4645 | return; |
4646 | } | |
4647 | ||
4648 | breakpoint_proceeded = 1; | |
4649 | } | |
4650 | ||
4a64f543 MS |
4651 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4652 | command. */ | |
c906108c | 4653 | static void |
4efb68b1 | 4654 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4655 | { |
4656 | executing_breakpoint_commands = 0; | |
4657 | } | |
4658 | ||
abf85f46 JK |
4659 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4660 | or its equivalent. */ | |
4661 | ||
4662 | static int | |
4663 | command_line_is_silent (struct command_line *cmd) | |
4664 | { | |
4f45d445 | 4665 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4666 | } |
4667 | ||
4a64f543 MS |
4668 | /* Execute all the commands associated with all the breakpoints at |
4669 | this location. Any of these commands could cause the process to | |
4670 | proceed beyond this point, etc. We look out for such changes by | |
4671 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4672 | |
347bddb7 PA |
4673 | Returns true if a breakpoint command resumed the inferior. In that |
4674 | case, it is the caller's responsibility to recall it again with the | |
4675 | bpstat of the current thread. */ | |
4676 | ||
4677 | static int | |
4678 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4679 | { |
4680 | bpstat bs; | |
4681 | struct cleanup *old_chain; | |
347bddb7 | 4682 | int again = 0; |
c906108c SS |
4683 | |
4684 | /* Avoid endless recursion if a `source' command is contained | |
4685 | in bs->commands. */ | |
4686 | if (executing_breakpoint_commands) | |
347bddb7 | 4687 | return 0; |
c906108c SS |
4688 | |
4689 | executing_breakpoint_commands = 1; | |
4690 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4691 | ||
cf6c5ffb TT |
4692 | prevent_dont_repeat (); |
4693 | ||
4a64f543 | 4694 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4695 | bs = *bsp; |
4696 | ||
4697 | breakpoint_proceeded = 0; | |
4698 | for (; bs != NULL; bs = bs->next) | |
4699 | { | |
9add0f1b | 4700 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4701 | struct command_line *cmd; |
4702 | struct cleanup *this_cmd_tree_chain; | |
4703 | ||
4704 | /* Take ownership of the BSP's command tree, if it has one. | |
4705 | ||
4706 | The command tree could legitimately contain commands like | |
4707 | 'step' and 'next', which call clear_proceed_status, which | |
4708 | frees stop_bpstat's command tree. To make sure this doesn't | |
4709 | free the tree we're executing out from under us, we need to | |
4710 | take ownership of the tree ourselves. Since a given bpstat's | |
4711 | commands are only executed once, we don't need to copy it; we | |
4712 | can clear the pointer in the bpstat, and make sure we free | |
4713 | the tree when we're done. */ | |
9add0f1b TT |
4714 | ccmd = bs->commands; |
4715 | bs->commands = NULL; | |
abf85f46 JK |
4716 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4717 | cmd = ccmd ? ccmd->commands : NULL; | |
4718 | if (command_line_is_silent (cmd)) | |
4719 | { | |
4720 | /* The action has been already done by bpstat_stop_status. */ | |
4721 | cmd = cmd->next; | |
4722 | } | |
6c50ab1c | 4723 | |
c906108c SS |
4724 | while (cmd != NULL) |
4725 | { | |
4726 | execute_control_command (cmd); | |
4727 | ||
4728 | if (breakpoint_proceeded) | |
4729 | break; | |
4730 | else | |
4731 | cmd = cmd->next; | |
4732 | } | |
6c50ab1c JB |
4733 | |
4734 | /* We can free this command tree now. */ | |
4735 | do_cleanups (this_cmd_tree_chain); | |
4736 | ||
c906108c | 4737 | if (breakpoint_proceeded) |
32c1e744 | 4738 | { |
cb814510 | 4739 | if (current_ui->async) |
347bddb7 PA |
4740 | /* If we are in async mode, then the target might be still |
4741 | running, not stopped at any breakpoint, so nothing for | |
4742 | us to do here -- just return to the event loop. */ | |
4743 | ; | |
32c1e744 VP |
4744 | else |
4745 | /* In sync mode, when execute_control_command returns | |
4746 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4747 | Breakpoint commands for that stop were not run, since |
4748 | execute_command does not run breakpoint commands -- | |
4749 | only command_line_handler does, but that one is not | |
4750 | involved in execution of breakpoint commands. So, we | |
4751 | can now execute breakpoint commands. It should be | |
4752 | noted that making execute_command do bpstat actions is | |
4753 | not an option -- in this case we'll have recursive | |
4754 | invocation of bpstat for each breakpoint with a | |
4755 | command, and can easily blow up GDB stack. Instead, we | |
4756 | return true, which will trigger the caller to recall us | |
4757 | with the new stop_bpstat. */ | |
4758 | again = 1; | |
4759 | break; | |
32c1e744 | 4760 | } |
c906108c | 4761 | } |
c2b8ed2c | 4762 | do_cleanups (old_chain); |
347bddb7 PA |
4763 | return again; |
4764 | } | |
4765 | ||
4766 | void | |
4767 | bpstat_do_actions (void) | |
4768 | { | |
353d1d73 JK |
4769 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4770 | ||
347bddb7 PA |
4771 | /* Do any commands attached to breakpoint we are stopped at. */ |
4772 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4773 | && target_has_execution | |
4774 | && !is_exited (inferior_ptid) | |
4775 | && !is_executing (inferior_ptid)) | |
4776 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4777 | and only return when it is stopped at the next breakpoint, we | |
4778 | keep doing breakpoint actions until it returns false to | |
4779 | indicate the inferior was not resumed. */ | |
16c381f0 | 4780 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4781 | break; |
353d1d73 JK |
4782 | |
4783 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4784 | } |
4785 | ||
fa4727a6 DJ |
4786 | /* Print out the (old or new) value associated with a watchpoint. */ |
4787 | ||
4788 | static void | |
4789 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4790 | { | |
4791 | if (val == NULL) | |
4792 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4793 | else | |
79a45b7d TT |
4794 | { |
4795 | struct value_print_options opts; | |
4796 | get_user_print_options (&opts); | |
4797 | value_print (val, stream, &opts); | |
4798 | } | |
fa4727a6 DJ |
4799 | } |
4800 | ||
f303dbd6 PA |
4801 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4802 | debugging multiple threads. */ | |
4803 | ||
4804 | void | |
4805 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4806 | { | |
4807 | if (ui_out_is_mi_like_p (uiout)) | |
4808 | return; | |
4809 | ||
4810 | ui_out_text (uiout, "\n"); | |
4811 | ||
4812 | if (show_thread_that_caused_stop ()) | |
4813 | { | |
4814 | const char *name; | |
4815 | struct thread_info *thr = inferior_thread (); | |
4816 | ||
4817 | ui_out_text (uiout, "Thread "); | |
4818 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4819 | ||
4820 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4821 | if (name != NULL) | |
4822 | { | |
4823 | ui_out_text (uiout, " \""); | |
4824 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4825 | ui_out_text (uiout, "\""); | |
4826 | } | |
4827 | ||
4828 | ui_out_text (uiout, " hit "); | |
4829 | } | |
4830 | } | |
4831 | ||
e514a9d6 | 4832 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4833 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4834 | 'print_it' in the bpstat structure. Under some circumstances we |
4835 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4836 | normal_stop(). */ |
e514a9d6 JM |
4837 | |
4838 | static enum print_stop_action | |
4839 | print_bp_stop_message (bpstat bs) | |
4840 | { | |
4841 | switch (bs->print_it) | |
4842 | { | |
4843 | case print_it_noop: | |
4a64f543 | 4844 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4845 | return PRINT_UNKNOWN; |
4846 | break; | |
4847 | ||
4848 | case print_it_done: | |
4849 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4850 | relevant messages. */ |
e514a9d6 JM |
4851 | return PRINT_SRC_AND_LOC; |
4852 | break; | |
4853 | ||
4854 | case print_it_normal: | |
4f8d1dc6 | 4855 | { |
f431efe5 PA |
4856 | struct breakpoint *b = bs->breakpoint_at; |
4857 | ||
1a6a67de TJB |
4858 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4859 | which has since been deleted. */ | |
4860 | if (b == NULL) | |
4861 | return PRINT_UNKNOWN; | |
4862 | ||
348d480f PA |
4863 | /* Normal case. Call the breakpoint's print_it method. */ |
4864 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4865 | } |
348d480f | 4866 | break; |
3086aeae | 4867 | |
e514a9d6 | 4868 | default: |
8e65ff28 | 4869 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4870 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4871 | break; |
c906108c | 4872 | } |
c906108c SS |
4873 | } |
4874 | ||
edcc5120 TT |
4875 | /* A helper function that prints a shared library stopped event. */ |
4876 | ||
4877 | static void | |
4878 | print_solib_event (int is_catchpoint) | |
4879 | { | |
4880 | int any_deleted | |
4881 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4882 | int any_added | |
4883 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4884 | ||
4885 | if (!is_catchpoint) | |
4886 | { | |
4887 | if (any_added || any_deleted) | |
4888 | ui_out_text (current_uiout, | |
4889 | _("Stopped due to shared library event:\n")); | |
4890 | else | |
4891 | ui_out_text (current_uiout, | |
4892 | _("Stopped due to shared library event (no " | |
4893 | "libraries added or removed)\n")); | |
4894 | } | |
4895 | ||
4896 | if (ui_out_is_mi_like_p (current_uiout)) | |
4897 | ui_out_field_string (current_uiout, "reason", | |
4898 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4899 | ||
4900 | if (any_deleted) | |
4901 | { | |
4902 | struct cleanup *cleanup; | |
4903 | char *name; | |
4904 | int ix; | |
4905 | ||
4906 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4907 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4908 | "removed"); | |
4909 | for (ix = 0; | |
4910 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4911 | ix, name); | |
4912 | ++ix) | |
4913 | { | |
4914 | if (ix > 0) | |
4915 | ui_out_text (current_uiout, " "); | |
4916 | ui_out_field_string (current_uiout, "library", name); | |
4917 | ui_out_text (current_uiout, "\n"); | |
4918 | } | |
4919 | ||
4920 | do_cleanups (cleanup); | |
4921 | } | |
4922 | ||
4923 | if (any_added) | |
4924 | { | |
4925 | struct so_list *iter; | |
4926 | int ix; | |
4927 | struct cleanup *cleanup; | |
4928 | ||
4929 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4930 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4931 | "added"); | |
4932 | for (ix = 0; | |
4933 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4934 | ix, iter); | |
4935 | ++ix) | |
4936 | { | |
4937 | if (ix > 0) | |
4938 | ui_out_text (current_uiout, " "); | |
4939 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4940 | ui_out_text (current_uiout, "\n"); | |
4941 | } | |
4942 | ||
4943 | do_cleanups (cleanup); | |
4944 | } | |
4945 | } | |
4946 | ||
e514a9d6 JM |
4947 | /* Print a message indicating what happened. This is called from |
4948 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4949 | list - a list of the eventpoints that caused this stop. KIND is |
4950 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4951 | routine calls the generic print routine for printing a message |
4952 | about reasons for stopping. This will print (for example) the | |
4953 | "Breakpoint n," part of the output. The return value of this | |
4954 | routine is one of: | |
c906108c | 4955 | |
4a64f543 | 4956 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4957 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4958 | code to print the location. An example is |
c5aa993b JM |
4959 | "Breakpoint 1, " which should be followed by |
4960 | the location. | |
917317f4 | 4961 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4962 | to also print the location part of the message. |
4963 | An example is the catch/throw messages, which | |
4a64f543 | 4964 | don't require a location appended to the end. |
917317f4 | 4965 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4966 | further info to be printed. */ |
c906108c | 4967 | |
917317f4 | 4968 | enum print_stop_action |
36dfb11c | 4969 | bpstat_print (bpstat bs, int kind) |
c906108c | 4970 | { |
f486487f | 4971 | enum print_stop_action val; |
c5aa993b | 4972 | |
c906108c | 4973 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4974 | (Currently all watchpoints go on the bpstat whether hit or not. |
4975 | That probably could (should) be changed, provided care is taken | |
c906108c | 4976 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4977 | for (; bs; bs = bs->next) |
4978 | { | |
4979 | val = print_bp_stop_message (bs); | |
4980 | if (val == PRINT_SRC_ONLY | |
4981 | || val == PRINT_SRC_AND_LOC | |
4982 | || val == PRINT_NOTHING) | |
4983 | return val; | |
4984 | } | |
c906108c | 4985 | |
36dfb11c TT |
4986 | /* If we had hit a shared library event breakpoint, |
4987 | print_bp_stop_message would print out this message. If we hit an | |
4988 | OS-level shared library event, do the same thing. */ | |
4989 | if (kind == TARGET_WAITKIND_LOADED) | |
4990 | { | |
edcc5120 | 4991 | print_solib_event (0); |
36dfb11c TT |
4992 | return PRINT_NOTHING; |
4993 | } | |
4994 | ||
e514a9d6 | 4995 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4996 | with and nothing was printed. */ |
917317f4 | 4997 | return PRINT_UNKNOWN; |
c906108c SS |
4998 | } |
4999 | ||
c42bd95a DE |
5000 | /* Evaluate the expression EXP and return 1 if value is zero. |
5001 | This returns the inverse of the condition because it is called | |
5002 | from catch_errors which returns 0 if an exception happened, and if an | |
5003 | exception happens we want execution to stop. | |
4a64f543 | 5004 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5005 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5006 | |
5007 | static int | |
4efb68b1 | 5008 | breakpoint_cond_eval (void *exp) |
c906108c | 5009 | { |
278cd55f | 5010 | struct value *mark = value_mark (); |
c5aa993b | 5011 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5012 | |
c906108c SS |
5013 | value_free_to_mark (mark); |
5014 | return i; | |
5015 | } | |
5016 | ||
5760d0ab | 5017 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5018 | |
5019 | static bpstat | |
5760d0ab | 5020 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5021 | { |
5022 | bpstat bs; | |
5023 | ||
5024 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5025 | bs->next = NULL; |
5026 | **bs_link_pointer = bs; | |
5027 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5028 | bs->breakpoint_at = bl->owner; |
5029 | bs->bp_location_at = bl; | |
5030 | incref_bp_location (bl); | |
c906108c SS |
5031 | /* If the condition is false, etc., don't do the commands. */ |
5032 | bs->commands = NULL; | |
5033 | bs->old_val = NULL; | |
5034 | bs->print_it = print_it_normal; | |
5035 | return bs; | |
5036 | } | |
5037 | \f | |
d983da9c DJ |
5038 | /* The target has stopped with waitstatus WS. Check if any hardware |
5039 | watchpoints have triggered, according to the target. */ | |
5040 | ||
5041 | int | |
5042 | watchpoints_triggered (struct target_waitstatus *ws) | |
5043 | { | |
d92524f1 | 5044 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5045 | CORE_ADDR addr; |
5046 | struct breakpoint *b; | |
5047 | ||
5048 | if (!stopped_by_watchpoint) | |
5049 | { | |
5050 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5051 | as not triggered. */ | |
5052 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5053 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5054 | { |
5055 | struct watchpoint *w = (struct watchpoint *) b; | |
5056 | ||
5057 | w->watchpoint_triggered = watch_triggered_no; | |
5058 | } | |
d983da9c DJ |
5059 | |
5060 | return 0; | |
5061 | } | |
5062 | ||
5063 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5064 | { | |
5065 | /* We were stopped by a watchpoint, but we don't know where. | |
5066 | Mark all watchpoints as unknown. */ | |
5067 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5068 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5069 | { |
5070 | struct watchpoint *w = (struct watchpoint *) b; | |
5071 | ||
5072 | w->watchpoint_triggered = watch_triggered_unknown; | |
5073 | } | |
d983da9c | 5074 | |
3c4797ba | 5075 | return 1; |
d983da9c DJ |
5076 | } |
5077 | ||
5078 | /* The target could report the data address. Mark watchpoints | |
5079 | affected by this data address as triggered, and all others as not | |
5080 | triggered. */ | |
5081 | ||
5082 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5083 | if (is_hardware_watchpoint (b)) |
d983da9c | 5084 | { |
3a5c3e22 | 5085 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5086 | struct bp_location *loc; |
d983da9c | 5087 | |
3a5c3e22 | 5088 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5089 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5090 | { |
3a5c3e22 | 5091 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5092 | { |
3a5c3e22 PA |
5093 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5094 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5095 | |
5096 | if (newaddr == start) | |
5097 | { | |
3a5c3e22 | 5098 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5099 | break; |
5100 | } | |
5101 | } | |
5102 | /* Exact match not required. Within range is sufficient. */ | |
5103 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5104 | addr, loc->address, | |
5105 | loc->length)) | |
5106 | { | |
3a5c3e22 | 5107 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5108 | break; |
5109 | } | |
5110 | } | |
d983da9c DJ |
5111 | } |
5112 | ||
5113 | return 1; | |
5114 | } | |
5115 | ||
c906108c SS |
5116 | /* Possible return values for watchpoint_check (this can't be an enum |
5117 | because of check_errors). */ | |
5118 | /* The watchpoint has been deleted. */ | |
5119 | #define WP_DELETED 1 | |
5120 | /* The value has changed. */ | |
5121 | #define WP_VALUE_CHANGED 2 | |
5122 | /* The value has not changed. */ | |
5123 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5124 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5125 | #define WP_IGNORE 4 | |
c906108c SS |
5126 | |
5127 | #define BP_TEMPFLAG 1 | |
5128 | #define BP_HARDWAREFLAG 2 | |
5129 | ||
4a64f543 MS |
5130 | /* Evaluate watchpoint condition expression and check if its value |
5131 | changed. | |
553e4c11 JB |
5132 | |
5133 | P should be a pointer to struct bpstat, but is defined as a void * | |
5134 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5135 | |
5136 | static int | |
4efb68b1 | 5137 | watchpoint_check (void *p) |
c906108c SS |
5138 | { |
5139 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5140 | struct watchpoint *b; |
c906108c SS |
5141 | struct frame_info *fr; |
5142 | int within_current_scope; | |
5143 | ||
f431efe5 | 5144 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5145 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5146 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5147 | |
f6bc2008 PA |
5148 | /* If this is a local watchpoint, we only want to check if the |
5149 | watchpoint frame is in scope if the current thread is the thread | |
5150 | that was used to create the watchpoint. */ | |
5151 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5152 | return WP_IGNORE; |
f6bc2008 | 5153 | |
c906108c SS |
5154 | if (b->exp_valid_block == NULL) |
5155 | within_current_scope = 1; | |
5156 | else | |
5157 | { | |
edb3359d DJ |
5158 | struct frame_info *frame = get_current_frame (); |
5159 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5160 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5161 | ||
c9cf6e20 | 5162 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5163 | still in the function but the stack frame has already been |
5164 | invalidated. Since we can't rely on the values of local | |
5165 | variables after the stack has been destroyed, we are treating | |
5166 | the watchpoint in that state as `not changed' without further | |
5167 | checking. Don't mark watchpoints as changed if the current | |
5168 | frame is in an epilogue - even if they are in some other | |
5169 | frame, our view of the stack is likely to be wrong and | |
5170 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5171 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5172 | return WP_IGNORE; |
a0f49112 | 5173 | |
101dcfbe | 5174 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5175 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5176 | |
5177 | /* If we've gotten confused in the unwinder, we might have | |
5178 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5179 | if (within_current_scope) |
5180 | { | |
5181 | struct symbol *function; | |
5182 | ||
5183 | function = get_frame_function (fr); | |
5184 | if (function == NULL | |
5185 | || !contained_in (b->exp_valid_block, | |
5186 | SYMBOL_BLOCK_VALUE (function))) | |
5187 | within_current_scope = 0; | |
5188 | } | |
69fbadd5 | 5189 | |
edb3359d | 5190 | if (within_current_scope) |
c906108c SS |
5191 | /* If we end up stopping, the current frame will get selected |
5192 | in normal_stop. So this call to select_frame won't affect | |
5193 | the user. */ | |
0f7d239c | 5194 | select_frame (fr); |
c906108c | 5195 | } |
c5aa993b | 5196 | |
c906108c SS |
5197 | if (within_current_scope) |
5198 | { | |
4a64f543 MS |
5199 | /* We use value_{,free_to_}mark because it could be a *long* |
5200 | time before we return to the command level and call | |
5201 | free_all_values. We can't call free_all_values because we | |
5202 | might be in the middle of evaluating a function call. */ | |
c906108c | 5203 | |
0cf6dd15 | 5204 | int pc = 0; |
9c06b0b4 | 5205 | struct value *mark; |
fa4727a6 DJ |
5206 | struct value *new_val; |
5207 | ||
3a5c3e22 | 5208 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5209 | /* Since we don't know the exact trigger address (from |
5210 | stopped_data_address), just tell the user we've triggered | |
5211 | a mask watchpoint. */ | |
5212 | return WP_VALUE_CHANGED; | |
5213 | ||
5214 | mark = value_mark (); | |
3a1115a0 | 5215 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5216 | |
bb9d5f81 PP |
5217 | if (b->val_bitsize != 0) |
5218 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5219 | ||
4a64f543 MS |
5220 | /* We use value_equal_contents instead of value_equal because |
5221 | the latter coerces an array to a pointer, thus comparing just | |
5222 | the address of the array instead of its contents. This is | |
5223 | not what we want. */ | |
fa4727a6 | 5224 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5225 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5226 | { |
fa4727a6 DJ |
5227 | if (new_val != NULL) |
5228 | { | |
5229 | release_value (new_val); | |
5230 | value_free_to_mark (mark); | |
5231 | } | |
c906108c SS |
5232 | bs->old_val = b->val; |
5233 | b->val = new_val; | |
fa4727a6 | 5234 | b->val_valid = 1; |
c906108c SS |
5235 | return WP_VALUE_CHANGED; |
5236 | } | |
5237 | else | |
5238 | { | |
60e1c644 | 5239 | /* Nothing changed. */ |
c906108c | 5240 | value_free_to_mark (mark); |
c906108c SS |
5241 | return WP_VALUE_NOT_CHANGED; |
5242 | } | |
5243 | } | |
5244 | else | |
5245 | { | |
468afe6c | 5246 | struct switch_thru_all_uis state; |
79a45e25 | 5247 | |
c906108c | 5248 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5249 | if we temporarily ignored the watchpoint, then when |
5250 | we reenter the block in which it is valid it contains | |
5251 | garbage (in the case of a function, it may have two | |
5252 | garbage values, one before and one after the prologue). | |
5253 | So we can't even detect the first assignment to it and | |
5254 | watch after that (since the garbage may or may not equal | |
5255 | the first value assigned). */ | |
348d480f PA |
5256 | /* We print all the stop information in |
5257 | breakpoint_ops->print_it, but in this case, by the time we | |
5258 | call breakpoint_ops->print_it this bp will be deleted | |
5259 | already. So we have no choice but print the information | |
5260 | here. */ | |
468afe6c PA |
5261 | |
5262 | SWITCH_THRU_ALL_UIS (state) | |
5263 | { | |
5264 | struct ui_out *uiout = current_uiout; | |
5265 | ||
5266 | if (ui_out_is_mi_like_p (uiout)) | |
5267 | ui_out_field_string | |
5268 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5269 | ui_out_text (uiout, "\nWatchpoint "); | |
5270 | ui_out_field_int (uiout, "wpnum", b->base.number); | |
5271 | ui_out_text (uiout, | |
5272 | " deleted because the program has left the block in\n" | |
5273 | "which its expression is valid.\n"); | |
5274 | } | |
4ce44c66 | 5275 | |
cdac0397 | 5276 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5277 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5278 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5279 | |
5280 | return WP_DELETED; | |
5281 | } | |
5282 | } | |
5283 | ||
18a18393 | 5284 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5285 | breakpoint location BL. This function does not check if we should |
5286 | stop, only if BL explains the stop. */ | |
5287 | ||
18a18393 | 5288 | static int |
6c95b8df | 5289 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5290 | struct address_space *aspace, CORE_ADDR bp_addr, |
5291 | const struct target_waitstatus *ws) | |
18a18393 VP |
5292 | { |
5293 | struct breakpoint *b = bl->owner; | |
5294 | ||
348d480f | 5295 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5296 | gdb_assert (b != NULL); |
5297 | ||
09ac7c10 | 5298 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5299 | } |
5300 | ||
3a5c3e22 PA |
5301 | /* Determine if the watched values have actually changed, and we |
5302 | should stop. If not, set BS->stop to 0. */ | |
5303 | ||
18a18393 VP |
5304 | static void |
5305 | bpstat_check_watchpoint (bpstat bs) | |
5306 | { | |
2bdf28a0 | 5307 | const struct bp_location *bl; |
3a5c3e22 | 5308 | struct watchpoint *b; |
2bdf28a0 JK |
5309 | |
5310 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5311 | bl = bs->bp_location_at; |
2bdf28a0 | 5312 | gdb_assert (bl != NULL); |
3a5c3e22 | 5313 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5314 | gdb_assert (b != NULL); |
18a18393 | 5315 | |
18a18393 | 5316 | { |
18a18393 VP |
5317 | int must_check_value = 0; |
5318 | ||
3a5c3e22 | 5319 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5320 | /* For a software watchpoint, we must always check the |
5321 | watched value. */ | |
5322 | must_check_value = 1; | |
5323 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5324 | /* We have a hardware watchpoint (read, write, or access) | |
5325 | and the target earlier reported an address watched by | |
5326 | this watchpoint. */ | |
5327 | must_check_value = 1; | |
5328 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5329 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5330 | /* We were stopped by a hardware watchpoint, but the target could |
5331 | not report the data address. We must check the watchpoint's | |
5332 | value. Access and read watchpoints are out of luck; without | |
5333 | a data address, we can't figure it out. */ | |
5334 | must_check_value = 1; | |
3a5c3e22 | 5335 | |
18a18393 VP |
5336 | if (must_check_value) |
5337 | { | |
3e43a32a MS |
5338 | char *message |
5339 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5340 | b->base.number); |
18a18393 VP |
5341 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5342 | int e = catch_errors (watchpoint_check, bs, message, | |
5343 | RETURN_MASK_ALL); | |
5344 | do_cleanups (cleanups); | |
5345 | switch (e) | |
5346 | { | |
5347 | case WP_DELETED: | |
5348 | /* We've already printed what needs to be printed. */ | |
5349 | bs->print_it = print_it_done; | |
5350 | /* Stop. */ | |
5351 | break; | |
60e1c644 PA |
5352 | case WP_IGNORE: |
5353 | bs->print_it = print_it_noop; | |
5354 | bs->stop = 0; | |
5355 | break; | |
18a18393 | 5356 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5357 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5358 | { |
85d721b8 PA |
5359 | /* There are two cases to consider here: |
5360 | ||
4a64f543 | 5361 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5362 | In that case, trust the target, and always report |
5363 | the watchpoint hit to the user. Even though | |
5364 | reads don't cause value changes, the value may | |
5365 | have changed since the last time it was read, and | |
5366 | since we're not trapping writes, we will not see | |
5367 | those, and as such we should ignore our notion of | |
5368 | old value. | |
5369 | ||
4a64f543 | 5370 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5371 | reads and writes. There are two ways this may |
5372 | happen: | |
5373 | ||
4a64f543 | 5374 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5375 | reads only, but can break on accesses (reads or |
5376 | writes), such as e.g., x86. We detect this case | |
5377 | at the time we try to insert read watchpoints. | |
5378 | ||
4a64f543 | 5379 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5380 | watchpoints, but, the user set an access or write |
5381 | watchpoint watching the same memory as this read | |
5382 | watchpoint. | |
5383 | ||
5384 | If we're watching memory writes as well as reads, | |
5385 | ignore watchpoint hits when we find that the | |
5386 | value hasn't changed, as reads don't cause | |
5387 | changes. This still gives false positives when | |
5388 | the program writes the same value to memory as | |
5389 | what there was already in memory (we will confuse | |
5390 | it for a read), but it's much better than | |
5391 | nothing. */ | |
5392 | ||
5393 | int other_write_watchpoint = 0; | |
5394 | ||
5395 | if (bl->watchpoint_type == hw_read) | |
5396 | { | |
5397 | struct breakpoint *other_b; | |
5398 | ||
5399 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5400 | if (other_b->type == bp_hardware_watchpoint |
5401 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5402 | { |
3a5c3e22 PA |
5403 | struct watchpoint *other_w = |
5404 | (struct watchpoint *) other_b; | |
5405 | ||
5406 | if (other_w->watchpoint_triggered | |
5407 | == watch_triggered_yes) | |
5408 | { | |
5409 | other_write_watchpoint = 1; | |
5410 | break; | |
5411 | } | |
85d721b8 PA |
5412 | } |
5413 | } | |
5414 | ||
5415 | if (other_write_watchpoint | |
5416 | || bl->watchpoint_type == hw_access) | |
5417 | { | |
5418 | /* We're watching the same memory for writes, | |
5419 | and the value changed since the last time we | |
5420 | updated it, so this trap must be for a write. | |
5421 | Ignore it. */ | |
5422 | bs->print_it = print_it_noop; | |
5423 | bs->stop = 0; | |
5424 | } | |
18a18393 VP |
5425 | } |
5426 | break; | |
5427 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5428 | if (b->base.type == bp_hardware_watchpoint |
5429 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5430 | { |
5431 | /* Don't stop: write watchpoints shouldn't fire if | |
5432 | the value hasn't changed. */ | |
5433 | bs->print_it = print_it_noop; | |
5434 | bs->stop = 0; | |
5435 | } | |
5436 | /* Stop. */ | |
5437 | break; | |
5438 | default: | |
5439 | /* Can't happen. */ | |
5440 | case 0: | |
5441 | /* Error from catch_errors. */ | |
468afe6c PA |
5442 | { |
5443 | struct switch_thru_all_uis state; | |
5444 | ||
5445 | SWITCH_THRU_ALL_UIS (state) | |
5446 | { | |
5447 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5448 | b->base.number); | |
5449 | } | |
5450 | watchpoint_del_at_next_stop (b); | |
5451 | /* We've already printed what needs to be printed. */ | |
5452 | bs->print_it = print_it_done; | |
5453 | } | |
18a18393 VP |
5454 | break; |
5455 | } | |
5456 | } | |
5457 | else /* must_check_value == 0 */ | |
5458 | { | |
5459 | /* This is a case where some watchpoint(s) triggered, but | |
5460 | not at the address of this watchpoint, or else no | |
5461 | watchpoint triggered after all. So don't print | |
5462 | anything for this watchpoint. */ | |
5463 | bs->print_it = print_it_noop; | |
5464 | bs->stop = 0; | |
5465 | } | |
5466 | } | |
5467 | } | |
5468 | ||
7d4df6a4 DE |
5469 | /* For breakpoints that are currently marked as telling gdb to stop, |
5470 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5471 | of breakpoint referred to by BS. If we should not stop for this |
5472 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5473 | |
18a18393 VP |
5474 | static void |
5475 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5476 | { | |
2bdf28a0 JK |
5477 | const struct bp_location *bl; |
5478 | struct breakpoint *b; | |
7d4df6a4 DE |
5479 | int value_is_zero = 0; |
5480 | struct expression *cond; | |
5481 | ||
5482 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5483 | |
5484 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5485 | bl = bs->bp_location_at; |
2bdf28a0 | 5486 | gdb_assert (bl != NULL); |
f431efe5 | 5487 | b = bs->breakpoint_at; |
2bdf28a0 | 5488 | gdb_assert (b != NULL); |
18a18393 | 5489 | |
b775012e LM |
5490 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5491 | need to do so again since GDB does not know if we stopped due to a | |
5492 | breakpoint or a single step breakpoint. */ | |
5493 | ||
18a18393 | 5494 | if (frame_id_p (b->frame_id) |
edb3359d | 5495 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5496 | { |
7d4df6a4 DE |
5497 | bs->stop = 0; |
5498 | return; | |
5499 | } | |
60e1c644 | 5500 | |
12ab52e9 PA |
5501 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5502 | evaluating the condition if this isn't the specified | |
5503 | thread/task. */ | |
5d5658a1 | 5504 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5505 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5506 | ||
6c1b0f7b DE |
5507 | { |
5508 | bs->stop = 0; | |
5509 | return; | |
5510 | } | |
5511 | ||
6dddc817 DE |
5512 | /* Evaluate extension language breakpoints that have a "stop" method |
5513 | implemented. */ | |
5514 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5515 | |
7d4df6a4 DE |
5516 | if (is_watchpoint (b)) |
5517 | { | |
5518 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5519 | |
7d4df6a4 DE |
5520 | cond = w->cond_exp; |
5521 | } | |
5522 | else | |
5523 | cond = bl->cond; | |
60e1c644 | 5524 | |
7d4df6a4 DE |
5525 | if (cond && b->disposition != disp_del_at_next_stop) |
5526 | { | |
5527 | int within_current_scope = 1; | |
5528 | struct watchpoint * w; | |
60e1c644 | 5529 | |
7d4df6a4 DE |
5530 | /* We use value_mark and value_free_to_mark because it could |
5531 | be a long time before we return to the command level and | |
5532 | call free_all_values. We can't call free_all_values | |
5533 | because we might be in the middle of evaluating a | |
5534 | function call. */ | |
5535 | struct value *mark = value_mark (); | |
5536 | ||
5537 | if (is_watchpoint (b)) | |
5538 | w = (struct watchpoint *) b; | |
5539 | else | |
5540 | w = NULL; | |
5541 | ||
5542 | /* Need to select the frame, with all that implies so that | |
5543 | the conditions will have the right context. Because we | |
5544 | use the frame, we will not see an inlined function's | |
5545 | variables when we arrive at a breakpoint at the start | |
5546 | of the inlined function; the current frame will be the | |
5547 | call site. */ | |
5548 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5549 | select_frame (get_current_frame ()); | |
5550 | else | |
18a18393 | 5551 | { |
7d4df6a4 DE |
5552 | struct frame_info *frame; |
5553 | ||
5554 | /* For local watchpoint expressions, which particular | |
5555 | instance of a local is being watched matters, so we | |
5556 | keep track of the frame to evaluate the expression | |
5557 | in. To evaluate the condition however, it doesn't | |
5558 | really matter which instantiation of the function | |
5559 | where the condition makes sense triggers the | |
5560 | watchpoint. This allows an expression like "watch | |
5561 | global if q > 10" set in `func', catch writes to | |
5562 | global on all threads that call `func', or catch | |
5563 | writes on all recursive calls of `func' by a single | |
5564 | thread. We simply always evaluate the condition in | |
5565 | the innermost frame that's executing where it makes | |
5566 | sense to evaluate the condition. It seems | |
5567 | intuitive. */ | |
5568 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5569 | if (frame != NULL) | |
5570 | select_frame (frame); | |
5571 | else | |
5572 | within_current_scope = 0; | |
18a18393 | 5573 | } |
7d4df6a4 DE |
5574 | if (within_current_scope) |
5575 | value_is_zero | |
5576 | = catch_errors (breakpoint_cond_eval, cond, | |
5577 | "Error in testing breakpoint condition:\n", | |
5578 | RETURN_MASK_ALL); | |
5579 | else | |
18a18393 | 5580 | { |
7d4df6a4 DE |
5581 | warning (_("Watchpoint condition cannot be tested " |
5582 | "in the current scope")); | |
5583 | /* If we failed to set the right context for this | |
5584 | watchpoint, unconditionally report it. */ | |
5585 | value_is_zero = 0; | |
18a18393 | 5586 | } |
7d4df6a4 DE |
5587 | /* FIXME-someday, should give breakpoint #. */ |
5588 | value_free_to_mark (mark); | |
18a18393 | 5589 | } |
7d4df6a4 DE |
5590 | |
5591 | if (cond && value_is_zero) | |
5592 | { | |
5593 | bs->stop = 0; | |
5594 | } | |
7d4df6a4 DE |
5595 | else if (b->ignore_count > 0) |
5596 | { | |
5597 | b->ignore_count--; | |
5598 | bs->stop = 0; | |
5599 | /* Increase the hit count even though we don't stop. */ | |
5600 | ++(b->hit_count); | |
5601 | observer_notify_breakpoint_modified (b); | |
5602 | } | |
18a18393 VP |
5603 | } |
5604 | ||
1cf4d951 PA |
5605 | /* Returns true if we need to track moribund locations of LOC's type |
5606 | on the current target. */ | |
5607 | ||
5608 | static int | |
5609 | need_moribund_for_location_type (struct bp_location *loc) | |
5610 | { | |
5611 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5612 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5613 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5614 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5615 | } | |
5616 | ||
18a18393 | 5617 | |
9709f61c | 5618 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5619 | BP_ADDR in thread PTID. |
c906108c | 5620 | |
d983da9c | 5621 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5622 | don't understand this stop. Result is a chain of bpstat's such |
5623 | that: | |
c906108c | 5624 | |
c5aa993b | 5625 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5626 | |
c5aa993b | 5627 | if we understand why we stopped, the result is not null. |
c906108c | 5628 | |
c5aa993b JM |
5629 | Each element of the chain refers to a particular breakpoint or |
5630 | watchpoint at which we have stopped. (We may have stopped for | |
5631 | several reasons concurrently.) | |
c906108c | 5632 | |
c5aa993b JM |
5633 | Each element of the chain has valid next, breakpoint_at, |
5634 | commands, FIXME??? fields. */ | |
c906108c SS |
5635 | |
5636 | bpstat | |
6c95b8df | 5637 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5638 | CORE_ADDR bp_addr, ptid_t ptid, |
5639 | const struct target_waitstatus *ws) | |
c906108c | 5640 | { |
0d381245 | 5641 | struct breakpoint *b = NULL; |
afe38095 | 5642 | struct bp_location *bl; |
20874c92 | 5643 | struct bp_location *loc; |
5760d0ab JK |
5644 | /* First item of allocated bpstat's. */ |
5645 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5646 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5647 | bpstat bs; |
20874c92 | 5648 | int ix; |
429374b8 | 5649 | int need_remove_insert; |
f431efe5 | 5650 | int removed_any; |
c906108c | 5651 | |
f431efe5 PA |
5652 | /* First, build the bpstat chain with locations that explain a |
5653 | target stop, while being careful to not set the target running, | |
5654 | as that may invalidate locations (in particular watchpoint | |
5655 | locations are recreated). Resuming will happen here with | |
5656 | breakpoint conditions or watchpoint expressions that include | |
5657 | inferior function calls. */ | |
c5aa993b | 5658 | |
429374b8 JK |
5659 | ALL_BREAKPOINTS (b) |
5660 | { | |
1a853c52 | 5661 | if (!breakpoint_enabled (b)) |
429374b8 | 5662 | continue; |
a5606eee | 5663 | |
429374b8 JK |
5664 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5665 | { | |
4a64f543 MS |
5666 | /* For hardware watchpoints, we look only at the first |
5667 | location. The watchpoint_check function will work on the | |
5668 | entire expression, not the individual locations. For | |
5669 | read watchpoints, the watchpoints_triggered function has | |
5670 | checked all locations already. */ | |
429374b8 JK |
5671 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5672 | break; | |
18a18393 | 5673 | |
f6592439 | 5674 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5675 | continue; |
c5aa993b | 5676 | |
09ac7c10 | 5677 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5678 | continue; |
c5aa993b | 5679 | |
4a64f543 MS |
5680 | /* Come here if it's a watchpoint, or if the break address |
5681 | matches. */ | |
c5aa993b | 5682 | |
4a64f543 MS |
5683 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5684 | explain stop. */ | |
c5aa993b | 5685 | |
f431efe5 PA |
5686 | /* Assume we stop. Should we find a watchpoint that is not |
5687 | actually triggered, or if the condition of the breakpoint | |
5688 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5689 | bs->stop = 1; |
5690 | bs->print = 1; | |
d983da9c | 5691 | |
f431efe5 PA |
5692 | /* If this is a scope breakpoint, mark the associated |
5693 | watchpoint as triggered so that we will handle the | |
5694 | out-of-scope event. We'll get to the watchpoint next | |
5695 | iteration. */ | |
d0fb5eae | 5696 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5697 | { |
5698 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5699 | ||
5700 | w->watchpoint_triggered = watch_triggered_yes; | |
5701 | } | |
f431efe5 PA |
5702 | } |
5703 | } | |
5704 | ||
7c16b83e | 5705 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5706 | if (!target_supports_stopped_by_sw_breakpoint () |
5707 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5708 | { |
1cf4d951 | 5709 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5710 | { |
1cf4d951 PA |
5711 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5712 | && need_moribund_for_location_type (loc)) | |
5713 | { | |
5714 | bs = bpstat_alloc (loc, &bs_link); | |
5715 | /* For hits of moribund locations, we should just proceed. */ | |
5716 | bs->stop = 0; | |
5717 | bs->print = 0; | |
5718 | bs->print_it = print_it_noop; | |
5719 | } | |
f431efe5 PA |
5720 | } |
5721 | } | |
5722 | ||
edcc5120 TT |
5723 | /* A bit of special processing for shlib breakpoints. We need to |
5724 | process solib loading here, so that the lists of loaded and | |
5725 | unloaded libraries are correct before we handle "catch load" and | |
5726 | "catch unload". */ | |
5727 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5728 | { | |
5d268276 | 5729 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5730 | { |
5731 | handle_solib_event (); | |
5732 | break; | |
5733 | } | |
5734 | } | |
5735 | ||
f431efe5 PA |
5736 | /* Now go through the locations that caused the target to stop, and |
5737 | check whether we're interested in reporting this stop to higher | |
5738 | layers, or whether we should resume the target transparently. */ | |
5739 | ||
5740 | removed_any = 0; | |
5741 | ||
5760d0ab | 5742 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5743 | { |
5744 | if (!bs->stop) | |
5745 | continue; | |
5746 | ||
f431efe5 | 5747 | b = bs->breakpoint_at; |
348d480f PA |
5748 | b->ops->check_status (bs); |
5749 | if (bs->stop) | |
28010a5d | 5750 | { |
348d480f | 5751 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5752 | |
429374b8 JK |
5753 | if (bs->stop) |
5754 | { | |
5755 | ++(b->hit_count); | |
8d3788bd | 5756 | observer_notify_breakpoint_modified (b); |
c906108c | 5757 | |
4a64f543 | 5758 | /* We will stop here. */ |
429374b8 JK |
5759 | if (b->disposition == disp_disable) |
5760 | { | |
816338b5 | 5761 | --(b->enable_count); |
1a853c52 | 5762 | if (b->enable_count <= 0) |
429374b8 | 5763 | b->enable_state = bp_disabled; |
f431efe5 | 5764 | removed_any = 1; |
429374b8 JK |
5765 | } |
5766 | if (b->silent) | |
5767 | bs->print = 0; | |
5768 | bs->commands = b->commands; | |
9add0f1b | 5769 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5770 | if (command_line_is_silent (bs->commands |
5771 | ? bs->commands->commands : NULL)) | |
5772 | bs->print = 0; | |
9d6e6e84 HZ |
5773 | |
5774 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5775 | } |
5776 | ||
348d480f | 5777 | } |
a9b3a50f PA |
5778 | |
5779 | /* Print nothing for this entry if we don't stop or don't | |
5780 | print. */ | |
5781 | if (!bs->stop || !bs->print) | |
5782 | bs->print_it = print_it_noop; | |
429374b8 | 5783 | } |
876fa593 | 5784 | |
d983da9c DJ |
5785 | /* If we aren't stopping, the value of some hardware watchpoint may |
5786 | not have changed, but the intermediate memory locations we are | |
5787 | watching may have. Don't bother if we're stopping; this will get | |
5788 | done later. */ | |
d832cb68 | 5789 | need_remove_insert = 0; |
5760d0ab JK |
5790 | if (! bpstat_causes_stop (bs_head)) |
5791 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5792 | if (!bs->stop |
f431efe5 PA |
5793 | && bs->breakpoint_at |
5794 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5795 | { |
3a5c3e22 PA |
5796 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5797 | ||
5798 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5799 | need_remove_insert = 1; |
d983da9c DJ |
5800 | } |
5801 | ||
d832cb68 | 5802 | if (need_remove_insert) |
44702360 | 5803 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5804 | else if (removed_any) |
44702360 | 5805 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5806 | |
5760d0ab | 5807 | return bs_head; |
c906108c | 5808 | } |
628fe4e4 JK |
5809 | |
5810 | static void | |
5811 | handle_jit_event (void) | |
5812 | { | |
5813 | struct frame_info *frame; | |
5814 | struct gdbarch *gdbarch; | |
5815 | ||
243a9253 PA |
5816 | if (debug_infrun) |
5817 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5818 | ||
628fe4e4 JK |
5819 | /* Switch terminal for any messages produced by |
5820 | breakpoint_re_set. */ | |
5821 | target_terminal_ours_for_output (); | |
5822 | ||
5823 | frame = get_current_frame (); | |
5824 | gdbarch = get_frame_arch (frame); | |
5825 | ||
5826 | jit_event_handler (gdbarch); | |
5827 | ||
5828 | target_terminal_inferior (); | |
5829 | } | |
5830 | ||
5831 | /* Prepare WHAT final decision for infrun. */ | |
5832 | ||
5833 | /* Decide what infrun needs to do with this bpstat. */ | |
5834 | ||
c906108c | 5835 | struct bpstat_what |
0e30163f | 5836 | bpstat_what (bpstat bs_head) |
c906108c | 5837 | { |
c906108c | 5838 | struct bpstat_what retval; |
0e30163f | 5839 | bpstat bs; |
c906108c | 5840 | |
628fe4e4 | 5841 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5842 | retval.call_dummy = STOP_NONE; |
186c406b | 5843 | retval.is_longjmp = 0; |
628fe4e4 | 5844 | |
0e30163f | 5845 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5846 | { |
628fe4e4 JK |
5847 | /* Extract this BS's action. After processing each BS, we check |
5848 | if its action overrides all we've seem so far. */ | |
5849 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5850 | enum bptype bptype; | |
5851 | ||
c906108c | 5852 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5853 | { |
5854 | /* I suspect this can happen if it was a momentary | |
5855 | breakpoint which has since been deleted. */ | |
5856 | bptype = bp_none; | |
5857 | } | |
20874c92 | 5858 | else |
f431efe5 | 5859 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5860 | |
5861 | switch (bptype) | |
c906108c SS |
5862 | { |
5863 | case bp_none: | |
628fe4e4 | 5864 | break; |
c906108c SS |
5865 | case bp_breakpoint: |
5866 | case bp_hardware_breakpoint: | |
7c16b83e | 5867 | case bp_single_step: |
c906108c SS |
5868 | case bp_until: |
5869 | case bp_finish: | |
a9b3a50f | 5870 | case bp_shlib_event: |
c906108c SS |
5871 | if (bs->stop) |
5872 | { | |
5873 | if (bs->print) | |
628fe4e4 | 5874 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5875 | else |
628fe4e4 | 5876 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5877 | } |
5878 | else | |
628fe4e4 | 5879 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5880 | break; |
5881 | case bp_watchpoint: | |
5882 | case bp_hardware_watchpoint: | |
5883 | case bp_read_watchpoint: | |
5884 | case bp_access_watchpoint: | |
5885 | if (bs->stop) | |
5886 | { | |
5887 | if (bs->print) | |
628fe4e4 | 5888 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5889 | else |
628fe4e4 | 5890 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5891 | } |
5892 | else | |
628fe4e4 JK |
5893 | { |
5894 | /* There was a watchpoint, but we're not stopping. | |
5895 | This requires no further action. */ | |
5896 | } | |
c906108c SS |
5897 | break; |
5898 | case bp_longjmp: | |
e2e4d78b | 5899 | case bp_longjmp_call_dummy: |
186c406b | 5900 | case bp_exception: |
0a39bb32 PA |
5901 | if (bs->stop) |
5902 | { | |
5903 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5904 | retval.is_longjmp = bptype != bp_exception; | |
5905 | } | |
5906 | else | |
5907 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5908 | break; |
5909 | case bp_longjmp_resume: | |
186c406b | 5910 | case bp_exception_resume: |
0a39bb32 PA |
5911 | if (bs->stop) |
5912 | { | |
5913 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5914 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5915 | } | |
5916 | else | |
5917 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5918 | break; |
5919 | case bp_step_resume: | |
5920 | if (bs->stop) | |
628fe4e4 JK |
5921 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5922 | else | |
c906108c | 5923 | { |
628fe4e4 JK |
5924 | /* It is for the wrong frame. */ |
5925 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5926 | } |
c906108c | 5927 | break; |
2c03e5be PA |
5928 | case bp_hp_step_resume: |
5929 | if (bs->stop) | |
5930 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5931 | else | |
5932 | { | |
5933 | /* It is for the wrong frame. */ | |
5934 | this_action = BPSTAT_WHAT_SINGLE; | |
5935 | } | |
5936 | break; | |
c906108c | 5937 | case bp_watchpoint_scope: |
c4093a6a | 5938 | case bp_thread_event: |
1900040c | 5939 | case bp_overlay_event: |
0fd8e87f | 5940 | case bp_longjmp_master: |
aa7d318d | 5941 | case bp_std_terminate_master: |
186c406b | 5942 | case bp_exception_master: |
628fe4e4 | 5943 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5944 | break; |
ce78b96d | 5945 | case bp_catchpoint: |
c5aa993b JM |
5946 | if (bs->stop) |
5947 | { | |
5948 | if (bs->print) | |
628fe4e4 | 5949 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5950 | else |
628fe4e4 | 5951 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5952 | } |
5953 | else | |
628fe4e4 JK |
5954 | { |
5955 | /* There was a catchpoint, but we're not stopping. | |
5956 | This requires no further action. */ | |
5957 | } | |
5958 | break; | |
628fe4e4 | 5959 | case bp_jit_event: |
628fe4e4 | 5960 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5961 | break; |
c906108c | 5962 | case bp_call_dummy: |
53a5351d JM |
5963 | /* Make sure the action is stop (silent or noisy), |
5964 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5965 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5966 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5967 | break; |
5968 | case bp_std_terminate: | |
5969 | /* Make sure the action is stop (silent or noisy), | |
5970 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5971 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5972 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5973 | break; |
1042e4c0 | 5974 | case bp_tracepoint: |
7a697b8d | 5975 | case bp_fast_tracepoint: |
0fb4aa4b | 5976 | case bp_static_tracepoint: |
1042e4c0 SS |
5977 | /* Tracepoint hits should not be reported back to GDB, and |
5978 | if one got through somehow, it should have been filtered | |
5979 | out already. */ | |
5980 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5981 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5982 | break; |
5983 | case bp_gnu_ifunc_resolver: | |
5984 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5985 | this_action = BPSTAT_WHAT_SINGLE; | |
5986 | break; | |
5987 | case bp_gnu_ifunc_resolver_return: | |
5988 | /* The breakpoint will be removed, execution will restart from the | |
5989 | PC of the former breakpoint. */ | |
5990 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5991 | break; | |
e7e0cddf SS |
5992 | |
5993 | case bp_dprintf: | |
a11cfd87 HZ |
5994 | if (bs->stop) |
5995 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5996 | else | |
5997 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5998 | break; |
5999 | ||
628fe4e4 JK |
6000 | default: |
6001 | internal_error (__FILE__, __LINE__, | |
6002 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 6003 | } |
628fe4e4 JK |
6004 | |
6005 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 6006 | } |
628fe4e4 | 6007 | |
243a9253 PA |
6008 | return retval; |
6009 | } | |
628fe4e4 | 6010 | |
243a9253 PA |
6011 | void |
6012 | bpstat_run_callbacks (bpstat bs_head) | |
6013 | { | |
6014 | bpstat bs; | |
628fe4e4 | 6015 | |
0e30163f JK |
6016 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6017 | { | |
6018 | struct breakpoint *b = bs->breakpoint_at; | |
6019 | ||
6020 | if (b == NULL) | |
6021 | continue; | |
6022 | switch (b->type) | |
6023 | { | |
243a9253 PA |
6024 | case bp_jit_event: |
6025 | handle_jit_event (); | |
6026 | break; | |
0e30163f JK |
6027 | case bp_gnu_ifunc_resolver: |
6028 | gnu_ifunc_resolver_stop (b); | |
6029 | break; | |
6030 | case bp_gnu_ifunc_resolver_return: | |
6031 | gnu_ifunc_resolver_return_stop (b); | |
6032 | break; | |
6033 | } | |
6034 | } | |
c906108c SS |
6035 | } |
6036 | ||
6037 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6038 | without hardware support). This isn't related to a specific bpstat, | |
6039 | just to things like whether watchpoints are set. */ | |
6040 | ||
c5aa993b | 6041 | int |
fba45db2 | 6042 | bpstat_should_step (void) |
c906108c SS |
6043 | { |
6044 | struct breakpoint *b; | |
cc59ec59 | 6045 | |
c906108c | 6046 | ALL_BREAKPOINTS (b) |
717a8278 | 6047 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6048 | return 1; |
c906108c SS |
6049 | return 0; |
6050 | } | |
6051 | ||
67822962 PA |
6052 | int |
6053 | bpstat_causes_stop (bpstat bs) | |
6054 | { | |
6055 | for (; bs != NULL; bs = bs->next) | |
6056 | if (bs->stop) | |
6057 | return 1; | |
6058 | ||
6059 | return 0; | |
6060 | } | |
6061 | ||
c906108c | 6062 | \f |
c5aa993b | 6063 | |
170b53b2 UW |
6064 | /* Compute a string of spaces suitable to indent the next line |
6065 | so it starts at the position corresponding to the table column | |
6066 | named COL_NAME in the currently active table of UIOUT. */ | |
6067 | ||
6068 | static char * | |
6069 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6070 | { | |
6071 | static char wrap_indent[80]; | |
6072 | int i, total_width, width, align; | |
6073 | char *text; | |
6074 | ||
6075 | total_width = 0; | |
6076 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6077 | { | |
6078 | if (strcmp (text, col_name) == 0) | |
6079 | { | |
6080 | gdb_assert (total_width < sizeof wrap_indent); | |
6081 | memset (wrap_indent, ' ', total_width); | |
6082 | wrap_indent[total_width] = 0; | |
6083 | ||
6084 | return wrap_indent; | |
6085 | } | |
6086 | ||
6087 | total_width += width + 1; | |
6088 | } | |
6089 | ||
6090 | return NULL; | |
6091 | } | |
6092 | ||
b775012e LM |
6093 | /* Determine if the locations of this breakpoint will have their conditions |
6094 | evaluated by the target, host or a mix of both. Returns the following: | |
6095 | ||
6096 | "host": Host evals condition. | |
6097 | "host or target": Host or Target evals condition. | |
6098 | "target": Target evals condition. | |
6099 | */ | |
6100 | ||
6101 | static const char * | |
6102 | bp_condition_evaluator (struct breakpoint *b) | |
6103 | { | |
6104 | struct bp_location *bl; | |
6105 | char host_evals = 0; | |
6106 | char target_evals = 0; | |
6107 | ||
6108 | if (!b) | |
6109 | return NULL; | |
6110 | ||
6111 | if (!is_breakpoint (b)) | |
6112 | return NULL; | |
6113 | ||
6114 | if (gdb_evaluates_breakpoint_condition_p () | |
6115 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6116 | return condition_evaluation_host; | |
6117 | ||
6118 | for (bl = b->loc; bl; bl = bl->next) | |
6119 | { | |
6120 | if (bl->cond_bytecode) | |
6121 | target_evals++; | |
6122 | else | |
6123 | host_evals++; | |
6124 | } | |
6125 | ||
6126 | if (host_evals && target_evals) | |
6127 | return condition_evaluation_both; | |
6128 | else if (target_evals) | |
6129 | return condition_evaluation_target; | |
6130 | else | |
6131 | return condition_evaluation_host; | |
6132 | } | |
6133 | ||
6134 | /* Determine the breakpoint location's condition evaluator. This is | |
6135 | similar to bp_condition_evaluator, but for locations. */ | |
6136 | ||
6137 | static const char * | |
6138 | bp_location_condition_evaluator (struct bp_location *bl) | |
6139 | { | |
6140 | if (bl && !is_breakpoint (bl->owner)) | |
6141 | return NULL; | |
6142 | ||
6143 | if (gdb_evaluates_breakpoint_condition_p () | |
6144 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6145 | return condition_evaluation_host; | |
6146 | ||
6147 | if (bl && bl->cond_bytecode) | |
6148 | return condition_evaluation_target; | |
6149 | else | |
6150 | return condition_evaluation_host; | |
6151 | } | |
6152 | ||
859825b8 JK |
6153 | /* Print the LOC location out of the list of B->LOC locations. */ |
6154 | ||
170b53b2 UW |
6155 | static void |
6156 | print_breakpoint_location (struct breakpoint *b, | |
6157 | struct bp_location *loc) | |
0d381245 | 6158 | { |
79a45e25 | 6159 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6160 | struct cleanup *old_chain = save_current_program_space (); |
6161 | ||
859825b8 JK |
6162 | if (loc != NULL && loc->shlib_disabled) |
6163 | loc = NULL; | |
6164 | ||
6c95b8df PA |
6165 | if (loc != NULL) |
6166 | set_current_program_space (loc->pspace); | |
6167 | ||
56435ebe | 6168 | if (b->display_canonical) |
f00aae0f KS |
6169 | ui_out_field_string (uiout, "what", |
6170 | event_location_to_string (b->location)); | |
2f202fde | 6171 | else if (loc && loc->symtab) |
0d381245 VP |
6172 | { |
6173 | struct symbol *sym | |
6174 | = find_pc_sect_function (loc->address, loc->section); | |
6175 | if (sym) | |
6176 | { | |
6177 | ui_out_text (uiout, "in "); | |
6178 | ui_out_field_string (uiout, "func", | |
6179 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6180 | ui_out_text (uiout, " "); |
6181 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6182 | ui_out_text (uiout, "at "); | |
0d381245 | 6183 | } |
05cba821 JK |
6184 | ui_out_field_string (uiout, "file", |
6185 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6186 | ui_out_text (uiout, ":"); |
05cba821 | 6187 | |
0d381245 | 6188 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6189 | ui_out_field_string (uiout, "fullname", |
6190 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6191 | |
f8eba3c6 | 6192 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6193 | } |
859825b8 | 6194 | else if (loc) |
0d381245 | 6195 | { |
f99d8bf4 PA |
6196 | struct ui_file *stb = mem_fileopen (); |
6197 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6198 | |
f99d8bf4 | 6199 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6200 | demangle, ""); |
0d381245 | 6201 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6202 | |
6203 | do_cleanups (stb_chain); | |
0d381245 | 6204 | } |
859825b8 | 6205 | else |
f00aae0f KS |
6206 | { |
6207 | ui_out_field_string (uiout, "pending", | |
6208 | event_location_to_string (b->location)); | |
6209 | /* If extra_string is available, it could be holding a condition | |
6210 | or dprintf arguments. In either case, make sure it is printed, | |
6211 | too, but only for non-MI streams. */ | |
6212 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6213 | { | |
6214 | if (b->type == bp_dprintf) | |
6215 | ui_out_text (uiout, ","); | |
6216 | else | |
6217 | ui_out_text (uiout, " "); | |
6218 | ui_out_text (uiout, b->extra_string); | |
6219 | } | |
6220 | } | |
6c95b8df | 6221 | |
b775012e LM |
6222 | if (loc && is_breakpoint (b) |
6223 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6224 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6225 | { | |
6226 | ui_out_text (uiout, " ("); | |
6227 | ui_out_field_string (uiout, "evaluated-by", | |
6228 | bp_location_condition_evaluator (loc)); | |
6229 | ui_out_text (uiout, ")"); | |
6230 | } | |
6231 | ||
6c95b8df | 6232 | do_cleanups (old_chain); |
0d381245 VP |
6233 | } |
6234 | ||
269b11a2 PA |
6235 | static const char * |
6236 | bptype_string (enum bptype type) | |
c906108c | 6237 | { |
c4093a6a JM |
6238 | struct ep_type_description |
6239 | { | |
6240 | enum bptype type; | |
6241 | char *description; | |
6242 | }; | |
6243 | static struct ep_type_description bptypes[] = | |
c906108c | 6244 | { |
c5aa993b JM |
6245 | {bp_none, "?deleted?"}, |
6246 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6247 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6248 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6249 | {bp_until, "until"}, |
6250 | {bp_finish, "finish"}, | |
6251 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6252 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6253 | {bp_read_watchpoint, "read watchpoint"}, |
6254 | {bp_access_watchpoint, "acc watchpoint"}, | |
6255 | {bp_longjmp, "longjmp"}, | |
6256 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6257 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6258 | {bp_exception, "exception"}, |
6259 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6260 | {bp_step_resume, "step resume"}, |
2c03e5be | 6261 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6262 | {bp_watchpoint_scope, "watchpoint scope"}, |
6263 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6264 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6265 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6266 | {bp_thread_event, "thread events"}, |
1900040c | 6267 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6268 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6269 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6270 | {bp_exception_master, "exception master"}, |
ce78b96d | 6271 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6272 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6273 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6274 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6275 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6276 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6277 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6278 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6279 | }; |
269b11a2 PA |
6280 | |
6281 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6282 | || ((int) type != bptypes[(int) type].type)) | |
6283 | internal_error (__FILE__, __LINE__, | |
6284 | _("bptypes table does not describe type #%d."), | |
6285 | (int) type); | |
6286 | ||
6287 | return bptypes[(int) type].description; | |
6288 | } | |
6289 | ||
998580f1 MK |
6290 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6291 | For CLI, prefix the list with the string 'inf'. */ | |
6292 | ||
6293 | static void | |
6294 | output_thread_groups (struct ui_out *uiout, | |
6295 | const char *field_name, | |
6296 | VEC(int) *inf_num, | |
6297 | int mi_only) | |
6298 | { | |
752eb8b4 | 6299 | struct cleanup *back_to; |
998580f1 MK |
6300 | int is_mi = ui_out_is_mi_like_p (uiout); |
6301 | int inf; | |
6302 | int i; | |
6303 | ||
6304 | /* For backward compatibility, don't display inferiors in CLI unless | |
6305 | there are several. Always display them for MI. */ | |
6306 | if (!is_mi && mi_only) | |
6307 | return; | |
6308 | ||
752eb8b4 TT |
6309 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6310 | ||
998580f1 MK |
6311 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6312 | { | |
6313 | if (is_mi) | |
6314 | { | |
6315 | char mi_group[10]; | |
6316 | ||
6317 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6318 | ui_out_field_string (uiout, NULL, mi_group); | |
6319 | } | |
6320 | else | |
6321 | { | |
6322 | if (i == 0) | |
6323 | ui_out_text (uiout, " inf "); | |
6324 | else | |
6325 | ui_out_text (uiout, ", "); | |
6326 | ||
6327 | ui_out_text (uiout, plongest (inf)); | |
6328 | } | |
6329 | } | |
6330 | ||
6331 | do_cleanups (back_to); | |
6332 | } | |
6333 | ||
269b11a2 PA |
6334 | /* Print B to gdb_stdout. */ |
6335 | ||
6336 | static void | |
6337 | print_one_breakpoint_location (struct breakpoint *b, | |
6338 | struct bp_location *loc, | |
6339 | int loc_number, | |
6340 | struct bp_location **last_loc, | |
269b11a2 PA |
6341 | int allflag) |
6342 | { | |
6343 | struct command_line *l; | |
c2c6d25f | 6344 | static char bpenables[] = "nynny"; |
c906108c | 6345 | |
79a45e25 | 6346 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6347 | int header_of_multiple = 0; |
6348 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6349 | struct value_print_options opts; |
6350 | ||
6351 | get_user_print_options (&opts); | |
0d381245 VP |
6352 | |
6353 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6354 | /* See comment in print_one_breakpoint concerning treatment of |
6355 | breakpoints with single disabled location. */ | |
0d381245 VP |
6356 | if (loc == NULL |
6357 | && (b->loc != NULL | |
6358 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6359 | header_of_multiple = 1; | |
6360 | if (loc == NULL) | |
6361 | loc = b->loc; | |
6362 | ||
c4093a6a JM |
6363 | annotate_record (); |
6364 | ||
6365 | /* 1 */ | |
6366 | annotate_field (0); | |
0d381245 VP |
6367 | if (part_of_multiple) |
6368 | { | |
6369 | char *formatted; | |
0c6773c1 | 6370 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6371 | ui_out_field_string (uiout, "number", formatted); |
6372 | xfree (formatted); | |
6373 | } | |
6374 | else | |
6375 | { | |
6376 | ui_out_field_int (uiout, "number", b->number); | |
6377 | } | |
c4093a6a JM |
6378 | |
6379 | /* 2 */ | |
6380 | annotate_field (1); | |
0d381245 VP |
6381 | if (part_of_multiple) |
6382 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6383 | else |
6384 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6385 | |
6386 | /* 3 */ | |
6387 | annotate_field (2); | |
0d381245 VP |
6388 | if (part_of_multiple) |
6389 | ui_out_field_skip (uiout, "disp"); | |
6390 | else | |
2cec12e5 | 6391 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6392 | |
c4093a6a JM |
6393 | |
6394 | /* 4 */ | |
6395 | annotate_field (3); | |
0d381245 | 6396 | if (part_of_multiple) |
54e52265 | 6397 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6398 | else |
4a64f543 MS |
6399 | ui_out_field_fmt (uiout, "enabled", "%c", |
6400 | bpenables[(int) b->enable_state]); | |
54e52265 | 6401 | ui_out_spaces (uiout, 2); |
0d381245 | 6402 | |
c4093a6a JM |
6403 | |
6404 | /* 5 and 6 */ | |
3086aeae | 6405 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6406 | { |
4a64f543 MS |
6407 | /* Although the print_one can possibly print all locations, |
6408 | calling it here is not likely to get any nice result. So, | |
6409 | make sure there's just one location. */ | |
0d381245 | 6410 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6411 | b->ops->print_one (b, last_loc); |
0d381245 | 6412 | } |
3086aeae DJ |
6413 | else |
6414 | switch (b->type) | |
6415 | { | |
6416 | case bp_none: | |
6417 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6418 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6419 | break; |
c906108c | 6420 | |
3086aeae DJ |
6421 | case bp_watchpoint: |
6422 | case bp_hardware_watchpoint: | |
6423 | case bp_read_watchpoint: | |
6424 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6425 | { |
6426 | struct watchpoint *w = (struct watchpoint *) b; | |
6427 | ||
6428 | /* Field 4, the address, is omitted (which makes the columns | |
6429 | not line up too nicely with the headers, but the effect | |
6430 | is relatively readable). */ | |
6431 | if (opts.addressprint) | |
6432 | ui_out_field_skip (uiout, "addr"); | |
6433 | annotate_field (5); | |
6434 | ui_out_field_string (uiout, "what", w->exp_string); | |
6435 | } | |
3086aeae DJ |
6436 | break; |
6437 | ||
3086aeae DJ |
6438 | case bp_breakpoint: |
6439 | case bp_hardware_breakpoint: | |
7c16b83e | 6440 | case bp_single_step: |
3086aeae DJ |
6441 | case bp_until: |
6442 | case bp_finish: | |
6443 | case bp_longjmp: | |
6444 | case bp_longjmp_resume: | |
e2e4d78b | 6445 | case bp_longjmp_call_dummy: |
186c406b TT |
6446 | case bp_exception: |
6447 | case bp_exception_resume: | |
3086aeae | 6448 | case bp_step_resume: |
2c03e5be | 6449 | case bp_hp_step_resume: |
3086aeae DJ |
6450 | case bp_watchpoint_scope: |
6451 | case bp_call_dummy: | |
aa7d318d | 6452 | case bp_std_terminate: |
3086aeae DJ |
6453 | case bp_shlib_event: |
6454 | case bp_thread_event: | |
6455 | case bp_overlay_event: | |
0fd8e87f | 6456 | case bp_longjmp_master: |
aa7d318d | 6457 | case bp_std_terminate_master: |
186c406b | 6458 | case bp_exception_master: |
1042e4c0 | 6459 | case bp_tracepoint: |
7a697b8d | 6460 | case bp_fast_tracepoint: |
0fb4aa4b | 6461 | case bp_static_tracepoint: |
e7e0cddf | 6462 | case bp_dprintf: |
4efc6507 | 6463 | case bp_jit_event: |
0e30163f JK |
6464 | case bp_gnu_ifunc_resolver: |
6465 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6466 | if (opts.addressprint) |
3086aeae DJ |
6467 | { |
6468 | annotate_field (4); | |
54e52265 | 6469 | if (header_of_multiple) |
0d381245 | 6470 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6471 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6472 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6473 | else |
5af949e3 UW |
6474 | ui_out_field_core_addr (uiout, "addr", |
6475 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6476 | } |
6477 | annotate_field (5); | |
0d381245 | 6478 | if (!header_of_multiple) |
170b53b2 | 6479 | print_breakpoint_location (b, loc); |
0d381245 | 6480 | if (b->loc) |
a6d9a66e | 6481 | *last_loc = b->loc; |
3086aeae DJ |
6482 | break; |
6483 | } | |
c906108c | 6484 | |
6c95b8df | 6485 | |
998580f1 | 6486 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6487 | { |
6488 | struct inferior *inf; | |
998580f1 MK |
6489 | VEC(int) *inf_num = NULL; |
6490 | int mi_only = 1; | |
6c95b8df | 6491 | |
998580f1 | 6492 | ALL_INFERIORS (inf) |
6c95b8df PA |
6493 | { |
6494 | if (inf->pspace == loc->pspace) | |
998580f1 | 6495 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6496 | } |
998580f1 MK |
6497 | |
6498 | /* For backward compatibility, don't display inferiors in CLI unless | |
6499 | there are several. Always display for MI. */ | |
6500 | if (allflag | |
6501 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6502 | && (number_of_program_spaces () > 1 | |
6503 | || number_of_inferiors () > 1) | |
6504 | /* LOC is for existing B, it cannot be in | |
6505 | moribund_locations and thus having NULL OWNER. */ | |
6506 | && loc->owner->type != bp_catchpoint)) | |
6507 | mi_only = 0; | |
6508 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6509 | VEC_free (int, inf_num); | |
6c95b8df PA |
6510 | } |
6511 | ||
4a306c9a | 6512 | if (!part_of_multiple) |
c4093a6a | 6513 | { |
4a306c9a JB |
6514 | if (b->thread != -1) |
6515 | { | |
6516 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6517 | "stop only in" line a little further down. */ |
4a306c9a JB |
6518 | ui_out_text (uiout, " thread "); |
6519 | ui_out_field_int (uiout, "thread", b->thread); | |
6520 | } | |
6521 | else if (b->task != 0) | |
6522 | { | |
6523 | ui_out_text (uiout, " task "); | |
6524 | ui_out_field_int (uiout, "task", b->task); | |
6525 | } | |
c4093a6a | 6526 | } |
f1310107 | 6527 | |
8b93c638 | 6528 | ui_out_text (uiout, "\n"); |
f1310107 | 6529 | |
348d480f | 6530 | if (!part_of_multiple) |
f1310107 TJB |
6531 | b->ops->print_one_detail (b, uiout); |
6532 | ||
0d381245 | 6533 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6534 | { |
6535 | annotate_field (6); | |
8b93c638 | 6536 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6537 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6538 | the frame ID. */ |
5af949e3 UW |
6539 | ui_out_field_core_addr (uiout, "frame", |
6540 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6541 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6542 | } |
6543 | ||
28010a5d | 6544 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6545 | { |
6546 | annotate_field (7); | |
d77f58be | 6547 | if (is_tracepoint (b)) |
1042e4c0 SS |
6548 | ui_out_text (uiout, "\ttrace only if "); |
6549 | else | |
6550 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6551 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6552 | |
6553 | /* Print whether the target is doing the breakpoint's condition | |
6554 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6555 | if (is_breakpoint (b) | |
6556 | && breakpoint_condition_evaluation_mode () | |
6557 | == condition_evaluation_target) | |
6558 | { | |
6559 | ui_out_text (uiout, " ("); | |
6560 | ui_out_field_string (uiout, "evaluated-by", | |
6561 | bp_condition_evaluator (b)); | |
6562 | ui_out_text (uiout, " evals)"); | |
6563 | } | |
0101ce28 JJ |
6564 | ui_out_text (uiout, "\n"); |
6565 | } | |
6566 | ||
0d381245 | 6567 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6568 | { |
4a64f543 | 6569 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6570 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6571 | if (ui_out_is_mi_like_p (uiout)) |
6572 | ui_out_field_int (uiout, "thread", b->thread); | |
6573 | else | |
6574 | { | |
6575 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6576 | ||
6577 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6578 | } | |
8b93c638 | 6579 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6580 | } |
6581 | ||
556ec64d YQ |
6582 | if (!part_of_multiple) |
6583 | { | |
6584 | if (b->hit_count) | |
31f56a27 YQ |
6585 | { |
6586 | /* FIXME should make an annotation for this. */ | |
6587 | if (is_catchpoint (b)) | |
6588 | ui_out_text (uiout, "\tcatchpoint"); | |
6589 | else if (is_tracepoint (b)) | |
6590 | ui_out_text (uiout, "\ttracepoint"); | |
6591 | else | |
6592 | ui_out_text (uiout, "\tbreakpoint"); | |
6593 | ui_out_text (uiout, " already hit "); | |
6594 | ui_out_field_int (uiout, "times", b->hit_count); | |
6595 | if (b->hit_count == 1) | |
6596 | ui_out_text (uiout, " time\n"); | |
6597 | else | |
6598 | ui_out_text (uiout, " times\n"); | |
6599 | } | |
556ec64d YQ |
6600 | else |
6601 | { | |
31f56a27 YQ |
6602 | /* Output the count also if it is zero, but only if this is mi. */ |
6603 | if (ui_out_is_mi_like_p (uiout)) | |
6604 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6605 | } |
6606 | } | |
8b93c638 | 6607 | |
0d381245 | 6608 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6609 | { |
6610 | annotate_field (8); | |
8b93c638 JM |
6611 | ui_out_text (uiout, "\tignore next "); |
6612 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6613 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6614 | } |
059fb39f | 6615 | |
816338b5 SS |
6616 | /* Note that an enable count of 1 corresponds to "enable once" |
6617 | behavior, which is reported by the combination of enablement and | |
6618 | disposition, so we don't need to mention it here. */ | |
6619 | if (!part_of_multiple && b->enable_count > 1) | |
6620 | { | |
6621 | annotate_field (8); | |
6622 | ui_out_text (uiout, "\tdisable after "); | |
6623 | /* Tweak the wording to clarify that ignore and enable counts | |
6624 | are distinct, and have additive effect. */ | |
6625 | if (b->ignore_count) | |
6626 | ui_out_text (uiout, "additional "); | |
6627 | else | |
6628 | ui_out_text (uiout, "next "); | |
6629 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6630 | ui_out_text (uiout, " hits\n"); | |
6631 | } | |
6632 | ||
f196051f SS |
6633 | if (!part_of_multiple && is_tracepoint (b)) |
6634 | { | |
6635 | struct tracepoint *tp = (struct tracepoint *) b; | |
6636 | ||
6637 | if (tp->traceframe_usage) | |
6638 | { | |
6639 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6640 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6641 | ui_out_text (uiout, " bytes\n"); | |
6642 | } | |
6643 | } | |
d3ce09f5 | 6644 | |
9add0f1b | 6645 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6646 | if (!part_of_multiple && l) |
c4093a6a | 6647 | { |
3b31d625 EZ |
6648 | struct cleanup *script_chain; |
6649 | ||
c4093a6a | 6650 | annotate_field (9); |
3b31d625 | 6651 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6652 | print_command_lines (uiout, l, 4); |
3b31d625 | 6653 | do_cleanups (script_chain); |
c4093a6a | 6654 | } |
d24317b4 | 6655 | |
d9b3f62e | 6656 | if (is_tracepoint (b)) |
1042e4c0 | 6657 | { |
d9b3f62e PA |
6658 | struct tracepoint *t = (struct tracepoint *) b; |
6659 | ||
6660 | if (!part_of_multiple && t->pass_count) | |
6661 | { | |
6662 | annotate_field (10); | |
6663 | ui_out_text (uiout, "\tpass count "); | |
6664 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6665 | ui_out_text (uiout, " \n"); | |
6666 | } | |
f2a8bc8a YQ |
6667 | |
6668 | /* Don't display it when tracepoint or tracepoint location is | |
6669 | pending. */ | |
6670 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6671 | { | |
6672 | annotate_field (11); | |
6673 | ||
6674 | if (ui_out_is_mi_like_p (uiout)) | |
6675 | ui_out_field_string (uiout, "installed", | |
6676 | loc->inserted ? "y" : "n"); | |
6677 | else | |
6678 | { | |
6679 | if (loc->inserted) | |
6680 | ui_out_text (uiout, "\t"); | |
6681 | else | |
6682 | ui_out_text (uiout, "\tnot "); | |
6683 | ui_out_text (uiout, "installed on target\n"); | |
6684 | } | |
6685 | } | |
1042e4c0 SS |
6686 | } |
6687 | ||
d24317b4 VP |
6688 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6689 | { | |
3a5c3e22 PA |
6690 | if (is_watchpoint (b)) |
6691 | { | |
6692 | struct watchpoint *w = (struct watchpoint *) b; | |
6693 | ||
6694 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6695 | } | |
f00aae0f KS |
6696 | else if (b->location != NULL |
6697 | && event_location_to_string (b->location) != NULL) | |
6698 | ui_out_field_string (uiout, "original-location", | |
6699 | event_location_to_string (b->location)); | |
d24317b4 | 6700 | } |
c4093a6a | 6701 | } |
c5aa993b | 6702 | |
0d381245 VP |
6703 | static void |
6704 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6705 | struct bp_location **last_loc, |
6c95b8df | 6706 | int allflag) |
0d381245 | 6707 | { |
8d3788bd | 6708 | struct cleanup *bkpt_chain; |
79a45e25 | 6709 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6710 | |
6711 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6712 | ||
12c5a436 | 6713 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6714 | do_cleanups (bkpt_chain); |
0d381245 VP |
6715 | |
6716 | /* If this breakpoint has custom print function, | |
6717 | it's already printed. Otherwise, print individual | |
6718 | locations, if any. */ | |
6719 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6720 | { | |
4a64f543 MS |
6721 | /* If breakpoint has a single location that is disabled, we |
6722 | print it as if it had several locations, since otherwise it's | |
6723 | hard to represent "breakpoint enabled, location disabled" | |
6724 | situation. | |
6725 | ||
6726 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6727 | internally, that's not a property exposed to user. */ |
0d381245 | 6728 | if (b->loc |
a5606eee | 6729 | && !is_hardware_watchpoint (b) |
8d3788bd | 6730 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6731 | { |
6732 | struct bp_location *loc; | |
6733 | int n = 1; | |
8d3788bd | 6734 | |
0d381245 | 6735 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6736 | { |
6737 | struct cleanup *inner2 = | |
6738 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6739 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6740 | do_cleanups (inner2); | |
6741 | } | |
0d381245 VP |
6742 | } |
6743 | } | |
6744 | } | |
6745 | ||
a6d9a66e UW |
6746 | static int |
6747 | breakpoint_address_bits (struct breakpoint *b) | |
6748 | { | |
6749 | int print_address_bits = 0; | |
6750 | struct bp_location *loc; | |
6751 | ||
c6d81124 PA |
6752 | /* Software watchpoints that aren't watching memory don't have an |
6753 | address to print. */ | |
6754 | if (is_no_memory_software_watchpoint (b)) | |
6755 | return 0; | |
6756 | ||
a6d9a66e UW |
6757 | for (loc = b->loc; loc; loc = loc->next) |
6758 | { | |
c7437ca6 PA |
6759 | int addr_bit; |
6760 | ||
c7437ca6 | 6761 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6762 | if (addr_bit > print_address_bits) |
6763 | print_address_bits = addr_bit; | |
6764 | } | |
6765 | ||
6766 | return print_address_bits; | |
6767 | } | |
0d381245 | 6768 | |
c4093a6a JM |
6769 | struct captured_breakpoint_query_args |
6770 | { | |
6771 | int bnum; | |
6772 | }; | |
c5aa993b | 6773 | |
c4093a6a | 6774 | static int |
2b65245e | 6775 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6776 | { |
9a3c8263 SM |
6777 | struct captured_breakpoint_query_args *args |
6778 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6779 | struct breakpoint *b; |
a6d9a66e | 6780 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6781 | |
c4093a6a JM |
6782 | ALL_BREAKPOINTS (b) |
6783 | { | |
6784 | if (args->bnum == b->number) | |
c5aa993b | 6785 | { |
12c5a436 | 6786 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6787 | return GDB_RC_OK; |
c5aa993b | 6788 | } |
c4093a6a JM |
6789 | } |
6790 | return GDB_RC_NONE; | |
6791 | } | |
c5aa993b | 6792 | |
c4093a6a | 6793 | enum gdb_rc |
4a64f543 MS |
6794 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6795 | char **error_message) | |
c4093a6a JM |
6796 | { |
6797 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6798 | |
c4093a6a JM |
6799 | args.bnum = bnum; |
6800 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6801 | an error. */ |
b0b13bb4 DJ |
6802 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6803 | error_message, RETURN_MASK_ALL) < 0) | |
6804 | return GDB_RC_FAIL; | |
6805 | else | |
6806 | return GDB_RC_OK; | |
c4093a6a | 6807 | } |
c5aa993b | 6808 | |
09d682a4 TT |
6809 | /* Return true if this breakpoint was set by the user, false if it is |
6810 | internal or momentary. */ | |
6811 | ||
6812 | int | |
6813 | user_breakpoint_p (struct breakpoint *b) | |
6814 | { | |
46c6471b | 6815 | return b->number > 0; |
09d682a4 TT |
6816 | } |
6817 | ||
93daf339 TT |
6818 | /* See breakpoint.h. */ |
6819 | ||
6820 | int | |
6821 | pending_breakpoint_p (struct breakpoint *b) | |
6822 | { | |
6823 | return b->loc == NULL; | |
6824 | } | |
6825 | ||
7f3b0473 | 6826 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6827 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6828 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6829 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6830 | ones for which it returns non-zero. Return the total number of | |
6831 | breakpoints listed. */ | |
c906108c | 6832 | |
d77f58be | 6833 | static int |
e5a67952 | 6834 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6835 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6836 | { |
52f0bd74 | 6837 | struct breakpoint *b; |
a6d9a66e | 6838 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6839 | int nr_printable_breakpoints; |
3b31d625 | 6840 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6841 | struct value_print_options opts; |
a6d9a66e | 6842 | int print_address_bits = 0; |
269b11a2 | 6843 | int print_type_col_width = 14; |
79a45e25 | 6844 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6845 | |
79a45b7d TT |
6846 | get_user_print_options (&opts); |
6847 | ||
4a64f543 MS |
6848 | /* Compute the number of rows in the table, as well as the size |
6849 | required for address fields. */ | |
7f3b0473 AC |
6850 | nr_printable_breakpoints = 0; |
6851 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6852 | { |
6853 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6854 | if (filter && !filter (b)) | |
6855 | continue; | |
6856 | ||
6857 | /* If we have an "args" string, it is a list of breakpoints to | |
6858 | accept. Skip the others. */ | |
6859 | if (args != NULL && *args != '\0') | |
6860 | { | |
6861 | if (allflag && parse_and_eval_long (args) != b->number) | |
6862 | continue; | |
6863 | if (!allflag && !number_is_in_list (args, b->number)) | |
6864 | continue; | |
6865 | } | |
269b11a2 | 6866 | |
e5a67952 MS |
6867 | if (allflag || user_breakpoint_p (b)) |
6868 | { | |
6869 | int addr_bit, type_len; | |
a6d9a66e | 6870 | |
e5a67952 MS |
6871 | addr_bit = breakpoint_address_bits (b); |
6872 | if (addr_bit > print_address_bits) | |
6873 | print_address_bits = addr_bit; | |
269b11a2 | 6874 | |
e5a67952 MS |
6875 | type_len = strlen (bptype_string (b->type)); |
6876 | if (type_len > print_type_col_width) | |
6877 | print_type_col_width = type_len; | |
6878 | ||
6879 | nr_printable_breakpoints++; | |
6880 | } | |
6881 | } | |
7f3b0473 | 6882 | |
79a45b7d | 6883 | if (opts.addressprint) |
3b31d625 | 6884 | bkpttbl_chain |
3e43a32a MS |
6885 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6886 | nr_printable_breakpoints, | |
3b31d625 | 6887 | "BreakpointTable"); |
8b93c638 | 6888 | else |
3b31d625 | 6889 | bkpttbl_chain |
3e43a32a MS |
6890 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6891 | nr_printable_breakpoints, | |
3b31d625 | 6892 | "BreakpointTable"); |
8b93c638 | 6893 | |
7f3b0473 | 6894 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6895 | annotate_breakpoints_headers (); |
6896 | if (nr_printable_breakpoints > 0) | |
6897 | annotate_field (0); | |
4a64f543 | 6898 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6899 | if (nr_printable_breakpoints > 0) |
6900 | annotate_field (1); | |
269b11a2 | 6901 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6902 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6903 | if (nr_printable_breakpoints > 0) |
6904 | annotate_field (2); | |
4a64f543 | 6905 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6906 | if (nr_printable_breakpoints > 0) |
6907 | annotate_field (3); | |
54e52265 | 6908 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6909 | if (opts.addressprint) |
e5a67952 MS |
6910 | { |
6911 | if (nr_printable_breakpoints > 0) | |
6912 | annotate_field (4); | |
6913 | if (print_address_bits <= 32) | |
6914 | ui_out_table_header (uiout, 10, ui_left, | |
6915 | "addr", "Address"); /* 5 */ | |
6916 | else | |
6917 | ui_out_table_header (uiout, 18, ui_left, | |
6918 | "addr", "Address"); /* 5 */ | |
6919 | } | |
d7faa9e7 AC |
6920 | if (nr_printable_breakpoints > 0) |
6921 | annotate_field (5); | |
6922 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6923 | ui_out_table_body (uiout); | |
6924 | if (nr_printable_breakpoints > 0) | |
6925 | annotate_breakpoints_table (); | |
7f3b0473 | 6926 | |
c4093a6a | 6927 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6928 | { |
6929 | QUIT; | |
6930 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6931 | if (filter && !filter (b)) | |
6932 | continue; | |
6933 | ||
6934 | /* If we have an "args" string, it is a list of breakpoints to | |
6935 | accept. Skip the others. */ | |
6936 | ||
6937 | if (args != NULL && *args != '\0') | |
6938 | { | |
6939 | if (allflag) /* maintenance info breakpoint */ | |
6940 | { | |
6941 | if (parse_and_eval_long (args) != b->number) | |
6942 | continue; | |
6943 | } | |
6944 | else /* all others */ | |
6945 | { | |
6946 | if (!number_is_in_list (args, b->number)) | |
6947 | continue; | |
6948 | } | |
6949 | } | |
6950 | /* We only print out user settable breakpoints unless the | |
6951 | allflag is set. */ | |
6952 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6953 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6954 | } |
6955 | ||
3b31d625 | 6956 | do_cleanups (bkpttbl_chain); |
698384cd | 6957 | |
7f3b0473 | 6958 | if (nr_printable_breakpoints == 0) |
c906108c | 6959 | { |
4a64f543 MS |
6960 | /* If there's a filter, let the caller decide how to report |
6961 | empty list. */ | |
d77f58be SS |
6962 | if (!filter) |
6963 | { | |
e5a67952 | 6964 | if (args == NULL || *args == '\0') |
d77f58be SS |
6965 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6966 | else | |
4a64f543 | 6967 | ui_out_message (uiout, 0, |
e5a67952 MS |
6968 | "No breakpoint or watchpoint matching '%s'.\n", |
6969 | args); | |
d77f58be | 6970 | } |
c906108c SS |
6971 | } |
6972 | else | |
c4093a6a | 6973 | { |
a6d9a66e UW |
6974 | if (last_loc && !server_command) |
6975 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6976 | } |
c906108c | 6977 | |
4a64f543 | 6978 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6979 | there have been breakpoints? */ |
c906108c | 6980 | annotate_breakpoints_table_end (); |
d77f58be SS |
6981 | |
6982 | return nr_printable_breakpoints; | |
c906108c SS |
6983 | } |
6984 | ||
ad443146 SS |
6985 | /* Display the value of default-collect in a way that is generally |
6986 | compatible with the breakpoint list. */ | |
6987 | ||
6988 | static void | |
6989 | default_collect_info (void) | |
6990 | { | |
79a45e25 PA |
6991 | struct ui_out *uiout = current_uiout; |
6992 | ||
ad443146 SS |
6993 | /* If it has no value (which is frequently the case), say nothing; a |
6994 | message like "No default-collect." gets in user's face when it's | |
6995 | not wanted. */ | |
6996 | if (!*default_collect) | |
6997 | return; | |
6998 | ||
6999 | /* The following phrase lines up nicely with per-tracepoint collect | |
7000 | actions. */ | |
7001 | ui_out_text (uiout, "default collect "); | |
7002 | ui_out_field_string (uiout, "default-collect", default_collect); | |
7003 | ui_out_text (uiout, " \n"); | |
7004 | } | |
7005 | ||
c906108c | 7006 | static void |
e5a67952 | 7007 | breakpoints_info (char *args, int from_tty) |
c906108c | 7008 | { |
e5a67952 | 7009 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
7010 | |
7011 | default_collect_info (); | |
d77f58be SS |
7012 | } |
7013 | ||
7014 | static void | |
e5a67952 | 7015 | watchpoints_info (char *args, int from_tty) |
d77f58be | 7016 | { |
e5a67952 | 7017 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 7018 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
7019 | |
7020 | if (num_printed == 0) | |
7021 | { | |
e5a67952 | 7022 | if (args == NULL || *args == '\0') |
d77f58be SS |
7023 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7024 | else | |
e5a67952 | 7025 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7026 | } |
c906108c SS |
7027 | } |
7028 | ||
7a292a7a | 7029 | static void |
e5a67952 | 7030 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7031 | { |
e5a67952 | 7032 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7033 | |
7034 | default_collect_info (); | |
c906108c SS |
7035 | } |
7036 | ||
0d381245 | 7037 | static int |
714835d5 | 7038 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7039 | struct program_space *pspace, |
714835d5 | 7040 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7041 | { |
7042 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7043 | |
0d381245 VP |
7044 | for (; bl; bl = bl->next) |
7045 | { | |
6c95b8df PA |
7046 | if (bl->pspace == pspace |
7047 | && bl->address == pc | |
0d381245 VP |
7048 | && (!overlay_debugging || bl->section == section)) |
7049 | return 1; | |
7050 | } | |
7051 | return 0; | |
7052 | } | |
7053 | ||
672f9b60 | 7054 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7055 | concerns with logical breakpoints, so we match program spaces, not |
7056 | address spaces. */ | |
c906108c SS |
7057 | |
7058 | static void | |
6c95b8df PA |
7059 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7060 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7061 | struct obj_section *section, int thread) |
c906108c | 7062 | { |
52f0bd74 AC |
7063 | int others = 0; |
7064 | struct breakpoint *b; | |
c906108c SS |
7065 | |
7066 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7067 | others += (user_breakpoint_p (b) |
7068 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7069 | if (others > 0) |
7070 | { | |
a3f17187 AC |
7071 | if (others == 1) |
7072 | printf_filtered (_("Note: breakpoint ")); | |
7073 | else /* if (others == ???) */ | |
7074 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7075 | ALL_BREAKPOINTS (b) |
672f9b60 | 7076 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7077 | { |
7078 | others--; | |
7079 | printf_filtered ("%d", b->number); | |
7080 | if (b->thread == -1 && thread != -1) | |
7081 | printf_filtered (" (all threads)"); | |
7082 | else if (b->thread != -1) | |
7083 | printf_filtered (" (thread %d)", b->thread); | |
7084 | printf_filtered ("%s%s ", | |
059fb39f | 7085 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7086 | || b->enable_state == bp_call_disabled) |
0d381245 | 7087 | ? " (disabled)" |
0d381245 VP |
7088 | : ""), |
7089 | (others > 1) ? "," | |
7090 | : ((others == 1) ? " and" : "")); | |
7091 | } | |
a3f17187 | 7092 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7093 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7094 | printf_filtered (".\n"); |
7095 | } | |
7096 | } | |
7097 | \f | |
c906108c | 7098 | |
e4f237da | 7099 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7100 | BPT locations. For some breakpoint types, the locations' address members |
7101 | are irrelevant and it makes no sense to attempt to compare them to other | |
7102 | addresses (or use them for any other purpose either). | |
e4f237da | 7103 | |
4a64f543 | 7104 | More specifically, each of the following breakpoint types will |
244558af | 7105 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7106 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7107 | breakpoint location at address zero: |
e4f237da KB |
7108 | |
7109 | bp_watchpoint | |
2d134ed3 PA |
7110 | bp_catchpoint |
7111 | ||
7112 | */ | |
e4f237da KB |
7113 | |
7114 | static int | |
7115 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7116 | { | |
7117 | enum bptype type = bpt->type; | |
7118 | ||
2d134ed3 PA |
7119 | return (type != bp_watchpoint && type != bp_catchpoint); |
7120 | } | |
7121 | ||
7122 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7123 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7124 | ||
7125 | static int | |
4a64f543 MS |
7126 | watchpoint_locations_match (struct bp_location *loc1, |
7127 | struct bp_location *loc2) | |
2d134ed3 | 7128 | { |
3a5c3e22 PA |
7129 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7130 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7131 | ||
7132 | /* Both of them must exist. */ | |
7133 | gdb_assert (w1 != NULL); | |
7134 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7135 | |
4a64f543 MS |
7136 | /* If the target can evaluate the condition expression in hardware, |
7137 | then we we need to insert both watchpoints even if they are at | |
7138 | the same place. Otherwise the watchpoint will only trigger when | |
7139 | the condition of whichever watchpoint was inserted evaluates to | |
7140 | true, not giving a chance for GDB to check the condition of the | |
7141 | other watchpoint. */ | |
3a5c3e22 | 7142 | if ((w1->cond_exp |
4a64f543 MS |
7143 | && target_can_accel_watchpoint_condition (loc1->address, |
7144 | loc1->length, | |
0cf6dd15 | 7145 | loc1->watchpoint_type, |
3a5c3e22 PA |
7146 | w1->cond_exp)) |
7147 | || (w2->cond_exp | |
4a64f543 MS |
7148 | && target_can_accel_watchpoint_condition (loc2->address, |
7149 | loc2->length, | |
0cf6dd15 | 7150 | loc2->watchpoint_type, |
3a5c3e22 | 7151 | w2->cond_exp))) |
0cf6dd15 TJB |
7152 | return 0; |
7153 | ||
85d721b8 PA |
7154 | /* Note that this checks the owner's type, not the location's. In |
7155 | case the target does not support read watchpoints, but does | |
7156 | support access watchpoints, we'll have bp_read_watchpoint | |
7157 | watchpoints with hw_access locations. Those should be considered | |
7158 | duplicates of hw_read locations. The hw_read locations will | |
7159 | become hw_access locations later. */ | |
2d134ed3 PA |
7160 | return (loc1->owner->type == loc2->owner->type |
7161 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7162 | && loc1->address == loc2->address | |
7163 | && loc1->length == loc2->length); | |
e4f237da KB |
7164 | } |
7165 | ||
31e77af2 | 7166 | /* See breakpoint.h. */ |
6c95b8df | 7167 | |
31e77af2 | 7168 | int |
6c95b8df PA |
7169 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7170 | struct address_space *aspace2, CORE_ADDR addr2) | |
7171 | { | |
f5656ead | 7172 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7173 | || aspace1 == aspace2) |
7174 | && addr1 == addr2); | |
7175 | } | |
7176 | ||
f1310107 TJB |
7177 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7178 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7179 | matches ASPACE2. On targets that have global breakpoints, the address | |
7180 | space doesn't really matter. */ | |
7181 | ||
7182 | static int | |
7183 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7184 | int len1, struct address_space *aspace2, | |
7185 | CORE_ADDR addr2) | |
7186 | { | |
f5656ead | 7187 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7188 | || aspace1 == aspace2) |
7189 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7190 | } | |
7191 | ||
7192 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7193 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7194 | matches the breakpoint's address space. On targets that have global | |
7195 | breakpoints, the address space doesn't really matter. */ | |
7196 | ||
7197 | static int | |
7198 | breakpoint_location_address_match (struct bp_location *bl, | |
7199 | struct address_space *aspace, | |
7200 | CORE_ADDR addr) | |
7201 | { | |
7202 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7203 | aspace, addr) | |
7204 | || (bl->length | |
7205 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7206 | bl->address, bl->length, | |
7207 | aspace, addr))); | |
7208 | } | |
7209 | ||
d35ae833 PA |
7210 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7211 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7212 | match happens only if ASPACE matches the breakpoint's address | |
7213 | space. On targets that have global breakpoints, the address space | |
7214 | doesn't really matter. */ | |
7215 | ||
7216 | static int | |
7217 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7218 | struct address_space *aspace, | |
7219 | CORE_ADDR addr, int len) | |
7220 | { | |
7221 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7222 | || bl->pspace->aspace == aspace) | |
7223 | { | |
7224 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7225 | ||
7226 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7227 | return 1; | |
7228 | } | |
7229 | return 0; | |
7230 | } | |
7231 | ||
1e4d1764 YQ |
7232 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7233 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7234 | true, otherwise returns false. */ | |
7235 | ||
7236 | static int | |
7237 | tracepoint_locations_match (struct bp_location *loc1, | |
7238 | struct bp_location *loc2) | |
7239 | { | |
7240 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7241 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7242 | locations at the same address of different tracepoints are regarded as | |
7243 | different locations. */ | |
7244 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7245 | else | |
7246 | return 0; | |
7247 | } | |
7248 | ||
2d134ed3 PA |
7249 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7250 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7251 | represent the same location. */ | |
7252 | ||
7253 | static int | |
4a64f543 MS |
7254 | breakpoint_locations_match (struct bp_location *loc1, |
7255 | struct bp_location *loc2) | |
2d134ed3 | 7256 | { |
2bdf28a0 JK |
7257 | int hw_point1, hw_point2; |
7258 | ||
7259 | /* Both of them must not be in moribund_locations. */ | |
7260 | gdb_assert (loc1->owner != NULL); | |
7261 | gdb_assert (loc2->owner != NULL); | |
7262 | ||
7263 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7264 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7265 | |
7266 | if (hw_point1 != hw_point2) | |
7267 | return 0; | |
7268 | else if (hw_point1) | |
7269 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7270 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7271 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7272 | else |
f1310107 TJB |
7273 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7274 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7275 | loc2->pspace->aspace, loc2->address) | |
7276 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7277 | } |
7278 | ||
76897487 KB |
7279 | static void |
7280 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7281 | int bnum, int have_bnum) | |
7282 | { | |
f63fbe86 MS |
7283 | /* The longest string possibly returned by hex_string_custom |
7284 | is 50 chars. These must be at least that big for safety. */ | |
7285 | char astr1[64]; | |
7286 | char astr2[64]; | |
76897487 | 7287 | |
bb599908 PH |
7288 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7289 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7290 | if (have_bnum) |
8a3fe4f8 | 7291 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7292 | bnum, astr1, astr2); |
7293 | else | |
8a3fe4f8 | 7294 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7295 | } |
7296 | ||
4a64f543 MS |
7297 | /* Adjust a breakpoint's address to account for architectural |
7298 | constraints on breakpoint placement. Return the adjusted address. | |
7299 | Note: Very few targets require this kind of adjustment. For most | |
7300 | targets, this function is simply the identity function. */ | |
76897487 KB |
7301 | |
7302 | static CORE_ADDR | |
a6d9a66e UW |
7303 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7304 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7305 | { |
a6d9a66e | 7306 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7307 | { |
7308 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7309 | return bpaddr; | |
7310 | } | |
88f7da05 KB |
7311 | else if (bptype == bp_watchpoint |
7312 | || bptype == bp_hardware_watchpoint | |
7313 | || bptype == bp_read_watchpoint | |
7314 | || bptype == bp_access_watchpoint | |
fe798b75 | 7315 | || bptype == bp_catchpoint) |
88f7da05 KB |
7316 | { |
7317 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7318 | have their addresses modified. */ | |
7319 | return bpaddr; | |
7320 | } | |
7c16b83e PA |
7321 | else if (bptype == bp_single_step) |
7322 | { | |
7323 | /* Single-step breakpoints should not have their addresses | |
7324 | modified. If there's any architectural constrain that | |
7325 | applies to this address, then it should have already been | |
7326 | taken into account when the breakpoint was created in the | |
7327 | first place. If we didn't do this, stepping through e.g., | |
7328 | Thumb-2 IT blocks would break. */ | |
7329 | return bpaddr; | |
7330 | } | |
76897487 KB |
7331 | else |
7332 | { | |
7333 | CORE_ADDR adjusted_bpaddr; | |
7334 | ||
7335 | /* Some targets have architectural constraints on the placement | |
7336 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7337 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7338 | |
7339 | /* An adjusted breakpoint address can significantly alter | |
7340 | a user's expectations. Print a warning if an adjustment | |
7341 | is required. */ | |
7342 | if (adjusted_bpaddr != bpaddr) | |
7343 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7344 | ||
7345 | return adjusted_bpaddr; | |
7346 | } | |
7347 | } | |
7348 | ||
28010a5d PA |
7349 | void |
7350 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7351 | struct breakpoint *owner) | |
7cc221ef | 7352 | { |
7cc221ef DJ |
7353 | memset (loc, 0, sizeof (*loc)); |
7354 | ||
348d480f PA |
7355 | gdb_assert (ops != NULL); |
7356 | ||
28010a5d PA |
7357 | loc->ops = ops; |
7358 | loc->owner = owner; | |
511a6cd4 | 7359 | loc->cond = NULL; |
b775012e | 7360 | loc->cond_bytecode = NULL; |
0d381245 VP |
7361 | loc->shlib_disabled = 0; |
7362 | loc->enabled = 1; | |
e049a4b5 | 7363 | |
28010a5d | 7364 | switch (owner->type) |
e049a4b5 DJ |
7365 | { |
7366 | case bp_breakpoint: | |
7c16b83e | 7367 | case bp_single_step: |
e049a4b5 DJ |
7368 | case bp_until: |
7369 | case bp_finish: | |
7370 | case bp_longjmp: | |
7371 | case bp_longjmp_resume: | |
e2e4d78b | 7372 | case bp_longjmp_call_dummy: |
186c406b TT |
7373 | case bp_exception: |
7374 | case bp_exception_resume: | |
e049a4b5 | 7375 | case bp_step_resume: |
2c03e5be | 7376 | case bp_hp_step_resume: |
e049a4b5 DJ |
7377 | case bp_watchpoint_scope: |
7378 | case bp_call_dummy: | |
aa7d318d | 7379 | case bp_std_terminate: |
e049a4b5 DJ |
7380 | case bp_shlib_event: |
7381 | case bp_thread_event: | |
7382 | case bp_overlay_event: | |
4efc6507 | 7383 | case bp_jit_event: |
0fd8e87f | 7384 | case bp_longjmp_master: |
aa7d318d | 7385 | case bp_std_terminate_master: |
186c406b | 7386 | case bp_exception_master: |
0e30163f JK |
7387 | case bp_gnu_ifunc_resolver: |
7388 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7389 | case bp_dprintf: |
e049a4b5 | 7390 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7391 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7392 | break; |
7393 | case bp_hardware_breakpoint: | |
7394 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7395 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7396 | break; |
7397 | case bp_hardware_watchpoint: | |
7398 | case bp_read_watchpoint: | |
7399 | case bp_access_watchpoint: | |
7400 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7401 | break; | |
7402 | case bp_watchpoint: | |
ce78b96d | 7403 | case bp_catchpoint: |
15c3d785 PA |
7404 | case bp_tracepoint: |
7405 | case bp_fast_tracepoint: | |
0fb4aa4b | 7406 | case bp_static_tracepoint: |
e049a4b5 DJ |
7407 | loc->loc_type = bp_loc_other; |
7408 | break; | |
7409 | default: | |
e2e0b3e5 | 7410 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7411 | } |
7412 | ||
f431efe5 | 7413 | loc->refc = 1; |
28010a5d PA |
7414 | } |
7415 | ||
7416 | /* Allocate a struct bp_location. */ | |
7417 | ||
7418 | static struct bp_location * | |
7419 | allocate_bp_location (struct breakpoint *bpt) | |
7420 | { | |
348d480f PA |
7421 | return bpt->ops->allocate_location (bpt); |
7422 | } | |
7cc221ef | 7423 | |
f431efe5 PA |
7424 | static void |
7425 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7426 | { |
348d480f | 7427 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7428 | xfree (loc); |
7429 | } | |
7430 | ||
f431efe5 PA |
7431 | /* Increment reference count. */ |
7432 | ||
7433 | static void | |
7434 | incref_bp_location (struct bp_location *bl) | |
7435 | { | |
7436 | ++bl->refc; | |
7437 | } | |
7438 | ||
7439 | /* Decrement reference count. If the reference count reaches 0, | |
7440 | destroy the bp_location. Sets *BLP to NULL. */ | |
7441 | ||
7442 | static void | |
7443 | decref_bp_location (struct bp_location **blp) | |
7444 | { | |
0807b50c PA |
7445 | gdb_assert ((*blp)->refc > 0); |
7446 | ||
f431efe5 PA |
7447 | if (--(*blp)->refc == 0) |
7448 | free_bp_location (*blp); | |
7449 | *blp = NULL; | |
7450 | } | |
7451 | ||
346774a9 | 7452 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7453 | |
346774a9 PA |
7454 | static void |
7455 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7456 | { |
346774a9 | 7457 | struct breakpoint *b1; |
c906108c | 7458 | |
346774a9 PA |
7459 | /* Add this breakpoint to the end of the chain so that a list of |
7460 | breakpoints will come out in order of increasing numbers. */ | |
7461 | ||
7462 | b1 = breakpoint_chain; | |
7463 | if (b1 == 0) | |
7464 | breakpoint_chain = b; | |
7465 | else | |
7466 | { | |
7467 | while (b1->next) | |
7468 | b1 = b1->next; | |
7469 | b1->next = b; | |
7470 | } | |
7471 | } | |
7472 | ||
7473 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7474 | ||
7475 | static void | |
7476 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7477 | struct gdbarch *gdbarch, | |
28010a5d | 7478 | enum bptype bptype, |
c0a91b2b | 7479 | const struct breakpoint_ops *ops) |
346774a9 | 7480 | { |
c906108c | 7481 | memset (b, 0, sizeof (*b)); |
2219d63c | 7482 | |
348d480f PA |
7483 | gdb_assert (ops != NULL); |
7484 | ||
28010a5d | 7485 | b->ops = ops; |
4d28f7a8 | 7486 | b->type = bptype; |
a6d9a66e | 7487 | b->gdbarch = gdbarch; |
c906108c SS |
7488 | b->language = current_language->la_language; |
7489 | b->input_radix = input_radix; | |
7490 | b->thread = -1; | |
b5de0fa7 | 7491 | b->enable_state = bp_enabled; |
c906108c SS |
7492 | b->next = 0; |
7493 | b->silent = 0; | |
7494 | b->ignore_count = 0; | |
7495 | b->commands = NULL; | |
818dd999 | 7496 | b->frame_id = null_frame_id; |
0d381245 | 7497 | b->condition_not_parsed = 0; |
84f4c1fe | 7498 | b->py_bp_object = NULL; |
d0fb5eae | 7499 | b->related_breakpoint = b; |
f00aae0f | 7500 | b->location = NULL; |
346774a9 PA |
7501 | } |
7502 | ||
7503 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7504 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7505 | |
7506 | static struct breakpoint * | |
7507 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7508 | enum bptype bptype, |
c0a91b2b | 7509 | const struct breakpoint_ops *ops) |
346774a9 PA |
7510 | { |
7511 | struct breakpoint *b = XNEW (struct breakpoint); | |
7512 | ||
348d480f | 7513 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7514 | add_to_breakpoint_chain (b); |
0d381245 VP |
7515 | return b; |
7516 | } | |
7517 | ||
0e30163f JK |
7518 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7519 | resolutions should be made as the user specified the location explicitly | |
7520 | enough. */ | |
7521 | ||
0d381245 | 7522 | static void |
0e30163f | 7523 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7524 | { |
2bdf28a0 JK |
7525 | gdb_assert (loc->owner != NULL); |
7526 | ||
0d381245 | 7527 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7528 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7529 | || is_tracepoint (loc->owner)) |
0d381245 | 7530 | { |
0e30163f | 7531 | int is_gnu_ifunc; |
2c02bd72 | 7532 | const char *function_name; |
6a3a010b | 7533 | CORE_ADDR func_addr; |
0e30163f | 7534 | |
2c02bd72 | 7535 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7536 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7537 | |
7538 | if (is_gnu_ifunc && !explicit_loc) | |
7539 | { | |
7540 | struct breakpoint *b = loc->owner; | |
7541 | ||
7542 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7543 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7544 | &loc->requested_address)) |
7545 | { | |
7546 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7547 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7548 | loc->requested_address, | |
7549 | b->type); | |
7550 | } | |
7551 | else if (b->type == bp_breakpoint && b->loc == loc | |
7552 | && loc->next == NULL && b->related_breakpoint == b) | |
7553 | { | |
7554 | /* Create only the whole new breakpoint of this type but do not | |
7555 | mess more complicated breakpoints with multiple locations. */ | |
7556 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7557 | /* Remember the resolver's address for use by the return |
7558 | breakpoint. */ | |
7559 | loc->related_address = func_addr; | |
0e30163f JK |
7560 | } |
7561 | } | |
7562 | ||
2c02bd72 DE |
7563 | if (function_name) |
7564 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7565 | } |
7566 | } | |
7567 | ||
a6d9a66e | 7568 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7569 | struct gdbarch * |
a6d9a66e UW |
7570 | get_sal_arch (struct symtab_and_line sal) |
7571 | { | |
7572 | if (sal.section) | |
7573 | return get_objfile_arch (sal.section->objfile); | |
7574 | if (sal.symtab) | |
eb822aa6 | 7575 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7576 | |
7577 | return NULL; | |
7578 | } | |
7579 | ||
346774a9 PA |
7580 | /* Low level routine for partially initializing a breakpoint of type |
7581 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7582 | file name, and line number are provided by SAL. |
0d381245 VP |
7583 | |
7584 | It is expected that the caller will complete the initialization of | |
7585 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7586 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7587 | |
346774a9 PA |
7588 | static void |
7589 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7590 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7591 | const struct breakpoint_ops *ops) |
0d381245 | 7592 | { |
28010a5d | 7593 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7594 | |
3742cc8b | 7595 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7596 | |
6c95b8df PA |
7597 | if (bptype != bp_catchpoint) |
7598 | gdb_assert (sal.pspace != NULL); | |
7599 | ||
f8eba3c6 TT |
7600 | /* Store the program space that was used to set the breakpoint, |
7601 | except for ordinary breakpoints, which are independent of the | |
7602 | program space. */ | |
7603 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7604 | b->pspace = sal.pspace; | |
346774a9 | 7605 | } |
c906108c | 7606 | |
346774a9 PA |
7607 | /* set_raw_breakpoint is a low level routine for allocating and |
7608 | partially initializing a breakpoint of type BPTYPE. The newly | |
7609 | created breakpoint's address, section, source file name, and line | |
7610 | number are provided by SAL. The newly created and partially | |
7611 | initialized breakpoint is added to the breakpoint chain and | |
7612 | is also returned as the value of this function. | |
7613 | ||
7614 | It is expected that the caller will complete the initialization of | |
7615 | the newly created breakpoint struct as well as output any status | |
7616 | information regarding the creation of a new breakpoint. In | |
7617 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7618 | number! Care should be taken to not allow an error to occur | |
7619 | prior to completing the initialization of the breakpoint. If this | |
7620 | should happen, a bogus breakpoint will be left on the chain. */ | |
7621 | ||
7622 | struct breakpoint * | |
7623 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7624 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7625 | const struct breakpoint_ops *ops) |
346774a9 PA |
7626 | { |
7627 | struct breakpoint *b = XNEW (struct breakpoint); | |
7628 | ||
348d480f | 7629 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7630 | add_to_breakpoint_chain (b); |
c906108c SS |
7631 | return b; |
7632 | } | |
7633 | ||
53a5351d | 7634 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7635 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7636 | initiated the operation. */ | |
c906108c SS |
7637 | |
7638 | void | |
186c406b | 7639 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7640 | { |
35df4500 | 7641 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7642 | int thread = tp->global_num; |
0fd8e87f UW |
7643 | |
7644 | /* To avoid having to rescan all objfile symbols at every step, | |
7645 | we maintain a list of continually-inserted but always disabled | |
7646 | longjmp "master" breakpoints. Here, we simply create momentary | |
7647 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7648 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7649 | if (b->pspace == current_program_space |
186c406b TT |
7650 | && (b->type == bp_longjmp_master |
7651 | || b->type == bp_exception_master)) | |
0fd8e87f | 7652 | { |
06edf0c0 PA |
7653 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7654 | struct breakpoint *clone; | |
cc59ec59 | 7655 | |
e2e4d78b JK |
7656 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7657 | after their removal. */ | |
06edf0c0 | 7658 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7659 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7660 | clone->thread = thread; |
7661 | } | |
186c406b TT |
7662 | |
7663 | tp->initiating_frame = frame; | |
c906108c SS |
7664 | } |
7665 | ||
611c83ae | 7666 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7667 | void |
611c83ae | 7668 | delete_longjmp_breakpoint (int thread) |
c906108c | 7669 | { |
35df4500 | 7670 | struct breakpoint *b, *b_tmp; |
c906108c | 7671 | |
35df4500 | 7672 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7673 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7674 | { |
7675 | if (b->thread == thread) | |
7676 | delete_breakpoint (b); | |
7677 | } | |
c906108c SS |
7678 | } |
7679 | ||
f59f708a PA |
7680 | void |
7681 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7682 | { | |
7683 | struct breakpoint *b, *b_tmp; | |
7684 | ||
7685 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7686 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7687 | { | |
7688 | if (b->thread == thread) | |
7689 | b->disposition = disp_del_at_next_stop; | |
7690 | } | |
7691 | } | |
7692 | ||
e2e4d78b JK |
7693 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7694 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7695 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7696 | breakpoints. */ | |
7697 | ||
7698 | struct breakpoint * | |
7699 | set_longjmp_breakpoint_for_call_dummy (void) | |
7700 | { | |
7701 | struct breakpoint *b, *retval = NULL; | |
7702 | ||
7703 | ALL_BREAKPOINTS (b) | |
7704 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7705 | { | |
7706 | struct breakpoint *new_b; | |
7707 | ||
7708 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7709 | &momentary_breakpoint_ops, |
7710 | 1); | |
5d5658a1 | 7711 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7712 | |
7713 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7714 | ||
7715 | gdb_assert (new_b->related_breakpoint == new_b); | |
7716 | if (retval == NULL) | |
7717 | retval = new_b; | |
7718 | new_b->related_breakpoint = retval; | |
7719 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7720 | retval = retval->related_breakpoint; | |
7721 | retval->related_breakpoint = new_b; | |
7722 | } | |
7723 | ||
7724 | return retval; | |
7725 | } | |
7726 | ||
7727 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7728 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7729 | stack. |
7730 | ||
7731 | You should call this function only at places where it is safe to currently | |
7732 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7733 | frames. */ | |
7734 | ||
7735 | void | |
b67a2c6f | 7736 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7737 | { |
7738 | struct breakpoint *b, *b_tmp; | |
7739 | ||
7740 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7741 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7742 | { |
7743 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7744 | ||
7745 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7746 | dummy_b = dummy_b->related_breakpoint; | |
7747 | if (dummy_b->type != bp_call_dummy | |
7748 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7749 | continue; | |
7750 | ||
b67a2c6f | 7751 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7752 | |
7753 | while (b->related_breakpoint != b) | |
7754 | { | |
7755 | if (b_tmp == b->related_breakpoint) | |
7756 | b_tmp = b->related_breakpoint->next; | |
7757 | delete_breakpoint (b->related_breakpoint); | |
7758 | } | |
7759 | delete_breakpoint (b); | |
7760 | } | |
7761 | } | |
7762 | ||
1900040c MS |
7763 | void |
7764 | enable_overlay_breakpoints (void) | |
7765 | { | |
52f0bd74 | 7766 | struct breakpoint *b; |
1900040c MS |
7767 | |
7768 | ALL_BREAKPOINTS (b) | |
7769 | if (b->type == bp_overlay_event) | |
7770 | { | |
7771 | b->enable_state = bp_enabled; | |
44702360 | 7772 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7773 | overlay_events_enabled = 1; |
1900040c MS |
7774 | } |
7775 | } | |
7776 | ||
7777 | void | |
7778 | disable_overlay_breakpoints (void) | |
7779 | { | |
52f0bd74 | 7780 | struct breakpoint *b; |
1900040c MS |
7781 | |
7782 | ALL_BREAKPOINTS (b) | |
7783 | if (b->type == bp_overlay_event) | |
7784 | { | |
7785 | b->enable_state = bp_disabled; | |
44702360 | 7786 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7787 | overlay_events_enabled = 0; |
1900040c MS |
7788 | } |
7789 | } | |
7790 | ||
aa7d318d TT |
7791 | /* Set an active std::terminate breakpoint for each std::terminate |
7792 | master breakpoint. */ | |
7793 | void | |
7794 | set_std_terminate_breakpoint (void) | |
7795 | { | |
35df4500 | 7796 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7797 | |
35df4500 | 7798 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7799 | if (b->pspace == current_program_space |
7800 | && b->type == bp_std_terminate_master) | |
7801 | { | |
06edf0c0 | 7802 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7803 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7804 | } |
7805 | } | |
7806 | ||
7807 | /* Delete all the std::terminate breakpoints. */ | |
7808 | void | |
7809 | delete_std_terminate_breakpoint (void) | |
7810 | { | |
35df4500 | 7811 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7812 | |
35df4500 | 7813 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7814 | if (b->type == bp_std_terminate) |
7815 | delete_breakpoint (b); | |
7816 | } | |
7817 | ||
c4093a6a | 7818 | struct breakpoint * |
a6d9a66e | 7819 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7820 | { |
7821 | struct breakpoint *b; | |
c4093a6a | 7822 | |
06edf0c0 PA |
7823 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7824 | &internal_breakpoint_ops); | |
7825 | ||
b5de0fa7 | 7826 | b->enable_state = bp_enabled; |
f00aae0f | 7827 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7828 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7829 | |
44702360 | 7830 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7831 | |
c4093a6a JM |
7832 | return b; |
7833 | } | |
7834 | ||
0101ce28 JJ |
7835 | struct lang_and_radix |
7836 | { | |
7837 | enum language lang; | |
7838 | int radix; | |
7839 | }; | |
7840 | ||
4efc6507 DE |
7841 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7842 | ||
7843 | struct breakpoint * | |
7844 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7845 | { | |
2a7f3dff PA |
7846 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7847 | &internal_breakpoint_ops); | |
4efc6507 | 7848 | } |
0101ce28 | 7849 | |
03673fc7 PP |
7850 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7851 | ||
7852 | void | |
7853 | remove_jit_event_breakpoints (void) | |
7854 | { | |
7855 | struct breakpoint *b, *b_tmp; | |
7856 | ||
7857 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7858 | if (b->type == bp_jit_event | |
7859 | && b->loc->pspace == current_program_space) | |
7860 | delete_breakpoint (b); | |
7861 | } | |
7862 | ||
cae688ec JJ |
7863 | void |
7864 | remove_solib_event_breakpoints (void) | |
7865 | { | |
35df4500 | 7866 | struct breakpoint *b, *b_tmp; |
cae688ec | 7867 | |
35df4500 | 7868 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7869 | if (b->type == bp_shlib_event |
7870 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7871 | delete_breakpoint (b); |
7872 | } | |
7873 | ||
f37f681c PA |
7874 | /* See breakpoint.h. */ |
7875 | ||
7876 | void | |
7877 | remove_solib_event_breakpoints_at_next_stop (void) | |
7878 | { | |
7879 | struct breakpoint *b, *b_tmp; | |
7880 | ||
7881 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7882 | if (b->type == bp_shlib_event | |
7883 | && b->loc->pspace == current_program_space) | |
7884 | b->disposition = disp_del_at_next_stop; | |
7885 | } | |
7886 | ||
04086b45 PA |
7887 | /* Helper for create_solib_event_breakpoint / |
7888 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7889 | INSERT_MODE to pass through to update_global_location_list. */ | |
7890 | ||
7891 | static struct breakpoint * | |
7892 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7893 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7894 | { |
7895 | struct breakpoint *b; | |
7896 | ||
06edf0c0 PA |
7897 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7898 | &internal_breakpoint_ops); | |
04086b45 | 7899 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7900 | return b; |
7901 | } | |
7902 | ||
04086b45 PA |
7903 | struct breakpoint * |
7904 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7905 | { | |
7906 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7907 | } | |
7908 | ||
f37f681c PA |
7909 | /* See breakpoint.h. */ |
7910 | ||
7911 | struct breakpoint * | |
7912 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7913 | { | |
7914 | struct breakpoint *b; | |
7915 | ||
04086b45 PA |
7916 | /* Explicitly tell update_global_location_list to insert |
7917 | locations. */ | |
7918 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7919 | if (!b->loc->inserted) |
7920 | { | |
7921 | delete_breakpoint (b); | |
7922 | return NULL; | |
7923 | } | |
7924 | return b; | |
7925 | } | |
7926 | ||
cae688ec JJ |
7927 | /* Disable any breakpoints that are on code in shared libraries. Only |
7928 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7929 | ||
7930 | void | |
cb851954 | 7931 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7932 | { |
876fa593 | 7933 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7934 | |
876fa593 | 7935 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7936 | { |
2bdf28a0 | 7937 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7938 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7939 | |
4a64f543 MS |
7940 | /* We apply the check to all breakpoints, including disabled for |
7941 | those with loc->duplicate set. This is so that when breakpoint | |
7942 | becomes enabled, or the duplicate is removed, gdb will try to | |
7943 | insert all breakpoints. If we don't set shlib_disabled here, | |
7944 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7945 | if (((b->type == bp_breakpoint) |
508ccb1f | 7946 | || (b->type == bp_jit_event) |
1042e4c0 | 7947 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7948 | || (is_tracepoint (b))) |
6c95b8df | 7949 | && loc->pspace == current_program_space |
0d381245 | 7950 | && !loc->shlib_disabled |
6c95b8df | 7951 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7952 | ) |
0d381245 VP |
7953 | { |
7954 | loc->shlib_disabled = 1; | |
7955 | } | |
cae688ec JJ |
7956 | } |
7957 | } | |
7958 | ||
63644780 NB |
7959 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7960 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7961 | disabled ones can just stay disabled. */ | |
84acb35a | 7962 | |
75149521 | 7963 | static void |
84acb35a JJ |
7964 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7965 | { | |
876fa593 | 7966 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7967 | int disabled_shlib_breaks = 0; |
7968 | ||
c86cf029 VP |
7969 | /* SunOS a.out shared libraries are always mapped, so do not |
7970 | disable breakpoints; they will only be reported as unloaded | |
7971 | through clear_solib when GDB discards its shared library | |
7972 | list. See clear_solib for more information. */ | |
7973 | if (exec_bfd != NULL | |
7974 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7975 | return; | |
7976 | ||
876fa593 | 7977 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7978 | { |
2bdf28a0 | 7979 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7980 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7981 | |
1e4d1764 | 7982 | if (solib->pspace == loc->pspace |
e2dd7057 | 7983 | && !loc->shlib_disabled |
1e4d1764 YQ |
7984 | && (((b->type == bp_breakpoint |
7985 | || b->type == bp_jit_event | |
7986 | || b->type == bp_hardware_breakpoint) | |
7987 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7988 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7989 | || is_tracepoint (b)) | |
e2dd7057 | 7990 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7991 | { |
e2dd7057 PP |
7992 | loc->shlib_disabled = 1; |
7993 | /* At this point, we cannot rely on remove_breakpoint | |
7994 | succeeding so we must mark the breakpoint as not inserted | |
7995 | to prevent future errors occurring in remove_breakpoints. */ | |
7996 | loc->inserted = 0; | |
8d3788bd VP |
7997 | |
7998 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7999 | observer_notify_breakpoint_modified (b); | |
8000 | ||
e2dd7057 PP |
8001 | if (!disabled_shlib_breaks) |
8002 | { | |
8003 | target_terminal_ours_for_output (); | |
3e43a32a MS |
8004 | warning (_("Temporarily disabling breakpoints " |
8005 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 8006 | solib->so_name); |
84acb35a | 8007 | } |
e2dd7057 | 8008 | disabled_shlib_breaks = 1; |
84acb35a JJ |
8009 | } |
8010 | } | |
84acb35a JJ |
8011 | } |
8012 | ||
63644780 NB |
8013 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
8014 | notification of free_objfile. Only apply to enabled breakpoints, | |
8015 | disabled ones can just stay disabled. */ | |
8016 | ||
8017 | static void | |
8018 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
8019 | { | |
8020 | struct breakpoint *b; | |
8021 | ||
8022 | if (objfile == NULL) | |
8023 | return; | |
8024 | ||
d03de421 PA |
8025 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8026 | managed by the user with add-symbol-file/remove-symbol-file. | |
8027 | Similarly to how breakpoints in shared libraries are handled in | |
8028 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8029 | shlib_disabled so they end up uninserted on the next global |
8030 | location list update. Shared libraries not loaded by the user | |
8031 | aren't handled here -- they're already handled in | |
8032 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8033 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8034 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8035 | main objfile). */ | |
8036 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8037 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8038 | return; |
8039 | ||
8040 | ALL_BREAKPOINTS (b) | |
8041 | { | |
8042 | struct bp_location *loc; | |
8043 | int bp_modified = 0; | |
8044 | ||
8045 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8046 | continue; | |
8047 | ||
8048 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8049 | { | |
8050 | CORE_ADDR loc_addr = loc->address; | |
8051 | ||
8052 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8053 | && loc->loc_type != bp_loc_software_breakpoint) | |
8054 | continue; | |
8055 | ||
8056 | if (loc->shlib_disabled != 0) | |
8057 | continue; | |
8058 | ||
8059 | if (objfile->pspace != loc->pspace) | |
8060 | continue; | |
8061 | ||
8062 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8063 | && loc->loc_type != bp_loc_software_breakpoint) | |
8064 | continue; | |
8065 | ||
8066 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8067 | { | |
8068 | loc->shlib_disabled = 1; | |
08351840 PA |
8069 | /* At this point, we don't know whether the object was |
8070 | unmapped from the inferior or not, so leave the | |
8071 | inserted flag alone. We'll handle failure to | |
8072 | uninsert quietly, in case the object was indeed | |
8073 | unmapped. */ | |
63644780 NB |
8074 | |
8075 | mark_breakpoint_location_modified (loc); | |
8076 | ||
8077 | bp_modified = 1; | |
8078 | } | |
8079 | } | |
8080 | ||
8081 | if (bp_modified) | |
8082 | observer_notify_breakpoint_modified (b); | |
8083 | } | |
8084 | } | |
8085 | ||
ce78b96d JB |
8086 | /* FORK & VFORK catchpoints. */ |
8087 | ||
e29a4733 PA |
8088 | /* An instance of this type is used to represent a fork or vfork |
8089 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8090 | class; users downcast to "struct breakpoint *" when needed. A | |
8091 | breakpoint is really of this type iff its ops pointer points to | |
8092 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8093 | ||
8094 | struct fork_catchpoint | |
8095 | { | |
8096 | /* The base class. */ | |
8097 | struct breakpoint base; | |
8098 | ||
8099 | /* Process id of a child process whose forking triggered this | |
8100 | catchpoint. This field is only valid immediately after this | |
8101 | catchpoint has triggered. */ | |
8102 | ptid_t forked_inferior_pid; | |
8103 | }; | |
8104 | ||
4a64f543 MS |
8105 | /* Implement the "insert" breakpoint_ops method for fork |
8106 | catchpoints. */ | |
ce78b96d | 8107 | |
77b06cd7 TJB |
8108 | static int |
8109 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8110 | { |
dfd4cc63 | 8111 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8112 | } |
8113 | ||
4a64f543 MS |
8114 | /* Implement the "remove" breakpoint_ops method for fork |
8115 | catchpoints. */ | |
ce78b96d JB |
8116 | |
8117 | static int | |
77b06cd7 | 8118 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 8119 | { |
dfd4cc63 | 8120 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8121 | } |
8122 | ||
8123 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8124 | catchpoints. */ | |
8125 | ||
8126 | static int | |
f1310107 | 8127 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8128 | struct address_space *aspace, CORE_ADDR bp_addr, |
8129 | const struct target_waitstatus *ws) | |
ce78b96d | 8130 | { |
e29a4733 PA |
8131 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8132 | ||
f90263c1 TT |
8133 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8134 | return 0; | |
8135 | ||
8136 | c->forked_inferior_pid = ws->value.related_pid; | |
8137 | return 1; | |
ce78b96d JB |
8138 | } |
8139 | ||
4a64f543 MS |
8140 | /* Implement the "print_it" breakpoint_ops method for fork |
8141 | catchpoints. */ | |
ce78b96d JB |
8142 | |
8143 | static enum print_stop_action | |
348d480f | 8144 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8145 | { |
36dfb11c | 8146 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8147 | struct breakpoint *b = bs->breakpoint_at; |
8148 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8149 | |
ce78b96d | 8150 | annotate_catchpoint (b->number); |
f303dbd6 | 8151 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8152 | if (b->disposition == disp_del) |
f303dbd6 | 8153 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8154 | else |
f303dbd6 | 8155 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8156 | if (ui_out_is_mi_like_p (uiout)) |
8157 | { | |
8158 | ui_out_field_string (uiout, "reason", | |
8159 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8160 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8161 | } | |
8162 | ui_out_field_int (uiout, "bkptno", b->number); | |
8163 | ui_out_text (uiout, " (forked process "); | |
8164 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8165 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8166 | return PRINT_SRC_AND_LOC; |
8167 | } | |
8168 | ||
4a64f543 MS |
8169 | /* Implement the "print_one" breakpoint_ops method for fork |
8170 | catchpoints. */ | |
ce78b96d JB |
8171 | |
8172 | static void | |
a6d9a66e | 8173 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8174 | { |
e29a4733 | 8175 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8176 | struct value_print_options opts; |
79a45e25 | 8177 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8178 | |
8179 | get_user_print_options (&opts); | |
8180 | ||
4a64f543 MS |
8181 | /* Field 4, the address, is omitted (which makes the columns not |
8182 | line up too nicely with the headers, but the effect is relatively | |
8183 | readable). */ | |
79a45b7d | 8184 | if (opts.addressprint) |
ce78b96d JB |
8185 | ui_out_field_skip (uiout, "addr"); |
8186 | annotate_field (5); | |
8187 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8188 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8189 | { |
8190 | ui_out_text (uiout, ", process "); | |
8191 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8192 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8193 | ui_out_spaces (uiout, 1); |
8194 | } | |
8ac3646f TT |
8195 | |
8196 | if (ui_out_is_mi_like_p (uiout)) | |
8197 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8198 | } |
8199 | ||
8200 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8201 | catchpoints. */ | |
8202 | ||
8203 | static void | |
8204 | print_mention_catch_fork (struct breakpoint *b) | |
8205 | { | |
8206 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8207 | } | |
8208 | ||
6149aea9 PA |
8209 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8210 | catchpoints. */ | |
8211 | ||
8212 | static void | |
8213 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8214 | { | |
8215 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8216 | print_recreate_thread (b, fp); |
6149aea9 PA |
8217 | } |
8218 | ||
ce78b96d JB |
8219 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8220 | ||
2060206e | 8221 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8222 | |
4a64f543 MS |
8223 | /* Implement the "insert" breakpoint_ops method for vfork |
8224 | catchpoints. */ | |
ce78b96d | 8225 | |
77b06cd7 TJB |
8226 | static int |
8227 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8228 | { |
dfd4cc63 | 8229 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8230 | } |
8231 | ||
4a64f543 MS |
8232 | /* Implement the "remove" breakpoint_ops method for vfork |
8233 | catchpoints. */ | |
ce78b96d JB |
8234 | |
8235 | static int | |
77b06cd7 | 8236 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8237 | { |
dfd4cc63 | 8238 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8239 | } |
8240 | ||
8241 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8242 | catchpoints. */ | |
8243 | ||
8244 | static int | |
f1310107 | 8245 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8246 | struct address_space *aspace, CORE_ADDR bp_addr, |
8247 | const struct target_waitstatus *ws) | |
ce78b96d | 8248 | { |
e29a4733 PA |
8249 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8250 | ||
f90263c1 TT |
8251 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8252 | return 0; | |
8253 | ||
8254 | c->forked_inferior_pid = ws->value.related_pid; | |
8255 | return 1; | |
ce78b96d JB |
8256 | } |
8257 | ||
4a64f543 MS |
8258 | /* Implement the "print_it" breakpoint_ops method for vfork |
8259 | catchpoints. */ | |
ce78b96d JB |
8260 | |
8261 | static enum print_stop_action | |
348d480f | 8262 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8263 | { |
36dfb11c | 8264 | struct ui_out *uiout = current_uiout; |
348d480f | 8265 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8266 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8267 | ||
ce78b96d | 8268 | annotate_catchpoint (b->number); |
f303dbd6 | 8269 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8270 | if (b->disposition == disp_del) |
f303dbd6 | 8271 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8272 | else |
f303dbd6 | 8273 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8274 | if (ui_out_is_mi_like_p (uiout)) |
8275 | { | |
8276 | ui_out_field_string (uiout, "reason", | |
8277 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8278 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8279 | } | |
8280 | ui_out_field_int (uiout, "bkptno", b->number); | |
8281 | ui_out_text (uiout, " (vforked process "); | |
8282 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8283 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8284 | return PRINT_SRC_AND_LOC; |
8285 | } | |
8286 | ||
4a64f543 MS |
8287 | /* Implement the "print_one" breakpoint_ops method for vfork |
8288 | catchpoints. */ | |
ce78b96d JB |
8289 | |
8290 | static void | |
a6d9a66e | 8291 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8292 | { |
e29a4733 | 8293 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8294 | struct value_print_options opts; |
79a45e25 | 8295 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8296 | |
8297 | get_user_print_options (&opts); | |
4a64f543 MS |
8298 | /* Field 4, the address, is omitted (which makes the columns not |
8299 | line up too nicely with the headers, but the effect is relatively | |
8300 | readable). */ | |
79a45b7d | 8301 | if (opts.addressprint) |
ce78b96d JB |
8302 | ui_out_field_skip (uiout, "addr"); |
8303 | annotate_field (5); | |
8304 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8305 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8306 | { |
8307 | ui_out_text (uiout, ", process "); | |
8308 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8309 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8310 | ui_out_spaces (uiout, 1); |
8311 | } | |
8ac3646f TT |
8312 | |
8313 | if (ui_out_is_mi_like_p (uiout)) | |
8314 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8315 | } |
8316 | ||
8317 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8318 | catchpoints. */ | |
8319 | ||
8320 | static void | |
8321 | print_mention_catch_vfork (struct breakpoint *b) | |
8322 | { | |
8323 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8324 | } | |
8325 | ||
6149aea9 PA |
8326 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8327 | catchpoints. */ | |
8328 | ||
8329 | static void | |
8330 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8331 | { | |
8332 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8333 | print_recreate_thread (b, fp); |
6149aea9 PA |
8334 | } |
8335 | ||
ce78b96d JB |
8336 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8337 | ||
2060206e | 8338 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8339 | |
edcc5120 TT |
8340 | /* An instance of this type is used to represent an solib catchpoint. |
8341 | It includes a "struct breakpoint" as a kind of base class; users | |
8342 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8343 | really of this type iff its ops pointer points to | |
8344 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8345 | ||
8346 | struct solib_catchpoint | |
8347 | { | |
8348 | /* The base class. */ | |
8349 | struct breakpoint base; | |
8350 | ||
8351 | /* True for "catch load", false for "catch unload". */ | |
8352 | unsigned char is_load; | |
8353 | ||
8354 | /* Regular expression to match, if any. COMPILED is only valid when | |
8355 | REGEX is non-NULL. */ | |
8356 | char *regex; | |
8357 | regex_t compiled; | |
8358 | }; | |
8359 | ||
8360 | static void | |
8361 | dtor_catch_solib (struct breakpoint *b) | |
8362 | { | |
8363 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8364 | ||
8365 | if (self->regex) | |
8366 | regfree (&self->compiled); | |
8367 | xfree (self->regex); | |
8368 | ||
8369 | base_breakpoint_ops.dtor (b); | |
8370 | } | |
8371 | ||
8372 | static int | |
8373 | insert_catch_solib (struct bp_location *ignore) | |
8374 | { | |
8375 | return 0; | |
8376 | } | |
8377 | ||
8378 | static int | |
8379 | remove_catch_solib (struct bp_location *ignore) | |
8380 | { | |
8381 | return 0; | |
8382 | } | |
8383 | ||
8384 | static int | |
8385 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8386 | struct address_space *aspace, | |
8387 | CORE_ADDR bp_addr, | |
8388 | const struct target_waitstatus *ws) | |
8389 | { | |
8390 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8391 | struct breakpoint *other; | |
8392 | ||
8393 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8394 | return 1; | |
8395 | ||
8396 | ALL_BREAKPOINTS (other) | |
8397 | { | |
8398 | struct bp_location *other_bl; | |
8399 | ||
8400 | if (other == bl->owner) | |
8401 | continue; | |
8402 | ||
8403 | if (other->type != bp_shlib_event) | |
8404 | continue; | |
8405 | ||
8406 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8407 | continue; | |
8408 | ||
8409 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8410 | { | |
8411 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8412 | return 1; | |
8413 | } | |
8414 | } | |
8415 | ||
8416 | return 0; | |
8417 | } | |
8418 | ||
8419 | static void | |
8420 | check_status_catch_solib (struct bpstats *bs) | |
8421 | { | |
8422 | struct solib_catchpoint *self | |
8423 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8424 | int ix; | |
8425 | ||
8426 | if (self->is_load) | |
8427 | { | |
8428 | struct so_list *iter; | |
8429 | ||
8430 | for (ix = 0; | |
8431 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8432 | ix, iter); | |
8433 | ++ix) | |
8434 | { | |
8435 | if (!self->regex | |
8436 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8437 | return; | |
8438 | } | |
8439 | } | |
8440 | else | |
8441 | { | |
8442 | char *iter; | |
8443 | ||
8444 | for (ix = 0; | |
8445 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8446 | ix, iter); | |
8447 | ++ix) | |
8448 | { | |
8449 | if (!self->regex | |
8450 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8451 | return; | |
8452 | } | |
8453 | } | |
8454 | ||
8455 | bs->stop = 0; | |
8456 | bs->print_it = print_it_noop; | |
8457 | } | |
8458 | ||
8459 | static enum print_stop_action | |
8460 | print_it_catch_solib (bpstat bs) | |
8461 | { | |
8462 | struct breakpoint *b = bs->breakpoint_at; | |
8463 | struct ui_out *uiout = current_uiout; | |
8464 | ||
8465 | annotate_catchpoint (b->number); | |
f303dbd6 | 8466 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8467 | if (b->disposition == disp_del) |
f303dbd6 | 8468 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8469 | else |
f303dbd6 | 8470 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8471 | ui_out_field_int (uiout, "bkptno", b->number); |
8472 | ui_out_text (uiout, "\n"); | |
8473 | if (ui_out_is_mi_like_p (uiout)) | |
8474 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8475 | print_solib_event (1); | |
8476 | return PRINT_SRC_AND_LOC; | |
8477 | } | |
8478 | ||
8479 | static void | |
8480 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8481 | { | |
8482 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8483 | struct value_print_options opts; | |
8484 | struct ui_out *uiout = current_uiout; | |
8485 | char *msg; | |
8486 | ||
8487 | get_user_print_options (&opts); | |
8488 | /* Field 4, the address, is omitted (which makes the columns not | |
8489 | line up too nicely with the headers, but the effect is relatively | |
8490 | readable). */ | |
8491 | if (opts.addressprint) | |
8492 | { | |
8493 | annotate_field (4); | |
8494 | ui_out_field_skip (uiout, "addr"); | |
8495 | } | |
8496 | ||
8497 | annotate_field (5); | |
8498 | if (self->is_load) | |
8499 | { | |
8500 | if (self->regex) | |
8501 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8502 | else | |
8503 | msg = xstrdup (_("load of library")); | |
8504 | } | |
8505 | else | |
8506 | { | |
8507 | if (self->regex) | |
8508 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8509 | else | |
8510 | msg = xstrdup (_("unload of library")); | |
8511 | } | |
8512 | ui_out_field_string (uiout, "what", msg); | |
8513 | xfree (msg); | |
8ac3646f TT |
8514 | |
8515 | if (ui_out_is_mi_like_p (uiout)) | |
8516 | ui_out_field_string (uiout, "catch-type", | |
8517 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8518 | } |
8519 | ||
8520 | static void | |
8521 | print_mention_catch_solib (struct breakpoint *b) | |
8522 | { | |
8523 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8524 | ||
8525 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8526 | self->is_load ? "load" : "unload"); | |
8527 | } | |
8528 | ||
8529 | static void | |
8530 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8531 | { | |
8532 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8533 | ||
8534 | fprintf_unfiltered (fp, "%s %s", | |
8535 | b->disposition == disp_del ? "tcatch" : "catch", | |
8536 | self->is_load ? "load" : "unload"); | |
8537 | if (self->regex) | |
8538 | fprintf_unfiltered (fp, " %s", self->regex); | |
8539 | fprintf_unfiltered (fp, "\n"); | |
8540 | } | |
8541 | ||
8542 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8543 | ||
91985142 MG |
8544 | /* Shared helper function (MI and CLI) for creating and installing |
8545 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8546 | the events to be caught are load events, otherwise they are | |
8547 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8548 | temporary one. If ENABLED is non-zero the catchpoint is | |
8549 | created in an enabled state. */ | |
edcc5120 | 8550 | |
91985142 MG |
8551 | void |
8552 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8553 | { |
8554 | struct solib_catchpoint *c; | |
8555 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8556 | struct cleanup *cleanup; |
8557 | ||
edcc5120 TT |
8558 | if (!arg) |
8559 | arg = ""; | |
8560 | arg = skip_spaces (arg); | |
8561 | ||
8562 | c = XCNEW (struct solib_catchpoint); | |
8563 | cleanup = make_cleanup (xfree, c); | |
8564 | ||
8565 | if (*arg != '\0') | |
8566 | { | |
8567 | int errcode; | |
8568 | ||
8569 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8570 | if (errcode != 0) | |
8571 | { | |
8572 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8573 | ||
8574 | make_cleanup (xfree, err); | |
8575 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8576 | } | |
8577 | c->regex = xstrdup (arg); | |
8578 | } | |
8579 | ||
8580 | c->is_load = is_load; | |
91985142 | 8581 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8582 | &catch_solib_breakpoint_ops); |
8583 | ||
91985142 MG |
8584 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8585 | ||
edcc5120 TT |
8586 | discard_cleanups (cleanup); |
8587 | install_breakpoint (0, &c->base, 1); | |
8588 | } | |
8589 | ||
91985142 MG |
8590 | /* A helper function that does all the work for "catch load" and |
8591 | "catch unload". */ | |
8592 | ||
8593 | static void | |
8594 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8595 | struct cmd_list_element *command) | |
8596 | { | |
8597 | int tempflag; | |
8598 | const int enabled = 1; | |
8599 | ||
8600 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8601 | ||
8602 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8603 | } | |
8604 | ||
edcc5120 TT |
8605 | static void |
8606 | catch_load_command_1 (char *arg, int from_tty, | |
8607 | struct cmd_list_element *command) | |
8608 | { | |
8609 | catch_load_or_unload (arg, from_tty, 1, command); | |
8610 | } | |
8611 | ||
8612 | static void | |
8613 | catch_unload_command_1 (char *arg, int from_tty, | |
8614 | struct cmd_list_element *command) | |
8615 | { | |
8616 | catch_load_or_unload (arg, from_tty, 0, command); | |
8617 | } | |
8618 | ||
346774a9 PA |
8619 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8620 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8621 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8622 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8623 | |
ab04a2af | 8624 | void |
346774a9 PA |
8625 | init_catchpoint (struct breakpoint *b, |
8626 | struct gdbarch *gdbarch, int tempflag, | |
8627 | char *cond_string, | |
c0a91b2b | 8628 | const struct breakpoint_ops *ops) |
c906108c | 8629 | { |
c5aa993b | 8630 | struct symtab_and_line sal; |
346774a9 | 8631 | |
fe39c653 | 8632 | init_sal (&sal); |
6c95b8df | 8633 | sal.pspace = current_program_space; |
c5aa993b | 8634 | |
28010a5d | 8635 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8636 | |
1b36a34b | 8637 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8638 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8639 | } |
8640 | ||
28010a5d | 8641 | void |
3ea46bff | 8642 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8643 | { |
8644 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8645 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8646 | if (is_tracepoint (b)) |
8647 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8648 | if (!internal) |
8649 | mention (b); | |
c56053d2 | 8650 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8651 | |
8652 | if (update_gll) | |
44702360 | 8653 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8654 | } |
8655 | ||
9b70b993 | 8656 | static void |
a6d9a66e UW |
8657 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8658 | int tempflag, char *cond_string, | |
c0a91b2b | 8659 | const struct breakpoint_ops *ops) |
c906108c | 8660 | { |
e29a4733 | 8661 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8662 | |
e29a4733 PA |
8663 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8664 | ||
8665 | c->forked_inferior_pid = null_ptid; | |
8666 | ||
3ea46bff | 8667 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8668 | } |
8669 | ||
fe798b75 JB |
8670 | /* Exec catchpoints. */ |
8671 | ||
b4d90040 PA |
8672 | /* An instance of this type is used to represent an exec catchpoint. |
8673 | It includes a "struct breakpoint" as a kind of base class; users | |
8674 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8675 | really of this type iff its ops pointer points to | |
8676 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8677 | ||
8678 | struct exec_catchpoint | |
8679 | { | |
8680 | /* The base class. */ | |
8681 | struct breakpoint base; | |
8682 | ||
8683 | /* Filename of a program whose exec triggered this catchpoint. | |
8684 | This field is only valid immediately after this catchpoint has | |
8685 | triggered. */ | |
8686 | char *exec_pathname; | |
8687 | }; | |
8688 | ||
8689 | /* Implement the "dtor" breakpoint_ops method for exec | |
8690 | catchpoints. */ | |
8691 | ||
8692 | static void | |
8693 | dtor_catch_exec (struct breakpoint *b) | |
8694 | { | |
8695 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8696 | ||
8697 | xfree (c->exec_pathname); | |
348d480f | 8698 | |
2060206e | 8699 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8700 | } |
8701 | ||
77b06cd7 TJB |
8702 | static int |
8703 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8704 | { |
dfd4cc63 | 8705 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8706 | } |
c906108c | 8707 | |
fe798b75 | 8708 | static int |
77b06cd7 | 8709 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8710 | { |
dfd4cc63 | 8711 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8712 | } |
c906108c | 8713 | |
fe798b75 | 8714 | static int |
f1310107 | 8715 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8716 | struct address_space *aspace, CORE_ADDR bp_addr, |
8717 | const struct target_waitstatus *ws) | |
fe798b75 | 8718 | { |
b4d90040 PA |
8719 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8720 | ||
f90263c1 TT |
8721 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8722 | return 0; | |
8723 | ||
8724 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8725 | return 1; | |
fe798b75 | 8726 | } |
c906108c | 8727 | |
fe798b75 | 8728 | static enum print_stop_action |
348d480f | 8729 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8730 | { |
36dfb11c | 8731 | struct ui_out *uiout = current_uiout; |
348d480f | 8732 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8733 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8734 | ||
fe798b75 | 8735 | annotate_catchpoint (b->number); |
f303dbd6 | 8736 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8737 | if (b->disposition == disp_del) |
f303dbd6 | 8738 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8739 | else |
f303dbd6 | 8740 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8741 | if (ui_out_is_mi_like_p (uiout)) |
8742 | { | |
8743 | ui_out_field_string (uiout, "reason", | |
8744 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8745 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8746 | } | |
8747 | ui_out_field_int (uiout, "bkptno", b->number); | |
8748 | ui_out_text (uiout, " (exec'd "); | |
8749 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8750 | ui_out_text (uiout, "), "); | |
8751 | ||
fe798b75 | 8752 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8753 | } |
8754 | ||
fe798b75 | 8755 | static void |
a6d9a66e | 8756 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8757 | { |
b4d90040 | 8758 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8759 | struct value_print_options opts; |
79a45e25 | 8760 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8761 | |
8762 | get_user_print_options (&opts); | |
8763 | ||
8764 | /* Field 4, the address, is omitted (which makes the columns | |
8765 | not line up too nicely with the headers, but the effect | |
8766 | is relatively readable). */ | |
8767 | if (opts.addressprint) | |
8768 | ui_out_field_skip (uiout, "addr"); | |
8769 | annotate_field (5); | |
8770 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8771 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8772 | { |
8773 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8774 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8775 | ui_out_text (uiout, "\" "); |
8776 | } | |
8ac3646f TT |
8777 | |
8778 | if (ui_out_is_mi_like_p (uiout)) | |
8779 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8780 | } |
8781 | ||
8782 | static void | |
8783 | print_mention_catch_exec (struct breakpoint *b) | |
8784 | { | |
8785 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8786 | } | |
8787 | ||
6149aea9 PA |
8788 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8789 | catchpoints. */ | |
8790 | ||
8791 | static void | |
8792 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8793 | { | |
8794 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8795 | print_recreate_thread (b, fp); |
6149aea9 PA |
8796 | } |
8797 | ||
2060206e | 8798 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8799 | |
c906108c | 8800 | static int |
fba45db2 | 8801 | hw_breakpoint_used_count (void) |
c906108c | 8802 | { |
c906108c | 8803 | int i = 0; |
f1310107 TJB |
8804 | struct breakpoint *b; |
8805 | struct bp_location *bl; | |
c906108c SS |
8806 | |
8807 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8808 | { |
d6b74ac4 | 8809 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8810 | for (bl = b->loc; bl; bl = bl->next) |
8811 | { | |
8812 | /* Special types of hardware breakpoints may use more than | |
8813 | one register. */ | |
348d480f | 8814 | i += b->ops->resources_needed (bl); |
f1310107 | 8815 | } |
c5aa993b | 8816 | } |
c906108c SS |
8817 | |
8818 | return i; | |
8819 | } | |
8820 | ||
a1398e0c PA |
8821 | /* Returns the resources B would use if it were a hardware |
8822 | watchpoint. */ | |
8823 | ||
c906108c | 8824 | static int |
a1398e0c | 8825 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8826 | { |
c906108c | 8827 | int i = 0; |
e09342b5 | 8828 | struct bp_location *bl; |
c906108c | 8829 | |
a1398e0c PA |
8830 | if (!breakpoint_enabled (b)) |
8831 | return 0; | |
8832 | ||
8833 | for (bl = b->loc; bl; bl = bl->next) | |
8834 | { | |
8835 | /* Special types of hardware watchpoints may use more than | |
8836 | one register. */ | |
8837 | i += b->ops->resources_needed (bl); | |
8838 | } | |
8839 | ||
8840 | return i; | |
8841 | } | |
8842 | ||
8843 | /* Returns the sum the used resources of all hardware watchpoints of | |
8844 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8845 | the sum of the used resources of all hardware watchpoints of other | |
8846 | types _not_ TYPE. */ | |
8847 | ||
8848 | static int | |
8849 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8850 | enum bptype type, int *other_type_used) | |
8851 | { | |
8852 | int i = 0; | |
8853 | struct breakpoint *b; | |
8854 | ||
c906108c SS |
8855 | *other_type_used = 0; |
8856 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8857 | { |
a1398e0c PA |
8858 | if (b == except) |
8859 | continue; | |
e09342b5 TJB |
8860 | if (!breakpoint_enabled (b)) |
8861 | continue; | |
8862 | ||
a1398e0c PA |
8863 | if (b->type == type) |
8864 | i += hw_watchpoint_use_count (b); | |
8865 | else if (is_hardware_watchpoint (b)) | |
8866 | *other_type_used = 1; | |
e09342b5 TJB |
8867 | } |
8868 | ||
c906108c SS |
8869 | return i; |
8870 | } | |
8871 | ||
c906108c | 8872 | void |
fba45db2 | 8873 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8874 | { |
c5aa993b | 8875 | struct breakpoint *b; |
c906108c SS |
8876 | |
8877 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8878 | { |
cc60f2e3 | 8879 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8880 | { |
b5de0fa7 | 8881 | b->enable_state = bp_call_disabled; |
44702360 | 8882 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8883 | } |
8884 | } | |
c906108c SS |
8885 | } |
8886 | ||
8887 | void | |
fba45db2 | 8888 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8889 | { |
c5aa993b | 8890 | struct breakpoint *b; |
c906108c SS |
8891 | |
8892 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8893 | { |
cc60f2e3 | 8894 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8895 | { |
b5de0fa7 | 8896 | b->enable_state = bp_enabled; |
44702360 | 8897 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8898 | } |
8899 | } | |
c906108c SS |
8900 | } |
8901 | ||
8bea4e01 UW |
8902 | void |
8903 | disable_breakpoints_before_startup (void) | |
8904 | { | |
6c95b8df | 8905 | current_program_space->executing_startup = 1; |
44702360 | 8906 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8907 | } |
8908 | ||
8909 | void | |
8910 | enable_breakpoints_after_startup (void) | |
8911 | { | |
6c95b8df | 8912 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8913 | breakpoint_re_set (); |
8bea4e01 UW |
8914 | } |
8915 | ||
7c16b83e PA |
8916 | /* Create a new single-step breakpoint for thread THREAD, with no |
8917 | locations. */ | |
c906108c | 8918 | |
7c16b83e PA |
8919 | static struct breakpoint * |
8920 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8921 | { | |
8922 | struct breakpoint *b = XNEW (struct breakpoint); | |
8923 | ||
8924 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8925 | &momentary_breakpoint_ops); | |
8926 | ||
8927 | b->disposition = disp_donttouch; | |
8928 | b->frame_id = null_frame_id; | |
8929 | ||
8930 | b->thread = thread; | |
8931 | gdb_assert (b->thread != 0); | |
8932 | ||
8933 | add_to_breakpoint_chain (b); | |
8934 | ||
8935 | return b; | |
8936 | } | |
8937 | ||
8938 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8939 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8940 | frame. */ | |
c906108c SS |
8941 | |
8942 | struct breakpoint * | |
a6d9a66e UW |
8943 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8944 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8945 | { |
52f0bd74 | 8946 | struct breakpoint *b; |
edb3359d | 8947 | |
193facb3 JK |
8948 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8949 | tail-called one. */ | |
8950 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8951 | |
06edf0c0 | 8952 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8953 | b->enable_state = bp_enabled; |
8954 | b->disposition = disp_donttouch; | |
818dd999 | 8955 | b->frame_id = frame_id; |
c906108c | 8956 | |
4a64f543 MS |
8957 | /* If we're debugging a multi-threaded program, then we want |
8958 | momentary breakpoints to be active in only a single thread of | |
8959 | control. */ | |
39f77062 | 8960 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8961 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8962 | |
44702360 | 8963 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8964 | |
c906108c SS |
8965 | return b; |
8966 | } | |
611c83ae | 8967 | |
06edf0c0 | 8968 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8969 | The new breakpoint will have type TYPE, use OPS as its |
8970 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8971 | |
06edf0c0 PA |
8972 | static struct breakpoint * |
8973 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8974 | enum bptype type, | |
a1aa2221 LM |
8975 | const struct breakpoint_ops *ops, |
8976 | int loc_enabled) | |
e58b0e63 PA |
8977 | { |
8978 | struct breakpoint *copy; | |
8979 | ||
06edf0c0 | 8980 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8981 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8982 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8983 | |
a6d9a66e | 8984 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8985 | copy->loc->requested_address = orig->loc->requested_address; |
8986 | copy->loc->address = orig->loc->address; | |
8987 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8988 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8989 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8990 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8991 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8992 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8993 | copy->frame_id = orig->frame_id; |
8994 | copy->thread = orig->thread; | |
6c95b8df | 8995 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8996 | |
8997 | copy->enable_state = bp_enabled; | |
8998 | copy->disposition = disp_donttouch; | |
8999 | copy->number = internal_breakpoint_number--; | |
9000 | ||
44702360 | 9001 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9002 | return copy; |
9003 | } | |
9004 | ||
06edf0c0 PA |
9005 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9006 | ORIG is NULL. */ | |
9007 | ||
9008 | struct breakpoint * | |
9009 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9010 | { | |
9011 | /* If there's nothing to clone, then return nothing. */ | |
9012 | if (orig == NULL) | |
9013 | return NULL; | |
9014 | ||
a1aa2221 | 9015 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9016 | } |
9017 | ||
611c83ae | 9018 | struct breakpoint * |
a6d9a66e UW |
9019 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9020 | enum bptype type) | |
611c83ae PA |
9021 | { |
9022 | struct symtab_and_line sal; | |
9023 | ||
9024 | sal = find_pc_line (pc, 0); | |
9025 | sal.pc = pc; | |
9026 | sal.section = find_pc_overlay (pc); | |
9027 | sal.explicit_pc = 1; | |
9028 | ||
a6d9a66e | 9029 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9030 | } |
c906108c | 9031 | \f |
c5aa993b | 9032 | |
c906108c SS |
9033 | /* Tell the user we have just set a breakpoint B. */ |
9034 | ||
9035 | static void | |
fba45db2 | 9036 | mention (struct breakpoint *b) |
c906108c | 9037 | { |
348d480f | 9038 | b->ops->print_mention (b); |
79a45e25 | 9039 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9040 | return; |
c906108c SS |
9041 | printf_filtered ("\n"); |
9042 | } | |
c906108c | 9043 | \f |
c5aa993b | 9044 | |
1a853c52 PA |
9045 | static int bp_loc_is_permanent (struct bp_location *loc); |
9046 | ||
0d381245 | 9047 | static struct bp_location * |
39d61571 | 9048 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9049 | const struct symtab_and_line *sal) |
9050 | { | |
9051 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9052 | CORE_ADDR adjusted_address; |
9053 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9054 | ||
9055 | if (loc_gdbarch == NULL) | |
9056 | loc_gdbarch = b->gdbarch; | |
9057 | ||
9058 | /* Adjust the breakpoint's address prior to allocating a location. | |
9059 | Once we call allocate_bp_location(), that mostly uninitialized | |
9060 | location will be placed on the location chain. Adjustment of the | |
9061 | breakpoint may cause target_read_memory() to be called and we do | |
9062 | not want its scan of the location chain to find a breakpoint and | |
9063 | location that's only been partially initialized. */ | |
9064 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9065 | sal->pc, b->type); | |
0d381245 | 9066 | |
d30113d4 | 9067 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9068 | loc = allocate_bp_location (b); |
d30113d4 JK |
9069 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9070 | tmp = &((*tmp)->next)) | |
0d381245 | 9071 | ; |
d30113d4 | 9072 | loc->next = *tmp; |
0d381245 | 9073 | *tmp = loc; |
3742cc8b | 9074 | |
0d381245 | 9075 | loc->requested_address = sal->pc; |
3742cc8b | 9076 | loc->address = adjusted_address; |
6c95b8df | 9077 | loc->pspace = sal->pspace; |
729662a5 TT |
9078 | loc->probe.probe = sal->probe; |
9079 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9080 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9081 | loc->section = sal->section; |
3742cc8b | 9082 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9083 | loc->line_number = sal->line; |
2f202fde | 9084 | loc->symtab = sal->symtab; |
f8eba3c6 | 9085 | |
0e30163f JK |
9086 | set_breakpoint_location_function (loc, |
9087 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9088 | |
6ae88661 LM |
9089 | /* While by definition, permanent breakpoints are already present in the |
9090 | code, we don't mark the location as inserted. Normally one would expect | |
9091 | that GDB could rely on that breakpoint instruction to stop the program, | |
9092 | thus removing the need to insert its own breakpoint, except that executing | |
9093 | the breakpoint instruction can kill the target instead of reporting a | |
9094 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9095 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9096 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9097 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9098 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9099 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9100 | it manually increments the PC, thus avoiding executing the breakpoint | |
9101 | instruction.) */ | |
1a853c52 | 9102 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9103 | loc->permanent = 1; |
1a853c52 | 9104 | |
0d381245 VP |
9105 | return loc; |
9106 | } | |
514f746b AR |
9107 | \f |
9108 | ||
1cf4d951 | 9109 | /* See breakpoint.h. */ |
514f746b | 9110 | |
1cf4d951 PA |
9111 | int |
9112 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9113 | { |
9114 | int len; | |
9115 | CORE_ADDR addr; | |
1afeeb75 | 9116 | const gdb_byte *bpoint; |
514f746b | 9117 | gdb_byte *target_mem; |
939c61fa JK |
9118 | struct cleanup *cleanup; |
9119 | int retval = 0; | |
514f746b | 9120 | |
1cf4d951 PA |
9121 | addr = address; |
9122 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9123 | ||
9124 | /* Software breakpoints unsupported? */ | |
9125 | if (bpoint == NULL) | |
9126 | return 0; | |
9127 | ||
224c3ddb | 9128 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9129 | |
9130 | /* Enable the automatic memory restoration from breakpoints while | |
9131 | we read the memory. Otherwise we could say about our temporary | |
9132 | breakpoints they are permanent. */ | |
9133 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9134 | ||
9135 | if (target_read_memory (address, target_mem, len) == 0 | |
9136 | && memcmp (target_mem, bpoint, len) == 0) | |
9137 | retval = 1; | |
9138 | ||
9139 | do_cleanups (cleanup); | |
9140 | ||
9141 | return retval; | |
9142 | } | |
9143 | ||
9144 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9145 | return 0 otherwise. */ | |
9146 | ||
9147 | static int | |
9148 | bp_loc_is_permanent (struct bp_location *loc) | |
9149 | { | |
9150 | struct cleanup *cleanup; | |
9151 | int retval; | |
9152 | ||
514f746b AR |
9153 | gdb_assert (loc != NULL); |
9154 | ||
244558af LM |
9155 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9156 | attempt to read from the addresses the locations of these breakpoint types | |
9157 | point to. program_breakpoint_here_p, below, will attempt to read | |
9158 | memory. */ | |
9159 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9160 | return 0; | |
9161 | ||
6c95b8df | 9162 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9163 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9164 | |
1cf4d951 | 9165 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9166 | |
939c61fa JK |
9167 | do_cleanups (cleanup); |
9168 | ||
9169 | return retval; | |
514f746b AR |
9170 | } |
9171 | ||
e7e0cddf SS |
9172 | /* Build a command list for the dprintf corresponding to the current |
9173 | settings of the dprintf style options. */ | |
9174 | ||
9175 | static void | |
9176 | update_dprintf_command_list (struct breakpoint *b) | |
9177 | { | |
9178 | char *dprintf_args = b->extra_string; | |
9179 | char *printf_line = NULL; | |
9180 | ||
9181 | if (!dprintf_args) | |
9182 | return; | |
9183 | ||
9184 | dprintf_args = skip_spaces (dprintf_args); | |
9185 | ||
9186 | /* Allow a comma, as it may have terminated a location, but don't | |
9187 | insist on it. */ | |
9188 | if (*dprintf_args == ',') | |
9189 | ++dprintf_args; | |
9190 | dprintf_args = skip_spaces (dprintf_args); | |
9191 | ||
9192 | if (*dprintf_args != '"') | |
9193 | error (_("Bad format string, missing '\"'.")); | |
9194 | ||
d3ce09f5 | 9195 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9196 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9197 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9198 | { |
9199 | if (!dprintf_function) | |
9200 | error (_("No function supplied for dprintf call")); | |
9201 | ||
9202 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9203 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9204 | dprintf_function, | |
9205 | dprintf_channel, | |
9206 | dprintf_args); | |
9207 | else | |
9208 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9209 | dprintf_function, | |
9210 | dprintf_args); | |
9211 | } | |
d3ce09f5 SS |
9212 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9213 | { | |
9214 | if (target_can_run_breakpoint_commands ()) | |
9215 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9216 | else | |
9217 | { | |
9218 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9219 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9220 | } | |
9221 | } | |
e7e0cddf SS |
9222 | else |
9223 | internal_error (__FILE__, __LINE__, | |
9224 | _("Invalid dprintf style.")); | |
9225 | ||
f28045c2 | 9226 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9227 | /* Manufacture a printf sequence. */ |
f28045c2 | 9228 | { |
8d749320 | 9229 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9230 | |
f28045c2 YQ |
9231 | printf_cmd_line->control_type = simple_control; |
9232 | printf_cmd_line->body_count = 0; | |
9233 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9234 | printf_cmd_line->next = NULL; |
f28045c2 | 9235 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9236 | |
f28045c2 YQ |
9237 | breakpoint_set_commands (b, printf_cmd_line); |
9238 | } | |
e7e0cddf SS |
9239 | } |
9240 | ||
9241 | /* Update all dprintf commands, making their command lists reflect | |
9242 | current style settings. */ | |
9243 | ||
9244 | static void | |
9245 | update_dprintf_commands (char *args, int from_tty, | |
9246 | struct cmd_list_element *c) | |
9247 | { | |
9248 | struct breakpoint *b; | |
9249 | ||
9250 | ALL_BREAKPOINTS (b) | |
9251 | { | |
9252 | if (b->type == bp_dprintf) | |
9253 | update_dprintf_command_list (b); | |
9254 | } | |
9255 | } | |
c3f6f71d | 9256 | |
f00aae0f KS |
9257 | /* Create a breakpoint with SAL as location. Use LOCATION |
9258 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9259 | as condition expression. If LOCATION is NULL then create an |
9260 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9261 | |
9262 | static void | |
d9b3f62e | 9263 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9264 | struct symtabs_and_lines sals, |
9265 | struct event_location *location, | |
f8eba3c6 | 9266 | char *filter, char *cond_string, |
e7e0cddf | 9267 | char *extra_string, |
d9b3f62e PA |
9268 | enum bptype type, enum bpdisp disposition, |
9269 | int thread, int task, int ignore_count, | |
c0a91b2b | 9270 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9271 | int enabled, int internal, unsigned flags, |
9272 | int display_canonical) | |
018d34a4 | 9273 | { |
0d381245 | 9274 | int i; |
018d34a4 VP |
9275 | |
9276 | if (type == bp_hardware_breakpoint) | |
9277 | { | |
fbbd034e AS |
9278 | int target_resources_ok; |
9279 | ||
9280 | i = hw_breakpoint_used_count (); | |
9281 | target_resources_ok = | |
9282 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9283 | i + 1, 0); |
9284 | if (target_resources_ok == 0) | |
9285 | error (_("No hardware breakpoint support in the target.")); | |
9286 | else if (target_resources_ok < 0) | |
9287 | error (_("Hardware breakpoints used exceeds limit.")); | |
9288 | } | |
9289 | ||
6c95b8df PA |
9290 | gdb_assert (sals.nelts > 0); |
9291 | ||
0d381245 VP |
9292 | for (i = 0; i < sals.nelts; ++i) |
9293 | { | |
9294 | struct symtab_and_line sal = sals.sals[i]; | |
9295 | struct bp_location *loc; | |
9296 | ||
9297 | if (from_tty) | |
5af949e3 UW |
9298 | { |
9299 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9300 | if (!loc_gdbarch) | |
9301 | loc_gdbarch = gdbarch; | |
9302 | ||
9303 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9304 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9305 | } |
0d381245 VP |
9306 | |
9307 | if (i == 0) | |
9308 | { | |
d9b3f62e | 9309 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9310 | b->thread = thread; |
4a306c9a | 9311 | b->task = task; |
855a6e68 | 9312 | |
0d381245 | 9313 | b->cond_string = cond_string; |
e7e0cddf | 9314 | b->extra_string = extra_string; |
0d381245 | 9315 | b->ignore_count = ignore_count; |
41447f92 | 9316 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9317 | b->disposition = disposition; |
6c95b8df | 9318 | |
44f238bb PA |
9319 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9320 | b->loc->inserted = 1; | |
9321 | ||
0fb4aa4b PA |
9322 | if (type == bp_static_tracepoint) |
9323 | { | |
d9b3f62e | 9324 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9325 | struct static_tracepoint_marker marker; |
9326 | ||
983af33b | 9327 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9328 | { |
9329 | /* We already know the marker exists, otherwise, we | |
9330 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9331 | const char *p = &event_location_to_string (b->location)[3]; |
9332 | const char *endp; | |
0fb4aa4b | 9333 | char *marker_str; |
0fb4aa4b | 9334 | |
f00aae0f | 9335 | p = skip_spaces_const (p); |
0fb4aa4b | 9336 | |
f00aae0f | 9337 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9338 | |
9339 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9340 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9341 | |
3e43a32a MS |
9342 | printf_filtered (_("Probed static tracepoint " |
9343 | "marker \"%s\"\n"), | |
d9b3f62e | 9344 | t->static_trace_marker_id); |
0fb4aa4b PA |
9345 | } |
9346 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9347 | { | |
d9b3f62e | 9348 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9349 | release_static_tracepoint_marker (&marker); |
9350 | ||
3e43a32a MS |
9351 | printf_filtered (_("Probed static tracepoint " |
9352 | "marker \"%s\"\n"), | |
d9b3f62e | 9353 | t->static_trace_marker_id); |
0fb4aa4b PA |
9354 | } |
9355 | else | |
3e43a32a MS |
9356 | warning (_("Couldn't determine the static " |
9357 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9358 | } |
9359 | ||
0d381245 VP |
9360 | loc = b->loc; |
9361 | } | |
9362 | else | |
018d34a4 | 9363 | { |
39d61571 | 9364 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9365 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9366 | loc->inserted = 1; | |
0d381245 VP |
9367 | } |
9368 | ||
9369 | if (b->cond_string) | |
9370 | { | |
bbc13ae3 KS |
9371 | const char *arg = b->cond_string; |
9372 | ||
1bb9788d TT |
9373 | loc->cond = parse_exp_1 (&arg, loc->address, |
9374 | block_for_pc (loc->address), 0); | |
0d381245 | 9375 | if (*arg) |
588ae58c | 9376 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9377 | } |
e7e0cddf SS |
9378 | |
9379 | /* Dynamic printf requires and uses additional arguments on the | |
9380 | command line, otherwise it's an error. */ | |
9381 | if (type == bp_dprintf) | |
9382 | { | |
9383 | if (b->extra_string) | |
9384 | update_dprintf_command_list (b); | |
9385 | else | |
9386 | error (_("Format string required")); | |
9387 | } | |
9388 | else if (b->extra_string) | |
588ae58c | 9389 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9390 | } |
018d34a4 | 9391 | |
56435ebe | 9392 | b->display_canonical = display_canonical; |
f00aae0f KS |
9393 | if (location != NULL) |
9394 | b->location = location; | |
018d34a4 | 9395 | else |
305e13e6 JB |
9396 | { |
9397 | const char *addr_string = NULL; | |
9398 | int addr_string_len = 0; | |
9399 | ||
9400 | if (location != NULL) | |
9401 | addr_string = event_location_to_string (location); | |
9402 | if (addr_string != NULL) | |
9403 | addr_string_len = strlen (addr_string); | |
9404 | ||
9405 | b->location = new_address_location (b->loc->address, | |
9406 | addr_string, addr_string_len); | |
9407 | } | |
f8eba3c6 | 9408 | b->filter = filter; |
d9b3f62e | 9409 | } |
018d34a4 | 9410 | |
d9b3f62e PA |
9411 | static void |
9412 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9413 | struct symtabs_and_lines sals, |
9414 | struct event_location *location, | |
f8eba3c6 | 9415 | char *filter, char *cond_string, |
e7e0cddf | 9416 | char *extra_string, |
d9b3f62e PA |
9417 | enum bptype type, enum bpdisp disposition, |
9418 | int thread, int task, int ignore_count, | |
c0a91b2b | 9419 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9420 | int enabled, int internal, unsigned flags, |
9421 | int display_canonical) | |
d9b3f62e PA |
9422 | { |
9423 | struct breakpoint *b; | |
9424 | struct cleanup *old_chain; | |
9425 | ||
9426 | if (is_tracepoint_type (type)) | |
9427 | { | |
9428 | struct tracepoint *t; | |
9429 | ||
9430 | t = XCNEW (struct tracepoint); | |
9431 | b = &t->base; | |
9432 | } | |
9433 | else | |
9434 | b = XNEW (struct breakpoint); | |
9435 | ||
9436 | old_chain = make_cleanup (xfree, b); | |
9437 | ||
9438 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9439 | sals, location, |
e7e0cddf | 9440 | filter, cond_string, extra_string, |
d9b3f62e PA |
9441 | type, disposition, |
9442 | thread, task, ignore_count, | |
9443 | ops, from_tty, | |
44f238bb PA |
9444 | enabled, internal, flags, |
9445 | display_canonical); | |
d9b3f62e PA |
9446 | discard_cleanups (old_chain); |
9447 | ||
3ea46bff | 9448 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9449 | } |
9450 | ||
9451 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9452 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9453 | value. COND_STRING, if not NULL, specified the condition to be | |
9454 | used for all breakpoints. Essentially the only case where | |
9455 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9456 | function. In that case, it's still not possible to specify | |
9457 | separate conditions for different overloaded functions, so | |
9458 | we take just a single condition string. | |
9459 | ||
c3f6f71d | 9460 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9461 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9462 | array contents). If the function fails (error() is called), the |
9463 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9464 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9465 | |
9466 | static void | |
8cdf0e15 | 9467 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9468 | struct linespec_result *canonical, |
e7e0cddf | 9469 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9470 | enum bptype type, enum bpdisp disposition, |
9471 | int thread, int task, int ignore_count, | |
c0a91b2b | 9472 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9473 | int enabled, int internal, unsigned flags) |
c906108c | 9474 | { |
018d34a4 | 9475 | int i; |
f8eba3c6 | 9476 | struct linespec_sals *lsal; |
cc59ec59 | 9477 | |
f8eba3c6 TT |
9478 | if (canonical->pre_expanded) |
9479 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9480 | ||
9481 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9482 | { |
f00aae0f | 9483 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9484 | 'break', without arguments. */ |
f00aae0f KS |
9485 | struct event_location *location |
9486 | = (canonical->location != NULL | |
9487 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9488 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9489 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9490 | |
f8eba3c6 TT |
9491 | make_cleanup (xfree, filter_string); |
9492 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9493 | location, |
f8eba3c6 | 9494 | filter_string, |
e7e0cddf SS |
9495 | cond_string, extra_string, |
9496 | type, disposition, | |
84f4c1fe | 9497 | thread, task, ignore_count, ops, |
44f238bb | 9498 | from_tty, enabled, internal, flags, |
56435ebe | 9499 | canonical->special_display); |
f8eba3c6 | 9500 | discard_cleanups (inner); |
c3f6f71d | 9501 | } |
c3f6f71d | 9502 | } |
c906108c | 9503 | |
f00aae0f | 9504 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9505 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9506 | addresses found. LOCATION points to the end of the SAL (for |
9507 | linespec locations). | |
9998af43 TJB |
9508 | |
9509 | The array and the line spec strings are allocated on the heap, it is | |
9510 | the caller's responsibility to free them. */ | |
c906108c | 9511 | |
b9362cc7 | 9512 | static void |
f00aae0f | 9513 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9514 | struct linespec_result *canonical) |
c3f6f71d | 9515 | { |
f00aae0f KS |
9516 | struct symtab_and_line cursal; |
9517 | ||
9518 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9519 | { | |
9520 | const char *address = get_linespec_location (location); | |
9521 | ||
9522 | if (address == NULL) | |
9523 | { | |
9524 | /* The last displayed codepoint, if it's valid, is our default | |
9525 | breakpoint address. */ | |
9526 | if (last_displayed_sal_is_valid ()) | |
9527 | { | |
9528 | struct linespec_sals lsal; | |
9529 | struct symtab_and_line sal; | |
9530 | CORE_ADDR pc; | |
9531 | ||
9532 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9533 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9534 | |
9535 | /* Set sal's pspace, pc, symtab, and line to the values | |
9536 | corresponding to the last call to print_frame_info. | |
9537 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9538 | as the breakpoint line number is inappropriate otherwise. | |
9539 | find_pc_line would adjust PC, re-set it back. */ | |
9540 | get_last_displayed_sal (&sal); | |
9541 | pc = sal.pc; | |
9542 | sal = find_pc_line (pc, 0); | |
9543 | ||
9544 | /* "break" without arguments is equivalent to "break *PC" | |
9545 | where PC is the last displayed codepoint's address. So | |
9546 | make sure to set sal.explicit_pc to prevent GDB from | |
9547 | trying to expand the list of sals to include all other | |
9548 | instances with the same symtab and line. */ | |
9549 | sal.pc = pc; | |
9550 | sal.explicit_pc = 1; | |
9551 | ||
9552 | lsal.sals.sals[0] = sal; | |
9553 | lsal.sals.nelts = 1; | |
9554 | lsal.canonical = NULL; | |
9555 | ||
9556 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9557 | return; | |
9558 | } | |
9559 | else | |
9560 | error (_("No default breakpoint address now.")); | |
c906108c | 9561 | } |
c906108c | 9562 | } |
f00aae0f KS |
9563 | |
9564 | /* Force almost all breakpoints to be in terms of the | |
9565 | current_source_symtab (which is decode_line_1's default). | |
9566 | This should produce the results we want almost all of the | |
9567 | time while leaving default_breakpoint_* alone. | |
9568 | ||
9569 | ObjC: However, don't match an Objective-C method name which | |
9570 | may have a '+' or '-' succeeded by a '['. */ | |
9571 | cursal = get_current_source_symtab_and_line (); | |
9572 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9573 | { |
f00aae0f | 9574 | const char *address = NULL; |
cc80f267 | 9575 | |
f00aae0f KS |
9576 | if (event_location_type (location) == LINESPEC_LOCATION) |
9577 | address = get_linespec_location (location); | |
cc80f267 | 9578 | |
f00aae0f KS |
9579 | if (!cursal.symtab |
9580 | || (address != NULL | |
9581 | && strchr ("+-", address[0]) != NULL | |
9582 | && address[1] != '[')) | |
9583 | { | |
c2f4122d | 9584 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9585 | get_last_displayed_symtab (), |
9586 | get_last_displayed_line (), | |
9587 | canonical, NULL, NULL); | |
9588 | return; | |
9589 | } | |
c906108c | 9590 | } |
f00aae0f | 9591 | |
c2f4122d | 9592 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9593 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9594 | } |
c906108c | 9595 | |
c906108c | 9596 | |
c3f6f71d | 9597 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9598 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9599 | |
b9362cc7 | 9600 | static void |
23e7acfb | 9601 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9602 | { |
9603 | int i; | |
cc59ec59 | 9604 | |
c3f6f71d | 9605 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9606 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9607 | } |
9608 | ||
7a697b8d SS |
9609 | /* Fast tracepoints may have restrictions on valid locations. For |
9610 | instance, a fast tracepoint using a jump instead of a trap will | |
9611 | likely have to overwrite more bytes than a trap would, and so can | |
9612 | only be placed where the instruction is longer than the jump, or a | |
9613 | multi-instruction sequence does not have a jump into the middle of | |
9614 | it, etc. */ | |
9615 | ||
9616 | static void | |
9617 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9618 | struct symtabs_and_lines *sals) | |
9619 | { | |
9620 | int i, rslt; | |
9621 | struct symtab_and_line *sal; | |
9622 | char *msg; | |
9623 | struct cleanup *old_chain; | |
9624 | ||
9625 | for (i = 0; i < sals->nelts; i++) | |
9626 | { | |
f8eba3c6 TT |
9627 | struct gdbarch *sarch; |
9628 | ||
7a697b8d SS |
9629 | sal = &sals->sals[i]; |
9630 | ||
f8eba3c6 TT |
9631 | sarch = get_sal_arch (*sal); |
9632 | /* We fall back to GDBARCH if there is no architecture | |
9633 | associated with SAL. */ | |
9634 | if (sarch == NULL) | |
9635 | sarch = gdbarch; | |
6b940e6a | 9636 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9637 | old_chain = make_cleanup (xfree, msg); |
9638 | ||
9639 | if (!rslt) | |
9640 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9641 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9642 | |
9643 | do_cleanups (old_chain); | |
9644 | } | |
9645 | } | |
9646 | ||
018d34a4 VP |
9647 | /* Given TOK, a string specification of condition and thread, as |
9648 | accepted by the 'break' command, extract the condition | |
9649 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9650 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9651 | If no condition is found, *COND_STRING is set to NULL. |
9652 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9653 | |
9654 | static void | |
bbc13ae3 | 9655 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9656 | char **cond_string, int *thread, int *task, |
9657 | char **rest) | |
018d34a4 VP |
9658 | { |
9659 | *cond_string = NULL; | |
9660 | *thread = -1; | |
ed1d1739 KS |
9661 | *task = 0; |
9662 | *rest = NULL; | |
9663 | ||
018d34a4 VP |
9664 | while (tok && *tok) |
9665 | { | |
bbc13ae3 | 9666 | const char *end_tok; |
018d34a4 | 9667 | int toklen; |
bbc13ae3 KS |
9668 | const char *cond_start = NULL; |
9669 | const char *cond_end = NULL; | |
cc59ec59 | 9670 | |
bbc13ae3 | 9671 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9672 | |
9673 | if ((*tok == '"' || *tok == ',') && rest) | |
9674 | { | |
9675 | *rest = savestring (tok, strlen (tok)); | |
9676 | return; | |
9677 | } | |
9678 | ||
bbc13ae3 | 9679 | end_tok = skip_to_space_const (tok); |
d634f2de | 9680 | |
018d34a4 | 9681 | toklen = end_tok - tok; |
d634f2de | 9682 | |
018d34a4 VP |
9683 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9684 | { | |
f7545552 TT |
9685 | struct expression *expr; |
9686 | ||
018d34a4 | 9687 | tok = cond_start = end_tok + 1; |
1bb9788d | 9688 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9689 | xfree (expr); |
018d34a4 | 9690 | cond_end = tok; |
d634f2de | 9691 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9692 | } |
9693 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9694 | { | |
5d5658a1 PA |
9695 | const char *tmptok; |
9696 | struct thread_info *thr; | |
d634f2de | 9697 | |
018d34a4 | 9698 | tok = end_tok + 1; |
5d5658a1 | 9699 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9700 | if (tok == tmptok) |
9701 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9702 | *thread = thr->global_num; |
bbc13ae3 | 9703 | tok = tmptok; |
018d34a4 | 9704 | } |
4a306c9a JB |
9705 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9706 | { | |
9707 | char *tmptok; | |
9708 | ||
9709 | tok = end_tok + 1; | |
bbc13ae3 | 9710 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9711 | if (tok == tmptok) |
9712 | error (_("Junk after task keyword.")); | |
9713 | if (!valid_task_id (*task)) | |
b6199126 | 9714 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9715 | tok = tmptok; |
4a306c9a | 9716 | } |
e7e0cddf SS |
9717 | else if (rest) |
9718 | { | |
9719 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9720 | return; |
e7e0cddf | 9721 | } |
018d34a4 VP |
9722 | else |
9723 | error (_("Junk at end of arguments.")); | |
9724 | } | |
9725 | } | |
9726 | ||
0fb4aa4b PA |
9727 | /* Decode a static tracepoint marker spec. */ |
9728 | ||
9729 | static struct symtabs_and_lines | |
f00aae0f | 9730 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9731 | { |
9732 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9733 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9734 | struct cleanup *old_chain; |
f00aae0f KS |
9735 | const char *p = &(*arg_p)[3]; |
9736 | const char *endp; | |
0fb4aa4b PA |
9737 | char *marker_str; |
9738 | int i; | |
9739 | ||
f00aae0f | 9740 | p = skip_spaces_const (p); |
0fb4aa4b | 9741 | |
f00aae0f | 9742 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9743 | |
9744 | marker_str = savestring (p, endp - p); | |
9745 | old_chain = make_cleanup (xfree, marker_str); | |
9746 | ||
9747 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9748 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9749 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9750 | ||
9751 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9752 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9753 | |
9754 | for (i = 0; i < sals.nelts; i++) | |
9755 | { | |
9756 | struct static_tracepoint_marker *marker; | |
9757 | ||
9758 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9759 | ||
9760 | init_sal (&sals.sals[i]); | |
9761 | ||
9762 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9763 | sals.sals[i].pc = marker->address; | |
9764 | ||
9765 | release_static_tracepoint_marker (marker); | |
9766 | } | |
9767 | ||
9768 | do_cleanups (old_chain); | |
9769 | ||
9770 | *arg_p = endp; | |
9771 | return sals; | |
9772 | } | |
9773 | ||
f00aae0f | 9774 | /* See breakpoint.h. */ |
0101ce28 | 9775 | |
8cdf0e15 VP |
9776 | int |
9777 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9778 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9779 | int thread, char *extra_string, |
f00aae0f | 9780 | int parse_extra, |
0fb4aa4b | 9781 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9782 | int ignore_count, |
9783 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9784 | const struct breakpoint_ops *ops, |
44f238bb PA |
9785 | int from_tty, int enabled, int internal, |
9786 | unsigned flags) | |
c3f6f71d | 9787 | { |
7efd8fc2 | 9788 | struct linespec_result canonical; |
c3f6f71d | 9789 | struct cleanup *old_chain; |
80c99de1 | 9790 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9791 | int pending = 0; |
4a306c9a | 9792 | int task = 0; |
86b17b60 | 9793 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9794 | |
348d480f PA |
9795 | gdb_assert (ops != NULL); |
9796 | ||
f00aae0f KS |
9797 | /* If extra_string isn't useful, set it to NULL. */ |
9798 | if (extra_string != NULL && *extra_string == '\0') | |
9799 | extra_string = NULL; | |
9800 | ||
7efd8fc2 | 9801 | init_linespec_result (&canonical); |
c3f6f71d | 9802 | |
492d29ea | 9803 | TRY |
b78a6381 | 9804 | { |
f00aae0f | 9805 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9806 | } |
492d29ea | 9807 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9808 | { |
492d29ea PA |
9809 | /* If caller is interested in rc value from parse, set |
9810 | value. */ | |
9811 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9812 | { |
05ff989b AC |
9813 | /* If pending breakpoint support is turned off, throw |
9814 | error. */ | |
fa8d40ab JJ |
9815 | |
9816 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9817 | throw_exception (e); |
9818 | ||
9819 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9820 | |
05ff989b AC |
9821 | /* If pending breakpoint support is auto query and the user |
9822 | selects no, then simply return the error code. */ | |
059fb39f | 9823 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9824 | && !nquery (_("Make %s pending on future shared library load? "), |
9825 | bptype_string (type_wanted))) | |
fd9b8c24 | 9826 | return 0; |
fa8d40ab | 9827 | |
05ff989b AC |
9828 | /* At this point, either the user was queried about setting |
9829 | a pending breakpoint and selected yes, or pending | |
9830 | breakpoint behavior is on and thus a pending breakpoint | |
9831 | is defaulted on behalf of the user. */ | |
f00aae0f | 9832 | pending = 1; |
0101ce28 | 9833 | } |
492d29ea PA |
9834 | else |
9835 | throw_exception (e); | |
0101ce28 | 9836 | } |
492d29ea PA |
9837 | END_CATCH |
9838 | ||
f00aae0f | 9839 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9840 | return 0; |
c3f6f71d | 9841 | |
4a64f543 | 9842 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9843 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9844 | |
c3f6f71d JM |
9845 | /* ----------------------------- SNIP ----------------------------- |
9846 | Anything added to the cleanup chain beyond this point is assumed | |
9847 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9848 | then the memory is not reclaimed. */ |
9849 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9850 | |
c3f6f71d JM |
9851 | /* Resolve all line numbers to PC's and verify that the addresses |
9852 | are ok for the target. */ | |
0101ce28 | 9853 | if (!pending) |
f8eba3c6 TT |
9854 | { |
9855 | int ix; | |
9856 | struct linespec_sals *iter; | |
9857 | ||
9858 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9859 | breakpoint_sals_to_pc (&iter->sals); | |
9860 | } | |
c3f6f71d | 9861 | |
7a697b8d | 9862 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9863 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9864 | { |
9865 | int ix; | |
9866 | struct linespec_sals *iter; | |
9867 | ||
9868 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9869 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9870 | } | |
7a697b8d | 9871 | |
c3f6f71d JM |
9872 | /* Verify that condition can be parsed, before setting any |
9873 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9874 | breakpoint. */ |
0101ce28 | 9875 | if (!pending) |
c3f6f71d | 9876 | { |
f00aae0f | 9877 | if (parse_extra) |
72b2ff0e | 9878 | { |
0878d0fa | 9879 | char *rest; |
52d361e1 YQ |
9880 | struct linespec_sals *lsal; |
9881 | ||
9882 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9883 | ||
0878d0fa YQ |
9884 | /* Here we only parse 'arg' to separate condition |
9885 | from thread number, so parsing in context of first | |
9886 | sal is OK. When setting the breakpoint we'll | |
9887 | re-parse it in context of each sal. */ | |
9888 | ||
f00aae0f KS |
9889 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9890 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9891 | if (cond_string) |
9892 | make_cleanup (xfree, cond_string); | |
9893 | if (rest) | |
9894 | make_cleanup (xfree, rest); | |
9895 | if (rest) | |
9896 | extra_string = rest; | |
f00aae0f KS |
9897 | else |
9898 | extra_string = NULL; | |
72b2ff0e | 9899 | } |
2f069f6f | 9900 | else |
72b2ff0e | 9901 | { |
f00aae0f KS |
9902 | if (type_wanted != bp_dprintf |
9903 | && extra_string != NULL && *extra_string != '\0') | |
9904 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9905 | |
9906 | /* Create a private copy of condition string. */ | |
9907 | if (cond_string) | |
9908 | { | |
9909 | cond_string = xstrdup (cond_string); | |
9910 | make_cleanup (xfree, cond_string); | |
9911 | } | |
9912 | /* Create a private copy of any extra string. */ | |
9913 | if (extra_string) | |
9914 | { | |
9915 | extra_string = xstrdup (extra_string); | |
9916 | make_cleanup (xfree, extra_string); | |
9917 | } | |
72b2ff0e | 9918 | } |
0fb4aa4b | 9919 | |
52d361e1 | 9920 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9921 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9922 | tempflag ? disp_del : disp_donttouch, |
9923 | thread, task, ignore_count, ops, | |
44f238bb | 9924 | from_tty, enabled, internal, flags); |
c906108c | 9925 | } |
0101ce28 JJ |
9926 | else |
9927 | { | |
0101ce28 JJ |
9928 | struct breakpoint *b; |
9929 | ||
bfccc43c YQ |
9930 | if (is_tracepoint_type (type_wanted)) |
9931 | { | |
9932 | struct tracepoint *t; | |
9933 | ||
9934 | t = XCNEW (struct tracepoint); | |
9935 | b = &t->base; | |
9936 | } | |
9937 | else | |
9938 | b = XNEW (struct breakpoint); | |
9939 | ||
9940 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9941 | b->location = copy_event_location (location); |
bfccc43c | 9942 | |
f00aae0f KS |
9943 | if (parse_extra) |
9944 | b->cond_string = NULL; | |
e12c7713 MK |
9945 | else |
9946 | { | |
9947 | /* Create a private copy of condition string. */ | |
9948 | if (cond_string) | |
9949 | { | |
9950 | cond_string = xstrdup (cond_string); | |
9951 | make_cleanup (xfree, cond_string); | |
9952 | } | |
9953 | b->cond_string = cond_string; | |
15630549 | 9954 | b->thread = thread; |
e12c7713 | 9955 | } |
f00aae0f KS |
9956 | |
9957 | /* Create a private copy of any extra string. */ | |
9958 | if (extra_string != NULL) | |
9959 | { | |
9960 | extra_string = xstrdup (extra_string); | |
9961 | make_cleanup (xfree, extra_string); | |
9962 | } | |
9963 | b->extra_string = extra_string; | |
0101ce28 | 9964 | b->ignore_count = ignore_count; |
0101ce28 | 9965 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9966 | b->condition_not_parsed = 1; |
41447f92 | 9967 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9968 | if ((type_wanted != bp_breakpoint |
9969 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9970 | b->pspace = current_program_space; |
8bea4e01 | 9971 | |
bfccc43c | 9972 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9973 | } |
9974 | ||
f8eba3c6 | 9975 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9976 | { |
3e43a32a MS |
9977 | warning (_("Multiple breakpoints were set.\nUse the " |
9978 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9979 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9980 | } |
9981 | ||
80c99de1 PA |
9982 | /* That's it. Discard the cleanups for data inserted into the |
9983 | breakpoint. */ | |
9984 | discard_cleanups (bkpt_chain); | |
9985 | /* But cleanup everything else. */ | |
c3f6f71d | 9986 | do_cleanups (old_chain); |
217dc9e2 | 9987 | |
80c99de1 | 9988 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9989 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9990 | |
9991 | return 1; | |
c3f6f71d | 9992 | } |
c906108c | 9993 | |
348d480f | 9994 | /* Set a breakpoint. |
72b2ff0e VP |
9995 | ARG is a string describing breakpoint address, |
9996 | condition, and thread. | |
9997 | FLAG specifies if a breakpoint is hardware on, | |
9998 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9999 | and BP_TEMPFLAG. */ | |
348d480f | 10000 | |
98deb0da | 10001 | static void |
72b2ff0e | 10002 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10003 | { |
72b2ff0e | 10004 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10005 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10006 | ? bp_hardware_breakpoint | |
10007 | : bp_breakpoint); | |
55aa24fb | 10008 | struct breakpoint_ops *ops; |
f00aae0f KS |
10009 | struct event_location *location; |
10010 | struct cleanup *cleanup; | |
10011 | ||
10012 | location = string_to_event_location (&arg, current_language); | |
10013 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
10014 | |
10015 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
10016 | if (location != NULL |
10017 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
10018 | ops = &bkpt_probe_breakpoint_ops; |
10019 | else | |
10020 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10021 | |
8cdf0e15 | 10022 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10023 | location, |
10024 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10025 | tempflag, type_wanted, |
8cdf0e15 VP |
10026 | 0 /* Ignore count */, |
10027 | pending_break_support, | |
55aa24fb | 10028 | ops, |
8cdf0e15 | 10029 | from_tty, |
84f4c1fe | 10030 | 1 /* enabled */, |
44f238bb PA |
10031 | 0 /* internal */, |
10032 | 0); | |
f00aae0f | 10033 | do_cleanups (cleanup); |
c906108c SS |
10034 | } |
10035 | ||
c906108c SS |
10036 | /* Helper function for break_command_1 and disassemble_command. */ |
10037 | ||
10038 | void | |
fba45db2 | 10039 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10040 | { |
10041 | CORE_ADDR pc; | |
10042 | ||
10043 | if (sal->pc == 0 && sal->symtab != NULL) | |
10044 | { | |
10045 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10046 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10047 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10048 | sal->pc = pc; |
6a048695 | 10049 | |
4a64f543 MS |
10050 | /* If this SAL corresponds to a breakpoint inserted using a line |
10051 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10052 | if (sal->explicit_line) |
059acae7 | 10053 | skip_prologue_sal (sal); |
c906108c SS |
10054 | } |
10055 | ||
10056 | if (sal->section == 0 && sal->symtab != NULL) | |
10057 | { | |
346d1dfe | 10058 | const struct blockvector *bv; |
3977b71f | 10059 | const struct block *b; |
c5aa993b | 10060 | struct symbol *sym; |
c906108c | 10061 | |
43f3e411 DE |
10062 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10063 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10064 | if (bv != NULL) |
10065 | { | |
7f0df278 | 10066 | sym = block_linkage_function (b); |
c906108c SS |
10067 | if (sym != NULL) |
10068 | { | |
eb822aa6 DE |
10069 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10070 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10071 | sym); | |
c906108c SS |
10072 | } |
10073 | else | |
10074 | { | |
4a64f543 MS |
10075 | /* It really is worthwhile to have the section, so we'll |
10076 | just have to look harder. This case can be executed | |
10077 | if we have line numbers but no functions (as can | |
10078 | happen in assembly source). */ | |
c906108c | 10079 | |
7cbd4a93 | 10080 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10081 | struct cleanup *old_chain = save_current_space_and_thread (); |
10082 | ||
10083 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10084 | |
10085 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10086 | if (msym.minsym) |
efd66ac6 | 10087 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10088 | |
10089 | do_cleanups (old_chain); | |
c906108c SS |
10090 | } |
10091 | } | |
10092 | } | |
10093 | } | |
10094 | ||
10095 | void | |
fba45db2 | 10096 | break_command (char *arg, int from_tty) |
c906108c | 10097 | { |
db107f19 | 10098 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10099 | } |
10100 | ||
c906108c | 10101 | void |
fba45db2 | 10102 | tbreak_command (char *arg, int from_tty) |
c906108c | 10103 | { |
db107f19 | 10104 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10105 | } |
10106 | ||
c906108c | 10107 | static void |
fba45db2 | 10108 | hbreak_command (char *arg, int from_tty) |
c906108c | 10109 | { |
db107f19 | 10110 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10111 | } |
10112 | ||
10113 | static void | |
fba45db2 | 10114 | thbreak_command (char *arg, int from_tty) |
c906108c | 10115 | { |
db107f19 | 10116 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10117 | } |
10118 | ||
10119 | static void | |
fba45db2 | 10120 | stop_command (char *arg, int from_tty) |
c906108c | 10121 | { |
a3f17187 | 10122 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10123 | Usage: stop in <function | address>\n\ |
a3f17187 | 10124 | stop at <line>\n")); |
c906108c SS |
10125 | } |
10126 | ||
10127 | static void | |
fba45db2 | 10128 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10129 | { |
10130 | int badInput = 0; | |
10131 | ||
c5aa993b | 10132 | if (arg == (char *) NULL) |
c906108c SS |
10133 | badInput = 1; |
10134 | else if (*arg != '*') | |
10135 | { | |
10136 | char *argptr = arg; | |
10137 | int hasColon = 0; | |
10138 | ||
4a64f543 | 10139 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10140 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10141 | function/method name. */ |
c906108c | 10142 | while (*argptr && !hasColon) |
c5aa993b JM |
10143 | { |
10144 | hasColon = (*argptr == ':'); | |
10145 | argptr++; | |
10146 | } | |
c906108c SS |
10147 | |
10148 | if (hasColon) | |
c5aa993b | 10149 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10150 | else |
c5aa993b | 10151 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10152 | } |
10153 | ||
10154 | if (badInput) | |
a3f17187 | 10155 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10156 | else |
db107f19 | 10157 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10158 | } |
10159 | ||
10160 | static void | |
fba45db2 | 10161 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10162 | { |
10163 | int badInput = 0; | |
10164 | ||
c5aa993b | 10165 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10166 | badInput = 1; |
10167 | else | |
10168 | { | |
10169 | char *argptr = arg; | |
10170 | int hasColon = 0; | |
10171 | ||
4a64f543 MS |
10172 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10173 | it is probably a line number. */ | |
c906108c | 10174 | while (*argptr && !hasColon) |
c5aa993b JM |
10175 | { |
10176 | hasColon = (*argptr == ':'); | |
10177 | argptr++; | |
10178 | } | |
c906108c SS |
10179 | |
10180 | if (hasColon) | |
c5aa993b | 10181 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10182 | else |
c5aa993b | 10183 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10184 | } |
10185 | ||
10186 | if (badInput) | |
a3f17187 | 10187 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10188 | else |
db107f19 | 10189 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10190 | } |
10191 | ||
e7e0cddf SS |
10192 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10193 | with a prewired command list consisting of a single output command, | |
10194 | built from extra arguments supplied on the dprintf command | |
10195 | line. */ | |
10196 | ||
da821c7b | 10197 | static void |
e7e0cddf SS |
10198 | dprintf_command (char *arg, int from_tty) |
10199 | { | |
f00aae0f KS |
10200 | struct event_location *location; |
10201 | struct cleanup *cleanup; | |
10202 | ||
10203 | location = string_to_event_location (&arg, current_language); | |
10204 | cleanup = make_cleanup_delete_event_location (location); | |
10205 | ||
10206 | /* If non-NULL, ARG should have been advanced past the location; | |
10207 | the next character must be ','. */ | |
10208 | if (arg != NULL) | |
10209 | { | |
10210 | if (arg[0] != ',' || arg[1] == '\0') | |
10211 | error (_("Format string required")); | |
10212 | else | |
10213 | { | |
10214 | /* Skip the comma. */ | |
10215 | ++arg; | |
10216 | } | |
10217 | } | |
10218 | ||
e7e0cddf | 10219 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10220 | location, |
10221 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10222 | 0, bp_dprintf, |
10223 | 0 /* Ignore count */, | |
10224 | pending_break_support, | |
10225 | &dprintf_breakpoint_ops, | |
10226 | from_tty, | |
10227 | 1 /* enabled */, | |
10228 | 0 /* internal */, | |
10229 | 0); | |
f00aae0f | 10230 | do_cleanups (cleanup); |
e7e0cddf SS |
10231 | } |
10232 | ||
d3ce09f5 SS |
10233 | static void |
10234 | agent_printf_command (char *arg, int from_tty) | |
10235 | { | |
10236 | error (_("May only run agent-printf on the target")); | |
10237 | } | |
10238 | ||
f1310107 TJB |
10239 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10240 | ranged breakpoints. */ | |
10241 | ||
10242 | static int | |
10243 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10244 | struct address_space *aspace, | |
09ac7c10 TT |
10245 | CORE_ADDR bp_addr, |
10246 | const struct target_waitstatus *ws) | |
f1310107 | 10247 | { |
09ac7c10 | 10248 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10249 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10250 | return 0; |
10251 | ||
f1310107 TJB |
10252 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10253 | bl->length, aspace, bp_addr); | |
10254 | } | |
10255 | ||
10256 | /* Implement the "resources_needed" breakpoint_ops method for | |
10257 | ranged breakpoints. */ | |
10258 | ||
10259 | static int | |
10260 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10261 | { | |
10262 | return target_ranged_break_num_registers (); | |
10263 | } | |
10264 | ||
10265 | /* Implement the "print_it" breakpoint_ops method for | |
10266 | ranged breakpoints. */ | |
10267 | ||
10268 | static enum print_stop_action | |
348d480f | 10269 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10270 | { |
348d480f | 10271 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10272 | struct bp_location *bl = b->loc; |
79a45e25 | 10273 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10274 | |
10275 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10276 | ||
10277 | /* Ranged breakpoints have only one location. */ | |
10278 | gdb_assert (bl && bl->next == NULL); | |
10279 | ||
10280 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10281 | |
10282 | maybe_print_thread_hit_breakpoint (uiout); | |
10283 | ||
f1310107 | 10284 | if (b->disposition == disp_del) |
f303dbd6 | 10285 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10286 | else |
f303dbd6 | 10287 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10288 | if (ui_out_is_mi_like_p (uiout)) |
10289 | { | |
10290 | ui_out_field_string (uiout, "reason", | |
10291 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10292 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10293 | } | |
10294 | ui_out_field_int (uiout, "bkptno", b->number); | |
10295 | ui_out_text (uiout, ", "); | |
10296 | ||
10297 | return PRINT_SRC_AND_LOC; | |
10298 | } | |
10299 | ||
10300 | /* Implement the "print_one" breakpoint_ops method for | |
10301 | ranged breakpoints. */ | |
10302 | ||
10303 | static void | |
10304 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10305 | struct bp_location **last_loc) | |
10306 | { | |
10307 | struct bp_location *bl = b->loc; | |
10308 | struct value_print_options opts; | |
79a45e25 | 10309 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10310 | |
10311 | /* Ranged breakpoints have only one location. */ | |
10312 | gdb_assert (bl && bl->next == NULL); | |
10313 | ||
10314 | get_user_print_options (&opts); | |
10315 | ||
10316 | if (opts.addressprint) | |
10317 | /* We don't print the address range here, it will be printed later | |
10318 | by print_one_detail_ranged_breakpoint. */ | |
10319 | ui_out_field_skip (uiout, "addr"); | |
10320 | annotate_field (5); | |
10321 | print_breakpoint_location (b, bl); | |
10322 | *last_loc = bl; | |
10323 | } | |
10324 | ||
10325 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10326 | ranged breakpoints. */ | |
10327 | ||
10328 | static void | |
10329 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10330 | struct ui_out *uiout) | |
10331 | { | |
10332 | CORE_ADDR address_start, address_end; | |
10333 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10334 | struct ui_file *stb = mem_fileopen (); |
10335 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10336 | |
10337 | gdb_assert (bl); | |
10338 | ||
10339 | address_start = bl->address; | |
10340 | address_end = address_start + bl->length - 1; | |
10341 | ||
10342 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10343 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10344 | print_core_address (bl->gdbarch, address_start), |
10345 | print_core_address (bl->gdbarch, address_end)); | |
10346 | ui_out_field_stream (uiout, "addr", stb); | |
10347 | ui_out_text (uiout, "\n"); | |
10348 | ||
10349 | do_cleanups (cleanup); | |
10350 | } | |
10351 | ||
10352 | /* Implement the "print_mention" breakpoint_ops method for | |
10353 | ranged breakpoints. */ | |
10354 | ||
10355 | static void | |
10356 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10357 | { | |
10358 | struct bp_location *bl = b->loc; | |
79a45e25 | 10359 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10360 | |
10361 | gdb_assert (bl); | |
10362 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10363 | ||
10364 | if (ui_out_is_mi_like_p (uiout)) | |
10365 | return; | |
10366 | ||
10367 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10368 | b->number, paddress (bl->gdbarch, bl->address), | |
10369 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10370 | } | |
10371 | ||
10372 | /* Implement the "print_recreate" breakpoint_ops method for | |
10373 | ranged breakpoints. */ | |
10374 | ||
10375 | static void | |
10376 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10377 | { | |
f00aae0f KS |
10378 | fprintf_unfiltered (fp, "break-range %s, %s", |
10379 | event_location_to_string (b->location), | |
10380 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10381 | print_recreate_thread (b, fp); |
f1310107 TJB |
10382 | } |
10383 | ||
10384 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10385 | ||
2060206e | 10386 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10387 | |
10388 | /* Find the address where the end of the breakpoint range should be | |
10389 | placed, given the SAL of the end of the range. This is so that if | |
10390 | the user provides a line number, the end of the range is set to the | |
10391 | last instruction of the given line. */ | |
10392 | ||
10393 | static CORE_ADDR | |
10394 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10395 | { | |
10396 | CORE_ADDR end; | |
10397 | ||
10398 | /* If the user provided a PC value, use it. Otherwise, | |
10399 | find the address of the end of the given location. */ | |
10400 | if (sal.explicit_pc) | |
10401 | end = sal.pc; | |
10402 | else | |
10403 | { | |
10404 | int ret; | |
10405 | CORE_ADDR start; | |
10406 | ||
10407 | ret = find_line_pc_range (sal, &start, &end); | |
10408 | if (!ret) | |
10409 | error (_("Could not find location of the end of the range.")); | |
10410 | ||
10411 | /* find_line_pc_range returns the start of the next line. */ | |
10412 | end--; | |
10413 | } | |
10414 | ||
10415 | return end; | |
10416 | } | |
10417 | ||
10418 | /* Implement the "break-range" CLI command. */ | |
10419 | ||
10420 | static void | |
10421 | break_range_command (char *arg, int from_tty) | |
10422 | { | |
870f88f7 | 10423 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10424 | struct linespec_result canonical_start, canonical_end; |
10425 | int bp_count, can_use_bp, length; | |
10426 | CORE_ADDR end; | |
10427 | struct breakpoint *b; | |
10428 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10429 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10430 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10431 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10432 | |
10433 | /* We don't support software ranged breakpoints. */ | |
10434 | if (target_ranged_break_num_registers () < 0) | |
10435 | error (_("This target does not support hardware ranged breakpoints.")); | |
10436 | ||
10437 | bp_count = hw_breakpoint_used_count (); | |
10438 | bp_count += target_ranged_break_num_registers (); | |
10439 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10440 | bp_count, 0); | |
10441 | if (can_use_bp < 0) | |
10442 | error (_("Hardware breakpoints used exceeds limit.")); | |
10443 | ||
f8eba3c6 | 10444 | arg = skip_spaces (arg); |
f1310107 TJB |
10445 | if (arg == NULL || arg[0] == '\0') |
10446 | error(_("No address range specified.")); | |
10447 | ||
f1310107 TJB |
10448 | init_linespec_result (&canonical_start); |
10449 | ||
f8eba3c6 | 10450 | arg_start = arg; |
f00aae0f KS |
10451 | start_location = string_to_event_location (&arg, current_language); |
10452 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10453 | parse_breakpoint_sals (start_location, &canonical_start); | |
10454 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10455 | |
10456 | if (arg[0] != ',') | |
10457 | error (_("Too few arguments.")); | |
f8eba3c6 | 10458 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10459 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10460 | |
10461 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10462 | ||
10463 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10464 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10465 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10466 | ||
f8eba3c6 TT |
10467 | sal_start = lsal_start->sals.sals[0]; |
10468 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10469 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10470 | |
10471 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10472 | arg = skip_spaces (arg); |
f1310107 TJB |
10473 | |
10474 | /* Parse the end location. */ | |
10475 | ||
f1310107 TJB |
10476 | init_linespec_result (&canonical_end); |
10477 | arg_start = arg; | |
10478 | ||
f8eba3c6 | 10479 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10480 | parse_breakpoint_sals because we need to specify the start location's |
10481 | symtab and line as the default symtab and line for the end of the | |
10482 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10483 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10484 | end_location = string_to_event_location (&arg, current_language); |
10485 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10486 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10487 | sal_start.symtab, sal_start.line, |
10488 | &canonical_end, NULL, NULL); | |
10489 | ||
10490 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10491 | |
f8eba3c6 | 10492 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10493 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10494 | |
10495 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10496 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10497 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10498 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10499 | ||
f8eba3c6 | 10500 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10501 | |
10502 | end = find_breakpoint_range_end (sal_end); | |
10503 | if (sal_start.pc > end) | |
177b42fe | 10504 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10505 | |
10506 | length = end - sal_start.pc + 1; | |
10507 | if (length < 0) | |
10508 | /* Length overflowed. */ | |
10509 | error (_("Address range too large.")); | |
10510 | else if (length == 1) | |
10511 | { | |
10512 | /* This range is simple enough to be handled by | |
10513 | the `hbreak' command. */ | |
10514 | hbreak_command (addr_string_start, 1); | |
10515 | ||
10516 | do_cleanups (cleanup_bkpt); | |
10517 | ||
10518 | return; | |
10519 | } | |
10520 | ||
10521 | /* Now set up the breakpoint. */ | |
10522 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10523 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10524 | set_breakpoint_count (breakpoint_count + 1); |
10525 | b->number = breakpoint_count; | |
10526 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10527 | b->location = copy_event_location (start_location); |
10528 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10529 | b->loc->length = length; |
10530 | ||
f8eba3c6 | 10531 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10532 | |
10533 | mention (b); | |
8d3788bd | 10534 | observer_notify_breakpoint_created (b); |
44702360 | 10535 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10536 | } |
10537 | ||
4a64f543 MS |
10538 | /* Return non-zero if EXP is verified as constant. Returned zero |
10539 | means EXP is variable. Also the constant detection may fail for | |
10540 | some constant expressions and in such case still falsely return | |
10541 | zero. */ | |
2e6e3d9c | 10542 | |
65d79d4b SDJ |
10543 | static int |
10544 | watchpoint_exp_is_const (const struct expression *exp) | |
10545 | { | |
10546 | int i = exp->nelts; | |
10547 | ||
10548 | while (i > 0) | |
10549 | { | |
10550 | int oplenp, argsp; | |
10551 | ||
10552 | /* We are only interested in the descriptor of each element. */ | |
10553 | operator_length (exp, i, &oplenp, &argsp); | |
10554 | i -= oplenp; | |
10555 | ||
10556 | switch (exp->elts[i].opcode) | |
10557 | { | |
10558 | case BINOP_ADD: | |
10559 | case BINOP_SUB: | |
10560 | case BINOP_MUL: | |
10561 | case BINOP_DIV: | |
10562 | case BINOP_REM: | |
10563 | case BINOP_MOD: | |
10564 | case BINOP_LSH: | |
10565 | case BINOP_RSH: | |
10566 | case BINOP_LOGICAL_AND: | |
10567 | case BINOP_LOGICAL_OR: | |
10568 | case BINOP_BITWISE_AND: | |
10569 | case BINOP_BITWISE_IOR: | |
10570 | case BINOP_BITWISE_XOR: | |
10571 | case BINOP_EQUAL: | |
10572 | case BINOP_NOTEQUAL: | |
10573 | case BINOP_LESS: | |
10574 | case BINOP_GTR: | |
10575 | case BINOP_LEQ: | |
10576 | case BINOP_GEQ: | |
10577 | case BINOP_REPEAT: | |
10578 | case BINOP_COMMA: | |
10579 | case BINOP_EXP: | |
10580 | case BINOP_MIN: | |
10581 | case BINOP_MAX: | |
10582 | case BINOP_INTDIV: | |
10583 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10584 | case TERNOP_COND: |
10585 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10586 | |
10587 | case OP_LONG: | |
10588 | case OP_DOUBLE: | |
10589 | case OP_DECFLOAT: | |
10590 | case OP_LAST: | |
10591 | case OP_COMPLEX: | |
10592 | case OP_STRING: | |
65d79d4b SDJ |
10593 | case OP_ARRAY: |
10594 | case OP_TYPE: | |
608b4967 TT |
10595 | case OP_TYPEOF: |
10596 | case OP_DECLTYPE: | |
6e72ca20 | 10597 | case OP_TYPEID: |
65d79d4b SDJ |
10598 | case OP_NAME: |
10599 | case OP_OBJC_NSSTRING: | |
10600 | ||
10601 | case UNOP_NEG: | |
10602 | case UNOP_LOGICAL_NOT: | |
10603 | case UNOP_COMPLEMENT: | |
10604 | case UNOP_ADDR: | |
10605 | case UNOP_HIGH: | |
aeaa2474 | 10606 | case UNOP_CAST: |
9eaf6705 TT |
10607 | |
10608 | case UNOP_CAST_TYPE: | |
10609 | case UNOP_REINTERPRET_CAST: | |
10610 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10611 | /* Unary, binary and ternary operators: We have to check |
10612 | their operands. If they are constant, then so is the | |
10613 | result of that operation. For instance, if A and B are | |
10614 | determined to be constants, then so is "A + B". | |
10615 | ||
10616 | UNOP_IND is one exception to the rule above, because the | |
10617 | value of *ADDR is not necessarily a constant, even when | |
10618 | ADDR is. */ | |
65d79d4b SDJ |
10619 | break; |
10620 | ||
10621 | case OP_VAR_VALUE: | |
10622 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10623 | |
65d79d4b | 10624 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10625 | possible that a buggy compiler could mark a variable as |
10626 | constant even when it is not, and TYPE_CONST would return | |
10627 | true in this case, while SYMBOL_CLASS wouldn't. | |
10628 | ||
10629 | We also have to check for function symbols because they | |
10630 | are always constant. */ | |
65d79d4b SDJ |
10631 | { |
10632 | struct symbol *s = exp->elts[i + 2].symbol; | |
10633 | ||
10634 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10635 | && SYMBOL_CLASS (s) != LOC_CONST | |
10636 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10637 | return 0; | |
10638 | break; | |
10639 | } | |
10640 | ||
10641 | /* The default action is to return 0 because we are using | |
10642 | the optimistic approach here: If we don't know something, | |
10643 | then it is not a constant. */ | |
10644 | default: | |
10645 | return 0; | |
10646 | } | |
10647 | } | |
10648 | ||
10649 | return 1; | |
10650 | } | |
10651 | ||
3a5c3e22 PA |
10652 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10653 | ||
10654 | static void | |
10655 | dtor_watchpoint (struct breakpoint *self) | |
10656 | { | |
10657 | struct watchpoint *w = (struct watchpoint *) self; | |
10658 | ||
10659 | xfree (w->cond_exp); | |
10660 | xfree (w->exp); | |
10661 | xfree (w->exp_string); | |
10662 | xfree (w->exp_string_reparse); | |
10663 | value_free (w->val); | |
10664 | ||
10665 | base_breakpoint_ops.dtor (self); | |
10666 | } | |
10667 | ||
348d480f PA |
10668 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10669 | ||
10670 | static void | |
10671 | re_set_watchpoint (struct breakpoint *b) | |
10672 | { | |
3a5c3e22 PA |
10673 | struct watchpoint *w = (struct watchpoint *) b; |
10674 | ||
348d480f PA |
10675 | /* Watchpoint can be either on expression using entirely global |
10676 | variables, or it can be on local variables. | |
10677 | ||
10678 | Watchpoints of the first kind are never auto-deleted, and even | |
10679 | persist across program restarts. Since they can use variables | |
10680 | from shared libraries, we need to reparse expression as libraries | |
10681 | are loaded and unloaded. | |
10682 | ||
10683 | Watchpoints on local variables can also change meaning as result | |
10684 | of solib event. For example, if a watchpoint uses both a local | |
10685 | and a global variables in expression, it's a local watchpoint, | |
10686 | but unloading of a shared library will make the expression | |
10687 | invalid. This is not a very common use case, but we still | |
10688 | re-evaluate expression, to avoid surprises to the user. | |
10689 | ||
10690 | Note that for local watchpoints, we re-evaluate it only if | |
10691 | watchpoints frame id is still valid. If it's not, it means the | |
10692 | watchpoint is out of scope and will be deleted soon. In fact, | |
10693 | I'm not sure we'll ever be called in this case. | |
10694 | ||
10695 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10696 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10697 | |
3a5c3e22 PA |
10698 | Don't do anything about disabled watchpoints, since they will be |
10699 | reevaluated again when enabled. */ | |
10700 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10701 | } |
10702 | ||
77b06cd7 TJB |
10703 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10704 | ||
10705 | static int | |
10706 | insert_watchpoint (struct bp_location *bl) | |
10707 | { | |
3a5c3e22 PA |
10708 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10709 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10710 | |
10711 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10712 | w->cond_exp); |
77b06cd7 TJB |
10713 | } |
10714 | ||
10715 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10716 | ||
10717 | static int | |
10718 | remove_watchpoint (struct bp_location *bl) | |
10719 | { | |
3a5c3e22 PA |
10720 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10721 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10722 | |
10723 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10724 | w->cond_exp); |
e09342b5 TJB |
10725 | } |
10726 | ||
e09342b5 | 10727 | static int |
348d480f | 10728 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10729 | struct address_space *aspace, CORE_ADDR bp_addr, |
10730 | const struct target_waitstatus *ws) | |
e09342b5 | 10731 | { |
348d480f | 10732 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10733 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10734 | |
348d480f PA |
10735 | /* Continuable hardware watchpoints are treated as non-existent if the |
10736 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10737 | some data address). Otherwise gdb won't stop on a break instruction | |
10738 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10739 | been defined. Also skip watchpoints which we know did not trigger | |
10740 | (did not match the data address). */ | |
10741 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10742 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10743 | return 0; |
9c06b0b4 | 10744 | |
348d480f | 10745 | return 1; |
9c06b0b4 TJB |
10746 | } |
10747 | ||
348d480f PA |
10748 | static void |
10749 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10750 | { |
348d480f | 10751 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10752 | |
348d480f | 10753 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10754 | } |
10755 | ||
10756 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10757 | hardware watchpoints. */ |
9c06b0b4 TJB |
10758 | |
10759 | static int | |
348d480f | 10760 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10761 | { |
3a5c3e22 PA |
10762 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10763 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10764 | |
10765 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10766 | } |
10767 | ||
10768 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10769 | hardware watchpoints. */ |
9c06b0b4 TJB |
10770 | |
10771 | static int | |
348d480f | 10772 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10773 | { |
efa80663 PA |
10774 | /* Read and access watchpoints only work with hardware support. */ |
10775 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10776 | } |
10777 | ||
9c06b0b4 | 10778 | static enum print_stop_action |
348d480f | 10779 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10780 | { |
348d480f PA |
10781 | struct cleanup *old_chain; |
10782 | struct breakpoint *b; | |
f99d8bf4 | 10783 | struct ui_file *stb; |
348d480f | 10784 | enum print_stop_action result; |
3a5c3e22 | 10785 | struct watchpoint *w; |
79a45e25 | 10786 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10787 | |
10788 | gdb_assert (bs->bp_location_at != NULL); | |
10789 | ||
348d480f | 10790 | b = bs->breakpoint_at; |
3a5c3e22 | 10791 | w = (struct watchpoint *) b; |
348d480f | 10792 | |
f99d8bf4 PA |
10793 | stb = mem_fileopen (); |
10794 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10795 | |
f303dbd6 PA |
10796 | annotate_watchpoint (b->number); |
10797 | maybe_print_thread_hit_breakpoint (uiout); | |
10798 | ||
9c06b0b4 TJB |
10799 | switch (b->type) |
10800 | { | |
348d480f | 10801 | case bp_watchpoint: |
9c06b0b4 | 10802 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10803 | if (ui_out_is_mi_like_p (uiout)) |
10804 | ui_out_field_string | |
10805 | (uiout, "reason", | |
10806 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10807 | mention (b); |
10808 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10809 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10810 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10811 | ui_out_field_stream (uiout, "old", stb); |
10812 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10813 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10814 | ui_out_field_stream (uiout, "new", stb); |
10815 | ui_out_text (uiout, "\n"); | |
10816 | /* More than one watchpoint may have been triggered. */ | |
10817 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10818 | break; |
10819 | ||
10820 | case bp_read_watchpoint: | |
10821 | if (ui_out_is_mi_like_p (uiout)) | |
10822 | ui_out_field_string | |
10823 | (uiout, "reason", | |
10824 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10825 | mention (b); |
10826 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10827 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10828 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10829 | ui_out_field_stream (uiout, "value", stb); |
10830 | ui_out_text (uiout, "\n"); | |
10831 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10832 | break; |
10833 | ||
10834 | case bp_access_watchpoint: | |
348d480f PA |
10835 | if (bs->old_val != NULL) |
10836 | { | |
348d480f PA |
10837 | if (ui_out_is_mi_like_p (uiout)) |
10838 | ui_out_field_string | |
10839 | (uiout, "reason", | |
10840 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10841 | mention (b); | |
10842 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10843 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10844 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10845 | ui_out_field_stream (uiout, "old", stb); |
10846 | ui_out_text (uiout, "\nNew value = "); | |
10847 | } | |
10848 | else | |
10849 | { | |
10850 | mention (b); | |
10851 | if (ui_out_is_mi_like_p (uiout)) | |
10852 | ui_out_field_string | |
10853 | (uiout, "reason", | |
10854 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10855 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10856 | ui_out_text (uiout, "\nValue = "); | |
10857 | } | |
f99d8bf4 | 10858 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10859 | ui_out_field_stream (uiout, "new", stb); |
10860 | ui_out_text (uiout, "\n"); | |
10861 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10862 | break; |
10863 | default: | |
348d480f | 10864 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10865 | } |
10866 | ||
348d480f PA |
10867 | do_cleanups (old_chain); |
10868 | return result; | |
10869 | } | |
10870 | ||
10871 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10872 | watchpoints. */ | |
10873 | ||
10874 | static void | |
10875 | print_mention_watchpoint (struct breakpoint *b) | |
10876 | { | |
10877 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10878 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10879 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10880 | |
10881 | switch (b->type) | |
10882 | { | |
10883 | case bp_watchpoint: | |
10884 | ui_out_text (uiout, "Watchpoint "); | |
10885 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10886 | break; | |
10887 | case bp_hardware_watchpoint: | |
10888 | ui_out_text (uiout, "Hardware watchpoint "); | |
10889 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10890 | break; | |
10891 | case bp_read_watchpoint: | |
10892 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10893 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10894 | break; | |
10895 | case bp_access_watchpoint: | |
10896 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10897 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10898 | break; | |
10899 | default: | |
10900 | internal_error (__FILE__, __LINE__, | |
10901 | _("Invalid hardware watchpoint type.")); | |
10902 | } | |
10903 | ||
10904 | ui_out_field_int (uiout, "number", b->number); | |
10905 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10906 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10907 | do_cleanups (ui_out_chain); |
10908 | } | |
10909 | ||
10910 | /* Implement the "print_recreate" breakpoint_ops method for | |
10911 | watchpoints. */ | |
10912 | ||
10913 | static void | |
10914 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10915 | { | |
3a5c3e22 PA |
10916 | struct watchpoint *w = (struct watchpoint *) b; |
10917 | ||
348d480f PA |
10918 | switch (b->type) |
10919 | { | |
10920 | case bp_watchpoint: | |
10921 | case bp_hardware_watchpoint: | |
10922 | fprintf_unfiltered (fp, "watch"); | |
10923 | break; | |
10924 | case bp_read_watchpoint: | |
10925 | fprintf_unfiltered (fp, "rwatch"); | |
10926 | break; | |
10927 | case bp_access_watchpoint: | |
10928 | fprintf_unfiltered (fp, "awatch"); | |
10929 | break; | |
10930 | default: | |
10931 | internal_error (__FILE__, __LINE__, | |
10932 | _("Invalid watchpoint type.")); | |
10933 | } | |
10934 | ||
3a5c3e22 | 10935 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10936 | print_recreate_thread (b, fp); |
348d480f PA |
10937 | } |
10938 | ||
427cd150 TT |
10939 | /* Implement the "explains_signal" breakpoint_ops method for |
10940 | watchpoints. */ | |
10941 | ||
47591c29 | 10942 | static int |
427cd150 TT |
10943 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10944 | { | |
10945 | /* A software watchpoint cannot cause a signal other than | |
10946 | GDB_SIGNAL_TRAP. */ | |
10947 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10948 | return 0; |
427cd150 | 10949 | |
47591c29 | 10950 | return 1; |
427cd150 TT |
10951 | } |
10952 | ||
348d480f PA |
10953 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10954 | ||
2060206e | 10955 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10956 | |
10957 | /* Implement the "insert" breakpoint_ops method for | |
10958 | masked hardware watchpoints. */ | |
10959 | ||
10960 | static int | |
10961 | insert_masked_watchpoint (struct bp_location *bl) | |
10962 | { | |
3a5c3e22 PA |
10963 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10964 | ||
10965 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10966 | bl->watchpoint_type); |
10967 | } | |
10968 | ||
10969 | /* Implement the "remove" breakpoint_ops method for | |
10970 | masked hardware watchpoints. */ | |
10971 | ||
10972 | static int | |
10973 | remove_masked_watchpoint (struct bp_location *bl) | |
10974 | { | |
3a5c3e22 PA |
10975 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10976 | ||
10977 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10978 | bl->watchpoint_type); |
10979 | } | |
10980 | ||
10981 | /* Implement the "resources_needed" breakpoint_ops method for | |
10982 | masked hardware watchpoints. */ | |
10983 | ||
10984 | static int | |
10985 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10986 | { | |
3a5c3e22 PA |
10987 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10988 | ||
10989 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10990 | } |
10991 | ||
10992 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10993 | masked hardware watchpoints. */ | |
10994 | ||
10995 | static int | |
10996 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10997 | { | |
10998 | return 0; | |
10999 | } | |
11000 | ||
11001 | /* Implement the "print_it" breakpoint_ops method for | |
11002 | masked hardware watchpoints. */ | |
11003 | ||
11004 | static enum print_stop_action | |
11005 | print_it_masked_watchpoint (bpstat bs) | |
11006 | { | |
11007 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11008 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11009 | |
11010 | /* Masked watchpoints have only one location. */ | |
11011 | gdb_assert (b->loc && b->loc->next == NULL); | |
11012 | ||
f303dbd6 PA |
11013 | annotate_watchpoint (b->number); |
11014 | maybe_print_thread_hit_breakpoint (uiout); | |
11015 | ||
348d480f PA |
11016 | switch (b->type) |
11017 | { | |
11018 | case bp_hardware_watchpoint: | |
348d480f PA |
11019 | if (ui_out_is_mi_like_p (uiout)) |
11020 | ui_out_field_string | |
11021 | (uiout, "reason", | |
11022 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11023 | break; | |
11024 | ||
11025 | case bp_read_watchpoint: | |
11026 | if (ui_out_is_mi_like_p (uiout)) | |
11027 | ui_out_field_string | |
11028 | (uiout, "reason", | |
11029 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11030 | break; | |
11031 | ||
11032 | case bp_access_watchpoint: | |
11033 | if (ui_out_is_mi_like_p (uiout)) | |
11034 | ui_out_field_string | |
11035 | (uiout, "reason", | |
11036 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11037 | break; | |
11038 | default: | |
11039 | internal_error (__FILE__, __LINE__, | |
11040 | _("Invalid hardware watchpoint type.")); | |
11041 | } | |
11042 | ||
11043 | mention (b); | |
9c06b0b4 TJB |
11044 | ui_out_text (uiout, _("\n\ |
11045 | Check the underlying instruction at PC for the memory\n\ | |
11046 | address and value which triggered this watchpoint.\n")); | |
11047 | ui_out_text (uiout, "\n"); | |
11048 | ||
11049 | /* More than one watchpoint may have been triggered. */ | |
11050 | return PRINT_UNKNOWN; | |
11051 | } | |
11052 | ||
11053 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11054 | masked hardware watchpoints. */ | |
11055 | ||
11056 | static void | |
11057 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11058 | struct ui_out *uiout) | |
11059 | { | |
3a5c3e22 PA |
11060 | struct watchpoint *w = (struct watchpoint *) b; |
11061 | ||
9c06b0b4 TJB |
11062 | /* Masked watchpoints have only one location. */ |
11063 | gdb_assert (b->loc && b->loc->next == NULL); | |
11064 | ||
11065 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11066 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11067 | ui_out_text (uiout, "\n"); |
11068 | } | |
11069 | ||
11070 | /* Implement the "print_mention" breakpoint_ops method for | |
11071 | masked hardware watchpoints. */ | |
11072 | ||
11073 | static void | |
11074 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11075 | { | |
3a5c3e22 | 11076 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11077 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11078 | struct cleanup *ui_out_chain; |
11079 | ||
11080 | switch (b->type) | |
11081 | { | |
11082 | case bp_hardware_watchpoint: | |
11083 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11084 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11085 | break; | |
11086 | case bp_read_watchpoint: | |
11087 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11088 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11089 | break; | |
11090 | case bp_access_watchpoint: | |
11091 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11092 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11093 | break; | |
11094 | default: | |
11095 | internal_error (__FILE__, __LINE__, | |
11096 | _("Invalid hardware watchpoint type.")); | |
11097 | } | |
11098 | ||
11099 | ui_out_field_int (uiout, "number", b->number); | |
11100 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11101 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11102 | do_cleanups (ui_out_chain); |
11103 | } | |
11104 | ||
11105 | /* Implement the "print_recreate" breakpoint_ops method for | |
11106 | masked hardware watchpoints. */ | |
11107 | ||
11108 | static void | |
11109 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11110 | { | |
3a5c3e22 | 11111 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11112 | char tmp[40]; |
11113 | ||
11114 | switch (b->type) | |
11115 | { | |
11116 | case bp_hardware_watchpoint: | |
11117 | fprintf_unfiltered (fp, "watch"); | |
11118 | break; | |
11119 | case bp_read_watchpoint: | |
11120 | fprintf_unfiltered (fp, "rwatch"); | |
11121 | break; | |
11122 | case bp_access_watchpoint: | |
11123 | fprintf_unfiltered (fp, "awatch"); | |
11124 | break; | |
11125 | default: | |
11126 | internal_error (__FILE__, __LINE__, | |
11127 | _("Invalid hardware watchpoint type.")); | |
11128 | } | |
11129 | ||
3a5c3e22 PA |
11130 | sprintf_vma (tmp, w->hw_wp_mask); |
11131 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11132 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11133 | } |
11134 | ||
11135 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11136 | ||
2060206e | 11137 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11138 | |
11139 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11140 | ||
11141 | static int | |
11142 | is_masked_watchpoint (const struct breakpoint *b) | |
11143 | { | |
11144 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11145 | } | |
11146 | ||
53a5351d JM |
11147 | /* accessflag: hw_write: watch write, |
11148 | hw_read: watch read, | |
11149 | hw_access: watch access (read or write) */ | |
c906108c | 11150 | static void |
bbc13ae3 | 11151 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11152 | int just_location, int internal) |
c906108c | 11153 | { |
d983da9c | 11154 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11155 | struct expression *exp; |
270140bd | 11156 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11157 | struct value *val, *mark, *result; |
bb9d5f81 | 11158 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11159 | struct frame_info *frame; |
bbc13ae3 KS |
11160 | const char *exp_start = NULL; |
11161 | const char *exp_end = NULL; | |
11162 | const char *tok, *end_tok; | |
9c06b0b4 | 11163 | int toklen = -1; |
bbc13ae3 KS |
11164 | const char *cond_start = NULL; |
11165 | const char *cond_end = NULL; | |
c906108c | 11166 | enum bptype bp_type; |
37e4754d | 11167 | int thread = -1; |
0cf6dd15 | 11168 | int pc = 0; |
9c06b0b4 TJB |
11169 | /* Flag to indicate whether we are going to use masks for |
11170 | the hardware watchpoint. */ | |
11171 | int use_mask = 0; | |
11172 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11173 | struct watchpoint *w; |
bbc13ae3 KS |
11174 | char *expression; |
11175 | struct cleanup *back_to; | |
c906108c | 11176 | |
37e4754d LM |
11177 | /* Make sure that we actually have parameters to parse. */ |
11178 | if (arg != NULL && arg[0] != '\0') | |
11179 | { | |
bbc13ae3 KS |
11180 | const char *value_start; |
11181 | ||
11182 | exp_end = arg + strlen (arg); | |
37e4754d | 11183 | |
9c06b0b4 TJB |
11184 | /* Look for "parameter value" pairs at the end |
11185 | of the arguments string. */ | |
bbc13ae3 | 11186 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11187 | { |
11188 | /* Skip whitespace at the end of the argument list. */ | |
11189 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11190 | tok--; | |
11191 | ||
11192 | /* Find the beginning of the last token. | |
11193 | This is the value of the parameter. */ | |
11194 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11195 | tok--; | |
11196 | value_start = tok + 1; | |
11197 | ||
11198 | /* Skip whitespace. */ | |
11199 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11200 | tok--; | |
11201 | ||
11202 | end_tok = tok; | |
11203 | ||
11204 | /* Find the beginning of the second to last token. | |
11205 | This is the parameter itself. */ | |
11206 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11207 | tok--; | |
11208 | tok++; | |
11209 | toklen = end_tok - tok + 1; | |
11210 | ||
61012eef | 11211 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11212 | { |
5d5658a1 | 11213 | struct thread_info *thr; |
9c06b0b4 TJB |
11214 | /* At this point we've found a "thread" token, which means |
11215 | the user is trying to set a watchpoint that triggers | |
11216 | only in a specific thread. */ | |
5d5658a1 | 11217 | const char *endp; |
37e4754d | 11218 | |
9c06b0b4 TJB |
11219 | if (thread != -1) |
11220 | error(_("You can specify only one thread.")); | |
37e4754d | 11221 | |
9c06b0b4 | 11222 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11223 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11224 | |
5d5658a1 | 11225 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11226 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11227 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11228 | |
5d5658a1 | 11229 | thread = thr->global_num; |
9c06b0b4 | 11230 | } |
61012eef | 11231 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11232 | { |
11233 | /* We've found a "mask" token, which means the user wants to | |
11234 | create a hardware watchpoint that is going to have the mask | |
11235 | facility. */ | |
11236 | struct value *mask_value, *mark; | |
37e4754d | 11237 | |
9c06b0b4 TJB |
11238 | if (use_mask) |
11239 | error(_("You can specify only one mask.")); | |
37e4754d | 11240 | |
9c06b0b4 | 11241 | use_mask = just_location = 1; |
37e4754d | 11242 | |
9c06b0b4 TJB |
11243 | mark = value_mark (); |
11244 | mask_value = parse_to_comma_and_eval (&value_start); | |
11245 | mask = value_as_address (mask_value); | |
11246 | value_free_to_mark (mark); | |
11247 | } | |
11248 | else | |
11249 | /* We didn't recognize what we found. We should stop here. */ | |
11250 | break; | |
37e4754d | 11251 | |
9c06b0b4 TJB |
11252 | /* Truncate the string and get rid of the "parameter value" pair before |
11253 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11254 | exp_end = tok; |
9c06b0b4 | 11255 | } |
37e4754d | 11256 | } |
bbc13ae3 KS |
11257 | else |
11258 | exp_end = arg; | |
37e4754d | 11259 | |
bbc13ae3 KS |
11260 | /* Parse the rest of the arguments. From here on out, everything |
11261 | is in terms of a newly allocated string instead of the original | |
11262 | ARG. */ | |
c906108c | 11263 | innermost_block = NULL; |
bbc13ae3 KS |
11264 | expression = savestring (arg, exp_end - arg); |
11265 | back_to = make_cleanup (xfree, expression); | |
11266 | exp_start = arg = expression; | |
1bb9788d | 11267 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11268 | exp_end = arg; |
fa8a61dc TT |
11269 | /* Remove trailing whitespace from the expression before saving it. |
11270 | This makes the eventual display of the expression string a bit | |
11271 | prettier. */ | |
11272 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11273 | --exp_end; | |
11274 | ||
65d79d4b SDJ |
11275 | /* Checking if the expression is not constant. */ |
11276 | if (watchpoint_exp_is_const (exp)) | |
11277 | { | |
11278 | int len; | |
11279 | ||
11280 | len = exp_end - exp_start; | |
11281 | while (len > 0 && isspace (exp_start[len - 1])) | |
11282 | len--; | |
11283 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11284 | } | |
11285 | ||
c906108c SS |
11286 | exp_valid_block = innermost_block; |
11287 | mark = value_mark (); | |
3a1115a0 | 11288 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11289 | |
bb9d5f81 PP |
11290 | if (val != NULL && just_location) |
11291 | { | |
11292 | saved_bitpos = value_bitpos (val); | |
11293 | saved_bitsize = value_bitsize (val); | |
11294 | } | |
11295 | ||
06a64a0b TT |
11296 | if (just_location) |
11297 | { | |
9c06b0b4 TJB |
11298 | int ret; |
11299 | ||
06a64a0b | 11300 | exp_valid_block = NULL; |
a1442452 | 11301 | val = value_addr (result); |
06a64a0b TT |
11302 | release_value (val); |
11303 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11304 | |
11305 | if (use_mask) | |
11306 | { | |
11307 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11308 | mask); | |
11309 | if (ret == -1) | |
11310 | error (_("This target does not support masked watchpoints.")); | |
11311 | else if (ret == -2) | |
11312 | error (_("Invalid mask or memory region.")); | |
11313 | } | |
06a64a0b TT |
11314 | } |
11315 | else if (val != NULL) | |
fa4727a6 | 11316 | release_value (val); |
c906108c | 11317 | |
bbc13ae3 KS |
11318 | tok = skip_spaces_const (arg); |
11319 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11320 | |
11321 | toklen = end_tok - tok; | |
11322 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11323 | { | |
2d134ed3 PA |
11324 | struct expression *cond; |
11325 | ||
60e1c644 | 11326 | innermost_block = NULL; |
c906108c | 11327 | tok = cond_start = end_tok + 1; |
1bb9788d | 11328 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11329 | |
11330 | /* The watchpoint expression may not be local, but the condition | |
11331 | may still be. E.g.: `watch global if local > 0'. */ | |
11332 | cond_exp_valid_block = innermost_block; | |
11333 | ||
2d134ed3 | 11334 | xfree (cond); |
c906108c SS |
11335 | cond_end = tok; |
11336 | } | |
11337 | if (*tok) | |
8a3fe4f8 | 11338 | error (_("Junk at end of command.")); |
c906108c | 11339 | |
d983da9c | 11340 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11341 | |
11342 | /* If the expression is "local", then set up a "watchpoint scope" | |
11343 | breakpoint at the point where we've left the scope of the watchpoint | |
11344 | expression. Create the scope breakpoint before the watchpoint, so | |
11345 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11346 | if (exp_valid_block && frame) |
d983da9c | 11347 | { |
edb3359d DJ |
11348 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11349 | { | |
11350 | scope_breakpoint | |
a6d9a66e UW |
11351 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11352 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11353 | bp_watchpoint_scope, |
11354 | &momentary_breakpoint_ops); | |
d983da9c | 11355 | |
edb3359d | 11356 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11357 | |
edb3359d DJ |
11358 | /* Automatically delete the breakpoint when it hits. */ |
11359 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11360 | |
edb3359d DJ |
11361 | /* Only break in the proper frame (help with recursion). */ |
11362 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11363 | |
edb3359d | 11364 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11365 | scope_breakpoint->loc->gdbarch |
11366 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11367 | scope_breakpoint->loc->requested_address |
11368 | = frame_unwind_caller_pc (frame); | |
11369 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11370 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11371 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11372 | scope_breakpoint->type); |
11373 | } | |
d983da9c DJ |
11374 | } |
11375 | ||
e8369a73 AB |
11376 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11377 | watchpoints here even if hardware watchpoints are turned off, a call | |
11378 | to update_watchpoint later in this function will cause the type to | |
11379 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11380 | ||
11381 | if (accessflag == hw_read) | |
11382 | bp_type = bp_read_watchpoint; | |
11383 | else if (accessflag == hw_access) | |
11384 | bp_type = bp_access_watchpoint; | |
11385 | else | |
11386 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11387 | |
11388 | w = XCNEW (struct watchpoint); | |
11389 | b = &w->base; | |
348d480f | 11390 | if (use_mask) |
3a5c3e22 PA |
11391 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11392 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11393 | else |
3a5c3e22 PA |
11394 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11395 | &watchpoint_breakpoint_ops); | |
37e4754d | 11396 | b->thread = thread; |
b5de0fa7 | 11397 | b->disposition = disp_donttouch; |
348d480f | 11398 | b->pspace = current_program_space; |
3a5c3e22 PA |
11399 | w->exp = exp; |
11400 | w->exp_valid_block = exp_valid_block; | |
11401 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11402 | if (just_location) |
11403 | { | |
11404 | struct type *t = value_type (val); | |
11405 | CORE_ADDR addr = value_as_address (val); | |
11406 | char *name; | |
11407 | ||
11408 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11409 | name = type_to_string (t); | |
11410 | ||
3a5c3e22 | 11411 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11412 | core_addr_to_string (addr)); |
06a64a0b TT |
11413 | xfree (name); |
11414 | ||
3a5c3e22 | 11415 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11416 | (int) (exp_end - exp_start), exp_start); |
11417 | ||
06a64a0b TT |
11418 | /* The above expression is in C. */ |
11419 | b->language = language_c; | |
11420 | } | |
11421 | else | |
3a5c3e22 | 11422 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11423 | |
11424 | if (use_mask) | |
11425 | { | |
3a5c3e22 | 11426 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11427 | } |
11428 | else | |
11429 | { | |
3a5c3e22 | 11430 | w->val = val; |
bb9d5f81 PP |
11431 | w->val_bitpos = saved_bitpos; |
11432 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11433 | w->val_valid = 1; |
9c06b0b4 | 11434 | } |
77b06cd7 | 11435 | |
c906108c SS |
11436 | if (cond_start) |
11437 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11438 | else | |
11439 | b->cond_string = 0; | |
c5aa993b | 11440 | |
c906108c | 11441 | if (frame) |
f6bc2008 | 11442 | { |
3a5c3e22 PA |
11443 | w->watchpoint_frame = get_frame_id (frame); |
11444 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11445 | } |
c906108c | 11446 | else |
f6bc2008 | 11447 | { |
3a5c3e22 PA |
11448 | w->watchpoint_frame = null_frame_id; |
11449 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11450 | } |
c906108c | 11451 | |
d983da9c | 11452 | if (scope_breakpoint != NULL) |
c906108c | 11453 | { |
d983da9c DJ |
11454 | /* The scope breakpoint is related to the watchpoint. We will |
11455 | need to act on them together. */ | |
11456 | b->related_breakpoint = scope_breakpoint; | |
11457 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11458 | } |
d983da9c | 11459 | |
06a64a0b TT |
11460 | if (!just_location) |
11461 | value_free_to_mark (mark); | |
2d134ed3 | 11462 | |
492d29ea | 11463 | TRY |
a9634178 TJB |
11464 | { |
11465 | /* Finally update the new watchpoint. This creates the locations | |
11466 | that should be inserted. */ | |
3a5c3e22 | 11467 | update_watchpoint (w, 1); |
a9634178 | 11468 | } |
492d29ea | 11469 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11470 | { |
11471 | delete_breakpoint (b); | |
11472 | throw_exception (e); | |
11473 | } | |
492d29ea | 11474 | END_CATCH |
a9634178 | 11475 | |
3ea46bff | 11476 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11477 | do_cleanups (back_to); |
c906108c SS |
11478 | } |
11479 | ||
e09342b5 | 11480 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11481 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11482 | |
c906108c | 11483 | static int |
a9634178 | 11484 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11485 | { |
11486 | int found_memory_cnt = 0; | |
2e70b7b9 | 11487 | struct value *head = v; |
c906108c SS |
11488 | |
11489 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11490 | if (!can_use_hw_watchpoints) |
c906108c | 11491 | return 0; |
c5aa993b | 11492 | |
5c44784c JM |
11493 | /* Make sure that the value of the expression depends only upon |
11494 | memory contents, and values computed from them within GDB. If we | |
11495 | find any register references or function calls, we can't use a | |
11496 | hardware watchpoint. | |
11497 | ||
11498 | The idea here is that evaluating an expression generates a series | |
11499 | of values, one holding the value of every subexpression. (The | |
11500 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11501 | a*b+c.) GDB's values hold almost enough information to establish | |
11502 | the criteria given above --- they identify memory lvalues, | |
11503 | register lvalues, computed values, etcetera. So we can evaluate | |
11504 | the expression, and then scan the chain of values that leaves | |
11505 | behind to decide whether we can detect any possible change to the | |
11506 | expression's final value using only hardware watchpoints. | |
11507 | ||
11508 | However, I don't think that the values returned by inferior | |
11509 | function calls are special in any way. So this function may not | |
11510 | notice that an expression involving an inferior function call | |
11511 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11512 | for (; v; v = value_next (v)) |
c906108c | 11513 | { |
5c44784c | 11514 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11515 | { |
8464be76 DJ |
11516 | if (v != head && value_lazy (v)) |
11517 | /* A lazy memory lvalue in the chain is one that GDB never | |
11518 | needed to fetch; we either just used its address (e.g., | |
11519 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11520 | in `a,b'). This doesn't apply to HEAD; if that is | |
11521 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11522 | ; |
53a5351d | 11523 | else |
5c44784c JM |
11524 | { |
11525 | /* Ahh, memory we actually used! Check if we can cover | |
11526 | it with hardware watchpoints. */ | |
df407dfe | 11527 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11528 | |
11529 | /* We only watch structs and arrays if user asked for it | |
11530 | explicitly, never if they just happen to appear in a | |
11531 | middle of some value chain. */ | |
11532 | if (v == head | |
11533 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11534 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11535 | { | |
42ae5230 | 11536 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11537 | int len; |
11538 | int num_regs; | |
11539 | ||
a9634178 | 11540 | len = (target_exact_watchpoints |
e09342b5 TJB |
11541 | && is_scalar_type_recursive (vtype))? |
11542 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11543 | |
e09342b5 TJB |
11544 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11545 | if (!num_regs) | |
2e70b7b9 MS |
11546 | return 0; |
11547 | else | |
e09342b5 | 11548 | found_memory_cnt += num_regs; |
2e70b7b9 | 11549 | } |
5c44784c | 11550 | } |
c5aa993b | 11551 | } |
5086187c AC |
11552 | else if (VALUE_LVAL (v) != not_lval |
11553 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11554 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11555 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11556 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11557 | } |
11558 | ||
11559 | /* The expression itself looks suitable for using a hardware | |
11560 | watchpoint, but give the target machine a chance to reject it. */ | |
11561 | return found_memory_cnt; | |
11562 | } | |
11563 | ||
8b93c638 | 11564 | void |
84f4c1fe | 11565 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11566 | { |
84f4c1fe | 11567 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11568 | } |
11569 | ||
06a64a0b TT |
11570 | /* A helper function that looks for the "-location" argument and then |
11571 | calls watch_command_1. */ | |
11572 | ||
11573 | static void | |
11574 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11575 | { | |
11576 | int just_location = 0; | |
11577 | ||
11578 | if (arg | |
11579 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11580 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11581 | { | |
e9cafbcc | 11582 | arg = skip_spaces (arg); |
06a64a0b TT |
11583 | just_location = 1; |
11584 | } | |
11585 | ||
84f4c1fe | 11586 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11587 | } |
8926118c | 11588 | |
c5aa993b | 11589 | static void |
fba45db2 | 11590 | watch_command (char *arg, int from_tty) |
c906108c | 11591 | { |
06a64a0b | 11592 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11593 | } |
11594 | ||
8b93c638 | 11595 | void |
84f4c1fe | 11596 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11597 | { |
84f4c1fe | 11598 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11599 | } |
8926118c | 11600 | |
c5aa993b | 11601 | static void |
fba45db2 | 11602 | rwatch_command (char *arg, int from_tty) |
c906108c | 11603 | { |
06a64a0b | 11604 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11605 | } |
11606 | ||
8b93c638 | 11607 | void |
84f4c1fe | 11608 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11609 | { |
84f4c1fe | 11610 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11611 | } |
8926118c | 11612 | |
c5aa993b | 11613 | static void |
fba45db2 | 11614 | awatch_command (char *arg, int from_tty) |
c906108c | 11615 | { |
06a64a0b | 11616 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11617 | } |
c906108c | 11618 | \f |
c5aa993b | 11619 | |
cfc31633 PA |
11620 | /* Data for the FSM that manages the until(location)/advance commands |
11621 | in infcmd.c. Here because it uses the mechanisms of | |
11622 | breakpoints. */ | |
c906108c | 11623 | |
cfc31633 | 11624 | struct until_break_fsm |
bfec99b2 | 11625 | { |
cfc31633 PA |
11626 | /* The base class. */ |
11627 | struct thread_fsm thread_fsm; | |
11628 | ||
11629 | /* The thread that as current when the command was executed. */ | |
11630 | int thread; | |
11631 | ||
11632 | /* The breakpoint set at the destination location. */ | |
11633 | struct breakpoint *location_breakpoint; | |
11634 | ||
11635 | /* Breakpoint set at the return address in the caller frame. May be | |
11636 | NULL. */ | |
11637 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11638 | }; |
11639 | ||
8980e177 PA |
11640 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11641 | struct thread_info *thread); | |
11642 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11643 | struct thread_info *thread); | |
cfc31633 PA |
11644 | static enum async_reply_reason |
11645 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11646 | ||
11647 | /* until_break_fsm's vtable. */ | |
11648 | ||
11649 | static struct thread_fsm_ops until_break_fsm_ops = | |
11650 | { | |
11651 | NULL, /* dtor */ | |
11652 | until_break_fsm_clean_up, | |
11653 | until_break_fsm_should_stop, | |
11654 | NULL, /* return_value */ | |
11655 | until_break_fsm_async_reply_reason, | |
11656 | }; | |
11657 | ||
11658 | /* Allocate a new until_break_command_fsm. */ | |
11659 | ||
11660 | static struct until_break_fsm * | |
8980e177 | 11661 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11662 | struct breakpoint *location_breakpoint, |
11663 | struct breakpoint *caller_breakpoint) | |
11664 | { | |
11665 | struct until_break_fsm *sm; | |
11666 | ||
11667 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11668 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11669 | |
11670 | sm->thread = thread; | |
11671 | sm->location_breakpoint = location_breakpoint; | |
11672 | sm->caller_breakpoint = caller_breakpoint; | |
11673 | ||
11674 | return sm; | |
11675 | } | |
11676 | ||
11677 | /* Implementation of the 'should_stop' FSM method for the | |
11678 | until(location)/advance commands. */ | |
11679 | ||
11680 | static int | |
8980e177 PA |
11681 | until_break_fsm_should_stop (struct thread_fsm *self, |
11682 | struct thread_info *tp) | |
cfc31633 PA |
11683 | { |
11684 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11685 | |
11686 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11687 | sm->location_breakpoint) != NULL | |
11688 | || (sm->caller_breakpoint != NULL | |
11689 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11690 | sm->caller_breakpoint) != NULL)) | |
11691 | thread_fsm_set_finished (self); | |
11692 | ||
11693 | return 1; | |
11694 | } | |
11695 | ||
11696 | /* Implementation of the 'clean_up' FSM method for the | |
11697 | until(location)/advance commands. */ | |
11698 | ||
c2c6d25f | 11699 | static void |
8980e177 PA |
11700 | until_break_fsm_clean_up (struct thread_fsm *self, |
11701 | struct thread_info *thread) | |
43ff13b4 | 11702 | { |
cfc31633 | 11703 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11704 | |
cfc31633 PA |
11705 | /* Clean up our temporary breakpoints. */ |
11706 | if (sm->location_breakpoint != NULL) | |
11707 | { | |
11708 | delete_breakpoint (sm->location_breakpoint); | |
11709 | sm->location_breakpoint = NULL; | |
11710 | } | |
11711 | if (sm->caller_breakpoint != NULL) | |
11712 | { | |
11713 | delete_breakpoint (sm->caller_breakpoint); | |
11714 | sm->caller_breakpoint = NULL; | |
11715 | } | |
11716 | delete_longjmp_breakpoint (sm->thread); | |
11717 | } | |
11718 | ||
11719 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11720 | until(location)/advance commands. */ | |
11721 | ||
11722 | static enum async_reply_reason | |
11723 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11724 | { | |
11725 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11726 | } |
11727 | ||
c906108c | 11728 | void |
ae66c1fc | 11729 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11730 | { |
11731 | struct symtabs_and_lines sals; | |
11732 | struct symtab_and_line sal; | |
8556afb4 PA |
11733 | struct frame_info *frame; |
11734 | struct gdbarch *frame_gdbarch; | |
11735 | struct frame_id stack_frame_id; | |
11736 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11737 | struct breakpoint *location_breakpoint; |
11738 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11739 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11740 | int thread; |
11741 | struct thread_info *tp; | |
f00aae0f | 11742 | struct event_location *location; |
cfc31633 | 11743 | struct until_break_fsm *sm; |
c906108c | 11744 | |
70509625 | 11745 | clear_proceed_status (0); |
c906108c SS |
11746 | |
11747 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11748 | this function. */ |
c5aa993b | 11749 | |
f00aae0f KS |
11750 | location = string_to_event_location (&arg, current_language); |
11751 | cleanup = make_cleanup_delete_event_location (location); | |
11752 | ||
1bfeeb0f | 11753 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11754 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11755 | get_last_displayed_symtab (), |
f8eba3c6 | 11756 | get_last_displayed_line ()); |
c906108c | 11757 | else |
f00aae0f | 11758 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11759 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11760 | |
c906108c | 11761 | if (sals.nelts != 1) |
8a3fe4f8 | 11762 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11763 | |
c906108c | 11764 | sal = sals.sals[0]; |
4a64f543 | 11765 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11766 | |
c906108c | 11767 | if (*arg) |
8a3fe4f8 | 11768 | error (_("Junk at end of arguments.")); |
c5aa993b | 11769 | |
c906108c | 11770 | resolve_sal_pc (&sal); |
c5aa993b | 11771 | |
186c406b | 11772 | tp = inferior_thread (); |
5d5658a1 | 11773 | thread = tp->global_num; |
186c406b | 11774 | |
883bc8d1 PA |
11775 | old_chain = make_cleanup (null_cleanup, NULL); |
11776 | ||
8556afb4 PA |
11777 | /* Note linespec handling above invalidates the frame chain. |
11778 | Installing a breakpoint also invalidates the frame chain (as it | |
11779 | may need to switch threads), so do any frame handling before | |
11780 | that. */ | |
11781 | ||
11782 | frame = get_selected_frame (NULL); | |
11783 | frame_gdbarch = get_frame_arch (frame); | |
11784 | stack_frame_id = get_stack_frame_id (frame); | |
11785 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11786 | |
ae66c1fc EZ |
11787 | /* Keep within the current frame, or in frames called by the current |
11788 | one. */ | |
edb3359d | 11789 | |
883bc8d1 | 11790 | if (frame_id_p (caller_frame_id)) |
c906108c | 11791 | { |
883bc8d1 | 11792 | struct symtab_and_line sal2; |
cfc31633 | 11793 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11794 | |
11795 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11796 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11797 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11798 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11799 | sal2, | |
11800 | caller_frame_id, | |
11801 | bp_until); | |
11802 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11803 | |
883bc8d1 | 11804 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11805 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11806 | } |
c5aa993b | 11807 | |
c70a6932 JK |
11808 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11809 | frame = NULL; | |
11810 | ||
883bc8d1 PA |
11811 | if (anywhere) |
11812 | /* If the user told us to continue until a specified location, | |
11813 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11814 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11815 | null_frame_id, bp_until); | |
883bc8d1 PA |
11816 | else |
11817 | /* Otherwise, specify the selected frame, because we want to stop | |
11818 | only at the very same frame. */ | |
cfc31633 PA |
11819 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11820 | stack_frame_id, bp_until); | |
11821 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11822 | |
8980e177 | 11823 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11824 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11825 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11826 | |
cfc31633 | 11827 | discard_cleanups (old_chain); |
f107f563 | 11828 | |
cfc31633 | 11829 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11830 | |
11831 | do_cleanups (cleanup); | |
c906108c | 11832 | } |
ae66c1fc | 11833 | |
c906108c SS |
11834 | /* This function attempts to parse an optional "if <cond>" clause |
11835 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11836 | |
c906108c SS |
11837 | Else, it returns a pointer to the condition string. (It does not |
11838 | attempt to evaluate the string against a particular block.) And, | |
11839 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11840 | if clause in the arg string. */ |
53a5351d | 11841 | |
916703c0 | 11842 | char * |
fba45db2 | 11843 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11844 | { |
c5aa993b JM |
11845 | char *cond_string; |
11846 | ||
11847 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11848 | return NULL; |
c5aa993b | 11849 | |
4a64f543 | 11850 | /* Skip the "if" keyword. */ |
c906108c | 11851 | (*arg) += 2; |
c5aa993b | 11852 | |
c906108c | 11853 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11854 | condition string. */ |
e9cafbcc | 11855 | *arg = skip_spaces (*arg); |
c906108c | 11856 | cond_string = *arg; |
c5aa993b | 11857 | |
4a64f543 MS |
11858 | /* Assume that the condition occupies the remainder of the arg |
11859 | string. */ | |
c906108c | 11860 | (*arg) += strlen (cond_string); |
c5aa993b | 11861 | |
c906108c SS |
11862 | return cond_string; |
11863 | } | |
c5aa993b | 11864 | |
c906108c SS |
11865 | /* Commands to deal with catching events, such as signals, exceptions, |
11866 | process start/exit, etc. */ | |
c5aa993b JM |
11867 | |
11868 | typedef enum | |
11869 | { | |
44feb3ce TT |
11870 | catch_fork_temporary, catch_vfork_temporary, |
11871 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11872 | } |
11873 | catch_fork_kind; | |
11874 | ||
c906108c | 11875 | static void |
cc59ec59 MS |
11876 | catch_fork_command_1 (char *arg, int from_tty, |
11877 | struct cmd_list_element *command) | |
c906108c | 11878 | { |
a6d9a66e | 11879 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11880 | char *cond_string = NULL; |
44feb3ce TT |
11881 | catch_fork_kind fork_kind; |
11882 | int tempflag; | |
11883 | ||
11884 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11885 | tempflag = (fork_kind == catch_fork_temporary | |
11886 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11887 | |
44feb3ce TT |
11888 | if (!arg) |
11889 | arg = ""; | |
e9cafbcc | 11890 | arg = skip_spaces (arg); |
c5aa993b | 11891 | |
c906108c | 11892 | /* The allowed syntax is: |
c5aa993b JM |
11893 | catch [v]fork |
11894 | catch [v]fork if <cond> | |
11895 | ||
4a64f543 | 11896 | First, check if there's an if clause. */ |
c906108c | 11897 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11898 | |
c906108c | 11899 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11900 | error (_("Junk at end of arguments.")); |
c5aa993b | 11901 | |
c906108c | 11902 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11903 | and enable reporting of such events. */ |
c5aa993b JM |
11904 | switch (fork_kind) |
11905 | { | |
44feb3ce TT |
11906 | case catch_fork_temporary: |
11907 | case catch_fork_permanent: | |
a6d9a66e | 11908 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11909 | &catch_fork_breakpoint_ops); |
c906108c | 11910 | break; |
44feb3ce TT |
11911 | case catch_vfork_temporary: |
11912 | case catch_vfork_permanent: | |
a6d9a66e | 11913 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11914 | &catch_vfork_breakpoint_ops); |
c906108c | 11915 | break; |
c5aa993b | 11916 | default: |
8a3fe4f8 | 11917 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11918 | break; |
c5aa993b | 11919 | } |
c906108c SS |
11920 | } |
11921 | ||
11922 | static void | |
cc59ec59 MS |
11923 | catch_exec_command_1 (char *arg, int from_tty, |
11924 | struct cmd_list_element *command) | |
c906108c | 11925 | { |
b4d90040 | 11926 | struct exec_catchpoint *c; |
a6d9a66e | 11927 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11928 | int tempflag; |
c5aa993b | 11929 | char *cond_string = NULL; |
c906108c | 11930 | |
44feb3ce TT |
11931 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11932 | ||
11933 | if (!arg) | |
11934 | arg = ""; | |
e9cafbcc | 11935 | arg = skip_spaces (arg); |
c906108c SS |
11936 | |
11937 | /* The allowed syntax is: | |
c5aa993b JM |
11938 | catch exec |
11939 | catch exec if <cond> | |
c906108c | 11940 | |
4a64f543 | 11941 | First, check if there's an if clause. */ |
c906108c SS |
11942 | cond_string = ep_parse_optional_if_clause (&arg); |
11943 | ||
11944 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11945 | error (_("Junk at end of arguments.")); |
c906108c | 11946 | |
b4d90040 PA |
11947 | c = XNEW (struct exec_catchpoint); |
11948 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11949 | &catch_exec_breakpoint_ops); | |
11950 | c->exec_pathname = NULL; | |
11951 | ||
3ea46bff | 11952 | install_breakpoint (0, &c->base, 1); |
c906108c | 11953 | } |
c5aa993b | 11954 | |
9ac4176b | 11955 | void |
28010a5d PA |
11956 | init_ada_exception_breakpoint (struct breakpoint *b, |
11957 | struct gdbarch *gdbarch, | |
11958 | struct symtab_and_line sal, | |
11959 | char *addr_string, | |
c0a91b2b | 11960 | const struct breakpoint_ops *ops, |
28010a5d | 11961 | int tempflag, |
349774ef | 11962 | int enabled, |
28010a5d | 11963 | int from_tty) |
f7f9143b | 11964 | { |
f7f9143b JB |
11965 | if (from_tty) |
11966 | { | |
5af949e3 UW |
11967 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11968 | if (!loc_gdbarch) | |
11969 | loc_gdbarch = gdbarch; | |
11970 | ||
6c95b8df PA |
11971 | describe_other_breakpoints (loc_gdbarch, |
11972 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11973 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11974 | version for exception catchpoints, because two catchpoints | |
11975 | used for different exception names will use the same address. | |
11976 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11977 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11978 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11979 | the user what type of catchpoint it is. The above is good |
11980 | enough for now, though. */ | |
11981 | } | |
11982 | ||
28010a5d | 11983 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11984 | |
349774ef | 11985 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11986 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11987 | b->location = string_to_event_location (&addr_string, |
11988 | language_def (language_ada)); | |
f7f9143b | 11989 | b->language = language_ada; |
f7f9143b JB |
11990 | } |
11991 | ||
c906108c | 11992 | static void |
fba45db2 | 11993 | catch_command (char *arg, int from_tty) |
c906108c | 11994 | { |
44feb3ce | 11995 | error (_("Catch requires an event name.")); |
c906108c SS |
11996 | } |
11997 | \f | |
11998 | ||
11999 | static void | |
fba45db2 | 12000 | tcatch_command (char *arg, int from_tty) |
c906108c | 12001 | { |
44feb3ce | 12002 | error (_("Catch requires an event name.")); |
c906108c SS |
12003 | } |
12004 | ||
8a2c437b TT |
12005 | /* A qsort comparison function that sorts breakpoints in order. */ |
12006 | ||
12007 | static int | |
12008 | compare_breakpoints (const void *a, const void *b) | |
12009 | { | |
9a3c8263 | 12010 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 12011 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 12012 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
12013 | uintptr_t ub = (uintptr_t) *bb; |
12014 | ||
12015 | if ((*ba)->number < (*bb)->number) | |
12016 | return -1; | |
12017 | else if ((*ba)->number > (*bb)->number) | |
12018 | return 1; | |
12019 | ||
12020 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12021 | the number 0. */ | |
12022 | if (ua < ub) | |
12023 | return -1; | |
94b0e70d | 12024 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12025 | } |
12026 | ||
80f8a6eb | 12027 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12028 | |
12029 | static void | |
fba45db2 | 12030 | clear_command (char *arg, int from_tty) |
c906108c | 12031 | { |
8a2c437b | 12032 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12033 | VEC(breakpoint_p) *found = 0; |
12034 | int ix; | |
c906108c SS |
12035 | int default_match; |
12036 | struct symtabs_and_lines sals; | |
12037 | struct symtab_and_line sal; | |
c906108c | 12038 | int i; |
8a2c437b | 12039 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12040 | |
12041 | if (arg) | |
12042 | { | |
39cf75f7 DE |
12043 | sals = decode_line_with_current_source (arg, |
12044 | (DECODE_LINE_FUNFIRSTLINE | |
12045 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12046 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12047 | default_match = 0; |
12048 | } | |
12049 | else | |
12050 | { | |
8d749320 | 12051 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12052 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12053 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12054 | |
12055 | /* Set sal's line, symtab, pc, and pspace to the values | |
12056 | corresponding to the last call to print_frame_info. If the | |
12057 | codepoint is not valid, this will set all the fields to 0. */ | |
12058 | get_last_displayed_sal (&sal); | |
c906108c | 12059 | if (sal.symtab == 0) |
8a3fe4f8 | 12060 | error (_("No source file specified.")); |
c906108c SS |
12061 | |
12062 | sals.sals[0] = sal; | |
12063 | sals.nelts = 1; | |
12064 | ||
12065 | default_match = 1; | |
12066 | } | |
12067 | ||
4a64f543 MS |
12068 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12069 | seems, because all existing breakpoints typically have both | |
12070 | file/line and pc set. So, if clear is given file/line, we can | |
12071 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12072 | |
12073 | We only support clearing given the address explicitly | |
12074 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12075 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12076 | due to optimization, all in one block. |
4a64f543 MS |
12077 | |
12078 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12079 | PC corresponding to the same file:line, the breakpoint won't |
12080 | be cleared. We probably can still clear the breakpoint, but | |
12081 | since the other PC value is never presented to user, user | |
12082 | can only find it by guessing, and it does not seem important | |
12083 | to support that. */ | |
12084 | ||
4a64f543 MS |
12085 | /* For each line spec given, delete bps which correspond to it. Do |
12086 | it in two passes, solely to preserve the current behavior that | |
12087 | from_tty is forced true if we delete more than one | |
12088 | breakpoint. */ | |
c906108c | 12089 | |
80f8a6eb | 12090 | found = NULL; |
8a2c437b | 12091 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12092 | for (i = 0; i < sals.nelts; i++) |
12093 | { | |
05cba821 JK |
12094 | const char *sal_fullname; |
12095 | ||
c906108c | 12096 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12097 | If line given (pc == 0), clear all bpts on specified line. |
12098 | If defaulting, clear all bpts on default line | |
c906108c | 12099 | or at default pc. |
c5aa993b JM |
12100 | |
12101 | defaulting sal.pc != 0 tests to do | |
12102 | ||
12103 | 0 1 pc | |
12104 | 1 1 pc _and_ line | |
12105 | 0 0 line | |
12106 | 1 0 <can't happen> */ | |
c906108c SS |
12107 | |
12108 | sal = sals.sals[i]; | |
05cba821 JK |
12109 | sal_fullname = (sal.symtab == NULL |
12110 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12111 | |
4a64f543 | 12112 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12113 | ALL_BREAKPOINTS (b) |
c5aa993b | 12114 | { |
0d381245 | 12115 | int match = 0; |
4a64f543 | 12116 | /* Are we going to delete b? */ |
cc60f2e3 | 12117 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12118 | { |
12119 | struct bp_location *loc = b->loc; | |
12120 | for (; loc; loc = loc->next) | |
12121 | { | |
f8eba3c6 TT |
12122 | /* If the user specified file:line, don't allow a PC |
12123 | match. This matches historical gdb behavior. */ | |
12124 | int pc_match = (!sal.explicit_line | |
12125 | && sal.pc | |
12126 | && (loc->pspace == sal.pspace) | |
12127 | && (loc->address == sal.pc) | |
12128 | && (!section_is_overlay (loc->section) | |
12129 | || loc->section == sal.section)); | |
4aac40c8 TT |
12130 | int line_match = 0; |
12131 | ||
12132 | if ((default_match || sal.explicit_line) | |
2f202fde | 12133 | && loc->symtab != NULL |
05cba821 | 12134 | && sal_fullname != NULL |
4aac40c8 | 12135 | && sal.pspace == loc->pspace |
05cba821 JK |
12136 | && loc->line_number == sal.line |
12137 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12138 | sal_fullname) == 0) | |
12139 | line_match = 1; | |
4aac40c8 | 12140 | |
0d381245 VP |
12141 | if (pc_match || line_match) |
12142 | { | |
12143 | match = 1; | |
12144 | break; | |
12145 | } | |
12146 | } | |
12147 | } | |
12148 | ||
12149 | if (match) | |
d6e956e5 | 12150 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12151 | } |
80f8a6eb | 12152 | } |
8a2c437b | 12153 | |
80f8a6eb | 12154 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12155 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12156 | { |
12157 | if (arg) | |
8a3fe4f8 | 12158 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12159 | else |
8a3fe4f8 | 12160 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12161 | } |
c906108c | 12162 | |
8a2c437b TT |
12163 | /* Remove duplicates from the vec. */ |
12164 | qsort (VEC_address (breakpoint_p, found), | |
12165 | VEC_length (breakpoint_p, found), | |
12166 | sizeof (breakpoint_p), | |
12167 | compare_breakpoints); | |
12168 | prev = VEC_index (breakpoint_p, found, 0); | |
12169 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12170 | { | |
12171 | if (b == prev) | |
12172 | { | |
12173 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12174 | --ix; | |
12175 | } | |
12176 | } | |
12177 | ||
d6e956e5 | 12178 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12179 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12180 | if (from_tty) |
a3f17187 | 12181 | { |
d6e956e5 | 12182 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12183 | printf_unfiltered (_("Deleted breakpoint ")); |
12184 | else | |
12185 | printf_unfiltered (_("Deleted breakpoints ")); | |
12186 | } | |
d6e956e5 VP |
12187 | |
12188 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12189 | { |
c5aa993b | 12190 | if (from_tty) |
d6e956e5 VP |
12191 | printf_unfiltered ("%d ", b->number); |
12192 | delete_breakpoint (b); | |
c906108c | 12193 | } |
80f8a6eb MS |
12194 | if (from_tty) |
12195 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12196 | |
12197 | do_cleanups (cleanups); | |
c906108c SS |
12198 | } |
12199 | \f | |
12200 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12201 | all breakpoints that are marked for deletion, whether hit or not. | |
12202 | This is called after any breakpoint is hit, or after errors. */ | |
12203 | ||
12204 | void | |
fba45db2 | 12205 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12206 | { |
35df4500 | 12207 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12208 | |
12209 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12210 | if (bs->breakpoint_at |
12211 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12212 | && bs->stop) |
f431efe5 | 12213 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12214 | |
35df4500 | 12215 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12216 | { |
b5de0fa7 | 12217 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12218 | delete_breakpoint (b); |
12219 | } | |
c906108c SS |
12220 | } |
12221 | ||
4a64f543 MS |
12222 | /* A comparison function for bp_location AP and BP being interfaced to |
12223 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12224 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12225 | secondarily by ordering first permanent elements and |
4a64f543 | 12226 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12227 | qsort being an unstable algorithm. */ |
876fa593 JK |
12228 | |
12229 | static int | |
494cfb0f | 12230 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12231 | { |
9a3c8263 SM |
12232 | const struct bp_location *a = *(const struct bp_location **) ap; |
12233 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12234 | |
12235 | if (a->address != b->address) | |
12236 | return (a->address > b->address) - (a->address < b->address); | |
12237 | ||
dea2aa5f LM |
12238 | /* Sort locations at the same address by their pspace number, keeping |
12239 | locations of the same inferior (in a multi-inferior environment) | |
12240 | grouped. */ | |
12241 | ||
12242 | if (a->pspace->num != b->pspace->num) | |
12243 | return ((a->pspace->num > b->pspace->num) | |
12244 | - (a->pspace->num < b->pspace->num)); | |
12245 | ||
876fa593 | 12246 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12247 | if (a->permanent != b->permanent) |
12248 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12249 | |
c56a97f9 JK |
12250 | /* Make the internal GDB representation stable across GDB runs |
12251 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12252 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12253 | |
12254 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12255 | return ((a->owner->number > b->owner->number) |
12256 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12257 | |
12258 | return (a > b) - (a < b); | |
12259 | } | |
12260 | ||
876fa593 | 12261 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12262 | bp_location_shadow_len_after_address_max according to the current |
12263 | content of the bp_location array. */ | |
f7545552 TT |
12264 | |
12265 | static void | |
876fa593 | 12266 | bp_location_target_extensions_update (void) |
f7545552 | 12267 | { |
876fa593 JK |
12268 | struct bp_location *bl, **blp_tmp; |
12269 | ||
12270 | bp_location_placed_address_before_address_max = 0; | |
12271 | bp_location_shadow_len_after_address_max = 0; | |
12272 | ||
12273 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12274 | { | |
12275 | CORE_ADDR start, end, addr; | |
12276 | ||
12277 | if (!bp_location_has_shadow (bl)) | |
12278 | continue; | |
12279 | ||
12280 | start = bl->target_info.placed_address; | |
12281 | end = start + bl->target_info.shadow_len; | |
12282 | ||
12283 | gdb_assert (bl->address >= start); | |
12284 | addr = bl->address - start; | |
12285 | if (addr > bp_location_placed_address_before_address_max) | |
12286 | bp_location_placed_address_before_address_max = addr; | |
12287 | ||
12288 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12289 | ||
12290 | gdb_assert (bl->address < end); | |
12291 | addr = end - bl->address; | |
12292 | if (addr > bp_location_shadow_len_after_address_max) | |
12293 | bp_location_shadow_len_after_address_max = addr; | |
12294 | } | |
f7545552 TT |
12295 | } |
12296 | ||
1e4d1764 YQ |
12297 | /* Download tracepoint locations if they haven't been. */ |
12298 | ||
12299 | static void | |
12300 | download_tracepoint_locations (void) | |
12301 | { | |
7ed2c994 | 12302 | struct breakpoint *b; |
1e4d1764 | 12303 | struct cleanup *old_chain; |
dd2e65cc | 12304 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12305 | |
12306 | old_chain = save_current_space_and_thread (); | |
12307 | ||
7ed2c994 | 12308 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12309 | { |
7ed2c994 | 12310 | struct bp_location *bl; |
1e4d1764 | 12311 | struct tracepoint *t; |
f2a8bc8a | 12312 | int bp_location_downloaded = 0; |
1e4d1764 | 12313 | |
7ed2c994 | 12314 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12315 | ? !may_insert_fast_tracepoints |
12316 | : !may_insert_tracepoints)) | |
12317 | continue; | |
12318 | ||
dd2e65cc YQ |
12319 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12320 | { | |
12321 | if (target_can_download_tracepoint ()) | |
12322 | can_download_tracepoint = TRIBOOL_TRUE; | |
12323 | else | |
12324 | can_download_tracepoint = TRIBOOL_FALSE; | |
12325 | } | |
12326 | ||
12327 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12328 | break; | |
12329 | ||
7ed2c994 YQ |
12330 | for (bl = b->loc; bl; bl = bl->next) |
12331 | { | |
12332 | /* In tracepoint, locations are _never_ duplicated, so | |
12333 | should_be_inserted is equivalent to | |
12334 | unduplicated_should_be_inserted. */ | |
12335 | if (!should_be_inserted (bl) || bl->inserted) | |
12336 | continue; | |
1e4d1764 | 12337 | |
7ed2c994 | 12338 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12339 | |
7ed2c994 | 12340 | target_download_tracepoint (bl); |
1e4d1764 | 12341 | |
7ed2c994 | 12342 | bl->inserted = 1; |
f2a8bc8a | 12343 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12344 | } |
12345 | t = (struct tracepoint *) b; | |
12346 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12347 | if (bp_location_downloaded) |
12348 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12349 | } |
12350 | ||
12351 | do_cleanups (old_chain); | |
12352 | } | |
12353 | ||
934709f0 PW |
12354 | /* Swap the insertion/duplication state between two locations. */ |
12355 | ||
12356 | static void | |
12357 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12358 | { | |
12359 | const int left_inserted = left->inserted; | |
12360 | const int left_duplicate = left->duplicate; | |
b775012e | 12361 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12362 | const struct bp_target_info left_target_info = left->target_info; |
12363 | ||
1e4d1764 YQ |
12364 | /* Locations of tracepoints can never be duplicated. */ |
12365 | if (is_tracepoint (left->owner)) | |
12366 | gdb_assert (!left->duplicate); | |
12367 | if (is_tracepoint (right->owner)) | |
12368 | gdb_assert (!right->duplicate); | |
12369 | ||
934709f0 PW |
12370 | left->inserted = right->inserted; |
12371 | left->duplicate = right->duplicate; | |
b775012e | 12372 | left->needs_update = right->needs_update; |
934709f0 PW |
12373 | left->target_info = right->target_info; |
12374 | right->inserted = left_inserted; | |
12375 | right->duplicate = left_duplicate; | |
b775012e | 12376 | right->needs_update = left_needs_update; |
934709f0 PW |
12377 | right->target_info = left_target_info; |
12378 | } | |
12379 | ||
b775012e LM |
12380 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12381 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12382 | conditions on the target's side. Such conditions need to be updated on | |
12383 | the target. */ | |
12384 | ||
12385 | static void | |
12386 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12387 | { | |
12388 | struct bp_location **locp = NULL, **loc2p; | |
12389 | struct bp_location *loc; | |
12390 | CORE_ADDR address = 0; | |
12391 | int pspace_num; | |
12392 | ||
12393 | address = bl->address; | |
12394 | pspace_num = bl->pspace->num; | |
12395 | ||
12396 | /* This is only meaningful if the target is | |
12397 | evaluating conditions and if the user has | |
12398 | opted for condition evaluation on the target's | |
12399 | side. */ | |
12400 | if (gdb_evaluates_breakpoint_condition_p () | |
12401 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12402 | return; | |
12403 | ||
12404 | /* Flag all breakpoint locations with this address and | |
12405 | the same program space as the location | |
12406 | as "its condition has changed". We need to | |
12407 | update the conditions on the target's side. */ | |
12408 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12409 | { | |
12410 | loc = *loc2p; | |
12411 | ||
12412 | if (!is_breakpoint (loc->owner) | |
12413 | || pspace_num != loc->pspace->num) | |
12414 | continue; | |
12415 | ||
12416 | /* Flag the location appropriately. We use a different state to | |
12417 | let everyone know that we already updated the set of locations | |
12418 | with addr bl->address and program space bl->pspace. This is so | |
12419 | we don't have to keep calling these functions just to mark locations | |
12420 | that have already been marked. */ | |
12421 | loc->condition_changed = condition_updated; | |
12422 | ||
12423 | /* Free the agent expression bytecode as well. We will compute | |
12424 | it later on. */ | |
12425 | if (loc->cond_bytecode) | |
12426 | { | |
12427 | free_agent_expr (loc->cond_bytecode); | |
12428 | loc->cond_bytecode = NULL; | |
12429 | } | |
12430 | } | |
12431 | } | |
44702360 PA |
12432 | /* Called whether new breakpoints are created, or existing breakpoints |
12433 | deleted, to update the global location list and recompute which | |
12434 | locations are duplicate of which. | |
b775012e | 12435 | |
04086b45 PA |
12436 | The INSERT_MODE flag determines whether locations may not, may, or |
12437 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12438 | info. */ | |
b60e7edf | 12439 | |
0d381245 | 12440 | static void |
44702360 | 12441 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12442 | { |
74960c60 | 12443 | struct breakpoint *b; |
876fa593 | 12444 | struct bp_location **locp, *loc; |
f7545552 | 12445 | struct cleanup *cleanups; |
b775012e LM |
12446 | /* Last breakpoint location address that was marked for update. */ |
12447 | CORE_ADDR last_addr = 0; | |
12448 | /* Last breakpoint location program space that was marked for update. */ | |
12449 | int last_pspace_num = -1; | |
f7545552 | 12450 | |
2d134ed3 PA |
12451 | /* Used in the duplicates detection below. When iterating over all |
12452 | bp_locations, points to the first bp_location of a given address. | |
12453 | Breakpoints and watchpoints of different types are never | |
12454 | duplicates of each other. Keep one pointer for each type of | |
12455 | breakpoint/watchpoint, so we only need to loop over all locations | |
12456 | once. */ | |
12457 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12458 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12459 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12460 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12461 | |
4a64f543 MS |
12462 | /* Saved former bp_location array which we compare against the newly |
12463 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12464 | struct bp_location **old_location, **old_locp; |
12465 | unsigned old_location_count; | |
12466 | ||
12467 | old_location = bp_location; | |
12468 | old_location_count = bp_location_count; | |
12469 | bp_location = NULL; | |
12470 | bp_location_count = 0; | |
12471 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12472 | |
74960c60 | 12473 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12474 | for (loc = b->loc; loc; loc = loc->next) |
12475 | bp_location_count++; | |
12476 | ||
8d749320 | 12477 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12478 | locp = bp_location; |
12479 | ALL_BREAKPOINTS (b) | |
12480 | for (loc = b->loc; loc; loc = loc->next) | |
12481 | *locp++ = loc; | |
12482 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12483 | bp_location_compare); |
876fa593 JK |
12484 | |
12485 | bp_location_target_extensions_update (); | |
74960c60 | 12486 | |
4a64f543 MS |
12487 | /* Identify bp_location instances that are no longer present in the |
12488 | new list, and therefore should be freed. Note that it's not | |
12489 | necessary that those locations should be removed from inferior -- | |
12490 | if there's another location at the same address (previously | |
12491 | marked as duplicate), we don't need to remove/insert the | |
12492 | location. | |
876fa593 | 12493 | |
4a64f543 MS |
12494 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12495 | and former bp_location array state respectively. */ | |
876fa593 JK |
12496 | |
12497 | locp = bp_location; | |
12498 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12499 | old_locp++) | |
74960c60 | 12500 | { |
876fa593 | 12501 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12502 | struct bp_location **loc2p; |
876fa593 | 12503 | |
e5dd4106 | 12504 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12505 | not, we have to free it. */ |
c7d46a38 | 12506 | int found_object = 0; |
20874c92 VP |
12507 | /* Tells if the location should remain inserted in the target. */ |
12508 | int keep_in_target = 0; | |
12509 | int removed = 0; | |
876fa593 | 12510 | |
4a64f543 MS |
12511 | /* Skip LOCP entries which will definitely never be needed. |
12512 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12513 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12514 | && (*locp)->address < old_loc->address) |
876fa593 | 12515 | locp++; |
c7d46a38 PA |
12516 | |
12517 | for (loc2p = locp; | |
12518 | (loc2p < bp_location + bp_location_count | |
12519 | && (*loc2p)->address == old_loc->address); | |
12520 | loc2p++) | |
12521 | { | |
b775012e LM |
12522 | /* Check if this is a new/duplicated location or a duplicated |
12523 | location that had its condition modified. If so, we want to send | |
12524 | its condition to the target if evaluation of conditions is taking | |
12525 | place there. */ | |
12526 | if ((*loc2p)->condition_changed == condition_modified | |
12527 | && (last_addr != old_loc->address | |
12528 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12529 | { |
b775012e LM |
12530 | force_breakpoint_reinsertion (*loc2p); |
12531 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12532 | } |
b775012e LM |
12533 | |
12534 | if (*loc2p == old_loc) | |
12535 | found_object = 1; | |
c7d46a38 | 12536 | } |
74960c60 | 12537 | |
b775012e LM |
12538 | /* We have already handled this address, update it so that we don't |
12539 | have to go through updates again. */ | |
12540 | last_addr = old_loc->address; | |
12541 | ||
12542 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12543 | if (!found_object) | |
12544 | force_breakpoint_reinsertion (old_loc); | |
12545 | ||
4a64f543 MS |
12546 | /* If this location is no longer present, and inserted, look if |
12547 | there's maybe a new location at the same address. If so, | |
12548 | mark that one inserted, and don't remove this one. This is | |
12549 | needed so that we don't have a time window where a breakpoint | |
12550 | at certain location is not inserted. */ | |
74960c60 | 12551 | |
876fa593 | 12552 | if (old_loc->inserted) |
0d381245 | 12553 | { |
4a64f543 MS |
12554 | /* If the location is inserted now, we might have to remove |
12555 | it. */ | |
74960c60 | 12556 | |
876fa593 | 12557 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12558 | { |
4a64f543 MS |
12559 | /* The location is still present in the location list, |
12560 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12561 | keep_in_target = 1; |
74960c60 VP |
12562 | } |
12563 | else | |
12564 | { | |
b775012e LM |
12565 | /* This location still exists, but it won't be kept in the |
12566 | target since it may have been disabled. We proceed to | |
12567 | remove its target-side condition. */ | |
12568 | ||
4a64f543 MS |
12569 | /* The location is either no longer present, or got |
12570 | disabled. See if there's another location at the | |
12571 | same address, in which case we don't need to remove | |
12572 | this one from the target. */ | |
876fa593 | 12573 | |
2bdf28a0 | 12574 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12575 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12576 | { | |
876fa593 | 12577 | for (loc2p = locp; |
c7d46a38 PA |
12578 | (loc2p < bp_location + bp_location_count |
12579 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12580 | loc2p++) |
12581 | { | |
12582 | struct bp_location *loc2 = *loc2p; | |
12583 | ||
2d134ed3 | 12584 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12585 | { |
85d721b8 PA |
12586 | /* Read watchpoint locations are switched to |
12587 | access watchpoints, if the former are not | |
12588 | supported, but the latter are. */ | |
12589 | if (is_hardware_watchpoint (old_loc->owner)) | |
12590 | { | |
12591 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12592 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12593 | } | |
12594 | ||
934709f0 PW |
12595 | /* loc2 is a duplicated location. We need to check |
12596 | if it should be inserted in case it will be | |
12597 | unduplicated. */ | |
12598 | if (loc2 != old_loc | |
12599 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12600 | { |
934709f0 | 12601 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12602 | keep_in_target = 1; |
12603 | break; | |
12604 | } | |
876fa593 JK |
12605 | } |
12606 | } | |
12607 | } | |
74960c60 VP |
12608 | } |
12609 | ||
20874c92 VP |
12610 | if (!keep_in_target) |
12611 | { | |
834c0d03 | 12612 | if (remove_breakpoint (old_loc)) |
20874c92 | 12613 | { |
4a64f543 MS |
12614 | /* This is just about all we can do. We could keep |
12615 | this location on the global list, and try to | |
12616 | remove it next time, but there's no particular | |
12617 | reason why we will succeed next time. | |
20874c92 | 12618 | |
4a64f543 MS |
12619 | Note that at this point, old_loc->owner is still |
12620 | valid, as delete_breakpoint frees the breakpoint | |
12621 | only after calling us. */ | |
3e43a32a MS |
12622 | printf_filtered (_("warning: Error removing " |
12623 | "breakpoint %d\n"), | |
876fa593 | 12624 | old_loc->owner->number); |
20874c92 VP |
12625 | } |
12626 | removed = 1; | |
12627 | } | |
0d381245 | 12628 | } |
74960c60 VP |
12629 | |
12630 | if (!found_object) | |
1c5cfe86 | 12631 | { |
fbea99ea | 12632 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12633 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12634 | { |
db82e815 PA |
12635 | /* This location was removed from the target. In |
12636 | non-stop mode, a race condition is possible where | |
12637 | we've removed a breakpoint, but stop events for that | |
12638 | breakpoint are already queued and will arrive later. | |
12639 | We apply an heuristic to be able to distinguish such | |
12640 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12641 | breakpoint location for a bit, and will retire it | |
12642 | after we see some number of events. The theory here | |
12643 | is that reporting of events should, "on the average", | |
12644 | be fair, so after a while we'll see events from all | |
12645 | threads that have anything of interest, and no longer | |
12646 | need to keep this breakpoint location around. We | |
12647 | don't hold locations forever so to reduce chances of | |
12648 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12649 | SIGTRAP. | |
12650 | ||
12651 | The heuristic failing can be disastrous on | |
12652 | decr_pc_after_break targets. | |
12653 | ||
12654 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12655 | if we fail to recognize a late breakpoint SIGTRAP, | |
12656 | because events_till_retirement has reached 0 too | |
12657 | soon, we'll fail to do the PC adjustment, and report | |
12658 | a random SIGTRAP to the user. When the user resumes | |
12659 | the inferior, it will most likely immediately crash | |
2dec564e | 12660 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12661 | corrupted, because of being resumed e.g., in the |
12662 | middle of a multi-byte instruction, or skipped a | |
12663 | one-byte instruction. This was actually seen happen | |
12664 | on native x86-linux, and should be less rare on | |
12665 | targets that do not support new thread events, like | |
12666 | remote, due to the heuristic depending on | |
12667 | thread_count. | |
12668 | ||
12669 | Mistaking a random SIGTRAP for a breakpoint trap | |
12670 | causes similar symptoms (PC adjustment applied when | |
12671 | it shouldn't), but then again, playing with SIGTRAPs | |
12672 | behind the debugger's back is asking for trouble. | |
12673 | ||
12674 | Since hardware watchpoint traps are always | |
12675 | distinguishable from other traps, so we don't need to | |
12676 | apply keep hardware watchpoint moribund locations | |
12677 | around. We simply always ignore hardware watchpoint | |
12678 | traps we can no longer explain. */ | |
12679 | ||
876fa593 JK |
12680 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12681 | old_loc->owner = NULL; | |
20874c92 | 12682 | |
876fa593 | 12683 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12684 | } |
12685 | else | |
f431efe5 PA |
12686 | { |
12687 | old_loc->owner = NULL; | |
12688 | decref_bp_location (&old_loc); | |
12689 | } | |
20874c92 | 12690 | } |
74960c60 | 12691 | } |
1c5cfe86 | 12692 | |
348d480f PA |
12693 | /* Rescan breakpoints at the same address and section, marking the |
12694 | first one as "first" and any others as "duplicates". This is so | |
12695 | that the bpt instruction is only inserted once. If we have a | |
12696 | permanent breakpoint at the same place as BPT, make that one the | |
12697 | official one, and the rest as duplicates. Permanent breakpoints | |
12698 | are sorted first for the same address. | |
12699 | ||
12700 | Do the same for hardware watchpoints, but also considering the | |
12701 | watchpoint's type (regular/access/read) and length. */ | |
12702 | ||
12703 | bp_loc_first = NULL; | |
12704 | wp_loc_first = NULL; | |
12705 | awp_loc_first = NULL; | |
12706 | rwp_loc_first = NULL; | |
12707 | ALL_BP_LOCATIONS (loc, locp) | |
12708 | { | |
12709 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12710 | non-NULL. */ | |
348d480f | 12711 | struct bp_location **loc_first_p; |
d3fbdd86 | 12712 | b = loc->owner; |
348d480f | 12713 | |
6f380991 | 12714 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12715 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12716 | /* Don't detect duplicate for tracepoint locations because they are |
12717 | never duplicated. See the comments in field `duplicate' of | |
12718 | `struct bp_location'. */ | |
348d480f | 12719 | || is_tracepoint (b)) |
b775012e LM |
12720 | { |
12721 | /* Clear the condition modification flag. */ | |
12722 | loc->condition_changed = condition_unchanged; | |
12723 | continue; | |
12724 | } | |
348d480f | 12725 | |
348d480f PA |
12726 | if (b->type == bp_hardware_watchpoint) |
12727 | loc_first_p = &wp_loc_first; | |
12728 | else if (b->type == bp_read_watchpoint) | |
12729 | loc_first_p = &rwp_loc_first; | |
12730 | else if (b->type == bp_access_watchpoint) | |
12731 | loc_first_p = &awp_loc_first; | |
12732 | else | |
12733 | loc_first_p = &bp_loc_first; | |
12734 | ||
12735 | if (*loc_first_p == NULL | |
12736 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12737 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12738 | { | |
12739 | *loc_first_p = loc; | |
12740 | loc->duplicate = 0; | |
b775012e LM |
12741 | |
12742 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12743 | { | |
12744 | loc->needs_update = 1; | |
12745 | /* Clear the condition modification flag. */ | |
12746 | loc->condition_changed = condition_unchanged; | |
12747 | } | |
348d480f PA |
12748 | continue; |
12749 | } | |
12750 | ||
934709f0 PW |
12751 | |
12752 | /* This and the above ensure the invariant that the first location | |
12753 | is not duplicated, and is the inserted one. | |
12754 | All following are marked as duplicated, and are not inserted. */ | |
12755 | if (loc->inserted) | |
12756 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12757 | loc->duplicate = 1; |
12758 | ||
b775012e LM |
12759 | /* Clear the condition modification flag. */ |
12760 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12761 | } |
12762 | ||
a25a5a45 | 12763 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12764 | { |
04086b45 | 12765 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12766 | insert_breakpoint_locations (); |
12767 | else | |
12768 | { | |
44702360 PA |
12769 | /* Even though the caller told us to not insert new |
12770 | locations, we may still need to update conditions on the | |
12771 | target's side of breakpoints that were already inserted | |
12772 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12773 | only update conditions for locations that are marked |
12774 | "needs_update". */ | |
12775 | update_inserted_breakpoint_locations (); | |
12776 | } | |
12777 | } | |
348d480f | 12778 | |
04086b45 | 12779 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12780 | download_tracepoint_locations (); |
12781 | ||
348d480f PA |
12782 | do_cleanups (cleanups); |
12783 | } | |
12784 | ||
12785 | void | |
12786 | breakpoint_retire_moribund (void) | |
12787 | { | |
12788 | struct bp_location *loc; | |
12789 | int ix; | |
12790 | ||
12791 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12792 | if (--(loc->events_till_retirement) == 0) | |
12793 | { | |
12794 | decref_bp_location (&loc); | |
12795 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12796 | --ix; | |
12797 | } | |
12798 | } | |
12799 | ||
12800 | static void | |
44702360 | 12801 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12802 | { |
348d480f | 12803 | |
492d29ea PA |
12804 | TRY |
12805 | { | |
12806 | update_global_location_list (insert_mode); | |
12807 | } | |
12808 | CATCH (e, RETURN_MASK_ERROR) | |
12809 | { | |
12810 | } | |
12811 | END_CATCH | |
348d480f PA |
12812 | } |
12813 | ||
12814 | /* Clear BKP from a BPS. */ | |
12815 | ||
12816 | static void | |
12817 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12818 | { | |
12819 | bpstat bs; | |
12820 | ||
12821 | for (bs = bps; bs; bs = bs->next) | |
12822 | if (bs->breakpoint_at == bpt) | |
12823 | { | |
12824 | bs->breakpoint_at = NULL; | |
12825 | bs->old_val = NULL; | |
12826 | /* bs->commands will be freed later. */ | |
12827 | } | |
12828 | } | |
12829 | ||
12830 | /* Callback for iterate_over_threads. */ | |
12831 | static int | |
12832 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12833 | { | |
9a3c8263 | 12834 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12835 | |
12836 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12837 | return 0; | |
12838 | } | |
12839 | ||
12840 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12841 | callbacks. */ | |
12842 | ||
12843 | static void | |
12844 | say_where (struct breakpoint *b) | |
12845 | { | |
12846 | struct value_print_options opts; | |
12847 | ||
12848 | get_user_print_options (&opts); | |
12849 | ||
12850 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12851 | single string. */ | |
12852 | if (b->loc == NULL) | |
12853 | { | |
f00aae0f KS |
12854 | /* For pending locations, the output differs slightly based |
12855 | on b->extra_string. If this is non-NULL, it contains either | |
12856 | a condition or dprintf arguments. */ | |
12857 | if (b->extra_string == NULL) | |
12858 | { | |
12859 | printf_filtered (_(" (%s) pending."), | |
12860 | event_location_to_string (b->location)); | |
12861 | } | |
12862 | else if (b->type == bp_dprintf) | |
12863 | { | |
12864 | printf_filtered (_(" (%s,%s) pending."), | |
12865 | event_location_to_string (b->location), | |
12866 | b->extra_string); | |
12867 | } | |
12868 | else | |
12869 | { | |
12870 | printf_filtered (_(" (%s %s) pending."), | |
12871 | event_location_to_string (b->location), | |
12872 | b->extra_string); | |
12873 | } | |
348d480f PA |
12874 | } |
12875 | else | |
12876 | { | |
2f202fde | 12877 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12878 | { |
12879 | printf_filtered (" at "); | |
12880 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12881 | gdb_stdout); | |
12882 | } | |
2f202fde | 12883 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12884 | { |
12885 | /* If there is a single location, we can print the location | |
12886 | more nicely. */ | |
12887 | if (b->loc->next == NULL) | |
12888 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12889 | symtab_to_filename_for_display (b->loc->symtab), |
12890 | b->loc->line_number); | |
f8eba3c6 TT |
12891 | else |
12892 | /* This is not ideal, but each location may have a | |
12893 | different file name, and this at least reflects the | |
12894 | real situation somewhat. */ | |
f00aae0f KS |
12895 | printf_filtered (": %s.", |
12896 | event_location_to_string (b->location)); | |
f8eba3c6 | 12897 | } |
348d480f PA |
12898 | |
12899 | if (b->loc->next) | |
12900 | { | |
12901 | struct bp_location *loc = b->loc; | |
12902 | int n = 0; | |
12903 | for (; loc; loc = loc->next) | |
12904 | ++n; | |
12905 | printf_filtered (" (%d locations)", n); | |
12906 | } | |
12907 | } | |
12908 | } | |
12909 | ||
348d480f PA |
12910 | /* Default bp_location_ops methods. */ |
12911 | ||
12912 | static void | |
12913 | bp_location_dtor (struct bp_location *self) | |
12914 | { | |
12915 | xfree (self->cond); | |
b775012e LM |
12916 | if (self->cond_bytecode) |
12917 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12918 | xfree (self->function_name); |
8b4f3082 PA |
12919 | |
12920 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12921 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12922 | } |
12923 | ||
12924 | static const struct bp_location_ops bp_location_ops = | |
12925 | { | |
12926 | bp_location_dtor | |
12927 | }; | |
12928 | ||
2060206e PA |
12929 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12930 | inherit from. */ | |
348d480f | 12931 | |
2060206e PA |
12932 | static void |
12933 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12934 | { |
12935 | decref_counted_command_line (&self->commands); | |
12936 | xfree (self->cond_string); | |
fb81d016 | 12937 | xfree (self->extra_string); |
f8eba3c6 | 12938 | xfree (self->filter); |
f00aae0f KS |
12939 | delete_event_location (self->location); |
12940 | delete_event_location (self->location_range_end); | |
348d480f PA |
12941 | } |
12942 | ||
2060206e PA |
12943 | static struct bp_location * |
12944 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12945 | { |
12946 | struct bp_location *loc; | |
12947 | ||
12948 | loc = XNEW (struct bp_location); | |
12949 | init_bp_location (loc, &bp_location_ops, self); | |
12950 | return loc; | |
12951 | } | |
12952 | ||
2060206e PA |
12953 | static void |
12954 | base_breakpoint_re_set (struct breakpoint *b) | |
12955 | { | |
12956 | /* Nothing to re-set. */ | |
12957 | } | |
12958 | ||
12959 | #define internal_error_pure_virtual_called() \ | |
12960 | gdb_assert_not_reached ("pure virtual function called") | |
12961 | ||
12962 | static int | |
12963 | base_breakpoint_insert_location (struct bp_location *bl) | |
12964 | { | |
12965 | internal_error_pure_virtual_called (); | |
12966 | } | |
12967 | ||
12968 | static int | |
12969 | base_breakpoint_remove_location (struct bp_location *bl) | |
12970 | { | |
12971 | internal_error_pure_virtual_called (); | |
12972 | } | |
12973 | ||
12974 | static int | |
12975 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12976 | struct address_space *aspace, | |
09ac7c10 TT |
12977 | CORE_ADDR bp_addr, |
12978 | const struct target_waitstatus *ws) | |
2060206e PA |
12979 | { |
12980 | internal_error_pure_virtual_called (); | |
12981 | } | |
12982 | ||
12983 | static void | |
12984 | base_breakpoint_check_status (bpstat bs) | |
12985 | { | |
12986 | /* Always stop. */ | |
12987 | } | |
12988 | ||
12989 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12990 | errors. */ | |
12991 | ||
12992 | static int | |
12993 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12994 | { | |
12995 | internal_error_pure_virtual_called (); | |
12996 | } | |
12997 | ||
12998 | /* A "resources_needed" breakpoint_ops method that just internal | |
12999 | errors. */ | |
13000 | ||
13001 | static int | |
13002 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13003 | { | |
13004 | internal_error_pure_virtual_called (); | |
13005 | } | |
13006 | ||
13007 | static enum print_stop_action | |
13008 | base_breakpoint_print_it (bpstat bs) | |
13009 | { | |
13010 | internal_error_pure_virtual_called (); | |
13011 | } | |
13012 | ||
13013 | static void | |
13014 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13015 | struct ui_out *uiout) | |
13016 | { | |
13017 | /* nothing */ | |
13018 | } | |
13019 | ||
13020 | static void | |
13021 | base_breakpoint_print_mention (struct breakpoint *b) | |
13022 | { | |
13023 | internal_error_pure_virtual_called (); | |
13024 | } | |
13025 | ||
13026 | static void | |
13027 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13028 | { | |
13029 | internal_error_pure_virtual_called (); | |
13030 | } | |
13031 | ||
983af33b | 13032 | static void |
f00aae0f KS |
13033 | base_breakpoint_create_sals_from_location |
13034 | (const struct event_location *location, | |
13035 | struct linespec_result *canonical, | |
13036 | enum bptype type_wanted) | |
983af33b SDJ |
13037 | { |
13038 | internal_error_pure_virtual_called (); | |
13039 | } | |
13040 | ||
13041 | static void | |
13042 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13043 | struct linespec_result *c, | |
983af33b | 13044 | char *cond_string, |
e7e0cddf | 13045 | char *extra_string, |
983af33b SDJ |
13046 | enum bptype type_wanted, |
13047 | enum bpdisp disposition, | |
13048 | int thread, | |
13049 | int task, int ignore_count, | |
13050 | const struct breakpoint_ops *o, | |
13051 | int from_tty, int enabled, | |
44f238bb | 13052 | int internal, unsigned flags) |
983af33b SDJ |
13053 | { |
13054 | internal_error_pure_virtual_called (); | |
13055 | } | |
13056 | ||
13057 | static void | |
f00aae0f KS |
13058 | base_breakpoint_decode_location (struct breakpoint *b, |
13059 | const struct event_location *location, | |
c2f4122d | 13060 | struct program_space *search_pspace, |
983af33b SDJ |
13061 | struct symtabs_and_lines *sals) |
13062 | { | |
13063 | internal_error_pure_virtual_called (); | |
13064 | } | |
13065 | ||
ab04a2af TT |
13066 | /* The default 'explains_signal' method. */ |
13067 | ||
47591c29 | 13068 | static int |
427cd150 | 13069 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13070 | { |
47591c29 | 13071 | return 1; |
ab04a2af TT |
13072 | } |
13073 | ||
9d6e6e84 HZ |
13074 | /* The default "after_condition_true" method. */ |
13075 | ||
13076 | static void | |
13077 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13078 | { | |
13079 | /* Nothing to do. */ | |
13080 | } | |
13081 | ||
ab04a2af | 13082 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13083 | { |
13084 | base_breakpoint_dtor, | |
13085 | base_breakpoint_allocate_location, | |
13086 | base_breakpoint_re_set, | |
13087 | base_breakpoint_insert_location, | |
13088 | base_breakpoint_remove_location, | |
13089 | base_breakpoint_breakpoint_hit, | |
13090 | base_breakpoint_check_status, | |
13091 | base_breakpoint_resources_needed, | |
13092 | base_breakpoint_works_in_software_mode, | |
13093 | base_breakpoint_print_it, | |
13094 | NULL, | |
13095 | base_breakpoint_print_one_detail, | |
13096 | base_breakpoint_print_mention, | |
983af33b | 13097 | base_breakpoint_print_recreate, |
5f700d83 | 13098 | base_breakpoint_create_sals_from_location, |
983af33b | 13099 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13100 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13101 | base_breakpoint_explains_signal, |
13102 | base_breakpoint_after_condition_true, | |
2060206e PA |
13103 | }; |
13104 | ||
13105 | /* Default breakpoint_ops methods. */ | |
13106 | ||
13107 | static void | |
348d480f PA |
13108 | bkpt_re_set (struct breakpoint *b) |
13109 | { | |
06edf0c0 | 13110 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13111 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13112 | { |
f00aae0f | 13113 | /* Anything without a location can't be re-set. */ |
348d480f | 13114 | delete_breakpoint (b); |
06edf0c0 | 13115 | return; |
348d480f | 13116 | } |
06edf0c0 PA |
13117 | |
13118 | breakpoint_re_set_default (b); | |
348d480f PA |
13119 | } |
13120 | ||
2060206e | 13121 | static int |
348d480f PA |
13122 | bkpt_insert_location (struct bp_location *bl) |
13123 | { | |
13124 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13125 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13126 | else |
7c16b83e | 13127 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13128 | } |
13129 | ||
2060206e | 13130 | static int |
348d480f PA |
13131 | bkpt_remove_location (struct bp_location *bl) |
13132 | { | |
13133 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13134 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13135 | else | |
7c16b83e | 13136 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13137 | } |
13138 | ||
2060206e | 13139 | static int |
348d480f | 13140 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13141 | struct address_space *aspace, CORE_ADDR bp_addr, |
13142 | const struct target_waitstatus *ws) | |
348d480f | 13143 | { |
09ac7c10 | 13144 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13145 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13146 | return 0; |
13147 | ||
348d480f PA |
13148 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13149 | aspace, bp_addr)) | |
13150 | return 0; | |
13151 | ||
13152 | if (overlay_debugging /* unmapped overlay section */ | |
13153 | && section_is_overlay (bl->section) | |
13154 | && !section_is_mapped (bl->section)) | |
13155 | return 0; | |
13156 | ||
13157 | return 1; | |
13158 | } | |
13159 | ||
cd1608cc PA |
13160 | static int |
13161 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13162 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13163 | const struct target_waitstatus *ws) | |
13164 | { | |
13165 | if (dprintf_style == dprintf_style_agent | |
13166 | && target_can_run_breakpoint_commands ()) | |
13167 | { | |
13168 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13169 | for this address it must be for a breakpoint that happens to | |
13170 | be set at the same address. */ | |
13171 | return 0; | |
13172 | } | |
13173 | ||
13174 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13175 | } | |
13176 | ||
2060206e | 13177 | static int |
348d480f PA |
13178 | bkpt_resources_needed (const struct bp_location *bl) |
13179 | { | |
13180 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13181 | ||
13182 | return 1; | |
13183 | } | |
13184 | ||
2060206e | 13185 | static enum print_stop_action |
348d480f PA |
13186 | bkpt_print_it (bpstat bs) |
13187 | { | |
348d480f PA |
13188 | struct breakpoint *b; |
13189 | const struct bp_location *bl; | |
001c8c33 | 13190 | int bp_temp; |
79a45e25 | 13191 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13192 | |
13193 | gdb_assert (bs->bp_location_at != NULL); | |
13194 | ||
13195 | bl = bs->bp_location_at; | |
13196 | b = bs->breakpoint_at; | |
13197 | ||
001c8c33 PA |
13198 | bp_temp = b->disposition == disp_del; |
13199 | if (bl->address != bl->requested_address) | |
13200 | breakpoint_adjustment_warning (bl->requested_address, | |
13201 | bl->address, | |
13202 | b->number, 1); | |
13203 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13204 | maybe_print_thread_hit_breakpoint (uiout); |
13205 | ||
001c8c33 | 13206 | if (bp_temp) |
f303dbd6 | 13207 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13208 | else |
f303dbd6 | 13209 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13210 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13211 | { |
001c8c33 PA |
13212 | ui_out_field_string (uiout, "reason", |
13213 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13214 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13215 | } |
001c8c33 PA |
13216 | ui_out_field_int (uiout, "bkptno", b->number); |
13217 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13218 | |
001c8c33 | 13219 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13220 | } |
13221 | ||
2060206e | 13222 | static void |
06edf0c0 PA |
13223 | bkpt_print_mention (struct breakpoint *b) |
13224 | { | |
79a45e25 | 13225 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13226 | return; |
13227 | ||
13228 | switch (b->type) | |
13229 | { | |
13230 | case bp_breakpoint: | |
13231 | case bp_gnu_ifunc_resolver: | |
13232 | if (b->disposition == disp_del) | |
13233 | printf_filtered (_("Temporary breakpoint")); | |
13234 | else | |
13235 | printf_filtered (_("Breakpoint")); | |
13236 | printf_filtered (_(" %d"), b->number); | |
13237 | if (b->type == bp_gnu_ifunc_resolver) | |
13238 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13239 | break; | |
13240 | case bp_hardware_breakpoint: | |
13241 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13242 | break; | |
e7e0cddf SS |
13243 | case bp_dprintf: |
13244 | printf_filtered (_("Dprintf %d"), b->number); | |
13245 | break; | |
06edf0c0 PA |
13246 | } |
13247 | ||
13248 | say_where (b); | |
13249 | } | |
13250 | ||
2060206e | 13251 | static void |
06edf0c0 PA |
13252 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13253 | { | |
13254 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13255 | fprintf_unfiltered (fp, "tbreak"); | |
13256 | else if (tp->type == bp_breakpoint) | |
13257 | fprintf_unfiltered (fp, "break"); | |
13258 | else if (tp->type == bp_hardware_breakpoint | |
13259 | && tp->disposition == disp_del) | |
13260 | fprintf_unfiltered (fp, "thbreak"); | |
13261 | else if (tp->type == bp_hardware_breakpoint) | |
13262 | fprintf_unfiltered (fp, "hbreak"); | |
13263 | else | |
13264 | internal_error (__FILE__, __LINE__, | |
13265 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13266 | ||
f00aae0f KS |
13267 | fprintf_unfiltered (fp, " %s", |
13268 | event_location_to_string (tp->location)); | |
13269 | ||
13270 | /* Print out extra_string if this breakpoint is pending. It might | |
13271 | contain, for example, conditions that were set by the user. */ | |
13272 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13273 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13274 | ||
dd11a36c | 13275 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13276 | } |
13277 | ||
983af33b | 13278 | static void |
f00aae0f KS |
13279 | bkpt_create_sals_from_location (const struct event_location *location, |
13280 | struct linespec_result *canonical, | |
13281 | enum bptype type_wanted) | |
983af33b | 13282 | { |
f00aae0f | 13283 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13284 | } |
13285 | ||
13286 | static void | |
13287 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13288 | struct linespec_result *canonical, | |
983af33b | 13289 | char *cond_string, |
e7e0cddf | 13290 | char *extra_string, |
983af33b SDJ |
13291 | enum bptype type_wanted, |
13292 | enum bpdisp disposition, | |
13293 | int thread, | |
13294 | int task, int ignore_count, | |
13295 | const struct breakpoint_ops *ops, | |
13296 | int from_tty, int enabled, | |
44f238bb | 13297 | int internal, unsigned flags) |
983af33b | 13298 | { |
023fa29b | 13299 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13300 | cond_string, extra_string, |
13301 | type_wanted, | |
983af33b SDJ |
13302 | disposition, thread, task, |
13303 | ignore_count, ops, from_tty, | |
44f238bb | 13304 | enabled, internal, flags); |
983af33b SDJ |
13305 | } |
13306 | ||
13307 | static void | |
f00aae0f KS |
13308 | bkpt_decode_location (struct breakpoint *b, |
13309 | const struct event_location *location, | |
c2f4122d | 13310 | struct program_space *search_pspace, |
983af33b SDJ |
13311 | struct symtabs_and_lines *sals) |
13312 | { | |
c2f4122d | 13313 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13314 | } |
13315 | ||
06edf0c0 PA |
13316 | /* Virtual table for internal breakpoints. */ |
13317 | ||
13318 | static void | |
13319 | internal_bkpt_re_set (struct breakpoint *b) | |
13320 | { | |
13321 | switch (b->type) | |
13322 | { | |
13323 | /* Delete overlay event and longjmp master breakpoints; they | |
13324 | will be reset later by breakpoint_re_set. */ | |
13325 | case bp_overlay_event: | |
13326 | case bp_longjmp_master: | |
13327 | case bp_std_terminate_master: | |
13328 | case bp_exception_master: | |
13329 | delete_breakpoint (b); | |
13330 | break; | |
13331 | ||
13332 | /* This breakpoint is special, it's set up when the inferior | |
13333 | starts and we really don't want to touch it. */ | |
13334 | case bp_shlib_event: | |
13335 | ||
13336 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13337 | it is set up, we do not want to touch it. */ | |
13338 | case bp_thread_event: | |
13339 | break; | |
13340 | } | |
13341 | } | |
13342 | ||
13343 | static void | |
13344 | internal_bkpt_check_status (bpstat bs) | |
13345 | { | |
a9b3a50f PA |
13346 | if (bs->breakpoint_at->type == bp_shlib_event) |
13347 | { | |
13348 | /* If requested, stop when the dynamic linker notifies GDB of | |
13349 | events. This allows the user to get control and place | |
13350 | breakpoints in initializer routines for dynamically loaded | |
13351 | objects (among other things). */ | |
13352 | bs->stop = stop_on_solib_events; | |
13353 | bs->print = stop_on_solib_events; | |
13354 | } | |
13355 | else | |
13356 | bs->stop = 0; | |
06edf0c0 PA |
13357 | } |
13358 | ||
13359 | static enum print_stop_action | |
13360 | internal_bkpt_print_it (bpstat bs) | |
13361 | { | |
06edf0c0 | 13362 | struct breakpoint *b; |
06edf0c0 | 13363 | |
06edf0c0 PA |
13364 | b = bs->breakpoint_at; |
13365 | ||
06edf0c0 PA |
13366 | switch (b->type) |
13367 | { | |
348d480f PA |
13368 | case bp_shlib_event: |
13369 | /* Did we stop because the user set the stop_on_solib_events | |
13370 | variable? (If so, we report this as a generic, "Stopped due | |
13371 | to shlib event" message.) */ | |
edcc5120 | 13372 | print_solib_event (0); |
348d480f PA |
13373 | break; |
13374 | ||
13375 | case bp_thread_event: | |
13376 | /* Not sure how we will get here. | |
13377 | GDB should not stop for these breakpoints. */ | |
13378 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13379 | break; |
13380 | ||
13381 | case bp_overlay_event: | |
13382 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13383 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13384 | break; |
13385 | ||
13386 | case bp_longjmp_master: | |
13387 | /* These should never be enabled. */ | |
13388 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13389 | break; |
13390 | ||
13391 | case bp_std_terminate_master: | |
13392 | /* These should never be enabled. */ | |
13393 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13394 | "gdb should not stop!\n")); | |
348d480f PA |
13395 | break; |
13396 | ||
13397 | case bp_exception_master: | |
13398 | /* These should never be enabled. */ | |
13399 | printf_filtered (_("Exception Master Breakpoint: " | |
13400 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13401 | break; |
13402 | } | |
13403 | ||
001c8c33 | 13404 | return PRINT_NOTHING; |
06edf0c0 PA |
13405 | } |
13406 | ||
13407 | static void | |
13408 | internal_bkpt_print_mention (struct breakpoint *b) | |
13409 | { | |
13410 | /* Nothing to mention. These breakpoints are internal. */ | |
13411 | } | |
13412 | ||
06edf0c0 PA |
13413 | /* Virtual table for momentary breakpoints */ |
13414 | ||
13415 | static void | |
13416 | momentary_bkpt_re_set (struct breakpoint *b) | |
13417 | { | |
13418 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13419 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13420 | Otherwise these should have been blown away via the cleanup chain |
13421 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13422 | } | |
13423 | ||
13424 | static void | |
13425 | momentary_bkpt_check_status (bpstat bs) | |
13426 | { | |
13427 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13428 | } | |
13429 | ||
13430 | static enum print_stop_action | |
13431 | momentary_bkpt_print_it (bpstat bs) | |
13432 | { | |
001c8c33 | 13433 | return PRINT_UNKNOWN; |
348d480f PA |
13434 | } |
13435 | ||
06edf0c0 PA |
13436 | static void |
13437 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13438 | { |
06edf0c0 | 13439 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13440 | } |
13441 | ||
e2e4d78b JK |
13442 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13443 | ||
13444 | It gets cleared already on the removal of the first one of such placed | |
13445 | breakpoints. This is OK as they get all removed altogether. */ | |
13446 | ||
13447 | static void | |
13448 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13449 | { | |
5d5658a1 | 13450 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13451 | |
13452 | if (tp) | |
13453 | tp->initiating_frame = null_frame_id; | |
13454 | ||
13455 | momentary_breakpoint_ops.dtor (self); | |
13456 | } | |
13457 | ||
55aa24fb SDJ |
13458 | /* Specific methods for probe breakpoints. */ |
13459 | ||
13460 | static int | |
13461 | bkpt_probe_insert_location (struct bp_location *bl) | |
13462 | { | |
13463 | int v = bkpt_insert_location (bl); | |
13464 | ||
13465 | if (v == 0) | |
13466 | { | |
13467 | /* The insertion was successful, now let's set the probe's semaphore | |
13468 | if needed. */ | |
0ea5cda8 SDJ |
13469 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13470 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13471 | bl->probe.objfile, | |
13472 | bl->gdbarch); | |
55aa24fb SDJ |
13473 | } |
13474 | ||
13475 | return v; | |
13476 | } | |
13477 | ||
13478 | static int | |
13479 | bkpt_probe_remove_location (struct bp_location *bl) | |
13480 | { | |
13481 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13482 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13483 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13484 | bl->probe.objfile, | |
13485 | bl->gdbarch); | |
55aa24fb SDJ |
13486 | |
13487 | return bkpt_remove_location (bl); | |
13488 | } | |
13489 | ||
13490 | static void | |
f00aae0f | 13491 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13492 | struct linespec_result *canonical, |
f00aae0f | 13493 | enum bptype type_wanted) |
55aa24fb SDJ |
13494 | { |
13495 | struct linespec_sals lsal; | |
13496 | ||
c2f4122d | 13497 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13498 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13499 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13500 | } | |
13501 | ||
13502 | static void | |
f00aae0f KS |
13503 | bkpt_probe_decode_location (struct breakpoint *b, |
13504 | const struct event_location *location, | |
c2f4122d | 13505 | struct program_space *search_pspace, |
55aa24fb SDJ |
13506 | struct symtabs_and_lines *sals) |
13507 | { | |
c2f4122d | 13508 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13509 | if (!sals->sals) |
13510 | error (_("probe not found")); | |
13511 | } | |
13512 | ||
348d480f | 13513 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13514 | |
348d480f PA |
13515 | static void |
13516 | tracepoint_re_set (struct breakpoint *b) | |
13517 | { | |
13518 | breakpoint_re_set_default (b); | |
13519 | } | |
876fa593 | 13520 | |
348d480f PA |
13521 | static int |
13522 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13523 | struct address_space *aspace, CORE_ADDR bp_addr, |
13524 | const struct target_waitstatus *ws) | |
348d480f PA |
13525 | { |
13526 | /* By definition, the inferior does not report stops at | |
13527 | tracepoints. */ | |
13528 | return 0; | |
74960c60 VP |
13529 | } |
13530 | ||
13531 | static void | |
348d480f PA |
13532 | tracepoint_print_one_detail (const struct breakpoint *self, |
13533 | struct ui_out *uiout) | |
74960c60 | 13534 | { |
d9b3f62e PA |
13535 | struct tracepoint *tp = (struct tracepoint *) self; |
13536 | if (tp->static_trace_marker_id) | |
348d480f PA |
13537 | { |
13538 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13539 | |
348d480f PA |
13540 | ui_out_text (uiout, "\tmarker id is "); |
13541 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13542 | tp->static_trace_marker_id); |
348d480f PA |
13543 | ui_out_text (uiout, "\n"); |
13544 | } | |
0d381245 VP |
13545 | } |
13546 | ||
a474d7c2 | 13547 | static void |
348d480f | 13548 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13549 | { |
79a45e25 | 13550 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13551 | return; |
cc59ec59 | 13552 | |
348d480f PA |
13553 | switch (b->type) |
13554 | { | |
13555 | case bp_tracepoint: | |
13556 | printf_filtered (_("Tracepoint")); | |
13557 | printf_filtered (_(" %d"), b->number); | |
13558 | break; | |
13559 | case bp_fast_tracepoint: | |
13560 | printf_filtered (_("Fast tracepoint")); | |
13561 | printf_filtered (_(" %d"), b->number); | |
13562 | break; | |
13563 | case bp_static_tracepoint: | |
13564 | printf_filtered (_("Static tracepoint")); | |
13565 | printf_filtered (_(" %d"), b->number); | |
13566 | break; | |
13567 | default: | |
13568 | internal_error (__FILE__, __LINE__, | |
13569 | _("unhandled tracepoint type %d"), (int) b->type); | |
13570 | } | |
13571 | ||
13572 | say_where (b); | |
a474d7c2 PA |
13573 | } |
13574 | ||
348d480f | 13575 | static void |
d9b3f62e | 13576 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13577 | { |
d9b3f62e PA |
13578 | struct tracepoint *tp = (struct tracepoint *) self; |
13579 | ||
13580 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13581 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13582 | else if (self->type == bp_static_tracepoint) |
348d480f | 13583 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13584 | else if (self->type == bp_tracepoint) |
348d480f PA |
13585 | fprintf_unfiltered (fp, "trace"); |
13586 | else | |
13587 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13588 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13589 | |
f00aae0f KS |
13590 | fprintf_unfiltered (fp, " %s", |
13591 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13592 | print_recreate_thread (self, fp); |
13593 | ||
13594 | if (tp->pass_count) | |
13595 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13596 | } |
13597 | ||
983af33b | 13598 | static void |
f00aae0f KS |
13599 | tracepoint_create_sals_from_location (const struct event_location *location, |
13600 | struct linespec_result *canonical, | |
13601 | enum bptype type_wanted) | |
983af33b | 13602 | { |
f00aae0f | 13603 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13604 | } |
13605 | ||
13606 | static void | |
13607 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13608 | struct linespec_result *canonical, | |
983af33b | 13609 | char *cond_string, |
e7e0cddf | 13610 | char *extra_string, |
983af33b SDJ |
13611 | enum bptype type_wanted, |
13612 | enum bpdisp disposition, | |
13613 | int thread, | |
13614 | int task, int ignore_count, | |
13615 | const struct breakpoint_ops *ops, | |
13616 | int from_tty, int enabled, | |
44f238bb | 13617 | int internal, unsigned flags) |
983af33b | 13618 | { |
023fa29b | 13619 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13620 | cond_string, extra_string, |
13621 | type_wanted, | |
983af33b SDJ |
13622 | disposition, thread, task, |
13623 | ignore_count, ops, from_tty, | |
44f238bb | 13624 | enabled, internal, flags); |
983af33b SDJ |
13625 | } |
13626 | ||
13627 | static void | |
f00aae0f KS |
13628 | tracepoint_decode_location (struct breakpoint *b, |
13629 | const struct event_location *location, | |
c2f4122d | 13630 | struct program_space *search_pspace, |
983af33b SDJ |
13631 | struct symtabs_and_lines *sals) |
13632 | { | |
c2f4122d | 13633 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13634 | } |
13635 | ||
2060206e | 13636 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13637 | |
55aa24fb SDJ |
13638 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13639 | static probe. */ | |
13640 | ||
13641 | static void | |
f00aae0f KS |
13642 | tracepoint_probe_create_sals_from_location |
13643 | (const struct event_location *location, | |
13644 | struct linespec_result *canonical, | |
13645 | enum bptype type_wanted) | |
55aa24fb SDJ |
13646 | { |
13647 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13648 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13649 | } |
13650 | ||
13651 | static void | |
f00aae0f KS |
13652 | tracepoint_probe_decode_location (struct breakpoint *b, |
13653 | const struct event_location *location, | |
c2f4122d | 13654 | struct program_space *search_pspace, |
55aa24fb SDJ |
13655 | struct symtabs_and_lines *sals) |
13656 | { | |
13657 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13658 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13659 | } |
13660 | ||
13661 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13662 | ||
5c2b4418 HZ |
13663 | /* Dprintf breakpoint_ops methods. */ |
13664 | ||
13665 | static void | |
13666 | dprintf_re_set (struct breakpoint *b) | |
13667 | { | |
13668 | breakpoint_re_set_default (b); | |
13669 | ||
f00aae0f KS |
13670 | /* extra_string should never be non-NULL for dprintf. */ |
13671 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13672 | |
13673 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13674 | 2 - create a dprintf, which resolves fine. | |
13675 | 3 - disconnect from target 1 | |
13676 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13677 | ||
13678 | After steps #3/#4, you'll want the dprintf command list to | |
13679 | be updated, because target 1 and 2 may well return different | |
13680 | answers for target_can_run_breakpoint_commands(). | |
13681 | Given absence of finer grained resetting, we get to do | |
13682 | it all the time. */ | |
13683 | if (b->extra_string != NULL) | |
13684 | update_dprintf_command_list (b); | |
13685 | } | |
13686 | ||
2d9442cc HZ |
13687 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13688 | ||
13689 | static void | |
13690 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13691 | { | |
f00aae0f KS |
13692 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13693 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13694 | tp->extra_string); |
13695 | print_recreate_thread (tp, fp); | |
13696 | } | |
13697 | ||
9d6e6e84 HZ |
13698 | /* Implement the "after_condition_true" breakpoint_ops method for |
13699 | dprintf. | |
13700 | ||
13701 | dprintf's are implemented with regular commands in their command | |
13702 | list, but we run the commands here instead of before presenting the | |
13703 | stop to the user, as dprintf's don't actually cause a stop. This | |
13704 | also makes it so that the commands of multiple dprintfs at the same | |
13705 | address are all handled. */ | |
13706 | ||
13707 | static void | |
13708 | dprintf_after_condition_true (struct bpstats *bs) | |
13709 | { | |
13710 | struct cleanup *old_chain; | |
13711 | struct bpstats tmp_bs = { NULL }; | |
13712 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13713 | ||
13714 | /* dprintf's never cause a stop. This wasn't set in the | |
13715 | check_status hook instead because that would make the dprintf's | |
13716 | condition not be evaluated. */ | |
13717 | bs->stop = 0; | |
13718 | ||
13719 | /* Run the command list here. Take ownership of it instead of | |
13720 | copying. We never want these commands to run later in | |
13721 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13722 | be set at same address as this dprintf, or even if running the | |
13723 | commands here throws. */ | |
13724 | tmp_bs.commands = bs->commands; | |
13725 | bs->commands = NULL; | |
13726 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13727 | ||
13728 | bpstat_do_actions_1 (&tmp_bs_p); | |
13729 | ||
13730 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13731 | bpstat_do_actions_1 may return early without processing the whole | |
13732 | list. */ | |
13733 | do_cleanups (old_chain); | |
13734 | } | |
13735 | ||
983af33b SDJ |
13736 | /* The breakpoint_ops structure to be used on static tracepoints with |
13737 | markers (`-m'). */ | |
13738 | ||
13739 | static void | |
f00aae0f | 13740 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13741 | struct linespec_result *canonical, |
f00aae0f | 13742 | enum bptype type_wanted) |
983af33b SDJ |
13743 | { |
13744 | struct linespec_sals lsal; | |
f00aae0f KS |
13745 | const char *arg_start, *arg; |
13746 | char *str; | |
13747 | struct cleanup *cleanup; | |
983af33b | 13748 | |
f00aae0f KS |
13749 | arg = arg_start = get_linespec_location (location); |
13750 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13751 | |
f00aae0f KS |
13752 | str = savestring (arg_start, arg - arg_start); |
13753 | cleanup = make_cleanup (xfree, str); | |
13754 | canonical->location = new_linespec_location (&str); | |
13755 | do_cleanups (cleanup); | |
983af33b | 13756 | |
f00aae0f | 13757 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13758 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13759 | } | |
13760 | ||
13761 | static void | |
13762 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13763 | struct linespec_result *canonical, | |
983af33b | 13764 | char *cond_string, |
e7e0cddf | 13765 | char *extra_string, |
983af33b SDJ |
13766 | enum bptype type_wanted, |
13767 | enum bpdisp disposition, | |
13768 | int thread, | |
13769 | int task, int ignore_count, | |
13770 | const struct breakpoint_ops *ops, | |
13771 | int from_tty, int enabled, | |
44f238bb | 13772 | int internal, unsigned flags) |
983af33b SDJ |
13773 | { |
13774 | int i; | |
52d361e1 YQ |
13775 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13776 | canonical->sals, 0); | |
983af33b SDJ |
13777 | |
13778 | /* If the user is creating a static tracepoint by marker id | |
13779 | (strace -m MARKER_ID), then store the sals index, so that | |
13780 | breakpoint_re_set can try to match up which of the newly | |
13781 | found markers corresponds to this one, and, don't try to | |
13782 | expand multiple locations for each sal, given than SALS | |
13783 | already should contain all sals for MARKER_ID. */ | |
13784 | ||
13785 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13786 | { | |
13787 | struct symtabs_and_lines expanded; | |
13788 | struct tracepoint *tp; | |
13789 | struct cleanup *old_chain; | |
f00aae0f | 13790 | struct event_location *location; |
983af33b SDJ |
13791 | |
13792 | expanded.nelts = 1; | |
13793 | expanded.sals = &lsal->sals.sals[i]; | |
13794 | ||
f00aae0f KS |
13795 | location = copy_event_location (canonical->location); |
13796 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13797 | |
13798 | tp = XCNEW (struct tracepoint); | |
13799 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13800 | location, NULL, |
e7e0cddf SS |
13801 | cond_string, extra_string, |
13802 | type_wanted, disposition, | |
983af33b | 13803 | thread, task, ignore_count, ops, |
44f238bb | 13804 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13805 | canonical->special_display); |
13806 | /* Given that its possible to have multiple markers with | |
13807 | the same string id, if the user is creating a static | |
13808 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13809 | store the sals index, so that breakpoint_re_set can | |
13810 | try to match up which of the newly found markers | |
13811 | corresponds to this one */ | |
13812 | tp->static_trace_marker_id_idx = i; | |
13813 | ||
13814 | install_breakpoint (internal, &tp->base, 0); | |
13815 | ||
13816 | discard_cleanups (old_chain); | |
13817 | } | |
13818 | } | |
13819 | ||
13820 | static void | |
f00aae0f KS |
13821 | strace_marker_decode_location (struct breakpoint *b, |
13822 | const struct event_location *location, | |
c2f4122d | 13823 | struct program_space *search_pspace, |
983af33b SDJ |
13824 | struct symtabs_and_lines *sals) |
13825 | { | |
13826 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13827 | const char *s = get_linespec_location (location); |
983af33b | 13828 | |
f00aae0f | 13829 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13830 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13831 | { | |
13832 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13833 | sals->nelts = 1; | |
13834 | } | |
13835 | else | |
13836 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13837 | } | |
13838 | ||
13839 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13840 | ||
13841 | static int | |
13842 | strace_marker_p (struct breakpoint *b) | |
13843 | { | |
13844 | return b->ops == &strace_marker_breakpoint_ops; | |
13845 | } | |
13846 | ||
53a5351d | 13847 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13848 | structures. */ |
c906108c SS |
13849 | |
13850 | void | |
fba45db2 | 13851 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13852 | { |
52f0bd74 | 13853 | struct breakpoint *b; |
c906108c | 13854 | |
8a3fe4f8 | 13855 | gdb_assert (bpt != NULL); |
c906108c | 13856 | |
4a64f543 MS |
13857 | /* Has this bp already been deleted? This can happen because |
13858 | multiple lists can hold pointers to bp's. bpstat lists are | |
13859 | especial culprits. | |
13860 | ||
13861 | One example of this happening is a watchpoint's scope bp. When | |
13862 | the scope bp triggers, we notice that the watchpoint is out of | |
13863 | scope, and delete it. We also delete its scope bp. But the | |
13864 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13865 | That bpstat is then checked for auto-deleting bp's, which are | |
13866 | deleted. | |
13867 | ||
13868 | A real solution to this problem might involve reference counts in | |
13869 | bp's, and/or giving them pointers back to their referencing | |
13870 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13871 | storage when no more references were extent. A cheaper bandaid | |
13872 | was chosen. */ | |
c906108c SS |
13873 | if (bpt->type == bp_none) |
13874 | return; | |
13875 | ||
4a64f543 MS |
13876 | /* At least avoid this stale reference until the reference counting |
13877 | of breakpoints gets resolved. */ | |
d0fb5eae | 13878 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13879 | { |
d0fb5eae | 13880 | struct breakpoint *related; |
3a5c3e22 | 13881 | struct watchpoint *w; |
d0fb5eae JK |
13882 | |
13883 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13884 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13885 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13886 | w = (struct watchpoint *) bpt; |
13887 | else | |
13888 | w = NULL; | |
13889 | if (w != NULL) | |
13890 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13891 | |
13892 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13893 | for (related = bpt; related->related_breakpoint != bpt; | |
13894 | related = related->related_breakpoint); | |
13895 | related->related_breakpoint = bpt->related_breakpoint; | |
13896 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13897 | } |
13898 | ||
a9634178 TJB |
13899 | /* watch_command_1 creates a watchpoint but only sets its number if |
13900 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13901 | a problem in that process, we'll be asked to delete the half-created | |
13902 | watchpoint. In that case, don't announce the deletion. */ | |
13903 | if (bpt->number) | |
13904 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13905 | |
c906108c SS |
13906 | if (breakpoint_chain == bpt) |
13907 | breakpoint_chain = bpt->next; | |
13908 | ||
c906108c SS |
13909 | ALL_BREAKPOINTS (b) |
13910 | if (b->next == bpt) | |
c5aa993b JM |
13911 | { |
13912 | b->next = bpt->next; | |
13913 | break; | |
13914 | } | |
c906108c | 13915 | |
f431efe5 PA |
13916 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13917 | been freed. */ | |
13918 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13919 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13920 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13921 | commands are associated with the bpstat; if we remove it here, | |
13922 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13923 | event-top.c won't do anything, and temporary breakpoints with | |
13924 | commands won't work. */ | |
13925 | ||
13926 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13927 | ||
4a64f543 MS |
13928 | /* Now that breakpoint is removed from breakpoint list, update the |
13929 | global location list. This will remove locations that used to | |
13930 | belong to this breakpoint. Do this before freeing the breakpoint | |
13931 | itself, since remove_breakpoint looks at location's owner. It | |
13932 | might be better design to have location completely | |
13933 | self-contained, but it's not the case now. */ | |
44702360 | 13934 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13935 | |
348d480f | 13936 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13937 | /* On the chance that someone will soon try again to delete this |
13938 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13939 | bpt->type = bp_none; |
b8c9b27d | 13940 | xfree (bpt); |
c906108c SS |
13941 | } |
13942 | ||
4d6140d9 AC |
13943 | static void |
13944 | do_delete_breakpoint_cleanup (void *b) | |
13945 | { | |
9a3c8263 | 13946 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13947 | } |
13948 | ||
13949 | struct cleanup * | |
13950 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13951 | { | |
13952 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13953 | } | |
13954 | ||
51be5b68 PA |
13955 | /* Iterator function to call a user-provided callback function once |
13956 | for each of B and its related breakpoints. */ | |
13957 | ||
13958 | static void | |
13959 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13960 | void (*function) (struct breakpoint *, | |
13961 | void *), | |
13962 | void *data) | |
13963 | { | |
13964 | struct breakpoint *related; | |
13965 | ||
13966 | related = b; | |
13967 | do | |
13968 | { | |
13969 | struct breakpoint *next; | |
13970 | ||
13971 | /* FUNCTION may delete RELATED. */ | |
13972 | next = related->related_breakpoint; | |
13973 | ||
13974 | if (next == related) | |
13975 | { | |
13976 | /* RELATED is the last ring entry. */ | |
13977 | function (related, data); | |
13978 | ||
13979 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13980 | B. There's nothing left to do anyway, so just break | |
13981 | out. */ | |
13982 | break; | |
13983 | } | |
13984 | else | |
13985 | function (related, data); | |
13986 | ||
13987 | related = next; | |
13988 | } | |
13989 | while (related != b); | |
13990 | } | |
95a42b64 TT |
13991 | |
13992 | static void | |
13993 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13994 | { | |
13995 | delete_breakpoint (b); | |
13996 | } | |
13997 | ||
51be5b68 PA |
13998 | /* A callback for map_breakpoint_numbers that calls |
13999 | delete_breakpoint. */ | |
14000 | ||
14001 | static void | |
14002 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14003 | { | |
14004 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14005 | } | |
14006 | ||
c906108c | 14007 | void |
fba45db2 | 14008 | delete_command (char *arg, int from_tty) |
c906108c | 14009 | { |
35df4500 | 14010 | struct breakpoint *b, *b_tmp; |
c906108c | 14011 | |
ea9365bb TT |
14012 | dont_repeat (); |
14013 | ||
c906108c SS |
14014 | if (arg == 0) |
14015 | { | |
14016 | int breaks_to_delete = 0; | |
14017 | ||
46c6471b PA |
14018 | /* Delete all breakpoints if no argument. Do not delete |
14019 | internal breakpoints, these have to be deleted with an | |
14020 | explicit breakpoint number argument. */ | |
c5aa993b | 14021 | ALL_BREAKPOINTS (b) |
46c6471b | 14022 | if (user_breakpoint_p (b)) |
973d738b DJ |
14023 | { |
14024 | breaks_to_delete = 1; | |
14025 | break; | |
14026 | } | |
c906108c SS |
14027 | |
14028 | /* Ask user only if there are some breakpoints to delete. */ | |
14029 | if (!from_tty | |
e2e0b3e5 | 14030 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14031 | { |
35df4500 | 14032 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14033 | if (user_breakpoint_p (b)) |
c5aa993b | 14034 | delete_breakpoint (b); |
c906108c SS |
14035 | } |
14036 | } | |
14037 | else | |
51be5b68 | 14038 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14039 | } |
14040 | ||
c2f4122d PA |
14041 | /* Return true if all locations of B bound to PSPACE are pending. If |
14042 | PSPACE is NULL, all locations of all program spaces are | |
14043 | considered. */ | |
14044 | ||
0d381245 | 14045 | static int |
c2f4122d | 14046 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14047 | { |
c2f4122d PA |
14048 | struct bp_location *loc; |
14049 | ||
14050 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14051 | if ((pspace == NULL | |
14052 | || loc->pspace == pspace) | |
14053 | && !loc->shlib_disabled | |
8645ff69 | 14054 | && !loc->pspace->executing_startup) |
0d381245 VP |
14055 | return 0; |
14056 | return 1; | |
fe3f5fa8 VP |
14057 | } |
14058 | ||
776592bf DE |
14059 | /* Subroutine of update_breakpoint_locations to simplify it. |
14060 | Return non-zero if multiple fns in list LOC have the same name. | |
14061 | Null names are ignored. */ | |
14062 | ||
14063 | static int | |
14064 | ambiguous_names_p (struct bp_location *loc) | |
14065 | { | |
14066 | struct bp_location *l; | |
14067 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14068 | (int (*) (const void *, |
14069 | const void *)) streq, | |
776592bf DE |
14070 | NULL, xcalloc, xfree); |
14071 | ||
14072 | for (l = loc; l != NULL; l = l->next) | |
14073 | { | |
14074 | const char **slot; | |
14075 | const char *name = l->function_name; | |
14076 | ||
14077 | /* Allow for some names to be NULL, ignore them. */ | |
14078 | if (name == NULL) | |
14079 | continue; | |
14080 | ||
14081 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14082 | INSERT); | |
4a64f543 MS |
14083 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14084 | returns NULL. */ | |
776592bf DE |
14085 | if (*slot != NULL) |
14086 | { | |
14087 | htab_delete (htab); | |
14088 | return 1; | |
14089 | } | |
14090 | *slot = name; | |
14091 | } | |
14092 | ||
14093 | htab_delete (htab); | |
14094 | return 0; | |
14095 | } | |
14096 | ||
0fb4aa4b PA |
14097 | /* When symbols change, it probably means the sources changed as well, |
14098 | and it might mean the static tracepoint markers are no longer at | |
14099 | the same address or line numbers they used to be at last we | |
14100 | checked. Losing your static tracepoints whenever you rebuild is | |
14101 | undesirable. This function tries to resync/rematch gdb static | |
14102 | tracepoints with the markers on the target, for static tracepoints | |
14103 | that have not been set by marker id. Static tracepoint that have | |
14104 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14105 | The heuristic is: | |
14106 | ||
14107 | 1) For a tracepoint set at a specific address, look for a marker at | |
14108 | the old PC. If one is found there, assume to be the same marker. | |
14109 | If the name / string id of the marker found is different from the | |
14110 | previous known name, assume that means the user renamed the marker | |
14111 | in the sources, and output a warning. | |
14112 | ||
14113 | 2) For a tracepoint set at a given line number, look for a marker | |
14114 | at the new address of the old line number. If one is found there, | |
14115 | assume to be the same marker. If the name / string id of the | |
14116 | marker found is different from the previous known name, assume that | |
14117 | means the user renamed the marker in the sources, and output a | |
14118 | warning. | |
14119 | ||
14120 | 3) If a marker is no longer found at the same address or line, it | |
14121 | may mean the marker no longer exists. But it may also just mean | |
14122 | the code changed a bit. Maybe the user added a few lines of code | |
14123 | that made the marker move up or down (in line number terms). Ask | |
14124 | the target for info about the marker with the string id as we knew | |
14125 | it. If found, update line number and address in the matching | |
14126 | static tracepoint. This will get confused if there's more than one | |
14127 | marker with the same ID (possible in UST, although unadvised | |
14128 | precisely because it confuses tools). */ | |
14129 | ||
14130 | static struct symtab_and_line | |
14131 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14132 | { | |
d9b3f62e | 14133 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14134 | struct static_tracepoint_marker marker; |
14135 | CORE_ADDR pc; | |
0fb4aa4b PA |
14136 | |
14137 | pc = sal.pc; | |
14138 | if (sal.line) | |
14139 | find_line_pc (sal.symtab, sal.line, &pc); | |
14140 | ||
14141 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14142 | { | |
d9b3f62e | 14143 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14144 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14145 | b->number, | |
d9b3f62e | 14146 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14147 | |
d9b3f62e PA |
14148 | xfree (tp->static_trace_marker_id); |
14149 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14150 | release_static_tracepoint_marker (&marker); |
14151 | ||
14152 | return sal; | |
14153 | } | |
14154 | ||
14155 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14156 | by string ID. */ | |
14157 | if (!sal.explicit_pc | |
14158 | && sal.line != 0 | |
14159 | && sal.symtab != NULL | |
d9b3f62e | 14160 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14161 | { |
14162 | VEC(static_tracepoint_marker_p) *markers; | |
14163 | ||
14164 | markers | |
d9b3f62e | 14165 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14166 | |
14167 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14168 | { | |
80e1d417 | 14169 | struct symtab_and_line sal2; |
0fb4aa4b | 14170 | struct symbol *sym; |
80e1d417 | 14171 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14172 | struct ui_out *uiout = current_uiout; |
67994074 | 14173 | struct explicit_location explicit_loc; |
0fb4aa4b | 14174 | |
80e1d417 | 14175 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14176 | |
d9b3f62e | 14177 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14178 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14179 | |
14180 | warning (_("marker for static tracepoint %d (%s) not " | |
14181 | "found at previous line number"), | |
d9b3f62e | 14182 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14183 | |
80e1d417 | 14184 | init_sal (&sal2); |
0fb4aa4b | 14185 | |
80e1d417 | 14186 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14187 | |
80e1d417 AS |
14188 | sal2 = find_pc_line (tpmarker->address, 0); |
14189 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14190 | ui_out_text (uiout, "Now in "); |
14191 | if (sym) | |
14192 | { | |
14193 | ui_out_field_string (uiout, "func", | |
14194 | SYMBOL_PRINT_NAME (sym)); | |
14195 | ui_out_text (uiout, " at "); | |
14196 | } | |
05cba821 JK |
14197 | ui_out_field_string (uiout, "file", |
14198 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14199 | ui_out_text (uiout, ":"); |
14200 | ||
14201 | if (ui_out_is_mi_like_p (uiout)) | |
14202 | { | |
0b0865da | 14203 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14204 | |
f35a17b5 | 14205 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14206 | } |
14207 | ||
80e1d417 | 14208 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14209 | ui_out_text (uiout, "\n"); |
14210 | ||
80e1d417 | 14211 | b->loc->line_number = sal2.line; |
2f202fde | 14212 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14213 | |
f00aae0f | 14214 | delete_event_location (b->location); |
67994074 KS |
14215 | initialize_explicit_location (&explicit_loc); |
14216 | explicit_loc.source_filename | |
00e52e53 | 14217 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14218 | explicit_loc.line_offset.offset = b->loc->line_number; |
14219 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14220 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14221 | |
14222 | /* Might be nice to check if function changed, and warn if | |
14223 | so. */ | |
14224 | ||
80e1d417 | 14225 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14226 | } |
14227 | } | |
14228 | return sal; | |
14229 | } | |
14230 | ||
8d3788bd VP |
14231 | /* Returns 1 iff locations A and B are sufficiently same that |
14232 | we don't need to report breakpoint as changed. */ | |
14233 | ||
14234 | static int | |
14235 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14236 | { | |
14237 | while (a && b) | |
14238 | { | |
14239 | if (a->address != b->address) | |
14240 | return 0; | |
14241 | ||
14242 | if (a->shlib_disabled != b->shlib_disabled) | |
14243 | return 0; | |
14244 | ||
14245 | if (a->enabled != b->enabled) | |
14246 | return 0; | |
14247 | ||
14248 | a = a->next; | |
14249 | b = b->next; | |
14250 | } | |
14251 | ||
14252 | if ((a == NULL) != (b == NULL)) | |
14253 | return 0; | |
14254 | ||
14255 | return 1; | |
14256 | } | |
14257 | ||
c2f4122d PA |
14258 | /* Split all locations of B that are bound to PSPACE out of B's |
14259 | location list to a separate list and return that list's head. If | |
14260 | PSPACE is NULL, hoist out all locations of B. */ | |
14261 | ||
14262 | static struct bp_location * | |
14263 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14264 | { | |
14265 | struct bp_location head; | |
14266 | struct bp_location *i = b->loc; | |
14267 | struct bp_location **i_link = &b->loc; | |
14268 | struct bp_location *hoisted = &head; | |
14269 | ||
14270 | if (pspace == NULL) | |
14271 | { | |
14272 | i = b->loc; | |
14273 | b->loc = NULL; | |
14274 | return i; | |
14275 | } | |
14276 | ||
14277 | head.next = NULL; | |
14278 | ||
14279 | while (i != NULL) | |
14280 | { | |
14281 | if (i->pspace == pspace) | |
14282 | { | |
14283 | *i_link = i->next; | |
14284 | i->next = NULL; | |
14285 | hoisted->next = i; | |
14286 | hoisted = i; | |
14287 | } | |
14288 | else | |
14289 | i_link = &i->next; | |
14290 | i = *i_link; | |
14291 | } | |
14292 | ||
14293 | return head.next; | |
14294 | } | |
14295 | ||
14296 | /* Create new breakpoint locations for B (a hardware or software | |
14297 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14298 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14299 | FILTER_PSPACE. Locations of other program spaces are left | |
14300 | untouched. */ | |
f1310107 | 14301 | |
0e30163f | 14302 | void |
0d381245 | 14303 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14304 | struct program_space *filter_pspace, |
f1310107 TJB |
14305 | struct symtabs_and_lines sals, |
14306 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14307 | { |
14308 | int i; | |
c2f4122d | 14309 | struct bp_location *existing_locations; |
0d381245 | 14310 | |
f8eba3c6 TT |
14311 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14312 | { | |
14313 | /* Ranged breakpoints have only one start location and one end | |
14314 | location. */ | |
14315 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14316 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14317 | "multiple locations found\n"), | |
14318 | b->number); | |
14319 | return; | |
14320 | } | |
f1310107 | 14321 | |
4a64f543 MS |
14322 | /* If there's no new locations, and all existing locations are |
14323 | pending, don't do anything. This optimizes the common case where | |
14324 | all locations are in the same shared library, that was unloaded. | |
14325 | We'd like to retain the location, so that when the library is | |
14326 | loaded again, we don't loose the enabled/disabled status of the | |
14327 | individual locations. */ | |
c2f4122d | 14328 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14329 | return; |
14330 | ||
c2f4122d | 14331 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14332 | |
0d381245 | 14333 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14334 | { |
f8eba3c6 TT |
14335 | struct bp_location *new_loc; |
14336 | ||
14337 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14338 | ||
14339 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14340 | |
0d381245 VP |
14341 | /* Reparse conditions, they might contain references to the |
14342 | old symtab. */ | |
14343 | if (b->cond_string != NULL) | |
14344 | { | |
bbc13ae3 | 14345 | const char *s; |
fe3f5fa8 | 14346 | |
0d381245 | 14347 | s = b->cond_string; |
492d29ea | 14348 | TRY |
0d381245 | 14349 | { |
1bb9788d TT |
14350 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14351 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14352 | 0); |
14353 | } | |
492d29ea | 14354 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14355 | { |
3e43a32a MS |
14356 | warning (_("failed to reevaluate condition " |
14357 | "for breakpoint %d: %s"), | |
0d381245 VP |
14358 | b->number, e.message); |
14359 | new_loc->enabled = 0; | |
14360 | } | |
492d29ea | 14361 | END_CATCH |
0d381245 | 14362 | } |
fe3f5fa8 | 14363 | |
f1310107 TJB |
14364 | if (sals_end.nelts) |
14365 | { | |
14366 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14367 | ||
14368 | new_loc->length = end - sals.sals[0].pc + 1; | |
14369 | } | |
0d381245 | 14370 | } |
fe3f5fa8 | 14371 | |
4a64f543 MS |
14372 | /* If possible, carry over 'disable' status from existing |
14373 | breakpoints. */ | |
0d381245 VP |
14374 | { |
14375 | struct bp_location *e = existing_locations; | |
776592bf DE |
14376 | /* If there are multiple breakpoints with the same function name, |
14377 | e.g. for inline functions, comparing function names won't work. | |
14378 | Instead compare pc addresses; this is just a heuristic as things | |
14379 | may have moved, but in practice it gives the correct answer | |
14380 | often enough until a better solution is found. */ | |
14381 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14382 | ||
0d381245 VP |
14383 | for (; e; e = e->next) |
14384 | { | |
14385 | if (!e->enabled && e->function_name) | |
14386 | { | |
14387 | struct bp_location *l = b->loc; | |
776592bf DE |
14388 | if (have_ambiguous_names) |
14389 | { | |
14390 | for (; l; l = l->next) | |
f1310107 | 14391 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14392 | { |
14393 | l->enabled = 0; | |
14394 | break; | |
14395 | } | |
14396 | } | |
14397 | else | |
14398 | { | |
14399 | for (; l; l = l->next) | |
14400 | if (l->function_name | |
14401 | && strcmp (e->function_name, l->function_name) == 0) | |
14402 | { | |
14403 | l->enabled = 0; | |
14404 | break; | |
14405 | } | |
14406 | } | |
0d381245 VP |
14407 | } |
14408 | } | |
14409 | } | |
fe3f5fa8 | 14410 | |
8d3788bd VP |
14411 | if (!locations_are_equal (existing_locations, b->loc)) |
14412 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14413 | } |
14414 | ||
f00aae0f | 14415 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14416 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14417 | ||
14418 | static struct symtabs_and_lines | |
f00aae0f | 14419 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14420 | struct program_space *search_pspace, int *found) |
ef23e705 | 14421 | { |
02d20e4a | 14422 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14423 | struct gdb_exception exception = exception_none; |
ef23e705 | 14424 | |
983af33b | 14425 | gdb_assert (b->ops != NULL); |
ef23e705 | 14426 | |
492d29ea | 14427 | TRY |
ef23e705 | 14428 | { |
c2f4122d | 14429 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14430 | } |
492d29ea | 14431 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14432 | { |
14433 | int not_found_and_ok = 0; | |
492d29ea PA |
14434 | |
14435 | exception = e; | |
14436 | ||
ef23e705 TJB |
14437 | /* For pending breakpoints, it's expected that parsing will |
14438 | fail until the right shared library is loaded. User has | |
14439 | already told to create pending breakpoints and don't need | |
14440 | extra messages. If breakpoint is in bp_shlib_disabled | |
14441 | state, then user already saw the message about that | |
14442 | breakpoint being disabled, and don't want to see more | |
14443 | errors. */ | |
58438ac1 | 14444 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14445 | && (b->condition_not_parsed |
14446 | || (b->loc != NULL | |
14447 | && search_pspace != NULL | |
14448 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14449 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14450 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14451 | || b->enable_state == bp_disabled)) |
14452 | not_found_and_ok = 1; | |
14453 | ||
14454 | if (!not_found_and_ok) | |
14455 | { | |
14456 | /* We surely don't want to warn about the same breakpoint | |
14457 | 10 times. One solution, implemented here, is disable | |
14458 | the breakpoint on error. Another solution would be to | |
14459 | have separate 'warning emitted' flag. Since this | |
14460 | happens only when a binary has changed, I don't know | |
14461 | which approach is better. */ | |
14462 | b->enable_state = bp_disabled; | |
14463 | throw_exception (e); | |
14464 | } | |
14465 | } | |
492d29ea | 14466 | END_CATCH |
ef23e705 | 14467 | |
492d29ea | 14468 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14469 | { |
f8eba3c6 | 14470 | int i; |
ef23e705 | 14471 | |
f8eba3c6 TT |
14472 | for (i = 0; i < sals.nelts; ++i) |
14473 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14474 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14475 | { |
ed1d1739 KS |
14476 | char *cond_string, *extra_string; |
14477 | int thread, task; | |
ef23e705 | 14478 | |
f00aae0f | 14479 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14480 | &cond_string, &thread, &task, |
14481 | &extra_string); | |
f00aae0f | 14482 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14483 | if (cond_string) |
14484 | b->cond_string = cond_string; | |
14485 | b->thread = thread; | |
14486 | b->task = task; | |
e7e0cddf | 14487 | if (extra_string) |
f00aae0f KS |
14488 | { |
14489 | xfree (b->extra_string); | |
14490 | b->extra_string = extra_string; | |
14491 | } | |
ef23e705 TJB |
14492 | b->condition_not_parsed = 0; |
14493 | } | |
14494 | ||
983af33b | 14495 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14496 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14497 | |
58438ac1 TT |
14498 | *found = 1; |
14499 | } | |
14500 | else | |
14501 | *found = 0; | |
ef23e705 TJB |
14502 | |
14503 | return sals; | |
14504 | } | |
14505 | ||
348d480f PA |
14506 | /* The default re_set method, for typical hardware or software |
14507 | breakpoints. Reevaluate the breakpoint and recreate its | |
14508 | locations. */ | |
14509 | ||
14510 | static void | |
28010a5d | 14511 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14512 | { |
14513 | int found; | |
f1310107 | 14514 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14515 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14516 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14517 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14518 | |
c2f4122d | 14519 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14520 | if (found) |
14521 | { | |
14522 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14523 | expanded = sals; |
ef23e705 TJB |
14524 | } |
14525 | ||
f00aae0f | 14526 | if (b->location_range_end != NULL) |
f1310107 | 14527 | { |
c2f4122d PA |
14528 | sals_end = location_to_sals (b, b->location_range_end, |
14529 | filter_pspace, &found); | |
f1310107 TJB |
14530 | if (found) |
14531 | { | |
14532 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14533 | expanded_end = sals_end; |
f1310107 TJB |
14534 | } |
14535 | } | |
14536 | ||
c2f4122d | 14537 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14538 | } |
14539 | ||
983af33b SDJ |
14540 | /* Default method for creating SALs from an address string. It basically |
14541 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14542 | ||
14543 | static void | |
f00aae0f KS |
14544 | create_sals_from_location_default (const struct event_location *location, |
14545 | struct linespec_result *canonical, | |
14546 | enum bptype type_wanted) | |
983af33b | 14547 | { |
f00aae0f | 14548 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14549 | } |
14550 | ||
14551 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14552 | function for the `create_breakpoints_sal' method of | |
14553 | breakpoint_ops. */ | |
14554 | ||
14555 | static void | |
14556 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14557 | struct linespec_result *canonical, | |
983af33b | 14558 | char *cond_string, |
e7e0cddf | 14559 | char *extra_string, |
983af33b SDJ |
14560 | enum bptype type_wanted, |
14561 | enum bpdisp disposition, | |
14562 | int thread, | |
14563 | int task, int ignore_count, | |
14564 | const struct breakpoint_ops *ops, | |
14565 | int from_tty, int enabled, | |
44f238bb | 14566 | int internal, unsigned flags) |
983af33b SDJ |
14567 | { |
14568 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14569 | extra_string, |
983af33b SDJ |
14570 | type_wanted, disposition, |
14571 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14572 | enabled, internal, flags); |
983af33b SDJ |
14573 | } |
14574 | ||
14575 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14576 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14577 | |
14578 | static void | |
f00aae0f KS |
14579 | decode_location_default (struct breakpoint *b, |
14580 | const struct event_location *location, | |
c2f4122d | 14581 | struct program_space *search_pspace, |
983af33b SDJ |
14582 | struct symtabs_and_lines *sals) |
14583 | { | |
14584 | struct linespec_result canonical; | |
14585 | ||
14586 | init_linespec_result (&canonical); | |
c2f4122d | 14587 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14588 | (struct symtab *) NULL, 0, |
14589 | &canonical, multiple_symbols_all, | |
14590 | b->filter); | |
14591 | ||
14592 | /* We should get 0 or 1 resulting SALs. */ | |
14593 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14594 | ||
14595 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14596 | { | |
14597 | struct linespec_sals *lsal; | |
14598 | ||
14599 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14600 | *sals = lsal->sals; | |
14601 | /* Arrange it so the destructor does not free the | |
14602 | contents. */ | |
14603 | lsal->sals.sals = NULL; | |
14604 | } | |
14605 | ||
14606 | destroy_linespec_result (&canonical); | |
14607 | } | |
14608 | ||
28010a5d PA |
14609 | /* Prepare the global context for a re-set of breakpoint B. */ |
14610 | ||
14611 | static struct cleanup * | |
14612 | prepare_re_set_context (struct breakpoint *b) | |
14613 | { | |
28010a5d | 14614 | input_radix = b->input_radix; |
28010a5d PA |
14615 | set_language (b->language); |
14616 | ||
c2f4122d | 14617 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14618 | } |
14619 | ||
c906108c SS |
14620 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14621 | The value we return ends up being the return value from catch_errors. | |
14622 | Unused in this case. */ | |
14623 | ||
14624 | static int | |
4efb68b1 | 14625 | breakpoint_re_set_one (void *bint) |
c906108c | 14626 | { |
4a64f543 | 14627 | /* Get past catch_errs. */ |
53a5351d | 14628 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14629 | struct cleanup *cleanups; |
c906108c | 14630 | |
348d480f PA |
14631 | cleanups = prepare_re_set_context (b); |
14632 | b->ops->re_set (b); | |
14633 | do_cleanups (cleanups); | |
c906108c SS |
14634 | return 0; |
14635 | } | |
14636 | ||
c2f4122d PA |
14637 | /* Re-set breakpoint locations for the current program space. |
14638 | Locations bound to other program spaces are left untouched. */ | |
14639 | ||
c906108c | 14640 | void |
69de3c6a | 14641 | breakpoint_re_set (void) |
c906108c | 14642 | { |
35df4500 | 14643 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14644 | enum language save_language; |
14645 | int save_input_radix; | |
6c95b8df | 14646 | struct cleanup *old_chain; |
c5aa993b | 14647 | |
c906108c SS |
14648 | save_language = current_language->la_language; |
14649 | save_input_radix = input_radix; | |
c2f4122d | 14650 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14651 | |
2a7f3dff PA |
14652 | /* Note: we must not try to insert locations until after all |
14653 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14654 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14655 | hadn't been re-set yet, and thus may have stale locations. */ | |
14656 | ||
35df4500 | 14657 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14658 | { |
4a64f543 | 14659 | /* Format possible error msg. */ |
fe3f5fa8 | 14660 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14661 | b->number); |
14662 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14663 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14664 | do_cleanups (cleanups); |
c5aa993b | 14665 | } |
c906108c SS |
14666 | set_language (save_language); |
14667 | input_radix = save_input_radix; | |
e62c965a | 14668 | |
0756c555 | 14669 | jit_breakpoint_re_set (); |
4efc6507 | 14670 | |
6c95b8df PA |
14671 | do_cleanups (old_chain); |
14672 | ||
af02033e PP |
14673 | create_overlay_event_breakpoint (); |
14674 | create_longjmp_master_breakpoint (); | |
14675 | create_std_terminate_master_breakpoint (); | |
186c406b | 14676 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14677 | |
14678 | /* Now we can insert. */ | |
14679 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14680 | } |
14681 | \f | |
c906108c SS |
14682 | /* Reset the thread number of this breakpoint: |
14683 | ||
14684 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14685 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14686 | void |
fba45db2 | 14687 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14688 | { |
14689 | if (b->thread != -1) | |
14690 | { | |
39f77062 | 14691 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14692 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14693 | |
14694 | /* We're being called after following a fork. The new fork is | |
14695 | selected as current, and unless this was a vfork will have a | |
14696 | different program space from the original thread. Reset that | |
14697 | as well. */ | |
14698 | b->loc->pspace = current_program_space; | |
c906108c SS |
14699 | } |
14700 | } | |
14701 | ||
03ac34d5 MS |
14702 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14703 | If from_tty is nonzero, it prints a message to that effect, | |
14704 | which ends with a period (no newline). */ | |
14705 | ||
c906108c | 14706 | void |
fba45db2 | 14707 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14708 | { |
52f0bd74 | 14709 | struct breakpoint *b; |
c906108c SS |
14710 | |
14711 | if (count < 0) | |
14712 | count = 0; | |
14713 | ||
14714 | ALL_BREAKPOINTS (b) | |
14715 | if (b->number == bptnum) | |
c5aa993b | 14716 | { |
d77f58be SS |
14717 | if (is_tracepoint (b)) |
14718 | { | |
14719 | if (from_tty && count != 0) | |
14720 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14721 | bptnum); | |
14722 | return; | |
14723 | } | |
14724 | ||
c5aa993b | 14725 | b->ignore_count = count; |
221ea385 KS |
14726 | if (from_tty) |
14727 | { | |
14728 | if (count == 0) | |
3e43a32a MS |
14729 | printf_filtered (_("Will stop next time " |
14730 | "breakpoint %d is reached."), | |
221ea385 KS |
14731 | bptnum); |
14732 | else if (count == 1) | |
a3f17187 | 14733 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14734 | bptnum); |
14735 | else | |
3e43a32a MS |
14736 | printf_filtered (_("Will ignore next %d " |
14737 | "crossings of breakpoint %d."), | |
221ea385 KS |
14738 | count, bptnum); |
14739 | } | |
8d3788bd | 14740 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14741 | return; |
14742 | } | |
c906108c | 14743 | |
8a3fe4f8 | 14744 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14745 | } |
14746 | ||
c906108c SS |
14747 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14748 | ||
14749 | static void | |
fba45db2 | 14750 | ignore_command (char *args, int from_tty) |
c906108c SS |
14751 | { |
14752 | char *p = args; | |
52f0bd74 | 14753 | int num; |
c906108c SS |
14754 | |
14755 | if (p == 0) | |
e2e0b3e5 | 14756 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14757 | |
c906108c | 14758 | num = get_number (&p); |
5c44784c | 14759 | if (num == 0) |
8a3fe4f8 | 14760 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14761 | if (*p == 0) |
8a3fe4f8 | 14762 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14763 | |
14764 | set_ignore_count (num, | |
14765 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14766 | from_tty); | |
221ea385 KS |
14767 | if (from_tty) |
14768 | printf_filtered ("\n"); | |
c906108c SS |
14769 | } |
14770 | \f | |
14771 | /* Call FUNCTION on each of the breakpoints | |
14772 | whose numbers are given in ARGS. */ | |
14773 | ||
14774 | static void | |
95a42b64 TT |
14775 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14776 | void *), | |
14777 | void *data) | |
c906108c | 14778 | { |
52f0bd74 AC |
14779 | int num; |
14780 | struct breakpoint *b, *tmp; | |
11cf8741 | 14781 | int match; |
197f0a60 | 14782 | struct get_number_or_range_state state; |
c906108c | 14783 | |
b9d61307 | 14784 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14785 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14786 | |
197f0a60 TT |
14787 | init_number_or_range (&state, args); |
14788 | ||
14789 | while (!state.finished) | |
c906108c | 14790 | { |
e799154c | 14791 | const char *p = state.string; |
197f0a60 | 14792 | |
11cf8741 | 14793 | match = 0; |
c5aa993b | 14794 | |
197f0a60 | 14795 | num = get_number_or_range (&state); |
5c44784c | 14796 | if (num == 0) |
c5aa993b | 14797 | { |
8a3fe4f8 | 14798 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14799 | } |
14800 | else | |
14801 | { | |
14802 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14803 | if (b->number == num) | |
14804 | { | |
11cf8741 | 14805 | match = 1; |
cdac0397 | 14806 | function (b, data); |
11cf8741 | 14807 | break; |
5c44784c | 14808 | } |
11cf8741 | 14809 | if (match == 0) |
a3f17187 | 14810 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14811 | } |
c906108c SS |
14812 | } |
14813 | } | |
14814 | ||
0d381245 VP |
14815 | static struct bp_location * |
14816 | find_location_by_number (char *number) | |
14817 | { | |
14818 | char *dot = strchr (number, '.'); | |
14819 | char *p1; | |
14820 | int bp_num; | |
14821 | int loc_num; | |
14822 | struct breakpoint *b; | |
14823 | struct bp_location *loc; | |
14824 | ||
14825 | *dot = '\0'; | |
14826 | ||
14827 | p1 = number; | |
197f0a60 | 14828 | bp_num = get_number (&p1); |
0d381245 VP |
14829 | if (bp_num == 0) |
14830 | error (_("Bad breakpoint number '%s'"), number); | |
14831 | ||
14832 | ALL_BREAKPOINTS (b) | |
14833 | if (b->number == bp_num) | |
14834 | { | |
14835 | break; | |
14836 | } | |
14837 | ||
14838 | if (!b || b->number != bp_num) | |
14839 | error (_("Bad breakpoint number '%s'"), number); | |
14840 | ||
14841 | p1 = dot+1; | |
197f0a60 | 14842 | loc_num = get_number (&p1); |
0d381245 VP |
14843 | if (loc_num == 0) |
14844 | error (_("Bad breakpoint location number '%s'"), number); | |
14845 | ||
14846 | --loc_num; | |
14847 | loc = b->loc; | |
14848 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14849 | ; | |
14850 | if (!loc) | |
14851 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14852 | ||
14853 | return loc; | |
14854 | } | |
14855 | ||
14856 | ||
1900040c MS |
14857 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14858 | If from_tty is nonzero, it prints a message to that effect, | |
14859 | which ends with a period (no newline). */ | |
14860 | ||
c906108c | 14861 | void |
fba45db2 | 14862 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14863 | { |
14864 | /* Never disable a watchpoint scope breakpoint; we want to | |
14865 | hit them when we leave scope so we can delete both the | |
14866 | watchpoint and its scope breakpoint at that time. */ | |
14867 | if (bpt->type == bp_watchpoint_scope) | |
14868 | return; | |
14869 | ||
b5de0fa7 | 14870 | bpt->enable_state = bp_disabled; |
c906108c | 14871 | |
b775012e LM |
14872 | /* Mark breakpoint locations modified. */ |
14873 | mark_breakpoint_modified (bpt); | |
14874 | ||
d248b706 KY |
14875 | if (target_supports_enable_disable_tracepoint () |
14876 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14877 | { | |
14878 | struct bp_location *location; | |
14879 | ||
14880 | for (location = bpt->loc; location; location = location->next) | |
14881 | target_disable_tracepoint (location); | |
14882 | } | |
14883 | ||
44702360 | 14884 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14885 | |
8d3788bd | 14886 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14887 | } |
14888 | ||
51be5b68 PA |
14889 | /* A callback for iterate_over_related_breakpoints. */ |
14890 | ||
14891 | static void | |
14892 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14893 | { | |
14894 | disable_breakpoint (b); | |
14895 | } | |
14896 | ||
95a42b64 TT |
14897 | /* A callback for map_breakpoint_numbers that calls |
14898 | disable_breakpoint. */ | |
14899 | ||
14900 | static void | |
14901 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14902 | { | |
51be5b68 | 14903 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14904 | } |
14905 | ||
c906108c | 14906 | static void |
fba45db2 | 14907 | disable_command (char *args, int from_tty) |
c906108c | 14908 | { |
c906108c | 14909 | if (args == 0) |
46c6471b PA |
14910 | { |
14911 | struct breakpoint *bpt; | |
14912 | ||
14913 | ALL_BREAKPOINTS (bpt) | |
14914 | if (user_breakpoint_p (bpt)) | |
14915 | disable_breakpoint (bpt); | |
14916 | } | |
9eaabc75 | 14917 | else |
0d381245 | 14918 | { |
9eaabc75 MW |
14919 | char *num = extract_arg (&args); |
14920 | ||
14921 | while (num) | |
d248b706 | 14922 | { |
9eaabc75 | 14923 | if (strchr (num, '.')) |
b775012e | 14924 | { |
9eaabc75 MW |
14925 | struct bp_location *loc = find_location_by_number (num); |
14926 | ||
14927 | if (loc) | |
14928 | { | |
14929 | if (loc->enabled) | |
14930 | { | |
14931 | loc->enabled = 0; | |
14932 | mark_breakpoint_location_modified (loc); | |
14933 | } | |
14934 | if (target_supports_enable_disable_tracepoint () | |
14935 | && current_trace_status ()->running && loc->owner | |
14936 | && is_tracepoint (loc->owner)) | |
14937 | target_disable_tracepoint (loc); | |
14938 | } | |
44702360 | 14939 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14940 | } |
9eaabc75 MW |
14941 | else |
14942 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14943 | num = extract_arg (&args); | |
d248b706 | 14944 | } |
0d381245 | 14945 | } |
c906108c SS |
14946 | } |
14947 | ||
14948 | static void | |
816338b5 SS |
14949 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14950 | int count) | |
c906108c | 14951 | { |
afe38095 | 14952 | int target_resources_ok; |
c906108c SS |
14953 | |
14954 | if (bpt->type == bp_hardware_breakpoint) | |
14955 | { | |
14956 | int i; | |
c5aa993b | 14957 | i = hw_breakpoint_used_count (); |
53a5351d | 14958 | target_resources_ok = |
d92524f1 | 14959 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14960 | i + 1, 0); |
c906108c | 14961 | if (target_resources_ok == 0) |
8a3fe4f8 | 14962 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14963 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14964 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14965 | } |
14966 | ||
cc60f2e3 | 14967 | if (is_watchpoint (bpt)) |
c906108c | 14968 | { |
d07205c2 | 14969 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14970 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14971 | |
492d29ea | 14972 | TRY |
c906108c | 14973 | { |
3a5c3e22 PA |
14974 | struct watchpoint *w = (struct watchpoint *) bpt; |
14975 | ||
1e718ff1 TJB |
14976 | orig_enable_state = bpt->enable_state; |
14977 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14978 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14979 | } |
492d29ea | 14980 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14981 | { |
1e718ff1 | 14982 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14983 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14984 | bpt->number); | |
14985 | return; | |
c5aa993b | 14986 | } |
492d29ea | 14987 | END_CATCH |
c906108c | 14988 | } |
0101ce28 | 14989 | |
b775012e LM |
14990 | bpt->enable_state = bp_enabled; |
14991 | ||
14992 | /* Mark breakpoint locations modified. */ | |
14993 | mark_breakpoint_modified (bpt); | |
14994 | ||
d248b706 KY |
14995 | if (target_supports_enable_disable_tracepoint () |
14996 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14997 | { | |
14998 | struct bp_location *location; | |
14999 | ||
15000 | for (location = bpt->loc; location; location = location->next) | |
15001 | target_enable_tracepoint (location); | |
15002 | } | |
15003 | ||
b4c291bb | 15004 | bpt->disposition = disposition; |
816338b5 | 15005 | bpt->enable_count = count; |
44702360 | 15006 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15007 | |
8d3788bd | 15008 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15009 | } |
15010 | ||
fe3f5fa8 | 15011 | |
c906108c | 15012 | void |
fba45db2 | 15013 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15014 | { |
816338b5 | 15015 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15016 | } |
15017 | ||
15018 | static void | |
15019 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15020 | { | |
15021 | enable_breakpoint (bpt); | |
c906108c SS |
15022 | } |
15023 | ||
95a42b64 TT |
15024 | /* A callback for map_breakpoint_numbers that calls |
15025 | enable_breakpoint. */ | |
15026 | ||
15027 | static void | |
15028 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15029 | { | |
51be5b68 | 15030 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15031 | } |
15032 | ||
c906108c SS |
15033 | /* The enable command enables the specified breakpoints (or all defined |
15034 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15035 | in stopping the inferior. */ |
c906108c | 15036 | |
c906108c | 15037 | static void |
fba45db2 | 15038 | enable_command (char *args, int from_tty) |
c906108c | 15039 | { |
c906108c | 15040 | if (args == 0) |
46c6471b PA |
15041 | { |
15042 | struct breakpoint *bpt; | |
15043 | ||
15044 | ALL_BREAKPOINTS (bpt) | |
15045 | if (user_breakpoint_p (bpt)) | |
15046 | enable_breakpoint (bpt); | |
15047 | } | |
9eaabc75 | 15048 | else |
0d381245 | 15049 | { |
9eaabc75 MW |
15050 | char *num = extract_arg (&args); |
15051 | ||
15052 | while (num) | |
d248b706 | 15053 | { |
9eaabc75 | 15054 | if (strchr (num, '.')) |
b775012e | 15055 | { |
9eaabc75 MW |
15056 | struct bp_location *loc = find_location_by_number (num); |
15057 | ||
15058 | if (loc) | |
15059 | { | |
15060 | if (!loc->enabled) | |
15061 | { | |
15062 | loc->enabled = 1; | |
15063 | mark_breakpoint_location_modified (loc); | |
15064 | } | |
15065 | if (target_supports_enable_disable_tracepoint () | |
15066 | && current_trace_status ()->running && loc->owner | |
15067 | && is_tracepoint (loc->owner)) | |
15068 | target_enable_tracepoint (loc); | |
15069 | } | |
44702360 | 15070 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15071 | } |
9eaabc75 MW |
15072 | else |
15073 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15074 | num = extract_arg (&args); | |
d248b706 | 15075 | } |
0d381245 | 15076 | } |
c906108c SS |
15077 | } |
15078 | ||
816338b5 SS |
15079 | /* This struct packages up disposition data for application to multiple |
15080 | breakpoints. */ | |
15081 | ||
15082 | struct disp_data | |
15083 | { | |
15084 | enum bpdisp disp; | |
15085 | int count; | |
15086 | }; | |
15087 | ||
c906108c | 15088 | static void |
51be5b68 PA |
15089 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15090 | { | |
816338b5 | 15091 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15092 | |
816338b5 | 15093 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15094 | } |
15095 | ||
15096 | static void | |
15097 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15098 | { |
816338b5 | 15099 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15100 | |
15101 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15102 | } |
15103 | ||
c906108c | 15104 | static void |
fba45db2 | 15105 | enable_once_command (char *args, int from_tty) |
c906108c | 15106 | { |
51be5b68 | 15107 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15108 | } |
15109 | ||
816338b5 SS |
15110 | static void |
15111 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15112 | { | |
15113 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15114 | ||
15115 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15116 | } | |
15117 | ||
15118 | static void | |
15119 | enable_count_command (char *args, int from_tty) | |
15120 | { | |
b9d61307 SM |
15121 | int count; |
15122 | ||
15123 | if (args == NULL) | |
15124 | error_no_arg (_("hit count")); | |
15125 | ||
15126 | count = get_number (&args); | |
816338b5 SS |
15127 | |
15128 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15129 | } | |
15130 | ||
c906108c | 15131 | static void |
51be5b68 | 15132 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15133 | { |
816338b5 | 15134 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15135 | |
15136 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15137 | } |
15138 | ||
c906108c | 15139 | static void |
fba45db2 | 15140 | enable_delete_command (char *args, int from_tty) |
c906108c | 15141 | { |
51be5b68 | 15142 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15143 | } |
15144 | \f | |
fa8d40ab JJ |
15145 | static void |
15146 | set_breakpoint_cmd (char *args, int from_tty) | |
15147 | { | |
15148 | } | |
15149 | ||
15150 | static void | |
15151 | show_breakpoint_cmd (char *args, int from_tty) | |
15152 | { | |
15153 | } | |
15154 | ||
1f3b5d1b PP |
15155 | /* Invalidate last known value of any hardware watchpoint if |
15156 | the memory which that value represents has been written to by | |
15157 | GDB itself. */ | |
15158 | ||
15159 | static void | |
8de0566d YQ |
15160 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15161 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15162 | const bfd_byte *data) |
15163 | { | |
15164 | struct breakpoint *bp; | |
15165 | ||
15166 | ALL_BREAKPOINTS (bp) | |
15167 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15168 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15169 | { |
3a5c3e22 | 15170 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15171 | |
3a5c3e22 PA |
15172 | if (wp->val_valid && wp->val) |
15173 | { | |
15174 | struct bp_location *loc; | |
15175 | ||
15176 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15177 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15178 | && loc->address + loc->length > addr | |
15179 | && addr + len > loc->address) | |
15180 | { | |
15181 | value_free (wp->val); | |
15182 | wp->val = NULL; | |
15183 | wp->val_valid = 0; | |
15184 | } | |
15185 | } | |
1f3b5d1b PP |
15186 | } |
15187 | } | |
15188 | ||
8181d85f DJ |
15189 | /* Create and insert a breakpoint for software single step. */ |
15190 | ||
15191 | void | |
6c95b8df | 15192 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15193 | struct address_space *aspace, |
15194 | CORE_ADDR next_pc) | |
8181d85f | 15195 | { |
7c16b83e PA |
15196 | struct thread_info *tp = inferior_thread (); |
15197 | struct symtab_and_line sal; | |
15198 | CORE_ADDR pc = next_pc; | |
8181d85f | 15199 | |
34b7e8a6 PA |
15200 | if (tp->control.single_step_breakpoints == NULL) |
15201 | { | |
15202 | tp->control.single_step_breakpoints | |
5d5658a1 | 15203 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15204 | } |
8181d85f | 15205 | |
7c16b83e PA |
15206 | sal = find_pc_line (pc, 0); |
15207 | sal.pc = pc; | |
15208 | sal.section = find_pc_overlay (pc); | |
15209 | sal.explicit_pc = 1; | |
34b7e8a6 | 15210 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15211 | |
7c16b83e | 15212 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15213 | } |
15214 | ||
34b7e8a6 | 15215 | /* See breakpoint.h. */ |
f02253f1 HZ |
15216 | |
15217 | int | |
7c16b83e PA |
15218 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15219 | struct address_space *aspace, | |
15220 | CORE_ADDR pc) | |
1aafd4da | 15221 | { |
7c16b83e | 15222 | struct bp_location *loc; |
1aafd4da | 15223 | |
7c16b83e PA |
15224 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15225 | if (loc->inserted | |
15226 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15227 | return 1; | |
1aafd4da | 15228 | |
7c16b83e | 15229 | return 0; |
ef370185 JB |
15230 | } |
15231 | ||
15232 | /* Check whether a software single-step breakpoint is inserted at | |
15233 | PC. */ | |
15234 | ||
15235 | int | |
15236 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15237 | CORE_ADDR pc) | |
15238 | { | |
34b7e8a6 PA |
15239 | struct breakpoint *bpt; |
15240 | ||
15241 | ALL_BREAKPOINTS (bpt) | |
15242 | { | |
15243 | if (bpt->type == bp_single_step | |
15244 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15245 | return 1; | |
15246 | } | |
15247 | return 0; | |
1aafd4da UW |
15248 | } |
15249 | ||
1042e4c0 SS |
15250 | /* Tracepoint-specific operations. */ |
15251 | ||
15252 | /* Set tracepoint count to NUM. */ | |
15253 | static void | |
15254 | set_tracepoint_count (int num) | |
15255 | { | |
15256 | tracepoint_count = num; | |
4fa62494 | 15257 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15258 | } |
15259 | ||
70221824 | 15260 | static void |
1042e4c0 SS |
15261 | trace_command (char *arg, int from_tty) |
15262 | { | |
55aa24fb | 15263 | struct breakpoint_ops *ops; |
f00aae0f KS |
15264 | struct event_location *location; |
15265 | struct cleanup *back_to; | |
55aa24fb | 15266 | |
f00aae0f KS |
15267 | location = string_to_event_location (&arg, current_language); |
15268 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15269 | if (location != NULL |
15270 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15271 | ops = &tracepoint_probe_breakpoint_ops; |
15272 | else | |
15273 | ops = &tracepoint_breakpoint_ops; | |
15274 | ||
558a9d82 | 15275 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15276 | location, |
15277 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15278 | 0 /* tempflag */, |
15279 | bp_tracepoint /* type_wanted */, | |
15280 | 0 /* Ignore count */, | |
15281 | pending_break_support, | |
15282 | ops, | |
15283 | from_tty, | |
15284 | 1 /* enabled */, | |
15285 | 0 /* internal */, 0); | |
f00aae0f | 15286 | do_cleanups (back_to); |
1042e4c0 SS |
15287 | } |
15288 | ||
70221824 | 15289 | static void |
7a697b8d SS |
15290 | ftrace_command (char *arg, int from_tty) |
15291 | { | |
f00aae0f KS |
15292 | struct event_location *location; |
15293 | struct cleanup *back_to; | |
15294 | ||
15295 | location = string_to_event_location (&arg, current_language); | |
15296 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15297 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15298 | location, |
15299 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15300 | 0 /* tempflag */, |
15301 | bp_fast_tracepoint /* type_wanted */, | |
15302 | 0 /* Ignore count */, | |
15303 | pending_break_support, | |
15304 | &tracepoint_breakpoint_ops, | |
15305 | from_tty, | |
15306 | 1 /* enabled */, | |
15307 | 0 /* internal */, 0); | |
f00aae0f | 15308 | do_cleanups (back_to); |
0fb4aa4b PA |
15309 | } |
15310 | ||
15311 | /* strace command implementation. Creates a static tracepoint. */ | |
15312 | ||
70221824 | 15313 | static void |
0fb4aa4b PA |
15314 | strace_command (char *arg, int from_tty) |
15315 | { | |
983af33b | 15316 | struct breakpoint_ops *ops; |
f00aae0f KS |
15317 | struct event_location *location; |
15318 | struct cleanup *back_to; | |
983af33b SDJ |
15319 | |
15320 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15321 | or with a normal static tracepoint. */ | |
61012eef | 15322 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15323 | { |
15324 | ops = &strace_marker_breakpoint_ops; | |
15325 | location = new_linespec_location (&arg); | |
15326 | } | |
983af33b | 15327 | else |
f00aae0f KS |
15328 | { |
15329 | ops = &tracepoint_breakpoint_ops; | |
15330 | location = string_to_event_location (&arg, current_language); | |
15331 | } | |
983af33b | 15332 | |
f00aae0f | 15333 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15334 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15335 | location, |
15336 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15337 | 0 /* tempflag */, |
15338 | bp_static_tracepoint /* type_wanted */, | |
15339 | 0 /* Ignore count */, | |
15340 | pending_break_support, | |
15341 | ops, | |
15342 | from_tty, | |
15343 | 1 /* enabled */, | |
15344 | 0 /* internal */, 0); | |
f00aae0f | 15345 | do_cleanups (back_to); |
7a697b8d SS |
15346 | } |
15347 | ||
409873ef SS |
15348 | /* Set up a fake reader function that gets command lines from a linked |
15349 | list that was acquired during tracepoint uploading. */ | |
15350 | ||
15351 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15352 | static int next_cmd; |
409873ef SS |
15353 | |
15354 | static char * | |
15355 | read_uploaded_action (void) | |
15356 | { | |
15357 | char *rslt; | |
15358 | ||
3149d8c1 | 15359 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15360 | |
3149d8c1 | 15361 | next_cmd++; |
409873ef SS |
15362 | |
15363 | return rslt; | |
15364 | } | |
15365 | ||
00bf0b85 SS |
15366 | /* Given information about a tracepoint as recorded on a target (which |
15367 | can be either a live system or a trace file), attempt to create an | |
15368 | equivalent GDB tracepoint. This is not a reliable process, since | |
15369 | the target does not necessarily have all the information used when | |
15370 | the tracepoint was originally defined. */ | |
15371 | ||
d9b3f62e | 15372 | struct tracepoint * |
00bf0b85 | 15373 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15374 | { |
409873ef | 15375 | char *addr_str, small_buf[100]; |
d9b3f62e | 15376 | struct tracepoint *tp; |
f00aae0f KS |
15377 | struct event_location *location; |
15378 | struct cleanup *cleanup; | |
fd9b8c24 | 15379 | |
409873ef SS |
15380 | if (utp->at_string) |
15381 | addr_str = utp->at_string; | |
15382 | else | |
15383 | { | |
15384 | /* In the absence of a source location, fall back to raw | |
15385 | address. Since there is no way to confirm that the address | |
15386 | means the same thing as when the trace was started, warn the | |
15387 | user. */ | |
3e43a32a MS |
15388 | warning (_("Uploaded tracepoint %d has no " |
15389 | "source location, using raw address"), | |
409873ef | 15390 | utp->number); |
8c042590 | 15391 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15392 | addr_str = small_buf; |
15393 | } | |
15394 | ||
15395 | /* There's not much we can do with a sequence of bytecodes. */ | |
15396 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15397 | warning (_("Uploaded tracepoint %d condition " |
15398 | "has no source form, ignoring it"), | |
409873ef | 15399 | utp->number); |
d5551862 | 15400 | |
f00aae0f KS |
15401 | location = string_to_event_location (&addr_str, current_language); |
15402 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15403 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15404 | location, |
15405 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15406 | 0 /* parse cond/thread */, |
8cdf0e15 | 15407 | 0 /* tempflag */, |
0fb4aa4b | 15408 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15409 | 0 /* Ignore count */, |
15410 | pending_break_support, | |
348d480f | 15411 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15412 | 0 /* from_tty */, |
84f4c1fe | 15413 | utp->enabled /* enabled */, |
44f238bb PA |
15414 | 0 /* internal */, |
15415 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15416 | { |
15417 | do_cleanups (cleanup); | |
15418 | return NULL; | |
15419 | } | |
15420 | ||
15421 | do_cleanups (cleanup); | |
fd9b8c24 | 15422 | |
409873ef | 15423 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15424 | tp = get_tracepoint (tracepoint_count); |
15425 | gdb_assert (tp != NULL); | |
d5551862 | 15426 | |
00bf0b85 SS |
15427 | if (utp->pass > 0) |
15428 | { | |
8c042590 PM |
15429 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15430 | tp->base.number); | |
00bf0b85 | 15431 | |
409873ef | 15432 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15433 | } |
15434 | ||
409873ef SS |
15435 | /* If we have uploaded versions of the original commands, set up a |
15436 | special-purpose "reader" function and call the usual command line | |
15437 | reader, then pass the result to the breakpoint command-setting | |
15438 | function. */ | |
3149d8c1 | 15439 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15440 | { |
409873ef | 15441 | struct command_line *cmd_list; |
00bf0b85 | 15442 | |
409873ef | 15443 | this_utp = utp; |
3149d8c1 | 15444 | next_cmd = 0; |
d5551862 | 15445 | |
409873ef SS |
15446 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15447 | ||
d9b3f62e | 15448 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15449 | } |
3149d8c1 SS |
15450 | else if (!VEC_empty (char_ptr, utp->actions) |
15451 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15452 | warning (_("Uploaded tracepoint %d actions " |
15453 | "have no source form, ignoring them"), | |
409873ef | 15454 | utp->number); |
00bf0b85 | 15455 | |
f196051f SS |
15456 | /* Copy any status information that might be available. */ |
15457 | tp->base.hit_count = utp->hit_count; | |
15458 | tp->traceframe_usage = utp->traceframe_usage; | |
15459 | ||
00bf0b85 | 15460 | return tp; |
d9b3f62e | 15461 | } |
00bf0b85 | 15462 | |
1042e4c0 SS |
15463 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15464 | omitted. */ | |
15465 | ||
15466 | static void | |
e5a67952 | 15467 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15468 | { |
79a45e25 | 15469 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15470 | int num_printed; |
1042e4c0 | 15471 | |
e5a67952 | 15472 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15473 | |
15474 | if (num_printed == 0) | |
1042e4c0 | 15475 | { |
e5a67952 | 15476 | if (args == NULL || *args == '\0') |
d77f58be SS |
15477 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15478 | else | |
e5a67952 | 15479 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15480 | } |
ad443146 SS |
15481 | |
15482 | default_collect_info (); | |
1042e4c0 SS |
15483 | } |
15484 | ||
4a64f543 | 15485 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15486 | Not supported by all targets. */ |
15487 | static void | |
15488 | enable_trace_command (char *args, int from_tty) | |
15489 | { | |
15490 | enable_command (args, from_tty); | |
15491 | } | |
15492 | ||
4a64f543 | 15493 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15494 | Not supported by all targets. */ |
15495 | static void | |
15496 | disable_trace_command (char *args, int from_tty) | |
15497 | { | |
15498 | disable_command (args, from_tty); | |
15499 | } | |
15500 | ||
4a64f543 | 15501 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15502 | static void |
15503 | delete_trace_command (char *arg, int from_tty) | |
15504 | { | |
35df4500 | 15505 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15506 | |
15507 | dont_repeat (); | |
15508 | ||
15509 | if (arg == 0) | |
15510 | { | |
15511 | int breaks_to_delete = 0; | |
15512 | ||
15513 | /* Delete all breakpoints if no argument. | |
15514 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15515 | have to be deleted with an explicit breakpoint number |
15516 | argument. */ | |
1042e4c0 | 15517 | ALL_TRACEPOINTS (b) |
46c6471b | 15518 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15519 | { |
15520 | breaks_to_delete = 1; | |
15521 | break; | |
15522 | } | |
1042e4c0 SS |
15523 | |
15524 | /* Ask user only if there are some breakpoints to delete. */ | |
15525 | if (!from_tty | |
15526 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15527 | { | |
35df4500 | 15528 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15529 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15530 | delete_breakpoint (b); |
1042e4c0 SS |
15531 | } |
15532 | } | |
15533 | else | |
51be5b68 | 15534 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15535 | } |
15536 | ||
197f0a60 TT |
15537 | /* Helper function for trace_pass_command. */ |
15538 | ||
15539 | static void | |
d9b3f62e | 15540 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15541 | { |
d9b3f62e | 15542 | tp->pass_count = count; |
6f6484cd | 15543 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15544 | if (from_tty) |
15545 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15546 | tp->base.number, count); |
197f0a60 TT |
15547 | } |
15548 | ||
1042e4c0 SS |
15549 | /* Set passcount for tracepoint. |
15550 | ||
15551 | First command argument is passcount, second is tracepoint number. | |
15552 | If tracepoint number omitted, apply to most recently defined. | |
15553 | Also accepts special argument "all". */ | |
15554 | ||
15555 | static void | |
15556 | trace_pass_command (char *args, int from_tty) | |
15557 | { | |
d9b3f62e | 15558 | struct tracepoint *t1; |
1042e4c0 | 15559 | unsigned int count; |
1042e4c0 SS |
15560 | |
15561 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15562 | error (_("passcount command requires an " |
15563 | "argument (count + optional TP num)")); | |
1042e4c0 | 15564 | |
4a64f543 | 15565 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15566 | |
529480d0 | 15567 | args = skip_spaces (args); |
1042e4c0 SS |
15568 | if (*args && strncasecmp (args, "all", 3) == 0) |
15569 | { | |
d9b3f62e PA |
15570 | struct breakpoint *b; |
15571 | ||
1042e4c0 | 15572 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15573 | if (*args) |
15574 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15575 | |
d9b3f62e | 15576 | ALL_TRACEPOINTS (b) |
197f0a60 | 15577 | { |
d9b3f62e | 15578 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15579 | trace_pass_set_count (t1, count, from_tty); |
15580 | } | |
15581 | } | |
15582 | else if (*args == '\0') | |
1042e4c0 | 15583 | { |
5fa1d40e | 15584 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15585 | if (t1) |
197f0a60 TT |
15586 | trace_pass_set_count (t1, count, from_tty); |
15587 | } | |
15588 | else | |
15589 | { | |
15590 | struct get_number_or_range_state state; | |
15591 | ||
15592 | init_number_or_range (&state, args); | |
15593 | while (!state.finished) | |
1042e4c0 | 15594 | { |
5fa1d40e | 15595 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15596 | if (t1) |
15597 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15598 | } |
15599 | } | |
1042e4c0 SS |
15600 | } |
15601 | ||
d9b3f62e | 15602 | struct tracepoint * |
1042e4c0 SS |
15603 | get_tracepoint (int num) |
15604 | { | |
15605 | struct breakpoint *t; | |
15606 | ||
15607 | ALL_TRACEPOINTS (t) | |
15608 | if (t->number == num) | |
d9b3f62e | 15609 | return (struct tracepoint *) t; |
1042e4c0 SS |
15610 | |
15611 | return NULL; | |
15612 | } | |
15613 | ||
d5551862 SS |
15614 | /* Find the tracepoint with the given target-side number (which may be |
15615 | different from the tracepoint number after disconnecting and | |
15616 | reconnecting). */ | |
15617 | ||
d9b3f62e | 15618 | struct tracepoint * |
d5551862 SS |
15619 | get_tracepoint_by_number_on_target (int num) |
15620 | { | |
d9b3f62e | 15621 | struct breakpoint *b; |
d5551862 | 15622 | |
d9b3f62e PA |
15623 | ALL_TRACEPOINTS (b) |
15624 | { | |
15625 | struct tracepoint *t = (struct tracepoint *) b; | |
15626 | ||
15627 | if (t->number_on_target == num) | |
15628 | return t; | |
15629 | } | |
d5551862 SS |
15630 | |
15631 | return NULL; | |
15632 | } | |
15633 | ||
1042e4c0 | 15634 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15635 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15636 | If the argument is missing, the most recent tracepoint |
15637 | (tracepoint_count) is returned. */ | |
15638 | ||
d9b3f62e | 15639 | struct tracepoint * |
197f0a60 | 15640 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15641 | struct get_number_or_range_state *state) |
1042e4c0 | 15642 | { |
1042e4c0 SS |
15643 | struct breakpoint *t; |
15644 | int tpnum; | |
15645 | char *instring = arg == NULL ? NULL : *arg; | |
15646 | ||
197f0a60 TT |
15647 | if (state) |
15648 | { | |
15649 | gdb_assert (!state->finished); | |
15650 | tpnum = get_number_or_range (state); | |
15651 | } | |
15652 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15653 | tpnum = tracepoint_count; |
1042e4c0 | 15654 | else |
197f0a60 | 15655 | tpnum = get_number (arg); |
1042e4c0 SS |
15656 | |
15657 | if (tpnum <= 0) | |
15658 | { | |
15659 | if (instring && *instring) | |
15660 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15661 | instring); | |
15662 | else | |
5fa1d40e | 15663 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15664 | return NULL; |
15665 | } | |
15666 | ||
15667 | ALL_TRACEPOINTS (t) | |
15668 | if (t->number == tpnum) | |
15669 | { | |
d9b3f62e | 15670 | return (struct tracepoint *) t; |
1042e4c0 SS |
15671 | } |
15672 | ||
1042e4c0 SS |
15673 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15674 | return NULL; | |
15675 | } | |
15676 | ||
d9b3f62e PA |
15677 | void |
15678 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15679 | { | |
15680 | if (b->thread != -1) | |
15681 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15682 | ||
15683 | if (b->task != 0) | |
15684 | fprintf_unfiltered (fp, " task %d", b->task); | |
15685 | ||
15686 | fprintf_unfiltered (fp, "\n"); | |
15687 | } | |
15688 | ||
6149aea9 PA |
15689 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15690 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15691 | on each breakpoint and only include the ones for which it returns | |
15692 | non-zero. */ | |
15693 | ||
1042e4c0 | 15694 | static void |
6149aea9 PA |
15695 | save_breakpoints (char *filename, int from_tty, |
15696 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15697 | { |
15698 | struct breakpoint *tp; | |
6149aea9 | 15699 | int any = 0; |
1042e4c0 | 15700 | struct cleanup *cleanup; |
a7bdde9e | 15701 | struct ui_file *fp; |
6149aea9 | 15702 | int extra_trace_bits = 0; |
1042e4c0 | 15703 | |
6149aea9 PA |
15704 | if (filename == 0 || *filename == 0) |
15705 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15706 | |
15707 | /* See if we have anything to save. */ | |
6149aea9 | 15708 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15709 | { |
6149aea9 | 15710 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15711 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15712 | continue; |
15713 | ||
15714 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15715 | if (filter && !filter (tp)) | |
15716 | continue; | |
15717 | ||
15718 | any = 1; | |
15719 | ||
15720 | if (is_tracepoint (tp)) | |
15721 | { | |
15722 | extra_trace_bits = 1; | |
15723 | ||
15724 | /* We can stop searching. */ | |
15725 | break; | |
15726 | } | |
1042e4c0 | 15727 | } |
6149aea9 PA |
15728 | |
15729 | if (!any) | |
1042e4c0 | 15730 | { |
6149aea9 | 15731 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15732 | return; |
15733 | } | |
15734 | ||
c718be47 PA |
15735 | filename = tilde_expand (filename); |
15736 | cleanup = make_cleanup (xfree, filename); | |
15737 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15738 | if (!fp) |
6149aea9 PA |
15739 | error (_("Unable to open file '%s' for saving (%s)"), |
15740 | filename, safe_strerror (errno)); | |
a7bdde9e | 15741 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15742 | |
6149aea9 PA |
15743 | if (extra_trace_bits) |
15744 | save_trace_state_variables (fp); | |
8bf6485c | 15745 | |
6149aea9 | 15746 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15747 | { |
6149aea9 | 15748 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15749 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15750 | continue; |
8bf6485c | 15751 | |
6149aea9 PA |
15752 | /* If we have a filter, only save the breakpoints it accepts. */ |
15753 | if (filter && !filter (tp)) | |
15754 | continue; | |
15755 | ||
348d480f | 15756 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15757 | |
6149aea9 PA |
15758 | /* Note, we can't rely on tp->number for anything, as we can't |
15759 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15760 | instead. */ | |
15761 | ||
15762 | if (tp->cond_string) | |
15763 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15764 | ||
15765 | if (tp->ignore_count) | |
15766 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15767 | ||
2d9442cc | 15768 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15769 | { |
6149aea9 | 15770 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15771 | |
79a45e25 | 15772 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15773 | TRY |
1042e4c0 | 15774 | { |
79a45e25 | 15775 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15776 | } |
492d29ea PA |
15777 | CATCH (ex, RETURN_MASK_ALL) |
15778 | { | |
6c63c96a | 15779 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15780 | throw_exception (ex); |
15781 | } | |
15782 | END_CATCH | |
1042e4c0 | 15783 | |
6c63c96a | 15784 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15785 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15786 | } |
6149aea9 PA |
15787 | |
15788 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15789 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15790 | |
15791 | /* If this is a multi-location breakpoint, check if the locations | |
15792 | should be individually disabled. Watchpoint locations are | |
15793 | special, and not user visible. */ | |
15794 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15795 | { | |
15796 | struct bp_location *loc; | |
15797 | int n = 1; | |
15798 | ||
15799 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15800 | if (!loc->enabled) | |
15801 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15802 | } | |
1042e4c0 | 15803 | } |
8bf6485c | 15804 | |
6149aea9 | 15805 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15806 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15807 | ||
1042e4c0 | 15808 | if (from_tty) |
6149aea9 | 15809 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15810 | do_cleanups (cleanup); |
6149aea9 PA |
15811 | } |
15812 | ||
15813 | /* The `save breakpoints' command. */ | |
15814 | ||
15815 | static void | |
15816 | save_breakpoints_command (char *args, int from_tty) | |
15817 | { | |
15818 | save_breakpoints (args, from_tty, NULL); | |
15819 | } | |
15820 | ||
15821 | /* The `save tracepoints' command. */ | |
15822 | ||
15823 | static void | |
15824 | save_tracepoints_command (char *args, int from_tty) | |
15825 | { | |
15826 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15827 | } |
15828 | ||
15829 | /* Create a vector of all tracepoints. */ | |
15830 | ||
15831 | VEC(breakpoint_p) * | |
eeae04df | 15832 | all_tracepoints (void) |
1042e4c0 SS |
15833 | { |
15834 | VEC(breakpoint_p) *tp_vec = 0; | |
15835 | struct breakpoint *tp; | |
15836 | ||
15837 | ALL_TRACEPOINTS (tp) | |
15838 | { | |
15839 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15840 | } | |
15841 | ||
15842 | return tp_vec; | |
15843 | } | |
15844 | ||
c906108c | 15845 | \f |
629500fa KS |
15846 | /* This help string is used to consolidate all the help string for specifying |
15847 | locations used by several commands. */ | |
15848 | ||
15849 | #define LOCATION_HELP_STRING \ | |
15850 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15851 | source filename, function name, label name, and line number.\n\ | |
15852 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15853 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15854 | \"factorial.c:fact:the_top\".\n\ | |
15855 | \n\ | |
15856 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15857 | program. Example: To specify the fourth byte past the start function\n\ | |
15858 | \"main\", use \"*main + 4\".\n\ | |
15859 | \n\ | |
15860 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15861 | syntax to specify location parameters.\n\ | |
15862 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15863 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15864 | -function fact -label the_top\".\n" | |
15865 | ||
4a64f543 MS |
15866 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15867 | commands. It is defined as a macro to prevent duplication. | |
15868 | COMMAND should be a string constant containing the name of the | |
15869 | command. */ | |
629500fa | 15870 | |
31e2b00f | 15871 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15872 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15873 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15874 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15875 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15876 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15877 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15878 | below.\n\ | |
15879 | \n\ | |
dc10affe PA |
15880 | With no LOCATION, uses current execution address of the selected\n\ |
15881 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15882 | \n\ |
15883 | THREADNUM is the number from \"info threads\".\n\ | |
15884 | CONDITION is a boolean expression.\n\ | |
629500fa | 15885 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15886 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15887 | conditions are different.\n\ | |
31e2b00f AS |
15888 | \n\ |
15889 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15890 | ||
44feb3ce TT |
15891 | /* List of subcommands for "catch". */ |
15892 | static struct cmd_list_element *catch_cmdlist; | |
15893 | ||
15894 | /* List of subcommands for "tcatch". */ | |
15895 | static struct cmd_list_element *tcatch_cmdlist; | |
15896 | ||
9ac4176b | 15897 | void |
44feb3ce | 15898 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15899 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15900 | completer_ftype *completer, |
44feb3ce TT |
15901 | void *user_data_catch, |
15902 | void *user_data_tcatch) | |
15903 | { | |
15904 | struct cmd_list_element *command; | |
15905 | ||
15906 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15907 | &catch_cmdlist); | |
15908 | set_cmd_sfunc (command, sfunc); | |
15909 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15910 | set_cmd_completer (command, completer); |
44feb3ce TT |
15911 | |
15912 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15913 | &tcatch_cmdlist); | |
15914 | set_cmd_sfunc (command, sfunc); | |
15915 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15916 | set_cmd_completer (command, completer); |
44feb3ce TT |
15917 | } |
15918 | ||
6149aea9 PA |
15919 | static void |
15920 | save_command (char *arg, int from_tty) | |
15921 | { | |
3e43a32a MS |
15922 | printf_unfiltered (_("\"save\" must be followed by " |
15923 | "the name of a save subcommand.\n")); | |
635c7e8a | 15924 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15925 | } |
15926 | ||
84f4c1fe PM |
15927 | struct breakpoint * |
15928 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15929 | void *data) | |
15930 | { | |
35df4500 | 15931 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15932 | |
35df4500 | 15933 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15934 | { |
15935 | if ((*callback) (b, data)) | |
15936 | return b; | |
15937 | } | |
15938 | ||
15939 | return NULL; | |
15940 | } | |
15941 | ||
0574c78f GB |
15942 | /* Zero if any of the breakpoint's locations could be a location where |
15943 | functions have been inlined, nonzero otherwise. */ | |
15944 | ||
15945 | static int | |
15946 | is_non_inline_function (struct breakpoint *b) | |
15947 | { | |
15948 | /* The shared library event breakpoint is set on the address of a | |
15949 | non-inline function. */ | |
15950 | if (b->type == bp_shlib_event) | |
15951 | return 1; | |
15952 | ||
15953 | return 0; | |
15954 | } | |
15955 | ||
15956 | /* Nonzero if the specified PC cannot be a location where functions | |
15957 | have been inlined. */ | |
15958 | ||
15959 | int | |
09ac7c10 TT |
15960 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15961 | const struct target_waitstatus *ws) | |
0574c78f GB |
15962 | { |
15963 | struct breakpoint *b; | |
15964 | struct bp_location *bl; | |
15965 | ||
15966 | ALL_BREAKPOINTS (b) | |
15967 | { | |
15968 | if (!is_non_inline_function (b)) | |
15969 | continue; | |
15970 | ||
15971 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15972 | { | |
15973 | if (!bl->shlib_disabled | |
09ac7c10 | 15974 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15975 | return 1; |
15976 | } | |
15977 | } | |
15978 | ||
15979 | return 0; | |
15980 | } | |
15981 | ||
2f202fde JK |
15982 | /* Remove any references to OBJFILE which is going to be freed. */ |
15983 | ||
15984 | void | |
15985 | breakpoint_free_objfile (struct objfile *objfile) | |
15986 | { | |
15987 | struct bp_location **locp, *loc; | |
15988 | ||
15989 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15990 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15991 | loc->symtab = NULL; |
15992 | } | |
15993 | ||
2060206e PA |
15994 | void |
15995 | initialize_breakpoint_ops (void) | |
15996 | { | |
15997 | static int initialized = 0; | |
15998 | ||
15999 | struct breakpoint_ops *ops; | |
16000 | ||
16001 | if (initialized) | |
16002 | return; | |
16003 | initialized = 1; | |
16004 | ||
16005 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16006 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16007 | internal and momentary breakpoints, etc.). */ | |
16008 | ops = &bkpt_base_breakpoint_ops; | |
16009 | *ops = base_breakpoint_ops; | |
16010 | ops->re_set = bkpt_re_set; | |
16011 | ops->insert_location = bkpt_insert_location; | |
16012 | ops->remove_location = bkpt_remove_location; | |
16013 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 16014 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 16015 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 16016 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
16017 | |
16018 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16019 | ops = &bkpt_breakpoint_ops; | |
16020 | *ops = bkpt_base_breakpoint_ops; | |
16021 | ops->re_set = bkpt_re_set; | |
16022 | ops->resources_needed = bkpt_resources_needed; | |
16023 | ops->print_it = bkpt_print_it; | |
16024 | ops->print_mention = bkpt_print_mention; | |
16025 | ops->print_recreate = bkpt_print_recreate; | |
16026 | ||
16027 | /* Ranged breakpoints. */ | |
16028 | ops = &ranged_breakpoint_ops; | |
16029 | *ops = bkpt_breakpoint_ops; | |
16030 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16031 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16032 | ops->print_it = print_it_ranged_breakpoint; | |
16033 | ops->print_one = print_one_ranged_breakpoint; | |
16034 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16035 | ops->print_mention = print_mention_ranged_breakpoint; | |
16036 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16037 | ||
16038 | /* Internal breakpoints. */ | |
16039 | ops = &internal_breakpoint_ops; | |
16040 | *ops = bkpt_base_breakpoint_ops; | |
16041 | ops->re_set = internal_bkpt_re_set; | |
16042 | ops->check_status = internal_bkpt_check_status; | |
16043 | ops->print_it = internal_bkpt_print_it; | |
16044 | ops->print_mention = internal_bkpt_print_mention; | |
16045 | ||
16046 | /* Momentary breakpoints. */ | |
16047 | ops = &momentary_breakpoint_ops; | |
16048 | *ops = bkpt_base_breakpoint_ops; | |
16049 | ops->re_set = momentary_bkpt_re_set; | |
16050 | ops->check_status = momentary_bkpt_check_status; | |
16051 | ops->print_it = momentary_bkpt_print_it; | |
16052 | ops->print_mention = momentary_bkpt_print_mention; | |
16053 | ||
e2e4d78b JK |
16054 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16055 | ops = &longjmp_breakpoint_ops; | |
16056 | *ops = momentary_breakpoint_ops; | |
16057 | ops->dtor = longjmp_bkpt_dtor; | |
16058 | ||
55aa24fb SDJ |
16059 | /* Probe breakpoints. */ |
16060 | ops = &bkpt_probe_breakpoint_ops; | |
16061 | *ops = bkpt_breakpoint_ops; | |
16062 | ops->insert_location = bkpt_probe_insert_location; | |
16063 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16064 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16065 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16066 | |
2060206e PA |
16067 | /* Watchpoints. */ |
16068 | ops = &watchpoint_breakpoint_ops; | |
16069 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16070 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16071 | ops->re_set = re_set_watchpoint; |
16072 | ops->insert_location = insert_watchpoint; | |
16073 | ops->remove_location = remove_watchpoint; | |
16074 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16075 | ops->check_status = check_status_watchpoint; | |
16076 | ops->resources_needed = resources_needed_watchpoint; | |
16077 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16078 | ops->print_it = print_it_watchpoint; | |
16079 | ops->print_mention = print_mention_watchpoint; | |
16080 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16081 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16082 | |
16083 | /* Masked watchpoints. */ | |
16084 | ops = &masked_watchpoint_breakpoint_ops; | |
16085 | *ops = watchpoint_breakpoint_ops; | |
16086 | ops->insert_location = insert_masked_watchpoint; | |
16087 | ops->remove_location = remove_masked_watchpoint; | |
16088 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16089 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16090 | ops->print_it = print_it_masked_watchpoint; | |
16091 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16092 | ops->print_mention = print_mention_masked_watchpoint; | |
16093 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16094 | ||
16095 | /* Tracepoints. */ | |
16096 | ops = &tracepoint_breakpoint_ops; | |
16097 | *ops = base_breakpoint_ops; | |
16098 | ops->re_set = tracepoint_re_set; | |
16099 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16100 | ops->print_one_detail = tracepoint_print_one_detail; | |
16101 | ops->print_mention = tracepoint_print_mention; | |
16102 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16103 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16104 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16105 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16106 | |
55aa24fb SDJ |
16107 | /* Probe tracepoints. */ |
16108 | ops = &tracepoint_probe_breakpoint_ops; | |
16109 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16110 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16111 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16112 | |
983af33b SDJ |
16113 | /* Static tracepoints with marker (`-m'). */ |
16114 | ops = &strace_marker_breakpoint_ops; | |
16115 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16116 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16117 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16118 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16119 | |
16120 | /* Fork catchpoints. */ | |
16121 | ops = &catch_fork_breakpoint_ops; | |
16122 | *ops = base_breakpoint_ops; | |
16123 | ops->insert_location = insert_catch_fork; | |
16124 | ops->remove_location = remove_catch_fork; | |
16125 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16126 | ops->print_it = print_it_catch_fork; | |
16127 | ops->print_one = print_one_catch_fork; | |
16128 | ops->print_mention = print_mention_catch_fork; | |
16129 | ops->print_recreate = print_recreate_catch_fork; | |
16130 | ||
16131 | /* Vfork catchpoints. */ | |
16132 | ops = &catch_vfork_breakpoint_ops; | |
16133 | *ops = base_breakpoint_ops; | |
16134 | ops->insert_location = insert_catch_vfork; | |
16135 | ops->remove_location = remove_catch_vfork; | |
16136 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16137 | ops->print_it = print_it_catch_vfork; | |
16138 | ops->print_one = print_one_catch_vfork; | |
16139 | ops->print_mention = print_mention_catch_vfork; | |
16140 | ops->print_recreate = print_recreate_catch_vfork; | |
16141 | ||
16142 | /* Exec catchpoints. */ | |
16143 | ops = &catch_exec_breakpoint_ops; | |
16144 | *ops = base_breakpoint_ops; | |
16145 | ops->dtor = dtor_catch_exec; | |
16146 | ops->insert_location = insert_catch_exec; | |
16147 | ops->remove_location = remove_catch_exec; | |
16148 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16149 | ops->print_it = print_it_catch_exec; | |
16150 | ops->print_one = print_one_catch_exec; | |
16151 | ops->print_mention = print_mention_catch_exec; | |
16152 | ops->print_recreate = print_recreate_catch_exec; | |
16153 | ||
edcc5120 TT |
16154 | /* Solib-related catchpoints. */ |
16155 | ops = &catch_solib_breakpoint_ops; | |
16156 | *ops = base_breakpoint_ops; | |
16157 | ops->dtor = dtor_catch_solib; | |
16158 | ops->insert_location = insert_catch_solib; | |
16159 | ops->remove_location = remove_catch_solib; | |
16160 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16161 | ops->check_status = check_status_catch_solib; | |
16162 | ops->print_it = print_it_catch_solib; | |
16163 | ops->print_one = print_one_catch_solib; | |
16164 | ops->print_mention = print_mention_catch_solib; | |
16165 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16166 | |
16167 | ops = &dprintf_breakpoint_ops; | |
16168 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16169 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16170 | ops->resources_needed = bkpt_resources_needed; |
16171 | ops->print_it = bkpt_print_it; | |
16172 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16173 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16174 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16175 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16176 | } |
16177 | ||
8bfd80db YQ |
16178 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16179 | ||
16180 | static struct cmd_list_element *enablebreaklist = NULL; | |
16181 | ||
c906108c | 16182 | void |
fba45db2 | 16183 | _initialize_breakpoint (void) |
c906108c SS |
16184 | { |
16185 | struct cmd_list_element *c; | |
16186 | ||
2060206e PA |
16187 | initialize_breakpoint_ops (); |
16188 | ||
84acb35a | 16189 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16190 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16191 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16192 | |
55aa24fb SDJ |
16193 | breakpoint_objfile_key |
16194 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16195 | |
c906108c SS |
16196 | breakpoint_chain = 0; |
16197 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16198 | before a breakpoint is set. */ | |
16199 | breakpoint_count = 0; | |
16200 | ||
1042e4c0 SS |
16201 | tracepoint_count = 0; |
16202 | ||
1bedd215 AC |
16203 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16204 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16205 | Usage is `ignore N COUNT'.")); | |
c906108c | 16206 | |
1bedd215 AC |
16207 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16208 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16209 | Give breakpoint number as argument after \"commands\".\n\ |
16210 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16211 | The commands themselves follow starting on the next line.\n\ | |
16212 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16213 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16214 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16215 | |
d55637df | 16216 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16217 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16218 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16219 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16220 | set_cmd_completer (c, condition_completer); |
c906108c | 16221 | |
1bedd215 | 16222 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16223 | Set a temporary breakpoint.\n\ |
c906108c SS |
16224 | Like \"break\" except the breakpoint is only temporary,\n\ |
16225 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16226 | by using \"enable delete\" on the breakpoint number.\n\ |
16227 | \n" | |
16228 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16229 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16230 | |
1bedd215 | 16231 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16232 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16233 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16234 | some target hardware may not have this support.\n\ |
16235 | \n" | |
16236 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16237 | set_cmd_completer (c, location_completer); |
c906108c | 16238 | |
1bedd215 | 16239 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16240 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16241 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16242 | so it will be deleted when hit.\n\ |
16243 | \n" | |
16244 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16245 | set_cmd_completer (c, location_completer); |
c906108c | 16246 | |
1bedd215 AC |
16247 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16248 | Enable some breakpoints.\n\ | |
c906108c SS |
16249 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16250 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16251 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16252 | With a subcommand you can enable temporarily."), |
c906108c | 16253 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16254 | |
16255 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16256 | ||
84951ab5 | 16257 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16258 | Enable some breakpoints.\n\ |
c906108c SS |
16259 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16260 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16261 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16262 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16263 | |
1a966eab AC |
16264 | add_cmd ("once", no_class, enable_once_command, _("\ |
16265 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16266 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16267 | &enablebreaklist); |
16268 | ||
1a966eab AC |
16269 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16270 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16271 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16272 | &enablebreaklist); |
16273 | ||
816338b5 SS |
16274 | add_cmd ("count", no_class, enable_count_command, _("\ |
16275 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16276 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16277 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16278 | &enablebreaklist); | |
16279 | ||
1a966eab AC |
16280 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16281 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16282 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16283 | &enablelist); |
16284 | ||
1a966eab AC |
16285 | add_cmd ("once", no_class, enable_once_command, _("\ |
16286 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16287 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16288 | &enablelist); |
16289 | ||
16290 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16291 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16292 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16293 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16294 | &enablelist); |
16295 | ||
1bedd215 AC |
16296 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16297 | Disable some breakpoints.\n\ | |
c906108c SS |
16298 | Arguments are breakpoint numbers with spaces in between.\n\ |
16299 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16300 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16301 | &disablelist, "disable ", 1, &cmdlist); |
16302 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16303 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16304 | |
1a966eab AC |
16305 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16306 | Disable some breakpoints.\n\ | |
c906108c SS |
16307 | Arguments are breakpoint numbers with spaces in between.\n\ |
16308 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16309 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16310 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16311 | &disablelist); |
16312 | ||
1bedd215 AC |
16313 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16314 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16315 | Arguments are breakpoint numbers with spaces in between.\n\ |
16316 | To delete all breakpoints, give no argument.\n\ | |
16317 | \n\ | |
16318 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16319 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16320 | &deletelist, "delete ", 1, &cmdlist); |
16321 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16322 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16323 | |
1a966eab AC |
16324 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16325 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16326 | Arguments are breakpoint numbers with spaces in between.\n\ |
16327 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16328 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16329 | &deletelist); |
16330 | ||
1bedd215 | 16331 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16332 | Clear breakpoint at specified location.\n\ |
16333 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16334 | \n\ |
16335 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16336 | is executing in.\n" |
16337 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16338 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16339 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16340 | |
1bedd215 | 16341 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16342 | Set breakpoint at specified location.\n" |
31e2b00f | 16343 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16344 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16345 | |
c906108c SS |
16346 | add_com_alias ("b", "break", class_run, 1); |
16347 | add_com_alias ("br", "break", class_run, 1); | |
16348 | add_com_alias ("bre", "break", class_run, 1); | |
16349 | add_com_alias ("brea", "break", class_run, 1); | |
16350 | ||
c906108c SS |
16351 | if (dbx_commands) |
16352 | { | |
1bedd215 AC |
16353 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16354 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16355 | &stoplist, "stop ", 1, &cmdlist); |
16356 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16357 | _("Break in function or address."), &stoplist); |
c5aa993b | 16358 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16359 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16360 | add_com ("status", class_info, breakpoints_info, _("\ |
16361 | Status of user-settable breakpoints, or breakpoint number NUMBER.\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 SS |
16375 | } |
16376 | ||
1bedd215 | 16377 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16378 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16379 | The \"Type\" column indicates one of:\n\ |
16380 | \tbreakpoint - normal breakpoint\n\ | |
16381 | \twatchpoint - watchpoint\n\ | |
16382 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16383 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16384 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16385 | address and file/line number respectively.\n\ |
16386 | \n\ | |
16387 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16388 | are set to the address of the last breakpoint listed unless the command\n\ |
16389 | is prefixed with \"server \".\n\n\ | |
c906108c | 16390 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16391 | breakpoint set.")); |
c906108c | 16392 | |
6b04bdb7 MS |
16393 | add_info_alias ("b", "breakpoints", 1); |
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); | |
c5aa993b | 16455 | |
1bedd215 AC |
16456 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16457 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16458 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16459 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16460 | an expression changes.\n\ |
16461 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16462 | the memory to which it refers.")); | |
65d12d83 | 16463 | set_cmd_completer (c, expression_completer); |
c906108c | 16464 | |
1bedd215 AC |
16465 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16466 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16467 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16468 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16469 | an expression is read.\n\ |
16470 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16471 | the memory to which it refers.")); | |
65d12d83 | 16472 | set_cmd_completer (c, expression_completer); |
c906108c | 16473 | |
1bedd215 AC |
16474 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16475 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16476 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16477 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16478 | an expression is either read or written.\n\ |
16479 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16480 | the memory to which it refers.")); | |
65d12d83 | 16481 | set_cmd_completer (c, expression_completer); |
c906108c | 16482 | |
d77f58be | 16483 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16484 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16485 | |
920d2a44 AC |
16486 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16487 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16488 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16489 | &can_use_hw_watchpoints, _("\ | |
16490 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16491 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16492 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16493 | such is available. (However, any hardware watchpoints that were\n\ | |
16494 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16495 | hardware.)"), |
16496 | NULL, | |
920d2a44 | 16497 | show_can_use_hw_watchpoints, |
85c07804 | 16498 | &setlist, &showlist); |
c906108c SS |
16499 | |
16500 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16501 | |
1042e4c0 SS |
16502 | /* Tracepoint manipulation commands. */ |
16503 | ||
16504 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16505 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16506 | \n" |
16507 | BREAK_ARGS_HELP ("trace") "\n\ | |
16508 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16509 | set_cmd_completer (c, location_completer); | |
16510 | ||
16511 | add_com_alias ("tp", "trace", class_alias, 0); | |
16512 | add_com_alias ("tr", "trace", class_alias, 1); | |
16513 | add_com_alias ("tra", "trace", class_alias, 1); | |
16514 | add_com_alias ("trac", "trace", class_alias, 1); | |
16515 | ||
7a697b8d | 16516 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16517 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16518 | \n" |
16519 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16520 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16521 | set_cmd_completer (c, location_completer); | |
16522 | ||
0fb4aa4b | 16523 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16524 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16525 | \n\ |
16526 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16527 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16528 | or -m MARKER_ID.\n\n\ | |
16529 | If a marker id is specified, probe the marker with that name. With\n\ | |
16530 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16531 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16532 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16533 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16534 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16535 | \n\ | |
16536 | CONDITION is a boolean expression.\n\ | |
629500fa | 16537 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16538 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16539 | conditions are different.\n\ | |
0fb4aa4b PA |
16540 | \n\ |
16541 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16542 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16543 | set_cmd_completer (c, location_completer); | |
16544 | ||
1042e4c0 | 16545 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16546 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16547 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16548 | last tracepoint set.")); | |
16549 | ||
16550 | add_info_alias ("tp", "tracepoints", 1); | |
16551 | ||
16552 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16553 | Delete specified tracepoints.\n\ | |
16554 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16555 | No argument means delete all tracepoints."), | |
16556 | &deletelist); | |
7e20dfcd | 16557 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16558 | |
16559 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16560 | Disable specified tracepoints.\n\ | |
16561 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16562 | No argument means disable all tracepoints."), | |
16563 | &disablelist); | |
16564 | deprecate_cmd (c, "disable"); | |
16565 | ||
16566 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16567 | Enable specified tracepoints.\n\ | |
16568 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16569 | No argument means enable all tracepoints."), | |
16570 | &enablelist); | |
16571 | deprecate_cmd (c, "enable"); | |
16572 | ||
16573 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16574 | Set the passcount for a tracepoint.\n\ | |
16575 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16576 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16577 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16578 | ||
6149aea9 PA |
16579 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16580 | _("Save breakpoint definitions as a script."), | |
16581 | &save_cmdlist, "save ", | |
16582 | 0/*allow-unknown*/, &cmdlist); | |
16583 | ||
16584 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16585 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16586 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16587 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16588 | session to restore them."), | |
16589 | &save_cmdlist); | |
16590 | set_cmd_completer (c, filename_completer); | |
16591 | ||
16592 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16593 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16594 | Use the 'source' command in another debug session to restore them."), |
16595 | &save_cmdlist); | |
1042e4c0 SS |
16596 | set_cmd_completer (c, filename_completer); |
16597 | ||
6149aea9 PA |
16598 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16599 | deprecate_cmd (c, "save tracepoints"); | |
16600 | ||
1bedd215 | 16601 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16602 | Breakpoint specific settings\n\ |
16603 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16604 | pending breakpoint behavior"), |
fa8d40ab JJ |
16605 | &breakpoint_set_cmdlist, "set breakpoint ", |
16606 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16607 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16608 | Breakpoint specific settings\n\ |
16609 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16610 | pending breakpoint behavior"), |
fa8d40ab JJ |
16611 | &breakpoint_show_cmdlist, "show breakpoint ", |
16612 | 0/*allow-unknown*/, &showlist); | |
16613 | ||
7915a72c AC |
16614 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16615 | &pending_break_support, _("\ | |
16616 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16617 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16618 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16619 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16620 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16621 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16622 | NULL, |
920d2a44 | 16623 | show_pending_break_support, |
6e1d7d6c AC |
16624 | &breakpoint_set_cmdlist, |
16625 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16626 | |
16627 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16628 | |
16629 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16630 | &automatic_hardware_breakpoints, _("\ | |
16631 | Set automatic usage of hardware breakpoints."), _("\ | |
16632 | Show automatic usage of hardware breakpoints."), _("\ | |
16633 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16634 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16635 | a warning will be emitted for such breakpoints."), | |
16636 | NULL, | |
16637 | show_automatic_hardware_breakpoints, | |
16638 | &breakpoint_set_cmdlist, | |
16639 | &breakpoint_show_cmdlist); | |
74960c60 | 16640 | |
a25a5a45 PA |
16641 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16642 | &always_inserted_mode, _("\ | |
74960c60 VP |
16643 | Set mode for inserting breakpoints."), _("\ |
16644 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16645 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16646 | they're created, kept inserted even when execution stops, and removed\n\ | |
16647 | only when the user deletes them. When this mode is off (the default),\n\ | |
16648 | breakpoints are inserted only when execution continues, and removed\n\ | |
16649 | when execution stops."), | |
72d0e2c5 YQ |
16650 | NULL, |
16651 | &show_always_inserted_mode, | |
16652 | &breakpoint_set_cmdlist, | |
16653 | &breakpoint_show_cmdlist); | |
f1310107 | 16654 | |
b775012e LM |
16655 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16656 | condition_evaluation_enums, | |
16657 | &condition_evaluation_mode_1, _("\ | |
16658 | Set mode of breakpoint condition evaluation."), _("\ | |
16659 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16660 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16661 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16662 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16663 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16664 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16665 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16666 | be set to \"gdb\""), | |
16667 | &set_condition_evaluation_mode, | |
16668 | &show_condition_evaluation_mode, | |
16669 | &breakpoint_set_cmdlist, | |
16670 | &breakpoint_show_cmdlist); | |
16671 | ||
f1310107 TJB |
16672 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16673 | Set a breakpoint for an address range.\n\ | |
16674 | break-range START-LOCATION, END-LOCATION\n\ | |
16675 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16676 | LINENUM, for that line in the current file,\n\ | |
16677 | FILE:LINENUM, for that line in that file,\n\ | |
16678 | +OFFSET, for that number of lines after the current line\n\ | |
16679 | or the start of the range\n\ | |
16680 | FUNCTION, for the first line in that function,\n\ | |
16681 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16682 | *ADDRESS, for the instruction at that address.\n\ | |
16683 | \n\ | |
16684 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16685 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16686 | range (including START-LOCATION and END-LOCATION).")); | |
16687 | ||
e7e0cddf | 16688 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16689 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16690 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16691 | location may be a linespec, explicit, or address location.\n" |
16692 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16693 | set_cmd_completer (c, location_completer); |
16694 | ||
16695 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16696 | dprintf_style_enums, &dprintf_style, _("\ | |
16697 | Set the style of usage for dynamic printf."), _("\ | |
16698 | Show the style of usage for dynamic printf."), _("\ | |
16699 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16700 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16701 | console, as with the \"printf\" command.\n\ | |
16702 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16703 | program; by default printf(), but you can choose a different function or\n\ | |
16704 | output stream by setting dprintf-function and dprintf-channel."), | |
16705 | update_dprintf_commands, NULL, | |
16706 | &setlist, &showlist); | |
16707 | ||
16708 | dprintf_function = xstrdup ("printf"); | |
16709 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16710 | &dprintf_function, _("\ | |
16711 | Set the function to use for dynamic printf"), _("\ | |
16712 | Show the function to use for dynamic printf"), NULL, | |
16713 | update_dprintf_commands, NULL, | |
16714 | &setlist, &showlist); | |
16715 | ||
16716 | dprintf_channel = xstrdup (""); | |
16717 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16718 | &dprintf_channel, _("\ | |
16719 | Set the channel to use for dynamic printf"), _("\ | |
16720 | Show the channel to use for dynamic printf"), NULL, | |
16721 | update_dprintf_commands, NULL, | |
16722 | &setlist, &showlist); | |
16723 | ||
d3ce09f5 SS |
16724 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16725 | &disconnected_dprintf, _("\ | |
16726 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16727 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16728 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16729 | even if GDB disconnects or detaches from the target."), | |
16730 | NULL, | |
16731 | NULL, | |
16732 | &setlist, &showlist); | |
16733 | ||
16734 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16735 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16736 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16737 | ||
765dc015 | 16738 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16739 | |
16740 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16741 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16742 | } |