Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 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" |
325fac50 | 83 | #include <algorithm> |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
896b6bda PA |
105 | static void map_breakpoint_numbers (const char *, |
106 | void (*) (struct breakpoint *, | |
107 | void *), | |
95a42b64 | 108 | void *); |
c906108c | 109 | |
a14ed312 | 110 | static void ignore_command (char *, int); |
c906108c | 111 | |
4efb68b1 | 112 | static int breakpoint_re_set_one (void *); |
c906108c | 113 | |
348d480f PA |
114 | static void breakpoint_re_set_default (struct breakpoint *); |
115 | ||
f00aae0f KS |
116 | static void |
117 | create_sals_from_location_default (const struct event_location *location, | |
118 | struct linespec_result *canonical, | |
119 | enum bptype type_wanted); | |
983af33b SDJ |
120 | |
121 | static void create_breakpoints_sal_default (struct gdbarch *, | |
122 | struct linespec_result *, | |
e7e0cddf | 123 | char *, char *, enum bptype, |
983af33b SDJ |
124 | enum bpdisp, int, int, |
125 | int, | |
126 | const struct breakpoint_ops *, | |
44f238bb | 127 | int, int, int, unsigned); |
983af33b | 128 | |
f00aae0f KS |
129 | static void decode_location_default (struct breakpoint *b, |
130 | const struct event_location *location, | |
c2f4122d | 131 | struct program_space *search_pspace, |
f00aae0f | 132 | struct symtabs_and_lines *sals); |
983af33b | 133 | |
a14ed312 | 134 | static void clear_command (char *, int); |
c906108c | 135 | |
a14ed312 | 136 | static void catch_command (char *, int); |
c906108c | 137 | |
a9634178 | 138 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 139 | |
98deb0da | 140 | static void break_command_1 (char *, int, int); |
c906108c | 141 | |
a14ed312 | 142 | static void mention (struct breakpoint *); |
c906108c | 143 | |
348d480f PA |
144 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
145 | enum bptype, | |
c0a91b2b | 146 | const struct breakpoint_ops *); |
3742cc8b YQ |
147 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
148 | const struct symtab_and_line *); | |
149 | ||
4a64f543 MS |
150 | /* This function is used in gdbtk sources and thus can not be made |
151 | static. */ | |
63c252f8 | 152 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 153 | struct symtab_and_line, |
c0a91b2b TT |
154 | enum bptype, |
155 | const struct breakpoint_ops *); | |
c906108c | 156 | |
06edf0c0 PA |
157 | static struct breakpoint * |
158 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
159 | enum bptype type, | |
a1aa2221 LM |
160 | const struct breakpoint_ops *ops, |
161 | int loc_enabled); | |
06edf0c0 | 162 | |
76897487 KB |
163 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
164 | ||
a6d9a66e UW |
165 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
166 | CORE_ADDR bpaddr, | |
88f7da05 | 167 | enum bptype bptype); |
76897487 | 168 | |
6c95b8df PA |
169 | static void describe_other_breakpoints (struct gdbarch *, |
170 | struct program_space *, CORE_ADDR, | |
5af949e3 | 171 | struct obj_section *, int); |
c906108c | 172 | |
85d721b8 PA |
173 | static int watchpoint_locations_match (struct bp_location *loc1, |
174 | struct bp_location *loc2); | |
175 | ||
f1310107 TJB |
176 | static int breakpoint_location_address_match (struct bp_location *bl, |
177 | struct address_space *aspace, | |
178 | CORE_ADDR addr); | |
179 | ||
d35ae833 PA |
180 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
181 | struct address_space *, | |
182 | CORE_ADDR, int); | |
183 | ||
a14ed312 | 184 | static void breakpoints_info (char *, int); |
c906108c | 185 | |
d77f58be SS |
186 | static void watchpoints_info (char *, int); |
187 | ||
e5a67952 MS |
188 | static int breakpoint_1 (char *, int, |
189 | int (*) (const struct breakpoint *)); | |
c906108c | 190 | |
4efb68b1 | 191 | static int breakpoint_cond_eval (void *); |
c906108c | 192 | |
4efb68b1 | 193 | static void cleanup_executing_breakpoints (void *); |
c906108c | 194 | |
a14ed312 | 195 | static void commands_command (char *, int); |
c906108c | 196 | |
a14ed312 | 197 | static void condition_command (char *, int); |
c906108c | 198 | |
834c0d03 | 199 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 200 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 201 | |
e514a9d6 | 202 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 203 | |
4efb68b1 | 204 | static int watchpoint_check (void *); |
c906108c | 205 | |
a14ed312 | 206 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 207 | |
a14ed312 | 208 | static int hw_breakpoint_used_count (void); |
c906108c | 209 | |
a1398e0c PA |
210 | static int hw_watchpoint_use_count (struct breakpoint *); |
211 | ||
212 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
213 | enum bptype type, | |
214 | int *other_type_used); | |
c906108c | 215 | |
a14ed312 | 216 | static void hbreak_command (char *, int); |
c906108c | 217 | |
a14ed312 | 218 | static void thbreak_command (char *, int); |
c906108c | 219 | |
816338b5 SS |
220 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
221 | int count); | |
c906108c | 222 | |
a14ed312 | 223 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 228 | |
a14ed312 | 229 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 230 | |
fe3f5fa8 | 231 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
232 | static void incref_bp_location (struct bp_location *loc); |
233 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 234 | |
39d61571 | 235 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 236 | |
44702360 PA |
237 | /* update_global_location_list's modes of operation wrt to whether to |
238 | insert locations now. */ | |
239 | enum ugll_insert_mode | |
240 | { | |
241 | /* Don't insert any breakpoint locations into the inferior, only | |
242 | remove already-inserted locations that no longer should be | |
243 | inserted. Functions that delete a breakpoint or breakpoints | |
244 | should specify this mode, so that deleting a breakpoint doesn't | |
245 | have the side effect of inserting the locations of other | |
246 | breakpoints that are marked not-inserted, but should_be_inserted | |
247 | returns true on them. | |
248 | ||
249 | This behavior is useful is situations close to tear-down -- e.g., | |
250 | after an exec, while the target still has execution, but | |
251 | breakpoint shadows of the previous executable image should *NOT* | |
252 | be restored to the new image; or before detaching, where the | |
253 | target still has execution and wants to delete breakpoints from | |
254 | GDB's lists, and all breakpoints had already been removed from | |
255 | the inferior. */ | |
256 | UGLL_DONT_INSERT, | |
257 | ||
a25a5a45 PA |
258 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
259 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
260 | UGLL_MAY_INSERT, |
261 | ||
a25a5a45 PA |
262 | /* Insert locations now, irrespective of |
263 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
264 | stopped right now, and the user did "continue". We need to | |
265 | insert breakpoints _before_ resuming the target, but | |
266 | UGLL_MAY_INSERT wouldn't insert them, because | |
267 | breakpoints_should_be_inserted_now returns false at that point, | |
268 | as no thread is running yet. */ | |
04086b45 | 269 | UGLL_INSERT |
44702360 PA |
270 | }; |
271 | ||
272 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 273 | |
44702360 | 274 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 275 | |
d77f58be | 276 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
277 | |
278 | static void insert_breakpoint_locations (void); | |
a5606eee | 279 | |
1042e4c0 SS |
280 | static void tracepoints_info (char *, int); |
281 | ||
282 | static void delete_trace_command (char *, int); | |
283 | ||
284 | static void enable_trace_command (char *, int); | |
285 | ||
286 | static void disable_trace_command (char *, int); | |
287 | ||
288 | static void trace_pass_command (char *, int); | |
289 | ||
558a9d82 YQ |
290 | static void set_tracepoint_count (int num); |
291 | ||
9c06b0b4 TJB |
292 | static int is_masked_watchpoint (const struct breakpoint *b); |
293 | ||
b775012e LM |
294 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
295 | ||
983af33b SDJ |
296 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
297 | otherwise. */ | |
298 | ||
299 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 300 | |
2060206e PA |
301 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
302 | that are implemented on top of software or hardware breakpoints | |
303 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
304 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
305 | ||
306 | /* Internal breakpoints class type. */ | |
06edf0c0 | 307 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
308 | |
309 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
310 | static struct breakpoint_ops momentary_breakpoint_ops; |
311 | ||
e2e4d78b JK |
312 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
313 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
314 | ||
2060206e PA |
315 | /* The breakpoint_ops structure to be used in regular user created |
316 | breakpoints. */ | |
317 | struct breakpoint_ops bkpt_breakpoint_ops; | |
318 | ||
55aa24fb SDJ |
319 | /* Breakpoints set on probes. */ |
320 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
321 | ||
e7e0cddf | 322 | /* Dynamic printf class type. */ |
c5867ab6 | 323 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 324 | |
d3ce09f5 SS |
325 | /* The style in which to perform a dynamic printf. This is a user |
326 | option because different output options have different tradeoffs; | |
327 | if GDB does the printing, there is better error handling if there | |
328 | is a problem with any of the arguments, but using an inferior | |
329 | function lets you have special-purpose printers and sending of | |
330 | output to the same place as compiled-in print functions. */ | |
331 | ||
332 | static const char dprintf_style_gdb[] = "gdb"; | |
333 | static const char dprintf_style_call[] = "call"; | |
334 | static const char dprintf_style_agent[] = "agent"; | |
335 | static const char *const dprintf_style_enums[] = { | |
336 | dprintf_style_gdb, | |
337 | dprintf_style_call, | |
338 | dprintf_style_agent, | |
339 | NULL | |
340 | }; | |
341 | static const char *dprintf_style = dprintf_style_gdb; | |
342 | ||
343 | /* The function to use for dynamic printf if the preferred style is to | |
344 | call into the inferior. The value is simply a string that is | |
345 | copied into the command, so it can be anything that GDB can | |
346 | evaluate to a callable address, not necessarily a function name. */ | |
347 | ||
bde6261a | 348 | static char *dprintf_function; |
d3ce09f5 SS |
349 | |
350 | /* The channel to use for dynamic printf if the preferred style is to | |
351 | call into the inferior; if a nonempty string, it will be passed to | |
352 | the call as the first argument, with the format string as the | |
353 | second. As with the dprintf function, this can be anything that | |
354 | GDB knows how to evaluate, so in addition to common choices like | |
355 | "stderr", this could be an app-specific expression like | |
356 | "mystreams[curlogger]". */ | |
357 | ||
bde6261a | 358 | static char *dprintf_channel; |
d3ce09f5 SS |
359 | |
360 | /* True if dprintf commands should continue to operate even if GDB | |
361 | has disconnected. */ | |
362 | static int disconnected_dprintf = 1; | |
363 | ||
5cea2a26 PA |
364 | /* A reference-counted struct command_line. This lets multiple |
365 | breakpoints share a single command list. */ | |
366 | struct counted_command_line | |
367 | { | |
368 | /* The reference count. */ | |
369 | int refc; | |
370 | ||
371 | /* The command list. */ | |
372 | struct command_line *commands; | |
373 | }; | |
374 | ||
375 | struct command_line * | |
376 | breakpoint_commands (struct breakpoint *b) | |
377 | { | |
378 | return b->commands ? b->commands->commands : NULL; | |
379 | } | |
3daf8fe5 | 380 | |
f3b1572e PA |
381 | /* Flag indicating that a command has proceeded the inferior past the |
382 | current breakpoint. */ | |
383 | ||
384 | static int breakpoint_proceeded; | |
385 | ||
956a9fb9 | 386 | const char * |
2cec12e5 AR |
387 | bpdisp_text (enum bpdisp disp) |
388 | { | |
4a64f543 MS |
389 | /* NOTE: the following values are a part of MI protocol and |
390 | represent values of 'disp' field returned when inferior stops at | |
391 | a breakpoint. */ | |
bc043ef3 | 392 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 393 | |
2cec12e5 AR |
394 | return bpdisps[(int) disp]; |
395 | } | |
c906108c | 396 | |
4a64f543 | 397 | /* Prototypes for exported functions. */ |
c906108c | 398 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 399 | if such is available. */ |
c906108c SS |
400 | static int can_use_hw_watchpoints; |
401 | ||
920d2a44 AC |
402 | static void |
403 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
404 | struct cmd_list_element *c, | |
405 | const char *value) | |
406 | { | |
3e43a32a MS |
407 | fprintf_filtered (file, |
408 | _("Debugger's willingness to use " | |
409 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
410 | value); |
411 | } | |
412 | ||
fa8d40ab JJ |
413 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
414 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 415 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
416 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
417 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
418 | static void |
419 | show_pending_break_support (struct ui_file *file, int from_tty, | |
420 | struct cmd_list_element *c, | |
421 | const char *value) | |
422 | { | |
3e43a32a MS |
423 | fprintf_filtered (file, |
424 | _("Debugger's behavior regarding " | |
425 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
426 | value); |
427 | } | |
fa8d40ab | 428 | |
765dc015 | 429 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 430 | set with "break" but falling in read-only memory. |
765dc015 VP |
431 | If 0, gdb will warn about such breakpoints, but won't automatically |
432 | use hardware breakpoints. */ | |
433 | static int automatic_hardware_breakpoints; | |
434 | static void | |
435 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
436 | struct cmd_list_element *c, | |
437 | const char *value) | |
438 | { | |
3e43a32a MS |
439 | fprintf_filtered (file, |
440 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
441 | value); |
442 | } | |
443 | ||
a25a5a45 PA |
444 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
445 | stopped, and immediately inserts any new breakpoints as soon as | |
446 | they're created. If off (default), GDB keeps breakpoints off of | |
447 | the target as long as possible. That is, it delays inserting | |
448 | breakpoints until the next resume, and removes them again when the | |
449 | target fully stops. This is a bit safer in case GDB crashes while | |
450 | processing user input. */ | |
451 | static int always_inserted_mode = 0; | |
72d0e2c5 | 452 | |
33e5cbd6 | 453 | static void |
74960c60 | 454 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 455 | struct cmd_list_element *c, const char *value) |
74960c60 | 456 | { |
a25a5a45 PA |
457 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
458 | value); | |
74960c60 VP |
459 | } |
460 | ||
b57bacec PA |
461 | /* See breakpoint.h. */ |
462 | ||
33e5cbd6 | 463 | int |
a25a5a45 | 464 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 465 | { |
a25a5a45 PA |
466 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
467 | { | |
468 | /* If breakpoints are global, they should be inserted even if no | |
469 | thread under gdb's control is running, or even if there are | |
470 | no threads under GDB's control yet. */ | |
471 | return 1; | |
472 | } | |
473 | else if (target_has_execution) | |
474 | { | |
372316f1 PA |
475 | struct thread_info *tp; |
476 | ||
a25a5a45 PA |
477 | if (always_inserted_mode) |
478 | { | |
479 | /* The user wants breakpoints inserted even if all threads | |
480 | are stopped. */ | |
481 | return 1; | |
482 | } | |
483 | ||
b57bacec PA |
484 | if (threads_are_executing ()) |
485 | return 1; | |
372316f1 PA |
486 | |
487 | /* Don't remove breakpoints yet if, even though all threads are | |
488 | stopped, we still have events to process. */ | |
489 | ALL_NON_EXITED_THREADS (tp) | |
490 | if (tp->resumed | |
491 | && tp->suspend.waitstatus_pending_p) | |
492 | return 1; | |
a25a5a45 PA |
493 | } |
494 | return 0; | |
33e5cbd6 | 495 | } |
765dc015 | 496 | |
b775012e LM |
497 | static const char condition_evaluation_both[] = "host or target"; |
498 | ||
499 | /* Modes for breakpoint condition evaluation. */ | |
500 | static const char condition_evaluation_auto[] = "auto"; | |
501 | static const char condition_evaluation_host[] = "host"; | |
502 | static const char condition_evaluation_target[] = "target"; | |
503 | static const char *const condition_evaluation_enums[] = { | |
504 | condition_evaluation_auto, | |
505 | condition_evaluation_host, | |
506 | condition_evaluation_target, | |
507 | NULL | |
508 | }; | |
509 | ||
510 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
511 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
512 | ||
513 | /* Global that we use to display information to the user (gets its value from | |
514 | condition_evaluation_mode_1. */ | |
515 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
516 | ||
517 | /* Translate a condition evaluation mode MODE into either "host" | |
518 | or "target". This is used mostly to translate from "auto" to the | |
519 | real setting that is being used. It returns the translated | |
520 | evaluation mode. */ | |
521 | ||
522 | static const char * | |
523 | translate_condition_evaluation_mode (const char *mode) | |
524 | { | |
525 | if (mode == condition_evaluation_auto) | |
526 | { | |
527 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
528 | return condition_evaluation_target; | |
529 | else | |
530 | return condition_evaluation_host; | |
531 | } | |
532 | else | |
533 | return mode; | |
534 | } | |
535 | ||
536 | /* Discovers what condition_evaluation_auto translates to. */ | |
537 | ||
538 | static const char * | |
539 | breakpoint_condition_evaluation_mode (void) | |
540 | { | |
541 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
542 | } | |
543 | ||
544 | /* Return true if GDB should evaluate breakpoint conditions or false | |
545 | otherwise. */ | |
546 | ||
547 | static int | |
548 | gdb_evaluates_breakpoint_condition_p (void) | |
549 | { | |
550 | const char *mode = breakpoint_condition_evaluation_mode (); | |
551 | ||
552 | return (mode == condition_evaluation_host); | |
553 | } | |
554 | ||
a14ed312 | 555 | void _initialize_breakpoint (void); |
c906108c | 556 | |
c906108c SS |
557 | /* Are we executing breakpoint commands? */ |
558 | static int executing_breakpoint_commands; | |
559 | ||
c02f5703 MS |
560 | /* Are overlay event breakpoints enabled? */ |
561 | static int overlay_events_enabled; | |
562 | ||
e09342b5 TJB |
563 | /* See description in breakpoint.h. */ |
564 | int target_exact_watchpoints = 0; | |
565 | ||
c906108c | 566 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 567 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 568 | current breakpoint. */ |
c906108c | 569 | |
5c44784c | 570 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 571 | |
5c44784c JM |
572 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
573 | for (B = breakpoint_chain; \ | |
574 | B ? (TMP=B->next, 1): 0; \ | |
575 | B = TMP) | |
c906108c | 576 | |
4a64f543 MS |
577 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
578 | not provided so update_global_location_list must not be called | |
579 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 580 | |
876fa593 JK |
581 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
582 | for (BP_TMP = bp_location; \ | |
583 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
584 | BP_TMP++) | |
7cc221ef | 585 | |
b775012e LM |
586 | /* Iterates through locations with address ADDRESS for the currently selected |
587 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
588 | to where the loop should start from. | |
589 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
590 | appropriate location to start with. */ | |
591 | ||
592 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
593 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
594 | BP_LOCP_TMP = BP_LOCP_START; \ | |
595 | BP_LOCP_START \ | |
596 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
597 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
598 | BP_LOCP_TMP++) | |
599 | ||
1042e4c0 SS |
600 | /* Iterator for tracepoints only. */ |
601 | ||
602 | #define ALL_TRACEPOINTS(B) \ | |
603 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 604 | if (is_tracepoint (B)) |
1042e4c0 | 605 | |
7cc221ef | 606 | /* Chains of all breakpoints defined. */ |
c906108c SS |
607 | |
608 | struct breakpoint *breakpoint_chain; | |
609 | ||
876fa593 JK |
610 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
611 | ||
612 | static struct bp_location **bp_location; | |
613 | ||
614 | /* Number of elements of BP_LOCATION. */ | |
615 | ||
616 | static unsigned bp_location_count; | |
617 | ||
4a64f543 MS |
618 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
619 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
620 | result from bp_location_has_shadow. You can use it for roughly | |
621 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
622 | an address you need to read. */ | |
876fa593 JK |
623 | |
624 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
625 | ||
4a64f543 MS |
626 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
627 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
628 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
629 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
630 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
631 | |
632 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 633 | |
4a64f543 MS |
634 | /* The locations that no longer correspond to any breakpoint, unlinked |
635 | from bp_location array, but for which a hit may still be reported | |
636 | by a target. */ | |
20874c92 VP |
637 | VEC(bp_location_p) *moribund_locations = NULL; |
638 | ||
c906108c SS |
639 | /* Number of last breakpoint made. */ |
640 | ||
95a42b64 TT |
641 | static int breakpoint_count; |
642 | ||
86b17b60 PA |
643 | /* The value of `breakpoint_count' before the last command that |
644 | created breakpoints. If the last (break-like) command created more | |
645 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
646 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
647 | static int prev_breakpoint_count; | |
c906108c | 648 | |
1042e4c0 SS |
649 | /* Number of last tracepoint made. */ |
650 | ||
95a42b64 | 651 | static int tracepoint_count; |
1042e4c0 | 652 | |
6149aea9 PA |
653 | static struct cmd_list_element *breakpoint_set_cmdlist; |
654 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 655 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 656 | |
badd37ce SDJ |
657 | /* See declaration at breakpoint.h. */ |
658 | ||
659 | struct breakpoint * | |
660 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
661 | void *user_data) | |
662 | { | |
663 | struct breakpoint *b = NULL; | |
664 | ||
665 | ALL_BREAKPOINTS (b) | |
666 | { | |
667 | if (func (b, user_data) != 0) | |
668 | break; | |
669 | } | |
670 | ||
671 | return b; | |
672 | } | |
673 | ||
468d015d JJ |
674 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
675 | static int | |
676 | breakpoint_enabled (struct breakpoint *b) | |
677 | { | |
0d381245 | 678 | return (b->enable_state == bp_enabled); |
468d015d JJ |
679 | } |
680 | ||
c906108c SS |
681 | /* Set breakpoint count to NUM. */ |
682 | ||
95a42b64 | 683 | static void |
fba45db2 | 684 | set_breakpoint_count (int num) |
c906108c | 685 | { |
86b17b60 | 686 | prev_breakpoint_count = breakpoint_count; |
c906108c | 687 | breakpoint_count = num; |
4fa62494 | 688 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
689 | } |
690 | ||
86b17b60 PA |
691 | /* Used by `start_rbreak_breakpoints' below, to record the current |
692 | breakpoint count before "rbreak" creates any breakpoint. */ | |
693 | static int rbreak_start_breakpoint_count; | |
694 | ||
95a42b64 TT |
695 | /* Called at the start an "rbreak" command to record the first |
696 | breakpoint made. */ | |
86b17b60 | 697 | |
95a42b64 TT |
698 | void |
699 | start_rbreak_breakpoints (void) | |
700 | { | |
86b17b60 | 701 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
702 | } |
703 | ||
704 | /* Called at the end of an "rbreak" command to record the last | |
705 | breakpoint made. */ | |
86b17b60 | 706 | |
95a42b64 TT |
707 | void |
708 | end_rbreak_breakpoints (void) | |
709 | { | |
86b17b60 | 710 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
711 | } |
712 | ||
4a64f543 | 713 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
714 | |
715 | void | |
fba45db2 | 716 | clear_breakpoint_hit_counts (void) |
c906108c SS |
717 | { |
718 | struct breakpoint *b; | |
719 | ||
720 | ALL_BREAKPOINTS (b) | |
721 | b->hit_count = 0; | |
722 | } | |
723 | ||
9add0f1b TT |
724 | /* Allocate a new counted_command_line with reference count of 1. |
725 | The new structure owns COMMANDS. */ | |
726 | ||
727 | static struct counted_command_line * | |
728 | alloc_counted_command_line (struct command_line *commands) | |
729 | { | |
8d749320 | 730 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 731 | |
9add0f1b TT |
732 | result->refc = 1; |
733 | result->commands = commands; | |
8d749320 | 734 | |
9add0f1b TT |
735 | return result; |
736 | } | |
737 | ||
738 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
739 | ||
740 | static void | |
741 | incref_counted_command_line (struct counted_command_line *cmd) | |
742 | { | |
743 | if (cmd) | |
744 | ++cmd->refc; | |
745 | } | |
746 | ||
747 | /* Decrement reference count. If the reference count reaches 0, | |
748 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
749 | nothing if *CMDP is NULL. */ | |
750 | ||
751 | static void | |
752 | decref_counted_command_line (struct counted_command_line **cmdp) | |
753 | { | |
754 | if (*cmdp) | |
755 | { | |
756 | if (--(*cmdp)->refc == 0) | |
757 | { | |
758 | free_command_lines (&(*cmdp)->commands); | |
759 | xfree (*cmdp); | |
760 | } | |
761 | *cmdp = NULL; | |
762 | } | |
763 | } | |
764 | ||
765 | /* A cleanup function that calls decref_counted_command_line. */ | |
766 | ||
767 | static void | |
768 | do_cleanup_counted_command_line (void *arg) | |
769 | { | |
9a3c8263 | 770 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
771 | } |
772 | ||
773 | /* Create a cleanup that calls decref_counted_command_line on the | |
774 | argument. */ | |
775 | ||
776 | static struct cleanup * | |
777 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
778 | { | |
779 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
780 | } | |
781 | ||
c906108c | 782 | \f |
48cb2d85 VP |
783 | /* Return the breakpoint with the specified number, or NULL |
784 | if the number does not refer to an existing breakpoint. */ | |
785 | ||
786 | struct breakpoint * | |
787 | get_breakpoint (int num) | |
788 | { | |
789 | struct breakpoint *b; | |
790 | ||
791 | ALL_BREAKPOINTS (b) | |
792 | if (b->number == num) | |
793 | return b; | |
794 | ||
795 | return NULL; | |
796 | } | |
5c44784c | 797 | |
c906108c | 798 | \f |
adc36818 | 799 | |
b775012e LM |
800 | /* Mark locations as "conditions have changed" in case the target supports |
801 | evaluating conditions on its side. */ | |
802 | ||
803 | static void | |
804 | mark_breakpoint_modified (struct breakpoint *b) | |
805 | { | |
806 | struct bp_location *loc; | |
807 | ||
808 | /* This is only meaningful if the target is | |
809 | evaluating conditions and if the user has | |
810 | opted for condition evaluation on the target's | |
811 | side. */ | |
812 | if (gdb_evaluates_breakpoint_condition_p () | |
813 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
814 | return; | |
815 | ||
816 | if (!is_breakpoint (b)) | |
817 | return; | |
818 | ||
819 | for (loc = b->loc; loc; loc = loc->next) | |
820 | loc->condition_changed = condition_modified; | |
821 | } | |
822 | ||
823 | /* Mark location as "conditions have changed" in case the target supports | |
824 | evaluating conditions on its side. */ | |
825 | ||
826 | static void | |
827 | mark_breakpoint_location_modified (struct bp_location *loc) | |
828 | { | |
829 | /* This is only meaningful if the target is | |
830 | evaluating conditions and if the user has | |
831 | opted for condition evaluation on the target's | |
832 | side. */ | |
833 | if (gdb_evaluates_breakpoint_condition_p () | |
834 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
835 | ||
836 | return; | |
837 | ||
838 | if (!is_breakpoint (loc->owner)) | |
839 | return; | |
840 | ||
841 | loc->condition_changed = condition_modified; | |
842 | } | |
843 | ||
844 | /* Sets the condition-evaluation mode using the static global | |
845 | condition_evaluation_mode. */ | |
846 | ||
847 | static void | |
848 | set_condition_evaluation_mode (char *args, int from_tty, | |
849 | struct cmd_list_element *c) | |
850 | { | |
b775012e LM |
851 | const char *old_mode, *new_mode; |
852 | ||
853 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
854 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
855 | { | |
856 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
857 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
858 | "Using host evaluation mode instead.")); | |
859 | return; | |
860 | } | |
861 | ||
862 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
863 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
864 | ||
abf1152a JK |
865 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
866 | settings was "auto". */ | |
867 | condition_evaluation_mode = condition_evaluation_mode_1; | |
868 | ||
b775012e LM |
869 | /* Only update the mode if the user picked a different one. */ |
870 | if (new_mode != old_mode) | |
871 | { | |
872 | struct bp_location *loc, **loc_tmp; | |
873 | /* If the user switched to a different evaluation mode, we | |
874 | need to synch the changes with the target as follows: | |
875 | ||
876 | "host" -> "target": Send all (valid) conditions to the target. | |
877 | "target" -> "host": Remove all the conditions from the target. | |
878 | */ | |
879 | ||
b775012e LM |
880 | if (new_mode == condition_evaluation_target) |
881 | { | |
882 | /* Mark everything modified and synch conditions with the | |
883 | target. */ | |
884 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
885 | mark_breakpoint_location_modified (loc); | |
886 | } | |
887 | else | |
888 | { | |
889 | /* Manually mark non-duplicate locations to synch conditions | |
890 | with the target. We do this to remove all the conditions the | |
891 | target knows about. */ | |
892 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
893 | if (is_breakpoint (loc->owner) && loc->inserted) | |
894 | loc->needs_update = 1; | |
895 | } | |
896 | ||
897 | /* Do the update. */ | |
44702360 | 898 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
899 | } |
900 | ||
901 | return; | |
902 | } | |
903 | ||
904 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
905 | what "auto" is translating to. */ | |
906 | ||
907 | static void | |
908 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
909 | struct cmd_list_element *c, const char *value) | |
910 | { | |
911 | if (condition_evaluation_mode == condition_evaluation_auto) | |
912 | fprintf_filtered (file, | |
913 | _("Breakpoint condition evaluation " | |
914 | "mode is %s (currently %s).\n"), | |
915 | value, | |
916 | breakpoint_condition_evaluation_mode ()); | |
917 | else | |
918 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
919 | value); | |
920 | } | |
921 | ||
922 | /* A comparison function for bp_location AP and BP that is used by | |
923 | bsearch. This comparison function only cares about addresses, unlike | |
924 | the more general bp_location_compare function. */ | |
925 | ||
926 | static int | |
927 | bp_location_compare_addrs (const void *ap, const void *bp) | |
928 | { | |
9a3c8263 SM |
929 | const struct bp_location *a = *(const struct bp_location **) ap; |
930 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
931 | |
932 | if (a->address == b->address) | |
933 | return 0; | |
934 | else | |
935 | return ((a->address > b->address) - (a->address < b->address)); | |
936 | } | |
937 | ||
938 | /* Helper function to skip all bp_locations with addresses | |
939 | less than ADDRESS. It returns the first bp_location that | |
940 | is greater than or equal to ADDRESS. If none is found, just | |
941 | return NULL. */ | |
942 | ||
943 | static struct bp_location ** | |
944 | get_first_locp_gte_addr (CORE_ADDR address) | |
945 | { | |
946 | struct bp_location dummy_loc; | |
947 | struct bp_location *dummy_locp = &dummy_loc; | |
948 | struct bp_location **locp_found = NULL; | |
949 | ||
950 | /* Initialize the dummy location's address field. */ | |
951 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
952 | dummy_loc.address = address; | |
953 | ||
954 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 SM |
955 | locp_found = ((struct bp_location **) |
956 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
957 | sizeof (struct bp_location **), | |
958 | bp_location_compare_addrs)); | |
b775012e LM |
959 | |
960 | /* Nothing was found, nothing left to do. */ | |
961 | if (locp_found == NULL) | |
962 | return NULL; | |
963 | ||
964 | /* We may have found a location that is at ADDRESS but is not the first in the | |
965 | location's list. Go backwards (if possible) and locate the first one. */ | |
966 | while ((locp_found - 1) >= bp_location | |
967 | && (*(locp_found - 1))->address == address) | |
968 | locp_found--; | |
969 | ||
970 | return locp_found; | |
971 | } | |
972 | ||
adc36818 | 973 | void |
7a26bd4d | 974 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
975 | int from_tty) |
976 | { | |
3a5c3e22 PA |
977 | xfree (b->cond_string); |
978 | b->cond_string = NULL; | |
adc36818 | 979 | |
3a5c3e22 | 980 | if (is_watchpoint (b)) |
adc36818 | 981 | { |
3a5c3e22 PA |
982 | struct watchpoint *w = (struct watchpoint *) b; |
983 | ||
4d01a485 | 984 | w->cond_exp.reset (); |
3a5c3e22 PA |
985 | } |
986 | else | |
987 | { | |
988 | struct bp_location *loc; | |
989 | ||
990 | for (loc = b->loc; loc; loc = loc->next) | |
991 | { | |
4d01a485 | 992 | loc->cond.reset (); |
b775012e LM |
993 | |
994 | /* No need to free the condition agent expression | |
995 | bytecode (if we have one). We will handle this | |
996 | when we go through update_global_location_list. */ | |
3a5c3e22 | 997 | } |
adc36818 | 998 | } |
adc36818 PM |
999 | |
1000 | if (*exp == 0) | |
1001 | { | |
1002 | if (from_tty) | |
1003 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1004 | } | |
1005 | else | |
1006 | { | |
bbc13ae3 | 1007 | const char *arg = exp; |
cc59ec59 | 1008 | |
adc36818 PM |
1009 | /* I don't know if it matters whether this is the string the user |
1010 | typed in or the decompiled expression. */ | |
1011 | b->cond_string = xstrdup (arg); | |
1012 | b->condition_not_parsed = 0; | |
1013 | ||
1014 | if (is_watchpoint (b)) | |
1015 | { | |
3a5c3e22 PA |
1016 | struct watchpoint *w = (struct watchpoint *) b; |
1017 | ||
adc36818 PM |
1018 | innermost_block = NULL; |
1019 | arg = exp; | |
1bb9788d | 1020 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1021 | if (*arg) |
1022 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1023 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1024 | } |
1025 | else | |
1026 | { | |
3a5c3e22 PA |
1027 | struct bp_location *loc; |
1028 | ||
adc36818 PM |
1029 | for (loc = b->loc; loc; loc = loc->next) |
1030 | { | |
1031 | arg = exp; | |
1032 | loc->cond = | |
1bb9788d TT |
1033 | parse_exp_1 (&arg, loc->address, |
1034 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1035 | if (*arg) |
1036 | error (_("Junk at end of expression")); | |
1037 | } | |
1038 | } | |
1039 | } | |
b775012e LM |
1040 | mark_breakpoint_modified (b); |
1041 | ||
8d3788bd | 1042 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1043 | } |
1044 | ||
d55637df TT |
1045 | /* Completion for the "condition" command. */ |
1046 | ||
1047 | static VEC (char_ptr) * | |
6f937416 PA |
1048 | condition_completer (struct cmd_list_element *cmd, |
1049 | const char *text, const char *word) | |
d55637df | 1050 | { |
6f937416 | 1051 | const char *space; |
d55637df | 1052 | |
6f937416 PA |
1053 | text = skip_spaces_const (text); |
1054 | space = skip_to_space_const (text); | |
d55637df TT |
1055 | if (*space == '\0') |
1056 | { | |
1057 | int len; | |
1058 | struct breakpoint *b; | |
1059 | VEC (char_ptr) *result = NULL; | |
1060 | ||
1061 | if (text[0] == '$') | |
1062 | { | |
1063 | /* We don't support completion of history indices. */ | |
1064 | if (isdigit (text[1])) | |
1065 | return NULL; | |
1066 | return complete_internalvar (&text[1]); | |
1067 | } | |
1068 | ||
1069 | /* We're completing the breakpoint number. */ | |
1070 | len = strlen (text); | |
1071 | ||
1072 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1073 | { |
1074 | char number[50]; | |
1075 | ||
1076 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1077 | ||
1078 | if (strncmp (number, text, len) == 0) | |
1079 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1080 | } | |
d55637df TT |
1081 | |
1082 | return result; | |
1083 | } | |
1084 | ||
1085 | /* We're completing the expression part. */ | |
6f937416 | 1086 | text = skip_spaces_const (space); |
d55637df TT |
1087 | return expression_completer (cmd, text, word); |
1088 | } | |
1089 | ||
c906108c SS |
1090 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1091 | ||
1092 | static void | |
fba45db2 | 1093 | condition_command (char *arg, int from_tty) |
c906108c | 1094 | { |
52f0bd74 | 1095 | struct breakpoint *b; |
c906108c | 1096 | char *p; |
52f0bd74 | 1097 | int bnum; |
c906108c SS |
1098 | |
1099 | if (arg == 0) | |
e2e0b3e5 | 1100 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1101 | |
1102 | p = arg; | |
1103 | bnum = get_number (&p); | |
5c44784c | 1104 | if (bnum == 0) |
8a3fe4f8 | 1105 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1106 | |
1107 | ALL_BREAKPOINTS (b) | |
1108 | if (b->number == bnum) | |
2f069f6f | 1109 | { |
6dddc817 DE |
1110 | /* Check if this breakpoint has a "stop" method implemented in an |
1111 | extension language. This method and conditions entered into GDB | |
1112 | from the CLI are mutually exclusive. */ | |
1113 | const struct extension_language_defn *extlang | |
1114 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1115 | ||
1116 | if (extlang != NULL) | |
1117 | { | |
1118 | error (_("Only one stop condition allowed. There is currently" | |
1119 | " a %s stop condition defined for this breakpoint."), | |
1120 | ext_lang_capitalized_name (extlang)); | |
1121 | } | |
2566ad2d | 1122 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1123 | |
1124 | if (is_breakpoint (b)) | |
44702360 | 1125 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1126 | |
2f069f6f JB |
1127 | return; |
1128 | } | |
c906108c | 1129 | |
8a3fe4f8 | 1130 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1131 | } |
1132 | ||
a7bdde9e VP |
1133 | /* Check that COMMAND do not contain commands that are suitable |
1134 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1135 | Throw if any such commands is found. */ |
1136 | ||
a7bdde9e VP |
1137 | static void |
1138 | check_no_tracepoint_commands (struct command_line *commands) | |
1139 | { | |
1140 | struct command_line *c; | |
cc59ec59 | 1141 | |
a7bdde9e VP |
1142 | for (c = commands; c; c = c->next) |
1143 | { | |
1144 | int i; | |
1145 | ||
1146 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1147 | error (_("The 'while-stepping' command can " |
1148 | "only be used for tracepoints")); | |
a7bdde9e VP |
1149 | |
1150 | for (i = 0; i < c->body_count; ++i) | |
1151 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1152 | ||
1153 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1154 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1155 | command directly. */ |
1156 | if (strstr (c->line, "collect ") == c->line) | |
1157 | error (_("The 'collect' command can only be used for tracepoints")); | |
1158 | ||
51661e93 VP |
1159 | if (strstr (c->line, "teval ") == c->line) |
1160 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1161 | } |
1162 | } | |
1163 | ||
d77f58be SS |
1164 | /* Encapsulate tests for different types of tracepoints. */ |
1165 | ||
d9b3f62e PA |
1166 | static int |
1167 | is_tracepoint_type (enum bptype type) | |
1168 | { | |
1169 | return (type == bp_tracepoint | |
1170 | || type == bp_fast_tracepoint | |
1171 | || type == bp_static_tracepoint); | |
1172 | } | |
1173 | ||
a7bdde9e | 1174 | int |
d77f58be | 1175 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1176 | { |
d9b3f62e | 1177 | return is_tracepoint_type (b->type); |
a7bdde9e | 1178 | } |
d9b3f62e | 1179 | |
e5dd4106 | 1180 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1181 | breakpoint. This function will throw an exception if a problem is |
1182 | found. */ | |
48cb2d85 | 1183 | |
95a42b64 TT |
1184 | static void |
1185 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1186 | struct command_line *commands) | |
48cb2d85 | 1187 | { |
d77f58be | 1188 | if (is_tracepoint (b)) |
a7bdde9e | 1189 | { |
c9a6ce02 | 1190 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1191 | struct command_line *c; |
1192 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1193 | |
1194 | /* Reset the while-stepping step count. The previous commands | |
1195 | might have included a while-stepping action, while the new | |
1196 | ones might not. */ | |
1197 | t->step_count = 0; | |
1198 | ||
1199 | /* We need to verify that each top-level element of commands is | |
1200 | valid for tracepoints, that there's at most one | |
1201 | while-stepping element, and that the while-stepping's body | |
1202 | has valid tracing commands excluding nested while-stepping. | |
1203 | We also need to validate the tracepoint action line in the | |
1204 | context of the tracepoint --- validate_actionline actually | |
1205 | has side effects, like setting the tracepoint's | |
1206 | while-stepping STEP_COUNT, in addition to checking if the | |
1207 | collect/teval actions parse and make sense in the | |
1208 | tracepoint's context. */ | |
a7bdde9e VP |
1209 | for (c = commands; c; c = c->next) |
1210 | { | |
a7bdde9e VP |
1211 | if (c->control_type == while_stepping_control) |
1212 | { | |
1213 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1214 | error (_("The 'while-stepping' command " |
1215 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1216 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1217 | error (_("The 'while-stepping' command " |
1218 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1219 | |
1220 | if (while_stepping) | |
3e43a32a MS |
1221 | error (_("The 'while-stepping' command " |
1222 | "can be used only once")); | |
a7bdde9e VP |
1223 | else |
1224 | while_stepping = c; | |
1225 | } | |
c9a6ce02 PA |
1226 | |
1227 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1228 | } |
1229 | if (while_stepping) | |
1230 | { | |
1231 | struct command_line *c2; | |
1232 | ||
1233 | gdb_assert (while_stepping->body_count == 1); | |
1234 | c2 = while_stepping->body_list[0]; | |
1235 | for (; c2; c2 = c2->next) | |
1236 | { | |
a7bdde9e VP |
1237 | if (c2->control_type == while_stepping_control) |
1238 | error (_("The 'while-stepping' command cannot be nested")); | |
1239 | } | |
1240 | } | |
1241 | } | |
1242 | else | |
1243 | { | |
1244 | check_no_tracepoint_commands (commands); | |
1245 | } | |
95a42b64 TT |
1246 | } |
1247 | ||
0fb4aa4b PA |
1248 | /* Return a vector of all the static tracepoints set at ADDR. The |
1249 | caller is responsible for releasing the vector. */ | |
1250 | ||
1251 | VEC(breakpoint_p) * | |
1252 | static_tracepoints_here (CORE_ADDR addr) | |
1253 | { | |
1254 | struct breakpoint *b; | |
1255 | VEC(breakpoint_p) *found = 0; | |
1256 | struct bp_location *loc; | |
1257 | ||
1258 | ALL_BREAKPOINTS (b) | |
1259 | if (b->type == bp_static_tracepoint) | |
1260 | { | |
1261 | for (loc = b->loc; loc; loc = loc->next) | |
1262 | if (loc->address == addr) | |
1263 | VEC_safe_push(breakpoint_p, found, b); | |
1264 | } | |
1265 | ||
1266 | return found; | |
1267 | } | |
1268 | ||
95a42b64 | 1269 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1270 | validate that only allowed commands are included. */ |
95a42b64 TT |
1271 | |
1272 | void | |
4a64f543 | 1273 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1274 | command_line_up &&commands) |
95a42b64 | 1275 | { |
93921405 | 1276 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1277 | |
9add0f1b | 1278 | decref_counted_command_line (&b->commands); |
93921405 | 1279 | b->commands = alloc_counted_command_line (commands.release ()); |
8d3788bd | 1280 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1281 | } |
1282 | ||
45a43567 TT |
1283 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1284 | is not the same as the "silent" that may appear in the breakpoint's | |
1285 | commands. */ | |
1286 | ||
1287 | void | |
1288 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1289 | { | |
1290 | int old_silent = b->silent; | |
1291 | ||
1292 | b->silent = silent; | |
1293 | if (old_silent != silent) | |
8d3788bd | 1294 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1295 | } |
1296 | ||
1297 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1298 | breakpoint work for any thread. */ | |
1299 | ||
1300 | void | |
1301 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1302 | { | |
1303 | int old_thread = b->thread; | |
1304 | ||
1305 | b->thread = thread; | |
1306 | if (old_thread != thread) | |
8d3788bd | 1307 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1308 | } |
1309 | ||
1310 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1311 | breakpoint work for any task. */ | |
1312 | ||
1313 | void | |
1314 | breakpoint_set_task (struct breakpoint *b, int task) | |
1315 | { | |
1316 | int old_task = b->task; | |
1317 | ||
1318 | b->task = task; | |
1319 | if (old_task != task) | |
8d3788bd | 1320 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1321 | } |
1322 | ||
95a42b64 TT |
1323 | void |
1324 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1325 | { |
9a3c8263 | 1326 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1327 | |
6f937416 | 1328 | validate_actionline (line, b); |
a7bdde9e VP |
1329 | } |
1330 | ||
95a42b64 TT |
1331 | /* A structure used to pass information through |
1332 | map_breakpoint_numbers. */ | |
1333 | ||
1334 | struct commands_info | |
1335 | { | |
1336 | /* True if the command was typed at a tty. */ | |
1337 | int from_tty; | |
86b17b60 PA |
1338 | |
1339 | /* The breakpoint range spec. */ | |
896b6bda | 1340 | const char *arg; |
86b17b60 | 1341 | |
95a42b64 TT |
1342 | /* Non-NULL if the body of the commands are being read from this |
1343 | already-parsed command. */ | |
1344 | struct command_line *control; | |
86b17b60 | 1345 | |
95a42b64 TT |
1346 | /* The command lines read from the user, or NULL if they have not |
1347 | yet been read. */ | |
1348 | struct counted_command_line *cmd; | |
1349 | }; | |
1350 | ||
1351 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1352 | commands_command. */ | |
1353 | ||
c906108c | 1354 | static void |
95a42b64 | 1355 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1356 | { |
9a3c8263 | 1357 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1358 | |
95a42b64 TT |
1359 | if (info->cmd == NULL) |
1360 | { | |
93921405 | 1361 | command_line_up l; |
5c44784c | 1362 | |
95a42b64 TT |
1363 | if (info->control != NULL) |
1364 | l = copy_command_lines (info->control->body_list[0]); | |
1365 | else | |
86b17b60 PA |
1366 | { |
1367 | struct cleanup *old_chain; | |
1368 | char *str; | |
c5aa993b | 1369 | |
3e43a32a MS |
1370 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1371 | "%s, one per line."), | |
86b17b60 PA |
1372 | info->arg); |
1373 | ||
1374 | old_chain = make_cleanup (xfree, str); | |
1375 | ||
1376 | l = read_command_lines (str, | |
1377 | info->from_tty, 1, | |
d77f58be | 1378 | (is_tracepoint (b) |
86b17b60 PA |
1379 | ? check_tracepoint_command : 0), |
1380 | b); | |
1381 | ||
1382 | do_cleanups (old_chain); | |
1383 | } | |
a7bdde9e | 1384 | |
93921405 | 1385 | info->cmd = alloc_counted_command_line (l.release ()); |
95a42b64 TT |
1386 | } |
1387 | ||
1388 | /* If a breakpoint was on the list more than once, we don't need to | |
1389 | do anything. */ | |
1390 | if (b->commands != info->cmd) | |
1391 | { | |
1392 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1393 | incref_counted_command_line (info->cmd); | |
1394 | decref_counted_command_line (&b->commands); | |
1395 | b->commands = info->cmd; | |
8d3788bd | 1396 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1397 | } |
95a42b64 TT |
1398 | } |
1399 | ||
1400 | static void | |
896b6bda | 1401 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1402 | struct command_line *control) |
95a42b64 TT |
1403 | { |
1404 | struct cleanup *cleanups; | |
1405 | struct commands_info info; | |
1406 | ||
1407 | info.from_tty = from_tty; | |
1408 | info.control = control; | |
1409 | info.cmd = NULL; | |
1410 | /* If we read command lines from the user, then `info' will hold an | |
1411 | extra reference to the commands that we must clean up. */ | |
1412 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1413 | ||
896b6bda PA |
1414 | std::string new_arg; |
1415 | ||
95a42b64 TT |
1416 | if (arg == NULL || !*arg) |
1417 | { | |
86b17b60 | 1418 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1419 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1420 | breakpoint_count); | |
95a42b64 | 1421 | else if (breakpoint_count > 0) |
896b6bda | 1422 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1423 | } |
9766ced4 | 1424 | else |
896b6bda | 1425 | new_arg = arg; |
86b17b60 | 1426 | |
896b6bda | 1427 | info.arg = new_arg.c_str (); |
95a42b64 | 1428 | |
896b6bda | 1429 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1430 | |
1431 | if (info.cmd == NULL) | |
1432 | error (_("No breakpoints specified.")); | |
1433 | ||
1434 | do_cleanups (cleanups); | |
1435 | } | |
1436 | ||
1437 | static void | |
1438 | commands_command (char *arg, int from_tty) | |
1439 | { | |
1440 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1441 | } |
40c03ae8 EZ |
1442 | |
1443 | /* Like commands_command, but instead of reading the commands from | |
1444 | input stream, takes them from an already parsed command structure. | |
1445 | ||
1446 | This is used by cli-script.c to DTRT with breakpoint commands | |
1447 | that are part of if and while bodies. */ | |
1448 | enum command_control_type | |
896b6bda | 1449 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1450 | { |
95a42b64 TT |
1451 | commands_command_1 (arg, 0, cmd); |
1452 | return simple_control; | |
40c03ae8 | 1453 | } |
876fa593 JK |
1454 | |
1455 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1456 | ||
1457 | static int | |
1458 | bp_location_has_shadow (struct bp_location *bl) | |
1459 | { | |
1460 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1461 | return 0; | |
1462 | if (!bl->inserted) | |
1463 | return 0; | |
1464 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1465 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1466 | return 0; |
1467 | return 1; | |
1468 | } | |
1469 | ||
9d497a19 PA |
1470 | /* Update BUF, which is LEN bytes read from the target address |
1471 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1472 | contents. | |
1473 | ||
1474 | If READBUF is not NULL, this buffer must not overlap with the of | |
1475 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1476 | failed assertion internal error will be raised. */ | |
1477 | ||
1478 | static void | |
1479 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1480 | const gdb_byte *writebuf_org, | |
1481 | ULONGEST memaddr, LONGEST len, | |
1482 | struct bp_target_info *target_info, | |
1483 | struct gdbarch *gdbarch) | |
1484 | { | |
1485 | /* Now do full processing of the found relevant range of elements. */ | |
1486 | CORE_ADDR bp_addr = 0; | |
1487 | int bp_size = 0; | |
1488 | int bptoffset = 0; | |
1489 | ||
1490 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1491 | current_program_space->aspace, 0)) | |
1492 | { | |
1493 | /* The breakpoint is inserted in a different address space. */ | |
1494 | return; | |
1495 | } | |
1496 | ||
1497 | /* Addresses and length of the part of the breakpoint that | |
1498 | we need to copy. */ | |
1499 | bp_addr = target_info->placed_address; | |
1500 | bp_size = target_info->shadow_len; | |
1501 | ||
1502 | if (bp_addr + bp_size <= memaddr) | |
1503 | { | |
1504 | /* The breakpoint is entirely before the chunk of memory we are | |
1505 | reading. */ | |
1506 | return; | |
1507 | } | |
1508 | ||
1509 | if (bp_addr >= memaddr + len) | |
1510 | { | |
1511 | /* The breakpoint is entirely after the chunk of memory we are | |
1512 | reading. */ | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | /* Offset within shadow_contents. */ | |
1517 | if (bp_addr < memaddr) | |
1518 | { | |
1519 | /* Only copy the second part of the breakpoint. */ | |
1520 | bp_size -= memaddr - bp_addr; | |
1521 | bptoffset = memaddr - bp_addr; | |
1522 | bp_addr = memaddr; | |
1523 | } | |
1524 | ||
1525 | if (bp_addr + bp_size > memaddr + len) | |
1526 | { | |
1527 | /* Only copy the first part of the breakpoint. */ | |
1528 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1529 | } | |
1530 | ||
1531 | if (readbuf != NULL) | |
1532 | { | |
1533 | /* Verify that the readbuf buffer does not overlap with the | |
1534 | shadow_contents buffer. */ | |
1535 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1536 | || readbuf >= (target_info->shadow_contents | |
1537 | + target_info->shadow_len)); | |
1538 | ||
1539 | /* Update the read buffer with this inserted breakpoint's | |
1540 | shadow. */ | |
1541 | memcpy (readbuf + bp_addr - memaddr, | |
1542 | target_info->shadow_contents + bptoffset, bp_size); | |
1543 | } | |
1544 | else | |
1545 | { | |
1546 | const unsigned char *bp; | |
0d5ed153 MR |
1547 | CORE_ADDR addr = target_info->reqstd_address; |
1548 | int placed_size; | |
9d497a19 PA |
1549 | |
1550 | /* Update the shadow with what we want to write to memory. */ | |
1551 | memcpy (target_info->shadow_contents + bptoffset, | |
1552 | writebuf_org + bp_addr - memaddr, bp_size); | |
1553 | ||
1554 | /* Determine appropriate breakpoint contents and size for this | |
1555 | address. */ | |
0d5ed153 | 1556 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1557 | |
1558 | /* Update the final write buffer with this inserted | |
1559 | breakpoint's INSN. */ | |
1560 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1561 | } | |
1562 | } | |
1563 | ||
8defab1a | 1564 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1565 | by replacing any memory breakpoints with their shadowed contents. |
1566 | ||
35c63cd8 JB |
1567 | If READBUF is not NULL, this buffer must not overlap with any of |
1568 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1569 | a failed assertion internal error will be raised. | |
1570 | ||
876fa593 | 1571 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1572 | bl->address - bp_location_placed_address_before_address_max |
1573 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1574 | The range we were requested to resolve shadows for is: |
1575 | memaddr ... memaddr + len | |
1576 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1577 | memaddr + len <= (bl->address |
1578 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1579 | and: |
35df4500 | 1580 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1581 | |
8defab1a | 1582 | void |
f0ba3972 PA |
1583 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1584 | const gdb_byte *writebuf_org, | |
1585 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1586 | { |
4a64f543 MS |
1587 | /* Left boundary, right boundary and median element of our binary |
1588 | search. */ | |
876fa593 JK |
1589 | unsigned bc_l, bc_r, bc; |
1590 | ||
4a64f543 MS |
1591 | /* Find BC_L which is a leftmost element which may affect BUF |
1592 | content. It is safe to report lower value but a failure to | |
1593 | report higher one. */ | |
876fa593 JK |
1594 | |
1595 | bc_l = 0; | |
1596 | bc_r = bp_location_count; | |
1597 | while (bc_l + 1 < bc_r) | |
1598 | { | |
35df4500 | 1599 | struct bp_location *bl; |
876fa593 JK |
1600 | |
1601 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1602 | bl = bp_location[bc]; |
876fa593 | 1603 | |
4a64f543 MS |
1604 | /* Check first BL->ADDRESS will not overflow due to the added |
1605 | constant. Then advance the left boundary only if we are sure | |
1606 | the BC element can in no way affect the BUF content (MEMADDR | |
1607 | to MEMADDR + LEN range). | |
876fa593 | 1608 | |
4a64f543 MS |
1609 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1610 | offset so that we cannot miss a breakpoint with its shadow | |
1611 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1612 | |
35df4500 TJB |
1613 | if ((bl->address + bp_location_shadow_len_after_address_max |
1614 | >= bl->address) | |
1615 | && (bl->address + bp_location_shadow_len_after_address_max | |
1616 | <= memaddr)) | |
876fa593 JK |
1617 | bc_l = bc; |
1618 | else | |
1619 | bc_r = bc; | |
1620 | } | |
1621 | ||
128070bb PA |
1622 | /* Due to the binary search above, we need to make sure we pick the |
1623 | first location that's at BC_L's address. E.g., if there are | |
1624 | multiple locations at the same address, BC_L may end up pointing | |
1625 | at a duplicate location, and miss the "master"/"inserted" | |
1626 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1627 | B: | |
1628 | ||
1629 | L1@A, L2@A, L3@B, ... | |
1630 | ||
1631 | BC_L could end up pointing at location L2, while the "master" | |
1632 | location could be L1. Since the `loc->inserted' flag is only set | |
1633 | on "master" locations, we'd forget to restore the shadow of L1 | |
1634 | and L2. */ | |
1635 | while (bc_l > 0 | |
1636 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1637 | bc_l--; | |
1638 | ||
876fa593 JK |
1639 | /* Now do full processing of the found relevant range of elements. */ |
1640 | ||
1641 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1642 | { |
35df4500 | 1643 | struct bp_location *bl = bp_location[bc]; |
876fa593 | 1644 | |
35df4500 TJB |
1645 | /* bp_location array has BL->OWNER always non-NULL. */ |
1646 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1647 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1648 | bl->owner->number); |
ffce0d52 | 1649 | |
e5dd4106 | 1650 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1651 | content. */ |
1652 | ||
35df4500 TJB |
1653 | if (bl->address >= bp_location_placed_address_before_address_max |
1654 | && memaddr + len <= (bl->address | |
1655 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1656 | break; |
1657 | ||
35df4500 | 1658 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1659 | continue; |
6c95b8df | 1660 | |
9d497a19 PA |
1661 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1662 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1663 | } | |
c906108c | 1664 | } |
9d497a19 | 1665 | |
c906108c | 1666 | \f |
c5aa993b | 1667 | |
b775012e LM |
1668 | /* Return true if BPT is either a software breakpoint or a hardware |
1669 | breakpoint. */ | |
1670 | ||
1671 | int | |
1672 | is_breakpoint (const struct breakpoint *bpt) | |
1673 | { | |
1674 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1675 | || bpt->type == bp_hardware_breakpoint |
1676 | || bpt->type == bp_dprintf); | |
b775012e LM |
1677 | } |
1678 | ||
60e1c644 PA |
1679 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1680 | ||
a5606eee | 1681 | static int |
d77f58be | 1682 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1683 | { |
1684 | return (bpt->type == bp_hardware_watchpoint | |
1685 | || bpt->type == bp_read_watchpoint | |
1686 | || bpt->type == bp_access_watchpoint); | |
1687 | } | |
7270d8f2 | 1688 | |
60e1c644 PA |
1689 | /* Return true if BPT is of any watchpoint kind, hardware or |
1690 | software. */ | |
1691 | ||
3a5c3e22 | 1692 | int |
d77f58be | 1693 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1694 | { |
1695 | return (is_hardware_watchpoint (bpt) | |
1696 | || bpt->type == bp_watchpoint); | |
1697 | } | |
1698 | ||
3a5c3e22 PA |
1699 | /* Returns true if the current thread and its running state are safe |
1700 | to evaluate or update watchpoint B. Watchpoints on local | |
1701 | expressions need to be evaluated in the context of the thread that | |
1702 | was current when the watchpoint was created, and, that thread needs | |
1703 | to be stopped to be able to select the correct frame context. | |
1704 | Watchpoints on global expressions can be evaluated on any thread, | |
1705 | and in any state. It is presently left to the target allowing | |
1706 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1707 | |
1708 | static int | |
3a5c3e22 | 1709 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1710 | { |
d0d8b0c6 JK |
1711 | return (b->base.pspace == current_program_space |
1712 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1713 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1714 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1715 | } |
1716 | ||
d0fb5eae JK |
1717 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1718 | associated bp_watchpoint_scope breakpoint. */ | |
1719 | ||
1720 | static void | |
3a5c3e22 | 1721 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1722 | { |
3a5c3e22 | 1723 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1724 | |
1725 | if (b->related_breakpoint != b) | |
1726 | { | |
1727 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1728 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1729 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1730 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1731 | b->related_breakpoint = b; | |
1732 | } | |
1733 | b->disposition = disp_del_at_next_stop; | |
1734 | } | |
1735 | ||
bb9d5f81 PP |
1736 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1737 | watchpoint W. */ | |
1738 | ||
1739 | static struct value * | |
1740 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1741 | { | |
1742 | struct value *bit_val; | |
1743 | ||
1744 | if (val == NULL) | |
1745 | return NULL; | |
1746 | ||
1747 | bit_val = allocate_value (value_type (val)); | |
1748 | ||
1749 | unpack_value_bitfield (bit_val, | |
1750 | w->val_bitpos, | |
1751 | w->val_bitsize, | |
1752 | value_contents_for_printing (val), | |
1753 | value_offset (val), | |
1754 | val); | |
1755 | ||
1756 | return bit_val; | |
1757 | } | |
1758 | ||
c6d81124 PA |
1759 | /* Allocate a dummy location and add it to B, which must be a software |
1760 | watchpoint. This is required because even if a software watchpoint | |
1761 | is not watching any memory, bpstat_stop_status requires a location | |
1762 | to be able to report stops. */ | |
1763 | ||
1764 | static void | |
1765 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1766 | struct program_space *pspace) | |
1767 | { | |
1768 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1769 | ||
1770 | b->loc = allocate_bp_location (b); | |
1771 | b->loc->pspace = pspace; | |
1772 | b->loc->address = -1; | |
1773 | b->loc->length = -1; | |
1774 | } | |
1775 | ||
1776 | /* Returns true if B is a software watchpoint that is not watching any | |
1777 | memory (e.g., "watch $pc"). */ | |
1778 | ||
1779 | static int | |
1780 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1781 | { | |
1782 | return (b->type == bp_watchpoint | |
1783 | && b->loc != NULL | |
1784 | && b->loc->next == NULL | |
1785 | && b->loc->address == -1 | |
1786 | && b->loc->length == -1); | |
1787 | } | |
1788 | ||
567e1b4e JB |
1789 | /* Assuming that B is a watchpoint: |
1790 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1791 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1792 | - Evaluate the condition if there is one, and store the result |
1793 | in b->loc->cond. | |
a5606eee VP |
1794 | - Update the list of values that must be watched in B->loc. |
1795 | ||
4a64f543 MS |
1796 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1797 | nothing. If this is local watchpoint that is out of scope, delete | |
1798 | it. | |
1799 | ||
1800 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1801 | removed + inserted on each stop here. Normal breakpoints must | |
1802 | never be removed because they might be missed by a running thread | |
1803 | when debugging in non-stop mode. On the other hand, hardware | |
1804 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1805 | to each LWP since they are stored in each LWP's hardware debug | |
1806 | registers. Therefore, such LWP must be stopped first in order to | |
1807 | be able to modify its hardware watchpoints. | |
1808 | ||
1809 | Hardware watchpoints must be reset exactly once after being | |
1810 | presented to the user. It cannot be done sooner, because it would | |
1811 | reset the data used to present the watchpoint hit to the user. And | |
1812 | it must not be done later because it could display the same single | |
1813 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1814 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1815 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1816 | not user-visible - its hit is suppressed if the memory content has | |
1817 | not changed. | |
1818 | ||
1819 | The following constraints influence the location where we can reset | |
1820 | hardware watchpoints: | |
1821 | ||
1822 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1823 | called several times when GDB stops. | |
1824 | ||
1825 | [linux] | |
1826 | * Multiple hardware watchpoints can be hit at the same time, | |
1827 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1828 | hit at a time as the reason for stopping, and all the other hits | |
1829 | are presented later, one after the other, each time the user | |
1830 | requests the execution to be resumed. Execution is not resumed | |
1831 | for the threads still having pending hit event stored in | |
1832 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1833 | the inferior on the first stop the thread hit event is kept being | |
1834 | reported from its cached value by linux_nat_stopped_data_address | |
1835 | until the real thread resume happens after the watchpoint gets | |
1836 | presented and thus its LWP_INFO->STATUS gets reset. | |
1837 | ||
1838 | Therefore the hardware watchpoint hit can get safely reset on the | |
1839 | watchpoint removal from inferior. */ | |
a79d3c27 | 1840 | |
b40ce68a | 1841 | static void |
3a5c3e22 | 1842 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1843 | { |
a5606eee | 1844 | int within_current_scope; |
a5606eee | 1845 | struct frame_id saved_frame_id; |
66076460 | 1846 | int frame_saved; |
a5606eee | 1847 | |
f6bc2008 PA |
1848 | /* If this is a local watchpoint, we only want to check if the |
1849 | watchpoint frame is in scope if the current thread is the thread | |
1850 | that was used to create the watchpoint. */ | |
1851 | if (!watchpoint_in_thread_scope (b)) | |
1852 | return; | |
1853 | ||
3a5c3e22 | 1854 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1855 | return; |
1856 | ||
66076460 | 1857 | frame_saved = 0; |
a5606eee VP |
1858 | |
1859 | /* Determine if the watchpoint is within scope. */ | |
1860 | if (b->exp_valid_block == NULL) | |
1861 | within_current_scope = 1; | |
1862 | else | |
1863 | { | |
b5db5dfc UW |
1864 | struct frame_info *fi = get_current_frame (); |
1865 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1866 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1867 | ||
c9cf6e20 MG |
1868 | /* If we're at a point where the stack has been destroyed |
1869 | (e.g. in a function epilogue), unwinding may not work | |
1870 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1871 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1872 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1873 | return; |
66076460 DJ |
1874 | |
1875 | /* Save the current frame's ID so we can restore it after | |
1876 | evaluating the watchpoint expression on its own frame. */ | |
1877 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1878 | took a frame parameter, so that we didn't have to change the | |
1879 | selected frame. */ | |
1880 | frame_saved = 1; | |
1881 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1882 | ||
a5606eee VP |
1883 | fi = frame_find_by_id (b->watchpoint_frame); |
1884 | within_current_scope = (fi != NULL); | |
1885 | if (within_current_scope) | |
1886 | select_frame (fi); | |
1887 | } | |
1888 | ||
b5db5dfc UW |
1889 | /* We don't free locations. They are stored in the bp_location array |
1890 | and update_global_location_list will eventually delete them and | |
1891 | remove breakpoints if needed. */ | |
3a5c3e22 | 1892 | b->base.loc = NULL; |
b5db5dfc | 1893 | |
a5606eee VP |
1894 | if (within_current_scope && reparse) |
1895 | { | |
bbc13ae3 | 1896 | const char *s; |
d63d0675 | 1897 | |
4d01a485 | 1898 | b->exp.reset (); |
d63d0675 | 1899 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1900 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1901 | /* If the meaning of expression itself changed, the old value is |
1902 | no longer relevant. We don't want to report a watchpoint hit | |
1903 | to the user when the old value and the new value may actually | |
1904 | be completely different objects. */ | |
1905 | value_free (b->val); | |
fa4727a6 DJ |
1906 | b->val = NULL; |
1907 | b->val_valid = 0; | |
60e1c644 PA |
1908 | |
1909 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1910 | expression is stored in the breakpoint object, not in the | |
1911 | locations (re)created below. */ | |
3a5c3e22 | 1912 | if (b->base.cond_string != NULL) |
60e1c644 | 1913 | { |
4d01a485 | 1914 | b->cond_exp.reset (); |
60e1c644 | 1915 | |
3a5c3e22 | 1916 | s = b->base.cond_string; |
1bb9788d | 1917 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1918 | } |
a5606eee | 1919 | } |
a5606eee VP |
1920 | |
1921 | /* If we failed to parse the expression, for example because | |
1922 | it refers to a global variable in a not-yet-loaded shared library, | |
1923 | don't try to insert watchpoint. We don't automatically delete | |
1924 | such watchpoint, though, since failure to parse expression | |
1925 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1926 | if (!target_has_execution) |
2d134ed3 PA |
1927 | { |
1928 | /* Without execution, memory can't change. No use to try and | |
1929 | set watchpoint locations. The watchpoint will be reset when | |
1930 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1931 | if (!can_use_hw_watchpoints) |
1932 | { | |
1933 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1934 | b->base.type = bp_watchpoint; | |
1935 | else | |
638aa5a1 AB |
1936 | error (_("Can't set read/access watchpoint when " |
1937 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1938 | } |
2d134ed3 PA |
1939 | } |
1940 | else if (within_current_scope && b->exp) | |
a5606eee | 1941 | { |
0cf6dd15 | 1942 | int pc = 0; |
fa4727a6 | 1943 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1944 | struct program_space *frame_pspace; |
a5606eee | 1945 | |
4d01a485 | 1946 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1947 | |
a5606eee VP |
1948 | /* Avoid setting b->val if it's already set. The meaning of |
1949 | b->val is 'the last value' user saw, and we should update | |
1950 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1951 | happens, the code that reports it updates b->val directly. |
1952 | We don't keep track of the memory value for masked | |
1953 | watchpoints. */ | |
3a5c3e22 | 1954 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1955 | { |
bb9d5f81 PP |
1956 | if (b->val_bitsize != 0) |
1957 | { | |
1958 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1959 | if (v != NULL) | |
1960 | release_value (v); | |
1961 | } | |
fa4727a6 DJ |
1962 | b->val = v; |
1963 | b->val_valid = 1; | |
1964 | } | |
a5606eee | 1965 | |
2d134ed3 PA |
1966 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1967 | ||
a5606eee | 1968 | /* Look at each value on the value chain. */ |
9fa40276 | 1969 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1970 | { |
1971 | /* If it's a memory location, and GDB actually needed | |
1972 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1973 | must watch it. If the first value returned is |
1974 | still lazy, that means an error occurred reading it; | |
1975 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1976 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1977 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1978 | { |
1979 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1980 | |
a5606eee VP |
1981 | /* We only watch structs and arrays if user asked |
1982 | for it explicitly, never if they just happen to | |
1983 | appear in the middle of some value chain. */ | |
fa4727a6 | 1984 | if (v == result |
a5606eee VP |
1985 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1986 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1987 | { | |
1988 | CORE_ADDR addr; | |
f486487f | 1989 | enum target_hw_bp_type type; |
a5606eee | 1990 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1991 | int bitpos = 0, bitsize = 0; |
1992 | ||
1993 | if (value_bitsize (v) != 0) | |
1994 | { | |
1995 | /* Extract the bit parameters out from the bitfield | |
1996 | sub-expression. */ | |
1997 | bitpos = value_bitpos (v); | |
1998 | bitsize = value_bitsize (v); | |
1999 | } | |
2000 | else if (v == result && b->val_bitsize != 0) | |
2001 | { | |
2002 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2003 | lvalue whose bit parameters are saved in the fields | |
2004 | VAL_BITPOS and VAL_BITSIZE. */ | |
2005 | bitpos = b->val_bitpos; | |
2006 | bitsize = b->val_bitsize; | |
2007 | } | |
a5606eee | 2008 | |
42ae5230 | 2009 | addr = value_address (v); |
bb9d5f81 PP |
2010 | if (bitsize != 0) |
2011 | { | |
2012 | /* Skip the bytes that don't contain the bitfield. */ | |
2013 | addr += bitpos / 8; | |
2014 | } | |
2015 | ||
a5606eee | 2016 | type = hw_write; |
3a5c3e22 | 2017 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2018 | type = hw_read; |
3a5c3e22 | 2019 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2020 | type = hw_access; |
3a5c3e22 PA |
2021 | |
2022 | loc = allocate_bp_location (&b->base); | |
2023 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2024 | ; |
2025 | *tmp = loc; | |
a6d9a66e | 2026 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2027 | |
2028 | loc->pspace = frame_pspace; | |
a5606eee | 2029 | loc->address = addr; |
bb9d5f81 PP |
2030 | |
2031 | if (bitsize != 0) | |
2032 | { | |
2033 | /* Just cover the bytes that make up the bitfield. */ | |
2034 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2035 | } | |
2036 | else | |
2037 | loc->length = TYPE_LENGTH (value_type (v)); | |
2038 | ||
a5606eee VP |
2039 | loc->watchpoint_type = type; |
2040 | } | |
2041 | } | |
9fa40276 TJB |
2042 | } |
2043 | ||
2044 | /* Change the type of breakpoint between hardware assisted or | |
2045 | an ordinary watchpoint depending on the hardware support | |
2046 | and free hardware slots. REPARSE is set when the inferior | |
2047 | is started. */ | |
a9634178 | 2048 | if (reparse) |
9fa40276 | 2049 | { |
e09342b5 | 2050 | int reg_cnt; |
9fa40276 TJB |
2051 | enum bp_loc_type loc_type; |
2052 | struct bp_location *bl; | |
a5606eee | 2053 | |
a9634178 | 2054 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2055 | |
2056 | if (reg_cnt) | |
9fa40276 TJB |
2057 | { |
2058 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2059 | enum bptype type; |
9fa40276 | 2060 | |
a9634178 TJB |
2061 | /* Use an exact watchpoint when there's only one memory region to be |
2062 | watched, and only one debug register is needed to watch it. */ | |
2063 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2064 | ||
9fa40276 | 2065 | /* We need to determine how many resources are already |
e09342b5 TJB |
2066 | used for all other hardware watchpoints plus this one |
2067 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2068 | this watchpoint in as well. */ |
2069 | ||
2070 | /* If this is a software watchpoint, we try to turn it | |
2071 | to a hardware one -- count resources as if B was of | |
2072 | hardware watchpoint type. */ | |
2073 | type = b->base.type; | |
2074 | if (type == bp_watchpoint) | |
2075 | type = bp_hardware_watchpoint; | |
2076 | ||
2077 | /* This watchpoint may or may not have been placed on | |
2078 | the list yet at this point (it won't be in the list | |
2079 | if we're trying to create it for the first time, | |
2080 | through watch_command), so always account for it | |
2081 | manually. */ | |
2082 | ||
2083 | /* Count resources used by all watchpoints except B. */ | |
2084 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2085 | ||
2086 | /* Add in the resources needed for B. */ | |
2087 | i += hw_watchpoint_use_count (&b->base); | |
2088 | ||
2089 | target_resources_ok | |
2090 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2091 | if (target_resources_ok <= 0) |
a9634178 | 2092 | { |
3a5c3e22 | 2093 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2094 | |
2095 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2096 | error (_("Target does not support this type of " |
2097 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2098 | else if (target_resources_ok < 0 && !sw_mode) |
2099 | error (_("There are not enough available hardware " | |
2100 | "resources for this watchpoint.")); | |
a1398e0c PA |
2101 | |
2102 | /* Downgrade to software watchpoint. */ | |
2103 | b->base.type = bp_watchpoint; | |
2104 | } | |
2105 | else | |
2106 | { | |
2107 | /* If this was a software watchpoint, we've just | |
2108 | found we have enough resources to turn it to a | |
2109 | hardware watchpoint. Otherwise, this is a | |
2110 | nop. */ | |
2111 | b->base.type = type; | |
a9634178 | 2112 | } |
9fa40276 | 2113 | } |
3a5c3e22 | 2114 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2115 | { |
2116 | if (!can_use_hw_watchpoints) | |
2117 | error (_("Can't set read/access watchpoint when " | |
2118 | "hardware watchpoints are disabled.")); | |
2119 | else | |
2120 | error (_("Expression cannot be implemented with " | |
2121 | "read/access watchpoint.")); | |
2122 | } | |
9fa40276 | 2123 | else |
3a5c3e22 | 2124 | b->base.type = bp_watchpoint; |
9fa40276 | 2125 | |
3a5c3e22 | 2126 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2127 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2128 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2129 | bl->loc_type = loc_type; |
2130 | } | |
2131 | ||
2132 | for (v = val_chain; v; v = next) | |
2133 | { | |
a5606eee VP |
2134 | next = value_next (v); |
2135 | if (v != b->val) | |
2136 | value_free (v); | |
2137 | } | |
2138 | ||
c7437ca6 PA |
2139 | /* If a software watchpoint is not watching any memory, then the |
2140 | above left it without any location set up. But, | |
2141 | bpstat_stop_status requires a location to be able to report | |
2142 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2143 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2144 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2145 | } |
2146 | else if (!within_current_scope) | |
7270d8f2 | 2147 | { |
ac74f770 MS |
2148 | printf_filtered (_("\ |
2149 | Watchpoint %d deleted because the program has left the block\n\ | |
2150 | in which its expression is valid.\n"), | |
3a5c3e22 | 2151 | b->base.number); |
d0fb5eae | 2152 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2153 | } |
a5606eee VP |
2154 | |
2155 | /* Restore the selected frame. */ | |
66076460 DJ |
2156 | if (frame_saved) |
2157 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2158 | } |
2159 | ||
a5606eee | 2160 | |
74960c60 | 2161 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2162 | inserted in the inferior. We don't differentiate the type of BL's owner |
2163 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2164 | breakpoint_ops is not defined, because in insert_bp_location, | |
2165 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2166 | static int |
35df4500 | 2167 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2168 | { |
35df4500 | 2169 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2170 | return 0; |
2171 | ||
35df4500 | 2172 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2173 | return 0; |
2174 | ||
35df4500 | 2175 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2176 | return 0; |
2177 | ||
f8eba3c6 TT |
2178 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2179 | return 0; | |
2180 | ||
56710373 PA |
2181 | /* This is set for example, when we're attached to the parent of a |
2182 | vfork, and have detached from the child. The child is running | |
2183 | free, and we expect it to do an exec or exit, at which point the | |
2184 | OS makes the parent schedulable again (and the target reports | |
2185 | that the vfork is done). Until the child is done with the shared | |
2186 | memory region, do not insert breakpoints in the parent, otherwise | |
2187 | the child could still trip on the parent's breakpoints. Since | |
2188 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2189 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2190 | return 0; |
2191 | ||
31e77af2 | 2192 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2193 | location, except if the breakpoint is a single-step breakpoint, |
2194 | and the breakpoint's thread is the thread which is stepping past | |
2195 | a breakpoint. */ | |
31e77af2 PA |
2196 | if ((bl->loc_type == bp_loc_software_breakpoint |
2197 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2198 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2199 | bl->address) |
2200 | /* The single-step breakpoint may be inserted at the location | |
2201 | we're trying to step if the instruction branches to itself. | |
2202 | However, the instruction won't be executed at all and it may | |
2203 | break the semantics of the instruction, for example, the | |
2204 | instruction is a conditional branch or updates some flags. | |
2205 | We can't fix it unless GDB is able to emulate the instruction | |
2206 | or switch to displaced stepping. */ | |
2207 | && !(bl->owner->type == bp_single_step | |
2208 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2209 | { |
2210 | if (debug_infrun) | |
2211 | { | |
2212 | fprintf_unfiltered (gdb_stdlog, | |
2213 | "infrun: skipping breakpoint: " | |
2214 | "stepping past insn at: %s\n", | |
2215 | paddress (bl->gdbarch, bl->address)); | |
2216 | } | |
2217 | return 0; | |
2218 | } | |
31e77af2 | 2219 | |
963f9c80 PA |
2220 | /* Don't insert watchpoints if we're trying to step past the |
2221 | instruction that triggered one. */ | |
2222 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2223 | && stepping_past_nonsteppable_watchpoint ()) | |
2224 | { | |
2225 | if (debug_infrun) | |
2226 | { | |
2227 | fprintf_unfiltered (gdb_stdlog, | |
2228 | "infrun: stepping past non-steppable watchpoint. " | |
2229 | "skipping watchpoint at %s:%d\n", | |
2230 | paddress (bl->gdbarch, bl->address), | |
2231 | bl->length); | |
2232 | } | |
2233 | return 0; | |
2234 | } | |
2235 | ||
74960c60 VP |
2236 | return 1; |
2237 | } | |
2238 | ||
934709f0 PW |
2239 | /* Same as should_be_inserted but does the check assuming |
2240 | that the location is not duplicated. */ | |
2241 | ||
2242 | static int | |
2243 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2244 | { | |
2245 | int result; | |
2246 | const int save_duplicate = bl->duplicate; | |
2247 | ||
2248 | bl->duplicate = 0; | |
2249 | result = should_be_inserted (bl); | |
2250 | bl->duplicate = save_duplicate; | |
2251 | return result; | |
2252 | } | |
2253 | ||
b775012e LM |
2254 | /* Parses a conditional described by an expression COND into an |
2255 | agent expression bytecode suitable for evaluation | |
2256 | by the bytecode interpreter. Return NULL if there was | |
2257 | any error during parsing. */ | |
2258 | ||
833177a4 | 2259 | static agent_expr_up |
b775012e LM |
2260 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2261 | { | |
833177a4 | 2262 | if (cond == NULL) |
b775012e LM |
2263 | return NULL; |
2264 | ||
833177a4 PA |
2265 | agent_expr_up aexpr; |
2266 | ||
b775012e LM |
2267 | /* We don't want to stop processing, so catch any errors |
2268 | that may show up. */ | |
492d29ea | 2269 | TRY |
b775012e | 2270 | { |
036e657b | 2271 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2272 | } |
2273 | ||
492d29ea | 2274 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2275 | { |
2276 | /* If we got here, it means the condition could not be parsed to a valid | |
2277 | bytecode expression and thus can't be evaluated on the target's side. | |
2278 | It's no use iterating through the conditions. */ | |
b775012e | 2279 | } |
492d29ea | 2280 | END_CATCH |
b775012e LM |
2281 | |
2282 | /* We have a valid agent expression. */ | |
2283 | return aexpr; | |
2284 | } | |
2285 | ||
2286 | /* Based on location BL, create a list of breakpoint conditions to be | |
2287 | passed on to the target. If we have duplicated locations with different | |
2288 | conditions, we will add such conditions to the list. The idea is that the | |
2289 | target will evaluate the list of conditions and will only notify GDB when | |
2290 | one of them is true. */ | |
2291 | ||
2292 | static void | |
2293 | build_target_condition_list (struct bp_location *bl) | |
2294 | { | |
2295 | struct bp_location **locp = NULL, **loc2p; | |
2296 | int null_condition_or_parse_error = 0; | |
2297 | int modified = bl->needs_update; | |
2298 | struct bp_location *loc; | |
2299 | ||
8b4f3082 | 2300 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2301 | bl->target_info.conditions.clear (); |
8b4f3082 | 2302 | |
b775012e LM |
2303 | /* This is only meaningful if the target is |
2304 | evaluating conditions and if the user has | |
2305 | opted for condition evaluation on the target's | |
2306 | side. */ | |
2307 | if (gdb_evaluates_breakpoint_condition_p () | |
2308 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2309 | return; | |
2310 | ||
2311 | /* Do a first pass to check for locations with no assigned | |
2312 | conditions or conditions that fail to parse to a valid agent expression | |
2313 | bytecode. If any of these happen, then it's no use to send conditions | |
2314 | to the target since this location will always trigger and generate a | |
2315 | response back to GDB. */ | |
2316 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2317 | { | |
2318 | loc = (*loc2p); | |
2319 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2320 | { | |
2321 | if (modified) | |
2322 | { | |
b775012e LM |
2323 | /* Re-parse the conditions since something changed. In that |
2324 | case we already freed the condition bytecodes (see | |
2325 | force_breakpoint_reinsertion). We just | |
2326 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2327 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2328 | loc->cond.get ()); | |
b775012e LM |
2329 | } |
2330 | ||
2331 | /* If we have a NULL bytecode expression, it means something | |
2332 | went wrong or we have a null condition expression. */ | |
2333 | if (!loc->cond_bytecode) | |
2334 | { | |
2335 | null_condition_or_parse_error = 1; | |
2336 | break; | |
2337 | } | |
2338 | } | |
2339 | } | |
2340 | ||
2341 | /* If any of these happened, it means we will have to evaluate the conditions | |
2342 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2343 | for all the other duplicate locations, thus we free all of them here. | |
2344 | ||
2345 | This is so we have a finer control over which locations' conditions are | |
2346 | being evaluated by GDB or the remote stub. */ | |
2347 | if (null_condition_or_parse_error) | |
2348 | { | |
2349 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2350 | { | |
2351 | loc = (*loc2p); | |
2352 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2353 | { | |
2354 | /* Only go as far as the first NULL bytecode is | |
2355 | located. */ | |
2356 | if (!loc->cond_bytecode) | |
2357 | return; | |
2358 | ||
833177a4 | 2359 | loc->cond_bytecode.reset (); |
b775012e LM |
2360 | } |
2361 | } | |
2362 | } | |
2363 | ||
2364 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2365 | for this location's address. */ | |
2366 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2367 | { | |
2368 | loc = (*loc2p); | |
2369 | if (loc->cond | |
2370 | && is_breakpoint (loc->owner) | |
2371 | && loc->pspace->num == bl->pspace->num | |
2372 | && loc->owner->enable_state == bp_enabled | |
2373 | && loc->enabled) | |
3cde5c42 PA |
2374 | { |
2375 | /* Add the condition to the vector. This will be used later | |
2376 | to send the conditions to the target. */ | |
2377 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2378 | } | |
b775012e LM |
2379 | } |
2380 | ||
2381 | return; | |
2382 | } | |
2383 | ||
d3ce09f5 SS |
2384 | /* Parses a command described by string CMD into an agent expression |
2385 | bytecode suitable for evaluation by the bytecode interpreter. | |
2386 | Return NULL if there was any error during parsing. */ | |
2387 | ||
833177a4 | 2388 | static agent_expr_up |
d3ce09f5 SS |
2389 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2390 | { | |
2391 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2392 | struct expression **argvec; |
bbc13ae3 KS |
2393 | const char *cmdrest; |
2394 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2395 | struct format_piece *fpieces; |
2396 | int nargs; | |
2397 | struct gdbarch *gdbarch = get_current_arch (); | |
2398 | ||
833177a4 | 2399 | if (cmd == NULL) |
d3ce09f5 SS |
2400 | return NULL; |
2401 | ||
2402 | cmdrest = cmd; | |
2403 | ||
2404 | if (*cmdrest == ',') | |
2405 | ++cmdrest; | |
bbc13ae3 | 2406 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2407 | |
2408 | if (*cmdrest++ != '"') | |
2409 | error (_("No format string following the location")); | |
2410 | ||
2411 | format_start = cmdrest; | |
2412 | ||
2413 | fpieces = parse_format_string (&cmdrest); | |
2414 | ||
2415 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2416 | ||
2417 | format_end = cmdrest; | |
2418 | ||
2419 | if (*cmdrest++ != '"') | |
2420 | error (_("Bad format string, non-terminated '\"'.")); | |
2421 | ||
bbc13ae3 | 2422 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2423 | |
2424 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2425 | error (_("Invalid argument syntax")); | |
2426 | ||
2427 | if (*cmdrest == ',') | |
2428 | cmdrest++; | |
bbc13ae3 | 2429 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2430 | |
2431 | /* For each argument, make an expression. */ | |
2432 | ||
2433 | argvec = (struct expression **) alloca (strlen (cmd) | |
2434 | * sizeof (struct expression *)); | |
2435 | ||
2436 | nargs = 0; | |
2437 | while (*cmdrest != '\0') | |
2438 | { | |
bbc13ae3 | 2439 | const char *cmd1; |
d3ce09f5 SS |
2440 | |
2441 | cmd1 = cmdrest; | |
4d01a485 PA |
2442 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2443 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2444 | cmdrest = cmd1; |
2445 | if (*cmdrest == ',') | |
2446 | ++cmdrest; | |
2447 | } | |
2448 | ||
833177a4 PA |
2449 | agent_expr_up aexpr; |
2450 | ||
d3ce09f5 SS |
2451 | /* We don't want to stop processing, so catch any errors |
2452 | that may show up. */ | |
492d29ea | 2453 | TRY |
d3ce09f5 | 2454 | { |
036e657b JB |
2455 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2456 | format_start, format_end - format_start, | |
2457 | fpieces, nargs, argvec); | |
d3ce09f5 | 2458 | } |
492d29ea | 2459 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2460 | { |
2461 | /* If we got here, it means the command could not be parsed to a valid | |
2462 | bytecode expression and thus can't be evaluated on the target's side. | |
2463 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2464 | } |
492d29ea PA |
2465 | END_CATCH |
2466 | ||
2467 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2468 | |
d3ce09f5 SS |
2469 | /* We have a valid agent expression, return it. */ |
2470 | return aexpr; | |
2471 | } | |
2472 | ||
2473 | /* Based on location BL, create a list of breakpoint commands to be | |
2474 | passed on to the target. If we have duplicated locations with | |
2475 | different commands, we will add any such to the list. */ | |
2476 | ||
2477 | static void | |
2478 | build_target_command_list (struct bp_location *bl) | |
2479 | { | |
2480 | struct bp_location **locp = NULL, **loc2p; | |
2481 | int null_command_or_parse_error = 0; | |
2482 | int modified = bl->needs_update; | |
2483 | struct bp_location *loc; | |
2484 | ||
3cde5c42 PA |
2485 | /* Clear commands left over from a previous insert. */ |
2486 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2487 | |
41fac0cf | 2488 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2489 | return; |
2490 | ||
41fac0cf PA |
2491 | /* For now, limit to agent-style dprintf breakpoints. */ |
2492 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2493 | return; |
2494 | ||
41fac0cf PA |
2495 | /* For now, if we have any duplicate location that isn't a dprintf, |
2496 | don't install the target-side commands, as that would make the | |
2497 | breakpoint not be reported to the core, and we'd lose | |
2498 | control. */ | |
2499 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2500 | { | |
2501 | loc = (*loc2p); | |
2502 | if (is_breakpoint (loc->owner) | |
2503 | && loc->pspace->num == bl->pspace->num | |
2504 | && loc->owner->type != bp_dprintf) | |
2505 | return; | |
2506 | } | |
2507 | ||
d3ce09f5 SS |
2508 | /* Do a first pass to check for locations with no assigned |
2509 | conditions or conditions that fail to parse to a valid agent expression | |
2510 | bytecode. If any of these happen, then it's no use to send conditions | |
2511 | to the target since this location will always trigger and generate a | |
2512 | response back to GDB. */ | |
2513 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2514 | { | |
2515 | loc = (*loc2p); | |
2516 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2517 | { | |
2518 | if (modified) | |
2519 | { | |
d3ce09f5 SS |
2520 | /* Re-parse the commands since something changed. In that |
2521 | case we already freed the command bytecodes (see | |
2522 | force_breakpoint_reinsertion). We just | |
2523 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2524 | loc->cmd_bytecode |
2525 | = parse_cmd_to_aexpr (bl->address, | |
2526 | loc->owner->extra_string); | |
d3ce09f5 SS |
2527 | } |
2528 | ||
2529 | /* If we have a NULL bytecode expression, it means something | |
2530 | went wrong or we have a null command expression. */ | |
2531 | if (!loc->cmd_bytecode) | |
2532 | { | |
2533 | null_command_or_parse_error = 1; | |
2534 | break; | |
2535 | } | |
2536 | } | |
2537 | } | |
2538 | ||
2539 | /* If anything failed, then we're not doing target-side commands, | |
2540 | and so clean up. */ | |
2541 | if (null_command_or_parse_error) | |
2542 | { | |
2543 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2544 | { | |
2545 | loc = (*loc2p); | |
2546 | if (is_breakpoint (loc->owner) | |
2547 | && loc->pspace->num == bl->pspace->num) | |
2548 | { | |
2549 | /* Only go as far as the first NULL bytecode is | |
2550 | located. */ | |
40fb6c5e | 2551 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2552 | return; |
2553 | ||
833177a4 | 2554 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2555 | } |
2556 | } | |
2557 | } | |
2558 | ||
2559 | /* No NULL commands or failed bytecode generation. Build a command list | |
2560 | for this location's address. */ | |
2561 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2562 | { | |
2563 | loc = (*loc2p); | |
2564 | if (loc->owner->extra_string | |
2565 | && is_breakpoint (loc->owner) | |
2566 | && loc->pspace->num == bl->pspace->num | |
2567 | && loc->owner->enable_state == bp_enabled | |
2568 | && loc->enabled) | |
3cde5c42 PA |
2569 | { |
2570 | /* Add the command to the vector. This will be used later | |
2571 | to send the commands to the target. */ | |
2572 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2573 | } | |
d3ce09f5 SS |
2574 | } |
2575 | ||
2576 | bl->target_info.persist = 0; | |
2577 | /* Maybe flag this location as persistent. */ | |
2578 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2579 | bl->target_info.persist = 1; | |
2580 | } | |
2581 | ||
833b7ab5 YQ |
2582 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2583 | of breakpoint according to ADDR except single-step breakpoint. | |
2584 | Get the kind of single-step breakpoint according to the current | |
2585 | registers state. */ | |
cd6c3b4f YQ |
2586 | |
2587 | static int | |
2588 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2589 | { | |
833b7ab5 YQ |
2590 | if (bl->owner->type == bp_single_step) |
2591 | { | |
2592 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2593 | struct regcache *regcache; | |
2594 | ||
2595 | regcache = get_thread_regcache (thr->ptid); | |
2596 | ||
2597 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2598 | regcache, addr); | |
2599 | } | |
2600 | else | |
2601 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2602 | } |
2603 | ||
35df4500 TJB |
2604 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2605 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2606 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2607 | Returns 0 for success, 1 if the bp_location type is not supported or |
2608 | -1 for failure. | |
879bfdc2 | 2609 | |
4a64f543 MS |
2610 | NOTE drow/2003-09-09: This routine could be broken down to an |
2611 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2612 | static int |
35df4500 | 2613 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2614 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2615 | int *disabled_breaks, |
dd61ec5c MW |
2616 | int *hw_breakpoint_error, |
2617 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2618 | { |
0000e5cc PA |
2619 | enum errors bp_err = GDB_NO_ERROR; |
2620 | const char *bp_err_message = NULL; | |
879bfdc2 | 2621 | |
b775012e | 2622 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2623 | return 0; |
2624 | ||
35c63cd8 JB |
2625 | /* Note we don't initialize bl->target_info, as that wipes out |
2626 | the breakpoint location's shadow_contents if the breakpoint | |
2627 | is still inserted at that location. This in turn breaks | |
2628 | target_read_memory which depends on these buffers when | |
2629 | a memory read is requested at the breakpoint location: | |
2630 | Once the target_info has been wiped, we fail to see that | |
2631 | we have a breakpoint inserted at that address and thus | |
2632 | read the breakpoint instead of returning the data saved in | |
2633 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2634 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2635 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2636 | bl->target_info.length = bl->length; |
8181d85f | 2637 | |
b775012e LM |
2638 | /* When working with target-side conditions, we must pass all the conditions |
2639 | for the same breakpoint address down to the target since GDB will not | |
2640 | insert those locations. With a list of breakpoint conditions, the target | |
2641 | can decide when to stop and notify GDB. */ | |
2642 | ||
2643 | if (is_breakpoint (bl->owner)) | |
2644 | { | |
2645 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2646 | build_target_command_list (bl); |
2647 | /* Reset the modification marker. */ | |
b775012e LM |
2648 | bl->needs_update = 0; |
2649 | } | |
2650 | ||
35df4500 TJB |
2651 | if (bl->loc_type == bp_loc_software_breakpoint |
2652 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2653 | { |
35df4500 | 2654 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2655 | { |
2656 | /* If the explicitly specified breakpoint type | |
2657 | is not hardware breakpoint, check the memory map to see | |
2658 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2659 | |
765dc015 VP |
2660 | Two important cases are: |
2661 | - location type is not hardware breakpoint, memory | |
2662 | is readonly. We change the type of the location to | |
2663 | hardware breakpoint. | |
4a64f543 MS |
2664 | - location type is hardware breakpoint, memory is |
2665 | read-write. This means we've previously made the | |
2666 | location hardware one, but then the memory map changed, | |
2667 | so we undo. | |
765dc015 | 2668 | |
4a64f543 MS |
2669 | When breakpoints are removed, remove_breakpoints will use |
2670 | location types we've just set here, the only possible | |
2671 | problem is that memory map has changed during running | |
2672 | program, but it's not going to work anyway with current | |
2673 | gdb. */ | |
765dc015 | 2674 | struct mem_region *mr |
0d5ed153 | 2675 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2676 | |
2677 | if (mr) | |
2678 | { | |
2679 | if (automatic_hardware_breakpoints) | |
2680 | { | |
765dc015 VP |
2681 | enum bp_loc_type new_type; |
2682 | ||
2683 | if (mr->attrib.mode != MEM_RW) | |
2684 | new_type = bp_loc_hardware_breakpoint; | |
2685 | else | |
2686 | new_type = bp_loc_software_breakpoint; | |
2687 | ||
35df4500 | 2688 | if (new_type != bl->loc_type) |
765dc015 VP |
2689 | { |
2690 | static int said = 0; | |
cc59ec59 | 2691 | |
35df4500 | 2692 | bl->loc_type = new_type; |
765dc015 VP |
2693 | if (!said) |
2694 | { | |
3e43a32a MS |
2695 | fprintf_filtered (gdb_stdout, |
2696 | _("Note: automatically using " | |
2697 | "hardware breakpoints for " | |
2698 | "read-only addresses.\n")); | |
765dc015 VP |
2699 | said = 1; |
2700 | } | |
2701 | } | |
2702 | } | |
35df4500 | 2703 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2704 | && mr->attrib.mode != MEM_RW) |
2705 | { | |
2706 | fprintf_unfiltered (tmp_error_stream, | |
2707 | _("Cannot insert breakpoint %d.\n" | |
2708 | "Cannot set software breakpoint " | |
2709 | "at read-only address %s\n"), | |
2710 | bl->owner->number, | |
2711 | paddress (bl->gdbarch, bl->address)); | |
2712 | return 1; | |
2713 | } | |
765dc015 VP |
2714 | } |
2715 | } | |
2716 | ||
879bfdc2 DJ |
2717 | /* First check to see if we have to handle an overlay. */ |
2718 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2719 | || bl->section == NULL |
2720 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2721 | { |
2722 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2723 | TRY |
dd61ec5c | 2724 | { |
0000e5cc PA |
2725 | int val; |
2726 | ||
dd61ec5c | 2727 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2728 | if (val) |
2729 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2730 | } |
492d29ea | 2731 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2732 | { |
0000e5cc PA |
2733 | bp_err = e.error; |
2734 | bp_err_message = e.message; | |
dd61ec5c | 2735 | } |
492d29ea | 2736 | END_CATCH |
879bfdc2 DJ |
2737 | } |
2738 | else | |
2739 | { | |
4a64f543 | 2740 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2741 | Shall we set a breakpoint at the LMA? */ |
2742 | if (!overlay_events_enabled) | |
2743 | { | |
2744 | /* Yes -- overlay event support is not active, | |
2745 | so we must try to set a breakpoint at the LMA. | |
2746 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2747 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2748 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2749 | bl->owner->number); |
879bfdc2 DJ |
2750 | else |
2751 | { | |
35df4500 TJB |
2752 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2753 | bl->section); | |
879bfdc2 | 2754 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2755 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2756 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2757 | |
2758 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2759 | TRY |
0000e5cc PA |
2760 | { |
2761 | int val; | |
2762 | ||
579c6ad9 | 2763 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2764 | = breakpoint_kind (bl, &addr); |
2765 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2766 | val = target_insert_breakpoint (bl->gdbarch, |
2767 | &bl->overlay_target_info); | |
2768 | if (val) | |
2769 | bp_err = GENERIC_ERROR; | |
2770 | } | |
492d29ea | 2771 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2772 | { |
2773 | bp_err = e.error; | |
2774 | bp_err_message = e.message; | |
2775 | } | |
492d29ea | 2776 | END_CATCH |
0000e5cc PA |
2777 | |
2778 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2779 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2780 | "Overlay breakpoint %d " |
2781 | "failed: in ROM?\n", | |
35df4500 | 2782 | bl->owner->number); |
879bfdc2 DJ |
2783 | } |
2784 | } | |
2785 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2786 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2787 | { |
2788 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2789 | TRY |
dd61ec5c | 2790 | { |
0000e5cc PA |
2791 | int val; |
2792 | ||
dd61ec5c | 2793 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2794 | if (val) |
2795 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2796 | } |
492d29ea | 2797 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2798 | { |
0000e5cc PA |
2799 | bp_err = e.error; |
2800 | bp_err_message = e.message; | |
dd61ec5c | 2801 | } |
492d29ea | 2802 | END_CATCH |
879bfdc2 DJ |
2803 | } |
2804 | else | |
2805 | { | |
2806 | /* No. This breakpoint will not be inserted. | |
2807 | No error, but do not mark the bp as 'inserted'. */ | |
2808 | return 0; | |
2809 | } | |
2810 | } | |
2811 | ||
0000e5cc | 2812 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2813 | { |
2814 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2815 | |
2816 | /* In some cases, we might not be able to insert a | |
2817 | breakpoint in a shared library that has already been | |
2818 | removed, but we have not yet processed the shlib unload | |
2819 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2820 | breakpoint insertion themselves can't tell why the |
2821 | breakpoint insertion failed (e.g., the remote target | |
2822 | doesn't define error codes), so we must treat generic | |
2823 | errors as memory errors. */ | |
0000e5cc | 2824 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2825 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2826 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2827 | || shared_objfile_contains_address_p (bl->pspace, |
2828 | bl->address))) | |
879bfdc2 | 2829 | { |
4a64f543 | 2830 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2831 | bl->shlib_disabled = 1; |
8d3788bd | 2832 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2833 | if (!*disabled_breaks) |
2834 | { | |
2835 | fprintf_unfiltered (tmp_error_stream, | |
2836 | "Cannot insert breakpoint %d.\n", | |
2837 | bl->owner->number); | |
2838 | fprintf_unfiltered (tmp_error_stream, | |
2839 | "Temporarily disabling shared " | |
2840 | "library breakpoints:\n"); | |
2841 | } | |
2842 | *disabled_breaks = 1; | |
879bfdc2 | 2843 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2844 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2845 | return 0; |
879bfdc2 DJ |
2846 | } |
2847 | else | |
879bfdc2 | 2848 | { |
35df4500 | 2849 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2850 | { |
0000e5cc PA |
2851 | *hw_breakpoint_error = 1; |
2852 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2853 | fprintf_unfiltered (tmp_error_stream, |
2854 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2855 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2856 | if (bp_err_message != NULL) | |
2857 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2858 | } |
2859 | else | |
2860 | { | |
0000e5cc PA |
2861 | if (bp_err_message == NULL) |
2862 | { | |
2863 | char *message | |
2864 | = memory_error_message (TARGET_XFER_E_IO, | |
2865 | bl->gdbarch, bl->address); | |
2866 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2867 | ||
2868 | fprintf_unfiltered (tmp_error_stream, | |
2869 | "Cannot insert breakpoint %d.\n" | |
2870 | "%s\n", | |
2871 | bl->owner->number, message); | |
2872 | do_cleanups (old_chain); | |
2873 | } | |
2874 | else | |
2875 | { | |
2876 | fprintf_unfiltered (tmp_error_stream, | |
2877 | "Cannot insert breakpoint %d: %s\n", | |
2878 | bl->owner->number, | |
2879 | bp_err_message); | |
2880 | } | |
879bfdc2 | 2881 | } |
0000e5cc | 2882 | return 1; |
879bfdc2 DJ |
2883 | |
2884 | } | |
2885 | } | |
2886 | else | |
35df4500 | 2887 | bl->inserted = 1; |
879bfdc2 | 2888 | |
0000e5cc | 2889 | return 0; |
879bfdc2 DJ |
2890 | } |
2891 | ||
35df4500 | 2892 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2893 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2894 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2895 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2896 | { |
0000e5cc PA |
2897 | int val; |
2898 | ||
77b06cd7 TJB |
2899 | gdb_assert (bl->owner->ops != NULL |
2900 | && bl->owner->ops->insert_location != NULL); | |
2901 | ||
2902 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2903 | |
2904 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2905 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2906 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2907 | { |
2908 | struct bp_location *loc, **loc_temp; | |
2909 | ||
2910 | /* But don't try to insert it, if there's already another | |
2911 | hw_access location that would be considered a duplicate | |
2912 | of this one. */ | |
2913 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2914 | if (loc != bl |
85d721b8 | 2915 | && loc->watchpoint_type == hw_access |
35df4500 | 2916 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2917 | { |
35df4500 TJB |
2918 | bl->duplicate = 1; |
2919 | bl->inserted = 1; | |
2920 | bl->target_info = loc->target_info; | |
2921 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2922 | val = 0; |
2923 | break; | |
2924 | } | |
2925 | ||
2926 | if (val == 1) | |
2927 | { | |
77b06cd7 TJB |
2928 | bl->watchpoint_type = hw_access; |
2929 | val = bl->owner->ops->insert_location (bl); | |
2930 | ||
2931 | if (val) | |
2932 | /* Back to the original value. */ | |
2933 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2934 | } |
2935 | } | |
2936 | ||
35df4500 | 2937 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2938 | } |
2939 | ||
35df4500 | 2940 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2941 | { |
0000e5cc PA |
2942 | int val; |
2943 | ||
77b06cd7 TJB |
2944 | gdb_assert (bl->owner->ops != NULL |
2945 | && bl->owner->ops->insert_location != NULL); | |
2946 | ||
2947 | val = bl->owner->ops->insert_location (bl); | |
2948 | if (val) | |
2949 | { | |
2950 | bl->owner->enable_state = bp_disabled; | |
2951 | ||
2952 | if (val == 1) | |
2953 | warning (_("\ | |
2954 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2955 | of catchpoint."), bl->owner->number); | |
2956 | else | |
2957 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2958 | } | |
2959 | ||
2960 | bl->inserted = (val == 0); | |
1640b821 DJ |
2961 | |
2962 | /* We've already printed an error message if there was a problem | |
2963 | inserting this catchpoint, and we've disabled the catchpoint, | |
2964 | so just return success. */ | |
2965 | return 0; | |
879bfdc2 DJ |
2966 | } |
2967 | ||
2968 | return 0; | |
2969 | } | |
2970 | ||
6c95b8df PA |
2971 | /* This function is called when program space PSPACE is about to be |
2972 | deleted. It takes care of updating breakpoints to not reference | |
2973 | PSPACE anymore. */ | |
2974 | ||
2975 | void | |
2976 | breakpoint_program_space_exit (struct program_space *pspace) | |
2977 | { | |
2978 | struct breakpoint *b, *b_temp; | |
876fa593 | 2979 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2980 | |
2981 | /* Remove any breakpoint that was set through this program space. */ | |
2982 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2983 | { | |
2984 | if (b->pspace == pspace) | |
2985 | delete_breakpoint (b); | |
2986 | } | |
2987 | ||
2988 | /* Breakpoints set through other program spaces could have locations | |
2989 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2990 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2991 | { |
2992 | struct bp_location *tmp; | |
2993 | ||
2994 | if (loc->pspace == pspace) | |
2995 | { | |
2bdf28a0 | 2996 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2997 | if (loc->owner->loc == loc) |
2998 | loc->owner->loc = loc->next; | |
2999 | else | |
3000 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3001 | if (tmp->next == loc) | |
3002 | { | |
3003 | tmp->next = loc->next; | |
3004 | break; | |
3005 | } | |
3006 | } | |
3007 | } | |
3008 | ||
3009 | /* Now update the global location list to permanently delete the | |
3010 | removed locations above. */ | |
44702360 | 3011 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3012 | } |
3013 | ||
74960c60 VP |
3014 | /* Make sure all breakpoints are inserted in inferior. |
3015 | Throws exception on any error. | |
3016 | A breakpoint that is already inserted won't be inserted | |
3017 | again, so calling this function twice is safe. */ | |
3018 | void | |
3019 | insert_breakpoints (void) | |
3020 | { | |
3021 | struct breakpoint *bpt; | |
3022 | ||
3023 | ALL_BREAKPOINTS (bpt) | |
3024 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3025 | { |
3026 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3027 | ||
3028 | update_watchpoint (w, 0 /* don't reparse. */); | |
3029 | } | |
74960c60 | 3030 | |
04086b45 PA |
3031 | /* Updating watchpoints creates new locations, so update the global |
3032 | location list. Explicitly tell ugll to insert locations and | |
3033 | ignore breakpoints_always_inserted_mode. */ | |
3034 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3035 | } |
3036 | ||
20388dd6 YQ |
3037 | /* Invoke CALLBACK for each of bp_location. */ |
3038 | ||
3039 | void | |
3040 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3041 | { | |
3042 | struct bp_location *loc, **loc_tmp; | |
3043 | ||
3044 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3045 | { | |
3046 | callback (loc, NULL); | |
3047 | } | |
3048 | } | |
3049 | ||
b775012e LM |
3050 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3051 | target. It is the case with deleting and disabling of breakpoints when using | |
3052 | always-inserted mode. */ | |
3053 | ||
3054 | static void | |
3055 | update_inserted_breakpoint_locations (void) | |
3056 | { | |
3057 | struct bp_location *bl, **blp_tmp; | |
3058 | int error_flag = 0; | |
3059 | int val = 0; | |
3060 | int disabled_breaks = 0; | |
3061 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3062 | int hw_bp_details_reported = 0; |
b775012e | 3063 | |
d7e74731 | 3064 | string_file tmp_error_stream; |
b775012e LM |
3065 | |
3066 | /* Explicitly mark the warning -- this will only be printed if | |
3067 | there was an error. */ | |
d7e74731 | 3068 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3069 | |
d7e74731 | 3070 | struct cleanup *cleanups = save_current_space_and_thread (); |
b775012e LM |
3071 | |
3072 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3073 | { | |
3074 | /* We only want to update software breakpoints and hardware | |
3075 | breakpoints. */ | |
3076 | if (!is_breakpoint (bl->owner)) | |
3077 | continue; | |
3078 | ||
3079 | /* We only want to update locations that are already inserted | |
3080 | and need updating. This is to avoid unwanted insertion during | |
3081 | deletion of breakpoints. */ | |
3082 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3083 | continue; | |
3084 | ||
3085 | switch_to_program_space_and_thread (bl->pspace); | |
3086 | ||
3087 | /* For targets that support global breakpoints, there's no need | |
3088 | to select an inferior to insert breakpoint to. In fact, even | |
3089 | if we aren't attached to any process yet, we should still | |
3090 | insert breakpoints. */ | |
f5656ead | 3091 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3092 | && ptid_equal (inferior_ptid, null_ptid)) |
3093 | continue; | |
3094 | ||
d7e74731 | 3095 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3096 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3097 | if (val) |
3098 | error_flag = val; | |
3099 | } | |
3100 | ||
3101 | if (error_flag) | |
3102 | { | |
3103 | target_terminal_ours_for_output (); | |
3104 | error_stream (tmp_error_stream); | |
3105 | } | |
3106 | ||
3107 | do_cleanups (cleanups); | |
3108 | } | |
3109 | ||
c30eee59 | 3110 | /* Used when starting or continuing the program. */ |
c906108c | 3111 | |
74960c60 VP |
3112 | static void |
3113 | insert_breakpoint_locations (void) | |
c906108c | 3114 | { |
a5606eee | 3115 | struct breakpoint *bpt; |
35df4500 | 3116 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3117 | int error_flag = 0; |
c906108c | 3118 | int val = 0; |
3fbb6ffa | 3119 | int disabled_breaks = 0; |
81d0cc19 | 3120 | int hw_breakpoint_error = 0; |
dd61ec5c | 3121 | int hw_bp_error_explained_already = 0; |
c906108c | 3122 | |
d7e74731 PA |
3123 | string_file tmp_error_stream; |
3124 | ||
81d0cc19 GS |
3125 | /* Explicitly mark the warning -- this will only be printed if |
3126 | there was an error. */ | |
d7e74731 | 3127 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3128 | |
d7e74731 | 3129 | struct cleanup *cleanups = save_current_space_and_thread (); |
6c95b8df | 3130 | |
35df4500 | 3131 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3132 | { |
b775012e | 3133 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3134 | continue; |
3135 | ||
4a64f543 MS |
3136 | /* There is no point inserting thread-specific breakpoints if |
3137 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3138 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3139 | if (bl->owner->thread != -1 |
5d5658a1 | 3140 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3141 | continue; |
3142 | ||
35df4500 | 3143 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3144 | |
3145 | /* For targets that support global breakpoints, there's no need | |
3146 | to select an inferior to insert breakpoint to. In fact, even | |
3147 | if we aren't attached to any process yet, we should still | |
3148 | insert breakpoints. */ | |
f5656ead | 3149 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3150 | && ptid_equal (inferior_ptid, null_ptid)) |
3151 | continue; | |
3152 | ||
d7e74731 | 3153 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3154 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3155 | if (val) |
eacd795a | 3156 | error_flag = val; |
879bfdc2 | 3157 | } |
c906108c | 3158 | |
4a64f543 MS |
3159 | /* If we failed to insert all locations of a watchpoint, remove |
3160 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3161 | ALL_BREAKPOINTS (bpt) |
3162 | { | |
3163 | int some_failed = 0; | |
3164 | struct bp_location *loc; | |
3165 | ||
3166 | if (!is_hardware_watchpoint (bpt)) | |
3167 | continue; | |
3168 | ||
d6b74ac4 | 3169 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3170 | continue; |
74960c60 VP |
3171 | |
3172 | if (bpt->disposition == disp_del_at_next_stop) | |
3173 | continue; | |
a5606eee VP |
3174 | |
3175 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3176 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3177 | { |
3178 | some_failed = 1; | |
3179 | break; | |
3180 | } | |
3181 | if (some_failed) | |
3182 | { | |
3183 | for (loc = bpt->loc; loc; loc = loc->next) | |
3184 | if (loc->inserted) | |
834c0d03 | 3185 | remove_breakpoint (loc); |
a5606eee VP |
3186 | |
3187 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3188 | tmp_error_stream.printf ("Could not insert " |
3189 | "hardware watchpoint %d.\n", | |
3190 | bpt->number); | |
eacd795a | 3191 | error_flag = -1; |
a5606eee VP |
3192 | } |
3193 | } | |
3194 | ||
eacd795a | 3195 | if (error_flag) |
81d0cc19 GS |
3196 | { |
3197 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3198 | message about possibly exhausted resources. */ | |
dd61ec5c | 3199 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3200 | { |
d7e74731 | 3201 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3202 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3203 | } |
81d0cc19 GS |
3204 | target_terminal_ours_for_output (); |
3205 | error_stream (tmp_error_stream); | |
3206 | } | |
f7545552 TT |
3207 | |
3208 | do_cleanups (cleanups); | |
c906108c SS |
3209 | } |
3210 | ||
c30eee59 TJB |
3211 | /* Used when the program stops. |
3212 | Returns zero if successful, or non-zero if there was a problem | |
3213 | removing a breakpoint location. */ | |
3214 | ||
c906108c | 3215 | int |
fba45db2 | 3216 | remove_breakpoints (void) |
c906108c | 3217 | { |
35df4500 | 3218 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3219 | int val = 0; |
c906108c | 3220 | |
35df4500 | 3221 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3222 | { |
1e4d1764 | 3223 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3224 | val |= remove_breakpoint (bl); |
c5aa993b | 3225 | } |
3a1bae8e | 3226 | return val; |
c906108c SS |
3227 | } |
3228 | ||
49fa26b0 PA |
3229 | /* When a thread exits, remove breakpoints that are related to |
3230 | that thread. */ | |
3231 | ||
3232 | static void | |
3233 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3234 | { | |
3235 | struct breakpoint *b, *b_tmp; | |
3236 | ||
3237 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3238 | { | |
5d5658a1 | 3239 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3240 | { |
3241 | b->disposition = disp_del_at_next_stop; | |
3242 | ||
3243 | printf_filtered (_("\ | |
43792cf0 PA |
3244 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3245 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3246 | |
3247 | /* Hide it from the user. */ | |
3248 | b->number = 0; | |
3249 | } | |
3250 | } | |
3251 | } | |
3252 | ||
6c95b8df PA |
3253 | /* Remove breakpoints of process PID. */ |
3254 | ||
3255 | int | |
3256 | remove_breakpoints_pid (int pid) | |
3257 | { | |
35df4500 | 3258 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3259 | int val; |
3260 | struct inferior *inf = find_inferior_pid (pid); | |
3261 | ||
35df4500 | 3262 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3263 | { |
35df4500 | 3264 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3265 | continue; |
3266 | ||
fc126975 | 3267 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3268 | { |
834c0d03 | 3269 | val = remove_breakpoint (bl); |
6c95b8df PA |
3270 | if (val != 0) |
3271 | return val; | |
3272 | } | |
3273 | } | |
3274 | return 0; | |
3275 | } | |
3276 | ||
c906108c | 3277 | int |
fba45db2 | 3278 | reattach_breakpoints (int pid) |
c906108c | 3279 | { |
6c95b8df | 3280 | struct cleanup *old_chain; |
35df4500 | 3281 | struct bp_location *bl, **blp_tmp; |
c906108c | 3282 | int val; |
dd61ec5c | 3283 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3284 | struct inferior *inf; |
3285 | struct thread_info *tp; | |
3286 | ||
3287 | tp = any_live_thread_of_process (pid); | |
3288 | if (tp == NULL) | |
3289 | return 1; | |
3290 | ||
3291 | inf = find_inferior_pid (pid); | |
3292 | old_chain = save_inferior_ptid (); | |
3293 | ||
3294 | inferior_ptid = tp->ptid; | |
a4954f26 | 3295 | |
d7e74731 | 3296 | string_file tmp_error_stream; |
c906108c | 3297 | |
35df4500 | 3298 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3299 | { |
35df4500 | 3300 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3301 | continue; |
3302 | ||
35df4500 | 3303 | if (bl->inserted) |
c5aa993b | 3304 | { |
35df4500 | 3305 | bl->inserted = 0; |
d7e74731 | 3306 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3307 | if (val != 0) |
3308 | { | |
ce696e05 | 3309 | do_cleanups (old_chain); |
c5aa993b JM |
3310 | return val; |
3311 | } | |
3312 | } | |
3313 | } | |
ce696e05 | 3314 | do_cleanups (old_chain); |
c906108c SS |
3315 | return 0; |
3316 | } | |
3317 | ||
e58b0e63 PA |
3318 | static int internal_breakpoint_number = -1; |
3319 | ||
84f4c1fe PM |
3320 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3321 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3322 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3323 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3324 | breakpoint_count and that value incremented. Internal breakpoints |
3325 | do not set the internal var bpnum. */ | |
3326 | static void | |
3327 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3328 | { | |
3329 | if (internal) | |
3330 | b->number = internal_breakpoint_number--; | |
3331 | else | |
3332 | { | |
3333 | set_breakpoint_count (breakpoint_count + 1); | |
3334 | b->number = breakpoint_count; | |
3335 | } | |
3336 | } | |
3337 | ||
e62c965a | 3338 | static struct breakpoint * |
a6d9a66e | 3339 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3340 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3341 | const struct breakpoint_ops *ops) |
e62c965a | 3342 | { |
e62c965a PP |
3343 | struct symtab_and_line sal; |
3344 | struct breakpoint *b; | |
3345 | ||
4a64f543 | 3346 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3347 | |
3348 | sal.pc = address; | |
3349 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3350 | sal.pspace = current_program_space; |
e62c965a | 3351 | |
06edf0c0 | 3352 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3353 | b->number = internal_breakpoint_number--; |
3354 | b->disposition = disp_donttouch; | |
3355 | ||
3356 | return b; | |
3357 | } | |
3358 | ||
17450429 PP |
3359 | static const char *const longjmp_names[] = |
3360 | { | |
3361 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3362 | }; | |
3363 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3364 | ||
3365 | /* Per-objfile data private to breakpoint.c. */ | |
3366 | struct breakpoint_objfile_data | |
3367 | { | |
3368 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3369 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3370 | |
3371 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3372 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3373 | |
28106bc2 SDJ |
3374 | /* True if we have looked for longjmp probes. */ |
3375 | int longjmp_searched; | |
3376 | ||
3377 | /* SystemTap probe points for longjmp (if any). */ | |
3378 | VEC (probe_p) *longjmp_probes; | |
3379 | ||
17450429 | 3380 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3381 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3382 | |
3383 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3384 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3385 | |
3386 | /* True if we have looked for exception probes. */ | |
3387 | int exception_searched; | |
3388 | ||
3389 | /* SystemTap probe points for unwinding (if any). */ | |
3390 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3391 | }; |
3392 | ||
3393 | static const struct objfile_data *breakpoint_objfile_key; | |
3394 | ||
3395 | /* Minimal symbol not found sentinel. */ | |
3396 | static struct minimal_symbol msym_not_found; | |
3397 | ||
3398 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3399 | ||
3400 | static int | |
3401 | msym_not_found_p (const struct minimal_symbol *msym) | |
3402 | { | |
3403 | return msym == &msym_not_found; | |
3404 | } | |
3405 | ||
3406 | /* Return per-objfile data needed by breakpoint.c. | |
3407 | Allocate the data if necessary. */ | |
3408 | ||
3409 | static struct breakpoint_objfile_data * | |
3410 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3411 | { | |
3412 | struct breakpoint_objfile_data *bp_objfile_data; | |
3413 | ||
9a3c8263 SM |
3414 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3415 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3416 | if (bp_objfile_data == NULL) |
3417 | { | |
8d749320 SM |
3418 | bp_objfile_data = |
3419 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3420 | |
3421 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3422 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3423 | } | |
3424 | return bp_objfile_data; | |
3425 | } | |
3426 | ||
28106bc2 SDJ |
3427 | static void |
3428 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3429 | { | |
9a3c8263 SM |
3430 | struct breakpoint_objfile_data *bp_objfile_data |
3431 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3432 | |
3433 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3434 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3435 | } | |
3436 | ||
e62c965a | 3437 | static void |
af02033e | 3438 | create_overlay_event_breakpoint (void) |
e62c965a | 3439 | { |
69de3c6a | 3440 | struct objfile *objfile; |
af02033e | 3441 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3442 | |
69de3c6a PP |
3443 | ALL_OBJFILES (objfile) |
3444 | { | |
3445 | struct breakpoint *b; | |
17450429 PP |
3446 | struct breakpoint_objfile_data *bp_objfile_data; |
3447 | CORE_ADDR addr; | |
67994074 | 3448 | struct explicit_location explicit_loc; |
69de3c6a | 3449 | |
17450429 PP |
3450 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3451 | ||
3b7344d5 | 3452 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3453 | continue; |
3454 | ||
3b7344d5 | 3455 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3456 | { |
3b7344d5 | 3457 | struct bound_minimal_symbol m; |
17450429 PP |
3458 | |
3459 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3460 | if (m.minsym == NULL) |
17450429 PP |
3461 | { |
3462 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3463 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3464 | continue; |
3465 | } | |
3466 | bp_objfile_data->overlay_msym = m; | |
3467 | } | |
e62c965a | 3468 | |
77e371c0 | 3469 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3470 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3471 | bp_overlay_event, |
3472 | &internal_breakpoint_ops); | |
67994074 KS |
3473 | initialize_explicit_location (&explicit_loc); |
3474 | explicit_loc.function_name = ASTRDUP (func_name); | |
ffc2605c | 3475 | b->location = new_explicit_location (&explicit_loc).release (); |
e62c965a | 3476 | |
69de3c6a PP |
3477 | if (overlay_debugging == ovly_auto) |
3478 | { | |
3479 | b->enable_state = bp_enabled; | |
3480 | overlay_events_enabled = 1; | |
3481 | } | |
3482 | else | |
3483 | { | |
3484 | b->enable_state = bp_disabled; | |
3485 | overlay_events_enabled = 0; | |
3486 | } | |
e62c965a | 3487 | } |
e62c965a PP |
3488 | } |
3489 | ||
0fd8e87f | 3490 | static void |
af02033e | 3491 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3492 | { |
6c95b8df | 3493 | struct program_space *pspace; |
6c95b8df PA |
3494 | struct cleanup *old_chain; |
3495 | ||
3496 | old_chain = save_current_program_space (); | |
0fd8e87f | 3497 | |
6c95b8df | 3498 | ALL_PSPACES (pspace) |
af02033e PP |
3499 | { |
3500 | struct objfile *objfile; | |
3501 | ||
3502 | set_current_program_space (pspace); | |
3503 | ||
3504 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3505 | { |
af02033e PP |
3506 | int i; |
3507 | struct gdbarch *gdbarch; | |
17450429 | 3508 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3509 | |
af02033e | 3510 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3511 | |
17450429 PP |
3512 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3513 | ||
28106bc2 SDJ |
3514 | if (!bp_objfile_data->longjmp_searched) |
3515 | { | |
25f9533e SDJ |
3516 | VEC (probe_p) *ret; |
3517 | ||
3518 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3519 | if (ret != NULL) | |
3520 | { | |
3521 | /* We are only interested in checking one element. */ | |
3522 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3523 | ||
3524 | if (!can_evaluate_probe_arguments (p)) | |
3525 | { | |
3526 | /* We cannot use the probe interface here, because it does | |
3527 | not know how to evaluate arguments. */ | |
3528 | VEC_free (probe_p, ret); | |
3529 | ret = NULL; | |
3530 | } | |
3531 | } | |
3532 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3533 | bp_objfile_data->longjmp_searched = 1; |
3534 | } | |
3535 | ||
3536 | if (bp_objfile_data->longjmp_probes != NULL) | |
3537 | { | |
3538 | int i; | |
3539 | struct probe *probe; | |
3540 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3541 | ||
3542 | for (i = 0; | |
3543 | VEC_iterate (probe_p, | |
3544 | bp_objfile_data->longjmp_probes, | |
3545 | i, probe); | |
3546 | ++i) | |
3547 | { | |
3548 | struct breakpoint *b; | |
3549 | ||
729662a5 TT |
3550 | b = create_internal_breakpoint (gdbarch, |
3551 | get_probe_address (probe, | |
3552 | objfile), | |
28106bc2 SDJ |
3553 | bp_longjmp_master, |
3554 | &internal_breakpoint_ops); | |
5b56227b | 3555 | b->location |
ffc2605c | 3556 | = new_probe_location ("-probe-stap libc:longjmp").release (); |
28106bc2 SDJ |
3557 | b->enable_state = bp_disabled; |
3558 | } | |
3559 | ||
3560 | continue; | |
3561 | } | |
3562 | ||
0569175e TSD |
3563 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3564 | continue; | |
3565 | ||
17450429 | 3566 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3567 | { |
3568 | struct breakpoint *b; | |
af02033e | 3569 | const char *func_name; |
17450429 | 3570 | CORE_ADDR addr; |
67994074 | 3571 | struct explicit_location explicit_loc; |
6c95b8df | 3572 | |
3b7344d5 | 3573 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3574 | continue; |
0fd8e87f | 3575 | |
17450429 | 3576 | func_name = longjmp_names[i]; |
3b7344d5 | 3577 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3578 | { |
3b7344d5 | 3579 | struct bound_minimal_symbol m; |
17450429 PP |
3580 | |
3581 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3582 | if (m.minsym == NULL) |
17450429 PP |
3583 | { |
3584 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3585 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3586 | continue; |
3587 | } | |
3588 | bp_objfile_data->longjmp_msym[i] = m; | |
3589 | } | |
3590 | ||
77e371c0 | 3591 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3592 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3593 | &internal_breakpoint_ops); | |
67994074 KS |
3594 | initialize_explicit_location (&explicit_loc); |
3595 | explicit_loc.function_name = ASTRDUP (func_name); | |
ffc2605c | 3596 | b->location = new_explicit_location (&explicit_loc).release (); |
af02033e PP |
3597 | b->enable_state = bp_disabled; |
3598 | } | |
0fd8e87f | 3599 | } |
af02033e | 3600 | } |
6c95b8df PA |
3601 | |
3602 | do_cleanups (old_chain); | |
0fd8e87f UW |
3603 | } |
3604 | ||
af02033e | 3605 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3606 | static void |
af02033e | 3607 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3608 | { |
3609 | struct program_space *pspace; | |
aa7d318d | 3610 | struct cleanup *old_chain; |
af02033e | 3611 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3612 | |
3613 | old_chain = save_current_program_space (); | |
3614 | ||
3615 | ALL_PSPACES (pspace) | |
17450429 PP |
3616 | { |
3617 | struct objfile *objfile; | |
3618 | CORE_ADDR addr; | |
3619 | ||
3620 | set_current_program_space (pspace); | |
3621 | ||
aa7d318d TT |
3622 | ALL_OBJFILES (objfile) |
3623 | { | |
3624 | struct breakpoint *b; | |
17450429 | 3625 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3626 | struct explicit_location explicit_loc; |
aa7d318d | 3627 | |
17450429 | 3628 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3629 | |
3b7344d5 | 3630 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3631 | continue; |
3632 | ||
3b7344d5 | 3633 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3634 | { |
3b7344d5 | 3635 | struct bound_minimal_symbol m; |
17450429 PP |
3636 | |
3637 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3638 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3639 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3640 | { |
3641 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3642 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3643 | continue; |
3644 | } | |
3645 | bp_objfile_data->terminate_msym = m; | |
3646 | } | |
aa7d318d | 3647 | |
77e371c0 | 3648 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3649 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3650 | bp_std_terminate_master, |
3651 | &internal_breakpoint_ops); | |
67994074 KS |
3652 | initialize_explicit_location (&explicit_loc); |
3653 | explicit_loc.function_name = ASTRDUP (func_name); | |
ffc2605c | 3654 | b->location = new_explicit_location (&explicit_loc).release (); |
aa7d318d TT |
3655 | b->enable_state = bp_disabled; |
3656 | } | |
17450429 PP |
3657 | } |
3658 | ||
aa7d318d TT |
3659 | do_cleanups (old_chain); |
3660 | } | |
3661 | ||
186c406b TT |
3662 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3663 | ||
70221824 | 3664 | static void |
186c406b TT |
3665 | create_exception_master_breakpoint (void) |
3666 | { | |
3667 | struct objfile *objfile; | |
17450429 | 3668 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3669 | |
3670 | ALL_OBJFILES (objfile) | |
3671 | { | |
17450429 PP |
3672 | struct breakpoint *b; |
3673 | struct gdbarch *gdbarch; | |
3674 | struct breakpoint_objfile_data *bp_objfile_data; | |
3675 | CORE_ADDR addr; | |
67994074 | 3676 | struct explicit_location explicit_loc; |
17450429 PP |
3677 | |
3678 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3679 | ||
28106bc2 SDJ |
3680 | /* We prefer the SystemTap probe point if it exists. */ |
3681 | if (!bp_objfile_data->exception_searched) | |
3682 | { | |
25f9533e SDJ |
3683 | VEC (probe_p) *ret; |
3684 | ||
3685 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3686 | ||
3687 | if (ret != NULL) | |
3688 | { | |
3689 | /* We are only interested in checking one element. */ | |
3690 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3691 | ||
3692 | if (!can_evaluate_probe_arguments (p)) | |
3693 | { | |
3694 | /* We cannot use the probe interface here, because it does | |
3695 | not know how to evaluate arguments. */ | |
3696 | VEC_free (probe_p, ret); | |
3697 | ret = NULL; | |
3698 | } | |
3699 | } | |
3700 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3701 | bp_objfile_data->exception_searched = 1; |
3702 | } | |
3703 | ||
3704 | if (bp_objfile_data->exception_probes != NULL) | |
3705 | { | |
3706 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3707 | int i; | |
3708 | struct probe *probe; | |
3709 | ||
3710 | for (i = 0; | |
3711 | VEC_iterate (probe_p, | |
3712 | bp_objfile_data->exception_probes, | |
3713 | i, probe); | |
3714 | ++i) | |
3715 | { | |
3716 | struct breakpoint *b; | |
3717 | ||
729662a5 TT |
3718 | b = create_internal_breakpoint (gdbarch, |
3719 | get_probe_address (probe, | |
3720 | objfile), | |
28106bc2 SDJ |
3721 | bp_exception_master, |
3722 | &internal_breakpoint_ops); | |
5b56227b | 3723 | b->location |
ffc2605c | 3724 | = new_probe_location ("-probe-stap libgcc:unwind").release (); |
28106bc2 SDJ |
3725 | b->enable_state = bp_disabled; |
3726 | } | |
3727 | ||
3728 | continue; | |
3729 | } | |
3730 | ||
3731 | /* Otherwise, try the hook function. */ | |
3732 | ||
3b7344d5 | 3733 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3734 | continue; |
3735 | ||
3736 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3737 | |
3b7344d5 | 3738 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3739 | { |
3b7344d5 | 3740 | struct bound_minimal_symbol debug_hook; |
186c406b | 3741 | |
17450429 | 3742 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3743 | if (debug_hook.minsym == NULL) |
17450429 | 3744 | { |
3b7344d5 | 3745 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3746 | continue; |
3747 | } | |
3748 | ||
3749 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3750 | } |
17450429 | 3751 | |
77e371c0 | 3752 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3753 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3754 | ¤t_target); | |
06edf0c0 PA |
3755 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3756 | &internal_breakpoint_ops); | |
67994074 KS |
3757 | initialize_explicit_location (&explicit_loc); |
3758 | explicit_loc.function_name = ASTRDUP (func_name); | |
ffc2605c | 3759 | b->location = new_explicit_location (&explicit_loc).release (); |
17450429 | 3760 | b->enable_state = bp_disabled; |
186c406b | 3761 | } |
186c406b TT |
3762 | } |
3763 | ||
9ef9e6a6 KS |
3764 | /* Does B have a location spec? */ |
3765 | ||
3766 | static int | |
3767 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3768 | { | |
3769 | return b->location != NULL && event_location_empty_p (b->location); | |
3770 | } | |
3771 | ||
c906108c | 3772 | void |
fba45db2 | 3773 | update_breakpoints_after_exec (void) |
c906108c | 3774 | { |
35df4500 | 3775 | struct breakpoint *b, *b_tmp; |
876fa593 | 3776 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3777 | |
25b22b0a PA |
3778 | /* We're about to delete breakpoints from GDB's lists. If the |
3779 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3780 | writing the breakpoints' "shadow contents" back into memory. The | |
3781 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3782 | do that. Instead, the target is responsible from marking | |
3783 | breakpoints out as soon as it detects an exec. We don't do that | |
3784 | here instead, because there may be other attempts to delete | |
3785 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3786 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3787 | if (bploc->pspace == current_program_space) |
3788 | gdb_assert (!bploc->inserted); | |
c906108c | 3789 | |
35df4500 | 3790 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3791 | { |
6c95b8df PA |
3792 | if (b->pspace != current_program_space) |
3793 | continue; | |
3794 | ||
4a64f543 | 3795 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3796 | if (b->type == bp_shlib_event) |
3797 | { | |
3798 | delete_breakpoint (b); | |
3799 | continue; | |
3800 | } | |
c906108c | 3801 | |
4a64f543 | 3802 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3803 | if (b->type == bp_jit_event) |
3804 | { | |
3805 | delete_breakpoint (b); | |
3806 | continue; | |
3807 | } | |
3808 | ||
1900040c | 3809 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3810 | as must overlay event and longjmp master breakpoints. */ |
3811 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3812 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3813 | || b->type == bp_exception_master) | |
c4093a6a JM |
3814 | { |
3815 | delete_breakpoint (b); | |
3816 | continue; | |
3817 | } | |
3818 | ||
4a64f543 | 3819 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3820 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3821 | { |
3822 | delete_breakpoint (b); | |
3823 | continue; | |
3824 | } | |
3825 | ||
7c16b83e PA |
3826 | /* Just like single-step breakpoints. */ |
3827 | if (b->type == bp_single_step) | |
3828 | { | |
3829 | delete_breakpoint (b); | |
3830 | continue; | |
3831 | } | |
3832 | ||
611c83ae PA |
3833 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3834 | after an exec. */ | |
186c406b | 3835 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3836 | || b->type == bp_longjmp_call_dummy |
186c406b | 3837 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3838 | { |
3839 | delete_breakpoint (b); | |
3840 | continue; | |
3841 | } | |
3842 | ||
ce78b96d JB |
3843 | if (b->type == bp_catchpoint) |
3844 | { | |
3845 | /* For now, none of the bp_catchpoint breakpoints need to | |
3846 | do anything at this point. In the future, if some of | |
3847 | the catchpoints need to something, we will need to add | |
3848 | a new method, and call this method from here. */ | |
3849 | continue; | |
3850 | } | |
3851 | ||
c5aa993b JM |
3852 | /* bp_finish is a special case. The only way we ought to be able |
3853 | to see one of these when an exec() has happened, is if the user | |
3854 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3855 | carries them to the call-site of the current callee, by setting | |
3856 | a temporary bp there and resuming. But in this case, the finish | |
3857 | will carry them entirely through the vfork & exec. | |
3858 | ||
3859 | We don't want to allow a bp_finish to remain inserted now. But | |
3860 | we can't safely delete it, 'cause finish_command has a handle to | |
3861 | the bp on a bpstat, and will later want to delete it. There's a | |
3862 | chance (and I've seen it happen) that if we delete the bp_finish | |
3863 | here, that its storage will get reused by the time finish_command | |
3864 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3865 | We really must allow finish_command to delete a bp_finish. | |
3866 | ||
e5dd4106 | 3867 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3868 | it's safe to delete something others may have handles to?" |
3869 | problem, what we'll do here is just uninsert the bp_finish, and | |
3870 | let finish_command delete it. | |
3871 | ||
3872 | (We know the bp_finish is "doomed" in the sense that it's | |
3873 | momentary, and will be deleted as soon as finish_command sees | |
3874 | the inferior stopped. So it doesn't matter that the bp's | |
3875 | address is probably bogus in the new a.out, unlike e.g., the | |
3876 | solib breakpoints.) */ | |
c5aa993b | 3877 | |
c5aa993b JM |
3878 | if (b->type == bp_finish) |
3879 | { | |
3880 | continue; | |
3881 | } | |
3882 | ||
3883 | /* Without a symbolic address, we have little hope of the | |
3884 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3885 | a.out. */ |
9ef9e6a6 | 3886 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3887 | { |
3888 | delete_breakpoint (b); | |
3889 | continue; | |
3890 | } | |
c5aa993b | 3891 | } |
c906108c SS |
3892 | } |
3893 | ||
3894 | int | |
d80ee84f | 3895 | detach_breakpoints (ptid_t ptid) |
c906108c | 3896 | { |
35df4500 | 3897 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3898 | int val = 0; |
ce696e05 | 3899 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3900 | struct inferior *inf = current_inferior (); |
c5aa993b | 3901 | |
dfd4cc63 | 3902 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3903 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3904 | |
6c95b8df | 3905 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3906 | inferior_ptid = ptid; |
35df4500 | 3907 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3908 | { |
35df4500 | 3909 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3910 | continue; |
3911 | ||
bd9673a4 PW |
3912 | /* This function must physically remove breakpoints locations |
3913 | from the specified ptid, without modifying the breakpoint | |
3914 | package's state. Locations of type bp_loc_other are only | |
3915 | maintained at GDB side. So, there is no need to remove | |
3916 | these bp_loc_other locations. Moreover, removing these | |
3917 | would modify the breakpoint package's state. */ | |
3918 | if (bl->loc_type == bp_loc_other) | |
3919 | continue; | |
3920 | ||
35df4500 | 3921 | if (bl->inserted) |
b2b6a7da | 3922 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3923 | } |
d03285ec | 3924 | |
ce696e05 | 3925 | do_cleanups (old_chain); |
3a1bae8e | 3926 | return val; |
c906108c SS |
3927 | } |
3928 | ||
35df4500 | 3929 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3930 | Note that this is used to detach breakpoints from a child fork. |
3931 | When we get here, the child isn't in the inferior list, and neither | |
3932 | do we have objects to represent its address space --- we should | |
35df4500 | 3933 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3934 | |
c906108c | 3935 | static int |
b2b6a7da | 3936 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3937 | { |
3938 | int val; | |
c5aa993b | 3939 | |
35df4500 TJB |
3940 | /* BL is never in moribund_locations by our callers. */ |
3941 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3942 | |
74960c60 VP |
3943 | /* The type of none suggests that owner is actually deleted. |
3944 | This should not ever happen. */ | |
35df4500 | 3945 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3946 | |
35df4500 TJB |
3947 | if (bl->loc_type == bp_loc_software_breakpoint |
3948 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3949 | { |
c02f5703 MS |
3950 | /* "Normal" instruction breakpoint: either the standard |
3951 | trap-instruction bp (bp_breakpoint), or a | |
3952 | bp_hardware_breakpoint. */ | |
3953 | ||
3954 | /* First check to see if we have to handle an overlay. */ | |
3955 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3956 | || bl->section == NULL |
3957 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3958 | { |
3959 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3960 | |
3961 | /* If we're trying to uninsert a memory breakpoint that we | |
3962 | know is set in a dynamic object that is marked | |
3963 | shlib_disabled, then either the dynamic object was | |
3964 | removed with "remove-symbol-file" or with | |
3965 | "nosharedlibrary". In the former case, we don't know | |
3966 | whether another dynamic object might have loaded over the | |
3967 | breakpoint's address -- the user might well let us know | |
3968 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3969 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3970 | list of dynamically loaded objects). If we have the |
3971 | breakpoint's shadow memory, that is, this is a software | |
3972 | breakpoint managed by GDB, check whether the breakpoint | |
3973 | is still inserted in memory, to avoid overwriting wrong | |
3974 | code with stale saved shadow contents. Note that HW | |
3975 | breakpoints don't have shadow memory, as they're | |
3976 | implemented using a mechanism that is not dependent on | |
3977 | being able to modify the target's memory, and as such | |
3978 | they should always be removed. */ | |
3979 | if (bl->shlib_disabled | |
3980 | && bl->target_info.shadow_len != 0 | |
3981 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3982 | val = 0; | |
3983 | else | |
73971819 | 3984 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3985 | } |
c906108c SS |
3986 | else |
3987 | { | |
4a64f543 | 3988 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3989 | Did we set a breakpoint at the LMA? */ |
3990 | if (!overlay_events_enabled) | |
3991 | { | |
3992 | /* Yes -- overlay event support is not active, so we | |
3993 | should have set a breakpoint at the LMA. Remove it. | |
3994 | */ | |
c02f5703 MS |
3995 | /* Ignore any failures: if the LMA is in ROM, we will |
3996 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3997 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3998 | target_remove_hw_breakpoint (bl->gdbarch, | |
3999 | &bl->overlay_target_info); | |
c02f5703 | 4000 | else |
35df4500 | 4001 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4002 | &bl->overlay_target_info, |
4003 | reason); | |
c02f5703 MS |
4004 | } |
4005 | /* Did we set a breakpoint at the VMA? | |
4006 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4007 | if (bl->inserted) |
c906108c | 4008 | { |
c02f5703 MS |
4009 | /* Yes -- remove it. Previously we did not bother to |
4010 | remove the breakpoint if the section had been | |
4011 | unmapped, but let's not rely on that being safe. We | |
4012 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4013 | |
4014 | /* However, we should remove *software* breakpoints only | |
4015 | if the section is still mapped, or else we overwrite | |
4016 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4017 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4018 | || section_is_mapped (bl->section)) | |
73971819 | 4019 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4020 | else |
4021 | val = 0; | |
c906108c | 4022 | } |
c02f5703 MS |
4023 | else |
4024 | { | |
4025 | /* No -- not inserted, so no need to remove. No error. */ | |
4026 | val = 0; | |
4027 | } | |
c906108c | 4028 | } |
879d1e6b | 4029 | |
08351840 PA |
4030 | /* In some cases, we might not be able to remove a breakpoint in |
4031 | a shared library that has already been removed, but we have | |
4032 | not yet processed the shlib unload event. Similarly for an | |
4033 | unloaded add-symbol-file object - the user might not yet have | |
4034 | had the chance to remove-symbol-file it. shlib_disabled will | |
4035 | be set if the library/object has already been removed, but | |
4036 | the breakpoint hasn't been uninserted yet, e.g., after | |
4037 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4038 | always-inserted mode. */ | |
076855f9 | 4039 | if (val |
08351840 PA |
4040 | && (bl->loc_type == bp_loc_software_breakpoint |
4041 | && (bl->shlib_disabled | |
4042 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4043 | || shared_objfile_contains_address_p (bl->pspace, |
4044 | bl->address)))) | |
879d1e6b UW |
4045 | val = 0; |
4046 | ||
c906108c SS |
4047 | if (val) |
4048 | return val; | |
b2b6a7da | 4049 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4050 | } |
35df4500 | 4051 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4052 | { |
77b06cd7 TJB |
4053 | gdb_assert (bl->owner->ops != NULL |
4054 | && bl->owner->ops->remove_location != NULL); | |
4055 | ||
b2b6a7da | 4056 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4057 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4058 | |
c906108c | 4059 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4060 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4061 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4062 | bl->owner->number); |
c906108c | 4063 | } |
35df4500 TJB |
4064 | else if (bl->owner->type == bp_catchpoint |
4065 | && breakpoint_enabled (bl->owner) | |
4066 | && !bl->duplicate) | |
ce78b96d | 4067 | { |
77b06cd7 TJB |
4068 | gdb_assert (bl->owner->ops != NULL |
4069 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4070 | |
73971819 | 4071 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4072 | if (val) |
4073 | return val; | |
77b06cd7 | 4074 | |
b2b6a7da | 4075 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4076 | } |
c906108c SS |
4077 | |
4078 | return 0; | |
4079 | } | |
4080 | ||
6c95b8df | 4081 | static int |
834c0d03 | 4082 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4083 | { |
4084 | int ret; | |
4085 | struct cleanup *old_chain; | |
4086 | ||
35df4500 TJB |
4087 | /* BL is never in moribund_locations by our callers. */ |
4088 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4089 | |
6c95b8df PA |
4090 | /* The type of none suggests that owner is actually deleted. |
4091 | This should not ever happen. */ | |
35df4500 | 4092 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4093 | |
4094 | old_chain = save_current_space_and_thread (); | |
4095 | ||
35df4500 | 4096 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4097 | |
b2b6a7da | 4098 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4099 | |
4100 | do_cleanups (old_chain); | |
4101 | return ret; | |
4102 | } | |
4103 | ||
c906108c SS |
4104 | /* Clear the "inserted" flag in all breakpoints. */ |
4105 | ||
25b22b0a | 4106 | void |
fba45db2 | 4107 | mark_breakpoints_out (void) |
c906108c | 4108 | { |
35df4500 | 4109 | struct bp_location *bl, **blp_tmp; |
c906108c | 4110 | |
35df4500 | 4111 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4112 | if (bl->pspace == current_program_space) |
35df4500 | 4113 | bl->inserted = 0; |
c906108c SS |
4114 | } |
4115 | ||
53a5351d JM |
4116 | /* Clear the "inserted" flag in all breakpoints and delete any |
4117 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4118 | |
4119 | Plus other such housekeeping that has to be done for breakpoints | |
4120 | between runs. | |
4121 | ||
53a5351d JM |
4122 | Note: this function gets called at the end of a run (by |
4123 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4124 | init_wait_for_inferior). */ |
c906108c SS |
4125 | |
4126 | ||
4127 | ||
4128 | void | |
fba45db2 | 4129 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4130 | { |
35df4500 | 4131 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4132 | struct bp_location *bl; |
1c5cfe86 | 4133 | int ix; |
6c95b8df | 4134 | struct program_space *pspace = current_program_space; |
c906108c | 4135 | |
50c71eaf PA |
4136 | /* If breakpoint locations are shared across processes, then there's |
4137 | nothing to do. */ | |
f5656ead | 4138 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4139 | return; |
4140 | ||
1a853c52 | 4141 | mark_breakpoints_out (); |
075f6582 | 4142 | |
35df4500 | 4143 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4144 | { |
6c95b8df PA |
4145 | if (b->loc && b->loc->pspace != pspace) |
4146 | continue; | |
4147 | ||
c5aa993b JM |
4148 | switch (b->type) |
4149 | { | |
4150 | case bp_call_dummy: | |
e2e4d78b | 4151 | case bp_longjmp_call_dummy: |
c906108c | 4152 | |
c5aa993b | 4153 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4154 | cause problems when the inferior is rerun, so we better get |
4155 | rid of it. */ | |
4156 | ||
4157 | case bp_watchpoint_scope: | |
4158 | ||
4159 | /* Also get rid of scope breakpoints. */ | |
4160 | ||
4161 | case bp_shlib_event: | |
4162 | ||
4163 | /* Also remove solib event breakpoints. Their addresses may | |
4164 | have changed since the last time we ran the program. | |
4165 | Actually we may now be debugging against different target; | |
4166 | and so the solib backend that installed this breakpoint may | |
4167 | not be used in by the target. E.g., | |
4168 | ||
4169 | (gdb) file prog-linux | |
4170 | (gdb) run # native linux target | |
4171 | ... | |
4172 | (gdb) kill | |
4173 | (gdb) file prog-win.exe | |
4174 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4175 | */ | |
c906108c | 4176 | |
f59f708a PA |
4177 | case bp_step_resume: |
4178 | ||
4179 | /* Also remove step-resume breakpoints. */ | |
4180 | ||
7c16b83e PA |
4181 | case bp_single_step: |
4182 | ||
4183 | /* Also remove single-step breakpoints. */ | |
4184 | ||
c5aa993b JM |
4185 | delete_breakpoint (b); |
4186 | break; | |
c906108c | 4187 | |
c5aa993b JM |
4188 | case bp_watchpoint: |
4189 | case bp_hardware_watchpoint: | |
4190 | case bp_read_watchpoint: | |
4191 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4192 | { |
4193 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4194 | |
3a5c3e22 PA |
4195 | /* Likewise for watchpoints on local expressions. */ |
4196 | if (w->exp_valid_block != NULL) | |
4197 | delete_breakpoint (b); | |
63000888 | 4198 | else |
3a5c3e22 | 4199 | { |
63000888 PA |
4200 | /* Get rid of existing locations, which are no longer |
4201 | valid. New ones will be created in | |
4202 | update_watchpoint, when the inferior is restarted. | |
4203 | The next update_global_location_list call will | |
4204 | garbage collect them. */ | |
4205 | b->loc = NULL; | |
4206 | ||
4207 | if (context == inf_starting) | |
4208 | { | |
4209 | /* Reset val field to force reread of starting value in | |
4210 | insert_breakpoints. */ | |
4211 | if (w->val) | |
4212 | value_free (w->val); | |
4213 | w->val = NULL; | |
4214 | w->val_valid = 0; | |
4215 | } | |
4216 | } | |
3a5c3e22 | 4217 | } |
c5aa993b JM |
4218 | break; |
4219 | default: | |
c5aa993b JM |
4220 | break; |
4221 | } | |
4222 | } | |
1c5cfe86 PA |
4223 | |
4224 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4225 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4226 | decref_bp_location (&bl); | |
1c5cfe86 | 4227 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4228 | } |
4229 | ||
6c95b8df PA |
4230 | /* These functions concern about actual breakpoints inserted in the |
4231 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4232 | we need to hop over the bkpt --- so we check for address space | |
4233 | match, not program space. */ | |
4234 | ||
c2c6d25f JM |
4235 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4236 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4237 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4238 | permanent breakpoint. | |
4239 | - When continuing from a location with an ordinary breakpoint, we | |
4240 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4241 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4242 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4243 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4244 | |
c2c6d25f | 4245 | enum breakpoint_here |
6c95b8df | 4246 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4247 | { |
35df4500 | 4248 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4249 | int any_breakpoint_here = 0; |
c906108c | 4250 | |
35df4500 | 4251 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4252 | { |
35df4500 TJB |
4253 | if (bl->loc_type != bp_loc_software_breakpoint |
4254 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4255 | continue; |
4256 | ||
f1310107 | 4257 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4258 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4259 | || bl->permanent) |
f1310107 | 4260 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4261 | { |
4262 | if (overlay_debugging | |
35df4500 TJB |
4263 | && section_is_overlay (bl->section) |
4264 | && !section_is_mapped (bl->section)) | |
075f6582 | 4265 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4266 | else if (bl->permanent) |
075f6582 DJ |
4267 | return permanent_breakpoint_here; |
4268 | else | |
4269 | any_breakpoint_here = 1; | |
4270 | } | |
4271 | } | |
c906108c | 4272 | |
f486487f | 4273 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4274 | } |
4275 | ||
d35ae833 PA |
4276 | /* See breakpoint.h. */ |
4277 | ||
4278 | int | |
4279 | breakpoint_in_range_p (struct address_space *aspace, | |
4280 | CORE_ADDR addr, ULONGEST len) | |
4281 | { | |
4282 | struct bp_location *bl, **blp_tmp; | |
4283 | ||
4284 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4285 | { | |
4286 | if (bl->loc_type != bp_loc_software_breakpoint | |
4287 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4288 | continue; | |
4289 | ||
4290 | if ((breakpoint_enabled (bl->owner) | |
4291 | || bl->permanent) | |
4292 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4293 | addr, len)) | |
4294 | { | |
4295 | if (overlay_debugging | |
4296 | && section_is_overlay (bl->section) | |
4297 | && !section_is_mapped (bl->section)) | |
4298 | { | |
4299 | /* Unmapped overlay -- can't be a match. */ | |
4300 | continue; | |
4301 | } | |
4302 | ||
4303 | return 1; | |
4304 | } | |
4305 | } | |
4306 | ||
4307 | return 0; | |
4308 | } | |
4309 | ||
1c5cfe86 PA |
4310 | /* Return true if there's a moribund breakpoint at PC. */ |
4311 | ||
4312 | int | |
6c95b8df | 4313 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4314 | { |
4315 | struct bp_location *loc; | |
4316 | int ix; | |
4317 | ||
4318 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4319 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4320 | return 1; |
4321 | ||
4322 | return 0; | |
4323 | } | |
c2c6d25f | 4324 | |
f7ce857f PA |
4325 | /* Returns non-zero iff BL is inserted at PC, in address space |
4326 | ASPACE. */ | |
4327 | ||
4328 | static int | |
4329 | bp_location_inserted_here_p (struct bp_location *bl, | |
4330 | struct address_space *aspace, CORE_ADDR pc) | |
4331 | { | |
4332 | if (bl->inserted | |
4333 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4334 | aspace, pc)) | |
4335 | { | |
4336 | if (overlay_debugging | |
4337 | && section_is_overlay (bl->section) | |
4338 | && !section_is_mapped (bl->section)) | |
4339 | return 0; /* unmapped overlay -- can't be a match */ | |
4340 | else | |
4341 | return 1; | |
4342 | } | |
4343 | return 0; | |
4344 | } | |
4345 | ||
a1fd2fa5 | 4346 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4347 | |
4348 | int | |
a1fd2fa5 | 4349 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4350 | { |
f7ce857f | 4351 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4352 | |
f7ce857f | 4353 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4354 | { |
f7ce857f PA |
4355 | struct bp_location *bl = *blp; |
4356 | ||
35df4500 TJB |
4357 | if (bl->loc_type != bp_loc_software_breakpoint |
4358 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4359 | continue; |
4360 | ||
f7ce857f PA |
4361 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4362 | return 1; | |
c5aa993b | 4363 | } |
c36b740a VP |
4364 | return 0; |
4365 | } | |
4366 | ||
a1fd2fa5 PA |
4367 | /* This function returns non-zero iff there is a software breakpoint |
4368 | inserted at PC. */ | |
c36b740a VP |
4369 | |
4370 | int | |
a1fd2fa5 PA |
4371 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4372 | CORE_ADDR pc) | |
4fa8626c | 4373 | { |
f7ce857f | 4374 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4375 | |
f7ce857f | 4376 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4377 | { |
f7ce857f PA |
4378 | struct bp_location *bl = *blp; |
4379 | ||
35df4500 | 4380 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4381 | continue; |
4382 | ||
f7ce857f PA |
4383 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4384 | return 1; | |
4fa8626c DJ |
4385 | } |
4386 | ||
4387 | return 0; | |
9c02b525 PA |
4388 | } |
4389 | ||
4390 | /* See breakpoint.h. */ | |
4391 | ||
4392 | int | |
4393 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4394 | CORE_ADDR pc) | |
4395 | { | |
4396 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4397 | |
4398 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4399 | { | |
4400 | struct bp_location *bl = *blp; | |
4401 | ||
4402 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4403 | continue; | |
4404 | ||
4405 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4406 | return 1; | |
4407 | } | |
4408 | ||
4409 | return 0; | |
4fa8626c DJ |
4410 | } |
4411 | ||
9093389c PA |
4412 | int |
4413 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4414 | CORE_ADDR addr, ULONGEST len) | |
4415 | { | |
4416 | struct breakpoint *bpt; | |
4417 | ||
4418 | ALL_BREAKPOINTS (bpt) | |
4419 | { | |
4420 | struct bp_location *loc; | |
4421 | ||
4422 | if (bpt->type != bp_hardware_watchpoint | |
4423 | && bpt->type != bp_access_watchpoint) | |
4424 | continue; | |
4425 | ||
4426 | if (!breakpoint_enabled (bpt)) | |
4427 | continue; | |
4428 | ||
4429 | for (loc = bpt->loc; loc; loc = loc->next) | |
4430 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4431 | { | |
4432 | CORE_ADDR l, h; | |
4433 | ||
4434 | /* Check for intersection. */ | |
768adc05 PA |
4435 | l = std::max<CORE_ADDR> (loc->address, addr); |
4436 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4437 | if (l < h) |
4438 | return 1; | |
4439 | } | |
4440 | } | |
4441 | return 0; | |
4442 | } | |
c906108c | 4443 | \f |
c5aa993b | 4444 | |
c906108c SS |
4445 | /* bpstat stuff. External routines' interfaces are documented |
4446 | in breakpoint.h. */ | |
4447 | ||
4448 | int | |
c326b90e | 4449 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4450 | { |
533be4dd | 4451 | return (ep->type == bp_catchpoint); |
c906108c SS |
4452 | } |
4453 | ||
f431efe5 PA |
4454 | /* Frees any storage that is part of a bpstat. Does not walk the |
4455 | 'next' chain. */ | |
4456 | ||
4457 | static void | |
198757a8 VP |
4458 | bpstat_free (bpstat bs) |
4459 | { | |
4460 | if (bs->old_val != NULL) | |
4461 | value_free (bs->old_val); | |
9add0f1b | 4462 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4463 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4464 | xfree (bs); |
4465 | } | |
4466 | ||
c906108c SS |
4467 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4468 | Also free any storage that is part of a bpstat. */ | |
4469 | ||
4470 | void | |
fba45db2 | 4471 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4472 | { |
4473 | bpstat p; | |
4474 | bpstat q; | |
4475 | ||
4476 | if (bsp == 0) | |
4477 | return; | |
4478 | p = *bsp; | |
4479 | while (p != NULL) | |
4480 | { | |
4481 | q = p->next; | |
198757a8 | 4482 | bpstat_free (p); |
c906108c SS |
4483 | p = q; |
4484 | } | |
4485 | *bsp = NULL; | |
4486 | } | |
4487 | ||
4488 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4489 | is part of the bpstat is copied as well. */ | |
4490 | ||
4491 | bpstat | |
fba45db2 | 4492 | bpstat_copy (bpstat bs) |
c906108c SS |
4493 | { |
4494 | bpstat p = NULL; | |
4495 | bpstat tmp; | |
4496 | bpstat retval = NULL; | |
4497 | ||
4498 | if (bs == NULL) | |
4499 | return bs; | |
4500 | ||
4501 | for (; bs != NULL; bs = bs->next) | |
4502 | { | |
4503 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4504 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4505 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4506 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4507 | if (bs->old_val != NULL) |
3c3185ac JK |
4508 | { |
4509 | tmp->old_val = value_copy (bs->old_val); | |
4510 | release_value (tmp->old_val); | |
4511 | } | |
31cc81e9 | 4512 | |
c906108c SS |
4513 | if (p == NULL) |
4514 | /* This is the first thing in the chain. */ | |
4515 | retval = tmp; | |
4516 | else | |
4517 | p->next = tmp; | |
4518 | p = tmp; | |
4519 | } | |
4520 | p->next = NULL; | |
4521 | return retval; | |
4522 | } | |
4523 | ||
4a64f543 | 4524 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4525 | |
4526 | bpstat | |
fba45db2 | 4527 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4528 | { |
c5aa993b JM |
4529 | if (bsp == NULL) |
4530 | return NULL; | |
c906108c | 4531 | |
c5aa993b JM |
4532 | for (; bsp != NULL; bsp = bsp->next) |
4533 | { | |
f431efe5 | 4534 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4535 | return bsp; |
4536 | } | |
c906108c SS |
4537 | return NULL; |
4538 | } | |
4539 | ||
ab04a2af TT |
4540 | /* See breakpoint.h. */ |
4541 | ||
47591c29 | 4542 | int |
427cd150 | 4543 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4544 | { |
ab04a2af TT |
4545 | for (; bsp != NULL; bsp = bsp->next) |
4546 | { | |
427cd150 TT |
4547 | if (bsp->breakpoint_at == NULL) |
4548 | { | |
4549 | /* A moribund location can never explain a signal other than | |
4550 | GDB_SIGNAL_TRAP. */ | |
4551 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4552 | return 1; |
427cd150 TT |
4553 | } |
4554 | else | |
47591c29 PA |
4555 | { |
4556 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4557 | sig)) | |
4558 | return 1; | |
4559 | } | |
ab04a2af TT |
4560 | } |
4561 | ||
47591c29 | 4562 | return 0; |
ab04a2af TT |
4563 | } |
4564 | ||
4a64f543 MS |
4565 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4566 | stopped at. *BSP upon return is a bpstat which points to the | |
4567 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4568 | good for anything but further calls to bpstat_num). | |
4569 | ||
8671a17b PA |
4570 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4571 | Return -1 if stopped at a breakpoint that has been deleted since | |
4572 | we set it. | |
4573 | Return 1 otherwise. */ | |
c906108c SS |
4574 | |
4575 | int | |
8671a17b | 4576 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4577 | { |
4578 | struct breakpoint *b; | |
4579 | ||
4580 | if ((*bsp) == NULL) | |
4581 | return 0; /* No more breakpoint values */ | |
8671a17b | 4582 | |
4a64f543 MS |
4583 | /* We assume we'll never have several bpstats that correspond to a |
4584 | single breakpoint -- otherwise, this function might return the | |
4585 | same number more than once and this will look ugly. */ | |
f431efe5 | 4586 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4587 | *bsp = (*bsp)->next; |
4588 | if (b == NULL) | |
4589 | return -1; /* breakpoint that's been deleted since */ | |
4590 | ||
4591 | *num = b->number; /* We have its number */ | |
4592 | return 1; | |
c906108c SS |
4593 | } |
4594 | ||
e93ca019 | 4595 | /* See breakpoint.h. */ |
c906108c SS |
4596 | |
4597 | void | |
e93ca019 | 4598 | bpstat_clear_actions (void) |
c906108c | 4599 | { |
e93ca019 JK |
4600 | struct thread_info *tp; |
4601 | bpstat bs; | |
4602 | ||
4603 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4604 | return; | |
4605 | ||
4606 | tp = find_thread_ptid (inferior_ptid); | |
4607 | if (tp == NULL) | |
4608 | return; | |
4609 | ||
4610 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4611 | { |
9add0f1b | 4612 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4613 | |
c906108c SS |
4614 | if (bs->old_val != NULL) |
4615 | { | |
4616 | value_free (bs->old_val); | |
4617 | bs->old_val = NULL; | |
4618 | } | |
4619 | } | |
4620 | } | |
4621 | ||
f3b1572e PA |
4622 | /* Called when a command is about to proceed the inferior. */ |
4623 | ||
4624 | static void | |
4625 | breakpoint_about_to_proceed (void) | |
4626 | { | |
4627 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4628 | { | |
4629 | struct thread_info *tp = inferior_thread (); | |
4630 | ||
4631 | /* Allow inferior function calls in breakpoint commands to not | |
4632 | interrupt the command list. When the call finishes | |
4633 | successfully, the inferior will be standing at the same | |
4634 | breakpoint as if nothing happened. */ | |
16c381f0 | 4635 | if (tp->control.in_infcall) |
f3b1572e PA |
4636 | return; |
4637 | } | |
4638 | ||
4639 | breakpoint_proceeded = 1; | |
4640 | } | |
4641 | ||
4a64f543 MS |
4642 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4643 | command. */ | |
c906108c | 4644 | static void |
4efb68b1 | 4645 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4646 | { |
4647 | executing_breakpoint_commands = 0; | |
4648 | } | |
4649 | ||
abf85f46 JK |
4650 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4651 | or its equivalent. */ | |
4652 | ||
4653 | static int | |
4654 | command_line_is_silent (struct command_line *cmd) | |
4655 | { | |
4f45d445 | 4656 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4657 | } |
4658 | ||
4a64f543 MS |
4659 | /* Execute all the commands associated with all the breakpoints at |
4660 | this location. Any of these commands could cause the process to | |
4661 | proceed beyond this point, etc. We look out for such changes by | |
4662 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4663 | |
347bddb7 PA |
4664 | Returns true if a breakpoint command resumed the inferior. In that |
4665 | case, it is the caller's responsibility to recall it again with the | |
4666 | bpstat of the current thread. */ | |
4667 | ||
4668 | static int | |
4669 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4670 | { |
4671 | bpstat bs; | |
4672 | struct cleanup *old_chain; | |
347bddb7 | 4673 | int again = 0; |
c906108c SS |
4674 | |
4675 | /* Avoid endless recursion if a `source' command is contained | |
4676 | in bs->commands. */ | |
4677 | if (executing_breakpoint_commands) | |
347bddb7 | 4678 | return 0; |
c906108c SS |
4679 | |
4680 | executing_breakpoint_commands = 1; | |
4681 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4682 | ||
1ac32117 | 4683 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4684 | |
4a64f543 | 4685 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4686 | bs = *bsp; |
4687 | ||
4688 | breakpoint_proceeded = 0; | |
4689 | for (; bs != NULL; bs = bs->next) | |
4690 | { | |
9add0f1b | 4691 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4692 | struct command_line *cmd; |
4693 | struct cleanup *this_cmd_tree_chain; | |
4694 | ||
4695 | /* Take ownership of the BSP's command tree, if it has one. | |
4696 | ||
4697 | The command tree could legitimately contain commands like | |
4698 | 'step' and 'next', which call clear_proceed_status, which | |
4699 | frees stop_bpstat's command tree. To make sure this doesn't | |
4700 | free the tree we're executing out from under us, we need to | |
4701 | take ownership of the tree ourselves. Since a given bpstat's | |
4702 | commands are only executed once, we don't need to copy it; we | |
4703 | can clear the pointer in the bpstat, and make sure we free | |
4704 | the tree when we're done. */ | |
9add0f1b TT |
4705 | ccmd = bs->commands; |
4706 | bs->commands = NULL; | |
abf85f46 JK |
4707 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4708 | cmd = ccmd ? ccmd->commands : NULL; | |
4709 | if (command_line_is_silent (cmd)) | |
4710 | { | |
4711 | /* The action has been already done by bpstat_stop_status. */ | |
4712 | cmd = cmd->next; | |
4713 | } | |
6c50ab1c | 4714 | |
c906108c SS |
4715 | while (cmd != NULL) |
4716 | { | |
4717 | execute_control_command (cmd); | |
4718 | ||
4719 | if (breakpoint_proceeded) | |
4720 | break; | |
4721 | else | |
4722 | cmd = cmd->next; | |
4723 | } | |
6c50ab1c JB |
4724 | |
4725 | /* We can free this command tree now. */ | |
4726 | do_cleanups (this_cmd_tree_chain); | |
4727 | ||
c906108c | 4728 | if (breakpoint_proceeded) |
32c1e744 | 4729 | { |
cb814510 | 4730 | if (current_ui->async) |
347bddb7 PA |
4731 | /* If we are in async mode, then the target might be still |
4732 | running, not stopped at any breakpoint, so nothing for | |
4733 | us to do here -- just return to the event loop. */ | |
4734 | ; | |
32c1e744 VP |
4735 | else |
4736 | /* In sync mode, when execute_control_command returns | |
4737 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4738 | Breakpoint commands for that stop were not run, since |
4739 | execute_command does not run breakpoint commands -- | |
4740 | only command_line_handler does, but that one is not | |
4741 | involved in execution of breakpoint commands. So, we | |
4742 | can now execute breakpoint commands. It should be | |
4743 | noted that making execute_command do bpstat actions is | |
4744 | not an option -- in this case we'll have recursive | |
4745 | invocation of bpstat for each breakpoint with a | |
4746 | command, and can easily blow up GDB stack. Instead, we | |
4747 | return true, which will trigger the caller to recall us | |
4748 | with the new stop_bpstat. */ | |
4749 | again = 1; | |
4750 | break; | |
32c1e744 | 4751 | } |
c906108c | 4752 | } |
c2b8ed2c | 4753 | do_cleanups (old_chain); |
347bddb7 PA |
4754 | return again; |
4755 | } | |
4756 | ||
4757 | void | |
4758 | bpstat_do_actions (void) | |
4759 | { | |
353d1d73 JK |
4760 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4761 | ||
347bddb7 PA |
4762 | /* Do any commands attached to breakpoint we are stopped at. */ |
4763 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4764 | && target_has_execution | |
4765 | && !is_exited (inferior_ptid) | |
4766 | && !is_executing (inferior_ptid)) | |
4767 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4768 | and only return when it is stopped at the next breakpoint, we | |
4769 | keep doing breakpoint actions until it returns false to | |
4770 | indicate the inferior was not resumed. */ | |
16c381f0 | 4771 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4772 | break; |
353d1d73 JK |
4773 | |
4774 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4775 | } |
4776 | ||
fa4727a6 DJ |
4777 | /* Print out the (old or new) value associated with a watchpoint. */ |
4778 | ||
4779 | static void | |
4780 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4781 | { | |
4782 | if (val == NULL) | |
4783 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4784 | else | |
79a45b7d TT |
4785 | { |
4786 | struct value_print_options opts; | |
4787 | get_user_print_options (&opts); | |
4788 | value_print (val, stream, &opts); | |
4789 | } | |
fa4727a6 DJ |
4790 | } |
4791 | ||
f303dbd6 PA |
4792 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4793 | debugging multiple threads. */ | |
4794 | ||
4795 | void | |
4796 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4797 | { | |
112e8700 | 4798 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4799 | return; |
4800 | ||
112e8700 | 4801 | uiout->text ("\n"); |
f303dbd6 PA |
4802 | |
4803 | if (show_thread_that_caused_stop ()) | |
4804 | { | |
4805 | const char *name; | |
4806 | struct thread_info *thr = inferior_thread (); | |
4807 | ||
112e8700 SM |
4808 | uiout->text ("Thread "); |
4809 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4810 | |
4811 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4812 | if (name != NULL) | |
4813 | { | |
112e8700 SM |
4814 | uiout->text (" \""); |
4815 | uiout->field_fmt ("name", "%s", name); | |
4816 | uiout->text ("\""); | |
f303dbd6 PA |
4817 | } |
4818 | ||
112e8700 | 4819 | uiout->text (" hit "); |
f303dbd6 PA |
4820 | } |
4821 | } | |
4822 | ||
e514a9d6 | 4823 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4824 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4825 | 'print_it' in the bpstat structure. Under some circumstances we |
4826 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4827 | normal_stop(). */ |
e514a9d6 JM |
4828 | |
4829 | static enum print_stop_action | |
4830 | print_bp_stop_message (bpstat bs) | |
4831 | { | |
4832 | switch (bs->print_it) | |
4833 | { | |
4834 | case print_it_noop: | |
4a64f543 | 4835 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4836 | return PRINT_UNKNOWN; |
4837 | break; | |
4838 | ||
4839 | case print_it_done: | |
4840 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4841 | relevant messages. */ |
e514a9d6 JM |
4842 | return PRINT_SRC_AND_LOC; |
4843 | break; | |
4844 | ||
4845 | case print_it_normal: | |
4f8d1dc6 | 4846 | { |
f431efe5 PA |
4847 | struct breakpoint *b = bs->breakpoint_at; |
4848 | ||
1a6a67de TJB |
4849 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4850 | which has since been deleted. */ | |
4851 | if (b == NULL) | |
4852 | return PRINT_UNKNOWN; | |
4853 | ||
348d480f PA |
4854 | /* Normal case. Call the breakpoint's print_it method. */ |
4855 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4856 | } |
348d480f | 4857 | break; |
3086aeae | 4858 | |
e514a9d6 | 4859 | default: |
8e65ff28 | 4860 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4861 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4862 | break; |
c906108c | 4863 | } |
c906108c SS |
4864 | } |
4865 | ||
edcc5120 TT |
4866 | /* A helper function that prints a shared library stopped event. */ |
4867 | ||
4868 | static void | |
4869 | print_solib_event (int is_catchpoint) | |
4870 | { | |
4871 | int any_deleted | |
4872 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4873 | int any_added | |
4874 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4875 | ||
4876 | if (!is_catchpoint) | |
4877 | { | |
4878 | if (any_added || any_deleted) | |
112e8700 | 4879 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4880 | else |
112e8700 SM |
4881 | current_uiout->text (_("Stopped due to shared library event (no " |
4882 | "libraries added or removed)\n")); | |
edcc5120 TT |
4883 | } |
4884 | ||
112e8700 SM |
4885 | if (current_uiout->is_mi_like_p ()) |
4886 | current_uiout->field_string ("reason", | |
4887 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4888 | |
4889 | if (any_deleted) | |
4890 | { | |
4891 | struct cleanup *cleanup; | |
4892 | char *name; | |
4893 | int ix; | |
4894 | ||
112e8700 | 4895 | current_uiout->text (_(" Inferior unloaded ")); |
edcc5120 TT |
4896 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
4897 | "removed"); | |
4898 | for (ix = 0; | |
4899 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4900 | ix, name); | |
4901 | ++ix) | |
4902 | { | |
4903 | if (ix > 0) | |
112e8700 SM |
4904 | current_uiout->text (" "); |
4905 | current_uiout->field_string ("library", name); | |
4906 | current_uiout->text ("\n"); | |
edcc5120 TT |
4907 | } |
4908 | ||
4909 | do_cleanups (cleanup); | |
4910 | } | |
4911 | ||
4912 | if (any_added) | |
4913 | { | |
4914 | struct so_list *iter; | |
4915 | int ix; | |
4916 | struct cleanup *cleanup; | |
4917 | ||
112e8700 | 4918 | current_uiout->text (_(" Inferior loaded ")); |
edcc5120 TT |
4919 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
4920 | "added"); | |
4921 | for (ix = 0; | |
4922 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4923 | ix, iter); | |
4924 | ++ix) | |
4925 | { | |
4926 | if (ix > 0) | |
112e8700 SM |
4927 | current_uiout->text (" "); |
4928 | current_uiout->field_string ("library", iter->so_name); | |
4929 | current_uiout->text ("\n"); | |
edcc5120 TT |
4930 | } |
4931 | ||
4932 | do_cleanups (cleanup); | |
4933 | } | |
4934 | } | |
4935 | ||
e514a9d6 JM |
4936 | /* Print a message indicating what happened. This is called from |
4937 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4938 | list - a list of the eventpoints that caused this stop. KIND is |
4939 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4940 | routine calls the generic print routine for printing a message |
4941 | about reasons for stopping. This will print (for example) the | |
4942 | "Breakpoint n," part of the output. The return value of this | |
4943 | routine is one of: | |
c906108c | 4944 | |
4a64f543 | 4945 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4946 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4947 | code to print the location. An example is |
c5aa993b JM |
4948 | "Breakpoint 1, " which should be followed by |
4949 | the location. | |
917317f4 | 4950 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4951 | to also print the location part of the message. |
4952 | An example is the catch/throw messages, which | |
4a64f543 | 4953 | don't require a location appended to the end. |
917317f4 | 4954 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4955 | further info to be printed. */ |
c906108c | 4956 | |
917317f4 | 4957 | enum print_stop_action |
36dfb11c | 4958 | bpstat_print (bpstat bs, int kind) |
c906108c | 4959 | { |
f486487f | 4960 | enum print_stop_action val; |
c5aa993b | 4961 | |
c906108c | 4962 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4963 | (Currently all watchpoints go on the bpstat whether hit or not. |
4964 | That probably could (should) be changed, provided care is taken | |
c906108c | 4965 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4966 | for (; bs; bs = bs->next) |
4967 | { | |
4968 | val = print_bp_stop_message (bs); | |
4969 | if (val == PRINT_SRC_ONLY | |
4970 | || val == PRINT_SRC_AND_LOC | |
4971 | || val == PRINT_NOTHING) | |
4972 | return val; | |
4973 | } | |
c906108c | 4974 | |
36dfb11c TT |
4975 | /* If we had hit a shared library event breakpoint, |
4976 | print_bp_stop_message would print out this message. If we hit an | |
4977 | OS-level shared library event, do the same thing. */ | |
4978 | if (kind == TARGET_WAITKIND_LOADED) | |
4979 | { | |
edcc5120 | 4980 | print_solib_event (0); |
36dfb11c TT |
4981 | return PRINT_NOTHING; |
4982 | } | |
4983 | ||
e514a9d6 | 4984 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4985 | with and nothing was printed. */ |
917317f4 | 4986 | return PRINT_UNKNOWN; |
c906108c SS |
4987 | } |
4988 | ||
c42bd95a DE |
4989 | /* Evaluate the expression EXP and return 1 if value is zero. |
4990 | This returns the inverse of the condition because it is called | |
4991 | from catch_errors which returns 0 if an exception happened, and if an | |
4992 | exception happens we want execution to stop. | |
4a64f543 | 4993 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4994 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4995 | |
4996 | static int | |
4efb68b1 | 4997 | breakpoint_cond_eval (void *exp) |
c906108c | 4998 | { |
278cd55f | 4999 | struct value *mark = value_mark (); |
c5aa993b | 5000 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5001 | |
c906108c SS |
5002 | value_free_to_mark (mark); |
5003 | return i; | |
5004 | } | |
5005 | ||
5760d0ab | 5006 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5007 | |
5008 | static bpstat | |
5760d0ab | 5009 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5010 | { |
5011 | bpstat bs; | |
5012 | ||
5013 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5014 | bs->next = NULL; |
5015 | **bs_link_pointer = bs; | |
5016 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5017 | bs->breakpoint_at = bl->owner; |
5018 | bs->bp_location_at = bl; | |
5019 | incref_bp_location (bl); | |
c906108c SS |
5020 | /* If the condition is false, etc., don't do the commands. */ |
5021 | bs->commands = NULL; | |
5022 | bs->old_val = NULL; | |
5023 | bs->print_it = print_it_normal; | |
5024 | return bs; | |
5025 | } | |
5026 | \f | |
d983da9c DJ |
5027 | /* The target has stopped with waitstatus WS. Check if any hardware |
5028 | watchpoints have triggered, according to the target. */ | |
5029 | ||
5030 | int | |
5031 | watchpoints_triggered (struct target_waitstatus *ws) | |
5032 | { | |
d92524f1 | 5033 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5034 | CORE_ADDR addr; |
5035 | struct breakpoint *b; | |
5036 | ||
5037 | if (!stopped_by_watchpoint) | |
5038 | { | |
5039 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5040 | as not triggered. */ | |
5041 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5042 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5043 | { |
5044 | struct watchpoint *w = (struct watchpoint *) b; | |
5045 | ||
5046 | w->watchpoint_triggered = watch_triggered_no; | |
5047 | } | |
d983da9c DJ |
5048 | |
5049 | return 0; | |
5050 | } | |
5051 | ||
5052 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5053 | { | |
5054 | /* We were stopped by a watchpoint, but we don't know where. | |
5055 | Mark all watchpoints as unknown. */ | |
5056 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5057 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5058 | { |
5059 | struct watchpoint *w = (struct watchpoint *) b; | |
5060 | ||
5061 | w->watchpoint_triggered = watch_triggered_unknown; | |
5062 | } | |
d983da9c | 5063 | |
3c4797ba | 5064 | return 1; |
d983da9c DJ |
5065 | } |
5066 | ||
5067 | /* The target could report the data address. Mark watchpoints | |
5068 | affected by this data address as triggered, and all others as not | |
5069 | triggered. */ | |
5070 | ||
5071 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5072 | if (is_hardware_watchpoint (b)) |
d983da9c | 5073 | { |
3a5c3e22 | 5074 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5075 | struct bp_location *loc; |
d983da9c | 5076 | |
3a5c3e22 | 5077 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5078 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5079 | { |
3a5c3e22 | 5080 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5081 | { |
3a5c3e22 PA |
5082 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5083 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5084 | |
5085 | if (newaddr == start) | |
5086 | { | |
3a5c3e22 | 5087 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5088 | break; |
5089 | } | |
5090 | } | |
5091 | /* Exact match not required. Within range is sufficient. */ | |
5092 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5093 | addr, loc->address, | |
5094 | loc->length)) | |
5095 | { | |
3a5c3e22 | 5096 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5097 | break; |
5098 | } | |
5099 | } | |
d983da9c DJ |
5100 | } |
5101 | ||
5102 | return 1; | |
5103 | } | |
5104 | ||
c906108c SS |
5105 | /* Possible return values for watchpoint_check (this can't be an enum |
5106 | because of check_errors). */ | |
5107 | /* The watchpoint has been deleted. */ | |
5108 | #define WP_DELETED 1 | |
5109 | /* The value has changed. */ | |
5110 | #define WP_VALUE_CHANGED 2 | |
5111 | /* The value has not changed. */ | |
5112 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5113 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5114 | #define WP_IGNORE 4 | |
c906108c SS |
5115 | |
5116 | #define BP_TEMPFLAG 1 | |
5117 | #define BP_HARDWAREFLAG 2 | |
5118 | ||
4a64f543 MS |
5119 | /* Evaluate watchpoint condition expression and check if its value |
5120 | changed. | |
553e4c11 JB |
5121 | |
5122 | P should be a pointer to struct bpstat, but is defined as a void * | |
5123 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5124 | |
5125 | static int | |
4efb68b1 | 5126 | watchpoint_check (void *p) |
c906108c SS |
5127 | { |
5128 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5129 | struct watchpoint *b; |
c906108c SS |
5130 | struct frame_info *fr; |
5131 | int within_current_scope; | |
5132 | ||
f431efe5 | 5133 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5134 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5135 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5136 | |
f6bc2008 PA |
5137 | /* If this is a local watchpoint, we only want to check if the |
5138 | watchpoint frame is in scope if the current thread is the thread | |
5139 | that was used to create the watchpoint. */ | |
5140 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5141 | return WP_IGNORE; |
f6bc2008 | 5142 | |
c906108c SS |
5143 | if (b->exp_valid_block == NULL) |
5144 | within_current_scope = 1; | |
5145 | else | |
5146 | { | |
edb3359d DJ |
5147 | struct frame_info *frame = get_current_frame (); |
5148 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5149 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5150 | ||
c9cf6e20 | 5151 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5152 | still in the function but the stack frame has already been |
5153 | invalidated. Since we can't rely on the values of local | |
5154 | variables after the stack has been destroyed, we are treating | |
5155 | the watchpoint in that state as `not changed' without further | |
5156 | checking. Don't mark watchpoints as changed if the current | |
5157 | frame is in an epilogue - even if they are in some other | |
5158 | frame, our view of the stack is likely to be wrong and | |
5159 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5160 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5161 | return WP_IGNORE; |
a0f49112 | 5162 | |
101dcfbe | 5163 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5164 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5165 | |
5166 | /* If we've gotten confused in the unwinder, we might have | |
5167 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5168 | if (within_current_scope) |
5169 | { | |
5170 | struct symbol *function; | |
5171 | ||
5172 | function = get_frame_function (fr); | |
5173 | if (function == NULL | |
5174 | || !contained_in (b->exp_valid_block, | |
5175 | SYMBOL_BLOCK_VALUE (function))) | |
5176 | within_current_scope = 0; | |
5177 | } | |
69fbadd5 | 5178 | |
edb3359d | 5179 | if (within_current_scope) |
c906108c SS |
5180 | /* If we end up stopping, the current frame will get selected |
5181 | in normal_stop. So this call to select_frame won't affect | |
5182 | the user. */ | |
0f7d239c | 5183 | select_frame (fr); |
c906108c | 5184 | } |
c5aa993b | 5185 | |
c906108c SS |
5186 | if (within_current_scope) |
5187 | { | |
4a64f543 MS |
5188 | /* We use value_{,free_to_}mark because it could be a *long* |
5189 | time before we return to the command level and call | |
5190 | free_all_values. We can't call free_all_values because we | |
5191 | might be in the middle of evaluating a function call. */ | |
c906108c | 5192 | |
0cf6dd15 | 5193 | int pc = 0; |
9c06b0b4 | 5194 | struct value *mark; |
fa4727a6 DJ |
5195 | struct value *new_val; |
5196 | ||
3a5c3e22 | 5197 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5198 | /* Since we don't know the exact trigger address (from |
5199 | stopped_data_address), just tell the user we've triggered | |
5200 | a mask watchpoint. */ | |
5201 | return WP_VALUE_CHANGED; | |
5202 | ||
5203 | mark = value_mark (); | |
4d01a485 | 5204 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5205 | |
bb9d5f81 PP |
5206 | if (b->val_bitsize != 0) |
5207 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5208 | ||
4a64f543 MS |
5209 | /* We use value_equal_contents instead of value_equal because |
5210 | the latter coerces an array to a pointer, thus comparing just | |
5211 | the address of the array instead of its contents. This is | |
5212 | not what we want. */ | |
fa4727a6 | 5213 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5214 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5215 | { |
fa4727a6 DJ |
5216 | if (new_val != NULL) |
5217 | { | |
5218 | release_value (new_val); | |
5219 | value_free_to_mark (mark); | |
5220 | } | |
c906108c SS |
5221 | bs->old_val = b->val; |
5222 | b->val = new_val; | |
fa4727a6 | 5223 | b->val_valid = 1; |
c906108c SS |
5224 | return WP_VALUE_CHANGED; |
5225 | } | |
5226 | else | |
5227 | { | |
60e1c644 | 5228 | /* Nothing changed. */ |
c906108c | 5229 | value_free_to_mark (mark); |
c906108c SS |
5230 | return WP_VALUE_NOT_CHANGED; |
5231 | } | |
5232 | } | |
5233 | else | |
5234 | { | |
5235 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5236 | if we temporarily ignored the watchpoint, then when |
5237 | we reenter the block in which it is valid it contains | |
5238 | garbage (in the case of a function, it may have two | |
5239 | garbage values, one before and one after the prologue). | |
5240 | So we can't even detect the first assignment to it and | |
5241 | watch after that (since the garbage may or may not equal | |
5242 | the first value assigned). */ | |
348d480f PA |
5243 | /* We print all the stop information in |
5244 | breakpoint_ops->print_it, but in this case, by the time we | |
5245 | call breakpoint_ops->print_it this bp will be deleted | |
5246 | already. So we have no choice but print the information | |
5247 | here. */ | |
468afe6c | 5248 | |
0e454242 | 5249 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5250 | { |
5251 | struct ui_out *uiout = current_uiout; | |
5252 | ||
112e8700 SM |
5253 | if (uiout->is_mi_like_p ()) |
5254 | uiout->field_string | |
5255 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5256 | uiout->text ("\nWatchpoint "); | |
5257 | uiout->field_int ("wpnum", b->base.number); | |
5258 | uiout->text (" deleted because the program has left the block in\n" | |
468afe6c PA |
5259 | "which its expression is valid.\n"); |
5260 | } | |
4ce44c66 | 5261 | |
cdac0397 | 5262 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5263 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5264 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5265 | |
5266 | return WP_DELETED; | |
5267 | } | |
5268 | } | |
5269 | ||
18a18393 | 5270 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5271 | breakpoint location BL. This function does not check if we should |
5272 | stop, only if BL explains the stop. */ | |
5273 | ||
18a18393 | 5274 | static int |
6c95b8df | 5275 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5276 | struct address_space *aspace, CORE_ADDR bp_addr, |
5277 | const struct target_waitstatus *ws) | |
18a18393 VP |
5278 | { |
5279 | struct breakpoint *b = bl->owner; | |
5280 | ||
348d480f | 5281 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5282 | gdb_assert (b != NULL); |
5283 | ||
09ac7c10 | 5284 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5285 | } |
5286 | ||
3a5c3e22 PA |
5287 | /* Determine if the watched values have actually changed, and we |
5288 | should stop. If not, set BS->stop to 0. */ | |
5289 | ||
18a18393 VP |
5290 | static void |
5291 | bpstat_check_watchpoint (bpstat bs) | |
5292 | { | |
2bdf28a0 | 5293 | const struct bp_location *bl; |
3a5c3e22 | 5294 | struct watchpoint *b; |
2bdf28a0 JK |
5295 | |
5296 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5297 | bl = bs->bp_location_at; |
2bdf28a0 | 5298 | gdb_assert (bl != NULL); |
3a5c3e22 | 5299 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5300 | gdb_assert (b != NULL); |
18a18393 | 5301 | |
18a18393 | 5302 | { |
18a18393 VP |
5303 | int must_check_value = 0; |
5304 | ||
3a5c3e22 | 5305 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5306 | /* For a software watchpoint, we must always check the |
5307 | watched value. */ | |
5308 | must_check_value = 1; | |
5309 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5310 | /* We have a hardware watchpoint (read, write, or access) | |
5311 | and the target earlier reported an address watched by | |
5312 | this watchpoint. */ | |
5313 | must_check_value = 1; | |
5314 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5315 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5316 | /* We were stopped by a hardware watchpoint, but the target could |
5317 | not report the data address. We must check the watchpoint's | |
5318 | value. Access and read watchpoints are out of luck; without | |
5319 | a data address, we can't figure it out. */ | |
5320 | must_check_value = 1; | |
3a5c3e22 | 5321 | |
18a18393 VP |
5322 | if (must_check_value) |
5323 | { | |
3e43a32a MS |
5324 | char *message |
5325 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5326 | b->base.number); |
18a18393 VP |
5327 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5328 | int e = catch_errors (watchpoint_check, bs, message, | |
5329 | RETURN_MASK_ALL); | |
5330 | do_cleanups (cleanups); | |
5331 | switch (e) | |
5332 | { | |
5333 | case WP_DELETED: | |
5334 | /* We've already printed what needs to be printed. */ | |
5335 | bs->print_it = print_it_done; | |
5336 | /* Stop. */ | |
5337 | break; | |
60e1c644 PA |
5338 | case WP_IGNORE: |
5339 | bs->print_it = print_it_noop; | |
5340 | bs->stop = 0; | |
5341 | break; | |
18a18393 | 5342 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5343 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5344 | { |
85d721b8 PA |
5345 | /* There are two cases to consider here: |
5346 | ||
4a64f543 | 5347 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5348 | In that case, trust the target, and always report |
5349 | the watchpoint hit to the user. Even though | |
5350 | reads don't cause value changes, the value may | |
5351 | have changed since the last time it was read, and | |
5352 | since we're not trapping writes, we will not see | |
5353 | those, and as such we should ignore our notion of | |
5354 | old value. | |
5355 | ||
4a64f543 | 5356 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5357 | reads and writes. There are two ways this may |
5358 | happen: | |
5359 | ||
4a64f543 | 5360 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5361 | reads only, but can break on accesses (reads or |
5362 | writes), such as e.g., x86. We detect this case | |
5363 | at the time we try to insert read watchpoints. | |
5364 | ||
4a64f543 | 5365 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5366 | watchpoints, but, the user set an access or write |
5367 | watchpoint watching the same memory as this read | |
5368 | watchpoint. | |
5369 | ||
5370 | If we're watching memory writes as well as reads, | |
5371 | ignore watchpoint hits when we find that the | |
5372 | value hasn't changed, as reads don't cause | |
5373 | changes. This still gives false positives when | |
5374 | the program writes the same value to memory as | |
5375 | what there was already in memory (we will confuse | |
5376 | it for a read), but it's much better than | |
5377 | nothing. */ | |
5378 | ||
5379 | int other_write_watchpoint = 0; | |
5380 | ||
5381 | if (bl->watchpoint_type == hw_read) | |
5382 | { | |
5383 | struct breakpoint *other_b; | |
5384 | ||
5385 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5386 | if (other_b->type == bp_hardware_watchpoint |
5387 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5388 | { |
3a5c3e22 PA |
5389 | struct watchpoint *other_w = |
5390 | (struct watchpoint *) other_b; | |
5391 | ||
5392 | if (other_w->watchpoint_triggered | |
5393 | == watch_triggered_yes) | |
5394 | { | |
5395 | other_write_watchpoint = 1; | |
5396 | break; | |
5397 | } | |
85d721b8 PA |
5398 | } |
5399 | } | |
5400 | ||
5401 | if (other_write_watchpoint | |
5402 | || bl->watchpoint_type == hw_access) | |
5403 | { | |
5404 | /* We're watching the same memory for writes, | |
5405 | and the value changed since the last time we | |
5406 | updated it, so this trap must be for a write. | |
5407 | Ignore it. */ | |
5408 | bs->print_it = print_it_noop; | |
5409 | bs->stop = 0; | |
5410 | } | |
18a18393 VP |
5411 | } |
5412 | break; | |
5413 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5414 | if (b->base.type == bp_hardware_watchpoint |
5415 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5416 | { |
5417 | /* Don't stop: write watchpoints shouldn't fire if | |
5418 | the value hasn't changed. */ | |
5419 | bs->print_it = print_it_noop; | |
5420 | bs->stop = 0; | |
5421 | } | |
5422 | /* Stop. */ | |
5423 | break; | |
5424 | default: | |
5425 | /* Can't happen. */ | |
5426 | case 0: | |
5427 | /* Error from catch_errors. */ | |
468afe6c | 5428 | { |
0e454242 | 5429 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5430 | { |
5431 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5432 | b->base.number); | |
5433 | } | |
5434 | watchpoint_del_at_next_stop (b); | |
5435 | /* We've already printed what needs to be printed. */ | |
5436 | bs->print_it = print_it_done; | |
5437 | } | |
18a18393 VP |
5438 | break; |
5439 | } | |
5440 | } | |
5441 | else /* must_check_value == 0 */ | |
5442 | { | |
5443 | /* This is a case where some watchpoint(s) triggered, but | |
5444 | not at the address of this watchpoint, or else no | |
5445 | watchpoint triggered after all. So don't print | |
5446 | anything for this watchpoint. */ | |
5447 | bs->print_it = print_it_noop; | |
5448 | bs->stop = 0; | |
5449 | } | |
5450 | } | |
5451 | } | |
5452 | ||
7d4df6a4 DE |
5453 | /* For breakpoints that are currently marked as telling gdb to stop, |
5454 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5455 | of breakpoint referred to by BS. If we should not stop for this |
5456 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5457 | |
18a18393 VP |
5458 | static void |
5459 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5460 | { | |
2bdf28a0 JK |
5461 | const struct bp_location *bl; |
5462 | struct breakpoint *b; | |
7d4df6a4 DE |
5463 | int value_is_zero = 0; |
5464 | struct expression *cond; | |
5465 | ||
5466 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5467 | |
5468 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5469 | bl = bs->bp_location_at; |
2bdf28a0 | 5470 | gdb_assert (bl != NULL); |
f431efe5 | 5471 | b = bs->breakpoint_at; |
2bdf28a0 | 5472 | gdb_assert (b != NULL); |
18a18393 | 5473 | |
b775012e LM |
5474 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5475 | need to do so again since GDB does not know if we stopped due to a | |
5476 | breakpoint or a single step breakpoint. */ | |
5477 | ||
18a18393 | 5478 | if (frame_id_p (b->frame_id) |
edb3359d | 5479 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5480 | { |
7d4df6a4 DE |
5481 | bs->stop = 0; |
5482 | return; | |
5483 | } | |
60e1c644 | 5484 | |
12ab52e9 PA |
5485 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5486 | evaluating the condition if this isn't the specified | |
5487 | thread/task. */ | |
5d5658a1 | 5488 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5489 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5490 | ||
6c1b0f7b DE |
5491 | { |
5492 | bs->stop = 0; | |
5493 | return; | |
5494 | } | |
5495 | ||
6dddc817 DE |
5496 | /* Evaluate extension language breakpoints that have a "stop" method |
5497 | implemented. */ | |
5498 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5499 | |
7d4df6a4 DE |
5500 | if (is_watchpoint (b)) |
5501 | { | |
5502 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5503 | |
4d01a485 | 5504 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5505 | } |
5506 | else | |
4d01a485 | 5507 | cond = bl->cond.get (); |
60e1c644 | 5508 | |
7d4df6a4 DE |
5509 | if (cond && b->disposition != disp_del_at_next_stop) |
5510 | { | |
5511 | int within_current_scope = 1; | |
5512 | struct watchpoint * w; | |
60e1c644 | 5513 | |
7d4df6a4 DE |
5514 | /* We use value_mark and value_free_to_mark because it could |
5515 | be a long time before we return to the command level and | |
5516 | call free_all_values. We can't call free_all_values | |
5517 | because we might be in the middle of evaluating a | |
5518 | function call. */ | |
5519 | struct value *mark = value_mark (); | |
5520 | ||
5521 | if (is_watchpoint (b)) | |
5522 | w = (struct watchpoint *) b; | |
5523 | else | |
5524 | w = NULL; | |
5525 | ||
5526 | /* Need to select the frame, with all that implies so that | |
5527 | the conditions will have the right context. Because we | |
5528 | use the frame, we will not see an inlined function's | |
5529 | variables when we arrive at a breakpoint at the start | |
5530 | of the inlined function; the current frame will be the | |
5531 | call site. */ | |
5532 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5533 | select_frame (get_current_frame ()); | |
5534 | else | |
18a18393 | 5535 | { |
7d4df6a4 DE |
5536 | struct frame_info *frame; |
5537 | ||
5538 | /* For local watchpoint expressions, which particular | |
5539 | instance of a local is being watched matters, so we | |
5540 | keep track of the frame to evaluate the expression | |
5541 | in. To evaluate the condition however, it doesn't | |
5542 | really matter which instantiation of the function | |
5543 | where the condition makes sense triggers the | |
5544 | watchpoint. This allows an expression like "watch | |
5545 | global if q > 10" set in `func', catch writes to | |
5546 | global on all threads that call `func', or catch | |
5547 | writes on all recursive calls of `func' by a single | |
5548 | thread. We simply always evaluate the condition in | |
5549 | the innermost frame that's executing where it makes | |
5550 | sense to evaluate the condition. It seems | |
5551 | intuitive. */ | |
5552 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5553 | if (frame != NULL) | |
5554 | select_frame (frame); | |
5555 | else | |
5556 | within_current_scope = 0; | |
18a18393 | 5557 | } |
7d4df6a4 DE |
5558 | if (within_current_scope) |
5559 | value_is_zero | |
5560 | = catch_errors (breakpoint_cond_eval, cond, | |
5561 | "Error in testing breakpoint condition:\n", | |
5562 | RETURN_MASK_ALL); | |
5563 | else | |
18a18393 | 5564 | { |
7d4df6a4 DE |
5565 | warning (_("Watchpoint condition cannot be tested " |
5566 | "in the current scope")); | |
5567 | /* If we failed to set the right context for this | |
5568 | watchpoint, unconditionally report it. */ | |
5569 | value_is_zero = 0; | |
18a18393 | 5570 | } |
7d4df6a4 DE |
5571 | /* FIXME-someday, should give breakpoint #. */ |
5572 | value_free_to_mark (mark); | |
18a18393 | 5573 | } |
7d4df6a4 DE |
5574 | |
5575 | if (cond && value_is_zero) | |
5576 | { | |
5577 | bs->stop = 0; | |
5578 | } | |
7d4df6a4 DE |
5579 | else if (b->ignore_count > 0) |
5580 | { | |
5581 | b->ignore_count--; | |
5582 | bs->stop = 0; | |
5583 | /* Increase the hit count even though we don't stop. */ | |
5584 | ++(b->hit_count); | |
5585 | observer_notify_breakpoint_modified (b); | |
5586 | } | |
18a18393 VP |
5587 | } |
5588 | ||
1cf4d951 PA |
5589 | /* Returns true if we need to track moribund locations of LOC's type |
5590 | on the current target. */ | |
5591 | ||
5592 | static int | |
5593 | need_moribund_for_location_type (struct bp_location *loc) | |
5594 | { | |
5595 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5596 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5597 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5598 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5599 | } | |
5600 | ||
18a18393 | 5601 | |
9709f61c | 5602 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5603 | BP_ADDR in thread PTID. |
c906108c | 5604 | |
d983da9c | 5605 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5606 | don't understand this stop. Result is a chain of bpstat's such |
5607 | that: | |
c906108c | 5608 | |
c5aa993b | 5609 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5610 | |
c5aa993b | 5611 | if we understand why we stopped, the result is not null. |
c906108c | 5612 | |
c5aa993b JM |
5613 | Each element of the chain refers to a particular breakpoint or |
5614 | watchpoint at which we have stopped. (We may have stopped for | |
5615 | several reasons concurrently.) | |
c906108c | 5616 | |
c5aa993b JM |
5617 | Each element of the chain has valid next, breakpoint_at, |
5618 | commands, FIXME??? fields. */ | |
c906108c SS |
5619 | |
5620 | bpstat | |
6c95b8df | 5621 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5622 | CORE_ADDR bp_addr, ptid_t ptid, |
5623 | const struct target_waitstatus *ws) | |
c906108c | 5624 | { |
0d381245 | 5625 | struct breakpoint *b = NULL; |
afe38095 | 5626 | struct bp_location *bl; |
20874c92 | 5627 | struct bp_location *loc; |
5760d0ab JK |
5628 | /* First item of allocated bpstat's. */ |
5629 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5630 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5631 | bpstat bs; |
20874c92 | 5632 | int ix; |
429374b8 | 5633 | int need_remove_insert; |
f431efe5 | 5634 | int removed_any; |
c906108c | 5635 | |
f431efe5 PA |
5636 | /* First, build the bpstat chain with locations that explain a |
5637 | target stop, while being careful to not set the target running, | |
5638 | as that may invalidate locations (in particular watchpoint | |
5639 | locations are recreated). Resuming will happen here with | |
5640 | breakpoint conditions or watchpoint expressions that include | |
5641 | inferior function calls. */ | |
c5aa993b | 5642 | |
429374b8 JK |
5643 | ALL_BREAKPOINTS (b) |
5644 | { | |
1a853c52 | 5645 | if (!breakpoint_enabled (b)) |
429374b8 | 5646 | continue; |
a5606eee | 5647 | |
429374b8 JK |
5648 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5649 | { | |
4a64f543 MS |
5650 | /* For hardware watchpoints, we look only at the first |
5651 | location. The watchpoint_check function will work on the | |
5652 | entire expression, not the individual locations. For | |
5653 | read watchpoints, the watchpoints_triggered function has | |
5654 | checked all locations already. */ | |
429374b8 JK |
5655 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5656 | break; | |
18a18393 | 5657 | |
f6592439 | 5658 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5659 | continue; |
c5aa993b | 5660 | |
09ac7c10 | 5661 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5662 | continue; |
c5aa993b | 5663 | |
4a64f543 MS |
5664 | /* Come here if it's a watchpoint, or if the break address |
5665 | matches. */ | |
c5aa993b | 5666 | |
4a64f543 MS |
5667 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5668 | explain stop. */ | |
c5aa993b | 5669 | |
f431efe5 PA |
5670 | /* Assume we stop. Should we find a watchpoint that is not |
5671 | actually triggered, or if the condition of the breakpoint | |
5672 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5673 | bs->stop = 1; |
5674 | bs->print = 1; | |
d983da9c | 5675 | |
f431efe5 PA |
5676 | /* If this is a scope breakpoint, mark the associated |
5677 | watchpoint as triggered so that we will handle the | |
5678 | out-of-scope event. We'll get to the watchpoint next | |
5679 | iteration. */ | |
d0fb5eae | 5680 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5681 | { |
5682 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5683 | ||
5684 | w->watchpoint_triggered = watch_triggered_yes; | |
5685 | } | |
f431efe5 PA |
5686 | } |
5687 | } | |
5688 | ||
7c16b83e | 5689 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5690 | if (!target_supports_stopped_by_sw_breakpoint () |
5691 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5692 | { |
1cf4d951 | 5693 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5694 | { |
1cf4d951 PA |
5695 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5696 | && need_moribund_for_location_type (loc)) | |
5697 | { | |
5698 | bs = bpstat_alloc (loc, &bs_link); | |
5699 | /* For hits of moribund locations, we should just proceed. */ | |
5700 | bs->stop = 0; | |
5701 | bs->print = 0; | |
5702 | bs->print_it = print_it_noop; | |
5703 | } | |
f431efe5 PA |
5704 | } |
5705 | } | |
5706 | ||
edcc5120 TT |
5707 | /* A bit of special processing for shlib breakpoints. We need to |
5708 | process solib loading here, so that the lists of loaded and | |
5709 | unloaded libraries are correct before we handle "catch load" and | |
5710 | "catch unload". */ | |
5711 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5712 | { | |
5d268276 | 5713 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5714 | { |
5715 | handle_solib_event (); | |
5716 | break; | |
5717 | } | |
5718 | } | |
5719 | ||
f431efe5 PA |
5720 | /* Now go through the locations that caused the target to stop, and |
5721 | check whether we're interested in reporting this stop to higher | |
5722 | layers, or whether we should resume the target transparently. */ | |
5723 | ||
5724 | removed_any = 0; | |
5725 | ||
5760d0ab | 5726 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5727 | { |
5728 | if (!bs->stop) | |
5729 | continue; | |
5730 | ||
f431efe5 | 5731 | b = bs->breakpoint_at; |
348d480f PA |
5732 | b->ops->check_status (bs); |
5733 | if (bs->stop) | |
28010a5d | 5734 | { |
348d480f | 5735 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5736 | |
429374b8 JK |
5737 | if (bs->stop) |
5738 | { | |
5739 | ++(b->hit_count); | |
8d3788bd | 5740 | observer_notify_breakpoint_modified (b); |
c906108c | 5741 | |
4a64f543 | 5742 | /* We will stop here. */ |
429374b8 JK |
5743 | if (b->disposition == disp_disable) |
5744 | { | |
816338b5 | 5745 | --(b->enable_count); |
1a853c52 | 5746 | if (b->enable_count <= 0) |
429374b8 | 5747 | b->enable_state = bp_disabled; |
f431efe5 | 5748 | removed_any = 1; |
429374b8 JK |
5749 | } |
5750 | if (b->silent) | |
5751 | bs->print = 0; | |
5752 | bs->commands = b->commands; | |
9add0f1b | 5753 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5754 | if (command_line_is_silent (bs->commands |
5755 | ? bs->commands->commands : NULL)) | |
5756 | bs->print = 0; | |
9d6e6e84 HZ |
5757 | |
5758 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5759 | } |
5760 | ||
348d480f | 5761 | } |
a9b3a50f PA |
5762 | |
5763 | /* Print nothing for this entry if we don't stop or don't | |
5764 | print. */ | |
5765 | if (!bs->stop || !bs->print) | |
5766 | bs->print_it = print_it_noop; | |
429374b8 | 5767 | } |
876fa593 | 5768 | |
d983da9c DJ |
5769 | /* If we aren't stopping, the value of some hardware watchpoint may |
5770 | not have changed, but the intermediate memory locations we are | |
5771 | watching may have. Don't bother if we're stopping; this will get | |
5772 | done later. */ | |
d832cb68 | 5773 | need_remove_insert = 0; |
5760d0ab JK |
5774 | if (! bpstat_causes_stop (bs_head)) |
5775 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5776 | if (!bs->stop |
f431efe5 PA |
5777 | && bs->breakpoint_at |
5778 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5779 | { |
3a5c3e22 PA |
5780 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5781 | ||
5782 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5783 | need_remove_insert = 1; |
d983da9c DJ |
5784 | } |
5785 | ||
d832cb68 | 5786 | if (need_remove_insert) |
44702360 | 5787 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5788 | else if (removed_any) |
44702360 | 5789 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5790 | |
5760d0ab | 5791 | return bs_head; |
c906108c | 5792 | } |
628fe4e4 JK |
5793 | |
5794 | static void | |
5795 | handle_jit_event (void) | |
5796 | { | |
5797 | struct frame_info *frame; | |
5798 | struct gdbarch *gdbarch; | |
5799 | ||
243a9253 PA |
5800 | if (debug_infrun) |
5801 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5802 | ||
628fe4e4 JK |
5803 | /* Switch terminal for any messages produced by |
5804 | breakpoint_re_set. */ | |
5805 | target_terminal_ours_for_output (); | |
5806 | ||
5807 | frame = get_current_frame (); | |
5808 | gdbarch = get_frame_arch (frame); | |
5809 | ||
5810 | jit_event_handler (gdbarch); | |
5811 | ||
5812 | target_terminal_inferior (); | |
5813 | } | |
5814 | ||
5815 | /* Prepare WHAT final decision for infrun. */ | |
5816 | ||
5817 | /* Decide what infrun needs to do with this bpstat. */ | |
5818 | ||
c906108c | 5819 | struct bpstat_what |
0e30163f | 5820 | bpstat_what (bpstat bs_head) |
c906108c | 5821 | { |
c906108c | 5822 | struct bpstat_what retval; |
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 | 5943 | case bp_jit_event: |
628fe4e4 | 5944 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5945 | break; |
c906108c | 5946 | case bp_call_dummy: |
53a5351d JM |
5947 | /* Make sure the action is stop (silent or noisy), |
5948 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5949 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5950 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5951 | break; |
5952 | case bp_std_terminate: | |
5953 | /* Make sure the action is stop (silent or noisy), | |
5954 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5955 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5956 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5957 | break; |
1042e4c0 | 5958 | case bp_tracepoint: |
7a697b8d | 5959 | case bp_fast_tracepoint: |
0fb4aa4b | 5960 | case bp_static_tracepoint: |
1042e4c0 SS |
5961 | /* Tracepoint hits should not be reported back to GDB, and |
5962 | if one got through somehow, it should have been filtered | |
5963 | out already. */ | |
5964 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5965 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5966 | break; |
5967 | case bp_gnu_ifunc_resolver: | |
5968 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5969 | this_action = BPSTAT_WHAT_SINGLE; | |
5970 | break; | |
5971 | case bp_gnu_ifunc_resolver_return: | |
5972 | /* The breakpoint will be removed, execution will restart from the | |
5973 | PC of the former breakpoint. */ | |
5974 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5975 | break; | |
e7e0cddf SS |
5976 | |
5977 | case bp_dprintf: | |
a11cfd87 HZ |
5978 | if (bs->stop) |
5979 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5980 | else | |
5981 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5982 | break; |
5983 | ||
628fe4e4 JK |
5984 | default: |
5985 | internal_error (__FILE__, __LINE__, | |
5986 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5987 | } |
628fe4e4 | 5988 | |
325fac50 | 5989 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5990 | } |
628fe4e4 | 5991 | |
243a9253 PA |
5992 | return retval; |
5993 | } | |
628fe4e4 | 5994 | |
243a9253 PA |
5995 | void |
5996 | bpstat_run_callbacks (bpstat bs_head) | |
5997 | { | |
5998 | bpstat bs; | |
628fe4e4 | 5999 | |
0e30163f JK |
6000 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6001 | { | |
6002 | struct breakpoint *b = bs->breakpoint_at; | |
6003 | ||
6004 | if (b == NULL) | |
6005 | continue; | |
6006 | switch (b->type) | |
6007 | { | |
243a9253 PA |
6008 | case bp_jit_event: |
6009 | handle_jit_event (); | |
6010 | break; | |
0e30163f JK |
6011 | case bp_gnu_ifunc_resolver: |
6012 | gnu_ifunc_resolver_stop (b); | |
6013 | break; | |
6014 | case bp_gnu_ifunc_resolver_return: | |
6015 | gnu_ifunc_resolver_return_stop (b); | |
6016 | break; | |
6017 | } | |
6018 | } | |
c906108c SS |
6019 | } |
6020 | ||
6021 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6022 | without hardware support). This isn't related to a specific bpstat, | |
6023 | just to things like whether watchpoints are set. */ | |
6024 | ||
c5aa993b | 6025 | int |
fba45db2 | 6026 | bpstat_should_step (void) |
c906108c SS |
6027 | { |
6028 | struct breakpoint *b; | |
cc59ec59 | 6029 | |
c906108c | 6030 | ALL_BREAKPOINTS (b) |
717a8278 | 6031 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6032 | return 1; |
c906108c SS |
6033 | return 0; |
6034 | } | |
6035 | ||
67822962 PA |
6036 | int |
6037 | bpstat_causes_stop (bpstat bs) | |
6038 | { | |
6039 | for (; bs != NULL; bs = bs->next) | |
6040 | if (bs->stop) | |
6041 | return 1; | |
6042 | ||
6043 | return 0; | |
6044 | } | |
6045 | ||
c906108c | 6046 | \f |
c5aa993b | 6047 | |
170b53b2 UW |
6048 | /* Compute a string of spaces suitable to indent the next line |
6049 | so it starts at the position corresponding to the table column | |
6050 | named COL_NAME in the currently active table of UIOUT. */ | |
6051 | ||
6052 | static char * | |
6053 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6054 | { | |
6055 | static char wrap_indent[80]; | |
6056 | int i, total_width, width, align; | |
c5209615 | 6057 | const char *text; |
170b53b2 UW |
6058 | |
6059 | total_width = 0; | |
112e8700 | 6060 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
6061 | { |
6062 | if (strcmp (text, col_name) == 0) | |
6063 | { | |
6064 | gdb_assert (total_width < sizeof wrap_indent); | |
6065 | memset (wrap_indent, ' ', total_width); | |
6066 | wrap_indent[total_width] = 0; | |
6067 | ||
6068 | return wrap_indent; | |
6069 | } | |
6070 | ||
6071 | total_width += width + 1; | |
6072 | } | |
6073 | ||
6074 | return NULL; | |
6075 | } | |
6076 | ||
b775012e LM |
6077 | /* Determine if the locations of this breakpoint will have their conditions |
6078 | evaluated by the target, host or a mix of both. Returns the following: | |
6079 | ||
6080 | "host": Host evals condition. | |
6081 | "host or target": Host or Target evals condition. | |
6082 | "target": Target evals condition. | |
6083 | */ | |
6084 | ||
6085 | static const char * | |
6086 | bp_condition_evaluator (struct breakpoint *b) | |
6087 | { | |
6088 | struct bp_location *bl; | |
6089 | char host_evals = 0; | |
6090 | char target_evals = 0; | |
6091 | ||
6092 | if (!b) | |
6093 | return NULL; | |
6094 | ||
6095 | if (!is_breakpoint (b)) | |
6096 | return NULL; | |
6097 | ||
6098 | if (gdb_evaluates_breakpoint_condition_p () | |
6099 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6100 | return condition_evaluation_host; | |
6101 | ||
6102 | for (bl = b->loc; bl; bl = bl->next) | |
6103 | { | |
6104 | if (bl->cond_bytecode) | |
6105 | target_evals++; | |
6106 | else | |
6107 | host_evals++; | |
6108 | } | |
6109 | ||
6110 | if (host_evals && target_evals) | |
6111 | return condition_evaluation_both; | |
6112 | else if (target_evals) | |
6113 | return condition_evaluation_target; | |
6114 | else | |
6115 | return condition_evaluation_host; | |
6116 | } | |
6117 | ||
6118 | /* Determine the breakpoint location's condition evaluator. This is | |
6119 | similar to bp_condition_evaluator, but for locations. */ | |
6120 | ||
6121 | static const char * | |
6122 | bp_location_condition_evaluator (struct bp_location *bl) | |
6123 | { | |
6124 | if (bl && !is_breakpoint (bl->owner)) | |
6125 | return NULL; | |
6126 | ||
6127 | if (gdb_evaluates_breakpoint_condition_p () | |
6128 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6129 | return condition_evaluation_host; | |
6130 | ||
6131 | if (bl && bl->cond_bytecode) | |
6132 | return condition_evaluation_target; | |
6133 | else | |
6134 | return condition_evaluation_host; | |
6135 | } | |
6136 | ||
859825b8 JK |
6137 | /* Print the LOC location out of the list of B->LOC locations. */ |
6138 | ||
170b53b2 UW |
6139 | static void |
6140 | print_breakpoint_location (struct breakpoint *b, | |
6141 | struct bp_location *loc) | |
0d381245 | 6142 | { |
79a45e25 | 6143 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6144 | struct cleanup *old_chain = save_current_program_space (); |
6145 | ||
859825b8 JK |
6146 | if (loc != NULL && loc->shlib_disabled) |
6147 | loc = NULL; | |
6148 | ||
6c95b8df PA |
6149 | if (loc != NULL) |
6150 | set_current_program_space (loc->pspace); | |
6151 | ||
56435ebe | 6152 | if (b->display_canonical) |
112e8700 | 6153 | uiout->field_string ("what", event_location_to_string (b->location)); |
2f202fde | 6154 | else if (loc && loc->symtab) |
0d381245 VP |
6155 | { |
6156 | struct symbol *sym | |
6157 | = find_pc_sect_function (loc->address, loc->section); | |
6158 | if (sym) | |
6159 | { | |
112e8700 SM |
6160 | uiout->text ("in "); |
6161 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6162 | uiout->text (" "); | |
6163 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6164 | uiout->text ("at "); | |
0d381245 | 6165 | } |
112e8700 | 6166 | uiout->field_string ("file", |
05cba821 | 6167 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6168 | uiout->text (":"); |
05cba821 | 6169 | |
112e8700 SM |
6170 | if (uiout->is_mi_like_p ()) |
6171 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6172 | |
112e8700 | 6173 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6174 | } |
859825b8 | 6175 | else if (loc) |
0d381245 | 6176 | { |
d7e74731 | 6177 | string_file stb; |
170b53b2 | 6178 | |
d7e74731 | 6179 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6180 | demangle, ""); |
112e8700 | 6181 | uiout->field_stream ("at", stb); |
0d381245 | 6182 | } |
859825b8 | 6183 | else |
f00aae0f | 6184 | { |
112e8700 | 6185 | uiout->field_string ("pending", event_location_to_string (b->location)); |
f00aae0f KS |
6186 | /* If extra_string is available, it could be holding a condition |
6187 | or dprintf arguments. In either case, make sure it is printed, | |
6188 | too, but only for non-MI streams. */ | |
112e8700 | 6189 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6190 | { |
6191 | if (b->type == bp_dprintf) | |
112e8700 | 6192 | uiout->text (","); |
f00aae0f | 6193 | else |
112e8700 SM |
6194 | uiout->text (" "); |
6195 | uiout->text (b->extra_string); | |
f00aae0f KS |
6196 | } |
6197 | } | |
6c95b8df | 6198 | |
b775012e LM |
6199 | if (loc && is_breakpoint (b) |
6200 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6201 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6202 | { | |
112e8700 SM |
6203 | uiout->text (" ("); |
6204 | uiout->field_string ("evaluated-by", | |
b775012e | 6205 | bp_location_condition_evaluator (loc)); |
112e8700 | 6206 | uiout->text (")"); |
b775012e LM |
6207 | } |
6208 | ||
6c95b8df | 6209 | do_cleanups (old_chain); |
0d381245 VP |
6210 | } |
6211 | ||
269b11a2 PA |
6212 | static const char * |
6213 | bptype_string (enum bptype type) | |
c906108c | 6214 | { |
c4093a6a JM |
6215 | struct ep_type_description |
6216 | { | |
6217 | enum bptype type; | |
a121b7c1 | 6218 | const char *description; |
c4093a6a JM |
6219 | }; |
6220 | static struct ep_type_description bptypes[] = | |
c906108c | 6221 | { |
c5aa993b JM |
6222 | {bp_none, "?deleted?"}, |
6223 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6224 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6225 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6226 | {bp_until, "until"}, |
6227 | {bp_finish, "finish"}, | |
6228 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6229 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6230 | {bp_read_watchpoint, "read watchpoint"}, |
6231 | {bp_access_watchpoint, "acc watchpoint"}, | |
6232 | {bp_longjmp, "longjmp"}, | |
6233 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6234 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6235 | {bp_exception, "exception"}, |
6236 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6237 | {bp_step_resume, "step resume"}, |
2c03e5be | 6238 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6239 | {bp_watchpoint_scope, "watchpoint scope"}, |
6240 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6241 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6242 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6243 | {bp_thread_event, "thread events"}, |
1900040c | 6244 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6245 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6246 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6247 | {bp_exception_master, "exception master"}, |
ce78b96d | 6248 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6249 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6250 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6251 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6252 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6253 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6254 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6255 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6256 | }; |
269b11a2 PA |
6257 | |
6258 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6259 | || ((int) type != bptypes[(int) type].type)) | |
6260 | internal_error (__FILE__, __LINE__, | |
6261 | _("bptypes table does not describe type #%d."), | |
6262 | (int) type); | |
6263 | ||
6264 | return bptypes[(int) type].description; | |
6265 | } | |
6266 | ||
998580f1 MK |
6267 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6268 | For CLI, prefix the list with the string 'inf'. */ | |
6269 | ||
6270 | static void | |
6271 | output_thread_groups (struct ui_out *uiout, | |
6272 | const char *field_name, | |
6273 | VEC(int) *inf_num, | |
6274 | int mi_only) | |
6275 | { | |
752eb8b4 | 6276 | struct cleanup *back_to; |
112e8700 | 6277 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6278 | int inf; |
6279 | int i; | |
6280 | ||
6281 | /* For backward compatibility, don't display inferiors in CLI unless | |
6282 | there are several. Always display them for MI. */ | |
6283 | if (!is_mi && mi_only) | |
6284 | return; | |
6285 | ||
752eb8b4 TT |
6286 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6287 | ||
998580f1 MK |
6288 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6289 | { | |
6290 | if (is_mi) | |
6291 | { | |
6292 | char mi_group[10]; | |
6293 | ||
6294 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6295 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6296 | } |
6297 | else | |
6298 | { | |
6299 | if (i == 0) | |
112e8700 | 6300 | uiout->text (" inf "); |
998580f1 | 6301 | else |
112e8700 | 6302 | uiout->text (", "); |
998580f1 | 6303 | |
112e8700 | 6304 | uiout->text (plongest (inf)); |
998580f1 MK |
6305 | } |
6306 | } | |
6307 | ||
6308 | do_cleanups (back_to); | |
6309 | } | |
6310 | ||
269b11a2 PA |
6311 | /* Print B to gdb_stdout. */ |
6312 | ||
6313 | static void | |
6314 | print_one_breakpoint_location (struct breakpoint *b, | |
6315 | struct bp_location *loc, | |
6316 | int loc_number, | |
6317 | struct bp_location **last_loc, | |
269b11a2 PA |
6318 | int allflag) |
6319 | { | |
6320 | struct command_line *l; | |
c2c6d25f | 6321 | static char bpenables[] = "nynny"; |
c906108c | 6322 | |
79a45e25 | 6323 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6324 | int header_of_multiple = 0; |
6325 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6326 | struct value_print_options opts; |
6327 | ||
6328 | get_user_print_options (&opts); | |
0d381245 VP |
6329 | |
6330 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6331 | /* See comment in print_one_breakpoint concerning treatment of |
6332 | breakpoints with single disabled location. */ | |
0d381245 VP |
6333 | if (loc == NULL |
6334 | && (b->loc != NULL | |
6335 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6336 | header_of_multiple = 1; | |
6337 | if (loc == NULL) | |
6338 | loc = b->loc; | |
6339 | ||
c4093a6a JM |
6340 | annotate_record (); |
6341 | ||
6342 | /* 1 */ | |
6343 | annotate_field (0); | |
0d381245 VP |
6344 | if (part_of_multiple) |
6345 | { | |
6346 | char *formatted; | |
0c6773c1 | 6347 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6348 | uiout->field_string ("number", formatted); |
0d381245 VP |
6349 | xfree (formatted); |
6350 | } | |
6351 | else | |
6352 | { | |
112e8700 | 6353 | uiout->field_int ("number", b->number); |
0d381245 | 6354 | } |
c4093a6a JM |
6355 | |
6356 | /* 2 */ | |
6357 | annotate_field (1); | |
0d381245 | 6358 | if (part_of_multiple) |
112e8700 | 6359 | uiout->field_skip ("type"); |
269b11a2 | 6360 | else |
112e8700 | 6361 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6362 | |
6363 | /* 3 */ | |
6364 | annotate_field (2); | |
0d381245 | 6365 | if (part_of_multiple) |
112e8700 | 6366 | uiout->field_skip ("disp"); |
0d381245 | 6367 | else |
112e8700 | 6368 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6369 | |
c4093a6a JM |
6370 | |
6371 | /* 4 */ | |
6372 | annotate_field (3); | |
0d381245 | 6373 | if (part_of_multiple) |
112e8700 | 6374 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6375 | else |
112e8700 SM |
6376 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6377 | uiout->spaces (2); | |
0d381245 | 6378 | |
c4093a6a JM |
6379 | |
6380 | /* 5 and 6 */ | |
3086aeae | 6381 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6382 | { |
4a64f543 MS |
6383 | /* Although the print_one can possibly print all locations, |
6384 | calling it here is not likely to get any nice result. So, | |
6385 | make sure there's just one location. */ | |
0d381245 | 6386 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6387 | b->ops->print_one (b, last_loc); |
0d381245 | 6388 | } |
3086aeae DJ |
6389 | else |
6390 | switch (b->type) | |
6391 | { | |
6392 | case bp_none: | |
6393 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6394 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6395 | break; |
c906108c | 6396 | |
3086aeae DJ |
6397 | case bp_watchpoint: |
6398 | case bp_hardware_watchpoint: | |
6399 | case bp_read_watchpoint: | |
6400 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6401 | { |
6402 | struct watchpoint *w = (struct watchpoint *) b; | |
6403 | ||
6404 | /* Field 4, the address, is omitted (which makes the columns | |
6405 | not line up too nicely with the headers, but the effect | |
6406 | is relatively readable). */ | |
6407 | if (opts.addressprint) | |
112e8700 | 6408 | uiout->field_skip ("addr"); |
3a5c3e22 | 6409 | annotate_field (5); |
112e8700 | 6410 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6411 | } |
3086aeae DJ |
6412 | break; |
6413 | ||
3086aeae DJ |
6414 | case bp_breakpoint: |
6415 | case bp_hardware_breakpoint: | |
7c16b83e | 6416 | case bp_single_step: |
3086aeae DJ |
6417 | case bp_until: |
6418 | case bp_finish: | |
6419 | case bp_longjmp: | |
6420 | case bp_longjmp_resume: | |
e2e4d78b | 6421 | case bp_longjmp_call_dummy: |
186c406b TT |
6422 | case bp_exception: |
6423 | case bp_exception_resume: | |
3086aeae | 6424 | case bp_step_resume: |
2c03e5be | 6425 | case bp_hp_step_resume: |
3086aeae DJ |
6426 | case bp_watchpoint_scope: |
6427 | case bp_call_dummy: | |
aa7d318d | 6428 | case bp_std_terminate: |
3086aeae DJ |
6429 | case bp_shlib_event: |
6430 | case bp_thread_event: | |
6431 | case bp_overlay_event: | |
0fd8e87f | 6432 | case bp_longjmp_master: |
aa7d318d | 6433 | case bp_std_terminate_master: |
186c406b | 6434 | case bp_exception_master: |
1042e4c0 | 6435 | case bp_tracepoint: |
7a697b8d | 6436 | case bp_fast_tracepoint: |
0fb4aa4b | 6437 | case bp_static_tracepoint: |
e7e0cddf | 6438 | case bp_dprintf: |
4efc6507 | 6439 | case bp_jit_event: |
0e30163f JK |
6440 | case bp_gnu_ifunc_resolver: |
6441 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6442 | if (opts.addressprint) |
3086aeae DJ |
6443 | { |
6444 | annotate_field (4); | |
54e52265 | 6445 | if (header_of_multiple) |
112e8700 | 6446 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6447 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6448 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6449 | else |
112e8700 | 6450 | uiout->field_core_addr ("addr", |
5af949e3 | 6451 | loc->gdbarch, loc->address); |
3086aeae DJ |
6452 | } |
6453 | annotate_field (5); | |
0d381245 | 6454 | if (!header_of_multiple) |
170b53b2 | 6455 | print_breakpoint_location (b, loc); |
0d381245 | 6456 | if (b->loc) |
a6d9a66e | 6457 | *last_loc = b->loc; |
3086aeae DJ |
6458 | break; |
6459 | } | |
c906108c | 6460 | |
6c95b8df | 6461 | |
998580f1 | 6462 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6463 | { |
6464 | struct inferior *inf; | |
998580f1 MK |
6465 | VEC(int) *inf_num = NULL; |
6466 | int mi_only = 1; | |
6c95b8df | 6467 | |
998580f1 | 6468 | ALL_INFERIORS (inf) |
6c95b8df PA |
6469 | { |
6470 | if (inf->pspace == loc->pspace) | |
998580f1 | 6471 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6472 | } |
998580f1 MK |
6473 | |
6474 | /* For backward compatibility, don't display inferiors in CLI unless | |
6475 | there are several. Always display for MI. */ | |
6476 | if (allflag | |
6477 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6478 | && (number_of_program_spaces () > 1 | |
6479 | || number_of_inferiors () > 1) | |
6480 | /* LOC is for existing B, it cannot be in | |
6481 | moribund_locations and thus having NULL OWNER. */ | |
6482 | && loc->owner->type != bp_catchpoint)) | |
6483 | mi_only = 0; | |
6484 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6485 | VEC_free (int, inf_num); | |
6c95b8df PA |
6486 | } |
6487 | ||
4a306c9a | 6488 | if (!part_of_multiple) |
c4093a6a | 6489 | { |
4a306c9a JB |
6490 | if (b->thread != -1) |
6491 | { | |
6492 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6493 | "stop only in" line a little further down. */ |
112e8700 SM |
6494 | uiout->text (" thread "); |
6495 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6496 | } |
6497 | else if (b->task != 0) | |
6498 | { | |
112e8700 SM |
6499 | uiout->text (" task "); |
6500 | uiout->field_int ("task", b->task); | |
4a306c9a | 6501 | } |
c4093a6a | 6502 | } |
f1310107 | 6503 | |
112e8700 | 6504 | uiout->text ("\n"); |
f1310107 | 6505 | |
348d480f | 6506 | if (!part_of_multiple) |
f1310107 TJB |
6507 | b->ops->print_one_detail (b, uiout); |
6508 | ||
0d381245 | 6509 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6510 | { |
6511 | annotate_field (6); | |
112e8700 | 6512 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6513 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6514 | the frame ID. */ |
112e8700 | 6515 | uiout->field_core_addr ("frame", |
5af949e3 | 6516 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6517 | uiout->text ("\n"); |
c4093a6a JM |
6518 | } |
6519 | ||
28010a5d | 6520 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6521 | { |
6522 | annotate_field (7); | |
d77f58be | 6523 | if (is_tracepoint (b)) |
112e8700 | 6524 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6525 | else |
112e8700 SM |
6526 | uiout->text ("\tstop only if "); |
6527 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6528 | |
6529 | /* Print whether the target is doing the breakpoint's condition | |
6530 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6531 | if (is_breakpoint (b) | |
6532 | && breakpoint_condition_evaluation_mode () | |
6533 | == condition_evaluation_target) | |
6534 | { | |
112e8700 SM |
6535 | uiout->text (" ("); |
6536 | uiout->field_string ("evaluated-by", | |
b775012e | 6537 | bp_condition_evaluator (b)); |
112e8700 | 6538 | uiout->text (" evals)"); |
b775012e | 6539 | } |
112e8700 | 6540 | uiout->text ("\n"); |
0101ce28 JJ |
6541 | } |
6542 | ||
0d381245 | 6543 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6544 | { |
4a64f543 | 6545 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6546 | uiout->text ("\tstop only in thread "); |
6547 | if (uiout->is_mi_like_p ()) | |
6548 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6549 | else |
6550 | { | |
6551 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6552 | ||
112e8700 | 6553 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6554 | } |
112e8700 | 6555 | uiout->text ("\n"); |
c4093a6a JM |
6556 | } |
6557 | ||
556ec64d YQ |
6558 | if (!part_of_multiple) |
6559 | { | |
6560 | if (b->hit_count) | |
31f56a27 YQ |
6561 | { |
6562 | /* FIXME should make an annotation for this. */ | |
6563 | if (is_catchpoint (b)) | |
112e8700 | 6564 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6565 | else if (is_tracepoint (b)) |
112e8700 | 6566 | uiout->text ("\ttracepoint"); |
31f56a27 | 6567 | else |
112e8700 SM |
6568 | uiout->text ("\tbreakpoint"); |
6569 | uiout->text (" already hit "); | |
6570 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6571 | if (b->hit_count == 1) |
112e8700 | 6572 | uiout->text (" time\n"); |
31f56a27 | 6573 | else |
112e8700 | 6574 | uiout->text (" times\n"); |
31f56a27 | 6575 | } |
556ec64d YQ |
6576 | else |
6577 | { | |
31f56a27 | 6578 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6579 | if (uiout->is_mi_like_p ()) |
6580 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6581 | } |
6582 | } | |
8b93c638 | 6583 | |
0d381245 | 6584 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6585 | { |
6586 | annotate_field (8); | |
112e8700 SM |
6587 | uiout->text ("\tignore next "); |
6588 | uiout->field_int ("ignore", b->ignore_count); | |
6589 | uiout->text (" hits\n"); | |
c4093a6a | 6590 | } |
059fb39f | 6591 | |
816338b5 SS |
6592 | /* Note that an enable count of 1 corresponds to "enable once" |
6593 | behavior, which is reported by the combination of enablement and | |
6594 | disposition, so we don't need to mention it here. */ | |
6595 | if (!part_of_multiple && b->enable_count > 1) | |
6596 | { | |
6597 | annotate_field (8); | |
112e8700 | 6598 | uiout->text ("\tdisable after "); |
816338b5 SS |
6599 | /* Tweak the wording to clarify that ignore and enable counts |
6600 | are distinct, and have additive effect. */ | |
6601 | if (b->ignore_count) | |
112e8700 | 6602 | uiout->text ("additional "); |
816338b5 | 6603 | else |
112e8700 SM |
6604 | uiout->text ("next "); |
6605 | uiout->field_int ("enable", b->enable_count); | |
6606 | uiout->text (" hits\n"); | |
816338b5 SS |
6607 | } |
6608 | ||
f196051f SS |
6609 | if (!part_of_multiple && is_tracepoint (b)) |
6610 | { | |
6611 | struct tracepoint *tp = (struct tracepoint *) b; | |
6612 | ||
6613 | if (tp->traceframe_usage) | |
6614 | { | |
112e8700 SM |
6615 | uiout->text ("\ttrace buffer usage "); |
6616 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6617 | uiout->text (" bytes\n"); | |
f196051f SS |
6618 | } |
6619 | } | |
d3ce09f5 | 6620 | |
9add0f1b | 6621 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6622 | if (!part_of_multiple && l) |
c4093a6a | 6623 | { |
3b31d625 EZ |
6624 | struct cleanup *script_chain; |
6625 | ||
c4093a6a | 6626 | annotate_field (9); |
3b31d625 | 6627 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6628 | print_command_lines (uiout, l, 4); |
3b31d625 | 6629 | do_cleanups (script_chain); |
c4093a6a | 6630 | } |
d24317b4 | 6631 | |
d9b3f62e | 6632 | if (is_tracepoint (b)) |
1042e4c0 | 6633 | { |
d9b3f62e PA |
6634 | struct tracepoint *t = (struct tracepoint *) b; |
6635 | ||
6636 | if (!part_of_multiple && t->pass_count) | |
6637 | { | |
6638 | annotate_field (10); | |
112e8700 SM |
6639 | uiout->text ("\tpass count "); |
6640 | uiout->field_int ("pass", t->pass_count); | |
6641 | uiout->text (" \n"); | |
d9b3f62e | 6642 | } |
f2a8bc8a YQ |
6643 | |
6644 | /* Don't display it when tracepoint or tracepoint location is | |
6645 | pending. */ | |
6646 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6647 | { | |
6648 | annotate_field (11); | |
6649 | ||
112e8700 SM |
6650 | if (uiout->is_mi_like_p ()) |
6651 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6652 | loc->inserted ? "y" : "n"); |
6653 | else | |
6654 | { | |
6655 | if (loc->inserted) | |
112e8700 | 6656 | uiout->text ("\t"); |
f2a8bc8a | 6657 | else |
112e8700 SM |
6658 | uiout->text ("\tnot "); |
6659 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6660 | } |
6661 | } | |
1042e4c0 SS |
6662 | } |
6663 | ||
112e8700 | 6664 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6665 | { |
3a5c3e22 PA |
6666 | if (is_watchpoint (b)) |
6667 | { | |
6668 | struct watchpoint *w = (struct watchpoint *) b; | |
6669 | ||
112e8700 | 6670 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6671 | } |
f00aae0f KS |
6672 | else if (b->location != NULL |
6673 | && event_location_to_string (b->location) != NULL) | |
112e8700 | 6674 | uiout->field_string ("original-location", |
f00aae0f | 6675 | event_location_to_string (b->location)); |
d24317b4 | 6676 | } |
c4093a6a | 6677 | } |
c5aa993b | 6678 | |
0d381245 VP |
6679 | static void |
6680 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6681 | struct bp_location **last_loc, |
6c95b8df | 6682 | int allflag) |
0d381245 | 6683 | { |
8d3788bd | 6684 | struct cleanup *bkpt_chain; |
79a45e25 | 6685 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6686 | |
6687 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6688 | ||
12c5a436 | 6689 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6690 | do_cleanups (bkpt_chain); |
0d381245 VP |
6691 | |
6692 | /* If this breakpoint has custom print function, | |
6693 | it's already printed. Otherwise, print individual | |
6694 | locations, if any. */ | |
6695 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6696 | { | |
4a64f543 MS |
6697 | /* If breakpoint has a single location that is disabled, we |
6698 | print it as if it had several locations, since otherwise it's | |
6699 | hard to represent "breakpoint enabled, location disabled" | |
6700 | situation. | |
6701 | ||
6702 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6703 | internally, that's not a property exposed to user. */ |
0d381245 | 6704 | if (b->loc |
a5606eee | 6705 | && !is_hardware_watchpoint (b) |
8d3788bd | 6706 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6707 | { |
6708 | struct bp_location *loc; | |
6709 | int n = 1; | |
8d3788bd | 6710 | |
0d381245 | 6711 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6712 | { |
6713 | struct cleanup *inner2 = | |
6714 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6715 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6716 | do_cleanups (inner2); | |
6717 | } | |
0d381245 VP |
6718 | } |
6719 | } | |
6720 | } | |
6721 | ||
a6d9a66e UW |
6722 | static int |
6723 | breakpoint_address_bits (struct breakpoint *b) | |
6724 | { | |
6725 | int print_address_bits = 0; | |
6726 | struct bp_location *loc; | |
6727 | ||
c6d81124 PA |
6728 | /* Software watchpoints that aren't watching memory don't have an |
6729 | address to print. */ | |
6730 | if (is_no_memory_software_watchpoint (b)) | |
6731 | return 0; | |
6732 | ||
a6d9a66e UW |
6733 | for (loc = b->loc; loc; loc = loc->next) |
6734 | { | |
c7437ca6 PA |
6735 | int addr_bit; |
6736 | ||
c7437ca6 | 6737 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6738 | if (addr_bit > print_address_bits) |
6739 | print_address_bits = addr_bit; | |
6740 | } | |
6741 | ||
6742 | return print_address_bits; | |
6743 | } | |
0d381245 | 6744 | |
c4093a6a JM |
6745 | struct captured_breakpoint_query_args |
6746 | { | |
6747 | int bnum; | |
6748 | }; | |
c5aa993b | 6749 | |
c4093a6a | 6750 | static int |
2b65245e | 6751 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6752 | { |
9a3c8263 SM |
6753 | struct captured_breakpoint_query_args *args |
6754 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6755 | struct breakpoint *b; |
a6d9a66e | 6756 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6757 | |
c4093a6a JM |
6758 | ALL_BREAKPOINTS (b) |
6759 | { | |
6760 | if (args->bnum == b->number) | |
c5aa993b | 6761 | { |
12c5a436 | 6762 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6763 | return GDB_RC_OK; |
c5aa993b | 6764 | } |
c4093a6a JM |
6765 | } |
6766 | return GDB_RC_NONE; | |
6767 | } | |
c5aa993b | 6768 | |
c4093a6a | 6769 | enum gdb_rc |
4a64f543 MS |
6770 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6771 | char **error_message) | |
c4093a6a JM |
6772 | { |
6773 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6774 | |
c4093a6a JM |
6775 | args.bnum = bnum; |
6776 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6777 | an error. */ |
b0b13bb4 DJ |
6778 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6779 | error_message, RETURN_MASK_ALL) < 0) | |
6780 | return GDB_RC_FAIL; | |
6781 | else | |
6782 | return GDB_RC_OK; | |
c4093a6a | 6783 | } |
c5aa993b | 6784 | |
09d682a4 TT |
6785 | /* Return true if this breakpoint was set by the user, false if it is |
6786 | internal or momentary. */ | |
6787 | ||
6788 | int | |
6789 | user_breakpoint_p (struct breakpoint *b) | |
6790 | { | |
46c6471b | 6791 | return b->number > 0; |
09d682a4 TT |
6792 | } |
6793 | ||
93daf339 TT |
6794 | /* See breakpoint.h. */ |
6795 | ||
6796 | int | |
6797 | pending_breakpoint_p (struct breakpoint *b) | |
6798 | { | |
6799 | return b->loc == NULL; | |
6800 | } | |
6801 | ||
7f3b0473 | 6802 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6803 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6804 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6805 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6806 | ones for which it returns non-zero. Return the total number of | |
6807 | breakpoints listed. */ | |
c906108c | 6808 | |
d77f58be | 6809 | static int |
e5a67952 | 6810 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6811 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6812 | { |
52f0bd74 | 6813 | struct breakpoint *b; |
a6d9a66e | 6814 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6815 | int nr_printable_breakpoints; |
3b31d625 | 6816 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6817 | struct value_print_options opts; |
a6d9a66e | 6818 | int print_address_bits = 0; |
269b11a2 | 6819 | int print_type_col_width = 14; |
79a45e25 | 6820 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6821 | |
79a45b7d TT |
6822 | get_user_print_options (&opts); |
6823 | ||
4a64f543 MS |
6824 | /* Compute the number of rows in the table, as well as the size |
6825 | required for address fields. */ | |
7f3b0473 AC |
6826 | nr_printable_breakpoints = 0; |
6827 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6828 | { |
6829 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6830 | if (filter && !filter (b)) | |
6831 | continue; | |
6832 | ||
6833 | /* If we have an "args" string, it is a list of breakpoints to | |
6834 | accept. Skip the others. */ | |
6835 | if (args != NULL && *args != '\0') | |
6836 | { | |
6837 | if (allflag && parse_and_eval_long (args) != b->number) | |
6838 | continue; | |
6839 | if (!allflag && !number_is_in_list (args, b->number)) | |
6840 | continue; | |
6841 | } | |
269b11a2 | 6842 | |
e5a67952 MS |
6843 | if (allflag || user_breakpoint_p (b)) |
6844 | { | |
6845 | int addr_bit, type_len; | |
a6d9a66e | 6846 | |
e5a67952 MS |
6847 | addr_bit = breakpoint_address_bits (b); |
6848 | if (addr_bit > print_address_bits) | |
6849 | print_address_bits = addr_bit; | |
269b11a2 | 6850 | |
e5a67952 MS |
6851 | type_len = strlen (bptype_string (b->type)); |
6852 | if (type_len > print_type_col_width) | |
6853 | print_type_col_width = type_len; | |
6854 | ||
6855 | nr_printable_breakpoints++; | |
6856 | } | |
6857 | } | |
7f3b0473 | 6858 | |
79a45b7d | 6859 | if (opts.addressprint) |
3b31d625 | 6860 | bkpttbl_chain |
3e43a32a MS |
6861 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6862 | nr_printable_breakpoints, | |
3b31d625 | 6863 | "BreakpointTable"); |
8b93c638 | 6864 | else |
3b31d625 | 6865 | bkpttbl_chain |
3e43a32a MS |
6866 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6867 | nr_printable_breakpoints, | |
3b31d625 | 6868 | "BreakpointTable"); |
8b93c638 | 6869 | |
7f3b0473 | 6870 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6871 | annotate_breakpoints_headers (); |
6872 | if (nr_printable_breakpoints > 0) | |
6873 | annotate_field (0); | |
112e8700 | 6874 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6875 | if (nr_printable_breakpoints > 0) |
6876 | annotate_field (1); | |
112e8700 | 6877 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6878 | if (nr_printable_breakpoints > 0) |
6879 | annotate_field (2); | |
112e8700 | 6880 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6881 | if (nr_printable_breakpoints > 0) |
6882 | annotate_field (3); | |
112e8700 | 6883 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6884 | if (opts.addressprint) |
e5a67952 MS |
6885 | { |
6886 | if (nr_printable_breakpoints > 0) | |
6887 | annotate_field (4); | |
6888 | if (print_address_bits <= 32) | |
112e8700 | 6889 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6890 | else |
112e8700 | 6891 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6892 | } |
d7faa9e7 AC |
6893 | if (nr_printable_breakpoints > 0) |
6894 | annotate_field (5); | |
112e8700 SM |
6895 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ |
6896 | uiout->table_body (); | |
d7faa9e7 AC |
6897 | if (nr_printable_breakpoints > 0) |
6898 | annotate_breakpoints_table (); | |
7f3b0473 | 6899 | |
c4093a6a | 6900 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6901 | { |
6902 | QUIT; | |
6903 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6904 | if (filter && !filter (b)) | |
6905 | continue; | |
6906 | ||
6907 | /* If we have an "args" string, it is a list of breakpoints to | |
6908 | accept. Skip the others. */ | |
6909 | ||
6910 | if (args != NULL && *args != '\0') | |
6911 | { | |
6912 | if (allflag) /* maintenance info breakpoint */ | |
6913 | { | |
6914 | if (parse_and_eval_long (args) != b->number) | |
6915 | continue; | |
6916 | } | |
6917 | else /* all others */ | |
6918 | { | |
6919 | if (!number_is_in_list (args, b->number)) | |
6920 | continue; | |
6921 | } | |
6922 | } | |
6923 | /* We only print out user settable breakpoints unless the | |
6924 | allflag is set. */ | |
6925 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6926 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6927 | } |
6928 | ||
3b31d625 | 6929 | do_cleanups (bkpttbl_chain); |
698384cd | 6930 | |
7f3b0473 | 6931 | if (nr_printable_breakpoints == 0) |
c906108c | 6932 | { |
4a64f543 MS |
6933 | /* If there's a filter, let the caller decide how to report |
6934 | empty list. */ | |
d77f58be SS |
6935 | if (!filter) |
6936 | { | |
e5a67952 | 6937 | if (args == NULL || *args == '\0') |
112e8700 | 6938 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6939 | else |
112e8700 | 6940 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6941 | args); |
d77f58be | 6942 | } |
c906108c SS |
6943 | } |
6944 | else | |
c4093a6a | 6945 | { |
a6d9a66e UW |
6946 | if (last_loc && !server_command) |
6947 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6948 | } |
c906108c | 6949 | |
4a64f543 | 6950 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6951 | there have been breakpoints? */ |
c906108c | 6952 | annotate_breakpoints_table_end (); |
d77f58be SS |
6953 | |
6954 | return nr_printable_breakpoints; | |
c906108c SS |
6955 | } |
6956 | ||
ad443146 SS |
6957 | /* Display the value of default-collect in a way that is generally |
6958 | compatible with the breakpoint list. */ | |
6959 | ||
6960 | static void | |
6961 | default_collect_info (void) | |
6962 | { | |
79a45e25 PA |
6963 | struct ui_out *uiout = current_uiout; |
6964 | ||
ad443146 SS |
6965 | /* If it has no value (which is frequently the case), say nothing; a |
6966 | message like "No default-collect." gets in user's face when it's | |
6967 | not wanted. */ | |
6968 | if (!*default_collect) | |
6969 | return; | |
6970 | ||
6971 | /* The following phrase lines up nicely with per-tracepoint collect | |
6972 | actions. */ | |
112e8700 SM |
6973 | uiout->text ("default collect "); |
6974 | uiout->field_string ("default-collect", default_collect); | |
6975 | uiout->text (" \n"); | |
ad443146 SS |
6976 | } |
6977 | ||
c906108c | 6978 | static void |
e5a67952 | 6979 | breakpoints_info (char *args, int from_tty) |
c906108c | 6980 | { |
e5a67952 | 6981 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6982 | |
6983 | default_collect_info (); | |
d77f58be SS |
6984 | } |
6985 | ||
6986 | static void | |
e5a67952 | 6987 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6988 | { |
e5a67952 | 6989 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6990 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6991 | |
6992 | if (num_printed == 0) | |
6993 | { | |
e5a67952 | 6994 | if (args == NULL || *args == '\0') |
112e8700 | 6995 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6996 | else |
112e8700 | 6997 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6998 | } |
c906108c SS |
6999 | } |
7000 | ||
7a292a7a | 7001 | static void |
e5a67952 | 7002 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7003 | { |
e5a67952 | 7004 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7005 | |
7006 | default_collect_info (); | |
c906108c SS |
7007 | } |
7008 | ||
0d381245 | 7009 | static int |
714835d5 | 7010 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7011 | struct program_space *pspace, |
714835d5 | 7012 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7013 | { |
7014 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7015 | |
0d381245 VP |
7016 | for (; bl; bl = bl->next) |
7017 | { | |
6c95b8df PA |
7018 | if (bl->pspace == pspace |
7019 | && bl->address == pc | |
0d381245 VP |
7020 | && (!overlay_debugging || bl->section == section)) |
7021 | return 1; | |
7022 | } | |
7023 | return 0; | |
7024 | } | |
7025 | ||
672f9b60 | 7026 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7027 | concerns with logical breakpoints, so we match program spaces, not |
7028 | address spaces. */ | |
c906108c SS |
7029 | |
7030 | static void | |
6c95b8df PA |
7031 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7032 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7033 | struct obj_section *section, int thread) |
c906108c | 7034 | { |
52f0bd74 AC |
7035 | int others = 0; |
7036 | struct breakpoint *b; | |
c906108c SS |
7037 | |
7038 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7039 | others += (user_breakpoint_p (b) |
7040 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7041 | if (others > 0) |
7042 | { | |
a3f17187 AC |
7043 | if (others == 1) |
7044 | printf_filtered (_("Note: breakpoint ")); | |
7045 | else /* if (others == ???) */ | |
7046 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7047 | ALL_BREAKPOINTS (b) |
672f9b60 | 7048 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7049 | { |
7050 | others--; | |
7051 | printf_filtered ("%d", b->number); | |
7052 | if (b->thread == -1 && thread != -1) | |
7053 | printf_filtered (" (all threads)"); | |
7054 | else if (b->thread != -1) | |
7055 | printf_filtered (" (thread %d)", b->thread); | |
7056 | printf_filtered ("%s%s ", | |
059fb39f | 7057 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7058 | || b->enable_state == bp_call_disabled) |
0d381245 | 7059 | ? " (disabled)" |
0d381245 VP |
7060 | : ""), |
7061 | (others > 1) ? "," | |
7062 | : ((others == 1) ? " and" : "")); | |
7063 | } | |
a3f17187 | 7064 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7065 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7066 | printf_filtered (".\n"); |
7067 | } | |
7068 | } | |
7069 | \f | |
c906108c | 7070 | |
e4f237da | 7071 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7072 | BPT locations. For some breakpoint types, the locations' address members |
7073 | are irrelevant and it makes no sense to attempt to compare them to other | |
7074 | addresses (or use them for any other purpose either). | |
e4f237da | 7075 | |
4a64f543 | 7076 | More specifically, each of the following breakpoint types will |
244558af | 7077 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7078 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7079 | breakpoint location at address zero: |
e4f237da KB |
7080 | |
7081 | bp_watchpoint | |
2d134ed3 PA |
7082 | bp_catchpoint |
7083 | ||
7084 | */ | |
e4f237da KB |
7085 | |
7086 | static int | |
7087 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7088 | { | |
7089 | enum bptype type = bpt->type; | |
7090 | ||
2d134ed3 PA |
7091 | return (type != bp_watchpoint && type != bp_catchpoint); |
7092 | } | |
7093 | ||
7094 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7095 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7096 | ||
7097 | static int | |
4a64f543 MS |
7098 | watchpoint_locations_match (struct bp_location *loc1, |
7099 | struct bp_location *loc2) | |
2d134ed3 | 7100 | { |
3a5c3e22 PA |
7101 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7102 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7103 | ||
7104 | /* Both of them must exist. */ | |
7105 | gdb_assert (w1 != NULL); | |
7106 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7107 | |
4a64f543 MS |
7108 | /* If the target can evaluate the condition expression in hardware, |
7109 | then we we need to insert both watchpoints even if they are at | |
7110 | the same place. Otherwise the watchpoint will only trigger when | |
7111 | the condition of whichever watchpoint was inserted evaluates to | |
7112 | true, not giving a chance for GDB to check the condition of the | |
7113 | other watchpoint. */ | |
3a5c3e22 | 7114 | if ((w1->cond_exp |
4a64f543 MS |
7115 | && target_can_accel_watchpoint_condition (loc1->address, |
7116 | loc1->length, | |
0cf6dd15 | 7117 | loc1->watchpoint_type, |
4d01a485 | 7118 | w1->cond_exp.get ())) |
3a5c3e22 | 7119 | || (w2->cond_exp |
4a64f543 MS |
7120 | && target_can_accel_watchpoint_condition (loc2->address, |
7121 | loc2->length, | |
0cf6dd15 | 7122 | loc2->watchpoint_type, |
4d01a485 | 7123 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7124 | return 0; |
7125 | ||
85d721b8 PA |
7126 | /* Note that this checks the owner's type, not the location's. In |
7127 | case the target does not support read watchpoints, but does | |
7128 | support access watchpoints, we'll have bp_read_watchpoint | |
7129 | watchpoints with hw_access locations. Those should be considered | |
7130 | duplicates of hw_read locations. The hw_read locations will | |
7131 | become hw_access locations later. */ | |
2d134ed3 PA |
7132 | return (loc1->owner->type == loc2->owner->type |
7133 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7134 | && loc1->address == loc2->address | |
7135 | && loc1->length == loc2->length); | |
e4f237da KB |
7136 | } |
7137 | ||
31e77af2 | 7138 | /* See breakpoint.h. */ |
6c95b8df | 7139 | |
31e77af2 | 7140 | int |
6c95b8df PA |
7141 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7142 | struct address_space *aspace2, CORE_ADDR addr2) | |
7143 | { | |
f5656ead | 7144 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7145 | || aspace1 == aspace2) |
7146 | && addr1 == addr2); | |
7147 | } | |
7148 | ||
f1310107 TJB |
7149 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7150 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7151 | matches ASPACE2. On targets that have global breakpoints, the address | |
7152 | space doesn't really matter. */ | |
7153 | ||
7154 | static int | |
7155 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7156 | int len1, struct address_space *aspace2, | |
7157 | CORE_ADDR addr2) | |
7158 | { | |
f5656ead | 7159 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7160 | || aspace1 == aspace2) |
7161 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7162 | } | |
7163 | ||
7164 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7165 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7166 | matches the breakpoint's address space. On targets that have global | |
7167 | breakpoints, the address space doesn't really matter. */ | |
7168 | ||
7169 | static int | |
7170 | breakpoint_location_address_match (struct bp_location *bl, | |
7171 | struct address_space *aspace, | |
7172 | CORE_ADDR addr) | |
7173 | { | |
7174 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7175 | aspace, addr) | |
7176 | || (bl->length | |
7177 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7178 | bl->address, bl->length, | |
7179 | aspace, addr))); | |
7180 | } | |
7181 | ||
d35ae833 PA |
7182 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7183 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7184 | match happens only if ASPACE matches the breakpoint's address | |
7185 | space. On targets that have global breakpoints, the address space | |
7186 | doesn't really matter. */ | |
7187 | ||
7188 | static int | |
7189 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7190 | struct address_space *aspace, | |
7191 | CORE_ADDR addr, int len) | |
7192 | { | |
7193 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7194 | || bl->pspace->aspace == aspace) | |
7195 | { | |
7196 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7197 | ||
7198 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7199 | return 1; | |
7200 | } | |
7201 | return 0; | |
7202 | } | |
7203 | ||
1e4d1764 YQ |
7204 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7205 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7206 | true, otherwise returns false. */ | |
7207 | ||
7208 | static int | |
7209 | tracepoint_locations_match (struct bp_location *loc1, | |
7210 | struct bp_location *loc2) | |
7211 | { | |
7212 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7213 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7214 | locations at the same address of different tracepoints are regarded as | |
7215 | different locations. */ | |
7216 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7217 | else | |
7218 | return 0; | |
7219 | } | |
7220 | ||
2d134ed3 PA |
7221 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7222 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7223 | represent the same location. */ | |
7224 | ||
7225 | static int | |
4a64f543 MS |
7226 | breakpoint_locations_match (struct bp_location *loc1, |
7227 | struct bp_location *loc2) | |
2d134ed3 | 7228 | { |
2bdf28a0 JK |
7229 | int hw_point1, hw_point2; |
7230 | ||
7231 | /* Both of them must not be in moribund_locations. */ | |
7232 | gdb_assert (loc1->owner != NULL); | |
7233 | gdb_assert (loc2->owner != NULL); | |
7234 | ||
7235 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7236 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7237 | |
7238 | if (hw_point1 != hw_point2) | |
7239 | return 0; | |
7240 | else if (hw_point1) | |
7241 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7242 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7243 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7244 | else |
f1310107 TJB |
7245 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7246 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7247 | loc2->pspace->aspace, loc2->address) | |
7248 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7249 | } |
7250 | ||
76897487 KB |
7251 | static void |
7252 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7253 | int bnum, int have_bnum) | |
7254 | { | |
f63fbe86 MS |
7255 | /* The longest string possibly returned by hex_string_custom |
7256 | is 50 chars. These must be at least that big for safety. */ | |
7257 | char astr1[64]; | |
7258 | char astr2[64]; | |
76897487 | 7259 | |
bb599908 PH |
7260 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7261 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7262 | if (have_bnum) |
8a3fe4f8 | 7263 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7264 | bnum, astr1, astr2); |
7265 | else | |
8a3fe4f8 | 7266 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7267 | } |
7268 | ||
4a64f543 MS |
7269 | /* Adjust a breakpoint's address to account for architectural |
7270 | constraints on breakpoint placement. Return the adjusted address. | |
7271 | Note: Very few targets require this kind of adjustment. For most | |
7272 | targets, this function is simply the identity function. */ | |
76897487 KB |
7273 | |
7274 | static CORE_ADDR | |
a6d9a66e UW |
7275 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7276 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7277 | { |
a6d9a66e | 7278 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7279 | { |
7280 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7281 | return bpaddr; | |
7282 | } | |
88f7da05 KB |
7283 | else if (bptype == bp_watchpoint |
7284 | || bptype == bp_hardware_watchpoint | |
7285 | || bptype == bp_read_watchpoint | |
7286 | || bptype == bp_access_watchpoint | |
fe798b75 | 7287 | || bptype == bp_catchpoint) |
88f7da05 KB |
7288 | { |
7289 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7290 | have their addresses modified. */ | |
7291 | return bpaddr; | |
7292 | } | |
7c16b83e PA |
7293 | else if (bptype == bp_single_step) |
7294 | { | |
7295 | /* Single-step breakpoints should not have their addresses | |
7296 | modified. If there's any architectural constrain that | |
7297 | applies to this address, then it should have already been | |
7298 | taken into account when the breakpoint was created in the | |
7299 | first place. If we didn't do this, stepping through e.g., | |
7300 | Thumb-2 IT blocks would break. */ | |
7301 | return bpaddr; | |
7302 | } | |
76897487 KB |
7303 | else |
7304 | { | |
7305 | CORE_ADDR adjusted_bpaddr; | |
7306 | ||
7307 | /* Some targets have architectural constraints on the placement | |
7308 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7309 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7310 | |
7311 | /* An adjusted breakpoint address can significantly alter | |
7312 | a user's expectations. Print a warning if an adjustment | |
7313 | is required. */ | |
7314 | if (adjusted_bpaddr != bpaddr) | |
7315 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7316 | ||
7317 | return adjusted_bpaddr; | |
7318 | } | |
7319 | } | |
7320 | ||
28010a5d PA |
7321 | void |
7322 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7323 | struct breakpoint *owner) | |
7cc221ef | 7324 | { |
7cc221ef DJ |
7325 | memset (loc, 0, sizeof (*loc)); |
7326 | ||
348d480f PA |
7327 | gdb_assert (ops != NULL); |
7328 | ||
28010a5d PA |
7329 | loc->ops = ops; |
7330 | loc->owner = owner; | |
b775012e | 7331 | loc->cond_bytecode = NULL; |
0d381245 VP |
7332 | loc->shlib_disabled = 0; |
7333 | loc->enabled = 1; | |
e049a4b5 | 7334 | |
28010a5d | 7335 | switch (owner->type) |
e049a4b5 DJ |
7336 | { |
7337 | case bp_breakpoint: | |
7c16b83e | 7338 | case bp_single_step: |
e049a4b5 DJ |
7339 | case bp_until: |
7340 | case bp_finish: | |
7341 | case bp_longjmp: | |
7342 | case bp_longjmp_resume: | |
e2e4d78b | 7343 | case bp_longjmp_call_dummy: |
186c406b TT |
7344 | case bp_exception: |
7345 | case bp_exception_resume: | |
e049a4b5 | 7346 | case bp_step_resume: |
2c03e5be | 7347 | case bp_hp_step_resume: |
e049a4b5 DJ |
7348 | case bp_watchpoint_scope: |
7349 | case bp_call_dummy: | |
aa7d318d | 7350 | case bp_std_terminate: |
e049a4b5 DJ |
7351 | case bp_shlib_event: |
7352 | case bp_thread_event: | |
7353 | case bp_overlay_event: | |
4efc6507 | 7354 | case bp_jit_event: |
0fd8e87f | 7355 | case bp_longjmp_master: |
aa7d318d | 7356 | case bp_std_terminate_master: |
186c406b | 7357 | case bp_exception_master: |
0e30163f JK |
7358 | case bp_gnu_ifunc_resolver: |
7359 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7360 | case bp_dprintf: |
e049a4b5 | 7361 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7362 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7363 | break; |
7364 | case bp_hardware_breakpoint: | |
7365 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7366 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7367 | break; |
7368 | case bp_hardware_watchpoint: | |
7369 | case bp_read_watchpoint: | |
7370 | case bp_access_watchpoint: | |
7371 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7372 | break; | |
7373 | case bp_watchpoint: | |
ce78b96d | 7374 | case bp_catchpoint: |
15c3d785 PA |
7375 | case bp_tracepoint: |
7376 | case bp_fast_tracepoint: | |
0fb4aa4b | 7377 | case bp_static_tracepoint: |
e049a4b5 DJ |
7378 | loc->loc_type = bp_loc_other; |
7379 | break; | |
7380 | default: | |
e2e0b3e5 | 7381 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7382 | } |
7383 | ||
f431efe5 | 7384 | loc->refc = 1; |
28010a5d PA |
7385 | } |
7386 | ||
7387 | /* Allocate a struct bp_location. */ | |
7388 | ||
7389 | static struct bp_location * | |
7390 | allocate_bp_location (struct breakpoint *bpt) | |
7391 | { | |
348d480f PA |
7392 | return bpt->ops->allocate_location (bpt); |
7393 | } | |
7cc221ef | 7394 | |
f431efe5 PA |
7395 | static void |
7396 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7397 | { |
348d480f | 7398 | loc->ops->dtor (loc); |
4d01a485 | 7399 | delete loc; |
fe3f5fa8 VP |
7400 | } |
7401 | ||
f431efe5 PA |
7402 | /* Increment reference count. */ |
7403 | ||
7404 | static void | |
7405 | incref_bp_location (struct bp_location *bl) | |
7406 | { | |
7407 | ++bl->refc; | |
7408 | } | |
7409 | ||
7410 | /* Decrement reference count. If the reference count reaches 0, | |
7411 | destroy the bp_location. Sets *BLP to NULL. */ | |
7412 | ||
7413 | static void | |
7414 | decref_bp_location (struct bp_location **blp) | |
7415 | { | |
0807b50c PA |
7416 | gdb_assert ((*blp)->refc > 0); |
7417 | ||
f431efe5 PA |
7418 | if (--(*blp)->refc == 0) |
7419 | free_bp_location (*blp); | |
7420 | *blp = NULL; | |
7421 | } | |
7422 | ||
346774a9 | 7423 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7424 | |
346774a9 PA |
7425 | static void |
7426 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7427 | { |
346774a9 | 7428 | struct breakpoint *b1; |
c906108c | 7429 | |
346774a9 PA |
7430 | /* Add this breakpoint to the end of the chain so that a list of |
7431 | breakpoints will come out in order of increasing numbers. */ | |
7432 | ||
7433 | b1 = breakpoint_chain; | |
7434 | if (b1 == 0) | |
7435 | breakpoint_chain = b; | |
7436 | else | |
7437 | { | |
7438 | while (b1->next) | |
7439 | b1 = b1->next; | |
7440 | b1->next = b; | |
7441 | } | |
7442 | } | |
7443 | ||
7444 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7445 | ||
7446 | static void | |
7447 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7448 | struct gdbarch *gdbarch, | |
28010a5d | 7449 | enum bptype bptype, |
c0a91b2b | 7450 | const struct breakpoint_ops *ops) |
346774a9 | 7451 | { |
c906108c | 7452 | memset (b, 0, sizeof (*b)); |
2219d63c | 7453 | |
348d480f PA |
7454 | gdb_assert (ops != NULL); |
7455 | ||
28010a5d | 7456 | b->ops = ops; |
4d28f7a8 | 7457 | b->type = bptype; |
a6d9a66e | 7458 | b->gdbarch = gdbarch; |
c906108c SS |
7459 | b->language = current_language->la_language; |
7460 | b->input_radix = input_radix; | |
7461 | b->thread = -1; | |
b5de0fa7 | 7462 | b->enable_state = bp_enabled; |
c906108c SS |
7463 | b->next = 0; |
7464 | b->silent = 0; | |
7465 | b->ignore_count = 0; | |
7466 | b->commands = NULL; | |
818dd999 | 7467 | b->frame_id = null_frame_id; |
0d381245 | 7468 | b->condition_not_parsed = 0; |
84f4c1fe | 7469 | b->py_bp_object = NULL; |
d0fb5eae | 7470 | b->related_breakpoint = b; |
f00aae0f | 7471 | b->location = NULL; |
346774a9 PA |
7472 | } |
7473 | ||
7474 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7475 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7476 | |
7477 | static struct breakpoint * | |
7478 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7479 | enum bptype bptype, |
c0a91b2b | 7480 | const struct breakpoint_ops *ops) |
346774a9 | 7481 | { |
4d01a485 | 7482 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7483 | |
348d480f | 7484 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7485 | add_to_breakpoint_chain (b); |
0d381245 VP |
7486 | return b; |
7487 | } | |
7488 | ||
0e30163f JK |
7489 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7490 | resolutions should be made as the user specified the location explicitly | |
7491 | enough. */ | |
7492 | ||
0d381245 | 7493 | static void |
0e30163f | 7494 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7495 | { |
2bdf28a0 JK |
7496 | gdb_assert (loc->owner != NULL); |
7497 | ||
0d381245 | 7498 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7499 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7500 | || is_tracepoint (loc->owner)) |
0d381245 | 7501 | { |
0e30163f | 7502 | int is_gnu_ifunc; |
2c02bd72 | 7503 | const char *function_name; |
6a3a010b | 7504 | CORE_ADDR func_addr; |
0e30163f | 7505 | |
2c02bd72 | 7506 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7507 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7508 | |
7509 | if (is_gnu_ifunc && !explicit_loc) | |
7510 | { | |
7511 | struct breakpoint *b = loc->owner; | |
7512 | ||
7513 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7514 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7515 | &loc->requested_address)) |
7516 | { | |
7517 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7518 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7519 | loc->requested_address, | |
7520 | b->type); | |
7521 | } | |
7522 | else if (b->type == bp_breakpoint && b->loc == loc | |
7523 | && loc->next == NULL && b->related_breakpoint == b) | |
7524 | { | |
7525 | /* Create only the whole new breakpoint of this type but do not | |
7526 | mess more complicated breakpoints with multiple locations. */ | |
7527 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7528 | /* Remember the resolver's address for use by the return |
7529 | breakpoint. */ | |
7530 | loc->related_address = func_addr; | |
0e30163f JK |
7531 | } |
7532 | } | |
7533 | ||
2c02bd72 DE |
7534 | if (function_name) |
7535 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7536 | } |
7537 | } | |
7538 | ||
a6d9a66e | 7539 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7540 | struct gdbarch * |
a6d9a66e UW |
7541 | get_sal_arch (struct symtab_and_line sal) |
7542 | { | |
7543 | if (sal.section) | |
7544 | return get_objfile_arch (sal.section->objfile); | |
7545 | if (sal.symtab) | |
eb822aa6 | 7546 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7547 | |
7548 | return NULL; | |
7549 | } | |
7550 | ||
346774a9 PA |
7551 | /* Low level routine for partially initializing a breakpoint of type |
7552 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7553 | file name, and line number are provided by SAL. |
0d381245 VP |
7554 | |
7555 | It is expected that the caller will complete the initialization of | |
7556 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7557 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7558 | |
346774a9 PA |
7559 | static void |
7560 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7561 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7562 | const struct breakpoint_ops *ops) |
0d381245 | 7563 | { |
28010a5d | 7564 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7565 | |
3742cc8b | 7566 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7567 | |
6c95b8df PA |
7568 | if (bptype != bp_catchpoint) |
7569 | gdb_assert (sal.pspace != NULL); | |
7570 | ||
f8eba3c6 TT |
7571 | /* Store the program space that was used to set the breakpoint, |
7572 | except for ordinary breakpoints, which are independent of the | |
7573 | program space. */ | |
7574 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7575 | b->pspace = sal.pspace; | |
346774a9 | 7576 | } |
c906108c | 7577 | |
346774a9 PA |
7578 | /* set_raw_breakpoint is a low level routine for allocating and |
7579 | partially initializing a breakpoint of type BPTYPE. The newly | |
7580 | created breakpoint's address, section, source file name, and line | |
7581 | number are provided by SAL. The newly created and partially | |
7582 | initialized breakpoint is added to the breakpoint chain and | |
7583 | is also returned as the value of this function. | |
7584 | ||
7585 | It is expected that the caller will complete the initialization of | |
7586 | the newly created breakpoint struct as well as output any status | |
7587 | information regarding the creation of a new breakpoint. In | |
7588 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7589 | number! Care should be taken to not allow an error to occur | |
7590 | prior to completing the initialization of the breakpoint. If this | |
7591 | should happen, a bogus breakpoint will be left on the chain. */ | |
7592 | ||
7593 | struct breakpoint * | |
7594 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7595 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7596 | const struct breakpoint_ops *ops) |
346774a9 | 7597 | { |
4d01a485 | 7598 | struct breakpoint *b = new breakpoint (); |
346774a9 | 7599 | |
348d480f | 7600 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7601 | add_to_breakpoint_chain (b); |
c906108c SS |
7602 | return b; |
7603 | } | |
7604 | ||
53a5351d | 7605 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7606 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7607 | initiated the operation. */ | |
c906108c SS |
7608 | |
7609 | void | |
186c406b | 7610 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7611 | { |
35df4500 | 7612 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7613 | int thread = tp->global_num; |
0fd8e87f UW |
7614 | |
7615 | /* To avoid having to rescan all objfile symbols at every step, | |
7616 | we maintain a list of continually-inserted but always disabled | |
7617 | longjmp "master" breakpoints. Here, we simply create momentary | |
7618 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7619 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7620 | if (b->pspace == current_program_space |
186c406b TT |
7621 | && (b->type == bp_longjmp_master |
7622 | || b->type == bp_exception_master)) | |
0fd8e87f | 7623 | { |
06edf0c0 PA |
7624 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7625 | struct breakpoint *clone; | |
cc59ec59 | 7626 | |
e2e4d78b JK |
7627 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7628 | after their removal. */ | |
06edf0c0 | 7629 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7630 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7631 | clone->thread = thread; |
7632 | } | |
186c406b TT |
7633 | |
7634 | tp->initiating_frame = frame; | |
c906108c SS |
7635 | } |
7636 | ||
611c83ae | 7637 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7638 | void |
611c83ae | 7639 | delete_longjmp_breakpoint (int thread) |
c906108c | 7640 | { |
35df4500 | 7641 | struct breakpoint *b, *b_tmp; |
c906108c | 7642 | |
35df4500 | 7643 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7644 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7645 | { |
7646 | if (b->thread == thread) | |
7647 | delete_breakpoint (b); | |
7648 | } | |
c906108c SS |
7649 | } |
7650 | ||
f59f708a PA |
7651 | void |
7652 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7653 | { | |
7654 | struct breakpoint *b, *b_tmp; | |
7655 | ||
7656 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7657 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7658 | { | |
7659 | if (b->thread == thread) | |
7660 | b->disposition = disp_del_at_next_stop; | |
7661 | } | |
7662 | } | |
7663 | ||
e2e4d78b JK |
7664 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7665 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7666 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7667 | breakpoints. */ | |
7668 | ||
7669 | struct breakpoint * | |
7670 | set_longjmp_breakpoint_for_call_dummy (void) | |
7671 | { | |
7672 | struct breakpoint *b, *retval = NULL; | |
7673 | ||
7674 | ALL_BREAKPOINTS (b) | |
7675 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7676 | { | |
7677 | struct breakpoint *new_b; | |
7678 | ||
7679 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7680 | &momentary_breakpoint_ops, |
7681 | 1); | |
5d5658a1 | 7682 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7683 | |
7684 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7685 | ||
7686 | gdb_assert (new_b->related_breakpoint == new_b); | |
7687 | if (retval == NULL) | |
7688 | retval = new_b; | |
7689 | new_b->related_breakpoint = retval; | |
7690 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7691 | retval = retval->related_breakpoint; | |
7692 | retval->related_breakpoint = new_b; | |
7693 | } | |
7694 | ||
7695 | return retval; | |
7696 | } | |
7697 | ||
7698 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7699 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7700 | stack. |
7701 | ||
7702 | You should call this function only at places where it is safe to currently | |
7703 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7704 | frames. */ | |
7705 | ||
7706 | void | |
b67a2c6f | 7707 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7708 | { |
7709 | struct breakpoint *b, *b_tmp; | |
7710 | ||
7711 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7712 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7713 | { |
7714 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7715 | ||
7716 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7717 | dummy_b = dummy_b->related_breakpoint; | |
7718 | if (dummy_b->type != bp_call_dummy | |
7719 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7720 | continue; | |
7721 | ||
b67a2c6f | 7722 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7723 | |
7724 | while (b->related_breakpoint != b) | |
7725 | { | |
7726 | if (b_tmp == b->related_breakpoint) | |
7727 | b_tmp = b->related_breakpoint->next; | |
7728 | delete_breakpoint (b->related_breakpoint); | |
7729 | } | |
7730 | delete_breakpoint (b); | |
7731 | } | |
7732 | } | |
7733 | ||
1900040c MS |
7734 | void |
7735 | enable_overlay_breakpoints (void) | |
7736 | { | |
52f0bd74 | 7737 | struct breakpoint *b; |
1900040c MS |
7738 | |
7739 | ALL_BREAKPOINTS (b) | |
7740 | if (b->type == bp_overlay_event) | |
7741 | { | |
7742 | b->enable_state = bp_enabled; | |
44702360 | 7743 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7744 | overlay_events_enabled = 1; |
1900040c MS |
7745 | } |
7746 | } | |
7747 | ||
7748 | void | |
7749 | disable_overlay_breakpoints (void) | |
7750 | { | |
52f0bd74 | 7751 | struct breakpoint *b; |
1900040c MS |
7752 | |
7753 | ALL_BREAKPOINTS (b) | |
7754 | if (b->type == bp_overlay_event) | |
7755 | { | |
7756 | b->enable_state = bp_disabled; | |
44702360 | 7757 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7758 | overlay_events_enabled = 0; |
1900040c MS |
7759 | } |
7760 | } | |
7761 | ||
aa7d318d TT |
7762 | /* Set an active std::terminate breakpoint for each std::terminate |
7763 | master breakpoint. */ | |
7764 | void | |
7765 | set_std_terminate_breakpoint (void) | |
7766 | { | |
35df4500 | 7767 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7768 | |
35df4500 | 7769 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7770 | if (b->pspace == current_program_space |
7771 | && b->type == bp_std_terminate_master) | |
7772 | { | |
06edf0c0 | 7773 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7774 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7775 | } |
7776 | } | |
7777 | ||
7778 | /* Delete all the std::terminate breakpoints. */ | |
7779 | void | |
7780 | delete_std_terminate_breakpoint (void) | |
7781 | { | |
35df4500 | 7782 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7783 | |
35df4500 | 7784 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7785 | if (b->type == bp_std_terminate) |
7786 | delete_breakpoint (b); | |
7787 | } | |
7788 | ||
c4093a6a | 7789 | struct breakpoint * |
a6d9a66e | 7790 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7791 | { |
7792 | struct breakpoint *b; | |
c4093a6a | 7793 | |
06edf0c0 PA |
7794 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7795 | &internal_breakpoint_ops); | |
7796 | ||
b5de0fa7 | 7797 | b->enable_state = bp_enabled; |
f00aae0f | 7798 | /* location has to be used or breakpoint_re_set will delete me. */ |
ffc2605c | 7799 | b->location = new_address_location (b->loc->address, NULL, 0).release (); |
c4093a6a | 7800 | |
44702360 | 7801 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7802 | |
c4093a6a JM |
7803 | return b; |
7804 | } | |
7805 | ||
0101ce28 JJ |
7806 | struct lang_and_radix |
7807 | { | |
7808 | enum language lang; | |
7809 | int radix; | |
7810 | }; | |
7811 | ||
4efc6507 DE |
7812 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7813 | ||
7814 | struct breakpoint * | |
7815 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7816 | { | |
2a7f3dff PA |
7817 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7818 | &internal_breakpoint_ops); | |
4efc6507 | 7819 | } |
0101ce28 | 7820 | |
03673fc7 PP |
7821 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7822 | ||
7823 | void | |
7824 | remove_jit_event_breakpoints (void) | |
7825 | { | |
7826 | struct breakpoint *b, *b_tmp; | |
7827 | ||
7828 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7829 | if (b->type == bp_jit_event | |
7830 | && b->loc->pspace == current_program_space) | |
7831 | delete_breakpoint (b); | |
7832 | } | |
7833 | ||
cae688ec JJ |
7834 | void |
7835 | remove_solib_event_breakpoints (void) | |
7836 | { | |
35df4500 | 7837 | struct breakpoint *b, *b_tmp; |
cae688ec | 7838 | |
35df4500 | 7839 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7840 | if (b->type == bp_shlib_event |
7841 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7842 | delete_breakpoint (b); |
7843 | } | |
7844 | ||
f37f681c PA |
7845 | /* See breakpoint.h. */ |
7846 | ||
7847 | void | |
7848 | remove_solib_event_breakpoints_at_next_stop (void) | |
7849 | { | |
7850 | struct breakpoint *b, *b_tmp; | |
7851 | ||
7852 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7853 | if (b->type == bp_shlib_event | |
7854 | && b->loc->pspace == current_program_space) | |
7855 | b->disposition = disp_del_at_next_stop; | |
7856 | } | |
7857 | ||
04086b45 PA |
7858 | /* Helper for create_solib_event_breakpoint / |
7859 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7860 | INSERT_MODE to pass through to update_global_location_list. */ | |
7861 | ||
7862 | static struct breakpoint * | |
7863 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7864 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7865 | { |
7866 | struct breakpoint *b; | |
7867 | ||
06edf0c0 PA |
7868 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7869 | &internal_breakpoint_ops); | |
04086b45 | 7870 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7871 | return b; |
7872 | } | |
7873 | ||
04086b45 PA |
7874 | struct breakpoint * |
7875 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7876 | { | |
7877 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7878 | } | |
7879 | ||
f37f681c PA |
7880 | /* See breakpoint.h. */ |
7881 | ||
7882 | struct breakpoint * | |
7883 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7884 | { | |
7885 | struct breakpoint *b; | |
7886 | ||
04086b45 PA |
7887 | /* Explicitly tell update_global_location_list to insert |
7888 | locations. */ | |
7889 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7890 | if (!b->loc->inserted) |
7891 | { | |
7892 | delete_breakpoint (b); | |
7893 | return NULL; | |
7894 | } | |
7895 | return b; | |
7896 | } | |
7897 | ||
cae688ec JJ |
7898 | /* Disable any breakpoints that are on code in shared libraries. Only |
7899 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7900 | ||
7901 | void | |
cb851954 | 7902 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7903 | { |
876fa593 | 7904 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7905 | |
876fa593 | 7906 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7907 | { |
2bdf28a0 | 7908 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7909 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7910 | |
4a64f543 MS |
7911 | /* We apply the check to all breakpoints, including disabled for |
7912 | those with loc->duplicate set. This is so that when breakpoint | |
7913 | becomes enabled, or the duplicate is removed, gdb will try to | |
7914 | insert all breakpoints. If we don't set shlib_disabled here, | |
7915 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7916 | if (((b->type == bp_breakpoint) |
508ccb1f | 7917 | || (b->type == bp_jit_event) |
1042e4c0 | 7918 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7919 | || (is_tracepoint (b))) |
6c95b8df | 7920 | && loc->pspace == current_program_space |
0d381245 | 7921 | && !loc->shlib_disabled |
6c95b8df | 7922 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7923 | ) |
0d381245 VP |
7924 | { |
7925 | loc->shlib_disabled = 1; | |
7926 | } | |
cae688ec JJ |
7927 | } |
7928 | } | |
7929 | ||
63644780 NB |
7930 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7931 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7932 | disabled ones can just stay disabled. */ | |
84acb35a | 7933 | |
75149521 | 7934 | static void |
84acb35a JJ |
7935 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7936 | { | |
876fa593 | 7937 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7938 | int disabled_shlib_breaks = 0; |
7939 | ||
876fa593 | 7940 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7941 | { |
2bdf28a0 | 7942 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7943 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7944 | |
1e4d1764 | 7945 | if (solib->pspace == loc->pspace |
e2dd7057 | 7946 | && !loc->shlib_disabled |
1e4d1764 YQ |
7947 | && (((b->type == bp_breakpoint |
7948 | || b->type == bp_jit_event | |
7949 | || b->type == bp_hardware_breakpoint) | |
7950 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7951 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7952 | || is_tracepoint (b)) | |
e2dd7057 | 7953 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7954 | { |
e2dd7057 PP |
7955 | loc->shlib_disabled = 1; |
7956 | /* At this point, we cannot rely on remove_breakpoint | |
7957 | succeeding so we must mark the breakpoint as not inserted | |
7958 | to prevent future errors occurring in remove_breakpoints. */ | |
7959 | loc->inserted = 0; | |
8d3788bd VP |
7960 | |
7961 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7962 | observer_notify_breakpoint_modified (b); | |
7963 | ||
e2dd7057 PP |
7964 | if (!disabled_shlib_breaks) |
7965 | { | |
7966 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7967 | warning (_("Temporarily disabling breakpoints " |
7968 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7969 | solib->so_name); |
84acb35a | 7970 | } |
e2dd7057 | 7971 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7972 | } |
7973 | } | |
84acb35a JJ |
7974 | } |
7975 | ||
63644780 NB |
7976 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7977 | notification of free_objfile. Only apply to enabled breakpoints, | |
7978 | disabled ones can just stay disabled. */ | |
7979 | ||
7980 | static void | |
7981 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7982 | { | |
7983 | struct breakpoint *b; | |
7984 | ||
7985 | if (objfile == NULL) | |
7986 | return; | |
7987 | ||
d03de421 PA |
7988 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7989 | managed by the user with add-symbol-file/remove-symbol-file. | |
7990 | Similarly to how breakpoints in shared libraries are handled in | |
7991 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7992 | shlib_disabled so they end up uninserted on the next global |
7993 | location list update. Shared libraries not loaded by the user | |
7994 | aren't handled here -- they're already handled in | |
7995 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7996 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7997 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7998 | main objfile). */ | |
7999 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8000 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8001 | return; |
8002 | ||
8003 | ALL_BREAKPOINTS (b) | |
8004 | { | |
8005 | struct bp_location *loc; | |
8006 | int bp_modified = 0; | |
8007 | ||
8008 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8009 | continue; | |
8010 | ||
8011 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8012 | { | |
8013 | CORE_ADDR loc_addr = loc->address; | |
8014 | ||
8015 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8016 | && loc->loc_type != bp_loc_software_breakpoint) | |
8017 | continue; | |
8018 | ||
8019 | if (loc->shlib_disabled != 0) | |
8020 | continue; | |
8021 | ||
8022 | if (objfile->pspace != loc->pspace) | |
8023 | continue; | |
8024 | ||
8025 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8026 | && loc->loc_type != bp_loc_software_breakpoint) | |
8027 | continue; | |
8028 | ||
8029 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8030 | { | |
8031 | loc->shlib_disabled = 1; | |
08351840 PA |
8032 | /* At this point, we don't know whether the object was |
8033 | unmapped from the inferior or not, so leave the | |
8034 | inserted flag alone. We'll handle failure to | |
8035 | uninsert quietly, in case the object was indeed | |
8036 | unmapped. */ | |
63644780 NB |
8037 | |
8038 | mark_breakpoint_location_modified (loc); | |
8039 | ||
8040 | bp_modified = 1; | |
8041 | } | |
8042 | } | |
8043 | ||
8044 | if (bp_modified) | |
8045 | observer_notify_breakpoint_modified (b); | |
8046 | } | |
8047 | } | |
8048 | ||
ce78b96d JB |
8049 | /* FORK & VFORK catchpoints. */ |
8050 | ||
e29a4733 PA |
8051 | /* An instance of this type is used to represent a fork or vfork |
8052 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8053 | class; users downcast to "struct breakpoint *" when needed. A | |
8054 | breakpoint is really of this type iff its ops pointer points to | |
8055 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8056 | ||
8057 | struct fork_catchpoint | |
8058 | { | |
8059 | /* The base class. */ | |
8060 | struct breakpoint base; | |
8061 | ||
8062 | /* Process id of a child process whose forking triggered this | |
8063 | catchpoint. This field is only valid immediately after this | |
8064 | catchpoint has triggered. */ | |
8065 | ptid_t forked_inferior_pid; | |
8066 | }; | |
8067 | ||
4a64f543 MS |
8068 | /* Implement the "insert" breakpoint_ops method for fork |
8069 | catchpoints. */ | |
ce78b96d | 8070 | |
77b06cd7 TJB |
8071 | static int |
8072 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8073 | { |
dfd4cc63 | 8074 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8075 | } |
8076 | ||
4a64f543 MS |
8077 | /* Implement the "remove" breakpoint_ops method for fork |
8078 | catchpoints. */ | |
ce78b96d JB |
8079 | |
8080 | static int | |
73971819 | 8081 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8082 | { |
dfd4cc63 | 8083 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8084 | } |
8085 | ||
8086 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8087 | catchpoints. */ | |
8088 | ||
8089 | static int | |
f1310107 | 8090 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8091 | struct address_space *aspace, CORE_ADDR bp_addr, |
8092 | const struct target_waitstatus *ws) | |
ce78b96d | 8093 | { |
e29a4733 PA |
8094 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8095 | ||
f90263c1 TT |
8096 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8097 | return 0; | |
8098 | ||
8099 | c->forked_inferior_pid = ws->value.related_pid; | |
8100 | return 1; | |
ce78b96d JB |
8101 | } |
8102 | ||
4a64f543 MS |
8103 | /* Implement the "print_it" breakpoint_ops method for fork |
8104 | catchpoints. */ | |
ce78b96d JB |
8105 | |
8106 | static enum print_stop_action | |
348d480f | 8107 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8108 | { |
36dfb11c | 8109 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8110 | struct breakpoint *b = bs->breakpoint_at; |
8111 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8112 | |
ce78b96d | 8113 | annotate_catchpoint (b->number); |
f303dbd6 | 8114 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8115 | if (b->disposition == disp_del) |
112e8700 | 8116 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8117 | else |
112e8700 SM |
8118 | uiout->text ("Catchpoint "); |
8119 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8120 | { |
112e8700 SM |
8121 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
8122 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8123 | } |
112e8700 SM |
8124 | uiout->field_int ("bkptno", b->number); |
8125 | uiout->text (" (forked process "); | |
8126 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8127 | uiout->text ("), "); | |
ce78b96d JB |
8128 | return PRINT_SRC_AND_LOC; |
8129 | } | |
8130 | ||
4a64f543 MS |
8131 | /* Implement the "print_one" breakpoint_ops method for fork |
8132 | catchpoints. */ | |
ce78b96d JB |
8133 | |
8134 | static void | |
a6d9a66e | 8135 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8136 | { |
e29a4733 | 8137 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8138 | struct value_print_options opts; |
79a45e25 | 8139 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8140 | |
8141 | get_user_print_options (&opts); | |
8142 | ||
4a64f543 MS |
8143 | /* Field 4, the address, is omitted (which makes the columns not |
8144 | line up too nicely with the headers, but the effect is relatively | |
8145 | readable). */ | |
79a45b7d | 8146 | if (opts.addressprint) |
112e8700 | 8147 | uiout->field_skip ("addr"); |
ce78b96d | 8148 | annotate_field (5); |
112e8700 | 8149 | uiout->text ("fork"); |
e29a4733 | 8150 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8151 | { |
112e8700 SM |
8152 | uiout->text (", process "); |
8153 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8154 | uiout->spaces (1); | |
ce78b96d | 8155 | } |
8ac3646f | 8156 | |
112e8700 SM |
8157 | if (uiout->is_mi_like_p ()) |
8158 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8159 | } |
8160 | ||
8161 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8162 | catchpoints. */ | |
8163 | ||
8164 | static void | |
8165 | print_mention_catch_fork (struct breakpoint *b) | |
8166 | { | |
8167 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8168 | } | |
8169 | ||
6149aea9 PA |
8170 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8171 | catchpoints. */ | |
8172 | ||
8173 | static void | |
8174 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8175 | { | |
8176 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8177 | print_recreate_thread (b, fp); |
6149aea9 PA |
8178 | } |
8179 | ||
ce78b96d JB |
8180 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8181 | ||
2060206e | 8182 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8183 | |
4a64f543 MS |
8184 | /* Implement the "insert" breakpoint_ops method for vfork |
8185 | catchpoints. */ | |
ce78b96d | 8186 | |
77b06cd7 TJB |
8187 | static int |
8188 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8189 | { |
dfd4cc63 | 8190 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8191 | } |
8192 | ||
4a64f543 MS |
8193 | /* Implement the "remove" breakpoint_ops method for vfork |
8194 | catchpoints. */ | |
ce78b96d JB |
8195 | |
8196 | static int | |
73971819 | 8197 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8198 | { |
dfd4cc63 | 8199 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8200 | } |
8201 | ||
8202 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8203 | catchpoints. */ | |
8204 | ||
8205 | static int | |
f1310107 | 8206 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8207 | struct address_space *aspace, CORE_ADDR bp_addr, |
8208 | const struct target_waitstatus *ws) | |
ce78b96d | 8209 | { |
e29a4733 PA |
8210 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8211 | ||
f90263c1 TT |
8212 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8213 | return 0; | |
8214 | ||
8215 | c->forked_inferior_pid = ws->value.related_pid; | |
8216 | return 1; | |
ce78b96d JB |
8217 | } |
8218 | ||
4a64f543 MS |
8219 | /* Implement the "print_it" breakpoint_ops method for vfork |
8220 | catchpoints. */ | |
ce78b96d JB |
8221 | |
8222 | static enum print_stop_action | |
348d480f | 8223 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8224 | { |
36dfb11c | 8225 | struct ui_out *uiout = current_uiout; |
348d480f | 8226 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8227 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8228 | ||
ce78b96d | 8229 | annotate_catchpoint (b->number); |
f303dbd6 | 8230 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8231 | if (b->disposition == disp_del) |
112e8700 | 8232 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8233 | else |
112e8700 SM |
8234 | uiout->text ("Catchpoint "); |
8235 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8236 | { |
112e8700 SM |
8237 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8238 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8239 | } |
112e8700 SM |
8240 | uiout->field_int ("bkptno", b->number); |
8241 | uiout->text (" (vforked process "); | |
8242 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8243 | uiout->text ("), "); | |
ce78b96d JB |
8244 | return PRINT_SRC_AND_LOC; |
8245 | } | |
8246 | ||
4a64f543 MS |
8247 | /* Implement the "print_one" breakpoint_ops method for vfork |
8248 | catchpoints. */ | |
ce78b96d JB |
8249 | |
8250 | static void | |
a6d9a66e | 8251 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8252 | { |
e29a4733 | 8253 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8254 | struct value_print_options opts; |
79a45e25 | 8255 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8256 | |
8257 | get_user_print_options (&opts); | |
4a64f543 MS |
8258 | /* Field 4, the address, is omitted (which makes the columns not |
8259 | line up too nicely with the headers, but the effect is relatively | |
8260 | readable). */ | |
79a45b7d | 8261 | if (opts.addressprint) |
112e8700 | 8262 | uiout->field_skip ("addr"); |
ce78b96d | 8263 | annotate_field (5); |
112e8700 | 8264 | uiout->text ("vfork"); |
e29a4733 | 8265 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8266 | { |
112e8700 SM |
8267 | uiout->text (", process "); |
8268 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8269 | uiout->spaces (1); | |
ce78b96d | 8270 | } |
8ac3646f | 8271 | |
112e8700 SM |
8272 | if (uiout->is_mi_like_p ()) |
8273 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8274 | } |
8275 | ||
8276 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8277 | catchpoints. */ | |
8278 | ||
8279 | static void | |
8280 | print_mention_catch_vfork (struct breakpoint *b) | |
8281 | { | |
8282 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8283 | } | |
8284 | ||
6149aea9 PA |
8285 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8286 | catchpoints. */ | |
8287 | ||
8288 | static void | |
8289 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8290 | { | |
8291 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8292 | print_recreate_thread (b, fp); |
6149aea9 PA |
8293 | } |
8294 | ||
ce78b96d JB |
8295 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8296 | ||
2060206e | 8297 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8298 | |
edcc5120 TT |
8299 | /* An instance of this type is used to represent an solib catchpoint. |
8300 | It includes a "struct breakpoint" as a kind of base class; users | |
8301 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8302 | really of this type iff its ops pointer points to | |
8303 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8304 | ||
8305 | struct solib_catchpoint | |
8306 | { | |
8307 | /* The base class. */ | |
8308 | struct breakpoint base; | |
8309 | ||
8310 | /* True for "catch load", false for "catch unload". */ | |
8311 | unsigned char is_load; | |
8312 | ||
8313 | /* Regular expression to match, if any. COMPILED is only valid when | |
8314 | REGEX is non-NULL. */ | |
8315 | char *regex; | |
8316 | regex_t compiled; | |
8317 | }; | |
8318 | ||
8319 | static void | |
8320 | dtor_catch_solib (struct breakpoint *b) | |
8321 | { | |
8322 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8323 | ||
8324 | if (self->regex) | |
8325 | regfree (&self->compiled); | |
8326 | xfree (self->regex); | |
8327 | ||
8328 | base_breakpoint_ops.dtor (b); | |
8329 | } | |
8330 | ||
8331 | static int | |
8332 | insert_catch_solib (struct bp_location *ignore) | |
8333 | { | |
8334 | return 0; | |
8335 | } | |
8336 | ||
8337 | static int | |
73971819 | 8338 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8339 | { |
8340 | return 0; | |
8341 | } | |
8342 | ||
8343 | static int | |
8344 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8345 | struct address_space *aspace, | |
8346 | CORE_ADDR bp_addr, | |
8347 | const struct target_waitstatus *ws) | |
8348 | { | |
8349 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8350 | struct breakpoint *other; | |
8351 | ||
8352 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8353 | return 1; | |
8354 | ||
8355 | ALL_BREAKPOINTS (other) | |
8356 | { | |
8357 | struct bp_location *other_bl; | |
8358 | ||
8359 | if (other == bl->owner) | |
8360 | continue; | |
8361 | ||
8362 | if (other->type != bp_shlib_event) | |
8363 | continue; | |
8364 | ||
8365 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8366 | continue; | |
8367 | ||
8368 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8369 | { | |
8370 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8371 | return 1; | |
8372 | } | |
8373 | } | |
8374 | ||
8375 | return 0; | |
8376 | } | |
8377 | ||
8378 | static void | |
8379 | check_status_catch_solib (struct bpstats *bs) | |
8380 | { | |
8381 | struct solib_catchpoint *self | |
8382 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8383 | int ix; | |
8384 | ||
8385 | if (self->is_load) | |
8386 | { | |
8387 | struct so_list *iter; | |
8388 | ||
8389 | for (ix = 0; | |
8390 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8391 | ix, iter); | |
8392 | ++ix) | |
8393 | { | |
8394 | if (!self->regex | |
8395 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8396 | return; | |
8397 | } | |
8398 | } | |
8399 | else | |
8400 | { | |
8401 | char *iter; | |
8402 | ||
8403 | for (ix = 0; | |
8404 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8405 | ix, iter); | |
8406 | ++ix) | |
8407 | { | |
8408 | if (!self->regex | |
8409 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8410 | return; | |
8411 | } | |
8412 | } | |
8413 | ||
8414 | bs->stop = 0; | |
8415 | bs->print_it = print_it_noop; | |
8416 | } | |
8417 | ||
8418 | static enum print_stop_action | |
8419 | print_it_catch_solib (bpstat bs) | |
8420 | { | |
8421 | struct breakpoint *b = bs->breakpoint_at; | |
8422 | struct ui_out *uiout = current_uiout; | |
8423 | ||
8424 | annotate_catchpoint (b->number); | |
f303dbd6 | 8425 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8426 | if (b->disposition == disp_del) |
112e8700 | 8427 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8428 | else |
112e8700 SM |
8429 | uiout->text ("Catchpoint "); |
8430 | uiout->field_int ("bkptno", b->number); | |
8431 | uiout->text ("\n"); | |
8432 | if (uiout->is_mi_like_p ()) | |
8433 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8434 | print_solib_event (1); |
8435 | return PRINT_SRC_AND_LOC; | |
8436 | } | |
8437 | ||
8438 | static void | |
8439 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8440 | { | |
8441 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8442 | struct value_print_options opts; | |
8443 | struct ui_out *uiout = current_uiout; | |
8444 | char *msg; | |
8445 | ||
8446 | get_user_print_options (&opts); | |
8447 | /* Field 4, the address, is omitted (which makes the columns not | |
8448 | line up too nicely with the headers, but the effect is relatively | |
8449 | readable). */ | |
8450 | if (opts.addressprint) | |
8451 | { | |
8452 | annotate_field (4); | |
112e8700 | 8453 | uiout->field_skip ("addr"); |
edcc5120 TT |
8454 | } |
8455 | ||
8456 | annotate_field (5); | |
8457 | if (self->is_load) | |
8458 | { | |
8459 | if (self->regex) | |
8460 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8461 | else | |
8462 | msg = xstrdup (_("load of library")); | |
8463 | } | |
8464 | else | |
8465 | { | |
8466 | if (self->regex) | |
8467 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8468 | else | |
8469 | msg = xstrdup (_("unload of library")); | |
8470 | } | |
112e8700 | 8471 | uiout->field_string ("what", msg); |
edcc5120 | 8472 | xfree (msg); |
8ac3646f | 8473 | |
112e8700 SM |
8474 | if (uiout->is_mi_like_p ()) |
8475 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8476 | } |
8477 | ||
8478 | static void | |
8479 | print_mention_catch_solib (struct breakpoint *b) | |
8480 | { | |
8481 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8482 | ||
8483 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8484 | self->is_load ? "load" : "unload"); | |
8485 | } | |
8486 | ||
8487 | static void | |
8488 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8489 | { | |
8490 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8491 | ||
8492 | fprintf_unfiltered (fp, "%s %s", | |
8493 | b->disposition == disp_del ? "tcatch" : "catch", | |
8494 | self->is_load ? "load" : "unload"); | |
8495 | if (self->regex) | |
8496 | fprintf_unfiltered (fp, " %s", self->regex); | |
8497 | fprintf_unfiltered (fp, "\n"); | |
8498 | } | |
8499 | ||
8500 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8501 | ||
91985142 MG |
8502 | /* Shared helper function (MI and CLI) for creating and installing |
8503 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8504 | the events to be caught are load events, otherwise they are | |
8505 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8506 | temporary one. If ENABLED is non-zero the catchpoint is | |
8507 | created in an enabled state. */ | |
edcc5120 | 8508 | |
91985142 | 8509 | void |
a121b7c1 | 8510 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 TT |
8511 | { |
8512 | struct solib_catchpoint *c; | |
8513 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8514 | struct cleanup *cleanup; |
8515 | ||
edcc5120 TT |
8516 | if (!arg) |
8517 | arg = ""; | |
a121b7c1 | 8518 | arg = skip_spaces_const (arg); |
edcc5120 | 8519 | |
4d01a485 | 8520 | c = new solib_catchpoint (); |
edcc5120 TT |
8521 | cleanup = make_cleanup (xfree, c); |
8522 | ||
8523 | if (*arg != '\0') | |
8524 | { | |
8525 | int errcode; | |
8526 | ||
8527 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8528 | if (errcode != 0) | |
8529 | { | |
8530 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8531 | ||
8532 | make_cleanup (xfree, err); | |
8533 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8534 | } | |
8535 | c->regex = xstrdup (arg); | |
8536 | } | |
8537 | ||
8538 | c->is_load = is_load; | |
91985142 | 8539 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8540 | &catch_solib_breakpoint_ops); |
8541 | ||
91985142 MG |
8542 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8543 | ||
edcc5120 TT |
8544 | discard_cleanups (cleanup); |
8545 | install_breakpoint (0, &c->base, 1); | |
8546 | } | |
8547 | ||
91985142 MG |
8548 | /* A helper function that does all the work for "catch load" and |
8549 | "catch unload". */ | |
8550 | ||
8551 | static void | |
8552 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8553 | struct cmd_list_element *command) | |
8554 | { | |
8555 | int tempflag; | |
8556 | const int enabled = 1; | |
8557 | ||
8558 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8559 | ||
8560 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8561 | } | |
8562 | ||
edcc5120 TT |
8563 | static void |
8564 | catch_load_command_1 (char *arg, int from_tty, | |
8565 | struct cmd_list_element *command) | |
8566 | { | |
8567 | catch_load_or_unload (arg, from_tty, 1, command); | |
8568 | } | |
8569 | ||
8570 | static void | |
8571 | catch_unload_command_1 (char *arg, int from_tty, | |
8572 | struct cmd_list_element *command) | |
8573 | { | |
8574 | catch_load_or_unload (arg, from_tty, 0, command); | |
8575 | } | |
8576 | ||
346774a9 PA |
8577 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8578 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8579 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8580 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8581 | |
ab04a2af | 8582 | void |
346774a9 PA |
8583 | init_catchpoint (struct breakpoint *b, |
8584 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8585 | const char *cond_string, |
c0a91b2b | 8586 | const struct breakpoint_ops *ops) |
c906108c | 8587 | { |
c5aa993b | 8588 | struct symtab_and_line sal; |
346774a9 | 8589 | |
fe39c653 | 8590 | init_sal (&sal); |
6c95b8df | 8591 | sal.pspace = current_program_space; |
c5aa993b | 8592 | |
28010a5d | 8593 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8594 | |
1b36a34b | 8595 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8596 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8597 | } |
8598 | ||
28010a5d | 8599 | void |
3ea46bff | 8600 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8601 | { |
8602 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8603 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8604 | if (is_tracepoint (b)) |
8605 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8606 | if (!internal) |
8607 | mention (b); | |
c56053d2 | 8608 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8609 | |
8610 | if (update_gll) | |
44702360 | 8611 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8612 | } |
8613 | ||
9b70b993 | 8614 | static void |
a6d9a66e | 8615 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8616 | int tempflag, const char *cond_string, |
c0a91b2b | 8617 | const struct breakpoint_ops *ops) |
c906108c | 8618 | { |
4d01a485 | 8619 | struct fork_catchpoint *c = new fork_catchpoint (); |
ce78b96d | 8620 | |
e29a4733 PA |
8621 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8622 | ||
8623 | c->forked_inferior_pid = null_ptid; | |
8624 | ||
3ea46bff | 8625 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8626 | } |
8627 | ||
fe798b75 JB |
8628 | /* Exec catchpoints. */ |
8629 | ||
b4d90040 PA |
8630 | /* An instance of this type is used to represent an exec catchpoint. |
8631 | It includes a "struct breakpoint" as a kind of base class; users | |
8632 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8633 | really of this type iff its ops pointer points to | |
8634 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8635 | ||
8636 | struct exec_catchpoint | |
8637 | { | |
8638 | /* The base class. */ | |
8639 | struct breakpoint base; | |
8640 | ||
8641 | /* Filename of a program whose exec triggered this catchpoint. | |
8642 | This field is only valid immediately after this catchpoint has | |
8643 | triggered. */ | |
8644 | char *exec_pathname; | |
8645 | }; | |
8646 | ||
8647 | /* Implement the "dtor" breakpoint_ops method for exec | |
8648 | catchpoints. */ | |
8649 | ||
8650 | static void | |
8651 | dtor_catch_exec (struct breakpoint *b) | |
8652 | { | |
8653 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8654 | ||
8655 | xfree (c->exec_pathname); | |
348d480f | 8656 | |
2060206e | 8657 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8658 | } |
8659 | ||
77b06cd7 TJB |
8660 | static int |
8661 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8662 | { |
dfd4cc63 | 8663 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8664 | } |
c906108c | 8665 | |
fe798b75 | 8666 | static int |
73971819 | 8667 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8668 | { |
dfd4cc63 | 8669 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8670 | } |
c906108c | 8671 | |
fe798b75 | 8672 | static int |
f1310107 | 8673 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8674 | struct address_space *aspace, CORE_ADDR bp_addr, |
8675 | const struct target_waitstatus *ws) | |
fe798b75 | 8676 | { |
b4d90040 PA |
8677 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8678 | ||
f90263c1 TT |
8679 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8680 | return 0; | |
8681 | ||
8682 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8683 | return 1; | |
fe798b75 | 8684 | } |
c906108c | 8685 | |
fe798b75 | 8686 | static enum print_stop_action |
348d480f | 8687 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8688 | { |
36dfb11c | 8689 | struct ui_out *uiout = current_uiout; |
348d480f | 8690 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8691 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8692 | ||
fe798b75 | 8693 | annotate_catchpoint (b->number); |
f303dbd6 | 8694 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8695 | if (b->disposition == disp_del) |
112e8700 | 8696 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8697 | else |
112e8700 SM |
8698 | uiout->text ("Catchpoint "); |
8699 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8700 | { |
112e8700 SM |
8701 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8702 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8703 | } |
112e8700 SM |
8704 | uiout->field_int ("bkptno", b->number); |
8705 | uiout->text (" (exec'd "); | |
8706 | uiout->field_string ("new-exec", c->exec_pathname); | |
8707 | uiout->text ("), "); | |
36dfb11c | 8708 | |
fe798b75 | 8709 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8710 | } |
8711 | ||
fe798b75 | 8712 | static void |
a6d9a66e | 8713 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8714 | { |
b4d90040 | 8715 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8716 | struct value_print_options opts; |
79a45e25 | 8717 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8718 | |
8719 | get_user_print_options (&opts); | |
8720 | ||
8721 | /* Field 4, the address, is omitted (which makes the columns | |
8722 | not line up too nicely with the headers, but the effect | |
8723 | is relatively readable). */ | |
8724 | if (opts.addressprint) | |
112e8700 | 8725 | uiout->field_skip ("addr"); |
fe798b75 | 8726 | annotate_field (5); |
112e8700 | 8727 | uiout->text ("exec"); |
b4d90040 | 8728 | if (c->exec_pathname != NULL) |
fe798b75 | 8729 | { |
112e8700 SM |
8730 | uiout->text (", program \""); |
8731 | uiout->field_string ("what", c->exec_pathname); | |
8732 | uiout->text ("\" "); | |
fe798b75 | 8733 | } |
8ac3646f | 8734 | |
112e8700 SM |
8735 | if (uiout->is_mi_like_p ()) |
8736 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8737 | } |
8738 | ||
8739 | static void | |
8740 | print_mention_catch_exec (struct breakpoint *b) | |
8741 | { | |
8742 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8743 | } | |
8744 | ||
6149aea9 PA |
8745 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8746 | catchpoints. */ | |
8747 | ||
8748 | static void | |
8749 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8750 | { | |
8751 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8752 | print_recreate_thread (b, fp); |
6149aea9 PA |
8753 | } |
8754 | ||
2060206e | 8755 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8756 | |
c906108c | 8757 | static int |
fba45db2 | 8758 | hw_breakpoint_used_count (void) |
c906108c | 8759 | { |
c906108c | 8760 | int i = 0; |
f1310107 TJB |
8761 | struct breakpoint *b; |
8762 | struct bp_location *bl; | |
c906108c SS |
8763 | |
8764 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8765 | { |
d6b74ac4 | 8766 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8767 | for (bl = b->loc; bl; bl = bl->next) |
8768 | { | |
8769 | /* Special types of hardware breakpoints may use more than | |
8770 | one register. */ | |
348d480f | 8771 | i += b->ops->resources_needed (bl); |
f1310107 | 8772 | } |
c5aa993b | 8773 | } |
c906108c SS |
8774 | |
8775 | return i; | |
8776 | } | |
8777 | ||
a1398e0c PA |
8778 | /* Returns the resources B would use if it were a hardware |
8779 | watchpoint. */ | |
8780 | ||
c906108c | 8781 | static int |
a1398e0c | 8782 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8783 | { |
c906108c | 8784 | int i = 0; |
e09342b5 | 8785 | struct bp_location *bl; |
c906108c | 8786 | |
a1398e0c PA |
8787 | if (!breakpoint_enabled (b)) |
8788 | return 0; | |
8789 | ||
8790 | for (bl = b->loc; bl; bl = bl->next) | |
8791 | { | |
8792 | /* Special types of hardware watchpoints may use more than | |
8793 | one register. */ | |
8794 | i += b->ops->resources_needed (bl); | |
8795 | } | |
8796 | ||
8797 | return i; | |
8798 | } | |
8799 | ||
8800 | /* Returns the sum the used resources of all hardware watchpoints of | |
8801 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8802 | the sum of the used resources of all hardware watchpoints of other | |
8803 | types _not_ TYPE. */ | |
8804 | ||
8805 | static int | |
8806 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8807 | enum bptype type, int *other_type_used) | |
8808 | { | |
8809 | int i = 0; | |
8810 | struct breakpoint *b; | |
8811 | ||
c906108c SS |
8812 | *other_type_used = 0; |
8813 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8814 | { |
a1398e0c PA |
8815 | if (b == except) |
8816 | continue; | |
e09342b5 TJB |
8817 | if (!breakpoint_enabled (b)) |
8818 | continue; | |
8819 | ||
a1398e0c PA |
8820 | if (b->type == type) |
8821 | i += hw_watchpoint_use_count (b); | |
8822 | else if (is_hardware_watchpoint (b)) | |
8823 | *other_type_used = 1; | |
e09342b5 TJB |
8824 | } |
8825 | ||
c906108c SS |
8826 | return i; |
8827 | } | |
8828 | ||
c906108c | 8829 | void |
fba45db2 | 8830 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8831 | { |
c5aa993b | 8832 | struct breakpoint *b; |
c906108c SS |
8833 | |
8834 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8835 | { |
cc60f2e3 | 8836 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8837 | { |
b5de0fa7 | 8838 | b->enable_state = bp_call_disabled; |
44702360 | 8839 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8840 | } |
8841 | } | |
c906108c SS |
8842 | } |
8843 | ||
8844 | void | |
fba45db2 | 8845 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8846 | { |
c5aa993b | 8847 | struct breakpoint *b; |
c906108c SS |
8848 | |
8849 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8850 | { |
cc60f2e3 | 8851 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8852 | { |
b5de0fa7 | 8853 | b->enable_state = bp_enabled; |
44702360 | 8854 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8855 | } |
8856 | } | |
c906108c SS |
8857 | } |
8858 | ||
8bea4e01 UW |
8859 | void |
8860 | disable_breakpoints_before_startup (void) | |
8861 | { | |
6c95b8df | 8862 | current_program_space->executing_startup = 1; |
44702360 | 8863 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8864 | } |
8865 | ||
8866 | void | |
8867 | enable_breakpoints_after_startup (void) | |
8868 | { | |
6c95b8df | 8869 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8870 | breakpoint_re_set (); |
8bea4e01 UW |
8871 | } |
8872 | ||
7c16b83e PA |
8873 | /* Create a new single-step breakpoint for thread THREAD, with no |
8874 | locations. */ | |
c906108c | 8875 | |
7c16b83e PA |
8876 | static struct breakpoint * |
8877 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8878 | { | |
4d01a485 | 8879 | struct breakpoint *b = new breakpoint (); |
7c16b83e PA |
8880 | |
8881 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8882 | &momentary_breakpoint_ops); | |
8883 | ||
8884 | b->disposition = disp_donttouch; | |
8885 | b->frame_id = null_frame_id; | |
8886 | ||
8887 | b->thread = thread; | |
8888 | gdb_assert (b->thread != 0); | |
8889 | ||
8890 | add_to_breakpoint_chain (b); | |
8891 | ||
8892 | return b; | |
8893 | } | |
8894 | ||
8895 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8896 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8897 | frame. */ | |
c906108c SS |
8898 | |
8899 | struct breakpoint * | |
a6d9a66e UW |
8900 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8901 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8902 | { |
52f0bd74 | 8903 | struct breakpoint *b; |
edb3359d | 8904 | |
193facb3 JK |
8905 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8906 | tail-called one. */ | |
8907 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8908 | |
06edf0c0 | 8909 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8910 | b->enable_state = bp_enabled; |
8911 | b->disposition = disp_donttouch; | |
818dd999 | 8912 | b->frame_id = frame_id; |
c906108c | 8913 | |
4a64f543 MS |
8914 | /* If we're debugging a multi-threaded program, then we want |
8915 | momentary breakpoints to be active in only a single thread of | |
8916 | control. */ | |
39f77062 | 8917 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8918 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8919 | |
44702360 | 8920 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8921 | |
c906108c SS |
8922 | return b; |
8923 | } | |
611c83ae | 8924 | |
06edf0c0 | 8925 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8926 | The new breakpoint will have type TYPE, use OPS as its |
8927 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8928 | |
06edf0c0 PA |
8929 | static struct breakpoint * |
8930 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8931 | enum bptype type, | |
a1aa2221 LM |
8932 | const struct breakpoint_ops *ops, |
8933 | int loc_enabled) | |
e58b0e63 PA |
8934 | { |
8935 | struct breakpoint *copy; | |
8936 | ||
06edf0c0 | 8937 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8938 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8939 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8940 | |
a6d9a66e | 8941 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8942 | copy->loc->requested_address = orig->loc->requested_address; |
8943 | copy->loc->address = orig->loc->address; | |
8944 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8945 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8946 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8947 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8948 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8949 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8950 | copy->frame_id = orig->frame_id; |
8951 | copy->thread = orig->thread; | |
6c95b8df | 8952 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8953 | |
8954 | copy->enable_state = bp_enabled; | |
8955 | copy->disposition = disp_donttouch; | |
8956 | copy->number = internal_breakpoint_number--; | |
8957 | ||
44702360 | 8958 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8959 | return copy; |
8960 | } | |
8961 | ||
06edf0c0 PA |
8962 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8963 | ORIG is NULL. */ | |
8964 | ||
8965 | struct breakpoint * | |
8966 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8967 | { | |
8968 | /* If there's nothing to clone, then return nothing. */ | |
8969 | if (orig == NULL) | |
8970 | return NULL; | |
8971 | ||
a1aa2221 | 8972 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8973 | } |
8974 | ||
611c83ae | 8975 | struct breakpoint * |
a6d9a66e UW |
8976 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8977 | enum bptype type) | |
611c83ae PA |
8978 | { |
8979 | struct symtab_and_line sal; | |
8980 | ||
8981 | sal = find_pc_line (pc, 0); | |
8982 | sal.pc = pc; | |
8983 | sal.section = find_pc_overlay (pc); | |
8984 | sal.explicit_pc = 1; | |
8985 | ||
a6d9a66e | 8986 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8987 | } |
c906108c | 8988 | \f |
c5aa993b | 8989 | |
c906108c SS |
8990 | /* Tell the user we have just set a breakpoint B. */ |
8991 | ||
8992 | static void | |
fba45db2 | 8993 | mention (struct breakpoint *b) |
c906108c | 8994 | { |
348d480f | 8995 | b->ops->print_mention (b); |
112e8700 | 8996 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8997 | return; |
c906108c SS |
8998 | printf_filtered ("\n"); |
8999 | } | |
c906108c | 9000 | \f |
c5aa993b | 9001 | |
1a853c52 PA |
9002 | static int bp_loc_is_permanent (struct bp_location *loc); |
9003 | ||
0d381245 | 9004 | static struct bp_location * |
39d61571 | 9005 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9006 | const struct symtab_and_line *sal) |
9007 | { | |
9008 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9009 | CORE_ADDR adjusted_address; |
9010 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9011 | ||
9012 | if (loc_gdbarch == NULL) | |
9013 | loc_gdbarch = b->gdbarch; | |
9014 | ||
9015 | /* Adjust the breakpoint's address prior to allocating a location. | |
9016 | Once we call allocate_bp_location(), that mostly uninitialized | |
9017 | location will be placed on the location chain. Adjustment of the | |
9018 | breakpoint may cause target_read_memory() to be called and we do | |
9019 | not want its scan of the location chain to find a breakpoint and | |
9020 | location that's only been partially initialized. */ | |
9021 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9022 | sal->pc, b->type); | |
0d381245 | 9023 | |
d30113d4 | 9024 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9025 | loc = allocate_bp_location (b); |
d30113d4 JK |
9026 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9027 | tmp = &((*tmp)->next)) | |
0d381245 | 9028 | ; |
d30113d4 | 9029 | loc->next = *tmp; |
0d381245 | 9030 | *tmp = loc; |
3742cc8b | 9031 | |
0d381245 | 9032 | loc->requested_address = sal->pc; |
3742cc8b | 9033 | loc->address = adjusted_address; |
6c95b8df | 9034 | loc->pspace = sal->pspace; |
729662a5 TT |
9035 | loc->probe.probe = sal->probe; |
9036 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9037 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9038 | loc->section = sal->section; |
3742cc8b | 9039 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9040 | loc->line_number = sal->line; |
2f202fde | 9041 | loc->symtab = sal->symtab; |
f8eba3c6 | 9042 | |
0e30163f JK |
9043 | set_breakpoint_location_function (loc, |
9044 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9045 | |
6ae88661 LM |
9046 | /* While by definition, permanent breakpoints are already present in the |
9047 | code, we don't mark the location as inserted. Normally one would expect | |
9048 | that GDB could rely on that breakpoint instruction to stop the program, | |
9049 | thus removing the need to insert its own breakpoint, except that executing | |
9050 | the breakpoint instruction can kill the target instead of reporting a | |
9051 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9052 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9053 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9054 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9055 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9056 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9057 | it manually increments the PC, thus avoiding executing the breakpoint | |
9058 | instruction.) */ | |
1a853c52 | 9059 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9060 | loc->permanent = 1; |
1a853c52 | 9061 | |
0d381245 VP |
9062 | return loc; |
9063 | } | |
514f746b AR |
9064 | \f |
9065 | ||
1cf4d951 | 9066 | /* See breakpoint.h. */ |
514f746b | 9067 | |
1cf4d951 PA |
9068 | int |
9069 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9070 | { |
9071 | int len; | |
9072 | CORE_ADDR addr; | |
1afeeb75 | 9073 | const gdb_byte *bpoint; |
514f746b | 9074 | gdb_byte *target_mem; |
939c61fa JK |
9075 | struct cleanup *cleanup; |
9076 | int retval = 0; | |
514f746b | 9077 | |
1cf4d951 PA |
9078 | addr = address; |
9079 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9080 | ||
9081 | /* Software breakpoints unsupported? */ | |
9082 | if (bpoint == NULL) | |
9083 | return 0; | |
9084 | ||
224c3ddb | 9085 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9086 | |
9087 | /* Enable the automatic memory restoration from breakpoints while | |
9088 | we read the memory. Otherwise we could say about our temporary | |
9089 | breakpoints they are permanent. */ | |
9090 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9091 | ||
9092 | if (target_read_memory (address, target_mem, len) == 0 | |
9093 | && memcmp (target_mem, bpoint, len) == 0) | |
9094 | retval = 1; | |
9095 | ||
9096 | do_cleanups (cleanup); | |
9097 | ||
9098 | return retval; | |
9099 | } | |
9100 | ||
9101 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9102 | return 0 otherwise. */ | |
9103 | ||
9104 | static int | |
9105 | bp_loc_is_permanent (struct bp_location *loc) | |
9106 | { | |
9107 | struct cleanup *cleanup; | |
9108 | int retval; | |
9109 | ||
514f746b AR |
9110 | gdb_assert (loc != NULL); |
9111 | ||
244558af LM |
9112 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9113 | attempt to read from the addresses the locations of these breakpoint types | |
9114 | point to. program_breakpoint_here_p, below, will attempt to read | |
9115 | memory. */ | |
9116 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9117 | return 0; | |
9118 | ||
6c95b8df | 9119 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9120 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9121 | |
1cf4d951 | 9122 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9123 | |
939c61fa JK |
9124 | do_cleanups (cleanup); |
9125 | ||
9126 | return retval; | |
514f746b AR |
9127 | } |
9128 | ||
e7e0cddf SS |
9129 | /* Build a command list for the dprintf corresponding to the current |
9130 | settings of the dprintf style options. */ | |
9131 | ||
9132 | static void | |
9133 | update_dprintf_command_list (struct breakpoint *b) | |
9134 | { | |
9135 | char *dprintf_args = b->extra_string; | |
9136 | char *printf_line = NULL; | |
9137 | ||
9138 | if (!dprintf_args) | |
9139 | return; | |
9140 | ||
9141 | dprintf_args = skip_spaces (dprintf_args); | |
9142 | ||
9143 | /* Allow a comma, as it may have terminated a location, but don't | |
9144 | insist on it. */ | |
9145 | if (*dprintf_args == ',') | |
9146 | ++dprintf_args; | |
9147 | dprintf_args = skip_spaces (dprintf_args); | |
9148 | ||
9149 | if (*dprintf_args != '"') | |
9150 | error (_("Bad format string, missing '\"'.")); | |
9151 | ||
d3ce09f5 | 9152 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9153 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9154 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9155 | { |
9156 | if (!dprintf_function) | |
9157 | error (_("No function supplied for dprintf call")); | |
9158 | ||
9159 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9160 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9161 | dprintf_function, | |
9162 | dprintf_channel, | |
9163 | dprintf_args); | |
9164 | else | |
9165 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9166 | dprintf_function, | |
9167 | dprintf_args); | |
9168 | } | |
d3ce09f5 SS |
9169 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9170 | { | |
9171 | if (target_can_run_breakpoint_commands ()) | |
9172 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9173 | else | |
9174 | { | |
9175 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9176 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9177 | } | |
9178 | } | |
e7e0cddf SS |
9179 | else |
9180 | internal_error (__FILE__, __LINE__, | |
9181 | _("Invalid dprintf style.")); | |
9182 | ||
f28045c2 | 9183 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9184 | /* Manufacture a printf sequence. */ |
f28045c2 | 9185 | { |
8d749320 | 9186 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9187 | |
f28045c2 YQ |
9188 | printf_cmd_line->control_type = simple_control; |
9189 | printf_cmd_line->body_count = 0; | |
9190 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9191 | printf_cmd_line->next = NULL; |
f28045c2 | 9192 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9193 | |
93921405 | 9194 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 9195 | } |
e7e0cddf SS |
9196 | } |
9197 | ||
9198 | /* Update all dprintf commands, making their command lists reflect | |
9199 | current style settings. */ | |
9200 | ||
9201 | static void | |
9202 | update_dprintf_commands (char *args, int from_tty, | |
9203 | struct cmd_list_element *c) | |
9204 | { | |
9205 | struct breakpoint *b; | |
9206 | ||
9207 | ALL_BREAKPOINTS (b) | |
9208 | { | |
9209 | if (b->type == bp_dprintf) | |
9210 | update_dprintf_command_list (b); | |
9211 | } | |
9212 | } | |
c3f6f71d | 9213 | |
f00aae0f KS |
9214 | /* Create a breakpoint with SAL as location. Use LOCATION |
9215 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9216 | as condition expression. If LOCATION is NULL then create an |
9217 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9218 | |
9219 | static void | |
d9b3f62e | 9220 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f | 9221 | struct symtabs_and_lines sals, |
ffc2605c | 9222 | event_location_up &&location, |
f8eba3c6 | 9223 | char *filter, char *cond_string, |
e7e0cddf | 9224 | char *extra_string, |
d9b3f62e PA |
9225 | enum bptype type, enum bpdisp disposition, |
9226 | int thread, int task, int ignore_count, | |
c0a91b2b | 9227 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9228 | int enabled, int internal, unsigned flags, |
9229 | int display_canonical) | |
018d34a4 | 9230 | { |
0d381245 | 9231 | int i; |
018d34a4 VP |
9232 | |
9233 | if (type == bp_hardware_breakpoint) | |
9234 | { | |
fbbd034e AS |
9235 | int target_resources_ok; |
9236 | ||
9237 | i = hw_breakpoint_used_count (); | |
9238 | target_resources_ok = | |
9239 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9240 | i + 1, 0); |
9241 | if (target_resources_ok == 0) | |
9242 | error (_("No hardware breakpoint support in the target.")); | |
9243 | else if (target_resources_ok < 0) | |
9244 | error (_("Hardware breakpoints used exceeds limit.")); | |
9245 | } | |
9246 | ||
6c95b8df PA |
9247 | gdb_assert (sals.nelts > 0); |
9248 | ||
0d381245 VP |
9249 | for (i = 0; i < sals.nelts; ++i) |
9250 | { | |
9251 | struct symtab_and_line sal = sals.sals[i]; | |
9252 | struct bp_location *loc; | |
9253 | ||
9254 | if (from_tty) | |
5af949e3 UW |
9255 | { |
9256 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9257 | if (!loc_gdbarch) | |
9258 | loc_gdbarch = gdbarch; | |
9259 | ||
9260 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9261 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9262 | } |
0d381245 VP |
9263 | |
9264 | if (i == 0) | |
9265 | { | |
d9b3f62e | 9266 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9267 | b->thread = thread; |
4a306c9a | 9268 | b->task = task; |
855a6e68 | 9269 | |
0d381245 | 9270 | b->cond_string = cond_string; |
e7e0cddf | 9271 | b->extra_string = extra_string; |
0d381245 | 9272 | b->ignore_count = ignore_count; |
41447f92 | 9273 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9274 | b->disposition = disposition; |
6c95b8df | 9275 | |
44f238bb PA |
9276 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9277 | b->loc->inserted = 1; | |
9278 | ||
0fb4aa4b PA |
9279 | if (type == bp_static_tracepoint) |
9280 | { | |
d9b3f62e | 9281 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9282 | struct static_tracepoint_marker marker; |
9283 | ||
983af33b | 9284 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9285 | { |
9286 | /* We already know the marker exists, otherwise, we | |
9287 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9288 | const char *p = &event_location_to_string (b->location)[3]; |
9289 | const char *endp; | |
0fb4aa4b | 9290 | char *marker_str; |
0fb4aa4b | 9291 | |
f00aae0f | 9292 | p = skip_spaces_const (p); |
0fb4aa4b | 9293 | |
f00aae0f | 9294 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9295 | |
9296 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9297 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9298 | |
3e43a32a MS |
9299 | printf_filtered (_("Probed static tracepoint " |
9300 | "marker \"%s\"\n"), | |
d9b3f62e | 9301 | t->static_trace_marker_id); |
0fb4aa4b PA |
9302 | } |
9303 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9304 | { | |
d9b3f62e | 9305 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9306 | release_static_tracepoint_marker (&marker); |
9307 | ||
3e43a32a MS |
9308 | printf_filtered (_("Probed static tracepoint " |
9309 | "marker \"%s\"\n"), | |
d9b3f62e | 9310 | t->static_trace_marker_id); |
0fb4aa4b PA |
9311 | } |
9312 | else | |
3e43a32a MS |
9313 | warning (_("Couldn't determine the static " |
9314 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9315 | } |
9316 | ||
0d381245 VP |
9317 | loc = b->loc; |
9318 | } | |
9319 | else | |
018d34a4 | 9320 | { |
39d61571 | 9321 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9322 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9323 | loc->inserted = 1; | |
0d381245 VP |
9324 | } |
9325 | ||
9326 | if (b->cond_string) | |
9327 | { | |
bbc13ae3 KS |
9328 | const char *arg = b->cond_string; |
9329 | ||
1bb9788d TT |
9330 | loc->cond = parse_exp_1 (&arg, loc->address, |
9331 | block_for_pc (loc->address), 0); | |
0d381245 | 9332 | if (*arg) |
588ae58c | 9333 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9334 | } |
e7e0cddf SS |
9335 | |
9336 | /* Dynamic printf requires and uses additional arguments on the | |
9337 | command line, otherwise it's an error. */ | |
9338 | if (type == bp_dprintf) | |
9339 | { | |
9340 | if (b->extra_string) | |
9341 | update_dprintf_command_list (b); | |
9342 | else | |
9343 | error (_("Format string required")); | |
9344 | } | |
9345 | else if (b->extra_string) | |
588ae58c | 9346 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9347 | } |
018d34a4 | 9348 | |
56435ebe | 9349 | b->display_canonical = display_canonical; |
f00aae0f | 9350 | if (location != NULL) |
ffc2605c | 9351 | b->location = location.release (); |
018d34a4 | 9352 | else |
ffc2605c | 9353 | b->location = new_address_location (b->loc->address, NULL, 0).release (); |
f8eba3c6 | 9354 | b->filter = filter; |
d9b3f62e | 9355 | } |
018d34a4 | 9356 | |
d9b3f62e PA |
9357 | static void |
9358 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f | 9359 | struct symtabs_and_lines sals, |
ffc2605c | 9360 | event_location_up &&location, |
f8eba3c6 | 9361 | char *filter, char *cond_string, |
e7e0cddf | 9362 | char *extra_string, |
d9b3f62e PA |
9363 | enum bptype type, enum bpdisp disposition, |
9364 | int thread, int task, int ignore_count, | |
c0a91b2b | 9365 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9366 | int enabled, int internal, unsigned flags, |
9367 | int display_canonical) | |
d9b3f62e PA |
9368 | { |
9369 | struct breakpoint *b; | |
9370 | struct cleanup *old_chain; | |
9371 | ||
9372 | if (is_tracepoint_type (type)) | |
9373 | { | |
9374 | struct tracepoint *t; | |
9375 | ||
4d01a485 | 9376 | t = new tracepoint (); |
d9b3f62e PA |
9377 | b = &t->base; |
9378 | } | |
9379 | else | |
4d01a485 | 9380 | b = new breakpoint (); |
d9b3f62e PA |
9381 | |
9382 | old_chain = make_cleanup (xfree, b); | |
9383 | ||
9384 | init_breakpoint_sal (b, gdbarch, | |
ffc2605c | 9385 | sals, std::move (location), |
e7e0cddf | 9386 | filter, cond_string, extra_string, |
d9b3f62e PA |
9387 | type, disposition, |
9388 | thread, task, ignore_count, | |
9389 | ops, from_tty, | |
44f238bb PA |
9390 | enabled, internal, flags, |
9391 | display_canonical); | |
d9b3f62e PA |
9392 | discard_cleanups (old_chain); |
9393 | ||
3ea46bff | 9394 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9395 | } |
9396 | ||
9397 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9398 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9399 | value. COND_STRING, if not NULL, specified the condition to be | |
9400 | used for all breakpoints. Essentially the only case where | |
9401 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9402 | function. In that case, it's still not possible to specify | |
9403 | separate conditions for different overloaded functions, so | |
9404 | we take just a single condition string. | |
9405 | ||
c3f6f71d | 9406 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9407 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9408 | array contents). If the function fails (error() is called), the |
9409 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9410 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9411 | |
9412 | static void | |
8cdf0e15 | 9413 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9414 | struct linespec_result *canonical, |
e7e0cddf | 9415 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9416 | enum bptype type, enum bpdisp disposition, |
9417 | int thread, int task, int ignore_count, | |
c0a91b2b | 9418 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9419 | int enabled, int internal, unsigned flags) |
c906108c | 9420 | { |
018d34a4 | 9421 | int i; |
f8eba3c6 | 9422 | struct linespec_sals *lsal; |
cc59ec59 | 9423 | |
f8eba3c6 TT |
9424 | if (canonical->pre_expanded) |
9425 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9426 | ||
9427 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9428 | { |
f00aae0f | 9429 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9430 | 'break', without arguments. */ |
ffc2605c | 9431 | event_location_up location |
f00aae0f KS |
9432 | = (canonical->location != NULL |
9433 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9434 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
0d381245 | 9435 | |
f8eba3c6 TT |
9436 | make_cleanup (xfree, filter_string); |
9437 | create_breakpoint_sal (gdbarch, lsal->sals, | |
ffc2605c | 9438 | std::move (location), |
f8eba3c6 | 9439 | filter_string, |
e7e0cddf SS |
9440 | cond_string, extra_string, |
9441 | type, disposition, | |
84f4c1fe | 9442 | thread, task, ignore_count, ops, |
44f238bb | 9443 | from_tty, enabled, internal, flags, |
56435ebe | 9444 | canonical->special_display); |
c3f6f71d | 9445 | } |
c3f6f71d | 9446 | } |
c906108c | 9447 | |
f00aae0f | 9448 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9449 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9450 | addresses found. LOCATION points to the end of the SAL (for |
9451 | linespec locations). | |
9998af43 TJB |
9452 | |
9453 | The array and the line spec strings are allocated on the heap, it is | |
9454 | the caller's responsibility to free them. */ | |
c906108c | 9455 | |
b9362cc7 | 9456 | static void |
f00aae0f | 9457 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9458 | struct linespec_result *canonical) |
c3f6f71d | 9459 | { |
f00aae0f KS |
9460 | struct symtab_and_line cursal; |
9461 | ||
9462 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9463 | { | |
9464 | const char *address = get_linespec_location (location); | |
9465 | ||
9466 | if (address == NULL) | |
9467 | { | |
9468 | /* The last displayed codepoint, if it's valid, is our default | |
9469 | breakpoint address. */ | |
9470 | if (last_displayed_sal_is_valid ()) | |
9471 | { | |
9472 | struct linespec_sals lsal; | |
9473 | struct symtab_and_line sal; | |
9474 | CORE_ADDR pc; | |
9475 | ||
9476 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9477 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9478 | |
9479 | /* Set sal's pspace, pc, symtab, and line to the values | |
9480 | corresponding to the last call to print_frame_info. | |
9481 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9482 | as the breakpoint line number is inappropriate otherwise. | |
9483 | find_pc_line would adjust PC, re-set it back. */ | |
9484 | get_last_displayed_sal (&sal); | |
9485 | pc = sal.pc; | |
9486 | sal = find_pc_line (pc, 0); | |
9487 | ||
9488 | /* "break" without arguments is equivalent to "break *PC" | |
9489 | where PC is the last displayed codepoint's address. So | |
9490 | make sure to set sal.explicit_pc to prevent GDB from | |
9491 | trying to expand the list of sals to include all other | |
9492 | instances with the same symtab and line. */ | |
9493 | sal.pc = pc; | |
9494 | sal.explicit_pc = 1; | |
9495 | ||
9496 | lsal.sals.sals[0] = sal; | |
9497 | lsal.sals.nelts = 1; | |
9498 | lsal.canonical = NULL; | |
9499 | ||
9500 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9501 | return; | |
9502 | } | |
9503 | else | |
9504 | error (_("No default breakpoint address now.")); | |
c906108c | 9505 | } |
c906108c | 9506 | } |
f00aae0f KS |
9507 | |
9508 | /* Force almost all breakpoints to be in terms of the | |
9509 | current_source_symtab (which is decode_line_1's default). | |
9510 | This should produce the results we want almost all of the | |
9511 | time while leaving default_breakpoint_* alone. | |
9512 | ||
9513 | ObjC: However, don't match an Objective-C method name which | |
9514 | may have a '+' or '-' succeeded by a '['. */ | |
9515 | cursal = get_current_source_symtab_and_line (); | |
9516 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9517 | { |
f00aae0f | 9518 | const char *address = NULL; |
cc80f267 | 9519 | |
f00aae0f KS |
9520 | if (event_location_type (location) == LINESPEC_LOCATION) |
9521 | address = get_linespec_location (location); | |
cc80f267 | 9522 | |
f00aae0f KS |
9523 | if (!cursal.symtab |
9524 | || (address != NULL | |
9525 | && strchr ("+-", address[0]) != NULL | |
9526 | && address[1] != '[')) | |
9527 | { | |
c2f4122d | 9528 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9529 | get_last_displayed_symtab (), |
9530 | get_last_displayed_line (), | |
9531 | canonical, NULL, NULL); | |
9532 | return; | |
9533 | } | |
c906108c | 9534 | } |
f00aae0f | 9535 | |
c2f4122d | 9536 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9537 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9538 | } |
c906108c | 9539 | |
c906108c | 9540 | |
c3f6f71d | 9541 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9542 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9543 | |
b9362cc7 | 9544 | static void |
23e7acfb | 9545 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9546 | { |
9547 | int i; | |
cc59ec59 | 9548 | |
c3f6f71d | 9549 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9550 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9551 | } |
9552 | ||
7a697b8d SS |
9553 | /* Fast tracepoints may have restrictions on valid locations. For |
9554 | instance, a fast tracepoint using a jump instead of a trap will | |
9555 | likely have to overwrite more bytes than a trap would, and so can | |
9556 | only be placed where the instruction is longer than the jump, or a | |
9557 | multi-instruction sequence does not have a jump into the middle of | |
9558 | it, etc. */ | |
9559 | ||
9560 | static void | |
9561 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9562 | struct symtabs_and_lines *sals) | |
9563 | { | |
9564 | int i, rslt; | |
9565 | struct symtab_and_line *sal; | |
9566 | char *msg; | |
9567 | struct cleanup *old_chain; | |
9568 | ||
9569 | for (i = 0; i < sals->nelts; i++) | |
9570 | { | |
f8eba3c6 TT |
9571 | struct gdbarch *sarch; |
9572 | ||
7a697b8d SS |
9573 | sal = &sals->sals[i]; |
9574 | ||
f8eba3c6 TT |
9575 | sarch = get_sal_arch (*sal); |
9576 | /* We fall back to GDBARCH if there is no architecture | |
9577 | associated with SAL. */ | |
9578 | if (sarch == NULL) | |
9579 | sarch = gdbarch; | |
6b940e6a | 9580 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9581 | old_chain = make_cleanup (xfree, msg); |
9582 | ||
9583 | if (!rslt) | |
53c3572a | 9584 | error (_("May not have a fast tracepoint at %s%s"), |
f8eba3c6 | 9585 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9586 | |
9587 | do_cleanups (old_chain); | |
9588 | } | |
9589 | } | |
9590 | ||
018d34a4 VP |
9591 | /* Given TOK, a string specification of condition and thread, as |
9592 | accepted by the 'break' command, extract the condition | |
9593 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9594 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9595 | If no condition is found, *COND_STRING is set to NULL. |
9596 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9597 | |
9598 | static void | |
bbc13ae3 | 9599 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9600 | char **cond_string, int *thread, int *task, |
9601 | char **rest) | |
018d34a4 VP |
9602 | { |
9603 | *cond_string = NULL; | |
9604 | *thread = -1; | |
ed1d1739 KS |
9605 | *task = 0; |
9606 | *rest = NULL; | |
9607 | ||
018d34a4 VP |
9608 | while (tok && *tok) |
9609 | { | |
bbc13ae3 | 9610 | const char *end_tok; |
018d34a4 | 9611 | int toklen; |
bbc13ae3 KS |
9612 | const char *cond_start = NULL; |
9613 | const char *cond_end = NULL; | |
cc59ec59 | 9614 | |
bbc13ae3 | 9615 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9616 | |
9617 | if ((*tok == '"' || *tok == ',') && rest) | |
9618 | { | |
9619 | *rest = savestring (tok, strlen (tok)); | |
9620 | return; | |
9621 | } | |
9622 | ||
bbc13ae3 | 9623 | end_tok = skip_to_space_const (tok); |
d634f2de | 9624 | |
018d34a4 | 9625 | toklen = end_tok - tok; |
d634f2de | 9626 | |
018d34a4 VP |
9627 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9628 | { | |
9629 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9630 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9631 | cond_end = tok; |
d634f2de | 9632 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9633 | } |
9634 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9635 | { | |
5d5658a1 PA |
9636 | const char *tmptok; |
9637 | struct thread_info *thr; | |
d634f2de | 9638 | |
018d34a4 | 9639 | tok = end_tok + 1; |
5d5658a1 | 9640 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9641 | if (tok == tmptok) |
9642 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9643 | *thread = thr->global_num; |
bbc13ae3 | 9644 | tok = tmptok; |
018d34a4 | 9645 | } |
4a306c9a JB |
9646 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9647 | { | |
9648 | char *tmptok; | |
9649 | ||
9650 | tok = end_tok + 1; | |
bbc13ae3 | 9651 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9652 | if (tok == tmptok) |
9653 | error (_("Junk after task keyword.")); | |
9654 | if (!valid_task_id (*task)) | |
b6199126 | 9655 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9656 | tok = tmptok; |
4a306c9a | 9657 | } |
e7e0cddf SS |
9658 | else if (rest) |
9659 | { | |
9660 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9661 | return; |
e7e0cddf | 9662 | } |
018d34a4 VP |
9663 | else |
9664 | error (_("Junk at end of arguments.")); | |
9665 | } | |
9666 | } | |
9667 | ||
0fb4aa4b PA |
9668 | /* Decode a static tracepoint marker spec. */ |
9669 | ||
9670 | static struct symtabs_and_lines | |
f00aae0f | 9671 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9672 | { |
9673 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9674 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9675 | struct cleanup *old_chain; |
f00aae0f KS |
9676 | const char *p = &(*arg_p)[3]; |
9677 | const char *endp; | |
0fb4aa4b PA |
9678 | char *marker_str; |
9679 | int i; | |
9680 | ||
f00aae0f | 9681 | p = skip_spaces_const (p); |
0fb4aa4b | 9682 | |
f00aae0f | 9683 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9684 | |
9685 | marker_str = savestring (p, endp - p); | |
9686 | old_chain = make_cleanup (xfree, marker_str); | |
9687 | ||
9688 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9689 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9690 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9691 | ||
9692 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9693 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9694 | |
9695 | for (i = 0; i < sals.nelts; i++) | |
9696 | { | |
9697 | struct static_tracepoint_marker *marker; | |
9698 | ||
9699 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9700 | ||
9701 | init_sal (&sals.sals[i]); | |
9702 | ||
9703 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9704 | sals.sals[i].pc = marker->address; | |
9705 | ||
9706 | release_static_tracepoint_marker (marker); | |
9707 | } | |
9708 | ||
9709 | do_cleanups (old_chain); | |
9710 | ||
9711 | *arg_p = endp; | |
9712 | return sals; | |
9713 | } | |
9714 | ||
f00aae0f | 9715 | /* See breakpoint.h. */ |
0101ce28 | 9716 | |
8cdf0e15 VP |
9717 | int |
9718 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9719 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9720 | int thread, char *extra_string, |
f00aae0f | 9721 | int parse_extra, |
0fb4aa4b | 9722 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9723 | int ignore_count, |
9724 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9725 | const struct breakpoint_ops *ops, |
44f238bb PA |
9726 | int from_tty, int enabled, int internal, |
9727 | unsigned flags) | |
c3f6f71d | 9728 | { |
7efd8fc2 | 9729 | struct linespec_result canonical; |
c3f6f71d | 9730 | struct cleanup *old_chain; |
80c99de1 | 9731 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9732 | int pending = 0; |
4a306c9a | 9733 | int task = 0; |
86b17b60 | 9734 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9735 | |
348d480f PA |
9736 | gdb_assert (ops != NULL); |
9737 | ||
f00aae0f KS |
9738 | /* If extra_string isn't useful, set it to NULL. */ |
9739 | if (extra_string != NULL && *extra_string == '\0') | |
9740 | extra_string = NULL; | |
9741 | ||
7efd8fc2 | 9742 | init_linespec_result (&canonical); |
c3f6f71d | 9743 | |
492d29ea | 9744 | TRY |
b78a6381 | 9745 | { |
f00aae0f | 9746 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9747 | } |
492d29ea | 9748 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9749 | { |
492d29ea PA |
9750 | /* If caller is interested in rc value from parse, set |
9751 | value. */ | |
9752 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9753 | { |
05ff989b AC |
9754 | /* If pending breakpoint support is turned off, throw |
9755 | error. */ | |
fa8d40ab JJ |
9756 | |
9757 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9758 | throw_exception (e); |
9759 | ||
9760 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9761 | |
05ff989b AC |
9762 | /* If pending breakpoint support is auto query and the user |
9763 | selects no, then simply return the error code. */ | |
059fb39f | 9764 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9765 | && !nquery (_("Make %s pending on future shared library load? "), |
9766 | bptype_string (type_wanted))) | |
fd9b8c24 | 9767 | return 0; |
fa8d40ab | 9768 | |
05ff989b AC |
9769 | /* At this point, either the user was queried about setting |
9770 | a pending breakpoint and selected yes, or pending | |
9771 | breakpoint behavior is on and thus a pending breakpoint | |
9772 | is defaulted on behalf of the user. */ | |
f00aae0f | 9773 | pending = 1; |
0101ce28 | 9774 | } |
492d29ea PA |
9775 | else |
9776 | throw_exception (e); | |
0101ce28 | 9777 | } |
492d29ea PA |
9778 | END_CATCH |
9779 | ||
f00aae0f | 9780 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9781 | return 0; |
c3f6f71d | 9782 | |
4a64f543 | 9783 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9784 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9785 | |
c3f6f71d JM |
9786 | /* ----------------------------- SNIP ----------------------------- |
9787 | Anything added to the cleanup chain beyond this point is assumed | |
9788 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9789 | then the memory is not reclaimed. */ |
9790 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9791 | |
c3f6f71d JM |
9792 | /* Resolve all line numbers to PC's and verify that the addresses |
9793 | are ok for the target. */ | |
0101ce28 | 9794 | if (!pending) |
f8eba3c6 TT |
9795 | { |
9796 | int ix; | |
9797 | struct linespec_sals *iter; | |
9798 | ||
9799 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9800 | breakpoint_sals_to_pc (&iter->sals); | |
9801 | } | |
c3f6f71d | 9802 | |
7a697b8d | 9803 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9804 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9805 | { |
9806 | int ix; | |
9807 | struct linespec_sals *iter; | |
9808 | ||
9809 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9810 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9811 | } | |
7a697b8d | 9812 | |
c3f6f71d JM |
9813 | /* Verify that condition can be parsed, before setting any |
9814 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9815 | breakpoint. */ |
0101ce28 | 9816 | if (!pending) |
c3f6f71d | 9817 | { |
f00aae0f | 9818 | if (parse_extra) |
72b2ff0e | 9819 | { |
0878d0fa | 9820 | char *rest; |
52d361e1 YQ |
9821 | struct linespec_sals *lsal; |
9822 | ||
9823 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9824 | ||
0878d0fa YQ |
9825 | /* Here we only parse 'arg' to separate condition |
9826 | from thread number, so parsing in context of first | |
9827 | sal is OK. When setting the breakpoint we'll | |
9828 | re-parse it in context of each sal. */ | |
9829 | ||
f00aae0f KS |
9830 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9831 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9832 | if (cond_string) |
9833 | make_cleanup (xfree, cond_string); | |
9834 | if (rest) | |
9835 | make_cleanup (xfree, rest); | |
9836 | if (rest) | |
9837 | extra_string = rest; | |
f00aae0f KS |
9838 | else |
9839 | extra_string = NULL; | |
72b2ff0e | 9840 | } |
2f069f6f | 9841 | else |
72b2ff0e | 9842 | { |
f00aae0f KS |
9843 | if (type_wanted != bp_dprintf |
9844 | && extra_string != NULL && *extra_string != '\0') | |
9845 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9846 | |
9847 | /* Create a private copy of condition string. */ | |
9848 | if (cond_string) | |
9849 | { | |
9850 | cond_string = xstrdup (cond_string); | |
9851 | make_cleanup (xfree, cond_string); | |
9852 | } | |
9853 | /* Create a private copy of any extra string. */ | |
9854 | if (extra_string) | |
9855 | { | |
9856 | extra_string = xstrdup (extra_string); | |
9857 | make_cleanup (xfree, extra_string); | |
9858 | } | |
72b2ff0e | 9859 | } |
0fb4aa4b | 9860 | |
52d361e1 | 9861 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9862 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9863 | tempflag ? disp_del : disp_donttouch, |
9864 | thread, task, ignore_count, ops, | |
44f238bb | 9865 | from_tty, enabled, internal, flags); |
c906108c | 9866 | } |
0101ce28 JJ |
9867 | else |
9868 | { | |
0101ce28 JJ |
9869 | struct breakpoint *b; |
9870 | ||
bfccc43c YQ |
9871 | if (is_tracepoint_type (type_wanted)) |
9872 | { | |
9873 | struct tracepoint *t; | |
9874 | ||
4d01a485 | 9875 | t = new tracepoint (); |
bfccc43c YQ |
9876 | b = &t->base; |
9877 | } | |
9878 | else | |
4d01a485 | 9879 | b = new breakpoint (); |
bfccc43c YQ |
9880 | |
9881 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
ffc2605c | 9882 | b->location = copy_event_location (location).release (); |
bfccc43c | 9883 | |
f00aae0f KS |
9884 | if (parse_extra) |
9885 | b->cond_string = NULL; | |
e12c7713 MK |
9886 | else |
9887 | { | |
9888 | /* Create a private copy of condition string. */ | |
9889 | if (cond_string) | |
9890 | { | |
9891 | cond_string = xstrdup (cond_string); | |
9892 | make_cleanup (xfree, cond_string); | |
9893 | } | |
9894 | b->cond_string = cond_string; | |
15630549 | 9895 | b->thread = thread; |
e12c7713 | 9896 | } |
f00aae0f KS |
9897 | |
9898 | /* Create a private copy of any extra string. */ | |
9899 | if (extra_string != NULL) | |
9900 | { | |
9901 | extra_string = xstrdup (extra_string); | |
9902 | make_cleanup (xfree, extra_string); | |
9903 | } | |
9904 | b->extra_string = extra_string; | |
0101ce28 | 9905 | b->ignore_count = ignore_count; |
0101ce28 | 9906 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9907 | b->condition_not_parsed = 1; |
41447f92 | 9908 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9909 | if ((type_wanted != bp_breakpoint |
9910 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9911 | b->pspace = current_program_space; |
8bea4e01 | 9912 | |
bfccc43c | 9913 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9914 | } |
9915 | ||
f8eba3c6 | 9916 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9917 | { |
3e43a32a MS |
9918 | warning (_("Multiple breakpoints were set.\nUse the " |
9919 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9920 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9921 | } |
9922 | ||
80c99de1 PA |
9923 | /* That's it. Discard the cleanups for data inserted into the |
9924 | breakpoint. */ | |
9925 | discard_cleanups (bkpt_chain); | |
9926 | /* But cleanup everything else. */ | |
c3f6f71d | 9927 | do_cleanups (old_chain); |
217dc9e2 | 9928 | |
80c99de1 | 9929 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9930 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9931 | |
9932 | return 1; | |
c3f6f71d | 9933 | } |
c906108c | 9934 | |
348d480f | 9935 | /* Set a breakpoint. |
72b2ff0e VP |
9936 | ARG is a string describing breakpoint address, |
9937 | condition, and thread. | |
9938 | FLAG specifies if a breakpoint is hardware on, | |
9939 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9940 | and BP_TEMPFLAG. */ | |
348d480f | 9941 | |
98deb0da | 9942 | static void |
72b2ff0e | 9943 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9944 | { |
72b2ff0e | 9945 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9946 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9947 | ? bp_hardware_breakpoint | |
9948 | : bp_breakpoint); | |
55aa24fb | 9949 | struct breakpoint_ops *ops; |
f00aae0f | 9950 | |
ffc2605c | 9951 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9952 | |
9953 | /* Matching breakpoints on probes. */ | |
5b56227b | 9954 | if (location != NULL |
ffc2605c | 9955 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9956 | ops = &bkpt_probe_breakpoint_ops; |
9957 | else | |
9958 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9959 | |
8cdf0e15 | 9960 | create_breakpoint (get_current_arch (), |
ffc2605c | 9961 | location.get (), |
f00aae0f | 9962 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9963 | tempflag, type_wanted, |
8cdf0e15 VP |
9964 | 0 /* Ignore count */, |
9965 | pending_break_support, | |
55aa24fb | 9966 | ops, |
8cdf0e15 | 9967 | from_tty, |
84f4c1fe | 9968 | 1 /* enabled */, |
44f238bb PA |
9969 | 0 /* internal */, |
9970 | 0); | |
c906108c SS |
9971 | } |
9972 | ||
c906108c SS |
9973 | /* Helper function for break_command_1 and disassemble_command. */ |
9974 | ||
9975 | void | |
fba45db2 | 9976 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9977 | { |
9978 | CORE_ADDR pc; | |
9979 | ||
9980 | if (sal->pc == 0 && sal->symtab != NULL) | |
9981 | { | |
9982 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9983 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9984 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9985 | sal->pc = pc; |
6a048695 | 9986 | |
4a64f543 MS |
9987 | /* If this SAL corresponds to a breakpoint inserted using a line |
9988 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9989 | if (sal->explicit_line) |
059acae7 | 9990 | skip_prologue_sal (sal); |
c906108c SS |
9991 | } |
9992 | ||
9993 | if (sal->section == 0 && sal->symtab != NULL) | |
9994 | { | |
346d1dfe | 9995 | const struct blockvector *bv; |
3977b71f | 9996 | const struct block *b; |
c5aa993b | 9997 | struct symbol *sym; |
c906108c | 9998 | |
43f3e411 DE |
9999 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10000 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10001 | if (bv != NULL) |
10002 | { | |
7f0df278 | 10003 | sym = block_linkage_function (b); |
c906108c SS |
10004 | if (sym != NULL) |
10005 | { | |
eb822aa6 DE |
10006 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10007 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10008 | sym); | |
c906108c SS |
10009 | } |
10010 | else | |
10011 | { | |
4a64f543 MS |
10012 | /* It really is worthwhile to have the section, so we'll |
10013 | just have to look harder. This case can be executed | |
10014 | if we have line numbers but no functions (as can | |
10015 | happen in assembly source). */ | |
c906108c | 10016 | |
7cbd4a93 | 10017 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10018 | struct cleanup *old_chain = save_current_space_and_thread (); |
10019 | ||
10020 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10021 | |
10022 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10023 | if (msym.minsym) |
efd66ac6 | 10024 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10025 | |
10026 | do_cleanups (old_chain); | |
c906108c SS |
10027 | } |
10028 | } | |
10029 | } | |
10030 | } | |
10031 | ||
10032 | void | |
fba45db2 | 10033 | break_command (char *arg, int from_tty) |
c906108c | 10034 | { |
db107f19 | 10035 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10036 | } |
10037 | ||
c906108c | 10038 | void |
fba45db2 | 10039 | tbreak_command (char *arg, int from_tty) |
c906108c | 10040 | { |
db107f19 | 10041 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10042 | } |
10043 | ||
c906108c | 10044 | static void |
fba45db2 | 10045 | hbreak_command (char *arg, int from_tty) |
c906108c | 10046 | { |
db107f19 | 10047 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10048 | } |
10049 | ||
10050 | static void | |
fba45db2 | 10051 | thbreak_command (char *arg, int from_tty) |
c906108c | 10052 | { |
db107f19 | 10053 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10054 | } |
10055 | ||
10056 | static void | |
fba45db2 | 10057 | stop_command (char *arg, int from_tty) |
c906108c | 10058 | { |
a3f17187 | 10059 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10060 | Usage: stop in <function | address>\n\ |
a3f17187 | 10061 | stop at <line>\n")); |
c906108c SS |
10062 | } |
10063 | ||
10064 | static void | |
fba45db2 | 10065 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10066 | { |
10067 | int badInput = 0; | |
10068 | ||
c5aa993b | 10069 | if (arg == (char *) NULL) |
c906108c SS |
10070 | badInput = 1; |
10071 | else if (*arg != '*') | |
10072 | { | |
10073 | char *argptr = arg; | |
10074 | int hasColon = 0; | |
10075 | ||
4a64f543 | 10076 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10077 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10078 | function/method name. */ |
c906108c | 10079 | while (*argptr && !hasColon) |
c5aa993b JM |
10080 | { |
10081 | hasColon = (*argptr == ':'); | |
10082 | argptr++; | |
10083 | } | |
c906108c SS |
10084 | |
10085 | if (hasColon) | |
c5aa993b | 10086 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10087 | else |
c5aa993b | 10088 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10089 | } |
10090 | ||
10091 | if (badInput) | |
a3f17187 | 10092 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10093 | else |
db107f19 | 10094 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10095 | } |
10096 | ||
10097 | static void | |
fba45db2 | 10098 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10099 | { |
10100 | int badInput = 0; | |
10101 | ||
c5aa993b | 10102 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10103 | badInput = 1; |
10104 | else | |
10105 | { | |
10106 | char *argptr = arg; | |
10107 | int hasColon = 0; | |
10108 | ||
4a64f543 MS |
10109 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10110 | it is probably a line number. */ | |
c906108c | 10111 | while (*argptr && !hasColon) |
c5aa993b JM |
10112 | { |
10113 | hasColon = (*argptr == ':'); | |
10114 | argptr++; | |
10115 | } | |
c906108c SS |
10116 | |
10117 | if (hasColon) | |
c5aa993b | 10118 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10119 | else |
c5aa993b | 10120 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10121 | } |
10122 | ||
10123 | if (badInput) | |
a3f17187 | 10124 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10125 | else |
db107f19 | 10126 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10127 | } |
10128 | ||
e7e0cddf SS |
10129 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10130 | with a prewired command list consisting of a single output command, | |
10131 | built from extra arguments supplied on the dprintf command | |
10132 | line. */ | |
10133 | ||
da821c7b | 10134 | static void |
e7e0cddf SS |
10135 | dprintf_command (char *arg, int from_tty) |
10136 | { | |
ffc2605c | 10137 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
10138 | |
10139 | /* If non-NULL, ARG should have been advanced past the location; | |
10140 | the next character must be ','. */ | |
10141 | if (arg != NULL) | |
10142 | { | |
10143 | if (arg[0] != ',' || arg[1] == '\0') | |
10144 | error (_("Format string required")); | |
10145 | else | |
10146 | { | |
10147 | /* Skip the comma. */ | |
10148 | ++arg; | |
10149 | } | |
10150 | } | |
10151 | ||
e7e0cddf | 10152 | create_breakpoint (get_current_arch (), |
ffc2605c | 10153 | location.get (), |
f00aae0f | 10154 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
10155 | 0, bp_dprintf, |
10156 | 0 /* Ignore count */, | |
10157 | pending_break_support, | |
10158 | &dprintf_breakpoint_ops, | |
10159 | from_tty, | |
10160 | 1 /* enabled */, | |
10161 | 0 /* internal */, | |
10162 | 0); | |
10163 | } | |
10164 | ||
d3ce09f5 SS |
10165 | static void |
10166 | agent_printf_command (char *arg, int from_tty) | |
10167 | { | |
10168 | error (_("May only run agent-printf on the target")); | |
10169 | } | |
10170 | ||
f1310107 TJB |
10171 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10172 | ranged breakpoints. */ | |
10173 | ||
10174 | static int | |
10175 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10176 | struct address_space *aspace, | |
09ac7c10 TT |
10177 | CORE_ADDR bp_addr, |
10178 | const struct target_waitstatus *ws) | |
f1310107 | 10179 | { |
09ac7c10 | 10180 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10181 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10182 | return 0; |
10183 | ||
f1310107 TJB |
10184 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10185 | bl->length, aspace, bp_addr); | |
10186 | } | |
10187 | ||
10188 | /* Implement the "resources_needed" breakpoint_ops method for | |
10189 | ranged breakpoints. */ | |
10190 | ||
10191 | static int | |
10192 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10193 | { | |
10194 | return target_ranged_break_num_registers (); | |
10195 | } | |
10196 | ||
10197 | /* Implement the "print_it" breakpoint_ops method for | |
10198 | ranged breakpoints. */ | |
10199 | ||
10200 | static enum print_stop_action | |
348d480f | 10201 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10202 | { |
348d480f | 10203 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10204 | struct bp_location *bl = b->loc; |
79a45e25 | 10205 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10206 | |
10207 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10208 | ||
10209 | /* Ranged breakpoints have only one location. */ | |
10210 | gdb_assert (bl && bl->next == NULL); | |
10211 | ||
10212 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10213 | |
10214 | maybe_print_thread_hit_breakpoint (uiout); | |
10215 | ||
f1310107 | 10216 | if (b->disposition == disp_del) |
112e8700 | 10217 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 10218 | else |
112e8700 SM |
10219 | uiout->text ("Ranged breakpoint "); |
10220 | if (uiout->is_mi_like_p ()) | |
f1310107 | 10221 | { |
112e8700 | 10222 | uiout->field_string ("reason", |
f1310107 | 10223 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 10224 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 10225 | } |
112e8700 SM |
10226 | uiout->field_int ("bkptno", b->number); |
10227 | uiout->text (", "); | |
f1310107 TJB |
10228 | |
10229 | return PRINT_SRC_AND_LOC; | |
10230 | } | |
10231 | ||
10232 | /* Implement the "print_one" breakpoint_ops method for | |
10233 | ranged breakpoints. */ | |
10234 | ||
10235 | static void | |
10236 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10237 | struct bp_location **last_loc) | |
10238 | { | |
10239 | struct bp_location *bl = b->loc; | |
10240 | struct value_print_options opts; | |
79a45e25 | 10241 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10242 | |
10243 | /* Ranged breakpoints have only one location. */ | |
10244 | gdb_assert (bl && bl->next == NULL); | |
10245 | ||
10246 | get_user_print_options (&opts); | |
10247 | ||
10248 | if (opts.addressprint) | |
10249 | /* We don't print the address range here, it will be printed later | |
10250 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 10251 | uiout->field_skip ("addr"); |
f1310107 TJB |
10252 | annotate_field (5); |
10253 | print_breakpoint_location (b, bl); | |
10254 | *last_loc = bl; | |
10255 | } | |
10256 | ||
10257 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10258 | ranged breakpoints. */ | |
10259 | ||
10260 | static void | |
10261 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10262 | struct ui_out *uiout) | |
10263 | { | |
10264 | CORE_ADDR address_start, address_end; | |
10265 | struct bp_location *bl = b->loc; | |
d7e74731 | 10266 | string_file stb; |
f1310107 TJB |
10267 | |
10268 | gdb_assert (bl); | |
10269 | ||
10270 | address_start = bl->address; | |
10271 | address_end = address_start + bl->length - 1; | |
10272 | ||
112e8700 | 10273 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10274 | stb.printf ("[%s, %s]", |
10275 | print_core_address (bl->gdbarch, address_start), | |
10276 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10277 | uiout->field_stream ("addr", stb); |
10278 | uiout->text ("\n"); | |
f1310107 TJB |
10279 | } |
10280 | ||
10281 | /* Implement the "print_mention" breakpoint_ops method for | |
10282 | ranged breakpoints. */ | |
10283 | ||
10284 | static void | |
10285 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10286 | { | |
10287 | struct bp_location *bl = b->loc; | |
79a45e25 | 10288 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10289 | |
10290 | gdb_assert (bl); | |
10291 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10292 | ||
112e8700 | 10293 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10294 | return; |
10295 | ||
10296 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10297 | b->number, paddress (bl->gdbarch, bl->address), | |
10298 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10299 | } | |
10300 | ||
10301 | /* Implement the "print_recreate" breakpoint_ops method for | |
10302 | ranged breakpoints. */ | |
10303 | ||
10304 | static void | |
10305 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10306 | { | |
f00aae0f KS |
10307 | fprintf_unfiltered (fp, "break-range %s, %s", |
10308 | event_location_to_string (b->location), | |
10309 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10310 | print_recreate_thread (b, fp); |
f1310107 TJB |
10311 | } |
10312 | ||
10313 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10314 | ||
2060206e | 10315 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10316 | |
10317 | /* Find the address where the end of the breakpoint range should be | |
10318 | placed, given the SAL of the end of the range. This is so that if | |
10319 | the user provides a line number, the end of the range is set to the | |
10320 | last instruction of the given line. */ | |
10321 | ||
10322 | static CORE_ADDR | |
10323 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10324 | { | |
10325 | CORE_ADDR end; | |
10326 | ||
10327 | /* If the user provided a PC value, use it. Otherwise, | |
10328 | find the address of the end of the given location. */ | |
10329 | if (sal.explicit_pc) | |
10330 | end = sal.pc; | |
10331 | else | |
10332 | { | |
10333 | int ret; | |
10334 | CORE_ADDR start; | |
10335 | ||
10336 | ret = find_line_pc_range (sal, &start, &end); | |
10337 | if (!ret) | |
10338 | error (_("Could not find location of the end of the range.")); | |
10339 | ||
10340 | /* find_line_pc_range returns the start of the next line. */ | |
10341 | end--; | |
10342 | } | |
10343 | ||
10344 | return end; | |
10345 | } | |
10346 | ||
10347 | /* Implement the "break-range" CLI command. */ | |
10348 | ||
10349 | static void | |
10350 | break_range_command (char *arg, int from_tty) | |
10351 | { | |
870f88f7 | 10352 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10353 | struct linespec_result canonical_start, canonical_end; |
10354 | int bp_count, can_use_bp, length; | |
10355 | CORE_ADDR end; | |
10356 | struct breakpoint *b; | |
10357 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10358 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10359 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10360 | |
10361 | /* We don't support software ranged breakpoints. */ | |
10362 | if (target_ranged_break_num_registers () < 0) | |
10363 | error (_("This target does not support hardware ranged breakpoints.")); | |
10364 | ||
10365 | bp_count = hw_breakpoint_used_count (); | |
10366 | bp_count += target_ranged_break_num_registers (); | |
10367 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10368 | bp_count, 0); | |
10369 | if (can_use_bp < 0) | |
10370 | error (_("Hardware breakpoints used exceeds limit.")); | |
10371 | ||
f8eba3c6 | 10372 | arg = skip_spaces (arg); |
f1310107 TJB |
10373 | if (arg == NULL || arg[0] == '\0') |
10374 | error(_("No address range specified.")); | |
10375 | ||
f1310107 TJB |
10376 | init_linespec_result (&canonical_start); |
10377 | ||
f8eba3c6 | 10378 | arg_start = arg; |
ffc2605c TT |
10379 | event_location_up start_location = string_to_event_location (&arg, |
10380 | current_language); | |
10381 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
10382 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10383 | |
10384 | if (arg[0] != ',') | |
10385 | error (_("Too few arguments.")); | |
f8eba3c6 | 10386 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10387 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10388 | |
10389 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10390 | ||
10391 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10392 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10393 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10394 | ||
f8eba3c6 TT |
10395 | sal_start = lsal_start->sals.sals[0]; |
10396 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10397 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10398 | |
10399 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10400 | arg = skip_spaces (arg); |
f1310107 TJB |
10401 | |
10402 | /* Parse the end location. */ | |
10403 | ||
f1310107 TJB |
10404 | init_linespec_result (&canonical_end); |
10405 | arg_start = arg; | |
10406 | ||
f8eba3c6 | 10407 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10408 | parse_breakpoint_sals because we need to specify the start location's |
10409 | symtab and line as the default symtab and line for the end of the | |
10410 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10411 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10412 | event_location_up end_location = string_to_event_location (&arg, |
10413 | current_language); | |
10414 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10415 | sal_start.symtab, sal_start.line, |
10416 | &canonical_end, NULL, NULL); | |
10417 | ||
10418 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10419 | |
f8eba3c6 | 10420 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10421 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10422 | |
10423 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10424 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10425 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10426 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10427 | ||
f8eba3c6 | 10428 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10429 | |
10430 | end = find_breakpoint_range_end (sal_end); | |
10431 | if (sal_start.pc > end) | |
177b42fe | 10432 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10433 | |
10434 | length = end - sal_start.pc + 1; | |
10435 | if (length < 0) | |
10436 | /* Length overflowed. */ | |
10437 | error (_("Address range too large.")); | |
10438 | else if (length == 1) | |
10439 | { | |
10440 | /* This range is simple enough to be handled by | |
10441 | the `hbreak' command. */ | |
10442 | hbreak_command (addr_string_start, 1); | |
10443 | ||
10444 | do_cleanups (cleanup_bkpt); | |
10445 | ||
10446 | return; | |
10447 | } | |
10448 | ||
10449 | /* Now set up the breakpoint. */ | |
10450 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10451 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10452 | set_breakpoint_count (breakpoint_count + 1); |
10453 | b->number = breakpoint_count; | |
10454 | b->disposition = disp_donttouch; | |
ffc2605c TT |
10455 | b->location = start_location.release (); |
10456 | b->location_range_end = end_location.release (); | |
f1310107 TJB |
10457 | b->loc->length = length; |
10458 | ||
f8eba3c6 | 10459 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10460 | |
10461 | mention (b); | |
8d3788bd | 10462 | observer_notify_breakpoint_created (b); |
44702360 | 10463 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10464 | } |
10465 | ||
4a64f543 MS |
10466 | /* Return non-zero if EXP is verified as constant. Returned zero |
10467 | means EXP is variable. Also the constant detection may fail for | |
10468 | some constant expressions and in such case still falsely return | |
10469 | zero. */ | |
2e6e3d9c | 10470 | |
65d79d4b SDJ |
10471 | static int |
10472 | watchpoint_exp_is_const (const struct expression *exp) | |
10473 | { | |
10474 | int i = exp->nelts; | |
10475 | ||
10476 | while (i > 0) | |
10477 | { | |
10478 | int oplenp, argsp; | |
10479 | ||
10480 | /* We are only interested in the descriptor of each element. */ | |
10481 | operator_length (exp, i, &oplenp, &argsp); | |
10482 | i -= oplenp; | |
10483 | ||
10484 | switch (exp->elts[i].opcode) | |
10485 | { | |
10486 | case BINOP_ADD: | |
10487 | case BINOP_SUB: | |
10488 | case BINOP_MUL: | |
10489 | case BINOP_DIV: | |
10490 | case BINOP_REM: | |
10491 | case BINOP_MOD: | |
10492 | case BINOP_LSH: | |
10493 | case BINOP_RSH: | |
10494 | case BINOP_LOGICAL_AND: | |
10495 | case BINOP_LOGICAL_OR: | |
10496 | case BINOP_BITWISE_AND: | |
10497 | case BINOP_BITWISE_IOR: | |
10498 | case BINOP_BITWISE_XOR: | |
10499 | case BINOP_EQUAL: | |
10500 | case BINOP_NOTEQUAL: | |
10501 | case BINOP_LESS: | |
10502 | case BINOP_GTR: | |
10503 | case BINOP_LEQ: | |
10504 | case BINOP_GEQ: | |
10505 | case BINOP_REPEAT: | |
10506 | case BINOP_COMMA: | |
10507 | case BINOP_EXP: | |
10508 | case BINOP_MIN: | |
10509 | case BINOP_MAX: | |
10510 | case BINOP_INTDIV: | |
10511 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10512 | case TERNOP_COND: |
10513 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10514 | |
10515 | case OP_LONG: | |
10516 | case OP_DOUBLE: | |
10517 | case OP_DECFLOAT: | |
10518 | case OP_LAST: | |
10519 | case OP_COMPLEX: | |
10520 | case OP_STRING: | |
65d79d4b SDJ |
10521 | case OP_ARRAY: |
10522 | case OP_TYPE: | |
608b4967 TT |
10523 | case OP_TYPEOF: |
10524 | case OP_DECLTYPE: | |
6e72ca20 | 10525 | case OP_TYPEID: |
65d79d4b SDJ |
10526 | case OP_NAME: |
10527 | case OP_OBJC_NSSTRING: | |
10528 | ||
10529 | case UNOP_NEG: | |
10530 | case UNOP_LOGICAL_NOT: | |
10531 | case UNOP_COMPLEMENT: | |
10532 | case UNOP_ADDR: | |
10533 | case UNOP_HIGH: | |
aeaa2474 | 10534 | case UNOP_CAST: |
9eaf6705 TT |
10535 | |
10536 | case UNOP_CAST_TYPE: | |
10537 | case UNOP_REINTERPRET_CAST: | |
10538 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10539 | /* Unary, binary and ternary operators: We have to check |
10540 | their operands. If they are constant, then so is the | |
10541 | result of that operation. For instance, if A and B are | |
10542 | determined to be constants, then so is "A + B". | |
10543 | ||
10544 | UNOP_IND is one exception to the rule above, because the | |
10545 | value of *ADDR is not necessarily a constant, even when | |
10546 | ADDR is. */ | |
65d79d4b SDJ |
10547 | break; |
10548 | ||
10549 | case OP_VAR_VALUE: | |
10550 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10551 | |
65d79d4b | 10552 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10553 | possible that a buggy compiler could mark a variable as |
10554 | constant even when it is not, and TYPE_CONST would return | |
10555 | true in this case, while SYMBOL_CLASS wouldn't. | |
10556 | ||
10557 | We also have to check for function symbols because they | |
10558 | are always constant. */ | |
65d79d4b SDJ |
10559 | { |
10560 | struct symbol *s = exp->elts[i + 2].symbol; | |
10561 | ||
10562 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10563 | && SYMBOL_CLASS (s) != LOC_CONST | |
10564 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10565 | return 0; | |
10566 | break; | |
10567 | } | |
10568 | ||
10569 | /* The default action is to return 0 because we are using | |
10570 | the optimistic approach here: If we don't know something, | |
10571 | then it is not a constant. */ | |
10572 | default: | |
10573 | return 0; | |
10574 | } | |
10575 | } | |
10576 | ||
10577 | return 1; | |
10578 | } | |
10579 | ||
3a5c3e22 PA |
10580 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10581 | ||
10582 | static void | |
10583 | dtor_watchpoint (struct breakpoint *self) | |
10584 | { | |
10585 | struct watchpoint *w = (struct watchpoint *) self; | |
10586 | ||
3a5c3e22 PA |
10587 | xfree (w->exp_string); |
10588 | xfree (w->exp_string_reparse); | |
10589 | value_free (w->val); | |
10590 | ||
10591 | base_breakpoint_ops.dtor (self); | |
10592 | } | |
10593 | ||
348d480f PA |
10594 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10595 | ||
10596 | static void | |
10597 | re_set_watchpoint (struct breakpoint *b) | |
10598 | { | |
3a5c3e22 PA |
10599 | struct watchpoint *w = (struct watchpoint *) b; |
10600 | ||
348d480f PA |
10601 | /* Watchpoint can be either on expression using entirely global |
10602 | variables, or it can be on local variables. | |
10603 | ||
10604 | Watchpoints of the first kind are never auto-deleted, and even | |
10605 | persist across program restarts. Since they can use variables | |
10606 | from shared libraries, we need to reparse expression as libraries | |
10607 | are loaded and unloaded. | |
10608 | ||
10609 | Watchpoints on local variables can also change meaning as result | |
10610 | of solib event. For example, if a watchpoint uses both a local | |
10611 | and a global variables in expression, it's a local watchpoint, | |
10612 | but unloading of a shared library will make the expression | |
10613 | invalid. This is not a very common use case, but we still | |
10614 | re-evaluate expression, to avoid surprises to the user. | |
10615 | ||
10616 | Note that for local watchpoints, we re-evaluate it only if | |
10617 | watchpoints frame id is still valid. If it's not, it means the | |
10618 | watchpoint is out of scope and will be deleted soon. In fact, | |
10619 | I'm not sure we'll ever be called in this case. | |
10620 | ||
10621 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10622 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10623 | |
3a5c3e22 PA |
10624 | Don't do anything about disabled watchpoints, since they will be |
10625 | reevaluated again when enabled. */ | |
10626 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10627 | } |
10628 | ||
77b06cd7 TJB |
10629 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10630 | ||
10631 | static int | |
10632 | insert_watchpoint (struct bp_location *bl) | |
10633 | { | |
3a5c3e22 PA |
10634 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10635 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10636 | |
10637 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10638 | w->cond_exp.get ()); |
77b06cd7 TJB |
10639 | } |
10640 | ||
10641 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10642 | ||
10643 | static int | |
73971819 | 10644 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10645 | { |
3a5c3e22 PA |
10646 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10647 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10648 | |
10649 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10650 | w->cond_exp.get ()); |
e09342b5 TJB |
10651 | } |
10652 | ||
e09342b5 | 10653 | static int |
348d480f | 10654 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10655 | struct address_space *aspace, CORE_ADDR bp_addr, |
10656 | const struct target_waitstatus *ws) | |
e09342b5 | 10657 | { |
348d480f | 10658 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10659 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10660 | |
348d480f PA |
10661 | /* Continuable hardware watchpoints are treated as non-existent if the |
10662 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10663 | some data address). Otherwise gdb won't stop on a break instruction | |
10664 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10665 | been defined. Also skip watchpoints which we know did not trigger | |
10666 | (did not match the data address). */ | |
10667 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10668 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10669 | return 0; |
9c06b0b4 | 10670 | |
348d480f | 10671 | return 1; |
9c06b0b4 TJB |
10672 | } |
10673 | ||
348d480f PA |
10674 | static void |
10675 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10676 | { |
348d480f | 10677 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10678 | |
348d480f | 10679 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10680 | } |
10681 | ||
10682 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10683 | hardware watchpoints. */ |
9c06b0b4 TJB |
10684 | |
10685 | static int | |
348d480f | 10686 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10687 | { |
3a5c3e22 PA |
10688 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10689 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10690 | |
10691 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10692 | } |
10693 | ||
10694 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10695 | hardware watchpoints. */ |
9c06b0b4 TJB |
10696 | |
10697 | static int | |
348d480f | 10698 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10699 | { |
efa80663 PA |
10700 | /* Read and access watchpoints only work with hardware support. */ |
10701 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10702 | } |
10703 | ||
9c06b0b4 | 10704 | static enum print_stop_action |
348d480f | 10705 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10706 | { |
348d480f PA |
10707 | struct cleanup *old_chain; |
10708 | struct breakpoint *b; | |
348d480f | 10709 | enum print_stop_action result; |
3a5c3e22 | 10710 | struct watchpoint *w; |
79a45e25 | 10711 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10712 | |
10713 | gdb_assert (bs->bp_location_at != NULL); | |
10714 | ||
348d480f | 10715 | b = bs->breakpoint_at; |
3a5c3e22 | 10716 | w = (struct watchpoint *) b; |
348d480f | 10717 | |
d7e74731 | 10718 | old_chain = make_cleanup (null_cleanup, NULL); |
9c06b0b4 | 10719 | |
f303dbd6 PA |
10720 | annotate_watchpoint (b->number); |
10721 | maybe_print_thread_hit_breakpoint (uiout); | |
10722 | ||
d7e74731 PA |
10723 | string_file stb; |
10724 | ||
9c06b0b4 TJB |
10725 | switch (b->type) |
10726 | { | |
348d480f | 10727 | case bp_watchpoint: |
9c06b0b4 | 10728 | case bp_hardware_watchpoint: |
112e8700 SM |
10729 | if (uiout->is_mi_like_p ()) |
10730 | uiout->field_string | |
10731 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10732 | mention (b); |
10733 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10734 | uiout->text ("\nOld value = "); |
d7e74731 | 10735 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10736 | uiout->field_stream ("old", stb); |
10737 | uiout->text ("\nNew value = "); | |
d7e74731 | 10738 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10739 | uiout->field_stream ("new", stb); |
10740 | uiout->text ("\n"); | |
348d480f PA |
10741 | /* More than one watchpoint may have been triggered. */ |
10742 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10743 | break; |
10744 | ||
10745 | case bp_read_watchpoint: | |
112e8700 SM |
10746 | if (uiout->is_mi_like_p ()) |
10747 | uiout->field_string | |
10748 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10749 | mention (b); |
10750 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10751 | uiout->text ("\nValue = "); |
d7e74731 | 10752 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10753 | uiout->field_stream ("value", stb); |
10754 | uiout->text ("\n"); | |
348d480f | 10755 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10756 | break; |
10757 | ||
10758 | case bp_access_watchpoint: | |
348d480f PA |
10759 | if (bs->old_val != NULL) |
10760 | { | |
112e8700 SM |
10761 | if (uiout->is_mi_like_p ()) |
10762 | uiout->field_string | |
10763 | ("reason", | |
348d480f PA |
10764 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10765 | mention (b); | |
10766 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10767 | uiout->text ("\nOld value = "); |
d7e74731 | 10768 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10769 | uiout->field_stream ("old", stb); |
10770 | uiout->text ("\nNew value = "); | |
348d480f PA |
10771 | } |
10772 | else | |
10773 | { | |
10774 | mention (b); | |
112e8700 SM |
10775 | if (uiout->is_mi_like_p ()) |
10776 | uiout->field_string | |
10777 | ("reason", | |
348d480f PA |
10778 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10779 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10780 | uiout->text ("\nValue = "); |
348d480f | 10781 | } |
d7e74731 | 10782 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10783 | uiout->field_stream ("new", stb); |
10784 | uiout->text ("\n"); | |
348d480f | 10785 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10786 | break; |
10787 | default: | |
348d480f | 10788 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10789 | } |
10790 | ||
348d480f PA |
10791 | do_cleanups (old_chain); |
10792 | return result; | |
10793 | } | |
10794 | ||
10795 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10796 | watchpoints. */ | |
10797 | ||
10798 | static void | |
10799 | print_mention_watchpoint (struct breakpoint *b) | |
10800 | { | |
10801 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10802 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10803 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10804 | |
10805 | switch (b->type) | |
10806 | { | |
10807 | case bp_watchpoint: | |
112e8700 | 10808 | uiout->text ("Watchpoint "); |
348d480f PA |
10809 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
10810 | break; | |
10811 | case bp_hardware_watchpoint: | |
112e8700 | 10812 | uiout->text ("Hardware watchpoint "); |
348d480f PA |
10813 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
10814 | break; | |
10815 | case bp_read_watchpoint: | |
112e8700 | 10816 | uiout->text ("Hardware read watchpoint "); |
348d480f PA |
10817 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
10818 | break; | |
10819 | case bp_access_watchpoint: | |
112e8700 | 10820 | uiout->text ("Hardware access (read/write) watchpoint "); |
348d480f PA |
10821 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
10822 | break; | |
10823 | default: | |
10824 | internal_error (__FILE__, __LINE__, | |
10825 | _("Invalid hardware watchpoint type.")); | |
10826 | } | |
10827 | ||
112e8700 SM |
10828 | uiout->field_int ("number", b->number); |
10829 | uiout->text (": "); | |
10830 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10831 | do_cleanups (ui_out_chain); |
10832 | } | |
10833 | ||
10834 | /* Implement the "print_recreate" breakpoint_ops method for | |
10835 | watchpoints. */ | |
10836 | ||
10837 | static void | |
10838 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10839 | { | |
3a5c3e22 PA |
10840 | struct watchpoint *w = (struct watchpoint *) b; |
10841 | ||
348d480f PA |
10842 | switch (b->type) |
10843 | { | |
10844 | case bp_watchpoint: | |
10845 | case bp_hardware_watchpoint: | |
10846 | fprintf_unfiltered (fp, "watch"); | |
10847 | break; | |
10848 | case bp_read_watchpoint: | |
10849 | fprintf_unfiltered (fp, "rwatch"); | |
10850 | break; | |
10851 | case bp_access_watchpoint: | |
10852 | fprintf_unfiltered (fp, "awatch"); | |
10853 | break; | |
10854 | default: | |
10855 | internal_error (__FILE__, __LINE__, | |
10856 | _("Invalid watchpoint type.")); | |
10857 | } | |
10858 | ||
3a5c3e22 | 10859 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10860 | print_recreate_thread (b, fp); |
348d480f PA |
10861 | } |
10862 | ||
427cd150 TT |
10863 | /* Implement the "explains_signal" breakpoint_ops method for |
10864 | watchpoints. */ | |
10865 | ||
47591c29 | 10866 | static int |
427cd150 TT |
10867 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10868 | { | |
10869 | /* A software watchpoint cannot cause a signal other than | |
10870 | GDB_SIGNAL_TRAP. */ | |
10871 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10872 | return 0; |
427cd150 | 10873 | |
47591c29 | 10874 | return 1; |
427cd150 TT |
10875 | } |
10876 | ||
348d480f PA |
10877 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10878 | ||
2060206e | 10879 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10880 | |
10881 | /* Implement the "insert" breakpoint_ops method for | |
10882 | masked hardware watchpoints. */ | |
10883 | ||
10884 | static int | |
10885 | insert_masked_watchpoint (struct bp_location *bl) | |
10886 | { | |
3a5c3e22 PA |
10887 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10888 | ||
10889 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10890 | bl->watchpoint_type); |
10891 | } | |
10892 | ||
10893 | /* Implement the "remove" breakpoint_ops method for | |
10894 | masked hardware watchpoints. */ | |
10895 | ||
10896 | static int | |
73971819 | 10897 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10898 | { |
3a5c3e22 PA |
10899 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10900 | ||
10901 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10902 | bl->watchpoint_type); |
10903 | } | |
10904 | ||
10905 | /* Implement the "resources_needed" breakpoint_ops method for | |
10906 | masked hardware watchpoints. */ | |
10907 | ||
10908 | static int | |
10909 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10910 | { | |
3a5c3e22 PA |
10911 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10912 | ||
10913 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10914 | } |
10915 | ||
10916 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10917 | masked hardware watchpoints. */ | |
10918 | ||
10919 | static int | |
10920 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10921 | { | |
10922 | return 0; | |
10923 | } | |
10924 | ||
10925 | /* Implement the "print_it" breakpoint_ops method for | |
10926 | masked hardware watchpoints. */ | |
10927 | ||
10928 | static enum print_stop_action | |
10929 | print_it_masked_watchpoint (bpstat bs) | |
10930 | { | |
10931 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10932 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10933 | |
10934 | /* Masked watchpoints have only one location. */ | |
10935 | gdb_assert (b->loc && b->loc->next == NULL); | |
10936 | ||
f303dbd6 PA |
10937 | annotate_watchpoint (b->number); |
10938 | maybe_print_thread_hit_breakpoint (uiout); | |
10939 | ||
348d480f PA |
10940 | switch (b->type) |
10941 | { | |
10942 | case bp_hardware_watchpoint: | |
112e8700 SM |
10943 | if (uiout->is_mi_like_p ()) |
10944 | uiout->field_string | |
10945 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10946 | break; |
10947 | ||
10948 | case bp_read_watchpoint: | |
112e8700 SM |
10949 | if (uiout->is_mi_like_p ()) |
10950 | uiout->field_string | |
10951 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10952 | break; |
10953 | ||
10954 | case bp_access_watchpoint: | |
112e8700 SM |
10955 | if (uiout->is_mi_like_p ()) |
10956 | uiout->field_string | |
10957 | ("reason", | |
348d480f PA |
10958 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10959 | break; | |
10960 | default: | |
10961 | internal_error (__FILE__, __LINE__, | |
10962 | _("Invalid hardware watchpoint type.")); | |
10963 | } | |
10964 | ||
10965 | mention (b); | |
112e8700 | 10966 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10967 | Check the underlying instruction at PC for the memory\n\ |
10968 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10969 | uiout->text ("\n"); |
9c06b0b4 TJB |
10970 | |
10971 | /* More than one watchpoint may have been triggered. */ | |
10972 | return PRINT_UNKNOWN; | |
10973 | } | |
10974 | ||
10975 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10976 | masked hardware watchpoints. */ | |
10977 | ||
10978 | static void | |
10979 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10980 | struct ui_out *uiout) | |
10981 | { | |
3a5c3e22 PA |
10982 | struct watchpoint *w = (struct watchpoint *) b; |
10983 | ||
9c06b0b4 TJB |
10984 | /* Masked watchpoints have only one location. */ |
10985 | gdb_assert (b->loc && b->loc->next == NULL); | |
10986 | ||
112e8700 SM |
10987 | uiout->text ("\tmask "); |
10988 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10989 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10990 | } |
10991 | ||
10992 | /* Implement the "print_mention" breakpoint_ops method for | |
10993 | masked hardware watchpoints. */ | |
10994 | ||
10995 | static void | |
10996 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10997 | { | |
3a5c3e22 | 10998 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10999 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11000 | struct cleanup *ui_out_chain; |
11001 | ||
11002 | switch (b->type) | |
11003 | { | |
11004 | case bp_hardware_watchpoint: | |
112e8700 | 11005 | uiout->text ("Masked hardware watchpoint "); |
9c06b0b4 TJB |
11006 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
11007 | break; | |
11008 | case bp_read_watchpoint: | |
112e8700 | 11009 | uiout->text ("Masked hardware read watchpoint "); |
9c06b0b4 TJB |
11010 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
11011 | break; | |
11012 | case bp_access_watchpoint: | |
112e8700 | 11013 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
9c06b0b4 TJB |
11014 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
11015 | break; | |
11016 | default: | |
11017 | internal_error (__FILE__, __LINE__, | |
11018 | _("Invalid hardware watchpoint type.")); | |
11019 | } | |
11020 | ||
112e8700 SM |
11021 | uiout->field_int ("number", b->number); |
11022 | uiout->text (": "); | |
11023 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
11024 | do_cleanups (ui_out_chain); |
11025 | } | |
11026 | ||
11027 | /* Implement the "print_recreate" breakpoint_ops method for | |
11028 | masked hardware watchpoints. */ | |
11029 | ||
11030 | static void | |
11031 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11032 | { | |
3a5c3e22 | 11033 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11034 | char tmp[40]; |
11035 | ||
11036 | switch (b->type) | |
11037 | { | |
11038 | case bp_hardware_watchpoint: | |
11039 | fprintf_unfiltered (fp, "watch"); | |
11040 | break; | |
11041 | case bp_read_watchpoint: | |
11042 | fprintf_unfiltered (fp, "rwatch"); | |
11043 | break; | |
11044 | case bp_access_watchpoint: | |
11045 | fprintf_unfiltered (fp, "awatch"); | |
11046 | break; | |
11047 | default: | |
11048 | internal_error (__FILE__, __LINE__, | |
11049 | _("Invalid hardware watchpoint type.")); | |
11050 | } | |
11051 | ||
3a5c3e22 PA |
11052 | sprintf_vma (tmp, w->hw_wp_mask); |
11053 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11054 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11055 | } |
11056 | ||
11057 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11058 | ||
2060206e | 11059 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11060 | |
11061 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11062 | ||
11063 | static int | |
11064 | is_masked_watchpoint (const struct breakpoint *b) | |
11065 | { | |
11066 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11067 | } | |
11068 | ||
53a5351d JM |
11069 | /* accessflag: hw_write: watch write, |
11070 | hw_read: watch read, | |
11071 | hw_access: watch access (read or write) */ | |
c906108c | 11072 | static void |
bbc13ae3 | 11073 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11074 | int just_location, int internal) |
c906108c | 11075 | { |
d983da9c | 11076 | struct breakpoint *b, *scope_breakpoint = NULL; |
270140bd | 11077 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11078 | struct value *val, *mark, *result; |
bb9d5f81 | 11079 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11080 | struct frame_info *frame; |
bbc13ae3 KS |
11081 | const char *exp_start = NULL; |
11082 | const char *exp_end = NULL; | |
11083 | const char *tok, *end_tok; | |
9c06b0b4 | 11084 | int toklen = -1; |
bbc13ae3 KS |
11085 | const char *cond_start = NULL; |
11086 | const char *cond_end = NULL; | |
c906108c | 11087 | enum bptype bp_type; |
37e4754d | 11088 | int thread = -1; |
0cf6dd15 | 11089 | int pc = 0; |
9c06b0b4 TJB |
11090 | /* Flag to indicate whether we are going to use masks for |
11091 | the hardware watchpoint. */ | |
11092 | int use_mask = 0; | |
11093 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11094 | struct watchpoint *w; |
bbc13ae3 KS |
11095 | char *expression; |
11096 | struct cleanup *back_to; | |
c906108c | 11097 | |
37e4754d LM |
11098 | /* Make sure that we actually have parameters to parse. */ |
11099 | if (arg != NULL && arg[0] != '\0') | |
11100 | { | |
bbc13ae3 KS |
11101 | const char *value_start; |
11102 | ||
11103 | exp_end = arg + strlen (arg); | |
37e4754d | 11104 | |
9c06b0b4 TJB |
11105 | /* Look for "parameter value" pairs at the end |
11106 | of the arguments string. */ | |
bbc13ae3 | 11107 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11108 | { |
11109 | /* Skip whitespace at the end of the argument list. */ | |
11110 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11111 | tok--; | |
11112 | ||
11113 | /* Find the beginning of the last token. | |
11114 | This is the value of the parameter. */ | |
11115 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11116 | tok--; | |
11117 | value_start = tok + 1; | |
11118 | ||
11119 | /* Skip whitespace. */ | |
11120 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11121 | tok--; | |
11122 | ||
11123 | end_tok = tok; | |
11124 | ||
11125 | /* Find the beginning of the second to last token. | |
11126 | This is the parameter itself. */ | |
11127 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11128 | tok--; | |
11129 | tok++; | |
11130 | toklen = end_tok - tok + 1; | |
11131 | ||
61012eef | 11132 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11133 | { |
5d5658a1 | 11134 | struct thread_info *thr; |
9c06b0b4 TJB |
11135 | /* At this point we've found a "thread" token, which means |
11136 | the user is trying to set a watchpoint that triggers | |
11137 | only in a specific thread. */ | |
5d5658a1 | 11138 | const char *endp; |
37e4754d | 11139 | |
9c06b0b4 TJB |
11140 | if (thread != -1) |
11141 | error(_("You can specify only one thread.")); | |
37e4754d | 11142 | |
9c06b0b4 | 11143 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11144 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11145 | |
5d5658a1 | 11146 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11147 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11148 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11149 | |
5d5658a1 | 11150 | thread = thr->global_num; |
9c06b0b4 | 11151 | } |
61012eef | 11152 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11153 | { |
11154 | /* We've found a "mask" token, which means the user wants to | |
11155 | create a hardware watchpoint that is going to have the mask | |
11156 | facility. */ | |
11157 | struct value *mask_value, *mark; | |
37e4754d | 11158 | |
9c06b0b4 TJB |
11159 | if (use_mask) |
11160 | error(_("You can specify only one mask.")); | |
37e4754d | 11161 | |
9c06b0b4 | 11162 | use_mask = just_location = 1; |
37e4754d | 11163 | |
9c06b0b4 TJB |
11164 | mark = value_mark (); |
11165 | mask_value = parse_to_comma_and_eval (&value_start); | |
11166 | mask = value_as_address (mask_value); | |
11167 | value_free_to_mark (mark); | |
11168 | } | |
11169 | else | |
11170 | /* We didn't recognize what we found. We should stop here. */ | |
11171 | break; | |
37e4754d | 11172 | |
9c06b0b4 TJB |
11173 | /* Truncate the string and get rid of the "parameter value" pair before |
11174 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11175 | exp_end = tok; |
9c06b0b4 | 11176 | } |
37e4754d | 11177 | } |
bbc13ae3 KS |
11178 | else |
11179 | exp_end = arg; | |
37e4754d | 11180 | |
bbc13ae3 KS |
11181 | /* Parse the rest of the arguments. From here on out, everything |
11182 | is in terms of a newly allocated string instead of the original | |
11183 | ARG. */ | |
c906108c | 11184 | innermost_block = NULL; |
bbc13ae3 KS |
11185 | expression = savestring (arg, exp_end - arg); |
11186 | back_to = make_cleanup (xfree, expression); | |
11187 | exp_start = arg = expression; | |
4d01a485 | 11188 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11189 | exp_end = arg; |
fa8a61dc TT |
11190 | /* Remove trailing whitespace from the expression before saving it. |
11191 | This makes the eventual display of the expression string a bit | |
11192 | prettier. */ | |
11193 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11194 | --exp_end; | |
11195 | ||
65d79d4b | 11196 | /* Checking if the expression is not constant. */ |
4d01a485 | 11197 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11198 | { |
11199 | int len; | |
11200 | ||
11201 | len = exp_end - exp_start; | |
11202 | while (len > 0 && isspace (exp_start[len - 1])) | |
11203 | len--; | |
11204 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11205 | } | |
11206 | ||
c906108c SS |
11207 | exp_valid_block = innermost_block; |
11208 | mark = value_mark (); | |
4d01a485 | 11209 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11210 | |
bb9d5f81 PP |
11211 | if (val != NULL && just_location) |
11212 | { | |
11213 | saved_bitpos = value_bitpos (val); | |
11214 | saved_bitsize = value_bitsize (val); | |
11215 | } | |
11216 | ||
06a64a0b TT |
11217 | if (just_location) |
11218 | { | |
9c06b0b4 TJB |
11219 | int ret; |
11220 | ||
06a64a0b | 11221 | exp_valid_block = NULL; |
a1442452 | 11222 | val = value_addr (result); |
06a64a0b TT |
11223 | release_value (val); |
11224 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11225 | |
11226 | if (use_mask) | |
11227 | { | |
11228 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11229 | mask); | |
11230 | if (ret == -1) | |
11231 | error (_("This target does not support masked watchpoints.")); | |
11232 | else if (ret == -2) | |
11233 | error (_("Invalid mask or memory region.")); | |
11234 | } | |
06a64a0b TT |
11235 | } |
11236 | else if (val != NULL) | |
fa4727a6 | 11237 | release_value (val); |
c906108c | 11238 | |
bbc13ae3 KS |
11239 | tok = skip_spaces_const (arg); |
11240 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11241 | |
11242 | toklen = end_tok - tok; | |
11243 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11244 | { | |
60e1c644 | 11245 | innermost_block = NULL; |
c906108c | 11246 | tok = cond_start = end_tok + 1; |
4d01a485 | 11247 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11248 | |
11249 | /* The watchpoint expression may not be local, but the condition | |
11250 | may still be. E.g.: `watch global if local > 0'. */ | |
11251 | cond_exp_valid_block = innermost_block; | |
11252 | ||
c906108c SS |
11253 | cond_end = tok; |
11254 | } | |
11255 | if (*tok) | |
8a3fe4f8 | 11256 | error (_("Junk at end of command.")); |
c906108c | 11257 | |
d983da9c | 11258 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11259 | |
11260 | /* If the expression is "local", then set up a "watchpoint scope" | |
11261 | breakpoint at the point where we've left the scope of the watchpoint | |
11262 | expression. Create the scope breakpoint before the watchpoint, so | |
11263 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11264 | if (exp_valid_block && frame) |
d983da9c | 11265 | { |
edb3359d DJ |
11266 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11267 | { | |
11268 | scope_breakpoint | |
a6d9a66e UW |
11269 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11270 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11271 | bp_watchpoint_scope, |
11272 | &momentary_breakpoint_ops); | |
d983da9c | 11273 | |
edb3359d | 11274 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11275 | |
edb3359d DJ |
11276 | /* Automatically delete the breakpoint when it hits. */ |
11277 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11278 | |
edb3359d DJ |
11279 | /* Only break in the proper frame (help with recursion). */ |
11280 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11281 | |
edb3359d | 11282 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11283 | scope_breakpoint->loc->gdbarch |
11284 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11285 | scope_breakpoint->loc->requested_address |
11286 | = frame_unwind_caller_pc (frame); | |
11287 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11288 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11289 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11290 | scope_breakpoint->type); |
11291 | } | |
d983da9c DJ |
11292 | } |
11293 | ||
e8369a73 AB |
11294 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11295 | watchpoints here even if hardware watchpoints are turned off, a call | |
11296 | to update_watchpoint later in this function will cause the type to | |
11297 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11298 | ||
11299 | if (accessflag == hw_read) | |
11300 | bp_type = bp_read_watchpoint; | |
11301 | else if (accessflag == hw_access) | |
11302 | bp_type = bp_access_watchpoint; | |
11303 | else | |
11304 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11305 | |
4d01a485 | 11306 | w = new watchpoint (); |
3a5c3e22 | 11307 | b = &w->base; |
348d480f | 11308 | if (use_mask) |
3a5c3e22 PA |
11309 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11310 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11311 | else |
3a5c3e22 PA |
11312 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11313 | &watchpoint_breakpoint_ops); | |
37e4754d | 11314 | b->thread = thread; |
b5de0fa7 | 11315 | b->disposition = disp_donttouch; |
348d480f | 11316 | b->pspace = current_program_space; |
b22e99fd | 11317 | w->exp = std::move (exp); |
3a5c3e22 PA |
11318 | w->exp_valid_block = exp_valid_block; |
11319 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11320 | if (just_location) |
11321 | { | |
11322 | struct type *t = value_type (val); | |
11323 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b TT |
11324 | |
11325 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
06a64a0b | 11326 | |
2f408ecb PA |
11327 | std::string name = type_to_string (t); |
11328 | ||
11329 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name.c_str (), | |
d63d0675 | 11330 | core_addr_to_string (addr)); |
06a64a0b | 11331 | |
3a5c3e22 | 11332 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11333 | (int) (exp_end - exp_start), exp_start); |
11334 | ||
06a64a0b TT |
11335 | /* The above expression is in C. */ |
11336 | b->language = language_c; | |
11337 | } | |
11338 | else | |
3a5c3e22 | 11339 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11340 | |
11341 | if (use_mask) | |
11342 | { | |
3a5c3e22 | 11343 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11344 | } |
11345 | else | |
11346 | { | |
3a5c3e22 | 11347 | w->val = val; |
bb9d5f81 PP |
11348 | w->val_bitpos = saved_bitpos; |
11349 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11350 | w->val_valid = 1; |
9c06b0b4 | 11351 | } |
77b06cd7 | 11352 | |
c906108c SS |
11353 | if (cond_start) |
11354 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11355 | else | |
11356 | b->cond_string = 0; | |
c5aa993b | 11357 | |
c906108c | 11358 | if (frame) |
f6bc2008 | 11359 | { |
3a5c3e22 PA |
11360 | w->watchpoint_frame = get_frame_id (frame); |
11361 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11362 | } |
c906108c | 11363 | else |
f6bc2008 | 11364 | { |
3a5c3e22 PA |
11365 | w->watchpoint_frame = null_frame_id; |
11366 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11367 | } |
c906108c | 11368 | |
d983da9c | 11369 | if (scope_breakpoint != NULL) |
c906108c | 11370 | { |
d983da9c DJ |
11371 | /* The scope breakpoint is related to the watchpoint. We will |
11372 | need to act on them together. */ | |
11373 | b->related_breakpoint = scope_breakpoint; | |
11374 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11375 | } |
d983da9c | 11376 | |
06a64a0b TT |
11377 | if (!just_location) |
11378 | value_free_to_mark (mark); | |
2d134ed3 | 11379 | |
492d29ea | 11380 | TRY |
a9634178 TJB |
11381 | { |
11382 | /* Finally update the new watchpoint. This creates the locations | |
11383 | that should be inserted. */ | |
3a5c3e22 | 11384 | update_watchpoint (w, 1); |
a9634178 | 11385 | } |
492d29ea | 11386 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11387 | { |
11388 | delete_breakpoint (b); | |
11389 | throw_exception (e); | |
11390 | } | |
492d29ea | 11391 | END_CATCH |
a9634178 | 11392 | |
3ea46bff | 11393 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11394 | do_cleanups (back_to); |
c906108c SS |
11395 | } |
11396 | ||
e09342b5 | 11397 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11398 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11399 | |
c906108c | 11400 | static int |
a9634178 | 11401 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11402 | { |
11403 | int found_memory_cnt = 0; | |
2e70b7b9 | 11404 | struct value *head = v; |
c906108c SS |
11405 | |
11406 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11407 | if (!can_use_hw_watchpoints) |
c906108c | 11408 | return 0; |
c5aa993b | 11409 | |
5c44784c JM |
11410 | /* Make sure that the value of the expression depends only upon |
11411 | memory contents, and values computed from them within GDB. If we | |
11412 | find any register references or function calls, we can't use a | |
11413 | hardware watchpoint. | |
11414 | ||
11415 | The idea here is that evaluating an expression generates a series | |
11416 | of values, one holding the value of every subexpression. (The | |
11417 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11418 | a*b+c.) GDB's values hold almost enough information to establish | |
11419 | the criteria given above --- they identify memory lvalues, | |
11420 | register lvalues, computed values, etcetera. So we can evaluate | |
11421 | the expression, and then scan the chain of values that leaves | |
11422 | behind to decide whether we can detect any possible change to the | |
11423 | expression's final value using only hardware watchpoints. | |
11424 | ||
11425 | However, I don't think that the values returned by inferior | |
11426 | function calls are special in any way. So this function may not | |
11427 | notice that an expression involving an inferior function call | |
11428 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11429 | for (; v; v = value_next (v)) |
c906108c | 11430 | { |
5c44784c | 11431 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11432 | { |
8464be76 DJ |
11433 | if (v != head && value_lazy (v)) |
11434 | /* A lazy memory lvalue in the chain is one that GDB never | |
11435 | needed to fetch; we either just used its address (e.g., | |
11436 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11437 | in `a,b'). This doesn't apply to HEAD; if that is | |
11438 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11439 | ; |
53a5351d | 11440 | else |
5c44784c JM |
11441 | { |
11442 | /* Ahh, memory we actually used! Check if we can cover | |
11443 | it with hardware watchpoints. */ | |
df407dfe | 11444 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11445 | |
11446 | /* We only watch structs and arrays if user asked for it | |
11447 | explicitly, never if they just happen to appear in a | |
11448 | middle of some value chain. */ | |
11449 | if (v == head | |
11450 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11451 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11452 | { | |
42ae5230 | 11453 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11454 | int len; |
11455 | int num_regs; | |
11456 | ||
a9634178 | 11457 | len = (target_exact_watchpoints |
e09342b5 TJB |
11458 | && is_scalar_type_recursive (vtype))? |
11459 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11460 | |
e09342b5 TJB |
11461 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11462 | if (!num_regs) | |
2e70b7b9 MS |
11463 | return 0; |
11464 | else | |
e09342b5 | 11465 | found_memory_cnt += num_regs; |
2e70b7b9 | 11466 | } |
5c44784c | 11467 | } |
c5aa993b | 11468 | } |
5086187c AC |
11469 | else if (VALUE_LVAL (v) != not_lval |
11470 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11471 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11472 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11473 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11474 | } |
11475 | ||
11476 | /* The expression itself looks suitable for using a hardware | |
11477 | watchpoint, but give the target machine a chance to reject it. */ | |
11478 | return found_memory_cnt; | |
11479 | } | |
11480 | ||
8b93c638 | 11481 | void |
84f4c1fe | 11482 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11483 | { |
84f4c1fe | 11484 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11485 | } |
11486 | ||
06a64a0b TT |
11487 | /* A helper function that looks for the "-location" argument and then |
11488 | calls watch_command_1. */ | |
11489 | ||
11490 | static void | |
11491 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11492 | { | |
11493 | int just_location = 0; | |
11494 | ||
11495 | if (arg | |
11496 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11497 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11498 | { | |
e9cafbcc | 11499 | arg = skip_spaces (arg); |
06a64a0b TT |
11500 | just_location = 1; |
11501 | } | |
11502 | ||
84f4c1fe | 11503 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11504 | } |
8926118c | 11505 | |
c5aa993b | 11506 | static void |
fba45db2 | 11507 | watch_command (char *arg, int from_tty) |
c906108c | 11508 | { |
06a64a0b | 11509 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11510 | } |
11511 | ||
8b93c638 | 11512 | void |
84f4c1fe | 11513 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11514 | { |
84f4c1fe | 11515 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11516 | } |
8926118c | 11517 | |
c5aa993b | 11518 | static void |
fba45db2 | 11519 | rwatch_command (char *arg, int from_tty) |
c906108c | 11520 | { |
06a64a0b | 11521 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11522 | } |
11523 | ||
8b93c638 | 11524 | void |
84f4c1fe | 11525 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11526 | { |
84f4c1fe | 11527 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11528 | } |
8926118c | 11529 | |
c5aa993b | 11530 | static void |
fba45db2 | 11531 | awatch_command (char *arg, int from_tty) |
c906108c | 11532 | { |
06a64a0b | 11533 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11534 | } |
c906108c | 11535 | \f |
c5aa993b | 11536 | |
cfc31633 PA |
11537 | /* Data for the FSM that manages the until(location)/advance commands |
11538 | in infcmd.c. Here because it uses the mechanisms of | |
11539 | breakpoints. */ | |
c906108c | 11540 | |
cfc31633 | 11541 | struct until_break_fsm |
bfec99b2 | 11542 | { |
cfc31633 PA |
11543 | /* The base class. */ |
11544 | struct thread_fsm thread_fsm; | |
11545 | ||
11546 | /* The thread that as current when the command was executed. */ | |
11547 | int thread; | |
11548 | ||
11549 | /* The breakpoint set at the destination location. */ | |
11550 | struct breakpoint *location_breakpoint; | |
11551 | ||
11552 | /* Breakpoint set at the return address in the caller frame. May be | |
11553 | NULL. */ | |
11554 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11555 | }; |
11556 | ||
8980e177 PA |
11557 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11558 | struct thread_info *thread); | |
11559 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11560 | struct thread_info *thread); | |
cfc31633 PA |
11561 | static enum async_reply_reason |
11562 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11563 | ||
11564 | /* until_break_fsm's vtable. */ | |
11565 | ||
11566 | static struct thread_fsm_ops until_break_fsm_ops = | |
11567 | { | |
11568 | NULL, /* dtor */ | |
11569 | until_break_fsm_clean_up, | |
11570 | until_break_fsm_should_stop, | |
11571 | NULL, /* return_value */ | |
11572 | until_break_fsm_async_reply_reason, | |
11573 | }; | |
11574 | ||
11575 | /* Allocate a new until_break_command_fsm. */ | |
11576 | ||
11577 | static struct until_break_fsm * | |
8980e177 | 11578 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11579 | struct breakpoint *location_breakpoint, |
11580 | struct breakpoint *caller_breakpoint) | |
11581 | { | |
11582 | struct until_break_fsm *sm; | |
11583 | ||
11584 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11585 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11586 | |
11587 | sm->thread = thread; | |
11588 | sm->location_breakpoint = location_breakpoint; | |
11589 | sm->caller_breakpoint = caller_breakpoint; | |
11590 | ||
11591 | return sm; | |
11592 | } | |
11593 | ||
11594 | /* Implementation of the 'should_stop' FSM method for the | |
11595 | until(location)/advance commands. */ | |
11596 | ||
11597 | static int | |
8980e177 PA |
11598 | until_break_fsm_should_stop (struct thread_fsm *self, |
11599 | struct thread_info *tp) | |
cfc31633 PA |
11600 | { |
11601 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11602 | |
11603 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11604 | sm->location_breakpoint) != NULL | |
11605 | || (sm->caller_breakpoint != NULL | |
11606 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11607 | sm->caller_breakpoint) != NULL)) | |
11608 | thread_fsm_set_finished (self); | |
11609 | ||
11610 | return 1; | |
11611 | } | |
11612 | ||
11613 | /* Implementation of the 'clean_up' FSM method for the | |
11614 | until(location)/advance commands. */ | |
11615 | ||
c2c6d25f | 11616 | static void |
8980e177 PA |
11617 | until_break_fsm_clean_up (struct thread_fsm *self, |
11618 | struct thread_info *thread) | |
43ff13b4 | 11619 | { |
cfc31633 | 11620 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11621 | |
cfc31633 PA |
11622 | /* Clean up our temporary breakpoints. */ |
11623 | if (sm->location_breakpoint != NULL) | |
11624 | { | |
11625 | delete_breakpoint (sm->location_breakpoint); | |
11626 | sm->location_breakpoint = NULL; | |
11627 | } | |
11628 | if (sm->caller_breakpoint != NULL) | |
11629 | { | |
11630 | delete_breakpoint (sm->caller_breakpoint); | |
11631 | sm->caller_breakpoint = NULL; | |
11632 | } | |
11633 | delete_longjmp_breakpoint (sm->thread); | |
11634 | } | |
11635 | ||
11636 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11637 | until(location)/advance commands. */ | |
11638 | ||
11639 | static enum async_reply_reason | |
11640 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11641 | { | |
11642 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11643 | } |
11644 | ||
c906108c | 11645 | void |
ae66c1fc | 11646 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11647 | { |
11648 | struct symtabs_and_lines sals; | |
11649 | struct symtab_and_line sal; | |
8556afb4 PA |
11650 | struct frame_info *frame; |
11651 | struct gdbarch *frame_gdbarch; | |
11652 | struct frame_id stack_frame_id; | |
11653 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11654 | struct breakpoint *location_breakpoint; |
11655 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11656 | struct cleanup *old_chain; |
186c406b TT |
11657 | int thread; |
11658 | struct thread_info *tp; | |
cfc31633 | 11659 | struct until_break_fsm *sm; |
c906108c | 11660 | |
70509625 | 11661 | clear_proceed_status (0); |
c906108c SS |
11662 | |
11663 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11664 | this function. */ |
c5aa993b | 11665 | |
ffc2605c | 11666 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11667 | |
1bfeeb0f | 11668 | if (last_displayed_sal_is_valid ()) |
ffc2605c | 11669 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11670 | get_last_displayed_symtab (), |
f8eba3c6 | 11671 | get_last_displayed_line ()); |
c906108c | 11672 | else |
ffc2605c | 11673 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11674 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11675 | |
c906108c | 11676 | if (sals.nelts != 1) |
8a3fe4f8 | 11677 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11678 | |
c906108c | 11679 | sal = sals.sals[0]; |
4a64f543 | 11680 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11681 | |
c906108c | 11682 | if (*arg) |
8a3fe4f8 | 11683 | error (_("Junk at end of arguments.")); |
c5aa993b | 11684 | |
c906108c | 11685 | resolve_sal_pc (&sal); |
c5aa993b | 11686 | |
186c406b | 11687 | tp = inferior_thread (); |
5d5658a1 | 11688 | thread = tp->global_num; |
186c406b | 11689 | |
883bc8d1 PA |
11690 | old_chain = make_cleanup (null_cleanup, NULL); |
11691 | ||
8556afb4 PA |
11692 | /* Note linespec handling above invalidates the frame chain. |
11693 | Installing a breakpoint also invalidates the frame chain (as it | |
11694 | may need to switch threads), so do any frame handling before | |
11695 | that. */ | |
11696 | ||
11697 | frame = get_selected_frame (NULL); | |
11698 | frame_gdbarch = get_frame_arch (frame); | |
11699 | stack_frame_id = get_stack_frame_id (frame); | |
11700 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11701 | |
ae66c1fc EZ |
11702 | /* Keep within the current frame, or in frames called by the current |
11703 | one. */ | |
edb3359d | 11704 | |
883bc8d1 | 11705 | if (frame_id_p (caller_frame_id)) |
c906108c | 11706 | { |
883bc8d1 | 11707 | struct symtab_and_line sal2; |
cfc31633 | 11708 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11709 | |
11710 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11711 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11712 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11713 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11714 | sal2, | |
11715 | caller_frame_id, | |
11716 | bp_until); | |
11717 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11718 | |
883bc8d1 | 11719 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11720 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11721 | } |
c5aa993b | 11722 | |
c70a6932 JK |
11723 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11724 | frame = NULL; | |
11725 | ||
883bc8d1 PA |
11726 | if (anywhere) |
11727 | /* If the user told us to continue until a specified location, | |
11728 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11729 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11730 | null_frame_id, bp_until); | |
883bc8d1 PA |
11731 | else |
11732 | /* Otherwise, specify the selected frame, because we want to stop | |
11733 | only at the very same frame. */ | |
cfc31633 PA |
11734 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11735 | stack_frame_id, bp_until); | |
11736 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11737 | |
8980e177 | 11738 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11739 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11740 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11741 | |
cfc31633 | 11742 | discard_cleanups (old_chain); |
f107f563 | 11743 | |
cfc31633 | 11744 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11745 | } |
ae66c1fc | 11746 | |
c906108c SS |
11747 | /* This function attempts to parse an optional "if <cond>" clause |
11748 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11749 | |
c906108c SS |
11750 | Else, it returns a pointer to the condition string. (It does not |
11751 | attempt to evaluate the string against a particular block.) And, | |
11752 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11753 | if clause in the arg string. */ |
53a5351d | 11754 | |
63160a43 PA |
11755 | const char * |
11756 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11757 | { |
63160a43 | 11758 | const char *cond_string; |
c5aa993b JM |
11759 | |
11760 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11761 | return NULL; |
c5aa993b | 11762 | |
4a64f543 | 11763 | /* Skip the "if" keyword. */ |
c906108c | 11764 | (*arg) += 2; |
c5aa993b | 11765 | |
c906108c | 11766 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11767 | condition string. */ |
63160a43 | 11768 | *arg = skip_spaces_const (*arg); |
c906108c | 11769 | cond_string = *arg; |
c5aa993b | 11770 | |
4a64f543 MS |
11771 | /* Assume that the condition occupies the remainder of the arg |
11772 | string. */ | |
c906108c | 11773 | (*arg) += strlen (cond_string); |
c5aa993b | 11774 | |
c906108c SS |
11775 | return cond_string; |
11776 | } | |
c5aa993b | 11777 | |
c906108c SS |
11778 | /* Commands to deal with catching events, such as signals, exceptions, |
11779 | process start/exit, etc. */ | |
c5aa993b JM |
11780 | |
11781 | typedef enum | |
11782 | { | |
44feb3ce TT |
11783 | catch_fork_temporary, catch_vfork_temporary, |
11784 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11785 | } |
11786 | catch_fork_kind; | |
11787 | ||
c906108c | 11788 | static void |
63160a43 | 11789 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11790 | struct cmd_list_element *command) |
c906108c | 11791 | { |
63160a43 | 11792 | const char *arg = arg_entry; |
a6d9a66e | 11793 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11794 | const char *cond_string = NULL; |
44feb3ce TT |
11795 | catch_fork_kind fork_kind; |
11796 | int tempflag; | |
11797 | ||
11798 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11799 | tempflag = (fork_kind == catch_fork_temporary | |
11800 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11801 | |
44feb3ce TT |
11802 | if (!arg) |
11803 | arg = ""; | |
63160a43 | 11804 | arg = skip_spaces_const (arg); |
c5aa993b | 11805 | |
c906108c | 11806 | /* The allowed syntax is: |
c5aa993b JM |
11807 | catch [v]fork |
11808 | catch [v]fork if <cond> | |
11809 | ||
4a64f543 | 11810 | First, check if there's an if clause. */ |
c906108c | 11811 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11812 | |
c906108c | 11813 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11814 | error (_("Junk at end of arguments.")); |
c5aa993b | 11815 | |
c906108c | 11816 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11817 | and enable reporting of such events. */ |
c5aa993b JM |
11818 | switch (fork_kind) |
11819 | { | |
44feb3ce TT |
11820 | case catch_fork_temporary: |
11821 | case catch_fork_permanent: | |
a6d9a66e | 11822 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11823 | &catch_fork_breakpoint_ops); |
c906108c | 11824 | break; |
44feb3ce TT |
11825 | case catch_vfork_temporary: |
11826 | case catch_vfork_permanent: | |
a6d9a66e | 11827 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11828 | &catch_vfork_breakpoint_ops); |
c906108c | 11829 | break; |
c5aa993b | 11830 | default: |
8a3fe4f8 | 11831 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11832 | break; |
c5aa993b | 11833 | } |
c906108c SS |
11834 | } |
11835 | ||
11836 | static void | |
63160a43 | 11837 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11838 | struct cmd_list_element *command) |
c906108c | 11839 | { |
63160a43 | 11840 | const char *arg = arg_entry; |
b4d90040 | 11841 | struct exec_catchpoint *c; |
a6d9a66e | 11842 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11843 | int tempflag; |
63160a43 | 11844 | const char *cond_string = NULL; |
c906108c | 11845 | |
44feb3ce TT |
11846 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11847 | ||
11848 | if (!arg) | |
11849 | arg = ""; | |
63160a43 | 11850 | arg = skip_spaces_const (arg); |
c906108c SS |
11851 | |
11852 | /* The allowed syntax is: | |
c5aa993b JM |
11853 | catch exec |
11854 | catch exec if <cond> | |
c906108c | 11855 | |
4a64f543 | 11856 | First, check if there's an if clause. */ |
c906108c SS |
11857 | cond_string = ep_parse_optional_if_clause (&arg); |
11858 | ||
11859 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11860 | error (_("Junk at end of arguments.")); |
c906108c | 11861 | |
4d01a485 | 11862 | c = new exec_catchpoint (); |
b4d90040 PA |
11863 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, |
11864 | &catch_exec_breakpoint_ops); | |
11865 | c->exec_pathname = NULL; | |
11866 | ||
3ea46bff | 11867 | install_breakpoint (0, &c->base, 1); |
c906108c | 11868 | } |
c5aa993b | 11869 | |
9ac4176b | 11870 | void |
28010a5d PA |
11871 | init_ada_exception_breakpoint (struct breakpoint *b, |
11872 | struct gdbarch *gdbarch, | |
11873 | struct symtab_and_line sal, | |
11874 | char *addr_string, | |
c0a91b2b | 11875 | const struct breakpoint_ops *ops, |
28010a5d | 11876 | int tempflag, |
349774ef | 11877 | int enabled, |
28010a5d | 11878 | int from_tty) |
f7f9143b | 11879 | { |
f7f9143b JB |
11880 | if (from_tty) |
11881 | { | |
5af949e3 UW |
11882 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11883 | if (!loc_gdbarch) | |
11884 | loc_gdbarch = gdbarch; | |
11885 | ||
6c95b8df PA |
11886 | describe_other_breakpoints (loc_gdbarch, |
11887 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11888 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11889 | version for exception catchpoints, because two catchpoints | |
11890 | used for different exception names will use the same address. | |
11891 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11892 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11893 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11894 | the user what type of catchpoint it is. The above is good |
11895 | enough for now, though. */ | |
11896 | } | |
11897 | ||
28010a5d | 11898 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11899 | |
349774ef | 11900 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11901 | b->disposition = tempflag ? disp_del : disp_donttouch; |
ffc2605c TT |
11902 | b->location |
11903 | = string_to_event_location (&addr_string, | |
11904 | language_def (language_ada)).release (); | |
f7f9143b | 11905 | b->language = language_ada; |
f7f9143b JB |
11906 | } |
11907 | ||
c906108c | 11908 | static void |
fba45db2 | 11909 | catch_command (char *arg, int from_tty) |
c906108c | 11910 | { |
44feb3ce | 11911 | error (_("Catch requires an event name.")); |
c906108c SS |
11912 | } |
11913 | \f | |
11914 | ||
11915 | static void | |
fba45db2 | 11916 | tcatch_command (char *arg, int from_tty) |
c906108c | 11917 | { |
44feb3ce | 11918 | error (_("Catch requires an event name.")); |
c906108c SS |
11919 | } |
11920 | ||
8a2c437b TT |
11921 | /* A qsort comparison function that sorts breakpoints in order. */ |
11922 | ||
11923 | static int | |
11924 | compare_breakpoints (const void *a, const void *b) | |
11925 | { | |
9a3c8263 | 11926 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11927 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11928 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11929 | uintptr_t ub = (uintptr_t) *bb; |
11930 | ||
11931 | if ((*ba)->number < (*bb)->number) | |
11932 | return -1; | |
11933 | else if ((*ba)->number > (*bb)->number) | |
11934 | return 1; | |
11935 | ||
11936 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11937 | the number 0. */ | |
11938 | if (ua < ub) | |
11939 | return -1; | |
94b0e70d | 11940 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11941 | } |
11942 | ||
80f8a6eb | 11943 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11944 | |
11945 | static void | |
fba45db2 | 11946 | clear_command (char *arg, int from_tty) |
c906108c | 11947 | { |
8a2c437b | 11948 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11949 | VEC(breakpoint_p) *found = 0; |
11950 | int ix; | |
c906108c SS |
11951 | int default_match; |
11952 | struct symtabs_and_lines sals; | |
11953 | struct symtab_and_line sal; | |
c906108c | 11954 | int i; |
8a2c437b | 11955 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11956 | |
11957 | if (arg) | |
11958 | { | |
39cf75f7 DE |
11959 | sals = decode_line_with_current_source (arg, |
11960 | (DECODE_LINE_FUNFIRSTLINE | |
11961 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11962 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11963 | default_match = 0; |
11964 | } | |
11965 | else | |
11966 | { | |
8d749320 | 11967 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 11968 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11969 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11970 | |
11971 | /* Set sal's line, symtab, pc, and pspace to the values | |
11972 | corresponding to the last call to print_frame_info. If the | |
11973 | codepoint is not valid, this will set all the fields to 0. */ | |
11974 | get_last_displayed_sal (&sal); | |
c906108c | 11975 | if (sal.symtab == 0) |
8a3fe4f8 | 11976 | error (_("No source file specified.")); |
c906108c SS |
11977 | |
11978 | sals.sals[0] = sal; | |
11979 | sals.nelts = 1; | |
11980 | ||
11981 | default_match = 1; | |
11982 | } | |
11983 | ||
4a64f543 MS |
11984 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11985 | seems, because all existing breakpoints typically have both | |
11986 | file/line and pc set. So, if clear is given file/line, we can | |
11987 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11988 | |
11989 | We only support clearing given the address explicitly | |
11990 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11991 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11992 | due to optimization, all in one block. |
4a64f543 MS |
11993 | |
11994 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11995 | PC corresponding to the same file:line, the breakpoint won't |
11996 | be cleared. We probably can still clear the breakpoint, but | |
11997 | since the other PC value is never presented to user, user | |
11998 | can only find it by guessing, and it does not seem important | |
11999 | to support that. */ | |
12000 | ||
4a64f543 MS |
12001 | /* For each line spec given, delete bps which correspond to it. Do |
12002 | it in two passes, solely to preserve the current behavior that | |
12003 | from_tty is forced true if we delete more than one | |
12004 | breakpoint. */ | |
c906108c | 12005 | |
80f8a6eb | 12006 | found = NULL; |
8a2c437b | 12007 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12008 | for (i = 0; i < sals.nelts; i++) |
12009 | { | |
05cba821 JK |
12010 | const char *sal_fullname; |
12011 | ||
c906108c | 12012 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12013 | If line given (pc == 0), clear all bpts on specified line. |
12014 | If defaulting, clear all bpts on default line | |
c906108c | 12015 | or at default pc. |
c5aa993b JM |
12016 | |
12017 | defaulting sal.pc != 0 tests to do | |
12018 | ||
12019 | 0 1 pc | |
12020 | 1 1 pc _and_ line | |
12021 | 0 0 line | |
12022 | 1 0 <can't happen> */ | |
c906108c SS |
12023 | |
12024 | sal = sals.sals[i]; | |
05cba821 JK |
12025 | sal_fullname = (sal.symtab == NULL |
12026 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12027 | |
4a64f543 | 12028 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12029 | ALL_BREAKPOINTS (b) |
c5aa993b | 12030 | { |
0d381245 | 12031 | int match = 0; |
4a64f543 | 12032 | /* Are we going to delete b? */ |
cc60f2e3 | 12033 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12034 | { |
12035 | struct bp_location *loc = b->loc; | |
12036 | for (; loc; loc = loc->next) | |
12037 | { | |
f8eba3c6 TT |
12038 | /* If the user specified file:line, don't allow a PC |
12039 | match. This matches historical gdb behavior. */ | |
12040 | int pc_match = (!sal.explicit_line | |
12041 | && sal.pc | |
12042 | && (loc->pspace == sal.pspace) | |
12043 | && (loc->address == sal.pc) | |
12044 | && (!section_is_overlay (loc->section) | |
12045 | || loc->section == sal.section)); | |
4aac40c8 TT |
12046 | int line_match = 0; |
12047 | ||
12048 | if ((default_match || sal.explicit_line) | |
2f202fde | 12049 | && loc->symtab != NULL |
05cba821 | 12050 | && sal_fullname != NULL |
4aac40c8 | 12051 | && sal.pspace == loc->pspace |
05cba821 JK |
12052 | && loc->line_number == sal.line |
12053 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12054 | sal_fullname) == 0) | |
12055 | line_match = 1; | |
4aac40c8 | 12056 | |
0d381245 VP |
12057 | if (pc_match || line_match) |
12058 | { | |
12059 | match = 1; | |
12060 | break; | |
12061 | } | |
12062 | } | |
12063 | } | |
12064 | ||
12065 | if (match) | |
d6e956e5 | 12066 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12067 | } |
80f8a6eb | 12068 | } |
8a2c437b | 12069 | |
80f8a6eb | 12070 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12071 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12072 | { |
12073 | if (arg) | |
8a3fe4f8 | 12074 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12075 | else |
8a3fe4f8 | 12076 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12077 | } |
c906108c | 12078 | |
8a2c437b TT |
12079 | /* Remove duplicates from the vec. */ |
12080 | qsort (VEC_address (breakpoint_p, found), | |
12081 | VEC_length (breakpoint_p, found), | |
12082 | sizeof (breakpoint_p), | |
12083 | compare_breakpoints); | |
12084 | prev = VEC_index (breakpoint_p, found, 0); | |
12085 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12086 | { | |
12087 | if (b == prev) | |
12088 | { | |
12089 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12090 | --ix; | |
12091 | } | |
12092 | } | |
12093 | ||
d6e956e5 | 12094 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12095 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12096 | if (from_tty) |
a3f17187 | 12097 | { |
d6e956e5 | 12098 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12099 | printf_unfiltered (_("Deleted breakpoint ")); |
12100 | else | |
12101 | printf_unfiltered (_("Deleted breakpoints ")); | |
12102 | } | |
d6e956e5 VP |
12103 | |
12104 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12105 | { |
c5aa993b | 12106 | if (from_tty) |
d6e956e5 VP |
12107 | printf_unfiltered ("%d ", b->number); |
12108 | delete_breakpoint (b); | |
c906108c | 12109 | } |
80f8a6eb MS |
12110 | if (from_tty) |
12111 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12112 | |
12113 | do_cleanups (cleanups); | |
c906108c SS |
12114 | } |
12115 | \f | |
12116 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12117 | all breakpoints that are marked for deletion, whether hit or not. | |
12118 | This is called after any breakpoint is hit, or after errors. */ | |
12119 | ||
12120 | void | |
fba45db2 | 12121 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12122 | { |
35df4500 | 12123 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12124 | |
12125 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12126 | if (bs->breakpoint_at |
12127 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12128 | && bs->stop) |
f431efe5 | 12129 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12130 | |
35df4500 | 12131 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12132 | { |
b5de0fa7 | 12133 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12134 | delete_breakpoint (b); |
12135 | } | |
c906108c SS |
12136 | } |
12137 | ||
4a64f543 MS |
12138 | /* A comparison function for bp_location AP and BP being interfaced to |
12139 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12140 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12141 | secondarily by ordering first permanent elements and |
4a64f543 | 12142 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12143 | qsort being an unstable algorithm. */ |
876fa593 JK |
12144 | |
12145 | static int | |
494cfb0f | 12146 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12147 | { |
9a3c8263 SM |
12148 | const struct bp_location *a = *(const struct bp_location **) ap; |
12149 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12150 | |
12151 | if (a->address != b->address) | |
12152 | return (a->address > b->address) - (a->address < b->address); | |
12153 | ||
dea2aa5f LM |
12154 | /* Sort locations at the same address by their pspace number, keeping |
12155 | locations of the same inferior (in a multi-inferior environment) | |
12156 | grouped. */ | |
12157 | ||
12158 | if (a->pspace->num != b->pspace->num) | |
12159 | return ((a->pspace->num > b->pspace->num) | |
12160 | - (a->pspace->num < b->pspace->num)); | |
12161 | ||
876fa593 | 12162 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12163 | if (a->permanent != b->permanent) |
12164 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12165 | |
c56a97f9 JK |
12166 | /* Make the internal GDB representation stable across GDB runs |
12167 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12168 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12169 | |
12170 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12171 | return ((a->owner->number > b->owner->number) |
12172 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12173 | |
12174 | return (a > b) - (a < b); | |
12175 | } | |
12176 | ||
876fa593 | 12177 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12178 | bp_location_shadow_len_after_address_max according to the current |
12179 | content of the bp_location array. */ | |
f7545552 TT |
12180 | |
12181 | static void | |
876fa593 | 12182 | bp_location_target_extensions_update (void) |
f7545552 | 12183 | { |
876fa593 JK |
12184 | struct bp_location *bl, **blp_tmp; |
12185 | ||
12186 | bp_location_placed_address_before_address_max = 0; | |
12187 | bp_location_shadow_len_after_address_max = 0; | |
12188 | ||
12189 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12190 | { | |
12191 | CORE_ADDR start, end, addr; | |
12192 | ||
12193 | if (!bp_location_has_shadow (bl)) | |
12194 | continue; | |
12195 | ||
12196 | start = bl->target_info.placed_address; | |
12197 | end = start + bl->target_info.shadow_len; | |
12198 | ||
12199 | gdb_assert (bl->address >= start); | |
12200 | addr = bl->address - start; | |
12201 | if (addr > bp_location_placed_address_before_address_max) | |
12202 | bp_location_placed_address_before_address_max = addr; | |
12203 | ||
12204 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12205 | ||
12206 | gdb_assert (bl->address < end); | |
12207 | addr = end - bl->address; | |
12208 | if (addr > bp_location_shadow_len_after_address_max) | |
12209 | bp_location_shadow_len_after_address_max = addr; | |
12210 | } | |
f7545552 TT |
12211 | } |
12212 | ||
1e4d1764 YQ |
12213 | /* Download tracepoint locations if they haven't been. */ |
12214 | ||
12215 | static void | |
12216 | download_tracepoint_locations (void) | |
12217 | { | |
7ed2c994 | 12218 | struct breakpoint *b; |
1e4d1764 | 12219 | struct cleanup *old_chain; |
dd2e65cc | 12220 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12221 | |
12222 | old_chain = save_current_space_and_thread (); | |
12223 | ||
7ed2c994 | 12224 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12225 | { |
7ed2c994 | 12226 | struct bp_location *bl; |
1e4d1764 | 12227 | struct tracepoint *t; |
f2a8bc8a | 12228 | int bp_location_downloaded = 0; |
1e4d1764 | 12229 | |
7ed2c994 | 12230 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12231 | ? !may_insert_fast_tracepoints |
12232 | : !may_insert_tracepoints)) | |
12233 | continue; | |
12234 | ||
dd2e65cc YQ |
12235 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12236 | { | |
12237 | if (target_can_download_tracepoint ()) | |
12238 | can_download_tracepoint = TRIBOOL_TRUE; | |
12239 | else | |
12240 | can_download_tracepoint = TRIBOOL_FALSE; | |
12241 | } | |
12242 | ||
12243 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12244 | break; | |
12245 | ||
7ed2c994 YQ |
12246 | for (bl = b->loc; bl; bl = bl->next) |
12247 | { | |
12248 | /* In tracepoint, locations are _never_ duplicated, so | |
12249 | should_be_inserted is equivalent to | |
12250 | unduplicated_should_be_inserted. */ | |
12251 | if (!should_be_inserted (bl) || bl->inserted) | |
12252 | continue; | |
1e4d1764 | 12253 | |
7ed2c994 | 12254 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12255 | |
7ed2c994 | 12256 | target_download_tracepoint (bl); |
1e4d1764 | 12257 | |
7ed2c994 | 12258 | bl->inserted = 1; |
f2a8bc8a | 12259 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12260 | } |
12261 | t = (struct tracepoint *) b; | |
12262 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12263 | if (bp_location_downloaded) |
12264 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12265 | } |
12266 | ||
12267 | do_cleanups (old_chain); | |
12268 | } | |
12269 | ||
934709f0 PW |
12270 | /* Swap the insertion/duplication state between two locations. */ |
12271 | ||
12272 | static void | |
12273 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12274 | { | |
12275 | const int left_inserted = left->inserted; | |
12276 | const int left_duplicate = left->duplicate; | |
b775012e | 12277 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12278 | const struct bp_target_info left_target_info = left->target_info; |
12279 | ||
1e4d1764 YQ |
12280 | /* Locations of tracepoints can never be duplicated. */ |
12281 | if (is_tracepoint (left->owner)) | |
12282 | gdb_assert (!left->duplicate); | |
12283 | if (is_tracepoint (right->owner)) | |
12284 | gdb_assert (!right->duplicate); | |
12285 | ||
934709f0 PW |
12286 | left->inserted = right->inserted; |
12287 | left->duplicate = right->duplicate; | |
b775012e | 12288 | left->needs_update = right->needs_update; |
934709f0 PW |
12289 | left->target_info = right->target_info; |
12290 | right->inserted = left_inserted; | |
12291 | right->duplicate = left_duplicate; | |
b775012e | 12292 | right->needs_update = left_needs_update; |
934709f0 PW |
12293 | right->target_info = left_target_info; |
12294 | } | |
12295 | ||
b775012e LM |
12296 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12297 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12298 | conditions on the target's side. Such conditions need to be updated on | |
12299 | the target. */ | |
12300 | ||
12301 | static void | |
12302 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12303 | { | |
12304 | struct bp_location **locp = NULL, **loc2p; | |
12305 | struct bp_location *loc; | |
12306 | CORE_ADDR address = 0; | |
12307 | int pspace_num; | |
12308 | ||
12309 | address = bl->address; | |
12310 | pspace_num = bl->pspace->num; | |
12311 | ||
12312 | /* This is only meaningful if the target is | |
12313 | evaluating conditions and if the user has | |
12314 | opted for condition evaluation on the target's | |
12315 | side. */ | |
12316 | if (gdb_evaluates_breakpoint_condition_p () | |
12317 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12318 | return; | |
12319 | ||
12320 | /* Flag all breakpoint locations with this address and | |
12321 | the same program space as the location | |
12322 | as "its condition has changed". We need to | |
12323 | update the conditions on the target's side. */ | |
12324 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12325 | { | |
12326 | loc = *loc2p; | |
12327 | ||
12328 | if (!is_breakpoint (loc->owner) | |
12329 | || pspace_num != loc->pspace->num) | |
12330 | continue; | |
12331 | ||
12332 | /* Flag the location appropriately. We use a different state to | |
12333 | let everyone know that we already updated the set of locations | |
12334 | with addr bl->address and program space bl->pspace. This is so | |
12335 | we don't have to keep calling these functions just to mark locations | |
12336 | that have already been marked. */ | |
12337 | loc->condition_changed = condition_updated; | |
12338 | ||
12339 | /* Free the agent expression bytecode as well. We will compute | |
12340 | it later on. */ | |
833177a4 | 12341 | loc->cond_bytecode.reset (); |
b775012e LM |
12342 | } |
12343 | } | |
44702360 PA |
12344 | /* Called whether new breakpoints are created, or existing breakpoints |
12345 | deleted, to update the global location list and recompute which | |
12346 | locations are duplicate of which. | |
b775012e | 12347 | |
04086b45 PA |
12348 | The INSERT_MODE flag determines whether locations may not, may, or |
12349 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12350 | info. */ | |
b60e7edf | 12351 | |
0d381245 | 12352 | static void |
44702360 | 12353 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12354 | { |
74960c60 | 12355 | struct breakpoint *b; |
876fa593 | 12356 | struct bp_location **locp, *loc; |
f7545552 | 12357 | struct cleanup *cleanups; |
b775012e LM |
12358 | /* Last breakpoint location address that was marked for update. */ |
12359 | CORE_ADDR last_addr = 0; | |
12360 | /* Last breakpoint location program space that was marked for update. */ | |
12361 | int last_pspace_num = -1; | |
f7545552 | 12362 | |
2d134ed3 PA |
12363 | /* Used in the duplicates detection below. When iterating over all |
12364 | bp_locations, points to the first bp_location of a given address. | |
12365 | Breakpoints and watchpoints of different types are never | |
12366 | duplicates of each other. Keep one pointer for each type of | |
12367 | breakpoint/watchpoint, so we only need to loop over all locations | |
12368 | once. */ | |
12369 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12370 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12371 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12372 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12373 | |
4a64f543 MS |
12374 | /* Saved former bp_location array which we compare against the newly |
12375 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12376 | struct bp_location **old_location, **old_locp; |
12377 | unsigned old_location_count; | |
12378 | ||
12379 | old_location = bp_location; | |
12380 | old_location_count = bp_location_count; | |
12381 | bp_location = NULL; | |
12382 | bp_location_count = 0; | |
12383 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12384 | |
74960c60 | 12385 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12386 | for (loc = b->loc; loc; loc = loc->next) |
12387 | bp_location_count++; | |
12388 | ||
8d749320 | 12389 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12390 | locp = bp_location; |
12391 | ALL_BREAKPOINTS (b) | |
12392 | for (loc = b->loc; loc; loc = loc->next) | |
12393 | *locp++ = loc; | |
12394 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12395 | bp_location_compare); |
876fa593 JK |
12396 | |
12397 | bp_location_target_extensions_update (); | |
74960c60 | 12398 | |
4a64f543 MS |
12399 | /* Identify bp_location instances that are no longer present in the |
12400 | new list, and therefore should be freed. Note that it's not | |
12401 | necessary that those locations should be removed from inferior -- | |
12402 | if there's another location at the same address (previously | |
12403 | marked as duplicate), we don't need to remove/insert the | |
12404 | location. | |
876fa593 | 12405 | |
4a64f543 MS |
12406 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12407 | and former bp_location array state respectively. */ | |
876fa593 JK |
12408 | |
12409 | locp = bp_location; | |
12410 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12411 | old_locp++) | |
74960c60 | 12412 | { |
876fa593 | 12413 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12414 | struct bp_location **loc2p; |
876fa593 | 12415 | |
e5dd4106 | 12416 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12417 | not, we have to free it. */ |
c7d46a38 | 12418 | int found_object = 0; |
20874c92 VP |
12419 | /* Tells if the location should remain inserted in the target. */ |
12420 | int keep_in_target = 0; | |
12421 | int removed = 0; | |
876fa593 | 12422 | |
4a64f543 MS |
12423 | /* Skip LOCP entries which will definitely never be needed. |
12424 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12425 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12426 | && (*locp)->address < old_loc->address) |
876fa593 | 12427 | locp++; |
c7d46a38 PA |
12428 | |
12429 | for (loc2p = locp; | |
12430 | (loc2p < bp_location + bp_location_count | |
12431 | && (*loc2p)->address == old_loc->address); | |
12432 | loc2p++) | |
12433 | { | |
b775012e LM |
12434 | /* Check if this is a new/duplicated location or a duplicated |
12435 | location that had its condition modified. If so, we want to send | |
12436 | its condition to the target if evaluation of conditions is taking | |
12437 | place there. */ | |
12438 | if ((*loc2p)->condition_changed == condition_modified | |
12439 | && (last_addr != old_loc->address | |
12440 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12441 | { |
b775012e LM |
12442 | force_breakpoint_reinsertion (*loc2p); |
12443 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12444 | } |
b775012e LM |
12445 | |
12446 | if (*loc2p == old_loc) | |
12447 | found_object = 1; | |
c7d46a38 | 12448 | } |
74960c60 | 12449 | |
b775012e LM |
12450 | /* We have already handled this address, update it so that we don't |
12451 | have to go through updates again. */ | |
12452 | last_addr = old_loc->address; | |
12453 | ||
12454 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12455 | if (!found_object) | |
12456 | force_breakpoint_reinsertion (old_loc); | |
12457 | ||
4a64f543 MS |
12458 | /* If this location is no longer present, and inserted, look if |
12459 | there's maybe a new location at the same address. If so, | |
12460 | mark that one inserted, and don't remove this one. This is | |
12461 | needed so that we don't have a time window where a breakpoint | |
12462 | at certain location is not inserted. */ | |
74960c60 | 12463 | |
876fa593 | 12464 | if (old_loc->inserted) |
0d381245 | 12465 | { |
4a64f543 MS |
12466 | /* If the location is inserted now, we might have to remove |
12467 | it. */ | |
74960c60 | 12468 | |
876fa593 | 12469 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12470 | { |
4a64f543 MS |
12471 | /* The location is still present in the location list, |
12472 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12473 | keep_in_target = 1; |
74960c60 VP |
12474 | } |
12475 | else | |
12476 | { | |
b775012e LM |
12477 | /* This location still exists, but it won't be kept in the |
12478 | target since it may have been disabled. We proceed to | |
12479 | remove its target-side condition. */ | |
12480 | ||
4a64f543 MS |
12481 | /* The location is either no longer present, or got |
12482 | disabled. See if there's another location at the | |
12483 | same address, in which case we don't need to remove | |
12484 | this one from the target. */ | |
876fa593 | 12485 | |
2bdf28a0 | 12486 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12487 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12488 | { | |
876fa593 | 12489 | for (loc2p = locp; |
c7d46a38 PA |
12490 | (loc2p < bp_location + bp_location_count |
12491 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12492 | loc2p++) |
12493 | { | |
12494 | struct bp_location *loc2 = *loc2p; | |
12495 | ||
2d134ed3 | 12496 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12497 | { |
85d721b8 PA |
12498 | /* Read watchpoint locations are switched to |
12499 | access watchpoints, if the former are not | |
12500 | supported, but the latter are. */ | |
12501 | if (is_hardware_watchpoint (old_loc->owner)) | |
12502 | { | |
12503 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12504 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12505 | } | |
12506 | ||
934709f0 PW |
12507 | /* loc2 is a duplicated location. We need to check |
12508 | if it should be inserted in case it will be | |
12509 | unduplicated. */ | |
12510 | if (loc2 != old_loc | |
12511 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12512 | { |
934709f0 | 12513 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12514 | keep_in_target = 1; |
12515 | break; | |
12516 | } | |
876fa593 JK |
12517 | } |
12518 | } | |
12519 | } | |
74960c60 VP |
12520 | } |
12521 | ||
20874c92 VP |
12522 | if (!keep_in_target) |
12523 | { | |
834c0d03 | 12524 | if (remove_breakpoint (old_loc)) |
20874c92 | 12525 | { |
4a64f543 MS |
12526 | /* This is just about all we can do. We could keep |
12527 | this location on the global list, and try to | |
12528 | remove it next time, but there's no particular | |
12529 | reason why we will succeed next time. | |
20874c92 | 12530 | |
4a64f543 MS |
12531 | Note that at this point, old_loc->owner is still |
12532 | valid, as delete_breakpoint frees the breakpoint | |
12533 | only after calling us. */ | |
3e43a32a MS |
12534 | printf_filtered (_("warning: Error removing " |
12535 | "breakpoint %d\n"), | |
876fa593 | 12536 | old_loc->owner->number); |
20874c92 VP |
12537 | } |
12538 | removed = 1; | |
12539 | } | |
0d381245 | 12540 | } |
74960c60 VP |
12541 | |
12542 | if (!found_object) | |
1c5cfe86 | 12543 | { |
fbea99ea | 12544 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12545 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12546 | { |
db82e815 PA |
12547 | /* This location was removed from the target. In |
12548 | non-stop mode, a race condition is possible where | |
12549 | we've removed a breakpoint, but stop events for that | |
12550 | breakpoint are already queued and will arrive later. | |
12551 | We apply an heuristic to be able to distinguish such | |
12552 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12553 | breakpoint location for a bit, and will retire it | |
12554 | after we see some number of events. The theory here | |
12555 | is that reporting of events should, "on the average", | |
12556 | be fair, so after a while we'll see events from all | |
12557 | threads that have anything of interest, and no longer | |
12558 | need to keep this breakpoint location around. We | |
12559 | don't hold locations forever so to reduce chances of | |
12560 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12561 | SIGTRAP. | |
12562 | ||
12563 | The heuristic failing can be disastrous on | |
12564 | decr_pc_after_break targets. | |
12565 | ||
12566 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12567 | if we fail to recognize a late breakpoint SIGTRAP, | |
12568 | because events_till_retirement has reached 0 too | |
12569 | soon, we'll fail to do the PC adjustment, and report | |
12570 | a random SIGTRAP to the user. When the user resumes | |
12571 | the inferior, it will most likely immediately crash | |
2dec564e | 12572 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12573 | corrupted, because of being resumed e.g., in the |
12574 | middle of a multi-byte instruction, or skipped a | |
12575 | one-byte instruction. This was actually seen happen | |
12576 | on native x86-linux, and should be less rare on | |
12577 | targets that do not support new thread events, like | |
12578 | remote, due to the heuristic depending on | |
12579 | thread_count. | |
12580 | ||
12581 | Mistaking a random SIGTRAP for a breakpoint trap | |
12582 | causes similar symptoms (PC adjustment applied when | |
12583 | it shouldn't), but then again, playing with SIGTRAPs | |
12584 | behind the debugger's back is asking for trouble. | |
12585 | ||
12586 | Since hardware watchpoint traps are always | |
12587 | distinguishable from other traps, so we don't need to | |
12588 | apply keep hardware watchpoint moribund locations | |
12589 | around. We simply always ignore hardware watchpoint | |
12590 | traps we can no longer explain. */ | |
12591 | ||
876fa593 JK |
12592 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12593 | old_loc->owner = NULL; | |
20874c92 | 12594 | |
876fa593 | 12595 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12596 | } |
12597 | else | |
f431efe5 PA |
12598 | { |
12599 | old_loc->owner = NULL; | |
12600 | decref_bp_location (&old_loc); | |
12601 | } | |
20874c92 | 12602 | } |
74960c60 | 12603 | } |
1c5cfe86 | 12604 | |
348d480f PA |
12605 | /* Rescan breakpoints at the same address and section, marking the |
12606 | first one as "first" and any others as "duplicates". This is so | |
12607 | that the bpt instruction is only inserted once. If we have a | |
12608 | permanent breakpoint at the same place as BPT, make that one the | |
12609 | official one, and the rest as duplicates. Permanent breakpoints | |
12610 | are sorted first for the same address. | |
12611 | ||
12612 | Do the same for hardware watchpoints, but also considering the | |
12613 | watchpoint's type (regular/access/read) and length. */ | |
12614 | ||
12615 | bp_loc_first = NULL; | |
12616 | wp_loc_first = NULL; | |
12617 | awp_loc_first = NULL; | |
12618 | rwp_loc_first = NULL; | |
12619 | ALL_BP_LOCATIONS (loc, locp) | |
12620 | { | |
12621 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12622 | non-NULL. */ | |
348d480f | 12623 | struct bp_location **loc_first_p; |
d3fbdd86 | 12624 | b = loc->owner; |
348d480f | 12625 | |
6f380991 | 12626 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12627 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12628 | /* Don't detect duplicate for tracepoint locations because they are |
12629 | never duplicated. See the comments in field `duplicate' of | |
12630 | `struct bp_location'. */ | |
348d480f | 12631 | || is_tracepoint (b)) |
b775012e LM |
12632 | { |
12633 | /* Clear the condition modification flag. */ | |
12634 | loc->condition_changed = condition_unchanged; | |
12635 | continue; | |
12636 | } | |
348d480f | 12637 | |
348d480f PA |
12638 | if (b->type == bp_hardware_watchpoint) |
12639 | loc_first_p = &wp_loc_first; | |
12640 | else if (b->type == bp_read_watchpoint) | |
12641 | loc_first_p = &rwp_loc_first; | |
12642 | else if (b->type == bp_access_watchpoint) | |
12643 | loc_first_p = &awp_loc_first; | |
12644 | else | |
12645 | loc_first_p = &bp_loc_first; | |
12646 | ||
12647 | if (*loc_first_p == NULL | |
12648 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12649 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12650 | { | |
12651 | *loc_first_p = loc; | |
12652 | loc->duplicate = 0; | |
b775012e LM |
12653 | |
12654 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12655 | { | |
12656 | loc->needs_update = 1; | |
12657 | /* Clear the condition modification flag. */ | |
12658 | loc->condition_changed = condition_unchanged; | |
12659 | } | |
348d480f PA |
12660 | continue; |
12661 | } | |
12662 | ||
934709f0 PW |
12663 | |
12664 | /* This and the above ensure the invariant that the first location | |
12665 | is not duplicated, and is the inserted one. | |
12666 | All following are marked as duplicated, and are not inserted. */ | |
12667 | if (loc->inserted) | |
12668 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12669 | loc->duplicate = 1; |
12670 | ||
b775012e LM |
12671 | /* Clear the condition modification flag. */ |
12672 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12673 | } |
12674 | ||
a25a5a45 | 12675 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12676 | { |
04086b45 | 12677 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12678 | insert_breakpoint_locations (); |
12679 | else | |
12680 | { | |
44702360 PA |
12681 | /* Even though the caller told us to not insert new |
12682 | locations, we may still need to update conditions on the | |
12683 | target's side of breakpoints that were already inserted | |
12684 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12685 | only update conditions for locations that are marked |
12686 | "needs_update". */ | |
12687 | update_inserted_breakpoint_locations (); | |
12688 | } | |
12689 | } | |
348d480f | 12690 | |
04086b45 | 12691 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12692 | download_tracepoint_locations (); |
12693 | ||
348d480f PA |
12694 | do_cleanups (cleanups); |
12695 | } | |
12696 | ||
12697 | void | |
12698 | breakpoint_retire_moribund (void) | |
12699 | { | |
12700 | struct bp_location *loc; | |
12701 | int ix; | |
12702 | ||
12703 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12704 | if (--(loc->events_till_retirement) == 0) | |
12705 | { | |
12706 | decref_bp_location (&loc); | |
12707 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12708 | --ix; | |
12709 | } | |
12710 | } | |
12711 | ||
12712 | static void | |
44702360 | 12713 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12714 | { |
348d480f | 12715 | |
492d29ea PA |
12716 | TRY |
12717 | { | |
12718 | update_global_location_list (insert_mode); | |
12719 | } | |
12720 | CATCH (e, RETURN_MASK_ERROR) | |
12721 | { | |
12722 | } | |
12723 | END_CATCH | |
348d480f PA |
12724 | } |
12725 | ||
12726 | /* Clear BKP from a BPS. */ | |
12727 | ||
12728 | static void | |
12729 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12730 | { | |
12731 | bpstat bs; | |
12732 | ||
12733 | for (bs = bps; bs; bs = bs->next) | |
12734 | if (bs->breakpoint_at == bpt) | |
12735 | { | |
12736 | bs->breakpoint_at = NULL; | |
12737 | bs->old_val = NULL; | |
12738 | /* bs->commands will be freed later. */ | |
12739 | } | |
12740 | } | |
12741 | ||
12742 | /* Callback for iterate_over_threads. */ | |
12743 | static int | |
12744 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12745 | { | |
9a3c8263 | 12746 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12747 | |
12748 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12749 | return 0; | |
12750 | } | |
12751 | ||
12752 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12753 | callbacks. */ | |
12754 | ||
12755 | static void | |
12756 | say_where (struct breakpoint *b) | |
12757 | { | |
12758 | struct value_print_options opts; | |
12759 | ||
12760 | get_user_print_options (&opts); | |
12761 | ||
12762 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12763 | single string. */ | |
12764 | if (b->loc == NULL) | |
12765 | { | |
f00aae0f KS |
12766 | /* For pending locations, the output differs slightly based |
12767 | on b->extra_string. If this is non-NULL, it contains either | |
12768 | a condition or dprintf arguments. */ | |
12769 | if (b->extra_string == NULL) | |
12770 | { | |
12771 | printf_filtered (_(" (%s) pending."), | |
12772 | event_location_to_string (b->location)); | |
12773 | } | |
12774 | else if (b->type == bp_dprintf) | |
12775 | { | |
12776 | printf_filtered (_(" (%s,%s) pending."), | |
12777 | event_location_to_string (b->location), | |
12778 | b->extra_string); | |
12779 | } | |
12780 | else | |
12781 | { | |
12782 | printf_filtered (_(" (%s %s) pending."), | |
12783 | event_location_to_string (b->location), | |
12784 | b->extra_string); | |
12785 | } | |
348d480f PA |
12786 | } |
12787 | else | |
12788 | { | |
2f202fde | 12789 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12790 | { |
12791 | printf_filtered (" at "); | |
12792 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12793 | gdb_stdout); | |
12794 | } | |
2f202fde | 12795 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12796 | { |
12797 | /* If there is a single location, we can print the location | |
12798 | more nicely. */ | |
12799 | if (b->loc->next == NULL) | |
12800 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12801 | symtab_to_filename_for_display (b->loc->symtab), |
12802 | b->loc->line_number); | |
f8eba3c6 TT |
12803 | else |
12804 | /* This is not ideal, but each location may have a | |
12805 | different file name, and this at least reflects the | |
12806 | real situation somewhat. */ | |
f00aae0f KS |
12807 | printf_filtered (": %s.", |
12808 | event_location_to_string (b->location)); | |
f8eba3c6 | 12809 | } |
348d480f PA |
12810 | |
12811 | if (b->loc->next) | |
12812 | { | |
12813 | struct bp_location *loc = b->loc; | |
12814 | int n = 0; | |
12815 | for (; loc; loc = loc->next) | |
12816 | ++n; | |
12817 | printf_filtered (" (%d locations)", n); | |
12818 | } | |
12819 | } | |
12820 | } | |
12821 | ||
348d480f PA |
12822 | /* Default bp_location_ops methods. */ |
12823 | ||
12824 | static void | |
12825 | bp_location_dtor (struct bp_location *self) | |
12826 | { | |
348d480f PA |
12827 | xfree (self->function_name); |
12828 | } | |
12829 | ||
12830 | static const struct bp_location_ops bp_location_ops = | |
12831 | { | |
12832 | bp_location_dtor | |
12833 | }; | |
12834 | ||
2060206e PA |
12835 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12836 | inherit from. */ | |
348d480f | 12837 | |
2060206e PA |
12838 | static void |
12839 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12840 | { |
12841 | decref_counted_command_line (&self->commands); | |
12842 | xfree (self->cond_string); | |
fb81d016 | 12843 | xfree (self->extra_string); |
f8eba3c6 | 12844 | xfree (self->filter); |
f00aae0f KS |
12845 | delete_event_location (self->location); |
12846 | delete_event_location (self->location_range_end); | |
348d480f PA |
12847 | } |
12848 | ||
2060206e PA |
12849 | static struct bp_location * |
12850 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12851 | { |
12852 | struct bp_location *loc; | |
12853 | ||
4d01a485 | 12854 | loc = new struct bp_location (); |
348d480f PA |
12855 | init_bp_location (loc, &bp_location_ops, self); |
12856 | return loc; | |
12857 | } | |
12858 | ||
2060206e PA |
12859 | static void |
12860 | base_breakpoint_re_set (struct breakpoint *b) | |
12861 | { | |
12862 | /* Nothing to re-set. */ | |
12863 | } | |
12864 | ||
12865 | #define internal_error_pure_virtual_called() \ | |
12866 | gdb_assert_not_reached ("pure virtual function called") | |
12867 | ||
12868 | static int | |
12869 | base_breakpoint_insert_location (struct bp_location *bl) | |
12870 | { | |
12871 | internal_error_pure_virtual_called (); | |
12872 | } | |
12873 | ||
12874 | static int | |
73971819 PA |
12875 | base_breakpoint_remove_location (struct bp_location *bl, |
12876 | enum remove_bp_reason reason) | |
2060206e PA |
12877 | { |
12878 | internal_error_pure_virtual_called (); | |
12879 | } | |
12880 | ||
12881 | static int | |
12882 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12883 | struct address_space *aspace, | |
09ac7c10 TT |
12884 | CORE_ADDR bp_addr, |
12885 | const struct target_waitstatus *ws) | |
2060206e PA |
12886 | { |
12887 | internal_error_pure_virtual_called (); | |
12888 | } | |
12889 | ||
12890 | static void | |
12891 | base_breakpoint_check_status (bpstat bs) | |
12892 | { | |
12893 | /* Always stop. */ | |
12894 | } | |
12895 | ||
12896 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12897 | errors. */ | |
12898 | ||
12899 | static int | |
12900 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12901 | { | |
12902 | internal_error_pure_virtual_called (); | |
12903 | } | |
12904 | ||
12905 | /* A "resources_needed" breakpoint_ops method that just internal | |
12906 | errors. */ | |
12907 | ||
12908 | static int | |
12909 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12910 | { | |
12911 | internal_error_pure_virtual_called (); | |
12912 | } | |
12913 | ||
12914 | static enum print_stop_action | |
12915 | base_breakpoint_print_it (bpstat bs) | |
12916 | { | |
12917 | internal_error_pure_virtual_called (); | |
12918 | } | |
12919 | ||
12920 | static void | |
12921 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12922 | struct ui_out *uiout) | |
12923 | { | |
12924 | /* nothing */ | |
12925 | } | |
12926 | ||
12927 | static void | |
12928 | base_breakpoint_print_mention (struct breakpoint *b) | |
12929 | { | |
12930 | internal_error_pure_virtual_called (); | |
12931 | } | |
12932 | ||
12933 | static void | |
12934 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12935 | { | |
12936 | internal_error_pure_virtual_called (); | |
12937 | } | |
12938 | ||
983af33b | 12939 | static void |
f00aae0f KS |
12940 | base_breakpoint_create_sals_from_location |
12941 | (const struct event_location *location, | |
12942 | struct linespec_result *canonical, | |
12943 | enum bptype type_wanted) | |
983af33b SDJ |
12944 | { |
12945 | internal_error_pure_virtual_called (); | |
12946 | } | |
12947 | ||
12948 | static void | |
12949 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12950 | struct linespec_result *c, | |
983af33b | 12951 | char *cond_string, |
e7e0cddf | 12952 | char *extra_string, |
983af33b SDJ |
12953 | enum bptype type_wanted, |
12954 | enum bpdisp disposition, | |
12955 | int thread, | |
12956 | int task, int ignore_count, | |
12957 | const struct breakpoint_ops *o, | |
12958 | int from_tty, int enabled, | |
44f238bb | 12959 | int internal, unsigned flags) |
983af33b SDJ |
12960 | { |
12961 | internal_error_pure_virtual_called (); | |
12962 | } | |
12963 | ||
12964 | static void | |
f00aae0f KS |
12965 | base_breakpoint_decode_location (struct breakpoint *b, |
12966 | const struct event_location *location, | |
c2f4122d | 12967 | struct program_space *search_pspace, |
983af33b SDJ |
12968 | struct symtabs_and_lines *sals) |
12969 | { | |
12970 | internal_error_pure_virtual_called (); | |
12971 | } | |
12972 | ||
ab04a2af TT |
12973 | /* The default 'explains_signal' method. */ |
12974 | ||
47591c29 | 12975 | static int |
427cd150 | 12976 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12977 | { |
47591c29 | 12978 | return 1; |
ab04a2af TT |
12979 | } |
12980 | ||
9d6e6e84 HZ |
12981 | /* The default "after_condition_true" method. */ |
12982 | ||
12983 | static void | |
12984 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12985 | { | |
12986 | /* Nothing to do. */ | |
12987 | } | |
12988 | ||
ab04a2af | 12989 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12990 | { |
12991 | base_breakpoint_dtor, | |
12992 | base_breakpoint_allocate_location, | |
12993 | base_breakpoint_re_set, | |
12994 | base_breakpoint_insert_location, | |
12995 | base_breakpoint_remove_location, | |
12996 | base_breakpoint_breakpoint_hit, | |
12997 | base_breakpoint_check_status, | |
12998 | base_breakpoint_resources_needed, | |
12999 | base_breakpoint_works_in_software_mode, | |
13000 | base_breakpoint_print_it, | |
13001 | NULL, | |
13002 | base_breakpoint_print_one_detail, | |
13003 | base_breakpoint_print_mention, | |
983af33b | 13004 | base_breakpoint_print_recreate, |
5f700d83 | 13005 | base_breakpoint_create_sals_from_location, |
983af33b | 13006 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13007 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13008 | base_breakpoint_explains_signal, |
13009 | base_breakpoint_after_condition_true, | |
2060206e PA |
13010 | }; |
13011 | ||
13012 | /* Default breakpoint_ops methods. */ | |
13013 | ||
13014 | static void | |
348d480f PA |
13015 | bkpt_re_set (struct breakpoint *b) |
13016 | { | |
06edf0c0 | 13017 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13018 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13019 | { |
f00aae0f | 13020 | /* Anything without a location can't be re-set. */ |
348d480f | 13021 | delete_breakpoint (b); |
06edf0c0 | 13022 | return; |
348d480f | 13023 | } |
06edf0c0 PA |
13024 | |
13025 | breakpoint_re_set_default (b); | |
348d480f PA |
13026 | } |
13027 | ||
2060206e | 13028 | static int |
348d480f PA |
13029 | bkpt_insert_location (struct bp_location *bl) |
13030 | { | |
cd6c3b4f YQ |
13031 | CORE_ADDR addr = bl->target_info.reqstd_address; |
13032 | ||
579c6ad9 | 13033 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
13034 | bl->target_info.placed_address = addr; |
13035 | ||
348d480f | 13036 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 13037 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13038 | else |
7c16b83e | 13039 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13040 | } |
13041 | ||
2060206e | 13042 | static int |
73971819 | 13043 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13044 | { |
13045 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13046 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13047 | else | |
73971819 | 13048 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13049 | } |
13050 | ||
2060206e | 13051 | static int |
348d480f | 13052 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13053 | struct address_space *aspace, CORE_ADDR bp_addr, |
13054 | const struct target_waitstatus *ws) | |
348d480f | 13055 | { |
09ac7c10 | 13056 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13057 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13058 | return 0; |
13059 | ||
348d480f PA |
13060 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13061 | aspace, bp_addr)) | |
13062 | return 0; | |
13063 | ||
13064 | if (overlay_debugging /* unmapped overlay section */ | |
13065 | && section_is_overlay (bl->section) | |
13066 | && !section_is_mapped (bl->section)) | |
13067 | return 0; | |
13068 | ||
13069 | return 1; | |
13070 | } | |
13071 | ||
cd1608cc PA |
13072 | static int |
13073 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13074 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13075 | const struct target_waitstatus *ws) | |
13076 | { | |
13077 | if (dprintf_style == dprintf_style_agent | |
13078 | && target_can_run_breakpoint_commands ()) | |
13079 | { | |
13080 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13081 | for this address it must be for a breakpoint that happens to | |
13082 | be set at the same address. */ | |
13083 | return 0; | |
13084 | } | |
13085 | ||
13086 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13087 | } | |
13088 | ||
2060206e | 13089 | static int |
348d480f PA |
13090 | bkpt_resources_needed (const struct bp_location *bl) |
13091 | { | |
13092 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13093 | ||
13094 | return 1; | |
13095 | } | |
13096 | ||
2060206e | 13097 | static enum print_stop_action |
348d480f PA |
13098 | bkpt_print_it (bpstat bs) |
13099 | { | |
348d480f PA |
13100 | struct breakpoint *b; |
13101 | const struct bp_location *bl; | |
001c8c33 | 13102 | int bp_temp; |
79a45e25 | 13103 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13104 | |
13105 | gdb_assert (bs->bp_location_at != NULL); | |
13106 | ||
13107 | bl = bs->bp_location_at; | |
13108 | b = bs->breakpoint_at; | |
13109 | ||
001c8c33 PA |
13110 | bp_temp = b->disposition == disp_del; |
13111 | if (bl->address != bl->requested_address) | |
13112 | breakpoint_adjustment_warning (bl->requested_address, | |
13113 | bl->address, | |
13114 | b->number, 1); | |
13115 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13116 | maybe_print_thread_hit_breakpoint (uiout); |
13117 | ||
001c8c33 | 13118 | if (bp_temp) |
112e8700 | 13119 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 13120 | else |
112e8700 SM |
13121 | uiout->text ("Breakpoint "); |
13122 | if (uiout->is_mi_like_p ()) | |
348d480f | 13123 | { |
112e8700 | 13124 | uiout->field_string ("reason", |
001c8c33 | 13125 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 13126 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 13127 | } |
112e8700 SM |
13128 | uiout->field_int ("bkptno", b->number); |
13129 | uiout->text (", "); | |
06edf0c0 | 13130 | |
001c8c33 | 13131 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13132 | } |
13133 | ||
2060206e | 13134 | static void |
06edf0c0 PA |
13135 | bkpt_print_mention (struct breakpoint *b) |
13136 | { | |
112e8700 | 13137 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
13138 | return; |
13139 | ||
13140 | switch (b->type) | |
13141 | { | |
13142 | case bp_breakpoint: | |
13143 | case bp_gnu_ifunc_resolver: | |
13144 | if (b->disposition == disp_del) | |
13145 | printf_filtered (_("Temporary breakpoint")); | |
13146 | else | |
13147 | printf_filtered (_("Breakpoint")); | |
13148 | printf_filtered (_(" %d"), b->number); | |
13149 | if (b->type == bp_gnu_ifunc_resolver) | |
13150 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13151 | break; | |
13152 | case bp_hardware_breakpoint: | |
13153 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13154 | break; | |
e7e0cddf SS |
13155 | case bp_dprintf: |
13156 | printf_filtered (_("Dprintf %d"), b->number); | |
13157 | break; | |
06edf0c0 PA |
13158 | } |
13159 | ||
13160 | say_where (b); | |
13161 | } | |
13162 | ||
2060206e | 13163 | static void |
06edf0c0 PA |
13164 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13165 | { | |
13166 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13167 | fprintf_unfiltered (fp, "tbreak"); | |
13168 | else if (tp->type == bp_breakpoint) | |
13169 | fprintf_unfiltered (fp, "break"); | |
13170 | else if (tp->type == bp_hardware_breakpoint | |
13171 | && tp->disposition == disp_del) | |
13172 | fprintf_unfiltered (fp, "thbreak"); | |
13173 | else if (tp->type == bp_hardware_breakpoint) | |
13174 | fprintf_unfiltered (fp, "hbreak"); | |
13175 | else | |
13176 | internal_error (__FILE__, __LINE__, | |
13177 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13178 | ||
f00aae0f KS |
13179 | fprintf_unfiltered (fp, " %s", |
13180 | event_location_to_string (tp->location)); | |
13181 | ||
13182 | /* Print out extra_string if this breakpoint is pending. It might | |
13183 | contain, for example, conditions that were set by the user. */ | |
13184 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13185 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13186 | ||
dd11a36c | 13187 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13188 | } |
13189 | ||
983af33b | 13190 | static void |
f00aae0f KS |
13191 | bkpt_create_sals_from_location (const struct event_location *location, |
13192 | struct linespec_result *canonical, | |
13193 | enum bptype type_wanted) | |
983af33b | 13194 | { |
f00aae0f | 13195 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13196 | } |
13197 | ||
13198 | static void | |
13199 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13200 | struct linespec_result *canonical, | |
983af33b | 13201 | char *cond_string, |
e7e0cddf | 13202 | char *extra_string, |
983af33b SDJ |
13203 | enum bptype type_wanted, |
13204 | enum bpdisp disposition, | |
13205 | int thread, | |
13206 | int task, int ignore_count, | |
13207 | const struct breakpoint_ops *ops, | |
13208 | int from_tty, int enabled, | |
44f238bb | 13209 | int internal, unsigned flags) |
983af33b | 13210 | { |
023fa29b | 13211 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13212 | cond_string, extra_string, |
13213 | type_wanted, | |
983af33b SDJ |
13214 | disposition, thread, task, |
13215 | ignore_count, ops, from_tty, | |
44f238bb | 13216 | enabled, internal, flags); |
983af33b SDJ |
13217 | } |
13218 | ||
13219 | static void | |
f00aae0f KS |
13220 | bkpt_decode_location (struct breakpoint *b, |
13221 | const struct event_location *location, | |
c2f4122d | 13222 | struct program_space *search_pspace, |
983af33b SDJ |
13223 | struct symtabs_and_lines *sals) |
13224 | { | |
c2f4122d | 13225 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13226 | } |
13227 | ||
06edf0c0 PA |
13228 | /* Virtual table for internal breakpoints. */ |
13229 | ||
13230 | static void | |
13231 | internal_bkpt_re_set (struct breakpoint *b) | |
13232 | { | |
13233 | switch (b->type) | |
13234 | { | |
13235 | /* Delete overlay event and longjmp master breakpoints; they | |
13236 | will be reset later by breakpoint_re_set. */ | |
13237 | case bp_overlay_event: | |
13238 | case bp_longjmp_master: | |
13239 | case bp_std_terminate_master: | |
13240 | case bp_exception_master: | |
13241 | delete_breakpoint (b); | |
13242 | break; | |
13243 | ||
13244 | /* This breakpoint is special, it's set up when the inferior | |
13245 | starts and we really don't want to touch it. */ | |
13246 | case bp_shlib_event: | |
13247 | ||
13248 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13249 | it is set up, we do not want to touch it. */ | |
13250 | case bp_thread_event: | |
13251 | break; | |
13252 | } | |
13253 | } | |
13254 | ||
13255 | static void | |
13256 | internal_bkpt_check_status (bpstat bs) | |
13257 | { | |
a9b3a50f PA |
13258 | if (bs->breakpoint_at->type == bp_shlib_event) |
13259 | { | |
13260 | /* If requested, stop when the dynamic linker notifies GDB of | |
13261 | events. This allows the user to get control and place | |
13262 | breakpoints in initializer routines for dynamically loaded | |
13263 | objects (among other things). */ | |
13264 | bs->stop = stop_on_solib_events; | |
13265 | bs->print = stop_on_solib_events; | |
13266 | } | |
13267 | else | |
13268 | bs->stop = 0; | |
06edf0c0 PA |
13269 | } |
13270 | ||
13271 | static enum print_stop_action | |
13272 | internal_bkpt_print_it (bpstat bs) | |
13273 | { | |
06edf0c0 | 13274 | struct breakpoint *b; |
06edf0c0 | 13275 | |
06edf0c0 PA |
13276 | b = bs->breakpoint_at; |
13277 | ||
06edf0c0 PA |
13278 | switch (b->type) |
13279 | { | |
348d480f PA |
13280 | case bp_shlib_event: |
13281 | /* Did we stop because the user set the stop_on_solib_events | |
13282 | variable? (If so, we report this as a generic, "Stopped due | |
13283 | to shlib event" message.) */ | |
edcc5120 | 13284 | print_solib_event (0); |
348d480f PA |
13285 | break; |
13286 | ||
13287 | case bp_thread_event: | |
13288 | /* Not sure how we will get here. | |
13289 | GDB should not stop for these breakpoints. */ | |
13290 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13291 | break; |
13292 | ||
13293 | case bp_overlay_event: | |
13294 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13295 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13296 | break; |
13297 | ||
13298 | case bp_longjmp_master: | |
13299 | /* These should never be enabled. */ | |
13300 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13301 | break; |
13302 | ||
13303 | case bp_std_terminate_master: | |
13304 | /* These should never be enabled. */ | |
13305 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13306 | "gdb should not stop!\n")); | |
348d480f PA |
13307 | break; |
13308 | ||
13309 | case bp_exception_master: | |
13310 | /* These should never be enabled. */ | |
13311 | printf_filtered (_("Exception Master Breakpoint: " | |
13312 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13313 | break; |
13314 | } | |
13315 | ||
001c8c33 | 13316 | return PRINT_NOTHING; |
06edf0c0 PA |
13317 | } |
13318 | ||
13319 | static void | |
13320 | internal_bkpt_print_mention (struct breakpoint *b) | |
13321 | { | |
13322 | /* Nothing to mention. These breakpoints are internal. */ | |
13323 | } | |
13324 | ||
06edf0c0 PA |
13325 | /* Virtual table for momentary breakpoints */ |
13326 | ||
13327 | static void | |
13328 | momentary_bkpt_re_set (struct breakpoint *b) | |
13329 | { | |
13330 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13331 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13332 | Otherwise these should have been blown away via the cleanup chain |
13333 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13334 | } | |
13335 | ||
13336 | static void | |
13337 | momentary_bkpt_check_status (bpstat bs) | |
13338 | { | |
13339 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13340 | } | |
13341 | ||
13342 | static enum print_stop_action | |
13343 | momentary_bkpt_print_it (bpstat bs) | |
13344 | { | |
001c8c33 | 13345 | return PRINT_UNKNOWN; |
348d480f PA |
13346 | } |
13347 | ||
06edf0c0 PA |
13348 | static void |
13349 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13350 | { |
06edf0c0 | 13351 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13352 | } |
13353 | ||
e2e4d78b JK |
13354 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13355 | ||
13356 | It gets cleared already on the removal of the first one of such placed | |
13357 | breakpoints. This is OK as they get all removed altogether. */ | |
13358 | ||
13359 | static void | |
13360 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13361 | { | |
5d5658a1 | 13362 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13363 | |
13364 | if (tp) | |
13365 | tp->initiating_frame = null_frame_id; | |
13366 | ||
13367 | momentary_breakpoint_ops.dtor (self); | |
13368 | } | |
13369 | ||
55aa24fb SDJ |
13370 | /* Specific methods for probe breakpoints. */ |
13371 | ||
13372 | static int | |
13373 | bkpt_probe_insert_location (struct bp_location *bl) | |
13374 | { | |
13375 | int v = bkpt_insert_location (bl); | |
13376 | ||
13377 | if (v == 0) | |
13378 | { | |
13379 | /* The insertion was successful, now let's set the probe's semaphore | |
13380 | if needed. */ | |
0ea5cda8 SDJ |
13381 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13382 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13383 | bl->probe.objfile, | |
13384 | bl->gdbarch); | |
55aa24fb SDJ |
13385 | } |
13386 | ||
13387 | return v; | |
13388 | } | |
13389 | ||
13390 | static int | |
73971819 PA |
13391 | bkpt_probe_remove_location (struct bp_location *bl, |
13392 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13393 | { |
13394 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13395 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13396 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13397 | bl->probe.objfile, | |
13398 | bl->gdbarch); | |
55aa24fb | 13399 | |
73971819 | 13400 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13401 | } |
13402 | ||
13403 | static void | |
f00aae0f | 13404 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13405 | struct linespec_result *canonical, |
f00aae0f | 13406 | enum bptype type_wanted) |
55aa24fb SDJ |
13407 | { |
13408 | struct linespec_sals lsal; | |
13409 | ||
c2f4122d | 13410 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13411 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13412 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13413 | } | |
13414 | ||
13415 | static void | |
f00aae0f KS |
13416 | bkpt_probe_decode_location (struct breakpoint *b, |
13417 | const struct event_location *location, | |
c2f4122d | 13418 | struct program_space *search_pspace, |
55aa24fb SDJ |
13419 | struct symtabs_and_lines *sals) |
13420 | { | |
c2f4122d | 13421 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13422 | if (!sals->sals) |
13423 | error (_("probe not found")); | |
13424 | } | |
13425 | ||
348d480f | 13426 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13427 | |
348d480f PA |
13428 | static void |
13429 | tracepoint_re_set (struct breakpoint *b) | |
13430 | { | |
13431 | breakpoint_re_set_default (b); | |
13432 | } | |
876fa593 | 13433 | |
348d480f PA |
13434 | static int |
13435 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13436 | struct address_space *aspace, CORE_ADDR bp_addr, |
13437 | const struct target_waitstatus *ws) | |
348d480f PA |
13438 | { |
13439 | /* By definition, the inferior does not report stops at | |
13440 | tracepoints. */ | |
13441 | return 0; | |
74960c60 VP |
13442 | } |
13443 | ||
13444 | static void | |
348d480f PA |
13445 | tracepoint_print_one_detail (const struct breakpoint *self, |
13446 | struct ui_out *uiout) | |
74960c60 | 13447 | { |
d9b3f62e PA |
13448 | struct tracepoint *tp = (struct tracepoint *) self; |
13449 | if (tp->static_trace_marker_id) | |
348d480f PA |
13450 | { |
13451 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13452 | |
112e8700 SM |
13453 | uiout->text ("\tmarker id is "); |
13454 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13455 | tp->static_trace_marker_id); |
112e8700 | 13456 | uiout->text ("\n"); |
348d480f | 13457 | } |
0d381245 VP |
13458 | } |
13459 | ||
a474d7c2 | 13460 | static void |
348d480f | 13461 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13462 | { |
112e8700 | 13463 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13464 | return; |
cc59ec59 | 13465 | |
348d480f PA |
13466 | switch (b->type) |
13467 | { | |
13468 | case bp_tracepoint: | |
13469 | printf_filtered (_("Tracepoint")); | |
13470 | printf_filtered (_(" %d"), b->number); | |
13471 | break; | |
13472 | case bp_fast_tracepoint: | |
13473 | printf_filtered (_("Fast tracepoint")); | |
13474 | printf_filtered (_(" %d"), b->number); | |
13475 | break; | |
13476 | case bp_static_tracepoint: | |
13477 | printf_filtered (_("Static tracepoint")); | |
13478 | printf_filtered (_(" %d"), b->number); | |
13479 | break; | |
13480 | default: | |
13481 | internal_error (__FILE__, __LINE__, | |
13482 | _("unhandled tracepoint type %d"), (int) b->type); | |
13483 | } | |
13484 | ||
13485 | say_where (b); | |
a474d7c2 PA |
13486 | } |
13487 | ||
348d480f | 13488 | static void |
d9b3f62e | 13489 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13490 | { |
d9b3f62e PA |
13491 | struct tracepoint *tp = (struct tracepoint *) self; |
13492 | ||
13493 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13494 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13495 | else if (self->type == bp_static_tracepoint) |
348d480f | 13496 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13497 | else if (self->type == bp_tracepoint) |
348d480f PA |
13498 | fprintf_unfiltered (fp, "trace"); |
13499 | else | |
13500 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13501 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13502 | |
f00aae0f KS |
13503 | fprintf_unfiltered (fp, " %s", |
13504 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13505 | print_recreate_thread (self, fp); |
13506 | ||
13507 | if (tp->pass_count) | |
13508 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13509 | } |
13510 | ||
983af33b | 13511 | static void |
f00aae0f KS |
13512 | tracepoint_create_sals_from_location (const struct event_location *location, |
13513 | struct linespec_result *canonical, | |
13514 | enum bptype type_wanted) | |
983af33b | 13515 | { |
f00aae0f | 13516 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13517 | } |
13518 | ||
13519 | static void | |
13520 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13521 | struct linespec_result *canonical, | |
983af33b | 13522 | char *cond_string, |
e7e0cddf | 13523 | char *extra_string, |
983af33b SDJ |
13524 | enum bptype type_wanted, |
13525 | enum bpdisp disposition, | |
13526 | int thread, | |
13527 | int task, int ignore_count, | |
13528 | const struct breakpoint_ops *ops, | |
13529 | int from_tty, int enabled, | |
44f238bb | 13530 | int internal, unsigned flags) |
983af33b | 13531 | { |
023fa29b | 13532 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13533 | cond_string, extra_string, |
13534 | type_wanted, | |
983af33b SDJ |
13535 | disposition, thread, task, |
13536 | ignore_count, ops, from_tty, | |
44f238bb | 13537 | enabled, internal, flags); |
983af33b SDJ |
13538 | } |
13539 | ||
13540 | static void | |
f00aae0f KS |
13541 | tracepoint_decode_location (struct breakpoint *b, |
13542 | const struct event_location *location, | |
c2f4122d | 13543 | struct program_space *search_pspace, |
983af33b SDJ |
13544 | struct symtabs_and_lines *sals) |
13545 | { | |
c2f4122d | 13546 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13547 | } |
13548 | ||
2060206e | 13549 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13550 | |
55aa24fb SDJ |
13551 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13552 | static probe. */ | |
13553 | ||
13554 | static void | |
f00aae0f KS |
13555 | tracepoint_probe_create_sals_from_location |
13556 | (const struct event_location *location, | |
13557 | struct linespec_result *canonical, | |
13558 | enum bptype type_wanted) | |
55aa24fb SDJ |
13559 | { |
13560 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13561 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13562 | } |
13563 | ||
13564 | static void | |
f00aae0f KS |
13565 | tracepoint_probe_decode_location (struct breakpoint *b, |
13566 | const struct event_location *location, | |
c2f4122d | 13567 | struct program_space *search_pspace, |
55aa24fb SDJ |
13568 | struct symtabs_and_lines *sals) |
13569 | { | |
13570 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13571 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13572 | } |
13573 | ||
13574 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13575 | ||
5c2b4418 HZ |
13576 | /* Dprintf breakpoint_ops methods. */ |
13577 | ||
13578 | static void | |
13579 | dprintf_re_set (struct breakpoint *b) | |
13580 | { | |
13581 | breakpoint_re_set_default (b); | |
13582 | ||
f00aae0f KS |
13583 | /* extra_string should never be non-NULL for dprintf. */ |
13584 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13585 | |
13586 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13587 | 2 - create a dprintf, which resolves fine. | |
13588 | 3 - disconnect from target 1 | |
13589 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13590 | ||
13591 | After steps #3/#4, you'll want the dprintf command list to | |
13592 | be updated, because target 1 and 2 may well return different | |
13593 | answers for target_can_run_breakpoint_commands(). | |
13594 | Given absence of finer grained resetting, we get to do | |
13595 | it all the time. */ | |
13596 | if (b->extra_string != NULL) | |
13597 | update_dprintf_command_list (b); | |
13598 | } | |
13599 | ||
2d9442cc HZ |
13600 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13601 | ||
13602 | static void | |
13603 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13604 | { | |
f00aae0f KS |
13605 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13606 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13607 | tp->extra_string); |
13608 | print_recreate_thread (tp, fp); | |
13609 | } | |
13610 | ||
9d6e6e84 HZ |
13611 | /* Implement the "after_condition_true" breakpoint_ops method for |
13612 | dprintf. | |
13613 | ||
13614 | dprintf's are implemented with regular commands in their command | |
13615 | list, but we run the commands here instead of before presenting the | |
13616 | stop to the user, as dprintf's don't actually cause a stop. This | |
13617 | also makes it so that the commands of multiple dprintfs at the same | |
13618 | address are all handled. */ | |
13619 | ||
13620 | static void | |
13621 | dprintf_after_condition_true (struct bpstats *bs) | |
13622 | { | |
13623 | struct cleanup *old_chain; | |
13624 | struct bpstats tmp_bs = { NULL }; | |
13625 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13626 | ||
13627 | /* dprintf's never cause a stop. This wasn't set in the | |
13628 | check_status hook instead because that would make the dprintf's | |
13629 | condition not be evaluated. */ | |
13630 | bs->stop = 0; | |
13631 | ||
13632 | /* Run the command list here. Take ownership of it instead of | |
13633 | copying. We never want these commands to run later in | |
13634 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13635 | be set at same address as this dprintf, or even if running the | |
13636 | commands here throws. */ | |
13637 | tmp_bs.commands = bs->commands; | |
13638 | bs->commands = NULL; | |
13639 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13640 | ||
13641 | bpstat_do_actions_1 (&tmp_bs_p); | |
13642 | ||
13643 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13644 | bpstat_do_actions_1 may return early without processing the whole | |
13645 | list. */ | |
13646 | do_cleanups (old_chain); | |
13647 | } | |
13648 | ||
983af33b SDJ |
13649 | /* The breakpoint_ops structure to be used on static tracepoints with |
13650 | markers (`-m'). */ | |
13651 | ||
13652 | static void | |
f00aae0f | 13653 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13654 | struct linespec_result *canonical, |
f00aae0f | 13655 | enum bptype type_wanted) |
983af33b SDJ |
13656 | { |
13657 | struct linespec_sals lsal; | |
f00aae0f KS |
13658 | const char *arg_start, *arg; |
13659 | char *str; | |
13660 | struct cleanup *cleanup; | |
983af33b | 13661 | |
f00aae0f KS |
13662 | arg = arg_start = get_linespec_location (location); |
13663 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13664 | |
f00aae0f KS |
13665 | str = savestring (arg_start, arg - arg_start); |
13666 | cleanup = make_cleanup (xfree, str); | |
ffc2605c | 13667 | canonical->location = new_linespec_location (&str).release (); |
f00aae0f | 13668 | do_cleanups (cleanup); |
983af33b | 13669 | |
f00aae0f | 13670 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13671 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13672 | } | |
13673 | ||
13674 | static void | |
13675 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13676 | struct linespec_result *canonical, | |
983af33b | 13677 | char *cond_string, |
e7e0cddf | 13678 | char *extra_string, |
983af33b SDJ |
13679 | enum bptype type_wanted, |
13680 | enum bpdisp disposition, | |
13681 | int thread, | |
13682 | int task, int ignore_count, | |
13683 | const struct breakpoint_ops *ops, | |
13684 | int from_tty, int enabled, | |
44f238bb | 13685 | int internal, unsigned flags) |
983af33b SDJ |
13686 | { |
13687 | int i; | |
52d361e1 YQ |
13688 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13689 | canonical->sals, 0); | |
983af33b SDJ |
13690 | |
13691 | /* If the user is creating a static tracepoint by marker id | |
13692 | (strace -m MARKER_ID), then store the sals index, so that | |
13693 | breakpoint_re_set can try to match up which of the newly | |
13694 | found markers corresponds to this one, and, don't try to | |
13695 | expand multiple locations for each sal, given than SALS | |
13696 | already should contain all sals for MARKER_ID. */ | |
13697 | ||
13698 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13699 | { | |
13700 | struct symtabs_and_lines expanded; | |
13701 | struct tracepoint *tp; | |
ffc2605c | 13702 | event_location_up location; |
983af33b SDJ |
13703 | |
13704 | expanded.nelts = 1; | |
13705 | expanded.sals = &lsal->sals.sals[i]; | |
13706 | ||
f00aae0f | 13707 | location = copy_event_location (canonical->location); |
983af33b | 13708 | |
4d01a485 | 13709 | tp = new tracepoint (); |
983af33b | 13710 | init_breakpoint_sal (&tp->base, gdbarch, expanded, |
ffc2605c | 13711 | std::move (location), NULL, |
e7e0cddf SS |
13712 | cond_string, extra_string, |
13713 | type_wanted, disposition, | |
983af33b | 13714 | thread, task, ignore_count, ops, |
44f238bb | 13715 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13716 | canonical->special_display); |
13717 | /* Given that its possible to have multiple markers with | |
13718 | the same string id, if the user is creating a static | |
13719 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13720 | store the sals index, so that breakpoint_re_set can | |
13721 | try to match up which of the newly found markers | |
13722 | corresponds to this one */ | |
13723 | tp->static_trace_marker_id_idx = i; | |
13724 | ||
13725 | install_breakpoint (internal, &tp->base, 0); | |
983af33b SDJ |
13726 | } |
13727 | } | |
13728 | ||
13729 | static void | |
f00aae0f KS |
13730 | strace_marker_decode_location (struct breakpoint *b, |
13731 | const struct event_location *location, | |
c2f4122d | 13732 | struct program_space *search_pspace, |
983af33b SDJ |
13733 | struct symtabs_and_lines *sals) |
13734 | { | |
13735 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13736 | const char *s = get_linespec_location (location); |
983af33b | 13737 | |
f00aae0f | 13738 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13739 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13740 | { | |
13741 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13742 | sals->nelts = 1; | |
13743 | } | |
13744 | else | |
13745 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13746 | } | |
13747 | ||
13748 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13749 | ||
13750 | static int | |
13751 | strace_marker_p (struct breakpoint *b) | |
13752 | { | |
13753 | return b->ops == &strace_marker_breakpoint_ops; | |
13754 | } | |
13755 | ||
53a5351d | 13756 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13757 | structures. */ |
c906108c SS |
13758 | |
13759 | void | |
fba45db2 | 13760 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13761 | { |
52f0bd74 | 13762 | struct breakpoint *b; |
c906108c | 13763 | |
8a3fe4f8 | 13764 | gdb_assert (bpt != NULL); |
c906108c | 13765 | |
4a64f543 MS |
13766 | /* Has this bp already been deleted? This can happen because |
13767 | multiple lists can hold pointers to bp's. bpstat lists are | |
13768 | especial culprits. | |
13769 | ||
13770 | One example of this happening is a watchpoint's scope bp. When | |
13771 | the scope bp triggers, we notice that the watchpoint is out of | |
13772 | scope, and delete it. We also delete its scope bp. But the | |
13773 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13774 | That bpstat is then checked for auto-deleting bp's, which are | |
13775 | deleted. | |
13776 | ||
13777 | A real solution to this problem might involve reference counts in | |
13778 | bp's, and/or giving them pointers back to their referencing | |
13779 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13780 | storage when no more references were extent. A cheaper bandaid | |
13781 | was chosen. */ | |
c906108c SS |
13782 | if (bpt->type == bp_none) |
13783 | return; | |
13784 | ||
4a64f543 MS |
13785 | /* At least avoid this stale reference until the reference counting |
13786 | of breakpoints gets resolved. */ | |
d0fb5eae | 13787 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13788 | { |
d0fb5eae | 13789 | struct breakpoint *related; |
3a5c3e22 | 13790 | struct watchpoint *w; |
d0fb5eae JK |
13791 | |
13792 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13793 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13794 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13795 | w = (struct watchpoint *) bpt; |
13796 | else | |
13797 | w = NULL; | |
13798 | if (w != NULL) | |
13799 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13800 | |
13801 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13802 | for (related = bpt; related->related_breakpoint != bpt; | |
13803 | related = related->related_breakpoint); | |
13804 | related->related_breakpoint = bpt->related_breakpoint; | |
13805 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13806 | } |
13807 | ||
a9634178 TJB |
13808 | /* watch_command_1 creates a watchpoint but only sets its number if |
13809 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13810 | a problem in that process, we'll be asked to delete the half-created | |
13811 | watchpoint. In that case, don't announce the deletion. */ | |
13812 | if (bpt->number) | |
13813 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13814 | |
c906108c SS |
13815 | if (breakpoint_chain == bpt) |
13816 | breakpoint_chain = bpt->next; | |
13817 | ||
c906108c SS |
13818 | ALL_BREAKPOINTS (b) |
13819 | if (b->next == bpt) | |
c5aa993b JM |
13820 | { |
13821 | b->next = bpt->next; | |
13822 | break; | |
13823 | } | |
c906108c | 13824 | |
f431efe5 PA |
13825 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13826 | been freed. */ | |
13827 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13828 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13829 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13830 | commands are associated with the bpstat; if we remove it here, | |
13831 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13832 | event-top.c won't do anything, and temporary breakpoints with | |
13833 | commands won't work. */ | |
13834 | ||
13835 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13836 | ||
4a64f543 MS |
13837 | /* Now that breakpoint is removed from breakpoint list, update the |
13838 | global location list. This will remove locations that used to | |
13839 | belong to this breakpoint. Do this before freeing the breakpoint | |
13840 | itself, since remove_breakpoint looks at location's owner. It | |
13841 | might be better design to have location completely | |
13842 | self-contained, but it's not the case now. */ | |
44702360 | 13843 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13844 | |
348d480f | 13845 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13846 | /* On the chance that someone will soon try again to delete this |
13847 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13848 | bpt->type = bp_none; |
4d01a485 | 13849 | delete bpt; |
c906108c SS |
13850 | } |
13851 | ||
4d6140d9 AC |
13852 | static void |
13853 | do_delete_breakpoint_cleanup (void *b) | |
13854 | { | |
9a3c8263 | 13855 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13856 | } |
13857 | ||
13858 | struct cleanup * | |
13859 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13860 | { | |
13861 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13862 | } | |
13863 | ||
51be5b68 PA |
13864 | /* Iterator function to call a user-provided callback function once |
13865 | for each of B and its related breakpoints. */ | |
13866 | ||
13867 | static void | |
13868 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13869 | void (*function) (struct breakpoint *, | |
13870 | void *), | |
13871 | void *data) | |
13872 | { | |
13873 | struct breakpoint *related; | |
13874 | ||
13875 | related = b; | |
13876 | do | |
13877 | { | |
13878 | struct breakpoint *next; | |
13879 | ||
13880 | /* FUNCTION may delete RELATED. */ | |
13881 | next = related->related_breakpoint; | |
13882 | ||
13883 | if (next == related) | |
13884 | { | |
13885 | /* RELATED is the last ring entry. */ | |
13886 | function (related, data); | |
13887 | ||
13888 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13889 | B. There's nothing left to do anyway, so just break | |
13890 | out. */ | |
13891 | break; | |
13892 | } | |
13893 | else | |
13894 | function (related, data); | |
13895 | ||
13896 | related = next; | |
13897 | } | |
13898 | while (related != b); | |
13899 | } | |
95a42b64 TT |
13900 | |
13901 | static void | |
13902 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13903 | { | |
13904 | delete_breakpoint (b); | |
13905 | } | |
13906 | ||
51be5b68 PA |
13907 | /* A callback for map_breakpoint_numbers that calls |
13908 | delete_breakpoint. */ | |
13909 | ||
13910 | static void | |
13911 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13912 | { | |
13913 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13914 | } | |
13915 | ||
c906108c | 13916 | void |
fba45db2 | 13917 | delete_command (char *arg, int from_tty) |
c906108c | 13918 | { |
35df4500 | 13919 | struct breakpoint *b, *b_tmp; |
c906108c | 13920 | |
ea9365bb TT |
13921 | dont_repeat (); |
13922 | ||
c906108c SS |
13923 | if (arg == 0) |
13924 | { | |
13925 | int breaks_to_delete = 0; | |
13926 | ||
46c6471b PA |
13927 | /* Delete all breakpoints if no argument. Do not delete |
13928 | internal breakpoints, these have to be deleted with an | |
13929 | explicit breakpoint number argument. */ | |
c5aa993b | 13930 | ALL_BREAKPOINTS (b) |
46c6471b | 13931 | if (user_breakpoint_p (b)) |
973d738b DJ |
13932 | { |
13933 | breaks_to_delete = 1; | |
13934 | break; | |
13935 | } | |
c906108c SS |
13936 | |
13937 | /* Ask user only if there are some breakpoints to delete. */ | |
13938 | if (!from_tty | |
e2e0b3e5 | 13939 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13940 | { |
35df4500 | 13941 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13942 | if (user_breakpoint_p (b)) |
c5aa993b | 13943 | delete_breakpoint (b); |
c906108c SS |
13944 | } |
13945 | } | |
13946 | else | |
51be5b68 | 13947 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13948 | } |
13949 | ||
c2f4122d PA |
13950 | /* Return true if all locations of B bound to PSPACE are pending. If |
13951 | PSPACE is NULL, all locations of all program spaces are | |
13952 | considered. */ | |
13953 | ||
0d381245 | 13954 | static int |
c2f4122d | 13955 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13956 | { |
c2f4122d PA |
13957 | struct bp_location *loc; |
13958 | ||
13959 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13960 | if ((pspace == NULL | |
13961 | || loc->pspace == pspace) | |
13962 | && !loc->shlib_disabled | |
8645ff69 | 13963 | && !loc->pspace->executing_startup) |
0d381245 VP |
13964 | return 0; |
13965 | return 1; | |
fe3f5fa8 VP |
13966 | } |
13967 | ||
776592bf DE |
13968 | /* Subroutine of update_breakpoint_locations to simplify it. |
13969 | Return non-zero if multiple fns in list LOC have the same name. | |
13970 | Null names are ignored. */ | |
13971 | ||
13972 | static int | |
13973 | ambiguous_names_p (struct bp_location *loc) | |
13974 | { | |
13975 | struct bp_location *l; | |
13976 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13977 | (int (*) (const void *, |
13978 | const void *)) streq, | |
776592bf DE |
13979 | NULL, xcalloc, xfree); |
13980 | ||
13981 | for (l = loc; l != NULL; l = l->next) | |
13982 | { | |
13983 | const char **slot; | |
13984 | const char *name = l->function_name; | |
13985 | ||
13986 | /* Allow for some names to be NULL, ignore them. */ | |
13987 | if (name == NULL) | |
13988 | continue; | |
13989 | ||
13990 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13991 | INSERT); | |
4a64f543 MS |
13992 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13993 | returns NULL. */ | |
776592bf DE |
13994 | if (*slot != NULL) |
13995 | { | |
13996 | htab_delete (htab); | |
13997 | return 1; | |
13998 | } | |
13999 | *slot = name; | |
14000 | } | |
14001 | ||
14002 | htab_delete (htab); | |
14003 | return 0; | |
14004 | } | |
14005 | ||
0fb4aa4b PA |
14006 | /* When symbols change, it probably means the sources changed as well, |
14007 | and it might mean the static tracepoint markers are no longer at | |
14008 | the same address or line numbers they used to be at last we | |
14009 | checked. Losing your static tracepoints whenever you rebuild is | |
14010 | undesirable. This function tries to resync/rematch gdb static | |
14011 | tracepoints with the markers on the target, for static tracepoints | |
14012 | that have not been set by marker id. Static tracepoint that have | |
14013 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14014 | The heuristic is: | |
14015 | ||
14016 | 1) For a tracepoint set at a specific address, look for a marker at | |
14017 | the old PC. If one is found there, assume to be the same marker. | |
14018 | If the name / string id of the marker found is different from the | |
14019 | previous known name, assume that means the user renamed the marker | |
14020 | in the sources, and output a warning. | |
14021 | ||
14022 | 2) For a tracepoint set at a given line number, look for a marker | |
14023 | at the new address of the old line number. If one is found there, | |
14024 | assume to be the same marker. If the name / string id of the | |
14025 | marker found is different from the previous known name, assume that | |
14026 | means the user renamed the marker in the sources, and output a | |
14027 | warning. | |
14028 | ||
14029 | 3) If a marker is no longer found at the same address or line, it | |
14030 | may mean the marker no longer exists. But it may also just mean | |
14031 | the code changed a bit. Maybe the user added a few lines of code | |
14032 | that made the marker move up or down (in line number terms). Ask | |
14033 | the target for info about the marker with the string id as we knew | |
14034 | it. If found, update line number and address in the matching | |
14035 | static tracepoint. This will get confused if there's more than one | |
14036 | marker with the same ID (possible in UST, although unadvised | |
14037 | precisely because it confuses tools). */ | |
14038 | ||
14039 | static struct symtab_and_line | |
14040 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14041 | { | |
d9b3f62e | 14042 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14043 | struct static_tracepoint_marker marker; |
14044 | CORE_ADDR pc; | |
0fb4aa4b PA |
14045 | |
14046 | pc = sal.pc; | |
14047 | if (sal.line) | |
14048 | find_line_pc (sal.symtab, sal.line, &pc); | |
14049 | ||
14050 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14051 | { | |
d9b3f62e | 14052 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14053 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14054 | b->number, | |
d9b3f62e | 14055 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14056 | |
d9b3f62e PA |
14057 | xfree (tp->static_trace_marker_id); |
14058 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14059 | release_static_tracepoint_marker (&marker); |
14060 | ||
14061 | return sal; | |
14062 | } | |
14063 | ||
14064 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14065 | by string ID. */ | |
14066 | if (!sal.explicit_pc | |
14067 | && sal.line != 0 | |
14068 | && sal.symtab != NULL | |
d9b3f62e | 14069 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14070 | { |
14071 | VEC(static_tracepoint_marker_p) *markers; | |
14072 | ||
14073 | markers | |
d9b3f62e | 14074 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14075 | |
14076 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14077 | { | |
80e1d417 | 14078 | struct symtab_and_line sal2; |
0fb4aa4b | 14079 | struct symbol *sym; |
80e1d417 | 14080 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14081 | struct ui_out *uiout = current_uiout; |
67994074 | 14082 | struct explicit_location explicit_loc; |
0fb4aa4b | 14083 | |
80e1d417 | 14084 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14085 | |
d9b3f62e | 14086 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14087 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14088 | |
14089 | warning (_("marker for static tracepoint %d (%s) not " | |
14090 | "found at previous line number"), | |
d9b3f62e | 14091 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14092 | |
80e1d417 | 14093 | init_sal (&sal2); |
0fb4aa4b | 14094 | |
80e1d417 | 14095 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14096 | |
80e1d417 AS |
14097 | sal2 = find_pc_line (tpmarker->address, 0); |
14098 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
112e8700 | 14099 | uiout->text ("Now in "); |
0fb4aa4b PA |
14100 | if (sym) |
14101 | { | |
112e8700 SM |
14102 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
14103 | uiout->text (" at "); | |
0fb4aa4b | 14104 | } |
112e8700 | 14105 | uiout->field_string ("file", |
05cba821 | 14106 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 14107 | uiout->text (":"); |
0fb4aa4b | 14108 | |
112e8700 | 14109 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 14110 | { |
0b0865da | 14111 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14112 | |
112e8700 | 14113 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
14114 | } |
14115 | ||
112e8700 SM |
14116 | uiout->field_int ("line", sal2.line); |
14117 | uiout->text ("\n"); | |
0fb4aa4b | 14118 | |
80e1d417 | 14119 | b->loc->line_number = sal2.line; |
2f202fde | 14120 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14121 | |
f00aae0f | 14122 | delete_event_location (b->location); |
67994074 KS |
14123 | initialize_explicit_location (&explicit_loc); |
14124 | explicit_loc.source_filename | |
00e52e53 | 14125 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14126 | explicit_loc.line_offset.offset = b->loc->line_number; |
14127 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
ffc2605c | 14128 | b->location = new_explicit_location (&explicit_loc).release (); |
0fb4aa4b PA |
14129 | |
14130 | /* Might be nice to check if function changed, and warn if | |
14131 | so. */ | |
14132 | ||
80e1d417 | 14133 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14134 | } |
14135 | } | |
14136 | return sal; | |
14137 | } | |
14138 | ||
8d3788bd VP |
14139 | /* Returns 1 iff locations A and B are sufficiently same that |
14140 | we don't need to report breakpoint as changed. */ | |
14141 | ||
14142 | static int | |
14143 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14144 | { | |
14145 | while (a && b) | |
14146 | { | |
14147 | if (a->address != b->address) | |
14148 | return 0; | |
14149 | ||
14150 | if (a->shlib_disabled != b->shlib_disabled) | |
14151 | return 0; | |
14152 | ||
14153 | if (a->enabled != b->enabled) | |
14154 | return 0; | |
14155 | ||
14156 | a = a->next; | |
14157 | b = b->next; | |
14158 | } | |
14159 | ||
14160 | if ((a == NULL) != (b == NULL)) | |
14161 | return 0; | |
14162 | ||
14163 | return 1; | |
14164 | } | |
14165 | ||
c2f4122d PA |
14166 | /* Split all locations of B that are bound to PSPACE out of B's |
14167 | location list to a separate list and return that list's head. If | |
14168 | PSPACE is NULL, hoist out all locations of B. */ | |
14169 | ||
14170 | static struct bp_location * | |
14171 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14172 | { | |
14173 | struct bp_location head; | |
14174 | struct bp_location *i = b->loc; | |
14175 | struct bp_location **i_link = &b->loc; | |
14176 | struct bp_location *hoisted = &head; | |
14177 | ||
14178 | if (pspace == NULL) | |
14179 | { | |
14180 | i = b->loc; | |
14181 | b->loc = NULL; | |
14182 | return i; | |
14183 | } | |
14184 | ||
14185 | head.next = NULL; | |
14186 | ||
14187 | while (i != NULL) | |
14188 | { | |
14189 | if (i->pspace == pspace) | |
14190 | { | |
14191 | *i_link = i->next; | |
14192 | i->next = NULL; | |
14193 | hoisted->next = i; | |
14194 | hoisted = i; | |
14195 | } | |
14196 | else | |
14197 | i_link = &i->next; | |
14198 | i = *i_link; | |
14199 | } | |
14200 | ||
14201 | return head.next; | |
14202 | } | |
14203 | ||
14204 | /* Create new breakpoint locations for B (a hardware or software | |
14205 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14206 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14207 | FILTER_PSPACE. Locations of other program spaces are left | |
14208 | untouched. */ | |
f1310107 | 14209 | |
0e30163f | 14210 | void |
0d381245 | 14211 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14212 | struct program_space *filter_pspace, |
f1310107 TJB |
14213 | struct symtabs_and_lines sals, |
14214 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14215 | { |
14216 | int i; | |
c2f4122d | 14217 | struct bp_location *existing_locations; |
0d381245 | 14218 | |
f8eba3c6 TT |
14219 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14220 | { | |
14221 | /* Ranged breakpoints have only one start location and one end | |
14222 | location. */ | |
14223 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14224 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14225 | "multiple locations found\n"), | |
14226 | b->number); | |
14227 | return; | |
14228 | } | |
f1310107 | 14229 | |
4a64f543 MS |
14230 | /* If there's no new locations, and all existing locations are |
14231 | pending, don't do anything. This optimizes the common case where | |
14232 | all locations are in the same shared library, that was unloaded. | |
14233 | We'd like to retain the location, so that when the library is | |
14234 | loaded again, we don't loose the enabled/disabled status of the | |
14235 | individual locations. */ | |
c2f4122d | 14236 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14237 | return; |
14238 | ||
c2f4122d | 14239 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14240 | |
0d381245 | 14241 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14242 | { |
f8eba3c6 TT |
14243 | struct bp_location *new_loc; |
14244 | ||
14245 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14246 | ||
14247 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14248 | |
0d381245 VP |
14249 | /* Reparse conditions, they might contain references to the |
14250 | old symtab. */ | |
14251 | if (b->cond_string != NULL) | |
14252 | { | |
bbc13ae3 | 14253 | const char *s; |
fe3f5fa8 | 14254 | |
0d381245 | 14255 | s = b->cond_string; |
492d29ea | 14256 | TRY |
0d381245 | 14257 | { |
1bb9788d TT |
14258 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14259 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14260 | 0); |
14261 | } | |
492d29ea | 14262 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14263 | { |
3e43a32a MS |
14264 | warning (_("failed to reevaluate condition " |
14265 | "for breakpoint %d: %s"), | |
0d381245 VP |
14266 | b->number, e.message); |
14267 | new_loc->enabled = 0; | |
14268 | } | |
492d29ea | 14269 | END_CATCH |
0d381245 | 14270 | } |
fe3f5fa8 | 14271 | |
f1310107 TJB |
14272 | if (sals_end.nelts) |
14273 | { | |
14274 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14275 | ||
14276 | new_loc->length = end - sals.sals[0].pc + 1; | |
14277 | } | |
0d381245 | 14278 | } |
fe3f5fa8 | 14279 | |
4a64f543 MS |
14280 | /* If possible, carry over 'disable' status from existing |
14281 | breakpoints. */ | |
0d381245 VP |
14282 | { |
14283 | struct bp_location *e = existing_locations; | |
776592bf DE |
14284 | /* If there are multiple breakpoints with the same function name, |
14285 | e.g. for inline functions, comparing function names won't work. | |
14286 | Instead compare pc addresses; this is just a heuristic as things | |
14287 | may have moved, but in practice it gives the correct answer | |
14288 | often enough until a better solution is found. */ | |
14289 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14290 | ||
0d381245 VP |
14291 | for (; e; e = e->next) |
14292 | { | |
14293 | if (!e->enabled && e->function_name) | |
14294 | { | |
14295 | struct bp_location *l = b->loc; | |
776592bf DE |
14296 | if (have_ambiguous_names) |
14297 | { | |
14298 | for (; l; l = l->next) | |
f1310107 | 14299 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14300 | { |
14301 | l->enabled = 0; | |
14302 | break; | |
14303 | } | |
14304 | } | |
14305 | else | |
14306 | { | |
14307 | for (; l; l = l->next) | |
14308 | if (l->function_name | |
14309 | && strcmp (e->function_name, l->function_name) == 0) | |
14310 | { | |
14311 | l->enabled = 0; | |
14312 | break; | |
14313 | } | |
14314 | } | |
0d381245 VP |
14315 | } |
14316 | } | |
14317 | } | |
fe3f5fa8 | 14318 | |
8d3788bd VP |
14319 | if (!locations_are_equal (existing_locations, b->loc)) |
14320 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14321 | } |
14322 | ||
f00aae0f | 14323 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14324 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14325 | ||
14326 | static struct symtabs_and_lines | |
f00aae0f | 14327 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14328 | struct program_space *search_pspace, int *found) |
ef23e705 | 14329 | { |
02d20e4a | 14330 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14331 | struct gdb_exception exception = exception_none; |
ef23e705 | 14332 | |
983af33b | 14333 | gdb_assert (b->ops != NULL); |
ef23e705 | 14334 | |
492d29ea | 14335 | TRY |
ef23e705 | 14336 | { |
c2f4122d | 14337 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14338 | } |
492d29ea | 14339 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14340 | { |
14341 | int not_found_and_ok = 0; | |
492d29ea PA |
14342 | |
14343 | exception = e; | |
14344 | ||
ef23e705 TJB |
14345 | /* For pending breakpoints, it's expected that parsing will |
14346 | fail until the right shared library is loaded. User has | |
14347 | already told to create pending breakpoints and don't need | |
14348 | extra messages. If breakpoint is in bp_shlib_disabled | |
14349 | state, then user already saw the message about that | |
14350 | breakpoint being disabled, and don't want to see more | |
14351 | errors. */ | |
58438ac1 | 14352 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14353 | && (b->condition_not_parsed |
14354 | || (b->loc != NULL | |
14355 | && search_pspace != NULL | |
14356 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14357 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14358 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14359 | || b->enable_state == bp_disabled)) |
14360 | not_found_and_ok = 1; | |
14361 | ||
14362 | if (!not_found_and_ok) | |
14363 | { | |
14364 | /* We surely don't want to warn about the same breakpoint | |
14365 | 10 times. One solution, implemented here, is disable | |
14366 | the breakpoint on error. Another solution would be to | |
14367 | have separate 'warning emitted' flag. Since this | |
14368 | happens only when a binary has changed, I don't know | |
14369 | which approach is better. */ | |
14370 | b->enable_state = bp_disabled; | |
14371 | throw_exception (e); | |
14372 | } | |
14373 | } | |
492d29ea | 14374 | END_CATCH |
ef23e705 | 14375 | |
492d29ea | 14376 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14377 | { |
f8eba3c6 | 14378 | int i; |
ef23e705 | 14379 | |
f8eba3c6 TT |
14380 | for (i = 0; i < sals.nelts; ++i) |
14381 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14382 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14383 | { |
ed1d1739 KS |
14384 | char *cond_string, *extra_string; |
14385 | int thread, task; | |
ef23e705 | 14386 | |
f00aae0f | 14387 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14388 | &cond_string, &thread, &task, |
14389 | &extra_string); | |
f00aae0f | 14390 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14391 | if (cond_string) |
14392 | b->cond_string = cond_string; | |
14393 | b->thread = thread; | |
14394 | b->task = task; | |
e7e0cddf | 14395 | if (extra_string) |
f00aae0f KS |
14396 | { |
14397 | xfree (b->extra_string); | |
14398 | b->extra_string = extra_string; | |
14399 | } | |
ef23e705 TJB |
14400 | b->condition_not_parsed = 0; |
14401 | } | |
14402 | ||
983af33b | 14403 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14404 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14405 | |
58438ac1 TT |
14406 | *found = 1; |
14407 | } | |
14408 | else | |
14409 | *found = 0; | |
ef23e705 TJB |
14410 | |
14411 | return sals; | |
14412 | } | |
14413 | ||
348d480f PA |
14414 | /* The default re_set method, for typical hardware or software |
14415 | breakpoints. Reevaluate the breakpoint and recreate its | |
14416 | locations. */ | |
14417 | ||
14418 | static void | |
28010a5d | 14419 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14420 | { |
14421 | int found; | |
f1310107 | 14422 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14423 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14424 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14425 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14426 | |
c2f4122d | 14427 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14428 | if (found) |
14429 | { | |
14430 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14431 | expanded = sals; |
ef23e705 TJB |
14432 | } |
14433 | ||
f00aae0f | 14434 | if (b->location_range_end != NULL) |
f1310107 | 14435 | { |
c2f4122d PA |
14436 | sals_end = location_to_sals (b, b->location_range_end, |
14437 | filter_pspace, &found); | |
f1310107 TJB |
14438 | if (found) |
14439 | { | |
14440 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14441 | expanded_end = sals_end; |
f1310107 TJB |
14442 | } |
14443 | } | |
14444 | ||
c2f4122d | 14445 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14446 | } |
14447 | ||
983af33b SDJ |
14448 | /* Default method for creating SALs from an address string. It basically |
14449 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14450 | ||
14451 | static void | |
f00aae0f KS |
14452 | create_sals_from_location_default (const struct event_location *location, |
14453 | struct linespec_result *canonical, | |
14454 | enum bptype type_wanted) | |
983af33b | 14455 | { |
f00aae0f | 14456 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14457 | } |
14458 | ||
14459 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14460 | function for the `create_breakpoints_sal' method of | |
14461 | breakpoint_ops. */ | |
14462 | ||
14463 | static void | |
14464 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14465 | struct linespec_result *canonical, | |
983af33b | 14466 | char *cond_string, |
e7e0cddf | 14467 | char *extra_string, |
983af33b SDJ |
14468 | enum bptype type_wanted, |
14469 | enum bpdisp disposition, | |
14470 | int thread, | |
14471 | int task, int ignore_count, | |
14472 | const struct breakpoint_ops *ops, | |
14473 | int from_tty, int enabled, | |
44f238bb | 14474 | int internal, unsigned flags) |
983af33b SDJ |
14475 | { |
14476 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14477 | extra_string, |
983af33b SDJ |
14478 | type_wanted, disposition, |
14479 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14480 | enabled, internal, flags); |
983af33b SDJ |
14481 | } |
14482 | ||
14483 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14484 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14485 | |
14486 | static void | |
f00aae0f KS |
14487 | decode_location_default (struct breakpoint *b, |
14488 | const struct event_location *location, | |
c2f4122d | 14489 | struct program_space *search_pspace, |
983af33b SDJ |
14490 | struct symtabs_and_lines *sals) |
14491 | { | |
14492 | struct linespec_result canonical; | |
14493 | ||
14494 | init_linespec_result (&canonical); | |
c2f4122d | 14495 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14496 | (struct symtab *) NULL, 0, |
14497 | &canonical, multiple_symbols_all, | |
14498 | b->filter); | |
14499 | ||
14500 | /* We should get 0 or 1 resulting SALs. */ | |
14501 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14502 | ||
14503 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14504 | { | |
14505 | struct linespec_sals *lsal; | |
14506 | ||
14507 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14508 | *sals = lsal->sals; | |
14509 | /* Arrange it so the destructor does not free the | |
14510 | contents. */ | |
14511 | lsal->sals.sals = NULL; | |
14512 | } | |
14513 | ||
14514 | destroy_linespec_result (&canonical); | |
14515 | } | |
14516 | ||
28010a5d PA |
14517 | /* Prepare the global context for a re-set of breakpoint B. */ |
14518 | ||
14519 | static struct cleanup * | |
14520 | prepare_re_set_context (struct breakpoint *b) | |
14521 | { | |
28010a5d | 14522 | input_radix = b->input_radix; |
28010a5d PA |
14523 | set_language (b->language); |
14524 | ||
c2f4122d | 14525 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14526 | } |
14527 | ||
c906108c SS |
14528 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14529 | The value we return ends up being the return value from catch_errors. | |
14530 | Unused in this case. */ | |
14531 | ||
14532 | static int | |
4efb68b1 | 14533 | breakpoint_re_set_one (void *bint) |
c906108c | 14534 | { |
4a64f543 | 14535 | /* Get past catch_errs. */ |
53a5351d | 14536 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14537 | struct cleanup *cleanups; |
c906108c | 14538 | |
348d480f PA |
14539 | cleanups = prepare_re_set_context (b); |
14540 | b->ops->re_set (b); | |
14541 | do_cleanups (cleanups); | |
c906108c SS |
14542 | return 0; |
14543 | } | |
14544 | ||
c2f4122d PA |
14545 | /* Re-set breakpoint locations for the current program space. |
14546 | Locations bound to other program spaces are left untouched. */ | |
14547 | ||
c906108c | 14548 | void |
69de3c6a | 14549 | breakpoint_re_set (void) |
c906108c | 14550 | { |
35df4500 | 14551 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14552 | enum language save_language; |
14553 | int save_input_radix; | |
6c95b8df | 14554 | struct cleanup *old_chain; |
c5aa993b | 14555 | |
c906108c SS |
14556 | save_language = current_language->la_language; |
14557 | save_input_radix = input_radix; | |
c2f4122d | 14558 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14559 | |
2a7f3dff PA |
14560 | /* Note: we must not try to insert locations until after all |
14561 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14562 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14563 | hadn't been re-set yet, and thus may have stale locations. */ | |
14564 | ||
35df4500 | 14565 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14566 | { |
4a64f543 | 14567 | /* Format possible error msg. */ |
fe3f5fa8 | 14568 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14569 | b->number); |
14570 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14571 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14572 | do_cleanups (cleanups); |
c5aa993b | 14573 | } |
c906108c SS |
14574 | set_language (save_language); |
14575 | input_radix = save_input_radix; | |
e62c965a | 14576 | |
0756c555 | 14577 | jit_breakpoint_re_set (); |
4efc6507 | 14578 | |
6c95b8df PA |
14579 | do_cleanups (old_chain); |
14580 | ||
af02033e PP |
14581 | create_overlay_event_breakpoint (); |
14582 | create_longjmp_master_breakpoint (); | |
14583 | create_std_terminate_master_breakpoint (); | |
186c406b | 14584 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14585 | |
14586 | /* Now we can insert. */ | |
14587 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14588 | } |
14589 | \f | |
c906108c SS |
14590 | /* Reset the thread number of this breakpoint: |
14591 | ||
14592 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14593 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14594 | void |
fba45db2 | 14595 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14596 | { |
14597 | if (b->thread != -1) | |
14598 | { | |
39f77062 | 14599 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14600 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14601 | |
14602 | /* We're being called after following a fork. The new fork is | |
14603 | selected as current, and unless this was a vfork will have a | |
14604 | different program space from the original thread. Reset that | |
14605 | as well. */ | |
14606 | b->loc->pspace = current_program_space; | |
c906108c SS |
14607 | } |
14608 | } | |
14609 | ||
03ac34d5 MS |
14610 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14611 | If from_tty is nonzero, it prints a message to that effect, | |
14612 | which ends with a period (no newline). */ | |
14613 | ||
c906108c | 14614 | void |
fba45db2 | 14615 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14616 | { |
52f0bd74 | 14617 | struct breakpoint *b; |
c906108c SS |
14618 | |
14619 | if (count < 0) | |
14620 | count = 0; | |
14621 | ||
14622 | ALL_BREAKPOINTS (b) | |
14623 | if (b->number == bptnum) | |
c5aa993b | 14624 | { |
d77f58be SS |
14625 | if (is_tracepoint (b)) |
14626 | { | |
14627 | if (from_tty && count != 0) | |
14628 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14629 | bptnum); | |
14630 | return; | |
14631 | } | |
14632 | ||
c5aa993b | 14633 | b->ignore_count = count; |
221ea385 KS |
14634 | if (from_tty) |
14635 | { | |
14636 | if (count == 0) | |
3e43a32a MS |
14637 | printf_filtered (_("Will stop next time " |
14638 | "breakpoint %d is reached."), | |
221ea385 KS |
14639 | bptnum); |
14640 | else if (count == 1) | |
a3f17187 | 14641 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14642 | bptnum); |
14643 | else | |
3e43a32a MS |
14644 | printf_filtered (_("Will ignore next %d " |
14645 | "crossings of breakpoint %d."), | |
221ea385 KS |
14646 | count, bptnum); |
14647 | } | |
8d3788bd | 14648 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14649 | return; |
14650 | } | |
c906108c | 14651 | |
8a3fe4f8 | 14652 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14653 | } |
14654 | ||
c906108c SS |
14655 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14656 | ||
14657 | static void | |
fba45db2 | 14658 | ignore_command (char *args, int from_tty) |
c906108c SS |
14659 | { |
14660 | char *p = args; | |
52f0bd74 | 14661 | int num; |
c906108c SS |
14662 | |
14663 | if (p == 0) | |
e2e0b3e5 | 14664 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14665 | |
c906108c | 14666 | num = get_number (&p); |
5c44784c | 14667 | if (num == 0) |
8a3fe4f8 | 14668 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14669 | if (*p == 0) |
8a3fe4f8 | 14670 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14671 | |
14672 | set_ignore_count (num, | |
14673 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14674 | from_tty); | |
221ea385 KS |
14675 | if (from_tty) |
14676 | printf_filtered ("\n"); | |
c906108c SS |
14677 | } |
14678 | \f | |
14679 | /* Call FUNCTION on each of the breakpoints | |
14680 | whose numbers are given in ARGS. */ | |
14681 | ||
14682 | static void | |
896b6bda PA |
14683 | map_breakpoint_numbers (const char *args, |
14684 | void (*function) (struct breakpoint *, | |
14685 | void *), | |
95a42b64 | 14686 | void *data) |
c906108c | 14687 | { |
52f0bd74 AC |
14688 | int num; |
14689 | struct breakpoint *b, *tmp; | |
c906108c | 14690 | |
b9d61307 | 14691 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14692 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14693 | |
bfd28288 | 14694 | number_or_range_parser parser (args); |
197f0a60 | 14695 | |
bfd28288 | 14696 | while (!parser.finished ()) |
c906108c | 14697 | { |
bfd28288 PA |
14698 | const char *p = parser.cur_tok (); |
14699 | bool match = false; | |
197f0a60 | 14700 | |
bfd28288 | 14701 | num = parser.get_number (); |
5c44784c | 14702 | if (num == 0) |
c5aa993b | 14703 | { |
8a3fe4f8 | 14704 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14705 | } |
14706 | else | |
14707 | { | |
14708 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14709 | if (b->number == num) | |
14710 | { | |
bfd28288 | 14711 | match = true; |
cdac0397 | 14712 | function (b, data); |
11cf8741 | 14713 | break; |
5c44784c | 14714 | } |
bfd28288 | 14715 | if (!match) |
a3f17187 | 14716 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14717 | } |
c906108c SS |
14718 | } |
14719 | } | |
14720 | ||
0d381245 VP |
14721 | static struct bp_location * |
14722 | find_location_by_number (char *number) | |
14723 | { | |
14724 | char *dot = strchr (number, '.'); | |
14725 | char *p1; | |
14726 | int bp_num; | |
14727 | int loc_num; | |
14728 | struct breakpoint *b; | |
14729 | struct bp_location *loc; | |
14730 | ||
14731 | *dot = '\0'; | |
14732 | ||
14733 | p1 = number; | |
197f0a60 | 14734 | bp_num = get_number (&p1); |
0d381245 VP |
14735 | if (bp_num == 0) |
14736 | error (_("Bad breakpoint number '%s'"), number); | |
14737 | ||
14738 | ALL_BREAKPOINTS (b) | |
14739 | if (b->number == bp_num) | |
14740 | { | |
14741 | break; | |
14742 | } | |
14743 | ||
14744 | if (!b || b->number != bp_num) | |
14745 | error (_("Bad breakpoint number '%s'"), number); | |
14746 | ||
14747 | p1 = dot+1; | |
197f0a60 | 14748 | loc_num = get_number (&p1); |
0d381245 VP |
14749 | if (loc_num == 0) |
14750 | error (_("Bad breakpoint location number '%s'"), number); | |
14751 | ||
14752 | --loc_num; | |
14753 | loc = b->loc; | |
14754 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14755 | ; | |
14756 | if (!loc) | |
14757 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14758 | ||
14759 | return loc; | |
14760 | } | |
14761 | ||
14762 | ||
1900040c MS |
14763 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14764 | If from_tty is nonzero, it prints a message to that effect, | |
14765 | which ends with a period (no newline). */ | |
14766 | ||
c906108c | 14767 | void |
fba45db2 | 14768 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14769 | { |
14770 | /* Never disable a watchpoint scope breakpoint; we want to | |
14771 | hit them when we leave scope so we can delete both the | |
14772 | watchpoint and its scope breakpoint at that time. */ | |
14773 | if (bpt->type == bp_watchpoint_scope) | |
14774 | return; | |
14775 | ||
b5de0fa7 | 14776 | bpt->enable_state = bp_disabled; |
c906108c | 14777 | |
b775012e LM |
14778 | /* Mark breakpoint locations modified. */ |
14779 | mark_breakpoint_modified (bpt); | |
14780 | ||
d248b706 KY |
14781 | if (target_supports_enable_disable_tracepoint () |
14782 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14783 | { | |
14784 | struct bp_location *location; | |
14785 | ||
14786 | for (location = bpt->loc; location; location = location->next) | |
14787 | target_disable_tracepoint (location); | |
14788 | } | |
14789 | ||
44702360 | 14790 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14791 | |
8d3788bd | 14792 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14793 | } |
14794 | ||
51be5b68 PA |
14795 | /* A callback for iterate_over_related_breakpoints. */ |
14796 | ||
14797 | static void | |
14798 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14799 | { | |
14800 | disable_breakpoint (b); | |
14801 | } | |
14802 | ||
95a42b64 TT |
14803 | /* A callback for map_breakpoint_numbers that calls |
14804 | disable_breakpoint. */ | |
14805 | ||
14806 | static void | |
14807 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14808 | { | |
51be5b68 | 14809 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14810 | } |
14811 | ||
c906108c | 14812 | static void |
fba45db2 | 14813 | disable_command (char *args, int from_tty) |
c906108c | 14814 | { |
c906108c | 14815 | if (args == 0) |
46c6471b PA |
14816 | { |
14817 | struct breakpoint *bpt; | |
14818 | ||
14819 | ALL_BREAKPOINTS (bpt) | |
14820 | if (user_breakpoint_p (bpt)) | |
14821 | disable_breakpoint (bpt); | |
14822 | } | |
9eaabc75 | 14823 | else |
0d381245 | 14824 | { |
9eaabc75 MW |
14825 | char *num = extract_arg (&args); |
14826 | ||
14827 | while (num) | |
d248b706 | 14828 | { |
9eaabc75 | 14829 | if (strchr (num, '.')) |
b775012e | 14830 | { |
9eaabc75 MW |
14831 | struct bp_location *loc = find_location_by_number (num); |
14832 | ||
14833 | if (loc) | |
14834 | { | |
14835 | if (loc->enabled) | |
14836 | { | |
14837 | loc->enabled = 0; | |
14838 | mark_breakpoint_location_modified (loc); | |
14839 | } | |
14840 | if (target_supports_enable_disable_tracepoint () | |
14841 | && current_trace_status ()->running && loc->owner | |
14842 | && is_tracepoint (loc->owner)) | |
14843 | target_disable_tracepoint (loc); | |
14844 | } | |
44702360 | 14845 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14846 | } |
9eaabc75 MW |
14847 | else |
14848 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14849 | num = extract_arg (&args); | |
d248b706 | 14850 | } |
0d381245 | 14851 | } |
c906108c SS |
14852 | } |
14853 | ||
14854 | static void | |
816338b5 SS |
14855 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14856 | int count) | |
c906108c | 14857 | { |
afe38095 | 14858 | int target_resources_ok; |
c906108c SS |
14859 | |
14860 | if (bpt->type == bp_hardware_breakpoint) | |
14861 | { | |
14862 | int i; | |
c5aa993b | 14863 | i = hw_breakpoint_used_count (); |
53a5351d | 14864 | target_resources_ok = |
d92524f1 | 14865 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14866 | i + 1, 0); |
c906108c | 14867 | if (target_resources_ok == 0) |
8a3fe4f8 | 14868 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14869 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14870 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14871 | } |
14872 | ||
cc60f2e3 | 14873 | if (is_watchpoint (bpt)) |
c906108c | 14874 | { |
d07205c2 | 14875 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14876 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14877 | |
492d29ea | 14878 | TRY |
c906108c | 14879 | { |
3a5c3e22 PA |
14880 | struct watchpoint *w = (struct watchpoint *) bpt; |
14881 | ||
1e718ff1 TJB |
14882 | orig_enable_state = bpt->enable_state; |
14883 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14884 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14885 | } |
492d29ea | 14886 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14887 | { |
1e718ff1 | 14888 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14889 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14890 | bpt->number); | |
14891 | return; | |
c5aa993b | 14892 | } |
492d29ea | 14893 | END_CATCH |
c906108c | 14894 | } |
0101ce28 | 14895 | |
b775012e LM |
14896 | bpt->enable_state = bp_enabled; |
14897 | ||
14898 | /* Mark breakpoint locations modified. */ | |
14899 | mark_breakpoint_modified (bpt); | |
14900 | ||
d248b706 KY |
14901 | if (target_supports_enable_disable_tracepoint () |
14902 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14903 | { | |
14904 | struct bp_location *location; | |
14905 | ||
14906 | for (location = bpt->loc; location; location = location->next) | |
14907 | target_enable_tracepoint (location); | |
14908 | } | |
14909 | ||
b4c291bb | 14910 | bpt->disposition = disposition; |
816338b5 | 14911 | bpt->enable_count = count; |
44702360 | 14912 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14913 | |
8d3788bd | 14914 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14915 | } |
14916 | ||
fe3f5fa8 | 14917 | |
c906108c | 14918 | void |
fba45db2 | 14919 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14920 | { |
816338b5 | 14921 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14922 | } |
14923 | ||
14924 | static void | |
14925 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14926 | { | |
14927 | enable_breakpoint (bpt); | |
c906108c SS |
14928 | } |
14929 | ||
95a42b64 TT |
14930 | /* A callback for map_breakpoint_numbers that calls |
14931 | enable_breakpoint. */ | |
14932 | ||
14933 | static void | |
14934 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14935 | { | |
51be5b68 | 14936 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14937 | } |
14938 | ||
c906108c SS |
14939 | /* The enable command enables the specified breakpoints (or all defined |
14940 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14941 | in stopping the inferior. */ |
c906108c | 14942 | |
c906108c | 14943 | static void |
fba45db2 | 14944 | enable_command (char *args, int from_tty) |
c906108c | 14945 | { |
c906108c | 14946 | if (args == 0) |
46c6471b PA |
14947 | { |
14948 | struct breakpoint *bpt; | |
14949 | ||
14950 | ALL_BREAKPOINTS (bpt) | |
14951 | if (user_breakpoint_p (bpt)) | |
14952 | enable_breakpoint (bpt); | |
14953 | } | |
9eaabc75 | 14954 | else |
0d381245 | 14955 | { |
9eaabc75 MW |
14956 | char *num = extract_arg (&args); |
14957 | ||
14958 | while (num) | |
d248b706 | 14959 | { |
9eaabc75 | 14960 | if (strchr (num, '.')) |
b775012e | 14961 | { |
9eaabc75 MW |
14962 | struct bp_location *loc = find_location_by_number (num); |
14963 | ||
14964 | if (loc) | |
14965 | { | |
14966 | if (!loc->enabled) | |
14967 | { | |
14968 | loc->enabled = 1; | |
14969 | mark_breakpoint_location_modified (loc); | |
14970 | } | |
14971 | if (target_supports_enable_disable_tracepoint () | |
14972 | && current_trace_status ()->running && loc->owner | |
14973 | && is_tracepoint (loc->owner)) | |
14974 | target_enable_tracepoint (loc); | |
14975 | } | |
44702360 | 14976 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14977 | } |
9eaabc75 MW |
14978 | else |
14979 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14980 | num = extract_arg (&args); | |
d248b706 | 14981 | } |
0d381245 | 14982 | } |
c906108c SS |
14983 | } |
14984 | ||
816338b5 SS |
14985 | /* This struct packages up disposition data for application to multiple |
14986 | breakpoints. */ | |
14987 | ||
14988 | struct disp_data | |
14989 | { | |
14990 | enum bpdisp disp; | |
14991 | int count; | |
14992 | }; | |
14993 | ||
c906108c | 14994 | static void |
51be5b68 PA |
14995 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14996 | { | |
816338b5 | 14997 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14998 | |
816338b5 | 14999 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15000 | } |
15001 | ||
15002 | static void | |
15003 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15004 | { |
816338b5 | 15005 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15006 | |
15007 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15008 | } |
15009 | ||
c906108c | 15010 | static void |
fba45db2 | 15011 | enable_once_command (char *args, int from_tty) |
c906108c | 15012 | { |
51be5b68 | 15013 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15014 | } |
15015 | ||
816338b5 SS |
15016 | static void |
15017 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15018 | { | |
15019 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15020 | ||
15021 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15022 | } | |
15023 | ||
15024 | static void | |
15025 | enable_count_command (char *args, int from_tty) | |
15026 | { | |
b9d61307 SM |
15027 | int count; |
15028 | ||
15029 | if (args == NULL) | |
15030 | error_no_arg (_("hit count")); | |
15031 | ||
15032 | count = get_number (&args); | |
816338b5 SS |
15033 | |
15034 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15035 | } | |
15036 | ||
c906108c | 15037 | static void |
51be5b68 | 15038 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15039 | { |
816338b5 | 15040 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15041 | |
15042 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15043 | } |
15044 | ||
c906108c | 15045 | static void |
fba45db2 | 15046 | enable_delete_command (char *args, int from_tty) |
c906108c | 15047 | { |
51be5b68 | 15048 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15049 | } |
15050 | \f | |
fa8d40ab JJ |
15051 | static void |
15052 | set_breakpoint_cmd (char *args, int from_tty) | |
15053 | { | |
15054 | } | |
15055 | ||
15056 | static void | |
15057 | show_breakpoint_cmd (char *args, int from_tty) | |
15058 | { | |
15059 | } | |
15060 | ||
1f3b5d1b PP |
15061 | /* Invalidate last known value of any hardware watchpoint if |
15062 | the memory which that value represents has been written to by | |
15063 | GDB itself. */ | |
15064 | ||
15065 | static void | |
8de0566d YQ |
15066 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15067 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15068 | const bfd_byte *data) |
15069 | { | |
15070 | struct breakpoint *bp; | |
15071 | ||
15072 | ALL_BREAKPOINTS (bp) | |
15073 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15074 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15075 | { |
3a5c3e22 | 15076 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15077 | |
3a5c3e22 PA |
15078 | if (wp->val_valid && wp->val) |
15079 | { | |
15080 | struct bp_location *loc; | |
15081 | ||
15082 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15083 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15084 | && loc->address + loc->length > addr | |
15085 | && addr + len > loc->address) | |
15086 | { | |
15087 | value_free (wp->val); | |
15088 | wp->val = NULL; | |
15089 | wp->val_valid = 0; | |
15090 | } | |
15091 | } | |
1f3b5d1b PP |
15092 | } |
15093 | } | |
15094 | ||
8181d85f DJ |
15095 | /* Create and insert a breakpoint for software single step. */ |
15096 | ||
15097 | void | |
6c95b8df | 15098 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15099 | struct address_space *aspace, |
15100 | CORE_ADDR next_pc) | |
8181d85f | 15101 | { |
7c16b83e PA |
15102 | struct thread_info *tp = inferior_thread (); |
15103 | struct symtab_and_line sal; | |
15104 | CORE_ADDR pc = next_pc; | |
8181d85f | 15105 | |
34b7e8a6 PA |
15106 | if (tp->control.single_step_breakpoints == NULL) |
15107 | { | |
15108 | tp->control.single_step_breakpoints | |
5d5658a1 | 15109 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15110 | } |
8181d85f | 15111 | |
7c16b83e PA |
15112 | sal = find_pc_line (pc, 0); |
15113 | sal.pc = pc; | |
15114 | sal.section = find_pc_overlay (pc); | |
15115 | sal.explicit_pc = 1; | |
34b7e8a6 | 15116 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15117 | |
7c16b83e | 15118 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15119 | } |
15120 | ||
93f9a11f YQ |
15121 | /* Insert single step breakpoints according to the current state. */ |
15122 | ||
15123 | int | |
15124 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
15125 | { | |
f5ea389a | 15126 | struct regcache *regcache = get_current_regcache (); |
93f9a11f YQ |
15127 | VEC (CORE_ADDR) * next_pcs; |
15128 | ||
f5ea389a | 15129 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f YQ |
15130 | |
15131 | if (next_pcs != NULL) | |
15132 | { | |
15133 | int i; | |
15134 | CORE_ADDR pc; | |
f5ea389a | 15135 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
15136 | struct address_space *aspace = get_frame_address_space (frame); |
15137 | ||
15138 | for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++) | |
15139 | insert_single_step_breakpoint (gdbarch, aspace, pc); | |
15140 | ||
15141 | VEC_free (CORE_ADDR, next_pcs); | |
15142 | ||
15143 | return 1; | |
15144 | } | |
15145 | else | |
15146 | return 0; | |
15147 | } | |
15148 | ||
34b7e8a6 | 15149 | /* See breakpoint.h. */ |
f02253f1 HZ |
15150 | |
15151 | int | |
7c16b83e PA |
15152 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15153 | struct address_space *aspace, | |
15154 | CORE_ADDR pc) | |
1aafd4da | 15155 | { |
7c16b83e | 15156 | struct bp_location *loc; |
1aafd4da | 15157 | |
7c16b83e PA |
15158 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15159 | if (loc->inserted | |
15160 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15161 | return 1; | |
1aafd4da | 15162 | |
7c16b83e | 15163 | return 0; |
ef370185 JB |
15164 | } |
15165 | ||
15166 | /* Check whether a software single-step breakpoint is inserted at | |
15167 | PC. */ | |
15168 | ||
15169 | int | |
15170 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15171 | CORE_ADDR pc) | |
15172 | { | |
34b7e8a6 PA |
15173 | struct breakpoint *bpt; |
15174 | ||
15175 | ALL_BREAKPOINTS (bpt) | |
15176 | { | |
15177 | if (bpt->type == bp_single_step | |
15178 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15179 | return 1; | |
15180 | } | |
15181 | return 0; | |
1aafd4da UW |
15182 | } |
15183 | ||
1042e4c0 SS |
15184 | /* Tracepoint-specific operations. */ |
15185 | ||
15186 | /* Set tracepoint count to NUM. */ | |
15187 | static void | |
15188 | set_tracepoint_count (int num) | |
15189 | { | |
15190 | tracepoint_count = num; | |
4fa62494 | 15191 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15192 | } |
15193 | ||
70221824 | 15194 | static void |
1042e4c0 SS |
15195 | trace_command (char *arg, int from_tty) |
15196 | { | |
55aa24fb | 15197 | struct breakpoint_ops *ops; |
55aa24fb | 15198 | |
ffc2605c TT |
15199 | event_location_up location = string_to_event_location (&arg, |
15200 | current_language); | |
5b56227b | 15201 | if (location != NULL |
ffc2605c | 15202 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
15203 | ops = &tracepoint_probe_breakpoint_ops; |
15204 | else | |
15205 | ops = &tracepoint_breakpoint_ops; | |
15206 | ||
558a9d82 | 15207 | create_breakpoint (get_current_arch (), |
ffc2605c | 15208 | location.get (), |
f00aae0f | 15209 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15210 | 0 /* tempflag */, |
15211 | bp_tracepoint /* type_wanted */, | |
15212 | 0 /* Ignore count */, | |
15213 | pending_break_support, | |
15214 | ops, | |
15215 | from_tty, | |
15216 | 1 /* enabled */, | |
15217 | 0 /* internal */, 0); | |
1042e4c0 SS |
15218 | } |
15219 | ||
70221824 | 15220 | static void |
7a697b8d SS |
15221 | ftrace_command (char *arg, int from_tty) |
15222 | { | |
ffc2605c TT |
15223 | event_location_up location = string_to_event_location (&arg, |
15224 | current_language); | |
558a9d82 | 15225 | create_breakpoint (get_current_arch (), |
ffc2605c | 15226 | location.get (), |
f00aae0f | 15227 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15228 | 0 /* tempflag */, |
15229 | bp_fast_tracepoint /* type_wanted */, | |
15230 | 0 /* Ignore count */, | |
15231 | pending_break_support, | |
15232 | &tracepoint_breakpoint_ops, | |
15233 | from_tty, | |
15234 | 1 /* enabled */, | |
15235 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15236 | } |
15237 | ||
15238 | /* strace command implementation. Creates a static tracepoint. */ | |
15239 | ||
70221824 | 15240 | static void |
0fb4aa4b PA |
15241 | strace_command (char *arg, int from_tty) |
15242 | { | |
983af33b | 15243 | struct breakpoint_ops *ops; |
ffc2605c | 15244 | event_location_up location; |
f00aae0f | 15245 | struct cleanup *back_to; |
983af33b SDJ |
15246 | |
15247 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15248 | or with a normal static tracepoint. */ | |
61012eef | 15249 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15250 | { |
15251 | ops = &strace_marker_breakpoint_ops; | |
15252 | location = new_linespec_location (&arg); | |
15253 | } | |
983af33b | 15254 | else |
f00aae0f KS |
15255 | { |
15256 | ops = &tracepoint_breakpoint_ops; | |
15257 | location = string_to_event_location (&arg, current_language); | |
15258 | } | |
983af33b | 15259 | |
558a9d82 | 15260 | create_breakpoint (get_current_arch (), |
ffc2605c | 15261 | location.get (), |
f00aae0f | 15262 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15263 | 0 /* tempflag */, |
15264 | bp_static_tracepoint /* type_wanted */, | |
15265 | 0 /* Ignore count */, | |
15266 | pending_break_support, | |
15267 | ops, | |
15268 | from_tty, | |
15269 | 1 /* enabled */, | |
15270 | 0 /* internal */, 0); | |
7a697b8d SS |
15271 | } |
15272 | ||
409873ef SS |
15273 | /* Set up a fake reader function that gets command lines from a linked |
15274 | list that was acquired during tracepoint uploading. */ | |
15275 | ||
15276 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15277 | static int next_cmd; |
409873ef SS |
15278 | |
15279 | static char * | |
15280 | read_uploaded_action (void) | |
15281 | { | |
15282 | char *rslt; | |
15283 | ||
3149d8c1 | 15284 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15285 | |
3149d8c1 | 15286 | next_cmd++; |
409873ef SS |
15287 | |
15288 | return rslt; | |
15289 | } | |
15290 | ||
00bf0b85 SS |
15291 | /* Given information about a tracepoint as recorded on a target (which |
15292 | can be either a live system or a trace file), attempt to create an | |
15293 | equivalent GDB tracepoint. This is not a reliable process, since | |
15294 | the target does not necessarily have all the information used when | |
15295 | the tracepoint was originally defined. */ | |
15296 | ||
d9b3f62e | 15297 | struct tracepoint * |
00bf0b85 | 15298 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15299 | { |
409873ef | 15300 | char *addr_str, small_buf[100]; |
d9b3f62e | 15301 | struct tracepoint *tp; |
fd9b8c24 | 15302 | |
409873ef SS |
15303 | if (utp->at_string) |
15304 | addr_str = utp->at_string; | |
15305 | else | |
15306 | { | |
15307 | /* In the absence of a source location, fall back to raw | |
15308 | address. Since there is no way to confirm that the address | |
15309 | means the same thing as when the trace was started, warn the | |
15310 | user. */ | |
3e43a32a MS |
15311 | warning (_("Uploaded tracepoint %d has no " |
15312 | "source location, using raw address"), | |
409873ef | 15313 | utp->number); |
8c042590 | 15314 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15315 | addr_str = small_buf; |
15316 | } | |
15317 | ||
15318 | /* There's not much we can do with a sequence of bytecodes. */ | |
15319 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15320 | warning (_("Uploaded tracepoint %d condition " |
15321 | "has no source form, ignoring it"), | |
409873ef | 15322 | utp->number); |
d5551862 | 15323 | |
ffc2605c TT |
15324 | event_location_up location = string_to_event_location (&addr_str, |
15325 | current_language); | |
8cdf0e15 | 15326 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 15327 | location.get (), |
f00aae0f | 15328 | utp->cond_string, -1, addr_str, |
e7e0cddf | 15329 | 0 /* parse cond/thread */, |
8cdf0e15 | 15330 | 0 /* tempflag */, |
0fb4aa4b | 15331 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15332 | 0 /* Ignore count */, |
15333 | pending_break_support, | |
348d480f | 15334 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15335 | 0 /* from_tty */, |
84f4c1fe | 15336 | utp->enabled /* enabled */, |
44f238bb PA |
15337 | 0 /* internal */, |
15338 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 15339 | return NULL; |
fd9b8c24 | 15340 | |
409873ef | 15341 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15342 | tp = get_tracepoint (tracepoint_count); |
15343 | gdb_assert (tp != NULL); | |
d5551862 | 15344 | |
00bf0b85 SS |
15345 | if (utp->pass > 0) |
15346 | { | |
8c042590 PM |
15347 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15348 | tp->base.number); | |
00bf0b85 | 15349 | |
409873ef | 15350 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15351 | } |
15352 | ||
409873ef SS |
15353 | /* If we have uploaded versions of the original commands, set up a |
15354 | special-purpose "reader" function and call the usual command line | |
15355 | reader, then pass the result to the breakpoint command-setting | |
15356 | function. */ | |
3149d8c1 | 15357 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15358 | { |
93921405 | 15359 | command_line_up cmd_list; |
00bf0b85 | 15360 | |
409873ef | 15361 | this_utp = utp; |
3149d8c1 | 15362 | next_cmd = 0; |
d5551862 | 15363 | |
409873ef SS |
15364 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15365 | ||
93921405 | 15366 | breakpoint_set_commands (&tp->base, std::move (cmd_list)); |
00bf0b85 | 15367 | } |
3149d8c1 SS |
15368 | else if (!VEC_empty (char_ptr, utp->actions) |
15369 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15370 | warning (_("Uploaded tracepoint %d actions " |
15371 | "have no source form, ignoring them"), | |
409873ef | 15372 | utp->number); |
00bf0b85 | 15373 | |
f196051f SS |
15374 | /* Copy any status information that might be available. */ |
15375 | tp->base.hit_count = utp->hit_count; | |
15376 | tp->traceframe_usage = utp->traceframe_usage; | |
15377 | ||
00bf0b85 | 15378 | return tp; |
d9b3f62e | 15379 | } |
00bf0b85 | 15380 | |
1042e4c0 SS |
15381 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15382 | omitted. */ | |
15383 | ||
15384 | static void | |
e5a67952 | 15385 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15386 | { |
79a45e25 | 15387 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15388 | int num_printed; |
1042e4c0 | 15389 | |
e5a67952 | 15390 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15391 | |
15392 | if (num_printed == 0) | |
1042e4c0 | 15393 | { |
e5a67952 | 15394 | if (args == NULL || *args == '\0') |
112e8700 | 15395 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15396 | else |
112e8700 | 15397 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15398 | } |
ad443146 SS |
15399 | |
15400 | default_collect_info (); | |
1042e4c0 SS |
15401 | } |
15402 | ||
4a64f543 | 15403 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15404 | Not supported by all targets. */ |
15405 | static void | |
15406 | enable_trace_command (char *args, int from_tty) | |
15407 | { | |
15408 | enable_command (args, from_tty); | |
15409 | } | |
15410 | ||
4a64f543 | 15411 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15412 | Not supported by all targets. */ |
15413 | static void | |
15414 | disable_trace_command (char *args, int from_tty) | |
15415 | { | |
15416 | disable_command (args, from_tty); | |
15417 | } | |
15418 | ||
4a64f543 | 15419 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15420 | static void |
15421 | delete_trace_command (char *arg, int from_tty) | |
15422 | { | |
35df4500 | 15423 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15424 | |
15425 | dont_repeat (); | |
15426 | ||
15427 | if (arg == 0) | |
15428 | { | |
15429 | int breaks_to_delete = 0; | |
15430 | ||
15431 | /* Delete all breakpoints if no argument. | |
15432 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15433 | have to be deleted with an explicit breakpoint number |
15434 | argument. */ | |
1042e4c0 | 15435 | ALL_TRACEPOINTS (b) |
46c6471b | 15436 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15437 | { |
15438 | breaks_to_delete = 1; | |
15439 | break; | |
15440 | } | |
1042e4c0 SS |
15441 | |
15442 | /* Ask user only if there are some breakpoints to delete. */ | |
15443 | if (!from_tty | |
15444 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15445 | { | |
35df4500 | 15446 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15447 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15448 | delete_breakpoint (b); |
1042e4c0 SS |
15449 | } |
15450 | } | |
15451 | else | |
51be5b68 | 15452 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15453 | } |
15454 | ||
197f0a60 TT |
15455 | /* Helper function for trace_pass_command. */ |
15456 | ||
15457 | static void | |
d9b3f62e | 15458 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15459 | { |
d9b3f62e | 15460 | tp->pass_count = count; |
6f6484cd | 15461 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15462 | if (from_tty) |
15463 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15464 | tp->base.number, count); |
197f0a60 TT |
15465 | } |
15466 | ||
1042e4c0 SS |
15467 | /* Set passcount for tracepoint. |
15468 | ||
15469 | First command argument is passcount, second is tracepoint number. | |
15470 | If tracepoint number omitted, apply to most recently defined. | |
15471 | Also accepts special argument "all". */ | |
15472 | ||
15473 | static void | |
15474 | trace_pass_command (char *args, int from_tty) | |
15475 | { | |
d9b3f62e | 15476 | struct tracepoint *t1; |
1042e4c0 | 15477 | unsigned int count; |
1042e4c0 SS |
15478 | |
15479 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15480 | error (_("passcount command requires an " |
15481 | "argument (count + optional TP num)")); | |
1042e4c0 | 15482 | |
4a64f543 | 15483 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15484 | |
529480d0 | 15485 | args = skip_spaces (args); |
1042e4c0 SS |
15486 | if (*args && strncasecmp (args, "all", 3) == 0) |
15487 | { | |
d9b3f62e PA |
15488 | struct breakpoint *b; |
15489 | ||
1042e4c0 | 15490 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15491 | if (*args) |
15492 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15493 | |
d9b3f62e | 15494 | ALL_TRACEPOINTS (b) |
197f0a60 | 15495 | { |
d9b3f62e | 15496 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15497 | trace_pass_set_count (t1, count, from_tty); |
15498 | } | |
15499 | } | |
15500 | else if (*args == '\0') | |
1042e4c0 | 15501 | { |
5fa1d40e | 15502 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15503 | if (t1) |
197f0a60 TT |
15504 | trace_pass_set_count (t1, count, from_tty); |
15505 | } | |
15506 | else | |
15507 | { | |
bfd28288 PA |
15508 | number_or_range_parser parser (args); |
15509 | while (!parser.finished ()) | |
1042e4c0 | 15510 | { |
bfd28288 | 15511 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15512 | if (t1) |
15513 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15514 | } |
15515 | } | |
1042e4c0 SS |
15516 | } |
15517 | ||
d9b3f62e | 15518 | struct tracepoint * |
1042e4c0 SS |
15519 | get_tracepoint (int num) |
15520 | { | |
15521 | struct breakpoint *t; | |
15522 | ||
15523 | ALL_TRACEPOINTS (t) | |
15524 | if (t->number == num) | |
d9b3f62e | 15525 | return (struct tracepoint *) t; |
1042e4c0 SS |
15526 | |
15527 | return NULL; | |
15528 | } | |
15529 | ||
d5551862 SS |
15530 | /* Find the tracepoint with the given target-side number (which may be |
15531 | different from the tracepoint number after disconnecting and | |
15532 | reconnecting). */ | |
15533 | ||
d9b3f62e | 15534 | struct tracepoint * |
d5551862 SS |
15535 | get_tracepoint_by_number_on_target (int num) |
15536 | { | |
d9b3f62e | 15537 | struct breakpoint *b; |
d5551862 | 15538 | |
d9b3f62e PA |
15539 | ALL_TRACEPOINTS (b) |
15540 | { | |
15541 | struct tracepoint *t = (struct tracepoint *) b; | |
15542 | ||
15543 | if (t->number_on_target == num) | |
15544 | return t; | |
15545 | } | |
d5551862 SS |
15546 | |
15547 | return NULL; | |
15548 | } | |
15549 | ||
1042e4c0 | 15550 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15551 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15552 | If the argument is missing, the most recent tracepoint |
15553 | (tracepoint_count) is returned. */ | |
15554 | ||
d9b3f62e | 15555 | struct tracepoint * |
197f0a60 | 15556 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15557 | number_or_range_parser *parser) |
1042e4c0 | 15558 | { |
1042e4c0 SS |
15559 | struct breakpoint *t; |
15560 | int tpnum; | |
15561 | char *instring = arg == NULL ? NULL : *arg; | |
15562 | ||
bfd28288 | 15563 | if (parser != NULL) |
197f0a60 | 15564 | { |
bfd28288 PA |
15565 | gdb_assert (!parser->finished ()); |
15566 | tpnum = parser->get_number (); | |
197f0a60 TT |
15567 | } |
15568 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15569 | tpnum = tracepoint_count; |
1042e4c0 | 15570 | else |
197f0a60 | 15571 | tpnum = get_number (arg); |
1042e4c0 SS |
15572 | |
15573 | if (tpnum <= 0) | |
15574 | { | |
15575 | if (instring && *instring) | |
15576 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15577 | instring); | |
15578 | else | |
5fa1d40e | 15579 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15580 | return NULL; |
15581 | } | |
15582 | ||
15583 | ALL_TRACEPOINTS (t) | |
15584 | if (t->number == tpnum) | |
15585 | { | |
d9b3f62e | 15586 | return (struct tracepoint *) t; |
1042e4c0 SS |
15587 | } |
15588 | ||
1042e4c0 SS |
15589 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15590 | return NULL; | |
15591 | } | |
15592 | ||
d9b3f62e PA |
15593 | void |
15594 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15595 | { | |
15596 | if (b->thread != -1) | |
15597 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15598 | ||
15599 | if (b->task != 0) | |
15600 | fprintf_unfiltered (fp, " task %d", b->task); | |
15601 | ||
15602 | fprintf_unfiltered (fp, "\n"); | |
15603 | } | |
15604 | ||
6149aea9 PA |
15605 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15606 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15607 | on each breakpoint and only include the ones for which it returns | |
15608 | non-zero. */ | |
15609 | ||
1042e4c0 | 15610 | static void |
6149aea9 PA |
15611 | save_breakpoints (char *filename, int from_tty, |
15612 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15613 | { |
15614 | struct breakpoint *tp; | |
6149aea9 | 15615 | int any = 0; |
1042e4c0 | 15616 | struct cleanup *cleanup; |
6149aea9 | 15617 | int extra_trace_bits = 0; |
1042e4c0 | 15618 | |
6149aea9 PA |
15619 | if (filename == 0 || *filename == 0) |
15620 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15621 | |
15622 | /* See if we have anything to save. */ | |
6149aea9 | 15623 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15624 | { |
6149aea9 | 15625 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15626 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15627 | continue; |
15628 | ||
15629 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15630 | if (filter && !filter (tp)) | |
15631 | continue; | |
15632 | ||
15633 | any = 1; | |
15634 | ||
15635 | if (is_tracepoint (tp)) | |
15636 | { | |
15637 | extra_trace_bits = 1; | |
15638 | ||
15639 | /* We can stop searching. */ | |
15640 | break; | |
15641 | } | |
1042e4c0 | 15642 | } |
6149aea9 PA |
15643 | |
15644 | if (!any) | |
1042e4c0 | 15645 | { |
6149aea9 | 15646 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15647 | return; |
15648 | } | |
15649 | ||
c718be47 PA |
15650 | filename = tilde_expand (filename); |
15651 | cleanup = make_cleanup (xfree, filename); | |
d7e74731 PA |
15652 | |
15653 | stdio_file fp; | |
15654 | ||
15655 | if (!fp.open (filename, "w")) | |
6149aea9 PA |
15656 | error (_("Unable to open file '%s' for saving (%s)"), |
15657 | filename, safe_strerror (errno)); | |
8bf6485c | 15658 | |
6149aea9 | 15659 | if (extra_trace_bits) |
d7e74731 | 15660 | save_trace_state_variables (&fp); |
8bf6485c | 15661 | |
6149aea9 | 15662 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15663 | { |
6149aea9 | 15664 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15665 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15666 | continue; |
8bf6485c | 15667 | |
6149aea9 PA |
15668 | /* If we have a filter, only save the breakpoints it accepts. */ |
15669 | if (filter && !filter (tp)) | |
15670 | continue; | |
15671 | ||
d7e74731 | 15672 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15673 | |
6149aea9 PA |
15674 | /* Note, we can't rely on tp->number for anything, as we can't |
15675 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15676 | instead. */ | |
15677 | ||
15678 | if (tp->cond_string) | |
d7e74731 | 15679 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15680 | |
15681 | if (tp->ignore_count) | |
d7e74731 | 15682 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15683 | |
2d9442cc | 15684 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15685 | { |
d7e74731 | 15686 | fp.puts (" commands\n"); |
a7bdde9e | 15687 | |
d7e74731 | 15688 | current_uiout->redirect (&fp); |
492d29ea | 15689 | TRY |
1042e4c0 | 15690 | { |
79a45e25 | 15691 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15692 | } |
492d29ea PA |
15693 | CATCH (ex, RETURN_MASK_ALL) |
15694 | { | |
112e8700 | 15695 | current_uiout->redirect (NULL); |
492d29ea PA |
15696 | throw_exception (ex); |
15697 | } | |
15698 | END_CATCH | |
1042e4c0 | 15699 | |
112e8700 | 15700 | current_uiout->redirect (NULL); |
d7e74731 | 15701 | fp.puts (" end\n"); |
1042e4c0 | 15702 | } |
6149aea9 PA |
15703 | |
15704 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15705 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15706 | |
15707 | /* If this is a multi-location breakpoint, check if the locations | |
15708 | should be individually disabled. Watchpoint locations are | |
15709 | special, and not user visible. */ | |
15710 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15711 | { | |
15712 | struct bp_location *loc; | |
15713 | int n = 1; | |
15714 | ||
15715 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15716 | if (!loc->enabled) | |
d7e74731 | 15717 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15718 | } |
1042e4c0 | 15719 | } |
8bf6485c | 15720 | |
6149aea9 | 15721 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15722 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15723 | |
1042e4c0 | 15724 | if (from_tty) |
6149aea9 | 15725 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15726 | do_cleanups (cleanup); |
6149aea9 PA |
15727 | } |
15728 | ||
15729 | /* The `save breakpoints' command. */ | |
15730 | ||
15731 | static void | |
15732 | save_breakpoints_command (char *args, int from_tty) | |
15733 | { | |
15734 | save_breakpoints (args, from_tty, NULL); | |
15735 | } | |
15736 | ||
15737 | /* The `save tracepoints' command. */ | |
15738 | ||
15739 | static void | |
15740 | save_tracepoints_command (char *args, int from_tty) | |
15741 | { | |
15742 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15743 | } |
15744 | ||
15745 | /* Create a vector of all tracepoints. */ | |
15746 | ||
15747 | VEC(breakpoint_p) * | |
eeae04df | 15748 | all_tracepoints (void) |
1042e4c0 SS |
15749 | { |
15750 | VEC(breakpoint_p) *tp_vec = 0; | |
15751 | struct breakpoint *tp; | |
15752 | ||
15753 | ALL_TRACEPOINTS (tp) | |
15754 | { | |
15755 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15756 | } | |
15757 | ||
15758 | return tp_vec; | |
15759 | } | |
15760 | ||
c906108c | 15761 | \f |
629500fa KS |
15762 | /* This help string is used to consolidate all the help string for specifying |
15763 | locations used by several commands. */ | |
15764 | ||
15765 | #define LOCATION_HELP_STRING \ | |
15766 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15767 | source filename, function name, label name, and line number.\n\ | |
15768 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15769 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15770 | \"factorial.c:fact:the_top\".\n\ | |
15771 | \n\ | |
15772 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15773 | program. Example: To specify the fourth byte past the start function\n\ | |
15774 | \"main\", use \"*main + 4\".\n\ | |
15775 | \n\ | |
15776 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15777 | syntax to specify location parameters.\n\ | |
15778 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15779 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15780 | -function fact -label the_top\".\n" | |
15781 | ||
4a64f543 MS |
15782 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15783 | commands. It is defined as a macro to prevent duplication. | |
15784 | COMMAND should be a string constant containing the name of the | |
15785 | command. */ | |
629500fa | 15786 | |
31e2b00f | 15787 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15788 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15789 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15790 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15791 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15792 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15793 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15794 | below.\n\ | |
15795 | \n\ | |
dc10affe PA |
15796 | With no LOCATION, uses current execution address of the selected\n\ |
15797 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15798 | \n\ |
15799 | THREADNUM is the number from \"info threads\".\n\ | |
15800 | CONDITION is a boolean expression.\n\ | |
629500fa | 15801 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15802 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15803 | conditions are different.\n\ | |
31e2b00f AS |
15804 | \n\ |
15805 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15806 | ||
44feb3ce TT |
15807 | /* List of subcommands for "catch". */ |
15808 | static struct cmd_list_element *catch_cmdlist; | |
15809 | ||
15810 | /* List of subcommands for "tcatch". */ | |
15811 | static struct cmd_list_element *tcatch_cmdlist; | |
15812 | ||
9ac4176b | 15813 | void |
a121b7c1 | 15814 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15815 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15816 | completer_ftype *completer, |
44feb3ce TT |
15817 | void *user_data_catch, |
15818 | void *user_data_tcatch) | |
15819 | { | |
15820 | struct cmd_list_element *command; | |
15821 | ||
15822 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15823 | &catch_cmdlist); | |
15824 | set_cmd_sfunc (command, sfunc); | |
15825 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15826 | set_cmd_completer (command, completer); |
44feb3ce TT |
15827 | |
15828 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15829 | &tcatch_cmdlist); | |
15830 | set_cmd_sfunc (command, sfunc); | |
15831 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15832 | set_cmd_completer (command, completer); |
44feb3ce TT |
15833 | } |
15834 | ||
6149aea9 PA |
15835 | static void |
15836 | save_command (char *arg, int from_tty) | |
15837 | { | |
3e43a32a MS |
15838 | printf_unfiltered (_("\"save\" must be followed by " |
15839 | "the name of a save subcommand.\n")); | |
635c7e8a | 15840 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15841 | } |
15842 | ||
84f4c1fe PM |
15843 | struct breakpoint * |
15844 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15845 | void *data) | |
15846 | { | |
35df4500 | 15847 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15848 | |
35df4500 | 15849 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15850 | { |
15851 | if ((*callback) (b, data)) | |
15852 | return b; | |
15853 | } | |
15854 | ||
15855 | return NULL; | |
15856 | } | |
15857 | ||
0574c78f GB |
15858 | /* Zero if any of the breakpoint's locations could be a location where |
15859 | functions have been inlined, nonzero otherwise. */ | |
15860 | ||
15861 | static int | |
15862 | is_non_inline_function (struct breakpoint *b) | |
15863 | { | |
15864 | /* The shared library event breakpoint is set on the address of a | |
15865 | non-inline function. */ | |
15866 | if (b->type == bp_shlib_event) | |
15867 | return 1; | |
15868 | ||
15869 | return 0; | |
15870 | } | |
15871 | ||
15872 | /* Nonzero if the specified PC cannot be a location where functions | |
15873 | have been inlined. */ | |
15874 | ||
15875 | int | |
09ac7c10 TT |
15876 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15877 | const struct target_waitstatus *ws) | |
0574c78f GB |
15878 | { |
15879 | struct breakpoint *b; | |
15880 | struct bp_location *bl; | |
15881 | ||
15882 | ALL_BREAKPOINTS (b) | |
15883 | { | |
15884 | if (!is_non_inline_function (b)) | |
15885 | continue; | |
15886 | ||
15887 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15888 | { | |
15889 | if (!bl->shlib_disabled | |
09ac7c10 | 15890 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15891 | return 1; |
15892 | } | |
15893 | } | |
15894 | ||
15895 | return 0; | |
15896 | } | |
15897 | ||
2f202fde JK |
15898 | /* Remove any references to OBJFILE which is going to be freed. */ |
15899 | ||
15900 | void | |
15901 | breakpoint_free_objfile (struct objfile *objfile) | |
15902 | { | |
15903 | struct bp_location **locp, *loc; | |
15904 | ||
15905 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15906 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15907 | loc->symtab = NULL; |
15908 | } | |
15909 | ||
2060206e PA |
15910 | void |
15911 | initialize_breakpoint_ops (void) | |
15912 | { | |
15913 | static int initialized = 0; | |
15914 | ||
15915 | struct breakpoint_ops *ops; | |
15916 | ||
15917 | if (initialized) | |
15918 | return; | |
15919 | initialized = 1; | |
15920 | ||
15921 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15922 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15923 | internal and momentary breakpoints, etc.). */ | |
15924 | ops = &bkpt_base_breakpoint_ops; | |
15925 | *ops = base_breakpoint_ops; | |
15926 | ops->re_set = bkpt_re_set; | |
15927 | ops->insert_location = bkpt_insert_location; | |
15928 | ops->remove_location = bkpt_remove_location; | |
15929 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15930 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15931 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15932 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15933 | |
15934 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15935 | ops = &bkpt_breakpoint_ops; | |
15936 | *ops = bkpt_base_breakpoint_ops; | |
15937 | ops->re_set = bkpt_re_set; | |
15938 | ops->resources_needed = bkpt_resources_needed; | |
15939 | ops->print_it = bkpt_print_it; | |
15940 | ops->print_mention = bkpt_print_mention; | |
15941 | ops->print_recreate = bkpt_print_recreate; | |
15942 | ||
15943 | /* Ranged breakpoints. */ | |
15944 | ops = &ranged_breakpoint_ops; | |
15945 | *ops = bkpt_breakpoint_ops; | |
15946 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15947 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15948 | ops->print_it = print_it_ranged_breakpoint; | |
15949 | ops->print_one = print_one_ranged_breakpoint; | |
15950 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15951 | ops->print_mention = print_mention_ranged_breakpoint; | |
15952 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15953 | ||
15954 | /* Internal breakpoints. */ | |
15955 | ops = &internal_breakpoint_ops; | |
15956 | *ops = bkpt_base_breakpoint_ops; | |
15957 | ops->re_set = internal_bkpt_re_set; | |
15958 | ops->check_status = internal_bkpt_check_status; | |
15959 | ops->print_it = internal_bkpt_print_it; | |
15960 | ops->print_mention = internal_bkpt_print_mention; | |
15961 | ||
15962 | /* Momentary breakpoints. */ | |
15963 | ops = &momentary_breakpoint_ops; | |
15964 | *ops = bkpt_base_breakpoint_ops; | |
15965 | ops->re_set = momentary_bkpt_re_set; | |
15966 | ops->check_status = momentary_bkpt_check_status; | |
15967 | ops->print_it = momentary_bkpt_print_it; | |
15968 | ops->print_mention = momentary_bkpt_print_mention; | |
15969 | ||
e2e4d78b JK |
15970 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15971 | ops = &longjmp_breakpoint_ops; | |
15972 | *ops = momentary_breakpoint_ops; | |
15973 | ops->dtor = longjmp_bkpt_dtor; | |
15974 | ||
55aa24fb SDJ |
15975 | /* Probe breakpoints. */ |
15976 | ops = &bkpt_probe_breakpoint_ops; | |
15977 | *ops = bkpt_breakpoint_ops; | |
15978 | ops->insert_location = bkpt_probe_insert_location; | |
15979 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15980 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15981 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15982 | |
2060206e PA |
15983 | /* Watchpoints. */ |
15984 | ops = &watchpoint_breakpoint_ops; | |
15985 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15986 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15987 | ops->re_set = re_set_watchpoint; |
15988 | ops->insert_location = insert_watchpoint; | |
15989 | ops->remove_location = remove_watchpoint; | |
15990 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15991 | ops->check_status = check_status_watchpoint; | |
15992 | ops->resources_needed = resources_needed_watchpoint; | |
15993 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15994 | ops->print_it = print_it_watchpoint; | |
15995 | ops->print_mention = print_mention_watchpoint; | |
15996 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15997 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15998 | |
15999 | /* Masked watchpoints. */ | |
16000 | ops = &masked_watchpoint_breakpoint_ops; | |
16001 | *ops = watchpoint_breakpoint_ops; | |
16002 | ops->insert_location = insert_masked_watchpoint; | |
16003 | ops->remove_location = remove_masked_watchpoint; | |
16004 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16005 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16006 | ops->print_it = print_it_masked_watchpoint; | |
16007 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16008 | ops->print_mention = print_mention_masked_watchpoint; | |
16009 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16010 | ||
16011 | /* Tracepoints. */ | |
16012 | ops = &tracepoint_breakpoint_ops; | |
16013 | *ops = base_breakpoint_ops; | |
16014 | ops->re_set = tracepoint_re_set; | |
16015 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16016 | ops->print_one_detail = tracepoint_print_one_detail; | |
16017 | ops->print_mention = tracepoint_print_mention; | |
16018 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16019 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16020 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16021 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16022 | |
55aa24fb SDJ |
16023 | /* Probe tracepoints. */ |
16024 | ops = &tracepoint_probe_breakpoint_ops; | |
16025 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16026 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16027 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16028 | |
983af33b SDJ |
16029 | /* Static tracepoints with marker (`-m'). */ |
16030 | ops = &strace_marker_breakpoint_ops; | |
16031 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16032 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16033 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16034 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16035 | |
16036 | /* Fork catchpoints. */ | |
16037 | ops = &catch_fork_breakpoint_ops; | |
16038 | *ops = base_breakpoint_ops; | |
16039 | ops->insert_location = insert_catch_fork; | |
16040 | ops->remove_location = remove_catch_fork; | |
16041 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16042 | ops->print_it = print_it_catch_fork; | |
16043 | ops->print_one = print_one_catch_fork; | |
16044 | ops->print_mention = print_mention_catch_fork; | |
16045 | ops->print_recreate = print_recreate_catch_fork; | |
16046 | ||
16047 | /* Vfork catchpoints. */ | |
16048 | ops = &catch_vfork_breakpoint_ops; | |
16049 | *ops = base_breakpoint_ops; | |
16050 | ops->insert_location = insert_catch_vfork; | |
16051 | ops->remove_location = remove_catch_vfork; | |
16052 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16053 | ops->print_it = print_it_catch_vfork; | |
16054 | ops->print_one = print_one_catch_vfork; | |
16055 | ops->print_mention = print_mention_catch_vfork; | |
16056 | ops->print_recreate = print_recreate_catch_vfork; | |
16057 | ||
16058 | /* Exec catchpoints. */ | |
16059 | ops = &catch_exec_breakpoint_ops; | |
16060 | *ops = base_breakpoint_ops; | |
16061 | ops->dtor = dtor_catch_exec; | |
16062 | ops->insert_location = insert_catch_exec; | |
16063 | ops->remove_location = remove_catch_exec; | |
16064 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16065 | ops->print_it = print_it_catch_exec; | |
16066 | ops->print_one = print_one_catch_exec; | |
16067 | ops->print_mention = print_mention_catch_exec; | |
16068 | ops->print_recreate = print_recreate_catch_exec; | |
16069 | ||
edcc5120 TT |
16070 | /* Solib-related catchpoints. */ |
16071 | ops = &catch_solib_breakpoint_ops; | |
16072 | *ops = base_breakpoint_ops; | |
16073 | ops->dtor = dtor_catch_solib; | |
16074 | ops->insert_location = insert_catch_solib; | |
16075 | ops->remove_location = remove_catch_solib; | |
16076 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16077 | ops->check_status = check_status_catch_solib; | |
16078 | ops->print_it = print_it_catch_solib; | |
16079 | ops->print_one = print_one_catch_solib; | |
16080 | ops->print_mention = print_mention_catch_solib; | |
16081 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16082 | |
16083 | ops = &dprintf_breakpoint_ops; | |
16084 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16085 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16086 | ops->resources_needed = bkpt_resources_needed; |
16087 | ops->print_it = bkpt_print_it; | |
16088 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16089 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16090 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16091 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16092 | } |
16093 | ||
8bfd80db YQ |
16094 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16095 | ||
16096 | static struct cmd_list_element *enablebreaklist = NULL; | |
16097 | ||
c906108c | 16098 | void |
fba45db2 | 16099 | _initialize_breakpoint (void) |
c906108c SS |
16100 | { |
16101 | struct cmd_list_element *c; | |
16102 | ||
2060206e PA |
16103 | initialize_breakpoint_ops (); |
16104 | ||
84acb35a | 16105 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16106 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16107 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16108 | |
55aa24fb SDJ |
16109 | breakpoint_objfile_key |
16110 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16111 | |
c906108c SS |
16112 | breakpoint_chain = 0; |
16113 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16114 | before a breakpoint is set. */ | |
16115 | breakpoint_count = 0; | |
16116 | ||
1042e4c0 SS |
16117 | tracepoint_count = 0; |
16118 | ||
1bedd215 AC |
16119 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16120 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16121 | Usage is `ignore N COUNT'.")); | |
c906108c | 16122 | |
1bedd215 | 16123 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
16124 | Set commands to be executed when the given breakpoints are hit.\n\ |
16125 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
16126 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
16127 | (e.g. `5-7').\n\ | |
c906108c SS |
16128 | With no argument, the targeted breakpoint is the last one set.\n\ |
16129 | The commands themselves follow starting on the next line.\n\ | |
16130 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16131 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16132 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16133 | |
d55637df | 16134 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16135 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16136 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16137 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16138 | set_cmd_completer (c, condition_completer); |
c906108c | 16139 | |
1bedd215 | 16140 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16141 | Set a temporary breakpoint.\n\ |
c906108c SS |
16142 | Like \"break\" except the breakpoint is only temporary,\n\ |
16143 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16144 | by using \"enable delete\" on the breakpoint number.\n\ |
16145 | \n" | |
16146 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16147 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16148 | |
1bedd215 | 16149 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16150 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16151 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16152 | some target hardware may not have this support.\n\ |
16153 | \n" | |
16154 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16155 | set_cmd_completer (c, location_completer); |
c906108c | 16156 | |
1bedd215 | 16157 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16158 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16159 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16160 | so it will be deleted when hit.\n\ |
16161 | \n" | |
16162 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16163 | set_cmd_completer (c, location_completer); |
c906108c | 16164 | |
1bedd215 AC |
16165 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16166 | Enable some breakpoints.\n\ | |
c906108c SS |
16167 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16168 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16169 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16170 | With a subcommand you can enable temporarily."), |
c906108c | 16171 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16172 | |
16173 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16174 | ||
84951ab5 | 16175 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16176 | Enable some breakpoints.\n\ |
c906108c SS |
16177 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16178 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16179 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16180 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16181 | |
1a966eab AC |
16182 | add_cmd ("once", no_class, enable_once_command, _("\ |
16183 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16184 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16185 | &enablebreaklist); |
16186 | ||
1a966eab AC |
16187 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16188 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16189 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16190 | &enablebreaklist); |
16191 | ||
816338b5 SS |
16192 | add_cmd ("count", no_class, enable_count_command, _("\ |
16193 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16194 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16195 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16196 | &enablebreaklist); | |
16197 | ||
1a966eab AC |
16198 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16199 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16200 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16201 | &enablelist); |
16202 | ||
1a966eab AC |
16203 | add_cmd ("once", no_class, enable_once_command, _("\ |
16204 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16205 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16206 | &enablelist); |
16207 | ||
16208 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16209 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16210 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16211 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16212 | &enablelist); |
16213 | ||
1bedd215 AC |
16214 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16215 | Disable some breakpoints.\n\ | |
c906108c SS |
16216 | Arguments are breakpoint numbers with spaces in between.\n\ |
16217 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16218 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16219 | &disablelist, "disable ", 1, &cmdlist); |
16220 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16221 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16222 | |
1a966eab AC |
16223 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16224 | Disable some breakpoints.\n\ | |
c906108c SS |
16225 | Arguments are breakpoint numbers with spaces in between.\n\ |
16226 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16227 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16228 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16229 | &disablelist); |
16230 | ||
1bedd215 AC |
16231 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16232 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16233 | Arguments are breakpoint numbers with spaces in between.\n\ |
16234 | To delete all breakpoints, give no argument.\n\ | |
16235 | \n\ | |
16236 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16237 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16238 | &deletelist, "delete ", 1, &cmdlist); |
16239 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16240 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16241 | |
1a966eab AC |
16242 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16243 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16244 | Arguments are breakpoint numbers with spaces in between.\n\ |
16245 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16246 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16247 | &deletelist); |
16248 | ||
1bedd215 | 16249 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16250 | Clear breakpoint at specified location.\n\ |
16251 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16252 | \n\ |
16253 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16254 | is executing in.\n" |
16255 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16256 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16257 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16258 | |
1bedd215 | 16259 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16260 | Set breakpoint at specified location.\n" |
31e2b00f | 16261 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16262 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16263 | |
c906108c SS |
16264 | add_com_alias ("b", "break", class_run, 1); |
16265 | add_com_alias ("br", "break", class_run, 1); | |
16266 | add_com_alias ("bre", "break", class_run, 1); | |
16267 | add_com_alias ("brea", "break", class_run, 1); | |
16268 | ||
c906108c SS |
16269 | if (dbx_commands) |
16270 | { | |
1bedd215 AC |
16271 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16272 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16273 | &stoplist, "stop ", 1, &cmdlist); |
16274 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16275 | _("Break in function or address."), &stoplist); |
c5aa993b | 16276 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16277 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16278 | add_com ("status", class_info, breakpoints_info, _("\ |
16279 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16280 | The \"Type\" column indicates one of:\n\ |
16281 | \tbreakpoint - normal breakpoint\n\ | |
16282 | \twatchpoint - watchpoint\n\ | |
16283 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16284 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16285 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16286 | address and file/line number respectively.\n\ |
16287 | \n\ | |
16288 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16289 | are set to the address of the last breakpoint listed unless the command\n\ |
16290 | is prefixed with \"server \".\n\n\ | |
c906108c | 16291 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16292 | breakpoint set.")); |
c906108c SS |
16293 | } |
16294 | ||
1bedd215 | 16295 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16296 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16297 | The \"Type\" column indicates one of:\n\ |
16298 | \tbreakpoint - normal breakpoint\n\ | |
16299 | \twatchpoint - watchpoint\n\ | |
16300 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16301 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16302 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16303 | address and file/line number respectively.\n\ |
16304 | \n\ | |
16305 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16306 | are set to the address of the last breakpoint listed unless the command\n\ |
16307 | is prefixed with \"server \".\n\n\ | |
c906108c | 16308 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16309 | breakpoint set.")); |
c906108c | 16310 | |
6b04bdb7 MS |
16311 | add_info_alias ("b", "breakpoints", 1); |
16312 | ||
1a966eab AC |
16313 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16314 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16315 | The \"Type\" column indicates one of:\n\ |
16316 | \tbreakpoint - normal breakpoint\n\ | |
16317 | \twatchpoint - watchpoint\n\ | |
16318 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16319 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16320 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16321 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16322 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16323 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16324 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16325 | address and file/line number respectively.\n\ |
16326 | \n\ | |
16327 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16328 | are set to the address of the last breakpoint listed unless the command\n\ |
16329 | is prefixed with \"server \".\n\n\ | |
c906108c | 16330 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16331 | breakpoint set."), |
c906108c SS |
16332 | &maintenanceinfolist); |
16333 | ||
44feb3ce TT |
16334 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16335 | Set catchpoints to catch events."), | |
16336 | &catch_cmdlist, "catch ", | |
16337 | 0/*allow-unknown*/, &cmdlist); | |
16338 | ||
16339 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16340 | Set temporary catchpoints to catch events."), | |
16341 | &tcatch_cmdlist, "tcatch ", | |
16342 | 0/*allow-unknown*/, &cmdlist); | |
16343 | ||
44feb3ce TT |
16344 | add_catch_command ("fork", _("Catch calls to fork."), |
16345 | catch_fork_command_1, | |
a96d9b2e | 16346 | NULL, |
44feb3ce TT |
16347 | (void *) (uintptr_t) catch_fork_permanent, |
16348 | (void *) (uintptr_t) catch_fork_temporary); | |
16349 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16350 | catch_fork_command_1, | |
a96d9b2e | 16351 | NULL, |
44feb3ce TT |
16352 | (void *) (uintptr_t) catch_vfork_permanent, |
16353 | (void *) (uintptr_t) catch_vfork_temporary); | |
16354 | add_catch_command ("exec", _("Catch calls to exec."), | |
16355 | catch_exec_command_1, | |
a96d9b2e SDJ |
16356 | NULL, |
16357 | CATCH_PERMANENT, | |
16358 | CATCH_TEMPORARY); | |
edcc5120 TT |
16359 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16360 | Usage: catch load [REGEX]\n\ | |
16361 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16362 | catch_load_command_1, | |
16363 | NULL, | |
16364 | CATCH_PERMANENT, | |
16365 | CATCH_TEMPORARY); | |
16366 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16367 | Usage: catch unload [REGEX]\n\ | |
16368 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16369 | catch_unload_command_1, | |
16370 | NULL, | |
16371 | CATCH_PERMANENT, | |
16372 | CATCH_TEMPORARY); | |
c5aa993b | 16373 | |
1bedd215 AC |
16374 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16375 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16376 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16377 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16378 | an expression changes.\n\ |
16379 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16380 | the memory to which it refers.")); | |
65d12d83 | 16381 | set_cmd_completer (c, expression_completer); |
c906108c | 16382 | |
1bedd215 AC |
16383 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16384 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16385 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16386 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16387 | an expression is read.\n\ |
16388 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16389 | the memory to which it refers.")); | |
65d12d83 | 16390 | set_cmd_completer (c, expression_completer); |
c906108c | 16391 | |
1bedd215 AC |
16392 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16393 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16394 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16395 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16396 | an expression is either read or written.\n\ |
16397 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16398 | the memory to which it refers.")); | |
65d12d83 | 16399 | set_cmd_completer (c, expression_completer); |
c906108c | 16400 | |
d77f58be | 16401 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16402 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16403 | |
920d2a44 AC |
16404 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16405 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16406 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16407 | &can_use_hw_watchpoints, _("\ | |
16408 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16409 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16410 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16411 | such is available. (However, any hardware watchpoints that were\n\ | |
16412 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16413 | hardware.)"), |
16414 | NULL, | |
920d2a44 | 16415 | show_can_use_hw_watchpoints, |
85c07804 | 16416 | &setlist, &showlist); |
c906108c SS |
16417 | |
16418 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16419 | |
1042e4c0 SS |
16420 | /* Tracepoint manipulation commands. */ |
16421 | ||
16422 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16423 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16424 | \n" |
16425 | BREAK_ARGS_HELP ("trace") "\n\ | |
16426 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16427 | set_cmd_completer (c, location_completer); | |
16428 | ||
16429 | add_com_alias ("tp", "trace", class_alias, 0); | |
16430 | add_com_alias ("tr", "trace", class_alias, 1); | |
16431 | add_com_alias ("tra", "trace", class_alias, 1); | |
16432 | add_com_alias ("trac", "trace", class_alias, 1); | |
16433 | ||
7a697b8d | 16434 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16435 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16436 | \n" |
16437 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16438 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16439 | set_cmd_completer (c, location_completer); | |
16440 | ||
0fb4aa4b | 16441 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16442 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16443 | \n\ |
16444 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16445 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16446 | or -m MARKER_ID.\n\n\ | |
16447 | If a marker id is specified, probe the marker with that name. With\n\ | |
16448 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16449 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16450 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16451 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16452 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16453 | \n\ | |
16454 | CONDITION is a boolean expression.\n\ | |
629500fa | 16455 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16456 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16457 | conditions are different.\n\ | |
0fb4aa4b PA |
16458 | \n\ |
16459 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16460 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16461 | set_cmd_completer (c, location_completer); | |
16462 | ||
1042e4c0 | 16463 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16464 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16465 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16466 | last tracepoint set.")); | |
16467 | ||
16468 | add_info_alias ("tp", "tracepoints", 1); | |
16469 | ||
16470 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16471 | Delete specified tracepoints.\n\ | |
16472 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16473 | No argument means delete all tracepoints."), | |
16474 | &deletelist); | |
7e20dfcd | 16475 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16476 | |
16477 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16478 | Disable specified tracepoints.\n\ | |
16479 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16480 | No argument means disable all tracepoints."), | |
16481 | &disablelist); | |
16482 | deprecate_cmd (c, "disable"); | |
16483 | ||
16484 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16485 | Enable specified tracepoints.\n\ | |
16486 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16487 | No argument means enable all tracepoints."), | |
16488 | &enablelist); | |
16489 | deprecate_cmd (c, "enable"); | |
16490 | ||
16491 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16492 | Set the passcount for a tracepoint.\n\ | |
16493 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16494 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16495 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16496 | ||
6149aea9 PA |
16497 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16498 | _("Save breakpoint definitions as a script."), | |
16499 | &save_cmdlist, "save ", | |
16500 | 0/*allow-unknown*/, &cmdlist); | |
16501 | ||
16502 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16503 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16504 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16505 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16506 | session to restore them."), | |
16507 | &save_cmdlist); | |
16508 | set_cmd_completer (c, filename_completer); | |
16509 | ||
16510 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16511 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16512 | Use the 'source' command in another debug session to restore them."), |
16513 | &save_cmdlist); | |
1042e4c0 SS |
16514 | set_cmd_completer (c, filename_completer); |
16515 | ||
6149aea9 PA |
16516 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16517 | deprecate_cmd (c, "save tracepoints"); | |
16518 | ||
1bedd215 | 16519 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16520 | Breakpoint specific settings\n\ |
16521 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16522 | pending breakpoint behavior"), |
fa8d40ab JJ |
16523 | &breakpoint_set_cmdlist, "set breakpoint ", |
16524 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16525 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16526 | Breakpoint specific settings\n\ |
16527 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16528 | pending breakpoint behavior"), |
fa8d40ab JJ |
16529 | &breakpoint_show_cmdlist, "show breakpoint ", |
16530 | 0/*allow-unknown*/, &showlist); | |
16531 | ||
7915a72c AC |
16532 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16533 | &pending_break_support, _("\ | |
16534 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16535 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16536 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16537 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16538 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16539 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16540 | NULL, |
920d2a44 | 16541 | show_pending_break_support, |
6e1d7d6c AC |
16542 | &breakpoint_set_cmdlist, |
16543 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16544 | |
16545 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16546 | |
16547 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16548 | &automatic_hardware_breakpoints, _("\ | |
16549 | Set automatic usage of hardware breakpoints."), _("\ | |
16550 | Show automatic usage of hardware breakpoints."), _("\ | |
16551 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16552 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16553 | a warning will be emitted for such breakpoints."), | |
16554 | NULL, | |
16555 | show_automatic_hardware_breakpoints, | |
16556 | &breakpoint_set_cmdlist, | |
16557 | &breakpoint_show_cmdlist); | |
74960c60 | 16558 | |
a25a5a45 PA |
16559 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16560 | &always_inserted_mode, _("\ | |
74960c60 VP |
16561 | Set mode for inserting breakpoints."), _("\ |
16562 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16563 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16564 | they're created, kept inserted even when execution stops, and removed\n\ | |
16565 | only when the user deletes them. When this mode is off (the default),\n\ | |
16566 | breakpoints are inserted only when execution continues, and removed\n\ | |
16567 | when execution stops."), | |
72d0e2c5 YQ |
16568 | NULL, |
16569 | &show_always_inserted_mode, | |
16570 | &breakpoint_set_cmdlist, | |
16571 | &breakpoint_show_cmdlist); | |
f1310107 | 16572 | |
b775012e LM |
16573 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16574 | condition_evaluation_enums, | |
16575 | &condition_evaluation_mode_1, _("\ | |
16576 | Set mode of breakpoint condition evaluation."), _("\ | |
16577 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16578 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16579 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16580 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16581 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16582 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16583 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16584 | be set to \"gdb\""), | |
16585 | &set_condition_evaluation_mode, | |
16586 | &show_condition_evaluation_mode, | |
16587 | &breakpoint_set_cmdlist, | |
16588 | &breakpoint_show_cmdlist); | |
16589 | ||
f1310107 TJB |
16590 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16591 | Set a breakpoint for an address range.\n\ | |
16592 | break-range START-LOCATION, END-LOCATION\n\ | |
16593 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16594 | LINENUM, for that line in the current file,\n\ | |
16595 | FILE:LINENUM, for that line in that file,\n\ | |
16596 | +OFFSET, for that number of lines after the current line\n\ | |
16597 | or the start of the range\n\ | |
16598 | FUNCTION, for the first line in that function,\n\ | |
16599 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16600 | *ADDRESS, for the instruction at that address.\n\ | |
16601 | \n\ | |
16602 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16603 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16604 | range (including START-LOCATION and END-LOCATION).")); | |
16605 | ||
e7e0cddf | 16606 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16607 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16608 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16609 | location may be a linespec, explicit, or address location.\n" |
16610 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16611 | set_cmd_completer (c, location_completer); |
16612 | ||
16613 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16614 | dprintf_style_enums, &dprintf_style, _("\ | |
16615 | Set the style of usage for dynamic printf."), _("\ | |
16616 | Show the style of usage for dynamic printf."), _("\ | |
16617 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16618 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16619 | console, as with the \"printf\" command.\n\ | |
16620 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16621 | program; by default printf(), but you can choose a different function or\n\ | |
16622 | output stream by setting dprintf-function and dprintf-channel."), | |
16623 | update_dprintf_commands, NULL, | |
16624 | &setlist, &showlist); | |
16625 | ||
16626 | dprintf_function = xstrdup ("printf"); | |
16627 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16628 | &dprintf_function, _("\ | |
16629 | Set the function to use for dynamic printf"), _("\ | |
16630 | Show the function to use for dynamic printf"), NULL, | |
16631 | update_dprintf_commands, NULL, | |
16632 | &setlist, &showlist); | |
16633 | ||
16634 | dprintf_channel = xstrdup (""); | |
16635 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16636 | &dprintf_channel, _("\ | |
16637 | Set the channel to use for dynamic printf"), _("\ | |
16638 | Show the channel to use for dynamic printf"), NULL, | |
16639 | update_dprintf_commands, NULL, | |
16640 | &setlist, &showlist); | |
16641 | ||
d3ce09f5 SS |
16642 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16643 | &disconnected_dprintf, _("\ | |
16644 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16645 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16646 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16647 | even if GDB disconnects or detaches from the target."), | |
16648 | NULL, | |
16649 | NULL, | |
16650 | &setlist, &showlist); | |
16651 | ||
16652 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16653 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16654 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16655 | ||
765dc015 | 16656 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16657 | |
16658 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16659 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16660 | } |