Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 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" |
d3ce09f5 | 72 | |
1042e4c0 SS |
73 | /* readline include files */ |
74 | #include "readline/readline.h" | |
75 | #include "readline/history.h" | |
76 | ||
77 | /* readline defines this. */ | |
78 | #undef savestring | |
79 | ||
034dad6f | 80 | #include "mi/mi-common.h" |
6dddc817 | 81 | #include "extension.h" |
104c1213 | 82 | |
e7e8980f YQ |
83 | /* Enums for exception-handling support. */ |
84 | enum exception_event_kind | |
85 | { | |
86 | EX_EVENT_THROW, | |
591f19e8 | 87 | EX_EVENT_RETHROW, |
e7e8980f YQ |
88 | EX_EVENT_CATCH |
89 | }; | |
90 | ||
4a64f543 | 91 | /* Prototypes for local functions. */ |
c906108c | 92 | |
a14ed312 | 93 | static void enable_delete_command (char *, int); |
c906108c | 94 | |
a14ed312 | 95 | static void enable_once_command (char *, int); |
c906108c | 96 | |
816338b5 SS |
97 | static void enable_count_command (char *, int); |
98 | ||
a14ed312 | 99 | static void disable_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void enable_command (char *, int); |
c906108c | 102 | |
95a42b64 TT |
103 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
104 | void *), | |
105 | void *); | |
c906108c | 106 | |
a14ed312 | 107 | static void ignore_command (char *, int); |
c906108c | 108 | |
4efb68b1 | 109 | static int breakpoint_re_set_one (void *); |
c906108c | 110 | |
348d480f PA |
111 | static void breakpoint_re_set_default (struct breakpoint *); |
112 | ||
f00aae0f KS |
113 | static void |
114 | create_sals_from_location_default (const struct event_location *location, | |
115 | struct linespec_result *canonical, | |
116 | enum bptype type_wanted); | |
983af33b SDJ |
117 | |
118 | static void create_breakpoints_sal_default (struct gdbarch *, | |
119 | struct linespec_result *, | |
e7e0cddf | 120 | char *, char *, enum bptype, |
983af33b SDJ |
121 | enum bpdisp, int, int, |
122 | int, | |
123 | const struct breakpoint_ops *, | |
44f238bb | 124 | int, int, int, unsigned); |
983af33b | 125 | |
f00aae0f KS |
126 | static void decode_location_default (struct breakpoint *b, |
127 | const struct event_location *location, | |
128 | struct symtabs_and_lines *sals); | |
983af33b | 129 | |
a14ed312 | 130 | static void clear_command (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void catch_command (char *, int); |
c906108c | 133 | |
a9634178 | 134 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 135 | |
98deb0da | 136 | static void break_command_1 (char *, int, int); |
c906108c | 137 | |
a14ed312 | 138 | static void mention (struct breakpoint *); |
c906108c | 139 | |
348d480f PA |
140 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
141 | enum bptype, | |
c0a91b2b | 142 | const struct breakpoint_ops *); |
3742cc8b YQ |
143 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
144 | const struct symtab_and_line *); | |
145 | ||
4a64f543 MS |
146 | /* This function is used in gdbtk sources and thus can not be made |
147 | static. */ | |
63c252f8 | 148 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 149 | struct symtab_and_line, |
c0a91b2b TT |
150 | enum bptype, |
151 | const struct breakpoint_ops *); | |
c906108c | 152 | |
06edf0c0 PA |
153 | static struct breakpoint * |
154 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
155 | enum bptype type, | |
a1aa2221 LM |
156 | const struct breakpoint_ops *ops, |
157 | int loc_enabled); | |
06edf0c0 | 158 | |
76897487 KB |
159 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
160 | ||
a6d9a66e UW |
161 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
162 | CORE_ADDR bpaddr, | |
88f7da05 | 163 | enum bptype bptype); |
76897487 | 164 | |
6c95b8df PA |
165 | static void describe_other_breakpoints (struct gdbarch *, |
166 | struct program_space *, CORE_ADDR, | |
5af949e3 | 167 | struct obj_section *, int); |
c906108c | 168 | |
85d721b8 PA |
169 | static int watchpoint_locations_match (struct bp_location *loc1, |
170 | struct bp_location *loc2); | |
171 | ||
f1310107 TJB |
172 | static int breakpoint_location_address_match (struct bp_location *bl, |
173 | struct address_space *aspace, | |
174 | CORE_ADDR addr); | |
175 | ||
d35ae833 PA |
176 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
177 | struct address_space *, | |
178 | CORE_ADDR, int); | |
179 | ||
a14ed312 | 180 | static void breakpoints_info (char *, int); |
c906108c | 181 | |
d77f58be SS |
182 | static void watchpoints_info (char *, int); |
183 | ||
e5a67952 MS |
184 | static int breakpoint_1 (char *, int, |
185 | int (*) (const struct breakpoint *)); | |
c906108c | 186 | |
4efb68b1 | 187 | static int breakpoint_cond_eval (void *); |
c906108c | 188 | |
4efb68b1 | 189 | static void cleanup_executing_breakpoints (void *); |
c906108c | 190 | |
a14ed312 | 191 | static void commands_command (char *, int); |
c906108c | 192 | |
a14ed312 | 193 | static void condition_command (char *, int); |
c906108c | 194 | |
c5aa993b JM |
195 | typedef enum |
196 | { | |
197 | mark_inserted, | |
198 | mark_uninserted | |
199 | } | |
200 | insertion_state_t; | |
c906108c | 201 | |
0bde7532 | 202 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 203 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 204 | |
e514a9d6 | 205 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 206 | |
4efb68b1 | 207 | static int watchpoint_check (void *); |
c906108c | 208 | |
a14ed312 | 209 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 210 | |
a14ed312 | 211 | static int hw_breakpoint_used_count (void); |
c906108c | 212 | |
a1398e0c PA |
213 | static int hw_watchpoint_use_count (struct breakpoint *); |
214 | ||
215 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
216 | enum bptype type, | |
217 | int *other_type_used); | |
c906108c | 218 | |
a14ed312 | 219 | static void hbreak_command (char *, int); |
c906108c | 220 | |
a14ed312 | 221 | static void thbreak_command (char *, int); |
c906108c | 222 | |
816338b5 SS |
223 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
224 | int count); | |
c906108c | 225 | |
a14ed312 | 226 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 227 | |
a14ed312 | 228 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 231 | |
a14ed312 | 232 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 233 | |
fe3f5fa8 | 234 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
235 | static void incref_bp_location (struct bp_location *loc); |
236 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 237 | |
39d61571 | 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 239 | |
44702360 PA |
240 | /* update_global_location_list's modes of operation wrt to whether to |
241 | insert locations now. */ | |
242 | enum ugll_insert_mode | |
243 | { | |
244 | /* Don't insert any breakpoint locations into the inferior, only | |
245 | remove already-inserted locations that no longer should be | |
246 | inserted. Functions that delete a breakpoint or breakpoints | |
247 | should specify this mode, so that deleting a breakpoint doesn't | |
248 | have the side effect of inserting the locations of other | |
249 | breakpoints that are marked not-inserted, but should_be_inserted | |
250 | returns true on them. | |
251 | ||
252 | This behavior is useful is situations close to tear-down -- e.g., | |
253 | after an exec, while the target still has execution, but | |
254 | breakpoint shadows of the previous executable image should *NOT* | |
255 | be restored to the new image; or before detaching, where the | |
256 | target still has execution and wants to delete breakpoints from | |
257 | GDB's lists, and all breakpoints had already been removed from | |
258 | the inferior. */ | |
259 | UGLL_DONT_INSERT, | |
260 | ||
a25a5a45 PA |
261 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
262 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
263 | UGLL_MAY_INSERT, |
264 | ||
a25a5a45 PA |
265 | /* Insert locations now, irrespective of |
266 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
267 | stopped right now, and the user did "continue". We need to | |
268 | insert breakpoints _before_ resuming the target, but | |
269 | UGLL_MAY_INSERT wouldn't insert them, because | |
270 | breakpoints_should_be_inserted_now returns false at that point, | |
271 | as no thread is running yet. */ | |
04086b45 | 272 | UGLL_INSERT |
44702360 PA |
273 | }; |
274 | ||
275 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 276 | |
44702360 | 277 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 278 | |
d77f58be | 279 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
280 | |
281 | static void insert_breakpoint_locations (void); | |
a5606eee | 282 | |
1042e4c0 SS |
283 | static void tracepoints_info (char *, int); |
284 | ||
285 | static void delete_trace_command (char *, int); | |
286 | ||
287 | static void enable_trace_command (char *, int); | |
288 | ||
289 | static void disable_trace_command (char *, int); | |
290 | ||
291 | static void trace_pass_command (char *, int); | |
292 | ||
558a9d82 YQ |
293 | static void set_tracepoint_count (int num); |
294 | ||
9c06b0b4 TJB |
295 | static int is_masked_watchpoint (const struct breakpoint *b); |
296 | ||
b775012e LM |
297 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
298 | ||
983af33b SDJ |
299 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
300 | otherwise. */ | |
301 | ||
302 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 303 | |
2060206e PA |
304 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
305 | that are implemented on top of software or hardware breakpoints | |
306 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
307 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
308 | ||
309 | /* Internal breakpoints class type. */ | |
06edf0c0 | 310 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
311 | |
312 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
313 | static struct breakpoint_ops momentary_breakpoint_ops; |
314 | ||
e2e4d78b JK |
315 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
316 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
317 | ||
2060206e PA |
318 | /* The breakpoint_ops structure to be used in regular user created |
319 | breakpoints. */ | |
320 | struct breakpoint_ops bkpt_breakpoint_ops; | |
321 | ||
55aa24fb SDJ |
322 | /* Breakpoints set on probes. */ |
323 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
324 | ||
e7e0cddf | 325 | /* Dynamic printf class type. */ |
c5867ab6 | 326 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 327 | |
d3ce09f5 SS |
328 | /* The style in which to perform a dynamic printf. This is a user |
329 | option because different output options have different tradeoffs; | |
330 | if GDB does the printing, there is better error handling if there | |
331 | is a problem with any of the arguments, but using an inferior | |
332 | function lets you have special-purpose printers and sending of | |
333 | output to the same place as compiled-in print functions. */ | |
334 | ||
335 | static const char dprintf_style_gdb[] = "gdb"; | |
336 | static const char dprintf_style_call[] = "call"; | |
337 | static const char dprintf_style_agent[] = "agent"; | |
338 | static const char *const dprintf_style_enums[] = { | |
339 | dprintf_style_gdb, | |
340 | dprintf_style_call, | |
341 | dprintf_style_agent, | |
342 | NULL | |
343 | }; | |
344 | static const char *dprintf_style = dprintf_style_gdb; | |
345 | ||
346 | /* The function to use for dynamic printf if the preferred style is to | |
347 | call into the inferior. The value is simply a string that is | |
348 | copied into the command, so it can be anything that GDB can | |
349 | evaluate to a callable address, not necessarily a function name. */ | |
350 | ||
351 | static char *dprintf_function = ""; | |
352 | ||
353 | /* The channel to use for dynamic printf if the preferred style is to | |
354 | call into the inferior; if a nonempty string, it will be passed to | |
355 | the call as the first argument, with the format string as the | |
356 | second. As with the dprintf function, this can be anything that | |
357 | GDB knows how to evaluate, so in addition to common choices like | |
358 | "stderr", this could be an app-specific expression like | |
359 | "mystreams[curlogger]". */ | |
360 | ||
361 | static char *dprintf_channel = ""; | |
362 | ||
363 | /* True if dprintf commands should continue to operate even if GDB | |
364 | has disconnected. */ | |
365 | static int disconnected_dprintf = 1; | |
366 | ||
5cea2a26 PA |
367 | /* A reference-counted struct command_line. This lets multiple |
368 | breakpoints share a single command list. */ | |
369 | struct counted_command_line | |
370 | { | |
371 | /* The reference count. */ | |
372 | int refc; | |
373 | ||
374 | /* The command list. */ | |
375 | struct command_line *commands; | |
376 | }; | |
377 | ||
378 | struct command_line * | |
379 | breakpoint_commands (struct breakpoint *b) | |
380 | { | |
381 | return b->commands ? b->commands->commands : NULL; | |
382 | } | |
3daf8fe5 | 383 | |
f3b1572e PA |
384 | /* Flag indicating that a command has proceeded the inferior past the |
385 | current breakpoint. */ | |
386 | ||
387 | static int breakpoint_proceeded; | |
388 | ||
956a9fb9 | 389 | const char * |
2cec12e5 AR |
390 | bpdisp_text (enum bpdisp disp) |
391 | { | |
4a64f543 MS |
392 | /* NOTE: the following values are a part of MI protocol and |
393 | represent values of 'disp' field returned when inferior stops at | |
394 | a breakpoint. */ | |
bc043ef3 | 395 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 396 | |
2cec12e5 AR |
397 | return bpdisps[(int) disp]; |
398 | } | |
c906108c | 399 | |
4a64f543 | 400 | /* Prototypes for exported functions. */ |
c906108c | 401 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 402 | if such is available. */ |
c906108c SS |
403 | static int can_use_hw_watchpoints; |
404 | ||
920d2a44 AC |
405 | static void |
406 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
407 | struct cmd_list_element *c, | |
408 | const char *value) | |
409 | { | |
3e43a32a MS |
410 | fprintf_filtered (file, |
411 | _("Debugger's willingness to use " | |
412 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
413 | value); |
414 | } | |
415 | ||
fa8d40ab JJ |
416 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
417 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 418 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
419 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
420 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
421 | static void |
422 | show_pending_break_support (struct ui_file *file, int from_tty, | |
423 | struct cmd_list_element *c, | |
424 | const char *value) | |
425 | { | |
3e43a32a MS |
426 | fprintf_filtered (file, |
427 | _("Debugger's behavior regarding " | |
428 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
429 | value); |
430 | } | |
fa8d40ab | 431 | |
765dc015 | 432 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 433 | set with "break" but falling in read-only memory. |
765dc015 VP |
434 | If 0, gdb will warn about such breakpoints, but won't automatically |
435 | use hardware breakpoints. */ | |
436 | static int automatic_hardware_breakpoints; | |
437 | static void | |
438 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
439 | struct cmd_list_element *c, | |
440 | const char *value) | |
441 | { | |
3e43a32a MS |
442 | fprintf_filtered (file, |
443 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
444 | value); |
445 | } | |
446 | ||
a25a5a45 PA |
447 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
448 | stopped, and immediately inserts any new breakpoints as soon as | |
449 | they're created. If off (default), GDB keeps breakpoints off of | |
450 | the target as long as possible. That is, it delays inserting | |
451 | breakpoints until the next resume, and removes them again when the | |
452 | target fully stops. This is a bit safer in case GDB crashes while | |
453 | processing user input. */ | |
454 | static int always_inserted_mode = 0; | |
72d0e2c5 | 455 | |
33e5cbd6 | 456 | static void |
74960c60 | 457 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 458 | struct cmd_list_element *c, const char *value) |
74960c60 | 459 | { |
a25a5a45 PA |
460 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
461 | value); | |
74960c60 VP |
462 | } |
463 | ||
b57bacec PA |
464 | /* See breakpoint.h. */ |
465 | ||
33e5cbd6 | 466 | int |
a25a5a45 | 467 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 468 | { |
a25a5a45 PA |
469 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
470 | { | |
471 | /* If breakpoints are global, they should be inserted even if no | |
472 | thread under gdb's control is running, or even if there are | |
473 | no threads under GDB's control yet. */ | |
474 | return 1; | |
475 | } | |
476 | else if (target_has_execution) | |
477 | { | |
372316f1 PA |
478 | struct thread_info *tp; |
479 | ||
a25a5a45 PA |
480 | if (always_inserted_mode) |
481 | { | |
482 | /* The user wants breakpoints inserted even if all threads | |
483 | are stopped. */ | |
484 | return 1; | |
485 | } | |
486 | ||
b57bacec PA |
487 | if (threads_are_executing ()) |
488 | return 1; | |
372316f1 PA |
489 | |
490 | /* Don't remove breakpoints yet if, even though all threads are | |
491 | stopped, we still have events to process. */ | |
492 | ALL_NON_EXITED_THREADS (tp) | |
493 | if (tp->resumed | |
494 | && tp->suspend.waitstatus_pending_p) | |
495 | return 1; | |
a25a5a45 PA |
496 | } |
497 | return 0; | |
33e5cbd6 | 498 | } |
765dc015 | 499 | |
b775012e LM |
500 | static const char condition_evaluation_both[] = "host or target"; |
501 | ||
502 | /* Modes for breakpoint condition evaluation. */ | |
503 | static const char condition_evaluation_auto[] = "auto"; | |
504 | static const char condition_evaluation_host[] = "host"; | |
505 | static const char condition_evaluation_target[] = "target"; | |
506 | static const char *const condition_evaluation_enums[] = { | |
507 | condition_evaluation_auto, | |
508 | condition_evaluation_host, | |
509 | condition_evaluation_target, | |
510 | NULL | |
511 | }; | |
512 | ||
513 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
514 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
515 | ||
516 | /* Global that we use to display information to the user (gets its value from | |
517 | condition_evaluation_mode_1. */ | |
518 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
519 | ||
520 | /* Translate a condition evaluation mode MODE into either "host" | |
521 | or "target". This is used mostly to translate from "auto" to the | |
522 | real setting that is being used. It returns the translated | |
523 | evaluation mode. */ | |
524 | ||
525 | static const char * | |
526 | translate_condition_evaluation_mode (const char *mode) | |
527 | { | |
528 | if (mode == condition_evaluation_auto) | |
529 | { | |
530 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
531 | return condition_evaluation_target; | |
532 | else | |
533 | return condition_evaluation_host; | |
534 | } | |
535 | else | |
536 | return mode; | |
537 | } | |
538 | ||
539 | /* Discovers what condition_evaluation_auto translates to. */ | |
540 | ||
541 | static const char * | |
542 | breakpoint_condition_evaluation_mode (void) | |
543 | { | |
544 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
545 | } | |
546 | ||
547 | /* Return true if GDB should evaluate breakpoint conditions or false | |
548 | otherwise. */ | |
549 | ||
550 | static int | |
551 | gdb_evaluates_breakpoint_condition_p (void) | |
552 | { | |
553 | const char *mode = breakpoint_condition_evaluation_mode (); | |
554 | ||
555 | return (mode == condition_evaluation_host); | |
556 | } | |
557 | ||
a14ed312 | 558 | void _initialize_breakpoint (void); |
c906108c | 559 | |
c906108c SS |
560 | /* Are we executing breakpoint commands? */ |
561 | static int executing_breakpoint_commands; | |
562 | ||
c02f5703 MS |
563 | /* Are overlay event breakpoints enabled? */ |
564 | static int overlay_events_enabled; | |
565 | ||
e09342b5 TJB |
566 | /* See description in breakpoint.h. */ |
567 | int target_exact_watchpoints = 0; | |
568 | ||
c906108c | 569 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 570 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 571 | current breakpoint. */ |
c906108c | 572 | |
5c44784c | 573 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 574 | |
5c44784c JM |
575 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
576 | for (B = breakpoint_chain; \ | |
577 | B ? (TMP=B->next, 1): 0; \ | |
578 | B = TMP) | |
c906108c | 579 | |
4a64f543 MS |
580 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
581 | not provided so update_global_location_list must not be called | |
582 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 583 | |
876fa593 JK |
584 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
585 | for (BP_TMP = bp_location; \ | |
586 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
587 | BP_TMP++) | |
7cc221ef | 588 | |
b775012e LM |
589 | /* Iterates through locations with address ADDRESS for the currently selected |
590 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
591 | to where the loop should start from. | |
592 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
593 | appropriate location to start with. */ | |
594 | ||
595 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
596 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
597 | BP_LOCP_TMP = BP_LOCP_START; \ | |
598 | BP_LOCP_START \ | |
599 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
600 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
601 | BP_LOCP_TMP++) | |
602 | ||
1042e4c0 SS |
603 | /* Iterator for tracepoints only. */ |
604 | ||
605 | #define ALL_TRACEPOINTS(B) \ | |
606 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 607 | if (is_tracepoint (B)) |
1042e4c0 | 608 | |
7cc221ef | 609 | /* Chains of all breakpoints defined. */ |
c906108c SS |
610 | |
611 | struct breakpoint *breakpoint_chain; | |
612 | ||
876fa593 JK |
613 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
614 | ||
615 | static struct bp_location **bp_location; | |
616 | ||
617 | /* Number of elements of BP_LOCATION. */ | |
618 | ||
619 | static unsigned bp_location_count; | |
620 | ||
4a64f543 MS |
621 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
622 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
623 | result from bp_location_has_shadow. You can use it for roughly | |
624 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
625 | an address you need to read. */ | |
876fa593 JK |
626 | |
627 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
628 | ||
4a64f543 MS |
629 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
630 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
631 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
632 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
633 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
634 | |
635 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 636 | |
4a64f543 MS |
637 | /* The locations that no longer correspond to any breakpoint, unlinked |
638 | from bp_location array, but for which a hit may still be reported | |
639 | by a target. */ | |
20874c92 VP |
640 | VEC(bp_location_p) *moribund_locations = NULL; |
641 | ||
c906108c SS |
642 | /* Number of last breakpoint made. */ |
643 | ||
95a42b64 TT |
644 | static int breakpoint_count; |
645 | ||
86b17b60 PA |
646 | /* The value of `breakpoint_count' before the last command that |
647 | created breakpoints. If the last (break-like) command created more | |
648 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
649 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
650 | static int prev_breakpoint_count; | |
c906108c | 651 | |
1042e4c0 SS |
652 | /* Number of last tracepoint made. */ |
653 | ||
95a42b64 | 654 | static int tracepoint_count; |
1042e4c0 | 655 | |
6149aea9 PA |
656 | static struct cmd_list_element *breakpoint_set_cmdlist; |
657 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 658 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 659 | |
badd37ce SDJ |
660 | /* See declaration at breakpoint.h. */ |
661 | ||
662 | struct breakpoint * | |
663 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
664 | void *user_data) | |
665 | { | |
666 | struct breakpoint *b = NULL; | |
667 | ||
668 | ALL_BREAKPOINTS (b) | |
669 | { | |
670 | if (func (b, user_data) != 0) | |
671 | break; | |
672 | } | |
673 | ||
674 | return b; | |
675 | } | |
676 | ||
468d015d JJ |
677 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
678 | static int | |
679 | breakpoint_enabled (struct breakpoint *b) | |
680 | { | |
0d381245 | 681 | return (b->enable_state == bp_enabled); |
468d015d JJ |
682 | } |
683 | ||
c906108c SS |
684 | /* Set breakpoint count to NUM. */ |
685 | ||
95a42b64 | 686 | static void |
fba45db2 | 687 | set_breakpoint_count (int num) |
c906108c | 688 | { |
86b17b60 | 689 | prev_breakpoint_count = breakpoint_count; |
c906108c | 690 | breakpoint_count = num; |
4fa62494 | 691 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
692 | } |
693 | ||
86b17b60 PA |
694 | /* Used by `start_rbreak_breakpoints' below, to record the current |
695 | breakpoint count before "rbreak" creates any breakpoint. */ | |
696 | static int rbreak_start_breakpoint_count; | |
697 | ||
95a42b64 TT |
698 | /* Called at the start an "rbreak" command to record the first |
699 | breakpoint made. */ | |
86b17b60 | 700 | |
95a42b64 TT |
701 | void |
702 | start_rbreak_breakpoints (void) | |
703 | { | |
86b17b60 | 704 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
705 | } |
706 | ||
707 | /* Called at the end of an "rbreak" command to record the last | |
708 | breakpoint made. */ | |
86b17b60 | 709 | |
95a42b64 TT |
710 | void |
711 | end_rbreak_breakpoints (void) | |
712 | { | |
86b17b60 | 713 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
714 | } |
715 | ||
4a64f543 | 716 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
717 | |
718 | void | |
fba45db2 | 719 | clear_breakpoint_hit_counts (void) |
c906108c SS |
720 | { |
721 | struct breakpoint *b; | |
722 | ||
723 | ALL_BREAKPOINTS (b) | |
724 | b->hit_count = 0; | |
725 | } | |
726 | ||
9add0f1b TT |
727 | /* Allocate a new counted_command_line with reference count of 1. |
728 | The new structure owns COMMANDS. */ | |
729 | ||
730 | static struct counted_command_line * | |
731 | alloc_counted_command_line (struct command_line *commands) | |
732 | { | |
8d749320 | 733 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 734 | |
9add0f1b TT |
735 | result->refc = 1; |
736 | result->commands = commands; | |
8d749320 | 737 | |
9add0f1b TT |
738 | return result; |
739 | } | |
740 | ||
741 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
742 | ||
743 | static void | |
744 | incref_counted_command_line (struct counted_command_line *cmd) | |
745 | { | |
746 | if (cmd) | |
747 | ++cmd->refc; | |
748 | } | |
749 | ||
750 | /* Decrement reference count. If the reference count reaches 0, | |
751 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
752 | nothing if *CMDP is NULL. */ | |
753 | ||
754 | static void | |
755 | decref_counted_command_line (struct counted_command_line **cmdp) | |
756 | { | |
757 | if (*cmdp) | |
758 | { | |
759 | if (--(*cmdp)->refc == 0) | |
760 | { | |
761 | free_command_lines (&(*cmdp)->commands); | |
762 | xfree (*cmdp); | |
763 | } | |
764 | *cmdp = NULL; | |
765 | } | |
766 | } | |
767 | ||
768 | /* A cleanup function that calls decref_counted_command_line. */ | |
769 | ||
770 | static void | |
771 | do_cleanup_counted_command_line (void *arg) | |
772 | { | |
9a3c8263 | 773 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
774 | } |
775 | ||
776 | /* Create a cleanup that calls decref_counted_command_line on the | |
777 | argument. */ | |
778 | ||
779 | static struct cleanup * | |
780 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
781 | { | |
782 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
783 | } | |
784 | ||
c906108c | 785 | \f |
48cb2d85 VP |
786 | /* Return the breakpoint with the specified number, or NULL |
787 | if the number does not refer to an existing breakpoint. */ | |
788 | ||
789 | struct breakpoint * | |
790 | get_breakpoint (int num) | |
791 | { | |
792 | struct breakpoint *b; | |
793 | ||
794 | ALL_BREAKPOINTS (b) | |
795 | if (b->number == num) | |
796 | return b; | |
797 | ||
798 | return NULL; | |
799 | } | |
5c44784c | 800 | |
c906108c | 801 | \f |
adc36818 | 802 | |
b775012e LM |
803 | /* Mark locations as "conditions have changed" in case the target supports |
804 | evaluating conditions on its side. */ | |
805 | ||
806 | static void | |
807 | mark_breakpoint_modified (struct breakpoint *b) | |
808 | { | |
809 | struct bp_location *loc; | |
810 | ||
811 | /* This is only meaningful if the target is | |
812 | evaluating conditions and if the user has | |
813 | opted for condition evaluation on the target's | |
814 | side. */ | |
815 | if (gdb_evaluates_breakpoint_condition_p () | |
816 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
817 | return; | |
818 | ||
819 | if (!is_breakpoint (b)) | |
820 | return; | |
821 | ||
822 | for (loc = b->loc; loc; loc = loc->next) | |
823 | loc->condition_changed = condition_modified; | |
824 | } | |
825 | ||
826 | /* Mark location as "conditions have changed" in case the target supports | |
827 | evaluating conditions on its side. */ | |
828 | ||
829 | static void | |
830 | mark_breakpoint_location_modified (struct bp_location *loc) | |
831 | { | |
832 | /* This is only meaningful if the target is | |
833 | evaluating conditions and if the user has | |
834 | opted for condition evaluation on the target's | |
835 | side. */ | |
836 | if (gdb_evaluates_breakpoint_condition_p () | |
837 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
838 | ||
839 | return; | |
840 | ||
841 | if (!is_breakpoint (loc->owner)) | |
842 | return; | |
843 | ||
844 | loc->condition_changed = condition_modified; | |
845 | } | |
846 | ||
847 | /* Sets the condition-evaluation mode using the static global | |
848 | condition_evaluation_mode. */ | |
849 | ||
850 | static void | |
851 | set_condition_evaluation_mode (char *args, int from_tty, | |
852 | struct cmd_list_element *c) | |
853 | { | |
b775012e LM |
854 | const char *old_mode, *new_mode; |
855 | ||
856 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
857 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
858 | { | |
859 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
860 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
861 | "Using host evaluation mode instead.")); | |
862 | return; | |
863 | } | |
864 | ||
865 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
866 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
867 | ||
abf1152a JK |
868 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
869 | settings was "auto". */ | |
870 | condition_evaluation_mode = condition_evaluation_mode_1; | |
871 | ||
b775012e LM |
872 | /* Only update the mode if the user picked a different one. */ |
873 | if (new_mode != old_mode) | |
874 | { | |
875 | struct bp_location *loc, **loc_tmp; | |
876 | /* If the user switched to a different evaluation mode, we | |
877 | need to synch the changes with the target as follows: | |
878 | ||
879 | "host" -> "target": Send all (valid) conditions to the target. | |
880 | "target" -> "host": Remove all the conditions from the target. | |
881 | */ | |
882 | ||
b775012e LM |
883 | if (new_mode == condition_evaluation_target) |
884 | { | |
885 | /* Mark everything modified and synch conditions with the | |
886 | target. */ | |
887 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
888 | mark_breakpoint_location_modified (loc); | |
889 | } | |
890 | else | |
891 | { | |
892 | /* Manually mark non-duplicate locations to synch conditions | |
893 | with the target. We do this to remove all the conditions the | |
894 | target knows about. */ | |
895 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
896 | if (is_breakpoint (loc->owner) && loc->inserted) | |
897 | loc->needs_update = 1; | |
898 | } | |
899 | ||
900 | /* Do the update. */ | |
44702360 | 901 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
902 | } |
903 | ||
904 | return; | |
905 | } | |
906 | ||
907 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
908 | what "auto" is translating to. */ | |
909 | ||
910 | static void | |
911 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
912 | struct cmd_list_element *c, const char *value) | |
913 | { | |
914 | if (condition_evaluation_mode == condition_evaluation_auto) | |
915 | fprintf_filtered (file, | |
916 | _("Breakpoint condition evaluation " | |
917 | "mode is %s (currently %s).\n"), | |
918 | value, | |
919 | breakpoint_condition_evaluation_mode ()); | |
920 | else | |
921 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
922 | value); | |
923 | } | |
924 | ||
925 | /* A comparison function for bp_location AP and BP that is used by | |
926 | bsearch. This comparison function only cares about addresses, unlike | |
927 | the more general bp_location_compare function. */ | |
928 | ||
929 | static int | |
930 | bp_location_compare_addrs (const void *ap, const void *bp) | |
931 | { | |
9a3c8263 SM |
932 | const struct bp_location *a = *(const struct bp_location **) ap; |
933 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
934 | |
935 | if (a->address == b->address) | |
936 | return 0; | |
937 | else | |
938 | return ((a->address > b->address) - (a->address < b->address)); | |
939 | } | |
940 | ||
941 | /* Helper function to skip all bp_locations with addresses | |
942 | less than ADDRESS. It returns the first bp_location that | |
943 | is greater than or equal to ADDRESS. If none is found, just | |
944 | return NULL. */ | |
945 | ||
946 | static struct bp_location ** | |
947 | get_first_locp_gte_addr (CORE_ADDR address) | |
948 | { | |
949 | struct bp_location dummy_loc; | |
950 | struct bp_location *dummy_locp = &dummy_loc; | |
951 | struct bp_location **locp_found = NULL; | |
952 | ||
953 | /* Initialize the dummy location's address field. */ | |
954 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
955 | dummy_loc.address = address; | |
956 | ||
957 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 SM |
958 | locp_found = ((struct bp_location **) |
959 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
960 | sizeof (struct bp_location **), | |
961 | bp_location_compare_addrs)); | |
b775012e LM |
962 | |
963 | /* Nothing was found, nothing left to do. */ | |
964 | if (locp_found == NULL) | |
965 | return NULL; | |
966 | ||
967 | /* We may have found a location that is at ADDRESS but is not the first in the | |
968 | location's list. Go backwards (if possible) and locate the first one. */ | |
969 | while ((locp_found - 1) >= bp_location | |
970 | && (*(locp_found - 1))->address == address) | |
971 | locp_found--; | |
972 | ||
973 | return locp_found; | |
974 | } | |
975 | ||
adc36818 | 976 | void |
7a26bd4d | 977 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
978 | int from_tty) |
979 | { | |
3a5c3e22 PA |
980 | xfree (b->cond_string); |
981 | b->cond_string = NULL; | |
adc36818 | 982 | |
3a5c3e22 | 983 | if (is_watchpoint (b)) |
adc36818 | 984 | { |
3a5c3e22 PA |
985 | struct watchpoint *w = (struct watchpoint *) b; |
986 | ||
987 | xfree (w->cond_exp); | |
988 | w->cond_exp = NULL; | |
989 | } | |
990 | else | |
991 | { | |
992 | struct bp_location *loc; | |
993 | ||
994 | for (loc = b->loc; loc; loc = loc->next) | |
995 | { | |
996 | xfree (loc->cond); | |
997 | loc->cond = NULL; | |
b775012e LM |
998 | |
999 | /* No need to free the condition agent expression | |
1000 | bytecode (if we have one). We will handle this | |
1001 | when we go through update_global_location_list. */ | |
3a5c3e22 | 1002 | } |
adc36818 | 1003 | } |
adc36818 PM |
1004 | |
1005 | if (*exp == 0) | |
1006 | { | |
1007 | if (from_tty) | |
1008 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1009 | } | |
1010 | else | |
1011 | { | |
bbc13ae3 | 1012 | const char *arg = exp; |
cc59ec59 | 1013 | |
adc36818 PM |
1014 | /* I don't know if it matters whether this is the string the user |
1015 | typed in or the decompiled expression. */ | |
1016 | b->cond_string = xstrdup (arg); | |
1017 | b->condition_not_parsed = 0; | |
1018 | ||
1019 | if (is_watchpoint (b)) | |
1020 | { | |
3a5c3e22 PA |
1021 | struct watchpoint *w = (struct watchpoint *) b; |
1022 | ||
adc36818 PM |
1023 | innermost_block = NULL; |
1024 | arg = exp; | |
1bb9788d | 1025 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1026 | if (*arg) |
1027 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1028 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1029 | } |
1030 | else | |
1031 | { | |
3a5c3e22 PA |
1032 | struct bp_location *loc; |
1033 | ||
adc36818 PM |
1034 | for (loc = b->loc; loc; loc = loc->next) |
1035 | { | |
1036 | arg = exp; | |
1037 | loc->cond = | |
1bb9788d TT |
1038 | parse_exp_1 (&arg, loc->address, |
1039 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1040 | if (*arg) |
1041 | error (_("Junk at end of expression")); | |
1042 | } | |
1043 | } | |
1044 | } | |
b775012e LM |
1045 | mark_breakpoint_modified (b); |
1046 | ||
8d3788bd | 1047 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1048 | } |
1049 | ||
d55637df TT |
1050 | /* Completion for the "condition" command. */ |
1051 | ||
1052 | static VEC (char_ptr) * | |
6f937416 PA |
1053 | condition_completer (struct cmd_list_element *cmd, |
1054 | const char *text, const char *word) | |
d55637df | 1055 | { |
6f937416 | 1056 | const char *space; |
d55637df | 1057 | |
6f937416 PA |
1058 | text = skip_spaces_const (text); |
1059 | space = skip_to_space_const (text); | |
d55637df TT |
1060 | if (*space == '\0') |
1061 | { | |
1062 | int len; | |
1063 | struct breakpoint *b; | |
1064 | VEC (char_ptr) *result = NULL; | |
1065 | ||
1066 | if (text[0] == '$') | |
1067 | { | |
1068 | /* We don't support completion of history indices. */ | |
1069 | if (isdigit (text[1])) | |
1070 | return NULL; | |
1071 | return complete_internalvar (&text[1]); | |
1072 | } | |
1073 | ||
1074 | /* We're completing the breakpoint number. */ | |
1075 | len = strlen (text); | |
1076 | ||
1077 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1078 | { |
1079 | char number[50]; | |
1080 | ||
1081 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1082 | ||
1083 | if (strncmp (number, text, len) == 0) | |
1084 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1085 | } | |
d55637df TT |
1086 | |
1087 | return result; | |
1088 | } | |
1089 | ||
1090 | /* We're completing the expression part. */ | |
6f937416 | 1091 | text = skip_spaces_const (space); |
d55637df TT |
1092 | return expression_completer (cmd, text, word); |
1093 | } | |
1094 | ||
c906108c SS |
1095 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1096 | ||
1097 | static void | |
fba45db2 | 1098 | condition_command (char *arg, int from_tty) |
c906108c | 1099 | { |
52f0bd74 | 1100 | struct breakpoint *b; |
c906108c | 1101 | char *p; |
52f0bd74 | 1102 | int bnum; |
c906108c SS |
1103 | |
1104 | if (arg == 0) | |
e2e0b3e5 | 1105 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1106 | |
1107 | p = arg; | |
1108 | bnum = get_number (&p); | |
5c44784c | 1109 | if (bnum == 0) |
8a3fe4f8 | 1110 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1111 | |
1112 | ALL_BREAKPOINTS (b) | |
1113 | if (b->number == bnum) | |
2f069f6f | 1114 | { |
6dddc817 DE |
1115 | /* Check if this breakpoint has a "stop" method implemented in an |
1116 | extension language. This method and conditions entered into GDB | |
1117 | from the CLI are mutually exclusive. */ | |
1118 | const struct extension_language_defn *extlang | |
1119 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1120 | ||
1121 | if (extlang != NULL) | |
1122 | { | |
1123 | error (_("Only one stop condition allowed. There is currently" | |
1124 | " a %s stop condition defined for this breakpoint."), | |
1125 | ext_lang_capitalized_name (extlang)); | |
1126 | } | |
2566ad2d | 1127 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1128 | |
1129 | if (is_breakpoint (b)) | |
44702360 | 1130 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1131 | |
2f069f6f JB |
1132 | return; |
1133 | } | |
c906108c | 1134 | |
8a3fe4f8 | 1135 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1136 | } |
1137 | ||
a7bdde9e VP |
1138 | /* Check that COMMAND do not contain commands that are suitable |
1139 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1140 | Throw if any such commands is found. */ |
1141 | ||
a7bdde9e VP |
1142 | static void |
1143 | check_no_tracepoint_commands (struct command_line *commands) | |
1144 | { | |
1145 | struct command_line *c; | |
cc59ec59 | 1146 | |
a7bdde9e VP |
1147 | for (c = commands; c; c = c->next) |
1148 | { | |
1149 | int i; | |
1150 | ||
1151 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1152 | error (_("The 'while-stepping' command can " |
1153 | "only be used for tracepoints")); | |
a7bdde9e VP |
1154 | |
1155 | for (i = 0; i < c->body_count; ++i) | |
1156 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1157 | ||
1158 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1159 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1160 | command directly. */ |
1161 | if (strstr (c->line, "collect ") == c->line) | |
1162 | error (_("The 'collect' command can only be used for tracepoints")); | |
1163 | ||
51661e93 VP |
1164 | if (strstr (c->line, "teval ") == c->line) |
1165 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1166 | } |
1167 | } | |
1168 | ||
d77f58be SS |
1169 | /* Encapsulate tests for different types of tracepoints. */ |
1170 | ||
d9b3f62e PA |
1171 | static int |
1172 | is_tracepoint_type (enum bptype type) | |
1173 | { | |
1174 | return (type == bp_tracepoint | |
1175 | || type == bp_fast_tracepoint | |
1176 | || type == bp_static_tracepoint); | |
1177 | } | |
1178 | ||
a7bdde9e | 1179 | int |
d77f58be | 1180 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1181 | { |
d9b3f62e | 1182 | return is_tracepoint_type (b->type); |
a7bdde9e | 1183 | } |
d9b3f62e | 1184 | |
e5dd4106 | 1185 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1186 | breakpoint. This function will throw an exception if a problem is |
1187 | found. */ | |
48cb2d85 | 1188 | |
95a42b64 TT |
1189 | static void |
1190 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1191 | struct command_line *commands) | |
48cb2d85 | 1192 | { |
d77f58be | 1193 | if (is_tracepoint (b)) |
a7bdde9e | 1194 | { |
c9a6ce02 | 1195 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1196 | struct command_line *c; |
1197 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1198 | |
1199 | /* Reset the while-stepping step count. The previous commands | |
1200 | might have included a while-stepping action, while the new | |
1201 | ones might not. */ | |
1202 | t->step_count = 0; | |
1203 | ||
1204 | /* We need to verify that each top-level element of commands is | |
1205 | valid for tracepoints, that there's at most one | |
1206 | while-stepping element, and that the while-stepping's body | |
1207 | has valid tracing commands excluding nested while-stepping. | |
1208 | We also need to validate the tracepoint action line in the | |
1209 | context of the tracepoint --- validate_actionline actually | |
1210 | has side effects, like setting the tracepoint's | |
1211 | while-stepping STEP_COUNT, in addition to checking if the | |
1212 | collect/teval actions parse and make sense in the | |
1213 | tracepoint's context. */ | |
a7bdde9e VP |
1214 | for (c = commands; c; c = c->next) |
1215 | { | |
a7bdde9e VP |
1216 | if (c->control_type == while_stepping_control) |
1217 | { | |
1218 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1219 | error (_("The 'while-stepping' command " |
1220 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1221 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1222 | error (_("The 'while-stepping' command " |
1223 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1224 | |
1225 | if (while_stepping) | |
3e43a32a MS |
1226 | error (_("The 'while-stepping' command " |
1227 | "can be used only once")); | |
a7bdde9e VP |
1228 | else |
1229 | while_stepping = c; | |
1230 | } | |
c9a6ce02 PA |
1231 | |
1232 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1233 | } |
1234 | if (while_stepping) | |
1235 | { | |
1236 | struct command_line *c2; | |
1237 | ||
1238 | gdb_assert (while_stepping->body_count == 1); | |
1239 | c2 = while_stepping->body_list[0]; | |
1240 | for (; c2; c2 = c2->next) | |
1241 | { | |
a7bdde9e VP |
1242 | if (c2->control_type == while_stepping_control) |
1243 | error (_("The 'while-stepping' command cannot be nested")); | |
1244 | } | |
1245 | } | |
1246 | } | |
1247 | else | |
1248 | { | |
1249 | check_no_tracepoint_commands (commands); | |
1250 | } | |
95a42b64 TT |
1251 | } |
1252 | ||
0fb4aa4b PA |
1253 | /* Return a vector of all the static tracepoints set at ADDR. The |
1254 | caller is responsible for releasing the vector. */ | |
1255 | ||
1256 | VEC(breakpoint_p) * | |
1257 | static_tracepoints_here (CORE_ADDR addr) | |
1258 | { | |
1259 | struct breakpoint *b; | |
1260 | VEC(breakpoint_p) *found = 0; | |
1261 | struct bp_location *loc; | |
1262 | ||
1263 | ALL_BREAKPOINTS (b) | |
1264 | if (b->type == bp_static_tracepoint) | |
1265 | { | |
1266 | for (loc = b->loc; loc; loc = loc->next) | |
1267 | if (loc->address == addr) | |
1268 | VEC_safe_push(breakpoint_p, found, b); | |
1269 | } | |
1270 | ||
1271 | return found; | |
1272 | } | |
1273 | ||
95a42b64 | 1274 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1275 | validate that only allowed commands are included. */ |
95a42b64 TT |
1276 | |
1277 | void | |
4a64f543 MS |
1278 | breakpoint_set_commands (struct breakpoint *b, |
1279 | struct command_line *commands) | |
95a42b64 TT |
1280 | { |
1281 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1282 | |
9add0f1b TT |
1283 | decref_counted_command_line (&b->commands); |
1284 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1285 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1286 | } |
1287 | ||
45a43567 TT |
1288 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1289 | is not the same as the "silent" that may appear in the breakpoint's | |
1290 | commands. */ | |
1291 | ||
1292 | void | |
1293 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1294 | { | |
1295 | int old_silent = b->silent; | |
1296 | ||
1297 | b->silent = silent; | |
1298 | if (old_silent != silent) | |
8d3788bd | 1299 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1300 | } |
1301 | ||
1302 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1303 | breakpoint work for any thread. */ | |
1304 | ||
1305 | void | |
1306 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1307 | { | |
1308 | int old_thread = b->thread; | |
1309 | ||
1310 | b->thread = thread; | |
1311 | if (old_thread != thread) | |
8d3788bd | 1312 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1313 | } |
1314 | ||
1315 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1316 | breakpoint work for any task. */ | |
1317 | ||
1318 | void | |
1319 | breakpoint_set_task (struct breakpoint *b, int task) | |
1320 | { | |
1321 | int old_task = b->task; | |
1322 | ||
1323 | b->task = task; | |
1324 | if (old_task != task) | |
8d3788bd | 1325 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1326 | } |
1327 | ||
95a42b64 TT |
1328 | void |
1329 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1330 | { |
9a3c8263 | 1331 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1332 | |
6f937416 | 1333 | validate_actionline (line, b); |
a7bdde9e VP |
1334 | } |
1335 | ||
95a42b64 TT |
1336 | /* A structure used to pass information through |
1337 | map_breakpoint_numbers. */ | |
1338 | ||
1339 | struct commands_info | |
1340 | { | |
1341 | /* True if the command was typed at a tty. */ | |
1342 | int from_tty; | |
86b17b60 PA |
1343 | |
1344 | /* The breakpoint range spec. */ | |
1345 | char *arg; | |
1346 | ||
95a42b64 TT |
1347 | /* Non-NULL if the body of the commands are being read from this |
1348 | already-parsed command. */ | |
1349 | struct command_line *control; | |
86b17b60 | 1350 | |
95a42b64 TT |
1351 | /* The command lines read from the user, or NULL if they have not |
1352 | yet been read. */ | |
1353 | struct counted_command_line *cmd; | |
1354 | }; | |
1355 | ||
1356 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1357 | commands_command. */ | |
1358 | ||
c906108c | 1359 | static void |
95a42b64 | 1360 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1361 | { |
9a3c8263 | 1362 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1363 | |
95a42b64 TT |
1364 | if (info->cmd == NULL) |
1365 | { | |
1366 | struct command_line *l; | |
5c44784c | 1367 | |
95a42b64 TT |
1368 | if (info->control != NULL) |
1369 | l = copy_command_lines (info->control->body_list[0]); | |
1370 | else | |
86b17b60 PA |
1371 | { |
1372 | struct cleanup *old_chain; | |
1373 | char *str; | |
c5aa993b | 1374 | |
3e43a32a MS |
1375 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1376 | "%s, one per line."), | |
86b17b60 PA |
1377 | info->arg); |
1378 | ||
1379 | old_chain = make_cleanup (xfree, str); | |
1380 | ||
1381 | l = read_command_lines (str, | |
1382 | info->from_tty, 1, | |
d77f58be | 1383 | (is_tracepoint (b) |
86b17b60 PA |
1384 | ? check_tracepoint_command : 0), |
1385 | b); | |
1386 | ||
1387 | do_cleanups (old_chain); | |
1388 | } | |
a7bdde9e | 1389 | |
95a42b64 TT |
1390 | info->cmd = alloc_counted_command_line (l); |
1391 | } | |
1392 | ||
1393 | /* If a breakpoint was on the list more than once, we don't need to | |
1394 | do anything. */ | |
1395 | if (b->commands != info->cmd) | |
1396 | { | |
1397 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1398 | incref_counted_command_line (info->cmd); | |
1399 | decref_counted_command_line (&b->commands); | |
1400 | b->commands = info->cmd; | |
8d3788bd | 1401 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1402 | } |
95a42b64 TT |
1403 | } |
1404 | ||
1405 | static void | |
4a64f543 MS |
1406 | commands_command_1 (char *arg, int from_tty, |
1407 | struct command_line *control) | |
95a42b64 TT |
1408 | { |
1409 | struct cleanup *cleanups; | |
1410 | struct commands_info info; | |
1411 | ||
1412 | info.from_tty = from_tty; | |
1413 | info.control = control; | |
1414 | info.cmd = NULL; | |
1415 | /* If we read command lines from the user, then `info' will hold an | |
1416 | extra reference to the commands that we must clean up. */ | |
1417 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1418 | ||
1419 | if (arg == NULL || !*arg) | |
1420 | { | |
86b17b60 | 1421 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1422 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1423 | breakpoint_count); | |
95a42b64 TT |
1424 | else if (breakpoint_count > 0) |
1425 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1426 | else |
1427 | { | |
1428 | /* So that we don't try to free the incoming non-NULL | |
1429 | argument in the cleanup below. Mapping breakpoint | |
1430 | numbers will fail in this case. */ | |
1431 | arg = NULL; | |
1432 | } | |
95a42b64 | 1433 | } |
9766ced4 SS |
1434 | else |
1435 | /* The command loop has some static state, so we need to preserve | |
1436 | our argument. */ | |
1437 | arg = xstrdup (arg); | |
86b17b60 PA |
1438 | |
1439 | if (arg != NULL) | |
1440 | make_cleanup (xfree, arg); | |
1441 | ||
1442 | info.arg = arg; | |
95a42b64 TT |
1443 | |
1444 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1445 | ||
1446 | if (info.cmd == NULL) | |
1447 | error (_("No breakpoints specified.")); | |
1448 | ||
1449 | do_cleanups (cleanups); | |
1450 | } | |
1451 | ||
1452 | static void | |
1453 | commands_command (char *arg, int from_tty) | |
1454 | { | |
1455 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1456 | } |
40c03ae8 EZ |
1457 | |
1458 | /* Like commands_command, but instead of reading the commands from | |
1459 | input stream, takes them from an already parsed command structure. | |
1460 | ||
1461 | This is used by cli-script.c to DTRT with breakpoint commands | |
1462 | that are part of if and while bodies. */ | |
1463 | enum command_control_type | |
1464 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1465 | { | |
95a42b64 TT |
1466 | commands_command_1 (arg, 0, cmd); |
1467 | return simple_control; | |
40c03ae8 | 1468 | } |
876fa593 JK |
1469 | |
1470 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1471 | ||
1472 | static int | |
1473 | bp_location_has_shadow (struct bp_location *bl) | |
1474 | { | |
1475 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1476 | return 0; | |
1477 | if (!bl->inserted) | |
1478 | return 0; | |
1479 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1480 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1481 | return 0; |
1482 | return 1; | |
1483 | } | |
1484 | ||
9d497a19 PA |
1485 | /* Update BUF, which is LEN bytes read from the target address |
1486 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1487 | contents. | |
1488 | ||
1489 | If READBUF is not NULL, this buffer must not overlap with the of | |
1490 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1491 | failed assertion internal error will be raised. */ | |
1492 | ||
1493 | static void | |
1494 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1495 | const gdb_byte *writebuf_org, | |
1496 | ULONGEST memaddr, LONGEST len, | |
1497 | struct bp_target_info *target_info, | |
1498 | struct gdbarch *gdbarch) | |
1499 | { | |
1500 | /* Now do full processing of the found relevant range of elements. */ | |
1501 | CORE_ADDR bp_addr = 0; | |
1502 | int bp_size = 0; | |
1503 | int bptoffset = 0; | |
1504 | ||
1505 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1506 | current_program_space->aspace, 0)) | |
1507 | { | |
1508 | /* The breakpoint is inserted in a different address space. */ | |
1509 | return; | |
1510 | } | |
1511 | ||
1512 | /* Addresses and length of the part of the breakpoint that | |
1513 | we need to copy. */ | |
1514 | bp_addr = target_info->placed_address; | |
1515 | bp_size = target_info->shadow_len; | |
1516 | ||
1517 | if (bp_addr + bp_size <= memaddr) | |
1518 | { | |
1519 | /* The breakpoint is entirely before the chunk of memory we are | |
1520 | reading. */ | |
1521 | return; | |
1522 | } | |
1523 | ||
1524 | if (bp_addr >= memaddr + len) | |
1525 | { | |
1526 | /* The breakpoint is entirely after the chunk of memory we are | |
1527 | reading. */ | |
1528 | return; | |
1529 | } | |
1530 | ||
1531 | /* Offset within shadow_contents. */ | |
1532 | if (bp_addr < memaddr) | |
1533 | { | |
1534 | /* Only copy the second part of the breakpoint. */ | |
1535 | bp_size -= memaddr - bp_addr; | |
1536 | bptoffset = memaddr - bp_addr; | |
1537 | bp_addr = memaddr; | |
1538 | } | |
1539 | ||
1540 | if (bp_addr + bp_size > memaddr + len) | |
1541 | { | |
1542 | /* Only copy the first part of the breakpoint. */ | |
1543 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1544 | } | |
1545 | ||
1546 | if (readbuf != NULL) | |
1547 | { | |
1548 | /* Verify that the readbuf buffer does not overlap with the | |
1549 | shadow_contents buffer. */ | |
1550 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1551 | || readbuf >= (target_info->shadow_contents | |
1552 | + target_info->shadow_len)); | |
1553 | ||
1554 | /* Update the read buffer with this inserted breakpoint's | |
1555 | shadow. */ | |
1556 | memcpy (readbuf + bp_addr - memaddr, | |
1557 | target_info->shadow_contents + bptoffset, bp_size); | |
1558 | } | |
1559 | else | |
1560 | { | |
1561 | const unsigned char *bp; | |
0d5ed153 MR |
1562 | CORE_ADDR addr = target_info->reqstd_address; |
1563 | int placed_size; | |
9d497a19 PA |
1564 | |
1565 | /* Update the shadow with what we want to write to memory. */ | |
1566 | memcpy (target_info->shadow_contents + bptoffset, | |
1567 | writebuf_org + bp_addr - memaddr, bp_size); | |
1568 | ||
1569 | /* Determine appropriate breakpoint contents and size for this | |
1570 | address. */ | |
0d5ed153 | 1571 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1572 | |
1573 | /* Update the final write buffer with this inserted | |
1574 | breakpoint's INSN. */ | |
1575 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1576 | } | |
1577 | } | |
1578 | ||
8defab1a | 1579 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1580 | by replacing any memory breakpoints with their shadowed contents. |
1581 | ||
35c63cd8 JB |
1582 | If READBUF is not NULL, this buffer must not overlap with any of |
1583 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1584 | a failed assertion internal error will be raised. | |
1585 | ||
876fa593 | 1586 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1587 | bl->address - bp_location_placed_address_before_address_max |
1588 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1589 | The range we were requested to resolve shadows for is: |
1590 | memaddr ... memaddr + len | |
1591 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1592 | memaddr + len <= (bl->address |
1593 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1594 | and: |
35df4500 | 1595 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1596 | |
8defab1a | 1597 | void |
f0ba3972 PA |
1598 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1599 | const gdb_byte *writebuf_org, | |
1600 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1601 | { |
4a64f543 MS |
1602 | /* Left boundary, right boundary and median element of our binary |
1603 | search. */ | |
876fa593 | 1604 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1605 | size_t i; |
876fa593 | 1606 | |
4a64f543 MS |
1607 | /* Find BC_L which is a leftmost element which may affect BUF |
1608 | content. It is safe to report lower value but a failure to | |
1609 | report higher one. */ | |
876fa593 JK |
1610 | |
1611 | bc_l = 0; | |
1612 | bc_r = bp_location_count; | |
1613 | while (bc_l + 1 < bc_r) | |
1614 | { | |
35df4500 | 1615 | struct bp_location *bl; |
876fa593 JK |
1616 | |
1617 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1618 | bl = bp_location[bc]; |
876fa593 | 1619 | |
4a64f543 MS |
1620 | /* Check first BL->ADDRESS will not overflow due to the added |
1621 | constant. Then advance the left boundary only if we are sure | |
1622 | the BC element can in no way affect the BUF content (MEMADDR | |
1623 | to MEMADDR + LEN range). | |
876fa593 | 1624 | |
4a64f543 MS |
1625 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1626 | offset so that we cannot miss a breakpoint with its shadow | |
1627 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1628 | |
35df4500 TJB |
1629 | if ((bl->address + bp_location_shadow_len_after_address_max |
1630 | >= bl->address) | |
1631 | && (bl->address + bp_location_shadow_len_after_address_max | |
1632 | <= memaddr)) | |
876fa593 JK |
1633 | bc_l = bc; |
1634 | else | |
1635 | bc_r = bc; | |
1636 | } | |
1637 | ||
128070bb PA |
1638 | /* Due to the binary search above, we need to make sure we pick the |
1639 | first location that's at BC_L's address. E.g., if there are | |
1640 | multiple locations at the same address, BC_L may end up pointing | |
1641 | at a duplicate location, and miss the "master"/"inserted" | |
1642 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1643 | B: | |
1644 | ||
1645 | L1@A, L2@A, L3@B, ... | |
1646 | ||
1647 | BC_L could end up pointing at location L2, while the "master" | |
1648 | location could be L1. Since the `loc->inserted' flag is only set | |
1649 | on "master" locations, we'd forget to restore the shadow of L1 | |
1650 | and L2. */ | |
1651 | while (bc_l > 0 | |
1652 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1653 | bc_l--; | |
1654 | ||
876fa593 JK |
1655 | /* Now do full processing of the found relevant range of elements. */ |
1656 | ||
1657 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1658 | { |
35df4500 | 1659 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1660 | CORE_ADDR bp_addr = 0; |
1661 | int bp_size = 0; | |
1662 | int bptoffset = 0; | |
1663 | ||
35df4500 TJB |
1664 | /* bp_location array has BL->OWNER always non-NULL. */ |
1665 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1666 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1667 | bl->owner->number); |
ffce0d52 | 1668 | |
e5dd4106 | 1669 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1670 | content. */ |
1671 | ||
35df4500 TJB |
1672 | if (bl->address >= bp_location_placed_address_before_address_max |
1673 | && memaddr + len <= (bl->address | |
1674 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1675 | break; |
1676 | ||
35df4500 | 1677 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1678 | continue; |
6c95b8df | 1679 | |
9d497a19 PA |
1680 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1681 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1682 | } | |
c906108c | 1683 | } |
9d497a19 | 1684 | |
c906108c | 1685 | \f |
c5aa993b | 1686 | |
b775012e LM |
1687 | /* Return true if BPT is either a software breakpoint or a hardware |
1688 | breakpoint. */ | |
1689 | ||
1690 | int | |
1691 | is_breakpoint (const struct breakpoint *bpt) | |
1692 | { | |
1693 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1694 | || bpt->type == bp_hardware_breakpoint |
1695 | || bpt->type == bp_dprintf); | |
b775012e LM |
1696 | } |
1697 | ||
60e1c644 PA |
1698 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1699 | ||
a5606eee | 1700 | static int |
d77f58be | 1701 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1702 | { |
1703 | return (bpt->type == bp_hardware_watchpoint | |
1704 | || bpt->type == bp_read_watchpoint | |
1705 | || bpt->type == bp_access_watchpoint); | |
1706 | } | |
7270d8f2 | 1707 | |
60e1c644 PA |
1708 | /* Return true if BPT is of any watchpoint kind, hardware or |
1709 | software. */ | |
1710 | ||
3a5c3e22 | 1711 | int |
d77f58be | 1712 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1713 | { |
1714 | return (is_hardware_watchpoint (bpt) | |
1715 | || bpt->type == bp_watchpoint); | |
1716 | } | |
1717 | ||
3a5c3e22 PA |
1718 | /* Returns true if the current thread and its running state are safe |
1719 | to evaluate or update watchpoint B. Watchpoints on local | |
1720 | expressions need to be evaluated in the context of the thread that | |
1721 | was current when the watchpoint was created, and, that thread needs | |
1722 | to be stopped to be able to select the correct frame context. | |
1723 | Watchpoints on global expressions can be evaluated on any thread, | |
1724 | and in any state. It is presently left to the target allowing | |
1725 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1726 | |
1727 | static int | |
3a5c3e22 | 1728 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1729 | { |
d0d8b0c6 JK |
1730 | return (b->base.pspace == current_program_space |
1731 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1732 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1733 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1734 | } |
1735 | ||
d0fb5eae JK |
1736 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1737 | associated bp_watchpoint_scope breakpoint. */ | |
1738 | ||
1739 | static void | |
3a5c3e22 | 1740 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1741 | { |
3a5c3e22 | 1742 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1743 | |
1744 | if (b->related_breakpoint != b) | |
1745 | { | |
1746 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1747 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1748 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1749 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1750 | b->related_breakpoint = b; | |
1751 | } | |
1752 | b->disposition = disp_del_at_next_stop; | |
1753 | } | |
1754 | ||
bb9d5f81 PP |
1755 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1756 | watchpoint W. */ | |
1757 | ||
1758 | static struct value * | |
1759 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1760 | { | |
1761 | struct value *bit_val; | |
1762 | ||
1763 | if (val == NULL) | |
1764 | return NULL; | |
1765 | ||
1766 | bit_val = allocate_value (value_type (val)); | |
1767 | ||
1768 | unpack_value_bitfield (bit_val, | |
1769 | w->val_bitpos, | |
1770 | w->val_bitsize, | |
1771 | value_contents_for_printing (val), | |
1772 | value_offset (val), | |
1773 | val); | |
1774 | ||
1775 | return bit_val; | |
1776 | } | |
1777 | ||
c6d81124 PA |
1778 | /* Allocate a dummy location and add it to B, which must be a software |
1779 | watchpoint. This is required because even if a software watchpoint | |
1780 | is not watching any memory, bpstat_stop_status requires a location | |
1781 | to be able to report stops. */ | |
1782 | ||
1783 | static void | |
1784 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1785 | struct program_space *pspace) | |
1786 | { | |
1787 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1788 | ||
1789 | b->loc = allocate_bp_location (b); | |
1790 | b->loc->pspace = pspace; | |
1791 | b->loc->address = -1; | |
1792 | b->loc->length = -1; | |
1793 | } | |
1794 | ||
1795 | /* Returns true if B is a software watchpoint that is not watching any | |
1796 | memory (e.g., "watch $pc"). */ | |
1797 | ||
1798 | static int | |
1799 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1800 | { | |
1801 | return (b->type == bp_watchpoint | |
1802 | && b->loc != NULL | |
1803 | && b->loc->next == NULL | |
1804 | && b->loc->address == -1 | |
1805 | && b->loc->length == -1); | |
1806 | } | |
1807 | ||
567e1b4e JB |
1808 | /* Assuming that B is a watchpoint: |
1809 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1810 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1811 | - Evaluate the condition if there is one, and store the result |
1812 | in b->loc->cond. | |
a5606eee VP |
1813 | - Update the list of values that must be watched in B->loc. |
1814 | ||
4a64f543 MS |
1815 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1816 | nothing. If this is local watchpoint that is out of scope, delete | |
1817 | it. | |
1818 | ||
1819 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1820 | removed + inserted on each stop here. Normal breakpoints must | |
1821 | never be removed because they might be missed by a running thread | |
1822 | when debugging in non-stop mode. On the other hand, hardware | |
1823 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1824 | to each LWP since they are stored in each LWP's hardware debug | |
1825 | registers. Therefore, such LWP must be stopped first in order to | |
1826 | be able to modify its hardware watchpoints. | |
1827 | ||
1828 | Hardware watchpoints must be reset exactly once after being | |
1829 | presented to the user. It cannot be done sooner, because it would | |
1830 | reset the data used to present the watchpoint hit to the user. And | |
1831 | it must not be done later because it could display the same single | |
1832 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1833 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1834 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1835 | not user-visible - its hit is suppressed if the memory content has | |
1836 | not changed. | |
1837 | ||
1838 | The following constraints influence the location where we can reset | |
1839 | hardware watchpoints: | |
1840 | ||
1841 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1842 | called several times when GDB stops. | |
1843 | ||
1844 | [linux] | |
1845 | * Multiple hardware watchpoints can be hit at the same time, | |
1846 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1847 | hit at a time as the reason for stopping, and all the other hits | |
1848 | are presented later, one after the other, each time the user | |
1849 | requests the execution to be resumed. Execution is not resumed | |
1850 | for the threads still having pending hit event stored in | |
1851 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1852 | the inferior on the first stop the thread hit event is kept being | |
1853 | reported from its cached value by linux_nat_stopped_data_address | |
1854 | until the real thread resume happens after the watchpoint gets | |
1855 | presented and thus its LWP_INFO->STATUS gets reset. | |
1856 | ||
1857 | Therefore the hardware watchpoint hit can get safely reset on the | |
1858 | watchpoint removal from inferior. */ | |
a79d3c27 | 1859 | |
b40ce68a | 1860 | static void |
3a5c3e22 | 1861 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1862 | { |
a5606eee | 1863 | int within_current_scope; |
a5606eee | 1864 | struct frame_id saved_frame_id; |
66076460 | 1865 | int frame_saved; |
a5606eee | 1866 | |
f6bc2008 PA |
1867 | /* If this is a local watchpoint, we only want to check if the |
1868 | watchpoint frame is in scope if the current thread is the thread | |
1869 | that was used to create the watchpoint. */ | |
1870 | if (!watchpoint_in_thread_scope (b)) | |
1871 | return; | |
1872 | ||
3a5c3e22 | 1873 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1874 | return; |
1875 | ||
66076460 | 1876 | frame_saved = 0; |
a5606eee VP |
1877 | |
1878 | /* Determine if the watchpoint is within scope. */ | |
1879 | if (b->exp_valid_block == NULL) | |
1880 | within_current_scope = 1; | |
1881 | else | |
1882 | { | |
b5db5dfc UW |
1883 | struct frame_info *fi = get_current_frame (); |
1884 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1885 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1886 | ||
c9cf6e20 MG |
1887 | /* If we're at a point where the stack has been destroyed |
1888 | (e.g. in a function epilogue), unwinding may not work | |
1889 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1890 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1891 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1892 | return; |
66076460 DJ |
1893 | |
1894 | /* Save the current frame's ID so we can restore it after | |
1895 | evaluating the watchpoint expression on its own frame. */ | |
1896 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1897 | took a frame parameter, so that we didn't have to change the | |
1898 | selected frame. */ | |
1899 | frame_saved = 1; | |
1900 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1901 | ||
a5606eee VP |
1902 | fi = frame_find_by_id (b->watchpoint_frame); |
1903 | within_current_scope = (fi != NULL); | |
1904 | if (within_current_scope) | |
1905 | select_frame (fi); | |
1906 | } | |
1907 | ||
b5db5dfc UW |
1908 | /* We don't free locations. They are stored in the bp_location array |
1909 | and update_global_location_list will eventually delete them and | |
1910 | remove breakpoints if needed. */ | |
3a5c3e22 | 1911 | b->base.loc = NULL; |
b5db5dfc | 1912 | |
a5606eee VP |
1913 | if (within_current_scope && reparse) |
1914 | { | |
bbc13ae3 | 1915 | const char *s; |
d63d0675 | 1916 | |
a5606eee VP |
1917 | if (b->exp) |
1918 | { | |
1919 | xfree (b->exp); | |
1920 | b->exp = NULL; | |
1921 | } | |
d63d0675 | 1922 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1923 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1924 | /* If the meaning of expression itself changed, the old value is |
1925 | no longer relevant. We don't want to report a watchpoint hit | |
1926 | to the user when the old value and the new value may actually | |
1927 | be completely different objects. */ | |
1928 | value_free (b->val); | |
fa4727a6 DJ |
1929 | b->val = NULL; |
1930 | b->val_valid = 0; | |
60e1c644 PA |
1931 | |
1932 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1933 | expression is stored in the breakpoint object, not in the | |
1934 | locations (re)created below. */ | |
3a5c3e22 | 1935 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1936 | { |
1937 | if (b->cond_exp != NULL) | |
1938 | { | |
1939 | xfree (b->cond_exp); | |
1940 | b->cond_exp = NULL; | |
1941 | } | |
1942 | ||
3a5c3e22 | 1943 | s = b->base.cond_string; |
1bb9788d | 1944 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1945 | } |
a5606eee | 1946 | } |
a5606eee VP |
1947 | |
1948 | /* If we failed to parse the expression, for example because | |
1949 | it refers to a global variable in a not-yet-loaded shared library, | |
1950 | don't try to insert watchpoint. We don't automatically delete | |
1951 | such watchpoint, though, since failure to parse expression | |
1952 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1953 | if (!target_has_execution) |
2d134ed3 PA |
1954 | { |
1955 | /* Without execution, memory can't change. No use to try and | |
1956 | set watchpoint locations. The watchpoint will be reset when | |
1957 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1958 | if (!can_use_hw_watchpoints) |
1959 | { | |
1960 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1961 | b->base.type = bp_watchpoint; | |
1962 | else | |
638aa5a1 AB |
1963 | error (_("Can't set read/access watchpoint when " |
1964 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1965 | } |
2d134ed3 PA |
1966 | } |
1967 | else if (within_current_scope && b->exp) | |
a5606eee | 1968 | { |
0cf6dd15 | 1969 | int pc = 0; |
fa4727a6 | 1970 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1971 | struct program_space *frame_pspace; |
a5606eee | 1972 | |
3a1115a0 | 1973 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1974 | |
a5606eee VP |
1975 | /* Avoid setting b->val if it's already set. The meaning of |
1976 | b->val is 'the last value' user saw, and we should update | |
1977 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1978 | happens, the code that reports it updates b->val directly. |
1979 | We don't keep track of the memory value for masked | |
1980 | watchpoints. */ | |
3a5c3e22 | 1981 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1982 | { |
bb9d5f81 PP |
1983 | if (b->val_bitsize != 0) |
1984 | { | |
1985 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1986 | if (v != NULL) | |
1987 | release_value (v); | |
1988 | } | |
fa4727a6 DJ |
1989 | b->val = v; |
1990 | b->val_valid = 1; | |
1991 | } | |
a5606eee | 1992 | |
2d134ed3 PA |
1993 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1994 | ||
a5606eee | 1995 | /* Look at each value on the value chain. */ |
9fa40276 | 1996 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1997 | { |
1998 | /* If it's a memory location, and GDB actually needed | |
1999 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
2000 | must watch it. If the first value returned is |
2001 | still lazy, that means an error occurred reading it; | |
2002 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2003 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2004 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2005 | { |
2006 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2007 | |
a5606eee VP |
2008 | /* We only watch structs and arrays if user asked |
2009 | for it explicitly, never if they just happen to | |
2010 | appear in the middle of some value chain. */ | |
fa4727a6 | 2011 | if (v == result |
a5606eee VP |
2012 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2013 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2014 | { | |
2015 | CORE_ADDR addr; | |
f486487f | 2016 | enum target_hw_bp_type type; |
a5606eee | 2017 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2018 | int bitpos = 0, bitsize = 0; |
2019 | ||
2020 | if (value_bitsize (v) != 0) | |
2021 | { | |
2022 | /* Extract the bit parameters out from the bitfield | |
2023 | sub-expression. */ | |
2024 | bitpos = value_bitpos (v); | |
2025 | bitsize = value_bitsize (v); | |
2026 | } | |
2027 | else if (v == result && b->val_bitsize != 0) | |
2028 | { | |
2029 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2030 | lvalue whose bit parameters are saved in the fields | |
2031 | VAL_BITPOS and VAL_BITSIZE. */ | |
2032 | bitpos = b->val_bitpos; | |
2033 | bitsize = b->val_bitsize; | |
2034 | } | |
a5606eee | 2035 | |
42ae5230 | 2036 | addr = value_address (v); |
bb9d5f81 PP |
2037 | if (bitsize != 0) |
2038 | { | |
2039 | /* Skip the bytes that don't contain the bitfield. */ | |
2040 | addr += bitpos / 8; | |
2041 | } | |
2042 | ||
a5606eee | 2043 | type = hw_write; |
3a5c3e22 | 2044 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2045 | type = hw_read; |
3a5c3e22 | 2046 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2047 | type = hw_access; |
3a5c3e22 PA |
2048 | |
2049 | loc = allocate_bp_location (&b->base); | |
2050 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2051 | ; |
2052 | *tmp = loc; | |
a6d9a66e | 2053 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2054 | |
2055 | loc->pspace = frame_pspace; | |
a5606eee | 2056 | loc->address = addr; |
bb9d5f81 PP |
2057 | |
2058 | if (bitsize != 0) | |
2059 | { | |
2060 | /* Just cover the bytes that make up the bitfield. */ | |
2061 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2062 | } | |
2063 | else | |
2064 | loc->length = TYPE_LENGTH (value_type (v)); | |
2065 | ||
a5606eee VP |
2066 | loc->watchpoint_type = type; |
2067 | } | |
2068 | } | |
9fa40276 TJB |
2069 | } |
2070 | ||
2071 | /* Change the type of breakpoint between hardware assisted or | |
2072 | an ordinary watchpoint depending on the hardware support | |
2073 | and free hardware slots. REPARSE is set when the inferior | |
2074 | is started. */ | |
a9634178 | 2075 | if (reparse) |
9fa40276 | 2076 | { |
e09342b5 | 2077 | int reg_cnt; |
9fa40276 TJB |
2078 | enum bp_loc_type loc_type; |
2079 | struct bp_location *bl; | |
a5606eee | 2080 | |
a9634178 | 2081 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2082 | |
2083 | if (reg_cnt) | |
9fa40276 TJB |
2084 | { |
2085 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2086 | enum bptype type; |
9fa40276 | 2087 | |
a9634178 TJB |
2088 | /* Use an exact watchpoint when there's only one memory region to be |
2089 | watched, and only one debug register is needed to watch it. */ | |
2090 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2091 | ||
9fa40276 | 2092 | /* We need to determine how many resources are already |
e09342b5 TJB |
2093 | used for all other hardware watchpoints plus this one |
2094 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2095 | this watchpoint in as well. */ |
2096 | ||
2097 | /* If this is a software watchpoint, we try to turn it | |
2098 | to a hardware one -- count resources as if B was of | |
2099 | hardware watchpoint type. */ | |
2100 | type = b->base.type; | |
2101 | if (type == bp_watchpoint) | |
2102 | type = bp_hardware_watchpoint; | |
2103 | ||
2104 | /* This watchpoint may or may not have been placed on | |
2105 | the list yet at this point (it won't be in the list | |
2106 | if we're trying to create it for the first time, | |
2107 | through watch_command), so always account for it | |
2108 | manually. */ | |
2109 | ||
2110 | /* Count resources used by all watchpoints except B. */ | |
2111 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2112 | ||
2113 | /* Add in the resources needed for B. */ | |
2114 | i += hw_watchpoint_use_count (&b->base); | |
2115 | ||
2116 | target_resources_ok | |
2117 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2118 | if (target_resources_ok <= 0) |
a9634178 | 2119 | { |
3a5c3e22 | 2120 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2121 | |
2122 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2123 | error (_("Target does not support this type of " |
2124 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2125 | else if (target_resources_ok < 0 && !sw_mode) |
2126 | error (_("There are not enough available hardware " | |
2127 | "resources for this watchpoint.")); | |
a1398e0c PA |
2128 | |
2129 | /* Downgrade to software watchpoint. */ | |
2130 | b->base.type = bp_watchpoint; | |
2131 | } | |
2132 | else | |
2133 | { | |
2134 | /* If this was a software watchpoint, we've just | |
2135 | found we have enough resources to turn it to a | |
2136 | hardware watchpoint. Otherwise, this is a | |
2137 | nop. */ | |
2138 | b->base.type = type; | |
a9634178 | 2139 | } |
9fa40276 | 2140 | } |
3a5c3e22 | 2141 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2142 | { |
2143 | if (!can_use_hw_watchpoints) | |
2144 | error (_("Can't set read/access watchpoint when " | |
2145 | "hardware watchpoints are disabled.")); | |
2146 | else | |
2147 | error (_("Expression cannot be implemented with " | |
2148 | "read/access watchpoint.")); | |
2149 | } | |
9fa40276 | 2150 | else |
3a5c3e22 | 2151 | b->base.type = bp_watchpoint; |
9fa40276 | 2152 | |
3a5c3e22 | 2153 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2154 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2155 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2156 | bl->loc_type = loc_type; |
2157 | } | |
2158 | ||
2159 | for (v = val_chain; v; v = next) | |
2160 | { | |
a5606eee VP |
2161 | next = value_next (v); |
2162 | if (v != b->val) | |
2163 | value_free (v); | |
2164 | } | |
2165 | ||
c7437ca6 PA |
2166 | /* If a software watchpoint is not watching any memory, then the |
2167 | above left it without any location set up. But, | |
2168 | bpstat_stop_status requires a location to be able to report | |
2169 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2170 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2171 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2172 | } |
2173 | else if (!within_current_scope) | |
7270d8f2 | 2174 | { |
ac74f770 MS |
2175 | printf_filtered (_("\ |
2176 | Watchpoint %d deleted because the program has left the block\n\ | |
2177 | in which its expression is valid.\n"), | |
3a5c3e22 | 2178 | b->base.number); |
d0fb5eae | 2179 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2180 | } |
a5606eee VP |
2181 | |
2182 | /* Restore the selected frame. */ | |
66076460 DJ |
2183 | if (frame_saved) |
2184 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2185 | } |
2186 | ||
a5606eee | 2187 | |
74960c60 | 2188 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2189 | inserted in the inferior. We don't differentiate the type of BL's owner |
2190 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2191 | breakpoint_ops is not defined, because in insert_bp_location, | |
2192 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2193 | static int |
35df4500 | 2194 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2195 | { |
35df4500 | 2196 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2197 | return 0; |
2198 | ||
35df4500 | 2199 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2200 | return 0; |
2201 | ||
35df4500 | 2202 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2203 | return 0; |
2204 | ||
f8eba3c6 TT |
2205 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2206 | return 0; | |
2207 | ||
56710373 PA |
2208 | /* This is set for example, when we're attached to the parent of a |
2209 | vfork, and have detached from the child. The child is running | |
2210 | free, and we expect it to do an exec or exit, at which point the | |
2211 | OS makes the parent schedulable again (and the target reports | |
2212 | that the vfork is done). Until the child is done with the shared | |
2213 | memory region, do not insert breakpoints in the parent, otherwise | |
2214 | the child could still trip on the parent's breakpoints. Since | |
2215 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2216 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2217 | return 0; |
2218 | ||
31e77af2 PA |
2219 | /* Don't insert a breakpoint if we're trying to step past its |
2220 | location. */ | |
2221 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2222 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2223 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2224 | bl->address)) | |
e558d7c1 PA |
2225 | { |
2226 | if (debug_infrun) | |
2227 | { | |
2228 | fprintf_unfiltered (gdb_stdlog, | |
2229 | "infrun: skipping breakpoint: " | |
2230 | "stepping past insn at: %s\n", | |
2231 | paddress (bl->gdbarch, bl->address)); | |
2232 | } | |
2233 | return 0; | |
2234 | } | |
31e77af2 | 2235 | |
963f9c80 PA |
2236 | /* Don't insert watchpoints if we're trying to step past the |
2237 | instruction that triggered one. */ | |
2238 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2239 | && stepping_past_nonsteppable_watchpoint ()) | |
2240 | { | |
2241 | if (debug_infrun) | |
2242 | { | |
2243 | fprintf_unfiltered (gdb_stdlog, | |
2244 | "infrun: stepping past non-steppable watchpoint. " | |
2245 | "skipping watchpoint at %s:%d\n", | |
2246 | paddress (bl->gdbarch, bl->address), | |
2247 | bl->length); | |
2248 | } | |
2249 | return 0; | |
2250 | } | |
2251 | ||
74960c60 VP |
2252 | return 1; |
2253 | } | |
2254 | ||
934709f0 PW |
2255 | /* Same as should_be_inserted but does the check assuming |
2256 | that the location is not duplicated. */ | |
2257 | ||
2258 | static int | |
2259 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2260 | { | |
2261 | int result; | |
2262 | const int save_duplicate = bl->duplicate; | |
2263 | ||
2264 | bl->duplicate = 0; | |
2265 | result = should_be_inserted (bl); | |
2266 | bl->duplicate = save_duplicate; | |
2267 | return result; | |
2268 | } | |
2269 | ||
b775012e LM |
2270 | /* Parses a conditional described by an expression COND into an |
2271 | agent expression bytecode suitable for evaluation | |
2272 | by the bytecode interpreter. Return NULL if there was | |
2273 | any error during parsing. */ | |
2274 | ||
2275 | static struct agent_expr * | |
2276 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2277 | { | |
2278 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2279 | |
2280 | if (!cond) | |
2281 | return NULL; | |
2282 | ||
2283 | /* We don't want to stop processing, so catch any errors | |
2284 | that may show up. */ | |
492d29ea | 2285 | TRY |
b775012e LM |
2286 | { |
2287 | aexpr = gen_eval_for_expr (scope, cond); | |
2288 | } | |
2289 | ||
492d29ea | 2290 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2291 | { |
2292 | /* If we got here, it means the condition could not be parsed to a valid | |
2293 | bytecode expression and thus can't be evaluated on the target's side. | |
2294 | It's no use iterating through the conditions. */ | |
2295 | return NULL; | |
2296 | } | |
492d29ea | 2297 | END_CATCH |
b775012e LM |
2298 | |
2299 | /* We have a valid agent expression. */ | |
2300 | return aexpr; | |
2301 | } | |
2302 | ||
2303 | /* Based on location BL, create a list of breakpoint conditions to be | |
2304 | passed on to the target. If we have duplicated locations with different | |
2305 | conditions, we will add such conditions to the list. The idea is that the | |
2306 | target will evaluate the list of conditions and will only notify GDB when | |
2307 | one of them is true. */ | |
2308 | ||
2309 | static void | |
2310 | build_target_condition_list (struct bp_location *bl) | |
2311 | { | |
2312 | struct bp_location **locp = NULL, **loc2p; | |
2313 | int null_condition_or_parse_error = 0; | |
2314 | int modified = bl->needs_update; | |
2315 | struct bp_location *loc; | |
2316 | ||
8b4f3082 PA |
2317 | /* Release conditions left over from a previous insert. */ |
2318 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2319 | ||
b775012e LM |
2320 | /* This is only meaningful if the target is |
2321 | evaluating conditions and if the user has | |
2322 | opted for condition evaluation on the target's | |
2323 | side. */ | |
2324 | if (gdb_evaluates_breakpoint_condition_p () | |
2325 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2326 | return; | |
2327 | ||
2328 | /* Do a first pass to check for locations with no assigned | |
2329 | conditions or conditions that fail to parse to a valid agent expression | |
2330 | bytecode. If any of these happen, then it's no use to send conditions | |
2331 | to the target since this location will always trigger and generate a | |
2332 | response back to GDB. */ | |
2333 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2334 | { | |
2335 | loc = (*loc2p); | |
2336 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2337 | { | |
2338 | if (modified) | |
2339 | { | |
2340 | struct agent_expr *aexpr; | |
2341 | ||
2342 | /* Re-parse the conditions since something changed. In that | |
2343 | case we already freed the condition bytecodes (see | |
2344 | force_breakpoint_reinsertion). We just | |
2345 | need to parse the condition to bytecodes again. */ | |
2346 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2347 | loc->cond_bytecode = aexpr; | |
2348 | ||
2349 | /* Check if we managed to parse the conditional expression | |
2350 | correctly. If not, we will not send this condition | |
2351 | to the target. */ | |
2352 | if (aexpr) | |
2353 | continue; | |
2354 | } | |
2355 | ||
2356 | /* If we have a NULL bytecode expression, it means something | |
2357 | went wrong or we have a null condition expression. */ | |
2358 | if (!loc->cond_bytecode) | |
2359 | { | |
2360 | null_condition_or_parse_error = 1; | |
2361 | break; | |
2362 | } | |
2363 | } | |
2364 | } | |
2365 | ||
2366 | /* If any of these happened, it means we will have to evaluate the conditions | |
2367 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2368 | for all the other duplicate locations, thus we free all of them here. | |
2369 | ||
2370 | This is so we have a finer control over which locations' conditions are | |
2371 | being evaluated by GDB or the remote stub. */ | |
2372 | if (null_condition_or_parse_error) | |
2373 | { | |
2374 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2375 | { | |
2376 | loc = (*loc2p); | |
2377 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2378 | { | |
2379 | /* Only go as far as the first NULL bytecode is | |
2380 | located. */ | |
2381 | if (!loc->cond_bytecode) | |
2382 | return; | |
2383 | ||
2384 | free_agent_expr (loc->cond_bytecode); | |
2385 | loc->cond_bytecode = NULL; | |
2386 | } | |
2387 | } | |
2388 | } | |
2389 | ||
2390 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2391 | for this location's address. */ | |
2392 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2393 | { | |
2394 | loc = (*loc2p); | |
2395 | if (loc->cond | |
2396 | && is_breakpoint (loc->owner) | |
2397 | && loc->pspace->num == bl->pspace->num | |
2398 | && loc->owner->enable_state == bp_enabled | |
2399 | && loc->enabled) | |
2400 | /* Add the condition to the vector. This will be used later to send the | |
2401 | conditions to the target. */ | |
2402 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2403 | loc->cond_bytecode); | |
2404 | } | |
2405 | ||
2406 | return; | |
2407 | } | |
2408 | ||
d3ce09f5 SS |
2409 | /* Parses a command described by string CMD into an agent expression |
2410 | bytecode suitable for evaluation by the bytecode interpreter. | |
2411 | Return NULL if there was any error during parsing. */ | |
2412 | ||
2413 | static struct agent_expr * | |
2414 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2415 | { | |
2416 | struct cleanup *old_cleanups = 0; | |
2417 | struct expression *expr, **argvec; | |
2418 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2419 | const char *cmdrest; |
2420 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2421 | struct format_piece *fpieces; |
2422 | int nargs; | |
2423 | struct gdbarch *gdbarch = get_current_arch (); | |
2424 | ||
2425 | if (!cmd) | |
2426 | return NULL; | |
2427 | ||
2428 | cmdrest = cmd; | |
2429 | ||
2430 | if (*cmdrest == ',') | |
2431 | ++cmdrest; | |
bbc13ae3 | 2432 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2433 | |
2434 | if (*cmdrest++ != '"') | |
2435 | error (_("No format string following the location")); | |
2436 | ||
2437 | format_start = cmdrest; | |
2438 | ||
2439 | fpieces = parse_format_string (&cmdrest); | |
2440 | ||
2441 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2442 | ||
2443 | format_end = cmdrest; | |
2444 | ||
2445 | if (*cmdrest++ != '"') | |
2446 | error (_("Bad format string, non-terminated '\"'.")); | |
2447 | ||
bbc13ae3 | 2448 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2449 | |
2450 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2451 | error (_("Invalid argument syntax")); | |
2452 | ||
2453 | if (*cmdrest == ',') | |
2454 | cmdrest++; | |
bbc13ae3 | 2455 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2456 | |
2457 | /* For each argument, make an expression. */ | |
2458 | ||
2459 | argvec = (struct expression **) alloca (strlen (cmd) | |
2460 | * sizeof (struct expression *)); | |
2461 | ||
2462 | nargs = 0; | |
2463 | while (*cmdrest != '\0') | |
2464 | { | |
bbc13ae3 | 2465 | const char *cmd1; |
d3ce09f5 SS |
2466 | |
2467 | cmd1 = cmdrest; | |
2468 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2469 | argvec[nargs++] = expr; | |
2470 | cmdrest = cmd1; | |
2471 | if (*cmdrest == ',') | |
2472 | ++cmdrest; | |
2473 | } | |
2474 | ||
2475 | /* We don't want to stop processing, so catch any errors | |
2476 | that may show up. */ | |
492d29ea | 2477 | TRY |
d3ce09f5 SS |
2478 | { |
2479 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2480 | format_start, format_end - format_start, | |
2481 | fpieces, nargs, argvec); | |
2482 | } | |
492d29ea | 2483 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2484 | { |
2485 | /* If we got here, it means the command could not be parsed to a valid | |
2486 | bytecode expression and thus can't be evaluated on the target's side. | |
2487 | It's no use iterating through the other commands. */ | |
492d29ea | 2488 | aexpr = NULL; |
d3ce09f5 | 2489 | } |
492d29ea PA |
2490 | END_CATCH |
2491 | ||
2492 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2493 | |
d3ce09f5 SS |
2494 | /* We have a valid agent expression, return it. */ |
2495 | return aexpr; | |
2496 | } | |
2497 | ||
2498 | /* Based on location BL, create a list of breakpoint commands to be | |
2499 | passed on to the target. If we have duplicated locations with | |
2500 | different commands, we will add any such to the list. */ | |
2501 | ||
2502 | static void | |
2503 | build_target_command_list (struct bp_location *bl) | |
2504 | { | |
2505 | struct bp_location **locp = NULL, **loc2p; | |
2506 | int null_command_or_parse_error = 0; | |
2507 | int modified = bl->needs_update; | |
2508 | struct bp_location *loc; | |
2509 | ||
8b4f3082 PA |
2510 | /* Release commands left over from a previous insert. */ |
2511 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2512 | ||
41fac0cf | 2513 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2514 | return; |
2515 | ||
41fac0cf PA |
2516 | /* For now, limit to agent-style dprintf breakpoints. */ |
2517 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2518 | return; |
2519 | ||
41fac0cf PA |
2520 | /* For now, if we have any duplicate location that isn't a dprintf, |
2521 | don't install the target-side commands, as that would make the | |
2522 | breakpoint not be reported to the core, and we'd lose | |
2523 | control. */ | |
2524 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2525 | { | |
2526 | loc = (*loc2p); | |
2527 | if (is_breakpoint (loc->owner) | |
2528 | && loc->pspace->num == bl->pspace->num | |
2529 | && loc->owner->type != bp_dprintf) | |
2530 | return; | |
2531 | } | |
2532 | ||
d3ce09f5 SS |
2533 | /* Do a first pass to check for locations with no assigned |
2534 | conditions or conditions that fail to parse to a valid agent expression | |
2535 | bytecode. If any of these happen, then it's no use to send conditions | |
2536 | to the target since this location will always trigger and generate a | |
2537 | response back to GDB. */ | |
2538 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2539 | { | |
2540 | loc = (*loc2p); | |
2541 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2542 | { | |
2543 | if (modified) | |
2544 | { | |
2545 | struct agent_expr *aexpr; | |
2546 | ||
2547 | /* Re-parse the commands since something changed. In that | |
2548 | case we already freed the command bytecodes (see | |
2549 | force_breakpoint_reinsertion). We just | |
2550 | need to parse the command to bytecodes again. */ | |
2551 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2552 | loc->owner->extra_string); | |
2553 | loc->cmd_bytecode = aexpr; | |
2554 | ||
2555 | if (!aexpr) | |
2556 | continue; | |
2557 | } | |
2558 | ||
2559 | /* If we have a NULL bytecode expression, it means something | |
2560 | went wrong or we have a null command expression. */ | |
2561 | if (!loc->cmd_bytecode) | |
2562 | { | |
2563 | null_command_or_parse_error = 1; | |
2564 | break; | |
2565 | } | |
2566 | } | |
2567 | } | |
2568 | ||
2569 | /* If anything failed, then we're not doing target-side commands, | |
2570 | and so clean up. */ | |
2571 | if (null_command_or_parse_error) | |
2572 | { | |
2573 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2574 | { | |
2575 | loc = (*loc2p); | |
2576 | if (is_breakpoint (loc->owner) | |
2577 | && loc->pspace->num == bl->pspace->num) | |
2578 | { | |
2579 | /* Only go as far as the first NULL bytecode is | |
2580 | located. */ | |
40fb6c5e | 2581 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2582 | return; |
2583 | ||
40fb6c5e HZ |
2584 | free_agent_expr (loc->cmd_bytecode); |
2585 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2586 | } |
2587 | } | |
2588 | } | |
2589 | ||
2590 | /* No NULL commands or failed bytecode generation. Build a command list | |
2591 | for this location's address. */ | |
2592 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2593 | { | |
2594 | loc = (*loc2p); | |
2595 | if (loc->owner->extra_string | |
2596 | && is_breakpoint (loc->owner) | |
2597 | && loc->pspace->num == bl->pspace->num | |
2598 | && loc->owner->enable_state == bp_enabled | |
2599 | && loc->enabled) | |
2600 | /* Add the command to the vector. This will be used later | |
2601 | to send the commands to the target. */ | |
2602 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2603 | loc->cmd_bytecode); | |
2604 | } | |
2605 | ||
2606 | bl->target_info.persist = 0; | |
2607 | /* Maybe flag this location as persistent. */ | |
2608 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2609 | bl->target_info.persist = 1; | |
2610 | } | |
2611 | ||
35df4500 TJB |
2612 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2613 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2614 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2615 | Returns 0 for success, 1 if the bp_location type is not supported or |
2616 | -1 for failure. | |
879bfdc2 | 2617 | |
4a64f543 MS |
2618 | NOTE drow/2003-09-09: This routine could be broken down to an |
2619 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2620 | static int |
35df4500 | 2621 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2622 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2623 | int *disabled_breaks, |
dd61ec5c MW |
2624 | int *hw_breakpoint_error, |
2625 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2626 | { |
0000e5cc PA |
2627 | enum errors bp_err = GDB_NO_ERROR; |
2628 | const char *bp_err_message = NULL; | |
879bfdc2 | 2629 | |
b775012e | 2630 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2631 | return 0; |
2632 | ||
35c63cd8 JB |
2633 | /* Note we don't initialize bl->target_info, as that wipes out |
2634 | the breakpoint location's shadow_contents if the breakpoint | |
2635 | is still inserted at that location. This in turn breaks | |
2636 | target_read_memory which depends on these buffers when | |
2637 | a memory read is requested at the breakpoint location: | |
2638 | Once the target_info has been wiped, we fail to see that | |
2639 | we have a breakpoint inserted at that address and thus | |
2640 | read the breakpoint instead of returning the data saved in | |
2641 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2642 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2643 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2644 | bl->target_info.length = bl->length; |
8181d85f | 2645 | |
b775012e LM |
2646 | /* When working with target-side conditions, we must pass all the conditions |
2647 | for the same breakpoint address down to the target since GDB will not | |
2648 | insert those locations. With a list of breakpoint conditions, the target | |
2649 | can decide when to stop and notify GDB. */ | |
2650 | ||
2651 | if (is_breakpoint (bl->owner)) | |
2652 | { | |
2653 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2654 | build_target_command_list (bl); |
2655 | /* Reset the modification marker. */ | |
b775012e LM |
2656 | bl->needs_update = 0; |
2657 | } | |
2658 | ||
35df4500 TJB |
2659 | if (bl->loc_type == bp_loc_software_breakpoint |
2660 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2661 | { |
35df4500 | 2662 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2663 | { |
2664 | /* If the explicitly specified breakpoint type | |
2665 | is not hardware breakpoint, check the memory map to see | |
2666 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2667 | |
765dc015 VP |
2668 | Two important cases are: |
2669 | - location type is not hardware breakpoint, memory | |
2670 | is readonly. We change the type of the location to | |
2671 | hardware breakpoint. | |
4a64f543 MS |
2672 | - location type is hardware breakpoint, memory is |
2673 | read-write. This means we've previously made the | |
2674 | location hardware one, but then the memory map changed, | |
2675 | so we undo. | |
765dc015 | 2676 | |
4a64f543 MS |
2677 | When breakpoints are removed, remove_breakpoints will use |
2678 | location types we've just set here, the only possible | |
2679 | problem is that memory map has changed during running | |
2680 | program, but it's not going to work anyway with current | |
2681 | gdb. */ | |
765dc015 | 2682 | struct mem_region *mr |
0d5ed153 | 2683 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2684 | |
2685 | if (mr) | |
2686 | { | |
2687 | if (automatic_hardware_breakpoints) | |
2688 | { | |
765dc015 VP |
2689 | enum bp_loc_type new_type; |
2690 | ||
2691 | if (mr->attrib.mode != MEM_RW) | |
2692 | new_type = bp_loc_hardware_breakpoint; | |
2693 | else | |
2694 | new_type = bp_loc_software_breakpoint; | |
2695 | ||
35df4500 | 2696 | if (new_type != bl->loc_type) |
765dc015 VP |
2697 | { |
2698 | static int said = 0; | |
cc59ec59 | 2699 | |
35df4500 | 2700 | bl->loc_type = new_type; |
765dc015 VP |
2701 | if (!said) |
2702 | { | |
3e43a32a MS |
2703 | fprintf_filtered (gdb_stdout, |
2704 | _("Note: automatically using " | |
2705 | "hardware breakpoints for " | |
2706 | "read-only addresses.\n")); | |
765dc015 VP |
2707 | said = 1; |
2708 | } | |
2709 | } | |
2710 | } | |
35df4500 | 2711 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2712 | && mr->attrib.mode != MEM_RW) |
2713 | { | |
2714 | fprintf_unfiltered (tmp_error_stream, | |
2715 | _("Cannot insert breakpoint %d.\n" | |
2716 | "Cannot set software breakpoint " | |
2717 | "at read-only address %s\n"), | |
2718 | bl->owner->number, | |
2719 | paddress (bl->gdbarch, bl->address)); | |
2720 | return 1; | |
2721 | } | |
765dc015 VP |
2722 | } |
2723 | } | |
2724 | ||
879bfdc2 DJ |
2725 | /* First check to see if we have to handle an overlay. */ |
2726 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2727 | || bl->section == NULL |
2728 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2729 | { |
2730 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2731 | TRY |
dd61ec5c | 2732 | { |
0000e5cc PA |
2733 | int val; |
2734 | ||
dd61ec5c | 2735 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2736 | if (val) |
2737 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2738 | } |
492d29ea | 2739 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2740 | { |
0000e5cc PA |
2741 | bp_err = e.error; |
2742 | bp_err_message = e.message; | |
dd61ec5c | 2743 | } |
492d29ea | 2744 | END_CATCH |
879bfdc2 DJ |
2745 | } |
2746 | else | |
2747 | { | |
4a64f543 | 2748 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2749 | Shall we set a breakpoint at the LMA? */ |
2750 | if (!overlay_events_enabled) | |
2751 | { | |
2752 | /* Yes -- overlay event support is not active, | |
2753 | so we must try to set a breakpoint at the LMA. | |
2754 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2755 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2756 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2757 | bl->owner->number); |
879bfdc2 DJ |
2758 | else |
2759 | { | |
35df4500 TJB |
2760 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2761 | bl->section); | |
879bfdc2 | 2762 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2763 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2764 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2765 | |
2766 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2767 | TRY |
0000e5cc PA |
2768 | { |
2769 | int val; | |
2770 | ||
2771 | val = target_insert_breakpoint (bl->gdbarch, | |
2772 | &bl->overlay_target_info); | |
2773 | if (val) | |
2774 | bp_err = GENERIC_ERROR; | |
2775 | } | |
492d29ea | 2776 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2777 | { |
2778 | bp_err = e.error; | |
2779 | bp_err_message = e.message; | |
2780 | } | |
492d29ea | 2781 | END_CATCH |
0000e5cc PA |
2782 | |
2783 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2784 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2785 | "Overlay breakpoint %d " |
2786 | "failed: in ROM?\n", | |
35df4500 | 2787 | bl->owner->number); |
879bfdc2 DJ |
2788 | } |
2789 | } | |
2790 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2791 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2792 | { |
2793 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2794 | TRY |
dd61ec5c | 2795 | { |
0000e5cc PA |
2796 | int val; |
2797 | ||
dd61ec5c | 2798 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2799 | if (val) |
2800 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2801 | } |
492d29ea | 2802 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2803 | { |
0000e5cc PA |
2804 | bp_err = e.error; |
2805 | bp_err_message = e.message; | |
dd61ec5c | 2806 | } |
492d29ea | 2807 | END_CATCH |
879bfdc2 DJ |
2808 | } |
2809 | else | |
2810 | { | |
2811 | /* No. This breakpoint will not be inserted. | |
2812 | No error, but do not mark the bp as 'inserted'. */ | |
2813 | return 0; | |
2814 | } | |
2815 | } | |
2816 | ||
0000e5cc | 2817 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2818 | { |
2819 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2820 | |
2821 | /* In some cases, we might not be able to insert a | |
2822 | breakpoint in a shared library that has already been | |
2823 | removed, but we have not yet processed the shlib unload | |
2824 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2825 | breakpoint insertion themselves can't tell why the |
2826 | breakpoint insertion failed (e.g., the remote target | |
2827 | doesn't define error codes), so we must treat generic | |
2828 | errors as memory errors. */ | |
0000e5cc | 2829 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2830 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2831 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2832 | || shared_objfile_contains_address_p (bl->pspace, |
2833 | bl->address))) | |
879bfdc2 | 2834 | { |
4a64f543 | 2835 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2836 | bl->shlib_disabled = 1; |
8d3788bd | 2837 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2838 | if (!*disabled_breaks) |
2839 | { | |
2840 | fprintf_unfiltered (tmp_error_stream, | |
2841 | "Cannot insert breakpoint %d.\n", | |
2842 | bl->owner->number); | |
2843 | fprintf_unfiltered (tmp_error_stream, | |
2844 | "Temporarily disabling shared " | |
2845 | "library breakpoints:\n"); | |
2846 | } | |
2847 | *disabled_breaks = 1; | |
879bfdc2 | 2848 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2849 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2850 | return 0; |
879bfdc2 DJ |
2851 | } |
2852 | else | |
879bfdc2 | 2853 | { |
35df4500 | 2854 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2855 | { |
0000e5cc PA |
2856 | *hw_breakpoint_error = 1; |
2857 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2858 | fprintf_unfiltered (tmp_error_stream, |
2859 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2860 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2861 | if (bp_err_message != NULL) | |
2862 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2863 | } |
2864 | else | |
2865 | { | |
0000e5cc PA |
2866 | if (bp_err_message == NULL) |
2867 | { | |
2868 | char *message | |
2869 | = memory_error_message (TARGET_XFER_E_IO, | |
2870 | bl->gdbarch, bl->address); | |
2871 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2872 | ||
2873 | fprintf_unfiltered (tmp_error_stream, | |
2874 | "Cannot insert breakpoint %d.\n" | |
2875 | "%s\n", | |
2876 | bl->owner->number, message); | |
2877 | do_cleanups (old_chain); | |
2878 | } | |
2879 | else | |
2880 | { | |
2881 | fprintf_unfiltered (tmp_error_stream, | |
2882 | "Cannot insert breakpoint %d: %s\n", | |
2883 | bl->owner->number, | |
2884 | bp_err_message); | |
2885 | } | |
879bfdc2 | 2886 | } |
0000e5cc | 2887 | return 1; |
879bfdc2 DJ |
2888 | |
2889 | } | |
2890 | } | |
2891 | else | |
35df4500 | 2892 | bl->inserted = 1; |
879bfdc2 | 2893 | |
0000e5cc | 2894 | return 0; |
879bfdc2 DJ |
2895 | } |
2896 | ||
35df4500 | 2897 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2898 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2899 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2900 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2901 | { |
0000e5cc PA |
2902 | int val; |
2903 | ||
77b06cd7 TJB |
2904 | gdb_assert (bl->owner->ops != NULL |
2905 | && bl->owner->ops->insert_location != NULL); | |
2906 | ||
2907 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2908 | |
2909 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2910 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2911 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2912 | { |
2913 | struct bp_location *loc, **loc_temp; | |
2914 | ||
2915 | /* But don't try to insert it, if there's already another | |
2916 | hw_access location that would be considered a duplicate | |
2917 | of this one. */ | |
2918 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2919 | if (loc != bl |
85d721b8 | 2920 | && loc->watchpoint_type == hw_access |
35df4500 | 2921 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2922 | { |
35df4500 TJB |
2923 | bl->duplicate = 1; |
2924 | bl->inserted = 1; | |
2925 | bl->target_info = loc->target_info; | |
2926 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2927 | val = 0; |
2928 | break; | |
2929 | } | |
2930 | ||
2931 | if (val == 1) | |
2932 | { | |
77b06cd7 TJB |
2933 | bl->watchpoint_type = hw_access; |
2934 | val = bl->owner->ops->insert_location (bl); | |
2935 | ||
2936 | if (val) | |
2937 | /* Back to the original value. */ | |
2938 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2939 | } |
2940 | } | |
2941 | ||
35df4500 | 2942 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2943 | } |
2944 | ||
35df4500 | 2945 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2946 | { |
0000e5cc PA |
2947 | int val; |
2948 | ||
77b06cd7 TJB |
2949 | gdb_assert (bl->owner->ops != NULL |
2950 | && bl->owner->ops->insert_location != NULL); | |
2951 | ||
2952 | val = bl->owner->ops->insert_location (bl); | |
2953 | if (val) | |
2954 | { | |
2955 | bl->owner->enable_state = bp_disabled; | |
2956 | ||
2957 | if (val == 1) | |
2958 | warning (_("\ | |
2959 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2960 | of catchpoint."), bl->owner->number); | |
2961 | else | |
2962 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2963 | } | |
2964 | ||
2965 | bl->inserted = (val == 0); | |
1640b821 DJ |
2966 | |
2967 | /* We've already printed an error message if there was a problem | |
2968 | inserting this catchpoint, and we've disabled the catchpoint, | |
2969 | so just return success. */ | |
2970 | return 0; | |
879bfdc2 DJ |
2971 | } |
2972 | ||
2973 | return 0; | |
2974 | } | |
2975 | ||
6c95b8df PA |
2976 | /* This function is called when program space PSPACE is about to be |
2977 | deleted. It takes care of updating breakpoints to not reference | |
2978 | PSPACE anymore. */ | |
2979 | ||
2980 | void | |
2981 | breakpoint_program_space_exit (struct program_space *pspace) | |
2982 | { | |
2983 | struct breakpoint *b, *b_temp; | |
876fa593 | 2984 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2985 | |
2986 | /* Remove any breakpoint that was set through this program space. */ | |
2987 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2988 | { | |
2989 | if (b->pspace == pspace) | |
2990 | delete_breakpoint (b); | |
2991 | } | |
2992 | ||
2993 | /* Breakpoints set through other program spaces could have locations | |
2994 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2995 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2996 | { |
2997 | struct bp_location *tmp; | |
2998 | ||
2999 | if (loc->pspace == pspace) | |
3000 | { | |
2bdf28a0 | 3001 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3002 | if (loc->owner->loc == loc) |
3003 | loc->owner->loc = loc->next; | |
3004 | else | |
3005 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3006 | if (tmp->next == loc) | |
3007 | { | |
3008 | tmp->next = loc->next; | |
3009 | break; | |
3010 | } | |
3011 | } | |
3012 | } | |
3013 | ||
3014 | /* Now update the global location list to permanently delete the | |
3015 | removed locations above. */ | |
44702360 | 3016 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3017 | } |
3018 | ||
74960c60 VP |
3019 | /* Make sure all breakpoints are inserted in inferior. |
3020 | Throws exception on any error. | |
3021 | A breakpoint that is already inserted won't be inserted | |
3022 | again, so calling this function twice is safe. */ | |
3023 | void | |
3024 | insert_breakpoints (void) | |
3025 | { | |
3026 | struct breakpoint *bpt; | |
3027 | ||
3028 | ALL_BREAKPOINTS (bpt) | |
3029 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3030 | { |
3031 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3032 | ||
3033 | update_watchpoint (w, 0 /* don't reparse. */); | |
3034 | } | |
74960c60 | 3035 | |
04086b45 PA |
3036 | /* Updating watchpoints creates new locations, so update the global |
3037 | location list. Explicitly tell ugll to insert locations and | |
3038 | ignore breakpoints_always_inserted_mode. */ | |
3039 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3040 | } |
3041 | ||
20388dd6 YQ |
3042 | /* Invoke CALLBACK for each of bp_location. */ |
3043 | ||
3044 | void | |
3045 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3046 | { | |
3047 | struct bp_location *loc, **loc_tmp; | |
3048 | ||
3049 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3050 | { | |
3051 | callback (loc, NULL); | |
3052 | } | |
3053 | } | |
3054 | ||
b775012e LM |
3055 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3056 | target. It is the case with deleting and disabling of breakpoints when using | |
3057 | always-inserted mode. */ | |
3058 | ||
3059 | static void | |
3060 | update_inserted_breakpoint_locations (void) | |
3061 | { | |
3062 | struct bp_location *bl, **blp_tmp; | |
3063 | int error_flag = 0; | |
3064 | int val = 0; | |
3065 | int disabled_breaks = 0; | |
3066 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3067 | int hw_bp_details_reported = 0; |
b775012e LM |
3068 | |
3069 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3070 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3071 | ||
3072 | /* Explicitly mark the warning -- this will only be printed if | |
3073 | there was an error. */ | |
3074 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3075 | ||
3076 | save_current_space_and_thread (); | |
3077 | ||
3078 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3079 | { | |
3080 | /* We only want to update software breakpoints and hardware | |
3081 | breakpoints. */ | |
3082 | if (!is_breakpoint (bl->owner)) | |
3083 | continue; | |
3084 | ||
3085 | /* We only want to update locations that are already inserted | |
3086 | and need updating. This is to avoid unwanted insertion during | |
3087 | deletion of breakpoints. */ | |
3088 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3089 | continue; | |
3090 | ||
3091 | switch_to_program_space_and_thread (bl->pspace); | |
3092 | ||
3093 | /* For targets that support global breakpoints, there's no need | |
3094 | to select an inferior to insert breakpoint to. In fact, even | |
3095 | if we aren't attached to any process yet, we should still | |
3096 | insert breakpoints. */ | |
f5656ead | 3097 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3098 | && ptid_equal (inferior_ptid, null_ptid)) |
3099 | continue; | |
3100 | ||
3101 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3102 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3103 | if (val) |
3104 | error_flag = val; | |
3105 | } | |
3106 | ||
3107 | if (error_flag) | |
3108 | { | |
3109 | target_terminal_ours_for_output (); | |
3110 | error_stream (tmp_error_stream); | |
3111 | } | |
3112 | ||
3113 | do_cleanups (cleanups); | |
3114 | } | |
3115 | ||
c30eee59 | 3116 | /* Used when starting or continuing the program. */ |
c906108c | 3117 | |
74960c60 VP |
3118 | static void |
3119 | insert_breakpoint_locations (void) | |
c906108c | 3120 | { |
a5606eee | 3121 | struct breakpoint *bpt; |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3123 | int error_flag = 0; |
c906108c | 3124 | int val = 0; |
3fbb6ffa | 3125 | int disabled_breaks = 0; |
81d0cc19 | 3126 | int hw_breakpoint_error = 0; |
dd61ec5c | 3127 | int hw_bp_error_explained_already = 0; |
c906108c | 3128 | |
81d0cc19 | 3129 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3130 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3131 | |
81d0cc19 GS |
3132 | /* Explicitly mark the warning -- this will only be printed if |
3133 | there was an error. */ | |
3134 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3135 | |
3136 | save_current_space_and_thread (); | |
3137 | ||
35df4500 | 3138 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3139 | { |
b775012e | 3140 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3141 | continue; |
3142 | ||
4a64f543 MS |
3143 | /* There is no point inserting thread-specific breakpoints if |
3144 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3145 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3146 | if (bl->owner->thread != -1 |
3147 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3148 | continue; |
3149 | ||
35df4500 | 3150 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3151 | |
3152 | /* For targets that support global breakpoints, there's no need | |
3153 | to select an inferior to insert breakpoint to. In fact, even | |
3154 | if we aren't attached to any process yet, we should still | |
3155 | insert breakpoints. */ | |
f5656ead | 3156 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3157 | && ptid_equal (inferior_ptid, null_ptid)) |
3158 | continue; | |
3159 | ||
3fbb6ffa | 3160 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3161 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3162 | if (val) |
eacd795a | 3163 | error_flag = val; |
879bfdc2 | 3164 | } |
c906108c | 3165 | |
4a64f543 MS |
3166 | /* If we failed to insert all locations of a watchpoint, remove |
3167 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3168 | ALL_BREAKPOINTS (bpt) |
3169 | { | |
3170 | int some_failed = 0; | |
3171 | struct bp_location *loc; | |
3172 | ||
3173 | if (!is_hardware_watchpoint (bpt)) | |
3174 | continue; | |
3175 | ||
d6b74ac4 | 3176 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3177 | continue; |
74960c60 VP |
3178 | |
3179 | if (bpt->disposition == disp_del_at_next_stop) | |
3180 | continue; | |
a5606eee VP |
3181 | |
3182 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3183 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3184 | { |
3185 | some_failed = 1; | |
3186 | break; | |
3187 | } | |
3188 | if (some_failed) | |
3189 | { | |
3190 | for (loc = bpt->loc; loc; loc = loc->next) | |
3191 | if (loc->inserted) | |
3192 | remove_breakpoint (loc, mark_uninserted); | |
3193 | ||
3194 | hw_breakpoint_error = 1; | |
3195 | fprintf_unfiltered (tmp_error_stream, | |
3196 | "Could not insert hardware watchpoint %d.\n", | |
3197 | bpt->number); | |
eacd795a | 3198 | error_flag = -1; |
a5606eee VP |
3199 | } |
3200 | } | |
3201 | ||
eacd795a | 3202 | if (error_flag) |
81d0cc19 GS |
3203 | { |
3204 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3205 | message about possibly exhausted resources. */ | |
dd61ec5c | 3206 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3207 | { |
c6510018 MS |
3208 | fprintf_unfiltered (tmp_error_stream, |
3209 | "Could not insert hardware breakpoints:\n\ | |
3210 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3211 | } |
81d0cc19 GS |
3212 | target_terminal_ours_for_output (); |
3213 | error_stream (tmp_error_stream); | |
3214 | } | |
f7545552 TT |
3215 | |
3216 | do_cleanups (cleanups); | |
c906108c SS |
3217 | } |
3218 | ||
c30eee59 TJB |
3219 | /* Used when the program stops. |
3220 | Returns zero if successful, or non-zero if there was a problem | |
3221 | removing a breakpoint location. */ | |
3222 | ||
c906108c | 3223 | int |
fba45db2 | 3224 | remove_breakpoints (void) |
c906108c | 3225 | { |
35df4500 | 3226 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3227 | int val = 0; |
c906108c | 3228 | |
35df4500 | 3229 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3230 | { |
1e4d1764 | 3231 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3232 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3233 | } |
3a1bae8e | 3234 | return val; |
c906108c SS |
3235 | } |
3236 | ||
49fa26b0 PA |
3237 | /* When a thread exits, remove breakpoints that are related to |
3238 | that thread. */ | |
3239 | ||
3240 | static void | |
3241 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3242 | { | |
3243 | struct breakpoint *b, *b_tmp; | |
3244 | ||
3245 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3246 | { | |
96181529 | 3247 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3248 | { |
3249 | b->disposition = disp_del_at_next_stop; | |
3250 | ||
3251 | printf_filtered (_("\ | |
46ecd527 | 3252 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3253 | b->number, tp->num); |
3254 | ||
3255 | /* Hide it from the user. */ | |
3256 | b->number = 0; | |
3257 | } | |
3258 | } | |
3259 | } | |
3260 | ||
6c95b8df PA |
3261 | /* Remove breakpoints of process PID. */ |
3262 | ||
3263 | int | |
3264 | remove_breakpoints_pid (int pid) | |
3265 | { | |
35df4500 | 3266 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3267 | int val; |
3268 | struct inferior *inf = find_inferior_pid (pid); | |
3269 | ||
35df4500 | 3270 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3271 | { |
35df4500 | 3272 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3273 | continue; |
3274 | ||
fc126975 | 3275 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3276 | { |
35df4500 | 3277 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3278 | if (val != 0) |
3279 | return val; | |
3280 | } | |
3281 | } | |
3282 | return 0; | |
3283 | } | |
3284 | ||
c906108c | 3285 | int |
fba45db2 | 3286 | reattach_breakpoints (int pid) |
c906108c | 3287 | { |
6c95b8df | 3288 | struct cleanup *old_chain; |
35df4500 | 3289 | struct bp_location *bl, **blp_tmp; |
c906108c | 3290 | int val; |
86b887df | 3291 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3292 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3293 | struct inferior *inf; |
3294 | struct thread_info *tp; | |
3295 | ||
3296 | tp = any_live_thread_of_process (pid); | |
3297 | if (tp == NULL) | |
3298 | return 1; | |
3299 | ||
3300 | inf = find_inferior_pid (pid); | |
3301 | old_chain = save_inferior_ptid (); | |
3302 | ||
3303 | inferior_ptid = tp->ptid; | |
a4954f26 | 3304 | |
86b887df | 3305 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3306 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3307 | |
35df4500 | 3308 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3309 | { |
35df4500 | 3310 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3311 | continue; |
3312 | ||
35df4500 | 3313 | if (bl->inserted) |
c5aa993b | 3314 | { |
35df4500 | 3315 | bl->inserted = 0; |
dd61ec5c | 3316 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3317 | if (val != 0) |
3318 | { | |
ce696e05 | 3319 | do_cleanups (old_chain); |
c5aa993b JM |
3320 | return val; |
3321 | } | |
3322 | } | |
3323 | } | |
ce696e05 | 3324 | do_cleanups (old_chain); |
c906108c SS |
3325 | return 0; |
3326 | } | |
3327 | ||
e58b0e63 PA |
3328 | static int internal_breakpoint_number = -1; |
3329 | ||
84f4c1fe PM |
3330 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3331 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3332 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3333 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3334 | breakpoint_count and that value incremented. Internal breakpoints |
3335 | do not set the internal var bpnum. */ | |
3336 | static void | |
3337 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3338 | { | |
3339 | if (internal) | |
3340 | b->number = internal_breakpoint_number--; | |
3341 | else | |
3342 | { | |
3343 | set_breakpoint_count (breakpoint_count + 1); | |
3344 | b->number = breakpoint_count; | |
3345 | } | |
3346 | } | |
3347 | ||
e62c965a | 3348 | static struct breakpoint * |
a6d9a66e | 3349 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3350 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3351 | const struct breakpoint_ops *ops) |
e62c965a | 3352 | { |
e62c965a PP |
3353 | struct symtab_and_line sal; |
3354 | struct breakpoint *b; | |
3355 | ||
4a64f543 | 3356 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3357 | |
3358 | sal.pc = address; | |
3359 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3360 | sal.pspace = current_program_space; |
e62c965a | 3361 | |
06edf0c0 | 3362 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3363 | b->number = internal_breakpoint_number--; |
3364 | b->disposition = disp_donttouch; | |
3365 | ||
3366 | return b; | |
3367 | } | |
3368 | ||
17450429 PP |
3369 | static const char *const longjmp_names[] = |
3370 | { | |
3371 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3372 | }; | |
3373 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3374 | ||
3375 | /* Per-objfile data private to breakpoint.c. */ | |
3376 | struct breakpoint_objfile_data | |
3377 | { | |
3378 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3379 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3380 | |
3381 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3382 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3383 | |
28106bc2 SDJ |
3384 | /* True if we have looked for longjmp probes. */ |
3385 | int longjmp_searched; | |
3386 | ||
3387 | /* SystemTap probe points for longjmp (if any). */ | |
3388 | VEC (probe_p) *longjmp_probes; | |
3389 | ||
17450429 | 3390 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3391 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3392 | |
3393 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3394 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3395 | |
3396 | /* True if we have looked for exception probes. */ | |
3397 | int exception_searched; | |
3398 | ||
3399 | /* SystemTap probe points for unwinding (if any). */ | |
3400 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3401 | }; |
3402 | ||
3403 | static const struct objfile_data *breakpoint_objfile_key; | |
3404 | ||
3405 | /* Minimal symbol not found sentinel. */ | |
3406 | static struct minimal_symbol msym_not_found; | |
3407 | ||
3408 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3409 | ||
3410 | static int | |
3411 | msym_not_found_p (const struct minimal_symbol *msym) | |
3412 | { | |
3413 | return msym == &msym_not_found; | |
3414 | } | |
3415 | ||
3416 | /* Return per-objfile data needed by breakpoint.c. | |
3417 | Allocate the data if necessary. */ | |
3418 | ||
3419 | static struct breakpoint_objfile_data * | |
3420 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3421 | { | |
3422 | struct breakpoint_objfile_data *bp_objfile_data; | |
3423 | ||
9a3c8263 SM |
3424 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3425 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3426 | if (bp_objfile_data == NULL) |
3427 | { | |
8d749320 SM |
3428 | bp_objfile_data = |
3429 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3430 | |
3431 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3432 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3433 | } | |
3434 | return bp_objfile_data; | |
3435 | } | |
3436 | ||
28106bc2 SDJ |
3437 | static void |
3438 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3439 | { | |
9a3c8263 SM |
3440 | struct breakpoint_objfile_data *bp_objfile_data |
3441 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3442 | |
3443 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3444 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3445 | } | |
3446 | ||
e62c965a | 3447 | static void |
af02033e | 3448 | create_overlay_event_breakpoint (void) |
e62c965a | 3449 | { |
69de3c6a | 3450 | struct objfile *objfile; |
af02033e | 3451 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3452 | |
69de3c6a PP |
3453 | ALL_OBJFILES (objfile) |
3454 | { | |
3455 | struct breakpoint *b; | |
17450429 PP |
3456 | struct breakpoint_objfile_data *bp_objfile_data; |
3457 | CORE_ADDR addr; | |
67994074 | 3458 | struct explicit_location explicit_loc; |
69de3c6a | 3459 | |
17450429 PP |
3460 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3461 | ||
3b7344d5 | 3462 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3463 | continue; |
3464 | ||
3b7344d5 | 3465 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3466 | { |
3b7344d5 | 3467 | struct bound_minimal_symbol m; |
17450429 PP |
3468 | |
3469 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3470 | if (m.minsym == NULL) |
17450429 PP |
3471 | { |
3472 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3473 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3474 | continue; |
3475 | } | |
3476 | bp_objfile_data->overlay_msym = m; | |
3477 | } | |
e62c965a | 3478 | |
77e371c0 | 3479 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3480 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3481 | bp_overlay_event, |
3482 | &internal_breakpoint_ops); | |
67994074 KS |
3483 | initialize_explicit_location (&explicit_loc); |
3484 | explicit_loc.function_name = ASTRDUP (func_name); | |
3485 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3486 | |
69de3c6a PP |
3487 | if (overlay_debugging == ovly_auto) |
3488 | { | |
3489 | b->enable_state = bp_enabled; | |
3490 | overlay_events_enabled = 1; | |
3491 | } | |
3492 | else | |
3493 | { | |
3494 | b->enable_state = bp_disabled; | |
3495 | overlay_events_enabled = 0; | |
3496 | } | |
e62c965a | 3497 | } |
44702360 | 3498 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3499 | } |
3500 | ||
0fd8e87f | 3501 | static void |
af02033e | 3502 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3503 | { |
6c95b8df | 3504 | struct program_space *pspace; |
6c95b8df PA |
3505 | struct cleanup *old_chain; |
3506 | ||
3507 | old_chain = save_current_program_space (); | |
0fd8e87f | 3508 | |
6c95b8df | 3509 | ALL_PSPACES (pspace) |
af02033e PP |
3510 | { |
3511 | struct objfile *objfile; | |
3512 | ||
3513 | set_current_program_space (pspace); | |
3514 | ||
3515 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3516 | { |
af02033e PP |
3517 | int i; |
3518 | struct gdbarch *gdbarch; | |
17450429 | 3519 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3520 | |
af02033e | 3521 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3522 | |
17450429 PP |
3523 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3524 | ||
28106bc2 SDJ |
3525 | if (!bp_objfile_data->longjmp_searched) |
3526 | { | |
25f9533e SDJ |
3527 | VEC (probe_p) *ret; |
3528 | ||
3529 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3530 | if (ret != NULL) | |
3531 | { | |
3532 | /* We are only interested in checking one element. */ | |
3533 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3534 | ||
3535 | if (!can_evaluate_probe_arguments (p)) | |
3536 | { | |
3537 | /* We cannot use the probe interface here, because it does | |
3538 | not know how to evaluate arguments. */ | |
3539 | VEC_free (probe_p, ret); | |
3540 | ret = NULL; | |
3541 | } | |
3542 | } | |
3543 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3544 | bp_objfile_data->longjmp_searched = 1; |
3545 | } | |
3546 | ||
3547 | if (bp_objfile_data->longjmp_probes != NULL) | |
3548 | { | |
3549 | int i; | |
3550 | struct probe *probe; | |
3551 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3552 | ||
3553 | for (i = 0; | |
3554 | VEC_iterate (probe_p, | |
3555 | bp_objfile_data->longjmp_probes, | |
3556 | i, probe); | |
3557 | ++i) | |
3558 | { | |
3559 | struct breakpoint *b; | |
3560 | ||
729662a5 TT |
3561 | b = create_internal_breakpoint (gdbarch, |
3562 | get_probe_address (probe, | |
3563 | objfile), | |
28106bc2 SDJ |
3564 | bp_longjmp_master, |
3565 | &internal_breakpoint_ops); | |
5b56227b KS |
3566 | b->location |
3567 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3568 | b->enable_state = bp_disabled; |
3569 | } | |
3570 | ||
3571 | continue; | |
3572 | } | |
3573 | ||
0569175e TSD |
3574 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3575 | continue; | |
3576 | ||
17450429 | 3577 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3578 | { |
3579 | struct breakpoint *b; | |
af02033e | 3580 | const char *func_name; |
17450429 | 3581 | CORE_ADDR addr; |
67994074 | 3582 | struct explicit_location explicit_loc; |
6c95b8df | 3583 | |
3b7344d5 | 3584 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3585 | continue; |
0fd8e87f | 3586 | |
17450429 | 3587 | func_name = longjmp_names[i]; |
3b7344d5 | 3588 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3589 | { |
3b7344d5 | 3590 | struct bound_minimal_symbol m; |
17450429 PP |
3591 | |
3592 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3593 | if (m.minsym == NULL) |
17450429 PP |
3594 | { |
3595 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3596 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3597 | continue; |
3598 | } | |
3599 | bp_objfile_data->longjmp_msym[i] = m; | |
3600 | } | |
3601 | ||
77e371c0 | 3602 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3603 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3604 | &internal_breakpoint_ops); | |
67994074 KS |
3605 | initialize_explicit_location (&explicit_loc); |
3606 | explicit_loc.function_name = ASTRDUP (func_name); | |
3607 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3608 | b->enable_state = bp_disabled; |
3609 | } | |
0fd8e87f | 3610 | } |
af02033e | 3611 | } |
44702360 | 3612 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3613 | |
3614 | do_cleanups (old_chain); | |
0fd8e87f UW |
3615 | } |
3616 | ||
af02033e | 3617 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3618 | static void |
af02033e | 3619 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3620 | { |
3621 | struct program_space *pspace; | |
aa7d318d | 3622 | struct cleanup *old_chain; |
af02033e | 3623 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3624 | |
3625 | old_chain = save_current_program_space (); | |
3626 | ||
3627 | ALL_PSPACES (pspace) | |
17450429 PP |
3628 | { |
3629 | struct objfile *objfile; | |
3630 | CORE_ADDR addr; | |
3631 | ||
3632 | set_current_program_space (pspace); | |
3633 | ||
aa7d318d TT |
3634 | ALL_OBJFILES (objfile) |
3635 | { | |
3636 | struct breakpoint *b; | |
17450429 | 3637 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3638 | struct explicit_location explicit_loc; |
aa7d318d | 3639 | |
17450429 | 3640 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3641 | |
3b7344d5 | 3642 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3643 | continue; |
3644 | ||
3b7344d5 | 3645 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3646 | { |
3b7344d5 | 3647 | struct bound_minimal_symbol m; |
17450429 PP |
3648 | |
3649 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3650 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3651 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3652 | { |
3653 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3654 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3655 | continue; |
3656 | } | |
3657 | bp_objfile_data->terminate_msym = m; | |
3658 | } | |
aa7d318d | 3659 | |
77e371c0 | 3660 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3661 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3662 | bp_std_terminate_master, |
3663 | &internal_breakpoint_ops); | |
67994074 KS |
3664 | initialize_explicit_location (&explicit_loc); |
3665 | explicit_loc.function_name = ASTRDUP (func_name); | |
3666 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3667 | b->enable_state = bp_disabled; |
3668 | } | |
17450429 PP |
3669 | } |
3670 | ||
44702360 | 3671 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3672 | |
3673 | do_cleanups (old_chain); | |
3674 | } | |
3675 | ||
186c406b TT |
3676 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3677 | ||
70221824 | 3678 | static void |
186c406b TT |
3679 | create_exception_master_breakpoint (void) |
3680 | { | |
3681 | struct objfile *objfile; | |
17450429 | 3682 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3683 | |
3684 | ALL_OBJFILES (objfile) | |
3685 | { | |
17450429 PP |
3686 | struct breakpoint *b; |
3687 | struct gdbarch *gdbarch; | |
3688 | struct breakpoint_objfile_data *bp_objfile_data; | |
3689 | CORE_ADDR addr; | |
67994074 | 3690 | struct explicit_location explicit_loc; |
17450429 PP |
3691 | |
3692 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3693 | ||
28106bc2 SDJ |
3694 | /* We prefer the SystemTap probe point if it exists. */ |
3695 | if (!bp_objfile_data->exception_searched) | |
3696 | { | |
25f9533e SDJ |
3697 | VEC (probe_p) *ret; |
3698 | ||
3699 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3700 | ||
3701 | if (ret != NULL) | |
3702 | { | |
3703 | /* We are only interested in checking one element. */ | |
3704 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3705 | ||
3706 | if (!can_evaluate_probe_arguments (p)) | |
3707 | { | |
3708 | /* We cannot use the probe interface here, because it does | |
3709 | not know how to evaluate arguments. */ | |
3710 | VEC_free (probe_p, ret); | |
3711 | ret = NULL; | |
3712 | } | |
3713 | } | |
3714 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3715 | bp_objfile_data->exception_searched = 1; |
3716 | } | |
3717 | ||
3718 | if (bp_objfile_data->exception_probes != NULL) | |
3719 | { | |
3720 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3721 | int i; | |
3722 | struct probe *probe; | |
3723 | ||
3724 | for (i = 0; | |
3725 | VEC_iterate (probe_p, | |
3726 | bp_objfile_data->exception_probes, | |
3727 | i, probe); | |
3728 | ++i) | |
3729 | { | |
3730 | struct breakpoint *b; | |
3731 | ||
729662a5 TT |
3732 | b = create_internal_breakpoint (gdbarch, |
3733 | get_probe_address (probe, | |
3734 | objfile), | |
28106bc2 SDJ |
3735 | bp_exception_master, |
3736 | &internal_breakpoint_ops); | |
5b56227b KS |
3737 | b->location |
3738 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3739 | b->enable_state = bp_disabled; |
3740 | } | |
3741 | ||
3742 | continue; | |
3743 | } | |
3744 | ||
3745 | /* Otherwise, try the hook function. */ | |
3746 | ||
3b7344d5 | 3747 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3748 | continue; |
3749 | ||
3750 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3751 | |
3b7344d5 | 3752 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3753 | { |
3b7344d5 | 3754 | struct bound_minimal_symbol debug_hook; |
186c406b | 3755 | |
17450429 | 3756 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3757 | if (debug_hook.minsym == NULL) |
17450429 | 3758 | { |
3b7344d5 | 3759 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3760 | continue; |
3761 | } | |
3762 | ||
3763 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3764 | } |
17450429 | 3765 | |
77e371c0 | 3766 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3767 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3768 | ¤t_target); | |
06edf0c0 PA |
3769 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3770 | &internal_breakpoint_ops); | |
67994074 KS |
3771 | initialize_explicit_location (&explicit_loc); |
3772 | explicit_loc.function_name = ASTRDUP (func_name); | |
3773 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3774 | b->enable_state = bp_disabled; |
186c406b TT |
3775 | } |
3776 | ||
44702360 | 3777 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3778 | } |
3779 | ||
c906108c | 3780 | void |
fba45db2 | 3781 | update_breakpoints_after_exec (void) |
c906108c | 3782 | { |
35df4500 | 3783 | struct breakpoint *b, *b_tmp; |
876fa593 | 3784 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3785 | |
25b22b0a PA |
3786 | /* We're about to delete breakpoints from GDB's lists. If the |
3787 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3788 | writing the breakpoints' "shadow contents" back into memory. The | |
3789 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3790 | do that. Instead, the target is responsible from marking | |
3791 | breakpoints out as soon as it detects an exec. We don't do that | |
3792 | here instead, because there may be other attempts to delete | |
3793 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3794 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3795 | if (bploc->pspace == current_program_space) |
3796 | gdb_assert (!bploc->inserted); | |
c906108c | 3797 | |
35df4500 | 3798 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3799 | { |
6c95b8df PA |
3800 | if (b->pspace != current_program_space) |
3801 | continue; | |
3802 | ||
4a64f543 | 3803 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3804 | if (b->type == bp_shlib_event) |
3805 | { | |
3806 | delete_breakpoint (b); | |
3807 | continue; | |
3808 | } | |
c906108c | 3809 | |
4a64f543 | 3810 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3811 | if (b->type == bp_jit_event) |
3812 | { | |
3813 | delete_breakpoint (b); | |
3814 | continue; | |
3815 | } | |
3816 | ||
1900040c | 3817 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3818 | as must overlay event and longjmp master breakpoints. */ |
3819 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3820 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3821 | || b->type == bp_exception_master) | |
c4093a6a JM |
3822 | { |
3823 | delete_breakpoint (b); | |
3824 | continue; | |
3825 | } | |
3826 | ||
4a64f543 | 3827 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3828 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3829 | { |
3830 | delete_breakpoint (b); | |
3831 | continue; | |
3832 | } | |
3833 | ||
7c16b83e PA |
3834 | /* Just like single-step breakpoints. */ |
3835 | if (b->type == bp_single_step) | |
3836 | { | |
3837 | delete_breakpoint (b); | |
3838 | continue; | |
3839 | } | |
3840 | ||
611c83ae PA |
3841 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3842 | after an exec. */ | |
186c406b | 3843 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3844 | || b->type == bp_longjmp_call_dummy |
186c406b | 3845 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3846 | { |
3847 | delete_breakpoint (b); | |
3848 | continue; | |
3849 | } | |
3850 | ||
ce78b96d JB |
3851 | if (b->type == bp_catchpoint) |
3852 | { | |
3853 | /* For now, none of the bp_catchpoint breakpoints need to | |
3854 | do anything at this point. In the future, if some of | |
3855 | the catchpoints need to something, we will need to add | |
3856 | a new method, and call this method from here. */ | |
3857 | continue; | |
3858 | } | |
3859 | ||
c5aa993b JM |
3860 | /* bp_finish is a special case. The only way we ought to be able |
3861 | to see one of these when an exec() has happened, is if the user | |
3862 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3863 | carries them to the call-site of the current callee, by setting | |
3864 | a temporary bp there and resuming. But in this case, the finish | |
3865 | will carry them entirely through the vfork & exec. | |
3866 | ||
3867 | We don't want to allow a bp_finish to remain inserted now. But | |
3868 | we can't safely delete it, 'cause finish_command has a handle to | |
3869 | the bp on a bpstat, and will later want to delete it. There's a | |
3870 | chance (and I've seen it happen) that if we delete the bp_finish | |
3871 | here, that its storage will get reused by the time finish_command | |
3872 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3873 | We really must allow finish_command to delete a bp_finish. | |
3874 | ||
e5dd4106 | 3875 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3876 | it's safe to delete something others may have handles to?" |
3877 | problem, what we'll do here is just uninsert the bp_finish, and | |
3878 | let finish_command delete it. | |
3879 | ||
3880 | (We know the bp_finish is "doomed" in the sense that it's | |
3881 | momentary, and will be deleted as soon as finish_command sees | |
3882 | the inferior stopped. So it doesn't matter that the bp's | |
3883 | address is probably bogus in the new a.out, unlike e.g., the | |
3884 | solib breakpoints.) */ | |
c5aa993b | 3885 | |
c5aa993b JM |
3886 | if (b->type == bp_finish) |
3887 | { | |
3888 | continue; | |
3889 | } | |
3890 | ||
3891 | /* Without a symbolic address, we have little hope of the | |
3892 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3893 | a.out. */ |
f00aae0f | 3894 | if (event_location_empty_p (b->location)) |
c5aa993b JM |
3895 | { |
3896 | delete_breakpoint (b); | |
3897 | continue; | |
3898 | } | |
c5aa993b | 3899 | } |
c906108c SS |
3900 | } |
3901 | ||
3902 | int | |
d80ee84f | 3903 | detach_breakpoints (ptid_t ptid) |
c906108c | 3904 | { |
35df4500 | 3905 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3906 | int val = 0; |
ce696e05 | 3907 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3908 | struct inferior *inf = current_inferior (); |
c5aa993b | 3909 | |
dfd4cc63 | 3910 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3911 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3912 | |
6c95b8df | 3913 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3914 | inferior_ptid = ptid; |
35df4500 | 3915 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3916 | { |
35df4500 | 3917 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3918 | continue; |
3919 | ||
bd9673a4 PW |
3920 | /* This function must physically remove breakpoints locations |
3921 | from the specified ptid, without modifying the breakpoint | |
3922 | package's state. Locations of type bp_loc_other are only | |
3923 | maintained at GDB side. So, there is no need to remove | |
3924 | these bp_loc_other locations. Moreover, removing these | |
3925 | would modify the breakpoint package's state. */ | |
3926 | if (bl->loc_type == bp_loc_other) | |
3927 | continue; | |
3928 | ||
35df4500 TJB |
3929 | if (bl->inserted) |
3930 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3931 | } |
d03285ec | 3932 | |
ce696e05 | 3933 | do_cleanups (old_chain); |
3a1bae8e | 3934 | return val; |
c906108c SS |
3935 | } |
3936 | ||
35df4500 | 3937 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3938 | Note that this is used to detach breakpoints from a child fork. |
3939 | When we get here, the child isn't in the inferior list, and neither | |
3940 | do we have objects to represent its address space --- we should | |
35df4500 | 3941 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3942 | |
c906108c | 3943 | static int |
35df4500 | 3944 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3945 | { |
3946 | int val; | |
c5aa993b | 3947 | |
35df4500 TJB |
3948 | /* BL is never in moribund_locations by our callers. */ |
3949 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3950 | |
74960c60 VP |
3951 | /* The type of none suggests that owner is actually deleted. |
3952 | This should not ever happen. */ | |
35df4500 | 3953 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3954 | |
35df4500 TJB |
3955 | if (bl->loc_type == bp_loc_software_breakpoint |
3956 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3957 | { |
c02f5703 MS |
3958 | /* "Normal" instruction breakpoint: either the standard |
3959 | trap-instruction bp (bp_breakpoint), or a | |
3960 | bp_hardware_breakpoint. */ | |
3961 | ||
3962 | /* First check to see if we have to handle an overlay. */ | |
3963 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3964 | || bl->section == NULL |
3965 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3966 | { |
3967 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3968 | |
3969 | /* If we're trying to uninsert a memory breakpoint that we | |
3970 | know is set in a dynamic object that is marked | |
3971 | shlib_disabled, then either the dynamic object was | |
3972 | removed with "remove-symbol-file" or with | |
3973 | "nosharedlibrary". In the former case, we don't know | |
3974 | whether another dynamic object might have loaded over the | |
3975 | breakpoint's address -- the user might well let us know | |
3976 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3977 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3978 | list of dynamically loaded objects). If we have the |
3979 | breakpoint's shadow memory, that is, this is a software | |
3980 | breakpoint managed by GDB, check whether the breakpoint | |
3981 | is still inserted in memory, to avoid overwriting wrong | |
3982 | code with stale saved shadow contents. Note that HW | |
3983 | breakpoints don't have shadow memory, as they're | |
3984 | implemented using a mechanism that is not dependent on | |
3985 | being able to modify the target's memory, and as such | |
3986 | they should always be removed. */ | |
3987 | if (bl->shlib_disabled | |
3988 | && bl->target_info.shadow_len != 0 | |
3989 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3990 | val = 0; | |
3991 | else | |
3992 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3993 | } |
c906108c SS |
3994 | else |
3995 | { | |
4a64f543 | 3996 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3997 | Did we set a breakpoint at the LMA? */ |
3998 | if (!overlay_events_enabled) | |
3999 | { | |
4000 | /* Yes -- overlay event support is not active, so we | |
4001 | should have set a breakpoint at the LMA. Remove it. | |
4002 | */ | |
c02f5703 MS |
4003 | /* Ignore any failures: if the LMA is in ROM, we will |
4004 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4005 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4006 | target_remove_hw_breakpoint (bl->gdbarch, | |
4007 | &bl->overlay_target_info); | |
c02f5703 | 4008 | else |
35df4500 TJB |
4009 | target_remove_breakpoint (bl->gdbarch, |
4010 | &bl->overlay_target_info); | |
c02f5703 MS |
4011 | } |
4012 | /* Did we set a breakpoint at the VMA? | |
4013 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4014 | if (bl->inserted) |
c906108c | 4015 | { |
c02f5703 MS |
4016 | /* Yes -- remove it. Previously we did not bother to |
4017 | remove the breakpoint if the section had been | |
4018 | unmapped, but let's not rely on that being safe. We | |
4019 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4020 | |
4021 | /* However, we should remove *software* breakpoints only | |
4022 | if the section is still mapped, or else we overwrite | |
4023 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4024 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4025 | || section_is_mapped (bl->section)) | |
4026 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
4027 | else |
4028 | val = 0; | |
c906108c | 4029 | } |
c02f5703 MS |
4030 | else |
4031 | { | |
4032 | /* No -- not inserted, so no need to remove. No error. */ | |
4033 | val = 0; | |
4034 | } | |
c906108c | 4035 | } |
879d1e6b | 4036 | |
08351840 PA |
4037 | /* In some cases, we might not be able to remove a breakpoint in |
4038 | a shared library that has already been removed, but we have | |
4039 | not yet processed the shlib unload event. Similarly for an | |
4040 | unloaded add-symbol-file object - the user might not yet have | |
4041 | had the chance to remove-symbol-file it. shlib_disabled will | |
4042 | be set if the library/object has already been removed, but | |
4043 | the breakpoint hasn't been uninserted yet, e.g., after | |
4044 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4045 | always-inserted mode. */ | |
076855f9 | 4046 | if (val |
08351840 PA |
4047 | && (bl->loc_type == bp_loc_software_breakpoint |
4048 | && (bl->shlib_disabled | |
4049 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4050 | || shared_objfile_contains_address_p (bl->pspace, |
4051 | bl->address)))) | |
879d1e6b UW |
4052 | val = 0; |
4053 | ||
c906108c SS |
4054 | if (val) |
4055 | return val; | |
35df4500 | 4056 | bl->inserted = (is == mark_inserted); |
c906108c | 4057 | } |
35df4500 | 4058 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4059 | { |
77b06cd7 TJB |
4060 | gdb_assert (bl->owner->ops != NULL |
4061 | && bl->owner->ops->remove_location != NULL); | |
4062 | ||
35df4500 | 4063 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4064 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4065 | |
c906108c | 4066 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4067 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4068 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4069 | bl->owner->number); |
c906108c | 4070 | } |
35df4500 TJB |
4071 | else if (bl->owner->type == bp_catchpoint |
4072 | && breakpoint_enabled (bl->owner) | |
4073 | && !bl->duplicate) | |
ce78b96d | 4074 | { |
77b06cd7 TJB |
4075 | gdb_assert (bl->owner->ops != NULL |
4076 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4077 | |
77b06cd7 | 4078 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4079 | if (val) |
4080 | return val; | |
77b06cd7 | 4081 | |
35df4500 | 4082 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4083 | } |
c906108c SS |
4084 | |
4085 | return 0; | |
4086 | } | |
4087 | ||
6c95b8df | 4088 | static int |
35df4500 | 4089 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4090 | { |
4091 | int ret; | |
4092 | struct cleanup *old_chain; | |
4093 | ||
35df4500 TJB |
4094 | /* BL is never in moribund_locations by our callers. */ |
4095 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4096 | |
6c95b8df PA |
4097 | /* The type of none suggests that owner is actually deleted. |
4098 | This should not ever happen. */ | |
35df4500 | 4099 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4100 | |
4101 | old_chain = save_current_space_and_thread (); | |
4102 | ||
35df4500 | 4103 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4104 | |
35df4500 | 4105 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4106 | |
4107 | do_cleanups (old_chain); | |
4108 | return ret; | |
4109 | } | |
4110 | ||
c906108c SS |
4111 | /* Clear the "inserted" flag in all breakpoints. */ |
4112 | ||
25b22b0a | 4113 | void |
fba45db2 | 4114 | mark_breakpoints_out (void) |
c906108c | 4115 | { |
35df4500 | 4116 | struct bp_location *bl, **blp_tmp; |
c906108c | 4117 | |
35df4500 | 4118 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4119 | if (bl->pspace == current_program_space) |
35df4500 | 4120 | bl->inserted = 0; |
c906108c SS |
4121 | } |
4122 | ||
53a5351d JM |
4123 | /* Clear the "inserted" flag in all breakpoints and delete any |
4124 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4125 | |
4126 | Plus other such housekeeping that has to be done for breakpoints | |
4127 | between runs. | |
4128 | ||
53a5351d JM |
4129 | Note: this function gets called at the end of a run (by |
4130 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4131 | init_wait_for_inferior). */ |
c906108c SS |
4132 | |
4133 | ||
4134 | ||
4135 | void | |
fba45db2 | 4136 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4137 | { |
35df4500 TJB |
4138 | struct breakpoint *b, *b_tmp; |
4139 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4140 | int ix; |
6c95b8df | 4141 | struct program_space *pspace = current_program_space; |
c906108c | 4142 | |
50c71eaf PA |
4143 | /* If breakpoint locations are shared across processes, then there's |
4144 | nothing to do. */ | |
f5656ead | 4145 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4146 | return; |
4147 | ||
1a853c52 | 4148 | mark_breakpoints_out (); |
075f6582 | 4149 | |
35df4500 | 4150 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4151 | { |
6c95b8df PA |
4152 | if (b->loc && b->loc->pspace != pspace) |
4153 | continue; | |
4154 | ||
c5aa993b JM |
4155 | switch (b->type) |
4156 | { | |
4157 | case bp_call_dummy: | |
e2e4d78b | 4158 | case bp_longjmp_call_dummy: |
c906108c | 4159 | |
c5aa993b | 4160 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4161 | cause problems when the inferior is rerun, so we better get |
4162 | rid of it. */ | |
4163 | ||
4164 | case bp_watchpoint_scope: | |
4165 | ||
4166 | /* Also get rid of scope breakpoints. */ | |
4167 | ||
4168 | case bp_shlib_event: | |
4169 | ||
4170 | /* Also remove solib event breakpoints. Their addresses may | |
4171 | have changed since the last time we ran the program. | |
4172 | Actually we may now be debugging against different target; | |
4173 | and so the solib backend that installed this breakpoint may | |
4174 | not be used in by the target. E.g., | |
4175 | ||
4176 | (gdb) file prog-linux | |
4177 | (gdb) run # native linux target | |
4178 | ... | |
4179 | (gdb) kill | |
4180 | (gdb) file prog-win.exe | |
4181 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4182 | */ | |
c906108c | 4183 | |
f59f708a PA |
4184 | case bp_step_resume: |
4185 | ||
4186 | /* Also remove step-resume breakpoints. */ | |
4187 | ||
7c16b83e PA |
4188 | case bp_single_step: |
4189 | ||
4190 | /* Also remove single-step breakpoints. */ | |
4191 | ||
c5aa993b JM |
4192 | delete_breakpoint (b); |
4193 | break; | |
c906108c | 4194 | |
c5aa993b JM |
4195 | case bp_watchpoint: |
4196 | case bp_hardware_watchpoint: | |
4197 | case bp_read_watchpoint: | |
4198 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4199 | { |
4200 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4201 | |
3a5c3e22 PA |
4202 | /* Likewise for watchpoints on local expressions. */ |
4203 | if (w->exp_valid_block != NULL) | |
4204 | delete_breakpoint (b); | |
4205 | else if (context == inf_starting) | |
4206 | { | |
4207 | /* Reset val field to force reread of starting value in | |
4208 | insert_breakpoints. */ | |
4209 | if (w->val) | |
4210 | value_free (w->val); | |
4211 | w->val = NULL; | |
4212 | w->val_valid = 0; | |
c860120c | 4213 | } |
3a5c3e22 | 4214 | } |
c5aa993b JM |
4215 | break; |
4216 | default: | |
c5aa993b JM |
4217 | break; |
4218 | } | |
4219 | } | |
1c5cfe86 PA |
4220 | |
4221 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4222 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4223 | decref_bp_location (&bl); | |
1c5cfe86 | 4224 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4225 | } |
4226 | ||
6c95b8df PA |
4227 | /* These functions concern about actual breakpoints inserted in the |
4228 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4229 | we need to hop over the bkpt --- so we check for address space | |
4230 | match, not program space. */ | |
4231 | ||
c2c6d25f JM |
4232 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4233 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4234 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4235 | permanent breakpoint. | |
4236 | - When continuing from a location with an ordinary breakpoint, we | |
4237 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4238 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4239 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4240 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4241 | |
c2c6d25f | 4242 | enum breakpoint_here |
6c95b8df | 4243 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4244 | { |
35df4500 | 4245 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4246 | int any_breakpoint_here = 0; |
c906108c | 4247 | |
35df4500 | 4248 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4249 | { |
35df4500 TJB |
4250 | if (bl->loc_type != bp_loc_software_breakpoint |
4251 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4252 | continue; |
4253 | ||
f1310107 | 4254 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4255 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4256 | || bl->permanent) |
f1310107 | 4257 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4258 | { |
4259 | if (overlay_debugging | |
35df4500 TJB |
4260 | && section_is_overlay (bl->section) |
4261 | && !section_is_mapped (bl->section)) | |
075f6582 | 4262 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4263 | else if (bl->permanent) |
075f6582 DJ |
4264 | return permanent_breakpoint_here; |
4265 | else | |
4266 | any_breakpoint_here = 1; | |
4267 | } | |
4268 | } | |
c906108c | 4269 | |
f486487f | 4270 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4271 | } |
4272 | ||
d35ae833 PA |
4273 | /* See breakpoint.h. */ |
4274 | ||
4275 | int | |
4276 | breakpoint_in_range_p (struct address_space *aspace, | |
4277 | CORE_ADDR addr, ULONGEST len) | |
4278 | { | |
4279 | struct bp_location *bl, **blp_tmp; | |
4280 | ||
4281 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4282 | { | |
4283 | if (bl->loc_type != bp_loc_software_breakpoint | |
4284 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4285 | continue; | |
4286 | ||
4287 | if ((breakpoint_enabled (bl->owner) | |
4288 | || bl->permanent) | |
4289 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4290 | addr, len)) | |
4291 | { | |
4292 | if (overlay_debugging | |
4293 | && section_is_overlay (bl->section) | |
4294 | && !section_is_mapped (bl->section)) | |
4295 | { | |
4296 | /* Unmapped overlay -- can't be a match. */ | |
4297 | continue; | |
4298 | } | |
4299 | ||
4300 | return 1; | |
4301 | } | |
4302 | } | |
4303 | ||
4304 | return 0; | |
4305 | } | |
4306 | ||
1c5cfe86 PA |
4307 | /* Return true if there's a moribund breakpoint at PC. */ |
4308 | ||
4309 | int | |
6c95b8df | 4310 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4311 | { |
4312 | struct bp_location *loc; | |
4313 | int ix; | |
4314 | ||
4315 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4316 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4317 | return 1; |
4318 | ||
4319 | return 0; | |
4320 | } | |
c2c6d25f | 4321 | |
f7ce857f PA |
4322 | /* Returns non-zero iff BL is inserted at PC, in address space |
4323 | ASPACE. */ | |
4324 | ||
4325 | static int | |
4326 | bp_location_inserted_here_p (struct bp_location *bl, | |
4327 | struct address_space *aspace, CORE_ADDR pc) | |
4328 | { | |
4329 | if (bl->inserted | |
4330 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4331 | aspace, pc)) | |
4332 | { | |
4333 | if (overlay_debugging | |
4334 | && section_is_overlay (bl->section) | |
4335 | && !section_is_mapped (bl->section)) | |
4336 | return 0; /* unmapped overlay -- can't be a match */ | |
4337 | else | |
4338 | return 1; | |
4339 | } | |
4340 | return 0; | |
4341 | } | |
4342 | ||
a1fd2fa5 | 4343 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4344 | |
4345 | int | |
a1fd2fa5 | 4346 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4347 | { |
f7ce857f PA |
4348 | struct bp_location **blp, **blp_tmp = NULL; |
4349 | struct bp_location *bl; | |
c906108c | 4350 | |
f7ce857f | 4351 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4352 | { |
f7ce857f PA |
4353 | struct bp_location *bl = *blp; |
4354 | ||
35df4500 TJB |
4355 | if (bl->loc_type != bp_loc_software_breakpoint |
4356 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4357 | continue; |
4358 | ||
f7ce857f PA |
4359 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4360 | return 1; | |
c5aa993b | 4361 | } |
c36b740a VP |
4362 | return 0; |
4363 | } | |
4364 | ||
a1fd2fa5 PA |
4365 | /* This function returns non-zero iff there is a software breakpoint |
4366 | inserted at PC. */ | |
c36b740a VP |
4367 | |
4368 | int | |
a1fd2fa5 PA |
4369 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4370 | CORE_ADDR pc) | |
4fa8626c | 4371 | { |
f7ce857f PA |
4372 | struct bp_location **blp, **blp_tmp = NULL; |
4373 | struct bp_location *bl; | |
4fa8626c | 4374 | |
f7ce857f | 4375 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4376 | { |
f7ce857f PA |
4377 | struct bp_location *bl = *blp; |
4378 | ||
35df4500 | 4379 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4380 | continue; |
4381 | ||
f7ce857f PA |
4382 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4383 | return 1; | |
4fa8626c DJ |
4384 | } |
4385 | ||
4386 | return 0; | |
9c02b525 PA |
4387 | } |
4388 | ||
4389 | /* See breakpoint.h. */ | |
4390 | ||
4391 | int | |
4392 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4393 | CORE_ADDR pc) | |
4394 | { | |
4395 | struct bp_location **blp, **blp_tmp = NULL; | |
4396 | struct bp_location *bl; | |
4397 | ||
4398 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4399 | { | |
4400 | struct bp_location *bl = *blp; | |
4401 | ||
4402 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4403 | continue; | |
4404 | ||
4405 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4406 | return 1; | |
4407 | } | |
4408 | ||
4409 | return 0; | |
4fa8626c DJ |
4410 | } |
4411 | ||
9093389c PA |
4412 | int |
4413 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4414 | CORE_ADDR addr, ULONGEST len) | |
4415 | { | |
4416 | struct breakpoint *bpt; | |
4417 | ||
4418 | ALL_BREAKPOINTS (bpt) | |
4419 | { | |
4420 | struct bp_location *loc; | |
4421 | ||
4422 | if (bpt->type != bp_hardware_watchpoint | |
4423 | && bpt->type != bp_access_watchpoint) | |
4424 | continue; | |
4425 | ||
4426 | if (!breakpoint_enabled (bpt)) | |
4427 | continue; | |
4428 | ||
4429 | for (loc = bpt->loc; loc; loc = loc->next) | |
4430 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4431 | { | |
4432 | CORE_ADDR l, h; | |
4433 | ||
4434 | /* Check for intersection. */ | |
4435 | l = max (loc->address, addr); | |
4436 | h = min (loc->address + loc->length, addr + len); | |
4437 | if (l < h) | |
4438 | return 1; | |
4439 | } | |
4440 | } | |
4441 | return 0; | |
4442 | } | |
c906108c | 4443 | \f |
c5aa993b | 4444 | |
c906108c SS |
4445 | /* bpstat stuff. External routines' interfaces are documented |
4446 | in breakpoint.h. */ | |
4447 | ||
4448 | int | |
c326b90e | 4449 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4450 | { |
533be4dd | 4451 | return (ep->type == bp_catchpoint); |
c906108c SS |
4452 | } |
4453 | ||
f431efe5 PA |
4454 | /* Frees any storage that is part of a bpstat. Does not walk the |
4455 | 'next' chain. */ | |
4456 | ||
4457 | static void | |
198757a8 VP |
4458 | bpstat_free (bpstat bs) |
4459 | { | |
4460 | if (bs->old_val != NULL) | |
4461 | value_free (bs->old_val); | |
9add0f1b | 4462 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4463 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4464 | xfree (bs); |
4465 | } | |
4466 | ||
c906108c SS |
4467 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4468 | Also free any storage that is part of a bpstat. */ | |
4469 | ||
4470 | void | |
fba45db2 | 4471 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4472 | { |
4473 | bpstat p; | |
4474 | bpstat q; | |
4475 | ||
4476 | if (bsp == 0) | |
4477 | return; | |
4478 | p = *bsp; | |
4479 | while (p != NULL) | |
4480 | { | |
4481 | q = p->next; | |
198757a8 | 4482 | bpstat_free (p); |
c906108c SS |
4483 | p = q; |
4484 | } | |
4485 | *bsp = NULL; | |
4486 | } | |
4487 | ||
4488 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4489 | is part of the bpstat is copied as well. */ | |
4490 | ||
4491 | bpstat | |
fba45db2 | 4492 | bpstat_copy (bpstat bs) |
c906108c SS |
4493 | { |
4494 | bpstat p = NULL; | |
4495 | bpstat tmp; | |
4496 | bpstat retval = NULL; | |
4497 | ||
4498 | if (bs == NULL) | |
4499 | return bs; | |
4500 | ||
4501 | for (; bs != NULL; bs = bs->next) | |
4502 | { | |
4503 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4504 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4505 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4506 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4507 | if (bs->old_val != NULL) |
3c3185ac JK |
4508 | { |
4509 | tmp->old_val = value_copy (bs->old_val); | |
4510 | release_value (tmp->old_val); | |
4511 | } | |
31cc81e9 | 4512 | |
c906108c SS |
4513 | if (p == NULL) |
4514 | /* This is the first thing in the chain. */ | |
4515 | retval = tmp; | |
4516 | else | |
4517 | p->next = tmp; | |
4518 | p = tmp; | |
4519 | } | |
4520 | p->next = NULL; | |
4521 | return retval; | |
4522 | } | |
4523 | ||
4a64f543 | 4524 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4525 | |
4526 | bpstat | |
fba45db2 | 4527 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4528 | { |
c5aa993b JM |
4529 | if (bsp == NULL) |
4530 | return NULL; | |
c906108c | 4531 | |
c5aa993b JM |
4532 | for (; bsp != NULL; bsp = bsp->next) |
4533 | { | |
f431efe5 | 4534 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4535 | return bsp; |
4536 | } | |
c906108c SS |
4537 | return NULL; |
4538 | } | |
4539 | ||
ab04a2af TT |
4540 | /* See breakpoint.h. */ |
4541 | ||
47591c29 | 4542 | int |
427cd150 | 4543 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4544 | { |
ab04a2af TT |
4545 | for (; bsp != NULL; bsp = bsp->next) |
4546 | { | |
427cd150 TT |
4547 | if (bsp->breakpoint_at == NULL) |
4548 | { | |
4549 | /* A moribund location can never explain a signal other than | |
4550 | GDB_SIGNAL_TRAP. */ | |
4551 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4552 | return 1; |
427cd150 TT |
4553 | } |
4554 | else | |
47591c29 PA |
4555 | { |
4556 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4557 | sig)) | |
4558 | return 1; | |
4559 | } | |
ab04a2af TT |
4560 | } |
4561 | ||
47591c29 | 4562 | return 0; |
ab04a2af TT |
4563 | } |
4564 | ||
4a64f543 MS |
4565 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4566 | stopped at. *BSP upon return is a bpstat which points to the | |
4567 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4568 | good for anything but further calls to bpstat_num). | |
4569 | ||
8671a17b PA |
4570 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4571 | Return -1 if stopped at a breakpoint that has been deleted since | |
4572 | we set it. | |
4573 | Return 1 otherwise. */ | |
c906108c SS |
4574 | |
4575 | int | |
8671a17b | 4576 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4577 | { |
4578 | struct breakpoint *b; | |
4579 | ||
4580 | if ((*bsp) == NULL) | |
4581 | return 0; /* No more breakpoint values */ | |
8671a17b | 4582 | |
4a64f543 MS |
4583 | /* We assume we'll never have several bpstats that correspond to a |
4584 | single breakpoint -- otherwise, this function might return the | |
4585 | same number more than once and this will look ugly. */ | |
f431efe5 | 4586 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4587 | *bsp = (*bsp)->next; |
4588 | if (b == NULL) | |
4589 | return -1; /* breakpoint that's been deleted since */ | |
4590 | ||
4591 | *num = b->number; /* We have its number */ | |
4592 | return 1; | |
c906108c SS |
4593 | } |
4594 | ||
e93ca019 | 4595 | /* See breakpoint.h. */ |
c906108c SS |
4596 | |
4597 | void | |
e93ca019 | 4598 | bpstat_clear_actions (void) |
c906108c | 4599 | { |
e93ca019 JK |
4600 | struct thread_info *tp; |
4601 | bpstat bs; | |
4602 | ||
4603 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4604 | return; | |
4605 | ||
4606 | tp = find_thread_ptid (inferior_ptid); | |
4607 | if (tp == NULL) | |
4608 | return; | |
4609 | ||
4610 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4611 | { |
9add0f1b | 4612 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4613 | |
c906108c SS |
4614 | if (bs->old_val != NULL) |
4615 | { | |
4616 | value_free (bs->old_val); | |
4617 | bs->old_val = NULL; | |
4618 | } | |
4619 | } | |
4620 | } | |
4621 | ||
f3b1572e PA |
4622 | /* Called when a command is about to proceed the inferior. */ |
4623 | ||
4624 | static void | |
4625 | breakpoint_about_to_proceed (void) | |
4626 | { | |
4627 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4628 | { | |
4629 | struct thread_info *tp = inferior_thread (); | |
4630 | ||
4631 | /* Allow inferior function calls in breakpoint commands to not | |
4632 | interrupt the command list. When the call finishes | |
4633 | successfully, the inferior will be standing at the same | |
4634 | breakpoint as if nothing happened. */ | |
16c381f0 | 4635 | if (tp->control.in_infcall) |
f3b1572e PA |
4636 | return; |
4637 | } | |
4638 | ||
4639 | breakpoint_proceeded = 1; | |
4640 | } | |
4641 | ||
4a64f543 MS |
4642 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4643 | command. */ | |
c906108c | 4644 | static void |
4efb68b1 | 4645 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4646 | { |
4647 | executing_breakpoint_commands = 0; | |
4648 | } | |
4649 | ||
abf85f46 JK |
4650 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4651 | or its equivalent. */ | |
4652 | ||
4653 | static int | |
4654 | command_line_is_silent (struct command_line *cmd) | |
4655 | { | |
4f45d445 | 4656 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4657 | } |
4658 | ||
4a64f543 MS |
4659 | /* Execute all the commands associated with all the breakpoints at |
4660 | this location. Any of these commands could cause the process to | |
4661 | proceed beyond this point, etc. We look out for such changes by | |
4662 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4663 | |
347bddb7 PA |
4664 | Returns true if a breakpoint command resumed the inferior. In that |
4665 | case, it is the caller's responsibility to recall it again with the | |
4666 | bpstat of the current thread. */ | |
4667 | ||
4668 | static int | |
4669 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4670 | { |
4671 | bpstat bs; | |
4672 | struct cleanup *old_chain; | |
347bddb7 | 4673 | int again = 0; |
c906108c SS |
4674 | |
4675 | /* Avoid endless recursion if a `source' command is contained | |
4676 | in bs->commands. */ | |
4677 | if (executing_breakpoint_commands) | |
347bddb7 | 4678 | return 0; |
c906108c SS |
4679 | |
4680 | executing_breakpoint_commands = 1; | |
4681 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4682 | ||
cf6c5ffb TT |
4683 | prevent_dont_repeat (); |
4684 | ||
4a64f543 | 4685 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4686 | bs = *bsp; |
4687 | ||
4688 | breakpoint_proceeded = 0; | |
4689 | for (; bs != NULL; bs = bs->next) | |
4690 | { | |
9add0f1b | 4691 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4692 | struct command_line *cmd; |
4693 | struct cleanup *this_cmd_tree_chain; | |
4694 | ||
4695 | /* Take ownership of the BSP's command tree, if it has one. | |
4696 | ||
4697 | The command tree could legitimately contain commands like | |
4698 | 'step' and 'next', which call clear_proceed_status, which | |
4699 | frees stop_bpstat's command tree. To make sure this doesn't | |
4700 | free the tree we're executing out from under us, we need to | |
4701 | take ownership of the tree ourselves. Since a given bpstat's | |
4702 | commands are only executed once, we don't need to copy it; we | |
4703 | can clear the pointer in the bpstat, and make sure we free | |
4704 | the tree when we're done. */ | |
9add0f1b TT |
4705 | ccmd = bs->commands; |
4706 | bs->commands = NULL; | |
abf85f46 JK |
4707 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4708 | cmd = ccmd ? ccmd->commands : NULL; | |
4709 | if (command_line_is_silent (cmd)) | |
4710 | { | |
4711 | /* The action has been already done by bpstat_stop_status. */ | |
4712 | cmd = cmd->next; | |
4713 | } | |
6c50ab1c | 4714 | |
c906108c SS |
4715 | while (cmd != NULL) |
4716 | { | |
4717 | execute_control_command (cmd); | |
4718 | ||
4719 | if (breakpoint_proceeded) | |
4720 | break; | |
4721 | else | |
4722 | cmd = cmd->next; | |
4723 | } | |
6c50ab1c JB |
4724 | |
4725 | /* We can free this command tree now. */ | |
4726 | do_cleanups (this_cmd_tree_chain); | |
4727 | ||
c906108c | 4728 | if (breakpoint_proceeded) |
32c1e744 | 4729 | { |
0b333c5e | 4730 | if (interpreter_async) |
347bddb7 PA |
4731 | /* If we are in async mode, then the target might be still |
4732 | running, not stopped at any breakpoint, so nothing for | |
4733 | us to do here -- just return to the event loop. */ | |
4734 | ; | |
32c1e744 VP |
4735 | else |
4736 | /* In sync mode, when execute_control_command returns | |
4737 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4738 | Breakpoint commands for that stop were not run, since |
4739 | execute_command does not run breakpoint commands -- | |
4740 | only command_line_handler does, but that one is not | |
4741 | involved in execution of breakpoint commands. So, we | |
4742 | can now execute breakpoint commands. It should be | |
4743 | noted that making execute_command do bpstat actions is | |
4744 | not an option -- in this case we'll have recursive | |
4745 | invocation of bpstat for each breakpoint with a | |
4746 | command, and can easily blow up GDB stack. Instead, we | |
4747 | return true, which will trigger the caller to recall us | |
4748 | with the new stop_bpstat. */ | |
4749 | again = 1; | |
4750 | break; | |
32c1e744 | 4751 | } |
c906108c | 4752 | } |
c2b8ed2c | 4753 | do_cleanups (old_chain); |
347bddb7 PA |
4754 | return again; |
4755 | } | |
4756 | ||
4757 | void | |
4758 | bpstat_do_actions (void) | |
4759 | { | |
353d1d73 JK |
4760 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4761 | ||
347bddb7 PA |
4762 | /* Do any commands attached to breakpoint we are stopped at. */ |
4763 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4764 | && target_has_execution | |
4765 | && !is_exited (inferior_ptid) | |
4766 | && !is_executing (inferior_ptid)) | |
4767 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4768 | and only return when it is stopped at the next breakpoint, we | |
4769 | keep doing breakpoint actions until it returns false to | |
4770 | indicate the inferior was not resumed. */ | |
16c381f0 | 4771 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4772 | break; |
353d1d73 JK |
4773 | |
4774 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4775 | } |
4776 | ||
fa4727a6 DJ |
4777 | /* Print out the (old or new) value associated with a watchpoint. */ |
4778 | ||
4779 | static void | |
4780 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4781 | { | |
4782 | if (val == NULL) | |
4783 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4784 | else | |
79a45b7d TT |
4785 | { |
4786 | struct value_print_options opts; | |
4787 | get_user_print_options (&opts); | |
4788 | value_print (val, stream, &opts); | |
4789 | } | |
fa4727a6 DJ |
4790 | } |
4791 | ||
e514a9d6 | 4792 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4793 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4794 | 'print_it' in the bpstat structure. Under some circumstances we |
4795 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4796 | normal_stop(). */ |
e514a9d6 JM |
4797 | |
4798 | static enum print_stop_action | |
4799 | print_bp_stop_message (bpstat bs) | |
4800 | { | |
4801 | switch (bs->print_it) | |
4802 | { | |
4803 | case print_it_noop: | |
4a64f543 | 4804 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4805 | return PRINT_UNKNOWN; |
4806 | break; | |
4807 | ||
4808 | case print_it_done: | |
4809 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4810 | relevant messages. */ |
e514a9d6 JM |
4811 | return PRINT_SRC_AND_LOC; |
4812 | break; | |
4813 | ||
4814 | case print_it_normal: | |
4f8d1dc6 | 4815 | { |
f431efe5 PA |
4816 | struct breakpoint *b = bs->breakpoint_at; |
4817 | ||
1a6a67de TJB |
4818 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4819 | which has since been deleted. */ | |
4820 | if (b == NULL) | |
4821 | return PRINT_UNKNOWN; | |
4822 | ||
348d480f PA |
4823 | /* Normal case. Call the breakpoint's print_it method. */ |
4824 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4825 | } |
348d480f | 4826 | break; |
3086aeae | 4827 | |
e514a9d6 | 4828 | default: |
8e65ff28 | 4829 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4830 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4831 | break; |
c906108c | 4832 | } |
c906108c SS |
4833 | } |
4834 | ||
edcc5120 TT |
4835 | /* A helper function that prints a shared library stopped event. */ |
4836 | ||
4837 | static void | |
4838 | print_solib_event (int is_catchpoint) | |
4839 | { | |
4840 | int any_deleted | |
4841 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4842 | int any_added | |
4843 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4844 | ||
4845 | if (!is_catchpoint) | |
4846 | { | |
4847 | if (any_added || any_deleted) | |
4848 | ui_out_text (current_uiout, | |
4849 | _("Stopped due to shared library event:\n")); | |
4850 | else | |
4851 | ui_out_text (current_uiout, | |
4852 | _("Stopped due to shared library event (no " | |
4853 | "libraries added or removed)\n")); | |
4854 | } | |
4855 | ||
4856 | if (ui_out_is_mi_like_p (current_uiout)) | |
4857 | ui_out_field_string (current_uiout, "reason", | |
4858 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4859 | ||
4860 | if (any_deleted) | |
4861 | { | |
4862 | struct cleanup *cleanup; | |
4863 | char *name; | |
4864 | int ix; | |
4865 | ||
4866 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4867 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4868 | "removed"); | |
4869 | for (ix = 0; | |
4870 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4871 | ix, name); | |
4872 | ++ix) | |
4873 | { | |
4874 | if (ix > 0) | |
4875 | ui_out_text (current_uiout, " "); | |
4876 | ui_out_field_string (current_uiout, "library", name); | |
4877 | ui_out_text (current_uiout, "\n"); | |
4878 | } | |
4879 | ||
4880 | do_cleanups (cleanup); | |
4881 | } | |
4882 | ||
4883 | if (any_added) | |
4884 | { | |
4885 | struct so_list *iter; | |
4886 | int ix; | |
4887 | struct cleanup *cleanup; | |
4888 | ||
4889 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4890 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4891 | "added"); | |
4892 | for (ix = 0; | |
4893 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4894 | ix, iter); | |
4895 | ++ix) | |
4896 | { | |
4897 | if (ix > 0) | |
4898 | ui_out_text (current_uiout, " "); | |
4899 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4900 | ui_out_text (current_uiout, "\n"); | |
4901 | } | |
4902 | ||
4903 | do_cleanups (cleanup); | |
4904 | } | |
4905 | } | |
4906 | ||
e514a9d6 JM |
4907 | /* Print a message indicating what happened. This is called from |
4908 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4909 | list - a list of the eventpoints that caused this stop. KIND is |
4910 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4911 | routine calls the generic print routine for printing a message |
4912 | about reasons for stopping. This will print (for example) the | |
4913 | "Breakpoint n," part of the output. The return value of this | |
4914 | routine is one of: | |
c906108c | 4915 | |
4a64f543 | 4916 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4917 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4918 | code to print the location. An example is |
c5aa993b JM |
4919 | "Breakpoint 1, " which should be followed by |
4920 | the location. | |
917317f4 | 4921 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4922 | to also print the location part of the message. |
4923 | An example is the catch/throw messages, which | |
4a64f543 | 4924 | don't require a location appended to the end. |
917317f4 | 4925 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4926 | further info to be printed. */ |
c906108c | 4927 | |
917317f4 | 4928 | enum print_stop_action |
36dfb11c | 4929 | bpstat_print (bpstat bs, int kind) |
c906108c | 4930 | { |
f486487f | 4931 | enum print_stop_action val; |
c5aa993b | 4932 | |
c906108c | 4933 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4934 | (Currently all watchpoints go on the bpstat whether hit or not. |
4935 | That probably could (should) be changed, provided care is taken | |
c906108c | 4936 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4937 | for (; bs; bs = bs->next) |
4938 | { | |
4939 | val = print_bp_stop_message (bs); | |
4940 | if (val == PRINT_SRC_ONLY | |
4941 | || val == PRINT_SRC_AND_LOC | |
4942 | || val == PRINT_NOTHING) | |
4943 | return val; | |
4944 | } | |
c906108c | 4945 | |
36dfb11c TT |
4946 | /* If we had hit a shared library event breakpoint, |
4947 | print_bp_stop_message would print out this message. If we hit an | |
4948 | OS-level shared library event, do the same thing. */ | |
4949 | if (kind == TARGET_WAITKIND_LOADED) | |
4950 | { | |
edcc5120 | 4951 | print_solib_event (0); |
36dfb11c TT |
4952 | return PRINT_NOTHING; |
4953 | } | |
4954 | ||
e514a9d6 | 4955 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4956 | with and nothing was printed. */ |
917317f4 | 4957 | return PRINT_UNKNOWN; |
c906108c SS |
4958 | } |
4959 | ||
c42bd95a DE |
4960 | /* Evaluate the expression EXP and return 1 if value is zero. |
4961 | This returns the inverse of the condition because it is called | |
4962 | from catch_errors which returns 0 if an exception happened, and if an | |
4963 | exception happens we want execution to stop. | |
4a64f543 | 4964 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4965 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4966 | |
4967 | static int | |
4efb68b1 | 4968 | breakpoint_cond_eval (void *exp) |
c906108c | 4969 | { |
278cd55f | 4970 | struct value *mark = value_mark (); |
c5aa993b | 4971 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4972 | |
c906108c SS |
4973 | value_free_to_mark (mark); |
4974 | return i; | |
4975 | } | |
4976 | ||
5760d0ab | 4977 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4978 | |
4979 | static bpstat | |
5760d0ab | 4980 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4981 | { |
4982 | bpstat bs; | |
4983 | ||
4984 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4985 | bs->next = NULL; |
4986 | **bs_link_pointer = bs; | |
4987 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4988 | bs->breakpoint_at = bl->owner; |
4989 | bs->bp_location_at = bl; | |
4990 | incref_bp_location (bl); | |
c906108c SS |
4991 | /* If the condition is false, etc., don't do the commands. */ |
4992 | bs->commands = NULL; | |
4993 | bs->old_val = NULL; | |
4994 | bs->print_it = print_it_normal; | |
4995 | return bs; | |
4996 | } | |
4997 | \f | |
d983da9c DJ |
4998 | /* The target has stopped with waitstatus WS. Check if any hardware |
4999 | watchpoints have triggered, according to the target. */ | |
5000 | ||
5001 | int | |
5002 | watchpoints_triggered (struct target_waitstatus *ws) | |
5003 | { | |
d92524f1 | 5004 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5005 | CORE_ADDR addr; |
5006 | struct breakpoint *b; | |
5007 | ||
5008 | if (!stopped_by_watchpoint) | |
5009 | { | |
5010 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5011 | as not triggered. */ | |
5012 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5013 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5014 | { |
5015 | struct watchpoint *w = (struct watchpoint *) b; | |
5016 | ||
5017 | w->watchpoint_triggered = watch_triggered_no; | |
5018 | } | |
d983da9c DJ |
5019 | |
5020 | return 0; | |
5021 | } | |
5022 | ||
5023 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5024 | { | |
5025 | /* We were stopped by a watchpoint, but we don't know where. | |
5026 | Mark all watchpoints as unknown. */ | |
5027 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5028 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5029 | { |
5030 | struct watchpoint *w = (struct watchpoint *) b; | |
5031 | ||
5032 | w->watchpoint_triggered = watch_triggered_unknown; | |
5033 | } | |
d983da9c | 5034 | |
3c4797ba | 5035 | return 1; |
d983da9c DJ |
5036 | } |
5037 | ||
5038 | /* The target could report the data address. Mark watchpoints | |
5039 | affected by this data address as triggered, and all others as not | |
5040 | triggered. */ | |
5041 | ||
5042 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5043 | if (is_hardware_watchpoint (b)) |
d983da9c | 5044 | { |
3a5c3e22 | 5045 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5046 | struct bp_location *loc; |
d983da9c | 5047 | |
3a5c3e22 | 5048 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5049 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5050 | { |
3a5c3e22 | 5051 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5052 | { |
3a5c3e22 PA |
5053 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5054 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5055 | |
5056 | if (newaddr == start) | |
5057 | { | |
3a5c3e22 | 5058 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5059 | break; |
5060 | } | |
5061 | } | |
5062 | /* Exact match not required. Within range is sufficient. */ | |
5063 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5064 | addr, loc->address, | |
5065 | loc->length)) | |
5066 | { | |
3a5c3e22 | 5067 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5068 | break; |
5069 | } | |
5070 | } | |
d983da9c DJ |
5071 | } |
5072 | ||
5073 | return 1; | |
5074 | } | |
5075 | ||
c906108c SS |
5076 | /* Possible return values for watchpoint_check (this can't be an enum |
5077 | because of check_errors). */ | |
5078 | /* The watchpoint has been deleted. */ | |
5079 | #define WP_DELETED 1 | |
5080 | /* The value has changed. */ | |
5081 | #define WP_VALUE_CHANGED 2 | |
5082 | /* The value has not changed. */ | |
5083 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5084 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5085 | #define WP_IGNORE 4 | |
c906108c SS |
5086 | |
5087 | #define BP_TEMPFLAG 1 | |
5088 | #define BP_HARDWAREFLAG 2 | |
5089 | ||
4a64f543 MS |
5090 | /* Evaluate watchpoint condition expression and check if its value |
5091 | changed. | |
553e4c11 JB |
5092 | |
5093 | P should be a pointer to struct bpstat, but is defined as a void * | |
5094 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5095 | |
5096 | static int | |
4efb68b1 | 5097 | watchpoint_check (void *p) |
c906108c SS |
5098 | { |
5099 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5100 | struct watchpoint *b; |
c906108c SS |
5101 | struct frame_info *fr; |
5102 | int within_current_scope; | |
5103 | ||
f431efe5 | 5104 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5105 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5106 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5107 | |
f6bc2008 PA |
5108 | /* If this is a local watchpoint, we only want to check if the |
5109 | watchpoint frame is in scope if the current thread is the thread | |
5110 | that was used to create the watchpoint. */ | |
5111 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5112 | return WP_IGNORE; |
f6bc2008 | 5113 | |
c906108c SS |
5114 | if (b->exp_valid_block == NULL) |
5115 | within_current_scope = 1; | |
5116 | else | |
5117 | { | |
edb3359d DJ |
5118 | struct frame_info *frame = get_current_frame (); |
5119 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5120 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5121 | ||
c9cf6e20 | 5122 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5123 | still in the function but the stack frame has already been |
5124 | invalidated. Since we can't rely on the values of local | |
5125 | variables after the stack has been destroyed, we are treating | |
5126 | the watchpoint in that state as `not changed' without further | |
5127 | checking. Don't mark watchpoints as changed if the current | |
5128 | frame is in an epilogue - even if they are in some other | |
5129 | frame, our view of the stack is likely to be wrong and | |
5130 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5131 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5132 | return WP_IGNORE; |
a0f49112 | 5133 | |
101dcfbe | 5134 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5135 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5136 | |
5137 | /* If we've gotten confused in the unwinder, we might have | |
5138 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5139 | if (within_current_scope) |
5140 | { | |
5141 | struct symbol *function; | |
5142 | ||
5143 | function = get_frame_function (fr); | |
5144 | if (function == NULL | |
5145 | || !contained_in (b->exp_valid_block, | |
5146 | SYMBOL_BLOCK_VALUE (function))) | |
5147 | within_current_scope = 0; | |
5148 | } | |
69fbadd5 | 5149 | |
edb3359d | 5150 | if (within_current_scope) |
c906108c SS |
5151 | /* If we end up stopping, the current frame will get selected |
5152 | in normal_stop. So this call to select_frame won't affect | |
5153 | the user. */ | |
0f7d239c | 5154 | select_frame (fr); |
c906108c | 5155 | } |
c5aa993b | 5156 | |
c906108c SS |
5157 | if (within_current_scope) |
5158 | { | |
4a64f543 MS |
5159 | /* We use value_{,free_to_}mark because it could be a *long* |
5160 | time before we return to the command level and call | |
5161 | free_all_values. We can't call free_all_values because we | |
5162 | might be in the middle of evaluating a function call. */ | |
c906108c | 5163 | |
0cf6dd15 | 5164 | int pc = 0; |
9c06b0b4 | 5165 | struct value *mark; |
fa4727a6 DJ |
5166 | struct value *new_val; |
5167 | ||
3a5c3e22 | 5168 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5169 | /* Since we don't know the exact trigger address (from |
5170 | stopped_data_address), just tell the user we've triggered | |
5171 | a mask watchpoint. */ | |
5172 | return WP_VALUE_CHANGED; | |
5173 | ||
5174 | mark = value_mark (); | |
3a1115a0 | 5175 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5176 | |
bb9d5f81 PP |
5177 | if (b->val_bitsize != 0) |
5178 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5179 | ||
4a64f543 MS |
5180 | /* We use value_equal_contents instead of value_equal because |
5181 | the latter coerces an array to a pointer, thus comparing just | |
5182 | the address of the array instead of its contents. This is | |
5183 | not what we want. */ | |
fa4727a6 | 5184 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5185 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5186 | { |
fa4727a6 DJ |
5187 | if (new_val != NULL) |
5188 | { | |
5189 | release_value (new_val); | |
5190 | value_free_to_mark (mark); | |
5191 | } | |
c906108c SS |
5192 | bs->old_val = b->val; |
5193 | b->val = new_val; | |
fa4727a6 | 5194 | b->val_valid = 1; |
c906108c SS |
5195 | return WP_VALUE_CHANGED; |
5196 | } | |
5197 | else | |
5198 | { | |
60e1c644 | 5199 | /* Nothing changed. */ |
c906108c | 5200 | value_free_to_mark (mark); |
c906108c SS |
5201 | return WP_VALUE_NOT_CHANGED; |
5202 | } | |
5203 | } | |
5204 | else | |
5205 | { | |
79a45e25 PA |
5206 | struct ui_out *uiout = current_uiout; |
5207 | ||
c906108c | 5208 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5209 | if we temporarily ignored the watchpoint, then when |
5210 | we reenter the block in which it is valid it contains | |
5211 | garbage (in the case of a function, it may have two | |
5212 | garbage values, one before and one after the prologue). | |
5213 | So we can't even detect the first assignment to it and | |
5214 | watch after that (since the garbage may or may not equal | |
5215 | the first value assigned). */ | |
348d480f PA |
5216 | /* We print all the stop information in |
5217 | breakpoint_ops->print_it, but in this case, by the time we | |
5218 | call breakpoint_ops->print_it this bp will be deleted | |
5219 | already. So we have no choice but print the information | |
5220 | here. */ | |
9dc5e2a9 | 5221 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5222 | ui_out_field_string |
5223 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5224 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5225 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5226 | ui_out_text (uiout, |
5227 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5228 | which its expression is valid.\n"); |
4ce44c66 | 5229 | |
cdac0397 | 5230 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5231 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5232 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5233 | |
5234 | return WP_DELETED; | |
5235 | } | |
5236 | } | |
5237 | ||
18a18393 | 5238 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5239 | breakpoint location BL. This function does not check if we should |
5240 | stop, only if BL explains the stop. */ | |
5241 | ||
18a18393 | 5242 | static int |
6c95b8df | 5243 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5244 | struct address_space *aspace, CORE_ADDR bp_addr, |
5245 | const struct target_waitstatus *ws) | |
18a18393 VP |
5246 | { |
5247 | struct breakpoint *b = bl->owner; | |
5248 | ||
348d480f | 5249 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5250 | gdb_assert (b != NULL); |
5251 | ||
09ac7c10 | 5252 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5253 | } |
5254 | ||
3a5c3e22 PA |
5255 | /* Determine if the watched values have actually changed, and we |
5256 | should stop. If not, set BS->stop to 0. */ | |
5257 | ||
18a18393 VP |
5258 | static void |
5259 | bpstat_check_watchpoint (bpstat bs) | |
5260 | { | |
2bdf28a0 | 5261 | const struct bp_location *bl; |
3a5c3e22 | 5262 | struct watchpoint *b; |
2bdf28a0 JK |
5263 | |
5264 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5265 | bl = bs->bp_location_at; |
2bdf28a0 | 5266 | gdb_assert (bl != NULL); |
3a5c3e22 | 5267 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5268 | gdb_assert (b != NULL); |
18a18393 | 5269 | |
18a18393 | 5270 | { |
18a18393 VP |
5271 | int must_check_value = 0; |
5272 | ||
3a5c3e22 | 5273 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5274 | /* For a software watchpoint, we must always check the |
5275 | watched value. */ | |
5276 | must_check_value = 1; | |
5277 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5278 | /* We have a hardware watchpoint (read, write, or access) | |
5279 | and the target earlier reported an address watched by | |
5280 | this watchpoint. */ | |
5281 | must_check_value = 1; | |
5282 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5283 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5284 | /* We were stopped by a hardware watchpoint, but the target could |
5285 | not report the data address. We must check the watchpoint's | |
5286 | value. Access and read watchpoints are out of luck; without | |
5287 | a data address, we can't figure it out. */ | |
5288 | must_check_value = 1; | |
3a5c3e22 | 5289 | |
18a18393 VP |
5290 | if (must_check_value) |
5291 | { | |
3e43a32a MS |
5292 | char *message |
5293 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5294 | b->base.number); |
18a18393 VP |
5295 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5296 | int e = catch_errors (watchpoint_check, bs, message, | |
5297 | RETURN_MASK_ALL); | |
5298 | do_cleanups (cleanups); | |
5299 | switch (e) | |
5300 | { | |
5301 | case WP_DELETED: | |
5302 | /* We've already printed what needs to be printed. */ | |
5303 | bs->print_it = print_it_done; | |
5304 | /* Stop. */ | |
5305 | break; | |
60e1c644 PA |
5306 | case WP_IGNORE: |
5307 | bs->print_it = print_it_noop; | |
5308 | bs->stop = 0; | |
5309 | break; | |
18a18393 | 5310 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5311 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5312 | { |
85d721b8 PA |
5313 | /* There are two cases to consider here: |
5314 | ||
4a64f543 | 5315 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5316 | In that case, trust the target, and always report |
5317 | the watchpoint hit to the user. Even though | |
5318 | reads don't cause value changes, the value may | |
5319 | have changed since the last time it was read, and | |
5320 | since we're not trapping writes, we will not see | |
5321 | those, and as such we should ignore our notion of | |
5322 | old value. | |
5323 | ||
4a64f543 | 5324 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5325 | reads and writes. There are two ways this may |
5326 | happen: | |
5327 | ||
4a64f543 | 5328 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5329 | reads only, but can break on accesses (reads or |
5330 | writes), such as e.g., x86. We detect this case | |
5331 | at the time we try to insert read watchpoints. | |
5332 | ||
4a64f543 | 5333 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5334 | watchpoints, but, the user set an access or write |
5335 | watchpoint watching the same memory as this read | |
5336 | watchpoint. | |
5337 | ||
5338 | If we're watching memory writes as well as reads, | |
5339 | ignore watchpoint hits when we find that the | |
5340 | value hasn't changed, as reads don't cause | |
5341 | changes. This still gives false positives when | |
5342 | the program writes the same value to memory as | |
5343 | what there was already in memory (we will confuse | |
5344 | it for a read), but it's much better than | |
5345 | nothing. */ | |
5346 | ||
5347 | int other_write_watchpoint = 0; | |
5348 | ||
5349 | if (bl->watchpoint_type == hw_read) | |
5350 | { | |
5351 | struct breakpoint *other_b; | |
5352 | ||
5353 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5354 | if (other_b->type == bp_hardware_watchpoint |
5355 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5356 | { |
3a5c3e22 PA |
5357 | struct watchpoint *other_w = |
5358 | (struct watchpoint *) other_b; | |
5359 | ||
5360 | if (other_w->watchpoint_triggered | |
5361 | == watch_triggered_yes) | |
5362 | { | |
5363 | other_write_watchpoint = 1; | |
5364 | break; | |
5365 | } | |
85d721b8 PA |
5366 | } |
5367 | } | |
5368 | ||
5369 | if (other_write_watchpoint | |
5370 | || bl->watchpoint_type == hw_access) | |
5371 | { | |
5372 | /* We're watching the same memory for writes, | |
5373 | and the value changed since the last time we | |
5374 | updated it, so this trap must be for a write. | |
5375 | Ignore it. */ | |
5376 | bs->print_it = print_it_noop; | |
5377 | bs->stop = 0; | |
5378 | } | |
18a18393 VP |
5379 | } |
5380 | break; | |
5381 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5382 | if (b->base.type == bp_hardware_watchpoint |
5383 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5384 | { |
5385 | /* Don't stop: write watchpoints shouldn't fire if | |
5386 | the value hasn't changed. */ | |
5387 | bs->print_it = print_it_noop; | |
5388 | bs->stop = 0; | |
5389 | } | |
5390 | /* Stop. */ | |
5391 | break; | |
5392 | default: | |
5393 | /* Can't happen. */ | |
5394 | case 0: | |
5395 | /* Error from catch_errors. */ | |
3a5c3e22 | 5396 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5397 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5398 | /* We've already printed what needs to be printed. */ |
5399 | bs->print_it = print_it_done; | |
5400 | break; | |
5401 | } | |
5402 | } | |
5403 | else /* must_check_value == 0 */ | |
5404 | { | |
5405 | /* This is a case where some watchpoint(s) triggered, but | |
5406 | not at the address of this watchpoint, or else no | |
5407 | watchpoint triggered after all. So don't print | |
5408 | anything for this watchpoint. */ | |
5409 | bs->print_it = print_it_noop; | |
5410 | bs->stop = 0; | |
5411 | } | |
5412 | } | |
5413 | } | |
5414 | ||
7d4df6a4 DE |
5415 | /* For breakpoints that are currently marked as telling gdb to stop, |
5416 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5417 | of breakpoint referred to by BS. If we should not stop for this |
5418 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5419 | |
18a18393 VP |
5420 | static void |
5421 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5422 | { | |
2bdf28a0 JK |
5423 | const struct bp_location *bl; |
5424 | struct breakpoint *b; | |
7d4df6a4 DE |
5425 | int value_is_zero = 0; |
5426 | struct expression *cond; | |
5427 | ||
5428 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5429 | |
5430 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5431 | bl = bs->bp_location_at; |
2bdf28a0 | 5432 | gdb_assert (bl != NULL); |
f431efe5 | 5433 | b = bs->breakpoint_at; |
2bdf28a0 | 5434 | gdb_assert (b != NULL); |
18a18393 | 5435 | |
b775012e LM |
5436 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5437 | need to do so again since GDB does not know if we stopped due to a | |
5438 | breakpoint or a single step breakpoint. */ | |
5439 | ||
18a18393 | 5440 | if (frame_id_p (b->frame_id) |
edb3359d | 5441 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5442 | { |
7d4df6a4 DE |
5443 | bs->stop = 0; |
5444 | return; | |
5445 | } | |
60e1c644 | 5446 | |
12ab52e9 PA |
5447 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5448 | evaluating the condition if this isn't the specified | |
5449 | thread/task. */ | |
5450 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5451 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5452 | ||
6c1b0f7b DE |
5453 | { |
5454 | bs->stop = 0; | |
5455 | return; | |
5456 | } | |
5457 | ||
6dddc817 DE |
5458 | /* Evaluate extension language breakpoints that have a "stop" method |
5459 | implemented. */ | |
5460 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5461 | |
7d4df6a4 DE |
5462 | if (is_watchpoint (b)) |
5463 | { | |
5464 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5465 | |
7d4df6a4 DE |
5466 | cond = w->cond_exp; |
5467 | } | |
5468 | else | |
5469 | cond = bl->cond; | |
60e1c644 | 5470 | |
7d4df6a4 DE |
5471 | if (cond && b->disposition != disp_del_at_next_stop) |
5472 | { | |
5473 | int within_current_scope = 1; | |
5474 | struct watchpoint * w; | |
60e1c644 | 5475 | |
7d4df6a4 DE |
5476 | /* We use value_mark and value_free_to_mark because it could |
5477 | be a long time before we return to the command level and | |
5478 | call free_all_values. We can't call free_all_values | |
5479 | because we might be in the middle of evaluating a | |
5480 | function call. */ | |
5481 | struct value *mark = value_mark (); | |
5482 | ||
5483 | if (is_watchpoint (b)) | |
5484 | w = (struct watchpoint *) b; | |
5485 | else | |
5486 | w = NULL; | |
5487 | ||
5488 | /* Need to select the frame, with all that implies so that | |
5489 | the conditions will have the right context. Because we | |
5490 | use the frame, we will not see an inlined function's | |
5491 | variables when we arrive at a breakpoint at the start | |
5492 | of the inlined function; the current frame will be the | |
5493 | call site. */ | |
5494 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5495 | select_frame (get_current_frame ()); | |
5496 | else | |
18a18393 | 5497 | { |
7d4df6a4 DE |
5498 | struct frame_info *frame; |
5499 | ||
5500 | /* For local watchpoint expressions, which particular | |
5501 | instance of a local is being watched matters, so we | |
5502 | keep track of the frame to evaluate the expression | |
5503 | in. To evaluate the condition however, it doesn't | |
5504 | really matter which instantiation of the function | |
5505 | where the condition makes sense triggers the | |
5506 | watchpoint. This allows an expression like "watch | |
5507 | global if q > 10" set in `func', catch writes to | |
5508 | global on all threads that call `func', or catch | |
5509 | writes on all recursive calls of `func' by a single | |
5510 | thread. We simply always evaluate the condition in | |
5511 | the innermost frame that's executing where it makes | |
5512 | sense to evaluate the condition. It seems | |
5513 | intuitive. */ | |
5514 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5515 | if (frame != NULL) | |
5516 | select_frame (frame); | |
5517 | else | |
5518 | within_current_scope = 0; | |
18a18393 | 5519 | } |
7d4df6a4 DE |
5520 | if (within_current_scope) |
5521 | value_is_zero | |
5522 | = catch_errors (breakpoint_cond_eval, cond, | |
5523 | "Error in testing breakpoint condition:\n", | |
5524 | RETURN_MASK_ALL); | |
5525 | else | |
18a18393 | 5526 | { |
7d4df6a4 DE |
5527 | warning (_("Watchpoint condition cannot be tested " |
5528 | "in the current scope")); | |
5529 | /* If we failed to set the right context for this | |
5530 | watchpoint, unconditionally report it. */ | |
5531 | value_is_zero = 0; | |
18a18393 | 5532 | } |
7d4df6a4 DE |
5533 | /* FIXME-someday, should give breakpoint #. */ |
5534 | value_free_to_mark (mark); | |
18a18393 | 5535 | } |
7d4df6a4 DE |
5536 | |
5537 | if (cond && value_is_zero) | |
5538 | { | |
5539 | bs->stop = 0; | |
5540 | } | |
7d4df6a4 DE |
5541 | else if (b->ignore_count > 0) |
5542 | { | |
5543 | b->ignore_count--; | |
5544 | bs->stop = 0; | |
5545 | /* Increase the hit count even though we don't stop. */ | |
5546 | ++(b->hit_count); | |
5547 | observer_notify_breakpoint_modified (b); | |
5548 | } | |
18a18393 VP |
5549 | } |
5550 | ||
1cf4d951 PA |
5551 | /* Returns true if we need to track moribund locations of LOC's type |
5552 | on the current target. */ | |
5553 | ||
5554 | static int | |
5555 | need_moribund_for_location_type (struct bp_location *loc) | |
5556 | { | |
5557 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5558 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5559 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5560 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5561 | } | |
5562 | ||
18a18393 | 5563 | |
9709f61c | 5564 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5565 | BP_ADDR in thread PTID. |
c906108c | 5566 | |
d983da9c | 5567 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5568 | don't understand this stop. Result is a chain of bpstat's such |
5569 | that: | |
c906108c | 5570 | |
c5aa993b | 5571 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5572 | |
c5aa993b | 5573 | if we understand why we stopped, the result is not null. |
c906108c | 5574 | |
c5aa993b JM |
5575 | Each element of the chain refers to a particular breakpoint or |
5576 | watchpoint at which we have stopped. (We may have stopped for | |
5577 | several reasons concurrently.) | |
c906108c | 5578 | |
c5aa993b JM |
5579 | Each element of the chain has valid next, breakpoint_at, |
5580 | commands, FIXME??? fields. */ | |
c906108c SS |
5581 | |
5582 | bpstat | |
6c95b8df | 5583 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5584 | CORE_ADDR bp_addr, ptid_t ptid, |
5585 | const struct target_waitstatus *ws) | |
c906108c | 5586 | { |
0d381245 | 5587 | struct breakpoint *b = NULL; |
afe38095 | 5588 | struct bp_location *bl; |
20874c92 | 5589 | struct bp_location *loc; |
5760d0ab JK |
5590 | /* First item of allocated bpstat's. */ |
5591 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5592 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5593 | bpstat bs; |
20874c92 | 5594 | int ix; |
429374b8 | 5595 | int need_remove_insert; |
f431efe5 | 5596 | int removed_any; |
c906108c | 5597 | |
f431efe5 PA |
5598 | /* First, build the bpstat chain with locations that explain a |
5599 | target stop, while being careful to not set the target running, | |
5600 | as that may invalidate locations (in particular watchpoint | |
5601 | locations are recreated). Resuming will happen here with | |
5602 | breakpoint conditions or watchpoint expressions that include | |
5603 | inferior function calls. */ | |
c5aa993b | 5604 | |
429374b8 JK |
5605 | ALL_BREAKPOINTS (b) |
5606 | { | |
1a853c52 | 5607 | if (!breakpoint_enabled (b)) |
429374b8 | 5608 | continue; |
a5606eee | 5609 | |
429374b8 JK |
5610 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5611 | { | |
4a64f543 MS |
5612 | /* For hardware watchpoints, we look only at the first |
5613 | location. The watchpoint_check function will work on the | |
5614 | entire expression, not the individual locations. For | |
5615 | read watchpoints, the watchpoints_triggered function has | |
5616 | checked all locations already. */ | |
429374b8 JK |
5617 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5618 | break; | |
18a18393 | 5619 | |
f6592439 | 5620 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5621 | continue; |
c5aa993b | 5622 | |
09ac7c10 | 5623 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5624 | continue; |
c5aa993b | 5625 | |
4a64f543 MS |
5626 | /* Come here if it's a watchpoint, or if the break address |
5627 | matches. */ | |
c5aa993b | 5628 | |
4a64f543 MS |
5629 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5630 | explain stop. */ | |
c5aa993b | 5631 | |
f431efe5 PA |
5632 | /* Assume we stop. Should we find a watchpoint that is not |
5633 | actually triggered, or if the condition of the breakpoint | |
5634 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5635 | bs->stop = 1; |
5636 | bs->print = 1; | |
d983da9c | 5637 | |
f431efe5 PA |
5638 | /* If this is a scope breakpoint, mark the associated |
5639 | watchpoint as triggered so that we will handle the | |
5640 | out-of-scope event. We'll get to the watchpoint next | |
5641 | iteration. */ | |
d0fb5eae | 5642 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5643 | { |
5644 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5645 | ||
5646 | w->watchpoint_triggered = watch_triggered_yes; | |
5647 | } | |
f431efe5 PA |
5648 | } |
5649 | } | |
5650 | ||
7c16b83e | 5651 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5652 | if (!target_supports_stopped_by_sw_breakpoint () |
5653 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5654 | { |
1cf4d951 | 5655 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5656 | { |
1cf4d951 PA |
5657 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5658 | && need_moribund_for_location_type (loc)) | |
5659 | { | |
5660 | bs = bpstat_alloc (loc, &bs_link); | |
5661 | /* For hits of moribund locations, we should just proceed. */ | |
5662 | bs->stop = 0; | |
5663 | bs->print = 0; | |
5664 | bs->print_it = print_it_noop; | |
5665 | } | |
f431efe5 PA |
5666 | } |
5667 | } | |
5668 | ||
edcc5120 TT |
5669 | /* A bit of special processing for shlib breakpoints. We need to |
5670 | process solib loading here, so that the lists of loaded and | |
5671 | unloaded libraries are correct before we handle "catch load" and | |
5672 | "catch unload". */ | |
5673 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5674 | { | |
5d268276 | 5675 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5676 | { |
5677 | handle_solib_event (); | |
5678 | break; | |
5679 | } | |
5680 | } | |
5681 | ||
f431efe5 PA |
5682 | /* Now go through the locations that caused the target to stop, and |
5683 | check whether we're interested in reporting this stop to higher | |
5684 | layers, or whether we should resume the target transparently. */ | |
5685 | ||
5686 | removed_any = 0; | |
5687 | ||
5760d0ab | 5688 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5689 | { |
5690 | if (!bs->stop) | |
5691 | continue; | |
5692 | ||
f431efe5 | 5693 | b = bs->breakpoint_at; |
348d480f PA |
5694 | b->ops->check_status (bs); |
5695 | if (bs->stop) | |
28010a5d | 5696 | { |
348d480f | 5697 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5698 | |
429374b8 JK |
5699 | if (bs->stop) |
5700 | { | |
5701 | ++(b->hit_count); | |
8d3788bd | 5702 | observer_notify_breakpoint_modified (b); |
c906108c | 5703 | |
4a64f543 | 5704 | /* We will stop here. */ |
429374b8 JK |
5705 | if (b->disposition == disp_disable) |
5706 | { | |
816338b5 | 5707 | --(b->enable_count); |
1a853c52 | 5708 | if (b->enable_count <= 0) |
429374b8 | 5709 | b->enable_state = bp_disabled; |
f431efe5 | 5710 | removed_any = 1; |
429374b8 JK |
5711 | } |
5712 | if (b->silent) | |
5713 | bs->print = 0; | |
5714 | bs->commands = b->commands; | |
9add0f1b | 5715 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5716 | if (command_line_is_silent (bs->commands |
5717 | ? bs->commands->commands : NULL)) | |
5718 | bs->print = 0; | |
9d6e6e84 HZ |
5719 | |
5720 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5721 | } |
5722 | ||
348d480f | 5723 | } |
a9b3a50f PA |
5724 | |
5725 | /* Print nothing for this entry if we don't stop or don't | |
5726 | print. */ | |
5727 | if (!bs->stop || !bs->print) | |
5728 | bs->print_it = print_it_noop; | |
429374b8 | 5729 | } |
876fa593 | 5730 | |
d983da9c DJ |
5731 | /* If we aren't stopping, the value of some hardware watchpoint may |
5732 | not have changed, but the intermediate memory locations we are | |
5733 | watching may have. Don't bother if we're stopping; this will get | |
5734 | done later. */ | |
d832cb68 | 5735 | need_remove_insert = 0; |
5760d0ab JK |
5736 | if (! bpstat_causes_stop (bs_head)) |
5737 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5738 | if (!bs->stop |
f431efe5 PA |
5739 | && bs->breakpoint_at |
5740 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5741 | { |
3a5c3e22 PA |
5742 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5743 | ||
5744 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5745 | need_remove_insert = 1; |
d983da9c DJ |
5746 | } |
5747 | ||
d832cb68 | 5748 | if (need_remove_insert) |
44702360 | 5749 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5750 | else if (removed_any) |
44702360 | 5751 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5752 | |
5760d0ab | 5753 | return bs_head; |
c906108c | 5754 | } |
628fe4e4 JK |
5755 | |
5756 | static void | |
5757 | handle_jit_event (void) | |
5758 | { | |
5759 | struct frame_info *frame; | |
5760 | struct gdbarch *gdbarch; | |
5761 | ||
243a9253 PA |
5762 | if (debug_infrun) |
5763 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5764 | ||
628fe4e4 JK |
5765 | /* Switch terminal for any messages produced by |
5766 | breakpoint_re_set. */ | |
5767 | target_terminal_ours_for_output (); | |
5768 | ||
5769 | frame = get_current_frame (); | |
5770 | gdbarch = get_frame_arch (frame); | |
5771 | ||
5772 | jit_event_handler (gdbarch); | |
5773 | ||
5774 | target_terminal_inferior (); | |
5775 | } | |
5776 | ||
5777 | /* Prepare WHAT final decision for infrun. */ | |
5778 | ||
5779 | /* Decide what infrun needs to do with this bpstat. */ | |
5780 | ||
c906108c | 5781 | struct bpstat_what |
0e30163f | 5782 | bpstat_what (bpstat bs_head) |
c906108c | 5783 | { |
c906108c | 5784 | struct bpstat_what retval; |
628fe4e4 | 5785 | int jit_event = 0; |
0e30163f | 5786 | bpstat bs; |
c906108c | 5787 | |
628fe4e4 | 5788 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5789 | retval.call_dummy = STOP_NONE; |
186c406b | 5790 | retval.is_longjmp = 0; |
628fe4e4 | 5791 | |
0e30163f | 5792 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5793 | { |
628fe4e4 JK |
5794 | /* Extract this BS's action. After processing each BS, we check |
5795 | if its action overrides all we've seem so far. */ | |
5796 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5797 | enum bptype bptype; | |
5798 | ||
c906108c | 5799 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5800 | { |
5801 | /* I suspect this can happen if it was a momentary | |
5802 | breakpoint which has since been deleted. */ | |
5803 | bptype = bp_none; | |
5804 | } | |
20874c92 | 5805 | else |
f431efe5 | 5806 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5807 | |
5808 | switch (bptype) | |
c906108c SS |
5809 | { |
5810 | case bp_none: | |
628fe4e4 | 5811 | break; |
c906108c SS |
5812 | case bp_breakpoint: |
5813 | case bp_hardware_breakpoint: | |
7c16b83e | 5814 | case bp_single_step: |
c906108c SS |
5815 | case bp_until: |
5816 | case bp_finish: | |
a9b3a50f | 5817 | case bp_shlib_event: |
c906108c SS |
5818 | if (bs->stop) |
5819 | { | |
5820 | if (bs->print) | |
628fe4e4 | 5821 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5822 | else |
628fe4e4 | 5823 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5824 | } |
5825 | else | |
628fe4e4 | 5826 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5827 | break; |
5828 | case bp_watchpoint: | |
5829 | case bp_hardware_watchpoint: | |
5830 | case bp_read_watchpoint: | |
5831 | case bp_access_watchpoint: | |
5832 | if (bs->stop) | |
5833 | { | |
5834 | if (bs->print) | |
628fe4e4 | 5835 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5836 | else |
628fe4e4 | 5837 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5838 | } |
5839 | else | |
628fe4e4 JK |
5840 | { |
5841 | /* There was a watchpoint, but we're not stopping. | |
5842 | This requires no further action. */ | |
5843 | } | |
c906108c SS |
5844 | break; |
5845 | case bp_longjmp: | |
e2e4d78b | 5846 | case bp_longjmp_call_dummy: |
186c406b | 5847 | case bp_exception: |
0a39bb32 PA |
5848 | if (bs->stop) |
5849 | { | |
5850 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5851 | retval.is_longjmp = bptype != bp_exception; | |
5852 | } | |
5853 | else | |
5854 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5855 | break; |
5856 | case bp_longjmp_resume: | |
186c406b | 5857 | case bp_exception_resume: |
0a39bb32 PA |
5858 | if (bs->stop) |
5859 | { | |
5860 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5861 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5862 | } | |
5863 | else | |
5864 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5865 | break; |
5866 | case bp_step_resume: | |
5867 | if (bs->stop) | |
628fe4e4 JK |
5868 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5869 | else | |
c906108c | 5870 | { |
628fe4e4 JK |
5871 | /* It is for the wrong frame. */ |
5872 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5873 | } |
c906108c | 5874 | break; |
2c03e5be PA |
5875 | case bp_hp_step_resume: |
5876 | if (bs->stop) | |
5877 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5878 | else | |
5879 | { | |
5880 | /* It is for the wrong frame. */ | |
5881 | this_action = BPSTAT_WHAT_SINGLE; | |
5882 | } | |
5883 | break; | |
c906108c | 5884 | case bp_watchpoint_scope: |
c4093a6a | 5885 | case bp_thread_event: |
1900040c | 5886 | case bp_overlay_event: |
0fd8e87f | 5887 | case bp_longjmp_master: |
aa7d318d | 5888 | case bp_std_terminate_master: |
186c406b | 5889 | case bp_exception_master: |
628fe4e4 | 5890 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5891 | break; |
ce78b96d | 5892 | case bp_catchpoint: |
c5aa993b JM |
5893 | if (bs->stop) |
5894 | { | |
5895 | if (bs->print) | |
628fe4e4 | 5896 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5897 | else |
628fe4e4 | 5898 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5899 | } |
5900 | else | |
628fe4e4 JK |
5901 | { |
5902 | /* There was a catchpoint, but we're not stopping. | |
5903 | This requires no further action. */ | |
5904 | } | |
5905 | break; | |
628fe4e4 JK |
5906 | case bp_jit_event: |
5907 | jit_event = 1; | |
5908 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5909 | break; |
c906108c | 5910 | case bp_call_dummy: |
53a5351d JM |
5911 | /* Make sure the action is stop (silent or noisy), |
5912 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5913 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5914 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5915 | break; |
5916 | case bp_std_terminate: | |
5917 | /* Make sure the action is stop (silent or noisy), | |
5918 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5919 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5920 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5921 | break; |
1042e4c0 | 5922 | case bp_tracepoint: |
7a697b8d | 5923 | case bp_fast_tracepoint: |
0fb4aa4b | 5924 | case bp_static_tracepoint: |
1042e4c0 SS |
5925 | /* Tracepoint hits should not be reported back to GDB, and |
5926 | if one got through somehow, it should have been filtered | |
5927 | out already. */ | |
5928 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5929 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5930 | break; |
5931 | case bp_gnu_ifunc_resolver: | |
5932 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5933 | this_action = BPSTAT_WHAT_SINGLE; | |
5934 | break; | |
5935 | case bp_gnu_ifunc_resolver_return: | |
5936 | /* The breakpoint will be removed, execution will restart from the | |
5937 | PC of the former breakpoint. */ | |
5938 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5939 | break; | |
e7e0cddf SS |
5940 | |
5941 | case bp_dprintf: | |
a11cfd87 HZ |
5942 | if (bs->stop) |
5943 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5944 | else | |
5945 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5946 | break; |
5947 | ||
628fe4e4 JK |
5948 | default: |
5949 | internal_error (__FILE__, __LINE__, | |
5950 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5951 | } |
628fe4e4 JK |
5952 | |
5953 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5954 | } |
628fe4e4 | 5955 | |
243a9253 PA |
5956 | return retval; |
5957 | } | |
628fe4e4 | 5958 | |
243a9253 PA |
5959 | void |
5960 | bpstat_run_callbacks (bpstat bs_head) | |
5961 | { | |
5962 | bpstat bs; | |
628fe4e4 | 5963 | |
0e30163f JK |
5964 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5965 | { | |
5966 | struct breakpoint *b = bs->breakpoint_at; | |
5967 | ||
5968 | if (b == NULL) | |
5969 | continue; | |
5970 | switch (b->type) | |
5971 | { | |
243a9253 PA |
5972 | case bp_jit_event: |
5973 | handle_jit_event (); | |
5974 | break; | |
0e30163f JK |
5975 | case bp_gnu_ifunc_resolver: |
5976 | gnu_ifunc_resolver_stop (b); | |
5977 | break; | |
5978 | case bp_gnu_ifunc_resolver_return: | |
5979 | gnu_ifunc_resolver_return_stop (b); | |
5980 | break; | |
5981 | } | |
5982 | } | |
c906108c SS |
5983 | } |
5984 | ||
5985 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5986 | without hardware support). This isn't related to a specific bpstat, | |
5987 | just to things like whether watchpoints are set. */ | |
5988 | ||
c5aa993b | 5989 | int |
fba45db2 | 5990 | bpstat_should_step (void) |
c906108c SS |
5991 | { |
5992 | struct breakpoint *b; | |
cc59ec59 | 5993 | |
c906108c | 5994 | ALL_BREAKPOINTS (b) |
717a8278 | 5995 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5996 | return 1; |
c906108c SS |
5997 | return 0; |
5998 | } | |
5999 | ||
67822962 PA |
6000 | int |
6001 | bpstat_causes_stop (bpstat bs) | |
6002 | { | |
6003 | for (; bs != NULL; bs = bs->next) | |
6004 | if (bs->stop) | |
6005 | return 1; | |
6006 | ||
6007 | return 0; | |
6008 | } | |
6009 | ||
c906108c | 6010 | \f |
c5aa993b | 6011 | |
170b53b2 UW |
6012 | /* Compute a string of spaces suitable to indent the next line |
6013 | so it starts at the position corresponding to the table column | |
6014 | named COL_NAME in the currently active table of UIOUT. */ | |
6015 | ||
6016 | static char * | |
6017 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6018 | { | |
6019 | static char wrap_indent[80]; | |
6020 | int i, total_width, width, align; | |
6021 | char *text; | |
6022 | ||
6023 | total_width = 0; | |
6024 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6025 | { | |
6026 | if (strcmp (text, col_name) == 0) | |
6027 | { | |
6028 | gdb_assert (total_width < sizeof wrap_indent); | |
6029 | memset (wrap_indent, ' ', total_width); | |
6030 | wrap_indent[total_width] = 0; | |
6031 | ||
6032 | return wrap_indent; | |
6033 | } | |
6034 | ||
6035 | total_width += width + 1; | |
6036 | } | |
6037 | ||
6038 | return NULL; | |
6039 | } | |
6040 | ||
b775012e LM |
6041 | /* Determine if the locations of this breakpoint will have their conditions |
6042 | evaluated by the target, host or a mix of both. Returns the following: | |
6043 | ||
6044 | "host": Host evals condition. | |
6045 | "host or target": Host or Target evals condition. | |
6046 | "target": Target evals condition. | |
6047 | */ | |
6048 | ||
6049 | static const char * | |
6050 | bp_condition_evaluator (struct breakpoint *b) | |
6051 | { | |
6052 | struct bp_location *bl; | |
6053 | char host_evals = 0; | |
6054 | char target_evals = 0; | |
6055 | ||
6056 | if (!b) | |
6057 | return NULL; | |
6058 | ||
6059 | if (!is_breakpoint (b)) | |
6060 | return NULL; | |
6061 | ||
6062 | if (gdb_evaluates_breakpoint_condition_p () | |
6063 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6064 | return condition_evaluation_host; | |
6065 | ||
6066 | for (bl = b->loc; bl; bl = bl->next) | |
6067 | { | |
6068 | if (bl->cond_bytecode) | |
6069 | target_evals++; | |
6070 | else | |
6071 | host_evals++; | |
6072 | } | |
6073 | ||
6074 | if (host_evals && target_evals) | |
6075 | return condition_evaluation_both; | |
6076 | else if (target_evals) | |
6077 | return condition_evaluation_target; | |
6078 | else | |
6079 | return condition_evaluation_host; | |
6080 | } | |
6081 | ||
6082 | /* Determine the breakpoint location's condition evaluator. This is | |
6083 | similar to bp_condition_evaluator, but for locations. */ | |
6084 | ||
6085 | static const char * | |
6086 | bp_location_condition_evaluator (struct bp_location *bl) | |
6087 | { | |
6088 | if (bl && !is_breakpoint (bl->owner)) | |
6089 | return NULL; | |
6090 | ||
6091 | if (gdb_evaluates_breakpoint_condition_p () | |
6092 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6093 | return condition_evaluation_host; | |
6094 | ||
6095 | if (bl && bl->cond_bytecode) | |
6096 | return condition_evaluation_target; | |
6097 | else | |
6098 | return condition_evaluation_host; | |
6099 | } | |
6100 | ||
859825b8 JK |
6101 | /* Print the LOC location out of the list of B->LOC locations. */ |
6102 | ||
170b53b2 UW |
6103 | static void |
6104 | print_breakpoint_location (struct breakpoint *b, | |
6105 | struct bp_location *loc) | |
0d381245 | 6106 | { |
79a45e25 | 6107 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6108 | struct cleanup *old_chain = save_current_program_space (); |
6109 | ||
859825b8 JK |
6110 | if (loc != NULL && loc->shlib_disabled) |
6111 | loc = NULL; | |
6112 | ||
6c95b8df PA |
6113 | if (loc != NULL) |
6114 | set_current_program_space (loc->pspace); | |
6115 | ||
56435ebe | 6116 | if (b->display_canonical) |
f00aae0f KS |
6117 | ui_out_field_string (uiout, "what", |
6118 | event_location_to_string (b->location)); | |
2f202fde | 6119 | else if (loc && loc->symtab) |
0d381245 VP |
6120 | { |
6121 | struct symbol *sym | |
6122 | = find_pc_sect_function (loc->address, loc->section); | |
6123 | if (sym) | |
6124 | { | |
6125 | ui_out_text (uiout, "in "); | |
6126 | ui_out_field_string (uiout, "func", | |
6127 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6128 | ui_out_text (uiout, " "); |
6129 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6130 | ui_out_text (uiout, "at "); | |
0d381245 | 6131 | } |
05cba821 JK |
6132 | ui_out_field_string (uiout, "file", |
6133 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6134 | ui_out_text (uiout, ":"); |
05cba821 | 6135 | |
0d381245 | 6136 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6137 | ui_out_field_string (uiout, "fullname", |
6138 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6139 | |
f8eba3c6 | 6140 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6141 | } |
859825b8 | 6142 | else if (loc) |
0d381245 | 6143 | { |
f99d8bf4 PA |
6144 | struct ui_file *stb = mem_fileopen (); |
6145 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6146 | |
f99d8bf4 | 6147 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6148 | demangle, ""); |
0d381245 | 6149 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6150 | |
6151 | do_cleanups (stb_chain); | |
0d381245 | 6152 | } |
859825b8 | 6153 | else |
f00aae0f KS |
6154 | { |
6155 | ui_out_field_string (uiout, "pending", | |
6156 | event_location_to_string (b->location)); | |
6157 | /* If extra_string is available, it could be holding a condition | |
6158 | or dprintf arguments. In either case, make sure it is printed, | |
6159 | too, but only for non-MI streams. */ | |
6160 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6161 | { | |
6162 | if (b->type == bp_dprintf) | |
6163 | ui_out_text (uiout, ","); | |
6164 | else | |
6165 | ui_out_text (uiout, " "); | |
6166 | ui_out_text (uiout, b->extra_string); | |
6167 | } | |
6168 | } | |
6c95b8df | 6169 | |
b775012e LM |
6170 | if (loc && is_breakpoint (b) |
6171 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6172 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6173 | { | |
6174 | ui_out_text (uiout, " ("); | |
6175 | ui_out_field_string (uiout, "evaluated-by", | |
6176 | bp_location_condition_evaluator (loc)); | |
6177 | ui_out_text (uiout, ")"); | |
6178 | } | |
6179 | ||
6c95b8df | 6180 | do_cleanups (old_chain); |
0d381245 VP |
6181 | } |
6182 | ||
269b11a2 PA |
6183 | static const char * |
6184 | bptype_string (enum bptype type) | |
c906108c | 6185 | { |
c4093a6a JM |
6186 | struct ep_type_description |
6187 | { | |
6188 | enum bptype type; | |
6189 | char *description; | |
6190 | }; | |
6191 | static struct ep_type_description bptypes[] = | |
c906108c | 6192 | { |
c5aa993b JM |
6193 | {bp_none, "?deleted?"}, |
6194 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6195 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6196 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6197 | {bp_until, "until"}, |
6198 | {bp_finish, "finish"}, | |
6199 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6200 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6201 | {bp_read_watchpoint, "read watchpoint"}, |
6202 | {bp_access_watchpoint, "acc watchpoint"}, | |
6203 | {bp_longjmp, "longjmp"}, | |
6204 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6205 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6206 | {bp_exception, "exception"}, |
6207 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6208 | {bp_step_resume, "step resume"}, |
2c03e5be | 6209 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6210 | {bp_watchpoint_scope, "watchpoint scope"}, |
6211 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6212 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6213 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6214 | {bp_thread_event, "thread events"}, |
1900040c | 6215 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6216 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6217 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6218 | {bp_exception_master, "exception master"}, |
ce78b96d | 6219 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6220 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6221 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6222 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6223 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6224 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6225 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6226 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6227 | }; |
269b11a2 PA |
6228 | |
6229 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6230 | || ((int) type != bptypes[(int) type].type)) | |
6231 | internal_error (__FILE__, __LINE__, | |
6232 | _("bptypes table does not describe type #%d."), | |
6233 | (int) type); | |
6234 | ||
6235 | return bptypes[(int) type].description; | |
6236 | } | |
6237 | ||
998580f1 MK |
6238 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6239 | For CLI, prefix the list with the string 'inf'. */ | |
6240 | ||
6241 | static void | |
6242 | output_thread_groups (struct ui_out *uiout, | |
6243 | const char *field_name, | |
6244 | VEC(int) *inf_num, | |
6245 | int mi_only) | |
6246 | { | |
752eb8b4 | 6247 | struct cleanup *back_to; |
998580f1 MK |
6248 | int is_mi = ui_out_is_mi_like_p (uiout); |
6249 | int inf; | |
6250 | int i; | |
6251 | ||
6252 | /* For backward compatibility, don't display inferiors in CLI unless | |
6253 | there are several. Always display them for MI. */ | |
6254 | if (!is_mi && mi_only) | |
6255 | return; | |
6256 | ||
752eb8b4 TT |
6257 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6258 | ||
998580f1 MK |
6259 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6260 | { | |
6261 | if (is_mi) | |
6262 | { | |
6263 | char mi_group[10]; | |
6264 | ||
6265 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6266 | ui_out_field_string (uiout, NULL, mi_group); | |
6267 | } | |
6268 | else | |
6269 | { | |
6270 | if (i == 0) | |
6271 | ui_out_text (uiout, " inf "); | |
6272 | else | |
6273 | ui_out_text (uiout, ", "); | |
6274 | ||
6275 | ui_out_text (uiout, plongest (inf)); | |
6276 | } | |
6277 | } | |
6278 | ||
6279 | do_cleanups (back_to); | |
6280 | } | |
6281 | ||
269b11a2 PA |
6282 | /* Print B to gdb_stdout. */ |
6283 | ||
6284 | static void | |
6285 | print_one_breakpoint_location (struct breakpoint *b, | |
6286 | struct bp_location *loc, | |
6287 | int loc_number, | |
6288 | struct bp_location **last_loc, | |
269b11a2 PA |
6289 | int allflag) |
6290 | { | |
6291 | struct command_line *l; | |
c2c6d25f | 6292 | static char bpenables[] = "nynny"; |
c906108c | 6293 | |
79a45e25 | 6294 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6295 | int header_of_multiple = 0; |
6296 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6297 | struct value_print_options opts; |
6298 | ||
6299 | get_user_print_options (&opts); | |
0d381245 VP |
6300 | |
6301 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6302 | /* See comment in print_one_breakpoint concerning treatment of |
6303 | breakpoints with single disabled location. */ | |
0d381245 VP |
6304 | if (loc == NULL |
6305 | && (b->loc != NULL | |
6306 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6307 | header_of_multiple = 1; | |
6308 | if (loc == NULL) | |
6309 | loc = b->loc; | |
6310 | ||
c4093a6a JM |
6311 | annotate_record (); |
6312 | ||
6313 | /* 1 */ | |
6314 | annotate_field (0); | |
0d381245 VP |
6315 | if (part_of_multiple) |
6316 | { | |
6317 | char *formatted; | |
0c6773c1 | 6318 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6319 | ui_out_field_string (uiout, "number", formatted); |
6320 | xfree (formatted); | |
6321 | } | |
6322 | else | |
6323 | { | |
6324 | ui_out_field_int (uiout, "number", b->number); | |
6325 | } | |
c4093a6a JM |
6326 | |
6327 | /* 2 */ | |
6328 | annotate_field (1); | |
0d381245 VP |
6329 | if (part_of_multiple) |
6330 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6331 | else |
6332 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6333 | |
6334 | /* 3 */ | |
6335 | annotate_field (2); | |
0d381245 VP |
6336 | if (part_of_multiple) |
6337 | ui_out_field_skip (uiout, "disp"); | |
6338 | else | |
2cec12e5 | 6339 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6340 | |
c4093a6a JM |
6341 | |
6342 | /* 4 */ | |
6343 | annotate_field (3); | |
0d381245 | 6344 | if (part_of_multiple) |
54e52265 | 6345 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6346 | else |
4a64f543 MS |
6347 | ui_out_field_fmt (uiout, "enabled", "%c", |
6348 | bpenables[(int) b->enable_state]); | |
54e52265 | 6349 | ui_out_spaces (uiout, 2); |
0d381245 | 6350 | |
c4093a6a JM |
6351 | |
6352 | /* 5 and 6 */ | |
3086aeae | 6353 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6354 | { |
4a64f543 MS |
6355 | /* Although the print_one can possibly print all locations, |
6356 | calling it here is not likely to get any nice result. So, | |
6357 | make sure there's just one location. */ | |
0d381245 | 6358 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6359 | b->ops->print_one (b, last_loc); |
0d381245 | 6360 | } |
3086aeae DJ |
6361 | else |
6362 | switch (b->type) | |
6363 | { | |
6364 | case bp_none: | |
6365 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6366 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6367 | break; |
c906108c | 6368 | |
3086aeae DJ |
6369 | case bp_watchpoint: |
6370 | case bp_hardware_watchpoint: | |
6371 | case bp_read_watchpoint: | |
6372 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6373 | { |
6374 | struct watchpoint *w = (struct watchpoint *) b; | |
6375 | ||
6376 | /* Field 4, the address, is omitted (which makes the columns | |
6377 | not line up too nicely with the headers, but the effect | |
6378 | is relatively readable). */ | |
6379 | if (opts.addressprint) | |
6380 | ui_out_field_skip (uiout, "addr"); | |
6381 | annotate_field (5); | |
6382 | ui_out_field_string (uiout, "what", w->exp_string); | |
6383 | } | |
3086aeae DJ |
6384 | break; |
6385 | ||
3086aeae DJ |
6386 | case bp_breakpoint: |
6387 | case bp_hardware_breakpoint: | |
7c16b83e | 6388 | case bp_single_step: |
3086aeae DJ |
6389 | case bp_until: |
6390 | case bp_finish: | |
6391 | case bp_longjmp: | |
6392 | case bp_longjmp_resume: | |
e2e4d78b | 6393 | case bp_longjmp_call_dummy: |
186c406b TT |
6394 | case bp_exception: |
6395 | case bp_exception_resume: | |
3086aeae | 6396 | case bp_step_resume: |
2c03e5be | 6397 | case bp_hp_step_resume: |
3086aeae DJ |
6398 | case bp_watchpoint_scope: |
6399 | case bp_call_dummy: | |
aa7d318d | 6400 | case bp_std_terminate: |
3086aeae DJ |
6401 | case bp_shlib_event: |
6402 | case bp_thread_event: | |
6403 | case bp_overlay_event: | |
0fd8e87f | 6404 | case bp_longjmp_master: |
aa7d318d | 6405 | case bp_std_terminate_master: |
186c406b | 6406 | case bp_exception_master: |
1042e4c0 | 6407 | case bp_tracepoint: |
7a697b8d | 6408 | case bp_fast_tracepoint: |
0fb4aa4b | 6409 | case bp_static_tracepoint: |
e7e0cddf | 6410 | case bp_dprintf: |
4efc6507 | 6411 | case bp_jit_event: |
0e30163f JK |
6412 | case bp_gnu_ifunc_resolver: |
6413 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6414 | if (opts.addressprint) |
3086aeae DJ |
6415 | { |
6416 | annotate_field (4); | |
54e52265 | 6417 | if (header_of_multiple) |
0d381245 | 6418 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6419 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6420 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6421 | else |
5af949e3 UW |
6422 | ui_out_field_core_addr (uiout, "addr", |
6423 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6424 | } |
6425 | annotate_field (5); | |
0d381245 | 6426 | if (!header_of_multiple) |
170b53b2 | 6427 | print_breakpoint_location (b, loc); |
0d381245 | 6428 | if (b->loc) |
a6d9a66e | 6429 | *last_loc = b->loc; |
3086aeae DJ |
6430 | break; |
6431 | } | |
c906108c | 6432 | |
6c95b8df | 6433 | |
998580f1 | 6434 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6435 | { |
6436 | struct inferior *inf; | |
998580f1 MK |
6437 | VEC(int) *inf_num = NULL; |
6438 | int mi_only = 1; | |
6c95b8df | 6439 | |
998580f1 | 6440 | ALL_INFERIORS (inf) |
6c95b8df PA |
6441 | { |
6442 | if (inf->pspace == loc->pspace) | |
998580f1 | 6443 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6444 | } |
998580f1 MK |
6445 | |
6446 | /* For backward compatibility, don't display inferiors in CLI unless | |
6447 | there are several. Always display for MI. */ | |
6448 | if (allflag | |
6449 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6450 | && (number_of_program_spaces () > 1 | |
6451 | || number_of_inferiors () > 1) | |
6452 | /* LOC is for existing B, it cannot be in | |
6453 | moribund_locations and thus having NULL OWNER. */ | |
6454 | && loc->owner->type != bp_catchpoint)) | |
6455 | mi_only = 0; | |
6456 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6457 | VEC_free (int, inf_num); | |
6c95b8df PA |
6458 | } |
6459 | ||
4a306c9a | 6460 | if (!part_of_multiple) |
c4093a6a | 6461 | { |
4a306c9a JB |
6462 | if (b->thread != -1) |
6463 | { | |
6464 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6465 | "stop only in" line a little further down. */ |
4a306c9a JB |
6466 | ui_out_text (uiout, " thread "); |
6467 | ui_out_field_int (uiout, "thread", b->thread); | |
6468 | } | |
6469 | else if (b->task != 0) | |
6470 | { | |
6471 | ui_out_text (uiout, " task "); | |
6472 | ui_out_field_int (uiout, "task", b->task); | |
6473 | } | |
c4093a6a | 6474 | } |
f1310107 | 6475 | |
8b93c638 | 6476 | ui_out_text (uiout, "\n"); |
f1310107 | 6477 | |
348d480f | 6478 | if (!part_of_multiple) |
f1310107 TJB |
6479 | b->ops->print_one_detail (b, uiout); |
6480 | ||
0d381245 | 6481 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6482 | { |
6483 | annotate_field (6); | |
8b93c638 | 6484 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6485 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6486 | the frame ID. */ |
5af949e3 UW |
6487 | ui_out_field_core_addr (uiout, "frame", |
6488 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6489 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6490 | } |
6491 | ||
28010a5d | 6492 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6493 | { |
6494 | annotate_field (7); | |
d77f58be | 6495 | if (is_tracepoint (b)) |
1042e4c0 SS |
6496 | ui_out_text (uiout, "\ttrace only if "); |
6497 | else | |
6498 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6499 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6500 | |
6501 | /* Print whether the target is doing the breakpoint's condition | |
6502 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6503 | if (is_breakpoint (b) | |
6504 | && breakpoint_condition_evaluation_mode () | |
6505 | == condition_evaluation_target) | |
6506 | { | |
6507 | ui_out_text (uiout, " ("); | |
6508 | ui_out_field_string (uiout, "evaluated-by", | |
6509 | bp_condition_evaluator (b)); | |
6510 | ui_out_text (uiout, " evals)"); | |
6511 | } | |
0101ce28 JJ |
6512 | ui_out_text (uiout, "\n"); |
6513 | } | |
6514 | ||
0d381245 | 6515 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6516 | { |
4a64f543 | 6517 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6518 | ui_out_text (uiout, "\tstop only in thread "); |
6519 | ui_out_field_int (uiout, "thread", b->thread); | |
6520 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6521 | } |
6522 | ||
556ec64d YQ |
6523 | if (!part_of_multiple) |
6524 | { | |
6525 | if (b->hit_count) | |
31f56a27 YQ |
6526 | { |
6527 | /* FIXME should make an annotation for this. */ | |
6528 | if (is_catchpoint (b)) | |
6529 | ui_out_text (uiout, "\tcatchpoint"); | |
6530 | else if (is_tracepoint (b)) | |
6531 | ui_out_text (uiout, "\ttracepoint"); | |
6532 | else | |
6533 | ui_out_text (uiout, "\tbreakpoint"); | |
6534 | ui_out_text (uiout, " already hit "); | |
6535 | ui_out_field_int (uiout, "times", b->hit_count); | |
6536 | if (b->hit_count == 1) | |
6537 | ui_out_text (uiout, " time\n"); | |
6538 | else | |
6539 | ui_out_text (uiout, " times\n"); | |
6540 | } | |
556ec64d YQ |
6541 | else |
6542 | { | |
31f56a27 YQ |
6543 | /* Output the count also if it is zero, but only if this is mi. */ |
6544 | if (ui_out_is_mi_like_p (uiout)) | |
6545 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6546 | } |
6547 | } | |
8b93c638 | 6548 | |
0d381245 | 6549 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6550 | { |
6551 | annotate_field (8); | |
8b93c638 JM |
6552 | ui_out_text (uiout, "\tignore next "); |
6553 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6554 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6555 | } |
059fb39f | 6556 | |
816338b5 SS |
6557 | /* Note that an enable count of 1 corresponds to "enable once" |
6558 | behavior, which is reported by the combination of enablement and | |
6559 | disposition, so we don't need to mention it here. */ | |
6560 | if (!part_of_multiple && b->enable_count > 1) | |
6561 | { | |
6562 | annotate_field (8); | |
6563 | ui_out_text (uiout, "\tdisable after "); | |
6564 | /* Tweak the wording to clarify that ignore and enable counts | |
6565 | are distinct, and have additive effect. */ | |
6566 | if (b->ignore_count) | |
6567 | ui_out_text (uiout, "additional "); | |
6568 | else | |
6569 | ui_out_text (uiout, "next "); | |
6570 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6571 | ui_out_text (uiout, " hits\n"); | |
6572 | } | |
6573 | ||
f196051f SS |
6574 | if (!part_of_multiple && is_tracepoint (b)) |
6575 | { | |
6576 | struct tracepoint *tp = (struct tracepoint *) b; | |
6577 | ||
6578 | if (tp->traceframe_usage) | |
6579 | { | |
6580 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6581 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6582 | ui_out_text (uiout, " bytes\n"); | |
6583 | } | |
6584 | } | |
d3ce09f5 | 6585 | |
9add0f1b | 6586 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6587 | if (!part_of_multiple && l) |
c4093a6a | 6588 | { |
3b31d625 EZ |
6589 | struct cleanup *script_chain; |
6590 | ||
c4093a6a | 6591 | annotate_field (9); |
3b31d625 | 6592 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6593 | print_command_lines (uiout, l, 4); |
3b31d625 | 6594 | do_cleanups (script_chain); |
c4093a6a | 6595 | } |
d24317b4 | 6596 | |
d9b3f62e | 6597 | if (is_tracepoint (b)) |
1042e4c0 | 6598 | { |
d9b3f62e PA |
6599 | struct tracepoint *t = (struct tracepoint *) b; |
6600 | ||
6601 | if (!part_of_multiple && t->pass_count) | |
6602 | { | |
6603 | annotate_field (10); | |
6604 | ui_out_text (uiout, "\tpass count "); | |
6605 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6606 | ui_out_text (uiout, " \n"); | |
6607 | } | |
f2a8bc8a YQ |
6608 | |
6609 | /* Don't display it when tracepoint or tracepoint location is | |
6610 | pending. */ | |
6611 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6612 | { | |
6613 | annotate_field (11); | |
6614 | ||
6615 | if (ui_out_is_mi_like_p (uiout)) | |
6616 | ui_out_field_string (uiout, "installed", | |
6617 | loc->inserted ? "y" : "n"); | |
6618 | else | |
6619 | { | |
6620 | if (loc->inserted) | |
6621 | ui_out_text (uiout, "\t"); | |
6622 | else | |
6623 | ui_out_text (uiout, "\tnot "); | |
6624 | ui_out_text (uiout, "installed on target\n"); | |
6625 | } | |
6626 | } | |
1042e4c0 SS |
6627 | } |
6628 | ||
d24317b4 VP |
6629 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6630 | { | |
3a5c3e22 PA |
6631 | if (is_watchpoint (b)) |
6632 | { | |
6633 | struct watchpoint *w = (struct watchpoint *) b; | |
6634 | ||
6635 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6636 | } | |
f00aae0f KS |
6637 | else if (b->location != NULL |
6638 | && event_location_to_string (b->location) != NULL) | |
6639 | ui_out_field_string (uiout, "original-location", | |
6640 | event_location_to_string (b->location)); | |
d24317b4 | 6641 | } |
c4093a6a | 6642 | } |
c5aa993b | 6643 | |
0d381245 VP |
6644 | static void |
6645 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6646 | struct bp_location **last_loc, |
6c95b8df | 6647 | int allflag) |
0d381245 | 6648 | { |
8d3788bd | 6649 | struct cleanup *bkpt_chain; |
79a45e25 | 6650 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6651 | |
6652 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6653 | ||
12c5a436 | 6654 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6655 | do_cleanups (bkpt_chain); |
0d381245 VP |
6656 | |
6657 | /* If this breakpoint has custom print function, | |
6658 | it's already printed. Otherwise, print individual | |
6659 | locations, if any. */ | |
6660 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6661 | { | |
4a64f543 MS |
6662 | /* If breakpoint has a single location that is disabled, we |
6663 | print it as if it had several locations, since otherwise it's | |
6664 | hard to represent "breakpoint enabled, location disabled" | |
6665 | situation. | |
6666 | ||
6667 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6668 | internally, that's not a property exposed to user. */ |
0d381245 | 6669 | if (b->loc |
a5606eee | 6670 | && !is_hardware_watchpoint (b) |
8d3788bd | 6671 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6672 | { |
6673 | struct bp_location *loc; | |
6674 | int n = 1; | |
8d3788bd | 6675 | |
0d381245 | 6676 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6677 | { |
6678 | struct cleanup *inner2 = | |
6679 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6680 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6681 | do_cleanups (inner2); | |
6682 | } | |
0d381245 VP |
6683 | } |
6684 | } | |
6685 | } | |
6686 | ||
a6d9a66e UW |
6687 | static int |
6688 | breakpoint_address_bits (struct breakpoint *b) | |
6689 | { | |
6690 | int print_address_bits = 0; | |
6691 | struct bp_location *loc; | |
6692 | ||
c6d81124 PA |
6693 | /* Software watchpoints that aren't watching memory don't have an |
6694 | address to print. */ | |
6695 | if (is_no_memory_software_watchpoint (b)) | |
6696 | return 0; | |
6697 | ||
a6d9a66e UW |
6698 | for (loc = b->loc; loc; loc = loc->next) |
6699 | { | |
c7437ca6 PA |
6700 | int addr_bit; |
6701 | ||
c7437ca6 | 6702 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6703 | if (addr_bit > print_address_bits) |
6704 | print_address_bits = addr_bit; | |
6705 | } | |
6706 | ||
6707 | return print_address_bits; | |
6708 | } | |
0d381245 | 6709 | |
c4093a6a JM |
6710 | struct captured_breakpoint_query_args |
6711 | { | |
6712 | int bnum; | |
6713 | }; | |
c5aa993b | 6714 | |
c4093a6a | 6715 | static int |
2b65245e | 6716 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6717 | { |
9a3c8263 SM |
6718 | struct captured_breakpoint_query_args *args |
6719 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6720 | struct breakpoint *b; |
a6d9a66e | 6721 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6722 | |
c4093a6a JM |
6723 | ALL_BREAKPOINTS (b) |
6724 | { | |
6725 | if (args->bnum == b->number) | |
c5aa993b | 6726 | { |
12c5a436 | 6727 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6728 | return GDB_RC_OK; |
c5aa993b | 6729 | } |
c4093a6a JM |
6730 | } |
6731 | return GDB_RC_NONE; | |
6732 | } | |
c5aa993b | 6733 | |
c4093a6a | 6734 | enum gdb_rc |
4a64f543 MS |
6735 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6736 | char **error_message) | |
c4093a6a JM |
6737 | { |
6738 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6739 | |
c4093a6a JM |
6740 | args.bnum = bnum; |
6741 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6742 | an error. */ |
b0b13bb4 DJ |
6743 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6744 | error_message, RETURN_MASK_ALL) < 0) | |
6745 | return GDB_RC_FAIL; | |
6746 | else | |
6747 | return GDB_RC_OK; | |
c4093a6a | 6748 | } |
c5aa993b | 6749 | |
09d682a4 TT |
6750 | /* Return true if this breakpoint was set by the user, false if it is |
6751 | internal or momentary. */ | |
6752 | ||
6753 | int | |
6754 | user_breakpoint_p (struct breakpoint *b) | |
6755 | { | |
46c6471b | 6756 | return b->number > 0; |
09d682a4 TT |
6757 | } |
6758 | ||
7f3b0473 | 6759 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6760 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6761 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6762 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6763 | ones for which it returns non-zero. Return the total number of | |
6764 | breakpoints listed. */ | |
c906108c | 6765 | |
d77f58be | 6766 | static int |
e5a67952 | 6767 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6768 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6769 | { |
52f0bd74 | 6770 | struct breakpoint *b; |
a6d9a66e | 6771 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6772 | int nr_printable_breakpoints; |
3b31d625 | 6773 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6774 | struct value_print_options opts; |
a6d9a66e | 6775 | int print_address_bits = 0; |
269b11a2 | 6776 | int print_type_col_width = 14; |
79a45e25 | 6777 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6778 | |
79a45b7d TT |
6779 | get_user_print_options (&opts); |
6780 | ||
4a64f543 MS |
6781 | /* Compute the number of rows in the table, as well as the size |
6782 | required for address fields. */ | |
7f3b0473 AC |
6783 | nr_printable_breakpoints = 0; |
6784 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6785 | { |
6786 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6787 | if (filter && !filter (b)) | |
6788 | continue; | |
6789 | ||
6790 | /* If we have an "args" string, it is a list of breakpoints to | |
6791 | accept. Skip the others. */ | |
6792 | if (args != NULL && *args != '\0') | |
6793 | { | |
6794 | if (allflag && parse_and_eval_long (args) != b->number) | |
6795 | continue; | |
6796 | if (!allflag && !number_is_in_list (args, b->number)) | |
6797 | continue; | |
6798 | } | |
269b11a2 | 6799 | |
e5a67952 MS |
6800 | if (allflag || user_breakpoint_p (b)) |
6801 | { | |
6802 | int addr_bit, type_len; | |
a6d9a66e | 6803 | |
e5a67952 MS |
6804 | addr_bit = breakpoint_address_bits (b); |
6805 | if (addr_bit > print_address_bits) | |
6806 | print_address_bits = addr_bit; | |
269b11a2 | 6807 | |
e5a67952 MS |
6808 | type_len = strlen (bptype_string (b->type)); |
6809 | if (type_len > print_type_col_width) | |
6810 | print_type_col_width = type_len; | |
6811 | ||
6812 | nr_printable_breakpoints++; | |
6813 | } | |
6814 | } | |
7f3b0473 | 6815 | |
79a45b7d | 6816 | if (opts.addressprint) |
3b31d625 | 6817 | bkpttbl_chain |
3e43a32a MS |
6818 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6819 | nr_printable_breakpoints, | |
3b31d625 | 6820 | "BreakpointTable"); |
8b93c638 | 6821 | else |
3b31d625 | 6822 | bkpttbl_chain |
3e43a32a MS |
6823 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6824 | nr_printable_breakpoints, | |
3b31d625 | 6825 | "BreakpointTable"); |
8b93c638 | 6826 | |
7f3b0473 | 6827 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6828 | annotate_breakpoints_headers (); |
6829 | if (nr_printable_breakpoints > 0) | |
6830 | annotate_field (0); | |
4a64f543 | 6831 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6832 | if (nr_printable_breakpoints > 0) |
6833 | annotate_field (1); | |
269b11a2 | 6834 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6835 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6836 | if (nr_printable_breakpoints > 0) |
6837 | annotate_field (2); | |
4a64f543 | 6838 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6839 | if (nr_printable_breakpoints > 0) |
6840 | annotate_field (3); | |
54e52265 | 6841 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6842 | if (opts.addressprint) |
e5a67952 MS |
6843 | { |
6844 | if (nr_printable_breakpoints > 0) | |
6845 | annotate_field (4); | |
6846 | if (print_address_bits <= 32) | |
6847 | ui_out_table_header (uiout, 10, ui_left, | |
6848 | "addr", "Address"); /* 5 */ | |
6849 | else | |
6850 | ui_out_table_header (uiout, 18, ui_left, | |
6851 | "addr", "Address"); /* 5 */ | |
6852 | } | |
d7faa9e7 AC |
6853 | if (nr_printable_breakpoints > 0) |
6854 | annotate_field (5); | |
6855 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6856 | ui_out_table_body (uiout); | |
6857 | if (nr_printable_breakpoints > 0) | |
6858 | annotate_breakpoints_table (); | |
7f3b0473 | 6859 | |
c4093a6a | 6860 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6861 | { |
6862 | QUIT; | |
6863 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6864 | if (filter && !filter (b)) | |
6865 | continue; | |
6866 | ||
6867 | /* If we have an "args" string, it is a list of breakpoints to | |
6868 | accept. Skip the others. */ | |
6869 | ||
6870 | if (args != NULL && *args != '\0') | |
6871 | { | |
6872 | if (allflag) /* maintenance info breakpoint */ | |
6873 | { | |
6874 | if (parse_and_eval_long (args) != b->number) | |
6875 | continue; | |
6876 | } | |
6877 | else /* all others */ | |
6878 | { | |
6879 | if (!number_is_in_list (args, b->number)) | |
6880 | continue; | |
6881 | } | |
6882 | } | |
6883 | /* We only print out user settable breakpoints unless the | |
6884 | allflag is set. */ | |
6885 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6886 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6887 | } |
6888 | ||
3b31d625 | 6889 | do_cleanups (bkpttbl_chain); |
698384cd | 6890 | |
7f3b0473 | 6891 | if (nr_printable_breakpoints == 0) |
c906108c | 6892 | { |
4a64f543 MS |
6893 | /* If there's a filter, let the caller decide how to report |
6894 | empty list. */ | |
d77f58be SS |
6895 | if (!filter) |
6896 | { | |
e5a67952 | 6897 | if (args == NULL || *args == '\0') |
d77f58be SS |
6898 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6899 | else | |
4a64f543 | 6900 | ui_out_message (uiout, 0, |
e5a67952 MS |
6901 | "No breakpoint or watchpoint matching '%s'.\n", |
6902 | args); | |
d77f58be | 6903 | } |
c906108c SS |
6904 | } |
6905 | else | |
c4093a6a | 6906 | { |
a6d9a66e UW |
6907 | if (last_loc && !server_command) |
6908 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6909 | } |
c906108c | 6910 | |
4a64f543 | 6911 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6912 | there have been breakpoints? */ |
c906108c | 6913 | annotate_breakpoints_table_end (); |
d77f58be SS |
6914 | |
6915 | return nr_printable_breakpoints; | |
c906108c SS |
6916 | } |
6917 | ||
ad443146 SS |
6918 | /* Display the value of default-collect in a way that is generally |
6919 | compatible with the breakpoint list. */ | |
6920 | ||
6921 | static void | |
6922 | default_collect_info (void) | |
6923 | { | |
79a45e25 PA |
6924 | struct ui_out *uiout = current_uiout; |
6925 | ||
ad443146 SS |
6926 | /* If it has no value (which is frequently the case), say nothing; a |
6927 | message like "No default-collect." gets in user's face when it's | |
6928 | not wanted. */ | |
6929 | if (!*default_collect) | |
6930 | return; | |
6931 | ||
6932 | /* The following phrase lines up nicely with per-tracepoint collect | |
6933 | actions. */ | |
6934 | ui_out_text (uiout, "default collect "); | |
6935 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6936 | ui_out_text (uiout, " \n"); | |
6937 | } | |
6938 | ||
c906108c | 6939 | static void |
e5a67952 | 6940 | breakpoints_info (char *args, int from_tty) |
c906108c | 6941 | { |
e5a67952 | 6942 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6943 | |
6944 | default_collect_info (); | |
d77f58be SS |
6945 | } |
6946 | ||
6947 | static void | |
e5a67952 | 6948 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6949 | { |
e5a67952 | 6950 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6951 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6952 | |
6953 | if (num_printed == 0) | |
6954 | { | |
e5a67952 | 6955 | if (args == NULL || *args == '\0') |
d77f58be SS |
6956 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6957 | else | |
e5a67952 | 6958 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6959 | } |
c906108c SS |
6960 | } |
6961 | ||
7a292a7a | 6962 | static void |
e5a67952 | 6963 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6964 | { |
e5a67952 | 6965 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6966 | |
6967 | default_collect_info (); | |
c906108c SS |
6968 | } |
6969 | ||
0d381245 | 6970 | static int |
714835d5 | 6971 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6972 | struct program_space *pspace, |
714835d5 | 6973 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6974 | { |
6975 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6976 | |
0d381245 VP |
6977 | for (; bl; bl = bl->next) |
6978 | { | |
6c95b8df PA |
6979 | if (bl->pspace == pspace |
6980 | && bl->address == pc | |
0d381245 VP |
6981 | && (!overlay_debugging || bl->section == section)) |
6982 | return 1; | |
6983 | } | |
6984 | return 0; | |
6985 | } | |
6986 | ||
672f9b60 | 6987 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6988 | concerns with logical breakpoints, so we match program spaces, not |
6989 | address spaces. */ | |
c906108c SS |
6990 | |
6991 | static void | |
6c95b8df PA |
6992 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6993 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6994 | struct obj_section *section, int thread) |
c906108c | 6995 | { |
52f0bd74 AC |
6996 | int others = 0; |
6997 | struct breakpoint *b; | |
c906108c SS |
6998 | |
6999 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7000 | others += (user_breakpoint_p (b) |
7001 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7002 | if (others > 0) |
7003 | { | |
a3f17187 AC |
7004 | if (others == 1) |
7005 | printf_filtered (_("Note: breakpoint ")); | |
7006 | else /* if (others == ???) */ | |
7007 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7008 | ALL_BREAKPOINTS (b) |
672f9b60 | 7009 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7010 | { |
7011 | others--; | |
7012 | printf_filtered ("%d", b->number); | |
7013 | if (b->thread == -1 && thread != -1) | |
7014 | printf_filtered (" (all threads)"); | |
7015 | else if (b->thread != -1) | |
7016 | printf_filtered (" (thread %d)", b->thread); | |
7017 | printf_filtered ("%s%s ", | |
059fb39f | 7018 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7019 | || b->enable_state == bp_call_disabled) |
0d381245 | 7020 | ? " (disabled)" |
0d381245 VP |
7021 | : ""), |
7022 | (others > 1) ? "," | |
7023 | : ((others == 1) ? " and" : "")); | |
7024 | } | |
a3f17187 | 7025 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7026 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7027 | printf_filtered (".\n"); |
7028 | } | |
7029 | } | |
7030 | \f | |
c906108c | 7031 | |
e4f237da | 7032 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7033 | BPT locations. For some breakpoint types, the locations' address members |
7034 | are irrelevant and it makes no sense to attempt to compare them to other | |
7035 | addresses (or use them for any other purpose either). | |
e4f237da | 7036 | |
4a64f543 | 7037 | More specifically, each of the following breakpoint types will |
244558af | 7038 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7039 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7040 | breakpoint location at address zero: |
e4f237da KB |
7041 | |
7042 | bp_watchpoint | |
2d134ed3 PA |
7043 | bp_catchpoint |
7044 | ||
7045 | */ | |
e4f237da KB |
7046 | |
7047 | static int | |
7048 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7049 | { | |
7050 | enum bptype type = bpt->type; | |
7051 | ||
2d134ed3 PA |
7052 | return (type != bp_watchpoint && type != bp_catchpoint); |
7053 | } | |
7054 | ||
7055 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7056 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7057 | ||
7058 | static int | |
4a64f543 MS |
7059 | watchpoint_locations_match (struct bp_location *loc1, |
7060 | struct bp_location *loc2) | |
2d134ed3 | 7061 | { |
3a5c3e22 PA |
7062 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7063 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7064 | ||
7065 | /* Both of them must exist. */ | |
7066 | gdb_assert (w1 != NULL); | |
7067 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7068 | |
4a64f543 MS |
7069 | /* If the target can evaluate the condition expression in hardware, |
7070 | then we we need to insert both watchpoints even if they are at | |
7071 | the same place. Otherwise the watchpoint will only trigger when | |
7072 | the condition of whichever watchpoint was inserted evaluates to | |
7073 | true, not giving a chance for GDB to check the condition of the | |
7074 | other watchpoint. */ | |
3a5c3e22 | 7075 | if ((w1->cond_exp |
4a64f543 MS |
7076 | && target_can_accel_watchpoint_condition (loc1->address, |
7077 | loc1->length, | |
0cf6dd15 | 7078 | loc1->watchpoint_type, |
3a5c3e22 PA |
7079 | w1->cond_exp)) |
7080 | || (w2->cond_exp | |
4a64f543 MS |
7081 | && target_can_accel_watchpoint_condition (loc2->address, |
7082 | loc2->length, | |
0cf6dd15 | 7083 | loc2->watchpoint_type, |
3a5c3e22 | 7084 | w2->cond_exp))) |
0cf6dd15 TJB |
7085 | return 0; |
7086 | ||
85d721b8 PA |
7087 | /* Note that this checks the owner's type, not the location's. In |
7088 | case the target does not support read watchpoints, but does | |
7089 | support access watchpoints, we'll have bp_read_watchpoint | |
7090 | watchpoints with hw_access locations. Those should be considered | |
7091 | duplicates of hw_read locations. The hw_read locations will | |
7092 | become hw_access locations later. */ | |
2d134ed3 PA |
7093 | return (loc1->owner->type == loc2->owner->type |
7094 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7095 | && loc1->address == loc2->address | |
7096 | && loc1->length == loc2->length); | |
e4f237da KB |
7097 | } |
7098 | ||
31e77af2 | 7099 | /* See breakpoint.h. */ |
6c95b8df | 7100 | |
31e77af2 | 7101 | int |
6c95b8df PA |
7102 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7103 | struct address_space *aspace2, CORE_ADDR addr2) | |
7104 | { | |
f5656ead | 7105 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7106 | || aspace1 == aspace2) |
7107 | && addr1 == addr2); | |
7108 | } | |
7109 | ||
f1310107 TJB |
7110 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7111 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7112 | matches ASPACE2. On targets that have global breakpoints, the address | |
7113 | space doesn't really matter. */ | |
7114 | ||
7115 | static int | |
7116 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7117 | int len1, struct address_space *aspace2, | |
7118 | CORE_ADDR addr2) | |
7119 | { | |
f5656ead | 7120 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7121 | || aspace1 == aspace2) |
7122 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7123 | } | |
7124 | ||
7125 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7126 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7127 | matches the breakpoint's address space. On targets that have global | |
7128 | breakpoints, the address space doesn't really matter. */ | |
7129 | ||
7130 | static int | |
7131 | breakpoint_location_address_match (struct bp_location *bl, | |
7132 | struct address_space *aspace, | |
7133 | CORE_ADDR addr) | |
7134 | { | |
7135 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7136 | aspace, addr) | |
7137 | || (bl->length | |
7138 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7139 | bl->address, bl->length, | |
7140 | aspace, addr))); | |
7141 | } | |
7142 | ||
d35ae833 PA |
7143 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7144 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7145 | match happens only if ASPACE matches the breakpoint's address | |
7146 | space. On targets that have global breakpoints, the address space | |
7147 | doesn't really matter. */ | |
7148 | ||
7149 | static int | |
7150 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7151 | struct address_space *aspace, | |
7152 | CORE_ADDR addr, int len) | |
7153 | { | |
7154 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7155 | || bl->pspace->aspace == aspace) | |
7156 | { | |
7157 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7158 | ||
7159 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7160 | return 1; | |
7161 | } | |
7162 | return 0; | |
7163 | } | |
7164 | ||
1e4d1764 YQ |
7165 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7166 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7167 | true, otherwise returns false. */ | |
7168 | ||
7169 | static int | |
7170 | tracepoint_locations_match (struct bp_location *loc1, | |
7171 | struct bp_location *loc2) | |
7172 | { | |
7173 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7174 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7175 | locations at the same address of different tracepoints are regarded as | |
7176 | different locations. */ | |
7177 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7178 | else | |
7179 | return 0; | |
7180 | } | |
7181 | ||
2d134ed3 PA |
7182 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7183 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7184 | represent the same location. */ | |
7185 | ||
7186 | static int | |
4a64f543 MS |
7187 | breakpoint_locations_match (struct bp_location *loc1, |
7188 | struct bp_location *loc2) | |
2d134ed3 | 7189 | { |
2bdf28a0 JK |
7190 | int hw_point1, hw_point2; |
7191 | ||
7192 | /* Both of them must not be in moribund_locations. */ | |
7193 | gdb_assert (loc1->owner != NULL); | |
7194 | gdb_assert (loc2->owner != NULL); | |
7195 | ||
7196 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7197 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7198 | |
7199 | if (hw_point1 != hw_point2) | |
7200 | return 0; | |
7201 | else if (hw_point1) | |
7202 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7203 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7204 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7205 | else |
f1310107 TJB |
7206 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7207 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7208 | loc2->pspace->aspace, loc2->address) | |
7209 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7210 | } |
7211 | ||
76897487 KB |
7212 | static void |
7213 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7214 | int bnum, int have_bnum) | |
7215 | { | |
f63fbe86 MS |
7216 | /* The longest string possibly returned by hex_string_custom |
7217 | is 50 chars. These must be at least that big for safety. */ | |
7218 | char astr1[64]; | |
7219 | char astr2[64]; | |
76897487 | 7220 | |
bb599908 PH |
7221 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7222 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7223 | if (have_bnum) |
8a3fe4f8 | 7224 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7225 | bnum, astr1, astr2); |
7226 | else | |
8a3fe4f8 | 7227 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7228 | } |
7229 | ||
4a64f543 MS |
7230 | /* Adjust a breakpoint's address to account for architectural |
7231 | constraints on breakpoint placement. Return the adjusted address. | |
7232 | Note: Very few targets require this kind of adjustment. For most | |
7233 | targets, this function is simply the identity function. */ | |
76897487 KB |
7234 | |
7235 | static CORE_ADDR | |
a6d9a66e UW |
7236 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7237 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7238 | { |
a6d9a66e | 7239 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7240 | { |
7241 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7242 | return bpaddr; | |
7243 | } | |
88f7da05 KB |
7244 | else if (bptype == bp_watchpoint |
7245 | || bptype == bp_hardware_watchpoint | |
7246 | || bptype == bp_read_watchpoint | |
7247 | || bptype == bp_access_watchpoint | |
fe798b75 | 7248 | || bptype == bp_catchpoint) |
88f7da05 KB |
7249 | { |
7250 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7251 | have their addresses modified. */ | |
7252 | return bpaddr; | |
7253 | } | |
7c16b83e PA |
7254 | else if (bptype == bp_single_step) |
7255 | { | |
7256 | /* Single-step breakpoints should not have their addresses | |
7257 | modified. If there's any architectural constrain that | |
7258 | applies to this address, then it should have already been | |
7259 | taken into account when the breakpoint was created in the | |
7260 | first place. If we didn't do this, stepping through e.g., | |
7261 | Thumb-2 IT blocks would break. */ | |
7262 | return bpaddr; | |
7263 | } | |
76897487 KB |
7264 | else |
7265 | { | |
7266 | CORE_ADDR adjusted_bpaddr; | |
7267 | ||
7268 | /* Some targets have architectural constraints on the placement | |
7269 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7270 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7271 | |
7272 | /* An adjusted breakpoint address can significantly alter | |
7273 | a user's expectations. Print a warning if an adjustment | |
7274 | is required. */ | |
7275 | if (adjusted_bpaddr != bpaddr) | |
7276 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7277 | ||
7278 | return adjusted_bpaddr; | |
7279 | } | |
7280 | } | |
7281 | ||
28010a5d PA |
7282 | void |
7283 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7284 | struct breakpoint *owner) | |
7cc221ef | 7285 | { |
7cc221ef DJ |
7286 | memset (loc, 0, sizeof (*loc)); |
7287 | ||
348d480f PA |
7288 | gdb_assert (ops != NULL); |
7289 | ||
28010a5d PA |
7290 | loc->ops = ops; |
7291 | loc->owner = owner; | |
511a6cd4 | 7292 | loc->cond = NULL; |
b775012e | 7293 | loc->cond_bytecode = NULL; |
0d381245 VP |
7294 | loc->shlib_disabled = 0; |
7295 | loc->enabled = 1; | |
e049a4b5 | 7296 | |
28010a5d | 7297 | switch (owner->type) |
e049a4b5 DJ |
7298 | { |
7299 | case bp_breakpoint: | |
7c16b83e | 7300 | case bp_single_step: |
e049a4b5 DJ |
7301 | case bp_until: |
7302 | case bp_finish: | |
7303 | case bp_longjmp: | |
7304 | case bp_longjmp_resume: | |
e2e4d78b | 7305 | case bp_longjmp_call_dummy: |
186c406b TT |
7306 | case bp_exception: |
7307 | case bp_exception_resume: | |
e049a4b5 | 7308 | case bp_step_resume: |
2c03e5be | 7309 | case bp_hp_step_resume: |
e049a4b5 DJ |
7310 | case bp_watchpoint_scope: |
7311 | case bp_call_dummy: | |
aa7d318d | 7312 | case bp_std_terminate: |
e049a4b5 DJ |
7313 | case bp_shlib_event: |
7314 | case bp_thread_event: | |
7315 | case bp_overlay_event: | |
4efc6507 | 7316 | case bp_jit_event: |
0fd8e87f | 7317 | case bp_longjmp_master: |
aa7d318d | 7318 | case bp_std_terminate_master: |
186c406b | 7319 | case bp_exception_master: |
0e30163f JK |
7320 | case bp_gnu_ifunc_resolver: |
7321 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7322 | case bp_dprintf: |
e049a4b5 | 7323 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7324 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7325 | break; |
7326 | case bp_hardware_breakpoint: | |
7327 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7328 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7329 | break; |
7330 | case bp_hardware_watchpoint: | |
7331 | case bp_read_watchpoint: | |
7332 | case bp_access_watchpoint: | |
7333 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7334 | break; | |
7335 | case bp_watchpoint: | |
ce78b96d | 7336 | case bp_catchpoint: |
15c3d785 PA |
7337 | case bp_tracepoint: |
7338 | case bp_fast_tracepoint: | |
0fb4aa4b | 7339 | case bp_static_tracepoint: |
e049a4b5 DJ |
7340 | loc->loc_type = bp_loc_other; |
7341 | break; | |
7342 | default: | |
e2e0b3e5 | 7343 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7344 | } |
7345 | ||
f431efe5 | 7346 | loc->refc = 1; |
28010a5d PA |
7347 | } |
7348 | ||
7349 | /* Allocate a struct bp_location. */ | |
7350 | ||
7351 | static struct bp_location * | |
7352 | allocate_bp_location (struct breakpoint *bpt) | |
7353 | { | |
348d480f PA |
7354 | return bpt->ops->allocate_location (bpt); |
7355 | } | |
7cc221ef | 7356 | |
f431efe5 PA |
7357 | static void |
7358 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7359 | { |
348d480f | 7360 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7361 | xfree (loc); |
7362 | } | |
7363 | ||
f431efe5 PA |
7364 | /* Increment reference count. */ |
7365 | ||
7366 | static void | |
7367 | incref_bp_location (struct bp_location *bl) | |
7368 | { | |
7369 | ++bl->refc; | |
7370 | } | |
7371 | ||
7372 | /* Decrement reference count. If the reference count reaches 0, | |
7373 | destroy the bp_location. Sets *BLP to NULL. */ | |
7374 | ||
7375 | static void | |
7376 | decref_bp_location (struct bp_location **blp) | |
7377 | { | |
0807b50c PA |
7378 | gdb_assert ((*blp)->refc > 0); |
7379 | ||
f431efe5 PA |
7380 | if (--(*blp)->refc == 0) |
7381 | free_bp_location (*blp); | |
7382 | *blp = NULL; | |
7383 | } | |
7384 | ||
346774a9 | 7385 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7386 | |
346774a9 PA |
7387 | static void |
7388 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7389 | { |
346774a9 | 7390 | struct breakpoint *b1; |
c906108c | 7391 | |
346774a9 PA |
7392 | /* Add this breakpoint to the end of the chain so that a list of |
7393 | breakpoints will come out in order of increasing numbers. */ | |
7394 | ||
7395 | b1 = breakpoint_chain; | |
7396 | if (b1 == 0) | |
7397 | breakpoint_chain = b; | |
7398 | else | |
7399 | { | |
7400 | while (b1->next) | |
7401 | b1 = b1->next; | |
7402 | b1->next = b; | |
7403 | } | |
7404 | } | |
7405 | ||
7406 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7407 | ||
7408 | static void | |
7409 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7410 | struct gdbarch *gdbarch, | |
28010a5d | 7411 | enum bptype bptype, |
c0a91b2b | 7412 | const struct breakpoint_ops *ops) |
346774a9 | 7413 | { |
c906108c | 7414 | memset (b, 0, sizeof (*b)); |
2219d63c | 7415 | |
348d480f PA |
7416 | gdb_assert (ops != NULL); |
7417 | ||
28010a5d | 7418 | b->ops = ops; |
4d28f7a8 | 7419 | b->type = bptype; |
a6d9a66e | 7420 | b->gdbarch = gdbarch; |
c906108c SS |
7421 | b->language = current_language->la_language; |
7422 | b->input_radix = input_radix; | |
7423 | b->thread = -1; | |
b5de0fa7 | 7424 | b->enable_state = bp_enabled; |
c906108c SS |
7425 | b->next = 0; |
7426 | b->silent = 0; | |
7427 | b->ignore_count = 0; | |
7428 | b->commands = NULL; | |
818dd999 | 7429 | b->frame_id = null_frame_id; |
0d381245 | 7430 | b->condition_not_parsed = 0; |
84f4c1fe | 7431 | b->py_bp_object = NULL; |
d0fb5eae | 7432 | b->related_breakpoint = b; |
f00aae0f | 7433 | b->location = NULL; |
346774a9 PA |
7434 | } |
7435 | ||
7436 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7437 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7438 | |
7439 | static struct breakpoint * | |
7440 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7441 | enum bptype bptype, |
c0a91b2b | 7442 | const struct breakpoint_ops *ops) |
346774a9 PA |
7443 | { |
7444 | struct breakpoint *b = XNEW (struct breakpoint); | |
7445 | ||
348d480f | 7446 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7447 | add_to_breakpoint_chain (b); |
0d381245 VP |
7448 | return b; |
7449 | } | |
7450 | ||
0e30163f JK |
7451 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7452 | resolutions should be made as the user specified the location explicitly | |
7453 | enough. */ | |
7454 | ||
0d381245 | 7455 | static void |
0e30163f | 7456 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7457 | { |
2bdf28a0 JK |
7458 | gdb_assert (loc->owner != NULL); |
7459 | ||
0d381245 | 7460 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7461 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7462 | || is_tracepoint (loc->owner)) |
0d381245 | 7463 | { |
0e30163f | 7464 | int is_gnu_ifunc; |
2c02bd72 | 7465 | const char *function_name; |
6a3a010b | 7466 | CORE_ADDR func_addr; |
0e30163f | 7467 | |
2c02bd72 | 7468 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7469 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7470 | |
7471 | if (is_gnu_ifunc && !explicit_loc) | |
7472 | { | |
7473 | struct breakpoint *b = loc->owner; | |
7474 | ||
7475 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7476 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7477 | &loc->requested_address)) |
7478 | { | |
7479 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7480 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7481 | loc->requested_address, | |
7482 | b->type); | |
7483 | } | |
7484 | else if (b->type == bp_breakpoint && b->loc == loc | |
7485 | && loc->next == NULL && b->related_breakpoint == b) | |
7486 | { | |
7487 | /* Create only the whole new breakpoint of this type but do not | |
7488 | mess more complicated breakpoints with multiple locations. */ | |
7489 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7490 | /* Remember the resolver's address for use by the return |
7491 | breakpoint. */ | |
7492 | loc->related_address = func_addr; | |
0e30163f JK |
7493 | } |
7494 | } | |
7495 | ||
2c02bd72 DE |
7496 | if (function_name) |
7497 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7498 | } |
7499 | } | |
7500 | ||
a6d9a66e | 7501 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7502 | struct gdbarch * |
a6d9a66e UW |
7503 | get_sal_arch (struct symtab_and_line sal) |
7504 | { | |
7505 | if (sal.section) | |
7506 | return get_objfile_arch (sal.section->objfile); | |
7507 | if (sal.symtab) | |
eb822aa6 | 7508 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7509 | |
7510 | return NULL; | |
7511 | } | |
7512 | ||
346774a9 PA |
7513 | /* Low level routine for partially initializing a breakpoint of type |
7514 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7515 | file name, and line number are provided by SAL. |
0d381245 VP |
7516 | |
7517 | It is expected that the caller will complete the initialization of | |
7518 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7519 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7520 | |
346774a9 PA |
7521 | static void |
7522 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7523 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7524 | const struct breakpoint_ops *ops) |
0d381245 | 7525 | { |
28010a5d | 7526 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7527 | |
3742cc8b | 7528 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7529 | |
6c95b8df PA |
7530 | if (bptype != bp_catchpoint) |
7531 | gdb_assert (sal.pspace != NULL); | |
7532 | ||
f8eba3c6 TT |
7533 | /* Store the program space that was used to set the breakpoint, |
7534 | except for ordinary breakpoints, which are independent of the | |
7535 | program space. */ | |
7536 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7537 | b->pspace = sal.pspace; | |
346774a9 | 7538 | } |
c906108c | 7539 | |
346774a9 PA |
7540 | /* set_raw_breakpoint is a low level routine for allocating and |
7541 | partially initializing a breakpoint of type BPTYPE. The newly | |
7542 | created breakpoint's address, section, source file name, and line | |
7543 | number are provided by SAL. The newly created and partially | |
7544 | initialized breakpoint is added to the breakpoint chain and | |
7545 | is also returned as the value of this function. | |
7546 | ||
7547 | It is expected that the caller will complete the initialization of | |
7548 | the newly created breakpoint struct as well as output any status | |
7549 | information regarding the creation of a new breakpoint. In | |
7550 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7551 | number! Care should be taken to not allow an error to occur | |
7552 | prior to completing the initialization of the breakpoint. If this | |
7553 | should happen, a bogus breakpoint will be left on the chain. */ | |
7554 | ||
7555 | struct breakpoint * | |
7556 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7557 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7558 | const struct breakpoint_ops *ops) |
346774a9 PA |
7559 | { |
7560 | struct breakpoint *b = XNEW (struct breakpoint); | |
7561 | ||
348d480f | 7562 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7563 | add_to_breakpoint_chain (b); |
c906108c SS |
7564 | return b; |
7565 | } | |
7566 | ||
53a5351d | 7567 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7568 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7569 | initiated the operation. */ | |
c906108c SS |
7570 | |
7571 | void | |
186c406b | 7572 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7573 | { |
35df4500 | 7574 | struct breakpoint *b, *b_tmp; |
186c406b | 7575 | int thread = tp->num; |
0fd8e87f UW |
7576 | |
7577 | /* To avoid having to rescan all objfile symbols at every step, | |
7578 | we maintain a list of continually-inserted but always disabled | |
7579 | longjmp "master" breakpoints. Here, we simply create momentary | |
7580 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7581 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7582 | if (b->pspace == current_program_space |
186c406b TT |
7583 | && (b->type == bp_longjmp_master |
7584 | || b->type == bp_exception_master)) | |
0fd8e87f | 7585 | { |
06edf0c0 PA |
7586 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7587 | struct breakpoint *clone; | |
cc59ec59 | 7588 | |
e2e4d78b JK |
7589 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7590 | after their removal. */ | |
06edf0c0 | 7591 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7592 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7593 | clone->thread = thread; |
7594 | } | |
186c406b TT |
7595 | |
7596 | tp->initiating_frame = frame; | |
c906108c SS |
7597 | } |
7598 | ||
611c83ae | 7599 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7600 | void |
611c83ae | 7601 | delete_longjmp_breakpoint (int thread) |
c906108c | 7602 | { |
35df4500 | 7603 | struct breakpoint *b, *b_tmp; |
c906108c | 7604 | |
35df4500 | 7605 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7606 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7607 | { |
7608 | if (b->thread == thread) | |
7609 | delete_breakpoint (b); | |
7610 | } | |
c906108c SS |
7611 | } |
7612 | ||
f59f708a PA |
7613 | void |
7614 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7615 | { | |
7616 | struct breakpoint *b, *b_tmp; | |
7617 | ||
7618 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7619 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7620 | { | |
7621 | if (b->thread == thread) | |
7622 | b->disposition = disp_del_at_next_stop; | |
7623 | } | |
7624 | } | |
7625 | ||
e2e4d78b JK |
7626 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7627 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7628 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7629 | breakpoints. */ | |
7630 | ||
7631 | struct breakpoint * | |
7632 | set_longjmp_breakpoint_for_call_dummy (void) | |
7633 | { | |
7634 | struct breakpoint *b, *retval = NULL; | |
7635 | ||
7636 | ALL_BREAKPOINTS (b) | |
7637 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7638 | { | |
7639 | struct breakpoint *new_b; | |
7640 | ||
7641 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7642 | &momentary_breakpoint_ops, |
7643 | 1); | |
e2e4d78b JK |
7644 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7645 | ||
7646 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7647 | ||
7648 | gdb_assert (new_b->related_breakpoint == new_b); | |
7649 | if (retval == NULL) | |
7650 | retval = new_b; | |
7651 | new_b->related_breakpoint = retval; | |
7652 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7653 | retval = retval->related_breakpoint; | |
7654 | retval->related_breakpoint = new_b; | |
7655 | } | |
7656 | ||
7657 | return retval; | |
7658 | } | |
7659 | ||
7660 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7661 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7662 | stack. |
7663 | ||
7664 | You should call this function only at places where it is safe to currently | |
7665 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7666 | frames. */ | |
7667 | ||
7668 | void | |
b67a2c6f | 7669 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7670 | { |
7671 | struct breakpoint *b, *b_tmp; | |
7672 | ||
7673 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7674 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7675 | { |
7676 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7677 | ||
7678 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7679 | dummy_b = dummy_b->related_breakpoint; | |
7680 | if (dummy_b->type != bp_call_dummy | |
7681 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7682 | continue; | |
7683 | ||
b67a2c6f | 7684 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7685 | |
7686 | while (b->related_breakpoint != b) | |
7687 | { | |
7688 | if (b_tmp == b->related_breakpoint) | |
7689 | b_tmp = b->related_breakpoint->next; | |
7690 | delete_breakpoint (b->related_breakpoint); | |
7691 | } | |
7692 | delete_breakpoint (b); | |
7693 | } | |
7694 | } | |
7695 | ||
1900040c MS |
7696 | void |
7697 | enable_overlay_breakpoints (void) | |
7698 | { | |
52f0bd74 | 7699 | struct breakpoint *b; |
1900040c MS |
7700 | |
7701 | ALL_BREAKPOINTS (b) | |
7702 | if (b->type == bp_overlay_event) | |
7703 | { | |
7704 | b->enable_state = bp_enabled; | |
44702360 | 7705 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7706 | overlay_events_enabled = 1; |
1900040c MS |
7707 | } |
7708 | } | |
7709 | ||
7710 | void | |
7711 | disable_overlay_breakpoints (void) | |
7712 | { | |
52f0bd74 | 7713 | struct breakpoint *b; |
1900040c MS |
7714 | |
7715 | ALL_BREAKPOINTS (b) | |
7716 | if (b->type == bp_overlay_event) | |
7717 | { | |
7718 | b->enable_state = bp_disabled; | |
44702360 | 7719 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7720 | overlay_events_enabled = 0; |
1900040c MS |
7721 | } |
7722 | } | |
7723 | ||
aa7d318d TT |
7724 | /* Set an active std::terminate breakpoint for each std::terminate |
7725 | master breakpoint. */ | |
7726 | void | |
7727 | set_std_terminate_breakpoint (void) | |
7728 | { | |
35df4500 | 7729 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7730 | |
35df4500 | 7731 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7732 | if (b->pspace == current_program_space |
7733 | && b->type == bp_std_terminate_master) | |
7734 | { | |
06edf0c0 | 7735 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7736 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7737 | } |
7738 | } | |
7739 | ||
7740 | /* Delete all the std::terminate breakpoints. */ | |
7741 | void | |
7742 | delete_std_terminate_breakpoint (void) | |
7743 | { | |
35df4500 | 7744 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7745 | |
35df4500 | 7746 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7747 | if (b->type == bp_std_terminate) |
7748 | delete_breakpoint (b); | |
7749 | } | |
7750 | ||
c4093a6a | 7751 | struct breakpoint * |
a6d9a66e | 7752 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7753 | { |
7754 | struct breakpoint *b; | |
c4093a6a | 7755 | |
06edf0c0 PA |
7756 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7757 | &internal_breakpoint_ops); | |
7758 | ||
b5de0fa7 | 7759 | b->enable_state = bp_enabled; |
f00aae0f | 7760 | /* location has to be used or breakpoint_re_set will delete me. */ |
a06efdd6 | 7761 | b->location = new_address_location (b->loc->address); |
c4093a6a | 7762 | |
44702360 | 7763 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7764 | |
c4093a6a JM |
7765 | return b; |
7766 | } | |
7767 | ||
7768 | void | |
7769 | remove_thread_event_breakpoints (void) | |
7770 | { | |
35df4500 | 7771 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7772 | |
35df4500 | 7773 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7774 | if (b->type == bp_thread_event |
7775 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7776 | delete_breakpoint (b); |
7777 | } | |
7778 | ||
0101ce28 JJ |
7779 | struct lang_and_radix |
7780 | { | |
7781 | enum language lang; | |
7782 | int radix; | |
7783 | }; | |
7784 | ||
4efc6507 DE |
7785 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7786 | ||
7787 | struct breakpoint * | |
7788 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7789 | { | |
7790 | struct breakpoint *b; | |
7791 | ||
06edf0c0 PA |
7792 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7793 | &internal_breakpoint_ops); | |
44702360 | 7794 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7795 | return b; |
7796 | } | |
0101ce28 | 7797 | |
03673fc7 PP |
7798 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7799 | ||
7800 | void | |
7801 | remove_jit_event_breakpoints (void) | |
7802 | { | |
7803 | struct breakpoint *b, *b_tmp; | |
7804 | ||
7805 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7806 | if (b->type == bp_jit_event | |
7807 | && b->loc->pspace == current_program_space) | |
7808 | delete_breakpoint (b); | |
7809 | } | |
7810 | ||
cae688ec JJ |
7811 | void |
7812 | remove_solib_event_breakpoints (void) | |
7813 | { | |
35df4500 | 7814 | struct breakpoint *b, *b_tmp; |
cae688ec | 7815 | |
35df4500 | 7816 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7817 | if (b->type == bp_shlib_event |
7818 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7819 | delete_breakpoint (b); |
7820 | } | |
7821 | ||
f37f681c PA |
7822 | /* See breakpoint.h. */ |
7823 | ||
7824 | void | |
7825 | remove_solib_event_breakpoints_at_next_stop (void) | |
7826 | { | |
7827 | struct breakpoint *b, *b_tmp; | |
7828 | ||
7829 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7830 | if (b->type == bp_shlib_event | |
7831 | && b->loc->pspace == current_program_space) | |
7832 | b->disposition = disp_del_at_next_stop; | |
7833 | } | |
7834 | ||
04086b45 PA |
7835 | /* Helper for create_solib_event_breakpoint / |
7836 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7837 | INSERT_MODE to pass through to update_global_location_list. */ | |
7838 | ||
7839 | static struct breakpoint * | |
7840 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7841 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7842 | { |
7843 | struct breakpoint *b; | |
7844 | ||
06edf0c0 PA |
7845 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7846 | &internal_breakpoint_ops); | |
04086b45 | 7847 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7848 | return b; |
7849 | } | |
7850 | ||
04086b45 PA |
7851 | struct breakpoint * |
7852 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7853 | { | |
7854 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7855 | } | |
7856 | ||
f37f681c PA |
7857 | /* See breakpoint.h. */ |
7858 | ||
7859 | struct breakpoint * | |
7860 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7861 | { | |
7862 | struct breakpoint *b; | |
7863 | ||
04086b45 PA |
7864 | /* Explicitly tell update_global_location_list to insert |
7865 | locations. */ | |
7866 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7867 | if (!b->loc->inserted) |
7868 | { | |
7869 | delete_breakpoint (b); | |
7870 | return NULL; | |
7871 | } | |
7872 | return b; | |
7873 | } | |
7874 | ||
cae688ec JJ |
7875 | /* Disable any breakpoints that are on code in shared libraries. Only |
7876 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7877 | ||
7878 | void | |
cb851954 | 7879 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7880 | { |
876fa593 | 7881 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7882 | |
876fa593 | 7883 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7884 | { |
2bdf28a0 | 7885 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7886 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7887 | |
4a64f543 MS |
7888 | /* We apply the check to all breakpoints, including disabled for |
7889 | those with loc->duplicate set. This is so that when breakpoint | |
7890 | becomes enabled, or the duplicate is removed, gdb will try to | |
7891 | insert all breakpoints. If we don't set shlib_disabled here, | |
7892 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7893 | if (((b->type == bp_breakpoint) |
508ccb1f | 7894 | || (b->type == bp_jit_event) |
1042e4c0 | 7895 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7896 | || (is_tracepoint (b))) |
6c95b8df | 7897 | && loc->pspace == current_program_space |
0d381245 | 7898 | && !loc->shlib_disabled |
6c95b8df | 7899 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7900 | ) |
0d381245 VP |
7901 | { |
7902 | loc->shlib_disabled = 1; | |
7903 | } | |
cae688ec JJ |
7904 | } |
7905 | } | |
7906 | ||
63644780 NB |
7907 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7908 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7909 | disabled ones can just stay disabled. */ | |
84acb35a | 7910 | |
75149521 | 7911 | static void |
84acb35a JJ |
7912 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7913 | { | |
876fa593 | 7914 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7915 | int disabled_shlib_breaks = 0; |
7916 | ||
c86cf029 VP |
7917 | /* SunOS a.out shared libraries are always mapped, so do not |
7918 | disable breakpoints; they will only be reported as unloaded | |
7919 | through clear_solib when GDB discards its shared library | |
7920 | list. See clear_solib for more information. */ | |
7921 | if (exec_bfd != NULL | |
7922 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7923 | return; | |
7924 | ||
876fa593 | 7925 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7926 | { |
2bdf28a0 | 7927 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7928 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7929 | |
1e4d1764 | 7930 | if (solib->pspace == loc->pspace |
e2dd7057 | 7931 | && !loc->shlib_disabled |
1e4d1764 YQ |
7932 | && (((b->type == bp_breakpoint |
7933 | || b->type == bp_jit_event | |
7934 | || b->type == bp_hardware_breakpoint) | |
7935 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7936 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7937 | || is_tracepoint (b)) | |
e2dd7057 | 7938 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7939 | { |
e2dd7057 PP |
7940 | loc->shlib_disabled = 1; |
7941 | /* At this point, we cannot rely on remove_breakpoint | |
7942 | succeeding so we must mark the breakpoint as not inserted | |
7943 | to prevent future errors occurring in remove_breakpoints. */ | |
7944 | loc->inserted = 0; | |
8d3788bd VP |
7945 | |
7946 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7947 | observer_notify_breakpoint_modified (b); | |
7948 | ||
e2dd7057 PP |
7949 | if (!disabled_shlib_breaks) |
7950 | { | |
7951 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7952 | warning (_("Temporarily disabling breakpoints " |
7953 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7954 | solib->so_name); |
84acb35a | 7955 | } |
e2dd7057 | 7956 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7957 | } |
7958 | } | |
84acb35a JJ |
7959 | } |
7960 | ||
63644780 NB |
7961 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7962 | notification of free_objfile. Only apply to enabled breakpoints, | |
7963 | disabled ones can just stay disabled. */ | |
7964 | ||
7965 | static void | |
7966 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7967 | { | |
7968 | struct breakpoint *b; | |
7969 | ||
7970 | if (objfile == NULL) | |
7971 | return; | |
7972 | ||
d03de421 PA |
7973 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7974 | managed by the user with add-symbol-file/remove-symbol-file. | |
7975 | Similarly to how breakpoints in shared libraries are handled in | |
7976 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7977 | shlib_disabled so they end up uninserted on the next global |
7978 | location list update. Shared libraries not loaded by the user | |
7979 | aren't handled here -- they're already handled in | |
7980 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7981 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7982 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7983 | main objfile). */ | |
7984 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7985 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7986 | return; |
7987 | ||
7988 | ALL_BREAKPOINTS (b) | |
7989 | { | |
7990 | struct bp_location *loc; | |
7991 | int bp_modified = 0; | |
7992 | ||
7993 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7994 | continue; | |
7995 | ||
7996 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7997 | { | |
7998 | CORE_ADDR loc_addr = loc->address; | |
7999 | ||
8000 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8001 | && loc->loc_type != bp_loc_software_breakpoint) | |
8002 | continue; | |
8003 | ||
8004 | if (loc->shlib_disabled != 0) | |
8005 | continue; | |
8006 | ||
8007 | if (objfile->pspace != loc->pspace) | |
8008 | continue; | |
8009 | ||
8010 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8011 | && loc->loc_type != bp_loc_software_breakpoint) | |
8012 | continue; | |
8013 | ||
8014 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8015 | { | |
8016 | loc->shlib_disabled = 1; | |
08351840 PA |
8017 | /* At this point, we don't know whether the object was |
8018 | unmapped from the inferior or not, so leave the | |
8019 | inserted flag alone. We'll handle failure to | |
8020 | uninsert quietly, in case the object was indeed | |
8021 | unmapped. */ | |
63644780 NB |
8022 | |
8023 | mark_breakpoint_location_modified (loc); | |
8024 | ||
8025 | bp_modified = 1; | |
8026 | } | |
8027 | } | |
8028 | ||
8029 | if (bp_modified) | |
8030 | observer_notify_breakpoint_modified (b); | |
8031 | } | |
8032 | } | |
8033 | ||
ce78b96d JB |
8034 | /* FORK & VFORK catchpoints. */ |
8035 | ||
e29a4733 PA |
8036 | /* An instance of this type is used to represent a fork or vfork |
8037 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8038 | class; users downcast to "struct breakpoint *" when needed. A | |
8039 | breakpoint is really of this type iff its ops pointer points to | |
8040 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8041 | ||
8042 | struct fork_catchpoint | |
8043 | { | |
8044 | /* The base class. */ | |
8045 | struct breakpoint base; | |
8046 | ||
8047 | /* Process id of a child process whose forking triggered this | |
8048 | catchpoint. This field is only valid immediately after this | |
8049 | catchpoint has triggered. */ | |
8050 | ptid_t forked_inferior_pid; | |
8051 | }; | |
8052 | ||
4a64f543 MS |
8053 | /* Implement the "insert" breakpoint_ops method for fork |
8054 | catchpoints. */ | |
ce78b96d | 8055 | |
77b06cd7 TJB |
8056 | static int |
8057 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8058 | { |
dfd4cc63 | 8059 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8060 | } |
8061 | ||
4a64f543 MS |
8062 | /* Implement the "remove" breakpoint_ops method for fork |
8063 | catchpoints. */ | |
ce78b96d JB |
8064 | |
8065 | static int | |
77b06cd7 | 8066 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 8067 | { |
dfd4cc63 | 8068 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8069 | } |
8070 | ||
8071 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8072 | catchpoints. */ | |
8073 | ||
8074 | static int | |
f1310107 | 8075 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8076 | struct address_space *aspace, CORE_ADDR bp_addr, |
8077 | const struct target_waitstatus *ws) | |
ce78b96d | 8078 | { |
e29a4733 PA |
8079 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8080 | ||
f90263c1 TT |
8081 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8082 | return 0; | |
8083 | ||
8084 | c->forked_inferior_pid = ws->value.related_pid; | |
8085 | return 1; | |
ce78b96d JB |
8086 | } |
8087 | ||
4a64f543 MS |
8088 | /* Implement the "print_it" breakpoint_ops method for fork |
8089 | catchpoints. */ | |
ce78b96d JB |
8090 | |
8091 | static enum print_stop_action | |
348d480f | 8092 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8093 | { |
36dfb11c | 8094 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8095 | struct breakpoint *b = bs->breakpoint_at; |
8096 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8097 | |
ce78b96d | 8098 | annotate_catchpoint (b->number); |
36dfb11c TT |
8099 | if (b->disposition == disp_del) |
8100 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8101 | else | |
8102 | ui_out_text (uiout, "\nCatchpoint "); | |
8103 | if (ui_out_is_mi_like_p (uiout)) | |
8104 | { | |
8105 | ui_out_field_string (uiout, "reason", | |
8106 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8107 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8108 | } | |
8109 | ui_out_field_int (uiout, "bkptno", b->number); | |
8110 | ui_out_text (uiout, " (forked process "); | |
8111 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8112 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8113 | return PRINT_SRC_AND_LOC; |
8114 | } | |
8115 | ||
4a64f543 MS |
8116 | /* Implement the "print_one" breakpoint_ops method for fork |
8117 | catchpoints. */ | |
ce78b96d JB |
8118 | |
8119 | static void | |
a6d9a66e | 8120 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8121 | { |
e29a4733 | 8122 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8123 | struct value_print_options opts; |
79a45e25 | 8124 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8125 | |
8126 | get_user_print_options (&opts); | |
8127 | ||
4a64f543 MS |
8128 | /* Field 4, the address, is omitted (which makes the columns not |
8129 | line up too nicely with the headers, but the effect is relatively | |
8130 | readable). */ | |
79a45b7d | 8131 | if (opts.addressprint) |
ce78b96d JB |
8132 | ui_out_field_skip (uiout, "addr"); |
8133 | annotate_field (5); | |
8134 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8135 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8136 | { |
8137 | ui_out_text (uiout, ", process "); | |
8138 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8139 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8140 | ui_out_spaces (uiout, 1); |
8141 | } | |
8ac3646f TT |
8142 | |
8143 | if (ui_out_is_mi_like_p (uiout)) | |
8144 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8145 | } |
8146 | ||
8147 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8148 | catchpoints. */ | |
8149 | ||
8150 | static void | |
8151 | print_mention_catch_fork (struct breakpoint *b) | |
8152 | { | |
8153 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8154 | } | |
8155 | ||
6149aea9 PA |
8156 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8157 | catchpoints. */ | |
8158 | ||
8159 | static void | |
8160 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8161 | { | |
8162 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8163 | print_recreate_thread (b, fp); |
6149aea9 PA |
8164 | } |
8165 | ||
ce78b96d JB |
8166 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8167 | ||
2060206e | 8168 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8169 | |
4a64f543 MS |
8170 | /* Implement the "insert" breakpoint_ops method for vfork |
8171 | catchpoints. */ | |
ce78b96d | 8172 | |
77b06cd7 TJB |
8173 | static int |
8174 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8175 | { |
dfd4cc63 | 8176 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8177 | } |
8178 | ||
4a64f543 MS |
8179 | /* Implement the "remove" breakpoint_ops method for vfork |
8180 | catchpoints. */ | |
ce78b96d JB |
8181 | |
8182 | static int | |
77b06cd7 | 8183 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8184 | { |
dfd4cc63 | 8185 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8186 | } |
8187 | ||
8188 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8189 | catchpoints. */ | |
8190 | ||
8191 | static int | |
f1310107 | 8192 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8193 | struct address_space *aspace, CORE_ADDR bp_addr, |
8194 | const struct target_waitstatus *ws) | |
ce78b96d | 8195 | { |
e29a4733 PA |
8196 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8197 | ||
f90263c1 TT |
8198 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8199 | return 0; | |
8200 | ||
8201 | c->forked_inferior_pid = ws->value.related_pid; | |
8202 | return 1; | |
ce78b96d JB |
8203 | } |
8204 | ||
4a64f543 MS |
8205 | /* Implement the "print_it" breakpoint_ops method for vfork |
8206 | catchpoints. */ | |
ce78b96d JB |
8207 | |
8208 | static enum print_stop_action | |
348d480f | 8209 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8210 | { |
36dfb11c | 8211 | struct ui_out *uiout = current_uiout; |
348d480f | 8212 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8213 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8214 | ||
ce78b96d | 8215 | annotate_catchpoint (b->number); |
36dfb11c TT |
8216 | if (b->disposition == disp_del) |
8217 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8218 | else | |
8219 | ui_out_text (uiout, "\nCatchpoint "); | |
8220 | if (ui_out_is_mi_like_p (uiout)) | |
8221 | { | |
8222 | ui_out_field_string (uiout, "reason", | |
8223 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8224 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8225 | } | |
8226 | ui_out_field_int (uiout, "bkptno", b->number); | |
8227 | ui_out_text (uiout, " (vforked process "); | |
8228 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8229 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8230 | return PRINT_SRC_AND_LOC; |
8231 | } | |
8232 | ||
4a64f543 MS |
8233 | /* Implement the "print_one" breakpoint_ops method for vfork |
8234 | catchpoints. */ | |
ce78b96d JB |
8235 | |
8236 | static void | |
a6d9a66e | 8237 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8238 | { |
e29a4733 | 8239 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8240 | struct value_print_options opts; |
79a45e25 | 8241 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8242 | |
8243 | get_user_print_options (&opts); | |
4a64f543 MS |
8244 | /* Field 4, the address, is omitted (which makes the columns not |
8245 | line up too nicely with the headers, but the effect is relatively | |
8246 | readable). */ | |
79a45b7d | 8247 | if (opts.addressprint) |
ce78b96d JB |
8248 | ui_out_field_skip (uiout, "addr"); |
8249 | annotate_field (5); | |
8250 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8251 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8252 | { |
8253 | ui_out_text (uiout, ", process "); | |
8254 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8255 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8256 | ui_out_spaces (uiout, 1); |
8257 | } | |
8ac3646f TT |
8258 | |
8259 | if (ui_out_is_mi_like_p (uiout)) | |
8260 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8261 | } |
8262 | ||
8263 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8264 | catchpoints. */ | |
8265 | ||
8266 | static void | |
8267 | print_mention_catch_vfork (struct breakpoint *b) | |
8268 | { | |
8269 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8270 | } | |
8271 | ||
6149aea9 PA |
8272 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8273 | catchpoints. */ | |
8274 | ||
8275 | static void | |
8276 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8277 | { | |
8278 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8279 | print_recreate_thread (b, fp); |
6149aea9 PA |
8280 | } |
8281 | ||
ce78b96d JB |
8282 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8283 | ||
2060206e | 8284 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8285 | |
edcc5120 TT |
8286 | /* An instance of this type is used to represent an solib catchpoint. |
8287 | It includes a "struct breakpoint" as a kind of base class; users | |
8288 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8289 | really of this type iff its ops pointer points to | |
8290 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8291 | ||
8292 | struct solib_catchpoint | |
8293 | { | |
8294 | /* The base class. */ | |
8295 | struct breakpoint base; | |
8296 | ||
8297 | /* True for "catch load", false for "catch unload". */ | |
8298 | unsigned char is_load; | |
8299 | ||
8300 | /* Regular expression to match, if any. COMPILED is only valid when | |
8301 | REGEX is non-NULL. */ | |
8302 | char *regex; | |
8303 | regex_t compiled; | |
8304 | }; | |
8305 | ||
8306 | static void | |
8307 | dtor_catch_solib (struct breakpoint *b) | |
8308 | { | |
8309 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8310 | ||
8311 | if (self->regex) | |
8312 | regfree (&self->compiled); | |
8313 | xfree (self->regex); | |
8314 | ||
8315 | base_breakpoint_ops.dtor (b); | |
8316 | } | |
8317 | ||
8318 | static int | |
8319 | insert_catch_solib (struct bp_location *ignore) | |
8320 | { | |
8321 | return 0; | |
8322 | } | |
8323 | ||
8324 | static int | |
8325 | remove_catch_solib (struct bp_location *ignore) | |
8326 | { | |
8327 | return 0; | |
8328 | } | |
8329 | ||
8330 | static int | |
8331 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8332 | struct address_space *aspace, | |
8333 | CORE_ADDR bp_addr, | |
8334 | const struct target_waitstatus *ws) | |
8335 | { | |
8336 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8337 | struct breakpoint *other; | |
8338 | ||
8339 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8340 | return 1; | |
8341 | ||
8342 | ALL_BREAKPOINTS (other) | |
8343 | { | |
8344 | struct bp_location *other_bl; | |
8345 | ||
8346 | if (other == bl->owner) | |
8347 | continue; | |
8348 | ||
8349 | if (other->type != bp_shlib_event) | |
8350 | continue; | |
8351 | ||
8352 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8353 | continue; | |
8354 | ||
8355 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8356 | { | |
8357 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8358 | return 1; | |
8359 | } | |
8360 | } | |
8361 | ||
8362 | return 0; | |
8363 | } | |
8364 | ||
8365 | static void | |
8366 | check_status_catch_solib (struct bpstats *bs) | |
8367 | { | |
8368 | struct solib_catchpoint *self | |
8369 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8370 | int ix; | |
8371 | ||
8372 | if (self->is_load) | |
8373 | { | |
8374 | struct so_list *iter; | |
8375 | ||
8376 | for (ix = 0; | |
8377 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8378 | ix, iter); | |
8379 | ++ix) | |
8380 | { | |
8381 | if (!self->regex | |
8382 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8383 | return; | |
8384 | } | |
8385 | } | |
8386 | else | |
8387 | { | |
8388 | char *iter; | |
8389 | ||
8390 | for (ix = 0; | |
8391 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8392 | ix, iter); | |
8393 | ++ix) | |
8394 | { | |
8395 | if (!self->regex | |
8396 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8397 | return; | |
8398 | } | |
8399 | } | |
8400 | ||
8401 | bs->stop = 0; | |
8402 | bs->print_it = print_it_noop; | |
8403 | } | |
8404 | ||
8405 | static enum print_stop_action | |
8406 | print_it_catch_solib (bpstat bs) | |
8407 | { | |
8408 | struct breakpoint *b = bs->breakpoint_at; | |
8409 | struct ui_out *uiout = current_uiout; | |
8410 | ||
8411 | annotate_catchpoint (b->number); | |
8412 | if (b->disposition == disp_del) | |
8413 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8414 | else | |
8415 | ui_out_text (uiout, "\nCatchpoint "); | |
8416 | ui_out_field_int (uiout, "bkptno", b->number); | |
8417 | ui_out_text (uiout, "\n"); | |
8418 | if (ui_out_is_mi_like_p (uiout)) | |
8419 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8420 | print_solib_event (1); | |
8421 | return PRINT_SRC_AND_LOC; | |
8422 | } | |
8423 | ||
8424 | static void | |
8425 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8426 | { | |
8427 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8428 | struct value_print_options opts; | |
8429 | struct ui_out *uiout = current_uiout; | |
8430 | char *msg; | |
8431 | ||
8432 | get_user_print_options (&opts); | |
8433 | /* Field 4, the address, is omitted (which makes the columns not | |
8434 | line up too nicely with the headers, but the effect is relatively | |
8435 | readable). */ | |
8436 | if (opts.addressprint) | |
8437 | { | |
8438 | annotate_field (4); | |
8439 | ui_out_field_skip (uiout, "addr"); | |
8440 | } | |
8441 | ||
8442 | annotate_field (5); | |
8443 | if (self->is_load) | |
8444 | { | |
8445 | if (self->regex) | |
8446 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8447 | else | |
8448 | msg = xstrdup (_("load of library")); | |
8449 | } | |
8450 | else | |
8451 | { | |
8452 | if (self->regex) | |
8453 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8454 | else | |
8455 | msg = xstrdup (_("unload of library")); | |
8456 | } | |
8457 | ui_out_field_string (uiout, "what", msg); | |
8458 | xfree (msg); | |
8ac3646f TT |
8459 | |
8460 | if (ui_out_is_mi_like_p (uiout)) | |
8461 | ui_out_field_string (uiout, "catch-type", | |
8462 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8463 | } |
8464 | ||
8465 | static void | |
8466 | print_mention_catch_solib (struct breakpoint *b) | |
8467 | { | |
8468 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8469 | ||
8470 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8471 | self->is_load ? "load" : "unload"); | |
8472 | } | |
8473 | ||
8474 | static void | |
8475 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8476 | { | |
8477 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8478 | ||
8479 | fprintf_unfiltered (fp, "%s %s", | |
8480 | b->disposition == disp_del ? "tcatch" : "catch", | |
8481 | self->is_load ? "load" : "unload"); | |
8482 | if (self->regex) | |
8483 | fprintf_unfiltered (fp, " %s", self->regex); | |
8484 | fprintf_unfiltered (fp, "\n"); | |
8485 | } | |
8486 | ||
8487 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8488 | ||
91985142 MG |
8489 | /* Shared helper function (MI and CLI) for creating and installing |
8490 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8491 | the events to be caught are load events, otherwise they are | |
8492 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8493 | temporary one. If ENABLED is non-zero the catchpoint is | |
8494 | created in an enabled state. */ | |
edcc5120 | 8495 | |
91985142 MG |
8496 | void |
8497 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8498 | { |
8499 | struct solib_catchpoint *c; | |
8500 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8501 | struct cleanup *cleanup; |
8502 | ||
edcc5120 TT |
8503 | if (!arg) |
8504 | arg = ""; | |
8505 | arg = skip_spaces (arg); | |
8506 | ||
8507 | c = XCNEW (struct solib_catchpoint); | |
8508 | cleanup = make_cleanup (xfree, c); | |
8509 | ||
8510 | if (*arg != '\0') | |
8511 | { | |
8512 | int errcode; | |
8513 | ||
8514 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8515 | if (errcode != 0) | |
8516 | { | |
8517 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8518 | ||
8519 | make_cleanup (xfree, err); | |
8520 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8521 | } | |
8522 | c->regex = xstrdup (arg); | |
8523 | } | |
8524 | ||
8525 | c->is_load = is_load; | |
91985142 | 8526 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8527 | &catch_solib_breakpoint_ops); |
8528 | ||
91985142 MG |
8529 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8530 | ||
edcc5120 TT |
8531 | discard_cleanups (cleanup); |
8532 | install_breakpoint (0, &c->base, 1); | |
8533 | } | |
8534 | ||
91985142 MG |
8535 | /* A helper function that does all the work for "catch load" and |
8536 | "catch unload". */ | |
8537 | ||
8538 | static void | |
8539 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8540 | struct cmd_list_element *command) | |
8541 | { | |
8542 | int tempflag; | |
8543 | const int enabled = 1; | |
8544 | ||
8545 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8546 | ||
8547 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8548 | } | |
8549 | ||
edcc5120 TT |
8550 | static void |
8551 | catch_load_command_1 (char *arg, int from_tty, | |
8552 | struct cmd_list_element *command) | |
8553 | { | |
8554 | catch_load_or_unload (arg, from_tty, 1, command); | |
8555 | } | |
8556 | ||
8557 | static void | |
8558 | catch_unload_command_1 (char *arg, int from_tty, | |
8559 | struct cmd_list_element *command) | |
8560 | { | |
8561 | catch_load_or_unload (arg, from_tty, 0, command); | |
8562 | } | |
8563 | ||
346774a9 PA |
8564 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8565 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8566 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8567 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8568 | |
ab04a2af | 8569 | void |
346774a9 PA |
8570 | init_catchpoint (struct breakpoint *b, |
8571 | struct gdbarch *gdbarch, int tempflag, | |
8572 | char *cond_string, | |
c0a91b2b | 8573 | const struct breakpoint_ops *ops) |
c906108c | 8574 | { |
c5aa993b | 8575 | struct symtab_and_line sal; |
346774a9 | 8576 | |
fe39c653 | 8577 | init_sal (&sal); |
6c95b8df | 8578 | sal.pspace = current_program_space; |
c5aa993b | 8579 | |
28010a5d | 8580 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8581 | |
1b36a34b | 8582 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8583 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8584 | } |
8585 | ||
28010a5d | 8586 | void |
3ea46bff | 8587 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8588 | { |
8589 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8590 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8591 | if (is_tracepoint (b)) |
8592 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8593 | if (!internal) |
8594 | mention (b); | |
c56053d2 | 8595 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8596 | |
8597 | if (update_gll) | |
44702360 | 8598 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8599 | } |
8600 | ||
9b70b993 | 8601 | static void |
a6d9a66e UW |
8602 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8603 | int tempflag, char *cond_string, | |
c0a91b2b | 8604 | const struct breakpoint_ops *ops) |
c906108c | 8605 | { |
e29a4733 | 8606 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8607 | |
e29a4733 PA |
8608 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8609 | ||
8610 | c->forked_inferior_pid = null_ptid; | |
8611 | ||
3ea46bff | 8612 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8613 | } |
8614 | ||
fe798b75 JB |
8615 | /* Exec catchpoints. */ |
8616 | ||
b4d90040 PA |
8617 | /* An instance of this type is used to represent an exec catchpoint. |
8618 | It includes a "struct breakpoint" as a kind of base class; users | |
8619 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8620 | really of this type iff its ops pointer points to | |
8621 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8622 | ||
8623 | struct exec_catchpoint | |
8624 | { | |
8625 | /* The base class. */ | |
8626 | struct breakpoint base; | |
8627 | ||
8628 | /* Filename of a program whose exec triggered this catchpoint. | |
8629 | This field is only valid immediately after this catchpoint has | |
8630 | triggered. */ | |
8631 | char *exec_pathname; | |
8632 | }; | |
8633 | ||
8634 | /* Implement the "dtor" breakpoint_ops method for exec | |
8635 | catchpoints. */ | |
8636 | ||
8637 | static void | |
8638 | dtor_catch_exec (struct breakpoint *b) | |
8639 | { | |
8640 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8641 | ||
8642 | xfree (c->exec_pathname); | |
348d480f | 8643 | |
2060206e | 8644 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8645 | } |
8646 | ||
77b06cd7 TJB |
8647 | static int |
8648 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8649 | { |
dfd4cc63 | 8650 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8651 | } |
c906108c | 8652 | |
fe798b75 | 8653 | static int |
77b06cd7 | 8654 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8655 | { |
dfd4cc63 | 8656 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8657 | } |
c906108c | 8658 | |
fe798b75 | 8659 | static int |
f1310107 | 8660 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8661 | struct address_space *aspace, CORE_ADDR bp_addr, |
8662 | const struct target_waitstatus *ws) | |
fe798b75 | 8663 | { |
b4d90040 PA |
8664 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8665 | ||
f90263c1 TT |
8666 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8667 | return 0; | |
8668 | ||
8669 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8670 | return 1; | |
fe798b75 | 8671 | } |
c906108c | 8672 | |
fe798b75 | 8673 | static enum print_stop_action |
348d480f | 8674 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8675 | { |
36dfb11c | 8676 | struct ui_out *uiout = current_uiout; |
348d480f | 8677 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8678 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8679 | ||
fe798b75 | 8680 | annotate_catchpoint (b->number); |
36dfb11c TT |
8681 | if (b->disposition == disp_del) |
8682 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8683 | else | |
8684 | ui_out_text (uiout, "\nCatchpoint "); | |
8685 | if (ui_out_is_mi_like_p (uiout)) | |
8686 | { | |
8687 | ui_out_field_string (uiout, "reason", | |
8688 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8689 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8690 | } | |
8691 | ui_out_field_int (uiout, "bkptno", b->number); | |
8692 | ui_out_text (uiout, " (exec'd "); | |
8693 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8694 | ui_out_text (uiout, "), "); | |
8695 | ||
fe798b75 | 8696 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8697 | } |
8698 | ||
fe798b75 | 8699 | static void |
a6d9a66e | 8700 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8701 | { |
b4d90040 | 8702 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8703 | struct value_print_options opts; |
79a45e25 | 8704 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8705 | |
8706 | get_user_print_options (&opts); | |
8707 | ||
8708 | /* Field 4, the address, is omitted (which makes the columns | |
8709 | not line up too nicely with the headers, but the effect | |
8710 | is relatively readable). */ | |
8711 | if (opts.addressprint) | |
8712 | ui_out_field_skip (uiout, "addr"); | |
8713 | annotate_field (5); | |
8714 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8715 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8716 | { |
8717 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8718 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8719 | ui_out_text (uiout, "\" "); |
8720 | } | |
8ac3646f TT |
8721 | |
8722 | if (ui_out_is_mi_like_p (uiout)) | |
8723 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8724 | } |
8725 | ||
8726 | static void | |
8727 | print_mention_catch_exec (struct breakpoint *b) | |
8728 | { | |
8729 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8730 | } | |
8731 | ||
6149aea9 PA |
8732 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8733 | catchpoints. */ | |
8734 | ||
8735 | static void | |
8736 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8737 | { | |
8738 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8739 | print_recreate_thread (b, fp); |
6149aea9 PA |
8740 | } |
8741 | ||
2060206e | 8742 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8743 | |
c906108c | 8744 | static int |
fba45db2 | 8745 | hw_breakpoint_used_count (void) |
c906108c | 8746 | { |
c906108c | 8747 | int i = 0; |
f1310107 TJB |
8748 | struct breakpoint *b; |
8749 | struct bp_location *bl; | |
c906108c SS |
8750 | |
8751 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8752 | { |
d6b74ac4 | 8753 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8754 | for (bl = b->loc; bl; bl = bl->next) |
8755 | { | |
8756 | /* Special types of hardware breakpoints may use more than | |
8757 | one register. */ | |
348d480f | 8758 | i += b->ops->resources_needed (bl); |
f1310107 | 8759 | } |
c5aa993b | 8760 | } |
c906108c SS |
8761 | |
8762 | return i; | |
8763 | } | |
8764 | ||
a1398e0c PA |
8765 | /* Returns the resources B would use if it were a hardware |
8766 | watchpoint. */ | |
8767 | ||
c906108c | 8768 | static int |
a1398e0c | 8769 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8770 | { |
c906108c | 8771 | int i = 0; |
e09342b5 | 8772 | struct bp_location *bl; |
c906108c | 8773 | |
a1398e0c PA |
8774 | if (!breakpoint_enabled (b)) |
8775 | return 0; | |
8776 | ||
8777 | for (bl = b->loc; bl; bl = bl->next) | |
8778 | { | |
8779 | /* Special types of hardware watchpoints may use more than | |
8780 | one register. */ | |
8781 | i += b->ops->resources_needed (bl); | |
8782 | } | |
8783 | ||
8784 | return i; | |
8785 | } | |
8786 | ||
8787 | /* Returns the sum the used resources of all hardware watchpoints of | |
8788 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8789 | the sum of the used resources of all hardware watchpoints of other | |
8790 | types _not_ TYPE. */ | |
8791 | ||
8792 | static int | |
8793 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8794 | enum bptype type, int *other_type_used) | |
8795 | { | |
8796 | int i = 0; | |
8797 | struct breakpoint *b; | |
8798 | ||
c906108c SS |
8799 | *other_type_used = 0; |
8800 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8801 | { |
a1398e0c PA |
8802 | if (b == except) |
8803 | continue; | |
e09342b5 TJB |
8804 | if (!breakpoint_enabled (b)) |
8805 | continue; | |
8806 | ||
a1398e0c PA |
8807 | if (b->type == type) |
8808 | i += hw_watchpoint_use_count (b); | |
8809 | else if (is_hardware_watchpoint (b)) | |
8810 | *other_type_used = 1; | |
e09342b5 TJB |
8811 | } |
8812 | ||
c906108c SS |
8813 | return i; |
8814 | } | |
8815 | ||
c906108c | 8816 | void |
fba45db2 | 8817 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8818 | { |
c5aa993b | 8819 | struct breakpoint *b; |
c906108c SS |
8820 | |
8821 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8822 | { |
cc60f2e3 | 8823 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8824 | { |
b5de0fa7 | 8825 | b->enable_state = bp_call_disabled; |
44702360 | 8826 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8827 | } |
8828 | } | |
c906108c SS |
8829 | } |
8830 | ||
8831 | void | |
fba45db2 | 8832 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8833 | { |
c5aa993b | 8834 | struct breakpoint *b; |
c906108c SS |
8835 | |
8836 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8837 | { |
cc60f2e3 | 8838 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8839 | { |
b5de0fa7 | 8840 | b->enable_state = bp_enabled; |
44702360 | 8841 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8842 | } |
8843 | } | |
c906108c SS |
8844 | } |
8845 | ||
8bea4e01 UW |
8846 | void |
8847 | disable_breakpoints_before_startup (void) | |
8848 | { | |
6c95b8df | 8849 | current_program_space->executing_startup = 1; |
44702360 | 8850 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8851 | } |
8852 | ||
8853 | void | |
8854 | enable_breakpoints_after_startup (void) | |
8855 | { | |
6c95b8df | 8856 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8857 | breakpoint_re_set (); |
8bea4e01 UW |
8858 | } |
8859 | ||
7c16b83e PA |
8860 | /* Create a new single-step breakpoint for thread THREAD, with no |
8861 | locations. */ | |
c906108c | 8862 | |
7c16b83e PA |
8863 | static struct breakpoint * |
8864 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8865 | { | |
8866 | struct breakpoint *b = XNEW (struct breakpoint); | |
8867 | ||
8868 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8869 | &momentary_breakpoint_ops); | |
8870 | ||
8871 | b->disposition = disp_donttouch; | |
8872 | b->frame_id = null_frame_id; | |
8873 | ||
8874 | b->thread = thread; | |
8875 | gdb_assert (b->thread != 0); | |
8876 | ||
8877 | add_to_breakpoint_chain (b); | |
8878 | ||
8879 | return b; | |
8880 | } | |
8881 | ||
8882 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8883 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8884 | frame. */ | |
c906108c SS |
8885 | |
8886 | struct breakpoint * | |
a6d9a66e UW |
8887 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8888 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8889 | { |
52f0bd74 | 8890 | struct breakpoint *b; |
edb3359d | 8891 | |
193facb3 JK |
8892 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8893 | tail-called one. */ | |
8894 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8895 | |
06edf0c0 | 8896 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8897 | b->enable_state = bp_enabled; |
8898 | b->disposition = disp_donttouch; | |
818dd999 | 8899 | b->frame_id = frame_id; |
c906108c | 8900 | |
4a64f543 MS |
8901 | /* If we're debugging a multi-threaded program, then we want |
8902 | momentary breakpoints to be active in only a single thread of | |
8903 | control. */ | |
39f77062 KB |
8904 | if (in_thread_list (inferior_ptid)) |
8905 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8906 | |
44702360 | 8907 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8908 | |
c906108c SS |
8909 | return b; |
8910 | } | |
611c83ae | 8911 | |
06edf0c0 | 8912 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8913 | The new breakpoint will have type TYPE, use OPS as its |
8914 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8915 | |
06edf0c0 PA |
8916 | static struct breakpoint * |
8917 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8918 | enum bptype type, | |
a1aa2221 LM |
8919 | const struct breakpoint_ops *ops, |
8920 | int loc_enabled) | |
e58b0e63 PA |
8921 | { |
8922 | struct breakpoint *copy; | |
8923 | ||
06edf0c0 | 8924 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8925 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8926 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8927 | |
a6d9a66e | 8928 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8929 | copy->loc->requested_address = orig->loc->requested_address; |
8930 | copy->loc->address = orig->loc->address; | |
8931 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8932 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8933 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8934 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8935 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8936 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8937 | copy->frame_id = orig->frame_id; |
8938 | copy->thread = orig->thread; | |
6c95b8df | 8939 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8940 | |
8941 | copy->enable_state = bp_enabled; | |
8942 | copy->disposition = disp_donttouch; | |
8943 | copy->number = internal_breakpoint_number--; | |
8944 | ||
44702360 | 8945 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8946 | return copy; |
8947 | } | |
8948 | ||
06edf0c0 PA |
8949 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8950 | ORIG is NULL. */ | |
8951 | ||
8952 | struct breakpoint * | |
8953 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8954 | { | |
8955 | /* If there's nothing to clone, then return nothing. */ | |
8956 | if (orig == NULL) | |
8957 | return NULL; | |
8958 | ||
a1aa2221 | 8959 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8960 | } |
8961 | ||
611c83ae | 8962 | struct breakpoint * |
a6d9a66e UW |
8963 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8964 | enum bptype type) | |
611c83ae PA |
8965 | { |
8966 | struct symtab_and_line sal; | |
8967 | ||
8968 | sal = find_pc_line (pc, 0); | |
8969 | sal.pc = pc; | |
8970 | sal.section = find_pc_overlay (pc); | |
8971 | sal.explicit_pc = 1; | |
8972 | ||
a6d9a66e | 8973 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8974 | } |
c906108c | 8975 | \f |
c5aa993b | 8976 | |
c906108c SS |
8977 | /* Tell the user we have just set a breakpoint B. */ |
8978 | ||
8979 | static void | |
fba45db2 | 8980 | mention (struct breakpoint *b) |
c906108c | 8981 | { |
348d480f | 8982 | b->ops->print_mention (b); |
79a45e25 | 8983 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8984 | return; |
c906108c SS |
8985 | printf_filtered ("\n"); |
8986 | } | |
c906108c | 8987 | \f |
c5aa993b | 8988 | |
1a853c52 PA |
8989 | static int bp_loc_is_permanent (struct bp_location *loc); |
8990 | ||
0d381245 | 8991 | static struct bp_location * |
39d61571 | 8992 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8993 | const struct symtab_and_line *sal) |
8994 | { | |
8995 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8996 | CORE_ADDR adjusted_address; |
8997 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8998 | ||
8999 | if (loc_gdbarch == NULL) | |
9000 | loc_gdbarch = b->gdbarch; | |
9001 | ||
9002 | /* Adjust the breakpoint's address prior to allocating a location. | |
9003 | Once we call allocate_bp_location(), that mostly uninitialized | |
9004 | location will be placed on the location chain. Adjustment of the | |
9005 | breakpoint may cause target_read_memory() to be called and we do | |
9006 | not want its scan of the location chain to find a breakpoint and | |
9007 | location that's only been partially initialized. */ | |
9008 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9009 | sal->pc, b->type); | |
0d381245 | 9010 | |
d30113d4 | 9011 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9012 | loc = allocate_bp_location (b); |
d30113d4 JK |
9013 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9014 | tmp = &((*tmp)->next)) | |
0d381245 | 9015 | ; |
d30113d4 | 9016 | loc->next = *tmp; |
0d381245 | 9017 | *tmp = loc; |
3742cc8b | 9018 | |
0d381245 | 9019 | loc->requested_address = sal->pc; |
3742cc8b | 9020 | loc->address = adjusted_address; |
6c95b8df | 9021 | loc->pspace = sal->pspace; |
729662a5 TT |
9022 | loc->probe.probe = sal->probe; |
9023 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9024 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9025 | loc->section = sal->section; |
3742cc8b | 9026 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9027 | loc->line_number = sal->line; |
2f202fde | 9028 | loc->symtab = sal->symtab; |
f8eba3c6 | 9029 | |
0e30163f JK |
9030 | set_breakpoint_location_function (loc, |
9031 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9032 | |
6ae88661 LM |
9033 | /* While by definition, permanent breakpoints are already present in the |
9034 | code, we don't mark the location as inserted. Normally one would expect | |
9035 | that GDB could rely on that breakpoint instruction to stop the program, | |
9036 | thus removing the need to insert its own breakpoint, except that executing | |
9037 | the breakpoint instruction can kill the target instead of reporting a | |
9038 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9039 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9040 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9041 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9042 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9043 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9044 | it manually increments the PC, thus avoiding executing the breakpoint | |
9045 | instruction.) */ | |
1a853c52 | 9046 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9047 | loc->permanent = 1; |
1a853c52 | 9048 | |
0d381245 VP |
9049 | return loc; |
9050 | } | |
514f746b AR |
9051 | \f |
9052 | ||
1cf4d951 | 9053 | /* See breakpoint.h. */ |
514f746b | 9054 | |
1cf4d951 PA |
9055 | int |
9056 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9057 | { |
9058 | int len; | |
9059 | CORE_ADDR addr; | |
1afeeb75 | 9060 | const gdb_byte *bpoint; |
514f746b | 9061 | gdb_byte *target_mem; |
939c61fa JK |
9062 | struct cleanup *cleanup; |
9063 | int retval = 0; | |
514f746b | 9064 | |
1cf4d951 PA |
9065 | addr = address; |
9066 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9067 | ||
9068 | /* Software breakpoints unsupported? */ | |
9069 | if (bpoint == NULL) | |
9070 | return 0; | |
9071 | ||
224c3ddb | 9072 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9073 | |
9074 | /* Enable the automatic memory restoration from breakpoints while | |
9075 | we read the memory. Otherwise we could say about our temporary | |
9076 | breakpoints they are permanent. */ | |
9077 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9078 | ||
9079 | if (target_read_memory (address, target_mem, len) == 0 | |
9080 | && memcmp (target_mem, bpoint, len) == 0) | |
9081 | retval = 1; | |
9082 | ||
9083 | do_cleanups (cleanup); | |
9084 | ||
9085 | return retval; | |
9086 | } | |
9087 | ||
9088 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9089 | return 0 otherwise. */ | |
9090 | ||
9091 | static int | |
9092 | bp_loc_is_permanent (struct bp_location *loc) | |
9093 | { | |
9094 | struct cleanup *cleanup; | |
9095 | int retval; | |
9096 | ||
514f746b AR |
9097 | gdb_assert (loc != NULL); |
9098 | ||
244558af LM |
9099 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9100 | attempt to read from the addresses the locations of these breakpoint types | |
9101 | point to. program_breakpoint_here_p, below, will attempt to read | |
9102 | memory. */ | |
9103 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9104 | return 0; | |
9105 | ||
6c95b8df | 9106 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9107 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9108 | |
1cf4d951 | 9109 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9110 | |
939c61fa JK |
9111 | do_cleanups (cleanup); |
9112 | ||
9113 | return retval; | |
514f746b AR |
9114 | } |
9115 | ||
e7e0cddf SS |
9116 | /* Build a command list for the dprintf corresponding to the current |
9117 | settings of the dprintf style options. */ | |
9118 | ||
9119 | static void | |
9120 | update_dprintf_command_list (struct breakpoint *b) | |
9121 | { | |
9122 | char *dprintf_args = b->extra_string; | |
9123 | char *printf_line = NULL; | |
9124 | ||
9125 | if (!dprintf_args) | |
9126 | return; | |
9127 | ||
9128 | dprintf_args = skip_spaces (dprintf_args); | |
9129 | ||
9130 | /* Allow a comma, as it may have terminated a location, but don't | |
9131 | insist on it. */ | |
9132 | if (*dprintf_args == ',') | |
9133 | ++dprintf_args; | |
9134 | dprintf_args = skip_spaces (dprintf_args); | |
9135 | ||
9136 | if (*dprintf_args != '"') | |
9137 | error (_("Bad format string, missing '\"'.")); | |
9138 | ||
d3ce09f5 | 9139 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9140 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9141 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9142 | { |
9143 | if (!dprintf_function) | |
9144 | error (_("No function supplied for dprintf call")); | |
9145 | ||
9146 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9147 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9148 | dprintf_function, | |
9149 | dprintf_channel, | |
9150 | dprintf_args); | |
9151 | else | |
9152 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9153 | dprintf_function, | |
9154 | dprintf_args); | |
9155 | } | |
d3ce09f5 SS |
9156 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9157 | { | |
9158 | if (target_can_run_breakpoint_commands ()) | |
9159 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9160 | else | |
9161 | { | |
9162 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9163 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9164 | } | |
9165 | } | |
e7e0cddf SS |
9166 | else |
9167 | internal_error (__FILE__, __LINE__, | |
9168 | _("Invalid dprintf style.")); | |
9169 | ||
f28045c2 | 9170 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9171 | /* Manufacture a printf sequence. */ |
f28045c2 | 9172 | { |
8d749320 | 9173 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9174 | |
f28045c2 YQ |
9175 | printf_cmd_line->control_type = simple_control; |
9176 | printf_cmd_line->body_count = 0; | |
9177 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9178 | printf_cmd_line->next = NULL; |
f28045c2 | 9179 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9180 | |
f28045c2 YQ |
9181 | breakpoint_set_commands (b, printf_cmd_line); |
9182 | } | |
e7e0cddf SS |
9183 | } |
9184 | ||
9185 | /* Update all dprintf commands, making their command lists reflect | |
9186 | current style settings. */ | |
9187 | ||
9188 | static void | |
9189 | update_dprintf_commands (char *args, int from_tty, | |
9190 | struct cmd_list_element *c) | |
9191 | { | |
9192 | struct breakpoint *b; | |
9193 | ||
9194 | ALL_BREAKPOINTS (b) | |
9195 | { | |
9196 | if (b->type == bp_dprintf) | |
9197 | update_dprintf_command_list (b); | |
9198 | } | |
9199 | } | |
c3f6f71d | 9200 | |
f00aae0f KS |
9201 | /* Create a breakpoint with SAL as location. Use LOCATION |
9202 | as a description of the location, and COND_STRING | |
db107f19 | 9203 | as condition expression. */ |
018d34a4 VP |
9204 | |
9205 | static void | |
d9b3f62e | 9206 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9207 | struct symtabs_and_lines sals, |
9208 | struct event_location *location, | |
f8eba3c6 | 9209 | char *filter, char *cond_string, |
e7e0cddf | 9210 | char *extra_string, |
d9b3f62e PA |
9211 | enum bptype type, enum bpdisp disposition, |
9212 | int thread, int task, int ignore_count, | |
c0a91b2b | 9213 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9214 | int enabled, int internal, unsigned flags, |
9215 | int display_canonical) | |
018d34a4 | 9216 | { |
0d381245 | 9217 | int i; |
018d34a4 VP |
9218 | |
9219 | if (type == bp_hardware_breakpoint) | |
9220 | { | |
fbbd034e AS |
9221 | int target_resources_ok; |
9222 | ||
9223 | i = hw_breakpoint_used_count (); | |
9224 | target_resources_ok = | |
9225 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9226 | i + 1, 0); |
9227 | if (target_resources_ok == 0) | |
9228 | error (_("No hardware breakpoint support in the target.")); | |
9229 | else if (target_resources_ok < 0) | |
9230 | error (_("Hardware breakpoints used exceeds limit.")); | |
9231 | } | |
9232 | ||
6c95b8df PA |
9233 | gdb_assert (sals.nelts > 0); |
9234 | ||
0d381245 VP |
9235 | for (i = 0; i < sals.nelts; ++i) |
9236 | { | |
9237 | struct symtab_and_line sal = sals.sals[i]; | |
9238 | struct bp_location *loc; | |
9239 | ||
9240 | if (from_tty) | |
5af949e3 UW |
9241 | { |
9242 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9243 | if (!loc_gdbarch) | |
9244 | loc_gdbarch = gdbarch; | |
9245 | ||
9246 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9247 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9248 | } |
0d381245 VP |
9249 | |
9250 | if (i == 0) | |
9251 | { | |
d9b3f62e | 9252 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9253 | b->thread = thread; |
4a306c9a | 9254 | b->task = task; |
855a6e68 | 9255 | |
0d381245 | 9256 | b->cond_string = cond_string; |
e7e0cddf | 9257 | b->extra_string = extra_string; |
0d381245 | 9258 | b->ignore_count = ignore_count; |
41447f92 | 9259 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9260 | b->disposition = disposition; |
6c95b8df | 9261 | |
44f238bb PA |
9262 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9263 | b->loc->inserted = 1; | |
9264 | ||
0fb4aa4b PA |
9265 | if (type == bp_static_tracepoint) |
9266 | { | |
d9b3f62e | 9267 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9268 | struct static_tracepoint_marker marker; |
9269 | ||
983af33b | 9270 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9271 | { |
9272 | /* We already know the marker exists, otherwise, we | |
9273 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9274 | const char *p = &event_location_to_string (b->location)[3]; |
9275 | const char *endp; | |
0fb4aa4b | 9276 | char *marker_str; |
0fb4aa4b | 9277 | |
f00aae0f | 9278 | p = skip_spaces_const (p); |
0fb4aa4b | 9279 | |
f00aae0f | 9280 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9281 | |
9282 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9283 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9284 | |
3e43a32a MS |
9285 | printf_filtered (_("Probed static tracepoint " |
9286 | "marker \"%s\"\n"), | |
d9b3f62e | 9287 | t->static_trace_marker_id); |
0fb4aa4b PA |
9288 | } |
9289 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9290 | { | |
d9b3f62e | 9291 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9292 | release_static_tracepoint_marker (&marker); |
9293 | ||
3e43a32a MS |
9294 | printf_filtered (_("Probed static tracepoint " |
9295 | "marker \"%s\"\n"), | |
d9b3f62e | 9296 | t->static_trace_marker_id); |
0fb4aa4b PA |
9297 | } |
9298 | else | |
3e43a32a MS |
9299 | warning (_("Couldn't determine the static " |
9300 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9301 | } |
9302 | ||
0d381245 VP |
9303 | loc = b->loc; |
9304 | } | |
9305 | else | |
018d34a4 | 9306 | { |
39d61571 | 9307 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9308 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9309 | loc->inserted = 1; | |
0d381245 VP |
9310 | } |
9311 | ||
9312 | if (b->cond_string) | |
9313 | { | |
bbc13ae3 KS |
9314 | const char *arg = b->cond_string; |
9315 | ||
1bb9788d TT |
9316 | loc->cond = parse_exp_1 (&arg, loc->address, |
9317 | block_for_pc (loc->address), 0); | |
0d381245 | 9318 | if (*arg) |
588ae58c | 9319 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9320 | } |
e7e0cddf SS |
9321 | |
9322 | /* Dynamic printf requires and uses additional arguments on the | |
9323 | command line, otherwise it's an error. */ | |
9324 | if (type == bp_dprintf) | |
9325 | { | |
9326 | if (b->extra_string) | |
9327 | update_dprintf_command_list (b); | |
9328 | else | |
9329 | error (_("Format string required")); | |
9330 | } | |
9331 | else if (b->extra_string) | |
588ae58c | 9332 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9333 | } |
018d34a4 | 9334 | |
56435ebe | 9335 | b->display_canonical = display_canonical; |
f00aae0f KS |
9336 | if (location != NULL) |
9337 | b->location = location; | |
018d34a4 | 9338 | else |
a06efdd6 | 9339 | b->location = new_address_location (b->loc->address); |
f8eba3c6 | 9340 | b->filter = filter; |
d9b3f62e | 9341 | } |
018d34a4 | 9342 | |
d9b3f62e PA |
9343 | static void |
9344 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9345 | struct symtabs_and_lines sals, |
9346 | struct event_location *location, | |
f8eba3c6 | 9347 | char *filter, char *cond_string, |
e7e0cddf | 9348 | char *extra_string, |
d9b3f62e PA |
9349 | enum bptype type, enum bpdisp disposition, |
9350 | int thread, int task, int ignore_count, | |
c0a91b2b | 9351 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9352 | int enabled, int internal, unsigned flags, |
9353 | int display_canonical) | |
d9b3f62e PA |
9354 | { |
9355 | struct breakpoint *b; | |
9356 | struct cleanup *old_chain; | |
9357 | ||
9358 | if (is_tracepoint_type (type)) | |
9359 | { | |
9360 | struct tracepoint *t; | |
9361 | ||
9362 | t = XCNEW (struct tracepoint); | |
9363 | b = &t->base; | |
9364 | } | |
9365 | else | |
9366 | b = XNEW (struct breakpoint); | |
9367 | ||
9368 | old_chain = make_cleanup (xfree, b); | |
9369 | ||
9370 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9371 | sals, location, |
e7e0cddf | 9372 | filter, cond_string, extra_string, |
d9b3f62e PA |
9373 | type, disposition, |
9374 | thread, task, ignore_count, | |
9375 | ops, from_tty, | |
44f238bb PA |
9376 | enabled, internal, flags, |
9377 | display_canonical); | |
d9b3f62e PA |
9378 | discard_cleanups (old_chain); |
9379 | ||
3ea46bff | 9380 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9381 | } |
9382 | ||
9383 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9384 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9385 | value. COND_STRING, if not NULL, specified the condition to be | |
9386 | used for all breakpoints. Essentially the only case where | |
9387 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9388 | function. In that case, it's still not possible to specify | |
9389 | separate conditions for different overloaded functions, so | |
9390 | we take just a single condition string. | |
9391 | ||
c3f6f71d | 9392 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9393 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9394 | array contents). If the function fails (error() is called), the |
9395 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9396 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9397 | |
9398 | static void | |
8cdf0e15 | 9399 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9400 | struct linespec_result *canonical, |
e7e0cddf | 9401 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9402 | enum bptype type, enum bpdisp disposition, |
9403 | int thread, int task, int ignore_count, | |
c0a91b2b | 9404 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9405 | int enabled, int internal, unsigned flags) |
c906108c | 9406 | { |
018d34a4 | 9407 | int i; |
f8eba3c6 | 9408 | struct linespec_sals *lsal; |
cc59ec59 | 9409 | |
f8eba3c6 TT |
9410 | if (canonical->pre_expanded) |
9411 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9412 | ||
9413 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9414 | { |
f00aae0f | 9415 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9416 | 'break', without arguments. */ |
f00aae0f KS |
9417 | struct event_location *location |
9418 | = (canonical->location != NULL | |
9419 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9420 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9421 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9422 | |
f8eba3c6 TT |
9423 | make_cleanup (xfree, filter_string); |
9424 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9425 | location, |
f8eba3c6 | 9426 | filter_string, |
e7e0cddf SS |
9427 | cond_string, extra_string, |
9428 | type, disposition, | |
84f4c1fe | 9429 | thread, task, ignore_count, ops, |
44f238bb | 9430 | from_tty, enabled, internal, flags, |
56435ebe | 9431 | canonical->special_display); |
f8eba3c6 | 9432 | discard_cleanups (inner); |
c3f6f71d | 9433 | } |
c3f6f71d | 9434 | } |
c906108c | 9435 | |
f00aae0f | 9436 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9437 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9438 | addresses found. LOCATION points to the end of the SAL (for |
9439 | linespec locations). | |
9998af43 TJB |
9440 | |
9441 | The array and the line spec strings are allocated on the heap, it is | |
9442 | the caller's responsibility to free them. */ | |
c906108c | 9443 | |
b9362cc7 | 9444 | static void |
f00aae0f | 9445 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9446 | struct linespec_result *canonical) |
c3f6f71d | 9447 | { |
f00aae0f KS |
9448 | struct symtab_and_line cursal; |
9449 | ||
9450 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9451 | { | |
9452 | const char *address = get_linespec_location (location); | |
9453 | ||
9454 | if (address == NULL) | |
9455 | { | |
9456 | /* The last displayed codepoint, if it's valid, is our default | |
9457 | breakpoint address. */ | |
9458 | if (last_displayed_sal_is_valid ()) | |
9459 | { | |
9460 | struct linespec_sals lsal; | |
9461 | struct symtab_and_line sal; | |
9462 | CORE_ADDR pc; | |
9463 | ||
9464 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9465 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9466 | |
9467 | /* Set sal's pspace, pc, symtab, and line to the values | |
9468 | corresponding to the last call to print_frame_info. | |
9469 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9470 | as the breakpoint line number is inappropriate otherwise. | |
9471 | find_pc_line would adjust PC, re-set it back. */ | |
9472 | get_last_displayed_sal (&sal); | |
9473 | pc = sal.pc; | |
9474 | sal = find_pc_line (pc, 0); | |
9475 | ||
9476 | /* "break" without arguments is equivalent to "break *PC" | |
9477 | where PC is the last displayed codepoint's address. So | |
9478 | make sure to set sal.explicit_pc to prevent GDB from | |
9479 | trying to expand the list of sals to include all other | |
9480 | instances with the same symtab and line. */ | |
9481 | sal.pc = pc; | |
9482 | sal.explicit_pc = 1; | |
9483 | ||
9484 | lsal.sals.sals[0] = sal; | |
9485 | lsal.sals.nelts = 1; | |
9486 | lsal.canonical = NULL; | |
9487 | ||
9488 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9489 | return; | |
9490 | } | |
9491 | else | |
9492 | error (_("No default breakpoint address now.")); | |
c906108c | 9493 | } |
c906108c | 9494 | } |
f00aae0f KS |
9495 | |
9496 | /* Force almost all breakpoints to be in terms of the | |
9497 | current_source_symtab (which is decode_line_1's default). | |
9498 | This should produce the results we want almost all of the | |
9499 | time while leaving default_breakpoint_* alone. | |
9500 | ||
9501 | ObjC: However, don't match an Objective-C method name which | |
9502 | may have a '+' or '-' succeeded by a '['. */ | |
9503 | cursal = get_current_source_symtab_and_line (); | |
9504 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9505 | { |
f00aae0f | 9506 | const char *address = NULL; |
cc80f267 | 9507 | |
f00aae0f KS |
9508 | if (event_location_type (location) == LINESPEC_LOCATION) |
9509 | address = get_linespec_location (location); | |
cc80f267 | 9510 | |
f00aae0f KS |
9511 | if (!cursal.symtab |
9512 | || (address != NULL | |
9513 | && strchr ("+-", address[0]) != NULL | |
9514 | && address[1] != '[')) | |
9515 | { | |
9516 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, | |
9517 | get_last_displayed_symtab (), | |
9518 | get_last_displayed_line (), | |
9519 | canonical, NULL, NULL); | |
9520 | return; | |
9521 | } | |
c906108c | 9522 | } |
f00aae0f KS |
9523 | |
9524 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, | |
9525 | cursal.symtab, cursal.line, canonical, NULL, NULL); | |
c3f6f71d | 9526 | } |
c906108c | 9527 | |
c906108c | 9528 | |
c3f6f71d | 9529 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9530 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9531 | |
b9362cc7 | 9532 | static void |
23e7acfb | 9533 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9534 | { |
9535 | int i; | |
cc59ec59 | 9536 | |
c3f6f71d | 9537 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9538 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9539 | } |
9540 | ||
7a697b8d SS |
9541 | /* Fast tracepoints may have restrictions on valid locations. For |
9542 | instance, a fast tracepoint using a jump instead of a trap will | |
9543 | likely have to overwrite more bytes than a trap would, and so can | |
9544 | only be placed where the instruction is longer than the jump, or a | |
9545 | multi-instruction sequence does not have a jump into the middle of | |
9546 | it, etc. */ | |
9547 | ||
9548 | static void | |
9549 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9550 | struct symtabs_and_lines *sals) | |
9551 | { | |
9552 | int i, rslt; | |
9553 | struct symtab_and_line *sal; | |
9554 | char *msg; | |
9555 | struct cleanup *old_chain; | |
9556 | ||
9557 | for (i = 0; i < sals->nelts; i++) | |
9558 | { | |
f8eba3c6 TT |
9559 | struct gdbarch *sarch; |
9560 | ||
7a697b8d SS |
9561 | sal = &sals->sals[i]; |
9562 | ||
f8eba3c6 TT |
9563 | sarch = get_sal_arch (*sal); |
9564 | /* We fall back to GDBARCH if there is no architecture | |
9565 | associated with SAL. */ | |
9566 | if (sarch == NULL) | |
9567 | sarch = gdbarch; | |
6b940e6a | 9568 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9569 | old_chain = make_cleanup (xfree, msg); |
9570 | ||
9571 | if (!rslt) | |
9572 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9573 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9574 | |
9575 | do_cleanups (old_chain); | |
9576 | } | |
9577 | } | |
9578 | ||
af4908ba KS |
9579 | /* Issue an invalid thread ID error. */ |
9580 | ||
9581 | static void ATTRIBUTE_NORETURN | |
9582 | invalid_thread_id_error (int id) | |
9583 | { | |
9584 | error (_("Unknown thread %d."), id); | |
9585 | } | |
9586 | ||
018d34a4 VP |
9587 | /* Given TOK, a string specification of condition and thread, as |
9588 | accepted by the 'break' command, extract the condition | |
9589 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9590 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9591 | If no condition is found, *COND_STRING is set to NULL. |
9592 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9593 | |
9594 | static void | |
bbc13ae3 | 9595 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9596 | char **cond_string, int *thread, int *task, |
9597 | char **rest) | |
018d34a4 VP |
9598 | { |
9599 | *cond_string = NULL; | |
9600 | *thread = -1; | |
ed1d1739 KS |
9601 | *task = 0; |
9602 | *rest = NULL; | |
9603 | ||
018d34a4 VP |
9604 | while (tok && *tok) |
9605 | { | |
bbc13ae3 | 9606 | const char *end_tok; |
018d34a4 | 9607 | int toklen; |
bbc13ae3 KS |
9608 | const char *cond_start = NULL; |
9609 | const char *cond_end = NULL; | |
cc59ec59 | 9610 | |
bbc13ae3 | 9611 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9612 | |
9613 | if ((*tok == '"' || *tok == ',') && rest) | |
9614 | { | |
9615 | *rest = savestring (tok, strlen (tok)); | |
9616 | return; | |
9617 | } | |
9618 | ||
bbc13ae3 | 9619 | end_tok = skip_to_space_const (tok); |
d634f2de | 9620 | |
018d34a4 | 9621 | toklen = end_tok - tok; |
d634f2de | 9622 | |
018d34a4 VP |
9623 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9624 | { | |
f7545552 TT |
9625 | struct expression *expr; |
9626 | ||
018d34a4 | 9627 | tok = cond_start = end_tok + 1; |
1bb9788d | 9628 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9629 | xfree (expr); |
018d34a4 | 9630 | cond_end = tok; |
d634f2de | 9631 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9632 | } |
9633 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9634 | { | |
9635 | char *tmptok; | |
d634f2de | 9636 | |
018d34a4 | 9637 | tok = end_tok + 1; |
bbc13ae3 | 9638 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9639 | if (tok == tmptok) |
9640 | error (_("Junk after thread keyword.")); | |
9641 | if (!valid_thread_id (*thread)) | |
af4908ba | 9642 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9643 | tok = tmptok; |
018d34a4 | 9644 | } |
4a306c9a JB |
9645 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9646 | { | |
9647 | char *tmptok; | |
9648 | ||
9649 | tok = end_tok + 1; | |
bbc13ae3 | 9650 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9651 | if (tok == tmptok) |
9652 | error (_("Junk after task keyword.")); | |
9653 | if (!valid_task_id (*task)) | |
b6199126 | 9654 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9655 | tok = tmptok; |
4a306c9a | 9656 | } |
e7e0cddf SS |
9657 | else if (rest) |
9658 | { | |
9659 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9660 | return; |
e7e0cddf | 9661 | } |
018d34a4 VP |
9662 | else |
9663 | error (_("Junk at end of arguments.")); | |
9664 | } | |
9665 | } | |
9666 | ||
0fb4aa4b PA |
9667 | /* Decode a static tracepoint marker spec. */ |
9668 | ||
9669 | static struct symtabs_and_lines | |
f00aae0f | 9670 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9671 | { |
9672 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9673 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9674 | struct cleanup *old_chain; |
f00aae0f KS |
9675 | const char *p = &(*arg_p)[3]; |
9676 | const char *endp; | |
0fb4aa4b PA |
9677 | char *marker_str; |
9678 | int i; | |
9679 | ||
f00aae0f | 9680 | p = skip_spaces_const (p); |
0fb4aa4b | 9681 | |
f00aae0f | 9682 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9683 | |
9684 | marker_str = savestring (p, endp - p); | |
9685 | old_chain = make_cleanup (xfree, marker_str); | |
9686 | ||
9687 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9688 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9689 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9690 | ||
9691 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9692 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9693 | |
9694 | for (i = 0; i < sals.nelts; i++) | |
9695 | { | |
9696 | struct static_tracepoint_marker *marker; | |
9697 | ||
9698 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9699 | ||
9700 | init_sal (&sals.sals[i]); | |
9701 | ||
9702 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9703 | sals.sals[i].pc = marker->address; | |
9704 | ||
9705 | release_static_tracepoint_marker (marker); | |
9706 | } | |
9707 | ||
9708 | do_cleanups (old_chain); | |
9709 | ||
9710 | *arg_p = endp; | |
9711 | return sals; | |
9712 | } | |
9713 | ||
f00aae0f | 9714 | /* See breakpoint.h. */ |
0101ce28 | 9715 | |
8cdf0e15 VP |
9716 | int |
9717 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9718 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9719 | int thread, char *extra_string, |
f00aae0f | 9720 | int parse_extra, |
0fb4aa4b | 9721 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9722 | int ignore_count, |
9723 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9724 | const struct breakpoint_ops *ops, |
44f238bb PA |
9725 | int from_tty, int enabled, int internal, |
9726 | unsigned flags) | |
c3f6f71d | 9727 | { |
7efd8fc2 | 9728 | struct linespec_result canonical; |
c3f6f71d | 9729 | struct cleanup *old_chain; |
80c99de1 | 9730 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9731 | int pending = 0; |
4a306c9a | 9732 | int task = 0; |
86b17b60 | 9733 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9734 | |
348d480f PA |
9735 | gdb_assert (ops != NULL); |
9736 | ||
f00aae0f KS |
9737 | /* If extra_string isn't useful, set it to NULL. */ |
9738 | if (extra_string != NULL && *extra_string == '\0') | |
9739 | extra_string = NULL; | |
9740 | ||
7efd8fc2 | 9741 | init_linespec_result (&canonical); |
c3f6f71d | 9742 | |
492d29ea | 9743 | TRY |
b78a6381 | 9744 | { |
f00aae0f | 9745 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9746 | } |
492d29ea | 9747 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9748 | { |
492d29ea PA |
9749 | /* If caller is interested in rc value from parse, set |
9750 | value. */ | |
9751 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9752 | { |
05ff989b AC |
9753 | /* If pending breakpoint support is turned off, throw |
9754 | error. */ | |
fa8d40ab JJ |
9755 | |
9756 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9757 | throw_exception (e); |
9758 | ||
9759 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9760 | |
05ff989b AC |
9761 | /* If pending breakpoint support is auto query and the user |
9762 | selects no, then simply return the error code. */ | |
059fb39f | 9763 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9764 | && !nquery (_("Make %s pending on future shared library load? "), |
9765 | bptype_string (type_wanted))) | |
fd9b8c24 | 9766 | return 0; |
fa8d40ab | 9767 | |
05ff989b AC |
9768 | /* At this point, either the user was queried about setting |
9769 | a pending breakpoint and selected yes, or pending | |
9770 | breakpoint behavior is on and thus a pending breakpoint | |
9771 | is defaulted on behalf of the user. */ | |
f00aae0f | 9772 | pending = 1; |
0101ce28 | 9773 | } |
492d29ea PA |
9774 | else |
9775 | throw_exception (e); | |
0101ce28 | 9776 | } |
492d29ea PA |
9777 | END_CATCH |
9778 | ||
f00aae0f | 9779 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9780 | return 0; |
c3f6f71d | 9781 | |
4a64f543 | 9782 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9783 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9784 | |
c3f6f71d JM |
9785 | /* ----------------------------- SNIP ----------------------------- |
9786 | Anything added to the cleanup chain beyond this point is assumed | |
9787 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9788 | then the memory is not reclaimed. */ |
9789 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9790 | |
c3f6f71d JM |
9791 | /* Resolve all line numbers to PC's and verify that the addresses |
9792 | are ok for the target. */ | |
0101ce28 | 9793 | if (!pending) |
f8eba3c6 TT |
9794 | { |
9795 | int ix; | |
9796 | struct linespec_sals *iter; | |
9797 | ||
9798 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9799 | breakpoint_sals_to_pc (&iter->sals); | |
9800 | } | |
c3f6f71d | 9801 | |
7a697b8d | 9802 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9803 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9804 | { |
9805 | int ix; | |
9806 | struct linespec_sals *iter; | |
9807 | ||
9808 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9809 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9810 | } | |
7a697b8d | 9811 | |
c3f6f71d JM |
9812 | /* Verify that condition can be parsed, before setting any |
9813 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9814 | breakpoint. */ |
0101ce28 | 9815 | if (!pending) |
c3f6f71d | 9816 | { |
f00aae0f | 9817 | if (parse_extra) |
72b2ff0e | 9818 | { |
0878d0fa | 9819 | char *rest; |
52d361e1 YQ |
9820 | struct linespec_sals *lsal; |
9821 | ||
9822 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9823 | ||
0878d0fa YQ |
9824 | /* Here we only parse 'arg' to separate condition |
9825 | from thread number, so parsing in context of first | |
9826 | sal is OK. When setting the breakpoint we'll | |
9827 | re-parse it in context of each sal. */ | |
9828 | ||
f00aae0f KS |
9829 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9830 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9831 | if (cond_string) |
9832 | make_cleanup (xfree, cond_string); | |
9833 | if (rest) | |
9834 | make_cleanup (xfree, rest); | |
9835 | if (rest) | |
9836 | extra_string = rest; | |
f00aae0f KS |
9837 | else |
9838 | extra_string = NULL; | |
72b2ff0e | 9839 | } |
2f069f6f | 9840 | else |
72b2ff0e | 9841 | { |
f00aae0f KS |
9842 | if (type_wanted != bp_dprintf |
9843 | && extra_string != NULL && *extra_string != '\0') | |
9844 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9845 | |
9846 | /* Create a private copy of condition string. */ | |
9847 | if (cond_string) | |
9848 | { | |
9849 | cond_string = xstrdup (cond_string); | |
9850 | make_cleanup (xfree, cond_string); | |
9851 | } | |
9852 | /* Create a private copy of any extra string. */ | |
9853 | if (extra_string) | |
9854 | { | |
9855 | extra_string = xstrdup (extra_string); | |
9856 | make_cleanup (xfree, extra_string); | |
9857 | } | |
72b2ff0e | 9858 | } |
0fb4aa4b | 9859 | |
52d361e1 | 9860 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9861 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9862 | tempflag ? disp_del : disp_donttouch, |
9863 | thread, task, ignore_count, ops, | |
44f238bb | 9864 | from_tty, enabled, internal, flags); |
c906108c | 9865 | } |
0101ce28 JJ |
9866 | else |
9867 | { | |
0101ce28 JJ |
9868 | struct breakpoint *b; |
9869 | ||
bfccc43c YQ |
9870 | if (is_tracepoint_type (type_wanted)) |
9871 | { | |
9872 | struct tracepoint *t; | |
9873 | ||
9874 | t = XCNEW (struct tracepoint); | |
9875 | b = &t->base; | |
9876 | } | |
9877 | else | |
9878 | b = XNEW (struct breakpoint); | |
9879 | ||
9880 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9881 | b->location = copy_event_location (location); |
bfccc43c | 9882 | |
f00aae0f KS |
9883 | if (parse_extra) |
9884 | b->cond_string = NULL; | |
e12c7713 MK |
9885 | else |
9886 | { | |
9887 | /* Create a private copy of condition string. */ | |
9888 | if (cond_string) | |
9889 | { | |
9890 | cond_string = xstrdup (cond_string); | |
9891 | make_cleanup (xfree, cond_string); | |
9892 | } | |
9893 | b->cond_string = cond_string; | |
15630549 | 9894 | b->thread = thread; |
e12c7713 | 9895 | } |
f00aae0f KS |
9896 | |
9897 | /* Create a private copy of any extra string. */ | |
9898 | if (extra_string != NULL) | |
9899 | { | |
9900 | extra_string = xstrdup (extra_string); | |
9901 | make_cleanup (xfree, extra_string); | |
9902 | } | |
9903 | b->extra_string = extra_string; | |
0101ce28 | 9904 | b->ignore_count = ignore_count; |
0101ce28 | 9905 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9906 | b->condition_not_parsed = 1; |
41447f92 | 9907 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9908 | if ((type_wanted != bp_breakpoint |
9909 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9910 | b->pspace = current_program_space; |
8bea4e01 | 9911 | |
bfccc43c | 9912 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9913 | } |
9914 | ||
f8eba3c6 | 9915 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9916 | { |
3e43a32a MS |
9917 | warning (_("Multiple breakpoints were set.\nUse the " |
9918 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9919 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9920 | } |
9921 | ||
80c99de1 PA |
9922 | /* That's it. Discard the cleanups for data inserted into the |
9923 | breakpoint. */ | |
9924 | discard_cleanups (bkpt_chain); | |
9925 | /* But cleanup everything else. */ | |
c3f6f71d | 9926 | do_cleanups (old_chain); |
217dc9e2 | 9927 | |
80c99de1 | 9928 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9929 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9930 | |
9931 | return 1; | |
c3f6f71d | 9932 | } |
c906108c | 9933 | |
348d480f | 9934 | /* Set a breakpoint. |
72b2ff0e VP |
9935 | ARG is a string describing breakpoint address, |
9936 | condition, and thread. | |
9937 | FLAG specifies if a breakpoint is hardware on, | |
9938 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9939 | and BP_TEMPFLAG. */ | |
348d480f | 9940 | |
98deb0da | 9941 | static void |
72b2ff0e | 9942 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9943 | { |
72b2ff0e | 9944 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9945 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9946 | ? bp_hardware_breakpoint | |
9947 | : bp_breakpoint); | |
55aa24fb | 9948 | struct breakpoint_ops *ops; |
f00aae0f KS |
9949 | struct event_location *location; |
9950 | struct cleanup *cleanup; | |
9951 | ||
9952 | location = string_to_event_location (&arg, current_language); | |
9953 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
9954 | |
9955 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
9956 | if (location != NULL |
9957 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
9958 | ops = &bkpt_probe_breakpoint_ops; |
9959 | else | |
9960 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9961 | |
8cdf0e15 | 9962 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
9963 | location, |
9964 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 9965 | tempflag, type_wanted, |
8cdf0e15 VP |
9966 | 0 /* Ignore count */, |
9967 | pending_break_support, | |
55aa24fb | 9968 | ops, |
8cdf0e15 | 9969 | from_tty, |
84f4c1fe | 9970 | 1 /* enabled */, |
44f238bb PA |
9971 | 0 /* internal */, |
9972 | 0); | |
f00aae0f | 9973 | do_cleanups (cleanup); |
c906108c SS |
9974 | } |
9975 | ||
c906108c SS |
9976 | /* Helper function for break_command_1 and disassemble_command. */ |
9977 | ||
9978 | void | |
fba45db2 | 9979 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9980 | { |
9981 | CORE_ADDR pc; | |
9982 | ||
9983 | if (sal->pc == 0 && sal->symtab != NULL) | |
9984 | { | |
9985 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9986 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9987 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9988 | sal->pc = pc; |
6a048695 | 9989 | |
4a64f543 MS |
9990 | /* If this SAL corresponds to a breakpoint inserted using a line |
9991 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9992 | if (sal->explicit_line) |
059acae7 | 9993 | skip_prologue_sal (sal); |
c906108c SS |
9994 | } |
9995 | ||
9996 | if (sal->section == 0 && sal->symtab != NULL) | |
9997 | { | |
346d1dfe | 9998 | const struct blockvector *bv; |
3977b71f | 9999 | const struct block *b; |
c5aa993b | 10000 | struct symbol *sym; |
c906108c | 10001 | |
43f3e411 DE |
10002 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10003 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10004 | if (bv != NULL) |
10005 | { | |
7f0df278 | 10006 | sym = block_linkage_function (b); |
c906108c SS |
10007 | if (sym != NULL) |
10008 | { | |
eb822aa6 DE |
10009 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10010 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10011 | sym); | |
c906108c SS |
10012 | } |
10013 | else | |
10014 | { | |
4a64f543 MS |
10015 | /* It really is worthwhile to have the section, so we'll |
10016 | just have to look harder. This case can be executed | |
10017 | if we have line numbers but no functions (as can | |
10018 | happen in assembly source). */ | |
c906108c | 10019 | |
7cbd4a93 | 10020 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10021 | struct cleanup *old_chain = save_current_space_and_thread (); |
10022 | ||
10023 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10024 | |
10025 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10026 | if (msym.minsym) |
efd66ac6 | 10027 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10028 | |
10029 | do_cleanups (old_chain); | |
c906108c SS |
10030 | } |
10031 | } | |
10032 | } | |
10033 | } | |
10034 | ||
10035 | void | |
fba45db2 | 10036 | break_command (char *arg, int from_tty) |
c906108c | 10037 | { |
db107f19 | 10038 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10039 | } |
10040 | ||
c906108c | 10041 | void |
fba45db2 | 10042 | tbreak_command (char *arg, int from_tty) |
c906108c | 10043 | { |
db107f19 | 10044 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10045 | } |
10046 | ||
c906108c | 10047 | static void |
fba45db2 | 10048 | hbreak_command (char *arg, int from_tty) |
c906108c | 10049 | { |
db107f19 | 10050 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10051 | } |
10052 | ||
10053 | static void | |
fba45db2 | 10054 | thbreak_command (char *arg, int from_tty) |
c906108c | 10055 | { |
db107f19 | 10056 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10057 | } |
10058 | ||
10059 | static void | |
fba45db2 | 10060 | stop_command (char *arg, int from_tty) |
c906108c | 10061 | { |
a3f17187 | 10062 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10063 | Usage: stop in <function | address>\n\ |
a3f17187 | 10064 | stop at <line>\n")); |
c906108c SS |
10065 | } |
10066 | ||
10067 | static void | |
fba45db2 | 10068 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10069 | { |
10070 | int badInput = 0; | |
10071 | ||
c5aa993b | 10072 | if (arg == (char *) NULL) |
c906108c SS |
10073 | badInput = 1; |
10074 | else if (*arg != '*') | |
10075 | { | |
10076 | char *argptr = arg; | |
10077 | int hasColon = 0; | |
10078 | ||
4a64f543 | 10079 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10080 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10081 | function/method name. */ |
c906108c | 10082 | while (*argptr && !hasColon) |
c5aa993b JM |
10083 | { |
10084 | hasColon = (*argptr == ':'); | |
10085 | argptr++; | |
10086 | } | |
c906108c SS |
10087 | |
10088 | if (hasColon) | |
c5aa993b | 10089 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10090 | else |
c5aa993b | 10091 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10092 | } |
10093 | ||
10094 | if (badInput) | |
a3f17187 | 10095 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10096 | else |
db107f19 | 10097 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10098 | } |
10099 | ||
10100 | static void | |
fba45db2 | 10101 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10102 | { |
10103 | int badInput = 0; | |
10104 | ||
c5aa993b | 10105 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10106 | badInput = 1; |
10107 | else | |
10108 | { | |
10109 | char *argptr = arg; | |
10110 | int hasColon = 0; | |
10111 | ||
4a64f543 MS |
10112 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10113 | it is probably a line number. */ | |
c906108c | 10114 | while (*argptr && !hasColon) |
c5aa993b JM |
10115 | { |
10116 | hasColon = (*argptr == ':'); | |
10117 | argptr++; | |
10118 | } | |
c906108c SS |
10119 | |
10120 | if (hasColon) | |
c5aa993b | 10121 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10122 | else |
c5aa993b | 10123 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10124 | } |
10125 | ||
10126 | if (badInput) | |
a3f17187 | 10127 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10128 | else |
db107f19 | 10129 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10130 | } |
10131 | ||
e7e0cddf SS |
10132 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10133 | with a prewired command list consisting of a single output command, | |
10134 | built from extra arguments supplied on the dprintf command | |
10135 | line. */ | |
10136 | ||
da821c7b | 10137 | static void |
e7e0cddf SS |
10138 | dprintf_command (char *arg, int from_tty) |
10139 | { | |
f00aae0f KS |
10140 | struct event_location *location; |
10141 | struct cleanup *cleanup; | |
10142 | ||
10143 | location = string_to_event_location (&arg, current_language); | |
10144 | cleanup = make_cleanup_delete_event_location (location); | |
10145 | ||
10146 | /* If non-NULL, ARG should have been advanced past the location; | |
10147 | the next character must be ','. */ | |
10148 | if (arg != NULL) | |
10149 | { | |
10150 | if (arg[0] != ',' || arg[1] == '\0') | |
10151 | error (_("Format string required")); | |
10152 | else | |
10153 | { | |
10154 | /* Skip the comma. */ | |
10155 | ++arg; | |
10156 | } | |
10157 | } | |
10158 | ||
e7e0cddf | 10159 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10160 | location, |
10161 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10162 | 0, bp_dprintf, |
10163 | 0 /* Ignore count */, | |
10164 | pending_break_support, | |
10165 | &dprintf_breakpoint_ops, | |
10166 | from_tty, | |
10167 | 1 /* enabled */, | |
10168 | 0 /* internal */, | |
10169 | 0); | |
f00aae0f | 10170 | do_cleanups (cleanup); |
e7e0cddf SS |
10171 | } |
10172 | ||
d3ce09f5 SS |
10173 | static void |
10174 | agent_printf_command (char *arg, int from_tty) | |
10175 | { | |
10176 | error (_("May only run agent-printf on the target")); | |
10177 | } | |
10178 | ||
f1310107 TJB |
10179 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10180 | ranged breakpoints. */ | |
10181 | ||
10182 | static int | |
10183 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10184 | struct address_space *aspace, | |
09ac7c10 TT |
10185 | CORE_ADDR bp_addr, |
10186 | const struct target_waitstatus *ws) | |
f1310107 | 10187 | { |
09ac7c10 | 10188 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10189 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10190 | return 0; |
10191 | ||
f1310107 TJB |
10192 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10193 | bl->length, aspace, bp_addr); | |
10194 | } | |
10195 | ||
10196 | /* Implement the "resources_needed" breakpoint_ops method for | |
10197 | ranged breakpoints. */ | |
10198 | ||
10199 | static int | |
10200 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10201 | { | |
10202 | return target_ranged_break_num_registers (); | |
10203 | } | |
10204 | ||
10205 | /* Implement the "print_it" breakpoint_ops method for | |
10206 | ranged breakpoints. */ | |
10207 | ||
10208 | static enum print_stop_action | |
348d480f | 10209 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10210 | { |
348d480f | 10211 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10212 | struct bp_location *bl = b->loc; |
79a45e25 | 10213 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10214 | |
10215 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10216 | ||
10217 | /* Ranged breakpoints have only one location. */ | |
10218 | gdb_assert (bl && bl->next == NULL); | |
10219 | ||
10220 | annotate_breakpoint (b->number); | |
10221 | if (b->disposition == disp_del) | |
10222 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10223 | else | |
10224 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10225 | if (ui_out_is_mi_like_p (uiout)) | |
10226 | { | |
10227 | ui_out_field_string (uiout, "reason", | |
10228 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10229 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10230 | } | |
10231 | ui_out_field_int (uiout, "bkptno", b->number); | |
10232 | ui_out_text (uiout, ", "); | |
10233 | ||
10234 | return PRINT_SRC_AND_LOC; | |
10235 | } | |
10236 | ||
10237 | /* Implement the "print_one" breakpoint_ops method for | |
10238 | ranged breakpoints. */ | |
10239 | ||
10240 | static void | |
10241 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10242 | struct bp_location **last_loc) | |
10243 | { | |
10244 | struct bp_location *bl = b->loc; | |
10245 | struct value_print_options opts; | |
79a45e25 | 10246 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10247 | |
10248 | /* Ranged breakpoints have only one location. */ | |
10249 | gdb_assert (bl && bl->next == NULL); | |
10250 | ||
10251 | get_user_print_options (&opts); | |
10252 | ||
10253 | if (opts.addressprint) | |
10254 | /* We don't print the address range here, it will be printed later | |
10255 | by print_one_detail_ranged_breakpoint. */ | |
10256 | ui_out_field_skip (uiout, "addr"); | |
10257 | annotate_field (5); | |
10258 | print_breakpoint_location (b, bl); | |
10259 | *last_loc = bl; | |
10260 | } | |
10261 | ||
10262 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10263 | ranged breakpoints. */ | |
10264 | ||
10265 | static void | |
10266 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10267 | struct ui_out *uiout) | |
10268 | { | |
10269 | CORE_ADDR address_start, address_end; | |
10270 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10271 | struct ui_file *stb = mem_fileopen (); |
10272 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10273 | |
10274 | gdb_assert (bl); | |
10275 | ||
10276 | address_start = bl->address; | |
10277 | address_end = address_start + bl->length - 1; | |
10278 | ||
10279 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10280 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10281 | print_core_address (bl->gdbarch, address_start), |
10282 | print_core_address (bl->gdbarch, address_end)); | |
10283 | ui_out_field_stream (uiout, "addr", stb); | |
10284 | ui_out_text (uiout, "\n"); | |
10285 | ||
10286 | do_cleanups (cleanup); | |
10287 | } | |
10288 | ||
10289 | /* Implement the "print_mention" breakpoint_ops method for | |
10290 | ranged breakpoints. */ | |
10291 | ||
10292 | static void | |
10293 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10294 | { | |
10295 | struct bp_location *bl = b->loc; | |
79a45e25 | 10296 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10297 | |
10298 | gdb_assert (bl); | |
10299 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10300 | ||
10301 | if (ui_out_is_mi_like_p (uiout)) | |
10302 | return; | |
10303 | ||
10304 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10305 | b->number, paddress (bl->gdbarch, bl->address), | |
10306 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10307 | } | |
10308 | ||
10309 | /* Implement the "print_recreate" breakpoint_ops method for | |
10310 | ranged breakpoints. */ | |
10311 | ||
10312 | static void | |
10313 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10314 | { | |
f00aae0f KS |
10315 | fprintf_unfiltered (fp, "break-range %s, %s", |
10316 | event_location_to_string (b->location), | |
10317 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10318 | print_recreate_thread (b, fp); |
f1310107 TJB |
10319 | } |
10320 | ||
10321 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10322 | ||
2060206e | 10323 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10324 | |
10325 | /* Find the address where the end of the breakpoint range should be | |
10326 | placed, given the SAL of the end of the range. This is so that if | |
10327 | the user provides a line number, the end of the range is set to the | |
10328 | last instruction of the given line. */ | |
10329 | ||
10330 | static CORE_ADDR | |
10331 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10332 | { | |
10333 | CORE_ADDR end; | |
10334 | ||
10335 | /* If the user provided a PC value, use it. Otherwise, | |
10336 | find the address of the end of the given location. */ | |
10337 | if (sal.explicit_pc) | |
10338 | end = sal.pc; | |
10339 | else | |
10340 | { | |
10341 | int ret; | |
10342 | CORE_ADDR start; | |
10343 | ||
10344 | ret = find_line_pc_range (sal, &start, &end); | |
10345 | if (!ret) | |
10346 | error (_("Could not find location of the end of the range.")); | |
10347 | ||
10348 | /* find_line_pc_range returns the start of the next line. */ | |
10349 | end--; | |
10350 | } | |
10351 | ||
10352 | return end; | |
10353 | } | |
10354 | ||
10355 | /* Implement the "break-range" CLI command. */ | |
10356 | ||
10357 | static void | |
10358 | break_range_command (char *arg, int from_tty) | |
10359 | { | |
10360 | char *arg_start, *addr_string_start, *addr_string_end; | |
10361 | struct linespec_result canonical_start, canonical_end; | |
10362 | int bp_count, can_use_bp, length; | |
10363 | CORE_ADDR end; | |
10364 | struct breakpoint *b; | |
10365 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10366 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10367 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10368 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10369 | |
10370 | /* We don't support software ranged breakpoints. */ | |
10371 | if (target_ranged_break_num_registers () < 0) | |
10372 | error (_("This target does not support hardware ranged breakpoints.")); | |
10373 | ||
10374 | bp_count = hw_breakpoint_used_count (); | |
10375 | bp_count += target_ranged_break_num_registers (); | |
10376 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10377 | bp_count, 0); | |
10378 | if (can_use_bp < 0) | |
10379 | error (_("Hardware breakpoints used exceeds limit.")); | |
10380 | ||
f8eba3c6 | 10381 | arg = skip_spaces (arg); |
f1310107 TJB |
10382 | if (arg == NULL || arg[0] == '\0') |
10383 | error(_("No address range specified.")); | |
10384 | ||
f1310107 TJB |
10385 | init_linespec_result (&canonical_start); |
10386 | ||
f8eba3c6 | 10387 | arg_start = arg; |
f00aae0f KS |
10388 | start_location = string_to_event_location (&arg, current_language); |
10389 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10390 | parse_breakpoint_sals (start_location, &canonical_start); | |
10391 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10392 | |
10393 | if (arg[0] != ',') | |
10394 | error (_("Too few arguments.")); | |
f8eba3c6 | 10395 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10396 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10397 | |
10398 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10399 | ||
10400 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10401 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10402 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10403 | ||
f8eba3c6 TT |
10404 | sal_start = lsal_start->sals.sals[0]; |
10405 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10406 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10407 | |
10408 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10409 | arg = skip_spaces (arg); |
f1310107 TJB |
10410 | |
10411 | /* Parse the end location. */ | |
10412 | ||
f1310107 TJB |
10413 | init_linespec_result (&canonical_end); |
10414 | arg_start = arg; | |
10415 | ||
f8eba3c6 | 10416 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10417 | parse_breakpoint_sals because we need to specify the start location's |
10418 | symtab and line as the default symtab and line for the end of the | |
10419 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10420 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10421 | end_location = string_to_event_location (&arg, current_language); |
10422 | make_cleanup_delete_event_location (end_location); | |
10423 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, | |
f8eba3c6 TT |
10424 | sal_start.symtab, sal_start.line, |
10425 | &canonical_end, NULL, NULL); | |
10426 | ||
10427 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10428 | |
f8eba3c6 | 10429 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10430 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10431 | |
10432 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10433 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10434 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10435 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10436 | ||
f8eba3c6 | 10437 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10438 | |
10439 | end = find_breakpoint_range_end (sal_end); | |
10440 | if (sal_start.pc > end) | |
177b42fe | 10441 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10442 | |
10443 | length = end - sal_start.pc + 1; | |
10444 | if (length < 0) | |
10445 | /* Length overflowed. */ | |
10446 | error (_("Address range too large.")); | |
10447 | else if (length == 1) | |
10448 | { | |
10449 | /* This range is simple enough to be handled by | |
10450 | the `hbreak' command. */ | |
10451 | hbreak_command (addr_string_start, 1); | |
10452 | ||
10453 | do_cleanups (cleanup_bkpt); | |
10454 | ||
10455 | return; | |
10456 | } | |
10457 | ||
10458 | /* Now set up the breakpoint. */ | |
10459 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10460 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10461 | set_breakpoint_count (breakpoint_count + 1); |
10462 | b->number = breakpoint_count; | |
10463 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10464 | b->location = copy_event_location (start_location); |
10465 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10466 | b->loc->length = length; |
10467 | ||
f8eba3c6 | 10468 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10469 | |
10470 | mention (b); | |
8d3788bd | 10471 | observer_notify_breakpoint_created (b); |
44702360 | 10472 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10473 | } |
10474 | ||
4a64f543 MS |
10475 | /* Return non-zero if EXP is verified as constant. Returned zero |
10476 | means EXP is variable. Also the constant detection may fail for | |
10477 | some constant expressions and in such case still falsely return | |
10478 | zero. */ | |
2e6e3d9c | 10479 | |
65d79d4b SDJ |
10480 | static int |
10481 | watchpoint_exp_is_const (const struct expression *exp) | |
10482 | { | |
10483 | int i = exp->nelts; | |
10484 | ||
10485 | while (i > 0) | |
10486 | { | |
10487 | int oplenp, argsp; | |
10488 | ||
10489 | /* We are only interested in the descriptor of each element. */ | |
10490 | operator_length (exp, i, &oplenp, &argsp); | |
10491 | i -= oplenp; | |
10492 | ||
10493 | switch (exp->elts[i].opcode) | |
10494 | { | |
10495 | case BINOP_ADD: | |
10496 | case BINOP_SUB: | |
10497 | case BINOP_MUL: | |
10498 | case BINOP_DIV: | |
10499 | case BINOP_REM: | |
10500 | case BINOP_MOD: | |
10501 | case BINOP_LSH: | |
10502 | case BINOP_RSH: | |
10503 | case BINOP_LOGICAL_AND: | |
10504 | case BINOP_LOGICAL_OR: | |
10505 | case BINOP_BITWISE_AND: | |
10506 | case BINOP_BITWISE_IOR: | |
10507 | case BINOP_BITWISE_XOR: | |
10508 | case BINOP_EQUAL: | |
10509 | case BINOP_NOTEQUAL: | |
10510 | case BINOP_LESS: | |
10511 | case BINOP_GTR: | |
10512 | case BINOP_LEQ: | |
10513 | case BINOP_GEQ: | |
10514 | case BINOP_REPEAT: | |
10515 | case BINOP_COMMA: | |
10516 | case BINOP_EXP: | |
10517 | case BINOP_MIN: | |
10518 | case BINOP_MAX: | |
10519 | case BINOP_INTDIV: | |
10520 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10521 | case TERNOP_COND: |
10522 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10523 | |
10524 | case OP_LONG: | |
10525 | case OP_DOUBLE: | |
10526 | case OP_DECFLOAT: | |
10527 | case OP_LAST: | |
10528 | case OP_COMPLEX: | |
10529 | case OP_STRING: | |
65d79d4b SDJ |
10530 | case OP_ARRAY: |
10531 | case OP_TYPE: | |
608b4967 TT |
10532 | case OP_TYPEOF: |
10533 | case OP_DECLTYPE: | |
6e72ca20 | 10534 | case OP_TYPEID: |
65d79d4b SDJ |
10535 | case OP_NAME: |
10536 | case OP_OBJC_NSSTRING: | |
10537 | ||
10538 | case UNOP_NEG: | |
10539 | case UNOP_LOGICAL_NOT: | |
10540 | case UNOP_COMPLEMENT: | |
10541 | case UNOP_ADDR: | |
10542 | case UNOP_HIGH: | |
aeaa2474 | 10543 | case UNOP_CAST: |
9eaf6705 TT |
10544 | |
10545 | case UNOP_CAST_TYPE: | |
10546 | case UNOP_REINTERPRET_CAST: | |
10547 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10548 | /* Unary, binary and ternary operators: We have to check |
10549 | their operands. If they are constant, then so is the | |
10550 | result of that operation. For instance, if A and B are | |
10551 | determined to be constants, then so is "A + B". | |
10552 | ||
10553 | UNOP_IND is one exception to the rule above, because the | |
10554 | value of *ADDR is not necessarily a constant, even when | |
10555 | ADDR is. */ | |
65d79d4b SDJ |
10556 | break; |
10557 | ||
10558 | case OP_VAR_VALUE: | |
10559 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10560 | |
65d79d4b | 10561 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10562 | possible that a buggy compiler could mark a variable as |
10563 | constant even when it is not, and TYPE_CONST would return | |
10564 | true in this case, while SYMBOL_CLASS wouldn't. | |
10565 | ||
10566 | We also have to check for function symbols because they | |
10567 | are always constant. */ | |
65d79d4b SDJ |
10568 | { |
10569 | struct symbol *s = exp->elts[i + 2].symbol; | |
10570 | ||
10571 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10572 | && SYMBOL_CLASS (s) != LOC_CONST | |
10573 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10574 | return 0; | |
10575 | break; | |
10576 | } | |
10577 | ||
10578 | /* The default action is to return 0 because we are using | |
10579 | the optimistic approach here: If we don't know something, | |
10580 | then it is not a constant. */ | |
10581 | default: | |
10582 | return 0; | |
10583 | } | |
10584 | } | |
10585 | ||
10586 | return 1; | |
10587 | } | |
10588 | ||
3a5c3e22 PA |
10589 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10590 | ||
10591 | static void | |
10592 | dtor_watchpoint (struct breakpoint *self) | |
10593 | { | |
10594 | struct watchpoint *w = (struct watchpoint *) self; | |
10595 | ||
10596 | xfree (w->cond_exp); | |
10597 | xfree (w->exp); | |
10598 | xfree (w->exp_string); | |
10599 | xfree (w->exp_string_reparse); | |
10600 | value_free (w->val); | |
10601 | ||
10602 | base_breakpoint_ops.dtor (self); | |
10603 | } | |
10604 | ||
348d480f PA |
10605 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10606 | ||
10607 | static void | |
10608 | re_set_watchpoint (struct breakpoint *b) | |
10609 | { | |
3a5c3e22 PA |
10610 | struct watchpoint *w = (struct watchpoint *) b; |
10611 | ||
348d480f PA |
10612 | /* Watchpoint can be either on expression using entirely global |
10613 | variables, or it can be on local variables. | |
10614 | ||
10615 | Watchpoints of the first kind are never auto-deleted, and even | |
10616 | persist across program restarts. Since they can use variables | |
10617 | from shared libraries, we need to reparse expression as libraries | |
10618 | are loaded and unloaded. | |
10619 | ||
10620 | Watchpoints on local variables can also change meaning as result | |
10621 | of solib event. For example, if a watchpoint uses both a local | |
10622 | and a global variables in expression, it's a local watchpoint, | |
10623 | but unloading of a shared library will make the expression | |
10624 | invalid. This is not a very common use case, but we still | |
10625 | re-evaluate expression, to avoid surprises to the user. | |
10626 | ||
10627 | Note that for local watchpoints, we re-evaluate it only if | |
10628 | watchpoints frame id is still valid. If it's not, it means the | |
10629 | watchpoint is out of scope and will be deleted soon. In fact, | |
10630 | I'm not sure we'll ever be called in this case. | |
10631 | ||
10632 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10633 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10634 | |
3a5c3e22 PA |
10635 | Don't do anything about disabled watchpoints, since they will be |
10636 | reevaluated again when enabled. */ | |
10637 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10638 | } |
10639 | ||
77b06cd7 TJB |
10640 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10641 | ||
10642 | static int | |
10643 | insert_watchpoint (struct bp_location *bl) | |
10644 | { | |
3a5c3e22 PA |
10645 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10646 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10647 | |
10648 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10649 | w->cond_exp); |
77b06cd7 TJB |
10650 | } |
10651 | ||
10652 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10653 | ||
10654 | static int | |
10655 | remove_watchpoint (struct bp_location *bl) | |
10656 | { | |
3a5c3e22 PA |
10657 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10658 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10659 | |
10660 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10661 | w->cond_exp); |
e09342b5 TJB |
10662 | } |
10663 | ||
e09342b5 | 10664 | static int |
348d480f | 10665 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10666 | struct address_space *aspace, CORE_ADDR bp_addr, |
10667 | const struct target_waitstatus *ws) | |
e09342b5 | 10668 | { |
348d480f | 10669 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10670 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10671 | |
348d480f PA |
10672 | /* Continuable hardware watchpoints are treated as non-existent if the |
10673 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10674 | some data address). Otherwise gdb won't stop on a break instruction | |
10675 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10676 | been defined. Also skip watchpoints which we know did not trigger | |
10677 | (did not match the data address). */ | |
10678 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10679 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10680 | return 0; |
9c06b0b4 | 10681 | |
348d480f | 10682 | return 1; |
9c06b0b4 TJB |
10683 | } |
10684 | ||
348d480f PA |
10685 | static void |
10686 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10687 | { |
348d480f | 10688 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10689 | |
348d480f | 10690 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10691 | } |
10692 | ||
10693 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10694 | hardware watchpoints. */ |
9c06b0b4 TJB |
10695 | |
10696 | static int | |
348d480f | 10697 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10698 | { |
3a5c3e22 PA |
10699 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10700 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10701 | |
10702 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10703 | } |
10704 | ||
10705 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10706 | hardware watchpoints. */ |
9c06b0b4 TJB |
10707 | |
10708 | static int | |
348d480f | 10709 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10710 | { |
efa80663 PA |
10711 | /* Read and access watchpoints only work with hardware support. */ |
10712 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10713 | } |
10714 | ||
9c06b0b4 | 10715 | static enum print_stop_action |
348d480f | 10716 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10717 | { |
348d480f PA |
10718 | struct cleanup *old_chain; |
10719 | struct breakpoint *b; | |
f99d8bf4 | 10720 | struct ui_file *stb; |
348d480f | 10721 | enum print_stop_action result; |
3a5c3e22 | 10722 | struct watchpoint *w; |
79a45e25 | 10723 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10724 | |
10725 | gdb_assert (bs->bp_location_at != NULL); | |
10726 | ||
348d480f | 10727 | b = bs->breakpoint_at; |
3a5c3e22 | 10728 | w = (struct watchpoint *) b; |
348d480f | 10729 | |
f99d8bf4 PA |
10730 | stb = mem_fileopen (); |
10731 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10732 | |
10733 | switch (b->type) | |
10734 | { | |
348d480f | 10735 | case bp_watchpoint: |
9c06b0b4 TJB |
10736 | case bp_hardware_watchpoint: |
10737 | annotate_watchpoint (b->number); | |
10738 | if (ui_out_is_mi_like_p (uiout)) | |
10739 | ui_out_field_string | |
10740 | (uiout, "reason", | |
10741 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10742 | mention (b); |
10743 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10744 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10745 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10746 | ui_out_field_stream (uiout, "old", stb); |
10747 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10748 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10749 | ui_out_field_stream (uiout, "new", stb); |
10750 | ui_out_text (uiout, "\n"); | |
10751 | /* More than one watchpoint may have been triggered. */ | |
10752 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10753 | break; |
10754 | ||
10755 | case bp_read_watchpoint: | |
10756 | if (ui_out_is_mi_like_p (uiout)) | |
10757 | ui_out_field_string | |
10758 | (uiout, "reason", | |
10759 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10760 | mention (b); |
10761 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10762 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10763 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10764 | ui_out_field_stream (uiout, "value", stb); |
10765 | ui_out_text (uiout, "\n"); | |
10766 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10767 | break; |
10768 | ||
10769 | case bp_access_watchpoint: | |
348d480f PA |
10770 | if (bs->old_val != NULL) |
10771 | { | |
10772 | annotate_watchpoint (b->number); | |
10773 | if (ui_out_is_mi_like_p (uiout)) | |
10774 | ui_out_field_string | |
10775 | (uiout, "reason", | |
10776 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10777 | mention (b); | |
10778 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10779 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10780 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10781 | ui_out_field_stream (uiout, "old", stb); |
10782 | ui_out_text (uiout, "\nNew value = "); | |
10783 | } | |
10784 | else | |
10785 | { | |
10786 | mention (b); | |
10787 | if (ui_out_is_mi_like_p (uiout)) | |
10788 | ui_out_field_string | |
10789 | (uiout, "reason", | |
10790 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10791 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10792 | ui_out_text (uiout, "\nValue = "); | |
10793 | } | |
f99d8bf4 | 10794 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10795 | ui_out_field_stream (uiout, "new", stb); |
10796 | ui_out_text (uiout, "\n"); | |
10797 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10798 | break; |
10799 | default: | |
348d480f | 10800 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10801 | } |
10802 | ||
348d480f PA |
10803 | do_cleanups (old_chain); |
10804 | return result; | |
10805 | } | |
10806 | ||
10807 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10808 | watchpoints. */ | |
10809 | ||
10810 | static void | |
10811 | print_mention_watchpoint (struct breakpoint *b) | |
10812 | { | |
10813 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10814 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10815 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10816 | |
10817 | switch (b->type) | |
10818 | { | |
10819 | case bp_watchpoint: | |
10820 | ui_out_text (uiout, "Watchpoint "); | |
10821 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10822 | break; | |
10823 | case bp_hardware_watchpoint: | |
10824 | ui_out_text (uiout, "Hardware watchpoint "); | |
10825 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10826 | break; | |
10827 | case bp_read_watchpoint: | |
10828 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10829 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10830 | break; | |
10831 | case bp_access_watchpoint: | |
10832 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10833 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10834 | break; | |
10835 | default: | |
10836 | internal_error (__FILE__, __LINE__, | |
10837 | _("Invalid hardware watchpoint type.")); | |
10838 | } | |
10839 | ||
10840 | ui_out_field_int (uiout, "number", b->number); | |
10841 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10842 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10843 | do_cleanups (ui_out_chain); |
10844 | } | |
10845 | ||
10846 | /* Implement the "print_recreate" breakpoint_ops method for | |
10847 | watchpoints. */ | |
10848 | ||
10849 | static void | |
10850 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10851 | { | |
3a5c3e22 PA |
10852 | struct watchpoint *w = (struct watchpoint *) b; |
10853 | ||
348d480f PA |
10854 | switch (b->type) |
10855 | { | |
10856 | case bp_watchpoint: | |
10857 | case bp_hardware_watchpoint: | |
10858 | fprintf_unfiltered (fp, "watch"); | |
10859 | break; | |
10860 | case bp_read_watchpoint: | |
10861 | fprintf_unfiltered (fp, "rwatch"); | |
10862 | break; | |
10863 | case bp_access_watchpoint: | |
10864 | fprintf_unfiltered (fp, "awatch"); | |
10865 | break; | |
10866 | default: | |
10867 | internal_error (__FILE__, __LINE__, | |
10868 | _("Invalid watchpoint type.")); | |
10869 | } | |
10870 | ||
3a5c3e22 | 10871 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10872 | print_recreate_thread (b, fp); |
348d480f PA |
10873 | } |
10874 | ||
427cd150 TT |
10875 | /* Implement the "explains_signal" breakpoint_ops method for |
10876 | watchpoints. */ | |
10877 | ||
47591c29 | 10878 | static int |
427cd150 TT |
10879 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10880 | { | |
10881 | /* A software watchpoint cannot cause a signal other than | |
10882 | GDB_SIGNAL_TRAP. */ | |
10883 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10884 | return 0; |
427cd150 | 10885 | |
47591c29 | 10886 | return 1; |
427cd150 TT |
10887 | } |
10888 | ||
348d480f PA |
10889 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10890 | ||
2060206e | 10891 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10892 | |
10893 | /* Implement the "insert" breakpoint_ops method for | |
10894 | masked hardware watchpoints. */ | |
10895 | ||
10896 | static int | |
10897 | insert_masked_watchpoint (struct bp_location *bl) | |
10898 | { | |
3a5c3e22 PA |
10899 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10900 | ||
10901 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10902 | bl->watchpoint_type); |
10903 | } | |
10904 | ||
10905 | /* Implement the "remove" breakpoint_ops method for | |
10906 | masked hardware watchpoints. */ | |
10907 | ||
10908 | static int | |
10909 | remove_masked_watchpoint (struct bp_location *bl) | |
10910 | { | |
3a5c3e22 PA |
10911 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10912 | ||
10913 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10914 | bl->watchpoint_type); |
10915 | } | |
10916 | ||
10917 | /* Implement the "resources_needed" breakpoint_ops method for | |
10918 | masked hardware watchpoints. */ | |
10919 | ||
10920 | static int | |
10921 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10922 | { | |
3a5c3e22 PA |
10923 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10924 | ||
10925 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10926 | } |
10927 | ||
10928 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10929 | masked hardware watchpoints. */ | |
10930 | ||
10931 | static int | |
10932 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10933 | { | |
10934 | return 0; | |
10935 | } | |
10936 | ||
10937 | /* Implement the "print_it" breakpoint_ops method for | |
10938 | masked hardware watchpoints. */ | |
10939 | ||
10940 | static enum print_stop_action | |
10941 | print_it_masked_watchpoint (bpstat bs) | |
10942 | { | |
10943 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10944 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10945 | |
10946 | /* Masked watchpoints have only one location. */ | |
10947 | gdb_assert (b->loc && b->loc->next == NULL); | |
10948 | ||
10949 | switch (b->type) | |
10950 | { | |
10951 | case bp_hardware_watchpoint: | |
10952 | annotate_watchpoint (b->number); | |
10953 | if (ui_out_is_mi_like_p (uiout)) | |
10954 | ui_out_field_string | |
10955 | (uiout, "reason", | |
10956 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10957 | break; | |
10958 | ||
10959 | case bp_read_watchpoint: | |
10960 | if (ui_out_is_mi_like_p (uiout)) | |
10961 | ui_out_field_string | |
10962 | (uiout, "reason", | |
10963 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10964 | break; | |
10965 | ||
10966 | case bp_access_watchpoint: | |
10967 | if (ui_out_is_mi_like_p (uiout)) | |
10968 | ui_out_field_string | |
10969 | (uiout, "reason", | |
10970 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10971 | break; | |
10972 | default: | |
10973 | internal_error (__FILE__, __LINE__, | |
10974 | _("Invalid hardware watchpoint type.")); | |
10975 | } | |
10976 | ||
10977 | mention (b); | |
9c06b0b4 TJB |
10978 | ui_out_text (uiout, _("\n\ |
10979 | Check the underlying instruction at PC for the memory\n\ | |
10980 | address and value which triggered this watchpoint.\n")); | |
10981 | ui_out_text (uiout, "\n"); | |
10982 | ||
10983 | /* More than one watchpoint may have been triggered. */ | |
10984 | return PRINT_UNKNOWN; | |
10985 | } | |
10986 | ||
10987 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10988 | masked hardware watchpoints. */ | |
10989 | ||
10990 | static void | |
10991 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10992 | struct ui_out *uiout) | |
10993 | { | |
3a5c3e22 PA |
10994 | struct watchpoint *w = (struct watchpoint *) b; |
10995 | ||
9c06b0b4 TJB |
10996 | /* Masked watchpoints have only one location. */ |
10997 | gdb_assert (b->loc && b->loc->next == NULL); | |
10998 | ||
10999 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11000 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11001 | ui_out_text (uiout, "\n"); |
11002 | } | |
11003 | ||
11004 | /* Implement the "print_mention" breakpoint_ops method for | |
11005 | masked hardware watchpoints. */ | |
11006 | ||
11007 | static void | |
11008 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11009 | { | |
3a5c3e22 | 11010 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11011 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11012 | struct cleanup *ui_out_chain; |
11013 | ||
11014 | switch (b->type) | |
11015 | { | |
11016 | case bp_hardware_watchpoint: | |
11017 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11018 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11019 | break; | |
11020 | case bp_read_watchpoint: | |
11021 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11022 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11023 | break; | |
11024 | case bp_access_watchpoint: | |
11025 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11026 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11027 | break; | |
11028 | default: | |
11029 | internal_error (__FILE__, __LINE__, | |
11030 | _("Invalid hardware watchpoint type.")); | |
11031 | } | |
11032 | ||
11033 | ui_out_field_int (uiout, "number", b->number); | |
11034 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11035 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11036 | do_cleanups (ui_out_chain); |
11037 | } | |
11038 | ||
11039 | /* Implement the "print_recreate" breakpoint_ops method for | |
11040 | masked hardware watchpoints. */ | |
11041 | ||
11042 | static void | |
11043 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11044 | { | |
3a5c3e22 | 11045 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11046 | char tmp[40]; |
11047 | ||
11048 | switch (b->type) | |
11049 | { | |
11050 | case bp_hardware_watchpoint: | |
11051 | fprintf_unfiltered (fp, "watch"); | |
11052 | break; | |
11053 | case bp_read_watchpoint: | |
11054 | fprintf_unfiltered (fp, "rwatch"); | |
11055 | break; | |
11056 | case bp_access_watchpoint: | |
11057 | fprintf_unfiltered (fp, "awatch"); | |
11058 | break; | |
11059 | default: | |
11060 | internal_error (__FILE__, __LINE__, | |
11061 | _("Invalid hardware watchpoint type.")); | |
11062 | } | |
11063 | ||
3a5c3e22 PA |
11064 | sprintf_vma (tmp, w->hw_wp_mask); |
11065 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11066 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11067 | } |
11068 | ||
11069 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11070 | ||
2060206e | 11071 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11072 | |
11073 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11074 | ||
11075 | static int | |
11076 | is_masked_watchpoint (const struct breakpoint *b) | |
11077 | { | |
11078 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11079 | } | |
11080 | ||
53a5351d JM |
11081 | /* accessflag: hw_write: watch write, |
11082 | hw_read: watch read, | |
11083 | hw_access: watch access (read or write) */ | |
c906108c | 11084 | static void |
bbc13ae3 | 11085 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11086 | int just_location, int internal) |
c906108c | 11087 | { |
d983da9c | 11088 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11089 | struct expression *exp; |
270140bd | 11090 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11091 | struct value *val, *mark, *result; |
bb9d5f81 | 11092 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11093 | struct frame_info *frame; |
bbc13ae3 KS |
11094 | const char *exp_start = NULL; |
11095 | const char *exp_end = NULL; | |
11096 | const char *tok, *end_tok; | |
9c06b0b4 | 11097 | int toklen = -1; |
bbc13ae3 KS |
11098 | const char *cond_start = NULL; |
11099 | const char *cond_end = NULL; | |
c906108c | 11100 | enum bptype bp_type; |
37e4754d | 11101 | int thread = -1; |
0cf6dd15 | 11102 | int pc = 0; |
9c06b0b4 TJB |
11103 | /* Flag to indicate whether we are going to use masks for |
11104 | the hardware watchpoint. */ | |
11105 | int use_mask = 0; | |
11106 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11107 | struct watchpoint *w; |
bbc13ae3 KS |
11108 | char *expression; |
11109 | struct cleanup *back_to; | |
c906108c | 11110 | |
37e4754d LM |
11111 | /* Make sure that we actually have parameters to parse. */ |
11112 | if (arg != NULL && arg[0] != '\0') | |
11113 | { | |
bbc13ae3 KS |
11114 | const char *value_start; |
11115 | ||
11116 | exp_end = arg + strlen (arg); | |
37e4754d | 11117 | |
9c06b0b4 TJB |
11118 | /* Look for "parameter value" pairs at the end |
11119 | of the arguments string. */ | |
bbc13ae3 | 11120 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11121 | { |
11122 | /* Skip whitespace at the end of the argument list. */ | |
11123 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11124 | tok--; | |
11125 | ||
11126 | /* Find the beginning of the last token. | |
11127 | This is the value of the parameter. */ | |
11128 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11129 | tok--; | |
11130 | value_start = tok + 1; | |
11131 | ||
11132 | /* Skip whitespace. */ | |
11133 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11134 | tok--; | |
11135 | ||
11136 | end_tok = tok; | |
11137 | ||
11138 | /* Find the beginning of the second to last token. | |
11139 | This is the parameter itself. */ | |
11140 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11141 | tok--; | |
11142 | tok++; | |
11143 | toklen = end_tok - tok + 1; | |
11144 | ||
61012eef | 11145 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 TJB |
11146 | { |
11147 | /* At this point we've found a "thread" token, which means | |
11148 | the user is trying to set a watchpoint that triggers | |
11149 | only in a specific thread. */ | |
11150 | char *endp; | |
37e4754d | 11151 | |
9c06b0b4 TJB |
11152 | if (thread != -1) |
11153 | error(_("You can specify only one thread.")); | |
37e4754d | 11154 | |
9c06b0b4 TJB |
11155 | /* Extract the thread ID from the next token. */ |
11156 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11157 | |
9c06b0b4 TJB |
11158 | /* Check if the user provided a valid numeric value for the |
11159 | thread ID. */ | |
11160 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11161 | error (_("Invalid thread ID specification %s."), value_start); | |
11162 | ||
11163 | /* Check if the thread actually exists. */ | |
11164 | if (!valid_thread_id (thread)) | |
af4908ba | 11165 | invalid_thread_id_error (thread); |
9c06b0b4 | 11166 | } |
61012eef | 11167 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11168 | { |
11169 | /* We've found a "mask" token, which means the user wants to | |
11170 | create a hardware watchpoint that is going to have the mask | |
11171 | facility. */ | |
11172 | struct value *mask_value, *mark; | |
37e4754d | 11173 | |
9c06b0b4 TJB |
11174 | if (use_mask) |
11175 | error(_("You can specify only one mask.")); | |
37e4754d | 11176 | |
9c06b0b4 | 11177 | use_mask = just_location = 1; |
37e4754d | 11178 | |
9c06b0b4 TJB |
11179 | mark = value_mark (); |
11180 | mask_value = parse_to_comma_and_eval (&value_start); | |
11181 | mask = value_as_address (mask_value); | |
11182 | value_free_to_mark (mark); | |
11183 | } | |
11184 | else | |
11185 | /* We didn't recognize what we found. We should stop here. */ | |
11186 | break; | |
37e4754d | 11187 | |
9c06b0b4 TJB |
11188 | /* Truncate the string and get rid of the "parameter value" pair before |
11189 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11190 | exp_end = tok; |
9c06b0b4 | 11191 | } |
37e4754d | 11192 | } |
bbc13ae3 KS |
11193 | else |
11194 | exp_end = arg; | |
37e4754d | 11195 | |
bbc13ae3 KS |
11196 | /* Parse the rest of the arguments. From here on out, everything |
11197 | is in terms of a newly allocated string instead of the original | |
11198 | ARG. */ | |
c906108c | 11199 | innermost_block = NULL; |
bbc13ae3 KS |
11200 | expression = savestring (arg, exp_end - arg); |
11201 | back_to = make_cleanup (xfree, expression); | |
11202 | exp_start = arg = expression; | |
1bb9788d | 11203 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11204 | exp_end = arg; |
fa8a61dc TT |
11205 | /* Remove trailing whitespace from the expression before saving it. |
11206 | This makes the eventual display of the expression string a bit | |
11207 | prettier. */ | |
11208 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11209 | --exp_end; | |
11210 | ||
65d79d4b SDJ |
11211 | /* Checking if the expression is not constant. */ |
11212 | if (watchpoint_exp_is_const (exp)) | |
11213 | { | |
11214 | int len; | |
11215 | ||
11216 | len = exp_end - exp_start; | |
11217 | while (len > 0 && isspace (exp_start[len - 1])) | |
11218 | len--; | |
11219 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11220 | } | |
11221 | ||
c906108c SS |
11222 | exp_valid_block = innermost_block; |
11223 | mark = value_mark (); | |
3a1115a0 | 11224 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11225 | |
bb9d5f81 PP |
11226 | if (val != NULL && just_location) |
11227 | { | |
11228 | saved_bitpos = value_bitpos (val); | |
11229 | saved_bitsize = value_bitsize (val); | |
11230 | } | |
11231 | ||
06a64a0b TT |
11232 | if (just_location) |
11233 | { | |
9c06b0b4 TJB |
11234 | int ret; |
11235 | ||
06a64a0b | 11236 | exp_valid_block = NULL; |
a1442452 | 11237 | val = value_addr (result); |
06a64a0b TT |
11238 | release_value (val); |
11239 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11240 | |
11241 | if (use_mask) | |
11242 | { | |
11243 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11244 | mask); | |
11245 | if (ret == -1) | |
11246 | error (_("This target does not support masked watchpoints.")); | |
11247 | else if (ret == -2) | |
11248 | error (_("Invalid mask or memory region.")); | |
11249 | } | |
06a64a0b TT |
11250 | } |
11251 | else if (val != NULL) | |
fa4727a6 | 11252 | release_value (val); |
c906108c | 11253 | |
bbc13ae3 KS |
11254 | tok = skip_spaces_const (arg); |
11255 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11256 | |
11257 | toklen = end_tok - tok; | |
11258 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11259 | { | |
2d134ed3 PA |
11260 | struct expression *cond; |
11261 | ||
60e1c644 | 11262 | innermost_block = NULL; |
c906108c | 11263 | tok = cond_start = end_tok + 1; |
1bb9788d | 11264 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11265 | |
11266 | /* The watchpoint expression may not be local, but the condition | |
11267 | may still be. E.g.: `watch global if local > 0'. */ | |
11268 | cond_exp_valid_block = innermost_block; | |
11269 | ||
2d134ed3 | 11270 | xfree (cond); |
c906108c SS |
11271 | cond_end = tok; |
11272 | } | |
11273 | if (*tok) | |
8a3fe4f8 | 11274 | error (_("Junk at end of command.")); |
c906108c | 11275 | |
d983da9c | 11276 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11277 | |
11278 | /* If the expression is "local", then set up a "watchpoint scope" | |
11279 | breakpoint at the point where we've left the scope of the watchpoint | |
11280 | expression. Create the scope breakpoint before the watchpoint, so | |
11281 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11282 | if (exp_valid_block && frame) |
d983da9c | 11283 | { |
edb3359d DJ |
11284 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11285 | { | |
11286 | scope_breakpoint | |
a6d9a66e UW |
11287 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11288 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11289 | bp_watchpoint_scope, |
11290 | &momentary_breakpoint_ops); | |
d983da9c | 11291 | |
edb3359d | 11292 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11293 | |
edb3359d DJ |
11294 | /* Automatically delete the breakpoint when it hits. */ |
11295 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11296 | |
edb3359d DJ |
11297 | /* Only break in the proper frame (help with recursion). */ |
11298 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11299 | |
edb3359d | 11300 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11301 | scope_breakpoint->loc->gdbarch |
11302 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11303 | scope_breakpoint->loc->requested_address |
11304 | = frame_unwind_caller_pc (frame); | |
11305 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11306 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11307 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11308 | scope_breakpoint->type); |
11309 | } | |
d983da9c DJ |
11310 | } |
11311 | ||
e8369a73 AB |
11312 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11313 | watchpoints here even if hardware watchpoints are turned off, a call | |
11314 | to update_watchpoint later in this function will cause the type to | |
11315 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11316 | ||
11317 | if (accessflag == hw_read) | |
11318 | bp_type = bp_read_watchpoint; | |
11319 | else if (accessflag == hw_access) | |
11320 | bp_type = bp_access_watchpoint; | |
11321 | else | |
11322 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11323 | |
11324 | w = XCNEW (struct watchpoint); | |
11325 | b = &w->base; | |
348d480f | 11326 | if (use_mask) |
3a5c3e22 PA |
11327 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11328 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11329 | else |
3a5c3e22 PA |
11330 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11331 | &watchpoint_breakpoint_ops); | |
37e4754d | 11332 | b->thread = thread; |
b5de0fa7 | 11333 | b->disposition = disp_donttouch; |
348d480f | 11334 | b->pspace = current_program_space; |
3a5c3e22 PA |
11335 | w->exp = exp; |
11336 | w->exp_valid_block = exp_valid_block; | |
11337 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11338 | if (just_location) |
11339 | { | |
11340 | struct type *t = value_type (val); | |
11341 | CORE_ADDR addr = value_as_address (val); | |
11342 | char *name; | |
11343 | ||
11344 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11345 | name = type_to_string (t); | |
11346 | ||
3a5c3e22 | 11347 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11348 | core_addr_to_string (addr)); |
06a64a0b TT |
11349 | xfree (name); |
11350 | ||
3a5c3e22 | 11351 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11352 | (int) (exp_end - exp_start), exp_start); |
11353 | ||
06a64a0b TT |
11354 | /* The above expression is in C. */ |
11355 | b->language = language_c; | |
11356 | } | |
11357 | else | |
3a5c3e22 | 11358 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11359 | |
11360 | if (use_mask) | |
11361 | { | |
3a5c3e22 | 11362 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11363 | } |
11364 | else | |
11365 | { | |
3a5c3e22 | 11366 | w->val = val; |
bb9d5f81 PP |
11367 | w->val_bitpos = saved_bitpos; |
11368 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11369 | w->val_valid = 1; |
9c06b0b4 | 11370 | } |
77b06cd7 | 11371 | |
c906108c SS |
11372 | if (cond_start) |
11373 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11374 | else | |
11375 | b->cond_string = 0; | |
c5aa993b | 11376 | |
c906108c | 11377 | if (frame) |
f6bc2008 | 11378 | { |
3a5c3e22 PA |
11379 | w->watchpoint_frame = get_frame_id (frame); |
11380 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11381 | } |
c906108c | 11382 | else |
f6bc2008 | 11383 | { |
3a5c3e22 PA |
11384 | w->watchpoint_frame = null_frame_id; |
11385 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11386 | } |
c906108c | 11387 | |
d983da9c | 11388 | if (scope_breakpoint != NULL) |
c906108c | 11389 | { |
d983da9c DJ |
11390 | /* The scope breakpoint is related to the watchpoint. We will |
11391 | need to act on them together. */ | |
11392 | b->related_breakpoint = scope_breakpoint; | |
11393 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11394 | } |
d983da9c | 11395 | |
06a64a0b TT |
11396 | if (!just_location) |
11397 | value_free_to_mark (mark); | |
2d134ed3 | 11398 | |
492d29ea | 11399 | TRY |
a9634178 TJB |
11400 | { |
11401 | /* Finally update the new watchpoint. This creates the locations | |
11402 | that should be inserted. */ | |
3a5c3e22 | 11403 | update_watchpoint (w, 1); |
a9634178 | 11404 | } |
492d29ea | 11405 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11406 | { |
11407 | delete_breakpoint (b); | |
11408 | throw_exception (e); | |
11409 | } | |
492d29ea | 11410 | END_CATCH |
a9634178 | 11411 | |
3ea46bff | 11412 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11413 | do_cleanups (back_to); |
c906108c SS |
11414 | } |
11415 | ||
e09342b5 | 11416 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11417 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11418 | |
c906108c | 11419 | static int |
a9634178 | 11420 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11421 | { |
11422 | int found_memory_cnt = 0; | |
2e70b7b9 | 11423 | struct value *head = v; |
c906108c SS |
11424 | |
11425 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11426 | if (!can_use_hw_watchpoints) |
c906108c | 11427 | return 0; |
c5aa993b | 11428 | |
5c44784c JM |
11429 | /* Make sure that the value of the expression depends only upon |
11430 | memory contents, and values computed from them within GDB. If we | |
11431 | find any register references or function calls, we can't use a | |
11432 | hardware watchpoint. | |
11433 | ||
11434 | The idea here is that evaluating an expression generates a series | |
11435 | of values, one holding the value of every subexpression. (The | |
11436 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11437 | a*b+c.) GDB's values hold almost enough information to establish | |
11438 | the criteria given above --- they identify memory lvalues, | |
11439 | register lvalues, computed values, etcetera. So we can evaluate | |
11440 | the expression, and then scan the chain of values that leaves | |
11441 | behind to decide whether we can detect any possible change to the | |
11442 | expression's final value using only hardware watchpoints. | |
11443 | ||
11444 | However, I don't think that the values returned by inferior | |
11445 | function calls are special in any way. So this function may not | |
11446 | notice that an expression involving an inferior function call | |
11447 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11448 | for (; v; v = value_next (v)) |
c906108c | 11449 | { |
5c44784c | 11450 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11451 | { |
8464be76 DJ |
11452 | if (v != head && value_lazy (v)) |
11453 | /* A lazy memory lvalue in the chain is one that GDB never | |
11454 | needed to fetch; we either just used its address (e.g., | |
11455 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11456 | in `a,b'). This doesn't apply to HEAD; if that is | |
11457 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11458 | ; |
53a5351d | 11459 | else |
5c44784c JM |
11460 | { |
11461 | /* Ahh, memory we actually used! Check if we can cover | |
11462 | it with hardware watchpoints. */ | |
df407dfe | 11463 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11464 | |
11465 | /* We only watch structs and arrays if user asked for it | |
11466 | explicitly, never if they just happen to appear in a | |
11467 | middle of some value chain. */ | |
11468 | if (v == head | |
11469 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11470 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11471 | { | |
42ae5230 | 11472 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11473 | int len; |
11474 | int num_regs; | |
11475 | ||
a9634178 | 11476 | len = (target_exact_watchpoints |
e09342b5 TJB |
11477 | && is_scalar_type_recursive (vtype))? |
11478 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11479 | |
e09342b5 TJB |
11480 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11481 | if (!num_regs) | |
2e70b7b9 MS |
11482 | return 0; |
11483 | else | |
e09342b5 | 11484 | found_memory_cnt += num_regs; |
2e70b7b9 | 11485 | } |
5c44784c | 11486 | } |
c5aa993b | 11487 | } |
5086187c AC |
11488 | else if (VALUE_LVAL (v) != not_lval |
11489 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11490 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11491 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11492 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11493 | } |
11494 | ||
11495 | /* The expression itself looks suitable for using a hardware | |
11496 | watchpoint, but give the target machine a chance to reject it. */ | |
11497 | return found_memory_cnt; | |
11498 | } | |
11499 | ||
8b93c638 | 11500 | void |
84f4c1fe | 11501 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11502 | { |
84f4c1fe | 11503 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11504 | } |
11505 | ||
06a64a0b TT |
11506 | /* A helper function that looks for the "-location" argument and then |
11507 | calls watch_command_1. */ | |
11508 | ||
11509 | static void | |
11510 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11511 | { | |
11512 | int just_location = 0; | |
11513 | ||
11514 | if (arg | |
11515 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11516 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11517 | { | |
e9cafbcc | 11518 | arg = skip_spaces (arg); |
06a64a0b TT |
11519 | just_location = 1; |
11520 | } | |
11521 | ||
84f4c1fe | 11522 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11523 | } |
8926118c | 11524 | |
c5aa993b | 11525 | static void |
fba45db2 | 11526 | watch_command (char *arg, int from_tty) |
c906108c | 11527 | { |
06a64a0b | 11528 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11529 | } |
11530 | ||
8b93c638 | 11531 | void |
84f4c1fe | 11532 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11533 | { |
84f4c1fe | 11534 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11535 | } |
8926118c | 11536 | |
c5aa993b | 11537 | static void |
fba45db2 | 11538 | rwatch_command (char *arg, int from_tty) |
c906108c | 11539 | { |
06a64a0b | 11540 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11541 | } |
11542 | ||
8b93c638 | 11543 | void |
84f4c1fe | 11544 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11545 | { |
84f4c1fe | 11546 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11547 | } |
8926118c | 11548 | |
c5aa993b | 11549 | static void |
fba45db2 | 11550 | awatch_command (char *arg, int from_tty) |
c906108c | 11551 | { |
06a64a0b | 11552 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11553 | } |
c906108c | 11554 | \f |
c5aa993b | 11555 | |
cfc31633 PA |
11556 | /* Data for the FSM that manages the until(location)/advance commands |
11557 | in infcmd.c. Here because it uses the mechanisms of | |
11558 | breakpoints. */ | |
c906108c | 11559 | |
cfc31633 | 11560 | struct until_break_fsm |
bfec99b2 | 11561 | { |
cfc31633 PA |
11562 | /* The base class. */ |
11563 | struct thread_fsm thread_fsm; | |
11564 | ||
11565 | /* The thread that as current when the command was executed. */ | |
11566 | int thread; | |
11567 | ||
11568 | /* The breakpoint set at the destination location. */ | |
11569 | struct breakpoint *location_breakpoint; | |
11570 | ||
11571 | /* Breakpoint set at the return address in the caller frame. May be | |
11572 | NULL. */ | |
11573 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11574 | }; |
11575 | ||
cfc31633 PA |
11576 | static void until_break_fsm_clean_up (struct thread_fsm *self); |
11577 | static int until_break_fsm_should_stop (struct thread_fsm *self); | |
11578 | static enum async_reply_reason | |
11579 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11580 | ||
11581 | /* until_break_fsm's vtable. */ | |
11582 | ||
11583 | static struct thread_fsm_ops until_break_fsm_ops = | |
11584 | { | |
11585 | NULL, /* dtor */ | |
11586 | until_break_fsm_clean_up, | |
11587 | until_break_fsm_should_stop, | |
11588 | NULL, /* return_value */ | |
11589 | until_break_fsm_async_reply_reason, | |
11590 | }; | |
11591 | ||
11592 | /* Allocate a new until_break_command_fsm. */ | |
11593 | ||
11594 | static struct until_break_fsm * | |
11595 | new_until_break_fsm (int thread, | |
11596 | struct breakpoint *location_breakpoint, | |
11597 | struct breakpoint *caller_breakpoint) | |
11598 | { | |
11599 | struct until_break_fsm *sm; | |
11600 | ||
11601 | sm = XCNEW (struct until_break_fsm); | |
11602 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops); | |
11603 | ||
11604 | sm->thread = thread; | |
11605 | sm->location_breakpoint = location_breakpoint; | |
11606 | sm->caller_breakpoint = caller_breakpoint; | |
11607 | ||
11608 | return sm; | |
11609 | } | |
11610 | ||
11611 | /* Implementation of the 'should_stop' FSM method for the | |
11612 | until(location)/advance commands. */ | |
11613 | ||
11614 | static int | |
11615 | until_break_fsm_should_stop (struct thread_fsm *self) | |
11616 | { | |
11617 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
11618 | struct thread_info *tp = inferior_thread (); | |
11619 | ||
11620 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11621 | sm->location_breakpoint) != NULL | |
11622 | || (sm->caller_breakpoint != NULL | |
11623 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11624 | sm->caller_breakpoint) != NULL)) | |
11625 | thread_fsm_set_finished (self); | |
11626 | ||
11627 | return 1; | |
11628 | } | |
11629 | ||
11630 | /* Implementation of the 'clean_up' FSM method for the | |
11631 | until(location)/advance commands. */ | |
11632 | ||
c2c6d25f | 11633 | static void |
cfc31633 | 11634 | until_break_fsm_clean_up (struct thread_fsm *self) |
43ff13b4 | 11635 | { |
cfc31633 | 11636 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11637 | |
cfc31633 PA |
11638 | /* Clean up our temporary breakpoints. */ |
11639 | if (sm->location_breakpoint != NULL) | |
11640 | { | |
11641 | delete_breakpoint (sm->location_breakpoint); | |
11642 | sm->location_breakpoint = NULL; | |
11643 | } | |
11644 | if (sm->caller_breakpoint != NULL) | |
11645 | { | |
11646 | delete_breakpoint (sm->caller_breakpoint); | |
11647 | sm->caller_breakpoint = NULL; | |
11648 | } | |
11649 | delete_longjmp_breakpoint (sm->thread); | |
11650 | } | |
11651 | ||
11652 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11653 | until(location)/advance commands. */ | |
11654 | ||
11655 | static enum async_reply_reason | |
11656 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11657 | { | |
11658 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11659 | } |
11660 | ||
c906108c | 11661 | void |
ae66c1fc | 11662 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11663 | { |
11664 | struct symtabs_and_lines sals; | |
11665 | struct symtab_and_line sal; | |
8556afb4 PA |
11666 | struct frame_info *frame; |
11667 | struct gdbarch *frame_gdbarch; | |
11668 | struct frame_id stack_frame_id; | |
11669 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11670 | struct breakpoint *location_breakpoint; |
11671 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11672 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11673 | int thread; |
11674 | struct thread_info *tp; | |
f00aae0f | 11675 | struct event_location *location; |
cfc31633 | 11676 | struct until_break_fsm *sm; |
c906108c | 11677 | |
70509625 | 11678 | clear_proceed_status (0); |
c906108c SS |
11679 | |
11680 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11681 | this function. */ |
c5aa993b | 11682 | |
f00aae0f KS |
11683 | location = string_to_event_location (&arg, current_language); |
11684 | cleanup = make_cleanup_delete_event_location (location); | |
11685 | ||
1bfeeb0f | 11686 | if (last_displayed_sal_is_valid ()) |
f00aae0f | 11687 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11688 | get_last_displayed_symtab (), |
f8eba3c6 | 11689 | get_last_displayed_line ()); |
c906108c | 11690 | else |
f00aae0f | 11691 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
f8eba3c6 | 11692 | (struct symtab *) NULL, 0); |
c5aa993b | 11693 | |
c906108c | 11694 | if (sals.nelts != 1) |
8a3fe4f8 | 11695 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11696 | |
c906108c | 11697 | sal = sals.sals[0]; |
4a64f543 | 11698 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11699 | |
c906108c | 11700 | if (*arg) |
8a3fe4f8 | 11701 | error (_("Junk at end of arguments.")); |
c5aa993b | 11702 | |
c906108c | 11703 | resolve_sal_pc (&sal); |
c5aa993b | 11704 | |
186c406b TT |
11705 | tp = inferior_thread (); |
11706 | thread = tp->num; | |
11707 | ||
883bc8d1 PA |
11708 | old_chain = make_cleanup (null_cleanup, NULL); |
11709 | ||
8556afb4 PA |
11710 | /* Note linespec handling above invalidates the frame chain. |
11711 | Installing a breakpoint also invalidates the frame chain (as it | |
11712 | may need to switch threads), so do any frame handling before | |
11713 | that. */ | |
11714 | ||
11715 | frame = get_selected_frame (NULL); | |
11716 | frame_gdbarch = get_frame_arch (frame); | |
11717 | stack_frame_id = get_stack_frame_id (frame); | |
11718 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11719 | |
ae66c1fc EZ |
11720 | /* Keep within the current frame, or in frames called by the current |
11721 | one. */ | |
edb3359d | 11722 | |
883bc8d1 | 11723 | if (frame_id_p (caller_frame_id)) |
c906108c | 11724 | { |
883bc8d1 | 11725 | struct symtab_and_line sal2; |
cfc31633 | 11726 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11727 | |
11728 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11729 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11730 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11731 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11732 | sal2, | |
11733 | caller_frame_id, | |
11734 | bp_until); | |
11735 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11736 | |
883bc8d1 | 11737 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11738 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11739 | } |
c5aa993b | 11740 | |
c70a6932 JK |
11741 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11742 | frame = NULL; | |
11743 | ||
883bc8d1 PA |
11744 | if (anywhere) |
11745 | /* If the user told us to continue until a specified location, | |
11746 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11747 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11748 | null_frame_id, bp_until); | |
883bc8d1 PA |
11749 | else |
11750 | /* Otherwise, specify the selected frame, because we want to stop | |
11751 | only at the very same frame. */ | |
cfc31633 PA |
11752 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11753 | stack_frame_id, bp_until); | |
11754 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11755 | |
cfc31633 PA |
11756 | sm = new_until_break_fsm (tp->num, location_breakpoint, caller_breakpoint); |
11757 | tp->thread_fsm = &sm->thread_fsm; | |
f107f563 | 11758 | |
cfc31633 | 11759 | discard_cleanups (old_chain); |
f107f563 | 11760 | |
cfc31633 | 11761 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11762 | |
11763 | do_cleanups (cleanup); | |
c906108c | 11764 | } |
ae66c1fc | 11765 | |
c906108c SS |
11766 | /* This function attempts to parse an optional "if <cond>" clause |
11767 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11768 | |
c906108c SS |
11769 | Else, it returns a pointer to the condition string. (It does not |
11770 | attempt to evaluate the string against a particular block.) And, | |
11771 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11772 | if clause in the arg string. */ |
53a5351d | 11773 | |
916703c0 | 11774 | char * |
fba45db2 | 11775 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11776 | { |
c5aa993b JM |
11777 | char *cond_string; |
11778 | ||
11779 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11780 | return NULL; |
c5aa993b | 11781 | |
4a64f543 | 11782 | /* Skip the "if" keyword. */ |
c906108c | 11783 | (*arg) += 2; |
c5aa993b | 11784 | |
c906108c | 11785 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11786 | condition string. */ |
e9cafbcc | 11787 | *arg = skip_spaces (*arg); |
c906108c | 11788 | cond_string = *arg; |
c5aa993b | 11789 | |
4a64f543 MS |
11790 | /* Assume that the condition occupies the remainder of the arg |
11791 | string. */ | |
c906108c | 11792 | (*arg) += strlen (cond_string); |
c5aa993b | 11793 | |
c906108c SS |
11794 | return cond_string; |
11795 | } | |
c5aa993b | 11796 | |
c906108c SS |
11797 | /* Commands to deal with catching events, such as signals, exceptions, |
11798 | process start/exit, etc. */ | |
c5aa993b JM |
11799 | |
11800 | typedef enum | |
11801 | { | |
44feb3ce TT |
11802 | catch_fork_temporary, catch_vfork_temporary, |
11803 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11804 | } |
11805 | catch_fork_kind; | |
11806 | ||
c906108c | 11807 | static void |
cc59ec59 MS |
11808 | catch_fork_command_1 (char *arg, int from_tty, |
11809 | struct cmd_list_element *command) | |
c906108c | 11810 | { |
a6d9a66e | 11811 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11812 | char *cond_string = NULL; |
44feb3ce TT |
11813 | catch_fork_kind fork_kind; |
11814 | int tempflag; | |
11815 | ||
11816 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11817 | tempflag = (fork_kind == catch_fork_temporary | |
11818 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11819 | |
44feb3ce TT |
11820 | if (!arg) |
11821 | arg = ""; | |
e9cafbcc | 11822 | arg = skip_spaces (arg); |
c5aa993b | 11823 | |
c906108c | 11824 | /* The allowed syntax is: |
c5aa993b JM |
11825 | catch [v]fork |
11826 | catch [v]fork if <cond> | |
11827 | ||
4a64f543 | 11828 | First, check if there's an if clause. */ |
c906108c | 11829 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11830 | |
c906108c | 11831 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11832 | error (_("Junk at end of arguments.")); |
c5aa993b | 11833 | |
c906108c | 11834 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11835 | and enable reporting of such events. */ |
c5aa993b JM |
11836 | switch (fork_kind) |
11837 | { | |
44feb3ce TT |
11838 | case catch_fork_temporary: |
11839 | case catch_fork_permanent: | |
a6d9a66e | 11840 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11841 | &catch_fork_breakpoint_ops); |
c906108c | 11842 | break; |
44feb3ce TT |
11843 | case catch_vfork_temporary: |
11844 | case catch_vfork_permanent: | |
a6d9a66e | 11845 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11846 | &catch_vfork_breakpoint_ops); |
c906108c | 11847 | break; |
c5aa993b | 11848 | default: |
8a3fe4f8 | 11849 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11850 | break; |
c5aa993b | 11851 | } |
c906108c SS |
11852 | } |
11853 | ||
11854 | static void | |
cc59ec59 MS |
11855 | catch_exec_command_1 (char *arg, int from_tty, |
11856 | struct cmd_list_element *command) | |
c906108c | 11857 | { |
b4d90040 | 11858 | struct exec_catchpoint *c; |
a6d9a66e | 11859 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11860 | int tempflag; |
c5aa993b | 11861 | char *cond_string = NULL; |
c906108c | 11862 | |
44feb3ce TT |
11863 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11864 | ||
11865 | if (!arg) | |
11866 | arg = ""; | |
e9cafbcc | 11867 | arg = skip_spaces (arg); |
c906108c SS |
11868 | |
11869 | /* The allowed syntax is: | |
c5aa993b JM |
11870 | catch exec |
11871 | catch exec if <cond> | |
c906108c | 11872 | |
4a64f543 | 11873 | First, check if there's an if clause. */ |
c906108c SS |
11874 | cond_string = ep_parse_optional_if_clause (&arg); |
11875 | ||
11876 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11877 | error (_("Junk at end of arguments.")); |
c906108c | 11878 | |
b4d90040 PA |
11879 | c = XNEW (struct exec_catchpoint); |
11880 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11881 | &catch_exec_breakpoint_ops); | |
11882 | c->exec_pathname = NULL; | |
11883 | ||
3ea46bff | 11884 | install_breakpoint (0, &c->base, 1); |
c906108c | 11885 | } |
c5aa993b | 11886 | |
9ac4176b | 11887 | void |
28010a5d PA |
11888 | init_ada_exception_breakpoint (struct breakpoint *b, |
11889 | struct gdbarch *gdbarch, | |
11890 | struct symtab_and_line sal, | |
11891 | char *addr_string, | |
c0a91b2b | 11892 | const struct breakpoint_ops *ops, |
28010a5d | 11893 | int tempflag, |
349774ef | 11894 | int enabled, |
28010a5d | 11895 | int from_tty) |
f7f9143b | 11896 | { |
f7f9143b JB |
11897 | if (from_tty) |
11898 | { | |
5af949e3 UW |
11899 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11900 | if (!loc_gdbarch) | |
11901 | loc_gdbarch = gdbarch; | |
11902 | ||
6c95b8df PA |
11903 | describe_other_breakpoints (loc_gdbarch, |
11904 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11905 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11906 | version for exception catchpoints, because two catchpoints | |
11907 | used for different exception names will use the same address. | |
11908 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11909 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11910 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11911 | the user what type of catchpoint it is. The above is good |
11912 | enough for now, though. */ | |
11913 | } | |
11914 | ||
28010a5d | 11915 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11916 | |
349774ef | 11917 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11918 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11919 | b->location = string_to_event_location (&addr_string, |
11920 | language_def (language_ada)); | |
f7f9143b | 11921 | b->language = language_ada; |
f7f9143b JB |
11922 | } |
11923 | ||
c906108c | 11924 | static void |
fba45db2 | 11925 | catch_command (char *arg, int from_tty) |
c906108c | 11926 | { |
44feb3ce | 11927 | error (_("Catch requires an event name.")); |
c906108c SS |
11928 | } |
11929 | \f | |
11930 | ||
11931 | static void | |
fba45db2 | 11932 | tcatch_command (char *arg, int from_tty) |
c906108c | 11933 | { |
44feb3ce | 11934 | error (_("Catch requires an event name.")); |
c906108c SS |
11935 | } |
11936 | ||
8a2c437b TT |
11937 | /* A qsort comparison function that sorts breakpoints in order. */ |
11938 | ||
11939 | static int | |
11940 | compare_breakpoints (const void *a, const void *b) | |
11941 | { | |
9a3c8263 | 11942 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11943 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11944 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11945 | uintptr_t ub = (uintptr_t) *bb; |
11946 | ||
11947 | if ((*ba)->number < (*bb)->number) | |
11948 | return -1; | |
11949 | else if ((*ba)->number > (*bb)->number) | |
11950 | return 1; | |
11951 | ||
11952 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11953 | the number 0. */ | |
11954 | if (ua < ub) | |
11955 | return -1; | |
94b0e70d | 11956 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11957 | } |
11958 | ||
80f8a6eb | 11959 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11960 | |
11961 | static void | |
fba45db2 | 11962 | clear_command (char *arg, int from_tty) |
c906108c | 11963 | { |
8a2c437b | 11964 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11965 | VEC(breakpoint_p) *found = 0; |
11966 | int ix; | |
c906108c SS |
11967 | int default_match; |
11968 | struct symtabs_and_lines sals; | |
11969 | struct symtab_and_line sal; | |
c906108c | 11970 | int i; |
8a2c437b | 11971 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11972 | |
11973 | if (arg) | |
11974 | { | |
39cf75f7 DE |
11975 | sals = decode_line_with_current_source (arg, |
11976 | (DECODE_LINE_FUNFIRSTLINE | |
11977 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11978 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11979 | default_match = 0; |
11980 | } | |
11981 | else | |
11982 | { | |
8d749320 | 11983 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 11984 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11985 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11986 | |
11987 | /* Set sal's line, symtab, pc, and pspace to the values | |
11988 | corresponding to the last call to print_frame_info. If the | |
11989 | codepoint is not valid, this will set all the fields to 0. */ | |
11990 | get_last_displayed_sal (&sal); | |
c906108c | 11991 | if (sal.symtab == 0) |
8a3fe4f8 | 11992 | error (_("No source file specified.")); |
c906108c SS |
11993 | |
11994 | sals.sals[0] = sal; | |
11995 | sals.nelts = 1; | |
11996 | ||
11997 | default_match = 1; | |
11998 | } | |
11999 | ||
4a64f543 MS |
12000 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12001 | seems, because all existing breakpoints typically have both | |
12002 | file/line and pc set. So, if clear is given file/line, we can | |
12003 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12004 | |
12005 | We only support clearing given the address explicitly | |
12006 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12007 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12008 | due to optimization, all in one block. |
4a64f543 MS |
12009 | |
12010 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12011 | PC corresponding to the same file:line, the breakpoint won't |
12012 | be cleared. We probably can still clear the breakpoint, but | |
12013 | since the other PC value is never presented to user, user | |
12014 | can only find it by guessing, and it does not seem important | |
12015 | to support that. */ | |
12016 | ||
4a64f543 MS |
12017 | /* For each line spec given, delete bps which correspond to it. Do |
12018 | it in two passes, solely to preserve the current behavior that | |
12019 | from_tty is forced true if we delete more than one | |
12020 | breakpoint. */ | |
c906108c | 12021 | |
80f8a6eb | 12022 | found = NULL; |
8a2c437b | 12023 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12024 | for (i = 0; i < sals.nelts; i++) |
12025 | { | |
05cba821 JK |
12026 | const char *sal_fullname; |
12027 | ||
c906108c | 12028 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12029 | If line given (pc == 0), clear all bpts on specified line. |
12030 | If defaulting, clear all bpts on default line | |
c906108c | 12031 | or at default pc. |
c5aa993b JM |
12032 | |
12033 | defaulting sal.pc != 0 tests to do | |
12034 | ||
12035 | 0 1 pc | |
12036 | 1 1 pc _and_ line | |
12037 | 0 0 line | |
12038 | 1 0 <can't happen> */ | |
c906108c SS |
12039 | |
12040 | sal = sals.sals[i]; | |
05cba821 JK |
12041 | sal_fullname = (sal.symtab == NULL |
12042 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12043 | |
4a64f543 | 12044 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12045 | ALL_BREAKPOINTS (b) |
c5aa993b | 12046 | { |
0d381245 | 12047 | int match = 0; |
4a64f543 | 12048 | /* Are we going to delete b? */ |
cc60f2e3 | 12049 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12050 | { |
12051 | struct bp_location *loc = b->loc; | |
12052 | for (; loc; loc = loc->next) | |
12053 | { | |
f8eba3c6 TT |
12054 | /* If the user specified file:line, don't allow a PC |
12055 | match. This matches historical gdb behavior. */ | |
12056 | int pc_match = (!sal.explicit_line | |
12057 | && sal.pc | |
12058 | && (loc->pspace == sal.pspace) | |
12059 | && (loc->address == sal.pc) | |
12060 | && (!section_is_overlay (loc->section) | |
12061 | || loc->section == sal.section)); | |
4aac40c8 TT |
12062 | int line_match = 0; |
12063 | ||
12064 | if ((default_match || sal.explicit_line) | |
2f202fde | 12065 | && loc->symtab != NULL |
05cba821 | 12066 | && sal_fullname != NULL |
4aac40c8 | 12067 | && sal.pspace == loc->pspace |
05cba821 JK |
12068 | && loc->line_number == sal.line |
12069 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12070 | sal_fullname) == 0) | |
12071 | line_match = 1; | |
4aac40c8 | 12072 | |
0d381245 VP |
12073 | if (pc_match || line_match) |
12074 | { | |
12075 | match = 1; | |
12076 | break; | |
12077 | } | |
12078 | } | |
12079 | } | |
12080 | ||
12081 | if (match) | |
d6e956e5 | 12082 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12083 | } |
80f8a6eb | 12084 | } |
8a2c437b | 12085 | |
80f8a6eb | 12086 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12087 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12088 | { |
12089 | if (arg) | |
8a3fe4f8 | 12090 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12091 | else |
8a3fe4f8 | 12092 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12093 | } |
c906108c | 12094 | |
8a2c437b TT |
12095 | /* Remove duplicates from the vec. */ |
12096 | qsort (VEC_address (breakpoint_p, found), | |
12097 | VEC_length (breakpoint_p, found), | |
12098 | sizeof (breakpoint_p), | |
12099 | compare_breakpoints); | |
12100 | prev = VEC_index (breakpoint_p, found, 0); | |
12101 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12102 | { | |
12103 | if (b == prev) | |
12104 | { | |
12105 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12106 | --ix; | |
12107 | } | |
12108 | } | |
12109 | ||
d6e956e5 | 12110 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12111 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12112 | if (from_tty) |
a3f17187 | 12113 | { |
d6e956e5 | 12114 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12115 | printf_unfiltered (_("Deleted breakpoint ")); |
12116 | else | |
12117 | printf_unfiltered (_("Deleted breakpoints ")); | |
12118 | } | |
d6e956e5 VP |
12119 | |
12120 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12121 | { |
c5aa993b | 12122 | if (from_tty) |
d6e956e5 VP |
12123 | printf_unfiltered ("%d ", b->number); |
12124 | delete_breakpoint (b); | |
c906108c | 12125 | } |
80f8a6eb MS |
12126 | if (from_tty) |
12127 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12128 | |
12129 | do_cleanups (cleanups); | |
c906108c SS |
12130 | } |
12131 | \f | |
12132 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12133 | all breakpoints that are marked for deletion, whether hit or not. | |
12134 | This is called after any breakpoint is hit, or after errors. */ | |
12135 | ||
12136 | void | |
fba45db2 | 12137 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12138 | { |
35df4500 | 12139 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12140 | |
12141 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12142 | if (bs->breakpoint_at |
12143 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12144 | && bs->stop) |
f431efe5 | 12145 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12146 | |
35df4500 | 12147 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12148 | { |
b5de0fa7 | 12149 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12150 | delete_breakpoint (b); |
12151 | } | |
c906108c SS |
12152 | } |
12153 | ||
4a64f543 MS |
12154 | /* A comparison function for bp_location AP and BP being interfaced to |
12155 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12156 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12157 | secondarily by ordering first permanent elements and |
4a64f543 | 12158 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12159 | qsort being an unstable algorithm. */ |
876fa593 JK |
12160 | |
12161 | static int | |
494cfb0f | 12162 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12163 | { |
9a3c8263 SM |
12164 | const struct bp_location *a = *(const struct bp_location **) ap; |
12165 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12166 | |
12167 | if (a->address != b->address) | |
12168 | return (a->address > b->address) - (a->address < b->address); | |
12169 | ||
dea2aa5f LM |
12170 | /* Sort locations at the same address by their pspace number, keeping |
12171 | locations of the same inferior (in a multi-inferior environment) | |
12172 | grouped. */ | |
12173 | ||
12174 | if (a->pspace->num != b->pspace->num) | |
12175 | return ((a->pspace->num > b->pspace->num) | |
12176 | - (a->pspace->num < b->pspace->num)); | |
12177 | ||
876fa593 | 12178 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12179 | if (a->permanent != b->permanent) |
12180 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12181 | |
c56a97f9 JK |
12182 | /* Make the internal GDB representation stable across GDB runs |
12183 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12184 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12185 | |
12186 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12187 | return ((a->owner->number > b->owner->number) |
12188 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12189 | |
12190 | return (a > b) - (a < b); | |
12191 | } | |
12192 | ||
876fa593 | 12193 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12194 | bp_location_shadow_len_after_address_max according to the current |
12195 | content of the bp_location array. */ | |
f7545552 TT |
12196 | |
12197 | static void | |
876fa593 | 12198 | bp_location_target_extensions_update (void) |
f7545552 | 12199 | { |
876fa593 JK |
12200 | struct bp_location *bl, **blp_tmp; |
12201 | ||
12202 | bp_location_placed_address_before_address_max = 0; | |
12203 | bp_location_shadow_len_after_address_max = 0; | |
12204 | ||
12205 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12206 | { | |
12207 | CORE_ADDR start, end, addr; | |
12208 | ||
12209 | if (!bp_location_has_shadow (bl)) | |
12210 | continue; | |
12211 | ||
12212 | start = bl->target_info.placed_address; | |
12213 | end = start + bl->target_info.shadow_len; | |
12214 | ||
12215 | gdb_assert (bl->address >= start); | |
12216 | addr = bl->address - start; | |
12217 | if (addr > bp_location_placed_address_before_address_max) | |
12218 | bp_location_placed_address_before_address_max = addr; | |
12219 | ||
12220 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12221 | ||
12222 | gdb_assert (bl->address < end); | |
12223 | addr = end - bl->address; | |
12224 | if (addr > bp_location_shadow_len_after_address_max) | |
12225 | bp_location_shadow_len_after_address_max = addr; | |
12226 | } | |
f7545552 TT |
12227 | } |
12228 | ||
1e4d1764 YQ |
12229 | /* Download tracepoint locations if they haven't been. */ |
12230 | ||
12231 | static void | |
12232 | download_tracepoint_locations (void) | |
12233 | { | |
7ed2c994 | 12234 | struct breakpoint *b; |
1e4d1764 | 12235 | struct cleanup *old_chain; |
dd2e65cc | 12236 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12237 | |
12238 | old_chain = save_current_space_and_thread (); | |
12239 | ||
7ed2c994 | 12240 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12241 | { |
7ed2c994 | 12242 | struct bp_location *bl; |
1e4d1764 | 12243 | struct tracepoint *t; |
f2a8bc8a | 12244 | int bp_location_downloaded = 0; |
1e4d1764 | 12245 | |
7ed2c994 | 12246 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12247 | ? !may_insert_fast_tracepoints |
12248 | : !may_insert_tracepoints)) | |
12249 | continue; | |
12250 | ||
dd2e65cc YQ |
12251 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12252 | { | |
12253 | if (target_can_download_tracepoint ()) | |
12254 | can_download_tracepoint = TRIBOOL_TRUE; | |
12255 | else | |
12256 | can_download_tracepoint = TRIBOOL_FALSE; | |
12257 | } | |
12258 | ||
12259 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12260 | break; | |
12261 | ||
7ed2c994 YQ |
12262 | for (bl = b->loc; bl; bl = bl->next) |
12263 | { | |
12264 | /* In tracepoint, locations are _never_ duplicated, so | |
12265 | should_be_inserted is equivalent to | |
12266 | unduplicated_should_be_inserted. */ | |
12267 | if (!should_be_inserted (bl) || bl->inserted) | |
12268 | continue; | |
1e4d1764 | 12269 | |
7ed2c994 | 12270 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12271 | |
7ed2c994 | 12272 | target_download_tracepoint (bl); |
1e4d1764 | 12273 | |
7ed2c994 | 12274 | bl->inserted = 1; |
f2a8bc8a | 12275 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12276 | } |
12277 | t = (struct tracepoint *) b; | |
12278 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12279 | if (bp_location_downloaded) |
12280 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12281 | } |
12282 | ||
12283 | do_cleanups (old_chain); | |
12284 | } | |
12285 | ||
934709f0 PW |
12286 | /* Swap the insertion/duplication state between two locations. */ |
12287 | ||
12288 | static void | |
12289 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12290 | { | |
12291 | const int left_inserted = left->inserted; | |
12292 | const int left_duplicate = left->duplicate; | |
b775012e | 12293 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12294 | const struct bp_target_info left_target_info = left->target_info; |
12295 | ||
1e4d1764 YQ |
12296 | /* Locations of tracepoints can never be duplicated. */ |
12297 | if (is_tracepoint (left->owner)) | |
12298 | gdb_assert (!left->duplicate); | |
12299 | if (is_tracepoint (right->owner)) | |
12300 | gdb_assert (!right->duplicate); | |
12301 | ||
934709f0 PW |
12302 | left->inserted = right->inserted; |
12303 | left->duplicate = right->duplicate; | |
b775012e | 12304 | left->needs_update = right->needs_update; |
934709f0 PW |
12305 | left->target_info = right->target_info; |
12306 | right->inserted = left_inserted; | |
12307 | right->duplicate = left_duplicate; | |
b775012e | 12308 | right->needs_update = left_needs_update; |
934709f0 PW |
12309 | right->target_info = left_target_info; |
12310 | } | |
12311 | ||
b775012e LM |
12312 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12313 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12314 | conditions on the target's side. Such conditions need to be updated on | |
12315 | the target. */ | |
12316 | ||
12317 | static void | |
12318 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12319 | { | |
12320 | struct bp_location **locp = NULL, **loc2p; | |
12321 | struct bp_location *loc; | |
12322 | CORE_ADDR address = 0; | |
12323 | int pspace_num; | |
12324 | ||
12325 | address = bl->address; | |
12326 | pspace_num = bl->pspace->num; | |
12327 | ||
12328 | /* This is only meaningful if the target is | |
12329 | evaluating conditions and if the user has | |
12330 | opted for condition evaluation on the target's | |
12331 | side. */ | |
12332 | if (gdb_evaluates_breakpoint_condition_p () | |
12333 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12334 | return; | |
12335 | ||
12336 | /* Flag all breakpoint locations with this address and | |
12337 | the same program space as the location | |
12338 | as "its condition has changed". We need to | |
12339 | update the conditions on the target's side. */ | |
12340 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12341 | { | |
12342 | loc = *loc2p; | |
12343 | ||
12344 | if (!is_breakpoint (loc->owner) | |
12345 | || pspace_num != loc->pspace->num) | |
12346 | continue; | |
12347 | ||
12348 | /* Flag the location appropriately. We use a different state to | |
12349 | let everyone know that we already updated the set of locations | |
12350 | with addr bl->address and program space bl->pspace. This is so | |
12351 | we don't have to keep calling these functions just to mark locations | |
12352 | that have already been marked. */ | |
12353 | loc->condition_changed = condition_updated; | |
12354 | ||
12355 | /* Free the agent expression bytecode as well. We will compute | |
12356 | it later on. */ | |
12357 | if (loc->cond_bytecode) | |
12358 | { | |
12359 | free_agent_expr (loc->cond_bytecode); | |
12360 | loc->cond_bytecode = NULL; | |
12361 | } | |
12362 | } | |
12363 | } | |
44702360 PA |
12364 | /* Called whether new breakpoints are created, or existing breakpoints |
12365 | deleted, to update the global location list and recompute which | |
12366 | locations are duplicate of which. | |
b775012e | 12367 | |
04086b45 PA |
12368 | The INSERT_MODE flag determines whether locations may not, may, or |
12369 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12370 | info. */ | |
b60e7edf | 12371 | |
0d381245 | 12372 | static void |
44702360 | 12373 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12374 | { |
74960c60 | 12375 | struct breakpoint *b; |
876fa593 | 12376 | struct bp_location **locp, *loc; |
f7545552 | 12377 | struct cleanup *cleanups; |
b775012e LM |
12378 | /* Last breakpoint location address that was marked for update. */ |
12379 | CORE_ADDR last_addr = 0; | |
12380 | /* Last breakpoint location program space that was marked for update. */ | |
12381 | int last_pspace_num = -1; | |
f7545552 | 12382 | |
2d134ed3 PA |
12383 | /* Used in the duplicates detection below. When iterating over all |
12384 | bp_locations, points to the first bp_location of a given address. | |
12385 | Breakpoints and watchpoints of different types are never | |
12386 | duplicates of each other. Keep one pointer for each type of | |
12387 | breakpoint/watchpoint, so we only need to loop over all locations | |
12388 | once. */ | |
12389 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12390 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12391 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12392 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12393 | |
4a64f543 MS |
12394 | /* Saved former bp_location array which we compare against the newly |
12395 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12396 | struct bp_location **old_location, **old_locp; |
12397 | unsigned old_location_count; | |
12398 | ||
12399 | old_location = bp_location; | |
12400 | old_location_count = bp_location_count; | |
12401 | bp_location = NULL; | |
12402 | bp_location_count = 0; | |
12403 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12404 | |
74960c60 | 12405 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12406 | for (loc = b->loc; loc; loc = loc->next) |
12407 | bp_location_count++; | |
12408 | ||
8d749320 | 12409 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12410 | locp = bp_location; |
12411 | ALL_BREAKPOINTS (b) | |
12412 | for (loc = b->loc; loc; loc = loc->next) | |
12413 | *locp++ = loc; | |
12414 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12415 | bp_location_compare); |
876fa593 JK |
12416 | |
12417 | bp_location_target_extensions_update (); | |
74960c60 | 12418 | |
4a64f543 MS |
12419 | /* Identify bp_location instances that are no longer present in the |
12420 | new list, and therefore should be freed. Note that it's not | |
12421 | necessary that those locations should be removed from inferior -- | |
12422 | if there's another location at the same address (previously | |
12423 | marked as duplicate), we don't need to remove/insert the | |
12424 | location. | |
876fa593 | 12425 | |
4a64f543 MS |
12426 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12427 | and former bp_location array state respectively. */ | |
876fa593 JK |
12428 | |
12429 | locp = bp_location; | |
12430 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12431 | old_locp++) | |
74960c60 | 12432 | { |
876fa593 | 12433 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12434 | struct bp_location **loc2p; |
876fa593 | 12435 | |
e5dd4106 | 12436 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12437 | not, we have to free it. */ |
c7d46a38 | 12438 | int found_object = 0; |
20874c92 VP |
12439 | /* Tells if the location should remain inserted in the target. */ |
12440 | int keep_in_target = 0; | |
12441 | int removed = 0; | |
876fa593 | 12442 | |
4a64f543 MS |
12443 | /* Skip LOCP entries which will definitely never be needed. |
12444 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12445 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12446 | && (*locp)->address < old_loc->address) |
876fa593 | 12447 | locp++; |
c7d46a38 PA |
12448 | |
12449 | for (loc2p = locp; | |
12450 | (loc2p < bp_location + bp_location_count | |
12451 | && (*loc2p)->address == old_loc->address); | |
12452 | loc2p++) | |
12453 | { | |
b775012e LM |
12454 | /* Check if this is a new/duplicated location or a duplicated |
12455 | location that had its condition modified. If so, we want to send | |
12456 | its condition to the target if evaluation of conditions is taking | |
12457 | place there. */ | |
12458 | if ((*loc2p)->condition_changed == condition_modified | |
12459 | && (last_addr != old_loc->address | |
12460 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12461 | { |
b775012e LM |
12462 | force_breakpoint_reinsertion (*loc2p); |
12463 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12464 | } |
b775012e LM |
12465 | |
12466 | if (*loc2p == old_loc) | |
12467 | found_object = 1; | |
c7d46a38 | 12468 | } |
74960c60 | 12469 | |
b775012e LM |
12470 | /* We have already handled this address, update it so that we don't |
12471 | have to go through updates again. */ | |
12472 | last_addr = old_loc->address; | |
12473 | ||
12474 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12475 | if (!found_object) | |
12476 | force_breakpoint_reinsertion (old_loc); | |
12477 | ||
4a64f543 MS |
12478 | /* If this location is no longer present, and inserted, look if |
12479 | there's maybe a new location at the same address. If so, | |
12480 | mark that one inserted, and don't remove this one. This is | |
12481 | needed so that we don't have a time window where a breakpoint | |
12482 | at certain location is not inserted. */ | |
74960c60 | 12483 | |
876fa593 | 12484 | if (old_loc->inserted) |
0d381245 | 12485 | { |
4a64f543 MS |
12486 | /* If the location is inserted now, we might have to remove |
12487 | it. */ | |
74960c60 | 12488 | |
876fa593 | 12489 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12490 | { |
4a64f543 MS |
12491 | /* The location is still present in the location list, |
12492 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12493 | keep_in_target = 1; |
74960c60 VP |
12494 | } |
12495 | else | |
12496 | { | |
b775012e LM |
12497 | /* This location still exists, but it won't be kept in the |
12498 | target since it may have been disabled. We proceed to | |
12499 | remove its target-side condition. */ | |
12500 | ||
4a64f543 MS |
12501 | /* The location is either no longer present, or got |
12502 | disabled. See if there's another location at the | |
12503 | same address, in which case we don't need to remove | |
12504 | this one from the target. */ | |
876fa593 | 12505 | |
2bdf28a0 | 12506 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12507 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12508 | { | |
876fa593 | 12509 | for (loc2p = locp; |
c7d46a38 PA |
12510 | (loc2p < bp_location + bp_location_count |
12511 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12512 | loc2p++) |
12513 | { | |
12514 | struct bp_location *loc2 = *loc2p; | |
12515 | ||
2d134ed3 | 12516 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12517 | { |
85d721b8 PA |
12518 | /* Read watchpoint locations are switched to |
12519 | access watchpoints, if the former are not | |
12520 | supported, but the latter are. */ | |
12521 | if (is_hardware_watchpoint (old_loc->owner)) | |
12522 | { | |
12523 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12524 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12525 | } | |
12526 | ||
934709f0 PW |
12527 | /* loc2 is a duplicated location. We need to check |
12528 | if it should be inserted in case it will be | |
12529 | unduplicated. */ | |
12530 | if (loc2 != old_loc | |
12531 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12532 | { |
934709f0 | 12533 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12534 | keep_in_target = 1; |
12535 | break; | |
12536 | } | |
876fa593 JK |
12537 | } |
12538 | } | |
12539 | } | |
74960c60 VP |
12540 | } |
12541 | ||
20874c92 VP |
12542 | if (!keep_in_target) |
12543 | { | |
876fa593 | 12544 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12545 | { |
4a64f543 MS |
12546 | /* This is just about all we can do. We could keep |
12547 | this location on the global list, and try to | |
12548 | remove it next time, but there's no particular | |
12549 | reason why we will succeed next time. | |
20874c92 | 12550 | |
4a64f543 MS |
12551 | Note that at this point, old_loc->owner is still |
12552 | valid, as delete_breakpoint frees the breakpoint | |
12553 | only after calling us. */ | |
3e43a32a MS |
12554 | printf_filtered (_("warning: Error removing " |
12555 | "breakpoint %d\n"), | |
876fa593 | 12556 | old_loc->owner->number); |
20874c92 VP |
12557 | } |
12558 | removed = 1; | |
12559 | } | |
0d381245 | 12560 | } |
74960c60 VP |
12561 | |
12562 | if (!found_object) | |
1c5cfe86 | 12563 | { |
fbea99ea | 12564 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12565 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12566 | { |
db82e815 PA |
12567 | /* This location was removed from the target. In |
12568 | non-stop mode, a race condition is possible where | |
12569 | we've removed a breakpoint, but stop events for that | |
12570 | breakpoint are already queued and will arrive later. | |
12571 | We apply an heuristic to be able to distinguish such | |
12572 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12573 | breakpoint location for a bit, and will retire it | |
12574 | after we see some number of events. The theory here | |
12575 | is that reporting of events should, "on the average", | |
12576 | be fair, so after a while we'll see events from all | |
12577 | threads that have anything of interest, and no longer | |
12578 | need to keep this breakpoint location around. We | |
12579 | don't hold locations forever so to reduce chances of | |
12580 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12581 | SIGTRAP. | |
12582 | ||
12583 | The heuristic failing can be disastrous on | |
12584 | decr_pc_after_break targets. | |
12585 | ||
12586 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12587 | if we fail to recognize a late breakpoint SIGTRAP, | |
12588 | because events_till_retirement has reached 0 too | |
12589 | soon, we'll fail to do the PC adjustment, and report | |
12590 | a random SIGTRAP to the user. When the user resumes | |
12591 | the inferior, it will most likely immediately crash | |
2dec564e | 12592 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12593 | corrupted, because of being resumed e.g., in the |
12594 | middle of a multi-byte instruction, or skipped a | |
12595 | one-byte instruction. This was actually seen happen | |
12596 | on native x86-linux, and should be less rare on | |
12597 | targets that do not support new thread events, like | |
12598 | remote, due to the heuristic depending on | |
12599 | thread_count. | |
12600 | ||
12601 | Mistaking a random SIGTRAP for a breakpoint trap | |
12602 | causes similar symptoms (PC adjustment applied when | |
12603 | it shouldn't), but then again, playing with SIGTRAPs | |
12604 | behind the debugger's back is asking for trouble. | |
12605 | ||
12606 | Since hardware watchpoint traps are always | |
12607 | distinguishable from other traps, so we don't need to | |
12608 | apply keep hardware watchpoint moribund locations | |
12609 | around. We simply always ignore hardware watchpoint | |
12610 | traps we can no longer explain. */ | |
12611 | ||
876fa593 JK |
12612 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12613 | old_loc->owner = NULL; | |
20874c92 | 12614 | |
876fa593 | 12615 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12616 | } |
12617 | else | |
f431efe5 PA |
12618 | { |
12619 | old_loc->owner = NULL; | |
12620 | decref_bp_location (&old_loc); | |
12621 | } | |
20874c92 | 12622 | } |
74960c60 | 12623 | } |
1c5cfe86 | 12624 | |
348d480f PA |
12625 | /* Rescan breakpoints at the same address and section, marking the |
12626 | first one as "first" and any others as "duplicates". This is so | |
12627 | that the bpt instruction is only inserted once. If we have a | |
12628 | permanent breakpoint at the same place as BPT, make that one the | |
12629 | official one, and the rest as duplicates. Permanent breakpoints | |
12630 | are sorted first for the same address. | |
12631 | ||
12632 | Do the same for hardware watchpoints, but also considering the | |
12633 | watchpoint's type (regular/access/read) and length. */ | |
12634 | ||
12635 | bp_loc_first = NULL; | |
12636 | wp_loc_first = NULL; | |
12637 | awp_loc_first = NULL; | |
12638 | rwp_loc_first = NULL; | |
12639 | ALL_BP_LOCATIONS (loc, locp) | |
12640 | { | |
12641 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12642 | non-NULL. */ | |
348d480f | 12643 | struct bp_location **loc_first_p; |
d3fbdd86 | 12644 | b = loc->owner; |
348d480f | 12645 | |
6f380991 | 12646 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12647 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12648 | /* Don't detect duplicate for tracepoint locations because they are |
12649 | never duplicated. See the comments in field `duplicate' of | |
12650 | `struct bp_location'. */ | |
348d480f | 12651 | || is_tracepoint (b)) |
b775012e LM |
12652 | { |
12653 | /* Clear the condition modification flag. */ | |
12654 | loc->condition_changed = condition_unchanged; | |
12655 | continue; | |
12656 | } | |
348d480f | 12657 | |
348d480f PA |
12658 | if (b->type == bp_hardware_watchpoint) |
12659 | loc_first_p = &wp_loc_first; | |
12660 | else if (b->type == bp_read_watchpoint) | |
12661 | loc_first_p = &rwp_loc_first; | |
12662 | else if (b->type == bp_access_watchpoint) | |
12663 | loc_first_p = &awp_loc_first; | |
12664 | else | |
12665 | loc_first_p = &bp_loc_first; | |
12666 | ||
12667 | if (*loc_first_p == NULL | |
12668 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12669 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12670 | { | |
12671 | *loc_first_p = loc; | |
12672 | loc->duplicate = 0; | |
b775012e LM |
12673 | |
12674 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12675 | { | |
12676 | loc->needs_update = 1; | |
12677 | /* Clear the condition modification flag. */ | |
12678 | loc->condition_changed = condition_unchanged; | |
12679 | } | |
348d480f PA |
12680 | continue; |
12681 | } | |
12682 | ||
934709f0 PW |
12683 | |
12684 | /* This and the above ensure the invariant that the first location | |
12685 | is not duplicated, and is the inserted one. | |
12686 | All following are marked as duplicated, and are not inserted. */ | |
12687 | if (loc->inserted) | |
12688 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12689 | loc->duplicate = 1; |
12690 | ||
b775012e LM |
12691 | /* Clear the condition modification flag. */ |
12692 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12693 | } |
12694 | ||
a25a5a45 | 12695 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12696 | { |
04086b45 | 12697 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12698 | insert_breakpoint_locations (); |
12699 | else | |
12700 | { | |
44702360 PA |
12701 | /* Even though the caller told us to not insert new |
12702 | locations, we may still need to update conditions on the | |
12703 | target's side of breakpoints that were already inserted | |
12704 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12705 | only update conditions for locations that are marked |
12706 | "needs_update". */ | |
12707 | update_inserted_breakpoint_locations (); | |
12708 | } | |
12709 | } | |
348d480f | 12710 | |
04086b45 | 12711 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12712 | download_tracepoint_locations (); |
12713 | ||
348d480f PA |
12714 | do_cleanups (cleanups); |
12715 | } | |
12716 | ||
12717 | void | |
12718 | breakpoint_retire_moribund (void) | |
12719 | { | |
12720 | struct bp_location *loc; | |
12721 | int ix; | |
12722 | ||
12723 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12724 | if (--(loc->events_till_retirement) == 0) | |
12725 | { | |
12726 | decref_bp_location (&loc); | |
12727 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12728 | --ix; | |
12729 | } | |
12730 | } | |
12731 | ||
12732 | static void | |
44702360 | 12733 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12734 | { |
348d480f | 12735 | |
492d29ea PA |
12736 | TRY |
12737 | { | |
12738 | update_global_location_list (insert_mode); | |
12739 | } | |
12740 | CATCH (e, RETURN_MASK_ERROR) | |
12741 | { | |
12742 | } | |
12743 | END_CATCH | |
348d480f PA |
12744 | } |
12745 | ||
12746 | /* Clear BKP from a BPS. */ | |
12747 | ||
12748 | static void | |
12749 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12750 | { | |
12751 | bpstat bs; | |
12752 | ||
12753 | for (bs = bps; bs; bs = bs->next) | |
12754 | if (bs->breakpoint_at == bpt) | |
12755 | { | |
12756 | bs->breakpoint_at = NULL; | |
12757 | bs->old_val = NULL; | |
12758 | /* bs->commands will be freed later. */ | |
12759 | } | |
12760 | } | |
12761 | ||
12762 | /* Callback for iterate_over_threads. */ | |
12763 | static int | |
12764 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12765 | { | |
9a3c8263 | 12766 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12767 | |
12768 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12769 | return 0; | |
12770 | } | |
12771 | ||
12772 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12773 | callbacks. */ | |
12774 | ||
12775 | static void | |
12776 | say_where (struct breakpoint *b) | |
12777 | { | |
12778 | struct value_print_options opts; | |
12779 | ||
12780 | get_user_print_options (&opts); | |
12781 | ||
12782 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12783 | single string. */ | |
12784 | if (b->loc == NULL) | |
12785 | { | |
f00aae0f KS |
12786 | /* For pending locations, the output differs slightly based |
12787 | on b->extra_string. If this is non-NULL, it contains either | |
12788 | a condition or dprintf arguments. */ | |
12789 | if (b->extra_string == NULL) | |
12790 | { | |
12791 | printf_filtered (_(" (%s) pending."), | |
12792 | event_location_to_string (b->location)); | |
12793 | } | |
12794 | else if (b->type == bp_dprintf) | |
12795 | { | |
12796 | printf_filtered (_(" (%s,%s) pending."), | |
12797 | event_location_to_string (b->location), | |
12798 | b->extra_string); | |
12799 | } | |
12800 | else | |
12801 | { | |
12802 | printf_filtered (_(" (%s %s) pending."), | |
12803 | event_location_to_string (b->location), | |
12804 | b->extra_string); | |
12805 | } | |
348d480f PA |
12806 | } |
12807 | else | |
12808 | { | |
2f202fde | 12809 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12810 | { |
12811 | printf_filtered (" at "); | |
12812 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12813 | gdb_stdout); | |
12814 | } | |
2f202fde | 12815 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12816 | { |
12817 | /* If there is a single location, we can print the location | |
12818 | more nicely. */ | |
12819 | if (b->loc->next == NULL) | |
12820 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12821 | symtab_to_filename_for_display (b->loc->symtab), |
12822 | b->loc->line_number); | |
f8eba3c6 TT |
12823 | else |
12824 | /* This is not ideal, but each location may have a | |
12825 | different file name, and this at least reflects the | |
12826 | real situation somewhat. */ | |
f00aae0f KS |
12827 | printf_filtered (": %s.", |
12828 | event_location_to_string (b->location)); | |
f8eba3c6 | 12829 | } |
348d480f PA |
12830 | |
12831 | if (b->loc->next) | |
12832 | { | |
12833 | struct bp_location *loc = b->loc; | |
12834 | int n = 0; | |
12835 | for (; loc; loc = loc->next) | |
12836 | ++n; | |
12837 | printf_filtered (" (%d locations)", n); | |
12838 | } | |
12839 | } | |
12840 | } | |
12841 | ||
348d480f PA |
12842 | /* Default bp_location_ops methods. */ |
12843 | ||
12844 | static void | |
12845 | bp_location_dtor (struct bp_location *self) | |
12846 | { | |
12847 | xfree (self->cond); | |
b775012e LM |
12848 | if (self->cond_bytecode) |
12849 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12850 | xfree (self->function_name); |
8b4f3082 PA |
12851 | |
12852 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12853 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12854 | } |
12855 | ||
12856 | static const struct bp_location_ops bp_location_ops = | |
12857 | { | |
12858 | bp_location_dtor | |
12859 | }; | |
12860 | ||
2060206e PA |
12861 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12862 | inherit from. */ | |
348d480f | 12863 | |
2060206e PA |
12864 | static void |
12865 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12866 | { |
12867 | decref_counted_command_line (&self->commands); | |
12868 | xfree (self->cond_string); | |
fb81d016 | 12869 | xfree (self->extra_string); |
f8eba3c6 | 12870 | xfree (self->filter); |
f00aae0f KS |
12871 | delete_event_location (self->location); |
12872 | delete_event_location (self->location_range_end); | |
348d480f PA |
12873 | } |
12874 | ||
2060206e PA |
12875 | static struct bp_location * |
12876 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12877 | { |
12878 | struct bp_location *loc; | |
12879 | ||
12880 | loc = XNEW (struct bp_location); | |
12881 | init_bp_location (loc, &bp_location_ops, self); | |
12882 | return loc; | |
12883 | } | |
12884 | ||
2060206e PA |
12885 | static void |
12886 | base_breakpoint_re_set (struct breakpoint *b) | |
12887 | { | |
12888 | /* Nothing to re-set. */ | |
12889 | } | |
12890 | ||
12891 | #define internal_error_pure_virtual_called() \ | |
12892 | gdb_assert_not_reached ("pure virtual function called") | |
12893 | ||
12894 | static int | |
12895 | base_breakpoint_insert_location (struct bp_location *bl) | |
12896 | { | |
12897 | internal_error_pure_virtual_called (); | |
12898 | } | |
12899 | ||
12900 | static int | |
12901 | base_breakpoint_remove_location (struct bp_location *bl) | |
12902 | { | |
12903 | internal_error_pure_virtual_called (); | |
12904 | } | |
12905 | ||
12906 | static int | |
12907 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12908 | struct address_space *aspace, | |
09ac7c10 TT |
12909 | CORE_ADDR bp_addr, |
12910 | const struct target_waitstatus *ws) | |
2060206e PA |
12911 | { |
12912 | internal_error_pure_virtual_called (); | |
12913 | } | |
12914 | ||
12915 | static void | |
12916 | base_breakpoint_check_status (bpstat bs) | |
12917 | { | |
12918 | /* Always stop. */ | |
12919 | } | |
12920 | ||
12921 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12922 | errors. */ | |
12923 | ||
12924 | static int | |
12925 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12926 | { | |
12927 | internal_error_pure_virtual_called (); | |
12928 | } | |
12929 | ||
12930 | /* A "resources_needed" breakpoint_ops method that just internal | |
12931 | errors. */ | |
12932 | ||
12933 | static int | |
12934 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12935 | { | |
12936 | internal_error_pure_virtual_called (); | |
12937 | } | |
12938 | ||
12939 | static enum print_stop_action | |
12940 | base_breakpoint_print_it (bpstat bs) | |
12941 | { | |
12942 | internal_error_pure_virtual_called (); | |
12943 | } | |
12944 | ||
12945 | static void | |
12946 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12947 | struct ui_out *uiout) | |
12948 | { | |
12949 | /* nothing */ | |
12950 | } | |
12951 | ||
12952 | static void | |
12953 | base_breakpoint_print_mention (struct breakpoint *b) | |
12954 | { | |
12955 | internal_error_pure_virtual_called (); | |
12956 | } | |
12957 | ||
12958 | static void | |
12959 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12960 | { | |
12961 | internal_error_pure_virtual_called (); | |
12962 | } | |
12963 | ||
983af33b | 12964 | static void |
f00aae0f KS |
12965 | base_breakpoint_create_sals_from_location |
12966 | (const struct event_location *location, | |
12967 | struct linespec_result *canonical, | |
12968 | enum bptype type_wanted) | |
983af33b SDJ |
12969 | { |
12970 | internal_error_pure_virtual_called (); | |
12971 | } | |
12972 | ||
12973 | static void | |
12974 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12975 | struct linespec_result *c, | |
983af33b | 12976 | char *cond_string, |
e7e0cddf | 12977 | char *extra_string, |
983af33b SDJ |
12978 | enum bptype type_wanted, |
12979 | enum bpdisp disposition, | |
12980 | int thread, | |
12981 | int task, int ignore_count, | |
12982 | const struct breakpoint_ops *o, | |
12983 | int from_tty, int enabled, | |
44f238bb | 12984 | int internal, unsigned flags) |
983af33b SDJ |
12985 | { |
12986 | internal_error_pure_virtual_called (); | |
12987 | } | |
12988 | ||
12989 | static void | |
f00aae0f KS |
12990 | base_breakpoint_decode_location (struct breakpoint *b, |
12991 | const struct event_location *location, | |
983af33b SDJ |
12992 | struct symtabs_and_lines *sals) |
12993 | { | |
12994 | internal_error_pure_virtual_called (); | |
12995 | } | |
12996 | ||
ab04a2af TT |
12997 | /* The default 'explains_signal' method. */ |
12998 | ||
47591c29 | 12999 | static int |
427cd150 | 13000 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13001 | { |
47591c29 | 13002 | return 1; |
ab04a2af TT |
13003 | } |
13004 | ||
9d6e6e84 HZ |
13005 | /* The default "after_condition_true" method. */ |
13006 | ||
13007 | static void | |
13008 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13009 | { | |
13010 | /* Nothing to do. */ | |
13011 | } | |
13012 | ||
ab04a2af | 13013 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13014 | { |
13015 | base_breakpoint_dtor, | |
13016 | base_breakpoint_allocate_location, | |
13017 | base_breakpoint_re_set, | |
13018 | base_breakpoint_insert_location, | |
13019 | base_breakpoint_remove_location, | |
13020 | base_breakpoint_breakpoint_hit, | |
13021 | base_breakpoint_check_status, | |
13022 | base_breakpoint_resources_needed, | |
13023 | base_breakpoint_works_in_software_mode, | |
13024 | base_breakpoint_print_it, | |
13025 | NULL, | |
13026 | base_breakpoint_print_one_detail, | |
13027 | base_breakpoint_print_mention, | |
983af33b | 13028 | base_breakpoint_print_recreate, |
5f700d83 | 13029 | base_breakpoint_create_sals_from_location, |
983af33b | 13030 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13031 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13032 | base_breakpoint_explains_signal, |
13033 | base_breakpoint_after_condition_true, | |
2060206e PA |
13034 | }; |
13035 | ||
13036 | /* Default breakpoint_ops methods. */ | |
13037 | ||
13038 | static void | |
348d480f PA |
13039 | bkpt_re_set (struct breakpoint *b) |
13040 | { | |
06edf0c0 | 13041 | /* FIXME: is this still reachable? */ |
f00aae0f | 13042 | if (event_location_empty_p (b->location)) |
06edf0c0 | 13043 | { |
f00aae0f | 13044 | /* Anything without a location can't be re-set. */ |
348d480f | 13045 | delete_breakpoint (b); |
06edf0c0 | 13046 | return; |
348d480f | 13047 | } |
06edf0c0 PA |
13048 | |
13049 | breakpoint_re_set_default (b); | |
348d480f PA |
13050 | } |
13051 | ||
2060206e | 13052 | static int |
348d480f PA |
13053 | bkpt_insert_location (struct bp_location *bl) |
13054 | { | |
13055 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13056 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13057 | else |
7c16b83e | 13058 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13059 | } |
13060 | ||
2060206e | 13061 | static int |
348d480f PA |
13062 | bkpt_remove_location (struct bp_location *bl) |
13063 | { | |
13064 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13065 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13066 | else | |
7c16b83e | 13067 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13068 | } |
13069 | ||
2060206e | 13070 | static int |
348d480f | 13071 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13072 | struct address_space *aspace, CORE_ADDR bp_addr, |
13073 | const struct target_waitstatus *ws) | |
348d480f | 13074 | { |
09ac7c10 | 13075 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13076 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13077 | return 0; |
13078 | ||
348d480f PA |
13079 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13080 | aspace, bp_addr)) | |
13081 | return 0; | |
13082 | ||
13083 | if (overlay_debugging /* unmapped overlay section */ | |
13084 | && section_is_overlay (bl->section) | |
13085 | && !section_is_mapped (bl->section)) | |
13086 | return 0; | |
13087 | ||
13088 | return 1; | |
13089 | } | |
13090 | ||
cd1608cc PA |
13091 | static int |
13092 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13093 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13094 | const struct target_waitstatus *ws) | |
13095 | { | |
13096 | if (dprintf_style == dprintf_style_agent | |
13097 | && target_can_run_breakpoint_commands ()) | |
13098 | { | |
13099 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13100 | for this address it must be for a breakpoint that happens to | |
13101 | be set at the same address. */ | |
13102 | return 0; | |
13103 | } | |
13104 | ||
13105 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13106 | } | |
13107 | ||
2060206e | 13108 | static int |
348d480f PA |
13109 | bkpt_resources_needed (const struct bp_location *bl) |
13110 | { | |
13111 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13112 | ||
13113 | return 1; | |
13114 | } | |
13115 | ||
2060206e | 13116 | static enum print_stop_action |
348d480f PA |
13117 | bkpt_print_it (bpstat bs) |
13118 | { | |
348d480f PA |
13119 | struct breakpoint *b; |
13120 | const struct bp_location *bl; | |
001c8c33 | 13121 | int bp_temp; |
79a45e25 | 13122 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13123 | |
13124 | gdb_assert (bs->bp_location_at != NULL); | |
13125 | ||
13126 | bl = bs->bp_location_at; | |
13127 | b = bs->breakpoint_at; | |
13128 | ||
001c8c33 PA |
13129 | bp_temp = b->disposition == disp_del; |
13130 | if (bl->address != bl->requested_address) | |
13131 | breakpoint_adjustment_warning (bl->requested_address, | |
13132 | bl->address, | |
13133 | b->number, 1); | |
13134 | annotate_breakpoint (b->number); | |
13135 | if (bp_temp) | |
13136 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13137 | else | |
13138 | ui_out_text (uiout, "\nBreakpoint "); | |
13139 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13140 | { |
001c8c33 PA |
13141 | ui_out_field_string (uiout, "reason", |
13142 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13143 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13144 | } |
001c8c33 PA |
13145 | ui_out_field_int (uiout, "bkptno", b->number); |
13146 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13147 | |
001c8c33 | 13148 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13149 | } |
13150 | ||
2060206e | 13151 | static void |
06edf0c0 PA |
13152 | bkpt_print_mention (struct breakpoint *b) |
13153 | { | |
79a45e25 | 13154 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13155 | return; |
13156 | ||
13157 | switch (b->type) | |
13158 | { | |
13159 | case bp_breakpoint: | |
13160 | case bp_gnu_ifunc_resolver: | |
13161 | if (b->disposition == disp_del) | |
13162 | printf_filtered (_("Temporary breakpoint")); | |
13163 | else | |
13164 | printf_filtered (_("Breakpoint")); | |
13165 | printf_filtered (_(" %d"), b->number); | |
13166 | if (b->type == bp_gnu_ifunc_resolver) | |
13167 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13168 | break; | |
13169 | case bp_hardware_breakpoint: | |
13170 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13171 | break; | |
e7e0cddf SS |
13172 | case bp_dprintf: |
13173 | printf_filtered (_("Dprintf %d"), b->number); | |
13174 | break; | |
06edf0c0 PA |
13175 | } |
13176 | ||
13177 | say_where (b); | |
13178 | } | |
13179 | ||
2060206e | 13180 | static void |
06edf0c0 PA |
13181 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13182 | { | |
13183 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13184 | fprintf_unfiltered (fp, "tbreak"); | |
13185 | else if (tp->type == bp_breakpoint) | |
13186 | fprintf_unfiltered (fp, "break"); | |
13187 | else if (tp->type == bp_hardware_breakpoint | |
13188 | && tp->disposition == disp_del) | |
13189 | fprintf_unfiltered (fp, "thbreak"); | |
13190 | else if (tp->type == bp_hardware_breakpoint) | |
13191 | fprintf_unfiltered (fp, "hbreak"); | |
13192 | else | |
13193 | internal_error (__FILE__, __LINE__, | |
13194 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13195 | ||
f00aae0f KS |
13196 | fprintf_unfiltered (fp, " %s", |
13197 | event_location_to_string (tp->location)); | |
13198 | ||
13199 | /* Print out extra_string if this breakpoint is pending. It might | |
13200 | contain, for example, conditions that were set by the user. */ | |
13201 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13202 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13203 | ||
dd11a36c | 13204 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13205 | } |
13206 | ||
983af33b | 13207 | static void |
f00aae0f KS |
13208 | bkpt_create_sals_from_location (const struct event_location *location, |
13209 | struct linespec_result *canonical, | |
13210 | enum bptype type_wanted) | |
983af33b | 13211 | { |
f00aae0f | 13212 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13213 | } |
13214 | ||
13215 | static void | |
13216 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13217 | struct linespec_result *canonical, | |
983af33b | 13218 | char *cond_string, |
e7e0cddf | 13219 | char *extra_string, |
983af33b SDJ |
13220 | enum bptype type_wanted, |
13221 | enum bpdisp disposition, | |
13222 | int thread, | |
13223 | int task, int ignore_count, | |
13224 | const struct breakpoint_ops *ops, | |
13225 | int from_tty, int enabled, | |
44f238bb | 13226 | int internal, unsigned flags) |
983af33b | 13227 | { |
023fa29b | 13228 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13229 | cond_string, extra_string, |
13230 | type_wanted, | |
983af33b SDJ |
13231 | disposition, thread, task, |
13232 | ignore_count, ops, from_tty, | |
44f238bb | 13233 | enabled, internal, flags); |
983af33b SDJ |
13234 | } |
13235 | ||
13236 | static void | |
f00aae0f KS |
13237 | bkpt_decode_location (struct breakpoint *b, |
13238 | const struct event_location *location, | |
983af33b SDJ |
13239 | struct symtabs_and_lines *sals) |
13240 | { | |
f00aae0f | 13241 | decode_location_default (b, location, sals); |
983af33b SDJ |
13242 | } |
13243 | ||
06edf0c0 PA |
13244 | /* Virtual table for internal breakpoints. */ |
13245 | ||
13246 | static void | |
13247 | internal_bkpt_re_set (struct breakpoint *b) | |
13248 | { | |
13249 | switch (b->type) | |
13250 | { | |
13251 | /* Delete overlay event and longjmp master breakpoints; they | |
13252 | will be reset later by breakpoint_re_set. */ | |
13253 | case bp_overlay_event: | |
13254 | case bp_longjmp_master: | |
13255 | case bp_std_terminate_master: | |
13256 | case bp_exception_master: | |
13257 | delete_breakpoint (b); | |
13258 | break; | |
13259 | ||
13260 | /* This breakpoint is special, it's set up when the inferior | |
13261 | starts and we really don't want to touch it. */ | |
13262 | case bp_shlib_event: | |
13263 | ||
13264 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13265 | it is set up, we do not want to touch it. */ | |
13266 | case bp_thread_event: | |
13267 | break; | |
13268 | } | |
13269 | } | |
13270 | ||
13271 | static void | |
13272 | internal_bkpt_check_status (bpstat bs) | |
13273 | { | |
a9b3a50f PA |
13274 | if (bs->breakpoint_at->type == bp_shlib_event) |
13275 | { | |
13276 | /* If requested, stop when the dynamic linker notifies GDB of | |
13277 | events. This allows the user to get control and place | |
13278 | breakpoints in initializer routines for dynamically loaded | |
13279 | objects (among other things). */ | |
13280 | bs->stop = stop_on_solib_events; | |
13281 | bs->print = stop_on_solib_events; | |
13282 | } | |
13283 | else | |
13284 | bs->stop = 0; | |
06edf0c0 PA |
13285 | } |
13286 | ||
13287 | static enum print_stop_action | |
13288 | internal_bkpt_print_it (bpstat bs) | |
13289 | { | |
06edf0c0 | 13290 | struct breakpoint *b; |
06edf0c0 | 13291 | |
06edf0c0 PA |
13292 | b = bs->breakpoint_at; |
13293 | ||
06edf0c0 PA |
13294 | switch (b->type) |
13295 | { | |
348d480f PA |
13296 | case bp_shlib_event: |
13297 | /* Did we stop because the user set the stop_on_solib_events | |
13298 | variable? (If so, we report this as a generic, "Stopped due | |
13299 | to shlib event" message.) */ | |
edcc5120 | 13300 | print_solib_event (0); |
348d480f PA |
13301 | break; |
13302 | ||
13303 | case bp_thread_event: | |
13304 | /* Not sure how we will get here. | |
13305 | GDB should not stop for these breakpoints. */ | |
13306 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13307 | break; |
13308 | ||
13309 | case bp_overlay_event: | |
13310 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13311 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13312 | break; |
13313 | ||
13314 | case bp_longjmp_master: | |
13315 | /* These should never be enabled. */ | |
13316 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13317 | break; |
13318 | ||
13319 | case bp_std_terminate_master: | |
13320 | /* These should never be enabled. */ | |
13321 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13322 | "gdb should not stop!\n")); | |
348d480f PA |
13323 | break; |
13324 | ||
13325 | case bp_exception_master: | |
13326 | /* These should never be enabled. */ | |
13327 | printf_filtered (_("Exception Master Breakpoint: " | |
13328 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13329 | break; |
13330 | } | |
13331 | ||
001c8c33 | 13332 | return PRINT_NOTHING; |
06edf0c0 PA |
13333 | } |
13334 | ||
13335 | static void | |
13336 | internal_bkpt_print_mention (struct breakpoint *b) | |
13337 | { | |
13338 | /* Nothing to mention. These breakpoints are internal. */ | |
13339 | } | |
13340 | ||
06edf0c0 PA |
13341 | /* Virtual table for momentary breakpoints */ |
13342 | ||
13343 | static void | |
13344 | momentary_bkpt_re_set (struct breakpoint *b) | |
13345 | { | |
13346 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13347 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13348 | Otherwise these should have been blown away via the cleanup chain |
13349 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13350 | } | |
13351 | ||
13352 | static void | |
13353 | momentary_bkpt_check_status (bpstat bs) | |
13354 | { | |
13355 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13356 | } | |
13357 | ||
13358 | static enum print_stop_action | |
13359 | momentary_bkpt_print_it (bpstat bs) | |
13360 | { | |
001c8c33 | 13361 | return PRINT_UNKNOWN; |
348d480f PA |
13362 | } |
13363 | ||
06edf0c0 PA |
13364 | static void |
13365 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13366 | { |
06edf0c0 | 13367 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13368 | } |
13369 | ||
e2e4d78b JK |
13370 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13371 | ||
13372 | It gets cleared already on the removal of the first one of such placed | |
13373 | breakpoints. This is OK as they get all removed altogether. */ | |
13374 | ||
13375 | static void | |
13376 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13377 | { | |
13378 | struct thread_info *tp = find_thread_id (self->thread); | |
13379 | ||
13380 | if (tp) | |
13381 | tp->initiating_frame = null_frame_id; | |
13382 | ||
13383 | momentary_breakpoint_ops.dtor (self); | |
13384 | } | |
13385 | ||
55aa24fb SDJ |
13386 | /* Specific methods for probe breakpoints. */ |
13387 | ||
13388 | static int | |
13389 | bkpt_probe_insert_location (struct bp_location *bl) | |
13390 | { | |
13391 | int v = bkpt_insert_location (bl); | |
13392 | ||
13393 | if (v == 0) | |
13394 | { | |
13395 | /* The insertion was successful, now let's set the probe's semaphore | |
13396 | if needed. */ | |
0ea5cda8 SDJ |
13397 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13398 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13399 | bl->probe.objfile, | |
13400 | bl->gdbarch); | |
55aa24fb SDJ |
13401 | } |
13402 | ||
13403 | return v; | |
13404 | } | |
13405 | ||
13406 | static int | |
13407 | bkpt_probe_remove_location (struct bp_location *bl) | |
13408 | { | |
13409 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13410 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13411 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13412 | bl->probe.objfile, | |
13413 | bl->gdbarch); | |
55aa24fb SDJ |
13414 | |
13415 | return bkpt_remove_location (bl); | |
13416 | } | |
13417 | ||
13418 | static void | |
f00aae0f | 13419 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13420 | struct linespec_result *canonical, |
f00aae0f | 13421 | enum bptype type_wanted) |
55aa24fb SDJ |
13422 | { |
13423 | struct linespec_sals lsal; | |
13424 | ||
f00aae0f KS |
13425 | lsal.sals = parse_probes (location, canonical); |
13426 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); | |
55aa24fb SDJ |
13427 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13428 | } | |
13429 | ||
13430 | static void | |
f00aae0f KS |
13431 | bkpt_probe_decode_location (struct breakpoint *b, |
13432 | const struct event_location *location, | |
55aa24fb SDJ |
13433 | struct symtabs_and_lines *sals) |
13434 | { | |
f00aae0f | 13435 | *sals = parse_probes (location, NULL); |
55aa24fb SDJ |
13436 | if (!sals->sals) |
13437 | error (_("probe not found")); | |
13438 | } | |
13439 | ||
348d480f | 13440 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13441 | |
348d480f PA |
13442 | static void |
13443 | tracepoint_re_set (struct breakpoint *b) | |
13444 | { | |
13445 | breakpoint_re_set_default (b); | |
13446 | } | |
876fa593 | 13447 | |
348d480f PA |
13448 | static int |
13449 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13450 | struct address_space *aspace, CORE_ADDR bp_addr, |
13451 | const struct target_waitstatus *ws) | |
348d480f PA |
13452 | { |
13453 | /* By definition, the inferior does not report stops at | |
13454 | tracepoints. */ | |
13455 | return 0; | |
74960c60 VP |
13456 | } |
13457 | ||
13458 | static void | |
348d480f PA |
13459 | tracepoint_print_one_detail (const struct breakpoint *self, |
13460 | struct ui_out *uiout) | |
74960c60 | 13461 | { |
d9b3f62e PA |
13462 | struct tracepoint *tp = (struct tracepoint *) self; |
13463 | if (tp->static_trace_marker_id) | |
348d480f PA |
13464 | { |
13465 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13466 | |
348d480f PA |
13467 | ui_out_text (uiout, "\tmarker id is "); |
13468 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13469 | tp->static_trace_marker_id); |
348d480f PA |
13470 | ui_out_text (uiout, "\n"); |
13471 | } | |
0d381245 VP |
13472 | } |
13473 | ||
a474d7c2 | 13474 | static void |
348d480f | 13475 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13476 | { |
79a45e25 | 13477 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13478 | return; |
cc59ec59 | 13479 | |
348d480f PA |
13480 | switch (b->type) |
13481 | { | |
13482 | case bp_tracepoint: | |
13483 | printf_filtered (_("Tracepoint")); | |
13484 | printf_filtered (_(" %d"), b->number); | |
13485 | break; | |
13486 | case bp_fast_tracepoint: | |
13487 | printf_filtered (_("Fast tracepoint")); | |
13488 | printf_filtered (_(" %d"), b->number); | |
13489 | break; | |
13490 | case bp_static_tracepoint: | |
13491 | printf_filtered (_("Static tracepoint")); | |
13492 | printf_filtered (_(" %d"), b->number); | |
13493 | break; | |
13494 | default: | |
13495 | internal_error (__FILE__, __LINE__, | |
13496 | _("unhandled tracepoint type %d"), (int) b->type); | |
13497 | } | |
13498 | ||
13499 | say_where (b); | |
a474d7c2 PA |
13500 | } |
13501 | ||
348d480f | 13502 | static void |
d9b3f62e | 13503 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13504 | { |
d9b3f62e PA |
13505 | struct tracepoint *tp = (struct tracepoint *) self; |
13506 | ||
13507 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13508 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13509 | if (self->type == bp_static_tracepoint) |
348d480f | 13510 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13511 | else if (self->type == bp_tracepoint) |
348d480f PA |
13512 | fprintf_unfiltered (fp, "trace"); |
13513 | else | |
13514 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13515 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13516 | |
f00aae0f KS |
13517 | fprintf_unfiltered (fp, " %s", |
13518 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13519 | print_recreate_thread (self, fp); |
13520 | ||
13521 | if (tp->pass_count) | |
13522 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13523 | } |
13524 | ||
983af33b | 13525 | static void |
f00aae0f KS |
13526 | tracepoint_create_sals_from_location (const struct event_location *location, |
13527 | struct linespec_result *canonical, | |
13528 | enum bptype type_wanted) | |
983af33b | 13529 | { |
f00aae0f | 13530 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13531 | } |
13532 | ||
13533 | static void | |
13534 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13535 | struct linespec_result *canonical, | |
983af33b | 13536 | char *cond_string, |
e7e0cddf | 13537 | char *extra_string, |
983af33b SDJ |
13538 | enum bptype type_wanted, |
13539 | enum bpdisp disposition, | |
13540 | int thread, | |
13541 | int task, int ignore_count, | |
13542 | const struct breakpoint_ops *ops, | |
13543 | int from_tty, int enabled, | |
44f238bb | 13544 | int internal, unsigned flags) |
983af33b | 13545 | { |
023fa29b | 13546 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13547 | cond_string, extra_string, |
13548 | type_wanted, | |
983af33b SDJ |
13549 | disposition, thread, task, |
13550 | ignore_count, ops, from_tty, | |
44f238bb | 13551 | enabled, internal, flags); |
983af33b SDJ |
13552 | } |
13553 | ||
13554 | static void | |
f00aae0f KS |
13555 | tracepoint_decode_location (struct breakpoint *b, |
13556 | const struct event_location *location, | |
983af33b SDJ |
13557 | struct symtabs_and_lines *sals) |
13558 | { | |
f00aae0f | 13559 | decode_location_default (b, location, sals); |
983af33b SDJ |
13560 | } |
13561 | ||
2060206e | 13562 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13563 | |
55aa24fb SDJ |
13564 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13565 | static probe. */ | |
13566 | ||
13567 | static void | |
f00aae0f KS |
13568 | tracepoint_probe_create_sals_from_location |
13569 | (const struct event_location *location, | |
13570 | struct linespec_result *canonical, | |
13571 | enum bptype type_wanted) | |
55aa24fb SDJ |
13572 | { |
13573 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13574 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13575 | } |
13576 | ||
13577 | static void | |
f00aae0f KS |
13578 | tracepoint_probe_decode_location (struct breakpoint *b, |
13579 | const struct event_location *location, | |
55aa24fb SDJ |
13580 | struct symtabs_and_lines *sals) |
13581 | { | |
13582 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13583 | bkpt_probe_decode_location (b, location, sals); |
55aa24fb SDJ |
13584 | } |
13585 | ||
13586 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13587 | ||
5c2b4418 HZ |
13588 | /* Dprintf breakpoint_ops methods. */ |
13589 | ||
13590 | static void | |
13591 | dprintf_re_set (struct breakpoint *b) | |
13592 | { | |
13593 | breakpoint_re_set_default (b); | |
13594 | ||
f00aae0f KS |
13595 | /* extra_string should never be non-NULL for dprintf. */ |
13596 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13597 | |
13598 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13599 | 2 - create a dprintf, which resolves fine. | |
13600 | 3 - disconnect from target 1 | |
13601 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13602 | ||
13603 | After steps #3/#4, you'll want the dprintf command list to | |
13604 | be updated, because target 1 and 2 may well return different | |
13605 | answers for target_can_run_breakpoint_commands(). | |
13606 | Given absence of finer grained resetting, we get to do | |
13607 | it all the time. */ | |
13608 | if (b->extra_string != NULL) | |
13609 | update_dprintf_command_list (b); | |
13610 | } | |
13611 | ||
2d9442cc HZ |
13612 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13613 | ||
13614 | static void | |
13615 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13616 | { | |
f00aae0f KS |
13617 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13618 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13619 | tp->extra_string); |
13620 | print_recreate_thread (tp, fp); | |
13621 | } | |
13622 | ||
9d6e6e84 HZ |
13623 | /* Implement the "after_condition_true" breakpoint_ops method for |
13624 | dprintf. | |
13625 | ||
13626 | dprintf's are implemented with regular commands in their command | |
13627 | list, but we run the commands here instead of before presenting the | |
13628 | stop to the user, as dprintf's don't actually cause a stop. This | |
13629 | also makes it so that the commands of multiple dprintfs at the same | |
13630 | address are all handled. */ | |
13631 | ||
13632 | static void | |
13633 | dprintf_after_condition_true (struct bpstats *bs) | |
13634 | { | |
13635 | struct cleanup *old_chain; | |
13636 | struct bpstats tmp_bs = { NULL }; | |
13637 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13638 | ||
13639 | /* dprintf's never cause a stop. This wasn't set in the | |
13640 | check_status hook instead because that would make the dprintf's | |
13641 | condition not be evaluated. */ | |
13642 | bs->stop = 0; | |
13643 | ||
13644 | /* Run the command list here. Take ownership of it instead of | |
13645 | copying. We never want these commands to run later in | |
13646 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13647 | be set at same address as this dprintf, or even if running the | |
13648 | commands here throws. */ | |
13649 | tmp_bs.commands = bs->commands; | |
13650 | bs->commands = NULL; | |
13651 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13652 | ||
13653 | bpstat_do_actions_1 (&tmp_bs_p); | |
13654 | ||
13655 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13656 | bpstat_do_actions_1 may return early without processing the whole | |
13657 | list. */ | |
13658 | do_cleanups (old_chain); | |
13659 | } | |
13660 | ||
983af33b SDJ |
13661 | /* The breakpoint_ops structure to be used on static tracepoints with |
13662 | markers (`-m'). */ | |
13663 | ||
13664 | static void | |
f00aae0f | 13665 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13666 | struct linespec_result *canonical, |
f00aae0f | 13667 | enum bptype type_wanted) |
983af33b SDJ |
13668 | { |
13669 | struct linespec_sals lsal; | |
f00aae0f KS |
13670 | const char *arg_start, *arg; |
13671 | char *str; | |
13672 | struct cleanup *cleanup; | |
983af33b | 13673 | |
f00aae0f KS |
13674 | arg = arg_start = get_linespec_location (location); |
13675 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13676 | |
f00aae0f KS |
13677 | str = savestring (arg_start, arg - arg_start); |
13678 | cleanup = make_cleanup (xfree, str); | |
13679 | canonical->location = new_linespec_location (&str); | |
13680 | do_cleanups (cleanup); | |
983af33b | 13681 | |
f00aae0f | 13682 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13683 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13684 | } | |
13685 | ||
13686 | static void | |
13687 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13688 | struct linespec_result *canonical, | |
983af33b | 13689 | char *cond_string, |
e7e0cddf | 13690 | char *extra_string, |
983af33b SDJ |
13691 | enum bptype type_wanted, |
13692 | enum bpdisp disposition, | |
13693 | int thread, | |
13694 | int task, int ignore_count, | |
13695 | const struct breakpoint_ops *ops, | |
13696 | int from_tty, int enabled, | |
44f238bb | 13697 | int internal, unsigned flags) |
983af33b SDJ |
13698 | { |
13699 | int i; | |
52d361e1 YQ |
13700 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13701 | canonical->sals, 0); | |
983af33b SDJ |
13702 | |
13703 | /* If the user is creating a static tracepoint by marker id | |
13704 | (strace -m MARKER_ID), then store the sals index, so that | |
13705 | breakpoint_re_set can try to match up which of the newly | |
13706 | found markers corresponds to this one, and, don't try to | |
13707 | expand multiple locations for each sal, given than SALS | |
13708 | already should contain all sals for MARKER_ID. */ | |
13709 | ||
13710 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13711 | { | |
13712 | struct symtabs_and_lines expanded; | |
13713 | struct tracepoint *tp; | |
13714 | struct cleanup *old_chain; | |
f00aae0f | 13715 | struct event_location *location; |
983af33b SDJ |
13716 | |
13717 | expanded.nelts = 1; | |
13718 | expanded.sals = &lsal->sals.sals[i]; | |
13719 | ||
f00aae0f KS |
13720 | location = copy_event_location (canonical->location); |
13721 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13722 | |
13723 | tp = XCNEW (struct tracepoint); | |
13724 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13725 | location, NULL, |
e7e0cddf SS |
13726 | cond_string, extra_string, |
13727 | type_wanted, disposition, | |
983af33b | 13728 | thread, task, ignore_count, ops, |
44f238bb | 13729 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13730 | canonical->special_display); |
13731 | /* Given that its possible to have multiple markers with | |
13732 | the same string id, if the user is creating a static | |
13733 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13734 | store the sals index, so that breakpoint_re_set can | |
13735 | try to match up which of the newly found markers | |
13736 | corresponds to this one */ | |
13737 | tp->static_trace_marker_id_idx = i; | |
13738 | ||
13739 | install_breakpoint (internal, &tp->base, 0); | |
13740 | ||
13741 | discard_cleanups (old_chain); | |
13742 | } | |
13743 | } | |
13744 | ||
13745 | static void | |
f00aae0f KS |
13746 | strace_marker_decode_location (struct breakpoint *b, |
13747 | const struct event_location *location, | |
983af33b SDJ |
13748 | struct symtabs_and_lines *sals) |
13749 | { | |
13750 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13751 | const char *s = get_linespec_location (location); |
983af33b | 13752 | |
f00aae0f | 13753 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13754 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13755 | { | |
13756 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13757 | sals->nelts = 1; | |
13758 | } | |
13759 | else | |
13760 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13761 | } | |
13762 | ||
13763 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13764 | ||
13765 | static int | |
13766 | strace_marker_p (struct breakpoint *b) | |
13767 | { | |
13768 | return b->ops == &strace_marker_breakpoint_ops; | |
13769 | } | |
13770 | ||
53a5351d | 13771 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13772 | structures. */ |
c906108c SS |
13773 | |
13774 | void | |
fba45db2 | 13775 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13776 | { |
52f0bd74 | 13777 | struct breakpoint *b; |
c906108c | 13778 | |
8a3fe4f8 | 13779 | gdb_assert (bpt != NULL); |
c906108c | 13780 | |
4a64f543 MS |
13781 | /* Has this bp already been deleted? This can happen because |
13782 | multiple lists can hold pointers to bp's. bpstat lists are | |
13783 | especial culprits. | |
13784 | ||
13785 | One example of this happening is a watchpoint's scope bp. When | |
13786 | the scope bp triggers, we notice that the watchpoint is out of | |
13787 | scope, and delete it. We also delete its scope bp. But the | |
13788 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13789 | That bpstat is then checked for auto-deleting bp's, which are | |
13790 | deleted. | |
13791 | ||
13792 | A real solution to this problem might involve reference counts in | |
13793 | bp's, and/or giving them pointers back to their referencing | |
13794 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13795 | storage when no more references were extent. A cheaper bandaid | |
13796 | was chosen. */ | |
c906108c SS |
13797 | if (bpt->type == bp_none) |
13798 | return; | |
13799 | ||
4a64f543 MS |
13800 | /* At least avoid this stale reference until the reference counting |
13801 | of breakpoints gets resolved. */ | |
d0fb5eae | 13802 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13803 | { |
d0fb5eae | 13804 | struct breakpoint *related; |
3a5c3e22 | 13805 | struct watchpoint *w; |
d0fb5eae JK |
13806 | |
13807 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13808 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13809 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13810 | w = (struct watchpoint *) bpt; |
13811 | else | |
13812 | w = NULL; | |
13813 | if (w != NULL) | |
13814 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13815 | |
13816 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13817 | for (related = bpt; related->related_breakpoint != bpt; | |
13818 | related = related->related_breakpoint); | |
13819 | related->related_breakpoint = bpt->related_breakpoint; | |
13820 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13821 | } |
13822 | ||
a9634178 TJB |
13823 | /* watch_command_1 creates a watchpoint but only sets its number if |
13824 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13825 | a problem in that process, we'll be asked to delete the half-created | |
13826 | watchpoint. In that case, don't announce the deletion. */ | |
13827 | if (bpt->number) | |
13828 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13829 | |
c906108c SS |
13830 | if (breakpoint_chain == bpt) |
13831 | breakpoint_chain = bpt->next; | |
13832 | ||
c906108c SS |
13833 | ALL_BREAKPOINTS (b) |
13834 | if (b->next == bpt) | |
c5aa993b JM |
13835 | { |
13836 | b->next = bpt->next; | |
13837 | break; | |
13838 | } | |
c906108c | 13839 | |
f431efe5 PA |
13840 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13841 | been freed. */ | |
13842 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13843 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13844 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13845 | commands are associated with the bpstat; if we remove it here, | |
13846 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13847 | event-top.c won't do anything, and temporary breakpoints with | |
13848 | commands won't work. */ | |
13849 | ||
13850 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13851 | ||
4a64f543 MS |
13852 | /* Now that breakpoint is removed from breakpoint list, update the |
13853 | global location list. This will remove locations that used to | |
13854 | belong to this breakpoint. Do this before freeing the breakpoint | |
13855 | itself, since remove_breakpoint looks at location's owner. It | |
13856 | might be better design to have location completely | |
13857 | self-contained, but it's not the case now. */ | |
44702360 | 13858 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13859 | |
348d480f | 13860 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13861 | /* On the chance that someone will soon try again to delete this |
13862 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13863 | bpt->type = bp_none; |
b8c9b27d | 13864 | xfree (bpt); |
c906108c SS |
13865 | } |
13866 | ||
4d6140d9 AC |
13867 | static void |
13868 | do_delete_breakpoint_cleanup (void *b) | |
13869 | { | |
9a3c8263 | 13870 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13871 | } |
13872 | ||
13873 | struct cleanup * | |
13874 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13875 | { | |
13876 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13877 | } | |
13878 | ||
51be5b68 PA |
13879 | /* Iterator function to call a user-provided callback function once |
13880 | for each of B and its related breakpoints. */ | |
13881 | ||
13882 | static void | |
13883 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13884 | void (*function) (struct breakpoint *, | |
13885 | void *), | |
13886 | void *data) | |
13887 | { | |
13888 | struct breakpoint *related; | |
13889 | ||
13890 | related = b; | |
13891 | do | |
13892 | { | |
13893 | struct breakpoint *next; | |
13894 | ||
13895 | /* FUNCTION may delete RELATED. */ | |
13896 | next = related->related_breakpoint; | |
13897 | ||
13898 | if (next == related) | |
13899 | { | |
13900 | /* RELATED is the last ring entry. */ | |
13901 | function (related, data); | |
13902 | ||
13903 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13904 | B. There's nothing left to do anyway, so just break | |
13905 | out. */ | |
13906 | break; | |
13907 | } | |
13908 | else | |
13909 | function (related, data); | |
13910 | ||
13911 | related = next; | |
13912 | } | |
13913 | while (related != b); | |
13914 | } | |
95a42b64 TT |
13915 | |
13916 | static void | |
13917 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13918 | { | |
13919 | delete_breakpoint (b); | |
13920 | } | |
13921 | ||
51be5b68 PA |
13922 | /* A callback for map_breakpoint_numbers that calls |
13923 | delete_breakpoint. */ | |
13924 | ||
13925 | static void | |
13926 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13927 | { | |
13928 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13929 | } | |
13930 | ||
c906108c | 13931 | void |
fba45db2 | 13932 | delete_command (char *arg, int from_tty) |
c906108c | 13933 | { |
35df4500 | 13934 | struct breakpoint *b, *b_tmp; |
c906108c | 13935 | |
ea9365bb TT |
13936 | dont_repeat (); |
13937 | ||
c906108c SS |
13938 | if (arg == 0) |
13939 | { | |
13940 | int breaks_to_delete = 0; | |
13941 | ||
46c6471b PA |
13942 | /* Delete all breakpoints if no argument. Do not delete |
13943 | internal breakpoints, these have to be deleted with an | |
13944 | explicit breakpoint number argument. */ | |
c5aa993b | 13945 | ALL_BREAKPOINTS (b) |
46c6471b | 13946 | if (user_breakpoint_p (b)) |
973d738b DJ |
13947 | { |
13948 | breaks_to_delete = 1; | |
13949 | break; | |
13950 | } | |
c906108c SS |
13951 | |
13952 | /* Ask user only if there are some breakpoints to delete. */ | |
13953 | if (!from_tty | |
e2e0b3e5 | 13954 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13955 | { |
35df4500 | 13956 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13957 | if (user_breakpoint_p (b)) |
c5aa993b | 13958 | delete_breakpoint (b); |
c906108c SS |
13959 | } |
13960 | } | |
13961 | else | |
51be5b68 | 13962 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13963 | } |
13964 | ||
0d381245 VP |
13965 | static int |
13966 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13967 | { |
0d381245 | 13968 | for (; loc; loc = loc->next) |
8645ff69 UW |
13969 | if (!loc->shlib_disabled |
13970 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13971 | return 0; |
13972 | return 1; | |
fe3f5fa8 VP |
13973 | } |
13974 | ||
776592bf DE |
13975 | /* Subroutine of update_breakpoint_locations to simplify it. |
13976 | Return non-zero if multiple fns in list LOC have the same name. | |
13977 | Null names are ignored. */ | |
13978 | ||
13979 | static int | |
13980 | ambiguous_names_p (struct bp_location *loc) | |
13981 | { | |
13982 | struct bp_location *l; | |
13983 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13984 | (int (*) (const void *, |
13985 | const void *)) streq, | |
776592bf DE |
13986 | NULL, xcalloc, xfree); |
13987 | ||
13988 | for (l = loc; l != NULL; l = l->next) | |
13989 | { | |
13990 | const char **slot; | |
13991 | const char *name = l->function_name; | |
13992 | ||
13993 | /* Allow for some names to be NULL, ignore them. */ | |
13994 | if (name == NULL) | |
13995 | continue; | |
13996 | ||
13997 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13998 | INSERT); | |
4a64f543 MS |
13999 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14000 | returns NULL. */ | |
776592bf DE |
14001 | if (*slot != NULL) |
14002 | { | |
14003 | htab_delete (htab); | |
14004 | return 1; | |
14005 | } | |
14006 | *slot = name; | |
14007 | } | |
14008 | ||
14009 | htab_delete (htab); | |
14010 | return 0; | |
14011 | } | |
14012 | ||
0fb4aa4b PA |
14013 | /* When symbols change, it probably means the sources changed as well, |
14014 | and it might mean the static tracepoint markers are no longer at | |
14015 | the same address or line numbers they used to be at last we | |
14016 | checked. Losing your static tracepoints whenever you rebuild is | |
14017 | undesirable. This function tries to resync/rematch gdb static | |
14018 | tracepoints with the markers on the target, for static tracepoints | |
14019 | that have not been set by marker id. Static tracepoint that have | |
14020 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14021 | The heuristic is: | |
14022 | ||
14023 | 1) For a tracepoint set at a specific address, look for a marker at | |
14024 | the old PC. If one is found there, assume to be the same marker. | |
14025 | If the name / string id of the marker found is different from the | |
14026 | previous known name, assume that means the user renamed the marker | |
14027 | in the sources, and output a warning. | |
14028 | ||
14029 | 2) For a tracepoint set at a given line number, look for a marker | |
14030 | at the new address of the old line number. If one is found there, | |
14031 | assume to be the same marker. If the name / string id of the | |
14032 | marker found is different from the previous known name, assume that | |
14033 | means the user renamed the marker in the sources, and output a | |
14034 | warning. | |
14035 | ||
14036 | 3) If a marker is no longer found at the same address or line, it | |
14037 | may mean the marker no longer exists. But it may also just mean | |
14038 | the code changed a bit. Maybe the user added a few lines of code | |
14039 | that made the marker move up or down (in line number terms). Ask | |
14040 | the target for info about the marker with the string id as we knew | |
14041 | it. If found, update line number and address in the matching | |
14042 | static tracepoint. This will get confused if there's more than one | |
14043 | marker with the same ID (possible in UST, although unadvised | |
14044 | precisely because it confuses tools). */ | |
14045 | ||
14046 | static struct symtab_and_line | |
14047 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14048 | { | |
d9b3f62e | 14049 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14050 | struct static_tracepoint_marker marker; |
14051 | CORE_ADDR pc; | |
0fb4aa4b PA |
14052 | |
14053 | pc = sal.pc; | |
14054 | if (sal.line) | |
14055 | find_line_pc (sal.symtab, sal.line, &pc); | |
14056 | ||
14057 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14058 | { | |
d9b3f62e | 14059 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14060 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14061 | b->number, | |
d9b3f62e | 14062 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14063 | |
d9b3f62e PA |
14064 | xfree (tp->static_trace_marker_id); |
14065 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14066 | release_static_tracepoint_marker (&marker); |
14067 | ||
14068 | return sal; | |
14069 | } | |
14070 | ||
14071 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14072 | by string ID. */ | |
14073 | if (!sal.explicit_pc | |
14074 | && sal.line != 0 | |
14075 | && sal.symtab != NULL | |
d9b3f62e | 14076 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14077 | { |
14078 | VEC(static_tracepoint_marker_p) *markers; | |
14079 | ||
14080 | markers | |
d9b3f62e | 14081 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14082 | |
14083 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14084 | { | |
80e1d417 | 14085 | struct symtab_and_line sal2; |
0fb4aa4b | 14086 | struct symbol *sym; |
80e1d417 | 14087 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14088 | struct ui_out *uiout = current_uiout; |
67994074 | 14089 | struct explicit_location explicit_loc; |
0fb4aa4b | 14090 | |
80e1d417 | 14091 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14092 | |
d9b3f62e | 14093 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14094 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14095 | |
14096 | warning (_("marker for static tracepoint %d (%s) not " | |
14097 | "found at previous line number"), | |
d9b3f62e | 14098 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14099 | |
80e1d417 | 14100 | init_sal (&sal2); |
0fb4aa4b | 14101 | |
80e1d417 | 14102 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14103 | |
80e1d417 AS |
14104 | sal2 = find_pc_line (tpmarker->address, 0); |
14105 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14106 | ui_out_text (uiout, "Now in "); |
14107 | if (sym) | |
14108 | { | |
14109 | ui_out_field_string (uiout, "func", | |
14110 | SYMBOL_PRINT_NAME (sym)); | |
14111 | ui_out_text (uiout, " at "); | |
14112 | } | |
05cba821 JK |
14113 | ui_out_field_string (uiout, "file", |
14114 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14115 | ui_out_text (uiout, ":"); |
14116 | ||
14117 | if (ui_out_is_mi_like_p (uiout)) | |
14118 | { | |
0b0865da | 14119 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14120 | |
f35a17b5 | 14121 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14122 | } |
14123 | ||
80e1d417 | 14124 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14125 | ui_out_text (uiout, "\n"); |
14126 | ||
80e1d417 | 14127 | b->loc->line_number = sal2.line; |
2f202fde | 14128 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14129 | |
f00aae0f | 14130 | delete_event_location (b->location); |
67994074 KS |
14131 | initialize_explicit_location (&explicit_loc); |
14132 | explicit_loc.source_filename | |
00e52e53 | 14133 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14134 | explicit_loc.line_offset.offset = b->loc->line_number; |
14135 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14136 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14137 | |
14138 | /* Might be nice to check if function changed, and warn if | |
14139 | so. */ | |
14140 | ||
80e1d417 | 14141 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14142 | } |
14143 | } | |
14144 | return sal; | |
14145 | } | |
14146 | ||
8d3788bd VP |
14147 | /* Returns 1 iff locations A and B are sufficiently same that |
14148 | we don't need to report breakpoint as changed. */ | |
14149 | ||
14150 | static int | |
14151 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14152 | { | |
14153 | while (a && b) | |
14154 | { | |
14155 | if (a->address != b->address) | |
14156 | return 0; | |
14157 | ||
14158 | if (a->shlib_disabled != b->shlib_disabled) | |
14159 | return 0; | |
14160 | ||
14161 | if (a->enabled != b->enabled) | |
14162 | return 0; | |
14163 | ||
14164 | a = a->next; | |
14165 | b = b->next; | |
14166 | } | |
14167 | ||
14168 | if ((a == NULL) != (b == NULL)) | |
14169 | return 0; | |
14170 | ||
14171 | return 1; | |
14172 | } | |
14173 | ||
f1310107 TJB |
14174 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14175 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14176 | a ranged breakpoint. */ | |
14177 | ||
0e30163f | 14178 | void |
0d381245 | 14179 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14180 | struct symtabs_and_lines sals, |
14181 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14182 | { |
14183 | int i; | |
0d381245 VP |
14184 | struct bp_location *existing_locations = b->loc; |
14185 | ||
f8eba3c6 TT |
14186 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14187 | { | |
14188 | /* Ranged breakpoints have only one start location and one end | |
14189 | location. */ | |
14190 | b->enable_state = bp_disabled; | |
44702360 | 14191 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14192 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14193 | "multiple locations found\n"), | |
14194 | b->number); | |
14195 | return; | |
14196 | } | |
f1310107 | 14197 | |
4a64f543 MS |
14198 | /* If there's no new locations, and all existing locations are |
14199 | pending, don't do anything. This optimizes the common case where | |
14200 | all locations are in the same shared library, that was unloaded. | |
14201 | We'd like to retain the location, so that when the library is | |
14202 | loaded again, we don't loose the enabled/disabled status of the | |
14203 | individual locations. */ | |
0d381245 | 14204 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14205 | return; |
14206 | ||
fe3f5fa8 VP |
14207 | b->loc = NULL; |
14208 | ||
0d381245 | 14209 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14210 | { |
f8eba3c6 TT |
14211 | struct bp_location *new_loc; |
14212 | ||
14213 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14214 | ||
14215 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14216 | |
0d381245 VP |
14217 | /* Reparse conditions, they might contain references to the |
14218 | old symtab. */ | |
14219 | if (b->cond_string != NULL) | |
14220 | { | |
bbc13ae3 | 14221 | const char *s; |
fe3f5fa8 | 14222 | |
0d381245 | 14223 | s = b->cond_string; |
492d29ea | 14224 | TRY |
0d381245 | 14225 | { |
1bb9788d TT |
14226 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14227 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14228 | 0); |
14229 | } | |
492d29ea | 14230 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14231 | { |
3e43a32a MS |
14232 | warning (_("failed to reevaluate condition " |
14233 | "for breakpoint %d: %s"), | |
0d381245 VP |
14234 | b->number, e.message); |
14235 | new_loc->enabled = 0; | |
14236 | } | |
492d29ea | 14237 | END_CATCH |
0d381245 | 14238 | } |
fe3f5fa8 | 14239 | |
f1310107 TJB |
14240 | if (sals_end.nelts) |
14241 | { | |
14242 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14243 | ||
14244 | new_loc->length = end - sals.sals[0].pc + 1; | |
14245 | } | |
0d381245 | 14246 | } |
fe3f5fa8 | 14247 | |
4a64f543 MS |
14248 | /* If possible, carry over 'disable' status from existing |
14249 | breakpoints. */ | |
0d381245 VP |
14250 | { |
14251 | struct bp_location *e = existing_locations; | |
776592bf DE |
14252 | /* If there are multiple breakpoints with the same function name, |
14253 | e.g. for inline functions, comparing function names won't work. | |
14254 | Instead compare pc addresses; this is just a heuristic as things | |
14255 | may have moved, but in practice it gives the correct answer | |
14256 | often enough until a better solution is found. */ | |
14257 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14258 | ||
0d381245 VP |
14259 | for (; e; e = e->next) |
14260 | { | |
14261 | if (!e->enabled && e->function_name) | |
14262 | { | |
14263 | struct bp_location *l = b->loc; | |
776592bf DE |
14264 | if (have_ambiguous_names) |
14265 | { | |
14266 | for (; l; l = l->next) | |
f1310107 | 14267 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14268 | { |
14269 | l->enabled = 0; | |
14270 | break; | |
14271 | } | |
14272 | } | |
14273 | else | |
14274 | { | |
14275 | for (; l; l = l->next) | |
14276 | if (l->function_name | |
14277 | && strcmp (e->function_name, l->function_name) == 0) | |
14278 | { | |
14279 | l->enabled = 0; | |
14280 | break; | |
14281 | } | |
14282 | } | |
0d381245 VP |
14283 | } |
14284 | } | |
14285 | } | |
fe3f5fa8 | 14286 | |
8d3788bd VP |
14287 | if (!locations_are_equal (existing_locations, b->loc)) |
14288 | observer_notify_breakpoint_modified (b); | |
14289 | ||
44702360 | 14290 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14291 | } |
14292 | ||
f00aae0f | 14293 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14294 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14295 | ||
14296 | static struct symtabs_and_lines | |
f00aae0f KS |
14297 | location_to_sals (struct breakpoint *b, struct event_location *location, |
14298 | int *found) | |
ef23e705 | 14299 | { |
02d20e4a | 14300 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14301 | struct gdb_exception exception = exception_none; |
ef23e705 | 14302 | |
983af33b | 14303 | gdb_assert (b->ops != NULL); |
ef23e705 | 14304 | |
492d29ea | 14305 | TRY |
ef23e705 | 14306 | { |
f00aae0f | 14307 | b->ops->decode_location (b, location, &sals); |
ef23e705 | 14308 | } |
492d29ea | 14309 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14310 | { |
14311 | int not_found_and_ok = 0; | |
492d29ea PA |
14312 | |
14313 | exception = e; | |
14314 | ||
ef23e705 TJB |
14315 | /* For pending breakpoints, it's expected that parsing will |
14316 | fail until the right shared library is loaded. User has | |
14317 | already told to create pending breakpoints and don't need | |
14318 | extra messages. If breakpoint is in bp_shlib_disabled | |
14319 | state, then user already saw the message about that | |
14320 | breakpoint being disabled, and don't want to see more | |
14321 | errors. */ | |
58438ac1 | 14322 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14323 | && (b->condition_not_parsed |
14324 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14325 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14326 | || b->enable_state == bp_disabled)) |
14327 | not_found_and_ok = 1; | |
14328 | ||
14329 | if (!not_found_and_ok) | |
14330 | { | |
14331 | /* We surely don't want to warn about the same breakpoint | |
14332 | 10 times. One solution, implemented here, is disable | |
14333 | the breakpoint on error. Another solution would be to | |
14334 | have separate 'warning emitted' flag. Since this | |
14335 | happens only when a binary has changed, I don't know | |
14336 | which approach is better. */ | |
14337 | b->enable_state = bp_disabled; | |
14338 | throw_exception (e); | |
14339 | } | |
14340 | } | |
492d29ea | 14341 | END_CATCH |
ef23e705 | 14342 | |
492d29ea | 14343 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14344 | { |
f8eba3c6 | 14345 | int i; |
ef23e705 | 14346 | |
f8eba3c6 TT |
14347 | for (i = 0; i < sals.nelts; ++i) |
14348 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14349 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14350 | { |
ed1d1739 KS |
14351 | char *cond_string, *extra_string; |
14352 | int thread, task; | |
ef23e705 | 14353 | |
f00aae0f | 14354 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14355 | &cond_string, &thread, &task, |
14356 | &extra_string); | |
f00aae0f | 14357 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14358 | if (cond_string) |
14359 | b->cond_string = cond_string; | |
14360 | b->thread = thread; | |
14361 | b->task = task; | |
e7e0cddf | 14362 | if (extra_string) |
f00aae0f KS |
14363 | { |
14364 | xfree (b->extra_string); | |
14365 | b->extra_string = extra_string; | |
14366 | } | |
ef23e705 TJB |
14367 | b->condition_not_parsed = 0; |
14368 | } | |
14369 | ||
983af33b | 14370 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14371 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14372 | |
58438ac1 TT |
14373 | *found = 1; |
14374 | } | |
14375 | else | |
14376 | *found = 0; | |
ef23e705 TJB |
14377 | |
14378 | return sals; | |
14379 | } | |
14380 | ||
348d480f PA |
14381 | /* The default re_set method, for typical hardware or software |
14382 | breakpoints. Reevaluate the breakpoint and recreate its | |
14383 | locations. */ | |
14384 | ||
14385 | static void | |
28010a5d | 14386 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14387 | { |
14388 | int found; | |
f1310107 | 14389 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14390 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14391 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 | 14392 | |
f00aae0f | 14393 | sals = location_to_sals (b, b->location, &found); |
ef23e705 TJB |
14394 | if (found) |
14395 | { | |
14396 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14397 | expanded = sals; |
ef23e705 TJB |
14398 | } |
14399 | ||
f00aae0f | 14400 | if (b->location_range_end != NULL) |
f1310107 | 14401 | { |
f00aae0f | 14402 | sals_end = location_to_sals (b, b->location_range_end, &found); |
f1310107 TJB |
14403 | if (found) |
14404 | { | |
14405 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14406 | expanded_end = sals_end; |
f1310107 TJB |
14407 | } |
14408 | } | |
14409 | ||
14410 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14411 | } |
14412 | ||
983af33b SDJ |
14413 | /* Default method for creating SALs from an address string. It basically |
14414 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14415 | ||
14416 | static void | |
f00aae0f KS |
14417 | create_sals_from_location_default (const struct event_location *location, |
14418 | struct linespec_result *canonical, | |
14419 | enum bptype type_wanted) | |
983af33b | 14420 | { |
f00aae0f | 14421 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14422 | } |
14423 | ||
14424 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14425 | function for the `create_breakpoints_sal' method of | |
14426 | breakpoint_ops. */ | |
14427 | ||
14428 | static void | |
14429 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14430 | struct linespec_result *canonical, | |
983af33b | 14431 | char *cond_string, |
e7e0cddf | 14432 | char *extra_string, |
983af33b SDJ |
14433 | enum bptype type_wanted, |
14434 | enum bpdisp disposition, | |
14435 | int thread, | |
14436 | int task, int ignore_count, | |
14437 | const struct breakpoint_ops *ops, | |
14438 | int from_tty, int enabled, | |
44f238bb | 14439 | int internal, unsigned flags) |
983af33b SDJ |
14440 | { |
14441 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14442 | extra_string, |
983af33b SDJ |
14443 | type_wanted, disposition, |
14444 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14445 | enabled, internal, flags); |
983af33b SDJ |
14446 | } |
14447 | ||
14448 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14449 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14450 | |
14451 | static void | |
f00aae0f KS |
14452 | decode_location_default (struct breakpoint *b, |
14453 | const struct event_location *location, | |
983af33b SDJ |
14454 | struct symtabs_and_lines *sals) |
14455 | { | |
14456 | struct linespec_result canonical; | |
14457 | ||
14458 | init_linespec_result (&canonical); | |
f00aae0f | 14459 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, |
983af33b SDJ |
14460 | (struct symtab *) NULL, 0, |
14461 | &canonical, multiple_symbols_all, | |
14462 | b->filter); | |
14463 | ||
14464 | /* We should get 0 or 1 resulting SALs. */ | |
14465 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14466 | ||
14467 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14468 | { | |
14469 | struct linespec_sals *lsal; | |
14470 | ||
14471 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14472 | *sals = lsal->sals; | |
14473 | /* Arrange it so the destructor does not free the | |
14474 | contents. */ | |
14475 | lsal->sals.sals = NULL; | |
14476 | } | |
14477 | ||
14478 | destroy_linespec_result (&canonical); | |
14479 | } | |
14480 | ||
28010a5d PA |
14481 | /* Prepare the global context for a re-set of breakpoint B. */ |
14482 | ||
14483 | static struct cleanup * | |
14484 | prepare_re_set_context (struct breakpoint *b) | |
14485 | { | |
14486 | struct cleanup *cleanups; | |
14487 | ||
14488 | input_radix = b->input_radix; | |
14489 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14490 | if (b->pspace != NULL) |
14491 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14492 | set_language (b->language); |
14493 | ||
14494 | return cleanups; | |
ef23e705 TJB |
14495 | } |
14496 | ||
c906108c SS |
14497 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14498 | The value we return ends up being the return value from catch_errors. | |
14499 | Unused in this case. */ | |
14500 | ||
14501 | static int | |
4efb68b1 | 14502 | breakpoint_re_set_one (void *bint) |
c906108c | 14503 | { |
4a64f543 | 14504 | /* Get past catch_errs. */ |
53a5351d | 14505 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14506 | struct cleanup *cleanups; |
c906108c | 14507 | |
348d480f PA |
14508 | cleanups = prepare_re_set_context (b); |
14509 | b->ops->re_set (b); | |
14510 | do_cleanups (cleanups); | |
c906108c SS |
14511 | return 0; |
14512 | } | |
14513 | ||
69de3c6a | 14514 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14515 | void |
69de3c6a | 14516 | breakpoint_re_set (void) |
c906108c | 14517 | { |
35df4500 | 14518 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14519 | enum language save_language; |
14520 | int save_input_radix; | |
6c95b8df | 14521 | struct cleanup *old_chain; |
c5aa993b | 14522 | |
c906108c SS |
14523 | save_language = current_language->la_language; |
14524 | save_input_radix = input_radix; | |
6c95b8df PA |
14525 | old_chain = save_current_program_space (); |
14526 | ||
35df4500 | 14527 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14528 | { |
4a64f543 | 14529 | /* Format possible error msg. */ |
fe3f5fa8 | 14530 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14531 | b->number); |
14532 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14533 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14534 | do_cleanups (cleanups); |
c5aa993b | 14535 | } |
c906108c SS |
14536 | set_language (save_language); |
14537 | input_radix = save_input_radix; | |
e62c965a | 14538 | |
0756c555 | 14539 | jit_breakpoint_re_set (); |
4efc6507 | 14540 | |
6c95b8df PA |
14541 | do_cleanups (old_chain); |
14542 | ||
af02033e PP |
14543 | create_overlay_event_breakpoint (); |
14544 | create_longjmp_master_breakpoint (); | |
14545 | create_std_terminate_master_breakpoint (); | |
186c406b | 14546 | create_exception_master_breakpoint (); |
c906108c SS |
14547 | } |
14548 | \f | |
c906108c SS |
14549 | /* Reset the thread number of this breakpoint: |
14550 | ||
14551 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14552 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14553 | void |
fba45db2 | 14554 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14555 | { |
14556 | if (b->thread != -1) | |
14557 | { | |
39f77062 KB |
14558 | if (in_thread_list (inferior_ptid)) |
14559 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14560 | |
14561 | /* We're being called after following a fork. The new fork is | |
14562 | selected as current, and unless this was a vfork will have a | |
14563 | different program space from the original thread. Reset that | |
14564 | as well. */ | |
14565 | b->loc->pspace = current_program_space; | |
c906108c SS |
14566 | } |
14567 | } | |
14568 | ||
03ac34d5 MS |
14569 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14570 | If from_tty is nonzero, it prints a message to that effect, | |
14571 | which ends with a period (no newline). */ | |
14572 | ||
c906108c | 14573 | void |
fba45db2 | 14574 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14575 | { |
52f0bd74 | 14576 | struct breakpoint *b; |
c906108c SS |
14577 | |
14578 | if (count < 0) | |
14579 | count = 0; | |
14580 | ||
14581 | ALL_BREAKPOINTS (b) | |
14582 | if (b->number == bptnum) | |
c5aa993b | 14583 | { |
d77f58be SS |
14584 | if (is_tracepoint (b)) |
14585 | { | |
14586 | if (from_tty && count != 0) | |
14587 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14588 | bptnum); | |
14589 | return; | |
14590 | } | |
14591 | ||
c5aa993b | 14592 | b->ignore_count = count; |
221ea385 KS |
14593 | if (from_tty) |
14594 | { | |
14595 | if (count == 0) | |
3e43a32a MS |
14596 | printf_filtered (_("Will stop next time " |
14597 | "breakpoint %d is reached."), | |
221ea385 KS |
14598 | bptnum); |
14599 | else if (count == 1) | |
a3f17187 | 14600 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14601 | bptnum); |
14602 | else | |
3e43a32a MS |
14603 | printf_filtered (_("Will ignore next %d " |
14604 | "crossings of breakpoint %d."), | |
221ea385 KS |
14605 | count, bptnum); |
14606 | } | |
8d3788bd | 14607 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14608 | return; |
14609 | } | |
c906108c | 14610 | |
8a3fe4f8 | 14611 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14612 | } |
14613 | ||
c906108c SS |
14614 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14615 | ||
14616 | static void | |
fba45db2 | 14617 | ignore_command (char *args, int from_tty) |
c906108c SS |
14618 | { |
14619 | char *p = args; | |
52f0bd74 | 14620 | int num; |
c906108c SS |
14621 | |
14622 | if (p == 0) | |
e2e0b3e5 | 14623 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14624 | |
c906108c | 14625 | num = get_number (&p); |
5c44784c | 14626 | if (num == 0) |
8a3fe4f8 | 14627 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14628 | if (*p == 0) |
8a3fe4f8 | 14629 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14630 | |
14631 | set_ignore_count (num, | |
14632 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14633 | from_tty); | |
221ea385 KS |
14634 | if (from_tty) |
14635 | printf_filtered ("\n"); | |
c906108c SS |
14636 | } |
14637 | \f | |
14638 | /* Call FUNCTION on each of the breakpoints | |
14639 | whose numbers are given in ARGS. */ | |
14640 | ||
14641 | static void | |
95a42b64 TT |
14642 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14643 | void *), | |
14644 | void *data) | |
c906108c | 14645 | { |
52f0bd74 AC |
14646 | int num; |
14647 | struct breakpoint *b, *tmp; | |
11cf8741 | 14648 | int match; |
197f0a60 | 14649 | struct get_number_or_range_state state; |
c906108c | 14650 | |
b9d61307 | 14651 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14652 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14653 | |
197f0a60 TT |
14654 | init_number_or_range (&state, args); |
14655 | ||
14656 | while (!state.finished) | |
c906108c | 14657 | { |
e799154c | 14658 | const char *p = state.string; |
197f0a60 | 14659 | |
11cf8741 | 14660 | match = 0; |
c5aa993b | 14661 | |
197f0a60 | 14662 | num = get_number_or_range (&state); |
5c44784c | 14663 | if (num == 0) |
c5aa993b | 14664 | { |
8a3fe4f8 | 14665 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14666 | } |
14667 | else | |
14668 | { | |
14669 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14670 | if (b->number == num) | |
14671 | { | |
11cf8741 | 14672 | match = 1; |
cdac0397 | 14673 | function (b, data); |
11cf8741 | 14674 | break; |
5c44784c | 14675 | } |
11cf8741 | 14676 | if (match == 0) |
a3f17187 | 14677 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14678 | } |
c906108c SS |
14679 | } |
14680 | } | |
14681 | ||
0d381245 VP |
14682 | static struct bp_location * |
14683 | find_location_by_number (char *number) | |
14684 | { | |
14685 | char *dot = strchr (number, '.'); | |
14686 | char *p1; | |
14687 | int bp_num; | |
14688 | int loc_num; | |
14689 | struct breakpoint *b; | |
14690 | struct bp_location *loc; | |
14691 | ||
14692 | *dot = '\0'; | |
14693 | ||
14694 | p1 = number; | |
197f0a60 | 14695 | bp_num = get_number (&p1); |
0d381245 VP |
14696 | if (bp_num == 0) |
14697 | error (_("Bad breakpoint number '%s'"), number); | |
14698 | ||
14699 | ALL_BREAKPOINTS (b) | |
14700 | if (b->number == bp_num) | |
14701 | { | |
14702 | break; | |
14703 | } | |
14704 | ||
14705 | if (!b || b->number != bp_num) | |
14706 | error (_("Bad breakpoint number '%s'"), number); | |
14707 | ||
14708 | p1 = dot+1; | |
197f0a60 | 14709 | loc_num = get_number (&p1); |
0d381245 VP |
14710 | if (loc_num == 0) |
14711 | error (_("Bad breakpoint location number '%s'"), number); | |
14712 | ||
14713 | --loc_num; | |
14714 | loc = b->loc; | |
14715 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14716 | ; | |
14717 | if (!loc) | |
14718 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14719 | ||
14720 | return loc; | |
14721 | } | |
14722 | ||
14723 | ||
1900040c MS |
14724 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14725 | If from_tty is nonzero, it prints a message to that effect, | |
14726 | which ends with a period (no newline). */ | |
14727 | ||
c906108c | 14728 | void |
fba45db2 | 14729 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14730 | { |
14731 | /* Never disable a watchpoint scope breakpoint; we want to | |
14732 | hit them when we leave scope so we can delete both the | |
14733 | watchpoint and its scope breakpoint at that time. */ | |
14734 | if (bpt->type == bp_watchpoint_scope) | |
14735 | return; | |
14736 | ||
b5de0fa7 | 14737 | bpt->enable_state = bp_disabled; |
c906108c | 14738 | |
b775012e LM |
14739 | /* Mark breakpoint locations modified. */ |
14740 | mark_breakpoint_modified (bpt); | |
14741 | ||
d248b706 KY |
14742 | if (target_supports_enable_disable_tracepoint () |
14743 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14744 | { | |
14745 | struct bp_location *location; | |
14746 | ||
14747 | for (location = bpt->loc; location; location = location->next) | |
14748 | target_disable_tracepoint (location); | |
14749 | } | |
14750 | ||
44702360 | 14751 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14752 | |
8d3788bd | 14753 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14754 | } |
14755 | ||
51be5b68 PA |
14756 | /* A callback for iterate_over_related_breakpoints. */ |
14757 | ||
14758 | static void | |
14759 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14760 | { | |
14761 | disable_breakpoint (b); | |
14762 | } | |
14763 | ||
95a42b64 TT |
14764 | /* A callback for map_breakpoint_numbers that calls |
14765 | disable_breakpoint. */ | |
14766 | ||
14767 | static void | |
14768 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14769 | { | |
51be5b68 | 14770 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14771 | } |
14772 | ||
c906108c | 14773 | static void |
fba45db2 | 14774 | disable_command (char *args, int from_tty) |
c906108c | 14775 | { |
c906108c | 14776 | if (args == 0) |
46c6471b PA |
14777 | { |
14778 | struct breakpoint *bpt; | |
14779 | ||
14780 | ALL_BREAKPOINTS (bpt) | |
14781 | if (user_breakpoint_p (bpt)) | |
14782 | disable_breakpoint (bpt); | |
14783 | } | |
9eaabc75 | 14784 | else |
0d381245 | 14785 | { |
9eaabc75 MW |
14786 | char *num = extract_arg (&args); |
14787 | ||
14788 | while (num) | |
d248b706 | 14789 | { |
9eaabc75 | 14790 | if (strchr (num, '.')) |
b775012e | 14791 | { |
9eaabc75 MW |
14792 | struct bp_location *loc = find_location_by_number (num); |
14793 | ||
14794 | if (loc) | |
14795 | { | |
14796 | if (loc->enabled) | |
14797 | { | |
14798 | loc->enabled = 0; | |
14799 | mark_breakpoint_location_modified (loc); | |
14800 | } | |
14801 | if (target_supports_enable_disable_tracepoint () | |
14802 | && current_trace_status ()->running && loc->owner | |
14803 | && is_tracepoint (loc->owner)) | |
14804 | target_disable_tracepoint (loc); | |
14805 | } | |
44702360 | 14806 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14807 | } |
9eaabc75 MW |
14808 | else |
14809 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14810 | num = extract_arg (&args); | |
d248b706 | 14811 | } |
0d381245 | 14812 | } |
c906108c SS |
14813 | } |
14814 | ||
14815 | static void | |
816338b5 SS |
14816 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14817 | int count) | |
c906108c | 14818 | { |
afe38095 | 14819 | int target_resources_ok; |
c906108c SS |
14820 | |
14821 | if (bpt->type == bp_hardware_breakpoint) | |
14822 | { | |
14823 | int i; | |
c5aa993b | 14824 | i = hw_breakpoint_used_count (); |
53a5351d | 14825 | target_resources_ok = |
d92524f1 | 14826 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14827 | i + 1, 0); |
c906108c | 14828 | if (target_resources_ok == 0) |
8a3fe4f8 | 14829 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14830 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14831 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14832 | } |
14833 | ||
cc60f2e3 | 14834 | if (is_watchpoint (bpt)) |
c906108c | 14835 | { |
d07205c2 | 14836 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14837 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14838 | |
492d29ea | 14839 | TRY |
c906108c | 14840 | { |
3a5c3e22 PA |
14841 | struct watchpoint *w = (struct watchpoint *) bpt; |
14842 | ||
1e718ff1 TJB |
14843 | orig_enable_state = bpt->enable_state; |
14844 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14845 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14846 | } |
492d29ea | 14847 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14848 | { |
1e718ff1 | 14849 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14850 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14851 | bpt->number); | |
14852 | return; | |
c5aa993b | 14853 | } |
492d29ea | 14854 | END_CATCH |
c906108c | 14855 | } |
0101ce28 | 14856 | |
b775012e LM |
14857 | bpt->enable_state = bp_enabled; |
14858 | ||
14859 | /* Mark breakpoint locations modified. */ | |
14860 | mark_breakpoint_modified (bpt); | |
14861 | ||
d248b706 KY |
14862 | if (target_supports_enable_disable_tracepoint () |
14863 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14864 | { | |
14865 | struct bp_location *location; | |
14866 | ||
14867 | for (location = bpt->loc; location; location = location->next) | |
14868 | target_enable_tracepoint (location); | |
14869 | } | |
14870 | ||
b4c291bb | 14871 | bpt->disposition = disposition; |
816338b5 | 14872 | bpt->enable_count = count; |
44702360 | 14873 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14874 | |
8d3788bd | 14875 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14876 | } |
14877 | ||
fe3f5fa8 | 14878 | |
c906108c | 14879 | void |
fba45db2 | 14880 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14881 | { |
816338b5 | 14882 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14883 | } |
14884 | ||
14885 | static void | |
14886 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14887 | { | |
14888 | enable_breakpoint (bpt); | |
c906108c SS |
14889 | } |
14890 | ||
95a42b64 TT |
14891 | /* A callback for map_breakpoint_numbers that calls |
14892 | enable_breakpoint. */ | |
14893 | ||
14894 | static void | |
14895 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14896 | { | |
51be5b68 | 14897 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14898 | } |
14899 | ||
c906108c SS |
14900 | /* The enable command enables the specified breakpoints (or all defined |
14901 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14902 | in stopping the inferior. */ |
c906108c | 14903 | |
c906108c | 14904 | static void |
fba45db2 | 14905 | enable_command (char *args, int from_tty) |
c906108c | 14906 | { |
c906108c | 14907 | if (args == 0) |
46c6471b PA |
14908 | { |
14909 | struct breakpoint *bpt; | |
14910 | ||
14911 | ALL_BREAKPOINTS (bpt) | |
14912 | if (user_breakpoint_p (bpt)) | |
14913 | enable_breakpoint (bpt); | |
14914 | } | |
9eaabc75 | 14915 | else |
0d381245 | 14916 | { |
9eaabc75 MW |
14917 | char *num = extract_arg (&args); |
14918 | ||
14919 | while (num) | |
d248b706 | 14920 | { |
9eaabc75 | 14921 | if (strchr (num, '.')) |
b775012e | 14922 | { |
9eaabc75 MW |
14923 | struct bp_location *loc = find_location_by_number (num); |
14924 | ||
14925 | if (loc) | |
14926 | { | |
14927 | if (!loc->enabled) | |
14928 | { | |
14929 | loc->enabled = 1; | |
14930 | mark_breakpoint_location_modified (loc); | |
14931 | } | |
14932 | if (target_supports_enable_disable_tracepoint () | |
14933 | && current_trace_status ()->running && loc->owner | |
14934 | && is_tracepoint (loc->owner)) | |
14935 | target_enable_tracepoint (loc); | |
14936 | } | |
44702360 | 14937 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14938 | } |
9eaabc75 MW |
14939 | else |
14940 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14941 | num = extract_arg (&args); | |
d248b706 | 14942 | } |
0d381245 | 14943 | } |
c906108c SS |
14944 | } |
14945 | ||
816338b5 SS |
14946 | /* This struct packages up disposition data for application to multiple |
14947 | breakpoints. */ | |
14948 | ||
14949 | struct disp_data | |
14950 | { | |
14951 | enum bpdisp disp; | |
14952 | int count; | |
14953 | }; | |
14954 | ||
c906108c | 14955 | static void |
51be5b68 PA |
14956 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14957 | { | |
816338b5 | 14958 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14959 | |
816338b5 | 14960 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14961 | } |
14962 | ||
14963 | static void | |
14964 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14965 | { |
816338b5 | 14966 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14967 | |
14968 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14969 | } |
14970 | ||
c906108c | 14971 | static void |
fba45db2 | 14972 | enable_once_command (char *args, int from_tty) |
c906108c | 14973 | { |
51be5b68 | 14974 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14975 | } |
14976 | ||
816338b5 SS |
14977 | static void |
14978 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14979 | { | |
14980 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14981 | ||
14982 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14983 | } | |
14984 | ||
14985 | static void | |
14986 | enable_count_command (char *args, int from_tty) | |
14987 | { | |
b9d61307 SM |
14988 | int count; |
14989 | ||
14990 | if (args == NULL) | |
14991 | error_no_arg (_("hit count")); | |
14992 | ||
14993 | count = get_number (&args); | |
816338b5 SS |
14994 | |
14995 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14996 | } | |
14997 | ||
c906108c | 14998 | static void |
51be5b68 | 14999 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15000 | { |
816338b5 | 15001 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15002 | |
15003 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15004 | } |
15005 | ||
c906108c | 15006 | static void |
fba45db2 | 15007 | enable_delete_command (char *args, int from_tty) |
c906108c | 15008 | { |
51be5b68 | 15009 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15010 | } |
15011 | \f | |
fa8d40ab JJ |
15012 | static void |
15013 | set_breakpoint_cmd (char *args, int from_tty) | |
15014 | { | |
15015 | } | |
15016 | ||
15017 | static void | |
15018 | show_breakpoint_cmd (char *args, int from_tty) | |
15019 | { | |
15020 | } | |
15021 | ||
1f3b5d1b PP |
15022 | /* Invalidate last known value of any hardware watchpoint if |
15023 | the memory which that value represents has been written to by | |
15024 | GDB itself. */ | |
15025 | ||
15026 | static void | |
8de0566d YQ |
15027 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15028 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15029 | const bfd_byte *data) |
15030 | { | |
15031 | struct breakpoint *bp; | |
15032 | ||
15033 | ALL_BREAKPOINTS (bp) | |
15034 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15035 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15036 | { |
3a5c3e22 | 15037 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15038 | |
3a5c3e22 PA |
15039 | if (wp->val_valid && wp->val) |
15040 | { | |
15041 | struct bp_location *loc; | |
15042 | ||
15043 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15044 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15045 | && loc->address + loc->length > addr | |
15046 | && addr + len > loc->address) | |
15047 | { | |
15048 | value_free (wp->val); | |
15049 | wp->val = NULL; | |
15050 | wp->val_valid = 0; | |
15051 | } | |
15052 | } | |
1f3b5d1b PP |
15053 | } |
15054 | } | |
15055 | ||
8181d85f DJ |
15056 | /* Create and insert a breakpoint for software single step. */ |
15057 | ||
15058 | void | |
6c95b8df | 15059 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15060 | struct address_space *aspace, |
15061 | CORE_ADDR next_pc) | |
8181d85f | 15062 | { |
7c16b83e PA |
15063 | struct thread_info *tp = inferior_thread (); |
15064 | struct symtab_and_line sal; | |
15065 | CORE_ADDR pc = next_pc; | |
8181d85f | 15066 | |
34b7e8a6 PA |
15067 | if (tp->control.single_step_breakpoints == NULL) |
15068 | { | |
15069 | tp->control.single_step_breakpoints | |
15070 | = new_single_step_breakpoint (tp->num, gdbarch); | |
15071 | } | |
8181d85f | 15072 | |
7c16b83e PA |
15073 | sal = find_pc_line (pc, 0); |
15074 | sal.pc = pc; | |
15075 | sal.section = find_pc_overlay (pc); | |
15076 | sal.explicit_pc = 1; | |
34b7e8a6 | 15077 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15078 | |
7c16b83e | 15079 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15080 | } |
15081 | ||
34b7e8a6 | 15082 | /* See breakpoint.h. */ |
f02253f1 HZ |
15083 | |
15084 | int | |
7c16b83e PA |
15085 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15086 | struct address_space *aspace, | |
15087 | CORE_ADDR pc) | |
1aafd4da | 15088 | { |
7c16b83e | 15089 | struct bp_location *loc; |
1aafd4da | 15090 | |
7c16b83e PA |
15091 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15092 | if (loc->inserted | |
15093 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15094 | return 1; | |
1aafd4da | 15095 | |
7c16b83e | 15096 | return 0; |
ef370185 JB |
15097 | } |
15098 | ||
15099 | /* Check whether a software single-step breakpoint is inserted at | |
15100 | PC. */ | |
15101 | ||
15102 | int | |
15103 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15104 | CORE_ADDR pc) | |
15105 | { | |
34b7e8a6 PA |
15106 | struct breakpoint *bpt; |
15107 | ||
15108 | ALL_BREAKPOINTS (bpt) | |
15109 | { | |
15110 | if (bpt->type == bp_single_step | |
15111 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15112 | return 1; | |
15113 | } | |
15114 | return 0; | |
1aafd4da UW |
15115 | } |
15116 | ||
1042e4c0 SS |
15117 | /* Tracepoint-specific operations. */ |
15118 | ||
15119 | /* Set tracepoint count to NUM. */ | |
15120 | static void | |
15121 | set_tracepoint_count (int num) | |
15122 | { | |
15123 | tracepoint_count = num; | |
4fa62494 | 15124 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15125 | } |
15126 | ||
70221824 | 15127 | static void |
1042e4c0 SS |
15128 | trace_command (char *arg, int from_tty) |
15129 | { | |
55aa24fb | 15130 | struct breakpoint_ops *ops; |
f00aae0f KS |
15131 | struct event_location *location; |
15132 | struct cleanup *back_to; | |
55aa24fb | 15133 | |
f00aae0f KS |
15134 | location = string_to_event_location (&arg, current_language); |
15135 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15136 | if (location != NULL |
15137 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15138 | ops = &tracepoint_probe_breakpoint_ops; |
15139 | else | |
15140 | ops = &tracepoint_breakpoint_ops; | |
15141 | ||
558a9d82 | 15142 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15143 | location, |
15144 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15145 | 0 /* tempflag */, |
15146 | bp_tracepoint /* type_wanted */, | |
15147 | 0 /* Ignore count */, | |
15148 | pending_break_support, | |
15149 | ops, | |
15150 | from_tty, | |
15151 | 1 /* enabled */, | |
15152 | 0 /* internal */, 0); | |
f00aae0f | 15153 | do_cleanups (back_to); |
1042e4c0 SS |
15154 | } |
15155 | ||
70221824 | 15156 | static void |
7a697b8d SS |
15157 | ftrace_command (char *arg, int from_tty) |
15158 | { | |
f00aae0f KS |
15159 | struct event_location *location; |
15160 | struct cleanup *back_to; | |
15161 | ||
15162 | location = string_to_event_location (&arg, current_language); | |
15163 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15164 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15165 | location, |
15166 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15167 | 0 /* tempflag */, |
15168 | bp_fast_tracepoint /* type_wanted */, | |
15169 | 0 /* Ignore count */, | |
15170 | pending_break_support, | |
15171 | &tracepoint_breakpoint_ops, | |
15172 | from_tty, | |
15173 | 1 /* enabled */, | |
15174 | 0 /* internal */, 0); | |
f00aae0f | 15175 | do_cleanups (back_to); |
0fb4aa4b PA |
15176 | } |
15177 | ||
15178 | /* strace command implementation. Creates a static tracepoint. */ | |
15179 | ||
70221824 | 15180 | static void |
0fb4aa4b PA |
15181 | strace_command (char *arg, int from_tty) |
15182 | { | |
983af33b | 15183 | struct breakpoint_ops *ops; |
f00aae0f KS |
15184 | struct event_location *location; |
15185 | struct cleanup *back_to; | |
983af33b SDJ |
15186 | |
15187 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15188 | or with a normal static tracepoint. */ | |
61012eef | 15189 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15190 | { |
15191 | ops = &strace_marker_breakpoint_ops; | |
15192 | location = new_linespec_location (&arg); | |
15193 | } | |
983af33b | 15194 | else |
f00aae0f KS |
15195 | { |
15196 | ops = &tracepoint_breakpoint_ops; | |
15197 | location = string_to_event_location (&arg, current_language); | |
15198 | } | |
983af33b | 15199 | |
f00aae0f | 15200 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15201 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15202 | location, |
15203 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15204 | 0 /* tempflag */, |
15205 | bp_static_tracepoint /* type_wanted */, | |
15206 | 0 /* Ignore count */, | |
15207 | pending_break_support, | |
15208 | ops, | |
15209 | from_tty, | |
15210 | 1 /* enabled */, | |
15211 | 0 /* internal */, 0); | |
f00aae0f | 15212 | do_cleanups (back_to); |
7a697b8d SS |
15213 | } |
15214 | ||
409873ef SS |
15215 | /* Set up a fake reader function that gets command lines from a linked |
15216 | list that was acquired during tracepoint uploading. */ | |
15217 | ||
15218 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15219 | static int next_cmd; |
409873ef SS |
15220 | |
15221 | static char * | |
15222 | read_uploaded_action (void) | |
15223 | { | |
15224 | char *rslt; | |
15225 | ||
3149d8c1 | 15226 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15227 | |
3149d8c1 | 15228 | next_cmd++; |
409873ef SS |
15229 | |
15230 | return rslt; | |
15231 | } | |
15232 | ||
00bf0b85 SS |
15233 | /* Given information about a tracepoint as recorded on a target (which |
15234 | can be either a live system or a trace file), attempt to create an | |
15235 | equivalent GDB tracepoint. This is not a reliable process, since | |
15236 | the target does not necessarily have all the information used when | |
15237 | the tracepoint was originally defined. */ | |
15238 | ||
d9b3f62e | 15239 | struct tracepoint * |
00bf0b85 | 15240 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15241 | { |
409873ef | 15242 | char *addr_str, small_buf[100]; |
d9b3f62e | 15243 | struct tracepoint *tp; |
f00aae0f KS |
15244 | struct event_location *location; |
15245 | struct cleanup *cleanup; | |
fd9b8c24 | 15246 | |
409873ef SS |
15247 | if (utp->at_string) |
15248 | addr_str = utp->at_string; | |
15249 | else | |
15250 | { | |
15251 | /* In the absence of a source location, fall back to raw | |
15252 | address. Since there is no way to confirm that the address | |
15253 | means the same thing as when the trace was started, warn the | |
15254 | user. */ | |
3e43a32a MS |
15255 | warning (_("Uploaded tracepoint %d has no " |
15256 | "source location, using raw address"), | |
409873ef | 15257 | utp->number); |
8c042590 | 15258 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15259 | addr_str = small_buf; |
15260 | } | |
15261 | ||
15262 | /* There's not much we can do with a sequence of bytecodes. */ | |
15263 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15264 | warning (_("Uploaded tracepoint %d condition " |
15265 | "has no source form, ignoring it"), | |
409873ef | 15266 | utp->number); |
d5551862 | 15267 | |
f00aae0f KS |
15268 | location = string_to_event_location (&addr_str, current_language); |
15269 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15270 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15271 | location, |
15272 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15273 | 0 /* parse cond/thread */, |
8cdf0e15 | 15274 | 0 /* tempflag */, |
0fb4aa4b | 15275 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15276 | 0 /* Ignore count */, |
15277 | pending_break_support, | |
348d480f | 15278 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15279 | 0 /* from_tty */, |
84f4c1fe | 15280 | utp->enabled /* enabled */, |
44f238bb PA |
15281 | 0 /* internal */, |
15282 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15283 | { |
15284 | do_cleanups (cleanup); | |
15285 | return NULL; | |
15286 | } | |
15287 | ||
15288 | do_cleanups (cleanup); | |
fd9b8c24 | 15289 | |
409873ef | 15290 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15291 | tp = get_tracepoint (tracepoint_count); |
15292 | gdb_assert (tp != NULL); | |
d5551862 | 15293 | |
00bf0b85 SS |
15294 | if (utp->pass > 0) |
15295 | { | |
8c042590 PM |
15296 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15297 | tp->base.number); | |
00bf0b85 | 15298 | |
409873ef | 15299 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15300 | } |
15301 | ||
409873ef SS |
15302 | /* If we have uploaded versions of the original commands, set up a |
15303 | special-purpose "reader" function and call the usual command line | |
15304 | reader, then pass the result to the breakpoint command-setting | |
15305 | function. */ | |
3149d8c1 | 15306 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15307 | { |
409873ef | 15308 | struct command_line *cmd_list; |
00bf0b85 | 15309 | |
409873ef | 15310 | this_utp = utp; |
3149d8c1 | 15311 | next_cmd = 0; |
d5551862 | 15312 | |
409873ef SS |
15313 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15314 | ||
d9b3f62e | 15315 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15316 | } |
3149d8c1 SS |
15317 | else if (!VEC_empty (char_ptr, utp->actions) |
15318 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15319 | warning (_("Uploaded tracepoint %d actions " |
15320 | "have no source form, ignoring them"), | |
409873ef | 15321 | utp->number); |
00bf0b85 | 15322 | |
f196051f SS |
15323 | /* Copy any status information that might be available. */ |
15324 | tp->base.hit_count = utp->hit_count; | |
15325 | tp->traceframe_usage = utp->traceframe_usage; | |
15326 | ||
00bf0b85 | 15327 | return tp; |
d9b3f62e | 15328 | } |
00bf0b85 | 15329 | |
1042e4c0 SS |
15330 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15331 | omitted. */ | |
15332 | ||
15333 | static void | |
e5a67952 | 15334 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15335 | { |
79a45e25 | 15336 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15337 | int num_printed; |
1042e4c0 | 15338 | |
e5a67952 | 15339 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15340 | |
15341 | if (num_printed == 0) | |
1042e4c0 | 15342 | { |
e5a67952 | 15343 | if (args == NULL || *args == '\0') |
d77f58be SS |
15344 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15345 | else | |
e5a67952 | 15346 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15347 | } |
ad443146 SS |
15348 | |
15349 | default_collect_info (); | |
1042e4c0 SS |
15350 | } |
15351 | ||
4a64f543 | 15352 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15353 | Not supported by all targets. */ |
15354 | static void | |
15355 | enable_trace_command (char *args, int from_tty) | |
15356 | { | |
15357 | enable_command (args, from_tty); | |
15358 | } | |
15359 | ||
4a64f543 | 15360 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15361 | Not supported by all targets. */ |
15362 | static void | |
15363 | disable_trace_command (char *args, int from_tty) | |
15364 | { | |
15365 | disable_command (args, from_tty); | |
15366 | } | |
15367 | ||
4a64f543 | 15368 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15369 | static void |
15370 | delete_trace_command (char *arg, int from_tty) | |
15371 | { | |
35df4500 | 15372 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15373 | |
15374 | dont_repeat (); | |
15375 | ||
15376 | if (arg == 0) | |
15377 | { | |
15378 | int breaks_to_delete = 0; | |
15379 | ||
15380 | /* Delete all breakpoints if no argument. | |
15381 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15382 | have to be deleted with an explicit breakpoint number |
15383 | argument. */ | |
1042e4c0 | 15384 | ALL_TRACEPOINTS (b) |
46c6471b | 15385 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15386 | { |
15387 | breaks_to_delete = 1; | |
15388 | break; | |
15389 | } | |
1042e4c0 SS |
15390 | |
15391 | /* Ask user only if there are some breakpoints to delete. */ | |
15392 | if (!from_tty | |
15393 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15394 | { | |
35df4500 | 15395 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15396 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15397 | delete_breakpoint (b); |
1042e4c0 SS |
15398 | } |
15399 | } | |
15400 | else | |
51be5b68 | 15401 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15402 | } |
15403 | ||
197f0a60 TT |
15404 | /* Helper function for trace_pass_command. */ |
15405 | ||
15406 | static void | |
d9b3f62e | 15407 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15408 | { |
d9b3f62e | 15409 | tp->pass_count = count; |
6f6484cd | 15410 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15411 | if (from_tty) |
15412 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15413 | tp->base.number, count); |
197f0a60 TT |
15414 | } |
15415 | ||
1042e4c0 SS |
15416 | /* Set passcount for tracepoint. |
15417 | ||
15418 | First command argument is passcount, second is tracepoint number. | |
15419 | If tracepoint number omitted, apply to most recently defined. | |
15420 | Also accepts special argument "all". */ | |
15421 | ||
15422 | static void | |
15423 | trace_pass_command (char *args, int from_tty) | |
15424 | { | |
d9b3f62e | 15425 | struct tracepoint *t1; |
1042e4c0 | 15426 | unsigned int count; |
1042e4c0 SS |
15427 | |
15428 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15429 | error (_("passcount command requires an " |
15430 | "argument (count + optional TP num)")); | |
1042e4c0 | 15431 | |
4a64f543 | 15432 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15433 | |
529480d0 | 15434 | args = skip_spaces (args); |
1042e4c0 SS |
15435 | if (*args && strncasecmp (args, "all", 3) == 0) |
15436 | { | |
d9b3f62e PA |
15437 | struct breakpoint *b; |
15438 | ||
1042e4c0 | 15439 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15440 | if (*args) |
15441 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15442 | |
d9b3f62e | 15443 | ALL_TRACEPOINTS (b) |
197f0a60 | 15444 | { |
d9b3f62e | 15445 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15446 | trace_pass_set_count (t1, count, from_tty); |
15447 | } | |
15448 | } | |
15449 | else if (*args == '\0') | |
1042e4c0 | 15450 | { |
5fa1d40e | 15451 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15452 | if (t1) |
197f0a60 TT |
15453 | trace_pass_set_count (t1, count, from_tty); |
15454 | } | |
15455 | else | |
15456 | { | |
15457 | struct get_number_or_range_state state; | |
15458 | ||
15459 | init_number_or_range (&state, args); | |
15460 | while (!state.finished) | |
1042e4c0 | 15461 | { |
5fa1d40e | 15462 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15463 | if (t1) |
15464 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15465 | } |
15466 | } | |
1042e4c0 SS |
15467 | } |
15468 | ||
d9b3f62e | 15469 | struct tracepoint * |
1042e4c0 SS |
15470 | get_tracepoint (int num) |
15471 | { | |
15472 | struct breakpoint *t; | |
15473 | ||
15474 | ALL_TRACEPOINTS (t) | |
15475 | if (t->number == num) | |
d9b3f62e | 15476 | return (struct tracepoint *) t; |
1042e4c0 SS |
15477 | |
15478 | return NULL; | |
15479 | } | |
15480 | ||
d5551862 SS |
15481 | /* Find the tracepoint with the given target-side number (which may be |
15482 | different from the tracepoint number after disconnecting and | |
15483 | reconnecting). */ | |
15484 | ||
d9b3f62e | 15485 | struct tracepoint * |
d5551862 SS |
15486 | get_tracepoint_by_number_on_target (int num) |
15487 | { | |
d9b3f62e | 15488 | struct breakpoint *b; |
d5551862 | 15489 | |
d9b3f62e PA |
15490 | ALL_TRACEPOINTS (b) |
15491 | { | |
15492 | struct tracepoint *t = (struct tracepoint *) b; | |
15493 | ||
15494 | if (t->number_on_target == num) | |
15495 | return t; | |
15496 | } | |
d5551862 SS |
15497 | |
15498 | return NULL; | |
15499 | } | |
15500 | ||
1042e4c0 | 15501 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15502 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15503 | If the argument is missing, the most recent tracepoint |
15504 | (tracepoint_count) is returned. */ | |
15505 | ||
d9b3f62e | 15506 | struct tracepoint * |
197f0a60 | 15507 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15508 | struct get_number_or_range_state *state) |
1042e4c0 | 15509 | { |
1042e4c0 SS |
15510 | struct breakpoint *t; |
15511 | int tpnum; | |
15512 | char *instring = arg == NULL ? NULL : *arg; | |
15513 | ||
197f0a60 TT |
15514 | if (state) |
15515 | { | |
15516 | gdb_assert (!state->finished); | |
15517 | tpnum = get_number_or_range (state); | |
15518 | } | |
15519 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15520 | tpnum = tracepoint_count; |
1042e4c0 | 15521 | else |
197f0a60 | 15522 | tpnum = get_number (arg); |
1042e4c0 SS |
15523 | |
15524 | if (tpnum <= 0) | |
15525 | { | |
15526 | if (instring && *instring) | |
15527 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15528 | instring); | |
15529 | else | |
5fa1d40e | 15530 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15531 | return NULL; |
15532 | } | |
15533 | ||
15534 | ALL_TRACEPOINTS (t) | |
15535 | if (t->number == tpnum) | |
15536 | { | |
d9b3f62e | 15537 | return (struct tracepoint *) t; |
1042e4c0 SS |
15538 | } |
15539 | ||
1042e4c0 SS |
15540 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15541 | return NULL; | |
15542 | } | |
15543 | ||
d9b3f62e PA |
15544 | void |
15545 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15546 | { | |
15547 | if (b->thread != -1) | |
15548 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15549 | ||
15550 | if (b->task != 0) | |
15551 | fprintf_unfiltered (fp, " task %d", b->task); | |
15552 | ||
15553 | fprintf_unfiltered (fp, "\n"); | |
15554 | } | |
15555 | ||
6149aea9 PA |
15556 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15557 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15558 | on each breakpoint and only include the ones for which it returns | |
15559 | non-zero. */ | |
15560 | ||
1042e4c0 | 15561 | static void |
6149aea9 PA |
15562 | save_breakpoints (char *filename, int from_tty, |
15563 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15564 | { |
15565 | struct breakpoint *tp; | |
6149aea9 | 15566 | int any = 0; |
1042e4c0 | 15567 | struct cleanup *cleanup; |
a7bdde9e | 15568 | struct ui_file *fp; |
6149aea9 | 15569 | int extra_trace_bits = 0; |
1042e4c0 | 15570 | |
6149aea9 PA |
15571 | if (filename == 0 || *filename == 0) |
15572 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15573 | |
15574 | /* See if we have anything to save. */ | |
6149aea9 | 15575 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15576 | { |
6149aea9 | 15577 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15578 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15579 | continue; |
15580 | ||
15581 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15582 | if (filter && !filter (tp)) | |
15583 | continue; | |
15584 | ||
15585 | any = 1; | |
15586 | ||
15587 | if (is_tracepoint (tp)) | |
15588 | { | |
15589 | extra_trace_bits = 1; | |
15590 | ||
15591 | /* We can stop searching. */ | |
15592 | break; | |
15593 | } | |
1042e4c0 | 15594 | } |
6149aea9 PA |
15595 | |
15596 | if (!any) | |
1042e4c0 | 15597 | { |
6149aea9 | 15598 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15599 | return; |
15600 | } | |
15601 | ||
c718be47 PA |
15602 | filename = tilde_expand (filename); |
15603 | cleanup = make_cleanup (xfree, filename); | |
15604 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15605 | if (!fp) |
6149aea9 PA |
15606 | error (_("Unable to open file '%s' for saving (%s)"), |
15607 | filename, safe_strerror (errno)); | |
a7bdde9e | 15608 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15609 | |
6149aea9 PA |
15610 | if (extra_trace_bits) |
15611 | save_trace_state_variables (fp); | |
8bf6485c | 15612 | |
6149aea9 | 15613 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15614 | { |
6149aea9 | 15615 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15616 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15617 | continue; |
8bf6485c | 15618 | |
6149aea9 PA |
15619 | /* If we have a filter, only save the breakpoints it accepts. */ |
15620 | if (filter && !filter (tp)) | |
15621 | continue; | |
15622 | ||
348d480f | 15623 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15624 | |
6149aea9 PA |
15625 | /* Note, we can't rely on tp->number for anything, as we can't |
15626 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15627 | instead. */ | |
15628 | ||
15629 | if (tp->cond_string) | |
15630 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15631 | ||
15632 | if (tp->ignore_count) | |
15633 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15634 | ||
2d9442cc | 15635 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15636 | { |
6c63c96a | 15637 | struct gdb_exception exception; |
a7bdde9e | 15638 | |
6149aea9 | 15639 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15640 | |
79a45e25 | 15641 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15642 | TRY |
1042e4c0 | 15643 | { |
79a45e25 | 15644 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15645 | } |
492d29ea PA |
15646 | CATCH (ex, RETURN_MASK_ALL) |
15647 | { | |
6c63c96a | 15648 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15649 | throw_exception (ex); |
15650 | } | |
15651 | END_CATCH | |
1042e4c0 | 15652 | |
6c63c96a | 15653 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15654 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15655 | } |
6149aea9 PA |
15656 | |
15657 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15658 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15659 | |
15660 | /* If this is a multi-location breakpoint, check if the locations | |
15661 | should be individually disabled. Watchpoint locations are | |
15662 | special, and not user visible. */ | |
15663 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15664 | { | |
15665 | struct bp_location *loc; | |
15666 | int n = 1; | |
15667 | ||
15668 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15669 | if (!loc->enabled) | |
15670 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15671 | } | |
1042e4c0 | 15672 | } |
8bf6485c | 15673 | |
6149aea9 | 15674 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15675 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15676 | ||
1042e4c0 | 15677 | if (from_tty) |
6149aea9 | 15678 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15679 | do_cleanups (cleanup); |
6149aea9 PA |
15680 | } |
15681 | ||
15682 | /* The `save breakpoints' command. */ | |
15683 | ||
15684 | static void | |
15685 | save_breakpoints_command (char *args, int from_tty) | |
15686 | { | |
15687 | save_breakpoints (args, from_tty, NULL); | |
15688 | } | |
15689 | ||
15690 | /* The `save tracepoints' command. */ | |
15691 | ||
15692 | static void | |
15693 | save_tracepoints_command (char *args, int from_tty) | |
15694 | { | |
15695 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15696 | } |
15697 | ||
15698 | /* Create a vector of all tracepoints. */ | |
15699 | ||
15700 | VEC(breakpoint_p) * | |
eeae04df | 15701 | all_tracepoints (void) |
1042e4c0 SS |
15702 | { |
15703 | VEC(breakpoint_p) *tp_vec = 0; | |
15704 | struct breakpoint *tp; | |
15705 | ||
15706 | ALL_TRACEPOINTS (tp) | |
15707 | { | |
15708 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15709 | } | |
15710 | ||
15711 | return tp_vec; | |
15712 | } | |
15713 | ||
c906108c | 15714 | \f |
629500fa KS |
15715 | /* This help string is used to consolidate all the help string for specifying |
15716 | locations used by several commands. */ | |
15717 | ||
15718 | #define LOCATION_HELP_STRING \ | |
15719 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15720 | source filename, function name, label name, and line number.\n\ | |
15721 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15722 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15723 | \"factorial.c:fact:the_top\".\n\ | |
15724 | \n\ | |
15725 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15726 | program. Example: To specify the fourth byte past the start function\n\ | |
15727 | \"main\", use \"*main + 4\".\n\ | |
15728 | \n\ | |
15729 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15730 | syntax to specify location parameters.\n\ | |
15731 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15732 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15733 | -function fact -label the_top\".\n" | |
15734 | ||
4a64f543 MS |
15735 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15736 | commands. It is defined as a macro to prevent duplication. | |
15737 | COMMAND should be a string constant containing the name of the | |
15738 | command. */ | |
629500fa | 15739 | |
31e2b00f | 15740 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15741 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15742 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15743 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15744 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15745 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15746 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15747 | below.\n\ | |
15748 | \n\ | |
dc10affe PA |
15749 | With no LOCATION, uses current execution address of the selected\n\ |
15750 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15751 | \n\ |
15752 | THREADNUM is the number from \"info threads\".\n\ | |
15753 | CONDITION is a boolean expression.\n\ | |
629500fa | 15754 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15755 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15756 | conditions are different.\n\ | |
31e2b00f AS |
15757 | \n\ |
15758 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15759 | ||
44feb3ce TT |
15760 | /* List of subcommands for "catch". */ |
15761 | static struct cmd_list_element *catch_cmdlist; | |
15762 | ||
15763 | /* List of subcommands for "tcatch". */ | |
15764 | static struct cmd_list_element *tcatch_cmdlist; | |
15765 | ||
9ac4176b | 15766 | void |
44feb3ce | 15767 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15768 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15769 | completer_ftype *completer, |
44feb3ce TT |
15770 | void *user_data_catch, |
15771 | void *user_data_tcatch) | |
15772 | { | |
15773 | struct cmd_list_element *command; | |
15774 | ||
15775 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15776 | &catch_cmdlist); | |
15777 | set_cmd_sfunc (command, sfunc); | |
15778 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15779 | set_cmd_completer (command, completer); |
44feb3ce TT |
15780 | |
15781 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15782 | &tcatch_cmdlist); | |
15783 | set_cmd_sfunc (command, sfunc); | |
15784 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15785 | set_cmd_completer (command, completer); |
44feb3ce TT |
15786 | } |
15787 | ||
6149aea9 PA |
15788 | static void |
15789 | save_command (char *arg, int from_tty) | |
15790 | { | |
3e43a32a MS |
15791 | printf_unfiltered (_("\"save\" must be followed by " |
15792 | "the name of a save subcommand.\n")); | |
635c7e8a | 15793 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15794 | } |
15795 | ||
84f4c1fe PM |
15796 | struct breakpoint * |
15797 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15798 | void *data) | |
15799 | { | |
35df4500 | 15800 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15801 | |
35df4500 | 15802 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15803 | { |
15804 | if ((*callback) (b, data)) | |
15805 | return b; | |
15806 | } | |
15807 | ||
15808 | return NULL; | |
15809 | } | |
15810 | ||
0574c78f GB |
15811 | /* Zero if any of the breakpoint's locations could be a location where |
15812 | functions have been inlined, nonzero otherwise. */ | |
15813 | ||
15814 | static int | |
15815 | is_non_inline_function (struct breakpoint *b) | |
15816 | { | |
15817 | /* The shared library event breakpoint is set on the address of a | |
15818 | non-inline function. */ | |
15819 | if (b->type == bp_shlib_event) | |
15820 | return 1; | |
15821 | ||
15822 | return 0; | |
15823 | } | |
15824 | ||
15825 | /* Nonzero if the specified PC cannot be a location where functions | |
15826 | have been inlined. */ | |
15827 | ||
15828 | int | |
09ac7c10 TT |
15829 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15830 | const struct target_waitstatus *ws) | |
0574c78f GB |
15831 | { |
15832 | struct breakpoint *b; | |
15833 | struct bp_location *bl; | |
15834 | ||
15835 | ALL_BREAKPOINTS (b) | |
15836 | { | |
15837 | if (!is_non_inline_function (b)) | |
15838 | continue; | |
15839 | ||
15840 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15841 | { | |
15842 | if (!bl->shlib_disabled | |
09ac7c10 | 15843 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15844 | return 1; |
15845 | } | |
15846 | } | |
15847 | ||
15848 | return 0; | |
15849 | } | |
15850 | ||
2f202fde JK |
15851 | /* Remove any references to OBJFILE which is going to be freed. */ |
15852 | ||
15853 | void | |
15854 | breakpoint_free_objfile (struct objfile *objfile) | |
15855 | { | |
15856 | struct bp_location **locp, *loc; | |
15857 | ||
15858 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15859 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15860 | loc->symtab = NULL; |
15861 | } | |
15862 | ||
2060206e PA |
15863 | void |
15864 | initialize_breakpoint_ops (void) | |
15865 | { | |
15866 | static int initialized = 0; | |
15867 | ||
15868 | struct breakpoint_ops *ops; | |
15869 | ||
15870 | if (initialized) | |
15871 | return; | |
15872 | initialized = 1; | |
15873 | ||
15874 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15875 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15876 | internal and momentary breakpoints, etc.). */ | |
15877 | ops = &bkpt_base_breakpoint_ops; | |
15878 | *ops = base_breakpoint_ops; | |
15879 | ops->re_set = bkpt_re_set; | |
15880 | ops->insert_location = bkpt_insert_location; | |
15881 | ops->remove_location = bkpt_remove_location; | |
15882 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15883 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15884 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15885 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15886 | |
15887 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15888 | ops = &bkpt_breakpoint_ops; | |
15889 | *ops = bkpt_base_breakpoint_ops; | |
15890 | ops->re_set = bkpt_re_set; | |
15891 | ops->resources_needed = bkpt_resources_needed; | |
15892 | ops->print_it = bkpt_print_it; | |
15893 | ops->print_mention = bkpt_print_mention; | |
15894 | ops->print_recreate = bkpt_print_recreate; | |
15895 | ||
15896 | /* Ranged breakpoints. */ | |
15897 | ops = &ranged_breakpoint_ops; | |
15898 | *ops = bkpt_breakpoint_ops; | |
15899 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15900 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15901 | ops->print_it = print_it_ranged_breakpoint; | |
15902 | ops->print_one = print_one_ranged_breakpoint; | |
15903 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15904 | ops->print_mention = print_mention_ranged_breakpoint; | |
15905 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15906 | ||
15907 | /* Internal breakpoints. */ | |
15908 | ops = &internal_breakpoint_ops; | |
15909 | *ops = bkpt_base_breakpoint_ops; | |
15910 | ops->re_set = internal_bkpt_re_set; | |
15911 | ops->check_status = internal_bkpt_check_status; | |
15912 | ops->print_it = internal_bkpt_print_it; | |
15913 | ops->print_mention = internal_bkpt_print_mention; | |
15914 | ||
15915 | /* Momentary breakpoints. */ | |
15916 | ops = &momentary_breakpoint_ops; | |
15917 | *ops = bkpt_base_breakpoint_ops; | |
15918 | ops->re_set = momentary_bkpt_re_set; | |
15919 | ops->check_status = momentary_bkpt_check_status; | |
15920 | ops->print_it = momentary_bkpt_print_it; | |
15921 | ops->print_mention = momentary_bkpt_print_mention; | |
15922 | ||
e2e4d78b JK |
15923 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15924 | ops = &longjmp_breakpoint_ops; | |
15925 | *ops = momentary_breakpoint_ops; | |
15926 | ops->dtor = longjmp_bkpt_dtor; | |
15927 | ||
55aa24fb SDJ |
15928 | /* Probe breakpoints. */ |
15929 | ops = &bkpt_probe_breakpoint_ops; | |
15930 | *ops = bkpt_breakpoint_ops; | |
15931 | ops->insert_location = bkpt_probe_insert_location; | |
15932 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15933 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15934 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15935 | |
2060206e PA |
15936 | /* Watchpoints. */ |
15937 | ops = &watchpoint_breakpoint_ops; | |
15938 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15939 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15940 | ops->re_set = re_set_watchpoint; |
15941 | ops->insert_location = insert_watchpoint; | |
15942 | ops->remove_location = remove_watchpoint; | |
15943 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15944 | ops->check_status = check_status_watchpoint; | |
15945 | ops->resources_needed = resources_needed_watchpoint; | |
15946 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15947 | ops->print_it = print_it_watchpoint; | |
15948 | ops->print_mention = print_mention_watchpoint; | |
15949 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15950 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15951 | |
15952 | /* Masked watchpoints. */ | |
15953 | ops = &masked_watchpoint_breakpoint_ops; | |
15954 | *ops = watchpoint_breakpoint_ops; | |
15955 | ops->insert_location = insert_masked_watchpoint; | |
15956 | ops->remove_location = remove_masked_watchpoint; | |
15957 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15958 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15959 | ops->print_it = print_it_masked_watchpoint; | |
15960 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15961 | ops->print_mention = print_mention_masked_watchpoint; | |
15962 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15963 | ||
15964 | /* Tracepoints. */ | |
15965 | ops = &tracepoint_breakpoint_ops; | |
15966 | *ops = base_breakpoint_ops; | |
15967 | ops->re_set = tracepoint_re_set; | |
15968 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15969 | ops->print_one_detail = tracepoint_print_one_detail; | |
15970 | ops->print_mention = tracepoint_print_mention; | |
15971 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15972 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15973 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15974 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15975 | |
55aa24fb SDJ |
15976 | /* Probe tracepoints. */ |
15977 | ops = &tracepoint_probe_breakpoint_ops; | |
15978 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15979 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15980 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15981 | |
983af33b SDJ |
15982 | /* Static tracepoints with marker (`-m'). */ |
15983 | ops = &strace_marker_breakpoint_ops; | |
15984 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15985 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15986 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15987 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15988 | |
15989 | /* Fork catchpoints. */ | |
15990 | ops = &catch_fork_breakpoint_ops; | |
15991 | *ops = base_breakpoint_ops; | |
15992 | ops->insert_location = insert_catch_fork; | |
15993 | ops->remove_location = remove_catch_fork; | |
15994 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15995 | ops->print_it = print_it_catch_fork; | |
15996 | ops->print_one = print_one_catch_fork; | |
15997 | ops->print_mention = print_mention_catch_fork; | |
15998 | ops->print_recreate = print_recreate_catch_fork; | |
15999 | ||
16000 | /* Vfork catchpoints. */ | |
16001 | ops = &catch_vfork_breakpoint_ops; | |
16002 | *ops = base_breakpoint_ops; | |
16003 | ops->insert_location = insert_catch_vfork; | |
16004 | ops->remove_location = remove_catch_vfork; | |
16005 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16006 | ops->print_it = print_it_catch_vfork; | |
16007 | ops->print_one = print_one_catch_vfork; | |
16008 | ops->print_mention = print_mention_catch_vfork; | |
16009 | ops->print_recreate = print_recreate_catch_vfork; | |
16010 | ||
16011 | /* Exec catchpoints. */ | |
16012 | ops = &catch_exec_breakpoint_ops; | |
16013 | *ops = base_breakpoint_ops; | |
16014 | ops->dtor = dtor_catch_exec; | |
16015 | ops->insert_location = insert_catch_exec; | |
16016 | ops->remove_location = remove_catch_exec; | |
16017 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16018 | ops->print_it = print_it_catch_exec; | |
16019 | ops->print_one = print_one_catch_exec; | |
16020 | ops->print_mention = print_mention_catch_exec; | |
16021 | ops->print_recreate = print_recreate_catch_exec; | |
16022 | ||
edcc5120 TT |
16023 | /* Solib-related catchpoints. */ |
16024 | ops = &catch_solib_breakpoint_ops; | |
16025 | *ops = base_breakpoint_ops; | |
16026 | ops->dtor = dtor_catch_solib; | |
16027 | ops->insert_location = insert_catch_solib; | |
16028 | ops->remove_location = remove_catch_solib; | |
16029 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16030 | ops->check_status = check_status_catch_solib; | |
16031 | ops->print_it = print_it_catch_solib; | |
16032 | ops->print_one = print_one_catch_solib; | |
16033 | ops->print_mention = print_mention_catch_solib; | |
16034 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16035 | |
16036 | ops = &dprintf_breakpoint_ops; | |
16037 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16038 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16039 | ops->resources_needed = bkpt_resources_needed; |
16040 | ops->print_it = bkpt_print_it; | |
16041 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16042 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16043 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16044 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16045 | } |
16046 | ||
8bfd80db YQ |
16047 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16048 | ||
16049 | static struct cmd_list_element *enablebreaklist = NULL; | |
16050 | ||
c906108c | 16051 | void |
fba45db2 | 16052 | _initialize_breakpoint (void) |
c906108c SS |
16053 | { |
16054 | struct cmd_list_element *c; | |
16055 | ||
2060206e PA |
16056 | initialize_breakpoint_ops (); |
16057 | ||
84acb35a | 16058 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16059 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16060 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16061 | |
55aa24fb SDJ |
16062 | breakpoint_objfile_key |
16063 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16064 | |
c906108c SS |
16065 | breakpoint_chain = 0; |
16066 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16067 | before a breakpoint is set. */ | |
16068 | breakpoint_count = 0; | |
16069 | ||
1042e4c0 SS |
16070 | tracepoint_count = 0; |
16071 | ||
1bedd215 AC |
16072 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16073 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16074 | Usage is `ignore N COUNT'.")); | |
c906108c | 16075 | |
1bedd215 AC |
16076 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16077 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16078 | Give breakpoint number as argument after \"commands\".\n\ |
16079 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16080 | The commands themselves follow starting on the next line.\n\ | |
16081 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16082 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16083 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16084 | |
d55637df | 16085 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16086 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16087 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16088 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16089 | set_cmd_completer (c, condition_completer); |
c906108c | 16090 | |
1bedd215 | 16091 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16092 | Set a temporary breakpoint.\n\ |
c906108c SS |
16093 | Like \"break\" except the breakpoint is only temporary,\n\ |
16094 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16095 | by using \"enable delete\" on the breakpoint number.\n\ |
16096 | \n" | |
16097 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16098 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16099 | |
1bedd215 | 16100 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16101 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16102 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16103 | some target hardware may not have this support.\n\ |
16104 | \n" | |
16105 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16106 | set_cmd_completer (c, location_completer); |
c906108c | 16107 | |
1bedd215 | 16108 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16109 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16110 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16111 | so it will be deleted when hit.\n\ |
16112 | \n" | |
16113 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16114 | set_cmd_completer (c, location_completer); |
c906108c | 16115 | |
1bedd215 AC |
16116 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16117 | Enable some breakpoints.\n\ | |
c906108c SS |
16118 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16119 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16120 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16121 | With a subcommand you can enable temporarily."), |
c906108c | 16122 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16123 | |
16124 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16125 | ||
84951ab5 | 16126 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16127 | Enable some breakpoints.\n\ |
c906108c SS |
16128 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16129 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16130 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16131 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16132 | |
1a966eab AC |
16133 | add_cmd ("once", no_class, enable_once_command, _("\ |
16134 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16135 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16136 | &enablebreaklist); |
16137 | ||
1a966eab AC |
16138 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16139 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16140 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16141 | &enablebreaklist); |
16142 | ||
816338b5 SS |
16143 | add_cmd ("count", no_class, enable_count_command, _("\ |
16144 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16145 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16146 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16147 | &enablebreaklist); | |
16148 | ||
1a966eab AC |
16149 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16150 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16151 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16152 | &enablelist); |
16153 | ||
1a966eab AC |
16154 | add_cmd ("once", no_class, enable_once_command, _("\ |
16155 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16156 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16157 | &enablelist); |
16158 | ||
16159 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16160 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16161 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16162 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16163 | &enablelist); |
16164 | ||
1bedd215 AC |
16165 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16166 | Disable some breakpoints.\n\ | |
c906108c SS |
16167 | Arguments are breakpoint numbers with spaces in between.\n\ |
16168 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16169 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16170 | &disablelist, "disable ", 1, &cmdlist); |
16171 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16172 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16173 | |
1a966eab AC |
16174 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16175 | Disable some breakpoints.\n\ | |
c906108c SS |
16176 | Arguments are breakpoint numbers with spaces in between.\n\ |
16177 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16178 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16179 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16180 | &disablelist); |
16181 | ||
1bedd215 AC |
16182 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16183 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16184 | Arguments are breakpoint numbers with spaces in between.\n\ |
16185 | To delete all breakpoints, give no argument.\n\ | |
16186 | \n\ | |
16187 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16188 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16189 | &deletelist, "delete ", 1, &cmdlist); |
16190 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16191 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16192 | |
1a966eab AC |
16193 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16194 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16195 | Arguments are breakpoint numbers with spaces in between.\n\ |
16196 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16197 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16198 | &deletelist); |
16199 | ||
1bedd215 | 16200 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16201 | Clear breakpoint at specified location.\n\ |
16202 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16203 | \n\ |
16204 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16205 | is executing in.\n" |
16206 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16207 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16208 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16209 | |
1bedd215 | 16210 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16211 | Set breakpoint at specified location.\n" |
31e2b00f | 16212 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16213 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16214 | |
c906108c SS |
16215 | add_com_alias ("b", "break", class_run, 1); |
16216 | add_com_alias ("br", "break", class_run, 1); | |
16217 | add_com_alias ("bre", "break", class_run, 1); | |
16218 | add_com_alias ("brea", "break", class_run, 1); | |
16219 | ||
c906108c SS |
16220 | if (dbx_commands) |
16221 | { | |
1bedd215 AC |
16222 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16223 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16224 | &stoplist, "stop ", 1, &cmdlist); |
16225 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16226 | _("Break in function or address."), &stoplist); |
c5aa993b | 16227 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16228 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16229 | add_com ("status", class_info, breakpoints_info, _("\ |
16230 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16231 | The \"Type\" column indicates one of:\n\ |
16232 | \tbreakpoint - normal breakpoint\n\ | |
16233 | \twatchpoint - watchpoint\n\ | |
16234 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16235 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16236 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16237 | address and file/line number respectively.\n\ |
16238 | \n\ | |
16239 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16240 | are set to the address of the last breakpoint listed unless the command\n\ |
16241 | is prefixed with \"server \".\n\n\ | |
c906108c | 16242 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16243 | breakpoint set.")); |
c906108c SS |
16244 | } |
16245 | ||
1bedd215 | 16246 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16247 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16248 | The \"Type\" column indicates one of:\n\ |
16249 | \tbreakpoint - normal breakpoint\n\ | |
16250 | \twatchpoint - watchpoint\n\ | |
16251 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16252 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16253 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16254 | address and file/line number respectively.\n\ |
16255 | \n\ | |
16256 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16257 | are set to the address of the last breakpoint listed unless the command\n\ |
16258 | is prefixed with \"server \".\n\n\ | |
c906108c | 16259 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16260 | breakpoint set.")); |
c906108c | 16261 | |
6b04bdb7 MS |
16262 | add_info_alias ("b", "breakpoints", 1); |
16263 | ||
1a966eab AC |
16264 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16265 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16266 | The \"Type\" column indicates one of:\n\ |
16267 | \tbreakpoint - normal breakpoint\n\ | |
16268 | \twatchpoint - watchpoint\n\ | |
16269 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16270 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16271 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16272 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16273 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16274 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16275 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16276 | address and file/line number respectively.\n\ |
16277 | \n\ | |
16278 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16279 | are set to the address of the last breakpoint listed unless the command\n\ |
16280 | is prefixed with \"server \".\n\n\ | |
c906108c | 16281 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16282 | breakpoint set."), |
c906108c SS |
16283 | &maintenanceinfolist); |
16284 | ||
44feb3ce TT |
16285 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16286 | Set catchpoints to catch events."), | |
16287 | &catch_cmdlist, "catch ", | |
16288 | 0/*allow-unknown*/, &cmdlist); | |
16289 | ||
16290 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16291 | Set temporary catchpoints to catch events."), | |
16292 | &tcatch_cmdlist, "tcatch ", | |
16293 | 0/*allow-unknown*/, &cmdlist); | |
16294 | ||
44feb3ce TT |
16295 | add_catch_command ("fork", _("Catch calls to fork."), |
16296 | catch_fork_command_1, | |
a96d9b2e | 16297 | NULL, |
44feb3ce TT |
16298 | (void *) (uintptr_t) catch_fork_permanent, |
16299 | (void *) (uintptr_t) catch_fork_temporary); | |
16300 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16301 | catch_fork_command_1, | |
a96d9b2e | 16302 | NULL, |
44feb3ce TT |
16303 | (void *) (uintptr_t) catch_vfork_permanent, |
16304 | (void *) (uintptr_t) catch_vfork_temporary); | |
16305 | add_catch_command ("exec", _("Catch calls to exec."), | |
16306 | catch_exec_command_1, | |
a96d9b2e SDJ |
16307 | NULL, |
16308 | CATCH_PERMANENT, | |
16309 | CATCH_TEMPORARY); | |
edcc5120 TT |
16310 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16311 | Usage: catch load [REGEX]\n\ | |
16312 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16313 | catch_load_command_1, | |
16314 | NULL, | |
16315 | CATCH_PERMANENT, | |
16316 | CATCH_TEMPORARY); | |
16317 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16318 | Usage: catch unload [REGEX]\n\ | |
16319 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16320 | catch_unload_command_1, | |
16321 | NULL, | |
16322 | CATCH_PERMANENT, | |
16323 | CATCH_TEMPORARY); | |
c5aa993b | 16324 | |
1bedd215 AC |
16325 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16326 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16327 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16328 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16329 | an expression changes.\n\ |
16330 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16331 | the memory to which it refers.")); | |
65d12d83 | 16332 | set_cmd_completer (c, expression_completer); |
c906108c | 16333 | |
1bedd215 AC |
16334 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16335 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16336 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16337 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16338 | an expression is read.\n\ |
16339 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16340 | the memory to which it refers.")); | |
65d12d83 | 16341 | set_cmd_completer (c, expression_completer); |
c906108c | 16342 | |
1bedd215 AC |
16343 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16344 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16345 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16346 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16347 | an expression is either read or written.\n\ |
16348 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16349 | the memory to which it refers.")); | |
65d12d83 | 16350 | set_cmd_completer (c, expression_completer); |
c906108c | 16351 | |
d77f58be | 16352 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16353 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16354 | |
920d2a44 AC |
16355 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16356 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16357 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16358 | &can_use_hw_watchpoints, _("\ | |
16359 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16360 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16361 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16362 | such is available. (However, any hardware watchpoints that were\n\ | |
16363 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16364 | hardware.)"), |
16365 | NULL, | |
920d2a44 | 16366 | show_can_use_hw_watchpoints, |
85c07804 | 16367 | &setlist, &showlist); |
c906108c SS |
16368 | |
16369 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16370 | |
1042e4c0 SS |
16371 | /* Tracepoint manipulation commands. */ |
16372 | ||
16373 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16374 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16375 | \n" |
16376 | BREAK_ARGS_HELP ("trace") "\n\ | |
16377 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16378 | set_cmd_completer (c, location_completer); | |
16379 | ||
16380 | add_com_alias ("tp", "trace", class_alias, 0); | |
16381 | add_com_alias ("tr", "trace", class_alias, 1); | |
16382 | add_com_alias ("tra", "trace", class_alias, 1); | |
16383 | add_com_alias ("trac", "trace", class_alias, 1); | |
16384 | ||
7a697b8d | 16385 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16386 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16387 | \n" |
16388 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16389 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16390 | set_cmd_completer (c, location_completer); | |
16391 | ||
0fb4aa4b | 16392 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16393 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16394 | \n\ |
16395 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16396 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16397 | or -m MARKER_ID.\n\n\ | |
16398 | If a marker id is specified, probe the marker with that name. With\n\ | |
16399 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16400 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16401 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16402 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16403 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16404 | \n\ | |
16405 | CONDITION is a boolean expression.\n\ | |
629500fa | 16406 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16407 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16408 | conditions are different.\n\ | |
0fb4aa4b PA |
16409 | \n\ |
16410 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16411 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16412 | set_cmd_completer (c, location_completer); | |
16413 | ||
1042e4c0 | 16414 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16415 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16416 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16417 | last tracepoint set.")); | |
16418 | ||
16419 | add_info_alias ("tp", "tracepoints", 1); | |
16420 | ||
16421 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16422 | Delete specified tracepoints.\n\ | |
16423 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16424 | No argument means delete all tracepoints."), | |
16425 | &deletelist); | |
7e20dfcd | 16426 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16427 | |
16428 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16429 | Disable specified tracepoints.\n\ | |
16430 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16431 | No argument means disable all tracepoints."), | |
16432 | &disablelist); | |
16433 | deprecate_cmd (c, "disable"); | |
16434 | ||
16435 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16436 | Enable specified tracepoints.\n\ | |
16437 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16438 | No argument means enable all tracepoints."), | |
16439 | &enablelist); | |
16440 | deprecate_cmd (c, "enable"); | |
16441 | ||
16442 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16443 | Set the passcount for a tracepoint.\n\ | |
16444 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16445 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16446 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16447 | ||
6149aea9 PA |
16448 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16449 | _("Save breakpoint definitions as a script."), | |
16450 | &save_cmdlist, "save ", | |
16451 | 0/*allow-unknown*/, &cmdlist); | |
16452 | ||
16453 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16454 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16455 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16456 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16457 | session to restore them."), | |
16458 | &save_cmdlist); | |
16459 | set_cmd_completer (c, filename_completer); | |
16460 | ||
16461 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16462 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16463 | Use the 'source' command in another debug session to restore them."), |
16464 | &save_cmdlist); | |
1042e4c0 SS |
16465 | set_cmd_completer (c, filename_completer); |
16466 | ||
6149aea9 PA |
16467 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16468 | deprecate_cmd (c, "save tracepoints"); | |
16469 | ||
1bedd215 | 16470 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16471 | Breakpoint specific settings\n\ |
16472 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16473 | pending breakpoint behavior"), |
fa8d40ab JJ |
16474 | &breakpoint_set_cmdlist, "set breakpoint ", |
16475 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16476 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16477 | Breakpoint specific settings\n\ |
16478 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16479 | pending breakpoint behavior"), |
fa8d40ab JJ |
16480 | &breakpoint_show_cmdlist, "show breakpoint ", |
16481 | 0/*allow-unknown*/, &showlist); | |
16482 | ||
7915a72c AC |
16483 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16484 | &pending_break_support, _("\ | |
16485 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16486 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16487 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16488 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16489 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16490 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16491 | NULL, |
920d2a44 | 16492 | show_pending_break_support, |
6e1d7d6c AC |
16493 | &breakpoint_set_cmdlist, |
16494 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16495 | |
16496 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16497 | |
16498 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16499 | &automatic_hardware_breakpoints, _("\ | |
16500 | Set automatic usage of hardware breakpoints."), _("\ | |
16501 | Show automatic usage of hardware breakpoints."), _("\ | |
16502 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16503 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16504 | a warning will be emitted for such breakpoints."), | |
16505 | NULL, | |
16506 | show_automatic_hardware_breakpoints, | |
16507 | &breakpoint_set_cmdlist, | |
16508 | &breakpoint_show_cmdlist); | |
74960c60 | 16509 | |
a25a5a45 PA |
16510 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16511 | &always_inserted_mode, _("\ | |
74960c60 VP |
16512 | Set mode for inserting breakpoints."), _("\ |
16513 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16514 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16515 | they're created, kept inserted even when execution stops, and removed\n\ | |
16516 | only when the user deletes them. When this mode is off (the default),\n\ | |
16517 | breakpoints are inserted only when execution continues, and removed\n\ | |
16518 | when execution stops."), | |
72d0e2c5 YQ |
16519 | NULL, |
16520 | &show_always_inserted_mode, | |
16521 | &breakpoint_set_cmdlist, | |
16522 | &breakpoint_show_cmdlist); | |
f1310107 | 16523 | |
b775012e LM |
16524 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16525 | condition_evaluation_enums, | |
16526 | &condition_evaluation_mode_1, _("\ | |
16527 | Set mode of breakpoint condition evaluation."), _("\ | |
16528 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16529 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16530 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16531 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16532 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16533 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16534 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16535 | be set to \"gdb\""), | |
16536 | &set_condition_evaluation_mode, | |
16537 | &show_condition_evaluation_mode, | |
16538 | &breakpoint_set_cmdlist, | |
16539 | &breakpoint_show_cmdlist); | |
16540 | ||
f1310107 TJB |
16541 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16542 | Set a breakpoint for an address range.\n\ | |
16543 | break-range START-LOCATION, END-LOCATION\n\ | |
16544 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16545 | LINENUM, for that line in the current file,\n\ | |
16546 | FILE:LINENUM, for that line in that file,\n\ | |
16547 | +OFFSET, for that number of lines after the current line\n\ | |
16548 | or the start of the range\n\ | |
16549 | FUNCTION, for the first line in that function,\n\ | |
16550 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16551 | *ADDRESS, for the instruction at that address.\n\ | |
16552 | \n\ | |
16553 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16554 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16555 | range (including START-LOCATION and END-LOCATION).")); | |
16556 | ||
e7e0cddf | 16557 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16558 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16559 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16560 | location may be a linespec, explicit, or address location.\n" |
16561 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16562 | set_cmd_completer (c, location_completer); |
16563 | ||
16564 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16565 | dprintf_style_enums, &dprintf_style, _("\ | |
16566 | Set the style of usage for dynamic printf."), _("\ | |
16567 | Show the style of usage for dynamic printf."), _("\ | |
16568 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16569 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16570 | console, as with the \"printf\" command.\n\ | |
16571 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16572 | program; by default printf(), but you can choose a different function or\n\ | |
16573 | output stream by setting dprintf-function and dprintf-channel."), | |
16574 | update_dprintf_commands, NULL, | |
16575 | &setlist, &showlist); | |
16576 | ||
16577 | dprintf_function = xstrdup ("printf"); | |
16578 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16579 | &dprintf_function, _("\ | |
16580 | Set the function to use for dynamic printf"), _("\ | |
16581 | Show the function to use for dynamic printf"), NULL, | |
16582 | update_dprintf_commands, NULL, | |
16583 | &setlist, &showlist); | |
16584 | ||
16585 | dprintf_channel = xstrdup (""); | |
16586 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16587 | &dprintf_channel, _("\ | |
16588 | Set the channel to use for dynamic printf"), _("\ | |
16589 | Show the channel to use for dynamic printf"), NULL, | |
16590 | update_dprintf_commands, NULL, | |
16591 | &setlist, &showlist); | |
16592 | ||
d3ce09f5 SS |
16593 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16594 | &disconnected_dprintf, _("\ | |
16595 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16596 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16597 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16598 | even if GDB disconnects or detaches from the target."), | |
16599 | NULL, | |
16600 | NULL, | |
16601 | &setlist, &showlist); | |
16602 | ||
16603 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16604 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16605 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16606 | ||
765dc015 | 16607 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16608 | |
16609 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16610 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16611 | } |