]>
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 SS |
69 | #include "format.h" |
70 | ||
1042e4c0 SS |
71 | /* readline include files */ |
72 | #include "readline/readline.h" | |
73 | #include "readline/history.h" | |
74 | ||
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
6dddc817 | 79 | #include "extension.h" |
104c1213 | 80 | |
e7e8980f YQ |
81 | /* Enums for exception-handling support. */ |
82 | enum exception_event_kind | |
83 | { | |
84 | EX_EVENT_THROW, | |
591f19e8 | 85 | EX_EVENT_RETHROW, |
e7e8980f YQ |
86 | EX_EVENT_CATCH |
87 | }; | |
88 | ||
4a64f543 | 89 | /* Prototypes for local functions. */ |
c906108c | 90 | |
a14ed312 | 91 | static void enable_delete_command (char *, int); |
c906108c | 92 | |
a14ed312 | 93 | static void enable_once_command (char *, int); |
c906108c | 94 | |
816338b5 SS |
95 | static void enable_count_command (char *, int); |
96 | ||
a14ed312 | 97 | static void disable_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void enable_command (char *, int); |
c906108c | 100 | |
95a42b64 TT |
101 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
102 | void *), | |
103 | void *); | |
c906108c | 104 | |
a14ed312 | 105 | static void ignore_command (char *, int); |
c906108c | 106 | |
4efb68b1 | 107 | static int breakpoint_re_set_one (void *); |
c906108c | 108 | |
348d480f PA |
109 | static void breakpoint_re_set_default (struct breakpoint *); |
110 | ||
983af33b SDJ |
111 | static void create_sals_from_address_default (char **, |
112 | struct linespec_result *, | |
113 | enum bptype, char *, | |
114 | char **); | |
115 | ||
116 | static void create_breakpoints_sal_default (struct gdbarch *, | |
117 | struct linespec_result *, | |
e7e0cddf | 118 | char *, char *, enum bptype, |
983af33b SDJ |
119 | enum bpdisp, int, int, |
120 | int, | |
121 | const struct breakpoint_ops *, | |
44f238bb | 122 | int, int, int, unsigned); |
983af33b SDJ |
123 | |
124 | static void decode_linespec_default (struct breakpoint *, char **, | |
125 | struct symtabs_and_lines *); | |
126 | ||
a14ed312 | 127 | static void clear_command (char *, int); |
c906108c | 128 | |
a14ed312 | 129 | static void catch_command (char *, int); |
c906108c | 130 | |
a9634178 | 131 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 132 | |
98deb0da | 133 | static void break_command_1 (char *, int, int); |
c906108c | 134 | |
a14ed312 | 135 | static void mention (struct breakpoint *); |
c906108c | 136 | |
348d480f PA |
137 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
138 | enum bptype, | |
c0a91b2b | 139 | const struct breakpoint_ops *); |
3742cc8b YQ |
140 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
141 | const struct symtab_and_line *); | |
142 | ||
4a64f543 MS |
143 | /* This function is used in gdbtk sources and thus can not be made |
144 | static. */ | |
63c252f8 | 145 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 146 | struct symtab_and_line, |
c0a91b2b TT |
147 | enum bptype, |
148 | const struct breakpoint_ops *); | |
c906108c | 149 | |
06edf0c0 PA |
150 | static struct breakpoint * |
151 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
152 | enum bptype type, | |
a1aa2221 LM |
153 | const struct breakpoint_ops *ops, |
154 | int loc_enabled); | |
06edf0c0 | 155 | |
76897487 KB |
156 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
157 | ||
a6d9a66e UW |
158 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
159 | CORE_ADDR bpaddr, | |
88f7da05 | 160 | enum bptype bptype); |
76897487 | 161 | |
6c95b8df PA |
162 | static void describe_other_breakpoints (struct gdbarch *, |
163 | struct program_space *, CORE_ADDR, | |
5af949e3 | 164 | struct obj_section *, int); |
c906108c | 165 | |
85d721b8 PA |
166 | static int watchpoint_locations_match (struct bp_location *loc1, |
167 | struct bp_location *loc2); | |
168 | ||
f1310107 TJB |
169 | static int breakpoint_location_address_match (struct bp_location *bl, |
170 | struct address_space *aspace, | |
171 | CORE_ADDR addr); | |
172 | ||
a14ed312 | 173 | static void breakpoints_info (char *, int); |
c906108c | 174 | |
d77f58be SS |
175 | static void watchpoints_info (char *, int); |
176 | ||
e5a67952 MS |
177 | static int breakpoint_1 (char *, int, |
178 | int (*) (const struct breakpoint *)); | |
c906108c | 179 | |
4efb68b1 | 180 | static int breakpoint_cond_eval (void *); |
c906108c | 181 | |
4efb68b1 | 182 | static void cleanup_executing_breakpoints (void *); |
c906108c | 183 | |
a14ed312 | 184 | static void commands_command (char *, int); |
c906108c | 185 | |
a14ed312 | 186 | static void condition_command (char *, int); |
c906108c | 187 | |
c5aa993b JM |
188 | typedef enum |
189 | { | |
190 | mark_inserted, | |
191 | mark_uninserted | |
192 | } | |
193 | insertion_state_t; | |
c906108c | 194 | |
0bde7532 | 195 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 196 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 197 | |
e514a9d6 | 198 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 199 | |
4efb68b1 | 200 | static int watchpoint_check (void *); |
c906108c | 201 | |
a14ed312 | 202 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 203 | |
a14ed312 | 204 | static int hw_breakpoint_used_count (void); |
c906108c | 205 | |
a1398e0c PA |
206 | static int hw_watchpoint_use_count (struct breakpoint *); |
207 | ||
208 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
209 | enum bptype type, | |
210 | int *other_type_used); | |
c906108c | 211 | |
a14ed312 | 212 | static void hbreak_command (char *, int); |
c906108c | 213 | |
a14ed312 | 214 | static void thbreak_command (char *, int); |
c906108c | 215 | |
816338b5 SS |
216 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
217 | int count); | |
c906108c | 218 | |
a14ed312 | 219 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 220 | |
a14ed312 | 221 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 222 | |
a14ed312 | 223 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 226 | |
fe3f5fa8 | 227 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
228 | static void incref_bp_location (struct bp_location *loc); |
229 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 230 | |
39d61571 | 231 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 232 | |
44702360 PA |
233 | /* update_global_location_list's modes of operation wrt to whether to |
234 | insert locations now. */ | |
235 | enum ugll_insert_mode | |
236 | { | |
237 | /* Don't insert any breakpoint locations into the inferior, only | |
238 | remove already-inserted locations that no longer should be | |
239 | inserted. Functions that delete a breakpoint or breakpoints | |
240 | should specify this mode, so that deleting a breakpoint doesn't | |
241 | have the side effect of inserting the locations of other | |
242 | breakpoints that are marked not-inserted, but should_be_inserted | |
243 | returns true on them. | |
244 | ||
245 | This behavior is useful is situations close to tear-down -- e.g., | |
246 | after an exec, while the target still has execution, but | |
247 | breakpoint shadows of the previous executable image should *NOT* | |
248 | be restored to the new image; or before detaching, where the | |
249 | target still has execution and wants to delete breakpoints from | |
250 | GDB's lists, and all breakpoints had already been removed from | |
251 | the inferior. */ | |
252 | UGLL_DONT_INSERT, | |
253 | ||
a25a5a45 PA |
254 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
255 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
256 | UGLL_MAY_INSERT, |
257 | ||
a25a5a45 PA |
258 | /* Insert locations now, irrespective of |
259 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
260 | stopped right now, and the user did "continue". We need to | |
261 | insert breakpoints _before_ resuming the target, but | |
262 | UGLL_MAY_INSERT wouldn't insert them, because | |
263 | breakpoints_should_be_inserted_now returns false at that point, | |
264 | as no thread is running yet. */ | |
04086b45 | 265 | UGLL_INSERT |
44702360 PA |
266 | }; |
267 | ||
268 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 269 | |
44702360 | 270 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 271 | |
d77f58be | 272 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
273 | |
274 | static void insert_breakpoint_locations (void); | |
a5606eee | 275 | |
1042e4c0 SS |
276 | static void tracepoints_info (char *, int); |
277 | ||
278 | static void delete_trace_command (char *, int); | |
279 | ||
280 | static void enable_trace_command (char *, int); | |
281 | ||
282 | static void disable_trace_command (char *, int); | |
283 | ||
284 | static void trace_pass_command (char *, int); | |
285 | ||
558a9d82 YQ |
286 | static void set_tracepoint_count (int num); |
287 | ||
9c06b0b4 TJB |
288 | static int is_masked_watchpoint (const struct breakpoint *b); |
289 | ||
b775012e LM |
290 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
291 | ||
983af33b SDJ |
292 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
293 | otherwise. */ | |
294 | ||
295 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 296 | |
2060206e PA |
297 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
298 | that are implemented on top of software or hardware breakpoints | |
299 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
300 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
301 | ||
302 | /* Internal breakpoints class type. */ | |
06edf0c0 | 303 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
304 | |
305 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
306 | static struct breakpoint_ops momentary_breakpoint_ops; |
307 | ||
e2e4d78b JK |
308 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
309 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
310 | ||
2060206e PA |
311 | /* The breakpoint_ops structure to be used in regular user created |
312 | breakpoints. */ | |
313 | struct breakpoint_ops bkpt_breakpoint_ops; | |
314 | ||
55aa24fb SDJ |
315 | /* Breakpoints set on probes. */ |
316 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
317 | ||
e7e0cddf | 318 | /* Dynamic printf class type. */ |
c5867ab6 | 319 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 320 | |
d3ce09f5 SS |
321 | /* The style in which to perform a dynamic printf. This is a user |
322 | option because different output options have different tradeoffs; | |
323 | if GDB does the printing, there is better error handling if there | |
324 | is a problem with any of the arguments, but using an inferior | |
325 | function lets you have special-purpose printers and sending of | |
326 | output to the same place as compiled-in print functions. */ | |
327 | ||
328 | static const char dprintf_style_gdb[] = "gdb"; | |
329 | static const char dprintf_style_call[] = "call"; | |
330 | static const char dprintf_style_agent[] = "agent"; | |
331 | static const char *const dprintf_style_enums[] = { | |
332 | dprintf_style_gdb, | |
333 | dprintf_style_call, | |
334 | dprintf_style_agent, | |
335 | NULL | |
336 | }; | |
337 | static const char *dprintf_style = dprintf_style_gdb; | |
338 | ||
339 | /* The function to use for dynamic printf if the preferred style is to | |
340 | call into the inferior. The value is simply a string that is | |
341 | copied into the command, so it can be anything that GDB can | |
342 | evaluate to a callable address, not necessarily a function name. */ | |
343 | ||
344 | static char *dprintf_function = ""; | |
345 | ||
346 | /* The channel to use for dynamic printf if the preferred style is to | |
347 | call into the inferior; if a nonempty string, it will be passed to | |
348 | the call as the first argument, with the format string as the | |
349 | second. As with the dprintf function, this can be anything that | |
350 | GDB knows how to evaluate, so in addition to common choices like | |
351 | "stderr", this could be an app-specific expression like | |
352 | "mystreams[curlogger]". */ | |
353 | ||
354 | static char *dprintf_channel = ""; | |
355 | ||
356 | /* True if dprintf commands should continue to operate even if GDB | |
357 | has disconnected. */ | |
358 | static int disconnected_dprintf = 1; | |
359 | ||
5cea2a26 PA |
360 | /* A reference-counted struct command_line. This lets multiple |
361 | breakpoints share a single command list. */ | |
362 | struct counted_command_line | |
363 | { | |
364 | /* The reference count. */ | |
365 | int refc; | |
366 | ||
367 | /* The command list. */ | |
368 | struct command_line *commands; | |
369 | }; | |
370 | ||
371 | struct command_line * | |
372 | breakpoint_commands (struct breakpoint *b) | |
373 | { | |
374 | return b->commands ? b->commands->commands : NULL; | |
375 | } | |
3daf8fe5 | 376 | |
f3b1572e PA |
377 | /* Flag indicating that a command has proceeded the inferior past the |
378 | current breakpoint. */ | |
379 | ||
380 | static int breakpoint_proceeded; | |
381 | ||
956a9fb9 | 382 | const char * |
2cec12e5 AR |
383 | bpdisp_text (enum bpdisp disp) |
384 | { | |
4a64f543 MS |
385 | /* NOTE: the following values are a part of MI protocol and |
386 | represent values of 'disp' field returned when inferior stops at | |
387 | a breakpoint. */ | |
bc043ef3 | 388 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 389 | |
2cec12e5 AR |
390 | return bpdisps[(int) disp]; |
391 | } | |
c906108c | 392 | |
4a64f543 | 393 | /* Prototypes for exported functions. */ |
c906108c | 394 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 395 | if such is available. */ |
c906108c SS |
396 | static int can_use_hw_watchpoints; |
397 | ||
920d2a44 AC |
398 | static void |
399 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
400 | struct cmd_list_element *c, | |
401 | const char *value) | |
402 | { | |
3e43a32a MS |
403 | fprintf_filtered (file, |
404 | _("Debugger's willingness to use " | |
405 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
406 | value); |
407 | } | |
408 | ||
fa8d40ab JJ |
409 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
410 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 411 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
412 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
413 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
414 | static void |
415 | show_pending_break_support (struct ui_file *file, int from_tty, | |
416 | struct cmd_list_element *c, | |
417 | const char *value) | |
418 | { | |
3e43a32a MS |
419 | fprintf_filtered (file, |
420 | _("Debugger's behavior regarding " | |
421 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
422 | value); |
423 | } | |
fa8d40ab | 424 | |
765dc015 | 425 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 426 | set with "break" but falling in read-only memory. |
765dc015 VP |
427 | If 0, gdb will warn about such breakpoints, but won't automatically |
428 | use hardware breakpoints. */ | |
429 | static int automatic_hardware_breakpoints; | |
430 | static void | |
431 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
432 | struct cmd_list_element *c, | |
433 | const char *value) | |
434 | { | |
3e43a32a MS |
435 | fprintf_filtered (file, |
436 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
437 | value); |
438 | } | |
439 | ||
a25a5a45 PA |
440 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
441 | stopped, and immediately inserts any new breakpoints as soon as | |
442 | they're created. If off (default), GDB keeps breakpoints off of | |
443 | the target as long as possible. That is, it delays inserting | |
444 | breakpoints until the next resume, and removes them again when the | |
445 | target fully stops. This is a bit safer in case GDB crashes while | |
446 | processing user input. */ | |
447 | static int always_inserted_mode = 0; | |
72d0e2c5 | 448 | |
33e5cbd6 | 449 | static void |
74960c60 | 450 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 451 | struct cmd_list_element *c, const char *value) |
74960c60 | 452 | { |
a25a5a45 PA |
453 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
454 | value); | |
74960c60 VP |
455 | } |
456 | ||
b57bacec PA |
457 | /* See breakpoint.h. */ |
458 | ||
33e5cbd6 | 459 | int |
a25a5a45 | 460 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 461 | { |
a25a5a45 PA |
462 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
463 | { | |
464 | /* If breakpoints are global, they should be inserted even if no | |
465 | thread under gdb's control is running, or even if there are | |
466 | no threads under GDB's control yet. */ | |
467 | return 1; | |
468 | } | |
469 | else if (target_has_execution) | |
470 | { | |
a25a5a45 PA |
471 | if (always_inserted_mode) |
472 | { | |
473 | /* The user wants breakpoints inserted even if all threads | |
474 | are stopped. */ | |
475 | return 1; | |
476 | } | |
477 | ||
b57bacec PA |
478 | if (threads_are_executing ()) |
479 | return 1; | |
a25a5a45 PA |
480 | } |
481 | return 0; | |
33e5cbd6 | 482 | } |
765dc015 | 483 | |
b775012e LM |
484 | static const char condition_evaluation_both[] = "host or target"; |
485 | ||
486 | /* Modes for breakpoint condition evaluation. */ | |
487 | static const char condition_evaluation_auto[] = "auto"; | |
488 | static const char condition_evaluation_host[] = "host"; | |
489 | static const char condition_evaluation_target[] = "target"; | |
490 | static const char *const condition_evaluation_enums[] = { | |
491 | condition_evaluation_auto, | |
492 | condition_evaluation_host, | |
493 | condition_evaluation_target, | |
494 | NULL | |
495 | }; | |
496 | ||
497 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
498 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
499 | ||
500 | /* Global that we use to display information to the user (gets its value from | |
501 | condition_evaluation_mode_1. */ | |
502 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
503 | ||
504 | /* Translate a condition evaluation mode MODE into either "host" | |
505 | or "target". This is used mostly to translate from "auto" to the | |
506 | real setting that is being used. It returns the translated | |
507 | evaluation mode. */ | |
508 | ||
509 | static const char * | |
510 | translate_condition_evaluation_mode (const char *mode) | |
511 | { | |
512 | if (mode == condition_evaluation_auto) | |
513 | { | |
514 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
515 | return condition_evaluation_target; | |
516 | else | |
517 | return condition_evaluation_host; | |
518 | } | |
519 | else | |
520 | return mode; | |
521 | } | |
522 | ||
523 | /* Discovers what condition_evaluation_auto translates to. */ | |
524 | ||
525 | static const char * | |
526 | breakpoint_condition_evaluation_mode (void) | |
527 | { | |
528 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
529 | } | |
530 | ||
531 | /* Return true if GDB should evaluate breakpoint conditions or false | |
532 | otherwise. */ | |
533 | ||
534 | static int | |
535 | gdb_evaluates_breakpoint_condition_p (void) | |
536 | { | |
537 | const char *mode = breakpoint_condition_evaluation_mode (); | |
538 | ||
539 | return (mode == condition_evaluation_host); | |
540 | } | |
541 | ||
a14ed312 | 542 | void _initialize_breakpoint (void); |
c906108c | 543 | |
c906108c SS |
544 | /* Are we executing breakpoint commands? */ |
545 | static int executing_breakpoint_commands; | |
546 | ||
c02f5703 MS |
547 | /* Are overlay event breakpoints enabled? */ |
548 | static int overlay_events_enabled; | |
549 | ||
e09342b5 TJB |
550 | /* See description in breakpoint.h. */ |
551 | int target_exact_watchpoints = 0; | |
552 | ||
c906108c | 553 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 554 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 555 | current breakpoint. */ |
c906108c | 556 | |
5c44784c | 557 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 558 | |
5c44784c JM |
559 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
560 | for (B = breakpoint_chain; \ | |
561 | B ? (TMP=B->next, 1): 0; \ | |
562 | B = TMP) | |
c906108c | 563 | |
4a64f543 MS |
564 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
565 | not provided so update_global_location_list must not be called | |
566 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 567 | |
876fa593 JK |
568 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
569 | for (BP_TMP = bp_location; \ | |
570 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
571 | BP_TMP++) | |
7cc221ef | 572 | |
b775012e LM |
573 | /* Iterates through locations with address ADDRESS for the currently selected |
574 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
575 | to where the loop should start from. | |
576 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
577 | appropriate location to start with. */ | |
578 | ||
579 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
580 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
581 | BP_LOCP_TMP = BP_LOCP_START; \ | |
582 | BP_LOCP_START \ | |
583 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
584 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
585 | BP_LOCP_TMP++) | |
586 | ||
1042e4c0 SS |
587 | /* Iterator for tracepoints only. */ |
588 | ||
589 | #define ALL_TRACEPOINTS(B) \ | |
590 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 591 | if (is_tracepoint (B)) |
1042e4c0 | 592 | |
7cc221ef | 593 | /* Chains of all breakpoints defined. */ |
c906108c SS |
594 | |
595 | struct breakpoint *breakpoint_chain; | |
596 | ||
876fa593 JK |
597 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
598 | ||
599 | static struct bp_location **bp_location; | |
600 | ||
601 | /* Number of elements of BP_LOCATION. */ | |
602 | ||
603 | static unsigned bp_location_count; | |
604 | ||
4a64f543 MS |
605 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
606 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
607 | result from bp_location_has_shadow. You can use it for roughly | |
608 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
609 | an address you need to read. */ | |
876fa593 JK |
610 | |
611 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
612 | ||
4a64f543 MS |
613 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
614 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
615 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
616 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
617 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
618 | |
619 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 620 | |
4a64f543 MS |
621 | /* The locations that no longer correspond to any breakpoint, unlinked |
622 | from bp_location array, but for which a hit may still be reported | |
623 | by a target. */ | |
20874c92 VP |
624 | VEC(bp_location_p) *moribund_locations = NULL; |
625 | ||
c906108c SS |
626 | /* Number of last breakpoint made. */ |
627 | ||
95a42b64 TT |
628 | static int breakpoint_count; |
629 | ||
86b17b60 PA |
630 | /* The value of `breakpoint_count' before the last command that |
631 | created breakpoints. If the last (break-like) command created more | |
632 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
633 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
634 | static int prev_breakpoint_count; | |
c906108c | 635 | |
1042e4c0 SS |
636 | /* Number of last tracepoint made. */ |
637 | ||
95a42b64 | 638 | static int tracepoint_count; |
1042e4c0 | 639 | |
6149aea9 PA |
640 | static struct cmd_list_element *breakpoint_set_cmdlist; |
641 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 642 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 643 | |
badd37ce SDJ |
644 | /* See declaration at breakpoint.h. */ |
645 | ||
646 | struct breakpoint * | |
647 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
648 | void *user_data) | |
649 | { | |
650 | struct breakpoint *b = NULL; | |
651 | ||
652 | ALL_BREAKPOINTS (b) | |
653 | { | |
654 | if (func (b, user_data) != 0) | |
655 | break; | |
656 | } | |
657 | ||
658 | return b; | |
659 | } | |
660 | ||
468d015d JJ |
661 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
662 | static int | |
663 | breakpoint_enabled (struct breakpoint *b) | |
664 | { | |
0d381245 | 665 | return (b->enable_state == bp_enabled); |
468d015d JJ |
666 | } |
667 | ||
c906108c SS |
668 | /* Set breakpoint count to NUM. */ |
669 | ||
95a42b64 | 670 | static void |
fba45db2 | 671 | set_breakpoint_count (int num) |
c906108c | 672 | { |
86b17b60 | 673 | prev_breakpoint_count = breakpoint_count; |
c906108c | 674 | breakpoint_count = num; |
4fa62494 | 675 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
676 | } |
677 | ||
86b17b60 PA |
678 | /* Used by `start_rbreak_breakpoints' below, to record the current |
679 | breakpoint count before "rbreak" creates any breakpoint. */ | |
680 | static int rbreak_start_breakpoint_count; | |
681 | ||
95a42b64 TT |
682 | /* Called at the start an "rbreak" command to record the first |
683 | breakpoint made. */ | |
86b17b60 | 684 | |
95a42b64 TT |
685 | void |
686 | start_rbreak_breakpoints (void) | |
687 | { | |
86b17b60 | 688 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
689 | } |
690 | ||
691 | /* Called at the end of an "rbreak" command to record the last | |
692 | breakpoint made. */ | |
86b17b60 | 693 | |
95a42b64 TT |
694 | void |
695 | end_rbreak_breakpoints (void) | |
696 | { | |
86b17b60 | 697 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
698 | } |
699 | ||
4a64f543 | 700 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
701 | |
702 | void | |
fba45db2 | 703 | clear_breakpoint_hit_counts (void) |
c906108c SS |
704 | { |
705 | struct breakpoint *b; | |
706 | ||
707 | ALL_BREAKPOINTS (b) | |
708 | b->hit_count = 0; | |
709 | } | |
710 | ||
9add0f1b TT |
711 | /* Allocate a new counted_command_line with reference count of 1. |
712 | The new structure owns COMMANDS. */ | |
713 | ||
714 | static struct counted_command_line * | |
715 | alloc_counted_command_line (struct command_line *commands) | |
716 | { | |
717 | struct counted_command_line *result | |
718 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 719 | |
9add0f1b TT |
720 | result->refc = 1; |
721 | result->commands = commands; | |
722 | return result; | |
723 | } | |
724 | ||
725 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
726 | ||
727 | static void | |
728 | incref_counted_command_line (struct counted_command_line *cmd) | |
729 | { | |
730 | if (cmd) | |
731 | ++cmd->refc; | |
732 | } | |
733 | ||
734 | /* Decrement reference count. If the reference count reaches 0, | |
735 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
736 | nothing if *CMDP is NULL. */ | |
737 | ||
738 | static void | |
739 | decref_counted_command_line (struct counted_command_line **cmdp) | |
740 | { | |
741 | if (*cmdp) | |
742 | { | |
743 | if (--(*cmdp)->refc == 0) | |
744 | { | |
745 | free_command_lines (&(*cmdp)->commands); | |
746 | xfree (*cmdp); | |
747 | } | |
748 | *cmdp = NULL; | |
749 | } | |
750 | } | |
751 | ||
752 | /* A cleanup function that calls decref_counted_command_line. */ | |
753 | ||
754 | static void | |
755 | do_cleanup_counted_command_line (void *arg) | |
756 | { | |
757 | decref_counted_command_line (arg); | |
758 | } | |
759 | ||
760 | /* Create a cleanup that calls decref_counted_command_line on the | |
761 | argument. */ | |
762 | ||
763 | static struct cleanup * | |
764 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
765 | { | |
766 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
767 | } | |
768 | ||
c906108c | 769 | \f |
48cb2d85 VP |
770 | /* Return the breakpoint with the specified number, or NULL |
771 | if the number does not refer to an existing breakpoint. */ | |
772 | ||
773 | struct breakpoint * | |
774 | get_breakpoint (int num) | |
775 | { | |
776 | struct breakpoint *b; | |
777 | ||
778 | ALL_BREAKPOINTS (b) | |
779 | if (b->number == num) | |
780 | return b; | |
781 | ||
782 | return NULL; | |
783 | } | |
5c44784c | 784 | |
c906108c | 785 | \f |
adc36818 | 786 | |
b775012e LM |
787 | /* Mark locations as "conditions have changed" in case the target supports |
788 | evaluating conditions on its side. */ | |
789 | ||
790 | static void | |
791 | mark_breakpoint_modified (struct breakpoint *b) | |
792 | { | |
793 | struct bp_location *loc; | |
794 | ||
795 | /* This is only meaningful if the target is | |
796 | evaluating conditions and if the user has | |
797 | opted for condition evaluation on the target's | |
798 | side. */ | |
799 | if (gdb_evaluates_breakpoint_condition_p () | |
800 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
801 | return; | |
802 | ||
803 | if (!is_breakpoint (b)) | |
804 | return; | |
805 | ||
806 | for (loc = b->loc; loc; loc = loc->next) | |
807 | loc->condition_changed = condition_modified; | |
808 | } | |
809 | ||
810 | /* Mark location as "conditions have changed" in case the target supports | |
811 | evaluating conditions on its side. */ | |
812 | ||
813 | static void | |
814 | mark_breakpoint_location_modified (struct bp_location *loc) | |
815 | { | |
816 | /* This is only meaningful if the target is | |
817 | evaluating conditions and if the user has | |
818 | opted for condition evaluation on the target's | |
819 | side. */ | |
820 | if (gdb_evaluates_breakpoint_condition_p () | |
821 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
822 | ||
823 | return; | |
824 | ||
825 | if (!is_breakpoint (loc->owner)) | |
826 | return; | |
827 | ||
828 | loc->condition_changed = condition_modified; | |
829 | } | |
830 | ||
831 | /* Sets the condition-evaluation mode using the static global | |
832 | condition_evaluation_mode. */ | |
833 | ||
834 | static void | |
835 | set_condition_evaluation_mode (char *args, int from_tty, | |
836 | struct cmd_list_element *c) | |
837 | { | |
b775012e LM |
838 | const char *old_mode, *new_mode; |
839 | ||
840 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
841 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
842 | { | |
843 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
844 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
845 | "Using host evaluation mode instead.")); | |
846 | return; | |
847 | } | |
848 | ||
849 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
850 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
851 | ||
abf1152a JK |
852 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
853 | settings was "auto". */ | |
854 | condition_evaluation_mode = condition_evaluation_mode_1; | |
855 | ||
b775012e LM |
856 | /* Only update the mode if the user picked a different one. */ |
857 | if (new_mode != old_mode) | |
858 | { | |
859 | struct bp_location *loc, **loc_tmp; | |
860 | /* If the user switched to a different evaluation mode, we | |
861 | need to synch the changes with the target as follows: | |
862 | ||
863 | "host" -> "target": Send all (valid) conditions to the target. | |
864 | "target" -> "host": Remove all the conditions from the target. | |
865 | */ | |
866 | ||
b775012e LM |
867 | if (new_mode == condition_evaluation_target) |
868 | { | |
869 | /* Mark everything modified and synch conditions with the | |
870 | target. */ | |
871 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
872 | mark_breakpoint_location_modified (loc); | |
873 | } | |
874 | else | |
875 | { | |
876 | /* Manually mark non-duplicate locations to synch conditions | |
877 | with the target. We do this to remove all the conditions the | |
878 | target knows about. */ | |
879 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
880 | if (is_breakpoint (loc->owner) && loc->inserted) | |
881 | loc->needs_update = 1; | |
882 | } | |
883 | ||
884 | /* Do the update. */ | |
44702360 | 885 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
886 | } |
887 | ||
888 | return; | |
889 | } | |
890 | ||
891 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
892 | what "auto" is translating to. */ | |
893 | ||
894 | static void | |
895 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
896 | struct cmd_list_element *c, const char *value) | |
897 | { | |
898 | if (condition_evaluation_mode == condition_evaluation_auto) | |
899 | fprintf_filtered (file, | |
900 | _("Breakpoint condition evaluation " | |
901 | "mode is %s (currently %s).\n"), | |
902 | value, | |
903 | breakpoint_condition_evaluation_mode ()); | |
904 | else | |
905 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
906 | value); | |
907 | } | |
908 | ||
909 | /* A comparison function for bp_location AP and BP that is used by | |
910 | bsearch. This comparison function only cares about addresses, unlike | |
911 | the more general bp_location_compare function. */ | |
912 | ||
913 | static int | |
914 | bp_location_compare_addrs (const void *ap, const void *bp) | |
915 | { | |
916 | struct bp_location *a = *(void **) ap; | |
917 | struct bp_location *b = *(void **) bp; | |
918 | ||
919 | if (a->address == b->address) | |
920 | return 0; | |
921 | else | |
922 | return ((a->address > b->address) - (a->address < b->address)); | |
923 | } | |
924 | ||
925 | /* Helper function to skip all bp_locations with addresses | |
926 | less than ADDRESS. It returns the first bp_location that | |
927 | is greater than or equal to ADDRESS. If none is found, just | |
928 | return NULL. */ | |
929 | ||
930 | static struct bp_location ** | |
931 | get_first_locp_gte_addr (CORE_ADDR address) | |
932 | { | |
933 | struct bp_location dummy_loc; | |
934 | struct bp_location *dummy_locp = &dummy_loc; | |
935 | struct bp_location **locp_found = NULL; | |
936 | ||
937 | /* Initialize the dummy location's address field. */ | |
938 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
939 | dummy_loc.address = address; | |
940 | ||
941 | /* Find a close match to the first location at ADDRESS. */ | |
942 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
943 | sizeof (struct bp_location **), | |
944 | bp_location_compare_addrs); | |
945 | ||
946 | /* Nothing was found, nothing left to do. */ | |
947 | if (locp_found == NULL) | |
948 | return NULL; | |
949 | ||
950 | /* We may have found a location that is at ADDRESS but is not the first in the | |
951 | location's list. Go backwards (if possible) and locate the first one. */ | |
952 | while ((locp_found - 1) >= bp_location | |
953 | && (*(locp_found - 1))->address == address) | |
954 | locp_found--; | |
955 | ||
956 | return locp_found; | |
957 | } | |
958 | ||
adc36818 | 959 | void |
7a26bd4d | 960 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
961 | int from_tty) |
962 | { | |
3a5c3e22 PA |
963 | xfree (b->cond_string); |
964 | b->cond_string = NULL; | |
adc36818 | 965 | |
3a5c3e22 | 966 | if (is_watchpoint (b)) |
adc36818 | 967 | { |
3a5c3e22 PA |
968 | struct watchpoint *w = (struct watchpoint *) b; |
969 | ||
970 | xfree (w->cond_exp); | |
971 | w->cond_exp = NULL; | |
972 | } | |
973 | else | |
974 | { | |
975 | struct bp_location *loc; | |
976 | ||
977 | for (loc = b->loc; loc; loc = loc->next) | |
978 | { | |
979 | xfree (loc->cond); | |
980 | loc->cond = NULL; | |
b775012e LM |
981 | |
982 | /* No need to free the condition agent expression | |
983 | bytecode (if we have one). We will handle this | |
984 | when we go through update_global_location_list. */ | |
3a5c3e22 | 985 | } |
adc36818 | 986 | } |
adc36818 PM |
987 | |
988 | if (*exp == 0) | |
989 | { | |
990 | if (from_tty) | |
991 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
992 | } | |
993 | else | |
994 | { | |
bbc13ae3 | 995 | const char *arg = exp; |
cc59ec59 | 996 | |
adc36818 PM |
997 | /* I don't know if it matters whether this is the string the user |
998 | typed in or the decompiled expression. */ | |
999 | b->cond_string = xstrdup (arg); | |
1000 | b->condition_not_parsed = 0; | |
1001 | ||
1002 | if (is_watchpoint (b)) | |
1003 | { | |
3a5c3e22 PA |
1004 | struct watchpoint *w = (struct watchpoint *) b; |
1005 | ||
adc36818 PM |
1006 | innermost_block = NULL; |
1007 | arg = exp; | |
1bb9788d | 1008 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1009 | if (*arg) |
1010 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1011 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1012 | } |
1013 | else | |
1014 | { | |
3a5c3e22 PA |
1015 | struct bp_location *loc; |
1016 | ||
adc36818 PM |
1017 | for (loc = b->loc; loc; loc = loc->next) |
1018 | { | |
1019 | arg = exp; | |
1020 | loc->cond = | |
1bb9788d TT |
1021 | parse_exp_1 (&arg, loc->address, |
1022 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1023 | if (*arg) |
1024 | error (_("Junk at end of expression")); | |
1025 | } | |
1026 | } | |
1027 | } | |
b775012e LM |
1028 | mark_breakpoint_modified (b); |
1029 | ||
8d3788bd | 1030 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1031 | } |
1032 | ||
d55637df TT |
1033 | /* Completion for the "condition" command. */ |
1034 | ||
1035 | static VEC (char_ptr) * | |
6f937416 PA |
1036 | condition_completer (struct cmd_list_element *cmd, |
1037 | const char *text, const char *word) | |
d55637df | 1038 | { |
6f937416 | 1039 | const char *space; |
d55637df | 1040 | |
6f937416 PA |
1041 | text = skip_spaces_const (text); |
1042 | space = skip_to_space_const (text); | |
d55637df TT |
1043 | if (*space == '\0') |
1044 | { | |
1045 | int len; | |
1046 | struct breakpoint *b; | |
1047 | VEC (char_ptr) *result = NULL; | |
1048 | ||
1049 | if (text[0] == '$') | |
1050 | { | |
1051 | /* We don't support completion of history indices. */ | |
1052 | if (isdigit (text[1])) | |
1053 | return NULL; | |
1054 | return complete_internalvar (&text[1]); | |
1055 | } | |
1056 | ||
1057 | /* We're completing the breakpoint number. */ | |
1058 | len = strlen (text); | |
1059 | ||
1060 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1061 | { |
1062 | char number[50]; | |
1063 | ||
1064 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1065 | ||
1066 | if (strncmp (number, text, len) == 0) | |
1067 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1068 | } | |
d55637df TT |
1069 | |
1070 | return result; | |
1071 | } | |
1072 | ||
1073 | /* We're completing the expression part. */ | |
6f937416 | 1074 | text = skip_spaces_const (space); |
d55637df TT |
1075 | return expression_completer (cmd, text, word); |
1076 | } | |
1077 | ||
c906108c SS |
1078 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1079 | ||
1080 | static void | |
fba45db2 | 1081 | condition_command (char *arg, int from_tty) |
c906108c | 1082 | { |
52f0bd74 | 1083 | struct breakpoint *b; |
c906108c | 1084 | char *p; |
52f0bd74 | 1085 | int bnum; |
c906108c SS |
1086 | |
1087 | if (arg == 0) | |
e2e0b3e5 | 1088 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1089 | |
1090 | p = arg; | |
1091 | bnum = get_number (&p); | |
5c44784c | 1092 | if (bnum == 0) |
8a3fe4f8 | 1093 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1094 | |
1095 | ALL_BREAKPOINTS (b) | |
1096 | if (b->number == bnum) | |
2f069f6f | 1097 | { |
6dddc817 DE |
1098 | /* Check if this breakpoint has a "stop" method implemented in an |
1099 | extension language. This method and conditions entered into GDB | |
1100 | from the CLI are mutually exclusive. */ | |
1101 | const struct extension_language_defn *extlang | |
1102 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1103 | ||
1104 | if (extlang != NULL) | |
1105 | { | |
1106 | error (_("Only one stop condition allowed. There is currently" | |
1107 | " a %s stop condition defined for this breakpoint."), | |
1108 | ext_lang_capitalized_name (extlang)); | |
1109 | } | |
2566ad2d | 1110 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1111 | |
1112 | if (is_breakpoint (b)) | |
44702360 | 1113 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1114 | |
2f069f6f JB |
1115 | return; |
1116 | } | |
c906108c | 1117 | |
8a3fe4f8 | 1118 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1119 | } |
1120 | ||
a7bdde9e VP |
1121 | /* Check that COMMAND do not contain commands that are suitable |
1122 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1123 | Throw if any such commands is found. */ |
1124 | ||
a7bdde9e VP |
1125 | static void |
1126 | check_no_tracepoint_commands (struct command_line *commands) | |
1127 | { | |
1128 | struct command_line *c; | |
cc59ec59 | 1129 | |
a7bdde9e VP |
1130 | for (c = commands; c; c = c->next) |
1131 | { | |
1132 | int i; | |
1133 | ||
1134 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1135 | error (_("The 'while-stepping' command can " |
1136 | "only be used for tracepoints")); | |
a7bdde9e VP |
1137 | |
1138 | for (i = 0; i < c->body_count; ++i) | |
1139 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1140 | ||
1141 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1142 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1143 | command directly. */ |
1144 | if (strstr (c->line, "collect ") == c->line) | |
1145 | error (_("The 'collect' command can only be used for tracepoints")); | |
1146 | ||
51661e93 VP |
1147 | if (strstr (c->line, "teval ") == c->line) |
1148 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1149 | } |
1150 | } | |
1151 | ||
d77f58be SS |
1152 | /* Encapsulate tests for different types of tracepoints. */ |
1153 | ||
d9b3f62e PA |
1154 | static int |
1155 | is_tracepoint_type (enum bptype type) | |
1156 | { | |
1157 | return (type == bp_tracepoint | |
1158 | || type == bp_fast_tracepoint | |
1159 | || type == bp_static_tracepoint); | |
1160 | } | |
1161 | ||
a7bdde9e | 1162 | int |
d77f58be | 1163 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1164 | { |
d9b3f62e | 1165 | return is_tracepoint_type (b->type); |
a7bdde9e | 1166 | } |
d9b3f62e | 1167 | |
e5dd4106 | 1168 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1169 | breakpoint. This function will throw an exception if a problem is |
1170 | found. */ | |
48cb2d85 | 1171 | |
95a42b64 TT |
1172 | static void |
1173 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1174 | struct command_line *commands) | |
48cb2d85 | 1175 | { |
d77f58be | 1176 | if (is_tracepoint (b)) |
a7bdde9e | 1177 | { |
c9a6ce02 | 1178 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1179 | struct command_line *c; |
1180 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1181 | |
1182 | /* Reset the while-stepping step count. The previous commands | |
1183 | might have included a while-stepping action, while the new | |
1184 | ones might not. */ | |
1185 | t->step_count = 0; | |
1186 | ||
1187 | /* We need to verify that each top-level element of commands is | |
1188 | valid for tracepoints, that there's at most one | |
1189 | while-stepping element, and that the while-stepping's body | |
1190 | has valid tracing commands excluding nested while-stepping. | |
1191 | We also need to validate the tracepoint action line in the | |
1192 | context of the tracepoint --- validate_actionline actually | |
1193 | has side effects, like setting the tracepoint's | |
1194 | while-stepping STEP_COUNT, in addition to checking if the | |
1195 | collect/teval actions parse and make sense in the | |
1196 | tracepoint's context. */ | |
a7bdde9e VP |
1197 | for (c = commands; c; c = c->next) |
1198 | { | |
a7bdde9e VP |
1199 | if (c->control_type == while_stepping_control) |
1200 | { | |
1201 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1202 | error (_("The 'while-stepping' command " |
1203 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1204 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1205 | error (_("The 'while-stepping' command " |
1206 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1207 | |
1208 | if (while_stepping) | |
3e43a32a MS |
1209 | error (_("The 'while-stepping' command " |
1210 | "can be used only once")); | |
a7bdde9e VP |
1211 | else |
1212 | while_stepping = c; | |
1213 | } | |
c9a6ce02 PA |
1214 | |
1215 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1216 | } |
1217 | if (while_stepping) | |
1218 | { | |
1219 | struct command_line *c2; | |
1220 | ||
1221 | gdb_assert (while_stepping->body_count == 1); | |
1222 | c2 = while_stepping->body_list[0]; | |
1223 | for (; c2; c2 = c2->next) | |
1224 | { | |
a7bdde9e VP |
1225 | if (c2->control_type == while_stepping_control) |
1226 | error (_("The 'while-stepping' command cannot be nested")); | |
1227 | } | |
1228 | } | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | check_no_tracepoint_commands (commands); | |
1233 | } | |
95a42b64 TT |
1234 | } |
1235 | ||
0fb4aa4b PA |
1236 | /* Return a vector of all the static tracepoints set at ADDR. The |
1237 | caller is responsible for releasing the vector. */ | |
1238 | ||
1239 | VEC(breakpoint_p) * | |
1240 | static_tracepoints_here (CORE_ADDR addr) | |
1241 | { | |
1242 | struct breakpoint *b; | |
1243 | VEC(breakpoint_p) *found = 0; | |
1244 | struct bp_location *loc; | |
1245 | ||
1246 | ALL_BREAKPOINTS (b) | |
1247 | if (b->type == bp_static_tracepoint) | |
1248 | { | |
1249 | for (loc = b->loc; loc; loc = loc->next) | |
1250 | if (loc->address == addr) | |
1251 | VEC_safe_push(breakpoint_p, found, b); | |
1252 | } | |
1253 | ||
1254 | return found; | |
1255 | } | |
1256 | ||
95a42b64 | 1257 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1258 | validate that only allowed commands are included. */ |
95a42b64 TT |
1259 | |
1260 | void | |
4a64f543 MS |
1261 | breakpoint_set_commands (struct breakpoint *b, |
1262 | struct command_line *commands) | |
95a42b64 TT |
1263 | { |
1264 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1265 | |
9add0f1b TT |
1266 | decref_counted_command_line (&b->commands); |
1267 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1268 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1269 | } |
1270 | ||
45a43567 TT |
1271 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1272 | is not the same as the "silent" that may appear in the breakpoint's | |
1273 | commands. */ | |
1274 | ||
1275 | void | |
1276 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1277 | { | |
1278 | int old_silent = b->silent; | |
1279 | ||
1280 | b->silent = silent; | |
1281 | if (old_silent != silent) | |
8d3788bd | 1282 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1283 | } |
1284 | ||
1285 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1286 | breakpoint work for any thread. */ | |
1287 | ||
1288 | void | |
1289 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1290 | { | |
1291 | int old_thread = b->thread; | |
1292 | ||
1293 | b->thread = thread; | |
1294 | if (old_thread != thread) | |
8d3788bd | 1295 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1296 | } |
1297 | ||
1298 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1299 | breakpoint work for any task. */ | |
1300 | ||
1301 | void | |
1302 | breakpoint_set_task (struct breakpoint *b, int task) | |
1303 | { | |
1304 | int old_task = b->task; | |
1305 | ||
1306 | b->task = task; | |
1307 | if (old_task != task) | |
8d3788bd | 1308 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1309 | } |
1310 | ||
95a42b64 TT |
1311 | void |
1312 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1313 | { |
1314 | struct breakpoint *b = closure; | |
cc59ec59 | 1315 | |
6f937416 | 1316 | validate_actionline (line, b); |
a7bdde9e VP |
1317 | } |
1318 | ||
95a42b64 TT |
1319 | /* A structure used to pass information through |
1320 | map_breakpoint_numbers. */ | |
1321 | ||
1322 | struct commands_info | |
1323 | { | |
1324 | /* True if the command was typed at a tty. */ | |
1325 | int from_tty; | |
86b17b60 PA |
1326 | |
1327 | /* The breakpoint range spec. */ | |
1328 | char *arg; | |
1329 | ||
95a42b64 TT |
1330 | /* Non-NULL if the body of the commands are being read from this |
1331 | already-parsed command. */ | |
1332 | struct command_line *control; | |
86b17b60 | 1333 | |
95a42b64 TT |
1334 | /* The command lines read from the user, or NULL if they have not |
1335 | yet been read. */ | |
1336 | struct counted_command_line *cmd; | |
1337 | }; | |
1338 | ||
1339 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1340 | commands_command. */ | |
1341 | ||
c906108c | 1342 | static void |
95a42b64 | 1343 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1344 | { |
95a42b64 | 1345 | struct commands_info *info = data; |
c906108c | 1346 | |
95a42b64 TT |
1347 | if (info->cmd == NULL) |
1348 | { | |
1349 | struct command_line *l; | |
5c44784c | 1350 | |
95a42b64 TT |
1351 | if (info->control != NULL) |
1352 | l = copy_command_lines (info->control->body_list[0]); | |
1353 | else | |
86b17b60 PA |
1354 | { |
1355 | struct cleanup *old_chain; | |
1356 | char *str; | |
c5aa993b | 1357 | |
3e43a32a MS |
1358 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1359 | "%s, one per line."), | |
86b17b60 PA |
1360 | info->arg); |
1361 | ||
1362 | old_chain = make_cleanup (xfree, str); | |
1363 | ||
1364 | l = read_command_lines (str, | |
1365 | info->from_tty, 1, | |
d77f58be | 1366 | (is_tracepoint (b) |
86b17b60 PA |
1367 | ? check_tracepoint_command : 0), |
1368 | b); | |
1369 | ||
1370 | do_cleanups (old_chain); | |
1371 | } | |
a7bdde9e | 1372 | |
95a42b64 TT |
1373 | info->cmd = alloc_counted_command_line (l); |
1374 | } | |
1375 | ||
1376 | /* If a breakpoint was on the list more than once, we don't need to | |
1377 | do anything. */ | |
1378 | if (b->commands != info->cmd) | |
1379 | { | |
1380 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1381 | incref_counted_command_line (info->cmd); | |
1382 | decref_counted_command_line (&b->commands); | |
1383 | b->commands = info->cmd; | |
8d3788bd | 1384 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1385 | } |
95a42b64 TT |
1386 | } |
1387 | ||
1388 | static void | |
4a64f543 MS |
1389 | commands_command_1 (char *arg, int from_tty, |
1390 | struct command_line *control) | |
95a42b64 TT |
1391 | { |
1392 | struct cleanup *cleanups; | |
1393 | struct commands_info info; | |
1394 | ||
1395 | info.from_tty = from_tty; | |
1396 | info.control = control; | |
1397 | info.cmd = NULL; | |
1398 | /* If we read command lines from the user, then `info' will hold an | |
1399 | extra reference to the commands that we must clean up. */ | |
1400 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1401 | ||
1402 | if (arg == NULL || !*arg) | |
1403 | { | |
86b17b60 | 1404 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1405 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1406 | breakpoint_count); | |
95a42b64 TT |
1407 | else if (breakpoint_count > 0) |
1408 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1409 | else |
1410 | { | |
1411 | /* So that we don't try to free the incoming non-NULL | |
1412 | argument in the cleanup below. Mapping breakpoint | |
1413 | numbers will fail in this case. */ | |
1414 | arg = NULL; | |
1415 | } | |
95a42b64 | 1416 | } |
9766ced4 SS |
1417 | else |
1418 | /* The command loop has some static state, so we need to preserve | |
1419 | our argument. */ | |
1420 | arg = xstrdup (arg); | |
86b17b60 PA |
1421 | |
1422 | if (arg != NULL) | |
1423 | make_cleanup (xfree, arg); | |
1424 | ||
1425 | info.arg = arg; | |
95a42b64 TT |
1426 | |
1427 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1428 | ||
1429 | if (info.cmd == NULL) | |
1430 | error (_("No breakpoints specified.")); | |
1431 | ||
1432 | do_cleanups (cleanups); | |
1433 | } | |
1434 | ||
1435 | static void | |
1436 | commands_command (char *arg, int from_tty) | |
1437 | { | |
1438 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1439 | } |
40c03ae8 EZ |
1440 | |
1441 | /* Like commands_command, but instead of reading the commands from | |
1442 | input stream, takes them from an already parsed command structure. | |
1443 | ||
1444 | This is used by cli-script.c to DTRT with breakpoint commands | |
1445 | that are part of if and while bodies. */ | |
1446 | enum command_control_type | |
1447 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1448 | { | |
95a42b64 TT |
1449 | commands_command_1 (arg, 0, cmd); |
1450 | return simple_control; | |
40c03ae8 | 1451 | } |
876fa593 JK |
1452 | |
1453 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1454 | ||
1455 | static int | |
1456 | bp_location_has_shadow (struct bp_location *bl) | |
1457 | { | |
1458 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1459 | return 0; | |
1460 | if (!bl->inserted) | |
1461 | return 0; | |
1462 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1463 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1464 | return 0; |
1465 | return 1; | |
1466 | } | |
1467 | ||
9d497a19 PA |
1468 | /* Update BUF, which is LEN bytes read from the target address |
1469 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1470 | contents. | |
1471 | ||
1472 | If READBUF is not NULL, this buffer must not overlap with the of | |
1473 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1474 | failed assertion internal error will be raised. */ | |
1475 | ||
1476 | static void | |
1477 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1478 | const gdb_byte *writebuf_org, | |
1479 | ULONGEST memaddr, LONGEST len, | |
1480 | struct bp_target_info *target_info, | |
1481 | struct gdbarch *gdbarch) | |
1482 | { | |
1483 | /* Now do full processing of the found relevant range of elements. */ | |
1484 | CORE_ADDR bp_addr = 0; | |
1485 | int bp_size = 0; | |
1486 | int bptoffset = 0; | |
1487 | ||
1488 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1489 | current_program_space->aspace, 0)) | |
1490 | { | |
1491 | /* The breakpoint is inserted in a different address space. */ | |
1492 | return; | |
1493 | } | |
1494 | ||
1495 | /* Addresses and length of the part of the breakpoint that | |
1496 | we need to copy. */ | |
1497 | bp_addr = target_info->placed_address; | |
1498 | bp_size = target_info->shadow_len; | |
1499 | ||
1500 | if (bp_addr + bp_size <= memaddr) | |
1501 | { | |
1502 | /* The breakpoint is entirely before the chunk of memory we are | |
1503 | reading. */ | |
1504 | return; | |
1505 | } | |
1506 | ||
1507 | if (bp_addr >= memaddr + len) | |
1508 | { | |
1509 | /* The breakpoint is entirely after the chunk of memory we are | |
1510 | reading. */ | |
1511 | return; | |
1512 | } | |
1513 | ||
1514 | /* Offset within shadow_contents. */ | |
1515 | if (bp_addr < memaddr) | |
1516 | { | |
1517 | /* Only copy the second part of the breakpoint. */ | |
1518 | bp_size -= memaddr - bp_addr; | |
1519 | bptoffset = memaddr - bp_addr; | |
1520 | bp_addr = memaddr; | |
1521 | } | |
1522 | ||
1523 | if (bp_addr + bp_size > memaddr + len) | |
1524 | { | |
1525 | /* Only copy the first part of the breakpoint. */ | |
1526 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1527 | } | |
1528 | ||
1529 | if (readbuf != NULL) | |
1530 | { | |
1531 | /* Verify that the readbuf buffer does not overlap with the | |
1532 | shadow_contents buffer. */ | |
1533 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1534 | || readbuf >= (target_info->shadow_contents | |
1535 | + target_info->shadow_len)); | |
1536 | ||
1537 | /* Update the read buffer with this inserted breakpoint's | |
1538 | shadow. */ | |
1539 | memcpy (readbuf + bp_addr - memaddr, | |
1540 | target_info->shadow_contents + bptoffset, bp_size); | |
1541 | } | |
1542 | else | |
1543 | { | |
1544 | const unsigned char *bp; | |
0d5ed153 MR |
1545 | CORE_ADDR addr = target_info->reqstd_address; |
1546 | int placed_size; | |
9d497a19 PA |
1547 | |
1548 | /* Update the shadow with what we want to write to memory. */ | |
1549 | memcpy (target_info->shadow_contents + bptoffset, | |
1550 | writebuf_org + bp_addr - memaddr, bp_size); | |
1551 | ||
1552 | /* Determine appropriate breakpoint contents and size for this | |
1553 | address. */ | |
0d5ed153 | 1554 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1555 | |
1556 | /* Update the final write buffer with this inserted | |
1557 | breakpoint's INSN. */ | |
1558 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1559 | } | |
1560 | } | |
1561 | ||
8defab1a | 1562 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1563 | by replacing any memory breakpoints with their shadowed contents. |
1564 | ||
35c63cd8 JB |
1565 | If READBUF is not NULL, this buffer must not overlap with any of |
1566 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1567 | a failed assertion internal error will be raised. | |
1568 | ||
876fa593 | 1569 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1570 | bl->address - bp_location_placed_address_before_address_max |
1571 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1572 | The range we were requested to resolve shadows for is: |
1573 | memaddr ... memaddr + len | |
1574 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1575 | memaddr + len <= (bl->address |
1576 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1577 | and: |
35df4500 | 1578 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1579 | |
8defab1a | 1580 | void |
f0ba3972 PA |
1581 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1582 | const gdb_byte *writebuf_org, | |
1583 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1584 | { |
4a64f543 MS |
1585 | /* Left boundary, right boundary and median element of our binary |
1586 | search. */ | |
876fa593 | 1587 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1588 | size_t i; |
876fa593 | 1589 | |
4a64f543 MS |
1590 | /* Find BC_L which is a leftmost element which may affect BUF |
1591 | content. It is safe to report lower value but a failure to | |
1592 | report higher one. */ | |
876fa593 JK |
1593 | |
1594 | bc_l = 0; | |
1595 | bc_r = bp_location_count; | |
1596 | while (bc_l + 1 < bc_r) | |
1597 | { | |
35df4500 | 1598 | struct bp_location *bl; |
876fa593 JK |
1599 | |
1600 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1601 | bl = bp_location[bc]; |
876fa593 | 1602 | |
4a64f543 MS |
1603 | /* Check first BL->ADDRESS will not overflow due to the added |
1604 | constant. Then advance the left boundary only if we are sure | |
1605 | the BC element can in no way affect the BUF content (MEMADDR | |
1606 | to MEMADDR + LEN range). | |
876fa593 | 1607 | |
4a64f543 MS |
1608 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1609 | offset so that we cannot miss a breakpoint with its shadow | |
1610 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1611 | |
35df4500 TJB |
1612 | if ((bl->address + bp_location_shadow_len_after_address_max |
1613 | >= bl->address) | |
1614 | && (bl->address + bp_location_shadow_len_after_address_max | |
1615 | <= memaddr)) | |
876fa593 JK |
1616 | bc_l = bc; |
1617 | else | |
1618 | bc_r = bc; | |
1619 | } | |
1620 | ||
128070bb PA |
1621 | /* Due to the binary search above, we need to make sure we pick the |
1622 | first location that's at BC_L's address. E.g., if there are | |
1623 | multiple locations at the same address, BC_L may end up pointing | |
1624 | at a duplicate location, and miss the "master"/"inserted" | |
1625 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1626 | B: | |
1627 | ||
1628 | L1@A, L2@A, L3@B, ... | |
1629 | ||
1630 | BC_L could end up pointing at location L2, while the "master" | |
1631 | location could be L1. Since the `loc->inserted' flag is only set | |
1632 | on "master" locations, we'd forget to restore the shadow of L1 | |
1633 | and L2. */ | |
1634 | while (bc_l > 0 | |
1635 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1636 | bc_l--; | |
1637 | ||
876fa593 JK |
1638 | /* Now do full processing of the found relevant range of elements. */ |
1639 | ||
1640 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1641 | { |
35df4500 | 1642 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1643 | CORE_ADDR bp_addr = 0; |
1644 | int bp_size = 0; | |
1645 | int bptoffset = 0; | |
1646 | ||
35df4500 TJB |
1647 | /* bp_location array has BL->OWNER always non-NULL. */ |
1648 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1649 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1650 | bl->owner->number); |
ffce0d52 | 1651 | |
e5dd4106 | 1652 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1653 | content. */ |
1654 | ||
35df4500 TJB |
1655 | if (bl->address >= bp_location_placed_address_before_address_max |
1656 | && memaddr + len <= (bl->address | |
1657 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1658 | break; |
1659 | ||
35df4500 | 1660 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1661 | continue; |
6c95b8df | 1662 | |
9d497a19 PA |
1663 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1664 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1665 | } | |
c906108c | 1666 | } |
9d497a19 | 1667 | |
c906108c | 1668 | \f |
c5aa993b | 1669 | |
b775012e LM |
1670 | /* Return true if BPT is either a software breakpoint or a hardware |
1671 | breakpoint. */ | |
1672 | ||
1673 | int | |
1674 | is_breakpoint (const struct breakpoint *bpt) | |
1675 | { | |
1676 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1677 | || bpt->type == bp_hardware_breakpoint |
1678 | || bpt->type == bp_dprintf); | |
b775012e LM |
1679 | } |
1680 | ||
60e1c644 PA |
1681 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1682 | ||
a5606eee | 1683 | static int |
d77f58be | 1684 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1685 | { |
1686 | return (bpt->type == bp_hardware_watchpoint | |
1687 | || bpt->type == bp_read_watchpoint | |
1688 | || bpt->type == bp_access_watchpoint); | |
1689 | } | |
7270d8f2 | 1690 | |
60e1c644 PA |
1691 | /* Return true if BPT is of any watchpoint kind, hardware or |
1692 | software. */ | |
1693 | ||
3a5c3e22 | 1694 | int |
d77f58be | 1695 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1696 | { |
1697 | return (is_hardware_watchpoint (bpt) | |
1698 | || bpt->type == bp_watchpoint); | |
1699 | } | |
1700 | ||
3a5c3e22 PA |
1701 | /* Returns true if the current thread and its running state are safe |
1702 | to evaluate or update watchpoint B. Watchpoints on local | |
1703 | expressions need to be evaluated in the context of the thread that | |
1704 | was current when the watchpoint was created, and, that thread needs | |
1705 | to be stopped to be able to select the correct frame context. | |
1706 | Watchpoints on global expressions can be evaluated on any thread, | |
1707 | and in any state. It is presently left to the target allowing | |
1708 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1709 | |
1710 | static int | |
3a5c3e22 | 1711 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1712 | { |
d0d8b0c6 JK |
1713 | return (b->base.pspace == current_program_space |
1714 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1715 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1716 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1717 | } |
1718 | ||
d0fb5eae JK |
1719 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1720 | associated bp_watchpoint_scope breakpoint. */ | |
1721 | ||
1722 | static void | |
3a5c3e22 | 1723 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1724 | { |
3a5c3e22 | 1725 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1726 | |
1727 | if (b->related_breakpoint != b) | |
1728 | { | |
1729 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1730 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1731 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1732 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1733 | b->related_breakpoint = b; | |
1734 | } | |
1735 | b->disposition = disp_del_at_next_stop; | |
1736 | } | |
1737 | ||
bb9d5f81 PP |
1738 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1739 | watchpoint W. */ | |
1740 | ||
1741 | static struct value * | |
1742 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1743 | { | |
1744 | struct value *bit_val; | |
1745 | ||
1746 | if (val == NULL) | |
1747 | return NULL; | |
1748 | ||
1749 | bit_val = allocate_value (value_type (val)); | |
1750 | ||
1751 | unpack_value_bitfield (bit_val, | |
1752 | w->val_bitpos, | |
1753 | w->val_bitsize, | |
1754 | value_contents_for_printing (val), | |
1755 | value_offset (val), | |
1756 | val); | |
1757 | ||
1758 | return bit_val; | |
1759 | } | |
1760 | ||
567e1b4e JB |
1761 | /* Assuming that B is a watchpoint: |
1762 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1763 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1764 | - Evaluate the condition if there is one, and store the result |
1765 | in b->loc->cond. | |
a5606eee VP |
1766 | - Update the list of values that must be watched in B->loc. |
1767 | ||
4a64f543 MS |
1768 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1769 | nothing. If this is local watchpoint that is out of scope, delete | |
1770 | it. | |
1771 | ||
1772 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1773 | removed + inserted on each stop here. Normal breakpoints must | |
1774 | never be removed because they might be missed by a running thread | |
1775 | when debugging in non-stop mode. On the other hand, hardware | |
1776 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1777 | to each LWP since they are stored in each LWP's hardware debug | |
1778 | registers. Therefore, such LWP must be stopped first in order to | |
1779 | be able to modify its hardware watchpoints. | |
1780 | ||
1781 | Hardware watchpoints must be reset exactly once after being | |
1782 | presented to the user. It cannot be done sooner, because it would | |
1783 | reset the data used to present the watchpoint hit to the user. And | |
1784 | it must not be done later because it could display the same single | |
1785 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1786 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1787 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1788 | not user-visible - its hit is suppressed if the memory content has | |
1789 | not changed. | |
1790 | ||
1791 | The following constraints influence the location where we can reset | |
1792 | hardware watchpoints: | |
1793 | ||
1794 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1795 | called several times when GDB stops. | |
1796 | ||
1797 | [linux] | |
1798 | * Multiple hardware watchpoints can be hit at the same time, | |
1799 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1800 | hit at a time as the reason for stopping, and all the other hits | |
1801 | are presented later, one after the other, each time the user | |
1802 | requests the execution to be resumed. Execution is not resumed | |
1803 | for the threads still having pending hit event stored in | |
1804 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1805 | the inferior on the first stop the thread hit event is kept being | |
1806 | reported from its cached value by linux_nat_stopped_data_address | |
1807 | until the real thread resume happens after the watchpoint gets | |
1808 | presented and thus its LWP_INFO->STATUS gets reset. | |
1809 | ||
1810 | Therefore the hardware watchpoint hit can get safely reset on the | |
1811 | watchpoint removal from inferior. */ | |
a79d3c27 | 1812 | |
b40ce68a | 1813 | static void |
3a5c3e22 | 1814 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1815 | { |
a5606eee | 1816 | int within_current_scope; |
a5606eee | 1817 | struct frame_id saved_frame_id; |
66076460 | 1818 | int frame_saved; |
a5606eee | 1819 | |
f6bc2008 PA |
1820 | /* If this is a local watchpoint, we only want to check if the |
1821 | watchpoint frame is in scope if the current thread is the thread | |
1822 | that was used to create the watchpoint. */ | |
1823 | if (!watchpoint_in_thread_scope (b)) | |
1824 | return; | |
1825 | ||
3a5c3e22 | 1826 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1827 | return; |
1828 | ||
66076460 | 1829 | frame_saved = 0; |
a5606eee VP |
1830 | |
1831 | /* Determine if the watchpoint is within scope. */ | |
1832 | if (b->exp_valid_block == NULL) | |
1833 | within_current_scope = 1; | |
1834 | else | |
1835 | { | |
b5db5dfc UW |
1836 | struct frame_info *fi = get_current_frame (); |
1837 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1838 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1839 | ||
c9cf6e20 MG |
1840 | /* If we're at a point where the stack has been destroyed |
1841 | (e.g. in a function epilogue), unwinding may not work | |
1842 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1843 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1844 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1845 | return; |
66076460 DJ |
1846 | |
1847 | /* Save the current frame's ID so we can restore it after | |
1848 | evaluating the watchpoint expression on its own frame. */ | |
1849 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1850 | took a frame parameter, so that we didn't have to change the | |
1851 | selected frame. */ | |
1852 | frame_saved = 1; | |
1853 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1854 | ||
a5606eee VP |
1855 | fi = frame_find_by_id (b->watchpoint_frame); |
1856 | within_current_scope = (fi != NULL); | |
1857 | if (within_current_scope) | |
1858 | select_frame (fi); | |
1859 | } | |
1860 | ||
b5db5dfc UW |
1861 | /* We don't free locations. They are stored in the bp_location array |
1862 | and update_global_location_list will eventually delete them and | |
1863 | remove breakpoints if needed. */ | |
3a5c3e22 | 1864 | b->base.loc = NULL; |
b5db5dfc | 1865 | |
a5606eee VP |
1866 | if (within_current_scope && reparse) |
1867 | { | |
bbc13ae3 | 1868 | const char *s; |
d63d0675 | 1869 | |
a5606eee VP |
1870 | if (b->exp) |
1871 | { | |
1872 | xfree (b->exp); | |
1873 | b->exp = NULL; | |
1874 | } | |
d63d0675 | 1875 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1876 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1877 | /* If the meaning of expression itself changed, the old value is |
1878 | no longer relevant. We don't want to report a watchpoint hit | |
1879 | to the user when the old value and the new value may actually | |
1880 | be completely different objects. */ | |
1881 | value_free (b->val); | |
fa4727a6 DJ |
1882 | b->val = NULL; |
1883 | b->val_valid = 0; | |
60e1c644 PA |
1884 | |
1885 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1886 | expression is stored in the breakpoint object, not in the | |
1887 | locations (re)created below. */ | |
3a5c3e22 | 1888 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1889 | { |
1890 | if (b->cond_exp != NULL) | |
1891 | { | |
1892 | xfree (b->cond_exp); | |
1893 | b->cond_exp = NULL; | |
1894 | } | |
1895 | ||
3a5c3e22 | 1896 | s = b->base.cond_string; |
1bb9788d | 1897 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1898 | } |
a5606eee | 1899 | } |
a5606eee VP |
1900 | |
1901 | /* If we failed to parse the expression, for example because | |
1902 | it refers to a global variable in a not-yet-loaded shared library, | |
1903 | don't try to insert watchpoint. We don't automatically delete | |
1904 | such watchpoint, though, since failure to parse expression | |
1905 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1906 | if (!target_has_execution) |
2d134ed3 PA |
1907 | { |
1908 | /* Without execution, memory can't change. No use to try and | |
1909 | set watchpoint locations. The watchpoint will be reset when | |
1910 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1911 | if (!can_use_hw_watchpoints) |
1912 | { | |
1913 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1914 | b->base.type = bp_watchpoint; | |
1915 | else | |
638aa5a1 AB |
1916 | error (_("Can't set read/access watchpoint when " |
1917 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1918 | } |
2d134ed3 PA |
1919 | } |
1920 | else if (within_current_scope && b->exp) | |
a5606eee | 1921 | { |
0cf6dd15 | 1922 | int pc = 0; |
fa4727a6 | 1923 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1924 | struct program_space *frame_pspace; |
a5606eee | 1925 | |
3a1115a0 | 1926 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1927 | |
a5606eee VP |
1928 | /* Avoid setting b->val if it's already set. The meaning of |
1929 | b->val is 'the last value' user saw, and we should update | |
1930 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1931 | happens, the code that reports it updates b->val directly. |
1932 | We don't keep track of the memory value for masked | |
1933 | watchpoints. */ | |
3a5c3e22 | 1934 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1935 | { |
bb9d5f81 PP |
1936 | if (b->val_bitsize != 0) |
1937 | { | |
1938 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1939 | if (v != NULL) | |
1940 | release_value (v); | |
1941 | } | |
fa4727a6 DJ |
1942 | b->val = v; |
1943 | b->val_valid = 1; | |
1944 | } | |
a5606eee | 1945 | |
2d134ed3 PA |
1946 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1947 | ||
a5606eee | 1948 | /* Look at each value on the value chain. */ |
9fa40276 | 1949 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1950 | { |
1951 | /* If it's a memory location, and GDB actually needed | |
1952 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1953 | must watch it. If the first value returned is |
1954 | still lazy, that means an error occurred reading it; | |
1955 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1956 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1957 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1958 | { |
1959 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1960 | |
a5606eee VP |
1961 | /* We only watch structs and arrays if user asked |
1962 | for it explicitly, never if they just happen to | |
1963 | appear in the middle of some value chain. */ | |
fa4727a6 | 1964 | if (v == result |
a5606eee VP |
1965 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1966 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1967 | { | |
1968 | CORE_ADDR addr; | |
744a8059 | 1969 | int type; |
a5606eee | 1970 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1971 | int bitpos = 0, bitsize = 0; |
1972 | ||
1973 | if (value_bitsize (v) != 0) | |
1974 | { | |
1975 | /* Extract the bit parameters out from the bitfield | |
1976 | sub-expression. */ | |
1977 | bitpos = value_bitpos (v); | |
1978 | bitsize = value_bitsize (v); | |
1979 | } | |
1980 | else if (v == result && b->val_bitsize != 0) | |
1981 | { | |
1982 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1983 | lvalue whose bit parameters are saved in the fields | |
1984 | VAL_BITPOS and VAL_BITSIZE. */ | |
1985 | bitpos = b->val_bitpos; | |
1986 | bitsize = b->val_bitsize; | |
1987 | } | |
a5606eee | 1988 | |
42ae5230 | 1989 | addr = value_address (v); |
bb9d5f81 PP |
1990 | if (bitsize != 0) |
1991 | { | |
1992 | /* Skip the bytes that don't contain the bitfield. */ | |
1993 | addr += bitpos / 8; | |
1994 | } | |
1995 | ||
a5606eee | 1996 | type = hw_write; |
3a5c3e22 | 1997 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1998 | type = hw_read; |
3a5c3e22 | 1999 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2000 | type = hw_access; |
3a5c3e22 PA |
2001 | |
2002 | loc = allocate_bp_location (&b->base); | |
2003 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2004 | ; |
2005 | *tmp = loc; | |
a6d9a66e | 2006 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2007 | |
2008 | loc->pspace = frame_pspace; | |
a5606eee | 2009 | loc->address = addr; |
bb9d5f81 PP |
2010 | |
2011 | if (bitsize != 0) | |
2012 | { | |
2013 | /* Just cover the bytes that make up the bitfield. */ | |
2014 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2015 | } | |
2016 | else | |
2017 | loc->length = TYPE_LENGTH (value_type (v)); | |
2018 | ||
a5606eee VP |
2019 | loc->watchpoint_type = type; |
2020 | } | |
2021 | } | |
9fa40276 TJB |
2022 | } |
2023 | ||
2024 | /* Change the type of breakpoint between hardware assisted or | |
2025 | an ordinary watchpoint depending on the hardware support | |
2026 | and free hardware slots. REPARSE is set when the inferior | |
2027 | is started. */ | |
a9634178 | 2028 | if (reparse) |
9fa40276 | 2029 | { |
e09342b5 | 2030 | int reg_cnt; |
9fa40276 TJB |
2031 | enum bp_loc_type loc_type; |
2032 | struct bp_location *bl; | |
a5606eee | 2033 | |
a9634178 | 2034 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2035 | |
2036 | if (reg_cnt) | |
9fa40276 TJB |
2037 | { |
2038 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2039 | enum bptype type; |
9fa40276 | 2040 | |
a9634178 TJB |
2041 | /* Use an exact watchpoint when there's only one memory region to be |
2042 | watched, and only one debug register is needed to watch it. */ | |
2043 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2044 | ||
9fa40276 | 2045 | /* We need to determine how many resources are already |
e09342b5 TJB |
2046 | used for all other hardware watchpoints plus this one |
2047 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2048 | this watchpoint in as well. */ |
2049 | ||
2050 | /* If this is a software watchpoint, we try to turn it | |
2051 | to a hardware one -- count resources as if B was of | |
2052 | hardware watchpoint type. */ | |
2053 | type = b->base.type; | |
2054 | if (type == bp_watchpoint) | |
2055 | type = bp_hardware_watchpoint; | |
2056 | ||
2057 | /* This watchpoint may or may not have been placed on | |
2058 | the list yet at this point (it won't be in the list | |
2059 | if we're trying to create it for the first time, | |
2060 | through watch_command), so always account for it | |
2061 | manually. */ | |
2062 | ||
2063 | /* Count resources used by all watchpoints except B. */ | |
2064 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2065 | ||
2066 | /* Add in the resources needed for B. */ | |
2067 | i += hw_watchpoint_use_count (&b->base); | |
2068 | ||
2069 | target_resources_ok | |
2070 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2071 | if (target_resources_ok <= 0) |
a9634178 | 2072 | { |
3a5c3e22 | 2073 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2074 | |
2075 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2076 | error (_("Target does not support this type of " |
2077 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2078 | else if (target_resources_ok < 0 && !sw_mode) |
2079 | error (_("There are not enough available hardware " | |
2080 | "resources for this watchpoint.")); | |
a1398e0c PA |
2081 | |
2082 | /* Downgrade to software watchpoint. */ | |
2083 | b->base.type = bp_watchpoint; | |
2084 | } | |
2085 | else | |
2086 | { | |
2087 | /* If this was a software watchpoint, we've just | |
2088 | found we have enough resources to turn it to a | |
2089 | hardware watchpoint. Otherwise, this is a | |
2090 | nop. */ | |
2091 | b->base.type = type; | |
a9634178 | 2092 | } |
9fa40276 | 2093 | } |
3a5c3e22 | 2094 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2095 | { |
2096 | if (!can_use_hw_watchpoints) | |
2097 | error (_("Can't set read/access watchpoint when " | |
2098 | "hardware watchpoints are disabled.")); | |
2099 | else | |
2100 | error (_("Expression cannot be implemented with " | |
2101 | "read/access watchpoint.")); | |
2102 | } | |
9fa40276 | 2103 | else |
3a5c3e22 | 2104 | b->base.type = bp_watchpoint; |
9fa40276 | 2105 | |
3a5c3e22 | 2106 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2107 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2108 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2109 | bl->loc_type = loc_type; |
2110 | } | |
2111 | ||
2112 | for (v = val_chain; v; v = next) | |
2113 | { | |
a5606eee VP |
2114 | next = value_next (v); |
2115 | if (v != b->val) | |
2116 | value_free (v); | |
2117 | } | |
2118 | ||
c7437ca6 PA |
2119 | /* If a software watchpoint is not watching any memory, then the |
2120 | above left it without any location set up. But, | |
2121 | bpstat_stop_status requires a location to be able to report | |
2122 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2123 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2124 | { |
3a5c3e22 PA |
2125 | struct breakpoint *base = &b->base; |
2126 | base->loc = allocate_bp_location (base); | |
2127 | base->loc->pspace = frame_pspace; | |
2128 | base->loc->address = -1; | |
2129 | base->loc->length = -1; | |
2130 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2131 | } |
a5606eee VP |
2132 | } |
2133 | else if (!within_current_scope) | |
7270d8f2 | 2134 | { |
ac74f770 MS |
2135 | printf_filtered (_("\ |
2136 | Watchpoint %d deleted because the program has left the block\n\ | |
2137 | in which its expression is valid.\n"), | |
3a5c3e22 | 2138 | b->base.number); |
d0fb5eae | 2139 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2140 | } |
a5606eee VP |
2141 | |
2142 | /* Restore the selected frame. */ | |
66076460 DJ |
2143 | if (frame_saved) |
2144 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2145 | } |
2146 | ||
a5606eee | 2147 | |
74960c60 | 2148 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2149 | inserted in the inferior. We don't differentiate the type of BL's owner |
2150 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2151 | breakpoint_ops is not defined, because in insert_bp_location, | |
2152 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2153 | static int |
35df4500 | 2154 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2155 | { |
35df4500 | 2156 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2157 | return 0; |
2158 | ||
35df4500 | 2159 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2160 | return 0; |
2161 | ||
35df4500 | 2162 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2163 | return 0; |
2164 | ||
f8eba3c6 TT |
2165 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2166 | return 0; | |
2167 | ||
56710373 PA |
2168 | /* This is set for example, when we're attached to the parent of a |
2169 | vfork, and have detached from the child. The child is running | |
2170 | free, and we expect it to do an exec or exit, at which point the | |
2171 | OS makes the parent schedulable again (and the target reports | |
2172 | that the vfork is done). Until the child is done with the shared | |
2173 | memory region, do not insert breakpoints in the parent, otherwise | |
2174 | the child could still trip on the parent's breakpoints. Since | |
2175 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2176 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2177 | return 0; |
2178 | ||
31e77af2 PA |
2179 | /* Don't insert a breakpoint if we're trying to step past its |
2180 | location. */ | |
2181 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2182 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2183 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2184 | bl->address)) | |
e558d7c1 PA |
2185 | { |
2186 | if (debug_infrun) | |
2187 | { | |
2188 | fprintf_unfiltered (gdb_stdlog, | |
2189 | "infrun: skipping breakpoint: " | |
2190 | "stepping past insn at: %s\n", | |
2191 | paddress (bl->gdbarch, bl->address)); | |
2192 | } | |
2193 | return 0; | |
2194 | } | |
31e77af2 | 2195 | |
963f9c80 PA |
2196 | /* Don't insert watchpoints if we're trying to step past the |
2197 | instruction that triggered one. */ | |
2198 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2199 | && stepping_past_nonsteppable_watchpoint ()) | |
2200 | { | |
2201 | if (debug_infrun) | |
2202 | { | |
2203 | fprintf_unfiltered (gdb_stdlog, | |
2204 | "infrun: stepping past non-steppable watchpoint. " | |
2205 | "skipping watchpoint at %s:%d\n", | |
2206 | paddress (bl->gdbarch, bl->address), | |
2207 | bl->length); | |
2208 | } | |
2209 | return 0; | |
2210 | } | |
2211 | ||
74960c60 VP |
2212 | return 1; |
2213 | } | |
2214 | ||
934709f0 PW |
2215 | /* Same as should_be_inserted but does the check assuming |
2216 | that the location is not duplicated. */ | |
2217 | ||
2218 | static int | |
2219 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2220 | { | |
2221 | int result; | |
2222 | const int save_duplicate = bl->duplicate; | |
2223 | ||
2224 | bl->duplicate = 0; | |
2225 | result = should_be_inserted (bl); | |
2226 | bl->duplicate = save_duplicate; | |
2227 | return result; | |
2228 | } | |
2229 | ||
b775012e LM |
2230 | /* Parses a conditional described by an expression COND into an |
2231 | agent expression bytecode suitable for evaluation | |
2232 | by the bytecode interpreter. Return NULL if there was | |
2233 | any error during parsing. */ | |
2234 | ||
2235 | static struct agent_expr * | |
2236 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2237 | { | |
2238 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2239 | |
2240 | if (!cond) | |
2241 | return NULL; | |
2242 | ||
2243 | /* We don't want to stop processing, so catch any errors | |
2244 | that may show up. */ | |
492d29ea | 2245 | TRY |
b775012e LM |
2246 | { |
2247 | aexpr = gen_eval_for_expr (scope, cond); | |
2248 | } | |
2249 | ||
492d29ea | 2250 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2251 | { |
2252 | /* If we got here, it means the condition could not be parsed to a valid | |
2253 | bytecode expression and thus can't be evaluated on the target's side. | |
2254 | It's no use iterating through the conditions. */ | |
2255 | return NULL; | |
2256 | } | |
492d29ea | 2257 | END_CATCH |
b775012e LM |
2258 | |
2259 | /* We have a valid agent expression. */ | |
2260 | return aexpr; | |
2261 | } | |
2262 | ||
2263 | /* Based on location BL, create a list of breakpoint conditions to be | |
2264 | passed on to the target. If we have duplicated locations with different | |
2265 | conditions, we will add such conditions to the list. The idea is that the | |
2266 | target will evaluate the list of conditions and will only notify GDB when | |
2267 | one of them is true. */ | |
2268 | ||
2269 | static void | |
2270 | build_target_condition_list (struct bp_location *bl) | |
2271 | { | |
2272 | struct bp_location **locp = NULL, **loc2p; | |
2273 | int null_condition_or_parse_error = 0; | |
2274 | int modified = bl->needs_update; | |
2275 | struct bp_location *loc; | |
2276 | ||
8b4f3082 PA |
2277 | /* Release conditions left over from a previous insert. */ |
2278 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2279 | ||
b775012e LM |
2280 | /* This is only meaningful if the target is |
2281 | evaluating conditions and if the user has | |
2282 | opted for condition evaluation on the target's | |
2283 | side. */ | |
2284 | if (gdb_evaluates_breakpoint_condition_p () | |
2285 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2286 | return; | |
2287 | ||
2288 | /* Do a first pass to check for locations with no assigned | |
2289 | conditions or conditions that fail to parse to a valid agent expression | |
2290 | bytecode. If any of these happen, then it's no use to send conditions | |
2291 | to the target since this location will always trigger and generate a | |
2292 | response back to GDB. */ | |
2293 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2294 | { | |
2295 | loc = (*loc2p); | |
2296 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2297 | { | |
2298 | if (modified) | |
2299 | { | |
2300 | struct agent_expr *aexpr; | |
2301 | ||
2302 | /* Re-parse the conditions since something changed. In that | |
2303 | case we already freed the condition bytecodes (see | |
2304 | force_breakpoint_reinsertion). We just | |
2305 | need to parse the condition to bytecodes again. */ | |
2306 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2307 | loc->cond_bytecode = aexpr; | |
2308 | ||
2309 | /* Check if we managed to parse the conditional expression | |
2310 | correctly. If not, we will not send this condition | |
2311 | to the target. */ | |
2312 | if (aexpr) | |
2313 | continue; | |
2314 | } | |
2315 | ||
2316 | /* If we have a NULL bytecode expression, it means something | |
2317 | went wrong or we have a null condition expression. */ | |
2318 | if (!loc->cond_bytecode) | |
2319 | { | |
2320 | null_condition_or_parse_error = 1; | |
2321 | break; | |
2322 | } | |
2323 | } | |
2324 | } | |
2325 | ||
2326 | /* If any of these happened, it means we will have to evaluate the conditions | |
2327 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2328 | for all the other duplicate locations, thus we free all of them here. | |
2329 | ||
2330 | This is so we have a finer control over which locations' conditions are | |
2331 | being evaluated by GDB or the remote stub. */ | |
2332 | if (null_condition_or_parse_error) | |
2333 | { | |
2334 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2335 | { | |
2336 | loc = (*loc2p); | |
2337 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2338 | { | |
2339 | /* Only go as far as the first NULL bytecode is | |
2340 | located. */ | |
2341 | if (!loc->cond_bytecode) | |
2342 | return; | |
2343 | ||
2344 | free_agent_expr (loc->cond_bytecode); | |
2345 | loc->cond_bytecode = NULL; | |
2346 | } | |
2347 | } | |
2348 | } | |
2349 | ||
2350 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2351 | for this location's address. */ | |
2352 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2353 | { | |
2354 | loc = (*loc2p); | |
2355 | if (loc->cond | |
2356 | && is_breakpoint (loc->owner) | |
2357 | && loc->pspace->num == bl->pspace->num | |
2358 | && loc->owner->enable_state == bp_enabled | |
2359 | && loc->enabled) | |
2360 | /* Add the condition to the vector. This will be used later to send the | |
2361 | conditions to the target. */ | |
2362 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2363 | loc->cond_bytecode); | |
2364 | } | |
2365 | ||
2366 | return; | |
2367 | } | |
2368 | ||
d3ce09f5 SS |
2369 | /* Parses a command described by string CMD into an agent expression |
2370 | bytecode suitable for evaluation by the bytecode interpreter. | |
2371 | Return NULL if there was any error during parsing. */ | |
2372 | ||
2373 | static struct agent_expr * | |
2374 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2375 | { | |
2376 | struct cleanup *old_cleanups = 0; | |
2377 | struct expression *expr, **argvec; | |
2378 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2379 | const char *cmdrest; |
2380 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2381 | struct format_piece *fpieces; |
2382 | int nargs; | |
2383 | struct gdbarch *gdbarch = get_current_arch (); | |
2384 | ||
2385 | if (!cmd) | |
2386 | return NULL; | |
2387 | ||
2388 | cmdrest = cmd; | |
2389 | ||
2390 | if (*cmdrest == ',') | |
2391 | ++cmdrest; | |
bbc13ae3 | 2392 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2393 | |
2394 | if (*cmdrest++ != '"') | |
2395 | error (_("No format string following the location")); | |
2396 | ||
2397 | format_start = cmdrest; | |
2398 | ||
2399 | fpieces = parse_format_string (&cmdrest); | |
2400 | ||
2401 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2402 | ||
2403 | format_end = cmdrest; | |
2404 | ||
2405 | if (*cmdrest++ != '"') | |
2406 | error (_("Bad format string, non-terminated '\"'.")); | |
2407 | ||
bbc13ae3 | 2408 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2409 | |
2410 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2411 | error (_("Invalid argument syntax")); | |
2412 | ||
2413 | if (*cmdrest == ',') | |
2414 | cmdrest++; | |
bbc13ae3 | 2415 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2416 | |
2417 | /* For each argument, make an expression. */ | |
2418 | ||
2419 | argvec = (struct expression **) alloca (strlen (cmd) | |
2420 | * sizeof (struct expression *)); | |
2421 | ||
2422 | nargs = 0; | |
2423 | while (*cmdrest != '\0') | |
2424 | { | |
bbc13ae3 | 2425 | const char *cmd1; |
d3ce09f5 SS |
2426 | |
2427 | cmd1 = cmdrest; | |
2428 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2429 | argvec[nargs++] = expr; | |
2430 | cmdrest = cmd1; | |
2431 | if (*cmdrest == ',') | |
2432 | ++cmdrest; | |
2433 | } | |
2434 | ||
2435 | /* We don't want to stop processing, so catch any errors | |
2436 | that may show up. */ | |
492d29ea | 2437 | TRY |
d3ce09f5 SS |
2438 | { |
2439 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2440 | format_start, format_end - format_start, | |
2441 | fpieces, nargs, argvec); | |
2442 | } | |
492d29ea | 2443 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2444 | { |
2445 | /* If we got here, it means the command could not be parsed to a valid | |
2446 | bytecode expression and thus can't be evaluated on the target's side. | |
2447 | It's no use iterating through the other commands. */ | |
492d29ea | 2448 | aexpr = NULL; |
d3ce09f5 | 2449 | } |
492d29ea PA |
2450 | END_CATCH |
2451 | ||
2452 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2453 | |
d3ce09f5 SS |
2454 | /* We have a valid agent expression, return it. */ |
2455 | return aexpr; | |
2456 | } | |
2457 | ||
2458 | /* Based on location BL, create a list of breakpoint commands to be | |
2459 | passed on to the target. If we have duplicated locations with | |
2460 | different commands, we will add any such to the list. */ | |
2461 | ||
2462 | static void | |
2463 | build_target_command_list (struct bp_location *bl) | |
2464 | { | |
2465 | struct bp_location **locp = NULL, **loc2p; | |
2466 | int null_command_or_parse_error = 0; | |
2467 | int modified = bl->needs_update; | |
2468 | struct bp_location *loc; | |
2469 | ||
8b4f3082 PA |
2470 | /* Release commands left over from a previous insert. */ |
2471 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2472 | ||
41fac0cf | 2473 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2474 | return; |
2475 | ||
41fac0cf PA |
2476 | /* For now, limit to agent-style dprintf breakpoints. */ |
2477 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2478 | return; |
2479 | ||
41fac0cf PA |
2480 | /* For now, if we have any duplicate location that isn't a dprintf, |
2481 | don't install the target-side commands, as that would make the | |
2482 | breakpoint not be reported to the core, and we'd lose | |
2483 | control. */ | |
2484 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2485 | { | |
2486 | loc = (*loc2p); | |
2487 | if (is_breakpoint (loc->owner) | |
2488 | && loc->pspace->num == bl->pspace->num | |
2489 | && loc->owner->type != bp_dprintf) | |
2490 | return; | |
2491 | } | |
2492 | ||
d3ce09f5 SS |
2493 | /* Do a first pass to check for locations with no assigned |
2494 | conditions or conditions that fail to parse to a valid agent expression | |
2495 | bytecode. If any of these happen, then it's no use to send conditions | |
2496 | to the target since this location will always trigger and generate a | |
2497 | response back to GDB. */ | |
2498 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2499 | { | |
2500 | loc = (*loc2p); | |
2501 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2502 | { | |
2503 | if (modified) | |
2504 | { | |
2505 | struct agent_expr *aexpr; | |
2506 | ||
2507 | /* Re-parse the commands since something changed. In that | |
2508 | case we already freed the command bytecodes (see | |
2509 | force_breakpoint_reinsertion). We just | |
2510 | need to parse the command to bytecodes again. */ | |
2511 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2512 | loc->owner->extra_string); | |
2513 | loc->cmd_bytecode = aexpr; | |
2514 | ||
2515 | if (!aexpr) | |
2516 | continue; | |
2517 | } | |
2518 | ||
2519 | /* If we have a NULL bytecode expression, it means something | |
2520 | went wrong or we have a null command expression. */ | |
2521 | if (!loc->cmd_bytecode) | |
2522 | { | |
2523 | null_command_or_parse_error = 1; | |
2524 | break; | |
2525 | } | |
2526 | } | |
2527 | } | |
2528 | ||
2529 | /* If anything failed, then we're not doing target-side commands, | |
2530 | and so clean up. */ | |
2531 | if (null_command_or_parse_error) | |
2532 | { | |
2533 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2534 | { | |
2535 | loc = (*loc2p); | |
2536 | if (is_breakpoint (loc->owner) | |
2537 | && loc->pspace->num == bl->pspace->num) | |
2538 | { | |
2539 | /* Only go as far as the first NULL bytecode is | |
2540 | located. */ | |
40fb6c5e | 2541 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2542 | return; |
2543 | ||
40fb6c5e HZ |
2544 | free_agent_expr (loc->cmd_bytecode); |
2545 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2546 | } |
2547 | } | |
2548 | } | |
2549 | ||
2550 | /* No NULL commands or failed bytecode generation. Build a command list | |
2551 | for this location's address. */ | |
2552 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2553 | { | |
2554 | loc = (*loc2p); | |
2555 | if (loc->owner->extra_string | |
2556 | && is_breakpoint (loc->owner) | |
2557 | && loc->pspace->num == bl->pspace->num | |
2558 | && loc->owner->enable_state == bp_enabled | |
2559 | && loc->enabled) | |
2560 | /* Add the command to the vector. This will be used later | |
2561 | to send the commands to the target. */ | |
2562 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2563 | loc->cmd_bytecode); | |
2564 | } | |
2565 | ||
2566 | bl->target_info.persist = 0; | |
2567 | /* Maybe flag this location as persistent. */ | |
2568 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2569 | bl->target_info.persist = 1; | |
2570 | } | |
2571 | ||
35df4500 TJB |
2572 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2573 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2574 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2575 | Returns 0 for success, 1 if the bp_location type is not supported or |
2576 | -1 for failure. | |
879bfdc2 | 2577 | |
4a64f543 MS |
2578 | NOTE drow/2003-09-09: This routine could be broken down to an |
2579 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2580 | static int |
35df4500 | 2581 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2582 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2583 | int *disabled_breaks, |
dd61ec5c MW |
2584 | int *hw_breakpoint_error, |
2585 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2586 | { |
0000e5cc PA |
2587 | enum errors bp_err = GDB_NO_ERROR; |
2588 | const char *bp_err_message = NULL; | |
879bfdc2 | 2589 | |
b775012e | 2590 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2591 | return 0; |
2592 | ||
35c63cd8 JB |
2593 | /* Note we don't initialize bl->target_info, as that wipes out |
2594 | the breakpoint location's shadow_contents if the breakpoint | |
2595 | is still inserted at that location. This in turn breaks | |
2596 | target_read_memory which depends on these buffers when | |
2597 | a memory read is requested at the breakpoint location: | |
2598 | Once the target_info has been wiped, we fail to see that | |
2599 | we have a breakpoint inserted at that address and thus | |
2600 | read the breakpoint instead of returning the data saved in | |
2601 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2602 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2603 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2604 | bl->target_info.length = bl->length; |
8181d85f | 2605 | |
b775012e LM |
2606 | /* When working with target-side conditions, we must pass all the conditions |
2607 | for the same breakpoint address down to the target since GDB will not | |
2608 | insert those locations. With a list of breakpoint conditions, the target | |
2609 | can decide when to stop and notify GDB. */ | |
2610 | ||
2611 | if (is_breakpoint (bl->owner)) | |
2612 | { | |
2613 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2614 | build_target_command_list (bl); |
2615 | /* Reset the modification marker. */ | |
b775012e LM |
2616 | bl->needs_update = 0; |
2617 | } | |
2618 | ||
35df4500 TJB |
2619 | if (bl->loc_type == bp_loc_software_breakpoint |
2620 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2621 | { |
35df4500 | 2622 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2623 | { |
2624 | /* If the explicitly specified breakpoint type | |
2625 | is not hardware breakpoint, check the memory map to see | |
2626 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2627 | |
765dc015 VP |
2628 | Two important cases are: |
2629 | - location type is not hardware breakpoint, memory | |
2630 | is readonly. We change the type of the location to | |
2631 | hardware breakpoint. | |
4a64f543 MS |
2632 | - location type is hardware breakpoint, memory is |
2633 | read-write. This means we've previously made the | |
2634 | location hardware one, but then the memory map changed, | |
2635 | so we undo. | |
765dc015 | 2636 | |
4a64f543 MS |
2637 | When breakpoints are removed, remove_breakpoints will use |
2638 | location types we've just set here, the only possible | |
2639 | problem is that memory map has changed during running | |
2640 | program, but it's not going to work anyway with current | |
2641 | gdb. */ | |
765dc015 | 2642 | struct mem_region *mr |
0d5ed153 | 2643 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2644 | |
2645 | if (mr) | |
2646 | { | |
2647 | if (automatic_hardware_breakpoints) | |
2648 | { | |
765dc015 VP |
2649 | enum bp_loc_type new_type; |
2650 | ||
2651 | if (mr->attrib.mode != MEM_RW) | |
2652 | new_type = bp_loc_hardware_breakpoint; | |
2653 | else | |
2654 | new_type = bp_loc_software_breakpoint; | |
2655 | ||
35df4500 | 2656 | if (new_type != bl->loc_type) |
765dc015 VP |
2657 | { |
2658 | static int said = 0; | |
cc59ec59 | 2659 | |
35df4500 | 2660 | bl->loc_type = new_type; |
765dc015 VP |
2661 | if (!said) |
2662 | { | |
3e43a32a MS |
2663 | fprintf_filtered (gdb_stdout, |
2664 | _("Note: automatically using " | |
2665 | "hardware breakpoints for " | |
2666 | "read-only addresses.\n")); | |
765dc015 VP |
2667 | said = 1; |
2668 | } | |
2669 | } | |
2670 | } | |
35df4500 | 2671 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2672 | && mr->attrib.mode != MEM_RW) |
2673 | { | |
2674 | fprintf_unfiltered (tmp_error_stream, | |
2675 | _("Cannot insert breakpoint %d.\n" | |
2676 | "Cannot set software breakpoint " | |
2677 | "at read-only address %s\n"), | |
2678 | bl->owner->number, | |
2679 | paddress (bl->gdbarch, bl->address)); | |
2680 | return 1; | |
2681 | } | |
765dc015 VP |
2682 | } |
2683 | } | |
2684 | ||
879bfdc2 DJ |
2685 | /* First check to see if we have to handle an overlay. */ |
2686 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2687 | || bl->section == NULL |
2688 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2689 | { |
2690 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2691 | TRY |
dd61ec5c | 2692 | { |
0000e5cc PA |
2693 | int val; |
2694 | ||
dd61ec5c | 2695 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2696 | if (val) |
2697 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2698 | } |
492d29ea | 2699 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2700 | { |
0000e5cc PA |
2701 | bp_err = e.error; |
2702 | bp_err_message = e.message; | |
dd61ec5c | 2703 | } |
492d29ea | 2704 | END_CATCH |
879bfdc2 DJ |
2705 | } |
2706 | else | |
2707 | { | |
4a64f543 | 2708 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2709 | Shall we set a breakpoint at the LMA? */ |
2710 | if (!overlay_events_enabled) | |
2711 | { | |
2712 | /* Yes -- overlay event support is not active, | |
2713 | so we must try to set a breakpoint at the LMA. | |
2714 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2715 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2716 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2717 | bl->owner->number); |
879bfdc2 DJ |
2718 | else |
2719 | { | |
35df4500 TJB |
2720 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2721 | bl->section); | |
879bfdc2 | 2722 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2723 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2724 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2725 | |
2726 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2727 | TRY |
0000e5cc PA |
2728 | { |
2729 | int val; | |
2730 | ||
2731 | val = target_insert_breakpoint (bl->gdbarch, | |
2732 | &bl->overlay_target_info); | |
2733 | if (val) | |
2734 | bp_err = GENERIC_ERROR; | |
2735 | } | |
492d29ea | 2736 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2737 | { |
2738 | bp_err = e.error; | |
2739 | bp_err_message = e.message; | |
2740 | } | |
492d29ea | 2741 | END_CATCH |
0000e5cc PA |
2742 | |
2743 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2744 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2745 | "Overlay breakpoint %d " |
2746 | "failed: in ROM?\n", | |
35df4500 | 2747 | bl->owner->number); |
879bfdc2 DJ |
2748 | } |
2749 | } | |
2750 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2751 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2752 | { |
2753 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2754 | TRY |
dd61ec5c | 2755 | { |
0000e5cc PA |
2756 | int val; |
2757 | ||
dd61ec5c | 2758 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2759 | if (val) |
2760 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2761 | } |
492d29ea | 2762 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2763 | { |
0000e5cc PA |
2764 | bp_err = e.error; |
2765 | bp_err_message = e.message; | |
dd61ec5c | 2766 | } |
492d29ea | 2767 | END_CATCH |
879bfdc2 DJ |
2768 | } |
2769 | else | |
2770 | { | |
2771 | /* No. This breakpoint will not be inserted. | |
2772 | No error, but do not mark the bp as 'inserted'. */ | |
2773 | return 0; | |
2774 | } | |
2775 | } | |
2776 | ||
0000e5cc | 2777 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2778 | { |
2779 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2780 | |
2781 | /* In some cases, we might not be able to insert a | |
2782 | breakpoint in a shared library that has already been | |
2783 | removed, but we have not yet processed the shlib unload | |
2784 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2785 | breakpoint insertion themselves can't tell why the |
2786 | breakpoint insertion failed (e.g., the remote target | |
2787 | doesn't define error codes), so we must treat generic | |
2788 | errors as memory errors. */ | |
0000e5cc | 2789 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2790 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2791 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2792 | || shared_objfile_contains_address_p (bl->pspace, |
2793 | bl->address))) | |
879bfdc2 | 2794 | { |
4a64f543 | 2795 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2796 | bl->shlib_disabled = 1; |
8d3788bd | 2797 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2798 | if (!*disabled_breaks) |
2799 | { | |
2800 | fprintf_unfiltered (tmp_error_stream, | |
2801 | "Cannot insert breakpoint %d.\n", | |
2802 | bl->owner->number); | |
2803 | fprintf_unfiltered (tmp_error_stream, | |
2804 | "Temporarily disabling shared " | |
2805 | "library breakpoints:\n"); | |
2806 | } | |
2807 | *disabled_breaks = 1; | |
879bfdc2 | 2808 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2809 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2810 | return 0; |
879bfdc2 DJ |
2811 | } |
2812 | else | |
879bfdc2 | 2813 | { |
35df4500 | 2814 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2815 | { |
0000e5cc PA |
2816 | *hw_breakpoint_error = 1; |
2817 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2818 | fprintf_unfiltered (tmp_error_stream, |
2819 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2820 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2821 | if (bp_err_message != NULL) | |
2822 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2823 | } |
2824 | else | |
2825 | { | |
0000e5cc PA |
2826 | if (bp_err_message == NULL) |
2827 | { | |
2828 | char *message | |
2829 | = memory_error_message (TARGET_XFER_E_IO, | |
2830 | bl->gdbarch, bl->address); | |
2831 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2832 | ||
2833 | fprintf_unfiltered (tmp_error_stream, | |
2834 | "Cannot insert breakpoint %d.\n" | |
2835 | "%s\n", | |
2836 | bl->owner->number, message); | |
2837 | do_cleanups (old_chain); | |
2838 | } | |
2839 | else | |
2840 | { | |
2841 | fprintf_unfiltered (tmp_error_stream, | |
2842 | "Cannot insert breakpoint %d: %s\n", | |
2843 | bl->owner->number, | |
2844 | bp_err_message); | |
2845 | } | |
879bfdc2 | 2846 | } |
0000e5cc | 2847 | return 1; |
879bfdc2 DJ |
2848 | |
2849 | } | |
2850 | } | |
2851 | else | |
35df4500 | 2852 | bl->inserted = 1; |
879bfdc2 | 2853 | |
0000e5cc | 2854 | return 0; |
879bfdc2 DJ |
2855 | } |
2856 | ||
35df4500 | 2857 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2858 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2859 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2860 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2861 | { |
0000e5cc PA |
2862 | int val; |
2863 | ||
77b06cd7 TJB |
2864 | gdb_assert (bl->owner->ops != NULL |
2865 | && bl->owner->ops->insert_location != NULL); | |
2866 | ||
2867 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2868 | |
2869 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2870 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2871 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2872 | { |
2873 | struct bp_location *loc, **loc_temp; | |
2874 | ||
2875 | /* But don't try to insert it, if there's already another | |
2876 | hw_access location that would be considered a duplicate | |
2877 | of this one. */ | |
2878 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2879 | if (loc != bl |
85d721b8 | 2880 | && loc->watchpoint_type == hw_access |
35df4500 | 2881 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2882 | { |
35df4500 TJB |
2883 | bl->duplicate = 1; |
2884 | bl->inserted = 1; | |
2885 | bl->target_info = loc->target_info; | |
2886 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2887 | val = 0; |
2888 | break; | |
2889 | } | |
2890 | ||
2891 | if (val == 1) | |
2892 | { | |
77b06cd7 TJB |
2893 | bl->watchpoint_type = hw_access; |
2894 | val = bl->owner->ops->insert_location (bl); | |
2895 | ||
2896 | if (val) | |
2897 | /* Back to the original value. */ | |
2898 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2899 | } |
2900 | } | |
2901 | ||
35df4500 | 2902 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2903 | } |
2904 | ||
35df4500 | 2905 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2906 | { |
0000e5cc PA |
2907 | int val; |
2908 | ||
77b06cd7 TJB |
2909 | gdb_assert (bl->owner->ops != NULL |
2910 | && bl->owner->ops->insert_location != NULL); | |
2911 | ||
2912 | val = bl->owner->ops->insert_location (bl); | |
2913 | if (val) | |
2914 | { | |
2915 | bl->owner->enable_state = bp_disabled; | |
2916 | ||
2917 | if (val == 1) | |
2918 | warning (_("\ | |
2919 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2920 | of catchpoint."), bl->owner->number); | |
2921 | else | |
2922 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2923 | } | |
2924 | ||
2925 | bl->inserted = (val == 0); | |
1640b821 DJ |
2926 | |
2927 | /* We've already printed an error message if there was a problem | |
2928 | inserting this catchpoint, and we've disabled the catchpoint, | |
2929 | so just return success. */ | |
2930 | return 0; | |
879bfdc2 DJ |
2931 | } |
2932 | ||
2933 | return 0; | |
2934 | } | |
2935 | ||
6c95b8df PA |
2936 | /* This function is called when program space PSPACE is about to be |
2937 | deleted. It takes care of updating breakpoints to not reference | |
2938 | PSPACE anymore. */ | |
2939 | ||
2940 | void | |
2941 | breakpoint_program_space_exit (struct program_space *pspace) | |
2942 | { | |
2943 | struct breakpoint *b, *b_temp; | |
876fa593 | 2944 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2945 | |
2946 | /* Remove any breakpoint that was set through this program space. */ | |
2947 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2948 | { | |
2949 | if (b->pspace == pspace) | |
2950 | delete_breakpoint (b); | |
2951 | } | |
2952 | ||
2953 | /* Breakpoints set through other program spaces could have locations | |
2954 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2955 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2956 | { |
2957 | struct bp_location *tmp; | |
2958 | ||
2959 | if (loc->pspace == pspace) | |
2960 | { | |
2bdf28a0 | 2961 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2962 | if (loc->owner->loc == loc) |
2963 | loc->owner->loc = loc->next; | |
2964 | else | |
2965 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2966 | if (tmp->next == loc) | |
2967 | { | |
2968 | tmp->next = loc->next; | |
2969 | break; | |
2970 | } | |
2971 | } | |
2972 | } | |
2973 | ||
2974 | /* Now update the global location list to permanently delete the | |
2975 | removed locations above. */ | |
44702360 | 2976 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2977 | } |
2978 | ||
74960c60 VP |
2979 | /* Make sure all breakpoints are inserted in inferior. |
2980 | Throws exception on any error. | |
2981 | A breakpoint that is already inserted won't be inserted | |
2982 | again, so calling this function twice is safe. */ | |
2983 | void | |
2984 | insert_breakpoints (void) | |
2985 | { | |
2986 | struct breakpoint *bpt; | |
2987 | ||
2988 | ALL_BREAKPOINTS (bpt) | |
2989 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2990 | { |
2991 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2992 | ||
2993 | update_watchpoint (w, 0 /* don't reparse. */); | |
2994 | } | |
74960c60 | 2995 | |
04086b45 PA |
2996 | /* Updating watchpoints creates new locations, so update the global |
2997 | location list. Explicitly tell ugll to insert locations and | |
2998 | ignore breakpoints_always_inserted_mode. */ | |
2999 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3000 | } |
3001 | ||
20388dd6 YQ |
3002 | /* Invoke CALLBACK for each of bp_location. */ |
3003 | ||
3004 | void | |
3005 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3006 | { | |
3007 | struct bp_location *loc, **loc_tmp; | |
3008 | ||
3009 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3010 | { | |
3011 | callback (loc, NULL); | |
3012 | } | |
3013 | } | |
3014 | ||
b775012e LM |
3015 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3016 | target. It is the case with deleting and disabling of breakpoints when using | |
3017 | always-inserted mode. */ | |
3018 | ||
3019 | static void | |
3020 | update_inserted_breakpoint_locations (void) | |
3021 | { | |
3022 | struct bp_location *bl, **blp_tmp; | |
3023 | int error_flag = 0; | |
3024 | int val = 0; | |
3025 | int disabled_breaks = 0; | |
3026 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3027 | int hw_bp_details_reported = 0; |
b775012e LM |
3028 | |
3029 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3030 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3031 | ||
3032 | /* Explicitly mark the warning -- this will only be printed if | |
3033 | there was an error. */ | |
3034 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3035 | ||
3036 | save_current_space_and_thread (); | |
3037 | ||
3038 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3039 | { | |
3040 | /* We only want to update software breakpoints and hardware | |
3041 | breakpoints. */ | |
3042 | if (!is_breakpoint (bl->owner)) | |
3043 | continue; | |
3044 | ||
3045 | /* We only want to update locations that are already inserted | |
3046 | and need updating. This is to avoid unwanted insertion during | |
3047 | deletion of breakpoints. */ | |
3048 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3049 | continue; | |
3050 | ||
3051 | switch_to_program_space_and_thread (bl->pspace); | |
3052 | ||
3053 | /* For targets that support global breakpoints, there's no need | |
3054 | to select an inferior to insert breakpoint to. In fact, even | |
3055 | if we aren't attached to any process yet, we should still | |
3056 | insert breakpoints. */ | |
f5656ead | 3057 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3058 | && ptid_equal (inferior_ptid, null_ptid)) |
3059 | continue; | |
3060 | ||
3061 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3062 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3063 | if (val) |
3064 | error_flag = val; | |
3065 | } | |
3066 | ||
3067 | if (error_flag) | |
3068 | { | |
3069 | target_terminal_ours_for_output (); | |
3070 | error_stream (tmp_error_stream); | |
3071 | } | |
3072 | ||
3073 | do_cleanups (cleanups); | |
3074 | } | |
3075 | ||
c30eee59 | 3076 | /* Used when starting or continuing the program. */ |
c906108c | 3077 | |
74960c60 VP |
3078 | static void |
3079 | insert_breakpoint_locations (void) | |
c906108c | 3080 | { |
a5606eee | 3081 | struct breakpoint *bpt; |
35df4500 | 3082 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3083 | int error_flag = 0; |
c906108c | 3084 | int val = 0; |
3fbb6ffa | 3085 | int disabled_breaks = 0; |
81d0cc19 | 3086 | int hw_breakpoint_error = 0; |
dd61ec5c | 3087 | int hw_bp_error_explained_already = 0; |
c906108c | 3088 | |
81d0cc19 | 3089 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3090 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3091 | |
81d0cc19 GS |
3092 | /* Explicitly mark the warning -- this will only be printed if |
3093 | there was an error. */ | |
3094 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3095 | |
3096 | save_current_space_and_thread (); | |
3097 | ||
35df4500 | 3098 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3099 | { |
b775012e | 3100 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3101 | continue; |
3102 | ||
4a64f543 MS |
3103 | /* There is no point inserting thread-specific breakpoints if |
3104 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3105 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3106 | if (bl->owner->thread != -1 |
3107 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3108 | continue; |
3109 | ||
35df4500 | 3110 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3111 | |
3112 | /* For targets that support global breakpoints, there's no need | |
3113 | to select an inferior to insert breakpoint to. In fact, even | |
3114 | if we aren't attached to any process yet, we should still | |
3115 | insert breakpoints. */ | |
f5656ead | 3116 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3117 | && ptid_equal (inferior_ptid, null_ptid)) |
3118 | continue; | |
3119 | ||
3fbb6ffa | 3120 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3121 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3122 | if (val) |
eacd795a | 3123 | error_flag = val; |
879bfdc2 | 3124 | } |
c906108c | 3125 | |
4a64f543 MS |
3126 | /* If we failed to insert all locations of a watchpoint, remove |
3127 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3128 | ALL_BREAKPOINTS (bpt) |
3129 | { | |
3130 | int some_failed = 0; | |
3131 | struct bp_location *loc; | |
3132 | ||
3133 | if (!is_hardware_watchpoint (bpt)) | |
3134 | continue; | |
3135 | ||
d6b74ac4 | 3136 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3137 | continue; |
74960c60 VP |
3138 | |
3139 | if (bpt->disposition == disp_del_at_next_stop) | |
3140 | continue; | |
a5606eee VP |
3141 | |
3142 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3143 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3144 | { |
3145 | some_failed = 1; | |
3146 | break; | |
3147 | } | |
3148 | if (some_failed) | |
3149 | { | |
3150 | for (loc = bpt->loc; loc; loc = loc->next) | |
3151 | if (loc->inserted) | |
3152 | remove_breakpoint (loc, mark_uninserted); | |
3153 | ||
3154 | hw_breakpoint_error = 1; | |
3155 | fprintf_unfiltered (tmp_error_stream, | |
3156 | "Could not insert hardware watchpoint %d.\n", | |
3157 | bpt->number); | |
eacd795a | 3158 | error_flag = -1; |
a5606eee VP |
3159 | } |
3160 | } | |
3161 | ||
eacd795a | 3162 | if (error_flag) |
81d0cc19 GS |
3163 | { |
3164 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3165 | message about possibly exhausted resources. */ | |
dd61ec5c | 3166 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3167 | { |
c6510018 MS |
3168 | fprintf_unfiltered (tmp_error_stream, |
3169 | "Could not insert hardware breakpoints:\n\ | |
3170 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3171 | } |
81d0cc19 GS |
3172 | target_terminal_ours_for_output (); |
3173 | error_stream (tmp_error_stream); | |
3174 | } | |
f7545552 TT |
3175 | |
3176 | do_cleanups (cleanups); | |
c906108c SS |
3177 | } |
3178 | ||
c30eee59 TJB |
3179 | /* Used when the program stops. |
3180 | Returns zero if successful, or non-zero if there was a problem | |
3181 | removing a breakpoint location. */ | |
3182 | ||
c906108c | 3183 | int |
fba45db2 | 3184 | remove_breakpoints (void) |
c906108c | 3185 | { |
35df4500 | 3186 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3187 | int val = 0; |
c906108c | 3188 | |
35df4500 | 3189 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3190 | { |
1e4d1764 | 3191 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3192 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3193 | } |
3a1bae8e | 3194 | return val; |
c906108c SS |
3195 | } |
3196 | ||
49fa26b0 PA |
3197 | /* When a thread exits, remove breakpoints that are related to |
3198 | that thread. */ | |
3199 | ||
3200 | static void | |
3201 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3202 | { | |
3203 | struct breakpoint *b, *b_tmp; | |
3204 | ||
3205 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3206 | { | |
96181529 | 3207 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3208 | { |
3209 | b->disposition = disp_del_at_next_stop; | |
3210 | ||
3211 | printf_filtered (_("\ | |
46ecd527 | 3212 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3213 | b->number, tp->num); |
3214 | ||
3215 | /* Hide it from the user. */ | |
3216 | b->number = 0; | |
3217 | } | |
3218 | } | |
3219 | } | |
3220 | ||
6c95b8df PA |
3221 | /* Remove breakpoints of process PID. */ |
3222 | ||
3223 | int | |
3224 | remove_breakpoints_pid (int pid) | |
3225 | { | |
35df4500 | 3226 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3227 | int val; |
3228 | struct inferior *inf = find_inferior_pid (pid); | |
3229 | ||
35df4500 | 3230 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3231 | { |
35df4500 | 3232 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3233 | continue; |
3234 | ||
fc126975 | 3235 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3236 | { |
35df4500 | 3237 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3238 | if (val != 0) |
3239 | return val; | |
3240 | } | |
3241 | } | |
3242 | return 0; | |
3243 | } | |
3244 | ||
c906108c | 3245 | int |
fba45db2 | 3246 | reattach_breakpoints (int pid) |
c906108c | 3247 | { |
6c95b8df | 3248 | struct cleanup *old_chain; |
35df4500 | 3249 | struct bp_location *bl, **blp_tmp; |
c906108c | 3250 | int val; |
86b887df | 3251 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3252 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3253 | struct inferior *inf; |
3254 | struct thread_info *tp; | |
3255 | ||
3256 | tp = any_live_thread_of_process (pid); | |
3257 | if (tp == NULL) | |
3258 | return 1; | |
3259 | ||
3260 | inf = find_inferior_pid (pid); | |
3261 | old_chain = save_inferior_ptid (); | |
3262 | ||
3263 | inferior_ptid = tp->ptid; | |
a4954f26 | 3264 | |
86b887df | 3265 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3266 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3267 | |
35df4500 | 3268 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3269 | { |
35df4500 | 3270 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3271 | continue; |
3272 | ||
35df4500 | 3273 | if (bl->inserted) |
c5aa993b | 3274 | { |
35df4500 | 3275 | bl->inserted = 0; |
dd61ec5c | 3276 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3277 | if (val != 0) |
3278 | { | |
ce696e05 | 3279 | do_cleanups (old_chain); |
c5aa993b JM |
3280 | return val; |
3281 | } | |
3282 | } | |
3283 | } | |
ce696e05 | 3284 | do_cleanups (old_chain); |
c906108c SS |
3285 | return 0; |
3286 | } | |
3287 | ||
e58b0e63 PA |
3288 | static int internal_breakpoint_number = -1; |
3289 | ||
84f4c1fe PM |
3290 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3291 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3292 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3293 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3294 | breakpoint_count and that value incremented. Internal breakpoints |
3295 | do not set the internal var bpnum. */ | |
3296 | static void | |
3297 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3298 | { | |
3299 | if (internal) | |
3300 | b->number = internal_breakpoint_number--; | |
3301 | else | |
3302 | { | |
3303 | set_breakpoint_count (breakpoint_count + 1); | |
3304 | b->number = breakpoint_count; | |
3305 | } | |
3306 | } | |
3307 | ||
e62c965a | 3308 | static struct breakpoint * |
a6d9a66e | 3309 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3310 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3311 | const struct breakpoint_ops *ops) |
e62c965a | 3312 | { |
e62c965a PP |
3313 | struct symtab_and_line sal; |
3314 | struct breakpoint *b; | |
3315 | ||
4a64f543 | 3316 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3317 | |
3318 | sal.pc = address; | |
3319 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3320 | sal.pspace = current_program_space; |
e62c965a | 3321 | |
06edf0c0 | 3322 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3323 | b->number = internal_breakpoint_number--; |
3324 | b->disposition = disp_donttouch; | |
3325 | ||
3326 | return b; | |
3327 | } | |
3328 | ||
17450429 PP |
3329 | static const char *const longjmp_names[] = |
3330 | { | |
3331 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3332 | }; | |
3333 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3334 | ||
3335 | /* Per-objfile data private to breakpoint.c. */ | |
3336 | struct breakpoint_objfile_data | |
3337 | { | |
3338 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3339 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3340 | |
3341 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3342 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3343 | |
28106bc2 SDJ |
3344 | /* True if we have looked for longjmp probes. */ |
3345 | int longjmp_searched; | |
3346 | ||
3347 | /* SystemTap probe points for longjmp (if any). */ | |
3348 | VEC (probe_p) *longjmp_probes; | |
3349 | ||
17450429 | 3350 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3351 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3352 | |
3353 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3354 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3355 | |
3356 | /* True if we have looked for exception probes. */ | |
3357 | int exception_searched; | |
3358 | ||
3359 | /* SystemTap probe points for unwinding (if any). */ | |
3360 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3361 | }; |
3362 | ||
3363 | static const struct objfile_data *breakpoint_objfile_key; | |
3364 | ||
3365 | /* Minimal symbol not found sentinel. */ | |
3366 | static struct minimal_symbol msym_not_found; | |
3367 | ||
3368 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3369 | ||
3370 | static int | |
3371 | msym_not_found_p (const struct minimal_symbol *msym) | |
3372 | { | |
3373 | return msym == &msym_not_found; | |
3374 | } | |
3375 | ||
3376 | /* Return per-objfile data needed by breakpoint.c. | |
3377 | Allocate the data if necessary. */ | |
3378 | ||
3379 | static struct breakpoint_objfile_data * | |
3380 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3381 | { | |
3382 | struct breakpoint_objfile_data *bp_objfile_data; | |
3383 | ||
3384 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3385 | if (bp_objfile_data == NULL) | |
3386 | { | |
3387 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3388 | sizeof (*bp_objfile_data)); | |
3389 | ||
3390 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3391 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3392 | } | |
3393 | return bp_objfile_data; | |
3394 | } | |
3395 | ||
28106bc2 SDJ |
3396 | static void |
3397 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3398 | { | |
3399 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3400 | ||
3401 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3402 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3403 | } | |
3404 | ||
e62c965a | 3405 | static void |
af02033e | 3406 | create_overlay_event_breakpoint (void) |
e62c965a | 3407 | { |
69de3c6a | 3408 | struct objfile *objfile; |
af02033e | 3409 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3410 | |
69de3c6a PP |
3411 | ALL_OBJFILES (objfile) |
3412 | { | |
3413 | struct breakpoint *b; | |
17450429 PP |
3414 | struct breakpoint_objfile_data *bp_objfile_data; |
3415 | CORE_ADDR addr; | |
69de3c6a | 3416 | |
17450429 PP |
3417 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3418 | ||
3b7344d5 | 3419 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3420 | continue; |
3421 | ||
3b7344d5 | 3422 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3423 | { |
3b7344d5 | 3424 | struct bound_minimal_symbol m; |
17450429 PP |
3425 | |
3426 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3427 | if (m.minsym == NULL) |
17450429 PP |
3428 | { |
3429 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3430 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3431 | continue; |
3432 | } | |
3433 | bp_objfile_data->overlay_msym = m; | |
3434 | } | |
e62c965a | 3435 | |
77e371c0 | 3436 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3437 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3438 | bp_overlay_event, |
3439 | &internal_breakpoint_ops); | |
69de3c6a | 3440 | b->addr_string = xstrdup (func_name); |
e62c965a | 3441 | |
69de3c6a PP |
3442 | if (overlay_debugging == ovly_auto) |
3443 | { | |
3444 | b->enable_state = bp_enabled; | |
3445 | overlay_events_enabled = 1; | |
3446 | } | |
3447 | else | |
3448 | { | |
3449 | b->enable_state = bp_disabled; | |
3450 | overlay_events_enabled = 0; | |
3451 | } | |
e62c965a | 3452 | } |
44702360 | 3453 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3454 | } |
3455 | ||
0fd8e87f | 3456 | static void |
af02033e | 3457 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3458 | { |
6c95b8df | 3459 | struct program_space *pspace; |
6c95b8df PA |
3460 | struct cleanup *old_chain; |
3461 | ||
3462 | old_chain = save_current_program_space (); | |
0fd8e87f | 3463 | |
6c95b8df | 3464 | ALL_PSPACES (pspace) |
af02033e PP |
3465 | { |
3466 | struct objfile *objfile; | |
3467 | ||
3468 | set_current_program_space (pspace); | |
3469 | ||
3470 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3471 | { |
af02033e PP |
3472 | int i; |
3473 | struct gdbarch *gdbarch; | |
17450429 | 3474 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3475 | |
af02033e | 3476 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3477 | |
17450429 PP |
3478 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3479 | ||
28106bc2 SDJ |
3480 | if (!bp_objfile_data->longjmp_searched) |
3481 | { | |
25f9533e SDJ |
3482 | VEC (probe_p) *ret; |
3483 | ||
3484 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3485 | if (ret != NULL) | |
3486 | { | |
3487 | /* We are only interested in checking one element. */ | |
3488 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3489 | ||
3490 | if (!can_evaluate_probe_arguments (p)) | |
3491 | { | |
3492 | /* We cannot use the probe interface here, because it does | |
3493 | not know how to evaluate arguments. */ | |
3494 | VEC_free (probe_p, ret); | |
3495 | ret = NULL; | |
3496 | } | |
3497 | } | |
3498 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3499 | bp_objfile_data->longjmp_searched = 1; |
3500 | } | |
3501 | ||
3502 | if (bp_objfile_data->longjmp_probes != NULL) | |
3503 | { | |
3504 | int i; | |
3505 | struct probe *probe; | |
3506 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3507 | ||
3508 | for (i = 0; | |
3509 | VEC_iterate (probe_p, | |
3510 | bp_objfile_data->longjmp_probes, | |
3511 | i, probe); | |
3512 | ++i) | |
3513 | { | |
3514 | struct breakpoint *b; | |
3515 | ||
729662a5 TT |
3516 | b = create_internal_breakpoint (gdbarch, |
3517 | get_probe_address (probe, | |
3518 | objfile), | |
28106bc2 SDJ |
3519 | bp_longjmp_master, |
3520 | &internal_breakpoint_ops); | |
3521 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3522 | b->enable_state = bp_disabled; | |
3523 | } | |
3524 | ||
3525 | continue; | |
3526 | } | |
3527 | ||
0569175e TSD |
3528 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3529 | continue; | |
3530 | ||
17450429 | 3531 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3532 | { |
3533 | struct breakpoint *b; | |
af02033e | 3534 | const char *func_name; |
17450429 | 3535 | CORE_ADDR addr; |
6c95b8df | 3536 | |
3b7344d5 | 3537 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3538 | continue; |
0fd8e87f | 3539 | |
17450429 | 3540 | func_name = longjmp_names[i]; |
3b7344d5 | 3541 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3542 | { |
3b7344d5 | 3543 | struct bound_minimal_symbol m; |
17450429 PP |
3544 | |
3545 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3546 | if (m.minsym == NULL) |
17450429 PP |
3547 | { |
3548 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3549 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3550 | continue; |
3551 | } | |
3552 | bp_objfile_data->longjmp_msym[i] = m; | |
3553 | } | |
3554 | ||
77e371c0 | 3555 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3556 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3557 | &internal_breakpoint_ops); | |
af02033e PP |
3558 | b->addr_string = xstrdup (func_name); |
3559 | b->enable_state = bp_disabled; | |
3560 | } | |
0fd8e87f | 3561 | } |
af02033e | 3562 | } |
44702360 | 3563 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3564 | |
3565 | do_cleanups (old_chain); | |
0fd8e87f UW |
3566 | } |
3567 | ||
af02033e | 3568 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3569 | static void |
af02033e | 3570 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3571 | { |
3572 | struct program_space *pspace; | |
aa7d318d | 3573 | struct cleanup *old_chain; |
af02033e | 3574 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3575 | |
3576 | old_chain = save_current_program_space (); | |
3577 | ||
3578 | ALL_PSPACES (pspace) | |
17450429 PP |
3579 | { |
3580 | struct objfile *objfile; | |
3581 | CORE_ADDR addr; | |
3582 | ||
3583 | set_current_program_space (pspace); | |
3584 | ||
aa7d318d TT |
3585 | ALL_OBJFILES (objfile) |
3586 | { | |
3587 | struct breakpoint *b; | |
17450429 | 3588 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3589 | |
17450429 | 3590 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3591 | |
3b7344d5 | 3592 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3593 | continue; |
3594 | ||
3b7344d5 | 3595 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3596 | { |
3b7344d5 | 3597 | struct bound_minimal_symbol m; |
17450429 PP |
3598 | |
3599 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3600 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3601 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3602 | { |
3603 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3604 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3605 | continue; |
3606 | } | |
3607 | bp_objfile_data->terminate_msym = m; | |
3608 | } | |
aa7d318d | 3609 | |
77e371c0 | 3610 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3611 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3612 | bp_std_terminate_master, |
3613 | &internal_breakpoint_ops); | |
aa7d318d TT |
3614 | b->addr_string = xstrdup (func_name); |
3615 | b->enable_state = bp_disabled; | |
3616 | } | |
17450429 PP |
3617 | } |
3618 | ||
44702360 | 3619 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3620 | |
3621 | do_cleanups (old_chain); | |
3622 | } | |
3623 | ||
186c406b TT |
3624 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3625 | ||
70221824 | 3626 | static void |
186c406b TT |
3627 | create_exception_master_breakpoint (void) |
3628 | { | |
3629 | struct objfile *objfile; | |
17450429 | 3630 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3631 | |
3632 | ALL_OBJFILES (objfile) | |
3633 | { | |
17450429 PP |
3634 | struct breakpoint *b; |
3635 | struct gdbarch *gdbarch; | |
3636 | struct breakpoint_objfile_data *bp_objfile_data; | |
3637 | CORE_ADDR addr; | |
3638 | ||
3639 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3640 | ||
28106bc2 SDJ |
3641 | /* We prefer the SystemTap probe point if it exists. */ |
3642 | if (!bp_objfile_data->exception_searched) | |
3643 | { | |
25f9533e SDJ |
3644 | VEC (probe_p) *ret; |
3645 | ||
3646 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3647 | ||
3648 | if (ret != NULL) | |
3649 | { | |
3650 | /* We are only interested in checking one element. */ | |
3651 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3652 | ||
3653 | if (!can_evaluate_probe_arguments (p)) | |
3654 | { | |
3655 | /* We cannot use the probe interface here, because it does | |
3656 | not know how to evaluate arguments. */ | |
3657 | VEC_free (probe_p, ret); | |
3658 | ret = NULL; | |
3659 | } | |
3660 | } | |
3661 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3662 | bp_objfile_data->exception_searched = 1; |
3663 | } | |
3664 | ||
3665 | if (bp_objfile_data->exception_probes != NULL) | |
3666 | { | |
3667 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3668 | int i; | |
3669 | struct probe *probe; | |
3670 | ||
3671 | for (i = 0; | |
3672 | VEC_iterate (probe_p, | |
3673 | bp_objfile_data->exception_probes, | |
3674 | i, probe); | |
3675 | ++i) | |
3676 | { | |
3677 | struct breakpoint *b; | |
3678 | ||
729662a5 TT |
3679 | b = create_internal_breakpoint (gdbarch, |
3680 | get_probe_address (probe, | |
3681 | objfile), | |
28106bc2 SDJ |
3682 | bp_exception_master, |
3683 | &internal_breakpoint_ops); | |
3684 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3685 | b->enable_state = bp_disabled; | |
3686 | } | |
3687 | ||
3688 | continue; | |
3689 | } | |
3690 | ||
3691 | /* Otherwise, try the hook function. */ | |
3692 | ||
3b7344d5 | 3693 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3694 | continue; |
3695 | ||
3696 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3697 | |
3b7344d5 | 3698 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3699 | { |
3b7344d5 | 3700 | struct bound_minimal_symbol debug_hook; |
186c406b | 3701 | |
17450429 | 3702 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3703 | if (debug_hook.minsym == NULL) |
17450429 | 3704 | { |
3b7344d5 | 3705 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3706 | continue; |
3707 | } | |
3708 | ||
3709 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3710 | } |
17450429 | 3711 | |
77e371c0 | 3712 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3713 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3714 | ¤t_target); | |
06edf0c0 PA |
3715 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3716 | &internal_breakpoint_ops); | |
17450429 PP |
3717 | b->addr_string = xstrdup (func_name); |
3718 | b->enable_state = bp_disabled; | |
186c406b TT |
3719 | } |
3720 | ||
44702360 | 3721 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3722 | } |
3723 | ||
c906108c | 3724 | void |
fba45db2 | 3725 | update_breakpoints_after_exec (void) |
c906108c | 3726 | { |
35df4500 | 3727 | struct breakpoint *b, *b_tmp; |
876fa593 | 3728 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3729 | |
25b22b0a PA |
3730 | /* We're about to delete breakpoints from GDB's lists. If the |
3731 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3732 | writing the breakpoints' "shadow contents" back into memory. The | |
3733 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3734 | do that. Instead, the target is responsible from marking | |
3735 | breakpoints out as soon as it detects an exec. We don't do that | |
3736 | here instead, because there may be other attempts to delete | |
3737 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3738 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3739 | if (bploc->pspace == current_program_space) |
3740 | gdb_assert (!bploc->inserted); | |
c906108c | 3741 | |
35df4500 | 3742 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3743 | { |
6c95b8df PA |
3744 | if (b->pspace != current_program_space) |
3745 | continue; | |
3746 | ||
4a64f543 | 3747 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3748 | if (b->type == bp_shlib_event) |
3749 | { | |
3750 | delete_breakpoint (b); | |
3751 | continue; | |
3752 | } | |
c906108c | 3753 | |
4a64f543 | 3754 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3755 | if (b->type == bp_jit_event) |
3756 | { | |
3757 | delete_breakpoint (b); | |
3758 | continue; | |
3759 | } | |
3760 | ||
1900040c | 3761 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3762 | as must overlay event and longjmp master breakpoints. */ |
3763 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3764 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3765 | || b->type == bp_exception_master) | |
c4093a6a JM |
3766 | { |
3767 | delete_breakpoint (b); | |
3768 | continue; | |
3769 | } | |
3770 | ||
4a64f543 | 3771 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3772 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3773 | { |
3774 | delete_breakpoint (b); | |
3775 | continue; | |
3776 | } | |
3777 | ||
7c16b83e PA |
3778 | /* Just like single-step breakpoints. */ |
3779 | if (b->type == bp_single_step) | |
3780 | { | |
3781 | delete_breakpoint (b); | |
3782 | continue; | |
3783 | } | |
3784 | ||
611c83ae PA |
3785 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3786 | after an exec. */ | |
186c406b | 3787 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3788 | || b->type == bp_longjmp_call_dummy |
186c406b | 3789 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3790 | { |
3791 | delete_breakpoint (b); | |
3792 | continue; | |
3793 | } | |
3794 | ||
ce78b96d JB |
3795 | if (b->type == bp_catchpoint) |
3796 | { | |
3797 | /* For now, none of the bp_catchpoint breakpoints need to | |
3798 | do anything at this point. In the future, if some of | |
3799 | the catchpoints need to something, we will need to add | |
3800 | a new method, and call this method from here. */ | |
3801 | continue; | |
3802 | } | |
3803 | ||
c5aa993b JM |
3804 | /* bp_finish is a special case. The only way we ought to be able |
3805 | to see one of these when an exec() has happened, is if the user | |
3806 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3807 | carries them to the call-site of the current callee, by setting | |
3808 | a temporary bp there and resuming. But in this case, the finish | |
3809 | will carry them entirely through the vfork & exec. | |
3810 | ||
3811 | We don't want to allow a bp_finish to remain inserted now. But | |
3812 | we can't safely delete it, 'cause finish_command has a handle to | |
3813 | the bp on a bpstat, and will later want to delete it. There's a | |
3814 | chance (and I've seen it happen) that if we delete the bp_finish | |
3815 | here, that its storage will get reused by the time finish_command | |
3816 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3817 | We really must allow finish_command to delete a bp_finish. | |
3818 | ||
e5dd4106 | 3819 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3820 | it's safe to delete something others may have handles to?" |
3821 | problem, what we'll do here is just uninsert the bp_finish, and | |
3822 | let finish_command delete it. | |
3823 | ||
3824 | (We know the bp_finish is "doomed" in the sense that it's | |
3825 | momentary, and will be deleted as soon as finish_command sees | |
3826 | the inferior stopped. So it doesn't matter that the bp's | |
3827 | address is probably bogus in the new a.out, unlike e.g., the | |
3828 | solib breakpoints.) */ | |
c5aa993b | 3829 | |
c5aa993b JM |
3830 | if (b->type == bp_finish) |
3831 | { | |
3832 | continue; | |
3833 | } | |
3834 | ||
3835 | /* Without a symbolic address, we have little hope of the | |
3836 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3837 | a.out. */ |
c5aa993b JM |
3838 | if (b->addr_string == NULL) |
3839 | { | |
3840 | delete_breakpoint (b); | |
3841 | continue; | |
3842 | } | |
c5aa993b | 3843 | } |
c906108c SS |
3844 | } |
3845 | ||
3846 | int | |
d80ee84f | 3847 | detach_breakpoints (ptid_t ptid) |
c906108c | 3848 | { |
35df4500 | 3849 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3850 | int val = 0; |
ce696e05 | 3851 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3852 | struct inferior *inf = current_inferior (); |
c5aa993b | 3853 | |
dfd4cc63 | 3854 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3855 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3856 | |
6c95b8df | 3857 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3858 | inferior_ptid = ptid; |
35df4500 | 3859 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3860 | { |
35df4500 | 3861 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3862 | continue; |
3863 | ||
bd9673a4 PW |
3864 | /* This function must physically remove breakpoints locations |
3865 | from the specified ptid, without modifying the breakpoint | |
3866 | package's state. Locations of type bp_loc_other are only | |
3867 | maintained at GDB side. So, there is no need to remove | |
3868 | these bp_loc_other locations. Moreover, removing these | |
3869 | would modify the breakpoint package's state. */ | |
3870 | if (bl->loc_type == bp_loc_other) | |
3871 | continue; | |
3872 | ||
35df4500 TJB |
3873 | if (bl->inserted) |
3874 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3875 | } |
d03285ec | 3876 | |
ce696e05 | 3877 | do_cleanups (old_chain); |
3a1bae8e | 3878 | return val; |
c906108c SS |
3879 | } |
3880 | ||
35df4500 | 3881 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3882 | Note that this is used to detach breakpoints from a child fork. |
3883 | When we get here, the child isn't in the inferior list, and neither | |
3884 | do we have objects to represent its address space --- we should | |
35df4500 | 3885 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3886 | |
c906108c | 3887 | static int |
35df4500 | 3888 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3889 | { |
3890 | int val; | |
c5aa993b | 3891 | |
35df4500 TJB |
3892 | /* BL is never in moribund_locations by our callers. */ |
3893 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3894 | |
1a853c52 | 3895 | if (bl->permanent) |
c2c6d25f JM |
3896 | /* Permanent breakpoints cannot be inserted or removed. */ |
3897 | return 0; | |
3898 | ||
74960c60 VP |
3899 | /* The type of none suggests that owner is actually deleted. |
3900 | This should not ever happen. */ | |
35df4500 | 3901 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3902 | |
35df4500 TJB |
3903 | if (bl->loc_type == bp_loc_software_breakpoint |
3904 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3905 | { |
c02f5703 MS |
3906 | /* "Normal" instruction breakpoint: either the standard |
3907 | trap-instruction bp (bp_breakpoint), or a | |
3908 | bp_hardware_breakpoint. */ | |
3909 | ||
3910 | /* First check to see if we have to handle an overlay. */ | |
3911 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3912 | || bl->section == NULL |
3913 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3914 | { |
3915 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3916 | |
3917 | /* If we're trying to uninsert a memory breakpoint that we | |
3918 | know is set in a dynamic object that is marked | |
3919 | shlib_disabled, then either the dynamic object was | |
3920 | removed with "remove-symbol-file" or with | |
3921 | "nosharedlibrary". In the former case, we don't know | |
3922 | whether another dynamic object might have loaded over the | |
3923 | breakpoint's address -- the user might well let us know | |
3924 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3925 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3926 | list of dynamically loaded objects). If we have the |
3927 | breakpoint's shadow memory, that is, this is a software | |
3928 | breakpoint managed by GDB, check whether the breakpoint | |
3929 | is still inserted in memory, to avoid overwriting wrong | |
3930 | code with stale saved shadow contents. Note that HW | |
3931 | breakpoints don't have shadow memory, as they're | |
3932 | implemented using a mechanism that is not dependent on | |
3933 | being able to modify the target's memory, and as such | |
3934 | they should always be removed. */ | |
3935 | if (bl->shlib_disabled | |
3936 | && bl->target_info.shadow_len != 0 | |
3937 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3938 | val = 0; | |
3939 | else | |
3940 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3941 | } |
c906108c SS |
3942 | else |
3943 | { | |
4a64f543 | 3944 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3945 | Did we set a breakpoint at the LMA? */ |
3946 | if (!overlay_events_enabled) | |
3947 | { | |
3948 | /* Yes -- overlay event support is not active, so we | |
3949 | should have set a breakpoint at the LMA. Remove it. | |
3950 | */ | |
c02f5703 MS |
3951 | /* Ignore any failures: if the LMA is in ROM, we will |
3952 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3953 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3954 | target_remove_hw_breakpoint (bl->gdbarch, | |
3955 | &bl->overlay_target_info); | |
c02f5703 | 3956 | else |
35df4500 TJB |
3957 | target_remove_breakpoint (bl->gdbarch, |
3958 | &bl->overlay_target_info); | |
c02f5703 MS |
3959 | } |
3960 | /* Did we set a breakpoint at the VMA? | |
3961 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3962 | if (bl->inserted) |
c906108c | 3963 | { |
c02f5703 MS |
3964 | /* Yes -- remove it. Previously we did not bother to |
3965 | remove the breakpoint if the section had been | |
3966 | unmapped, but let's not rely on that being safe. We | |
3967 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3968 | |
3969 | /* However, we should remove *software* breakpoints only | |
3970 | if the section is still mapped, or else we overwrite | |
3971 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3972 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3973 | || section_is_mapped (bl->section)) | |
3974 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3975 | else |
3976 | val = 0; | |
c906108c | 3977 | } |
c02f5703 MS |
3978 | else |
3979 | { | |
3980 | /* No -- not inserted, so no need to remove. No error. */ | |
3981 | val = 0; | |
3982 | } | |
c906108c | 3983 | } |
879d1e6b | 3984 | |
08351840 PA |
3985 | /* In some cases, we might not be able to remove a breakpoint in |
3986 | a shared library that has already been removed, but we have | |
3987 | not yet processed the shlib unload event. Similarly for an | |
3988 | unloaded add-symbol-file object - the user might not yet have | |
3989 | had the chance to remove-symbol-file it. shlib_disabled will | |
3990 | be set if the library/object has already been removed, but | |
3991 | the breakpoint hasn't been uninserted yet, e.g., after | |
3992 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3993 | always-inserted mode. */ | |
076855f9 | 3994 | if (val |
08351840 PA |
3995 | && (bl->loc_type == bp_loc_software_breakpoint |
3996 | && (bl->shlib_disabled | |
3997 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3998 | || shared_objfile_contains_address_p (bl->pspace, |
3999 | bl->address)))) | |
879d1e6b UW |
4000 | val = 0; |
4001 | ||
c906108c SS |
4002 | if (val) |
4003 | return val; | |
35df4500 | 4004 | bl->inserted = (is == mark_inserted); |
c906108c | 4005 | } |
35df4500 | 4006 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4007 | { |
77b06cd7 TJB |
4008 | gdb_assert (bl->owner->ops != NULL |
4009 | && bl->owner->ops->remove_location != NULL); | |
4010 | ||
35df4500 | 4011 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4012 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4013 | |
c906108c | 4014 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4015 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4016 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4017 | bl->owner->number); |
c906108c | 4018 | } |
35df4500 TJB |
4019 | else if (bl->owner->type == bp_catchpoint |
4020 | && breakpoint_enabled (bl->owner) | |
4021 | && !bl->duplicate) | |
ce78b96d | 4022 | { |
77b06cd7 TJB |
4023 | gdb_assert (bl->owner->ops != NULL |
4024 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4025 | |
77b06cd7 | 4026 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4027 | if (val) |
4028 | return val; | |
77b06cd7 | 4029 | |
35df4500 | 4030 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4031 | } |
c906108c SS |
4032 | |
4033 | return 0; | |
4034 | } | |
4035 | ||
6c95b8df | 4036 | static int |
35df4500 | 4037 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4038 | { |
4039 | int ret; | |
4040 | struct cleanup *old_chain; | |
4041 | ||
35df4500 TJB |
4042 | /* BL is never in moribund_locations by our callers. */ |
4043 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4044 | |
1a853c52 | 4045 | if (bl->permanent) |
6c95b8df PA |
4046 | /* Permanent breakpoints cannot be inserted or removed. */ |
4047 | return 0; | |
4048 | ||
4049 | /* The type of none suggests that owner is actually deleted. | |
4050 | This should not ever happen. */ | |
35df4500 | 4051 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4052 | |
4053 | old_chain = save_current_space_and_thread (); | |
4054 | ||
35df4500 | 4055 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4056 | |
35df4500 | 4057 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4058 | |
4059 | do_cleanups (old_chain); | |
4060 | return ret; | |
4061 | } | |
4062 | ||
c906108c SS |
4063 | /* Clear the "inserted" flag in all breakpoints. */ |
4064 | ||
25b22b0a | 4065 | void |
fba45db2 | 4066 | mark_breakpoints_out (void) |
c906108c | 4067 | { |
35df4500 | 4068 | struct bp_location *bl, **blp_tmp; |
c906108c | 4069 | |
35df4500 | 4070 | ALL_BP_LOCATIONS (bl, blp_tmp) |
1a853c52 PA |
4071 | if (bl->pspace == current_program_space |
4072 | && !bl->permanent) | |
35df4500 | 4073 | bl->inserted = 0; |
c906108c SS |
4074 | } |
4075 | ||
53a5351d JM |
4076 | /* Clear the "inserted" flag in all breakpoints and delete any |
4077 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4078 | |
4079 | Plus other such housekeeping that has to be done for breakpoints | |
4080 | between runs. | |
4081 | ||
53a5351d JM |
4082 | Note: this function gets called at the end of a run (by |
4083 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4084 | init_wait_for_inferior). */ |
c906108c SS |
4085 | |
4086 | ||
4087 | ||
4088 | void | |
fba45db2 | 4089 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4090 | { |
35df4500 TJB |
4091 | struct breakpoint *b, *b_tmp; |
4092 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4093 | int ix; |
6c95b8df | 4094 | struct program_space *pspace = current_program_space; |
c906108c | 4095 | |
50c71eaf PA |
4096 | /* If breakpoint locations are shared across processes, then there's |
4097 | nothing to do. */ | |
f5656ead | 4098 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4099 | return; |
4100 | ||
1a853c52 | 4101 | mark_breakpoints_out (); |
075f6582 | 4102 | |
35df4500 | 4103 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4104 | { |
6c95b8df PA |
4105 | if (b->loc && b->loc->pspace != pspace) |
4106 | continue; | |
4107 | ||
c5aa993b JM |
4108 | switch (b->type) |
4109 | { | |
4110 | case bp_call_dummy: | |
e2e4d78b | 4111 | case bp_longjmp_call_dummy: |
c906108c | 4112 | |
c5aa993b | 4113 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4114 | cause problems when the inferior is rerun, so we better get |
4115 | rid of it. */ | |
4116 | ||
4117 | case bp_watchpoint_scope: | |
4118 | ||
4119 | /* Also get rid of scope breakpoints. */ | |
4120 | ||
4121 | case bp_shlib_event: | |
4122 | ||
4123 | /* Also remove solib event breakpoints. Their addresses may | |
4124 | have changed since the last time we ran the program. | |
4125 | Actually we may now be debugging against different target; | |
4126 | and so the solib backend that installed this breakpoint may | |
4127 | not be used in by the target. E.g., | |
4128 | ||
4129 | (gdb) file prog-linux | |
4130 | (gdb) run # native linux target | |
4131 | ... | |
4132 | (gdb) kill | |
4133 | (gdb) file prog-win.exe | |
4134 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4135 | */ | |
c906108c | 4136 | |
f59f708a PA |
4137 | case bp_step_resume: |
4138 | ||
4139 | /* Also remove step-resume breakpoints. */ | |
4140 | ||
7c16b83e PA |
4141 | case bp_single_step: |
4142 | ||
4143 | /* Also remove single-step breakpoints. */ | |
4144 | ||
c5aa993b JM |
4145 | delete_breakpoint (b); |
4146 | break; | |
c906108c | 4147 | |
c5aa993b JM |
4148 | case bp_watchpoint: |
4149 | case bp_hardware_watchpoint: | |
4150 | case bp_read_watchpoint: | |
4151 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4152 | { |
4153 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4154 | |
3a5c3e22 PA |
4155 | /* Likewise for watchpoints on local expressions. */ |
4156 | if (w->exp_valid_block != NULL) | |
4157 | delete_breakpoint (b); | |
4158 | else if (context == inf_starting) | |
4159 | { | |
4160 | /* Reset val field to force reread of starting value in | |
4161 | insert_breakpoints. */ | |
4162 | if (w->val) | |
4163 | value_free (w->val); | |
4164 | w->val = NULL; | |
4165 | w->val_valid = 0; | |
c860120c | 4166 | } |
3a5c3e22 | 4167 | } |
c5aa993b JM |
4168 | break; |
4169 | default: | |
c5aa993b JM |
4170 | break; |
4171 | } | |
4172 | } | |
1c5cfe86 PA |
4173 | |
4174 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4175 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4176 | decref_bp_location (&bl); | |
1c5cfe86 | 4177 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4178 | } |
4179 | ||
6c95b8df PA |
4180 | /* These functions concern about actual breakpoints inserted in the |
4181 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4182 | we need to hop over the bkpt --- so we check for address space | |
4183 | match, not program space. */ | |
4184 | ||
c2c6d25f JM |
4185 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4186 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4187 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4188 | permanent breakpoint. | |
4189 | - When continuing from a location with an ordinary breakpoint, we | |
4190 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4191 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4192 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4193 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4194 | |
c2c6d25f | 4195 | enum breakpoint_here |
6c95b8df | 4196 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4197 | { |
35df4500 | 4198 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4199 | int any_breakpoint_here = 0; |
c906108c | 4200 | |
35df4500 | 4201 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4202 | { |
35df4500 TJB |
4203 | if (bl->loc_type != bp_loc_software_breakpoint |
4204 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4205 | continue; |
4206 | ||
f1310107 | 4207 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4208 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4209 | || bl->permanent) |
f1310107 | 4210 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4211 | { |
4212 | if (overlay_debugging | |
35df4500 TJB |
4213 | && section_is_overlay (bl->section) |
4214 | && !section_is_mapped (bl->section)) | |
075f6582 | 4215 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4216 | else if (bl->permanent) |
075f6582 DJ |
4217 | return permanent_breakpoint_here; |
4218 | else | |
4219 | any_breakpoint_here = 1; | |
4220 | } | |
4221 | } | |
c906108c | 4222 | |
c2c6d25f | 4223 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4224 | } |
4225 | ||
1c5cfe86 PA |
4226 | /* Return true if there's a moribund breakpoint at PC. */ |
4227 | ||
4228 | int | |
6c95b8df | 4229 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4230 | { |
4231 | struct bp_location *loc; | |
4232 | int ix; | |
4233 | ||
4234 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4235 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4236 | return 1; |
4237 | ||
4238 | return 0; | |
4239 | } | |
c2c6d25f | 4240 | |
f7ce857f PA |
4241 | /* Returns non-zero iff BL is inserted at PC, in address space |
4242 | ASPACE. */ | |
4243 | ||
4244 | static int | |
4245 | bp_location_inserted_here_p (struct bp_location *bl, | |
4246 | struct address_space *aspace, CORE_ADDR pc) | |
4247 | { | |
4248 | if (bl->inserted | |
4249 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4250 | aspace, pc)) | |
4251 | { | |
4252 | if (overlay_debugging | |
4253 | && section_is_overlay (bl->section) | |
4254 | && !section_is_mapped (bl->section)) | |
4255 | return 0; /* unmapped overlay -- can't be a match */ | |
4256 | else | |
4257 | return 1; | |
4258 | } | |
4259 | return 0; | |
4260 | } | |
4261 | ||
a1fd2fa5 | 4262 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4263 | |
4264 | int | |
a1fd2fa5 | 4265 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4266 | { |
f7ce857f PA |
4267 | struct bp_location **blp, **blp_tmp = NULL; |
4268 | struct bp_location *bl; | |
c906108c | 4269 | |
f7ce857f | 4270 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4271 | { |
f7ce857f PA |
4272 | struct bp_location *bl = *blp; |
4273 | ||
35df4500 TJB |
4274 | if (bl->loc_type != bp_loc_software_breakpoint |
4275 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4276 | continue; |
4277 | ||
f7ce857f PA |
4278 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4279 | return 1; | |
c5aa993b | 4280 | } |
c36b740a VP |
4281 | return 0; |
4282 | } | |
4283 | ||
a1fd2fa5 PA |
4284 | /* This function returns non-zero iff there is a software breakpoint |
4285 | inserted at PC. */ | |
c36b740a VP |
4286 | |
4287 | int | |
a1fd2fa5 PA |
4288 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4289 | CORE_ADDR pc) | |
4fa8626c | 4290 | { |
f7ce857f PA |
4291 | struct bp_location **blp, **blp_tmp = NULL; |
4292 | struct bp_location *bl; | |
4fa8626c | 4293 | |
f7ce857f | 4294 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4295 | { |
f7ce857f PA |
4296 | struct bp_location *bl = *blp; |
4297 | ||
35df4500 | 4298 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4299 | continue; |
4300 | ||
f7ce857f PA |
4301 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4302 | return 1; | |
4fa8626c DJ |
4303 | } |
4304 | ||
4305 | return 0; | |
9c02b525 PA |
4306 | } |
4307 | ||
4308 | /* See breakpoint.h. */ | |
4309 | ||
4310 | int | |
4311 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4312 | CORE_ADDR pc) | |
4313 | { | |
4314 | struct bp_location **blp, **blp_tmp = NULL; | |
4315 | struct bp_location *bl; | |
4316 | ||
4317 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4318 | { | |
4319 | struct bp_location *bl = *blp; | |
4320 | ||
4321 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4322 | continue; | |
4323 | ||
4324 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4325 | return 1; | |
4326 | } | |
4327 | ||
4328 | return 0; | |
4fa8626c DJ |
4329 | } |
4330 | ||
9093389c PA |
4331 | int |
4332 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4333 | CORE_ADDR addr, ULONGEST len) | |
4334 | { | |
4335 | struct breakpoint *bpt; | |
4336 | ||
4337 | ALL_BREAKPOINTS (bpt) | |
4338 | { | |
4339 | struct bp_location *loc; | |
4340 | ||
4341 | if (bpt->type != bp_hardware_watchpoint | |
4342 | && bpt->type != bp_access_watchpoint) | |
4343 | continue; | |
4344 | ||
4345 | if (!breakpoint_enabled (bpt)) | |
4346 | continue; | |
4347 | ||
4348 | for (loc = bpt->loc; loc; loc = loc->next) | |
4349 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4350 | { | |
4351 | CORE_ADDR l, h; | |
4352 | ||
4353 | /* Check for intersection. */ | |
4354 | l = max (loc->address, addr); | |
4355 | h = min (loc->address + loc->length, addr + len); | |
4356 | if (l < h) | |
4357 | return 1; | |
4358 | } | |
4359 | } | |
4360 | return 0; | |
4361 | } | |
c906108c | 4362 | \f |
c5aa993b | 4363 | |
c906108c SS |
4364 | /* bpstat stuff. External routines' interfaces are documented |
4365 | in breakpoint.h. */ | |
4366 | ||
4367 | int | |
c326b90e | 4368 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4369 | { |
533be4dd | 4370 | return (ep->type == bp_catchpoint); |
c906108c SS |
4371 | } |
4372 | ||
f431efe5 PA |
4373 | /* Frees any storage that is part of a bpstat. Does not walk the |
4374 | 'next' chain. */ | |
4375 | ||
4376 | static void | |
198757a8 VP |
4377 | bpstat_free (bpstat bs) |
4378 | { | |
4379 | if (bs->old_val != NULL) | |
4380 | value_free (bs->old_val); | |
9add0f1b | 4381 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4382 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4383 | xfree (bs); |
4384 | } | |
4385 | ||
c906108c SS |
4386 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4387 | Also free any storage that is part of a bpstat. */ | |
4388 | ||
4389 | void | |
fba45db2 | 4390 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4391 | { |
4392 | bpstat p; | |
4393 | bpstat q; | |
4394 | ||
4395 | if (bsp == 0) | |
4396 | return; | |
4397 | p = *bsp; | |
4398 | while (p != NULL) | |
4399 | { | |
4400 | q = p->next; | |
198757a8 | 4401 | bpstat_free (p); |
c906108c SS |
4402 | p = q; |
4403 | } | |
4404 | *bsp = NULL; | |
4405 | } | |
4406 | ||
4407 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4408 | is part of the bpstat is copied as well. */ | |
4409 | ||
4410 | bpstat | |
fba45db2 | 4411 | bpstat_copy (bpstat bs) |
c906108c SS |
4412 | { |
4413 | bpstat p = NULL; | |
4414 | bpstat tmp; | |
4415 | bpstat retval = NULL; | |
4416 | ||
4417 | if (bs == NULL) | |
4418 | return bs; | |
4419 | ||
4420 | for (; bs != NULL; bs = bs->next) | |
4421 | { | |
4422 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4423 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4424 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4425 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4426 | if (bs->old_val != NULL) |
3c3185ac JK |
4427 | { |
4428 | tmp->old_val = value_copy (bs->old_val); | |
4429 | release_value (tmp->old_val); | |
4430 | } | |
31cc81e9 | 4431 | |
c906108c SS |
4432 | if (p == NULL) |
4433 | /* This is the first thing in the chain. */ | |
4434 | retval = tmp; | |
4435 | else | |
4436 | p->next = tmp; | |
4437 | p = tmp; | |
4438 | } | |
4439 | p->next = NULL; | |
4440 | return retval; | |
4441 | } | |
4442 | ||
4a64f543 | 4443 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4444 | |
4445 | bpstat | |
fba45db2 | 4446 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4447 | { |
c5aa993b JM |
4448 | if (bsp == NULL) |
4449 | return NULL; | |
c906108c | 4450 | |
c5aa993b JM |
4451 | for (; bsp != NULL; bsp = bsp->next) |
4452 | { | |
f431efe5 | 4453 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4454 | return bsp; |
4455 | } | |
c906108c SS |
4456 | return NULL; |
4457 | } | |
4458 | ||
ab04a2af TT |
4459 | /* See breakpoint.h. */ |
4460 | ||
47591c29 | 4461 | int |
427cd150 | 4462 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4463 | { |
ab04a2af TT |
4464 | for (; bsp != NULL; bsp = bsp->next) |
4465 | { | |
427cd150 TT |
4466 | if (bsp->breakpoint_at == NULL) |
4467 | { | |
4468 | /* A moribund location can never explain a signal other than | |
4469 | GDB_SIGNAL_TRAP. */ | |
4470 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4471 | return 1; |
427cd150 TT |
4472 | } |
4473 | else | |
47591c29 PA |
4474 | { |
4475 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4476 | sig)) | |
4477 | return 1; | |
4478 | } | |
ab04a2af TT |
4479 | } |
4480 | ||
47591c29 | 4481 | return 0; |
ab04a2af TT |
4482 | } |
4483 | ||
4a64f543 MS |
4484 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4485 | stopped at. *BSP upon return is a bpstat which points to the | |
4486 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4487 | good for anything but further calls to bpstat_num). | |
4488 | ||
8671a17b PA |
4489 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4490 | Return -1 if stopped at a breakpoint that has been deleted since | |
4491 | we set it. | |
4492 | Return 1 otherwise. */ | |
c906108c SS |
4493 | |
4494 | int | |
8671a17b | 4495 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4496 | { |
4497 | struct breakpoint *b; | |
4498 | ||
4499 | if ((*bsp) == NULL) | |
4500 | return 0; /* No more breakpoint values */ | |
8671a17b | 4501 | |
4a64f543 MS |
4502 | /* We assume we'll never have several bpstats that correspond to a |
4503 | single breakpoint -- otherwise, this function might return the | |
4504 | same number more than once and this will look ugly. */ | |
f431efe5 | 4505 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4506 | *bsp = (*bsp)->next; |
4507 | if (b == NULL) | |
4508 | return -1; /* breakpoint that's been deleted since */ | |
4509 | ||
4510 | *num = b->number; /* We have its number */ | |
4511 | return 1; | |
c906108c SS |
4512 | } |
4513 | ||
e93ca019 | 4514 | /* See breakpoint.h. */ |
c906108c SS |
4515 | |
4516 | void | |
e93ca019 | 4517 | bpstat_clear_actions (void) |
c906108c | 4518 | { |
e93ca019 JK |
4519 | struct thread_info *tp; |
4520 | bpstat bs; | |
4521 | ||
4522 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4523 | return; | |
4524 | ||
4525 | tp = find_thread_ptid (inferior_ptid); | |
4526 | if (tp == NULL) | |
4527 | return; | |
4528 | ||
4529 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4530 | { |
9add0f1b | 4531 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4532 | |
c906108c SS |
4533 | if (bs->old_val != NULL) |
4534 | { | |
4535 | value_free (bs->old_val); | |
4536 | bs->old_val = NULL; | |
4537 | } | |
4538 | } | |
4539 | } | |
4540 | ||
f3b1572e PA |
4541 | /* Called when a command is about to proceed the inferior. */ |
4542 | ||
4543 | static void | |
4544 | breakpoint_about_to_proceed (void) | |
4545 | { | |
4546 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4547 | { | |
4548 | struct thread_info *tp = inferior_thread (); | |
4549 | ||
4550 | /* Allow inferior function calls in breakpoint commands to not | |
4551 | interrupt the command list. When the call finishes | |
4552 | successfully, the inferior will be standing at the same | |
4553 | breakpoint as if nothing happened. */ | |
16c381f0 | 4554 | if (tp->control.in_infcall) |
f3b1572e PA |
4555 | return; |
4556 | } | |
4557 | ||
4558 | breakpoint_proceeded = 1; | |
4559 | } | |
4560 | ||
4a64f543 MS |
4561 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4562 | command. */ | |
c906108c | 4563 | static void |
4efb68b1 | 4564 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4565 | { |
4566 | executing_breakpoint_commands = 0; | |
4567 | } | |
4568 | ||
abf85f46 JK |
4569 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4570 | or its equivalent. */ | |
4571 | ||
4572 | static int | |
4573 | command_line_is_silent (struct command_line *cmd) | |
4574 | { | |
4f45d445 | 4575 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4576 | } |
4577 | ||
4a64f543 MS |
4578 | /* Execute all the commands associated with all the breakpoints at |
4579 | this location. Any of these commands could cause the process to | |
4580 | proceed beyond this point, etc. We look out for such changes by | |
4581 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4582 | |
347bddb7 PA |
4583 | Returns true if a breakpoint command resumed the inferior. In that |
4584 | case, it is the caller's responsibility to recall it again with the | |
4585 | bpstat of the current thread. */ | |
4586 | ||
4587 | static int | |
4588 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4589 | { |
4590 | bpstat bs; | |
4591 | struct cleanup *old_chain; | |
347bddb7 | 4592 | int again = 0; |
c906108c SS |
4593 | |
4594 | /* Avoid endless recursion if a `source' command is contained | |
4595 | in bs->commands. */ | |
4596 | if (executing_breakpoint_commands) | |
347bddb7 | 4597 | return 0; |
c906108c SS |
4598 | |
4599 | executing_breakpoint_commands = 1; | |
4600 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4601 | ||
cf6c5ffb TT |
4602 | prevent_dont_repeat (); |
4603 | ||
4a64f543 | 4604 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4605 | bs = *bsp; |
4606 | ||
4607 | breakpoint_proceeded = 0; | |
4608 | for (; bs != NULL; bs = bs->next) | |
4609 | { | |
9add0f1b | 4610 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4611 | struct command_line *cmd; |
4612 | struct cleanup *this_cmd_tree_chain; | |
4613 | ||
4614 | /* Take ownership of the BSP's command tree, if it has one. | |
4615 | ||
4616 | The command tree could legitimately contain commands like | |
4617 | 'step' and 'next', which call clear_proceed_status, which | |
4618 | frees stop_bpstat's command tree. To make sure this doesn't | |
4619 | free the tree we're executing out from under us, we need to | |
4620 | take ownership of the tree ourselves. Since a given bpstat's | |
4621 | commands are only executed once, we don't need to copy it; we | |
4622 | can clear the pointer in the bpstat, and make sure we free | |
4623 | the tree when we're done. */ | |
9add0f1b TT |
4624 | ccmd = bs->commands; |
4625 | bs->commands = NULL; | |
abf85f46 JK |
4626 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4627 | cmd = ccmd ? ccmd->commands : NULL; | |
4628 | if (command_line_is_silent (cmd)) | |
4629 | { | |
4630 | /* The action has been already done by bpstat_stop_status. */ | |
4631 | cmd = cmd->next; | |
4632 | } | |
6c50ab1c | 4633 | |
c906108c SS |
4634 | while (cmd != NULL) |
4635 | { | |
4636 | execute_control_command (cmd); | |
4637 | ||
4638 | if (breakpoint_proceeded) | |
4639 | break; | |
4640 | else | |
4641 | cmd = cmd->next; | |
4642 | } | |
6c50ab1c JB |
4643 | |
4644 | /* We can free this command tree now. */ | |
4645 | do_cleanups (this_cmd_tree_chain); | |
4646 | ||
c906108c | 4647 | if (breakpoint_proceeded) |
32c1e744 | 4648 | { |
5589af0e | 4649 | if (interpreter_async && target_can_async_p ()) |
347bddb7 PA |
4650 | /* If we are in async mode, then the target might be still |
4651 | running, not stopped at any breakpoint, so nothing for | |
4652 | us to do here -- just return to the event loop. */ | |
4653 | ; | |
32c1e744 VP |
4654 | else |
4655 | /* In sync mode, when execute_control_command returns | |
4656 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4657 | Breakpoint commands for that stop were not run, since |
4658 | execute_command does not run breakpoint commands -- | |
4659 | only command_line_handler does, but that one is not | |
4660 | involved in execution of breakpoint commands. So, we | |
4661 | can now execute breakpoint commands. It should be | |
4662 | noted that making execute_command do bpstat actions is | |
4663 | not an option -- in this case we'll have recursive | |
4664 | invocation of bpstat for each breakpoint with a | |
4665 | command, and can easily blow up GDB stack. Instead, we | |
4666 | return true, which will trigger the caller to recall us | |
4667 | with the new stop_bpstat. */ | |
4668 | again = 1; | |
4669 | break; | |
32c1e744 | 4670 | } |
c906108c | 4671 | } |
c2b8ed2c | 4672 | do_cleanups (old_chain); |
347bddb7 PA |
4673 | return again; |
4674 | } | |
4675 | ||
4676 | void | |
4677 | bpstat_do_actions (void) | |
4678 | { | |
353d1d73 JK |
4679 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4680 | ||
347bddb7 PA |
4681 | /* Do any commands attached to breakpoint we are stopped at. */ |
4682 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4683 | && target_has_execution | |
4684 | && !is_exited (inferior_ptid) | |
4685 | && !is_executing (inferior_ptid)) | |
4686 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4687 | and only return when it is stopped at the next breakpoint, we | |
4688 | keep doing breakpoint actions until it returns false to | |
4689 | indicate the inferior was not resumed. */ | |
16c381f0 | 4690 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4691 | break; |
353d1d73 JK |
4692 | |
4693 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4694 | } |
4695 | ||
fa4727a6 DJ |
4696 | /* Print out the (old or new) value associated with a watchpoint. */ |
4697 | ||
4698 | static void | |
4699 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4700 | { | |
4701 | if (val == NULL) | |
4702 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4703 | else | |
79a45b7d TT |
4704 | { |
4705 | struct value_print_options opts; | |
4706 | get_user_print_options (&opts); | |
4707 | value_print (val, stream, &opts); | |
4708 | } | |
fa4727a6 DJ |
4709 | } |
4710 | ||
e514a9d6 | 4711 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4712 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4713 | 'print_it' in the bpstat structure. Under some circumstances we |
4714 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4715 | normal_stop(). */ |
e514a9d6 JM |
4716 | |
4717 | static enum print_stop_action | |
4718 | print_bp_stop_message (bpstat bs) | |
4719 | { | |
4720 | switch (bs->print_it) | |
4721 | { | |
4722 | case print_it_noop: | |
4a64f543 | 4723 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4724 | return PRINT_UNKNOWN; |
4725 | break; | |
4726 | ||
4727 | case print_it_done: | |
4728 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4729 | relevant messages. */ |
e514a9d6 JM |
4730 | return PRINT_SRC_AND_LOC; |
4731 | break; | |
4732 | ||
4733 | case print_it_normal: | |
4f8d1dc6 | 4734 | { |
f431efe5 PA |
4735 | struct breakpoint *b = bs->breakpoint_at; |
4736 | ||
1a6a67de TJB |
4737 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4738 | which has since been deleted. */ | |
4739 | if (b == NULL) | |
4740 | return PRINT_UNKNOWN; | |
4741 | ||
348d480f PA |
4742 | /* Normal case. Call the breakpoint's print_it method. */ |
4743 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4744 | } |
348d480f | 4745 | break; |
3086aeae | 4746 | |
e514a9d6 | 4747 | default: |
8e65ff28 | 4748 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4749 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4750 | break; |
c906108c | 4751 | } |
c906108c SS |
4752 | } |
4753 | ||
edcc5120 TT |
4754 | /* A helper function that prints a shared library stopped event. */ |
4755 | ||
4756 | static void | |
4757 | print_solib_event (int is_catchpoint) | |
4758 | { | |
4759 | int any_deleted | |
4760 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4761 | int any_added | |
4762 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4763 | ||
4764 | if (!is_catchpoint) | |
4765 | { | |
4766 | if (any_added || any_deleted) | |
4767 | ui_out_text (current_uiout, | |
4768 | _("Stopped due to shared library event:\n")); | |
4769 | else | |
4770 | ui_out_text (current_uiout, | |
4771 | _("Stopped due to shared library event (no " | |
4772 | "libraries added or removed)\n")); | |
4773 | } | |
4774 | ||
4775 | if (ui_out_is_mi_like_p (current_uiout)) | |
4776 | ui_out_field_string (current_uiout, "reason", | |
4777 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4778 | ||
4779 | if (any_deleted) | |
4780 | { | |
4781 | struct cleanup *cleanup; | |
4782 | char *name; | |
4783 | int ix; | |
4784 | ||
4785 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4786 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4787 | "removed"); | |
4788 | for (ix = 0; | |
4789 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4790 | ix, name); | |
4791 | ++ix) | |
4792 | { | |
4793 | if (ix > 0) | |
4794 | ui_out_text (current_uiout, " "); | |
4795 | ui_out_field_string (current_uiout, "library", name); | |
4796 | ui_out_text (current_uiout, "\n"); | |
4797 | } | |
4798 | ||
4799 | do_cleanups (cleanup); | |
4800 | } | |
4801 | ||
4802 | if (any_added) | |
4803 | { | |
4804 | struct so_list *iter; | |
4805 | int ix; | |
4806 | struct cleanup *cleanup; | |
4807 | ||
4808 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4809 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4810 | "added"); | |
4811 | for (ix = 0; | |
4812 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4813 | ix, iter); | |
4814 | ++ix) | |
4815 | { | |
4816 | if (ix > 0) | |
4817 | ui_out_text (current_uiout, " "); | |
4818 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4819 | ui_out_text (current_uiout, "\n"); | |
4820 | } | |
4821 | ||
4822 | do_cleanups (cleanup); | |
4823 | } | |
4824 | } | |
4825 | ||
e514a9d6 JM |
4826 | /* Print a message indicating what happened. This is called from |
4827 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4828 | list - a list of the eventpoints that caused this stop. KIND is |
4829 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4830 | routine calls the generic print routine for printing a message |
4831 | about reasons for stopping. This will print (for example) the | |
4832 | "Breakpoint n," part of the output. The return value of this | |
4833 | routine is one of: | |
c906108c | 4834 | |
4a64f543 | 4835 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4836 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4837 | code to print the location. An example is |
c5aa993b JM |
4838 | "Breakpoint 1, " which should be followed by |
4839 | the location. | |
917317f4 | 4840 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4841 | to also print the location part of the message. |
4842 | An example is the catch/throw messages, which | |
4a64f543 | 4843 | don't require a location appended to the end. |
917317f4 | 4844 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4845 | further info to be printed. */ |
c906108c | 4846 | |
917317f4 | 4847 | enum print_stop_action |
36dfb11c | 4848 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4849 | { |
4850 | int val; | |
c5aa993b | 4851 | |
c906108c | 4852 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4853 | (Currently all watchpoints go on the bpstat whether hit or not. |
4854 | That probably could (should) be changed, provided care is taken | |
c906108c | 4855 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4856 | for (; bs; bs = bs->next) |
4857 | { | |
4858 | val = print_bp_stop_message (bs); | |
4859 | if (val == PRINT_SRC_ONLY | |
4860 | || val == PRINT_SRC_AND_LOC | |
4861 | || val == PRINT_NOTHING) | |
4862 | return val; | |
4863 | } | |
c906108c | 4864 | |
36dfb11c TT |
4865 | /* If we had hit a shared library event breakpoint, |
4866 | print_bp_stop_message would print out this message. If we hit an | |
4867 | OS-level shared library event, do the same thing. */ | |
4868 | if (kind == TARGET_WAITKIND_LOADED) | |
4869 | { | |
edcc5120 | 4870 | print_solib_event (0); |
36dfb11c TT |
4871 | return PRINT_NOTHING; |
4872 | } | |
4873 | ||
e514a9d6 | 4874 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4875 | with and nothing was printed. */ |
917317f4 | 4876 | return PRINT_UNKNOWN; |
c906108c SS |
4877 | } |
4878 | ||
c42bd95a DE |
4879 | /* Evaluate the expression EXP and return 1 if value is zero. |
4880 | This returns the inverse of the condition because it is called | |
4881 | from catch_errors which returns 0 if an exception happened, and if an | |
4882 | exception happens we want execution to stop. | |
4a64f543 | 4883 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4884 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4885 | |
4886 | static int | |
4efb68b1 | 4887 | breakpoint_cond_eval (void *exp) |
c906108c | 4888 | { |
278cd55f | 4889 | struct value *mark = value_mark (); |
c5aa993b | 4890 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4891 | |
c906108c SS |
4892 | value_free_to_mark (mark); |
4893 | return i; | |
4894 | } | |
4895 | ||
5760d0ab | 4896 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4897 | |
4898 | static bpstat | |
5760d0ab | 4899 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4900 | { |
4901 | bpstat bs; | |
4902 | ||
4903 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4904 | bs->next = NULL; |
4905 | **bs_link_pointer = bs; | |
4906 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4907 | bs->breakpoint_at = bl->owner; |
4908 | bs->bp_location_at = bl; | |
4909 | incref_bp_location (bl); | |
c906108c SS |
4910 | /* If the condition is false, etc., don't do the commands. */ |
4911 | bs->commands = NULL; | |
4912 | bs->old_val = NULL; | |
4913 | bs->print_it = print_it_normal; | |
4914 | return bs; | |
4915 | } | |
4916 | \f | |
d983da9c DJ |
4917 | /* The target has stopped with waitstatus WS. Check if any hardware |
4918 | watchpoints have triggered, according to the target. */ | |
4919 | ||
4920 | int | |
4921 | watchpoints_triggered (struct target_waitstatus *ws) | |
4922 | { | |
d92524f1 | 4923 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4924 | CORE_ADDR addr; |
4925 | struct breakpoint *b; | |
4926 | ||
4927 | if (!stopped_by_watchpoint) | |
4928 | { | |
4929 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4930 | as not triggered. */ | |
4931 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4932 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4933 | { |
4934 | struct watchpoint *w = (struct watchpoint *) b; | |
4935 | ||
4936 | w->watchpoint_triggered = watch_triggered_no; | |
4937 | } | |
d983da9c DJ |
4938 | |
4939 | return 0; | |
4940 | } | |
4941 | ||
4942 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4943 | { | |
4944 | /* We were stopped by a watchpoint, but we don't know where. | |
4945 | Mark all watchpoints as unknown. */ | |
4946 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4947 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4948 | { |
4949 | struct watchpoint *w = (struct watchpoint *) b; | |
4950 | ||
4951 | w->watchpoint_triggered = watch_triggered_unknown; | |
4952 | } | |
d983da9c | 4953 | |
3c4797ba | 4954 | return 1; |
d983da9c DJ |
4955 | } |
4956 | ||
4957 | /* The target could report the data address. Mark watchpoints | |
4958 | affected by this data address as triggered, and all others as not | |
4959 | triggered. */ | |
4960 | ||
4961 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4962 | if (is_hardware_watchpoint (b)) |
d983da9c | 4963 | { |
3a5c3e22 | 4964 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4965 | struct bp_location *loc; |
d983da9c | 4966 | |
3a5c3e22 | 4967 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4968 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4969 | { |
3a5c3e22 | 4970 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4971 | { |
3a5c3e22 PA |
4972 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4973 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4974 | |
4975 | if (newaddr == start) | |
4976 | { | |
3a5c3e22 | 4977 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4978 | break; |
4979 | } | |
4980 | } | |
4981 | /* Exact match not required. Within range is sufficient. */ | |
4982 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4983 | addr, loc->address, | |
4984 | loc->length)) | |
4985 | { | |
3a5c3e22 | 4986 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4987 | break; |
4988 | } | |
4989 | } | |
d983da9c DJ |
4990 | } |
4991 | ||
4992 | return 1; | |
4993 | } | |
4994 | ||
c906108c SS |
4995 | /* Possible return values for watchpoint_check (this can't be an enum |
4996 | because of check_errors). */ | |
4997 | /* The watchpoint has been deleted. */ | |
4998 | #define WP_DELETED 1 | |
4999 | /* The value has changed. */ | |
5000 | #define WP_VALUE_CHANGED 2 | |
5001 | /* The value has not changed. */ | |
5002 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5003 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5004 | #define WP_IGNORE 4 | |
c906108c SS |
5005 | |
5006 | #define BP_TEMPFLAG 1 | |
5007 | #define BP_HARDWAREFLAG 2 | |
5008 | ||
4a64f543 MS |
5009 | /* Evaluate watchpoint condition expression and check if its value |
5010 | changed. | |
553e4c11 JB |
5011 | |
5012 | P should be a pointer to struct bpstat, but is defined as a void * | |
5013 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5014 | |
5015 | static int | |
4efb68b1 | 5016 | watchpoint_check (void *p) |
c906108c SS |
5017 | { |
5018 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5019 | struct watchpoint *b; |
c906108c SS |
5020 | struct frame_info *fr; |
5021 | int within_current_scope; | |
5022 | ||
f431efe5 | 5023 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5024 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5025 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5026 | |
f6bc2008 PA |
5027 | /* If this is a local watchpoint, we only want to check if the |
5028 | watchpoint frame is in scope if the current thread is the thread | |
5029 | that was used to create the watchpoint. */ | |
5030 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5031 | return WP_IGNORE; |
f6bc2008 | 5032 | |
c906108c SS |
5033 | if (b->exp_valid_block == NULL) |
5034 | within_current_scope = 1; | |
5035 | else | |
5036 | { | |
edb3359d DJ |
5037 | struct frame_info *frame = get_current_frame (); |
5038 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5039 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5040 | ||
c9cf6e20 | 5041 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5042 | still in the function but the stack frame has already been |
5043 | invalidated. Since we can't rely on the values of local | |
5044 | variables after the stack has been destroyed, we are treating | |
5045 | the watchpoint in that state as `not changed' without further | |
5046 | checking. Don't mark watchpoints as changed if the current | |
5047 | frame is in an epilogue - even if they are in some other | |
5048 | frame, our view of the stack is likely to be wrong and | |
5049 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5050 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5051 | return WP_IGNORE; |
a0f49112 | 5052 | |
101dcfbe | 5053 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5054 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5055 | |
5056 | /* If we've gotten confused in the unwinder, we might have | |
5057 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5058 | if (within_current_scope) |
5059 | { | |
5060 | struct symbol *function; | |
5061 | ||
5062 | function = get_frame_function (fr); | |
5063 | if (function == NULL | |
5064 | || !contained_in (b->exp_valid_block, | |
5065 | SYMBOL_BLOCK_VALUE (function))) | |
5066 | within_current_scope = 0; | |
5067 | } | |
69fbadd5 | 5068 | |
edb3359d | 5069 | if (within_current_scope) |
c906108c SS |
5070 | /* If we end up stopping, the current frame will get selected |
5071 | in normal_stop. So this call to select_frame won't affect | |
5072 | the user. */ | |
0f7d239c | 5073 | select_frame (fr); |
c906108c | 5074 | } |
c5aa993b | 5075 | |
c906108c SS |
5076 | if (within_current_scope) |
5077 | { | |
4a64f543 MS |
5078 | /* We use value_{,free_to_}mark because it could be a *long* |
5079 | time before we return to the command level and call | |
5080 | free_all_values. We can't call free_all_values because we | |
5081 | might be in the middle of evaluating a function call. */ | |
c906108c | 5082 | |
0cf6dd15 | 5083 | int pc = 0; |
9c06b0b4 | 5084 | struct value *mark; |
fa4727a6 DJ |
5085 | struct value *new_val; |
5086 | ||
3a5c3e22 | 5087 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5088 | /* Since we don't know the exact trigger address (from |
5089 | stopped_data_address), just tell the user we've triggered | |
5090 | a mask watchpoint. */ | |
5091 | return WP_VALUE_CHANGED; | |
5092 | ||
5093 | mark = value_mark (); | |
3a1115a0 | 5094 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5095 | |
bb9d5f81 PP |
5096 | if (b->val_bitsize != 0) |
5097 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5098 | ||
4a64f543 MS |
5099 | /* We use value_equal_contents instead of value_equal because |
5100 | the latter coerces an array to a pointer, thus comparing just | |
5101 | the address of the array instead of its contents. This is | |
5102 | not what we want. */ | |
fa4727a6 | 5103 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5104 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5105 | { |
fa4727a6 DJ |
5106 | if (new_val != NULL) |
5107 | { | |
5108 | release_value (new_val); | |
5109 | value_free_to_mark (mark); | |
5110 | } | |
c906108c SS |
5111 | bs->old_val = b->val; |
5112 | b->val = new_val; | |
fa4727a6 | 5113 | b->val_valid = 1; |
c906108c SS |
5114 | return WP_VALUE_CHANGED; |
5115 | } | |
5116 | else | |
5117 | { | |
60e1c644 | 5118 | /* Nothing changed. */ |
c906108c | 5119 | value_free_to_mark (mark); |
c906108c SS |
5120 | return WP_VALUE_NOT_CHANGED; |
5121 | } | |
5122 | } | |
5123 | else | |
5124 | { | |
79a45e25 PA |
5125 | struct ui_out *uiout = current_uiout; |
5126 | ||
c906108c | 5127 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5128 | if we temporarily ignored the watchpoint, then when |
5129 | we reenter the block in which it is valid it contains | |
5130 | garbage (in the case of a function, it may have two | |
5131 | garbage values, one before and one after the prologue). | |
5132 | So we can't even detect the first assignment to it and | |
5133 | watch after that (since the garbage may or may not equal | |
5134 | the first value assigned). */ | |
348d480f PA |
5135 | /* We print all the stop information in |
5136 | breakpoint_ops->print_it, but in this case, by the time we | |
5137 | call breakpoint_ops->print_it this bp will be deleted | |
5138 | already. So we have no choice but print the information | |
5139 | here. */ | |
9dc5e2a9 | 5140 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5141 | ui_out_field_string |
5142 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5143 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5144 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5145 | ui_out_text (uiout, |
5146 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5147 | which its expression is valid.\n"); |
4ce44c66 | 5148 | |
cdac0397 | 5149 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5150 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5151 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5152 | |
5153 | return WP_DELETED; | |
5154 | } | |
5155 | } | |
5156 | ||
18a18393 | 5157 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5158 | breakpoint location BL. This function does not check if we should |
5159 | stop, only if BL explains the stop. */ | |
5160 | ||
18a18393 | 5161 | static int |
6c95b8df | 5162 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5163 | struct address_space *aspace, CORE_ADDR bp_addr, |
5164 | const struct target_waitstatus *ws) | |
18a18393 VP |
5165 | { |
5166 | struct breakpoint *b = bl->owner; | |
5167 | ||
348d480f | 5168 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5169 | gdb_assert (b != NULL); |
5170 | ||
09ac7c10 | 5171 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5172 | } |
5173 | ||
3a5c3e22 PA |
5174 | /* Determine if the watched values have actually changed, and we |
5175 | should stop. If not, set BS->stop to 0. */ | |
5176 | ||
18a18393 VP |
5177 | static void |
5178 | bpstat_check_watchpoint (bpstat bs) | |
5179 | { | |
2bdf28a0 | 5180 | const struct bp_location *bl; |
3a5c3e22 | 5181 | struct watchpoint *b; |
2bdf28a0 JK |
5182 | |
5183 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5184 | bl = bs->bp_location_at; |
2bdf28a0 | 5185 | gdb_assert (bl != NULL); |
3a5c3e22 | 5186 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5187 | gdb_assert (b != NULL); |
18a18393 | 5188 | |
18a18393 | 5189 | { |
18a18393 VP |
5190 | int must_check_value = 0; |
5191 | ||
3a5c3e22 | 5192 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5193 | /* For a software watchpoint, we must always check the |
5194 | watched value. */ | |
5195 | must_check_value = 1; | |
5196 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5197 | /* We have a hardware watchpoint (read, write, or access) | |
5198 | and the target earlier reported an address watched by | |
5199 | this watchpoint. */ | |
5200 | must_check_value = 1; | |
5201 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5202 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5203 | /* We were stopped by a hardware watchpoint, but the target could |
5204 | not report the data address. We must check the watchpoint's | |
5205 | value. Access and read watchpoints are out of luck; without | |
5206 | a data address, we can't figure it out. */ | |
5207 | must_check_value = 1; | |
3a5c3e22 | 5208 | |
18a18393 VP |
5209 | if (must_check_value) |
5210 | { | |
3e43a32a MS |
5211 | char *message |
5212 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5213 | b->base.number); |
18a18393 VP |
5214 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5215 | int e = catch_errors (watchpoint_check, bs, message, | |
5216 | RETURN_MASK_ALL); | |
5217 | do_cleanups (cleanups); | |
5218 | switch (e) | |
5219 | { | |
5220 | case WP_DELETED: | |
5221 | /* We've already printed what needs to be printed. */ | |
5222 | bs->print_it = print_it_done; | |
5223 | /* Stop. */ | |
5224 | break; | |
60e1c644 PA |
5225 | case WP_IGNORE: |
5226 | bs->print_it = print_it_noop; | |
5227 | bs->stop = 0; | |
5228 | break; | |
18a18393 | 5229 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5230 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5231 | { |
85d721b8 PA |
5232 | /* There are two cases to consider here: |
5233 | ||
4a64f543 | 5234 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5235 | In that case, trust the target, and always report |
5236 | the watchpoint hit to the user. Even though | |
5237 | reads don't cause value changes, the value may | |
5238 | have changed since the last time it was read, and | |
5239 | since we're not trapping writes, we will not see | |
5240 | those, and as such we should ignore our notion of | |
5241 | old value. | |
5242 | ||
4a64f543 | 5243 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5244 | reads and writes. There are two ways this may |
5245 | happen: | |
5246 | ||
4a64f543 | 5247 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5248 | reads only, but can break on accesses (reads or |
5249 | writes), such as e.g., x86. We detect this case | |
5250 | at the time we try to insert read watchpoints. | |
5251 | ||
4a64f543 | 5252 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5253 | watchpoints, but, the user set an access or write |
5254 | watchpoint watching the same memory as this read | |
5255 | watchpoint. | |
5256 | ||
5257 | If we're watching memory writes as well as reads, | |
5258 | ignore watchpoint hits when we find that the | |
5259 | value hasn't changed, as reads don't cause | |
5260 | changes. This still gives false positives when | |
5261 | the program writes the same value to memory as | |
5262 | what there was already in memory (we will confuse | |
5263 | it for a read), but it's much better than | |
5264 | nothing. */ | |
5265 | ||
5266 | int other_write_watchpoint = 0; | |
5267 | ||
5268 | if (bl->watchpoint_type == hw_read) | |
5269 | { | |
5270 | struct breakpoint *other_b; | |
5271 | ||
5272 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5273 | if (other_b->type == bp_hardware_watchpoint |
5274 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5275 | { |
3a5c3e22 PA |
5276 | struct watchpoint *other_w = |
5277 | (struct watchpoint *) other_b; | |
5278 | ||
5279 | if (other_w->watchpoint_triggered | |
5280 | == watch_triggered_yes) | |
5281 | { | |
5282 | other_write_watchpoint = 1; | |
5283 | break; | |
5284 | } | |
85d721b8 PA |
5285 | } |
5286 | } | |
5287 | ||
5288 | if (other_write_watchpoint | |
5289 | || bl->watchpoint_type == hw_access) | |
5290 | { | |
5291 | /* We're watching the same memory for writes, | |
5292 | and the value changed since the last time we | |
5293 | updated it, so this trap must be for a write. | |
5294 | Ignore it. */ | |
5295 | bs->print_it = print_it_noop; | |
5296 | bs->stop = 0; | |
5297 | } | |
18a18393 VP |
5298 | } |
5299 | break; | |
5300 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5301 | if (b->base.type == bp_hardware_watchpoint |
5302 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5303 | { |
5304 | /* Don't stop: write watchpoints shouldn't fire if | |
5305 | the value hasn't changed. */ | |
5306 | bs->print_it = print_it_noop; | |
5307 | bs->stop = 0; | |
5308 | } | |
5309 | /* Stop. */ | |
5310 | break; | |
5311 | default: | |
5312 | /* Can't happen. */ | |
5313 | case 0: | |
5314 | /* Error from catch_errors. */ | |
3a5c3e22 | 5315 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5316 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5317 | /* We've already printed what needs to be printed. */ |
5318 | bs->print_it = print_it_done; | |
5319 | break; | |
5320 | } | |
5321 | } | |
5322 | else /* must_check_value == 0 */ | |
5323 | { | |
5324 | /* This is a case where some watchpoint(s) triggered, but | |
5325 | not at the address of this watchpoint, or else no | |
5326 | watchpoint triggered after all. So don't print | |
5327 | anything for this watchpoint. */ | |
5328 | bs->print_it = print_it_noop; | |
5329 | bs->stop = 0; | |
5330 | } | |
5331 | } | |
5332 | } | |
5333 | ||
7d4df6a4 DE |
5334 | /* For breakpoints that are currently marked as telling gdb to stop, |
5335 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5336 | of breakpoint referred to by BS. If we should not stop for this |
5337 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5338 | |
18a18393 VP |
5339 | static void |
5340 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5341 | { | |
2bdf28a0 JK |
5342 | const struct bp_location *bl; |
5343 | struct breakpoint *b; | |
7d4df6a4 DE |
5344 | int value_is_zero = 0; |
5345 | struct expression *cond; | |
5346 | ||
5347 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5348 | |
5349 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5350 | bl = bs->bp_location_at; |
2bdf28a0 | 5351 | gdb_assert (bl != NULL); |
f431efe5 | 5352 | b = bs->breakpoint_at; |
2bdf28a0 | 5353 | gdb_assert (b != NULL); |
18a18393 | 5354 | |
b775012e LM |
5355 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5356 | need to do so again since GDB does not know if we stopped due to a | |
5357 | breakpoint or a single step breakpoint. */ | |
5358 | ||
18a18393 | 5359 | if (frame_id_p (b->frame_id) |
edb3359d | 5360 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5361 | { |
7d4df6a4 DE |
5362 | bs->stop = 0; |
5363 | return; | |
5364 | } | |
60e1c644 | 5365 | |
12ab52e9 PA |
5366 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5367 | evaluating the condition if this isn't the specified | |
5368 | thread/task. */ | |
5369 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5370 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5371 | ||
6c1b0f7b DE |
5372 | { |
5373 | bs->stop = 0; | |
5374 | return; | |
5375 | } | |
5376 | ||
6dddc817 DE |
5377 | /* Evaluate extension language breakpoints that have a "stop" method |
5378 | implemented. */ | |
5379 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5380 | |
7d4df6a4 DE |
5381 | if (is_watchpoint (b)) |
5382 | { | |
5383 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5384 | |
7d4df6a4 DE |
5385 | cond = w->cond_exp; |
5386 | } | |
5387 | else | |
5388 | cond = bl->cond; | |
60e1c644 | 5389 | |
7d4df6a4 DE |
5390 | if (cond && b->disposition != disp_del_at_next_stop) |
5391 | { | |
5392 | int within_current_scope = 1; | |
5393 | struct watchpoint * w; | |
60e1c644 | 5394 | |
7d4df6a4 DE |
5395 | /* We use value_mark and value_free_to_mark because it could |
5396 | be a long time before we return to the command level and | |
5397 | call free_all_values. We can't call free_all_values | |
5398 | because we might be in the middle of evaluating a | |
5399 | function call. */ | |
5400 | struct value *mark = value_mark (); | |
5401 | ||
5402 | if (is_watchpoint (b)) | |
5403 | w = (struct watchpoint *) b; | |
5404 | else | |
5405 | w = NULL; | |
5406 | ||
5407 | /* Need to select the frame, with all that implies so that | |
5408 | the conditions will have the right context. Because we | |
5409 | use the frame, we will not see an inlined function's | |
5410 | variables when we arrive at a breakpoint at the start | |
5411 | of the inlined function; the current frame will be the | |
5412 | call site. */ | |
5413 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5414 | select_frame (get_current_frame ()); | |
5415 | else | |
18a18393 | 5416 | { |
7d4df6a4 DE |
5417 | struct frame_info *frame; |
5418 | ||
5419 | /* For local watchpoint expressions, which particular | |
5420 | instance of a local is being watched matters, so we | |
5421 | keep track of the frame to evaluate the expression | |
5422 | in. To evaluate the condition however, it doesn't | |
5423 | really matter which instantiation of the function | |
5424 | where the condition makes sense triggers the | |
5425 | watchpoint. This allows an expression like "watch | |
5426 | global if q > 10" set in `func', catch writes to | |
5427 | global on all threads that call `func', or catch | |
5428 | writes on all recursive calls of `func' by a single | |
5429 | thread. We simply always evaluate the condition in | |
5430 | the innermost frame that's executing where it makes | |
5431 | sense to evaluate the condition. It seems | |
5432 | intuitive. */ | |
5433 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5434 | if (frame != NULL) | |
5435 | select_frame (frame); | |
5436 | else | |
5437 | within_current_scope = 0; | |
18a18393 | 5438 | } |
7d4df6a4 DE |
5439 | if (within_current_scope) |
5440 | value_is_zero | |
5441 | = catch_errors (breakpoint_cond_eval, cond, | |
5442 | "Error in testing breakpoint condition:\n", | |
5443 | RETURN_MASK_ALL); | |
5444 | else | |
18a18393 | 5445 | { |
7d4df6a4 DE |
5446 | warning (_("Watchpoint condition cannot be tested " |
5447 | "in the current scope")); | |
5448 | /* If we failed to set the right context for this | |
5449 | watchpoint, unconditionally report it. */ | |
5450 | value_is_zero = 0; | |
18a18393 | 5451 | } |
7d4df6a4 DE |
5452 | /* FIXME-someday, should give breakpoint #. */ |
5453 | value_free_to_mark (mark); | |
18a18393 | 5454 | } |
7d4df6a4 DE |
5455 | |
5456 | if (cond && value_is_zero) | |
5457 | { | |
5458 | bs->stop = 0; | |
5459 | } | |
7d4df6a4 DE |
5460 | else if (b->ignore_count > 0) |
5461 | { | |
5462 | b->ignore_count--; | |
5463 | bs->stop = 0; | |
5464 | /* Increase the hit count even though we don't stop. */ | |
5465 | ++(b->hit_count); | |
5466 | observer_notify_breakpoint_modified (b); | |
5467 | } | |
18a18393 VP |
5468 | } |
5469 | ||
1cf4d951 PA |
5470 | /* Returns true if we need to track moribund locations of LOC's type |
5471 | on the current target. */ | |
5472 | ||
5473 | static int | |
5474 | need_moribund_for_location_type (struct bp_location *loc) | |
5475 | { | |
5476 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5477 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5478 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5479 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5480 | } | |
5481 | ||
18a18393 | 5482 | |
9709f61c | 5483 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5484 | BP_ADDR in thread PTID. |
c906108c | 5485 | |
d983da9c | 5486 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5487 | don't understand this stop. Result is a chain of bpstat's such |
5488 | that: | |
c906108c | 5489 | |
c5aa993b | 5490 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5491 | |
c5aa993b | 5492 | if we understand why we stopped, the result is not null. |
c906108c | 5493 | |
c5aa993b JM |
5494 | Each element of the chain refers to a particular breakpoint or |
5495 | watchpoint at which we have stopped. (We may have stopped for | |
5496 | several reasons concurrently.) | |
c906108c | 5497 | |
c5aa993b JM |
5498 | Each element of the chain has valid next, breakpoint_at, |
5499 | commands, FIXME??? fields. */ | |
c906108c SS |
5500 | |
5501 | bpstat | |
6c95b8df | 5502 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5503 | CORE_ADDR bp_addr, ptid_t ptid, |
5504 | const struct target_waitstatus *ws) | |
c906108c | 5505 | { |
0d381245 | 5506 | struct breakpoint *b = NULL; |
afe38095 | 5507 | struct bp_location *bl; |
20874c92 | 5508 | struct bp_location *loc; |
5760d0ab JK |
5509 | /* First item of allocated bpstat's. */ |
5510 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5511 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5512 | bpstat bs; |
20874c92 | 5513 | int ix; |
429374b8 | 5514 | int need_remove_insert; |
f431efe5 | 5515 | int removed_any; |
c906108c | 5516 | |
f431efe5 PA |
5517 | /* First, build the bpstat chain with locations that explain a |
5518 | target stop, while being careful to not set the target running, | |
5519 | as that may invalidate locations (in particular watchpoint | |
5520 | locations are recreated). Resuming will happen here with | |
5521 | breakpoint conditions or watchpoint expressions that include | |
5522 | inferior function calls. */ | |
c5aa993b | 5523 | |
429374b8 JK |
5524 | ALL_BREAKPOINTS (b) |
5525 | { | |
1a853c52 | 5526 | if (!breakpoint_enabled (b)) |
429374b8 | 5527 | continue; |
a5606eee | 5528 | |
429374b8 JK |
5529 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5530 | { | |
4a64f543 MS |
5531 | /* For hardware watchpoints, we look only at the first |
5532 | location. The watchpoint_check function will work on the | |
5533 | entire expression, not the individual locations. For | |
5534 | read watchpoints, the watchpoints_triggered function has | |
5535 | checked all locations already. */ | |
429374b8 JK |
5536 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5537 | break; | |
18a18393 | 5538 | |
f6592439 | 5539 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5540 | continue; |
c5aa993b | 5541 | |
09ac7c10 | 5542 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5543 | continue; |
c5aa993b | 5544 | |
4a64f543 MS |
5545 | /* Come here if it's a watchpoint, or if the break address |
5546 | matches. */ | |
c5aa993b | 5547 | |
4a64f543 MS |
5548 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5549 | explain stop. */ | |
c5aa993b | 5550 | |
f431efe5 PA |
5551 | /* Assume we stop. Should we find a watchpoint that is not |
5552 | actually triggered, or if the condition of the breakpoint | |
5553 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5554 | bs->stop = 1; |
5555 | bs->print = 1; | |
d983da9c | 5556 | |
f431efe5 PA |
5557 | /* If this is a scope breakpoint, mark the associated |
5558 | watchpoint as triggered so that we will handle the | |
5559 | out-of-scope event. We'll get to the watchpoint next | |
5560 | iteration. */ | |
d0fb5eae | 5561 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5562 | { |
5563 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5564 | ||
5565 | w->watchpoint_triggered = watch_triggered_yes; | |
5566 | } | |
f431efe5 PA |
5567 | } |
5568 | } | |
5569 | ||
7c16b83e | 5570 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5571 | if (!target_supports_stopped_by_sw_breakpoint () |
5572 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5573 | { |
1cf4d951 | 5574 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5575 | { |
1cf4d951 PA |
5576 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5577 | && need_moribund_for_location_type (loc)) | |
5578 | { | |
5579 | bs = bpstat_alloc (loc, &bs_link); | |
5580 | /* For hits of moribund locations, we should just proceed. */ | |
5581 | bs->stop = 0; | |
5582 | bs->print = 0; | |
5583 | bs->print_it = print_it_noop; | |
5584 | } | |
f431efe5 PA |
5585 | } |
5586 | } | |
5587 | ||
edcc5120 TT |
5588 | /* A bit of special processing for shlib breakpoints. We need to |
5589 | process solib loading here, so that the lists of loaded and | |
5590 | unloaded libraries are correct before we handle "catch load" and | |
5591 | "catch unload". */ | |
5592 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5593 | { | |
5d268276 | 5594 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5595 | { |
5596 | handle_solib_event (); | |
5597 | break; | |
5598 | } | |
5599 | } | |
5600 | ||
f431efe5 PA |
5601 | /* Now go through the locations that caused the target to stop, and |
5602 | check whether we're interested in reporting this stop to higher | |
5603 | layers, or whether we should resume the target transparently. */ | |
5604 | ||
5605 | removed_any = 0; | |
5606 | ||
5760d0ab | 5607 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5608 | { |
5609 | if (!bs->stop) | |
5610 | continue; | |
5611 | ||
f431efe5 | 5612 | b = bs->breakpoint_at; |
348d480f PA |
5613 | b->ops->check_status (bs); |
5614 | if (bs->stop) | |
28010a5d | 5615 | { |
348d480f | 5616 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5617 | |
429374b8 JK |
5618 | if (bs->stop) |
5619 | { | |
5620 | ++(b->hit_count); | |
8d3788bd | 5621 | observer_notify_breakpoint_modified (b); |
c906108c | 5622 | |
4a64f543 | 5623 | /* We will stop here. */ |
429374b8 JK |
5624 | if (b->disposition == disp_disable) |
5625 | { | |
816338b5 | 5626 | --(b->enable_count); |
1a853c52 | 5627 | if (b->enable_count <= 0) |
429374b8 | 5628 | b->enable_state = bp_disabled; |
f431efe5 | 5629 | removed_any = 1; |
429374b8 JK |
5630 | } |
5631 | if (b->silent) | |
5632 | bs->print = 0; | |
5633 | bs->commands = b->commands; | |
9add0f1b | 5634 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5635 | if (command_line_is_silent (bs->commands |
5636 | ? bs->commands->commands : NULL)) | |
5637 | bs->print = 0; | |
9d6e6e84 HZ |
5638 | |
5639 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5640 | } |
5641 | ||
348d480f | 5642 | } |
a9b3a50f PA |
5643 | |
5644 | /* Print nothing for this entry if we don't stop or don't | |
5645 | print. */ | |
5646 | if (!bs->stop || !bs->print) | |
5647 | bs->print_it = print_it_noop; | |
429374b8 | 5648 | } |
876fa593 | 5649 | |
d983da9c DJ |
5650 | /* If we aren't stopping, the value of some hardware watchpoint may |
5651 | not have changed, but the intermediate memory locations we are | |
5652 | watching may have. Don't bother if we're stopping; this will get | |
5653 | done later. */ | |
d832cb68 | 5654 | need_remove_insert = 0; |
5760d0ab JK |
5655 | if (! bpstat_causes_stop (bs_head)) |
5656 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5657 | if (!bs->stop |
f431efe5 PA |
5658 | && bs->breakpoint_at |
5659 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5660 | { |
3a5c3e22 PA |
5661 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5662 | ||
5663 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5664 | need_remove_insert = 1; |
d983da9c DJ |
5665 | } |
5666 | ||
d832cb68 | 5667 | if (need_remove_insert) |
44702360 | 5668 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5669 | else if (removed_any) |
44702360 | 5670 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5671 | |
5760d0ab | 5672 | return bs_head; |
c906108c | 5673 | } |
628fe4e4 JK |
5674 | |
5675 | static void | |
5676 | handle_jit_event (void) | |
5677 | { | |
5678 | struct frame_info *frame; | |
5679 | struct gdbarch *gdbarch; | |
5680 | ||
5681 | /* Switch terminal for any messages produced by | |
5682 | breakpoint_re_set. */ | |
5683 | target_terminal_ours_for_output (); | |
5684 | ||
5685 | frame = get_current_frame (); | |
5686 | gdbarch = get_frame_arch (frame); | |
5687 | ||
5688 | jit_event_handler (gdbarch); | |
5689 | ||
5690 | target_terminal_inferior (); | |
5691 | } | |
5692 | ||
5693 | /* Prepare WHAT final decision for infrun. */ | |
5694 | ||
5695 | /* Decide what infrun needs to do with this bpstat. */ | |
5696 | ||
c906108c | 5697 | struct bpstat_what |
0e30163f | 5698 | bpstat_what (bpstat bs_head) |
c906108c | 5699 | { |
c906108c | 5700 | struct bpstat_what retval; |
628fe4e4 | 5701 | int jit_event = 0; |
0e30163f | 5702 | bpstat bs; |
c906108c | 5703 | |
628fe4e4 | 5704 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5705 | retval.call_dummy = STOP_NONE; |
186c406b | 5706 | retval.is_longjmp = 0; |
628fe4e4 | 5707 | |
0e30163f | 5708 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5709 | { |
628fe4e4 JK |
5710 | /* Extract this BS's action. After processing each BS, we check |
5711 | if its action overrides all we've seem so far. */ | |
5712 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5713 | enum bptype bptype; | |
5714 | ||
c906108c | 5715 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5716 | { |
5717 | /* I suspect this can happen if it was a momentary | |
5718 | breakpoint which has since been deleted. */ | |
5719 | bptype = bp_none; | |
5720 | } | |
20874c92 | 5721 | else |
f431efe5 | 5722 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5723 | |
5724 | switch (bptype) | |
c906108c SS |
5725 | { |
5726 | case bp_none: | |
628fe4e4 | 5727 | break; |
c906108c SS |
5728 | case bp_breakpoint: |
5729 | case bp_hardware_breakpoint: | |
7c16b83e | 5730 | case bp_single_step: |
c906108c SS |
5731 | case bp_until: |
5732 | case bp_finish: | |
a9b3a50f | 5733 | case bp_shlib_event: |
c906108c SS |
5734 | if (bs->stop) |
5735 | { | |
5736 | if (bs->print) | |
628fe4e4 | 5737 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5738 | else |
628fe4e4 | 5739 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5740 | } |
5741 | else | |
628fe4e4 | 5742 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5743 | break; |
5744 | case bp_watchpoint: | |
5745 | case bp_hardware_watchpoint: | |
5746 | case bp_read_watchpoint: | |
5747 | case bp_access_watchpoint: | |
5748 | if (bs->stop) | |
5749 | { | |
5750 | if (bs->print) | |
628fe4e4 | 5751 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5752 | else |
628fe4e4 | 5753 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5754 | } |
5755 | else | |
628fe4e4 JK |
5756 | { |
5757 | /* There was a watchpoint, but we're not stopping. | |
5758 | This requires no further action. */ | |
5759 | } | |
c906108c SS |
5760 | break; |
5761 | case bp_longjmp: | |
e2e4d78b | 5762 | case bp_longjmp_call_dummy: |
186c406b | 5763 | case bp_exception: |
628fe4e4 | 5764 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5765 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5766 | break; |
5767 | case bp_longjmp_resume: | |
186c406b | 5768 | case bp_exception_resume: |
628fe4e4 | 5769 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5770 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5771 | break; |
5772 | case bp_step_resume: | |
5773 | if (bs->stop) | |
628fe4e4 JK |
5774 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5775 | else | |
c906108c | 5776 | { |
628fe4e4 JK |
5777 | /* It is for the wrong frame. */ |
5778 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5779 | } |
c906108c | 5780 | break; |
2c03e5be PA |
5781 | case bp_hp_step_resume: |
5782 | if (bs->stop) | |
5783 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5784 | else | |
5785 | { | |
5786 | /* It is for the wrong frame. */ | |
5787 | this_action = BPSTAT_WHAT_SINGLE; | |
5788 | } | |
5789 | break; | |
c906108c | 5790 | case bp_watchpoint_scope: |
c4093a6a | 5791 | case bp_thread_event: |
1900040c | 5792 | case bp_overlay_event: |
0fd8e87f | 5793 | case bp_longjmp_master: |
aa7d318d | 5794 | case bp_std_terminate_master: |
186c406b | 5795 | case bp_exception_master: |
628fe4e4 | 5796 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5797 | break; |
ce78b96d | 5798 | case bp_catchpoint: |
c5aa993b JM |
5799 | if (bs->stop) |
5800 | { | |
5801 | if (bs->print) | |
628fe4e4 | 5802 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5803 | else |
628fe4e4 | 5804 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5805 | } |
5806 | else | |
628fe4e4 JK |
5807 | { |
5808 | /* There was a catchpoint, but we're not stopping. | |
5809 | This requires no further action. */ | |
5810 | } | |
5811 | break; | |
628fe4e4 JK |
5812 | case bp_jit_event: |
5813 | jit_event = 1; | |
5814 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5815 | break; |
c906108c | 5816 | case bp_call_dummy: |
53a5351d JM |
5817 | /* Make sure the action is stop (silent or noisy), |
5818 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5819 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5820 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5821 | break; |
5822 | case bp_std_terminate: | |
5823 | /* Make sure the action is stop (silent or noisy), | |
5824 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5825 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5826 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5827 | break; |
1042e4c0 | 5828 | case bp_tracepoint: |
7a697b8d | 5829 | case bp_fast_tracepoint: |
0fb4aa4b | 5830 | case bp_static_tracepoint: |
1042e4c0 SS |
5831 | /* Tracepoint hits should not be reported back to GDB, and |
5832 | if one got through somehow, it should have been filtered | |
5833 | out already. */ | |
5834 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5835 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5836 | break; |
5837 | case bp_gnu_ifunc_resolver: | |
5838 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5839 | this_action = BPSTAT_WHAT_SINGLE; | |
5840 | break; | |
5841 | case bp_gnu_ifunc_resolver_return: | |
5842 | /* The breakpoint will be removed, execution will restart from the | |
5843 | PC of the former breakpoint. */ | |
5844 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5845 | break; | |
e7e0cddf SS |
5846 | |
5847 | case bp_dprintf: | |
a11cfd87 HZ |
5848 | if (bs->stop) |
5849 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5850 | else | |
5851 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5852 | break; |
5853 | ||
628fe4e4 JK |
5854 | default: |
5855 | internal_error (__FILE__, __LINE__, | |
5856 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5857 | } |
628fe4e4 JK |
5858 | |
5859 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5860 | } |
628fe4e4 | 5861 | |
0e30163f JK |
5862 | /* These operations may affect the bs->breakpoint_at state so they are |
5863 | delayed after MAIN_ACTION is decided above. */ | |
5864 | ||
628fe4e4 JK |
5865 | if (jit_event) |
5866 | { | |
5867 | if (debug_infrun) | |
5868 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5869 | ||
5870 | handle_jit_event (); | |
5871 | } | |
5872 | ||
0e30163f JK |
5873 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5874 | { | |
5875 | struct breakpoint *b = bs->breakpoint_at; | |
5876 | ||
5877 | if (b == NULL) | |
5878 | continue; | |
5879 | switch (b->type) | |
5880 | { | |
5881 | case bp_gnu_ifunc_resolver: | |
5882 | gnu_ifunc_resolver_stop (b); | |
5883 | break; | |
5884 | case bp_gnu_ifunc_resolver_return: | |
5885 | gnu_ifunc_resolver_return_stop (b); | |
5886 | break; | |
5887 | } | |
5888 | } | |
5889 | ||
c906108c SS |
5890 | return retval; |
5891 | } | |
5892 | ||
5893 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5894 | without hardware support). This isn't related to a specific bpstat, | |
5895 | just to things like whether watchpoints are set. */ | |
5896 | ||
c5aa993b | 5897 | int |
fba45db2 | 5898 | bpstat_should_step (void) |
c906108c SS |
5899 | { |
5900 | struct breakpoint *b; | |
cc59ec59 | 5901 | |
c906108c | 5902 | ALL_BREAKPOINTS (b) |
717a8278 | 5903 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5904 | return 1; |
c906108c SS |
5905 | return 0; |
5906 | } | |
5907 | ||
67822962 PA |
5908 | int |
5909 | bpstat_causes_stop (bpstat bs) | |
5910 | { | |
5911 | for (; bs != NULL; bs = bs->next) | |
5912 | if (bs->stop) | |
5913 | return 1; | |
5914 | ||
5915 | return 0; | |
5916 | } | |
5917 | ||
c906108c | 5918 | \f |
c5aa993b | 5919 | |
170b53b2 UW |
5920 | /* Compute a string of spaces suitable to indent the next line |
5921 | so it starts at the position corresponding to the table column | |
5922 | named COL_NAME in the currently active table of UIOUT. */ | |
5923 | ||
5924 | static char * | |
5925 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5926 | { | |
5927 | static char wrap_indent[80]; | |
5928 | int i, total_width, width, align; | |
5929 | char *text; | |
5930 | ||
5931 | total_width = 0; | |
5932 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5933 | { | |
5934 | if (strcmp (text, col_name) == 0) | |
5935 | { | |
5936 | gdb_assert (total_width < sizeof wrap_indent); | |
5937 | memset (wrap_indent, ' ', total_width); | |
5938 | wrap_indent[total_width] = 0; | |
5939 | ||
5940 | return wrap_indent; | |
5941 | } | |
5942 | ||
5943 | total_width += width + 1; | |
5944 | } | |
5945 | ||
5946 | return NULL; | |
5947 | } | |
5948 | ||
b775012e LM |
5949 | /* Determine if the locations of this breakpoint will have their conditions |
5950 | evaluated by the target, host or a mix of both. Returns the following: | |
5951 | ||
5952 | "host": Host evals condition. | |
5953 | "host or target": Host or Target evals condition. | |
5954 | "target": Target evals condition. | |
5955 | */ | |
5956 | ||
5957 | static const char * | |
5958 | bp_condition_evaluator (struct breakpoint *b) | |
5959 | { | |
5960 | struct bp_location *bl; | |
5961 | char host_evals = 0; | |
5962 | char target_evals = 0; | |
5963 | ||
5964 | if (!b) | |
5965 | return NULL; | |
5966 | ||
5967 | if (!is_breakpoint (b)) | |
5968 | return NULL; | |
5969 | ||
5970 | if (gdb_evaluates_breakpoint_condition_p () | |
5971 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5972 | return condition_evaluation_host; | |
5973 | ||
5974 | for (bl = b->loc; bl; bl = bl->next) | |
5975 | { | |
5976 | if (bl->cond_bytecode) | |
5977 | target_evals++; | |
5978 | else | |
5979 | host_evals++; | |
5980 | } | |
5981 | ||
5982 | if (host_evals && target_evals) | |
5983 | return condition_evaluation_both; | |
5984 | else if (target_evals) | |
5985 | return condition_evaluation_target; | |
5986 | else | |
5987 | return condition_evaluation_host; | |
5988 | } | |
5989 | ||
5990 | /* Determine the breakpoint location's condition evaluator. This is | |
5991 | similar to bp_condition_evaluator, but for locations. */ | |
5992 | ||
5993 | static const char * | |
5994 | bp_location_condition_evaluator (struct bp_location *bl) | |
5995 | { | |
5996 | if (bl && !is_breakpoint (bl->owner)) | |
5997 | return NULL; | |
5998 | ||
5999 | if (gdb_evaluates_breakpoint_condition_p () | |
6000 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6001 | return condition_evaluation_host; | |
6002 | ||
6003 | if (bl && bl->cond_bytecode) | |
6004 | return condition_evaluation_target; | |
6005 | else | |
6006 | return condition_evaluation_host; | |
6007 | } | |
6008 | ||
859825b8 JK |
6009 | /* Print the LOC location out of the list of B->LOC locations. */ |
6010 | ||
170b53b2 UW |
6011 | static void |
6012 | print_breakpoint_location (struct breakpoint *b, | |
6013 | struct bp_location *loc) | |
0d381245 | 6014 | { |
79a45e25 | 6015 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6016 | struct cleanup *old_chain = save_current_program_space (); |
6017 | ||
859825b8 JK |
6018 | if (loc != NULL && loc->shlib_disabled) |
6019 | loc = NULL; | |
6020 | ||
6c95b8df PA |
6021 | if (loc != NULL) |
6022 | set_current_program_space (loc->pspace); | |
6023 | ||
56435ebe TT |
6024 | if (b->display_canonical) |
6025 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 6026 | else if (loc && loc->symtab) |
0d381245 VP |
6027 | { |
6028 | struct symbol *sym | |
6029 | = find_pc_sect_function (loc->address, loc->section); | |
6030 | if (sym) | |
6031 | { | |
6032 | ui_out_text (uiout, "in "); | |
6033 | ui_out_field_string (uiout, "func", | |
6034 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6035 | ui_out_text (uiout, " "); |
6036 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6037 | ui_out_text (uiout, "at "); | |
0d381245 | 6038 | } |
05cba821 JK |
6039 | ui_out_field_string (uiout, "file", |
6040 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6041 | ui_out_text (uiout, ":"); |
05cba821 | 6042 | |
0d381245 | 6043 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6044 | ui_out_field_string (uiout, "fullname", |
6045 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6046 | |
f8eba3c6 | 6047 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6048 | } |
859825b8 | 6049 | else if (loc) |
0d381245 | 6050 | { |
f99d8bf4 PA |
6051 | struct ui_file *stb = mem_fileopen (); |
6052 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6053 | |
f99d8bf4 | 6054 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6055 | demangle, ""); |
0d381245 | 6056 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6057 | |
6058 | do_cleanups (stb_chain); | |
0d381245 | 6059 | } |
859825b8 JK |
6060 | else |
6061 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 6062 | |
b775012e LM |
6063 | if (loc && is_breakpoint (b) |
6064 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6065 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6066 | { | |
6067 | ui_out_text (uiout, " ("); | |
6068 | ui_out_field_string (uiout, "evaluated-by", | |
6069 | bp_location_condition_evaluator (loc)); | |
6070 | ui_out_text (uiout, ")"); | |
6071 | } | |
6072 | ||
6c95b8df | 6073 | do_cleanups (old_chain); |
0d381245 VP |
6074 | } |
6075 | ||
269b11a2 PA |
6076 | static const char * |
6077 | bptype_string (enum bptype type) | |
c906108c | 6078 | { |
c4093a6a JM |
6079 | struct ep_type_description |
6080 | { | |
6081 | enum bptype type; | |
6082 | char *description; | |
6083 | }; | |
6084 | static struct ep_type_description bptypes[] = | |
c906108c | 6085 | { |
c5aa993b JM |
6086 | {bp_none, "?deleted?"}, |
6087 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6088 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6089 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6090 | {bp_until, "until"}, |
6091 | {bp_finish, "finish"}, | |
6092 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6093 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6094 | {bp_read_watchpoint, "read watchpoint"}, |
6095 | {bp_access_watchpoint, "acc watchpoint"}, | |
6096 | {bp_longjmp, "longjmp"}, | |
6097 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6098 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6099 | {bp_exception, "exception"}, |
6100 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6101 | {bp_step_resume, "step resume"}, |
2c03e5be | 6102 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6103 | {bp_watchpoint_scope, "watchpoint scope"}, |
6104 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6105 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6106 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6107 | {bp_thread_event, "thread events"}, |
1900040c | 6108 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6109 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6110 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6111 | {bp_exception_master, "exception master"}, |
ce78b96d | 6112 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6113 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6114 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6115 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6116 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6117 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6118 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6119 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6120 | }; |
269b11a2 PA |
6121 | |
6122 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6123 | || ((int) type != bptypes[(int) type].type)) | |
6124 | internal_error (__FILE__, __LINE__, | |
6125 | _("bptypes table does not describe type #%d."), | |
6126 | (int) type); | |
6127 | ||
6128 | return bptypes[(int) type].description; | |
6129 | } | |
6130 | ||
998580f1 MK |
6131 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6132 | For CLI, prefix the list with the string 'inf'. */ | |
6133 | ||
6134 | static void | |
6135 | output_thread_groups (struct ui_out *uiout, | |
6136 | const char *field_name, | |
6137 | VEC(int) *inf_num, | |
6138 | int mi_only) | |
6139 | { | |
752eb8b4 | 6140 | struct cleanup *back_to; |
998580f1 MK |
6141 | int is_mi = ui_out_is_mi_like_p (uiout); |
6142 | int inf; | |
6143 | int i; | |
6144 | ||
6145 | /* For backward compatibility, don't display inferiors in CLI unless | |
6146 | there are several. Always display them for MI. */ | |
6147 | if (!is_mi && mi_only) | |
6148 | return; | |
6149 | ||
752eb8b4 TT |
6150 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6151 | ||
998580f1 MK |
6152 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6153 | { | |
6154 | if (is_mi) | |
6155 | { | |
6156 | char mi_group[10]; | |
6157 | ||
6158 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6159 | ui_out_field_string (uiout, NULL, mi_group); | |
6160 | } | |
6161 | else | |
6162 | { | |
6163 | if (i == 0) | |
6164 | ui_out_text (uiout, " inf "); | |
6165 | else | |
6166 | ui_out_text (uiout, ", "); | |
6167 | ||
6168 | ui_out_text (uiout, plongest (inf)); | |
6169 | } | |
6170 | } | |
6171 | ||
6172 | do_cleanups (back_to); | |
6173 | } | |
6174 | ||
269b11a2 PA |
6175 | /* Print B to gdb_stdout. */ |
6176 | ||
6177 | static void | |
6178 | print_one_breakpoint_location (struct breakpoint *b, | |
6179 | struct bp_location *loc, | |
6180 | int loc_number, | |
6181 | struct bp_location **last_loc, | |
269b11a2 PA |
6182 | int allflag) |
6183 | { | |
6184 | struct command_line *l; | |
c2c6d25f | 6185 | static char bpenables[] = "nynny"; |
c906108c | 6186 | |
79a45e25 | 6187 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6188 | int header_of_multiple = 0; |
6189 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6190 | struct value_print_options opts; |
6191 | ||
6192 | get_user_print_options (&opts); | |
0d381245 VP |
6193 | |
6194 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6195 | /* See comment in print_one_breakpoint concerning treatment of |
6196 | breakpoints with single disabled location. */ | |
0d381245 VP |
6197 | if (loc == NULL |
6198 | && (b->loc != NULL | |
6199 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6200 | header_of_multiple = 1; | |
6201 | if (loc == NULL) | |
6202 | loc = b->loc; | |
6203 | ||
c4093a6a JM |
6204 | annotate_record (); |
6205 | ||
6206 | /* 1 */ | |
6207 | annotate_field (0); | |
0d381245 VP |
6208 | if (part_of_multiple) |
6209 | { | |
6210 | char *formatted; | |
0c6773c1 | 6211 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6212 | ui_out_field_string (uiout, "number", formatted); |
6213 | xfree (formatted); | |
6214 | } | |
6215 | else | |
6216 | { | |
6217 | ui_out_field_int (uiout, "number", b->number); | |
6218 | } | |
c4093a6a JM |
6219 | |
6220 | /* 2 */ | |
6221 | annotate_field (1); | |
0d381245 VP |
6222 | if (part_of_multiple) |
6223 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6224 | else |
6225 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6226 | |
6227 | /* 3 */ | |
6228 | annotate_field (2); | |
0d381245 VP |
6229 | if (part_of_multiple) |
6230 | ui_out_field_skip (uiout, "disp"); | |
6231 | else | |
2cec12e5 | 6232 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6233 | |
c4093a6a JM |
6234 | |
6235 | /* 4 */ | |
6236 | annotate_field (3); | |
0d381245 | 6237 | if (part_of_multiple) |
54e52265 | 6238 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6239 | else |
4a64f543 MS |
6240 | ui_out_field_fmt (uiout, "enabled", "%c", |
6241 | bpenables[(int) b->enable_state]); | |
54e52265 | 6242 | ui_out_spaces (uiout, 2); |
0d381245 | 6243 | |
c4093a6a JM |
6244 | |
6245 | /* 5 and 6 */ | |
3086aeae | 6246 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6247 | { |
4a64f543 MS |
6248 | /* Although the print_one can possibly print all locations, |
6249 | calling it here is not likely to get any nice result. So, | |
6250 | make sure there's just one location. */ | |
0d381245 | 6251 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6252 | b->ops->print_one (b, last_loc); |
0d381245 | 6253 | } |
3086aeae DJ |
6254 | else |
6255 | switch (b->type) | |
6256 | { | |
6257 | case bp_none: | |
6258 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6259 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6260 | break; |
c906108c | 6261 | |
3086aeae DJ |
6262 | case bp_watchpoint: |
6263 | case bp_hardware_watchpoint: | |
6264 | case bp_read_watchpoint: | |
6265 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6266 | { |
6267 | struct watchpoint *w = (struct watchpoint *) b; | |
6268 | ||
6269 | /* Field 4, the address, is omitted (which makes the columns | |
6270 | not line up too nicely with the headers, but the effect | |
6271 | is relatively readable). */ | |
6272 | if (opts.addressprint) | |
6273 | ui_out_field_skip (uiout, "addr"); | |
6274 | annotate_field (5); | |
6275 | ui_out_field_string (uiout, "what", w->exp_string); | |
6276 | } | |
3086aeae DJ |
6277 | break; |
6278 | ||
3086aeae DJ |
6279 | case bp_breakpoint: |
6280 | case bp_hardware_breakpoint: | |
7c16b83e | 6281 | case bp_single_step: |
3086aeae DJ |
6282 | case bp_until: |
6283 | case bp_finish: | |
6284 | case bp_longjmp: | |
6285 | case bp_longjmp_resume: | |
e2e4d78b | 6286 | case bp_longjmp_call_dummy: |
186c406b TT |
6287 | case bp_exception: |
6288 | case bp_exception_resume: | |
3086aeae | 6289 | case bp_step_resume: |
2c03e5be | 6290 | case bp_hp_step_resume: |
3086aeae DJ |
6291 | case bp_watchpoint_scope: |
6292 | case bp_call_dummy: | |
aa7d318d | 6293 | case bp_std_terminate: |
3086aeae DJ |
6294 | case bp_shlib_event: |
6295 | case bp_thread_event: | |
6296 | case bp_overlay_event: | |
0fd8e87f | 6297 | case bp_longjmp_master: |
aa7d318d | 6298 | case bp_std_terminate_master: |
186c406b | 6299 | case bp_exception_master: |
1042e4c0 | 6300 | case bp_tracepoint: |
7a697b8d | 6301 | case bp_fast_tracepoint: |
0fb4aa4b | 6302 | case bp_static_tracepoint: |
e7e0cddf | 6303 | case bp_dprintf: |
4efc6507 | 6304 | case bp_jit_event: |
0e30163f JK |
6305 | case bp_gnu_ifunc_resolver: |
6306 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6307 | if (opts.addressprint) |
3086aeae DJ |
6308 | { |
6309 | annotate_field (4); | |
54e52265 | 6310 | if (header_of_multiple) |
0d381245 | 6311 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6312 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6313 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6314 | else |
5af949e3 UW |
6315 | ui_out_field_core_addr (uiout, "addr", |
6316 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6317 | } |
6318 | annotate_field (5); | |
0d381245 | 6319 | if (!header_of_multiple) |
170b53b2 | 6320 | print_breakpoint_location (b, loc); |
0d381245 | 6321 | if (b->loc) |
a6d9a66e | 6322 | *last_loc = b->loc; |
3086aeae DJ |
6323 | break; |
6324 | } | |
c906108c | 6325 | |
6c95b8df | 6326 | |
998580f1 | 6327 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6328 | { |
6329 | struct inferior *inf; | |
998580f1 MK |
6330 | VEC(int) *inf_num = NULL; |
6331 | int mi_only = 1; | |
6c95b8df | 6332 | |
998580f1 | 6333 | ALL_INFERIORS (inf) |
6c95b8df PA |
6334 | { |
6335 | if (inf->pspace == loc->pspace) | |
998580f1 | 6336 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6337 | } |
998580f1 MK |
6338 | |
6339 | /* For backward compatibility, don't display inferiors in CLI unless | |
6340 | there are several. Always display for MI. */ | |
6341 | if (allflag | |
6342 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6343 | && (number_of_program_spaces () > 1 | |
6344 | || number_of_inferiors () > 1) | |
6345 | /* LOC is for existing B, it cannot be in | |
6346 | moribund_locations and thus having NULL OWNER. */ | |
6347 | && loc->owner->type != bp_catchpoint)) | |
6348 | mi_only = 0; | |
6349 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6350 | VEC_free (int, inf_num); | |
6c95b8df PA |
6351 | } |
6352 | ||
4a306c9a | 6353 | if (!part_of_multiple) |
c4093a6a | 6354 | { |
4a306c9a JB |
6355 | if (b->thread != -1) |
6356 | { | |
6357 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6358 | "stop only in" line a little further down. */ |
4a306c9a JB |
6359 | ui_out_text (uiout, " thread "); |
6360 | ui_out_field_int (uiout, "thread", b->thread); | |
6361 | } | |
6362 | else if (b->task != 0) | |
6363 | { | |
6364 | ui_out_text (uiout, " task "); | |
6365 | ui_out_field_int (uiout, "task", b->task); | |
6366 | } | |
c4093a6a | 6367 | } |
f1310107 | 6368 | |
8b93c638 | 6369 | ui_out_text (uiout, "\n"); |
f1310107 | 6370 | |
348d480f | 6371 | if (!part_of_multiple) |
f1310107 TJB |
6372 | b->ops->print_one_detail (b, uiout); |
6373 | ||
0d381245 | 6374 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6375 | { |
6376 | annotate_field (6); | |
8b93c638 | 6377 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6378 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6379 | the frame ID. */ |
5af949e3 UW |
6380 | ui_out_field_core_addr (uiout, "frame", |
6381 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6382 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6383 | } |
6384 | ||
28010a5d | 6385 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6386 | { |
6387 | annotate_field (7); | |
d77f58be | 6388 | if (is_tracepoint (b)) |
1042e4c0 SS |
6389 | ui_out_text (uiout, "\ttrace only if "); |
6390 | else | |
6391 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6392 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6393 | |
6394 | /* Print whether the target is doing the breakpoint's condition | |
6395 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6396 | if (is_breakpoint (b) | |
6397 | && breakpoint_condition_evaluation_mode () | |
6398 | == condition_evaluation_target) | |
6399 | { | |
6400 | ui_out_text (uiout, " ("); | |
6401 | ui_out_field_string (uiout, "evaluated-by", | |
6402 | bp_condition_evaluator (b)); | |
6403 | ui_out_text (uiout, " evals)"); | |
6404 | } | |
0101ce28 JJ |
6405 | ui_out_text (uiout, "\n"); |
6406 | } | |
6407 | ||
0d381245 | 6408 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6409 | { |
4a64f543 | 6410 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6411 | ui_out_text (uiout, "\tstop only in thread "); |
6412 | ui_out_field_int (uiout, "thread", b->thread); | |
6413 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6414 | } |
6415 | ||
556ec64d YQ |
6416 | if (!part_of_multiple) |
6417 | { | |
6418 | if (b->hit_count) | |
31f56a27 YQ |
6419 | { |
6420 | /* FIXME should make an annotation for this. */ | |
6421 | if (is_catchpoint (b)) | |
6422 | ui_out_text (uiout, "\tcatchpoint"); | |
6423 | else if (is_tracepoint (b)) | |
6424 | ui_out_text (uiout, "\ttracepoint"); | |
6425 | else | |
6426 | ui_out_text (uiout, "\tbreakpoint"); | |
6427 | ui_out_text (uiout, " already hit "); | |
6428 | ui_out_field_int (uiout, "times", b->hit_count); | |
6429 | if (b->hit_count == 1) | |
6430 | ui_out_text (uiout, " time\n"); | |
6431 | else | |
6432 | ui_out_text (uiout, " times\n"); | |
6433 | } | |
556ec64d YQ |
6434 | else |
6435 | { | |
31f56a27 YQ |
6436 | /* Output the count also if it is zero, but only if this is mi. */ |
6437 | if (ui_out_is_mi_like_p (uiout)) | |
6438 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6439 | } |
6440 | } | |
8b93c638 | 6441 | |
0d381245 | 6442 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6443 | { |
6444 | annotate_field (8); | |
8b93c638 JM |
6445 | ui_out_text (uiout, "\tignore next "); |
6446 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6447 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6448 | } |
059fb39f | 6449 | |
816338b5 SS |
6450 | /* Note that an enable count of 1 corresponds to "enable once" |
6451 | behavior, which is reported by the combination of enablement and | |
6452 | disposition, so we don't need to mention it here. */ | |
6453 | if (!part_of_multiple && b->enable_count > 1) | |
6454 | { | |
6455 | annotate_field (8); | |
6456 | ui_out_text (uiout, "\tdisable after "); | |
6457 | /* Tweak the wording to clarify that ignore and enable counts | |
6458 | are distinct, and have additive effect. */ | |
6459 | if (b->ignore_count) | |
6460 | ui_out_text (uiout, "additional "); | |
6461 | else | |
6462 | ui_out_text (uiout, "next "); | |
6463 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6464 | ui_out_text (uiout, " hits\n"); | |
6465 | } | |
6466 | ||
f196051f SS |
6467 | if (!part_of_multiple && is_tracepoint (b)) |
6468 | { | |
6469 | struct tracepoint *tp = (struct tracepoint *) b; | |
6470 | ||
6471 | if (tp->traceframe_usage) | |
6472 | { | |
6473 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6474 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6475 | ui_out_text (uiout, " bytes\n"); | |
6476 | } | |
6477 | } | |
d3ce09f5 | 6478 | |
9add0f1b | 6479 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6480 | if (!part_of_multiple && l) |
c4093a6a | 6481 | { |
3b31d625 EZ |
6482 | struct cleanup *script_chain; |
6483 | ||
c4093a6a | 6484 | annotate_field (9); |
3b31d625 | 6485 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6486 | print_command_lines (uiout, l, 4); |
3b31d625 | 6487 | do_cleanups (script_chain); |
c4093a6a | 6488 | } |
d24317b4 | 6489 | |
d9b3f62e | 6490 | if (is_tracepoint (b)) |
1042e4c0 | 6491 | { |
d9b3f62e PA |
6492 | struct tracepoint *t = (struct tracepoint *) b; |
6493 | ||
6494 | if (!part_of_multiple && t->pass_count) | |
6495 | { | |
6496 | annotate_field (10); | |
6497 | ui_out_text (uiout, "\tpass count "); | |
6498 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6499 | ui_out_text (uiout, " \n"); | |
6500 | } | |
f2a8bc8a YQ |
6501 | |
6502 | /* Don't display it when tracepoint or tracepoint location is | |
6503 | pending. */ | |
6504 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6505 | { | |
6506 | annotate_field (11); | |
6507 | ||
6508 | if (ui_out_is_mi_like_p (uiout)) | |
6509 | ui_out_field_string (uiout, "installed", | |
6510 | loc->inserted ? "y" : "n"); | |
6511 | else | |
6512 | { | |
6513 | if (loc->inserted) | |
6514 | ui_out_text (uiout, "\t"); | |
6515 | else | |
6516 | ui_out_text (uiout, "\tnot "); | |
6517 | ui_out_text (uiout, "installed on target\n"); | |
6518 | } | |
6519 | } | |
1042e4c0 SS |
6520 | } |
6521 | ||
d24317b4 VP |
6522 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6523 | { | |
3a5c3e22 PA |
6524 | if (is_watchpoint (b)) |
6525 | { | |
6526 | struct watchpoint *w = (struct watchpoint *) b; | |
6527 | ||
6528 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6529 | } | |
6530 | else if (b->addr_string) | |
d24317b4 | 6531 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6532 | } |
c4093a6a | 6533 | } |
c5aa993b | 6534 | |
0d381245 VP |
6535 | static void |
6536 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6537 | struct bp_location **last_loc, |
6c95b8df | 6538 | int allflag) |
0d381245 | 6539 | { |
8d3788bd | 6540 | struct cleanup *bkpt_chain; |
79a45e25 | 6541 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6542 | |
6543 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6544 | ||
12c5a436 | 6545 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6546 | do_cleanups (bkpt_chain); |
0d381245 VP |
6547 | |
6548 | /* If this breakpoint has custom print function, | |
6549 | it's already printed. Otherwise, print individual | |
6550 | locations, if any. */ | |
6551 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6552 | { | |
4a64f543 MS |
6553 | /* If breakpoint has a single location that is disabled, we |
6554 | print it as if it had several locations, since otherwise it's | |
6555 | hard to represent "breakpoint enabled, location disabled" | |
6556 | situation. | |
6557 | ||
6558 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6559 | internally, that's not a property exposed to user. */ |
0d381245 | 6560 | if (b->loc |
a5606eee | 6561 | && !is_hardware_watchpoint (b) |
8d3788bd | 6562 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6563 | { |
6564 | struct bp_location *loc; | |
6565 | int n = 1; | |
8d3788bd | 6566 | |
0d381245 | 6567 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6568 | { |
6569 | struct cleanup *inner2 = | |
6570 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6571 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6572 | do_cleanups (inner2); | |
6573 | } | |
0d381245 VP |
6574 | } |
6575 | } | |
6576 | } | |
6577 | ||
a6d9a66e UW |
6578 | static int |
6579 | breakpoint_address_bits (struct breakpoint *b) | |
6580 | { | |
6581 | int print_address_bits = 0; | |
6582 | struct bp_location *loc; | |
6583 | ||
6584 | for (loc = b->loc; loc; loc = loc->next) | |
6585 | { | |
c7437ca6 PA |
6586 | int addr_bit; |
6587 | ||
6588 | /* Software watchpoints that aren't watching memory don't have | |
6589 | an address to print. */ | |
6590 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6591 | continue; | |
6592 | ||
6593 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6594 | if (addr_bit > print_address_bits) |
6595 | print_address_bits = addr_bit; | |
6596 | } | |
6597 | ||
6598 | return print_address_bits; | |
6599 | } | |
0d381245 | 6600 | |
c4093a6a JM |
6601 | struct captured_breakpoint_query_args |
6602 | { | |
6603 | int bnum; | |
6604 | }; | |
c5aa993b | 6605 | |
c4093a6a | 6606 | static int |
2b65245e | 6607 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6608 | { |
6609 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6610 | struct breakpoint *b; |
a6d9a66e | 6611 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6612 | |
c4093a6a JM |
6613 | ALL_BREAKPOINTS (b) |
6614 | { | |
6615 | if (args->bnum == b->number) | |
c5aa993b | 6616 | { |
12c5a436 | 6617 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6618 | return GDB_RC_OK; |
c5aa993b | 6619 | } |
c4093a6a JM |
6620 | } |
6621 | return GDB_RC_NONE; | |
6622 | } | |
c5aa993b | 6623 | |
c4093a6a | 6624 | enum gdb_rc |
4a64f543 MS |
6625 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6626 | char **error_message) | |
c4093a6a JM |
6627 | { |
6628 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6629 | |
c4093a6a JM |
6630 | args.bnum = bnum; |
6631 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6632 | an error. */ |
b0b13bb4 DJ |
6633 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6634 | error_message, RETURN_MASK_ALL) < 0) | |
6635 | return GDB_RC_FAIL; | |
6636 | else | |
6637 | return GDB_RC_OK; | |
c4093a6a | 6638 | } |
c5aa993b | 6639 | |
09d682a4 TT |
6640 | /* Return true if this breakpoint was set by the user, false if it is |
6641 | internal or momentary. */ | |
6642 | ||
6643 | int | |
6644 | user_breakpoint_p (struct breakpoint *b) | |
6645 | { | |
46c6471b | 6646 | return b->number > 0; |
09d682a4 TT |
6647 | } |
6648 | ||
7f3b0473 | 6649 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6650 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6651 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6652 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6653 | ones for which it returns non-zero. Return the total number of | |
6654 | breakpoints listed. */ | |
c906108c | 6655 | |
d77f58be | 6656 | static int |
e5a67952 | 6657 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6658 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6659 | { |
52f0bd74 | 6660 | struct breakpoint *b; |
a6d9a66e | 6661 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6662 | int nr_printable_breakpoints; |
3b31d625 | 6663 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6664 | struct value_print_options opts; |
a6d9a66e | 6665 | int print_address_bits = 0; |
269b11a2 | 6666 | int print_type_col_width = 14; |
79a45e25 | 6667 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6668 | |
79a45b7d TT |
6669 | get_user_print_options (&opts); |
6670 | ||
4a64f543 MS |
6671 | /* Compute the number of rows in the table, as well as the size |
6672 | required for address fields. */ | |
7f3b0473 AC |
6673 | nr_printable_breakpoints = 0; |
6674 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6675 | { |
6676 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6677 | if (filter && !filter (b)) | |
6678 | continue; | |
6679 | ||
6680 | /* If we have an "args" string, it is a list of breakpoints to | |
6681 | accept. Skip the others. */ | |
6682 | if (args != NULL && *args != '\0') | |
6683 | { | |
6684 | if (allflag && parse_and_eval_long (args) != b->number) | |
6685 | continue; | |
6686 | if (!allflag && !number_is_in_list (args, b->number)) | |
6687 | continue; | |
6688 | } | |
269b11a2 | 6689 | |
e5a67952 MS |
6690 | if (allflag || user_breakpoint_p (b)) |
6691 | { | |
6692 | int addr_bit, type_len; | |
a6d9a66e | 6693 | |
e5a67952 MS |
6694 | addr_bit = breakpoint_address_bits (b); |
6695 | if (addr_bit > print_address_bits) | |
6696 | print_address_bits = addr_bit; | |
269b11a2 | 6697 | |
e5a67952 MS |
6698 | type_len = strlen (bptype_string (b->type)); |
6699 | if (type_len > print_type_col_width) | |
6700 | print_type_col_width = type_len; | |
6701 | ||
6702 | nr_printable_breakpoints++; | |
6703 | } | |
6704 | } | |
7f3b0473 | 6705 | |
79a45b7d | 6706 | if (opts.addressprint) |
3b31d625 | 6707 | bkpttbl_chain |
3e43a32a MS |
6708 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6709 | nr_printable_breakpoints, | |
3b31d625 | 6710 | "BreakpointTable"); |
8b93c638 | 6711 | else |
3b31d625 | 6712 | bkpttbl_chain |
3e43a32a MS |
6713 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6714 | nr_printable_breakpoints, | |
3b31d625 | 6715 | "BreakpointTable"); |
8b93c638 | 6716 | |
7f3b0473 | 6717 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6718 | annotate_breakpoints_headers (); |
6719 | if (nr_printable_breakpoints > 0) | |
6720 | annotate_field (0); | |
4a64f543 | 6721 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6722 | if (nr_printable_breakpoints > 0) |
6723 | annotate_field (1); | |
269b11a2 | 6724 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6725 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6726 | if (nr_printable_breakpoints > 0) |
6727 | annotate_field (2); | |
4a64f543 | 6728 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6729 | if (nr_printable_breakpoints > 0) |
6730 | annotate_field (3); | |
54e52265 | 6731 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6732 | if (opts.addressprint) |
e5a67952 MS |
6733 | { |
6734 | if (nr_printable_breakpoints > 0) | |
6735 | annotate_field (4); | |
6736 | if (print_address_bits <= 32) | |
6737 | ui_out_table_header (uiout, 10, ui_left, | |
6738 | "addr", "Address"); /* 5 */ | |
6739 | else | |
6740 | ui_out_table_header (uiout, 18, ui_left, | |
6741 | "addr", "Address"); /* 5 */ | |
6742 | } | |
d7faa9e7 AC |
6743 | if (nr_printable_breakpoints > 0) |
6744 | annotate_field (5); | |
6745 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6746 | ui_out_table_body (uiout); | |
6747 | if (nr_printable_breakpoints > 0) | |
6748 | annotate_breakpoints_table (); | |
7f3b0473 | 6749 | |
c4093a6a | 6750 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6751 | { |
6752 | QUIT; | |
6753 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6754 | if (filter && !filter (b)) | |
6755 | continue; | |
6756 | ||
6757 | /* If we have an "args" string, it is a list of breakpoints to | |
6758 | accept. Skip the others. */ | |
6759 | ||
6760 | if (args != NULL && *args != '\0') | |
6761 | { | |
6762 | if (allflag) /* maintenance info breakpoint */ | |
6763 | { | |
6764 | if (parse_and_eval_long (args) != b->number) | |
6765 | continue; | |
6766 | } | |
6767 | else /* all others */ | |
6768 | { | |
6769 | if (!number_is_in_list (args, b->number)) | |
6770 | continue; | |
6771 | } | |
6772 | } | |
6773 | /* We only print out user settable breakpoints unless the | |
6774 | allflag is set. */ | |
6775 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6776 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6777 | } |
6778 | ||
3b31d625 | 6779 | do_cleanups (bkpttbl_chain); |
698384cd | 6780 | |
7f3b0473 | 6781 | if (nr_printable_breakpoints == 0) |
c906108c | 6782 | { |
4a64f543 MS |
6783 | /* If there's a filter, let the caller decide how to report |
6784 | empty list. */ | |
d77f58be SS |
6785 | if (!filter) |
6786 | { | |
e5a67952 | 6787 | if (args == NULL || *args == '\0') |
d77f58be SS |
6788 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6789 | else | |
4a64f543 | 6790 | ui_out_message (uiout, 0, |
e5a67952 MS |
6791 | "No breakpoint or watchpoint matching '%s'.\n", |
6792 | args); | |
d77f58be | 6793 | } |
c906108c SS |
6794 | } |
6795 | else | |
c4093a6a | 6796 | { |
a6d9a66e UW |
6797 | if (last_loc && !server_command) |
6798 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6799 | } |
c906108c | 6800 | |
4a64f543 | 6801 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6802 | there have been breakpoints? */ |
c906108c | 6803 | annotate_breakpoints_table_end (); |
d77f58be SS |
6804 | |
6805 | return nr_printable_breakpoints; | |
c906108c SS |
6806 | } |
6807 | ||
ad443146 SS |
6808 | /* Display the value of default-collect in a way that is generally |
6809 | compatible with the breakpoint list. */ | |
6810 | ||
6811 | static void | |
6812 | default_collect_info (void) | |
6813 | { | |
79a45e25 PA |
6814 | struct ui_out *uiout = current_uiout; |
6815 | ||
ad443146 SS |
6816 | /* If it has no value (which is frequently the case), say nothing; a |
6817 | message like "No default-collect." gets in user's face when it's | |
6818 | not wanted. */ | |
6819 | if (!*default_collect) | |
6820 | return; | |
6821 | ||
6822 | /* The following phrase lines up nicely with per-tracepoint collect | |
6823 | actions. */ | |
6824 | ui_out_text (uiout, "default collect "); | |
6825 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6826 | ui_out_text (uiout, " \n"); | |
6827 | } | |
6828 | ||
c906108c | 6829 | static void |
e5a67952 | 6830 | breakpoints_info (char *args, int from_tty) |
c906108c | 6831 | { |
e5a67952 | 6832 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6833 | |
6834 | default_collect_info (); | |
d77f58be SS |
6835 | } |
6836 | ||
6837 | static void | |
e5a67952 | 6838 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6839 | { |
e5a67952 | 6840 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6841 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6842 | |
6843 | if (num_printed == 0) | |
6844 | { | |
e5a67952 | 6845 | if (args == NULL || *args == '\0') |
d77f58be SS |
6846 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6847 | else | |
e5a67952 | 6848 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6849 | } |
c906108c SS |
6850 | } |
6851 | ||
7a292a7a | 6852 | static void |
e5a67952 | 6853 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6854 | { |
e5a67952 | 6855 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6856 | |
6857 | default_collect_info (); | |
c906108c SS |
6858 | } |
6859 | ||
0d381245 | 6860 | static int |
714835d5 | 6861 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6862 | struct program_space *pspace, |
714835d5 | 6863 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6864 | { |
6865 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6866 | |
0d381245 VP |
6867 | for (; bl; bl = bl->next) |
6868 | { | |
6c95b8df PA |
6869 | if (bl->pspace == pspace |
6870 | && bl->address == pc | |
0d381245 VP |
6871 | && (!overlay_debugging || bl->section == section)) |
6872 | return 1; | |
6873 | } | |
6874 | return 0; | |
6875 | } | |
6876 | ||
672f9b60 | 6877 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6878 | concerns with logical breakpoints, so we match program spaces, not |
6879 | address spaces. */ | |
c906108c SS |
6880 | |
6881 | static void | |
6c95b8df PA |
6882 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6883 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6884 | struct obj_section *section, int thread) |
c906108c | 6885 | { |
52f0bd74 AC |
6886 | int others = 0; |
6887 | struct breakpoint *b; | |
c906108c SS |
6888 | |
6889 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6890 | others += (user_breakpoint_p (b) |
6891 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6892 | if (others > 0) |
6893 | { | |
a3f17187 AC |
6894 | if (others == 1) |
6895 | printf_filtered (_("Note: breakpoint ")); | |
6896 | else /* if (others == ???) */ | |
6897 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6898 | ALL_BREAKPOINTS (b) |
672f9b60 | 6899 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6900 | { |
6901 | others--; | |
6902 | printf_filtered ("%d", b->number); | |
6903 | if (b->thread == -1 && thread != -1) | |
6904 | printf_filtered (" (all threads)"); | |
6905 | else if (b->thread != -1) | |
6906 | printf_filtered (" (thread %d)", b->thread); | |
6907 | printf_filtered ("%s%s ", | |
059fb39f | 6908 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6909 | || b->enable_state == bp_call_disabled) |
0d381245 | 6910 | ? " (disabled)" |
0d381245 VP |
6911 | : ""), |
6912 | (others > 1) ? "," | |
6913 | : ((others == 1) ? " and" : "")); | |
6914 | } | |
a3f17187 | 6915 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6916 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6917 | printf_filtered (".\n"); |
6918 | } | |
6919 | } | |
6920 | \f | |
c906108c | 6921 | |
e4f237da KB |
6922 | /* Return true iff it is meaningful to use the address member of |
6923 | BPT. For some breakpoint types, the address member is irrelevant | |
6924 | and it makes no sense to attempt to compare it to other addresses | |
6925 | (or use it for any other purpose either). | |
6926 | ||
4a64f543 MS |
6927 | More specifically, each of the following breakpoint types will |
6928 | always have a zero valued address and we don't want to mark | |
6929 | breakpoints of any of these types to be a duplicate of an actual | |
6930 | breakpoint at address zero: | |
e4f237da KB |
6931 | |
6932 | bp_watchpoint | |
2d134ed3 PA |
6933 | bp_catchpoint |
6934 | ||
6935 | */ | |
e4f237da KB |
6936 | |
6937 | static int | |
6938 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6939 | { | |
6940 | enum bptype type = bpt->type; | |
6941 | ||
2d134ed3 PA |
6942 | return (type != bp_watchpoint && type != bp_catchpoint); |
6943 | } | |
6944 | ||
6945 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6946 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6947 | ||
6948 | static int | |
4a64f543 MS |
6949 | watchpoint_locations_match (struct bp_location *loc1, |
6950 | struct bp_location *loc2) | |
2d134ed3 | 6951 | { |
3a5c3e22 PA |
6952 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6953 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6954 | ||
6955 | /* Both of them must exist. */ | |
6956 | gdb_assert (w1 != NULL); | |
6957 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6958 | |
4a64f543 MS |
6959 | /* If the target can evaluate the condition expression in hardware, |
6960 | then we we need to insert both watchpoints even if they are at | |
6961 | the same place. Otherwise the watchpoint will only trigger when | |
6962 | the condition of whichever watchpoint was inserted evaluates to | |
6963 | true, not giving a chance for GDB to check the condition of the | |
6964 | other watchpoint. */ | |
3a5c3e22 | 6965 | if ((w1->cond_exp |
4a64f543 MS |
6966 | && target_can_accel_watchpoint_condition (loc1->address, |
6967 | loc1->length, | |
0cf6dd15 | 6968 | loc1->watchpoint_type, |
3a5c3e22 PA |
6969 | w1->cond_exp)) |
6970 | || (w2->cond_exp | |
4a64f543 MS |
6971 | && target_can_accel_watchpoint_condition (loc2->address, |
6972 | loc2->length, | |
0cf6dd15 | 6973 | loc2->watchpoint_type, |
3a5c3e22 | 6974 | w2->cond_exp))) |
0cf6dd15 TJB |
6975 | return 0; |
6976 | ||
85d721b8 PA |
6977 | /* Note that this checks the owner's type, not the location's. In |
6978 | case the target does not support read watchpoints, but does | |
6979 | support access watchpoints, we'll have bp_read_watchpoint | |
6980 | watchpoints with hw_access locations. Those should be considered | |
6981 | duplicates of hw_read locations. The hw_read locations will | |
6982 | become hw_access locations later. */ | |
2d134ed3 PA |
6983 | return (loc1->owner->type == loc2->owner->type |
6984 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6985 | && loc1->address == loc2->address | |
6986 | && loc1->length == loc2->length); | |
e4f237da KB |
6987 | } |
6988 | ||
31e77af2 | 6989 | /* See breakpoint.h. */ |
6c95b8df | 6990 | |
31e77af2 | 6991 | int |
6c95b8df PA |
6992 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6993 | struct address_space *aspace2, CORE_ADDR addr2) | |
6994 | { | |
f5656ead | 6995 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6996 | || aspace1 == aspace2) |
6997 | && addr1 == addr2); | |
6998 | } | |
6999 | ||
f1310107 TJB |
7000 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7001 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7002 | matches ASPACE2. On targets that have global breakpoints, the address | |
7003 | space doesn't really matter. */ | |
7004 | ||
7005 | static int | |
7006 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7007 | int len1, struct address_space *aspace2, | |
7008 | CORE_ADDR addr2) | |
7009 | { | |
f5656ead | 7010 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7011 | || aspace1 == aspace2) |
7012 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7013 | } | |
7014 | ||
7015 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7016 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7017 | matches the breakpoint's address space. On targets that have global | |
7018 | breakpoints, the address space doesn't really matter. */ | |
7019 | ||
7020 | static int | |
7021 | breakpoint_location_address_match (struct bp_location *bl, | |
7022 | struct address_space *aspace, | |
7023 | CORE_ADDR addr) | |
7024 | { | |
7025 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7026 | aspace, addr) | |
7027 | || (bl->length | |
7028 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7029 | bl->address, bl->length, | |
7030 | aspace, addr))); | |
7031 | } | |
7032 | ||
1e4d1764 YQ |
7033 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7034 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7035 | true, otherwise returns false. */ | |
7036 | ||
7037 | static int | |
7038 | tracepoint_locations_match (struct bp_location *loc1, | |
7039 | struct bp_location *loc2) | |
7040 | { | |
7041 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7042 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7043 | locations at the same address of different tracepoints are regarded as | |
7044 | different locations. */ | |
7045 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7046 | else | |
7047 | return 0; | |
7048 | } | |
7049 | ||
2d134ed3 PA |
7050 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7051 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7052 | represent the same location. */ | |
7053 | ||
7054 | static int | |
4a64f543 MS |
7055 | breakpoint_locations_match (struct bp_location *loc1, |
7056 | struct bp_location *loc2) | |
2d134ed3 | 7057 | { |
2bdf28a0 JK |
7058 | int hw_point1, hw_point2; |
7059 | ||
7060 | /* Both of them must not be in moribund_locations. */ | |
7061 | gdb_assert (loc1->owner != NULL); | |
7062 | gdb_assert (loc2->owner != NULL); | |
7063 | ||
7064 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7065 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7066 | |
7067 | if (hw_point1 != hw_point2) | |
7068 | return 0; | |
7069 | else if (hw_point1) | |
7070 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7071 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7072 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7073 | else |
f1310107 TJB |
7074 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7075 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7076 | loc2->pspace->aspace, loc2->address) | |
7077 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7078 | } |
7079 | ||
76897487 KB |
7080 | static void |
7081 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7082 | int bnum, int have_bnum) | |
7083 | { | |
f63fbe86 MS |
7084 | /* The longest string possibly returned by hex_string_custom |
7085 | is 50 chars. These must be at least that big for safety. */ | |
7086 | char astr1[64]; | |
7087 | char astr2[64]; | |
76897487 | 7088 | |
bb599908 PH |
7089 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7090 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7091 | if (have_bnum) |
8a3fe4f8 | 7092 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7093 | bnum, astr1, astr2); |
7094 | else | |
8a3fe4f8 | 7095 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7096 | } |
7097 | ||
4a64f543 MS |
7098 | /* Adjust a breakpoint's address to account for architectural |
7099 | constraints on breakpoint placement. Return the adjusted address. | |
7100 | Note: Very few targets require this kind of adjustment. For most | |
7101 | targets, this function is simply the identity function. */ | |
76897487 KB |
7102 | |
7103 | static CORE_ADDR | |
a6d9a66e UW |
7104 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7105 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7106 | { |
a6d9a66e | 7107 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7108 | { |
7109 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7110 | return bpaddr; | |
7111 | } | |
88f7da05 KB |
7112 | else if (bptype == bp_watchpoint |
7113 | || bptype == bp_hardware_watchpoint | |
7114 | || bptype == bp_read_watchpoint | |
7115 | || bptype == bp_access_watchpoint | |
fe798b75 | 7116 | || bptype == bp_catchpoint) |
88f7da05 KB |
7117 | { |
7118 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7119 | have their addresses modified. */ | |
7120 | return bpaddr; | |
7121 | } | |
7c16b83e PA |
7122 | else if (bptype == bp_single_step) |
7123 | { | |
7124 | /* Single-step breakpoints should not have their addresses | |
7125 | modified. If there's any architectural constrain that | |
7126 | applies to this address, then it should have already been | |
7127 | taken into account when the breakpoint was created in the | |
7128 | first place. If we didn't do this, stepping through e.g., | |
7129 | Thumb-2 IT blocks would break. */ | |
7130 | return bpaddr; | |
7131 | } | |
76897487 KB |
7132 | else |
7133 | { | |
7134 | CORE_ADDR adjusted_bpaddr; | |
7135 | ||
7136 | /* Some targets have architectural constraints on the placement | |
7137 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7138 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7139 | |
7140 | /* An adjusted breakpoint address can significantly alter | |
7141 | a user's expectations. Print a warning if an adjustment | |
7142 | is required. */ | |
7143 | if (adjusted_bpaddr != bpaddr) | |
7144 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7145 | ||
7146 | return adjusted_bpaddr; | |
7147 | } | |
7148 | } | |
7149 | ||
28010a5d PA |
7150 | void |
7151 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7152 | struct breakpoint *owner) | |
7cc221ef | 7153 | { |
7cc221ef DJ |
7154 | memset (loc, 0, sizeof (*loc)); |
7155 | ||
348d480f PA |
7156 | gdb_assert (ops != NULL); |
7157 | ||
28010a5d PA |
7158 | loc->ops = ops; |
7159 | loc->owner = owner; | |
511a6cd4 | 7160 | loc->cond = NULL; |
b775012e | 7161 | loc->cond_bytecode = NULL; |
0d381245 VP |
7162 | loc->shlib_disabled = 0; |
7163 | loc->enabled = 1; | |
e049a4b5 | 7164 | |
28010a5d | 7165 | switch (owner->type) |
e049a4b5 DJ |
7166 | { |
7167 | case bp_breakpoint: | |
7c16b83e | 7168 | case bp_single_step: |
e049a4b5 DJ |
7169 | case bp_until: |
7170 | case bp_finish: | |
7171 | case bp_longjmp: | |
7172 | case bp_longjmp_resume: | |
e2e4d78b | 7173 | case bp_longjmp_call_dummy: |
186c406b TT |
7174 | case bp_exception: |
7175 | case bp_exception_resume: | |
e049a4b5 | 7176 | case bp_step_resume: |
2c03e5be | 7177 | case bp_hp_step_resume: |
e049a4b5 DJ |
7178 | case bp_watchpoint_scope: |
7179 | case bp_call_dummy: | |
aa7d318d | 7180 | case bp_std_terminate: |
e049a4b5 DJ |
7181 | case bp_shlib_event: |
7182 | case bp_thread_event: | |
7183 | case bp_overlay_event: | |
4efc6507 | 7184 | case bp_jit_event: |
0fd8e87f | 7185 | case bp_longjmp_master: |
aa7d318d | 7186 | case bp_std_terminate_master: |
186c406b | 7187 | case bp_exception_master: |
0e30163f JK |
7188 | case bp_gnu_ifunc_resolver: |
7189 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7190 | case bp_dprintf: |
e049a4b5 | 7191 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7192 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7193 | break; |
7194 | case bp_hardware_breakpoint: | |
7195 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7196 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7197 | break; |
7198 | case bp_hardware_watchpoint: | |
7199 | case bp_read_watchpoint: | |
7200 | case bp_access_watchpoint: | |
7201 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7202 | break; | |
7203 | case bp_watchpoint: | |
ce78b96d | 7204 | case bp_catchpoint: |
15c3d785 PA |
7205 | case bp_tracepoint: |
7206 | case bp_fast_tracepoint: | |
0fb4aa4b | 7207 | case bp_static_tracepoint: |
e049a4b5 DJ |
7208 | loc->loc_type = bp_loc_other; |
7209 | break; | |
7210 | default: | |
e2e0b3e5 | 7211 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7212 | } |
7213 | ||
f431efe5 | 7214 | loc->refc = 1; |
28010a5d PA |
7215 | } |
7216 | ||
7217 | /* Allocate a struct bp_location. */ | |
7218 | ||
7219 | static struct bp_location * | |
7220 | allocate_bp_location (struct breakpoint *bpt) | |
7221 | { | |
348d480f PA |
7222 | return bpt->ops->allocate_location (bpt); |
7223 | } | |
7cc221ef | 7224 | |
f431efe5 PA |
7225 | static void |
7226 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7227 | { |
348d480f | 7228 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7229 | xfree (loc); |
7230 | } | |
7231 | ||
f431efe5 PA |
7232 | /* Increment reference count. */ |
7233 | ||
7234 | static void | |
7235 | incref_bp_location (struct bp_location *bl) | |
7236 | { | |
7237 | ++bl->refc; | |
7238 | } | |
7239 | ||
7240 | /* Decrement reference count. If the reference count reaches 0, | |
7241 | destroy the bp_location. Sets *BLP to NULL. */ | |
7242 | ||
7243 | static void | |
7244 | decref_bp_location (struct bp_location **blp) | |
7245 | { | |
0807b50c PA |
7246 | gdb_assert ((*blp)->refc > 0); |
7247 | ||
f431efe5 PA |
7248 | if (--(*blp)->refc == 0) |
7249 | free_bp_location (*blp); | |
7250 | *blp = NULL; | |
7251 | } | |
7252 | ||
346774a9 | 7253 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7254 | |
346774a9 PA |
7255 | static void |
7256 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7257 | { |
346774a9 | 7258 | struct breakpoint *b1; |
c906108c | 7259 | |
346774a9 PA |
7260 | /* Add this breakpoint to the end of the chain so that a list of |
7261 | breakpoints will come out in order of increasing numbers. */ | |
7262 | ||
7263 | b1 = breakpoint_chain; | |
7264 | if (b1 == 0) | |
7265 | breakpoint_chain = b; | |
7266 | else | |
7267 | { | |
7268 | while (b1->next) | |
7269 | b1 = b1->next; | |
7270 | b1->next = b; | |
7271 | } | |
7272 | } | |
7273 | ||
7274 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7275 | ||
7276 | static void | |
7277 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7278 | struct gdbarch *gdbarch, | |
28010a5d | 7279 | enum bptype bptype, |
c0a91b2b | 7280 | const struct breakpoint_ops *ops) |
346774a9 | 7281 | { |
c906108c | 7282 | memset (b, 0, sizeof (*b)); |
2219d63c | 7283 | |
348d480f PA |
7284 | gdb_assert (ops != NULL); |
7285 | ||
28010a5d | 7286 | b->ops = ops; |
4d28f7a8 | 7287 | b->type = bptype; |
a6d9a66e | 7288 | b->gdbarch = gdbarch; |
c906108c SS |
7289 | b->language = current_language->la_language; |
7290 | b->input_radix = input_radix; | |
7291 | b->thread = -1; | |
b5de0fa7 | 7292 | b->enable_state = bp_enabled; |
c906108c SS |
7293 | b->next = 0; |
7294 | b->silent = 0; | |
7295 | b->ignore_count = 0; | |
7296 | b->commands = NULL; | |
818dd999 | 7297 | b->frame_id = null_frame_id; |
0d381245 | 7298 | b->condition_not_parsed = 0; |
84f4c1fe | 7299 | b->py_bp_object = NULL; |
d0fb5eae | 7300 | b->related_breakpoint = b; |
346774a9 PA |
7301 | } |
7302 | ||
7303 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7304 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7305 | |
7306 | static struct breakpoint * | |
7307 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7308 | enum bptype bptype, |
c0a91b2b | 7309 | const struct breakpoint_ops *ops) |
346774a9 PA |
7310 | { |
7311 | struct breakpoint *b = XNEW (struct breakpoint); | |
7312 | ||
348d480f | 7313 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7314 | add_to_breakpoint_chain (b); |
0d381245 VP |
7315 | return b; |
7316 | } | |
7317 | ||
0e30163f JK |
7318 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7319 | resolutions should be made as the user specified the location explicitly | |
7320 | enough. */ | |
7321 | ||
0d381245 | 7322 | static void |
0e30163f | 7323 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7324 | { |
2bdf28a0 JK |
7325 | gdb_assert (loc->owner != NULL); |
7326 | ||
0d381245 | 7327 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7328 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7329 | || is_tracepoint (loc->owner)) |
0d381245 | 7330 | { |
0e30163f | 7331 | int is_gnu_ifunc; |
2c02bd72 | 7332 | const char *function_name; |
6a3a010b | 7333 | CORE_ADDR func_addr; |
0e30163f | 7334 | |
2c02bd72 | 7335 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7336 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7337 | |
7338 | if (is_gnu_ifunc && !explicit_loc) | |
7339 | { | |
7340 | struct breakpoint *b = loc->owner; | |
7341 | ||
7342 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7343 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7344 | &loc->requested_address)) |
7345 | { | |
7346 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7347 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7348 | loc->requested_address, | |
7349 | b->type); | |
7350 | } | |
7351 | else if (b->type == bp_breakpoint && b->loc == loc | |
7352 | && loc->next == NULL && b->related_breakpoint == b) | |
7353 | { | |
7354 | /* Create only the whole new breakpoint of this type but do not | |
7355 | mess more complicated breakpoints with multiple locations. */ | |
7356 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7357 | /* Remember the resolver's address for use by the return |
7358 | breakpoint. */ | |
7359 | loc->related_address = func_addr; | |
0e30163f JK |
7360 | } |
7361 | } | |
7362 | ||
2c02bd72 DE |
7363 | if (function_name) |
7364 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7365 | } |
7366 | } | |
7367 | ||
a6d9a66e | 7368 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7369 | struct gdbarch * |
a6d9a66e UW |
7370 | get_sal_arch (struct symtab_and_line sal) |
7371 | { | |
7372 | if (sal.section) | |
7373 | return get_objfile_arch (sal.section->objfile); | |
7374 | if (sal.symtab) | |
eb822aa6 | 7375 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7376 | |
7377 | return NULL; | |
7378 | } | |
7379 | ||
346774a9 PA |
7380 | /* Low level routine for partially initializing a breakpoint of type |
7381 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7382 | file name, and line number are provided by SAL. |
0d381245 VP |
7383 | |
7384 | It is expected that the caller will complete the initialization of | |
7385 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7386 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7387 | |
346774a9 PA |
7388 | static void |
7389 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7390 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7391 | const struct breakpoint_ops *ops) |
0d381245 | 7392 | { |
28010a5d | 7393 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7394 | |
3742cc8b | 7395 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7396 | |
6c95b8df PA |
7397 | if (bptype != bp_catchpoint) |
7398 | gdb_assert (sal.pspace != NULL); | |
7399 | ||
f8eba3c6 TT |
7400 | /* Store the program space that was used to set the breakpoint, |
7401 | except for ordinary breakpoints, which are independent of the | |
7402 | program space. */ | |
7403 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7404 | b->pspace = sal.pspace; | |
346774a9 | 7405 | } |
c906108c | 7406 | |
346774a9 PA |
7407 | /* set_raw_breakpoint is a low level routine for allocating and |
7408 | partially initializing a breakpoint of type BPTYPE. The newly | |
7409 | created breakpoint's address, section, source file name, and line | |
7410 | number are provided by SAL. The newly created and partially | |
7411 | initialized breakpoint is added to the breakpoint chain and | |
7412 | is also returned as the value of this function. | |
7413 | ||
7414 | It is expected that the caller will complete the initialization of | |
7415 | the newly created breakpoint struct as well as output any status | |
7416 | information regarding the creation of a new breakpoint. In | |
7417 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7418 | number! Care should be taken to not allow an error to occur | |
7419 | prior to completing the initialization of the breakpoint. If this | |
7420 | should happen, a bogus breakpoint will be left on the chain. */ | |
7421 | ||
7422 | struct breakpoint * | |
7423 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7424 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7425 | const struct breakpoint_ops *ops) |
346774a9 PA |
7426 | { |
7427 | struct breakpoint *b = XNEW (struct breakpoint); | |
7428 | ||
348d480f | 7429 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7430 | add_to_breakpoint_chain (b); |
c906108c SS |
7431 | return b; |
7432 | } | |
7433 | ||
53a5351d | 7434 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7435 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7436 | initiated the operation. */ | |
c906108c SS |
7437 | |
7438 | void | |
186c406b | 7439 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7440 | { |
35df4500 | 7441 | struct breakpoint *b, *b_tmp; |
186c406b | 7442 | int thread = tp->num; |
0fd8e87f UW |
7443 | |
7444 | /* To avoid having to rescan all objfile symbols at every step, | |
7445 | we maintain a list of continually-inserted but always disabled | |
7446 | longjmp "master" breakpoints. Here, we simply create momentary | |
7447 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7448 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7449 | if (b->pspace == current_program_space |
186c406b TT |
7450 | && (b->type == bp_longjmp_master |
7451 | || b->type == bp_exception_master)) | |
0fd8e87f | 7452 | { |
06edf0c0 PA |
7453 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7454 | struct breakpoint *clone; | |
cc59ec59 | 7455 | |
e2e4d78b JK |
7456 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7457 | after their removal. */ | |
06edf0c0 | 7458 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7459 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7460 | clone->thread = thread; |
7461 | } | |
186c406b TT |
7462 | |
7463 | tp->initiating_frame = frame; | |
c906108c SS |
7464 | } |
7465 | ||
611c83ae | 7466 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7467 | void |
611c83ae | 7468 | delete_longjmp_breakpoint (int thread) |
c906108c | 7469 | { |
35df4500 | 7470 | struct breakpoint *b, *b_tmp; |
c906108c | 7471 | |
35df4500 | 7472 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7473 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7474 | { |
7475 | if (b->thread == thread) | |
7476 | delete_breakpoint (b); | |
7477 | } | |
c906108c SS |
7478 | } |
7479 | ||
f59f708a PA |
7480 | void |
7481 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7482 | { | |
7483 | struct breakpoint *b, *b_tmp; | |
7484 | ||
7485 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7486 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7487 | { | |
7488 | if (b->thread == thread) | |
7489 | b->disposition = disp_del_at_next_stop; | |
7490 | } | |
7491 | } | |
7492 | ||
e2e4d78b JK |
7493 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7494 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7495 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7496 | breakpoints. */ | |
7497 | ||
7498 | struct breakpoint * | |
7499 | set_longjmp_breakpoint_for_call_dummy (void) | |
7500 | { | |
7501 | struct breakpoint *b, *retval = NULL; | |
7502 | ||
7503 | ALL_BREAKPOINTS (b) | |
7504 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7505 | { | |
7506 | struct breakpoint *new_b; | |
7507 | ||
7508 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7509 | &momentary_breakpoint_ops, |
7510 | 1); | |
e2e4d78b JK |
7511 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7512 | ||
7513 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7514 | ||
7515 | gdb_assert (new_b->related_breakpoint == new_b); | |
7516 | if (retval == NULL) | |
7517 | retval = new_b; | |
7518 | new_b->related_breakpoint = retval; | |
7519 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7520 | retval = retval->related_breakpoint; | |
7521 | retval->related_breakpoint = new_b; | |
7522 | } | |
7523 | ||
7524 | return retval; | |
7525 | } | |
7526 | ||
7527 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7528 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7529 | stack. |
7530 | ||
7531 | You should call this function only at places where it is safe to currently | |
7532 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7533 | frames. */ | |
7534 | ||
7535 | void | |
b67a2c6f | 7536 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7537 | { |
7538 | struct breakpoint *b, *b_tmp; | |
7539 | ||
7540 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7541 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7542 | { |
7543 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7544 | ||
7545 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7546 | dummy_b = dummy_b->related_breakpoint; | |
7547 | if (dummy_b->type != bp_call_dummy | |
7548 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7549 | continue; | |
7550 | ||
b67a2c6f | 7551 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7552 | |
7553 | while (b->related_breakpoint != b) | |
7554 | { | |
7555 | if (b_tmp == b->related_breakpoint) | |
7556 | b_tmp = b->related_breakpoint->next; | |
7557 | delete_breakpoint (b->related_breakpoint); | |
7558 | } | |
7559 | delete_breakpoint (b); | |
7560 | } | |
7561 | } | |
7562 | ||
1900040c MS |
7563 | void |
7564 | enable_overlay_breakpoints (void) | |
7565 | { | |
52f0bd74 | 7566 | struct breakpoint *b; |
1900040c MS |
7567 | |
7568 | ALL_BREAKPOINTS (b) | |
7569 | if (b->type == bp_overlay_event) | |
7570 | { | |
7571 | b->enable_state = bp_enabled; | |
44702360 | 7572 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7573 | overlay_events_enabled = 1; |
1900040c MS |
7574 | } |
7575 | } | |
7576 | ||
7577 | void | |
7578 | disable_overlay_breakpoints (void) | |
7579 | { | |
52f0bd74 | 7580 | struct breakpoint *b; |
1900040c MS |
7581 | |
7582 | ALL_BREAKPOINTS (b) | |
7583 | if (b->type == bp_overlay_event) | |
7584 | { | |
7585 | b->enable_state = bp_disabled; | |
44702360 | 7586 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7587 | overlay_events_enabled = 0; |
1900040c MS |
7588 | } |
7589 | } | |
7590 | ||
aa7d318d TT |
7591 | /* Set an active std::terminate breakpoint for each std::terminate |
7592 | master breakpoint. */ | |
7593 | void | |
7594 | set_std_terminate_breakpoint (void) | |
7595 | { | |
35df4500 | 7596 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7597 | |
35df4500 | 7598 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7599 | if (b->pspace == current_program_space |
7600 | && b->type == bp_std_terminate_master) | |
7601 | { | |
06edf0c0 | 7602 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7603 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7604 | } |
7605 | } | |
7606 | ||
7607 | /* Delete all the std::terminate breakpoints. */ | |
7608 | void | |
7609 | delete_std_terminate_breakpoint (void) | |
7610 | { | |
35df4500 | 7611 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7612 | |
35df4500 | 7613 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7614 | if (b->type == bp_std_terminate) |
7615 | delete_breakpoint (b); | |
7616 | } | |
7617 | ||
c4093a6a | 7618 | struct breakpoint * |
a6d9a66e | 7619 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7620 | { |
7621 | struct breakpoint *b; | |
c4093a6a | 7622 | |
06edf0c0 PA |
7623 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7624 | &internal_breakpoint_ops); | |
7625 | ||
b5de0fa7 | 7626 | b->enable_state = bp_enabled; |
c4093a6a | 7627 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7628 | b->addr_string |
7629 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7630 | |
44702360 | 7631 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7632 | |
c4093a6a JM |
7633 | return b; |
7634 | } | |
7635 | ||
7636 | void | |
7637 | remove_thread_event_breakpoints (void) | |
7638 | { | |
35df4500 | 7639 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7640 | |
35df4500 | 7641 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7642 | if (b->type == bp_thread_event |
7643 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7644 | delete_breakpoint (b); |
7645 | } | |
7646 | ||
0101ce28 JJ |
7647 | struct lang_and_radix |
7648 | { | |
7649 | enum language lang; | |
7650 | int radix; | |
7651 | }; | |
7652 | ||
4efc6507 DE |
7653 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7654 | ||
7655 | struct breakpoint * | |
7656 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7657 | { | |
7658 | struct breakpoint *b; | |
7659 | ||
06edf0c0 PA |
7660 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7661 | &internal_breakpoint_ops); | |
44702360 | 7662 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7663 | return b; |
7664 | } | |
0101ce28 | 7665 | |
03673fc7 PP |
7666 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7667 | ||
7668 | void | |
7669 | remove_jit_event_breakpoints (void) | |
7670 | { | |
7671 | struct breakpoint *b, *b_tmp; | |
7672 | ||
7673 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7674 | if (b->type == bp_jit_event | |
7675 | && b->loc->pspace == current_program_space) | |
7676 | delete_breakpoint (b); | |
7677 | } | |
7678 | ||
cae688ec JJ |
7679 | void |
7680 | remove_solib_event_breakpoints (void) | |
7681 | { | |
35df4500 | 7682 | struct breakpoint *b, *b_tmp; |
cae688ec | 7683 | |
35df4500 | 7684 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7685 | if (b->type == bp_shlib_event |
7686 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7687 | delete_breakpoint (b); |
7688 | } | |
7689 | ||
f37f681c PA |
7690 | /* See breakpoint.h. */ |
7691 | ||
7692 | void | |
7693 | remove_solib_event_breakpoints_at_next_stop (void) | |
7694 | { | |
7695 | struct breakpoint *b, *b_tmp; | |
7696 | ||
7697 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7698 | if (b->type == bp_shlib_event | |
7699 | && b->loc->pspace == current_program_space) | |
7700 | b->disposition = disp_del_at_next_stop; | |
7701 | } | |
7702 | ||
04086b45 PA |
7703 | /* Helper for create_solib_event_breakpoint / |
7704 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7705 | INSERT_MODE to pass through to update_global_location_list. */ | |
7706 | ||
7707 | static struct breakpoint * | |
7708 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7709 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7710 | { |
7711 | struct breakpoint *b; | |
7712 | ||
06edf0c0 PA |
7713 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7714 | &internal_breakpoint_ops); | |
04086b45 | 7715 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7716 | return b; |
7717 | } | |
7718 | ||
04086b45 PA |
7719 | struct breakpoint * |
7720 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7721 | { | |
7722 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7723 | } | |
7724 | ||
f37f681c PA |
7725 | /* See breakpoint.h. */ |
7726 | ||
7727 | struct breakpoint * | |
7728 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7729 | { | |
7730 | struct breakpoint *b; | |
7731 | ||
04086b45 PA |
7732 | /* Explicitly tell update_global_location_list to insert |
7733 | locations. */ | |
7734 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7735 | if (!b->loc->inserted) |
7736 | { | |
7737 | delete_breakpoint (b); | |
7738 | return NULL; | |
7739 | } | |
7740 | return b; | |
7741 | } | |
7742 | ||
cae688ec JJ |
7743 | /* Disable any breakpoints that are on code in shared libraries. Only |
7744 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7745 | ||
7746 | void | |
cb851954 | 7747 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7748 | { |
876fa593 | 7749 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7750 | |
876fa593 | 7751 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7752 | { |
2bdf28a0 | 7753 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7754 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7755 | |
4a64f543 MS |
7756 | /* We apply the check to all breakpoints, including disabled for |
7757 | those with loc->duplicate set. This is so that when breakpoint | |
7758 | becomes enabled, or the duplicate is removed, gdb will try to | |
7759 | insert all breakpoints. If we don't set shlib_disabled here, | |
7760 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7761 | if (((b->type == bp_breakpoint) |
508ccb1f | 7762 | || (b->type == bp_jit_event) |
1042e4c0 | 7763 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7764 | || (is_tracepoint (b))) |
6c95b8df | 7765 | && loc->pspace == current_program_space |
0d381245 | 7766 | && !loc->shlib_disabled |
6c95b8df | 7767 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7768 | ) |
0d381245 VP |
7769 | { |
7770 | loc->shlib_disabled = 1; | |
7771 | } | |
cae688ec JJ |
7772 | } |
7773 | } | |
7774 | ||
63644780 NB |
7775 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7776 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7777 | disabled ones can just stay disabled. */ | |
84acb35a | 7778 | |
75149521 | 7779 | static void |
84acb35a JJ |
7780 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7781 | { | |
876fa593 | 7782 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7783 | int disabled_shlib_breaks = 0; |
7784 | ||
c86cf029 VP |
7785 | /* SunOS a.out shared libraries are always mapped, so do not |
7786 | disable breakpoints; they will only be reported as unloaded | |
7787 | through clear_solib when GDB discards its shared library | |
7788 | list. See clear_solib for more information. */ | |
7789 | if (exec_bfd != NULL | |
7790 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7791 | return; | |
7792 | ||
876fa593 | 7793 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7794 | { |
2bdf28a0 | 7795 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7796 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7797 | |
1e4d1764 | 7798 | if (solib->pspace == loc->pspace |
e2dd7057 | 7799 | && !loc->shlib_disabled |
1e4d1764 YQ |
7800 | && (((b->type == bp_breakpoint |
7801 | || b->type == bp_jit_event | |
7802 | || b->type == bp_hardware_breakpoint) | |
7803 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7804 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7805 | || is_tracepoint (b)) | |
e2dd7057 | 7806 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7807 | { |
e2dd7057 PP |
7808 | loc->shlib_disabled = 1; |
7809 | /* At this point, we cannot rely on remove_breakpoint | |
7810 | succeeding so we must mark the breakpoint as not inserted | |
7811 | to prevent future errors occurring in remove_breakpoints. */ | |
7812 | loc->inserted = 0; | |
8d3788bd VP |
7813 | |
7814 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7815 | observer_notify_breakpoint_modified (b); | |
7816 | ||
e2dd7057 PP |
7817 | if (!disabled_shlib_breaks) |
7818 | { | |
7819 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7820 | warning (_("Temporarily disabling breakpoints " |
7821 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7822 | solib->so_name); |
84acb35a | 7823 | } |
e2dd7057 | 7824 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7825 | } |
7826 | } | |
84acb35a JJ |
7827 | } |
7828 | ||
63644780 NB |
7829 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7830 | notification of free_objfile. Only apply to enabled breakpoints, | |
7831 | disabled ones can just stay disabled. */ | |
7832 | ||
7833 | static void | |
7834 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7835 | { | |
7836 | struct breakpoint *b; | |
7837 | ||
7838 | if (objfile == NULL) | |
7839 | return; | |
7840 | ||
d03de421 PA |
7841 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7842 | managed by the user with add-symbol-file/remove-symbol-file. | |
7843 | Similarly to how breakpoints in shared libraries are handled in | |
7844 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7845 | shlib_disabled so they end up uninserted on the next global |
7846 | location list update. Shared libraries not loaded by the user | |
7847 | aren't handled here -- they're already handled in | |
7848 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7849 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7850 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7851 | main objfile). */ | |
7852 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7853 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7854 | return; |
7855 | ||
7856 | ALL_BREAKPOINTS (b) | |
7857 | { | |
7858 | struct bp_location *loc; | |
7859 | int bp_modified = 0; | |
7860 | ||
7861 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7862 | continue; | |
7863 | ||
7864 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7865 | { | |
7866 | CORE_ADDR loc_addr = loc->address; | |
7867 | ||
7868 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7869 | && loc->loc_type != bp_loc_software_breakpoint) | |
7870 | continue; | |
7871 | ||
7872 | if (loc->shlib_disabled != 0) | |
7873 | continue; | |
7874 | ||
7875 | if (objfile->pspace != loc->pspace) | |
7876 | continue; | |
7877 | ||
7878 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7879 | && loc->loc_type != bp_loc_software_breakpoint) | |
7880 | continue; | |
7881 | ||
7882 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7883 | { | |
7884 | loc->shlib_disabled = 1; | |
08351840 PA |
7885 | /* At this point, we don't know whether the object was |
7886 | unmapped from the inferior or not, so leave the | |
7887 | inserted flag alone. We'll handle failure to | |
7888 | uninsert quietly, in case the object was indeed | |
7889 | unmapped. */ | |
63644780 NB |
7890 | |
7891 | mark_breakpoint_location_modified (loc); | |
7892 | ||
7893 | bp_modified = 1; | |
7894 | } | |
7895 | } | |
7896 | ||
7897 | if (bp_modified) | |
7898 | observer_notify_breakpoint_modified (b); | |
7899 | } | |
7900 | } | |
7901 | ||
ce78b96d JB |
7902 | /* FORK & VFORK catchpoints. */ |
7903 | ||
e29a4733 PA |
7904 | /* An instance of this type is used to represent a fork or vfork |
7905 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7906 | class; users downcast to "struct breakpoint *" when needed. A | |
7907 | breakpoint is really of this type iff its ops pointer points to | |
7908 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7909 | ||
7910 | struct fork_catchpoint | |
7911 | { | |
7912 | /* The base class. */ | |
7913 | struct breakpoint base; | |
7914 | ||
7915 | /* Process id of a child process whose forking triggered this | |
7916 | catchpoint. This field is only valid immediately after this | |
7917 | catchpoint has triggered. */ | |
7918 | ptid_t forked_inferior_pid; | |
7919 | }; | |
7920 | ||
4a64f543 MS |
7921 | /* Implement the "insert" breakpoint_ops method for fork |
7922 | catchpoints. */ | |
ce78b96d | 7923 | |
77b06cd7 TJB |
7924 | static int |
7925 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7926 | { |
dfd4cc63 | 7927 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7928 | } |
7929 | ||
4a64f543 MS |
7930 | /* Implement the "remove" breakpoint_ops method for fork |
7931 | catchpoints. */ | |
ce78b96d JB |
7932 | |
7933 | static int | |
77b06cd7 | 7934 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7935 | { |
dfd4cc63 | 7936 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7937 | } |
7938 | ||
7939 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7940 | catchpoints. */ | |
7941 | ||
7942 | static int | |
f1310107 | 7943 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7944 | struct address_space *aspace, CORE_ADDR bp_addr, |
7945 | const struct target_waitstatus *ws) | |
ce78b96d | 7946 | { |
e29a4733 PA |
7947 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7948 | ||
f90263c1 TT |
7949 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7950 | return 0; | |
7951 | ||
7952 | c->forked_inferior_pid = ws->value.related_pid; | |
7953 | return 1; | |
ce78b96d JB |
7954 | } |
7955 | ||
4a64f543 MS |
7956 | /* Implement the "print_it" breakpoint_ops method for fork |
7957 | catchpoints. */ | |
ce78b96d JB |
7958 | |
7959 | static enum print_stop_action | |
348d480f | 7960 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7961 | { |
36dfb11c | 7962 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7963 | struct breakpoint *b = bs->breakpoint_at; |
7964 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7965 | |
ce78b96d | 7966 | annotate_catchpoint (b->number); |
36dfb11c TT |
7967 | if (b->disposition == disp_del) |
7968 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7969 | else | |
7970 | ui_out_text (uiout, "\nCatchpoint "); | |
7971 | if (ui_out_is_mi_like_p (uiout)) | |
7972 | { | |
7973 | ui_out_field_string (uiout, "reason", | |
7974 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7975 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7976 | } | |
7977 | ui_out_field_int (uiout, "bkptno", b->number); | |
7978 | ui_out_text (uiout, " (forked process "); | |
7979 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7980 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7981 | return PRINT_SRC_AND_LOC; |
7982 | } | |
7983 | ||
4a64f543 MS |
7984 | /* Implement the "print_one" breakpoint_ops method for fork |
7985 | catchpoints. */ | |
ce78b96d JB |
7986 | |
7987 | static void | |
a6d9a66e | 7988 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7989 | { |
e29a4733 | 7990 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7991 | struct value_print_options opts; |
79a45e25 | 7992 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7993 | |
7994 | get_user_print_options (&opts); | |
7995 | ||
4a64f543 MS |
7996 | /* Field 4, the address, is omitted (which makes the columns not |
7997 | line up too nicely with the headers, but the effect is relatively | |
7998 | readable). */ | |
79a45b7d | 7999 | if (opts.addressprint) |
ce78b96d JB |
8000 | ui_out_field_skip (uiout, "addr"); |
8001 | annotate_field (5); | |
8002 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8003 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8004 | { |
8005 | ui_out_text (uiout, ", process "); | |
8006 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8007 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8008 | ui_out_spaces (uiout, 1); |
8009 | } | |
8ac3646f TT |
8010 | |
8011 | if (ui_out_is_mi_like_p (uiout)) | |
8012 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8013 | } |
8014 | ||
8015 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8016 | catchpoints. */ | |
8017 | ||
8018 | static void | |
8019 | print_mention_catch_fork (struct breakpoint *b) | |
8020 | { | |
8021 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8022 | } | |
8023 | ||
6149aea9 PA |
8024 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8025 | catchpoints. */ | |
8026 | ||
8027 | static void | |
8028 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8029 | { | |
8030 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8031 | print_recreate_thread (b, fp); |
6149aea9 PA |
8032 | } |
8033 | ||
ce78b96d JB |
8034 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8035 | ||
2060206e | 8036 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8037 | |
4a64f543 MS |
8038 | /* Implement the "insert" breakpoint_ops method for vfork |
8039 | catchpoints. */ | |
ce78b96d | 8040 | |
77b06cd7 TJB |
8041 | static int |
8042 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8043 | { |
dfd4cc63 | 8044 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8045 | } |
8046 | ||
4a64f543 MS |
8047 | /* Implement the "remove" breakpoint_ops method for vfork |
8048 | catchpoints. */ | |
ce78b96d JB |
8049 | |
8050 | static int | |
77b06cd7 | 8051 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8052 | { |
dfd4cc63 | 8053 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8054 | } |
8055 | ||
8056 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8057 | catchpoints. */ | |
8058 | ||
8059 | static int | |
f1310107 | 8060 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8061 | struct address_space *aspace, CORE_ADDR bp_addr, |
8062 | const struct target_waitstatus *ws) | |
ce78b96d | 8063 | { |
e29a4733 PA |
8064 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8065 | ||
f90263c1 TT |
8066 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8067 | return 0; | |
8068 | ||
8069 | c->forked_inferior_pid = ws->value.related_pid; | |
8070 | return 1; | |
ce78b96d JB |
8071 | } |
8072 | ||
4a64f543 MS |
8073 | /* Implement the "print_it" breakpoint_ops method for vfork |
8074 | catchpoints. */ | |
ce78b96d JB |
8075 | |
8076 | static enum print_stop_action | |
348d480f | 8077 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8078 | { |
36dfb11c | 8079 | struct ui_out *uiout = current_uiout; |
348d480f | 8080 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8081 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8082 | ||
ce78b96d | 8083 | annotate_catchpoint (b->number); |
36dfb11c TT |
8084 | if (b->disposition == disp_del) |
8085 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8086 | else | |
8087 | ui_out_text (uiout, "\nCatchpoint "); | |
8088 | if (ui_out_is_mi_like_p (uiout)) | |
8089 | { | |
8090 | ui_out_field_string (uiout, "reason", | |
8091 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8092 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8093 | } | |
8094 | ui_out_field_int (uiout, "bkptno", b->number); | |
8095 | ui_out_text (uiout, " (vforked process "); | |
8096 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8097 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8098 | return PRINT_SRC_AND_LOC; |
8099 | } | |
8100 | ||
4a64f543 MS |
8101 | /* Implement the "print_one" breakpoint_ops method for vfork |
8102 | catchpoints. */ | |
ce78b96d JB |
8103 | |
8104 | static void | |
a6d9a66e | 8105 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8106 | { |
e29a4733 | 8107 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8108 | struct value_print_options opts; |
79a45e25 | 8109 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8110 | |
8111 | get_user_print_options (&opts); | |
4a64f543 MS |
8112 | /* Field 4, the address, is omitted (which makes the columns not |
8113 | line up too nicely with the headers, but the effect is relatively | |
8114 | readable). */ | |
79a45b7d | 8115 | if (opts.addressprint) |
ce78b96d JB |
8116 | ui_out_field_skip (uiout, "addr"); |
8117 | annotate_field (5); | |
8118 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8119 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8120 | { |
8121 | ui_out_text (uiout, ", process "); | |
8122 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8123 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8124 | ui_out_spaces (uiout, 1); |
8125 | } | |
8ac3646f TT |
8126 | |
8127 | if (ui_out_is_mi_like_p (uiout)) | |
8128 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8129 | } |
8130 | ||
8131 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8132 | catchpoints. */ | |
8133 | ||
8134 | static void | |
8135 | print_mention_catch_vfork (struct breakpoint *b) | |
8136 | { | |
8137 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8138 | } | |
8139 | ||
6149aea9 PA |
8140 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8141 | catchpoints. */ | |
8142 | ||
8143 | static void | |
8144 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8145 | { | |
8146 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8147 | print_recreate_thread (b, fp); |
6149aea9 PA |
8148 | } |
8149 | ||
ce78b96d JB |
8150 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8151 | ||
2060206e | 8152 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8153 | |
edcc5120 TT |
8154 | /* An instance of this type is used to represent an solib catchpoint. |
8155 | It includes a "struct breakpoint" as a kind of base class; users | |
8156 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8157 | really of this type iff its ops pointer points to | |
8158 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8159 | ||
8160 | struct solib_catchpoint | |
8161 | { | |
8162 | /* The base class. */ | |
8163 | struct breakpoint base; | |
8164 | ||
8165 | /* True for "catch load", false for "catch unload". */ | |
8166 | unsigned char is_load; | |
8167 | ||
8168 | /* Regular expression to match, if any. COMPILED is only valid when | |
8169 | REGEX is non-NULL. */ | |
8170 | char *regex; | |
8171 | regex_t compiled; | |
8172 | }; | |
8173 | ||
8174 | static void | |
8175 | dtor_catch_solib (struct breakpoint *b) | |
8176 | { | |
8177 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8178 | ||
8179 | if (self->regex) | |
8180 | regfree (&self->compiled); | |
8181 | xfree (self->regex); | |
8182 | ||
8183 | base_breakpoint_ops.dtor (b); | |
8184 | } | |
8185 | ||
8186 | static int | |
8187 | insert_catch_solib (struct bp_location *ignore) | |
8188 | { | |
8189 | return 0; | |
8190 | } | |
8191 | ||
8192 | static int | |
8193 | remove_catch_solib (struct bp_location *ignore) | |
8194 | { | |
8195 | return 0; | |
8196 | } | |
8197 | ||
8198 | static int | |
8199 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8200 | struct address_space *aspace, | |
8201 | CORE_ADDR bp_addr, | |
8202 | const struct target_waitstatus *ws) | |
8203 | { | |
8204 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8205 | struct breakpoint *other; | |
8206 | ||
8207 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8208 | return 1; | |
8209 | ||
8210 | ALL_BREAKPOINTS (other) | |
8211 | { | |
8212 | struct bp_location *other_bl; | |
8213 | ||
8214 | if (other == bl->owner) | |
8215 | continue; | |
8216 | ||
8217 | if (other->type != bp_shlib_event) | |
8218 | continue; | |
8219 | ||
8220 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8221 | continue; | |
8222 | ||
8223 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8224 | { | |
8225 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8226 | return 1; | |
8227 | } | |
8228 | } | |
8229 | ||
8230 | return 0; | |
8231 | } | |
8232 | ||
8233 | static void | |
8234 | check_status_catch_solib (struct bpstats *bs) | |
8235 | { | |
8236 | struct solib_catchpoint *self | |
8237 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8238 | int ix; | |
8239 | ||
8240 | if (self->is_load) | |
8241 | { | |
8242 | struct so_list *iter; | |
8243 | ||
8244 | for (ix = 0; | |
8245 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8246 | ix, iter); | |
8247 | ++ix) | |
8248 | { | |
8249 | if (!self->regex | |
8250 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8251 | return; | |
8252 | } | |
8253 | } | |
8254 | else | |
8255 | { | |
8256 | char *iter; | |
8257 | ||
8258 | for (ix = 0; | |
8259 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8260 | ix, iter); | |
8261 | ++ix) | |
8262 | { | |
8263 | if (!self->regex | |
8264 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8265 | return; | |
8266 | } | |
8267 | } | |
8268 | ||
8269 | bs->stop = 0; | |
8270 | bs->print_it = print_it_noop; | |
8271 | } | |
8272 | ||
8273 | static enum print_stop_action | |
8274 | print_it_catch_solib (bpstat bs) | |
8275 | { | |
8276 | struct breakpoint *b = bs->breakpoint_at; | |
8277 | struct ui_out *uiout = current_uiout; | |
8278 | ||
8279 | annotate_catchpoint (b->number); | |
8280 | if (b->disposition == disp_del) | |
8281 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8282 | else | |
8283 | ui_out_text (uiout, "\nCatchpoint "); | |
8284 | ui_out_field_int (uiout, "bkptno", b->number); | |
8285 | ui_out_text (uiout, "\n"); | |
8286 | if (ui_out_is_mi_like_p (uiout)) | |
8287 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8288 | print_solib_event (1); | |
8289 | return PRINT_SRC_AND_LOC; | |
8290 | } | |
8291 | ||
8292 | static void | |
8293 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8294 | { | |
8295 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8296 | struct value_print_options opts; | |
8297 | struct ui_out *uiout = current_uiout; | |
8298 | char *msg; | |
8299 | ||
8300 | get_user_print_options (&opts); | |
8301 | /* Field 4, the address, is omitted (which makes the columns not | |
8302 | line up too nicely with the headers, but the effect is relatively | |
8303 | readable). */ | |
8304 | if (opts.addressprint) | |
8305 | { | |
8306 | annotate_field (4); | |
8307 | ui_out_field_skip (uiout, "addr"); | |
8308 | } | |
8309 | ||
8310 | annotate_field (5); | |
8311 | if (self->is_load) | |
8312 | { | |
8313 | if (self->regex) | |
8314 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8315 | else | |
8316 | msg = xstrdup (_("load of library")); | |
8317 | } | |
8318 | else | |
8319 | { | |
8320 | if (self->regex) | |
8321 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8322 | else | |
8323 | msg = xstrdup (_("unload of library")); | |
8324 | } | |
8325 | ui_out_field_string (uiout, "what", msg); | |
8326 | xfree (msg); | |
8ac3646f TT |
8327 | |
8328 | if (ui_out_is_mi_like_p (uiout)) | |
8329 | ui_out_field_string (uiout, "catch-type", | |
8330 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8331 | } |
8332 | ||
8333 | static void | |
8334 | print_mention_catch_solib (struct breakpoint *b) | |
8335 | { | |
8336 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8337 | ||
8338 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8339 | self->is_load ? "load" : "unload"); | |
8340 | } | |
8341 | ||
8342 | static void | |
8343 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8344 | { | |
8345 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8346 | ||
8347 | fprintf_unfiltered (fp, "%s %s", | |
8348 | b->disposition == disp_del ? "tcatch" : "catch", | |
8349 | self->is_load ? "load" : "unload"); | |
8350 | if (self->regex) | |
8351 | fprintf_unfiltered (fp, " %s", self->regex); | |
8352 | fprintf_unfiltered (fp, "\n"); | |
8353 | } | |
8354 | ||
8355 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8356 | ||
91985142 MG |
8357 | /* Shared helper function (MI and CLI) for creating and installing |
8358 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8359 | the events to be caught are load events, otherwise they are | |
8360 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8361 | temporary one. If ENABLED is non-zero the catchpoint is | |
8362 | created in an enabled state. */ | |
edcc5120 | 8363 | |
91985142 MG |
8364 | void |
8365 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8366 | { |
8367 | struct solib_catchpoint *c; | |
8368 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8369 | struct cleanup *cleanup; |
8370 | ||
edcc5120 TT |
8371 | if (!arg) |
8372 | arg = ""; | |
8373 | arg = skip_spaces (arg); | |
8374 | ||
8375 | c = XCNEW (struct solib_catchpoint); | |
8376 | cleanup = make_cleanup (xfree, c); | |
8377 | ||
8378 | if (*arg != '\0') | |
8379 | { | |
8380 | int errcode; | |
8381 | ||
8382 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8383 | if (errcode != 0) | |
8384 | { | |
8385 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8386 | ||
8387 | make_cleanup (xfree, err); | |
8388 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8389 | } | |
8390 | c->regex = xstrdup (arg); | |
8391 | } | |
8392 | ||
8393 | c->is_load = is_load; | |
91985142 | 8394 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8395 | &catch_solib_breakpoint_ops); |
8396 | ||
91985142 MG |
8397 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8398 | ||
edcc5120 TT |
8399 | discard_cleanups (cleanup); |
8400 | install_breakpoint (0, &c->base, 1); | |
8401 | } | |
8402 | ||
91985142 MG |
8403 | /* A helper function that does all the work for "catch load" and |
8404 | "catch unload". */ | |
8405 | ||
8406 | static void | |
8407 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8408 | struct cmd_list_element *command) | |
8409 | { | |
8410 | int tempflag; | |
8411 | const int enabled = 1; | |
8412 | ||
8413 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8414 | ||
8415 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8416 | } | |
8417 | ||
edcc5120 TT |
8418 | static void |
8419 | catch_load_command_1 (char *arg, int from_tty, | |
8420 | struct cmd_list_element *command) | |
8421 | { | |
8422 | catch_load_or_unload (arg, from_tty, 1, command); | |
8423 | } | |
8424 | ||
8425 | static void | |
8426 | catch_unload_command_1 (char *arg, int from_tty, | |
8427 | struct cmd_list_element *command) | |
8428 | { | |
8429 | catch_load_or_unload (arg, from_tty, 0, command); | |
8430 | } | |
8431 | ||
346774a9 PA |
8432 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8433 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8434 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8435 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8436 | |
ab04a2af | 8437 | void |
346774a9 PA |
8438 | init_catchpoint (struct breakpoint *b, |
8439 | struct gdbarch *gdbarch, int tempflag, | |
8440 | char *cond_string, | |
c0a91b2b | 8441 | const struct breakpoint_ops *ops) |
c906108c | 8442 | { |
c5aa993b | 8443 | struct symtab_and_line sal; |
346774a9 | 8444 | |
fe39c653 | 8445 | init_sal (&sal); |
6c95b8df | 8446 | sal.pspace = current_program_space; |
c5aa993b | 8447 | |
28010a5d | 8448 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8449 | |
1b36a34b | 8450 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8451 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8452 | } |
8453 | ||
28010a5d | 8454 | void |
3ea46bff | 8455 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8456 | { |
8457 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8458 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8459 | if (is_tracepoint (b)) |
8460 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8461 | if (!internal) |
8462 | mention (b); | |
c56053d2 | 8463 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8464 | |
8465 | if (update_gll) | |
44702360 | 8466 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8467 | } |
8468 | ||
9b70b993 | 8469 | static void |
a6d9a66e UW |
8470 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8471 | int tempflag, char *cond_string, | |
c0a91b2b | 8472 | const struct breakpoint_ops *ops) |
c906108c | 8473 | { |
e29a4733 | 8474 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8475 | |
e29a4733 PA |
8476 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8477 | ||
8478 | c->forked_inferior_pid = null_ptid; | |
8479 | ||
3ea46bff | 8480 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8481 | } |
8482 | ||
fe798b75 JB |
8483 | /* Exec catchpoints. */ |
8484 | ||
b4d90040 PA |
8485 | /* An instance of this type is used to represent an exec catchpoint. |
8486 | It includes a "struct breakpoint" as a kind of base class; users | |
8487 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8488 | really of this type iff its ops pointer points to | |
8489 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8490 | ||
8491 | struct exec_catchpoint | |
8492 | { | |
8493 | /* The base class. */ | |
8494 | struct breakpoint base; | |
8495 | ||
8496 | /* Filename of a program whose exec triggered this catchpoint. | |
8497 | This field is only valid immediately after this catchpoint has | |
8498 | triggered. */ | |
8499 | char *exec_pathname; | |
8500 | }; | |
8501 | ||
8502 | /* Implement the "dtor" breakpoint_ops method for exec | |
8503 | catchpoints. */ | |
8504 | ||
8505 | static void | |
8506 | dtor_catch_exec (struct breakpoint *b) | |
8507 | { | |
8508 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8509 | ||
8510 | xfree (c->exec_pathname); | |
348d480f | 8511 | |
2060206e | 8512 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8513 | } |
8514 | ||
77b06cd7 TJB |
8515 | static int |
8516 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8517 | { |
dfd4cc63 | 8518 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8519 | } |
c906108c | 8520 | |
fe798b75 | 8521 | static int |
77b06cd7 | 8522 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8523 | { |
dfd4cc63 | 8524 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8525 | } |
c906108c | 8526 | |
fe798b75 | 8527 | static int |
f1310107 | 8528 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8529 | struct address_space *aspace, CORE_ADDR bp_addr, |
8530 | const struct target_waitstatus *ws) | |
fe798b75 | 8531 | { |
b4d90040 PA |
8532 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8533 | ||
f90263c1 TT |
8534 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8535 | return 0; | |
8536 | ||
8537 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8538 | return 1; | |
fe798b75 | 8539 | } |
c906108c | 8540 | |
fe798b75 | 8541 | static enum print_stop_action |
348d480f | 8542 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8543 | { |
36dfb11c | 8544 | struct ui_out *uiout = current_uiout; |
348d480f | 8545 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8546 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8547 | ||
fe798b75 | 8548 | annotate_catchpoint (b->number); |
36dfb11c TT |
8549 | if (b->disposition == disp_del) |
8550 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8551 | else | |
8552 | ui_out_text (uiout, "\nCatchpoint "); | |
8553 | if (ui_out_is_mi_like_p (uiout)) | |
8554 | { | |
8555 | ui_out_field_string (uiout, "reason", | |
8556 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8557 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8558 | } | |
8559 | ui_out_field_int (uiout, "bkptno", b->number); | |
8560 | ui_out_text (uiout, " (exec'd "); | |
8561 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8562 | ui_out_text (uiout, "), "); | |
8563 | ||
fe798b75 | 8564 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8565 | } |
8566 | ||
fe798b75 | 8567 | static void |
a6d9a66e | 8568 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8569 | { |
b4d90040 | 8570 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8571 | struct value_print_options opts; |
79a45e25 | 8572 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8573 | |
8574 | get_user_print_options (&opts); | |
8575 | ||
8576 | /* Field 4, the address, is omitted (which makes the columns | |
8577 | not line up too nicely with the headers, but the effect | |
8578 | is relatively readable). */ | |
8579 | if (opts.addressprint) | |
8580 | ui_out_field_skip (uiout, "addr"); | |
8581 | annotate_field (5); | |
8582 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8583 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8584 | { |
8585 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8586 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8587 | ui_out_text (uiout, "\" "); |
8588 | } | |
8ac3646f TT |
8589 | |
8590 | if (ui_out_is_mi_like_p (uiout)) | |
8591 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8592 | } |
8593 | ||
8594 | static void | |
8595 | print_mention_catch_exec (struct breakpoint *b) | |
8596 | { | |
8597 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8598 | } | |
8599 | ||
6149aea9 PA |
8600 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8601 | catchpoints. */ | |
8602 | ||
8603 | static void | |
8604 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8605 | { | |
8606 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8607 | print_recreate_thread (b, fp); |
6149aea9 PA |
8608 | } |
8609 | ||
2060206e | 8610 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8611 | |
c906108c | 8612 | static int |
fba45db2 | 8613 | hw_breakpoint_used_count (void) |
c906108c | 8614 | { |
c906108c | 8615 | int i = 0; |
f1310107 TJB |
8616 | struct breakpoint *b; |
8617 | struct bp_location *bl; | |
c906108c SS |
8618 | |
8619 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8620 | { |
d6b74ac4 | 8621 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8622 | for (bl = b->loc; bl; bl = bl->next) |
8623 | { | |
8624 | /* Special types of hardware breakpoints may use more than | |
8625 | one register. */ | |
348d480f | 8626 | i += b->ops->resources_needed (bl); |
f1310107 | 8627 | } |
c5aa993b | 8628 | } |
c906108c SS |
8629 | |
8630 | return i; | |
8631 | } | |
8632 | ||
a1398e0c PA |
8633 | /* Returns the resources B would use if it were a hardware |
8634 | watchpoint. */ | |
8635 | ||
c906108c | 8636 | static int |
a1398e0c | 8637 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8638 | { |
c906108c | 8639 | int i = 0; |
e09342b5 | 8640 | struct bp_location *bl; |
c906108c | 8641 | |
a1398e0c PA |
8642 | if (!breakpoint_enabled (b)) |
8643 | return 0; | |
8644 | ||
8645 | for (bl = b->loc; bl; bl = bl->next) | |
8646 | { | |
8647 | /* Special types of hardware watchpoints may use more than | |
8648 | one register. */ | |
8649 | i += b->ops->resources_needed (bl); | |
8650 | } | |
8651 | ||
8652 | return i; | |
8653 | } | |
8654 | ||
8655 | /* Returns the sum the used resources of all hardware watchpoints of | |
8656 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8657 | the sum of the used resources of all hardware watchpoints of other | |
8658 | types _not_ TYPE. */ | |
8659 | ||
8660 | static int | |
8661 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8662 | enum bptype type, int *other_type_used) | |
8663 | { | |
8664 | int i = 0; | |
8665 | struct breakpoint *b; | |
8666 | ||
c906108c SS |
8667 | *other_type_used = 0; |
8668 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8669 | { |
a1398e0c PA |
8670 | if (b == except) |
8671 | continue; | |
e09342b5 TJB |
8672 | if (!breakpoint_enabled (b)) |
8673 | continue; | |
8674 | ||
a1398e0c PA |
8675 | if (b->type == type) |
8676 | i += hw_watchpoint_use_count (b); | |
8677 | else if (is_hardware_watchpoint (b)) | |
8678 | *other_type_used = 1; | |
e09342b5 TJB |
8679 | } |
8680 | ||
c906108c SS |
8681 | return i; |
8682 | } | |
8683 | ||
c906108c | 8684 | void |
fba45db2 | 8685 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8686 | { |
c5aa993b | 8687 | struct breakpoint *b; |
c906108c SS |
8688 | |
8689 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8690 | { |
cc60f2e3 | 8691 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8692 | { |
b5de0fa7 | 8693 | b->enable_state = bp_call_disabled; |
44702360 | 8694 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8695 | } |
8696 | } | |
c906108c SS |
8697 | } |
8698 | ||
8699 | void | |
fba45db2 | 8700 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8701 | { |
c5aa993b | 8702 | struct breakpoint *b; |
c906108c SS |
8703 | |
8704 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8705 | { |
cc60f2e3 | 8706 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8707 | { |
b5de0fa7 | 8708 | b->enable_state = bp_enabled; |
44702360 | 8709 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8710 | } |
8711 | } | |
c906108c SS |
8712 | } |
8713 | ||
8bea4e01 UW |
8714 | void |
8715 | disable_breakpoints_before_startup (void) | |
8716 | { | |
6c95b8df | 8717 | current_program_space->executing_startup = 1; |
44702360 | 8718 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8719 | } |
8720 | ||
8721 | void | |
8722 | enable_breakpoints_after_startup (void) | |
8723 | { | |
6c95b8df | 8724 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8725 | breakpoint_re_set (); |
8bea4e01 UW |
8726 | } |
8727 | ||
7c16b83e PA |
8728 | /* Create a new single-step breakpoint for thread THREAD, with no |
8729 | locations. */ | |
c906108c | 8730 | |
7c16b83e PA |
8731 | static struct breakpoint * |
8732 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8733 | { | |
8734 | struct breakpoint *b = XNEW (struct breakpoint); | |
8735 | ||
8736 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8737 | &momentary_breakpoint_ops); | |
8738 | ||
8739 | b->disposition = disp_donttouch; | |
8740 | b->frame_id = null_frame_id; | |
8741 | ||
8742 | b->thread = thread; | |
8743 | gdb_assert (b->thread != 0); | |
8744 | ||
8745 | add_to_breakpoint_chain (b); | |
8746 | ||
8747 | return b; | |
8748 | } | |
8749 | ||
8750 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8751 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8752 | frame. */ | |
c906108c SS |
8753 | |
8754 | struct breakpoint * | |
a6d9a66e UW |
8755 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8756 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8757 | { |
52f0bd74 | 8758 | struct breakpoint *b; |
edb3359d | 8759 | |
193facb3 JK |
8760 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8761 | tail-called one. */ | |
8762 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8763 | |
06edf0c0 | 8764 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8765 | b->enable_state = bp_enabled; |
8766 | b->disposition = disp_donttouch; | |
818dd999 | 8767 | b->frame_id = frame_id; |
c906108c | 8768 | |
4a64f543 MS |
8769 | /* If we're debugging a multi-threaded program, then we want |
8770 | momentary breakpoints to be active in only a single thread of | |
8771 | control. */ | |
39f77062 KB |
8772 | if (in_thread_list (inferior_ptid)) |
8773 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8774 | |
44702360 | 8775 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8776 | |
c906108c SS |
8777 | return b; |
8778 | } | |
611c83ae | 8779 | |
06edf0c0 | 8780 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8781 | The new breakpoint will have type TYPE, use OPS as its |
8782 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8783 | |
06edf0c0 PA |
8784 | static struct breakpoint * |
8785 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8786 | enum bptype type, | |
a1aa2221 LM |
8787 | const struct breakpoint_ops *ops, |
8788 | int loc_enabled) | |
e58b0e63 PA |
8789 | { |
8790 | struct breakpoint *copy; | |
8791 | ||
06edf0c0 | 8792 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8793 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8794 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8795 | |
a6d9a66e | 8796 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8797 | copy->loc->requested_address = orig->loc->requested_address; |
8798 | copy->loc->address = orig->loc->address; | |
8799 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8800 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8801 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8802 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8803 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8804 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8805 | copy->frame_id = orig->frame_id; |
8806 | copy->thread = orig->thread; | |
6c95b8df | 8807 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8808 | |
8809 | copy->enable_state = bp_enabled; | |
8810 | copy->disposition = disp_donttouch; | |
8811 | copy->number = internal_breakpoint_number--; | |
8812 | ||
44702360 | 8813 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8814 | return copy; |
8815 | } | |
8816 | ||
06edf0c0 PA |
8817 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8818 | ORIG is NULL. */ | |
8819 | ||
8820 | struct breakpoint * | |
8821 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8822 | { | |
8823 | /* If there's nothing to clone, then return nothing. */ | |
8824 | if (orig == NULL) | |
8825 | return NULL; | |
8826 | ||
a1aa2221 | 8827 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8828 | } |
8829 | ||
611c83ae | 8830 | struct breakpoint * |
a6d9a66e UW |
8831 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8832 | enum bptype type) | |
611c83ae PA |
8833 | { |
8834 | struct symtab_and_line sal; | |
8835 | ||
8836 | sal = find_pc_line (pc, 0); | |
8837 | sal.pc = pc; | |
8838 | sal.section = find_pc_overlay (pc); | |
8839 | sal.explicit_pc = 1; | |
8840 | ||
a6d9a66e | 8841 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8842 | } |
c906108c | 8843 | \f |
c5aa993b | 8844 | |
c906108c SS |
8845 | /* Tell the user we have just set a breakpoint B. */ |
8846 | ||
8847 | static void | |
fba45db2 | 8848 | mention (struct breakpoint *b) |
c906108c | 8849 | { |
348d480f | 8850 | b->ops->print_mention (b); |
79a45e25 | 8851 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8852 | return; |
c906108c SS |
8853 | printf_filtered ("\n"); |
8854 | } | |
c906108c | 8855 | \f |
c5aa993b | 8856 | |
1a853c52 PA |
8857 | static int bp_loc_is_permanent (struct bp_location *loc); |
8858 | ||
0d381245 | 8859 | static struct bp_location * |
39d61571 | 8860 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8861 | const struct symtab_and_line *sal) |
8862 | { | |
8863 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8864 | CORE_ADDR adjusted_address; |
8865 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8866 | ||
8867 | if (loc_gdbarch == NULL) | |
8868 | loc_gdbarch = b->gdbarch; | |
8869 | ||
8870 | /* Adjust the breakpoint's address prior to allocating a location. | |
8871 | Once we call allocate_bp_location(), that mostly uninitialized | |
8872 | location will be placed on the location chain. Adjustment of the | |
8873 | breakpoint may cause target_read_memory() to be called and we do | |
8874 | not want its scan of the location chain to find a breakpoint and | |
8875 | location that's only been partially initialized. */ | |
8876 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8877 | sal->pc, b->type); | |
0d381245 | 8878 | |
d30113d4 | 8879 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8880 | loc = allocate_bp_location (b); |
d30113d4 JK |
8881 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8882 | tmp = &((*tmp)->next)) | |
0d381245 | 8883 | ; |
d30113d4 | 8884 | loc->next = *tmp; |
0d381245 | 8885 | *tmp = loc; |
3742cc8b | 8886 | |
0d381245 | 8887 | loc->requested_address = sal->pc; |
3742cc8b | 8888 | loc->address = adjusted_address; |
6c95b8df | 8889 | loc->pspace = sal->pspace; |
729662a5 TT |
8890 | loc->probe.probe = sal->probe; |
8891 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8892 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8893 | loc->section = sal->section; |
3742cc8b | 8894 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8895 | loc->line_number = sal->line; |
2f202fde | 8896 | loc->symtab = sal->symtab; |
f8eba3c6 | 8897 | |
0e30163f JK |
8898 | set_breakpoint_location_function (loc, |
8899 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 PA |
8900 | |
8901 | if (bp_loc_is_permanent (loc)) | |
8902 | { | |
8903 | loc->inserted = 1; | |
8904 | loc->permanent = 1; | |
8905 | } | |
8906 | ||
0d381245 VP |
8907 | return loc; |
8908 | } | |
514f746b AR |
8909 | \f |
8910 | ||
1cf4d951 | 8911 | /* See breakpoint.h. */ |
514f746b | 8912 | |
1cf4d951 PA |
8913 | int |
8914 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8915 | { |
8916 | int len; | |
8917 | CORE_ADDR addr; | |
1afeeb75 | 8918 | const gdb_byte *bpoint; |
514f746b | 8919 | gdb_byte *target_mem; |
939c61fa JK |
8920 | struct cleanup *cleanup; |
8921 | int retval = 0; | |
514f746b | 8922 | |
1cf4d951 PA |
8923 | addr = address; |
8924 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8925 | ||
8926 | /* Software breakpoints unsupported? */ | |
8927 | if (bpoint == NULL) | |
8928 | return 0; | |
8929 | ||
8930 | target_mem = alloca (len); | |
8931 | ||
8932 | /* Enable the automatic memory restoration from breakpoints while | |
8933 | we read the memory. Otherwise we could say about our temporary | |
8934 | breakpoints they are permanent. */ | |
8935 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
8936 | ||
8937 | if (target_read_memory (address, target_mem, len) == 0 | |
8938 | && memcmp (target_mem, bpoint, len) == 0) | |
8939 | retval = 1; | |
8940 | ||
8941 | do_cleanups (cleanup); | |
8942 | ||
8943 | return retval; | |
8944 | } | |
8945 | ||
8946 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8947 | return 0 otherwise. */ | |
8948 | ||
8949 | static int | |
8950 | bp_loc_is_permanent (struct bp_location *loc) | |
8951 | { | |
8952 | struct cleanup *cleanup; | |
8953 | int retval; | |
8954 | ||
514f746b AR |
8955 | gdb_assert (loc != NULL); |
8956 | ||
e8af5d7a JB |
8957 | /* bp_call_dummy breakpoint locations are usually memory locations |
8958 | where GDB just wrote a breakpoint instruction, making it look | |
8959 | as if there is a permanent breakpoint at that location. Considering | |
8960 | it permanent makes GDB rely on that breakpoint instruction to stop | |
8961 | the program, thus removing the need to insert its own breakpoint | |
8962 | there. This is normally expected to work, except that some versions | |
8963 | of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap | |
8964 | 0x02 while interrupts disabled, Error state) instead of reporting | |
8965 | a SIGTRAP. QEMU should probably be fixed, but in the interest of | |
8966 | compatibility with versions that behave this way, we always consider | |
8967 | bp_call_dummy breakpoint locations as non-permanent. */ | |
8968 | if (loc->owner->type == bp_call_dummy) | |
8969 | return 0; | |
8970 | ||
6c95b8df | 8971 | cleanup = save_current_space_and_thread (); |
6c95b8df | 8972 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 8973 | |
1cf4d951 | 8974 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 8975 | |
939c61fa JK |
8976 | do_cleanups (cleanup); |
8977 | ||
8978 | return retval; | |
514f746b AR |
8979 | } |
8980 | ||
e7e0cddf SS |
8981 | /* Build a command list for the dprintf corresponding to the current |
8982 | settings of the dprintf style options. */ | |
8983 | ||
8984 | static void | |
8985 | update_dprintf_command_list (struct breakpoint *b) | |
8986 | { | |
8987 | char *dprintf_args = b->extra_string; | |
8988 | char *printf_line = NULL; | |
8989 | ||
8990 | if (!dprintf_args) | |
8991 | return; | |
8992 | ||
8993 | dprintf_args = skip_spaces (dprintf_args); | |
8994 | ||
8995 | /* Allow a comma, as it may have terminated a location, but don't | |
8996 | insist on it. */ | |
8997 | if (*dprintf_args == ',') | |
8998 | ++dprintf_args; | |
8999 | dprintf_args = skip_spaces (dprintf_args); | |
9000 | ||
9001 | if (*dprintf_args != '"') | |
9002 | error (_("Bad format string, missing '\"'.")); | |
9003 | ||
d3ce09f5 | 9004 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9005 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9006 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9007 | { |
9008 | if (!dprintf_function) | |
9009 | error (_("No function supplied for dprintf call")); | |
9010 | ||
9011 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9012 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9013 | dprintf_function, | |
9014 | dprintf_channel, | |
9015 | dprintf_args); | |
9016 | else | |
9017 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9018 | dprintf_function, | |
9019 | dprintf_args); | |
9020 | } | |
d3ce09f5 SS |
9021 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9022 | { | |
9023 | if (target_can_run_breakpoint_commands ()) | |
9024 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9025 | else | |
9026 | { | |
9027 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9028 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9029 | } | |
9030 | } | |
e7e0cddf SS |
9031 | else |
9032 | internal_error (__FILE__, __LINE__, | |
9033 | _("Invalid dprintf style.")); | |
9034 | ||
f28045c2 | 9035 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9036 | /* Manufacture a printf sequence. */ |
f28045c2 | 9037 | { |
9d6e6e84 HZ |
9038 | struct command_line *printf_cmd_line |
9039 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9040 | |
f28045c2 YQ |
9041 | printf_cmd_line->control_type = simple_control; |
9042 | printf_cmd_line->body_count = 0; | |
9043 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9044 | printf_cmd_line->next = NULL; |
f28045c2 | 9045 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9046 | |
f28045c2 YQ |
9047 | breakpoint_set_commands (b, printf_cmd_line); |
9048 | } | |
e7e0cddf SS |
9049 | } |
9050 | ||
9051 | /* Update all dprintf commands, making their command lists reflect | |
9052 | current style settings. */ | |
9053 | ||
9054 | static void | |
9055 | update_dprintf_commands (char *args, int from_tty, | |
9056 | struct cmd_list_element *c) | |
9057 | { | |
9058 | struct breakpoint *b; | |
9059 | ||
9060 | ALL_BREAKPOINTS (b) | |
9061 | { | |
9062 | if (b->type == bp_dprintf) | |
9063 | update_dprintf_command_list (b); | |
9064 | } | |
9065 | } | |
c3f6f71d | 9066 | |
018d34a4 VP |
9067 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9068 | as textual description of the location, and COND_STRING | |
db107f19 | 9069 | as condition expression. */ |
018d34a4 VP |
9070 | |
9071 | static void | |
d9b3f62e PA |
9072 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9073 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9074 | char *filter, char *cond_string, |
e7e0cddf | 9075 | char *extra_string, |
d9b3f62e PA |
9076 | enum bptype type, enum bpdisp disposition, |
9077 | int thread, int task, int ignore_count, | |
c0a91b2b | 9078 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9079 | int enabled, int internal, unsigned flags, |
9080 | int display_canonical) | |
018d34a4 | 9081 | { |
0d381245 | 9082 | int i; |
018d34a4 VP |
9083 | |
9084 | if (type == bp_hardware_breakpoint) | |
9085 | { | |
fbbd034e AS |
9086 | int target_resources_ok; |
9087 | ||
9088 | i = hw_breakpoint_used_count (); | |
9089 | target_resources_ok = | |
9090 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9091 | i + 1, 0); |
9092 | if (target_resources_ok == 0) | |
9093 | error (_("No hardware breakpoint support in the target.")); | |
9094 | else if (target_resources_ok < 0) | |
9095 | error (_("Hardware breakpoints used exceeds limit.")); | |
9096 | } | |
9097 | ||
6c95b8df PA |
9098 | gdb_assert (sals.nelts > 0); |
9099 | ||
0d381245 VP |
9100 | for (i = 0; i < sals.nelts; ++i) |
9101 | { | |
9102 | struct symtab_and_line sal = sals.sals[i]; | |
9103 | struct bp_location *loc; | |
9104 | ||
9105 | if (from_tty) | |
5af949e3 UW |
9106 | { |
9107 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9108 | if (!loc_gdbarch) | |
9109 | loc_gdbarch = gdbarch; | |
9110 | ||
9111 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9112 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9113 | } |
0d381245 VP |
9114 | |
9115 | if (i == 0) | |
9116 | { | |
d9b3f62e | 9117 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9118 | b->thread = thread; |
4a306c9a | 9119 | b->task = task; |
855a6e68 | 9120 | |
0d381245 | 9121 | b->cond_string = cond_string; |
e7e0cddf | 9122 | b->extra_string = extra_string; |
0d381245 | 9123 | b->ignore_count = ignore_count; |
41447f92 | 9124 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9125 | b->disposition = disposition; |
6c95b8df | 9126 | |
44f238bb PA |
9127 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9128 | b->loc->inserted = 1; | |
9129 | ||
0fb4aa4b PA |
9130 | if (type == bp_static_tracepoint) |
9131 | { | |
d9b3f62e | 9132 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9133 | struct static_tracepoint_marker marker; |
9134 | ||
983af33b | 9135 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9136 | { |
9137 | /* We already know the marker exists, otherwise, we | |
9138 | wouldn't see a sal for it. */ | |
9139 | char *p = &addr_string[3]; | |
9140 | char *endp; | |
9141 | char *marker_str; | |
0fb4aa4b | 9142 | |
e9cafbcc | 9143 | p = skip_spaces (p); |
0fb4aa4b | 9144 | |
e9cafbcc | 9145 | endp = skip_to_space (p); |
0fb4aa4b PA |
9146 | |
9147 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9148 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9149 | |
3e43a32a MS |
9150 | printf_filtered (_("Probed static tracepoint " |
9151 | "marker \"%s\"\n"), | |
d9b3f62e | 9152 | t->static_trace_marker_id); |
0fb4aa4b PA |
9153 | } |
9154 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9155 | { | |
d9b3f62e | 9156 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9157 | release_static_tracepoint_marker (&marker); |
9158 | ||
3e43a32a MS |
9159 | printf_filtered (_("Probed static tracepoint " |
9160 | "marker \"%s\"\n"), | |
d9b3f62e | 9161 | t->static_trace_marker_id); |
0fb4aa4b PA |
9162 | } |
9163 | else | |
3e43a32a MS |
9164 | warning (_("Couldn't determine the static " |
9165 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9166 | } |
9167 | ||
0d381245 VP |
9168 | loc = b->loc; |
9169 | } | |
9170 | else | |
018d34a4 | 9171 | { |
39d61571 | 9172 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9173 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9174 | loc->inserted = 1; | |
0d381245 VP |
9175 | } |
9176 | ||
9177 | if (b->cond_string) | |
9178 | { | |
bbc13ae3 KS |
9179 | const char *arg = b->cond_string; |
9180 | ||
1bb9788d TT |
9181 | loc->cond = parse_exp_1 (&arg, loc->address, |
9182 | block_for_pc (loc->address), 0); | |
0d381245 | 9183 | if (*arg) |
588ae58c | 9184 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9185 | } |
e7e0cddf SS |
9186 | |
9187 | /* Dynamic printf requires and uses additional arguments on the | |
9188 | command line, otherwise it's an error. */ | |
9189 | if (type == bp_dprintf) | |
9190 | { | |
9191 | if (b->extra_string) | |
9192 | update_dprintf_command_list (b); | |
9193 | else | |
9194 | error (_("Format string required")); | |
9195 | } | |
9196 | else if (b->extra_string) | |
588ae58c | 9197 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9198 | } |
018d34a4 | 9199 | |
56435ebe | 9200 | b->display_canonical = display_canonical; |
018d34a4 VP |
9201 | if (addr_string) |
9202 | b->addr_string = addr_string; | |
9203 | else | |
9204 | /* addr_string has to be used or breakpoint_re_set will delete | |
9205 | me. */ | |
5af949e3 UW |
9206 | b->addr_string |
9207 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9208 | b->filter = filter; |
d9b3f62e | 9209 | } |
018d34a4 | 9210 | |
d9b3f62e PA |
9211 | static void |
9212 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9213 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9214 | char *filter, char *cond_string, |
e7e0cddf | 9215 | char *extra_string, |
d9b3f62e PA |
9216 | enum bptype type, enum bpdisp disposition, |
9217 | int thread, int task, int ignore_count, | |
c0a91b2b | 9218 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9219 | int enabled, int internal, unsigned flags, |
9220 | int display_canonical) | |
d9b3f62e PA |
9221 | { |
9222 | struct breakpoint *b; | |
9223 | struct cleanup *old_chain; | |
9224 | ||
9225 | if (is_tracepoint_type (type)) | |
9226 | { | |
9227 | struct tracepoint *t; | |
9228 | ||
9229 | t = XCNEW (struct tracepoint); | |
9230 | b = &t->base; | |
9231 | } | |
9232 | else | |
9233 | b = XNEW (struct breakpoint); | |
9234 | ||
9235 | old_chain = make_cleanup (xfree, b); | |
9236 | ||
9237 | init_breakpoint_sal (b, gdbarch, | |
9238 | sals, addr_string, | |
e7e0cddf | 9239 | filter, cond_string, extra_string, |
d9b3f62e PA |
9240 | type, disposition, |
9241 | thread, task, ignore_count, | |
9242 | ops, from_tty, | |
44f238bb PA |
9243 | enabled, internal, flags, |
9244 | display_canonical); | |
d9b3f62e PA |
9245 | discard_cleanups (old_chain); |
9246 | ||
3ea46bff | 9247 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9248 | } |
9249 | ||
9250 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9251 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9252 | value. COND_STRING, if not NULL, specified the condition to be | |
9253 | used for all breakpoints. Essentially the only case where | |
9254 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9255 | function. In that case, it's still not possible to specify | |
9256 | separate conditions for different overloaded functions, so | |
9257 | we take just a single condition string. | |
9258 | ||
c3f6f71d | 9259 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9260 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9261 | array contents). If the function fails (error() is called), the |
9262 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9263 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9264 | |
9265 | static void | |
8cdf0e15 | 9266 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9267 | struct linespec_result *canonical, |
e7e0cddf | 9268 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9269 | enum bptype type, enum bpdisp disposition, |
9270 | int thread, int task, int ignore_count, | |
c0a91b2b | 9271 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9272 | int enabled, int internal, unsigned flags) |
c906108c | 9273 | { |
018d34a4 | 9274 | int i; |
f8eba3c6 | 9275 | struct linespec_sals *lsal; |
cc59ec59 | 9276 | |
f8eba3c6 TT |
9277 | if (canonical->pre_expanded) |
9278 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9279 | ||
9280 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9281 | { |
f8eba3c6 TT |
9282 | /* Note that 'addr_string' can be NULL in the case of a plain |
9283 | 'break', without arguments. */ | |
9284 | char *addr_string = (canonical->addr_string | |
9285 | ? xstrdup (canonical->addr_string) | |
9286 | : NULL); | |
9287 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9288 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9289 | |
f8eba3c6 TT |
9290 | make_cleanup (xfree, filter_string); |
9291 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9292 | addr_string, | |
9293 | filter_string, | |
e7e0cddf SS |
9294 | cond_string, extra_string, |
9295 | type, disposition, | |
84f4c1fe | 9296 | thread, task, ignore_count, ops, |
44f238bb | 9297 | from_tty, enabled, internal, flags, |
56435ebe | 9298 | canonical->special_display); |
f8eba3c6 | 9299 | discard_cleanups (inner); |
c3f6f71d | 9300 | } |
c3f6f71d | 9301 | } |
c906108c | 9302 | |
9998af43 | 9303 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9304 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9305 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9306 | address strings. ADDRESS points to the end of the SAL. |
9307 | ||
9308 | The array and the line spec strings are allocated on the heap, it is | |
9309 | the caller's responsibility to free them. */ | |
c906108c | 9310 | |
b9362cc7 | 9311 | static void |
c3f6f71d | 9312 | parse_breakpoint_sals (char **address, |
58438ac1 | 9313 | struct linespec_result *canonical) |
c3f6f71d | 9314 | { |
c3f6f71d | 9315 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9316 | breakpoint. */ |
0578b14e | 9317 | if ((*address) == NULL || linespec_lexer_lex_keyword (*address)) |
c906108c | 9318 | { |
1bfeeb0f JL |
9319 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9320 | address. */ | |
9321 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9322 | { |
f8eba3c6 | 9323 | struct linespec_sals lsal; |
c3f6f71d | 9324 | struct symtab_and_line sal; |
1c8cdcb1 | 9325 | CORE_ADDR pc; |
cc59ec59 | 9326 | |
4a64f543 | 9327 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9328 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9329 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9330 | |
9331 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9332 | corresponding to the last call to print_frame_info. |
9333 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9334 | as the breakpoint line number is inappropriate otherwise. | |
9335 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9336 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9337 | pc = sal.pc; |
9338 | sal = find_pc_line (pc, 0); | |
00903456 | 9339 | |
4a64f543 | 9340 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9341 | where PC is the last displayed codepoint's address. So |
9342 | make sure to set sal.explicit_pc to prevent GDB from | |
9343 | trying to expand the list of sals to include all other | |
9344 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9345 | sal.pc = pc; |
00903456 JK |
9346 | sal.explicit_pc = 1; |
9347 | ||
f8eba3c6 TT |
9348 | lsal.sals.sals[0] = sal; |
9349 | lsal.sals.nelts = 1; | |
9350 | lsal.canonical = NULL; | |
9351 | ||
9352 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9353 | } |
9354 | else | |
8a3fe4f8 | 9355 | error (_("No default breakpoint address now.")); |
c906108c SS |
9356 | } |
9357 | else | |
9358 | { | |
cc80f267 JK |
9359 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9360 | ||
c906108c | 9361 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9362 | current_source_symtab (which is decode_line_1's default). |
9363 | This should produce the results we want almost all of the | |
cc80f267 JK |
9364 | time while leaving default_breakpoint_* alone. |
9365 | ||
9366 | ObjC: However, don't match an Objective-C method name which | |
9367 | may have a '+' or '-' succeeded by a '['. */ | |
9368 | if (last_displayed_sal_is_valid () | |
9369 | && (!cursal.symtab | |
9370 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9371 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9372 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9373 | get_last_displayed_symtab (), | |
9374 | get_last_displayed_line (), | |
9375 | canonical, NULL, NULL); | |
c906108c | 9376 | else |
f8eba3c6 | 9377 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9378 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9379 | } |
c3f6f71d | 9380 | } |
c906108c | 9381 | |
c906108c | 9382 | |
c3f6f71d | 9383 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9384 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9385 | |
b9362cc7 | 9386 | static void |
23e7acfb | 9387 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9388 | { |
9389 | int i; | |
cc59ec59 | 9390 | |
c3f6f71d | 9391 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9392 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9393 | } |
9394 | ||
7a697b8d SS |
9395 | /* Fast tracepoints may have restrictions on valid locations. For |
9396 | instance, a fast tracepoint using a jump instead of a trap will | |
9397 | likely have to overwrite more bytes than a trap would, and so can | |
9398 | only be placed where the instruction is longer than the jump, or a | |
9399 | multi-instruction sequence does not have a jump into the middle of | |
9400 | it, etc. */ | |
9401 | ||
9402 | static void | |
9403 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9404 | struct symtabs_and_lines *sals) | |
9405 | { | |
9406 | int i, rslt; | |
9407 | struct symtab_and_line *sal; | |
9408 | char *msg; | |
9409 | struct cleanup *old_chain; | |
9410 | ||
9411 | for (i = 0; i < sals->nelts; i++) | |
9412 | { | |
f8eba3c6 TT |
9413 | struct gdbarch *sarch; |
9414 | ||
7a697b8d SS |
9415 | sal = &sals->sals[i]; |
9416 | ||
f8eba3c6 TT |
9417 | sarch = get_sal_arch (*sal); |
9418 | /* We fall back to GDBARCH if there is no architecture | |
9419 | associated with SAL. */ | |
9420 | if (sarch == NULL) | |
9421 | sarch = gdbarch; | |
9422 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9423 | NULL, &msg); |
9424 | old_chain = make_cleanup (xfree, msg); | |
9425 | ||
9426 | if (!rslt) | |
9427 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9428 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9429 | |
9430 | do_cleanups (old_chain); | |
9431 | } | |
9432 | } | |
9433 | ||
af4908ba KS |
9434 | /* Issue an invalid thread ID error. */ |
9435 | ||
9436 | static void ATTRIBUTE_NORETURN | |
9437 | invalid_thread_id_error (int id) | |
9438 | { | |
9439 | error (_("Unknown thread %d."), id); | |
9440 | } | |
9441 | ||
018d34a4 VP |
9442 | /* Given TOK, a string specification of condition and thread, as |
9443 | accepted by the 'break' command, extract the condition | |
9444 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9445 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9446 | If no condition is found, *COND_STRING is set to NULL. |
9447 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9448 | |
9449 | static void | |
bbc13ae3 | 9450 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9451 | char **cond_string, int *thread, int *task, |
9452 | char **rest) | |
018d34a4 VP |
9453 | { |
9454 | *cond_string = NULL; | |
9455 | *thread = -1; | |
ed1d1739 KS |
9456 | *task = 0; |
9457 | *rest = NULL; | |
9458 | ||
018d34a4 VP |
9459 | while (tok && *tok) |
9460 | { | |
bbc13ae3 | 9461 | const char *end_tok; |
018d34a4 | 9462 | int toklen; |
bbc13ae3 KS |
9463 | const char *cond_start = NULL; |
9464 | const char *cond_end = NULL; | |
cc59ec59 | 9465 | |
bbc13ae3 | 9466 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9467 | |
9468 | if ((*tok == '"' || *tok == ',') && rest) | |
9469 | { | |
9470 | *rest = savestring (tok, strlen (tok)); | |
9471 | return; | |
9472 | } | |
9473 | ||
bbc13ae3 | 9474 | end_tok = skip_to_space_const (tok); |
d634f2de | 9475 | |
018d34a4 | 9476 | toklen = end_tok - tok; |
d634f2de | 9477 | |
018d34a4 VP |
9478 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9479 | { | |
f7545552 TT |
9480 | struct expression *expr; |
9481 | ||
018d34a4 | 9482 | tok = cond_start = end_tok + 1; |
1bb9788d | 9483 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9484 | xfree (expr); |
018d34a4 | 9485 | cond_end = tok; |
d634f2de | 9486 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9487 | } |
9488 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9489 | { | |
9490 | char *tmptok; | |
d634f2de | 9491 | |
018d34a4 | 9492 | tok = end_tok + 1; |
bbc13ae3 | 9493 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9494 | if (tok == tmptok) |
9495 | error (_("Junk after thread keyword.")); | |
9496 | if (!valid_thread_id (*thread)) | |
af4908ba | 9497 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9498 | tok = tmptok; |
018d34a4 | 9499 | } |
4a306c9a JB |
9500 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9501 | { | |
9502 | char *tmptok; | |
9503 | ||
9504 | tok = end_tok + 1; | |
bbc13ae3 | 9505 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9506 | if (tok == tmptok) |
9507 | error (_("Junk after task keyword.")); | |
9508 | if (!valid_task_id (*task)) | |
b6199126 | 9509 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9510 | tok = tmptok; |
4a306c9a | 9511 | } |
e7e0cddf SS |
9512 | else if (rest) |
9513 | { | |
9514 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9515 | return; |
e7e0cddf | 9516 | } |
018d34a4 VP |
9517 | else |
9518 | error (_("Junk at end of arguments.")); | |
9519 | } | |
9520 | } | |
9521 | ||
0fb4aa4b PA |
9522 | /* Decode a static tracepoint marker spec. */ |
9523 | ||
9524 | static struct symtabs_and_lines | |
9525 | decode_static_tracepoint_spec (char **arg_p) | |
9526 | { | |
9527 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9528 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9529 | struct cleanup *old_chain; |
9530 | char *p = &(*arg_p)[3]; | |
9531 | char *endp; | |
9532 | char *marker_str; | |
9533 | int i; | |
9534 | ||
e9cafbcc | 9535 | p = skip_spaces (p); |
0fb4aa4b | 9536 | |
e9cafbcc | 9537 | endp = skip_to_space (p); |
0fb4aa4b PA |
9538 | |
9539 | marker_str = savestring (p, endp - p); | |
9540 | old_chain = make_cleanup (xfree, marker_str); | |
9541 | ||
9542 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9543 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9544 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9545 | ||
9546 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9547 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9548 | ||
9549 | for (i = 0; i < sals.nelts; i++) | |
9550 | { | |
9551 | struct static_tracepoint_marker *marker; | |
9552 | ||
9553 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9554 | ||
9555 | init_sal (&sals.sals[i]); | |
9556 | ||
9557 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9558 | sals.sals[i].pc = marker->address; | |
9559 | ||
9560 | release_static_tracepoint_marker (marker); | |
9561 | } | |
9562 | ||
9563 | do_cleanups (old_chain); | |
9564 | ||
9565 | *arg_p = endp; | |
9566 | return sals; | |
9567 | } | |
9568 | ||
fd9b8c24 PA |
9569 | /* Set a breakpoint. This function is shared between CLI and MI |
9570 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9571 | modes of operations, selected by the PARSE_ARG parameter. If |
9572 | non-zero, the function will parse ARG, extracting location, | |
9573 | condition, thread and extra string. Otherwise, ARG is just the | |
9574 | breakpoint's location, with condition, thread, and extra string | |
9575 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9576 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9577 | from the internal breakpoint count. Returns true if any breakpoint | |
9578 | was created; false otherwise. */ | |
0101ce28 | 9579 | |
8cdf0e15 VP |
9580 | int |
9581 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9582 | char *arg, char *cond_string, |
9583 | int thread, char *extra_string, | |
f6de8ec2 | 9584 | int parse_arg, |
0fb4aa4b | 9585 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9586 | int ignore_count, |
9587 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9588 | const struct breakpoint_ops *ops, |
44f238bb PA |
9589 | int from_tty, int enabled, int internal, |
9590 | unsigned flags) | |
c3f6f71d | 9591 | { |
f8eba3c6 | 9592 | char *copy_arg = NULL; |
c3f6f71d | 9593 | char *addr_start = arg; |
7efd8fc2 | 9594 | struct linespec_result canonical; |
c3f6f71d | 9595 | struct cleanup *old_chain; |
80c99de1 | 9596 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9597 | int pending = 0; |
4a306c9a | 9598 | int task = 0; |
86b17b60 | 9599 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9600 | |
348d480f PA |
9601 | gdb_assert (ops != NULL); |
9602 | ||
7efd8fc2 | 9603 | init_linespec_result (&canonical); |
c3f6f71d | 9604 | |
492d29ea | 9605 | TRY |
b78a6381 | 9606 | { |
983af33b SDJ |
9607 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9608 | addr_start, ©_arg); | |
b78a6381 | 9609 | } |
492d29ea | 9610 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9611 | { |
492d29ea PA |
9612 | /* If caller is interested in rc value from parse, set |
9613 | value. */ | |
9614 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9615 | { |
05ff989b AC |
9616 | /* If pending breakpoint support is turned off, throw |
9617 | error. */ | |
fa8d40ab JJ |
9618 | |
9619 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9620 | throw_exception (e); |
9621 | ||
9622 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9623 | |
05ff989b AC |
9624 | /* If pending breakpoint support is auto query and the user |
9625 | selects no, then simply return the error code. */ | |
059fb39f | 9626 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9627 | && !nquery (_("Make %s pending on future shared library load? "), |
9628 | bptype_string (type_wanted))) | |
fd9b8c24 | 9629 | return 0; |
fa8d40ab | 9630 | |
05ff989b AC |
9631 | /* At this point, either the user was queried about setting |
9632 | a pending breakpoint and selected yes, or pending | |
9633 | breakpoint behavior is on and thus a pending breakpoint | |
9634 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9635 | { |
9636 | struct linespec_sals lsal; | |
9637 | ||
9638 | copy_arg = xstrdup (addr_start); | |
9639 | lsal.canonical = xstrdup (copy_arg); | |
9640 | lsal.sals.nelts = 1; | |
9641 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9642 | init_sal (&lsal.sals.sals[0]); | |
9643 | pending = 1; | |
9644 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9645 | } | |
0101ce28 | 9646 | } |
492d29ea PA |
9647 | else |
9648 | throw_exception (e); | |
0101ce28 | 9649 | } |
492d29ea PA |
9650 | END_CATCH |
9651 | ||
9652 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9653 | return 0; | |
c3f6f71d | 9654 | |
4a64f543 | 9655 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9656 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9657 | |
c3f6f71d JM |
9658 | /* ----------------------------- SNIP ----------------------------- |
9659 | Anything added to the cleanup chain beyond this point is assumed | |
9660 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9661 | then the memory is not reclaimed. */ |
9662 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9663 | |
c3f6f71d JM |
9664 | /* Resolve all line numbers to PC's and verify that the addresses |
9665 | are ok for the target. */ | |
0101ce28 | 9666 | if (!pending) |
f8eba3c6 TT |
9667 | { |
9668 | int ix; | |
9669 | struct linespec_sals *iter; | |
9670 | ||
9671 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9672 | breakpoint_sals_to_pc (&iter->sals); | |
9673 | } | |
c3f6f71d | 9674 | |
7a697b8d | 9675 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9676 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9677 | { |
9678 | int ix; | |
9679 | struct linespec_sals *iter; | |
9680 | ||
9681 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9682 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9683 | } | |
7a697b8d | 9684 | |
c3f6f71d JM |
9685 | /* Verify that condition can be parsed, before setting any |
9686 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9687 | breakpoint. */ |
0101ce28 | 9688 | if (!pending) |
c3f6f71d | 9689 | { |
f6de8ec2 | 9690 | if (parse_arg) |
72b2ff0e | 9691 | { |
0878d0fa | 9692 | char *rest; |
52d361e1 YQ |
9693 | struct linespec_sals *lsal; |
9694 | ||
9695 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9696 | ||
0878d0fa YQ |
9697 | /* Here we only parse 'arg' to separate condition |
9698 | from thread number, so parsing in context of first | |
9699 | sal is OK. When setting the breakpoint we'll | |
9700 | re-parse it in context of each sal. */ | |
9701 | ||
9702 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9703 | &thread, &task, &rest); | |
9704 | if (cond_string) | |
9705 | make_cleanup (xfree, cond_string); | |
9706 | if (rest) | |
9707 | make_cleanup (xfree, rest); | |
9708 | if (rest) | |
9709 | extra_string = rest; | |
72b2ff0e | 9710 | } |
2f069f6f | 9711 | else |
72b2ff0e | 9712 | { |
0878d0fa YQ |
9713 | if (*arg != '\0') |
9714 | error (_("Garbage '%s' at end of location"), arg); | |
9715 | ||
9716 | /* Create a private copy of condition string. */ | |
9717 | if (cond_string) | |
9718 | { | |
9719 | cond_string = xstrdup (cond_string); | |
9720 | make_cleanup (xfree, cond_string); | |
9721 | } | |
9722 | /* Create a private copy of any extra string. */ | |
9723 | if (extra_string) | |
9724 | { | |
9725 | extra_string = xstrdup (extra_string); | |
9726 | make_cleanup (xfree, extra_string); | |
9727 | } | |
72b2ff0e | 9728 | } |
0fb4aa4b | 9729 | |
52d361e1 | 9730 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9731 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9732 | tempflag ? disp_del : disp_donttouch, |
9733 | thread, task, ignore_count, ops, | |
44f238bb | 9734 | from_tty, enabled, internal, flags); |
c906108c | 9735 | } |
0101ce28 JJ |
9736 | else |
9737 | { | |
0101ce28 JJ |
9738 | struct breakpoint *b; |
9739 | ||
0101ce28 JJ |
9740 | make_cleanup (xfree, copy_arg); |
9741 | ||
bfccc43c YQ |
9742 | if (is_tracepoint_type (type_wanted)) |
9743 | { | |
9744 | struct tracepoint *t; | |
9745 | ||
9746 | t = XCNEW (struct tracepoint); | |
9747 | b = &t->base; | |
9748 | } | |
9749 | else | |
9750 | b = XNEW (struct breakpoint); | |
9751 | ||
9752 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9753 | ||
f8eba3c6 | 9754 | b->addr_string = copy_arg; |
f6de8ec2 | 9755 | if (parse_arg) |
98aa42ee AT |
9756 | { |
9757 | b->cond_string = NULL; | |
9758 | b->extra_string = NULL; | |
9759 | } | |
e12c7713 MK |
9760 | else |
9761 | { | |
9762 | /* Create a private copy of condition string. */ | |
9763 | if (cond_string) | |
9764 | { | |
9765 | cond_string = xstrdup (cond_string); | |
9766 | make_cleanup (xfree, cond_string); | |
9767 | } | |
98aa42ee AT |
9768 | /* Create a private copy of any extra string. */ |
9769 | if (extra_string != NULL) | |
9770 | { | |
9771 | extra_string = xstrdup (extra_string); | |
9772 | make_cleanup (xfree, extra_string); | |
9773 | } | |
e12c7713 | 9774 | b->cond_string = cond_string; |
98aa42ee | 9775 | b->extra_string = extra_string; |
15630549 | 9776 | b->thread = thread; |
e12c7713 | 9777 | } |
0101ce28 | 9778 | b->ignore_count = ignore_count; |
0101ce28 | 9779 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9780 | b->condition_not_parsed = 1; |
41447f92 | 9781 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9782 | if ((type_wanted != bp_breakpoint |
9783 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9784 | b->pspace = current_program_space; |
8bea4e01 | 9785 | |
bfccc43c | 9786 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9787 | } |
9788 | ||
f8eba3c6 | 9789 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9790 | { |
3e43a32a MS |
9791 | warning (_("Multiple breakpoints were set.\nUse the " |
9792 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9793 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9794 | } |
9795 | ||
80c99de1 PA |
9796 | /* That's it. Discard the cleanups for data inserted into the |
9797 | breakpoint. */ | |
9798 | discard_cleanups (bkpt_chain); | |
9799 | /* But cleanup everything else. */ | |
c3f6f71d | 9800 | do_cleanups (old_chain); |
217dc9e2 | 9801 | |
80c99de1 | 9802 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9803 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9804 | |
9805 | return 1; | |
c3f6f71d | 9806 | } |
c906108c | 9807 | |
348d480f | 9808 | /* Set a breakpoint. |
72b2ff0e VP |
9809 | ARG is a string describing breakpoint address, |
9810 | condition, and thread. | |
9811 | FLAG specifies if a breakpoint is hardware on, | |
9812 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9813 | and BP_TEMPFLAG. */ | |
348d480f | 9814 | |
98deb0da | 9815 | static void |
72b2ff0e | 9816 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9817 | { |
72b2ff0e | 9818 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9819 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9820 | ? bp_hardware_breakpoint | |
9821 | : bp_breakpoint); | |
55aa24fb SDJ |
9822 | struct breakpoint_ops *ops; |
9823 | const char *arg_cp = arg; | |
9824 | ||
9825 | /* Matching breakpoints on probes. */ | |
9826 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9827 | ops = &bkpt_probe_breakpoint_ops; | |
9828 | else | |
9829 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9830 | |
8cdf0e15 VP |
9831 | create_breakpoint (get_current_arch (), |
9832 | arg, | |
e7e0cddf | 9833 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9834 | tempflag, type_wanted, |
8cdf0e15 VP |
9835 | 0 /* Ignore count */, |
9836 | pending_break_support, | |
55aa24fb | 9837 | ops, |
8cdf0e15 | 9838 | from_tty, |
84f4c1fe | 9839 | 1 /* enabled */, |
44f238bb PA |
9840 | 0 /* internal */, |
9841 | 0); | |
c906108c SS |
9842 | } |
9843 | ||
c906108c SS |
9844 | /* Helper function for break_command_1 and disassemble_command. */ |
9845 | ||
9846 | void | |
fba45db2 | 9847 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9848 | { |
9849 | CORE_ADDR pc; | |
9850 | ||
9851 | if (sal->pc == 0 && sal->symtab != NULL) | |
9852 | { | |
9853 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9854 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9855 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9856 | sal->pc = pc; |
6a048695 | 9857 | |
4a64f543 MS |
9858 | /* If this SAL corresponds to a breakpoint inserted using a line |
9859 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9860 | if (sal->explicit_line) |
059acae7 | 9861 | skip_prologue_sal (sal); |
c906108c SS |
9862 | } |
9863 | ||
9864 | if (sal->section == 0 && sal->symtab != NULL) | |
9865 | { | |
346d1dfe | 9866 | const struct blockvector *bv; |
3977b71f | 9867 | const struct block *b; |
c5aa993b | 9868 | struct symbol *sym; |
c906108c | 9869 | |
43f3e411 DE |
9870 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9871 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9872 | if (bv != NULL) |
9873 | { | |
7f0df278 | 9874 | sym = block_linkage_function (b); |
c906108c SS |
9875 | if (sym != NULL) |
9876 | { | |
eb822aa6 DE |
9877 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9878 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9879 | sym); | |
c906108c SS |
9880 | } |
9881 | else | |
9882 | { | |
4a64f543 MS |
9883 | /* It really is worthwhile to have the section, so we'll |
9884 | just have to look harder. This case can be executed | |
9885 | if we have line numbers but no functions (as can | |
9886 | happen in assembly source). */ | |
c906108c | 9887 | |
7cbd4a93 | 9888 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9889 | struct cleanup *old_chain = save_current_space_and_thread (); |
9890 | ||
9891 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9892 | |
9893 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9894 | if (msym.minsym) |
efd66ac6 | 9895 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9896 | |
9897 | do_cleanups (old_chain); | |
c906108c SS |
9898 | } |
9899 | } | |
9900 | } | |
9901 | } | |
9902 | ||
9903 | void | |
fba45db2 | 9904 | break_command (char *arg, int from_tty) |
c906108c | 9905 | { |
db107f19 | 9906 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9907 | } |
9908 | ||
c906108c | 9909 | void |
fba45db2 | 9910 | tbreak_command (char *arg, int from_tty) |
c906108c | 9911 | { |
db107f19 | 9912 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9913 | } |
9914 | ||
c906108c | 9915 | static void |
fba45db2 | 9916 | hbreak_command (char *arg, int from_tty) |
c906108c | 9917 | { |
db107f19 | 9918 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9919 | } |
9920 | ||
9921 | static void | |
fba45db2 | 9922 | thbreak_command (char *arg, int from_tty) |
c906108c | 9923 | { |
db107f19 | 9924 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9925 | } |
9926 | ||
9927 | static void | |
fba45db2 | 9928 | stop_command (char *arg, int from_tty) |
c906108c | 9929 | { |
a3f17187 | 9930 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9931 | Usage: stop in <function | address>\n\ |
a3f17187 | 9932 | stop at <line>\n")); |
c906108c SS |
9933 | } |
9934 | ||
9935 | static void | |
fba45db2 | 9936 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9937 | { |
9938 | int badInput = 0; | |
9939 | ||
c5aa993b | 9940 | if (arg == (char *) NULL) |
c906108c SS |
9941 | badInput = 1; |
9942 | else if (*arg != '*') | |
9943 | { | |
9944 | char *argptr = arg; | |
9945 | int hasColon = 0; | |
9946 | ||
4a64f543 | 9947 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9948 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9949 | function/method name. */ |
c906108c | 9950 | while (*argptr && !hasColon) |
c5aa993b JM |
9951 | { |
9952 | hasColon = (*argptr == ':'); | |
9953 | argptr++; | |
9954 | } | |
c906108c SS |
9955 | |
9956 | if (hasColon) | |
c5aa993b | 9957 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9958 | else |
c5aa993b | 9959 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9960 | } |
9961 | ||
9962 | if (badInput) | |
a3f17187 | 9963 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9964 | else |
db107f19 | 9965 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9966 | } |
9967 | ||
9968 | static void | |
fba45db2 | 9969 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9970 | { |
9971 | int badInput = 0; | |
9972 | ||
c5aa993b | 9973 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9974 | badInput = 1; |
9975 | else | |
9976 | { | |
9977 | char *argptr = arg; | |
9978 | int hasColon = 0; | |
9979 | ||
4a64f543 MS |
9980 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9981 | it is probably a line number. */ | |
c906108c | 9982 | while (*argptr && !hasColon) |
c5aa993b JM |
9983 | { |
9984 | hasColon = (*argptr == ':'); | |
9985 | argptr++; | |
9986 | } | |
c906108c SS |
9987 | |
9988 | if (hasColon) | |
c5aa993b | 9989 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9990 | else |
c5aa993b | 9991 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9992 | } |
9993 | ||
9994 | if (badInput) | |
a3f17187 | 9995 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9996 | else |
db107f19 | 9997 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9998 | } |
9999 | ||
e7e0cddf SS |
10000 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10001 | with a prewired command list consisting of a single output command, | |
10002 | built from extra arguments supplied on the dprintf command | |
10003 | line. */ | |
10004 | ||
da821c7b | 10005 | static void |
e7e0cddf SS |
10006 | dprintf_command (char *arg, int from_tty) |
10007 | { | |
10008 | create_breakpoint (get_current_arch (), | |
10009 | arg, | |
10010 | NULL, 0, NULL, 1 /* parse arg */, | |
10011 | 0, bp_dprintf, | |
10012 | 0 /* Ignore count */, | |
10013 | pending_break_support, | |
10014 | &dprintf_breakpoint_ops, | |
10015 | from_tty, | |
10016 | 1 /* enabled */, | |
10017 | 0 /* internal */, | |
10018 | 0); | |
10019 | } | |
10020 | ||
d3ce09f5 SS |
10021 | static void |
10022 | agent_printf_command (char *arg, int from_tty) | |
10023 | { | |
10024 | error (_("May only run agent-printf on the target")); | |
10025 | } | |
10026 | ||
f1310107 TJB |
10027 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10028 | ranged breakpoints. */ | |
10029 | ||
10030 | static int | |
10031 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10032 | struct address_space *aspace, | |
09ac7c10 TT |
10033 | CORE_ADDR bp_addr, |
10034 | const struct target_waitstatus *ws) | |
f1310107 | 10035 | { |
09ac7c10 | 10036 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10037 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10038 | return 0; |
10039 | ||
f1310107 TJB |
10040 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10041 | bl->length, aspace, bp_addr); | |
10042 | } | |
10043 | ||
10044 | /* Implement the "resources_needed" breakpoint_ops method for | |
10045 | ranged breakpoints. */ | |
10046 | ||
10047 | static int | |
10048 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10049 | { | |
10050 | return target_ranged_break_num_registers (); | |
10051 | } | |
10052 | ||
10053 | /* Implement the "print_it" breakpoint_ops method for | |
10054 | ranged breakpoints. */ | |
10055 | ||
10056 | static enum print_stop_action | |
348d480f | 10057 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10058 | { |
348d480f | 10059 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10060 | struct bp_location *bl = b->loc; |
79a45e25 | 10061 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10062 | |
10063 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10064 | ||
10065 | /* Ranged breakpoints have only one location. */ | |
10066 | gdb_assert (bl && bl->next == NULL); | |
10067 | ||
10068 | annotate_breakpoint (b->number); | |
10069 | if (b->disposition == disp_del) | |
10070 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10071 | else | |
10072 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10073 | if (ui_out_is_mi_like_p (uiout)) | |
10074 | { | |
10075 | ui_out_field_string (uiout, "reason", | |
10076 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10077 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10078 | } | |
10079 | ui_out_field_int (uiout, "bkptno", b->number); | |
10080 | ui_out_text (uiout, ", "); | |
10081 | ||
10082 | return PRINT_SRC_AND_LOC; | |
10083 | } | |
10084 | ||
10085 | /* Implement the "print_one" breakpoint_ops method for | |
10086 | ranged breakpoints. */ | |
10087 | ||
10088 | static void | |
10089 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10090 | struct bp_location **last_loc) | |
10091 | { | |
10092 | struct bp_location *bl = b->loc; | |
10093 | struct value_print_options opts; | |
79a45e25 | 10094 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10095 | |
10096 | /* Ranged breakpoints have only one location. */ | |
10097 | gdb_assert (bl && bl->next == NULL); | |
10098 | ||
10099 | get_user_print_options (&opts); | |
10100 | ||
10101 | if (opts.addressprint) | |
10102 | /* We don't print the address range here, it will be printed later | |
10103 | by print_one_detail_ranged_breakpoint. */ | |
10104 | ui_out_field_skip (uiout, "addr"); | |
10105 | annotate_field (5); | |
10106 | print_breakpoint_location (b, bl); | |
10107 | *last_loc = bl; | |
10108 | } | |
10109 | ||
10110 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10111 | ranged breakpoints. */ | |
10112 | ||
10113 | static void | |
10114 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10115 | struct ui_out *uiout) | |
10116 | { | |
10117 | CORE_ADDR address_start, address_end; | |
10118 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10119 | struct ui_file *stb = mem_fileopen (); |
10120 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10121 | |
10122 | gdb_assert (bl); | |
10123 | ||
10124 | address_start = bl->address; | |
10125 | address_end = address_start + bl->length - 1; | |
10126 | ||
10127 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10128 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10129 | print_core_address (bl->gdbarch, address_start), |
10130 | print_core_address (bl->gdbarch, address_end)); | |
10131 | ui_out_field_stream (uiout, "addr", stb); | |
10132 | ui_out_text (uiout, "\n"); | |
10133 | ||
10134 | do_cleanups (cleanup); | |
10135 | } | |
10136 | ||
10137 | /* Implement the "print_mention" breakpoint_ops method for | |
10138 | ranged breakpoints. */ | |
10139 | ||
10140 | static void | |
10141 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10142 | { | |
10143 | struct bp_location *bl = b->loc; | |
79a45e25 | 10144 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10145 | |
10146 | gdb_assert (bl); | |
10147 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10148 | ||
10149 | if (ui_out_is_mi_like_p (uiout)) | |
10150 | return; | |
10151 | ||
10152 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10153 | b->number, paddress (bl->gdbarch, bl->address), | |
10154 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10155 | } | |
10156 | ||
10157 | /* Implement the "print_recreate" breakpoint_ops method for | |
10158 | ranged breakpoints. */ | |
10159 | ||
10160 | static void | |
10161 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10162 | { | |
10163 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10164 | b->addr_string_range_end); | |
d9b3f62e | 10165 | print_recreate_thread (b, fp); |
f1310107 TJB |
10166 | } |
10167 | ||
10168 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10169 | ||
2060206e | 10170 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10171 | |
10172 | /* Find the address where the end of the breakpoint range should be | |
10173 | placed, given the SAL of the end of the range. This is so that if | |
10174 | the user provides a line number, the end of the range is set to the | |
10175 | last instruction of the given line. */ | |
10176 | ||
10177 | static CORE_ADDR | |
10178 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10179 | { | |
10180 | CORE_ADDR end; | |
10181 | ||
10182 | /* If the user provided a PC value, use it. Otherwise, | |
10183 | find the address of the end of the given location. */ | |
10184 | if (sal.explicit_pc) | |
10185 | end = sal.pc; | |
10186 | else | |
10187 | { | |
10188 | int ret; | |
10189 | CORE_ADDR start; | |
10190 | ||
10191 | ret = find_line_pc_range (sal, &start, &end); | |
10192 | if (!ret) | |
10193 | error (_("Could not find location of the end of the range.")); | |
10194 | ||
10195 | /* find_line_pc_range returns the start of the next line. */ | |
10196 | end--; | |
10197 | } | |
10198 | ||
10199 | return end; | |
10200 | } | |
10201 | ||
10202 | /* Implement the "break-range" CLI command. */ | |
10203 | ||
10204 | static void | |
10205 | break_range_command (char *arg, int from_tty) | |
10206 | { | |
10207 | char *arg_start, *addr_string_start, *addr_string_end; | |
10208 | struct linespec_result canonical_start, canonical_end; | |
10209 | int bp_count, can_use_bp, length; | |
10210 | CORE_ADDR end; | |
10211 | struct breakpoint *b; | |
10212 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10213 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10214 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10215 | |
10216 | /* We don't support software ranged breakpoints. */ | |
10217 | if (target_ranged_break_num_registers () < 0) | |
10218 | error (_("This target does not support hardware ranged breakpoints.")); | |
10219 | ||
10220 | bp_count = hw_breakpoint_used_count (); | |
10221 | bp_count += target_ranged_break_num_registers (); | |
10222 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10223 | bp_count, 0); | |
10224 | if (can_use_bp < 0) | |
10225 | error (_("Hardware breakpoints used exceeds limit.")); | |
10226 | ||
f8eba3c6 | 10227 | arg = skip_spaces (arg); |
f1310107 TJB |
10228 | if (arg == NULL || arg[0] == '\0') |
10229 | error(_("No address range specified.")); | |
10230 | ||
f1310107 TJB |
10231 | init_linespec_result (&canonical_start); |
10232 | ||
f8eba3c6 TT |
10233 | arg_start = arg; |
10234 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10235 | |
f8eba3c6 | 10236 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10237 | |
10238 | if (arg[0] != ',') | |
10239 | error (_("Too few arguments.")); | |
f8eba3c6 | 10240 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10241 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10242 | |
10243 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10244 | ||
10245 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10246 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10247 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10248 | ||
f8eba3c6 TT |
10249 | sal_start = lsal_start->sals.sals[0]; |
10250 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10251 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10252 | |
10253 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10254 | arg = skip_spaces (arg); |
f1310107 TJB |
10255 | |
10256 | /* Parse the end location. */ | |
10257 | ||
f1310107 TJB |
10258 | init_linespec_result (&canonical_end); |
10259 | arg_start = arg; | |
10260 | ||
f8eba3c6 | 10261 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10262 | parse_breakpoint_sals because we need to specify the start location's |
10263 | symtab and line as the default symtab and line for the end of the | |
10264 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10265 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10266 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10267 | sal_start.symtab, sal_start.line, | |
10268 | &canonical_end, NULL, NULL); | |
10269 | ||
10270 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10271 | |
f8eba3c6 | 10272 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10273 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10274 | |
10275 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10276 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10277 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10278 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10279 | ||
f8eba3c6 TT |
10280 | sal_end = lsal_end->sals.sals[0]; |
10281 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10282 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10283 | |
10284 | end = find_breakpoint_range_end (sal_end); | |
10285 | if (sal_start.pc > end) | |
177b42fe | 10286 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10287 | |
10288 | length = end - sal_start.pc + 1; | |
10289 | if (length < 0) | |
10290 | /* Length overflowed. */ | |
10291 | error (_("Address range too large.")); | |
10292 | else if (length == 1) | |
10293 | { | |
10294 | /* This range is simple enough to be handled by | |
10295 | the `hbreak' command. */ | |
10296 | hbreak_command (addr_string_start, 1); | |
10297 | ||
10298 | do_cleanups (cleanup_bkpt); | |
10299 | ||
10300 | return; | |
10301 | } | |
10302 | ||
10303 | /* Now set up the breakpoint. */ | |
10304 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10305 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10306 | set_breakpoint_count (breakpoint_count + 1); |
10307 | b->number = breakpoint_count; | |
10308 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10309 | b->addr_string = xstrdup (addr_string_start); |
10310 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10311 | b->loc->length = length; |
10312 | ||
f8eba3c6 | 10313 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10314 | |
10315 | mention (b); | |
8d3788bd | 10316 | observer_notify_breakpoint_created (b); |
44702360 | 10317 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10318 | } |
10319 | ||
4a64f543 MS |
10320 | /* Return non-zero if EXP is verified as constant. Returned zero |
10321 | means EXP is variable. Also the constant detection may fail for | |
10322 | some constant expressions and in such case still falsely return | |
10323 | zero. */ | |
2e6e3d9c | 10324 | |
65d79d4b SDJ |
10325 | static int |
10326 | watchpoint_exp_is_const (const struct expression *exp) | |
10327 | { | |
10328 | int i = exp->nelts; | |
10329 | ||
10330 | while (i > 0) | |
10331 | { | |
10332 | int oplenp, argsp; | |
10333 | ||
10334 | /* We are only interested in the descriptor of each element. */ | |
10335 | operator_length (exp, i, &oplenp, &argsp); | |
10336 | i -= oplenp; | |
10337 | ||
10338 | switch (exp->elts[i].opcode) | |
10339 | { | |
10340 | case BINOP_ADD: | |
10341 | case BINOP_SUB: | |
10342 | case BINOP_MUL: | |
10343 | case BINOP_DIV: | |
10344 | case BINOP_REM: | |
10345 | case BINOP_MOD: | |
10346 | case BINOP_LSH: | |
10347 | case BINOP_RSH: | |
10348 | case BINOP_LOGICAL_AND: | |
10349 | case BINOP_LOGICAL_OR: | |
10350 | case BINOP_BITWISE_AND: | |
10351 | case BINOP_BITWISE_IOR: | |
10352 | case BINOP_BITWISE_XOR: | |
10353 | case BINOP_EQUAL: | |
10354 | case BINOP_NOTEQUAL: | |
10355 | case BINOP_LESS: | |
10356 | case BINOP_GTR: | |
10357 | case BINOP_LEQ: | |
10358 | case BINOP_GEQ: | |
10359 | case BINOP_REPEAT: | |
10360 | case BINOP_COMMA: | |
10361 | case BINOP_EXP: | |
10362 | case BINOP_MIN: | |
10363 | case BINOP_MAX: | |
10364 | case BINOP_INTDIV: | |
10365 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10366 | case TERNOP_COND: |
10367 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10368 | |
10369 | case OP_LONG: | |
10370 | case OP_DOUBLE: | |
10371 | case OP_DECFLOAT: | |
10372 | case OP_LAST: | |
10373 | case OP_COMPLEX: | |
10374 | case OP_STRING: | |
65d79d4b SDJ |
10375 | case OP_ARRAY: |
10376 | case OP_TYPE: | |
608b4967 TT |
10377 | case OP_TYPEOF: |
10378 | case OP_DECLTYPE: | |
6e72ca20 | 10379 | case OP_TYPEID: |
65d79d4b SDJ |
10380 | case OP_NAME: |
10381 | case OP_OBJC_NSSTRING: | |
10382 | ||
10383 | case UNOP_NEG: | |
10384 | case UNOP_LOGICAL_NOT: | |
10385 | case UNOP_COMPLEMENT: | |
10386 | case UNOP_ADDR: | |
10387 | case UNOP_HIGH: | |
aeaa2474 | 10388 | case UNOP_CAST: |
9eaf6705 TT |
10389 | |
10390 | case UNOP_CAST_TYPE: | |
10391 | case UNOP_REINTERPRET_CAST: | |
10392 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10393 | /* Unary, binary and ternary operators: We have to check |
10394 | their operands. If they are constant, then so is the | |
10395 | result of that operation. For instance, if A and B are | |
10396 | determined to be constants, then so is "A + B". | |
10397 | ||
10398 | UNOP_IND is one exception to the rule above, because the | |
10399 | value of *ADDR is not necessarily a constant, even when | |
10400 | ADDR is. */ | |
65d79d4b SDJ |
10401 | break; |
10402 | ||
10403 | case OP_VAR_VALUE: | |
10404 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10405 | |
65d79d4b | 10406 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10407 | possible that a buggy compiler could mark a variable as |
10408 | constant even when it is not, and TYPE_CONST would return | |
10409 | true in this case, while SYMBOL_CLASS wouldn't. | |
10410 | ||
10411 | We also have to check for function symbols because they | |
10412 | are always constant. */ | |
65d79d4b SDJ |
10413 | { |
10414 | struct symbol *s = exp->elts[i + 2].symbol; | |
10415 | ||
10416 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10417 | && SYMBOL_CLASS (s) != LOC_CONST | |
10418 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10419 | return 0; | |
10420 | break; | |
10421 | } | |
10422 | ||
10423 | /* The default action is to return 0 because we are using | |
10424 | the optimistic approach here: If we don't know something, | |
10425 | then it is not a constant. */ | |
10426 | default: | |
10427 | return 0; | |
10428 | } | |
10429 | } | |
10430 | ||
10431 | return 1; | |
10432 | } | |
10433 | ||
3a5c3e22 PA |
10434 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10435 | ||
10436 | static void | |
10437 | dtor_watchpoint (struct breakpoint *self) | |
10438 | { | |
10439 | struct watchpoint *w = (struct watchpoint *) self; | |
10440 | ||
10441 | xfree (w->cond_exp); | |
10442 | xfree (w->exp); | |
10443 | xfree (w->exp_string); | |
10444 | xfree (w->exp_string_reparse); | |
10445 | value_free (w->val); | |
10446 | ||
10447 | base_breakpoint_ops.dtor (self); | |
10448 | } | |
10449 | ||
348d480f PA |
10450 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10451 | ||
10452 | static void | |
10453 | re_set_watchpoint (struct breakpoint *b) | |
10454 | { | |
3a5c3e22 PA |
10455 | struct watchpoint *w = (struct watchpoint *) b; |
10456 | ||
348d480f PA |
10457 | /* Watchpoint can be either on expression using entirely global |
10458 | variables, or it can be on local variables. | |
10459 | ||
10460 | Watchpoints of the first kind are never auto-deleted, and even | |
10461 | persist across program restarts. Since they can use variables | |
10462 | from shared libraries, we need to reparse expression as libraries | |
10463 | are loaded and unloaded. | |
10464 | ||
10465 | Watchpoints on local variables can also change meaning as result | |
10466 | of solib event. For example, if a watchpoint uses both a local | |
10467 | and a global variables in expression, it's a local watchpoint, | |
10468 | but unloading of a shared library will make the expression | |
10469 | invalid. This is not a very common use case, but we still | |
10470 | re-evaluate expression, to avoid surprises to the user. | |
10471 | ||
10472 | Note that for local watchpoints, we re-evaluate it only if | |
10473 | watchpoints frame id is still valid. If it's not, it means the | |
10474 | watchpoint is out of scope and will be deleted soon. In fact, | |
10475 | I'm not sure we'll ever be called in this case. | |
10476 | ||
10477 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10478 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10479 | |
3a5c3e22 PA |
10480 | Don't do anything about disabled watchpoints, since they will be |
10481 | reevaluated again when enabled. */ | |
10482 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10483 | } |
10484 | ||
77b06cd7 TJB |
10485 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10486 | ||
10487 | static int | |
10488 | insert_watchpoint (struct bp_location *bl) | |
10489 | { | |
3a5c3e22 PA |
10490 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10491 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10492 | |
10493 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10494 | w->cond_exp); |
77b06cd7 TJB |
10495 | } |
10496 | ||
10497 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10498 | ||
10499 | static int | |
10500 | remove_watchpoint (struct bp_location *bl) | |
10501 | { | |
3a5c3e22 PA |
10502 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10503 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10504 | |
10505 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10506 | w->cond_exp); |
e09342b5 TJB |
10507 | } |
10508 | ||
e09342b5 | 10509 | static int |
348d480f | 10510 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10511 | struct address_space *aspace, CORE_ADDR bp_addr, |
10512 | const struct target_waitstatus *ws) | |
e09342b5 | 10513 | { |
348d480f | 10514 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10515 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10516 | |
348d480f PA |
10517 | /* Continuable hardware watchpoints are treated as non-existent if the |
10518 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10519 | some data address). Otherwise gdb won't stop on a break instruction | |
10520 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10521 | been defined. Also skip watchpoints which we know did not trigger | |
10522 | (did not match the data address). */ | |
10523 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10524 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10525 | return 0; |
9c06b0b4 | 10526 | |
348d480f | 10527 | return 1; |
9c06b0b4 TJB |
10528 | } |
10529 | ||
348d480f PA |
10530 | static void |
10531 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10532 | { |
348d480f | 10533 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10534 | |
348d480f | 10535 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10536 | } |
10537 | ||
10538 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10539 | hardware watchpoints. */ |
9c06b0b4 TJB |
10540 | |
10541 | static int | |
348d480f | 10542 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10543 | { |
3a5c3e22 PA |
10544 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10545 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10546 | |
10547 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10548 | } |
10549 | ||
10550 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10551 | hardware watchpoints. */ |
9c06b0b4 TJB |
10552 | |
10553 | static int | |
348d480f | 10554 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10555 | { |
efa80663 PA |
10556 | /* Read and access watchpoints only work with hardware support. */ |
10557 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10558 | } |
10559 | ||
9c06b0b4 | 10560 | static enum print_stop_action |
348d480f | 10561 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10562 | { |
348d480f PA |
10563 | struct cleanup *old_chain; |
10564 | struct breakpoint *b; | |
f99d8bf4 | 10565 | struct ui_file *stb; |
348d480f | 10566 | enum print_stop_action result; |
3a5c3e22 | 10567 | struct watchpoint *w; |
79a45e25 | 10568 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10569 | |
10570 | gdb_assert (bs->bp_location_at != NULL); | |
10571 | ||
348d480f | 10572 | b = bs->breakpoint_at; |
3a5c3e22 | 10573 | w = (struct watchpoint *) b; |
348d480f | 10574 | |
f99d8bf4 PA |
10575 | stb = mem_fileopen (); |
10576 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10577 | |
10578 | switch (b->type) | |
10579 | { | |
348d480f | 10580 | case bp_watchpoint: |
9c06b0b4 TJB |
10581 | case bp_hardware_watchpoint: |
10582 | annotate_watchpoint (b->number); | |
10583 | if (ui_out_is_mi_like_p (uiout)) | |
10584 | ui_out_field_string | |
10585 | (uiout, "reason", | |
10586 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10587 | mention (b); |
10588 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10589 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10590 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10591 | ui_out_field_stream (uiout, "old", stb); |
10592 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10593 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10594 | ui_out_field_stream (uiout, "new", stb); |
10595 | ui_out_text (uiout, "\n"); | |
10596 | /* More than one watchpoint may have been triggered. */ | |
10597 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10598 | break; |
10599 | ||
10600 | case bp_read_watchpoint: | |
10601 | if (ui_out_is_mi_like_p (uiout)) | |
10602 | ui_out_field_string | |
10603 | (uiout, "reason", | |
10604 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10605 | mention (b); |
10606 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10607 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10608 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10609 | ui_out_field_stream (uiout, "value", stb); |
10610 | ui_out_text (uiout, "\n"); | |
10611 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10612 | break; |
10613 | ||
10614 | case bp_access_watchpoint: | |
348d480f PA |
10615 | if (bs->old_val != NULL) |
10616 | { | |
10617 | annotate_watchpoint (b->number); | |
10618 | if (ui_out_is_mi_like_p (uiout)) | |
10619 | ui_out_field_string | |
10620 | (uiout, "reason", | |
10621 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10622 | mention (b); | |
10623 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10624 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10625 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10626 | ui_out_field_stream (uiout, "old", stb); |
10627 | ui_out_text (uiout, "\nNew value = "); | |
10628 | } | |
10629 | else | |
10630 | { | |
10631 | mention (b); | |
10632 | if (ui_out_is_mi_like_p (uiout)) | |
10633 | ui_out_field_string | |
10634 | (uiout, "reason", | |
10635 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10636 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10637 | ui_out_text (uiout, "\nValue = "); | |
10638 | } | |
f99d8bf4 | 10639 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10640 | ui_out_field_stream (uiout, "new", stb); |
10641 | ui_out_text (uiout, "\n"); | |
10642 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10643 | break; |
10644 | default: | |
348d480f | 10645 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10646 | } |
10647 | ||
348d480f PA |
10648 | do_cleanups (old_chain); |
10649 | return result; | |
10650 | } | |
10651 | ||
10652 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10653 | watchpoints. */ | |
10654 | ||
10655 | static void | |
10656 | print_mention_watchpoint (struct breakpoint *b) | |
10657 | { | |
10658 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10659 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10660 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10661 | |
10662 | switch (b->type) | |
10663 | { | |
10664 | case bp_watchpoint: | |
10665 | ui_out_text (uiout, "Watchpoint "); | |
10666 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10667 | break; | |
10668 | case bp_hardware_watchpoint: | |
10669 | ui_out_text (uiout, "Hardware watchpoint "); | |
10670 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10671 | break; | |
10672 | case bp_read_watchpoint: | |
10673 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10674 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10675 | break; | |
10676 | case bp_access_watchpoint: | |
10677 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10678 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10679 | break; | |
10680 | default: | |
10681 | internal_error (__FILE__, __LINE__, | |
10682 | _("Invalid hardware watchpoint type.")); | |
10683 | } | |
10684 | ||
10685 | ui_out_field_int (uiout, "number", b->number); | |
10686 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10687 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10688 | do_cleanups (ui_out_chain); |
10689 | } | |
10690 | ||
10691 | /* Implement the "print_recreate" breakpoint_ops method for | |
10692 | watchpoints. */ | |
10693 | ||
10694 | static void | |
10695 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10696 | { | |
3a5c3e22 PA |
10697 | struct watchpoint *w = (struct watchpoint *) b; |
10698 | ||
348d480f PA |
10699 | switch (b->type) |
10700 | { | |
10701 | case bp_watchpoint: | |
10702 | case bp_hardware_watchpoint: | |
10703 | fprintf_unfiltered (fp, "watch"); | |
10704 | break; | |
10705 | case bp_read_watchpoint: | |
10706 | fprintf_unfiltered (fp, "rwatch"); | |
10707 | break; | |
10708 | case bp_access_watchpoint: | |
10709 | fprintf_unfiltered (fp, "awatch"); | |
10710 | break; | |
10711 | default: | |
10712 | internal_error (__FILE__, __LINE__, | |
10713 | _("Invalid watchpoint type.")); | |
10714 | } | |
10715 | ||
3a5c3e22 | 10716 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10717 | print_recreate_thread (b, fp); |
348d480f PA |
10718 | } |
10719 | ||
427cd150 TT |
10720 | /* Implement the "explains_signal" breakpoint_ops method for |
10721 | watchpoints. */ | |
10722 | ||
47591c29 | 10723 | static int |
427cd150 TT |
10724 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10725 | { | |
10726 | /* A software watchpoint cannot cause a signal other than | |
10727 | GDB_SIGNAL_TRAP. */ | |
10728 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10729 | return 0; |
427cd150 | 10730 | |
47591c29 | 10731 | return 1; |
427cd150 TT |
10732 | } |
10733 | ||
348d480f PA |
10734 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10735 | ||
2060206e | 10736 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10737 | |
10738 | /* Implement the "insert" breakpoint_ops method for | |
10739 | masked hardware watchpoints. */ | |
10740 | ||
10741 | static int | |
10742 | insert_masked_watchpoint (struct bp_location *bl) | |
10743 | { | |
3a5c3e22 PA |
10744 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10745 | ||
10746 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10747 | bl->watchpoint_type); |
10748 | } | |
10749 | ||
10750 | /* Implement the "remove" breakpoint_ops method for | |
10751 | masked hardware watchpoints. */ | |
10752 | ||
10753 | static int | |
10754 | remove_masked_watchpoint (struct bp_location *bl) | |
10755 | { | |
3a5c3e22 PA |
10756 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10757 | ||
10758 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10759 | bl->watchpoint_type); |
10760 | } | |
10761 | ||
10762 | /* Implement the "resources_needed" breakpoint_ops method for | |
10763 | masked hardware watchpoints. */ | |
10764 | ||
10765 | static int | |
10766 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10767 | { | |
3a5c3e22 PA |
10768 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10769 | ||
10770 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10771 | } |
10772 | ||
10773 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10774 | masked hardware watchpoints. */ | |
10775 | ||
10776 | static int | |
10777 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10778 | { | |
10779 | return 0; | |
10780 | } | |
10781 | ||
10782 | /* Implement the "print_it" breakpoint_ops method for | |
10783 | masked hardware watchpoints. */ | |
10784 | ||
10785 | static enum print_stop_action | |
10786 | print_it_masked_watchpoint (bpstat bs) | |
10787 | { | |
10788 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10789 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10790 | |
10791 | /* Masked watchpoints have only one location. */ | |
10792 | gdb_assert (b->loc && b->loc->next == NULL); | |
10793 | ||
10794 | switch (b->type) | |
10795 | { | |
10796 | case bp_hardware_watchpoint: | |
10797 | annotate_watchpoint (b->number); | |
10798 | if (ui_out_is_mi_like_p (uiout)) | |
10799 | ui_out_field_string | |
10800 | (uiout, "reason", | |
10801 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10802 | break; | |
10803 | ||
10804 | case bp_read_watchpoint: | |
10805 | if (ui_out_is_mi_like_p (uiout)) | |
10806 | ui_out_field_string | |
10807 | (uiout, "reason", | |
10808 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10809 | break; | |
10810 | ||
10811 | case bp_access_watchpoint: | |
10812 | if (ui_out_is_mi_like_p (uiout)) | |
10813 | ui_out_field_string | |
10814 | (uiout, "reason", | |
10815 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10816 | break; | |
10817 | default: | |
10818 | internal_error (__FILE__, __LINE__, | |
10819 | _("Invalid hardware watchpoint type.")); | |
10820 | } | |
10821 | ||
10822 | mention (b); | |
9c06b0b4 TJB |
10823 | ui_out_text (uiout, _("\n\ |
10824 | Check the underlying instruction at PC for the memory\n\ | |
10825 | address and value which triggered this watchpoint.\n")); | |
10826 | ui_out_text (uiout, "\n"); | |
10827 | ||
10828 | /* More than one watchpoint may have been triggered. */ | |
10829 | return PRINT_UNKNOWN; | |
10830 | } | |
10831 | ||
10832 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10833 | masked hardware watchpoints. */ | |
10834 | ||
10835 | static void | |
10836 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10837 | struct ui_out *uiout) | |
10838 | { | |
3a5c3e22 PA |
10839 | struct watchpoint *w = (struct watchpoint *) b; |
10840 | ||
9c06b0b4 TJB |
10841 | /* Masked watchpoints have only one location. */ |
10842 | gdb_assert (b->loc && b->loc->next == NULL); | |
10843 | ||
10844 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10845 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10846 | ui_out_text (uiout, "\n"); |
10847 | } | |
10848 | ||
10849 | /* Implement the "print_mention" breakpoint_ops method for | |
10850 | masked hardware watchpoints. */ | |
10851 | ||
10852 | static void | |
10853 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10854 | { | |
3a5c3e22 | 10855 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10856 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10857 | struct cleanup *ui_out_chain; |
10858 | ||
10859 | switch (b->type) | |
10860 | { | |
10861 | case bp_hardware_watchpoint: | |
10862 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10863 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10864 | break; | |
10865 | case bp_read_watchpoint: | |
10866 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10867 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10868 | break; | |
10869 | case bp_access_watchpoint: | |
10870 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10871 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10872 | break; | |
10873 | default: | |
10874 | internal_error (__FILE__, __LINE__, | |
10875 | _("Invalid hardware watchpoint type.")); | |
10876 | } | |
10877 | ||
10878 | ui_out_field_int (uiout, "number", b->number); | |
10879 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10880 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10881 | do_cleanups (ui_out_chain); |
10882 | } | |
10883 | ||
10884 | /* Implement the "print_recreate" breakpoint_ops method for | |
10885 | masked hardware watchpoints. */ | |
10886 | ||
10887 | static void | |
10888 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10889 | { | |
3a5c3e22 | 10890 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10891 | char tmp[40]; |
10892 | ||
10893 | switch (b->type) | |
10894 | { | |
10895 | case bp_hardware_watchpoint: | |
10896 | fprintf_unfiltered (fp, "watch"); | |
10897 | break; | |
10898 | case bp_read_watchpoint: | |
10899 | fprintf_unfiltered (fp, "rwatch"); | |
10900 | break; | |
10901 | case bp_access_watchpoint: | |
10902 | fprintf_unfiltered (fp, "awatch"); | |
10903 | break; | |
10904 | default: | |
10905 | internal_error (__FILE__, __LINE__, | |
10906 | _("Invalid hardware watchpoint type.")); | |
10907 | } | |
10908 | ||
3a5c3e22 PA |
10909 | sprintf_vma (tmp, w->hw_wp_mask); |
10910 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10911 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10912 | } |
10913 | ||
10914 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10915 | ||
2060206e | 10916 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10917 | |
10918 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10919 | ||
10920 | static int | |
10921 | is_masked_watchpoint (const struct breakpoint *b) | |
10922 | { | |
10923 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10924 | } | |
10925 | ||
53a5351d JM |
10926 | /* accessflag: hw_write: watch write, |
10927 | hw_read: watch read, | |
10928 | hw_access: watch access (read or write) */ | |
c906108c | 10929 | static void |
bbc13ae3 | 10930 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10931 | int just_location, int internal) |
c906108c | 10932 | { |
d983da9c | 10933 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10934 | struct expression *exp; |
270140bd | 10935 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10936 | struct value *val, *mark, *result; |
bb9d5f81 | 10937 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 10938 | struct frame_info *frame; |
bbc13ae3 KS |
10939 | const char *exp_start = NULL; |
10940 | const char *exp_end = NULL; | |
10941 | const char *tok, *end_tok; | |
9c06b0b4 | 10942 | int toklen = -1; |
bbc13ae3 KS |
10943 | const char *cond_start = NULL; |
10944 | const char *cond_end = NULL; | |
c906108c | 10945 | enum bptype bp_type; |
37e4754d | 10946 | int thread = -1; |
0cf6dd15 | 10947 | int pc = 0; |
9c06b0b4 TJB |
10948 | /* Flag to indicate whether we are going to use masks for |
10949 | the hardware watchpoint. */ | |
10950 | int use_mask = 0; | |
10951 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10952 | struct watchpoint *w; |
bbc13ae3 KS |
10953 | char *expression; |
10954 | struct cleanup *back_to; | |
c906108c | 10955 | |
37e4754d LM |
10956 | /* Make sure that we actually have parameters to parse. */ |
10957 | if (arg != NULL && arg[0] != '\0') | |
10958 | { | |
bbc13ae3 KS |
10959 | const char *value_start; |
10960 | ||
10961 | exp_end = arg + strlen (arg); | |
37e4754d | 10962 | |
9c06b0b4 TJB |
10963 | /* Look for "parameter value" pairs at the end |
10964 | of the arguments string. */ | |
bbc13ae3 | 10965 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10966 | { |
10967 | /* Skip whitespace at the end of the argument list. */ | |
10968 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10969 | tok--; | |
10970 | ||
10971 | /* Find the beginning of the last token. | |
10972 | This is the value of the parameter. */ | |
10973 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10974 | tok--; | |
10975 | value_start = tok + 1; | |
10976 | ||
10977 | /* Skip whitespace. */ | |
10978 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10979 | tok--; | |
10980 | ||
10981 | end_tok = tok; | |
10982 | ||
10983 | /* Find the beginning of the second to last token. | |
10984 | This is the parameter itself. */ | |
10985 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10986 | tok--; | |
10987 | tok++; | |
10988 | toklen = end_tok - tok + 1; | |
10989 | ||
61012eef | 10990 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 TJB |
10991 | { |
10992 | /* At this point we've found a "thread" token, which means | |
10993 | the user is trying to set a watchpoint that triggers | |
10994 | only in a specific thread. */ | |
10995 | char *endp; | |
37e4754d | 10996 | |
9c06b0b4 TJB |
10997 | if (thread != -1) |
10998 | error(_("You can specify only one thread.")); | |
37e4754d | 10999 | |
9c06b0b4 TJB |
11000 | /* Extract the thread ID from the next token. */ |
11001 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11002 | |
9c06b0b4 TJB |
11003 | /* Check if the user provided a valid numeric value for the |
11004 | thread ID. */ | |
11005 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11006 | error (_("Invalid thread ID specification %s."), value_start); | |
11007 | ||
11008 | /* Check if the thread actually exists. */ | |
11009 | if (!valid_thread_id (thread)) | |
af4908ba | 11010 | invalid_thread_id_error (thread); |
9c06b0b4 | 11011 | } |
61012eef | 11012 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11013 | { |
11014 | /* We've found a "mask" token, which means the user wants to | |
11015 | create a hardware watchpoint that is going to have the mask | |
11016 | facility. */ | |
11017 | struct value *mask_value, *mark; | |
37e4754d | 11018 | |
9c06b0b4 TJB |
11019 | if (use_mask) |
11020 | error(_("You can specify only one mask.")); | |
37e4754d | 11021 | |
9c06b0b4 | 11022 | use_mask = just_location = 1; |
37e4754d | 11023 | |
9c06b0b4 TJB |
11024 | mark = value_mark (); |
11025 | mask_value = parse_to_comma_and_eval (&value_start); | |
11026 | mask = value_as_address (mask_value); | |
11027 | value_free_to_mark (mark); | |
11028 | } | |
11029 | else | |
11030 | /* We didn't recognize what we found. We should stop here. */ | |
11031 | break; | |
37e4754d | 11032 | |
9c06b0b4 TJB |
11033 | /* Truncate the string and get rid of the "parameter value" pair before |
11034 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11035 | exp_end = tok; |
9c06b0b4 | 11036 | } |
37e4754d | 11037 | } |
bbc13ae3 KS |
11038 | else |
11039 | exp_end = arg; | |
37e4754d | 11040 | |
bbc13ae3 KS |
11041 | /* Parse the rest of the arguments. From here on out, everything |
11042 | is in terms of a newly allocated string instead of the original | |
11043 | ARG. */ | |
c906108c | 11044 | innermost_block = NULL; |
bbc13ae3 KS |
11045 | expression = savestring (arg, exp_end - arg); |
11046 | back_to = make_cleanup (xfree, expression); | |
11047 | exp_start = arg = expression; | |
1bb9788d | 11048 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11049 | exp_end = arg; |
fa8a61dc TT |
11050 | /* Remove trailing whitespace from the expression before saving it. |
11051 | This makes the eventual display of the expression string a bit | |
11052 | prettier. */ | |
11053 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11054 | --exp_end; | |
11055 | ||
65d79d4b SDJ |
11056 | /* Checking if the expression is not constant. */ |
11057 | if (watchpoint_exp_is_const (exp)) | |
11058 | { | |
11059 | int len; | |
11060 | ||
11061 | len = exp_end - exp_start; | |
11062 | while (len > 0 && isspace (exp_start[len - 1])) | |
11063 | len--; | |
11064 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11065 | } | |
11066 | ||
c906108c SS |
11067 | exp_valid_block = innermost_block; |
11068 | mark = value_mark (); | |
3a1115a0 | 11069 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11070 | |
bb9d5f81 PP |
11071 | if (val != NULL && just_location) |
11072 | { | |
11073 | saved_bitpos = value_bitpos (val); | |
11074 | saved_bitsize = value_bitsize (val); | |
11075 | } | |
11076 | ||
06a64a0b TT |
11077 | if (just_location) |
11078 | { | |
9c06b0b4 TJB |
11079 | int ret; |
11080 | ||
06a64a0b | 11081 | exp_valid_block = NULL; |
a1442452 | 11082 | val = value_addr (result); |
06a64a0b TT |
11083 | release_value (val); |
11084 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11085 | |
11086 | if (use_mask) | |
11087 | { | |
11088 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11089 | mask); | |
11090 | if (ret == -1) | |
11091 | error (_("This target does not support masked watchpoints.")); | |
11092 | else if (ret == -2) | |
11093 | error (_("Invalid mask or memory region.")); | |
11094 | } | |
06a64a0b TT |
11095 | } |
11096 | else if (val != NULL) | |
fa4727a6 | 11097 | release_value (val); |
c906108c | 11098 | |
bbc13ae3 KS |
11099 | tok = skip_spaces_const (arg); |
11100 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11101 | |
11102 | toklen = end_tok - tok; | |
11103 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11104 | { | |
2d134ed3 PA |
11105 | struct expression *cond; |
11106 | ||
60e1c644 | 11107 | innermost_block = NULL; |
c906108c | 11108 | tok = cond_start = end_tok + 1; |
1bb9788d | 11109 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11110 | |
11111 | /* The watchpoint expression may not be local, but the condition | |
11112 | may still be. E.g.: `watch global if local > 0'. */ | |
11113 | cond_exp_valid_block = innermost_block; | |
11114 | ||
2d134ed3 | 11115 | xfree (cond); |
c906108c SS |
11116 | cond_end = tok; |
11117 | } | |
11118 | if (*tok) | |
8a3fe4f8 | 11119 | error (_("Junk at end of command.")); |
c906108c | 11120 | |
d983da9c | 11121 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11122 | |
11123 | /* If the expression is "local", then set up a "watchpoint scope" | |
11124 | breakpoint at the point where we've left the scope of the watchpoint | |
11125 | expression. Create the scope breakpoint before the watchpoint, so | |
11126 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11127 | if (exp_valid_block && frame) |
d983da9c | 11128 | { |
edb3359d DJ |
11129 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11130 | { | |
11131 | scope_breakpoint | |
a6d9a66e UW |
11132 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11133 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11134 | bp_watchpoint_scope, |
11135 | &momentary_breakpoint_ops); | |
d983da9c | 11136 | |
edb3359d | 11137 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11138 | |
edb3359d DJ |
11139 | /* Automatically delete the breakpoint when it hits. */ |
11140 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11141 | |
edb3359d DJ |
11142 | /* Only break in the proper frame (help with recursion). */ |
11143 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11144 | |
edb3359d | 11145 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11146 | scope_breakpoint->loc->gdbarch |
11147 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11148 | scope_breakpoint->loc->requested_address |
11149 | = frame_unwind_caller_pc (frame); | |
11150 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11151 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11152 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11153 | scope_breakpoint->type); |
11154 | } | |
d983da9c DJ |
11155 | } |
11156 | ||
e8369a73 AB |
11157 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11158 | watchpoints here even if hardware watchpoints are turned off, a call | |
11159 | to update_watchpoint later in this function will cause the type to | |
11160 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11161 | ||
11162 | if (accessflag == hw_read) | |
11163 | bp_type = bp_read_watchpoint; | |
11164 | else if (accessflag == hw_access) | |
11165 | bp_type = bp_access_watchpoint; | |
11166 | else | |
11167 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11168 | |
11169 | w = XCNEW (struct watchpoint); | |
11170 | b = &w->base; | |
348d480f | 11171 | if (use_mask) |
3a5c3e22 PA |
11172 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11173 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11174 | else |
3a5c3e22 PA |
11175 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11176 | &watchpoint_breakpoint_ops); | |
37e4754d | 11177 | b->thread = thread; |
b5de0fa7 | 11178 | b->disposition = disp_donttouch; |
348d480f | 11179 | b->pspace = current_program_space; |
3a5c3e22 PA |
11180 | w->exp = exp; |
11181 | w->exp_valid_block = exp_valid_block; | |
11182 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11183 | if (just_location) |
11184 | { | |
11185 | struct type *t = value_type (val); | |
11186 | CORE_ADDR addr = value_as_address (val); | |
11187 | char *name; | |
11188 | ||
11189 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11190 | name = type_to_string (t); | |
11191 | ||
3a5c3e22 | 11192 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11193 | core_addr_to_string (addr)); |
06a64a0b TT |
11194 | xfree (name); |
11195 | ||
3a5c3e22 | 11196 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11197 | (int) (exp_end - exp_start), exp_start); |
11198 | ||
06a64a0b TT |
11199 | /* The above expression is in C. */ |
11200 | b->language = language_c; | |
11201 | } | |
11202 | else | |
3a5c3e22 | 11203 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11204 | |
11205 | if (use_mask) | |
11206 | { | |
3a5c3e22 | 11207 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11208 | } |
11209 | else | |
11210 | { | |
3a5c3e22 | 11211 | w->val = val; |
bb9d5f81 PP |
11212 | w->val_bitpos = saved_bitpos; |
11213 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11214 | w->val_valid = 1; |
9c06b0b4 | 11215 | } |
77b06cd7 | 11216 | |
c906108c SS |
11217 | if (cond_start) |
11218 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11219 | else | |
11220 | b->cond_string = 0; | |
c5aa993b | 11221 | |
c906108c | 11222 | if (frame) |
f6bc2008 | 11223 | { |
3a5c3e22 PA |
11224 | w->watchpoint_frame = get_frame_id (frame); |
11225 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11226 | } |
c906108c | 11227 | else |
f6bc2008 | 11228 | { |
3a5c3e22 PA |
11229 | w->watchpoint_frame = null_frame_id; |
11230 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11231 | } |
c906108c | 11232 | |
d983da9c | 11233 | if (scope_breakpoint != NULL) |
c906108c | 11234 | { |
d983da9c DJ |
11235 | /* The scope breakpoint is related to the watchpoint. We will |
11236 | need to act on them together. */ | |
11237 | b->related_breakpoint = scope_breakpoint; | |
11238 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11239 | } |
d983da9c | 11240 | |
06a64a0b TT |
11241 | if (!just_location) |
11242 | value_free_to_mark (mark); | |
2d134ed3 | 11243 | |
492d29ea | 11244 | TRY |
a9634178 TJB |
11245 | { |
11246 | /* Finally update the new watchpoint. This creates the locations | |
11247 | that should be inserted. */ | |
3a5c3e22 | 11248 | update_watchpoint (w, 1); |
a9634178 | 11249 | } |
492d29ea | 11250 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11251 | { |
11252 | delete_breakpoint (b); | |
11253 | throw_exception (e); | |
11254 | } | |
492d29ea | 11255 | END_CATCH |
a9634178 | 11256 | |
3ea46bff | 11257 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11258 | do_cleanups (back_to); |
c906108c SS |
11259 | } |
11260 | ||
e09342b5 | 11261 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11262 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11263 | |
c906108c | 11264 | static int |
a9634178 | 11265 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11266 | { |
11267 | int found_memory_cnt = 0; | |
2e70b7b9 | 11268 | struct value *head = v; |
c906108c SS |
11269 | |
11270 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11271 | if (!can_use_hw_watchpoints) |
c906108c | 11272 | return 0; |
c5aa993b | 11273 | |
5c44784c JM |
11274 | /* Make sure that the value of the expression depends only upon |
11275 | memory contents, and values computed from them within GDB. If we | |
11276 | find any register references or function calls, we can't use a | |
11277 | hardware watchpoint. | |
11278 | ||
11279 | The idea here is that evaluating an expression generates a series | |
11280 | of values, one holding the value of every subexpression. (The | |
11281 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11282 | a*b+c.) GDB's values hold almost enough information to establish | |
11283 | the criteria given above --- they identify memory lvalues, | |
11284 | register lvalues, computed values, etcetera. So we can evaluate | |
11285 | the expression, and then scan the chain of values that leaves | |
11286 | behind to decide whether we can detect any possible change to the | |
11287 | expression's final value using only hardware watchpoints. | |
11288 | ||
11289 | However, I don't think that the values returned by inferior | |
11290 | function calls are special in any way. So this function may not | |
11291 | notice that an expression involving an inferior function call | |
11292 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11293 | for (; v; v = value_next (v)) |
c906108c | 11294 | { |
5c44784c | 11295 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11296 | { |
8464be76 DJ |
11297 | if (v != head && value_lazy (v)) |
11298 | /* A lazy memory lvalue in the chain is one that GDB never | |
11299 | needed to fetch; we either just used its address (e.g., | |
11300 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11301 | in `a,b'). This doesn't apply to HEAD; if that is | |
11302 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11303 | ; |
53a5351d | 11304 | else |
5c44784c JM |
11305 | { |
11306 | /* Ahh, memory we actually used! Check if we can cover | |
11307 | it with hardware watchpoints. */ | |
df407dfe | 11308 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11309 | |
11310 | /* We only watch structs and arrays if user asked for it | |
11311 | explicitly, never if they just happen to appear in a | |
11312 | middle of some value chain. */ | |
11313 | if (v == head | |
11314 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11315 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11316 | { | |
42ae5230 | 11317 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11318 | int len; |
11319 | int num_regs; | |
11320 | ||
a9634178 | 11321 | len = (target_exact_watchpoints |
e09342b5 TJB |
11322 | && is_scalar_type_recursive (vtype))? |
11323 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11324 | |
e09342b5 TJB |
11325 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11326 | if (!num_regs) | |
2e70b7b9 MS |
11327 | return 0; |
11328 | else | |
e09342b5 | 11329 | found_memory_cnt += num_regs; |
2e70b7b9 | 11330 | } |
5c44784c | 11331 | } |
c5aa993b | 11332 | } |
5086187c AC |
11333 | else if (VALUE_LVAL (v) != not_lval |
11334 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11335 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11336 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11337 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11338 | } |
11339 | ||
11340 | /* The expression itself looks suitable for using a hardware | |
11341 | watchpoint, but give the target machine a chance to reject it. */ | |
11342 | return found_memory_cnt; | |
11343 | } | |
11344 | ||
8b93c638 | 11345 | void |
84f4c1fe | 11346 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11347 | { |
84f4c1fe | 11348 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11349 | } |
11350 | ||
06a64a0b TT |
11351 | /* A helper function that looks for the "-location" argument and then |
11352 | calls watch_command_1. */ | |
11353 | ||
11354 | static void | |
11355 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11356 | { | |
11357 | int just_location = 0; | |
11358 | ||
11359 | if (arg | |
11360 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11361 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11362 | { | |
e9cafbcc | 11363 | arg = skip_spaces (arg); |
06a64a0b TT |
11364 | just_location = 1; |
11365 | } | |
11366 | ||
84f4c1fe | 11367 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11368 | } |
8926118c | 11369 | |
c5aa993b | 11370 | static void |
fba45db2 | 11371 | watch_command (char *arg, int from_tty) |
c906108c | 11372 | { |
06a64a0b | 11373 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11374 | } |
11375 | ||
8b93c638 | 11376 | void |
84f4c1fe | 11377 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11378 | { |
84f4c1fe | 11379 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11380 | } |
8926118c | 11381 | |
c5aa993b | 11382 | static void |
fba45db2 | 11383 | rwatch_command (char *arg, int from_tty) |
c906108c | 11384 | { |
06a64a0b | 11385 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11386 | } |
11387 | ||
8b93c638 | 11388 | void |
84f4c1fe | 11389 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11390 | { |
84f4c1fe | 11391 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11392 | } |
8926118c | 11393 | |
c5aa993b | 11394 | static void |
fba45db2 | 11395 | awatch_command (char *arg, int from_tty) |
c906108c | 11396 | { |
06a64a0b | 11397 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11398 | } |
c906108c | 11399 | \f |
c5aa993b | 11400 | |
43ff13b4 | 11401 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11402 | because it uses the mechanisms of breakpoints. */ |
11403 | ||
bfec99b2 PA |
11404 | struct until_break_command_continuation_args |
11405 | { | |
11406 | struct breakpoint *breakpoint; | |
11407 | struct breakpoint *breakpoint2; | |
186c406b | 11408 | int thread_num; |
bfec99b2 PA |
11409 | }; |
11410 | ||
43ff13b4 | 11411 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11412 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11413 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11414 | command. */ |
c2c6d25f | 11415 | static void |
fa4cd53f | 11416 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11417 | { |
bfec99b2 PA |
11418 | struct until_break_command_continuation_args *a = arg; |
11419 | ||
11420 | delete_breakpoint (a->breakpoint); | |
11421 | if (a->breakpoint2) | |
11422 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11423 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11424 | } |
11425 | ||
c906108c | 11426 | void |
ae66c1fc | 11427 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11428 | { |
11429 | struct symtabs_and_lines sals; | |
11430 | struct symtab_and_line sal; | |
8556afb4 PA |
11431 | struct frame_info *frame; |
11432 | struct gdbarch *frame_gdbarch; | |
11433 | struct frame_id stack_frame_id; | |
11434 | struct frame_id caller_frame_id; | |
c906108c | 11435 | struct breakpoint *breakpoint; |
f107f563 | 11436 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11437 | struct cleanup *old_chain; |
186c406b TT |
11438 | int thread; |
11439 | struct thread_info *tp; | |
c906108c | 11440 | |
70509625 | 11441 | clear_proceed_status (0); |
c906108c SS |
11442 | |
11443 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11444 | this function. */ |
c5aa993b | 11445 | |
1bfeeb0f | 11446 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11447 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11448 | get_last_displayed_symtab (), |
f8eba3c6 | 11449 | get_last_displayed_line ()); |
c906108c | 11450 | else |
f8eba3c6 TT |
11451 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11452 | (struct symtab *) NULL, 0); | |
c5aa993b | 11453 | |
c906108c | 11454 | if (sals.nelts != 1) |
8a3fe4f8 | 11455 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11456 | |
c906108c | 11457 | sal = sals.sals[0]; |
4a64f543 | 11458 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11459 | |
c906108c | 11460 | if (*arg) |
8a3fe4f8 | 11461 | error (_("Junk at end of arguments.")); |
c5aa993b | 11462 | |
c906108c | 11463 | resolve_sal_pc (&sal); |
c5aa993b | 11464 | |
186c406b TT |
11465 | tp = inferior_thread (); |
11466 | thread = tp->num; | |
11467 | ||
883bc8d1 PA |
11468 | old_chain = make_cleanup (null_cleanup, NULL); |
11469 | ||
8556afb4 PA |
11470 | /* Note linespec handling above invalidates the frame chain. |
11471 | Installing a breakpoint also invalidates the frame chain (as it | |
11472 | may need to switch threads), so do any frame handling before | |
11473 | that. */ | |
11474 | ||
11475 | frame = get_selected_frame (NULL); | |
11476 | frame_gdbarch = get_frame_arch (frame); | |
11477 | stack_frame_id = get_stack_frame_id (frame); | |
11478 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11479 | |
ae66c1fc EZ |
11480 | /* Keep within the current frame, or in frames called by the current |
11481 | one. */ | |
edb3359d | 11482 | |
883bc8d1 | 11483 | if (frame_id_p (caller_frame_id)) |
c906108c | 11484 | { |
883bc8d1 PA |
11485 | struct symtab_and_line sal2; |
11486 | ||
11487 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11488 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11489 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11490 | sal2, |
11491 | caller_frame_id, | |
f107f563 VP |
11492 | bp_until); |
11493 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11494 | |
883bc8d1 | 11495 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11496 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11497 | } |
c5aa993b | 11498 | |
c70a6932 JK |
11499 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11500 | frame = NULL; | |
11501 | ||
883bc8d1 PA |
11502 | if (anywhere) |
11503 | /* If the user told us to continue until a specified location, | |
11504 | we don't specify a frame at which we need to stop. */ | |
11505 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11506 | null_frame_id, bp_until); | |
11507 | else | |
11508 | /* Otherwise, specify the selected frame, because we want to stop | |
11509 | only at the very same frame. */ | |
11510 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11511 | stack_frame_id, bp_until); | |
11512 | make_cleanup_delete_breakpoint (breakpoint); | |
11513 | ||
64ce06e4 | 11514 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f107f563 | 11515 | |
4a64f543 MS |
11516 | /* If we are running asynchronously, and proceed call above has |
11517 | actually managed to start the target, arrange for breakpoints to | |
11518 | be deleted when the target stops. Otherwise, we're already | |
11519 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11520 | |
8ea051c5 | 11521 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11522 | { |
bfec99b2 PA |
11523 | struct until_break_command_continuation_args *args; |
11524 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11525 | |
bfec99b2 PA |
11526 | args->breakpoint = breakpoint; |
11527 | args->breakpoint2 = breakpoint2; | |
186c406b | 11528 | args->thread_num = thread; |
f107f563 VP |
11529 | |
11530 | discard_cleanups (old_chain); | |
95e54da7 PA |
11531 | add_continuation (inferior_thread (), |
11532 | until_break_command_continuation, args, | |
604ead4a | 11533 | xfree); |
f107f563 VP |
11534 | } |
11535 | else | |
c5aa993b | 11536 | do_cleanups (old_chain); |
c906108c | 11537 | } |
ae66c1fc | 11538 | |
c906108c SS |
11539 | /* This function attempts to parse an optional "if <cond>" clause |
11540 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11541 | |
c906108c SS |
11542 | Else, it returns a pointer to the condition string. (It does not |
11543 | attempt to evaluate the string against a particular block.) And, | |
11544 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11545 | if clause in the arg string. */ |
53a5351d | 11546 | |
916703c0 | 11547 | char * |
fba45db2 | 11548 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11549 | { |
c5aa993b JM |
11550 | char *cond_string; |
11551 | ||
11552 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11553 | return NULL; |
c5aa993b | 11554 | |
4a64f543 | 11555 | /* Skip the "if" keyword. */ |
c906108c | 11556 | (*arg) += 2; |
c5aa993b | 11557 | |
c906108c | 11558 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11559 | condition string. */ |
e9cafbcc | 11560 | *arg = skip_spaces (*arg); |
c906108c | 11561 | cond_string = *arg; |
c5aa993b | 11562 | |
4a64f543 MS |
11563 | /* Assume that the condition occupies the remainder of the arg |
11564 | string. */ | |
c906108c | 11565 | (*arg) += strlen (cond_string); |
c5aa993b | 11566 | |
c906108c SS |
11567 | return cond_string; |
11568 | } | |
c5aa993b | 11569 | |
c906108c SS |
11570 | /* Commands to deal with catching events, such as signals, exceptions, |
11571 | process start/exit, etc. */ | |
c5aa993b JM |
11572 | |
11573 | typedef enum | |
11574 | { | |
44feb3ce TT |
11575 | catch_fork_temporary, catch_vfork_temporary, |
11576 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11577 | } |
11578 | catch_fork_kind; | |
11579 | ||
c906108c | 11580 | static void |
cc59ec59 MS |
11581 | catch_fork_command_1 (char *arg, int from_tty, |
11582 | struct cmd_list_element *command) | |
c906108c | 11583 | { |
a6d9a66e | 11584 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11585 | char *cond_string = NULL; |
44feb3ce TT |
11586 | catch_fork_kind fork_kind; |
11587 | int tempflag; | |
11588 | ||
11589 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11590 | tempflag = (fork_kind == catch_fork_temporary | |
11591 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11592 | |
44feb3ce TT |
11593 | if (!arg) |
11594 | arg = ""; | |
e9cafbcc | 11595 | arg = skip_spaces (arg); |
c5aa993b | 11596 | |
c906108c | 11597 | /* The allowed syntax is: |
c5aa993b JM |
11598 | catch [v]fork |
11599 | catch [v]fork if <cond> | |
11600 | ||
4a64f543 | 11601 | First, check if there's an if clause. */ |
c906108c | 11602 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11603 | |
c906108c | 11604 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11605 | error (_("Junk at end of arguments.")); |
c5aa993b | 11606 | |
c906108c | 11607 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11608 | and enable reporting of such events. */ |
c5aa993b JM |
11609 | switch (fork_kind) |
11610 | { | |
44feb3ce TT |
11611 | case catch_fork_temporary: |
11612 | case catch_fork_permanent: | |
a6d9a66e | 11613 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11614 | &catch_fork_breakpoint_ops); |
c906108c | 11615 | break; |
44feb3ce TT |
11616 | case catch_vfork_temporary: |
11617 | case catch_vfork_permanent: | |
a6d9a66e | 11618 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11619 | &catch_vfork_breakpoint_ops); |
c906108c | 11620 | break; |
c5aa993b | 11621 | default: |
8a3fe4f8 | 11622 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11623 | break; |
c5aa993b | 11624 | } |
c906108c SS |
11625 | } |
11626 | ||
11627 | static void | |
cc59ec59 MS |
11628 | catch_exec_command_1 (char *arg, int from_tty, |
11629 | struct cmd_list_element *command) | |
c906108c | 11630 | { |
b4d90040 | 11631 | struct exec_catchpoint *c; |
a6d9a66e | 11632 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11633 | int tempflag; |
c5aa993b | 11634 | char *cond_string = NULL; |
c906108c | 11635 | |
44feb3ce TT |
11636 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11637 | ||
11638 | if (!arg) | |
11639 | arg = ""; | |
e9cafbcc | 11640 | arg = skip_spaces (arg); |
c906108c SS |
11641 | |
11642 | /* The allowed syntax is: | |
c5aa993b JM |
11643 | catch exec |
11644 | catch exec if <cond> | |
c906108c | 11645 | |
4a64f543 | 11646 | First, check if there's an if clause. */ |
c906108c SS |
11647 | cond_string = ep_parse_optional_if_clause (&arg); |
11648 | ||
11649 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11650 | error (_("Junk at end of arguments.")); |
c906108c | 11651 | |
b4d90040 PA |
11652 | c = XNEW (struct exec_catchpoint); |
11653 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11654 | &catch_exec_breakpoint_ops); | |
11655 | c->exec_pathname = NULL; | |
11656 | ||
3ea46bff | 11657 | install_breakpoint (0, &c->base, 1); |
c906108c | 11658 | } |
c5aa993b | 11659 | |
9ac4176b | 11660 | void |
28010a5d PA |
11661 | init_ada_exception_breakpoint (struct breakpoint *b, |
11662 | struct gdbarch *gdbarch, | |
11663 | struct symtab_and_line sal, | |
11664 | char *addr_string, | |
c0a91b2b | 11665 | const struct breakpoint_ops *ops, |
28010a5d | 11666 | int tempflag, |
349774ef | 11667 | int enabled, |
28010a5d | 11668 | int from_tty) |
f7f9143b | 11669 | { |
f7f9143b JB |
11670 | if (from_tty) |
11671 | { | |
5af949e3 UW |
11672 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11673 | if (!loc_gdbarch) | |
11674 | loc_gdbarch = gdbarch; | |
11675 | ||
6c95b8df PA |
11676 | describe_other_breakpoints (loc_gdbarch, |
11677 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11678 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11679 | version for exception catchpoints, because two catchpoints | |
11680 | used for different exception names will use the same address. | |
11681 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11682 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11683 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11684 | the user what type of catchpoint it is. The above is good |
11685 | enough for now, though. */ | |
11686 | } | |
11687 | ||
28010a5d | 11688 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11689 | |
349774ef | 11690 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11691 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11692 | b->addr_string = addr_string; |
11693 | b->language = language_ada; | |
f7f9143b JB |
11694 | } |
11695 | ||
c906108c | 11696 | static void |
fba45db2 | 11697 | catch_command (char *arg, int from_tty) |
c906108c | 11698 | { |
44feb3ce | 11699 | error (_("Catch requires an event name.")); |
c906108c SS |
11700 | } |
11701 | \f | |
11702 | ||
11703 | static void | |
fba45db2 | 11704 | tcatch_command (char *arg, int from_tty) |
c906108c | 11705 | { |
44feb3ce | 11706 | error (_("Catch requires an event name.")); |
c906108c SS |
11707 | } |
11708 | ||
8a2c437b TT |
11709 | /* A qsort comparison function that sorts breakpoints in order. */ |
11710 | ||
11711 | static int | |
11712 | compare_breakpoints (const void *a, const void *b) | |
11713 | { | |
11714 | const breakpoint_p *ba = a; | |
11715 | uintptr_t ua = (uintptr_t) *ba; | |
11716 | const breakpoint_p *bb = b; | |
11717 | uintptr_t ub = (uintptr_t) *bb; | |
11718 | ||
11719 | if ((*ba)->number < (*bb)->number) | |
11720 | return -1; | |
11721 | else if ((*ba)->number > (*bb)->number) | |
11722 | return 1; | |
11723 | ||
11724 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11725 | the number 0. */ | |
11726 | if (ua < ub) | |
11727 | return -1; | |
94b0e70d | 11728 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11729 | } |
11730 | ||
80f8a6eb | 11731 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11732 | |
11733 | static void | |
fba45db2 | 11734 | clear_command (char *arg, int from_tty) |
c906108c | 11735 | { |
8a2c437b | 11736 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11737 | VEC(breakpoint_p) *found = 0; |
11738 | int ix; | |
c906108c SS |
11739 | int default_match; |
11740 | struct symtabs_and_lines sals; | |
11741 | struct symtab_and_line sal; | |
c906108c | 11742 | int i; |
8a2c437b | 11743 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11744 | |
11745 | if (arg) | |
11746 | { | |
39cf75f7 DE |
11747 | sals = decode_line_with_current_source (arg, |
11748 | (DECODE_LINE_FUNFIRSTLINE | |
11749 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11750 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11751 | default_match = 0; |
11752 | } | |
11753 | else | |
11754 | { | |
c5aa993b | 11755 | sals.sals = (struct symtab_and_line *) |
c906108c | 11756 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11757 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11758 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11759 | |
11760 | /* Set sal's line, symtab, pc, and pspace to the values | |
11761 | corresponding to the last call to print_frame_info. If the | |
11762 | codepoint is not valid, this will set all the fields to 0. */ | |
11763 | get_last_displayed_sal (&sal); | |
c906108c | 11764 | if (sal.symtab == 0) |
8a3fe4f8 | 11765 | error (_("No source file specified.")); |
c906108c SS |
11766 | |
11767 | sals.sals[0] = sal; | |
11768 | sals.nelts = 1; | |
11769 | ||
11770 | default_match = 1; | |
11771 | } | |
11772 | ||
4a64f543 MS |
11773 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11774 | seems, because all existing breakpoints typically have both | |
11775 | file/line and pc set. So, if clear is given file/line, we can | |
11776 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11777 | |
11778 | We only support clearing given the address explicitly | |
11779 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11780 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11781 | due to optimization, all in one block. |
4a64f543 MS |
11782 | |
11783 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11784 | PC corresponding to the same file:line, the breakpoint won't |
11785 | be cleared. We probably can still clear the breakpoint, but | |
11786 | since the other PC value is never presented to user, user | |
11787 | can only find it by guessing, and it does not seem important | |
11788 | to support that. */ | |
11789 | ||
4a64f543 MS |
11790 | /* For each line spec given, delete bps which correspond to it. Do |
11791 | it in two passes, solely to preserve the current behavior that | |
11792 | from_tty is forced true if we delete more than one | |
11793 | breakpoint. */ | |
c906108c | 11794 | |
80f8a6eb | 11795 | found = NULL; |
8a2c437b | 11796 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11797 | for (i = 0; i < sals.nelts; i++) |
11798 | { | |
05cba821 JK |
11799 | const char *sal_fullname; |
11800 | ||
c906108c | 11801 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11802 | If line given (pc == 0), clear all bpts on specified line. |
11803 | If defaulting, clear all bpts on default line | |
c906108c | 11804 | or at default pc. |
c5aa993b JM |
11805 | |
11806 | defaulting sal.pc != 0 tests to do | |
11807 | ||
11808 | 0 1 pc | |
11809 | 1 1 pc _and_ line | |
11810 | 0 0 line | |
11811 | 1 0 <can't happen> */ | |
c906108c SS |
11812 | |
11813 | sal = sals.sals[i]; | |
05cba821 JK |
11814 | sal_fullname = (sal.symtab == NULL |
11815 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11816 | |
4a64f543 | 11817 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11818 | ALL_BREAKPOINTS (b) |
c5aa993b | 11819 | { |
0d381245 | 11820 | int match = 0; |
4a64f543 | 11821 | /* Are we going to delete b? */ |
cc60f2e3 | 11822 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11823 | { |
11824 | struct bp_location *loc = b->loc; | |
11825 | for (; loc; loc = loc->next) | |
11826 | { | |
f8eba3c6 TT |
11827 | /* If the user specified file:line, don't allow a PC |
11828 | match. This matches historical gdb behavior. */ | |
11829 | int pc_match = (!sal.explicit_line | |
11830 | && sal.pc | |
11831 | && (loc->pspace == sal.pspace) | |
11832 | && (loc->address == sal.pc) | |
11833 | && (!section_is_overlay (loc->section) | |
11834 | || loc->section == sal.section)); | |
4aac40c8 TT |
11835 | int line_match = 0; |
11836 | ||
11837 | if ((default_match || sal.explicit_line) | |
2f202fde | 11838 | && loc->symtab != NULL |
05cba821 | 11839 | && sal_fullname != NULL |
4aac40c8 | 11840 | && sal.pspace == loc->pspace |
05cba821 JK |
11841 | && loc->line_number == sal.line |
11842 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11843 | sal_fullname) == 0) | |
11844 | line_match = 1; | |
4aac40c8 | 11845 | |
0d381245 VP |
11846 | if (pc_match || line_match) |
11847 | { | |
11848 | match = 1; | |
11849 | break; | |
11850 | } | |
11851 | } | |
11852 | } | |
11853 | ||
11854 | if (match) | |
d6e956e5 | 11855 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11856 | } |
80f8a6eb | 11857 | } |
8a2c437b | 11858 | |
80f8a6eb | 11859 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11860 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11861 | { |
11862 | if (arg) | |
8a3fe4f8 | 11863 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11864 | else |
8a3fe4f8 | 11865 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11866 | } |
c906108c | 11867 | |
8a2c437b TT |
11868 | /* Remove duplicates from the vec. */ |
11869 | qsort (VEC_address (breakpoint_p, found), | |
11870 | VEC_length (breakpoint_p, found), | |
11871 | sizeof (breakpoint_p), | |
11872 | compare_breakpoints); | |
11873 | prev = VEC_index (breakpoint_p, found, 0); | |
11874 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11875 | { | |
11876 | if (b == prev) | |
11877 | { | |
11878 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11879 | --ix; | |
11880 | } | |
11881 | } | |
11882 | ||
d6e956e5 | 11883 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11884 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11885 | if (from_tty) |
a3f17187 | 11886 | { |
d6e956e5 | 11887 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11888 | printf_unfiltered (_("Deleted breakpoint ")); |
11889 | else | |
11890 | printf_unfiltered (_("Deleted breakpoints ")); | |
11891 | } | |
d6e956e5 VP |
11892 | |
11893 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11894 | { |
c5aa993b | 11895 | if (from_tty) |
d6e956e5 VP |
11896 | printf_unfiltered ("%d ", b->number); |
11897 | delete_breakpoint (b); | |
c906108c | 11898 | } |
80f8a6eb MS |
11899 | if (from_tty) |
11900 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11901 | |
11902 | do_cleanups (cleanups); | |
c906108c SS |
11903 | } |
11904 | \f | |
11905 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11906 | all breakpoints that are marked for deletion, whether hit or not. | |
11907 | This is called after any breakpoint is hit, or after errors. */ | |
11908 | ||
11909 | void | |
fba45db2 | 11910 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11911 | { |
35df4500 | 11912 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11913 | |
11914 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11915 | if (bs->breakpoint_at |
11916 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11917 | && bs->stop) |
f431efe5 | 11918 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11919 | |
35df4500 | 11920 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11921 | { |
b5de0fa7 | 11922 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11923 | delete_breakpoint (b); |
11924 | } | |
c906108c SS |
11925 | } |
11926 | ||
4a64f543 MS |
11927 | /* A comparison function for bp_location AP and BP being interfaced to |
11928 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11929 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11930 | secondarily by ordering first permanent elements and |
4a64f543 | 11931 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11932 | qsort being an unstable algorithm. */ |
876fa593 JK |
11933 | |
11934 | static int | |
494cfb0f | 11935 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 11936 | { |
494cfb0f JK |
11937 | struct bp_location *a = *(void **) ap; |
11938 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
11939 | |
11940 | if (a->address != b->address) | |
11941 | return (a->address > b->address) - (a->address < b->address); | |
11942 | ||
dea2aa5f LM |
11943 | /* Sort locations at the same address by their pspace number, keeping |
11944 | locations of the same inferior (in a multi-inferior environment) | |
11945 | grouped. */ | |
11946 | ||
11947 | if (a->pspace->num != b->pspace->num) | |
11948 | return ((a->pspace->num > b->pspace->num) | |
11949 | - (a->pspace->num < b->pspace->num)); | |
11950 | ||
876fa593 | 11951 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11952 | if (a->permanent != b->permanent) |
11953 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11954 | |
c56a97f9 JK |
11955 | /* Make the internal GDB representation stable across GDB runs |
11956 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11957 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11958 | |
11959 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11960 | return ((a->owner->number > b->owner->number) |
11961 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11962 | |
11963 | return (a > b) - (a < b); | |
11964 | } | |
11965 | ||
876fa593 | 11966 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
11967 | bp_location_shadow_len_after_address_max according to the current |
11968 | content of the bp_location array. */ | |
f7545552 TT |
11969 | |
11970 | static void | |
876fa593 | 11971 | bp_location_target_extensions_update (void) |
f7545552 | 11972 | { |
876fa593 JK |
11973 | struct bp_location *bl, **blp_tmp; |
11974 | ||
11975 | bp_location_placed_address_before_address_max = 0; | |
11976 | bp_location_shadow_len_after_address_max = 0; | |
11977 | ||
11978 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11979 | { | |
11980 | CORE_ADDR start, end, addr; | |
11981 | ||
11982 | if (!bp_location_has_shadow (bl)) | |
11983 | continue; | |
11984 | ||
11985 | start = bl->target_info.placed_address; | |
11986 | end = start + bl->target_info.shadow_len; | |
11987 | ||
11988 | gdb_assert (bl->address >= start); | |
11989 | addr = bl->address - start; | |
11990 | if (addr > bp_location_placed_address_before_address_max) | |
11991 | bp_location_placed_address_before_address_max = addr; | |
11992 | ||
11993 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11994 | ||
11995 | gdb_assert (bl->address < end); | |
11996 | addr = end - bl->address; | |
11997 | if (addr > bp_location_shadow_len_after_address_max) | |
11998 | bp_location_shadow_len_after_address_max = addr; | |
11999 | } | |
f7545552 TT |
12000 | } |
12001 | ||
1e4d1764 YQ |
12002 | /* Download tracepoint locations if they haven't been. */ |
12003 | ||
12004 | static void | |
12005 | download_tracepoint_locations (void) | |
12006 | { | |
7ed2c994 | 12007 | struct breakpoint *b; |
1e4d1764 YQ |
12008 | struct cleanup *old_chain; |
12009 | ||
12010 | if (!target_can_download_tracepoint ()) | |
12011 | return; | |
12012 | ||
12013 | old_chain = save_current_space_and_thread (); | |
12014 | ||
7ed2c994 | 12015 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12016 | { |
7ed2c994 | 12017 | struct bp_location *bl; |
1e4d1764 | 12018 | struct tracepoint *t; |
f2a8bc8a | 12019 | int bp_location_downloaded = 0; |
1e4d1764 | 12020 | |
7ed2c994 | 12021 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12022 | ? !may_insert_fast_tracepoints |
12023 | : !may_insert_tracepoints)) | |
12024 | continue; | |
12025 | ||
7ed2c994 YQ |
12026 | for (bl = b->loc; bl; bl = bl->next) |
12027 | { | |
12028 | /* In tracepoint, locations are _never_ duplicated, so | |
12029 | should_be_inserted is equivalent to | |
12030 | unduplicated_should_be_inserted. */ | |
12031 | if (!should_be_inserted (bl) || bl->inserted) | |
12032 | continue; | |
1e4d1764 | 12033 | |
7ed2c994 | 12034 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12035 | |
7ed2c994 | 12036 | target_download_tracepoint (bl); |
1e4d1764 | 12037 | |
7ed2c994 | 12038 | bl->inserted = 1; |
f2a8bc8a | 12039 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12040 | } |
12041 | t = (struct tracepoint *) b; | |
12042 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12043 | if (bp_location_downloaded) |
12044 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12045 | } |
12046 | ||
12047 | do_cleanups (old_chain); | |
12048 | } | |
12049 | ||
934709f0 PW |
12050 | /* Swap the insertion/duplication state between two locations. */ |
12051 | ||
12052 | static void | |
12053 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12054 | { | |
12055 | const int left_inserted = left->inserted; | |
12056 | const int left_duplicate = left->duplicate; | |
b775012e | 12057 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12058 | const struct bp_target_info left_target_info = left->target_info; |
12059 | ||
1e4d1764 YQ |
12060 | /* Locations of tracepoints can never be duplicated. */ |
12061 | if (is_tracepoint (left->owner)) | |
12062 | gdb_assert (!left->duplicate); | |
12063 | if (is_tracepoint (right->owner)) | |
12064 | gdb_assert (!right->duplicate); | |
12065 | ||
934709f0 PW |
12066 | left->inserted = right->inserted; |
12067 | left->duplicate = right->duplicate; | |
b775012e | 12068 | left->needs_update = right->needs_update; |
934709f0 PW |
12069 | left->target_info = right->target_info; |
12070 | right->inserted = left_inserted; | |
12071 | right->duplicate = left_duplicate; | |
b775012e | 12072 | right->needs_update = left_needs_update; |
934709f0 PW |
12073 | right->target_info = left_target_info; |
12074 | } | |
12075 | ||
b775012e LM |
12076 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12077 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12078 | conditions on the target's side. Such conditions need to be updated on | |
12079 | the target. */ | |
12080 | ||
12081 | static void | |
12082 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12083 | { | |
12084 | struct bp_location **locp = NULL, **loc2p; | |
12085 | struct bp_location *loc; | |
12086 | CORE_ADDR address = 0; | |
12087 | int pspace_num; | |
12088 | ||
12089 | address = bl->address; | |
12090 | pspace_num = bl->pspace->num; | |
12091 | ||
12092 | /* This is only meaningful if the target is | |
12093 | evaluating conditions and if the user has | |
12094 | opted for condition evaluation on the target's | |
12095 | side. */ | |
12096 | if (gdb_evaluates_breakpoint_condition_p () | |
12097 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12098 | return; | |
12099 | ||
12100 | /* Flag all breakpoint locations with this address and | |
12101 | the same program space as the location | |
12102 | as "its condition has changed". We need to | |
12103 | update the conditions on the target's side. */ | |
12104 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12105 | { | |
12106 | loc = *loc2p; | |
12107 | ||
12108 | if (!is_breakpoint (loc->owner) | |
12109 | || pspace_num != loc->pspace->num) | |
12110 | continue; | |
12111 | ||
12112 | /* Flag the location appropriately. We use a different state to | |
12113 | let everyone know that we already updated the set of locations | |
12114 | with addr bl->address and program space bl->pspace. This is so | |
12115 | we don't have to keep calling these functions just to mark locations | |
12116 | that have already been marked. */ | |
12117 | loc->condition_changed = condition_updated; | |
12118 | ||
12119 | /* Free the agent expression bytecode as well. We will compute | |
12120 | it later on. */ | |
12121 | if (loc->cond_bytecode) | |
12122 | { | |
12123 | free_agent_expr (loc->cond_bytecode); | |
12124 | loc->cond_bytecode = NULL; | |
12125 | } | |
12126 | } | |
12127 | } | |
44702360 PA |
12128 | /* Called whether new breakpoints are created, or existing breakpoints |
12129 | deleted, to update the global location list and recompute which | |
12130 | locations are duplicate of which. | |
b775012e | 12131 | |
04086b45 PA |
12132 | The INSERT_MODE flag determines whether locations may not, may, or |
12133 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12134 | info. */ | |
b60e7edf | 12135 | |
0d381245 | 12136 | static void |
44702360 | 12137 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12138 | { |
74960c60 | 12139 | struct breakpoint *b; |
876fa593 | 12140 | struct bp_location **locp, *loc; |
f7545552 | 12141 | struct cleanup *cleanups; |
b775012e LM |
12142 | /* Last breakpoint location address that was marked for update. */ |
12143 | CORE_ADDR last_addr = 0; | |
12144 | /* Last breakpoint location program space that was marked for update. */ | |
12145 | int last_pspace_num = -1; | |
f7545552 | 12146 | |
2d134ed3 PA |
12147 | /* Used in the duplicates detection below. When iterating over all |
12148 | bp_locations, points to the first bp_location of a given address. | |
12149 | Breakpoints and watchpoints of different types are never | |
12150 | duplicates of each other. Keep one pointer for each type of | |
12151 | breakpoint/watchpoint, so we only need to loop over all locations | |
12152 | once. */ | |
12153 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12154 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12155 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12156 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12157 | |
4a64f543 MS |
12158 | /* Saved former bp_location array which we compare against the newly |
12159 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12160 | struct bp_location **old_location, **old_locp; |
12161 | unsigned old_location_count; | |
12162 | ||
12163 | old_location = bp_location; | |
12164 | old_location_count = bp_location_count; | |
12165 | bp_location = NULL; | |
12166 | bp_location_count = 0; | |
12167 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12168 | |
74960c60 | 12169 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12170 | for (loc = b->loc; loc; loc = loc->next) |
12171 | bp_location_count++; | |
12172 | ||
12173 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12174 | locp = bp_location; | |
12175 | ALL_BREAKPOINTS (b) | |
12176 | for (loc = b->loc; loc; loc = loc->next) | |
12177 | *locp++ = loc; | |
12178 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12179 | bp_location_compare); |
876fa593 JK |
12180 | |
12181 | bp_location_target_extensions_update (); | |
74960c60 | 12182 | |
4a64f543 MS |
12183 | /* Identify bp_location instances that are no longer present in the |
12184 | new list, and therefore should be freed. Note that it's not | |
12185 | necessary that those locations should be removed from inferior -- | |
12186 | if there's another location at the same address (previously | |
12187 | marked as duplicate), we don't need to remove/insert the | |
12188 | location. | |
876fa593 | 12189 | |
4a64f543 MS |
12190 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12191 | and former bp_location array state respectively. */ | |
876fa593 JK |
12192 | |
12193 | locp = bp_location; | |
12194 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12195 | old_locp++) | |
74960c60 | 12196 | { |
876fa593 | 12197 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12198 | struct bp_location **loc2p; |
876fa593 | 12199 | |
e5dd4106 | 12200 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12201 | not, we have to free it. */ |
c7d46a38 | 12202 | int found_object = 0; |
20874c92 VP |
12203 | /* Tells if the location should remain inserted in the target. */ |
12204 | int keep_in_target = 0; | |
12205 | int removed = 0; | |
876fa593 | 12206 | |
4a64f543 MS |
12207 | /* Skip LOCP entries which will definitely never be needed. |
12208 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12209 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12210 | && (*locp)->address < old_loc->address) |
876fa593 | 12211 | locp++; |
c7d46a38 PA |
12212 | |
12213 | for (loc2p = locp; | |
12214 | (loc2p < bp_location + bp_location_count | |
12215 | && (*loc2p)->address == old_loc->address); | |
12216 | loc2p++) | |
12217 | { | |
b775012e LM |
12218 | /* Check if this is a new/duplicated location or a duplicated |
12219 | location that had its condition modified. If so, we want to send | |
12220 | its condition to the target if evaluation of conditions is taking | |
12221 | place there. */ | |
12222 | if ((*loc2p)->condition_changed == condition_modified | |
12223 | && (last_addr != old_loc->address | |
12224 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12225 | { |
b775012e LM |
12226 | force_breakpoint_reinsertion (*loc2p); |
12227 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12228 | } |
b775012e LM |
12229 | |
12230 | if (*loc2p == old_loc) | |
12231 | found_object = 1; | |
c7d46a38 | 12232 | } |
74960c60 | 12233 | |
b775012e LM |
12234 | /* We have already handled this address, update it so that we don't |
12235 | have to go through updates again. */ | |
12236 | last_addr = old_loc->address; | |
12237 | ||
12238 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12239 | if (!found_object) | |
12240 | force_breakpoint_reinsertion (old_loc); | |
12241 | ||
4a64f543 MS |
12242 | /* If this location is no longer present, and inserted, look if |
12243 | there's maybe a new location at the same address. If so, | |
12244 | mark that one inserted, and don't remove this one. This is | |
12245 | needed so that we don't have a time window where a breakpoint | |
12246 | at certain location is not inserted. */ | |
74960c60 | 12247 | |
876fa593 | 12248 | if (old_loc->inserted) |
0d381245 | 12249 | { |
4a64f543 MS |
12250 | /* If the location is inserted now, we might have to remove |
12251 | it. */ | |
74960c60 | 12252 | |
876fa593 | 12253 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12254 | { |
4a64f543 MS |
12255 | /* The location is still present in the location list, |
12256 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12257 | keep_in_target = 1; |
74960c60 VP |
12258 | } |
12259 | else | |
12260 | { | |
b775012e LM |
12261 | /* This location still exists, but it won't be kept in the |
12262 | target since it may have been disabled. We proceed to | |
12263 | remove its target-side condition. */ | |
12264 | ||
4a64f543 MS |
12265 | /* The location is either no longer present, or got |
12266 | disabled. See if there's another location at the | |
12267 | same address, in which case we don't need to remove | |
12268 | this one from the target. */ | |
876fa593 | 12269 | |
2bdf28a0 | 12270 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12271 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12272 | { | |
876fa593 | 12273 | for (loc2p = locp; |
c7d46a38 PA |
12274 | (loc2p < bp_location + bp_location_count |
12275 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12276 | loc2p++) |
12277 | { | |
12278 | struct bp_location *loc2 = *loc2p; | |
12279 | ||
2d134ed3 | 12280 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12281 | { |
85d721b8 PA |
12282 | /* Read watchpoint locations are switched to |
12283 | access watchpoints, if the former are not | |
12284 | supported, but the latter are. */ | |
12285 | if (is_hardware_watchpoint (old_loc->owner)) | |
12286 | { | |
12287 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12288 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12289 | } | |
12290 | ||
934709f0 PW |
12291 | /* loc2 is a duplicated location. We need to check |
12292 | if it should be inserted in case it will be | |
12293 | unduplicated. */ | |
12294 | if (loc2 != old_loc | |
12295 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12296 | { |
934709f0 | 12297 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12298 | keep_in_target = 1; |
12299 | break; | |
12300 | } | |
876fa593 JK |
12301 | } |
12302 | } | |
12303 | } | |
74960c60 VP |
12304 | } |
12305 | ||
20874c92 VP |
12306 | if (!keep_in_target) |
12307 | { | |
876fa593 | 12308 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12309 | { |
4a64f543 MS |
12310 | /* This is just about all we can do. We could keep |
12311 | this location on the global list, and try to | |
12312 | remove it next time, but there's no particular | |
12313 | reason why we will succeed next time. | |
20874c92 | 12314 | |
4a64f543 MS |
12315 | Note that at this point, old_loc->owner is still |
12316 | valid, as delete_breakpoint frees the breakpoint | |
12317 | only after calling us. */ | |
3e43a32a MS |
12318 | printf_filtered (_("warning: Error removing " |
12319 | "breakpoint %d\n"), | |
876fa593 | 12320 | old_loc->owner->number); |
20874c92 VP |
12321 | } |
12322 | removed = 1; | |
12323 | } | |
0d381245 | 12324 | } |
74960c60 VP |
12325 | |
12326 | if (!found_object) | |
1c5cfe86 | 12327 | { |
db82e815 | 12328 | if (removed && non_stop |
1cf4d951 | 12329 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12330 | { |
db82e815 PA |
12331 | /* This location was removed from the target. In |
12332 | non-stop mode, a race condition is possible where | |
12333 | we've removed a breakpoint, but stop events for that | |
12334 | breakpoint are already queued and will arrive later. | |
12335 | We apply an heuristic to be able to distinguish such | |
12336 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12337 | breakpoint location for a bit, and will retire it | |
12338 | after we see some number of events. The theory here | |
12339 | is that reporting of events should, "on the average", | |
12340 | be fair, so after a while we'll see events from all | |
12341 | threads that have anything of interest, and no longer | |
12342 | need to keep this breakpoint location around. We | |
12343 | don't hold locations forever so to reduce chances of | |
12344 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12345 | SIGTRAP. | |
12346 | ||
12347 | The heuristic failing can be disastrous on | |
12348 | decr_pc_after_break targets. | |
12349 | ||
12350 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12351 | if we fail to recognize a late breakpoint SIGTRAP, | |
12352 | because events_till_retirement has reached 0 too | |
12353 | soon, we'll fail to do the PC adjustment, and report | |
12354 | a random SIGTRAP to the user. When the user resumes | |
12355 | the inferior, it will most likely immediately crash | |
2dec564e | 12356 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12357 | corrupted, because of being resumed e.g., in the |
12358 | middle of a multi-byte instruction, or skipped a | |
12359 | one-byte instruction. This was actually seen happen | |
12360 | on native x86-linux, and should be less rare on | |
12361 | targets that do not support new thread events, like | |
12362 | remote, due to the heuristic depending on | |
12363 | thread_count. | |
12364 | ||
12365 | Mistaking a random SIGTRAP for a breakpoint trap | |
12366 | causes similar symptoms (PC adjustment applied when | |
12367 | it shouldn't), but then again, playing with SIGTRAPs | |
12368 | behind the debugger's back is asking for trouble. | |
12369 | ||
12370 | Since hardware watchpoint traps are always | |
12371 | distinguishable from other traps, so we don't need to | |
12372 | apply keep hardware watchpoint moribund locations | |
12373 | around. We simply always ignore hardware watchpoint | |
12374 | traps we can no longer explain. */ | |
12375 | ||
876fa593 JK |
12376 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12377 | old_loc->owner = NULL; | |
20874c92 | 12378 | |
876fa593 | 12379 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12380 | } |
12381 | else | |
f431efe5 PA |
12382 | { |
12383 | old_loc->owner = NULL; | |
12384 | decref_bp_location (&old_loc); | |
12385 | } | |
20874c92 | 12386 | } |
74960c60 | 12387 | } |
1c5cfe86 | 12388 | |
348d480f PA |
12389 | /* Rescan breakpoints at the same address and section, marking the |
12390 | first one as "first" and any others as "duplicates". This is so | |
12391 | that the bpt instruction is only inserted once. If we have a | |
12392 | permanent breakpoint at the same place as BPT, make that one the | |
12393 | official one, and the rest as duplicates. Permanent breakpoints | |
12394 | are sorted first for the same address. | |
12395 | ||
12396 | Do the same for hardware watchpoints, but also considering the | |
12397 | watchpoint's type (regular/access/read) and length. */ | |
12398 | ||
12399 | bp_loc_first = NULL; | |
12400 | wp_loc_first = NULL; | |
12401 | awp_loc_first = NULL; | |
12402 | rwp_loc_first = NULL; | |
12403 | ALL_BP_LOCATIONS (loc, locp) | |
12404 | { | |
12405 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12406 | non-NULL. */ | |
348d480f | 12407 | struct bp_location **loc_first_p; |
d3fbdd86 | 12408 | b = loc->owner; |
348d480f | 12409 | |
6f380991 | 12410 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12411 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12412 | /* Don't detect duplicate for tracepoint locations because they are |
12413 | never duplicated. See the comments in field `duplicate' of | |
12414 | `struct bp_location'. */ | |
348d480f | 12415 | || is_tracepoint (b)) |
b775012e LM |
12416 | { |
12417 | /* Clear the condition modification flag. */ | |
12418 | loc->condition_changed = condition_unchanged; | |
12419 | continue; | |
12420 | } | |
348d480f PA |
12421 | |
12422 | /* Permanent breakpoint should always be inserted. */ | |
1a853c52 | 12423 | if (loc->permanent && ! loc->inserted) |
348d480f PA |
12424 | internal_error (__FILE__, __LINE__, |
12425 | _("allegedly permanent breakpoint is not " | |
12426 | "actually inserted")); | |
12427 | ||
12428 | if (b->type == bp_hardware_watchpoint) | |
12429 | loc_first_p = &wp_loc_first; | |
12430 | else if (b->type == bp_read_watchpoint) | |
12431 | loc_first_p = &rwp_loc_first; | |
12432 | else if (b->type == bp_access_watchpoint) | |
12433 | loc_first_p = &awp_loc_first; | |
12434 | else | |
12435 | loc_first_p = &bp_loc_first; | |
12436 | ||
12437 | if (*loc_first_p == NULL | |
12438 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12439 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12440 | { | |
12441 | *loc_first_p = loc; | |
12442 | loc->duplicate = 0; | |
b775012e LM |
12443 | |
12444 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12445 | { | |
12446 | loc->needs_update = 1; | |
12447 | /* Clear the condition modification flag. */ | |
12448 | loc->condition_changed = condition_unchanged; | |
12449 | } | |
348d480f PA |
12450 | continue; |
12451 | } | |
12452 | ||
934709f0 PW |
12453 | |
12454 | /* This and the above ensure the invariant that the first location | |
12455 | is not duplicated, and is the inserted one. | |
12456 | All following are marked as duplicated, and are not inserted. */ | |
12457 | if (loc->inserted) | |
12458 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12459 | loc->duplicate = 1; |
12460 | ||
b775012e LM |
12461 | /* Clear the condition modification flag. */ |
12462 | loc->condition_changed = condition_unchanged; | |
12463 | ||
1a853c52 PA |
12464 | if (loc->inserted && !loc->permanent |
12465 | && (*loc_first_p)->permanent) | |
348d480f PA |
12466 | internal_error (__FILE__, __LINE__, |
12467 | _("another breakpoint was inserted on top of " | |
12468 | "a permanent breakpoint")); | |
12469 | } | |
12470 | ||
a25a5a45 | 12471 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12472 | { |
04086b45 | 12473 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12474 | insert_breakpoint_locations (); |
12475 | else | |
12476 | { | |
44702360 PA |
12477 | /* Even though the caller told us to not insert new |
12478 | locations, we may still need to update conditions on the | |
12479 | target's side of breakpoints that were already inserted | |
12480 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12481 | only update conditions for locations that are marked |
12482 | "needs_update". */ | |
12483 | update_inserted_breakpoint_locations (); | |
12484 | } | |
12485 | } | |
348d480f | 12486 | |
04086b45 | 12487 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12488 | download_tracepoint_locations (); |
12489 | ||
348d480f PA |
12490 | do_cleanups (cleanups); |
12491 | } | |
12492 | ||
12493 | void | |
12494 | breakpoint_retire_moribund (void) | |
12495 | { | |
12496 | struct bp_location *loc; | |
12497 | int ix; | |
12498 | ||
12499 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12500 | if (--(loc->events_till_retirement) == 0) | |
12501 | { | |
12502 | decref_bp_location (&loc); | |
12503 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12504 | --ix; | |
12505 | } | |
12506 | } | |
12507 | ||
12508 | static void | |
44702360 | 12509 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12510 | { |
348d480f | 12511 | |
492d29ea PA |
12512 | TRY |
12513 | { | |
12514 | update_global_location_list (insert_mode); | |
12515 | } | |
12516 | CATCH (e, RETURN_MASK_ERROR) | |
12517 | { | |
12518 | } | |
12519 | END_CATCH | |
348d480f PA |
12520 | } |
12521 | ||
12522 | /* Clear BKP from a BPS. */ | |
12523 | ||
12524 | static void | |
12525 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12526 | { | |
12527 | bpstat bs; | |
12528 | ||
12529 | for (bs = bps; bs; bs = bs->next) | |
12530 | if (bs->breakpoint_at == bpt) | |
12531 | { | |
12532 | bs->breakpoint_at = NULL; | |
12533 | bs->old_val = NULL; | |
12534 | /* bs->commands will be freed later. */ | |
12535 | } | |
12536 | } | |
12537 | ||
12538 | /* Callback for iterate_over_threads. */ | |
12539 | static int | |
12540 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12541 | { | |
12542 | struct breakpoint *bpt = data; | |
12543 | ||
12544 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12545 | return 0; | |
12546 | } | |
12547 | ||
12548 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12549 | callbacks. */ | |
12550 | ||
12551 | static void | |
12552 | say_where (struct breakpoint *b) | |
12553 | { | |
12554 | struct value_print_options opts; | |
12555 | ||
12556 | get_user_print_options (&opts); | |
12557 | ||
12558 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12559 | single string. */ | |
12560 | if (b->loc == NULL) | |
12561 | { | |
12562 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12563 | } | |
12564 | else | |
12565 | { | |
2f202fde | 12566 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12567 | { |
12568 | printf_filtered (" at "); | |
12569 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12570 | gdb_stdout); | |
12571 | } | |
2f202fde | 12572 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12573 | { |
12574 | /* If there is a single location, we can print the location | |
12575 | more nicely. */ | |
12576 | if (b->loc->next == NULL) | |
12577 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12578 | symtab_to_filename_for_display (b->loc->symtab), |
12579 | b->loc->line_number); | |
f8eba3c6 TT |
12580 | else |
12581 | /* This is not ideal, but each location may have a | |
12582 | different file name, and this at least reflects the | |
12583 | real situation somewhat. */ | |
12584 | printf_filtered (": %s.", b->addr_string); | |
12585 | } | |
348d480f PA |
12586 | |
12587 | if (b->loc->next) | |
12588 | { | |
12589 | struct bp_location *loc = b->loc; | |
12590 | int n = 0; | |
12591 | for (; loc; loc = loc->next) | |
12592 | ++n; | |
12593 | printf_filtered (" (%d locations)", n); | |
12594 | } | |
12595 | } | |
12596 | } | |
12597 | ||
348d480f PA |
12598 | /* Default bp_location_ops methods. */ |
12599 | ||
12600 | static void | |
12601 | bp_location_dtor (struct bp_location *self) | |
12602 | { | |
12603 | xfree (self->cond); | |
b775012e LM |
12604 | if (self->cond_bytecode) |
12605 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12606 | xfree (self->function_name); |
8b4f3082 PA |
12607 | |
12608 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12609 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12610 | } |
12611 | ||
12612 | static const struct bp_location_ops bp_location_ops = | |
12613 | { | |
12614 | bp_location_dtor | |
12615 | }; | |
12616 | ||
2060206e PA |
12617 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12618 | inherit from. */ | |
348d480f | 12619 | |
2060206e PA |
12620 | static void |
12621 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12622 | { |
12623 | decref_counted_command_line (&self->commands); | |
12624 | xfree (self->cond_string); | |
fb81d016 | 12625 | xfree (self->extra_string); |
348d480f | 12626 | xfree (self->addr_string); |
f8eba3c6 | 12627 | xfree (self->filter); |
348d480f | 12628 | xfree (self->addr_string_range_end); |
348d480f PA |
12629 | } |
12630 | ||
2060206e PA |
12631 | static struct bp_location * |
12632 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12633 | { |
12634 | struct bp_location *loc; | |
12635 | ||
12636 | loc = XNEW (struct bp_location); | |
12637 | init_bp_location (loc, &bp_location_ops, self); | |
12638 | return loc; | |
12639 | } | |
12640 | ||
2060206e PA |
12641 | static void |
12642 | base_breakpoint_re_set (struct breakpoint *b) | |
12643 | { | |
12644 | /* Nothing to re-set. */ | |
12645 | } | |
12646 | ||
12647 | #define internal_error_pure_virtual_called() \ | |
12648 | gdb_assert_not_reached ("pure virtual function called") | |
12649 | ||
12650 | static int | |
12651 | base_breakpoint_insert_location (struct bp_location *bl) | |
12652 | { | |
12653 | internal_error_pure_virtual_called (); | |
12654 | } | |
12655 | ||
12656 | static int | |
12657 | base_breakpoint_remove_location (struct bp_location *bl) | |
12658 | { | |
12659 | internal_error_pure_virtual_called (); | |
12660 | } | |
12661 | ||
12662 | static int | |
12663 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12664 | struct address_space *aspace, | |
09ac7c10 TT |
12665 | CORE_ADDR bp_addr, |
12666 | const struct target_waitstatus *ws) | |
2060206e PA |
12667 | { |
12668 | internal_error_pure_virtual_called (); | |
12669 | } | |
12670 | ||
12671 | static void | |
12672 | base_breakpoint_check_status (bpstat bs) | |
12673 | { | |
12674 | /* Always stop. */ | |
12675 | } | |
12676 | ||
12677 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12678 | errors. */ | |
12679 | ||
12680 | static int | |
12681 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12682 | { | |
12683 | internal_error_pure_virtual_called (); | |
12684 | } | |
12685 | ||
12686 | /* A "resources_needed" breakpoint_ops method that just internal | |
12687 | errors. */ | |
12688 | ||
12689 | static int | |
12690 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12691 | { | |
12692 | internal_error_pure_virtual_called (); | |
12693 | } | |
12694 | ||
12695 | static enum print_stop_action | |
12696 | base_breakpoint_print_it (bpstat bs) | |
12697 | { | |
12698 | internal_error_pure_virtual_called (); | |
12699 | } | |
12700 | ||
12701 | static void | |
12702 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12703 | struct ui_out *uiout) | |
12704 | { | |
12705 | /* nothing */ | |
12706 | } | |
12707 | ||
12708 | static void | |
12709 | base_breakpoint_print_mention (struct breakpoint *b) | |
12710 | { | |
12711 | internal_error_pure_virtual_called (); | |
12712 | } | |
12713 | ||
12714 | static void | |
12715 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12716 | { | |
12717 | internal_error_pure_virtual_called (); | |
12718 | } | |
12719 | ||
983af33b SDJ |
12720 | static void |
12721 | base_breakpoint_create_sals_from_address (char **arg, | |
12722 | struct linespec_result *canonical, | |
12723 | enum bptype type_wanted, | |
12724 | char *addr_start, | |
12725 | char **copy_arg) | |
12726 | { | |
12727 | internal_error_pure_virtual_called (); | |
12728 | } | |
12729 | ||
12730 | static void | |
12731 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12732 | struct linespec_result *c, | |
983af33b | 12733 | char *cond_string, |
e7e0cddf | 12734 | char *extra_string, |
983af33b SDJ |
12735 | enum bptype type_wanted, |
12736 | enum bpdisp disposition, | |
12737 | int thread, | |
12738 | int task, int ignore_count, | |
12739 | const struct breakpoint_ops *o, | |
12740 | int from_tty, int enabled, | |
44f238bb | 12741 | int internal, unsigned flags) |
983af33b SDJ |
12742 | { |
12743 | internal_error_pure_virtual_called (); | |
12744 | } | |
12745 | ||
12746 | static void | |
12747 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
12748 | struct symtabs_and_lines *sals) | |
12749 | { | |
12750 | internal_error_pure_virtual_called (); | |
12751 | } | |
12752 | ||
ab04a2af TT |
12753 | /* The default 'explains_signal' method. */ |
12754 | ||
47591c29 | 12755 | static int |
427cd150 | 12756 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12757 | { |
47591c29 | 12758 | return 1; |
ab04a2af TT |
12759 | } |
12760 | ||
9d6e6e84 HZ |
12761 | /* The default "after_condition_true" method. */ |
12762 | ||
12763 | static void | |
12764 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12765 | { | |
12766 | /* Nothing to do. */ | |
12767 | } | |
12768 | ||
ab04a2af | 12769 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12770 | { |
12771 | base_breakpoint_dtor, | |
12772 | base_breakpoint_allocate_location, | |
12773 | base_breakpoint_re_set, | |
12774 | base_breakpoint_insert_location, | |
12775 | base_breakpoint_remove_location, | |
12776 | base_breakpoint_breakpoint_hit, | |
12777 | base_breakpoint_check_status, | |
12778 | base_breakpoint_resources_needed, | |
12779 | base_breakpoint_works_in_software_mode, | |
12780 | base_breakpoint_print_it, | |
12781 | NULL, | |
12782 | base_breakpoint_print_one_detail, | |
12783 | base_breakpoint_print_mention, | |
983af33b SDJ |
12784 | base_breakpoint_print_recreate, |
12785 | base_breakpoint_create_sals_from_address, | |
12786 | base_breakpoint_create_breakpoints_sal, | |
12787 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
12788 | base_breakpoint_explains_signal, |
12789 | base_breakpoint_after_condition_true, | |
2060206e PA |
12790 | }; |
12791 | ||
12792 | /* Default breakpoint_ops methods. */ | |
12793 | ||
12794 | static void | |
348d480f PA |
12795 | bkpt_re_set (struct breakpoint *b) |
12796 | { | |
06edf0c0 PA |
12797 | /* FIXME: is this still reachable? */ |
12798 | if (b->addr_string == NULL) | |
12799 | { | |
12800 | /* Anything without a string can't be re-set. */ | |
348d480f | 12801 | delete_breakpoint (b); |
06edf0c0 | 12802 | return; |
348d480f | 12803 | } |
06edf0c0 PA |
12804 | |
12805 | breakpoint_re_set_default (b); | |
348d480f PA |
12806 | } |
12807 | ||
2060206e | 12808 | static int |
348d480f PA |
12809 | bkpt_insert_location (struct bp_location *bl) |
12810 | { | |
12811 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 12812 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12813 | else |
7c16b83e | 12814 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12815 | } |
12816 | ||
2060206e | 12817 | static int |
348d480f PA |
12818 | bkpt_remove_location (struct bp_location *bl) |
12819 | { | |
12820 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12821 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12822 | else | |
7c16b83e | 12823 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12824 | } |
12825 | ||
2060206e | 12826 | static int |
348d480f | 12827 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12828 | struct address_space *aspace, CORE_ADDR bp_addr, |
12829 | const struct target_waitstatus *ws) | |
348d480f | 12830 | { |
09ac7c10 | 12831 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12832 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12833 | return 0; |
12834 | ||
348d480f PA |
12835 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12836 | aspace, bp_addr)) | |
12837 | return 0; | |
12838 | ||
12839 | if (overlay_debugging /* unmapped overlay section */ | |
12840 | && section_is_overlay (bl->section) | |
12841 | && !section_is_mapped (bl->section)) | |
12842 | return 0; | |
12843 | ||
12844 | return 1; | |
12845 | } | |
12846 | ||
cd1608cc PA |
12847 | static int |
12848 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12849 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12850 | const struct target_waitstatus *ws) | |
12851 | { | |
12852 | if (dprintf_style == dprintf_style_agent | |
12853 | && target_can_run_breakpoint_commands ()) | |
12854 | { | |
12855 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12856 | for this address it must be for a breakpoint that happens to | |
12857 | be set at the same address. */ | |
12858 | return 0; | |
12859 | } | |
12860 | ||
12861 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12862 | } | |
12863 | ||
2060206e | 12864 | static int |
348d480f PA |
12865 | bkpt_resources_needed (const struct bp_location *bl) |
12866 | { | |
12867 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12868 | ||
12869 | return 1; | |
12870 | } | |
12871 | ||
2060206e | 12872 | static enum print_stop_action |
348d480f PA |
12873 | bkpt_print_it (bpstat bs) |
12874 | { | |
348d480f PA |
12875 | struct breakpoint *b; |
12876 | const struct bp_location *bl; | |
001c8c33 | 12877 | int bp_temp; |
79a45e25 | 12878 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12879 | |
12880 | gdb_assert (bs->bp_location_at != NULL); | |
12881 | ||
12882 | bl = bs->bp_location_at; | |
12883 | b = bs->breakpoint_at; | |
12884 | ||
001c8c33 PA |
12885 | bp_temp = b->disposition == disp_del; |
12886 | if (bl->address != bl->requested_address) | |
12887 | breakpoint_adjustment_warning (bl->requested_address, | |
12888 | bl->address, | |
12889 | b->number, 1); | |
12890 | annotate_breakpoint (b->number); | |
12891 | if (bp_temp) | |
12892 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12893 | else | |
12894 | ui_out_text (uiout, "\nBreakpoint "); | |
12895 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12896 | { |
001c8c33 PA |
12897 | ui_out_field_string (uiout, "reason", |
12898 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12899 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12900 | } |
001c8c33 PA |
12901 | ui_out_field_int (uiout, "bkptno", b->number); |
12902 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12903 | |
001c8c33 | 12904 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12905 | } |
12906 | ||
2060206e | 12907 | static void |
06edf0c0 PA |
12908 | bkpt_print_mention (struct breakpoint *b) |
12909 | { | |
79a45e25 | 12910 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12911 | return; |
12912 | ||
12913 | switch (b->type) | |
12914 | { | |
12915 | case bp_breakpoint: | |
12916 | case bp_gnu_ifunc_resolver: | |
12917 | if (b->disposition == disp_del) | |
12918 | printf_filtered (_("Temporary breakpoint")); | |
12919 | else | |
12920 | printf_filtered (_("Breakpoint")); | |
12921 | printf_filtered (_(" %d"), b->number); | |
12922 | if (b->type == bp_gnu_ifunc_resolver) | |
12923 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12924 | break; | |
12925 | case bp_hardware_breakpoint: | |
12926 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12927 | break; | |
e7e0cddf SS |
12928 | case bp_dprintf: |
12929 | printf_filtered (_("Dprintf %d"), b->number); | |
12930 | break; | |
06edf0c0 PA |
12931 | } |
12932 | ||
12933 | say_where (b); | |
12934 | } | |
12935 | ||
2060206e | 12936 | static void |
06edf0c0 PA |
12937 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12938 | { | |
12939 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12940 | fprintf_unfiltered (fp, "tbreak"); | |
12941 | else if (tp->type == bp_breakpoint) | |
12942 | fprintf_unfiltered (fp, "break"); | |
12943 | else if (tp->type == bp_hardware_breakpoint | |
12944 | && tp->disposition == disp_del) | |
12945 | fprintf_unfiltered (fp, "thbreak"); | |
12946 | else if (tp->type == bp_hardware_breakpoint) | |
12947 | fprintf_unfiltered (fp, "hbreak"); | |
12948 | else | |
12949 | internal_error (__FILE__, __LINE__, | |
12950 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12951 | ||
2060206e | 12952 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 12953 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12954 | } |
12955 | ||
983af33b SDJ |
12956 | static void |
12957 | bkpt_create_sals_from_address (char **arg, | |
12958 | struct linespec_result *canonical, | |
12959 | enum bptype type_wanted, | |
12960 | char *addr_start, char **copy_arg) | |
12961 | { | |
12962 | create_sals_from_address_default (arg, canonical, type_wanted, | |
12963 | addr_start, copy_arg); | |
12964 | } | |
12965 | ||
12966 | static void | |
12967 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12968 | struct linespec_result *canonical, | |
983af33b | 12969 | char *cond_string, |
e7e0cddf | 12970 | char *extra_string, |
983af33b SDJ |
12971 | enum bptype type_wanted, |
12972 | enum bpdisp disposition, | |
12973 | int thread, | |
12974 | int task, int ignore_count, | |
12975 | const struct breakpoint_ops *ops, | |
12976 | int from_tty, int enabled, | |
44f238bb | 12977 | int internal, unsigned flags) |
983af33b | 12978 | { |
023fa29b | 12979 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
12980 | cond_string, extra_string, |
12981 | type_wanted, | |
983af33b SDJ |
12982 | disposition, thread, task, |
12983 | ignore_count, ops, from_tty, | |
44f238bb | 12984 | enabled, internal, flags); |
983af33b SDJ |
12985 | } |
12986 | ||
12987 | static void | |
12988 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
12989 | struct symtabs_and_lines *sals) | |
12990 | { | |
12991 | decode_linespec_default (b, s, sals); | |
12992 | } | |
12993 | ||
06edf0c0 PA |
12994 | /* Virtual table for internal breakpoints. */ |
12995 | ||
12996 | static void | |
12997 | internal_bkpt_re_set (struct breakpoint *b) | |
12998 | { | |
12999 | switch (b->type) | |
13000 | { | |
13001 | /* Delete overlay event and longjmp master breakpoints; they | |
13002 | will be reset later by breakpoint_re_set. */ | |
13003 | case bp_overlay_event: | |
13004 | case bp_longjmp_master: | |
13005 | case bp_std_terminate_master: | |
13006 | case bp_exception_master: | |
13007 | delete_breakpoint (b); | |
13008 | break; | |
13009 | ||
13010 | /* This breakpoint is special, it's set up when the inferior | |
13011 | starts and we really don't want to touch it. */ | |
13012 | case bp_shlib_event: | |
13013 | ||
13014 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13015 | it is set up, we do not want to touch it. */ | |
13016 | case bp_thread_event: | |
13017 | break; | |
13018 | } | |
13019 | } | |
13020 | ||
13021 | static void | |
13022 | internal_bkpt_check_status (bpstat bs) | |
13023 | { | |
a9b3a50f PA |
13024 | if (bs->breakpoint_at->type == bp_shlib_event) |
13025 | { | |
13026 | /* If requested, stop when the dynamic linker notifies GDB of | |
13027 | events. This allows the user to get control and place | |
13028 | breakpoints in initializer routines for dynamically loaded | |
13029 | objects (among other things). */ | |
13030 | bs->stop = stop_on_solib_events; | |
13031 | bs->print = stop_on_solib_events; | |
13032 | } | |
13033 | else | |
13034 | bs->stop = 0; | |
06edf0c0 PA |
13035 | } |
13036 | ||
13037 | static enum print_stop_action | |
13038 | internal_bkpt_print_it (bpstat bs) | |
13039 | { | |
06edf0c0 | 13040 | struct breakpoint *b; |
06edf0c0 | 13041 | |
06edf0c0 PA |
13042 | b = bs->breakpoint_at; |
13043 | ||
06edf0c0 PA |
13044 | switch (b->type) |
13045 | { | |
348d480f PA |
13046 | case bp_shlib_event: |
13047 | /* Did we stop because the user set the stop_on_solib_events | |
13048 | variable? (If so, we report this as a generic, "Stopped due | |
13049 | to shlib event" message.) */ | |
edcc5120 | 13050 | print_solib_event (0); |
348d480f PA |
13051 | break; |
13052 | ||
13053 | case bp_thread_event: | |
13054 | /* Not sure how we will get here. | |
13055 | GDB should not stop for these breakpoints. */ | |
13056 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13057 | break; |
13058 | ||
13059 | case bp_overlay_event: | |
13060 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13061 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13062 | break; |
13063 | ||
13064 | case bp_longjmp_master: | |
13065 | /* These should never be enabled. */ | |
13066 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13067 | break; |
13068 | ||
13069 | case bp_std_terminate_master: | |
13070 | /* These should never be enabled. */ | |
13071 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13072 | "gdb should not stop!\n")); | |
348d480f PA |
13073 | break; |
13074 | ||
13075 | case bp_exception_master: | |
13076 | /* These should never be enabled. */ | |
13077 | printf_filtered (_("Exception Master Breakpoint: " | |
13078 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13079 | break; |
13080 | } | |
13081 | ||
001c8c33 | 13082 | return PRINT_NOTHING; |
06edf0c0 PA |
13083 | } |
13084 | ||
13085 | static void | |
13086 | internal_bkpt_print_mention (struct breakpoint *b) | |
13087 | { | |
13088 | /* Nothing to mention. These breakpoints are internal. */ | |
13089 | } | |
13090 | ||
06edf0c0 PA |
13091 | /* Virtual table for momentary breakpoints */ |
13092 | ||
13093 | static void | |
13094 | momentary_bkpt_re_set (struct breakpoint *b) | |
13095 | { | |
13096 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13097 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13098 | Otherwise these should have been blown away via the cleanup chain |
13099 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13100 | } | |
13101 | ||
13102 | static void | |
13103 | momentary_bkpt_check_status (bpstat bs) | |
13104 | { | |
13105 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13106 | } | |
13107 | ||
13108 | static enum print_stop_action | |
13109 | momentary_bkpt_print_it (bpstat bs) | |
13110 | { | |
79a45e25 PA |
13111 | struct ui_out *uiout = current_uiout; |
13112 | ||
001c8c33 | 13113 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13114 | { |
001c8c33 | 13115 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13116 | |
001c8c33 PA |
13117 | switch (b->type) |
13118 | { | |
13119 | case bp_finish: | |
13120 | ui_out_field_string | |
13121 | (uiout, "reason", | |
13122 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13123 | break; | |
348d480f | 13124 | |
001c8c33 PA |
13125 | case bp_until: |
13126 | ui_out_field_string | |
13127 | (uiout, "reason", | |
13128 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13129 | break; | |
13130 | } | |
348d480f PA |
13131 | } |
13132 | ||
001c8c33 | 13133 | return PRINT_UNKNOWN; |
348d480f PA |
13134 | } |
13135 | ||
06edf0c0 PA |
13136 | static void |
13137 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13138 | { |
06edf0c0 | 13139 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13140 | } |
13141 | ||
e2e4d78b JK |
13142 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13143 | ||
13144 | It gets cleared already on the removal of the first one of such placed | |
13145 | breakpoints. This is OK as they get all removed altogether. */ | |
13146 | ||
13147 | static void | |
13148 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13149 | { | |
13150 | struct thread_info *tp = find_thread_id (self->thread); | |
13151 | ||
13152 | if (tp) | |
13153 | tp->initiating_frame = null_frame_id; | |
13154 | ||
13155 | momentary_breakpoint_ops.dtor (self); | |
13156 | } | |
13157 | ||
55aa24fb SDJ |
13158 | /* Specific methods for probe breakpoints. */ |
13159 | ||
13160 | static int | |
13161 | bkpt_probe_insert_location (struct bp_location *bl) | |
13162 | { | |
13163 | int v = bkpt_insert_location (bl); | |
13164 | ||
13165 | if (v == 0) | |
13166 | { | |
13167 | /* The insertion was successful, now let's set the probe's semaphore | |
13168 | if needed. */ | |
0ea5cda8 SDJ |
13169 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13170 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13171 | bl->probe.objfile, | |
13172 | bl->gdbarch); | |
55aa24fb SDJ |
13173 | } |
13174 | ||
13175 | return v; | |
13176 | } | |
13177 | ||
13178 | static int | |
13179 | bkpt_probe_remove_location (struct bp_location *bl) | |
13180 | { | |
13181 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13182 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13183 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13184 | bl->probe.objfile, | |
13185 | bl->gdbarch); | |
55aa24fb SDJ |
13186 | |
13187 | return bkpt_remove_location (bl); | |
13188 | } | |
13189 | ||
13190 | static void | |
13191 | bkpt_probe_create_sals_from_address (char **arg, | |
13192 | struct linespec_result *canonical, | |
13193 | enum bptype type_wanted, | |
13194 | char *addr_start, char **copy_arg) | |
13195 | { | |
13196 | struct linespec_sals lsal; | |
13197 | ||
13198 | lsal.sals = parse_probes (arg, canonical); | |
13199 | ||
13200 | *copy_arg = xstrdup (canonical->addr_string); | |
13201 | lsal.canonical = xstrdup (*copy_arg); | |
13202 | ||
13203 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13204 | } | |
13205 | ||
13206 | static void | |
13207 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13208 | struct symtabs_and_lines *sals) | |
13209 | { | |
13210 | *sals = parse_probes (s, NULL); | |
13211 | if (!sals->sals) | |
13212 | error (_("probe not found")); | |
13213 | } | |
13214 | ||
348d480f | 13215 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13216 | |
348d480f PA |
13217 | static void |
13218 | tracepoint_re_set (struct breakpoint *b) | |
13219 | { | |
13220 | breakpoint_re_set_default (b); | |
13221 | } | |
876fa593 | 13222 | |
348d480f PA |
13223 | static int |
13224 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13225 | struct address_space *aspace, CORE_ADDR bp_addr, |
13226 | const struct target_waitstatus *ws) | |
348d480f PA |
13227 | { |
13228 | /* By definition, the inferior does not report stops at | |
13229 | tracepoints. */ | |
13230 | return 0; | |
74960c60 VP |
13231 | } |
13232 | ||
13233 | static void | |
348d480f PA |
13234 | tracepoint_print_one_detail (const struct breakpoint *self, |
13235 | struct ui_out *uiout) | |
74960c60 | 13236 | { |
d9b3f62e PA |
13237 | struct tracepoint *tp = (struct tracepoint *) self; |
13238 | if (tp->static_trace_marker_id) | |
348d480f PA |
13239 | { |
13240 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13241 | |
348d480f PA |
13242 | ui_out_text (uiout, "\tmarker id is "); |
13243 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13244 | tp->static_trace_marker_id); |
348d480f PA |
13245 | ui_out_text (uiout, "\n"); |
13246 | } | |
0d381245 VP |
13247 | } |
13248 | ||
a474d7c2 | 13249 | static void |
348d480f | 13250 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13251 | { |
79a45e25 | 13252 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13253 | return; |
cc59ec59 | 13254 | |
348d480f PA |
13255 | switch (b->type) |
13256 | { | |
13257 | case bp_tracepoint: | |
13258 | printf_filtered (_("Tracepoint")); | |
13259 | printf_filtered (_(" %d"), b->number); | |
13260 | break; | |
13261 | case bp_fast_tracepoint: | |
13262 | printf_filtered (_("Fast tracepoint")); | |
13263 | printf_filtered (_(" %d"), b->number); | |
13264 | break; | |
13265 | case bp_static_tracepoint: | |
13266 | printf_filtered (_("Static tracepoint")); | |
13267 | printf_filtered (_(" %d"), b->number); | |
13268 | break; | |
13269 | default: | |
13270 | internal_error (__FILE__, __LINE__, | |
13271 | _("unhandled tracepoint type %d"), (int) b->type); | |
13272 | } | |
13273 | ||
13274 | say_where (b); | |
a474d7c2 PA |
13275 | } |
13276 | ||
348d480f | 13277 | static void |
d9b3f62e | 13278 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13279 | { |
d9b3f62e PA |
13280 | struct tracepoint *tp = (struct tracepoint *) self; |
13281 | ||
13282 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13283 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13284 | if (self->type == bp_static_tracepoint) |
348d480f | 13285 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13286 | else if (self->type == bp_tracepoint) |
348d480f PA |
13287 | fprintf_unfiltered (fp, "trace"); |
13288 | else | |
13289 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13290 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13291 | |
d9b3f62e PA |
13292 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13293 | print_recreate_thread (self, fp); | |
13294 | ||
13295 | if (tp->pass_count) | |
13296 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13297 | } |
13298 | ||
983af33b SDJ |
13299 | static void |
13300 | tracepoint_create_sals_from_address (char **arg, | |
13301 | struct linespec_result *canonical, | |
13302 | enum bptype type_wanted, | |
13303 | char *addr_start, char **copy_arg) | |
13304 | { | |
13305 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13306 | addr_start, copy_arg); | |
13307 | } | |
13308 | ||
13309 | static void | |
13310 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13311 | struct linespec_result *canonical, | |
983af33b | 13312 | char *cond_string, |
e7e0cddf | 13313 | char *extra_string, |
983af33b SDJ |
13314 | enum bptype type_wanted, |
13315 | enum bpdisp disposition, | |
13316 | int thread, | |
13317 | int task, int ignore_count, | |
13318 | const struct breakpoint_ops *ops, | |
13319 | int from_tty, int enabled, | |
44f238bb | 13320 | int internal, unsigned flags) |
983af33b | 13321 | { |
023fa29b | 13322 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13323 | cond_string, extra_string, |
13324 | type_wanted, | |
983af33b SDJ |
13325 | disposition, thread, task, |
13326 | ignore_count, ops, from_tty, | |
44f238bb | 13327 | enabled, internal, flags); |
983af33b SDJ |
13328 | } |
13329 | ||
13330 | static void | |
13331 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13332 | struct symtabs_and_lines *sals) | |
13333 | { | |
13334 | decode_linespec_default (b, s, sals); | |
13335 | } | |
13336 | ||
2060206e | 13337 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13338 | |
55aa24fb SDJ |
13339 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13340 | static probe. */ | |
13341 | ||
13342 | static void | |
13343 | tracepoint_probe_create_sals_from_address (char **arg, | |
13344 | struct linespec_result *canonical, | |
13345 | enum bptype type_wanted, | |
13346 | char *addr_start, char **copy_arg) | |
13347 | { | |
13348 | /* We use the same method for breakpoint on probes. */ | |
13349 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13350 | addr_start, copy_arg); | |
13351 | } | |
13352 | ||
13353 | static void | |
13354 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13355 | struct symtabs_and_lines *sals) | |
13356 | { | |
13357 | /* We use the same method for breakpoint on probes. */ | |
13358 | bkpt_probe_decode_linespec (b, s, sals); | |
13359 | } | |
13360 | ||
13361 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13362 | ||
5c2b4418 HZ |
13363 | /* Dprintf breakpoint_ops methods. */ |
13364 | ||
13365 | static void | |
13366 | dprintf_re_set (struct breakpoint *b) | |
13367 | { | |
13368 | breakpoint_re_set_default (b); | |
13369 | ||
13370 | /* This breakpoint could have been pending, and be resolved now, and | |
13371 | if so, we should now have the extra string. If we don't, the | |
13372 | dprintf was malformed when created, but we couldn't tell because | |
13373 | we can't extract the extra string until the location is | |
13374 | resolved. */ | |
13375 | if (b->loc != NULL && b->extra_string == NULL) | |
13376 | error (_("Format string required")); | |
13377 | ||
13378 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13379 | 2 - create a dprintf, which resolves fine. | |
13380 | 3 - disconnect from target 1 | |
13381 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13382 | ||
13383 | After steps #3/#4, you'll want the dprintf command list to | |
13384 | be updated, because target 1 and 2 may well return different | |
13385 | answers for target_can_run_breakpoint_commands(). | |
13386 | Given absence of finer grained resetting, we get to do | |
13387 | it all the time. */ | |
13388 | if (b->extra_string != NULL) | |
13389 | update_dprintf_command_list (b); | |
13390 | } | |
13391 | ||
2d9442cc HZ |
13392 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13393 | ||
13394 | static void | |
13395 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13396 | { | |
13397 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13398 | tp->extra_string); | |
13399 | print_recreate_thread (tp, fp); | |
13400 | } | |
13401 | ||
9d6e6e84 HZ |
13402 | /* Implement the "after_condition_true" breakpoint_ops method for |
13403 | dprintf. | |
13404 | ||
13405 | dprintf's are implemented with regular commands in their command | |
13406 | list, but we run the commands here instead of before presenting the | |
13407 | stop to the user, as dprintf's don't actually cause a stop. This | |
13408 | also makes it so that the commands of multiple dprintfs at the same | |
13409 | address are all handled. */ | |
13410 | ||
13411 | static void | |
13412 | dprintf_after_condition_true (struct bpstats *bs) | |
13413 | { | |
13414 | struct cleanup *old_chain; | |
13415 | struct bpstats tmp_bs = { NULL }; | |
13416 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13417 | ||
13418 | /* dprintf's never cause a stop. This wasn't set in the | |
13419 | check_status hook instead because that would make the dprintf's | |
13420 | condition not be evaluated. */ | |
13421 | bs->stop = 0; | |
13422 | ||
13423 | /* Run the command list here. Take ownership of it instead of | |
13424 | copying. We never want these commands to run later in | |
13425 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13426 | be set at same address as this dprintf, or even if running the | |
13427 | commands here throws. */ | |
13428 | tmp_bs.commands = bs->commands; | |
13429 | bs->commands = NULL; | |
13430 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13431 | ||
13432 | bpstat_do_actions_1 (&tmp_bs_p); | |
13433 | ||
13434 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13435 | bpstat_do_actions_1 may return early without processing the whole | |
13436 | list. */ | |
13437 | do_cleanups (old_chain); | |
13438 | } | |
13439 | ||
983af33b SDJ |
13440 | /* The breakpoint_ops structure to be used on static tracepoints with |
13441 | markers (`-m'). */ | |
13442 | ||
13443 | static void | |
13444 | strace_marker_create_sals_from_address (char **arg, | |
13445 | struct linespec_result *canonical, | |
13446 | enum bptype type_wanted, | |
13447 | char *addr_start, char **copy_arg) | |
13448 | { | |
13449 | struct linespec_sals lsal; | |
13450 | ||
13451 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13452 | ||
13453 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13454 | ||
13455 | canonical->addr_string = xstrdup (*copy_arg); | |
13456 | lsal.canonical = xstrdup (*copy_arg); | |
13457 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13458 | } | |
13459 | ||
13460 | static void | |
13461 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13462 | struct linespec_result *canonical, | |
983af33b | 13463 | char *cond_string, |
e7e0cddf | 13464 | char *extra_string, |
983af33b SDJ |
13465 | enum bptype type_wanted, |
13466 | enum bpdisp disposition, | |
13467 | int thread, | |
13468 | int task, int ignore_count, | |
13469 | const struct breakpoint_ops *ops, | |
13470 | int from_tty, int enabled, | |
44f238bb | 13471 | int internal, unsigned flags) |
983af33b SDJ |
13472 | { |
13473 | int i; | |
52d361e1 YQ |
13474 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13475 | canonical->sals, 0); | |
983af33b SDJ |
13476 | |
13477 | /* If the user is creating a static tracepoint by marker id | |
13478 | (strace -m MARKER_ID), then store the sals index, so that | |
13479 | breakpoint_re_set can try to match up which of the newly | |
13480 | found markers corresponds to this one, and, don't try to | |
13481 | expand multiple locations for each sal, given than SALS | |
13482 | already should contain all sals for MARKER_ID. */ | |
13483 | ||
13484 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13485 | { | |
13486 | struct symtabs_and_lines expanded; | |
13487 | struct tracepoint *tp; | |
13488 | struct cleanup *old_chain; | |
13489 | char *addr_string; | |
13490 | ||
13491 | expanded.nelts = 1; | |
13492 | expanded.sals = &lsal->sals.sals[i]; | |
13493 | ||
13494 | addr_string = xstrdup (canonical->addr_string); | |
13495 | old_chain = make_cleanup (xfree, addr_string); | |
13496 | ||
13497 | tp = XCNEW (struct tracepoint); | |
13498 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13499 | addr_string, NULL, | |
e7e0cddf SS |
13500 | cond_string, extra_string, |
13501 | type_wanted, disposition, | |
983af33b | 13502 | thread, task, ignore_count, ops, |
44f238bb | 13503 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13504 | canonical->special_display); |
13505 | /* Given that its possible to have multiple markers with | |
13506 | the same string id, if the user is creating a static | |
13507 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13508 | store the sals index, so that breakpoint_re_set can | |
13509 | try to match up which of the newly found markers | |
13510 | corresponds to this one */ | |
13511 | tp->static_trace_marker_id_idx = i; | |
13512 | ||
13513 | install_breakpoint (internal, &tp->base, 0); | |
13514 | ||
13515 | discard_cleanups (old_chain); | |
13516 | } | |
13517 | } | |
13518 | ||
13519 | static void | |
13520 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13521 | struct symtabs_and_lines *sals) | |
13522 | { | |
13523 | struct tracepoint *tp = (struct tracepoint *) b; | |
13524 | ||
13525 | *sals = decode_static_tracepoint_spec (s); | |
13526 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13527 | { | |
13528 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13529 | sals->nelts = 1; | |
13530 | } | |
13531 | else | |
13532 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13533 | } | |
13534 | ||
13535 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13536 | ||
13537 | static int | |
13538 | strace_marker_p (struct breakpoint *b) | |
13539 | { | |
13540 | return b->ops == &strace_marker_breakpoint_ops; | |
13541 | } | |
13542 | ||
53a5351d | 13543 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13544 | structures. */ |
c906108c SS |
13545 | |
13546 | void | |
fba45db2 | 13547 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13548 | { |
52f0bd74 | 13549 | struct breakpoint *b; |
c906108c | 13550 | |
8a3fe4f8 | 13551 | gdb_assert (bpt != NULL); |
c906108c | 13552 | |
4a64f543 MS |
13553 | /* Has this bp already been deleted? This can happen because |
13554 | multiple lists can hold pointers to bp's. bpstat lists are | |
13555 | especial culprits. | |
13556 | ||
13557 | One example of this happening is a watchpoint's scope bp. When | |
13558 | the scope bp triggers, we notice that the watchpoint is out of | |
13559 | scope, and delete it. We also delete its scope bp. But the | |
13560 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13561 | That bpstat is then checked for auto-deleting bp's, which are | |
13562 | deleted. | |
13563 | ||
13564 | A real solution to this problem might involve reference counts in | |
13565 | bp's, and/or giving them pointers back to their referencing | |
13566 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13567 | storage when no more references were extent. A cheaper bandaid | |
13568 | was chosen. */ | |
c906108c SS |
13569 | if (bpt->type == bp_none) |
13570 | return; | |
13571 | ||
4a64f543 MS |
13572 | /* At least avoid this stale reference until the reference counting |
13573 | of breakpoints gets resolved. */ | |
d0fb5eae | 13574 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13575 | { |
d0fb5eae | 13576 | struct breakpoint *related; |
3a5c3e22 | 13577 | struct watchpoint *w; |
d0fb5eae JK |
13578 | |
13579 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13580 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13581 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13582 | w = (struct watchpoint *) bpt; |
13583 | else | |
13584 | w = NULL; | |
13585 | if (w != NULL) | |
13586 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13587 | |
13588 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13589 | for (related = bpt; related->related_breakpoint != bpt; | |
13590 | related = related->related_breakpoint); | |
13591 | related->related_breakpoint = bpt->related_breakpoint; | |
13592 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13593 | } |
13594 | ||
a9634178 TJB |
13595 | /* watch_command_1 creates a watchpoint but only sets its number if |
13596 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13597 | a problem in that process, we'll be asked to delete the half-created | |
13598 | watchpoint. In that case, don't announce the deletion. */ | |
13599 | if (bpt->number) | |
13600 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13601 | |
c906108c SS |
13602 | if (breakpoint_chain == bpt) |
13603 | breakpoint_chain = bpt->next; | |
13604 | ||
c906108c SS |
13605 | ALL_BREAKPOINTS (b) |
13606 | if (b->next == bpt) | |
c5aa993b JM |
13607 | { |
13608 | b->next = bpt->next; | |
13609 | break; | |
13610 | } | |
c906108c | 13611 | |
f431efe5 PA |
13612 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13613 | been freed. */ | |
13614 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13615 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13616 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13617 | commands are associated with the bpstat; if we remove it here, | |
13618 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13619 | event-top.c won't do anything, and temporary breakpoints with | |
13620 | commands won't work. */ | |
13621 | ||
13622 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13623 | ||
4a64f543 MS |
13624 | /* Now that breakpoint is removed from breakpoint list, update the |
13625 | global location list. This will remove locations that used to | |
13626 | belong to this breakpoint. Do this before freeing the breakpoint | |
13627 | itself, since remove_breakpoint looks at location's owner. It | |
13628 | might be better design to have location completely | |
13629 | self-contained, but it's not the case now. */ | |
44702360 | 13630 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13631 | |
348d480f | 13632 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13633 | /* On the chance that someone will soon try again to delete this |
13634 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13635 | bpt->type = bp_none; |
b8c9b27d | 13636 | xfree (bpt); |
c906108c SS |
13637 | } |
13638 | ||
4d6140d9 AC |
13639 | static void |
13640 | do_delete_breakpoint_cleanup (void *b) | |
13641 | { | |
13642 | delete_breakpoint (b); | |
13643 | } | |
13644 | ||
13645 | struct cleanup * | |
13646 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13647 | { | |
13648 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13649 | } | |
13650 | ||
51be5b68 PA |
13651 | /* Iterator function to call a user-provided callback function once |
13652 | for each of B and its related breakpoints. */ | |
13653 | ||
13654 | static void | |
13655 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13656 | void (*function) (struct breakpoint *, | |
13657 | void *), | |
13658 | void *data) | |
13659 | { | |
13660 | struct breakpoint *related; | |
13661 | ||
13662 | related = b; | |
13663 | do | |
13664 | { | |
13665 | struct breakpoint *next; | |
13666 | ||
13667 | /* FUNCTION may delete RELATED. */ | |
13668 | next = related->related_breakpoint; | |
13669 | ||
13670 | if (next == related) | |
13671 | { | |
13672 | /* RELATED is the last ring entry. */ | |
13673 | function (related, data); | |
13674 | ||
13675 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13676 | B. There's nothing left to do anyway, so just break | |
13677 | out. */ | |
13678 | break; | |
13679 | } | |
13680 | else | |
13681 | function (related, data); | |
13682 | ||
13683 | related = next; | |
13684 | } | |
13685 | while (related != b); | |
13686 | } | |
95a42b64 TT |
13687 | |
13688 | static void | |
13689 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13690 | { | |
13691 | delete_breakpoint (b); | |
13692 | } | |
13693 | ||
51be5b68 PA |
13694 | /* A callback for map_breakpoint_numbers that calls |
13695 | delete_breakpoint. */ | |
13696 | ||
13697 | static void | |
13698 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13699 | { | |
13700 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13701 | } | |
13702 | ||
c906108c | 13703 | void |
fba45db2 | 13704 | delete_command (char *arg, int from_tty) |
c906108c | 13705 | { |
35df4500 | 13706 | struct breakpoint *b, *b_tmp; |
c906108c | 13707 | |
ea9365bb TT |
13708 | dont_repeat (); |
13709 | ||
c906108c SS |
13710 | if (arg == 0) |
13711 | { | |
13712 | int breaks_to_delete = 0; | |
13713 | ||
46c6471b PA |
13714 | /* Delete all breakpoints if no argument. Do not delete |
13715 | internal breakpoints, these have to be deleted with an | |
13716 | explicit breakpoint number argument. */ | |
c5aa993b | 13717 | ALL_BREAKPOINTS (b) |
46c6471b | 13718 | if (user_breakpoint_p (b)) |
973d738b DJ |
13719 | { |
13720 | breaks_to_delete = 1; | |
13721 | break; | |
13722 | } | |
c906108c SS |
13723 | |
13724 | /* Ask user only if there are some breakpoints to delete. */ | |
13725 | if (!from_tty | |
e2e0b3e5 | 13726 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13727 | { |
35df4500 | 13728 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13729 | if (user_breakpoint_p (b)) |
c5aa993b | 13730 | delete_breakpoint (b); |
c906108c SS |
13731 | } |
13732 | } | |
13733 | else | |
51be5b68 | 13734 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13735 | } |
13736 | ||
0d381245 VP |
13737 | static int |
13738 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13739 | { |
0d381245 | 13740 | for (; loc; loc = loc->next) |
8645ff69 UW |
13741 | if (!loc->shlib_disabled |
13742 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13743 | return 0; |
13744 | return 1; | |
fe3f5fa8 VP |
13745 | } |
13746 | ||
776592bf DE |
13747 | /* Subroutine of update_breakpoint_locations to simplify it. |
13748 | Return non-zero if multiple fns in list LOC have the same name. | |
13749 | Null names are ignored. */ | |
13750 | ||
13751 | static int | |
13752 | ambiguous_names_p (struct bp_location *loc) | |
13753 | { | |
13754 | struct bp_location *l; | |
13755 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13756 | (int (*) (const void *, |
13757 | const void *)) streq, | |
776592bf DE |
13758 | NULL, xcalloc, xfree); |
13759 | ||
13760 | for (l = loc; l != NULL; l = l->next) | |
13761 | { | |
13762 | const char **slot; | |
13763 | const char *name = l->function_name; | |
13764 | ||
13765 | /* Allow for some names to be NULL, ignore them. */ | |
13766 | if (name == NULL) | |
13767 | continue; | |
13768 | ||
13769 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13770 | INSERT); | |
4a64f543 MS |
13771 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13772 | returns NULL. */ | |
776592bf DE |
13773 | if (*slot != NULL) |
13774 | { | |
13775 | htab_delete (htab); | |
13776 | return 1; | |
13777 | } | |
13778 | *slot = name; | |
13779 | } | |
13780 | ||
13781 | htab_delete (htab); | |
13782 | return 0; | |
13783 | } | |
13784 | ||
0fb4aa4b PA |
13785 | /* When symbols change, it probably means the sources changed as well, |
13786 | and it might mean the static tracepoint markers are no longer at | |
13787 | the same address or line numbers they used to be at last we | |
13788 | checked. Losing your static tracepoints whenever you rebuild is | |
13789 | undesirable. This function tries to resync/rematch gdb static | |
13790 | tracepoints with the markers on the target, for static tracepoints | |
13791 | that have not been set by marker id. Static tracepoint that have | |
13792 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13793 | The heuristic is: | |
13794 | ||
13795 | 1) For a tracepoint set at a specific address, look for a marker at | |
13796 | the old PC. If one is found there, assume to be the same marker. | |
13797 | If the name / string id of the marker found is different from the | |
13798 | previous known name, assume that means the user renamed the marker | |
13799 | in the sources, and output a warning. | |
13800 | ||
13801 | 2) For a tracepoint set at a given line number, look for a marker | |
13802 | at the new address of the old line number. If one is found there, | |
13803 | assume to be the same marker. If the name / string id of the | |
13804 | marker found is different from the previous known name, assume that | |
13805 | means the user renamed the marker in the sources, and output a | |
13806 | warning. | |
13807 | ||
13808 | 3) If a marker is no longer found at the same address or line, it | |
13809 | may mean the marker no longer exists. But it may also just mean | |
13810 | the code changed a bit. Maybe the user added a few lines of code | |
13811 | that made the marker move up or down (in line number terms). Ask | |
13812 | the target for info about the marker with the string id as we knew | |
13813 | it. If found, update line number and address in the matching | |
13814 | static tracepoint. This will get confused if there's more than one | |
13815 | marker with the same ID (possible in UST, although unadvised | |
13816 | precisely because it confuses tools). */ | |
13817 | ||
13818 | static struct symtab_and_line | |
13819 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13820 | { | |
d9b3f62e | 13821 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13822 | struct static_tracepoint_marker marker; |
13823 | CORE_ADDR pc; | |
0fb4aa4b PA |
13824 | |
13825 | pc = sal.pc; | |
13826 | if (sal.line) | |
13827 | find_line_pc (sal.symtab, sal.line, &pc); | |
13828 | ||
13829 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13830 | { | |
d9b3f62e | 13831 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13832 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13833 | b->number, | |
d9b3f62e | 13834 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13835 | |
d9b3f62e PA |
13836 | xfree (tp->static_trace_marker_id); |
13837 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13838 | release_static_tracepoint_marker (&marker); |
13839 | ||
13840 | return sal; | |
13841 | } | |
13842 | ||
13843 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13844 | by string ID. */ | |
13845 | if (!sal.explicit_pc | |
13846 | && sal.line != 0 | |
13847 | && sal.symtab != NULL | |
d9b3f62e | 13848 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13849 | { |
13850 | VEC(static_tracepoint_marker_p) *markers; | |
13851 | ||
13852 | markers | |
d9b3f62e | 13853 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13854 | |
13855 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13856 | { | |
80e1d417 | 13857 | struct symtab_and_line sal2; |
0fb4aa4b | 13858 | struct symbol *sym; |
80e1d417 | 13859 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13860 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 13861 | |
80e1d417 | 13862 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13863 | |
d9b3f62e | 13864 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13865 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13866 | |
13867 | warning (_("marker for static tracepoint %d (%s) not " | |
13868 | "found at previous line number"), | |
d9b3f62e | 13869 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13870 | |
80e1d417 | 13871 | init_sal (&sal2); |
0fb4aa4b | 13872 | |
80e1d417 | 13873 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13874 | |
80e1d417 AS |
13875 | sal2 = find_pc_line (tpmarker->address, 0); |
13876 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13877 | ui_out_text (uiout, "Now in "); |
13878 | if (sym) | |
13879 | { | |
13880 | ui_out_field_string (uiout, "func", | |
13881 | SYMBOL_PRINT_NAME (sym)); | |
13882 | ui_out_text (uiout, " at "); | |
13883 | } | |
05cba821 JK |
13884 | ui_out_field_string (uiout, "file", |
13885 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
13886 | ui_out_text (uiout, ":"); |
13887 | ||
13888 | if (ui_out_is_mi_like_p (uiout)) | |
13889 | { | |
0b0865da | 13890 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13891 | |
f35a17b5 | 13892 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
13893 | } |
13894 | ||
80e1d417 | 13895 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13896 | ui_out_text (uiout, "\n"); |
13897 | ||
80e1d417 | 13898 | b->loc->line_number = sal2.line; |
2f202fde | 13899 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
13900 | |
13901 | xfree (b->addr_string); | |
13902 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 13903 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 13904 | b->loc->line_number); |
0fb4aa4b PA |
13905 | |
13906 | /* Might be nice to check if function changed, and warn if | |
13907 | so. */ | |
13908 | ||
80e1d417 | 13909 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13910 | } |
13911 | } | |
13912 | return sal; | |
13913 | } | |
13914 | ||
8d3788bd VP |
13915 | /* Returns 1 iff locations A and B are sufficiently same that |
13916 | we don't need to report breakpoint as changed. */ | |
13917 | ||
13918 | static int | |
13919 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13920 | { | |
13921 | while (a && b) | |
13922 | { | |
13923 | if (a->address != b->address) | |
13924 | return 0; | |
13925 | ||
13926 | if (a->shlib_disabled != b->shlib_disabled) | |
13927 | return 0; | |
13928 | ||
13929 | if (a->enabled != b->enabled) | |
13930 | return 0; | |
13931 | ||
13932 | a = a->next; | |
13933 | b = b->next; | |
13934 | } | |
13935 | ||
13936 | if ((a == NULL) != (b == NULL)) | |
13937 | return 0; | |
13938 | ||
13939 | return 1; | |
13940 | } | |
13941 | ||
f1310107 TJB |
13942 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
13943 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
13944 | a ranged breakpoint. */ | |
13945 | ||
0e30163f | 13946 | void |
0d381245 | 13947 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
13948 | struct symtabs_and_lines sals, |
13949 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
13950 | { |
13951 | int i; | |
0d381245 VP |
13952 | struct bp_location *existing_locations = b->loc; |
13953 | ||
f8eba3c6 TT |
13954 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
13955 | { | |
13956 | /* Ranged breakpoints have only one start location and one end | |
13957 | location. */ | |
13958 | b->enable_state = bp_disabled; | |
44702360 | 13959 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
13960 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13961 | "multiple locations found\n"), | |
13962 | b->number); | |
13963 | return; | |
13964 | } | |
f1310107 | 13965 | |
4a64f543 MS |
13966 | /* If there's no new locations, and all existing locations are |
13967 | pending, don't do anything. This optimizes the common case where | |
13968 | all locations are in the same shared library, that was unloaded. | |
13969 | We'd like to retain the location, so that when the library is | |
13970 | loaded again, we don't loose the enabled/disabled status of the | |
13971 | individual locations. */ | |
0d381245 | 13972 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
13973 | return; |
13974 | ||
fe3f5fa8 VP |
13975 | b->loc = NULL; |
13976 | ||
0d381245 | 13977 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 13978 | { |
f8eba3c6 TT |
13979 | struct bp_location *new_loc; |
13980 | ||
13981 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
13982 | ||
13983 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 13984 | |
0d381245 VP |
13985 | /* Reparse conditions, they might contain references to the |
13986 | old symtab. */ | |
13987 | if (b->cond_string != NULL) | |
13988 | { | |
bbc13ae3 | 13989 | const char *s; |
fe3f5fa8 | 13990 | |
0d381245 | 13991 | s = b->cond_string; |
492d29ea | 13992 | TRY |
0d381245 | 13993 | { |
1bb9788d TT |
13994 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
13995 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
13996 | 0); |
13997 | } | |
492d29ea | 13998 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 13999 | { |
3e43a32a MS |
14000 | warning (_("failed to reevaluate condition " |
14001 | "for breakpoint %d: %s"), | |
0d381245 VP |
14002 | b->number, e.message); |
14003 | new_loc->enabled = 0; | |
14004 | } | |
492d29ea | 14005 | END_CATCH |
0d381245 | 14006 | } |
fe3f5fa8 | 14007 | |
f1310107 TJB |
14008 | if (sals_end.nelts) |
14009 | { | |
14010 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14011 | ||
14012 | new_loc->length = end - sals.sals[0].pc + 1; | |
14013 | } | |
0d381245 | 14014 | } |
fe3f5fa8 | 14015 | |
4a64f543 MS |
14016 | /* If possible, carry over 'disable' status from existing |
14017 | breakpoints. */ | |
0d381245 VP |
14018 | { |
14019 | struct bp_location *e = existing_locations; | |
776592bf DE |
14020 | /* If there are multiple breakpoints with the same function name, |
14021 | e.g. for inline functions, comparing function names won't work. | |
14022 | Instead compare pc addresses; this is just a heuristic as things | |
14023 | may have moved, but in practice it gives the correct answer | |
14024 | often enough until a better solution is found. */ | |
14025 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14026 | ||
0d381245 VP |
14027 | for (; e; e = e->next) |
14028 | { | |
14029 | if (!e->enabled && e->function_name) | |
14030 | { | |
14031 | struct bp_location *l = b->loc; | |
776592bf DE |
14032 | if (have_ambiguous_names) |
14033 | { | |
14034 | for (; l; l = l->next) | |
f1310107 | 14035 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14036 | { |
14037 | l->enabled = 0; | |
14038 | break; | |
14039 | } | |
14040 | } | |
14041 | else | |
14042 | { | |
14043 | for (; l; l = l->next) | |
14044 | if (l->function_name | |
14045 | && strcmp (e->function_name, l->function_name) == 0) | |
14046 | { | |
14047 | l->enabled = 0; | |
14048 | break; | |
14049 | } | |
14050 | } | |
0d381245 VP |
14051 | } |
14052 | } | |
14053 | } | |
fe3f5fa8 | 14054 | |
8d3788bd VP |
14055 | if (!locations_are_equal (existing_locations, b->loc)) |
14056 | observer_notify_breakpoint_modified (b); | |
14057 | ||
44702360 | 14058 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14059 | } |
14060 | ||
ef23e705 TJB |
14061 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14062 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14063 | ||
14064 | static struct symtabs_and_lines | |
14065 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14066 | { | |
14067 | char *s; | |
02d20e4a | 14068 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14069 | struct gdb_exception exception = exception_none; |
ef23e705 | 14070 | |
983af33b | 14071 | gdb_assert (b->ops != NULL); |
ef23e705 | 14072 | s = addr_string; |
ef23e705 | 14073 | |
492d29ea | 14074 | TRY |
ef23e705 | 14075 | { |
983af33b | 14076 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 | 14077 | } |
492d29ea | 14078 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14079 | { |
14080 | int not_found_and_ok = 0; | |
492d29ea PA |
14081 | |
14082 | exception = e; | |
14083 | ||
ef23e705 TJB |
14084 | /* For pending breakpoints, it's expected that parsing will |
14085 | fail until the right shared library is loaded. User has | |
14086 | already told to create pending breakpoints and don't need | |
14087 | extra messages. If breakpoint is in bp_shlib_disabled | |
14088 | state, then user already saw the message about that | |
14089 | breakpoint being disabled, and don't want to see more | |
14090 | errors. */ | |
58438ac1 | 14091 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14092 | && (b->condition_not_parsed |
14093 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14094 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14095 | || b->enable_state == bp_disabled)) |
14096 | not_found_and_ok = 1; | |
14097 | ||
14098 | if (!not_found_and_ok) | |
14099 | { | |
14100 | /* We surely don't want to warn about the same breakpoint | |
14101 | 10 times. One solution, implemented here, is disable | |
14102 | the breakpoint on error. Another solution would be to | |
14103 | have separate 'warning emitted' flag. Since this | |
14104 | happens only when a binary has changed, I don't know | |
14105 | which approach is better. */ | |
14106 | b->enable_state = bp_disabled; | |
14107 | throw_exception (e); | |
14108 | } | |
14109 | } | |
492d29ea | 14110 | END_CATCH |
ef23e705 | 14111 | |
492d29ea | 14112 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14113 | { |
f8eba3c6 | 14114 | int i; |
ef23e705 | 14115 | |
f8eba3c6 TT |
14116 | for (i = 0; i < sals.nelts; ++i) |
14117 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14118 | if (b->condition_not_parsed && s && s[0]) |
14119 | { | |
ed1d1739 KS |
14120 | char *cond_string, *extra_string; |
14121 | int thread, task; | |
ef23e705 TJB |
14122 | |
14123 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14124 | &cond_string, &thread, &task, |
14125 | &extra_string); | |
ef23e705 TJB |
14126 | if (cond_string) |
14127 | b->cond_string = cond_string; | |
14128 | b->thread = thread; | |
14129 | b->task = task; | |
e7e0cddf SS |
14130 | if (extra_string) |
14131 | b->extra_string = extra_string; | |
ef23e705 TJB |
14132 | b->condition_not_parsed = 0; |
14133 | } | |
14134 | ||
983af33b | 14135 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14136 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14137 | |
58438ac1 TT |
14138 | *found = 1; |
14139 | } | |
14140 | else | |
14141 | *found = 0; | |
ef23e705 TJB |
14142 | |
14143 | return sals; | |
14144 | } | |
14145 | ||
348d480f PA |
14146 | /* The default re_set method, for typical hardware or software |
14147 | breakpoints. Reevaluate the breakpoint and recreate its | |
14148 | locations. */ | |
14149 | ||
14150 | static void | |
28010a5d | 14151 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14152 | { |
14153 | int found; | |
f1310107 | 14154 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14155 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14156 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14157 | |
14158 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14159 | if (found) | |
14160 | { | |
14161 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14162 | expanded = sals; |
ef23e705 TJB |
14163 | } |
14164 | ||
f1310107 TJB |
14165 | if (b->addr_string_range_end) |
14166 | { | |
14167 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14168 | if (found) | |
14169 | { | |
14170 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14171 | expanded_end = sals_end; |
f1310107 TJB |
14172 | } |
14173 | } | |
14174 | ||
14175 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14176 | } |
14177 | ||
983af33b SDJ |
14178 | /* Default method for creating SALs from an address string. It basically |
14179 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14180 | ||
14181 | static void | |
14182 | create_sals_from_address_default (char **arg, | |
14183 | struct linespec_result *canonical, | |
14184 | enum bptype type_wanted, | |
14185 | char *addr_start, char **copy_arg) | |
14186 | { | |
14187 | parse_breakpoint_sals (arg, canonical); | |
14188 | } | |
14189 | ||
14190 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14191 | function for the `create_breakpoints_sal' method of | |
14192 | breakpoint_ops. */ | |
14193 | ||
14194 | static void | |
14195 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14196 | struct linespec_result *canonical, | |
983af33b | 14197 | char *cond_string, |
e7e0cddf | 14198 | char *extra_string, |
983af33b SDJ |
14199 | enum bptype type_wanted, |
14200 | enum bpdisp disposition, | |
14201 | int thread, | |
14202 | int task, int ignore_count, | |
14203 | const struct breakpoint_ops *ops, | |
14204 | int from_tty, int enabled, | |
44f238bb | 14205 | int internal, unsigned flags) |
983af33b SDJ |
14206 | { |
14207 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14208 | extra_string, |
983af33b SDJ |
14209 | type_wanted, disposition, |
14210 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14211 | enabled, internal, flags); |
983af33b SDJ |
14212 | } |
14213 | ||
14214 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14215 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14216 | ||
14217 | static void | |
14218 | decode_linespec_default (struct breakpoint *b, char **s, | |
14219 | struct symtabs_and_lines *sals) | |
14220 | { | |
14221 | struct linespec_result canonical; | |
14222 | ||
14223 | init_linespec_result (&canonical); | |
14224 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14225 | (struct symtab *) NULL, 0, | |
14226 | &canonical, multiple_symbols_all, | |
14227 | b->filter); | |
14228 | ||
14229 | /* We should get 0 or 1 resulting SALs. */ | |
14230 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14231 | ||
14232 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14233 | { | |
14234 | struct linespec_sals *lsal; | |
14235 | ||
14236 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14237 | *sals = lsal->sals; | |
14238 | /* Arrange it so the destructor does not free the | |
14239 | contents. */ | |
14240 | lsal->sals.sals = NULL; | |
14241 | } | |
14242 | ||
14243 | destroy_linespec_result (&canonical); | |
14244 | } | |
14245 | ||
28010a5d PA |
14246 | /* Prepare the global context for a re-set of breakpoint B. */ |
14247 | ||
14248 | static struct cleanup * | |
14249 | prepare_re_set_context (struct breakpoint *b) | |
14250 | { | |
14251 | struct cleanup *cleanups; | |
14252 | ||
14253 | input_radix = b->input_radix; | |
14254 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14255 | if (b->pspace != NULL) |
14256 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14257 | set_language (b->language); |
14258 | ||
14259 | return cleanups; | |
ef23e705 TJB |
14260 | } |
14261 | ||
c906108c SS |
14262 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14263 | The value we return ends up being the return value from catch_errors. | |
14264 | Unused in this case. */ | |
14265 | ||
14266 | static int | |
4efb68b1 | 14267 | breakpoint_re_set_one (void *bint) |
c906108c | 14268 | { |
4a64f543 | 14269 | /* Get past catch_errs. */ |
53a5351d | 14270 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14271 | struct cleanup *cleanups; |
c906108c | 14272 | |
348d480f PA |
14273 | cleanups = prepare_re_set_context (b); |
14274 | b->ops->re_set (b); | |
14275 | do_cleanups (cleanups); | |
c906108c SS |
14276 | return 0; |
14277 | } | |
14278 | ||
69de3c6a | 14279 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14280 | void |
69de3c6a | 14281 | breakpoint_re_set (void) |
c906108c | 14282 | { |
35df4500 | 14283 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14284 | enum language save_language; |
14285 | int save_input_radix; | |
6c95b8df | 14286 | struct cleanup *old_chain; |
c5aa993b | 14287 | |
c906108c SS |
14288 | save_language = current_language->la_language; |
14289 | save_input_radix = input_radix; | |
6c95b8df PA |
14290 | old_chain = save_current_program_space (); |
14291 | ||
35df4500 | 14292 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14293 | { |
4a64f543 | 14294 | /* Format possible error msg. */ |
fe3f5fa8 | 14295 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14296 | b->number); |
14297 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14298 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14299 | do_cleanups (cleanups); |
c5aa993b | 14300 | } |
c906108c SS |
14301 | set_language (save_language); |
14302 | input_radix = save_input_radix; | |
e62c965a | 14303 | |
0756c555 | 14304 | jit_breakpoint_re_set (); |
4efc6507 | 14305 | |
6c95b8df PA |
14306 | do_cleanups (old_chain); |
14307 | ||
af02033e PP |
14308 | create_overlay_event_breakpoint (); |
14309 | create_longjmp_master_breakpoint (); | |
14310 | create_std_terminate_master_breakpoint (); | |
186c406b | 14311 | create_exception_master_breakpoint (); |
c906108c SS |
14312 | } |
14313 | \f | |
c906108c SS |
14314 | /* Reset the thread number of this breakpoint: |
14315 | ||
14316 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14317 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14318 | void |
fba45db2 | 14319 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14320 | { |
14321 | if (b->thread != -1) | |
14322 | { | |
39f77062 KB |
14323 | if (in_thread_list (inferior_ptid)) |
14324 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14325 | |
14326 | /* We're being called after following a fork. The new fork is | |
14327 | selected as current, and unless this was a vfork will have a | |
14328 | different program space from the original thread. Reset that | |
14329 | as well. */ | |
14330 | b->loc->pspace = current_program_space; | |
c906108c SS |
14331 | } |
14332 | } | |
14333 | ||
03ac34d5 MS |
14334 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14335 | If from_tty is nonzero, it prints a message to that effect, | |
14336 | which ends with a period (no newline). */ | |
14337 | ||
c906108c | 14338 | void |
fba45db2 | 14339 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14340 | { |
52f0bd74 | 14341 | struct breakpoint *b; |
c906108c SS |
14342 | |
14343 | if (count < 0) | |
14344 | count = 0; | |
14345 | ||
14346 | ALL_BREAKPOINTS (b) | |
14347 | if (b->number == bptnum) | |
c5aa993b | 14348 | { |
d77f58be SS |
14349 | if (is_tracepoint (b)) |
14350 | { | |
14351 | if (from_tty && count != 0) | |
14352 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14353 | bptnum); | |
14354 | return; | |
14355 | } | |
14356 | ||
c5aa993b | 14357 | b->ignore_count = count; |
221ea385 KS |
14358 | if (from_tty) |
14359 | { | |
14360 | if (count == 0) | |
3e43a32a MS |
14361 | printf_filtered (_("Will stop next time " |
14362 | "breakpoint %d is reached."), | |
221ea385 KS |
14363 | bptnum); |
14364 | else if (count == 1) | |
a3f17187 | 14365 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14366 | bptnum); |
14367 | else | |
3e43a32a MS |
14368 | printf_filtered (_("Will ignore next %d " |
14369 | "crossings of breakpoint %d."), | |
221ea385 KS |
14370 | count, bptnum); |
14371 | } | |
8d3788bd | 14372 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14373 | return; |
14374 | } | |
c906108c | 14375 | |
8a3fe4f8 | 14376 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14377 | } |
14378 | ||
c906108c SS |
14379 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14380 | ||
14381 | static void | |
fba45db2 | 14382 | ignore_command (char *args, int from_tty) |
c906108c SS |
14383 | { |
14384 | char *p = args; | |
52f0bd74 | 14385 | int num; |
c906108c SS |
14386 | |
14387 | if (p == 0) | |
e2e0b3e5 | 14388 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14389 | |
c906108c | 14390 | num = get_number (&p); |
5c44784c | 14391 | if (num == 0) |
8a3fe4f8 | 14392 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14393 | if (*p == 0) |
8a3fe4f8 | 14394 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14395 | |
14396 | set_ignore_count (num, | |
14397 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14398 | from_tty); | |
221ea385 KS |
14399 | if (from_tty) |
14400 | printf_filtered ("\n"); | |
c906108c SS |
14401 | } |
14402 | \f | |
14403 | /* Call FUNCTION on each of the breakpoints | |
14404 | whose numbers are given in ARGS. */ | |
14405 | ||
14406 | static void | |
95a42b64 TT |
14407 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14408 | void *), | |
14409 | void *data) | |
c906108c | 14410 | { |
52f0bd74 AC |
14411 | int num; |
14412 | struct breakpoint *b, *tmp; | |
11cf8741 | 14413 | int match; |
197f0a60 | 14414 | struct get_number_or_range_state state; |
c906108c | 14415 | |
b9d61307 | 14416 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14417 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14418 | |
197f0a60 TT |
14419 | init_number_or_range (&state, args); |
14420 | ||
14421 | while (!state.finished) | |
c906108c | 14422 | { |
e799154c | 14423 | const char *p = state.string; |
197f0a60 | 14424 | |
11cf8741 | 14425 | match = 0; |
c5aa993b | 14426 | |
197f0a60 | 14427 | num = get_number_or_range (&state); |
5c44784c | 14428 | if (num == 0) |
c5aa993b | 14429 | { |
8a3fe4f8 | 14430 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14431 | } |
14432 | else | |
14433 | { | |
14434 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14435 | if (b->number == num) | |
14436 | { | |
11cf8741 | 14437 | match = 1; |
cdac0397 | 14438 | function (b, data); |
11cf8741 | 14439 | break; |
5c44784c | 14440 | } |
11cf8741 | 14441 | if (match == 0) |
a3f17187 | 14442 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14443 | } |
c906108c SS |
14444 | } |
14445 | } | |
14446 | ||
0d381245 VP |
14447 | static struct bp_location * |
14448 | find_location_by_number (char *number) | |
14449 | { | |
14450 | char *dot = strchr (number, '.'); | |
14451 | char *p1; | |
14452 | int bp_num; | |
14453 | int loc_num; | |
14454 | struct breakpoint *b; | |
14455 | struct bp_location *loc; | |
14456 | ||
14457 | *dot = '\0'; | |
14458 | ||
14459 | p1 = number; | |
197f0a60 | 14460 | bp_num = get_number (&p1); |
0d381245 VP |
14461 | if (bp_num == 0) |
14462 | error (_("Bad breakpoint number '%s'"), number); | |
14463 | ||
14464 | ALL_BREAKPOINTS (b) | |
14465 | if (b->number == bp_num) | |
14466 | { | |
14467 | break; | |
14468 | } | |
14469 | ||
14470 | if (!b || b->number != bp_num) | |
14471 | error (_("Bad breakpoint number '%s'"), number); | |
14472 | ||
14473 | p1 = dot+1; | |
197f0a60 | 14474 | loc_num = get_number (&p1); |
0d381245 VP |
14475 | if (loc_num == 0) |
14476 | error (_("Bad breakpoint location number '%s'"), number); | |
14477 | ||
14478 | --loc_num; | |
14479 | loc = b->loc; | |
14480 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14481 | ; | |
14482 | if (!loc) | |
14483 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14484 | ||
14485 | return loc; | |
14486 | } | |
14487 | ||
14488 | ||
1900040c MS |
14489 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14490 | If from_tty is nonzero, it prints a message to that effect, | |
14491 | which ends with a period (no newline). */ | |
14492 | ||
c906108c | 14493 | void |
fba45db2 | 14494 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14495 | { |
14496 | /* Never disable a watchpoint scope breakpoint; we want to | |
14497 | hit them when we leave scope so we can delete both the | |
14498 | watchpoint and its scope breakpoint at that time. */ | |
14499 | if (bpt->type == bp_watchpoint_scope) | |
14500 | return; | |
14501 | ||
b5de0fa7 | 14502 | bpt->enable_state = bp_disabled; |
c906108c | 14503 | |
b775012e LM |
14504 | /* Mark breakpoint locations modified. */ |
14505 | mark_breakpoint_modified (bpt); | |
14506 | ||
d248b706 KY |
14507 | if (target_supports_enable_disable_tracepoint () |
14508 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14509 | { | |
14510 | struct bp_location *location; | |
14511 | ||
14512 | for (location = bpt->loc; location; location = location->next) | |
14513 | target_disable_tracepoint (location); | |
14514 | } | |
14515 | ||
44702360 | 14516 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14517 | |
8d3788bd | 14518 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14519 | } |
14520 | ||
51be5b68 PA |
14521 | /* A callback for iterate_over_related_breakpoints. */ |
14522 | ||
14523 | static void | |
14524 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14525 | { | |
14526 | disable_breakpoint (b); | |
14527 | } | |
14528 | ||
95a42b64 TT |
14529 | /* A callback for map_breakpoint_numbers that calls |
14530 | disable_breakpoint. */ | |
14531 | ||
14532 | static void | |
14533 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14534 | { | |
51be5b68 | 14535 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14536 | } |
14537 | ||
c906108c | 14538 | static void |
fba45db2 | 14539 | disable_command (char *args, int from_tty) |
c906108c | 14540 | { |
c906108c | 14541 | if (args == 0) |
46c6471b PA |
14542 | { |
14543 | struct breakpoint *bpt; | |
14544 | ||
14545 | ALL_BREAKPOINTS (bpt) | |
14546 | if (user_breakpoint_p (bpt)) | |
14547 | disable_breakpoint (bpt); | |
14548 | } | |
9eaabc75 | 14549 | else |
0d381245 | 14550 | { |
9eaabc75 MW |
14551 | char *num = extract_arg (&args); |
14552 | ||
14553 | while (num) | |
d248b706 | 14554 | { |
9eaabc75 | 14555 | if (strchr (num, '.')) |
b775012e | 14556 | { |
9eaabc75 MW |
14557 | struct bp_location *loc = find_location_by_number (num); |
14558 | ||
14559 | if (loc) | |
14560 | { | |
14561 | if (loc->enabled) | |
14562 | { | |
14563 | loc->enabled = 0; | |
14564 | mark_breakpoint_location_modified (loc); | |
14565 | } | |
14566 | if (target_supports_enable_disable_tracepoint () | |
14567 | && current_trace_status ()->running && loc->owner | |
14568 | && is_tracepoint (loc->owner)) | |
14569 | target_disable_tracepoint (loc); | |
14570 | } | |
44702360 | 14571 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14572 | } |
9eaabc75 MW |
14573 | else |
14574 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14575 | num = extract_arg (&args); | |
d248b706 | 14576 | } |
0d381245 | 14577 | } |
c906108c SS |
14578 | } |
14579 | ||
14580 | static void | |
816338b5 SS |
14581 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14582 | int count) | |
c906108c | 14583 | { |
afe38095 | 14584 | int target_resources_ok; |
c906108c SS |
14585 | |
14586 | if (bpt->type == bp_hardware_breakpoint) | |
14587 | { | |
14588 | int i; | |
c5aa993b | 14589 | i = hw_breakpoint_used_count (); |
53a5351d | 14590 | target_resources_ok = |
d92524f1 | 14591 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14592 | i + 1, 0); |
c906108c | 14593 | if (target_resources_ok == 0) |
8a3fe4f8 | 14594 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14595 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14596 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14597 | } |
14598 | ||
cc60f2e3 | 14599 | if (is_watchpoint (bpt)) |
c906108c | 14600 | { |
d07205c2 JK |
14601 | /* Initialize it just to avoid a GCC false warning. */ |
14602 | enum enable_state orig_enable_state = 0; | |
dde02812 | 14603 | |
492d29ea | 14604 | TRY |
c906108c | 14605 | { |
3a5c3e22 PA |
14606 | struct watchpoint *w = (struct watchpoint *) bpt; |
14607 | ||
1e718ff1 TJB |
14608 | orig_enable_state = bpt->enable_state; |
14609 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14610 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14611 | } |
492d29ea | 14612 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14613 | { |
1e718ff1 | 14614 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14615 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14616 | bpt->number); | |
14617 | return; | |
c5aa993b | 14618 | } |
492d29ea | 14619 | END_CATCH |
c906108c | 14620 | } |
0101ce28 | 14621 | |
b775012e LM |
14622 | bpt->enable_state = bp_enabled; |
14623 | ||
14624 | /* Mark breakpoint locations modified. */ | |
14625 | mark_breakpoint_modified (bpt); | |
14626 | ||
d248b706 KY |
14627 | if (target_supports_enable_disable_tracepoint () |
14628 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14629 | { | |
14630 | struct bp_location *location; | |
14631 | ||
14632 | for (location = bpt->loc; location; location = location->next) | |
14633 | target_enable_tracepoint (location); | |
14634 | } | |
14635 | ||
b4c291bb | 14636 | bpt->disposition = disposition; |
816338b5 | 14637 | bpt->enable_count = count; |
44702360 | 14638 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14639 | |
8d3788bd | 14640 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14641 | } |
14642 | ||
fe3f5fa8 | 14643 | |
c906108c | 14644 | void |
fba45db2 | 14645 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14646 | { |
816338b5 | 14647 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14648 | } |
14649 | ||
14650 | static void | |
14651 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14652 | { | |
14653 | enable_breakpoint (bpt); | |
c906108c SS |
14654 | } |
14655 | ||
95a42b64 TT |
14656 | /* A callback for map_breakpoint_numbers that calls |
14657 | enable_breakpoint. */ | |
14658 | ||
14659 | static void | |
14660 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14661 | { | |
51be5b68 | 14662 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14663 | } |
14664 | ||
c906108c SS |
14665 | /* The enable command enables the specified breakpoints (or all defined |
14666 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14667 | in stopping the inferior. */ |
c906108c | 14668 | |
c906108c | 14669 | static void |
fba45db2 | 14670 | enable_command (char *args, int from_tty) |
c906108c | 14671 | { |
c906108c | 14672 | if (args == 0) |
46c6471b PA |
14673 | { |
14674 | struct breakpoint *bpt; | |
14675 | ||
14676 | ALL_BREAKPOINTS (bpt) | |
14677 | if (user_breakpoint_p (bpt)) | |
14678 | enable_breakpoint (bpt); | |
14679 | } | |
9eaabc75 | 14680 | else |
0d381245 | 14681 | { |
9eaabc75 MW |
14682 | char *num = extract_arg (&args); |
14683 | ||
14684 | while (num) | |
d248b706 | 14685 | { |
9eaabc75 | 14686 | if (strchr (num, '.')) |
b775012e | 14687 | { |
9eaabc75 MW |
14688 | struct bp_location *loc = find_location_by_number (num); |
14689 | ||
14690 | if (loc) | |
14691 | { | |
14692 | if (!loc->enabled) | |
14693 | { | |
14694 | loc->enabled = 1; | |
14695 | mark_breakpoint_location_modified (loc); | |
14696 | } | |
14697 | if (target_supports_enable_disable_tracepoint () | |
14698 | && current_trace_status ()->running && loc->owner | |
14699 | && is_tracepoint (loc->owner)) | |
14700 | target_enable_tracepoint (loc); | |
14701 | } | |
44702360 | 14702 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14703 | } |
9eaabc75 MW |
14704 | else |
14705 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14706 | num = extract_arg (&args); | |
d248b706 | 14707 | } |
0d381245 | 14708 | } |
c906108c SS |
14709 | } |
14710 | ||
816338b5 SS |
14711 | /* This struct packages up disposition data for application to multiple |
14712 | breakpoints. */ | |
14713 | ||
14714 | struct disp_data | |
14715 | { | |
14716 | enum bpdisp disp; | |
14717 | int count; | |
14718 | }; | |
14719 | ||
c906108c | 14720 | static void |
51be5b68 PA |
14721 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14722 | { | |
816338b5 | 14723 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14724 | |
816338b5 | 14725 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14726 | } |
14727 | ||
14728 | static void | |
14729 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14730 | { |
816338b5 | 14731 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14732 | |
14733 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14734 | } |
14735 | ||
c906108c | 14736 | static void |
fba45db2 | 14737 | enable_once_command (char *args, int from_tty) |
c906108c | 14738 | { |
51be5b68 | 14739 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14740 | } |
14741 | ||
816338b5 SS |
14742 | static void |
14743 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14744 | { | |
14745 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14746 | ||
14747 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14748 | } | |
14749 | ||
14750 | static void | |
14751 | enable_count_command (char *args, int from_tty) | |
14752 | { | |
b9d61307 SM |
14753 | int count; |
14754 | ||
14755 | if (args == NULL) | |
14756 | error_no_arg (_("hit count")); | |
14757 | ||
14758 | count = get_number (&args); | |
816338b5 SS |
14759 | |
14760 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14761 | } | |
14762 | ||
c906108c | 14763 | static void |
51be5b68 | 14764 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14765 | { |
816338b5 | 14766 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14767 | |
14768 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14769 | } |
14770 | ||
c906108c | 14771 | static void |
fba45db2 | 14772 | enable_delete_command (char *args, int from_tty) |
c906108c | 14773 | { |
51be5b68 | 14774 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14775 | } |
14776 | \f | |
fa8d40ab JJ |
14777 | static void |
14778 | set_breakpoint_cmd (char *args, int from_tty) | |
14779 | { | |
14780 | } | |
14781 | ||
14782 | static void | |
14783 | show_breakpoint_cmd (char *args, int from_tty) | |
14784 | { | |
14785 | } | |
14786 | ||
1f3b5d1b PP |
14787 | /* Invalidate last known value of any hardware watchpoint if |
14788 | the memory which that value represents has been written to by | |
14789 | GDB itself. */ | |
14790 | ||
14791 | static void | |
8de0566d YQ |
14792 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14793 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14794 | const bfd_byte *data) |
14795 | { | |
14796 | struct breakpoint *bp; | |
14797 | ||
14798 | ALL_BREAKPOINTS (bp) | |
14799 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14800 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14801 | { |
3a5c3e22 | 14802 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14803 | |
3a5c3e22 PA |
14804 | if (wp->val_valid && wp->val) |
14805 | { | |
14806 | struct bp_location *loc; | |
14807 | ||
14808 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14809 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14810 | && loc->address + loc->length > addr | |
14811 | && addr + len > loc->address) | |
14812 | { | |
14813 | value_free (wp->val); | |
14814 | wp->val = NULL; | |
14815 | wp->val_valid = 0; | |
14816 | } | |
14817 | } | |
1f3b5d1b PP |
14818 | } |
14819 | } | |
14820 | ||
8181d85f DJ |
14821 | /* Create and insert a breakpoint for software single step. */ |
14822 | ||
14823 | void | |
6c95b8df | 14824 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14825 | struct address_space *aspace, |
14826 | CORE_ADDR next_pc) | |
8181d85f | 14827 | { |
7c16b83e PA |
14828 | struct thread_info *tp = inferior_thread (); |
14829 | struct symtab_and_line sal; | |
14830 | CORE_ADDR pc = next_pc; | |
8181d85f | 14831 | |
34b7e8a6 PA |
14832 | if (tp->control.single_step_breakpoints == NULL) |
14833 | { | |
14834 | tp->control.single_step_breakpoints | |
14835 | = new_single_step_breakpoint (tp->num, gdbarch); | |
14836 | } | |
8181d85f | 14837 | |
7c16b83e PA |
14838 | sal = find_pc_line (pc, 0); |
14839 | sal.pc = pc; | |
14840 | sal.section = find_pc_overlay (pc); | |
14841 | sal.explicit_pc = 1; | |
34b7e8a6 | 14842 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14843 | |
7c16b83e | 14844 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14845 | } |
14846 | ||
34b7e8a6 | 14847 | /* See breakpoint.h. */ |
f02253f1 HZ |
14848 | |
14849 | int | |
7c16b83e PA |
14850 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14851 | struct address_space *aspace, | |
14852 | CORE_ADDR pc) | |
1aafd4da | 14853 | { |
7c16b83e | 14854 | struct bp_location *loc; |
1aafd4da | 14855 | |
7c16b83e PA |
14856 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14857 | if (loc->inserted | |
14858 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14859 | return 1; | |
1aafd4da | 14860 | |
7c16b83e | 14861 | return 0; |
ef370185 JB |
14862 | } |
14863 | ||
14864 | /* Check whether a software single-step breakpoint is inserted at | |
14865 | PC. */ | |
14866 | ||
14867 | int | |
14868 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14869 | CORE_ADDR pc) | |
14870 | { | |
34b7e8a6 PA |
14871 | struct breakpoint *bpt; |
14872 | ||
14873 | ALL_BREAKPOINTS (bpt) | |
14874 | { | |
14875 | if (bpt->type == bp_single_step | |
14876 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14877 | return 1; | |
14878 | } | |
14879 | return 0; | |
1aafd4da UW |
14880 | } |
14881 | ||
1042e4c0 SS |
14882 | /* Tracepoint-specific operations. */ |
14883 | ||
14884 | /* Set tracepoint count to NUM. */ | |
14885 | static void | |
14886 | set_tracepoint_count (int num) | |
14887 | { | |
14888 | tracepoint_count = num; | |
4fa62494 | 14889 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14890 | } |
14891 | ||
70221824 | 14892 | static void |
1042e4c0 SS |
14893 | trace_command (char *arg, int from_tty) |
14894 | { | |
55aa24fb SDJ |
14895 | struct breakpoint_ops *ops; |
14896 | const char *arg_cp = arg; | |
14897 | ||
14898 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
14899 | ops = &tracepoint_probe_breakpoint_ops; | |
14900 | else | |
14901 | ops = &tracepoint_breakpoint_ops; | |
14902 | ||
558a9d82 YQ |
14903 | create_breakpoint (get_current_arch (), |
14904 | arg, | |
14905 | NULL, 0, NULL, 1 /* parse arg */, | |
14906 | 0 /* tempflag */, | |
14907 | bp_tracepoint /* type_wanted */, | |
14908 | 0 /* Ignore count */, | |
14909 | pending_break_support, | |
14910 | ops, | |
14911 | from_tty, | |
14912 | 1 /* enabled */, | |
14913 | 0 /* internal */, 0); | |
1042e4c0 SS |
14914 | } |
14915 | ||
70221824 | 14916 | static void |
7a697b8d SS |
14917 | ftrace_command (char *arg, int from_tty) |
14918 | { | |
558a9d82 YQ |
14919 | create_breakpoint (get_current_arch (), |
14920 | arg, | |
14921 | NULL, 0, NULL, 1 /* parse arg */, | |
14922 | 0 /* tempflag */, | |
14923 | bp_fast_tracepoint /* type_wanted */, | |
14924 | 0 /* Ignore count */, | |
14925 | pending_break_support, | |
14926 | &tracepoint_breakpoint_ops, | |
14927 | from_tty, | |
14928 | 1 /* enabled */, | |
14929 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14930 | } |
14931 | ||
14932 | /* strace command implementation. Creates a static tracepoint. */ | |
14933 | ||
70221824 | 14934 | static void |
0fb4aa4b PA |
14935 | strace_command (char *arg, int from_tty) |
14936 | { | |
983af33b SDJ |
14937 | struct breakpoint_ops *ops; |
14938 | ||
14939 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14940 | or with a normal static tracepoint. */ | |
61012eef | 14941 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
983af33b SDJ |
14942 | ops = &strace_marker_breakpoint_ops; |
14943 | else | |
14944 | ops = &tracepoint_breakpoint_ops; | |
14945 | ||
558a9d82 YQ |
14946 | create_breakpoint (get_current_arch (), |
14947 | arg, | |
14948 | NULL, 0, NULL, 1 /* parse arg */, | |
14949 | 0 /* tempflag */, | |
14950 | bp_static_tracepoint /* type_wanted */, | |
14951 | 0 /* Ignore count */, | |
14952 | pending_break_support, | |
14953 | ops, | |
14954 | from_tty, | |
14955 | 1 /* enabled */, | |
14956 | 0 /* internal */, 0); | |
7a697b8d SS |
14957 | } |
14958 | ||
409873ef SS |
14959 | /* Set up a fake reader function that gets command lines from a linked |
14960 | list that was acquired during tracepoint uploading. */ | |
14961 | ||
14962 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14963 | static int next_cmd; |
409873ef SS |
14964 | |
14965 | static char * | |
14966 | read_uploaded_action (void) | |
14967 | { | |
14968 | char *rslt; | |
14969 | ||
3149d8c1 | 14970 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14971 | |
3149d8c1 | 14972 | next_cmd++; |
409873ef SS |
14973 | |
14974 | return rslt; | |
14975 | } | |
14976 | ||
00bf0b85 SS |
14977 | /* Given information about a tracepoint as recorded on a target (which |
14978 | can be either a live system or a trace file), attempt to create an | |
14979 | equivalent GDB tracepoint. This is not a reliable process, since | |
14980 | the target does not necessarily have all the information used when | |
14981 | the tracepoint was originally defined. */ | |
14982 | ||
d9b3f62e | 14983 | struct tracepoint * |
00bf0b85 | 14984 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14985 | { |
409873ef | 14986 | char *addr_str, small_buf[100]; |
d9b3f62e | 14987 | struct tracepoint *tp; |
fd9b8c24 | 14988 | |
409873ef SS |
14989 | if (utp->at_string) |
14990 | addr_str = utp->at_string; | |
14991 | else | |
14992 | { | |
14993 | /* In the absence of a source location, fall back to raw | |
14994 | address. Since there is no way to confirm that the address | |
14995 | means the same thing as when the trace was started, warn the | |
14996 | user. */ | |
3e43a32a MS |
14997 | warning (_("Uploaded tracepoint %d has no " |
14998 | "source location, using raw address"), | |
409873ef | 14999 | utp->number); |
8c042590 | 15000 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15001 | addr_str = small_buf; |
15002 | } | |
15003 | ||
15004 | /* There's not much we can do with a sequence of bytecodes. */ | |
15005 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15006 | warning (_("Uploaded tracepoint %d condition " |
15007 | "has no source form, ignoring it"), | |
409873ef | 15008 | utp->number); |
d5551862 | 15009 | |
8cdf0e15 | 15010 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15011 | addr_str, |
e7e0cddf SS |
15012 | utp->cond_string, -1, NULL, |
15013 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15014 | 0 /* tempflag */, |
0fb4aa4b | 15015 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15016 | 0 /* Ignore count */, |
15017 | pending_break_support, | |
348d480f | 15018 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15019 | 0 /* from_tty */, |
84f4c1fe | 15020 | utp->enabled /* enabled */, |
44f238bb PA |
15021 | 0 /* internal */, |
15022 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15023 | return NULL; |
15024 | ||
409873ef | 15025 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15026 | tp = get_tracepoint (tracepoint_count); |
15027 | gdb_assert (tp != NULL); | |
d5551862 | 15028 | |
00bf0b85 SS |
15029 | if (utp->pass > 0) |
15030 | { | |
8c042590 PM |
15031 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15032 | tp->base.number); | |
00bf0b85 | 15033 | |
409873ef | 15034 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15035 | } |
15036 | ||
409873ef SS |
15037 | /* If we have uploaded versions of the original commands, set up a |
15038 | special-purpose "reader" function and call the usual command line | |
15039 | reader, then pass the result to the breakpoint command-setting | |
15040 | function. */ | |
3149d8c1 | 15041 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15042 | { |
409873ef | 15043 | struct command_line *cmd_list; |
00bf0b85 | 15044 | |
409873ef | 15045 | this_utp = utp; |
3149d8c1 | 15046 | next_cmd = 0; |
d5551862 | 15047 | |
409873ef SS |
15048 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15049 | ||
d9b3f62e | 15050 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15051 | } |
3149d8c1 SS |
15052 | else if (!VEC_empty (char_ptr, utp->actions) |
15053 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15054 | warning (_("Uploaded tracepoint %d actions " |
15055 | "have no source form, ignoring them"), | |
409873ef | 15056 | utp->number); |
00bf0b85 | 15057 | |
f196051f SS |
15058 | /* Copy any status information that might be available. */ |
15059 | tp->base.hit_count = utp->hit_count; | |
15060 | tp->traceframe_usage = utp->traceframe_usage; | |
15061 | ||
00bf0b85 | 15062 | return tp; |
d9b3f62e | 15063 | } |
00bf0b85 | 15064 | |
1042e4c0 SS |
15065 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15066 | omitted. */ | |
15067 | ||
15068 | static void | |
e5a67952 | 15069 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15070 | { |
79a45e25 | 15071 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15072 | int num_printed; |
1042e4c0 | 15073 | |
e5a67952 | 15074 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15075 | |
15076 | if (num_printed == 0) | |
1042e4c0 | 15077 | { |
e5a67952 | 15078 | if (args == NULL || *args == '\0') |
d77f58be SS |
15079 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15080 | else | |
e5a67952 | 15081 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15082 | } |
ad443146 SS |
15083 | |
15084 | default_collect_info (); | |
1042e4c0 SS |
15085 | } |
15086 | ||
4a64f543 | 15087 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15088 | Not supported by all targets. */ |
15089 | static void | |
15090 | enable_trace_command (char *args, int from_tty) | |
15091 | { | |
15092 | enable_command (args, from_tty); | |
15093 | } | |
15094 | ||
4a64f543 | 15095 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15096 | Not supported by all targets. */ |
15097 | static void | |
15098 | disable_trace_command (char *args, int from_tty) | |
15099 | { | |
15100 | disable_command (args, from_tty); | |
15101 | } | |
15102 | ||
4a64f543 | 15103 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15104 | static void |
15105 | delete_trace_command (char *arg, int from_tty) | |
15106 | { | |
35df4500 | 15107 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15108 | |
15109 | dont_repeat (); | |
15110 | ||
15111 | if (arg == 0) | |
15112 | { | |
15113 | int breaks_to_delete = 0; | |
15114 | ||
15115 | /* Delete all breakpoints if no argument. | |
15116 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15117 | have to be deleted with an explicit breakpoint number |
15118 | argument. */ | |
1042e4c0 | 15119 | ALL_TRACEPOINTS (b) |
46c6471b | 15120 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15121 | { |
15122 | breaks_to_delete = 1; | |
15123 | break; | |
15124 | } | |
1042e4c0 SS |
15125 | |
15126 | /* Ask user only if there are some breakpoints to delete. */ | |
15127 | if (!from_tty | |
15128 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15129 | { | |
35df4500 | 15130 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15131 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15132 | delete_breakpoint (b); |
1042e4c0 SS |
15133 | } |
15134 | } | |
15135 | else | |
51be5b68 | 15136 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15137 | } |
15138 | ||
197f0a60 TT |
15139 | /* Helper function for trace_pass_command. */ |
15140 | ||
15141 | static void | |
d9b3f62e | 15142 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15143 | { |
d9b3f62e | 15144 | tp->pass_count = count; |
6f6484cd | 15145 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15146 | if (from_tty) |
15147 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15148 | tp->base.number, count); |
197f0a60 TT |
15149 | } |
15150 | ||
1042e4c0 SS |
15151 | /* Set passcount for tracepoint. |
15152 | ||
15153 | First command argument is passcount, second is tracepoint number. | |
15154 | If tracepoint number omitted, apply to most recently defined. | |
15155 | Also accepts special argument "all". */ | |
15156 | ||
15157 | static void | |
15158 | trace_pass_command (char *args, int from_tty) | |
15159 | { | |
d9b3f62e | 15160 | struct tracepoint *t1; |
1042e4c0 | 15161 | unsigned int count; |
1042e4c0 SS |
15162 | |
15163 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15164 | error (_("passcount command requires an " |
15165 | "argument (count + optional TP num)")); | |
1042e4c0 | 15166 | |
4a64f543 | 15167 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15168 | |
529480d0 | 15169 | args = skip_spaces (args); |
1042e4c0 SS |
15170 | if (*args && strncasecmp (args, "all", 3) == 0) |
15171 | { | |
d9b3f62e PA |
15172 | struct breakpoint *b; |
15173 | ||
1042e4c0 | 15174 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15175 | if (*args) |
15176 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15177 | |
d9b3f62e | 15178 | ALL_TRACEPOINTS (b) |
197f0a60 | 15179 | { |
d9b3f62e | 15180 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15181 | trace_pass_set_count (t1, count, from_tty); |
15182 | } | |
15183 | } | |
15184 | else if (*args == '\0') | |
1042e4c0 | 15185 | { |
5fa1d40e | 15186 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15187 | if (t1) |
197f0a60 TT |
15188 | trace_pass_set_count (t1, count, from_tty); |
15189 | } | |
15190 | else | |
15191 | { | |
15192 | struct get_number_or_range_state state; | |
15193 | ||
15194 | init_number_or_range (&state, args); | |
15195 | while (!state.finished) | |
1042e4c0 | 15196 | { |
5fa1d40e | 15197 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15198 | if (t1) |
15199 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15200 | } |
15201 | } | |
1042e4c0 SS |
15202 | } |
15203 | ||
d9b3f62e | 15204 | struct tracepoint * |
1042e4c0 SS |
15205 | get_tracepoint (int num) |
15206 | { | |
15207 | struct breakpoint *t; | |
15208 | ||
15209 | ALL_TRACEPOINTS (t) | |
15210 | if (t->number == num) | |
d9b3f62e | 15211 | return (struct tracepoint *) t; |
1042e4c0 SS |
15212 | |
15213 | return NULL; | |
15214 | } | |
15215 | ||
d5551862 SS |
15216 | /* Find the tracepoint with the given target-side number (which may be |
15217 | different from the tracepoint number after disconnecting and | |
15218 | reconnecting). */ | |
15219 | ||
d9b3f62e | 15220 | struct tracepoint * |
d5551862 SS |
15221 | get_tracepoint_by_number_on_target (int num) |
15222 | { | |
d9b3f62e | 15223 | struct breakpoint *b; |
d5551862 | 15224 | |
d9b3f62e PA |
15225 | ALL_TRACEPOINTS (b) |
15226 | { | |
15227 | struct tracepoint *t = (struct tracepoint *) b; | |
15228 | ||
15229 | if (t->number_on_target == num) | |
15230 | return t; | |
15231 | } | |
d5551862 SS |
15232 | |
15233 | return NULL; | |
15234 | } | |
15235 | ||
1042e4c0 | 15236 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15237 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15238 | If the argument is missing, the most recent tracepoint |
15239 | (tracepoint_count) is returned. */ | |
15240 | ||
d9b3f62e | 15241 | struct tracepoint * |
197f0a60 | 15242 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15243 | struct get_number_or_range_state *state) |
1042e4c0 | 15244 | { |
1042e4c0 SS |
15245 | struct breakpoint *t; |
15246 | int tpnum; | |
15247 | char *instring = arg == NULL ? NULL : *arg; | |
15248 | ||
197f0a60 TT |
15249 | if (state) |
15250 | { | |
15251 | gdb_assert (!state->finished); | |
15252 | tpnum = get_number_or_range (state); | |
15253 | } | |
15254 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15255 | tpnum = tracepoint_count; |
1042e4c0 | 15256 | else |
197f0a60 | 15257 | tpnum = get_number (arg); |
1042e4c0 SS |
15258 | |
15259 | if (tpnum <= 0) | |
15260 | { | |
15261 | if (instring && *instring) | |
15262 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15263 | instring); | |
15264 | else | |
5fa1d40e | 15265 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15266 | return NULL; |
15267 | } | |
15268 | ||
15269 | ALL_TRACEPOINTS (t) | |
15270 | if (t->number == tpnum) | |
15271 | { | |
d9b3f62e | 15272 | return (struct tracepoint *) t; |
1042e4c0 SS |
15273 | } |
15274 | ||
1042e4c0 SS |
15275 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15276 | return NULL; | |
15277 | } | |
15278 | ||
d9b3f62e PA |
15279 | void |
15280 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15281 | { | |
15282 | if (b->thread != -1) | |
15283 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15284 | ||
15285 | if (b->task != 0) | |
15286 | fprintf_unfiltered (fp, " task %d", b->task); | |
15287 | ||
15288 | fprintf_unfiltered (fp, "\n"); | |
15289 | } | |
15290 | ||
6149aea9 PA |
15291 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15292 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15293 | on each breakpoint and only include the ones for which it returns | |
15294 | non-zero. */ | |
15295 | ||
1042e4c0 | 15296 | static void |
6149aea9 PA |
15297 | save_breakpoints (char *filename, int from_tty, |
15298 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15299 | { |
15300 | struct breakpoint *tp; | |
6149aea9 | 15301 | int any = 0; |
1042e4c0 | 15302 | struct cleanup *cleanup; |
a7bdde9e | 15303 | struct ui_file *fp; |
6149aea9 | 15304 | int extra_trace_bits = 0; |
1042e4c0 | 15305 | |
6149aea9 PA |
15306 | if (filename == 0 || *filename == 0) |
15307 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15308 | |
15309 | /* See if we have anything to save. */ | |
6149aea9 | 15310 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15311 | { |
6149aea9 | 15312 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15313 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15314 | continue; |
15315 | ||
15316 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15317 | if (filter && !filter (tp)) | |
15318 | continue; | |
15319 | ||
15320 | any = 1; | |
15321 | ||
15322 | if (is_tracepoint (tp)) | |
15323 | { | |
15324 | extra_trace_bits = 1; | |
15325 | ||
15326 | /* We can stop searching. */ | |
15327 | break; | |
15328 | } | |
1042e4c0 | 15329 | } |
6149aea9 PA |
15330 | |
15331 | if (!any) | |
1042e4c0 | 15332 | { |
6149aea9 | 15333 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15334 | return; |
15335 | } | |
15336 | ||
c718be47 PA |
15337 | filename = tilde_expand (filename); |
15338 | cleanup = make_cleanup (xfree, filename); | |
15339 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15340 | if (!fp) |
6149aea9 PA |
15341 | error (_("Unable to open file '%s' for saving (%s)"), |
15342 | filename, safe_strerror (errno)); | |
a7bdde9e | 15343 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15344 | |
6149aea9 PA |
15345 | if (extra_trace_bits) |
15346 | save_trace_state_variables (fp); | |
8bf6485c | 15347 | |
6149aea9 | 15348 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15349 | { |
6149aea9 | 15350 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15351 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15352 | continue; |
8bf6485c | 15353 | |
6149aea9 PA |
15354 | /* If we have a filter, only save the breakpoints it accepts. */ |
15355 | if (filter && !filter (tp)) | |
15356 | continue; | |
15357 | ||
348d480f | 15358 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15359 | |
6149aea9 PA |
15360 | /* Note, we can't rely on tp->number for anything, as we can't |
15361 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15362 | instead. */ | |
15363 | ||
15364 | if (tp->cond_string) | |
15365 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15366 | ||
15367 | if (tp->ignore_count) | |
15368 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15369 | ||
2d9442cc | 15370 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15371 | { |
6c63c96a | 15372 | struct gdb_exception exception; |
a7bdde9e | 15373 | |
6149aea9 | 15374 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15375 | |
79a45e25 | 15376 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15377 | TRY |
1042e4c0 | 15378 | { |
79a45e25 | 15379 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15380 | } |
492d29ea PA |
15381 | CATCH (ex, RETURN_MASK_ALL) |
15382 | { | |
6c63c96a | 15383 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15384 | throw_exception (ex); |
15385 | } | |
15386 | END_CATCH | |
1042e4c0 | 15387 | |
6c63c96a | 15388 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15389 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15390 | } |
6149aea9 PA |
15391 | |
15392 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15393 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15394 | |
15395 | /* If this is a multi-location breakpoint, check if the locations | |
15396 | should be individually disabled. Watchpoint locations are | |
15397 | special, and not user visible. */ | |
15398 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15399 | { | |
15400 | struct bp_location *loc; | |
15401 | int n = 1; | |
15402 | ||
15403 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15404 | if (!loc->enabled) | |
15405 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15406 | } | |
1042e4c0 | 15407 | } |
8bf6485c | 15408 | |
6149aea9 | 15409 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15410 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15411 | ||
1042e4c0 | 15412 | if (from_tty) |
6149aea9 | 15413 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15414 | do_cleanups (cleanup); |
6149aea9 PA |
15415 | } |
15416 | ||
15417 | /* The `save breakpoints' command. */ | |
15418 | ||
15419 | static void | |
15420 | save_breakpoints_command (char *args, int from_tty) | |
15421 | { | |
15422 | save_breakpoints (args, from_tty, NULL); | |
15423 | } | |
15424 | ||
15425 | /* The `save tracepoints' command. */ | |
15426 | ||
15427 | static void | |
15428 | save_tracepoints_command (char *args, int from_tty) | |
15429 | { | |
15430 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15431 | } |
15432 | ||
15433 | /* Create a vector of all tracepoints. */ | |
15434 | ||
15435 | VEC(breakpoint_p) * | |
eeae04df | 15436 | all_tracepoints (void) |
1042e4c0 SS |
15437 | { |
15438 | VEC(breakpoint_p) *tp_vec = 0; | |
15439 | struct breakpoint *tp; | |
15440 | ||
15441 | ALL_TRACEPOINTS (tp) | |
15442 | { | |
15443 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15444 | } | |
15445 | ||
15446 | return tp_vec; | |
15447 | } | |
15448 | ||
c906108c | 15449 | \f |
4a64f543 MS |
15450 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15451 | commands. It is defined as a macro to prevent duplication. | |
15452 | COMMAND should be a string constant containing the name of the | |
15453 | command. */ | |
31e2b00f | 15454 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15455 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15456 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15457 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15458 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15459 | `-probe-dtrace' (for a DTrace probe).\n\ | |
31e2b00f AS |
15460 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15461 | If a line number is specified, break at start of code for that line.\n\ | |
15462 | If a function is specified, break at start of code for that function.\n\ | |
15463 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15464 | With no LOCATION, uses current execution address of the selected\n\ |
15465 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15466 | \n\ |
15467 | THREADNUM is the number from \"info threads\".\n\ | |
15468 | CONDITION is a boolean expression.\n\ | |
15469 | \n\ | |
d41c0fc8 PA |
15470 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15471 | conditions are different.\n\ | |
31e2b00f AS |
15472 | \n\ |
15473 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15474 | ||
44feb3ce TT |
15475 | /* List of subcommands for "catch". */ |
15476 | static struct cmd_list_element *catch_cmdlist; | |
15477 | ||
15478 | /* List of subcommands for "tcatch". */ | |
15479 | static struct cmd_list_element *tcatch_cmdlist; | |
15480 | ||
9ac4176b | 15481 | void |
44feb3ce | 15482 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15483 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15484 | completer_ftype *completer, |
44feb3ce TT |
15485 | void *user_data_catch, |
15486 | void *user_data_tcatch) | |
15487 | { | |
15488 | struct cmd_list_element *command; | |
15489 | ||
15490 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15491 | &catch_cmdlist); | |
15492 | set_cmd_sfunc (command, sfunc); | |
15493 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15494 | set_cmd_completer (command, completer); |
44feb3ce TT |
15495 | |
15496 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15497 | &tcatch_cmdlist); | |
15498 | set_cmd_sfunc (command, sfunc); | |
15499 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15500 | set_cmd_completer (command, completer); |
44feb3ce TT |
15501 | } |
15502 | ||
6149aea9 PA |
15503 | static void |
15504 | save_command (char *arg, int from_tty) | |
15505 | { | |
3e43a32a MS |
15506 | printf_unfiltered (_("\"save\" must be followed by " |
15507 | "the name of a save subcommand.\n")); | |
635c7e8a | 15508 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15509 | } |
15510 | ||
84f4c1fe PM |
15511 | struct breakpoint * |
15512 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15513 | void *data) | |
15514 | { | |
35df4500 | 15515 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15516 | |
35df4500 | 15517 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15518 | { |
15519 | if ((*callback) (b, data)) | |
15520 | return b; | |
15521 | } | |
15522 | ||
15523 | return NULL; | |
15524 | } | |
15525 | ||
0574c78f GB |
15526 | /* Zero if any of the breakpoint's locations could be a location where |
15527 | functions have been inlined, nonzero otherwise. */ | |
15528 | ||
15529 | static int | |
15530 | is_non_inline_function (struct breakpoint *b) | |
15531 | { | |
15532 | /* The shared library event breakpoint is set on the address of a | |
15533 | non-inline function. */ | |
15534 | if (b->type == bp_shlib_event) | |
15535 | return 1; | |
15536 | ||
15537 | return 0; | |
15538 | } | |
15539 | ||
15540 | /* Nonzero if the specified PC cannot be a location where functions | |
15541 | have been inlined. */ | |
15542 | ||
15543 | int | |
09ac7c10 TT |
15544 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15545 | const struct target_waitstatus *ws) | |
0574c78f GB |
15546 | { |
15547 | struct breakpoint *b; | |
15548 | struct bp_location *bl; | |
15549 | ||
15550 | ALL_BREAKPOINTS (b) | |
15551 | { | |
15552 | if (!is_non_inline_function (b)) | |
15553 | continue; | |
15554 | ||
15555 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15556 | { | |
15557 | if (!bl->shlib_disabled | |
09ac7c10 | 15558 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15559 | return 1; |
15560 | } | |
15561 | } | |
15562 | ||
15563 | return 0; | |
15564 | } | |
15565 | ||
2f202fde JK |
15566 | /* Remove any references to OBJFILE which is going to be freed. */ |
15567 | ||
15568 | void | |
15569 | breakpoint_free_objfile (struct objfile *objfile) | |
15570 | { | |
15571 | struct bp_location **locp, *loc; | |
15572 | ||
15573 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15574 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15575 | loc->symtab = NULL; |
15576 | } | |
15577 | ||
2060206e PA |
15578 | void |
15579 | initialize_breakpoint_ops (void) | |
15580 | { | |
15581 | static int initialized = 0; | |
15582 | ||
15583 | struct breakpoint_ops *ops; | |
15584 | ||
15585 | if (initialized) | |
15586 | return; | |
15587 | initialized = 1; | |
15588 | ||
15589 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15590 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15591 | internal and momentary breakpoints, etc.). */ | |
15592 | ops = &bkpt_base_breakpoint_ops; | |
15593 | *ops = base_breakpoint_ops; | |
15594 | ops->re_set = bkpt_re_set; | |
15595 | ops->insert_location = bkpt_insert_location; | |
15596 | ops->remove_location = bkpt_remove_location; | |
15597 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
15598 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
15599 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
15600 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
15601 | |
15602 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15603 | ops = &bkpt_breakpoint_ops; | |
15604 | *ops = bkpt_base_breakpoint_ops; | |
15605 | ops->re_set = bkpt_re_set; | |
15606 | ops->resources_needed = bkpt_resources_needed; | |
15607 | ops->print_it = bkpt_print_it; | |
15608 | ops->print_mention = bkpt_print_mention; | |
15609 | ops->print_recreate = bkpt_print_recreate; | |
15610 | ||
15611 | /* Ranged breakpoints. */ | |
15612 | ops = &ranged_breakpoint_ops; | |
15613 | *ops = bkpt_breakpoint_ops; | |
15614 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15615 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15616 | ops->print_it = print_it_ranged_breakpoint; | |
15617 | ops->print_one = print_one_ranged_breakpoint; | |
15618 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15619 | ops->print_mention = print_mention_ranged_breakpoint; | |
15620 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15621 | ||
15622 | /* Internal breakpoints. */ | |
15623 | ops = &internal_breakpoint_ops; | |
15624 | *ops = bkpt_base_breakpoint_ops; | |
15625 | ops->re_set = internal_bkpt_re_set; | |
15626 | ops->check_status = internal_bkpt_check_status; | |
15627 | ops->print_it = internal_bkpt_print_it; | |
15628 | ops->print_mention = internal_bkpt_print_mention; | |
15629 | ||
15630 | /* Momentary breakpoints. */ | |
15631 | ops = &momentary_breakpoint_ops; | |
15632 | *ops = bkpt_base_breakpoint_ops; | |
15633 | ops->re_set = momentary_bkpt_re_set; | |
15634 | ops->check_status = momentary_bkpt_check_status; | |
15635 | ops->print_it = momentary_bkpt_print_it; | |
15636 | ops->print_mention = momentary_bkpt_print_mention; | |
15637 | ||
e2e4d78b JK |
15638 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15639 | ops = &longjmp_breakpoint_ops; | |
15640 | *ops = momentary_breakpoint_ops; | |
15641 | ops->dtor = longjmp_bkpt_dtor; | |
15642 | ||
55aa24fb SDJ |
15643 | /* Probe breakpoints. */ |
15644 | ops = &bkpt_probe_breakpoint_ops; | |
15645 | *ops = bkpt_breakpoint_ops; | |
15646 | ops->insert_location = bkpt_probe_insert_location; | |
15647 | ops->remove_location = bkpt_probe_remove_location; | |
15648 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
15649 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
15650 | ||
2060206e PA |
15651 | /* Watchpoints. */ |
15652 | ops = &watchpoint_breakpoint_ops; | |
15653 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15654 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15655 | ops->re_set = re_set_watchpoint; |
15656 | ops->insert_location = insert_watchpoint; | |
15657 | ops->remove_location = remove_watchpoint; | |
15658 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15659 | ops->check_status = check_status_watchpoint; | |
15660 | ops->resources_needed = resources_needed_watchpoint; | |
15661 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15662 | ops->print_it = print_it_watchpoint; | |
15663 | ops->print_mention = print_mention_watchpoint; | |
15664 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15665 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15666 | |
15667 | /* Masked watchpoints. */ | |
15668 | ops = &masked_watchpoint_breakpoint_ops; | |
15669 | *ops = watchpoint_breakpoint_ops; | |
15670 | ops->insert_location = insert_masked_watchpoint; | |
15671 | ops->remove_location = remove_masked_watchpoint; | |
15672 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15673 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15674 | ops->print_it = print_it_masked_watchpoint; | |
15675 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15676 | ops->print_mention = print_mention_masked_watchpoint; | |
15677 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15678 | ||
15679 | /* Tracepoints. */ | |
15680 | ops = &tracepoint_breakpoint_ops; | |
15681 | *ops = base_breakpoint_ops; | |
15682 | ops->re_set = tracepoint_re_set; | |
15683 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15684 | ops->print_one_detail = tracepoint_print_one_detail; | |
15685 | ops->print_mention = tracepoint_print_mention; | |
15686 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
15687 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
15688 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
15689 | ops->decode_linespec = tracepoint_decode_linespec; | |
15690 | ||
55aa24fb SDJ |
15691 | /* Probe tracepoints. */ |
15692 | ops = &tracepoint_probe_breakpoint_ops; | |
15693 | *ops = tracepoint_breakpoint_ops; | |
15694 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
15695 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
15696 | ||
983af33b SDJ |
15697 | /* Static tracepoints with marker (`-m'). */ |
15698 | ops = &strace_marker_breakpoint_ops; | |
15699 | *ops = tracepoint_breakpoint_ops; | |
15700 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
15701 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
15702 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
15703 | |
15704 | /* Fork catchpoints. */ | |
15705 | ops = &catch_fork_breakpoint_ops; | |
15706 | *ops = base_breakpoint_ops; | |
15707 | ops->insert_location = insert_catch_fork; | |
15708 | ops->remove_location = remove_catch_fork; | |
15709 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15710 | ops->print_it = print_it_catch_fork; | |
15711 | ops->print_one = print_one_catch_fork; | |
15712 | ops->print_mention = print_mention_catch_fork; | |
15713 | ops->print_recreate = print_recreate_catch_fork; | |
15714 | ||
15715 | /* Vfork catchpoints. */ | |
15716 | ops = &catch_vfork_breakpoint_ops; | |
15717 | *ops = base_breakpoint_ops; | |
15718 | ops->insert_location = insert_catch_vfork; | |
15719 | ops->remove_location = remove_catch_vfork; | |
15720 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15721 | ops->print_it = print_it_catch_vfork; | |
15722 | ops->print_one = print_one_catch_vfork; | |
15723 | ops->print_mention = print_mention_catch_vfork; | |
15724 | ops->print_recreate = print_recreate_catch_vfork; | |
15725 | ||
15726 | /* Exec catchpoints. */ | |
15727 | ops = &catch_exec_breakpoint_ops; | |
15728 | *ops = base_breakpoint_ops; | |
15729 | ops->dtor = dtor_catch_exec; | |
15730 | ops->insert_location = insert_catch_exec; | |
15731 | ops->remove_location = remove_catch_exec; | |
15732 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15733 | ops->print_it = print_it_catch_exec; | |
15734 | ops->print_one = print_one_catch_exec; | |
15735 | ops->print_mention = print_mention_catch_exec; | |
15736 | ops->print_recreate = print_recreate_catch_exec; | |
15737 | ||
edcc5120 TT |
15738 | /* Solib-related catchpoints. */ |
15739 | ops = &catch_solib_breakpoint_ops; | |
15740 | *ops = base_breakpoint_ops; | |
15741 | ops->dtor = dtor_catch_solib; | |
15742 | ops->insert_location = insert_catch_solib; | |
15743 | ops->remove_location = remove_catch_solib; | |
15744 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15745 | ops->check_status = check_status_catch_solib; | |
15746 | ops->print_it = print_it_catch_solib; | |
15747 | ops->print_one = print_one_catch_solib; | |
15748 | ops->print_mention = print_mention_catch_solib; | |
15749 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15750 | |
15751 | ops = &dprintf_breakpoint_ops; | |
15752 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15753 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15754 | ops->resources_needed = bkpt_resources_needed; |
15755 | ops->print_it = bkpt_print_it; | |
15756 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15757 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15758 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15759 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15760 | } |
15761 | ||
8bfd80db YQ |
15762 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15763 | ||
15764 | static struct cmd_list_element *enablebreaklist = NULL; | |
15765 | ||
c906108c | 15766 | void |
fba45db2 | 15767 | _initialize_breakpoint (void) |
c906108c SS |
15768 | { |
15769 | struct cmd_list_element *c; | |
15770 | ||
2060206e PA |
15771 | initialize_breakpoint_ops (); |
15772 | ||
84acb35a | 15773 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15774 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15775 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15776 | |
55aa24fb SDJ |
15777 | breakpoint_objfile_key |
15778 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15779 | |
c906108c SS |
15780 | breakpoint_chain = 0; |
15781 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15782 | before a breakpoint is set. */ | |
15783 | breakpoint_count = 0; | |
15784 | ||
1042e4c0 SS |
15785 | tracepoint_count = 0; |
15786 | ||
1bedd215 AC |
15787 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15788 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15789 | Usage is `ignore N COUNT'.")); | |
c906108c | 15790 | |
1bedd215 AC |
15791 | add_com ("commands", class_breakpoint, commands_command, _("\ |
15792 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
15793 | Give breakpoint number as argument after \"commands\".\n\ |
15794 | With no argument, the targeted breakpoint is the last one set.\n\ | |
15795 | The commands themselves follow starting on the next line.\n\ | |
15796 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15797 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15798 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15799 | |
d55637df | 15800 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15801 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15802 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15803 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15804 | set_cmd_completer (c, condition_completer); |
c906108c | 15805 | |
1bedd215 | 15806 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15807 | Set a temporary breakpoint.\n\ |
c906108c SS |
15808 | Like \"break\" except the breakpoint is only temporary,\n\ |
15809 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15810 | by using \"enable delete\" on the breakpoint number.\n\ |
15811 | \n" | |
15812 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15813 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15814 | |
1bedd215 | 15815 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15816 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15817 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15818 | some target hardware may not have this support.\n\ |
15819 | \n" | |
15820 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15821 | set_cmd_completer (c, location_completer); |
c906108c | 15822 | |
1bedd215 | 15823 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15824 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15825 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15826 | so it will be deleted when hit.\n\ |
15827 | \n" | |
15828 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15829 | set_cmd_completer (c, location_completer); |
c906108c | 15830 | |
1bedd215 AC |
15831 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15832 | Enable some breakpoints.\n\ | |
c906108c SS |
15833 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15834 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15835 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15836 | With a subcommand you can enable temporarily."), |
c906108c | 15837 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15838 | |
15839 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15840 | ||
84951ab5 | 15841 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15842 | Enable some breakpoints.\n\ |
c906108c SS |
15843 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15844 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15845 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15846 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15847 | |
1a966eab AC |
15848 | add_cmd ("once", no_class, enable_once_command, _("\ |
15849 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15850 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15851 | &enablebreaklist); |
15852 | ||
1a966eab AC |
15853 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15854 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15855 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15856 | &enablebreaklist); |
15857 | ||
816338b5 SS |
15858 | add_cmd ("count", no_class, enable_count_command, _("\ |
15859 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15860 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15861 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15862 | &enablebreaklist); | |
15863 | ||
1a966eab AC |
15864 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15865 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15866 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15867 | &enablelist); |
15868 | ||
1a966eab AC |
15869 | add_cmd ("once", no_class, enable_once_command, _("\ |
15870 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15871 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15872 | &enablelist); |
15873 | ||
15874 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15875 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15876 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15877 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15878 | &enablelist); |
15879 | ||
1bedd215 AC |
15880 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15881 | Disable some breakpoints.\n\ | |
c906108c SS |
15882 | Arguments are breakpoint numbers with spaces in between.\n\ |
15883 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15884 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15885 | &disablelist, "disable ", 1, &cmdlist); |
15886 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15887 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15888 | |
1a966eab AC |
15889 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15890 | Disable some breakpoints.\n\ | |
c906108c SS |
15891 | Arguments are breakpoint numbers with spaces in between.\n\ |
15892 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15893 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15894 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15895 | &disablelist); |
15896 | ||
1bedd215 AC |
15897 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15898 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15899 | Arguments are breakpoint numbers with spaces in between.\n\ |
15900 | To delete all breakpoints, give no argument.\n\ | |
15901 | \n\ | |
15902 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15903 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15904 | &deletelist, "delete ", 1, &cmdlist); |
15905 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15906 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15907 | |
1a966eab AC |
15908 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15909 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15910 | Arguments are breakpoint numbers with spaces in between.\n\ |
15911 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15912 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15913 | &deletelist); |
15914 | ||
1bedd215 AC |
15915 | add_com ("clear", class_breakpoint, clear_command, _("\ |
15916 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
15917 | Argument may be line number, function name, or \"*\" and an address.\n\ |
15918 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
15919 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
15920 | If an address is specified, breakpoints at that address are cleared.\n\ |
15921 | \n\ | |
15922 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
15923 | is executing in.\n\ |
15924 | \n\ | |
1bedd215 | 15925 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15926 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15927 | |
1bedd215 | 15928 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
15929 | Set breakpoint at specified line or function.\n" |
15930 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 15931 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15932 | |
c906108c SS |
15933 | add_com_alias ("b", "break", class_run, 1); |
15934 | add_com_alias ("br", "break", class_run, 1); | |
15935 | add_com_alias ("bre", "break", class_run, 1); | |
15936 | add_com_alias ("brea", "break", class_run, 1); | |
15937 | ||
c906108c SS |
15938 | if (dbx_commands) |
15939 | { | |
1bedd215 AC |
15940 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15941 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15942 | &stoplist, "stop ", 1, &cmdlist); |
15943 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15944 | _("Break in function or address."), &stoplist); |
c5aa993b | 15945 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15946 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
15947 | add_com ("status", class_info, breakpoints_info, _("\ |
15948 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15949 | The \"Type\" column indicates one of:\n\ |
15950 | \tbreakpoint - normal breakpoint\n\ | |
15951 | \twatchpoint - watchpoint\n\ | |
15952 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15953 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15954 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15955 | address and file/line number respectively.\n\ |
15956 | \n\ | |
15957 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15958 | are set to the address of the last breakpoint listed unless the command\n\ |
15959 | is prefixed with \"server \".\n\n\ | |
c906108c | 15960 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15961 | breakpoint set.")); |
c906108c SS |
15962 | } |
15963 | ||
1bedd215 | 15964 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 15965 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15966 | The \"Type\" column indicates one of:\n\ |
15967 | \tbreakpoint - normal breakpoint\n\ | |
15968 | \twatchpoint - watchpoint\n\ | |
15969 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15970 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15971 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15972 | address and file/line number respectively.\n\ |
15973 | \n\ | |
15974 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15975 | are set to the address of the last breakpoint listed unless the command\n\ |
15976 | is prefixed with \"server \".\n\n\ | |
c906108c | 15977 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15978 | breakpoint set.")); |
c906108c | 15979 | |
6b04bdb7 MS |
15980 | add_info_alias ("b", "breakpoints", 1); |
15981 | ||
1a966eab AC |
15982 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15983 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15984 | The \"Type\" column indicates one of:\n\ |
15985 | \tbreakpoint - normal breakpoint\n\ | |
15986 | \twatchpoint - watchpoint\n\ | |
15987 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15988 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15989 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15990 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15991 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15992 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15993 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15994 | address and file/line number respectively.\n\ |
15995 | \n\ | |
15996 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15997 | are set to the address of the last breakpoint listed unless the command\n\ |
15998 | is prefixed with \"server \".\n\n\ | |
c906108c | 15999 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16000 | breakpoint set."), |
c906108c SS |
16001 | &maintenanceinfolist); |
16002 | ||
44feb3ce TT |
16003 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16004 | Set catchpoints to catch events."), | |
16005 | &catch_cmdlist, "catch ", | |
16006 | 0/*allow-unknown*/, &cmdlist); | |
16007 | ||
16008 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16009 | Set temporary catchpoints to catch events."), | |
16010 | &tcatch_cmdlist, "tcatch ", | |
16011 | 0/*allow-unknown*/, &cmdlist); | |
16012 | ||
44feb3ce TT |
16013 | add_catch_command ("fork", _("Catch calls to fork."), |
16014 | catch_fork_command_1, | |
a96d9b2e | 16015 | NULL, |
44feb3ce TT |
16016 | (void *) (uintptr_t) catch_fork_permanent, |
16017 | (void *) (uintptr_t) catch_fork_temporary); | |
16018 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16019 | catch_fork_command_1, | |
a96d9b2e | 16020 | NULL, |
44feb3ce TT |
16021 | (void *) (uintptr_t) catch_vfork_permanent, |
16022 | (void *) (uintptr_t) catch_vfork_temporary); | |
16023 | add_catch_command ("exec", _("Catch calls to exec."), | |
16024 | catch_exec_command_1, | |
a96d9b2e SDJ |
16025 | NULL, |
16026 | CATCH_PERMANENT, | |
16027 | CATCH_TEMPORARY); | |
edcc5120 TT |
16028 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16029 | Usage: catch load [REGEX]\n\ | |
16030 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16031 | catch_load_command_1, | |
16032 | NULL, | |
16033 | CATCH_PERMANENT, | |
16034 | CATCH_TEMPORARY); | |
16035 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16036 | Usage: catch unload [REGEX]\n\ | |
16037 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16038 | catch_unload_command_1, | |
16039 | NULL, | |
16040 | CATCH_PERMANENT, | |
16041 | CATCH_TEMPORARY); | |
c5aa993b | 16042 | |
1bedd215 AC |
16043 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16044 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16045 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16046 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16047 | an expression changes.\n\ |
16048 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16049 | the memory to which it refers.")); | |
65d12d83 | 16050 | set_cmd_completer (c, expression_completer); |
c906108c | 16051 | |
1bedd215 AC |
16052 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16053 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16054 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16055 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16056 | an expression is read.\n\ |
16057 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16058 | the memory to which it refers.")); | |
65d12d83 | 16059 | set_cmd_completer (c, expression_completer); |
c906108c | 16060 | |
1bedd215 AC |
16061 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16062 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16063 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16064 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16065 | an expression is either read or written.\n\ |
16066 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16067 | the memory to which it refers.")); | |
65d12d83 | 16068 | set_cmd_completer (c, expression_completer); |
c906108c | 16069 | |
d77f58be | 16070 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16071 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16072 | |
920d2a44 AC |
16073 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16074 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16075 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16076 | &can_use_hw_watchpoints, _("\ | |
16077 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16078 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16079 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16080 | such is available. (However, any hardware watchpoints that were\n\ | |
16081 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16082 | hardware.)"), |
16083 | NULL, | |
920d2a44 | 16084 | show_can_use_hw_watchpoints, |
85c07804 | 16085 | &setlist, &showlist); |
c906108c SS |
16086 | |
16087 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16088 | |
1042e4c0 SS |
16089 | /* Tracepoint manipulation commands. */ |
16090 | ||
16091 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16092 | Set a tracepoint at specified line or function.\n\ | |
16093 | \n" | |
16094 | BREAK_ARGS_HELP ("trace") "\n\ | |
16095 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16096 | set_cmd_completer (c, location_completer); | |
16097 | ||
16098 | add_com_alias ("tp", "trace", class_alias, 0); | |
16099 | add_com_alias ("tr", "trace", class_alias, 1); | |
16100 | add_com_alias ("tra", "trace", class_alias, 1); | |
16101 | add_com_alias ("trac", "trace", class_alias, 1); | |
16102 | ||
7a697b8d SS |
16103 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16104 | Set a fast tracepoint at specified line or function.\n\ | |
16105 | \n" | |
16106 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16107 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16108 | set_cmd_completer (c, location_completer); | |
16109 | ||
0fb4aa4b PA |
16110 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16111 | Set a static tracepoint at specified line, function or marker.\n\ | |
16112 | \n\ | |
16113 | strace [LOCATION] [if CONDITION]\n\ | |
16114 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16115 | or -m MARKER_ID.\n\ | |
16116 | If a line number is specified, probe the marker at start of code\n\ | |
16117 | for that line. If a function is specified, probe the marker at start\n\ | |
16118 | of code for that function. If an address is specified, probe the marker\n\ | |
16119 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16120 | with that name. With no LOCATION, uses current execution address of\n\ | |
16121 | the selected stack frame.\n\ | |
16122 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16123 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16124 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16125 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16126 | \n\ | |
16127 | CONDITION is a boolean expression.\n\ | |
16128 | \n\ | |
d41c0fc8 PA |
16129 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16130 | conditions are different.\n\ | |
0fb4aa4b PA |
16131 | \n\ |
16132 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16133 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16134 | set_cmd_completer (c, location_completer); | |
16135 | ||
1042e4c0 | 16136 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16137 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16138 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16139 | last tracepoint set.")); | |
16140 | ||
16141 | add_info_alias ("tp", "tracepoints", 1); | |
16142 | ||
16143 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16144 | Delete specified tracepoints.\n\ | |
16145 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16146 | No argument means delete all tracepoints."), | |
16147 | &deletelist); | |
7e20dfcd | 16148 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16149 | |
16150 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16151 | Disable specified tracepoints.\n\ | |
16152 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16153 | No argument means disable all tracepoints."), | |
16154 | &disablelist); | |
16155 | deprecate_cmd (c, "disable"); | |
16156 | ||
16157 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16158 | Enable specified tracepoints.\n\ | |
16159 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16160 | No argument means enable all tracepoints."), | |
16161 | &enablelist); | |
16162 | deprecate_cmd (c, "enable"); | |
16163 | ||
16164 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16165 | Set the passcount for a tracepoint.\n\ | |
16166 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16167 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16168 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16169 | ||
6149aea9 PA |
16170 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16171 | _("Save breakpoint definitions as a script."), | |
16172 | &save_cmdlist, "save ", | |
16173 | 0/*allow-unknown*/, &cmdlist); | |
16174 | ||
16175 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16176 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16177 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16178 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16179 | session to restore them."), | |
16180 | &save_cmdlist); | |
16181 | set_cmd_completer (c, filename_completer); | |
16182 | ||
16183 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16184 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16185 | Use the 'source' command in another debug session to restore them."), |
16186 | &save_cmdlist); | |
1042e4c0 SS |
16187 | set_cmd_completer (c, filename_completer); |
16188 | ||
6149aea9 PA |
16189 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16190 | deprecate_cmd (c, "save tracepoints"); | |
16191 | ||
1bedd215 | 16192 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16193 | Breakpoint specific settings\n\ |
16194 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16195 | pending breakpoint behavior"), |
fa8d40ab JJ |
16196 | &breakpoint_set_cmdlist, "set breakpoint ", |
16197 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16198 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16199 | Breakpoint specific settings\n\ |
16200 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16201 | pending breakpoint behavior"), |
fa8d40ab JJ |
16202 | &breakpoint_show_cmdlist, "show breakpoint ", |
16203 | 0/*allow-unknown*/, &showlist); | |
16204 | ||
7915a72c AC |
16205 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16206 | &pending_break_support, _("\ | |
16207 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16208 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16209 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16210 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16211 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16212 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16213 | NULL, |
920d2a44 | 16214 | show_pending_break_support, |
6e1d7d6c AC |
16215 | &breakpoint_set_cmdlist, |
16216 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16217 | |
16218 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16219 | |
16220 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16221 | &automatic_hardware_breakpoints, _("\ | |
16222 | Set automatic usage of hardware breakpoints."), _("\ | |
16223 | Show automatic usage of hardware breakpoints."), _("\ | |
16224 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16225 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16226 | a warning will be emitted for such breakpoints."), | |
16227 | NULL, | |
16228 | show_automatic_hardware_breakpoints, | |
16229 | &breakpoint_set_cmdlist, | |
16230 | &breakpoint_show_cmdlist); | |
74960c60 | 16231 | |
a25a5a45 PA |
16232 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16233 | &always_inserted_mode, _("\ | |
74960c60 VP |
16234 | Set mode for inserting breakpoints."), _("\ |
16235 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16236 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16237 | they're created, kept inserted even when execution stops, and removed\n\ | |
16238 | only when the user deletes them. When this mode is off (the default),\n\ | |
16239 | breakpoints are inserted only when execution continues, and removed\n\ | |
16240 | when execution stops."), | |
72d0e2c5 YQ |
16241 | NULL, |
16242 | &show_always_inserted_mode, | |
16243 | &breakpoint_set_cmdlist, | |
16244 | &breakpoint_show_cmdlist); | |
f1310107 | 16245 | |
b775012e LM |
16246 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16247 | condition_evaluation_enums, | |
16248 | &condition_evaluation_mode_1, _("\ | |
16249 | Set mode of breakpoint condition evaluation."), _("\ | |
16250 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16251 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16252 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16253 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16254 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16255 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16256 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16257 | be set to \"gdb\""), | |
16258 | &set_condition_evaluation_mode, | |
16259 | &show_condition_evaluation_mode, | |
16260 | &breakpoint_set_cmdlist, | |
16261 | &breakpoint_show_cmdlist); | |
16262 | ||
f1310107 TJB |
16263 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16264 | Set a breakpoint for an address range.\n\ | |
16265 | break-range START-LOCATION, END-LOCATION\n\ | |
16266 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16267 | LINENUM, for that line in the current file,\n\ | |
16268 | FILE:LINENUM, for that line in that file,\n\ | |
16269 | +OFFSET, for that number of lines after the current line\n\ | |
16270 | or the start of the range\n\ | |
16271 | FUNCTION, for the first line in that function,\n\ | |
16272 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16273 | *ADDRESS, for the instruction at that address.\n\ | |
16274 | \n\ | |
16275 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16276 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16277 | range (including START-LOCATION and END-LOCATION).")); | |
16278 | ||
e7e0cddf SS |
16279 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16280 | Set a dynamic printf at specified line or function.\n\ | |
16281 | dprintf location,format string,arg1,arg2,...\n\ | |
16282 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16283 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16284 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16285 | set_cmd_completer (c, location_completer); |
16286 | ||
16287 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16288 | dprintf_style_enums, &dprintf_style, _("\ | |
16289 | Set the style of usage for dynamic printf."), _("\ | |
16290 | Show the style of usage for dynamic printf."), _("\ | |
16291 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16292 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16293 | console, as with the \"printf\" command.\n\ | |
16294 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16295 | program; by default printf(), but you can choose a different function or\n\ | |
16296 | output stream by setting dprintf-function and dprintf-channel."), | |
16297 | update_dprintf_commands, NULL, | |
16298 | &setlist, &showlist); | |
16299 | ||
16300 | dprintf_function = xstrdup ("printf"); | |
16301 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16302 | &dprintf_function, _("\ | |
16303 | Set the function to use for dynamic printf"), _("\ | |
16304 | Show the function to use for dynamic printf"), NULL, | |
16305 | update_dprintf_commands, NULL, | |
16306 | &setlist, &showlist); | |
16307 | ||
16308 | dprintf_channel = xstrdup (""); | |
16309 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16310 | &dprintf_channel, _("\ | |
16311 | Set the channel to use for dynamic printf"), _("\ | |
16312 | Show the channel to use for dynamic printf"), NULL, | |
16313 | update_dprintf_commands, NULL, | |
16314 | &setlist, &showlist); | |
16315 | ||
d3ce09f5 SS |
16316 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16317 | &disconnected_dprintf, _("\ | |
16318 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16319 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16320 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16321 | even if GDB disconnects or detaches from the target."), | |
16322 | NULL, | |
16323 | NULL, | |
16324 | &setlist, &showlist); | |
16325 | ||
16326 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16327 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16328 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16329 | ||
765dc015 | 16330 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16331 | |
16332 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16333 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16334 | } |