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 | |
0bde7532 | 204 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
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 | 1606 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1607 | size_t i; |
876fa593 | 1608 | |
4a64f543 MS |
1609 | /* Find BC_L which is a leftmost element which may affect BUF |
1610 | content. It is safe to report lower value but a failure to | |
1611 | report higher one. */ | |
876fa593 JK |
1612 | |
1613 | bc_l = 0; | |
1614 | bc_r = bp_location_count; | |
1615 | while (bc_l + 1 < bc_r) | |
1616 | { | |
35df4500 | 1617 | struct bp_location *bl; |
876fa593 JK |
1618 | |
1619 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1620 | bl = bp_location[bc]; |
876fa593 | 1621 | |
4a64f543 MS |
1622 | /* Check first BL->ADDRESS will not overflow due to the added |
1623 | constant. Then advance the left boundary only if we are sure | |
1624 | the BC element can in no way affect the BUF content (MEMADDR | |
1625 | to MEMADDR + LEN range). | |
876fa593 | 1626 | |
4a64f543 MS |
1627 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1628 | offset so that we cannot miss a breakpoint with its shadow | |
1629 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1630 | |
35df4500 TJB |
1631 | if ((bl->address + bp_location_shadow_len_after_address_max |
1632 | >= bl->address) | |
1633 | && (bl->address + bp_location_shadow_len_after_address_max | |
1634 | <= memaddr)) | |
876fa593 JK |
1635 | bc_l = bc; |
1636 | else | |
1637 | bc_r = bc; | |
1638 | } | |
1639 | ||
128070bb PA |
1640 | /* Due to the binary search above, we need to make sure we pick the |
1641 | first location that's at BC_L's address. E.g., if there are | |
1642 | multiple locations at the same address, BC_L may end up pointing | |
1643 | at a duplicate location, and miss the "master"/"inserted" | |
1644 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1645 | B: | |
1646 | ||
1647 | L1@A, L2@A, L3@B, ... | |
1648 | ||
1649 | BC_L could end up pointing at location L2, while the "master" | |
1650 | location could be L1. Since the `loc->inserted' flag is only set | |
1651 | on "master" locations, we'd forget to restore the shadow of L1 | |
1652 | and L2. */ | |
1653 | while (bc_l > 0 | |
1654 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1655 | bc_l--; | |
1656 | ||
876fa593 JK |
1657 | /* Now do full processing of the found relevant range of elements. */ |
1658 | ||
1659 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1660 | { |
35df4500 | 1661 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1662 | CORE_ADDR bp_addr = 0; |
1663 | int bp_size = 0; | |
1664 | int bptoffset = 0; | |
1665 | ||
35df4500 TJB |
1666 | /* bp_location array has BL->OWNER always non-NULL. */ |
1667 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1668 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1669 | bl->owner->number); |
ffce0d52 | 1670 | |
e5dd4106 | 1671 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1672 | content. */ |
1673 | ||
35df4500 TJB |
1674 | if (bl->address >= bp_location_placed_address_before_address_max |
1675 | && memaddr + len <= (bl->address | |
1676 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1677 | break; |
1678 | ||
35df4500 | 1679 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1680 | continue; |
6c95b8df | 1681 | |
9d497a19 PA |
1682 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1683 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1684 | } | |
c906108c | 1685 | } |
9d497a19 | 1686 | |
c906108c | 1687 | \f |
c5aa993b | 1688 | |
b775012e LM |
1689 | /* Return true if BPT is either a software breakpoint or a hardware |
1690 | breakpoint. */ | |
1691 | ||
1692 | int | |
1693 | is_breakpoint (const struct breakpoint *bpt) | |
1694 | { | |
1695 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1696 | || bpt->type == bp_hardware_breakpoint |
1697 | || bpt->type == bp_dprintf); | |
b775012e LM |
1698 | } |
1699 | ||
60e1c644 PA |
1700 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1701 | ||
a5606eee | 1702 | static int |
d77f58be | 1703 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1704 | { |
1705 | return (bpt->type == bp_hardware_watchpoint | |
1706 | || bpt->type == bp_read_watchpoint | |
1707 | || bpt->type == bp_access_watchpoint); | |
1708 | } | |
7270d8f2 | 1709 | |
60e1c644 PA |
1710 | /* Return true if BPT is of any watchpoint kind, hardware or |
1711 | software. */ | |
1712 | ||
3a5c3e22 | 1713 | int |
d77f58be | 1714 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1715 | { |
1716 | return (is_hardware_watchpoint (bpt) | |
1717 | || bpt->type == bp_watchpoint); | |
1718 | } | |
1719 | ||
3a5c3e22 PA |
1720 | /* Returns true if the current thread and its running state are safe |
1721 | to evaluate or update watchpoint B. Watchpoints on local | |
1722 | expressions need to be evaluated in the context of the thread that | |
1723 | was current when the watchpoint was created, and, that thread needs | |
1724 | to be stopped to be able to select the correct frame context. | |
1725 | Watchpoints on global expressions can be evaluated on any thread, | |
1726 | and in any state. It is presently left to the target allowing | |
1727 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1728 | |
1729 | static int | |
3a5c3e22 | 1730 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1731 | { |
d0d8b0c6 JK |
1732 | return (b->base.pspace == current_program_space |
1733 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1734 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1735 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1736 | } |
1737 | ||
d0fb5eae JK |
1738 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1739 | associated bp_watchpoint_scope breakpoint. */ | |
1740 | ||
1741 | static void | |
3a5c3e22 | 1742 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1743 | { |
3a5c3e22 | 1744 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1745 | |
1746 | if (b->related_breakpoint != b) | |
1747 | { | |
1748 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1749 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1750 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1751 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1752 | b->related_breakpoint = b; | |
1753 | } | |
1754 | b->disposition = disp_del_at_next_stop; | |
1755 | } | |
1756 | ||
bb9d5f81 PP |
1757 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1758 | watchpoint W. */ | |
1759 | ||
1760 | static struct value * | |
1761 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1762 | { | |
1763 | struct value *bit_val; | |
1764 | ||
1765 | if (val == NULL) | |
1766 | return NULL; | |
1767 | ||
1768 | bit_val = allocate_value (value_type (val)); | |
1769 | ||
1770 | unpack_value_bitfield (bit_val, | |
1771 | w->val_bitpos, | |
1772 | w->val_bitsize, | |
1773 | value_contents_for_printing (val), | |
1774 | value_offset (val), | |
1775 | val); | |
1776 | ||
1777 | return bit_val; | |
1778 | } | |
1779 | ||
c6d81124 PA |
1780 | /* Allocate a dummy location and add it to B, which must be a software |
1781 | watchpoint. This is required because even if a software watchpoint | |
1782 | is not watching any memory, bpstat_stop_status requires a location | |
1783 | to be able to report stops. */ | |
1784 | ||
1785 | static void | |
1786 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1787 | struct program_space *pspace) | |
1788 | { | |
1789 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1790 | ||
1791 | b->loc = allocate_bp_location (b); | |
1792 | b->loc->pspace = pspace; | |
1793 | b->loc->address = -1; | |
1794 | b->loc->length = -1; | |
1795 | } | |
1796 | ||
1797 | /* Returns true if B is a software watchpoint that is not watching any | |
1798 | memory (e.g., "watch $pc"). */ | |
1799 | ||
1800 | static int | |
1801 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1802 | { | |
1803 | return (b->type == bp_watchpoint | |
1804 | && b->loc != NULL | |
1805 | && b->loc->next == NULL | |
1806 | && b->loc->address == -1 | |
1807 | && b->loc->length == -1); | |
1808 | } | |
1809 | ||
567e1b4e JB |
1810 | /* Assuming that B is a watchpoint: |
1811 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1812 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1813 | - Evaluate the condition if there is one, and store the result |
1814 | in b->loc->cond. | |
a5606eee VP |
1815 | - Update the list of values that must be watched in B->loc. |
1816 | ||
4a64f543 MS |
1817 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1818 | nothing. If this is local watchpoint that is out of scope, delete | |
1819 | it. | |
1820 | ||
1821 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1822 | removed + inserted on each stop here. Normal breakpoints must | |
1823 | never be removed because they might be missed by a running thread | |
1824 | when debugging in non-stop mode. On the other hand, hardware | |
1825 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1826 | to each LWP since they are stored in each LWP's hardware debug | |
1827 | registers. Therefore, such LWP must be stopped first in order to | |
1828 | be able to modify its hardware watchpoints. | |
1829 | ||
1830 | Hardware watchpoints must be reset exactly once after being | |
1831 | presented to the user. It cannot be done sooner, because it would | |
1832 | reset the data used to present the watchpoint hit to the user. And | |
1833 | it must not be done later because it could display the same single | |
1834 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1835 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1836 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1837 | not user-visible - its hit is suppressed if the memory content has | |
1838 | not changed. | |
1839 | ||
1840 | The following constraints influence the location where we can reset | |
1841 | hardware watchpoints: | |
1842 | ||
1843 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1844 | called several times when GDB stops. | |
1845 | ||
1846 | [linux] | |
1847 | * Multiple hardware watchpoints can be hit at the same time, | |
1848 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1849 | hit at a time as the reason for stopping, and all the other hits | |
1850 | are presented later, one after the other, each time the user | |
1851 | requests the execution to be resumed. Execution is not resumed | |
1852 | for the threads still having pending hit event stored in | |
1853 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1854 | the inferior on the first stop the thread hit event is kept being | |
1855 | reported from its cached value by linux_nat_stopped_data_address | |
1856 | until the real thread resume happens after the watchpoint gets | |
1857 | presented and thus its LWP_INFO->STATUS gets reset. | |
1858 | ||
1859 | Therefore the hardware watchpoint hit can get safely reset on the | |
1860 | watchpoint removal from inferior. */ | |
a79d3c27 | 1861 | |
b40ce68a | 1862 | static void |
3a5c3e22 | 1863 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1864 | { |
a5606eee | 1865 | int within_current_scope; |
a5606eee | 1866 | struct frame_id saved_frame_id; |
66076460 | 1867 | int frame_saved; |
a5606eee | 1868 | |
f6bc2008 PA |
1869 | /* If this is a local watchpoint, we only want to check if the |
1870 | watchpoint frame is in scope if the current thread is the thread | |
1871 | that was used to create the watchpoint. */ | |
1872 | if (!watchpoint_in_thread_scope (b)) | |
1873 | return; | |
1874 | ||
3a5c3e22 | 1875 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1876 | return; |
1877 | ||
66076460 | 1878 | frame_saved = 0; |
a5606eee VP |
1879 | |
1880 | /* Determine if the watchpoint is within scope. */ | |
1881 | if (b->exp_valid_block == NULL) | |
1882 | within_current_scope = 1; | |
1883 | else | |
1884 | { | |
b5db5dfc UW |
1885 | struct frame_info *fi = get_current_frame (); |
1886 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1887 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1888 | ||
c9cf6e20 MG |
1889 | /* If we're at a point where the stack has been destroyed |
1890 | (e.g. in a function epilogue), unwinding may not work | |
1891 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1892 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1893 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1894 | return; |
66076460 DJ |
1895 | |
1896 | /* Save the current frame's ID so we can restore it after | |
1897 | evaluating the watchpoint expression on its own frame. */ | |
1898 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1899 | took a frame parameter, so that we didn't have to change the | |
1900 | selected frame. */ | |
1901 | frame_saved = 1; | |
1902 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1903 | ||
a5606eee VP |
1904 | fi = frame_find_by_id (b->watchpoint_frame); |
1905 | within_current_scope = (fi != NULL); | |
1906 | if (within_current_scope) | |
1907 | select_frame (fi); | |
1908 | } | |
1909 | ||
b5db5dfc UW |
1910 | /* We don't free locations. They are stored in the bp_location array |
1911 | and update_global_location_list will eventually delete them and | |
1912 | remove breakpoints if needed. */ | |
3a5c3e22 | 1913 | b->base.loc = NULL; |
b5db5dfc | 1914 | |
a5606eee VP |
1915 | if (within_current_scope && reparse) |
1916 | { | |
bbc13ae3 | 1917 | const char *s; |
d63d0675 | 1918 | |
a5606eee VP |
1919 | if (b->exp) |
1920 | { | |
1921 | xfree (b->exp); | |
1922 | b->exp = NULL; | |
1923 | } | |
d63d0675 | 1924 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1925 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1926 | /* If the meaning of expression itself changed, the old value is |
1927 | no longer relevant. We don't want to report a watchpoint hit | |
1928 | to the user when the old value and the new value may actually | |
1929 | be completely different objects. */ | |
1930 | value_free (b->val); | |
fa4727a6 DJ |
1931 | b->val = NULL; |
1932 | b->val_valid = 0; | |
60e1c644 PA |
1933 | |
1934 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1935 | expression is stored in the breakpoint object, not in the | |
1936 | locations (re)created below. */ | |
3a5c3e22 | 1937 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1938 | { |
1939 | if (b->cond_exp != NULL) | |
1940 | { | |
1941 | xfree (b->cond_exp); | |
1942 | b->cond_exp = NULL; | |
1943 | } | |
1944 | ||
3a5c3e22 | 1945 | s = b->base.cond_string; |
1bb9788d | 1946 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1947 | } |
a5606eee | 1948 | } |
a5606eee VP |
1949 | |
1950 | /* If we failed to parse the expression, for example because | |
1951 | it refers to a global variable in a not-yet-loaded shared library, | |
1952 | don't try to insert watchpoint. We don't automatically delete | |
1953 | such watchpoint, though, since failure to parse expression | |
1954 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1955 | if (!target_has_execution) |
2d134ed3 PA |
1956 | { |
1957 | /* Without execution, memory can't change. No use to try and | |
1958 | set watchpoint locations. The watchpoint will be reset when | |
1959 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1960 | if (!can_use_hw_watchpoints) |
1961 | { | |
1962 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1963 | b->base.type = bp_watchpoint; | |
1964 | else | |
638aa5a1 AB |
1965 | error (_("Can't set read/access watchpoint when " |
1966 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1967 | } |
2d134ed3 PA |
1968 | } |
1969 | else if (within_current_scope && b->exp) | |
a5606eee | 1970 | { |
0cf6dd15 | 1971 | int pc = 0; |
fa4727a6 | 1972 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1973 | struct program_space *frame_pspace; |
a5606eee | 1974 | |
3a1115a0 | 1975 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1976 | |
a5606eee VP |
1977 | /* Avoid setting b->val if it's already set. The meaning of |
1978 | b->val is 'the last value' user saw, and we should update | |
1979 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1980 | happens, the code that reports it updates b->val directly. |
1981 | We don't keep track of the memory value for masked | |
1982 | watchpoints. */ | |
3a5c3e22 | 1983 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1984 | { |
bb9d5f81 PP |
1985 | if (b->val_bitsize != 0) |
1986 | { | |
1987 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1988 | if (v != NULL) | |
1989 | release_value (v); | |
1990 | } | |
fa4727a6 DJ |
1991 | b->val = v; |
1992 | b->val_valid = 1; | |
1993 | } | |
a5606eee | 1994 | |
2d134ed3 PA |
1995 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1996 | ||
a5606eee | 1997 | /* Look at each value on the value chain. */ |
9fa40276 | 1998 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1999 | { |
2000 | /* If it's a memory location, and GDB actually needed | |
2001 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
2002 | must watch it. If the first value returned is |
2003 | still lazy, that means an error occurred reading it; | |
2004 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2005 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2006 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2007 | { |
2008 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2009 | |
a5606eee VP |
2010 | /* We only watch structs and arrays if user asked |
2011 | for it explicitly, never if they just happen to | |
2012 | appear in the middle of some value chain. */ | |
fa4727a6 | 2013 | if (v == result |
a5606eee VP |
2014 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2015 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2016 | { | |
2017 | CORE_ADDR addr; | |
f486487f | 2018 | enum target_hw_bp_type type; |
a5606eee | 2019 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2020 | int bitpos = 0, bitsize = 0; |
2021 | ||
2022 | if (value_bitsize (v) != 0) | |
2023 | { | |
2024 | /* Extract the bit parameters out from the bitfield | |
2025 | sub-expression. */ | |
2026 | bitpos = value_bitpos (v); | |
2027 | bitsize = value_bitsize (v); | |
2028 | } | |
2029 | else if (v == result && b->val_bitsize != 0) | |
2030 | { | |
2031 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2032 | lvalue whose bit parameters are saved in the fields | |
2033 | VAL_BITPOS and VAL_BITSIZE. */ | |
2034 | bitpos = b->val_bitpos; | |
2035 | bitsize = b->val_bitsize; | |
2036 | } | |
a5606eee | 2037 | |
42ae5230 | 2038 | addr = value_address (v); |
bb9d5f81 PP |
2039 | if (bitsize != 0) |
2040 | { | |
2041 | /* Skip the bytes that don't contain the bitfield. */ | |
2042 | addr += bitpos / 8; | |
2043 | } | |
2044 | ||
a5606eee | 2045 | type = hw_write; |
3a5c3e22 | 2046 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2047 | type = hw_read; |
3a5c3e22 | 2048 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2049 | type = hw_access; |
3a5c3e22 PA |
2050 | |
2051 | loc = allocate_bp_location (&b->base); | |
2052 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2053 | ; |
2054 | *tmp = loc; | |
a6d9a66e | 2055 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2056 | |
2057 | loc->pspace = frame_pspace; | |
a5606eee | 2058 | loc->address = addr; |
bb9d5f81 PP |
2059 | |
2060 | if (bitsize != 0) | |
2061 | { | |
2062 | /* Just cover the bytes that make up the bitfield. */ | |
2063 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2064 | } | |
2065 | else | |
2066 | loc->length = TYPE_LENGTH (value_type (v)); | |
2067 | ||
a5606eee VP |
2068 | loc->watchpoint_type = type; |
2069 | } | |
2070 | } | |
9fa40276 TJB |
2071 | } |
2072 | ||
2073 | /* Change the type of breakpoint between hardware assisted or | |
2074 | an ordinary watchpoint depending on the hardware support | |
2075 | and free hardware slots. REPARSE is set when the inferior | |
2076 | is started. */ | |
a9634178 | 2077 | if (reparse) |
9fa40276 | 2078 | { |
e09342b5 | 2079 | int reg_cnt; |
9fa40276 TJB |
2080 | enum bp_loc_type loc_type; |
2081 | struct bp_location *bl; | |
a5606eee | 2082 | |
a9634178 | 2083 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2084 | |
2085 | if (reg_cnt) | |
9fa40276 TJB |
2086 | { |
2087 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2088 | enum bptype type; |
9fa40276 | 2089 | |
a9634178 TJB |
2090 | /* Use an exact watchpoint when there's only one memory region to be |
2091 | watched, and only one debug register is needed to watch it. */ | |
2092 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2093 | ||
9fa40276 | 2094 | /* We need to determine how many resources are already |
e09342b5 TJB |
2095 | used for all other hardware watchpoints plus this one |
2096 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2097 | this watchpoint in as well. */ |
2098 | ||
2099 | /* If this is a software watchpoint, we try to turn it | |
2100 | to a hardware one -- count resources as if B was of | |
2101 | hardware watchpoint type. */ | |
2102 | type = b->base.type; | |
2103 | if (type == bp_watchpoint) | |
2104 | type = bp_hardware_watchpoint; | |
2105 | ||
2106 | /* This watchpoint may or may not have been placed on | |
2107 | the list yet at this point (it won't be in the list | |
2108 | if we're trying to create it for the first time, | |
2109 | through watch_command), so always account for it | |
2110 | manually. */ | |
2111 | ||
2112 | /* Count resources used by all watchpoints except B. */ | |
2113 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2114 | ||
2115 | /* Add in the resources needed for B. */ | |
2116 | i += hw_watchpoint_use_count (&b->base); | |
2117 | ||
2118 | target_resources_ok | |
2119 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2120 | if (target_resources_ok <= 0) |
a9634178 | 2121 | { |
3a5c3e22 | 2122 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2123 | |
2124 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2125 | error (_("Target does not support this type of " |
2126 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2127 | else if (target_resources_ok < 0 && !sw_mode) |
2128 | error (_("There are not enough available hardware " | |
2129 | "resources for this watchpoint.")); | |
a1398e0c PA |
2130 | |
2131 | /* Downgrade to software watchpoint. */ | |
2132 | b->base.type = bp_watchpoint; | |
2133 | } | |
2134 | else | |
2135 | { | |
2136 | /* If this was a software watchpoint, we've just | |
2137 | found we have enough resources to turn it to a | |
2138 | hardware watchpoint. Otherwise, this is a | |
2139 | nop. */ | |
2140 | b->base.type = type; | |
a9634178 | 2141 | } |
9fa40276 | 2142 | } |
3a5c3e22 | 2143 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2144 | { |
2145 | if (!can_use_hw_watchpoints) | |
2146 | error (_("Can't set read/access watchpoint when " | |
2147 | "hardware watchpoints are disabled.")); | |
2148 | else | |
2149 | error (_("Expression cannot be implemented with " | |
2150 | "read/access watchpoint.")); | |
2151 | } | |
9fa40276 | 2152 | else |
3a5c3e22 | 2153 | b->base.type = bp_watchpoint; |
9fa40276 | 2154 | |
3a5c3e22 | 2155 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2156 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2157 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2158 | bl->loc_type = loc_type; |
2159 | } | |
2160 | ||
2161 | for (v = val_chain; v; v = next) | |
2162 | { | |
a5606eee VP |
2163 | next = value_next (v); |
2164 | if (v != b->val) | |
2165 | value_free (v); | |
2166 | } | |
2167 | ||
c7437ca6 PA |
2168 | /* If a software watchpoint is not watching any memory, then the |
2169 | above left it without any location set up. But, | |
2170 | bpstat_stop_status requires a location to be able to report | |
2171 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2172 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2173 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2174 | } |
2175 | else if (!within_current_scope) | |
7270d8f2 | 2176 | { |
ac74f770 MS |
2177 | printf_filtered (_("\ |
2178 | Watchpoint %d deleted because the program has left the block\n\ | |
2179 | in which its expression is valid.\n"), | |
3a5c3e22 | 2180 | b->base.number); |
d0fb5eae | 2181 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2182 | } |
a5606eee VP |
2183 | |
2184 | /* Restore the selected frame. */ | |
66076460 DJ |
2185 | if (frame_saved) |
2186 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2187 | } |
2188 | ||
a5606eee | 2189 | |
74960c60 | 2190 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2191 | inserted in the inferior. We don't differentiate the type of BL's owner |
2192 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2193 | breakpoint_ops is not defined, because in insert_bp_location, | |
2194 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2195 | static int |
35df4500 | 2196 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2197 | { |
35df4500 | 2198 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2199 | return 0; |
2200 | ||
35df4500 | 2201 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2202 | return 0; |
2203 | ||
35df4500 | 2204 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2205 | return 0; |
2206 | ||
f8eba3c6 TT |
2207 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2208 | return 0; | |
2209 | ||
56710373 PA |
2210 | /* This is set for example, when we're attached to the parent of a |
2211 | vfork, and have detached from the child. The child is running | |
2212 | free, and we expect it to do an exec or exit, at which point the | |
2213 | OS makes the parent schedulable again (and the target reports | |
2214 | that the vfork is done). Until the child is done with the shared | |
2215 | memory region, do not insert breakpoints in the parent, otherwise | |
2216 | the child could still trip on the parent's breakpoints. Since | |
2217 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2218 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2219 | return 0; |
2220 | ||
31e77af2 | 2221 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2222 | location, except if the breakpoint is a single-step breakpoint, |
2223 | and the breakpoint's thread is the thread which is stepping past | |
2224 | a breakpoint. */ | |
31e77af2 PA |
2225 | if ((bl->loc_type == bp_loc_software_breakpoint |
2226 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2227 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2228 | bl->address) |
2229 | /* The single-step breakpoint may be inserted at the location | |
2230 | we're trying to step if the instruction branches to itself. | |
2231 | However, the instruction won't be executed at all and it may | |
2232 | break the semantics of the instruction, for example, the | |
2233 | instruction is a conditional branch or updates some flags. | |
2234 | We can't fix it unless GDB is able to emulate the instruction | |
2235 | or switch to displaced stepping. */ | |
2236 | && !(bl->owner->type == bp_single_step | |
2237 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2238 | { |
2239 | if (debug_infrun) | |
2240 | { | |
2241 | fprintf_unfiltered (gdb_stdlog, | |
2242 | "infrun: skipping breakpoint: " | |
2243 | "stepping past insn at: %s\n", | |
2244 | paddress (bl->gdbarch, bl->address)); | |
2245 | } | |
2246 | return 0; | |
2247 | } | |
31e77af2 | 2248 | |
963f9c80 PA |
2249 | /* Don't insert watchpoints if we're trying to step past the |
2250 | instruction that triggered one. */ | |
2251 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2252 | && stepping_past_nonsteppable_watchpoint ()) | |
2253 | { | |
2254 | if (debug_infrun) | |
2255 | { | |
2256 | fprintf_unfiltered (gdb_stdlog, | |
2257 | "infrun: stepping past non-steppable watchpoint. " | |
2258 | "skipping watchpoint at %s:%d\n", | |
2259 | paddress (bl->gdbarch, bl->address), | |
2260 | bl->length); | |
2261 | } | |
2262 | return 0; | |
2263 | } | |
2264 | ||
74960c60 VP |
2265 | return 1; |
2266 | } | |
2267 | ||
934709f0 PW |
2268 | /* Same as should_be_inserted but does the check assuming |
2269 | that the location is not duplicated. */ | |
2270 | ||
2271 | static int | |
2272 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2273 | { | |
2274 | int result; | |
2275 | const int save_duplicate = bl->duplicate; | |
2276 | ||
2277 | bl->duplicate = 0; | |
2278 | result = should_be_inserted (bl); | |
2279 | bl->duplicate = save_duplicate; | |
2280 | return result; | |
2281 | } | |
2282 | ||
b775012e LM |
2283 | /* Parses a conditional described by an expression COND into an |
2284 | agent expression bytecode suitable for evaluation | |
2285 | by the bytecode interpreter. Return NULL if there was | |
2286 | any error during parsing. */ | |
2287 | ||
2288 | static struct agent_expr * | |
2289 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2290 | { | |
2291 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2292 | |
2293 | if (!cond) | |
2294 | return NULL; | |
2295 | ||
2296 | /* We don't want to stop processing, so catch any errors | |
2297 | that may show up. */ | |
492d29ea | 2298 | TRY |
b775012e LM |
2299 | { |
2300 | aexpr = gen_eval_for_expr (scope, cond); | |
2301 | } | |
2302 | ||
492d29ea | 2303 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2304 | { |
2305 | /* If we got here, it means the condition could not be parsed to a valid | |
2306 | bytecode expression and thus can't be evaluated on the target's side. | |
2307 | It's no use iterating through the conditions. */ | |
2308 | return NULL; | |
2309 | } | |
492d29ea | 2310 | END_CATCH |
b775012e LM |
2311 | |
2312 | /* We have a valid agent expression. */ | |
2313 | return aexpr; | |
2314 | } | |
2315 | ||
2316 | /* Based on location BL, create a list of breakpoint conditions to be | |
2317 | passed on to the target. If we have duplicated locations with different | |
2318 | conditions, we will add such conditions to the list. The idea is that the | |
2319 | target will evaluate the list of conditions and will only notify GDB when | |
2320 | one of them is true. */ | |
2321 | ||
2322 | static void | |
2323 | build_target_condition_list (struct bp_location *bl) | |
2324 | { | |
2325 | struct bp_location **locp = NULL, **loc2p; | |
2326 | int null_condition_or_parse_error = 0; | |
2327 | int modified = bl->needs_update; | |
2328 | struct bp_location *loc; | |
2329 | ||
8b4f3082 PA |
2330 | /* Release conditions left over from a previous insert. */ |
2331 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2332 | ||
b775012e LM |
2333 | /* This is only meaningful if the target is |
2334 | evaluating conditions and if the user has | |
2335 | opted for condition evaluation on the target's | |
2336 | side. */ | |
2337 | if (gdb_evaluates_breakpoint_condition_p () | |
2338 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2339 | return; | |
2340 | ||
2341 | /* Do a first pass to check for locations with no assigned | |
2342 | conditions or conditions that fail to parse to a valid agent expression | |
2343 | bytecode. If any of these happen, then it's no use to send conditions | |
2344 | to the target since this location will always trigger and generate a | |
2345 | response back to GDB. */ | |
2346 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2347 | { | |
2348 | loc = (*loc2p); | |
2349 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2350 | { | |
2351 | if (modified) | |
2352 | { | |
2353 | struct agent_expr *aexpr; | |
2354 | ||
2355 | /* Re-parse the conditions since something changed. In that | |
2356 | case we already freed the condition bytecodes (see | |
2357 | force_breakpoint_reinsertion). We just | |
2358 | need to parse the condition to bytecodes again. */ | |
2359 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2360 | loc->cond_bytecode = aexpr; | |
b775012e LM |
2361 | } |
2362 | ||
2363 | /* If we have a NULL bytecode expression, it means something | |
2364 | went wrong or we have a null condition expression. */ | |
2365 | if (!loc->cond_bytecode) | |
2366 | { | |
2367 | null_condition_or_parse_error = 1; | |
2368 | break; | |
2369 | } | |
2370 | } | |
2371 | } | |
2372 | ||
2373 | /* If any of these happened, it means we will have to evaluate the conditions | |
2374 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2375 | for all the other duplicate locations, thus we free all of them here. | |
2376 | ||
2377 | This is so we have a finer control over which locations' conditions are | |
2378 | being evaluated by GDB or the remote stub. */ | |
2379 | if (null_condition_or_parse_error) | |
2380 | { | |
2381 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2382 | { | |
2383 | loc = (*loc2p); | |
2384 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2385 | { | |
2386 | /* Only go as far as the first NULL bytecode is | |
2387 | located. */ | |
2388 | if (!loc->cond_bytecode) | |
2389 | return; | |
2390 | ||
2391 | free_agent_expr (loc->cond_bytecode); | |
2392 | loc->cond_bytecode = NULL; | |
2393 | } | |
2394 | } | |
2395 | } | |
2396 | ||
2397 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2398 | for this location's address. */ | |
2399 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2400 | { | |
2401 | loc = (*loc2p); | |
2402 | if (loc->cond | |
2403 | && is_breakpoint (loc->owner) | |
2404 | && loc->pspace->num == bl->pspace->num | |
2405 | && loc->owner->enable_state == bp_enabled | |
2406 | && loc->enabled) | |
2407 | /* Add the condition to the vector. This will be used later to send the | |
2408 | conditions to the target. */ | |
2409 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2410 | loc->cond_bytecode); | |
2411 | } | |
2412 | ||
2413 | return; | |
2414 | } | |
2415 | ||
d3ce09f5 SS |
2416 | /* Parses a command described by string CMD into an agent expression |
2417 | bytecode suitable for evaluation by the bytecode interpreter. | |
2418 | Return NULL if there was any error during parsing. */ | |
2419 | ||
2420 | static struct agent_expr * | |
2421 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2422 | { | |
2423 | struct cleanup *old_cleanups = 0; | |
2424 | struct expression *expr, **argvec; | |
2425 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2426 | const char *cmdrest; |
2427 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2428 | struct format_piece *fpieces; |
2429 | int nargs; | |
2430 | struct gdbarch *gdbarch = get_current_arch (); | |
2431 | ||
2432 | if (!cmd) | |
2433 | return NULL; | |
2434 | ||
2435 | cmdrest = cmd; | |
2436 | ||
2437 | if (*cmdrest == ',') | |
2438 | ++cmdrest; | |
bbc13ae3 | 2439 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2440 | |
2441 | if (*cmdrest++ != '"') | |
2442 | error (_("No format string following the location")); | |
2443 | ||
2444 | format_start = cmdrest; | |
2445 | ||
2446 | fpieces = parse_format_string (&cmdrest); | |
2447 | ||
2448 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2449 | ||
2450 | format_end = cmdrest; | |
2451 | ||
2452 | if (*cmdrest++ != '"') | |
2453 | error (_("Bad format string, non-terminated '\"'.")); | |
2454 | ||
bbc13ae3 | 2455 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2456 | |
2457 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2458 | error (_("Invalid argument syntax")); | |
2459 | ||
2460 | if (*cmdrest == ',') | |
2461 | cmdrest++; | |
bbc13ae3 | 2462 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2463 | |
2464 | /* For each argument, make an expression. */ | |
2465 | ||
2466 | argvec = (struct expression **) alloca (strlen (cmd) | |
2467 | * sizeof (struct expression *)); | |
2468 | ||
2469 | nargs = 0; | |
2470 | while (*cmdrest != '\0') | |
2471 | { | |
bbc13ae3 | 2472 | const char *cmd1; |
d3ce09f5 SS |
2473 | |
2474 | cmd1 = cmdrest; | |
2475 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2476 | argvec[nargs++] = expr; | |
2477 | cmdrest = cmd1; | |
2478 | if (*cmdrest == ',') | |
2479 | ++cmdrest; | |
2480 | } | |
2481 | ||
2482 | /* We don't want to stop processing, so catch any errors | |
2483 | that may show up. */ | |
492d29ea | 2484 | TRY |
d3ce09f5 SS |
2485 | { |
2486 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2487 | format_start, format_end - format_start, | |
2488 | fpieces, nargs, argvec); | |
2489 | } | |
492d29ea | 2490 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2491 | { |
2492 | /* If we got here, it means the command could not be parsed to a valid | |
2493 | bytecode expression and thus can't be evaluated on the target's side. | |
2494 | It's no use iterating through the other commands. */ | |
492d29ea | 2495 | aexpr = NULL; |
d3ce09f5 | 2496 | } |
492d29ea PA |
2497 | END_CATCH |
2498 | ||
2499 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2500 | |
d3ce09f5 SS |
2501 | /* We have a valid agent expression, return it. */ |
2502 | return aexpr; | |
2503 | } | |
2504 | ||
2505 | /* Based on location BL, create a list of breakpoint commands to be | |
2506 | passed on to the target. If we have duplicated locations with | |
2507 | different commands, we will add any such to the list. */ | |
2508 | ||
2509 | static void | |
2510 | build_target_command_list (struct bp_location *bl) | |
2511 | { | |
2512 | struct bp_location **locp = NULL, **loc2p; | |
2513 | int null_command_or_parse_error = 0; | |
2514 | int modified = bl->needs_update; | |
2515 | struct bp_location *loc; | |
2516 | ||
8b4f3082 PA |
2517 | /* Release commands left over from a previous insert. */ |
2518 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2519 | ||
41fac0cf | 2520 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2521 | return; |
2522 | ||
41fac0cf PA |
2523 | /* For now, limit to agent-style dprintf breakpoints. */ |
2524 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2525 | return; |
2526 | ||
41fac0cf PA |
2527 | /* For now, if we have any duplicate location that isn't a dprintf, |
2528 | don't install the target-side commands, as that would make the | |
2529 | breakpoint not be reported to the core, and we'd lose | |
2530 | control. */ | |
2531 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2532 | { | |
2533 | loc = (*loc2p); | |
2534 | if (is_breakpoint (loc->owner) | |
2535 | && loc->pspace->num == bl->pspace->num | |
2536 | && loc->owner->type != bp_dprintf) | |
2537 | return; | |
2538 | } | |
2539 | ||
d3ce09f5 SS |
2540 | /* Do a first pass to check for locations with no assigned |
2541 | conditions or conditions that fail to parse to a valid agent expression | |
2542 | bytecode. If any of these happen, then it's no use to send conditions | |
2543 | to the target since this location will always trigger and generate a | |
2544 | response back to GDB. */ | |
2545 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2546 | { | |
2547 | loc = (*loc2p); | |
2548 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2549 | { | |
2550 | if (modified) | |
2551 | { | |
2552 | struct agent_expr *aexpr; | |
2553 | ||
2554 | /* Re-parse the commands since something changed. In that | |
2555 | case we already freed the command bytecodes (see | |
2556 | force_breakpoint_reinsertion). We just | |
2557 | need to parse the command to bytecodes again. */ | |
2558 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2559 | loc->owner->extra_string); | |
2560 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2561 | } |
2562 | ||
2563 | /* If we have a NULL bytecode expression, it means something | |
2564 | went wrong or we have a null command expression. */ | |
2565 | if (!loc->cmd_bytecode) | |
2566 | { | |
2567 | null_command_or_parse_error = 1; | |
2568 | break; | |
2569 | } | |
2570 | } | |
2571 | } | |
2572 | ||
2573 | /* If anything failed, then we're not doing target-side commands, | |
2574 | and so clean up. */ | |
2575 | if (null_command_or_parse_error) | |
2576 | { | |
2577 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2578 | { | |
2579 | loc = (*loc2p); | |
2580 | if (is_breakpoint (loc->owner) | |
2581 | && loc->pspace->num == bl->pspace->num) | |
2582 | { | |
2583 | /* Only go as far as the first NULL bytecode is | |
2584 | located. */ | |
40fb6c5e | 2585 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2586 | return; |
2587 | ||
40fb6c5e HZ |
2588 | free_agent_expr (loc->cmd_bytecode); |
2589 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2590 | } |
2591 | } | |
2592 | } | |
2593 | ||
2594 | /* No NULL commands or failed bytecode generation. Build a command list | |
2595 | for this location's address. */ | |
2596 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2597 | { | |
2598 | loc = (*loc2p); | |
2599 | if (loc->owner->extra_string | |
2600 | && is_breakpoint (loc->owner) | |
2601 | && loc->pspace->num == bl->pspace->num | |
2602 | && loc->owner->enable_state == bp_enabled | |
2603 | && loc->enabled) | |
2604 | /* Add the command to the vector. This will be used later | |
2605 | to send the commands to the target. */ | |
2606 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2607 | loc->cmd_bytecode); | |
2608 | } | |
2609 | ||
2610 | bl->target_info.persist = 0; | |
2611 | /* Maybe flag this location as persistent. */ | |
2612 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2613 | bl->target_info.persist = 1; | |
2614 | } | |
2615 | ||
35df4500 TJB |
2616 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2617 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2618 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2619 | Returns 0 for success, 1 if the bp_location type is not supported or |
2620 | -1 for failure. | |
879bfdc2 | 2621 | |
4a64f543 MS |
2622 | NOTE drow/2003-09-09: This routine could be broken down to an |
2623 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2624 | static int |
35df4500 | 2625 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2626 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2627 | int *disabled_breaks, |
dd61ec5c MW |
2628 | int *hw_breakpoint_error, |
2629 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2630 | { |
0000e5cc PA |
2631 | enum errors bp_err = GDB_NO_ERROR; |
2632 | const char *bp_err_message = NULL; | |
879bfdc2 | 2633 | |
b775012e | 2634 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2635 | return 0; |
2636 | ||
35c63cd8 JB |
2637 | /* Note we don't initialize bl->target_info, as that wipes out |
2638 | the breakpoint location's shadow_contents if the breakpoint | |
2639 | is still inserted at that location. This in turn breaks | |
2640 | target_read_memory which depends on these buffers when | |
2641 | a memory read is requested at the breakpoint location: | |
2642 | Once the target_info has been wiped, we fail to see that | |
2643 | we have a breakpoint inserted at that address and thus | |
2644 | read the breakpoint instead of returning the data saved in | |
2645 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2646 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2647 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2648 | bl->target_info.length = bl->length; |
8181d85f | 2649 | |
b775012e LM |
2650 | /* When working with target-side conditions, we must pass all the conditions |
2651 | for the same breakpoint address down to the target since GDB will not | |
2652 | insert those locations. With a list of breakpoint conditions, the target | |
2653 | can decide when to stop and notify GDB. */ | |
2654 | ||
2655 | if (is_breakpoint (bl->owner)) | |
2656 | { | |
2657 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2658 | build_target_command_list (bl); |
2659 | /* Reset the modification marker. */ | |
b775012e LM |
2660 | bl->needs_update = 0; |
2661 | } | |
2662 | ||
35df4500 TJB |
2663 | if (bl->loc_type == bp_loc_software_breakpoint |
2664 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2665 | { |
35df4500 | 2666 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2667 | { |
2668 | /* If the explicitly specified breakpoint type | |
2669 | is not hardware breakpoint, check the memory map to see | |
2670 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2671 | |
765dc015 VP |
2672 | Two important cases are: |
2673 | - location type is not hardware breakpoint, memory | |
2674 | is readonly. We change the type of the location to | |
2675 | hardware breakpoint. | |
4a64f543 MS |
2676 | - location type is hardware breakpoint, memory is |
2677 | read-write. This means we've previously made the | |
2678 | location hardware one, but then the memory map changed, | |
2679 | so we undo. | |
765dc015 | 2680 | |
4a64f543 MS |
2681 | When breakpoints are removed, remove_breakpoints will use |
2682 | location types we've just set here, the only possible | |
2683 | problem is that memory map has changed during running | |
2684 | program, but it's not going to work anyway with current | |
2685 | gdb. */ | |
765dc015 | 2686 | struct mem_region *mr |
0d5ed153 | 2687 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2688 | |
2689 | if (mr) | |
2690 | { | |
2691 | if (automatic_hardware_breakpoints) | |
2692 | { | |
765dc015 VP |
2693 | enum bp_loc_type new_type; |
2694 | ||
2695 | if (mr->attrib.mode != MEM_RW) | |
2696 | new_type = bp_loc_hardware_breakpoint; | |
2697 | else | |
2698 | new_type = bp_loc_software_breakpoint; | |
2699 | ||
35df4500 | 2700 | if (new_type != bl->loc_type) |
765dc015 VP |
2701 | { |
2702 | static int said = 0; | |
cc59ec59 | 2703 | |
35df4500 | 2704 | bl->loc_type = new_type; |
765dc015 VP |
2705 | if (!said) |
2706 | { | |
3e43a32a MS |
2707 | fprintf_filtered (gdb_stdout, |
2708 | _("Note: automatically using " | |
2709 | "hardware breakpoints for " | |
2710 | "read-only addresses.\n")); | |
765dc015 VP |
2711 | said = 1; |
2712 | } | |
2713 | } | |
2714 | } | |
35df4500 | 2715 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2716 | && mr->attrib.mode != MEM_RW) |
2717 | { | |
2718 | fprintf_unfiltered (tmp_error_stream, | |
2719 | _("Cannot insert breakpoint %d.\n" | |
2720 | "Cannot set software breakpoint " | |
2721 | "at read-only address %s\n"), | |
2722 | bl->owner->number, | |
2723 | paddress (bl->gdbarch, bl->address)); | |
2724 | return 1; | |
2725 | } | |
765dc015 VP |
2726 | } |
2727 | } | |
2728 | ||
879bfdc2 DJ |
2729 | /* First check to see if we have to handle an overlay. */ |
2730 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2731 | || bl->section == NULL |
2732 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2733 | { |
2734 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2735 | TRY |
dd61ec5c | 2736 | { |
0000e5cc PA |
2737 | int val; |
2738 | ||
dd61ec5c | 2739 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2740 | if (val) |
2741 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2742 | } |
492d29ea | 2743 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2744 | { |
0000e5cc PA |
2745 | bp_err = e.error; |
2746 | bp_err_message = e.message; | |
dd61ec5c | 2747 | } |
492d29ea | 2748 | END_CATCH |
879bfdc2 DJ |
2749 | } |
2750 | else | |
2751 | { | |
4a64f543 | 2752 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2753 | Shall we set a breakpoint at the LMA? */ |
2754 | if (!overlay_events_enabled) | |
2755 | { | |
2756 | /* Yes -- overlay event support is not active, | |
2757 | so we must try to set a breakpoint at the LMA. | |
2758 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2759 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2760 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2761 | bl->owner->number); |
879bfdc2 DJ |
2762 | else |
2763 | { | |
35df4500 TJB |
2764 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2765 | bl->section); | |
879bfdc2 | 2766 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2767 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2768 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2769 | |
2770 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2771 | TRY |
0000e5cc PA |
2772 | { |
2773 | int val; | |
2774 | ||
2775 | val = target_insert_breakpoint (bl->gdbarch, | |
2776 | &bl->overlay_target_info); | |
2777 | if (val) | |
2778 | bp_err = GENERIC_ERROR; | |
2779 | } | |
492d29ea | 2780 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2781 | { |
2782 | bp_err = e.error; | |
2783 | bp_err_message = e.message; | |
2784 | } | |
492d29ea | 2785 | END_CATCH |
0000e5cc PA |
2786 | |
2787 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2788 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2789 | "Overlay breakpoint %d " |
2790 | "failed: in ROM?\n", | |
35df4500 | 2791 | bl->owner->number); |
879bfdc2 DJ |
2792 | } |
2793 | } | |
2794 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2795 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2796 | { |
2797 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2798 | TRY |
dd61ec5c | 2799 | { |
0000e5cc PA |
2800 | int val; |
2801 | ||
dd61ec5c | 2802 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2803 | if (val) |
2804 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2805 | } |
492d29ea | 2806 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2807 | { |
0000e5cc PA |
2808 | bp_err = e.error; |
2809 | bp_err_message = e.message; | |
dd61ec5c | 2810 | } |
492d29ea | 2811 | END_CATCH |
879bfdc2 DJ |
2812 | } |
2813 | else | |
2814 | { | |
2815 | /* No. This breakpoint will not be inserted. | |
2816 | No error, but do not mark the bp as 'inserted'. */ | |
2817 | return 0; | |
2818 | } | |
2819 | } | |
2820 | ||
0000e5cc | 2821 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2822 | { |
2823 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2824 | |
2825 | /* In some cases, we might not be able to insert a | |
2826 | breakpoint in a shared library that has already been | |
2827 | removed, but we have not yet processed the shlib unload | |
2828 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2829 | breakpoint insertion themselves can't tell why the |
2830 | breakpoint insertion failed (e.g., the remote target | |
2831 | doesn't define error codes), so we must treat generic | |
2832 | errors as memory errors. */ | |
0000e5cc | 2833 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2834 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2835 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2836 | || shared_objfile_contains_address_p (bl->pspace, |
2837 | bl->address))) | |
879bfdc2 | 2838 | { |
4a64f543 | 2839 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2840 | bl->shlib_disabled = 1; |
8d3788bd | 2841 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2842 | if (!*disabled_breaks) |
2843 | { | |
2844 | fprintf_unfiltered (tmp_error_stream, | |
2845 | "Cannot insert breakpoint %d.\n", | |
2846 | bl->owner->number); | |
2847 | fprintf_unfiltered (tmp_error_stream, | |
2848 | "Temporarily disabling shared " | |
2849 | "library breakpoints:\n"); | |
2850 | } | |
2851 | *disabled_breaks = 1; | |
879bfdc2 | 2852 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2853 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2854 | return 0; |
879bfdc2 DJ |
2855 | } |
2856 | else | |
879bfdc2 | 2857 | { |
35df4500 | 2858 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2859 | { |
0000e5cc PA |
2860 | *hw_breakpoint_error = 1; |
2861 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2862 | fprintf_unfiltered (tmp_error_stream, |
2863 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2864 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2865 | if (bp_err_message != NULL) | |
2866 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2867 | } |
2868 | else | |
2869 | { | |
0000e5cc PA |
2870 | if (bp_err_message == NULL) |
2871 | { | |
2872 | char *message | |
2873 | = memory_error_message (TARGET_XFER_E_IO, | |
2874 | bl->gdbarch, bl->address); | |
2875 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2876 | ||
2877 | fprintf_unfiltered (tmp_error_stream, | |
2878 | "Cannot insert breakpoint %d.\n" | |
2879 | "%s\n", | |
2880 | bl->owner->number, message); | |
2881 | do_cleanups (old_chain); | |
2882 | } | |
2883 | else | |
2884 | { | |
2885 | fprintf_unfiltered (tmp_error_stream, | |
2886 | "Cannot insert breakpoint %d: %s\n", | |
2887 | bl->owner->number, | |
2888 | bp_err_message); | |
2889 | } | |
879bfdc2 | 2890 | } |
0000e5cc | 2891 | return 1; |
879bfdc2 DJ |
2892 | |
2893 | } | |
2894 | } | |
2895 | else | |
35df4500 | 2896 | bl->inserted = 1; |
879bfdc2 | 2897 | |
0000e5cc | 2898 | return 0; |
879bfdc2 DJ |
2899 | } |
2900 | ||
35df4500 | 2901 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2902 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2903 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2904 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2905 | { |
0000e5cc PA |
2906 | int val; |
2907 | ||
77b06cd7 TJB |
2908 | gdb_assert (bl->owner->ops != NULL |
2909 | && bl->owner->ops->insert_location != NULL); | |
2910 | ||
2911 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2912 | |
2913 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2914 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2915 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2916 | { |
2917 | struct bp_location *loc, **loc_temp; | |
2918 | ||
2919 | /* But don't try to insert it, if there's already another | |
2920 | hw_access location that would be considered a duplicate | |
2921 | of this one. */ | |
2922 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2923 | if (loc != bl |
85d721b8 | 2924 | && loc->watchpoint_type == hw_access |
35df4500 | 2925 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2926 | { |
35df4500 TJB |
2927 | bl->duplicate = 1; |
2928 | bl->inserted = 1; | |
2929 | bl->target_info = loc->target_info; | |
2930 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2931 | val = 0; |
2932 | break; | |
2933 | } | |
2934 | ||
2935 | if (val == 1) | |
2936 | { | |
77b06cd7 TJB |
2937 | bl->watchpoint_type = hw_access; |
2938 | val = bl->owner->ops->insert_location (bl); | |
2939 | ||
2940 | if (val) | |
2941 | /* Back to the original value. */ | |
2942 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2943 | } |
2944 | } | |
2945 | ||
35df4500 | 2946 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2947 | } |
2948 | ||
35df4500 | 2949 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2950 | { |
0000e5cc PA |
2951 | int val; |
2952 | ||
77b06cd7 TJB |
2953 | gdb_assert (bl->owner->ops != NULL |
2954 | && bl->owner->ops->insert_location != NULL); | |
2955 | ||
2956 | val = bl->owner->ops->insert_location (bl); | |
2957 | if (val) | |
2958 | { | |
2959 | bl->owner->enable_state = bp_disabled; | |
2960 | ||
2961 | if (val == 1) | |
2962 | warning (_("\ | |
2963 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2964 | of catchpoint."), bl->owner->number); | |
2965 | else | |
2966 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2967 | } | |
2968 | ||
2969 | bl->inserted = (val == 0); | |
1640b821 DJ |
2970 | |
2971 | /* We've already printed an error message if there was a problem | |
2972 | inserting this catchpoint, and we've disabled the catchpoint, | |
2973 | so just return success. */ | |
2974 | return 0; | |
879bfdc2 DJ |
2975 | } |
2976 | ||
2977 | return 0; | |
2978 | } | |
2979 | ||
6c95b8df PA |
2980 | /* This function is called when program space PSPACE is about to be |
2981 | deleted. It takes care of updating breakpoints to not reference | |
2982 | PSPACE anymore. */ | |
2983 | ||
2984 | void | |
2985 | breakpoint_program_space_exit (struct program_space *pspace) | |
2986 | { | |
2987 | struct breakpoint *b, *b_temp; | |
876fa593 | 2988 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2989 | |
2990 | /* Remove any breakpoint that was set through this program space. */ | |
2991 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2992 | { | |
2993 | if (b->pspace == pspace) | |
2994 | delete_breakpoint (b); | |
2995 | } | |
2996 | ||
2997 | /* Breakpoints set through other program spaces could have locations | |
2998 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2999 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
3000 | { |
3001 | struct bp_location *tmp; | |
3002 | ||
3003 | if (loc->pspace == pspace) | |
3004 | { | |
2bdf28a0 | 3005 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3006 | if (loc->owner->loc == loc) |
3007 | loc->owner->loc = loc->next; | |
3008 | else | |
3009 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3010 | if (tmp->next == loc) | |
3011 | { | |
3012 | tmp->next = loc->next; | |
3013 | break; | |
3014 | } | |
3015 | } | |
3016 | } | |
3017 | ||
3018 | /* Now update the global location list to permanently delete the | |
3019 | removed locations above. */ | |
44702360 | 3020 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3021 | } |
3022 | ||
74960c60 VP |
3023 | /* Make sure all breakpoints are inserted in inferior. |
3024 | Throws exception on any error. | |
3025 | A breakpoint that is already inserted won't be inserted | |
3026 | again, so calling this function twice is safe. */ | |
3027 | void | |
3028 | insert_breakpoints (void) | |
3029 | { | |
3030 | struct breakpoint *bpt; | |
3031 | ||
3032 | ALL_BREAKPOINTS (bpt) | |
3033 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3034 | { |
3035 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3036 | ||
3037 | update_watchpoint (w, 0 /* don't reparse. */); | |
3038 | } | |
74960c60 | 3039 | |
04086b45 PA |
3040 | /* Updating watchpoints creates new locations, so update the global |
3041 | location list. Explicitly tell ugll to insert locations and | |
3042 | ignore breakpoints_always_inserted_mode. */ | |
3043 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3044 | } |
3045 | ||
20388dd6 YQ |
3046 | /* Invoke CALLBACK for each of bp_location. */ |
3047 | ||
3048 | void | |
3049 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3050 | { | |
3051 | struct bp_location *loc, **loc_tmp; | |
3052 | ||
3053 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3054 | { | |
3055 | callback (loc, NULL); | |
3056 | } | |
3057 | } | |
3058 | ||
b775012e LM |
3059 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3060 | target. It is the case with deleting and disabling of breakpoints when using | |
3061 | always-inserted mode. */ | |
3062 | ||
3063 | static void | |
3064 | update_inserted_breakpoint_locations (void) | |
3065 | { | |
3066 | struct bp_location *bl, **blp_tmp; | |
3067 | int error_flag = 0; | |
3068 | int val = 0; | |
3069 | int disabled_breaks = 0; | |
3070 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3071 | int hw_bp_details_reported = 0; |
b775012e LM |
3072 | |
3073 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3074 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3075 | ||
3076 | /* Explicitly mark the warning -- this will only be printed if | |
3077 | there was an error. */ | |
3078 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3079 | ||
3080 | save_current_space_and_thread (); | |
3081 | ||
3082 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3083 | { | |
3084 | /* We only want to update software breakpoints and hardware | |
3085 | breakpoints. */ | |
3086 | if (!is_breakpoint (bl->owner)) | |
3087 | continue; | |
3088 | ||
3089 | /* We only want to update locations that are already inserted | |
3090 | and need updating. This is to avoid unwanted insertion during | |
3091 | deletion of breakpoints. */ | |
3092 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3093 | continue; | |
3094 | ||
3095 | switch_to_program_space_and_thread (bl->pspace); | |
3096 | ||
3097 | /* For targets that support global breakpoints, there's no need | |
3098 | to select an inferior to insert breakpoint to. In fact, even | |
3099 | if we aren't attached to any process yet, we should still | |
3100 | insert breakpoints. */ | |
f5656ead | 3101 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3102 | && ptid_equal (inferior_ptid, null_ptid)) |
3103 | continue; | |
3104 | ||
3105 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3106 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3107 | if (val) |
3108 | error_flag = val; | |
3109 | } | |
3110 | ||
3111 | if (error_flag) | |
3112 | { | |
3113 | target_terminal_ours_for_output (); | |
3114 | error_stream (tmp_error_stream); | |
3115 | } | |
3116 | ||
3117 | do_cleanups (cleanups); | |
3118 | } | |
3119 | ||
c30eee59 | 3120 | /* Used when starting or continuing the program. */ |
c906108c | 3121 | |
74960c60 VP |
3122 | static void |
3123 | insert_breakpoint_locations (void) | |
c906108c | 3124 | { |
a5606eee | 3125 | struct breakpoint *bpt; |
35df4500 | 3126 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3127 | int error_flag = 0; |
c906108c | 3128 | int val = 0; |
3fbb6ffa | 3129 | int disabled_breaks = 0; |
81d0cc19 | 3130 | int hw_breakpoint_error = 0; |
dd61ec5c | 3131 | int hw_bp_error_explained_already = 0; |
c906108c | 3132 | |
81d0cc19 | 3133 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3134 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3135 | |
81d0cc19 GS |
3136 | /* Explicitly mark the warning -- this will only be printed if |
3137 | there was an error. */ | |
3138 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3139 | |
3140 | save_current_space_and_thread (); | |
3141 | ||
35df4500 | 3142 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3143 | { |
b775012e | 3144 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3145 | continue; |
3146 | ||
4a64f543 MS |
3147 | /* There is no point inserting thread-specific breakpoints if |
3148 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3149 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3150 | if (bl->owner->thread != -1 |
5d5658a1 | 3151 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3152 | continue; |
3153 | ||
35df4500 | 3154 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3155 | |
3156 | /* For targets that support global breakpoints, there's no need | |
3157 | to select an inferior to insert breakpoint to. In fact, even | |
3158 | if we aren't attached to any process yet, we should still | |
3159 | insert breakpoints. */ | |
f5656ead | 3160 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3161 | && ptid_equal (inferior_ptid, null_ptid)) |
3162 | continue; | |
3163 | ||
3fbb6ffa | 3164 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3165 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3166 | if (val) |
eacd795a | 3167 | error_flag = val; |
879bfdc2 | 3168 | } |
c906108c | 3169 | |
4a64f543 MS |
3170 | /* If we failed to insert all locations of a watchpoint, remove |
3171 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3172 | ALL_BREAKPOINTS (bpt) |
3173 | { | |
3174 | int some_failed = 0; | |
3175 | struct bp_location *loc; | |
3176 | ||
3177 | if (!is_hardware_watchpoint (bpt)) | |
3178 | continue; | |
3179 | ||
d6b74ac4 | 3180 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3181 | continue; |
74960c60 VP |
3182 | |
3183 | if (bpt->disposition == disp_del_at_next_stop) | |
3184 | continue; | |
a5606eee VP |
3185 | |
3186 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3187 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3188 | { |
3189 | some_failed = 1; | |
3190 | break; | |
3191 | } | |
3192 | if (some_failed) | |
3193 | { | |
3194 | for (loc = bpt->loc; loc; loc = loc->next) | |
3195 | if (loc->inserted) | |
3196 | remove_breakpoint (loc, mark_uninserted); | |
3197 | ||
3198 | hw_breakpoint_error = 1; | |
3199 | fprintf_unfiltered (tmp_error_stream, | |
3200 | "Could not insert hardware watchpoint %d.\n", | |
3201 | bpt->number); | |
eacd795a | 3202 | error_flag = -1; |
a5606eee VP |
3203 | } |
3204 | } | |
3205 | ||
eacd795a | 3206 | if (error_flag) |
81d0cc19 GS |
3207 | { |
3208 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3209 | message about possibly exhausted resources. */ | |
dd61ec5c | 3210 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3211 | { |
c6510018 MS |
3212 | fprintf_unfiltered (tmp_error_stream, |
3213 | "Could not insert hardware breakpoints:\n\ | |
3214 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3215 | } |
81d0cc19 GS |
3216 | target_terminal_ours_for_output (); |
3217 | error_stream (tmp_error_stream); | |
3218 | } | |
f7545552 TT |
3219 | |
3220 | do_cleanups (cleanups); | |
c906108c SS |
3221 | } |
3222 | ||
c30eee59 TJB |
3223 | /* Used when the program stops. |
3224 | Returns zero if successful, or non-zero if there was a problem | |
3225 | removing a breakpoint location. */ | |
3226 | ||
c906108c | 3227 | int |
fba45db2 | 3228 | remove_breakpoints (void) |
c906108c | 3229 | { |
35df4500 | 3230 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3231 | int val = 0; |
c906108c | 3232 | |
35df4500 | 3233 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3234 | { |
1e4d1764 | 3235 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3236 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3237 | } |
3a1bae8e | 3238 | return val; |
c906108c SS |
3239 | } |
3240 | ||
49fa26b0 PA |
3241 | /* When a thread exits, remove breakpoints that are related to |
3242 | that thread. */ | |
3243 | ||
3244 | static void | |
3245 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3246 | { | |
3247 | struct breakpoint *b, *b_tmp; | |
3248 | ||
3249 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3250 | { | |
5d5658a1 | 3251 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3252 | { |
3253 | b->disposition = disp_del_at_next_stop; | |
3254 | ||
3255 | printf_filtered (_("\ | |
43792cf0 PA |
3256 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3257 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3258 | |
3259 | /* Hide it from the user. */ | |
3260 | b->number = 0; | |
3261 | } | |
3262 | } | |
3263 | } | |
3264 | ||
6c95b8df PA |
3265 | /* Remove breakpoints of process PID. */ |
3266 | ||
3267 | int | |
3268 | remove_breakpoints_pid (int pid) | |
3269 | { | |
35df4500 | 3270 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3271 | int val; |
3272 | struct inferior *inf = find_inferior_pid (pid); | |
3273 | ||
35df4500 | 3274 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3275 | { |
35df4500 | 3276 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3277 | continue; |
3278 | ||
fc126975 | 3279 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3280 | { |
35df4500 | 3281 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3282 | if (val != 0) |
3283 | return val; | |
3284 | } | |
3285 | } | |
3286 | return 0; | |
3287 | } | |
3288 | ||
c906108c | 3289 | int |
fba45db2 | 3290 | reattach_breakpoints (int pid) |
c906108c | 3291 | { |
6c95b8df | 3292 | struct cleanup *old_chain; |
35df4500 | 3293 | struct bp_location *bl, **blp_tmp; |
c906108c | 3294 | int val; |
86b887df | 3295 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3296 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3297 | struct inferior *inf; |
3298 | struct thread_info *tp; | |
3299 | ||
3300 | tp = any_live_thread_of_process (pid); | |
3301 | if (tp == NULL) | |
3302 | return 1; | |
3303 | ||
3304 | inf = find_inferior_pid (pid); | |
3305 | old_chain = save_inferior_ptid (); | |
3306 | ||
3307 | inferior_ptid = tp->ptid; | |
a4954f26 | 3308 | |
86b887df | 3309 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3310 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3311 | |
35df4500 | 3312 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3313 | { |
35df4500 | 3314 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3315 | continue; |
3316 | ||
35df4500 | 3317 | if (bl->inserted) |
c5aa993b | 3318 | { |
35df4500 | 3319 | bl->inserted = 0; |
dd61ec5c | 3320 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3321 | if (val != 0) |
3322 | { | |
ce696e05 | 3323 | do_cleanups (old_chain); |
c5aa993b JM |
3324 | return val; |
3325 | } | |
3326 | } | |
3327 | } | |
ce696e05 | 3328 | do_cleanups (old_chain); |
c906108c SS |
3329 | return 0; |
3330 | } | |
3331 | ||
e58b0e63 PA |
3332 | static int internal_breakpoint_number = -1; |
3333 | ||
84f4c1fe PM |
3334 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3335 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3336 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3337 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3338 | breakpoint_count and that value incremented. Internal breakpoints |
3339 | do not set the internal var bpnum. */ | |
3340 | static void | |
3341 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3342 | { | |
3343 | if (internal) | |
3344 | b->number = internal_breakpoint_number--; | |
3345 | else | |
3346 | { | |
3347 | set_breakpoint_count (breakpoint_count + 1); | |
3348 | b->number = breakpoint_count; | |
3349 | } | |
3350 | } | |
3351 | ||
e62c965a | 3352 | static struct breakpoint * |
a6d9a66e | 3353 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3354 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3355 | const struct breakpoint_ops *ops) |
e62c965a | 3356 | { |
e62c965a PP |
3357 | struct symtab_and_line sal; |
3358 | struct breakpoint *b; | |
3359 | ||
4a64f543 | 3360 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3361 | |
3362 | sal.pc = address; | |
3363 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3364 | sal.pspace = current_program_space; |
e62c965a | 3365 | |
06edf0c0 | 3366 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3367 | b->number = internal_breakpoint_number--; |
3368 | b->disposition = disp_donttouch; | |
3369 | ||
3370 | return b; | |
3371 | } | |
3372 | ||
17450429 PP |
3373 | static const char *const longjmp_names[] = |
3374 | { | |
3375 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3376 | }; | |
3377 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3378 | ||
3379 | /* Per-objfile data private to breakpoint.c. */ | |
3380 | struct breakpoint_objfile_data | |
3381 | { | |
3382 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3383 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3384 | |
3385 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3386 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3387 | |
28106bc2 SDJ |
3388 | /* True if we have looked for longjmp probes. */ |
3389 | int longjmp_searched; | |
3390 | ||
3391 | /* SystemTap probe points for longjmp (if any). */ | |
3392 | VEC (probe_p) *longjmp_probes; | |
3393 | ||
17450429 | 3394 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3395 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3396 | |
3397 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3398 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3399 | |
3400 | /* True if we have looked for exception probes. */ | |
3401 | int exception_searched; | |
3402 | ||
3403 | /* SystemTap probe points for unwinding (if any). */ | |
3404 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3405 | }; |
3406 | ||
3407 | static const struct objfile_data *breakpoint_objfile_key; | |
3408 | ||
3409 | /* Minimal symbol not found sentinel. */ | |
3410 | static struct minimal_symbol msym_not_found; | |
3411 | ||
3412 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3413 | ||
3414 | static int | |
3415 | msym_not_found_p (const struct minimal_symbol *msym) | |
3416 | { | |
3417 | return msym == &msym_not_found; | |
3418 | } | |
3419 | ||
3420 | /* Return per-objfile data needed by breakpoint.c. | |
3421 | Allocate the data if necessary. */ | |
3422 | ||
3423 | static struct breakpoint_objfile_data * | |
3424 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3425 | { | |
3426 | struct breakpoint_objfile_data *bp_objfile_data; | |
3427 | ||
9a3c8263 SM |
3428 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3429 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3430 | if (bp_objfile_data == NULL) |
3431 | { | |
8d749320 SM |
3432 | bp_objfile_data = |
3433 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3434 | |
3435 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3436 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3437 | } | |
3438 | return bp_objfile_data; | |
3439 | } | |
3440 | ||
28106bc2 SDJ |
3441 | static void |
3442 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3443 | { | |
9a3c8263 SM |
3444 | struct breakpoint_objfile_data *bp_objfile_data |
3445 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3446 | |
3447 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3448 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3449 | } | |
3450 | ||
e62c965a | 3451 | static void |
af02033e | 3452 | create_overlay_event_breakpoint (void) |
e62c965a | 3453 | { |
69de3c6a | 3454 | struct objfile *objfile; |
af02033e | 3455 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3456 | |
69de3c6a PP |
3457 | ALL_OBJFILES (objfile) |
3458 | { | |
3459 | struct breakpoint *b; | |
17450429 PP |
3460 | struct breakpoint_objfile_data *bp_objfile_data; |
3461 | CORE_ADDR addr; | |
67994074 | 3462 | struct explicit_location explicit_loc; |
69de3c6a | 3463 | |
17450429 PP |
3464 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3465 | ||
3b7344d5 | 3466 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3467 | continue; |
3468 | ||
3b7344d5 | 3469 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3470 | { |
3b7344d5 | 3471 | struct bound_minimal_symbol m; |
17450429 PP |
3472 | |
3473 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3474 | if (m.minsym == NULL) |
17450429 PP |
3475 | { |
3476 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3477 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3478 | continue; |
3479 | } | |
3480 | bp_objfile_data->overlay_msym = m; | |
3481 | } | |
e62c965a | 3482 | |
77e371c0 | 3483 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3484 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3485 | bp_overlay_event, |
3486 | &internal_breakpoint_ops); | |
67994074 KS |
3487 | initialize_explicit_location (&explicit_loc); |
3488 | explicit_loc.function_name = ASTRDUP (func_name); | |
3489 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3490 | |
69de3c6a PP |
3491 | if (overlay_debugging == ovly_auto) |
3492 | { | |
3493 | b->enable_state = bp_enabled; | |
3494 | overlay_events_enabled = 1; | |
3495 | } | |
3496 | else | |
3497 | { | |
3498 | b->enable_state = bp_disabled; | |
3499 | overlay_events_enabled = 0; | |
3500 | } | |
e62c965a | 3501 | } |
e62c965a PP |
3502 | } |
3503 | ||
0fd8e87f | 3504 | static void |
af02033e | 3505 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3506 | { |
6c95b8df | 3507 | struct program_space *pspace; |
6c95b8df PA |
3508 | struct cleanup *old_chain; |
3509 | ||
3510 | old_chain = save_current_program_space (); | |
0fd8e87f | 3511 | |
6c95b8df | 3512 | ALL_PSPACES (pspace) |
af02033e PP |
3513 | { |
3514 | struct objfile *objfile; | |
3515 | ||
3516 | set_current_program_space (pspace); | |
3517 | ||
3518 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3519 | { |
af02033e PP |
3520 | int i; |
3521 | struct gdbarch *gdbarch; | |
17450429 | 3522 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3523 | |
af02033e | 3524 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3525 | |
17450429 PP |
3526 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3527 | ||
28106bc2 SDJ |
3528 | if (!bp_objfile_data->longjmp_searched) |
3529 | { | |
25f9533e SDJ |
3530 | VEC (probe_p) *ret; |
3531 | ||
3532 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3533 | if (ret != NULL) | |
3534 | { | |
3535 | /* We are only interested in checking one element. */ | |
3536 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3537 | ||
3538 | if (!can_evaluate_probe_arguments (p)) | |
3539 | { | |
3540 | /* We cannot use the probe interface here, because it does | |
3541 | not know how to evaluate arguments. */ | |
3542 | VEC_free (probe_p, ret); | |
3543 | ret = NULL; | |
3544 | } | |
3545 | } | |
3546 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3547 | bp_objfile_data->longjmp_searched = 1; |
3548 | } | |
3549 | ||
3550 | if (bp_objfile_data->longjmp_probes != NULL) | |
3551 | { | |
3552 | int i; | |
3553 | struct probe *probe; | |
3554 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3555 | ||
3556 | for (i = 0; | |
3557 | VEC_iterate (probe_p, | |
3558 | bp_objfile_data->longjmp_probes, | |
3559 | i, probe); | |
3560 | ++i) | |
3561 | { | |
3562 | struct breakpoint *b; | |
3563 | ||
729662a5 TT |
3564 | b = create_internal_breakpoint (gdbarch, |
3565 | get_probe_address (probe, | |
3566 | objfile), | |
28106bc2 SDJ |
3567 | bp_longjmp_master, |
3568 | &internal_breakpoint_ops); | |
5b56227b KS |
3569 | b->location |
3570 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3571 | b->enable_state = bp_disabled; |
3572 | } | |
3573 | ||
3574 | continue; | |
3575 | } | |
3576 | ||
0569175e TSD |
3577 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3578 | continue; | |
3579 | ||
17450429 | 3580 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3581 | { |
3582 | struct breakpoint *b; | |
af02033e | 3583 | const char *func_name; |
17450429 | 3584 | CORE_ADDR addr; |
67994074 | 3585 | struct explicit_location explicit_loc; |
6c95b8df | 3586 | |
3b7344d5 | 3587 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3588 | continue; |
0fd8e87f | 3589 | |
17450429 | 3590 | func_name = longjmp_names[i]; |
3b7344d5 | 3591 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3592 | { |
3b7344d5 | 3593 | struct bound_minimal_symbol m; |
17450429 PP |
3594 | |
3595 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3596 | if (m.minsym == NULL) |
17450429 PP |
3597 | { |
3598 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3599 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3600 | continue; |
3601 | } | |
3602 | bp_objfile_data->longjmp_msym[i] = m; | |
3603 | } | |
3604 | ||
77e371c0 | 3605 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3606 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3607 | &internal_breakpoint_ops); | |
67994074 KS |
3608 | initialize_explicit_location (&explicit_loc); |
3609 | explicit_loc.function_name = ASTRDUP (func_name); | |
3610 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3611 | b->enable_state = bp_disabled; |
3612 | } | |
0fd8e87f | 3613 | } |
af02033e | 3614 | } |
6c95b8df PA |
3615 | |
3616 | do_cleanups (old_chain); | |
0fd8e87f UW |
3617 | } |
3618 | ||
af02033e | 3619 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3620 | static void |
af02033e | 3621 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3622 | { |
3623 | struct program_space *pspace; | |
aa7d318d | 3624 | struct cleanup *old_chain; |
af02033e | 3625 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3626 | |
3627 | old_chain = save_current_program_space (); | |
3628 | ||
3629 | ALL_PSPACES (pspace) | |
17450429 PP |
3630 | { |
3631 | struct objfile *objfile; | |
3632 | CORE_ADDR addr; | |
3633 | ||
3634 | set_current_program_space (pspace); | |
3635 | ||
aa7d318d TT |
3636 | ALL_OBJFILES (objfile) |
3637 | { | |
3638 | struct breakpoint *b; | |
17450429 | 3639 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3640 | struct explicit_location explicit_loc; |
aa7d318d | 3641 | |
17450429 | 3642 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3643 | |
3b7344d5 | 3644 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3645 | continue; |
3646 | ||
3b7344d5 | 3647 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3648 | { |
3b7344d5 | 3649 | struct bound_minimal_symbol m; |
17450429 PP |
3650 | |
3651 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3652 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3653 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3654 | { |
3655 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3656 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3657 | continue; |
3658 | } | |
3659 | bp_objfile_data->terminate_msym = m; | |
3660 | } | |
aa7d318d | 3661 | |
77e371c0 | 3662 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3663 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3664 | bp_std_terminate_master, |
3665 | &internal_breakpoint_ops); | |
67994074 KS |
3666 | initialize_explicit_location (&explicit_loc); |
3667 | explicit_loc.function_name = ASTRDUP (func_name); | |
3668 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3669 | b->enable_state = bp_disabled; |
3670 | } | |
17450429 PP |
3671 | } |
3672 | ||
aa7d318d TT |
3673 | do_cleanups (old_chain); |
3674 | } | |
3675 | ||
186c406b TT |
3676 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3677 | ||
70221824 | 3678 | static void |
186c406b TT |
3679 | create_exception_master_breakpoint (void) |
3680 | { | |
3681 | struct objfile *objfile; | |
17450429 | 3682 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3683 | |
3684 | ALL_OBJFILES (objfile) | |
3685 | { | |
17450429 PP |
3686 | struct breakpoint *b; |
3687 | struct gdbarch *gdbarch; | |
3688 | struct breakpoint_objfile_data *bp_objfile_data; | |
3689 | CORE_ADDR addr; | |
67994074 | 3690 | struct explicit_location explicit_loc; |
17450429 PP |
3691 | |
3692 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3693 | ||
28106bc2 SDJ |
3694 | /* We prefer the SystemTap probe point if it exists. */ |
3695 | if (!bp_objfile_data->exception_searched) | |
3696 | { | |
25f9533e SDJ |
3697 | VEC (probe_p) *ret; |
3698 | ||
3699 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3700 | ||
3701 | if (ret != NULL) | |
3702 | { | |
3703 | /* We are only interested in checking one element. */ | |
3704 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3705 | ||
3706 | if (!can_evaluate_probe_arguments (p)) | |
3707 | { | |
3708 | /* We cannot use the probe interface here, because it does | |
3709 | not know how to evaluate arguments. */ | |
3710 | VEC_free (probe_p, ret); | |
3711 | ret = NULL; | |
3712 | } | |
3713 | } | |
3714 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3715 | bp_objfile_data->exception_searched = 1; |
3716 | } | |
3717 | ||
3718 | if (bp_objfile_data->exception_probes != NULL) | |
3719 | { | |
3720 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3721 | int i; | |
3722 | struct probe *probe; | |
3723 | ||
3724 | for (i = 0; | |
3725 | VEC_iterate (probe_p, | |
3726 | bp_objfile_data->exception_probes, | |
3727 | i, probe); | |
3728 | ++i) | |
3729 | { | |
3730 | struct breakpoint *b; | |
3731 | ||
729662a5 TT |
3732 | b = create_internal_breakpoint (gdbarch, |
3733 | get_probe_address (probe, | |
3734 | objfile), | |
28106bc2 SDJ |
3735 | bp_exception_master, |
3736 | &internal_breakpoint_ops); | |
5b56227b KS |
3737 | b->location |
3738 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3739 | b->enable_state = bp_disabled; |
3740 | } | |
3741 | ||
3742 | continue; | |
3743 | } | |
3744 | ||
3745 | /* Otherwise, try the hook function. */ | |
3746 | ||
3b7344d5 | 3747 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3748 | continue; |
3749 | ||
3750 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3751 | |
3b7344d5 | 3752 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3753 | { |
3b7344d5 | 3754 | struct bound_minimal_symbol debug_hook; |
186c406b | 3755 | |
17450429 | 3756 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3757 | if (debug_hook.minsym == NULL) |
17450429 | 3758 | { |
3b7344d5 | 3759 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3760 | continue; |
3761 | } | |
3762 | ||
3763 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3764 | } |
17450429 | 3765 | |
77e371c0 | 3766 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3767 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3768 | ¤t_target); | |
06edf0c0 PA |
3769 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3770 | &internal_breakpoint_ops); | |
67994074 KS |
3771 | initialize_explicit_location (&explicit_loc); |
3772 | explicit_loc.function_name = ASTRDUP (func_name); | |
3773 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3774 | b->enable_state = bp_disabled; |
186c406b | 3775 | } |
186c406b TT |
3776 | } |
3777 | ||
9ef9e6a6 KS |
3778 | /* Does B have a location spec? */ |
3779 | ||
3780 | static int | |
3781 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3782 | { | |
3783 | return b->location != NULL && event_location_empty_p (b->location); | |
3784 | } | |
3785 | ||
c906108c | 3786 | void |
fba45db2 | 3787 | update_breakpoints_after_exec (void) |
c906108c | 3788 | { |
35df4500 | 3789 | struct breakpoint *b, *b_tmp; |
876fa593 | 3790 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3791 | |
25b22b0a PA |
3792 | /* We're about to delete breakpoints from GDB's lists. If the |
3793 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3794 | writing the breakpoints' "shadow contents" back into memory. The | |
3795 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3796 | do that. Instead, the target is responsible from marking | |
3797 | breakpoints out as soon as it detects an exec. We don't do that | |
3798 | here instead, because there may be other attempts to delete | |
3799 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3800 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3801 | if (bploc->pspace == current_program_space) |
3802 | gdb_assert (!bploc->inserted); | |
c906108c | 3803 | |
35df4500 | 3804 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3805 | { |
6c95b8df PA |
3806 | if (b->pspace != current_program_space) |
3807 | continue; | |
3808 | ||
4a64f543 | 3809 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3810 | if (b->type == bp_shlib_event) |
3811 | { | |
3812 | delete_breakpoint (b); | |
3813 | continue; | |
3814 | } | |
c906108c | 3815 | |
4a64f543 | 3816 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3817 | if (b->type == bp_jit_event) |
3818 | { | |
3819 | delete_breakpoint (b); | |
3820 | continue; | |
3821 | } | |
3822 | ||
1900040c | 3823 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3824 | as must overlay event and longjmp master breakpoints. */ |
3825 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3826 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3827 | || b->type == bp_exception_master) | |
c4093a6a JM |
3828 | { |
3829 | delete_breakpoint (b); | |
3830 | continue; | |
3831 | } | |
3832 | ||
4a64f543 | 3833 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3834 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3835 | { |
3836 | delete_breakpoint (b); | |
3837 | continue; | |
3838 | } | |
3839 | ||
7c16b83e PA |
3840 | /* Just like single-step breakpoints. */ |
3841 | if (b->type == bp_single_step) | |
3842 | { | |
3843 | delete_breakpoint (b); | |
3844 | continue; | |
3845 | } | |
3846 | ||
611c83ae PA |
3847 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3848 | after an exec. */ | |
186c406b | 3849 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3850 | || b->type == bp_longjmp_call_dummy |
186c406b | 3851 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3852 | { |
3853 | delete_breakpoint (b); | |
3854 | continue; | |
3855 | } | |
3856 | ||
ce78b96d JB |
3857 | if (b->type == bp_catchpoint) |
3858 | { | |
3859 | /* For now, none of the bp_catchpoint breakpoints need to | |
3860 | do anything at this point. In the future, if some of | |
3861 | the catchpoints need to something, we will need to add | |
3862 | a new method, and call this method from here. */ | |
3863 | continue; | |
3864 | } | |
3865 | ||
c5aa993b JM |
3866 | /* bp_finish is a special case. The only way we ought to be able |
3867 | to see one of these when an exec() has happened, is if the user | |
3868 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3869 | carries them to the call-site of the current callee, by setting | |
3870 | a temporary bp there and resuming. But in this case, the finish | |
3871 | will carry them entirely through the vfork & exec. | |
3872 | ||
3873 | We don't want to allow a bp_finish to remain inserted now. But | |
3874 | we can't safely delete it, 'cause finish_command has a handle to | |
3875 | the bp on a bpstat, and will later want to delete it. There's a | |
3876 | chance (and I've seen it happen) that if we delete the bp_finish | |
3877 | here, that its storage will get reused by the time finish_command | |
3878 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3879 | We really must allow finish_command to delete a bp_finish. | |
3880 | ||
e5dd4106 | 3881 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3882 | it's safe to delete something others may have handles to?" |
3883 | problem, what we'll do here is just uninsert the bp_finish, and | |
3884 | let finish_command delete it. | |
3885 | ||
3886 | (We know the bp_finish is "doomed" in the sense that it's | |
3887 | momentary, and will be deleted as soon as finish_command sees | |
3888 | the inferior stopped. So it doesn't matter that the bp's | |
3889 | address is probably bogus in the new a.out, unlike e.g., the | |
3890 | solib breakpoints.) */ | |
c5aa993b | 3891 | |
c5aa993b JM |
3892 | if (b->type == bp_finish) |
3893 | { | |
3894 | continue; | |
3895 | } | |
3896 | ||
3897 | /* Without a symbolic address, we have little hope of the | |
3898 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3899 | a.out. */ |
9ef9e6a6 | 3900 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3901 | { |
3902 | delete_breakpoint (b); | |
3903 | continue; | |
3904 | } | |
c5aa993b | 3905 | } |
c906108c SS |
3906 | } |
3907 | ||
3908 | int | |
d80ee84f | 3909 | detach_breakpoints (ptid_t ptid) |
c906108c | 3910 | { |
35df4500 | 3911 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3912 | int val = 0; |
ce696e05 | 3913 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3914 | struct inferior *inf = current_inferior (); |
c5aa993b | 3915 | |
dfd4cc63 | 3916 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3917 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3918 | |
6c95b8df | 3919 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3920 | inferior_ptid = ptid; |
35df4500 | 3921 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3922 | { |
35df4500 | 3923 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3924 | continue; |
3925 | ||
bd9673a4 PW |
3926 | /* This function must physically remove breakpoints locations |
3927 | from the specified ptid, without modifying the breakpoint | |
3928 | package's state. Locations of type bp_loc_other are only | |
3929 | maintained at GDB side. So, there is no need to remove | |
3930 | these bp_loc_other locations. Moreover, removing these | |
3931 | would modify the breakpoint package's state. */ | |
3932 | if (bl->loc_type == bp_loc_other) | |
3933 | continue; | |
3934 | ||
35df4500 TJB |
3935 | if (bl->inserted) |
3936 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3937 | } |
d03285ec | 3938 | |
ce696e05 | 3939 | do_cleanups (old_chain); |
3a1bae8e | 3940 | return val; |
c906108c SS |
3941 | } |
3942 | ||
35df4500 | 3943 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3944 | Note that this is used to detach breakpoints from a child fork. |
3945 | When we get here, the child isn't in the inferior list, and neither | |
3946 | do we have objects to represent its address space --- we should | |
35df4500 | 3947 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3948 | |
c906108c | 3949 | static int |
35df4500 | 3950 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3951 | { |
3952 | int val; | |
c5aa993b | 3953 | |
35df4500 TJB |
3954 | /* BL is never in moribund_locations by our callers. */ |
3955 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3956 | |
74960c60 VP |
3957 | /* The type of none suggests that owner is actually deleted. |
3958 | This should not ever happen. */ | |
35df4500 | 3959 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3960 | |
35df4500 TJB |
3961 | if (bl->loc_type == bp_loc_software_breakpoint |
3962 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3963 | { |
c02f5703 MS |
3964 | /* "Normal" instruction breakpoint: either the standard |
3965 | trap-instruction bp (bp_breakpoint), or a | |
3966 | bp_hardware_breakpoint. */ | |
3967 | ||
3968 | /* First check to see if we have to handle an overlay. */ | |
3969 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3970 | || bl->section == NULL |
3971 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3972 | { |
3973 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3974 | |
3975 | /* If we're trying to uninsert a memory breakpoint that we | |
3976 | know is set in a dynamic object that is marked | |
3977 | shlib_disabled, then either the dynamic object was | |
3978 | removed with "remove-symbol-file" or with | |
3979 | "nosharedlibrary". In the former case, we don't know | |
3980 | whether another dynamic object might have loaded over the | |
3981 | breakpoint's address -- the user might well let us know | |
3982 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3983 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3984 | list of dynamically loaded objects). If we have the |
3985 | breakpoint's shadow memory, that is, this is a software | |
3986 | breakpoint managed by GDB, check whether the breakpoint | |
3987 | is still inserted in memory, to avoid overwriting wrong | |
3988 | code with stale saved shadow contents. Note that HW | |
3989 | breakpoints don't have shadow memory, as they're | |
3990 | implemented using a mechanism that is not dependent on | |
3991 | being able to modify the target's memory, and as such | |
3992 | they should always be removed. */ | |
3993 | if (bl->shlib_disabled | |
3994 | && bl->target_info.shadow_len != 0 | |
3995 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3996 | val = 0; | |
3997 | else | |
3998 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3999 | } |
c906108c SS |
4000 | else |
4001 | { | |
4a64f543 | 4002 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
4003 | Did we set a breakpoint at the LMA? */ |
4004 | if (!overlay_events_enabled) | |
4005 | { | |
4006 | /* Yes -- overlay event support is not active, so we | |
4007 | should have set a breakpoint at the LMA. Remove it. | |
4008 | */ | |
c02f5703 MS |
4009 | /* Ignore any failures: if the LMA is in ROM, we will |
4010 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4011 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4012 | target_remove_hw_breakpoint (bl->gdbarch, | |
4013 | &bl->overlay_target_info); | |
c02f5703 | 4014 | else |
35df4500 TJB |
4015 | target_remove_breakpoint (bl->gdbarch, |
4016 | &bl->overlay_target_info); | |
c02f5703 MS |
4017 | } |
4018 | /* Did we set a breakpoint at the VMA? | |
4019 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4020 | if (bl->inserted) |
c906108c | 4021 | { |
c02f5703 MS |
4022 | /* Yes -- remove it. Previously we did not bother to |
4023 | remove the breakpoint if the section had been | |
4024 | unmapped, but let's not rely on that being safe. We | |
4025 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4026 | |
4027 | /* However, we should remove *software* breakpoints only | |
4028 | if the section is still mapped, or else we overwrite | |
4029 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4030 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4031 | || section_is_mapped (bl->section)) | |
4032 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
4033 | else |
4034 | val = 0; | |
c906108c | 4035 | } |
c02f5703 MS |
4036 | else |
4037 | { | |
4038 | /* No -- not inserted, so no need to remove. No error. */ | |
4039 | val = 0; | |
4040 | } | |
c906108c | 4041 | } |
879d1e6b | 4042 | |
08351840 PA |
4043 | /* In some cases, we might not be able to remove a breakpoint in |
4044 | a shared library that has already been removed, but we have | |
4045 | not yet processed the shlib unload event. Similarly for an | |
4046 | unloaded add-symbol-file object - the user might not yet have | |
4047 | had the chance to remove-symbol-file it. shlib_disabled will | |
4048 | be set if the library/object has already been removed, but | |
4049 | the breakpoint hasn't been uninserted yet, e.g., after | |
4050 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4051 | always-inserted mode. */ | |
076855f9 | 4052 | if (val |
08351840 PA |
4053 | && (bl->loc_type == bp_loc_software_breakpoint |
4054 | && (bl->shlib_disabled | |
4055 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4056 | || shared_objfile_contains_address_p (bl->pspace, |
4057 | bl->address)))) | |
879d1e6b UW |
4058 | val = 0; |
4059 | ||
c906108c SS |
4060 | if (val) |
4061 | return val; | |
35df4500 | 4062 | bl->inserted = (is == mark_inserted); |
c906108c | 4063 | } |
35df4500 | 4064 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4065 | { |
77b06cd7 TJB |
4066 | gdb_assert (bl->owner->ops != NULL |
4067 | && bl->owner->ops->remove_location != NULL); | |
4068 | ||
35df4500 | 4069 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4070 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4071 | |
c906108c | 4072 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4073 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4074 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4075 | bl->owner->number); |
c906108c | 4076 | } |
35df4500 TJB |
4077 | else if (bl->owner->type == bp_catchpoint |
4078 | && breakpoint_enabled (bl->owner) | |
4079 | && !bl->duplicate) | |
ce78b96d | 4080 | { |
77b06cd7 TJB |
4081 | gdb_assert (bl->owner->ops != NULL |
4082 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4083 | |
77b06cd7 | 4084 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4085 | if (val) |
4086 | return val; | |
77b06cd7 | 4087 | |
35df4500 | 4088 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4089 | } |
c906108c SS |
4090 | |
4091 | return 0; | |
4092 | } | |
4093 | ||
6c95b8df | 4094 | static int |
35df4500 | 4095 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4096 | { |
4097 | int ret; | |
4098 | struct cleanup *old_chain; | |
4099 | ||
35df4500 TJB |
4100 | /* BL is never in moribund_locations by our callers. */ |
4101 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4102 | |
6c95b8df PA |
4103 | /* The type of none suggests that owner is actually deleted. |
4104 | This should not ever happen. */ | |
35df4500 | 4105 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4106 | |
4107 | old_chain = save_current_space_and_thread (); | |
4108 | ||
35df4500 | 4109 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4110 | |
35df4500 | 4111 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4112 | |
4113 | do_cleanups (old_chain); | |
4114 | return ret; | |
4115 | } | |
4116 | ||
c906108c SS |
4117 | /* Clear the "inserted" flag in all breakpoints. */ |
4118 | ||
25b22b0a | 4119 | void |
fba45db2 | 4120 | mark_breakpoints_out (void) |
c906108c | 4121 | { |
35df4500 | 4122 | struct bp_location *bl, **blp_tmp; |
c906108c | 4123 | |
35df4500 | 4124 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4125 | if (bl->pspace == current_program_space) |
35df4500 | 4126 | bl->inserted = 0; |
c906108c SS |
4127 | } |
4128 | ||
53a5351d JM |
4129 | /* Clear the "inserted" flag in all breakpoints and delete any |
4130 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4131 | |
4132 | Plus other such housekeeping that has to be done for breakpoints | |
4133 | between runs. | |
4134 | ||
53a5351d JM |
4135 | Note: this function gets called at the end of a run (by |
4136 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4137 | init_wait_for_inferior). */ |
c906108c SS |
4138 | |
4139 | ||
4140 | ||
4141 | void | |
fba45db2 | 4142 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4143 | { |
35df4500 TJB |
4144 | struct breakpoint *b, *b_tmp; |
4145 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4146 | int ix; |
6c95b8df | 4147 | struct program_space *pspace = current_program_space; |
c906108c | 4148 | |
50c71eaf PA |
4149 | /* If breakpoint locations are shared across processes, then there's |
4150 | nothing to do. */ | |
f5656ead | 4151 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4152 | return; |
4153 | ||
1a853c52 | 4154 | mark_breakpoints_out (); |
075f6582 | 4155 | |
35df4500 | 4156 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4157 | { |
6c95b8df PA |
4158 | if (b->loc && b->loc->pspace != pspace) |
4159 | continue; | |
4160 | ||
c5aa993b JM |
4161 | switch (b->type) |
4162 | { | |
4163 | case bp_call_dummy: | |
e2e4d78b | 4164 | case bp_longjmp_call_dummy: |
c906108c | 4165 | |
c5aa993b | 4166 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4167 | cause problems when the inferior is rerun, so we better get |
4168 | rid of it. */ | |
4169 | ||
4170 | case bp_watchpoint_scope: | |
4171 | ||
4172 | /* Also get rid of scope breakpoints. */ | |
4173 | ||
4174 | case bp_shlib_event: | |
4175 | ||
4176 | /* Also remove solib event breakpoints. Their addresses may | |
4177 | have changed since the last time we ran the program. | |
4178 | Actually we may now be debugging against different target; | |
4179 | and so the solib backend that installed this breakpoint may | |
4180 | not be used in by the target. E.g., | |
4181 | ||
4182 | (gdb) file prog-linux | |
4183 | (gdb) run # native linux target | |
4184 | ... | |
4185 | (gdb) kill | |
4186 | (gdb) file prog-win.exe | |
4187 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4188 | */ | |
c906108c | 4189 | |
f59f708a PA |
4190 | case bp_step_resume: |
4191 | ||
4192 | /* Also remove step-resume breakpoints. */ | |
4193 | ||
7c16b83e PA |
4194 | case bp_single_step: |
4195 | ||
4196 | /* Also remove single-step breakpoints. */ | |
4197 | ||
c5aa993b JM |
4198 | delete_breakpoint (b); |
4199 | break; | |
c906108c | 4200 | |
c5aa993b JM |
4201 | case bp_watchpoint: |
4202 | case bp_hardware_watchpoint: | |
4203 | case bp_read_watchpoint: | |
4204 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4205 | { |
4206 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4207 | |
3a5c3e22 PA |
4208 | /* Likewise for watchpoints on local expressions. */ |
4209 | if (w->exp_valid_block != NULL) | |
4210 | delete_breakpoint (b); | |
4211 | else if (context == inf_starting) | |
4212 | { | |
4213 | /* Reset val field to force reread of starting value in | |
4214 | insert_breakpoints. */ | |
4215 | if (w->val) | |
4216 | value_free (w->val); | |
4217 | w->val = NULL; | |
4218 | w->val_valid = 0; | |
c860120c | 4219 | } |
3a5c3e22 | 4220 | } |
c5aa993b JM |
4221 | break; |
4222 | default: | |
c5aa993b JM |
4223 | break; |
4224 | } | |
4225 | } | |
1c5cfe86 PA |
4226 | |
4227 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4228 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4229 | decref_bp_location (&bl); | |
1c5cfe86 | 4230 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4231 | } |
4232 | ||
6c95b8df PA |
4233 | /* These functions concern about actual breakpoints inserted in the |
4234 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4235 | we need to hop over the bkpt --- so we check for address space | |
4236 | match, not program space. */ | |
4237 | ||
c2c6d25f JM |
4238 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4239 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4240 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4241 | permanent breakpoint. | |
4242 | - When continuing from a location with an ordinary breakpoint, we | |
4243 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4244 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4245 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4246 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4247 | |
c2c6d25f | 4248 | enum breakpoint_here |
6c95b8df | 4249 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4250 | { |
35df4500 | 4251 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4252 | int any_breakpoint_here = 0; |
c906108c | 4253 | |
35df4500 | 4254 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4255 | { |
35df4500 TJB |
4256 | if (bl->loc_type != bp_loc_software_breakpoint |
4257 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4258 | continue; |
4259 | ||
f1310107 | 4260 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4261 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4262 | || bl->permanent) |
f1310107 | 4263 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4264 | { |
4265 | if (overlay_debugging | |
35df4500 TJB |
4266 | && section_is_overlay (bl->section) |
4267 | && !section_is_mapped (bl->section)) | |
075f6582 | 4268 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4269 | else if (bl->permanent) |
075f6582 DJ |
4270 | return permanent_breakpoint_here; |
4271 | else | |
4272 | any_breakpoint_here = 1; | |
4273 | } | |
4274 | } | |
c906108c | 4275 | |
f486487f | 4276 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4277 | } |
4278 | ||
d35ae833 PA |
4279 | /* See breakpoint.h. */ |
4280 | ||
4281 | int | |
4282 | breakpoint_in_range_p (struct address_space *aspace, | |
4283 | CORE_ADDR addr, ULONGEST len) | |
4284 | { | |
4285 | struct bp_location *bl, **blp_tmp; | |
4286 | ||
4287 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4288 | { | |
4289 | if (bl->loc_type != bp_loc_software_breakpoint | |
4290 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4291 | continue; | |
4292 | ||
4293 | if ((breakpoint_enabled (bl->owner) | |
4294 | || bl->permanent) | |
4295 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4296 | addr, len)) | |
4297 | { | |
4298 | if (overlay_debugging | |
4299 | && section_is_overlay (bl->section) | |
4300 | && !section_is_mapped (bl->section)) | |
4301 | { | |
4302 | /* Unmapped overlay -- can't be a match. */ | |
4303 | continue; | |
4304 | } | |
4305 | ||
4306 | return 1; | |
4307 | } | |
4308 | } | |
4309 | ||
4310 | return 0; | |
4311 | } | |
4312 | ||
1c5cfe86 PA |
4313 | /* Return true if there's a moribund breakpoint at PC. */ |
4314 | ||
4315 | int | |
6c95b8df | 4316 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4317 | { |
4318 | struct bp_location *loc; | |
4319 | int ix; | |
4320 | ||
4321 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4322 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4323 | return 1; |
4324 | ||
4325 | return 0; | |
4326 | } | |
c2c6d25f | 4327 | |
f7ce857f PA |
4328 | /* Returns non-zero iff BL is inserted at PC, in address space |
4329 | ASPACE. */ | |
4330 | ||
4331 | static int | |
4332 | bp_location_inserted_here_p (struct bp_location *bl, | |
4333 | struct address_space *aspace, CORE_ADDR pc) | |
4334 | { | |
4335 | if (bl->inserted | |
4336 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4337 | aspace, pc)) | |
4338 | { | |
4339 | if (overlay_debugging | |
4340 | && section_is_overlay (bl->section) | |
4341 | && !section_is_mapped (bl->section)) | |
4342 | return 0; /* unmapped overlay -- can't be a match */ | |
4343 | else | |
4344 | return 1; | |
4345 | } | |
4346 | return 0; | |
4347 | } | |
4348 | ||
a1fd2fa5 | 4349 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4350 | |
4351 | int | |
a1fd2fa5 | 4352 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4353 | { |
f7ce857f PA |
4354 | struct bp_location **blp, **blp_tmp = NULL; |
4355 | struct bp_location *bl; | |
c906108c | 4356 | |
f7ce857f | 4357 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4358 | { |
f7ce857f PA |
4359 | struct bp_location *bl = *blp; |
4360 | ||
35df4500 TJB |
4361 | if (bl->loc_type != bp_loc_software_breakpoint |
4362 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4363 | continue; |
4364 | ||
f7ce857f PA |
4365 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4366 | return 1; | |
c5aa993b | 4367 | } |
c36b740a VP |
4368 | return 0; |
4369 | } | |
4370 | ||
a1fd2fa5 PA |
4371 | /* This function returns non-zero iff there is a software breakpoint |
4372 | inserted at PC. */ | |
c36b740a VP |
4373 | |
4374 | int | |
a1fd2fa5 PA |
4375 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4376 | CORE_ADDR pc) | |
4fa8626c | 4377 | { |
f7ce857f PA |
4378 | struct bp_location **blp, **blp_tmp = NULL; |
4379 | struct bp_location *bl; | |
4fa8626c | 4380 | |
f7ce857f | 4381 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4382 | { |
f7ce857f PA |
4383 | struct bp_location *bl = *blp; |
4384 | ||
35df4500 | 4385 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4386 | continue; |
4387 | ||
f7ce857f PA |
4388 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4389 | return 1; | |
4fa8626c DJ |
4390 | } |
4391 | ||
4392 | return 0; | |
9c02b525 PA |
4393 | } |
4394 | ||
4395 | /* See breakpoint.h. */ | |
4396 | ||
4397 | int | |
4398 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4399 | CORE_ADDR pc) | |
4400 | { | |
4401 | struct bp_location **blp, **blp_tmp = NULL; | |
4402 | struct bp_location *bl; | |
4403 | ||
4404 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4405 | { | |
4406 | struct bp_location *bl = *blp; | |
4407 | ||
4408 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4409 | continue; | |
4410 | ||
4411 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4412 | return 1; | |
4413 | } | |
4414 | ||
4415 | return 0; | |
4fa8626c DJ |
4416 | } |
4417 | ||
9093389c PA |
4418 | int |
4419 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4420 | CORE_ADDR addr, ULONGEST len) | |
4421 | { | |
4422 | struct breakpoint *bpt; | |
4423 | ||
4424 | ALL_BREAKPOINTS (bpt) | |
4425 | { | |
4426 | struct bp_location *loc; | |
4427 | ||
4428 | if (bpt->type != bp_hardware_watchpoint | |
4429 | && bpt->type != bp_access_watchpoint) | |
4430 | continue; | |
4431 | ||
4432 | if (!breakpoint_enabled (bpt)) | |
4433 | continue; | |
4434 | ||
4435 | for (loc = bpt->loc; loc; loc = loc->next) | |
4436 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4437 | { | |
4438 | CORE_ADDR l, h; | |
4439 | ||
4440 | /* Check for intersection. */ | |
4441 | l = max (loc->address, addr); | |
4442 | h = min (loc->address + loc->length, addr + len); | |
4443 | if (l < h) | |
4444 | return 1; | |
4445 | } | |
4446 | } | |
4447 | return 0; | |
4448 | } | |
c906108c | 4449 | \f |
c5aa993b | 4450 | |
c906108c SS |
4451 | /* bpstat stuff. External routines' interfaces are documented |
4452 | in breakpoint.h. */ | |
4453 | ||
4454 | int | |
c326b90e | 4455 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4456 | { |
533be4dd | 4457 | return (ep->type == bp_catchpoint); |
c906108c SS |
4458 | } |
4459 | ||
f431efe5 PA |
4460 | /* Frees any storage that is part of a bpstat. Does not walk the |
4461 | 'next' chain. */ | |
4462 | ||
4463 | static void | |
198757a8 VP |
4464 | bpstat_free (bpstat bs) |
4465 | { | |
4466 | if (bs->old_val != NULL) | |
4467 | value_free (bs->old_val); | |
9add0f1b | 4468 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4469 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4470 | xfree (bs); |
4471 | } | |
4472 | ||
c906108c SS |
4473 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4474 | Also free any storage that is part of a bpstat. */ | |
4475 | ||
4476 | void | |
fba45db2 | 4477 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4478 | { |
4479 | bpstat p; | |
4480 | bpstat q; | |
4481 | ||
4482 | if (bsp == 0) | |
4483 | return; | |
4484 | p = *bsp; | |
4485 | while (p != NULL) | |
4486 | { | |
4487 | q = p->next; | |
198757a8 | 4488 | bpstat_free (p); |
c906108c SS |
4489 | p = q; |
4490 | } | |
4491 | *bsp = NULL; | |
4492 | } | |
4493 | ||
4494 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4495 | is part of the bpstat is copied as well. */ | |
4496 | ||
4497 | bpstat | |
fba45db2 | 4498 | bpstat_copy (bpstat bs) |
c906108c SS |
4499 | { |
4500 | bpstat p = NULL; | |
4501 | bpstat tmp; | |
4502 | bpstat retval = NULL; | |
4503 | ||
4504 | if (bs == NULL) | |
4505 | return bs; | |
4506 | ||
4507 | for (; bs != NULL; bs = bs->next) | |
4508 | { | |
4509 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4510 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4511 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4512 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4513 | if (bs->old_val != NULL) |
3c3185ac JK |
4514 | { |
4515 | tmp->old_val = value_copy (bs->old_val); | |
4516 | release_value (tmp->old_val); | |
4517 | } | |
31cc81e9 | 4518 | |
c906108c SS |
4519 | if (p == NULL) |
4520 | /* This is the first thing in the chain. */ | |
4521 | retval = tmp; | |
4522 | else | |
4523 | p->next = tmp; | |
4524 | p = tmp; | |
4525 | } | |
4526 | p->next = NULL; | |
4527 | return retval; | |
4528 | } | |
4529 | ||
4a64f543 | 4530 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4531 | |
4532 | bpstat | |
fba45db2 | 4533 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4534 | { |
c5aa993b JM |
4535 | if (bsp == NULL) |
4536 | return NULL; | |
c906108c | 4537 | |
c5aa993b JM |
4538 | for (; bsp != NULL; bsp = bsp->next) |
4539 | { | |
f431efe5 | 4540 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4541 | return bsp; |
4542 | } | |
c906108c SS |
4543 | return NULL; |
4544 | } | |
4545 | ||
ab04a2af TT |
4546 | /* See breakpoint.h. */ |
4547 | ||
47591c29 | 4548 | int |
427cd150 | 4549 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4550 | { |
ab04a2af TT |
4551 | for (; bsp != NULL; bsp = bsp->next) |
4552 | { | |
427cd150 TT |
4553 | if (bsp->breakpoint_at == NULL) |
4554 | { | |
4555 | /* A moribund location can never explain a signal other than | |
4556 | GDB_SIGNAL_TRAP. */ | |
4557 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4558 | return 1; |
427cd150 TT |
4559 | } |
4560 | else | |
47591c29 PA |
4561 | { |
4562 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4563 | sig)) | |
4564 | return 1; | |
4565 | } | |
ab04a2af TT |
4566 | } |
4567 | ||
47591c29 | 4568 | return 0; |
ab04a2af TT |
4569 | } |
4570 | ||
4a64f543 MS |
4571 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4572 | stopped at. *BSP upon return is a bpstat which points to the | |
4573 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4574 | good for anything but further calls to bpstat_num). | |
4575 | ||
8671a17b PA |
4576 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4577 | Return -1 if stopped at a breakpoint that has been deleted since | |
4578 | we set it. | |
4579 | Return 1 otherwise. */ | |
c906108c SS |
4580 | |
4581 | int | |
8671a17b | 4582 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4583 | { |
4584 | struct breakpoint *b; | |
4585 | ||
4586 | if ((*bsp) == NULL) | |
4587 | return 0; /* No more breakpoint values */ | |
8671a17b | 4588 | |
4a64f543 MS |
4589 | /* We assume we'll never have several bpstats that correspond to a |
4590 | single breakpoint -- otherwise, this function might return the | |
4591 | same number more than once and this will look ugly. */ | |
f431efe5 | 4592 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4593 | *bsp = (*bsp)->next; |
4594 | if (b == NULL) | |
4595 | return -1; /* breakpoint that's been deleted since */ | |
4596 | ||
4597 | *num = b->number; /* We have its number */ | |
4598 | return 1; | |
c906108c SS |
4599 | } |
4600 | ||
e93ca019 | 4601 | /* See breakpoint.h. */ |
c906108c SS |
4602 | |
4603 | void | |
e93ca019 | 4604 | bpstat_clear_actions (void) |
c906108c | 4605 | { |
e93ca019 JK |
4606 | struct thread_info *tp; |
4607 | bpstat bs; | |
4608 | ||
4609 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4610 | return; | |
4611 | ||
4612 | tp = find_thread_ptid (inferior_ptid); | |
4613 | if (tp == NULL) | |
4614 | return; | |
4615 | ||
4616 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4617 | { |
9add0f1b | 4618 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4619 | |
c906108c SS |
4620 | if (bs->old_val != NULL) |
4621 | { | |
4622 | value_free (bs->old_val); | |
4623 | bs->old_val = NULL; | |
4624 | } | |
4625 | } | |
4626 | } | |
4627 | ||
f3b1572e PA |
4628 | /* Called when a command is about to proceed the inferior. */ |
4629 | ||
4630 | static void | |
4631 | breakpoint_about_to_proceed (void) | |
4632 | { | |
4633 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4634 | { | |
4635 | struct thread_info *tp = inferior_thread (); | |
4636 | ||
4637 | /* Allow inferior function calls in breakpoint commands to not | |
4638 | interrupt the command list. When the call finishes | |
4639 | successfully, the inferior will be standing at the same | |
4640 | breakpoint as if nothing happened. */ | |
16c381f0 | 4641 | if (tp->control.in_infcall) |
f3b1572e PA |
4642 | return; |
4643 | } | |
4644 | ||
4645 | breakpoint_proceeded = 1; | |
4646 | } | |
4647 | ||
4a64f543 MS |
4648 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4649 | command. */ | |
c906108c | 4650 | static void |
4efb68b1 | 4651 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4652 | { |
4653 | executing_breakpoint_commands = 0; | |
4654 | } | |
4655 | ||
abf85f46 JK |
4656 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4657 | or its equivalent. */ | |
4658 | ||
4659 | static int | |
4660 | command_line_is_silent (struct command_line *cmd) | |
4661 | { | |
4f45d445 | 4662 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4663 | } |
4664 | ||
4a64f543 MS |
4665 | /* Execute all the commands associated with all the breakpoints at |
4666 | this location. Any of these commands could cause the process to | |
4667 | proceed beyond this point, etc. We look out for such changes by | |
4668 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4669 | |
347bddb7 PA |
4670 | Returns true if a breakpoint command resumed the inferior. In that |
4671 | case, it is the caller's responsibility to recall it again with the | |
4672 | bpstat of the current thread. */ | |
4673 | ||
4674 | static int | |
4675 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4676 | { |
4677 | bpstat bs; | |
4678 | struct cleanup *old_chain; | |
347bddb7 | 4679 | int again = 0; |
c906108c SS |
4680 | |
4681 | /* Avoid endless recursion if a `source' command is contained | |
4682 | in bs->commands. */ | |
4683 | if (executing_breakpoint_commands) | |
347bddb7 | 4684 | return 0; |
c906108c SS |
4685 | |
4686 | executing_breakpoint_commands = 1; | |
4687 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4688 | ||
cf6c5ffb TT |
4689 | prevent_dont_repeat (); |
4690 | ||
4a64f543 | 4691 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4692 | bs = *bsp; |
4693 | ||
4694 | breakpoint_proceeded = 0; | |
4695 | for (; bs != NULL; bs = bs->next) | |
4696 | { | |
9add0f1b | 4697 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4698 | struct command_line *cmd; |
4699 | struct cleanup *this_cmd_tree_chain; | |
4700 | ||
4701 | /* Take ownership of the BSP's command tree, if it has one. | |
4702 | ||
4703 | The command tree could legitimately contain commands like | |
4704 | 'step' and 'next', which call clear_proceed_status, which | |
4705 | frees stop_bpstat's command tree. To make sure this doesn't | |
4706 | free the tree we're executing out from under us, we need to | |
4707 | take ownership of the tree ourselves. Since a given bpstat's | |
4708 | commands are only executed once, we don't need to copy it; we | |
4709 | can clear the pointer in the bpstat, and make sure we free | |
4710 | the tree when we're done. */ | |
9add0f1b TT |
4711 | ccmd = bs->commands; |
4712 | bs->commands = NULL; | |
abf85f46 JK |
4713 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4714 | cmd = ccmd ? ccmd->commands : NULL; | |
4715 | if (command_line_is_silent (cmd)) | |
4716 | { | |
4717 | /* The action has been already done by bpstat_stop_status. */ | |
4718 | cmd = cmd->next; | |
4719 | } | |
6c50ab1c | 4720 | |
c906108c SS |
4721 | while (cmd != NULL) |
4722 | { | |
4723 | execute_control_command (cmd); | |
4724 | ||
4725 | if (breakpoint_proceeded) | |
4726 | break; | |
4727 | else | |
4728 | cmd = cmd->next; | |
4729 | } | |
6c50ab1c JB |
4730 | |
4731 | /* We can free this command tree now. */ | |
4732 | do_cleanups (this_cmd_tree_chain); | |
4733 | ||
c906108c | 4734 | if (breakpoint_proceeded) |
32c1e744 | 4735 | { |
0b333c5e | 4736 | if (interpreter_async) |
347bddb7 PA |
4737 | /* If we are in async mode, then the target might be still |
4738 | running, not stopped at any breakpoint, so nothing for | |
4739 | us to do here -- just return to the event loop. */ | |
4740 | ; | |
32c1e744 VP |
4741 | else |
4742 | /* In sync mode, when execute_control_command returns | |
4743 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4744 | Breakpoint commands for that stop were not run, since |
4745 | execute_command does not run breakpoint commands -- | |
4746 | only command_line_handler does, but that one is not | |
4747 | involved in execution of breakpoint commands. So, we | |
4748 | can now execute breakpoint commands. It should be | |
4749 | noted that making execute_command do bpstat actions is | |
4750 | not an option -- in this case we'll have recursive | |
4751 | invocation of bpstat for each breakpoint with a | |
4752 | command, and can easily blow up GDB stack. Instead, we | |
4753 | return true, which will trigger the caller to recall us | |
4754 | with the new stop_bpstat. */ | |
4755 | again = 1; | |
4756 | break; | |
32c1e744 | 4757 | } |
c906108c | 4758 | } |
c2b8ed2c | 4759 | do_cleanups (old_chain); |
347bddb7 PA |
4760 | return again; |
4761 | } | |
4762 | ||
4763 | void | |
4764 | bpstat_do_actions (void) | |
4765 | { | |
353d1d73 JK |
4766 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4767 | ||
347bddb7 PA |
4768 | /* Do any commands attached to breakpoint we are stopped at. */ |
4769 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4770 | && target_has_execution | |
4771 | && !is_exited (inferior_ptid) | |
4772 | && !is_executing (inferior_ptid)) | |
4773 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4774 | and only return when it is stopped at the next breakpoint, we | |
4775 | keep doing breakpoint actions until it returns false to | |
4776 | indicate the inferior was not resumed. */ | |
16c381f0 | 4777 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4778 | break; |
353d1d73 JK |
4779 | |
4780 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4781 | } |
4782 | ||
fa4727a6 DJ |
4783 | /* Print out the (old or new) value associated with a watchpoint. */ |
4784 | ||
4785 | static void | |
4786 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4787 | { | |
4788 | if (val == NULL) | |
4789 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4790 | else | |
79a45b7d TT |
4791 | { |
4792 | struct value_print_options opts; | |
4793 | get_user_print_options (&opts); | |
4794 | value_print (val, stream, &opts); | |
4795 | } | |
fa4727a6 DJ |
4796 | } |
4797 | ||
f303dbd6 PA |
4798 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4799 | debugging multiple threads. */ | |
4800 | ||
4801 | void | |
4802 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4803 | { | |
4804 | if (ui_out_is_mi_like_p (uiout)) | |
4805 | return; | |
4806 | ||
4807 | ui_out_text (uiout, "\n"); | |
4808 | ||
4809 | if (show_thread_that_caused_stop ()) | |
4810 | { | |
4811 | const char *name; | |
4812 | struct thread_info *thr = inferior_thread (); | |
4813 | ||
4814 | ui_out_text (uiout, "Thread "); | |
4815 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4816 | ||
4817 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4818 | if (name != NULL) | |
4819 | { | |
4820 | ui_out_text (uiout, " \""); | |
4821 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4822 | ui_out_text (uiout, "\""); | |
4823 | } | |
4824 | ||
4825 | ui_out_text (uiout, " hit "); | |
4826 | } | |
4827 | } | |
4828 | ||
e514a9d6 | 4829 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4830 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4831 | 'print_it' in the bpstat structure. Under some circumstances we |
4832 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4833 | normal_stop(). */ |
e514a9d6 JM |
4834 | |
4835 | static enum print_stop_action | |
4836 | print_bp_stop_message (bpstat bs) | |
4837 | { | |
4838 | switch (bs->print_it) | |
4839 | { | |
4840 | case print_it_noop: | |
4a64f543 | 4841 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4842 | return PRINT_UNKNOWN; |
4843 | break; | |
4844 | ||
4845 | case print_it_done: | |
4846 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4847 | relevant messages. */ |
e514a9d6 JM |
4848 | return PRINT_SRC_AND_LOC; |
4849 | break; | |
4850 | ||
4851 | case print_it_normal: | |
4f8d1dc6 | 4852 | { |
f431efe5 PA |
4853 | struct breakpoint *b = bs->breakpoint_at; |
4854 | ||
1a6a67de TJB |
4855 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4856 | which has since been deleted. */ | |
4857 | if (b == NULL) | |
4858 | return PRINT_UNKNOWN; | |
4859 | ||
348d480f PA |
4860 | /* Normal case. Call the breakpoint's print_it method. */ |
4861 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4862 | } |
348d480f | 4863 | break; |
3086aeae | 4864 | |
e514a9d6 | 4865 | default: |
8e65ff28 | 4866 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4867 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4868 | break; |
c906108c | 4869 | } |
c906108c SS |
4870 | } |
4871 | ||
edcc5120 TT |
4872 | /* A helper function that prints a shared library stopped event. */ |
4873 | ||
4874 | static void | |
4875 | print_solib_event (int is_catchpoint) | |
4876 | { | |
4877 | int any_deleted | |
4878 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4879 | int any_added | |
4880 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4881 | ||
4882 | if (!is_catchpoint) | |
4883 | { | |
4884 | if (any_added || any_deleted) | |
4885 | ui_out_text (current_uiout, | |
4886 | _("Stopped due to shared library event:\n")); | |
4887 | else | |
4888 | ui_out_text (current_uiout, | |
4889 | _("Stopped due to shared library event (no " | |
4890 | "libraries added or removed)\n")); | |
4891 | } | |
4892 | ||
4893 | if (ui_out_is_mi_like_p (current_uiout)) | |
4894 | ui_out_field_string (current_uiout, "reason", | |
4895 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4896 | ||
4897 | if (any_deleted) | |
4898 | { | |
4899 | struct cleanup *cleanup; | |
4900 | char *name; | |
4901 | int ix; | |
4902 | ||
4903 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4904 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4905 | "removed"); | |
4906 | for (ix = 0; | |
4907 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4908 | ix, name); | |
4909 | ++ix) | |
4910 | { | |
4911 | if (ix > 0) | |
4912 | ui_out_text (current_uiout, " "); | |
4913 | ui_out_field_string (current_uiout, "library", name); | |
4914 | ui_out_text (current_uiout, "\n"); | |
4915 | } | |
4916 | ||
4917 | do_cleanups (cleanup); | |
4918 | } | |
4919 | ||
4920 | if (any_added) | |
4921 | { | |
4922 | struct so_list *iter; | |
4923 | int ix; | |
4924 | struct cleanup *cleanup; | |
4925 | ||
4926 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4927 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4928 | "added"); | |
4929 | for (ix = 0; | |
4930 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4931 | ix, iter); | |
4932 | ++ix) | |
4933 | { | |
4934 | if (ix > 0) | |
4935 | ui_out_text (current_uiout, " "); | |
4936 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4937 | ui_out_text (current_uiout, "\n"); | |
4938 | } | |
4939 | ||
4940 | do_cleanups (cleanup); | |
4941 | } | |
4942 | } | |
4943 | ||
e514a9d6 JM |
4944 | /* Print a message indicating what happened. This is called from |
4945 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4946 | list - a list of the eventpoints that caused this stop. KIND is |
4947 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4948 | routine calls the generic print routine for printing a message |
4949 | about reasons for stopping. This will print (for example) the | |
4950 | "Breakpoint n," part of the output. The return value of this | |
4951 | routine is one of: | |
c906108c | 4952 | |
4a64f543 | 4953 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4954 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4955 | code to print the location. An example is |
c5aa993b JM |
4956 | "Breakpoint 1, " which should be followed by |
4957 | the location. | |
917317f4 | 4958 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4959 | to also print the location part of the message. |
4960 | An example is the catch/throw messages, which | |
4a64f543 | 4961 | don't require a location appended to the end. |
917317f4 | 4962 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4963 | further info to be printed. */ |
c906108c | 4964 | |
917317f4 | 4965 | enum print_stop_action |
36dfb11c | 4966 | bpstat_print (bpstat bs, int kind) |
c906108c | 4967 | { |
f486487f | 4968 | enum print_stop_action val; |
c5aa993b | 4969 | |
c906108c | 4970 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4971 | (Currently all watchpoints go on the bpstat whether hit or not. |
4972 | That probably could (should) be changed, provided care is taken | |
c906108c | 4973 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4974 | for (; bs; bs = bs->next) |
4975 | { | |
4976 | val = print_bp_stop_message (bs); | |
4977 | if (val == PRINT_SRC_ONLY | |
4978 | || val == PRINT_SRC_AND_LOC | |
4979 | || val == PRINT_NOTHING) | |
4980 | return val; | |
4981 | } | |
c906108c | 4982 | |
36dfb11c TT |
4983 | /* If we had hit a shared library event breakpoint, |
4984 | print_bp_stop_message would print out this message. If we hit an | |
4985 | OS-level shared library event, do the same thing. */ | |
4986 | if (kind == TARGET_WAITKIND_LOADED) | |
4987 | { | |
edcc5120 | 4988 | print_solib_event (0); |
36dfb11c TT |
4989 | return PRINT_NOTHING; |
4990 | } | |
4991 | ||
e514a9d6 | 4992 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4993 | with and nothing was printed. */ |
917317f4 | 4994 | return PRINT_UNKNOWN; |
c906108c SS |
4995 | } |
4996 | ||
c42bd95a DE |
4997 | /* Evaluate the expression EXP and return 1 if value is zero. |
4998 | This returns the inverse of the condition because it is called | |
4999 | from catch_errors which returns 0 if an exception happened, and if an | |
5000 | exception happens we want execution to stop. | |
4a64f543 | 5001 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5002 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5003 | |
5004 | static int | |
4efb68b1 | 5005 | breakpoint_cond_eval (void *exp) |
c906108c | 5006 | { |
278cd55f | 5007 | struct value *mark = value_mark (); |
c5aa993b | 5008 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5009 | |
c906108c SS |
5010 | value_free_to_mark (mark); |
5011 | return i; | |
5012 | } | |
5013 | ||
5760d0ab | 5014 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5015 | |
5016 | static bpstat | |
5760d0ab | 5017 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5018 | { |
5019 | bpstat bs; | |
5020 | ||
5021 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5022 | bs->next = NULL; |
5023 | **bs_link_pointer = bs; | |
5024 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5025 | bs->breakpoint_at = bl->owner; |
5026 | bs->bp_location_at = bl; | |
5027 | incref_bp_location (bl); | |
c906108c SS |
5028 | /* If the condition is false, etc., don't do the commands. */ |
5029 | bs->commands = NULL; | |
5030 | bs->old_val = NULL; | |
5031 | bs->print_it = print_it_normal; | |
5032 | return bs; | |
5033 | } | |
5034 | \f | |
d983da9c DJ |
5035 | /* The target has stopped with waitstatus WS. Check if any hardware |
5036 | watchpoints have triggered, according to the target. */ | |
5037 | ||
5038 | int | |
5039 | watchpoints_triggered (struct target_waitstatus *ws) | |
5040 | { | |
d92524f1 | 5041 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5042 | CORE_ADDR addr; |
5043 | struct breakpoint *b; | |
5044 | ||
5045 | if (!stopped_by_watchpoint) | |
5046 | { | |
5047 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5048 | as not triggered. */ | |
5049 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5050 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5051 | { |
5052 | struct watchpoint *w = (struct watchpoint *) b; | |
5053 | ||
5054 | w->watchpoint_triggered = watch_triggered_no; | |
5055 | } | |
d983da9c DJ |
5056 | |
5057 | return 0; | |
5058 | } | |
5059 | ||
5060 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5061 | { | |
5062 | /* We were stopped by a watchpoint, but we don't know where. | |
5063 | Mark all watchpoints as unknown. */ | |
5064 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5065 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5066 | { |
5067 | struct watchpoint *w = (struct watchpoint *) b; | |
5068 | ||
5069 | w->watchpoint_triggered = watch_triggered_unknown; | |
5070 | } | |
d983da9c | 5071 | |
3c4797ba | 5072 | return 1; |
d983da9c DJ |
5073 | } |
5074 | ||
5075 | /* The target could report the data address. Mark watchpoints | |
5076 | affected by this data address as triggered, and all others as not | |
5077 | triggered. */ | |
5078 | ||
5079 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5080 | if (is_hardware_watchpoint (b)) |
d983da9c | 5081 | { |
3a5c3e22 | 5082 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5083 | struct bp_location *loc; |
d983da9c | 5084 | |
3a5c3e22 | 5085 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5086 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5087 | { |
3a5c3e22 | 5088 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5089 | { |
3a5c3e22 PA |
5090 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5091 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5092 | |
5093 | if (newaddr == start) | |
5094 | { | |
3a5c3e22 | 5095 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5096 | break; |
5097 | } | |
5098 | } | |
5099 | /* Exact match not required. Within range is sufficient. */ | |
5100 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5101 | addr, loc->address, | |
5102 | loc->length)) | |
5103 | { | |
3a5c3e22 | 5104 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5105 | break; |
5106 | } | |
5107 | } | |
d983da9c DJ |
5108 | } |
5109 | ||
5110 | return 1; | |
5111 | } | |
5112 | ||
c906108c SS |
5113 | /* Possible return values for watchpoint_check (this can't be an enum |
5114 | because of check_errors). */ | |
5115 | /* The watchpoint has been deleted. */ | |
5116 | #define WP_DELETED 1 | |
5117 | /* The value has changed. */ | |
5118 | #define WP_VALUE_CHANGED 2 | |
5119 | /* The value has not changed. */ | |
5120 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5121 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5122 | #define WP_IGNORE 4 | |
c906108c SS |
5123 | |
5124 | #define BP_TEMPFLAG 1 | |
5125 | #define BP_HARDWAREFLAG 2 | |
5126 | ||
4a64f543 MS |
5127 | /* Evaluate watchpoint condition expression and check if its value |
5128 | changed. | |
553e4c11 JB |
5129 | |
5130 | P should be a pointer to struct bpstat, but is defined as a void * | |
5131 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5132 | |
5133 | static int | |
4efb68b1 | 5134 | watchpoint_check (void *p) |
c906108c SS |
5135 | { |
5136 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5137 | struct watchpoint *b; |
c906108c SS |
5138 | struct frame_info *fr; |
5139 | int within_current_scope; | |
5140 | ||
f431efe5 | 5141 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5142 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5143 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5144 | |
f6bc2008 PA |
5145 | /* If this is a local watchpoint, we only want to check if the |
5146 | watchpoint frame is in scope if the current thread is the thread | |
5147 | that was used to create the watchpoint. */ | |
5148 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5149 | return WP_IGNORE; |
f6bc2008 | 5150 | |
c906108c SS |
5151 | if (b->exp_valid_block == NULL) |
5152 | within_current_scope = 1; | |
5153 | else | |
5154 | { | |
edb3359d DJ |
5155 | struct frame_info *frame = get_current_frame (); |
5156 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5157 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5158 | ||
c9cf6e20 | 5159 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5160 | still in the function but the stack frame has already been |
5161 | invalidated. Since we can't rely on the values of local | |
5162 | variables after the stack has been destroyed, we are treating | |
5163 | the watchpoint in that state as `not changed' without further | |
5164 | checking. Don't mark watchpoints as changed if the current | |
5165 | frame is in an epilogue - even if they are in some other | |
5166 | frame, our view of the stack is likely to be wrong and | |
5167 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5168 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5169 | return WP_IGNORE; |
a0f49112 | 5170 | |
101dcfbe | 5171 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5172 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5173 | |
5174 | /* If we've gotten confused in the unwinder, we might have | |
5175 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5176 | if (within_current_scope) |
5177 | { | |
5178 | struct symbol *function; | |
5179 | ||
5180 | function = get_frame_function (fr); | |
5181 | if (function == NULL | |
5182 | || !contained_in (b->exp_valid_block, | |
5183 | SYMBOL_BLOCK_VALUE (function))) | |
5184 | within_current_scope = 0; | |
5185 | } | |
69fbadd5 | 5186 | |
edb3359d | 5187 | if (within_current_scope) |
c906108c SS |
5188 | /* If we end up stopping, the current frame will get selected |
5189 | in normal_stop. So this call to select_frame won't affect | |
5190 | the user. */ | |
0f7d239c | 5191 | select_frame (fr); |
c906108c | 5192 | } |
c5aa993b | 5193 | |
c906108c SS |
5194 | if (within_current_scope) |
5195 | { | |
4a64f543 MS |
5196 | /* We use value_{,free_to_}mark because it could be a *long* |
5197 | time before we return to the command level and call | |
5198 | free_all_values. We can't call free_all_values because we | |
5199 | might be in the middle of evaluating a function call. */ | |
c906108c | 5200 | |
0cf6dd15 | 5201 | int pc = 0; |
9c06b0b4 | 5202 | struct value *mark; |
fa4727a6 DJ |
5203 | struct value *new_val; |
5204 | ||
3a5c3e22 | 5205 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5206 | /* Since we don't know the exact trigger address (from |
5207 | stopped_data_address), just tell the user we've triggered | |
5208 | a mask watchpoint. */ | |
5209 | return WP_VALUE_CHANGED; | |
5210 | ||
5211 | mark = value_mark (); | |
3a1115a0 | 5212 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5213 | |
bb9d5f81 PP |
5214 | if (b->val_bitsize != 0) |
5215 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5216 | ||
4a64f543 MS |
5217 | /* We use value_equal_contents instead of value_equal because |
5218 | the latter coerces an array to a pointer, thus comparing just | |
5219 | the address of the array instead of its contents. This is | |
5220 | not what we want. */ | |
fa4727a6 | 5221 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5222 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5223 | { |
fa4727a6 DJ |
5224 | if (new_val != NULL) |
5225 | { | |
5226 | release_value (new_val); | |
5227 | value_free_to_mark (mark); | |
5228 | } | |
c906108c SS |
5229 | bs->old_val = b->val; |
5230 | b->val = new_val; | |
fa4727a6 | 5231 | b->val_valid = 1; |
c906108c SS |
5232 | return WP_VALUE_CHANGED; |
5233 | } | |
5234 | else | |
5235 | { | |
60e1c644 | 5236 | /* Nothing changed. */ |
c906108c | 5237 | value_free_to_mark (mark); |
c906108c SS |
5238 | return WP_VALUE_NOT_CHANGED; |
5239 | } | |
5240 | } | |
5241 | else | |
5242 | { | |
79a45e25 PA |
5243 | struct ui_out *uiout = current_uiout; |
5244 | ||
c906108c | 5245 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5246 | if we temporarily ignored the watchpoint, then when |
5247 | we reenter the block in which it is valid it contains | |
5248 | garbage (in the case of a function, it may have two | |
5249 | garbage values, one before and one after the prologue). | |
5250 | So we can't even detect the first assignment to it and | |
5251 | watch after that (since the garbage may or may not equal | |
5252 | the first value assigned). */ | |
348d480f PA |
5253 | /* We print all the stop information in |
5254 | breakpoint_ops->print_it, but in this case, by the time we | |
5255 | call breakpoint_ops->print_it this bp will be deleted | |
5256 | already. So we have no choice but print the information | |
5257 | here. */ | |
9dc5e2a9 | 5258 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5259 | ui_out_field_string |
5260 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5261 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5262 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5263 | ui_out_text (uiout, |
5264 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5265 | which its expression is valid.\n"); |
4ce44c66 | 5266 | |
cdac0397 | 5267 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5268 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5269 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5270 | |
5271 | return WP_DELETED; | |
5272 | } | |
5273 | } | |
5274 | ||
18a18393 | 5275 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5276 | breakpoint location BL. This function does not check if we should |
5277 | stop, only if BL explains the stop. */ | |
5278 | ||
18a18393 | 5279 | static int |
6c95b8df | 5280 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5281 | struct address_space *aspace, CORE_ADDR bp_addr, |
5282 | const struct target_waitstatus *ws) | |
18a18393 VP |
5283 | { |
5284 | struct breakpoint *b = bl->owner; | |
5285 | ||
348d480f | 5286 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5287 | gdb_assert (b != NULL); |
5288 | ||
09ac7c10 | 5289 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5290 | } |
5291 | ||
3a5c3e22 PA |
5292 | /* Determine if the watched values have actually changed, and we |
5293 | should stop. If not, set BS->stop to 0. */ | |
5294 | ||
18a18393 VP |
5295 | static void |
5296 | bpstat_check_watchpoint (bpstat bs) | |
5297 | { | |
2bdf28a0 | 5298 | const struct bp_location *bl; |
3a5c3e22 | 5299 | struct watchpoint *b; |
2bdf28a0 JK |
5300 | |
5301 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5302 | bl = bs->bp_location_at; |
2bdf28a0 | 5303 | gdb_assert (bl != NULL); |
3a5c3e22 | 5304 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5305 | gdb_assert (b != NULL); |
18a18393 | 5306 | |
18a18393 | 5307 | { |
18a18393 VP |
5308 | int must_check_value = 0; |
5309 | ||
3a5c3e22 | 5310 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5311 | /* For a software watchpoint, we must always check the |
5312 | watched value. */ | |
5313 | must_check_value = 1; | |
5314 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5315 | /* We have a hardware watchpoint (read, write, or access) | |
5316 | and the target earlier reported an address watched by | |
5317 | this watchpoint. */ | |
5318 | must_check_value = 1; | |
5319 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5320 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5321 | /* We were stopped by a hardware watchpoint, but the target could |
5322 | not report the data address. We must check the watchpoint's | |
5323 | value. Access and read watchpoints are out of luck; without | |
5324 | a data address, we can't figure it out. */ | |
5325 | must_check_value = 1; | |
3a5c3e22 | 5326 | |
18a18393 VP |
5327 | if (must_check_value) |
5328 | { | |
3e43a32a MS |
5329 | char *message |
5330 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5331 | b->base.number); |
18a18393 VP |
5332 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5333 | int e = catch_errors (watchpoint_check, bs, message, | |
5334 | RETURN_MASK_ALL); | |
5335 | do_cleanups (cleanups); | |
5336 | switch (e) | |
5337 | { | |
5338 | case WP_DELETED: | |
5339 | /* We've already printed what needs to be printed. */ | |
5340 | bs->print_it = print_it_done; | |
5341 | /* Stop. */ | |
5342 | break; | |
60e1c644 PA |
5343 | case WP_IGNORE: |
5344 | bs->print_it = print_it_noop; | |
5345 | bs->stop = 0; | |
5346 | break; | |
18a18393 | 5347 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5348 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5349 | { |
85d721b8 PA |
5350 | /* There are two cases to consider here: |
5351 | ||
4a64f543 | 5352 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5353 | In that case, trust the target, and always report |
5354 | the watchpoint hit to the user. Even though | |
5355 | reads don't cause value changes, the value may | |
5356 | have changed since the last time it was read, and | |
5357 | since we're not trapping writes, we will not see | |
5358 | those, and as such we should ignore our notion of | |
5359 | old value. | |
5360 | ||
4a64f543 | 5361 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5362 | reads and writes. There are two ways this may |
5363 | happen: | |
5364 | ||
4a64f543 | 5365 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5366 | reads only, but can break on accesses (reads or |
5367 | writes), such as e.g., x86. We detect this case | |
5368 | at the time we try to insert read watchpoints. | |
5369 | ||
4a64f543 | 5370 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5371 | watchpoints, but, the user set an access or write |
5372 | watchpoint watching the same memory as this read | |
5373 | watchpoint. | |
5374 | ||
5375 | If we're watching memory writes as well as reads, | |
5376 | ignore watchpoint hits when we find that the | |
5377 | value hasn't changed, as reads don't cause | |
5378 | changes. This still gives false positives when | |
5379 | the program writes the same value to memory as | |
5380 | what there was already in memory (we will confuse | |
5381 | it for a read), but it's much better than | |
5382 | nothing. */ | |
5383 | ||
5384 | int other_write_watchpoint = 0; | |
5385 | ||
5386 | if (bl->watchpoint_type == hw_read) | |
5387 | { | |
5388 | struct breakpoint *other_b; | |
5389 | ||
5390 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5391 | if (other_b->type == bp_hardware_watchpoint |
5392 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5393 | { |
3a5c3e22 PA |
5394 | struct watchpoint *other_w = |
5395 | (struct watchpoint *) other_b; | |
5396 | ||
5397 | if (other_w->watchpoint_triggered | |
5398 | == watch_triggered_yes) | |
5399 | { | |
5400 | other_write_watchpoint = 1; | |
5401 | break; | |
5402 | } | |
85d721b8 PA |
5403 | } |
5404 | } | |
5405 | ||
5406 | if (other_write_watchpoint | |
5407 | || bl->watchpoint_type == hw_access) | |
5408 | { | |
5409 | /* We're watching the same memory for writes, | |
5410 | and the value changed since the last time we | |
5411 | updated it, so this trap must be for a write. | |
5412 | Ignore it. */ | |
5413 | bs->print_it = print_it_noop; | |
5414 | bs->stop = 0; | |
5415 | } | |
18a18393 VP |
5416 | } |
5417 | break; | |
5418 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5419 | if (b->base.type == bp_hardware_watchpoint |
5420 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5421 | { |
5422 | /* Don't stop: write watchpoints shouldn't fire if | |
5423 | the value hasn't changed. */ | |
5424 | bs->print_it = print_it_noop; | |
5425 | bs->stop = 0; | |
5426 | } | |
5427 | /* Stop. */ | |
5428 | break; | |
5429 | default: | |
5430 | /* Can't happen. */ | |
5431 | case 0: | |
5432 | /* Error from catch_errors. */ | |
3a5c3e22 | 5433 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5434 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5435 | /* We've already printed what needs to be printed. */ |
5436 | bs->print_it = print_it_done; | |
5437 | break; | |
5438 | } | |
5439 | } | |
5440 | else /* must_check_value == 0 */ | |
5441 | { | |
5442 | /* This is a case where some watchpoint(s) triggered, but | |
5443 | not at the address of this watchpoint, or else no | |
5444 | watchpoint triggered after all. So don't print | |
5445 | anything for this watchpoint. */ | |
5446 | bs->print_it = print_it_noop; | |
5447 | bs->stop = 0; | |
5448 | } | |
5449 | } | |
5450 | } | |
5451 | ||
7d4df6a4 DE |
5452 | /* For breakpoints that are currently marked as telling gdb to stop, |
5453 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5454 | of breakpoint referred to by BS. If we should not stop for this |
5455 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5456 | |
18a18393 VP |
5457 | static void |
5458 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5459 | { | |
2bdf28a0 JK |
5460 | const struct bp_location *bl; |
5461 | struct breakpoint *b; | |
7d4df6a4 DE |
5462 | int value_is_zero = 0; |
5463 | struct expression *cond; | |
5464 | ||
5465 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5466 | |
5467 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5468 | bl = bs->bp_location_at; |
2bdf28a0 | 5469 | gdb_assert (bl != NULL); |
f431efe5 | 5470 | b = bs->breakpoint_at; |
2bdf28a0 | 5471 | gdb_assert (b != NULL); |
18a18393 | 5472 | |
b775012e LM |
5473 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5474 | need to do so again since GDB does not know if we stopped due to a | |
5475 | breakpoint or a single step breakpoint. */ | |
5476 | ||
18a18393 | 5477 | if (frame_id_p (b->frame_id) |
edb3359d | 5478 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5479 | { |
7d4df6a4 DE |
5480 | bs->stop = 0; |
5481 | return; | |
5482 | } | |
60e1c644 | 5483 | |
12ab52e9 PA |
5484 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5485 | evaluating the condition if this isn't the specified | |
5486 | thread/task. */ | |
5d5658a1 | 5487 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5488 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5489 | ||
6c1b0f7b DE |
5490 | { |
5491 | bs->stop = 0; | |
5492 | return; | |
5493 | } | |
5494 | ||
6dddc817 DE |
5495 | /* Evaluate extension language breakpoints that have a "stop" method |
5496 | implemented. */ | |
5497 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5498 | |
7d4df6a4 DE |
5499 | if (is_watchpoint (b)) |
5500 | { | |
5501 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5502 | |
7d4df6a4 DE |
5503 | cond = w->cond_exp; |
5504 | } | |
5505 | else | |
5506 | cond = bl->cond; | |
60e1c644 | 5507 | |
7d4df6a4 DE |
5508 | if (cond && b->disposition != disp_del_at_next_stop) |
5509 | { | |
5510 | int within_current_scope = 1; | |
5511 | struct watchpoint * w; | |
60e1c644 | 5512 | |
7d4df6a4 DE |
5513 | /* We use value_mark and value_free_to_mark because it could |
5514 | be a long time before we return to the command level and | |
5515 | call free_all_values. We can't call free_all_values | |
5516 | because we might be in the middle of evaluating a | |
5517 | function call. */ | |
5518 | struct value *mark = value_mark (); | |
5519 | ||
5520 | if (is_watchpoint (b)) | |
5521 | w = (struct watchpoint *) b; | |
5522 | else | |
5523 | w = NULL; | |
5524 | ||
5525 | /* Need to select the frame, with all that implies so that | |
5526 | the conditions will have the right context. Because we | |
5527 | use the frame, we will not see an inlined function's | |
5528 | variables when we arrive at a breakpoint at the start | |
5529 | of the inlined function; the current frame will be the | |
5530 | call site. */ | |
5531 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5532 | select_frame (get_current_frame ()); | |
5533 | else | |
18a18393 | 5534 | { |
7d4df6a4 DE |
5535 | struct frame_info *frame; |
5536 | ||
5537 | /* For local watchpoint expressions, which particular | |
5538 | instance of a local is being watched matters, so we | |
5539 | keep track of the frame to evaluate the expression | |
5540 | in. To evaluate the condition however, it doesn't | |
5541 | really matter which instantiation of the function | |
5542 | where the condition makes sense triggers the | |
5543 | watchpoint. This allows an expression like "watch | |
5544 | global if q > 10" set in `func', catch writes to | |
5545 | global on all threads that call `func', or catch | |
5546 | writes on all recursive calls of `func' by a single | |
5547 | thread. We simply always evaluate the condition in | |
5548 | the innermost frame that's executing where it makes | |
5549 | sense to evaluate the condition. It seems | |
5550 | intuitive. */ | |
5551 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5552 | if (frame != NULL) | |
5553 | select_frame (frame); | |
5554 | else | |
5555 | within_current_scope = 0; | |
18a18393 | 5556 | } |
7d4df6a4 DE |
5557 | if (within_current_scope) |
5558 | value_is_zero | |
5559 | = catch_errors (breakpoint_cond_eval, cond, | |
5560 | "Error in testing breakpoint condition:\n", | |
5561 | RETURN_MASK_ALL); | |
5562 | else | |
18a18393 | 5563 | { |
7d4df6a4 DE |
5564 | warning (_("Watchpoint condition cannot be tested " |
5565 | "in the current scope")); | |
5566 | /* If we failed to set the right context for this | |
5567 | watchpoint, unconditionally report it. */ | |
5568 | value_is_zero = 0; | |
18a18393 | 5569 | } |
7d4df6a4 DE |
5570 | /* FIXME-someday, should give breakpoint #. */ |
5571 | value_free_to_mark (mark); | |
18a18393 | 5572 | } |
7d4df6a4 DE |
5573 | |
5574 | if (cond && value_is_zero) | |
5575 | { | |
5576 | bs->stop = 0; | |
5577 | } | |
7d4df6a4 DE |
5578 | else if (b->ignore_count > 0) |
5579 | { | |
5580 | b->ignore_count--; | |
5581 | bs->stop = 0; | |
5582 | /* Increase the hit count even though we don't stop. */ | |
5583 | ++(b->hit_count); | |
5584 | observer_notify_breakpoint_modified (b); | |
5585 | } | |
18a18393 VP |
5586 | } |
5587 | ||
1cf4d951 PA |
5588 | /* Returns true if we need to track moribund locations of LOC's type |
5589 | on the current target. */ | |
5590 | ||
5591 | static int | |
5592 | need_moribund_for_location_type (struct bp_location *loc) | |
5593 | { | |
5594 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5595 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5596 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5597 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5598 | } | |
5599 | ||
18a18393 | 5600 | |
9709f61c | 5601 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5602 | BP_ADDR in thread PTID. |
c906108c | 5603 | |
d983da9c | 5604 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5605 | don't understand this stop. Result is a chain of bpstat's such |
5606 | that: | |
c906108c | 5607 | |
c5aa993b | 5608 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5609 | |
c5aa993b | 5610 | if we understand why we stopped, the result is not null. |
c906108c | 5611 | |
c5aa993b JM |
5612 | Each element of the chain refers to a particular breakpoint or |
5613 | watchpoint at which we have stopped. (We may have stopped for | |
5614 | several reasons concurrently.) | |
c906108c | 5615 | |
c5aa993b JM |
5616 | Each element of the chain has valid next, breakpoint_at, |
5617 | commands, FIXME??? fields. */ | |
c906108c SS |
5618 | |
5619 | bpstat | |
6c95b8df | 5620 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5621 | CORE_ADDR bp_addr, ptid_t ptid, |
5622 | const struct target_waitstatus *ws) | |
c906108c | 5623 | { |
0d381245 | 5624 | struct breakpoint *b = NULL; |
afe38095 | 5625 | struct bp_location *bl; |
20874c92 | 5626 | struct bp_location *loc; |
5760d0ab JK |
5627 | /* First item of allocated bpstat's. */ |
5628 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5629 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5630 | bpstat bs; |
20874c92 | 5631 | int ix; |
429374b8 | 5632 | int need_remove_insert; |
f431efe5 | 5633 | int removed_any; |
c906108c | 5634 | |
f431efe5 PA |
5635 | /* First, build the bpstat chain with locations that explain a |
5636 | target stop, while being careful to not set the target running, | |
5637 | as that may invalidate locations (in particular watchpoint | |
5638 | locations are recreated). Resuming will happen here with | |
5639 | breakpoint conditions or watchpoint expressions that include | |
5640 | inferior function calls. */ | |
c5aa993b | 5641 | |
429374b8 JK |
5642 | ALL_BREAKPOINTS (b) |
5643 | { | |
1a853c52 | 5644 | if (!breakpoint_enabled (b)) |
429374b8 | 5645 | continue; |
a5606eee | 5646 | |
429374b8 JK |
5647 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5648 | { | |
4a64f543 MS |
5649 | /* For hardware watchpoints, we look only at the first |
5650 | location. The watchpoint_check function will work on the | |
5651 | entire expression, not the individual locations. For | |
5652 | read watchpoints, the watchpoints_triggered function has | |
5653 | checked all locations already. */ | |
429374b8 JK |
5654 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5655 | break; | |
18a18393 | 5656 | |
f6592439 | 5657 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5658 | continue; |
c5aa993b | 5659 | |
09ac7c10 | 5660 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5661 | continue; |
c5aa993b | 5662 | |
4a64f543 MS |
5663 | /* Come here if it's a watchpoint, or if the break address |
5664 | matches. */ | |
c5aa993b | 5665 | |
4a64f543 MS |
5666 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5667 | explain stop. */ | |
c5aa993b | 5668 | |
f431efe5 PA |
5669 | /* Assume we stop. Should we find a watchpoint that is not |
5670 | actually triggered, or if the condition of the breakpoint | |
5671 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5672 | bs->stop = 1; |
5673 | bs->print = 1; | |
d983da9c | 5674 | |
f431efe5 PA |
5675 | /* If this is a scope breakpoint, mark the associated |
5676 | watchpoint as triggered so that we will handle the | |
5677 | out-of-scope event. We'll get to the watchpoint next | |
5678 | iteration. */ | |
d0fb5eae | 5679 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5680 | { |
5681 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5682 | ||
5683 | w->watchpoint_triggered = watch_triggered_yes; | |
5684 | } | |
f431efe5 PA |
5685 | } |
5686 | } | |
5687 | ||
7c16b83e | 5688 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5689 | if (!target_supports_stopped_by_sw_breakpoint () |
5690 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5691 | { |
1cf4d951 | 5692 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5693 | { |
1cf4d951 PA |
5694 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5695 | && need_moribund_for_location_type (loc)) | |
5696 | { | |
5697 | bs = bpstat_alloc (loc, &bs_link); | |
5698 | /* For hits of moribund locations, we should just proceed. */ | |
5699 | bs->stop = 0; | |
5700 | bs->print = 0; | |
5701 | bs->print_it = print_it_noop; | |
5702 | } | |
f431efe5 PA |
5703 | } |
5704 | } | |
5705 | ||
edcc5120 TT |
5706 | /* A bit of special processing for shlib breakpoints. We need to |
5707 | process solib loading here, so that the lists of loaded and | |
5708 | unloaded libraries are correct before we handle "catch load" and | |
5709 | "catch unload". */ | |
5710 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5711 | { | |
5d268276 | 5712 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5713 | { |
5714 | handle_solib_event (); | |
5715 | break; | |
5716 | } | |
5717 | } | |
5718 | ||
f431efe5 PA |
5719 | /* Now go through the locations that caused the target to stop, and |
5720 | check whether we're interested in reporting this stop to higher | |
5721 | layers, or whether we should resume the target transparently. */ | |
5722 | ||
5723 | removed_any = 0; | |
5724 | ||
5760d0ab | 5725 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5726 | { |
5727 | if (!bs->stop) | |
5728 | continue; | |
5729 | ||
f431efe5 | 5730 | b = bs->breakpoint_at; |
348d480f PA |
5731 | b->ops->check_status (bs); |
5732 | if (bs->stop) | |
28010a5d | 5733 | { |
348d480f | 5734 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5735 | |
429374b8 JK |
5736 | if (bs->stop) |
5737 | { | |
5738 | ++(b->hit_count); | |
8d3788bd | 5739 | observer_notify_breakpoint_modified (b); |
c906108c | 5740 | |
4a64f543 | 5741 | /* We will stop here. */ |
429374b8 JK |
5742 | if (b->disposition == disp_disable) |
5743 | { | |
816338b5 | 5744 | --(b->enable_count); |
1a853c52 | 5745 | if (b->enable_count <= 0) |
429374b8 | 5746 | b->enable_state = bp_disabled; |
f431efe5 | 5747 | removed_any = 1; |
429374b8 JK |
5748 | } |
5749 | if (b->silent) | |
5750 | bs->print = 0; | |
5751 | bs->commands = b->commands; | |
9add0f1b | 5752 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5753 | if (command_line_is_silent (bs->commands |
5754 | ? bs->commands->commands : NULL)) | |
5755 | bs->print = 0; | |
9d6e6e84 HZ |
5756 | |
5757 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5758 | } |
5759 | ||
348d480f | 5760 | } |
a9b3a50f PA |
5761 | |
5762 | /* Print nothing for this entry if we don't stop or don't | |
5763 | print. */ | |
5764 | if (!bs->stop || !bs->print) | |
5765 | bs->print_it = print_it_noop; | |
429374b8 | 5766 | } |
876fa593 | 5767 | |
d983da9c DJ |
5768 | /* If we aren't stopping, the value of some hardware watchpoint may |
5769 | not have changed, but the intermediate memory locations we are | |
5770 | watching may have. Don't bother if we're stopping; this will get | |
5771 | done later. */ | |
d832cb68 | 5772 | need_remove_insert = 0; |
5760d0ab JK |
5773 | if (! bpstat_causes_stop (bs_head)) |
5774 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5775 | if (!bs->stop |
f431efe5 PA |
5776 | && bs->breakpoint_at |
5777 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5778 | { |
3a5c3e22 PA |
5779 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5780 | ||
5781 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5782 | need_remove_insert = 1; |
d983da9c DJ |
5783 | } |
5784 | ||
d832cb68 | 5785 | if (need_remove_insert) |
44702360 | 5786 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5787 | else if (removed_any) |
44702360 | 5788 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5789 | |
5760d0ab | 5790 | return bs_head; |
c906108c | 5791 | } |
628fe4e4 JK |
5792 | |
5793 | static void | |
5794 | handle_jit_event (void) | |
5795 | { | |
5796 | struct frame_info *frame; | |
5797 | struct gdbarch *gdbarch; | |
5798 | ||
243a9253 PA |
5799 | if (debug_infrun) |
5800 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5801 | ||
628fe4e4 JK |
5802 | /* Switch terminal for any messages produced by |
5803 | breakpoint_re_set. */ | |
5804 | target_terminal_ours_for_output (); | |
5805 | ||
5806 | frame = get_current_frame (); | |
5807 | gdbarch = get_frame_arch (frame); | |
5808 | ||
5809 | jit_event_handler (gdbarch); | |
5810 | ||
5811 | target_terminal_inferior (); | |
5812 | } | |
5813 | ||
5814 | /* Prepare WHAT final decision for infrun. */ | |
5815 | ||
5816 | /* Decide what infrun needs to do with this bpstat. */ | |
5817 | ||
c906108c | 5818 | struct bpstat_what |
0e30163f | 5819 | bpstat_what (bpstat bs_head) |
c906108c | 5820 | { |
c906108c | 5821 | struct bpstat_what retval; |
628fe4e4 | 5822 | int jit_event = 0; |
0e30163f | 5823 | bpstat bs; |
c906108c | 5824 | |
628fe4e4 | 5825 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5826 | retval.call_dummy = STOP_NONE; |
186c406b | 5827 | retval.is_longjmp = 0; |
628fe4e4 | 5828 | |
0e30163f | 5829 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5830 | { |
628fe4e4 JK |
5831 | /* Extract this BS's action. After processing each BS, we check |
5832 | if its action overrides all we've seem so far. */ | |
5833 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5834 | enum bptype bptype; | |
5835 | ||
c906108c | 5836 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5837 | { |
5838 | /* I suspect this can happen if it was a momentary | |
5839 | breakpoint which has since been deleted. */ | |
5840 | bptype = bp_none; | |
5841 | } | |
20874c92 | 5842 | else |
f431efe5 | 5843 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5844 | |
5845 | switch (bptype) | |
c906108c SS |
5846 | { |
5847 | case bp_none: | |
628fe4e4 | 5848 | break; |
c906108c SS |
5849 | case bp_breakpoint: |
5850 | case bp_hardware_breakpoint: | |
7c16b83e | 5851 | case bp_single_step: |
c906108c SS |
5852 | case bp_until: |
5853 | case bp_finish: | |
a9b3a50f | 5854 | case bp_shlib_event: |
c906108c SS |
5855 | if (bs->stop) |
5856 | { | |
5857 | if (bs->print) | |
628fe4e4 | 5858 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5859 | else |
628fe4e4 | 5860 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5861 | } |
5862 | else | |
628fe4e4 | 5863 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5864 | break; |
5865 | case bp_watchpoint: | |
5866 | case bp_hardware_watchpoint: | |
5867 | case bp_read_watchpoint: | |
5868 | case bp_access_watchpoint: | |
5869 | if (bs->stop) | |
5870 | { | |
5871 | if (bs->print) | |
628fe4e4 | 5872 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5873 | else |
628fe4e4 | 5874 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5875 | } |
5876 | else | |
628fe4e4 JK |
5877 | { |
5878 | /* There was a watchpoint, but we're not stopping. | |
5879 | This requires no further action. */ | |
5880 | } | |
c906108c SS |
5881 | break; |
5882 | case bp_longjmp: | |
e2e4d78b | 5883 | case bp_longjmp_call_dummy: |
186c406b | 5884 | case bp_exception: |
0a39bb32 PA |
5885 | if (bs->stop) |
5886 | { | |
5887 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5888 | retval.is_longjmp = bptype != bp_exception; | |
5889 | } | |
5890 | else | |
5891 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5892 | break; |
5893 | case bp_longjmp_resume: | |
186c406b | 5894 | case bp_exception_resume: |
0a39bb32 PA |
5895 | if (bs->stop) |
5896 | { | |
5897 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5898 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5899 | } | |
5900 | else | |
5901 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5902 | break; |
5903 | case bp_step_resume: | |
5904 | if (bs->stop) | |
628fe4e4 JK |
5905 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5906 | else | |
c906108c | 5907 | { |
628fe4e4 JK |
5908 | /* It is for the wrong frame. */ |
5909 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5910 | } |
c906108c | 5911 | break; |
2c03e5be PA |
5912 | case bp_hp_step_resume: |
5913 | if (bs->stop) | |
5914 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5915 | else | |
5916 | { | |
5917 | /* It is for the wrong frame. */ | |
5918 | this_action = BPSTAT_WHAT_SINGLE; | |
5919 | } | |
5920 | break; | |
c906108c | 5921 | case bp_watchpoint_scope: |
c4093a6a | 5922 | case bp_thread_event: |
1900040c | 5923 | case bp_overlay_event: |
0fd8e87f | 5924 | case bp_longjmp_master: |
aa7d318d | 5925 | case bp_std_terminate_master: |
186c406b | 5926 | case bp_exception_master: |
628fe4e4 | 5927 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5928 | break; |
ce78b96d | 5929 | case bp_catchpoint: |
c5aa993b JM |
5930 | if (bs->stop) |
5931 | { | |
5932 | if (bs->print) | |
628fe4e4 | 5933 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5934 | else |
628fe4e4 | 5935 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5936 | } |
5937 | else | |
628fe4e4 JK |
5938 | { |
5939 | /* There was a catchpoint, but we're not stopping. | |
5940 | This requires no further action. */ | |
5941 | } | |
5942 | break; | |
628fe4e4 JK |
5943 | case bp_jit_event: |
5944 | jit_event = 1; | |
5945 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5946 | break; |
c906108c | 5947 | case bp_call_dummy: |
53a5351d JM |
5948 | /* Make sure the action is stop (silent or noisy), |
5949 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5950 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5951 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5952 | break; |
5953 | case bp_std_terminate: | |
5954 | /* Make sure the action is stop (silent or noisy), | |
5955 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5956 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5957 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5958 | break; |
1042e4c0 | 5959 | case bp_tracepoint: |
7a697b8d | 5960 | case bp_fast_tracepoint: |
0fb4aa4b | 5961 | case bp_static_tracepoint: |
1042e4c0 SS |
5962 | /* Tracepoint hits should not be reported back to GDB, and |
5963 | if one got through somehow, it should have been filtered | |
5964 | out already. */ | |
5965 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5966 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5967 | break; |
5968 | case bp_gnu_ifunc_resolver: | |
5969 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5970 | this_action = BPSTAT_WHAT_SINGLE; | |
5971 | break; | |
5972 | case bp_gnu_ifunc_resolver_return: | |
5973 | /* The breakpoint will be removed, execution will restart from the | |
5974 | PC of the former breakpoint. */ | |
5975 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5976 | break; | |
e7e0cddf SS |
5977 | |
5978 | case bp_dprintf: | |
a11cfd87 HZ |
5979 | if (bs->stop) |
5980 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5981 | else | |
5982 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5983 | break; |
5984 | ||
628fe4e4 JK |
5985 | default: |
5986 | internal_error (__FILE__, __LINE__, | |
5987 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5988 | } |
628fe4e4 JK |
5989 | |
5990 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5991 | } |
628fe4e4 | 5992 | |
243a9253 PA |
5993 | return retval; |
5994 | } | |
628fe4e4 | 5995 | |
243a9253 PA |
5996 | void |
5997 | bpstat_run_callbacks (bpstat bs_head) | |
5998 | { | |
5999 | bpstat bs; | |
628fe4e4 | 6000 | |
0e30163f JK |
6001 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6002 | { | |
6003 | struct breakpoint *b = bs->breakpoint_at; | |
6004 | ||
6005 | if (b == NULL) | |
6006 | continue; | |
6007 | switch (b->type) | |
6008 | { | |
243a9253 PA |
6009 | case bp_jit_event: |
6010 | handle_jit_event (); | |
6011 | break; | |
0e30163f JK |
6012 | case bp_gnu_ifunc_resolver: |
6013 | gnu_ifunc_resolver_stop (b); | |
6014 | break; | |
6015 | case bp_gnu_ifunc_resolver_return: | |
6016 | gnu_ifunc_resolver_return_stop (b); | |
6017 | break; | |
6018 | } | |
6019 | } | |
c906108c SS |
6020 | } |
6021 | ||
6022 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6023 | without hardware support). This isn't related to a specific bpstat, | |
6024 | just to things like whether watchpoints are set. */ | |
6025 | ||
c5aa993b | 6026 | int |
fba45db2 | 6027 | bpstat_should_step (void) |
c906108c SS |
6028 | { |
6029 | struct breakpoint *b; | |
cc59ec59 | 6030 | |
c906108c | 6031 | ALL_BREAKPOINTS (b) |
717a8278 | 6032 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6033 | return 1; |
c906108c SS |
6034 | return 0; |
6035 | } | |
6036 | ||
67822962 PA |
6037 | int |
6038 | bpstat_causes_stop (bpstat bs) | |
6039 | { | |
6040 | for (; bs != NULL; bs = bs->next) | |
6041 | if (bs->stop) | |
6042 | return 1; | |
6043 | ||
6044 | return 0; | |
6045 | } | |
6046 | ||
c906108c | 6047 | \f |
c5aa993b | 6048 | |
170b53b2 UW |
6049 | /* Compute a string of spaces suitable to indent the next line |
6050 | so it starts at the position corresponding to the table column | |
6051 | named COL_NAME in the currently active table of UIOUT. */ | |
6052 | ||
6053 | static char * | |
6054 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6055 | { | |
6056 | static char wrap_indent[80]; | |
6057 | int i, total_width, width, align; | |
6058 | char *text; | |
6059 | ||
6060 | total_width = 0; | |
6061 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6062 | { | |
6063 | if (strcmp (text, col_name) == 0) | |
6064 | { | |
6065 | gdb_assert (total_width < sizeof wrap_indent); | |
6066 | memset (wrap_indent, ' ', total_width); | |
6067 | wrap_indent[total_width] = 0; | |
6068 | ||
6069 | return wrap_indent; | |
6070 | } | |
6071 | ||
6072 | total_width += width + 1; | |
6073 | } | |
6074 | ||
6075 | return NULL; | |
6076 | } | |
6077 | ||
b775012e LM |
6078 | /* Determine if the locations of this breakpoint will have their conditions |
6079 | evaluated by the target, host or a mix of both. Returns the following: | |
6080 | ||
6081 | "host": Host evals condition. | |
6082 | "host or target": Host or Target evals condition. | |
6083 | "target": Target evals condition. | |
6084 | */ | |
6085 | ||
6086 | static const char * | |
6087 | bp_condition_evaluator (struct breakpoint *b) | |
6088 | { | |
6089 | struct bp_location *bl; | |
6090 | char host_evals = 0; | |
6091 | char target_evals = 0; | |
6092 | ||
6093 | if (!b) | |
6094 | return NULL; | |
6095 | ||
6096 | if (!is_breakpoint (b)) | |
6097 | return NULL; | |
6098 | ||
6099 | if (gdb_evaluates_breakpoint_condition_p () | |
6100 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6101 | return condition_evaluation_host; | |
6102 | ||
6103 | for (bl = b->loc; bl; bl = bl->next) | |
6104 | { | |
6105 | if (bl->cond_bytecode) | |
6106 | target_evals++; | |
6107 | else | |
6108 | host_evals++; | |
6109 | } | |
6110 | ||
6111 | if (host_evals && target_evals) | |
6112 | return condition_evaluation_both; | |
6113 | else if (target_evals) | |
6114 | return condition_evaluation_target; | |
6115 | else | |
6116 | return condition_evaluation_host; | |
6117 | } | |
6118 | ||
6119 | /* Determine the breakpoint location's condition evaluator. This is | |
6120 | similar to bp_condition_evaluator, but for locations. */ | |
6121 | ||
6122 | static const char * | |
6123 | bp_location_condition_evaluator (struct bp_location *bl) | |
6124 | { | |
6125 | if (bl && !is_breakpoint (bl->owner)) | |
6126 | return NULL; | |
6127 | ||
6128 | if (gdb_evaluates_breakpoint_condition_p () | |
6129 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6130 | return condition_evaluation_host; | |
6131 | ||
6132 | if (bl && bl->cond_bytecode) | |
6133 | return condition_evaluation_target; | |
6134 | else | |
6135 | return condition_evaluation_host; | |
6136 | } | |
6137 | ||
859825b8 JK |
6138 | /* Print the LOC location out of the list of B->LOC locations. */ |
6139 | ||
170b53b2 UW |
6140 | static void |
6141 | print_breakpoint_location (struct breakpoint *b, | |
6142 | struct bp_location *loc) | |
0d381245 | 6143 | { |
79a45e25 | 6144 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6145 | struct cleanup *old_chain = save_current_program_space (); |
6146 | ||
859825b8 JK |
6147 | if (loc != NULL && loc->shlib_disabled) |
6148 | loc = NULL; | |
6149 | ||
6c95b8df PA |
6150 | if (loc != NULL) |
6151 | set_current_program_space (loc->pspace); | |
6152 | ||
56435ebe | 6153 | if (b->display_canonical) |
f00aae0f KS |
6154 | ui_out_field_string (uiout, "what", |
6155 | event_location_to_string (b->location)); | |
2f202fde | 6156 | else if (loc && loc->symtab) |
0d381245 VP |
6157 | { |
6158 | struct symbol *sym | |
6159 | = find_pc_sect_function (loc->address, loc->section); | |
6160 | if (sym) | |
6161 | { | |
6162 | ui_out_text (uiout, "in "); | |
6163 | ui_out_field_string (uiout, "func", | |
6164 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6165 | ui_out_text (uiout, " "); |
6166 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6167 | ui_out_text (uiout, "at "); | |
0d381245 | 6168 | } |
05cba821 JK |
6169 | ui_out_field_string (uiout, "file", |
6170 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6171 | ui_out_text (uiout, ":"); |
05cba821 | 6172 | |
0d381245 | 6173 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6174 | ui_out_field_string (uiout, "fullname", |
6175 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6176 | |
f8eba3c6 | 6177 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6178 | } |
859825b8 | 6179 | else if (loc) |
0d381245 | 6180 | { |
f99d8bf4 PA |
6181 | struct ui_file *stb = mem_fileopen (); |
6182 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6183 | |
f99d8bf4 | 6184 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6185 | demangle, ""); |
0d381245 | 6186 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6187 | |
6188 | do_cleanups (stb_chain); | |
0d381245 | 6189 | } |
859825b8 | 6190 | else |
f00aae0f KS |
6191 | { |
6192 | ui_out_field_string (uiout, "pending", | |
6193 | event_location_to_string (b->location)); | |
6194 | /* If extra_string is available, it could be holding a condition | |
6195 | or dprintf arguments. In either case, make sure it is printed, | |
6196 | too, but only for non-MI streams. */ | |
6197 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6198 | { | |
6199 | if (b->type == bp_dprintf) | |
6200 | ui_out_text (uiout, ","); | |
6201 | else | |
6202 | ui_out_text (uiout, " "); | |
6203 | ui_out_text (uiout, b->extra_string); | |
6204 | } | |
6205 | } | |
6c95b8df | 6206 | |
b775012e LM |
6207 | if (loc && is_breakpoint (b) |
6208 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6209 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6210 | { | |
6211 | ui_out_text (uiout, " ("); | |
6212 | ui_out_field_string (uiout, "evaluated-by", | |
6213 | bp_location_condition_evaluator (loc)); | |
6214 | ui_out_text (uiout, ")"); | |
6215 | } | |
6216 | ||
6c95b8df | 6217 | do_cleanups (old_chain); |
0d381245 VP |
6218 | } |
6219 | ||
269b11a2 PA |
6220 | static const char * |
6221 | bptype_string (enum bptype type) | |
c906108c | 6222 | { |
c4093a6a JM |
6223 | struct ep_type_description |
6224 | { | |
6225 | enum bptype type; | |
6226 | char *description; | |
6227 | }; | |
6228 | static struct ep_type_description bptypes[] = | |
c906108c | 6229 | { |
c5aa993b JM |
6230 | {bp_none, "?deleted?"}, |
6231 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6232 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6233 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6234 | {bp_until, "until"}, |
6235 | {bp_finish, "finish"}, | |
6236 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6237 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6238 | {bp_read_watchpoint, "read watchpoint"}, |
6239 | {bp_access_watchpoint, "acc watchpoint"}, | |
6240 | {bp_longjmp, "longjmp"}, | |
6241 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6242 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6243 | {bp_exception, "exception"}, |
6244 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6245 | {bp_step_resume, "step resume"}, |
2c03e5be | 6246 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6247 | {bp_watchpoint_scope, "watchpoint scope"}, |
6248 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6249 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6250 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6251 | {bp_thread_event, "thread events"}, |
1900040c | 6252 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6253 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6254 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6255 | {bp_exception_master, "exception master"}, |
ce78b96d | 6256 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6257 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6258 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6259 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6260 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6261 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6262 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6263 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6264 | }; |
269b11a2 PA |
6265 | |
6266 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6267 | || ((int) type != bptypes[(int) type].type)) | |
6268 | internal_error (__FILE__, __LINE__, | |
6269 | _("bptypes table does not describe type #%d."), | |
6270 | (int) type); | |
6271 | ||
6272 | return bptypes[(int) type].description; | |
6273 | } | |
6274 | ||
998580f1 MK |
6275 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6276 | For CLI, prefix the list with the string 'inf'. */ | |
6277 | ||
6278 | static void | |
6279 | output_thread_groups (struct ui_out *uiout, | |
6280 | const char *field_name, | |
6281 | VEC(int) *inf_num, | |
6282 | int mi_only) | |
6283 | { | |
752eb8b4 | 6284 | struct cleanup *back_to; |
998580f1 MK |
6285 | int is_mi = ui_out_is_mi_like_p (uiout); |
6286 | int inf; | |
6287 | int i; | |
6288 | ||
6289 | /* For backward compatibility, don't display inferiors in CLI unless | |
6290 | there are several. Always display them for MI. */ | |
6291 | if (!is_mi && mi_only) | |
6292 | return; | |
6293 | ||
752eb8b4 TT |
6294 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6295 | ||
998580f1 MK |
6296 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6297 | { | |
6298 | if (is_mi) | |
6299 | { | |
6300 | char mi_group[10]; | |
6301 | ||
6302 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6303 | ui_out_field_string (uiout, NULL, mi_group); | |
6304 | } | |
6305 | else | |
6306 | { | |
6307 | if (i == 0) | |
6308 | ui_out_text (uiout, " inf "); | |
6309 | else | |
6310 | ui_out_text (uiout, ", "); | |
6311 | ||
6312 | ui_out_text (uiout, plongest (inf)); | |
6313 | } | |
6314 | } | |
6315 | ||
6316 | do_cleanups (back_to); | |
6317 | } | |
6318 | ||
269b11a2 PA |
6319 | /* Print B to gdb_stdout. */ |
6320 | ||
6321 | static void | |
6322 | print_one_breakpoint_location (struct breakpoint *b, | |
6323 | struct bp_location *loc, | |
6324 | int loc_number, | |
6325 | struct bp_location **last_loc, | |
269b11a2 PA |
6326 | int allflag) |
6327 | { | |
6328 | struct command_line *l; | |
c2c6d25f | 6329 | static char bpenables[] = "nynny"; |
c906108c | 6330 | |
79a45e25 | 6331 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6332 | int header_of_multiple = 0; |
6333 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6334 | struct value_print_options opts; |
6335 | ||
6336 | get_user_print_options (&opts); | |
0d381245 VP |
6337 | |
6338 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6339 | /* See comment in print_one_breakpoint concerning treatment of |
6340 | breakpoints with single disabled location. */ | |
0d381245 VP |
6341 | if (loc == NULL |
6342 | && (b->loc != NULL | |
6343 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6344 | header_of_multiple = 1; | |
6345 | if (loc == NULL) | |
6346 | loc = b->loc; | |
6347 | ||
c4093a6a JM |
6348 | annotate_record (); |
6349 | ||
6350 | /* 1 */ | |
6351 | annotate_field (0); | |
0d381245 VP |
6352 | if (part_of_multiple) |
6353 | { | |
6354 | char *formatted; | |
0c6773c1 | 6355 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6356 | ui_out_field_string (uiout, "number", formatted); |
6357 | xfree (formatted); | |
6358 | } | |
6359 | else | |
6360 | { | |
6361 | ui_out_field_int (uiout, "number", b->number); | |
6362 | } | |
c4093a6a JM |
6363 | |
6364 | /* 2 */ | |
6365 | annotate_field (1); | |
0d381245 VP |
6366 | if (part_of_multiple) |
6367 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6368 | else |
6369 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6370 | |
6371 | /* 3 */ | |
6372 | annotate_field (2); | |
0d381245 VP |
6373 | if (part_of_multiple) |
6374 | ui_out_field_skip (uiout, "disp"); | |
6375 | else | |
2cec12e5 | 6376 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6377 | |
c4093a6a JM |
6378 | |
6379 | /* 4 */ | |
6380 | annotate_field (3); | |
0d381245 | 6381 | if (part_of_multiple) |
54e52265 | 6382 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6383 | else |
4a64f543 MS |
6384 | ui_out_field_fmt (uiout, "enabled", "%c", |
6385 | bpenables[(int) b->enable_state]); | |
54e52265 | 6386 | ui_out_spaces (uiout, 2); |
0d381245 | 6387 | |
c4093a6a JM |
6388 | |
6389 | /* 5 and 6 */ | |
3086aeae | 6390 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6391 | { |
4a64f543 MS |
6392 | /* Although the print_one can possibly print all locations, |
6393 | calling it here is not likely to get any nice result. So, | |
6394 | make sure there's just one location. */ | |
0d381245 | 6395 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6396 | b->ops->print_one (b, last_loc); |
0d381245 | 6397 | } |
3086aeae DJ |
6398 | else |
6399 | switch (b->type) | |
6400 | { | |
6401 | case bp_none: | |
6402 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6403 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6404 | break; |
c906108c | 6405 | |
3086aeae DJ |
6406 | case bp_watchpoint: |
6407 | case bp_hardware_watchpoint: | |
6408 | case bp_read_watchpoint: | |
6409 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6410 | { |
6411 | struct watchpoint *w = (struct watchpoint *) b; | |
6412 | ||
6413 | /* Field 4, the address, is omitted (which makes the columns | |
6414 | not line up too nicely with the headers, but the effect | |
6415 | is relatively readable). */ | |
6416 | if (opts.addressprint) | |
6417 | ui_out_field_skip (uiout, "addr"); | |
6418 | annotate_field (5); | |
6419 | ui_out_field_string (uiout, "what", w->exp_string); | |
6420 | } | |
3086aeae DJ |
6421 | break; |
6422 | ||
3086aeae DJ |
6423 | case bp_breakpoint: |
6424 | case bp_hardware_breakpoint: | |
7c16b83e | 6425 | case bp_single_step: |
3086aeae DJ |
6426 | case bp_until: |
6427 | case bp_finish: | |
6428 | case bp_longjmp: | |
6429 | case bp_longjmp_resume: | |
e2e4d78b | 6430 | case bp_longjmp_call_dummy: |
186c406b TT |
6431 | case bp_exception: |
6432 | case bp_exception_resume: | |
3086aeae | 6433 | case bp_step_resume: |
2c03e5be | 6434 | case bp_hp_step_resume: |
3086aeae DJ |
6435 | case bp_watchpoint_scope: |
6436 | case bp_call_dummy: | |
aa7d318d | 6437 | case bp_std_terminate: |
3086aeae DJ |
6438 | case bp_shlib_event: |
6439 | case bp_thread_event: | |
6440 | case bp_overlay_event: | |
0fd8e87f | 6441 | case bp_longjmp_master: |
aa7d318d | 6442 | case bp_std_terminate_master: |
186c406b | 6443 | case bp_exception_master: |
1042e4c0 | 6444 | case bp_tracepoint: |
7a697b8d | 6445 | case bp_fast_tracepoint: |
0fb4aa4b | 6446 | case bp_static_tracepoint: |
e7e0cddf | 6447 | case bp_dprintf: |
4efc6507 | 6448 | case bp_jit_event: |
0e30163f JK |
6449 | case bp_gnu_ifunc_resolver: |
6450 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6451 | if (opts.addressprint) |
3086aeae DJ |
6452 | { |
6453 | annotate_field (4); | |
54e52265 | 6454 | if (header_of_multiple) |
0d381245 | 6455 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6456 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6457 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6458 | else |
5af949e3 UW |
6459 | ui_out_field_core_addr (uiout, "addr", |
6460 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6461 | } |
6462 | annotate_field (5); | |
0d381245 | 6463 | if (!header_of_multiple) |
170b53b2 | 6464 | print_breakpoint_location (b, loc); |
0d381245 | 6465 | if (b->loc) |
a6d9a66e | 6466 | *last_loc = b->loc; |
3086aeae DJ |
6467 | break; |
6468 | } | |
c906108c | 6469 | |
6c95b8df | 6470 | |
998580f1 | 6471 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6472 | { |
6473 | struct inferior *inf; | |
998580f1 MK |
6474 | VEC(int) *inf_num = NULL; |
6475 | int mi_only = 1; | |
6c95b8df | 6476 | |
998580f1 | 6477 | ALL_INFERIORS (inf) |
6c95b8df PA |
6478 | { |
6479 | if (inf->pspace == loc->pspace) | |
998580f1 | 6480 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6481 | } |
998580f1 MK |
6482 | |
6483 | /* For backward compatibility, don't display inferiors in CLI unless | |
6484 | there are several. Always display for MI. */ | |
6485 | if (allflag | |
6486 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6487 | && (number_of_program_spaces () > 1 | |
6488 | || number_of_inferiors () > 1) | |
6489 | /* LOC is for existing B, it cannot be in | |
6490 | moribund_locations and thus having NULL OWNER. */ | |
6491 | && loc->owner->type != bp_catchpoint)) | |
6492 | mi_only = 0; | |
6493 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6494 | VEC_free (int, inf_num); | |
6c95b8df PA |
6495 | } |
6496 | ||
4a306c9a | 6497 | if (!part_of_multiple) |
c4093a6a | 6498 | { |
4a306c9a JB |
6499 | if (b->thread != -1) |
6500 | { | |
6501 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6502 | "stop only in" line a little further down. */ |
4a306c9a JB |
6503 | ui_out_text (uiout, " thread "); |
6504 | ui_out_field_int (uiout, "thread", b->thread); | |
6505 | } | |
6506 | else if (b->task != 0) | |
6507 | { | |
6508 | ui_out_text (uiout, " task "); | |
6509 | ui_out_field_int (uiout, "task", b->task); | |
6510 | } | |
c4093a6a | 6511 | } |
f1310107 | 6512 | |
8b93c638 | 6513 | ui_out_text (uiout, "\n"); |
f1310107 | 6514 | |
348d480f | 6515 | if (!part_of_multiple) |
f1310107 TJB |
6516 | b->ops->print_one_detail (b, uiout); |
6517 | ||
0d381245 | 6518 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6519 | { |
6520 | annotate_field (6); | |
8b93c638 | 6521 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6522 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6523 | the frame ID. */ |
5af949e3 UW |
6524 | ui_out_field_core_addr (uiout, "frame", |
6525 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6526 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6527 | } |
6528 | ||
28010a5d | 6529 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6530 | { |
6531 | annotate_field (7); | |
d77f58be | 6532 | if (is_tracepoint (b)) |
1042e4c0 SS |
6533 | ui_out_text (uiout, "\ttrace only if "); |
6534 | else | |
6535 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6536 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6537 | |
6538 | /* Print whether the target is doing the breakpoint's condition | |
6539 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6540 | if (is_breakpoint (b) | |
6541 | && breakpoint_condition_evaluation_mode () | |
6542 | == condition_evaluation_target) | |
6543 | { | |
6544 | ui_out_text (uiout, " ("); | |
6545 | ui_out_field_string (uiout, "evaluated-by", | |
6546 | bp_condition_evaluator (b)); | |
6547 | ui_out_text (uiout, " evals)"); | |
6548 | } | |
0101ce28 JJ |
6549 | ui_out_text (uiout, "\n"); |
6550 | } | |
6551 | ||
0d381245 | 6552 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6553 | { |
4a64f543 | 6554 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6555 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6556 | if (ui_out_is_mi_like_p (uiout)) |
6557 | ui_out_field_int (uiout, "thread", b->thread); | |
6558 | else | |
6559 | { | |
6560 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6561 | ||
6562 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6563 | } | |
8b93c638 | 6564 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6565 | } |
6566 | ||
556ec64d YQ |
6567 | if (!part_of_multiple) |
6568 | { | |
6569 | if (b->hit_count) | |
31f56a27 YQ |
6570 | { |
6571 | /* FIXME should make an annotation for this. */ | |
6572 | if (is_catchpoint (b)) | |
6573 | ui_out_text (uiout, "\tcatchpoint"); | |
6574 | else if (is_tracepoint (b)) | |
6575 | ui_out_text (uiout, "\ttracepoint"); | |
6576 | else | |
6577 | ui_out_text (uiout, "\tbreakpoint"); | |
6578 | ui_out_text (uiout, " already hit "); | |
6579 | ui_out_field_int (uiout, "times", b->hit_count); | |
6580 | if (b->hit_count == 1) | |
6581 | ui_out_text (uiout, " time\n"); | |
6582 | else | |
6583 | ui_out_text (uiout, " times\n"); | |
6584 | } | |
556ec64d YQ |
6585 | else |
6586 | { | |
31f56a27 YQ |
6587 | /* Output the count also if it is zero, but only if this is mi. */ |
6588 | if (ui_out_is_mi_like_p (uiout)) | |
6589 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6590 | } |
6591 | } | |
8b93c638 | 6592 | |
0d381245 | 6593 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6594 | { |
6595 | annotate_field (8); | |
8b93c638 JM |
6596 | ui_out_text (uiout, "\tignore next "); |
6597 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6598 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6599 | } |
059fb39f | 6600 | |
816338b5 SS |
6601 | /* Note that an enable count of 1 corresponds to "enable once" |
6602 | behavior, which is reported by the combination of enablement and | |
6603 | disposition, so we don't need to mention it here. */ | |
6604 | if (!part_of_multiple && b->enable_count > 1) | |
6605 | { | |
6606 | annotate_field (8); | |
6607 | ui_out_text (uiout, "\tdisable after "); | |
6608 | /* Tweak the wording to clarify that ignore and enable counts | |
6609 | are distinct, and have additive effect. */ | |
6610 | if (b->ignore_count) | |
6611 | ui_out_text (uiout, "additional "); | |
6612 | else | |
6613 | ui_out_text (uiout, "next "); | |
6614 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6615 | ui_out_text (uiout, " hits\n"); | |
6616 | } | |
6617 | ||
f196051f SS |
6618 | if (!part_of_multiple && is_tracepoint (b)) |
6619 | { | |
6620 | struct tracepoint *tp = (struct tracepoint *) b; | |
6621 | ||
6622 | if (tp->traceframe_usage) | |
6623 | { | |
6624 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6625 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6626 | ui_out_text (uiout, " bytes\n"); | |
6627 | } | |
6628 | } | |
d3ce09f5 | 6629 | |
9add0f1b | 6630 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6631 | if (!part_of_multiple && l) |
c4093a6a | 6632 | { |
3b31d625 EZ |
6633 | struct cleanup *script_chain; |
6634 | ||
c4093a6a | 6635 | annotate_field (9); |
3b31d625 | 6636 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6637 | print_command_lines (uiout, l, 4); |
3b31d625 | 6638 | do_cleanups (script_chain); |
c4093a6a | 6639 | } |
d24317b4 | 6640 | |
d9b3f62e | 6641 | if (is_tracepoint (b)) |
1042e4c0 | 6642 | { |
d9b3f62e PA |
6643 | struct tracepoint *t = (struct tracepoint *) b; |
6644 | ||
6645 | if (!part_of_multiple && t->pass_count) | |
6646 | { | |
6647 | annotate_field (10); | |
6648 | ui_out_text (uiout, "\tpass count "); | |
6649 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6650 | ui_out_text (uiout, " \n"); | |
6651 | } | |
f2a8bc8a YQ |
6652 | |
6653 | /* Don't display it when tracepoint or tracepoint location is | |
6654 | pending. */ | |
6655 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6656 | { | |
6657 | annotate_field (11); | |
6658 | ||
6659 | if (ui_out_is_mi_like_p (uiout)) | |
6660 | ui_out_field_string (uiout, "installed", | |
6661 | loc->inserted ? "y" : "n"); | |
6662 | else | |
6663 | { | |
6664 | if (loc->inserted) | |
6665 | ui_out_text (uiout, "\t"); | |
6666 | else | |
6667 | ui_out_text (uiout, "\tnot "); | |
6668 | ui_out_text (uiout, "installed on target\n"); | |
6669 | } | |
6670 | } | |
1042e4c0 SS |
6671 | } |
6672 | ||
d24317b4 VP |
6673 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6674 | { | |
3a5c3e22 PA |
6675 | if (is_watchpoint (b)) |
6676 | { | |
6677 | struct watchpoint *w = (struct watchpoint *) b; | |
6678 | ||
6679 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6680 | } | |
f00aae0f KS |
6681 | else if (b->location != NULL |
6682 | && event_location_to_string (b->location) != NULL) | |
6683 | ui_out_field_string (uiout, "original-location", | |
6684 | event_location_to_string (b->location)); | |
d24317b4 | 6685 | } |
c4093a6a | 6686 | } |
c5aa993b | 6687 | |
0d381245 VP |
6688 | static void |
6689 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6690 | struct bp_location **last_loc, |
6c95b8df | 6691 | int allflag) |
0d381245 | 6692 | { |
8d3788bd | 6693 | struct cleanup *bkpt_chain; |
79a45e25 | 6694 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6695 | |
6696 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6697 | ||
12c5a436 | 6698 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6699 | do_cleanups (bkpt_chain); |
0d381245 VP |
6700 | |
6701 | /* If this breakpoint has custom print function, | |
6702 | it's already printed. Otherwise, print individual | |
6703 | locations, if any. */ | |
6704 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6705 | { | |
4a64f543 MS |
6706 | /* If breakpoint has a single location that is disabled, we |
6707 | print it as if it had several locations, since otherwise it's | |
6708 | hard to represent "breakpoint enabled, location disabled" | |
6709 | situation. | |
6710 | ||
6711 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6712 | internally, that's not a property exposed to user. */ |
0d381245 | 6713 | if (b->loc |
a5606eee | 6714 | && !is_hardware_watchpoint (b) |
8d3788bd | 6715 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6716 | { |
6717 | struct bp_location *loc; | |
6718 | int n = 1; | |
8d3788bd | 6719 | |
0d381245 | 6720 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6721 | { |
6722 | struct cleanup *inner2 = | |
6723 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6724 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6725 | do_cleanups (inner2); | |
6726 | } | |
0d381245 VP |
6727 | } |
6728 | } | |
6729 | } | |
6730 | ||
a6d9a66e UW |
6731 | static int |
6732 | breakpoint_address_bits (struct breakpoint *b) | |
6733 | { | |
6734 | int print_address_bits = 0; | |
6735 | struct bp_location *loc; | |
6736 | ||
c6d81124 PA |
6737 | /* Software watchpoints that aren't watching memory don't have an |
6738 | address to print. */ | |
6739 | if (is_no_memory_software_watchpoint (b)) | |
6740 | return 0; | |
6741 | ||
a6d9a66e UW |
6742 | for (loc = b->loc; loc; loc = loc->next) |
6743 | { | |
c7437ca6 PA |
6744 | int addr_bit; |
6745 | ||
c7437ca6 | 6746 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6747 | if (addr_bit > print_address_bits) |
6748 | print_address_bits = addr_bit; | |
6749 | } | |
6750 | ||
6751 | return print_address_bits; | |
6752 | } | |
0d381245 | 6753 | |
c4093a6a JM |
6754 | struct captured_breakpoint_query_args |
6755 | { | |
6756 | int bnum; | |
6757 | }; | |
c5aa993b | 6758 | |
c4093a6a | 6759 | static int |
2b65245e | 6760 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6761 | { |
9a3c8263 SM |
6762 | struct captured_breakpoint_query_args *args |
6763 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6764 | struct breakpoint *b; |
a6d9a66e | 6765 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6766 | |
c4093a6a JM |
6767 | ALL_BREAKPOINTS (b) |
6768 | { | |
6769 | if (args->bnum == b->number) | |
c5aa993b | 6770 | { |
12c5a436 | 6771 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6772 | return GDB_RC_OK; |
c5aa993b | 6773 | } |
c4093a6a JM |
6774 | } |
6775 | return GDB_RC_NONE; | |
6776 | } | |
c5aa993b | 6777 | |
c4093a6a | 6778 | enum gdb_rc |
4a64f543 MS |
6779 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6780 | char **error_message) | |
c4093a6a JM |
6781 | { |
6782 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6783 | |
c4093a6a JM |
6784 | args.bnum = bnum; |
6785 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6786 | an error. */ |
b0b13bb4 DJ |
6787 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6788 | error_message, RETURN_MASK_ALL) < 0) | |
6789 | return GDB_RC_FAIL; | |
6790 | else | |
6791 | return GDB_RC_OK; | |
c4093a6a | 6792 | } |
c5aa993b | 6793 | |
09d682a4 TT |
6794 | /* Return true if this breakpoint was set by the user, false if it is |
6795 | internal or momentary. */ | |
6796 | ||
6797 | int | |
6798 | user_breakpoint_p (struct breakpoint *b) | |
6799 | { | |
46c6471b | 6800 | return b->number > 0; |
09d682a4 TT |
6801 | } |
6802 | ||
7f3b0473 | 6803 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6804 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6805 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6806 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6807 | ones for which it returns non-zero. Return the total number of | |
6808 | breakpoints listed. */ | |
c906108c | 6809 | |
d77f58be | 6810 | static int |
e5a67952 | 6811 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6812 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6813 | { |
52f0bd74 | 6814 | struct breakpoint *b; |
a6d9a66e | 6815 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6816 | int nr_printable_breakpoints; |
3b31d625 | 6817 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6818 | struct value_print_options opts; |
a6d9a66e | 6819 | int print_address_bits = 0; |
269b11a2 | 6820 | int print_type_col_width = 14; |
79a45e25 | 6821 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6822 | |
79a45b7d TT |
6823 | get_user_print_options (&opts); |
6824 | ||
4a64f543 MS |
6825 | /* Compute the number of rows in the table, as well as the size |
6826 | required for address fields. */ | |
7f3b0473 AC |
6827 | nr_printable_breakpoints = 0; |
6828 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6829 | { |
6830 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6831 | if (filter && !filter (b)) | |
6832 | continue; | |
6833 | ||
6834 | /* If we have an "args" string, it is a list of breakpoints to | |
6835 | accept. Skip the others. */ | |
6836 | if (args != NULL && *args != '\0') | |
6837 | { | |
6838 | if (allflag && parse_and_eval_long (args) != b->number) | |
6839 | continue; | |
6840 | if (!allflag && !number_is_in_list (args, b->number)) | |
6841 | continue; | |
6842 | } | |
269b11a2 | 6843 | |
e5a67952 MS |
6844 | if (allflag || user_breakpoint_p (b)) |
6845 | { | |
6846 | int addr_bit, type_len; | |
a6d9a66e | 6847 | |
e5a67952 MS |
6848 | addr_bit = breakpoint_address_bits (b); |
6849 | if (addr_bit > print_address_bits) | |
6850 | print_address_bits = addr_bit; | |
269b11a2 | 6851 | |
e5a67952 MS |
6852 | type_len = strlen (bptype_string (b->type)); |
6853 | if (type_len > print_type_col_width) | |
6854 | print_type_col_width = type_len; | |
6855 | ||
6856 | nr_printable_breakpoints++; | |
6857 | } | |
6858 | } | |
7f3b0473 | 6859 | |
79a45b7d | 6860 | if (opts.addressprint) |
3b31d625 | 6861 | bkpttbl_chain |
3e43a32a MS |
6862 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6863 | nr_printable_breakpoints, | |
3b31d625 | 6864 | "BreakpointTable"); |
8b93c638 | 6865 | else |
3b31d625 | 6866 | bkpttbl_chain |
3e43a32a MS |
6867 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6868 | nr_printable_breakpoints, | |
3b31d625 | 6869 | "BreakpointTable"); |
8b93c638 | 6870 | |
7f3b0473 | 6871 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6872 | annotate_breakpoints_headers (); |
6873 | if (nr_printable_breakpoints > 0) | |
6874 | annotate_field (0); | |
4a64f543 | 6875 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6876 | if (nr_printable_breakpoints > 0) |
6877 | annotate_field (1); | |
269b11a2 | 6878 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6879 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6880 | if (nr_printable_breakpoints > 0) |
6881 | annotate_field (2); | |
4a64f543 | 6882 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6883 | if (nr_printable_breakpoints > 0) |
6884 | annotate_field (3); | |
54e52265 | 6885 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6886 | if (opts.addressprint) |
e5a67952 MS |
6887 | { |
6888 | if (nr_printable_breakpoints > 0) | |
6889 | annotate_field (4); | |
6890 | if (print_address_bits <= 32) | |
6891 | ui_out_table_header (uiout, 10, ui_left, | |
6892 | "addr", "Address"); /* 5 */ | |
6893 | else | |
6894 | ui_out_table_header (uiout, 18, ui_left, | |
6895 | "addr", "Address"); /* 5 */ | |
6896 | } | |
d7faa9e7 AC |
6897 | if (nr_printable_breakpoints > 0) |
6898 | annotate_field (5); | |
6899 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6900 | ui_out_table_body (uiout); | |
6901 | if (nr_printable_breakpoints > 0) | |
6902 | annotate_breakpoints_table (); | |
7f3b0473 | 6903 | |
c4093a6a | 6904 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6905 | { |
6906 | QUIT; | |
6907 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6908 | if (filter && !filter (b)) | |
6909 | continue; | |
6910 | ||
6911 | /* If we have an "args" string, it is a list of breakpoints to | |
6912 | accept. Skip the others. */ | |
6913 | ||
6914 | if (args != NULL && *args != '\0') | |
6915 | { | |
6916 | if (allflag) /* maintenance info breakpoint */ | |
6917 | { | |
6918 | if (parse_and_eval_long (args) != b->number) | |
6919 | continue; | |
6920 | } | |
6921 | else /* all others */ | |
6922 | { | |
6923 | if (!number_is_in_list (args, b->number)) | |
6924 | continue; | |
6925 | } | |
6926 | } | |
6927 | /* We only print out user settable breakpoints unless the | |
6928 | allflag is set. */ | |
6929 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6930 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6931 | } |
6932 | ||
3b31d625 | 6933 | do_cleanups (bkpttbl_chain); |
698384cd | 6934 | |
7f3b0473 | 6935 | if (nr_printable_breakpoints == 0) |
c906108c | 6936 | { |
4a64f543 MS |
6937 | /* If there's a filter, let the caller decide how to report |
6938 | empty list. */ | |
d77f58be SS |
6939 | if (!filter) |
6940 | { | |
e5a67952 | 6941 | if (args == NULL || *args == '\0') |
d77f58be SS |
6942 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6943 | else | |
4a64f543 | 6944 | ui_out_message (uiout, 0, |
e5a67952 MS |
6945 | "No breakpoint or watchpoint matching '%s'.\n", |
6946 | args); | |
d77f58be | 6947 | } |
c906108c SS |
6948 | } |
6949 | else | |
c4093a6a | 6950 | { |
a6d9a66e UW |
6951 | if (last_loc && !server_command) |
6952 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6953 | } |
c906108c | 6954 | |
4a64f543 | 6955 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6956 | there have been breakpoints? */ |
c906108c | 6957 | annotate_breakpoints_table_end (); |
d77f58be SS |
6958 | |
6959 | return nr_printable_breakpoints; | |
c906108c SS |
6960 | } |
6961 | ||
ad443146 SS |
6962 | /* Display the value of default-collect in a way that is generally |
6963 | compatible with the breakpoint list. */ | |
6964 | ||
6965 | static void | |
6966 | default_collect_info (void) | |
6967 | { | |
79a45e25 PA |
6968 | struct ui_out *uiout = current_uiout; |
6969 | ||
ad443146 SS |
6970 | /* If it has no value (which is frequently the case), say nothing; a |
6971 | message like "No default-collect." gets in user's face when it's | |
6972 | not wanted. */ | |
6973 | if (!*default_collect) | |
6974 | return; | |
6975 | ||
6976 | /* The following phrase lines up nicely with per-tracepoint collect | |
6977 | actions. */ | |
6978 | ui_out_text (uiout, "default collect "); | |
6979 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6980 | ui_out_text (uiout, " \n"); | |
6981 | } | |
6982 | ||
c906108c | 6983 | static void |
e5a67952 | 6984 | breakpoints_info (char *args, int from_tty) |
c906108c | 6985 | { |
e5a67952 | 6986 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6987 | |
6988 | default_collect_info (); | |
d77f58be SS |
6989 | } |
6990 | ||
6991 | static void | |
e5a67952 | 6992 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6993 | { |
e5a67952 | 6994 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6995 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6996 | |
6997 | if (num_printed == 0) | |
6998 | { | |
e5a67952 | 6999 | if (args == NULL || *args == '\0') |
d77f58be SS |
7000 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7001 | else | |
e5a67952 | 7002 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7003 | } |
c906108c SS |
7004 | } |
7005 | ||
7a292a7a | 7006 | static void |
e5a67952 | 7007 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7008 | { |
e5a67952 | 7009 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7010 | |
7011 | default_collect_info (); | |
c906108c SS |
7012 | } |
7013 | ||
0d381245 | 7014 | static int |
714835d5 | 7015 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7016 | struct program_space *pspace, |
714835d5 | 7017 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7018 | { |
7019 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7020 | |
0d381245 VP |
7021 | for (; bl; bl = bl->next) |
7022 | { | |
6c95b8df PA |
7023 | if (bl->pspace == pspace |
7024 | && bl->address == pc | |
0d381245 VP |
7025 | && (!overlay_debugging || bl->section == section)) |
7026 | return 1; | |
7027 | } | |
7028 | return 0; | |
7029 | } | |
7030 | ||
672f9b60 | 7031 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7032 | concerns with logical breakpoints, so we match program spaces, not |
7033 | address spaces. */ | |
c906108c SS |
7034 | |
7035 | static void | |
6c95b8df PA |
7036 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7037 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7038 | struct obj_section *section, int thread) |
c906108c | 7039 | { |
52f0bd74 AC |
7040 | int others = 0; |
7041 | struct breakpoint *b; | |
c906108c SS |
7042 | |
7043 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7044 | others += (user_breakpoint_p (b) |
7045 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7046 | if (others > 0) |
7047 | { | |
a3f17187 AC |
7048 | if (others == 1) |
7049 | printf_filtered (_("Note: breakpoint ")); | |
7050 | else /* if (others == ???) */ | |
7051 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7052 | ALL_BREAKPOINTS (b) |
672f9b60 | 7053 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7054 | { |
7055 | others--; | |
7056 | printf_filtered ("%d", b->number); | |
7057 | if (b->thread == -1 && thread != -1) | |
7058 | printf_filtered (" (all threads)"); | |
7059 | else if (b->thread != -1) | |
7060 | printf_filtered (" (thread %d)", b->thread); | |
7061 | printf_filtered ("%s%s ", | |
059fb39f | 7062 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7063 | || b->enable_state == bp_call_disabled) |
0d381245 | 7064 | ? " (disabled)" |
0d381245 VP |
7065 | : ""), |
7066 | (others > 1) ? "," | |
7067 | : ((others == 1) ? " and" : "")); | |
7068 | } | |
a3f17187 | 7069 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7070 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7071 | printf_filtered (".\n"); |
7072 | } | |
7073 | } | |
7074 | \f | |
c906108c | 7075 | |
e4f237da | 7076 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7077 | BPT locations. For some breakpoint types, the locations' address members |
7078 | are irrelevant and it makes no sense to attempt to compare them to other | |
7079 | addresses (or use them for any other purpose either). | |
e4f237da | 7080 | |
4a64f543 | 7081 | More specifically, each of the following breakpoint types will |
244558af | 7082 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7083 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7084 | breakpoint location at address zero: |
e4f237da KB |
7085 | |
7086 | bp_watchpoint | |
2d134ed3 PA |
7087 | bp_catchpoint |
7088 | ||
7089 | */ | |
e4f237da KB |
7090 | |
7091 | static int | |
7092 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7093 | { | |
7094 | enum bptype type = bpt->type; | |
7095 | ||
2d134ed3 PA |
7096 | return (type != bp_watchpoint && type != bp_catchpoint); |
7097 | } | |
7098 | ||
7099 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7100 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7101 | ||
7102 | static int | |
4a64f543 MS |
7103 | watchpoint_locations_match (struct bp_location *loc1, |
7104 | struct bp_location *loc2) | |
2d134ed3 | 7105 | { |
3a5c3e22 PA |
7106 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7107 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7108 | ||
7109 | /* Both of them must exist. */ | |
7110 | gdb_assert (w1 != NULL); | |
7111 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7112 | |
4a64f543 MS |
7113 | /* If the target can evaluate the condition expression in hardware, |
7114 | then we we need to insert both watchpoints even if they are at | |
7115 | the same place. Otherwise the watchpoint will only trigger when | |
7116 | the condition of whichever watchpoint was inserted evaluates to | |
7117 | true, not giving a chance for GDB to check the condition of the | |
7118 | other watchpoint. */ | |
3a5c3e22 | 7119 | if ((w1->cond_exp |
4a64f543 MS |
7120 | && target_can_accel_watchpoint_condition (loc1->address, |
7121 | loc1->length, | |
0cf6dd15 | 7122 | loc1->watchpoint_type, |
3a5c3e22 PA |
7123 | w1->cond_exp)) |
7124 | || (w2->cond_exp | |
4a64f543 MS |
7125 | && target_can_accel_watchpoint_condition (loc2->address, |
7126 | loc2->length, | |
0cf6dd15 | 7127 | loc2->watchpoint_type, |
3a5c3e22 | 7128 | w2->cond_exp))) |
0cf6dd15 TJB |
7129 | return 0; |
7130 | ||
85d721b8 PA |
7131 | /* Note that this checks the owner's type, not the location's. In |
7132 | case the target does not support read watchpoints, but does | |
7133 | support access watchpoints, we'll have bp_read_watchpoint | |
7134 | watchpoints with hw_access locations. Those should be considered | |
7135 | duplicates of hw_read locations. The hw_read locations will | |
7136 | become hw_access locations later. */ | |
2d134ed3 PA |
7137 | return (loc1->owner->type == loc2->owner->type |
7138 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7139 | && loc1->address == loc2->address | |
7140 | && loc1->length == loc2->length); | |
e4f237da KB |
7141 | } |
7142 | ||
31e77af2 | 7143 | /* See breakpoint.h. */ |
6c95b8df | 7144 | |
31e77af2 | 7145 | int |
6c95b8df PA |
7146 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7147 | struct address_space *aspace2, CORE_ADDR addr2) | |
7148 | { | |
f5656ead | 7149 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7150 | || aspace1 == aspace2) |
7151 | && addr1 == addr2); | |
7152 | } | |
7153 | ||
f1310107 TJB |
7154 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7155 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7156 | matches ASPACE2. On targets that have global breakpoints, the address | |
7157 | space doesn't really matter. */ | |
7158 | ||
7159 | static int | |
7160 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7161 | int len1, struct address_space *aspace2, | |
7162 | CORE_ADDR addr2) | |
7163 | { | |
f5656ead | 7164 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7165 | || aspace1 == aspace2) |
7166 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7167 | } | |
7168 | ||
7169 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7170 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7171 | matches the breakpoint's address space. On targets that have global | |
7172 | breakpoints, the address space doesn't really matter. */ | |
7173 | ||
7174 | static int | |
7175 | breakpoint_location_address_match (struct bp_location *bl, | |
7176 | struct address_space *aspace, | |
7177 | CORE_ADDR addr) | |
7178 | { | |
7179 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7180 | aspace, addr) | |
7181 | || (bl->length | |
7182 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7183 | bl->address, bl->length, | |
7184 | aspace, addr))); | |
7185 | } | |
7186 | ||
d35ae833 PA |
7187 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7188 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7189 | match happens only if ASPACE matches the breakpoint's address | |
7190 | space. On targets that have global breakpoints, the address space | |
7191 | doesn't really matter. */ | |
7192 | ||
7193 | static int | |
7194 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7195 | struct address_space *aspace, | |
7196 | CORE_ADDR addr, int len) | |
7197 | { | |
7198 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7199 | || bl->pspace->aspace == aspace) | |
7200 | { | |
7201 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7202 | ||
7203 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7204 | return 1; | |
7205 | } | |
7206 | return 0; | |
7207 | } | |
7208 | ||
1e4d1764 YQ |
7209 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7210 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7211 | true, otherwise returns false. */ | |
7212 | ||
7213 | static int | |
7214 | tracepoint_locations_match (struct bp_location *loc1, | |
7215 | struct bp_location *loc2) | |
7216 | { | |
7217 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7218 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7219 | locations at the same address of different tracepoints are regarded as | |
7220 | different locations. */ | |
7221 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7222 | else | |
7223 | return 0; | |
7224 | } | |
7225 | ||
2d134ed3 PA |
7226 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7227 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7228 | represent the same location. */ | |
7229 | ||
7230 | static int | |
4a64f543 MS |
7231 | breakpoint_locations_match (struct bp_location *loc1, |
7232 | struct bp_location *loc2) | |
2d134ed3 | 7233 | { |
2bdf28a0 JK |
7234 | int hw_point1, hw_point2; |
7235 | ||
7236 | /* Both of them must not be in moribund_locations. */ | |
7237 | gdb_assert (loc1->owner != NULL); | |
7238 | gdb_assert (loc2->owner != NULL); | |
7239 | ||
7240 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7241 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7242 | |
7243 | if (hw_point1 != hw_point2) | |
7244 | return 0; | |
7245 | else if (hw_point1) | |
7246 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7247 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7248 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7249 | else |
f1310107 TJB |
7250 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7251 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7252 | loc2->pspace->aspace, loc2->address) | |
7253 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7254 | } |
7255 | ||
76897487 KB |
7256 | static void |
7257 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7258 | int bnum, int have_bnum) | |
7259 | { | |
f63fbe86 MS |
7260 | /* The longest string possibly returned by hex_string_custom |
7261 | is 50 chars. These must be at least that big for safety. */ | |
7262 | char astr1[64]; | |
7263 | char astr2[64]; | |
76897487 | 7264 | |
bb599908 PH |
7265 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7266 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7267 | if (have_bnum) |
8a3fe4f8 | 7268 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7269 | bnum, astr1, astr2); |
7270 | else | |
8a3fe4f8 | 7271 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7272 | } |
7273 | ||
4a64f543 MS |
7274 | /* Adjust a breakpoint's address to account for architectural |
7275 | constraints on breakpoint placement. Return the adjusted address. | |
7276 | Note: Very few targets require this kind of adjustment. For most | |
7277 | targets, this function is simply the identity function. */ | |
76897487 KB |
7278 | |
7279 | static CORE_ADDR | |
a6d9a66e UW |
7280 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7281 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7282 | { |
a6d9a66e | 7283 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7284 | { |
7285 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7286 | return bpaddr; | |
7287 | } | |
88f7da05 KB |
7288 | else if (bptype == bp_watchpoint |
7289 | || bptype == bp_hardware_watchpoint | |
7290 | || bptype == bp_read_watchpoint | |
7291 | || bptype == bp_access_watchpoint | |
fe798b75 | 7292 | || bptype == bp_catchpoint) |
88f7da05 KB |
7293 | { |
7294 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7295 | have their addresses modified. */ | |
7296 | return bpaddr; | |
7297 | } | |
7c16b83e PA |
7298 | else if (bptype == bp_single_step) |
7299 | { | |
7300 | /* Single-step breakpoints should not have their addresses | |
7301 | modified. If there's any architectural constrain that | |
7302 | applies to this address, then it should have already been | |
7303 | taken into account when the breakpoint was created in the | |
7304 | first place. If we didn't do this, stepping through e.g., | |
7305 | Thumb-2 IT blocks would break. */ | |
7306 | return bpaddr; | |
7307 | } | |
76897487 KB |
7308 | else |
7309 | { | |
7310 | CORE_ADDR adjusted_bpaddr; | |
7311 | ||
7312 | /* Some targets have architectural constraints on the placement | |
7313 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7314 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7315 | |
7316 | /* An adjusted breakpoint address can significantly alter | |
7317 | a user's expectations. Print a warning if an adjustment | |
7318 | is required. */ | |
7319 | if (adjusted_bpaddr != bpaddr) | |
7320 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7321 | ||
7322 | return adjusted_bpaddr; | |
7323 | } | |
7324 | } | |
7325 | ||
28010a5d PA |
7326 | void |
7327 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7328 | struct breakpoint *owner) | |
7cc221ef | 7329 | { |
7cc221ef DJ |
7330 | memset (loc, 0, sizeof (*loc)); |
7331 | ||
348d480f PA |
7332 | gdb_assert (ops != NULL); |
7333 | ||
28010a5d PA |
7334 | loc->ops = ops; |
7335 | loc->owner = owner; | |
511a6cd4 | 7336 | loc->cond = NULL; |
b775012e | 7337 | loc->cond_bytecode = NULL; |
0d381245 VP |
7338 | loc->shlib_disabled = 0; |
7339 | loc->enabled = 1; | |
e049a4b5 | 7340 | |
28010a5d | 7341 | switch (owner->type) |
e049a4b5 DJ |
7342 | { |
7343 | case bp_breakpoint: | |
7c16b83e | 7344 | case bp_single_step: |
e049a4b5 DJ |
7345 | case bp_until: |
7346 | case bp_finish: | |
7347 | case bp_longjmp: | |
7348 | case bp_longjmp_resume: | |
e2e4d78b | 7349 | case bp_longjmp_call_dummy: |
186c406b TT |
7350 | case bp_exception: |
7351 | case bp_exception_resume: | |
e049a4b5 | 7352 | case bp_step_resume: |
2c03e5be | 7353 | case bp_hp_step_resume: |
e049a4b5 DJ |
7354 | case bp_watchpoint_scope: |
7355 | case bp_call_dummy: | |
aa7d318d | 7356 | case bp_std_terminate: |
e049a4b5 DJ |
7357 | case bp_shlib_event: |
7358 | case bp_thread_event: | |
7359 | case bp_overlay_event: | |
4efc6507 | 7360 | case bp_jit_event: |
0fd8e87f | 7361 | case bp_longjmp_master: |
aa7d318d | 7362 | case bp_std_terminate_master: |
186c406b | 7363 | case bp_exception_master: |
0e30163f JK |
7364 | case bp_gnu_ifunc_resolver: |
7365 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7366 | case bp_dprintf: |
e049a4b5 | 7367 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7368 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7369 | break; |
7370 | case bp_hardware_breakpoint: | |
7371 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7372 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7373 | break; |
7374 | case bp_hardware_watchpoint: | |
7375 | case bp_read_watchpoint: | |
7376 | case bp_access_watchpoint: | |
7377 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7378 | break; | |
7379 | case bp_watchpoint: | |
ce78b96d | 7380 | case bp_catchpoint: |
15c3d785 PA |
7381 | case bp_tracepoint: |
7382 | case bp_fast_tracepoint: | |
0fb4aa4b | 7383 | case bp_static_tracepoint: |
e049a4b5 DJ |
7384 | loc->loc_type = bp_loc_other; |
7385 | break; | |
7386 | default: | |
e2e0b3e5 | 7387 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7388 | } |
7389 | ||
f431efe5 | 7390 | loc->refc = 1; |
28010a5d PA |
7391 | } |
7392 | ||
7393 | /* Allocate a struct bp_location. */ | |
7394 | ||
7395 | static struct bp_location * | |
7396 | allocate_bp_location (struct breakpoint *bpt) | |
7397 | { | |
348d480f PA |
7398 | return bpt->ops->allocate_location (bpt); |
7399 | } | |
7cc221ef | 7400 | |
f431efe5 PA |
7401 | static void |
7402 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7403 | { |
348d480f | 7404 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7405 | xfree (loc); |
7406 | } | |
7407 | ||
f431efe5 PA |
7408 | /* Increment reference count. */ |
7409 | ||
7410 | static void | |
7411 | incref_bp_location (struct bp_location *bl) | |
7412 | { | |
7413 | ++bl->refc; | |
7414 | } | |
7415 | ||
7416 | /* Decrement reference count. If the reference count reaches 0, | |
7417 | destroy the bp_location. Sets *BLP to NULL. */ | |
7418 | ||
7419 | static void | |
7420 | decref_bp_location (struct bp_location **blp) | |
7421 | { | |
0807b50c PA |
7422 | gdb_assert ((*blp)->refc > 0); |
7423 | ||
f431efe5 PA |
7424 | if (--(*blp)->refc == 0) |
7425 | free_bp_location (*blp); | |
7426 | *blp = NULL; | |
7427 | } | |
7428 | ||
346774a9 | 7429 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7430 | |
346774a9 PA |
7431 | static void |
7432 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7433 | { |
346774a9 | 7434 | struct breakpoint *b1; |
c906108c | 7435 | |
346774a9 PA |
7436 | /* Add this breakpoint to the end of the chain so that a list of |
7437 | breakpoints will come out in order of increasing numbers. */ | |
7438 | ||
7439 | b1 = breakpoint_chain; | |
7440 | if (b1 == 0) | |
7441 | breakpoint_chain = b; | |
7442 | else | |
7443 | { | |
7444 | while (b1->next) | |
7445 | b1 = b1->next; | |
7446 | b1->next = b; | |
7447 | } | |
7448 | } | |
7449 | ||
7450 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7451 | ||
7452 | static void | |
7453 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7454 | struct gdbarch *gdbarch, | |
28010a5d | 7455 | enum bptype bptype, |
c0a91b2b | 7456 | const struct breakpoint_ops *ops) |
346774a9 | 7457 | { |
c906108c | 7458 | memset (b, 0, sizeof (*b)); |
2219d63c | 7459 | |
348d480f PA |
7460 | gdb_assert (ops != NULL); |
7461 | ||
28010a5d | 7462 | b->ops = ops; |
4d28f7a8 | 7463 | b->type = bptype; |
a6d9a66e | 7464 | b->gdbarch = gdbarch; |
c906108c SS |
7465 | b->language = current_language->la_language; |
7466 | b->input_radix = input_radix; | |
7467 | b->thread = -1; | |
b5de0fa7 | 7468 | b->enable_state = bp_enabled; |
c906108c SS |
7469 | b->next = 0; |
7470 | b->silent = 0; | |
7471 | b->ignore_count = 0; | |
7472 | b->commands = NULL; | |
818dd999 | 7473 | b->frame_id = null_frame_id; |
0d381245 | 7474 | b->condition_not_parsed = 0; |
84f4c1fe | 7475 | b->py_bp_object = NULL; |
d0fb5eae | 7476 | b->related_breakpoint = b; |
f00aae0f | 7477 | b->location = NULL; |
346774a9 PA |
7478 | } |
7479 | ||
7480 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7481 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7482 | |
7483 | static struct breakpoint * | |
7484 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7485 | enum bptype bptype, |
c0a91b2b | 7486 | const struct breakpoint_ops *ops) |
346774a9 PA |
7487 | { |
7488 | struct breakpoint *b = XNEW (struct breakpoint); | |
7489 | ||
348d480f | 7490 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7491 | add_to_breakpoint_chain (b); |
0d381245 VP |
7492 | return b; |
7493 | } | |
7494 | ||
0e30163f JK |
7495 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7496 | resolutions should be made as the user specified the location explicitly | |
7497 | enough. */ | |
7498 | ||
0d381245 | 7499 | static void |
0e30163f | 7500 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7501 | { |
2bdf28a0 JK |
7502 | gdb_assert (loc->owner != NULL); |
7503 | ||
0d381245 | 7504 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7505 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7506 | || is_tracepoint (loc->owner)) |
0d381245 | 7507 | { |
0e30163f | 7508 | int is_gnu_ifunc; |
2c02bd72 | 7509 | const char *function_name; |
6a3a010b | 7510 | CORE_ADDR func_addr; |
0e30163f | 7511 | |
2c02bd72 | 7512 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7513 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7514 | |
7515 | if (is_gnu_ifunc && !explicit_loc) | |
7516 | { | |
7517 | struct breakpoint *b = loc->owner; | |
7518 | ||
7519 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7520 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7521 | &loc->requested_address)) |
7522 | { | |
7523 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7524 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7525 | loc->requested_address, | |
7526 | b->type); | |
7527 | } | |
7528 | else if (b->type == bp_breakpoint && b->loc == loc | |
7529 | && loc->next == NULL && b->related_breakpoint == b) | |
7530 | { | |
7531 | /* Create only the whole new breakpoint of this type but do not | |
7532 | mess more complicated breakpoints with multiple locations. */ | |
7533 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7534 | /* Remember the resolver's address for use by the return |
7535 | breakpoint. */ | |
7536 | loc->related_address = func_addr; | |
0e30163f JK |
7537 | } |
7538 | } | |
7539 | ||
2c02bd72 DE |
7540 | if (function_name) |
7541 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7542 | } |
7543 | } | |
7544 | ||
a6d9a66e | 7545 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7546 | struct gdbarch * |
a6d9a66e UW |
7547 | get_sal_arch (struct symtab_and_line sal) |
7548 | { | |
7549 | if (sal.section) | |
7550 | return get_objfile_arch (sal.section->objfile); | |
7551 | if (sal.symtab) | |
eb822aa6 | 7552 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7553 | |
7554 | return NULL; | |
7555 | } | |
7556 | ||
346774a9 PA |
7557 | /* Low level routine for partially initializing a breakpoint of type |
7558 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7559 | file name, and line number are provided by SAL. |
0d381245 VP |
7560 | |
7561 | It is expected that the caller will complete the initialization of | |
7562 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7563 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7564 | |
346774a9 PA |
7565 | static void |
7566 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7567 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7568 | const struct breakpoint_ops *ops) |
0d381245 | 7569 | { |
28010a5d | 7570 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7571 | |
3742cc8b | 7572 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7573 | |
6c95b8df PA |
7574 | if (bptype != bp_catchpoint) |
7575 | gdb_assert (sal.pspace != NULL); | |
7576 | ||
f8eba3c6 TT |
7577 | /* Store the program space that was used to set the breakpoint, |
7578 | except for ordinary breakpoints, which are independent of the | |
7579 | program space. */ | |
7580 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7581 | b->pspace = sal.pspace; | |
346774a9 | 7582 | } |
c906108c | 7583 | |
346774a9 PA |
7584 | /* set_raw_breakpoint is a low level routine for allocating and |
7585 | partially initializing a breakpoint of type BPTYPE. The newly | |
7586 | created breakpoint's address, section, source file name, and line | |
7587 | number are provided by SAL. The newly created and partially | |
7588 | initialized breakpoint is added to the breakpoint chain and | |
7589 | is also returned as the value of this function. | |
7590 | ||
7591 | It is expected that the caller will complete the initialization of | |
7592 | the newly created breakpoint struct as well as output any status | |
7593 | information regarding the creation of a new breakpoint. In | |
7594 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7595 | number! Care should be taken to not allow an error to occur | |
7596 | prior to completing the initialization of the breakpoint. If this | |
7597 | should happen, a bogus breakpoint will be left on the chain. */ | |
7598 | ||
7599 | struct breakpoint * | |
7600 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7601 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7602 | const struct breakpoint_ops *ops) |
346774a9 PA |
7603 | { |
7604 | struct breakpoint *b = XNEW (struct breakpoint); | |
7605 | ||
348d480f | 7606 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7607 | add_to_breakpoint_chain (b); |
c906108c SS |
7608 | return b; |
7609 | } | |
7610 | ||
53a5351d | 7611 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7612 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7613 | initiated the operation. */ | |
c906108c SS |
7614 | |
7615 | void | |
186c406b | 7616 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7617 | { |
35df4500 | 7618 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7619 | int thread = tp->global_num; |
0fd8e87f UW |
7620 | |
7621 | /* To avoid having to rescan all objfile symbols at every step, | |
7622 | we maintain a list of continually-inserted but always disabled | |
7623 | longjmp "master" breakpoints. Here, we simply create momentary | |
7624 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7625 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7626 | if (b->pspace == current_program_space |
186c406b TT |
7627 | && (b->type == bp_longjmp_master |
7628 | || b->type == bp_exception_master)) | |
0fd8e87f | 7629 | { |
06edf0c0 PA |
7630 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7631 | struct breakpoint *clone; | |
cc59ec59 | 7632 | |
e2e4d78b JK |
7633 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7634 | after their removal. */ | |
06edf0c0 | 7635 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7636 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7637 | clone->thread = thread; |
7638 | } | |
186c406b TT |
7639 | |
7640 | tp->initiating_frame = frame; | |
c906108c SS |
7641 | } |
7642 | ||
611c83ae | 7643 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7644 | void |
611c83ae | 7645 | delete_longjmp_breakpoint (int thread) |
c906108c | 7646 | { |
35df4500 | 7647 | struct breakpoint *b, *b_tmp; |
c906108c | 7648 | |
35df4500 | 7649 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7650 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7651 | { |
7652 | if (b->thread == thread) | |
7653 | delete_breakpoint (b); | |
7654 | } | |
c906108c SS |
7655 | } |
7656 | ||
f59f708a PA |
7657 | void |
7658 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7659 | { | |
7660 | struct breakpoint *b, *b_tmp; | |
7661 | ||
7662 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7663 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7664 | { | |
7665 | if (b->thread == thread) | |
7666 | b->disposition = disp_del_at_next_stop; | |
7667 | } | |
7668 | } | |
7669 | ||
e2e4d78b JK |
7670 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7671 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7672 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7673 | breakpoints. */ | |
7674 | ||
7675 | struct breakpoint * | |
7676 | set_longjmp_breakpoint_for_call_dummy (void) | |
7677 | { | |
7678 | struct breakpoint *b, *retval = NULL; | |
7679 | ||
7680 | ALL_BREAKPOINTS (b) | |
7681 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7682 | { | |
7683 | struct breakpoint *new_b; | |
7684 | ||
7685 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7686 | &momentary_breakpoint_ops, |
7687 | 1); | |
5d5658a1 | 7688 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7689 | |
7690 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7691 | ||
7692 | gdb_assert (new_b->related_breakpoint == new_b); | |
7693 | if (retval == NULL) | |
7694 | retval = new_b; | |
7695 | new_b->related_breakpoint = retval; | |
7696 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7697 | retval = retval->related_breakpoint; | |
7698 | retval->related_breakpoint = new_b; | |
7699 | } | |
7700 | ||
7701 | return retval; | |
7702 | } | |
7703 | ||
7704 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7705 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7706 | stack. |
7707 | ||
7708 | You should call this function only at places where it is safe to currently | |
7709 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7710 | frames. */ | |
7711 | ||
7712 | void | |
b67a2c6f | 7713 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7714 | { |
7715 | struct breakpoint *b, *b_tmp; | |
7716 | ||
7717 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7718 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7719 | { |
7720 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7721 | ||
7722 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7723 | dummy_b = dummy_b->related_breakpoint; | |
7724 | if (dummy_b->type != bp_call_dummy | |
7725 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7726 | continue; | |
7727 | ||
b67a2c6f | 7728 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7729 | |
7730 | while (b->related_breakpoint != b) | |
7731 | { | |
7732 | if (b_tmp == b->related_breakpoint) | |
7733 | b_tmp = b->related_breakpoint->next; | |
7734 | delete_breakpoint (b->related_breakpoint); | |
7735 | } | |
7736 | delete_breakpoint (b); | |
7737 | } | |
7738 | } | |
7739 | ||
1900040c MS |
7740 | void |
7741 | enable_overlay_breakpoints (void) | |
7742 | { | |
52f0bd74 | 7743 | struct breakpoint *b; |
1900040c MS |
7744 | |
7745 | ALL_BREAKPOINTS (b) | |
7746 | if (b->type == bp_overlay_event) | |
7747 | { | |
7748 | b->enable_state = bp_enabled; | |
44702360 | 7749 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7750 | overlay_events_enabled = 1; |
1900040c MS |
7751 | } |
7752 | } | |
7753 | ||
7754 | void | |
7755 | disable_overlay_breakpoints (void) | |
7756 | { | |
52f0bd74 | 7757 | struct breakpoint *b; |
1900040c MS |
7758 | |
7759 | ALL_BREAKPOINTS (b) | |
7760 | if (b->type == bp_overlay_event) | |
7761 | { | |
7762 | b->enable_state = bp_disabled; | |
44702360 | 7763 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7764 | overlay_events_enabled = 0; |
1900040c MS |
7765 | } |
7766 | } | |
7767 | ||
aa7d318d TT |
7768 | /* Set an active std::terminate breakpoint for each std::terminate |
7769 | master breakpoint. */ | |
7770 | void | |
7771 | set_std_terminate_breakpoint (void) | |
7772 | { | |
35df4500 | 7773 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7774 | |
35df4500 | 7775 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7776 | if (b->pspace == current_program_space |
7777 | && b->type == bp_std_terminate_master) | |
7778 | { | |
06edf0c0 | 7779 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7780 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7781 | } |
7782 | } | |
7783 | ||
7784 | /* Delete all the std::terminate breakpoints. */ | |
7785 | void | |
7786 | delete_std_terminate_breakpoint (void) | |
7787 | { | |
35df4500 | 7788 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7789 | |
35df4500 | 7790 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7791 | if (b->type == bp_std_terminate) |
7792 | delete_breakpoint (b); | |
7793 | } | |
7794 | ||
c4093a6a | 7795 | struct breakpoint * |
a6d9a66e | 7796 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7797 | { |
7798 | struct breakpoint *b; | |
c4093a6a | 7799 | |
06edf0c0 PA |
7800 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7801 | &internal_breakpoint_ops); | |
7802 | ||
b5de0fa7 | 7803 | b->enable_state = bp_enabled; |
f00aae0f | 7804 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7805 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7806 | |
44702360 | 7807 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7808 | |
c4093a6a JM |
7809 | return b; |
7810 | } | |
7811 | ||
0101ce28 JJ |
7812 | struct lang_and_radix |
7813 | { | |
7814 | enum language lang; | |
7815 | int radix; | |
7816 | }; | |
7817 | ||
4efc6507 DE |
7818 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7819 | ||
7820 | struct breakpoint * | |
7821 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7822 | { | |
2a7f3dff PA |
7823 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7824 | &internal_breakpoint_ops); | |
4efc6507 | 7825 | } |
0101ce28 | 7826 | |
03673fc7 PP |
7827 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7828 | ||
7829 | void | |
7830 | remove_jit_event_breakpoints (void) | |
7831 | { | |
7832 | struct breakpoint *b, *b_tmp; | |
7833 | ||
7834 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7835 | if (b->type == bp_jit_event | |
7836 | && b->loc->pspace == current_program_space) | |
7837 | delete_breakpoint (b); | |
7838 | } | |
7839 | ||
cae688ec JJ |
7840 | void |
7841 | remove_solib_event_breakpoints (void) | |
7842 | { | |
35df4500 | 7843 | struct breakpoint *b, *b_tmp; |
cae688ec | 7844 | |
35df4500 | 7845 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7846 | if (b->type == bp_shlib_event |
7847 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7848 | delete_breakpoint (b); |
7849 | } | |
7850 | ||
f37f681c PA |
7851 | /* See breakpoint.h. */ |
7852 | ||
7853 | void | |
7854 | remove_solib_event_breakpoints_at_next_stop (void) | |
7855 | { | |
7856 | struct breakpoint *b, *b_tmp; | |
7857 | ||
7858 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7859 | if (b->type == bp_shlib_event | |
7860 | && b->loc->pspace == current_program_space) | |
7861 | b->disposition = disp_del_at_next_stop; | |
7862 | } | |
7863 | ||
04086b45 PA |
7864 | /* Helper for create_solib_event_breakpoint / |
7865 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7866 | INSERT_MODE to pass through to update_global_location_list. */ | |
7867 | ||
7868 | static struct breakpoint * | |
7869 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7870 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7871 | { |
7872 | struct breakpoint *b; | |
7873 | ||
06edf0c0 PA |
7874 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7875 | &internal_breakpoint_ops); | |
04086b45 | 7876 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7877 | return b; |
7878 | } | |
7879 | ||
04086b45 PA |
7880 | struct breakpoint * |
7881 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7882 | { | |
7883 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7884 | } | |
7885 | ||
f37f681c PA |
7886 | /* See breakpoint.h. */ |
7887 | ||
7888 | struct breakpoint * | |
7889 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7890 | { | |
7891 | struct breakpoint *b; | |
7892 | ||
04086b45 PA |
7893 | /* Explicitly tell update_global_location_list to insert |
7894 | locations. */ | |
7895 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7896 | if (!b->loc->inserted) |
7897 | { | |
7898 | delete_breakpoint (b); | |
7899 | return NULL; | |
7900 | } | |
7901 | return b; | |
7902 | } | |
7903 | ||
cae688ec JJ |
7904 | /* Disable any breakpoints that are on code in shared libraries. Only |
7905 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7906 | ||
7907 | void | |
cb851954 | 7908 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7909 | { |
876fa593 | 7910 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7911 | |
876fa593 | 7912 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7913 | { |
2bdf28a0 | 7914 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7915 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7916 | |
4a64f543 MS |
7917 | /* We apply the check to all breakpoints, including disabled for |
7918 | those with loc->duplicate set. This is so that when breakpoint | |
7919 | becomes enabled, or the duplicate is removed, gdb will try to | |
7920 | insert all breakpoints. If we don't set shlib_disabled here, | |
7921 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7922 | if (((b->type == bp_breakpoint) |
508ccb1f | 7923 | || (b->type == bp_jit_event) |
1042e4c0 | 7924 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7925 | || (is_tracepoint (b))) |
6c95b8df | 7926 | && loc->pspace == current_program_space |
0d381245 | 7927 | && !loc->shlib_disabled |
6c95b8df | 7928 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7929 | ) |
0d381245 VP |
7930 | { |
7931 | loc->shlib_disabled = 1; | |
7932 | } | |
cae688ec JJ |
7933 | } |
7934 | } | |
7935 | ||
63644780 NB |
7936 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7937 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7938 | disabled ones can just stay disabled. */ | |
84acb35a | 7939 | |
75149521 | 7940 | static void |
84acb35a JJ |
7941 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7942 | { | |
876fa593 | 7943 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7944 | int disabled_shlib_breaks = 0; |
7945 | ||
c86cf029 VP |
7946 | /* SunOS a.out shared libraries are always mapped, so do not |
7947 | disable breakpoints; they will only be reported as unloaded | |
7948 | through clear_solib when GDB discards its shared library | |
7949 | list. See clear_solib for more information. */ | |
7950 | if (exec_bfd != NULL | |
7951 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7952 | return; | |
7953 | ||
876fa593 | 7954 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7955 | { |
2bdf28a0 | 7956 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7957 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7958 | |
1e4d1764 | 7959 | if (solib->pspace == loc->pspace |
e2dd7057 | 7960 | && !loc->shlib_disabled |
1e4d1764 YQ |
7961 | && (((b->type == bp_breakpoint |
7962 | || b->type == bp_jit_event | |
7963 | || b->type == bp_hardware_breakpoint) | |
7964 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7965 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7966 | || is_tracepoint (b)) | |
e2dd7057 | 7967 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7968 | { |
e2dd7057 PP |
7969 | loc->shlib_disabled = 1; |
7970 | /* At this point, we cannot rely on remove_breakpoint | |
7971 | succeeding so we must mark the breakpoint as not inserted | |
7972 | to prevent future errors occurring in remove_breakpoints. */ | |
7973 | loc->inserted = 0; | |
8d3788bd VP |
7974 | |
7975 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7976 | observer_notify_breakpoint_modified (b); | |
7977 | ||
e2dd7057 PP |
7978 | if (!disabled_shlib_breaks) |
7979 | { | |
7980 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7981 | warning (_("Temporarily disabling breakpoints " |
7982 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7983 | solib->so_name); |
84acb35a | 7984 | } |
e2dd7057 | 7985 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7986 | } |
7987 | } | |
84acb35a JJ |
7988 | } |
7989 | ||
63644780 NB |
7990 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7991 | notification of free_objfile. Only apply to enabled breakpoints, | |
7992 | disabled ones can just stay disabled. */ | |
7993 | ||
7994 | static void | |
7995 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7996 | { | |
7997 | struct breakpoint *b; | |
7998 | ||
7999 | if (objfile == NULL) | |
8000 | return; | |
8001 | ||
d03de421 PA |
8002 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8003 | managed by the user with add-symbol-file/remove-symbol-file. | |
8004 | Similarly to how breakpoints in shared libraries are handled in | |
8005 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8006 | shlib_disabled so they end up uninserted on the next global |
8007 | location list update. Shared libraries not loaded by the user | |
8008 | aren't handled here -- they're already handled in | |
8009 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8010 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8011 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8012 | main objfile). */ | |
8013 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8014 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8015 | return; |
8016 | ||
8017 | ALL_BREAKPOINTS (b) | |
8018 | { | |
8019 | struct bp_location *loc; | |
8020 | int bp_modified = 0; | |
8021 | ||
8022 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8023 | continue; | |
8024 | ||
8025 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8026 | { | |
8027 | CORE_ADDR loc_addr = loc->address; | |
8028 | ||
8029 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8030 | && loc->loc_type != bp_loc_software_breakpoint) | |
8031 | continue; | |
8032 | ||
8033 | if (loc->shlib_disabled != 0) | |
8034 | continue; | |
8035 | ||
8036 | if (objfile->pspace != loc->pspace) | |
8037 | continue; | |
8038 | ||
8039 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8040 | && loc->loc_type != bp_loc_software_breakpoint) | |
8041 | continue; | |
8042 | ||
8043 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8044 | { | |
8045 | loc->shlib_disabled = 1; | |
08351840 PA |
8046 | /* At this point, we don't know whether the object was |
8047 | unmapped from the inferior or not, so leave the | |
8048 | inserted flag alone. We'll handle failure to | |
8049 | uninsert quietly, in case the object was indeed | |
8050 | unmapped. */ | |
63644780 NB |
8051 | |
8052 | mark_breakpoint_location_modified (loc); | |
8053 | ||
8054 | bp_modified = 1; | |
8055 | } | |
8056 | } | |
8057 | ||
8058 | if (bp_modified) | |
8059 | observer_notify_breakpoint_modified (b); | |
8060 | } | |
8061 | } | |
8062 | ||
ce78b96d JB |
8063 | /* FORK & VFORK catchpoints. */ |
8064 | ||
e29a4733 PA |
8065 | /* An instance of this type is used to represent a fork or vfork |
8066 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8067 | class; users downcast to "struct breakpoint *" when needed. A | |
8068 | breakpoint is really of this type iff its ops pointer points to | |
8069 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8070 | ||
8071 | struct fork_catchpoint | |
8072 | { | |
8073 | /* The base class. */ | |
8074 | struct breakpoint base; | |
8075 | ||
8076 | /* Process id of a child process whose forking triggered this | |
8077 | catchpoint. This field is only valid immediately after this | |
8078 | catchpoint has triggered. */ | |
8079 | ptid_t forked_inferior_pid; | |
8080 | }; | |
8081 | ||
4a64f543 MS |
8082 | /* Implement the "insert" breakpoint_ops method for fork |
8083 | catchpoints. */ | |
ce78b96d | 8084 | |
77b06cd7 TJB |
8085 | static int |
8086 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8087 | { |
dfd4cc63 | 8088 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8089 | } |
8090 | ||
4a64f543 MS |
8091 | /* Implement the "remove" breakpoint_ops method for fork |
8092 | catchpoints. */ | |
ce78b96d JB |
8093 | |
8094 | static int | |
77b06cd7 | 8095 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 8096 | { |
dfd4cc63 | 8097 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8098 | } |
8099 | ||
8100 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8101 | catchpoints. */ | |
8102 | ||
8103 | static int | |
f1310107 | 8104 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8105 | struct address_space *aspace, CORE_ADDR bp_addr, |
8106 | const struct target_waitstatus *ws) | |
ce78b96d | 8107 | { |
e29a4733 PA |
8108 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8109 | ||
f90263c1 TT |
8110 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8111 | return 0; | |
8112 | ||
8113 | c->forked_inferior_pid = ws->value.related_pid; | |
8114 | return 1; | |
ce78b96d JB |
8115 | } |
8116 | ||
4a64f543 MS |
8117 | /* Implement the "print_it" breakpoint_ops method for fork |
8118 | catchpoints. */ | |
ce78b96d JB |
8119 | |
8120 | static enum print_stop_action | |
348d480f | 8121 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8122 | { |
36dfb11c | 8123 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8124 | struct breakpoint *b = bs->breakpoint_at; |
8125 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8126 | |
ce78b96d | 8127 | annotate_catchpoint (b->number); |
f303dbd6 | 8128 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8129 | if (b->disposition == disp_del) |
f303dbd6 | 8130 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8131 | else |
f303dbd6 | 8132 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8133 | if (ui_out_is_mi_like_p (uiout)) |
8134 | { | |
8135 | ui_out_field_string (uiout, "reason", | |
8136 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8137 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8138 | } | |
8139 | ui_out_field_int (uiout, "bkptno", b->number); | |
8140 | ui_out_text (uiout, " (forked process "); | |
8141 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8142 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8143 | return PRINT_SRC_AND_LOC; |
8144 | } | |
8145 | ||
4a64f543 MS |
8146 | /* Implement the "print_one" breakpoint_ops method for fork |
8147 | catchpoints. */ | |
ce78b96d JB |
8148 | |
8149 | static void | |
a6d9a66e | 8150 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8151 | { |
e29a4733 | 8152 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8153 | struct value_print_options opts; |
79a45e25 | 8154 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8155 | |
8156 | get_user_print_options (&opts); | |
8157 | ||
4a64f543 MS |
8158 | /* Field 4, the address, is omitted (which makes the columns not |
8159 | line up too nicely with the headers, but the effect is relatively | |
8160 | readable). */ | |
79a45b7d | 8161 | if (opts.addressprint) |
ce78b96d JB |
8162 | ui_out_field_skip (uiout, "addr"); |
8163 | annotate_field (5); | |
8164 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8165 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8166 | { |
8167 | ui_out_text (uiout, ", process "); | |
8168 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8169 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8170 | ui_out_spaces (uiout, 1); |
8171 | } | |
8ac3646f TT |
8172 | |
8173 | if (ui_out_is_mi_like_p (uiout)) | |
8174 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8175 | } |
8176 | ||
8177 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8178 | catchpoints. */ | |
8179 | ||
8180 | static void | |
8181 | print_mention_catch_fork (struct breakpoint *b) | |
8182 | { | |
8183 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8184 | } | |
8185 | ||
6149aea9 PA |
8186 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8187 | catchpoints. */ | |
8188 | ||
8189 | static void | |
8190 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8191 | { | |
8192 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8193 | print_recreate_thread (b, fp); |
6149aea9 PA |
8194 | } |
8195 | ||
ce78b96d JB |
8196 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8197 | ||
2060206e | 8198 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8199 | |
4a64f543 MS |
8200 | /* Implement the "insert" breakpoint_ops method for vfork |
8201 | catchpoints. */ | |
ce78b96d | 8202 | |
77b06cd7 TJB |
8203 | static int |
8204 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8205 | { |
dfd4cc63 | 8206 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8207 | } |
8208 | ||
4a64f543 MS |
8209 | /* Implement the "remove" breakpoint_ops method for vfork |
8210 | catchpoints. */ | |
ce78b96d JB |
8211 | |
8212 | static int | |
77b06cd7 | 8213 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8214 | { |
dfd4cc63 | 8215 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8216 | } |
8217 | ||
8218 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8219 | catchpoints. */ | |
8220 | ||
8221 | static int | |
f1310107 | 8222 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8223 | struct address_space *aspace, CORE_ADDR bp_addr, |
8224 | const struct target_waitstatus *ws) | |
ce78b96d | 8225 | { |
e29a4733 PA |
8226 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8227 | ||
f90263c1 TT |
8228 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8229 | return 0; | |
8230 | ||
8231 | c->forked_inferior_pid = ws->value.related_pid; | |
8232 | return 1; | |
ce78b96d JB |
8233 | } |
8234 | ||
4a64f543 MS |
8235 | /* Implement the "print_it" breakpoint_ops method for vfork |
8236 | catchpoints. */ | |
ce78b96d JB |
8237 | |
8238 | static enum print_stop_action | |
348d480f | 8239 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8240 | { |
36dfb11c | 8241 | struct ui_out *uiout = current_uiout; |
348d480f | 8242 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8243 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8244 | ||
ce78b96d | 8245 | annotate_catchpoint (b->number); |
f303dbd6 | 8246 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8247 | if (b->disposition == disp_del) |
f303dbd6 | 8248 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8249 | else |
f303dbd6 | 8250 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8251 | if (ui_out_is_mi_like_p (uiout)) |
8252 | { | |
8253 | ui_out_field_string (uiout, "reason", | |
8254 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8255 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8256 | } | |
8257 | ui_out_field_int (uiout, "bkptno", b->number); | |
8258 | ui_out_text (uiout, " (vforked process "); | |
8259 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8260 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8261 | return PRINT_SRC_AND_LOC; |
8262 | } | |
8263 | ||
4a64f543 MS |
8264 | /* Implement the "print_one" breakpoint_ops method for vfork |
8265 | catchpoints. */ | |
ce78b96d JB |
8266 | |
8267 | static void | |
a6d9a66e | 8268 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8269 | { |
e29a4733 | 8270 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8271 | struct value_print_options opts; |
79a45e25 | 8272 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8273 | |
8274 | get_user_print_options (&opts); | |
4a64f543 MS |
8275 | /* Field 4, the address, is omitted (which makes the columns not |
8276 | line up too nicely with the headers, but the effect is relatively | |
8277 | readable). */ | |
79a45b7d | 8278 | if (opts.addressprint) |
ce78b96d JB |
8279 | ui_out_field_skip (uiout, "addr"); |
8280 | annotate_field (5); | |
8281 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8282 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8283 | { |
8284 | ui_out_text (uiout, ", process "); | |
8285 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8286 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8287 | ui_out_spaces (uiout, 1); |
8288 | } | |
8ac3646f TT |
8289 | |
8290 | if (ui_out_is_mi_like_p (uiout)) | |
8291 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8292 | } |
8293 | ||
8294 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8295 | catchpoints. */ | |
8296 | ||
8297 | static void | |
8298 | print_mention_catch_vfork (struct breakpoint *b) | |
8299 | { | |
8300 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8301 | } | |
8302 | ||
6149aea9 PA |
8303 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8304 | catchpoints. */ | |
8305 | ||
8306 | static void | |
8307 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8308 | { | |
8309 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8310 | print_recreate_thread (b, fp); |
6149aea9 PA |
8311 | } |
8312 | ||
ce78b96d JB |
8313 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8314 | ||
2060206e | 8315 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8316 | |
edcc5120 TT |
8317 | /* An instance of this type is used to represent an solib catchpoint. |
8318 | It includes a "struct breakpoint" as a kind of base class; users | |
8319 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8320 | really of this type iff its ops pointer points to | |
8321 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8322 | ||
8323 | struct solib_catchpoint | |
8324 | { | |
8325 | /* The base class. */ | |
8326 | struct breakpoint base; | |
8327 | ||
8328 | /* True for "catch load", false for "catch unload". */ | |
8329 | unsigned char is_load; | |
8330 | ||
8331 | /* Regular expression to match, if any. COMPILED is only valid when | |
8332 | REGEX is non-NULL. */ | |
8333 | char *regex; | |
8334 | regex_t compiled; | |
8335 | }; | |
8336 | ||
8337 | static void | |
8338 | dtor_catch_solib (struct breakpoint *b) | |
8339 | { | |
8340 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8341 | ||
8342 | if (self->regex) | |
8343 | regfree (&self->compiled); | |
8344 | xfree (self->regex); | |
8345 | ||
8346 | base_breakpoint_ops.dtor (b); | |
8347 | } | |
8348 | ||
8349 | static int | |
8350 | insert_catch_solib (struct bp_location *ignore) | |
8351 | { | |
8352 | return 0; | |
8353 | } | |
8354 | ||
8355 | static int | |
8356 | remove_catch_solib (struct bp_location *ignore) | |
8357 | { | |
8358 | return 0; | |
8359 | } | |
8360 | ||
8361 | static int | |
8362 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8363 | struct address_space *aspace, | |
8364 | CORE_ADDR bp_addr, | |
8365 | const struct target_waitstatus *ws) | |
8366 | { | |
8367 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8368 | struct breakpoint *other; | |
8369 | ||
8370 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8371 | return 1; | |
8372 | ||
8373 | ALL_BREAKPOINTS (other) | |
8374 | { | |
8375 | struct bp_location *other_bl; | |
8376 | ||
8377 | if (other == bl->owner) | |
8378 | continue; | |
8379 | ||
8380 | if (other->type != bp_shlib_event) | |
8381 | continue; | |
8382 | ||
8383 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8384 | continue; | |
8385 | ||
8386 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8387 | { | |
8388 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8389 | return 1; | |
8390 | } | |
8391 | } | |
8392 | ||
8393 | return 0; | |
8394 | } | |
8395 | ||
8396 | static void | |
8397 | check_status_catch_solib (struct bpstats *bs) | |
8398 | { | |
8399 | struct solib_catchpoint *self | |
8400 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8401 | int ix; | |
8402 | ||
8403 | if (self->is_load) | |
8404 | { | |
8405 | struct so_list *iter; | |
8406 | ||
8407 | for (ix = 0; | |
8408 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8409 | ix, iter); | |
8410 | ++ix) | |
8411 | { | |
8412 | if (!self->regex | |
8413 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8414 | return; | |
8415 | } | |
8416 | } | |
8417 | else | |
8418 | { | |
8419 | char *iter; | |
8420 | ||
8421 | for (ix = 0; | |
8422 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8423 | ix, iter); | |
8424 | ++ix) | |
8425 | { | |
8426 | if (!self->regex | |
8427 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8428 | return; | |
8429 | } | |
8430 | } | |
8431 | ||
8432 | bs->stop = 0; | |
8433 | bs->print_it = print_it_noop; | |
8434 | } | |
8435 | ||
8436 | static enum print_stop_action | |
8437 | print_it_catch_solib (bpstat bs) | |
8438 | { | |
8439 | struct breakpoint *b = bs->breakpoint_at; | |
8440 | struct ui_out *uiout = current_uiout; | |
8441 | ||
8442 | annotate_catchpoint (b->number); | |
f303dbd6 | 8443 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8444 | if (b->disposition == disp_del) |
f303dbd6 | 8445 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8446 | else |
f303dbd6 | 8447 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8448 | ui_out_field_int (uiout, "bkptno", b->number); |
8449 | ui_out_text (uiout, "\n"); | |
8450 | if (ui_out_is_mi_like_p (uiout)) | |
8451 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8452 | print_solib_event (1); | |
8453 | return PRINT_SRC_AND_LOC; | |
8454 | } | |
8455 | ||
8456 | static void | |
8457 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8458 | { | |
8459 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8460 | struct value_print_options opts; | |
8461 | struct ui_out *uiout = current_uiout; | |
8462 | char *msg; | |
8463 | ||
8464 | get_user_print_options (&opts); | |
8465 | /* Field 4, the address, is omitted (which makes the columns not | |
8466 | line up too nicely with the headers, but the effect is relatively | |
8467 | readable). */ | |
8468 | if (opts.addressprint) | |
8469 | { | |
8470 | annotate_field (4); | |
8471 | ui_out_field_skip (uiout, "addr"); | |
8472 | } | |
8473 | ||
8474 | annotate_field (5); | |
8475 | if (self->is_load) | |
8476 | { | |
8477 | if (self->regex) | |
8478 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8479 | else | |
8480 | msg = xstrdup (_("load of library")); | |
8481 | } | |
8482 | else | |
8483 | { | |
8484 | if (self->regex) | |
8485 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8486 | else | |
8487 | msg = xstrdup (_("unload of library")); | |
8488 | } | |
8489 | ui_out_field_string (uiout, "what", msg); | |
8490 | xfree (msg); | |
8ac3646f TT |
8491 | |
8492 | if (ui_out_is_mi_like_p (uiout)) | |
8493 | ui_out_field_string (uiout, "catch-type", | |
8494 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8495 | } |
8496 | ||
8497 | static void | |
8498 | print_mention_catch_solib (struct breakpoint *b) | |
8499 | { | |
8500 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8501 | ||
8502 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8503 | self->is_load ? "load" : "unload"); | |
8504 | } | |
8505 | ||
8506 | static void | |
8507 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8508 | { | |
8509 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8510 | ||
8511 | fprintf_unfiltered (fp, "%s %s", | |
8512 | b->disposition == disp_del ? "tcatch" : "catch", | |
8513 | self->is_load ? "load" : "unload"); | |
8514 | if (self->regex) | |
8515 | fprintf_unfiltered (fp, " %s", self->regex); | |
8516 | fprintf_unfiltered (fp, "\n"); | |
8517 | } | |
8518 | ||
8519 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8520 | ||
91985142 MG |
8521 | /* Shared helper function (MI and CLI) for creating and installing |
8522 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8523 | the events to be caught are load events, otherwise they are | |
8524 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8525 | temporary one. If ENABLED is non-zero the catchpoint is | |
8526 | created in an enabled state. */ | |
edcc5120 | 8527 | |
91985142 MG |
8528 | void |
8529 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8530 | { |
8531 | struct solib_catchpoint *c; | |
8532 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8533 | struct cleanup *cleanup; |
8534 | ||
edcc5120 TT |
8535 | if (!arg) |
8536 | arg = ""; | |
8537 | arg = skip_spaces (arg); | |
8538 | ||
8539 | c = XCNEW (struct solib_catchpoint); | |
8540 | cleanup = make_cleanup (xfree, c); | |
8541 | ||
8542 | if (*arg != '\0') | |
8543 | { | |
8544 | int errcode; | |
8545 | ||
8546 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8547 | if (errcode != 0) | |
8548 | { | |
8549 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8550 | ||
8551 | make_cleanup (xfree, err); | |
8552 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8553 | } | |
8554 | c->regex = xstrdup (arg); | |
8555 | } | |
8556 | ||
8557 | c->is_load = is_load; | |
91985142 | 8558 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8559 | &catch_solib_breakpoint_ops); |
8560 | ||
91985142 MG |
8561 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8562 | ||
edcc5120 TT |
8563 | discard_cleanups (cleanup); |
8564 | install_breakpoint (0, &c->base, 1); | |
8565 | } | |
8566 | ||
91985142 MG |
8567 | /* A helper function that does all the work for "catch load" and |
8568 | "catch unload". */ | |
8569 | ||
8570 | static void | |
8571 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8572 | struct cmd_list_element *command) | |
8573 | { | |
8574 | int tempflag; | |
8575 | const int enabled = 1; | |
8576 | ||
8577 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8578 | ||
8579 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8580 | } | |
8581 | ||
edcc5120 TT |
8582 | static void |
8583 | catch_load_command_1 (char *arg, int from_tty, | |
8584 | struct cmd_list_element *command) | |
8585 | { | |
8586 | catch_load_or_unload (arg, from_tty, 1, command); | |
8587 | } | |
8588 | ||
8589 | static void | |
8590 | catch_unload_command_1 (char *arg, int from_tty, | |
8591 | struct cmd_list_element *command) | |
8592 | { | |
8593 | catch_load_or_unload (arg, from_tty, 0, command); | |
8594 | } | |
8595 | ||
346774a9 PA |
8596 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8597 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8598 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8599 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8600 | |
ab04a2af | 8601 | void |
346774a9 PA |
8602 | init_catchpoint (struct breakpoint *b, |
8603 | struct gdbarch *gdbarch, int tempflag, | |
8604 | char *cond_string, | |
c0a91b2b | 8605 | const struct breakpoint_ops *ops) |
c906108c | 8606 | { |
c5aa993b | 8607 | struct symtab_and_line sal; |
346774a9 | 8608 | |
fe39c653 | 8609 | init_sal (&sal); |
6c95b8df | 8610 | sal.pspace = current_program_space; |
c5aa993b | 8611 | |
28010a5d | 8612 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8613 | |
1b36a34b | 8614 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8615 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8616 | } |
8617 | ||
28010a5d | 8618 | void |
3ea46bff | 8619 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8620 | { |
8621 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8622 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8623 | if (is_tracepoint (b)) |
8624 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8625 | if (!internal) |
8626 | mention (b); | |
c56053d2 | 8627 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8628 | |
8629 | if (update_gll) | |
44702360 | 8630 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8631 | } |
8632 | ||
9b70b993 | 8633 | static void |
a6d9a66e UW |
8634 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8635 | int tempflag, char *cond_string, | |
c0a91b2b | 8636 | const struct breakpoint_ops *ops) |
c906108c | 8637 | { |
e29a4733 | 8638 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8639 | |
e29a4733 PA |
8640 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8641 | ||
8642 | c->forked_inferior_pid = null_ptid; | |
8643 | ||
3ea46bff | 8644 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8645 | } |
8646 | ||
fe798b75 JB |
8647 | /* Exec catchpoints. */ |
8648 | ||
b4d90040 PA |
8649 | /* An instance of this type is used to represent an exec catchpoint. |
8650 | It includes a "struct breakpoint" as a kind of base class; users | |
8651 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8652 | really of this type iff its ops pointer points to | |
8653 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8654 | ||
8655 | struct exec_catchpoint | |
8656 | { | |
8657 | /* The base class. */ | |
8658 | struct breakpoint base; | |
8659 | ||
8660 | /* Filename of a program whose exec triggered this catchpoint. | |
8661 | This field is only valid immediately after this catchpoint has | |
8662 | triggered. */ | |
8663 | char *exec_pathname; | |
8664 | }; | |
8665 | ||
8666 | /* Implement the "dtor" breakpoint_ops method for exec | |
8667 | catchpoints. */ | |
8668 | ||
8669 | static void | |
8670 | dtor_catch_exec (struct breakpoint *b) | |
8671 | { | |
8672 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8673 | ||
8674 | xfree (c->exec_pathname); | |
348d480f | 8675 | |
2060206e | 8676 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8677 | } |
8678 | ||
77b06cd7 TJB |
8679 | static int |
8680 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8681 | { |
dfd4cc63 | 8682 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8683 | } |
c906108c | 8684 | |
fe798b75 | 8685 | static int |
77b06cd7 | 8686 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8687 | { |
dfd4cc63 | 8688 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8689 | } |
c906108c | 8690 | |
fe798b75 | 8691 | static int |
f1310107 | 8692 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8693 | struct address_space *aspace, CORE_ADDR bp_addr, |
8694 | const struct target_waitstatus *ws) | |
fe798b75 | 8695 | { |
b4d90040 PA |
8696 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8697 | ||
f90263c1 TT |
8698 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8699 | return 0; | |
8700 | ||
8701 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8702 | return 1; | |
fe798b75 | 8703 | } |
c906108c | 8704 | |
fe798b75 | 8705 | static enum print_stop_action |
348d480f | 8706 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8707 | { |
36dfb11c | 8708 | struct ui_out *uiout = current_uiout; |
348d480f | 8709 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8710 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8711 | ||
fe798b75 | 8712 | annotate_catchpoint (b->number); |
f303dbd6 | 8713 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8714 | if (b->disposition == disp_del) |
f303dbd6 | 8715 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8716 | else |
f303dbd6 | 8717 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8718 | if (ui_out_is_mi_like_p (uiout)) |
8719 | { | |
8720 | ui_out_field_string (uiout, "reason", | |
8721 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8722 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8723 | } | |
8724 | ui_out_field_int (uiout, "bkptno", b->number); | |
8725 | ui_out_text (uiout, " (exec'd "); | |
8726 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8727 | ui_out_text (uiout, "), "); | |
8728 | ||
fe798b75 | 8729 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8730 | } |
8731 | ||
fe798b75 | 8732 | static void |
a6d9a66e | 8733 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8734 | { |
b4d90040 | 8735 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8736 | struct value_print_options opts; |
79a45e25 | 8737 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8738 | |
8739 | get_user_print_options (&opts); | |
8740 | ||
8741 | /* Field 4, the address, is omitted (which makes the columns | |
8742 | not line up too nicely with the headers, but the effect | |
8743 | is relatively readable). */ | |
8744 | if (opts.addressprint) | |
8745 | ui_out_field_skip (uiout, "addr"); | |
8746 | annotate_field (5); | |
8747 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8748 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8749 | { |
8750 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8751 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8752 | ui_out_text (uiout, "\" "); |
8753 | } | |
8ac3646f TT |
8754 | |
8755 | if (ui_out_is_mi_like_p (uiout)) | |
8756 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8757 | } |
8758 | ||
8759 | static void | |
8760 | print_mention_catch_exec (struct breakpoint *b) | |
8761 | { | |
8762 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8763 | } | |
8764 | ||
6149aea9 PA |
8765 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8766 | catchpoints. */ | |
8767 | ||
8768 | static void | |
8769 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8770 | { | |
8771 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8772 | print_recreate_thread (b, fp); |
6149aea9 PA |
8773 | } |
8774 | ||
2060206e | 8775 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8776 | |
c906108c | 8777 | static int |
fba45db2 | 8778 | hw_breakpoint_used_count (void) |
c906108c | 8779 | { |
c906108c | 8780 | int i = 0; |
f1310107 TJB |
8781 | struct breakpoint *b; |
8782 | struct bp_location *bl; | |
c906108c SS |
8783 | |
8784 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8785 | { |
d6b74ac4 | 8786 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8787 | for (bl = b->loc; bl; bl = bl->next) |
8788 | { | |
8789 | /* Special types of hardware breakpoints may use more than | |
8790 | one register. */ | |
348d480f | 8791 | i += b->ops->resources_needed (bl); |
f1310107 | 8792 | } |
c5aa993b | 8793 | } |
c906108c SS |
8794 | |
8795 | return i; | |
8796 | } | |
8797 | ||
a1398e0c PA |
8798 | /* Returns the resources B would use if it were a hardware |
8799 | watchpoint. */ | |
8800 | ||
c906108c | 8801 | static int |
a1398e0c | 8802 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8803 | { |
c906108c | 8804 | int i = 0; |
e09342b5 | 8805 | struct bp_location *bl; |
c906108c | 8806 | |
a1398e0c PA |
8807 | if (!breakpoint_enabled (b)) |
8808 | return 0; | |
8809 | ||
8810 | for (bl = b->loc; bl; bl = bl->next) | |
8811 | { | |
8812 | /* Special types of hardware watchpoints may use more than | |
8813 | one register. */ | |
8814 | i += b->ops->resources_needed (bl); | |
8815 | } | |
8816 | ||
8817 | return i; | |
8818 | } | |
8819 | ||
8820 | /* Returns the sum the used resources of all hardware watchpoints of | |
8821 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8822 | the sum of the used resources of all hardware watchpoints of other | |
8823 | types _not_ TYPE. */ | |
8824 | ||
8825 | static int | |
8826 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8827 | enum bptype type, int *other_type_used) | |
8828 | { | |
8829 | int i = 0; | |
8830 | struct breakpoint *b; | |
8831 | ||
c906108c SS |
8832 | *other_type_used = 0; |
8833 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8834 | { |
a1398e0c PA |
8835 | if (b == except) |
8836 | continue; | |
e09342b5 TJB |
8837 | if (!breakpoint_enabled (b)) |
8838 | continue; | |
8839 | ||
a1398e0c PA |
8840 | if (b->type == type) |
8841 | i += hw_watchpoint_use_count (b); | |
8842 | else if (is_hardware_watchpoint (b)) | |
8843 | *other_type_used = 1; | |
e09342b5 TJB |
8844 | } |
8845 | ||
c906108c SS |
8846 | return i; |
8847 | } | |
8848 | ||
c906108c | 8849 | void |
fba45db2 | 8850 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8851 | { |
c5aa993b | 8852 | struct breakpoint *b; |
c906108c SS |
8853 | |
8854 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8855 | { |
cc60f2e3 | 8856 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8857 | { |
b5de0fa7 | 8858 | b->enable_state = bp_call_disabled; |
44702360 | 8859 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8860 | } |
8861 | } | |
c906108c SS |
8862 | } |
8863 | ||
8864 | void | |
fba45db2 | 8865 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8866 | { |
c5aa993b | 8867 | struct breakpoint *b; |
c906108c SS |
8868 | |
8869 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8870 | { |
cc60f2e3 | 8871 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8872 | { |
b5de0fa7 | 8873 | b->enable_state = bp_enabled; |
44702360 | 8874 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8875 | } |
8876 | } | |
c906108c SS |
8877 | } |
8878 | ||
8bea4e01 UW |
8879 | void |
8880 | disable_breakpoints_before_startup (void) | |
8881 | { | |
6c95b8df | 8882 | current_program_space->executing_startup = 1; |
44702360 | 8883 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8884 | } |
8885 | ||
8886 | void | |
8887 | enable_breakpoints_after_startup (void) | |
8888 | { | |
6c95b8df | 8889 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8890 | breakpoint_re_set (); |
8bea4e01 UW |
8891 | } |
8892 | ||
7c16b83e PA |
8893 | /* Create a new single-step breakpoint for thread THREAD, with no |
8894 | locations. */ | |
c906108c | 8895 | |
7c16b83e PA |
8896 | static struct breakpoint * |
8897 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8898 | { | |
8899 | struct breakpoint *b = XNEW (struct breakpoint); | |
8900 | ||
8901 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8902 | &momentary_breakpoint_ops); | |
8903 | ||
8904 | b->disposition = disp_donttouch; | |
8905 | b->frame_id = null_frame_id; | |
8906 | ||
8907 | b->thread = thread; | |
8908 | gdb_assert (b->thread != 0); | |
8909 | ||
8910 | add_to_breakpoint_chain (b); | |
8911 | ||
8912 | return b; | |
8913 | } | |
8914 | ||
8915 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8916 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8917 | frame. */ | |
c906108c SS |
8918 | |
8919 | struct breakpoint * | |
a6d9a66e UW |
8920 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8921 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8922 | { |
52f0bd74 | 8923 | struct breakpoint *b; |
edb3359d | 8924 | |
193facb3 JK |
8925 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8926 | tail-called one. */ | |
8927 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8928 | |
06edf0c0 | 8929 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8930 | b->enable_state = bp_enabled; |
8931 | b->disposition = disp_donttouch; | |
818dd999 | 8932 | b->frame_id = frame_id; |
c906108c | 8933 | |
4a64f543 MS |
8934 | /* If we're debugging a multi-threaded program, then we want |
8935 | momentary breakpoints to be active in only a single thread of | |
8936 | control. */ | |
39f77062 | 8937 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8938 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8939 | |
44702360 | 8940 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8941 | |
c906108c SS |
8942 | return b; |
8943 | } | |
611c83ae | 8944 | |
06edf0c0 | 8945 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8946 | The new breakpoint will have type TYPE, use OPS as its |
8947 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8948 | |
06edf0c0 PA |
8949 | static struct breakpoint * |
8950 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8951 | enum bptype type, | |
a1aa2221 LM |
8952 | const struct breakpoint_ops *ops, |
8953 | int loc_enabled) | |
e58b0e63 PA |
8954 | { |
8955 | struct breakpoint *copy; | |
8956 | ||
06edf0c0 | 8957 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8958 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8959 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8960 | |
a6d9a66e | 8961 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8962 | copy->loc->requested_address = orig->loc->requested_address; |
8963 | copy->loc->address = orig->loc->address; | |
8964 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8965 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8966 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8967 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8968 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8969 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8970 | copy->frame_id = orig->frame_id; |
8971 | copy->thread = orig->thread; | |
6c95b8df | 8972 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8973 | |
8974 | copy->enable_state = bp_enabled; | |
8975 | copy->disposition = disp_donttouch; | |
8976 | copy->number = internal_breakpoint_number--; | |
8977 | ||
44702360 | 8978 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8979 | return copy; |
8980 | } | |
8981 | ||
06edf0c0 PA |
8982 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8983 | ORIG is NULL. */ | |
8984 | ||
8985 | struct breakpoint * | |
8986 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8987 | { | |
8988 | /* If there's nothing to clone, then return nothing. */ | |
8989 | if (orig == NULL) | |
8990 | return NULL; | |
8991 | ||
a1aa2221 | 8992 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8993 | } |
8994 | ||
611c83ae | 8995 | struct breakpoint * |
a6d9a66e UW |
8996 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8997 | enum bptype type) | |
611c83ae PA |
8998 | { |
8999 | struct symtab_and_line sal; | |
9000 | ||
9001 | sal = find_pc_line (pc, 0); | |
9002 | sal.pc = pc; | |
9003 | sal.section = find_pc_overlay (pc); | |
9004 | sal.explicit_pc = 1; | |
9005 | ||
a6d9a66e | 9006 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9007 | } |
c906108c | 9008 | \f |
c5aa993b | 9009 | |
c906108c SS |
9010 | /* Tell the user we have just set a breakpoint B. */ |
9011 | ||
9012 | static void | |
fba45db2 | 9013 | mention (struct breakpoint *b) |
c906108c | 9014 | { |
348d480f | 9015 | b->ops->print_mention (b); |
79a45e25 | 9016 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9017 | return; |
c906108c SS |
9018 | printf_filtered ("\n"); |
9019 | } | |
c906108c | 9020 | \f |
c5aa993b | 9021 | |
1a853c52 PA |
9022 | static int bp_loc_is_permanent (struct bp_location *loc); |
9023 | ||
0d381245 | 9024 | static struct bp_location * |
39d61571 | 9025 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9026 | const struct symtab_and_line *sal) |
9027 | { | |
9028 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9029 | CORE_ADDR adjusted_address; |
9030 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9031 | ||
9032 | if (loc_gdbarch == NULL) | |
9033 | loc_gdbarch = b->gdbarch; | |
9034 | ||
9035 | /* Adjust the breakpoint's address prior to allocating a location. | |
9036 | Once we call allocate_bp_location(), that mostly uninitialized | |
9037 | location will be placed on the location chain. Adjustment of the | |
9038 | breakpoint may cause target_read_memory() to be called and we do | |
9039 | not want its scan of the location chain to find a breakpoint and | |
9040 | location that's only been partially initialized. */ | |
9041 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9042 | sal->pc, b->type); | |
0d381245 | 9043 | |
d30113d4 | 9044 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9045 | loc = allocate_bp_location (b); |
d30113d4 JK |
9046 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9047 | tmp = &((*tmp)->next)) | |
0d381245 | 9048 | ; |
d30113d4 | 9049 | loc->next = *tmp; |
0d381245 | 9050 | *tmp = loc; |
3742cc8b | 9051 | |
0d381245 | 9052 | loc->requested_address = sal->pc; |
3742cc8b | 9053 | loc->address = adjusted_address; |
6c95b8df | 9054 | loc->pspace = sal->pspace; |
729662a5 TT |
9055 | loc->probe.probe = sal->probe; |
9056 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9057 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9058 | loc->section = sal->section; |
3742cc8b | 9059 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9060 | loc->line_number = sal->line; |
2f202fde | 9061 | loc->symtab = sal->symtab; |
f8eba3c6 | 9062 | |
0e30163f JK |
9063 | set_breakpoint_location_function (loc, |
9064 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9065 | |
6ae88661 LM |
9066 | /* While by definition, permanent breakpoints are already present in the |
9067 | code, we don't mark the location as inserted. Normally one would expect | |
9068 | that GDB could rely on that breakpoint instruction to stop the program, | |
9069 | thus removing the need to insert its own breakpoint, except that executing | |
9070 | the breakpoint instruction can kill the target instead of reporting a | |
9071 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9072 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9073 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9074 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9075 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9076 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9077 | it manually increments the PC, thus avoiding executing the breakpoint | |
9078 | instruction.) */ | |
1a853c52 | 9079 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9080 | loc->permanent = 1; |
1a853c52 | 9081 | |
0d381245 VP |
9082 | return loc; |
9083 | } | |
514f746b AR |
9084 | \f |
9085 | ||
1cf4d951 | 9086 | /* See breakpoint.h. */ |
514f746b | 9087 | |
1cf4d951 PA |
9088 | int |
9089 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9090 | { |
9091 | int len; | |
9092 | CORE_ADDR addr; | |
1afeeb75 | 9093 | const gdb_byte *bpoint; |
514f746b | 9094 | gdb_byte *target_mem; |
939c61fa JK |
9095 | struct cleanup *cleanup; |
9096 | int retval = 0; | |
514f746b | 9097 | |
1cf4d951 PA |
9098 | addr = address; |
9099 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9100 | ||
9101 | /* Software breakpoints unsupported? */ | |
9102 | if (bpoint == NULL) | |
9103 | return 0; | |
9104 | ||
224c3ddb | 9105 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9106 | |
9107 | /* Enable the automatic memory restoration from breakpoints while | |
9108 | we read the memory. Otherwise we could say about our temporary | |
9109 | breakpoints they are permanent. */ | |
9110 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9111 | ||
9112 | if (target_read_memory (address, target_mem, len) == 0 | |
9113 | && memcmp (target_mem, bpoint, len) == 0) | |
9114 | retval = 1; | |
9115 | ||
9116 | do_cleanups (cleanup); | |
9117 | ||
9118 | return retval; | |
9119 | } | |
9120 | ||
9121 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9122 | return 0 otherwise. */ | |
9123 | ||
9124 | static int | |
9125 | bp_loc_is_permanent (struct bp_location *loc) | |
9126 | { | |
9127 | struct cleanup *cleanup; | |
9128 | int retval; | |
9129 | ||
514f746b AR |
9130 | gdb_assert (loc != NULL); |
9131 | ||
244558af LM |
9132 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9133 | attempt to read from the addresses the locations of these breakpoint types | |
9134 | point to. program_breakpoint_here_p, below, will attempt to read | |
9135 | memory. */ | |
9136 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9137 | return 0; | |
9138 | ||
6c95b8df | 9139 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9140 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9141 | |
1cf4d951 | 9142 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9143 | |
939c61fa JK |
9144 | do_cleanups (cleanup); |
9145 | ||
9146 | return retval; | |
514f746b AR |
9147 | } |
9148 | ||
e7e0cddf SS |
9149 | /* Build a command list for the dprintf corresponding to the current |
9150 | settings of the dprintf style options. */ | |
9151 | ||
9152 | static void | |
9153 | update_dprintf_command_list (struct breakpoint *b) | |
9154 | { | |
9155 | char *dprintf_args = b->extra_string; | |
9156 | char *printf_line = NULL; | |
9157 | ||
9158 | if (!dprintf_args) | |
9159 | return; | |
9160 | ||
9161 | dprintf_args = skip_spaces (dprintf_args); | |
9162 | ||
9163 | /* Allow a comma, as it may have terminated a location, but don't | |
9164 | insist on it. */ | |
9165 | if (*dprintf_args == ',') | |
9166 | ++dprintf_args; | |
9167 | dprintf_args = skip_spaces (dprintf_args); | |
9168 | ||
9169 | if (*dprintf_args != '"') | |
9170 | error (_("Bad format string, missing '\"'.")); | |
9171 | ||
d3ce09f5 | 9172 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9173 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9174 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9175 | { |
9176 | if (!dprintf_function) | |
9177 | error (_("No function supplied for dprintf call")); | |
9178 | ||
9179 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9180 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9181 | dprintf_function, | |
9182 | dprintf_channel, | |
9183 | dprintf_args); | |
9184 | else | |
9185 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9186 | dprintf_function, | |
9187 | dprintf_args); | |
9188 | } | |
d3ce09f5 SS |
9189 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9190 | { | |
9191 | if (target_can_run_breakpoint_commands ()) | |
9192 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9193 | else | |
9194 | { | |
9195 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9196 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9197 | } | |
9198 | } | |
e7e0cddf SS |
9199 | else |
9200 | internal_error (__FILE__, __LINE__, | |
9201 | _("Invalid dprintf style.")); | |
9202 | ||
f28045c2 | 9203 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9204 | /* Manufacture a printf sequence. */ |
f28045c2 | 9205 | { |
8d749320 | 9206 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9207 | |
f28045c2 YQ |
9208 | printf_cmd_line->control_type = simple_control; |
9209 | printf_cmd_line->body_count = 0; | |
9210 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9211 | printf_cmd_line->next = NULL; |
f28045c2 | 9212 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9213 | |
f28045c2 YQ |
9214 | breakpoint_set_commands (b, printf_cmd_line); |
9215 | } | |
e7e0cddf SS |
9216 | } |
9217 | ||
9218 | /* Update all dprintf commands, making their command lists reflect | |
9219 | current style settings. */ | |
9220 | ||
9221 | static void | |
9222 | update_dprintf_commands (char *args, int from_tty, | |
9223 | struct cmd_list_element *c) | |
9224 | { | |
9225 | struct breakpoint *b; | |
9226 | ||
9227 | ALL_BREAKPOINTS (b) | |
9228 | { | |
9229 | if (b->type == bp_dprintf) | |
9230 | update_dprintf_command_list (b); | |
9231 | } | |
9232 | } | |
c3f6f71d | 9233 | |
f00aae0f KS |
9234 | /* Create a breakpoint with SAL as location. Use LOCATION |
9235 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9236 | as condition expression. If LOCATION is NULL then create an |
9237 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9238 | |
9239 | static void | |
d9b3f62e | 9240 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9241 | struct symtabs_and_lines sals, |
9242 | struct event_location *location, | |
f8eba3c6 | 9243 | char *filter, char *cond_string, |
e7e0cddf | 9244 | char *extra_string, |
d9b3f62e PA |
9245 | enum bptype type, enum bpdisp disposition, |
9246 | int thread, int task, int ignore_count, | |
c0a91b2b | 9247 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9248 | int enabled, int internal, unsigned flags, |
9249 | int display_canonical) | |
018d34a4 | 9250 | { |
0d381245 | 9251 | int i; |
018d34a4 VP |
9252 | |
9253 | if (type == bp_hardware_breakpoint) | |
9254 | { | |
fbbd034e AS |
9255 | int target_resources_ok; |
9256 | ||
9257 | i = hw_breakpoint_used_count (); | |
9258 | target_resources_ok = | |
9259 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9260 | i + 1, 0); |
9261 | if (target_resources_ok == 0) | |
9262 | error (_("No hardware breakpoint support in the target.")); | |
9263 | else if (target_resources_ok < 0) | |
9264 | error (_("Hardware breakpoints used exceeds limit.")); | |
9265 | } | |
9266 | ||
6c95b8df PA |
9267 | gdb_assert (sals.nelts > 0); |
9268 | ||
0d381245 VP |
9269 | for (i = 0; i < sals.nelts; ++i) |
9270 | { | |
9271 | struct symtab_and_line sal = sals.sals[i]; | |
9272 | struct bp_location *loc; | |
9273 | ||
9274 | if (from_tty) | |
5af949e3 UW |
9275 | { |
9276 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9277 | if (!loc_gdbarch) | |
9278 | loc_gdbarch = gdbarch; | |
9279 | ||
9280 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9281 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9282 | } |
0d381245 VP |
9283 | |
9284 | if (i == 0) | |
9285 | { | |
d9b3f62e | 9286 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9287 | b->thread = thread; |
4a306c9a | 9288 | b->task = task; |
855a6e68 | 9289 | |
0d381245 | 9290 | b->cond_string = cond_string; |
e7e0cddf | 9291 | b->extra_string = extra_string; |
0d381245 | 9292 | b->ignore_count = ignore_count; |
41447f92 | 9293 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9294 | b->disposition = disposition; |
6c95b8df | 9295 | |
44f238bb PA |
9296 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9297 | b->loc->inserted = 1; | |
9298 | ||
0fb4aa4b PA |
9299 | if (type == bp_static_tracepoint) |
9300 | { | |
d9b3f62e | 9301 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9302 | struct static_tracepoint_marker marker; |
9303 | ||
983af33b | 9304 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9305 | { |
9306 | /* We already know the marker exists, otherwise, we | |
9307 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9308 | const char *p = &event_location_to_string (b->location)[3]; |
9309 | const char *endp; | |
0fb4aa4b | 9310 | char *marker_str; |
0fb4aa4b | 9311 | |
f00aae0f | 9312 | p = skip_spaces_const (p); |
0fb4aa4b | 9313 | |
f00aae0f | 9314 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9315 | |
9316 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9317 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9318 | |
3e43a32a MS |
9319 | printf_filtered (_("Probed static tracepoint " |
9320 | "marker \"%s\"\n"), | |
d9b3f62e | 9321 | t->static_trace_marker_id); |
0fb4aa4b PA |
9322 | } |
9323 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9324 | { | |
d9b3f62e | 9325 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9326 | release_static_tracepoint_marker (&marker); |
9327 | ||
3e43a32a MS |
9328 | printf_filtered (_("Probed static tracepoint " |
9329 | "marker \"%s\"\n"), | |
d9b3f62e | 9330 | t->static_trace_marker_id); |
0fb4aa4b PA |
9331 | } |
9332 | else | |
3e43a32a MS |
9333 | warning (_("Couldn't determine the static " |
9334 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9335 | } |
9336 | ||
0d381245 VP |
9337 | loc = b->loc; |
9338 | } | |
9339 | else | |
018d34a4 | 9340 | { |
39d61571 | 9341 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9342 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9343 | loc->inserted = 1; | |
0d381245 VP |
9344 | } |
9345 | ||
9346 | if (b->cond_string) | |
9347 | { | |
bbc13ae3 KS |
9348 | const char *arg = b->cond_string; |
9349 | ||
1bb9788d TT |
9350 | loc->cond = parse_exp_1 (&arg, loc->address, |
9351 | block_for_pc (loc->address), 0); | |
0d381245 | 9352 | if (*arg) |
588ae58c | 9353 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9354 | } |
e7e0cddf SS |
9355 | |
9356 | /* Dynamic printf requires and uses additional arguments on the | |
9357 | command line, otherwise it's an error. */ | |
9358 | if (type == bp_dprintf) | |
9359 | { | |
9360 | if (b->extra_string) | |
9361 | update_dprintf_command_list (b); | |
9362 | else | |
9363 | error (_("Format string required")); | |
9364 | } | |
9365 | else if (b->extra_string) | |
588ae58c | 9366 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9367 | } |
018d34a4 | 9368 | |
56435ebe | 9369 | b->display_canonical = display_canonical; |
f00aae0f KS |
9370 | if (location != NULL) |
9371 | b->location = location; | |
018d34a4 | 9372 | else |
305e13e6 JB |
9373 | { |
9374 | const char *addr_string = NULL; | |
9375 | int addr_string_len = 0; | |
9376 | ||
9377 | if (location != NULL) | |
9378 | addr_string = event_location_to_string (location); | |
9379 | if (addr_string != NULL) | |
9380 | addr_string_len = strlen (addr_string); | |
9381 | ||
9382 | b->location = new_address_location (b->loc->address, | |
9383 | addr_string, addr_string_len); | |
9384 | } | |
f8eba3c6 | 9385 | b->filter = filter; |
d9b3f62e | 9386 | } |
018d34a4 | 9387 | |
d9b3f62e PA |
9388 | static void |
9389 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9390 | struct symtabs_and_lines sals, |
9391 | struct event_location *location, | |
f8eba3c6 | 9392 | char *filter, char *cond_string, |
e7e0cddf | 9393 | char *extra_string, |
d9b3f62e PA |
9394 | enum bptype type, enum bpdisp disposition, |
9395 | int thread, int task, int ignore_count, | |
c0a91b2b | 9396 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9397 | int enabled, int internal, unsigned flags, |
9398 | int display_canonical) | |
d9b3f62e PA |
9399 | { |
9400 | struct breakpoint *b; | |
9401 | struct cleanup *old_chain; | |
9402 | ||
9403 | if (is_tracepoint_type (type)) | |
9404 | { | |
9405 | struct tracepoint *t; | |
9406 | ||
9407 | t = XCNEW (struct tracepoint); | |
9408 | b = &t->base; | |
9409 | } | |
9410 | else | |
9411 | b = XNEW (struct breakpoint); | |
9412 | ||
9413 | old_chain = make_cleanup (xfree, b); | |
9414 | ||
9415 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9416 | sals, location, |
e7e0cddf | 9417 | filter, cond_string, extra_string, |
d9b3f62e PA |
9418 | type, disposition, |
9419 | thread, task, ignore_count, | |
9420 | ops, from_tty, | |
44f238bb PA |
9421 | enabled, internal, flags, |
9422 | display_canonical); | |
d9b3f62e PA |
9423 | discard_cleanups (old_chain); |
9424 | ||
3ea46bff | 9425 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9426 | } |
9427 | ||
9428 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9429 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9430 | value. COND_STRING, if not NULL, specified the condition to be | |
9431 | used for all breakpoints. Essentially the only case where | |
9432 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9433 | function. In that case, it's still not possible to specify | |
9434 | separate conditions for different overloaded functions, so | |
9435 | we take just a single condition string. | |
9436 | ||
c3f6f71d | 9437 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9438 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9439 | array contents). If the function fails (error() is called), the |
9440 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9441 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9442 | |
9443 | static void | |
8cdf0e15 | 9444 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9445 | struct linespec_result *canonical, |
e7e0cddf | 9446 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9447 | enum bptype type, enum bpdisp disposition, |
9448 | int thread, int task, int ignore_count, | |
c0a91b2b | 9449 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9450 | int enabled, int internal, unsigned flags) |
c906108c | 9451 | { |
018d34a4 | 9452 | int i; |
f8eba3c6 | 9453 | struct linespec_sals *lsal; |
cc59ec59 | 9454 | |
f8eba3c6 TT |
9455 | if (canonical->pre_expanded) |
9456 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9457 | ||
9458 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9459 | { |
f00aae0f | 9460 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9461 | 'break', without arguments. */ |
f00aae0f KS |
9462 | struct event_location *location |
9463 | = (canonical->location != NULL | |
9464 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9465 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9466 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9467 | |
f8eba3c6 TT |
9468 | make_cleanup (xfree, filter_string); |
9469 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9470 | location, |
f8eba3c6 | 9471 | filter_string, |
e7e0cddf SS |
9472 | cond_string, extra_string, |
9473 | type, disposition, | |
84f4c1fe | 9474 | thread, task, ignore_count, ops, |
44f238bb | 9475 | from_tty, enabled, internal, flags, |
56435ebe | 9476 | canonical->special_display); |
f8eba3c6 | 9477 | discard_cleanups (inner); |
c3f6f71d | 9478 | } |
c3f6f71d | 9479 | } |
c906108c | 9480 | |
f00aae0f | 9481 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9482 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9483 | addresses found. LOCATION points to the end of the SAL (for |
9484 | linespec locations). | |
9998af43 TJB |
9485 | |
9486 | The array and the line spec strings are allocated on the heap, it is | |
9487 | the caller's responsibility to free them. */ | |
c906108c | 9488 | |
b9362cc7 | 9489 | static void |
f00aae0f | 9490 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9491 | struct linespec_result *canonical) |
c3f6f71d | 9492 | { |
f00aae0f KS |
9493 | struct symtab_and_line cursal; |
9494 | ||
9495 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9496 | { | |
9497 | const char *address = get_linespec_location (location); | |
9498 | ||
9499 | if (address == NULL) | |
9500 | { | |
9501 | /* The last displayed codepoint, if it's valid, is our default | |
9502 | breakpoint address. */ | |
9503 | if (last_displayed_sal_is_valid ()) | |
9504 | { | |
9505 | struct linespec_sals lsal; | |
9506 | struct symtab_and_line sal; | |
9507 | CORE_ADDR pc; | |
9508 | ||
9509 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9510 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9511 | |
9512 | /* Set sal's pspace, pc, symtab, and line to the values | |
9513 | corresponding to the last call to print_frame_info. | |
9514 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9515 | as the breakpoint line number is inappropriate otherwise. | |
9516 | find_pc_line would adjust PC, re-set it back. */ | |
9517 | get_last_displayed_sal (&sal); | |
9518 | pc = sal.pc; | |
9519 | sal = find_pc_line (pc, 0); | |
9520 | ||
9521 | /* "break" without arguments is equivalent to "break *PC" | |
9522 | where PC is the last displayed codepoint's address. So | |
9523 | make sure to set sal.explicit_pc to prevent GDB from | |
9524 | trying to expand the list of sals to include all other | |
9525 | instances with the same symtab and line. */ | |
9526 | sal.pc = pc; | |
9527 | sal.explicit_pc = 1; | |
9528 | ||
9529 | lsal.sals.sals[0] = sal; | |
9530 | lsal.sals.nelts = 1; | |
9531 | lsal.canonical = NULL; | |
9532 | ||
9533 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9534 | return; | |
9535 | } | |
9536 | else | |
9537 | error (_("No default breakpoint address now.")); | |
c906108c | 9538 | } |
c906108c | 9539 | } |
f00aae0f KS |
9540 | |
9541 | /* Force almost all breakpoints to be in terms of the | |
9542 | current_source_symtab (which is decode_line_1's default). | |
9543 | This should produce the results we want almost all of the | |
9544 | time while leaving default_breakpoint_* alone. | |
9545 | ||
9546 | ObjC: However, don't match an Objective-C method name which | |
9547 | may have a '+' or '-' succeeded by a '['. */ | |
9548 | cursal = get_current_source_symtab_and_line (); | |
9549 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9550 | { |
f00aae0f | 9551 | const char *address = NULL; |
cc80f267 | 9552 | |
f00aae0f KS |
9553 | if (event_location_type (location) == LINESPEC_LOCATION) |
9554 | address = get_linespec_location (location); | |
cc80f267 | 9555 | |
f00aae0f KS |
9556 | if (!cursal.symtab |
9557 | || (address != NULL | |
9558 | && strchr ("+-", address[0]) != NULL | |
9559 | && address[1] != '[')) | |
9560 | { | |
c2f4122d | 9561 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9562 | get_last_displayed_symtab (), |
9563 | get_last_displayed_line (), | |
9564 | canonical, NULL, NULL); | |
9565 | return; | |
9566 | } | |
c906108c | 9567 | } |
f00aae0f | 9568 | |
c2f4122d | 9569 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9570 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9571 | } |
c906108c | 9572 | |
c906108c | 9573 | |
c3f6f71d | 9574 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9575 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9576 | |
b9362cc7 | 9577 | static void |
23e7acfb | 9578 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9579 | { |
9580 | int i; | |
cc59ec59 | 9581 | |
c3f6f71d | 9582 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9583 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9584 | } |
9585 | ||
7a697b8d SS |
9586 | /* Fast tracepoints may have restrictions on valid locations. For |
9587 | instance, a fast tracepoint using a jump instead of a trap will | |
9588 | likely have to overwrite more bytes than a trap would, and so can | |
9589 | only be placed where the instruction is longer than the jump, or a | |
9590 | multi-instruction sequence does not have a jump into the middle of | |
9591 | it, etc. */ | |
9592 | ||
9593 | static void | |
9594 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9595 | struct symtabs_and_lines *sals) | |
9596 | { | |
9597 | int i, rslt; | |
9598 | struct symtab_and_line *sal; | |
9599 | char *msg; | |
9600 | struct cleanup *old_chain; | |
9601 | ||
9602 | for (i = 0; i < sals->nelts; i++) | |
9603 | { | |
f8eba3c6 TT |
9604 | struct gdbarch *sarch; |
9605 | ||
7a697b8d SS |
9606 | sal = &sals->sals[i]; |
9607 | ||
f8eba3c6 TT |
9608 | sarch = get_sal_arch (*sal); |
9609 | /* We fall back to GDBARCH if there is no architecture | |
9610 | associated with SAL. */ | |
9611 | if (sarch == NULL) | |
9612 | sarch = gdbarch; | |
6b940e6a | 9613 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9614 | old_chain = make_cleanup (xfree, msg); |
9615 | ||
9616 | if (!rslt) | |
9617 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9618 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9619 | |
9620 | do_cleanups (old_chain); | |
9621 | } | |
9622 | } | |
9623 | ||
018d34a4 VP |
9624 | /* Given TOK, a string specification of condition and thread, as |
9625 | accepted by the 'break' command, extract the condition | |
9626 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9627 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9628 | If no condition is found, *COND_STRING is set to NULL. |
9629 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9630 | |
9631 | static void | |
bbc13ae3 | 9632 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9633 | char **cond_string, int *thread, int *task, |
9634 | char **rest) | |
018d34a4 VP |
9635 | { |
9636 | *cond_string = NULL; | |
9637 | *thread = -1; | |
ed1d1739 KS |
9638 | *task = 0; |
9639 | *rest = NULL; | |
9640 | ||
018d34a4 VP |
9641 | while (tok && *tok) |
9642 | { | |
bbc13ae3 | 9643 | const char *end_tok; |
018d34a4 | 9644 | int toklen; |
bbc13ae3 KS |
9645 | const char *cond_start = NULL; |
9646 | const char *cond_end = NULL; | |
cc59ec59 | 9647 | |
bbc13ae3 | 9648 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9649 | |
9650 | if ((*tok == '"' || *tok == ',') && rest) | |
9651 | { | |
9652 | *rest = savestring (tok, strlen (tok)); | |
9653 | return; | |
9654 | } | |
9655 | ||
bbc13ae3 | 9656 | end_tok = skip_to_space_const (tok); |
d634f2de | 9657 | |
018d34a4 | 9658 | toklen = end_tok - tok; |
d634f2de | 9659 | |
018d34a4 VP |
9660 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9661 | { | |
f7545552 TT |
9662 | struct expression *expr; |
9663 | ||
018d34a4 | 9664 | tok = cond_start = end_tok + 1; |
1bb9788d | 9665 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9666 | xfree (expr); |
018d34a4 | 9667 | cond_end = tok; |
d634f2de | 9668 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9669 | } |
9670 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9671 | { | |
5d5658a1 PA |
9672 | const char *tmptok; |
9673 | struct thread_info *thr; | |
d634f2de | 9674 | |
018d34a4 | 9675 | tok = end_tok + 1; |
5d5658a1 | 9676 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9677 | if (tok == tmptok) |
9678 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9679 | *thread = thr->global_num; |
bbc13ae3 | 9680 | tok = tmptok; |
018d34a4 | 9681 | } |
4a306c9a JB |
9682 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9683 | { | |
9684 | char *tmptok; | |
9685 | ||
9686 | tok = end_tok + 1; | |
bbc13ae3 | 9687 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9688 | if (tok == tmptok) |
9689 | error (_("Junk after task keyword.")); | |
9690 | if (!valid_task_id (*task)) | |
b6199126 | 9691 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9692 | tok = tmptok; |
4a306c9a | 9693 | } |
e7e0cddf SS |
9694 | else if (rest) |
9695 | { | |
9696 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9697 | return; |
e7e0cddf | 9698 | } |
018d34a4 VP |
9699 | else |
9700 | error (_("Junk at end of arguments.")); | |
9701 | } | |
9702 | } | |
9703 | ||
0fb4aa4b PA |
9704 | /* Decode a static tracepoint marker spec. */ |
9705 | ||
9706 | static struct symtabs_and_lines | |
f00aae0f | 9707 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9708 | { |
9709 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9710 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9711 | struct cleanup *old_chain; |
f00aae0f KS |
9712 | const char *p = &(*arg_p)[3]; |
9713 | const char *endp; | |
0fb4aa4b PA |
9714 | char *marker_str; |
9715 | int i; | |
9716 | ||
f00aae0f | 9717 | p = skip_spaces_const (p); |
0fb4aa4b | 9718 | |
f00aae0f | 9719 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9720 | |
9721 | marker_str = savestring (p, endp - p); | |
9722 | old_chain = make_cleanup (xfree, marker_str); | |
9723 | ||
9724 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9725 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9726 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9727 | ||
9728 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9729 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9730 | |
9731 | for (i = 0; i < sals.nelts; i++) | |
9732 | { | |
9733 | struct static_tracepoint_marker *marker; | |
9734 | ||
9735 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9736 | ||
9737 | init_sal (&sals.sals[i]); | |
9738 | ||
9739 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9740 | sals.sals[i].pc = marker->address; | |
9741 | ||
9742 | release_static_tracepoint_marker (marker); | |
9743 | } | |
9744 | ||
9745 | do_cleanups (old_chain); | |
9746 | ||
9747 | *arg_p = endp; | |
9748 | return sals; | |
9749 | } | |
9750 | ||
f00aae0f | 9751 | /* See breakpoint.h. */ |
0101ce28 | 9752 | |
8cdf0e15 VP |
9753 | int |
9754 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9755 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9756 | int thread, char *extra_string, |
f00aae0f | 9757 | int parse_extra, |
0fb4aa4b | 9758 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9759 | int ignore_count, |
9760 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9761 | const struct breakpoint_ops *ops, |
44f238bb PA |
9762 | int from_tty, int enabled, int internal, |
9763 | unsigned flags) | |
c3f6f71d | 9764 | { |
7efd8fc2 | 9765 | struct linespec_result canonical; |
c3f6f71d | 9766 | struct cleanup *old_chain; |
80c99de1 | 9767 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9768 | int pending = 0; |
4a306c9a | 9769 | int task = 0; |
86b17b60 | 9770 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9771 | |
348d480f PA |
9772 | gdb_assert (ops != NULL); |
9773 | ||
f00aae0f KS |
9774 | /* If extra_string isn't useful, set it to NULL. */ |
9775 | if (extra_string != NULL && *extra_string == '\0') | |
9776 | extra_string = NULL; | |
9777 | ||
7efd8fc2 | 9778 | init_linespec_result (&canonical); |
c3f6f71d | 9779 | |
492d29ea | 9780 | TRY |
b78a6381 | 9781 | { |
f00aae0f | 9782 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9783 | } |
492d29ea | 9784 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9785 | { |
492d29ea PA |
9786 | /* If caller is interested in rc value from parse, set |
9787 | value. */ | |
9788 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9789 | { |
05ff989b AC |
9790 | /* If pending breakpoint support is turned off, throw |
9791 | error. */ | |
fa8d40ab JJ |
9792 | |
9793 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9794 | throw_exception (e); |
9795 | ||
9796 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9797 | |
05ff989b AC |
9798 | /* If pending breakpoint support is auto query and the user |
9799 | selects no, then simply return the error code. */ | |
059fb39f | 9800 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9801 | && !nquery (_("Make %s pending on future shared library load? "), |
9802 | bptype_string (type_wanted))) | |
fd9b8c24 | 9803 | return 0; |
fa8d40ab | 9804 | |
05ff989b AC |
9805 | /* At this point, either the user was queried about setting |
9806 | a pending breakpoint and selected yes, or pending | |
9807 | breakpoint behavior is on and thus a pending breakpoint | |
9808 | is defaulted on behalf of the user. */ | |
f00aae0f | 9809 | pending = 1; |
0101ce28 | 9810 | } |
492d29ea PA |
9811 | else |
9812 | throw_exception (e); | |
0101ce28 | 9813 | } |
492d29ea PA |
9814 | END_CATCH |
9815 | ||
f00aae0f | 9816 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9817 | return 0; |
c3f6f71d | 9818 | |
4a64f543 | 9819 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9820 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9821 | |
c3f6f71d JM |
9822 | /* ----------------------------- SNIP ----------------------------- |
9823 | Anything added to the cleanup chain beyond this point is assumed | |
9824 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9825 | then the memory is not reclaimed. */ |
9826 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9827 | |
c3f6f71d JM |
9828 | /* Resolve all line numbers to PC's and verify that the addresses |
9829 | are ok for the target. */ | |
0101ce28 | 9830 | if (!pending) |
f8eba3c6 TT |
9831 | { |
9832 | int ix; | |
9833 | struct linespec_sals *iter; | |
9834 | ||
9835 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9836 | breakpoint_sals_to_pc (&iter->sals); | |
9837 | } | |
c3f6f71d | 9838 | |
7a697b8d | 9839 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9840 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9841 | { |
9842 | int ix; | |
9843 | struct linespec_sals *iter; | |
9844 | ||
9845 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9846 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9847 | } | |
7a697b8d | 9848 | |
c3f6f71d JM |
9849 | /* Verify that condition can be parsed, before setting any |
9850 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9851 | breakpoint. */ |
0101ce28 | 9852 | if (!pending) |
c3f6f71d | 9853 | { |
f00aae0f | 9854 | if (parse_extra) |
72b2ff0e | 9855 | { |
0878d0fa | 9856 | char *rest; |
52d361e1 YQ |
9857 | struct linespec_sals *lsal; |
9858 | ||
9859 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9860 | ||
0878d0fa YQ |
9861 | /* Here we only parse 'arg' to separate condition |
9862 | from thread number, so parsing in context of first | |
9863 | sal is OK. When setting the breakpoint we'll | |
9864 | re-parse it in context of each sal. */ | |
9865 | ||
f00aae0f KS |
9866 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9867 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9868 | if (cond_string) |
9869 | make_cleanup (xfree, cond_string); | |
9870 | if (rest) | |
9871 | make_cleanup (xfree, rest); | |
9872 | if (rest) | |
9873 | extra_string = rest; | |
f00aae0f KS |
9874 | else |
9875 | extra_string = NULL; | |
72b2ff0e | 9876 | } |
2f069f6f | 9877 | else |
72b2ff0e | 9878 | { |
f00aae0f KS |
9879 | if (type_wanted != bp_dprintf |
9880 | && extra_string != NULL && *extra_string != '\0') | |
9881 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9882 | |
9883 | /* Create a private copy of condition string. */ | |
9884 | if (cond_string) | |
9885 | { | |
9886 | cond_string = xstrdup (cond_string); | |
9887 | make_cleanup (xfree, cond_string); | |
9888 | } | |
9889 | /* Create a private copy of any extra string. */ | |
9890 | if (extra_string) | |
9891 | { | |
9892 | extra_string = xstrdup (extra_string); | |
9893 | make_cleanup (xfree, extra_string); | |
9894 | } | |
72b2ff0e | 9895 | } |
0fb4aa4b | 9896 | |
52d361e1 | 9897 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9898 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9899 | tempflag ? disp_del : disp_donttouch, |
9900 | thread, task, ignore_count, ops, | |
44f238bb | 9901 | from_tty, enabled, internal, flags); |
c906108c | 9902 | } |
0101ce28 JJ |
9903 | else |
9904 | { | |
0101ce28 JJ |
9905 | struct breakpoint *b; |
9906 | ||
bfccc43c YQ |
9907 | if (is_tracepoint_type (type_wanted)) |
9908 | { | |
9909 | struct tracepoint *t; | |
9910 | ||
9911 | t = XCNEW (struct tracepoint); | |
9912 | b = &t->base; | |
9913 | } | |
9914 | else | |
9915 | b = XNEW (struct breakpoint); | |
9916 | ||
9917 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9918 | b->location = copy_event_location (location); |
bfccc43c | 9919 | |
f00aae0f KS |
9920 | if (parse_extra) |
9921 | b->cond_string = NULL; | |
e12c7713 MK |
9922 | else |
9923 | { | |
9924 | /* Create a private copy of condition string. */ | |
9925 | if (cond_string) | |
9926 | { | |
9927 | cond_string = xstrdup (cond_string); | |
9928 | make_cleanup (xfree, cond_string); | |
9929 | } | |
9930 | b->cond_string = cond_string; | |
15630549 | 9931 | b->thread = thread; |
e12c7713 | 9932 | } |
f00aae0f KS |
9933 | |
9934 | /* Create a private copy of any extra string. */ | |
9935 | if (extra_string != NULL) | |
9936 | { | |
9937 | extra_string = xstrdup (extra_string); | |
9938 | make_cleanup (xfree, extra_string); | |
9939 | } | |
9940 | b->extra_string = extra_string; | |
0101ce28 | 9941 | b->ignore_count = ignore_count; |
0101ce28 | 9942 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9943 | b->condition_not_parsed = 1; |
41447f92 | 9944 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9945 | if ((type_wanted != bp_breakpoint |
9946 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9947 | b->pspace = current_program_space; |
8bea4e01 | 9948 | |
bfccc43c | 9949 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9950 | } |
9951 | ||
f8eba3c6 | 9952 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9953 | { |
3e43a32a MS |
9954 | warning (_("Multiple breakpoints were set.\nUse the " |
9955 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9956 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9957 | } |
9958 | ||
80c99de1 PA |
9959 | /* That's it. Discard the cleanups for data inserted into the |
9960 | breakpoint. */ | |
9961 | discard_cleanups (bkpt_chain); | |
9962 | /* But cleanup everything else. */ | |
c3f6f71d | 9963 | do_cleanups (old_chain); |
217dc9e2 | 9964 | |
80c99de1 | 9965 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9966 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9967 | |
9968 | return 1; | |
c3f6f71d | 9969 | } |
c906108c | 9970 | |
348d480f | 9971 | /* Set a breakpoint. |
72b2ff0e VP |
9972 | ARG is a string describing breakpoint address, |
9973 | condition, and thread. | |
9974 | FLAG specifies if a breakpoint is hardware on, | |
9975 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9976 | and BP_TEMPFLAG. */ | |
348d480f | 9977 | |
98deb0da | 9978 | static void |
72b2ff0e | 9979 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9980 | { |
72b2ff0e | 9981 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9982 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9983 | ? bp_hardware_breakpoint | |
9984 | : bp_breakpoint); | |
55aa24fb | 9985 | struct breakpoint_ops *ops; |
f00aae0f KS |
9986 | struct event_location *location; |
9987 | struct cleanup *cleanup; | |
9988 | ||
9989 | location = string_to_event_location (&arg, current_language); | |
9990 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
9991 | |
9992 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
9993 | if (location != NULL |
9994 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
9995 | ops = &bkpt_probe_breakpoint_ops; |
9996 | else | |
9997 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9998 | |
8cdf0e15 | 9999 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10000 | location, |
10001 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10002 | tempflag, type_wanted, |
8cdf0e15 VP |
10003 | 0 /* Ignore count */, |
10004 | pending_break_support, | |
55aa24fb | 10005 | ops, |
8cdf0e15 | 10006 | from_tty, |
84f4c1fe | 10007 | 1 /* enabled */, |
44f238bb PA |
10008 | 0 /* internal */, |
10009 | 0); | |
f00aae0f | 10010 | do_cleanups (cleanup); |
c906108c SS |
10011 | } |
10012 | ||
c906108c SS |
10013 | /* Helper function for break_command_1 and disassemble_command. */ |
10014 | ||
10015 | void | |
fba45db2 | 10016 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10017 | { |
10018 | CORE_ADDR pc; | |
10019 | ||
10020 | if (sal->pc == 0 && sal->symtab != NULL) | |
10021 | { | |
10022 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10023 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10024 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10025 | sal->pc = pc; |
6a048695 | 10026 | |
4a64f543 MS |
10027 | /* If this SAL corresponds to a breakpoint inserted using a line |
10028 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10029 | if (sal->explicit_line) |
059acae7 | 10030 | skip_prologue_sal (sal); |
c906108c SS |
10031 | } |
10032 | ||
10033 | if (sal->section == 0 && sal->symtab != NULL) | |
10034 | { | |
346d1dfe | 10035 | const struct blockvector *bv; |
3977b71f | 10036 | const struct block *b; |
c5aa993b | 10037 | struct symbol *sym; |
c906108c | 10038 | |
43f3e411 DE |
10039 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10040 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10041 | if (bv != NULL) |
10042 | { | |
7f0df278 | 10043 | sym = block_linkage_function (b); |
c906108c SS |
10044 | if (sym != NULL) |
10045 | { | |
eb822aa6 DE |
10046 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10047 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10048 | sym); | |
c906108c SS |
10049 | } |
10050 | else | |
10051 | { | |
4a64f543 MS |
10052 | /* It really is worthwhile to have the section, so we'll |
10053 | just have to look harder. This case can be executed | |
10054 | if we have line numbers but no functions (as can | |
10055 | happen in assembly source). */ | |
c906108c | 10056 | |
7cbd4a93 | 10057 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10058 | struct cleanup *old_chain = save_current_space_and_thread (); |
10059 | ||
10060 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10061 | |
10062 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10063 | if (msym.minsym) |
efd66ac6 | 10064 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10065 | |
10066 | do_cleanups (old_chain); | |
c906108c SS |
10067 | } |
10068 | } | |
10069 | } | |
10070 | } | |
10071 | ||
10072 | void | |
fba45db2 | 10073 | break_command (char *arg, int from_tty) |
c906108c | 10074 | { |
db107f19 | 10075 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10076 | } |
10077 | ||
c906108c | 10078 | void |
fba45db2 | 10079 | tbreak_command (char *arg, int from_tty) |
c906108c | 10080 | { |
db107f19 | 10081 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10082 | } |
10083 | ||
c906108c | 10084 | static void |
fba45db2 | 10085 | hbreak_command (char *arg, int from_tty) |
c906108c | 10086 | { |
db107f19 | 10087 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10088 | } |
10089 | ||
10090 | static void | |
fba45db2 | 10091 | thbreak_command (char *arg, int from_tty) |
c906108c | 10092 | { |
db107f19 | 10093 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10094 | } |
10095 | ||
10096 | static void | |
fba45db2 | 10097 | stop_command (char *arg, int from_tty) |
c906108c | 10098 | { |
a3f17187 | 10099 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10100 | Usage: stop in <function | address>\n\ |
a3f17187 | 10101 | stop at <line>\n")); |
c906108c SS |
10102 | } |
10103 | ||
10104 | static void | |
fba45db2 | 10105 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10106 | { |
10107 | int badInput = 0; | |
10108 | ||
c5aa993b | 10109 | if (arg == (char *) NULL) |
c906108c SS |
10110 | badInput = 1; |
10111 | else if (*arg != '*') | |
10112 | { | |
10113 | char *argptr = arg; | |
10114 | int hasColon = 0; | |
10115 | ||
4a64f543 | 10116 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10117 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10118 | function/method name. */ |
c906108c | 10119 | while (*argptr && !hasColon) |
c5aa993b JM |
10120 | { |
10121 | hasColon = (*argptr == ':'); | |
10122 | argptr++; | |
10123 | } | |
c906108c SS |
10124 | |
10125 | if (hasColon) | |
c5aa993b | 10126 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10127 | else |
c5aa993b | 10128 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10129 | } |
10130 | ||
10131 | if (badInput) | |
a3f17187 | 10132 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10133 | else |
db107f19 | 10134 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10135 | } |
10136 | ||
10137 | static void | |
fba45db2 | 10138 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10139 | { |
10140 | int badInput = 0; | |
10141 | ||
c5aa993b | 10142 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10143 | badInput = 1; |
10144 | else | |
10145 | { | |
10146 | char *argptr = arg; | |
10147 | int hasColon = 0; | |
10148 | ||
4a64f543 MS |
10149 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10150 | it is probably a line number. */ | |
c906108c | 10151 | while (*argptr && !hasColon) |
c5aa993b JM |
10152 | { |
10153 | hasColon = (*argptr == ':'); | |
10154 | argptr++; | |
10155 | } | |
c906108c SS |
10156 | |
10157 | if (hasColon) | |
c5aa993b | 10158 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10159 | else |
c5aa993b | 10160 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10161 | } |
10162 | ||
10163 | if (badInput) | |
a3f17187 | 10164 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10165 | else |
db107f19 | 10166 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10167 | } |
10168 | ||
e7e0cddf SS |
10169 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10170 | with a prewired command list consisting of a single output command, | |
10171 | built from extra arguments supplied on the dprintf command | |
10172 | line. */ | |
10173 | ||
da821c7b | 10174 | static void |
e7e0cddf SS |
10175 | dprintf_command (char *arg, int from_tty) |
10176 | { | |
f00aae0f KS |
10177 | struct event_location *location; |
10178 | struct cleanup *cleanup; | |
10179 | ||
10180 | location = string_to_event_location (&arg, current_language); | |
10181 | cleanup = make_cleanup_delete_event_location (location); | |
10182 | ||
10183 | /* If non-NULL, ARG should have been advanced past the location; | |
10184 | the next character must be ','. */ | |
10185 | if (arg != NULL) | |
10186 | { | |
10187 | if (arg[0] != ',' || arg[1] == '\0') | |
10188 | error (_("Format string required")); | |
10189 | else | |
10190 | { | |
10191 | /* Skip the comma. */ | |
10192 | ++arg; | |
10193 | } | |
10194 | } | |
10195 | ||
e7e0cddf | 10196 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10197 | location, |
10198 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10199 | 0, bp_dprintf, |
10200 | 0 /* Ignore count */, | |
10201 | pending_break_support, | |
10202 | &dprintf_breakpoint_ops, | |
10203 | from_tty, | |
10204 | 1 /* enabled */, | |
10205 | 0 /* internal */, | |
10206 | 0); | |
f00aae0f | 10207 | do_cleanups (cleanup); |
e7e0cddf SS |
10208 | } |
10209 | ||
d3ce09f5 SS |
10210 | static void |
10211 | agent_printf_command (char *arg, int from_tty) | |
10212 | { | |
10213 | error (_("May only run agent-printf on the target")); | |
10214 | } | |
10215 | ||
f1310107 TJB |
10216 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10217 | ranged breakpoints. */ | |
10218 | ||
10219 | static int | |
10220 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10221 | struct address_space *aspace, | |
09ac7c10 TT |
10222 | CORE_ADDR bp_addr, |
10223 | const struct target_waitstatus *ws) | |
f1310107 | 10224 | { |
09ac7c10 | 10225 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10226 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10227 | return 0; |
10228 | ||
f1310107 TJB |
10229 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10230 | bl->length, aspace, bp_addr); | |
10231 | } | |
10232 | ||
10233 | /* Implement the "resources_needed" breakpoint_ops method for | |
10234 | ranged breakpoints. */ | |
10235 | ||
10236 | static int | |
10237 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10238 | { | |
10239 | return target_ranged_break_num_registers (); | |
10240 | } | |
10241 | ||
10242 | /* Implement the "print_it" breakpoint_ops method for | |
10243 | ranged breakpoints. */ | |
10244 | ||
10245 | static enum print_stop_action | |
348d480f | 10246 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10247 | { |
348d480f | 10248 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10249 | struct bp_location *bl = b->loc; |
79a45e25 | 10250 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10251 | |
10252 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10253 | ||
10254 | /* Ranged breakpoints have only one location. */ | |
10255 | gdb_assert (bl && bl->next == NULL); | |
10256 | ||
10257 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10258 | |
10259 | maybe_print_thread_hit_breakpoint (uiout); | |
10260 | ||
f1310107 | 10261 | if (b->disposition == disp_del) |
f303dbd6 | 10262 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10263 | else |
f303dbd6 | 10264 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10265 | if (ui_out_is_mi_like_p (uiout)) |
10266 | { | |
10267 | ui_out_field_string (uiout, "reason", | |
10268 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10269 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10270 | } | |
10271 | ui_out_field_int (uiout, "bkptno", b->number); | |
10272 | ui_out_text (uiout, ", "); | |
10273 | ||
10274 | return PRINT_SRC_AND_LOC; | |
10275 | } | |
10276 | ||
10277 | /* Implement the "print_one" breakpoint_ops method for | |
10278 | ranged breakpoints. */ | |
10279 | ||
10280 | static void | |
10281 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10282 | struct bp_location **last_loc) | |
10283 | { | |
10284 | struct bp_location *bl = b->loc; | |
10285 | struct value_print_options opts; | |
79a45e25 | 10286 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10287 | |
10288 | /* Ranged breakpoints have only one location. */ | |
10289 | gdb_assert (bl && bl->next == NULL); | |
10290 | ||
10291 | get_user_print_options (&opts); | |
10292 | ||
10293 | if (opts.addressprint) | |
10294 | /* We don't print the address range here, it will be printed later | |
10295 | by print_one_detail_ranged_breakpoint. */ | |
10296 | ui_out_field_skip (uiout, "addr"); | |
10297 | annotate_field (5); | |
10298 | print_breakpoint_location (b, bl); | |
10299 | *last_loc = bl; | |
10300 | } | |
10301 | ||
10302 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10303 | ranged breakpoints. */ | |
10304 | ||
10305 | static void | |
10306 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10307 | struct ui_out *uiout) | |
10308 | { | |
10309 | CORE_ADDR address_start, address_end; | |
10310 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10311 | struct ui_file *stb = mem_fileopen (); |
10312 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10313 | |
10314 | gdb_assert (bl); | |
10315 | ||
10316 | address_start = bl->address; | |
10317 | address_end = address_start + bl->length - 1; | |
10318 | ||
10319 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10320 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10321 | print_core_address (bl->gdbarch, address_start), |
10322 | print_core_address (bl->gdbarch, address_end)); | |
10323 | ui_out_field_stream (uiout, "addr", stb); | |
10324 | ui_out_text (uiout, "\n"); | |
10325 | ||
10326 | do_cleanups (cleanup); | |
10327 | } | |
10328 | ||
10329 | /* Implement the "print_mention" breakpoint_ops method for | |
10330 | ranged breakpoints. */ | |
10331 | ||
10332 | static void | |
10333 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10334 | { | |
10335 | struct bp_location *bl = b->loc; | |
79a45e25 | 10336 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10337 | |
10338 | gdb_assert (bl); | |
10339 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10340 | ||
10341 | if (ui_out_is_mi_like_p (uiout)) | |
10342 | return; | |
10343 | ||
10344 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10345 | b->number, paddress (bl->gdbarch, bl->address), | |
10346 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10347 | } | |
10348 | ||
10349 | /* Implement the "print_recreate" breakpoint_ops method for | |
10350 | ranged breakpoints. */ | |
10351 | ||
10352 | static void | |
10353 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10354 | { | |
f00aae0f KS |
10355 | fprintf_unfiltered (fp, "break-range %s, %s", |
10356 | event_location_to_string (b->location), | |
10357 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10358 | print_recreate_thread (b, fp); |
f1310107 TJB |
10359 | } |
10360 | ||
10361 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10362 | ||
2060206e | 10363 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10364 | |
10365 | /* Find the address where the end of the breakpoint range should be | |
10366 | placed, given the SAL of the end of the range. This is so that if | |
10367 | the user provides a line number, the end of the range is set to the | |
10368 | last instruction of the given line. */ | |
10369 | ||
10370 | static CORE_ADDR | |
10371 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10372 | { | |
10373 | CORE_ADDR end; | |
10374 | ||
10375 | /* If the user provided a PC value, use it. Otherwise, | |
10376 | find the address of the end of the given location. */ | |
10377 | if (sal.explicit_pc) | |
10378 | end = sal.pc; | |
10379 | else | |
10380 | { | |
10381 | int ret; | |
10382 | CORE_ADDR start; | |
10383 | ||
10384 | ret = find_line_pc_range (sal, &start, &end); | |
10385 | if (!ret) | |
10386 | error (_("Could not find location of the end of the range.")); | |
10387 | ||
10388 | /* find_line_pc_range returns the start of the next line. */ | |
10389 | end--; | |
10390 | } | |
10391 | ||
10392 | return end; | |
10393 | } | |
10394 | ||
10395 | /* Implement the "break-range" CLI command. */ | |
10396 | ||
10397 | static void | |
10398 | break_range_command (char *arg, int from_tty) | |
10399 | { | |
10400 | char *arg_start, *addr_string_start, *addr_string_end; | |
10401 | struct linespec_result canonical_start, canonical_end; | |
10402 | int bp_count, can_use_bp, length; | |
10403 | CORE_ADDR end; | |
10404 | struct breakpoint *b; | |
10405 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10406 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10407 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10408 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10409 | |
10410 | /* We don't support software ranged breakpoints. */ | |
10411 | if (target_ranged_break_num_registers () < 0) | |
10412 | error (_("This target does not support hardware ranged breakpoints.")); | |
10413 | ||
10414 | bp_count = hw_breakpoint_used_count (); | |
10415 | bp_count += target_ranged_break_num_registers (); | |
10416 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10417 | bp_count, 0); | |
10418 | if (can_use_bp < 0) | |
10419 | error (_("Hardware breakpoints used exceeds limit.")); | |
10420 | ||
f8eba3c6 | 10421 | arg = skip_spaces (arg); |
f1310107 TJB |
10422 | if (arg == NULL || arg[0] == '\0') |
10423 | error(_("No address range specified.")); | |
10424 | ||
f1310107 TJB |
10425 | init_linespec_result (&canonical_start); |
10426 | ||
f8eba3c6 | 10427 | arg_start = arg; |
f00aae0f KS |
10428 | start_location = string_to_event_location (&arg, current_language); |
10429 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10430 | parse_breakpoint_sals (start_location, &canonical_start); | |
10431 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10432 | |
10433 | if (arg[0] != ',') | |
10434 | error (_("Too few arguments.")); | |
f8eba3c6 | 10435 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10436 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10437 | |
10438 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10439 | ||
10440 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10441 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10442 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10443 | ||
f8eba3c6 TT |
10444 | sal_start = lsal_start->sals.sals[0]; |
10445 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10446 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10447 | |
10448 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10449 | arg = skip_spaces (arg); |
f1310107 TJB |
10450 | |
10451 | /* Parse the end location. */ | |
10452 | ||
f1310107 TJB |
10453 | init_linespec_result (&canonical_end); |
10454 | arg_start = arg; | |
10455 | ||
f8eba3c6 | 10456 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10457 | parse_breakpoint_sals because we need to specify the start location's |
10458 | symtab and line as the default symtab and line for the end of the | |
10459 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10460 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10461 | end_location = string_to_event_location (&arg, current_language); |
10462 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10463 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10464 | sal_start.symtab, sal_start.line, |
10465 | &canonical_end, NULL, NULL); | |
10466 | ||
10467 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10468 | |
f8eba3c6 | 10469 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10470 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10471 | |
10472 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10473 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10474 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10475 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10476 | ||
f8eba3c6 | 10477 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10478 | |
10479 | end = find_breakpoint_range_end (sal_end); | |
10480 | if (sal_start.pc > end) | |
177b42fe | 10481 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10482 | |
10483 | length = end - sal_start.pc + 1; | |
10484 | if (length < 0) | |
10485 | /* Length overflowed. */ | |
10486 | error (_("Address range too large.")); | |
10487 | else if (length == 1) | |
10488 | { | |
10489 | /* This range is simple enough to be handled by | |
10490 | the `hbreak' command. */ | |
10491 | hbreak_command (addr_string_start, 1); | |
10492 | ||
10493 | do_cleanups (cleanup_bkpt); | |
10494 | ||
10495 | return; | |
10496 | } | |
10497 | ||
10498 | /* Now set up the breakpoint. */ | |
10499 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10500 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10501 | set_breakpoint_count (breakpoint_count + 1); |
10502 | b->number = breakpoint_count; | |
10503 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10504 | b->location = copy_event_location (start_location); |
10505 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10506 | b->loc->length = length; |
10507 | ||
f8eba3c6 | 10508 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10509 | |
10510 | mention (b); | |
8d3788bd | 10511 | observer_notify_breakpoint_created (b); |
44702360 | 10512 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10513 | } |
10514 | ||
4a64f543 MS |
10515 | /* Return non-zero if EXP is verified as constant. Returned zero |
10516 | means EXP is variable. Also the constant detection may fail for | |
10517 | some constant expressions and in such case still falsely return | |
10518 | zero. */ | |
2e6e3d9c | 10519 | |
65d79d4b SDJ |
10520 | static int |
10521 | watchpoint_exp_is_const (const struct expression *exp) | |
10522 | { | |
10523 | int i = exp->nelts; | |
10524 | ||
10525 | while (i > 0) | |
10526 | { | |
10527 | int oplenp, argsp; | |
10528 | ||
10529 | /* We are only interested in the descriptor of each element. */ | |
10530 | operator_length (exp, i, &oplenp, &argsp); | |
10531 | i -= oplenp; | |
10532 | ||
10533 | switch (exp->elts[i].opcode) | |
10534 | { | |
10535 | case BINOP_ADD: | |
10536 | case BINOP_SUB: | |
10537 | case BINOP_MUL: | |
10538 | case BINOP_DIV: | |
10539 | case BINOP_REM: | |
10540 | case BINOP_MOD: | |
10541 | case BINOP_LSH: | |
10542 | case BINOP_RSH: | |
10543 | case BINOP_LOGICAL_AND: | |
10544 | case BINOP_LOGICAL_OR: | |
10545 | case BINOP_BITWISE_AND: | |
10546 | case BINOP_BITWISE_IOR: | |
10547 | case BINOP_BITWISE_XOR: | |
10548 | case BINOP_EQUAL: | |
10549 | case BINOP_NOTEQUAL: | |
10550 | case BINOP_LESS: | |
10551 | case BINOP_GTR: | |
10552 | case BINOP_LEQ: | |
10553 | case BINOP_GEQ: | |
10554 | case BINOP_REPEAT: | |
10555 | case BINOP_COMMA: | |
10556 | case BINOP_EXP: | |
10557 | case BINOP_MIN: | |
10558 | case BINOP_MAX: | |
10559 | case BINOP_INTDIV: | |
10560 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10561 | case TERNOP_COND: |
10562 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10563 | |
10564 | case OP_LONG: | |
10565 | case OP_DOUBLE: | |
10566 | case OP_DECFLOAT: | |
10567 | case OP_LAST: | |
10568 | case OP_COMPLEX: | |
10569 | case OP_STRING: | |
65d79d4b SDJ |
10570 | case OP_ARRAY: |
10571 | case OP_TYPE: | |
608b4967 TT |
10572 | case OP_TYPEOF: |
10573 | case OP_DECLTYPE: | |
6e72ca20 | 10574 | case OP_TYPEID: |
65d79d4b SDJ |
10575 | case OP_NAME: |
10576 | case OP_OBJC_NSSTRING: | |
10577 | ||
10578 | case UNOP_NEG: | |
10579 | case UNOP_LOGICAL_NOT: | |
10580 | case UNOP_COMPLEMENT: | |
10581 | case UNOP_ADDR: | |
10582 | case UNOP_HIGH: | |
aeaa2474 | 10583 | case UNOP_CAST: |
9eaf6705 TT |
10584 | |
10585 | case UNOP_CAST_TYPE: | |
10586 | case UNOP_REINTERPRET_CAST: | |
10587 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10588 | /* Unary, binary and ternary operators: We have to check |
10589 | their operands. If they are constant, then so is the | |
10590 | result of that operation. For instance, if A and B are | |
10591 | determined to be constants, then so is "A + B". | |
10592 | ||
10593 | UNOP_IND is one exception to the rule above, because the | |
10594 | value of *ADDR is not necessarily a constant, even when | |
10595 | ADDR is. */ | |
65d79d4b SDJ |
10596 | break; |
10597 | ||
10598 | case OP_VAR_VALUE: | |
10599 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10600 | |
65d79d4b | 10601 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10602 | possible that a buggy compiler could mark a variable as |
10603 | constant even when it is not, and TYPE_CONST would return | |
10604 | true in this case, while SYMBOL_CLASS wouldn't. | |
10605 | ||
10606 | We also have to check for function symbols because they | |
10607 | are always constant. */ | |
65d79d4b SDJ |
10608 | { |
10609 | struct symbol *s = exp->elts[i + 2].symbol; | |
10610 | ||
10611 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10612 | && SYMBOL_CLASS (s) != LOC_CONST | |
10613 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10614 | return 0; | |
10615 | break; | |
10616 | } | |
10617 | ||
10618 | /* The default action is to return 0 because we are using | |
10619 | the optimistic approach here: If we don't know something, | |
10620 | then it is not a constant. */ | |
10621 | default: | |
10622 | return 0; | |
10623 | } | |
10624 | } | |
10625 | ||
10626 | return 1; | |
10627 | } | |
10628 | ||
3a5c3e22 PA |
10629 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10630 | ||
10631 | static void | |
10632 | dtor_watchpoint (struct breakpoint *self) | |
10633 | { | |
10634 | struct watchpoint *w = (struct watchpoint *) self; | |
10635 | ||
10636 | xfree (w->cond_exp); | |
10637 | xfree (w->exp); | |
10638 | xfree (w->exp_string); | |
10639 | xfree (w->exp_string_reparse); | |
10640 | value_free (w->val); | |
10641 | ||
10642 | base_breakpoint_ops.dtor (self); | |
10643 | } | |
10644 | ||
348d480f PA |
10645 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10646 | ||
10647 | static void | |
10648 | re_set_watchpoint (struct breakpoint *b) | |
10649 | { | |
3a5c3e22 PA |
10650 | struct watchpoint *w = (struct watchpoint *) b; |
10651 | ||
348d480f PA |
10652 | /* Watchpoint can be either on expression using entirely global |
10653 | variables, or it can be on local variables. | |
10654 | ||
10655 | Watchpoints of the first kind are never auto-deleted, and even | |
10656 | persist across program restarts. Since they can use variables | |
10657 | from shared libraries, we need to reparse expression as libraries | |
10658 | are loaded and unloaded. | |
10659 | ||
10660 | Watchpoints on local variables can also change meaning as result | |
10661 | of solib event. For example, if a watchpoint uses both a local | |
10662 | and a global variables in expression, it's a local watchpoint, | |
10663 | but unloading of a shared library will make the expression | |
10664 | invalid. This is not a very common use case, but we still | |
10665 | re-evaluate expression, to avoid surprises to the user. | |
10666 | ||
10667 | Note that for local watchpoints, we re-evaluate it only if | |
10668 | watchpoints frame id is still valid. If it's not, it means the | |
10669 | watchpoint is out of scope and will be deleted soon. In fact, | |
10670 | I'm not sure we'll ever be called in this case. | |
10671 | ||
10672 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10673 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10674 | |
3a5c3e22 PA |
10675 | Don't do anything about disabled watchpoints, since they will be |
10676 | reevaluated again when enabled. */ | |
10677 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10678 | } |
10679 | ||
77b06cd7 TJB |
10680 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10681 | ||
10682 | static int | |
10683 | insert_watchpoint (struct bp_location *bl) | |
10684 | { | |
3a5c3e22 PA |
10685 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10686 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10687 | |
10688 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10689 | w->cond_exp); |
77b06cd7 TJB |
10690 | } |
10691 | ||
10692 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10693 | ||
10694 | static int | |
10695 | remove_watchpoint (struct bp_location *bl) | |
10696 | { | |
3a5c3e22 PA |
10697 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10698 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10699 | |
10700 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10701 | w->cond_exp); |
e09342b5 TJB |
10702 | } |
10703 | ||
e09342b5 | 10704 | static int |
348d480f | 10705 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10706 | struct address_space *aspace, CORE_ADDR bp_addr, |
10707 | const struct target_waitstatus *ws) | |
e09342b5 | 10708 | { |
348d480f | 10709 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10710 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10711 | |
348d480f PA |
10712 | /* Continuable hardware watchpoints are treated as non-existent if the |
10713 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10714 | some data address). Otherwise gdb won't stop on a break instruction | |
10715 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10716 | been defined. Also skip watchpoints which we know did not trigger | |
10717 | (did not match the data address). */ | |
10718 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10719 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10720 | return 0; |
9c06b0b4 | 10721 | |
348d480f | 10722 | return 1; |
9c06b0b4 TJB |
10723 | } |
10724 | ||
348d480f PA |
10725 | static void |
10726 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10727 | { |
348d480f | 10728 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10729 | |
348d480f | 10730 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10731 | } |
10732 | ||
10733 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10734 | hardware watchpoints. */ |
9c06b0b4 TJB |
10735 | |
10736 | static int | |
348d480f | 10737 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10738 | { |
3a5c3e22 PA |
10739 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10740 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10741 | |
10742 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10743 | } |
10744 | ||
10745 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10746 | hardware watchpoints. */ |
9c06b0b4 TJB |
10747 | |
10748 | static int | |
348d480f | 10749 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10750 | { |
efa80663 PA |
10751 | /* Read and access watchpoints only work with hardware support. */ |
10752 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10753 | } |
10754 | ||
9c06b0b4 | 10755 | static enum print_stop_action |
348d480f | 10756 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10757 | { |
348d480f PA |
10758 | struct cleanup *old_chain; |
10759 | struct breakpoint *b; | |
f99d8bf4 | 10760 | struct ui_file *stb; |
348d480f | 10761 | enum print_stop_action result; |
3a5c3e22 | 10762 | struct watchpoint *w; |
79a45e25 | 10763 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10764 | |
10765 | gdb_assert (bs->bp_location_at != NULL); | |
10766 | ||
348d480f | 10767 | b = bs->breakpoint_at; |
3a5c3e22 | 10768 | w = (struct watchpoint *) b; |
348d480f | 10769 | |
f99d8bf4 PA |
10770 | stb = mem_fileopen (); |
10771 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10772 | |
f303dbd6 PA |
10773 | annotate_watchpoint (b->number); |
10774 | maybe_print_thread_hit_breakpoint (uiout); | |
10775 | ||
9c06b0b4 TJB |
10776 | switch (b->type) |
10777 | { | |
348d480f | 10778 | case bp_watchpoint: |
9c06b0b4 | 10779 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10780 | if (ui_out_is_mi_like_p (uiout)) |
10781 | ui_out_field_string | |
10782 | (uiout, "reason", | |
10783 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10784 | mention (b); |
10785 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10786 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10787 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10788 | ui_out_field_stream (uiout, "old", stb); |
10789 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10790 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10791 | ui_out_field_stream (uiout, "new", stb); |
10792 | ui_out_text (uiout, "\n"); | |
10793 | /* More than one watchpoint may have been triggered. */ | |
10794 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10795 | break; |
10796 | ||
10797 | case bp_read_watchpoint: | |
10798 | if (ui_out_is_mi_like_p (uiout)) | |
10799 | ui_out_field_string | |
10800 | (uiout, "reason", | |
10801 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10802 | mention (b); |
10803 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10804 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10805 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10806 | ui_out_field_stream (uiout, "value", stb); |
10807 | ui_out_text (uiout, "\n"); | |
10808 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10809 | break; |
10810 | ||
10811 | case bp_access_watchpoint: | |
348d480f PA |
10812 | if (bs->old_val != NULL) |
10813 | { | |
348d480f PA |
10814 | if (ui_out_is_mi_like_p (uiout)) |
10815 | ui_out_field_string | |
10816 | (uiout, "reason", | |
10817 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10818 | mention (b); | |
10819 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10820 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10821 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10822 | ui_out_field_stream (uiout, "old", stb); |
10823 | ui_out_text (uiout, "\nNew value = "); | |
10824 | } | |
10825 | else | |
10826 | { | |
10827 | mention (b); | |
10828 | if (ui_out_is_mi_like_p (uiout)) | |
10829 | ui_out_field_string | |
10830 | (uiout, "reason", | |
10831 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10832 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10833 | ui_out_text (uiout, "\nValue = "); | |
10834 | } | |
f99d8bf4 | 10835 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10836 | ui_out_field_stream (uiout, "new", stb); |
10837 | ui_out_text (uiout, "\n"); | |
10838 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10839 | break; |
10840 | default: | |
348d480f | 10841 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10842 | } |
10843 | ||
348d480f PA |
10844 | do_cleanups (old_chain); |
10845 | return result; | |
10846 | } | |
10847 | ||
10848 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10849 | watchpoints. */ | |
10850 | ||
10851 | static void | |
10852 | print_mention_watchpoint (struct breakpoint *b) | |
10853 | { | |
10854 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10855 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10856 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10857 | |
10858 | switch (b->type) | |
10859 | { | |
10860 | case bp_watchpoint: | |
10861 | ui_out_text (uiout, "Watchpoint "); | |
10862 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10863 | break; | |
10864 | case bp_hardware_watchpoint: | |
10865 | ui_out_text (uiout, "Hardware watchpoint "); | |
10866 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10867 | break; | |
10868 | case bp_read_watchpoint: | |
10869 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10870 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10871 | break; | |
10872 | case bp_access_watchpoint: | |
10873 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10874 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10875 | break; | |
10876 | default: | |
10877 | internal_error (__FILE__, __LINE__, | |
10878 | _("Invalid hardware watchpoint type.")); | |
10879 | } | |
10880 | ||
10881 | ui_out_field_int (uiout, "number", b->number); | |
10882 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10883 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10884 | do_cleanups (ui_out_chain); |
10885 | } | |
10886 | ||
10887 | /* Implement the "print_recreate" breakpoint_ops method for | |
10888 | watchpoints. */ | |
10889 | ||
10890 | static void | |
10891 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10892 | { | |
3a5c3e22 PA |
10893 | struct watchpoint *w = (struct watchpoint *) b; |
10894 | ||
348d480f PA |
10895 | switch (b->type) |
10896 | { | |
10897 | case bp_watchpoint: | |
10898 | case bp_hardware_watchpoint: | |
10899 | fprintf_unfiltered (fp, "watch"); | |
10900 | break; | |
10901 | case bp_read_watchpoint: | |
10902 | fprintf_unfiltered (fp, "rwatch"); | |
10903 | break; | |
10904 | case bp_access_watchpoint: | |
10905 | fprintf_unfiltered (fp, "awatch"); | |
10906 | break; | |
10907 | default: | |
10908 | internal_error (__FILE__, __LINE__, | |
10909 | _("Invalid watchpoint type.")); | |
10910 | } | |
10911 | ||
3a5c3e22 | 10912 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10913 | print_recreate_thread (b, fp); |
348d480f PA |
10914 | } |
10915 | ||
427cd150 TT |
10916 | /* Implement the "explains_signal" breakpoint_ops method for |
10917 | watchpoints. */ | |
10918 | ||
47591c29 | 10919 | static int |
427cd150 TT |
10920 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10921 | { | |
10922 | /* A software watchpoint cannot cause a signal other than | |
10923 | GDB_SIGNAL_TRAP. */ | |
10924 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10925 | return 0; |
427cd150 | 10926 | |
47591c29 | 10927 | return 1; |
427cd150 TT |
10928 | } |
10929 | ||
348d480f PA |
10930 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10931 | ||
2060206e | 10932 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10933 | |
10934 | /* Implement the "insert" breakpoint_ops method for | |
10935 | masked hardware watchpoints. */ | |
10936 | ||
10937 | static int | |
10938 | insert_masked_watchpoint (struct bp_location *bl) | |
10939 | { | |
3a5c3e22 PA |
10940 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10941 | ||
10942 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10943 | bl->watchpoint_type); |
10944 | } | |
10945 | ||
10946 | /* Implement the "remove" breakpoint_ops method for | |
10947 | masked hardware watchpoints. */ | |
10948 | ||
10949 | static int | |
10950 | remove_masked_watchpoint (struct bp_location *bl) | |
10951 | { | |
3a5c3e22 PA |
10952 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10953 | ||
10954 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10955 | bl->watchpoint_type); |
10956 | } | |
10957 | ||
10958 | /* Implement the "resources_needed" breakpoint_ops method for | |
10959 | masked hardware watchpoints. */ | |
10960 | ||
10961 | static int | |
10962 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10963 | { | |
3a5c3e22 PA |
10964 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10965 | ||
10966 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10967 | } |
10968 | ||
10969 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10970 | masked hardware watchpoints. */ | |
10971 | ||
10972 | static int | |
10973 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10974 | { | |
10975 | return 0; | |
10976 | } | |
10977 | ||
10978 | /* Implement the "print_it" breakpoint_ops method for | |
10979 | masked hardware watchpoints. */ | |
10980 | ||
10981 | static enum print_stop_action | |
10982 | print_it_masked_watchpoint (bpstat bs) | |
10983 | { | |
10984 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10985 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10986 | |
10987 | /* Masked watchpoints have only one location. */ | |
10988 | gdb_assert (b->loc && b->loc->next == NULL); | |
10989 | ||
f303dbd6 PA |
10990 | annotate_watchpoint (b->number); |
10991 | maybe_print_thread_hit_breakpoint (uiout); | |
10992 | ||
348d480f PA |
10993 | switch (b->type) |
10994 | { | |
10995 | case bp_hardware_watchpoint: | |
348d480f PA |
10996 | if (ui_out_is_mi_like_p (uiout)) |
10997 | ui_out_field_string | |
10998 | (uiout, "reason", | |
10999 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11000 | break; | |
11001 | ||
11002 | case bp_read_watchpoint: | |
11003 | if (ui_out_is_mi_like_p (uiout)) | |
11004 | ui_out_field_string | |
11005 | (uiout, "reason", | |
11006 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11007 | break; | |
11008 | ||
11009 | case bp_access_watchpoint: | |
11010 | if (ui_out_is_mi_like_p (uiout)) | |
11011 | ui_out_field_string | |
11012 | (uiout, "reason", | |
11013 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11014 | break; | |
11015 | default: | |
11016 | internal_error (__FILE__, __LINE__, | |
11017 | _("Invalid hardware watchpoint type.")); | |
11018 | } | |
11019 | ||
11020 | mention (b); | |
9c06b0b4 TJB |
11021 | ui_out_text (uiout, _("\n\ |
11022 | Check the underlying instruction at PC for the memory\n\ | |
11023 | address and value which triggered this watchpoint.\n")); | |
11024 | ui_out_text (uiout, "\n"); | |
11025 | ||
11026 | /* More than one watchpoint may have been triggered. */ | |
11027 | return PRINT_UNKNOWN; | |
11028 | } | |
11029 | ||
11030 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11031 | masked hardware watchpoints. */ | |
11032 | ||
11033 | static void | |
11034 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11035 | struct ui_out *uiout) | |
11036 | { | |
3a5c3e22 PA |
11037 | struct watchpoint *w = (struct watchpoint *) b; |
11038 | ||
9c06b0b4 TJB |
11039 | /* Masked watchpoints have only one location. */ |
11040 | gdb_assert (b->loc && b->loc->next == NULL); | |
11041 | ||
11042 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11043 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11044 | ui_out_text (uiout, "\n"); |
11045 | } | |
11046 | ||
11047 | /* Implement the "print_mention" breakpoint_ops method for | |
11048 | masked hardware watchpoints. */ | |
11049 | ||
11050 | static void | |
11051 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11052 | { | |
3a5c3e22 | 11053 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11054 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11055 | struct cleanup *ui_out_chain; |
11056 | ||
11057 | switch (b->type) | |
11058 | { | |
11059 | case bp_hardware_watchpoint: | |
11060 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11061 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11062 | break; | |
11063 | case bp_read_watchpoint: | |
11064 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11065 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11066 | break; | |
11067 | case bp_access_watchpoint: | |
11068 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11069 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11070 | break; | |
11071 | default: | |
11072 | internal_error (__FILE__, __LINE__, | |
11073 | _("Invalid hardware watchpoint type.")); | |
11074 | } | |
11075 | ||
11076 | ui_out_field_int (uiout, "number", b->number); | |
11077 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11078 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11079 | do_cleanups (ui_out_chain); |
11080 | } | |
11081 | ||
11082 | /* Implement the "print_recreate" breakpoint_ops method for | |
11083 | masked hardware watchpoints. */ | |
11084 | ||
11085 | static void | |
11086 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11087 | { | |
3a5c3e22 | 11088 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11089 | char tmp[40]; |
11090 | ||
11091 | switch (b->type) | |
11092 | { | |
11093 | case bp_hardware_watchpoint: | |
11094 | fprintf_unfiltered (fp, "watch"); | |
11095 | break; | |
11096 | case bp_read_watchpoint: | |
11097 | fprintf_unfiltered (fp, "rwatch"); | |
11098 | break; | |
11099 | case bp_access_watchpoint: | |
11100 | fprintf_unfiltered (fp, "awatch"); | |
11101 | break; | |
11102 | default: | |
11103 | internal_error (__FILE__, __LINE__, | |
11104 | _("Invalid hardware watchpoint type.")); | |
11105 | } | |
11106 | ||
3a5c3e22 PA |
11107 | sprintf_vma (tmp, w->hw_wp_mask); |
11108 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11109 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11110 | } |
11111 | ||
11112 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11113 | ||
2060206e | 11114 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11115 | |
11116 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11117 | ||
11118 | static int | |
11119 | is_masked_watchpoint (const struct breakpoint *b) | |
11120 | { | |
11121 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11122 | } | |
11123 | ||
53a5351d JM |
11124 | /* accessflag: hw_write: watch write, |
11125 | hw_read: watch read, | |
11126 | hw_access: watch access (read or write) */ | |
c906108c | 11127 | static void |
bbc13ae3 | 11128 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11129 | int just_location, int internal) |
c906108c | 11130 | { |
d983da9c | 11131 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11132 | struct expression *exp; |
270140bd | 11133 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11134 | struct value *val, *mark, *result; |
bb9d5f81 | 11135 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11136 | struct frame_info *frame; |
bbc13ae3 KS |
11137 | const char *exp_start = NULL; |
11138 | const char *exp_end = NULL; | |
11139 | const char *tok, *end_tok; | |
9c06b0b4 | 11140 | int toklen = -1; |
bbc13ae3 KS |
11141 | const char *cond_start = NULL; |
11142 | const char *cond_end = NULL; | |
c906108c | 11143 | enum bptype bp_type; |
37e4754d | 11144 | int thread = -1; |
0cf6dd15 | 11145 | int pc = 0; |
9c06b0b4 TJB |
11146 | /* Flag to indicate whether we are going to use masks for |
11147 | the hardware watchpoint. */ | |
11148 | int use_mask = 0; | |
11149 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11150 | struct watchpoint *w; |
bbc13ae3 KS |
11151 | char *expression; |
11152 | struct cleanup *back_to; | |
c906108c | 11153 | |
37e4754d LM |
11154 | /* Make sure that we actually have parameters to parse. */ |
11155 | if (arg != NULL && arg[0] != '\0') | |
11156 | { | |
bbc13ae3 KS |
11157 | const char *value_start; |
11158 | ||
11159 | exp_end = arg + strlen (arg); | |
37e4754d | 11160 | |
9c06b0b4 TJB |
11161 | /* Look for "parameter value" pairs at the end |
11162 | of the arguments string. */ | |
bbc13ae3 | 11163 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11164 | { |
11165 | /* Skip whitespace at the end of the argument list. */ | |
11166 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11167 | tok--; | |
11168 | ||
11169 | /* Find the beginning of the last token. | |
11170 | This is the value of the parameter. */ | |
11171 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11172 | tok--; | |
11173 | value_start = tok + 1; | |
11174 | ||
11175 | /* Skip whitespace. */ | |
11176 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11177 | tok--; | |
11178 | ||
11179 | end_tok = tok; | |
11180 | ||
11181 | /* Find the beginning of the second to last token. | |
11182 | This is the parameter itself. */ | |
11183 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11184 | tok--; | |
11185 | tok++; | |
11186 | toklen = end_tok - tok + 1; | |
11187 | ||
61012eef | 11188 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11189 | { |
5d5658a1 | 11190 | struct thread_info *thr; |
9c06b0b4 TJB |
11191 | /* At this point we've found a "thread" token, which means |
11192 | the user is trying to set a watchpoint that triggers | |
11193 | only in a specific thread. */ | |
5d5658a1 | 11194 | const char *endp; |
37e4754d | 11195 | |
9c06b0b4 TJB |
11196 | if (thread != -1) |
11197 | error(_("You can specify only one thread.")); | |
37e4754d | 11198 | |
9c06b0b4 | 11199 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11200 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11201 | |
5d5658a1 | 11202 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11203 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11204 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11205 | |
5d5658a1 | 11206 | thread = thr->global_num; |
9c06b0b4 | 11207 | } |
61012eef | 11208 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11209 | { |
11210 | /* We've found a "mask" token, which means the user wants to | |
11211 | create a hardware watchpoint that is going to have the mask | |
11212 | facility. */ | |
11213 | struct value *mask_value, *mark; | |
37e4754d | 11214 | |
9c06b0b4 TJB |
11215 | if (use_mask) |
11216 | error(_("You can specify only one mask.")); | |
37e4754d | 11217 | |
9c06b0b4 | 11218 | use_mask = just_location = 1; |
37e4754d | 11219 | |
9c06b0b4 TJB |
11220 | mark = value_mark (); |
11221 | mask_value = parse_to_comma_and_eval (&value_start); | |
11222 | mask = value_as_address (mask_value); | |
11223 | value_free_to_mark (mark); | |
11224 | } | |
11225 | else | |
11226 | /* We didn't recognize what we found. We should stop here. */ | |
11227 | break; | |
37e4754d | 11228 | |
9c06b0b4 TJB |
11229 | /* Truncate the string and get rid of the "parameter value" pair before |
11230 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11231 | exp_end = tok; |
9c06b0b4 | 11232 | } |
37e4754d | 11233 | } |
bbc13ae3 KS |
11234 | else |
11235 | exp_end = arg; | |
37e4754d | 11236 | |
bbc13ae3 KS |
11237 | /* Parse the rest of the arguments. From here on out, everything |
11238 | is in terms of a newly allocated string instead of the original | |
11239 | ARG. */ | |
c906108c | 11240 | innermost_block = NULL; |
bbc13ae3 KS |
11241 | expression = savestring (arg, exp_end - arg); |
11242 | back_to = make_cleanup (xfree, expression); | |
11243 | exp_start = arg = expression; | |
1bb9788d | 11244 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11245 | exp_end = arg; |
fa8a61dc TT |
11246 | /* Remove trailing whitespace from the expression before saving it. |
11247 | This makes the eventual display of the expression string a bit | |
11248 | prettier. */ | |
11249 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11250 | --exp_end; | |
11251 | ||
65d79d4b SDJ |
11252 | /* Checking if the expression is not constant. */ |
11253 | if (watchpoint_exp_is_const (exp)) | |
11254 | { | |
11255 | int len; | |
11256 | ||
11257 | len = exp_end - exp_start; | |
11258 | while (len > 0 && isspace (exp_start[len - 1])) | |
11259 | len--; | |
11260 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11261 | } | |
11262 | ||
c906108c SS |
11263 | exp_valid_block = innermost_block; |
11264 | mark = value_mark (); | |
3a1115a0 | 11265 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11266 | |
bb9d5f81 PP |
11267 | if (val != NULL && just_location) |
11268 | { | |
11269 | saved_bitpos = value_bitpos (val); | |
11270 | saved_bitsize = value_bitsize (val); | |
11271 | } | |
11272 | ||
06a64a0b TT |
11273 | if (just_location) |
11274 | { | |
9c06b0b4 TJB |
11275 | int ret; |
11276 | ||
06a64a0b | 11277 | exp_valid_block = NULL; |
a1442452 | 11278 | val = value_addr (result); |
06a64a0b TT |
11279 | release_value (val); |
11280 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11281 | |
11282 | if (use_mask) | |
11283 | { | |
11284 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11285 | mask); | |
11286 | if (ret == -1) | |
11287 | error (_("This target does not support masked watchpoints.")); | |
11288 | else if (ret == -2) | |
11289 | error (_("Invalid mask or memory region.")); | |
11290 | } | |
06a64a0b TT |
11291 | } |
11292 | else if (val != NULL) | |
fa4727a6 | 11293 | release_value (val); |
c906108c | 11294 | |
bbc13ae3 KS |
11295 | tok = skip_spaces_const (arg); |
11296 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11297 | |
11298 | toklen = end_tok - tok; | |
11299 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11300 | { | |
2d134ed3 PA |
11301 | struct expression *cond; |
11302 | ||
60e1c644 | 11303 | innermost_block = NULL; |
c906108c | 11304 | tok = cond_start = end_tok + 1; |
1bb9788d | 11305 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11306 | |
11307 | /* The watchpoint expression may not be local, but the condition | |
11308 | may still be. E.g.: `watch global if local > 0'. */ | |
11309 | cond_exp_valid_block = innermost_block; | |
11310 | ||
2d134ed3 | 11311 | xfree (cond); |
c906108c SS |
11312 | cond_end = tok; |
11313 | } | |
11314 | if (*tok) | |
8a3fe4f8 | 11315 | error (_("Junk at end of command.")); |
c906108c | 11316 | |
d983da9c | 11317 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11318 | |
11319 | /* If the expression is "local", then set up a "watchpoint scope" | |
11320 | breakpoint at the point where we've left the scope of the watchpoint | |
11321 | expression. Create the scope breakpoint before the watchpoint, so | |
11322 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11323 | if (exp_valid_block && frame) |
d983da9c | 11324 | { |
edb3359d DJ |
11325 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11326 | { | |
11327 | scope_breakpoint | |
a6d9a66e UW |
11328 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11329 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11330 | bp_watchpoint_scope, |
11331 | &momentary_breakpoint_ops); | |
d983da9c | 11332 | |
edb3359d | 11333 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11334 | |
edb3359d DJ |
11335 | /* Automatically delete the breakpoint when it hits. */ |
11336 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11337 | |
edb3359d DJ |
11338 | /* Only break in the proper frame (help with recursion). */ |
11339 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11340 | |
edb3359d | 11341 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11342 | scope_breakpoint->loc->gdbarch |
11343 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11344 | scope_breakpoint->loc->requested_address |
11345 | = frame_unwind_caller_pc (frame); | |
11346 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11347 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11348 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11349 | scope_breakpoint->type); |
11350 | } | |
d983da9c DJ |
11351 | } |
11352 | ||
e8369a73 AB |
11353 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11354 | watchpoints here even if hardware watchpoints are turned off, a call | |
11355 | to update_watchpoint later in this function will cause the type to | |
11356 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11357 | ||
11358 | if (accessflag == hw_read) | |
11359 | bp_type = bp_read_watchpoint; | |
11360 | else if (accessflag == hw_access) | |
11361 | bp_type = bp_access_watchpoint; | |
11362 | else | |
11363 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11364 | |
11365 | w = XCNEW (struct watchpoint); | |
11366 | b = &w->base; | |
348d480f | 11367 | if (use_mask) |
3a5c3e22 PA |
11368 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11369 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11370 | else |
3a5c3e22 PA |
11371 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11372 | &watchpoint_breakpoint_ops); | |
37e4754d | 11373 | b->thread = thread; |
b5de0fa7 | 11374 | b->disposition = disp_donttouch; |
348d480f | 11375 | b->pspace = current_program_space; |
3a5c3e22 PA |
11376 | w->exp = exp; |
11377 | w->exp_valid_block = exp_valid_block; | |
11378 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11379 | if (just_location) |
11380 | { | |
11381 | struct type *t = value_type (val); | |
11382 | CORE_ADDR addr = value_as_address (val); | |
11383 | char *name; | |
11384 | ||
11385 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11386 | name = type_to_string (t); | |
11387 | ||
3a5c3e22 | 11388 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11389 | core_addr_to_string (addr)); |
06a64a0b TT |
11390 | xfree (name); |
11391 | ||
3a5c3e22 | 11392 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11393 | (int) (exp_end - exp_start), exp_start); |
11394 | ||
06a64a0b TT |
11395 | /* The above expression is in C. */ |
11396 | b->language = language_c; | |
11397 | } | |
11398 | else | |
3a5c3e22 | 11399 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11400 | |
11401 | if (use_mask) | |
11402 | { | |
3a5c3e22 | 11403 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11404 | } |
11405 | else | |
11406 | { | |
3a5c3e22 | 11407 | w->val = val; |
bb9d5f81 PP |
11408 | w->val_bitpos = saved_bitpos; |
11409 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11410 | w->val_valid = 1; |
9c06b0b4 | 11411 | } |
77b06cd7 | 11412 | |
c906108c SS |
11413 | if (cond_start) |
11414 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11415 | else | |
11416 | b->cond_string = 0; | |
c5aa993b | 11417 | |
c906108c | 11418 | if (frame) |
f6bc2008 | 11419 | { |
3a5c3e22 PA |
11420 | w->watchpoint_frame = get_frame_id (frame); |
11421 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11422 | } |
c906108c | 11423 | else |
f6bc2008 | 11424 | { |
3a5c3e22 PA |
11425 | w->watchpoint_frame = null_frame_id; |
11426 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11427 | } |
c906108c | 11428 | |
d983da9c | 11429 | if (scope_breakpoint != NULL) |
c906108c | 11430 | { |
d983da9c DJ |
11431 | /* The scope breakpoint is related to the watchpoint. We will |
11432 | need to act on them together. */ | |
11433 | b->related_breakpoint = scope_breakpoint; | |
11434 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11435 | } |
d983da9c | 11436 | |
06a64a0b TT |
11437 | if (!just_location) |
11438 | value_free_to_mark (mark); | |
2d134ed3 | 11439 | |
492d29ea | 11440 | TRY |
a9634178 TJB |
11441 | { |
11442 | /* Finally update the new watchpoint. This creates the locations | |
11443 | that should be inserted. */ | |
3a5c3e22 | 11444 | update_watchpoint (w, 1); |
a9634178 | 11445 | } |
492d29ea | 11446 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11447 | { |
11448 | delete_breakpoint (b); | |
11449 | throw_exception (e); | |
11450 | } | |
492d29ea | 11451 | END_CATCH |
a9634178 | 11452 | |
3ea46bff | 11453 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11454 | do_cleanups (back_to); |
c906108c SS |
11455 | } |
11456 | ||
e09342b5 | 11457 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11458 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11459 | |
c906108c | 11460 | static int |
a9634178 | 11461 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11462 | { |
11463 | int found_memory_cnt = 0; | |
2e70b7b9 | 11464 | struct value *head = v; |
c906108c SS |
11465 | |
11466 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11467 | if (!can_use_hw_watchpoints) |
c906108c | 11468 | return 0; |
c5aa993b | 11469 | |
5c44784c JM |
11470 | /* Make sure that the value of the expression depends only upon |
11471 | memory contents, and values computed from them within GDB. If we | |
11472 | find any register references or function calls, we can't use a | |
11473 | hardware watchpoint. | |
11474 | ||
11475 | The idea here is that evaluating an expression generates a series | |
11476 | of values, one holding the value of every subexpression. (The | |
11477 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11478 | a*b+c.) GDB's values hold almost enough information to establish | |
11479 | the criteria given above --- they identify memory lvalues, | |
11480 | register lvalues, computed values, etcetera. So we can evaluate | |
11481 | the expression, and then scan the chain of values that leaves | |
11482 | behind to decide whether we can detect any possible change to the | |
11483 | expression's final value using only hardware watchpoints. | |
11484 | ||
11485 | However, I don't think that the values returned by inferior | |
11486 | function calls are special in any way. So this function may not | |
11487 | notice that an expression involving an inferior function call | |
11488 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11489 | for (; v; v = value_next (v)) |
c906108c | 11490 | { |
5c44784c | 11491 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11492 | { |
8464be76 DJ |
11493 | if (v != head && value_lazy (v)) |
11494 | /* A lazy memory lvalue in the chain is one that GDB never | |
11495 | needed to fetch; we either just used its address (e.g., | |
11496 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11497 | in `a,b'). This doesn't apply to HEAD; if that is | |
11498 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11499 | ; |
53a5351d | 11500 | else |
5c44784c JM |
11501 | { |
11502 | /* Ahh, memory we actually used! Check if we can cover | |
11503 | it with hardware watchpoints. */ | |
df407dfe | 11504 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11505 | |
11506 | /* We only watch structs and arrays if user asked for it | |
11507 | explicitly, never if they just happen to appear in a | |
11508 | middle of some value chain. */ | |
11509 | if (v == head | |
11510 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11511 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11512 | { | |
42ae5230 | 11513 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11514 | int len; |
11515 | int num_regs; | |
11516 | ||
a9634178 | 11517 | len = (target_exact_watchpoints |
e09342b5 TJB |
11518 | && is_scalar_type_recursive (vtype))? |
11519 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11520 | |
e09342b5 TJB |
11521 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11522 | if (!num_regs) | |
2e70b7b9 MS |
11523 | return 0; |
11524 | else | |
e09342b5 | 11525 | found_memory_cnt += num_regs; |
2e70b7b9 | 11526 | } |
5c44784c | 11527 | } |
c5aa993b | 11528 | } |
5086187c AC |
11529 | else if (VALUE_LVAL (v) != not_lval |
11530 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11531 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11532 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11533 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11534 | } |
11535 | ||
11536 | /* The expression itself looks suitable for using a hardware | |
11537 | watchpoint, but give the target machine a chance to reject it. */ | |
11538 | return found_memory_cnt; | |
11539 | } | |
11540 | ||
8b93c638 | 11541 | void |
84f4c1fe | 11542 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11543 | { |
84f4c1fe | 11544 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11545 | } |
11546 | ||
06a64a0b TT |
11547 | /* A helper function that looks for the "-location" argument and then |
11548 | calls watch_command_1. */ | |
11549 | ||
11550 | static void | |
11551 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11552 | { | |
11553 | int just_location = 0; | |
11554 | ||
11555 | if (arg | |
11556 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11557 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11558 | { | |
e9cafbcc | 11559 | arg = skip_spaces (arg); |
06a64a0b TT |
11560 | just_location = 1; |
11561 | } | |
11562 | ||
84f4c1fe | 11563 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11564 | } |
8926118c | 11565 | |
c5aa993b | 11566 | static void |
fba45db2 | 11567 | watch_command (char *arg, int from_tty) |
c906108c | 11568 | { |
06a64a0b | 11569 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11570 | } |
11571 | ||
8b93c638 | 11572 | void |
84f4c1fe | 11573 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11574 | { |
84f4c1fe | 11575 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11576 | } |
8926118c | 11577 | |
c5aa993b | 11578 | static void |
fba45db2 | 11579 | rwatch_command (char *arg, int from_tty) |
c906108c | 11580 | { |
06a64a0b | 11581 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11582 | } |
11583 | ||
8b93c638 | 11584 | void |
84f4c1fe | 11585 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11586 | { |
84f4c1fe | 11587 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11588 | } |
8926118c | 11589 | |
c5aa993b | 11590 | static void |
fba45db2 | 11591 | awatch_command (char *arg, int from_tty) |
c906108c | 11592 | { |
06a64a0b | 11593 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11594 | } |
c906108c | 11595 | \f |
c5aa993b | 11596 | |
cfc31633 PA |
11597 | /* Data for the FSM that manages the until(location)/advance commands |
11598 | in infcmd.c. Here because it uses the mechanisms of | |
11599 | breakpoints. */ | |
c906108c | 11600 | |
cfc31633 | 11601 | struct until_break_fsm |
bfec99b2 | 11602 | { |
cfc31633 PA |
11603 | /* The base class. */ |
11604 | struct thread_fsm thread_fsm; | |
11605 | ||
11606 | /* The thread that as current when the command was executed. */ | |
11607 | int thread; | |
11608 | ||
11609 | /* The breakpoint set at the destination location. */ | |
11610 | struct breakpoint *location_breakpoint; | |
11611 | ||
11612 | /* Breakpoint set at the return address in the caller frame. May be | |
11613 | NULL. */ | |
11614 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11615 | }; |
11616 | ||
cfc31633 PA |
11617 | static void until_break_fsm_clean_up (struct thread_fsm *self); |
11618 | static int until_break_fsm_should_stop (struct thread_fsm *self); | |
11619 | static enum async_reply_reason | |
11620 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11621 | ||
11622 | /* until_break_fsm's vtable. */ | |
11623 | ||
11624 | static struct thread_fsm_ops until_break_fsm_ops = | |
11625 | { | |
11626 | NULL, /* dtor */ | |
11627 | until_break_fsm_clean_up, | |
11628 | until_break_fsm_should_stop, | |
11629 | NULL, /* return_value */ | |
11630 | until_break_fsm_async_reply_reason, | |
11631 | }; | |
11632 | ||
11633 | /* Allocate a new until_break_command_fsm. */ | |
11634 | ||
11635 | static struct until_break_fsm * | |
11636 | new_until_break_fsm (int thread, | |
11637 | struct breakpoint *location_breakpoint, | |
11638 | struct breakpoint *caller_breakpoint) | |
11639 | { | |
11640 | struct until_break_fsm *sm; | |
11641 | ||
11642 | sm = XCNEW (struct until_break_fsm); | |
11643 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops); | |
11644 | ||
11645 | sm->thread = thread; | |
11646 | sm->location_breakpoint = location_breakpoint; | |
11647 | sm->caller_breakpoint = caller_breakpoint; | |
11648 | ||
11649 | return sm; | |
11650 | } | |
11651 | ||
11652 | /* Implementation of the 'should_stop' FSM method for the | |
11653 | until(location)/advance commands. */ | |
11654 | ||
11655 | static int | |
11656 | until_break_fsm_should_stop (struct thread_fsm *self) | |
11657 | { | |
11658 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
11659 | struct thread_info *tp = inferior_thread (); | |
11660 | ||
11661 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11662 | sm->location_breakpoint) != NULL | |
11663 | || (sm->caller_breakpoint != NULL | |
11664 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11665 | sm->caller_breakpoint) != NULL)) | |
11666 | thread_fsm_set_finished (self); | |
11667 | ||
11668 | return 1; | |
11669 | } | |
11670 | ||
11671 | /* Implementation of the 'clean_up' FSM method for the | |
11672 | until(location)/advance commands. */ | |
11673 | ||
c2c6d25f | 11674 | static void |
cfc31633 | 11675 | until_break_fsm_clean_up (struct thread_fsm *self) |
43ff13b4 | 11676 | { |
cfc31633 | 11677 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11678 | |
cfc31633 PA |
11679 | /* Clean up our temporary breakpoints. */ |
11680 | if (sm->location_breakpoint != NULL) | |
11681 | { | |
11682 | delete_breakpoint (sm->location_breakpoint); | |
11683 | sm->location_breakpoint = NULL; | |
11684 | } | |
11685 | if (sm->caller_breakpoint != NULL) | |
11686 | { | |
11687 | delete_breakpoint (sm->caller_breakpoint); | |
11688 | sm->caller_breakpoint = NULL; | |
11689 | } | |
11690 | delete_longjmp_breakpoint (sm->thread); | |
11691 | } | |
11692 | ||
11693 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11694 | until(location)/advance commands. */ | |
11695 | ||
11696 | static enum async_reply_reason | |
11697 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11698 | { | |
11699 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11700 | } |
11701 | ||
c906108c | 11702 | void |
ae66c1fc | 11703 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11704 | { |
11705 | struct symtabs_and_lines sals; | |
11706 | struct symtab_and_line sal; | |
8556afb4 PA |
11707 | struct frame_info *frame; |
11708 | struct gdbarch *frame_gdbarch; | |
11709 | struct frame_id stack_frame_id; | |
11710 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11711 | struct breakpoint *location_breakpoint; |
11712 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11713 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11714 | int thread; |
11715 | struct thread_info *tp; | |
f00aae0f | 11716 | struct event_location *location; |
cfc31633 | 11717 | struct until_break_fsm *sm; |
c906108c | 11718 | |
70509625 | 11719 | clear_proceed_status (0); |
c906108c SS |
11720 | |
11721 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11722 | this function. */ |
c5aa993b | 11723 | |
f00aae0f KS |
11724 | location = string_to_event_location (&arg, current_language); |
11725 | cleanup = make_cleanup_delete_event_location (location); | |
11726 | ||
1bfeeb0f | 11727 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11728 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11729 | get_last_displayed_symtab (), |
f8eba3c6 | 11730 | get_last_displayed_line ()); |
c906108c | 11731 | else |
f00aae0f | 11732 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11733 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11734 | |
c906108c | 11735 | if (sals.nelts != 1) |
8a3fe4f8 | 11736 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11737 | |
c906108c | 11738 | sal = sals.sals[0]; |
4a64f543 | 11739 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11740 | |
c906108c | 11741 | if (*arg) |
8a3fe4f8 | 11742 | error (_("Junk at end of arguments.")); |
c5aa993b | 11743 | |
c906108c | 11744 | resolve_sal_pc (&sal); |
c5aa993b | 11745 | |
186c406b | 11746 | tp = inferior_thread (); |
5d5658a1 | 11747 | thread = tp->global_num; |
186c406b | 11748 | |
883bc8d1 PA |
11749 | old_chain = make_cleanup (null_cleanup, NULL); |
11750 | ||
8556afb4 PA |
11751 | /* Note linespec handling above invalidates the frame chain. |
11752 | Installing a breakpoint also invalidates the frame chain (as it | |
11753 | may need to switch threads), so do any frame handling before | |
11754 | that. */ | |
11755 | ||
11756 | frame = get_selected_frame (NULL); | |
11757 | frame_gdbarch = get_frame_arch (frame); | |
11758 | stack_frame_id = get_stack_frame_id (frame); | |
11759 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11760 | |
ae66c1fc EZ |
11761 | /* Keep within the current frame, or in frames called by the current |
11762 | one. */ | |
edb3359d | 11763 | |
883bc8d1 | 11764 | if (frame_id_p (caller_frame_id)) |
c906108c | 11765 | { |
883bc8d1 | 11766 | struct symtab_and_line sal2; |
cfc31633 | 11767 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11768 | |
11769 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11770 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11771 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11772 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11773 | sal2, | |
11774 | caller_frame_id, | |
11775 | bp_until); | |
11776 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11777 | |
883bc8d1 | 11778 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11779 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11780 | } |
c5aa993b | 11781 | |
c70a6932 JK |
11782 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11783 | frame = NULL; | |
11784 | ||
883bc8d1 PA |
11785 | if (anywhere) |
11786 | /* If the user told us to continue until a specified location, | |
11787 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11788 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11789 | null_frame_id, bp_until); | |
883bc8d1 PA |
11790 | else |
11791 | /* Otherwise, specify the selected frame, because we want to stop | |
11792 | only at the very same frame. */ | |
cfc31633 PA |
11793 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11794 | stack_frame_id, bp_until); | |
11795 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11796 | |
5d5658a1 PA |
11797 | sm = new_until_break_fsm (tp->global_num, |
11798 | location_breakpoint, caller_breakpoint); | |
cfc31633 | 11799 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11800 | |
cfc31633 | 11801 | discard_cleanups (old_chain); |
f107f563 | 11802 | |
cfc31633 | 11803 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11804 | |
11805 | do_cleanups (cleanup); | |
c906108c | 11806 | } |
ae66c1fc | 11807 | |
c906108c SS |
11808 | /* This function attempts to parse an optional "if <cond>" clause |
11809 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11810 | |
c906108c SS |
11811 | Else, it returns a pointer to the condition string. (It does not |
11812 | attempt to evaluate the string against a particular block.) And, | |
11813 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11814 | if clause in the arg string. */ |
53a5351d | 11815 | |
916703c0 | 11816 | char * |
fba45db2 | 11817 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11818 | { |
c5aa993b JM |
11819 | char *cond_string; |
11820 | ||
11821 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11822 | return NULL; |
c5aa993b | 11823 | |
4a64f543 | 11824 | /* Skip the "if" keyword. */ |
c906108c | 11825 | (*arg) += 2; |
c5aa993b | 11826 | |
c906108c | 11827 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11828 | condition string. */ |
e9cafbcc | 11829 | *arg = skip_spaces (*arg); |
c906108c | 11830 | cond_string = *arg; |
c5aa993b | 11831 | |
4a64f543 MS |
11832 | /* Assume that the condition occupies the remainder of the arg |
11833 | string. */ | |
c906108c | 11834 | (*arg) += strlen (cond_string); |
c5aa993b | 11835 | |
c906108c SS |
11836 | return cond_string; |
11837 | } | |
c5aa993b | 11838 | |
c906108c SS |
11839 | /* Commands to deal with catching events, such as signals, exceptions, |
11840 | process start/exit, etc. */ | |
c5aa993b JM |
11841 | |
11842 | typedef enum | |
11843 | { | |
44feb3ce TT |
11844 | catch_fork_temporary, catch_vfork_temporary, |
11845 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11846 | } |
11847 | catch_fork_kind; | |
11848 | ||
c906108c | 11849 | static void |
cc59ec59 MS |
11850 | catch_fork_command_1 (char *arg, int from_tty, |
11851 | struct cmd_list_element *command) | |
c906108c | 11852 | { |
a6d9a66e | 11853 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11854 | char *cond_string = NULL; |
44feb3ce TT |
11855 | catch_fork_kind fork_kind; |
11856 | int tempflag; | |
11857 | ||
11858 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11859 | tempflag = (fork_kind == catch_fork_temporary | |
11860 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11861 | |
44feb3ce TT |
11862 | if (!arg) |
11863 | arg = ""; | |
e9cafbcc | 11864 | arg = skip_spaces (arg); |
c5aa993b | 11865 | |
c906108c | 11866 | /* The allowed syntax is: |
c5aa993b JM |
11867 | catch [v]fork |
11868 | catch [v]fork if <cond> | |
11869 | ||
4a64f543 | 11870 | First, check if there's an if clause. */ |
c906108c | 11871 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11872 | |
c906108c | 11873 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11874 | error (_("Junk at end of arguments.")); |
c5aa993b | 11875 | |
c906108c | 11876 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11877 | and enable reporting of such events. */ |
c5aa993b JM |
11878 | switch (fork_kind) |
11879 | { | |
44feb3ce TT |
11880 | case catch_fork_temporary: |
11881 | case catch_fork_permanent: | |
a6d9a66e | 11882 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11883 | &catch_fork_breakpoint_ops); |
c906108c | 11884 | break; |
44feb3ce TT |
11885 | case catch_vfork_temporary: |
11886 | case catch_vfork_permanent: | |
a6d9a66e | 11887 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11888 | &catch_vfork_breakpoint_ops); |
c906108c | 11889 | break; |
c5aa993b | 11890 | default: |
8a3fe4f8 | 11891 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11892 | break; |
c5aa993b | 11893 | } |
c906108c SS |
11894 | } |
11895 | ||
11896 | static void | |
cc59ec59 MS |
11897 | catch_exec_command_1 (char *arg, int from_tty, |
11898 | struct cmd_list_element *command) | |
c906108c | 11899 | { |
b4d90040 | 11900 | struct exec_catchpoint *c; |
a6d9a66e | 11901 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11902 | int tempflag; |
c5aa993b | 11903 | char *cond_string = NULL; |
c906108c | 11904 | |
44feb3ce TT |
11905 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11906 | ||
11907 | if (!arg) | |
11908 | arg = ""; | |
e9cafbcc | 11909 | arg = skip_spaces (arg); |
c906108c SS |
11910 | |
11911 | /* The allowed syntax is: | |
c5aa993b JM |
11912 | catch exec |
11913 | catch exec if <cond> | |
c906108c | 11914 | |
4a64f543 | 11915 | First, check if there's an if clause. */ |
c906108c SS |
11916 | cond_string = ep_parse_optional_if_clause (&arg); |
11917 | ||
11918 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11919 | error (_("Junk at end of arguments.")); |
c906108c | 11920 | |
b4d90040 PA |
11921 | c = XNEW (struct exec_catchpoint); |
11922 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11923 | &catch_exec_breakpoint_ops); | |
11924 | c->exec_pathname = NULL; | |
11925 | ||
3ea46bff | 11926 | install_breakpoint (0, &c->base, 1); |
c906108c | 11927 | } |
c5aa993b | 11928 | |
9ac4176b | 11929 | void |
28010a5d PA |
11930 | init_ada_exception_breakpoint (struct breakpoint *b, |
11931 | struct gdbarch *gdbarch, | |
11932 | struct symtab_and_line sal, | |
11933 | char *addr_string, | |
c0a91b2b | 11934 | const struct breakpoint_ops *ops, |
28010a5d | 11935 | int tempflag, |
349774ef | 11936 | int enabled, |
28010a5d | 11937 | int from_tty) |
f7f9143b | 11938 | { |
f7f9143b JB |
11939 | if (from_tty) |
11940 | { | |
5af949e3 UW |
11941 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11942 | if (!loc_gdbarch) | |
11943 | loc_gdbarch = gdbarch; | |
11944 | ||
6c95b8df PA |
11945 | describe_other_breakpoints (loc_gdbarch, |
11946 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11947 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11948 | version for exception catchpoints, because two catchpoints | |
11949 | used for different exception names will use the same address. | |
11950 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11951 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11952 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11953 | the user what type of catchpoint it is. The above is good |
11954 | enough for now, though. */ | |
11955 | } | |
11956 | ||
28010a5d | 11957 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11958 | |
349774ef | 11959 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11960 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11961 | b->location = string_to_event_location (&addr_string, |
11962 | language_def (language_ada)); | |
f7f9143b | 11963 | b->language = language_ada; |
f7f9143b JB |
11964 | } |
11965 | ||
c906108c | 11966 | static void |
fba45db2 | 11967 | catch_command (char *arg, int from_tty) |
c906108c | 11968 | { |
44feb3ce | 11969 | error (_("Catch requires an event name.")); |
c906108c SS |
11970 | } |
11971 | \f | |
11972 | ||
11973 | static void | |
fba45db2 | 11974 | tcatch_command (char *arg, int from_tty) |
c906108c | 11975 | { |
44feb3ce | 11976 | error (_("Catch requires an event name.")); |
c906108c SS |
11977 | } |
11978 | ||
8a2c437b TT |
11979 | /* A qsort comparison function that sorts breakpoints in order. */ |
11980 | ||
11981 | static int | |
11982 | compare_breakpoints (const void *a, const void *b) | |
11983 | { | |
9a3c8263 | 11984 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11985 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11986 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11987 | uintptr_t ub = (uintptr_t) *bb; |
11988 | ||
11989 | if ((*ba)->number < (*bb)->number) | |
11990 | return -1; | |
11991 | else if ((*ba)->number > (*bb)->number) | |
11992 | return 1; | |
11993 | ||
11994 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11995 | the number 0. */ | |
11996 | if (ua < ub) | |
11997 | return -1; | |
94b0e70d | 11998 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11999 | } |
12000 | ||
80f8a6eb | 12001 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12002 | |
12003 | static void | |
fba45db2 | 12004 | clear_command (char *arg, int from_tty) |
c906108c | 12005 | { |
8a2c437b | 12006 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12007 | VEC(breakpoint_p) *found = 0; |
12008 | int ix; | |
c906108c SS |
12009 | int default_match; |
12010 | struct symtabs_and_lines sals; | |
12011 | struct symtab_and_line sal; | |
c906108c | 12012 | int i; |
8a2c437b | 12013 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12014 | |
12015 | if (arg) | |
12016 | { | |
39cf75f7 DE |
12017 | sals = decode_line_with_current_source (arg, |
12018 | (DECODE_LINE_FUNFIRSTLINE | |
12019 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12020 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12021 | default_match = 0; |
12022 | } | |
12023 | else | |
12024 | { | |
8d749320 | 12025 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12026 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12027 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12028 | |
12029 | /* Set sal's line, symtab, pc, and pspace to the values | |
12030 | corresponding to the last call to print_frame_info. If the | |
12031 | codepoint is not valid, this will set all the fields to 0. */ | |
12032 | get_last_displayed_sal (&sal); | |
c906108c | 12033 | if (sal.symtab == 0) |
8a3fe4f8 | 12034 | error (_("No source file specified.")); |
c906108c SS |
12035 | |
12036 | sals.sals[0] = sal; | |
12037 | sals.nelts = 1; | |
12038 | ||
12039 | default_match = 1; | |
12040 | } | |
12041 | ||
4a64f543 MS |
12042 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12043 | seems, because all existing breakpoints typically have both | |
12044 | file/line and pc set. So, if clear is given file/line, we can | |
12045 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12046 | |
12047 | We only support clearing given the address explicitly | |
12048 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12049 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12050 | due to optimization, all in one block. |
4a64f543 MS |
12051 | |
12052 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12053 | PC corresponding to the same file:line, the breakpoint won't |
12054 | be cleared. We probably can still clear the breakpoint, but | |
12055 | since the other PC value is never presented to user, user | |
12056 | can only find it by guessing, and it does not seem important | |
12057 | to support that. */ | |
12058 | ||
4a64f543 MS |
12059 | /* For each line spec given, delete bps which correspond to it. Do |
12060 | it in two passes, solely to preserve the current behavior that | |
12061 | from_tty is forced true if we delete more than one | |
12062 | breakpoint. */ | |
c906108c | 12063 | |
80f8a6eb | 12064 | found = NULL; |
8a2c437b | 12065 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12066 | for (i = 0; i < sals.nelts; i++) |
12067 | { | |
05cba821 JK |
12068 | const char *sal_fullname; |
12069 | ||
c906108c | 12070 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12071 | If line given (pc == 0), clear all bpts on specified line. |
12072 | If defaulting, clear all bpts on default line | |
c906108c | 12073 | or at default pc. |
c5aa993b JM |
12074 | |
12075 | defaulting sal.pc != 0 tests to do | |
12076 | ||
12077 | 0 1 pc | |
12078 | 1 1 pc _and_ line | |
12079 | 0 0 line | |
12080 | 1 0 <can't happen> */ | |
c906108c SS |
12081 | |
12082 | sal = sals.sals[i]; | |
05cba821 JK |
12083 | sal_fullname = (sal.symtab == NULL |
12084 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12085 | |
4a64f543 | 12086 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12087 | ALL_BREAKPOINTS (b) |
c5aa993b | 12088 | { |
0d381245 | 12089 | int match = 0; |
4a64f543 | 12090 | /* Are we going to delete b? */ |
cc60f2e3 | 12091 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12092 | { |
12093 | struct bp_location *loc = b->loc; | |
12094 | for (; loc; loc = loc->next) | |
12095 | { | |
f8eba3c6 TT |
12096 | /* If the user specified file:line, don't allow a PC |
12097 | match. This matches historical gdb behavior. */ | |
12098 | int pc_match = (!sal.explicit_line | |
12099 | && sal.pc | |
12100 | && (loc->pspace == sal.pspace) | |
12101 | && (loc->address == sal.pc) | |
12102 | && (!section_is_overlay (loc->section) | |
12103 | || loc->section == sal.section)); | |
4aac40c8 TT |
12104 | int line_match = 0; |
12105 | ||
12106 | if ((default_match || sal.explicit_line) | |
2f202fde | 12107 | && loc->symtab != NULL |
05cba821 | 12108 | && sal_fullname != NULL |
4aac40c8 | 12109 | && sal.pspace == loc->pspace |
05cba821 JK |
12110 | && loc->line_number == sal.line |
12111 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12112 | sal_fullname) == 0) | |
12113 | line_match = 1; | |
4aac40c8 | 12114 | |
0d381245 VP |
12115 | if (pc_match || line_match) |
12116 | { | |
12117 | match = 1; | |
12118 | break; | |
12119 | } | |
12120 | } | |
12121 | } | |
12122 | ||
12123 | if (match) | |
d6e956e5 | 12124 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12125 | } |
80f8a6eb | 12126 | } |
8a2c437b | 12127 | |
80f8a6eb | 12128 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12129 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12130 | { |
12131 | if (arg) | |
8a3fe4f8 | 12132 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12133 | else |
8a3fe4f8 | 12134 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12135 | } |
c906108c | 12136 | |
8a2c437b TT |
12137 | /* Remove duplicates from the vec. */ |
12138 | qsort (VEC_address (breakpoint_p, found), | |
12139 | VEC_length (breakpoint_p, found), | |
12140 | sizeof (breakpoint_p), | |
12141 | compare_breakpoints); | |
12142 | prev = VEC_index (breakpoint_p, found, 0); | |
12143 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12144 | { | |
12145 | if (b == prev) | |
12146 | { | |
12147 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12148 | --ix; | |
12149 | } | |
12150 | } | |
12151 | ||
d6e956e5 | 12152 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12153 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12154 | if (from_tty) |
a3f17187 | 12155 | { |
d6e956e5 | 12156 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12157 | printf_unfiltered (_("Deleted breakpoint ")); |
12158 | else | |
12159 | printf_unfiltered (_("Deleted breakpoints ")); | |
12160 | } | |
d6e956e5 VP |
12161 | |
12162 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12163 | { |
c5aa993b | 12164 | if (from_tty) |
d6e956e5 VP |
12165 | printf_unfiltered ("%d ", b->number); |
12166 | delete_breakpoint (b); | |
c906108c | 12167 | } |
80f8a6eb MS |
12168 | if (from_tty) |
12169 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12170 | |
12171 | do_cleanups (cleanups); | |
c906108c SS |
12172 | } |
12173 | \f | |
12174 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12175 | all breakpoints that are marked for deletion, whether hit or not. | |
12176 | This is called after any breakpoint is hit, or after errors. */ | |
12177 | ||
12178 | void | |
fba45db2 | 12179 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12180 | { |
35df4500 | 12181 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12182 | |
12183 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12184 | if (bs->breakpoint_at |
12185 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12186 | && bs->stop) |
f431efe5 | 12187 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12188 | |
35df4500 | 12189 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12190 | { |
b5de0fa7 | 12191 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12192 | delete_breakpoint (b); |
12193 | } | |
c906108c SS |
12194 | } |
12195 | ||
4a64f543 MS |
12196 | /* A comparison function for bp_location AP and BP being interfaced to |
12197 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12198 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12199 | secondarily by ordering first permanent elements and |
4a64f543 | 12200 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12201 | qsort being an unstable algorithm. */ |
876fa593 JK |
12202 | |
12203 | static int | |
494cfb0f | 12204 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12205 | { |
9a3c8263 SM |
12206 | const struct bp_location *a = *(const struct bp_location **) ap; |
12207 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12208 | |
12209 | if (a->address != b->address) | |
12210 | return (a->address > b->address) - (a->address < b->address); | |
12211 | ||
dea2aa5f LM |
12212 | /* Sort locations at the same address by their pspace number, keeping |
12213 | locations of the same inferior (in a multi-inferior environment) | |
12214 | grouped. */ | |
12215 | ||
12216 | if (a->pspace->num != b->pspace->num) | |
12217 | return ((a->pspace->num > b->pspace->num) | |
12218 | - (a->pspace->num < b->pspace->num)); | |
12219 | ||
876fa593 | 12220 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12221 | if (a->permanent != b->permanent) |
12222 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12223 | |
c56a97f9 JK |
12224 | /* Make the internal GDB representation stable across GDB runs |
12225 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12226 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12227 | |
12228 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12229 | return ((a->owner->number > b->owner->number) |
12230 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12231 | |
12232 | return (a > b) - (a < b); | |
12233 | } | |
12234 | ||
876fa593 | 12235 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12236 | bp_location_shadow_len_after_address_max according to the current |
12237 | content of the bp_location array. */ | |
f7545552 TT |
12238 | |
12239 | static void | |
876fa593 | 12240 | bp_location_target_extensions_update (void) |
f7545552 | 12241 | { |
876fa593 JK |
12242 | struct bp_location *bl, **blp_tmp; |
12243 | ||
12244 | bp_location_placed_address_before_address_max = 0; | |
12245 | bp_location_shadow_len_after_address_max = 0; | |
12246 | ||
12247 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12248 | { | |
12249 | CORE_ADDR start, end, addr; | |
12250 | ||
12251 | if (!bp_location_has_shadow (bl)) | |
12252 | continue; | |
12253 | ||
12254 | start = bl->target_info.placed_address; | |
12255 | end = start + bl->target_info.shadow_len; | |
12256 | ||
12257 | gdb_assert (bl->address >= start); | |
12258 | addr = bl->address - start; | |
12259 | if (addr > bp_location_placed_address_before_address_max) | |
12260 | bp_location_placed_address_before_address_max = addr; | |
12261 | ||
12262 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12263 | ||
12264 | gdb_assert (bl->address < end); | |
12265 | addr = end - bl->address; | |
12266 | if (addr > bp_location_shadow_len_after_address_max) | |
12267 | bp_location_shadow_len_after_address_max = addr; | |
12268 | } | |
f7545552 TT |
12269 | } |
12270 | ||
1e4d1764 YQ |
12271 | /* Download tracepoint locations if they haven't been. */ |
12272 | ||
12273 | static void | |
12274 | download_tracepoint_locations (void) | |
12275 | { | |
7ed2c994 | 12276 | struct breakpoint *b; |
1e4d1764 | 12277 | struct cleanup *old_chain; |
dd2e65cc | 12278 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12279 | |
12280 | old_chain = save_current_space_and_thread (); | |
12281 | ||
7ed2c994 | 12282 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12283 | { |
7ed2c994 | 12284 | struct bp_location *bl; |
1e4d1764 | 12285 | struct tracepoint *t; |
f2a8bc8a | 12286 | int bp_location_downloaded = 0; |
1e4d1764 | 12287 | |
7ed2c994 | 12288 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12289 | ? !may_insert_fast_tracepoints |
12290 | : !may_insert_tracepoints)) | |
12291 | continue; | |
12292 | ||
dd2e65cc YQ |
12293 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12294 | { | |
12295 | if (target_can_download_tracepoint ()) | |
12296 | can_download_tracepoint = TRIBOOL_TRUE; | |
12297 | else | |
12298 | can_download_tracepoint = TRIBOOL_FALSE; | |
12299 | } | |
12300 | ||
12301 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12302 | break; | |
12303 | ||
7ed2c994 YQ |
12304 | for (bl = b->loc; bl; bl = bl->next) |
12305 | { | |
12306 | /* In tracepoint, locations are _never_ duplicated, so | |
12307 | should_be_inserted is equivalent to | |
12308 | unduplicated_should_be_inserted. */ | |
12309 | if (!should_be_inserted (bl) || bl->inserted) | |
12310 | continue; | |
1e4d1764 | 12311 | |
7ed2c994 | 12312 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12313 | |
7ed2c994 | 12314 | target_download_tracepoint (bl); |
1e4d1764 | 12315 | |
7ed2c994 | 12316 | bl->inserted = 1; |
f2a8bc8a | 12317 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12318 | } |
12319 | t = (struct tracepoint *) b; | |
12320 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12321 | if (bp_location_downloaded) |
12322 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12323 | } |
12324 | ||
12325 | do_cleanups (old_chain); | |
12326 | } | |
12327 | ||
934709f0 PW |
12328 | /* Swap the insertion/duplication state between two locations. */ |
12329 | ||
12330 | static void | |
12331 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12332 | { | |
12333 | const int left_inserted = left->inserted; | |
12334 | const int left_duplicate = left->duplicate; | |
b775012e | 12335 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12336 | const struct bp_target_info left_target_info = left->target_info; |
12337 | ||
1e4d1764 YQ |
12338 | /* Locations of tracepoints can never be duplicated. */ |
12339 | if (is_tracepoint (left->owner)) | |
12340 | gdb_assert (!left->duplicate); | |
12341 | if (is_tracepoint (right->owner)) | |
12342 | gdb_assert (!right->duplicate); | |
12343 | ||
934709f0 PW |
12344 | left->inserted = right->inserted; |
12345 | left->duplicate = right->duplicate; | |
b775012e | 12346 | left->needs_update = right->needs_update; |
934709f0 PW |
12347 | left->target_info = right->target_info; |
12348 | right->inserted = left_inserted; | |
12349 | right->duplicate = left_duplicate; | |
b775012e | 12350 | right->needs_update = left_needs_update; |
934709f0 PW |
12351 | right->target_info = left_target_info; |
12352 | } | |
12353 | ||
b775012e LM |
12354 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12355 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12356 | conditions on the target's side. Such conditions need to be updated on | |
12357 | the target. */ | |
12358 | ||
12359 | static void | |
12360 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12361 | { | |
12362 | struct bp_location **locp = NULL, **loc2p; | |
12363 | struct bp_location *loc; | |
12364 | CORE_ADDR address = 0; | |
12365 | int pspace_num; | |
12366 | ||
12367 | address = bl->address; | |
12368 | pspace_num = bl->pspace->num; | |
12369 | ||
12370 | /* This is only meaningful if the target is | |
12371 | evaluating conditions and if the user has | |
12372 | opted for condition evaluation on the target's | |
12373 | side. */ | |
12374 | if (gdb_evaluates_breakpoint_condition_p () | |
12375 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12376 | return; | |
12377 | ||
12378 | /* Flag all breakpoint locations with this address and | |
12379 | the same program space as the location | |
12380 | as "its condition has changed". We need to | |
12381 | update the conditions on the target's side. */ | |
12382 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12383 | { | |
12384 | loc = *loc2p; | |
12385 | ||
12386 | if (!is_breakpoint (loc->owner) | |
12387 | || pspace_num != loc->pspace->num) | |
12388 | continue; | |
12389 | ||
12390 | /* Flag the location appropriately. We use a different state to | |
12391 | let everyone know that we already updated the set of locations | |
12392 | with addr bl->address and program space bl->pspace. This is so | |
12393 | we don't have to keep calling these functions just to mark locations | |
12394 | that have already been marked. */ | |
12395 | loc->condition_changed = condition_updated; | |
12396 | ||
12397 | /* Free the agent expression bytecode as well. We will compute | |
12398 | it later on. */ | |
12399 | if (loc->cond_bytecode) | |
12400 | { | |
12401 | free_agent_expr (loc->cond_bytecode); | |
12402 | loc->cond_bytecode = NULL; | |
12403 | } | |
12404 | } | |
12405 | } | |
44702360 PA |
12406 | /* Called whether new breakpoints are created, or existing breakpoints |
12407 | deleted, to update the global location list and recompute which | |
12408 | locations are duplicate of which. | |
b775012e | 12409 | |
04086b45 PA |
12410 | The INSERT_MODE flag determines whether locations may not, may, or |
12411 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12412 | info. */ | |
b60e7edf | 12413 | |
0d381245 | 12414 | static void |
44702360 | 12415 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12416 | { |
74960c60 | 12417 | struct breakpoint *b; |
876fa593 | 12418 | struct bp_location **locp, *loc; |
f7545552 | 12419 | struct cleanup *cleanups; |
b775012e LM |
12420 | /* Last breakpoint location address that was marked for update. */ |
12421 | CORE_ADDR last_addr = 0; | |
12422 | /* Last breakpoint location program space that was marked for update. */ | |
12423 | int last_pspace_num = -1; | |
f7545552 | 12424 | |
2d134ed3 PA |
12425 | /* Used in the duplicates detection below. When iterating over all |
12426 | bp_locations, points to the first bp_location of a given address. | |
12427 | Breakpoints and watchpoints of different types are never | |
12428 | duplicates of each other. Keep one pointer for each type of | |
12429 | breakpoint/watchpoint, so we only need to loop over all locations | |
12430 | once. */ | |
12431 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12432 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12433 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12434 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12435 | |
4a64f543 MS |
12436 | /* Saved former bp_location array which we compare against the newly |
12437 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12438 | struct bp_location **old_location, **old_locp; |
12439 | unsigned old_location_count; | |
12440 | ||
12441 | old_location = bp_location; | |
12442 | old_location_count = bp_location_count; | |
12443 | bp_location = NULL; | |
12444 | bp_location_count = 0; | |
12445 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12446 | |
74960c60 | 12447 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12448 | for (loc = b->loc; loc; loc = loc->next) |
12449 | bp_location_count++; | |
12450 | ||
8d749320 | 12451 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12452 | locp = bp_location; |
12453 | ALL_BREAKPOINTS (b) | |
12454 | for (loc = b->loc; loc; loc = loc->next) | |
12455 | *locp++ = loc; | |
12456 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12457 | bp_location_compare); |
876fa593 JK |
12458 | |
12459 | bp_location_target_extensions_update (); | |
74960c60 | 12460 | |
4a64f543 MS |
12461 | /* Identify bp_location instances that are no longer present in the |
12462 | new list, and therefore should be freed. Note that it's not | |
12463 | necessary that those locations should be removed from inferior -- | |
12464 | if there's another location at the same address (previously | |
12465 | marked as duplicate), we don't need to remove/insert the | |
12466 | location. | |
876fa593 | 12467 | |
4a64f543 MS |
12468 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12469 | and former bp_location array state respectively. */ | |
876fa593 JK |
12470 | |
12471 | locp = bp_location; | |
12472 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12473 | old_locp++) | |
74960c60 | 12474 | { |
876fa593 | 12475 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12476 | struct bp_location **loc2p; |
876fa593 | 12477 | |
e5dd4106 | 12478 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12479 | not, we have to free it. */ |
c7d46a38 | 12480 | int found_object = 0; |
20874c92 VP |
12481 | /* Tells if the location should remain inserted in the target. */ |
12482 | int keep_in_target = 0; | |
12483 | int removed = 0; | |
876fa593 | 12484 | |
4a64f543 MS |
12485 | /* Skip LOCP entries which will definitely never be needed. |
12486 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12487 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12488 | && (*locp)->address < old_loc->address) |
876fa593 | 12489 | locp++; |
c7d46a38 PA |
12490 | |
12491 | for (loc2p = locp; | |
12492 | (loc2p < bp_location + bp_location_count | |
12493 | && (*loc2p)->address == old_loc->address); | |
12494 | loc2p++) | |
12495 | { | |
b775012e LM |
12496 | /* Check if this is a new/duplicated location or a duplicated |
12497 | location that had its condition modified. If so, we want to send | |
12498 | its condition to the target if evaluation of conditions is taking | |
12499 | place there. */ | |
12500 | if ((*loc2p)->condition_changed == condition_modified | |
12501 | && (last_addr != old_loc->address | |
12502 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12503 | { |
b775012e LM |
12504 | force_breakpoint_reinsertion (*loc2p); |
12505 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12506 | } |
b775012e LM |
12507 | |
12508 | if (*loc2p == old_loc) | |
12509 | found_object = 1; | |
c7d46a38 | 12510 | } |
74960c60 | 12511 | |
b775012e LM |
12512 | /* We have already handled this address, update it so that we don't |
12513 | have to go through updates again. */ | |
12514 | last_addr = old_loc->address; | |
12515 | ||
12516 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12517 | if (!found_object) | |
12518 | force_breakpoint_reinsertion (old_loc); | |
12519 | ||
4a64f543 MS |
12520 | /* If this location is no longer present, and inserted, look if |
12521 | there's maybe a new location at the same address. If so, | |
12522 | mark that one inserted, and don't remove this one. This is | |
12523 | needed so that we don't have a time window where a breakpoint | |
12524 | at certain location is not inserted. */ | |
74960c60 | 12525 | |
876fa593 | 12526 | if (old_loc->inserted) |
0d381245 | 12527 | { |
4a64f543 MS |
12528 | /* If the location is inserted now, we might have to remove |
12529 | it. */ | |
74960c60 | 12530 | |
876fa593 | 12531 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12532 | { |
4a64f543 MS |
12533 | /* The location is still present in the location list, |
12534 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12535 | keep_in_target = 1; |
74960c60 VP |
12536 | } |
12537 | else | |
12538 | { | |
b775012e LM |
12539 | /* This location still exists, but it won't be kept in the |
12540 | target since it may have been disabled. We proceed to | |
12541 | remove its target-side condition. */ | |
12542 | ||
4a64f543 MS |
12543 | /* The location is either no longer present, or got |
12544 | disabled. See if there's another location at the | |
12545 | same address, in which case we don't need to remove | |
12546 | this one from the target. */ | |
876fa593 | 12547 | |
2bdf28a0 | 12548 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12549 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12550 | { | |
876fa593 | 12551 | for (loc2p = locp; |
c7d46a38 PA |
12552 | (loc2p < bp_location + bp_location_count |
12553 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12554 | loc2p++) |
12555 | { | |
12556 | struct bp_location *loc2 = *loc2p; | |
12557 | ||
2d134ed3 | 12558 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12559 | { |
85d721b8 PA |
12560 | /* Read watchpoint locations are switched to |
12561 | access watchpoints, if the former are not | |
12562 | supported, but the latter are. */ | |
12563 | if (is_hardware_watchpoint (old_loc->owner)) | |
12564 | { | |
12565 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12566 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12567 | } | |
12568 | ||
934709f0 PW |
12569 | /* loc2 is a duplicated location. We need to check |
12570 | if it should be inserted in case it will be | |
12571 | unduplicated. */ | |
12572 | if (loc2 != old_loc | |
12573 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12574 | { |
934709f0 | 12575 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12576 | keep_in_target = 1; |
12577 | break; | |
12578 | } | |
876fa593 JK |
12579 | } |
12580 | } | |
12581 | } | |
74960c60 VP |
12582 | } |
12583 | ||
20874c92 VP |
12584 | if (!keep_in_target) |
12585 | { | |
876fa593 | 12586 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12587 | { |
4a64f543 MS |
12588 | /* This is just about all we can do. We could keep |
12589 | this location on the global list, and try to | |
12590 | remove it next time, but there's no particular | |
12591 | reason why we will succeed next time. | |
20874c92 | 12592 | |
4a64f543 MS |
12593 | Note that at this point, old_loc->owner is still |
12594 | valid, as delete_breakpoint frees the breakpoint | |
12595 | only after calling us. */ | |
3e43a32a MS |
12596 | printf_filtered (_("warning: Error removing " |
12597 | "breakpoint %d\n"), | |
876fa593 | 12598 | old_loc->owner->number); |
20874c92 VP |
12599 | } |
12600 | removed = 1; | |
12601 | } | |
0d381245 | 12602 | } |
74960c60 VP |
12603 | |
12604 | if (!found_object) | |
1c5cfe86 | 12605 | { |
fbea99ea | 12606 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12607 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12608 | { |
db82e815 PA |
12609 | /* This location was removed from the target. In |
12610 | non-stop mode, a race condition is possible where | |
12611 | we've removed a breakpoint, but stop events for that | |
12612 | breakpoint are already queued and will arrive later. | |
12613 | We apply an heuristic to be able to distinguish such | |
12614 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12615 | breakpoint location for a bit, and will retire it | |
12616 | after we see some number of events. The theory here | |
12617 | is that reporting of events should, "on the average", | |
12618 | be fair, so after a while we'll see events from all | |
12619 | threads that have anything of interest, and no longer | |
12620 | need to keep this breakpoint location around. We | |
12621 | don't hold locations forever so to reduce chances of | |
12622 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12623 | SIGTRAP. | |
12624 | ||
12625 | The heuristic failing can be disastrous on | |
12626 | decr_pc_after_break targets. | |
12627 | ||
12628 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12629 | if we fail to recognize a late breakpoint SIGTRAP, | |
12630 | because events_till_retirement has reached 0 too | |
12631 | soon, we'll fail to do the PC adjustment, and report | |
12632 | a random SIGTRAP to the user. When the user resumes | |
12633 | the inferior, it will most likely immediately crash | |
2dec564e | 12634 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12635 | corrupted, because of being resumed e.g., in the |
12636 | middle of a multi-byte instruction, or skipped a | |
12637 | one-byte instruction. This was actually seen happen | |
12638 | on native x86-linux, and should be less rare on | |
12639 | targets that do not support new thread events, like | |
12640 | remote, due to the heuristic depending on | |
12641 | thread_count. | |
12642 | ||
12643 | Mistaking a random SIGTRAP for a breakpoint trap | |
12644 | causes similar symptoms (PC adjustment applied when | |
12645 | it shouldn't), but then again, playing with SIGTRAPs | |
12646 | behind the debugger's back is asking for trouble. | |
12647 | ||
12648 | Since hardware watchpoint traps are always | |
12649 | distinguishable from other traps, so we don't need to | |
12650 | apply keep hardware watchpoint moribund locations | |
12651 | around. We simply always ignore hardware watchpoint | |
12652 | traps we can no longer explain. */ | |
12653 | ||
876fa593 JK |
12654 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12655 | old_loc->owner = NULL; | |
20874c92 | 12656 | |
876fa593 | 12657 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12658 | } |
12659 | else | |
f431efe5 PA |
12660 | { |
12661 | old_loc->owner = NULL; | |
12662 | decref_bp_location (&old_loc); | |
12663 | } | |
20874c92 | 12664 | } |
74960c60 | 12665 | } |
1c5cfe86 | 12666 | |
348d480f PA |
12667 | /* Rescan breakpoints at the same address and section, marking the |
12668 | first one as "first" and any others as "duplicates". This is so | |
12669 | that the bpt instruction is only inserted once. If we have a | |
12670 | permanent breakpoint at the same place as BPT, make that one the | |
12671 | official one, and the rest as duplicates. Permanent breakpoints | |
12672 | are sorted first for the same address. | |
12673 | ||
12674 | Do the same for hardware watchpoints, but also considering the | |
12675 | watchpoint's type (regular/access/read) and length. */ | |
12676 | ||
12677 | bp_loc_first = NULL; | |
12678 | wp_loc_first = NULL; | |
12679 | awp_loc_first = NULL; | |
12680 | rwp_loc_first = NULL; | |
12681 | ALL_BP_LOCATIONS (loc, locp) | |
12682 | { | |
12683 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12684 | non-NULL. */ | |
348d480f | 12685 | struct bp_location **loc_first_p; |
d3fbdd86 | 12686 | b = loc->owner; |
348d480f | 12687 | |
6f380991 | 12688 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12689 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12690 | /* Don't detect duplicate for tracepoint locations because they are |
12691 | never duplicated. See the comments in field `duplicate' of | |
12692 | `struct bp_location'. */ | |
348d480f | 12693 | || is_tracepoint (b)) |
b775012e LM |
12694 | { |
12695 | /* Clear the condition modification flag. */ | |
12696 | loc->condition_changed = condition_unchanged; | |
12697 | continue; | |
12698 | } | |
348d480f | 12699 | |
348d480f PA |
12700 | if (b->type == bp_hardware_watchpoint) |
12701 | loc_first_p = &wp_loc_first; | |
12702 | else if (b->type == bp_read_watchpoint) | |
12703 | loc_first_p = &rwp_loc_first; | |
12704 | else if (b->type == bp_access_watchpoint) | |
12705 | loc_first_p = &awp_loc_first; | |
12706 | else | |
12707 | loc_first_p = &bp_loc_first; | |
12708 | ||
12709 | if (*loc_first_p == NULL | |
12710 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12711 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12712 | { | |
12713 | *loc_first_p = loc; | |
12714 | loc->duplicate = 0; | |
b775012e LM |
12715 | |
12716 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12717 | { | |
12718 | loc->needs_update = 1; | |
12719 | /* Clear the condition modification flag. */ | |
12720 | loc->condition_changed = condition_unchanged; | |
12721 | } | |
348d480f PA |
12722 | continue; |
12723 | } | |
12724 | ||
934709f0 PW |
12725 | |
12726 | /* This and the above ensure the invariant that the first location | |
12727 | is not duplicated, and is the inserted one. | |
12728 | All following are marked as duplicated, and are not inserted. */ | |
12729 | if (loc->inserted) | |
12730 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12731 | loc->duplicate = 1; |
12732 | ||
b775012e LM |
12733 | /* Clear the condition modification flag. */ |
12734 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12735 | } |
12736 | ||
a25a5a45 | 12737 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12738 | { |
04086b45 | 12739 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12740 | insert_breakpoint_locations (); |
12741 | else | |
12742 | { | |
44702360 PA |
12743 | /* Even though the caller told us to not insert new |
12744 | locations, we may still need to update conditions on the | |
12745 | target's side of breakpoints that were already inserted | |
12746 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12747 | only update conditions for locations that are marked |
12748 | "needs_update". */ | |
12749 | update_inserted_breakpoint_locations (); | |
12750 | } | |
12751 | } | |
348d480f | 12752 | |
04086b45 | 12753 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12754 | download_tracepoint_locations (); |
12755 | ||
348d480f PA |
12756 | do_cleanups (cleanups); |
12757 | } | |
12758 | ||
12759 | void | |
12760 | breakpoint_retire_moribund (void) | |
12761 | { | |
12762 | struct bp_location *loc; | |
12763 | int ix; | |
12764 | ||
12765 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12766 | if (--(loc->events_till_retirement) == 0) | |
12767 | { | |
12768 | decref_bp_location (&loc); | |
12769 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12770 | --ix; | |
12771 | } | |
12772 | } | |
12773 | ||
12774 | static void | |
44702360 | 12775 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12776 | { |
348d480f | 12777 | |
492d29ea PA |
12778 | TRY |
12779 | { | |
12780 | update_global_location_list (insert_mode); | |
12781 | } | |
12782 | CATCH (e, RETURN_MASK_ERROR) | |
12783 | { | |
12784 | } | |
12785 | END_CATCH | |
348d480f PA |
12786 | } |
12787 | ||
12788 | /* Clear BKP from a BPS. */ | |
12789 | ||
12790 | static void | |
12791 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12792 | { | |
12793 | bpstat bs; | |
12794 | ||
12795 | for (bs = bps; bs; bs = bs->next) | |
12796 | if (bs->breakpoint_at == bpt) | |
12797 | { | |
12798 | bs->breakpoint_at = NULL; | |
12799 | bs->old_val = NULL; | |
12800 | /* bs->commands will be freed later. */ | |
12801 | } | |
12802 | } | |
12803 | ||
12804 | /* Callback for iterate_over_threads. */ | |
12805 | static int | |
12806 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12807 | { | |
9a3c8263 | 12808 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12809 | |
12810 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12811 | return 0; | |
12812 | } | |
12813 | ||
12814 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12815 | callbacks. */ | |
12816 | ||
12817 | static void | |
12818 | say_where (struct breakpoint *b) | |
12819 | { | |
12820 | struct value_print_options opts; | |
12821 | ||
12822 | get_user_print_options (&opts); | |
12823 | ||
12824 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12825 | single string. */ | |
12826 | if (b->loc == NULL) | |
12827 | { | |
f00aae0f KS |
12828 | /* For pending locations, the output differs slightly based |
12829 | on b->extra_string. If this is non-NULL, it contains either | |
12830 | a condition or dprintf arguments. */ | |
12831 | if (b->extra_string == NULL) | |
12832 | { | |
12833 | printf_filtered (_(" (%s) pending."), | |
12834 | event_location_to_string (b->location)); | |
12835 | } | |
12836 | else if (b->type == bp_dprintf) | |
12837 | { | |
12838 | printf_filtered (_(" (%s,%s) pending."), | |
12839 | event_location_to_string (b->location), | |
12840 | b->extra_string); | |
12841 | } | |
12842 | else | |
12843 | { | |
12844 | printf_filtered (_(" (%s %s) pending."), | |
12845 | event_location_to_string (b->location), | |
12846 | b->extra_string); | |
12847 | } | |
348d480f PA |
12848 | } |
12849 | else | |
12850 | { | |
2f202fde | 12851 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12852 | { |
12853 | printf_filtered (" at "); | |
12854 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12855 | gdb_stdout); | |
12856 | } | |
2f202fde | 12857 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12858 | { |
12859 | /* If there is a single location, we can print the location | |
12860 | more nicely. */ | |
12861 | if (b->loc->next == NULL) | |
12862 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12863 | symtab_to_filename_for_display (b->loc->symtab), |
12864 | b->loc->line_number); | |
f8eba3c6 TT |
12865 | else |
12866 | /* This is not ideal, but each location may have a | |
12867 | different file name, and this at least reflects the | |
12868 | real situation somewhat. */ | |
f00aae0f KS |
12869 | printf_filtered (": %s.", |
12870 | event_location_to_string (b->location)); | |
f8eba3c6 | 12871 | } |
348d480f PA |
12872 | |
12873 | if (b->loc->next) | |
12874 | { | |
12875 | struct bp_location *loc = b->loc; | |
12876 | int n = 0; | |
12877 | for (; loc; loc = loc->next) | |
12878 | ++n; | |
12879 | printf_filtered (" (%d locations)", n); | |
12880 | } | |
12881 | } | |
12882 | } | |
12883 | ||
348d480f PA |
12884 | /* Default bp_location_ops methods. */ |
12885 | ||
12886 | static void | |
12887 | bp_location_dtor (struct bp_location *self) | |
12888 | { | |
12889 | xfree (self->cond); | |
b775012e LM |
12890 | if (self->cond_bytecode) |
12891 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12892 | xfree (self->function_name); |
8b4f3082 PA |
12893 | |
12894 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12895 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12896 | } |
12897 | ||
12898 | static const struct bp_location_ops bp_location_ops = | |
12899 | { | |
12900 | bp_location_dtor | |
12901 | }; | |
12902 | ||
2060206e PA |
12903 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12904 | inherit from. */ | |
348d480f | 12905 | |
2060206e PA |
12906 | static void |
12907 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12908 | { |
12909 | decref_counted_command_line (&self->commands); | |
12910 | xfree (self->cond_string); | |
fb81d016 | 12911 | xfree (self->extra_string); |
f8eba3c6 | 12912 | xfree (self->filter); |
f00aae0f KS |
12913 | delete_event_location (self->location); |
12914 | delete_event_location (self->location_range_end); | |
348d480f PA |
12915 | } |
12916 | ||
2060206e PA |
12917 | static struct bp_location * |
12918 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12919 | { |
12920 | struct bp_location *loc; | |
12921 | ||
12922 | loc = XNEW (struct bp_location); | |
12923 | init_bp_location (loc, &bp_location_ops, self); | |
12924 | return loc; | |
12925 | } | |
12926 | ||
2060206e PA |
12927 | static void |
12928 | base_breakpoint_re_set (struct breakpoint *b) | |
12929 | { | |
12930 | /* Nothing to re-set. */ | |
12931 | } | |
12932 | ||
12933 | #define internal_error_pure_virtual_called() \ | |
12934 | gdb_assert_not_reached ("pure virtual function called") | |
12935 | ||
12936 | static int | |
12937 | base_breakpoint_insert_location (struct bp_location *bl) | |
12938 | { | |
12939 | internal_error_pure_virtual_called (); | |
12940 | } | |
12941 | ||
12942 | static int | |
12943 | base_breakpoint_remove_location (struct bp_location *bl) | |
12944 | { | |
12945 | internal_error_pure_virtual_called (); | |
12946 | } | |
12947 | ||
12948 | static int | |
12949 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12950 | struct address_space *aspace, | |
09ac7c10 TT |
12951 | CORE_ADDR bp_addr, |
12952 | const struct target_waitstatus *ws) | |
2060206e PA |
12953 | { |
12954 | internal_error_pure_virtual_called (); | |
12955 | } | |
12956 | ||
12957 | static void | |
12958 | base_breakpoint_check_status (bpstat bs) | |
12959 | { | |
12960 | /* Always stop. */ | |
12961 | } | |
12962 | ||
12963 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12964 | errors. */ | |
12965 | ||
12966 | static int | |
12967 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12968 | { | |
12969 | internal_error_pure_virtual_called (); | |
12970 | } | |
12971 | ||
12972 | /* A "resources_needed" breakpoint_ops method that just internal | |
12973 | errors. */ | |
12974 | ||
12975 | static int | |
12976 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12977 | { | |
12978 | internal_error_pure_virtual_called (); | |
12979 | } | |
12980 | ||
12981 | static enum print_stop_action | |
12982 | base_breakpoint_print_it (bpstat bs) | |
12983 | { | |
12984 | internal_error_pure_virtual_called (); | |
12985 | } | |
12986 | ||
12987 | static void | |
12988 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12989 | struct ui_out *uiout) | |
12990 | { | |
12991 | /* nothing */ | |
12992 | } | |
12993 | ||
12994 | static void | |
12995 | base_breakpoint_print_mention (struct breakpoint *b) | |
12996 | { | |
12997 | internal_error_pure_virtual_called (); | |
12998 | } | |
12999 | ||
13000 | static void | |
13001 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13002 | { | |
13003 | internal_error_pure_virtual_called (); | |
13004 | } | |
13005 | ||
983af33b | 13006 | static void |
f00aae0f KS |
13007 | base_breakpoint_create_sals_from_location |
13008 | (const struct event_location *location, | |
13009 | struct linespec_result *canonical, | |
13010 | enum bptype type_wanted) | |
983af33b SDJ |
13011 | { |
13012 | internal_error_pure_virtual_called (); | |
13013 | } | |
13014 | ||
13015 | static void | |
13016 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13017 | struct linespec_result *c, | |
983af33b | 13018 | char *cond_string, |
e7e0cddf | 13019 | char *extra_string, |
983af33b SDJ |
13020 | enum bptype type_wanted, |
13021 | enum bpdisp disposition, | |
13022 | int thread, | |
13023 | int task, int ignore_count, | |
13024 | const struct breakpoint_ops *o, | |
13025 | int from_tty, int enabled, | |
44f238bb | 13026 | int internal, unsigned flags) |
983af33b SDJ |
13027 | { |
13028 | internal_error_pure_virtual_called (); | |
13029 | } | |
13030 | ||
13031 | static void | |
f00aae0f KS |
13032 | base_breakpoint_decode_location (struct breakpoint *b, |
13033 | const struct event_location *location, | |
c2f4122d | 13034 | struct program_space *search_pspace, |
983af33b SDJ |
13035 | struct symtabs_and_lines *sals) |
13036 | { | |
13037 | internal_error_pure_virtual_called (); | |
13038 | } | |
13039 | ||
ab04a2af TT |
13040 | /* The default 'explains_signal' method. */ |
13041 | ||
47591c29 | 13042 | static int |
427cd150 | 13043 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13044 | { |
47591c29 | 13045 | return 1; |
ab04a2af TT |
13046 | } |
13047 | ||
9d6e6e84 HZ |
13048 | /* The default "after_condition_true" method. */ |
13049 | ||
13050 | static void | |
13051 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13052 | { | |
13053 | /* Nothing to do. */ | |
13054 | } | |
13055 | ||
ab04a2af | 13056 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13057 | { |
13058 | base_breakpoint_dtor, | |
13059 | base_breakpoint_allocate_location, | |
13060 | base_breakpoint_re_set, | |
13061 | base_breakpoint_insert_location, | |
13062 | base_breakpoint_remove_location, | |
13063 | base_breakpoint_breakpoint_hit, | |
13064 | base_breakpoint_check_status, | |
13065 | base_breakpoint_resources_needed, | |
13066 | base_breakpoint_works_in_software_mode, | |
13067 | base_breakpoint_print_it, | |
13068 | NULL, | |
13069 | base_breakpoint_print_one_detail, | |
13070 | base_breakpoint_print_mention, | |
983af33b | 13071 | base_breakpoint_print_recreate, |
5f700d83 | 13072 | base_breakpoint_create_sals_from_location, |
983af33b | 13073 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13074 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13075 | base_breakpoint_explains_signal, |
13076 | base_breakpoint_after_condition_true, | |
2060206e PA |
13077 | }; |
13078 | ||
13079 | /* Default breakpoint_ops methods. */ | |
13080 | ||
13081 | static void | |
348d480f PA |
13082 | bkpt_re_set (struct breakpoint *b) |
13083 | { | |
06edf0c0 | 13084 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13085 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13086 | { |
f00aae0f | 13087 | /* Anything without a location can't be re-set. */ |
348d480f | 13088 | delete_breakpoint (b); |
06edf0c0 | 13089 | return; |
348d480f | 13090 | } |
06edf0c0 PA |
13091 | |
13092 | breakpoint_re_set_default (b); | |
348d480f PA |
13093 | } |
13094 | ||
2060206e | 13095 | static int |
348d480f PA |
13096 | bkpt_insert_location (struct bp_location *bl) |
13097 | { | |
13098 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13099 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13100 | else |
7c16b83e | 13101 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13102 | } |
13103 | ||
2060206e | 13104 | static int |
348d480f PA |
13105 | bkpt_remove_location (struct bp_location *bl) |
13106 | { | |
13107 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13108 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13109 | else | |
7c16b83e | 13110 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13111 | } |
13112 | ||
2060206e | 13113 | static int |
348d480f | 13114 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13115 | struct address_space *aspace, CORE_ADDR bp_addr, |
13116 | const struct target_waitstatus *ws) | |
348d480f | 13117 | { |
09ac7c10 | 13118 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13119 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13120 | return 0; |
13121 | ||
348d480f PA |
13122 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13123 | aspace, bp_addr)) | |
13124 | return 0; | |
13125 | ||
13126 | if (overlay_debugging /* unmapped overlay section */ | |
13127 | && section_is_overlay (bl->section) | |
13128 | && !section_is_mapped (bl->section)) | |
13129 | return 0; | |
13130 | ||
13131 | return 1; | |
13132 | } | |
13133 | ||
cd1608cc PA |
13134 | static int |
13135 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13136 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13137 | const struct target_waitstatus *ws) | |
13138 | { | |
13139 | if (dprintf_style == dprintf_style_agent | |
13140 | && target_can_run_breakpoint_commands ()) | |
13141 | { | |
13142 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13143 | for this address it must be for a breakpoint that happens to | |
13144 | be set at the same address. */ | |
13145 | return 0; | |
13146 | } | |
13147 | ||
13148 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13149 | } | |
13150 | ||
2060206e | 13151 | static int |
348d480f PA |
13152 | bkpt_resources_needed (const struct bp_location *bl) |
13153 | { | |
13154 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13155 | ||
13156 | return 1; | |
13157 | } | |
13158 | ||
2060206e | 13159 | static enum print_stop_action |
348d480f PA |
13160 | bkpt_print_it (bpstat bs) |
13161 | { | |
348d480f PA |
13162 | struct breakpoint *b; |
13163 | const struct bp_location *bl; | |
001c8c33 | 13164 | int bp_temp; |
79a45e25 | 13165 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13166 | |
13167 | gdb_assert (bs->bp_location_at != NULL); | |
13168 | ||
13169 | bl = bs->bp_location_at; | |
13170 | b = bs->breakpoint_at; | |
13171 | ||
001c8c33 PA |
13172 | bp_temp = b->disposition == disp_del; |
13173 | if (bl->address != bl->requested_address) | |
13174 | breakpoint_adjustment_warning (bl->requested_address, | |
13175 | bl->address, | |
13176 | b->number, 1); | |
13177 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13178 | maybe_print_thread_hit_breakpoint (uiout); |
13179 | ||
001c8c33 | 13180 | if (bp_temp) |
f303dbd6 | 13181 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13182 | else |
f303dbd6 | 13183 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13184 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13185 | { |
001c8c33 PA |
13186 | ui_out_field_string (uiout, "reason", |
13187 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13188 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13189 | } |
001c8c33 PA |
13190 | ui_out_field_int (uiout, "bkptno", b->number); |
13191 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13192 | |
001c8c33 | 13193 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13194 | } |
13195 | ||
2060206e | 13196 | static void |
06edf0c0 PA |
13197 | bkpt_print_mention (struct breakpoint *b) |
13198 | { | |
79a45e25 | 13199 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13200 | return; |
13201 | ||
13202 | switch (b->type) | |
13203 | { | |
13204 | case bp_breakpoint: | |
13205 | case bp_gnu_ifunc_resolver: | |
13206 | if (b->disposition == disp_del) | |
13207 | printf_filtered (_("Temporary breakpoint")); | |
13208 | else | |
13209 | printf_filtered (_("Breakpoint")); | |
13210 | printf_filtered (_(" %d"), b->number); | |
13211 | if (b->type == bp_gnu_ifunc_resolver) | |
13212 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13213 | break; | |
13214 | case bp_hardware_breakpoint: | |
13215 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13216 | break; | |
e7e0cddf SS |
13217 | case bp_dprintf: |
13218 | printf_filtered (_("Dprintf %d"), b->number); | |
13219 | break; | |
06edf0c0 PA |
13220 | } |
13221 | ||
13222 | say_where (b); | |
13223 | } | |
13224 | ||
2060206e | 13225 | static void |
06edf0c0 PA |
13226 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13227 | { | |
13228 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13229 | fprintf_unfiltered (fp, "tbreak"); | |
13230 | else if (tp->type == bp_breakpoint) | |
13231 | fprintf_unfiltered (fp, "break"); | |
13232 | else if (tp->type == bp_hardware_breakpoint | |
13233 | && tp->disposition == disp_del) | |
13234 | fprintf_unfiltered (fp, "thbreak"); | |
13235 | else if (tp->type == bp_hardware_breakpoint) | |
13236 | fprintf_unfiltered (fp, "hbreak"); | |
13237 | else | |
13238 | internal_error (__FILE__, __LINE__, | |
13239 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13240 | ||
f00aae0f KS |
13241 | fprintf_unfiltered (fp, " %s", |
13242 | event_location_to_string (tp->location)); | |
13243 | ||
13244 | /* Print out extra_string if this breakpoint is pending. It might | |
13245 | contain, for example, conditions that were set by the user. */ | |
13246 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13247 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13248 | ||
dd11a36c | 13249 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13250 | } |
13251 | ||
983af33b | 13252 | static void |
f00aae0f KS |
13253 | bkpt_create_sals_from_location (const struct event_location *location, |
13254 | struct linespec_result *canonical, | |
13255 | enum bptype type_wanted) | |
983af33b | 13256 | { |
f00aae0f | 13257 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13258 | } |
13259 | ||
13260 | static void | |
13261 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13262 | struct linespec_result *canonical, | |
983af33b | 13263 | char *cond_string, |
e7e0cddf | 13264 | char *extra_string, |
983af33b SDJ |
13265 | enum bptype type_wanted, |
13266 | enum bpdisp disposition, | |
13267 | int thread, | |
13268 | int task, int ignore_count, | |
13269 | const struct breakpoint_ops *ops, | |
13270 | int from_tty, int enabled, | |
44f238bb | 13271 | int internal, unsigned flags) |
983af33b | 13272 | { |
023fa29b | 13273 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13274 | cond_string, extra_string, |
13275 | type_wanted, | |
983af33b SDJ |
13276 | disposition, thread, task, |
13277 | ignore_count, ops, from_tty, | |
44f238bb | 13278 | enabled, internal, flags); |
983af33b SDJ |
13279 | } |
13280 | ||
13281 | static void | |
f00aae0f KS |
13282 | bkpt_decode_location (struct breakpoint *b, |
13283 | const struct event_location *location, | |
c2f4122d | 13284 | struct program_space *search_pspace, |
983af33b SDJ |
13285 | struct symtabs_and_lines *sals) |
13286 | { | |
c2f4122d | 13287 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13288 | } |
13289 | ||
06edf0c0 PA |
13290 | /* Virtual table for internal breakpoints. */ |
13291 | ||
13292 | static void | |
13293 | internal_bkpt_re_set (struct breakpoint *b) | |
13294 | { | |
13295 | switch (b->type) | |
13296 | { | |
13297 | /* Delete overlay event and longjmp master breakpoints; they | |
13298 | will be reset later by breakpoint_re_set. */ | |
13299 | case bp_overlay_event: | |
13300 | case bp_longjmp_master: | |
13301 | case bp_std_terminate_master: | |
13302 | case bp_exception_master: | |
13303 | delete_breakpoint (b); | |
13304 | break; | |
13305 | ||
13306 | /* This breakpoint is special, it's set up when the inferior | |
13307 | starts and we really don't want to touch it. */ | |
13308 | case bp_shlib_event: | |
13309 | ||
13310 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13311 | it is set up, we do not want to touch it. */ | |
13312 | case bp_thread_event: | |
13313 | break; | |
13314 | } | |
13315 | } | |
13316 | ||
13317 | static void | |
13318 | internal_bkpt_check_status (bpstat bs) | |
13319 | { | |
a9b3a50f PA |
13320 | if (bs->breakpoint_at->type == bp_shlib_event) |
13321 | { | |
13322 | /* If requested, stop when the dynamic linker notifies GDB of | |
13323 | events. This allows the user to get control and place | |
13324 | breakpoints in initializer routines for dynamically loaded | |
13325 | objects (among other things). */ | |
13326 | bs->stop = stop_on_solib_events; | |
13327 | bs->print = stop_on_solib_events; | |
13328 | } | |
13329 | else | |
13330 | bs->stop = 0; | |
06edf0c0 PA |
13331 | } |
13332 | ||
13333 | static enum print_stop_action | |
13334 | internal_bkpt_print_it (bpstat bs) | |
13335 | { | |
06edf0c0 | 13336 | struct breakpoint *b; |
06edf0c0 | 13337 | |
06edf0c0 PA |
13338 | b = bs->breakpoint_at; |
13339 | ||
06edf0c0 PA |
13340 | switch (b->type) |
13341 | { | |
348d480f PA |
13342 | case bp_shlib_event: |
13343 | /* Did we stop because the user set the stop_on_solib_events | |
13344 | variable? (If so, we report this as a generic, "Stopped due | |
13345 | to shlib event" message.) */ | |
edcc5120 | 13346 | print_solib_event (0); |
348d480f PA |
13347 | break; |
13348 | ||
13349 | case bp_thread_event: | |
13350 | /* Not sure how we will get here. | |
13351 | GDB should not stop for these breakpoints. */ | |
13352 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13353 | break; |
13354 | ||
13355 | case bp_overlay_event: | |
13356 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13357 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13358 | break; |
13359 | ||
13360 | case bp_longjmp_master: | |
13361 | /* These should never be enabled. */ | |
13362 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13363 | break; |
13364 | ||
13365 | case bp_std_terminate_master: | |
13366 | /* These should never be enabled. */ | |
13367 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13368 | "gdb should not stop!\n")); | |
348d480f PA |
13369 | break; |
13370 | ||
13371 | case bp_exception_master: | |
13372 | /* These should never be enabled. */ | |
13373 | printf_filtered (_("Exception Master Breakpoint: " | |
13374 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13375 | break; |
13376 | } | |
13377 | ||
001c8c33 | 13378 | return PRINT_NOTHING; |
06edf0c0 PA |
13379 | } |
13380 | ||
13381 | static void | |
13382 | internal_bkpt_print_mention (struct breakpoint *b) | |
13383 | { | |
13384 | /* Nothing to mention. These breakpoints are internal. */ | |
13385 | } | |
13386 | ||
06edf0c0 PA |
13387 | /* Virtual table for momentary breakpoints */ |
13388 | ||
13389 | static void | |
13390 | momentary_bkpt_re_set (struct breakpoint *b) | |
13391 | { | |
13392 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13393 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13394 | Otherwise these should have been blown away via the cleanup chain |
13395 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13396 | } | |
13397 | ||
13398 | static void | |
13399 | momentary_bkpt_check_status (bpstat bs) | |
13400 | { | |
13401 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13402 | } | |
13403 | ||
13404 | static enum print_stop_action | |
13405 | momentary_bkpt_print_it (bpstat bs) | |
13406 | { | |
001c8c33 | 13407 | return PRINT_UNKNOWN; |
348d480f PA |
13408 | } |
13409 | ||
06edf0c0 PA |
13410 | static void |
13411 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13412 | { |
06edf0c0 | 13413 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13414 | } |
13415 | ||
e2e4d78b JK |
13416 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13417 | ||
13418 | It gets cleared already on the removal of the first one of such placed | |
13419 | breakpoints. This is OK as they get all removed altogether. */ | |
13420 | ||
13421 | static void | |
13422 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13423 | { | |
5d5658a1 | 13424 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13425 | |
13426 | if (tp) | |
13427 | tp->initiating_frame = null_frame_id; | |
13428 | ||
13429 | momentary_breakpoint_ops.dtor (self); | |
13430 | } | |
13431 | ||
55aa24fb SDJ |
13432 | /* Specific methods for probe breakpoints. */ |
13433 | ||
13434 | static int | |
13435 | bkpt_probe_insert_location (struct bp_location *bl) | |
13436 | { | |
13437 | int v = bkpt_insert_location (bl); | |
13438 | ||
13439 | if (v == 0) | |
13440 | { | |
13441 | /* The insertion was successful, now let's set the probe's semaphore | |
13442 | if needed. */ | |
0ea5cda8 SDJ |
13443 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13444 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13445 | bl->probe.objfile, | |
13446 | bl->gdbarch); | |
55aa24fb SDJ |
13447 | } |
13448 | ||
13449 | return v; | |
13450 | } | |
13451 | ||
13452 | static int | |
13453 | bkpt_probe_remove_location (struct bp_location *bl) | |
13454 | { | |
13455 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13456 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13457 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13458 | bl->probe.objfile, | |
13459 | bl->gdbarch); | |
55aa24fb SDJ |
13460 | |
13461 | return bkpt_remove_location (bl); | |
13462 | } | |
13463 | ||
13464 | static void | |
f00aae0f | 13465 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13466 | struct linespec_result *canonical, |
f00aae0f | 13467 | enum bptype type_wanted) |
55aa24fb SDJ |
13468 | { |
13469 | struct linespec_sals lsal; | |
13470 | ||
c2f4122d | 13471 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13472 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13473 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13474 | } | |
13475 | ||
13476 | static void | |
f00aae0f KS |
13477 | bkpt_probe_decode_location (struct breakpoint *b, |
13478 | const struct event_location *location, | |
c2f4122d | 13479 | struct program_space *search_pspace, |
55aa24fb SDJ |
13480 | struct symtabs_and_lines *sals) |
13481 | { | |
c2f4122d | 13482 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13483 | if (!sals->sals) |
13484 | error (_("probe not found")); | |
13485 | } | |
13486 | ||
348d480f | 13487 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13488 | |
348d480f PA |
13489 | static void |
13490 | tracepoint_re_set (struct breakpoint *b) | |
13491 | { | |
13492 | breakpoint_re_set_default (b); | |
13493 | } | |
876fa593 | 13494 | |
348d480f PA |
13495 | static int |
13496 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13497 | struct address_space *aspace, CORE_ADDR bp_addr, |
13498 | const struct target_waitstatus *ws) | |
348d480f PA |
13499 | { |
13500 | /* By definition, the inferior does not report stops at | |
13501 | tracepoints. */ | |
13502 | return 0; | |
74960c60 VP |
13503 | } |
13504 | ||
13505 | static void | |
348d480f PA |
13506 | tracepoint_print_one_detail (const struct breakpoint *self, |
13507 | struct ui_out *uiout) | |
74960c60 | 13508 | { |
d9b3f62e PA |
13509 | struct tracepoint *tp = (struct tracepoint *) self; |
13510 | if (tp->static_trace_marker_id) | |
348d480f PA |
13511 | { |
13512 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13513 | |
348d480f PA |
13514 | ui_out_text (uiout, "\tmarker id is "); |
13515 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13516 | tp->static_trace_marker_id); |
348d480f PA |
13517 | ui_out_text (uiout, "\n"); |
13518 | } | |
0d381245 VP |
13519 | } |
13520 | ||
a474d7c2 | 13521 | static void |
348d480f | 13522 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13523 | { |
79a45e25 | 13524 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13525 | return; |
cc59ec59 | 13526 | |
348d480f PA |
13527 | switch (b->type) |
13528 | { | |
13529 | case bp_tracepoint: | |
13530 | printf_filtered (_("Tracepoint")); | |
13531 | printf_filtered (_(" %d"), b->number); | |
13532 | break; | |
13533 | case bp_fast_tracepoint: | |
13534 | printf_filtered (_("Fast tracepoint")); | |
13535 | printf_filtered (_(" %d"), b->number); | |
13536 | break; | |
13537 | case bp_static_tracepoint: | |
13538 | printf_filtered (_("Static tracepoint")); | |
13539 | printf_filtered (_(" %d"), b->number); | |
13540 | break; | |
13541 | default: | |
13542 | internal_error (__FILE__, __LINE__, | |
13543 | _("unhandled tracepoint type %d"), (int) b->type); | |
13544 | } | |
13545 | ||
13546 | say_where (b); | |
a474d7c2 PA |
13547 | } |
13548 | ||
348d480f | 13549 | static void |
d9b3f62e | 13550 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13551 | { |
d9b3f62e PA |
13552 | struct tracepoint *tp = (struct tracepoint *) self; |
13553 | ||
13554 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13555 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13556 | else if (self->type == bp_static_tracepoint) |
348d480f | 13557 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13558 | else if (self->type == bp_tracepoint) |
348d480f PA |
13559 | fprintf_unfiltered (fp, "trace"); |
13560 | else | |
13561 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13562 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13563 | |
f00aae0f KS |
13564 | fprintf_unfiltered (fp, " %s", |
13565 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13566 | print_recreate_thread (self, fp); |
13567 | ||
13568 | if (tp->pass_count) | |
13569 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13570 | } |
13571 | ||
983af33b | 13572 | static void |
f00aae0f KS |
13573 | tracepoint_create_sals_from_location (const struct event_location *location, |
13574 | struct linespec_result *canonical, | |
13575 | enum bptype type_wanted) | |
983af33b | 13576 | { |
f00aae0f | 13577 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13578 | } |
13579 | ||
13580 | static void | |
13581 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13582 | struct linespec_result *canonical, | |
983af33b | 13583 | char *cond_string, |
e7e0cddf | 13584 | char *extra_string, |
983af33b SDJ |
13585 | enum bptype type_wanted, |
13586 | enum bpdisp disposition, | |
13587 | int thread, | |
13588 | int task, int ignore_count, | |
13589 | const struct breakpoint_ops *ops, | |
13590 | int from_tty, int enabled, | |
44f238bb | 13591 | int internal, unsigned flags) |
983af33b | 13592 | { |
023fa29b | 13593 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13594 | cond_string, extra_string, |
13595 | type_wanted, | |
983af33b SDJ |
13596 | disposition, thread, task, |
13597 | ignore_count, ops, from_tty, | |
44f238bb | 13598 | enabled, internal, flags); |
983af33b SDJ |
13599 | } |
13600 | ||
13601 | static void | |
f00aae0f KS |
13602 | tracepoint_decode_location (struct breakpoint *b, |
13603 | const struct event_location *location, | |
c2f4122d | 13604 | struct program_space *search_pspace, |
983af33b SDJ |
13605 | struct symtabs_and_lines *sals) |
13606 | { | |
c2f4122d | 13607 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13608 | } |
13609 | ||
2060206e | 13610 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13611 | |
55aa24fb SDJ |
13612 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13613 | static probe. */ | |
13614 | ||
13615 | static void | |
f00aae0f KS |
13616 | tracepoint_probe_create_sals_from_location |
13617 | (const struct event_location *location, | |
13618 | struct linespec_result *canonical, | |
13619 | enum bptype type_wanted) | |
55aa24fb SDJ |
13620 | { |
13621 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13622 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13623 | } |
13624 | ||
13625 | static void | |
f00aae0f KS |
13626 | tracepoint_probe_decode_location (struct breakpoint *b, |
13627 | const struct event_location *location, | |
c2f4122d | 13628 | struct program_space *search_pspace, |
55aa24fb SDJ |
13629 | struct symtabs_and_lines *sals) |
13630 | { | |
13631 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13632 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13633 | } |
13634 | ||
13635 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13636 | ||
5c2b4418 HZ |
13637 | /* Dprintf breakpoint_ops methods. */ |
13638 | ||
13639 | static void | |
13640 | dprintf_re_set (struct breakpoint *b) | |
13641 | { | |
13642 | breakpoint_re_set_default (b); | |
13643 | ||
f00aae0f KS |
13644 | /* extra_string should never be non-NULL for dprintf. */ |
13645 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13646 | |
13647 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13648 | 2 - create a dprintf, which resolves fine. | |
13649 | 3 - disconnect from target 1 | |
13650 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13651 | ||
13652 | After steps #3/#4, you'll want the dprintf command list to | |
13653 | be updated, because target 1 and 2 may well return different | |
13654 | answers for target_can_run_breakpoint_commands(). | |
13655 | Given absence of finer grained resetting, we get to do | |
13656 | it all the time. */ | |
13657 | if (b->extra_string != NULL) | |
13658 | update_dprintf_command_list (b); | |
13659 | } | |
13660 | ||
2d9442cc HZ |
13661 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13662 | ||
13663 | static void | |
13664 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13665 | { | |
f00aae0f KS |
13666 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13667 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13668 | tp->extra_string); |
13669 | print_recreate_thread (tp, fp); | |
13670 | } | |
13671 | ||
9d6e6e84 HZ |
13672 | /* Implement the "after_condition_true" breakpoint_ops method for |
13673 | dprintf. | |
13674 | ||
13675 | dprintf's are implemented with regular commands in their command | |
13676 | list, but we run the commands here instead of before presenting the | |
13677 | stop to the user, as dprintf's don't actually cause a stop. This | |
13678 | also makes it so that the commands of multiple dprintfs at the same | |
13679 | address are all handled. */ | |
13680 | ||
13681 | static void | |
13682 | dprintf_after_condition_true (struct bpstats *bs) | |
13683 | { | |
13684 | struct cleanup *old_chain; | |
13685 | struct bpstats tmp_bs = { NULL }; | |
13686 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13687 | ||
13688 | /* dprintf's never cause a stop. This wasn't set in the | |
13689 | check_status hook instead because that would make the dprintf's | |
13690 | condition not be evaluated. */ | |
13691 | bs->stop = 0; | |
13692 | ||
13693 | /* Run the command list here. Take ownership of it instead of | |
13694 | copying. We never want these commands to run later in | |
13695 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13696 | be set at same address as this dprintf, or even if running the | |
13697 | commands here throws. */ | |
13698 | tmp_bs.commands = bs->commands; | |
13699 | bs->commands = NULL; | |
13700 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13701 | ||
13702 | bpstat_do_actions_1 (&tmp_bs_p); | |
13703 | ||
13704 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13705 | bpstat_do_actions_1 may return early without processing the whole | |
13706 | list. */ | |
13707 | do_cleanups (old_chain); | |
13708 | } | |
13709 | ||
983af33b SDJ |
13710 | /* The breakpoint_ops structure to be used on static tracepoints with |
13711 | markers (`-m'). */ | |
13712 | ||
13713 | static void | |
f00aae0f | 13714 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13715 | struct linespec_result *canonical, |
f00aae0f | 13716 | enum bptype type_wanted) |
983af33b SDJ |
13717 | { |
13718 | struct linespec_sals lsal; | |
f00aae0f KS |
13719 | const char *arg_start, *arg; |
13720 | char *str; | |
13721 | struct cleanup *cleanup; | |
983af33b | 13722 | |
f00aae0f KS |
13723 | arg = arg_start = get_linespec_location (location); |
13724 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13725 | |
f00aae0f KS |
13726 | str = savestring (arg_start, arg - arg_start); |
13727 | cleanup = make_cleanup (xfree, str); | |
13728 | canonical->location = new_linespec_location (&str); | |
13729 | do_cleanups (cleanup); | |
983af33b | 13730 | |
f00aae0f | 13731 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13732 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13733 | } | |
13734 | ||
13735 | static void | |
13736 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13737 | struct linespec_result *canonical, | |
983af33b | 13738 | char *cond_string, |
e7e0cddf | 13739 | char *extra_string, |
983af33b SDJ |
13740 | enum bptype type_wanted, |
13741 | enum bpdisp disposition, | |
13742 | int thread, | |
13743 | int task, int ignore_count, | |
13744 | const struct breakpoint_ops *ops, | |
13745 | int from_tty, int enabled, | |
44f238bb | 13746 | int internal, unsigned flags) |
983af33b SDJ |
13747 | { |
13748 | int i; | |
52d361e1 YQ |
13749 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13750 | canonical->sals, 0); | |
983af33b SDJ |
13751 | |
13752 | /* If the user is creating a static tracepoint by marker id | |
13753 | (strace -m MARKER_ID), then store the sals index, so that | |
13754 | breakpoint_re_set can try to match up which of the newly | |
13755 | found markers corresponds to this one, and, don't try to | |
13756 | expand multiple locations for each sal, given than SALS | |
13757 | already should contain all sals for MARKER_ID. */ | |
13758 | ||
13759 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13760 | { | |
13761 | struct symtabs_and_lines expanded; | |
13762 | struct tracepoint *tp; | |
13763 | struct cleanup *old_chain; | |
f00aae0f | 13764 | struct event_location *location; |
983af33b SDJ |
13765 | |
13766 | expanded.nelts = 1; | |
13767 | expanded.sals = &lsal->sals.sals[i]; | |
13768 | ||
f00aae0f KS |
13769 | location = copy_event_location (canonical->location); |
13770 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13771 | |
13772 | tp = XCNEW (struct tracepoint); | |
13773 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13774 | location, NULL, |
e7e0cddf SS |
13775 | cond_string, extra_string, |
13776 | type_wanted, disposition, | |
983af33b | 13777 | thread, task, ignore_count, ops, |
44f238bb | 13778 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13779 | canonical->special_display); |
13780 | /* Given that its possible to have multiple markers with | |
13781 | the same string id, if the user is creating a static | |
13782 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13783 | store the sals index, so that breakpoint_re_set can | |
13784 | try to match up which of the newly found markers | |
13785 | corresponds to this one */ | |
13786 | tp->static_trace_marker_id_idx = i; | |
13787 | ||
13788 | install_breakpoint (internal, &tp->base, 0); | |
13789 | ||
13790 | discard_cleanups (old_chain); | |
13791 | } | |
13792 | } | |
13793 | ||
13794 | static void | |
f00aae0f KS |
13795 | strace_marker_decode_location (struct breakpoint *b, |
13796 | const struct event_location *location, | |
c2f4122d | 13797 | struct program_space *search_pspace, |
983af33b SDJ |
13798 | struct symtabs_and_lines *sals) |
13799 | { | |
13800 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13801 | const char *s = get_linespec_location (location); |
983af33b | 13802 | |
f00aae0f | 13803 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13804 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13805 | { | |
13806 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13807 | sals->nelts = 1; | |
13808 | } | |
13809 | else | |
13810 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13811 | } | |
13812 | ||
13813 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13814 | ||
13815 | static int | |
13816 | strace_marker_p (struct breakpoint *b) | |
13817 | { | |
13818 | return b->ops == &strace_marker_breakpoint_ops; | |
13819 | } | |
13820 | ||
53a5351d | 13821 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13822 | structures. */ |
c906108c SS |
13823 | |
13824 | void | |
fba45db2 | 13825 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13826 | { |
52f0bd74 | 13827 | struct breakpoint *b; |
c906108c | 13828 | |
8a3fe4f8 | 13829 | gdb_assert (bpt != NULL); |
c906108c | 13830 | |
4a64f543 MS |
13831 | /* Has this bp already been deleted? This can happen because |
13832 | multiple lists can hold pointers to bp's. bpstat lists are | |
13833 | especial culprits. | |
13834 | ||
13835 | One example of this happening is a watchpoint's scope bp. When | |
13836 | the scope bp triggers, we notice that the watchpoint is out of | |
13837 | scope, and delete it. We also delete its scope bp. But the | |
13838 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13839 | That bpstat is then checked for auto-deleting bp's, which are | |
13840 | deleted. | |
13841 | ||
13842 | A real solution to this problem might involve reference counts in | |
13843 | bp's, and/or giving them pointers back to their referencing | |
13844 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13845 | storage when no more references were extent. A cheaper bandaid | |
13846 | was chosen. */ | |
c906108c SS |
13847 | if (bpt->type == bp_none) |
13848 | return; | |
13849 | ||
4a64f543 MS |
13850 | /* At least avoid this stale reference until the reference counting |
13851 | of breakpoints gets resolved. */ | |
d0fb5eae | 13852 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13853 | { |
d0fb5eae | 13854 | struct breakpoint *related; |
3a5c3e22 | 13855 | struct watchpoint *w; |
d0fb5eae JK |
13856 | |
13857 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13858 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13859 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13860 | w = (struct watchpoint *) bpt; |
13861 | else | |
13862 | w = NULL; | |
13863 | if (w != NULL) | |
13864 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13865 | |
13866 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13867 | for (related = bpt; related->related_breakpoint != bpt; | |
13868 | related = related->related_breakpoint); | |
13869 | related->related_breakpoint = bpt->related_breakpoint; | |
13870 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13871 | } |
13872 | ||
a9634178 TJB |
13873 | /* watch_command_1 creates a watchpoint but only sets its number if |
13874 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13875 | a problem in that process, we'll be asked to delete the half-created | |
13876 | watchpoint. In that case, don't announce the deletion. */ | |
13877 | if (bpt->number) | |
13878 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13879 | |
c906108c SS |
13880 | if (breakpoint_chain == bpt) |
13881 | breakpoint_chain = bpt->next; | |
13882 | ||
c906108c SS |
13883 | ALL_BREAKPOINTS (b) |
13884 | if (b->next == bpt) | |
c5aa993b JM |
13885 | { |
13886 | b->next = bpt->next; | |
13887 | break; | |
13888 | } | |
c906108c | 13889 | |
f431efe5 PA |
13890 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13891 | been freed. */ | |
13892 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13893 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13894 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13895 | commands are associated with the bpstat; if we remove it here, | |
13896 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13897 | event-top.c won't do anything, and temporary breakpoints with | |
13898 | commands won't work. */ | |
13899 | ||
13900 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13901 | ||
4a64f543 MS |
13902 | /* Now that breakpoint is removed from breakpoint list, update the |
13903 | global location list. This will remove locations that used to | |
13904 | belong to this breakpoint. Do this before freeing the breakpoint | |
13905 | itself, since remove_breakpoint looks at location's owner. It | |
13906 | might be better design to have location completely | |
13907 | self-contained, but it's not the case now. */ | |
44702360 | 13908 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13909 | |
348d480f | 13910 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13911 | /* On the chance that someone will soon try again to delete this |
13912 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13913 | bpt->type = bp_none; |
b8c9b27d | 13914 | xfree (bpt); |
c906108c SS |
13915 | } |
13916 | ||
4d6140d9 AC |
13917 | static void |
13918 | do_delete_breakpoint_cleanup (void *b) | |
13919 | { | |
9a3c8263 | 13920 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13921 | } |
13922 | ||
13923 | struct cleanup * | |
13924 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13925 | { | |
13926 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13927 | } | |
13928 | ||
51be5b68 PA |
13929 | /* Iterator function to call a user-provided callback function once |
13930 | for each of B and its related breakpoints. */ | |
13931 | ||
13932 | static void | |
13933 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13934 | void (*function) (struct breakpoint *, | |
13935 | void *), | |
13936 | void *data) | |
13937 | { | |
13938 | struct breakpoint *related; | |
13939 | ||
13940 | related = b; | |
13941 | do | |
13942 | { | |
13943 | struct breakpoint *next; | |
13944 | ||
13945 | /* FUNCTION may delete RELATED. */ | |
13946 | next = related->related_breakpoint; | |
13947 | ||
13948 | if (next == related) | |
13949 | { | |
13950 | /* RELATED is the last ring entry. */ | |
13951 | function (related, data); | |
13952 | ||
13953 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13954 | B. There's nothing left to do anyway, so just break | |
13955 | out. */ | |
13956 | break; | |
13957 | } | |
13958 | else | |
13959 | function (related, data); | |
13960 | ||
13961 | related = next; | |
13962 | } | |
13963 | while (related != b); | |
13964 | } | |
95a42b64 TT |
13965 | |
13966 | static void | |
13967 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13968 | { | |
13969 | delete_breakpoint (b); | |
13970 | } | |
13971 | ||
51be5b68 PA |
13972 | /* A callback for map_breakpoint_numbers that calls |
13973 | delete_breakpoint. */ | |
13974 | ||
13975 | static void | |
13976 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13977 | { | |
13978 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13979 | } | |
13980 | ||
c906108c | 13981 | void |
fba45db2 | 13982 | delete_command (char *arg, int from_tty) |
c906108c | 13983 | { |
35df4500 | 13984 | struct breakpoint *b, *b_tmp; |
c906108c | 13985 | |
ea9365bb TT |
13986 | dont_repeat (); |
13987 | ||
c906108c SS |
13988 | if (arg == 0) |
13989 | { | |
13990 | int breaks_to_delete = 0; | |
13991 | ||
46c6471b PA |
13992 | /* Delete all breakpoints if no argument. Do not delete |
13993 | internal breakpoints, these have to be deleted with an | |
13994 | explicit breakpoint number argument. */ | |
c5aa993b | 13995 | ALL_BREAKPOINTS (b) |
46c6471b | 13996 | if (user_breakpoint_p (b)) |
973d738b DJ |
13997 | { |
13998 | breaks_to_delete = 1; | |
13999 | break; | |
14000 | } | |
c906108c SS |
14001 | |
14002 | /* Ask user only if there are some breakpoints to delete. */ | |
14003 | if (!from_tty | |
e2e0b3e5 | 14004 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14005 | { |
35df4500 | 14006 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14007 | if (user_breakpoint_p (b)) |
c5aa993b | 14008 | delete_breakpoint (b); |
c906108c SS |
14009 | } |
14010 | } | |
14011 | else | |
51be5b68 | 14012 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14013 | } |
14014 | ||
c2f4122d PA |
14015 | /* Return true if all locations of B bound to PSPACE are pending. If |
14016 | PSPACE is NULL, all locations of all program spaces are | |
14017 | considered. */ | |
14018 | ||
0d381245 | 14019 | static int |
c2f4122d | 14020 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14021 | { |
c2f4122d PA |
14022 | struct bp_location *loc; |
14023 | ||
14024 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14025 | if ((pspace == NULL | |
14026 | || loc->pspace == pspace) | |
14027 | && !loc->shlib_disabled | |
8645ff69 | 14028 | && !loc->pspace->executing_startup) |
0d381245 VP |
14029 | return 0; |
14030 | return 1; | |
fe3f5fa8 VP |
14031 | } |
14032 | ||
776592bf DE |
14033 | /* Subroutine of update_breakpoint_locations to simplify it. |
14034 | Return non-zero if multiple fns in list LOC have the same name. | |
14035 | Null names are ignored. */ | |
14036 | ||
14037 | static int | |
14038 | ambiguous_names_p (struct bp_location *loc) | |
14039 | { | |
14040 | struct bp_location *l; | |
14041 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14042 | (int (*) (const void *, |
14043 | const void *)) streq, | |
776592bf DE |
14044 | NULL, xcalloc, xfree); |
14045 | ||
14046 | for (l = loc; l != NULL; l = l->next) | |
14047 | { | |
14048 | const char **slot; | |
14049 | const char *name = l->function_name; | |
14050 | ||
14051 | /* Allow for some names to be NULL, ignore them. */ | |
14052 | if (name == NULL) | |
14053 | continue; | |
14054 | ||
14055 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14056 | INSERT); | |
4a64f543 MS |
14057 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14058 | returns NULL. */ | |
776592bf DE |
14059 | if (*slot != NULL) |
14060 | { | |
14061 | htab_delete (htab); | |
14062 | return 1; | |
14063 | } | |
14064 | *slot = name; | |
14065 | } | |
14066 | ||
14067 | htab_delete (htab); | |
14068 | return 0; | |
14069 | } | |
14070 | ||
0fb4aa4b PA |
14071 | /* When symbols change, it probably means the sources changed as well, |
14072 | and it might mean the static tracepoint markers are no longer at | |
14073 | the same address or line numbers they used to be at last we | |
14074 | checked. Losing your static tracepoints whenever you rebuild is | |
14075 | undesirable. This function tries to resync/rematch gdb static | |
14076 | tracepoints with the markers on the target, for static tracepoints | |
14077 | that have not been set by marker id. Static tracepoint that have | |
14078 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14079 | The heuristic is: | |
14080 | ||
14081 | 1) For a tracepoint set at a specific address, look for a marker at | |
14082 | the old PC. If one is found there, assume to be the same marker. | |
14083 | If the name / string id of the marker found is different from the | |
14084 | previous known name, assume that means the user renamed the marker | |
14085 | in the sources, and output a warning. | |
14086 | ||
14087 | 2) For a tracepoint set at a given line number, look for a marker | |
14088 | at the new address of the old line number. If one is found there, | |
14089 | assume to be the same marker. If the name / string id of the | |
14090 | marker found is different from the previous known name, assume that | |
14091 | means the user renamed the marker in the sources, and output a | |
14092 | warning. | |
14093 | ||
14094 | 3) If a marker is no longer found at the same address or line, it | |
14095 | may mean the marker no longer exists. But it may also just mean | |
14096 | the code changed a bit. Maybe the user added a few lines of code | |
14097 | that made the marker move up or down (in line number terms). Ask | |
14098 | the target for info about the marker with the string id as we knew | |
14099 | it. If found, update line number and address in the matching | |
14100 | static tracepoint. This will get confused if there's more than one | |
14101 | marker with the same ID (possible in UST, although unadvised | |
14102 | precisely because it confuses tools). */ | |
14103 | ||
14104 | static struct symtab_and_line | |
14105 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14106 | { | |
d9b3f62e | 14107 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14108 | struct static_tracepoint_marker marker; |
14109 | CORE_ADDR pc; | |
0fb4aa4b PA |
14110 | |
14111 | pc = sal.pc; | |
14112 | if (sal.line) | |
14113 | find_line_pc (sal.symtab, sal.line, &pc); | |
14114 | ||
14115 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14116 | { | |
d9b3f62e | 14117 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14118 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14119 | b->number, | |
d9b3f62e | 14120 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14121 | |
d9b3f62e PA |
14122 | xfree (tp->static_trace_marker_id); |
14123 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14124 | release_static_tracepoint_marker (&marker); |
14125 | ||
14126 | return sal; | |
14127 | } | |
14128 | ||
14129 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14130 | by string ID. */ | |
14131 | if (!sal.explicit_pc | |
14132 | && sal.line != 0 | |
14133 | && sal.symtab != NULL | |
d9b3f62e | 14134 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14135 | { |
14136 | VEC(static_tracepoint_marker_p) *markers; | |
14137 | ||
14138 | markers | |
d9b3f62e | 14139 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14140 | |
14141 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14142 | { | |
80e1d417 | 14143 | struct symtab_and_line sal2; |
0fb4aa4b | 14144 | struct symbol *sym; |
80e1d417 | 14145 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14146 | struct ui_out *uiout = current_uiout; |
67994074 | 14147 | struct explicit_location explicit_loc; |
0fb4aa4b | 14148 | |
80e1d417 | 14149 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14150 | |
d9b3f62e | 14151 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14152 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14153 | |
14154 | warning (_("marker for static tracepoint %d (%s) not " | |
14155 | "found at previous line number"), | |
d9b3f62e | 14156 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14157 | |
80e1d417 | 14158 | init_sal (&sal2); |
0fb4aa4b | 14159 | |
80e1d417 | 14160 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14161 | |
80e1d417 AS |
14162 | sal2 = find_pc_line (tpmarker->address, 0); |
14163 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14164 | ui_out_text (uiout, "Now in "); |
14165 | if (sym) | |
14166 | { | |
14167 | ui_out_field_string (uiout, "func", | |
14168 | SYMBOL_PRINT_NAME (sym)); | |
14169 | ui_out_text (uiout, " at "); | |
14170 | } | |
05cba821 JK |
14171 | ui_out_field_string (uiout, "file", |
14172 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14173 | ui_out_text (uiout, ":"); |
14174 | ||
14175 | if (ui_out_is_mi_like_p (uiout)) | |
14176 | { | |
0b0865da | 14177 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14178 | |
f35a17b5 | 14179 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14180 | } |
14181 | ||
80e1d417 | 14182 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14183 | ui_out_text (uiout, "\n"); |
14184 | ||
80e1d417 | 14185 | b->loc->line_number = sal2.line; |
2f202fde | 14186 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14187 | |
f00aae0f | 14188 | delete_event_location (b->location); |
67994074 KS |
14189 | initialize_explicit_location (&explicit_loc); |
14190 | explicit_loc.source_filename | |
00e52e53 | 14191 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14192 | explicit_loc.line_offset.offset = b->loc->line_number; |
14193 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14194 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14195 | |
14196 | /* Might be nice to check if function changed, and warn if | |
14197 | so. */ | |
14198 | ||
80e1d417 | 14199 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14200 | } |
14201 | } | |
14202 | return sal; | |
14203 | } | |
14204 | ||
8d3788bd VP |
14205 | /* Returns 1 iff locations A and B are sufficiently same that |
14206 | we don't need to report breakpoint as changed. */ | |
14207 | ||
14208 | static int | |
14209 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14210 | { | |
14211 | while (a && b) | |
14212 | { | |
14213 | if (a->address != b->address) | |
14214 | return 0; | |
14215 | ||
14216 | if (a->shlib_disabled != b->shlib_disabled) | |
14217 | return 0; | |
14218 | ||
14219 | if (a->enabled != b->enabled) | |
14220 | return 0; | |
14221 | ||
14222 | a = a->next; | |
14223 | b = b->next; | |
14224 | } | |
14225 | ||
14226 | if ((a == NULL) != (b == NULL)) | |
14227 | return 0; | |
14228 | ||
14229 | return 1; | |
14230 | } | |
14231 | ||
c2f4122d PA |
14232 | /* Split all locations of B that are bound to PSPACE out of B's |
14233 | location list to a separate list and return that list's head. If | |
14234 | PSPACE is NULL, hoist out all locations of B. */ | |
14235 | ||
14236 | static struct bp_location * | |
14237 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14238 | { | |
14239 | struct bp_location head; | |
14240 | struct bp_location *i = b->loc; | |
14241 | struct bp_location **i_link = &b->loc; | |
14242 | struct bp_location *hoisted = &head; | |
14243 | ||
14244 | if (pspace == NULL) | |
14245 | { | |
14246 | i = b->loc; | |
14247 | b->loc = NULL; | |
14248 | return i; | |
14249 | } | |
14250 | ||
14251 | head.next = NULL; | |
14252 | ||
14253 | while (i != NULL) | |
14254 | { | |
14255 | if (i->pspace == pspace) | |
14256 | { | |
14257 | *i_link = i->next; | |
14258 | i->next = NULL; | |
14259 | hoisted->next = i; | |
14260 | hoisted = i; | |
14261 | } | |
14262 | else | |
14263 | i_link = &i->next; | |
14264 | i = *i_link; | |
14265 | } | |
14266 | ||
14267 | return head.next; | |
14268 | } | |
14269 | ||
14270 | /* Create new breakpoint locations for B (a hardware or software | |
14271 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14272 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14273 | FILTER_PSPACE. Locations of other program spaces are left | |
14274 | untouched. */ | |
f1310107 | 14275 | |
0e30163f | 14276 | void |
0d381245 | 14277 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14278 | struct program_space *filter_pspace, |
f1310107 TJB |
14279 | struct symtabs_and_lines sals, |
14280 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14281 | { |
14282 | int i; | |
c2f4122d | 14283 | struct bp_location *existing_locations; |
0d381245 | 14284 | |
f8eba3c6 TT |
14285 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14286 | { | |
14287 | /* Ranged breakpoints have only one start location and one end | |
14288 | location. */ | |
14289 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14290 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14291 | "multiple locations found\n"), | |
14292 | b->number); | |
14293 | return; | |
14294 | } | |
f1310107 | 14295 | |
4a64f543 MS |
14296 | /* If there's no new locations, and all existing locations are |
14297 | pending, don't do anything. This optimizes the common case where | |
14298 | all locations are in the same shared library, that was unloaded. | |
14299 | We'd like to retain the location, so that when the library is | |
14300 | loaded again, we don't loose the enabled/disabled status of the | |
14301 | individual locations. */ | |
c2f4122d | 14302 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14303 | return; |
14304 | ||
c2f4122d | 14305 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14306 | |
0d381245 | 14307 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14308 | { |
f8eba3c6 TT |
14309 | struct bp_location *new_loc; |
14310 | ||
14311 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14312 | ||
14313 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14314 | |
0d381245 VP |
14315 | /* Reparse conditions, they might contain references to the |
14316 | old symtab. */ | |
14317 | if (b->cond_string != NULL) | |
14318 | { | |
bbc13ae3 | 14319 | const char *s; |
fe3f5fa8 | 14320 | |
0d381245 | 14321 | s = b->cond_string; |
492d29ea | 14322 | TRY |
0d381245 | 14323 | { |
1bb9788d TT |
14324 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14325 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14326 | 0); |
14327 | } | |
492d29ea | 14328 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14329 | { |
3e43a32a MS |
14330 | warning (_("failed to reevaluate condition " |
14331 | "for breakpoint %d: %s"), | |
0d381245 VP |
14332 | b->number, e.message); |
14333 | new_loc->enabled = 0; | |
14334 | } | |
492d29ea | 14335 | END_CATCH |
0d381245 | 14336 | } |
fe3f5fa8 | 14337 | |
f1310107 TJB |
14338 | if (sals_end.nelts) |
14339 | { | |
14340 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14341 | ||
14342 | new_loc->length = end - sals.sals[0].pc + 1; | |
14343 | } | |
0d381245 | 14344 | } |
fe3f5fa8 | 14345 | |
4a64f543 MS |
14346 | /* If possible, carry over 'disable' status from existing |
14347 | breakpoints. */ | |
0d381245 VP |
14348 | { |
14349 | struct bp_location *e = existing_locations; | |
776592bf DE |
14350 | /* If there are multiple breakpoints with the same function name, |
14351 | e.g. for inline functions, comparing function names won't work. | |
14352 | Instead compare pc addresses; this is just a heuristic as things | |
14353 | may have moved, but in practice it gives the correct answer | |
14354 | often enough until a better solution is found. */ | |
14355 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14356 | ||
0d381245 VP |
14357 | for (; e; e = e->next) |
14358 | { | |
14359 | if (!e->enabled && e->function_name) | |
14360 | { | |
14361 | struct bp_location *l = b->loc; | |
776592bf DE |
14362 | if (have_ambiguous_names) |
14363 | { | |
14364 | for (; l; l = l->next) | |
f1310107 | 14365 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14366 | { |
14367 | l->enabled = 0; | |
14368 | break; | |
14369 | } | |
14370 | } | |
14371 | else | |
14372 | { | |
14373 | for (; l; l = l->next) | |
14374 | if (l->function_name | |
14375 | && strcmp (e->function_name, l->function_name) == 0) | |
14376 | { | |
14377 | l->enabled = 0; | |
14378 | break; | |
14379 | } | |
14380 | } | |
0d381245 VP |
14381 | } |
14382 | } | |
14383 | } | |
fe3f5fa8 | 14384 | |
8d3788bd VP |
14385 | if (!locations_are_equal (existing_locations, b->loc)) |
14386 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14387 | } |
14388 | ||
f00aae0f | 14389 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14390 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14391 | ||
14392 | static struct symtabs_and_lines | |
f00aae0f | 14393 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14394 | struct program_space *search_pspace, int *found) |
ef23e705 | 14395 | { |
02d20e4a | 14396 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14397 | struct gdb_exception exception = exception_none; |
ef23e705 | 14398 | |
983af33b | 14399 | gdb_assert (b->ops != NULL); |
ef23e705 | 14400 | |
492d29ea | 14401 | TRY |
ef23e705 | 14402 | { |
c2f4122d | 14403 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14404 | } |
492d29ea | 14405 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14406 | { |
14407 | int not_found_and_ok = 0; | |
492d29ea PA |
14408 | |
14409 | exception = e; | |
14410 | ||
ef23e705 TJB |
14411 | /* For pending breakpoints, it's expected that parsing will |
14412 | fail until the right shared library is loaded. User has | |
14413 | already told to create pending breakpoints and don't need | |
14414 | extra messages. If breakpoint is in bp_shlib_disabled | |
14415 | state, then user already saw the message about that | |
14416 | breakpoint being disabled, and don't want to see more | |
14417 | errors. */ | |
58438ac1 | 14418 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14419 | && (b->condition_not_parsed |
14420 | || (b->loc != NULL | |
14421 | && search_pspace != NULL | |
14422 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14423 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14424 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14425 | || b->enable_state == bp_disabled)) |
14426 | not_found_and_ok = 1; | |
14427 | ||
14428 | if (!not_found_and_ok) | |
14429 | { | |
14430 | /* We surely don't want to warn about the same breakpoint | |
14431 | 10 times. One solution, implemented here, is disable | |
14432 | the breakpoint on error. Another solution would be to | |
14433 | have separate 'warning emitted' flag. Since this | |
14434 | happens only when a binary has changed, I don't know | |
14435 | which approach is better. */ | |
14436 | b->enable_state = bp_disabled; | |
14437 | throw_exception (e); | |
14438 | } | |
14439 | } | |
492d29ea | 14440 | END_CATCH |
ef23e705 | 14441 | |
492d29ea | 14442 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14443 | { |
f8eba3c6 | 14444 | int i; |
ef23e705 | 14445 | |
f8eba3c6 TT |
14446 | for (i = 0; i < sals.nelts; ++i) |
14447 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14448 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14449 | { |
ed1d1739 KS |
14450 | char *cond_string, *extra_string; |
14451 | int thread, task; | |
ef23e705 | 14452 | |
f00aae0f | 14453 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14454 | &cond_string, &thread, &task, |
14455 | &extra_string); | |
f00aae0f | 14456 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14457 | if (cond_string) |
14458 | b->cond_string = cond_string; | |
14459 | b->thread = thread; | |
14460 | b->task = task; | |
e7e0cddf | 14461 | if (extra_string) |
f00aae0f KS |
14462 | { |
14463 | xfree (b->extra_string); | |
14464 | b->extra_string = extra_string; | |
14465 | } | |
ef23e705 TJB |
14466 | b->condition_not_parsed = 0; |
14467 | } | |
14468 | ||
983af33b | 14469 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14470 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14471 | |
58438ac1 TT |
14472 | *found = 1; |
14473 | } | |
14474 | else | |
14475 | *found = 0; | |
ef23e705 TJB |
14476 | |
14477 | return sals; | |
14478 | } | |
14479 | ||
348d480f PA |
14480 | /* The default re_set method, for typical hardware or software |
14481 | breakpoints. Reevaluate the breakpoint and recreate its | |
14482 | locations. */ | |
14483 | ||
14484 | static void | |
28010a5d | 14485 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14486 | { |
14487 | int found; | |
f1310107 | 14488 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14489 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14490 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14491 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14492 | |
c2f4122d | 14493 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14494 | if (found) |
14495 | { | |
14496 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14497 | expanded = sals; |
ef23e705 TJB |
14498 | } |
14499 | ||
f00aae0f | 14500 | if (b->location_range_end != NULL) |
f1310107 | 14501 | { |
c2f4122d PA |
14502 | sals_end = location_to_sals (b, b->location_range_end, |
14503 | filter_pspace, &found); | |
f1310107 TJB |
14504 | if (found) |
14505 | { | |
14506 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14507 | expanded_end = sals_end; |
f1310107 TJB |
14508 | } |
14509 | } | |
14510 | ||
c2f4122d | 14511 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14512 | } |
14513 | ||
983af33b SDJ |
14514 | /* Default method for creating SALs from an address string. It basically |
14515 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14516 | ||
14517 | static void | |
f00aae0f KS |
14518 | create_sals_from_location_default (const struct event_location *location, |
14519 | struct linespec_result *canonical, | |
14520 | enum bptype type_wanted) | |
983af33b | 14521 | { |
f00aae0f | 14522 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14523 | } |
14524 | ||
14525 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14526 | function for the `create_breakpoints_sal' method of | |
14527 | breakpoint_ops. */ | |
14528 | ||
14529 | static void | |
14530 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14531 | struct linespec_result *canonical, | |
983af33b | 14532 | char *cond_string, |
e7e0cddf | 14533 | char *extra_string, |
983af33b SDJ |
14534 | enum bptype type_wanted, |
14535 | enum bpdisp disposition, | |
14536 | int thread, | |
14537 | int task, int ignore_count, | |
14538 | const struct breakpoint_ops *ops, | |
14539 | int from_tty, int enabled, | |
44f238bb | 14540 | int internal, unsigned flags) |
983af33b SDJ |
14541 | { |
14542 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14543 | extra_string, |
983af33b SDJ |
14544 | type_wanted, disposition, |
14545 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14546 | enabled, internal, flags); |
983af33b SDJ |
14547 | } |
14548 | ||
14549 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14550 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14551 | |
14552 | static void | |
f00aae0f KS |
14553 | decode_location_default (struct breakpoint *b, |
14554 | const struct event_location *location, | |
c2f4122d | 14555 | struct program_space *search_pspace, |
983af33b SDJ |
14556 | struct symtabs_and_lines *sals) |
14557 | { | |
14558 | struct linespec_result canonical; | |
14559 | ||
14560 | init_linespec_result (&canonical); | |
c2f4122d | 14561 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14562 | (struct symtab *) NULL, 0, |
14563 | &canonical, multiple_symbols_all, | |
14564 | b->filter); | |
14565 | ||
14566 | /* We should get 0 or 1 resulting SALs. */ | |
14567 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14568 | ||
14569 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14570 | { | |
14571 | struct linespec_sals *lsal; | |
14572 | ||
14573 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14574 | *sals = lsal->sals; | |
14575 | /* Arrange it so the destructor does not free the | |
14576 | contents. */ | |
14577 | lsal->sals.sals = NULL; | |
14578 | } | |
14579 | ||
14580 | destroy_linespec_result (&canonical); | |
14581 | } | |
14582 | ||
28010a5d PA |
14583 | /* Prepare the global context for a re-set of breakpoint B. */ |
14584 | ||
14585 | static struct cleanup * | |
14586 | prepare_re_set_context (struct breakpoint *b) | |
14587 | { | |
28010a5d | 14588 | input_radix = b->input_radix; |
28010a5d PA |
14589 | set_language (b->language); |
14590 | ||
c2f4122d | 14591 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14592 | } |
14593 | ||
c906108c SS |
14594 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14595 | The value we return ends up being the return value from catch_errors. | |
14596 | Unused in this case. */ | |
14597 | ||
14598 | static int | |
4efb68b1 | 14599 | breakpoint_re_set_one (void *bint) |
c906108c | 14600 | { |
4a64f543 | 14601 | /* Get past catch_errs. */ |
53a5351d | 14602 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14603 | struct cleanup *cleanups; |
c906108c | 14604 | |
348d480f PA |
14605 | cleanups = prepare_re_set_context (b); |
14606 | b->ops->re_set (b); | |
14607 | do_cleanups (cleanups); | |
c906108c SS |
14608 | return 0; |
14609 | } | |
14610 | ||
c2f4122d PA |
14611 | /* Re-set breakpoint locations for the current program space. |
14612 | Locations bound to other program spaces are left untouched. */ | |
14613 | ||
c906108c | 14614 | void |
69de3c6a | 14615 | breakpoint_re_set (void) |
c906108c | 14616 | { |
35df4500 | 14617 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14618 | enum language save_language; |
14619 | int save_input_radix; | |
6c95b8df | 14620 | struct cleanup *old_chain; |
c5aa993b | 14621 | |
c906108c SS |
14622 | save_language = current_language->la_language; |
14623 | save_input_radix = input_radix; | |
c2f4122d | 14624 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14625 | |
2a7f3dff PA |
14626 | /* Note: we must not try to insert locations until after all |
14627 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14628 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14629 | hadn't been re-set yet, and thus may have stale locations. */ | |
14630 | ||
35df4500 | 14631 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14632 | { |
4a64f543 | 14633 | /* Format possible error msg. */ |
fe3f5fa8 | 14634 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14635 | b->number); |
14636 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14637 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14638 | do_cleanups (cleanups); |
c5aa993b | 14639 | } |
c906108c SS |
14640 | set_language (save_language); |
14641 | input_radix = save_input_radix; | |
e62c965a | 14642 | |
0756c555 | 14643 | jit_breakpoint_re_set (); |
4efc6507 | 14644 | |
6c95b8df PA |
14645 | do_cleanups (old_chain); |
14646 | ||
af02033e PP |
14647 | create_overlay_event_breakpoint (); |
14648 | create_longjmp_master_breakpoint (); | |
14649 | create_std_terminate_master_breakpoint (); | |
186c406b | 14650 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14651 | |
14652 | /* Now we can insert. */ | |
14653 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14654 | } |
14655 | \f | |
c906108c SS |
14656 | /* Reset the thread number of this breakpoint: |
14657 | ||
14658 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14659 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14660 | void |
fba45db2 | 14661 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14662 | { |
14663 | if (b->thread != -1) | |
14664 | { | |
39f77062 | 14665 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14666 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14667 | |
14668 | /* We're being called after following a fork. The new fork is | |
14669 | selected as current, and unless this was a vfork will have a | |
14670 | different program space from the original thread. Reset that | |
14671 | as well. */ | |
14672 | b->loc->pspace = current_program_space; | |
c906108c SS |
14673 | } |
14674 | } | |
14675 | ||
03ac34d5 MS |
14676 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14677 | If from_tty is nonzero, it prints a message to that effect, | |
14678 | which ends with a period (no newline). */ | |
14679 | ||
c906108c | 14680 | void |
fba45db2 | 14681 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14682 | { |
52f0bd74 | 14683 | struct breakpoint *b; |
c906108c SS |
14684 | |
14685 | if (count < 0) | |
14686 | count = 0; | |
14687 | ||
14688 | ALL_BREAKPOINTS (b) | |
14689 | if (b->number == bptnum) | |
c5aa993b | 14690 | { |
d77f58be SS |
14691 | if (is_tracepoint (b)) |
14692 | { | |
14693 | if (from_tty && count != 0) | |
14694 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14695 | bptnum); | |
14696 | return; | |
14697 | } | |
14698 | ||
c5aa993b | 14699 | b->ignore_count = count; |
221ea385 KS |
14700 | if (from_tty) |
14701 | { | |
14702 | if (count == 0) | |
3e43a32a MS |
14703 | printf_filtered (_("Will stop next time " |
14704 | "breakpoint %d is reached."), | |
221ea385 KS |
14705 | bptnum); |
14706 | else if (count == 1) | |
a3f17187 | 14707 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14708 | bptnum); |
14709 | else | |
3e43a32a MS |
14710 | printf_filtered (_("Will ignore next %d " |
14711 | "crossings of breakpoint %d."), | |
221ea385 KS |
14712 | count, bptnum); |
14713 | } | |
8d3788bd | 14714 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14715 | return; |
14716 | } | |
c906108c | 14717 | |
8a3fe4f8 | 14718 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14719 | } |
14720 | ||
c906108c SS |
14721 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14722 | ||
14723 | static void | |
fba45db2 | 14724 | ignore_command (char *args, int from_tty) |
c906108c SS |
14725 | { |
14726 | char *p = args; | |
52f0bd74 | 14727 | int num; |
c906108c SS |
14728 | |
14729 | if (p == 0) | |
e2e0b3e5 | 14730 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14731 | |
c906108c | 14732 | num = get_number (&p); |
5c44784c | 14733 | if (num == 0) |
8a3fe4f8 | 14734 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14735 | if (*p == 0) |
8a3fe4f8 | 14736 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14737 | |
14738 | set_ignore_count (num, | |
14739 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14740 | from_tty); | |
221ea385 KS |
14741 | if (from_tty) |
14742 | printf_filtered ("\n"); | |
c906108c SS |
14743 | } |
14744 | \f | |
14745 | /* Call FUNCTION on each of the breakpoints | |
14746 | whose numbers are given in ARGS. */ | |
14747 | ||
14748 | static void | |
95a42b64 TT |
14749 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14750 | void *), | |
14751 | void *data) | |
c906108c | 14752 | { |
52f0bd74 AC |
14753 | int num; |
14754 | struct breakpoint *b, *tmp; | |
11cf8741 | 14755 | int match; |
197f0a60 | 14756 | struct get_number_or_range_state state; |
c906108c | 14757 | |
b9d61307 | 14758 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14759 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14760 | |
197f0a60 TT |
14761 | init_number_or_range (&state, args); |
14762 | ||
14763 | while (!state.finished) | |
c906108c | 14764 | { |
e799154c | 14765 | const char *p = state.string; |
197f0a60 | 14766 | |
11cf8741 | 14767 | match = 0; |
c5aa993b | 14768 | |
197f0a60 | 14769 | num = get_number_or_range (&state); |
5c44784c | 14770 | if (num == 0) |
c5aa993b | 14771 | { |
8a3fe4f8 | 14772 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14773 | } |
14774 | else | |
14775 | { | |
14776 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14777 | if (b->number == num) | |
14778 | { | |
11cf8741 | 14779 | match = 1; |
cdac0397 | 14780 | function (b, data); |
11cf8741 | 14781 | break; |
5c44784c | 14782 | } |
11cf8741 | 14783 | if (match == 0) |
a3f17187 | 14784 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14785 | } |
c906108c SS |
14786 | } |
14787 | } | |
14788 | ||
0d381245 VP |
14789 | static struct bp_location * |
14790 | find_location_by_number (char *number) | |
14791 | { | |
14792 | char *dot = strchr (number, '.'); | |
14793 | char *p1; | |
14794 | int bp_num; | |
14795 | int loc_num; | |
14796 | struct breakpoint *b; | |
14797 | struct bp_location *loc; | |
14798 | ||
14799 | *dot = '\0'; | |
14800 | ||
14801 | p1 = number; | |
197f0a60 | 14802 | bp_num = get_number (&p1); |
0d381245 VP |
14803 | if (bp_num == 0) |
14804 | error (_("Bad breakpoint number '%s'"), number); | |
14805 | ||
14806 | ALL_BREAKPOINTS (b) | |
14807 | if (b->number == bp_num) | |
14808 | { | |
14809 | break; | |
14810 | } | |
14811 | ||
14812 | if (!b || b->number != bp_num) | |
14813 | error (_("Bad breakpoint number '%s'"), number); | |
14814 | ||
14815 | p1 = dot+1; | |
197f0a60 | 14816 | loc_num = get_number (&p1); |
0d381245 VP |
14817 | if (loc_num == 0) |
14818 | error (_("Bad breakpoint location number '%s'"), number); | |
14819 | ||
14820 | --loc_num; | |
14821 | loc = b->loc; | |
14822 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14823 | ; | |
14824 | if (!loc) | |
14825 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14826 | ||
14827 | return loc; | |
14828 | } | |
14829 | ||
14830 | ||
1900040c MS |
14831 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14832 | If from_tty is nonzero, it prints a message to that effect, | |
14833 | which ends with a period (no newline). */ | |
14834 | ||
c906108c | 14835 | void |
fba45db2 | 14836 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14837 | { |
14838 | /* Never disable a watchpoint scope breakpoint; we want to | |
14839 | hit them when we leave scope so we can delete both the | |
14840 | watchpoint and its scope breakpoint at that time. */ | |
14841 | if (bpt->type == bp_watchpoint_scope) | |
14842 | return; | |
14843 | ||
b5de0fa7 | 14844 | bpt->enable_state = bp_disabled; |
c906108c | 14845 | |
b775012e LM |
14846 | /* Mark breakpoint locations modified. */ |
14847 | mark_breakpoint_modified (bpt); | |
14848 | ||
d248b706 KY |
14849 | if (target_supports_enable_disable_tracepoint () |
14850 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14851 | { | |
14852 | struct bp_location *location; | |
14853 | ||
14854 | for (location = bpt->loc; location; location = location->next) | |
14855 | target_disable_tracepoint (location); | |
14856 | } | |
14857 | ||
44702360 | 14858 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14859 | |
8d3788bd | 14860 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14861 | } |
14862 | ||
51be5b68 PA |
14863 | /* A callback for iterate_over_related_breakpoints. */ |
14864 | ||
14865 | static void | |
14866 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14867 | { | |
14868 | disable_breakpoint (b); | |
14869 | } | |
14870 | ||
95a42b64 TT |
14871 | /* A callback for map_breakpoint_numbers that calls |
14872 | disable_breakpoint. */ | |
14873 | ||
14874 | static void | |
14875 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14876 | { | |
51be5b68 | 14877 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14878 | } |
14879 | ||
c906108c | 14880 | static void |
fba45db2 | 14881 | disable_command (char *args, int from_tty) |
c906108c | 14882 | { |
c906108c | 14883 | if (args == 0) |
46c6471b PA |
14884 | { |
14885 | struct breakpoint *bpt; | |
14886 | ||
14887 | ALL_BREAKPOINTS (bpt) | |
14888 | if (user_breakpoint_p (bpt)) | |
14889 | disable_breakpoint (bpt); | |
14890 | } | |
9eaabc75 | 14891 | else |
0d381245 | 14892 | { |
9eaabc75 MW |
14893 | char *num = extract_arg (&args); |
14894 | ||
14895 | while (num) | |
d248b706 | 14896 | { |
9eaabc75 | 14897 | if (strchr (num, '.')) |
b775012e | 14898 | { |
9eaabc75 MW |
14899 | struct bp_location *loc = find_location_by_number (num); |
14900 | ||
14901 | if (loc) | |
14902 | { | |
14903 | if (loc->enabled) | |
14904 | { | |
14905 | loc->enabled = 0; | |
14906 | mark_breakpoint_location_modified (loc); | |
14907 | } | |
14908 | if (target_supports_enable_disable_tracepoint () | |
14909 | && current_trace_status ()->running && loc->owner | |
14910 | && is_tracepoint (loc->owner)) | |
14911 | target_disable_tracepoint (loc); | |
14912 | } | |
44702360 | 14913 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14914 | } |
9eaabc75 MW |
14915 | else |
14916 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14917 | num = extract_arg (&args); | |
d248b706 | 14918 | } |
0d381245 | 14919 | } |
c906108c SS |
14920 | } |
14921 | ||
14922 | static void | |
816338b5 SS |
14923 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14924 | int count) | |
c906108c | 14925 | { |
afe38095 | 14926 | int target_resources_ok; |
c906108c SS |
14927 | |
14928 | if (bpt->type == bp_hardware_breakpoint) | |
14929 | { | |
14930 | int i; | |
c5aa993b | 14931 | i = hw_breakpoint_used_count (); |
53a5351d | 14932 | target_resources_ok = |
d92524f1 | 14933 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14934 | i + 1, 0); |
c906108c | 14935 | if (target_resources_ok == 0) |
8a3fe4f8 | 14936 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14937 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14938 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14939 | } |
14940 | ||
cc60f2e3 | 14941 | if (is_watchpoint (bpt)) |
c906108c | 14942 | { |
d07205c2 | 14943 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14944 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14945 | |
492d29ea | 14946 | TRY |
c906108c | 14947 | { |
3a5c3e22 PA |
14948 | struct watchpoint *w = (struct watchpoint *) bpt; |
14949 | ||
1e718ff1 TJB |
14950 | orig_enable_state = bpt->enable_state; |
14951 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14952 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14953 | } |
492d29ea | 14954 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14955 | { |
1e718ff1 | 14956 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14957 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14958 | bpt->number); | |
14959 | return; | |
c5aa993b | 14960 | } |
492d29ea | 14961 | END_CATCH |
c906108c | 14962 | } |
0101ce28 | 14963 | |
b775012e LM |
14964 | bpt->enable_state = bp_enabled; |
14965 | ||
14966 | /* Mark breakpoint locations modified. */ | |
14967 | mark_breakpoint_modified (bpt); | |
14968 | ||
d248b706 KY |
14969 | if (target_supports_enable_disable_tracepoint () |
14970 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14971 | { | |
14972 | struct bp_location *location; | |
14973 | ||
14974 | for (location = bpt->loc; location; location = location->next) | |
14975 | target_enable_tracepoint (location); | |
14976 | } | |
14977 | ||
b4c291bb | 14978 | bpt->disposition = disposition; |
816338b5 | 14979 | bpt->enable_count = count; |
44702360 | 14980 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14981 | |
8d3788bd | 14982 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14983 | } |
14984 | ||
fe3f5fa8 | 14985 | |
c906108c | 14986 | void |
fba45db2 | 14987 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14988 | { |
816338b5 | 14989 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14990 | } |
14991 | ||
14992 | static void | |
14993 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14994 | { | |
14995 | enable_breakpoint (bpt); | |
c906108c SS |
14996 | } |
14997 | ||
95a42b64 TT |
14998 | /* A callback for map_breakpoint_numbers that calls |
14999 | enable_breakpoint. */ | |
15000 | ||
15001 | static void | |
15002 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15003 | { | |
51be5b68 | 15004 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15005 | } |
15006 | ||
c906108c SS |
15007 | /* The enable command enables the specified breakpoints (or all defined |
15008 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15009 | in stopping the inferior. */ |
c906108c | 15010 | |
c906108c | 15011 | static void |
fba45db2 | 15012 | enable_command (char *args, int from_tty) |
c906108c | 15013 | { |
c906108c | 15014 | if (args == 0) |
46c6471b PA |
15015 | { |
15016 | struct breakpoint *bpt; | |
15017 | ||
15018 | ALL_BREAKPOINTS (bpt) | |
15019 | if (user_breakpoint_p (bpt)) | |
15020 | enable_breakpoint (bpt); | |
15021 | } | |
9eaabc75 | 15022 | else |
0d381245 | 15023 | { |
9eaabc75 MW |
15024 | char *num = extract_arg (&args); |
15025 | ||
15026 | while (num) | |
d248b706 | 15027 | { |
9eaabc75 | 15028 | if (strchr (num, '.')) |
b775012e | 15029 | { |
9eaabc75 MW |
15030 | struct bp_location *loc = find_location_by_number (num); |
15031 | ||
15032 | if (loc) | |
15033 | { | |
15034 | if (!loc->enabled) | |
15035 | { | |
15036 | loc->enabled = 1; | |
15037 | mark_breakpoint_location_modified (loc); | |
15038 | } | |
15039 | if (target_supports_enable_disable_tracepoint () | |
15040 | && current_trace_status ()->running && loc->owner | |
15041 | && is_tracepoint (loc->owner)) | |
15042 | target_enable_tracepoint (loc); | |
15043 | } | |
44702360 | 15044 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15045 | } |
9eaabc75 MW |
15046 | else |
15047 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15048 | num = extract_arg (&args); | |
d248b706 | 15049 | } |
0d381245 | 15050 | } |
c906108c SS |
15051 | } |
15052 | ||
816338b5 SS |
15053 | /* This struct packages up disposition data for application to multiple |
15054 | breakpoints. */ | |
15055 | ||
15056 | struct disp_data | |
15057 | { | |
15058 | enum bpdisp disp; | |
15059 | int count; | |
15060 | }; | |
15061 | ||
c906108c | 15062 | static void |
51be5b68 PA |
15063 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15064 | { | |
816338b5 | 15065 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15066 | |
816338b5 | 15067 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15068 | } |
15069 | ||
15070 | static void | |
15071 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15072 | { |
816338b5 | 15073 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15074 | |
15075 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15076 | } |
15077 | ||
c906108c | 15078 | static void |
fba45db2 | 15079 | enable_once_command (char *args, int from_tty) |
c906108c | 15080 | { |
51be5b68 | 15081 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15082 | } |
15083 | ||
816338b5 SS |
15084 | static void |
15085 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15086 | { | |
15087 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15088 | ||
15089 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15090 | } | |
15091 | ||
15092 | static void | |
15093 | enable_count_command (char *args, int from_tty) | |
15094 | { | |
b9d61307 SM |
15095 | int count; |
15096 | ||
15097 | if (args == NULL) | |
15098 | error_no_arg (_("hit count")); | |
15099 | ||
15100 | count = get_number (&args); | |
816338b5 SS |
15101 | |
15102 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15103 | } | |
15104 | ||
c906108c | 15105 | static void |
51be5b68 | 15106 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15107 | { |
816338b5 | 15108 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15109 | |
15110 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15111 | } |
15112 | ||
c906108c | 15113 | static void |
fba45db2 | 15114 | enable_delete_command (char *args, int from_tty) |
c906108c | 15115 | { |
51be5b68 | 15116 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15117 | } |
15118 | \f | |
fa8d40ab JJ |
15119 | static void |
15120 | set_breakpoint_cmd (char *args, int from_tty) | |
15121 | { | |
15122 | } | |
15123 | ||
15124 | static void | |
15125 | show_breakpoint_cmd (char *args, int from_tty) | |
15126 | { | |
15127 | } | |
15128 | ||
1f3b5d1b PP |
15129 | /* Invalidate last known value of any hardware watchpoint if |
15130 | the memory which that value represents has been written to by | |
15131 | GDB itself. */ | |
15132 | ||
15133 | static void | |
8de0566d YQ |
15134 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15135 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15136 | const bfd_byte *data) |
15137 | { | |
15138 | struct breakpoint *bp; | |
15139 | ||
15140 | ALL_BREAKPOINTS (bp) | |
15141 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15142 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15143 | { |
3a5c3e22 | 15144 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15145 | |
3a5c3e22 PA |
15146 | if (wp->val_valid && wp->val) |
15147 | { | |
15148 | struct bp_location *loc; | |
15149 | ||
15150 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15151 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15152 | && loc->address + loc->length > addr | |
15153 | && addr + len > loc->address) | |
15154 | { | |
15155 | value_free (wp->val); | |
15156 | wp->val = NULL; | |
15157 | wp->val_valid = 0; | |
15158 | } | |
15159 | } | |
1f3b5d1b PP |
15160 | } |
15161 | } | |
15162 | ||
8181d85f DJ |
15163 | /* Create and insert a breakpoint for software single step. */ |
15164 | ||
15165 | void | |
6c95b8df | 15166 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15167 | struct address_space *aspace, |
15168 | CORE_ADDR next_pc) | |
8181d85f | 15169 | { |
7c16b83e PA |
15170 | struct thread_info *tp = inferior_thread (); |
15171 | struct symtab_and_line sal; | |
15172 | CORE_ADDR pc = next_pc; | |
8181d85f | 15173 | |
34b7e8a6 PA |
15174 | if (tp->control.single_step_breakpoints == NULL) |
15175 | { | |
15176 | tp->control.single_step_breakpoints | |
5d5658a1 | 15177 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15178 | } |
8181d85f | 15179 | |
7c16b83e PA |
15180 | sal = find_pc_line (pc, 0); |
15181 | sal.pc = pc; | |
15182 | sal.section = find_pc_overlay (pc); | |
15183 | sal.explicit_pc = 1; | |
34b7e8a6 | 15184 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15185 | |
7c16b83e | 15186 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15187 | } |
15188 | ||
34b7e8a6 | 15189 | /* See breakpoint.h. */ |
f02253f1 HZ |
15190 | |
15191 | int | |
7c16b83e PA |
15192 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15193 | struct address_space *aspace, | |
15194 | CORE_ADDR pc) | |
1aafd4da | 15195 | { |
7c16b83e | 15196 | struct bp_location *loc; |
1aafd4da | 15197 | |
7c16b83e PA |
15198 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15199 | if (loc->inserted | |
15200 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15201 | return 1; | |
1aafd4da | 15202 | |
7c16b83e | 15203 | return 0; |
ef370185 JB |
15204 | } |
15205 | ||
15206 | /* Check whether a software single-step breakpoint is inserted at | |
15207 | PC. */ | |
15208 | ||
15209 | int | |
15210 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15211 | CORE_ADDR pc) | |
15212 | { | |
34b7e8a6 PA |
15213 | struct breakpoint *bpt; |
15214 | ||
15215 | ALL_BREAKPOINTS (bpt) | |
15216 | { | |
15217 | if (bpt->type == bp_single_step | |
15218 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15219 | return 1; | |
15220 | } | |
15221 | return 0; | |
1aafd4da UW |
15222 | } |
15223 | ||
1042e4c0 SS |
15224 | /* Tracepoint-specific operations. */ |
15225 | ||
15226 | /* Set tracepoint count to NUM. */ | |
15227 | static void | |
15228 | set_tracepoint_count (int num) | |
15229 | { | |
15230 | tracepoint_count = num; | |
4fa62494 | 15231 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15232 | } |
15233 | ||
70221824 | 15234 | static void |
1042e4c0 SS |
15235 | trace_command (char *arg, int from_tty) |
15236 | { | |
55aa24fb | 15237 | struct breakpoint_ops *ops; |
f00aae0f KS |
15238 | struct event_location *location; |
15239 | struct cleanup *back_to; | |
55aa24fb | 15240 | |
f00aae0f KS |
15241 | location = string_to_event_location (&arg, current_language); |
15242 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15243 | if (location != NULL |
15244 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15245 | ops = &tracepoint_probe_breakpoint_ops; |
15246 | else | |
15247 | ops = &tracepoint_breakpoint_ops; | |
15248 | ||
558a9d82 | 15249 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15250 | location, |
15251 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15252 | 0 /* tempflag */, |
15253 | bp_tracepoint /* type_wanted */, | |
15254 | 0 /* Ignore count */, | |
15255 | pending_break_support, | |
15256 | ops, | |
15257 | from_tty, | |
15258 | 1 /* enabled */, | |
15259 | 0 /* internal */, 0); | |
f00aae0f | 15260 | do_cleanups (back_to); |
1042e4c0 SS |
15261 | } |
15262 | ||
70221824 | 15263 | static void |
7a697b8d SS |
15264 | ftrace_command (char *arg, int from_tty) |
15265 | { | |
f00aae0f KS |
15266 | struct event_location *location; |
15267 | struct cleanup *back_to; | |
15268 | ||
15269 | location = string_to_event_location (&arg, current_language); | |
15270 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15271 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15272 | location, |
15273 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15274 | 0 /* tempflag */, |
15275 | bp_fast_tracepoint /* type_wanted */, | |
15276 | 0 /* Ignore count */, | |
15277 | pending_break_support, | |
15278 | &tracepoint_breakpoint_ops, | |
15279 | from_tty, | |
15280 | 1 /* enabled */, | |
15281 | 0 /* internal */, 0); | |
f00aae0f | 15282 | do_cleanups (back_to); |
0fb4aa4b PA |
15283 | } |
15284 | ||
15285 | /* strace command implementation. Creates a static tracepoint. */ | |
15286 | ||
70221824 | 15287 | static void |
0fb4aa4b PA |
15288 | strace_command (char *arg, int from_tty) |
15289 | { | |
983af33b | 15290 | struct breakpoint_ops *ops; |
f00aae0f KS |
15291 | struct event_location *location; |
15292 | struct cleanup *back_to; | |
983af33b SDJ |
15293 | |
15294 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15295 | or with a normal static tracepoint. */ | |
61012eef | 15296 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15297 | { |
15298 | ops = &strace_marker_breakpoint_ops; | |
15299 | location = new_linespec_location (&arg); | |
15300 | } | |
983af33b | 15301 | else |
f00aae0f KS |
15302 | { |
15303 | ops = &tracepoint_breakpoint_ops; | |
15304 | location = string_to_event_location (&arg, current_language); | |
15305 | } | |
983af33b | 15306 | |
f00aae0f | 15307 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15308 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15309 | location, |
15310 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15311 | 0 /* tempflag */, |
15312 | bp_static_tracepoint /* type_wanted */, | |
15313 | 0 /* Ignore count */, | |
15314 | pending_break_support, | |
15315 | ops, | |
15316 | from_tty, | |
15317 | 1 /* enabled */, | |
15318 | 0 /* internal */, 0); | |
f00aae0f | 15319 | do_cleanups (back_to); |
7a697b8d SS |
15320 | } |
15321 | ||
409873ef SS |
15322 | /* Set up a fake reader function that gets command lines from a linked |
15323 | list that was acquired during tracepoint uploading. */ | |
15324 | ||
15325 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15326 | static int next_cmd; |
409873ef SS |
15327 | |
15328 | static char * | |
15329 | read_uploaded_action (void) | |
15330 | { | |
15331 | char *rslt; | |
15332 | ||
3149d8c1 | 15333 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15334 | |
3149d8c1 | 15335 | next_cmd++; |
409873ef SS |
15336 | |
15337 | return rslt; | |
15338 | } | |
15339 | ||
00bf0b85 SS |
15340 | /* Given information about a tracepoint as recorded on a target (which |
15341 | can be either a live system or a trace file), attempt to create an | |
15342 | equivalent GDB tracepoint. This is not a reliable process, since | |
15343 | the target does not necessarily have all the information used when | |
15344 | the tracepoint was originally defined. */ | |
15345 | ||
d9b3f62e | 15346 | struct tracepoint * |
00bf0b85 | 15347 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15348 | { |
409873ef | 15349 | char *addr_str, small_buf[100]; |
d9b3f62e | 15350 | struct tracepoint *tp; |
f00aae0f KS |
15351 | struct event_location *location; |
15352 | struct cleanup *cleanup; | |
fd9b8c24 | 15353 | |
409873ef SS |
15354 | if (utp->at_string) |
15355 | addr_str = utp->at_string; | |
15356 | else | |
15357 | { | |
15358 | /* In the absence of a source location, fall back to raw | |
15359 | address. Since there is no way to confirm that the address | |
15360 | means the same thing as when the trace was started, warn the | |
15361 | user. */ | |
3e43a32a MS |
15362 | warning (_("Uploaded tracepoint %d has no " |
15363 | "source location, using raw address"), | |
409873ef | 15364 | utp->number); |
8c042590 | 15365 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15366 | addr_str = small_buf; |
15367 | } | |
15368 | ||
15369 | /* There's not much we can do with a sequence of bytecodes. */ | |
15370 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15371 | warning (_("Uploaded tracepoint %d condition " |
15372 | "has no source form, ignoring it"), | |
409873ef | 15373 | utp->number); |
d5551862 | 15374 | |
f00aae0f KS |
15375 | location = string_to_event_location (&addr_str, current_language); |
15376 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15377 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15378 | location, |
15379 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15380 | 0 /* parse cond/thread */, |
8cdf0e15 | 15381 | 0 /* tempflag */, |
0fb4aa4b | 15382 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15383 | 0 /* Ignore count */, |
15384 | pending_break_support, | |
348d480f | 15385 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15386 | 0 /* from_tty */, |
84f4c1fe | 15387 | utp->enabled /* enabled */, |
44f238bb PA |
15388 | 0 /* internal */, |
15389 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15390 | { |
15391 | do_cleanups (cleanup); | |
15392 | return NULL; | |
15393 | } | |
15394 | ||
15395 | do_cleanups (cleanup); | |
fd9b8c24 | 15396 | |
409873ef | 15397 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15398 | tp = get_tracepoint (tracepoint_count); |
15399 | gdb_assert (tp != NULL); | |
d5551862 | 15400 | |
00bf0b85 SS |
15401 | if (utp->pass > 0) |
15402 | { | |
8c042590 PM |
15403 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15404 | tp->base.number); | |
00bf0b85 | 15405 | |
409873ef | 15406 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15407 | } |
15408 | ||
409873ef SS |
15409 | /* If we have uploaded versions of the original commands, set up a |
15410 | special-purpose "reader" function and call the usual command line | |
15411 | reader, then pass the result to the breakpoint command-setting | |
15412 | function. */ | |
3149d8c1 | 15413 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15414 | { |
409873ef | 15415 | struct command_line *cmd_list; |
00bf0b85 | 15416 | |
409873ef | 15417 | this_utp = utp; |
3149d8c1 | 15418 | next_cmd = 0; |
d5551862 | 15419 | |
409873ef SS |
15420 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15421 | ||
d9b3f62e | 15422 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15423 | } |
3149d8c1 SS |
15424 | else if (!VEC_empty (char_ptr, utp->actions) |
15425 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15426 | warning (_("Uploaded tracepoint %d actions " |
15427 | "have no source form, ignoring them"), | |
409873ef | 15428 | utp->number); |
00bf0b85 | 15429 | |
f196051f SS |
15430 | /* Copy any status information that might be available. */ |
15431 | tp->base.hit_count = utp->hit_count; | |
15432 | tp->traceframe_usage = utp->traceframe_usage; | |
15433 | ||
00bf0b85 | 15434 | return tp; |
d9b3f62e | 15435 | } |
00bf0b85 | 15436 | |
1042e4c0 SS |
15437 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15438 | omitted. */ | |
15439 | ||
15440 | static void | |
e5a67952 | 15441 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15442 | { |
79a45e25 | 15443 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15444 | int num_printed; |
1042e4c0 | 15445 | |
e5a67952 | 15446 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15447 | |
15448 | if (num_printed == 0) | |
1042e4c0 | 15449 | { |
e5a67952 | 15450 | if (args == NULL || *args == '\0') |
d77f58be SS |
15451 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15452 | else | |
e5a67952 | 15453 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15454 | } |
ad443146 SS |
15455 | |
15456 | default_collect_info (); | |
1042e4c0 SS |
15457 | } |
15458 | ||
4a64f543 | 15459 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15460 | Not supported by all targets. */ |
15461 | static void | |
15462 | enable_trace_command (char *args, int from_tty) | |
15463 | { | |
15464 | enable_command (args, from_tty); | |
15465 | } | |
15466 | ||
4a64f543 | 15467 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15468 | Not supported by all targets. */ |
15469 | static void | |
15470 | disable_trace_command (char *args, int from_tty) | |
15471 | { | |
15472 | disable_command (args, from_tty); | |
15473 | } | |
15474 | ||
4a64f543 | 15475 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15476 | static void |
15477 | delete_trace_command (char *arg, int from_tty) | |
15478 | { | |
35df4500 | 15479 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15480 | |
15481 | dont_repeat (); | |
15482 | ||
15483 | if (arg == 0) | |
15484 | { | |
15485 | int breaks_to_delete = 0; | |
15486 | ||
15487 | /* Delete all breakpoints if no argument. | |
15488 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15489 | have to be deleted with an explicit breakpoint number |
15490 | argument. */ | |
1042e4c0 | 15491 | ALL_TRACEPOINTS (b) |
46c6471b | 15492 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15493 | { |
15494 | breaks_to_delete = 1; | |
15495 | break; | |
15496 | } | |
1042e4c0 SS |
15497 | |
15498 | /* Ask user only if there are some breakpoints to delete. */ | |
15499 | if (!from_tty | |
15500 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15501 | { | |
35df4500 | 15502 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15503 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15504 | delete_breakpoint (b); |
1042e4c0 SS |
15505 | } |
15506 | } | |
15507 | else | |
51be5b68 | 15508 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15509 | } |
15510 | ||
197f0a60 TT |
15511 | /* Helper function for trace_pass_command. */ |
15512 | ||
15513 | static void | |
d9b3f62e | 15514 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15515 | { |
d9b3f62e | 15516 | tp->pass_count = count; |
6f6484cd | 15517 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15518 | if (from_tty) |
15519 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15520 | tp->base.number, count); |
197f0a60 TT |
15521 | } |
15522 | ||
1042e4c0 SS |
15523 | /* Set passcount for tracepoint. |
15524 | ||
15525 | First command argument is passcount, second is tracepoint number. | |
15526 | If tracepoint number omitted, apply to most recently defined. | |
15527 | Also accepts special argument "all". */ | |
15528 | ||
15529 | static void | |
15530 | trace_pass_command (char *args, int from_tty) | |
15531 | { | |
d9b3f62e | 15532 | struct tracepoint *t1; |
1042e4c0 | 15533 | unsigned int count; |
1042e4c0 SS |
15534 | |
15535 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15536 | error (_("passcount command requires an " |
15537 | "argument (count + optional TP num)")); | |
1042e4c0 | 15538 | |
4a64f543 | 15539 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15540 | |
529480d0 | 15541 | args = skip_spaces (args); |
1042e4c0 SS |
15542 | if (*args && strncasecmp (args, "all", 3) == 0) |
15543 | { | |
d9b3f62e PA |
15544 | struct breakpoint *b; |
15545 | ||
1042e4c0 | 15546 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15547 | if (*args) |
15548 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15549 | |
d9b3f62e | 15550 | ALL_TRACEPOINTS (b) |
197f0a60 | 15551 | { |
d9b3f62e | 15552 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15553 | trace_pass_set_count (t1, count, from_tty); |
15554 | } | |
15555 | } | |
15556 | else if (*args == '\0') | |
1042e4c0 | 15557 | { |
5fa1d40e | 15558 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15559 | if (t1) |
197f0a60 TT |
15560 | trace_pass_set_count (t1, count, from_tty); |
15561 | } | |
15562 | else | |
15563 | { | |
15564 | struct get_number_or_range_state state; | |
15565 | ||
15566 | init_number_or_range (&state, args); | |
15567 | while (!state.finished) | |
1042e4c0 | 15568 | { |
5fa1d40e | 15569 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15570 | if (t1) |
15571 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15572 | } |
15573 | } | |
1042e4c0 SS |
15574 | } |
15575 | ||
d9b3f62e | 15576 | struct tracepoint * |
1042e4c0 SS |
15577 | get_tracepoint (int num) |
15578 | { | |
15579 | struct breakpoint *t; | |
15580 | ||
15581 | ALL_TRACEPOINTS (t) | |
15582 | if (t->number == num) | |
d9b3f62e | 15583 | return (struct tracepoint *) t; |
1042e4c0 SS |
15584 | |
15585 | return NULL; | |
15586 | } | |
15587 | ||
d5551862 SS |
15588 | /* Find the tracepoint with the given target-side number (which may be |
15589 | different from the tracepoint number after disconnecting and | |
15590 | reconnecting). */ | |
15591 | ||
d9b3f62e | 15592 | struct tracepoint * |
d5551862 SS |
15593 | get_tracepoint_by_number_on_target (int num) |
15594 | { | |
d9b3f62e | 15595 | struct breakpoint *b; |
d5551862 | 15596 | |
d9b3f62e PA |
15597 | ALL_TRACEPOINTS (b) |
15598 | { | |
15599 | struct tracepoint *t = (struct tracepoint *) b; | |
15600 | ||
15601 | if (t->number_on_target == num) | |
15602 | return t; | |
15603 | } | |
d5551862 SS |
15604 | |
15605 | return NULL; | |
15606 | } | |
15607 | ||
1042e4c0 | 15608 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15609 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15610 | If the argument is missing, the most recent tracepoint |
15611 | (tracepoint_count) is returned. */ | |
15612 | ||
d9b3f62e | 15613 | struct tracepoint * |
197f0a60 | 15614 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15615 | struct get_number_or_range_state *state) |
1042e4c0 | 15616 | { |
1042e4c0 SS |
15617 | struct breakpoint *t; |
15618 | int tpnum; | |
15619 | char *instring = arg == NULL ? NULL : *arg; | |
15620 | ||
197f0a60 TT |
15621 | if (state) |
15622 | { | |
15623 | gdb_assert (!state->finished); | |
15624 | tpnum = get_number_or_range (state); | |
15625 | } | |
15626 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15627 | tpnum = tracepoint_count; |
1042e4c0 | 15628 | else |
197f0a60 | 15629 | tpnum = get_number (arg); |
1042e4c0 SS |
15630 | |
15631 | if (tpnum <= 0) | |
15632 | { | |
15633 | if (instring && *instring) | |
15634 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15635 | instring); | |
15636 | else | |
5fa1d40e | 15637 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15638 | return NULL; |
15639 | } | |
15640 | ||
15641 | ALL_TRACEPOINTS (t) | |
15642 | if (t->number == tpnum) | |
15643 | { | |
d9b3f62e | 15644 | return (struct tracepoint *) t; |
1042e4c0 SS |
15645 | } |
15646 | ||
1042e4c0 SS |
15647 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15648 | return NULL; | |
15649 | } | |
15650 | ||
d9b3f62e PA |
15651 | void |
15652 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15653 | { | |
15654 | if (b->thread != -1) | |
15655 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15656 | ||
15657 | if (b->task != 0) | |
15658 | fprintf_unfiltered (fp, " task %d", b->task); | |
15659 | ||
15660 | fprintf_unfiltered (fp, "\n"); | |
15661 | } | |
15662 | ||
6149aea9 PA |
15663 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15664 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15665 | on each breakpoint and only include the ones for which it returns | |
15666 | non-zero. */ | |
15667 | ||
1042e4c0 | 15668 | static void |
6149aea9 PA |
15669 | save_breakpoints (char *filename, int from_tty, |
15670 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15671 | { |
15672 | struct breakpoint *tp; | |
6149aea9 | 15673 | int any = 0; |
1042e4c0 | 15674 | struct cleanup *cleanup; |
a7bdde9e | 15675 | struct ui_file *fp; |
6149aea9 | 15676 | int extra_trace_bits = 0; |
1042e4c0 | 15677 | |
6149aea9 PA |
15678 | if (filename == 0 || *filename == 0) |
15679 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15680 | |
15681 | /* See if we have anything to save. */ | |
6149aea9 | 15682 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15683 | { |
6149aea9 | 15684 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15685 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15686 | continue; |
15687 | ||
15688 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15689 | if (filter && !filter (tp)) | |
15690 | continue; | |
15691 | ||
15692 | any = 1; | |
15693 | ||
15694 | if (is_tracepoint (tp)) | |
15695 | { | |
15696 | extra_trace_bits = 1; | |
15697 | ||
15698 | /* We can stop searching. */ | |
15699 | break; | |
15700 | } | |
1042e4c0 | 15701 | } |
6149aea9 PA |
15702 | |
15703 | if (!any) | |
1042e4c0 | 15704 | { |
6149aea9 | 15705 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15706 | return; |
15707 | } | |
15708 | ||
c718be47 PA |
15709 | filename = tilde_expand (filename); |
15710 | cleanup = make_cleanup (xfree, filename); | |
15711 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15712 | if (!fp) |
6149aea9 PA |
15713 | error (_("Unable to open file '%s' for saving (%s)"), |
15714 | filename, safe_strerror (errno)); | |
a7bdde9e | 15715 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15716 | |
6149aea9 PA |
15717 | if (extra_trace_bits) |
15718 | save_trace_state_variables (fp); | |
8bf6485c | 15719 | |
6149aea9 | 15720 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15721 | { |
6149aea9 | 15722 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15723 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15724 | continue; |
8bf6485c | 15725 | |
6149aea9 PA |
15726 | /* If we have a filter, only save the breakpoints it accepts. */ |
15727 | if (filter && !filter (tp)) | |
15728 | continue; | |
15729 | ||
348d480f | 15730 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15731 | |
6149aea9 PA |
15732 | /* Note, we can't rely on tp->number for anything, as we can't |
15733 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15734 | instead. */ | |
15735 | ||
15736 | if (tp->cond_string) | |
15737 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15738 | ||
15739 | if (tp->ignore_count) | |
15740 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15741 | ||
2d9442cc | 15742 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15743 | { |
6c63c96a | 15744 | struct gdb_exception exception; |
a7bdde9e | 15745 | |
6149aea9 | 15746 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15747 | |
79a45e25 | 15748 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15749 | TRY |
1042e4c0 | 15750 | { |
79a45e25 | 15751 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15752 | } |
492d29ea PA |
15753 | CATCH (ex, RETURN_MASK_ALL) |
15754 | { | |
6c63c96a | 15755 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15756 | throw_exception (ex); |
15757 | } | |
15758 | END_CATCH | |
1042e4c0 | 15759 | |
6c63c96a | 15760 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15761 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15762 | } |
6149aea9 PA |
15763 | |
15764 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15765 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15766 | |
15767 | /* If this is a multi-location breakpoint, check if the locations | |
15768 | should be individually disabled. Watchpoint locations are | |
15769 | special, and not user visible. */ | |
15770 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15771 | { | |
15772 | struct bp_location *loc; | |
15773 | int n = 1; | |
15774 | ||
15775 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15776 | if (!loc->enabled) | |
15777 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15778 | } | |
1042e4c0 | 15779 | } |
8bf6485c | 15780 | |
6149aea9 | 15781 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15782 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15783 | ||
1042e4c0 | 15784 | if (from_tty) |
6149aea9 | 15785 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15786 | do_cleanups (cleanup); |
6149aea9 PA |
15787 | } |
15788 | ||
15789 | /* The `save breakpoints' command. */ | |
15790 | ||
15791 | static void | |
15792 | save_breakpoints_command (char *args, int from_tty) | |
15793 | { | |
15794 | save_breakpoints (args, from_tty, NULL); | |
15795 | } | |
15796 | ||
15797 | /* The `save tracepoints' command. */ | |
15798 | ||
15799 | static void | |
15800 | save_tracepoints_command (char *args, int from_tty) | |
15801 | { | |
15802 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15803 | } |
15804 | ||
15805 | /* Create a vector of all tracepoints. */ | |
15806 | ||
15807 | VEC(breakpoint_p) * | |
eeae04df | 15808 | all_tracepoints (void) |
1042e4c0 SS |
15809 | { |
15810 | VEC(breakpoint_p) *tp_vec = 0; | |
15811 | struct breakpoint *tp; | |
15812 | ||
15813 | ALL_TRACEPOINTS (tp) | |
15814 | { | |
15815 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15816 | } | |
15817 | ||
15818 | return tp_vec; | |
15819 | } | |
15820 | ||
c906108c | 15821 | \f |
629500fa KS |
15822 | /* This help string is used to consolidate all the help string for specifying |
15823 | locations used by several commands. */ | |
15824 | ||
15825 | #define LOCATION_HELP_STRING \ | |
15826 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15827 | source filename, function name, label name, and line number.\n\ | |
15828 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15829 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15830 | \"factorial.c:fact:the_top\".\n\ | |
15831 | \n\ | |
15832 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15833 | program. Example: To specify the fourth byte past the start function\n\ | |
15834 | \"main\", use \"*main + 4\".\n\ | |
15835 | \n\ | |
15836 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15837 | syntax to specify location parameters.\n\ | |
15838 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15839 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15840 | -function fact -label the_top\".\n" | |
15841 | ||
4a64f543 MS |
15842 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15843 | commands. It is defined as a macro to prevent duplication. | |
15844 | COMMAND should be a string constant containing the name of the | |
15845 | command. */ | |
629500fa | 15846 | |
31e2b00f | 15847 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15848 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15849 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15850 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15851 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15852 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15853 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15854 | below.\n\ | |
15855 | \n\ | |
dc10affe PA |
15856 | With no LOCATION, uses current execution address of the selected\n\ |
15857 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15858 | \n\ |
15859 | THREADNUM is the number from \"info threads\".\n\ | |
15860 | CONDITION is a boolean expression.\n\ | |
629500fa | 15861 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15862 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15863 | conditions are different.\n\ | |
31e2b00f AS |
15864 | \n\ |
15865 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15866 | ||
44feb3ce TT |
15867 | /* List of subcommands for "catch". */ |
15868 | static struct cmd_list_element *catch_cmdlist; | |
15869 | ||
15870 | /* List of subcommands for "tcatch". */ | |
15871 | static struct cmd_list_element *tcatch_cmdlist; | |
15872 | ||
9ac4176b | 15873 | void |
44feb3ce | 15874 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15875 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15876 | completer_ftype *completer, |
44feb3ce TT |
15877 | void *user_data_catch, |
15878 | void *user_data_tcatch) | |
15879 | { | |
15880 | struct cmd_list_element *command; | |
15881 | ||
15882 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15883 | &catch_cmdlist); | |
15884 | set_cmd_sfunc (command, sfunc); | |
15885 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15886 | set_cmd_completer (command, completer); |
44feb3ce TT |
15887 | |
15888 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15889 | &tcatch_cmdlist); | |
15890 | set_cmd_sfunc (command, sfunc); | |
15891 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15892 | set_cmd_completer (command, completer); |
44feb3ce TT |
15893 | } |
15894 | ||
6149aea9 PA |
15895 | static void |
15896 | save_command (char *arg, int from_tty) | |
15897 | { | |
3e43a32a MS |
15898 | printf_unfiltered (_("\"save\" must be followed by " |
15899 | "the name of a save subcommand.\n")); | |
635c7e8a | 15900 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15901 | } |
15902 | ||
84f4c1fe PM |
15903 | struct breakpoint * |
15904 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15905 | void *data) | |
15906 | { | |
35df4500 | 15907 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15908 | |
35df4500 | 15909 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15910 | { |
15911 | if ((*callback) (b, data)) | |
15912 | return b; | |
15913 | } | |
15914 | ||
15915 | return NULL; | |
15916 | } | |
15917 | ||
0574c78f GB |
15918 | /* Zero if any of the breakpoint's locations could be a location where |
15919 | functions have been inlined, nonzero otherwise. */ | |
15920 | ||
15921 | static int | |
15922 | is_non_inline_function (struct breakpoint *b) | |
15923 | { | |
15924 | /* The shared library event breakpoint is set on the address of a | |
15925 | non-inline function. */ | |
15926 | if (b->type == bp_shlib_event) | |
15927 | return 1; | |
15928 | ||
15929 | return 0; | |
15930 | } | |
15931 | ||
15932 | /* Nonzero if the specified PC cannot be a location where functions | |
15933 | have been inlined. */ | |
15934 | ||
15935 | int | |
09ac7c10 TT |
15936 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15937 | const struct target_waitstatus *ws) | |
0574c78f GB |
15938 | { |
15939 | struct breakpoint *b; | |
15940 | struct bp_location *bl; | |
15941 | ||
15942 | ALL_BREAKPOINTS (b) | |
15943 | { | |
15944 | if (!is_non_inline_function (b)) | |
15945 | continue; | |
15946 | ||
15947 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15948 | { | |
15949 | if (!bl->shlib_disabled | |
09ac7c10 | 15950 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15951 | return 1; |
15952 | } | |
15953 | } | |
15954 | ||
15955 | return 0; | |
15956 | } | |
15957 | ||
2f202fde JK |
15958 | /* Remove any references to OBJFILE which is going to be freed. */ |
15959 | ||
15960 | void | |
15961 | breakpoint_free_objfile (struct objfile *objfile) | |
15962 | { | |
15963 | struct bp_location **locp, *loc; | |
15964 | ||
15965 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15966 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15967 | loc->symtab = NULL; |
15968 | } | |
15969 | ||
2060206e PA |
15970 | void |
15971 | initialize_breakpoint_ops (void) | |
15972 | { | |
15973 | static int initialized = 0; | |
15974 | ||
15975 | struct breakpoint_ops *ops; | |
15976 | ||
15977 | if (initialized) | |
15978 | return; | |
15979 | initialized = 1; | |
15980 | ||
15981 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15982 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15983 | internal and momentary breakpoints, etc.). */ | |
15984 | ops = &bkpt_base_breakpoint_ops; | |
15985 | *ops = base_breakpoint_ops; | |
15986 | ops->re_set = bkpt_re_set; | |
15987 | ops->insert_location = bkpt_insert_location; | |
15988 | ops->remove_location = bkpt_remove_location; | |
15989 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15990 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15991 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15992 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15993 | |
15994 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15995 | ops = &bkpt_breakpoint_ops; | |
15996 | *ops = bkpt_base_breakpoint_ops; | |
15997 | ops->re_set = bkpt_re_set; | |
15998 | ops->resources_needed = bkpt_resources_needed; | |
15999 | ops->print_it = bkpt_print_it; | |
16000 | ops->print_mention = bkpt_print_mention; | |
16001 | ops->print_recreate = bkpt_print_recreate; | |
16002 | ||
16003 | /* Ranged breakpoints. */ | |
16004 | ops = &ranged_breakpoint_ops; | |
16005 | *ops = bkpt_breakpoint_ops; | |
16006 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16007 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16008 | ops->print_it = print_it_ranged_breakpoint; | |
16009 | ops->print_one = print_one_ranged_breakpoint; | |
16010 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16011 | ops->print_mention = print_mention_ranged_breakpoint; | |
16012 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16013 | ||
16014 | /* Internal breakpoints. */ | |
16015 | ops = &internal_breakpoint_ops; | |
16016 | *ops = bkpt_base_breakpoint_ops; | |
16017 | ops->re_set = internal_bkpt_re_set; | |
16018 | ops->check_status = internal_bkpt_check_status; | |
16019 | ops->print_it = internal_bkpt_print_it; | |
16020 | ops->print_mention = internal_bkpt_print_mention; | |
16021 | ||
16022 | /* Momentary breakpoints. */ | |
16023 | ops = &momentary_breakpoint_ops; | |
16024 | *ops = bkpt_base_breakpoint_ops; | |
16025 | ops->re_set = momentary_bkpt_re_set; | |
16026 | ops->check_status = momentary_bkpt_check_status; | |
16027 | ops->print_it = momentary_bkpt_print_it; | |
16028 | ops->print_mention = momentary_bkpt_print_mention; | |
16029 | ||
e2e4d78b JK |
16030 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16031 | ops = &longjmp_breakpoint_ops; | |
16032 | *ops = momentary_breakpoint_ops; | |
16033 | ops->dtor = longjmp_bkpt_dtor; | |
16034 | ||
55aa24fb SDJ |
16035 | /* Probe breakpoints. */ |
16036 | ops = &bkpt_probe_breakpoint_ops; | |
16037 | *ops = bkpt_breakpoint_ops; | |
16038 | ops->insert_location = bkpt_probe_insert_location; | |
16039 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16040 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16041 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16042 | |
2060206e PA |
16043 | /* Watchpoints. */ |
16044 | ops = &watchpoint_breakpoint_ops; | |
16045 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16046 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16047 | ops->re_set = re_set_watchpoint; |
16048 | ops->insert_location = insert_watchpoint; | |
16049 | ops->remove_location = remove_watchpoint; | |
16050 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16051 | ops->check_status = check_status_watchpoint; | |
16052 | ops->resources_needed = resources_needed_watchpoint; | |
16053 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16054 | ops->print_it = print_it_watchpoint; | |
16055 | ops->print_mention = print_mention_watchpoint; | |
16056 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16057 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16058 | |
16059 | /* Masked watchpoints. */ | |
16060 | ops = &masked_watchpoint_breakpoint_ops; | |
16061 | *ops = watchpoint_breakpoint_ops; | |
16062 | ops->insert_location = insert_masked_watchpoint; | |
16063 | ops->remove_location = remove_masked_watchpoint; | |
16064 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16065 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16066 | ops->print_it = print_it_masked_watchpoint; | |
16067 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16068 | ops->print_mention = print_mention_masked_watchpoint; | |
16069 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16070 | ||
16071 | /* Tracepoints. */ | |
16072 | ops = &tracepoint_breakpoint_ops; | |
16073 | *ops = base_breakpoint_ops; | |
16074 | ops->re_set = tracepoint_re_set; | |
16075 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16076 | ops->print_one_detail = tracepoint_print_one_detail; | |
16077 | ops->print_mention = tracepoint_print_mention; | |
16078 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16079 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16080 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16081 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16082 | |
55aa24fb SDJ |
16083 | /* Probe tracepoints. */ |
16084 | ops = &tracepoint_probe_breakpoint_ops; | |
16085 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16086 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16087 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16088 | |
983af33b SDJ |
16089 | /* Static tracepoints with marker (`-m'). */ |
16090 | ops = &strace_marker_breakpoint_ops; | |
16091 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16092 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16093 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16094 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16095 | |
16096 | /* Fork catchpoints. */ | |
16097 | ops = &catch_fork_breakpoint_ops; | |
16098 | *ops = base_breakpoint_ops; | |
16099 | ops->insert_location = insert_catch_fork; | |
16100 | ops->remove_location = remove_catch_fork; | |
16101 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16102 | ops->print_it = print_it_catch_fork; | |
16103 | ops->print_one = print_one_catch_fork; | |
16104 | ops->print_mention = print_mention_catch_fork; | |
16105 | ops->print_recreate = print_recreate_catch_fork; | |
16106 | ||
16107 | /* Vfork catchpoints. */ | |
16108 | ops = &catch_vfork_breakpoint_ops; | |
16109 | *ops = base_breakpoint_ops; | |
16110 | ops->insert_location = insert_catch_vfork; | |
16111 | ops->remove_location = remove_catch_vfork; | |
16112 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16113 | ops->print_it = print_it_catch_vfork; | |
16114 | ops->print_one = print_one_catch_vfork; | |
16115 | ops->print_mention = print_mention_catch_vfork; | |
16116 | ops->print_recreate = print_recreate_catch_vfork; | |
16117 | ||
16118 | /* Exec catchpoints. */ | |
16119 | ops = &catch_exec_breakpoint_ops; | |
16120 | *ops = base_breakpoint_ops; | |
16121 | ops->dtor = dtor_catch_exec; | |
16122 | ops->insert_location = insert_catch_exec; | |
16123 | ops->remove_location = remove_catch_exec; | |
16124 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16125 | ops->print_it = print_it_catch_exec; | |
16126 | ops->print_one = print_one_catch_exec; | |
16127 | ops->print_mention = print_mention_catch_exec; | |
16128 | ops->print_recreate = print_recreate_catch_exec; | |
16129 | ||
edcc5120 TT |
16130 | /* Solib-related catchpoints. */ |
16131 | ops = &catch_solib_breakpoint_ops; | |
16132 | *ops = base_breakpoint_ops; | |
16133 | ops->dtor = dtor_catch_solib; | |
16134 | ops->insert_location = insert_catch_solib; | |
16135 | ops->remove_location = remove_catch_solib; | |
16136 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16137 | ops->check_status = check_status_catch_solib; | |
16138 | ops->print_it = print_it_catch_solib; | |
16139 | ops->print_one = print_one_catch_solib; | |
16140 | ops->print_mention = print_mention_catch_solib; | |
16141 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16142 | |
16143 | ops = &dprintf_breakpoint_ops; | |
16144 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16145 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16146 | ops->resources_needed = bkpt_resources_needed; |
16147 | ops->print_it = bkpt_print_it; | |
16148 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16149 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16150 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16151 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16152 | } |
16153 | ||
8bfd80db YQ |
16154 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16155 | ||
16156 | static struct cmd_list_element *enablebreaklist = NULL; | |
16157 | ||
c906108c | 16158 | void |
fba45db2 | 16159 | _initialize_breakpoint (void) |
c906108c SS |
16160 | { |
16161 | struct cmd_list_element *c; | |
16162 | ||
2060206e PA |
16163 | initialize_breakpoint_ops (); |
16164 | ||
84acb35a | 16165 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16166 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16167 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16168 | |
55aa24fb SDJ |
16169 | breakpoint_objfile_key |
16170 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16171 | |
c906108c SS |
16172 | breakpoint_chain = 0; |
16173 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16174 | before a breakpoint is set. */ | |
16175 | breakpoint_count = 0; | |
16176 | ||
1042e4c0 SS |
16177 | tracepoint_count = 0; |
16178 | ||
1bedd215 AC |
16179 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16180 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16181 | Usage is `ignore N COUNT'.")); | |
c906108c | 16182 | |
1bedd215 AC |
16183 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16184 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16185 | Give breakpoint number as argument after \"commands\".\n\ |
16186 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16187 | The commands themselves follow starting on the next line.\n\ | |
16188 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16189 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16190 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16191 | |
d55637df | 16192 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16193 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16194 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16195 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16196 | set_cmd_completer (c, condition_completer); |
c906108c | 16197 | |
1bedd215 | 16198 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16199 | Set a temporary breakpoint.\n\ |
c906108c SS |
16200 | Like \"break\" except the breakpoint is only temporary,\n\ |
16201 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16202 | by using \"enable delete\" on the breakpoint number.\n\ |
16203 | \n" | |
16204 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16205 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16206 | |
1bedd215 | 16207 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16208 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16209 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16210 | some target hardware may not have this support.\n\ |
16211 | \n" | |
16212 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16213 | set_cmd_completer (c, location_completer); |
c906108c | 16214 | |
1bedd215 | 16215 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16216 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16217 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16218 | so it will be deleted when hit.\n\ |
16219 | \n" | |
16220 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16221 | set_cmd_completer (c, location_completer); |
c906108c | 16222 | |
1bedd215 AC |
16223 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16224 | Enable some breakpoints.\n\ | |
c906108c SS |
16225 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16226 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16227 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16228 | With a subcommand you can enable temporarily."), |
c906108c | 16229 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16230 | |
16231 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16232 | ||
84951ab5 | 16233 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16234 | Enable some breakpoints.\n\ |
c906108c SS |
16235 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16236 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16237 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16238 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16239 | |
1a966eab AC |
16240 | add_cmd ("once", no_class, enable_once_command, _("\ |
16241 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16242 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16243 | &enablebreaklist); |
16244 | ||
1a966eab AC |
16245 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16246 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16247 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16248 | &enablebreaklist); |
16249 | ||
816338b5 SS |
16250 | add_cmd ("count", no_class, enable_count_command, _("\ |
16251 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16252 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16253 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16254 | &enablebreaklist); | |
16255 | ||
1a966eab AC |
16256 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16257 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16258 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16259 | &enablelist); |
16260 | ||
1a966eab AC |
16261 | add_cmd ("once", no_class, enable_once_command, _("\ |
16262 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16263 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16264 | &enablelist); |
16265 | ||
16266 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16267 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16268 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16269 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16270 | &enablelist); |
16271 | ||
1bedd215 AC |
16272 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16273 | Disable some breakpoints.\n\ | |
c906108c SS |
16274 | Arguments are breakpoint numbers with spaces in between.\n\ |
16275 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16276 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16277 | &disablelist, "disable ", 1, &cmdlist); |
16278 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16279 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16280 | |
1a966eab AC |
16281 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16282 | Disable some breakpoints.\n\ | |
c906108c SS |
16283 | Arguments are breakpoint numbers with spaces in between.\n\ |
16284 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16285 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16286 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16287 | &disablelist); |
16288 | ||
1bedd215 AC |
16289 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16290 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16291 | Arguments are breakpoint numbers with spaces in between.\n\ |
16292 | To delete all breakpoints, give no argument.\n\ | |
16293 | \n\ | |
16294 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16295 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16296 | &deletelist, "delete ", 1, &cmdlist); |
16297 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16298 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16299 | |
1a966eab AC |
16300 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16301 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16302 | Arguments are breakpoint numbers with spaces in between.\n\ |
16303 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16304 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16305 | &deletelist); |
16306 | ||
1bedd215 | 16307 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16308 | Clear breakpoint at specified location.\n\ |
16309 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16310 | \n\ |
16311 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16312 | is executing in.\n" |
16313 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16314 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16315 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16316 | |
1bedd215 | 16317 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16318 | Set breakpoint at specified location.\n" |
31e2b00f | 16319 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16320 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16321 | |
c906108c SS |
16322 | add_com_alias ("b", "break", class_run, 1); |
16323 | add_com_alias ("br", "break", class_run, 1); | |
16324 | add_com_alias ("bre", "break", class_run, 1); | |
16325 | add_com_alias ("brea", "break", class_run, 1); | |
16326 | ||
c906108c SS |
16327 | if (dbx_commands) |
16328 | { | |
1bedd215 AC |
16329 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16330 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16331 | &stoplist, "stop ", 1, &cmdlist); |
16332 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16333 | _("Break in function or address."), &stoplist); |
c5aa993b | 16334 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16335 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16336 | add_com ("status", class_info, breakpoints_info, _("\ |
16337 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16338 | The \"Type\" column indicates one of:\n\ |
16339 | \tbreakpoint - normal breakpoint\n\ | |
16340 | \twatchpoint - watchpoint\n\ | |
16341 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16342 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16343 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16344 | address and file/line number respectively.\n\ |
16345 | \n\ | |
16346 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16347 | are set to the address of the last breakpoint listed unless the command\n\ |
16348 | is prefixed with \"server \".\n\n\ | |
c906108c | 16349 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16350 | breakpoint set.")); |
c906108c SS |
16351 | } |
16352 | ||
1bedd215 | 16353 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16354 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16355 | The \"Type\" column indicates one of:\n\ |
16356 | \tbreakpoint - normal breakpoint\n\ | |
16357 | \twatchpoint - watchpoint\n\ | |
16358 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16359 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16360 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16361 | address and file/line number respectively.\n\ |
16362 | \n\ | |
16363 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16364 | are set to the address of the last breakpoint listed unless the command\n\ |
16365 | is prefixed with \"server \".\n\n\ | |
c906108c | 16366 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16367 | breakpoint set.")); |
c906108c | 16368 | |
6b04bdb7 MS |
16369 | add_info_alias ("b", "breakpoints", 1); |
16370 | ||
1a966eab AC |
16371 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16372 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16373 | The \"Type\" column indicates one of:\n\ |
16374 | \tbreakpoint - normal breakpoint\n\ | |
16375 | \twatchpoint - watchpoint\n\ | |
16376 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16377 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16378 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16379 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16380 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16381 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16382 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16383 | address and file/line number respectively.\n\ |
16384 | \n\ | |
16385 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16386 | are set to the address of the last breakpoint listed unless the command\n\ |
16387 | is prefixed with \"server \".\n\n\ | |
c906108c | 16388 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16389 | breakpoint set."), |
c906108c SS |
16390 | &maintenanceinfolist); |
16391 | ||
44feb3ce TT |
16392 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16393 | Set catchpoints to catch events."), | |
16394 | &catch_cmdlist, "catch ", | |
16395 | 0/*allow-unknown*/, &cmdlist); | |
16396 | ||
16397 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16398 | Set temporary catchpoints to catch events."), | |
16399 | &tcatch_cmdlist, "tcatch ", | |
16400 | 0/*allow-unknown*/, &cmdlist); | |
16401 | ||
44feb3ce TT |
16402 | add_catch_command ("fork", _("Catch calls to fork."), |
16403 | catch_fork_command_1, | |
a96d9b2e | 16404 | NULL, |
44feb3ce TT |
16405 | (void *) (uintptr_t) catch_fork_permanent, |
16406 | (void *) (uintptr_t) catch_fork_temporary); | |
16407 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16408 | catch_fork_command_1, | |
a96d9b2e | 16409 | NULL, |
44feb3ce TT |
16410 | (void *) (uintptr_t) catch_vfork_permanent, |
16411 | (void *) (uintptr_t) catch_vfork_temporary); | |
16412 | add_catch_command ("exec", _("Catch calls to exec."), | |
16413 | catch_exec_command_1, | |
a96d9b2e SDJ |
16414 | NULL, |
16415 | CATCH_PERMANENT, | |
16416 | CATCH_TEMPORARY); | |
edcc5120 TT |
16417 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16418 | Usage: catch load [REGEX]\n\ | |
16419 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16420 | catch_load_command_1, | |
16421 | NULL, | |
16422 | CATCH_PERMANENT, | |
16423 | CATCH_TEMPORARY); | |
16424 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16425 | Usage: catch unload [REGEX]\n\ | |
16426 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16427 | catch_unload_command_1, | |
16428 | NULL, | |
16429 | CATCH_PERMANENT, | |
16430 | CATCH_TEMPORARY); | |
c5aa993b | 16431 | |
1bedd215 AC |
16432 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16433 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16434 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16435 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16436 | an expression changes.\n\ |
16437 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16438 | the memory to which it refers.")); | |
65d12d83 | 16439 | set_cmd_completer (c, expression_completer); |
c906108c | 16440 | |
1bedd215 AC |
16441 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16442 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16443 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16444 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16445 | an expression is read.\n\ |
16446 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16447 | the memory to which it refers.")); | |
65d12d83 | 16448 | set_cmd_completer (c, expression_completer); |
c906108c | 16449 | |
1bedd215 AC |
16450 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16451 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16452 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16453 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16454 | an expression is either read or written.\n\ |
16455 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16456 | the memory to which it refers.")); | |
65d12d83 | 16457 | set_cmd_completer (c, expression_completer); |
c906108c | 16458 | |
d77f58be | 16459 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16460 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16461 | |
920d2a44 AC |
16462 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16463 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16464 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16465 | &can_use_hw_watchpoints, _("\ | |
16466 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16467 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16468 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16469 | such is available. (However, any hardware watchpoints that were\n\ | |
16470 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16471 | hardware.)"), |
16472 | NULL, | |
920d2a44 | 16473 | show_can_use_hw_watchpoints, |
85c07804 | 16474 | &setlist, &showlist); |
c906108c SS |
16475 | |
16476 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16477 | |
1042e4c0 SS |
16478 | /* Tracepoint manipulation commands. */ |
16479 | ||
16480 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16481 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16482 | \n" |
16483 | BREAK_ARGS_HELP ("trace") "\n\ | |
16484 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16485 | set_cmd_completer (c, location_completer); | |
16486 | ||
16487 | add_com_alias ("tp", "trace", class_alias, 0); | |
16488 | add_com_alias ("tr", "trace", class_alias, 1); | |
16489 | add_com_alias ("tra", "trace", class_alias, 1); | |
16490 | add_com_alias ("trac", "trace", class_alias, 1); | |
16491 | ||
7a697b8d | 16492 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16493 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16494 | \n" |
16495 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16496 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16497 | set_cmd_completer (c, location_completer); | |
16498 | ||
0fb4aa4b | 16499 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16500 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16501 | \n\ |
16502 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16503 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16504 | or -m MARKER_ID.\n\n\ | |
16505 | If a marker id is specified, probe the marker with that name. With\n\ | |
16506 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16507 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16508 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16509 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16510 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16511 | \n\ | |
16512 | CONDITION is a boolean expression.\n\ | |
629500fa | 16513 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16514 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16515 | conditions are different.\n\ | |
0fb4aa4b PA |
16516 | \n\ |
16517 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16518 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16519 | set_cmd_completer (c, location_completer); | |
16520 | ||
1042e4c0 | 16521 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16522 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16523 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16524 | last tracepoint set.")); | |
16525 | ||
16526 | add_info_alias ("tp", "tracepoints", 1); | |
16527 | ||
16528 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16529 | Delete specified tracepoints.\n\ | |
16530 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16531 | No argument means delete all tracepoints."), | |
16532 | &deletelist); | |
7e20dfcd | 16533 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16534 | |
16535 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16536 | Disable specified tracepoints.\n\ | |
16537 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16538 | No argument means disable all tracepoints."), | |
16539 | &disablelist); | |
16540 | deprecate_cmd (c, "disable"); | |
16541 | ||
16542 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16543 | Enable specified tracepoints.\n\ | |
16544 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16545 | No argument means enable all tracepoints."), | |
16546 | &enablelist); | |
16547 | deprecate_cmd (c, "enable"); | |
16548 | ||
16549 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16550 | Set the passcount for a tracepoint.\n\ | |
16551 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16552 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16553 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16554 | ||
6149aea9 PA |
16555 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16556 | _("Save breakpoint definitions as a script."), | |
16557 | &save_cmdlist, "save ", | |
16558 | 0/*allow-unknown*/, &cmdlist); | |
16559 | ||
16560 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16561 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16562 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16563 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16564 | session to restore them."), | |
16565 | &save_cmdlist); | |
16566 | set_cmd_completer (c, filename_completer); | |
16567 | ||
16568 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16569 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16570 | Use the 'source' command in another debug session to restore them."), |
16571 | &save_cmdlist); | |
1042e4c0 SS |
16572 | set_cmd_completer (c, filename_completer); |
16573 | ||
6149aea9 PA |
16574 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16575 | deprecate_cmd (c, "save tracepoints"); | |
16576 | ||
1bedd215 | 16577 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16578 | Breakpoint specific settings\n\ |
16579 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16580 | pending breakpoint behavior"), |
fa8d40ab JJ |
16581 | &breakpoint_set_cmdlist, "set breakpoint ", |
16582 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16583 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16584 | Breakpoint specific settings\n\ |
16585 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16586 | pending breakpoint behavior"), |
fa8d40ab JJ |
16587 | &breakpoint_show_cmdlist, "show breakpoint ", |
16588 | 0/*allow-unknown*/, &showlist); | |
16589 | ||
7915a72c AC |
16590 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16591 | &pending_break_support, _("\ | |
16592 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16593 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16594 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16595 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16596 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16597 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16598 | NULL, |
920d2a44 | 16599 | show_pending_break_support, |
6e1d7d6c AC |
16600 | &breakpoint_set_cmdlist, |
16601 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16602 | |
16603 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16604 | |
16605 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16606 | &automatic_hardware_breakpoints, _("\ | |
16607 | Set automatic usage of hardware breakpoints."), _("\ | |
16608 | Show automatic usage of hardware breakpoints."), _("\ | |
16609 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16610 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16611 | a warning will be emitted for such breakpoints."), | |
16612 | NULL, | |
16613 | show_automatic_hardware_breakpoints, | |
16614 | &breakpoint_set_cmdlist, | |
16615 | &breakpoint_show_cmdlist); | |
74960c60 | 16616 | |
a25a5a45 PA |
16617 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16618 | &always_inserted_mode, _("\ | |
74960c60 VP |
16619 | Set mode for inserting breakpoints."), _("\ |
16620 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16621 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16622 | they're created, kept inserted even when execution stops, and removed\n\ | |
16623 | only when the user deletes them. When this mode is off (the default),\n\ | |
16624 | breakpoints are inserted only when execution continues, and removed\n\ | |
16625 | when execution stops."), | |
72d0e2c5 YQ |
16626 | NULL, |
16627 | &show_always_inserted_mode, | |
16628 | &breakpoint_set_cmdlist, | |
16629 | &breakpoint_show_cmdlist); | |
f1310107 | 16630 | |
b775012e LM |
16631 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16632 | condition_evaluation_enums, | |
16633 | &condition_evaluation_mode_1, _("\ | |
16634 | Set mode of breakpoint condition evaluation."), _("\ | |
16635 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16636 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16637 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16638 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16639 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16640 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16641 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16642 | be set to \"gdb\""), | |
16643 | &set_condition_evaluation_mode, | |
16644 | &show_condition_evaluation_mode, | |
16645 | &breakpoint_set_cmdlist, | |
16646 | &breakpoint_show_cmdlist); | |
16647 | ||
f1310107 TJB |
16648 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16649 | Set a breakpoint for an address range.\n\ | |
16650 | break-range START-LOCATION, END-LOCATION\n\ | |
16651 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16652 | LINENUM, for that line in the current file,\n\ | |
16653 | FILE:LINENUM, for that line in that file,\n\ | |
16654 | +OFFSET, for that number of lines after the current line\n\ | |
16655 | or the start of the range\n\ | |
16656 | FUNCTION, for the first line in that function,\n\ | |
16657 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16658 | *ADDRESS, for the instruction at that address.\n\ | |
16659 | \n\ | |
16660 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16661 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16662 | range (including START-LOCATION and END-LOCATION).")); | |
16663 | ||
e7e0cddf | 16664 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16665 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16666 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16667 | location may be a linespec, explicit, or address location.\n" |
16668 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16669 | set_cmd_completer (c, location_completer); |
16670 | ||
16671 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16672 | dprintf_style_enums, &dprintf_style, _("\ | |
16673 | Set the style of usage for dynamic printf."), _("\ | |
16674 | Show the style of usage for dynamic printf."), _("\ | |
16675 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16676 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16677 | console, as with the \"printf\" command.\n\ | |
16678 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16679 | program; by default printf(), but you can choose a different function or\n\ | |
16680 | output stream by setting dprintf-function and dprintf-channel."), | |
16681 | update_dprintf_commands, NULL, | |
16682 | &setlist, &showlist); | |
16683 | ||
16684 | dprintf_function = xstrdup ("printf"); | |
16685 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16686 | &dprintf_function, _("\ | |
16687 | Set the function to use for dynamic printf"), _("\ | |
16688 | Show the function to use for dynamic printf"), NULL, | |
16689 | update_dprintf_commands, NULL, | |
16690 | &setlist, &showlist); | |
16691 | ||
16692 | dprintf_channel = xstrdup (""); | |
16693 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16694 | &dprintf_channel, _("\ | |
16695 | Set the channel to use for dynamic printf"), _("\ | |
16696 | Show the channel to use for dynamic printf"), NULL, | |
16697 | update_dprintf_commands, NULL, | |
16698 | &setlist, &showlist); | |
16699 | ||
d3ce09f5 SS |
16700 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16701 | &disconnected_dprintf, _("\ | |
16702 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16703 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16704 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16705 | even if GDB disconnects or detaches from the target."), | |
16706 | NULL, | |
16707 | NULL, | |
16708 | &setlist, &showlist); | |
16709 | ||
16710 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16711 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16712 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16713 | ||
765dc015 | 16714 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16715 | |
16716 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16717 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16718 | } |