]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
618f726f | 3 | Copyright (C) 1986-2016 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
f00aae0f | 70 | #include "location.h" |
cfc31633 | 71 | #include "thread-fsm.h" |
5d5658a1 | 72 | #include "tid-parse.h" |
d3ce09f5 | 73 | |
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
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 | ||
348 | static char *dprintf_function = ""; | |
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 | ||
358 | static char *dprintf_channel = ""; | |
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 | ||
984 | xfree (w->cond_exp); | |
985 | w->cond_exp = NULL; | |
986 | } | |
987 | else | |
988 | { | |
989 | struct bp_location *loc; | |
990 | ||
991 | for (loc = b->loc; loc; loc = loc->next) | |
992 | { | |
993 | xfree (loc->cond); | |
994 | loc->cond = NULL; | |
b775012e LM |
995 | |
996 | /* No need to free the condition agent expression | |
997 | bytecode (if we have one). We will handle this | |
998 | when we go through update_global_location_list. */ | |
3a5c3e22 | 999 | } |
adc36818 | 1000 | } |
adc36818 PM |
1001 | |
1002 | if (*exp == 0) | |
1003 | { | |
1004 | if (from_tty) | |
1005 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1006 | } | |
1007 | else | |
1008 | { | |
bbc13ae3 | 1009 | const char *arg = exp; |
cc59ec59 | 1010 | |
adc36818 PM |
1011 | /* I don't know if it matters whether this is the string the user |
1012 | typed in or the decompiled expression. */ | |
1013 | b->cond_string = xstrdup (arg); | |
1014 | b->condition_not_parsed = 0; | |
1015 | ||
1016 | if (is_watchpoint (b)) | |
1017 | { | |
3a5c3e22 PA |
1018 | struct watchpoint *w = (struct watchpoint *) b; |
1019 | ||
adc36818 PM |
1020 | innermost_block = NULL; |
1021 | arg = exp; | |
1bb9788d | 1022 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1023 | if (*arg) |
1024 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1025 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1026 | } |
1027 | else | |
1028 | { | |
3a5c3e22 PA |
1029 | struct bp_location *loc; |
1030 | ||
adc36818 PM |
1031 | for (loc = b->loc; loc; loc = loc->next) |
1032 | { | |
1033 | arg = exp; | |
1034 | loc->cond = | |
1bb9788d TT |
1035 | parse_exp_1 (&arg, loc->address, |
1036 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1037 | if (*arg) |
1038 | error (_("Junk at end of expression")); | |
1039 | } | |
1040 | } | |
1041 | } | |
b775012e LM |
1042 | mark_breakpoint_modified (b); |
1043 | ||
8d3788bd | 1044 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1045 | } |
1046 | ||
d55637df TT |
1047 | /* Completion for the "condition" command. */ |
1048 | ||
1049 | static VEC (char_ptr) * | |
6f937416 PA |
1050 | condition_completer (struct cmd_list_element *cmd, |
1051 | const char *text, const char *word) | |
d55637df | 1052 | { |
6f937416 | 1053 | const char *space; |
d55637df | 1054 | |
6f937416 PA |
1055 | text = skip_spaces_const (text); |
1056 | space = skip_to_space_const (text); | |
d55637df TT |
1057 | if (*space == '\0') |
1058 | { | |
1059 | int len; | |
1060 | struct breakpoint *b; | |
1061 | VEC (char_ptr) *result = NULL; | |
1062 | ||
1063 | if (text[0] == '$') | |
1064 | { | |
1065 | /* We don't support completion of history indices. */ | |
1066 | if (isdigit (text[1])) | |
1067 | return NULL; | |
1068 | return complete_internalvar (&text[1]); | |
1069 | } | |
1070 | ||
1071 | /* We're completing the breakpoint number. */ | |
1072 | len = strlen (text); | |
1073 | ||
1074 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1075 | { |
1076 | char number[50]; | |
1077 | ||
1078 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1079 | ||
1080 | if (strncmp (number, text, len) == 0) | |
1081 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1082 | } | |
d55637df TT |
1083 | |
1084 | return result; | |
1085 | } | |
1086 | ||
1087 | /* We're completing the expression part. */ | |
6f937416 | 1088 | text = skip_spaces_const (space); |
d55637df TT |
1089 | return expression_completer (cmd, text, word); |
1090 | } | |
1091 | ||
c906108c SS |
1092 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1093 | ||
1094 | static void | |
fba45db2 | 1095 | condition_command (char *arg, int from_tty) |
c906108c | 1096 | { |
52f0bd74 | 1097 | struct breakpoint *b; |
c906108c | 1098 | char *p; |
52f0bd74 | 1099 | int bnum; |
c906108c SS |
1100 | |
1101 | if (arg == 0) | |
e2e0b3e5 | 1102 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1103 | |
1104 | p = arg; | |
1105 | bnum = get_number (&p); | |
5c44784c | 1106 | if (bnum == 0) |
8a3fe4f8 | 1107 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1108 | |
1109 | ALL_BREAKPOINTS (b) | |
1110 | if (b->number == bnum) | |
2f069f6f | 1111 | { |
6dddc817 DE |
1112 | /* Check if this breakpoint has a "stop" method implemented in an |
1113 | extension language. This method and conditions entered into GDB | |
1114 | from the CLI are mutually exclusive. */ | |
1115 | const struct extension_language_defn *extlang | |
1116 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1117 | ||
1118 | if (extlang != NULL) | |
1119 | { | |
1120 | error (_("Only one stop condition allowed. There is currently" | |
1121 | " a %s stop condition defined for this breakpoint."), | |
1122 | ext_lang_capitalized_name (extlang)); | |
1123 | } | |
2566ad2d | 1124 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1125 | |
1126 | if (is_breakpoint (b)) | |
44702360 | 1127 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1128 | |
2f069f6f JB |
1129 | return; |
1130 | } | |
c906108c | 1131 | |
8a3fe4f8 | 1132 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1133 | } |
1134 | ||
a7bdde9e VP |
1135 | /* Check that COMMAND do not contain commands that are suitable |
1136 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1137 | Throw if any such commands is found. */ |
1138 | ||
a7bdde9e VP |
1139 | static void |
1140 | check_no_tracepoint_commands (struct command_line *commands) | |
1141 | { | |
1142 | struct command_line *c; | |
cc59ec59 | 1143 | |
a7bdde9e VP |
1144 | for (c = commands; c; c = c->next) |
1145 | { | |
1146 | int i; | |
1147 | ||
1148 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1149 | error (_("The 'while-stepping' command can " |
1150 | "only be used for tracepoints")); | |
a7bdde9e VP |
1151 | |
1152 | for (i = 0; i < c->body_count; ++i) | |
1153 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1154 | ||
1155 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1156 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1157 | command directly. */ |
1158 | if (strstr (c->line, "collect ") == c->line) | |
1159 | error (_("The 'collect' command can only be used for tracepoints")); | |
1160 | ||
51661e93 VP |
1161 | if (strstr (c->line, "teval ") == c->line) |
1162 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1163 | } |
1164 | } | |
1165 | ||
d77f58be SS |
1166 | /* Encapsulate tests for different types of tracepoints. */ |
1167 | ||
d9b3f62e PA |
1168 | static int |
1169 | is_tracepoint_type (enum bptype type) | |
1170 | { | |
1171 | return (type == bp_tracepoint | |
1172 | || type == bp_fast_tracepoint | |
1173 | || type == bp_static_tracepoint); | |
1174 | } | |
1175 | ||
a7bdde9e | 1176 | int |
d77f58be | 1177 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1178 | { |
d9b3f62e | 1179 | return is_tracepoint_type (b->type); |
a7bdde9e | 1180 | } |
d9b3f62e | 1181 | |
e5dd4106 | 1182 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1183 | breakpoint. This function will throw an exception if a problem is |
1184 | found. */ | |
48cb2d85 | 1185 | |
95a42b64 TT |
1186 | static void |
1187 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1188 | struct command_line *commands) | |
48cb2d85 | 1189 | { |
d77f58be | 1190 | if (is_tracepoint (b)) |
a7bdde9e | 1191 | { |
c9a6ce02 | 1192 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1193 | struct command_line *c; |
1194 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1195 | |
1196 | /* Reset the while-stepping step count. The previous commands | |
1197 | might have included a while-stepping action, while the new | |
1198 | ones might not. */ | |
1199 | t->step_count = 0; | |
1200 | ||
1201 | /* We need to verify that each top-level element of commands is | |
1202 | valid for tracepoints, that there's at most one | |
1203 | while-stepping element, and that the while-stepping's body | |
1204 | has valid tracing commands excluding nested while-stepping. | |
1205 | We also need to validate the tracepoint action line in the | |
1206 | context of the tracepoint --- validate_actionline actually | |
1207 | has side effects, like setting the tracepoint's | |
1208 | while-stepping STEP_COUNT, in addition to checking if the | |
1209 | collect/teval actions parse and make sense in the | |
1210 | tracepoint's context. */ | |
a7bdde9e VP |
1211 | for (c = commands; c; c = c->next) |
1212 | { | |
a7bdde9e VP |
1213 | if (c->control_type == while_stepping_control) |
1214 | { | |
1215 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1216 | error (_("The 'while-stepping' command " |
1217 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1218 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1219 | error (_("The 'while-stepping' command " |
1220 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1221 | |
1222 | if (while_stepping) | |
3e43a32a MS |
1223 | error (_("The 'while-stepping' command " |
1224 | "can be used only once")); | |
a7bdde9e VP |
1225 | else |
1226 | while_stepping = c; | |
1227 | } | |
c9a6ce02 PA |
1228 | |
1229 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1230 | } |
1231 | if (while_stepping) | |
1232 | { | |
1233 | struct command_line *c2; | |
1234 | ||
1235 | gdb_assert (while_stepping->body_count == 1); | |
1236 | c2 = while_stepping->body_list[0]; | |
1237 | for (; c2; c2 = c2->next) | |
1238 | { | |
a7bdde9e VP |
1239 | if (c2->control_type == while_stepping_control) |
1240 | error (_("The 'while-stepping' command cannot be nested")); | |
1241 | } | |
1242 | } | |
1243 | } | |
1244 | else | |
1245 | { | |
1246 | check_no_tracepoint_commands (commands); | |
1247 | } | |
95a42b64 TT |
1248 | } |
1249 | ||
0fb4aa4b PA |
1250 | /* Return a vector of all the static tracepoints set at ADDR. The |
1251 | caller is responsible for releasing the vector. */ | |
1252 | ||
1253 | VEC(breakpoint_p) * | |
1254 | static_tracepoints_here (CORE_ADDR addr) | |
1255 | { | |
1256 | struct breakpoint *b; | |
1257 | VEC(breakpoint_p) *found = 0; | |
1258 | struct bp_location *loc; | |
1259 | ||
1260 | ALL_BREAKPOINTS (b) | |
1261 | if (b->type == bp_static_tracepoint) | |
1262 | { | |
1263 | for (loc = b->loc; loc; loc = loc->next) | |
1264 | if (loc->address == addr) | |
1265 | VEC_safe_push(breakpoint_p, found, b); | |
1266 | } | |
1267 | ||
1268 | return found; | |
1269 | } | |
1270 | ||
95a42b64 | 1271 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1272 | validate that only allowed commands are included. */ |
95a42b64 TT |
1273 | |
1274 | void | |
4a64f543 MS |
1275 | breakpoint_set_commands (struct breakpoint *b, |
1276 | struct command_line *commands) | |
95a42b64 TT |
1277 | { |
1278 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1279 | |
9add0f1b TT |
1280 | decref_counted_command_line (&b->commands); |
1281 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1282 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1283 | } |
1284 | ||
45a43567 TT |
1285 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1286 | is not the same as the "silent" that may appear in the breakpoint's | |
1287 | commands. */ | |
1288 | ||
1289 | void | |
1290 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1291 | { | |
1292 | int old_silent = b->silent; | |
1293 | ||
1294 | b->silent = silent; | |
1295 | if (old_silent != silent) | |
8d3788bd | 1296 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1297 | } |
1298 | ||
1299 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1300 | breakpoint work for any thread. */ | |
1301 | ||
1302 | void | |
1303 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1304 | { | |
1305 | int old_thread = b->thread; | |
1306 | ||
1307 | b->thread = thread; | |
1308 | if (old_thread != thread) | |
8d3788bd | 1309 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1310 | } |
1311 | ||
1312 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1313 | breakpoint work for any task. */ | |
1314 | ||
1315 | void | |
1316 | breakpoint_set_task (struct breakpoint *b, int task) | |
1317 | { | |
1318 | int old_task = b->task; | |
1319 | ||
1320 | b->task = task; | |
1321 | if (old_task != task) | |
8d3788bd | 1322 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1323 | } |
1324 | ||
95a42b64 TT |
1325 | void |
1326 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1327 | { |
9a3c8263 | 1328 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1329 | |
6f937416 | 1330 | validate_actionline (line, b); |
a7bdde9e VP |
1331 | } |
1332 | ||
95a42b64 TT |
1333 | /* A structure used to pass information through |
1334 | map_breakpoint_numbers. */ | |
1335 | ||
1336 | struct commands_info | |
1337 | { | |
1338 | /* True if the command was typed at a tty. */ | |
1339 | int from_tty; | |
86b17b60 PA |
1340 | |
1341 | /* The breakpoint range spec. */ | |
896b6bda | 1342 | const char *arg; |
86b17b60 | 1343 | |
95a42b64 TT |
1344 | /* Non-NULL if the body of the commands are being read from this |
1345 | already-parsed command. */ | |
1346 | struct command_line *control; | |
86b17b60 | 1347 | |
95a42b64 TT |
1348 | /* The command lines read from the user, or NULL if they have not |
1349 | yet been read. */ | |
1350 | struct counted_command_line *cmd; | |
1351 | }; | |
1352 | ||
1353 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1354 | commands_command. */ | |
1355 | ||
c906108c | 1356 | static void |
95a42b64 | 1357 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1358 | { |
9a3c8263 | 1359 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1360 | |
95a42b64 TT |
1361 | if (info->cmd == NULL) |
1362 | { | |
1363 | struct command_line *l; | |
5c44784c | 1364 | |
95a42b64 TT |
1365 | if (info->control != NULL) |
1366 | l = copy_command_lines (info->control->body_list[0]); | |
1367 | else | |
86b17b60 PA |
1368 | { |
1369 | struct cleanup *old_chain; | |
1370 | char *str; | |
c5aa993b | 1371 | |
3e43a32a MS |
1372 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1373 | "%s, one per line."), | |
86b17b60 PA |
1374 | info->arg); |
1375 | ||
1376 | old_chain = make_cleanup (xfree, str); | |
1377 | ||
1378 | l = read_command_lines (str, | |
1379 | info->from_tty, 1, | |
d77f58be | 1380 | (is_tracepoint (b) |
86b17b60 PA |
1381 | ? check_tracepoint_command : 0), |
1382 | b); | |
1383 | ||
1384 | do_cleanups (old_chain); | |
1385 | } | |
a7bdde9e | 1386 | |
95a42b64 TT |
1387 | info->cmd = alloc_counted_command_line (l); |
1388 | } | |
1389 | ||
1390 | /* If a breakpoint was on the list more than once, we don't need to | |
1391 | do anything. */ | |
1392 | if (b->commands != info->cmd) | |
1393 | { | |
1394 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1395 | incref_counted_command_line (info->cmd); | |
1396 | decref_counted_command_line (&b->commands); | |
1397 | b->commands = info->cmd; | |
8d3788bd | 1398 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1399 | } |
95a42b64 TT |
1400 | } |
1401 | ||
1402 | static void | |
896b6bda | 1403 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1404 | struct command_line *control) |
95a42b64 TT |
1405 | { |
1406 | struct cleanup *cleanups; | |
1407 | struct commands_info info; | |
1408 | ||
1409 | info.from_tty = from_tty; | |
1410 | info.control = control; | |
1411 | info.cmd = NULL; | |
1412 | /* If we read command lines from the user, then `info' will hold an | |
1413 | extra reference to the commands that we must clean up. */ | |
1414 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1415 | ||
896b6bda PA |
1416 | std::string new_arg; |
1417 | ||
95a42b64 TT |
1418 | if (arg == NULL || !*arg) |
1419 | { | |
86b17b60 | 1420 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1421 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1422 | breakpoint_count); | |
95a42b64 | 1423 | else if (breakpoint_count > 0) |
896b6bda | 1424 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1425 | } |
9766ced4 | 1426 | else |
896b6bda | 1427 | new_arg = arg; |
86b17b60 | 1428 | |
896b6bda | 1429 | info.arg = new_arg.c_str (); |
95a42b64 | 1430 | |
896b6bda | 1431 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1432 | |
1433 | if (info.cmd == NULL) | |
1434 | error (_("No breakpoints specified.")); | |
1435 | ||
1436 | do_cleanups (cleanups); | |
1437 | } | |
1438 | ||
1439 | static void | |
1440 | commands_command (char *arg, int from_tty) | |
1441 | { | |
1442 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1443 | } |
40c03ae8 EZ |
1444 | |
1445 | /* Like commands_command, but instead of reading the commands from | |
1446 | input stream, takes them from an already parsed command structure. | |
1447 | ||
1448 | This is used by cli-script.c to DTRT with breakpoint commands | |
1449 | that are part of if and while bodies. */ | |
1450 | enum command_control_type | |
896b6bda | 1451 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1452 | { |
95a42b64 TT |
1453 | commands_command_1 (arg, 0, cmd); |
1454 | return simple_control; | |
40c03ae8 | 1455 | } |
876fa593 JK |
1456 | |
1457 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1458 | ||
1459 | static int | |
1460 | bp_location_has_shadow (struct bp_location *bl) | |
1461 | { | |
1462 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1463 | return 0; | |
1464 | if (!bl->inserted) | |
1465 | return 0; | |
1466 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1467 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1468 | return 0; |
1469 | return 1; | |
1470 | } | |
1471 | ||
9d497a19 PA |
1472 | /* Update BUF, which is LEN bytes read from the target address |
1473 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1474 | contents. | |
1475 | ||
1476 | If READBUF is not NULL, this buffer must not overlap with the of | |
1477 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1478 | failed assertion internal error will be raised. */ | |
1479 | ||
1480 | static void | |
1481 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1482 | const gdb_byte *writebuf_org, | |
1483 | ULONGEST memaddr, LONGEST len, | |
1484 | struct bp_target_info *target_info, | |
1485 | struct gdbarch *gdbarch) | |
1486 | { | |
1487 | /* Now do full processing of the found relevant range of elements. */ | |
1488 | CORE_ADDR bp_addr = 0; | |
1489 | int bp_size = 0; | |
1490 | int bptoffset = 0; | |
1491 | ||
1492 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1493 | current_program_space->aspace, 0)) | |
1494 | { | |
1495 | /* The breakpoint is inserted in a different address space. */ | |
1496 | return; | |
1497 | } | |
1498 | ||
1499 | /* Addresses and length of the part of the breakpoint that | |
1500 | we need to copy. */ | |
1501 | bp_addr = target_info->placed_address; | |
1502 | bp_size = target_info->shadow_len; | |
1503 | ||
1504 | if (bp_addr + bp_size <= memaddr) | |
1505 | { | |
1506 | /* The breakpoint is entirely before the chunk of memory we are | |
1507 | reading. */ | |
1508 | return; | |
1509 | } | |
1510 | ||
1511 | if (bp_addr >= memaddr + len) | |
1512 | { | |
1513 | /* The breakpoint is entirely after the chunk of memory we are | |
1514 | reading. */ | |
1515 | return; | |
1516 | } | |
1517 | ||
1518 | /* Offset within shadow_contents. */ | |
1519 | if (bp_addr < memaddr) | |
1520 | { | |
1521 | /* Only copy the second part of the breakpoint. */ | |
1522 | bp_size -= memaddr - bp_addr; | |
1523 | bptoffset = memaddr - bp_addr; | |
1524 | bp_addr = memaddr; | |
1525 | } | |
1526 | ||
1527 | if (bp_addr + bp_size > memaddr + len) | |
1528 | { | |
1529 | /* Only copy the first part of the breakpoint. */ | |
1530 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1531 | } | |
1532 | ||
1533 | if (readbuf != NULL) | |
1534 | { | |
1535 | /* Verify that the readbuf buffer does not overlap with the | |
1536 | shadow_contents buffer. */ | |
1537 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1538 | || readbuf >= (target_info->shadow_contents | |
1539 | + target_info->shadow_len)); | |
1540 | ||
1541 | /* Update the read buffer with this inserted breakpoint's | |
1542 | shadow. */ | |
1543 | memcpy (readbuf + bp_addr - memaddr, | |
1544 | target_info->shadow_contents + bptoffset, bp_size); | |
1545 | } | |
1546 | else | |
1547 | { | |
1548 | const unsigned char *bp; | |
0d5ed153 MR |
1549 | CORE_ADDR addr = target_info->reqstd_address; |
1550 | int placed_size; | |
9d497a19 PA |
1551 | |
1552 | /* Update the shadow with what we want to write to memory. */ | |
1553 | memcpy (target_info->shadow_contents + bptoffset, | |
1554 | writebuf_org + bp_addr - memaddr, bp_size); | |
1555 | ||
1556 | /* Determine appropriate breakpoint contents and size for this | |
1557 | address. */ | |
0d5ed153 | 1558 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1559 | |
1560 | /* Update the final write buffer with this inserted | |
1561 | breakpoint's INSN. */ | |
1562 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1563 | } | |
1564 | } | |
1565 | ||
8defab1a | 1566 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1567 | by replacing any memory breakpoints with their shadowed contents. |
1568 | ||
35c63cd8 JB |
1569 | If READBUF is not NULL, this buffer must not overlap with any of |
1570 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1571 | a failed assertion internal error will be raised. | |
1572 | ||
876fa593 | 1573 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1574 | bl->address - bp_location_placed_address_before_address_max |
1575 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1576 | The range we were requested to resolve shadows for is: |
1577 | memaddr ... memaddr + len | |
1578 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1579 | memaddr + len <= (bl->address |
1580 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1581 | and: |
35df4500 | 1582 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1583 | |
8defab1a | 1584 | void |
f0ba3972 PA |
1585 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1586 | const gdb_byte *writebuf_org, | |
1587 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1588 | { |
4a64f543 MS |
1589 | /* Left boundary, right boundary and median element of our binary |
1590 | search. */ | |
876fa593 JK |
1591 | unsigned bc_l, bc_r, bc; |
1592 | ||
4a64f543 MS |
1593 | /* Find BC_L which is a leftmost element which may affect BUF |
1594 | content. It is safe to report lower value but a failure to | |
1595 | report higher one. */ | |
876fa593 JK |
1596 | |
1597 | bc_l = 0; | |
1598 | bc_r = bp_location_count; | |
1599 | while (bc_l + 1 < bc_r) | |
1600 | { | |
35df4500 | 1601 | struct bp_location *bl; |
876fa593 JK |
1602 | |
1603 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1604 | bl = bp_location[bc]; |
876fa593 | 1605 | |
4a64f543 MS |
1606 | /* Check first BL->ADDRESS will not overflow due to the added |
1607 | constant. Then advance the left boundary only if we are sure | |
1608 | the BC element can in no way affect the BUF content (MEMADDR | |
1609 | to MEMADDR + LEN range). | |
876fa593 | 1610 | |
4a64f543 MS |
1611 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1612 | offset so that we cannot miss a breakpoint with its shadow | |
1613 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1614 | |
35df4500 TJB |
1615 | if ((bl->address + bp_location_shadow_len_after_address_max |
1616 | >= bl->address) | |
1617 | && (bl->address + bp_location_shadow_len_after_address_max | |
1618 | <= memaddr)) | |
876fa593 JK |
1619 | bc_l = bc; |
1620 | else | |
1621 | bc_r = bc; | |
1622 | } | |
1623 | ||
128070bb PA |
1624 | /* Due to the binary search above, we need to make sure we pick the |
1625 | first location that's at BC_L's address. E.g., if there are | |
1626 | multiple locations at the same address, BC_L may end up pointing | |
1627 | at a duplicate location, and miss the "master"/"inserted" | |
1628 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1629 | B: | |
1630 | ||
1631 | L1@A, L2@A, L3@B, ... | |
1632 | ||
1633 | BC_L could end up pointing at location L2, while the "master" | |
1634 | location could be L1. Since the `loc->inserted' flag is only set | |
1635 | on "master" locations, we'd forget to restore the shadow of L1 | |
1636 | and L2. */ | |
1637 | while (bc_l > 0 | |
1638 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1639 | bc_l--; | |
1640 | ||
876fa593 JK |
1641 | /* Now do full processing of the found relevant range of elements. */ |
1642 | ||
1643 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1644 | { |
35df4500 | 1645 | struct bp_location *bl = bp_location[bc]; |
876fa593 | 1646 | |
35df4500 TJB |
1647 | /* bp_location array has BL->OWNER always non-NULL. */ |
1648 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1649 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1650 | bl->owner->number); |
ffce0d52 | 1651 | |
e5dd4106 | 1652 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1653 | content. */ |
1654 | ||
35df4500 TJB |
1655 | if (bl->address >= bp_location_placed_address_before_address_max |
1656 | && memaddr + len <= (bl->address | |
1657 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1658 | break; |
1659 | ||
35df4500 | 1660 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1661 | continue; |
6c95b8df | 1662 | |
9d497a19 PA |
1663 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1664 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1665 | } | |
c906108c | 1666 | } |
9d497a19 | 1667 | |
c906108c | 1668 | \f |
c5aa993b | 1669 | |
b775012e LM |
1670 | /* Return true if BPT is either a software breakpoint or a hardware |
1671 | breakpoint. */ | |
1672 | ||
1673 | int | |
1674 | is_breakpoint (const struct breakpoint *bpt) | |
1675 | { | |
1676 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1677 | || bpt->type == bp_hardware_breakpoint |
1678 | || bpt->type == bp_dprintf); | |
b775012e LM |
1679 | } |
1680 | ||
60e1c644 PA |
1681 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1682 | ||
a5606eee | 1683 | static int |
d77f58be | 1684 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1685 | { |
1686 | return (bpt->type == bp_hardware_watchpoint | |
1687 | || bpt->type == bp_read_watchpoint | |
1688 | || bpt->type == bp_access_watchpoint); | |
1689 | } | |
7270d8f2 | 1690 | |
60e1c644 PA |
1691 | /* Return true if BPT is of any watchpoint kind, hardware or |
1692 | software. */ | |
1693 | ||
3a5c3e22 | 1694 | int |
d77f58be | 1695 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1696 | { |
1697 | return (is_hardware_watchpoint (bpt) | |
1698 | || bpt->type == bp_watchpoint); | |
1699 | } | |
1700 | ||
3a5c3e22 PA |
1701 | /* Returns true if the current thread and its running state are safe |
1702 | to evaluate or update watchpoint B. Watchpoints on local | |
1703 | expressions need to be evaluated in the context of the thread that | |
1704 | was current when the watchpoint was created, and, that thread needs | |
1705 | to be stopped to be able to select the correct frame context. | |
1706 | Watchpoints on global expressions can be evaluated on any thread, | |
1707 | and in any state. It is presently left to the target allowing | |
1708 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1709 | |
1710 | static int | |
3a5c3e22 | 1711 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1712 | { |
d0d8b0c6 JK |
1713 | return (b->base.pspace == current_program_space |
1714 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1715 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1716 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1717 | } |
1718 | ||
d0fb5eae JK |
1719 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1720 | associated bp_watchpoint_scope breakpoint. */ | |
1721 | ||
1722 | static void | |
3a5c3e22 | 1723 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1724 | { |
3a5c3e22 | 1725 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1726 | |
1727 | if (b->related_breakpoint != b) | |
1728 | { | |
1729 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1730 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1731 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1732 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1733 | b->related_breakpoint = b; | |
1734 | } | |
1735 | b->disposition = disp_del_at_next_stop; | |
1736 | } | |
1737 | ||
bb9d5f81 PP |
1738 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1739 | watchpoint W. */ | |
1740 | ||
1741 | static struct value * | |
1742 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1743 | { | |
1744 | struct value *bit_val; | |
1745 | ||
1746 | if (val == NULL) | |
1747 | return NULL; | |
1748 | ||
1749 | bit_val = allocate_value (value_type (val)); | |
1750 | ||
1751 | unpack_value_bitfield (bit_val, | |
1752 | w->val_bitpos, | |
1753 | w->val_bitsize, | |
1754 | value_contents_for_printing (val), | |
1755 | value_offset (val), | |
1756 | val); | |
1757 | ||
1758 | return bit_val; | |
1759 | } | |
1760 | ||
c6d81124 PA |
1761 | /* Allocate a dummy location and add it to B, which must be a software |
1762 | watchpoint. This is required because even if a software watchpoint | |
1763 | is not watching any memory, bpstat_stop_status requires a location | |
1764 | to be able to report stops. */ | |
1765 | ||
1766 | static void | |
1767 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1768 | struct program_space *pspace) | |
1769 | { | |
1770 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1771 | ||
1772 | b->loc = allocate_bp_location (b); | |
1773 | b->loc->pspace = pspace; | |
1774 | b->loc->address = -1; | |
1775 | b->loc->length = -1; | |
1776 | } | |
1777 | ||
1778 | /* Returns true if B is a software watchpoint that is not watching any | |
1779 | memory (e.g., "watch $pc"). */ | |
1780 | ||
1781 | static int | |
1782 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1783 | { | |
1784 | return (b->type == bp_watchpoint | |
1785 | && b->loc != NULL | |
1786 | && b->loc->next == NULL | |
1787 | && b->loc->address == -1 | |
1788 | && b->loc->length == -1); | |
1789 | } | |
1790 | ||
567e1b4e JB |
1791 | /* Assuming that B is a watchpoint: |
1792 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1793 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1794 | - Evaluate the condition if there is one, and store the result |
1795 | in b->loc->cond. | |
a5606eee VP |
1796 | - Update the list of values that must be watched in B->loc. |
1797 | ||
4a64f543 MS |
1798 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1799 | nothing. If this is local watchpoint that is out of scope, delete | |
1800 | it. | |
1801 | ||
1802 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1803 | removed + inserted on each stop here. Normal breakpoints must | |
1804 | never be removed because they might be missed by a running thread | |
1805 | when debugging in non-stop mode. On the other hand, hardware | |
1806 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1807 | to each LWP since they are stored in each LWP's hardware debug | |
1808 | registers. Therefore, such LWP must be stopped first in order to | |
1809 | be able to modify its hardware watchpoints. | |
1810 | ||
1811 | Hardware watchpoints must be reset exactly once after being | |
1812 | presented to the user. It cannot be done sooner, because it would | |
1813 | reset the data used to present the watchpoint hit to the user. And | |
1814 | it must not be done later because it could display the same single | |
1815 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1816 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1817 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1818 | not user-visible - its hit is suppressed if the memory content has | |
1819 | not changed. | |
1820 | ||
1821 | The following constraints influence the location where we can reset | |
1822 | hardware watchpoints: | |
1823 | ||
1824 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1825 | called several times when GDB stops. | |
1826 | ||
1827 | [linux] | |
1828 | * Multiple hardware watchpoints can be hit at the same time, | |
1829 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1830 | hit at a time as the reason for stopping, and all the other hits | |
1831 | are presented later, one after the other, each time the user | |
1832 | requests the execution to be resumed. Execution is not resumed | |
1833 | for the threads still having pending hit event stored in | |
1834 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1835 | the inferior on the first stop the thread hit event is kept being | |
1836 | reported from its cached value by linux_nat_stopped_data_address | |
1837 | until the real thread resume happens after the watchpoint gets | |
1838 | presented and thus its LWP_INFO->STATUS gets reset. | |
1839 | ||
1840 | Therefore the hardware watchpoint hit can get safely reset on the | |
1841 | watchpoint removal from inferior. */ | |
a79d3c27 | 1842 | |
b40ce68a | 1843 | static void |
3a5c3e22 | 1844 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1845 | { |
a5606eee | 1846 | int within_current_scope; |
a5606eee | 1847 | struct frame_id saved_frame_id; |
66076460 | 1848 | int frame_saved; |
a5606eee | 1849 | |
f6bc2008 PA |
1850 | /* If this is a local watchpoint, we only want to check if the |
1851 | watchpoint frame is in scope if the current thread is the thread | |
1852 | that was used to create the watchpoint. */ | |
1853 | if (!watchpoint_in_thread_scope (b)) | |
1854 | return; | |
1855 | ||
3a5c3e22 | 1856 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1857 | return; |
1858 | ||
66076460 | 1859 | frame_saved = 0; |
a5606eee VP |
1860 | |
1861 | /* Determine if the watchpoint is within scope. */ | |
1862 | if (b->exp_valid_block == NULL) | |
1863 | within_current_scope = 1; | |
1864 | else | |
1865 | { | |
b5db5dfc UW |
1866 | struct frame_info *fi = get_current_frame (); |
1867 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1868 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1869 | ||
c9cf6e20 MG |
1870 | /* If we're at a point where the stack has been destroyed |
1871 | (e.g. in a function epilogue), unwinding may not work | |
1872 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1873 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1874 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1875 | return; |
66076460 DJ |
1876 | |
1877 | /* Save the current frame's ID so we can restore it after | |
1878 | evaluating the watchpoint expression on its own frame. */ | |
1879 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1880 | took a frame parameter, so that we didn't have to change the | |
1881 | selected frame. */ | |
1882 | frame_saved = 1; | |
1883 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1884 | ||
a5606eee VP |
1885 | fi = frame_find_by_id (b->watchpoint_frame); |
1886 | within_current_scope = (fi != NULL); | |
1887 | if (within_current_scope) | |
1888 | select_frame (fi); | |
1889 | } | |
1890 | ||
b5db5dfc UW |
1891 | /* We don't free locations. They are stored in the bp_location array |
1892 | and update_global_location_list will eventually delete them and | |
1893 | remove breakpoints if needed. */ | |
3a5c3e22 | 1894 | b->base.loc = NULL; |
b5db5dfc | 1895 | |
a5606eee VP |
1896 | if (within_current_scope && reparse) |
1897 | { | |
bbc13ae3 | 1898 | const char *s; |
d63d0675 | 1899 | |
a5606eee VP |
1900 | if (b->exp) |
1901 | { | |
1902 | xfree (b->exp); | |
1903 | b->exp = NULL; | |
1904 | } | |
d63d0675 | 1905 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1906 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1907 | /* If the meaning of expression itself changed, the old value is |
1908 | no longer relevant. We don't want to report a watchpoint hit | |
1909 | to the user when the old value and the new value may actually | |
1910 | be completely different objects. */ | |
1911 | value_free (b->val); | |
fa4727a6 DJ |
1912 | b->val = NULL; |
1913 | b->val_valid = 0; | |
60e1c644 PA |
1914 | |
1915 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1916 | expression is stored in the breakpoint object, not in the | |
1917 | locations (re)created below. */ | |
3a5c3e22 | 1918 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1919 | { |
1920 | if (b->cond_exp != NULL) | |
1921 | { | |
1922 | xfree (b->cond_exp); | |
1923 | b->cond_exp = NULL; | |
1924 | } | |
1925 | ||
3a5c3e22 | 1926 | s = b->base.cond_string; |
1bb9788d | 1927 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1928 | } |
a5606eee | 1929 | } |
a5606eee VP |
1930 | |
1931 | /* If we failed to parse the expression, for example because | |
1932 | it refers to a global variable in a not-yet-loaded shared library, | |
1933 | don't try to insert watchpoint. We don't automatically delete | |
1934 | such watchpoint, though, since failure to parse expression | |
1935 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1936 | if (!target_has_execution) |
2d134ed3 PA |
1937 | { |
1938 | /* Without execution, memory can't change. No use to try and | |
1939 | set watchpoint locations. The watchpoint will be reset when | |
1940 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1941 | if (!can_use_hw_watchpoints) |
1942 | { | |
1943 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1944 | b->base.type = bp_watchpoint; | |
1945 | else | |
638aa5a1 AB |
1946 | error (_("Can't set read/access watchpoint when " |
1947 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1948 | } |
2d134ed3 PA |
1949 | } |
1950 | else if (within_current_scope && b->exp) | |
a5606eee | 1951 | { |
0cf6dd15 | 1952 | int pc = 0; |
fa4727a6 | 1953 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1954 | struct program_space *frame_pspace; |
a5606eee | 1955 | |
3a1115a0 | 1956 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1957 | |
a5606eee VP |
1958 | /* Avoid setting b->val if it's already set. The meaning of |
1959 | b->val is 'the last value' user saw, and we should update | |
1960 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1961 | happens, the code that reports it updates b->val directly. |
1962 | We don't keep track of the memory value for masked | |
1963 | watchpoints. */ | |
3a5c3e22 | 1964 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1965 | { |
bb9d5f81 PP |
1966 | if (b->val_bitsize != 0) |
1967 | { | |
1968 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1969 | if (v != NULL) | |
1970 | release_value (v); | |
1971 | } | |
fa4727a6 DJ |
1972 | b->val = v; |
1973 | b->val_valid = 1; | |
1974 | } | |
a5606eee | 1975 | |
2d134ed3 PA |
1976 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1977 | ||
a5606eee | 1978 | /* Look at each value on the value chain. */ |
9fa40276 | 1979 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1980 | { |
1981 | /* If it's a memory location, and GDB actually needed | |
1982 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1983 | must watch it. If the first value returned is |
1984 | still lazy, that means an error occurred reading it; | |
1985 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1986 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1987 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1988 | { |
1989 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1990 | |
a5606eee VP |
1991 | /* We only watch structs and arrays if user asked |
1992 | for it explicitly, never if they just happen to | |
1993 | appear in the middle of some value chain. */ | |
fa4727a6 | 1994 | if (v == result |
a5606eee VP |
1995 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1996 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1997 | { | |
1998 | CORE_ADDR addr; | |
f486487f | 1999 | enum target_hw_bp_type type; |
a5606eee | 2000 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2001 | int bitpos = 0, bitsize = 0; |
2002 | ||
2003 | if (value_bitsize (v) != 0) | |
2004 | { | |
2005 | /* Extract the bit parameters out from the bitfield | |
2006 | sub-expression. */ | |
2007 | bitpos = value_bitpos (v); | |
2008 | bitsize = value_bitsize (v); | |
2009 | } | |
2010 | else if (v == result && b->val_bitsize != 0) | |
2011 | { | |
2012 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2013 | lvalue whose bit parameters are saved in the fields | |
2014 | VAL_BITPOS and VAL_BITSIZE. */ | |
2015 | bitpos = b->val_bitpos; | |
2016 | bitsize = b->val_bitsize; | |
2017 | } | |
a5606eee | 2018 | |
42ae5230 | 2019 | addr = value_address (v); |
bb9d5f81 PP |
2020 | if (bitsize != 0) |
2021 | { | |
2022 | /* Skip the bytes that don't contain the bitfield. */ | |
2023 | addr += bitpos / 8; | |
2024 | } | |
2025 | ||
a5606eee | 2026 | type = hw_write; |
3a5c3e22 | 2027 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2028 | type = hw_read; |
3a5c3e22 | 2029 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2030 | type = hw_access; |
3a5c3e22 PA |
2031 | |
2032 | loc = allocate_bp_location (&b->base); | |
2033 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2034 | ; |
2035 | *tmp = loc; | |
a6d9a66e | 2036 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2037 | |
2038 | loc->pspace = frame_pspace; | |
a5606eee | 2039 | loc->address = addr; |
bb9d5f81 PP |
2040 | |
2041 | if (bitsize != 0) | |
2042 | { | |
2043 | /* Just cover the bytes that make up the bitfield. */ | |
2044 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2045 | } | |
2046 | else | |
2047 | loc->length = TYPE_LENGTH (value_type (v)); | |
2048 | ||
a5606eee VP |
2049 | loc->watchpoint_type = type; |
2050 | } | |
2051 | } | |
9fa40276 TJB |
2052 | } |
2053 | ||
2054 | /* Change the type of breakpoint between hardware assisted or | |
2055 | an ordinary watchpoint depending on the hardware support | |
2056 | and free hardware slots. REPARSE is set when the inferior | |
2057 | is started. */ | |
a9634178 | 2058 | if (reparse) |
9fa40276 | 2059 | { |
e09342b5 | 2060 | int reg_cnt; |
9fa40276 TJB |
2061 | enum bp_loc_type loc_type; |
2062 | struct bp_location *bl; | |
a5606eee | 2063 | |
a9634178 | 2064 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2065 | |
2066 | if (reg_cnt) | |
9fa40276 TJB |
2067 | { |
2068 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2069 | enum bptype type; |
9fa40276 | 2070 | |
a9634178 TJB |
2071 | /* Use an exact watchpoint when there's only one memory region to be |
2072 | watched, and only one debug register is needed to watch it. */ | |
2073 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2074 | ||
9fa40276 | 2075 | /* We need to determine how many resources are already |
e09342b5 TJB |
2076 | used for all other hardware watchpoints plus this one |
2077 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2078 | this watchpoint in as well. */ |
2079 | ||
2080 | /* If this is a software watchpoint, we try to turn it | |
2081 | to a hardware one -- count resources as if B was of | |
2082 | hardware watchpoint type. */ | |
2083 | type = b->base.type; | |
2084 | if (type == bp_watchpoint) | |
2085 | type = bp_hardware_watchpoint; | |
2086 | ||
2087 | /* This watchpoint may or may not have been placed on | |
2088 | the list yet at this point (it won't be in the list | |
2089 | if we're trying to create it for the first time, | |
2090 | through watch_command), so always account for it | |
2091 | manually. */ | |
2092 | ||
2093 | /* Count resources used by all watchpoints except B. */ | |
2094 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2095 | ||
2096 | /* Add in the resources needed for B. */ | |
2097 | i += hw_watchpoint_use_count (&b->base); | |
2098 | ||
2099 | target_resources_ok | |
2100 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2101 | if (target_resources_ok <= 0) |
a9634178 | 2102 | { |
3a5c3e22 | 2103 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2104 | |
2105 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2106 | error (_("Target does not support this type of " |
2107 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2108 | else if (target_resources_ok < 0 && !sw_mode) |
2109 | error (_("There are not enough available hardware " | |
2110 | "resources for this watchpoint.")); | |
a1398e0c PA |
2111 | |
2112 | /* Downgrade to software watchpoint. */ | |
2113 | b->base.type = bp_watchpoint; | |
2114 | } | |
2115 | else | |
2116 | { | |
2117 | /* If this was a software watchpoint, we've just | |
2118 | found we have enough resources to turn it to a | |
2119 | hardware watchpoint. Otherwise, this is a | |
2120 | nop. */ | |
2121 | b->base.type = type; | |
a9634178 | 2122 | } |
9fa40276 | 2123 | } |
3a5c3e22 | 2124 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2125 | { |
2126 | if (!can_use_hw_watchpoints) | |
2127 | error (_("Can't set read/access watchpoint when " | |
2128 | "hardware watchpoints are disabled.")); | |
2129 | else | |
2130 | error (_("Expression cannot be implemented with " | |
2131 | "read/access watchpoint.")); | |
2132 | } | |
9fa40276 | 2133 | else |
3a5c3e22 | 2134 | b->base.type = bp_watchpoint; |
9fa40276 | 2135 | |
3a5c3e22 | 2136 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2137 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2138 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2139 | bl->loc_type = loc_type; |
2140 | } | |
2141 | ||
2142 | for (v = val_chain; v; v = next) | |
2143 | { | |
a5606eee VP |
2144 | next = value_next (v); |
2145 | if (v != b->val) | |
2146 | value_free (v); | |
2147 | } | |
2148 | ||
c7437ca6 PA |
2149 | /* If a software watchpoint is not watching any memory, then the |
2150 | above left it without any location set up. But, | |
2151 | bpstat_stop_status requires a location to be able to report | |
2152 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2153 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2154 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2155 | } |
2156 | else if (!within_current_scope) | |
7270d8f2 | 2157 | { |
ac74f770 MS |
2158 | printf_filtered (_("\ |
2159 | Watchpoint %d deleted because the program has left the block\n\ | |
2160 | in which its expression is valid.\n"), | |
3a5c3e22 | 2161 | b->base.number); |
d0fb5eae | 2162 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2163 | } |
a5606eee VP |
2164 | |
2165 | /* Restore the selected frame. */ | |
66076460 DJ |
2166 | if (frame_saved) |
2167 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2168 | } |
2169 | ||
a5606eee | 2170 | |
74960c60 | 2171 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2172 | inserted in the inferior. We don't differentiate the type of BL's owner |
2173 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2174 | breakpoint_ops is not defined, because in insert_bp_location, | |
2175 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2176 | static int |
35df4500 | 2177 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2178 | { |
35df4500 | 2179 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2180 | return 0; |
2181 | ||
35df4500 | 2182 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2183 | return 0; |
2184 | ||
35df4500 | 2185 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2186 | return 0; |
2187 | ||
f8eba3c6 TT |
2188 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2189 | return 0; | |
2190 | ||
56710373 PA |
2191 | /* This is set for example, when we're attached to the parent of a |
2192 | vfork, and have detached from the child. The child is running | |
2193 | free, and we expect it to do an exec or exit, at which point the | |
2194 | OS makes the parent schedulable again (and the target reports | |
2195 | that the vfork is done). Until the child is done with the shared | |
2196 | memory region, do not insert breakpoints in the parent, otherwise | |
2197 | the child could still trip on the parent's breakpoints. Since | |
2198 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2199 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2200 | return 0; |
2201 | ||
31e77af2 | 2202 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2203 | location, except if the breakpoint is a single-step breakpoint, |
2204 | and the breakpoint's thread is the thread which is stepping past | |
2205 | a breakpoint. */ | |
31e77af2 PA |
2206 | if ((bl->loc_type == bp_loc_software_breakpoint |
2207 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2208 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2209 | bl->address) |
2210 | /* The single-step breakpoint may be inserted at the location | |
2211 | we're trying to step if the instruction branches to itself. | |
2212 | However, the instruction won't be executed at all and it may | |
2213 | break the semantics of the instruction, for example, the | |
2214 | instruction is a conditional branch or updates some flags. | |
2215 | We can't fix it unless GDB is able to emulate the instruction | |
2216 | or switch to displaced stepping. */ | |
2217 | && !(bl->owner->type == bp_single_step | |
2218 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2219 | { |
2220 | if (debug_infrun) | |
2221 | { | |
2222 | fprintf_unfiltered (gdb_stdlog, | |
2223 | "infrun: skipping breakpoint: " | |
2224 | "stepping past insn at: %s\n", | |
2225 | paddress (bl->gdbarch, bl->address)); | |
2226 | } | |
2227 | return 0; | |
2228 | } | |
31e77af2 | 2229 | |
963f9c80 PA |
2230 | /* Don't insert watchpoints if we're trying to step past the |
2231 | instruction that triggered one. */ | |
2232 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2233 | && stepping_past_nonsteppable_watchpoint ()) | |
2234 | { | |
2235 | if (debug_infrun) | |
2236 | { | |
2237 | fprintf_unfiltered (gdb_stdlog, | |
2238 | "infrun: stepping past non-steppable watchpoint. " | |
2239 | "skipping watchpoint at %s:%d\n", | |
2240 | paddress (bl->gdbarch, bl->address), | |
2241 | bl->length); | |
2242 | } | |
2243 | return 0; | |
2244 | } | |
2245 | ||
74960c60 VP |
2246 | return 1; |
2247 | } | |
2248 | ||
934709f0 PW |
2249 | /* Same as should_be_inserted but does the check assuming |
2250 | that the location is not duplicated. */ | |
2251 | ||
2252 | static int | |
2253 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2254 | { | |
2255 | int result; | |
2256 | const int save_duplicate = bl->duplicate; | |
2257 | ||
2258 | bl->duplicate = 0; | |
2259 | result = should_be_inserted (bl); | |
2260 | bl->duplicate = save_duplicate; | |
2261 | return result; | |
2262 | } | |
2263 | ||
b775012e LM |
2264 | /* Parses a conditional described by an expression COND into an |
2265 | agent expression bytecode suitable for evaluation | |
2266 | by the bytecode interpreter. Return NULL if there was | |
2267 | any error during parsing. */ | |
2268 | ||
2269 | static struct agent_expr * | |
2270 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2271 | { | |
2272 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2273 | |
2274 | if (!cond) | |
2275 | return NULL; | |
2276 | ||
2277 | /* We don't want to stop processing, so catch any errors | |
2278 | that may show up. */ | |
492d29ea | 2279 | TRY |
b775012e LM |
2280 | { |
2281 | aexpr = gen_eval_for_expr (scope, cond); | |
2282 | } | |
2283 | ||
492d29ea | 2284 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2285 | { |
2286 | /* If we got here, it means the condition could not be parsed to a valid | |
2287 | bytecode expression and thus can't be evaluated on the target's side. | |
2288 | It's no use iterating through the conditions. */ | |
2289 | return NULL; | |
2290 | } | |
492d29ea | 2291 | END_CATCH |
b775012e LM |
2292 | |
2293 | /* We have a valid agent expression. */ | |
2294 | return aexpr; | |
2295 | } | |
2296 | ||
2297 | /* Based on location BL, create a list of breakpoint conditions to be | |
2298 | passed on to the target. If we have duplicated locations with different | |
2299 | conditions, we will add such conditions to the list. The idea is that the | |
2300 | target will evaluate the list of conditions and will only notify GDB when | |
2301 | one of them is true. */ | |
2302 | ||
2303 | static void | |
2304 | build_target_condition_list (struct bp_location *bl) | |
2305 | { | |
2306 | struct bp_location **locp = NULL, **loc2p; | |
2307 | int null_condition_or_parse_error = 0; | |
2308 | int modified = bl->needs_update; | |
2309 | struct bp_location *loc; | |
2310 | ||
8b4f3082 PA |
2311 | /* Release conditions left over from a previous insert. */ |
2312 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2313 | ||
b775012e LM |
2314 | /* This is only meaningful if the target is |
2315 | evaluating conditions and if the user has | |
2316 | opted for condition evaluation on the target's | |
2317 | side. */ | |
2318 | if (gdb_evaluates_breakpoint_condition_p () | |
2319 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2320 | return; | |
2321 | ||
2322 | /* Do a first pass to check for locations with no assigned | |
2323 | conditions or conditions that fail to parse to a valid agent expression | |
2324 | bytecode. If any of these happen, then it's no use to send conditions | |
2325 | to the target since this location will always trigger and generate a | |
2326 | response back to GDB. */ | |
2327 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2328 | { | |
2329 | loc = (*loc2p); | |
2330 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2331 | { | |
2332 | if (modified) | |
2333 | { | |
2334 | struct agent_expr *aexpr; | |
2335 | ||
2336 | /* Re-parse the conditions since something changed. In that | |
2337 | case we already freed the condition bytecodes (see | |
2338 | force_breakpoint_reinsertion). We just | |
2339 | need to parse the condition to bytecodes again. */ | |
2340 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2341 | loc->cond_bytecode = aexpr; | |
b775012e LM |
2342 | } |
2343 | ||
2344 | /* If we have a NULL bytecode expression, it means something | |
2345 | went wrong or we have a null condition expression. */ | |
2346 | if (!loc->cond_bytecode) | |
2347 | { | |
2348 | null_condition_or_parse_error = 1; | |
2349 | break; | |
2350 | } | |
2351 | } | |
2352 | } | |
2353 | ||
2354 | /* If any of these happened, it means we will have to evaluate the conditions | |
2355 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2356 | for all the other duplicate locations, thus we free all of them here. | |
2357 | ||
2358 | This is so we have a finer control over which locations' conditions are | |
2359 | being evaluated by GDB or the remote stub. */ | |
2360 | if (null_condition_or_parse_error) | |
2361 | { | |
2362 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2363 | { | |
2364 | loc = (*loc2p); | |
2365 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2366 | { | |
2367 | /* Only go as far as the first NULL bytecode is | |
2368 | located. */ | |
2369 | if (!loc->cond_bytecode) | |
2370 | return; | |
2371 | ||
2372 | free_agent_expr (loc->cond_bytecode); | |
2373 | loc->cond_bytecode = NULL; | |
2374 | } | |
2375 | } | |
2376 | } | |
2377 | ||
2378 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2379 | for this location's address. */ | |
2380 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2381 | { | |
2382 | loc = (*loc2p); | |
2383 | if (loc->cond | |
2384 | && is_breakpoint (loc->owner) | |
2385 | && loc->pspace->num == bl->pspace->num | |
2386 | && loc->owner->enable_state == bp_enabled | |
2387 | && loc->enabled) | |
2388 | /* Add the condition to the vector. This will be used later to send the | |
2389 | conditions to the target. */ | |
2390 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2391 | loc->cond_bytecode); | |
2392 | } | |
2393 | ||
2394 | return; | |
2395 | } | |
2396 | ||
d3ce09f5 SS |
2397 | /* Parses a command described by string CMD into an agent expression |
2398 | bytecode suitable for evaluation by the bytecode interpreter. | |
2399 | Return NULL if there was any error during parsing. */ | |
2400 | ||
2401 | static struct agent_expr * | |
2402 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2403 | { | |
2404 | struct cleanup *old_cleanups = 0; | |
2405 | struct expression *expr, **argvec; | |
2406 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2407 | const char *cmdrest; |
2408 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2409 | struct format_piece *fpieces; |
2410 | int nargs; | |
2411 | struct gdbarch *gdbarch = get_current_arch (); | |
2412 | ||
2413 | if (!cmd) | |
2414 | return NULL; | |
2415 | ||
2416 | cmdrest = cmd; | |
2417 | ||
2418 | if (*cmdrest == ',') | |
2419 | ++cmdrest; | |
bbc13ae3 | 2420 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2421 | |
2422 | if (*cmdrest++ != '"') | |
2423 | error (_("No format string following the location")); | |
2424 | ||
2425 | format_start = cmdrest; | |
2426 | ||
2427 | fpieces = parse_format_string (&cmdrest); | |
2428 | ||
2429 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2430 | ||
2431 | format_end = cmdrest; | |
2432 | ||
2433 | if (*cmdrest++ != '"') | |
2434 | error (_("Bad format string, non-terminated '\"'.")); | |
2435 | ||
bbc13ae3 | 2436 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2437 | |
2438 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2439 | error (_("Invalid argument syntax")); | |
2440 | ||
2441 | if (*cmdrest == ',') | |
2442 | cmdrest++; | |
bbc13ae3 | 2443 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2444 | |
2445 | /* For each argument, make an expression. */ | |
2446 | ||
2447 | argvec = (struct expression **) alloca (strlen (cmd) | |
2448 | * sizeof (struct expression *)); | |
2449 | ||
2450 | nargs = 0; | |
2451 | while (*cmdrest != '\0') | |
2452 | { | |
bbc13ae3 | 2453 | const char *cmd1; |
d3ce09f5 SS |
2454 | |
2455 | cmd1 = cmdrest; | |
2456 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2457 | argvec[nargs++] = expr; | |
2458 | cmdrest = cmd1; | |
2459 | if (*cmdrest == ',') | |
2460 | ++cmdrest; | |
2461 | } | |
2462 | ||
2463 | /* We don't want to stop processing, so catch any errors | |
2464 | that may show up. */ | |
492d29ea | 2465 | TRY |
d3ce09f5 SS |
2466 | { |
2467 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2468 | format_start, format_end - format_start, | |
2469 | fpieces, nargs, argvec); | |
2470 | } | |
492d29ea | 2471 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2472 | { |
2473 | /* If we got here, it means the command could not be parsed to a valid | |
2474 | bytecode expression and thus can't be evaluated on the target's side. | |
2475 | It's no use iterating through the other commands. */ | |
492d29ea | 2476 | aexpr = NULL; |
d3ce09f5 | 2477 | } |
492d29ea PA |
2478 | END_CATCH |
2479 | ||
2480 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2481 | |
d3ce09f5 SS |
2482 | /* We have a valid agent expression, return it. */ |
2483 | return aexpr; | |
2484 | } | |
2485 | ||
2486 | /* Based on location BL, create a list of breakpoint commands to be | |
2487 | passed on to the target. If we have duplicated locations with | |
2488 | different commands, we will add any such to the list. */ | |
2489 | ||
2490 | static void | |
2491 | build_target_command_list (struct bp_location *bl) | |
2492 | { | |
2493 | struct bp_location **locp = NULL, **loc2p; | |
2494 | int null_command_or_parse_error = 0; | |
2495 | int modified = bl->needs_update; | |
2496 | struct bp_location *loc; | |
2497 | ||
8b4f3082 PA |
2498 | /* Release commands left over from a previous insert. */ |
2499 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2500 | ||
41fac0cf | 2501 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2502 | return; |
2503 | ||
41fac0cf PA |
2504 | /* For now, limit to agent-style dprintf breakpoints. */ |
2505 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2506 | return; |
2507 | ||
41fac0cf PA |
2508 | /* For now, if we have any duplicate location that isn't a dprintf, |
2509 | don't install the target-side commands, as that would make the | |
2510 | breakpoint not be reported to the core, and we'd lose | |
2511 | control. */ | |
2512 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2513 | { | |
2514 | loc = (*loc2p); | |
2515 | if (is_breakpoint (loc->owner) | |
2516 | && loc->pspace->num == bl->pspace->num | |
2517 | && loc->owner->type != bp_dprintf) | |
2518 | return; | |
2519 | } | |
2520 | ||
d3ce09f5 SS |
2521 | /* Do a first pass to check for locations with no assigned |
2522 | conditions or conditions that fail to parse to a valid agent expression | |
2523 | bytecode. If any of these happen, then it's no use to send conditions | |
2524 | to the target since this location will always trigger and generate a | |
2525 | response back to GDB. */ | |
2526 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2527 | { | |
2528 | loc = (*loc2p); | |
2529 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2530 | { | |
2531 | if (modified) | |
2532 | { | |
2533 | struct agent_expr *aexpr; | |
2534 | ||
2535 | /* Re-parse the commands since something changed. In that | |
2536 | case we already freed the command bytecodes (see | |
2537 | force_breakpoint_reinsertion). We just | |
2538 | need to parse the command to bytecodes again. */ | |
2539 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2540 | loc->owner->extra_string); | |
2541 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2542 | } |
2543 | ||
2544 | /* If we have a NULL bytecode expression, it means something | |
2545 | went wrong or we have a null command expression. */ | |
2546 | if (!loc->cmd_bytecode) | |
2547 | { | |
2548 | null_command_or_parse_error = 1; | |
2549 | break; | |
2550 | } | |
2551 | } | |
2552 | } | |
2553 | ||
2554 | /* If anything failed, then we're not doing target-side commands, | |
2555 | and so clean up. */ | |
2556 | if (null_command_or_parse_error) | |
2557 | { | |
2558 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2559 | { | |
2560 | loc = (*loc2p); | |
2561 | if (is_breakpoint (loc->owner) | |
2562 | && loc->pspace->num == bl->pspace->num) | |
2563 | { | |
2564 | /* Only go as far as the first NULL bytecode is | |
2565 | located. */ | |
40fb6c5e | 2566 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2567 | return; |
2568 | ||
40fb6c5e HZ |
2569 | free_agent_expr (loc->cmd_bytecode); |
2570 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2571 | } |
2572 | } | |
2573 | } | |
2574 | ||
2575 | /* No NULL commands or failed bytecode generation. Build a command list | |
2576 | for this location's address. */ | |
2577 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2578 | { | |
2579 | loc = (*loc2p); | |
2580 | if (loc->owner->extra_string | |
2581 | && is_breakpoint (loc->owner) | |
2582 | && loc->pspace->num == bl->pspace->num | |
2583 | && loc->owner->enable_state == bp_enabled | |
2584 | && loc->enabled) | |
2585 | /* Add the command to the vector. This will be used later | |
2586 | to send the commands to the target. */ | |
2587 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2588 | loc->cmd_bytecode); | |
2589 | } | |
2590 | ||
2591 | bl->target_info.persist = 0; | |
2592 | /* Maybe flag this location as persistent. */ | |
2593 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2594 | bl->target_info.persist = 1; | |
2595 | } | |
2596 | ||
833b7ab5 YQ |
2597 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2598 | of breakpoint according to ADDR except single-step breakpoint. | |
2599 | Get the kind of single-step breakpoint according to the current | |
2600 | registers state. */ | |
cd6c3b4f YQ |
2601 | |
2602 | static int | |
2603 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2604 | { | |
833b7ab5 YQ |
2605 | if (bl->owner->type == bp_single_step) |
2606 | { | |
2607 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2608 | struct regcache *regcache; | |
2609 | ||
2610 | regcache = get_thread_regcache (thr->ptid); | |
2611 | ||
2612 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2613 | regcache, addr); | |
2614 | } | |
2615 | else | |
2616 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2617 | } |
2618 | ||
35df4500 TJB |
2619 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2620 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2621 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2622 | Returns 0 for success, 1 if the bp_location type is not supported or |
2623 | -1 for failure. | |
879bfdc2 | 2624 | |
4a64f543 MS |
2625 | NOTE drow/2003-09-09: This routine could be broken down to an |
2626 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2627 | static int |
35df4500 | 2628 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2629 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2630 | int *disabled_breaks, |
dd61ec5c MW |
2631 | int *hw_breakpoint_error, |
2632 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2633 | { |
0000e5cc PA |
2634 | enum errors bp_err = GDB_NO_ERROR; |
2635 | const char *bp_err_message = NULL; | |
879bfdc2 | 2636 | |
b775012e | 2637 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2638 | return 0; |
2639 | ||
35c63cd8 JB |
2640 | /* Note we don't initialize bl->target_info, as that wipes out |
2641 | the breakpoint location's shadow_contents if the breakpoint | |
2642 | is still inserted at that location. This in turn breaks | |
2643 | target_read_memory which depends on these buffers when | |
2644 | a memory read is requested at the breakpoint location: | |
2645 | Once the target_info has been wiped, we fail to see that | |
2646 | we have a breakpoint inserted at that address and thus | |
2647 | read the breakpoint instead of returning the data saved in | |
2648 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2649 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2650 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2651 | bl->target_info.length = bl->length; |
8181d85f | 2652 | |
b775012e LM |
2653 | /* When working with target-side conditions, we must pass all the conditions |
2654 | for the same breakpoint address down to the target since GDB will not | |
2655 | insert those locations. With a list of breakpoint conditions, the target | |
2656 | can decide when to stop and notify GDB. */ | |
2657 | ||
2658 | if (is_breakpoint (bl->owner)) | |
2659 | { | |
2660 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2661 | build_target_command_list (bl); |
2662 | /* Reset the modification marker. */ | |
b775012e LM |
2663 | bl->needs_update = 0; |
2664 | } | |
2665 | ||
35df4500 TJB |
2666 | if (bl->loc_type == bp_loc_software_breakpoint |
2667 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2668 | { |
35df4500 | 2669 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2670 | { |
2671 | /* If the explicitly specified breakpoint type | |
2672 | is not hardware breakpoint, check the memory map to see | |
2673 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2674 | |
765dc015 VP |
2675 | Two important cases are: |
2676 | - location type is not hardware breakpoint, memory | |
2677 | is readonly. We change the type of the location to | |
2678 | hardware breakpoint. | |
4a64f543 MS |
2679 | - location type is hardware breakpoint, memory is |
2680 | read-write. This means we've previously made the | |
2681 | location hardware one, but then the memory map changed, | |
2682 | so we undo. | |
765dc015 | 2683 | |
4a64f543 MS |
2684 | When breakpoints are removed, remove_breakpoints will use |
2685 | location types we've just set here, the only possible | |
2686 | problem is that memory map has changed during running | |
2687 | program, but it's not going to work anyway with current | |
2688 | gdb. */ | |
765dc015 | 2689 | struct mem_region *mr |
0d5ed153 | 2690 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2691 | |
2692 | if (mr) | |
2693 | { | |
2694 | if (automatic_hardware_breakpoints) | |
2695 | { | |
765dc015 VP |
2696 | enum bp_loc_type new_type; |
2697 | ||
2698 | if (mr->attrib.mode != MEM_RW) | |
2699 | new_type = bp_loc_hardware_breakpoint; | |
2700 | else | |
2701 | new_type = bp_loc_software_breakpoint; | |
2702 | ||
35df4500 | 2703 | if (new_type != bl->loc_type) |
765dc015 VP |
2704 | { |
2705 | static int said = 0; | |
cc59ec59 | 2706 | |
35df4500 | 2707 | bl->loc_type = new_type; |
765dc015 VP |
2708 | if (!said) |
2709 | { | |
3e43a32a MS |
2710 | fprintf_filtered (gdb_stdout, |
2711 | _("Note: automatically using " | |
2712 | "hardware breakpoints for " | |
2713 | "read-only addresses.\n")); | |
765dc015 VP |
2714 | said = 1; |
2715 | } | |
2716 | } | |
2717 | } | |
35df4500 | 2718 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2719 | && mr->attrib.mode != MEM_RW) |
2720 | { | |
2721 | fprintf_unfiltered (tmp_error_stream, | |
2722 | _("Cannot insert breakpoint %d.\n" | |
2723 | "Cannot set software breakpoint " | |
2724 | "at read-only address %s\n"), | |
2725 | bl->owner->number, | |
2726 | paddress (bl->gdbarch, bl->address)); | |
2727 | return 1; | |
2728 | } | |
765dc015 VP |
2729 | } |
2730 | } | |
2731 | ||
879bfdc2 DJ |
2732 | /* First check to see if we have to handle an overlay. */ |
2733 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2734 | || bl->section == NULL |
2735 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2736 | { |
2737 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2738 | TRY |
dd61ec5c | 2739 | { |
0000e5cc PA |
2740 | int val; |
2741 | ||
dd61ec5c | 2742 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2743 | if (val) |
2744 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2745 | } |
492d29ea | 2746 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2747 | { |
0000e5cc PA |
2748 | bp_err = e.error; |
2749 | bp_err_message = e.message; | |
dd61ec5c | 2750 | } |
492d29ea | 2751 | END_CATCH |
879bfdc2 DJ |
2752 | } |
2753 | else | |
2754 | { | |
4a64f543 | 2755 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2756 | Shall we set a breakpoint at the LMA? */ |
2757 | if (!overlay_events_enabled) | |
2758 | { | |
2759 | /* Yes -- overlay event support is not active, | |
2760 | so we must try to set a breakpoint at the LMA. | |
2761 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2762 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2763 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2764 | bl->owner->number); |
879bfdc2 DJ |
2765 | else |
2766 | { | |
35df4500 TJB |
2767 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2768 | bl->section); | |
879bfdc2 | 2769 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2770 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2771 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2772 | |
2773 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2774 | TRY |
0000e5cc PA |
2775 | { |
2776 | int val; | |
2777 | ||
579c6ad9 | 2778 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2779 | = breakpoint_kind (bl, &addr); |
2780 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2781 | val = target_insert_breakpoint (bl->gdbarch, |
2782 | &bl->overlay_target_info); | |
2783 | if (val) | |
2784 | bp_err = GENERIC_ERROR; | |
2785 | } | |
492d29ea | 2786 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2787 | { |
2788 | bp_err = e.error; | |
2789 | bp_err_message = e.message; | |
2790 | } | |
492d29ea | 2791 | END_CATCH |
0000e5cc PA |
2792 | |
2793 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2794 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2795 | "Overlay breakpoint %d " |
2796 | "failed: in ROM?\n", | |
35df4500 | 2797 | bl->owner->number); |
879bfdc2 DJ |
2798 | } |
2799 | } | |
2800 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2801 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2802 | { |
2803 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2804 | TRY |
dd61ec5c | 2805 | { |
0000e5cc PA |
2806 | int val; |
2807 | ||
dd61ec5c | 2808 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2809 | if (val) |
2810 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2811 | } |
492d29ea | 2812 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2813 | { |
0000e5cc PA |
2814 | bp_err = e.error; |
2815 | bp_err_message = e.message; | |
dd61ec5c | 2816 | } |
492d29ea | 2817 | END_CATCH |
879bfdc2 DJ |
2818 | } |
2819 | else | |
2820 | { | |
2821 | /* No. This breakpoint will not be inserted. | |
2822 | No error, but do not mark the bp as 'inserted'. */ | |
2823 | return 0; | |
2824 | } | |
2825 | } | |
2826 | ||
0000e5cc | 2827 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2828 | { |
2829 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2830 | |
2831 | /* In some cases, we might not be able to insert a | |
2832 | breakpoint in a shared library that has already been | |
2833 | removed, but we have not yet processed the shlib unload | |
2834 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2835 | breakpoint insertion themselves can't tell why the |
2836 | breakpoint insertion failed (e.g., the remote target | |
2837 | doesn't define error codes), so we must treat generic | |
2838 | errors as memory errors. */ | |
0000e5cc | 2839 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2840 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2841 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2842 | || shared_objfile_contains_address_p (bl->pspace, |
2843 | bl->address))) | |
879bfdc2 | 2844 | { |
4a64f543 | 2845 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2846 | bl->shlib_disabled = 1; |
8d3788bd | 2847 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2848 | if (!*disabled_breaks) |
2849 | { | |
2850 | fprintf_unfiltered (tmp_error_stream, | |
2851 | "Cannot insert breakpoint %d.\n", | |
2852 | bl->owner->number); | |
2853 | fprintf_unfiltered (tmp_error_stream, | |
2854 | "Temporarily disabling shared " | |
2855 | "library breakpoints:\n"); | |
2856 | } | |
2857 | *disabled_breaks = 1; | |
879bfdc2 | 2858 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2859 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2860 | return 0; |
879bfdc2 DJ |
2861 | } |
2862 | else | |
879bfdc2 | 2863 | { |
35df4500 | 2864 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2865 | { |
0000e5cc PA |
2866 | *hw_breakpoint_error = 1; |
2867 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2868 | fprintf_unfiltered (tmp_error_stream, |
2869 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2870 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2871 | if (bp_err_message != NULL) | |
2872 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2873 | } |
2874 | else | |
2875 | { | |
0000e5cc PA |
2876 | if (bp_err_message == NULL) |
2877 | { | |
2878 | char *message | |
2879 | = memory_error_message (TARGET_XFER_E_IO, | |
2880 | bl->gdbarch, bl->address); | |
2881 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2882 | ||
2883 | fprintf_unfiltered (tmp_error_stream, | |
2884 | "Cannot insert breakpoint %d.\n" | |
2885 | "%s\n", | |
2886 | bl->owner->number, message); | |
2887 | do_cleanups (old_chain); | |
2888 | } | |
2889 | else | |
2890 | { | |
2891 | fprintf_unfiltered (tmp_error_stream, | |
2892 | "Cannot insert breakpoint %d: %s\n", | |
2893 | bl->owner->number, | |
2894 | bp_err_message); | |
2895 | } | |
879bfdc2 | 2896 | } |
0000e5cc | 2897 | return 1; |
879bfdc2 DJ |
2898 | |
2899 | } | |
2900 | } | |
2901 | else | |
35df4500 | 2902 | bl->inserted = 1; |
879bfdc2 | 2903 | |
0000e5cc | 2904 | return 0; |
879bfdc2 DJ |
2905 | } |
2906 | ||
35df4500 | 2907 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2908 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2909 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2910 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2911 | { |
0000e5cc PA |
2912 | int val; |
2913 | ||
77b06cd7 TJB |
2914 | gdb_assert (bl->owner->ops != NULL |
2915 | && bl->owner->ops->insert_location != NULL); | |
2916 | ||
2917 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2918 | |
2919 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2920 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2921 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2922 | { |
2923 | struct bp_location *loc, **loc_temp; | |
2924 | ||
2925 | /* But don't try to insert it, if there's already another | |
2926 | hw_access location that would be considered a duplicate | |
2927 | of this one. */ | |
2928 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2929 | if (loc != bl |
85d721b8 | 2930 | && loc->watchpoint_type == hw_access |
35df4500 | 2931 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2932 | { |
35df4500 TJB |
2933 | bl->duplicate = 1; |
2934 | bl->inserted = 1; | |
2935 | bl->target_info = loc->target_info; | |
2936 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2937 | val = 0; |
2938 | break; | |
2939 | } | |
2940 | ||
2941 | if (val == 1) | |
2942 | { | |
77b06cd7 TJB |
2943 | bl->watchpoint_type = hw_access; |
2944 | val = bl->owner->ops->insert_location (bl); | |
2945 | ||
2946 | if (val) | |
2947 | /* Back to the original value. */ | |
2948 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2949 | } |
2950 | } | |
2951 | ||
35df4500 | 2952 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2953 | } |
2954 | ||
35df4500 | 2955 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2956 | { |
0000e5cc PA |
2957 | int val; |
2958 | ||
77b06cd7 TJB |
2959 | gdb_assert (bl->owner->ops != NULL |
2960 | && bl->owner->ops->insert_location != NULL); | |
2961 | ||
2962 | val = bl->owner->ops->insert_location (bl); | |
2963 | if (val) | |
2964 | { | |
2965 | bl->owner->enable_state = bp_disabled; | |
2966 | ||
2967 | if (val == 1) | |
2968 | warning (_("\ | |
2969 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2970 | of catchpoint."), bl->owner->number); | |
2971 | else | |
2972 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2973 | } | |
2974 | ||
2975 | bl->inserted = (val == 0); | |
1640b821 DJ |
2976 | |
2977 | /* We've already printed an error message if there was a problem | |
2978 | inserting this catchpoint, and we've disabled the catchpoint, | |
2979 | so just return success. */ | |
2980 | return 0; | |
879bfdc2 DJ |
2981 | } |
2982 | ||
2983 | return 0; | |
2984 | } | |
2985 | ||
6c95b8df PA |
2986 | /* This function is called when program space PSPACE is about to be |
2987 | deleted. It takes care of updating breakpoints to not reference | |
2988 | PSPACE anymore. */ | |
2989 | ||
2990 | void | |
2991 | breakpoint_program_space_exit (struct program_space *pspace) | |
2992 | { | |
2993 | struct breakpoint *b, *b_temp; | |
876fa593 | 2994 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2995 | |
2996 | /* Remove any breakpoint that was set through this program space. */ | |
2997 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2998 | { | |
2999 | if (b->pspace == pspace) | |
3000 | delete_breakpoint (b); | |
3001 | } | |
3002 | ||
3003 | /* Breakpoints set through other program spaces could have locations | |
3004 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 3005 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
3006 | { |
3007 | struct bp_location *tmp; | |
3008 | ||
3009 | if (loc->pspace == pspace) | |
3010 | { | |
2bdf28a0 | 3011 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3012 | if (loc->owner->loc == loc) |
3013 | loc->owner->loc = loc->next; | |
3014 | else | |
3015 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3016 | if (tmp->next == loc) | |
3017 | { | |
3018 | tmp->next = loc->next; | |
3019 | break; | |
3020 | } | |
3021 | } | |
3022 | } | |
3023 | ||
3024 | /* Now update the global location list to permanently delete the | |
3025 | removed locations above. */ | |
44702360 | 3026 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3027 | } |
3028 | ||
74960c60 VP |
3029 | /* Make sure all breakpoints are inserted in inferior. |
3030 | Throws exception on any error. | |
3031 | A breakpoint that is already inserted won't be inserted | |
3032 | again, so calling this function twice is safe. */ | |
3033 | void | |
3034 | insert_breakpoints (void) | |
3035 | { | |
3036 | struct breakpoint *bpt; | |
3037 | ||
3038 | ALL_BREAKPOINTS (bpt) | |
3039 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3040 | { |
3041 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3042 | ||
3043 | update_watchpoint (w, 0 /* don't reparse. */); | |
3044 | } | |
74960c60 | 3045 | |
04086b45 PA |
3046 | /* Updating watchpoints creates new locations, so update the global |
3047 | location list. Explicitly tell ugll to insert locations and | |
3048 | ignore breakpoints_always_inserted_mode. */ | |
3049 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3050 | } |
3051 | ||
20388dd6 YQ |
3052 | /* Invoke CALLBACK for each of bp_location. */ |
3053 | ||
3054 | void | |
3055 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3056 | { | |
3057 | struct bp_location *loc, **loc_tmp; | |
3058 | ||
3059 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3060 | { | |
3061 | callback (loc, NULL); | |
3062 | } | |
3063 | } | |
3064 | ||
b775012e LM |
3065 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3066 | target. It is the case with deleting and disabling of breakpoints when using | |
3067 | always-inserted mode. */ | |
3068 | ||
3069 | static void | |
3070 | update_inserted_breakpoint_locations (void) | |
3071 | { | |
3072 | struct bp_location *bl, **blp_tmp; | |
3073 | int error_flag = 0; | |
3074 | int val = 0; | |
3075 | int disabled_breaks = 0; | |
3076 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3077 | int hw_bp_details_reported = 0; |
b775012e LM |
3078 | |
3079 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3080 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3081 | ||
3082 | /* Explicitly mark the warning -- this will only be printed if | |
3083 | there was an error. */ | |
3084 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3085 | ||
3086 | save_current_space_and_thread (); | |
3087 | ||
3088 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3089 | { | |
3090 | /* We only want to update software breakpoints and hardware | |
3091 | breakpoints. */ | |
3092 | if (!is_breakpoint (bl->owner)) | |
3093 | continue; | |
3094 | ||
3095 | /* We only want to update locations that are already inserted | |
3096 | and need updating. This is to avoid unwanted insertion during | |
3097 | deletion of breakpoints. */ | |
3098 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3099 | continue; | |
3100 | ||
3101 | switch_to_program_space_and_thread (bl->pspace); | |
3102 | ||
3103 | /* For targets that support global breakpoints, there's no need | |
3104 | to select an inferior to insert breakpoint to. In fact, even | |
3105 | if we aren't attached to any process yet, we should still | |
3106 | insert breakpoints. */ | |
f5656ead | 3107 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3108 | && ptid_equal (inferior_ptid, null_ptid)) |
3109 | continue; | |
3110 | ||
3111 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3112 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3113 | if (val) |
3114 | error_flag = val; | |
3115 | } | |
3116 | ||
3117 | if (error_flag) | |
3118 | { | |
3119 | target_terminal_ours_for_output (); | |
3120 | error_stream (tmp_error_stream); | |
3121 | } | |
3122 | ||
3123 | do_cleanups (cleanups); | |
3124 | } | |
3125 | ||
c30eee59 | 3126 | /* Used when starting or continuing the program. */ |
c906108c | 3127 | |
74960c60 VP |
3128 | static void |
3129 | insert_breakpoint_locations (void) | |
c906108c | 3130 | { |
a5606eee | 3131 | struct breakpoint *bpt; |
35df4500 | 3132 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3133 | int error_flag = 0; |
c906108c | 3134 | int val = 0; |
3fbb6ffa | 3135 | int disabled_breaks = 0; |
81d0cc19 | 3136 | int hw_breakpoint_error = 0; |
dd61ec5c | 3137 | int hw_bp_error_explained_already = 0; |
c906108c | 3138 | |
81d0cc19 | 3139 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3140 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3141 | |
81d0cc19 GS |
3142 | /* Explicitly mark the warning -- this will only be printed if |
3143 | there was an error. */ | |
3144 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3145 | |
3146 | save_current_space_and_thread (); | |
3147 | ||
35df4500 | 3148 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3149 | { |
b775012e | 3150 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3151 | continue; |
3152 | ||
4a64f543 MS |
3153 | /* There is no point inserting thread-specific breakpoints if |
3154 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3155 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3156 | if (bl->owner->thread != -1 |
5d5658a1 | 3157 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3158 | continue; |
3159 | ||
35df4500 | 3160 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3161 | |
3162 | /* For targets that support global breakpoints, there's no need | |
3163 | to select an inferior to insert breakpoint to. In fact, even | |
3164 | if we aren't attached to any process yet, we should still | |
3165 | insert breakpoints. */ | |
f5656ead | 3166 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3167 | && ptid_equal (inferior_ptid, null_ptid)) |
3168 | continue; | |
3169 | ||
3fbb6ffa | 3170 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3171 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3172 | if (val) |
eacd795a | 3173 | error_flag = val; |
879bfdc2 | 3174 | } |
c906108c | 3175 | |
4a64f543 MS |
3176 | /* If we failed to insert all locations of a watchpoint, remove |
3177 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3178 | ALL_BREAKPOINTS (bpt) |
3179 | { | |
3180 | int some_failed = 0; | |
3181 | struct bp_location *loc; | |
3182 | ||
3183 | if (!is_hardware_watchpoint (bpt)) | |
3184 | continue; | |
3185 | ||
d6b74ac4 | 3186 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3187 | continue; |
74960c60 VP |
3188 | |
3189 | if (bpt->disposition == disp_del_at_next_stop) | |
3190 | continue; | |
a5606eee VP |
3191 | |
3192 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3193 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3194 | { |
3195 | some_failed = 1; | |
3196 | break; | |
3197 | } | |
3198 | if (some_failed) | |
3199 | { | |
3200 | for (loc = bpt->loc; loc; loc = loc->next) | |
3201 | if (loc->inserted) | |
834c0d03 | 3202 | remove_breakpoint (loc); |
a5606eee VP |
3203 | |
3204 | hw_breakpoint_error = 1; | |
3205 | fprintf_unfiltered (tmp_error_stream, | |
3206 | "Could not insert hardware watchpoint %d.\n", | |
3207 | bpt->number); | |
eacd795a | 3208 | error_flag = -1; |
a5606eee VP |
3209 | } |
3210 | } | |
3211 | ||
eacd795a | 3212 | if (error_flag) |
81d0cc19 GS |
3213 | { |
3214 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3215 | message about possibly exhausted resources. */ | |
dd61ec5c | 3216 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3217 | { |
c6510018 MS |
3218 | fprintf_unfiltered (tmp_error_stream, |
3219 | "Could not insert hardware breakpoints:\n\ | |
3220 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3221 | } |
81d0cc19 GS |
3222 | target_terminal_ours_for_output (); |
3223 | error_stream (tmp_error_stream); | |
3224 | } | |
f7545552 TT |
3225 | |
3226 | do_cleanups (cleanups); | |
c906108c SS |
3227 | } |
3228 | ||
c30eee59 TJB |
3229 | /* Used when the program stops. |
3230 | Returns zero if successful, or non-zero if there was a problem | |
3231 | removing a breakpoint location. */ | |
3232 | ||
c906108c | 3233 | int |
fba45db2 | 3234 | remove_breakpoints (void) |
c906108c | 3235 | { |
35df4500 | 3236 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3237 | int val = 0; |
c906108c | 3238 | |
35df4500 | 3239 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3240 | { |
1e4d1764 | 3241 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3242 | val |= remove_breakpoint (bl); |
c5aa993b | 3243 | } |
3a1bae8e | 3244 | return val; |
c906108c SS |
3245 | } |
3246 | ||
49fa26b0 PA |
3247 | /* When a thread exits, remove breakpoints that are related to |
3248 | that thread. */ | |
3249 | ||
3250 | static void | |
3251 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3252 | { | |
3253 | struct breakpoint *b, *b_tmp; | |
3254 | ||
3255 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3256 | { | |
5d5658a1 | 3257 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3258 | { |
3259 | b->disposition = disp_del_at_next_stop; | |
3260 | ||
3261 | printf_filtered (_("\ | |
43792cf0 PA |
3262 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3263 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3264 | |
3265 | /* Hide it from the user. */ | |
3266 | b->number = 0; | |
3267 | } | |
3268 | } | |
3269 | } | |
3270 | ||
6c95b8df PA |
3271 | /* Remove breakpoints of process PID. */ |
3272 | ||
3273 | int | |
3274 | remove_breakpoints_pid (int pid) | |
3275 | { | |
35df4500 | 3276 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3277 | int val; |
3278 | struct inferior *inf = find_inferior_pid (pid); | |
3279 | ||
35df4500 | 3280 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3281 | { |
35df4500 | 3282 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3283 | continue; |
3284 | ||
fc126975 | 3285 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3286 | { |
834c0d03 | 3287 | val = remove_breakpoint (bl); |
6c95b8df PA |
3288 | if (val != 0) |
3289 | return val; | |
3290 | } | |
3291 | } | |
3292 | return 0; | |
3293 | } | |
3294 | ||
c906108c | 3295 | int |
fba45db2 | 3296 | reattach_breakpoints (int pid) |
c906108c | 3297 | { |
6c95b8df | 3298 | struct cleanup *old_chain; |
35df4500 | 3299 | struct bp_location *bl, **blp_tmp; |
c906108c | 3300 | int val; |
86b887df | 3301 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3302 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3303 | struct inferior *inf; |
3304 | struct thread_info *tp; | |
3305 | ||
3306 | tp = any_live_thread_of_process (pid); | |
3307 | if (tp == NULL) | |
3308 | return 1; | |
3309 | ||
3310 | inf = find_inferior_pid (pid); | |
3311 | old_chain = save_inferior_ptid (); | |
3312 | ||
3313 | inferior_ptid = tp->ptid; | |
a4954f26 | 3314 | |
86b887df | 3315 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3316 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3317 | |
35df4500 | 3318 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3319 | { |
35df4500 | 3320 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3321 | continue; |
3322 | ||
35df4500 | 3323 | if (bl->inserted) |
c5aa993b | 3324 | { |
35df4500 | 3325 | bl->inserted = 0; |
dd61ec5c | 3326 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3327 | if (val != 0) |
3328 | { | |
ce696e05 | 3329 | do_cleanups (old_chain); |
c5aa993b JM |
3330 | return val; |
3331 | } | |
3332 | } | |
3333 | } | |
ce696e05 | 3334 | do_cleanups (old_chain); |
c906108c SS |
3335 | return 0; |
3336 | } | |
3337 | ||
e58b0e63 PA |
3338 | static int internal_breakpoint_number = -1; |
3339 | ||
84f4c1fe PM |
3340 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3341 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3342 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3343 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3344 | breakpoint_count and that value incremented. Internal breakpoints |
3345 | do not set the internal var bpnum. */ | |
3346 | static void | |
3347 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3348 | { | |
3349 | if (internal) | |
3350 | b->number = internal_breakpoint_number--; | |
3351 | else | |
3352 | { | |
3353 | set_breakpoint_count (breakpoint_count + 1); | |
3354 | b->number = breakpoint_count; | |
3355 | } | |
3356 | } | |
3357 | ||
e62c965a | 3358 | static struct breakpoint * |
a6d9a66e | 3359 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3360 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3361 | const struct breakpoint_ops *ops) |
e62c965a | 3362 | { |
e62c965a PP |
3363 | struct symtab_and_line sal; |
3364 | struct breakpoint *b; | |
3365 | ||
4a64f543 | 3366 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3367 | |
3368 | sal.pc = address; | |
3369 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3370 | sal.pspace = current_program_space; |
e62c965a | 3371 | |
06edf0c0 | 3372 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3373 | b->number = internal_breakpoint_number--; |
3374 | b->disposition = disp_donttouch; | |
3375 | ||
3376 | return b; | |
3377 | } | |
3378 | ||
17450429 PP |
3379 | static const char *const longjmp_names[] = |
3380 | { | |
3381 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3382 | }; | |
3383 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3384 | ||
3385 | /* Per-objfile data private to breakpoint.c. */ | |
3386 | struct breakpoint_objfile_data | |
3387 | { | |
3388 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3389 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3390 | |
3391 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3392 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3393 | |
28106bc2 SDJ |
3394 | /* True if we have looked for longjmp probes. */ |
3395 | int longjmp_searched; | |
3396 | ||
3397 | /* SystemTap probe points for longjmp (if any). */ | |
3398 | VEC (probe_p) *longjmp_probes; | |
3399 | ||
17450429 | 3400 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3401 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3402 | |
3403 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3404 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3405 | |
3406 | /* True if we have looked for exception probes. */ | |
3407 | int exception_searched; | |
3408 | ||
3409 | /* SystemTap probe points for unwinding (if any). */ | |
3410 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3411 | }; |
3412 | ||
3413 | static const struct objfile_data *breakpoint_objfile_key; | |
3414 | ||
3415 | /* Minimal symbol not found sentinel. */ | |
3416 | static struct minimal_symbol msym_not_found; | |
3417 | ||
3418 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3419 | ||
3420 | static int | |
3421 | msym_not_found_p (const struct minimal_symbol *msym) | |
3422 | { | |
3423 | return msym == &msym_not_found; | |
3424 | } | |
3425 | ||
3426 | /* Return per-objfile data needed by breakpoint.c. | |
3427 | Allocate the data if necessary. */ | |
3428 | ||
3429 | static struct breakpoint_objfile_data * | |
3430 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3431 | { | |
3432 | struct breakpoint_objfile_data *bp_objfile_data; | |
3433 | ||
9a3c8263 SM |
3434 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3435 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3436 | if (bp_objfile_data == NULL) |
3437 | { | |
8d749320 SM |
3438 | bp_objfile_data = |
3439 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3440 | |
3441 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3442 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3443 | } | |
3444 | return bp_objfile_data; | |
3445 | } | |
3446 | ||
28106bc2 SDJ |
3447 | static void |
3448 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3449 | { | |
9a3c8263 SM |
3450 | struct breakpoint_objfile_data *bp_objfile_data |
3451 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3452 | |
3453 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3454 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3455 | } | |
3456 | ||
e62c965a | 3457 | static void |
af02033e | 3458 | create_overlay_event_breakpoint (void) |
e62c965a | 3459 | { |
69de3c6a | 3460 | struct objfile *objfile; |
af02033e | 3461 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3462 | |
69de3c6a PP |
3463 | ALL_OBJFILES (objfile) |
3464 | { | |
3465 | struct breakpoint *b; | |
17450429 PP |
3466 | struct breakpoint_objfile_data *bp_objfile_data; |
3467 | CORE_ADDR addr; | |
67994074 | 3468 | struct explicit_location explicit_loc; |
69de3c6a | 3469 | |
17450429 PP |
3470 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3471 | ||
3b7344d5 | 3472 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3473 | continue; |
3474 | ||
3b7344d5 | 3475 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3476 | { |
3b7344d5 | 3477 | struct bound_minimal_symbol m; |
17450429 PP |
3478 | |
3479 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3480 | if (m.minsym == NULL) |
17450429 PP |
3481 | { |
3482 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3483 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3484 | continue; |
3485 | } | |
3486 | bp_objfile_data->overlay_msym = m; | |
3487 | } | |
e62c965a | 3488 | |
77e371c0 | 3489 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3490 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3491 | bp_overlay_event, |
3492 | &internal_breakpoint_ops); | |
67994074 KS |
3493 | initialize_explicit_location (&explicit_loc); |
3494 | explicit_loc.function_name = ASTRDUP (func_name); | |
3495 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3496 | |
69de3c6a PP |
3497 | if (overlay_debugging == ovly_auto) |
3498 | { | |
3499 | b->enable_state = bp_enabled; | |
3500 | overlay_events_enabled = 1; | |
3501 | } | |
3502 | else | |
3503 | { | |
3504 | b->enable_state = bp_disabled; | |
3505 | overlay_events_enabled = 0; | |
3506 | } | |
e62c965a | 3507 | } |
e62c965a PP |
3508 | } |
3509 | ||
0fd8e87f | 3510 | static void |
af02033e | 3511 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3512 | { |
6c95b8df | 3513 | struct program_space *pspace; |
6c95b8df PA |
3514 | struct cleanup *old_chain; |
3515 | ||
3516 | old_chain = save_current_program_space (); | |
0fd8e87f | 3517 | |
6c95b8df | 3518 | ALL_PSPACES (pspace) |
af02033e PP |
3519 | { |
3520 | struct objfile *objfile; | |
3521 | ||
3522 | set_current_program_space (pspace); | |
3523 | ||
3524 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3525 | { |
af02033e PP |
3526 | int i; |
3527 | struct gdbarch *gdbarch; | |
17450429 | 3528 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3529 | |
af02033e | 3530 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3531 | |
17450429 PP |
3532 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3533 | ||
28106bc2 SDJ |
3534 | if (!bp_objfile_data->longjmp_searched) |
3535 | { | |
25f9533e SDJ |
3536 | VEC (probe_p) *ret; |
3537 | ||
3538 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3539 | if (ret != NULL) | |
3540 | { | |
3541 | /* We are only interested in checking one element. */ | |
3542 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3543 | ||
3544 | if (!can_evaluate_probe_arguments (p)) | |
3545 | { | |
3546 | /* We cannot use the probe interface here, because it does | |
3547 | not know how to evaluate arguments. */ | |
3548 | VEC_free (probe_p, ret); | |
3549 | ret = NULL; | |
3550 | } | |
3551 | } | |
3552 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3553 | bp_objfile_data->longjmp_searched = 1; |
3554 | } | |
3555 | ||
3556 | if (bp_objfile_data->longjmp_probes != NULL) | |
3557 | { | |
3558 | int i; | |
3559 | struct probe *probe; | |
3560 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3561 | ||
3562 | for (i = 0; | |
3563 | VEC_iterate (probe_p, | |
3564 | bp_objfile_data->longjmp_probes, | |
3565 | i, probe); | |
3566 | ++i) | |
3567 | { | |
3568 | struct breakpoint *b; | |
3569 | ||
729662a5 TT |
3570 | b = create_internal_breakpoint (gdbarch, |
3571 | get_probe_address (probe, | |
3572 | objfile), | |
28106bc2 SDJ |
3573 | bp_longjmp_master, |
3574 | &internal_breakpoint_ops); | |
5b56227b KS |
3575 | b->location |
3576 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3577 | b->enable_state = bp_disabled; |
3578 | } | |
3579 | ||
3580 | continue; | |
3581 | } | |
3582 | ||
0569175e TSD |
3583 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3584 | continue; | |
3585 | ||
17450429 | 3586 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3587 | { |
3588 | struct breakpoint *b; | |
af02033e | 3589 | const char *func_name; |
17450429 | 3590 | CORE_ADDR addr; |
67994074 | 3591 | struct explicit_location explicit_loc; |
6c95b8df | 3592 | |
3b7344d5 | 3593 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3594 | continue; |
0fd8e87f | 3595 | |
17450429 | 3596 | func_name = longjmp_names[i]; |
3b7344d5 | 3597 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3598 | { |
3b7344d5 | 3599 | struct bound_minimal_symbol m; |
17450429 PP |
3600 | |
3601 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3602 | if (m.minsym == NULL) |
17450429 PP |
3603 | { |
3604 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3605 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3606 | continue; |
3607 | } | |
3608 | bp_objfile_data->longjmp_msym[i] = m; | |
3609 | } | |
3610 | ||
77e371c0 | 3611 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3612 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3613 | &internal_breakpoint_ops); | |
67994074 KS |
3614 | initialize_explicit_location (&explicit_loc); |
3615 | explicit_loc.function_name = ASTRDUP (func_name); | |
3616 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3617 | b->enable_state = bp_disabled; |
3618 | } | |
0fd8e87f | 3619 | } |
af02033e | 3620 | } |
6c95b8df PA |
3621 | |
3622 | do_cleanups (old_chain); | |
0fd8e87f UW |
3623 | } |
3624 | ||
af02033e | 3625 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3626 | static void |
af02033e | 3627 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3628 | { |
3629 | struct program_space *pspace; | |
aa7d318d | 3630 | struct cleanup *old_chain; |
af02033e | 3631 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3632 | |
3633 | old_chain = save_current_program_space (); | |
3634 | ||
3635 | ALL_PSPACES (pspace) | |
17450429 PP |
3636 | { |
3637 | struct objfile *objfile; | |
3638 | CORE_ADDR addr; | |
3639 | ||
3640 | set_current_program_space (pspace); | |
3641 | ||
aa7d318d TT |
3642 | ALL_OBJFILES (objfile) |
3643 | { | |
3644 | struct breakpoint *b; | |
17450429 | 3645 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3646 | struct explicit_location explicit_loc; |
aa7d318d | 3647 | |
17450429 | 3648 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3649 | |
3b7344d5 | 3650 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3651 | continue; |
3652 | ||
3b7344d5 | 3653 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3654 | { |
3b7344d5 | 3655 | struct bound_minimal_symbol m; |
17450429 PP |
3656 | |
3657 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3658 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3659 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3660 | { |
3661 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3662 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3663 | continue; |
3664 | } | |
3665 | bp_objfile_data->terminate_msym = m; | |
3666 | } | |
aa7d318d | 3667 | |
77e371c0 | 3668 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3669 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3670 | bp_std_terminate_master, |
3671 | &internal_breakpoint_ops); | |
67994074 KS |
3672 | initialize_explicit_location (&explicit_loc); |
3673 | explicit_loc.function_name = ASTRDUP (func_name); | |
3674 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3675 | b->enable_state = bp_disabled; |
3676 | } | |
17450429 PP |
3677 | } |
3678 | ||
aa7d318d TT |
3679 | do_cleanups (old_chain); |
3680 | } | |
3681 | ||
186c406b TT |
3682 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3683 | ||
70221824 | 3684 | static void |
186c406b TT |
3685 | create_exception_master_breakpoint (void) |
3686 | { | |
3687 | struct objfile *objfile; | |
17450429 | 3688 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3689 | |
3690 | ALL_OBJFILES (objfile) | |
3691 | { | |
17450429 PP |
3692 | struct breakpoint *b; |
3693 | struct gdbarch *gdbarch; | |
3694 | struct breakpoint_objfile_data *bp_objfile_data; | |
3695 | CORE_ADDR addr; | |
67994074 | 3696 | struct explicit_location explicit_loc; |
17450429 PP |
3697 | |
3698 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3699 | ||
28106bc2 SDJ |
3700 | /* We prefer the SystemTap probe point if it exists. */ |
3701 | if (!bp_objfile_data->exception_searched) | |
3702 | { | |
25f9533e SDJ |
3703 | VEC (probe_p) *ret; |
3704 | ||
3705 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3706 | ||
3707 | if (ret != NULL) | |
3708 | { | |
3709 | /* We are only interested in checking one element. */ | |
3710 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3711 | ||
3712 | if (!can_evaluate_probe_arguments (p)) | |
3713 | { | |
3714 | /* We cannot use the probe interface here, because it does | |
3715 | not know how to evaluate arguments. */ | |
3716 | VEC_free (probe_p, ret); | |
3717 | ret = NULL; | |
3718 | } | |
3719 | } | |
3720 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3721 | bp_objfile_data->exception_searched = 1; |
3722 | } | |
3723 | ||
3724 | if (bp_objfile_data->exception_probes != NULL) | |
3725 | { | |
3726 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3727 | int i; | |
3728 | struct probe *probe; | |
3729 | ||
3730 | for (i = 0; | |
3731 | VEC_iterate (probe_p, | |
3732 | bp_objfile_data->exception_probes, | |
3733 | i, probe); | |
3734 | ++i) | |
3735 | { | |
3736 | struct breakpoint *b; | |
3737 | ||
729662a5 TT |
3738 | b = create_internal_breakpoint (gdbarch, |
3739 | get_probe_address (probe, | |
3740 | objfile), | |
28106bc2 SDJ |
3741 | bp_exception_master, |
3742 | &internal_breakpoint_ops); | |
5b56227b KS |
3743 | b->location |
3744 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3745 | b->enable_state = bp_disabled; |
3746 | } | |
3747 | ||
3748 | continue; | |
3749 | } | |
3750 | ||
3751 | /* Otherwise, try the hook function. */ | |
3752 | ||
3b7344d5 | 3753 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3754 | continue; |
3755 | ||
3756 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3757 | |
3b7344d5 | 3758 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3759 | { |
3b7344d5 | 3760 | struct bound_minimal_symbol debug_hook; |
186c406b | 3761 | |
17450429 | 3762 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3763 | if (debug_hook.minsym == NULL) |
17450429 | 3764 | { |
3b7344d5 | 3765 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3766 | continue; |
3767 | } | |
3768 | ||
3769 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3770 | } |
17450429 | 3771 | |
77e371c0 | 3772 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3773 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3774 | ¤t_target); | |
06edf0c0 PA |
3775 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3776 | &internal_breakpoint_ops); | |
67994074 KS |
3777 | initialize_explicit_location (&explicit_loc); |
3778 | explicit_loc.function_name = ASTRDUP (func_name); | |
3779 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3780 | b->enable_state = bp_disabled; |
186c406b | 3781 | } |
186c406b TT |
3782 | } |
3783 | ||
9ef9e6a6 KS |
3784 | /* Does B have a location spec? */ |
3785 | ||
3786 | static int | |
3787 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3788 | { | |
3789 | return b->location != NULL && event_location_empty_p (b->location); | |
3790 | } | |
3791 | ||
c906108c | 3792 | void |
fba45db2 | 3793 | update_breakpoints_after_exec (void) |
c906108c | 3794 | { |
35df4500 | 3795 | struct breakpoint *b, *b_tmp; |
876fa593 | 3796 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3797 | |
25b22b0a PA |
3798 | /* We're about to delete breakpoints from GDB's lists. If the |
3799 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3800 | writing the breakpoints' "shadow contents" back into memory. The | |
3801 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3802 | do that. Instead, the target is responsible from marking | |
3803 | breakpoints out as soon as it detects an exec. We don't do that | |
3804 | here instead, because there may be other attempts to delete | |
3805 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3806 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3807 | if (bploc->pspace == current_program_space) |
3808 | gdb_assert (!bploc->inserted); | |
c906108c | 3809 | |
35df4500 | 3810 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3811 | { |
6c95b8df PA |
3812 | if (b->pspace != current_program_space) |
3813 | continue; | |
3814 | ||
4a64f543 | 3815 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3816 | if (b->type == bp_shlib_event) |
3817 | { | |
3818 | delete_breakpoint (b); | |
3819 | continue; | |
3820 | } | |
c906108c | 3821 | |
4a64f543 | 3822 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3823 | if (b->type == bp_jit_event) |
3824 | { | |
3825 | delete_breakpoint (b); | |
3826 | continue; | |
3827 | } | |
3828 | ||
1900040c | 3829 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3830 | as must overlay event and longjmp master breakpoints. */ |
3831 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3832 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3833 | || b->type == bp_exception_master) | |
c4093a6a JM |
3834 | { |
3835 | delete_breakpoint (b); | |
3836 | continue; | |
3837 | } | |
3838 | ||
4a64f543 | 3839 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3840 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3841 | { |
3842 | delete_breakpoint (b); | |
3843 | continue; | |
3844 | } | |
3845 | ||
7c16b83e PA |
3846 | /* Just like single-step breakpoints. */ |
3847 | if (b->type == bp_single_step) | |
3848 | { | |
3849 | delete_breakpoint (b); | |
3850 | continue; | |
3851 | } | |
3852 | ||
611c83ae PA |
3853 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3854 | after an exec. */ | |
186c406b | 3855 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3856 | || b->type == bp_longjmp_call_dummy |
186c406b | 3857 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3858 | { |
3859 | delete_breakpoint (b); | |
3860 | continue; | |
3861 | } | |
3862 | ||
ce78b96d JB |
3863 | if (b->type == bp_catchpoint) |
3864 | { | |
3865 | /* For now, none of the bp_catchpoint breakpoints need to | |
3866 | do anything at this point. In the future, if some of | |
3867 | the catchpoints need to something, we will need to add | |
3868 | a new method, and call this method from here. */ | |
3869 | continue; | |
3870 | } | |
3871 | ||
c5aa993b JM |
3872 | /* bp_finish is a special case. The only way we ought to be able |
3873 | to see one of these when an exec() has happened, is if the user | |
3874 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3875 | carries them to the call-site of the current callee, by setting | |
3876 | a temporary bp there and resuming. But in this case, the finish | |
3877 | will carry them entirely through the vfork & exec. | |
3878 | ||
3879 | We don't want to allow a bp_finish to remain inserted now. But | |
3880 | we can't safely delete it, 'cause finish_command has a handle to | |
3881 | the bp on a bpstat, and will later want to delete it. There's a | |
3882 | chance (and I've seen it happen) that if we delete the bp_finish | |
3883 | here, that its storage will get reused by the time finish_command | |
3884 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3885 | We really must allow finish_command to delete a bp_finish. | |
3886 | ||
e5dd4106 | 3887 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3888 | it's safe to delete something others may have handles to?" |
3889 | problem, what we'll do here is just uninsert the bp_finish, and | |
3890 | let finish_command delete it. | |
3891 | ||
3892 | (We know the bp_finish is "doomed" in the sense that it's | |
3893 | momentary, and will be deleted as soon as finish_command sees | |
3894 | the inferior stopped. So it doesn't matter that the bp's | |
3895 | address is probably bogus in the new a.out, unlike e.g., the | |
3896 | solib breakpoints.) */ | |
c5aa993b | 3897 | |
c5aa993b JM |
3898 | if (b->type == bp_finish) |
3899 | { | |
3900 | continue; | |
3901 | } | |
3902 | ||
3903 | /* Without a symbolic address, we have little hope of the | |
3904 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3905 | a.out. */ |
9ef9e6a6 | 3906 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3907 | { |
3908 | delete_breakpoint (b); | |
3909 | continue; | |
3910 | } | |
c5aa993b | 3911 | } |
c906108c SS |
3912 | } |
3913 | ||
3914 | int | |
d80ee84f | 3915 | detach_breakpoints (ptid_t ptid) |
c906108c | 3916 | { |
35df4500 | 3917 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3918 | int val = 0; |
ce696e05 | 3919 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3920 | struct inferior *inf = current_inferior (); |
c5aa993b | 3921 | |
dfd4cc63 | 3922 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3923 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3924 | |
6c95b8df | 3925 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3926 | inferior_ptid = ptid; |
35df4500 | 3927 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3928 | { |
35df4500 | 3929 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3930 | continue; |
3931 | ||
bd9673a4 PW |
3932 | /* This function must physically remove breakpoints locations |
3933 | from the specified ptid, without modifying the breakpoint | |
3934 | package's state. Locations of type bp_loc_other are only | |
3935 | maintained at GDB side. So, there is no need to remove | |
3936 | these bp_loc_other locations. Moreover, removing these | |
3937 | would modify the breakpoint package's state. */ | |
3938 | if (bl->loc_type == bp_loc_other) | |
3939 | continue; | |
3940 | ||
35df4500 | 3941 | if (bl->inserted) |
b2b6a7da | 3942 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3943 | } |
d03285ec | 3944 | |
ce696e05 | 3945 | do_cleanups (old_chain); |
3a1bae8e | 3946 | return val; |
c906108c SS |
3947 | } |
3948 | ||
35df4500 | 3949 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3950 | Note that this is used to detach breakpoints from a child fork. |
3951 | When we get here, the child isn't in the inferior list, and neither | |
3952 | do we have objects to represent its address space --- we should | |
35df4500 | 3953 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3954 | |
c906108c | 3955 | static int |
b2b6a7da | 3956 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3957 | { |
3958 | int val; | |
c5aa993b | 3959 | |
35df4500 TJB |
3960 | /* BL is never in moribund_locations by our callers. */ |
3961 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3962 | |
74960c60 VP |
3963 | /* The type of none suggests that owner is actually deleted. |
3964 | This should not ever happen. */ | |
35df4500 | 3965 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3966 | |
35df4500 TJB |
3967 | if (bl->loc_type == bp_loc_software_breakpoint |
3968 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3969 | { |
c02f5703 MS |
3970 | /* "Normal" instruction breakpoint: either the standard |
3971 | trap-instruction bp (bp_breakpoint), or a | |
3972 | bp_hardware_breakpoint. */ | |
3973 | ||
3974 | /* First check to see if we have to handle an overlay. */ | |
3975 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3976 | || bl->section == NULL |
3977 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3978 | { |
3979 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3980 | |
3981 | /* If we're trying to uninsert a memory breakpoint that we | |
3982 | know is set in a dynamic object that is marked | |
3983 | shlib_disabled, then either the dynamic object was | |
3984 | removed with "remove-symbol-file" or with | |
3985 | "nosharedlibrary". In the former case, we don't know | |
3986 | whether another dynamic object might have loaded over the | |
3987 | breakpoint's address -- the user might well let us know | |
3988 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3989 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3990 | list of dynamically loaded objects). If we have the |
3991 | breakpoint's shadow memory, that is, this is a software | |
3992 | breakpoint managed by GDB, check whether the breakpoint | |
3993 | is still inserted in memory, to avoid overwriting wrong | |
3994 | code with stale saved shadow contents. Note that HW | |
3995 | breakpoints don't have shadow memory, as they're | |
3996 | implemented using a mechanism that is not dependent on | |
3997 | being able to modify the target's memory, and as such | |
3998 | they should always be removed. */ | |
3999 | if (bl->shlib_disabled | |
4000 | && bl->target_info.shadow_len != 0 | |
4001 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
4002 | val = 0; | |
4003 | else | |
73971819 | 4004 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 4005 | } |
c906108c SS |
4006 | else |
4007 | { | |
4a64f543 | 4008 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
4009 | Did we set a breakpoint at the LMA? */ |
4010 | if (!overlay_events_enabled) | |
4011 | { | |
4012 | /* Yes -- overlay event support is not active, so we | |
4013 | should have set a breakpoint at the LMA. Remove it. | |
4014 | */ | |
c02f5703 MS |
4015 | /* Ignore any failures: if the LMA is in ROM, we will |
4016 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4017 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4018 | target_remove_hw_breakpoint (bl->gdbarch, | |
4019 | &bl->overlay_target_info); | |
c02f5703 | 4020 | else |
35df4500 | 4021 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4022 | &bl->overlay_target_info, |
4023 | reason); | |
c02f5703 MS |
4024 | } |
4025 | /* Did we set a breakpoint at the VMA? | |
4026 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4027 | if (bl->inserted) |
c906108c | 4028 | { |
c02f5703 MS |
4029 | /* Yes -- remove it. Previously we did not bother to |
4030 | remove the breakpoint if the section had been | |
4031 | unmapped, but let's not rely on that being safe. We | |
4032 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4033 | |
4034 | /* However, we should remove *software* breakpoints only | |
4035 | if the section is still mapped, or else we overwrite | |
4036 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4037 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4038 | || section_is_mapped (bl->section)) | |
73971819 | 4039 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4040 | else |
4041 | val = 0; | |
c906108c | 4042 | } |
c02f5703 MS |
4043 | else |
4044 | { | |
4045 | /* No -- not inserted, so no need to remove. No error. */ | |
4046 | val = 0; | |
4047 | } | |
c906108c | 4048 | } |
879d1e6b | 4049 | |
08351840 PA |
4050 | /* In some cases, we might not be able to remove a breakpoint in |
4051 | a shared library that has already been removed, but we have | |
4052 | not yet processed the shlib unload event. Similarly for an | |
4053 | unloaded add-symbol-file object - the user might not yet have | |
4054 | had the chance to remove-symbol-file it. shlib_disabled will | |
4055 | be set if the library/object has already been removed, but | |
4056 | the breakpoint hasn't been uninserted yet, e.g., after | |
4057 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4058 | always-inserted mode. */ | |
076855f9 | 4059 | if (val |
08351840 PA |
4060 | && (bl->loc_type == bp_loc_software_breakpoint |
4061 | && (bl->shlib_disabled | |
4062 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4063 | || shared_objfile_contains_address_p (bl->pspace, |
4064 | bl->address)))) | |
879d1e6b UW |
4065 | val = 0; |
4066 | ||
c906108c SS |
4067 | if (val) |
4068 | return val; | |
b2b6a7da | 4069 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4070 | } |
35df4500 | 4071 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4072 | { |
77b06cd7 TJB |
4073 | gdb_assert (bl->owner->ops != NULL |
4074 | && bl->owner->ops->remove_location != NULL); | |
4075 | ||
b2b6a7da | 4076 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4077 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4078 | |
c906108c | 4079 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4080 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4081 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4082 | bl->owner->number); |
c906108c | 4083 | } |
35df4500 TJB |
4084 | else if (bl->owner->type == bp_catchpoint |
4085 | && breakpoint_enabled (bl->owner) | |
4086 | && !bl->duplicate) | |
ce78b96d | 4087 | { |
77b06cd7 TJB |
4088 | gdb_assert (bl->owner->ops != NULL |
4089 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4090 | |
73971819 | 4091 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4092 | if (val) |
4093 | return val; | |
77b06cd7 | 4094 | |
b2b6a7da | 4095 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4096 | } |
c906108c SS |
4097 | |
4098 | return 0; | |
4099 | } | |
4100 | ||
6c95b8df | 4101 | static int |
834c0d03 | 4102 | remove_breakpoint (struct bp_location *bl) |
6c95b8df PA |
4103 | { |
4104 | int ret; | |
4105 | struct cleanup *old_chain; | |
4106 | ||
35df4500 TJB |
4107 | /* BL is never in moribund_locations by our callers. */ |
4108 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4109 | |
6c95b8df PA |
4110 | /* The type of none suggests that owner is actually deleted. |
4111 | This should not ever happen. */ | |
35df4500 | 4112 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4113 | |
4114 | old_chain = save_current_space_and_thread (); | |
4115 | ||
35df4500 | 4116 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4117 | |
b2b6a7da | 4118 | ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4119 | |
4120 | do_cleanups (old_chain); | |
4121 | return ret; | |
4122 | } | |
4123 | ||
c906108c SS |
4124 | /* Clear the "inserted" flag in all breakpoints. */ |
4125 | ||
25b22b0a | 4126 | void |
fba45db2 | 4127 | mark_breakpoints_out (void) |
c906108c | 4128 | { |
35df4500 | 4129 | struct bp_location *bl, **blp_tmp; |
c906108c | 4130 | |
35df4500 | 4131 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4132 | if (bl->pspace == current_program_space) |
35df4500 | 4133 | bl->inserted = 0; |
c906108c SS |
4134 | } |
4135 | ||
53a5351d JM |
4136 | /* Clear the "inserted" flag in all breakpoints and delete any |
4137 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4138 | |
4139 | Plus other such housekeeping that has to be done for breakpoints | |
4140 | between runs. | |
4141 | ||
53a5351d JM |
4142 | Note: this function gets called at the end of a run (by |
4143 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4144 | init_wait_for_inferior). */ |
c906108c SS |
4145 | |
4146 | ||
4147 | ||
4148 | void | |
fba45db2 | 4149 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4150 | { |
35df4500 | 4151 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4152 | struct bp_location *bl; |
1c5cfe86 | 4153 | int ix; |
6c95b8df | 4154 | struct program_space *pspace = current_program_space; |
c906108c | 4155 | |
50c71eaf PA |
4156 | /* If breakpoint locations are shared across processes, then there's |
4157 | nothing to do. */ | |
f5656ead | 4158 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4159 | return; |
4160 | ||
1a853c52 | 4161 | mark_breakpoints_out (); |
075f6582 | 4162 | |
35df4500 | 4163 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4164 | { |
6c95b8df PA |
4165 | if (b->loc && b->loc->pspace != pspace) |
4166 | continue; | |
4167 | ||
c5aa993b JM |
4168 | switch (b->type) |
4169 | { | |
4170 | case bp_call_dummy: | |
e2e4d78b | 4171 | case bp_longjmp_call_dummy: |
c906108c | 4172 | |
c5aa993b | 4173 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4174 | cause problems when the inferior is rerun, so we better get |
4175 | rid of it. */ | |
4176 | ||
4177 | case bp_watchpoint_scope: | |
4178 | ||
4179 | /* Also get rid of scope breakpoints. */ | |
4180 | ||
4181 | case bp_shlib_event: | |
4182 | ||
4183 | /* Also remove solib event breakpoints. Their addresses may | |
4184 | have changed since the last time we ran the program. | |
4185 | Actually we may now be debugging against different target; | |
4186 | and so the solib backend that installed this breakpoint may | |
4187 | not be used in by the target. E.g., | |
4188 | ||
4189 | (gdb) file prog-linux | |
4190 | (gdb) run # native linux target | |
4191 | ... | |
4192 | (gdb) kill | |
4193 | (gdb) file prog-win.exe | |
4194 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4195 | */ | |
c906108c | 4196 | |
f59f708a PA |
4197 | case bp_step_resume: |
4198 | ||
4199 | /* Also remove step-resume breakpoints. */ | |
4200 | ||
7c16b83e PA |
4201 | case bp_single_step: |
4202 | ||
4203 | /* Also remove single-step breakpoints. */ | |
4204 | ||
c5aa993b JM |
4205 | delete_breakpoint (b); |
4206 | break; | |
c906108c | 4207 | |
c5aa993b JM |
4208 | case bp_watchpoint: |
4209 | case bp_hardware_watchpoint: | |
4210 | case bp_read_watchpoint: | |
4211 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4212 | { |
4213 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4214 | |
3a5c3e22 PA |
4215 | /* Likewise for watchpoints on local expressions. */ |
4216 | if (w->exp_valid_block != NULL) | |
4217 | delete_breakpoint (b); | |
63000888 | 4218 | else |
3a5c3e22 | 4219 | { |
63000888 PA |
4220 | /* Get rid of existing locations, which are no longer |
4221 | valid. New ones will be created in | |
4222 | update_watchpoint, when the inferior is restarted. | |
4223 | The next update_global_location_list call will | |
4224 | garbage collect them. */ | |
4225 | b->loc = NULL; | |
4226 | ||
4227 | if (context == inf_starting) | |
4228 | { | |
4229 | /* Reset val field to force reread of starting value in | |
4230 | insert_breakpoints. */ | |
4231 | if (w->val) | |
4232 | value_free (w->val); | |
4233 | w->val = NULL; | |
4234 | w->val_valid = 0; | |
4235 | } | |
4236 | } | |
3a5c3e22 | 4237 | } |
c5aa993b JM |
4238 | break; |
4239 | default: | |
c5aa993b JM |
4240 | break; |
4241 | } | |
4242 | } | |
1c5cfe86 PA |
4243 | |
4244 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4245 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4246 | decref_bp_location (&bl); | |
1c5cfe86 | 4247 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4248 | } |
4249 | ||
6c95b8df PA |
4250 | /* These functions concern about actual breakpoints inserted in the |
4251 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4252 | we need to hop over the bkpt --- so we check for address space | |
4253 | match, not program space. */ | |
4254 | ||
c2c6d25f JM |
4255 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4256 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4257 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4258 | permanent breakpoint. | |
4259 | - When continuing from a location with an ordinary breakpoint, we | |
4260 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4261 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4262 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4263 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4264 | |
c2c6d25f | 4265 | enum breakpoint_here |
6c95b8df | 4266 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4267 | { |
35df4500 | 4268 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4269 | int any_breakpoint_here = 0; |
c906108c | 4270 | |
35df4500 | 4271 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4272 | { |
35df4500 TJB |
4273 | if (bl->loc_type != bp_loc_software_breakpoint |
4274 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4275 | continue; |
4276 | ||
f1310107 | 4277 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4278 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4279 | || bl->permanent) |
f1310107 | 4280 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4281 | { |
4282 | if (overlay_debugging | |
35df4500 TJB |
4283 | && section_is_overlay (bl->section) |
4284 | && !section_is_mapped (bl->section)) | |
075f6582 | 4285 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4286 | else if (bl->permanent) |
075f6582 DJ |
4287 | return permanent_breakpoint_here; |
4288 | else | |
4289 | any_breakpoint_here = 1; | |
4290 | } | |
4291 | } | |
c906108c | 4292 | |
f486487f | 4293 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4294 | } |
4295 | ||
d35ae833 PA |
4296 | /* See breakpoint.h. */ |
4297 | ||
4298 | int | |
4299 | breakpoint_in_range_p (struct address_space *aspace, | |
4300 | CORE_ADDR addr, ULONGEST len) | |
4301 | { | |
4302 | struct bp_location *bl, **blp_tmp; | |
4303 | ||
4304 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4305 | { | |
4306 | if (bl->loc_type != bp_loc_software_breakpoint | |
4307 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4308 | continue; | |
4309 | ||
4310 | if ((breakpoint_enabled (bl->owner) | |
4311 | || bl->permanent) | |
4312 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4313 | addr, len)) | |
4314 | { | |
4315 | if (overlay_debugging | |
4316 | && section_is_overlay (bl->section) | |
4317 | && !section_is_mapped (bl->section)) | |
4318 | { | |
4319 | /* Unmapped overlay -- can't be a match. */ | |
4320 | continue; | |
4321 | } | |
4322 | ||
4323 | return 1; | |
4324 | } | |
4325 | } | |
4326 | ||
4327 | return 0; | |
4328 | } | |
4329 | ||
1c5cfe86 PA |
4330 | /* Return true if there's a moribund breakpoint at PC. */ |
4331 | ||
4332 | int | |
6c95b8df | 4333 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4334 | { |
4335 | struct bp_location *loc; | |
4336 | int ix; | |
4337 | ||
4338 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4339 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4340 | return 1; |
4341 | ||
4342 | return 0; | |
4343 | } | |
c2c6d25f | 4344 | |
f7ce857f PA |
4345 | /* Returns non-zero iff BL is inserted at PC, in address space |
4346 | ASPACE. */ | |
4347 | ||
4348 | static int | |
4349 | bp_location_inserted_here_p (struct bp_location *bl, | |
4350 | struct address_space *aspace, CORE_ADDR pc) | |
4351 | { | |
4352 | if (bl->inserted | |
4353 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4354 | aspace, pc)) | |
4355 | { | |
4356 | if (overlay_debugging | |
4357 | && section_is_overlay (bl->section) | |
4358 | && !section_is_mapped (bl->section)) | |
4359 | return 0; /* unmapped overlay -- can't be a match */ | |
4360 | else | |
4361 | return 1; | |
4362 | } | |
4363 | return 0; | |
4364 | } | |
4365 | ||
a1fd2fa5 | 4366 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4367 | |
4368 | int | |
a1fd2fa5 | 4369 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4370 | { |
f7ce857f | 4371 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4372 | |
f7ce857f | 4373 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4374 | { |
f7ce857f PA |
4375 | struct bp_location *bl = *blp; |
4376 | ||
35df4500 TJB |
4377 | if (bl->loc_type != bp_loc_software_breakpoint |
4378 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4379 | continue; |
4380 | ||
f7ce857f PA |
4381 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4382 | return 1; | |
c5aa993b | 4383 | } |
c36b740a VP |
4384 | return 0; |
4385 | } | |
4386 | ||
a1fd2fa5 PA |
4387 | /* This function returns non-zero iff there is a software breakpoint |
4388 | inserted at PC. */ | |
c36b740a VP |
4389 | |
4390 | int | |
a1fd2fa5 PA |
4391 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4392 | CORE_ADDR pc) | |
4fa8626c | 4393 | { |
f7ce857f | 4394 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4395 | |
f7ce857f | 4396 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4397 | { |
f7ce857f PA |
4398 | struct bp_location *bl = *blp; |
4399 | ||
35df4500 | 4400 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4401 | continue; |
4402 | ||
f7ce857f PA |
4403 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4404 | return 1; | |
4fa8626c DJ |
4405 | } |
4406 | ||
4407 | return 0; | |
9c02b525 PA |
4408 | } |
4409 | ||
4410 | /* See breakpoint.h. */ | |
4411 | ||
4412 | int | |
4413 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4414 | CORE_ADDR pc) | |
4415 | { | |
4416 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4417 | |
4418 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4419 | { | |
4420 | struct bp_location *bl = *blp; | |
4421 | ||
4422 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4423 | continue; | |
4424 | ||
4425 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4426 | return 1; | |
4427 | } | |
4428 | ||
4429 | return 0; | |
4fa8626c DJ |
4430 | } |
4431 | ||
9093389c PA |
4432 | int |
4433 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4434 | CORE_ADDR addr, ULONGEST len) | |
4435 | { | |
4436 | struct breakpoint *bpt; | |
4437 | ||
4438 | ALL_BREAKPOINTS (bpt) | |
4439 | { | |
4440 | struct bp_location *loc; | |
4441 | ||
4442 | if (bpt->type != bp_hardware_watchpoint | |
4443 | && bpt->type != bp_access_watchpoint) | |
4444 | continue; | |
4445 | ||
4446 | if (!breakpoint_enabled (bpt)) | |
4447 | continue; | |
4448 | ||
4449 | for (loc = bpt->loc; loc; loc = loc->next) | |
4450 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4451 | { | |
4452 | CORE_ADDR l, h; | |
4453 | ||
4454 | /* Check for intersection. */ | |
768adc05 PA |
4455 | l = std::max<CORE_ADDR> (loc->address, addr); |
4456 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4457 | if (l < h) |
4458 | return 1; | |
4459 | } | |
4460 | } | |
4461 | return 0; | |
4462 | } | |
c906108c | 4463 | \f |
c5aa993b | 4464 | |
c906108c SS |
4465 | /* bpstat stuff. External routines' interfaces are documented |
4466 | in breakpoint.h. */ | |
4467 | ||
4468 | int | |
c326b90e | 4469 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4470 | { |
533be4dd | 4471 | return (ep->type == bp_catchpoint); |
c906108c SS |
4472 | } |
4473 | ||
f431efe5 PA |
4474 | /* Frees any storage that is part of a bpstat. Does not walk the |
4475 | 'next' chain. */ | |
4476 | ||
4477 | static void | |
198757a8 VP |
4478 | bpstat_free (bpstat bs) |
4479 | { | |
4480 | if (bs->old_val != NULL) | |
4481 | value_free (bs->old_val); | |
9add0f1b | 4482 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4483 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4484 | xfree (bs); |
4485 | } | |
4486 | ||
c906108c SS |
4487 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4488 | Also free any storage that is part of a bpstat. */ | |
4489 | ||
4490 | void | |
fba45db2 | 4491 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4492 | { |
4493 | bpstat p; | |
4494 | bpstat q; | |
4495 | ||
4496 | if (bsp == 0) | |
4497 | return; | |
4498 | p = *bsp; | |
4499 | while (p != NULL) | |
4500 | { | |
4501 | q = p->next; | |
198757a8 | 4502 | bpstat_free (p); |
c906108c SS |
4503 | p = q; |
4504 | } | |
4505 | *bsp = NULL; | |
4506 | } | |
4507 | ||
4508 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4509 | is part of the bpstat is copied as well. */ | |
4510 | ||
4511 | bpstat | |
fba45db2 | 4512 | bpstat_copy (bpstat bs) |
c906108c SS |
4513 | { |
4514 | bpstat p = NULL; | |
4515 | bpstat tmp; | |
4516 | bpstat retval = NULL; | |
4517 | ||
4518 | if (bs == NULL) | |
4519 | return bs; | |
4520 | ||
4521 | for (; bs != NULL; bs = bs->next) | |
4522 | { | |
4523 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4524 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4525 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4526 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4527 | if (bs->old_val != NULL) |
3c3185ac JK |
4528 | { |
4529 | tmp->old_val = value_copy (bs->old_val); | |
4530 | release_value (tmp->old_val); | |
4531 | } | |
31cc81e9 | 4532 | |
c906108c SS |
4533 | if (p == NULL) |
4534 | /* This is the first thing in the chain. */ | |
4535 | retval = tmp; | |
4536 | else | |
4537 | p->next = tmp; | |
4538 | p = tmp; | |
4539 | } | |
4540 | p->next = NULL; | |
4541 | return retval; | |
4542 | } | |
4543 | ||
4a64f543 | 4544 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4545 | |
4546 | bpstat | |
fba45db2 | 4547 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4548 | { |
c5aa993b JM |
4549 | if (bsp == NULL) |
4550 | return NULL; | |
c906108c | 4551 | |
c5aa993b JM |
4552 | for (; bsp != NULL; bsp = bsp->next) |
4553 | { | |
f431efe5 | 4554 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4555 | return bsp; |
4556 | } | |
c906108c SS |
4557 | return NULL; |
4558 | } | |
4559 | ||
ab04a2af TT |
4560 | /* See breakpoint.h. */ |
4561 | ||
47591c29 | 4562 | int |
427cd150 | 4563 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4564 | { |
ab04a2af TT |
4565 | for (; bsp != NULL; bsp = bsp->next) |
4566 | { | |
427cd150 TT |
4567 | if (bsp->breakpoint_at == NULL) |
4568 | { | |
4569 | /* A moribund location can never explain a signal other than | |
4570 | GDB_SIGNAL_TRAP. */ | |
4571 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4572 | return 1; |
427cd150 TT |
4573 | } |
4574 | else | |
47591c29 PA |
4575 | { |
4576 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4577 | sig)) | |
4578 | return 1; | |
4579 | } | |
ab04a2af TT |
4580 | } |
4581 | ||
47591c29 | 4582 | return 0; |
ab04a2af TT |
4583 | } |
4584 | ||
4a64f543 MS |
4585 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4586 | stopped at. *BSP upon return is a bpstat which points to the | |
4587 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4588 | good for anything but further calls to bpstat_num). | |
4589 | ||
8671a17b PA |
4590 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4591 | Return -1 if stopped at a breakpoint that has been deleted since | |
4592 | we set it. | |
4593 | Return 1 otherwise. */ | |
c906108c SS |
4594 | |
4595 | int | |
8671a17b | 4596 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4597 | { |
4598 | struct breakpoint *b; | |
4599 | ||
4600 | if ((*bsp) == NULL) | |
4601 | return 0; /* No more breakpoint values */ | |
8671a17b | 4602 | |
4a64f543 MS |
4603 | /* We assume we'll never have several bpstats that correspond to a |
4604 | single breakpoint -- otherwise, this function might return the | |
4605 | same number more than once and this will look ugly. */ | |
f431efe5 | 4606 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4607 | *bsp = (*bsp)->next; |
4608 | if (b == NULL) | |
4609 | return -1; /* breakpoint that's been deleted since */ | |
4610 | ||
4611 | *num = b->number; /* We have its number */ | |
4612 | return 1; | |
c906108c SS |
4613 | } |
4614 | ||
e93ca019 | 4615 | /* See breakpoint.h. */ |
c906108c SS |
4616 | |
4617 | void | |
e93ca019 | 4618 | bpstat_clear_actions (void) |
c906108c | 4619 | { |
e93ca019 JK |
4620 | struct thread_info *tp; |
4621 | bpstat bs; | |
4622 | ||
4623 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4624 | return; | |
4625 | ||
4626 | tp = find_thread_ptid (inferior_ptid); | |
4627 | if (tp == NULL) | |
4628 | return; | |
4629 | ||
4630 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4631 | { |
9add0f1b | 4632 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4633 | |
c906108c SS |
4634 | if (bs->old_val != NULL) |
4635 | { | |
4636 | value_free (bs->old_val); | |
4637 | bs->old_val = NULL; | |
4638 | } | |
4639 | } | |
4640 | } | |
4641 | ||
f3b1572e PA |
4642 | /* Called when a command is about to proceed the inferior. */ |
4643 | ||
4644 | static void | |
4645 | breakpoint_about_to_proceed (void) | |
4646 | { | |
4647 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4648 | { | |
4649 | struct thread_info *tp = inferior_thread (); | |
4650 | ||
4651 | /* Allow inferior function calls in breakpoint commands to not | |
4652 | interrupt the command list. When the call finishes | |
4653 | successfully, the inferior will be standing at the same | |
4654 | breakpoint as if nothing happened. */ | |
16c381f0 | 4655 | if (tp->control.in_infcall) |
f3b1572e PA |
4656 | return; |
4657 | } | |
4658 | ||
4659 | breakpoint_proceeded = 1; | |
4660 | } | |
4661 | ||
4a64f543 MS |
4662 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4663 | command. */ | |
c906108c | 4664 | static void |
4efb68b1 | 4665 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4666 | { |
4667 | executing_breakpoint_commands = 0; | |
4668 | } | |
4669 | ||
abf85f46 JK |
4670 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4671 | or its equivalent. */ | |
4672 | ||
4673 | static int | |
4674 | command_line_is_silent (struct command_line *cmd) | |
4675 | { | |
4f45d445 | 4676 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4677 | } |
4678 | ||
4a64f543 MS |
4679 | /* Execute all the commands associated with all the breakpoints at |
4680 | this location. Any of these commands could cause the process to | |
4681 | proceed beyond this point, etc. We look out for such changes by | |
4682 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4683 | |
347bddb7 PA |
4684 | Returns true if a breakpoint command resumed the inferior. In that |
4685 | case, it is the caller's responsibility to recall it again with the | |
4686 | bpstat of the current thread. */ | |
4687 | ||
4688 | static int | |
4689 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4690 | { |
4691 | bpstat bs; | |
4692 | struct cleanup *old_chain; | |
347bddb7 | 4693 | int again = 0; |
c906108c SS |
4694 | |
4695 | /* Avoid endless recursion if a `source' command is contained | |
4696 | in bs->commands. */ | |
4697 | if (executing_breakpoint_commands) | |
347bddb7 | 4698 | return 0; |
c906108c SS |
4699 | |
4700 | executing_breakpoint_commands = 1; | |
4701 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4702 | ||
cf6c5ffb TT |
4703 | prevent_dont_repeat (); |
4704 | ||
4a64f543 | 4705 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4706 | bs = *bsp; |
4707 | ||
4708 | breakpoint_proceeded = 0; | |
4709 | for (; bs != NULL; bs = bs->next) | |
4710 | { | |
9add0f1b | 4711 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4712 | struct command_line *cmd; |
4713 | struct cleanup *this_cmd_tree_chain; | |
4714 | ||
4715 | /* Take ownership of the BSP's command tree, if it has one. | |
4716 | ||
4717 | The command tree could legitimately contain commands like | |
4718 | 'step' and 'next', which call clear_proceed_status, which | |
4719 | frees stop_bpstat's command tree. To make sure this doesn't | |
4720 | free the tree we're executing out from under us, we need to | |
4721 | take ownership of the tree ourselves. Since a given bpstat's | |
4722 | commands are only executed once, we don't need to copy it; we | |
4723 | can clear the pointer in the bpstat, and make sure we free | |
4724 | the tree when we're done. */ | |
9add0f1b TT |
4725 | ccmd = bs->commands; |
4726 | bs->commands = NULL; | |
abf85f46 JK |
4727 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4728 | cmd = ccmd ? ccmd->commands : NULL; | |
4729 | if (command_line_is_silent (cmd)) | |
4730 | { | |
4731 | /* The action has been already done by bpstat_stop_status. */ | |
4732 | cmd = cmd->next; | |
4733 | } | |
6c50ab1c | 4734 | |
c906108c SS |
4735 | while (cmd != NULL) |
4736 | { | |
4737 | execute_control_command (cmd); | |
4738 | ||
4739 | if (breakpoint_proceeded) | |
4740 | break; | |
4741 | else | |
4742 | cmd = cmd->next; | |
4743 | } | |
6c50ab1c JB |
4744 | |
4745 | /* We can free this command tree now. */ | |
4746 | do_cleanups (this_cmd_tree_chain); | |
4747 | ||
c906108c | 4748 | if (breakpoint_proceeded) |
32c1e744 | 4749 | { |
cb814510 | 4750 | if (current_ui->async) |
347bddb7 PA |
4751 | /* If we are in async mode, then the target might be still |
4752 | running, not stopped at any breakpoint, so nothing for | |
4753 | us to do here -- just return to the event loop. */ | |
4754 | ; | |
32c1e744 VP |
4755 | else |
4756 | /* In sync mode, when execute_control_command returns | |
4757 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4758 | Breakpoint commands for that stop were not run, since |
4759 | execute_command does not run breakpoint commands -- | |
4760 | only command_line_handler does, but that one is not | |
4761 | involved in execution of breakpoint commands. So, we | |
4762 | can now execute breakpoint commands. It should be | |
4763 | noted that making execute_command do bpstat actions is | |
4764 | not an option -- in this case we'll have recursive | |
4765 | invocation of bpstat for each breakpoint with a | |
4766 | command, and can easily blow up GDB stack. Instead, we | |
4767 | return true, which will trigger the caller to recall us | |
4768 | with the new stop_bpstat. */ | |
4769 | again = 1; | |
4770 | break; | |
32c1e744 | 4771 | } |
c906108c | 4772 | } |
c2b8ed2c | 4773 | do_cleanups (old_chain); |
347bddb7 PA |
4774 | return again; |
4775 | } | |
4776 | ||
4777 | void | |
4778 | bpstat_do_actions (void) | |
4779 | { | |
353d1d73 JK |
4780 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4781 | ||
347bddb7 PA |
4782 | /* Do any commands attached to breakpoint we are stopped at. */ |
4783 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4784 | && target_has_execution | |
4785 | && !is_exited (inferior_ptid) | |
4786 | && !is_executing (inferior_ptid)) | |
4787 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4788 | and only return when it is stopped at the next breakpoint, we | |
4789 | keep doing breakpoint actions until it returns false to | |
4790 | indicate the inferior was not resumed. */ | |
16c381f0 | 4791 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4792 | break; |
353d1d73 JK |
4793 | |
4794 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4795 | } |
4796 | ||
fa4727a6 DJ |
4797 | /* Print out the (old or new) value associated with a watchpoint. */ |
4798 | ||
4799 | static void | |
4800 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4801 | { | |
4802 | if (val == NULL) | |
4803 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4804 | else | |
79a45b7d TT |
4805 | { |
4806 | struct value_print_options opts; | |
4807 | get_user_print_options (&opts); | |
4808 | value_print (val, stream, &opts); | |
4809 | } | |
fa4727a6 DJ |
4810 | } |
4811 | ||
f303dbd6 PA |
4812 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4813 | debugging multiple threads. */ | |
4814 | ||
4815 | void | |
4816 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4817 | { | |
4818 | if (ui_out_is_mi_like_p (uiout)) | |
4819 | return; | |
4820 | ||
4821 | ui_out_text (uiout, "\n"); | |
4822 | ||
4823 | if (show_thread_that_caused_stop ()) | |
4824 | { | |
4825 | const char *name; | |
4826 | struct thread_info *thr = inferior_thread (); | |
4827 | ||
4828 | ui_out_text (uiout, "Thread "); | |
4829 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4830 | ||
4831 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4832 | if (name != NULL) | |
4833 | { | |
4834 | ui_out_text (uiout, " \""); | |
4835 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4836 | ui_out_text (uiout, "\""); | |
4837 | } | |
4838 | ||
4839 | ui_out_text (uiout, " hit "); | |
4840 | } | |
4841 | } | |
4842 | ||
e514a9d6 | 4843 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4844 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4845 | 'print_it' in the bpstat structure. Under some circumstances we |
4846 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4847 | normal_stop(). */ |
e514a9d6 JM |
4848 | |
4849 | static enum print_stop_action | |
4850 | print_bp_stop_message (bpstat bs) | |
4851 | { | |
4852 | switch (bs->print_it) | |
4853 | { | |
4854 | case print_it_noop: | |
4a64f543 | 4855 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4856 | return PRINT_UNKNOWN; |
4857 | break; | |
4858 | ||
4859 | case print_it_done: | |
4860 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4861 | relevant messages. */ |
e514a9d6 JM |
4862 | return PRINT_SRC_AND_LOC; |
4863 | break; | |
4864 | ||
4865 | case print_it_normal: | |
4f8d1dc6 | 4866 | { |
f431efe5 PA |
4867 | struct breakpoint *b = bs->breakpoint_at; |
4868 | ||
1a6a67de TJB |
4869 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4870 | which has since been deleted. */ | |
4871 | if (b == NULL) | |
4872 | return PRINT_UNKNOWN; | |
4873 | ||
348d480f PA |
4874 | /* Normal case. Call the breakpoint's print_it method. */ |
4875 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4876 | } |
348d480f | 4877 | break; |
3086aeae | 4878 | |
e514a9d6 | 4879 | default: |
8e65ff28 | 4880 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4881 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4882 | break; |
c906108c | 4883 | } |
c906108c SS |
4884 | } |
4885 | ||
edcc5120 TT |
4886 | /* A helper function that prints a shared library stopped event. */ |
4887 | ||
4888 | static void | |
4889 | print_solib_event (int is_catchpoint) | |
4890 | { | |
4891 | int any_deleted | |
4892 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4893 | int any_added | |
4894 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4895 | ||
4896 | if (!is_catchpoint) | |
4897 | { | |
4898 | if (any_added || any_deleted) | |
4899 | ui_out_text (current_uiout, | |
4900 | _("Stopped due to shared library event:\n")); | |
4901 | else | |
4902 | ui_out_text (current_uiout, | |
4903 | _("Stopped due to shared library event (no " | |
4904 | "libraries added or removed)\n")); | |
4905 | } | |
4906 | ||
4907 | if (ui_out_is_mi_like_p (current_uiout)) | |
4908 | ui_out_field_string (current_uiout, "reason", | |
4909 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4910 | ||
4911 | if (any_deleted) | |
4912 | { | |
4913 | struct cleanup *cleanup; | |
4914 | char *name; | |
4915 | int ix; | |
4916 | ||
4917 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4918 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4919 | "removed"); | |
4920 | for (ix = 0; | |
4921 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4922 | ix, name); | |
4923 | ++ix) | |
4924 | { | |
4925 | if (ix > 0) | |
4926 | ui_out_text (current_uiout, " "); | |
4927 | ui_out_field_string (current_uiout, "library", name); | |
4928 | ui_out_text (current_uiout, "\n"); | |
4929 | } | |
4930 | ||
4931 | do_cleanups (cleanup); | |
4932 | } | |
4933 | ||
4934 | if (any_added) | |
4935 | { | |
4936 | struct so_list *iter; | |
4937 | int ix; | |
4938 | struct cleanup *cleanup; | |
4939 | ||
4940 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4941 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4942 | "added"); | |
4943 | for (ix = 0; | |
4944 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4945 | ix, iter); | |
4946 | ++ix) | |
4947 | { | |
4948 | if (ix > 0) | |
4949 | ui_out_text (current_uiout, " "); | |
4950 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4951 | ui_out_text (current_uiout, "\n"); | |
4952 | } | |
4953 | ||
4954 | do_cleanups (cleanup); | |
4955 | } | |
4956 | } | |
4957 | ||
e514a9d6 JM |
4958 | /* Print a message indicating what happened. This is called from |
4959 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4960 | list - a list of the eventpoints that caused this stop. KIND is |
4961 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4962 | routine calls the generic print routine for printing a message |
4963 | about reasons for stopping. This will print (for example) the | |
4964 | "Breakpoint n," part of the output. The return value of this | |
4965 | routine is one of: | |
c906108c | 4966 | |
4a64f543 | 4967 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4968 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4969 | code to print the location. An example is |
c5aa993b JM |
4970 | "Breakpoint 1, " which should be followed by |
4971 | the location. | |
917317f4 | 4972 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4973 | to also print the location part of the message. |
4974 | An example is the catch/throw messages, which | |
4a64f543 | 4975 | don't require a location appended to the end. |
917317f4 | 4976 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4977 | further info to be printed. */ |
c906108c | 4978 | |
917317f4 | 4979 | enum print_stop_action |
36dfb11c | 4980 | bpstat_print (bpstat bs, int kind) |
c906108c | 4981 | { |
f486487f | 4982 | enum print_stop_action val; |
c5aa993b | 4983 | |
c906108c | 4984 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4985 | (Currently all watchpoints go on the bpstat whether hit or not. |
4986 | That probably could (should) be changed, provided care is taken | |
c906108c | 4987 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4988 | for (; bs; bs = bs->next) |
4989 | { | |
4990 | val = print_bp_stop_message (bs); | |
4991 | if (val == PRINT_SRC_ONLY | |
4992 | || val == PRINT_SRC_AND_LOC | |
4993 | || val == PRINT_NOTHING) | |
4994 | return val; | |
4995 | } | |
c906108c | 4996 | |
36dfb11c TT |
4997 | /* If we had hit a shared library event breakpoint, |
4998 | print_bp_stop_message would print out this message. If we hit an | |
4999 | OS-level shared library event, do the same thing. */ | |
5000 | if (kind == TARGET_WAITKIND_LOADED) | |
5001 | { | |
edcc5120 | 5002 | print_solib_event (0); |
36dfb11c TT |
5003 | return PRINT_NOTHING; |
5004 | } | |
5005 | ||
e514a9d6 | 5006 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 5007 | with and nothing was printed. */ |
917317f4 | 5008 | return PRINT_UNKNOWN; |
c906108c SS |
5009 | } |
5010 | ||
c42bd95a DE |
5011 | /* Evaluate the expression EXP and return 1 if value is zero. |
5012 | This returns the inverse of the condition because it is called | |
5013 | from catch_errors which returns 0 if an exception happened, and if an | |
5014 | exception happens we want execution to stop. | |
4a64f543 | 5015 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 5016 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
5017 | |
5018 | static int | |
4efb68b1 | 5019 | breakpoint_cond_eval (void *exp) |
c906108c | 5020 | { |
278cd55f | 5021 | struct value *mark = value_mark (); |
c5aa993b | 5022 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5023 | |
c906108c SS |
5024 | value_free_to_mark (mark); |
5025 | return i; | |
5026 | } | |
5027 | ||
5760d0ab | 5028 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5029 | |
5030 | static bpstat | |
5760d0ab | 5031 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5032 | { |
5033 | bpstat bs; | |
5034 | ||
5035 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5036 | bs->next = NULL; |
5037 | **bs_link_pointer = bs; | |
5038 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5039 | bs->breakpoint_at = bl->owner; |
5040 | bs->bp_location_at = bl; | |
5041 | incref_bp_location (bl); | |
c906108c SS |
5042 | /* If the condition is false, etc., don't do the commands. */ |
5043 | bs->commands = NULL; | |
5044 | bs->old_val = NULL; | |
5045 | bs->print_it = print_it_normal; | |
5046 | return bs; | |
5047 | } | |
5048 | \f | |
d983da9c DJ |
5049 | /* The target has stopped with waitstatus WS. Check if any hardware |
5050 | watchpoints have triggered, according to the target. */ | |
5051 | ||
5052 | int | |
5053 | watchpoints_triggered (struct target_waitstatus *ws) | |
5054 | { | |
d92524f1 | 5055 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5056 | CORE_ADDR addr; |
5057 | struct breakpoint *b; | |
5058 | ||
5059 | if (!stopped_by_watchpoint) | |
5060 | { | |
5061 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5062 | as not triggered. */ | |
5063 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5064 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5065 | { |
5066 | struct watchpoint *w = (struct watchpoint *) b; | |
5067 | ||
5068 | w->watchpoint_triggered = watch_triggered_no; | |
5069 | } | |
d983da9c DJ |
5070 | |
5071 | return 0; | |
5072 | } | |
5073 | ||
5074 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5075 | { | |
5076 | /* We were stopped by a watchpoint, but we don't know where. | |
5077 | Mark all watchpoints as unknown. */ | |
5078 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5079 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5080 | { |
5081 | struct watchpoint *w = (struct watchpoint *) b; | |
5082 | ||
5083 | w->watchpoint_triggered = watch_triggered_unknown; | |
5084 | } | |
d983da9c | 5085 | |
3c4797ba | 5086 | return 1; |
d983da9c DJ |
5087 | } |
5088 | ||
5089 | /* The target could report the data address. Mark watchpoints | |
5090 | affected by this data address as triggered, and all others as not | |
5091 | triggered. */ | |
5092 | ||
5093 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5094 | if (is_hardware_watchpoint (b)) |
d983da9c | 5095 | { |
3a5c3e22 | 5096 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5097 | struct bp_location *loc; |
d983da9c | 5098 | |
3a5c3e22 | 5099 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5100 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5101 | { |
3a5c3e22 | 5102 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5103 | { |
3a5c3e22 PA |
5104 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5105 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5106 | |
5107 | if (newaddr == start) | |
5108 | { | |
3a5c3e22 | 5109 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5110 | break; |
5111 | } | |
5112 | } | |
5113 | /* Exact match not required. Within range is sufficient. */ | |
5114 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5115 | addr, loc->address, | |
5116 | loc->length)) | |
5117 | { | |
3a5c3e22 | 5118 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5119 | break; |
5120 | } | |
5121 | } | |
d983da9c DJ |
5122 | } |
5123 | ||
5124 | return 1; | |
5125 | } | |
5126 | ||
c906108c SS |
5127 | /* Possible return values for watchpoint_check (this can't be an enum |
5128 | because of check_errors). */ | |
5129 | /* The watchpoint has been deleted. */ | |
5130 | #define WP_DELETED 1 | |
5131 | /* The value has changed. */ | |
5132 | #define WP_VALUE_CHANGED 2 | |
5133 | /* The value has not changed. */ | |
5134 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5135 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5136 | #define WP_IGNORE 4 | |
c906108c SS |
5137 | |
5138 | #define BP_TEMPFLAG 1 | |
5139 | #define BP_HARDWAREFLAG 2 | |
5140 | ||
4a64f543 MS |
5141 | /* Evaluate watchpoint condition expression and check if its value |
5142 | changed. | |
553e4c11 JB |
5143 | |
5144 | P should be a pointer to struct bpstat, but is defined as a void * | |
5145 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5146 | |
5147 | static int | |
4efb68b1 | 5148 | watchpoint_check (void *p) |
c906108c SS |
5149 | { |
5150 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5151 | struct watchpoint *b; |
c906108c SS |
5152 | struct frame_info *fr; |
5153 | int within_current_scope; | |
5154 | ||
f431efe5 | 5155 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5156 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5157 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5158 | |
f6bc2008 PA |
5159 | /* If this is a local watchpoint, we only want to check if the |
5160 | watchpoint frame is in scope if the current thread is the thread | |
5161 | that was used to create the watchpoint. */ | |
5162 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5163 | return WP_IGNORE; |
f6bc2008 | 5164 | |
c906108c SS |
5165 | if (b->exp_valid_block == NULL) |
5166 | within_current_scope = 1; | |
5167 | else | |
5168 | { | |
edb3359d DJ |
5169 | struct frame_info *frame = get_current_frame (); |
5170 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5171 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5172 | ||
c9cf6e20 | 5173 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5174 | still in the function but the stack frame has already been |
5175 | invalidated. Since we can't rely on the values of local | |
5176 | variables after the stack has been destroyed, we are treating | |
5177 | the watchpoint in that state as `not changed' without further | |
5178 | checking. Don't mark watchpoints as changed if the current | |
5179 | frame is in an epilogue - even if they are in some other | |
5180 | frame, our view of the stack is likely to be wrong and | |
5181 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5182 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5183 | return WP_IGNORE; |
a0f49112 | 5184 | |
101dcfbe | 5185 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5186 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5187 | |
5188 | /* If we've gotten confused in the unwinder, we might have | |
5189 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5190 | if (within_current_scope) |
5191 | { | |
5192 | struct symbol *function; | |
5193 | ||
5194 | function = get_frame_function (fr); | |
5195 | if (function == NULL | |
5196 | || !contained_in (b->exp_valid_block, | |
5197 | SYMBOL_BLOCK_VALUE (function))) | |
5198 | within_current_scope = 0; | |
5199 | } | |
69fbadd5 | 5200 | |
edb3359d | 5201 | if (within_current_scope) |
c906108c SS |
5202 | /* If we end up stopping, the current frame will get selected |
5203 | in normal_stop. So this call to select_frame won't affect | |
5204 | the user. */ | |
0f7d239c | 5205 | select_frame (fr); |
c906108c | 5206 | } |
c5aa993b | 5207 | |
c906108c SS |
5208 | if (within_current_scope) |
5209 | { | |
4a64f543 MS |
5210 | /* We use value_{,free_to_}mark because it could be a *long* |
5211 | time before we return to the command level and call | |
5212 | free_all_values. We can't call free_all_values because we | |
5213 | might be in the middle of evaluating a function call. */ | |
c906108c | 5214 | |
0cf6dd15 | 5215 | int pc = 0; |
9c06b0b4 | 5216 | struct value *mark; |
fa4727a6 DJ |
5217 | struct value *new_val; |
5218 | ||
3a5c3e22 | 5219 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5220 | /* Since we don't know the exact trigger address (from |
5221 | stopped_data_address), just tell the user we've triggered | |
5222 | a mask watchpoint. */ | |
5223 | return WP_VALUE_CHANGED; | |
5224 | ||
5225 | mark = value_mark (); | |
3a1115a0 | 5226 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5227 | |
bb9d5f81 PP |
5228 | if (b->val_bitsize != 0) |
5229 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5230 | ||
4a64f543 MS |
5231 | /* We use value_equal_contents instead of value_equal because |
5232 | the latter coerces an array to a pointer, thus comparing just | |
5233 | the address of the array instead of its contents. This is | |
5234 | not what we want. */ | |
fa4727a6 | 5235 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5236 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5237 | { |
fa4727a6 DJ |
5238 | if (new_val != NULL) |
5239 | { | |
5240 | release_value (new_val); | |
5241 | value_free_to_mark (mark); | |
5242 | } | |
c906108c SS |
5243 | bs->old_val = b->val; |
5244 | b->val = new_val; | |
fa4727a6 | 5245 | b->val_valid = 1; |
c906108c SS |
5246 | return WP_VALUE_CHANGED; |
5247 | } | |
5248 | else | |
5249 | { | |
60e1c644 | 5250 | /* Nothing changed. */ |
c906108c | 5251 | value_free_to_mark (mark); |
c906108c SS |
5252 | return WP_VALUE_NOT_CHANGED; |
5253 | } | |
5254 | } | |
5255 | else | |
5256 | { | |
5257 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5258 | if we temporarily ignored the watchpoint, then when |
5259 | we reenter the block in which it is valid it contains | |
5260 | garbage (in the case of a function, it may have two | |
5261 | garbage values, one before and one after the prologue). | |
5262 | So we can't even detect the first assignment to it and | |
5263 | watch after that (since the garbage may or may not equal | |
5264 | the first value assigned). */ | |
348d480f PA |
5265 | /* We print all the stop information in |
5266 | breakpoint_ops->print_it, but in this case, by the time we | |
5267 | call breakpoint_ops->print_it this bp will be deleted | |
5268 | already. So we have no choice but print the information | |
5269 | here. */ | |
468afe6c | 5270 | |
0e454242 | 5271 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5272 | { |
5273 | struct ui_out *uiout = current_uiout; | |
5274 | ||
5275 | if (ui_out_is_mi_like_p (uiout)) | |
5276 | ui_out_field_string | |
5277 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5278 | ui_out_text (uiout, "\nWatchpoint "); | |
5279 | ui_out_field_int (uiout, "wpnum", b->base.number); | |
5280 | ui_out_text (uiout, | |
5281 | " deleted because the program has left the block in\n" | |
5282 | "which its expression is valid.\n"); | |
5283 | } | |
4ce44c66 | 5284 | |
cdac0397 | 5285 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5286 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5287 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5288 | |
5289 | return WP_DELETED; | |
5290 | } | |
5291 | } | |
5292 | ||
18a18393 | 5293 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5294 | breakpoint location BL. This function does not check if we should |
5295 | stop, only if BL explains the stop. */ | |
5296 | ||
18a18393 | 5297 | static int |
6c95b8df | 5298 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5299 | struct address_space *aspace, CORE_ADDR bp_addr, |
5300 | const struct target_waitstatus *ws) | |
18a18393 VP |
5301 | { |
5302 | struct breakpoint *b = bl->owner; | |
5303 | ||
348d480f | 5304 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5305 | gdb_assert (b != NULL); |
5306 | ||
09ac7c10 | 5307 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5308 | } |
5309 | ||
3a5c3e22 PA |
5310 | /* Determine if the watched values have actually changed, and we |
5311 | should stop. If not, set BS->stop to 0. */ | |
5312 | ||
18a18393 VP |
5313 | static void |
5314 | bpstat_check_watchpoint (bpstat bs) | |
5315 | { | |
2bdf28a0 | 5316 | const struct bp_location *bl; |
3a5c3e22 | 5317 | struct watchpoint *b; |
2bdf28a0 JK |
5318 | |
5319 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5320 | bl = bs->bp_location_at; |
2bdf28a0 | 5321 | gdb_assert (bl != NULL); |
3a5c3e22 | 5322 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5323 | gdb_assert (b != NULL); |
18a18393 | 5324 | |
18a18393 | 5325 | { |
18a18393 VP |
5326 | int must_check_value = 0; |
5327 | ||
3a5c3e22 | 5328 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5329 | /* For a software watchpoint, we must always check the |
5330 | watched value. */ | |
5331 | must_check_value = 1; | |
5332 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5333 | /* We have a hardware watchpoint (read, write, or access) | |
5334 | and the target earlier reported an address watched by | |
5335 | this watchpoint. */ | |
5336 | must_check_value = 1; | |
5337 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5338 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5339 | /* We were stopped by a hardware watchpoint, but the target could |
5340 | not report the data address. We must check the watchpoint's | |
5341 | value. Access and read watchpoints are out of luck; without | |
5342 | a data address, we can't figure it out. */ | |
5343 | must_check_value = 1; | |
3a5c3e22 | 5344 | |
18a18393 VP |
5345 | if (must_check_value) |
5346 | { | |
3e43a32a MS |
5347 | char *message |
5348 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5349 | b->base.number); |
18a18393 VP |
5350 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5351 | int e = catch_errors (watchpoint_check, bs, message, | |
5352 | RETURN_MASK_ALL); | |
5353 | do_cleanups (cleanups); | |
5354 | switch (e) | |
5355 | { | |
5356 | case WP_DELETED: | |
5357 | /* We've already printed what needs to be printed. */ | |
5358 | bs->print_it = print_it_done; | |
5359 | /* Stop. */ | |
5360 | break; | |
60e1c644 PA |
5361 | case WP_IGNORE: |
5362 | bs->print_it = print_it_noop; | |
5363 | bs->stop = 0; | |
5364 | break; | |
18a18393 | 5365 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5366 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5367 | { |
85d721b8 PA |
5368 | /* There are two cases to consider here: |
5369 | ||
4a64f543 | 5370 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5371 | In that case, trust the target, and always report |
5372 | the watchpoint hit to the user. Even though | |
5373 | reads don't cause value changes, the value may | |
5374 | have changed since the last time it was read, and | |
5375 | since we're not trapping writes, we will not see | |
5376 | those, and as such we should ignore our notion of | |
5377 | old value. | |
5378 | ||
4a64f543 | 5379 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5380 | reads and writes. There are two ways this may |
5381 | happen: | |
5382 | ||
4a64f543 | 5383 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5384 | reads only, but can break on accesses (reads or |
5385 | writes), such as e.g., x86. We detect this case | |
5386 | at the time we try to insert read watchpoints. | |
5387 | ||
4a64f543 | 5388 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5389 | watchpoints, but, the user set an access or write |
5390 | watchpoint watching the same memory as this read | |
5391 | watchpoint. | |
5392 | ||
5393 | If we're watching memory writes as well as reads, | |
5394 | ignore watchpoint hits when we find that the | |
5395 | value hasn't changed, as reads don't cause | |
5396 | changes. This still gives false positives when | |
5397 | the program writes the same value to memory as | |
5398 | what there was already in memory (we will confuse | |
5399 | it for a read), but it's much better than | |
5400 | nothing. */ | |
5401 | ||
5402 | int other_write_watchpoint = 0; | |
5403 | ||
5404 | if (bl->watchpoint_type == hw_read) | |
5405 | { | |
5406 | struct breakpoint *other_b; | |
5407 | ||
5408 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5409 | if (other_b->type == bp_hardware_watchpoint |
5410 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5411 | { |
3a5c3e22 PA |
5412 | struct watchpoint *other_w = |
5413 | (struct watchpoint *) other_b; | |
5414 | ||
5415 | if (other_w->watchpoint_triggered | |
5416 | == watch_triggered_yes) | |
5417 | { | |
5418 | other_write_watchpoint = 1; | |
5419 | break; | |
5420 | } | |
85d721b8 PA |
5421 | } |
5422 | } | |
5423 | ||
5424 | if (other_write_watchpoint | |
5425 | || bl->watchpoint_type == hw_access) | |
5426 | { | |
5427 | /* We're watching the same memory for writes, | |
5428 | and the value changed since the last time we | |
5429 | updated it, so this trap must be for a write. | |
5430 | Ignore it. */ | |
5431 | bs->print_it = print_it_noop; | |
5432 | bs->stop = 0; | |
5433 | } | |
18a18393 VP |
5434 | } |
5435 | break; | |
5436 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5437 | if (b->base.type == bp_hardware_watchpoint |
5438 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5439 | { |
5440 | /* Don't stop: write watchpoints shouldn't fire if | |
5441 | the value hasn't changed. */ | |
5442 | bs->print_it = print_it_noop; | |
5443 | bs->stop = 0; | |
5444 | } | |
5445 | /* Stop. */ | |
5446 | break; | |
5447 | default: | |
5448 | /* Can't happen. */ | |
5449 | case 0: | |
5450 | /* Error from catch_errors. */ | |
468afe6c | 5451 | { |
0e454242 | 5452 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5453 | { |
5454 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5455 | b->base.number); | |
5456 | } | |
5457 | watchpoint_del_at_next_stop (b); | |
5458 | /* We've already printed what needs to be printed. */ | |
5459 | bs->print_it = print_it_done; | |
5460 | } | |
18a18393 VP |
5461 | break; |
5462 | } | |
5463 | } | |
5464 | else /* must_check_value == 0 */ | |
5465 | { | |
5466 | /* This is a case where some watchpoint(s) triggered, but | |
5467 | not at the address of this watchpoint, or else no | |
5468 | watchpoint triggered after all. So don't print | |
5469 | anything for this watchpoint. */ | |
5470 | bs->print_it = print_it_noop; | |
5471 | bs->stop = 0; | |
5472 | } | |
5473 | } | |
5474 | } | |
5475 | ||
7d4df6a4 DE |
5476 | /* For breakpoints that are currently marked as telling gdb to stop, |
5477 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5478 | of breakpoint referred to by BS. If we should not stop for this |
5479 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5480 | |
18a18393 VP |
5481 | static void |
5482 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5483 | { | |
2bdf28a0 JK |
5484 | const struct bp_location *bl; |
5485 | struct breakpoint *b; | |
7d4df6a4 DE |
5486 | int value_is_zero = 0; |
5487 | struct expression *cond; | |
5488 | ||
5489 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5490 | |
5491 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5492 | bl = bs->bp_location_at; |
2bdf28a0 | 5493 | gdb_assert (bl != NULL); |
f431efe5 | 5494 | b = bs->breakpoint_at; |
2bdf28a0 | 5495 | gdb_assert (b != NULL); |
18a18393 | 5496 | |
b775012e LM |
5497 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5498 | need to do so again since GDB does not know if we stopped due to a | |
5499 | breakpoint or a single step breakpoint. */ | |
5500 | ||
18a18393 | 5501 | if (frame_id_p (b->frame_id) |
edb3359d | 5502 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5503 | { |
7d4df6a4 DE |
5504 | bs->stop = 0; |
5505 | return; | |
5506 | } | |
60e1c644 | 5507 | |
12ab52e9 PA |
5508 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5509 | evaluating the condition if this isn't the specified | |
5510 | thread/task. */ | |
5d5658a1 | 5511 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5512 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5513 | ||
6c1b0f7b DE |
5514 | { |
5515 | bs->stop = 0; | |
5516 | return; | |
5517 | } | |
5518 | ||
6dddc817 DE |
5519 | /* Evaluate extension language breakpoints that have a "stop" method |
5520 | implemented. */ | |
5521 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5522 | |
7d4df6a4 DE |
5523 | if (is_watchpoint (b)) |
5524 | { | |
5525 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5526 | |
7d4df6a4 DE |
5527 | cond = w->cond_exp; |
5528 | } | |
5529 | else | |
5530 | cond = bl->cond; | |
60e1c644 | 5531 | |
7d4df6a4 DE |
5532 | if (cond && b->disposition != disp_del_at_next_stop) |
5533 | { | |
5534 | int within_current_scope = 1; | |
5535 | struct watchpoint * w; | |
60e1c644 | 5536 | |
7d4df6a4 DE |
5537 | /* We use value_mark and value_free_to_mark because it could |
5538 | be a long time before we return to the command level and | |
5539 | call free_all_values. We can't call free_all_values | |
5540 | because we might be in the middle of evaluating a | |
5541 | function call. */ | |
5542 | struct value *mark = value_mark (); | |
5543 | ||
5544 | if (is_watchpoint (b)) | |
5545 | w = (struct watchpoint *) b; | |
5546 | else | |
5547 | w = NULL; | |
5548 | ||
5549 | /* Need to select the frame, with all that implies so that | |
5550 | the conditions will have the right context. Because we | |
5551 | use the frame, we will not see an inlined function's | |
5552 | variables when we arrive at a breakpoint at the start | |
5553 | of the inlined function; the current frame will be the | |
5554 | call site. */ | |
5555 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5556 | select_frame (get_current_frame ()); | |
5557 | else | |
18a18393 | 5558 | { |
7d4df6a4 DE |
5559 | struct frame_info *frame; |
5560 | ||
5561 | /* For local watchpoint expressions, which particular | |
5562 | instance of a local is being watched matters, so we | |
5563 | keep track of the frame to evaluate the expression | |
5564 | in. To evaluate the condition however, it doesn't | |
5565 | really matter which instantiation of the function | |
5566 | where the condition makes sense triggers the | |
5567 | watchpoint. This allows an expression like "watch | |
5568 | global if q > 10" set in `func', catch writes to | |
5569 | global on all threads that call `func', or catch | |
5570 | writes on all recursive calls of `func' by a single | |
5571 | thread. We simply always evaluate the condition in | |
5572 | the innermost frame that's executing where it makes | |
5573 | sense to evaluate the condition. It seems | |
5574 | intuitive. */ | |
5575 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5576 | if (frame != NULL) | |
5577 | select_frame (frame); | |
5578 | else | |
5579 | within_current_scope = 0; | |
18a18393 | 5580 | } |
7d4df6a4 DE |
5581 | if (within_current_scope) |
5582 | value_is_zero | |
5583 | = catch_errors (breakpoint_cond_eval, cond, | |
5584 | "Error in testing breakpoint condition:\n", | |
5585 | RETURN_MASK_ALL); | |
5586 | else | |
18a18393 | 5587 | { |
7d4df6a4 DE |
5588 | warning (_("Watchpoint condition cannot be tested " |
5589 | "in the current scope")); | |
5590 | /* If we failed to set the right context for this | |
5591 | watchpoint, unconditionally report it. */ | |
5592 | value_is_zero = 0; | |
18a18393 | 5593 | } |
7d4df6a4 DE |
5594 | /* FIXME-someday, should give breakpoint #. */ |
5595 | value_free_to_mark (mark); | |
18a18393 | 5596 | } |
7d4df6a4 DE |
5597 | |
5598 | if (cond && value_is_zero) | |
5599 | { | |
5600 | bs->stop = 0; | |
5601 | } | |
7d4df6a4 DE |
5602 | else if (b->ignore_count > 0) |
5603 | { | |
5604 | b->ignore_count--; | |
5605 | bs->stop = 0; | |
5606 | /* Increase the hit count even though we don't stop. */ | |
5607 | ++(b->hit_count); | |
5608 | observer_notify_breakpoint_modified (b); | |
5609 | } | |
18a18393 VP |
5610 | } |
5611 | ||
1cf4d951 PA |
5612 | /* Returns true if we need to track moribund locations of LOC's type |
5613 | on the current target. */ | |
5614 | ||
5615 | static int | |
5616 | need_moribund_for_location_type (struct bp_location *loc) | |
5617 | { | |
5618 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5619 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5620 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5621 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5622 | } | |
5623 | ||
18a18393 | 5624 | |
9709f61c | 5625 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5626 | BP_ADDR in thread PTID. |
c906108c | 5627 | |
d983da9c | 5628 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5629 | don't understand this stop. Result is a chain of bpstat's such |
5630 | that: | |
c906108c | 5631 | |
c5aa993b | 5632 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5633 | |
c5aa993b | 5634 | if we understand why we stopped, the result is not null. |
c906108c | 5635 | |
c5aa993b JM |
5636 | Each element of the chain refers to a particular breakpoint or |
5637 | watchpoint at which we have stopped. (We may have stopped for | |
5638 | several reasons concurrently.) | |
c906108c | 5639 | |
c5aa993b JM |
5640 | Each element of the chain has valid next, breakpoint_at, |
5641 | commands, FIXME??? fields. */ | |
c906108c SS |
5642 | |
5643 | bpstat | |
6c95b8df | 5644 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5645 | CORE_ADDR bp_addr, ptid_t ptid, |
5646 | const struct target_waitstatus *ws) | |
c906108c | 5647 | { |
0d381245 | 5648 | struct breakpoint *b = NULL; |
afe38095 | 5649 | struct bp_location *bl; |
20874c92 | 5650 | struct bp_location *loc; |
5760d0ab JK |
5651 | /* First item of allocated bpstat's. */ |
5652 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5653 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5654 | bpstat bs; |
20874c92 | 5655 | int ix; |
429374b8 | 5656 | int need_remove_insert; |
f431efe5 | 5657 | int removed_any; |
c906108c | 5658 | |
f431efe5 PA |
5659 | /* First, build the bpstat chain with locations that explain a |
5660 | target stop, while being careful to not set the target running, | |
5661 | as that may invalidate locations (in particular watchpoint | |
5662 | locations are recreated). Resuming will happen here with | |
5663 | breakpoint conditions or watchpoint expressions that include | |
5664 | inferior function calls. */ | |
c5aa993b | 5665 | |
429374b8 JK |
5666 | ALL_BREAKPOINTS (b) |
5667 | { | |
1a853c52 | 5668 | if (!breakpoint_enabled (b)) |
429374b8 | 5669 | continue; |
a5606eee | 5670 | |
429374b8 JK |
5671 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5672 | { | |
4a64f543 MS |
5673 | /* For hardware watchpoints, we look only at the first |
5674 | location. The watchpoint_check function will work on the | |
5675 | entire expression, not the individual locations. For | |
5676 | read watchpoints, the watchpoints_triggered function has | |
5677 | checked all locations already. */ | |
429374b8 JK |
5678 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5679 | break; | |
18a18393 | 5680 | |
f6592439 | 5681 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5682 | continue; |
c5aa993b | 5683 | |
09ac7c10 | 5684 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5685 | continue; |
c5aa993b | 5686 | |
4a64f543 MS |
5687 | /* Come here if it's a watchpoint, or if the break address |
5688 | matches. */ | |
c5aa993b | 5689 | |
4a64f543 MS |
5690 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5691 | explain stop. */ | |
c5aa993b | 5692 | |
f431efe5 PA |
5693 | /* Assume we stop. Should we find a watchpoint that is not |
5694 | actually triggered, or if the condition of the breakpoint | |
5695 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5696 | bs->stop = 1; |
5697 | bs->print = 1; | |
d983da9c | 5698 | |
f431efe5 PA |
5699 | /* If this is a scope breakpoint, mark the associated |
5700 | watchpoint as triggered so that we will handle the | |
5701 | out-of-scope event. We'll get to the watchpoint next | |
5702 | iteration. */ | |
d0fb5eae | 5703 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5704 | { |
5705 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5706 | ||
5707 | w->watchpoint_triggered = watch_triggered_yes; | |
5708 | } | |
f431efe5 PA |
5709 | } |
5710 | } | |
5711 | ||
7c16b83e | 5712 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5713 | if (!target_supports_stopped_by_sw_breakpoint () |
5714 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5715 | { |
1cf4d951 | 5716 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5717 | { |
1cf4d951 PA |
5718 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5719 | && need_moribund_for_location_type (loc)) | |
5720 | { | |
5721 | bs = bpstat_alloc (loc, &bs_link); | |
5722 | /* For hits of moribund locations, we should just proceed. */ | |
5723 | bs->stop = 0; | |
5724 | bs->print = 0; | |
5725 | bs->print_it = print_it_noop; | |
5726 | } | |
f431efe5 PA |
5727 | } |
5728 | } | |
5729 | ||
edcc5120 TT |
5730 | /* A bit of special processing for shlib breakpoints. We need to |
5731 | process solib loading here, so that the lists of loaded and | |
5732 | unloaded libraries are correct before we handle "catch load" and | |
5733 | "catch unload". */ | |
5734 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5735 | { | |
5d268276 | 5736 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5737 | { |
5738 | handle_solib_event (); | |
5739 | break; | |
5740 | } | |
5741 | } | |
5742 | ||
f431efe5 PA |
5743 | /* Now go through the locations that caused the target to stop, and |
5744 | check whether we're interested in reporting this stop to higher | |
5745 | layers, or whether we should resume the target transparently. */ | |
5746 | ||
5747 | removed_any = 0; | |
5748 | ||
5760d0ab | 5749 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5750 | { |
5751 | if (!bs->stop) | |
5752 | continue; | |
5753 | ||
f431efe5 | 5754 | b = bs->breakpoint_at; |
348d480f PA |
5755 | b->ops->check_status (bs); |
5756 | if (bs->stop) | |
28010a5d | 5757 | { |
348d480f | 5758 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5759 | |
429374b8 JK |
5760 | if (bs->stop) |
5761 | { | |
5762 | ++(b->hit_count); | |
8d3788bd | 5763 | observer_notify_breakpoint_modified (b); |
c906108c | 5764 | |
4a64f543 | 5765 | /* We will stop here. */ |
429374b8 JK |
5766 | if (b->disposition == disp_disable) |
5767 | { | |
816338b5 | 5768 | --(b->enable_count); |
1a853c52 | 5769 | if (b->enable_count <= 0) |
429374b8 | 5770 | b->enable_state = bp_disabled; |
f431efe5 | 5771 | removed_any = 1; |
429374b8 JK |
5772 | } |
5773 | if (b->silent) | |
5774 | bs->print = 0; | |
5775 | bs->commands = b->commands; | |
9add0f1b | 5776 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5777 | if (command_line_is_silent (bs->commands |
5778 | ? bs->commands->commands : NULL)) | |
5779 | bs->print = 0; | |
9d6e6e84 HZ |
5780 | |
5781 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5782 | } |
5783 | ||
348d480f | 5784 | } |
a9b3a50f PA |
5785 | |
5786 | /* Print nothing for this entry if we don't stop or don't | |
5787 | print. */ | |
5788 | if (!bs->stop || !bs->print) | |
5789 | bs->print_it = print_it_noop; | |
429374b8 | 5790 | } |
876fa593 | 5791 | |
d983da9c DJ |
5792 | /* If we aren't stopping, the value of some hardware watchpoint may |
5793 | not have changed, but the intermediate memory locations we are | |
5794 | watching may have. Don't bother if we're stopping; this will get | |
5795 | done later. */ | |
d832cb68 | 5796 | need_remove_insert = 0; |
5760d0ab JK |
5797 | if (! bpstat_causes_stop (bs_head)) |
5798 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5799 | if (!bs->stop |
f431efe5 PA |
5800 | && bs->breakpoint_at |
5801 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5802 | { |
3a5c3e22 PA |
5803 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5804 | ||
5805 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5806 | need_remove_insert = 1; |
d983da9c DJ |
5807 | } |
5808 | ||
d832cb68 | 5809 | if (need_remove_insert) |
44702360 | 5810 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5811 | else if (removed_any) |
44702360 | 5812 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5813 | |
5760d0ab | 5814 | return bs_head; |
c906108c | 5815 | } |
628fe4e4 JK |
5816 | |
5817 | static void | |
5818 | handle_jit_event (void) | |
5819 | { | |
5820 | struct frame_info *frame; | |
5821 | struct gdbarch *gdbarch; | |
5822 | ||
243a9253 PA |
5823 | if (debug_infrun) |
5824 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5825 | ||
628fe4e4 JK |
5826 | /* Switch terminal for any messages produced by |
5827 | breakpoint_re_set. */ | |
5828 | target_terminal_ours_for_output (); | |
5829 | ||
5830 | frame = get_current_frame (); | |
5831 | gdbarch = get_frame_arch (frame); | |
5832 | ||
5833 | jit_event_handler (gdbarch); | |
5834 | ||
5835 | target_terminal_inferior (); | |
5836 | } | |
5837 | ||
5838 | /* Prepare WHAT final decision for infrun. */ | |
5839 | ||
5840 | /* Decide what infrun needs to do with this bpstat. */ | |
5841 | ||
c906108c | 5842 | struct bpstat_what |
0e30163f | 5843 | bpstat_what (bpstat bs_head) |
c906108c | 5844 | { |
c906108c | 5845 | struct bpstat_what retval; |
0e30163f | 5846 | bpstat bs; |
c906108c | 5847 | |
628fe4e4 | 5848 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5849 | retval.call_dummy = STOP_NONE; |
186c406b | 5850 | retval.is_longjmp = 0; |
628fe4e4 | 5851 | |
0e30163f | 5852 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5853 | { |
628fe4e4 JK |
5854 | /* Extract this BS's action. After processing each BS, we check |
5855 | if its action overrides all we've seem so far. */ | |
5856 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5857 | enum bptype bptype; | |
5858 | ||
c906108c | 5859 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5860 | { |
5861 | /* I suspect this can happen if it was a momentary | |
5862 | breakpoint which has since been deleted. */ | |
5863 | bptype = bp_none; | |
5864 | } | |
20874c92 | 5865 | else |
f431efe5 | 5866 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5867 | |
5868 | switch (bptype) | |
c906108c SS |
5869 | { |
5870 | case bp_none: | |
628fe4e4 | 5871 | break; |
c906108c SS |
5872 | case bp_breakpoint: |
5873 | case bp_hardware_breakpoint: | |
7c16b83e | 5874 | case bp_single_step: |
c906108c SS |
5875 | case bp_until: |
5876 | case bp_finish: | |
a9b3a50f | 5877 | case bp_shlib_event: |
c906108c SS |
5878 | if (bs->stop) |
5879 | { | |
5880 | if (bs->print) | |
628fe4e4 | 5881 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5882 | else |
628fe4e4 | 5883 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5884 | } |
5885 | else | |
628fe4e4 | 5886 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5887 | break; |
5888 | case bp_watchpoint: | |
5889 | case bp_hardware_watchpoint: | |
5890 | case bp_read_watchpoint: | |
5891 | case bp_access_watchpoint: | |
5892 | if (bs->stop) | |
5893 | { | |
5894 | if (bs->print) | |
628fe4e4 | 5895 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5896 | else |
628fe4e4 | 5897 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5898 | } |
5899 | else | |
628fe4e4 JK |
5900 | { |
5901 | /* There was a watchpoint, but we're not stopping. | |
5902 | This requires no further action. */ | |
5903 | } | |
c906108c SS |
5904 | break; |
5905 | case bp_longjmp: | |
e2e4d78b | 5906 | case bp_longjmp_call_dummy: |
186c406b | 5907 | case bp_exception: |
0a39bb32 PA |
5908 | if (bs->stop) |
5909 | { | |
5910 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5911 | retval.is_longjmp = bptype != bp_exception; | |
5912 | } | |
5913 | else | |
5914 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5915 | break; |
5916 | case bp_longjmp_resume: | |
186c406b | 5917 | case bp_exception_resume: |
0a39bb32 PA |
5918 | if (bs->stop) |
5919 | { | |
5920 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5921 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5922 | } | |
5923 | else | |
5924 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5925 | break; |
5926 | case bp_step_resume: | |
5927 | if (bs->stop) | |
628fe4e4 JK |
5928 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5929 | else | |
c906108c | 5930 | { |
628fe4e4 JK |
5931 | /* It is for the wrong frame. */ |
5932 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5933 | } |
c906108c | 5934 | break; |
2c03e5be PA |
5935 | case bp_hp_step_resume: |
5936 | if (bs->stop) | |
5937 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5938 | else | |
5939 | { | |
5940 | /* It is for the wrong frame. */ | |
5941 | this_action = BPSTAT_WHAT_SINGLE; | |
5942 | } | |
5943 | break; | |
c906108c | 5944 | case bp_watchpoint_scope: |
c4093a6a | 5945 | case bp_thread_event: |
1900040c | 5946 | case bp_overlay_event: |
0fd8e87f | 5947 | case bp_longjmp_master: |
aa7d318d | 5948 | case bp_std_terminate_master: |
186c406b | 5949 | case bp_exception_master: |
628fe4e4 | 5950 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5951 | break; |
ce78b96d | 5952 | case bp_catchpoint: |
c5aa993b JM |
5953 | if (bs->stop) |
5954 | { | |
5955 | if (bs->print) | |
628fe4e4 | 5956 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5957 | else |
628fe4e4 | 5958 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5959 | } |
5960 | else | |
628fe4e4 JK |
5961 | { |
5962 | /* There was a catchpoint, but we're not stopping. | |
5963 | This requires no further action. */ | |
5964 | } | |
5965 | break; | |
628fe4e4 | 5966 | case bp_jit_event: |
628fe4e4 | 5967 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5968 | break; |
c906108c | 5969 | case bp_call_dummy: |
53a5351d JM |
5970 | /* Make sure the action is stop (silent or noisy), |
5971 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5972 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5973 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5974 | break; |
5975 | case bp_std_terminate: | |
5976 | /* Make sure the action is stop (silent or noisy), | |
5977 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5978 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5979 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5980 | break; |
1042e4c0 | 5981 | case bp_tracepoint: |
7a697b8d | 5982 | case bp_fast_tracepoint: |
0fb4aa4b | 5983 | case bp_static_tracepoint: |
1042e4c0 SS |
5984 | /* Tracepoint hits should not be reported back to GDB, and |
5985 | if one got through somehow, it should have been filtered | |
5986 | out already. */ | |
5987 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5988 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5989 | break; |
5990 | case bp_gnu_ifunc_resolver: | |
5991 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5992 | this_action = BPSTAT_WHAT_SINGLE; | |
5993 | break; | |
5994 | case bp_gnu_ifunc_resolver_return: | |
5995 | /* The breakpoint will be removed, execution will restart from the | |
5996 | PC of the former breakpoint. */ | |
5997 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5998 | break; | |
e7e0cddf SS |
5999 | |
6000 | case bp_dprintf: | |
a11cfd87 HZ |
6001 | if (bs->stop) |
6002 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
6003 | else | |
6004 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
6005 | break; |
6006 | ||
628fe4e4 JK |
6007 | default: |
6008 | internal_error (__FILE__, __LINE__, | |
6009 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 6010 | } |
628fe4e4 | 6011 | |
325fac50 | 6012 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 6013 | } |
628fe4e4 | 6014 | |
243a9253 PA |
6015 | return retval; |
6016 | } | |
628fe4e4 | 6017 | |
243a9253 PA |
6018 | void |
6019 | bpstat_run_callbacks (bpstat bs_head) | |
6020 | { | |
6021 | bpstat bs; | |
628fe4e4 | 6022 | |
0e30163f JK |
6023 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6024 | { | |
6025 | struct breakpoint *b = bs->breakpoint_at; | |
6026 | ||
6027 | if (b == NULL) | |
6028 | continue; | |
6029 | switch (b->type) | |
6030 | { | |
243a9253 PA |
6031 | case bp_jit_event: |
6032 | handle_jit_event (); | |
6033 | break; | |
0e30163f JK |
6034 | case bp_gnu_ifunc_resolver: |
6035 | gnu_ifunc_resolver_stop (b); | |
6036 | break; | |
6037 | case bp_gnu_ifunc_resolver_return: | |
6038 | gnu_ifunc_resolver_return_stop (b); | |
6039 | break; | |
6040 | } | |
6041 | } | |
c906108c SS |
6042 | } |
6043 | ||
6044 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6045 | without hardware support). This isn't related to a specific bpstat, | |
6046 | just to things like whether watchpoints are set. */ | |
6047 | ||
c5aa993b | 6048 | int |
fba45db2 | 6049 | bpstat_should_step (void) |
c906108c SS |
6050 | { |
6051 | struct breakpoint *b; | |
cc59ec59 | 6052 | |
c906108c | 6053 | ALL_BREAKPOINTS (b) |
717a8278 | 6054 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6055 | return 1; |
c906108c SS |
6056 | return 0; |
6057 | } | |
6058 | ||
67822962 PA |
6059 | int |
6060 | bpstat_causes_stop (bpstat bs) | |
6061 | { | |
6062 | for (; bs != NULL; bs = bs->next) | |
6063 | if (bs->stop) | |
6064 | return 1; | |
6065 | ||
6066 | return 0; | |
6067 | } | |
6068 | ||
c906108c | 6069 | \f |
c5aa993b | 6070 | |
170b53b2 UW |
6071 | /* Compute a string of spaces suitable to indent the next line |
6072 | so it starts at the position corresponding to the table column | |
6073 | named COL_NAME in the currently active table of UIOUT. */ | |
6074 | ||
6075 | static char * | |
6076 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6077 | { | |
6078 | static char wrap_indent[80]; | |
6079 | int i, total_width, width, align; | |
6080 | char *text; | |
6081 | ||
6082 | total_width = 0; | |
6083 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6084 | { | |
6085 | if (strcmp (text, col_name) == 0) | |
6086 | { | |
6087 | gdb_assert (total_width < sizeof wrap_indent); | |
6088 | memset (wrap_indent, ' ', total_width); | |
6089 | wrap_indent[total_width] = 0; | |
6090 | ||
6091 | return wrap_indent; | |
6092 | } | |
6093 | ||
6094 | total_width += width + 1; | |
6095 | } | |
6096 | ||
6097 | return NULL; | |
6098 | } | |
6099 | ||
b775012e LM |
6100 | /* Determine if the locations of this breakpoint will have their conditions |
6101 | evaluated by the target, host or a mix of both. Returns the following: | |
6102 | ||
6103 | "host": Host evals condition. | |
6104 | "host or target": Host or Target evals condition. | |
6105 | "target": Target evals condition. | |
6106 | */ | |
6107 | ||
6108 | static const char * | |
6109 | bp_condition_evaluator (struct breakpoint *b) | |
6110 | { | |
6111 | struct bp_location *bl; | |
6112 | char host_evals = 0; | |
6113 | char target_evals = 0; | |
6114 | ||
6115 | if (!b) | |
6116 | return NULL; | |
6117 | ||
6118 | if (!is_breakpoint (b)) | |
6119 | return NULL; | |
6120 | ||
6121 | if (gdb_evaluates_breakpoint_condition_p () | |
6122 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6123 | return condition_evaluation_host; | |
6124 | ||
6125 | for (bl = b->loc; bl; bl = bl->next) | |
6126 | { | |
6127 | if (bl->cond_bytecode) | |
6128 | target_evals++; | |
6129 | else | |
6130 | host_evals++; | |
6131 | } | |
6132 | ||
6133 | if (host_evals && target_evals) | |
6134 | return condition_evaluation_both; | |
6135 | else if (target_evals) | |
6136 | return condition_evaluation_target; | |
6137 | else | |
6138 | return condition_evaluation_host; | |
6139 | } | |
6140 | ||
6141 | /* Determine the breakpoint location's condition evaluator. This is | |
6142 | similar to bp_condition_evaluator, but for locations. */ | |
6143 | ||
6144 | static const char * | |
6145 | bp_location_condition_evaluator (struct bp_location *bl) | |
6146 | { | |
6147 | if (bl && !is_breakpoint (bl->owner)) | |
6148 | return NULL; | |
6149 | ||
6150 | if (gdb_evaluates_breakpoint_condition_p () | |
6151 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6152 | return condition_evaluation_host; | |
6153 | ||
6154 | if (bl && bl->cond_bytecode) | |
6155 | return condition_evaluation_target; | |
6156 | else | |
6157 | return condition_evaluation_host; | |
6158 | } | |
6159 | ||
859825b8 JK |
6160 | /* Print the LOC location out of the list of B->LOC locations. */ |
6161 | ||
170b53b2 UW |
6162 | static void |
6163 | print_breakpoint_location (struct breakpoint *b, | |
6164 | struct bp_location *loc) | |
0d381245 | 6165 | { |
79a45e25 | 6166 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6167 | struct cleanup *old_chain = save_current_program_space (); |
6168 | ||
859825b8 JK |
6169 | if (loc != NULL && loc->shlib_disabled) |
6170 | loc = NULL; | |
6171 | ||
6c95b8df PA |
6172 | if (loc != NULL) |
6173 | set_current_program_space (loc->pspace); | |
6174 | ||
56435ebe | 6175 | if (b->display_canonical) |
f00aae0f KS |
6176 | ui_out_field_string (uiout, "what", |
6177 | event_location_to_string (b->location)); | |
2f202fde | 6178 | else if (loc && loc->symtab) |
0d381245 VP |
6179 | { |
6180 | struct symbol *sym | |
6181 | = find_pc_sect_function (loc->address, loc->section); | |
6182 | if (sym) | |
6183 | { | |
6184 | ui_out_text (uiout, "in "); | |
6185 | ui_out_field_string (uiout, "func", | |
6186 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6187 | ui_out_text (uiout, " "); |
6188 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6189 | ui_out_text (uiout, "at "); | |
0d381245 | 6190 | } |
05cba821 JK |
6191 | ui_out_field_string (uiout, "file", |
6192 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6193 | ui_out_text (uiout, ":"); |
05cba821 | 6194 | |
0d381245 | 6195 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6196 | ui_out_field_string (uiout, "fullname", |
6197 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6198 | |
f8eba3c6 | 6199 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6200 | } |
859825b8 | 6201 | else if (loc) |
0d381245 | 6202 | { |
f99d8bf4 PA |
6203 | struct ui_file *stb = mem_fileopen (); |
6204 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6205 | |
f99d8bf4 | 6206 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6207 | demangle, ""); |
0d381245 | 6208 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6209 | |
6210 | do_cleanups (stb_chain); | |
0d381245 | 6211 | } |
859825b8 | 6212 | else |
f00aae0f KS |
6213 | { |
6214 | ui_out_field_string (uiout, "pending", | |
6215 | event_location_to_string (b->location)); | |
6216 | /* If extra_string is available, it could be holding a condition | |
6217 | or dprintf arguments. In either case, make sure it is printed, | |
6218 | too, but only for non-MI streams. */ | |
6219 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6220 | { | |
6221 | if (b->type == bp_dprintf) | |
6222 | ui_out_text (uiout, ","); | |
6223 | else | |
6224 | ui_out_text (uiout, " "); | |
6225 | ui_out_text (uiout, b->extra_string); | |
6226 | } | |
6227 | } | |
6c95b8df | 6228 | |
b775012e LM |
6229 | if (loc && is_breakpoint (b) |
6230 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6231 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6232 | { | |
6233 | ui_out_text (uiout, " ("); | |
6234 | ui_out_field_string (uiout, "evaluated-by", | |
6235 | bp_location_condition_evaluator (loc)); | |
6236 | ui_out_text (uiout, ")"); | |
6237 | } | |
6238 | ||
6c95b8df | 6239 | do_cleanups (old_chain); |
0d381245 VP |
6240 | } |
6241 | ||
269b11a2 PA |
6242 | static const char * |
6243 | bptype_string (enum bptype type) | |
c906108c | 6244 | { |
c4093a6a JM |
6245 | struct ep_type_description |
6246 | { | |
6247 | enum bptype type; | |
6248 | char *description; | |
6249 | }; | |
6250 | static struct ep_type_description bptypes[] = | |
c906108c | 6251 | { |
c5aa993b JM |
6252 | {bp_none, "?deleted?"}, |
6253 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6254 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6255 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6256 | {bp_until, "until"}, |
6257 | {bp_finish, "finish"}, | |
6258 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6259 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6260 | {bp_read_watchpoint, "read watchpoint"}, |
6261 | {bp_access_watchpoint, "acc watchpoint"}, | |
6262 | {bp_longjmp, "longjmp"}, | |
6263 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6264 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6265 | {bp_exception, "exception"}, |
6266 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6267 | {bp_step_resume, "step resume"}, |
2c03e5be | 6268 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6269 | {bp_watchpoint_scope, "watchpoint scope"}, |
6270 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6271 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6272 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6273 | {bp_thread_event, "thread events"}, |
1900040c | 6274 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6275 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6276 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6277 | {bp_exception_master, "exception master"}, |
ce78b96d | 6278 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6279 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6280 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6281 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6282 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6283 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6284 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6285 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6286 | }; |
269b11a2 PA |
6287 | |
6288 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6289 | || ((int) type != bptypes[(int) type].type)) | |
6290 | internal_error (__FILE__, __LINE__, | |
6291 | _("bptypes table does not describe type #%d."), | |
6292 | (int) type); | |
6293 | ||
6294 | return bptypes[(int) type].description; | |
6295 | } | |
6296 | ||
998580f1 MK |
6297 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6298 | For CLI, prefix the list with the string 'inf'. */ | |
6299 | ||
6300 | static void | |
6301 | output_thread_groups (struct ui_out *uiout, | |
6302 | const char *field_name, | |
6303 | VEC(int) *inf_num, | |
6304 | int mi_only) | |
6305 | { | |
752eb8b4 | 6306 | struct cleanup *back_to; |
998580f1 MK |
6307 | int is_mi = ui_out_is_mi_like_p (uiout); |
6308 | int inf; | |
6309 | int i; | |
6310 | ||
6311 | /* For backward compatibility, don't display inferiors in CLI unless | |
6312 | there are several. Always display them for MI. */ | |
6313 | if (!is_mi && mi_only) | |
6314 | return; | |
6315 | ||
752eb8b4 TT |
6316 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6317 | ||
998580f1 MK |
6318 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6319 | { | |
6320 | if (is_mi) | |
6321 | { | |
6322 | char mi_group[10]; | |
6323 | ||
6324 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6325 | ui_out_field_string (uiout, NULL, mi_group); | |
6326 | } | |
6327 | else | |
6328 | { | |
6329 | if (i == 0) | |
6330 | ui_out_text (uiout, " inf "); | |
6331 | else | |
6332 | ui_out_text (uiout, ", "); | |
6333 | ||
6334 | ui_out_text (uiout, plongest (inf)); | |
6335 | } | |
6336 | } | |
6337 | ||
6338 | do_cleanups (back_to); | |
6339 | } | |
6340 | ||
269b11a2 PA |
6341 | /* Print B to gdb_stdout. */ |
6342 | ||
6343 | static void | |
6344 | print_one_breakpoint_location (struct breakpoint *b, | |
6345 | struct bp_location *loc, | |
6346 | int loc_number, | |
6347 | struct bp_location **last_loc, | |
269b11a2 PA |
6348 | int allflag) |
6349 | { | |
6350 | struct command_line *l; | |
c2c6d25f | 6351 | static char bpenables[] = "nynny"; |
c906108c | 6352 | |
79a45e25 | 6353 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6354 | int header_of_multiple = 0; |
6355 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6356 | struct value_print_options opts; |
6357 | ||
6358 | get_user_print_options (&opts); | |
0d381245 VP |
6359 | |
6360 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6361 | /* See comment in print_one_breakpoint concerning treatment of |
6362 | breakpoints with single disabled location. */ | |
0d381245 VP |
6363 | if (loc == NULL |
6364 | && (b->loc != NULL | |
6365 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6366 | header_of_multiple = 1; | |
6367 | if (loc == NULL) | |
6368 | loc = b->loc; | |
6369 | ||
c4093a6a JM |
6370 | annotate_record (); |
6371 | ||
6372 | /* 1 */ | |
6373 | annotate_field (0); | |
0d381245 VP |
6374 | if (part_of_multiple) |
6375 | { | |
6376 | char *formatted; | |
0c6773c1 | 6377 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6378 | ui_out_field_string (uiout, "number", formatted); |
6379 | xfree (formatted); | |
6380 | } | |
6381 | else | |
6382 | { | |
6383 | ui_out_field_int (uiout, "number", b->number); | |
6384 | } | |
c4093a6a JM |
6385 | |
6386 | /* 2 */ | |
6387 | annotate_field (1); | |
0d381245 VP |
6388 | if (part_of_multiple) |
6389 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6390 | else |
6391 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6392 | |
6393 | /* 3 */ | |
6394 | annotate_field (2); | |
0d381245 VP |
6395 | if (part_of_multiple) |
6396 | ui_out_field_skip (uiout, "disp"); | |
6397 | else | |
2cec12e5 | 6398 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6399 | |
c4093a6a JM |
6400 | |
6401 | /* 4 */ | |
6402 | annotate_field (3); | |
0d381245 | 6403 | if (part_of_multiple) |
54e52265 | 6404 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6405 | else |
4a64f543 MS |
6406 | ui_out_field_fmt (uiout, "enabled", "%c", |
6407 | bpenables[(int) b->enable_state]); | |
54e52265 | 6408 | ui_out_spaces (uiout, 2); |
0d381245 | 6409 | |
c4093a6a JM |
6410 | |
6411 | /* 5 and 6 */ | |
3086aeae | 6412 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6413 | { |
4a64f543 MS |
6414 | /* Although the print_one can possibly print all locations, |
6415 | calling it here is not likely to get any nice result. So, | |
6416 | make sure there's just one location. */ | |
0d381245 | 6417 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6418 | b->ops->print_one (b, last_loc); |
0d381245 | 6419 | } |
3086aeae DJ |
6420 | else |
6421 | switch (b->type) | |
6422 | { | |
6423 | case bp_none: | |
6424 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6425 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6426 | break; |
c906108c | 6427 | |
3086aeae DJ |
6428 | case bp_watchpoint: |
6429 | case bp_hardware_watchpoint: | |
6430 | case bp_read_watchpoint: | |
6431 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6432 | { |
6433 | struct watchpoint *w = (struct watchpoint *) b; | |
6434 | ||
6435 | /* Field 4, the address, is omitted (which makes the columns | |
6436 | not line up too nicely with the headers, but the effect | |
6437 | is relatively readable). */ | |
6438 | if (opts.addressprint) | |
6439 | ui_out_field_skip (uiout, "addr"); | |
6440 | annotate_field (5); | |
6441 | ui_out_field_string (uiout, "what", w->exp_string); | |
6442 | } | |
3086aeae DJ |
6443 | break; |
6444 | ||
3086aeae DJ |
6445 | case bp_breakpoint: |
6446 | case bp_hardware_breakpoint: | |
7c16b83e | 6447 | case bp_single_step: |
3086aeae DJ |
6448 | case bp_until: |
6449 | case bp_finish: | |
6450 | case bp_longjmp: | |
6451 | case bp_longjmp_resume: | |
e2e4d78b | 6452 | case bp_longjmp_call_dummy: |
186c406b TT |
6453 | case bp_exception: |
6454 | case bp_exception_resume: | |
3086aeae | 6455 | case bp_step_resume: |
2c03e5be | 6456 | case bp_hp_step_resume: |
3086aeae DJ |
6457 | case bp_watchpoint_scope: |
6458 | case bp_call_dummy: | |
aa7d318d | 6459 | case bp_std_terminate: |
3086aeae DJ |
6460 | case bp_shlib_event: |
6461 | case bp_thread_event: | |
6462 | case bp_overlay_event: | |
0fd8e87f | 6463 | case bp_longjmp_master: |
aa7d318d | 6464 | case bp_std_terminate_master: |
186c406b | 6465 | case bp_exception_master: |
1042e4c0 | 6466 | case bp_tracepoint: |
7a697b8d | 6467 | case bp_fast_tracepoint: |
0fb4aa4b | 6468 | case bp_static_tracepoint: |
e7e0cddf | 6469 | case bp_dprintf: |
4efc6507 | 6470 | case bp_jit_event: |
0e30163f JK |
6471 | case bp_gnu_ifunc_resolver: |
6472 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6473 | if (opts.addressprint) |
3086aeae DJ |
6474 | { |
6475 | annotate_field (4); | |
54e52265 | 6476 | if (header_of_multiple) |
0d381245 | 6477 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6478 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6479 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6480 | else |
5af949e3 UW |
6481 | ui_out_field_core_addr (uiout, "addr", |
6482 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6483 | } |
6484 | annotate_field (5); | |
0d381245 | 6485 | if (!header_of_multiple) |
170b53b2 | 6486 | print_breakpoint_location (b, loc); |
0d381245 | 6487 | if (b->loc) |
a6d9a66e | 6488 | *last_loc = b->loc; |
3086aeae DJ |
6489 | break; |
6490 | } | |
c906108c | 6491 | |
6c95b8df | 6492 | |
998580f1 | 6493 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6494 | { |
6495 | struct inferior *inf; | |
998580f1 MK |
6496 | VEC(int) *inf_num = NULL; |
6497 | int mi_only = 1; | |
6c95b8df | 6498 | |
998580f1 | 6499 | ALL_INFERIORS (inf) |
6c95b8df PA |
6500 | { |
6501 | if (inf->pspace == loc->pspace) | |
998580f1 | 6502 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6503 | } |
998580f1 MK |
6504 | |
6505 | /* For backward compatibility, don't display inferiors in CLI unless | |
6506 | there are several. Always display for MI. */ | |
6507 | if (allflag | |
6508 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6509 | && (number_of_program_spaces () > 1 | |
6510 | || number_of_inferiors () > 1) | |
6511 | /* LOC is for existing B, it cannot be in | |
6512 | moribund_locations and thus having NULL OWNER. */ | |
6513 | && loc->owner->type != bp_catchpoint)) | |
6514 | mi_only = 0; | |
6515 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6516 | VEC_free (int, inf_num); | |
6c95b8df PA |
6517 | } |
6518 | ||
4a306c9a | 6519 | if (!part_of_multiple) |
c4093a6a | 6520 | { |
4a306c9a JB |
6521 | if (b->thread != -1) |
6522 | { | |
6523 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6524 | "stop only in" line a little further down. */ |
4a306c9a JB |
6525 | ui_out_text (uiout, " thread "); |
6526 | ui_out_field_int (uiout, "thread", b->thread); | |
6527 | } | |
6528 | else if (b->task != 0) | |
6529 | { | |
6530 | ui_out_text (uiout, " task "); | |
6531 | ui_out_field_int (uiout, "task", b->task); | |
6532 | } | |
c4093a6a | 6533 | } |
f1310107 | 6534 | |
8b93c638 | 6535 | ui_out_text (uiout, "\n"); |
f1310107 | 6536 | |
348d480f | 6537 | if (!part_of_multiple) |
f1310107 TJB |
6538 | b->ops->print_one_detail (b, uiout); |
6539 | ||
0d381245 | 6540 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6541 | { |
6542 | annotate_field (6); | |
8b93c638 | 6543 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6544 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6545 | the frame ID. */ |
5af949e3 UW |
6546 | ui_out_field_core_addr (uiout, "frame", |
6547 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6548 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6549 | } |
6550 | ||
28010a5d | 6551 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6552 | { |
6553 | annotate_field (7); | |
d77f58be | 6554 | if (is_tracepoint (b)) |
1042e4c0 SS |
6555 | ui_out_text (uiout, "\ttrace only if "); |
6556 | else | |
6557 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6558 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6559 | |
6560 | /* Print whether the target is doing the breakpoint's condition | |
6561 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6562 | if (is_breakpoint (b) | |
6563 | && breakpoint_condition_evaluation_mode () | |
6564 | == condition_evaluation_target) | |
6565 | { | |
6566 | ui_out_text (uiout, " ("); | |
6567 | ui_out_field_string (uiout, "evaluated-by", | |
6568 | bp_condition_evaluator (b)); | |
6569 | ui_out_text (uiout, " evals)"); | |
6570 | } | |
0101ce28 JJ |
6571 | ui_out_text (uiout, "\n"); |
6572 | } | |
6573 | ||
0d381245 | 6574 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6575 | { |
4a64f543 | 6576 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6577 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6578 | if (ui_out_is_mi_like_p (uiout)) |
6579 | ui_out_field_int (uiout, "thread", b->thread); | |
6580 | else | |
6581 | { | |
6582 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6583 | ||
6584 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6585 | } | |
8b93c638 | 6586 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6587 | } |
6588 | ||
556ec64d YQ |
6589 | if (!part_of_multiple) |
6590 | { | |
6591 | if (b->hit_count) | |
31f56a27 YQ |
6592 | { |
6593 | /* FIXME should make an annotation for this. */ | |
6594 | if (is_catchpoint (b)) | |
6595 | ui_out_text (uiout, "\tcatchpoint"); | |
6596 | else if (is_tracepoint (b)) | |
6597 | ui_out_text (uiout, "\ttracepoint"); | |
6598 | else | |
6599 | ui_out_text (uiout, "\tbreakpoint"); | |
6600 | ui_out_text (uiout, " already hit "); | |
6601 | ui_out_field_int (uiout, "times", b->hit_count); | |
6602 | if (b->hit_count == 1) | |
6603 | ui_out_text (uiout, " time\n"); | |
6604 | else | |
6605 | ui_out_text (uiout, " times\n"); | |
6606 | } | |
556ec64d YQ |
6607 | else |
6608 | { | |
31f56a27 YQ |
6609 | /* Output the count also if it is zero, but only if this is mi. */ |
6610 | if (ui_out_is_mi_like_p (uiout)) | |
6611 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6612 | } |
6613 | } | |
8b93c638 | 6614 | |
0d381245 | 6615 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6616 | { |
6617 | annotate_field (8); | |
8b93c638 JM |
6618 | ui_out_text (uiout, "\tignore next "); |
6619 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6620 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6621 | } |
059fb39f | 6622 | |
816338b5 SS |
6623 | /* Note that an enable count of 1 corresponds to "enable once" |
6624 | behavior, which is reported by the combination of enablement and | |
6625 | disposition, so we don't need to mention it here. */ | |
6626 | if (!part_of_multiple && b->enable_count > 1) | |
6627 | { | |
6628 | annotate_field (8); | |
6629 | ui_out_text (uiout, "\tdisable after "); | |
6630 | /* Tweak the wording to clarify that ignore and enable counts | |
6631 | are distinct, and have additive effect. */ | |
6632 | if (b->ignore_count) | |
6633 | ui_out_text (uiout, "additional "); | |
6634 | else | |
6635 | ui_out_text (uiout, "next "); | |
6636 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6637 | ui_out_text (uiout, " hits\n"); | |
6638 | } | |
6639 | ||
f196051f SS |
6640 | if (!part_of_multiple && is_tracepoint (b)) |
6641 | { | |
6642 | struct tracepoint *tp = (struct tracepoint *) b; | |
6643 | ||
6644 | if (tp->traceframe_usage) | |
6645 | { | |
6646 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6647 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6648 | ui_out_text (uiout, " bytes\n"); | |
6649 | } | |
6650 | } | |
d3ce09f5 | 6651 | |
9add0f1b | 6652 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6653 | if (!part_of_multiple && l) |
c4093a6a | 6654 | { |
3b31d625 EZ |
6655 | struct cleanup *script_chain; |
6656 | ||
c4093a6a | 6657 | annotate_field (9); |
3b31d625 | 6658 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6659 | print_command_lines (uiout, l, 4); |
3b31d625 | 6660 | do_cleanups (script_chain); |
c4093a6a | 6661 | } |
d24317b4 | 6662 | |
d9b3f62e | 6663 | if (is_tracepoint (b)) |
1042e4c0 | 6664 | { |
d9b3f62e PA |
6665 | struct tracepoint *t = (struct tracepoint *) b; |
6666 | ||
6667 | if (!part_of_multiple && t->pass_count) | |
6668 | { | |
6669 | annotate_field (10); | |
6670 | ui_out_text (uiout, "\tpass count "); | |
6671 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6672 | ui_out_text (uiout, " \n"); | |
6673 | } | |
f2a8bc8a YQ |
6674 | |
6675 | /* Don't display it when tracepoint or tracepoint location is | |
6676 | pending. */ | |
6677 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6678 | { | |
6679 | annotate_field (11); | |
6680 | ||
6681 | if (ui_out_is_mi_like_p (uiout)) | |
6682 | ui_out_field_string (uiout, "installed", | |
6683 | loc->inserted ? "y" : "n"); | |
6684 | else | |
6685 | { | |
6686 | if (loc->inserted) | |
6687 | ui_out_text (uiout, "\t"); | |
6688 | else | |
6689 | ui_out_text (uiout, "\tnot "); | |
6690 | ui_out_text (uiout, "installed on target\n"); | |
6691 | } | |
6692 | } | |
1042e4c0 SS |
6693 | } |
6694 | ||
d24317b4 VP |
6695 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6696 | { | |
3a5c3e22 PA |
6697 | if (is_watchpoint (b)) |
6698 | { | |
6699 | struct watchpoint *w = (struct watchpoint *) b; | |
6700 | ||
6701 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6702 | } | |
f00aae0f KS |
6703 | else if (b->location != NULL |
6704 | && event_location_to_string (b->location) != NULL) | |
6705 | ui_out_field_string (uiout, "original-location", | |
6706 | event_location_to_string (b->location)); | |
d24317b4 | 6707 | } |
c4093a6a | 6708 | } |
c5aa993b | 6709 | |
0d381245 VP |
6710 | static void |
6711 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6712 | struct bp_location **last_loc, |
6c95b8df | 6713 | int allflag) |
0d381245 | 6714 | { |
8d3788bd | 6715 | struct cleanup *bkpt_chain; |
79a45e25 | 6716 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6717 | |
6718 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6719 | ||
12c5a436 | 6720 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6721 | do_cleanups (bkpt_chain); |
0d381245 VP |
6722 | |
6723 | /* If this breakpoint has custom print function, | |
6724 | it's already printed. Otherwise, print individual | |
6725 | locations, if any. */ | |
6726 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6727 | { | |
4a64f543 MS |
6728 | /* If breakpoint has a single location that is disabled, we |
6729 | print it as if it had several locations, since otherwise it's | |
6730 | hard to represent "breakpoint enabled, location disabled" | |
6731 | situation. | |
6732 | ||
6733 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6734 | internally, that's not a property exposed to user. */ |
0d381245 | 6735 | if (b->loc |
a5606eee | 6736 | && !is_hardware_watchpoint (b) |
8d3788bd | 6737 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6738 | { |
6739 | struct bp_location *loc; | |
6740 | int n = 1; | |
8d3788bd | 6741 | |
0d381245 | 6742 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6743 | { |
6744 | struct cleanup *inner2 = | |
6745 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6746 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6747 | do_cleanups (inner2); | |
6748 | } | |
0d381245 VP |
6749 | } |
6750 | } | |
6751 | } | |
6752 | ||
a6d9a66e UW |
6753 | static int |
6754 | breakpoint_address_bits (struct breakpoint *b) | |
6755 | { | |
6756 | int print_address_bits = 0; | |
6757 | struct bp_location *loc; | |
6758 | ||
c6d81124 PA |
6759 | /* Software watchpoints that aren't watching memory don't have an |
6760 | address to print. */ | |
6761 | if (is_no_memory_software_watchpoint (b)) | |
6762 | return 0; | |
6763 | ||
a6d9a66e UW |
6764 | for (loc = b->loc; loc; loc = loc->next) |
6765 | { | |
c7437ca6 PA |
6766 | int addr_bit; |
6767 | ||
c7437ca6 | 6768 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6769 | if (addr_bit > print_address_bits) |
6770 | print_address_bits = addr_bit; | |
6771 | } | |
6772 | ||
6773 | return print_address_bits; | |
6774 | } | |
0d381245 | 6775 | |
c4093a6a JM |
6776 | struct captured_breakpoint_query_args |
6777 | { | |
6778 | int bnum; | |
6779 | }; | |
c5aa993b | 6780 | |
c4093a6a | 6781 | static int |
2b65245e | 6782 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6783 | { |
9a3c8263 SM |
6784 | struct captured_breakpoint_query_args *args |
6785 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6786 | struct breakpoint *b; |
a6d9a66e | 6787 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6788 | |
c4093a6a JM |
6789 | ALL_BREAKPOINTS (b) |
6790 | { | |
6791 | if (args->bnum == b->number) | |
c5aa993b | 6792 | { |
12c5a436 | 6793 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6794 | return GDB_RC_OK; |
c5aa993b | 6795 | } |
c4093a6a JM |
6796 | } |
6797 | return GDB_RC_NONE; | |
6798 | } | |
c5aa993b | 6799 | |
c4093a6a | 6800 | enum gdb_rc |
4a64f543 MS |
6801 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6802 | char **error_message) | |
c4093a6a JM |
6803 | { |
6804 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6805 | |
c4093a6a JM |
6806 | args.bnum = bnum; |
6807 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6808 | an error. */ |
b0b13bb4 DJ |
6809 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6810 | error_message, RETURN_MASK_ALL) < 0) | |
6811 | return GDB_RC_FAIL; | |
6812 | else | |
6813 | return GDB_RC_OK; | |
c4093a6a | 6814 | } |
c5aa993b | 6815 | |
09d682a4 TT |
6816 | /* Return true if this breakpoint was set by the user, false if it is |
6817 | internal or momentary. */ | |
6818 | ||
6819 | int | |
6820 | user_breakpoint_p (struct breakpoint *b) | |
6821 | { | |
46c6471b | 6822 | return b->number > 0; |
09d682a4 TT |
6823 | } |
6824 | ||
93daf339 TT |
6825 | /* See breakpoint.h. */ |
6826 | ||
6827 | int | |
6828 | pending_breakpoint_p (struct breakpoint *b) | |
6829 | { | |
6830 | return b->loc == NULL; | |
6831 | } | |
6832 | ||
7f3b0473 | 6833 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6834 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6835 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6836 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6837 | ones for which it returns non-zero. Return the total number of | |
6838 | breakpoints listed. */ | |
c906108c | 6839 | |
d77f58be | 6840 | static int |
e5a67952 | 6841 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6842 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6843 | { |
52f0bd74 | 6844 | struct breakpoint *b; |
a6d9a66e | 6845 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6846 | int nr_printable_breakpoints; |
3b31d625 | 6847 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6848 | struct value_print_options opts; |
a6d9a66e | 6849 | int print_address_bits = 0; |
269b11a2 | 6850 | int print_type_col_width = 14; |
79a45e25 | 6851 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6852 | |
79a45b7d TT |
6853 | get_user_print_options (&opts); |
6854 | ||
4a64f543 MS |
6855 | /* Compute the number of rows in the table, as well as the size |
6856 | required for address fields. */ | |
7f3b0473 AC |
6857 | nr_printable_breakpoints = 0; |
6858 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6859 | { |
6860 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6861 | if (filter && !filter (b)) | |
6862 | continue; | |
6863 | ||
6864 | /* If we have an "args" string, it is a list of breakpoints to | |
6865 | accept. Skip the others. */ | |
6866 | if (args != NULL && *args != '\0') | |
6867 | { | |
6868 | if (allflag && parse_and_eval_long (args) != b->number) | |
6869 | continue; | |
6870 | if (!allflag && !number_is_in_list (args, b->number)) | |
6871 | continue; | |
6872 | } | |
269b11a2 | 6873 | |
e5a67952 MS |
6874 | if (allflag || user_breakpoint_p (b)) |
6875 | { | |
6876 | int addr_bit, type_len; | |
a6d9a66e | 6877 | |
e5a67952 MS |
6878 | addr_bit = breakpoint_address_bits (b); |
6879 | if (addr_bit > print_address_bits) | |
6880 | print_address_bits = addr_bit; | |
269b11a2 | 6881 | |
e5a67952 MS |
6882 | type_len = strlen (bptype_string (b->type)); |
6883 | if (type_len > print_type_col_width) | |
6884 | print_type_col_width = type_len; | |
6885 | ||
6886 | nr_printable_breakpoints++; | |
6887 | } | |
6888 | } | |
7f3b0473 | 6889 | |
79a45b7d | 6890 | if (opts.addressprint) |
3b31d625 | 6891 | bkpttbl_chain |
3e43a32a MS |
6892 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6893 | nr_printable_breakpoints, | |
3b31d625 | 6894 | "BreakpointTable"); |
8b93c638 | 6895 | else |
3b31d625 | 6896 | bkpttbl_chain |
3e43a32a MS |
6897 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6898 | nr_printable_breakpoints, | |
3b31d625 | 6899 | "BreakpointTable"); |
8b93c638 | 6900 | |
7f3b0473 | 6901 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6902 | annotate_breakpoints_headers (); |
6903 | if (nr_printable_breakpoints > 0) | |
6904 | annotate_field (0); | |
4a64f543 | 6905 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6906 | if (nr_printable_breakpoints > 0) |
6907 | annotate_field (1); | |
269b11a2 | 6908 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6909 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6910 | if (nr_printable_breakpoints > 0) |
6911 | annotate_field (2); | |
4a64f543 | 6912 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6913 | if (nr_printable_breakpoints > 0) |
6914 | annotate_field (3); | |
54e52265 | 6915 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6916 | if (opts.addressprint) |
e5a67952 MS |
6917 | { |
6918 | if (nr_printable_breakpoints > 0) | |
6919 | annotate_field (4); | |
6920 | if (print_address_bits <= 32) | |
6921 | ui_out_table_header (uiout, 10, ui_left, | |
6922 | "addr", "Address"); /* 5 */ | |
6923 | else | |
6924 | ui_out_table_header (uiout, 18, ui_left, | |
6925 | "addr", "Address"); /* 5 */ | |
6926 | } | |
d7faa9e7 AC |
6927 | if (nr_printable_breakpoints > 0) |
6928 | annotate_field (5); | |
6929 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6930 | ui_out_table_body (uiout); | |
6931 | if (nr_printable_breakpoints > 0) | |
6932 | annotate_breakpoints_table (); | |
7f3b0473 | 6933 | |
c4093a6a | 6934 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6935 | { |
6936 | QUIT; | |
6937 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6938 | if (filter && !filter (b)) | |
6939 | continue; | |
6940 | ||
6941 | /* If we have an "args" string, it is a list of breakpoints to | |
6942 | accept. Skip the others. */ | |
6943 | ||
6944 | if (args != NULL && *args != '\0') | |
6945 | { | |
6946 | if (allflag) /* maintenance info breakpoint */ | |
6947 | { | |
6948 | if (parse_and_eval_long (args) != b->number) | |
6949 | continue; | |
6950 | } | |
6951 | else /* all others */ | |
6952 | { | |
6953 | if (!number_is_in_list (args, b->number)) | |
6954 | continue; | |
6955 | } | |
6956 | } | |
6957 | /* We only print out user settable breakpoints unless the | |
6958 | allflag is set. */ | |
6959 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6960 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6961 | } |
6962 | ||
3b31d625 | 6963 | do_cleanups (bkpttbl_chain); |
698384cd | 6964 | |
7f3b0473 | 6965 | if (nr_printable_breakpoints == 0) |
c906108c | 6966 | { |
4a64f543 MS |
6967 | /* If there's a filter, let the caller decide how to report |
6968 | empty list. */ | |
d77f58be SS |
6969 | if (!filter) |
6970 | { | |
e5a67952 | 6971 | if (args == NULL || *args == '\0') |
d77f58be SS |
6972 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6973 | else | |
4a64f543 | 6974 | ui_out_message (uiout, 0, |
e5a67952 MS |
6975 | "No breakpoint or watchpoint matching '%s'.\n", |
6976 | args); | |
d77f58be | 6977 | } |
c906108c SS |
6978 | } |
6979 | else | |
c4093a6a | 6980 | { |
a6d9a66e UW |
6981 | if (last_loc && !server_command) |
6982 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6983 | } |
c906108c | 6984 | |
4a64f543 | 6985 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6986 | there have been breakpoints? */ |
c906108c | 6987 | annotate_breakpoints_table_end (); |
d77f58be SS |
6988 | |
6989 | return nr_printable_breakpoints; | |
c906108c SS |
6990 | } |
6991 | ||
ad443146 SS |
6992 | /* Display the value of default-collect in a way that is generally |
6993 | compatible with the breakpoint list. */ | |
6994 | ||
6995 | static void | |
6996 | default_collect_info (void) | |
6997 | { | |
79a45e25 PA |
6998 | struct ui_out *uiout = current_uiout; |
6999 | ||
ad443146 SS |
7000 | /* If it has no value (which is frequently the case), say nothing; a |
7001 | message like "No default-collect." gets in user's face when it's | |
7002 | not wanted. */ | |
7003 | if (!*default_collect) | |
7004 | return; | |
7005 | ||
7006 | /* The following phrase lines up nicely with per-tracepoint collect | |
7007 | actions. */ | |
7008 | ui_out_text (uiout, "default collect "); | |
7009 | ui_out_field_string (uiout, "default-collect", default_collect); | |
7010 | ui_out_text (uiout, " \n"); | |
7011 | } | |
7012 | ||
c906108c | 7013 | static void |
e5a67952 | 7014 | breakpoints_info (char *args, int from_tty) |
c906108c | 7015 | { |
e5a67952 | 7016 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
7017 | |
7018 | default_collect_info (); | |
d77f58be SS |
7019 | } |
7020 | ||
7021 | static void | |
e5a67952 | 7022 | watchpoints_info (char *args, int from_tty) |
d77f58be | 7023 | { |
e5a67952 | 7024 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 7025 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
7026 | |
7027 | if (num_printed == 0) | |
7028 | { | |
e5a67952 | 7029 | if (args == NULL || *args == '\0') |
d77f58be SS |
7030 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
7031 | else | |
e5a67952 | 7032 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 7033 | } |
c906108c SS |
7034 | } |
7035 | ||
7a292a7a | 7036 | static void |
e5a67952 | 7037 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 7038 | { |
e5a67952 | 7039 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
7040 | |
7041 | default_collect_info (); | |
c906108c SS |
7042 | } |
7043 | ||
0d381245 | 7044 | static int |
714835d5 | 7045 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7046 | struct program_space *pspace, |
714835d5 | 7047 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7048 | { |
7049 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7050 | |
0d381245 VP |
7051 | for (; bl; bl = bl->next) |
7052 | { | |
6c95b8df PA |
7053 | if (bl->pspace == pspace |
7054 | && bl->address == pc | |
0d381245 VP |
7055 | && (!overlay_debugging || bl->section == section)) |
7056 | return 1; | |
7057 | } | |
7058 | return 0; | |
7059 | } | |
7060 | ||
672f9b60 | 7061 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7062 | concerns with logical breakpoints, so we match program spaces, not |
7063 | address spaces. */ | |
c906108c SS |
7064 | |
7065 | static void | |
6c95b8df PA |
7066 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7067 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7068 | struct obj_section *section, int thread) |
c906108c | 7069 | { |
52f0bd74 AC |
7070 | int others = 0; |
7071 | struct breakpoint *b; | |
c906108c SS |
7072 | |
7073 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7074 | others += (user_breakpoint_p (b) |
7075 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7076 | if (others > 0) |
7077 | { | |
a3f17187 AC |
7078 | if (others == 1) |
7079 | printf_filtered (_("Note: breakpoint ")); | |
7080 | else /* if (others == ???) */ | |
7081 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7082 | ALL_BREAKPOINTS (b) |
672f9b60 | 7083 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7084 | { |
7085 | others--; | |
7086 | printf_filtered ("%d", b->number); | |
7087 | if (b->thread == -1 && thread != -1) | |
7088 | printf_filtered (" (all threads)"); | |
7089 | else if (b->thread != -1) | |
7090 | printf_filtered (" (thread %d)", b->thread); | |
7091 | printf_filtered ("%s%s ", | |
059fb39f | 7092 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7093 | || b->enable_state == bp_call_disabled) |
0d381245 | 7094 | ? " (disabled)" |
0d381245 VP |
7095 | : ""), |
7096 | (others > 1) ? "," | |
7097 | : ((others == 1) ? " and" : "")); | |
7098 | } | |
a3f17187 | 7099 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7100 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7101 | printf_filtered (".\n"); |
7102 | } | |
7103 | } | |
7104 | \f | |
c906108c | 7105 | |
e4f237da | 7106 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7107 | BPT locations. For some breakpoint types, the locations' address members |
7108 | are irrelevant and it makes no sense to attempt to compare them to other | |
7109 | addresses (or use them for any other purpose either). | |
e4f237da | 7110 | |
4a64f543 | 7111 | More specifically, each of the following breakpoint types will |
244558af | 7112 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7113 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7114 | breakpoint location at address zero: |
e4f237da KB |
7115 | |
7116 | bp_watchpoint | |
2d134ed3 PA |
7117 | bp_catchpoint |
7118 | ||
7119 | */ | |
e4f237da KB |
7120 | |
7121 | static int | |
7122 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7123 | { | |
7124 | enum bptype type = bpt->type; | |
7125 | ||
2d134ed3 PA |
7126 | return (type != bp_watchpoint && type != bp_catchpoint); |
7127 | } | |
7128 | ||
7129 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7130 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7131 | ||
7132 | static int | |
4a64f543 MS |
7133 | watchpoint_locations_match (struct bp_location *loc1, |
7134 | struct bp_location *loc2) | |
2d134ed3 | 7135 | { |
3a5c3e22 PA |
7136 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7137 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7138 | ||
7139 | /* Both of them must exist. */ | |
7140 | gdb_assert (w1 != NULL); | |
7141 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7142 | |
4a64f543 MS |
7143 | /* If the target can evaluate the condition expression in hardware, |
7144 | then we we need to insert both watchpoints even if they are at | |
7145 | the same place. Otherwise the watchpoint will only trigger when | |
7146 | the condition of whichever watchpoint was inserted evaluates to | |
7147 | true, not giving a chance for GDB to check the condition of the | |
7148 | other watchpoint. */ | |
3a5c3e22 | 7149 | if ((w1->cond_exp |
4a64f543 MS |
7150 | && target_can_accel_watchpoint_condition (loc1->address, |
7151 | loc1->length, | |
0cf6dd15 | 7152 | loc1->watchpoint_type, |
3a5c3e22 PA |
7153 | w1->cond_exp)) |
7154 | || (w2->cond_exp | |
4a64f543 MS |
7155 | && target_can_accel_watchpoint_condition (loc2->address, |
7156 | loc2->length, | |
0cf6dd15 | 7157 | loc2->watchpoint_type, |
3a5c3e22 | 7158 | w2->cond_exp))) |
0cf6dd15 TJB |
7159 | return 0; |
7160 | ||
85d721b8 PA |
7161 | /* Note that this checks the owner's type, not the location's. In |
7162 | case the target does not support read watchpoints, but does | |
7163 | support access watchpoints, we'll have bp_read_watchpoint | |
7164 | watchpoints with hw_access locations. Those should be considered | |
7165 | duplicates of hw_read locations. The hw_read locations will | |
7166 | become hw_access locations later. */ | |
2d134ed3 PA |
7167 | return (loc1->owner->type == loc2->owner->type |
7168 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7169 | && loc1->address == loc2->address | |
7170 | && loc1->length == loc2->length); | |
e4f237da KB |
7171 | } |
7172 | ||
31e77af2 | 7173 | /* See breakpoint.h. */ |
6c95b8df | 7174 | |
31e77af2 | 7175 | int |
6c95b8df PA |
7176 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7177 | struct address_space *aspace2, CORE_ADDR addr2) | |
7178 | { | |
f5656ead | 7179 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7180 | || aspace1 == aspace2) |
7181 | && addr1 == addr2); | |
7182 | } | |
7183 | ||
f1310107 TJB |
7184 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7185 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7186 | matches ASPACE2. On targets that have global breakpoints, the address | |
7187 | space doesn't really matter. */ | |
7188 | ||
7189 | static int | |
7190 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7191 | int len1, struct address_space *aspace2, | |
7192 | CORE_ADDR addr2) | |
7193 | { | |
f5656ead | 7194 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7195 | || aspace1 == aspace2) |
7196 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7197 | } | |
7198 | ||
7199 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7200 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7201 | matches the breakpoint's address space. On targets that have global | |
7202 | breakpoints, the address space doesn't really matter. */ | |
7203 | ||
7204 | static int | |
7205 | breakpoint_location_address_match (struct bp_location *bl, | |
7206 | struct address_space *aspace, | |
7207 | CORE_ADDR addr) | |
7208 | { | |
7209 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7210 | aspace, addr) | |
7211 | || (bl->length | |
7212 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7213 | bl->address, bl->length, | |
7214 | aspace, addr))); | |
7215 | } | |
7216 | ||
d35ae833 PA |
7217 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7218 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7219 | match happens only if ASPACE matches the breakpoint's address | |
7220 | space. On targets that have global breakpoints, the address space | |
7221 | doesn't really matter. */ | |
7222 | ||
7223 | static int | |
7224 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7225 | struct address_space *aspace, | |
7226 | CORE_ADDR addr, int len) | |
7227 | { | |
7228 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7229 | || bl->pspace->aspace == aspace) | |
7230 | { | |
7231 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7232 | ||
7233 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7234 | return 1; | |
7235 | } | |
7236 | return 0; | |
7237 | } | |
7238 | ||
1e4d1764 YQ |
7239 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7240 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7241 | true, otherwise returns false. */ | |
7242 | ||
7243 | static int | |
7244 | tracepoint_locations_match (struct bp_location *loc1, | |
7245 | struct bp_location *loc2) | |
7246 | { | |
7247 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7248 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7249 | locations at the same address of different tracepoints are regarded as | |
7250 | different locations. */ | |
7251 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7252 | else | |
7253 | return 0; | |
7254 | } | |
7255 | ||
2d134ed3 PA |
7256 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7257 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7258 | represent the same location. */ | |
7259 | ||
7260 | static int | |
4a64f543 MS |
7261 | breakpoint_locations_match (struct bp_location *loc1, |
7262 | struct bp_location *loc2) | |
2d134ed3 | 7263 | { |
2bdf28a0 JK |
7264 | int hw_point1, hw_point2; |
7265 | ||
7266 | /* Both of them must not be in moribund_locations. */ | |
7267 | gdb_assert (loc1->owner != NULL); | |
7268 | gdb_assert (loc2->owner != NULL); | |
7269 | ||
7270 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7271 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7272 | |
7273 | if (hw_point1 != hw_point2) | |
7274 | return 0; | |
7275 | else if (hw_point1) | |
7276 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7277 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7278 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7279 | else |
f1310107 TJB |
7280 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7281 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7282 | loc2->pspace->aspace, loc2->address) | |
7283 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7284 | } |
7285 | ||
76897487 KB |
7286 | static void |
7287 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7288 | int bnum, int have_bnum) | |
7289 | { | |
f63fbe86 MS |
7290 | /* The longest string possibly returned by hex_string_custom |
7291 | is 50 chars. These must be at least that big for safety. */ | |
7292 | char astr1[64]; | |
7293 | char astr2[64]; | |
76897487 | 7294 | |
bb599908 PH |
7295 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7296 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7297 | if (have_bnum) |
8a3fe4f8 | 7298 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7299 | bnum, astr1, astr2); |
7300 | else | |
8a3fe4f8 | 7301 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7302 | } |
7303 | ||
4a64f543 MS |
7304 | /* Adjust a breakpoint's address to account for architectural |
7305 | constraints on breakpoint placement. Return the adjusted address. | |
7306 | Note: Very few targets require this kind of adjustment. For most | |
7307 | targets, this function is simply the identity function. */ | |
76897487 KB |
7308 | |
7309 | static CORE_ADDR | |
a6d9a66e UW |
7310 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7311 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7312 | { |
a6d9a66e | 7313 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7314 | { |
7315 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7316 | return bpaddr; | |
7317 | } | |
88f7da05 KB |
7318 | else if (bptype == bp_watchpoint |
7319 | || bptype == bp_hardware_watchpoint | |
7320 | || bptype == bp_read_watchpoint | |
7321 | || bptype == bp_access_watchpoint | |
fe798b75 | 7322 | || bptype == bp_catchpoint) |
88f7da05 KB |
7323 | { |
7324 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7325 | have their addresses modified. */ | |
7326 | return bpaddr; | |
7327 | } | |
7c16b83e PA |
7328 | else if (bptype == bp_single_step) |
7329 | { | |
7330 | /* Single-step breakpoints should not have their addresses | |
7331 | modified. If there's any architectural constrain that | |
7332 | applies to this address, then it should have already been | |
7333 | taken into account when the breakpoint was created in the | |
7334 | first place. If we didn't do this, stepping through e.g., | |
7335 | Thumb-2 IT blocks would break. */ | |
7336 | return bpaddr; | |
7337 | } | |
76897487 KB |
7338 | else |
7339 | { | |
7340 | CORE_ADDR adjusted_bpaddr; | |
7341 | ||
7342 | /* Some targets have architectural constraints on the placement | |
7343 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7344 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7345 | |
7346 | /* An adjusted breakpoint address can significantly alter | |
7347 | a user's expectations. Print a warning if an adjustment | |
7348 | is required. */ | |
7349 | if (adjusted_bpaddr != bpaddr) | |
7350 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7351 | ||
7352 | return adjusted_bpaddr; | |
7353 | } | |
7354 | } | |
7355 | ||
28010a5d PA |
7356 | void |
7357 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7358 | struct breakpoint *owner) | |
7cc221ef | 7359 | { |
7cc221ef DJ |
7360 | memset (loc, 0, sizeof (*loc)); |
7361 | ||
348d480f PA |
7362 | gdb_assert (ops != NULL); |
7363 | ||
28010a5d PA |
7364 | loc->ops = ops; |
7365 | loc->owner = owner; | |
511a6cd4 | 7366 | loc->cond = NULL; |
b775012e | 7367 | loc->cond_bytecode = NULL; |
0d381245 VP |
7368 | loc->shlib_disabled = 0; |
7369 | loc->enabled = 1; | |
e049a4b5 | 7370 | |
28010a5d | 7371 | switch (owner->type) |
e049a4b5 DJ |
7372 | { |
7373 | case bp_breakpoint: | |
7c16b83e | 7374 | case bp_single_step: |
e049a4b5 DJ |
7375 | case bp_until: |
7376 | case bp_finish: | |
7377 | case bp_longjmp: | |
7378 | case bp_longjmp_resume: | |
e2e4d78b | 7379 | case bp_longjmp_call_dummy: |
186c406b TT |
7380 | case bp_exception: |
7381 | case bp_exception_resume: | |
e049a4b5 | 7382 | case bp_step_resume: |
2c03e5be | 7383 | case bp_hp_step_resume: |
e049a4b5 DJ |
7384 | case bp_watchpoint_scope: |
7385 | case bp_call_dummy: | |
aa7d318d | 7386 | case bp_std_terminate: |
e049a4b5 DJ |
7387 | case bp_shlib_event: |
7388 | case bp_thread_event: | |
7389 | case bp_overlay_event: | |
4efc6507 | 7390 | case bp_jit_event: |
0fd8e87f | 7391 | case bp_longjmp_master: |
aa7d318d | 7392 | case bp_std_terminate_master: |
186c406b | 7393 | case bp_exception_master: |
0e30163f JK |
7394 | case bp_gnu_ifunc_resolver: |
7395 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7396 | case bp_dprintf: |
e049a4b5 | 7397 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7398 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7399 | break; |
7400 | case bp_hardware_breakpoint: | |
7401 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7402 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7403 | break; |
7404 | case bp_hardware_watchpoint: | |
7405 | case bp_read_watchpoint: | |
7406 | case bp_access_watchpoint: | |
7407 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7408 | break; | |
7409 | case bp_watchpoint: | |
ce78b96d | 7410 | case bp_catchpoint: |
15c3d785 PA |
7411 | case bp_tracepoint: |
7412 | case bp_fast_tracepoint: | |
0fb4aa4b | 7413 | case bp_static_tracepoint: |
e049a4b5 DJ |
7414 | loc->loc_type = bp_loc_other; |
7415 | break; | |
7416 | default: | |
e2e0b3e5 | 7417 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7418 | } |
7419 | ||
f431efe5 | 7420 | loc->refc = 1; |
28010a5d PA |
7421 | } |
7422 | ||
7423 | /* Allocate a struct bp_location. */ | |
7424 | ||
7425 | static struct bp_location * | |
7426 | allocate_bp_location (struct breakpoint *bpt) | |
7427 | { | |
348d480f PA |
7428 | return bpt->ops->allocate_location (bpt); |
7429 | } | |
7cc221ef | 7430 | |
f431efe5 PA |
7431 | static void |
7432 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7433 | { |
348d480f | 7434 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7435 | xfree (loc); |
7436 | } | |
7437 | ||
f431efe5 PA |
7438 | /* Increment reference count. */ |
7439 | ||
7440 | static void | |
7441 | incref_bp_location (struct bp_location *bl) | |
7442 | { | |
7443 | ++bl->refc; | |
7444 | } | |
7445 | ||
7446 | /* Decrement reference count. If the reference count reaches 0, | |
7447 | destroy the bp_location. Sets *BLP to NULL. */ | |
7448 | ||
7449 | static void | |
7450 | decref_bp_location (struct bp_location **blp) | |
7451 | { | |
0807b50c PA |
7452 | gdb_assert ((*blp)->refc > 0); |
7453 | ||
f431efe5 PA |
7454 | if (--(*blp)->refc == 0) |
7455 | free_bp_location (*blp); | |
7456 | *blp = NULL; | |
7457 | } | |
7458 | ||
346774a9 | 7459 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7460 | |
346774a9 PA |
7461 | static void |
7462 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7463 | { |
346774a9 | 7464 | struct breakpoint *b1; |
c906108c | 7465 | |
346774a9 PA |
7466 | /* Add this breakpoint to the end of the chain so that a list of |
7467 | breakpoints will come out in order of increasing numbers. */ | |
7468 | ||
7469 | b1 = breakpoint_chain; | |
7470 | if (b1 == 0) | |
7471 | breakpoint_chain = b; | |
7472 | else | |
7473 | { | |
7474 | while (b1->next) | |
7475 | b1 = b1->next; | |
7476 | b1->next = b; | |
7477 | } | |
7478 | } | |
7479 | ||
7480 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7481 | ||
7482 | static void | |
7483 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7484 | struct gdbarch *gdbarch, | |
28010a5d | 7485 | enum bptype bptype, |
c0a91b2b | 7486 | const struct breakpoint_ops *ops) |
346774a9 | 7487 | { |
c906108c | 7488 | memset (b, 0, sizeof (*b)); |
2219d63c | 7489 | |
348d480f PA |
7490 | gdb_assert (ops != NULL); |
7491 | ||
28010a5d | 7492 | b->ops = ops; |
4d28f7a8 | 7493 | b->type = bptype; |
a6d9a66e | 7494 | b->gdbarch = gdbarch; |
c906108c SS |
7495 | b->language = current_language->la_language; |
7496 | b->input_radix = input_radix; | |
7497 | b->thread = -1; | |
b5de0fa7 | 7498 | b->enable_state = bp_enabled; |
c906108c SS |
7499 | b->next = 0; |
7500 | b->silent = 0; | |
7501 | b->ignore_count = 0; | |
7502 | b->commands = NULL; | |
818dd999 | 7503 | b->frame_id = null_frame_id; |
0d381245 | 7504 | b->condition_not_parsed = 0; |
84f4c1fe | 7505 | b->py_bp_object = NULL; |
d0fb5eae | 7506 | b->related_breakpoint = b; |
f00aae0f | 7507 | b->location = NULL; |
346774a9 PA |
7508 | } |
7509 | ||
7510 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7511 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7512 | |
7513 | static struct breakpoint * | |
7514 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7515 | enum bptype bptype, |
c0a91b2b | 7516 | const struct breakpoint_ops *ops) |
346774a9 PA |
7517 | { |
7518 | struct breakpoint *b = XNEW (struct breakpoint); | |
7519 | ||
348d480f | 7520 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7521 | add_to_breakpoint_chain (b); |
0d381245 VP |
7522 | return b; |
7523 | } | |
7524 | ||
0e30163f JK |
7525 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7526 | resolutions should be made as the user specified the location explicitly | |
7527 | enough. */ | |
7528 | ||
0d381245 | 7529 | static void |
0e30163f | 7530 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7531 | { |
2bdf28a0 JK |
7532 | gdb_assert (loc->owner != NULL); |
7533 | ||
0d381245 | 7534 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7535 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7536 | || is_tracepoint (loc->owner)) |
0d381245 | 7537 | { |
0e30163f | 7538 | int is_gnu_ifunc; |
2c02bd72 | 7539 | const char *function_name; |
6a3a010b | 7540 | CORE_ADDR func_addr; |
0e30163f | 7541 | |
2c02bd72 | 7542 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7543 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7544 | |
7545 | if (is_gnu_ifunc && !explicit_loc) | |
7546 | { | |
7547 | struct breakpoint *b = loc->owner; | |
7548 | ||
7549 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7550 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7551 | &loc->requested_address)) |
7552 | { | |
7553 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7554 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7555 | loc->requested_address, | |
7556 | b->type); | |
7557 | } | |
7558 | else if (b->type == bp_breakpoint && b->loc == loc | |
7559 | && loc->next == NULL && b->related_breakpoint == b) | |
7560 | { | |
7561 | /* Create only the whole new breakpoint of this type but do not | |
7562 | mess more complicated breakpoints with multiple locations. */ | |
7563 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7564 | /* Remember the resolver's address for use by the return |
7565 | breakpoint. */ | |
7566 | loc->related_address = func_addr; | |
0e30163f JK |
7567 | } |
7568 | } | |
7569 | ||
2c02bd72 DE |
7570 | if (function_name) |
7571 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7572 | } |
7573 | } | |
7574 | ||
a6d9a66e | 7575 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7576 | struct gdbarch * |
a6d9a66e UW |
7577 | get_sal_arch (struct symtab_and_line sal) |
7578 | { | |
7579 | if (sal.section) | |
7580 | return get_objfile_arch (sal.section->objfile); | |
7581 | if (sal.symtab) | |
eb822aa6 | 7582 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7583 | |
7584 | return NULL; | |
7585 | } | |
7586 | ||
346774a9 PA |
7587 | /* Low level routine for partially initializing a breakpoint of type |
7588 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7589 | file name, and line number are provided by SAL. |
0d381245 VP |
7590 | |
7591 | It is expected that the caller will complete the initialization of | |
7592 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7593 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7594 | |
346774a9 PA |
7595 | static void |
7596 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7597 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7598 | const struct breakpoint_ops *ops) |
0d381245 | 7599 | { |
28010a5d | 7600 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7601 | |
3742cc8b | 7602 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7603 | |
6c95b8df PA |
7604 | if (bptype != bp_catchpoint) |
7605 | gdb_assert (sal.pspace != NULL); | |
7606 | ||
f8eba3c6 TT |
7607 | /* Store the program space that was used to set the breakpoint, |
7608 | except for ordinary breakpoints, which are independent of the | |
7609 | program space. */ | |
7610 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7611 | b->pspace = sal.pspace; | |
346774a9 | 7612 | } |
c906108c | 7613 | |
346774a9 PA |
7614 | /* set_raw_breakpoint is a low level routine for allocating and |
7615 | partially initializing a breakpoint of type BPTYPE. The newly | |
7616 | created breakpoint's address, section, source file name, and line | |
7617 | number are provided by SAL. The newly created and partially | |
7618 | initialized breakpoint is added to the breakpoint chain and | |
7619 | is also returned as the value of this function. | |
7620 | ||
7621 | It is expected that the caller will complete the initialization of | |
7622 | the newly created breakpoint struct as well as output any status | |
7623 | information regarding the creation of a new breakpoint. In | |
7624 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7625 | number! Care should be taken to not allow an error to occur | |
7626 | prior to completing the initialization of the breakpoint. If this | |
7627 | should happen, a bogus breakpoint will be left on the chain. */ | |
7628 | ||
7629 | struct breakpoint * | |
7630 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7631 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7632 | const struct breakpoint_ops *ops) |
346774a9 PA |
7633 | { |
7634 | struct breakpoint *b = XNEW (struct breakpoint); | |
7635 | ||
348d480f | 7636 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7637 | add_to_breakpoint_chain (b); |
c906108c SS |
7638 | return b; |
7639 | } | |
7640 | ||
53a5351d | 7641 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7642 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7643 | initiated the operation. */ | |
c906108c SS |
7644 | |
7645 | void | |
186c406b | 7646 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7647 | { |
35df4500 | 7648 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7649 | int thread = tp->global_num; |
0fd8e87f UW |
7650 | |
7651 | /* To avoid having to rescan all objfile symbols at every step, | |
7652 | we maintain a list of continually-inserted but always disabled | |
7653 | longjmp "master" breakpoints. Here, we simply create momentary | |
7654 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7655 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7656 | if (b->pspace == current_program_space |
186c406b TT |
7657 | && (b->type == bp_longjmp_master |
7658 | || b->type == bp_exception_master)) | |
0fd8e87f | 7659 | { |
06edf0c0 PA |
7660 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7661 | struct breakpoint *clone; | |
cc59ec59 | 7662 | |
e2e4d78b JK |
7663 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7664 | after their removal. */ | |
06edf0c0 | 7665 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7666 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7667 | clone->thread = thread; |
7668 | } | |
186c406b TT |
7669 | |
7670 | tp->initiating_frame = frame; | |
c906108c SS |
7671 | } |
7672 | ||
611c83ae | 7673 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7674 | void |
611c83ae | 7675 | delete_longjmp_breakpoint (int thread) |
c906108c | 7676 | { |
35df4500 | 7677 | struct breakpoint *b, *b_tmp; |
c906108c | 7678 | |
35df4500 | 7679 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7680 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7681 | { |
7682 | if (b->thread == thread) | |
7683 | delete_breakpoint (b); | |
7684 | } | |
c906108c SS |
7685 | } |
7686 | ||
f59f708a PA |
7687 | void |
7688 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7689 | { | |
7690 | struct breakpoint *b, *b_tmp; | |
7691 | ||
7692 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7693 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7694 | { | |
7695 | if (b->thread == thread) | |
7696 | b->disposition = disp_del_at_next_stop; | |
7697 | } | |
7698 | } | |
7699 | ||
e2e4d78b JK |
7700 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7701 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7702 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7703 | breakpoints. */ | |
7704 | ||
7705 | struct breakpoint * | |
7706 | set_longjmp_breakpoint_for_call_dummy (void) | |
7707 | { | |
7708 | struct breakpoint *b, *retval = NULL; | |
7709 | ||
7710 | ALL_BREAKPOINTS (b) | |
7711 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7712 | { | |
7713 | struct breakpoint *new_b; | |
7714 | ||
7715 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7716 | &momentary_breakpoint_ops, |
7717 | 1); | |
5d5658a1 | 7718 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7719 | |
7720 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7721 | ||
7722 | gdb_assert (new_b->related_breakpoint == new_b); | |
7723 | if (retval == NULL) | |
7724 | retval = new_b; | |
7725 | new_b->related_breakpoint = retval; | |
7726 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7727 | retval = retval->related_breakpoint; | |
7728 | retval->related_breakpoint = new_b; | |
7729 | } | |
7730 | ||
7731 | return retval; | |
7732 | } | |
7733 | ||
7734 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7735 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7736 | stack. |
7737 | ||
7738 | You should call this function only at places where it is safe to currently | |
7739 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7740 | frames. */ | |
7741 | ||
7742 | void | |
b67a2c6f | 7743 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7744 | { |
7745 | struct breakpoint *b, *b_tmp; | |
7746 | ||
7747 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7748 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7749 | { |
7750 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7751 | ||
7752 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7753 | dummy_b = dummy_b->related_breakpoint; | |
7754 | if (dummy_b->type != bp_call_dummy | |
7755 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7756 | continue; | |
7757 | ||
b67a2c6f | 7758 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7759 | |
7760 | while (b->related_breakpoint != b) | |
7761 | { | |
7762 | if (b_tmp == b->related_breakpoint) | |
7763 | b_tmp = b->related_breakpoint->next; | |
7764 | delete_breakpoint (b->related_breakpoint); | |
7765 | } | |
7766 | delete_breakpoint (b); | |
7767 | } | |
7768 | } | |
7769 | ||
1900040c MS |
7770 | void |
7771 | enable_overlay_breakpoints (void) | |
7772 | { | |
52f0bd74 | 7773 | struct breakpoint *b; |
1900040c MS |
7774 | |
7775 | ALL_BREAKPOINTS (b) | |
7776 | if (b->type == bp_overlay_event) | |
7777 | { | |
7778 | b->enable_state = bp_enabled; | |
44702360 | 7779 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7780 | overlay_events_enabled = 1; |
1900040c MS |
7781 | } |
7782 | } | |
7783 | ||
7784 | void | |
7785 | disable_overlay_breakpoints (void) | |
7786 | { | |
52f0bd74 | 7787 | struct breakpoint *b; |
1900040c MS |
7788 | |
7789 | ALL_BREAKPOINTS (b) | |
7790 | if (b->type == bp_overlay_event) | |
7791 | { | |
7792 | b->enable_state = bp_disabled; | |
44702360 | 7793 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7794 | overlay_events_enabled = 0; |
1900040c MS |
7795 | } |
7796 | } | |
7797 | ||
aa7d318d TT |
7798 | /* Set an active std::terminate breakpoint for each std::terminate |
7799 | master breakpoint. */ | |
7800 | void | |
7801 | set_std_terminate_breakpoint (void) | |
7802 | { | |
35df4500 | 7803 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7804 | |
35df4500 | 7805 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7806 | if (b->pspace == current_program_space |
7807 | && b->type == bp_std_terminate_master) | |
7808 | { | |
06edf0c0 | 7809 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7810 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7811 | } |
7812 | } | |
7813 | ||
7814 | /* Delete all the std::terminate breakpoints. */ | |
7815 | void | |
7816 | delete_std_terminate_breakpoint (void) | |
7817 | { | |
35df4500 | 7818 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7819 | |
35df4500 | 7820 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7821 | if (b->type == bp_std_terminate) |
7822 | delete_breakpoint (b); | |
7823 | } | |
7824 | ||
c4093a6a | 7825 | struct breakpoint * |
a6d9a66e | 7826 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7827 | { |
7828 | struct breakpoint *b; | |
c4093a6a | 7829 | |
06edf0c0 PA |
7830 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7831 | &internal_breakpoint_ops); | |
7832 | ||
b5de0fa7 | 7833 | b->enable_state = bp_enabled; |
f00aae0f | 7834 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7835 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7836 | |
44702360 | 7837 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7838 | |
c4093a6a JM |
7839 | return b; |
7840 | } | |
7841 | ||
0101ce28 JJ |
7842 | struct lang_and_radix |
7843 | { | |
7844 | enum language lang; | |
7845 | int radix; | |
7846 | }; | |
7847 | ||
4efc6507 DE |
7848 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7849 | ||
7850 | struct breakpoint * | |
7851 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7852 | { | |
2a7f3dff PA |
7853 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7854 | &internal_breakpoint_ops); | |
4efc6507 | 7855 | } |
0101ce28 | 7856 | |
03673fc7 PP |
7857 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7858 | ||
7859 | void | |
7860 | remove_jit_event_breakpoints (void) | |
7861 | { | |
7862 | struct breakpoint *b, *b_tmp; | |
7863 | ||
7864 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7865 | if (b->type == bp_jit_event | |
7866 | && b->loc->pspace == current_program_space) | |
7867 | delete_breakpoint (b); | |
7868 | } | |
7869 | ||
cae688ec JJ |
7870 | void |
7871 | remove_solib_event_breakpoints (void) | |
7872 | { | |
35df4500 | 7873 | struct breakpoint *b, *b_tmp; |
cae688ec | 7874 | |
35df4500 | 7875 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7876 | if (b->type == bp_shlib_event |
7877 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7878 | delete_breakpoint (b); |
7879 | } | |
7880 | ||
f37f681c PA |
7881 | /* See breakpoint.h. */ |
7882 | ||
7883 | void | |
7884 | remove_solib_event_breakpoints_at_next_stop (void) | |
7885 | { | |
7886 | struct breakpoint *b, *b_tmp; | |
7887 | ||
7888 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7889 | if (b->type == bp_shlib_event | |
7890 | && b->loc->pspace == current_program_space) | |
7891 | b->disposition = disp_del_at_next_stop; | |
7892 | } | |
7893 | ||
04086b45 PA |
7894 | /* Helper for create_solib_event_breakpoint / |
7895 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7896 | INSERT_MODE to pass through to update_global_location_list. */ | |
7897 | ||
7898 | static struct breakpoint * | |
7899 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7900 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7901 | { |
7902 | struct breakpoint *b; | |
7903 | ||
06edf0c0 PA |
7904 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7905 | &internal_breakpoint_ops); | |
04086b45 | 7906 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7907 | return b; |
7908 | } | |
7909 | ||
04086b45 PA |
7910 | struct breakpoint * |
7911 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7912 | { | |
7913 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7914 | } | |
7915 | ||
f37f681c PA |
7916 | /* See breakpoint.h. */ |
7917 | ||
7918 | struct breakpoint * | |
7919 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7920 | { | |
7921 | struct breakpoint *b; | |
7922 | ||
04086b45 PA |
7923 | /* Explicitly tell update_global_location_list to insert |
7924 | locations. */ | |
7925 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7926 | if (!b->loc->inserted) |
7927 | { | |
7928 | delete_breakpoint (b); | |
7929 | return NULL; | |
7930 | } | |
7931 | return b; | |
7932 | } | |
7933 | ||
cae688ec JJ |
7934 | /* Disable any breakpoints that are on code in shared libraries. Only |
7935 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7936 | ||
7937 | void | |
cb851954 | 7938 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7939 | { |
876fa593 | 7940 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7941 | |
876fa593 | 7942 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7943 | { |
2bdf28a0 | 7944 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7945 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7946 | |
4a64f543 MS |
7947 | /* We apply the check to all breakpoints, including disabled for |
7948 | those with loc->duplicate set. This is so that when breakpoint | |
7949 | becomes enabled, or the duplicate is removed, gdb will try to | |
7950 | insert all breakpoints. If we don't set shlib_disabled here, | |
7951 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7952 | if (((b->type == bp_breakpoint) |
508ccb1f | 7953 | || (b->type == bp_jit_event) |
1042e4c0 | 7954 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7955 | || (is_tracepoint (b))) |
6c95b8df | 7956 | && loc->pspace == current_program_space |
0d381245 | 7957 | && !loc->shlib_disabled |
6c95b8df | 7958 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7959 | ) |
0d381245 VP |
7960 | { |
7961 | loc->shlib_disabled = 1; | |
7962 | } | |
cae688ec JJ |
7963 | } |
7964 | } | |
7965 | ||
63644780 NB |
7966 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7967 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7968 | disabled ones can just stay disabled. */ | |
84acb35a | 7969 | |
75149521 | 7970 | static void |
84acb35a JJ |
7971 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7972 | { | |
876fa593 | 7973 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7974 | int disabled_shlib_breaks = 0; |
7975 | ||
c86cf029 VP |
7976 | /* SunOS a.out shared libraries are always mapped, so do not |
7977 | disable breakpoints; they will only be reported as unloaded | |
7978 | through clear_solib when GDB discards its shared library | |
7979 | list. See clear_solib for more information. */ | |
7980 | if (exec_bfd != NULL | |
7981 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7982 | return; | |
7983 | ||
876fa593 | 7984 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7985 | { |
2bdf28a0 | 7986 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7987 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7988 | |
1e4d1764 | 7989 | if (solib->pspace == loc->pspace |
e2dd7057 | 7990 | && !loc->shlib_disabled |
1e4d1764 YQ |
7991 | && (((b->type == bp_breakpoint |
7992 | || b->type == bp_jit_event | |
7993 | || b->type == bp_hardware_breakpoint) | |
7994 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7995 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7996 | || is_tracepoint (b)) | |
e2dd7057 | 7997 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7998 | { |
e2dd7057 PP |
7999 | loc->shlib_disabled = 1; |
8000 | /* At this point, we cannot rely on remove_breakpoint | |
8001 | succeeding so we must mark the breakpoint as not inserted | |
8002 | to prevent future errors occurring in remove_breakpoints. */ | |
8003 | loc->inserted = 0; | |
8d3788bd VP |
8004 | |
8005 | /* This may cause duplicate notifications for the same breakpoint. */ | |
8006 | observer_notify_breakpoint_modified (b); | |
8007 | ||
e2dd7057 PP |
8008 | if (!disabled_shlib_breaks) |
8009 | { | |
8010 | target_terminal_ours_for_output (); | |
3e43a32a MS |
8011 | warning (_("Temporarily disabling breakpoints " |
8012 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 8013 | solib->so_name); |
84acb35a | 8014 | } |
e2dd7057 | 8015 | disabled_shlib_breaks = 1; |
84acb35a JJ |
8016 | } |
8017 | } | |
84acb35a JJ |
8018 | } |
8019 | ||
63644780 NB |
8020 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
8021 | notification of free_objfile. Only apply to enabled breakpoints, | |
8022 | disabled ones can just stay disabled. */ | |
8023 | ||
8024 | static void | |
8025 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
8026 | { | |
8027 | struct breakpoint *b; | |
8028 | ||
8029 | if (objfile == NULL) | |
8030 | return; | |
8031 | ||
d03de421 PA |
8032 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
8033 | managed by the user with add-symbol-file/remove-symbol-file. | |
8034 | Similarly to how breakpoints in shared libraries are handled in | |
8035 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
8036 | shlib_disabled so they end up uninserted on the next global |
8037 | location list update. Shared libraries not loaded by the user | |
8038 | aren't handled here -- they're already handled in | |
8039 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8040 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8041 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8042 | main objfile). */ | |
8043 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8044 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8045 | return; |
8046 | ||
8047 | ALL_BREAKPOINTS (b) | |
8048 | { | |
8049 | struct bp_location *loc; | |
8050 | int bp_modified = 0; | |
8051 | ||
8052 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8053 | continue; | |
8054 | ||
8055 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8056 | { | |
8057 | CORE_ADDR loc_addr = loc->address; | |
8058 | ||
8059 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8060 | && loc->loc_type != bp_loc_software_breakpoint) | |
8061 | continue; | |
8062 | ||
8063 | if (loc->shlib_disabled != 0) | |
8064 | continue; | |
8065 | ||
8066 | if (objfile->pspace != loc->pspace) | |
8067 | continue; | |
8068 | ||
8069 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8070 | && loc->loc_type != bp_loc_software_breakpoint) | |
8071 | continue; | |
8072 | ||
8073 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8074 | { | |
8075 | loc->shlib_disabled = 1; | |
08351840 PA |
8076 | /* At this point, we don't know whether the object was |
8077 | unmapped from the inferior or not, so leave the | |
8078 | inserted flag alone. We'll handle failure to | |
8079 | uninsert quietly, in case the object was indeed | |
8080 | unmapped. */ | |
63644780 NB |
8081 | |
8082 | mark_breakpoint_location_modified (loc); | |
8083 | ||
8084 | bp_modified = 1; | |
8085 | } | |
8086 | } | |
8087 | ||
8088 | if (bp_modified) | |
8089 | observer_notify_breakpoint_modified (b); | |
8090 | } | |
8091 | } | |
8092 | ||
ce78b96d JB |
8093 | /* FORK & VFORK catchpoints. */ |
8094 | ||
e29a4733 PA |
8095 | /* An instance of this type is used to represent a fork or vfork |
8096 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8097 | class; users downcast to "struct breakpoint *" when needed. A | |
8098 | breakpoint is really of this type iff its ops pointer points to | |
8099 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8100 | ||
8101 | struct fork_catchpoint | |
8102 | { | |
8103 | /* The base class. */ | |
8104 | struct breakpoint base; | |
8105 | ||
8106 | /* Process id of a child process whose forking triggered this | |
8107 | catchpoint. This field is only valid immediately after this | |
8108 | catchpoint has triggered. */ | |
8109 | ptid_t forked_inferior_pid; | |
8110 | }; | |
8111 | ||
4a64f543 MS |
8112 | /* Implement the "insert" breakpoint_ops method for fork |
8113 | catchpoints. */ | |
ce78b96d | 8114 | |
77b06cd7 TJB |
8115 | static int |
8116 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8117 | { |
dfd4cc63 | 8118 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8119 | } |
8120 | ||
4a64f543 MS |
8121 | /* Implement the "remove" breakpoint_ops method for fork |
8122 | catchpoints. */ | |
ce78b96d JB |
8123 | |
8124 | static int | |
73971819 | 8125 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8126 | { |
dfd4cc63 | 8127 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8128 | } |
8129 | ||
8130 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8131 | catchpoints. */ | |
8132 | ||
8133 | static int | |
f1310107 | 8134 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8135 | struct address_space *aspace, CORE_ADDR bp_addr, |
8136 | const struct target_waitstatus *ws) | |
ce78b96d | 8137 | { |
e29a4733 PA |
8138 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8139 | ||
f90263c1 TT |
8140 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8141 | return 0; | |
8142 | ||
8143 | c->forked_inferior_pid = ws->value.related_pid; | |
8144 | return 1; | |
ce78b96d JB |
8145 | } |
8146 | ||
4a64f543 MS |
8147 | /* Implement the "print_it" breakpoint_ops method for fork |
8148 | catchpoints. */ | |
ce78b96d JB |
8149 | |
8150 | static enum print_stop_action | |
348d480f | 8151 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8152 | { |
36dfb11c | 8153 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8154 | struct breakpoint *b = bs->breakpoint_at; |
8155 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8156 | |
ce78b96d | 8157 | annotate_catchpoint (b->number); |
f303dbd6 | 8158 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8159 | if (b->disposition == disp_del) |
f303dbd6 | 8160 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8161 | else |
f303dbd6 | 8162 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8163 | if (ui_out_is_mi_like_p (uiout)) |
8164 | { | |
8165 | ui_out_field_string (uiout, "reason", | |
8166 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8167 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8168 | } | |
8169 | ui_out_field_int (uiout, "bkptno", b->number); | |
8170 | ui_out_text (uiout, " (forked process "); | |
8171 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8172 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8173 | return PRINT_SRC_AND_LOC; |
8174 | } | |
8175 | ||
4a64f543 MS |
8176 | /* Implement the "print_one" breakpoint_ops method for fork |
8177 | catchpoints. */ | |
ce78b96d JB |
8178 | |
8179 | static void | |
a6d9a66e | 8180 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8181 | { |
e29a4733 | 8182 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8183 | struct value_print_options opts; |
79a45e25 | 8184 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8185 | |
8186 | get_user_print_options (&opts); | |
8187 | ||
4a64f543 MS |
8188 | /* Field 4, the address, is omitted (which makes the columns not |
8189 | line up too nicely with the headers, but the effect is relatively | |
8190 | readable). */ | |
79a45b7d | 8191 | if (opts.addressprint) |
ce78b96d JB |
8192 | ui_out_field_skip (uiout, "addr"); |
8193 | annotate_field (5); | |
8194 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8195 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8196 | { |
8197 | ui_out_text (uiout, ", process "); | |
8198 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8199 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8200 | ui_out_spaces (uiout, 1); |
8201 | } | |
8ac3646f TT |
8202 | |
8203 | if (ui_out_is_mi_like_p (uiout)) | |
8204 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8205 | } |
8206 | ||
8207 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8208 | catchpoints. */ | |
8209 | ||
8210 | static void | |
8211 | print_mention_catch_fork (struct breakpoint *b) | |
8212 | { | |
8213 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8214 | } | |
8215 | ||
6149aea9 PA |
8216 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8217 | catchpoints. */ | |
8218 | ||
8219 | static void | |
8220 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8221 | { | |
8222 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8223 | print_recreate_thread (b, fp); |
6149aea9 PA |
8224 | } |
8225 | ||
ce78b96d JB |
8226 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8227 | ||
2060206e | 8228 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8229 | |
4a64f543 MS |
8230 | /* Implement the "insert" breakpoint_ops method for vfork |
8231 | catchpoints. */ | |
ce78b96d | 8232 | |
77b06cd7 TJB |
8233 | static int |
8234 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8235 | { |
dfd4cc63 | 8236 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8237 | } |
8238 | ||
4a64f543 MS |
8239 | /* Implement the "remove" breakpoint_ops method for vfork |
8240 | catchpoints. */ | |
ce78b96d JB |
8241 | |
8242 | static int | |
73971819 | 8243 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8244 | { |
dfd4cc63 | 8245 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8246 | } |
8247 | ||
8248 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8249 | catchpoints. */ | |
8250 | ||
8251 | static int | |
f1310107 | 8252 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8253 | struct address_space *aspace, CORE_ADDR bp_addr, |
8254 | const struct target_waitstatus *ws) | |
ce78b96d | 8255 | { |
e29a4733 PA |
8256 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8257 | ||
f90263c1 TT |
8258 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8259 | return 0; | |
8260 | ||
8261 | c->forked_inferior_pid = ws->value.related_pid; | |
8262 | return 1; | |
ce78b96d JB |
8263 | } |
8264 | ||
4a64f543 MS |
8265 | /* Implement the "print_it" breakpoint_ops method for vfork |
8266 | catchpoints. */ | |
ce78b96d JB |
8267 | |
8268 | static enum print_stop_action | |
348d480f | 8269 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8270 | { |
36dfb11c | 8271 | struct ui_out *uiout = current_uiout; |
348d480f | 8272 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8273 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8274 | ||
ce78b96d | 8275 | annotate_catchpoint (b->number); |
f303dbd6 | 8276 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8277 | if (b->disposition == disp_del) |
f303dbd6 | 8278 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8279 | else |
f303dbd6 | 8280 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8281 | if (ui_out_is_mi_like_p (uiout)) |
8282 | { | |
8283 | ui_out_field_string (uiout, "reason", | |
8284 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8285 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8286 | } | |
8287 | ui_out_field_int (uiout, "bkptno", b->number); | |
8288 | ui_out_text (uiout, " (vforked process "); | |
8289 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8290 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8291 | return PRINT_SRC_AND_LOC; |
8292 | } | |
8293 | ||
4a64f543 MS |
8294 | /* Implement the "print_one" breakpoint_ops method for vfork |
8295 | catchpoints. */ | |
ce78b96d JB |
8296 | |
8297 | static void | |
a6d9a66e | 8298 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8299 | { |
e29a4733 | 8300 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8301 | struct value_print_options opts; |
79a45e25 | 8302 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8303 | |
8304 | get_user_print_options (&opts); | |
4a64f543 MS |
8305 | /* Field 4, the address, is omitted (which makes the columns not |
8306 | line up too nicely with the headers, but the effect is relatively | |
8307 | readable). */ | |
79a45b7d | 8308 | if (opts.addressprint) |
ce78b96d JB |
8309 | ui_out_field_skip (uiout, "addr"); |
8310 | annotate_field (5); | |
8311 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8312 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8313 | { |
8314 | ui_out_text (uiout, ", process "); | |
8315 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8316 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8317 | ui_out_spaces (uiout, 1); |
8318 | } | |
8ac3646f TT |
8319 | |
8320 | if (ui_out_is_mi_like_p (uiout)) | |
8321 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8322 | } |
8323 | ||
8324 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8325 | catchpoints. */ | |
8326 | ||
8327 | static void | |
8328 | print_mention_catch_vfork (struct breakpoint *b) | |
8329 | { | |
8330 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8331 | } | |
8332 | ||
6149aea9 PA |
8333 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8334 | catchpoints. */ | |
8335 | ||
8336 | static void | |
8337 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8338 | { | |
8339 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8340 | print_recreate_thread (b, fp); |
6149aea9 PA |
8341 | } |
8342 | ||
ce78b96d JB |
8343 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8344 | ||
2060206e | 8345 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8346 | |
edcc5120 TT |
8347 | /* An instance of this type is used to represent an solib catchpoint. |
8348 | It includes a "struct breakpoint" as a kind of base class; users | |
8349 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8350 | really of this type iff its ops pointer points to | |
8351 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8352 | ||
8353 | struct solib_catchpoint | |
8354 | { | |
8355 | /* The base class. */ | |
8356 | struct breakpoint base; | |
8357 | ||
8358 | /* True for "catch load", false for "catch unload". */ | |
8359 | unsigned char is_load; | |
8360 | ||
8361 | /* Regular expression to match, if any. COMPILED is only valid when | |
8362 | REGEX is non-NULL. */ | |
8363 | char *regex; | |
8364 | regex_t compiled; | |
8365 | }; | |
8366 | ||
8367 | static void | |
8368 | dtor_catch_solib (struct breakpoint *b) | |
8369 | { | |
8370 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8371 | ||
8372 | if (self->regex) | |
8373 | regfree (&self->compiled); | |
8374 | xfree (self->regex); | |
8375 | ||
8376 | base_breakpoint_ops.dtor (b); | |
8377 | } | |
8378 | ||
8379 | static int | |
8380 | insert_catch_solib (struct bp_location *ignore) | |
8381 | { | |
8382 | return 0; | |
8383 | } | |
8384 | ||
8385 | static int | |
73971819 | 8386 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8387 | { |
8388 | return 0; | |
8389 | } | |
8390 | ||
8391 | static int | |
8392 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8393 | struct address_space *aspace, | |
8394 | CORE_ADDR bp_addr, | |
8395 | const struct target_waitstatus *ws) | |
8396 | { | |
8397 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8398 | struct breakpoint *other; | |
8399 | ||
8400 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8401 | return 1; | |
8402 | ||
8403 | ALL_BREAKPOINTS (other) | |
8404 | { | |
8405 | struct bp_location *other_bl; | |
8406 | ||
8407 | if (other == bl->owner) | |
8408 | continue; | |
8409 | ||
8410 | if (other->type != bp_shlib_event) | |
8411 | continue; | |
8412 | ||
8413 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8414 | continue; | |
8415 | ||
8416 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8417 | { | |
8418 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8419 | return 1; | |
8420 | } | |
8421 | } | |
8422 | ||
8423 | return 0; | |
8424 | } | |
8425 | ||
8426 | static void | |
8427 | check_status_catch_solib (struct bpstats *bs) | |
8428 | { | |
8429 | struct solib_catchpoint *self | |
8430 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8431 | int ix; | |
8432 | ||
8433 | if (self->is_load) | |
8434 | { | |
8435 | struct so_list *iter; | |
8436 | ||
8437 | for (ix = 0; | |
8438 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8439 | ix, iter); | |
8440 | ++ix) | |
8441 | { | |
8442 | if (!self->regex | |
8443 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8444 | return; | |
8445 | } | |
8446 | } | |
8447 | else | |
8448 | { | |
8449 | char *iter; | |
8450 | ||
8451 | for (ix = 0; | |
8452 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8453 | ix, iter); | |
8454 | ++ix) | |
8455 | { | |
8456 | if (!self->regex | |
8457 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8458 | return; | |
8459 | } | |
8460 | } | |
8461 | ||
8462 | bs->stop = 0; | |
8463 | bs->print_it = print_it_noop; | |
8464 | } | |
8465 | ||
8466 | static enum print_stop_action | |
8467 | print_it_catch_solib (bpstat bs) | |
8468 | { | |
8469 | struct breakpoint *b = bs->breakpoint_at; | |
8470 | struct ui_out *uiout = current_uiout; | |
8471 | ||
8472 | annotate_catchpoint (b->number); | |
f303dbd6 | 8473 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8474 | if (b->disposition == disp_del) |
f303dbd6 | 8475 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8476 | else |
f303dbd6 | 8477 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8478 | ui_out_field_int (uiout, "bkptno", b->number); |
8479 | ui_out_text (uiout, "\n"); | |
8480 | if (ui_out_is_mi_like_p (uiout)) | |
8481 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8482 | print_solib_event (1); | |
8483 | return PRINT_SRC_AND_LOC; | |
8484 | } | |
8485 | ||
8486 | static void | |
8487 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8488 | { | |
8489 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8490 | struct value_print_options opts; | |
8491 | struct ui_out *uiout = current_uiout; | |
8492 | char *msg; | |
8493 | ||
8494 | get_user_print_options (&opts); | |
8495 | /* Field 4, the address, is omitted (which makes the columns not | |
8496 | line up too nicely with the headers, but the effect is relatively | |
8497 | readable). */ | |
8498 | if (opts.addressprint) | |
8499 | { | |
8500 | annotate_field (4); | |
8501 | ui_out_field_skip (uiout, "addr"); | |
8502 | } | |
8503 | ||
8504 | annotate_field (5); | |
8505 | if (self->is_load) | |
8506 | { | |
8507 | if (self->regex) | |
8508 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8509 | else | |
8510 | msg = xstrdup (_("load of library")); | |
8511 | } | |
8512 | else | |
8513 | { | |
8514 | if (self->regex) | |
8515 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8516 | else | |
8517 | msg = xstrdup (_("unload of library")); | |
8518 | } | |
8519 | ui_out_field_string (uiout, "what", msg); | |
8520 | xfree (msg); | |
8ac3646f TT |
8521 | |
8522 | if (ui_out_is_mi_like_p (uiout)) | |
8523 | ui_out_field_string (uiout, "catch-type", | |
8524 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8525 | } |
8526 | ||
8527 | static void | |
8528 | print_mention_catch_solib (struct breakpoint *b) | |
8529 | { | |
8530 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8531 | ||
8532 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8533 | self->is_load ? "load" : "unload"); | |
8534 | } | |
8535 | ||
8536 | static void | |
8537 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8538 | { | |
8539 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8540 | ||
8541 | fprintf_unfiltered (fp, "%s %s", | |
8542 | b->disposition == disp_del ? "tcatch" : "catch", | |
8543 | self->is_load ? "load" : "unload"); | |
8544 | if (self->regex) | |
8545 | fprintf_unfiltered (fp, " %s", self->regex); | |
8546 | fprintf_unfiltered (fp, "\n"); | |
8547 | } | |
8548 | ||
8549 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8550 | ||
91985142 MG |
8551 | /* Shared helper function (MI and CLI) for creating and installing |
8552 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8553 | the events to be caught are load events, otherwise they are | |
8554 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8555 | temporary one. If ENABLED is non-zero the catchpoint is | |
8556 | created in an enabled state. */ | |
edcc5120 | 8557 | |
91985142 MG |
8558 | void |
8559 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8560 | { |
8561 | struct solib_catchpoint *c; | |
8562 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8563 | struct cleanup *cleanup; |
8564 | ||
edcc5120 TT |
8565 | if (!arg) |
8566 | arg = ""; | |
8567 | arg = skip_spaces (arg); | |
8568 | ||
8569 | c = XCNEW (struct solib_catchpoint); | |
8570 | cleanup = make_cleanup (xfree, c); | |
8571 | ||
8572 | if (*arg != '\0') | |
8573 | { | |
8574 | int errcode; | |
8575 | ||
8576 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8577 | if (errcode != 0) | |
8578 | { | |
8579 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8580 | ||
8581 | make_cleanup (xfree, err); | |
8582 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8583 | } | |
8584 | c->regex = xstrdup (arg); | |
8585 | } | |
8586 | ||
8587 | c->is_load = is_load; | |
91985142 | 8588 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8589 | &catch_solib_breakpoint_ops); |
8590 | ||
91985142 MG |
8591 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8592 | ||
edcc5120 TT |
8593 | discard_cleanups (cleanup); |
8594 | install_breakpoint (0, &c->base, 1); | |
8595 | } | |
8596 | ||
91985142 MG |
8597 | /* A helper function that does all the work for "catch load" and |
8598 | "catch unload". */ | |
8599 | ||
8600 | static void | |
8601 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8602 | struct cmd_list_element *command) | |
8603 | { | |
8604 | int tempflag; | |
8605 | const int enabled = 1; | |
8606 | ||
8607 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8608 | ||
8609 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8610 | } | |
8611 | ||
edcc5120 TT |
8612 | static void |
8613 | catch_load_command_1 (char *arg, int from_tty, | |
8614 | struct cmd_list_element *command) | |
8615 | { | |
8616 | catch_load_or_unload (arg, from_tty, 1, command); | |
8617 | } | |
8618 | ||
8619 | static void | |
8620 | catch_unload_command_1 (char *arg, int from_tty, | |
8621 | struct cmd_list_element *command) | |
8622 | { | |
8623 | catch_load_or_unload (arg, from_tty, 0, command); | |
8624 | } | |
8625 | ||
346774a9 PA |
8626 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8627 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8628 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8629 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8630 | |
ab04a2af | 8631 | void |
346774a9 PA |
8632 | init_catchpoint (struct breakpoint *b, |
8633 | struct gdbarch *gdbarch, int tempflag, | |
8634 | char *cond_string, | |
c0a91b2b | 8635 | const struct breakpoint_ops *ops) |
c906108c | 8636 | { |
c5aa993b | 8637 | struct symtab_and_line sal; |
346774a9 | 8638 | |
fe39c653 | 8639 | init_sal (&sal); |
6c95b8df | 8640 | sal.pspace = current_program_space; |
c5aa993b | 8641 | |
28010a5d | 8642 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8643 | |
1b36a34b | 8644 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8645 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8646 | } |
8647 | ||
28010a5d | 8648 | void |
3ea46bff | 8649 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8650 | { |
8651 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8652 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8653 | if (is_tracepoint (b)) |
8654 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8655 | if (!internal) |
8656 | mention (b); | |
c56053d2 | 8657 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8658 | |
8659 | if (update_gll) | |
44702360 | 8660 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8661 | } |
8662 | ||
9b70b993 | 8663 | static void |
a6d9a66e UW |
8664 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8665 | int tempflag, char *cond_string, | |
c0a91b2b | 8666 | const struct breakpoint_ops *ops) |
c906108c | 8667 | { |
e29a4733 | 8668 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8669 | |
e29a4733 PA |
8670 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8671 | ||
8672 | c->forked_inferior_pid = null_ptid; | |
8673 | ||
3ea46bff | 8674 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8675 | } |
8676 | ||
fe798b75 JB |
8677 | /* Exec catchpoints. */ |
8678 | ||
b4d90040 PA |
8679 | /* An instance of this type is used to represent an exec catchpoint. |
8680 | It includes a "struct breakpoint" as a kind of base class; users | |
8681 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8682 | really of this type iff its ops pointer points to | |
8683 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8684 | ||
8685 | struct exec_catchpoint | |
8686 | { | |
8687 | /* The base class. */ | |
8688 | struct breakpoint base; | |
8689 | ||
8690 | /* Filename of a program whose exec triggered this catchpoint. | |
8691 | This field is only valid immediately after this catchpoint has | |
8692 | triggered. */ | |
8693 | char *exec_pathname; | |
8694 | }; | |
8695 | ||
8696 | /* Implement the "dtor" breakpoint_ops method for exec | |
8697 | catchpoints. */ | |
8698 | ||
8699 | static void | |
8700 | dtor_catch_exec (struct breakpoint *b) | |
8701 | { | |
8702 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8703 | ||
8704 | xfree (c->exec_pathname); | |
348d480f | 8705 | |
2060206e | 8706 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8707 | } |
8708 | ||
77b06cd7 TJB |
8709 | static int |
8710 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8711 | { |
dfd4cc63 | 8712 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8713 | } |
c906108c | 8714 | |
fe798b75 | 8715 | static int |
73971819 | 8716 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8717 | { |
dfd4cc63 | 8718 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8719 | } |
c906108c | 8720 | |
fe798b75 | 8721 | static int |
f1310107 | 8722 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8723 | struct address_space *aspace, CORE_ADDR bp_addr, |
8724 | const struct target_waitstatus *ws) | |
fe798b75 | 8725 | { |
b4d90040 PA |
8726 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8727 | ||
f90263c1 TT |
8728 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8729 | return 0; | |
8730 | ||
8731 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8732 | return 1; | |
fe798b75 | 8733 | } |
c906108c | 8734 | |
fe798b75 | 8735 | static enum print_stop_action |
348d480f | 8736 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8737 | { |
36dfb11c | 8738 | struct ui_out *uiout = current_uiout; |
348d480f | 8739 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8740 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8741 | ||
fe798b75 | 8742 | annotate_catchpoint (b->number); |
f303dbd6 | 8743 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8744 | if (b->disposition == disp_del) |
f303dbd6 | 8745 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8746 | else |
f303dbd6 | 8747 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8748 | if (ui_out_is_mi_like_p (uiout)) |
8749 | { | |
8750 | ui_out_field_string (uiout, "reason", | |
8751 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8752 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8753 | } | |
8754 | ui_out_field_int (uiout, "bkptno", b->number); | |
8755 | ui_out_text (uiout, " (exec'd "); | |
8756 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8757 | ui_out_text (uiout, "), "); | |
8758 | ||
fe798b75 | 8759 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8760 | } |
8761 | ||
fe798b75 | 8762 | static void |
a6d9a66e | 8763 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8764 | { |
b4d90040 | 8765 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8766 | struct value_print_options opts; |
79a45e25 | 8767 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8768 | |
8769 | get_user_print_options (&opts); | |
8770 | ||
8771 | /* Field 4, the address, is omitted (which makes the columns | |
8772 | not line up too nicely with the headers, but the effect | |
8773 | is relatively readable). */ | |
8774 | if (opts.addressprint) | |
8775 | ui_out_field_skip (uiout, "addr"); | |
8776 | annotate_field (5); | |
8777 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8778 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8779 | { |
8780 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8781 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8782 | ui_out_text (uiout, "\" "); |
8783 | } | |
8ac3646f TT |
8784 | |
8785 | if (ui_out_is_mi_like_p (uiout)) | |
8786 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8787 | } |
8788 | ||
8789 | static void | |
8790 | print_mention_catch_exec (struct breakpoint *b) | |
8791 | { | |
8792 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8793 | } | |
8794 | ||
6149aea9 PA |
8795 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8796 | catchpoints. */ | |
8797 | ||
8798 | static void | |
8799 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8800 | { | |
8801 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8802 | print_recreate_thread (b, fp); |
6149aea9 PA |
8803 | } |
8804 | ||
2060206e | 8805 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8806 | |
c906108c | 8807 | static int |
fba45db2 | 8808 | hw_breakpoint_used_count (void) |
c906108c | 8809 | { |
c906108c | 8810 | int i = 0; |
f1310107 TJB |
8811 | struct breakpoint *b; |
8812 | struct bp_location *bl; | |
c906108c SS |
8813 | |
8814 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8815 | { |
d6b74ac4 | 8816 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8817 | for (bl = b->loc; bl; bl = bl->next) |
8818 | { | |
8819 | /* Special types of hardware breakpoints may use more than | |
8820 | one register. */ | |
348d480f | 8821 | i += b->ops->resources_needed (bl); |
f1310107 | 8822 | } |
c5aa993b | 8823 | } |
c906108c SS |
8824 | |
8825 | return i; | |
8826 | } | |
8827 | ||
a1398e0c PA |
8828 | /* Returns the resources B would use if it were a hardware |
8829 | watchpoint. */ | |
8830 | ||
c906108c | 8831 | static int |
a1398e0c | 8832 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8833 | { |
c906108c | 8834 | int i = 0; |
e09342b5 | 8835 | struct bp_location *bl; |
c906108c | 8836 | |
a1398e0c PA |
8837 | if (!breakpoint_enabled (b)) |
8838 | return 0; | |
8839 | ||
8840 | for (bl = b->loc; bl; bl = bl->next) | |
8841 | { | |
8842 | /* Special types of hardware watchpoints may use more than | |
8843 | one register. */ | |
8844 | i += b->ops->resources_needed (bl); | |
8845 | } | |
8846 | ||
8847 | return i; | |
8848 | } | |
8849 | ||
8850 | /* Returns the sum the used resources of all hardware watchpoints of | |
8851 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8852 | the sum of the used resources of all hardware watchpoints of other | |
8853 | types _not_ TYPE. */ | |
8854 | ||
8855 | static int | |
8856 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8857 | enum bptype type, int *other_type_used) | |
8858 | { | |
8859 | int i = 0; | |
8860 | struct breakpoint *b; | |
8861 | ||
c906108c SS |
8862 | *other_type_used = 0; |
8863 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8864 | { |
a1398e0c PA |
8865 | if (b == except) |
8866 | continue; | |
e09342b5 TJB |
8867 | if (!breakpoint_enabled (b)) |
8868 | continue; | |
8869 | ||
a1398e0c PA |
8870 | if (b->type == type) |
8871 | i += hw_watchpoint_use_count (b); | |
8872 | else if (is_hardware_watchpoint (b)) | |
8873 | *other_type_used = 1; | |
e09342b5 TJB |
8874 | } |
8875 | ||
c906108c SS |
8876 | return i; |
8877 | } | |
8878 | ||
c906108c | 8879 | void |
fba45db2 | 8880 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8881 | { |
c5aa993b | 8882 | struct breakpoint *b; |
c906108c SS |
8883 | |
8884 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8885 | { |
cc60f2e3 | 8886 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8887 | { |
b5de0fa7 | 8888 | b->enable_state = bp_call_disabled; |
44702360 | 8889 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8890 | } |
8891 | } | |
c906108c SS |
8892 | } |
8893 | ||
8894 | void | |
fba45db2 | 8895 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8896 | { |
c5aa993b | 8897 | struct breakpoint *b; |
c906108c SS |
8898 | |
8899 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8900 | { |
cc60f2e3 | 8901 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8902 | { |
b5de0fa7 | 8903 | b->enable_state = bp_enabled; |
44702360 | 8904 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8905 | } |
8906 | } | |
c906108c SS |
8907 | } |
8908 | ||
8bea4e01 UW |
8909 | void |
8910 | disable_breakpoints_before_startup (void) | |
8911 | { | |
6c95b8df | 8912 | current_program_space->executing_startup = 1; |
44702360 | 8913 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8914 | } |
8915 | ||
8916 | void | |
8917 | enable_breakpoints_after_startup (void) | |
8918 | { | |
6c95b8df | 8919 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8920 | breakpoint_re_set (); |
8bea4e01 UW |
8921 | } |
8922 | ||
7c16b83e PA |
8923 | /* Create a new single-step breakpoint for thread THREAD, with no |
8924 | locations. */ | |
c906108c | 8925 | |
7c16b83e PA |
8926 | static struct breakpoint * |
8927 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8928 | { | |
8929 | struct breakpoint *b = XNEW (struct breakpoint); | |
8930 | ||
8931 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8932 | &momentary_breakpoint_ops); | |
8933 | ||
8934 | b->disposition = disp_donttouch; | |
8935 | b->frame_id = null_frame_id; | |
8936 | ||
8937 | b->thread = thread; | |
8938 | gdb_assert (b->thread != 0); | |
8939 | ||
8940 | add_to_breakpoint_chain (b); | |
8941 | ||
8942 | return b; | |
8943 | } | |
8944 | ||
8945 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8946 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8947 | frame. */ | |
c906108c SS |
8948 | |
8949 | struct breakpoint * | |
a6d9a66e UW |
8950 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8951 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8952 | { |
52f0bd74 | 8953 | struct breakpoint *b; |
edb3359d | 8954 | |
193facb3 JK |
8955 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8956 | tail-called one. */ | |
8957 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8958 | |
06edf0c0 | 8959 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8960 | b->enable_state = bp_enabled; |
8961 | b->disposition = disp_donttouch; | |
818dd999 | 8962 | b->frame_id = frame_id; |
c906108c | 8963 | |
4a64f543 MS |
8964 | /* If we're debugging a multi-threaded program, then we want |
8965 | momentary breakpoints to be active in only a single thread of | |
8966 | control. */ | |
39f77062 | 8967 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8968 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8969 | |
44702360 | 8970 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8971 | |
c906108c SS |
8972 | return b; |
8973 | } | |
611c83ae | 8974 | |
06edf0c0 | 8975 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8976 | The new breakpoint will have type TYPE, use OPS as its |
8977 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8978 | |
06edf0c0 PA |
8979 | static struct breakpoint * |
8980 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8981 | enum bptype type, | |
a1aa2221 LM |
8982 | const struct breakpoint_ops *ops, |
8983 | int loc_enabled) | |
e58b0e63 PA |
8984 | { |
8985 | struct breakpoint *copy; | |
8986 | ||
06edf0c0 | 8987 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8988 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8989 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8990 | |
a6d9a66e | 8991 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8992 | copy->loc->requested_address = orig->loc->requested_address; |
8993 | copy->loc->address = orig->loc->address; | |
8994 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8995 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8996 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8997 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8998 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8999 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9000 | copy->frame_id = orig->frame_id; |
9001 | copy->thread = orig->thread; | |
6c95b8df | 9002 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9003 | |
9004 | copy->enable_state = bp_enabled; | |
9005 | copy->disposition = disp_donttouch; | |
9006 | copy->number = internal_breakpoint_number--; | |
9007 | ||
44702360 | 9008 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9009 | return copy; |
9010 | } | |
9011 | ||
06edf0c0 PA |
9012 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9013 | ORIG is NULL. */ | |
9014 | ||
9015 | struct breakpoint * | |
9016 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9017 | { | |
9018 | /* If there's nothing to clone, then return nothing. */ | |
9019 | if (orig == NULL) | |
9020 | return NULL; | |
9021 | ||
a1aa2221 | 9022 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9023 | } |
9024 | ||
611c83ae | 9025 | struct breakpoint * |
a6d9a66e UW |
9026 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9027 | enum bptype type) | |
611c83ae PA |
9028 | { |
9029 | struct symtab_and_line sal; | |
9030 | ||
9031 | sal = find_pc_line (pc, 0); | |
9032 | sal.pc = pc; | |
9033 | sal.section = find_pc_overlay (pc); | |
9034 | sal.explicit_pc = 1; | |
9035 | ||
a6d9a66e | 9036 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9037 | } |
c906108c | 9038 | \f |
c5aa993b | 9039 | |
c906108c SS |
9040 | /* Tell the user we have just set a breakpoint B. */ |
9041 | ||
9042 | static void | |
fba45db2 | 9043 | mention (struct breakpoint *b) |
c906108c | 9044 | { |
348d480f | 9045 | b->ops->print_mention (b); |
79a45e25 | 9046 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9047 | return; |
c906108c SS |
9048 | printf_filtered ("\n"); |
9049 | } | |
c906108c | 9050 | \f |
c5aa993b | 9051 | |
1a853c52 PA |
9052 | static int bp_loc_is_permanent (struct bp_location *loc); |
9053 | ||
0d381245 | 9054 | static struct bp_location * |
39d61571 | 9055 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9056 | const struct symtab_and_line *sal) |
9057 | { | |
9058 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9059 | CORE_ADDR adjusted_address; |
9060 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9061 | ||
9062 | if (loc_gdbarch == NULL) | |
9063 | loc_gdbarch = b->gdbarch; | |
9064 | ||
9065 | /* Adjust the breakpoint's address prior to allocating a location. | |
9066 | Once we call allocate_bp_location(), that mostly uninitialized | |
9067 | location will be placed on the location chain. Adjustment of the | |
9068 | breakpoint may cause target_read_memory() to be called and we do | |
9069 | not want its scan of the location chain to find a breakpoint and | |
9070 | location that's only been partially initialized. */ | |
9071 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9072 | sal->pc, b->type); | |
0d381245 | 9073 | |
d30113d4 | 9074 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9075 | loc = allocate_bp_location (b); |
d30113d4 JK |
9076 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9077 | tmp = &((*tmp)->next)) | |
0d381245 | 9078 | ; |
d30113d4 | 9079 | loc->next = *tmp; |
0d381245 | 9080 | *tmp = loc; |
3742cc8b | 9081 | |
0d381245 | 9082 | loc->requested_address = sal->pc; |
3742cc8b | 9083 | loc->address = adjusted_address; |
6c95b8df | 9084 | loc->pspace = sal->pspace; |
729662a5 TT |
9085 | loc->probe.probe = sal->probe; |
9086 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9087 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9088 | loc->section = sal->section; |
3742cc8b | 9089 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9090 | loc->line_number = sal->line; |
2f202fde | 9091 | loc->symtab = sal->symtab; |
f8eba3c6 | 9092 | |
0e30163f JK |
9093 | set_breakpoint_location_function (loc, |
9094 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9095 | |
6ae88661 LM |
9096 | /* While by definition, permanent breakpoints are already present in the |
9097 | code, we don't mark the location as inserted. Normally one would expect | |
9098 | that GDB could rely on that breakpoint instruction to stop the program, | |
9099 | thus removing the need to insert its own breakpoint, except that executing | |
9100 | the breakpoint instruction can kill the target instead of reporting a | |
9101 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9102 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9103 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9104 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9105 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9106 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9107 | it manually increments the PC, thus avoiding executing the breakpoint | |
9108 | instruction.) */ | |
1a853c52 | 9109 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9110 | loc->permanent = 1; |
1a853c52 | 9111 | |
0d381245 VP |
9112 | return loc; |
9113 | } | |
514f746b AR |
9114 | \f |
9115 | ||
1cf4d951 | 9116 | /* See breakpoint.h. */ |
514f746b | 9117 | |
1cf4d951 PA |
9118 | int |
9119 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9120 | { |
9121 | int len; | |
9122 | CORE_ADDR addr; | |
1afeeb75 | 9123 | const gdb_byte *bpoint; |
514f746b | 9124 | gdb_byte *target_mem; |
939c61fa JK |
9125 | struct cleanup *cleanup; |
9126 | int retval = 0; | |
514f746b | 9127 | |
1cf4d951 PA |
9128 | addr = address; |
9129 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9130 | ||
9131 | /* Software breakpoints unsupported? */ | |
9132 | if (bpoint == NULL) | |
9133 | return 0; | |
9134 | ||
224c3ddb | 9135 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9136 | |
9137 | /* Enable the automatic memory restoration from breakpoints while | |
9138 | we read the memory. Otherwise we could say about our temporary | |
9139 | breakpoints they are permanent. */ | |
9140 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9141 | ||
9142 | if (target_read_memory (address, target_mem, len) == 0 | |
9143 | && memcmp (target_mem, bpoint, len) == 0) | |
9144 | retval = 1; | |
9145 | ||
9146 | do_cleanups (cleanup); | |
9147 | ||
9148 | return retval; | |
9149 | } | |
9150 | ||
9151 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9152 | return 0 otherwise. */ | |
9153 | ||
9154 | static int | |
9155 | bp_loc_is_permanent (struct bp_location *loc) | |
9156 | { | |
9157 | struct cleanup *cleanup; | |
9158 | int retval; | |
9159 | ||
514f746b AR |
9160 | gdb_assert (loc != NULL); |
9161 | ||
244558af LM |
9162 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9163 | attempt to read from the addresses the locations of these breakpoint types | |
9164 | point to. program_breakpoint_here_p, below, will attempt to read | |
9165 | memory. */ | |
9166 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9167 | return 0; | |
9168 | ||
6c95b8df | 9169 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9170 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9171 | |
1cf4d951 | 9172 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9173 | |
939c61fa JK |
9174 | do_cleanups (cleanup); |
9175 | ||
9176 | return retval; | |
514f746b AR |
9177 | } |
9178 | ||
e7e0cddf SS |
9179 | /* Build a command list for the dprintf corresponding to the current |
9180 | settings of the dprintf style options. */ | |
9181 | ||
9182 | static void | |
9183 | update_dprintf_command_list (struct breakpoint *b) | |
9184 | { | |
9185 | char *dprintf_args = b->extra_string; | |
9186 | char *printf_line = NULL; | |
9187 | ||
9188 | if (!dprintf_args) | |
9189 | return; | |
9190 | ||
9191 | dprintf_args = skip_spaces (dprintf_args); | |
9192 | ||
9193 | /* Allow a comma, as it may have terminated a location, but don't | |
9194 | insist on it. */ | |
9195 | if (*dprintf_args == ',') | |
9196 | ++dprintf_args; | |
9197 | dprintf_args = skip_spaces (dprintf_args); | |
9198 | ||
9199 | if (*dprintf_args != '"') | |
9200 | error (_("Bad format string, missing '\"'.")); | |
9201 | ||
d3ce09f5 | 9202 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9203 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9204 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9205 | { |
9206 | if (!dprintf_function) | |
9207 | error (_("No function supplied for dprintf call")); | |
9208 | ||
9209 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9210 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9211 | dprintf_function, | |
9212 | dprintf_channel, | |
9213 | dprintf_args); | |
9214 | else | |
9215 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9216 | dprintf_function, | |
9217 | dprintf_args); | |
9218 | } | |
d3ce09f5 SS |
9219 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9220 | { | |
9221 | if (target_can_run_breakpoint_commands ()) | |
9222 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9223 | else | |
9224 | { | |
9225 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9226 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9227 | } | |
9228 | } | |
e7e0cddf SS |
9229 | else |
9230 | internal_error (__FILE__, __LINE__, | |
9231 | _("Invalid dprintf style.")); | |
9232 | ||
f28045c2 | 9233 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9234 | /* Manufacture a printf sequence. */ |
f28045c2 | 9235 | { |
8d749320 | 9236 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9237 | |
f28045c2 YQ |
9238 | printf_cmd_line->control_type = simple_control; |
9239 | printf_cmd_line->body_count = 0; | |
9240 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9241 | printf_cmd_line->next = NULL; |
f28045c2 | 9242 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9243 | |
f28045c2 YQ |
9244 | breakpoint_set_commands (b, printf_cmd_line); |
9245 | } | |
e7e0cddf SS |
9246 | } |
9247 | ||
9248 | /* Update all dprintf commands, making their command lists reflect | |
9249 | current style settings. */ | |
9250 | ||
9251 | static void | |
9252 | update_dprintf_commands (char *args, int from_tty, | |
9253 | struct cmd_list_element *c) | |
9254 | { | |
9255 | struct breakpoint *b; | |
9256 | ||
9257 | ALL_BREAKPOINTS (b) | |
9258 | { | |
9259 | if (b->type == bp_dprintf) | |
9260 | update_dprintf_command_list (b); | |
9261 | } | |
9262 | } | |
c3f6f71d | 9263 | |
f00aae0f KS |
9264 | /* Create a breakpoint with SAL as location. Use LOCATION |
9265 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9266 | as condition expression. If LOCATION is NULL then create an |
9267 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9268 | |
9269 | static void | |
d9b3f62e | 9270 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9271 | struct symtabs_and_lines sals, |
9272 | struct event_location *location, | |
f8eba3c6 | 9273 | char *filter, char *cond_string, |
e7e0cddf | 9274 | char *extra_string, |
d9b3f62e PA |
9275 | enum bptype type, enum bpdisp disposition, |
9276 | int thread, int task, int ignore_count, | |
c0a91b2b | 9277 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9278 | int enabled, int internal, unsigned flags, |
9279 | int display_canonical) | |
018d34a4 | 9280 | { |
0d381245 | 9281 | int i; |
018d34a4 VP |
9282 | |
9283 | if (type == bp_hardware_breakpoint) | |
9284 | { | |
fbbd034e AS |
9285 | int target_resources_ok; |
9286 | ||
9287 | i = hw_breakpoint_used_count (); | |
9288 | target_resources_ok = | |
9289 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9290 | i + 1, 0); |
9291 | if (target_resources_ok == 0) | |
9292 | error (_("No hardware breakpoint support in the target.")); | |
9293 | else if (target_resources_ok < 0) | |
9294 | error (_("Hardware breakpoints used exceeds limit.")); | |
9295 | } | |
9296 | ||
6c95b8df PA |
9297 | gdb_assert (sals.nelts > 0); |
9298 | ||
0d381245 VP |
9299 | for (i = 0; i < sals.nelts; ++i) |
9300 | { | |
9301 | struct symtab_and_line sal = sals.sals[i]; | |
9302 | struct bp_location *loc; | |
9303 | ||
9304 | if (from_tty) | |
5af949e3 UW |
9305 | { |
9306 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9307 | if (!loc_gdbarch) | |
9308 | loc_gdbarch = gdbarch; | |
9309 | ||
9310 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9311 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9312 | } |
0d381245 VP |
9313 | |
9314 | if (i == 0) | |
9315 | { | |
d9b3f62e | 9316 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9317 | b->thread = thread; |
4a306c9a | 9318 | b->task = task; |
855a6e68 | 9319 | |
0d381245 | 9320 | b->cond_string = cond_string; |
e7e0cddf | 9321 | b->extra_string = extra_string; |
0d381245 | 9322 | b->ignore_count = ignore_count; |
41447f92 | 9323 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9324 | b->disposition = disposition; |
6c95b8df | 9325 | |
44f238bb PA |
9326 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9327 | b->loc->inserted = 1; | |
9328 | ||
0fb4aa4b PA |
9329 | if (type == bp_static_tracepoint) |
9330 | { | |
d9b3f62e | 9331 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9332 | struct static_tracepoint_marker marker; |
9333 | ||
983af33b | 9334 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9335 | { |
9336 | /* We already know the marker exists, otherwise, we | |
9337 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9338 | const char *p = &event_location_to_string (b->location)[3]; |
9339 | const char *endp; | |
0fb4aa4b | 9340 | char *marker_str; |
0fb4aa4b | 9341 | |
f00aae0f | 9342 | p = skip_spaces_const (p); |
0fb4aa4b | 9343 | |
f00aae0f | 9344 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9345 | |
9346 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9347 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9348 | |
3e43a32a MS |
9349 | printf_filtered (_("Probed static tracepoint " |
9350 | "marker \"%s\"\n"), | |
d9b3f62e | 9351 | t->static_trace_marker_id); |
0fb4aa4b PA |
9352 | } |
9353 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9354 | { | |
d9b3f62e | 9355 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9356 | release_static_tracepoint_marker (&marker); |
9357 | ||
3e43a32a MS |
9358 | printf_filtered (_("Probed static tracepoint " |
9359 | "marker \"%s\"\n"), | |
d9b3f62e | 9360 | t->static_trace_marker_id); |
0fb4aa4b PA |
9361 | } |
9362 | else | |
3e43a32a MS |
9363 | warning (_("Couldn't determine the static " |
9364 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9365 | } |
9366 | ||
0d381245 VP |
9367 | loc = b->loc; |
9368 | } | |
9369 | else | |
018d34a4 | 9370 | { |
39d61571 | 9371 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9372 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9373 | loc->inserted = 1; | |
0d381245 VP |
9374 | } |
9375 | ||
9376 | if (b->cond_string) | |
9377 | { | |
bbc13ae3 KS |
9378 | const char *arg = b->cond_string; |
9379 | ||
1bb9788d TT |
9380 | loc->cond = parse_exp_1 (&arg, loc->address, |
9381 | block_for_pc (loc->address), 0); | |
0d381245 | 9382 | if (*arg) |
588ae58c | 9383 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9384 | } |
e7e0cddf SS |
9385 | |
9386 | /* Dynamic printf requires and uses additional arguments on the | |
9387 | command line, otherwise it's an error. */ | |
9388 | if (type == bp_dprintf) | |
9389 | { | |
9390 | if (b->extra_string) | |
9391 | update_dprintf_command_list (b); | |
9392 | else | |
9393 | error (_("Format string required")); | |
9394 | } | |
9395 | else if (b->extra_string) | |
588ae58c | 9396 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9397 | } |
018d34a4 | 9398 | |
56435ebe | 9399 | b->display_canonical = display_canonical; |
f00aae0f KS |
9400 | if (location != NULL) |
9401 | b->location = location; | |
018d34a4 | 9402 | else |
305e13e6 JB |
9403 | { |
9404 | const char *addr_string = NULL; | |
9405 | int addr_string_len = 0; | |
9406 | ||
9407 | if (location != NULL) | |
9408 | addr_string = event_location_to_string (location); | |
9409 | if (addr_string != NULL) | |
9410 | addr_string_len = strlen (addr_string); | |
9411 | ||
9412 | b->location = new_address_location (b->loc->address, | |
9413 | addr_string, addr_string_len); | |
9414 | } | |
f8eba3c6 | 9415 | b->filter = filter; |
d9b3f62e | 9416 | } |
018d34a4 | 9417 | |
d9b3f62e PA |
9418 | static void |
9419 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9420 | struct symtabs_and_lines sals, |
9421 | struct event_location *location, | |
f8eba3c6 | 9422 | char *filter, char *cond_string, |
e7e0cddf | 9423 | char *extra_string, |
d9b3f62e PA |
9424 | enum bptype type, enum bpdisp disposition, |
9425 | int thread, int task, int ignore_count, | |
c0a91b2b | 9426 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9427 | int enabled, int internal, unsigned flags, |
9428 | int display_canonical) | |
d9b3f62e PA |
9429 | { |
9430 | struct breakpoint *b; | |
9431 | struct cleanup *old_chain; | |
9432 | ||
9433 | if (is_tracepoint_type (type)) | |
9434 | { | |
9435 | struct tracepoint *t; | |
9436 | ||
9437 | t = XCNEW (struct tracepoint); | |
9438 | b = &t->base; | |
9439 | } | |
9440 | else | |
9441 | b = XNEW (struct breakpoint); | |
9442 | ||
9443 | old_chain = make_cleanup (xfree, b); | |
9444 | ||
9445 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9446 | sals, location, |
e7e0cddf | 9447 | filter, cond_string, extra_string, |
d9b3f62e PA |
9448 | type, disposition, |
9449 | thread, task, ignore_count, | |
9450 | ops, from_tty, | |
44f238bb PA |
9451 | enabled, internal, flags, |
9452 | display_canonical); | |
d9b3f62e PA |
9453 | discard_cleanups (old_chain); |
9454 | ||
3ea46bff | 9455 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9456 | } |
9457 | ||
9458 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9459 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9460 | value. COND_STRING, if not NULL, specified the condition to be | |
9461 | used for all breakpoints. Essentially the only case where | |
9462 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9463 | function. In that case, it's still not possible to specify | |
9464 | separate conditions for different overloaded functions, so | |
9465 | we take just a single condition string. | |
9466 | ||
c3f6f71d | 9467 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9468 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9469 | array contents). If the function fails (error() is called), the |
9470 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9471 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9472 | |
9473 | static void | |
8cdf0e15 | 9474 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9475 | struct linespec_result *canonical, |
e7e0cddf | 9476 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9477 | enum bptype type, enum bpdisp disposition, |
9478 | int thread, int task, int ignore_count, | |
c0a91b2b | 9479 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9480 | int enabled, int internal, unsigned flags) |
c906108c | 9481 | { |
018d34a4 | 9482 | int i; |
f8eba3c6 | 9483 | struct linespec_sals *lsal; |
cc59ec59 | 9484 | |
f8eba3c6 TT |
9485 | if (canonical->pre_expanded) |
9486 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9487 | ||
9488 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9489 | { |
f00aae0f | 9490 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9491 | 'break', without arguments. */ |
f00aae0f KS |
9492 | struct event_location *location |
9493 | = (canonical->location != NULL | |
9494 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9495 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9496 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9497 | |
f8eba3c6 TT |
9498 | make_cleanup (xfree, filter_string); |
9499 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9500 | location, |
f8eba3c6 | 9501 | filter_string, |
e7e0cddf SS |
9502 | cond_string, extra_string, |
9503 | type, disposition, | |
84f4c1fe | 9504 | thread, task, ignore_count, ops, |
44f238bb | 9505 | from_tty, enabled, internal, flags, |
56435ebe | 9506 | canonical->special_display); |
f8eba3c6 | 9507 | discard_cleanups (inner); |
c3f6f71d | 9508 | } |
c3f6f71d | 9509 | } |
c906108c | 9510 | |
f00aae0f | 9511 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9512 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9513 | addresses found. LOCATION points to the end of the SAL (for |
9514 | linespec locations). | |
9998af43 TJB |
9515 | |
9516 | The array and the line spec strings are allocated on the heap, it is | |
9517 | the caller's responsibility to free them. */ | |
c906108c | 9518 | |
b9362cc7 | 9519 | static void |
f00aae0f | 9520 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9521 | struct linespec_result *canonical) |
c3f6f71d | 9522 | { |
f00aae0f KS |
9523 | struct symtab_and_line cursal; |
9524 | ||
9525 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9526 | { | |
9527 | const char *address = get_linespec_location (location); | |
9528 | ||
9529 | if (address == NULL) | |
9530 | { | |
9531 | /* The last displayed codepoint, if it's valid, is our default | |
9532 | breakpoint address. */ | |
9533 | if (last_displayed_sal_is_valid ()) | |
9534 | { | |
9535 | struct linespec_sals lsal; | |
9536 | struct symtab_and_line sal; | |
9537 | CORE_ADDR pc; | |
9538 | ||
9539 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9540 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9541 | |
9542 | /* Set sal's pspace, pc, symtab, and line to the values | |
9543 | corresponding to the last call to print_frame_info. | |
9544 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9545 | as the breakpoint line number is inappropriate otherwise. | |
9546 | find_pc_line would adjust PC, re-set it back. */ | |
9547 | get_last_displayed_sal (&sal); | |
9548 | pc = sal.pc; | |
9549 | sal = find_pc_line (pc, 0); | |
9550 | ||
9551 | /* "break" without arguments is equivalent to "break *PC" | |
9552 | where PC is the last displayed codepoint's address. So | |
9553 | make sure to set sal.explicit_pc to prevent GDB from | |
9554 | trying to expand the list of sals to include all other | |
9555 | instances with the same symtab and line. */ | |
9556 | sal.pc = pc; | |
9557 | sal.explicit_pc = 1; | |
9558 | ||
9559 | lsal.sals.sals[0] = sal; | |
9560 | lsal.sals.nelts = 1; | |
9561 | lsal.canonical = NULL; | |
9562 | ||
9563 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9564 | return; | |
9565 | } | |
9566 | else | |
9567 | error (_("No default breakpoint address now.")); | |
c906108c | 9568 | } |
c906108c | 9569 | } |
f00aae0f KS |
9570 | |
9571 | /* Force almost all breakpoints to be in terms of the | |
9572 | current_source_symtab (which is decode_line_1's default). | |
9573 | This should produce the results we want almost all of the | |
9574 | time while leaving default_breakpoint_* alone. | |
9575 | ||
9576 | ObjC: However, don't match an Objective-C method name which | |
9577 | may have a '+' or '-' succeeded by a '['. */ | |
9578 | cursal = get_current_source_symtab_and_line (); | |
9579 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9580 | { |
f00aae0f | 9581 | const char *address = NULL; |
cc80f267 | 9582 | |
f00aae0f KS |
9583 | if (event_location_type (location) == LINESPEC_LOCATION) |
9584 | address = get_linespec_location (location); | |
cc80f267 | 9585 | |
f00aae0f KS |
9586 | if (!cursal.symtab |
9587 | || (address != NULL | |
9588 | && strchr ("+-", address[0]) != NULL | |
9589 | && address[1] != '[')) | |
9590 | { | |
c2f4122d | 9591 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9592 | get_last_displayed_symtab (), |
9593 | get_last_displayed_line (), | |
9594 | canonical, NULL, NULL); | |
9595 | return; | |
9596 | } | |
c906108c | 9597 | } |
f00aae0f | 9598 | |
c2f4122d | 9599 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9600 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9601 | } |
c906108c | 9602 | |
c906108c | 9603 | |
c3f6f71d | 9604 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9605 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9606 | |
b9362cc7 | 9607 | static void |
23e7acfb | 9608 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9609 | { |
9610 | int i; | |
cc59ec59 | 9611 | |
c3f6f71d | 9612 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9613 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9614 | } |
9615 | ||
7a697b8d SS |
9616 | /* Fast tracepoints may have restrictions on valid locations. For |
9617 | instance, a fast tracepoint using a jump instead of a trap will | |
9618 | likely have to overwrite more bytes than a trap would, and so can | |
9619 | only be placed where the instruction is longer than the jump, or a | |
9620 | multi-instruction sequence does not have a jump into the middle of | |
9621 | it, etc. */ | |
9622 | ||
9623 | static void | |
9624 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9625 | struct symtabs_and_lines *sals) | |
9626 | { | |
9627 | int i, rslt; | |
9628 | struct symtab_and_line *sal; | |
9629 | char *msg; | |
9630 | struct cleanup *old_chain; | |
9631 | ||
9632 | for (i = 0; i < sals->nelts; i++) | |
9633 | { | |
f8eba3c6 TT |
9634 | struct gdbarch *sarch; |
9635 | ||
7a697b8d SS |
9636 | sal = &sals->sals[i]; |
9637 | ||
f8eba3c6 TT |
9638 | sarch = get_sal_arch (*sal); |
9639 | /* We fall back to GDBARCH if there is no architecture | |
9640 | associated with SAL. */ | |
9641 | if (sarch == NULL) | |
9642 | sarch = gdbarch; | |
6b940e6a | 9643 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9644 | old_chain = make_cleanup (xfree, msg); |
9645 | ||
9646 | if (!rslt) | |
53c3572a | 9647 | error (_("May not have a fast tracepoint at %s%s"), |
f8eba3c6 | 9648 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9649 | |
9650 | do_cleanups (old_chain); | |
9651 | } | |
9652 | } | |
9653 | ||
018d34a4 VP |
9654 | /* Given TOK, a string specification of condition and thread, as |
9655 | accepted by the 'break' command, extract the condition | |
9656 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9657 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9658 | If no condition is found, *COND_STRING is set to NULL. |
9659 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9660 | |
9661 | static void | |
bbc13ae3 | 9662 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9663 | char **cond_string, int *thread, int *task, |
9664 | char **rest) | |
018d34a4 VP |
9665 | { |
9666 | *cond_string = NULL; | |
9667 | *thread = -1; | |
ed1d1739 KS |
9668 | *task = 0; |
9669 | *rest = NULL; | |
9670 | ||
018d34a4 VP |
9671 | while (tok && *tok) |
9672 | { | |
bbc13ae3 | 9673 | const char *end_tok; |
018d34a4 | 9674 | int toklen; |
bbc13ae3 KS |
9675 | const char *cond_start = NULL; |
9676 | const char *cond_end = NULL; | |
cc59ec59 | 9677 | |
bbc13ae3 | 9678 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9679 | |
9680 | if ((*tok == '"' || *tok == ',') && rest) | |
9681 | { | |
9682 | *rest = savestring (tok, strlen (tok)); | |
9683 | return; | |
9684 | } | |
9685 | ||
bbc13ae3 | 9686 | end_tok = skip_to_space_const (tok); |
d634f2de | 9687 | |
018d34a4 | 9688 | toklen = end_tok - tok; |
d634f2de | 9689 | |
018d34a4 VP |
9690 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9691 | { | |
f7545552 TT |
9692 | struct expression *expr; |
9693 | ||
018d34a4 | 9694 | tok = cond_start = end_tok + 1; |
1bb9788d | 9695 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9696 | xfree (expr); |
018d34a4 | 9697 | cond_end = tok; |
d634f2de | 9698 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9699 | } |
9700 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9701 | { | |
5d5658a1 PA |
9702 | const char *tmptok; |
9703 | struct thread_info *thr; | |
d634f2de | 9704 | |
018d34a4 | 9705 | tok = end_tok + 1; |
5d5658a1 | 9706 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9707 | if (tok == tmptok) |
9708 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9709 | *thread = thr->global_num; |
bbc13ae3 | 9710 | tok = tmptok; |
018d34a4 | 9711 | } |
4a306c9a JB |
9712 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9713 | { | |
9714 | char *tmptok; | |
9715 | ||
9716 | tok = end_tok + 1; | |
bbc13ae3 | 9717 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9718 | if (tok == tmptok) |
9719 | error (_("Junk after task keyword.")); | |
9720 | if (!valid_task_id (*task)) | |
b6199126 | 9721 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9722 | tok = tmptok; |
4a306c9a | 9723 | } |
e7e0cddf SS |
9724 | else if (rest) |
9725 | { | |
9726 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9727 | return; |
e7e0cddf | 9728 | } |
018d34a4 VP |
9729 | else |
9730 | error (_("Junk at end of arguments.")); | |
9731 | } | |
9732 | } | |
9733 | ||
0fb4aa4b PA |
9734 | /* Decode a static tracepoint marker spec. */ |
9735 | ||
9736 | static struct symtabs_and_lines | |
f00aae0f | 9737 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9738 | { |
9739 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9740 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9741 | struct cleanup *old_chain; |
f00aae0f KS |
9742 | const char *p = &(*arg_p)[3]; |
9743 | const char *endp; | |
0fb4aa4b PA |
9744 | char *marker_str; |
9745 | int i; | |
9746 | ||
f00aae0f | 9747 | p = skip_spaces_const (p); |
0fb4aa4b | 9748 | |
f00aae0f | 9749 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9750 | |
9751 | marker_str = savestring (p, endp - p); | |
9752 | old_chain = make_cleanup (xfree, marker_str); | |
9753 | ||
9754 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9755 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9756 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9757 | ||
9758 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9759 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9760 | |
9761 | for (i = 0; i < sals.nelts; i++) | |
9762 | { | |
9763 | struct static_tracepoint_marker *marker; | |
9764 | ||
9765 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9766 | ||
9767 | init_sal (&sals.sals[i]); | |
9768 | ||
9769 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9770 | sals.sals[i].pc = marker->address; | |
9771 | ||
9772 | release_static_tracepoint_marker (marker); | |
9773 | } | |
9774 | ||
9775 | do_cleanups (old_chain); | |
9776 | ||
9777 | *arg_p = endp; | |
9778 | return sals; | |
9779 | } | |
9780 | ||
f00aae0f | 9781 | /* See breakpoint.h. */ |
0101ce28 | 9782 | |
8cdf0e15 VP |
9783 | int |
9784 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9785 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9786 | int thread, char *extra_string, |
f00aae0f | 9787 | int parse_extra, |
0fb4aa4b | 9788 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9789 | int ignore_count, |
9790 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9791 | const struct breakpoint_ops *ops, |
44f238bb PA |
9792 | int from_tty, int enabled, int internal, |
9793 | unsigned flags) | |
c3f6f71d | 9794 | { |
7efd8fc2 | 9795 | struct linespec_result canonical; |
c3f6f71d | 9796 | struct cleanup *old_chain; |
80c99de1 | 9797 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9798 | int pending = 0; |
4a306c9a | 9799 | int task = 0; |
86b17b60 | 9800 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9801 | |
348d480f PA |
9802 | gdb_assert (ops != NULL); |
9803 | ||
f00aae0f KS |
9804 | /* If extra_string isn't useful, set it to NULL. */ |
9805 | if (extra_string != NULL && *extra_string == '\0') | |
9806 | extra_string = NULL; | |
9807 | ||
7efd8fc2 | 9808 | init_linespec_result (&canonical); |
c3f6f71d | 9809 | |
492d29ea | 9810 | TRY |
b78a6381 | 9811 | { |
f00aae0f | 9812 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9813 | } |
492d29ea | 9814 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9815 | { |
492d29ea PA |
9816 | /* If caller is interested in rc value from parse, set |
9817 | value. */ | |
9818 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9819 | { |
05ff989b AC |
9820 | /* If pending breakpoint support is turned off, throw |
9821 | error. */ | |
fa8d40ab JJ |
9822 | |
9823 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9824 | throw_exception (e); |
9825 | ||
9826 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9827 | |
05ff989b AC |
9828 | /* If pending breakpoint support is auto query and the user |
9829 | selects no, then simply return the error code. */ | |
059fb39f | 9830 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9831 | && !nquery (_("Make %s pending on future shared library load? "), |
9832 | bptype_string (type_wanted))) | |
fd9b8c24 | 9833 | return 0; |
fa8d40ab | 9834 | |
05ff989b AC |
9835 | /* At this point, either the user was queried about setting |
9836 | a pending breakpoint and selected yes, or pending | |
9837 | breakpoint behavior is on and thus a pending breakpoint | |
9838 | is defaulted on behalf of the user. */ | |
f00aae0f | 9839 | pending = 1; |
0101ce28 | 9840 | } |
492d29ea PA |
9841 | else |
9842 | throw_exception (e); | |
0101ce28 | 9843 | } |
492d29ea PA |
9844 | END_CATCH |
9845 | ||
f00aae0f | 9846 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9847 | return 0; |
c3f6f71d | 9848 | |
4a64f543 | 9849 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9850 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9851 | |
c3f6f71d JM |
9852 | /* ----------------------------- SNIP ----------------------------- |
9853 | Anything added to the cleanup chain beyond this point is assumed | |
9854 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9855 | then the memory is not reclaimed. */ |
9856 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9857 | |
c3f6f71d JM |
9858 | /* Resolve all line numbers to PC's and verify that the addresses |
9859 | are ok for the target. */ | |
0101ce28 | 9860 | if (!pending) |
f8eba3c6 TT |
9861 | { |
9862 | int ix; | |
9863 | struct linespec_sals *iter; | |
9864 | ||
9865 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9866 | breakpoint_sals_to_pc (&iter->sals); | |
9867 | } | |
c3f6f71d | 9868 | |
7a697b8d | 9869 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9870 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9871 | { |
9872 | int ix; | |
9873 | struct linespec_sals *iter; | |
9874 | ||
9875 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9876 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9877 | } | |
7a697b8d | 9878 | |
c3f6f71d JM |
9879 | /* Verify that condition can be parsed, before setting any |
9880 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9881 | breakpoint. */ |
0101ce28 | 9882 | if (!pending) |
c3f6f71d | 9883 | { |
f00aae0f | 9884 | if (parse_extra) |
72b2ff0e | 9885 | { |
0878d0fa | 9886 | char *rest; |
52d361e1 YQ |
9887 | struct linespec_sals *lsal; |
9888 | ||
9889 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9890 | ||
0878d0fa YQ |
9891 | /* Here we only parse 'arg' to separate condition |
9892 | from thread number, so parsing in context of first | |
9893 | sal is OK. When setting the breakpoint we'll | |
9894 | re-parse it in context of each sal. */ | |
9895 | ||
f00aae0f KS |
9896 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9897 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9898 | if (cond_string) |
9899 | make_cleanup (xfree, cond_string); | |
9900 | if (rest) | |
9901 | make_cleanup (xfree, rest); | |
9902 | if (rest) | |
9903 | extra_string = rest; | |
f00aae0f KS |
9904 | else |
9905 | extra_string = NULL; | |
72b2ff0e | 9906 | } |
2f069f6f | 9907 | else |
72b2ff0e | 9908 | { |
f00aae0f KS |
9909 | if (type_wanted != bp_dprintf |
9910 | && extra_string != NULL && *extra_string != '\0') | |
9911 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9912 | |
9913 | /* Create a private copy of condition string. */ | |
9914 | if (cond_string) | |
9915 | { | |
9916 | cond_string = xstrdup (cond_string); | |
9917 | make_cleanup (xfree, cond_string); | |
9918 | } | |
9919 | /* Create a private copy of any extra string. */ | |
9920 | if (extra_string) | |
9921 | { | |
9922 | extra_string = xstrdup (extra_string); | |
9923 | make_cleanup (xfree, extra_string); | |
9924 | } | |
72b2ff0e | 9925 | } |
0fb4aa4b | 9926 | |
52d361e1 | 9927 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9928 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9929 | tempflag ? disp_del : disp_donttouch, |
9930 | thread, task, ignore_count, ops, | |
44f238bb | 9931 | from_tty, enabled, internal, flags); |
c906108c | 9932 | } |
0101ce28 JJ |
9933 | else |
9934 | { | |
0101ce28 JJ |
9935 | struct breakpoint *b; |
9936 | ||
bfccc43c YQ |
9937 | if (is_tracepoint_type (type_wanted)) |
9938 | { | |
9939 | struct tracepoint *t; | |
9940 | ||
9941 | t = XCNEW (struct tracepoint); | |
9942 | b = &t->base; | |
9943 | } | |
9944 | else | |
9945 | b = XNEW (struct breakpoint); | |
9946 | ||
9947 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9948 | b->location = copy_event_location (location); |
bfccc43c | 9949 | |
f00aae0f KS |
9950 | if (parse_extra) |
9951 | b->cond_string = NULL; | |
e12c7713 MK |
9952 | else |
9953 | { | |
9954 | /* Create a private copy of condition string. */ | |
9955 | if (cond_string) | |
9956 | { | |
9957 | cond_string = xstrdup (cond_string); | |
9958 | make_cleanup (xfree, cond_string); | |
9959 | } | |
9960 | b->cond_string = cond_string; | |
15630549 | 9961 | b->thread = thread; |
e12c7713 | 9962 | } |
f00aae0f KS |
9963 | |
9964 | /* Create a private copy of any extra string. */ | |
9965 | if (extra_string != NULL) | |
9966 | { | |
9967 | extra_string = xstrdup (extra_string); | |
9968 | make_cleanup (xfree, extra_string); | |
9969 | } | |
9970 | b->extra_string = extra_string; | |
0101ce28 | 9971 | b->ignore_count = ignore_count; |
0101ce28 | 9972 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9973 | b->condition_not_parsed = 1; |
41447f92 | 9974 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9975 | if ((type_wanted != bp_breakpoint |
9976 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9977 | b->pspace = current_program_space; |
8bea4e01 | 9978 | |
bfccc43c | 9979 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9980 | } |
9981 | ||
f8eba3c6 | 9982 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9983 | { |
3e43a32a MS |
9984 | warning (_("Multiple breakpoints were set.\nUse the " |
9985 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9986 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9987 | } |
9988 | ||
80c99de1 PA |
9989 | /* That's it. Discard the cleanups for data inserted into the |
9990 | breakpoint. */ | |
9991 | discard_cleanups (bkpt_chain); | |
9992 | /* But cleanup everything else. */ | |
c3f6f71d | 9993 | do_cleanups (old_chain); |
217dc9e2 | 9994 | |
80c99de1 | 9995 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9996 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9997 | |
9998 | return 1; | |
c3f6f71d | 9999 | } |
c906108c | 10000 | |
348d480f | 10001 | /* Set a breakpoint. |
72b2ff0e VP |
10002 | ARG is a string describing breakpoint address, |
10003 | condition, and thread. | |
10004 | FLAG specifies if a breakpoint is hardware on, | |
10005 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10006 | and BP_TEMPFLAG. */ | |
348d480f | 10007 | |
98deb0da | 10008 | static void |
72b2ff0e | 10009 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10010 | { |
72b2ff0e | 10011 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10012 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10013 | ? bp_hardware_breakpoint | |
10014 | : bp_breakpoint); | |
55aa24fb | 10015 | struct breakpoint_ops *ops; |
f00aae0f KS |
10016 | struct event_location *location; |
10017 | struct cleanup *cleanup; | |
10018 | ||
10019 | location = string_to_event_location (&arg, current_language); | |
10020 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
10021 | |
10022 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
10023 | if (location != NULL |
10024 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
10025 | ops = &bkpt_probe_breakpoint_ops; |
10026 | else | |
10027 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10028 | |
8cdf0e15 | 10029 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10030 | location, |
10031 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 10032 | tempflag, type_wanted, |
8cdf0e15 VP |
10033 | 0 /* Ignore count */, |
10034 | pending_break_support, | |
55aa24fb | 10035 | ops, |
8cdf0e15 | 10036 | from_tty, |
84f4c1fe | 10037 | 1 /* enabled */, |
44f238bb PA |
10038 | 0 /* internal */, |
10039 | 0); | |
f00aae0f | 10040 | do_cleanups (cleanup); |
c906108c SS |
10041 | } |
10042 | ||
c906108c SS |
10043 | /* Helper function for break_command_1 and disassemble_command. */ |
10044 | ||
10045 | void | |
fba45db2 | 10046 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10047 | { |
10048 | CORE_ADDR pc; | |
10049 | ||
10050 | if (sal->pc == 0 && sal->symtab != NULL) | |
10051 | { | |
10052 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10053 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10054 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10055 | sal->pc = pc; |
6a048695 | 10056 | |
4a64f543 MS |
10057 | /* If this SAL corresponds to a breakpoint inserted using a line |
10058 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10059 | if (sal->explicit_line) |
059acae7 | 10060 | skip_prologue_sal (sal); |
c906108c SS |
10061 | } |
10062 | ||
10063 | if (sal->section == 0 && sal->symtab != NULL) | |
10064 | { | |
346d1dfe | 10065 | const struct blockvector *bv; |
3977b71f | 10066 | const struct block *b; |
c5aa993b | 10067 | struct symbol *sym; |
c906108c | 10068 | |
43f3e411 DE |
10069 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10070 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10071 | if (bv != NULL) |
10072 | { | |
7f0df278 | 10073 | sym = block_linkage_function (b); |
c906108c SS |
10074 | if (sym != NULL) |
10075 | { | |
eb822aa6 DE |
10076 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10077 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10078 | sym); | |
c906108c SS |
10079 | } |
10080 | else | |
10081 | { | |
4a64f543 MS |
10082 | /* It really is worthwhile to have the section, so we'll |
10083 | just have to look harder. This case can be executed | |
10084 | if we have line numbers but no functions (as can | |
10085 | happen in assembly source). */ | |
c906108c | 10086 | |
7cbd4a93 | 10087 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10088 | struct cleanup *old_chain = save_current_space_and_thread (); |
10089 | ||
10090 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10091 | |
10092 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10093 | if (msym.minsym) |
efd66ac6 | 10094 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10095 | |
10096 | do_cleanups (old_chain); | |
c906108c SS |
10097 | } |
10098 | } | |
10099 | } | |
10100 | } | |
10101 | ||
10102 | void | |
fba45db2 | 10103 | break_command (char *arg, int from_tty) |
c906108c | 10104 | { |
db107f19 | 10105 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10106 | } |
10107 | ||
c906108c | 10108 | void |
fba45db2 | 10109 | tbreak_command (char *arg, int from_tty) |
c906108c | 10110 | { |
db107f19 | 10111 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10112 | } |
10113 | ||
c906108c | 10114 | static void |
fba45db2 | 10115 | hbreak_command (char *arg, int from_tty) |
c906108c | 10116 | { |
db107f19 | 10117 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10118 | } |
10119 | ||
10120 | static void | |
fba45db2 | 10121 | thbreak_command (char *arg, int from_tty) |
c906108c | 10122 | { |
db107f19 | 10123 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10124 | } |
10125 | ||
10126 | static void | |
fba45db2 | 10127 | stop_command (char *arg, int from_tty) |
c906108c | 10128 | { |
a3f17187 | 10129 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10130 | Usage: stop in <function | address>\n\ |
a3f17187 | 10131 | stop at <line>\n")); |
c906108c SS |
10132 | } |
10133 | ||
10134 | static void | |
fba45db2 | 10135 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10136 | { |
10137 | int badInput = 0; | |
10138 | ||
c5aa993b | 10139 | if (arg == (char *) NULL) |
c906108c SS |
10140 | badInput = 1; |
10141 | else if (*arg != '*') | |
10142 | { | |
10143 | char *argptr = arg; | |
10144 | int hasColon = 0; | |
10145 | ||
4a64f543 | 10146 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10147 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10148 | function/method name. */ |
c906108c | 10149 | while (*argptr && !hasColon) |
c5aa993b JM |
10150 | { |
10151 | hasColon = (*argptr == ':'); | |
10152 | argptr++; | |
10153 | } | |
c906108c SS |
10154 | |
10155 | if (hasColon) | |
c5aa993b | 10156 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10157 | else |
c5aa993b | 10158 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10159 | } |
10160 | ||
10161 | if (badInput) | |
a3f17187 | 10162 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10163 | else |
db107f19 | 10164 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10165 | } |
10166 | ||
10167 | static void | |
fba45db2 | 10168 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10169 | { |
10170 | int badInput = 0; | |
10171 | ||
c5aa993b | 10172 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10173 | badInput = 1; |
10174 | else | |
10175 | { | |
10176 | char *argptr = arg; | |
10177 | int hasColon = 0; | |
10178 | ||
4a64f543 MS |
10179 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10180 | it is probably a line number. */ | |
c906108c | 10181 | while (*argptr && !hasColon) |
c5aa993b JM |
10182 | { |
10183 | hasColon = (*argptr == ':'); | |
10184 | argptr++; | |
10185 | } | |
c906108c SS |
10186 | |
10187 | if (hasColon) | |
c5aa993b | 10188 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10189 | else |
c5aa993b | 10190 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10191 | } |
10192 | ||
10193 | if (badInput) | |
a3f17187 | 10194 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10195 | else |
db107f19 | 10196 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10197 | } |
10198 | ||
e7e0cddf SS |
10199 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10200 | with a prewired command list consisting of a single output command, | |
10201 | built from extra arguments supplied on the dprintf command | |
10202 | line. */ | |
10203 | ||
da821c7b | 10204 | static void |
e7e0cddf SS |
10205 | dprintf_command (char *arg, int from_tty) |
10206 | { | |
f00aae0f KS |
10207 | struct event_location *location; |
10208 | struct cleanup *cleanup; | |
10209 | ||
10210 | location = string_to_event_location (&arg, current_language); | |
10211 | cleanup = make_cleanup_delete_event_location (location); | |
10212 | ||
10213 | /* If non-NULL, ARG should have been advanced past the location; | |
10214 | the next character must be ','. */ | |
10215 | if (arg != NULL) | |
10216 | { | |
10217 | if (arg[0] != ',' || arg[1] == '\0') | |
10218 | error (_("Format string required")); | |
10219 | else | |
10220 | { | |
10221 | /* Skip the comma. */ | |
10222 | ++arg; | |
10223 | } | |
10224 | } | |
10225 | ||
e7e0cddf | 10226 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10227 | location, |
10228 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10229 | 0, bp_dprintf, |
10230 | 0 /* Ignore count */, | |
10231 | pending_break_support, | |
10232 | &dprintf_breakpoint_ops, | |
10233 | from_tty, | |
10234 | 1 /* enabled */, | |
10235 | 0 /* internal */, | |
10236 | 0); | |
f00aae0f | 10237 | do_cleanups (cleanup); |
e7e0cddf SS |
10238 | } |
10239 | ||
d3ce09f5 SS |
10240 | static void |
10241 | agent_printf_command (char *arg, int from_tty) | |
10242 | { | |
10243 | error (_("May only run agent-printf on the target")); | |
10244 | } | |
10245 | ||
f1310107 TJB |
10246 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10247 | ranged breakpoints. */ | |
10248 | ||
10249 | static int | |
10250 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10251 | struct address_space *aspace, | |
09ac7c10 TT |
10252 | CORE_ADDR bp_addr, |
10253 | const struct target_waitstatus *ws) | |
f1310107 | 10254 | { |
09ac7c10 | 10255 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10256 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10257 | return 0; |
10258 | ||
f1310107 TJB |
10259 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10260 | bl->length, aspace, bp_addr); | |
10261 | } | |
10262 | ||
10263 | /* Implement the "resources_needed" breakpoint_ops method for | |
10264 | ranged breakpoints. */ | |
10265 | ||
10266 | static int | |
10267 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10268 | { | |
10269 | return target_ranged_break_num_registers (); | |
10270 | } | |
10271 | ||
10272 | /* Implement the "print_it" breakpoint_ops method for | |
10273 | ranged breakpoints. */ | |
10274 | ||
10275 | static enum print_stop_action | |
348d480f | 10276 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10277 | { |
348d480f | 10278 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10279 | struct bp_location *bl = b->loc; |
79a45e25 | 10280 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10281 | |
10282 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10283 | ||
10284 | /* Ranged breakpoints have only one location. */ | |
10285 | gdb_assert (bl && bl->next == NULL); | |
10286 | ||
10287 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10288 | |
10289 | maybe_print_thread_hit_breakpoint (uiout); | |
10290 | ||
f1310107 | 10291 | if (b->disposition == disp_del) |
f303dbd6 | 10292 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10293 | else |
f303dbd6 | 10294 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10295 | if (ui_out_is_mi_like_p (uiout)) |
10296 | { | |
10297 | ui_out_field_string (uiout, "reason", | |
10298 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10299 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10300 | } | |
10301 | ui_out_field_int (uiout, "bkptno", b->number); | |
10302 | ui_out_text (uiout, ", "); | |
10303 | ||
10304 | return PRINT_SRC_AND_LOC; | |
10305 | } | |
10306 | ||
10307 | /* Implement the "print_one" breakpoint_ops method for | |
10308 | ranged breakpoints. */ | |
10309 | ||
10310 | static void | |
10311 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10312 | struct bp_location **last_loc) | |
10313 | { | |
10314 | struct bp_location *bl = b->loc; | |
10315 | struct value_print_options opts; | |
79a45e25 | 10316 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10317 | |
10318 | /* Ranged breakpoints have only one location. */ | |
10319 | gdb_assert (bl && bl->next == NULL); | |
10320 | ||
10321 | get_user_print_options (&opts); | |
10322 | ||
10323 | if (opts.addressprint) | |
10324 | /* We don't print the address range here, it will be printed later | |
10325 | by print_one_detail_ranged_breakpoint. */ | |
10326 | ui_out_field_skip (uiout, "addr"); | |
10327 | annotate_field (5); | |
10328 | print_breakpoint_location (b, bl); | |
10329 | *last_loc = bl; | |
10330 | } | |
10331 | ||
10332 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10333 | ranged breakpoints. */ | |
10334 | ||
10335 | static void | |
10336 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10337 | struct ui_out *uiout) | |
10338 | { | |
10339 | CORE_ADDR address_start, address_end; | |
10340 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10341 | struct ui_file *stb = mem_fileopen (); |
10342 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10343 | |
10344 | gdb_assert (bl); | |
10345 | ||
10346 | address_start = bl->address; | |
10347 | address_end = address_start + bl->length - 1; | |
10348 | ||
10349 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10350 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10351 | print_core_address (bl->gdbarch, address_start), |
10352 | print_core_address (bl->gdbarch, address_end)); | |
10353 | ui_out_field_stream (uiout, "addr", stb); | |
10354 | ui_out_text (uiout, "\n"); | |
10355 | ||
10356 | do_cleanups (cleanup); | |
10357 | } | |
10358 | ||
10359 | /* Implement the "print_mention" breakpoint_ops method for | |
10360 | ranged breakpoints. */ | |
10361 | ||
10362 | static void | |
10363 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10364 | { | |
10365 | struct bp_location *bl = b->loc; | |
79a45e25 | 10366 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10367 | |
10368 | gdb_assert (bl); | |
10369 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10370 | ||
10371 | if (ui_out_is_mi_like_p (uiout)) | |
10372 | return; | |
10373 | ||
10374 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10375 | b->number, paddress (bl->gdbarch, bl->address), | |
10376 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10377 | } | |
10378 | ||
10379 | /* Implement the "print_recreate" breakpoint_ops method for | |
10380 | ranged breakpoints. */ | |
10381 | ||
10382 | static void | |
10383 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10384 | { | |
f00aae0f KS |
10385 | fprintf_unfiltered (fp, "break-range %s, %s", |
10386 | event_location_to_string (b->location), | |
10387 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10388 | print_recreate_thread (b, fp); |
f1310107 TJB |
10389 | } |
10390 | ||
10391 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10392 | ||
2060206e | 10393 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10394 | |
10395 | /* Find the address where the end of the breakpoint range should be | |
10396 | placed, given the SAL of the end of the range. This is so that if | |
10397 | the user provides a line number, the end of the range is set to the | |
10398 | last instruction of the given line. */ | |
10399 | ||
10400 | static CORE_ADDR | |
10401 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10402 | { | |
10403 | CORE_ADDR end; | |
10404 | ||
10405 | /* If the user provided a PC value, use it. Otherwise, | |
10406 | find the address of the end of the given location. */ | |
10407 | if (sal.explicit_pc) | |
10408 | end = sal.pc; | |
10409 | else | |
10410 | { | |
10411 | int ret; | |
10412 | CORE_ADDR start; | |
10413 | ||
10414 | ret = find_line_pc_range (sal, &start, &end); | |
10415 | if (!ret) | |
10416 | error (_("Could not find location of the end of the range.")); | |
10417 | ||
10418 | /* find_line_pc_range returns the start of the next line. */ | |
10419 | end--; | |
10420 | } | |
10421 | ||
10422 | return end; | |
10423 | } | |
10424 | ||
10425 | /* Implement the "break-range" CLI command. */ | |
10426 | ||
10427 | static void | |
10428 | break_range_command (char *arg, int from_tty) | |
10429 | { | |
870f88f7 | 10430 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10431 | struct linespec_result canonical_start, canonical_end; |
10432 | int bp_count, can_use_bp, length; | |
10433 | CORE_ADDR end; | |
10434 | struct breakpoint *b; | |
10435 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10436 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10437 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10438 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10439 | |
10440 | /* We don't support software ranged breakpoints. */ | |
10441 | if (target_ranged_break_num_registers () < 0) | |
10442 | error (_("This target does not support hardware ranged breakpoints.")); | |
10443 | ||
10444 | bp_count = hw_breakpoint_used_count (); | |
10445 | bp_count += target_ranged_break_num_registers (); | |
10446 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10447 | bp_count, 0); | |
10448 | if (can_use_bp < 0) | |
10449 | error (_("Hardware breakpoints used exceeds limit.")); | |
10450 | ||
f8eba3c6 | 10451 | arg = skip_spaces (arg); |
f1310107 TJB |
10452 | if (arg == NULL || arg[0] == '\0') |
10453 | error(_("No address range specified.")); | |
10454 | ||
f1310107 TJB |
10455 | init_linespec_result (&canonical_start); |
10456 | ||
f8eba3c6 | 10457 | arg_start = arg; |
f00aae0f KS |
10458 | start_location = string_to_event_location (&arg, current_language); |
10459 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10460 | parse_breakpoint_sals (start_location, &canonical_start); | |
10461 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10462 | |
10463 | if (arg[0] != ',') | |
10464 | error (_("Too few arguments.")); | |
f8eba3c6 | 10465 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10466 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10467 | |
10468 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10469 | ||
10470 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10471 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10472 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10473 | ||
f8eba3c6 TT |
10474 | sal_start = lsal_start->sals.sals[0]; |
10475 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10476 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10477 | |
10478 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10479 | arg = skip_spaces (arg); |
f1310107 TJB |
10480 | |
10481 | /* Parse the end location. */ | |
10482 | ||
f1310107 TJB |
10483 | init_linespec_result (&canonical_end); |
10484 | arg_start = arg; | |
10485 | ||
f8eba3c6 | 10486 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10487 | parse_breakpoint_sals because we need to specify the start location's |
10488 | symtab and line as the default symtab and line for the end of the | |
10489 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10490 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10491 | end_location = string_to_event_location (&arg, current_language); |
10492 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10493 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10494 | sal_start.symtab, sal_start.line, |
10495 | &canonical_end, NULL, NULL); | |
10496 | ||
10497 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10498 | |
f8eba3c6 | 10499 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10500 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10501 | |
10502 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10503 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10504 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10505 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10506 | ||
f8eba3c6 | 10507 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10508 | |
10509 | end = find_breakpoint_range_end (sal_end); | |
10510 | if (sal_start.pc > end) | |
177b42fe | 10511 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10512 | |
10513 | length = end - sal_start.pc + 1; | |
10514 | if (length < 0) | |
10515 | /* Length overflowed. */ | |
10516 | error (_("Address range too large.")); | |
10517 | else if (length == 1) | |
10518 | { | |
10519 | /* This range is simple enough to be handled by | |
10520 | the `hbreak' command. */ | |
10521 | hbreak_command (addr_string_start, 1); | |
10522 | ||
10523 | do_cleanups (cleanup_bkpt); | |
10524 | ||
10525 | return; | |
10526 | } | |
10527 | ||
10528 | /* Now set up the breakpoint. */ | |
10529 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10530 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10531 | set_breakpoint_count (breakpoint_count + 1); |
10532 | b->number = breakpoint_count; | |
10533 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10534 | b->location = copy_event_location (start_location); |
10535 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10536 | b->loc->length = length; |
10537 | ||
f8eba3c6 | 10538 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10539 | |
10540 | mention (b); | |
8d3788bd | 10541 | observer_notify_breakpoint_created (b); |
44702360 | 10542 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10543 | } |
10544 | ||
4a64f543 MS |
10545 | /* Return non-zero if EXP is verified as constant. Returned zero |
10546 | means EXP is variable. Also the constant detection may fail for | |
10547 | some constant expressions and in such case still falsely return | |
10548 | zero. */ | |
2e6e3d9c | 10549 | |
65d79d4b SDJ |
10550 | static int |
10551 | watchpoint_exp_is_const (const struct expression *exp) | |
10552 | { | |
10553 | int i = exp->nelts; | |
10554 | ||
10555 | while (i > 0) | |
10556 | { | |
10557 | int oplenp, argsp; | |
10558 | ||
10559 | /* We are only interested in the descriptor of each element. */ | |
10560 | operator_length (exp, i, &oplenp, &argsp); | |
10561 | i -= oplenp; | |
10562 | ||
10563 | switch (exp->elts[i].opcode) | |
10564 | { | |
10565 | case BINOP_ADD: | |
10566 | case BINOP_SUB: | |
10567 | case BINOP_MUL: | |
10568 | case BINOP_DIV: | |
10569 | case BINOP_REM: | |
10570 | case BINOP_MOD: | |
10571 | case BINOP_LSH: | |
10572 | case BINOP_RSH: | |
10573 | case BINOP_LOGICAL_AND: | |
10574 | case BINOP_LOGICAL_OR: | |
10575 | case BINOP_BITWISE_AND: | |
10576 | case BINOP_BITWISE_IOR: | |
10577 | case BINOP_BITWISE_XOR: | |
10578 | case BINOP_EQUAL: | |
10579 | case BINOP_NOTEQUAL: | |
10580 | case BINOP_LESS: | |
10581 | case BINOP_GTR: | |
10582 | case BINOP_LEQ: | |
10583 | case BINOP_GEQ: | |
10584 | case BINOP_REPEAT: | |
10585 | case BINOP_COMMA: | |
10586 | case BINOP_EXP: | |
10587 | case BINOP_MIN: | |
10588 | case BINOP_MAX: | |
10589 | case BINOP_INTDIV: | |
10590 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10591 | case TERNOP_COND: |
10592 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10593 | |
10594 | case OP_LONG: | |
10595 | case OP_DOUBLE: | |
10596 | case OP_DECFLOAT: | |
10597 | case OP_LAST: | |
10598 | case OP_COMPLEX: | |
10599 | case OP_STRING: | |
65d79d4b SDJ |
10600 | case OP_ARRAY: |
10601 | case OP_TYPE: | |
608b4967 TT |
10602 | case OP_TYPEOF: |
10603 | case OP_DECLTYPE: | |
6e72ca20 | 10604 | case OP_TYPEID: |
65d79d4b SDJ |
10605 | case OP_NAME: |
10606 | case OP_OBJC_NSSTRING: | |
10607 | ||
10608 | case UNOP_NEG: | |
10609 | case UNOP_LOGICAL_NOT: | |
10610 | case UNOP_COMPLEMENT: | |
10611 | case UNOP_ADDR: | |
10612 | case UNOP_HIGH: | |
aeaa2474 | 10613 | case UNOP_CAST: |
9eaf6705 TT |
10614 | |
10615 | case UNOP_CAST_TYPE: | |
10616 | case UNOP_REINTERPRET_CAST: | |
10617 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10618 | /* Unary, binary and ternary operators: We have to check |
10619 | their operands. If they are constant, then so is the | |
10620 | result of that operation. For instance, if A and B are | |
10621 | determined to be constants, then so is "A + B". | |
10622 | ||
10623 | UNOP_IND is one exception to the rule above, because the | |
10624 | value of *ADDR is not necessarily a constant, even when | |
10625 | ADDR is. */ | |
65d79d4b SDJ |
10626 | break; |
10627 | ||
10628 | case OP_VAR_VALUE: | |
10629 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10630 | |
65d79d4b | 10631 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10632 | possible that a buggy compiler could mark a variable as |
10633 | constant even when it is not, and TYPE_CONST would return | |
10634 | true in this case, while SYMBOL_CLASS wouldn't. | |
10635 | ||
10636 | We also have to check for function symbols because they | |
10637 | are always constant. */ | |
65d79d4b SDJ |
10638 | { |
10639 | struct symbol *s = exp->elts[i + 2].symbol; | |
10640 | ||
10641 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10642 | && SYMBOL_CLASS (s) != LOC_CONST | |
10643 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10644 | return 0; | |
10645 | break; | |
10646 | } | |
10647 | ||
10648 | /* The default action is to return 0 because we are using | |
10649 | the optimistic approach here: If we don't know something, | |
10650 | then it is not a constant. */ | |
10651 | default: | |
10652 | return 0; | |
10653 | } | |
10654 | } | |
10655 | ||
10656 | return 1; | |
10657 | } | |
10658 | ||
3a5c3e22 PA |
10659 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10660 | ||
10661 | static void | |
10662 | dtor_watchpoint (struct breakpoint *self) | |
10663 | { | |
10664 | struct watchpoint *w = (struct watchpoint *) self; | |
10665 | ||
10666 | xfree (w->cond_exp); | |
10667 | xfree (w->exp); | |
10668 | xfree (w->exp_string); | |
10669 | xfree (w->exp_string_reparse); | |
10670 | value_free (w->val); | |
10671 | ||
10672 | base_breakpoint_ops.dtor (self); | |
10673 | } | |
10674 | ||
348d480f PA |
10675 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10676 | ||
10677 | static void | |
10678 | re_set_watchpoint (struct breakpoint *b) | |
10679 | { | |
3a5c3e22 PA |
10680 | struct watchpoint *w = (struct watchpoint *) b; |
10681 | ||
348d480f PA |
10682 | /* Watchpoint can be either on expression using entirely global |
10683 | variables, or it can be on local variables. | |
10684 | ||
10685 | Watchpoints of the first kind are never auto-deleted, and even | |
10686 | persist across program restarts. Since they can use variables | |
10687 | from shared libraries, we need to reparse expression as libraries | |
10688 | are loaded and unloaded. | |
10689 | ||
10690 | Watchpoints on local variables can also change meaning as result | |
10691 | of solib event. For example, if a watchpoint uses both a local | |
10692 | and a global variables in expression, it's a local watchpoint, | |
10693 | but unloading of a shared library will make the expression | |
10694 | invalid. This is not a very common use case, but we still | |
10695 | re-evaluate expression, to avoid surprises to the user. | |
10696 | ||
10697 | Note that for local watchpoints, we re-evaluate it only if | |
10698 | watchpoints frame id is still valid. If it's not, it means the | |
10699 | watchpoint is out of scope and will be deleted soon. In fact, | |
10700 | I'm not sure we'll ever be called in this case. | |
10701 | ||
10702 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10703 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10704 | |
3a5c3e22 PA |
10705 | Don't do anything about disabled watchpoints, since they will be |
10706 | reevaluated again when enabled. */ | |
10707 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10708 | } |
10709 | ||
77b06cd7 TJB |
10710 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10711 | ||
10712 | static int | |
10713 | insert_watchpoint (struct bp_location *bl) | |
10714 | { | |
3a5c3e22 PA |
10715 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10716 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10717 | |
10718 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10719 | w->cond_exp); |
77b06cd7 TJB |
10720 | } |
10721 | ||
10722 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10723 | ||
10724 | static int | |
73971819 | 10725 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10726 | { |
3a5c3e22 PA |
10727 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10728 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10729 | |
10730 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10731 | w->cond_exp); |
e09342b5 TJB |
10732 | } |
10733 | ||
e09342b5 | 10734 | static int |
348d480f | 10735 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10736 | struct address_space *aspace, CORE_ADDR bp_addr, |
10737 | const struct target_waitstatus *ws) | |
e09342b5 | 10738 | { |
348d480f | 10739 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10740 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10741 | |
348d480f PA |
10742 | /* Continuable hardware watchpoints are treated as non-existent if the |
10743 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10744 | some data address). Otherwise gdb won't stop on a break instruction | |
10745 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10746 | been defined. Also skip watchpoints which we know did not trigger | |
10747 | (did not match the data address). */ | |
10748 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10749 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10750 | return 0; |
9c06b0b4 | 10751 | |
348d480f | 10752 | return 1; |
9c06b0b4 TJB |
10753 | } |
10754 | ||
348d480f PA |
10755 | static void |
10756 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10757 | { |
348d480f | 10758 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10759 | |
348d480f | 10760 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10761 | } |
10762 | ||
10763 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10764 | hardware watchpoints. */ |
9c06b0b4 TJB |
10765 | |
10766 | static int | |
348d480f | 10767 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10768 | { |
3a5c3e22 PA |
10769 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10770 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10771 | |
10772 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10773 | } |
10774 | ||
10775 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10776 | hardware watchpoints. */ |
9c06b0b4 TJB |
10777 | |
10778 | static int | |
348d480f | 10779 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10780 | { |
efa80663 PA |
10781 | /* Read and access watchpoints only work with hardware support. */ |
10782 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10783 | } |
10784 | ||
9c06b0b4 | 10785 | static enum print_stop_action |
348d480f | 10786 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10787 | { |
348d480f PA |
10788 | struct cleanup *old_chain; |
10789 | struct breakpoint *b; | |
f99d8bf4 | 10790 | struct ui_file *stb; |
348d480f | 10791 | enum print_stop_action result; |
3a5c3e22 | 10792 | struct watchpoint *w; |
79a45e25 | 10793 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10794 | |
10795 | gdb_assert (bs->bp_location_at != NULL); | |
10796 | ||
348d480f | 10797 | b = bs->breakpoint_at; |
3a5c3e22 | 10798 | w = (struct watchpoint *) b; |
348d480f | 10799 | |
f99d8bf4 PA |
10800 | stb = mem_fileopen (); |
10801 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10802 | |
f303dbd6 PA |
10803 | annotate_watchpoint (b->number); |
10804 | maybe_print_thread_hit_breakpoint (uiout); | |
10805 | ||
9c06b0b4 TJB |
10806 | switch (b->type) |
10807 | { | |
348d480f | 10808 | case bp_watchpoint: |
9c06b0b4 | 10809 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10810 | if (ui_out_is_mi_like_p (uiout)) |
10811 | ui_out_field_string | |
10812 | (uiout, "reason", | |
10813 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10814 | mention (b); |
10815 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10816 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10817 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10818 | ui_out_field_stream (uiout, "old", stb); |
10819 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10820 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10821 | ui_out_field_stream (uiout, "new", stb); |
10822 | ui_out_text (uiout, "\n"); | |
10823 | /* More than one watchpoint may have been triggered. */ | |
10824 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10825 | break; |
10826 | ||
10827 | case bp_read_watchpoint: | |
10828 | if (ui_out_is_mi_like_p (uiout)) | |
10829 | ui_out_field_string | |
10830 | (uiout, "reason", | |
10831 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10832 | mention (b); |
10833 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10834 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10835 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10836 | ui_out_field_stream (uiout, "value", stb); |
10837 | ui_out_text (uiout, "\n"); | |
10838 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10839 | break; |
10840 | ||
10841 | case bp_access_watchpoint: | |
348d480f PA |
10842 | if (bs->old_val != NULL) |
10843 | { | |
348d480f PA |
10844 | if (ui_out_is_mi_like_p (uiout)) |
10845 | ui_out_field_string | |
10846 | (uiout, "reason", | |
10847 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10848 | mention (b); | |
10849 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10850 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10851 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10852 | ui_out_field_stream (uiout, "old", stb); |
10853 | ui_out_text (uiout, "\nNew value = "); | |
10854 | } | |
10855 | else | |
10856 | { | |
10857 | mention (b); | |
10858 | if (ui_out_is_mi_like_p (uiout)) | |
10859 | ui_out_field_string | |
10860 | (uiout, "reason", | |
10861 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10862 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10863 | ui_out_text (uiout, "\nValue = "); | |
10864 | } | |
f99d8bf4 | 10865 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10866 | ui_out_field_stream (uiout, "new", stb); |
10867 | ui_out_text (uiout, "\n"); | |
10868 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10869 | break; |
10870 | default: | |
348d480f | 10871 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10872 | } |
10873 | ||
348d480f PA |
10874 | do_cleanups (old_chain); |
10875 | return result; | |
10876 | } | |
10877 | ||
10878 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10879 | watchpoints. */ | |
10880 | ||
10881 | static void | |
10882 | print_mention_watchpoint (struct breakpoint *b) | |
10883 | { | |
10884 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10885 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10886 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10887 | |
10888 | switch (b->type) | |
10889 | { | |
10890 | case bp_watchpoint: | |
10891 | ui_out_text (uiout, "Watchpoint "); | |
10892 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10893 | break; | |
10894 | case bp_hardware_watchpoint: | |
10895 | ui_out_text (uiout, "Hardware watchpoint "); | |
10896 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10897 | break; | |
10898 | case bp_read_watchpoint: | |
10899 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10900 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10901 | break; | |
10902 | case bp_access_watchpoint: | |
10903 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10904 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10905 | break; | |
10906 | default: | |
10907 | internal_error (__FILE__, __LINE__, | |
10908 | _("Invalid hardware watchpoint type.")); | |
10909 | } | |
10910 | ||
10911 | ui_out_field_int (uiout, "number", b->number); | |
10912 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10913 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10914 | do_cleanups (ui_out_chain); |
10915 | } | |
10916 | ||
10917 | /* Implement the "print_recreate" breakpoint_ops method for | |
10918 | watchpoints. */ | |
10919 | ||
10920 | static void | |
10921 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10922 | { | |
3a5c3e22 PA |
10923 | struct watchpoint *w = (struct watchpoint *) b; |
10924 | ||
348d480f PA |
10925 | switch (b->type) |
10926 | { | |
10927 | case bp_watchpoint: | |
10928 | case bp_hardware_watchpoint: | |
10929 | fprintf_unfiltered (fp, "watch"); | |
10930 | break; | |
10931 | case bp_read_watchpoint: | |
10932 | fprintf_unfiltered (fp, "rwatch"); | |
10933 | break; | |
10934 | case bp_access_watchpoint: | |
10935 | fprintf_unfiltered (fp, "awatch"); | |
10936 | break; | |
10937 | default: | |
10938 | internal_error (__FILE__, __LINE__, | |
10939 | _("Invalid watchpoint type.")); | |
10940 | } | |
10941 | ||
3a5c3e22 | 10942 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10943 | print_recreate_thread (b, fp); |
348d480f PA |
10944 | } |
10945 | ||
427cd150 TT |
10946 | /* Implement the "explains_signal" breakpoint_ops method for |
10947 | watchpoints. */ | |
10948 | ||
47591c29 | 10949 | static int |
427cd150 TT |
10950 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10951 | { | |
10952 | /* A software watchpoint cannot cause a signal other than | |
10953 | GDB_SIGNAL_TRAP. */ | |
10954 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10955 | return 0; |
427cd150 | 10956 | |
47591c29 | 10957 | return 1; |
427cd150 TT |
10958 | } |
10959 | ||
348d480f PA |
10960 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10961 | ||
2060206e | 10962 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10963 | |
10964 | /* Implement the "insert" breakpoint_ops method for | |
10965 | masked hardware watchpoints. */ | |
10966 | ||
10967 | static int | |
10968 | insert_masked_watchpoint (struct bp_location *bl) | |
10969 | { | |
3a5c3e22 PA |
10970 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10971 | ||
10972 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10973 | bl->watchpoint_type); |
10974 | } | |
10975 | ||
10976 | /* Implement the "remove" breakpoint_ops method for | |
10977 | masked hardware watchpoints. */ | |
10978 | ||
10979 | static int | |
73971819 | 10980 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10981 | { |
3a5c3e22 PA |
10982 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10983 | ||
10984 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10985 | bl->watchpoint_type); |
10986 | } | |
10987 | ||
10988 | /* Implement the "resources_needed" breakpoint_ops method for | |
10989 | masked hardware watchpoints. */ | |
10990 | ||
10991 | static int | |
10992 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10993 | { | |
3a5c3e22 PA |
10994 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10995 | ||
10996 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10997 | } |
10998 | ||
10999 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11000 | masked hardware watchpoints. */ | |
11001 | ||
11002 | static int | |
11003 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11004 | { | |
11005 | return 0; | |
11006 | } | |
11007 | ||
11008 | /* Implement the "print_it" breakpoint_ops method for | |
11009 | masked hardware watchpoints. */ | |
11010 | ||
11011 | static enum print_stop_action | |
11012 | print_it_masked_watchpoint (bpstat bs) | |
11013 | { | |
11014 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11015 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11016 | |
11017 | /* Masked watchpoints have only one location. */ | |
11018 | gdb_assert (b->loc && b->loc->next == NULL); | |
11019 | ||
f303dbd6 PA |
11020 | annotate_watchpoint (b->number); |
11021 | maybe_print_thread_hit_breakpoint (uiout); | |
11022 | ||
348d480f PA |
11023 | switch (b->type) |
11024 | { | |
11025 | case bp_hardware_watchpoint: | |
348d480f PA |
11026 | if (ui_out_is_mi_like_p (uiout)) |
11027 | ui_out_field_string | |
11028 | (uiout, "reason", | |
11029 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11030 | break; | |
11031 | ||
11032 | case bp_read_watchpoint: | |
11033 | if (ui_out_is_mi_like_p (uiout)) | |
11034 | ui_out_field_string | |
11035 | (uiout, "reason", | |
11036 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11037 | break; | |
11038 | ||
11039 | case bp_access_watchpoint: | |
11040 | if (ui_out_is_mi_like_p (uiout)) | |
11041 | ui_out_field_string | |
11042 | (uiout, "reason", | |
11043 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11044 | break; | |
11045 | default: | |
11046 | internal_error (__FILE__, __LINE__, | |
11047 | _("Invalid hardware watchpoint type.")); | |
11048 | } | |
11049 | ||
11050 | mention (b); | |
9c06b0b4 TJB |
11051 | ui_out_text (uiout, _("\n\ |
11052 | Check the underlying instruction at PC for the memory\n\ | |
11053 | address and value which triggered this watchpoint.\n")); | |
11054 | ui_out_text (uiout, "\n"); | |
11055 | ||
11056 | /* More than one watchpoint may have been triggered. */ | |
11057 | return PRINT_UNKNOWN; | |
11058 | } | |
11059 | ||
11060 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11061 | masked hardware watchpoints. */ | |
11062 | ||
11063 | static void | |
11064 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11065 | struct ui_out *uiout) | |
11066 | { | |
3a5c3e22 PA |
11067 | struct watchpoint *w = (struct watchpoint *) b; |
11068 | ||
9c06b0b4 TJB |
11069 | /* Masked watchpoints have only one location. */ |
11070 | gdb_assert (b->loc && b->loc->next == NULL); | |
11071 | ||
11072 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11073 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11074 | ui_out_text (uiout, "\n"); |
11075 | } | |
11076 | ||
11077 | /* Implement the "print_mention" breakpoint_ops method for | |
11078 | masked hardware watchpoints. */ | |
11079 | ||
11080 | static void | |
11081 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11082 | { | |
3a5c3e22 | 11083 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11084 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11085 | struct cleanup *ui_out_chain; |
11086 | ||
11087 | switch (b->type) | |
11088 | { | |
11089 | case bp_hardware_watchpoint: | |
11090 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11091 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11092 | break; | |
11093 | case bp_read_watchpoint: | |
11094 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11095 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11096 | break; | |
11097 | case bp_access_watchpoint: | |
11098 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11099 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11100 | break; | |
11101 | default: | |
11102 | internal_error (__FILE__, __LINE__, | |
11103 | _("Invalid hardware watchpoint type.")); | |
11104 | } | |
11105 | ||
11106 | ui_out_field_int (uiout, "number", b->number); | |
11107 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11108 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11109 | do_cleanups (ui_out_chain); |
11110 | } | |
11111 | ||
11112 | /* Implement the "print_recreate" breakpoint_ops method for | |
11113 | masked hardware watchpoints. */ | |
11114 | ||
11115 | static void | |
11116 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11117 | { | |
3a5c3e22 | 11118 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11119 | char tmp[40]; |
11120 | ||
11121 | switch (b->type) | |
11122 | { | |
11123 | case bp_hardware_watchpoint: | |
11124 | fprintf_unfiltered (fp, "watch"); | |
11125 | break; | |
11126 | case bp_read_watchpoint: | |
11127 | fprintf_unfiltered (fp, "rwatch"); | |
11128 | break; | |
11129 | case bp_access_watchpoint: | |
11130 | fprintf_unfiltered (fp, "awatch"); | |
11131 | break; | |
11132 | default: | |
11133 | internal_error (__FILE__, __LINE__, | |
11134 | _("Invalid hardware watchpoint type.")); | |
11135 | } | |
11136 | ||
3a5c3e22 PA |
11137 | sprintf_vma (tmp, w->hw_wp_mask); |
11138 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11139 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11140 | } |
11141 | ||
11142 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11143 | ||
2060206e | 11144 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11145 | |
11146 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11147 | ||
11148 | static int | |
11149 | is_masked_watchpoint (const struct breakpoint *b) | |
11150 | { | |
11151 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11152 | } | |
11153 | ||
53a5351d JM |
11154 | /* accessflag: hw_write: watch write, |
11155 | hw_read: watch read, | |
11156 | hw_access: watch access (read or write) */ | |
c906108c | 11157 | static void |
bbc13ae3 | 11158 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11159 | int just_location, int internal) |
c906108c | 11160 | { |
d983da9c | 11161 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11162 | struct expression *exp; |
270140bd | 11163 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11164 | struct value *val, *mark, *result; |
bb9d5f81 | 11165 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11166 | struct frame_info *frame; |
bbc13ae3 KS |
11167 | const char *exp_start = NULL; |
11168 | const char *exp_end = NULL; | |
11169 | const char *tok, *end_tok; | |
9c06b0b4 | 11170 | int toklen = -1; |
bbc13ae3 KS |
11171 | const char *cond_start = NULL; |
11172 | const char *cond_end = NULL; | |
c906108c | 11173 | enum bptype bp_type; |
37e4754d | 11174 | int thread = -1; |
0cf6dd15 | 11175 | int pc = 0; |
9c06b0b4 TJB |
11176 | /* Flag to indicate whether we are going to use masks for |
11177 | the hardware watchpoint. */ | |
11178 | int use_mask = 0; | |
11179 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11180 | struct watchpoint *w; |
bbc13ae3 KS |
11181 | char *expression; |
11182 | struct cleanup *back_to; | |
c906108c | 11183 | |
37e4754d LM |
11184 | /* Make sure that we actually have parameters to parse. */ |
11185 | if (arg != NULL && arg[0] != '\0') | |
11186 | { | |
bbc13ae3 KS |
11187 | const char *value_start; |
11188 | ||
11189 | exp_end = arg + strlen (arg); | |
37e4754d | 11190 | |
9c06b0b4 TJB |
11191 | /* Look for "parameter value" pairs at the end |
11192 | of the arguments string. */ | |
bbc13ae3 | 11193 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11194 | { |
11195 | /* Skip whitespace at the end of the argument list. */ | |
11196 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11197 | tok--; | |
11198 | ||
11199 | /* Find the beginning of the last token. | |
11200 | This is the value of the parameter. */ | |
11201 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11202 | tok--; | |
11203 | value_start = tok + 1; | |
11204 | ||
11205 | /* Skip whitespace. */ | |
11206 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11207 | tok--; | |
11208 | ||
11209 | end_tok = tok; | |
11210 | ||
11211 | /* Find the beginning of the second to last token. | |
11212 | This is the parameter itself. */ | |
11213 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11214 | tok--; | |
11215 | tok++; | |
11216 | toklen = end_tok - tok + 1; | |
11217 | ||
61012eef | 11218 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11219 | { |
5d5658a1 | 11220 | struct thread_info *thr; |
9c06b0b4 TJB |
11221 | /* At this point we've found a "thread" token, which means |
11222 | the user is trying to set a watchpoint that triggers | |
11223 | only in a specific thread. */ | |
5d5658a1 | 11224 | const char *endp; |
37e4754d | 11225 | |
9c06b0b4 TJB |
11226 | if (thread != -1) |
11227 | error(_("You can specify only one thread.")); | |
37e4754d | 11228 | |
9c06b0b4 | 11229 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11230 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11231 | |
5d5658a1 | 11232 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11233 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11234 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11235 | |
5d5658a1 | 11236 | thread = thr->global_num; |
9c06b0b4 | 11237 | } |
61012eef | 11238 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11239 | { |
11240 | /* We've found a "mask" token, which means the user wants to | |
11241 | create a hardware watchpoint that is going to have the mask | |
11242 | facility. */ | |
11243 | struct value *mask_value, *mark; | |
37e4754d | 11244 | |
9c06b0b4 TJB |
11245 | if (use_mask) |
11246 | error(_("You can specify only one mask.")); | |
37e4754d | 11247 | |
9c06b0b4 | 11248 | use_mask = just_location = 1; |
37e4754d | 11249 | |
9c06b0b4 TJB |
11250 | mark = value_mark (); |
11251 | mask_value = parse_to_comma_and_eval (&value_start); | |
11252 | mask = value_as_address (mask_value); | |
11253 | value_free_to_mark (mark); | |
11254 | } | |
11255 | else | |
11256 | /* We didn't recognize what we found. We should stop here. */ | |
11257 | break; | |
37e4754d | 11258 | |
9c06b0b4 TJB |
11259 | /* Truncate the string and get rid of the "parameter value" pair before |
11260 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11261 | exp_end = tok; |
9c06b0b4 | 11262 | } |
37e4754d | 11263 | } |
bbc13ae3 KS |
11264 | else |
11265 | exp_end = arg; | |
37e4754d | 11266 | |
bbc13ae3 KS |
11267 | /* Parse the rest of the arguments. From here on out, everything |
11268 | is in terms of a newly allocated string instead of the original | |
11269 | ARG. */ | |
c906108c | 11270 | innermost_block = NULL; |
bbc13ae3 KS |
11271 | expression = savestring (arg, exp_end - arg); |
11272 | back_to = make_cleanup (xfree, expression); | |
11273 | exp_start = arg = expression; | |
1bb9788d | 11274 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11275 | exp_end = arg; |
fa8a61dc TT |
11276 | /* Remove trailing whitespace from the expression before saving it. |
11277 | This makes the eventual display of the expression string a bit | |
11278 | prettier. */ | |
11279 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11280 | --exp_end; | |
11281 | ||
65d79d4b SDJ |
11282 | /* Checking if the expression is not constant. */ |
11283 | if (watchpoint_exp_is_const (exp)) | |
11284 | { | |
11285 | int len; | |
11286 | ||
11287 | len = exp_end - exp_start; | |
11288 | while (len > 0 && isspace (exp_start[len - 1])) | |
11289 | len--; | |
11290 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11291 | } | |
11292 | ||
c906108c SS |
11293 | exp_valid_block = innermost_block; |
11294 | mark = value_mark (); | |
3a1115a0 | 11295 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11296 | |
bb9d5f81 PP |
11297 | if (val != NULL && just_location) |
11298 | { | |
11299 | saved_bitpos = value_bitpos (val); | |
11300 | saved_bitsize = value_bitsize (val); | |
11301 | } | |
11302 | ||
06a64a0b TT |
11303 | if (just_location) |
11304 | { | |
9c06b0b4 TJB |
11305 | int ret; |
11306 | ||
06a64a0b | 11307 | exp_valid_block = NULL; |
a1442452 | 11308 | val = value_addr (result); |
06a64a0b TT |
11309 | release_value (val); |
11310 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11311 | |
11312 | if (use_mask) | |
11313 | { | |
11314 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11315 | mask); | |
11316 | if (ret == -1) | |
11317 | error (_("This target does not support masked watchpoints.")); | |
11318 | else if (ret == -2) | |
11319 | error (_("Invalid mask or memory region.")); | |
11320 | } | |
06a64a0b TT |
11321 | } |
11322 | else if (val != NULL) | |
fa4727a6 | 11323 | release_value (val); |
c906108c | 11324 | |
bbc13ae3 KS |
11325 | tok = skip_spaces_const (arg); |
11326 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11327 | |
11328 | toklen = end_tok - tok; | |
11329 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11330 | { | |
2d134ed3 PA |
11331 | struct expression *cond; |
11332 | ||
60e1c644 | 11333 | innermost_block = NULL; |
c906108c | 11334 | tok = cond_start = end_tok + 1; |
1bb9788d | 11335 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11336 | |
11337 | /* The watchpoint expression may not be local, but the condition | |
11338 | may still be. E.g.: `watch global if local > 0'. */ | |
11339 | cond_exp_valid_block = innermost_block; | |
11340 | ||
2d134ed3 | 11341 | xfree (cond); |
c906108c SS |
11342 | cond_end = tok; |
11343 | } | |
11344 | if (*tok) | |
8a3fe4f8 | 11345 | error (_("Junk at end of command.")); |
c906108c | 11346 | |
d983da9c | 11347 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11348 | |
11349 | /* If the expression is "local", then set up a "watchpoint scope" | |
11350 | breakpoint at the point where we've left the scope of the watchpoint | |
11351 | expression. Create the scope breakpoint before the watchpoint, so | |
11352 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11353 | if (exp_valid_block && frame) |
d983da9c | 11354 | { |
edb3359d DJ |
11355 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11356 | { | |
11357 | scope_breakpoint | |
a6d9a66e UW |
11358 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11359 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11360 | bp_watchpoint_scope, |
11361 | &momentary_breakpoint_ops); | |
d983da9c | 11362 | |
edb3359d | 11363 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11364 | |
edb3359d DJ |
11365 | /* Automatically delete the breakpoint when it hits. */ |
11366 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11367 | |
edb3359d DJ |
11368 | /* Only break in the proper frame (help with recursion). */ |
11369 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11370 | |
edb3359d | 11371 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11372 | scope_breakpoint->loc->gdbarch |
11373 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11374 | scope_breakpoint->loc->requested_address |
11375 | = frame_unwind_caller_pc (frame); | |
11376 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11377 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11378 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11379 | scope_breakpoint->type); |
11380 | } | |
d983da9c DJ |
11381 | } |
11382 | ||
e8369a73 AB |
11383 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11384 | watchpoints here even if hardware watchpoints are turned off, a call | |
11385 | to update_watchpoint later in this function will cause the type to | |
11386 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11387 | ||
11388 | if (accessflag == hw_read) | |
11389 | bp_type = bp_read_watchpoint; | |
11390 | else if (accessflag == hw_access) | |
11391 | bp_type = bp_access_watchpoint; | |
11392 | else | |
11393 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11394 | |
11395 | w = XCNEW (struct watchpoint); | |
11396 | b = &w->base; | |
348d480f | 11397 | if (use_mask) |
3a5c3e22 PA |
11398 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11399 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11400 | else |
3a5c3e22 PA |
11401 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11402 | &watchpoint_breakpoint_ops); | |
37e4754d | 11403 | b->thread = thread; |
b5de0fa7 | 11404 | b->disposition = disp_donttouch; |
348d480f | 11405 | b->pspace = current_program_space; |
3a5c3e22 PA |
11406 | w->exp = exp; |
11407 | w->exp_valid_block = exp_valid_block; | |
11408 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11409 | if (just_location) |
11410 | { | |
11411 | struct type *t = value_type (val); | |
11412 | CORE_ADDR addr = value_as_address (val); | |
11413 | char *name; | |
11414 | ||
11415 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11416 | name = type_to_string (t); | |
11417 | ||
3a5c3e22 | 11418 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11419 | core_addr_to_string (addr)); |
06a64a0b TT |
11420 | xfree (name); |
11421 | ||
3a5c3e22 | 11422 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11423 | (int) (exp_end - exp_start), exp_start); |
11424 | ||
06a64a0b TT |
11425 | /* The above expression is in C. */ |
11426 | b->language = language_c; | |
11427 | } | |
11428 | else | |
3a5c3e22 | 11429 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11430 | |
11431 | if (use_mask) | |
11432 | { | |
3a5c3e22 | 11433 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11434 | } |
11435 | else | |
11436 | { | |
3a5c3e22 | 11437 | w->val = val; |
bb9d5f81 PP |
11438 | w->val_bitpos = saved_bitpos; |
11439 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11440 | w->val_valid = 1; |
9c06b0b4 | 11441 | } |
77b06cd7 | 11442 | |
c906108c SS |
11443 | if (cond_start) |
11444 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11445 | else | |
11446 | b->cond_string = 0; | |
c5aa993b | 11447 | |
c906108c | 11448 | if (frame) |
f6bc2008 | 11449 | { |
3a5c3e22 PA |
11450 | w->watchpoint_frame = get_frame_id (frame); |
11451 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11452 | } |
c906108c | 11453 | else |
f6bc2008 | 11454 | { |
3a5c3e22 PA |
11455 | w->watchpoint_frame = null_frame_id; |
11456 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11457 | } |
c906108c | 11458 | |
d983da9c | 11459 | if (scope_breakpoint != NULL) |
c906108c | 11460 | { |
d983da9c DJ |
11461 | /* The scope breakpoint is related to the watchpoint. We will |
11462 | need to act on them together. */ | |
11463 | b->related_breakpoint = scope_breakpoint; | |
11464 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11465 | } |
d983da9c | 11466 | |
06a64a0b TT |
11467 | if (!just_location) |
11468 | value_free_to_mark (mark); | |
2d134ed3 | 11469 | |
492d29ea | 11470 | TRY |
a9634178 TJB |
11471 | { |
11472 | /* Finally update the new watchpoint. This creates the locations | |
11473 | that should be inserted. */ | |
3a5c3e22 | 11474 | update_watchpoint (w, 1); |
a9634178 | 11475 | } |
492d29ea | 11476 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11477 | { |
11478 | delete_breakpoint (b); | |
11479 | throw_exception (e); | |
11480 | } | |
492d29ea | 11481 | END_CATCH |
a9634178 | 11482 | |
3ea46bff | 11483 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11484 | do_cleanups (back_to); |
c906108c SS |
11485 | } |
11486 | ||
e09342b5 | 11487 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11488 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11489 | |
c906108c | 11490 | static int |
a9634178 | 11491 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11492 | { |
11493 | int found_memory_cnt = 0; | |
2e70b7b9 | 11494 | struct value *head = v; |
c906108c SS |
11495 | |
11496 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11497 | if (!can_use_hw_watchpoints) |
c906108c | 11498 | return 0; |
c5aa993b | 11499 | |
5c44784c JM |
11500 | /* Make sure that the value of the expression depends only upon |
11501 | memory contents, and values computed from them within GDB. If we | |
11502 | find any register references or function calls, we can't use a | |
11503 | hardware watchpoint. | |
11504 | ||
11505 | The idea here is that evaluating an expression generates a series | |
11506 | of values, one holding the value of every subexpression. (The | |
11507 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11508 | a*b+c.) GDB's values hold almost enough information to establish | |
11509 | the criteria given above --- they identify memory lvalues, | |
11510 | register lvalues, computed values, etcetera. So we can evaluate | |
11511 | the expression, and then scan the chain of values that leaves | |
11512 | behind to decide whether we can detect any possible change to the | |
11513 | expression's final value using only hardware watchpoints. | |
11514 | ||
11515 | However, I don't think that the values returned by inferior | |
11516 | function calls are special in any way. So this function may not | |
11517 | notice that an expression involving an inferior function call | |
11518 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11519 | for (; v; v = value_next (v)) |
c906108c | 11520 | { |
5c44784c | 11521 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11522 | { |
8464be76 DJ |
11523 | if (v != head && value_lazy (v)) |
11524 | /* A lazy memory lvalue in the chain is one that GDB never | |
11525 | needed to fetch; we either just used its address (e.g., | |
11526 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11527 | in `a,b'). This doesn't apply to HEAD; if that is | |
11528 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11529 | ; |
53a5351d | 11530 | else |
5c44784c JM |
11531 | { |
11532 | /* Ahh, memory we actually used! Check if we can cover | |
11533 | it with hardware watchpoints. */ | |
df407dfe | 11534 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11535 | |
11536 | /* We only watch structs and arrays if user asked for it | |
11537 | explicitly, never if they just happen to appear in a | |
11538 | middle of some value chain. */ | |
11539 | if (v == head | |
11540 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11541 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11542 | { | |
42ae5230 | 11543 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11544 | int len; |
11545 | int num_regs; | |
11546 | ||
a9634178 | 11547 | len = (target_exact_watchpoints |
e09342b5 TJB |
11548 | && is_scalar_type_recursive (vtype))? |
11549 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11550 | |
e09342b5 TJB |
11551 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11552 | if (!num_regs) | |
2e70b7b9 MS |
11553 | return 0; |
11554 | else | |
e09342b5 | 11555 | found_memory_cnt += num_regs; |
2e70b7b9 | 11556 | } |
5c44784c | 11557 | } |
c5aa993b | 11558 | } |
5086187c AC |
11559 | else if (VALUE_LVAL (v) != not_lval |
11560 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11561 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11562 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11563 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11564 | } |
11565 | ||
11566 | /* The expression itself looks suitable for using a hardware | |
11567 | watchpoint, but give the target machine a chance to reject it. */ | |
11568 | return found_memory_cnt; | |
11569 | } | |
11570 | ||
8b93c638 | 11571 | void |
84f4c1fe | 11572 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11573 | { |
84f4c1fe | 11574 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11575 | } |
11576 | ||
06a64a0b TT |
11577 | /* A helper function that looks for the "-location" argument and then |
11578 | calls watch_command_1. */ | |
11579 | ||
11580 | static void | |
11581 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11582 | { | |
11583 | int just_location = 0; | |
11584 | ||
11585 | if (arg | |
11586 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11587 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11588 | { | |
e9cafbcc | 11589 | arg = skip_spaces (arg); |
06a64a0b TT |
11590 | just_location = 1; |
11591 | } | |
11592 | ||
84f4c1fe | 11593 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11594 | } |
8926118c | 11595 | |
c5aa993b | 11596 | static void |
fba45db2 | 11597 | watch_command (char *arg, int from_tty) |
c906108c | 11598 | { |
06a64a0b | 11599 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11600 | } |
11601 | ||
8b93c638 | 11602 | void |
84f4c1fe | 11603 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11604 | { |
84f4c1fe | 11605 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11606 | } |
8926118c | 11607 | |
c5aa993b | 11608 | static void |
fba45db2 | 11609 | rwatch_command (char *arg, int from_tty) |
c906108c | 11610 | { |
06a64a0b | 11611 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11612 | } |
11613 | ||
8b93c638 | 11614 | void |
84f4c1fe | 11615 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11616 | { |
84f4c1fe | 11617 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11618 | } |
8926118c | 11619 | |
c5aa993b | 11620 | static void |
fba45db2 | 11621 | awatch_command (char *arg, int from_tty) |
c906108c | 11622 | { |
06a64a0b | 11623 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11624 | } |
c906108c | 11625 | \f |
c5aa993b | 11626 | |
cfc31633 PA |
11627 | /* Data for the FSM that manages the until(location)/advance commands |
11628 | in infcmd.c. Here because it uses the mechanisms of | |
11629 | breakpoints. */ | |
c906108c | 11630 | |
cfc31633 | 11631 | struct until_break_fsm |
bfec99b2 | 11632 | { |
cfc31633 PA |
11633 | /* The base class. */ |
11634 | struct thread_fsm thread_fsm; | |
11635 | ||
11636 | /* The thread that as current when the command was executed. */ | |
11637 | int thread; | |
11638 | ||
11639 | /* The breakpoint set at the destination location. */ | |
11640 | struct breakpoint *location_breakpoint; | |
11641 | ||
11642 | /* Breakpoint set at the return address in the caller frame. May be | |
11643 | NULL. */ | |
11644 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11645 | }; |
11646 | ||
8980e177 PA |
11647 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11648 | struct thread_info *thread); | |
11649 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11650 | struct thread_info *thread); | |
cfc31633 PA |
11651 | static enum async_reply_reason |
11652 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11653 | ||
11654 | /* until_break_fsm's vtable. */ | |
11655 | ||
11656 | static struct thread_fsm_ops until_break_fsm_ops = | |
11657 | { | |
11658 | NULL, /* dtor */ | |
11659 | until_break_fsm_clean_up, | |
11660 | until_break_fsm_should_stop, | |
11661 | NULL, /* return_value */ | |
11662 | until_break_fsm_async_reply_reason, | |
11663 | }; | |
11664 | ||
11665 | /* Allocate a new until_break_command_fsm. */ | |
11666 | ||
11667 | static struct until_break_fsm * | |
8980e177 | 11668 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11669 | struct breakpoint *location_breakpoint, |
11670 | struct breakpoint *caller_breakpoint) | |
11671 | { | |
11672 | struct until_break_fsm *sm; | |
11673 | ||
11674 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11675 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11676 | |
11677 | sm->thread = thread; | |
11678 | sm->location_breakpoint = location_breakpoint; | |
11679 | sm->caller_breakpoint = caller_breakpoint; | |
11680 | ||
11681 | return sm; | |
11682 | } | |
11683 | ||
11684 | /* Implementation of the 'should_stop' FSM method for the | |
11685 | until(location)/advance commands. */ | |
11686 | ||
11687 | static int | |
8980e177 PA |
11688 | until_break_fsm_should_stop (struct thread_fsm *self, |
11689 | struct thread_info *tp) | |
cfc31633 PA |
11690 | { |
11691 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11692 | |
11693 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11694 | sm->location_breakpoint) != NULL | |
11695 | || (sm->caller_breakpoint != NULL | |
11696 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11697 | sm->caller_breakpoint) != NULL)) | |
11698 | thread_fsm_set_finished (self); | |
11699 | ||
11700 | return 1; | |
11701 | } | |
11702 | ||
11703 | /* Implementation of the 'clean_up' FSM method for the | |
11704 | until(location)/advance commands. */ | |
11705 | ||
c2c6d25f | 11706 | static void |
8980e177 PA |
11707 | until_break_fsm_clean_up (struct thread_fsm *self, |
11708 | struct thread_info *thread) | |
43ff13b4 | 11709 | { |
cfc31633 | 11710 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11711 | |
cfc31633 PA |
11712 | /* Clean up our temporary breakpoints. */ |
11713 | if (sm->location_breakpoint != NULL) | |
11714 | { | |
11715 | delete_breakpoint (sm->location_breakpoint); | |
11716 | sm->location_breakpoint = NULL; | |
11717 | } | |
11718 | if (sm->caller_breakpoint != NULL) | |
11719 | { | |
11720 | delete_breakpoint (sm->caller_breakpoint); | |
11721 | sm->caller_breakpoint = NULL; | |
11722 | } | |
11723 | delete_longjmp_breakpoint (sm->thread); | |
11724 | } | |
11725 | ||
11726 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11727 | until(location)/advance commands. */ | |
11728 | ||
11729 | static enum async_reply_reason | |
11730 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11731 | { | |
11732 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11733 | } |
11734 | ||
c906108c | 11735 | void |
ae66c1fc | 11736 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11737 | { |
11738 | struct symtabs_and_lines sals; | |
11739 | struct symtab_and_line sal; | |
8556afb4 PA |
11740 | struct frame_info *frame; |
11741 | struct gdbarch *frame_gdbarch; | |
11742 | struct frame_id stack_frame_id; | |
11743 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11744 | struct breakpoint *location_breakpoint; |
11745 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11746 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11747 | int thread; |
11748 | struct thread_info *tp; | |
f00aae0f | 11749 | struct event_location *location; |
cfc31633 | 11750 | struct until_break_fsm *sm; |
c906108c | 11751 | |
70509625 | 11752 | clear_proceed_status (0); |
c906108c SS |
11753 | |
11754 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11755 | this function. */ |
c5aa993b | 11756 | |
f00aae0f KS |
11757 | location = string_to_event_location (&arg, current_language); |
11758 | cleanup = make_cleanup_delete_event_location (location); | |
11759 | ||
1bfeeb0f | 11760 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11761 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11762 | get_last_displayed_symtab (), |
f8eba3c6 | 11763 | get_last_displayed_line ()); |
c906108c | 11764 | else |
f00aae0f | 11765 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11766 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11767 | |
c906108c | 11768 | if (sals.nelts != 1) |
8a3fe4f8 | 11769 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11770 | |
c906108c | 11771 | sal = sals.sals[0]; |
4a64f543 | 11772 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11773 | |
c906108c | 11774 | if (*arg) |
8a3fe4f8 | 11775 | error (_("Junk at end of arguments.")); |
c5aa993b | 11776 | |
c906108c | 11777 | resolve_sal_pc (&sal); |
c5aa993b | 11778 | |
186c406b | 11779 | tp = inferior_thread (); |
5d5658a1 | 11780 | thread = tp->global_num; |
186c406b | 11781 | |
883bc8d1 PA |
11782 | old_chain = make_cleanup (null_cleanup, NULL); |
11783 | ||
8556afb4 PA |
11784 | /* Note linespec handling above invalidates the frame chain. |
11785 | Installing a breakpoint also invalidates the frame chain (as it | |
11786 | may need to switch threads), so do any frame handling before | |
11787 | that. */ | |
11788 | ||
11789 | frame = get_selected_frame (NULL); | |
11790 | frame_gdbarch = get_frame_arch (frame); | |
11791 | stack_frame_id = get_stack_frame_id (frame); | |
11792 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11793 | |
ae66c1fc EZ |
11794 | /* Keep within the current frame, or in frames called by the current |
11795 | one. */ | |
edb3359d | 11796 | |
883bc8d1 | 11797 | if (frame_id_p (caller_frame_id)) |
c906108c | 11798 | { |
883bc8d1 | 11799 | struct symtab_and_line sal2; |
cfc31633 | 11800 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11801 | |
11802 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11803 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11804 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11805 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11806 | sal2, | |
11807 | caller_frame_id, | |
11808 | bp_until); | |
11809 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11810 | |
883bc8d1 | 11811 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11812 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11813 | } |
c5aa993b | 11814 | |
c70a6932 JK |
11815 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11816 | frame = NULL; | |
11817 | ||
883bc8d1 PA |
11818 | if (anywhere) |
11819 | /* If the user told us to continue until a specified location, | |
11820 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11821 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11822 | null_frame_id, bp_until); | |
883bc8d1 PA |
11823 | else |
11824 | /* Otherwise, specify the selected frame, because we want to stop | |
11825 | only at the very same frame. */ | |
cfc31633 PA |
11826 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11827 | stack_frame_id, bp_until); | |
11828 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11829 | |
8980e177 | 11830 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11831 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11832 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11833 | |
cfc31633 | 11834 | discard_cleanups (old_chain); |
f107f563 | 11835 | |
cfc31633 | 11836 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11837 | |
11838 | do_cleanups (cleanup); | |
c906108c | 11839 | } |
ae66c1fc | 11840 | |
c906108c SS |
11841 | /* This function attempts to parse an optional "if <cond>" clause |
11842 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11843 | |
c906108c SS |
11844 | Else, it returns a pointer to the condition string. (It does not |
11845 | attempt to evaluate the string against a particular block.) And, | |
11846 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11847 | if clause in the arg string. */ |
53a5351d | 11848 | |
916703c0 | 11849 | char * |
fba45db2 | 11850 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11851 | { |
c5aa993b JM |
11852 | char *cond_string; |
11853 | ||
11854 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11855 | return NULL; |
c5aa993b | 11856 | |
4a64f543 | 11857 | /* Skip the "if" keyword. */ |
c906108c | 11858 | (*arg) += 2; |
c5aa993b | 11859 | |
c906108c | 11860 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11861 | condition string. */ |
e9cafbcc | 11862 | *arg = skip_spaces (*arg); |
c906108c | 11863 | cond_string = *arg; |
c5aa993b | 11864 | |
4a64f543 MS |
11865 | /* Assume that the condition occupies the remainder of the arg |
11866 | string. */ | |
c906108c | 11867 | (*arg) += strlen (cond_string); |
c5aa993b | 11868 | |
c906108c SS |
11869 | return cond_string; |
11870 | } | |
c5aa993b | 11871 | |
c906108c SS |
11872 | /* Commands to deal with catching events, such as signals, exceptions, |
11873 | process start/exit, etc. */ | |
c5aa993b JM |
11874 | |
11875 | typedef enum | |
11876 | { | |
44feb3ce TT |
11877 | catch_fork_temporary, catch_vfork_temporary, |
11878 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11879 | } |
11880 | catch_fork_kind; | |
11881 | ||
c906108c | 11882 | static void |
cc59ec59 MS |
11883 | catch_fork_command_1 (char *arg, int from_tty, |
11884 | struct cmd_list_element *command) | |
c906108c | 11885 | { |
a6d9a66e | 11886 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11887 | char *cond_string = NULL; |
44feb3ce TT |
11888 | catch_fork_kind fork_kind; |
11889 | int tempflag; | |
11890 | ||
11891 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11892 | tempflag = (fork_kind == catch_fork_temporary | |
11893 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11894 | |
44feb3ce TT |
11895 | if (!arg) |
11896 | arg = ""; | |
e9cafbcc | 11897 | arg = skip_spaces (arg); |
c5aa993b | 11898 | |
c906108c | 11899 | /* The allowed syntax is: |
c5aa993b JM |
11900 | catch [v]fork |
11901 | catch [v]fork if <cond> | |
11902 | ||
4a64f543 | 11903 | First, check if there's an if clause. */ |
c906108c | 11904 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11905 | |
c906108c | 11906 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11907 | error (_("Junk at end of arguments.")); |
c5aa993b | 11908 | |
c906108c | 11909 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11910 | and enable reporting of such events. */ |
c5aa993b JM |
11911 | switch (fork_kind) |
11912 | { | |
44feb3ce TT |
11913 | case catch_fork_temporary: |
11914 | case catch_fork_permanent: | |
a6d9a66e | 11915 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11916 | &catch_fork_breakpoint_ops); |
c906108c | 11917 | break; |
44feb3ce TT |
11918 | case catch_vfork_temporary: |
11919 | case catch_vfork_permanent: | |
a6d9a66e | 11920 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11921 | &catch_vfork_breakpoint_ops); |
c906108c | 11922 | break; |
c5aa993b | 11923 | default: |
8a3fe4f8 | 11924 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11925 | break; |
c5aa993b | 11926 | } |
c906108c SS |
11927 | } |
11928 | ||
11929 | static void | |
cc59ec59 MS |
11930 | catch_exec_command_1 (char *arg, int from_tty, |
11931 | struct cmd_list_element *command) | |
c906108c | 11932 | { |
b4d90040 | 11933 | struct exec_catchpoint *c; |
a6d9a66e | 11934 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11935 | int tempflag; |
c5aa993b | 11936 | char *cond_string = NULL; |
c906108c | 11937 | |
44feb3ce TT |
11938 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11939 | ||
11940 | if (!arg) | |
11941 | arg = ""; | |
e9cafbcc | 11942 | arg = skip_spaces (arg); |
c906108c SS |
11943 | |
11944 | /* The allowed syntax is: | |
c5aa993b JM |
11945 | catch exec |
11946 | catch exec if <cond> | |
c906108c | 11947 | |
4a64f543 | 11948 | First, check if there's an if clause. */ |
c906108c SS |
11949 | cond_string = ep_parse_optional_if_clause (&arg); |
11950 | ||
11951 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11952 | error (_("Junk at end of arguments.")); |
c906108c | 11953 | |
b4d90040 PA |
11954 | c = XNEW (struct exec_catchpoint); |
11955 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11956 | &catch_exec_breakpoint_ops); | |
11957 | c->exec_pathname = NULL; | |
11958 | ||
3ea46bff | 11959 | install_breakpoint (0, &c->base, 1); |
c906108c | 11960 | } |
c5aa993b | 11961 | |
9ac4176b | 11962 | void |
28010a5d PA |
11963 | init_ada_exception_breakpoint (struct breakpoint *b, |
11964 | struct gdbarch *gdbarch, | |
11965 | struct symtab_and_line sal, | |
11966 | char *addr_string, | |
c0a91b2b | 11967 | const struct breakpoint_ops *ops, |
28010a5d | 11968 | int tempflag, |
349774ef | 11969 | int enabled, |
28010a5d | 11970 | int from_tty) |
f7f9143b | 11971 | { |
f7f9143b JB |
11972 | if (from_tty) |
11973 | { | |
5af949e3 UW |
11974 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11975 | if (!loc_gdbarch) | |
11976 | loc_gdbarch = gdbarch; | |
11977 | ||
6c95b8df PA |
11978 | describe_other_breakpoints (loc_gdbarch, |
11979 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11980 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11981 | version for exception catchpoints, because two catchpoints | |
11982 | used for different exception names will use the same address. | |
11983 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11984 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11985 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11986 | the user what type of catchpoint it is. The above is good |
11987 | enough for now, though. */ | |
11988 | } | |
11989 | ||
28010a5d | 11990 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11991 | |
349774ef | 11992 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11993 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11994 | b->location = string_to_event_location (&addr_string, |
11995 | language_def (language_ada)); | |
f7f9143b | 11996 | b->language = language_ada; |
f7f9143b JB |
11997 | } |
11998 | ||
c906108c | 11999 | static void |
fba45db2 | 12000 | catch_command (char *arg, int from_tty) |
c906108c | 12001 | { |
44feb3ce | 12002 | error (_("Catch requires an event name.")); |
c906108c SS |
12003 | } |
12004 | \f | |
12005 | ||
12006 | static void | |
fba45db2 | 12007 | tcatch_command (char *arg, int from_tty) |
c906108c | 12008 | { |
44feb3ce | 12009 | error (_("Catch requires an event name.")); |
c906108c SS |
12010 | } |
12011 | ||
8a2c437b TT |
12012 | /* A qsort comparison function that sorts breakpoints in order. */ |
12013 | ||
12014 | static int | |
12015 | compare_breakpoints (const void *a, const void *b) | |
12016 | { | |
9a3c8263 | 12017 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 12018 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 12019 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
12020 | uintptr_t ub = (uintptr_t) *bb; |
12021 | ||
12022 | if ((*ba)->number < (*bb)->number) | |
12023 | return -1; | |
12024 | else if ((*ba)->number > (*bb)->number) | |
12025 | return 1; | |
12026 | ||
12027 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12028 | the number 0. */ | |
12029 | if (ua < ub) | |
12030 | return -1; | |
94b0e70d | 12031 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12032 | } |
12033 | ||
80f8a6eb | 12034 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12035 | |
12036 | static void | |
fba45db2 | 12037 | clear_command (char *arg, int from_tty) |
c906108c | 12038 | { |
8a2c437b | 12039 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12040 | VEC(breakpoint_p) *found = 0; |
12041 | int ix; | |
c906108c SS |
12042 | int default_match; |
12043 | struct symtabs_and_lines sals; | |
12044 | struct symtab_and_line sal; | |
c906108c | 12045 | int i; |
8a2c437b | 12046 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12047 | |
12048 | if (arg) | |
12049 | { | |
39cf75f7 DE |
12050 | sals = decode_line_with_current_source (arg, |
12051 | (DECODE_LINE_FUNFIRSTLINE | |
12052 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12053 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12054 | default_match = 0; |
12055 | } | |
12056 | else | |
12057 | { | |
8d749320 | 12058 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12059 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12060 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12061 | |
12062 | /* Set sal's line, symtab, pc, and pspace to the values | |
12063 | corresponding to the last call to print_frame_info. If the | |
12064 | codepoint is not valid, this will set all the fields to 0. */ | |
12065 | get_last_displayed_sal (&sal); | |
c906108c | 12066 | if (sal.symtab == 0) |
8a3fe4f8 | 12067 | error (_("No source file specified.")); |
c906108c SS |
12068 | |
12069 | sals.sals[0] = sal; | |
12070 | sals.nelts = 1; | |
12071 | ||
12072 | default_match = 1; | |
12073 | } | |
12074 | ||
4a64f543 MS |
12075 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12076 | seems, because all existing breakpoints typically have both | |
12077 | file/line and pc set. So, if clear is given file/line, we can | |
12078 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12079 | |
12080 | We only support clearing given the address explicitly | |
12081 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12082 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12083 | due to optimization, all in one block. |
4a64f543 MS |
12084 | |
12085 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12086 | PC corresponding to the same file:line, the breakpoint won't |
12087 | be cleared. We probably can still clear the breakpoint, but | |
12088 | since the other PC value is never presented to user, user | |
12089 | can only find it by guessing, and it does not seem important | |
12090 | to support that. */ | |
12091 | ||
4a64f543 MS |
12092 | /* For each line spec given, delete bps which correspond to it. Do |
12093 | it in two passes, solely to preserve the current behavior that | |
12094 | from_tty is forced true if we delete more than one | |
12095 | breakpoint. */ | |
c906108c | 12096 | |
80f8a6eb | 12097 | found = NULL; |
8a2c437b | 12098 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12099 | for (i = 0; i < sals.nelts; i++) |
12100 | { | |
05cba821 JK |
12101 | const char *sal_fullname; |
12102 | ||
c906108c | 12103 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12104 | If line given (pc == 0), clear all bpts on specified line. |
12105 | If defaulting, clear all bpts on default line | |
c906108c | 12106 | or at default pc. |
c5aa993b JM |
12107 | |
12108 | defaulting sal.pc != 0 tests to do | |
12109 | ||
12110 | 0 1 pc | |
12111 | 1 1 pc _and_ line | |
12112 | 0 0 line | |
12113 | 1 0 <can't happen> */ | |
c906108c SS |
12114 | |
12115 | sal = sals.sals[i]; | |
05cba821 JK |
12116 | sal_fullname = (sal.symtab == NULL |
12117 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12118 | |
4a64f543 | 12119 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12120 | ALL_BREAKPOINTS (b) |
c5aa993b | 12121 | { |
0d381245 | 12122 | int match = 0; |
4a64f543 | 12123 | /* Are we going to delete b? */ |
cc60f2e3 | 12124 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12125 | { |
12126 | struct bp_location *loc = b->loc; | |
12127 | for (; loc; loc = loc->next) | |
12128 | { | |
f8eba3c6 TT |
12129 | /* If the user specified file:line, don't allow a PC |
12130 | match. This matches historical gdb behavior. */ | |
12131 | int pc_match = (!sal.explicit_line | |
12132 | && sal.pc | |
12133 | && (loc->pspace == sal.pspace) | |
12134 | && (loc->address == sal.pc) | |
12135 | && (!section_is_overlay (loc->section) | |
12136 | || loc->section == sal.section)); | |
4aac40c8 TT |
12137 | int line_match = 0; |
12138 | ||
12139 | if ((default_match || sal.explicit_line) | |
2f202fde | 12140 | && loc->symtab != NULL |
05cba821 | 12141 | && sal_fullname != NULL |
4aac40c8 | 12142 | && sal.pspace == loc->pspace |
05cba821 JK |
12143 | && loc->line_number == sal.line |
12144 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12145 | sal_fullname) == 0) | |
12146 | line_match = 1; | |
4aac40c8 | 12147 | |
0d381245 VP |
12148 | if (pc_match || line_match) |
12149 | { | |
12150 | match = 1; | |
12151 | break; | |
12152 | } | |
12153 | } | |
12154 | } | |
12155 | ||
12156 | if (match) | |
d6e956e5 | 12157 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12158 | } |
80f8a6eb | 12159 | } |
8a2c437b | 12160 | |
80f8a6eb | 12161 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12162 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12163 | { |
12164 | if (arg) | |
8a3fe4f8 | 12165 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12166 | else |
8a3fe4f8 | 12167 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12168 | } |
c906108c | 12169 | |
8a2c437b TT |
12170 | /* Remove duplicates from the vec. */ |
12171 | qsort (VEC_address (breakpoint_p, found), | |
12172 | VEC_length (breakpoint_p, found), | |
12173 | sizeof (breakpoint_p), | |
12174 | compare_breakpoints); | |
12175 | prev = VEC_index (breakpoint_p, found, 0); | |
12176 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12177 | { | |
12178 | if (b == prev) | |
12179 | { | |
12180 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12181 | --ix; | |
12182 | } | |
12183 | } | |
12184 | ||
d6e956e5 | 12185 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12186 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12187 | if (from_tty) |
a3f17187 | 12188 | { |
d6e956e5 | 12189 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12190 | printf_unfiltered (_("Deleted breakpoint ")); |
12191 | else | |
12192 | printf_unfiltered (_("Deleted breakpoints ")); | |
12193 | } | |
d6e956e5 VP |
12194 | |
12195 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12196 | { |
c5aa993b | 12197 | if (from_tty) |
d6e956e5 VP |
12198 | printf_unfiltered ("%d ", b->number); |
12199 | delete_breakpoint (b); | |
c906108c | 12200 | } |
80f8a6eb MS |
12201 | if (from_tty) |
12202 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12203 | |
12204 | do_cleanups (cleanups); | |
c906108c SS |
12205 | } |
12206 | \f | |
12207 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12208 | all breakpoints that are marked for deletion, whether hit or not. | |
12209 | This is called after any breakpoint is hit, or after errors. */ | |
12210 | ||
12211 | void | |
fba45db2 | 12212 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12213 | { |
35df4500 | 12214 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12215 | |
12216 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12217 | if (bs->breakpoint_at |
12218 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12219 | && bs->stop) |
f431efe5 | 12220 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12221 | |
35df4500 | 12222 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12223 | { |
b5de0fa7 | 12224 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12225 | delete_breakpoint (b); |
12226 | } | |
c906108c SS |
12227 | } |
12228 | ||
4a64f543 MS |
12229 | /* A comparison function for bp_location AP and BP being interfaced to |
12230 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12231 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12232 | secondarily by ordering first permanent elements and |
4a64f543 | 12233 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12234 | qsort being an unstable algorithm. */ |
876fa593 JK |
12235 | |
12236 | static int | |
494cfb0f | 12237 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12238 | { |
9a3c8263 SM |
12239 | const struct bp_location *a = *(const struct bp_location **) ap; |
12240 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12241 | |
12242 | if (a->address != b->address) | |
12243 | return (a->address > b->address) - (a->address < b->address); | |
12244 | ||
dea2aa5f LM |
12245 | /* Sort locations at the same address by their pspace number, keeping |
12246 | locations of the same inferior (in a multi-inferior environment) | |
12247 | grouped. */ | |
12248 | ||
12249 | if (a->pspace->num != b->pspace->num) | |
12250 | return ((a->pspace->num > b->pspace->num) | |
12251 | - (a->pspace->num < b->pspace->num)); | |
12252 | ||
876fa593 | 12253 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12254 | if (a->permanent != b->permanent) |
12255 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12256 | |
c56a97f9 JK |
12257 | /* Make the internal GDB representation stable across GDB runs |
12258 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12259 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12260 | |
12261 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12262 | return ((a->owner->number > b->owner->number) |
12263 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12264 | |
12265 | return (a > b) - (a < b); | |
12266 | } | |
12267 | ||
876fa593 | 12268 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12269 | bp_location_shadow_len_after_address_max according to the current |
12270 | content of the bp_location array. */ | |
f7545552 TT |
12271 | |
12272 | static void | |
876fa593 | 12273 | bp_location_target_extensions_update (void) |
f7545552 | 12274 | { |
876fa593 JK |
12275 | struct bp_location *bl, **blp_tmp; |
12276 | ||
12277 | bp_location_placed_address_before_address_max = 0; | |
12278 | bp_location_shadow_len_after_address_max = 0; | |
12279 | ||
12280 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12281 | { | |
12282 | CORE_ADDR start, end, addr; | |
12283 | ||
12284 | if (!bp_location_has_shadow (bl)) | |
12285 | continue; | |
12286 | ||
12287 | start = bl->target_info.placed_address; | |
12288 | end = start + bl->target_info.shadow_len; | |
12289 | ||
12290 | gdb_assert (bl->address >= start); | |
12291 | addr = bl->address - start; | |
12292 | if (addr > bp_location_placed_address_before_address_max) | |
12293 | bp_location_placed_address_before_address_max = addr; | |
12294 | ||
12295 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12296 | ||
12297 | gdb_assert (bl->address < end); | |
12298 | addr = end - bl->address; | |
12299 | if (addr > bp_location_shadow_len_after_address_max) | |
12300 | bp_location_shadow_len_after_address_max = addr; | |
12301 | } | |
f7545552 TT |
12302 | } |
12303 | ||
1e4d1764 YQ |
12304 | /* Download tracepoint locations if they haven't been. */ |
12305 | ||
12306 | static void | |
12307 | download_tracepoint_locations (void) | |
12308 | { | |
7ed2c994 | 12309 | struct breakpoint *b; |
1e4d1764 | 12310 | struct cleanup *old_chain; |
dd2e65cc | 12311 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12312 | |
12313 | old_chain = save_current_space_and_thread (); | |
12314 | ||
7ed2c994 | 12315 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12316 | { |
7ed2c994 | 12317 | struct bp_location *bl; |
1e4d1764 | 12318 | struct tracepoint *t; |
f2a8bc8a | 12319 | int bp_location_downloaded = 0; |
1e4d1764 | 12320 | |
7ed2c994 | 12321 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12322 | ? !may_insert_fast_tracepoints |
12323 | : !may_insert_tracepoints)) | |
12324 | continue; | |
12325 | ||
dd2e65cc YQ |
12326 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12327 | { | |
12328 | if (target_can_download_tracepoint ()) | |
12329 | can_download_tracepoint = TRIBOOL_TRUE; | |
12330 | else | |
12331 | can_download_tracepoint = TRIBOOL_FALSE; | |
12332 | } | |
12333 | ||
12334 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12335 | break; | |
12336 | ||
7ed2c994 YQ |
12337 | for (bl = b->loc; bl; bl = bl->next) |
12338 | { | |
12339 | /* In tracepoint, locations are _never_ duplicated, so | |
12340 | should_be_inserted is equivalent to | |
12341 | unduplicated_should_be_inserted. */ | |
12342 | if (!should_be_inserted (bl) || bl->inserted) | |
12343 | continue; | |
1e4d1764 | 12344 | |
7ed2c994 | 12345 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12346 | |
7ed2c994 | 12347 | target_download_tracepoint (bl); |
1e4d1764 | 12348 | |
7ed2c994 | 12349 | bl->inserted = 1; |
f2a8bc8a | 12350 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12351 | } |
12352 | t = (struct tracepoint *) b; | |
12353 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12354 | if (bp_location_downloaded) |
12355 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12356 | } |
12357 | ||
12358 | do_cleanups (old_chain); | |
12359 | } | |
12360 | ||
934709f0 PW |
12361 | /* Swap the insertion/duplication state between two locations. */ |
12362 | ||
12363 | static void | |
12364 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12365 | { | |
12366 | const int left_inserted = left->inserted; | |
12367 | const int left_duplicate = left->duplicate; | |
b775012e | 12368 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12369 | const struct bp_target_info left_target_info = left->target_info; |
12370 | ||
1e4d1764 YQ |
12371 | /* Locations of tracepoints can never be duplicated. */ |
12372 | if (is_tracepoint (left->owner)) | |
12373 | gdb_assert (!left->duplicate); | |
12374 | if (is_tracepoint (right->owner)) | |
12375 | gdb_assert (!right->duplicate); | |
12376 | ||
934709f0 PW |
12377 | left->inserted = right->inserted; |
12378 | left->duplicate = right->duplicate; | |
b775012e | 12379 | left->needs_update = right->needs_update; |
934709f0 PW |
12380 | left->target_info = right->target_info; |
12381 | right->inserted = left_inserted; | |
12382 | right->duplicate = left_duplicate; | |
b775012e | 12383 | right->needs_update = left_needs_update; |
934709f0 PW |
12384 | right->target_info = left_target_info; |
12385 | } | |
12386 | ||
b775012e LM |
12387 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12388 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12389 | conditions on the target's side. Such conditions need to be updated on | |
12390 | the target. */ | |
12391 | ||
12392 | static void | |
12393 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12394 | { | |
12395 | struct bp_location **locp = NULL, **loc2p; | |
12396 | struct bp_location *loc; | |
12397 | CORE_ADDR address = 0; | |
12398 | int pspace_num; | |
12399 | ||
12400 | address = bl->address; | |
12401 | pspace_num = bl->pspace->num; | |
12402 | ||
12403 | /* This is only meaningful if the target is | |
12404 | evaluating conditions and if the user has | |
12405 | opted for condition evaluation on the target's | |
12406 | side. */ | |
12407 | if (gdb_evaluates_breakpoint_condition_p () | |
12408 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12409 | return; | |
12410 | ||
12411 | /* Flag all breakpoint locations with this address and | |
12412 | the same program space as the location | |
12413 | as "its condition has changed". We need to | |
12414 | update the conditions on the target's side. */ | |
12415 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12416 | { | |
12417 | loc = *loc2p; | |
12418 | ||
12419 | if (!is_breakpoint (loc->owner) | |
12420 | || pspace_num != loc->pspace->num) | |
12421 | continue; | |
12422 | ||
12423 | /* Flag the location appropriately. We use a different state to | |
12424 | let everyone know that we already updated the set of locations | |
12425 | with addr bl->address and program space bl->pspace. This is so | |
12426 | we don't have to keep calling these functions just to mark locations | |
12427 | that have already been marked. */ | |
12428 | loc->condition_changed = condition_updated; | |
12429 | ||
12430 | /* Free the agent expression bytecode as well. We will compute | |
12431 | it later on. */ | |
12432 | if (loc->cond_bytecode) | |
12433 | { | |
12434 | free_agent_expr (loc->cond_bytecode); | |
12435 | loc->cond_bytecode = NULL; | |
12436 | } | |
12437 | } | |
12438 | } | |
44702360 PA |
12439 | /* Called whether new breakpoints are created, or existing breakpoints |
12440 | deleted, to update the global location list and recompute which | |
12441 | locations are duplicate of which. | |
b775012e | 12442 | |
04086b45 PA |
12443 | The INSERT_MODE flag determines whether locations may not, may, or |
12444 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12445 | info. */ | |
b60e7edf | 12446 | |
0d381245 | 12447 | static void |
44702360 | 12448 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12449 | { |
74960c60 | 12450 | struct breakpoint *b; |
876fa593 | 12451 | struct bp_location **locp, *loc; |
f7545552 | 12452 | struct cleanup *cleanups; |
b775012e LM |
12453 | /* Last breakpoint location address that was marked for update. */ |
12454 | CORE_ADDR last_addr = 0; | |
12455 | /* Last breakpoint location program space that was marked for update. */ | |
12456 | int last_pspace_num = -1; | |
f7545552 | 12457 | |
2d134ed3 PA |
12458 | /* Used in the duplicates detection below. When iterating over all |
12459 | bp_locations, points to the first bp_location of a given address. | |
12460 | Breakpoints and watchpoints of different types are never | |
12461 | duplicates of each other. Keep one pointer for each type of | |
12462 | breakpoint/watchpoint, so we only need to loop over all locations | |
12463 | once. */ | |
12464 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12465 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12466 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12467 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12468 | |
4a64f543 MS |
12469 | /* Saved former bp_location array which we compare against the newly |
12470 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12471 | struct bp_location **old_location, **old_locp; |
12472 | unsigned old_location_count; | |
12473 | ||
12474 | old_location = bp_location; | |
12475 | old_location_count = bp_location_count; | |
12476 | bp_location = NULL; | |
12477 | bp_location_count = 0; | |
12478 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12479 | |
74960c60 | 12480 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12481 | for (loc = b->loc; loc; loc = loc->next) |
12482 | bp_location_count++; | |
12483 | ||
8d749320 | 12484 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12485 | locp = bp_location; |
12486 | ALL_BREAKPOINTS (b) | |
12487 | for (loc = b->loc; loc; loc = loc->next) | |
12488 | *locp++ = loc; | |
12489 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12490 | bp_location_compare); |
876fa593 JK |
12491 | |
12492 | bp_location_target_extensions_update (); | |
74960c60 | 12493 | |
4a64f543 MS |
12494 | /* Identify bp_location instances that are no longer present in the |
12495 | new list, and therefore should be freed. Note that it's not | |
12496 | necessary that those locations should be removed from inferior -- | |
12497 | if there's another location at the same address (previously | |
12498 | marked as duplicate), we don't need to remove/insert the | |
12499 | location. | |
876fa593 | 12500 | |
4a64f543 MS |
12501 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12502 | and former bp_location array state respectively. */ | |
876fa593 JK |
12503 | |
12504 | locp = bp_location; | |
12505 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12506 | old_locp++) | |
74960c60 | 12507 | { |
876fa593 | 12508 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12509 | struct bp_location **loc2p; |
876fa593 | 12510 | |
e5dd4106 | 12511 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12512 | not, we have to free it. */ |
c7d46a38 | 12513 | int found_object = 0; |
20874c92 VP |
12514 | /* Tells if the location should remain inserted in the target. */ |
12515 | int keep_in_target = 0; | |
12516 | int removed = 0; | |
876fa593 | 12517 | |
4a64f543 MS |
12518 | /* Skip LOCP entries which will definitely never be needed. |
12519 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12520 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12521 | && (*locp)->address < old_loc->address) |
876fa593 | 12522 | locp++; |
c7d46a38 PA |
12523 | |
12524 | for (loc2p = locp; | |
12525 | (loc2p < bp_location + bp_location_count | |
12526 | && (*loc2p)->address == old_loc->address); | |
12527 | loc2p++) | |
12528 | { | |
b775012e LM |
12529 | /* Check if this is a new/duplicated location or a duplicated |
12530 | location that had its condition modified. If so, we want to send | |
12531 | its condition to the target if evaluation of conditions is taking | |
12532 | place there. */ | |
12533 | if ((*loc2p)->condition_changed == condition_modified | |
12534 | && (last_addr != old_loc->address | |
12535 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12536 | { |
b775012e LM |
12537 | force_breakpoint_reinsertion (*loc2p); |
12538 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12539 | } |
b775012e LM |
12540 | |
12541 | if (*loc2p == old_loc) | |
12542 | found_object = 1; | |
c7d46a38 | 12543 | } |
74960c60 | 12544 | |
b775012e LM |
12545 | /* We have already handled this address, update it so that we don't |
12546 | have to go through updates again. */ | |
12547 | last_addr = old_loc->address; | |
12548 | ||
12549 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12550 | if (!found_object) | |
12551 | force_breakpoint_reinsertion (old_loc); | |
12552 | ||
4a64f543 MS |
12553 | /* If this location is no longer present, and inserted, look if |
12554 | there's maybe a new location at the same address. If so, | |
12555 | mark that one inserted, and don't remove this one. This is | |
12556 | needed so that we don't have a time window where a breakpoint | |
12557 | at certain location is not inserted. */ | |
74960c60 | 12558 | |
876fa593 | 12559 | if (old_loc->inserted) |
0d381245 | 12560 | { |
4a64f543 MS |
12561 | /* If the location is inserted now, we might have to remove |
12562 | it. */ | |
74960c60 | 12563 | |
876fa593 | 12564 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12565 | { |
4a64f543 MS |
12566 | /* The location is still present in the location list, |
12567 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12568 | keep_in_target = 1; |
74960c60 VP |
12569 | } |
12570 | else | |
12571 | { | |
b775012e LM |
12572 | /* This location still exists, but it won't be kept in the |
12573 | target since it may have been disabled. We proceed to | |
12574 | remove its target-side condition. */ | |
12575 | ||
4a64f543 MS |
12576 | /* The location is either no longer present, or got |
12577 | disabled. See if there's another location at the | |
12578 | same address, in which case we don't need to remove | |
12579 | this one from the target. */ | |
876fa593 | 12580 | |
2bdf28a0 | 12581 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12582 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12583 | { | |
876fa593 | 12584 | for (loc2p = locp; |
c7d46a38 PA |
12585 | (loc2p < bp_location + bp_location_count |
12586 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12587 | loc2p++) |
12588 | { | |
12589 | struct bp_location *loc2 = *loc2p; | |
12590 | ||
2d134ed3 | 12591 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12592 | { |
85d721b8 PA |
12593 | /* Read watchpoint locations are switched to |
12594 | access watchpoints, if the former are not | |
12595 | supported, but the latter are. */ | |
12596 | if (is_hardware_watchpoint (old_loc->owner)) | |
12597 | { | |
12598 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12599 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12600 | } | |
12601 | ||
934709f0 PW |
12602 | /* loc2 is a duplicated location. We need to check |
12603 | if it should be inserted in case it will be | |
12604 | unduplicated. */ | |
12605 | if (loc2 != old_loc | |
12606 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12607 | { |
934709f0 | 12608 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12609 | keep_in_target = 1; |
12610 | break; | |
12611 | } | |
876fa593 JK |
12612 | } |
12613 | } | |
12614 | } | |
74960c60 VP |
12615 | } |
12616 | ||
20874c92 VP |
12617 | if (!keep_in_target) |
12618 | { | |
834c0d03 | 12619 | if (remove_breakpoint (old_loc)) |
20874c92 | 12620 | { |
4a64f543 MS |
12621 | /* This is just about all we can do. We could keep |
12622 | this location on the global list, and try to | |
12623 | remove it next time, but there's no particular | |
12624 | reason why we will succeed next time. | |
20874c92 | 12625 | |
4a64f543 MS |
12626 | Note that at this point, old_loc->owner is still |
12627 | valid, as delete_breakpoint frees the breakpoint | |
12628 | only after calling us. */ | |
3e43a32a MS |
12629 | printf_filtered (_("warning: Error removing " |
12630 | "breakpoint %d\n"), | |
876fa593 | 12631 | old_loc->owner->number); |
20874c92 VP |
12632 | } |
12633 | removed = 1; | |
12634 | } | |
0d381245 | 12635 | } |
74960c60 VP |
12636 | |
12637 | if (!found_object) | |
1c5cfe86 | 12638 | { |
fbea99ea | 12639 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12640 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12641 | { |
db82e815 PA |
12642 | /* This location was removed from the target. In |
12643 | non-stop mode, a race condition is possible where | |
12644 | we've removed a breakpoint, but stop events for that | |
12645 | breakpoint are already queued and will arrive later. | |
12646 | We apply an heuristic to be able to distinguish such | |
12647 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12648 | breakpoint location for a bit, and will retire it | |
12649 | after we see some number of events. The theory here | |
12650 | is that reporting of events should, "on the average", | |
12651 | be fair, so after a while we'll see events from all | |
12652 | threads that have anything of interest, and no longer | |
12653 | need to keep this breakpoint location around. We | |
12654 | don't hold locations forever so to reduce chances of | |
12655 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12656 | SIGTRAP. | |
12657 | ||
12658 | The heuristic failing can be disastrous on | |
12659 | decr_pc_after_break targets. | |
12660 | ||
12661 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12662 | if we fail to recognize a late breakpoint SIGTRAP, | |
12663 | because events_till_retirement has reached 0 too | |
12664 | soon, we'll fail to do the PC adjustment, and report | |
12665 | a random SIGTRAP to the user. When the user resumes | |
12666 | the inferior, it will most likely immediately crash | |
2dec564e | 12667 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12668 | corrupted, because of being resumed e.g., in the |
12669 | middle of a multi-byte instruction, or skipped a | |
12670 | one-byte instruction. This was actually seen happen | |
12671 | on native x86-linux, and should be less rare on | |
12672 | targets that do not support new thread events, like | |
12673 | remote, due to the heuristic depending on | |
12674 | thread_count. | |
12675 | ||
12676 | Mistaking a random SIGTRAP for a breakpoint trap | |
12677 | causes similar symptoms (PC adjustment applied when | |
12678 | it shouldn't), but then again, playing with SIGTRAPs | |
12679 | behind the debugger's back is asking for trouble. | |
12680 | ||
12681 | Since hardware watchpoint traps are always | |
12682 | distinguishable from other traps, so we don't need to | |
12683 | apply keep hardware watchpoint moribund locations | |
12684 | around. We simply always ignore hardware watchpoint | |
12685 | traps we can no longer explain. */ | |
12686 | ||
876fa593 JK |
12687 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12688 | old_loc->owner = NULL; | |
20874c92 | 12689 | |
876fa593 | 12690 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12691 | } |
12692 | else | |
f431efe5 PA |
12693 | { |
12694 | old_loc->owner = NULL; | |
12695 | decref_bp_location (&old_loc); | |
12696 | } | |
20874c92 | 12697 | } |
74960c60 | 12698 | } |
1c5cfe86 | 12699 | |
348d480f PA |
12700 | /* Rescan breakpoints at the same address and section, marking the |
12701 | first one as "first" and any others as "duplicates". This is so | |
12702 | that the bpt instruction is only inserted once. If we have a | |
12703 | permanent breakpoint at the same place as BPT, make that one the | |
12704 | official one, and the rest as duplicates. Permanent breakpoints | |
12705 | are sorted first for the same address. | |
12706 | ||
12707 | Do the same for hardware watchpoints, but also considering the | |
12708 | watchpoint's type (regular/access/read) and length. */ | |
12709 | ||
12710 | bp_loc_first = NULL; | |
12711 | wp_loc_first = NULL; | |
12712 | awp_loc_first = NULL; | |
12713 | rwp_loc_first = NULL; | |
12714 | ALL_BP_LOCATIONS (loc, locp) | |
12715 | { | |
12716 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12717 | non-NULL. */ | |
348d480f | 12718 | struct bp_location **loc_first_p; |
d3fbdd86 | 12719 | b = loc->owner; |
348d480f | 12720 | |
6f380991 | 12721 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12722 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12723 | /* Don't detect duplicate for tracepoint locations because they are |
12724 | never duplicated. See the comments in field `duplicate' of | |
12725 | `struct bp_location'. */ | |
348d480f | 12726 | || is_tracepoint (b)) |
b775012e LM |
12727 | { |
12728 | /* Clear the condition modification flag. */ | |
12729 | loc->condition_changed = condition_unchanged; | |
12730 | continue; | |
12731 | } | |
348d480f | 12732 | |
348d480f PA |
12733 | if (b->type == bp_hardware_watchpoint) |
12734 | loc_first_p = &wp_loc_first; | |
12735 | else if (b->type == bp_read_watchpoint) | |
12736 | loc_first_p = &rwp_loc_first; | |
12737 | else if (b->type == bp_access_watchpoint) | |
12738 | loc_first_p = &awp_loc_first; | |
12739 | else | |
12740 | loc_first_p = &bp_loc_first; | |
12741 | ||
12742 | if (*loc_first_p == NULL | |
12743 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12744 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12745 | { | |
12746 | *loc_first_p = loc; | |
12747 | loc->duplicate = 0; | |
b775012e LM |
12748 | |
12749 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12750 | { | |
12751 | loc->needs_update = 1; | |
12752 | /* Clear the condition modification flag. */ | |
12753 | loc->condition_changed = condition_unchanged; | |
12754 | } | |
348d480f PA |
12755 | continue; |
12756 | } | |
12757 | ||
934709f0 PW |
12758 | |
12759 | /* This and the above ensure the invariant that the first location | |
12760 | is not duplicated, and is the inserted one. | |
12761 | All following are marked as duplicated, and are not inserted. */ | |
12762 | if (loc->inserted) | |
12763 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12764 | loc->duplicate = 1; |
12765 | ||
b775012e LM |
12766 | /* Clear the condition modification flag. */ |
12767 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12768 | } |
12769 | ||
a25a5a45 | 12770 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12771 | { |
04086b45 | 12772 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12773 | insert_breakpoint_locations (); |
12774 | else | |
12775 | { | |
44702360 PA |
12776 | /* Even though the caller told us to not insert new |
12777 | locations, we may still need to update conditions on the | |
12778 | target's side of breakpoints that were already inserted | |
12779 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12780 | only update conditions for locations that are marked |
12781 | "needs_update". */ | |
12782 | update_inserted_breakpoint_locations (); | |
12783 | } | |
12784 | } | |
348d480f | 12785 | |
04086b45 | 12786 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12787 | download_tracepoint_locations (); |
12788 | ||
348d480f PA |
12789 | do_cleanups (cleanups); |
12790 | } | |
12791 | ||
12792 | void | |
12793 | breakpoint_retire_moribund (void) | |
12794 | { | |
12795 | struct bp_location *loc; | |
12796 | int ix; | |
12797 | ||
12798 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12799 | if (--(loc->events_till_retirement) == 0) | |
12800 | { | |
12801 | decref_bp_location (&loc); | |
12802 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12803 | --ix; | |
12804 | } | |
12805 | } | |
12806 | ||
12807 | static void | |
44702360 | 12808 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12809 | { |
348d480f | 12810 | |
492d29ea PA |
12811 | TRY |
12812 | { | |
12813 | update_global_location_list (insert_mode); | |
12814 | } | |
12815 | CATCH (e, RETURN_MASK_ERROR) | |
12816 | { | |
12817 | } | |
12818 | END_CATCH | |
348d480f PA |
12819 | } |
12820 | ||
12821 | /* Clear BKP from a BPS. */ | |
12822 | ||
12823 | static void | |
12824 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12825 | { | |
12826 | bpstat bs; | |
12827 | ||
12828 | for (bs = bps; bs; bs = bs->next) | |
12829 | if (bs->breakpoint_at == bpt) | |
12830 | { | |
12831 | bs->breakpoint_at = NULL; | |
12832 | bs->old_val = NULL; | |
12833 | /* bs->commands will be freed later. */ | |
12834 | } | |
12835 | } | |
12836 | ||
12837 | /* Callback for iterate_over_threads. */ | |
12838 | static int | |
12839 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12840 | { | |
9a3c8263 | 12841 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12842 | |
12843 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12844 | return 0; | |
12845 | } | |
12846 | ||
12847 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12848 | callbacks. */ | |
12849 | ||
12850 | static void | |
12851 | say_where (struct breakpoint *b) | |
12852 | { | |
12853 | struct value_print_options opts; | |
12854 | ||
12855 | get_user_print_options (&opts); | |
12856 | ||
12857 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12858 | single string. */ | |
12859 | if (b->loc == NULL) | |
12860 | { | |
f00aae0f KS |
12861 | /* For pending locations, the output differs slightly based |
12862 | on b->extra_string. If this is non-NULL, it contains either | |
12863 | a condition or dprintf arguments. */ | |
12864 | if (b->extra_string == NULL) | |
12865 | { | |
12866 | printf_filtered (_(" (%s) pending."), | |
12867 | event_location_to_string (b->location)); | |
12868 | } | |
12869 | else if (b->type == bp_dprintf) | |
12870 | { | |
12871 | printf_filtered (_(" (%s,%s) pending."), | |
12872 | event_location_to_string (b->location), | |
12873 | b->extra_string); | |
12874 | } | |
12875 | else | |
12876 | { | |
12877 | printf_filtered (_(" (%s %s) pending."), | |
12878 | event_location_to_string (b->location), | |
12879 | b->extra_string); | |
12880 | } | |
348d480f PA |
12881 | } |
12882 | else | |
12883 | { | |
2f202fde | 12884 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12885 | { |
12886 | printf_filtered (" at "); | |
12887 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12888 | gdb_stdout); | |
12889 | } | |
2f202fde | 12890 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12891 | { |
12892 | /* If there is a single location, we can print the location | |
12893 | more nicely. */ | |
12894 | if (b->loc->next == NULL) | |
12895 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12896 | symtab_to_filename_for_display (b->loc->symtab), |
12897 | b->loc->line_number); | |
f8eba3c6 TT |
12898 | else |
12899 | /* This is not ideal, but each location may have a | |
12900 | different file name, and this at least reflects the | |
12901 | real situation somewhat. */ | |
f00aae0f KS |
12902 | printf_filtered (": %s.", |
12903 | event_location_to_string (b->location)); | |
f8eba3c6 | 12904 | } |
348d480f PA |
12905 | |
12906 | if (b->loc->next) | |
12907 | { | |
12908 | struct bp_location *loc = b->loc; | |
12909 | int n = 0; | |
12910 | for (; loc; loc = loc->next) | |
12911 | ++n; | |
12912 | printf_filtered (" (%d locations)", n); | |
12913 | } | |
12914 | } | |
12915 | } | |
12916 | ||
348d480f PA |
12917 | /* Default bp_location_ops methods. */ |
12918 | ||
12919 | static void | |
12920 | bp_location_dtor (struct bp_location *self) | |
12921 | { | |
12922 | xfree (self->cond); | |
b775012e LM |
12923 | if (self->cond_bytecode) |
12924 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12925 | xfree (self->function_name); |
8b4f3082 PA |
12926 | |
12927 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12928 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12929 | } |
12930 | ||
12931 | static const struct bp_location_ops bp_location_ops = | |
12932 | { | |
12933 | bp_location_dtor | |
12934 | }; | |
12935 | ||
2060206e PA |
12936 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12937 | inherit from. */ | |
348d480f | 12938 | |
2060206e PA |
12939 | static void |
12940 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12941 | { |
12942 | decref_counted_command_line (&self->commands); | |
12943 | xfree (self->cond_string); | |
fb81d016 | 12944 | xfree (self->extra_string); |
f8eba3c6 | 12945 | xfree (self->filter); |
f00aae0f KS |
12946 | delete_event_location (self->location); |
12947 | delete_event_location (self->location_range_end); | |
348d480f PA |
12948 | } |
12949 | ||
2060206e PA |
12950 | static struct bp_location * |
12951 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12952 | { |
12953 | struct bp_location *loc; | |
12954 | ||
12955 | loc = XNEW (struct bp_location); | |
12956 | init_bp_location (loc, &bp_location_ops, self); | |
12957 | return loc; | |
12958 | } | |
12959 | ||
2060206e PA |
12960 | static void |
12961 | base_breakpoint_re_set (struct breakpoint *b) | |
12962 | { | |
12963 | /* Nothing to re-set. */ | |
12964 | } | |
12965 | ||
12966 | #define internal_error_pure_virtual_called() \ | |
12967 | gdb_assert_not_reached ("pure virtual function called") | |
12968 | ||
12969 | static int | |
12970 | base_breakpoint_insert_location (struct bp_location *bl) | |
12971 | { | |
12972 | internal_error_pure_virtual_called (); | |
12973 | } | |
12974 | ||
12975 | static int | |
73971819 PA |
12976 | base_breakpoint_remove_location (struct bp_location *bl, |
12977 | enum remove_bp_reason reason) | |
2060206e PA |
12978 | { |
12979 | internal_error_pure_virtual_called (); | |
12980 | } | |
12981 | ||
12982 | static int | |
12983 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12984 | struct address_space *aspace, | |
09ac7c10 TT |
12985 | CORE_ADDR bp_addr, |
12986 | const struct target_waitstatus *ws) | |
2060206e PA |
12987 | { |
12988 | internal_error_pure_virtual_called (); | |
12989 | } | |
12990 | ||
12991 | static void | |
12992 | base_breakpoint_check_status (bpstat bs) | |
12993 | { | |
12994 | /* Always stop. */ | |
12995 | } | |
12996 | ||
12997 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12998 | errors. */ | |
12999 | ||
13000 | static int | |
13001 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13002 | { | |
13003 | internal_error_pure_virtual_called (); | |
13004 | } | |
13005 | ||
13006 | /* A "resources_needed" breakpoint_ops method that just internal | |
13007 | errors. */ | |
13008 | ||
13009 | static int | |
13010 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13011 | { | |
13012 | internal_error_pure_virtual_called (); | |
13013 | } | |
13014 | ||
13015 | static enum print_stop_action | |
13016 | base_breakpoint_print_it (bpstat bs) | |
13017 | { | |
13018 | internal_error_pure_virtual_called (); | |
13019 | } | |
13020 | ||
13021 | static void | |
13022 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13023 | struct ui_out *uiout) | |
13024 | { | |
13025 | /* nothing */ | |
13026 | } | |
13027 | ||
13028 | static void | |
13029 | base_breakpoint_print_mention (struct breakpoint *b) | |
13030 | { | |
13031 | internal_error_pure_virtual_called (); | |
13032 | } | |
13033 | ||
13034 | static void | |
13035 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13036 | { | |
13037 | internal_error_pure_virtual_called (); | |
13038 | } | |
13039 | ||
983af33b | 13040 | static void |
f00aae0f KS |
13041 | base_breakpoint_create_sals_from_location |
13042 | (const struct event_location *location, | |
13043 | struct linespec_result *canonical, | |
13044 | enum bptype type_wanted) | |
983af33b SDJ |
13045 | { |
13046 | internal_error_pure_virtual_called (); | |
13047 | } | |
13048 | ||
13049 | static void | |
13050 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13051 | struct linespec_result *c, | |
983af33b | 13052 | char *cond_string, |
e7e0cddf | 13053 | char *extra_string, |
983af33b SDJ |
13054 | enum bptype type_wanted, |
13055 | enum bpdisp disposition, | |
13056 | int thread, | |
13057 | int task, int ignore_count, | |
13058 | const struct breakpoint_ops *o, | |
13059 | int from_tty, int enabled, | |
44f238bb | 13060 | int internal, unsigned flags) |
983af33b SDJ |
13061 | { |
13062 | internal_error_pure_virtual_called (); | |
13063 | } | |
13064 | ||
13065 | static void | |
f00aae0f KS |
13066 | base_breakpoint_decode_location (struct breakpoint *b, |
13067 | const struct event_location *location, | |
c2f4122d | 13068 | struct program_space *search_pspace, |
983af33b SDJ |
13069 | struct symtabs_and_lines *sals) |
13070 | { | |
13071 | internal_error_pure_virtual_called (); | |
13072 | } | |
13073 | ||
ab04a2af TT |
13074 | /* The default 'explains_signal' method. */ |
13075 | ||
47591c29 | 13076 | static int |
427cd150 | 13077 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13078 | { |
47591c29 | 13079 | return 1; |
ab04a2af TT |
13080 | } |
13081 | ||
9d6e6e84 HZ |
13082 | /* The default "after_condition_true" method. */ |
13083 | ||
13084 | static void | |
13085 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13086 | { | |
13087 | /* Nothing to do. */ | |
13088 | } | |
13089 | ||
ab04a2af | 13090 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13091 | { |
13092 | base_breakpoint_dtor, | |
13093 | base_breakpoint_allocate_location, | |
13094 | base_breakpoint_re_set, | |
13095 | base_breakpoint_insert_location, | |
13096 | base_breakpoint_remove_location, | |
13097 | base_breakpoint_breakpoint_hit, | |
13098 | base_breakpoint_check_status, | |
13099 | base_breakpoint_resources_needed, | |
13100 | base_breakpoint_works_in_software_mode, | |
13101 | base_breakpoint_print_it, | |
13102 | NULL, | |
13103 | base_breakpoint_print_one_detail, | |
13104 | base_breakpoint_print_mention, | |
983af33b | 13105 | base_breakpoint_print_recreate, |
5f700d83 | 13106 | base_breakpoint_create_sals_from_location, |
983af33b | 13107 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13108 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13109 | base_breakpoint_explains_signal, |
13110 | base_breakpoint_after_condition_true, | |
2060206e PA |
13111 | }; |
13112 | ||
13113 | /* Default breakpoint_ops methods. */ | |
13114 | ||
13115 | static void | |
348d480f PA |
13116 | bkpt_re_set (struct breakpoint *b) |
13117 | { | |
06edf0c0 | 13118 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 13119 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 13120 | { |
f00aae0f | 13121 | /* Anything without a location can't be re-set. */ |
348d480f | 13122 | delete_breakpoint (b); |
06edf0c0 | 13123 | return; |
348d480f | 13124 | } |
06edf0c0 PA |
13125 | |
13126 | breakpoint_re_set_default (b); | |
348d480f PA |
13127 | } |
13128 | ||
2060206e | 13129 | static int |
348d480f PA |
13130 | bkpt_insert_location (struct bp_location *bl) |
13131 | { | |
cd6c3b4f YQ |
13132 | CORE_ADDR addr = bl->target_info.reqstd_address; |
13133 | ||
579c6ad9 | 13134 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
13135 | bl->target_info.placed_address = addr; |
13136 | ||
348d480f | 13137 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 13138 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13139 | else |
7c16b83e | 13140 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13141 | } |
13142 | ||
2060206e | 13143 | static int |
73971819 | 13144 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
13145 | { |
13146 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13147 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13148 | else | |
73971819 | 13149 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
13150 | } |
13151 | ||
2060206e | 13152 | static int |
348d480f | 13153 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13154 | struct address_space *aspace, CORE_ADDR bp_addr, |
13155 | const struct target_waitstatus *ws) | |
348d480f | 13156 | { |
09ac7c10 | 13157 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13158 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13159 | return 0; |
13160 | ||
348d480f PA |
13161 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13162 | aspace, bp_addr)) | |
13163 | return 0; | |
13164 | ||
13165 | if (overlay_debugging /* unmapped overlay section */ | |
13166 | && section_is_overlay (bl->section) | |
13167 | && !section_is_mapped (bl->section)) | |
13168 | return 0; | |
13169 | ||
13170 | return 1; | |
13171 | } | |
13172 | ||
cd1608cc PA |
13173 | static int |
13174 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13175 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13176 | const struct target_waitstatus *ws) | |
13177 | { | |
13178 | if (dprintf_style == dprintf_style_agent | |
13179 | && target_can_run_breakpoint_commands ()) | |
13180 | { | |
13181 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13182 | for this address it must be for a breakpoint that happens to | |
13183 | be set at the same address. */ | |
13184 | return 0; | |
13185 | } | |
13186 | ||
13187 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13188 | } | |
13189 | ||
2060206e | 13190 | static int |
348d480f PA |
13191 | bkpt_resources_needed (const struct bp_location *bl) |
13192 | { | |
13193 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13194 | ||
13195 | return 1; | |
13196 | } | |
13197 | ||
2060206e | 13198 | static enum print_stop_action |
348d480f PA |
13199 | bkpt_print_it (bpstat bs) |
13200 | { | |
348d480f PA |
13201 | struct breakpoint *b; |
13202 | const struct bp_location *bl; | |
001c8c33 | 13203 | int bp_temp; |
79a45e25 | 13204 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13205 | |
13206 | gdb_assert (bs->bp_location_at != NULL); | |
13207 | ||
13208 | bl = bs->bp_location_at; | |
13209 | b = bs->breakpoint_at; | |
13210 | ||
001c8c33 PA |
13211 | bp_temp = b->disposition == disp_del; |
13212 | if (bl->address != bl->requested_address) | |
13213 | breakpoint_adjustment_warning (bl->requested_address, | |
13214 | bl->address, | |
13215 | b->number, 1); | |
13216 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13217 | maybe_print_thread_hit_breakpoint (uiout); |
13218 | ||
001c8c33 | 13219 | if (bp_temp) |
f303dbd6 | 13220 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13221 | else |
f303dbd6 | 13222 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13223 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13224 | { |
001c8c33 PA |
13225 | ui_out_field_string (uiout, "reason", |
13226 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13227 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13228 | } |
001c8c33 PA |
13229 | ui_out_field_int (uiout, "bkptno", b->number); |
13230 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13231 | |
001c8c33 | 13232 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13233 | } |
13234 | ||
2060206e | 13235 | static void |
06edf0c0 PA |
13236 | bkpt_print_mention (struct breakpoint *b) |
13237 | { | |
79a45e25 | 13238 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13239 | return; |
13240 | ||
13241 | switch (b->type) | |
13242 | { | |
13243 | case bp_breakpoint: | |
13244 | case bp_gnu_ifunc_resolver: | |
13245 | if (b->disposition == disp_del) | |
13246 | printf_filtered (_("Temporary breakpoint")); | |
13247 | else | |
13248 | printf_filtered (_("Breakpoint")); | |
13249 | printf_filtered (_(" %d"), b->number); | |
13250 | if (b->type == bp_gnu_ifunc_resolver) | |
13251 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13252 | break; | |
13253 | case bp_hardware_breakpoint: | |
13254 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13255 | break; | |
e7e0cddf SS |
13256 | case bp_dprintf: |
13257 | printf_filtered (_("Dprintf %d"), b->number); | |
13258 | break; | |
06edf0c0 PA |
13259 | } |
13260 | ||
13261 | say_where (b); | |
13262 | } | |
13263 | ||
2060206e | 13264 | static void |
06edf0c0 PA |
13265 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13266 | { | |
13267 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13268 | fprintf_unfiltered (fp, "tbreak"); | |
13269 | else if (tp->type == bp_breakpoint) | |
13270 | fprintf_unfiltered (fp, "break"); | |
13271 | else if (tp->type == bp_hardware_breakpoint | |
13272 | && tp->disposition == disp_del) | |
13273 | fprintf_unfiltered (fp, "thbreak"); | |
13274 | else if (tp->type == bp_hardware_breakpoint) | |
13275 | fprintf_unfiltered (fp, "hbreak"); | |
13276 | else | |
13277 | internal_error (__FILE__, __LINE__, | |
13278 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13279 | ||
f00aae0f KS |
13280 | fprintf_unfiltered (fp, " %s", |
13281 | event_location_to_string (tp->location)); | |
13282 | ||
13283 | /* Print out extra_string if this breakpoint is pending. It might | |
13284 | contain, for example, conditions that were set by the user. */ | |
13285 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13286 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13287 | ||
dd11a36c | 13288 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13289 | } |
13290 | ||
983af33b | 13291 | static void |
f00aae0f KS |
13292 | bkpt_create_sals_from_location (const struct event_location *location, |
13293 | struct linespec_result *canonical, | |
13294 | enum bptype type_wanted) | |
983af33b | 13295 | { |
f00aae0f | 13296 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13297 | } |
13298 | ||
13299 | static void | |
13300 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13301 | struct linespec_result *canonical, | |
983af33b | 13302 | char *cond_string, |
e7e0cddf | 13303 | char *extra_string, |
983af33b SDJ |
13304 | enum bptype type_wanted, |
13305 | enum bpdisp disposition, | |
13306 | int thread, | |
13307 | int task, int ignore_count, | |
13308 | const struct breakpoint_ops *ops, | |
13309 | int from_tty, int enabled, | |
44f238bb | 13310 | int internal, unsigned flags) |
983af33b | 13311 | { |
023fa29b | 13312 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13313 | cond_string, extra_string, |
13314 | type_wanted, | |
983af33b SDJ |
13315 | disposition, thread, task, |
13316 | ignore_count, ops, from_tty, | |
44f238bb | 13317 | enabled, internal, flags); |
983af33b SDJ |
13318 | } |
13319 | ||
13320 | static void | |
f00aae0f KS |
13321 | bkpt_decode_location (struct breakpoint *b, |
13322 | const struct event_location *location, | |
c2f4122d | 13323 | struct program_space *search_pspace, |
983af33b SDJ |
13324 | struct symtabs_and_lines *sals) |
13325 | { | |
c2f4122d | 13326 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13327 | } |
13328 | ||
06edf0c0 PA |
13329 | /* Virtual table for internal breakpoints. */ |
13330 | ||
13331 | static void | |
13332 | internal_bkpt_re_set (struct breakpoint *b) | |
13333 | { | |
13334 | switch (b->type) | |
13335 | { | |
13336 | /* Delete overlay event and longjmp master breakpoints; they | |
13337 | will be reset later by breakpoint_re_set. */ | |
13338 | case bp_overlay_event: | |
13339 | case bp_longjmp_master: | |
13340 | case bp_std_terminate_master: | |
13341 | case bp_exception_master: | |
13342 | delete_breakpoint (b); | |
13343 | break; | |
13344 | ||
13345 | /* This breakpoint is special, it's set up when the inferior | |
13346 | starts and we really don't want to touch it. */ | |
13347 | case bp_shlib_event: | |
13348 | ||
13349 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13350 | it is set up, we do not want to touch it. */ | |
13351 | case bp_thread_event: | |
13352 | break; | |
13353 | } | |
13354 | } | |
13355 | ||
13356 | static void | |
13357 | internal_bkpt_check_status (bpstat bs) | |
13358 | { | |
a9b3a50f PA |
13359 | if (bs->breakpoint_at->type == bp_shlib_event) |
13360 | { | |
13361 | /* If requested, stop when the dynamic linker notifies GDB of | |
13362 | events. This allows the user to get control and place | |
13363 | breakpoints in initializer routines for dynamically loaded | |
13364 | objects (among other things). */ | |
13365 | bs->stop = stop_on_solib_events; | |
13366 | bs->print = stop_on_solib_events; | |
13367 | } | |
13368 | else | |
13369 | bs->stop = 0; | |
06edf0c0 PA |
13370 | } |
13371 | ||
13372 | static enum print_stop_action | |
13373 | internal_bkpt_print_it (bpstat bs) | |
13374 | { | |
06edf0c0 | 13375 | struct breakpoint *b; |
06edf0c0 | 13376 | |
06edf0c0 PA |
13377 | b = bs->breakpoint_at; |
13378 | ||
06edf0c0 PA |
13379 | switch (b->type) |
13380 | { | |
348d480f PA |
13381 | case bp_shlib_event: |
13382 | /* Did we stop because the user set the stop_on_solib_events | |
13383 | variable? (If so, we report this as a generic, "Stopped due | |
13384 | to shlib event" message.) */ | |
edcc5120 | 13385 | print_solib_event (0); |
348d480f PA |
13386 | break; |
13387 | ||
13388 | case bp_thread_event: | |
13389 | /* Not sure how we will get here. | |
13390 | GDB should not stop for these breakpoints. */ | |
13391 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13392 | break; |
13393 | ||
13394 | case bp_overlay_event: | |
13395 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13396 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13397 | break; |
13398 | ||
13399 | case bp_longjmp_master: | |
13400 | /* These should never be enabled. */ | |
13401 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13402 | break; |
13403 | ||
13404 | case bp_std_terminate_master: | |
13405 | /* These should never be enabled. */ | |
13406 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13407 | "gdb should not stop!\n")); | |
348d480f PA |
13408 | break; |
13409 | ||
13410 | case bp_exception_master: | |
13411 | /* These should never be enabled. */ | |
13412 | printf_filtered (_("Exception Master Breakpoint: " | |
13413 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13414 | break; |
13415 | } | |
13416 | ||
001c8c33 | 13417 | return PRINT_NOTHING; |
06edf0c0 PA |
13418 | } |
13419 | ||
13420 | static void | |
13421 | internal_bkpt_print_mention (struct breakpoint *b) | |
13422 | { | |
13423 | /* Nothing to mention. These breakpoints are internal. */ | |
13424 | } | |
13425 | ||
06edf0c0 PA |
13426 | /* Virtual table for momentary breakpoints */ |
13427 | ||
13428 | static void | |
13429 | momentary_bkpt_re_set (struct breakpoint *b) | |
13430 | { | |
13431 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13432 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13433 | Otherwise these should have been blown away via the cleanup chain |
13434 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13435 | } | |
13436 | ||
13437 | static void | |
13438 | momentary_bkpt_check_status (bpstat bs) | |
13439 | { | |
13440 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13441 | } | |
13442 | ||
13443 | static enum print_stop_action | |
13444 | momentary_bkpt_print_it (bpstat bs) | |
13445 | { | |
001c8c33 | 13446 | return PRINT_UNKNOWN; |
348d480f PA |
13447 | } |
13448 | ||
06edf0c0 PA |
13449 | static void |
13450 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13451 | { |
06edf0c0 | 13452 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13453 | } |
13454 | ||
e2e4d78b JK |
13455 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13456 | ||
13457 | It gets cleared already on the removal of the first one of such placed | |
13458 | breakpoints. This is OK as they get all removed altogether. */ | |
13459 | ||
13460 | static void | |
13461 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13462 | { | |
5d5658a1 | 13463 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13464 | |
13465 | if (tp) | |
13466 | tp->initiating_frame = null_frame_id; | |
13467 | ||
13468 | momentary_breakpoint_ops.dtor (self); | |
13469 | } | |
13470 | ||
55aa24fb SDJ |
13471 | /* Specific methods for probe breakpoints. */ |
13472 | ||
13473 | static int | |
13474 | bkpt_probe_insert_location (struct bp_location *bl) | |
13475 | { | |
13476 | int v = bkpt_insert_location (bl); | |
13477 | ||
13478 | if (v == 0) | |
13479 | { | |
13480 | /* The insertion was successful, now let's set the probe's semaphore | |
13481 | if needed. */ | |
0ea5cda8 SDJ |
13482 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13483 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13484 | bl->probe.objfile, | |
13485 | bl->gdbarch); | |
55aa24fb SDJ |
13486 | } |
13487 | ||
13488 | return v; | |
13489 | } | |
13490 | ||
13491 | static int | |
73971819 PA |
13492 | bkpt_probe_remove_location (struct bp_location *bl, |
13493 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13494 | { |
13495 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13496 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13497 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13498 | bl->probe.objfile, | |
13499 | bl->gdbarch); | |
55aa24fb | 13500 | |
73971819 | 13501 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13502 | } |
13503 | ||
13504 | static void | |
f00aae0f | 13505 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13506 | struct linespec_result *canonical, |
f00aae0f | 13507 | enum bptype type_wanted) |
55aa24fb SDJ |
13508 | { |
13509 | struct linespec_sals lsal; | |
13510 | ||
c2f4122d | 13511 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13512 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13513 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13514 | } | |
13515 | ||
13516 | static void | |
f00aae0f KS |
13517 | bkpt_probe_decode_location (struct breakpoint *b, |
13518 | const struct event_location *location, | |
c2f4122d | 13519 | struct program_space *search_pspace, |
55aa24fb SDJ |
13520 | struct symtabs_and_lines *sals) |
13521 | { | |
c2f4122d | 13522 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13523 | if (!sals->sals) |
13524 | error (_("probe not found")); | |
13525 | } | |
13526 | ||
348d480f | 13527 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13528 | |
348d480f PA |
13529 | static void |
13530 | tracepoint_re_set (struct breakpoint *b) | |
13531 | { | |
13532 | breakpoint_re_set_default (b); | |
13533 | } | |
876fa593 | 13534 | |
348d480f PA |
13535 | static int |
13536 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13537 | struct address_space *aspace, CORE_ADDR bp_addr, |
13538 | const struct target_waitstatus *ws) | |
348d480f PA |
13539 | { |
13540 | /* By definition, the inferior does not report stops at | |
13541 | tracepoints. */ | |
13542 | return 0; | |
74960c60 VP |
13543 | } |
13544 | ||
13545 | static void | |
348d480f PA |
13546 | tracepoint_print_one_detail (const struct breakpoint *self, |
13547 | struct ui_out *uiout) | |
74960c60 | 13548 | { |
d9b3f62e PA |
13549 | struct tracepoint *tp = (struct tracepoint *) self; |
13550 | if (tp->static_trace_marker_id) | |
348d480f PA |
13551 | { |
13552 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13553 | |
348d480f PA |
13554 | ui_out_text (uiout, "\tmarker id is "); |
13555 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13556 | tp->static_trace_marker_id); |
348d480f PA |
13557 | ui_out_text (uiout, "\n"); |
13558 | } | |
0d381245 VP |
13559 | } |
13560 | ||
a474d7c2 | 13561 | static void |
348d480f | 13562 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13563 | { |
79a45e25 | 13564 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13565 | return; |
cc59ec59 | 13566 | |
348d480f PA |
13567 | switch (b->type) |
13568 | { | |
13569 | case bp_tracepoint: | |
13570 | printf_filtered (_("Tracepoint")); | |
13571 | printf_filtered (_(" %d"), b->number); | |
13572 | break; | |
13573 | case bp_fast_tracepoint: | |
13574 | printf_filtered (_("Fast tracepoint")); | |
13575 | printf_filtered (_(" %d"), b->number); | |
13576 | break; | |
13577 | case bp_static_tracepoint: | |
13578 | printf_filtered (_("Static tracepoint")); | |
13579 | printf_filtered (_(" %d"), b->number); | |
13580 | break; | |
13581 | default: | |
13582 | internal_error (__FILE__, __LINE__, | |
13583 | _("unhandled tracepoint type %d"), (int) b->type); | |
13584 | } | |
13585 | ||
13586 | say_where (b); | |
a474d7c2 PA |
13587 | } |
13588 | ||
348d480f | 13589 | static void |
d9b3f62e | 13590 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13591 | { |
d9b3f62e PA |
13592 | struct tracepoint *tp = (struct tracepoint *) self; |
13593 | ||
13594 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13595 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13596 | else if (self->type == bp_static_tracepoint) |
348d480f | 13597 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13598 | else if (self->type == bp_tracepoint) |
348d480f PA |
13599 | fprintf_unfiltered (fp, "trace"); |
13600 | else | |
13601 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13602 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13603 | |
f00aae0f KS |
13604 | fprintf_unfiltered (fp, " %s", |
13605 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13606 | print_recreate_thread (self, fp); |
13607 | ||
13608 | if (tp->pass_count) | |
13609 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13610 | } |
13611 | ||
983af33b | 13612 | static void |
f00aae0f KS |
13613 | tracepoint_create_sals_from_location (const struct event_location *location, |
13614 | struct linespec_result *canonical, | |
13615 | enum bptype type_wanted) | |
983af33b | 13616 | { |
f00aae0f | 13617 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13618 | } |
13619 | ||
13620 | static void | |
13621 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13622 | struct linespec_result *canonical, | |
983af33b | 13623 | char *cond_string, |
e7e0cddf | 13624 | char *extra_string, |
983af33b SDJ |
13625 | enum bptype type_wanted, |
13626 | enum bpdisp disposition, | |
13627 | int thread, | |
13628 | int task, int ignore_count, | |
13629 | const struct breakpoint_ops *ops, | |
13630 | int from_tty, int enabled, | |
44f238bb | 13631 | int internal, unsigned flags) |
983af33b | 13632 | { |
023fa29b | 13633 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13634 | cond_string, extra_string, |
13635 | type_wanted, | |
983af33b SDJ |
13636 | disposition, thread, task, |
13637 | ignore_count, ops, from_tty, | |
44f238bb | 13638 | enabled, internal, flags); |
983af33b SDJ |
13639 | } |
13640 | ||
13641 | static void | |
f00aae0f KS |
13642 | tracepoint_decode_location (struct breakpoint *b, |
13643 | const struct event_location *location, | |
c2f4122d | 13644 | struct program_space *search_pspace, |
983af33b SDJ |
13645 | struct symtabs_and_lines *sals) |
13646 | { | |
c2f4122d | 13647 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13648 | } |
13649 | ||
2060206e | 13650 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13651 | |
55aa24fb SDJ |
13652 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13653 | static probe. */ | |
13654 | ||
13655 | static void | |
f00aae0f KS |
13656 | tracepoint_probe_create_sals_from_location |
13657 | (const struct event_location *location, | |
13658 | struct linespec_result *canonical, | |
13659 | enum bptype type_wanted) | |
55aa24fb SDJ |
13660 | { |
13661 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13662 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13663 | } |
13664 | ||
13665 | static void | |
f00aae0f KS |
13666 | tracepoint_probe_decode_location (struct breakpoint *b, |
13667 | const struct event_location *location, | |
c2f4122d | 13668 | struct program_space *search_pspace, |
55aa24fb SDJ |
13669 | struct symtabs_and_lines *sals) |
13670 | { | |
13671 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13672 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13673 | } |
13674 | ||
13675 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13676 | ||
5c2b4418 HZ |
13677 | /* Dprintf breakpoint_ops methods. */ |
13678 | ||
13679 | static void | |
13680 | dprintf_re_set (struct breakpoint *b) | |
13681 | { | |
13682 | breakpoint_re_set_default (b); | |
13683 | ||
f00aae0f KS |
13684 | /* extra_string should never be non-NULL for dprintf. */ |
13685 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13686 | |
13687 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13688 | 2 - create a dprintf, which resolves fine. | |
13689 | 3 - disconnect from target 1 | |
13690 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13691 | ||
13692 | After steps #3/#4, you'll want the dprintf command list to | |
13693 | be updated, because target 1 and 2 may well return different | |
13694 | answers for target_can_run_breakpoint_commands(). | |
13695 | Given absence of finer grained resetting, we get to do | |
13696 | it all the time. */ | |
13697 | if (b->extra_string != NULL) | |
13698 | update_dprintf_command_list (b); | |
13699 | } | |
13700 | ||
2d9442cc HZ |
13701 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13702 | ||
13703 | static void | |
13704 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13705 | { | |
f00aae0f KS |
13706 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13707 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13708 | tp->extra_string); |
13709 | print_recreate_thread (tp, fp); | |
13710 | } | |
13711 | ||
9d6e6e84 HZ |
13712 | /* Implement the "after_condition_true" breakpoint_ops method for |
13713 | dprintf. | |
13714 | ||
13715 | dprintf's are implemented with regular commands in their command | |
13716 | list, but we run the commands here instead of before presenting the | |
13717 | stop to the user, as dprintf's don't actually cause a stop. This | |
13718 | also makes it so that the commands of multiple dprintfs at the same | |
13719 | address are all handled. */ | |
13720 | ||
13721 | static void | |
13722 | dprintf_after_condition_true (struct bpstats *bs) | |
13723 | { | |
13724 | struct cleanup *old_chain; | |
13725 | struct bpstats tmp_bs = { NULL }; | |
13726 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13727 | ||
13728 | /* dprintf's never cause a stop. This wasn't set in the | |
13729 | check_status hook instead because that would make the dprintf's | |
13730 | condition not be evaluated. */ | |
13731 | bs->stop = 0; | |
13732 | ||
13733 | /* Run the command list here. Take ownership of it instead of | |
13734 | copying. We never want these commands to run later in | |
13735 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13736 | be set at same address as this dprintf, or even if running the | |
13737 | commands here throws. */ | |
13738 | tmp_bs.commands = bs->commands; | |
13739 | bs->commands = NULL; | |
13740 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13741 | ||
13742 | bpstat_do_actions_1 (&tmp_bs_p); | |
13743 | ||
13744 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13745 | bpstat_do_actions_1 may return early without processing the whole | |
13746 | list. */ | |
13747 | do_cleanups (old_chain); | |
13748 | } | |
13749 | ||
983af33b SDJ |
13750 | /* The breakpoint_ops structure to be used on static tracepoints with |
13751 | markers (`-m'). */ | |
13752 | ||
13753 | static void | |
f00aae0f | 13754 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13755 | struct linespec_result *canonical, |
f00aae0f | 13756 | enum bptype type_wanted) |
983af33b SDJ |
13757 | { |
13758 | struct linespec_sals lsal; | |
f00aae0f KS |
13759 | const char *arg_start, *arg; |
13760 | char *str; | |
13761 | struct cleanup *cleanup; | |
983af33b | 13762 | |
f00aae0f KS |
13763 | arg = arg_start = get_linespec_location (location); |
13764 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13765 | |
f00aae0f KS |
13766 | str = savestring (arg_start, arg - arg_start); |
13767 | cleanup = make_cleanup (xfree, str); | |
13768 | canonical->location = new_linespec_location (&str); | |
13769 | do_cleanups (cleanup); | |
983af33b | 13770 | |
f00aae0f | 13771 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13772 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13773 | } | |
13774 | ||
13775 | static void | |
13776 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13777 | struct linespec_result *canonical, | |
983af33b | 13778 | char *cond_string, |
e7e0cddf | 13779 | char *extra_string, |
983af33b SDJ |
13780 | enum bptype type_wanted, |
13781 | enum bpdisp disposition, | |
13782 | int thread, | |
13783 | int task, int ignore_count, | |
13784 | const struct breakpoint_ops *ops, | |
13785 | int from_tty, int enabled, | |
44f238bb | 13786 | int internal, unsigned flags) |
983af33b SDJ |
13787 | { |
13788 | int i; | |
52d361e1 YQ |
13789 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13790 | canonical->sals, 0); | |
983af33b SDJ |
13791 | |
13792 | /* If the user is creating a static tracepoint by marker id | |
13793 | (strace -m MARKER_ID), then store the sals index, so that | |
13794 | breakpoint_re_set can try to match up which of the newly | |
13795 | found markers corresponds to this one, and, don't try to | |
13796 | expand multiple locations for each sal, given than SALS | |
13797 | already should contain all sals for MARKER_ID. */ | |
13798 | ||
13799 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13800 | { | |
13801 | struct symtabs_and_lines expanded; | |
13802 | struct tracepoint *tp; | |
13803 | struct cleanup *old_chain; | |
f00aae0f | 13804 | struct event_location *location; |
983af33b SDJ |
13805 | |
13806 | expanded.nelts = 1; | |
13807 | expanded.sals = &lsal->sals.sals[i]; | |
13808 | ||
f00aae0f KS |
13809 | location = copy_event_location (canonical->location); |
13810 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13811 | |
13812 | tp = XCNEW (struct tracepoint); | |
13813 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13814 | location, NULL, |
e7e0cddf SS |
13815 | cond_string, extra_string, |
13816 | type_wanted, disposition, | |
983af33b | 13817 | thread, task, ignore_count, ops, |
44f238bb | 13818 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13819 | canonical->special_display); |
13820 | /* Given that its possible to have multiple markers with | |
13821 | the same string id, if the user is creating a static | |
13822 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13823 | store the sals index, so that breakpoint_re_set can | |
13824 | try to match up which of the newly found markers | |
13825 | corresponds to this one */ | |
13826 | tp->static_trace_marker_id_idx = i; | |
13827 | ||
13828 | install_breakpoint (internal, &tp->base, 0); | |
13829 | ||
13830 | discard_cleanups (old_chain); | |
13831 | } | |
13832 | } | |
13833 | ||
13834 | static void | |
f00aae0f KS |
13835 | strace_marker_decode_location (struct breakpoint *b, |
13836 | const struct event_location *location, | |
c2f4122d | 13837 | struct program_space *search_pspace, |
983af33b SDJ |
13838 | struct symtabs_and_lines *sals) |
13839 | { | |
13840 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13841 | const char *s = get_linespec_location (location); |
983af33b | 13842 | |
f00aae0f | 13843 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13844 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13845 | { | |
13846 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13847 | sals->nelts = 1; | |
13848 | } | |
13849 | else | |
13850 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13851 | } | |
13852 | ||
13853 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13854 | ||
13855 | static int | |
13856 | strace_marker_p (struct breakpoint *b) | |
13857 | { | |
13858 | return b->ops == &strace_marker_breakpoint_ops; | |
13859 | } | |
13860 | ||
53a5351d | 13861 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13862 | structures. */ |
c906108c SS |
13863 | |
13864 | void | |
fba45db2 | 13865 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13866 | { |
52f0bd74 | 13867 | struct breakpoint *b; |
c906108c | 13868 | |
8a3fe4f8 | 13869 | gdb_assert (bpt != NULL); |
c906108c | 13870 | |
4a64f543 MS |
13871 | /* Has this bp already been deleted? This can happen because |
13872 | multiple lists can hold pointers to bp's. bpstat lists are | |
13873 | especial culprits. | |
13874 | ||
13875 | One example of this happening is a watchpoint's scope bp. When | |
13876 | the scope bp triggers, we notice that the watchpoint is out of | |
13877 | scope, and delete it. We also delete its scope bp. But the | |
13878 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13879 | That bpstat is then checked for auto-deleting bp's, which are | |
13880 | deleted. | |
13881 | ||
13882 | A real solution to this problem might involve reference counts in | |
13883 | bp's, and/or giving them pointers back to their referencing | |
13884 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13885 | storage when no more references were extent. A cheaper bandaid | |
13886 | was chosen. */ | |
c906108c SS |
13887 | if (bpt->type == bp_none) |
13888 | return; | |
13889 | ||
4a64f543 MS |
13890 | /* At least avoid this stale reference until the reference counting |
13891 | of breakpoints gets resolved. */ | |
d0fb5eae | 13892 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13893 | { |
d0fb5eae | 13894 | struct breakpoint *related; |
3a5c3e22 | 13895 | struct watchpoint *w; |
d0fb5eae JK |
13896 | |
13897 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13898 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13899 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13900 | w = (struct watchpoint *) bpt; |
13901 | else | |
13902 | w = NULL; | |
13903 | if (w != NULL) | |
13904 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13905 | |
13906 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13907 | for (related = bpt; related->related_breakpoint != bpt; | |
13908 | related = related->related_breakpoint); | |
13909 | related->related_breakpoint = bpt->related_breakpoint; | |
13910 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13911 | } |
13912 | ||
a9634178 TJB |
13913 | /* watch_command_1 creates a watchpoint but only sets its number if |
13914 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13915 | a problem in that process, we'll be asked to delete the half-created | |
13916 | watchpoint. In that case, don't announce the deletion. */ | |
13917 | if (bpt->number) | |
13918 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13919 | |
c906108c SS |
13920 | if (breakpoint_chain == bpt) |
13921 | breakpoint_chain = bpt->next; | |
13922 | ||
c906108c SS |
13923 | ALL_BREAKPOINTS (b) |
13924 | if (b->next == bpt) | |
c5aa993b JM |
13925 | { |
13926 | b->next = bpt->next; | |
13927 | break; | |
13928 | } | |
c906108c | 13929 | |
f431efe5 PA |
13930 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13931 | been freed. */ | |
13932 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13933 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13934 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13935 | commands are associated with the bpstat; if we remove it here, | |
13936 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13937 | event-top.c won't do anything, and temporary breakpoints with | |
13938 | commands won't work. */ | |
13939 | ||
13940 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13941 | ||
4a64f543 MS |
13942 | /* Now that breakpoint is removed from breakpoint list, update the |
13943 | global location list. This will remove locations that used to | |
13944 | belong to this breakpoint. Do this before freeing the breakpoint | |
13945 | itself, since remove_breakpoint looks at location's owner. It | |
13946 | might be better design to have location completely | |
13947 | self-contained, but it's not the case now. */ | |
44702360 | 13948 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13949 | |
348d480f | 13950 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13951 | /* On the chance that someone will soon try again to delete this |
13952 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13953 | bpt->type = bp_none; |
b8c9b27d | 13954 | xfree (bpt); |
c906108c SS |
13955 | } |
13956 | ||
4d6140d9 AC |
13957 | static void |
13958 | do_delete_breakpoint_cleanup (void *b) | |
13959 | { | |
9a3c8263 | 13960 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13961 | } |
13962 | ||
13963 | struct cleanup * | |
13964 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13965 | { | |
13966 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13967 | } | |
13968 | ||
51be5b68 PA |
13969 | /* Iterator function to call a user-provided callback function once |
13970 | for each of B and its related breakpoints. */ | |
13971 | ||
13972 | static void | |
13973 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13974 | void (*function) (struct breakpoint *, | |
13975 | void *), | |
13976 | void *data) | |
13977 | { | |
13978 | struct breakpoint *related; | |
13979 | ||
13980 | related = b; | |
13981 | do | |
13982 | { | |
13983 | struct breakpoint *next; | |
13984 | ||
13985 | /* FUNCTION may delete RELATED. */ | |
13986 | next = related->related_breakpoint; | |
13987 | ||
13988 | if (next == related) | |
13989 | { | |
13990 | /* RELATED is the last ring entry. */ | |
13991 | function (related, data); | |
13992 | ||
13993 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13994 | B. There's nothing left to do anyway, so just break | |
13995 | out. */ | |
13996 | break; | |
13997 | } | |
13998 | else | |
13999 | function (related, data); | |
14000 | ||
14001 | related = next; | |
14002 | } | |
14003 | while (related != b); | |
14004 | } | |
95a42b64 TT |
14005 | |
14006 | static void | |
14007 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14008 | { | |
14009 | delete_breakpoint (b); | |
14010 | } | |
14011 | ||
51be5b68 PA |
14012 | /* A callback for map_breakpoint_numbers that calls |
14013 | delete_breakpoint. */ | |
14014 | ||
14015 | static void | |
14016 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14017 | { | |
14018 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14019 | } | |
14020 | ||
c906108c | 14021 | void |
fba45db2 | 14022 | delete_command (char *arg, int from_tty) |
c906108c | 14023 | { |
35df4500 | 14024 | struct breakpoint *b, *b_tmp; |
c906108c | 14025 | |
ea9365bb TT |
14026 | dont_repeat (); |
14027 | ||
c906108c SS |
14028 | if (arg == 0) |
14029 | { | |
14030 | int breaks_to_delete = 0; | |
14031 | ||
46c6471b PA |
14032 | /* Delete all breakpoints if no argument. Do not delete |
14033 | internal breakpoints, these have to be deleted with an | |
14034 | explicit breakpoint number argument. */ | |
c5aa993b | 14035 | ALL_BREAKPOINTS (b) |
46c6471b | 14036 | if (user_breakpoint_p (b)) |
973d738b DJ |
14037 | { |
14038 | breaks_to_delete = 1; | |
14039 | break; | |
14040 | } | |
c906108c SS |
14041 | |
14042 | /* Ask user only if there are some breakpoints to delete. */ | |
14043 | if (!from_tty | |
e2e0b3e5 | 14044 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14045 | { |
35df4500 | 14046 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14047 | if (user_breakpoint_p (b)) |
c5aa993b | 14048 | delete_breakpoint (b); |
c906108c SS |
14049 | } |
14050 | } | |
14051 | else | |
51be5b68 | 14052 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14053 | } |
14054 | ||
c2f4122d PA |
14055 | /* Return true if all locations of B bound to PSPACE are pending. If |
14056 | PSPACE is NULL, all locations of all program spaces are | |
14057 | considered. */ | |
14058 | ||
0d381245 | 14059 | static int |
c2f4122d | 14060 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14061 | { |
c2f4122d PA |
14062 | struct bp_location *loc; |
14063 | ||
14064 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14065 | if ((pspace == NULL | |
14066 | || loc->pspace == pspace) | |
14067 | && !loc->shlib_disabled | |
8645ff69 | 14068 | && !loc->pspace->executing_startup) |
0d381245 VP |
14069 | return 0; |
14070 | return 1; | |
fe3f5fa8 VP |
14071 | } |
14072 | ||
776592bf DE |
14073 | /* Subroutine of update_breakpoint_locations to simplify it. |
14074 | Return non-zero if multiple fns in list LOC have the same name. | |
14075 | Null names are ignored. */ | |
14076 | ||
14077 | static int | |
14078 | ambiguous_names_p (struct bp_location *loc) | |
14079 | { | |
14080 | struct bp_location *l; | |
14081 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14082 | (int (*) (const void *, |
14083 | const void *)) streq, | |
776592bf DE |
14084 | NULL, xcalloc, xfree); |
14085 | ||
14086 | for (l = loc; l != NULL; l = l->next) | |
14087 | { | |
14088 | const char **slot; | |
14089 | const char *name = l->function_name; | |
14090 | ||
14091 | /* Allow for some names to be NULL, ignore them. */ | |
14092 | if (name == NULL) | |
14093 | continue; | |
14094 | ||
14095 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14096 | INSERT); | |
4a64f543 MS |
14097 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14098 | returns NULL. */ | |
776592bf DE |
14099 | if (*slot != NULL) |
14100 | { | |
14101 | htab_delete (htab); | |
14102 | return 1; | |
14103 | } | |
14104 | *slot = name; | |
14105 | } | |
14106 | ||
14107 | htab_delete (htab); | |
14108 | return 0; | |
14109 | } | |
14110 | ||
0fb4aa4b PA |
14111 | /* When symbols change, it probably means the sources changed as well, |
14112 | and it might mean the static tracepoint markers are no longer at | |
14113 | the same address or line numbers they used to be at last we | |
14114 | checked. Losing your static tracepoints whenever you rebuild is | |
14115 | undesirable. This function tries to resync/rematch gdb static | |
14116 | tracepoints with the markers on the target, for static tracepoints | |
14117 | that have not been set by marker id. Static tracepoint that have | |
14118 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14119 | The heuristic is: | |
14120 | ||
14121 | 1) For a tracepoint set at a specific address, look for a marker at | |
14122 | the old PC. If one is found there, assume to be the same marker. | |
14123 | If the name / string id of the marker found is different from the | |
14124 | previous known name, assume that means the user renamed the marker | |
14125 | in the sources, and output a warning. | |
14126 | ||
14127 | 2) For a tracepoint set at a given line number, look for a marker | |
14128 | at the new address of the old line number. If one is found there, | |
14129 | assume to be the same marker. If the name / string id of the | |
14130 | marker found is different from the previous known name, assume that | |
14131 | means the user renamed the marker in the sources, and output a | |
14132 | warning. | |
14133 | ||
14134 | 3) If a marker is no longer found at the same address or line, it | |
14135 | may mean the marker no longer exists. But it may also just mean | |
14136 | the code changed a bit. Maybe the user added a few lines of code | |
14137 | that made the marker move up or down (in line number terms). Ask | |
14138 | the target for info about the marker with the string id as we knew | |
14139 | it. If found, update line number and address in the matching | |
14140 | static tracepoint. This will get confused if there's more than one | |
14141 | marker with the same ID (possible in UST, although unadvised | |
14142 | precisely because it confuses tools). */ | |
14143 | ||
14144 | static struct symtab_and_line | |
14145 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14146 | { | |
d9b3f62e | 14147 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14148 | struct static_tracepoint_marker marker; |
14149 | CORE_ADDR pc; | |
0fb4aa4b PA |
14150 | |
14151 | pc = sal.pc; | |
14152 | if (sal.line) | |
14153 | find_line_pc (sal.symtab, sal.line, &pc); | |
14154 | ||
14155 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14156 | { | |
d9b3f62e | 14157 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14158 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14159 | b->number, | |
d9b3f62e | 14160 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14161 | |
d9b3f62e PA |
14162 | xfree (tp->static_trace_marker_id); |
14163 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14164 | release_static_tracepoint_marker (&marker); |
14165 | ||
14166 | return sal; | |
14167 | } | |
14168 | ||
14169 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14170 | by string ID. */ | |
14171 | if (!sal.explicit_pc | |
14172 | && sal.line != 0 | |
14173 | && sal.symtab != NULL | |
d9b3f62e | 14174 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14175 | { |
14176 | VEC(static_tracepoint_marker_p) *markers; | |
14177 | ||
14178 | markers | |
d9b3f62e | 14179 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14180 | |
14181 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14182 | { | |
80e1d417 | 14183 | struct symtab_and_line sal2; |
0fb4aa4b | 14184 | struct symbol *sym; |
80e1d417 | 14185 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14186 | struct ui_out *uiout = current_uiout; |
67994074 | 14187 | struct explicit_location explicit_loc; |
0fb4aa4b | 14188 | |
80e1d417 | 14189 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14190 | |
d9b3f62e | 14191 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14192 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14193 | |
14194 | warning (_("marker for static tracepoint %d (%s) not " | |
14195 | "found at previous line number"), | |
d9b3f62e | 14196 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14197 | |
80e1d417 | 14198 | init_sal (&sal2); |
0fb4aa4b | 14199 | |
80e1d417 | 14200 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14201 | |
80e1d417 AS |
14202 | sal2 = find_pc_line (tpmarker->address, 0); |
14203 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14204 | ui_out_text (uiout, "Now in "); |
14205 | if (sym) | |
14206 | { | |
14207 | ui_out_field_string (uiout, "func", | |
14208 | SYMBOL_PRINT_NAME (sym)); | |
14209 | ui_out_text (uiout, " at "); | |
14210 | } | |
05cba821 JK |
14211 | ui_out_field_string (uiout, "file", |
14212 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14213 | ui_out_text (uiout, ":"); |
14214 | ||
14215 | if (ui_out_is_mi_like_p (uiout)) | |
14216 | { | |
0b0865da | 14217 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14218 | |
f35a17b5 | 14219 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14220 | } |
14221 | ||
80e1d417 | 14222 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14223 | ui_out_text (uiout, "\n"); |
14224 | ||
80e1d417 | 14225 | b->loc->line_number = sal2.line; |
2f202fde | 14226 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14227 | |
f00aae0f | 14228 | delete_event_location (b->location); |
67994074 KS |
14229 | initialize_explicit_location (&explicit_loc); |
14230 | explicit_loc.source_filename | |
00e52e53 | 14231 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14232 | explicit_loc.line_offset.offset = b->loc->line_number; |
14233 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14234 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14235 | |
14236 | /* Might be nice to check if function changed, and warn if | |
14237 | so. */ | |
14238 | ||
80e1d417 | 14239 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14240 | } |
14241 | } | |
14242 | return sal; | |
14243 | } | |
14244 | ||
8d3788bd VP |
14245 | /* Returns 1 iff locations A and B are sufficiently same that |
14246 | we don't need to report breakpoint as changed. */ | |
14247 | ||
14248 | static int | |
14249 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14250 | { | |
14251 | while (a && b) | |
14252 | { | |
14253 | if (a->address != b->address) | |
14254 | return 0; | |
14255 | ||
14256 | if (a->shlib_disabled != b->shlib_disabled) | |
14257 | return 0; | |
14258 | ||
14259 | if (a->enabled != b->enabled) | |
14260 | return 0; | |
14261 | ||
14262 | a = a->next; | |
14263 | b = b->next; | |
14264 | } | |
14265 | ||
14266 | if ((a == NULL) != (b == NULL)) | |
14267 | return 0; | |
14268 | ||
14269 | return 1; | |
14270 | } | |
14271 | ||
c2f4122d PA |
14272 | /* Split all locations of B that are bound to PSPACE out of B's |
14273 | location list to a separate list and return that list's head. If | |
14274 | PSPACE is NULL, hoist out all locations of B. */ | |
14275 | ||
14276 | static struct bp_location * | |
14277 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14278 | { | |
14279 | struct bp_location head; | |
14280 | struct bp_location *i = b->loc; | |
14281 | struct bp_location **i_link = &b->loc; | |
14282 | struct bp_location *hoisted = &head; | |
14283 | ||
14284 | if (pspace == NULL) | |
14285 | { | |
14286 | i = b->loc; | |
14287 | b->loc = NULL; | |
14288 | return i; | |
14289 | } | |
14290 | ||
14291 | head.next = NULL; | |
14292 | ||
14293 | while (i != NULL) | |
14294 | { | |
14295 | if (i->pspace == pspace) | |
14296 | { | |
14297 | *i_link = i->next; | |
14298 | i->next = NULL; | |
14299 | hoisted->next = i; | |
14300 | hoisted = i; | |
14301 | } | |
14302 | else | |
14303 | i_link = &i->next; | |
14304 | i = *i_link; | |
14305 | } | |
14306 | ||
14307 | return head.next; | |
14308 | } | |
14309 | ||
14310 | /* Create new breakpoint locations for B (a hardware or software | |
14311 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14312 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14313 | FILTER_PSPACE. Locations of other program spaces are left | |
14314 | untouched. */ | |
f1310107 | 14315 | |
0e30163f | 14316 | void |
0d381245 | 14317 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14318 | struct program_space *filter_pspace, |
f1310107 TJB |
14319 | struct symtabs_and_lines sals, |
14320 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14321 | { |
14322 | int i; | |
c2f4122d | 14323 | struct bp_location *existing_locations; |
0d381245 | 14324 | |
f8eba3c6 TT |
14325 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14326 | { | |
14327 | /* Ranged breakpoints have only one start location and one end | |
14328 | location. */ | |
14329 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14330 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14331 | "multiple locations found\n"), | |
14332 | b->number); | |
14333 | return; | |
14334 | } | |
f1310107 | 14335 | |
4a64f543 MS |
14336 | /* If there's no new locations, and all existing locations are |
14337 | pending, don't do anything. This optimizes the common case where | |
14338 | all locations are in the same shared library, that was unloaded. | |
14339 | We'd like to retain the location, so that when the library is | |
14340 | loaded again, we don't loose the enabled/disabled status of the | |
14341 | individual locations. */ | |
c2f4122d | 14342 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14343 | return; |
14344 | ||
c2f4122d | 14345 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14346 | |
0d381245 | 14347 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14348 | { |
f8eba3c6 TT |
14349 | struct bp_location *new_loc; |
14350 | ||
14351 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14352 | ||
14353 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14354 | |
0d381245 VP |
14355 | /* Reparse conditions, they might contain references to the |
14356 | old symtab. */ | |
14357 | if (b->cond_string != NULL) | |
14358 | { | |
bbc13ae3 | 14359 | const char *s; |
fe3f5fa8 | 14360 | |
0d381245 | 14361 | s = b->cond_string; |
492d29ea | 14362 | TRY |
0d381245 | 14363 | { |
1bb9788d TT |
14364 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14365 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14366 | 0); |
14367 | } | |
492d29ea | 14368 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14369 | { |
3e43a32a MS |
14370 | warning (_("failed to reevaluate condition " |
14371 | "for breakpoint %d: %s"), | |
0d381245 VP |
14372 | b->number, e.message); |
14373 | new_loc->enabled = 0; | |
14374 | } | |
492d29ea | 14375 | END_CATCH |
0d381245 | 14376 | } |
fe3f5fa8 | 14377 | |
f1310107 TJB |
14378 | if (sals_end.nelts) |
14379 | { | |
14380 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14381 | ||
14382 | new_loc->length = end - sals.sals[0].pc + 1; | |
14383 | } | |
0d381245 | 14384 | } |
fe3f5fa8 | 14385 | |
4a64f543 MS |
14386 | /* If possible, carry over 'disable' status from existing |
14387 | breakpoints. */ | |
0d381245 VP |
14388 | { |
14389 | struct bp_location *e = existing_locations; | |
776592bf DE |
14390 | /* If there are multiple breakpoints with the same function name, |
14391 | e.g. for inline functions, comparing function names won't work. | |
14392 | Instead compare pc addresses; this is just a heuristic as things | |
14393 | may have moved, but in practice it gives the correct answer | |
14394 | often enough until a better solution is found. */ | |
14395 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14396 | ||
0d381245 VP |
14397 | for (; e; e = e->next) |
14398 | { | |
14399 | if (!e->enabled && e->function_name) | |
14400 | { | |
14401 | struct bp_location *l = b->loc; | |
776592bf DE |
14402 | if (have_ambiguous_names) |
14403 | { | |
14404 | for (; l; l = l->next) | |
f1310107 | 14405 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14406 | { |
14407 | l->enabled = 0; | |
14408 | break; | |
14409 | } | |
14410 | } | |
14411 | else | |
14412 | { | |
14413 | for (; l; l = l->next) | |
14414 | if (l->function_name | |
14415 | && strcmp (e->function_name, l->function_name) == 0) | |
14416 | { | |
14417 | l->enabled = 0; | |
14418 | break; | |
14419 | } | |
14420 | } | |
0d381245 VP |
14421 | } |
14422 | } | |
14423 | } | |
fe3f5fa8 | 14424 | |
8d3788bd VP |
14425 | if (!locations_are_equal (existing_locations, b->loc)) |
14426 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14427 | } |
14428 | ||
f00aae0f | 14429 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14430 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14431 | ||
14432 | static struct symtabs_and_lines | |
f00aae0f | 14433 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14434 | struct program_space *search_pspace, int *found) |
ef23e705 | 14435 | { |
02d20e4a | 14436 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14437 | struct gdb_exception exception = exception_none; |
ef23e705 | 14438 | |
983af33b | 14439 | gdb_assert (b->ops != NULL); |
ef23e705 | 14440 | |
492d29ea | 14441 | TRY |
ef23e705 | 14442 | { |
c2f4122d | 14443 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14444 | } |
492d29ea | 14445 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14446 | { |
14447 | int not_found_and_ok = 0; | |
492d29ea PA |
14448 | |
14449 | exception = e; | |
14450 | ||
ef23e705 TJB |
14451 | /* For pending breakpoints, it's expected that parsing will |
14452 | fail until the right shared library is loaded. User has | |
14453 | already told to create pending breakpoints and don't need | |
14454 | extra messages. If breakpoint is in bp_shlib_disabled | |
14455 | state, then user already saw the message about that | |
14456 | breakpoint being disabled, and don't want to see more | |
14457 | errors. */ | |
58438ac1 | 14458 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14459 | && (b->condition_not_parsed |
14460 | || (b->loc != NULL | |
14461 | && search_pspace != NULL | |
14462 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14463 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14464 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14465 | || b->enable_state == bp_disabled)) |
14466 | not_found_and_ok = 1; | |
14467 | ||
14468 | if (!not_found_and_ok) | |
14469 | { | |
14470 | /* We surely don't want to warn about the same breakpoint | |
14471 | 10 times. One solution, implemented here, is disable | |
14472 | the breakpoint on error. Another solution would be to | |
14473 | have separate 'warning emitted' flag. Since this | |
14474 | happens only when a binary has changed, I don't know | |
14475 | which approach is better. */ | |
14476 | b->enable_state = bp_disabled; | |
14477 | throw_exception (e); | |
14478 | } | |
14479 | } | |
492d29ea | 14480 | END_CATCH |
ef23e705 | 14481 | |
492d29ea | 14482 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14483 | { |
f8eba3c6 | 14484 | int i; |
ef23e705 | 14485 | |
f8eba3c6 TT |
14486 | for (i = 0; i < sals.nelts; ++i) |
14487 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14488 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14489 | { |
ed1d1739 KS |
14490 | char *cond_string, *extra_string; |
14491 | int thread, task; | |
ef23e705 | 14492 | |
f00aae0f | 14493 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14494 | &cond_string, &thread, &task, |
14495 | &extra_string); | |
f00aae0f | 14496 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14497 | if (cond_string) |
14498 | b->cond_string = cond_string; | |
14499 | b->thread = thread; | |
14500 | b->task = task; | |
e7e0cddf | 14501 | if (extra_string) |
f00aae0f KS |
14502 | { |
14503 | xfree (b->extra_string); | |
14504 | b->extra_string = extra_string; | |
14505 | } | |
ef23e705 TJB |
14506 | b->condition_not_parsed = 0; |
14507 | } | |
14508 | ||
983af33b | 14509 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14510 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14511 | |
58438ac1 TT |
14512 | *found = 1; |
14513 | } | |
14514 | else | |
14515 | *found = 0; | |
ef23e705 TJB |
14516 | |
14517 | return sals; | |
14518 | } | |
14519 | ||
348d480f PA |
14520 | /* The default re_set method, for typical hardware or software |
14521 | breakpoints. Reevaluate the breakpoint and recreate its | |
14522 | locations. */ | |
14523 | ||
14524 | static void | |
28010a5d | 14525 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14526 | { |
14527 | int found; | |
f1310107 | 14528 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14529 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14530 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14531 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14532 | |
c2f4122d | 14533 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14534 | if (found) |
14535 | { | |
14536 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14537 | expanded = sals; |
ef23e705 TJB |
14538 | } |
14539 | ||
f00aae0f | 14540 | if (b->location_range_end != NULL) |
f1310107 | 14541 | { |
c2f4122d PA |
14542 | sals_end = location_to_sals (b, b->location_range_end, |
14543 | filter_pspace, &found); | |
f1310107 TJB |
14544 | if (found) |
14545 | { | |
14546 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14547 | expanded_end = sals_end; |
f1310107 TJB |
14548 | } |
14549 | } | |
14550 | ||
c2f4122d | 14551 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14552 | } |
14553 | ||
983af33b SDJ |
14554 | /* Default method for creating SALs from an address string. It basically |
14555 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14556 | ||
14557 | static void | |
f00aae0f KS |
14558 | create_sals_from_location_default (const struct event_location *location, |
14559 | struct linespec_result *canonical, | |
14560 | enum bptype type_wanted) | |
983af33b | 14561 | { |
f00aae0f | 14562 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14563 | } |
14564 | ||
14565 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14566 | function for the `create_breakpoints_sal' method of | |
14567 | breakpoint_ops. */ | |
14568 | ||
14569 | static void | |
14570 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14571 | struct linespec_result *canonical, | |
983af33b | 14572 | char *cond_string, |
e7e0cddf | 14573 | char *extra_string, |
983af33b SDJ |
14574 | enum bptype type_wanted, |
14575 | enum bpdisp disposition, | |
14576 | int thread, | |
14577 | int task, int ignore_count, | |
14578 | const struct breakpoint_ops *ops, | |
14579 | int from_tty, int enabled, | |
44f238bb | 14580 | int internal, unsigned flags) |
983af33b SDJ |
14581 | { |
14582 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14583 | extra_string, |
983af33b SDJ |
14584 | type_wanted, disposition, |
14585 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14586 | enabled, internal, flags); |
983af33b SDJ |
14587 | } |
14588 | ||
14589 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14590 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14591 | |
14592 | static void | |
f00aae0f KS |
14593 | decode_location_default (struct breakpoint *b, |
14594 | const struct event_location *location, | |
c2f4122d | 14595 | struct program_space *search_pspace, |
983af33b SDJ |
14596 | struct symtabs_and_lines *sals) |
14597 | { | |
14598 | struct linespec_result canonical; | |
14599 | ||
14600 | init_linespec_result (&canonical); | |
c2f4122d | 14601 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14602 | (struct symtab *) NULL, 0, |
14603 | &canonical, multiple_symbols_all, | |
14604 | b->filter); | |
14605 | ||
14606 | /* We should get 0 or 1 resulting SALs. */ | |
14607 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14608 | ||
14609 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14610 | { | |
14611 | struct linespec_sals *lsal; | |
14612 | ||
14613 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14614 | *sals = lsal->sals; | |
14615 | /* Arrange it so the destructor does not free the | |
14616 | contents. */ | |
14617 | lsal->sals.sals = NULL; | |
14618 | } | |
14619 | ||
14620 | destroy_linespec_result (&canonical); | |
14621 | } | |
14622 | ||
28010a5d PA |
14623 | /* Prepare the global context for a re-set of breakpoint B. */ |
14624 | ||
14625 | static struct cleanup * | |
14626 | prepare_re_set_context (struct breakpoint *b) | |
14627 | { | |
28010a5d | 14628 | input_radix = b->input_radix; |
28010a5d PA |
14629 | set_language (b->language); |
14630 | ||
c2f4122d | 14631 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14632 | } |
14633 | ||
c906108c SS |
14634 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14635 | The value we return ends up being the return value from catch_errors. | |
14636 | Unused in this case. */ | |
14637 | ||
14638 | static int | |
4efb68b1 | 14639 | breakpoint_re_set_one (void *bint) |
c906108c | 14640 | { |
4a64f543 | 14641 | /* Get past catch_errs. */ |
53a5351d | 14642 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14643 | struct cleanup *cleanups; |
c906108c | 14644 | |
348d480f PA |
14645 | cleanups = prepare_re_set_context (b); |
14646 | b->ops->re_set (b); | |
14647 | do_cleanups (cleanups); | |
c906108c SS |
14648 | return 0; |
14649 | } | |
14650 | ||
c2f4122d PA |
14651 | /* Re-set breakpoint locations for the current program space. |
14652 | Locations bound to other program spaces are left untouched. */ | |
14653 | ||
c906108c | 14654 | void |
69de3c6a | 14655 | breakpoint_re_set (void) |
c906108c | 14656 | { |
35df4500 | 14657 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14658 | enum language save_language; |
14659 | int save_input_radix; | |
6c95b8df | 14660 | struct cleanup *old_chain; |
c5aa993b | 14661 | |
c906108c SS |
14662 | save_language = current_language->la_language; |
14663 | save_input_radix = input_radix; | |
c2f4122d | 14664 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14665 | |
2a7f3dff PA |
14666 | /* Note: we must not try to insert locations until after all |
14667 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14668 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14669 | hadn't been re-set yet, and thus may have stale locations. */ | |
14670 | ||
35df4500 | 14671 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14672 | { |
4a64f543 | 14673 | /* Format possible error msg. */ |
fe3f5fa8 | 14674 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14675 | b->number); |
14676 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14677 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14678 | do_cleanups (cleanups); |
c5aa993b | 14679 | } |
c906108c SS |
14680 | set_language (save_language); |
14681 | input_radix = save_input_radix; | |
e62c965a | 14682 | |
0756c555 | 14683 | jit_breakpoint_re_set (); |
4efc6507 | 14684 | |
6c95b8df PA |
14685 | do_cleanups (old_chain); |
14686 | ||
af02033e PP |
14687 | create_overlay_event_breakpoint (); |
14688 | create_longjmp_master_breakpoint (); | |
14689 | create_std_terminate_master_breakpoint (); | |
186c406b | 14690 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14691 | |
14692 | /* Now we can insert. */ | |
14693 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14694 | } |
14695 | \f | |
c906108c SS |
14696 | /* Reset the thread number of this breakpoint: |
14697 | ||
14698 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14699 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14700 | void |
fba45db2 | 14701 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14702 | { |
14703 | if (b->thread != -1) | |
14704 | { | |
39f77062 | 14705 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14706 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14707 | |
14708 | /* We're being called after following a fork. The new fork is | |
14709 | selected as current, and unless this was a vfork will have a | |
14710 | different program space from the original thread. Reset that | |
14711 | as well. */ | |
14712 | b->loc->pspace = current_program_space; | |
c906108c SS |
14713 | } |
14714 | } | |
14715 | ||
03ac34d5 MS |
14716 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14717 | If from_tty is nonzero, it prints a message to that effect, | |
14718 | which ends with a period (no newline). */ | |
14719 | ||
c906108c | 14720 | void |
fba45db2 | 14721 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14722 | { |
52f0bd74 | 14723 | struct breakpoint *b; |
c906108c SS |
14724 | |
14725 | if (count < 0) | |
14726 | count = 0; | |
14727 | ||
14728 | ALL_BREAKPOINTS (b) | |
14729 | if (b->number == bptnum) | |
c5aa993b | 14730 | { |
d77f58be SS |
14731 | if (is_tracepoint (b)) |
14732 | { | |
14733 | if (from_tty && count != 0) | |
14734 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14735 | bptnum); | |
14736 | return; | |
14737 | } | |
14738 | ||
c5aa993b | 14739 | b->ignore_count = count; |
221ea385 KS |
14740 | if (from_tty) |
14741 | { | |
14742 | if (count == 0) | |
3e43a32a MS |
14743 | printf_filtered (_("Will stop next time " |
14744 | "breakpoint %d is reached."), | |
221ea385 KS |
14745 | bptnum); |
14746 | else if (count == 1) | |
a3f17187 | 14747 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14748 | bptnum); |
14749 | else | |
3e43a32a MS |
14750 | printf_filtered (_("Will ignore next %d " |
14751 | "crossings of breakpoint %d."), | |
221ea385 KS |
14752 | count, bptnum); |
14753 | } | |
8d3788bd | 14754 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14755 | return; |
14756 | } | |
c906108c | 14757 | |
8a3fe4f8 | 14758 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14759 | } |
14760 | ||
c906108c SS |
14761 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14762 | ||
14763 | static void | |
fba45db2 | 14764 | ignore_command (char *args, int from_tty) |
c906108c SS |
14765 | { |
14766 | char *p = args; | |
52f0bd74 | 14767 | int num; |
c906108c SS |
14768 | |
14769 | if (p == 0) | |
e2e0b3e5 | 14770 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14771 | |
c906108c | 14772 | num = get_number (&p); |
5c44784c | 14773 | if (num == 0) |
8a3fe4f8 | 14774 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14775 | if (*p == 0) |
8a3fe4f8 | 14776 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14777 | |
14778 | set_ignore_count (num, | |
14779 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14780 | from_tty); | |
221ea385 KS |
14781 | if (from_tty) |
14782 | printf_filtered ("\n"); | |
c906108c SS |
14783 | } |
14784 | \f | |
14785 | /* Call FUNCTION on each of the breakpoints | |
14786 | whose numbers are given in ARGS. */ | |
14787 | ||
14788 | static void | |
896b6bda PA |
14789 | map_breakpoint_numbers (const char *args, |
14790 | void (*function) (struct breakpoint *, | |
14791 | void *), | |
95a42b64 | 14792 | void *data) |
c906108c | 14793 | { |
52f0bd74 AC |
14794 | int num; |
14795 | struct breakpoint *b, *tmp; | |
c906108c | 14796 | |
b9d61307 | 14797 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14798 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14799 | |
bfd28288 | 14800 | number_or_range_parser parser (args); |
197f0a60 | 14801 | |
bfd28288 | 14802 | while (!parser.finished ()) |
c906108c | 14803 | { |
bfd28288 PA |
14804 | const char *p = parser.cur_tok (); |
14805 | bool match = false; | |
197f0a60 | 14806 | |
bfd28288 | 14807 | num = parser.get_number (); |
5c44784c | 14808 | if (num == 0) |
c5aa993b | 14809 | { |
8a3fe4f8 | 14810 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14811 | } |
14812 | else | |
14813 | { | |
14814 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14815 | if (b->number == num) | |
14816 | { | |
bfd28288 | 14817 | match = true; |
cdac0397 | 14818 | function (b, data); |
11cf8741 | 14819 | break; |
5c44784c | 14820 | } |
bfd28288 | 14821 | if (!match) |
a3f17187 | 14822 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14823 | } |
c906108c SS |
14824 | } |
14825 | } | |
14826 | ||
0d381245 VP |
14827 | static struct bp_location * |
14828 | find_location_by_number (char *number) | |
14829 | { | |
14830 | char *dot = strchr (number, '.'); | |
14831 | char *p1; | |
14832 | int bp_num; | |
14833 | int loc_num; | |
14834 | struct breakpoint *b; | |
14835 | struct bp_location *loc; | |
14836 | ||
14837 | *dot = '\0'; | |
14838 | ||
14839 | p1 = number; | |
197f0a60 | 14840 | bp_num = get_number (&p1); |
0d381245 VP |
14841 | if (bp_num == 0) |
14842 | error (_("Bad breakpoint number '%s'"), number); | |
14843 | ||
14844 | ALL_BREAKPOINTS (b) | |
14845 | if (b->number == bp_num) | |
14846 | { | |
14847 | break; | |
14848 | } | |
14849 | ||
14850 | if (!b || b->number != bp_num) | |
14851 | error (_("Bad breakpoint number '%s'"), number); | |
14852 | ||
14853 | p1 = dot+1; | |
197f0a60 | 14854 | loc_num = get_number (&p1); |
0d381245 VP |
14855 | if (loc_num == 0) |
14856 | error (_("Bad breakpoint location number '%s'"), number); | |
14857 | ||
14858 | --loc_num; | |
14859 | loc = b->loc; | |
14860 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14861 | ; | |
14862 | if (!loc) | |
14863 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14864 | ||
14865 | return loc; | |
14866 | } | |
14867 | ||
14868 | ||
1900040c MS |
14869 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14870 | If from_tty is nonzero, it prints a message to that effect, | |
14871 | which ends with a period (no newline). */ | |
14872 | ||
c906108c | 14873 | void |
fba45db2 | 14874 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14875 | { |
14876 | /* Never disable a watchpoint scope breakpoint; we want to | |
14877 | hit them when we leave scope so we can delete both the | |
14878 | watchpoint and its scope breakpoint at that time. */ | |
14879 | if (bpt->type == bp_watchpoint_scope) | |
14880 | return; | |
14881 | ||
b5de0fa7 | 14882 | bpt->enable_state = bp_disabled; |
c906108c | 14883 | |
b775012e LM |
14884 | /* Mark breakpoint locations modified. */ |
14885 | mark_breakpoint_modified (bpt); | |
14886 | ||
d248b706 KY |
14887 | if (target_supports_enable_disable_tracepoint () |
14888 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14889 | { | |
14890 | struct bp_location *location; | |
14891 | ||
14892 | for (location = bpt->loc; location; location = location->next) | |
14893 | target_disable_tracepoint (location); | |
14894 | } | |
14895 | ||
44702360 | 14896 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14897 | |
8d3788bd | 14898 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14899 | } |
14900 | ||
51be5b68 PA |
14901 | /* A callback for iterate_over_related_breakpoints. */ |
14902 | ||
14903 | static void | |
14904 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14905 | { | |
14906 | disable_breakpoint (b); | |
14907 | } | |
14908 | ||
95a42b64 TT |
14909 | /* A callback for map_breakpoint_numbers that calls |
14910 | disable_breakpoint. */ | |
14911 | ||
14912 | static void | |
14913 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14914 | { | |
51be5b68 | 14915 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14916 | } |
14917 | ||
c906108c | 14918 | static void |
fba45db2 | 14919 | disable_command (char *args, int from_tty) |
c906108c | 14920 | { |
c906108c | 14921 | if (args == 0) |
46c6471b PA |
14922 | { |
14923 | struct breakpoint *bpt; | |
14924 | ||
14925 | ALL_BREAKPOINTS (bpt) | |
14926 | if (user_breakpoint_p (bpt)) | |
14927 | disable_breakpoint (bpt); | |
14928 | } | |
9eaabc75 | 14929 | else |
0d381245 | 14930 | { |
9eaabc75 MW |
14931 | char *num = extract_arg (&args); |
14932 | ||
14933 | while (num) | |
d248b706 | 14934 | { |
9eaabc75 | 14935 | if (strchr (num, '.')) |
b775012e | 14936 | { |
9eaabc75 MW |
14937 | struct bp_location *loc = find_location_by_number (num); |
14938 | ||
14939 | if (loc) | |
14940 | { | |
14941 | if (loc->enabled) | |
14942 | { | |
14943 | loc->enabled = 0; | |
14944 | mark_breakpoint_location_modified (loc); | |
14945 | } | |
14946 | if (target_supports_enable_disable_tracepoint () | |
14947 | && current_trace_status ()->running && loc->owner | |
14948 | && is_tracepoint (loc->owner)) | |
14949 | target_disable_tracepoint (loc); | |
14950 | } | |
44702360 | 14951 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14952 | } |
9eaabc75 MW |
14953 | else |
14954 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14955 | num = extract_arg (&args); | |
d248b706 | 14956 | } |
0d381245 | 14957 | } |
c906108c SS |
14958 | } |
14959 | ||
14960 | static void | |
816338b5 SS |
14961 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14962 | int count) | |
c906108c | 14963 | { |
afe38095 | 14964 | int target_resources_ok; |
c906108c SS |
14965 | |
14966 | if (bpt->type == bp_hardware_breakpoint) | |
14967 | { | |
14968 | int i; | |
c5aa993b | 14969 | i = hw_breakpoint_used_count (); |
53a5351d | 14970 | target_resources_ok = |
d92524f1 | 14971 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14972 | i + 1, 0); |
c906108c | 14973 | if (target_resources_ok == 0) |
8a3fe4f8 | 14974 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14975 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14976 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14977 | } |
14978 | ||
cc60f2e3 | 14979 | if (is_watchpoint (bpt)) |
c906108c | 14980 | { |
d07205c2 | 14981 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14982 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14983 | |
492d29ea | 14984 | TRY |
c906108c | 14985 | { |
3a5c3e22 PA |
14986 | struct watchpoint *w = (struct watchpoint *) bpt; |
14987 | ||
1e718ff1 TJB |
14988 | orig_enable_state = bpt->enable_state; |
14989 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14990 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14991 | } |
492d29ea | 14992 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14993 | { |
1e718ff1 | 14994 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14995 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14996 | bpt->number); | |
14997 | return; | |
c5aa993b | 14998 | } |
492d29ea | 14999 | END_CATCH |
c906108c | 15000 | } |
0101ce28 | 15001 | |
b775012e LM |
15002 | bpt->enable_state = bp_enabled; |
15003 | ||
15004 | /* Mark breakpoint locations modified. */ | |
15005 | mark_breakpoint_modified (bpt); | |
15006 | ||
d248b706 KY |
15007 | if (target_supports_enable_disable_tracepoint () |
15008 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15009 | { | |
15010 | struct bp_location *location; | |
15011 | ||
15012 | for (location = bpt->loc; location; location = location->next) | |
15013 | target_enable_tracepoint (location); | |
15014 | } | |
15015 | ||
b4c291bb | 15016 | bpt->disposition = disposition; |
816338b5 | 15017 | bpt->enable_count = count; |
44702360 | 15018 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15019 | |
8d3788bd | 15020 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15021 | } |
15022 | ||
fe3f5fa8 | 15023 | |
c906108c | 15024 | void |
fba45db2 | 15025 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15026 | { |
816338b5 | 15027 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15028 | } |
15029 | ||
15030 | static void | |
15031 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15032 | { | |
15033 | enable_breakpoint (bpt); | |
c906108c SS |
15034 | } |
15035 | ||
95a42b64 TT |
15036 | /* A callback for map_breakpoint_numbers that calls |
15037 | enable_breakpoint. */ | |
15038 | ||
15039 | static void | |
15040 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15041 | { | |
51be5b68 | 15042 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15043 | } |
15044 | ||
c906108c SS |
15045 | /* The enable command enables the specified breakpoints (or all defined |
15046 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15047 | in stopping the inferior. */ |
c906108c | 15048 | |
c906108c | 15049 | static void |
fba45db2 | 15050 | enable_command (char *args, int from_tty) |
c906108c | 15051 | { |
c906108c | 15052 | if (args == 0) |
46c6471b PA |
15053 | { |
15054 | struct breakpoint *bpt; | |
15055 | ||
15056 | ALL_BREAKPOINTS (bpt) | |
15057 | if (user_breakpoint_p (bpt)) | |
15058 | enable_breakpoint (bpt); | |
15059 | } | |
9eaabc75 | 15060 | else |
0d381245 | 15061 | { |
9eaabc75 MW |
15062 | char *num = extract_arg (&args); |
15063 | ||
15064 | while (num) | |
d248b706 | 15065 | { |
9eaabc75 | 15066 | if (strchr (num, '.')) |
b775012e | 15067 | { |
9eaabc75 MW |
15068 | struct bp_location *loc = find_location_by_number (num); |
15069 | ||
15070 | if (loc) | |
15071 | { | |
15072 | if (!loc->enabled) | |
15073 | { | |
15074 | loc->enabled = 1; | |
15075 | mark_breakpoint_location_modified (loc); | |
15076 | } | |
15077 | if (target_supports_enable_disable_tracepoint () | |
15078 | && current_trace_status ()->running && loc->owner | |
15079 | && is_tracepoint (loc->owner)) | |
15080 | target_enable_tracepoint (loc); | |
15081 | } | |
44702360 | 15082 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15083 | } |
9eaabc75 MW |
15084 | else |
15085 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15086 | num = extract_arg (&args); | |
d248b706 | 15087 | } |
0d381245 | 15088 | } |
c906108c SS |
15089 | } |
15090 | ||
816338b5 SS |
15091 | /* This struct packages up disposition data for application to multiple |
15092 | breakpoints. */ | |
15093 | ||
15094 | struct disp_data | |
15095 | { | |
15096 | enum bpdisp disp; | |
15097 | int count; | |
15098 | }; | |
15099 | ||
c906108c | 15100 | static void |
51be5b68 PA |
15101 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15102 | { | |
816338b5 | 15103 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15104 | |
816338b5 | 15105 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15106 | } |
15107 | ||
15108 | static void | |
15109 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15110 | { |
816338b5 | 15111 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15112 | |
15113 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15114 | } |
15115 | ||
c906108c | 15116 | static void |
fba45db2 | 15117 | enable_once_command (char *args, int from_tty) |
c906108c | 15118 | { |
51be5b68 | 15119 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15120 | } |
15121 | ||
816338b5 SS |
15122 | static void |
15123 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15124 | { | |
15125 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15126 | ||
15127 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15128 | } | |
15129 | ||
15130 | static void | |
15131 | enable_count_command (char *args, int from_tty) | |
15132 | { | |
b9d61307 SM |
15133 | int count; |
15134 | ||
15135 | if (args == NULL) | |
15136 | error_no_arg (_("hit count")); | |
15137 | ||
15138 | count = get_number (&args); | |
816338b5 SS |
15139 | |
15140 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15141 | } | |
15142 | ||
c906108c | 15143 | static void |
51be5b68 | 15144 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15145 | { |
816338b5 | 15146 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15147 | |
15148 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15149 | } |
15150 | ||
c906108c | 15151 | static void |
fba45db2 | 15152 | enable_delete_command (char *args, int from_tty) |
c906108c | 15153 | { |
51be5b68 | 15154 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15155 | } |
15156 | \f | |
fa8d40ab JJ |
15157 | static void |
15158 | set_breakpoint_cmd (char *args, int from_tty) | |
15159 | { | |
15160 | } | |
15161 | ||
15162 | static void | |
15163 | show_breakpoint_cmd (char *args, int from_tty) | |
15164 | { | |
15165 | } | |
15166 | ||
1f3b5d1b PP |
15167 | /* Invalidate last known value of any hardware watchpoint if |
15168 | the memory which that value represents has been written to by | |
15169 | GDB itself. */ | |
15170 | ||
15171 | static void | |
8de0566d YQ |
15172 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15173 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15174 | const bfd_byte *data) |
15175 | { | |
15176 | struct breakpoint *bp; | |
15177 | ||
15178 | ALL_BREAKPOINTS (bp) | |
15179 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15180 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15181 | { |
3a5c3e22 | 15182 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15183 | |
3a5c3e22 PA |
15184 | if (wp->val_valid && wp->val) |
15185 | { | |
15186 | struct bp_location *loc; | |
15187 | ||
15188 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15189 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15190 | && loc->address + loc->length > addr | |
15191 | && addr + len > loc->address) | |
15192 | { | |
15193 | value_free (wp->val); | |
15194 | wp->val = NULL; | |
15195 | wp->val_valid = 0; | |
15196 | } | |
15197 | } | |
1f3b5d1b PP |
15198 | } |
15199 | } | |
15200 | ||
8181d85f DJ |
15201 | /* Create and insert a breakpoint for software single step. */ |
15202 | ||
15203 | void | |
6c95b8df | 15204 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15205 | struct address_space *aspace, |
15206 | CORE_ADDR next_pc) | |
8181d85f | 15207 | { |
7c16b83e PA |
15208 | struct thread_info *tp = inferior_thread (); |
15209 | struct symtab_and_line sal; | |
15210 | CORE_ADDR pc = next_pc; | |
8181d85f | 15211 | |
34b7e8a6 PA |
15212 | if (tp->control.single_step_breakpoints == NULL) |
15213 | { | |
15214 | tp->control.single_step_breakpoints | |
5d5658a1 | 15215 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15216 | } |
8181d85f | 15217 | |
7c16b83e PA |
15218 | sal = find_pc_line (pc, 0); |
15219 | sal.pc = pc; | |
15220 | sal.section = find_pc_overlay (pc); | |
15221 | sal.explicit_pc = 1; | |
34b7e8a6 | 15222 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15223 | |
7c16b83e | 15224 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15225 | } |
15226 | ||
93f9a11f YQ |
15227 | /* Insert single step breakpoints according to the current state. */ |
15228 | ||
15229 | int | |
15230 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
15231 | { | |
15232 | struct frame_info *frame = get_current_frame (); | |
15233 | VEC (CORE_ADDR) * next_pcs; | |
15234 | ||
15235 | next_pcs = gdbarch_software_single_step (gdbarch, frame); | |
15236 | ||
15237 | if (next_pcs != NULL) | |
15238 | { | |
15239 | int i; | |
15240 | CORE_ADDR pc; | |
15241 | struct address_space *aspace = get_frame_address_space (frame); | |
15242 | ||
15243 | for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++) | |
15244 | insert_single_step_breakpoint (gdbarch, aspace, pc); | |
15245 | ||
15246 | VEC_free (CORE_ADDR, next_pcs); | |
15247 | ||
15248 | return 1; | |
15249 | } | |
15250 | else | |
15251 | return 0; | |
15252 | } | |
15253 | ||
34b7e8a6 | 15254 | /* See breakpoint.h. */ |
f02253f1 HZ |
15255 | |
15256 | int | |
7c16b83e PA |
15257 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15258 | struct address_space *aspace, | |
15259 | CORE_ADDR pc) | |
1aafd4da | 15260 | { |
7c16b83e | 15261 | struct bp_location *loc; |
1aafd4da | 15262 | |
7c16b83e PA |
15263 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15264 | if (loc->inserted | |
15265 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15266 | return 1; | |
1aafd4da | 15267 | |
7c16b83e | 15268 | return 0; |
ef370185 JB |
15269 | } |
15270 | ||
15271 | /* Check whether a software single-step breakpoint is inserted at | |
15272 | PC. */ | |
15273 | ||
15274 | int | |
15275 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15276 | CORE_ADDR pc) | |
15277 | { | |
34b7e8a6 PA |
15278 | struct breakpoint *bpt; |
15279 | ||
15280 | ALL_BREAKPOINTS (bpt) | |
15281 | { | |
15282 | if (bpt->type == bp_single_step | |
15283 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15284 | return 1; | |
15285 | } | |
15286 | return 0; | |
1aafd4da UW |
15287 | } |
15288 | ||
1042e4c0 SS |
15289 | /* Tracepoint-specific operations. */ |
15290 | ||
15291 | /* Set tracepoint count to NUM. */ | |
15292 | static void | |
15293 | set_tracepoint_count (int num) | |
15294 | { | |
15295 | tracepoint_count = num; | |
4fa62494 | 15296 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15297 | } |
15298 | ||
70221824 | 15299 | static void |
1042e4c0 SS |
15300 | trace_command (char *arg, int from_tty) |
15301 | { | |
55aa24fb | 15302 | struct breakpoint_ops *ops; |
f00aae0f KS |
15303 | struct event_location *location; |
15304 | struct cleanup *back_to; | |
55aa24fb | 15305 | |
f00aae0f KS |
15306 | location = string_to_event_location (&arg, current_language); |
15307 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15308 | if (location != NULL |
15309 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15310 | ops = &tracepoint_probe_breakpoint_ops; |
15311 | else | |
15312 | ops = &tracepoint_breakpoint_ops; | |
15313 | ||
558a9d82 | 15314 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15315 | location, |
15316 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15317 | 0 /* tempflag */, |
15318 | bp_tracepoint /* type_wanted */, | |
15319 | 0 /* Ignore count */, | |
15320 | pending_break_support, | |
15321 | ops, | |
15322 | from_tty, | |
15323 | 1 /* enabled */, | |
15324 | 0 /* internal */, 0); | |
f00aae0f | 15325 | do_cleanups (back_to); |
1042e4c0 SS |
15326 | } |
15327 | ||
70221824 | 15328 | static void |
7a697b8d SS |
15329 | ftrace_command (char *arg, int from_tty) |
15330 | { | |
f00aae0f KS |
15331 | struct event_location *location; |
15332 | struct cleanup *back_to; | |
15333 | ||
15334 | location = string_to_event_location (&arg, current_language); | |
15335 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15336 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15337 | location, |
15338 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15339 | 0 /* tempflag */, |
15340 | bp_fast_tracepoint /* type_wanted */, | |
15341 | 0 /* Ignore count */, | |
15342 | pending_break_support, | |
15343 | &tracepoint_breakpoint_ops, | |
15344 | from_tty, | |
15345 | 1 /* enabled */, | |
15346 | 0 /* internal */, 0); | |
f00aae0f | 15347 | do_cleanups (back_to); |
0fb4aa4b PA |
15348 | } |
15349 | ||
15350 | /* strace command implementation. Creates a static tracepoint. */ | |
15351 | ||
70221824 | 15352 | static void |
0fb4aa4b PA |
15353 | strace_command (char *arg, int from_tty) |
15354 | { | |
983af33b | 15355 | struct breakpoint_ops *ops; |
f00aae0f KS |
15356 | struct event_location *location; |
15357 | struct cleanup *back_to; | |
983af33b SDJ |
15358 | |
15359 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15360 | or with a normal static tracepoint. */ | |
61012eef | 15361 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15362 | { |
15363 | ops = &strace_marker_breakpoint_ops; | |
15364 | location = new_linespec_location (&arg); | |
15365 | } | |
983af33b | 15366 | else |
f00aae0f KS |
15367 | { |
15368 | ops = &tracepoint_breakpoint_ops; | |
15369 | location = string_to_event_location (&arg, current_language); | |
15370 | } | |
983af33b | 15371 | |
f00aae0f | 15372 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15373 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15374 | location, |
15375 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15376 | 0 /* tempflag */, |
15377 | bp_static_tracepoint /* type_wanted */, | |
15378 | 0 /* Ignore count */, | |
15379 | pending_break_support, | |
15380 | ops, | |
15381 | from_tty, | |
15382 | 1 /* enabled */, | |
15383 | 0 /* internal */, 0); | |
f00aae0f | 15384 | do_cleanups (back_to); |
7a697b8d SS |
15385 | } |
15386 | ||
409873ef SS |
15387 | /* Set up a fake reader function that gets command lines from a linked |
15388 | list that was acquired during tracepoint uploading. */ | |
15389 | ||
15390 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15391 | static int next_cmd; |
409873ef SS |
15392 | |
15393 | static char * | |
15394 | read_uploaded_action (void) | |
15395 | { | |
15396 | char *rslt; | |
15397 | ||
3149d8c1 | 15398 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15399 | |
3149d8c1 | 15400 | next_cmd++; |
409873ef SS |
15401 | |
15402 | return rslt; | |
15403 | } | |
15404 | ||
00bf0b85 SS |
15405 | /* Given information about a tracepoint as recorded on a target (which |
15406 | can be either a live system or a trace file), attempt to create an | |
15407 | equivalent GDB tracepoint. This is not a reliable process, since | |
15408 | the target does not necessarily have all the information used when | |
15409 | the tracepoint was originally defined. */ | |
15410 | ||
d9b3f62e | 15411 | struct tracepoint * |
00bf0b85 | 15412 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15413 | { |
409873ef | 15414 | char *addr_str, small_buf[100]; |
d9b3f62e | 15415 | struct tracepoint *tp; |
f00aae0f KS |
15416 | struct event_location *location; |
15417 | struct cleanup *cleanup; | |
fd9b8c24 | 15418 | |
409873ef SS |
15419 | if (utp->at_string) |
15420 | addr_str = utp->at_string; | |
15421 | else | |
15422 | { | |
15423 | /* In the absence of a source location, fall back to raw | |
15424 | address. Since there is no way to confirm that the address | |
15425 | means the same thing as when the trace was started, warn the | |
15426 | user. */ | |
3e43a32a MS |
15427 | warning (_("Uploaded tracepoint %d has no " |
15428 | "source location, using raw address"), | |
409873ef | 15429 | utp->number); |
8c042590 | 15430 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15431 | addr_str = small_buf; |
15432 | } | |
15433 | ||
15434 | /* There's not much we can do with a sequence of bytecodes. */ | |
15435 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15436 | warning (_("Uploaded tracepoint %d condition " |
15437 | "has no source form, ignoring it"), | |
409873ef | 15438 | utp->number); |
d5551862 | 15439 | |
f00aae0f KS |
15440 | location = string_to_event_location (&addr_str, current_language); |
15441 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15442 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15443 | location, |
15444 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15445 | 0 /* parse cond/thread */, |
8cdf0e15 | 15446 | 0 /* tempflag */, |
0fb4aa4b | 15447 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15448 | 0 /* Ignore count */, |
15449 | pending_break_support, | |
348d480f | 15450 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15451 | 0 /* from_tty */, |
84f4c1fe | 15452 | utp->enabled /* enabled */, |
44f238bb PA |
15453 | 0 /* internal */, |
15454 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15455 | { |
15456 | do_cleanups (cleanup); | |
15457 | return NULL; | |
15458 | } | |
15459 | ||
15460 | do_cleanups (cleanup); | |
fd9b8c24 | 15461 | |
409873ef | 15462 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15463 | tp = get_tracepoint (tracepoint_count); |
15464 | gdb_assert (tp != NULL); | |
d5551862 | 15465 | |
00bf0b85 SS |
15466 | if (utp->pass > 0) |
15467 | { | |
8c042590 PM |
15468 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15469 | tp->base.number); | |
00bf0b85 | 15470 | |
409873ef | 15471 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15472 | } |
15473 | ||
409873ef SS |
15474 | /* If we have uploaded versions of the original commands, set up a |
15475 | special-purpose "reader" function and call the usual command line | |
15476 | reader, then pass the result to the breakpoint command-setting | |
15477 | function. */ | |
3149d8c1 | 15478 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15479 | { |
409873ef | 15480 | struct command_line *cmd_list; |
00bf0b85 | 15481 | |
409873ef | 15482 | this_utp = utp; |
3149d8c1 | 15483 | next_cmd = 0; |
d5551862 | 15484 | |
409873ef SS |
15485 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15486 | ||
d9b3f62e | 15487 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15488 | } |
3149d8c1 SS |
15489 | else if (!VEC_empty (char_ptr, utp->actions) |
15490 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15491 | warning (_("Uploaded tracepoint %d actions " |
15492 | "have no source form, ignoring them"), | |
409873ef | 15493 | utp->number); |
00bf0b85 | 15494 | |
f196051f SS |
15495 | /* Copy any status information that might be available. */ |
15496 | tp->base.hit_count = utp->hit_count; | |
15497 | tp->traceframe_usage = utp->traceframe_usage; | |
15498 | ||
00bf0b85 | 15499 | return tp; |
d9b3f62e | 15500 | } |
00bf0b85 | 15501 | |
1042e4c0 SS |
15502 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15503 | omitted. */ | |
15504 | ||
15505 | static void | |
e5a67952 | 15506 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15507 | { |
79a45e25 | 15508 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15509 | int num_printed; |
1042e4c0 | 15510 | |
e5a67952 | 15511 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15512 | |
15513 | if (num_printed == 0) | |
1042e4c0 | 15514 | { |
e5a67952 | 15515 | if (args == NULL || *args == '\0') |
d77f58be SS |
15516 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15517 | else | |
e5a67952 | 15518 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15519 | } |
ad443146 SS |
15520 | |
15521 | default_collect_info (); | |
1042e4c0 SS |
15522 | } |
15523 | ||
4a64f543 | 15524 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15525 | Not supported by all targets. */ |
15526 | static void | |
15527 | enable_trace_command (char *args, int from_tty) | |
15528 | { | |
15529 | enable_command (args, from_tty); | |
15530 | } | |
15531 | ||
4a64f543 | 15532 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15533 | Not supported by all targets. */ |
15534 | static void | |
15535 | disable_trace_command (char *args, int from_tty) | |
15536 | { | |
15537 | disable_command (args, from_tty); | |
15538 | } | |
15539 | ||
4a64f543 | 15540 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15541 | static void |
15542 | delete_trace_command (char *arg, int from_tty) | |
15543 | { | |
35df4500 | 15544 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15545 | |
15546 | dont_repeat (); | |
15547 | ||
15548 | if (arg == 0) | |
15549 | { | |
15550 | int breaks_to_delete = 0; | |
15551 | ||
15552 | /* Delete all breakpoints if no argument. | |
15553 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15554 | have to be deleted with an explicit breakpoint number |
15555 | argument. */ | |
1042e4c0 | 15556 | ALL_TRACEPOINTS (b) |
46c6471b | 15557 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15558 | { |
15559 | breaks_to_delete = 1; | |
15560 | break; | |
15561 | } | |
1042e4c0 SS |
15562 | |
15563 | /* Ask user only if there are some breakpoints to delete. */ | |
15564 | if (!from_tty | |
15565 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15566 | { | |
35df4500 | 15567 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15568 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15569 | delete_breakpoint (b); |
1042e4c0 SS |
15570 | } |
15571 | } | |
15572 | else | |
51be5b68 | 15573 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15574 | } |
15575 | ||
197f0a60 TT |
15576 | /* Helper function for trace_pass_command. */ |
15577 | ||
15578 | static void | |
d9b3f62e | 15579 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15580 | { |
d9b3f62e | 15581 | tp->pass_count = count; |
6f6484cd | 15582 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15583 | if (from_tty) |
15584 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15585 | tp->base.number, count); |
197f0a60 TT |
15586 | } |
15587 | ||
1042e4c0 SS |
15588 | /* Set passcount for tracepoint. |
15589 | ||
15590 | First command argument is passcount, second is tracepoint number. | |
15591 | If tracepoint number omitted, apply to most recently defined. | |
15592 | Also accepts special argument "all". */ | |
15593 | ||
15594 | static void | |
15595 | trace_pass_command (char *args, int from_tty) | |
15596 | { | |
d9b3f62e | 15597 | struct tracepoint *t1; |
1042e4c0 | 15598 | unsigned int count; |
1042e4c0 SS |
15599 | |
15600 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15601 | error (_("passcount command requires an " |
15602 | "argument (count + optional TP num)")); | |
1042e4c0 | 15603 | |
4a64f543 | 15604 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15605 | |
529480d0 | 15606 | args = skip_spaces (args); |
1042e4c0 SS |
15607 | if (*args && strncasecmp (args, "all", 3) == 0) |
15608 | { | |
d9b3f62e PA |
15609 | struct breakpoint *b; |
15610 | ||
1042e4c0 | 15611 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15612 | if (*args) |
15613 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15614 | |
d9b3f62e | 15615 | ALL_TRACEPOINTS (b) |
197f0a60 | 15616 | { |
d9b3f62e | 15617 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15618 | trace_pass_set_count (t1, count, from_tty); |
15619 | } | |
15620 | } | |
15621 | else if (*args == '\0') | |
1042e4c0 | 15622 | { |
5fa1d40e | 15623 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15624 | if (t1) |
197f0a60 TT |
15625 | trace_pass_set_count (t1, count, from_tty); |
15626 | } | |
15627 | else | |
15628 | { | |
bfd28288 PA |
15629 | number_or_range_parser parser (args); |
15630 | while (!parser.finished ()) | |
1042e4c0 | 15631 | { |
bfd28288 | 15632 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15633 | if (t1) |
15634 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15635 | } |
15636 | } | |
1042e4c0 SS |
15637 | } |
15638 | ||
d9b3f62e | 15639 | struct tracepoint * |
1042e4c0 SS |
15640 | get_tracepoint (int num) |
15641 | { | |
15642 | struct breakpoint *t; | |
15643 | ||
15644 | ALL_TRACEPOINTS (t) | |
15645 | if (t->number == num) | |
d9b3f62e | 15646 | return (struct tracepoint *) t; |
1042e4c0 SS |
15647 | |
15648 | return NULL; | |
15649 | } | |
15650 | ||
d5551862 SS |
15651 | /* Find the tracepoint with the given target-side number (which may be |
15652 | different from the tracepoint number after disconnecting and | |
15653 | reconnecting). */ | |
15654 | ||
d9b3f62e | 15655 | struct tracepoint * |
d5551862 SS |
15656 | get_tracepoint_by_number_on_target (int num) |
15657 | { | |
d9b3f62e | 15658 | struct breakpoint *b; |
d5551862 | 15659 | |
d9b3f62e PA |
15660 | ALL_TRACEPOINTS (b) |
15661 | { | |
15662 | struct tracepoint *t = (struct tracepoint *) b; | |
15663 | ||
15664 | if (t->number_on_target == num) | |
15665 | return t; | |
15666 | } | |
d5551862 SS |
15667 | |
15668 | return NULL; | |
15669 | } | |
15670 | ||
1042e4c0 | 15671 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15672 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15673 | If the argument is missing, the most recent tracepoint |
15674 | (tracepoint_count) is returned. */ | |
15675 | ||
d9b3f62e | 15676 | struct tracepoint * |
197f0a60 | 15677 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15678 | number_or_range_parser *parser) |
1042e4c0 | 15679 | { |
1042e4c0 SS |
15680 | struct breakpoint *t; |
15681 | int tpnum; | |
15682 | char *instring = arg == NULL ? NULL : *arg; | |
15683 | ||
bfd28288 | 15684 | if (parser != NULL) |
197f0a60 | 15685 | { |
bfd28288 PA |
15686 | gdb_assert (!parser->finished ()); |
15687 | tpnum = parser->get_number (); | |
197f0a60 TT |
15688 | } |
15689 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15690 | tpnum = tracepoint_count; |
1042e4c0 | 15691 | else |
197f0a60 | 15692 | tpnum = get_number (arg); |
1042e4c0 SS |
15693 | |
15694 | if (tpnum <= 0) | |
15695 | { | |
15696 | if (instring && *instring) | |
15697 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15698 | instring); | |
15699 | else | |
5fa1d40e | 15700 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15701 | return NULL; |
15702 | } | |
15703 | ||
15704 | ALL_TRACEPOINTS (t) | |
15705 | if (t->number == tpnum) | |
15706 | { | |
d9b3f62e | 15707 | return (struct tracepoint *) t; |
1042e4c0 SS |
15708 | } |
15709 | ||
1042e4c0 SS |
15710 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15711 | return NULL; | |
15712 | } | |
15713 | ||
d9b3f62e PA |
15714 | void |
15715 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15716 | { | |
15717 | if (b->thread != -1) | |
15718 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15719 | ||
15720 | if (b->task != 0) | |
15721 | fprintf_unfiltered (fp, " task %d", b->task); | |
15722 | ||
15723 | fprintf_unfiltered (fp, "\n"); | |
15724 | } | |
15725 | ||
6149aea9 PA |
15726 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15727 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15728 | on each breakpoint and only include the ones for which it returns | |
15729 | non-zero. */ | |
15730 | ||
1042e4c0 | 15731 | static void |
6149aea9 PA |
15732 | save_breakpoints (char *filename, int from_tty, |
15733 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15734 | { |
15735 | struct breakpoint *tp; | |
6149aea9 | 15736 | int any = 0; |
1042e4c0 | 15737 | struct cleanup *cleanup; |
a7bdde9e | 15738 | struct ui_file *fp; |
6149aea9 | 15739 | int extra_trace_bits = 0; |
1042e4c0 | 15740 | |
6149aea9 PA |
15741 | if (filename == 0 || *filename == 0) |
15742 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15743 | |
15744 | /* See if we have anything to save. */ | |
6149aea9 | 15745 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15746 | { |
6149aea9 | 15747 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15748 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15749 | continue; |
15750 | ||
15751 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15752 | if (filter && !filter (tp)) | |
15753 | continue; | |
15754 | ||
15755 | any = 1; | |
15756 | ||
15757 | if (is_tracepoint (tp)) | |
15758 | { | |
15759 | extra_trace_bits = 1; | |
15760 | ||
15761 | /* We can stop searching. */ | |
15762 | break; | |
15763 | } | |
1042e4c0 | 15764 | } |
6149aea9 PA |
15765 | |
15766 | if (!any) | |
1042e4c0 | 15767 | { |
6149aea9 | 15768 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15769 | return; |
15770 | } | |
15771 | ||
c718be47 PA |
15772 | filename = tilde_expand (filename); |
15773 | cleanup = make_cleanup (xfree, filename); | |
15774 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15775 | if (!fp) |
6149aea9 PA |
15776 | error (_("Unable to open file '%s' for saving (%s)"), |
15777 | filename, safe_strerror (errno)); | |
a7bdde9e | 15778 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15779 | |
6149aea9 PA |
15780 | if (extra_trace_bits) |
15781 | save_trace_state_variables (fp); | |
8bf6485c | 15782 | |
6149aea9 | 15783 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15784 | { |
6149aea9 | 15785 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15786 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15787 | continue; |
8bf6485c | 15788 | |
6149aea9 PA |
15789 | /* If we have a filter, only save the breakpoints it accepts. */ |
15790 | if (filter && !filter (tp)) | |
15791 | continue; | |
15792 | ||
348d480f | 15793 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15794 | |
6149aea9 PA |
15795 | /* Note, we can't rely on tp->number for anything, as we can't |
15796 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15797 | instead. */ | |
15798 | ||
15799 | if (tp->cond_string) | |
15800 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15801 | ||
15802 | if (tp->ignore_count) | |
15803 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15804 | ||
2d9442cc | 15805 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15806 | { |
6149aea9 | 15807 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15808 | |
79a45e25 | 15809 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15810 | TRY |
1042e4c0 | 15811 | { |
79a45e25 | 15812 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15813 | } |
492d29ea PA |
15814 | CATCH (ex, RETURN_MASK_ALL) |
15815 | { | |
6c63c96a | 15816 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15817 | throw_exception (ex); |
15818 | } | |
15819 | END_CATCH | |
1042e4c0 | 15820 | |
6c63c96a | 15821 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15822 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15823 | } |
6149aea9 PA |
15824 | |
15825 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15826 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15827 | |
15828 | /* If this is a multi-location breakpoint, check if the locations | |
15829 | should be individually disabled. Watchpoint locations are | |
15830 | special, and not user visible. */ | |
15831 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15832 | { | |
15833 | struct bp_location *loc; | |
15834 | int n = 1; | |
15835 | ||
15836 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15837 | if (!loc->enabled) | |
15838 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15839 | } | |
1042e4c0 | 15840 | } |
8bf6485c | 15841 | |
6149aea9 | 15842 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15843 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15844 | ||
1042e4c0 | 15845 | if (from_tty) |
6149aea9 | 15846 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15847 | do_cleanups (cleanup); |
6149aea9 PA |
15848 | } |
15849 | ||
15850 | /* The `save breakpoints' command. */ | |
15851 | ||
15852 | static void | |
15853 | save_breakpoints_command (char *args, int from_tty) | |
15854 | { | |
15855 | save_breakpoints (args, from_tty, NULL); | |
15856 | } | |
15857 | ||
15858 | /* The `save tracepoints' command. */ | |
15859 | ||
15860 | static void | |
15861 | save_tracepoints_command (char *args, int from_tty) | |
15862 | { | |
15863 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15864 | } |
15865 | ||
15866 | /* Create a vector of all tracepoints. */ | |
15867 | ||
15868 | VEC(breakpoint_p) * | |
eeae04df | 15869 | all_tracepoints (void) |
1042e4c0 SS |
15870 | { |
15871 | VEC(breakpoint_p) *tp_vec = 0; | |
15872 | struct breakpoint *tp; | |
15873 | ||
15874 | ALL_TRACEPOINTS (tp) | |
15875 | { | |
15876 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15877 | } | |
15878 | ||
15879 | return tp_vec; | |
15880 | } | |
15881 | ||
c906108c | 15882 | \f |
629500fa KS |
15883 | /* This help string is used to consolidate all the help string for specifying |
15884 | locations used by several commands. */ | |
15885 | ||
15886 | #define LOCATION_HELP_STRING \ | |
15887 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15888 | source filename, function name, label name, and line number.\n\ | |
15889 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15890 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15891 | \"factorial.c:fact:the_top\".\n\ | |
15892 | \n\ | |
15893 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15894 | program. Example: To specify the fourth byte past the start function\n\ | |
15895 | \"main\", use \"*main + 4\".\n\ | |
15896 | \n\ | |
15897 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15898 | syntax to specify location parameters.\n\ | |
15899 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15900 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15901 | -function fact -label the_top\".\n" | |
15902 | ||
4a64f543 MS |
15903 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15904 | commands. It is defined as a macro to prevent duplication. | |
15905 | COMMAND should be a string constant containing the name of the | |
15906 | command. */ | |
629500fa | 15907 | |
31e2b00f | 15908 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15909 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15910 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15911 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15912 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15913 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15914 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15915 | below.\n\ | |
15916 | \n\ | |
dc10affe PA |
15917 | With no LOCATION, uses current execution address of the selected\n\ |
15918 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15919 | \n\ |
15920 | THREADNUM is the number from \"info threads\".\n\ | |
15921 | CONDITION is a boolean expression.\n\ | |
629500fa | 15922 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15923 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15924 | conditions are different.\n\ | |
31e2b00f AS |
15925 | \n\ |
15926 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15927 | ||
44feb3ce TT |
15928 | /* List of subcommands for "catch". */ |
15929 | static struct cmd_list_element *catch_cmdlist; | |
15930 | ||
15931 | /* List of subcommands for "tcatch". */ | |
15932 | static struct cmd_list_element *tcatch_cmdlist; | |
15933 | ||
9ac4176b | 15934 | void |
44feb3ce | 15935 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15936 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15937 | completer_ftype *completer, |
44feb3ce TT |
15938 | void *user_data_catch, |
15939 | void *user_data_tcatch) | |
15940 | { | |
15941 | struct cmd_list_element *command; | |
15942 | ||
15943 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15944 | &catch_cmdlist); | |
15945 | set_cmd_sfunc (command, sfunc); | |
15946 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15947 | set_cmd_completer (command, completer); |
44feb3ce TT |
15948 | |
15949 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15950 | &tcatch_cmdlist); | |
15951 | set_cmd_sfunc (command, sfunc); | |
15952 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15953 | set_cmd_completer (command, completer); |
44feb3ce TT |
15954 | } |
15955 | ||
6149aea9 PA |
15956 | static void |
15957 | save_command (char *arg, int from_tty) | |
15958 | { | |
3e43a32a MS |
15959 | printf_unfiltered (_("\"save\" must be followed by " |
15960 | "the name of a save subcommand.\n")); | |
635c7e8a | 15961 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15962 | } |
15963 | ||
84f4c1fe PM |
15964 | struct breakpoint * |
15965 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15966 | void *data) | |
15967 | { | |
35df4500 | 15968 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15969 | |
35df4500 | 15970 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15971 | { |
15972 | if ((*callback) (b, data)) | |
15973 | return b; | |
15974 | } | |
15975 | ||
15976 | return NULL; | |
15977 | } | |
15978 | ||
0574c78f GB |
15979 | /* Zero if any of the breakpoint's locations could be a location where |
15980 | functions have been inlined, nonzero otherwise. */ | |
15981 | ||
15982 | static int | |
15983 | is_non_inline_function (struct breakpoint *b) | |
15984 | { | |
15985 | /* The shared library event breakpoint is set on the address of a | |
15986 | non-inline function. */ | |
15987 | if (b->type == bp_shlib_event) | |
15988 | return 1; | |
15989 | ||
15990 | return 0; | |
15991 | } | |
15992 | ||
15993 | /* Nonzero if the specified PC cannot be a location where functions | |
15994 | have been inlined. */ | |
15995 | ||
15996 | int | |
09ac7c10 TT |
15997 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15998 | const struct target_waitstatus *ws) | |
0574c78f GB |
15999 | { |
16000 | struct breakpoint *b; | |
16001 | struct bp_location *bl; | |
16002 | ||
16003 | ALL_BREAKPOINTS (b) | |
16004 | { | |
16005 | if (!is_non_inline_function (b)) | |
16006 | continue; | |
16007 | ||
16008 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
16009 | { | |
16010 | if (!bl->shlib_disabled | |
09ac7c10 | 16011 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
16012 | return 1; |
16013 | } | |
16014 | } | |
16015 | ||
16016 | return 0; | |
16017 | } | |
16018 | ||
2f202fde JK |
16019 | /* Remove any references to OBJFILE which is going to be freed. */ |
16020 | ||
16021 | void | |
16022 | breakpoint_free_objfile (struct objfile *objfile) | |
16023 | { | |
16024 | struct bp_location **locp, *loc; | |
16025 | ||
16026 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 16027 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
16028 | loc->symtab = NULL; |
16029 | } | |
16030 | ||
2060206e PA |
16031 | void |
16032 | initialize_breakpoint_ops (void) | |
16033 | { | |
16034 | static int initialized = 0; | |
16035 | ||
16036 | struct breakpoint_ops *ops; | |
16037 | ||
16038 | if (initialized) | |
16039 | return; | |
16040 | initialized = 1; | |
16041 | ||
16042 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16043 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16044 | internal and momentary breakpoints, etc.). */ | |
16045 | ops = &bkpt_base_breakpoint_ops; | |
16046 | *ops = base_breakpoint_ops; | |
16047 | ops->re_set = bkpt_re_set; | |
16048 | ops->insert_location = bkpt_insert_location; | |
16049 | ops->remove_location = bkpt_remove_location; | |
16050 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 16051 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 16052 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 16053 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
16054 | |
16055 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16056 | ops = &bkpt_breakpoint_ops; | |
16057 | *ops = bkpt_base_breakpoint_ops; | |
16058 | ops->re_set = bkpt_re_set; | |
16059 | ops->resources_needed = bkpt_resources_needed; | |
16060 | ops->print_it = bkpt_print_it; | |
16061 | ops->print_mention = bkpt_print_mention; | |
16062 | ops->print_recreate = bkpt_print_recreate; | |
16063 | ||
16064 | /* Ranged breakpoints. */ | |
16065 | ops = &ranged_breakpoint_ops; | |
16066 | *ops = bkpt_breakpoint_ops; | |
16067 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16068 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16069 | ops->print_it = print_it_ranged_breakpoint; | |
16070 | ops->print_one = print_one_ranged_breakpoint; | |
16071 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16072 | ops->print_mention = print_mention_ranged_breakpoint; | |
16073 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16074 | ||
16075 | /* Internal breakpoints. */ | |
16076 | ops = &internal_breakpoint_ops; | |
16077 | *ops = bkpt_base_breakpoint_ops; | |
16078 | ops->re_set = internal_bkpt_re_set; | |
16079 | ops->check_status = internal_bkpt_check_status; | |
16080 | ops->print_it = internal_bkpt_print_it; | |
16081 | ops->print_mention = internal_bkpt_print_mention; | |
16082 | ||
16083 | /* Momentary breakpoints. */ | |
16084 | ops = &momentary_breakpoint_ops; | |
16085 | *ops = bkpt_base_breakpoint_ops; | |
16086 | ops->re_set = momentary_bkpt_re_set; | |
16087 | ops->check_status = momentary_bkpt_check_status; | |
16088 | ops->print_it = momentary_bkpt_print_it; | |
16089 | ops->print_mention = momentary_bkpt_print_mention; | |
16090 | ||
e2e4d78b JK |
16091 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16092 | ops = &longjmp_breakpoint_ops; | |
16093 | *ops = momentary_breakpoint_ops; | |
16094 | ops->dtor = longjmp_bkpt_dtor; | |
16095 | ||
55aa24fb SDJ |
16096 | /* Probe breakpoints. */ |
16097 | ops = &bkpt_probe_breakpoint_ops; | |
16098 | *ops = bkpt_breakpoint_ops; | |
16099 | ops->insert_location = bkpt_probe_insert_location; | |
16100 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16101 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16102 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16103 | |
2060206e PA |
16104 | /* Watchpoints. */ |
16105 | ops = &watchpoint_breakpoint_ops; | |
16106 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16107 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16108 | ops->re_set = re_set_watchpoint; |
16109 | ops->insert_location = insert_watchpoint; | |
16110 | ops->remove_location = remove_watchpoint; | |
16111 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16112 | ops->check_status = check_status_watchpoint; | |
16113 | ops->resources_needed = resources_needed_watchpoint; | |
16114 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16115 | ops->print_it = print_it_watchpoint; | |
16116 | ops->print_mention = print_mention_watchpoint; | |
16117 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16118 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16119 | |
16120 | /* Masked watchpoints. */ | |
16121 | ops = &masked_watchpoint_breakpoint_ops; | |
16122 | *ops = watchpoint_breakpoint_ops; | |
16123 | ops->insert_location = insert_masked_watchpoint; | |
16124 | ops->remove_location = remove_masked_watchpoint; | |
16125 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16126 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16127 | ops->print_it = print_it_masked_watchpoint; | |
16128 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16129 | ops->print_mention = print_mention_masked_watchpoint; | |
16130 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16131 | ||
16132 | /* Tracepoints. */ | |
16133 | ops = &tracepoint_breakpoint_ops; | |
16134 | *ops = base_breakpoint_ops; | |
16135 | ops->re_set = tracepoint_re_set; | |
16136 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16137 | ops->print_one_detail = tracepoint_print_one_detail; | |
16138 | ops->print_mention = tracepoint_print_mention; | |
16139 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16140 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16141 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16142 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16143 | |
55aa24fb SDJ |
16144 | /* Probe tracepoints. */ |
16145 | ops = &tracepoint_probe_breakpoint_ops; | |
16146 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16147 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16148 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16149 | |
983af33b SDJ |
16150 | /* Static tracepoints with marker (`-m'). */ |
16151 | ops = &strace_marker_breakpoint_ops; | |
16152 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16153 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16154 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16155 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16156 | |
16157 | /* Fork catchpoints. */ | |
16158 | ops = &catch_fork_breakpoint_ops; | |
16159 | *ops = base_breakpoint_ops; | |
16160 | ops->insert_location = insert_catch_fork; | |
16161 | ops->remove_location = remove_catch_fork; | |
16162 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16163 | ops->print_it = print_it_catch_fork; | |
16164 | ops->print_one = print_one_catch_fork; | |
16165 | ops->print_mention = print_mention_catch_fork; | |
16166 | ops->print_recreate = print_recreate_catch_fork; | |
16167 | ||
16168 | /* Vfork catchpoints. */ | |
16169 | ops = &catch_vfork_breakpoint_ops; | |
16170 | *ops = base_breakpoint_ops; | |
16171 | ops->insert_location = insert_catch_vfork; | |
16172 | ops->remove_location = remove_catch_vfork; | |
16173 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16174 | ops->print_it = print_it_catch_vfork; | |
16175 | ops->print_one = print_one_catch_vfork; | |
16176 | ops->print_mention = print_mention_catch_vfork; | |
16177 | ops->print_recreate = print_recreate_catch_vfork; | |
16178 | ||
16179 | /* Exec catchpoints. */ | |
16180 | ops = &catch_exec_breakpoint_ops; | |
16181 | *ops = base_breakpoint_ops; | |
16182 | ops->dtor = dtor_catch_exec; | |
16183 | ops->insert_location = insert_catch_exec; | |
16184 | ops->remove_location = remove_catch_exec; | |
16185 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16186 | ops->print_it = print_it_catch_exec; | |
16187 | ops->print_one = print_one_catch_exec; | |
16188 | ops->print_mention = print_mention_catch_exec; | |
16189 | ops->print_recreate = print_recreate_catch_exec; | |
16190 | ||
edcc5120 TT |
16191 | /* Solib-related catchpoints. */ |
16192 | ops = &catch_solib_breakpoint_ops; | |
16193 | *ops = base_breakpoint_ops; | |
16194 | ops->dtor = dtor_catch_solib; | |
16195 | ops->insert_location = insert_catch_solib; | |
16196 | ops->remove_location = remove_catch_solib; | |
16197 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16198 | ops->check_status = check_status_catch_solib; | |
16199 | ops->print_it = print_it_catch_solib; | |
16200 | ops->print_one = print_one_catch_solib; | |
16201 | ops->print_mention = print_mention_catch_solib; | |
16202 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16203 | |
16204 | ops = &dprintf_breakpoint_ops; | |
16205 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16206 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16207 | ops->resources_needed = bkpt_resources_needed; |
16208 | ops->print_it = bkpt_print_it; | |
16209 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16210 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16211 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16212 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16213 | } |
16214 | ||
8bfd80db YQ |
16215 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16216 | ||
16217 | static struct cmd_list_element *enablebreaklist = NULL; | |
16218 | ||
c906108c | 16219 | void |
fba45db2 | 16220 | _initialize_breakpoint (void) |
c906108c SS |
16221 | { |
16222 | struct cmd_list_element *c; | |
16223 | ||
2060206e PA |
16224 | initialize_breakpoint_ops (); |
16225 | ||
84acb35a | 16226 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16227 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16228 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16229 | |
55aa24fb SDJ |
16230 | breakpoint_objfile_key |
16231 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16232 | |
c906108c SS |
16233 | breakpoint_chain = 0; |
16234 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16235 | before a breakpoint is set. */ | |
16236 | breakpoint_count = 0; | |
16237 | ||
1042e4c0 SS |
16238 | tracepoint_count = 0; |
16239 | ||
1bedd215 AC |
16240 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16241 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16242 | Usage is `ignore N COUNT'.")); | |
c906108c | 16243 | |
1bedd215 AC |
16244 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16245 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16246 | Give breakpoint number as argument after \"commands\".\n\ |
16247 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16248 | The commands themselves follow starting on the next line.\n\ | |
16249 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16250 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16251 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16252 | |
d55637df | 16253 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16254 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16255 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16256 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16257 | set_cmd_completer (c, condition_completer); |
c906108c | 16258 | |
1bedd215 | 16259 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16260 | Set a temporary breakpoint.\n\ |
c906108c SS |
16261 | Like \"break\" except the breakpoint is only temporary,\n\ |
16262 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16263 | by using \"enable delete\" on the breakpoint number.\n\ |
16264 | \n" | |
16265 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16266 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16267 | |
1bedd215 | 16268 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16269 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16270 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16271 | some target hardware may not have this support.\n\ |
16272 | \n" | |
16273 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16274 | set_cmd_completer (c, location_completer); |
c906108c | 16275 | |
1bedd215 | 16276 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16277 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16278 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16279 | so it will be deleted when hit.\n\ |
16280 | \n" | |
16281 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16282 | set_cmd_completer (c, location_completer); |
c906108c | 16283 | |
1bedd215 AC |
16284 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16285 | Enable some breakpoints.\n\ | |
c906108c SS |
16286 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16287 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16288 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16289 | With a subcommand you can enable temporarily."), |
c906108c | 16290 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16291 | |
16292 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16293 | ||
84951ab5 | 16294 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16295 | Enable some breakpoints.\n\ |
c906108c SS |
16296 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16297 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16298 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16299 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16300 | |
1a966eab AC |
16301 | add_cmd ("once", no_class, enable_once_command, _("\ |
16302 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16303 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16304 | &enablebreaklist); |
16305 | ||
1a966eab AC |
16306 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16307 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16308 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16309 | &enablebreaklist); |
16310 | ||
816338b5 SS |
16311 | add_cmd ("count", no_class, enable_count_command, _("\ |
16312 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16313 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16314 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16315 | &enablebreaklist); | |
16316 | ||
1a966eab AC |
16317 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16318 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16319 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16320 | &enablelist); |
16321 | ||
1a966eab AC |
16322 | add_cmd ("once", no_class, enable_once_command, _("\ |
16323 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16324 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16325 | &enablelist); |
16326 | ||
16327 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16328 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16329 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16330 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16331 | &enablelist); |
16332 | ||
1bedd215 AC |
16333 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16334 | Disable some breakpoints.\n\ | |
c906108c SS |
16335 | Arguments are breakpoint numbers with spaces in between.\n\ |
16336 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16337 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16338 | &disablelist, "disable ", 1, &cmdlist); |
16339 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16340 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16341 | |
1a966eab AC |
16342 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16343 | Disable some breakpoints.\n\ | |
c906108c SS |
16344 | Arguments are breakpoint numbers with spaces in between.\n\ |
16345 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16346 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16347 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16348 | &disablelist); |
16349 | ||
1bedd215 AC |
16350 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16351 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16352 | Arguments are breakpoint numbers with spaces in between.\n\ |
16353 | To delete all breakpoints, give no argument.\n\ | |
16354 | \n\ | |
16355 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16356 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16357 | &deletelist, "delete ", 1, &cmdlist); |
16358 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16359 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16360 | |
1a966eab AC |
16361 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16362 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16363 | Arguments are breakpoint numbers with spaces in between.\n\ |
16364 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16365 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16366 | &deletelist); |
16367 | ||
1bedd215 | 16368 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16369 | Clear breakpoint at specified location.\n\ |
16370 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16371 | \n\ |
16372 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16373 | is executing in.\n" |
16374 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16375 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16376 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16377 | |
1bedd215 | 16378 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16379 | Set breakpoint at specified location.\n" |
31e2b00f | 16380 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16381 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16382 | |
c906108c SS |
16383 | add_com_alias ("b", "break", class_run, 1); |
16384 | add_com_alias ("br", "break", class_run, 1); | |
16385 | add_com_alias ("bre", "break", class_run, 1); | |
16386 | add_com_alias ("brea", "break", class_run, 1); | |
16387 | ||
c906108c SS |
16388 | if (dbx_commands) |
16389 | { | |
1bedd215 AC |
16390 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16391 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16392 | &stoplist, "stop ", 1, &cmdlist); |
16393 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16394 | _("Break in function or address."), &stoplist); |
c5aa993b | 16395 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16396 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16397 | add_com ("status", class_info, breakpoints_info, _("\ |
16398 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16399 | The \"Type\" column indicates one of:\n\ |
16400 | \tbreakpoint - normal breakpoint\n\ | |
16401 | \twatchpoint - watchpoint\n\ | |
16402 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16403 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16404 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16405 | address and file/line number respectively.\n\ |
16406 | \n\ | |
16407 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16408 | are set to the address of the last breakpoint listed unless the command\n\ |
16409 | is prefixed with \"server \".\n\n\ | |
c906108c | 16410 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16411 | breakpoint set.")); |
c906108c SS |
16412 | } |
16413 | ||
1bedd215 | 16414 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16415 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16416 | The \"Type\" column indicates one of:\n\ |
16417 | \tbreakpoint - normal breakpoint\n\ | |
16418 | \twatchpoint - watchpoint\n\ | |
16419 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16420 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16421 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16422 | address and file/line number respectively.\n\ |
16423 | \n\ | |
16424 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16425 | are set to the address of the last breakpoint listed unless the command\n\ |
16426 | is prefixed with \"server \".\n\n\ | |
c906108c | 16427 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16428 | breakpoint set.")); |
c906108c | 16429 | |
6b04bdb7 MS |
16430 | add_info_alias ("b", "breakpoints", 1); |
16431 | ||
1a966eab AC |
16432 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16433 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16434 | The \"Type\" column indicates one of:\n\ |
16435 | \tbreakpoint - normal breakpoint\n\ | |
16436 | \twatchpoint - watchpoint\n\ | |
16437 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16438 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16439 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16440 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16441 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16442 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16443 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16444 | address and file/line number respectively.\n\ |
16445 | \n\ | |
16446 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16447 | are set to the address of the last breakpoint listed unless the command\n\ |
16448 | is prefixed with \"server \".\n\n\ | |
c906108c | 16449 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16450 | breakpoint set."), |
c906108c SS |
16451 | &maintenanceinfolist); |
16452 | ||
44feb3ce TT |
16453 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16454 | Set catchpoints to catch events."), | |
16455 | &catch_cmdlist, "catch ", | |
16456 | 0/*allow-unknown*/, &cmdlist); | |
16457 | ||
16458 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16459 | Set temporary catchpoints to catch events."), | |
16460 | &tcatch_cmdlist, "tcatch ", | |
16461 | 0/*allow-unknown*/, &cmdlist); | |
16462 | ||
44feb3ce TT |
16463 | add_catch_command ("fork", _("Catch calls to fork."), |
16464 | catch_fork_command_1, | |
a96d9b2e | 16465 | NULL, |
44feb3ce TT |
16466 | (void *) (uintptr_t) catch_fork_permanent, |
16467 | (void *) (uintptr_t) catch_fork_temporary); | |
16468 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16469 | catch_fork_command_1, | |
a96d9b2e | 16470 | NULL, |
44feb3ce TT |
16471 | (void *) (uintptr_t) catch_vfork_permanent, |
16472 | (void *) (uintptr_t) catch_vfork_temporary); | |
16473 | add_catch_command ("exec", _("Catch calls to exec."), | |
16474 | catch_exec_command_1, | |
a96d9b2e SDJ |
16475 | NULL, |
16476 | CATCH_PERMANENT, | |
16477 | CATCH_TEMPORARY); | |
edcc5120 TT |
16478 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16479 | Usage: catch load [REGEX]\n\ | |
16480 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16481 | catch_load_command_1, | |
16482 | NULL, | |
16483 | CATCH_PERMANENT, | |
16484 | CATCH_TEMPORARY); | |
16485 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16486 | Usage: catch unload [REGEX]\n\ | |
16487 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16488 | catch_unload_command_1, | |
16489 | NULL, | |
16490 | CATCH_PERMANENT, | |
16491 | CATCH_TEMPORARY); | |
c5aa993b | 16492 | |
1bedd215 AC |
16493 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16494 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16495 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16496 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16497 | an expression changes.\n\ |
16498 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16499 | the memory to which it refers.")); | |
65d12d83 | 16500 | set_cmd_completer (c, expression_completer); |
c906108c | 16501 | |
1bedd215 AC |
16502 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16503 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16504 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16505 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16506 | an expression is read.\n\ |
16507 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16508 | the memory to which it refers.")); | |
65d12d83 | 16509 | set_cmd_completer (c, expression_completer); |
c906108c | 16510 | |
1bedd215 AC |
16511 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16512 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16513 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16514 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16515 | an expression is either read or written.\n\ |
16516 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16517 | the memory to which it refers.")); | |
65d12d83 | 16518 | set_cmd_completer (c, expression_completer); |
c906108c | 16519 | |
d77f58be | 16520 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16521 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16522 | |
920d2a44 AC |
16523 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16524 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16525 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16526 | &can_use_hw_watchpoints, _("\ | |
16527 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16528 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16529 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16530 | such is available. (However, any hardware watchpoints that were\n\ | |
16531 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16532 | hardware.)"), |
16533 | NULL, | |
920d2a44 | 16534 | show_can_use_hw_watchpoints, |
85c07804 | 16535 | &setlist, &showlist); |
c906108c SS |
16536 | |
16537 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16538 | |
1042e4c0 SS |
16539 | /* Tracepoint manipulation commands. */ |
16540 | ||
16541 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16542 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16543 | \n" |
16544 | BREAK_ARGS_HELP ("trace") "\n\ | |
16545 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16546 | set_cmd_completer (c, location_completer); | |
16547 | ||
16548 | add_com_alias ("tp", "trace", class_alias, 0); | |
16549 | add_com_alias ("tr", "trace", class_alias, 1); | |
16550 | add_com_alias ("tra", "trace", class_alias, 1); | |
16551 | add_com_alias ("trac", "trace", class_alias, 1); | |
16552 | ||
7a697b8d | 16553 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16554 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16555 | \n" |
16556 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16557 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16558 | set_cmd_completer (c, location_completer); | |
16559 | ||
0fb4aa4b | 16560 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16561 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16562 | \n\ |
16563 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16564 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16565 | or -m MARKER_ID.\n\n\ | |
16566 | If a marker id is specified, probe the marker with that name. With\n\ | |
16567 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16568 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16569 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16570 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16571 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16572 | \n\ | |
16573 | CONDITION is a boolean expression.\n\ | |
629500fa | 16574 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16575 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16576 | conditions are different.\n\ | |
0fb4aa4b PA |
16577 | \n\ |
16578 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16579 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16580 | set_cmd_completer (c, location_completer); | |
16581 | ||
1042e4c0 | 16582 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16583 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16584 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16585 | last tracepoint set.")); | |
16586 | ||
16587 | add_info_alias ("tp", "tracepoints", 1); | |
16588 | ||
16589 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16590 | Delete specified tracepoints.\n\ | |
16591 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16592 | No argument means delete all tracepoints."), | |
16593 | &deletelist); | |
7e20dfcd | 16594 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16595 | |
16596 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16597 | Disable specified tracepoints.\n\ | |
16598 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16599 | No argument means disable all tracepoints."), | |
16600 | &disablelist); | |
16601 | deprecate_cmd (c, "disable"); | |
16602 | ||
16603 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16604 | Enable specified tracepoints.\n\ | |
16605 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16606 | No argument means enable all tracepoints."), | |
16607 | &enablelist); | |
16608 | deprecate_cmd (c, "enable"); | |
16609 | ||
16610 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16611 | Set the passcount for a tracepoint.\n\ | |
16612 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16613 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16614 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16615 | ||
6149aea9 PA |
16616 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16617 | _("Save breakpoint definitions as a script."), | |
16618 | &save_cmdlist, "save ", | |
16619 | 0/*allow-unknown*/, &cmdlist); | |
16620 | ||
16621 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16622 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16623 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16624 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16625 | session to restore them."), | |
16626 | &save_cmdlist); | |
16627 | set_cmd_completer (c, filename_completer); | |
16628 | ||
16629 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16630 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16631 | Use the 'source' command in another debug session to restore them."), |
16632 | &save_cmdlist); | |
1042e4c0 SS |
16633 | set_cmd_completer (c, filename_completer); |
16634 | ||
6149aea9 PA |
16635 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16636 | deprecate_cmd (c, "save tracepoints"); | |
16637 | ||
1bedd215 | 16638 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16639 | Breakpoint specific settings\n\ |
16640 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16641 | pending breakpoint behavior"), |
fa8d40ab JJ |
16642 | &breakpoint_set_cmdlist, "set breakpoint ", |
16643 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16644 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16645 | Breakpoint specific settings\n\ |
16646 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16647 | pending breakpoint behavior"), |
fa8d40ab JJ |
16648 | &breakpoint_show_cmdlist, "show breakpoint ", |
16649 | 0/*allow-unknown*/, &showlist); | |
16650 | ||
7915a72c AC |
16651 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16652 | &pending_break_support, _("\ | |
16653 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16654 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16655 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16656 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16657 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16658 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16659 | NULL, |
920d2a44 | 16660 | show_pending_break_support, |
6e1d7d6c AC |
16661 | &breakpoint_set_cmdlist, |
16662 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16663 | |
16664 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16665 | |
16666 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16667 | &automatic_hardware_breakpoints, _("\ | |
16668 | Set automatic usage of hardware breakpoints."), _("\ | |
16669 | Show automatic usage of hardware breakpoints."), _("\ | |
16670 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16671 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16672 | a warning will be emitted for such breakpoints."), | |
16673 | NULL, | |
16674 | show_automatic_hardware_breakpoints, | |
16675 | &breakpoint_set_cmdlist, | |
16676 | &breakpoint_show_cmdlist); | |
74960c60 | 16677 | |
a25a5a45 PA |
16678 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16679 | &always_inserted_mode, _("\ | |
74960c60 VP |
16680 | Set mode for inserting breakpoints."), _("\ |
16681 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16682 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16683 | they're created, kept inserted even when execution stops, and removed\n\ | |
16684 | only when the user deletes them. When this mode is off (the default),\n\ | |
16685 | breakpoints are inserted only when execution continues, and removed\n\ | |
16686 | when execution stops."), | |
72d0e2c5 YQ |
16687 | NULL, |
16688 | &show_always_inserted_mode, | |
16689 | &breakpoint_set_cmdlist, | |
16690 | &breakpoint_show_cmdlist); | |
f1310107 | 16691 | |
b775012e LM |
16692 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16693 | condition_evaluation_enums, | |
16694 | &condition_evaluation_mode_1, _("\ | |
16695 | Set mode of breakpoint condition evaluation."), _("\ | |
16696 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16697 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16698 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16699 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16700 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16701 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16702 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16703 | be set to \"gdb\""), | |
16704 | &set_condition_evaluation_mode, | |
16705 | &show_condition_evaluation_mode, | |
16706 | &breakpoint_set_cmdlist, | |
16707 | &breakpoint_show_cmdlist); | |
16708 | ||
f1310107 TJB |
16709 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16710 | Set a breakpoint for an address range.\n\ | |
16711 | break-range START-LOCATION, END-LOCATION\n\ | |
16712 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16713 | LINENUM, for that line in the current file,\n\ | |
16714 | FILE:LINENUM, for that line in that file,\n\ | |
16715 | +OFFSET, for that number of lines after the current line\n\ | |
16716 | or the start of the range\n\ | |
16717 | FUNCTION, for the first line in that function,\n\ | |
16718 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16719 | *ADDRESS, for the instruction at that address.\n\ | |
16720 | \n\ | |
16721 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16722 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16723 | range (including START-LOCATION and END-LOCATION).")); | |
16724 | ||
e7e0cddf | 16725 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16726 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16727 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16728 | location may be a linespec, explicit, or address location.\n" |
16729 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16730 | set_cmd_completer (c, location_completer); |
16731 | ||
16732 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16733 | dprintf_style_enums, &dprintf_style, _("\ | |
16734 | Set the style of usage for dynamic printf."), _("\ | |
16735 | Show the style of usage for dynamic printf."), _("\ | |
16736 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16737 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16738 | console, as with the \"printf\" command.\n\ | |
16739 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16740 | program; by default printf(), but you can choose a different function or\n\ | |
16741 | output stream by setting dprintf-function and dprintf-channel."), | |
16742 | update_dprintf_commands, NULL, | |
16743 | &setlist, &showlist); | |
16744 | ||
16745 | dprintf_function = xstrdup ("printf"); | |
16746 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16747 | &dprintf_function, _("\ | |
16748 | Set the function to use for dynamic printf"), _("\ | |
16749 | Show the function to use for dynamic printf"), NULL, | |
16750 | update_dprintf_commands, NULL, | |
16751 | &setlist, &showlist); | |
16752 | ||
16753 | dprintf_channel = xstrdup (""); | |
16754 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16755 | &dprintf_channel, _("\ | |
16756 | Set the channel to use for dynamic printf"), _("\ | |
16757 | Show the channel to use for dynamic printf"), NULL, | |
16758 | update_dprintf_commands, NULL, | |
16759 | &setlist, &showlist); | |
16760 | ||
d3ce09f5 SS |
16761 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16762 | &disconnected_dprintf, _("\ | |
16763 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16764 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16765 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16766 | even if GDB disconnects or detaches from the target."), | |
16767 | NULL, | |
16768 | NULL, | |
16769 | &setlist, &showlist); | |
16770 | ||
16771 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16772 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16773 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16774 | ||
765dc015 | 16775 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16776 | |
16777 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16778 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16779 | } |